Skip to content

Commit df88120

Browse files
authored
Merge pull request #2 from hyperweb-io/feat/merge-config
Add config merging methods
2 parents 2c30aae + 25d8b81 commit df88120

File tree

10 files changed

+1080
-703
lines changed

10 files changed

+1080
-703
lines changed

packages/jsonld-tools/README.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const blogConfig = globalConfig.includeTypes(['Article']);
6363

6464
// Use configurations
6565
const result = createJsonLdBuilder()
66-
.applyConfig(homeConfig)
66+
.mergeConfig(homeConfig.getConfig())
6767
.excludeIds(['runtime:override']) // Runtime overrides
6868
.build({ prettyPrint: true });
6969
```
@@ -122,7 +122,7 @@ const config = createJsonLdConfig()
122122
Creates a new builder that extends the configuration builder with graph processing capabilities.
123123

124124
```typescript
125-
const builder = createJsonLdBuilder().baseGraph(graph).applyConfig(config);
125+
const builder = createJsonLdBuilder().baseGraph(graph).mergeConfig(config);
126126
```
127127

128128
### Configuration Methods
@@ -149,6 +149,37 @@ All methods are inherited by the builder from the configuration builder:
149149
- `.clearSubgraph()` - Clear subgraphRoots
150150
- `.clearAll()` - Clear entire configuration (except baseGraph)
151151

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+
152183
#### Property Filtering
153184

154185
- `.filterPropertiesByIds(entityIds, rule)` - Filter properties for specific entity IDs
@@ -175,7 +206,6 @@ All methods are inherited by the builder from the configuration builder:
175206

176207
#### Builder-Only Methods
177208

178-
- `.applyConfig(config: JsonLdConfig)` - Apply a pre-built configuration
179209
- `.getCurrentGraph()` - Get the current graph state
180210
- `.build(options?: BuildOptions)` - Build the final JSON-LD output
181211

packages/jsonld-tools/__tests__/builder/__snapshots__/general.test.ts.snap

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,6 @@ exports[`JsonLdBuilder adds additional entities with snapshot 1`] = `
3131
}"
3232
`;
3333

34-
exports[`JsonLdBuilder applies configuration with snapshot 1`] = `
35-
"{
36-
"@context": "https://schema.org",
37-
"@graph": [
38-
{
39-
"@id": "org:hyperweb",
40-
"@type": "Organization",
41-
"name": "HyperWeb",
42-
"url": "https://hyperweb.com",
43-
"member": [
44-
{
45-
"@id": "person:danlynch"
46-
},
47-
{
48-
"@id": "person:john"
49-
}
50-
],
51-
"foundingDate": "2020-01-01",
52-
"location": {
53-
"@id": "place:san-francisco"
54-
}
55-
}
56-
]
57-
}"
58-
`;
59-
6034
exports[`JsonLdBuilder applies custom pipes with snapshot 1`] = `
6135
"{
6236
"@context": "https://schema.org",
@@ -1357,6 +1331,32 @@ exports[`JsonLdBuilder limits max entities with snapshot 1`] = `
13571331
}"
13581332
`;
13591333

1334+
exports[`JsonLdBuilder merges configuration with snapshot 1`] = `
1335+
"{
1336+
"@context": "https://schema.org",
1337+
"@graph": [
1338+
{
1339+
"@id": "org:hyperweb",
1340+
"@type": "Organization",
1341+
"name": "HyperWeb",
1342+
"url": "https://hyperweb.com",
1343+
"member": [
1344+
{
1345+
"@id": "person:danlynch"
1346+
},
1347+
{
1348+
"@id": "person:john"
1349+
}
1350+
],
1351+
"foundingDate": "2020-01-01",
1352+
"location": {
1353+
"@id": "place:san-francisco"
1354+
}
1355+
}
1356+
]
1357+
}"
1358+
`;
1359+
13601360
exports[`JsonLdBuilder merges configurations correctly 1`] = `
13611361
"{
13621362
"@context": "https://schema.org",

0 commit comments

Comments
 (0)