Skip to content

Commit 14f1eee

Browse files
committed
#1, #2 and #3 issues bug fixes
1 parent 25400dd commit 14f1eee

File tree

4 files changed

+50
-8
lines changed

4 files changed

+50
-8
lines changed

example/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ function connect () {
1414
function find (contentType = 'blog') {
1515
return Stack.contentType(contentType)
1616
.entries()
17+
.includeReferences()
1718
.find()
1819
}
1920

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "datasync-filesystem-sdk",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "JavaScript filesystem SDK to query data synced via @contentstack/datasync-content-store-filesystem",
55
"main": "dist/index.js",
66
"scripts": {

src/stack.ts

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ export class Stack {
512512
}
513513

514514
if (uid && typeof uid === 'string') {
515-
this.q.query[uid] = uid
515+
this.q.query.uid = uid
516516
}
517517

518518
return this
@@ -535,7 +535,7 @@ export class Stack {
535535
stack.q.isSingle = true
536536
stack.q.content_type_uid = stack.types.assets
537537
if (uid && typeof uid === 'string') {
538-
stack.q.query[uid] = uid
538+
stack.q.query.uid = uid
539539
}
540540

541541
return stack
@@ -605,7 +605,7 @@ export class Stack {
605605
stack.q.isSingle = true
606606
stack.q.content_type_uid = stack.types.content_types
607607
if (uid && typeof uid === 'string') {
608-
stack.q.query[uid] = uid
608+
stack.q.query.uid = uid
609609
}
610610

611611
return stack
@@ -726,8 +726,14 @@ export class Stack {
726726
*/
727727
public tags(values) {
728728
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+
}
731737
}
732738

733739
return this
@@ -1323,7 +1329,11 @@ export class Stack {
13231329

13241330
private async includeReferenceIteration(eQuery: any, ctQuery: any, locale: string, include: string[], oldShelf:
13251331
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+
13271337
return
13281338
}
13291339

@@ -1680,11 +1690,41 @@ export class Stack {
16801690
return this.includeAllReferencesIteration(queries, ctQueries, locale, objectPointerList)
16811691
}
16821692

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+
16831717
// tslint:disable-next-line: max-line-length
16841718
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+
16861725
return
16871726
}
1727+
16881728
const {
16891729
ctQueries,
16901730
paths,

typings/stack.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ export declare class Stack {
527527
private fetchDocuments;
528528
private includeAssetsOnly;
529529
private bindReferences;
530+
private bindLeftoverAssets;
530531
private includeAllReferencesIteration;
531532
private subIncludeAllReferencesIteration;
532533
private getAllReferencePaths;

0 commit comments

Comments
 (0)