5
5
* MIT Licensed
6
6
*/
7
7
var __awaiter = ( this && this . __awaiter ) || function ( thisArg , _arguments , P , generator ) {
8
+ function adopt ( value ) { return value instanceof P ? value : new P ( function ( resolve ) { resolve ( value ) ; } ) ; }
8
9
return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
9
10
function fulfilled ( value ) { try { step ( generator . next ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
10
11
function rejected ( value ) { try { step ( generator [ "throw" ] ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
11
- function step ( result ) { result . done ? resolve ( result . value ) : new P ( function ( resolve ) { resolve ( result . value ) ; } ) . then ( fulfilled , rejected ) ; }
12
+ function step ( result ) { result . done ? resolve ( result . value ) : adopt ( result . value ) . then ( fulfilled , rejected ) ; }
12
13
step ( ( generator = generator . apply ( thisArg , _arguments || [ ] ) ) . next ( ) ) ;
13
14
} ) ;
14
15
} ;
15
16
var __importDefault = ( this && this . __importDefault ) || function ( mod ) {
16
17
return ( mod && mod . __esModule ) ? mod : { "default" : mod } ;
17
18
} ;
18
19
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
20
+ exports . Stack = void 0 ;
19
21
const lodash_1 = require ( "lodash" ) ;
20
22
const mongodb_1 = require ( "mongodb" ) ;
21
23
const sift_1 = __importDefault ( require ( "sift" ) ) ;
@@ -30,9 +32,9 @@ const util_1 = require("./util");
30
32
*/
31
33
class Stack {
32
34
constructor ( stackConfig , existingDB ) {
33
- this . config = lodash_1 . merge ( config_1 . config , stackConfig ) ;
35
+ this . config = ( 0 , lodash_1 . merge ) ( config_1 . config , stackConfig ) ;
34
36
// validates config.locales property
35
- util_1 . validateConfig ( this . config ) ;
37
+ ( 0 , util_1 . validateConfig ) ( this . config ) ;
36
38
this . contentStore = this . config . contentStore ;
37
39
this . collectionNames = this . contentStore . collection ;
38
40
this . types = this . contentStore . internal . types ;
@@ -137,8 +139,8 @@ class Stack {
137
139
*/
138
140
connect ( overrides = { } ) {
139
141
return __awaiter ( this , void 0 , void 0 , function * ( ) {
140
- const dbConfig = lodash_1 . merge ( { } , this . config , overrides ) . contentStore ;
141
- const url = util_1 . validateURI ( dbConfig . url ) ;
142
+ const dbConfig = ( 0 , lodash_1 . merge ) ( { } , this . config , overrides ) . contentStore ;
143
+ const url = ( 0 , util_1 . validateURI ) ( dbConfig . url ) ;
142
144
const options = dbConfig . options ;
143
145
const dbName = dbConfig . dbName ;
144
146
const client = new mongodb_1 . MongoClient ( url , options ) ;
@@ -218,7 +220,7 @@ class Stack {
218
220
throw new Error ( 'Kindly provide valid parameters for .and()!' ) ;
219
221
}
220
222
else if ( this . q . query && typeof this . q . query === 'object' ) {
221
- this . q . query = lodash_1 . merge ( this . q . query , {
223
+ this . q . query = ( 0 , lodash_1 . merge ) ( this . q . query , {
222
224
$and : queries ,
223
225
} ) ;
224
226
}
@@ -262,7 +264,7 @@ class Stack {
262
264
throw new Error ( 'Kindly provide valid parameters for .or()!' ) ;
263
265
}
264
266
else if ( this . q . query && typeof this . q . query === 'object' ) {
265
- this . q . query = lodash_1 . merge ( this . q . query , {
267
+ this . q . query = ( 0 , lodash_1 . merge ) ( this . q . query , {
266
268
$or : queries ,
267
269
} ) ;
268
270
}
@@ -1011,7 +1013,7 @@ class Stack {
1011
1013
*/
1012
1014
query ( queryObject = { } ) {
1013
1015
if ( this . q . query && typeof this . q . query === 'object' ) {
1014
- this . q . query = lodash_1 . merge ( this . q . query , queryObject ) ;
1016
+ this . q . query = ( 0 , lodash_1 . merge ) ( this . q . query , queryObject ) ;
1015
1017
}
1016
1018
else {
1017
1019
this . q . query = queryObject ;
@@ -1086,7 +1088,7 @@ class Stack {
1086
1088
this . internal . except [ field ] = 0 ;
1087
1089
}
1088
1090
} ) ;
1089
- this . internal . except = lodash_1 . merge ( this . contentStore . projections , this . internal . except ) ;
1091
+ this . internal . except = ( 0 , lodash_1 . merge ) ( this . contentStore . projections , this . internal . except ) ;
1090
1092
return this ;
1091
1093
}
1092
1094
/**
@@ -1118,7 +1120,7 @@ class Stack {
1118
1120
throw new Error ( 'Kindly provide a valid field and pattern value for \'.regex()\'' ) ;
1119
1121
}
1120
1122
else if ( this . q . query && typeof this . q . query === 'object' ) {
1121
- this . q . query = lodash_1 . merge ( this . q . query , {
1123
+ this . q . query = ( 0 , lodash_1 . merge ) ( this . q . query , {
1122
1124
[ field ] : {
1123
1125
$options : options ,
1124
1126
$regex : pattern ,
@@ -1161,7 +1163,7 @@ class Stack {
1161
1163
throw new Error ( 'Kindly provide valid \'field\' values for \'tags()\'' ) ;
1162
1164
}
1163
1165
// filter non-string keys
1164
- lodash_1 . remove ( values , ( value ) => {
1166
+ ( 0 , lodash_1 . remove ) ( values , ( value ) => {
1165
1167
return typeof value !== 'string' ;
1166
1168
} ) ;
1167
1169
this . q . query = this . q . query || { } ;
@@ -1217,7 +1219,7 @@ class Stack {
1217
1219
if ( typeof expr === 'function' ) {
1218
1220
expr = expr . toString ( ) ;
1219
1221
}
1220
- this . q . query = lodash_1 . merge ( this . q . query , {
1222
+ this . q . query = ( 0 , lodash_1 . merge ) ( this . q . query , {
1221
1223
$where : expr ,
1222
1224
} ) ;
1223
1225
}
@@ -1489,7 +1491,7 @@ class Stack {
1489
1491
yield this . includeAssetsOnly ( result , this . q . content_type_uid , this . q . locale ) ;
1490
1492
}
1491
1493
if ( this . internal . queryReferences ) {
1492
- result = result . filter ( sift_1 . default ( this . internal . queryReferences ) ) ;
1494
+ result = result . filter ( ( 0 , sift_1 . default ) ( this . internal . queryReferences ) ) ;
1493
1495
if ( this . internal . skip ) {
1494
1496
result = result . splice ( this . internal . skip , this . internal . limit ) ;
1495
1497
}
@@ -1583,7 +1585,7 @@ class Stack {
1583
1585
preProcess ( query ) {
1584
1586
let queryFilters ;
1585
1587
if ( this . q . query && typeof this . q . query === 'object' ) {
1586
- this . q . query = lodash_1 . merge ( this . q . query , query ) ;
1588
+ this . q . query = ( 0 , lodash_1 . merge ) ( this . q . query , query ) ;
1587
1589
}
1588
1590
else {
1589
1591
this . q . query = { } ;
@@ -1594,7 +1596,7 @@ class Stack {
1594
1596
this . internal . projections = this . internal . only ;
1595
1597
}
1596
1598
else {
1597
- this . internal . projections = lodash_1 . merge ( this . contentStore . projections , this . internal . except ) ;
1599
+ this . internal . projections = ( 0 , lodash_1 . merge ) ( this . contentStore . projections , this . internal . except ) ;
1598
1600
}
1599
1601
// set default limit, if .limit() hasn't been called
1600
1602
if ( ! ( this . internal . limit ) ) {
@@ -1631,7 +1633,7 @@ class Stack {
1631
1633
else {
1632
1634
queryFilters = filters ;
1633
1635
}
1634
- this . collection = this . db . collection ( util_1 . getCollectionName ( {
1636
+ this . collection = this . db . collection ( ( 0 , util_1 . getCollectionName ) ( {
1635
1637
content_type_uid : this . q . content_type_uid ,
1636
1638
locale : this . q . locale ,
1637
1639
} , this . collectionNames ) ) ;
@@ -1696,7 +1698,7 @@ class Stack {
1696
1698
break ;
1697
1699
}
1698
1700
if ( this . internal . includeCount ) {
1699
- output . count = yield this . db . collection ( util_1 . getCollectionName ( {
1701
+ output . count = yield this . db . collection ( ( 0 , util_1 . getCollectionName ) ( {
1700
1702
content_type_uid : this . q . content_type_uid ,
1701
1703
locale : this . q . locale ,
1702
1704
} , this . collectionNames ) )
@@ -1705,17 +1707,19 @@ class Stack {
1705
1707
} ) ;
1706
1708
}
1707
1709
if ( this . internal . includeSchema ) {
1708
- output . content_type = yield this . db . collection ( util_1 . getCollectionName ( {
1710
+ output . content_type = yield this . db . collection ( ( 0 , util_1 . getCollectionName ) ( {
1709
1711
content_type_uid : this . types . content_types ,
1710
1712
locale : this . q . locale ,
1711
1713
} , this . collectionNames ) )
1712
1714
. findOne ( {
1713
1715
uid : this . q . content_type_uid ,
1714
1716
} , {
1715
- _assets : 0 ,
1716
- _content_type_uid : 0 ,
1717
- _id : 0 ,
1718
- _references : 0 ,
1717
+ projection : {
1718
+ _assets : 0 ,
1719
+ _content_type_uid : 0 ,
1720
+ _id : 0 ,
1721
+ _references : 0 ,
1722
+ }
1719
1723
} ) ;
1720
1724
}
1721
1725
this . cleanup ( ) ;
@@ -1725,16 +1729,18 @@ class Stack {
1725
1729
includeAssetsOnly ( entries , contentTypeUid , locale ) {
1726
1730
return __awaiter ( this , void 0 , void 0 , function * ( ) {
1727
1731
const schema = yield this . db
1728
- . collection ( util_1 . getCollectionName ( {
1732
+ . collection ( ( 0 , util_1 . getCollectionName ) ( {
1729
1733
content_type_uid : this . types . content_types ,
1730
1734
locale,
1731
1735
} , this . collectionNames ) )
1732
1736
. findOne ( {
1733
1737
_content_type_uid : this . types . content_types ,
1734
1738
uid : contentTypeUid ,
1735
1739
} , {
1736
- _assets : 1 ,
1737
- _id : 0 ,
1740
+ projection : {
1741
+ _assets : 1 ,
1742
+ _id : 0 ,
1743
+ }
1738
1744
} ) ;
1739
1745
if ( schema === null || schema [ this . types . assets ] !== 'object' ) {
1740
1746
return ;
@@ -1750,7 +1756,7 @@ class Stack {
1750
1756
if ( shelf . length === 0 ) {
1751
1757
return ;
1752
1758
}
1753
- const assets = yield this . db . collection ( util_1 . getCollectionName ( {
1759
+ const assets = yield this . db . collection ( ( 0 , util_1 . getCollectionName ) ( {
1754
1760
content_type_uid : this . types . assets ,
1755
1761
locale,
1756
1762
} , this . collectionNames ) )
@@ -1788,7 +1794,8 @@ class Stack {
1788
1794
} ;
1789
1795
const { paths, // ref. fields in the current content types
1790
1796
pendingPath, // left over of *paths*
1791
- schemaList, } = yield this . getReferencePath ( ctQuery , locale , include ) ;
1797
+ schemaList, // list of content type uids, the current content types refer to
1798
+ } = yield this . getReferencePath ( ctQuery , locale , include ) ;
1792
1799
const queries = {
1793
1800
$or : [ ] ,
1794
1801
} ; // reference field paths
@@ -1892,7 +1899,7 @@ class Stack {
1892
1899
bindLeftoverAssets ( queries , locale , pointerList ) {
1893
1900
return __awaiter ( this , void 0 , void 0 , function * ( ) {
1894
1901
// const contents = await readFile(getAssetsPath(locale) + '.json')
1895
- const filteredAssets = yield this . db . collection ( util_1 . getCollectionName ( {
1902
+ const filteredAssets = yield this . db . collection ( ( 0 , util_1 . getCollectionName ) ( {
1896
1903
content_type_uid : this . types . assets ,
1897
1904
locale,
1898
1905
} , this . collectionNames ) )
@@ -1955,7 +1962,7 @@ class Stack {
1955
1962
}
1956
1963
getReferencePath ( query , locale , currentInclude ) {
1957
1964
return __awaiter ( this , void 0 , void 0 , function * ( ) {
1958
- const schemas = yield this . db . collection ( util_1 . getCollectionName ( {
1965
+ const schemas = yield this . db . collection ( ( 0 , util_1 . getCollectionName ) ( {
1959
1966
content_type_uid : this . types . content_types ,
1960
1967
locale,
1961
1968
} , this . collectionNames ) )
@@ -1982,7 +1989,7 @@ class Stack {
1982
1989
let entryReferences = { } ;
1983
1990
schemas . forEach ( ( schema ) => {
1984
1991
// Entry references
1985
- entryReferences = lodash_1 . merge ( entryReferences , schema [ this . types . references ] ) ;
1992
+ entryReferences = ( 0 , lodash_1 . merge ) ( entryReferences , schema [ this . types . references ] ) ;
1986
1993
// tslint:disable-next-line: forin
1987
1994
for ( const path in schema [ this . types . assets ] ) {
1988
1995
paths . push ( path ) ;
@@ -2035,7 +2042,7 @@ class Stack {
2035
2042
}
2036
2043
fetchEntries ( query , locale , paths , include , includeAll = false ) {
2037
2044
return __awaiter ( this , void 0 , void 0 , function * ( ) {
2038
- const result = yield this . db . collection ( util_1 . getCollectionName ( {
2045
+ const result = yield this . db . collection ( ( 0 , util_1 . getCollectionName ) ( {
2039
2046
content_type_uid : 'entries' ,
2040
2047
locale,
2041
2048
} , this . collectionNames ) )
@@ -2085,7 +2092,8 @@ class Stack {
2085
2092
} ] ,
2086
2093
} ;
2087
2094
const { paths, // ref. fields in the current content types
2088
- ctQueries, } = yield this . getAllReferencePaths ( ctQuery , locale ) ;
2095
+ ctQueries, // list of content type uids, the current content types refer to
2096
+ } = yield this . getAllReferencePaths ( ctQuery , locale ) ;
2089
2097
const queries = {
2090
2098
$or : [ ] ,
2091
2099
} ; // reference field paths
@@ -2151,7 +2159,7 @@ class Stack {
2151
2159
getAllReferencePaths ( contentTypeQueries , locale ) {
2152
2160
return __awaiter ( this , void 0 , void 0 , function * ( ) {
2153
2161
const contents = yield this . db
2154
- . collection ( util_1 . getCollectionName ( {
2162
+ . collection ( ( 0 , util_1 . getCollectionName ) ( {
2155
2163
content_type_uid : this . types . content_types ,
2156
2164
locale,
2157
2165
} , this . collectionNames ) )
0 commit comments