Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/datasync-filesystem-sdk",
"version": "1.4.0",
"version": "1.5.0",
"description": "JavaScript filesystem SDK to query data synced via @contentstack/datasync-content-store-filesystem",
"main": "dist/index.js",
"scripts": {
Expand Down
44 changes: 24 additions & 20 deletions src/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,26 @@ export class Stack {
}
}

/**
* @private
* @method addToShelfIfNotExists
* @description Helper function to add entry to shelf only if it doesn't already exist
* @param {IShelf[]} shelf - The shelf array to add to
* @param {any} path - The path reference
* @param {number} position - The position in the path
* @param {string} uid - The unique identifier
*/
private addToShelfIfNotExists(shelf: IShelf[], path, position, uid) {
const exists = shelf.some(entry =>
entry.path === path &&
entry.position === position &&
entry.uid === uid
);
if (!exists) {
shelf.push({ path, position, uid });
}
}

// tslint:disable-next-line: max-line-length
private fetchPathDetails(data: any, locale: string, pathArr: string[], queryBucket: IQuery, shelf, assetsOnly = false, parent, pos, counter = 0) {
if (counter === (pathArr.length)) {
Expand All @@ -1641,23 +1661,15 @@ export class Stack {
uid: elem,
})

shelf.push({
path: data,
position: idx,
uid: elem,
})
this.addToShelfIfNotExists(shelf, data, idx, elem);
} else if (elem && typeof elem === 'object' && elem.hasOwnProperty('_content_type_uid')) {
queryBucket.$or.push({
_content_type_uid: elem._content_type_uid,
locale,
uid: elem.uid,
})

shelf.push({
path: data,
position: idx,
uid: elem.uid,
})
this.addToShelfIfNotExists(shelf, data, idx, elem.uid);
}
})
} else if (typeof data === 'object') {
Expand All @@ -1668,11 +1680,7 @@ export class Stack {
uid: data.uid,
})

shelf.push({
path: parent,
position: pos,
uid: data.uid,
})
this.addToShelfIfNotExists(shelf, parent, pos, data.uid);
}
}
} else if (typeof data === 'string') {
Expand All @@ -1683,11 +1691,7 @@ export class Stack {
uid: data,
})

shelf.push({
path: parent,
position: pos,
uid: data,
})
this.addToShelfIfNotExists(shelf, parent, pos, data);
}
} else {
const currentField = pathArr[counter]
Expand Down
10 changes: 10 additions & 0 deletions typings/stack.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,16 @@ export declare class Stack {
private includeReferenceIteration;
private subIncludeReferenceIteration;
private getReferencePath;
/**
* @private
* @method addToShelfIfNotExists
* @description Helper function to add entry to shelf only if it doesn't already exist
* @param {IShelf[]} shelf - The shelf array to add to
* @param {any} path - The path reference
* @param {number} position - The position in the path
* @param {string} uid - The unique identifier
*/
private addToShelfIfNotExists;
private fetchPathDetails;
private fetchDocuments;
private includeAssetsOnly;
Expand Down
Loading