@@ -512,7 +512,7 @@ export class Stack {
512
512
}
513
513
514
514
if ( uid && typeof uid === 'string' ) {
515
- this . q . query [ uid ] = uid
515
+ this . q . query . uid = uid
516
516
}
517
517
518
518
return this
@@ -535,7 +535,7 @@ export class Stack {
535
535
stack . q . isSingle = true
536
536
stack . q . content_type_uid = stack . types . assets
537
537
if ( uid && typeof uid === 'string' ) {
538
- stack . q . query [ uid ] = uid
538
+ stack . q . query . uid = uid
539
539
}
540
540
541
541
return stack
@@ -605,7 +605,7 @@ export class Stack {
605
605
stack . q . isSingle = true
606
606
stack . q . content_type_uid = stack . types . content_types
607
607
if ( uid && typeof uid === 'string' ) {
608
- stack . q . query [ uid ] = uid
608
+ stack . q . query . uid = uid
609
609
}
610
610
611
611
return stack
@@ -726,8 +726,14 @@ export class Stack {
726
726
*/
727
727
public tags ( values ) {
728
728
if ( values && typeof values === 'object' && values instanceof Array ) {
729
- this . q . query . tags = {
730
- $in : values ,
729
+ if ( values . length === 0 ) {
730
+ this . q . query . tags = {
731
+ $size : 0 ,
732
+ }
733
+ } else {
734
+ this . q . query . tags = {
735
+ $in : values ,
736
+ }
731
737
}
732
738
733
739
return this
@@ -1323,7 +1329,11 @@ export class Stack {
1323
1329
1324
1330
private async includeReferenceIteration ( eQuery : any , ctQuery : any , locale : string , include : string [ ] , oldShelf :
1325
1331
IShelf [ ] ) {
1326
- if ( oldShelf . length === 0 || ctQuery . $or . length === 0 ) {
1332
+ if ( oldShelf . length === 0 ) {
1333
+ return
1334
+ } else if ( ctQuery . $or . length === 0 && eQuery . $or . length > 0 ) {
1335
+ await this . bindLeftoverAssets ( eQuery , locale , oldShelf )
1336
+
1327
1337
return
1328
1338
}
1329
1339
@@ -1680,11 +1690,41 @@ export class Stack {
1680
1690
return this . includeAllReferencesIteration ( queries , ctQueries , locale , objectPointerList )
1681
1691
}
1682
1692
1693
+ private async bindLeftoverAssets ( queries : IQuery , locale : string , pointerList : IShelf [ ] ) {
1694
+ const contents = await readFile ( getAssetsPath ( locale ) + '.json' )
1695
+ const filteredAssets = contents . filter ( sift ( queries ) )
1696
+
1697
+ filteredAssets . forEach ( ( doc ) => {
1698
+ this . projections . forEach ( ( key ) => {
1699
+ if ( doc . hasOwnProperty ( key ) ) {
1700
+ delete doc [ key ]
1701
+ }
1702
+ } )
1703
+ } )
1704
+
1705
+ for ( let l = 0 , m = pointerList . length ; l < m ; l ++ ) {
1706
+ for ( let n = 0 , o = filteredAssets . length ; n < o ; n ++ ) {
1707
+ if ( pointerList [ l ] . uid === filteredAssets [ n ] . uid ) {
1708
+ pointerList [ l ] . path [ pointerList [ l ] . position ] = filteredAssets [ n ]
1709
+ break
1710
+ }
1711
+ }
1712
+ }
1713
+
1714
+ return
1715
+ }
1716
+
1683
1717
// tslint:disable-next-line: max-line-length
1684
1718
private async includeAllReferencesIteration ( oldEntryQueries : IQuery , oldCtQueries : IQuery , locale : string , oldObjectPointerList : IShelf [ ] , depth = 0 ) {
1685
- if ( depth > this . q . referenceDepth || oldObjectPointerList . length === 0 || oldCtQueries . $or . length === 0 ) {
1719
+ if ( depth > this . q . referenceDepth || oldObjectPointerList . length === 0 ) {
1720
+ return
1721
+ } else if ( oldCtQueries . $or . length === 0 && oldObjectPointerList . length > 0 && oldEntryQueries . $or . length > 0 ) {
1722
+ // its most likely only assets
1723
+ await this . bindLeftoverAssets ( oldEntryQueries , locale , oldObjectPointerList )
1724
+
1686
1725
return
1687
1726
}
1727
+
1688
1728
const {
1689
1729
ctQueries,
1690
1730
paths,
0 commit comments