jsonldjs 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -3
- package/builder-utils.d.ts +4 -0
- package/builder-utils.js +11 -14
- package/builder.d.ts +0 -4
- package/builder.js +3 -11
- package/config.d.ts +11 -1
- package/config.js +46 -8
- package/esm/builder-utils.js +11 -15
- package/esm/builder.js +4 -12
- package/esm/config.js +46 -8
- package/package.json +1 -1
- package/types.d.ts +12 -8
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@ const blogConfig = globalConfig.includeTypes(['Article']);
|
|
|
63
63
|
|
|
64
64
|
// Use configurations
|
|
65
65
|
const result = createJsonLdBuilder()
|
|
66
|
-
.
|
|
66
|
+
.mergeConfig(homeConfig.getConfig())
|
|
67
67
|
.excludeIds(['runtime:override']) // Runtime overrides
|
|
68
68
|
.build({ prettyPrint: true });
|
|
69
69
|
```
|
|
@@ -122,7 +122,7 @@ const config = createJsonLdConfig()
|
|
|
122
122
|
Creates a new builder that extends the configuration builder with graph processing capabilities.
|
|
123
123
|
|
|
124
124
|
```typescript
|
|
125
|
-
const builder = createJsonLdBuilder().baseGraph(graph).
|
|
125
|
+
const builder = createJsonLdBuilder().baseGraph(graph).mergeConfig(config);
|
|
126
126
|
```
|
|
127
127
|
|
|
128
128
|
### Configuration Methods
|
|
@@ -149,6 +149,37 @@ All methods are inherited by the builder from the configuration builder:
|
|
|
149
149
|
- `.clearSubgraph()` - Clear subgraphRoots
|
|
150
150
|
- `.clearAll()` - Clear entire configuration (except baseGraph)
|
|
151
151
|
|
|
152
|
+
#### Configuration Merging
|
|
153
|
+
|
|
154
|
+
- `.mergeConfig(config: JsonLdConfig)` - Merge with another complete configuration
|
|
155
|
+
- `.mergeFilters(filters: JsonLdFilterOptions)` - Merge only the filters part of another configuration
|
|
156
|
+
|
|
157
|
+
**Available in both config builder and main builder** - These methods work the same way in both classes.
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
// Config builder usage
|
|
161
|
+
const baseConfig = createJsonLdConfig().includeTypes(['Person']);
|
|
162
|
+
const otherConfig = createJsonLdConfig()
|
|
163
|
+
.includeTypes(['Organization'])
|
|
164
|
+
.excludeIds(['test'])
|
|
165
|
+
.getConfig();
|
|
166
|
+
const merged = baseConfig.mergeConfig(otherConfig);
|
|
167
|
+
// Result: includeTypes: ['Person', 'Organization'], excludeIds: ['test']
|
|
168
|
+
|
|
169
|
+
// Main builder usage (processes graph immediately)
|
|
170
|
+
const result = createJsonLdBuilder()
|
|
171
|
+
.baseGraph(graph)
|
|
172
|
+
.includeTypes(['Person'])
|
|
173
|
+
.mergeConfig(otherConfig)
|
|
174
|
+
.build({ prettyPrint: true });
|
|
175
|
+
|
|
176
|
+
// Merge only filters
|
|
177
|
+
const baseConfig = createJsonLdConfig().includeTypes(['Person']).addEntities([entity]);
|
|
178
|
+
const otherFilters = { includeTypes: ['Organization'], maxEntities: 10 };
|
|
179
|
+
const merged = baseConfig.mergeFilters(otherFilters);
|
|
180
|
+
// Result: includeTypes: ['Person', 'Organization'], maxEntities: 10, additionalEntities preserved
|
|
181
|
+
```
|
|
182
|
+
|
|
152
183
|
#### Property Filtering
|
|
153
184
|
|
|
154
185
|
- `.filterPropertiesByIds(entityIds, rule)` - Filter properties for specific entity IDs
|
|
@@ -175,7 +206,6 @@ All methods are inherited by the builder from the configuration builder:
|
|
|
175
206
|
|
|
176
207
|
#### Builder-Only Methods
|
|
177
208
|
|
|
178
|
-
- `.applyConfig(config: JsonLdConfig)` - Apply a pre-built configuration
|
|
179
209
|
- `.getCurrentGraph()` - Get the current graph state
|
|
180
210
|
- `.build(options?: BuildOptions)` - Build the final JSON-LD output
|
|
181
211
|
|
package/builder-utils.d.ts
CHANGED
|
@@ -10,6 +10,10 @@ import type { JsonLdConfig, JsonLdFilterOptions, PopulateConfig, PropertyFilterB
|
|
|
10
10
|
* Merge two configurations, with the second taking precedence
|
|
11
11
|
*/
|
|
12
12
|
export declare function mergeConfigs(base: JsonLdConfig, override: JsonLdConfig): JsonLdConfig;
|
|
13
|
+
/**
|
|
14
|
+
* Merge filter options, merging arrays and using override for single values
|
|
15
|
+
*/
|
|
16
|
+
export declare function mergeFilterOptions(base?: JsonLdFilterOptions, override?: JsonLdFilterOptions): JsonLdFilterOptions | undefined;
|
|
13
17
|
/**
|
|
14
18
|
* Convert property filter by ID rules to PropertyFilterConfig
|
|
15
19
|
*/
|
package/builder-utils.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.mergeConfigs = mergeConfigs;
|
|
10
|
+
exports.mergeFilterOptions = mergeFilterOptions;
|
|
10
11
|
exports.convertPropertyFiltersByIds = convertPropertyFiltersByIds;
|
|
11
12
|
exports.convertPropertyFiltersByTypes = convertPropertyFiltersByTypes;
|
|
12
13
|
exports.buildPropertyFilterConfig = buildPropertyFilterConfig;
|
|
@@ -26,14 +27,6 @@ function mergeConfigs(base, override) {
|
|
|
26
27
|
baseGraph: override.baseGraph ?? base.baseGraph,
|
|
27
28
|
// Filters: merge filter options
|
|
28
29
|
filters: mergeFilterOptions(base.filters, override.filters),
|
|
29
|
-
// Subgraph roots: override takes precedence
|
|
30
|
-
subgraphRoots: override.subgraphRoots ?? base.subgraphRoots,
|
|
31
|
-
// Property filters: combine arrays
|
|
32
|
-
propertyFilters: combinePropertyFilters(base.propertyFilters, override.propertyFilters),
|
|
33
|
-
// Property filters by IDs: combine arrays
|
|
34
|
-
propertyFiltersByIds: combineArrays(base.propertyFiltersByIds, override.propertyFiltersByIds),
|
|
35
|
-
// Property filters by types: combine arrays
|
|
36
|
-
propertyFiltersByTypes: combineArrays(base.propertyFiltersByTypes, override.propertyFiltersByTypes),
|
|
37
30
|
// Additional entities: combine arrays
|
|
38
31
|
additionalEntities: combineArrays(base.additionalEntities, override.additionalEntities),
|
|
39
32
|
// Pipes: combine arrays
|
|
@@ -60,6 +53,10 @@ function mergeFilterOptions(base, override) {
|
|
|
60
53
|
excludeIds: combineArrays(base.excludeIds, override.excludeIds),
|
|
61
54
|
requiredProperties: combineArrays(base.requiredProperties, override.requiredProperties),
|
|
62
55
|
excludeEntitiesWithProperties: combineArrays(base.excludeEntitiesWithProperties, override.excludeEntitiesWithProperties),
|
|
56
|
+
subgraphRoots: combineArrays(base.subgraphRoots, override.subgraphRoots),
|
|
57
|
+
propertyFilters: combinePropertyFilters(base.propertyFilters, override.propertyFilters),
|
|
58
|
+
propertyFiltersByIds: combineArrays(base.propertyFiltersByIds, override.propertyFiltersByIds),
|
|
59
|
+
propertyFiltersByTypes: combineArrays(base.propertyFiltersByTypes, override.propertyFiltersByTypes),
|
|
63
60
|
// Single values - override takes precedence
|
|
64
61
|
customFilter: override.customFilter ?? base.customFilter,
|
|
65
62
|
maxEntities: override.maxEntities ?? base.maxEntities,
|
|
@@ -115,16 +112,16 @@ function convertPropertyFiltersByTypes(rules) {
|
|
|
115
112
|
function buildPropertyFilterConfig(config) {
|
|
116
113
|
const filters = [];
|
|
117
114
|
// Add base property filters
|
|
118
|
-
if (config.propertyFilters) {
|
|
119
|
-
filters.push(...config.propertyFilters);
|
|
115
|
+
if (config.filters?.propertyFilters) {
|
|
116
|
+
filters.push(...config.filters.propertyFilters);
|
|
120
117
|
}
|
|
121
118
|
// Add property filters by IDs
|
|
122
|
-
if (config.propertyFiltersByIds) {
|
|
123
|
-
filters.push(...convertPropertyFiltersByIds(config.propertyFiltersByIds));
|
|
119
|
+
if (config.filters?.propertyFiltersByIds) {
|
|
120
|
+
filters.push(...convertPropertyFiltersByIds(config.filters.propertyFiltersByIds));
|
|
124
121
|
}
|
|
125
122
|
// Add property filters by types
|
|
126
|
-
if (config.propertyFiltersByTypes) {
|
|
127
|
-
filters.push(...convertPropertyFiltersByTypes(config.propertyFiltersByTypes));
|
|
123
|
+
if (config.filters?.propertyFiltersByTypes) {
|
|
124
|
+
filters.push(...convertPropertyFiltersByTypes(config.filters.propertyFiltersByTypes));
|
|
128
125
|
}
|
|
129
126
|
return filters.length > 0 ? filters : undefined;
|
|
130
127
|
}
|
package/builder.d.ts
CHANGED
|
@@ -18,10 +18,6 @@ export declare class JsonLdBuilder extends JsonLdConfigBuilder {
|
|
|
18
18
|
* Override the config builder's method creation to return JsonLdBuilder instances
|
|
19
19
|
*/
|
|
20
20
|
protected createInstance(config: JsonLdConfig): JsonLdBuilder;
|
|
21
|
-
/**
|
|
22
|
-
* Apply a pre-built configuration (builder-specific method)
|
|
23
|
-
*/
|
|
24
|
-
applyConfig(config: JsonLdConfig): JsonLdBuilder;
|
|
25
21
|
/**
|
|
26
22
|
* Get the current graph state (processes the graph if not already done)
|
|
27
23
|
*/
|
package/builder.js
CHANGED
|
@@ -25,14 +25,6 @@ class JsonLdBuilder extends config_1.JsonLdConfigBuilder {
|
|
|
25
25
|
createInstance(config) {
|
|
26
26
|
return new JsonLdBuilder(config);
|
|
27
27
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Apply a pre-built configuration (builder-specific method)
|
|
30
|
-
*/
|
|
31
|
-
applyConfig(config) {
|
|
32
|
-
const currentConfig = this.getConfig();
|
|
33
|
-
const mergedConfig = (0, builder_utils_1.mergeConfigs)(currentConfig, config);
|
|
34
|
-
return new JsonLdBuilder(mergedConfig);
|
|
35
|
-
}
|
|
36
28
|
/**
|
|
37
29
|
* Get the current graph state (processes the graph if not already done)
|
|
38
30
|
*/
|
|
@@ -75,7 +67,7 @@ class JsonLdBuilder extends config_1.JsonLdConfigBuilder {
|
|
|
75
67
|
processGraph() {
|
|
76
68
|
const config = this.getConfig();
|
|
77
69
|
if (!config.baseGraph) {
|
|
78
|
-
throw new Error('No base graph provided. Use baseGraph() or
|
|
70
|
+
throw new Error('No base graph provided. Use baseGraph() or mergeConfig() with a baseGraph.');
|
|
79
71
|
}
|
|
80
72
|
// Validate configuration - only check for critical errors that would break processing
|
|
81
73
|
const errors = (0, builder_utils_1.validateRuntimeConfig)(config);
|
|
@@ -86,9 +78,9 @@ class JsonLdBuilder extends config_1.JsonLdConfigBuilder {
|
|
|
86
78
|
const propertyFilters = (0, builder_utils_1.buildPropertyFilterConfig)(config);
|
|
87
79
|
let propertyFiltersApplied = false;
|
|
88
80
|
// Layer 1: Subgraph extraction with property filtering if subgraphRoots are set
|
|
89
|
-
if (config.subgraphRoots && config.subgraphRoots.length > 0) {
|
|
81
|
+
if (config.filters?.subgraphRoots && config.filters.subgraphRoots.length > 0) {
|
|
90
82
|
// Extract subgraph with property filtering during traversal
|
|
91
|
-
graph = (0, jsonld_utils_1.extractSubgraphs)(graph, config.subgraphRoots, propertyFilters);
|
|
83
|
+
graph = (0, jsonld_utils_1.extractSubgraphs)(graph, config.filters.subgraphRoots, propertyFilters);
|
|
92
84
|
propertyFiltersApplied = true; // Property filters were applied during subgraph extraction
|
|
93
85
|
}
|
|
94
86
|
// Layer 2: Regular entity filtering with property filtering if not already applied
|
package/config.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* performing any graph processing. Each method returns a new
|
|
6
6
|
* configuration object for safe reuse and extension.
|
|
7
7
|
*/
|
|
8
|
-
import type { IJsonLdConfigBuilder, JsonLdConfig, JsonLdEntity, JsonLdFilter, JsonLdGraph, PipeFunction, PopulateConfig } from './types';
|
|
8
|
+
import type { IJsonLdConfigBuilder, JsonLdConfig, JsonLdEntity, JsonLdFilter, JsonLdFilterOptions, JsonLdGraph, PipeFunction, PopulateConfig } from './types';
|
|
9
9
|
/**
|
|
10
10
|
* Immutable configuration builder class
|
|
11
11
|
*/
|
|
@@ -122,6 +122,16 @@ export declare class JsonLdConfigBuilder implements IJsonLdConfigBuilder {
|
|
|
122
122
|
* ```
|
|
123
123
|
*/
|
|
124
124
|
clearAll(): this;
|
|
125
|
+
/**
|
|
126
|
+
* Merge with another configuration
|
|
127
|
+
* @param config - Configuration to merge with current configuration
|
|
128
|
+
*/
|
|
129
|
+
mergeConfig(config: JsonLdConfig): this;
|
|
130
|
+
/**
|
|
131
|
+
* Merge only the filters part of another configuration
|
|
132
|
+
* @param filters - Filter options to merge with current filters
|
|
133
|
+
*/
|
|
134
|
+
mergeFilters(filters: JsonLdFilterOptions): this;
|
|
125
135
|
/**
|
|
126
136
|
* Get the current configuration
|
|
127
137
|
*/
|
package/config.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.JsonLdConfigBuilder = void 0;
|
|
11
11
|
exports.createJsonLdConfig = createJsonLdConfig;
|
|
12
|
+
const builder_utils_1 = require("./builder-utils");
|
|
12
13
|
/**
|
|
13
14
|
* Immutable configuration builder class
|
|
14
15
|
*/
|
|
@@ -143,37 +144,47 @@ class JsonLdConfigBuilder {
|
|
|
143
144
|
* Extract subgraph starting from these root IDs
|
|
144
145
|
*/
|
|
145
146
|
subgraph(rootIds) {
|
|
147
|
+
const existingRoots = this.config.filters?.subgraphRoots || [];
|
|
146
148
|
return this.createInstance({
|
|
147
149
|
...this.config,
|
|
148
|
-
|
|
150
|
+
filters: {
|
|
151
|
+
...this.config.filters,
|
|
152
|
+
subgraphRoots: [...existingRoots, ...rootIds],
|
|
153
|
+
},
|
|
149
154
|
});
|
|
150
155
|
}
|
|
151
156
|
/**
|
|
152
157
|
* Filter properties for specific entity IDs
|
|
153
158
|
*/
|
|
154
159
|
filterPropertiesByIds(entityIds, rule) {
|
|
155
|
-
const existingRules = this.config.propertyFiltersByIds || [];
|
|
160
|
+
const existingRules = this.config.filters?.propertyFiltersByIds || [];
|
|
156
161
|
const newRule = {
|
|
157
162
|
entityIds,
|
|
158
163
|
...rule,
|
|
159
164
|
};
|
|
160
165
|
return this.createInstance({
|
|
161
166
|
...this.config,
|
|
162
|
-
|
|
167
|
+
filters: {
|
|
168
|
+
...this.config.filters,
|
|
169
|
+
propertyFiltersByIds: [...existingRules, newRule],
|
|
170
|
+
},
|
|
163
171
|
});
|
|
164
172
|
}
|
|
165
173
|
/**
|
|
166
174
|
* Filter properties for specific entity types
|
|
167
175
|
*/
|
|
168
176
|
filterPropertiesByTypes(entityTypes, rule) {
|
|
169
|
-
const existingRules = this.config.propertyFiltersByTypes || [];
|
|
177
|
+
const existingRules = this.config.filters?.propertyFiltersByTypes || [];
|
|
170
178
|
const newRule = {
|
|
171
179
|
entityTypes,
|
|
172
180
|
...rule,
|
|
173
181
|
};
|
|
174
182
|
return this.createInstance({
|
|
175
183
|
...this.config,
|
|
176
|
-
|
|
184
|
+
filters: {
|
|
185
|
+
...this.config.filters,
|
|
186
|
+
propertyFiltersByTypes: [...existingRules, newRule],
|
|
187
|
+
},
|
|
177
188
|
});
|
|
178
189
|
}
|
|
179
190
|
/**
|
|
@@ -264,8 +275,11 @@ class JsonLdConfigBuilder {
|
|
|
264
275
|
clearPropertyFilters() {
|
|
265
276
|
return this.createInstance({
|
|
266
277
|
...this.config,
|
|
267
|
-
|
|
268
|
-
|
|
278
|
+
filters: {
|
|
279
|
+
...this.config.filters,
|
|
280
|
+
propertyFiltersByIds: undefined,
|
|
281
|
+
propertyFiltersByTypes: undefined,
|
|
282
|
+
},
|
|
269
283
|
});
|
|
270
284
|
}
|
|
271
285
|
/**
|
|
@@ -274,7 +288,10 @@ class JsonLdConfigBuilder {
|
|
|
274
288
|
clearSubgraph() {
|
|
275
289
|
return this.createInstance({
|
|
276
290
|
...this.config,
|
|
277
|
-
|
|
291
|
+
filters: {
|
|
292
|
+
...this.config.filters,
|
|
293
|
+
subgraphRoots: undefined,
|
|
294
|
+
},
|
|
278
295
|
});
|
|
279
296
|
}
|
|
280
297
|
/**
|
|
@@ -290,6 +307,27 @@ class JsonLdConfigBuilder {
|
|
|
290
307
|
baseGraph: this.config.baseGraph,
|
|
291
308
|
});
|
|
292
309
|
}
|
|
310
|
+
/**
|
|
311
|
+
* Merge with another configuration
|
|
312
|
+
* @param config - Configuration to merge with current configuration
|
|
313
|
+
*/
|
|
314
|
+
mergeConfig(config) {
|
|
315
|
+
const currentConfig = this.getConfig();
|
|
316
|
+
const mergedConfig = (0, builder_utils_1.mergeConfigs)(currentConfig, config);
|
|
317
|
+
return this.createInstance(mergedConfig);
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Merge only the filters part of another configuration
|
|
321
|
+
* @param filters - Filter options to merge with current filters
|
|
322
|
+
*/
|
|
323
|
+
mergeFilters(filters) {
|
|
324
|
+
const currentFilters = this.config.filters;
|
|
325
|
+
const mergedFilters = (0, builder_utils_1.mergeFilterOptions)(currentFilters, filters);
|
|
326
|
+
return this.createInstance({
|
|
327
|
+
...this.config,
|
|
328
|
+
filters: mergedFilters,
|
|
329
|
+
});
|
|
330
|
+
}
|
|
293
331
|
/**
|
|
294
332
|
* Get the current configuration
|
|
295
333
|
*/
|
package/esm/builder-utils.js
CHANGED
|
@@ -13,14 +13,6 @@ export function mergeConfigs(base, override) {
|
|
|
13
13
|
baseGraph: override.baseGraph ?? base.baseGraph,
|
|
14
14
|
// Filters: merge filter options
|
|
15
15
|
filters: mergeFilterOptions(base.filters, override.filters),
|
|
16
|
-
// Subgraph roots: override takes precedence
|
|
17
|
-
subgraphRoots: override.subgraphRoots ?? base.subgraphRoots,
|
|
18
|
-
// Property filters: combine arrays
|
|
19
|
-
propertyFilters: combinePropertyFilters(base.propertyFilters, override.propertyFilters),
|
|
20
|
-
// Property filters by IDs: combine arrays
|
|
21
|
-
propertyFiltersByIds: combineArrays(base.propertyFiltersByIds, override.propertyFiltersByIds),
|
|
22
|
-
// Property filters by types: combine arrays
|
|
23
|
-
propertyFiltersByTypes: combineArrays(base.propertyFiltersByTypes, override.propertyFiltersByTypes),
|
|
24
16
|
// Additional entities: combine arrays
|
|
25
17
|
additionalEntities: combineArrays(base.additionalEntities, override.additionalEntities),
|
|
26
18
|
// Pipes: combine arrays
|
|
@@ -32,7 +24,7 @@ export function mergeConfigs(base, override) {
|
|
|
32
24
|
/**
|
|
33
25
|
* Merge filter options, merging arrays and using override for single values
|
|
34
26
|
*/
|
|
35
|
-
function mergeFilterOptions(base, override) {
|
|
27
|
+
export function mergeFilterOptions(base, override) {
|
|
36
28
|
if (!base && !override)
|
|
37
29
|
return undefined;
|
|
38
30
|
if (!base)
|
|
@@ -47,6 +39,10 @@ function mergeFilterOptions(base, override) {
|
|
|
47
39
|
excludeIds: combineArrays(base.excludeIds, override.excludeIds),
|
|
48
40
|
requiredProperties: combineArrays(base.requiredProperties, override.requiredProperties),
|
|
49
41
|
excludeEntitiesWithProperties: combineArrays(base.excludeEntitiesWithProperties, override.excludeEntitiesWithProperties),
|
|
42
|
+
subgraphRoots: combineArrays(base.subgraphRoots, override.subgraphRoots),
|
|
43
|
+
propertyFilters: combinePropertyFilters(base.propertyFilters, override.propertyFilters),
|
|
44
|
+
propertyFiltersByIds: combineArrays(base.propertyFiltersByIds, override.propertyFiltersByIds),
|
|
45
|
+
propertyFiltersByTypes: combineArrays(base.propertyFiltersByTypes, override.propertyFiltersByTypes),
|
|
50
46
|
// Single values - override takes precedence
|
|
51
47
|
customFilter: override.customFilter ?? base.customFilter,
|
|
52
48
|
maxEntities: override.maxEntities ?? base.maxEntities,
|
|
@@ -102,16 +98,16 @@ export function convertPropertyFiltersByTypes(rules) {
|
|
|
102
98
|
export function buildPropertyFilterConfig(config) {
|
|
103
99
|
const filters = [];
|
|
104
100
|
// Add base property filters
|
|
105
|
-
if (config.propertyFilters) {
|
|
106
|
-
filters.push(...config.propertyFilters);
|
|
101
|
+
if (config.filters?.propertyFilters) {
|
|
102
|
+
filters.push(...config.filters.propertyFilters);
|
|
107
103
|
}
|
|
108
104
|
// Add property filters by IDs
|
|
109
|
-
if (config.propertyFiltersByIds) {
|
|
110
|
-
filters.push(...convertPropertyFiltersByIds(config.propertyFiltersByIds));
|
|
105
|
+
if (config.filters?.propertyFiltersByIds) {
|
|
106
|
+
filters.push(...convertPropertyFiltersByIds(config.filters.propertyFiltersByIds));
|
|
111
107
|
}
|
|
112
108
|
// Add property filters by types
|
|
113
|
-
if (config.propertyFiltersByTypes) {
|
|
114
|
-
filters.push(...convertPropertyFiltersByTypes(config.propertyFiltersByTypes));
|
|
109
|
+
if (config.filters?.propertyFiltersByTypes) {
|
|
110
|
+
filters.push(...convertPropertyFiltersByTypes(config.filters.propertyFiltersByTypes));
|
|
115
111
|
}
|
|
116
112
|
return filters.length > 0 ? filters : undefined;
|
|
117
113
|
}
|
package/esm/builder.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { JsonLdConfigBuilder } from './config';
|
|
9
9
|
import { extractSubgraphs, filterGraphProperties } from './jsonld-utils';
|
|
10
|
-
import { applyPopulateConfig, buildPropertyFilterConfig, filterJsonLdGraph,
|
|
10
|
+
import { applyPopulateConfig, buildPropertyFilterConfig, filterJsonLdGraph, validateRuntimeConfig, } from './builder-utils';
|
|
11
11
|
/**
|
|
12
12
|
* Mutable builder class that extends config builder with automatic method delegation
|
|
13
13
|
*/
|
|
@@ -21,14 +21,6 @@ export class JsonLdBuilder extends JsonLdConfigBuilder {
|
|
|
21
21
|
createInstance(config) {
|
|
22
22
|
return new JsonLdBuilder(config);
|
|
23
23
|
}
|
|
24
|
-
/**
|
|
25
|
-
* Apply a pre-built configuration (builder-specific method)
|
|
26
|
-
*/
|
|
27
|
-
applyConfig(config) {
|
|
28
|
-
const currentConfig = this.getConfig();
|
|
29
|
-
const mergedConfig = mergeConfigs(currentConfig, config);
|
|
30
|
-
return new JsonLdBuilder(mergedConfig);
|
|
31
|
-
}
|
|
32
24
|
/**
|
|
33
25
|
* Get the current graph state (processes the graph if not already done)
|
|
34
26
|
*/
|
|
@@ -71,7 +63,7 @@ export class JsonLdBuilder extends JsonLdConfigBuilder {
|
|
|
71
63
|
processGraph() {
|
|
72
64
|
const config = this.getConfig();
|
|
73
65
|
if (!config.baseGraph) {
|
|
74
|
-
throw new Error('No base graph provided. Use baseGraph() or
|
|
66
|
+
throw new Error('No base graph provided. Use baseGraph() or mergeConfig() with a baseGraph.');
|
|
75
67
|
}
|
|
76
68
|
// Validate configuration - only check for critical errors that would break processing
|
|
77
69
|
const errors = validateRuntimeConfig(config);
|
|
@@ -82,9 +74,9 @@ export class JsonLdBuilder extends JsonLdConfigBuilder {
|
|
|
82
74
|
const propertyFilters = buildPropertyFilterConfig(config);
|
|
83
75
|
let propertyFiltersApplied = false;
|
|
84
76
|
// Layer 1: Subgraph extraction with property filtering if subgraphRoots are set
|
|
85
|
-
if (config.subgraphRoots && config.subgraphRoots.length > 0) {
|
|
77
|
+
if (config.filters?.subgraphRoots && config.filters.subgraphRoots.length > 0) {
|
|
86
78
|
// Extract subgraph with property filtering during traversal
|
|
87
|
-
graph = extractSubgraphs(graph, config.subgraphRoots, propertyFilters);
|
|
79
|
+
graph = extractSubgraphs(graph, config.filters.subgraphRoots, propertyFilters);
|
|
88
80
|
propertyFiltersApplied = true; // Property filters were applied during subgraph extraction
|
|
89
81
|
}
|
|
90
82
|
// Layer 2: Regular entity filtering with property filtering if not already applied
|
package/esm/config.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* performing any graph processing. Each method returns a new
|
|
6
6
|
* configuration object for safe reuse and extension.
|
|
7
7
|
*/
|
|
8
|
+
import { mergeConfigs, mergeFilterOptions } from './builder-utils';
|
|
8
9
|
/**
|
|
9
10
|
* Immutable configuration builder class
|
|
10
11
|
*/
|
|
@@ -139,37 +140,47 @@ export class JsonLdConfigBuilder {
|
|
|
139
140
|
* Extract subgraph starting from these root IDs
|
|
140
141
|
*/
|
|
141
142
|
subgraph(rootIds) {
|
|
143
|
+
const existingRoots = this.config.filters?.subgraphRoots || [];
|
|
142
144
|
return this.createInstance({
|
|
143
145
|
...this.config,
|
|
144
|
-
|
|
146
|
+
filters: {
|
|
147
|
+
...this.config.filters,
|
|
148
|
+
subgraphRoots: [...existingRoots, ...rootIds],
|
|
149
|
+
},
|
|
145
150
|
});
|
|
146
151
|
}
|
|
147
152
|
/**
|
|
148
153
|
* Filter properties for specific entity IDs
|
|
149
154
|
*/
|
|
150
155
|
filterPropertiesByIds(entityIds, rule) {
|
|
151
|
-
const existingRules = this.config.propertyFiltersByIds || [];
|
|
156
|
+
const existingRules = this.config.filters?.propertyFiltersByIds || [];
|
|
152
157
|
const newRule = {
|
|
153
158
|
entityIds,
|
|
154
159
|
...rule,
|
|
155
160
|
};
|
|
156
161
|
return this.createInstance({
|
|
157
162
|
...this.config,
|
|
158
|
-
|
|
163
|
+
filters: {
|
|
164
|
+
...this.config.filters,
|
|
165
|
+
propertyFiltersByIds: [...existingRules, newRule],
|
|
166
|
+
},
|
|
159
167
|
});
|
|
160
168
|
}
|
|
161
169
|
/**
|
|
162
170
|
* Filter properties for specific entity types
|
|
163
171
|
*/
|
|
164
172
|
filterPropertiesByTypes(entityTypes, rule) {
|
|
165
|
-
const existingRules = this.config.propertyFiltersByTypes || [];
|
|
173
|
+
const existingRules = this.config.filters?.propertyFiltersByTypes || [];
|
|
166
174
|
const newRule = {
|
|
167
175
|
entityTypes,
|
|
168
176
|
...rule,
|
|
169
177
|
};
|
|
170
178
|
return this.createInstance({
|
|
171
179
|
...this.config,
|
|
172
|
-
|
|
180
|
+
filters: {
|
|
181
|
+
...this.config.filters,
|
|
182
|
+
propertyFiltersByTypes: [...existingRules, newRule],
|
|
183
|
+
},
|
|
173
184
|
});
|
|
174
185
|
}
|
|
175
186
|
/**
|
|
@@ -260,8 +271,11 @@ export class JsonLdConfigBuilder {
|
|
|
260
271
|
clearPropertyFilters() {
|
|
261
272
|
return this.createInstance({
|
|
262
273
|
...this.config,
|
|
263
|
-
|
|
264
|
-
|
|
274
|
+
filters: {
|
|
275
|
+
...this.config.filters,
|
|
276
|
+
propertyFiltersByIds: undefined,
|
|
277
|
+
propertyFiltersByTypes: undefined,
|
|
278
|
+
},
|
|
265
279
|
});
|
|
266
280
|
}
|
|
267
281
|
/**
|
|
@@ -270,7 +284,10 @@ export class JsonLdConfigBuilder {
|
|
|
270
284
|
clearSubgraph() {
|
|
271
285
|
return this.createInstance({
|
|
272
286
|
...this.config,
|
|
273
|
-
|
|
287
|
+
filters: {
|
|
288
|
+
...this.config.filters,
|
|
289
|
+
subgraphRoots: undefined,
|
|
290
|
+
},
|
|
274
291
|
});
|
|
275
292
|
}
|
|
276
293
|
/**
|
|
@@ -286,6 +303,27 @@ export class JsonLdConfigBuilder {
|
|
|
286
303
|
baseGraph: this.config.baseGraph,
|
|
287
304
|
});
|
|
288
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* Merge with another configuration
|
|
308
|
+
* @param config - Configuration to merge with current configuration
|
|
309
|
+
*/
|
|
310
|
+
mergeConfig(config) {
|
|
311
|
+
const currentConfig = this.getConfig();
|
|
312
|
+
const mergedConfig = mergeConfigs(currentConfig, config);
|
|
313
|
+
return this.createInstance(mergedConfig);
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Merge only the filters part of another configuration
|
|
317
|
+
* @param filters - Filter options to merge with current filters
|
|
318
|
+
*/
|
|
319
|
+
mergeFilters(filters) {
|
|
320
|
+
const currentFilters = this.config.filters;
|
|
321
|
+
const mergedFilters = mergeFilterOptions(currentFilters, filters);
|
|
322
|
+
return this.createInstance({
|
|
323
|
+
...this.config,
|
|
324
|
+
filters: mergedFilters,
|
|
325
|
+
});
|
|
326
|
+
}
|
|
289
327
|
/**
|
|
290
328
|
* Get the current configuration
|
|
291
329
|
*/
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -31,6 +31,14 @@ export interface JsonLdFilterOptions {
|
|
|
31
31
|
requiredProperties?: string[];
|
|
32
32
|
/** Exclude entities with specific properties (renamed from excludeProperties) */
|
|
33
33
|
excludeEntitiesWithProperties?: string[];
|
|
34
|
+
/** Root IDs for subgraph extraction */
|
|
35
|
+
subgraphRoots?: string[];
|
|
36
|
+
/** Property-level filtering configuration */
|
|
37
|
+
propertyFilters?: PropertyFilterConfig;
|
|
38
|
+
/** Property filtering rules by entity IDs */
|
|
39
|
+
propertyFiltersByIds?: PropertyFilterByIdRule[];
|
|
40
|
+
/** Property filtering rules by entity types */
|
|
41
|
+
propertyFiltersByTypes?: PropertyFilterByTypeRule[];
|
|
34
42
|
}
|
|
35
43
|
/**
|
|
36
44
|
* Configuration for property filtering by entity IDs
|
|
@@ -69,14 +77,6 @@ export interface JsonLdConfig {
|
|
|
69
77
|
baseGraph?: JsonLdGraph;
|
|
70
78
|
/** Entity filtering options */
|
|
71
79
|
filters?: JsonLdFilterOptions;
|
|
72
|
-
/** Root IDs for subgraph extraction */
|
|
73
|
-
subgraphRoots?: string[];
|
|
74
|
-
/** Property-level filtering configuration */
|
|
75
|
-
propertyFilters?: PropertyFilterConfig;
|
|
76
|
-
/** Property filtering rules by entity IDs */
|
|
77
|
-
propertyFiltersByIds?: PropertyFilterByIdRule[];
|
|
78
|
-
/** Property filtering rules by entity types */
|
|
79
|
-
propertyFiltersByTypes?: PropertyFilterByTypeRule[];
|
|
80
80
|
/** Additional entities to include */
|
|
81
81
|
additionalEntities?: JsonLdEntity[];
|
|
82
82
|
/** Custom transformation functions */
|
|
@@ -153,6 +153,10 @@ export interface IJsonLdConfigBuilder {
|
|
|
153
153
|
clearSubgraph(): this;
|
|
154
154
|
/** Clear entire configuration except baseGraph */
|
|
155
155
|
clearAll(): this;
|
|
156
|
+
/** Merge with another configuration */
|
|
157
|
+
mergeConfig(config: JsonLdConfig): this;
|
|
158
|
+
/** Merge only the filters part of another configuration */
|
|
159
|
+
mergeFilters(filters: JsonLdFilterOptions): this;
|
|
156
160
|
/** Get the current configuration */
|
|
157
161
|
getConfig(): JsonLdConfig;
|
|
158
162
|
}
|