Skip to content

feat(events): change notifications on DatasetWrapper (on/off) - #94

Draft
jeswr wants to merge 1 commit into
rdfjs:mainfrom
jeswr:feat/dataset-change-events
Draft

feat(events): change notifications on DatasetWrapper (on/off)#94
jeswr wants to merge 1 commit into
rdfjs:mainfrom
jeswr:feat/dataset-change-events

Conversation

@jeswr

@jeswr jeswr commented Jul 6, 2026

Copy link
Copy Markdown
Member

Adds change notifications to DatasetWrapper: consumers can now observe every effective mutation of the underlying data with on(listener) / off(listener).

What it does

  • DatasetWrapper still accepts any RDF/JS DatasetCore (constructor signature unchanged) and now internally ensures an eventful layer over it (ensureEventfulDatasetCore). The passed dataset remains the single place of storage — mutations write through to it, so external references to it observe all changes.
  • New public API: DatasetWrapper.on(listener) and DatasetWrapper.off(listener), plus the exported IDatasetChangeListener / ChangeEvent types. Listeners are called synchronously with ("add" | "delete", quad).
  • Only effective changes notify (per Quad.equals): adding an already-contained quad or deleting an absent one emits nothing.
  • Because all wrapper-driven mutations flow through DatasetWrapper.add/delete, events fire uniformly for:
    • direct add/delete calls,
    • property assignments through RequiredAs/OptionalAs mappings (delete of the previous quads, then add — assignments do not deduplicate; clearing an optional property emits only deletes),
    • mutations of Sets produced by SetFrom (add/delete/clear),
    • mutations through named graph views created with named(...), which share the same eventful core.
  • Subscribing the same listener twice is a no-op; so is detaching a listener that is not subscribed.

Dependency

This introduces the package's first runtime dependency: the event-emitting DatasetCore lives in @jeswr/eventful-dataset rather than being copied in-repo. It is currently pinned as a github: branch dependency while it is staged; it would move to a released npm version (or wherever the group prefers it to live) before this leaves draft. Flagging it explicitly since "dependencies": {} was a visible property of this package.

Relation to #73

Supersedes the events slice of #73 (Omnibus): the DatasetWrapper.on/off wiring, the NotificationsDatasetCore concern, and the dataset events tests. The EventEmitter/notifying-dataset implementation now comes from the foundation package instead of the in-repo src/EventEmitter.ts + src/dataset/NotifyingDatasetCore.ts copies.

Deliberately not included from #73 (left to their own slices): the Triple/default-graph restriction, the datasetFactory constructor parameter, GraphScopedDataset/ProjectedDataset, and all of the async (AsyncDatasetCore) work. No size/match semantics change here.

Tests

  • test/unit/dataset_events.test.ts — direct add/delete notifications, effective-change filtering, listener bookkeeping (off, double-subscribe, multiple listeners), and wrapper-driven events for required/optional/typed properties and Set mappings, on the existing Parent/Child fixtures.
  • test/unit/dataset_events_examples.test.ts — the JSDoc-style examples as executable tests: observing a SetFrom-backed children set (live views, per-item events) and an optional email field.

npm i && npx tsc && npm test && npx typedoc && npm audit --omit=dev --audit-level=moderate all pass locally (150 tests, 0 fail; typedoc warnings unchanged from main).

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).

DatasetWrapper now layers @jeswr/eventful-dataset's EventfulDatasetCore
over the wrapped dataset (constructor signature unchanged; write-through
storage preserved) and exposes on(listener)/off(listener) so consumers
can observe effective additions and deletions - whether performed
directly or through mapped properties, Set mappings, or named graph
views sharing the same eventful core.

Adds the IDatasetChangeListener/ChangeEvent types to the public surface
and ports the dataset_events test slices from rdfjs#73.

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