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
36 changes: 33 additions & 3 deletions packages/jsonld-tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const blogConfig = globalConfig.includeTypes(['Article']);

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

```typescript
const builder = createJsonLdBuilder().baseGraph(graph).applyConfig(config);
const builder = createJsonLdBuilder().baseGraph(graph).mergeConfig(config);
```

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

#### Configuration Merging

- `.mergeConfig(config: JsonLdConfig)` - Merge with another complete configuration
- `.mergeFilters(filters: JsonLdFilterOptions)` - Merge only the filters part of another configuration

**Available in both config builder and main builder** - These methods work the same way in both classes.

```typescript
// Config builder usage
const baseConfig = createJsonLdConfig().includeTypes(['Person']);
const otherConfig = createJsonLdConfig()
.includeTypes(['Organization'])
.excludeIds(['test'])
.getConfig();
const merged = baseConfig.mergeConfig(otherConfig);
// Result: includeTypes: ['Person', 'Organization'], excludeIds: ['test']

// Main builder usage (processes graph immediately)
const result = createJsonLdBuilder()
.baseGraph(graph)
.includeTypes(['Person'])
.mergeConfig(otherConfig)
.build({ prettyPrint: true });

// Merge only filters
const baseConfig = createJsonLdConfig().includeTypes(['Person']).addEntities([entity]);
const otherFilters = { includeTypes: ['Organization'], maxEntities: 10 };
const merged = baseConfig.mergeFilters(otherFilters);
// Result: includeTypes: ['Person', 'Organization'], maxEntities: 10, additionalEntities preserved
```

#### Property Filtering

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

#### Builder-Only Methods

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,6 @@ exports[`JsonLdBuilder adds additional entities with snapshot 1`] = `
}"
`;

exports[`JsonLdBuilder applies configuration with snapshot 1`] = `
"{
"@context": "https://schema.org",
"@graph": [
{
"@id": "org:hyperweb",
"@type": "Organization",
"name": "HyperWeb",
"url": "https://hyperweb.com",
"member": [
{
"@id": "person:danlynch"
},
{
"@id": "person:john"
}
],
"foundingDate": "2020-01-01",
"location": {
"@id": "place:san-francisco"
}
}
]
}"
`;

exports[`JsonLdBuilder applies custom pipes with snapshot 1`] = `
"{
"@context": "https://schema.org",
Expand Down Expand Up @@ -1357,6 +1331,32 @@ exports[`JsonLdBuilder limits max entities with snapshot 1`] = `
}"
`;

exports[`JsonLdBuilder merges configuration with snapshot 1`] = `
"{
"@context": "https://schema.org",
"@graph": [
{
"@id": "org:hyperweb",
"@type": "Organization",
"name": "HyperWeb",
"url": "https://hyperweb.com",
"member": [
{
"@id": "person:danlynch"
},
{
"@id": "person:john"
}
],
"foundingDate": "2020-01-01",
"location": {
"@id": "place:san-francisco"
}
}
]
}"
`;

exports[`JsonLdBuilder merges configurations correctly 1`] = `
"{
"@context": "https://schema.org",
Expand Down
Loading