Skip to content

feat: GraphScopedDataset — read from many graphs, write to one - #95

Draft
jeswr wants to merge 1 commit into
rdfjs:mainfrom
jeswr:feat/graph-scoped-dataset
Draft

feat: GraphScopedDataset — read from many graphs, write to one#95
jeswr wants to merge 1 commit into
rdfjs:mainfrom
jeswr:feat/graph-scoped-dataset

Conversation

@jeswr

@jeswr jeswr commented Jul 6, 2026

Copy link
Copy Markdown
Member

What this does

Adds GraphScopedDataset: a dataset view that reads from a configurable set of graphs and writes to a single graph, generalizing NamedGraphDataset (which is the special case of reading from and writing to the same one graph, and stays untouched for back-compat).

  • Reads union the configured readGraphs, projected onto the default graph, with per-triple deduplication (a triple appearing in several read graphs is exposed once). readGraphs === undefined reads every graph — a deduplicated union view.
  • Writes (add / delete) are rewritten into the configured writeGraph; delete leaves copies of the triple in other graphs untouched. Non-default-graph input quads throw NamedGraphError (via the existing ensureDefaultGraph).
  • has answers from the read scope, consistent with iteration.
  • match(s, p, o[, defaultGraph]) mirrors NamedGraphDataset's self-wrapping pattern and throws TermTypeError for non-default graph arguments.
  • DatasetWrapper gains a protected scoped(writeGraph, readGraphs, klass) helper beside named(), accepting IRIs or terms; IGraphScopedDatasetConstructor is added to src/type/. Both new symbols are exported from mod.ts.

Because the projection rewrites every read quad to the default graph, existing TermWrapper/DatasetWrapper models work unchanged against quads that live in named graphs — including the common read-many/write-one asymmetry (e.g. read the union of a document's graphs, write changes to one designated graph).

Why

Addresses the graph-scoping follow-up from #43 (@jaxoncreed): LDO-style control over which graph writes land in, independent of which graphs are read.

Relation to #73

Supersedes the GraphScopedDataset read-write graph-scoping slice of the #73 omnibus, including its union_graph / projected_dataset read-write test slices. It deliberately excludes the rest of that omnibus: no events plumbing (NotifyingDatasetCore), no LazyMaterialize, and no breaking default-graph-only DatasetWrapper rework — this is a purely additive change.

Notes

  • Triple deduplication keys terms by termType/value (plus language/direction/datatype for literals, recursion for quoted triples), the same keying used in fix: DatasetWrapper helpers yield distinct terms #88; if both land, the helper can be shared in a follow-up.
  • Tests: test/unit/graph_scoped.test.ts (explicit read scope + union view) and test/unit/graph_scoped_integration.test.ts (TermWrapper models reading across graphs and writing into the scoped graph). New code is at 100% line coverage; npm test and npx typedoc are green.

Review timing: This draft was prepared with Claude; I (@jeswr) will personally review it before it progresses. I'm currently batching a lot of work in flight, so expect active review Wednesday-Friday (8-10 July).

Generalizes NamedGraphDataset (which stays untouched) into a view that
reads a configurable set of graphs — or every graph when the read scope
is undefined — projected onto the default graph with per-triple
deduplication, while directing all writes to a single configured graph.

- src/GraphScopedDataset.ts: reads union the read graphs and project to
  the default graph; add/delete/has enforce default-graph input via
  ensureDefaultGraph; match mirrors NamedGraphDataset's self-wrapping
  pattern and rejects non-default graph arguments with TermTypeError.
- DatasetWrapper.scoped(writeGraph, readGraphs, klass) beside named().
- IGraphScopedDatasetConstructor in src/type/, both exported from mod.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant