@@ -918,6 +918,30 @@ class Stack {
918
918
// stack.collection = stack.db.collection(stack.contentStore.collectionName)
919
919
return stack ;
920
920
}
921
+ /**
922
+ * @public
923
+ * @method contentTypes
924
+ * @description
925
+ * Query for a set of content type schemas
926
+ * @example
927
+ * Stack
928
+ * .contentTypes()
929
+ * .find()
930
+ * .then((result) => {
931
+ * // returns a set of content type schemas
932
+ * })
933
+ * .catch((error) => {
934
+ * // handle query errors
935
+ * })
936
+ *
937
+ * @returns {Stack } Returns an instance of 'stack'
938
+ */
939
+ contentTypes ( ) {
940
+ const stack = new Stack ( this . config , this . db ) ;
941
+ stack . q . content_type_uid = this . types . content_types ;
942
+ // stack.collection = stack.db.collection(stack.contentStore.collectionName)
943
+ return stack ;
944
+ }
921
945
/**
922
946
* @public
923
947
* @method limit
@@ -1300,7 +1324,7 @@ class Stack {
1300
1324
* @public
1301
1325
* @method excludeReferences
1302
1326
* @description
1303
- * Excludes all references of the entries being scanned
1327
+ * Excludes all references of the entries being scanned.
1304
1328
* Note: On calling this, assets will not be binded in the result being returned.
1305
1329
*
1306
1330
* @example
@@ -1373,14 +1397,15 @@ class Stack {
1373
1397
}
1374
1398
/**
1375
1399
* @public
1376
- * @method includeAllReferences
1400
+ * @method includeReferences
1377
1401
* @description
1378
- * This method would return all the references of your queried entries (until depth 4 )
1379
- * Note: If you wish to increase the depth of the references fetched, call .referenceDepth()
1402
+ * This method would return all the references of your queried entries (until depth 2 )
1403
+ * Note: If you wish to increase the depth of the references fetched, call pass a numeric parameter
1380
1404
* @example
1381
- * Stack.contentType('blog')
1405
+ * Stack
1406
+ * .contentType('blog')
1382
1407
* .entries()
1383
- * .includeAllReferences( )
1408
+ * .includeReferences(3 )
1384
1409
* @returns {Stack } Returns 'this' instance (of Stack)
1385
1410
*/
1386
1411
includeReferences ( depth ) {
@@ -1396,7 +1421,7 @@ class Stack {
1396
1421
* @method include
1397
1422
* @description
1398
1423
* Pass in reference field uids, that you want included in your result.
1399
- * If you want all the references, use .includeAllReferences ()
1424
+ * If you want all the references, use .includeReferences ()
1400
1425
* @example
1401
1426
* Stack.contentType('blog')
1402
1427
* .entries()
@@ -1528,6 +1553,7 @@ class Stack {
1528
1553
/**
1529
1554
* @public
1530
1555
* @method findOne
1556
+ * @deprecated - Use .fetch() instead
1531
1557
* @description
1532
1558
* Queries the db using the query built/passed. Returns a single entry/asset/content type object
1533
1559
* Does all the processing, filtering, referencing after querying the DB
@@ -1545,6 +1571,26 @@ class Stack {
1545
1571
this . internal . single = true ;
1546
1572
return this . find ( query ) ;
1547
1573
}
1574
+ /**
1575
+ * @public
1576
+ * @method fetch
1577
+ * @description
1578
+ * Queries the db using the query built/passed. Returns a single entry/asset/content type object
1579
+ * Does all the processing, filtering, referencing after querying the DB
1580
+ * @param {object } query Optional query object, that overrides all the previously build queries
1581
+ *
1582
+ * @example
1583
+ * Stack
1584
+ * .contentType('blog')
1585
+ * .entries()
1586
+ * .fetch()
1587
+ *
1588
+ * @returns {object } - Returns an object, that has been processed, filtered and referenced
1589
+ */
1590
+ fetch ( query = { } ) {
1591
+ this . internal . single = true ;
1592
+ return this . find ( query ) ;
1593
+ }
1548
1594
/**
1549
1595
* @private
1550
1596
* @method preProcess
@@ -1708,11 +1754,10 @@ class Stack {
1708
1754
_assets : 1 ,
1709
1755
_id : 0 ,
1710
1756
} ) ;
1711
- if ( schema === null ) {
1757
+ if ( schema === null || schema [ this . types . assets ] !== 'object' ) {
1712
1758
return ;
1713
1759
}
1714
- const assetPaths = schema . _assets ;
1715
- const paths = Object . keys ( assetPaths ) ;
1760
+ const paths = Object . keys ( schema [ this . types . assets ] ) ;
1716
1761
const shelf = [ ] ;
1717
1762
const queryBucket = {
1718
1763
$or : [ ] ,
@@ -1759,22 +1804,6 @@ class Stack {
1759
1804
_content_type_uid : this . types . content_types ,
1760
1805
uid : contentTypeUid ,
1761
1806
} ;
1762
- /**
1763
- * key: {
1764
- * $in_query: {
1765
- * $or: [
1766
- * {
1767
- * range: { $in: [10, 100] }
1768
- * },
1769
- * {
1770
- * key2: {
1771
- * $in_query: ...
1772
- * }
1773
- * }
1774
- * ]
1775
- * }
1776
- * }
1777
- */
1778
1807
const { paths, // ref. fields in the current content types
1779
1808
pendingPath, // left over of *paths*
1780
1809
schemaList, } = yield this . getReferencePath ( ctQuery , locale , include ) ;
@@ -1943,9 +1972,9 @@ class Stack {
1943
1972
let entryReferences = { } ;
1944
1973
schemas . forEach ( ( schema ) => {
1945
1974
// Entry references
1946
- entryReferences = lodash_1 . merge ( entryReferences , schema . _references ) ;
1975
+ entryReferences = lodash_1 . merge ( entryReferences , schema [ this . types . references ] ) ;
1947
1976
// tslint:disable-next-line: forin
1948
- for ( const path in schema . _assets ) {
1977
+ for ( const path in schema [ this . types . assets ] ) {
1949
1978
paths . push ( path ) ;
1950
1979
}
1951
1980
} ) ;
@@ -2126,23 +2155,23 @@ class Stack {
2126
2155
let assetFieldPaths ;
2127
2156
let entryReferencePaths ;
2128
2157
if ( contents [ i ] . hasOwnProperty ( this . types . assets ) ) {
2129
- assetFieldPaths = Object . keys ( contents [ i ] . _assets ) ;
2158
+ assetFieldPaths = Object . keys ( contents [ i ] [ this . types . assets ] ) ;
2130
2159
paths = paths . concat ( assetFieldPaths ) ;
2131
2160
}
2132
2161
if ( contents [ i ] . hasOwnProperty ( '_references' ) ) {
2133
- entryReferencePaths = Object . keys ( contents [ i ] . _references ) ;
2162
+ entryReferencePaths = Object . keys ( contents [ i ] [ this . types . references ] ) ;
2134
2163
paths = paths . concat ( entryReferencePaths ) ;
2135
2164
for ( let k = 0 , l = entryReferencePaths . length ; k < l ; k ++ ) {
2136
- if ( typeof contents [ i ] . _references [ entryReferencePaths [ k ] ] === 'string' ) {
2165
+ if ( typeof contents [ i ] [ this . types . references ] [ entryReferencePaths [ k ] ] === 'string' ) {
2137
2166
ctQueries . $or . push ( {
2138
2167
_content_type_uid : this . types . content_types ,
2139
2168
// this would probably make it slow in FS, avoid this there?
2140
2169
// locale,
2141
- uid : contents [ i ] . _references [ entryReferencePaths [ k ] ] ,
2170
+ uid : contents [ i ] [ this . types . references ] [ entryReferencePaths [ k ] ] ,
2142
2171
} ) ;
2143
2172
}
2144
- else if ( contents [ i ] . _references [ entryReferencePaths [ k ] ] . length ) {
2145
- contents [ i ] . _references [ entryReferencePaths [ k ] ] . forEach ( ( uid ) => {
2173
+ else if ( contents [ i ] [ this . types . references ] [ entryReferencePaths [ k ] ] . length ) {
2174
+ contents [ i ] [ this . types . references ] [ entryReferencePaths [ k ] ] . forEach ( ( uid ) => {
2146
2175
ctQueries . $or . push ( {
2147
2176
_content_type_uid : this . types . content_types ,
2148
2177
// avoiding locale here, not sure if its required
0 commit comments