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
81 changes: 46 additions & 35 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.3.1",
"version": "1.4.0",
"description": "JavaScript filesystem SDK to query data synced via @contentstack/datasync-content-store-filesystem",
"main": "dist/index.js",
"scripts": {
Expand Down
60 changes: 43 additions & 17 deletions src/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1232,32 +1232,58 @@ export class Stack {
* @returns {this} - Returns stack instance
*/
private processOverlappingPaths(pathAnalysis: any): Stack {
// Start with independent paths (if any)
// Collect ALL paths first
const allPaths: string[] = []

// Add independent paths
if (pathAnalysis.independentPaths.length > 0) {
this.q.includeSpecificReferences = pathAnalysis.independentPaths
allPaths.push(...pathAnalysis.independentPaths)
}

// Process each overlapping group by using the most specific path
// Add all paths from overlapping groups
pathAnalysis.overlappingGroups.forEach((group: string[]) => {
// Sort group by length (longest/most specific first)
const sortedGroup = group.sort((a, b) => b.length - a.length)

// Use the most specific path from each group
const mostSpecificPath = sortedGroup[0]

// If this is the first group and we have no independent paths,
// set the includeSpecificReferences
if (!this.q.includeSpecificReferences) {
this.q.includeSpecificReferences = [mostSpecificPath]
} else {
// Add the most specific path to existing references
this.q.includeSpecificReferences.push(mostSpecificPath)
}
allPaths.push(...group)
})

// Remove exact duplicates
const uniquePaths = [...new Set(allPaths)]

// Smart filtering: remove parent paths that are fully covered by child paths
const filteredPaths = this.removeRedundantPaths(uniquePaths)

this.q.includeSpecificReferences = filteredPaths
return this
}

/**
* @private
* @method removeRedundantPaths
* @description Removes parent paths that are fully covered by more specific child paths
* Example: ["content", "content.content"] → ["content.content"]
* But keeps: ["form", "form.fields", "form.fields.rules"] → all three (not redundant)
*/
private removeRedundantPaths(paths: string[]): string[] {
// Sort by length (longest first) to prioritize more specific paths
const sortedPaths = paths.sort((a, b) => b.length - a.length)
const result: string[] = []

for (const currentPath of sortedPaths) {
// Check if this path is made redundant by a more specific path already in result
const isRedundant = result.some(existingPath => {
// Check if currentPath is a direct parent of existingPath
return existingPath.startsWith(currentPath + '.') &&
existingPath.split('.').length === currentPath.split('.').length + 1
})

if (!isRedundant) {
result.push(currentPath)
}
}

return result
}


/**
* @private
* @method preProcess
Expand Down
8 changes: 8 additions & 0 deletions typings/stack.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,14 @@ export declare class Stack {
* @returns {this} - Returns stack instance
*/
private processOverlappingPaths;
/**
* @private
* @method removeRedundantPaths
* @description Removes parent paths that are fully covered by more specific child paths
* Example: ["content", "content.content"] → ["content.content"]
* But keeps: ["form", "form.fields", "form.fields.rules"] → all three (not redundant)
*/
private removeRedundantPaths;
/**
* @private
* @method preProcess
Expand Down
Loading