@grafctory/keep 0.0.0-stage → 0.15.0

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.
@@ -0,0 +1,328 @@
1
+ /*
2
+ * Copyright © 2025-2026 Metreeca srl
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Caching store wrapper.
18
+ *
19
+ * Speeds up read-heavy workloads by serving repeated retrievals from an in-memory cache. The cache stays bounded
20
+ * by size and age, shares concurrent identical retrievals, and stays coherent with writes made through the store, by
21
+ * other clients, or signalled by the backend.
22
+ *
23
+ * @module
24
+ */
25
+ import { isArray, isObject } from "@grafctory/core";
26
+ import { immutable } from "@grafctory/core/values";
27
+ /**
28
+ * Creates a caching store backed by a delegate.
29
+ *
30
+ * Serves repeated retrievals from an in-memory cache, sparing the delegate a round-trip whenever a prior result can
31
+ * be reused. This cuts latency and backend load for read-heavy workloads, while writes and eviction keep cached
32
+ * results coherent and bounded.
33
+ *
34
+ * Results are cached by `entry`, `model` and `virtual`, and by the `locale` and `limit` of the retrieval scope of
35
+ * {@link Store.lookup lookup}. Templates differing only in member or element order share a cached result.
36
+ *
37
+ * > [!IMPORTANT]
38
+ * > `shape` is not part of the cache key. A retrieval result MUST depend only on `entry`, `model`, `virtual`,
39
+ * > `locale` and `limit`, with `shape` supplying structural metadata that does not affect the returned payload.
40
+ *
41
+ * > [!IMPORTANT]
42
+ * > The request `virtual` flag is part of the cache key, because virtual and held retrievals of the same entry
43
+ * > return different collections. An omitted and a `false` flag share a single cached result.
44
+ *
45
+ * > [!IMPORTANT]
46
+ * > The scope `locale` is part of the cache key, because it selects which localised content a retrieval returns.
47
+ * > Unlike the model, the locale priority list is order-significant: `["en", "it"]` and `["it", "en"]` are cached
48
+ * > separately. An omitted and an empty locale list share a single cached result, distinct from any explicit list.
49
+ *
50
+ * > [!IMPORTANT]
51
+ * > The scope `limit` is part of the cache key, because it caps the page size of each collection and so changes the
52
+ * > returned payload. An omitted and a `0` limit share a single cached result. The scope `plain` and `depth` are not
53
+ * > part of the key: they only accept or reject a model, and never alter a successful payload.
54
+ *
55
+ * The cache offers three observable guarantees:
56
+ *
57
+ * - **coalescing** — concurrent retrievals for the same key resolve from a single delegate fetch, and a failed
58
+ * retrieval or one finding no resource is never cached, so a later retrieval re-fetches;
59
+ * - **read-after-write coherence** — a retrieval never returns content staler than the latest write made through this
60
+ * store: {@link Store.create create}, {@link Store.update update}, {@link Store.delete delete},
61
+ * {@link Store.insert insert} and {@link Store.remove remove} invalidate matching entries, and a
62
+ * retrieval overlapping an in-progress write to the same entry is served from the delegate without being cached;
63
+ * - **commit coherence** — writes committed through {@link Store.execute execute}, by other clients sharing the
64
+ * delegate, or signalled by the backend invalidate matching entries on commit, for as long as the store stays open
65
+ * ({@link Store.close close} ends further invalidation).
66
+ *
67
+ * The configurable `match` predicate selects which cached entries a write invalidates.
68
+ *
69
+ * > [!IMPORTANT]
70
+ * > **Transaction Isolation** — Inherited from the wrapped {@link Store}.
71
+ *
72
+ * > [!IMPORTANT]
73
+ * > **Mutation Events** — Inherited from the wrapped {@link Store}.
74
+ *
75
+ * @param store - The delegate store to cache
76
+ * @param options - Cache configuration options
77
+ *
78
+ * @returns An immutable store with caching behaviour
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * const cache = createCachingStore(restStore, { size: 1_000, ttl: 60_000 });
83
+ * const product = await cache.lookup({ entry, shape, model });
84
+ * ```
85
+ */
86
+ export function createCachingStore(store, { size = 0, ttl = 0, match = () => true } = {}) {
87
+ // LRU ordering is supplied for free by `Map`'s insertion-order iteration: every hit re-sets the entry,
88
+ // moving it to the tail, so `cache.keys().next().value` is always the least-recently-used key.
89
+ const cache = new Map();
90
+ // Tracks entries with at least one in-flight wrapper-initiated write. Reads of these entries bypass the
91
+ // cache entirely: they still query the delegate, but their result is not stored. This closes the window
92
+ // between a lookup call resolving with a pre-commit value and the reactive observer firing on commit, during
93
+ // which the cache would otherwise hold a stale-but-fresh-looking record.
94
+ const writing = new Map();
95
+ // Reactive invalidation: subscribe to the delegate's mutation events and drop matching records on commit.
96
+ // Covers writes routed through `execute`, writes from other clients sharing the delegate, and backends that
97
+ // emit storage-level events. The subscription is released by `close()` so the delegate does not retain a
98
+ // reference to a discarded wrapper.
99
+ const unsubscribe = store.observe(mutations => {
100
+ Object.keys(mutations).forEach(invalidate);
101
+ });
102
+ return immutable({
103
+ lookup({ virtual, entry, shape, model }, opts) {
104
+ return memoise(entry, model, { ...opts, virtual }, () => store.lookup({ virtual, entry, shape, model }, opts));
105
+ },
106
+ create({ entry, shape, model, state }) {
107
+ return write(entry, () => store.create({ entry, shape, model, state }));
108
+ },
109
+ update({ entry, shape, state }) {
110
+ return write(entry, () => store.update({ entry, shape, state }));
111
+ },
112
+ delete({ entry, shape }) {
113
+ return write(entry, () => store.delete({ entry, shape }));
114
+ },
115
+ insert({ entry, shape, state }) {
116
+ return write(entry, () => store.insert({ entry, shape, state }));
117
+ },
118
+ remove({ entry, shape }) {
119
+ return write(entry, () => store.remove({ entry, shape }));
120
+ },
121
+ observe(observer, resources) {
122
+ return store.observe(observer, resources);
123
+ },
124
+ execute(task) {
125
+ return store.execute(task); // task mutations invalidate the cache reactively through events
126
+ },
127
+ close() {
128
+ unsubscribe();
129
+ return store.close();
130
+ }
131
+ });
132
+ /**
133
+ * Retrieve-with-cache core.
134
+ *
135
+ * Three branches:
136
+ *
137
+ * - **bypass** — when `entry` has any wrapper-initiated write in flight, runs `miss()` and returns its
138
+ * promise without storing it, so a pre-commit snapshot cannot be installed as fresh;
139
+ * - **fresh hit** — returns the memoised promise and re-inserts the record to bump its LRU position;
140
+ * - **miss / TTL-expired** — runs `miss()`, stores the pending promise under the canonicalised key so
141
+ * concurrent callers share the in-flight request, and enforces TTL/size bounds via {@link purge}; a
142
+ * fetch resolving to an absent resource or rejecting evicts its record only if an intervening invalidation
143
+ * has not already replaced it.
144
+ *
145
+ * @typeParam V - The retrieved payload, opaque to the cache
146
+ *
147
+ * @param entry - Resource identifier; paired with the canonicalised model and varying scope members to form the
148
+ * cache key
149
+ * @param model - Retrieval model, canonicalised so that equivalent models in different orderings share a key
150
+ * @param vary - Request and retrieval scope members whose values vary the returned payload, folded into the key:
151
+ * `locale` order-significantly (an omitted or empty list collapsing to a single key), `limit` because it caps
152
+ * each collection's `#` pagination bound (an omitted or `0` unbounded value collapsing to a single key) and
153
+ * `virtual` because it derives collections by class rather than by links (omitted and `false` collapsing to one)
154
+ * @param miss - Fetcher invoked on cache miss, on TTL expiration, or while the entry has an in-flight write
155
+ *
156
+ * @returns The memoised, freshly-fetched, or bypass-fetched promise
157
+ */
158
+ function memoise(entry, model, vary = {}, miss) {
159
+ // Bypass the cache while a write to this entry is in flight: still query the delegate so the caller
160
+ // gets a value, but do not store the result: it is liable to be the pre-commit snapshot that the
161
+ // reactive observer would invalidate moments later
162
+ if (writing.has(entry)) {
163
+ return miss();
164
+ }
165
+ else {
166
+ // Cache key layout: `<entry>\x00<canonical-model>\x00<locale>\x00<limit>\x00<virtual>`. `canonical`
167
+ // walks the model bottom-up, sorting object keys and (already-canonical) array elements, so models
168
+ // differing only in ordering share a key. The locale segment is serialised verbatim (order preserved,
169
+ // since the priority list is order-significant) with omitted and empty lists collapsing to `[]`. The
170
+ // limit segment is keyed because it caps each collection's `#` and so changes the payload, with omitted
171
+ // and `0` (both unbounded) collapsing to `0`. The virtual segment is keyed because it derives collections
172
+ // by class rather than by stored links, with omitted and `false` collapsing to `false`. `\x00` is safe
173
+ // as a separator: IRIs cannot contain it and JSON always escapes it inside string payloads.
174
+ const key = [
175
+ entry, canonical(model), JSON.stringify(vary.locale ?? []), vary.limit ?? 0, vary.virtual ?? false
176
+ ].join("\x00");
177
+ const cached = cache.get(key);
178
+ if (cached && !expired(cached.created)) {
179
+ // hit: re-insert to move the entry to the tail of the Map's iteration order (the LRU position),
180
+ // and return the memoised promise; ;(cast) the type-erased `Promise<unknown>` storage lets records
181
+ // with different payload types share one Map
182
+ cache.delete(key);
183
+ cache.set(key, cached);
184
+ return cached.value;
185
+ }
186
+ else {
187
+ // miss (or TTL-expired): drop any stale record, run the fetcher, and memoise the pending promise
188
+ // under the same key so concurrent callers share the in-flight request; an absent resource or a
189
+ // failure evicts its own record once settled, so neither a missing resource nor a transient error
190
+ // is retained
191
+ if (cached) {
192
+ cache.delete(key);
193
+ }
194
+ const value = miss().then(resource => {
195
+ if (resource === undefined) {
196
+ evict();
197
+ }
198
+ return resource;
199
+ }, error => {
200
+ evict();
201
+ throw error;
202
+ });
203
+ // identity-check: only evict if this promise is still the cached one, avoiding dropping a newer
204
+ // record installed after an intervening invalidate
205
+ function evict() {
206
+ if (cache.get(key)?.value === value) {
207
+ cache.delete(key);
208
+ }
209
+ }
210
+ cache.set(key, {
211
+ entry,
212
+ value,
213
+ created: Date.now()
214
+ });
215
+ purge();
216
+ return value;
217
+ }
218
+ }
219
+ }
220
+ /**
221
+ * Serialises a value to a canonical JSON-like string.
222
+ *
223
+ * Children are canonicalised first, then sorted by their already-canonical string form, so arrays of
224
+ * objects are ordered by structural content rather than by the `"[object Object]"` placeholder that
225
+ * `Array.prototype.sort` would otherwise impose. The output collapses values differing only in property
226
+ * or element order to the same string.
227
+ *
228
+ * @param value - Value to serialise
229
+ *
230
+ * @returns A canonical string representation of `value`
231
+ */
232
+ function canonical(value) {
233
+ if (isArray(value)) {
234
+ return `[${value.map(canonical).sort().join(",")}]`;
235
+ }
236
+ else if (isObject(value)) {
237
+ return `{${Object.keys(value).sort().map(k => `${JSON.stringify(k)}:${canonical(value[k])}`).join(",")}}`;
238
+ }
239
+ else {
240
+ // JSON.stringify(undefined) returns undefined, not a string; substitute a distinct sentinel so the
241
+ // signature holds and `undefined` does not collide with the string literal `"undefined"` (which JSON
242
+ // would render with surrounding quotes)
243
+ return value === undefined ? "undefined" : JSON.stringify(value);
244
+ }
245
+ }
246
+ /**
247
+ * Tests whether a record is older than the configured TTL.
248
+ *
249
+ * Returns false when `ttl <= 0`, so the predicate can be reused at both the hit guard and the purge sweep
250
+ * without duplicating the boundary check. The reference timestamp defaults to `Date.now` but may be
251
+ * passed in to share a single snapshot across a batch of comparisons.
252
+ *
253
+ * @param created - Insertion timestamp (ms) of the record under test
254
+ * @param now - Reference timestamp (ms) to compare against; defaults to `Date.now`
255
+ *
256
+ * @returns true if `ttl > 0` and `created` is older than `ttl` milliseconds relative to `now`; false otherwise
257
+ */
258
+ function expired(created, now = Date.now()) {
259
+ return ttl > 0 && now - created > ttl;
260
+ }
261
+ /**
262
+ * Run a wrapper-initiated write under in-flight tracking.
263
+ *
264
+ * Marks `entry` as having an in-flight write, runs the configured pre-commit invalidation, delegates to
265
+ * `op`, and clears the marker once the delegate settles. While the marker is set, retrievals of `entry`
266
+ * bypass the cache so a pre-commit value can never be stored as fresh.
267
+ *
268
+ * @param entry - Resource identifier targeted by the write
269
+ * @param op - Thunk that delegates the write to the wrapped store and returns its promise
270
+ *
271
+ * @returns The promise returned by `op`, settled after the in-flight marker has been cleared
272
+ */
273
+ function write(entry, op) {
274
+ writing.set(entry, (writing.get(entry) ?? 0) + 1);
275
+ invalidate(entry);
276
+ return op().finally(() => {
277
+ const count = (writing.get(entry) ?? 1) - 1;
278
+ if (count <= 0) {
279
+ writing.delete(entry);
280
+ }
281
+ else {
282
+ writing.set(entry, count);
283
+ }
284
+ });
285
+ }
286
+ /**
287
+ * Drop cached records matching a mutated resource.
288
+ *
289
+ * Iterates the cache and removes every record whose stored identifier satisfies the configured {@link match}
290
+ * predicate against the mutated `entry`. Called from both the pre-commit write path on the wrapper and the
291
+ * reactive observer attached to the delegate.
292
+ *
293
+ * @param entry - Identifier of the mutated resource
294
+ */
295
+ function invalidate(entry) {
296
+ for (const [key, record] of cache) {
297
+ if (match(entry, record.entry)) {
298
+ cache.delete(key);
299
+ }
300
+ }
301
+ }
302
+ /**
303
+ * Enforce TTL and size bounds.
304
+ *
305
+ * Runs two sweeps: first, when `ttl > 0`, drops every record older than `ttl` milliseconds; second, when
306
+ * `size > 0` and the cache is overfull, drops the head slice of the Map (least-recently-used first) in
307
+ * a single batch sized to the exact overflow. Invoked after every miss so expired siblings and overfill
308
+ * are cleaned up incrementally, as the cache has no background sweeper.
309
+ */
310
+ function purge() {
311
+ if (ttl > 0) {
312
+ const now = Date.now();
313
+ for (const [key, record] of cache) {
314
+ if (expired(record.created, now)) {
315
+ cache.delete(key);
316
+ }
317
+ }
318
+ }
319
+ // LRU sweep: when over the size bound, take the head slice of Map keys (insertion order = LRU first)
320
+ // and drop them: `cache.size - size` is the exact overflow, so no loop condition needs re-checking
321
+ if (size > 0 && cache.size > size) {
322
+ Array.from(cache.keys())
323
+ .slice(0, cache.size - size)
324
+ .forEach(key => cache.delete(key));
325
+ }
326
+ }
327
+ }
328
+ //# sourceMappingURL=caching.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"caching.js","sourceRoot":"","sources":["../../src/stores/caching.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;GAQG;AAEH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAiB,MAAM,iBAAiB,CAAC;AAEnE,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAKnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAY,EAAE,EAEhD,IAAI,GAAG,CAAC,EACR,GAAG,GAAG,CAAC,EACP,KAAK,GAAG,GAAG,EAAE,CAAC,IAAI,KAwCf,EAAE;IAEL,uGA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AAC;YAC3D,CAAC;QAEF,CAAC;QAED,qGAAqG;QACrG,mGAAmG;QAEnG,IAAK,IAAI,GAAG,CAAC,IAAI,KAAK,CAAC,IAAI,GAAG,IAAI,EAAG,CAAC;YAErC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;iBACtB,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,GAAC,IAAI,CAAC;iBACzB,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAErC,CAAC;IAEF,CAAC;AAEF,CAAC"}
@@ -0,0 +1,57 @@
1
+ import type { Store } from "../index.js";
2
+ /**
3
+ * Manages mutation events, transactional execution, and lifecycle for a connector's {@link StoreClient},
4
+ * exposing it as a full {@link Store}.
5
+ *
6
+ * A connector can implement only the {@link StoreClient} data surface and still offer the full {@link Store}
7
+ * contract. The connector supplies its transaction primitive through `management.execute`, which hands the
8
+ * connector's {@link StoreClient} to every data call. The option is required, since only the connector knows what
9
+ * atomicity its backend can provide. Backend primitives supplied through `management` may also back `observe` or
10
+ * `close`, and the wrapper fills in whatever is missing.
11
+ *
12
+ * Each standalone mutation call and each {@link Store.execute execute} call delivers a single filtered event to each
13
+ * matching {@link StoreObserver observer} once the call resolves. If the call rejects, its pending events are
14
+ * discarded and no observer is notified. Synchronous throws and asynchronous rejections from observers are caught and
15
+ * silently ignored, so one faulty observer cannot break delivery to others.
16
+ *
17
+ * All errors, including {@link !RangeError RangeError}, {@link @grafctory/core!TraceError | TraceError} and
18
+ * {@link @grafctory/http!Problem | Problem}, propagate as promise rejections, in line with the unified {@link Store}
19
+ * error channel.
20
+ *
21
+ * > [!IMPORTANT]
22
+ * > **Transaction Isolation** — Determined by the supplied `execute` option, typically through a backend
23
+ * > transaction primitive: the wrapper adds neither isolation nor atomicity of its own.
24
+ *
25
+ * > [!IMPORTANT]
26
+ * > **Mutation Events** — emits in-process observer events: each standalone mutation and each
27
+ * > {@link Store.execute execute} call delivers a single filtered batch to matching {@link StoreObserver observer}s
28
+ * > on resolve, and none on rejection. Mutations made by other clients reach local observers only if a
29
+ * > backend-bridging `observe` option is supplied through `management`.
30
+ *
31
+ * @param management - {@link Store} management methods backed by the connector: `execute` is required, and the
32
+ * wrapper fills in whatever else is missing
33
+ * @param management.execute - Transaction wrapper applied to every standalone StoreClient call and to the body of
34
+ * each {@link Store.execute execute} call, typically a backend transaction primitive (for example,
35
+ * `graph.execute` for a SPARQL connector) responsible for atomic commit and rollback. A backend with no
36
+ * transaction primitive supplies a wrapper applying the task directly to its StoreClient, and declares on its
37
+ * factory that a failing task neither rolls back nor isolates its mutations. The option MUST call each task it
38
+ * receives with a `scope` StoreClient dedicated to that call, so per-call state, such as a freshly bound graph
39
+ * buffer, never leaks across concurrent invocations; every data call within the transaction is routed through
40
+ * `scope`. Calls made by a user task inside {@link Store.execute execute} do not open further transactions: they
41
+ * share the outer one. The option MUST convert synchronous throws from the task into promise rejections, to
42
+ * preserve the unified Store error channel: lookups are routed through it with no additional guard
43
+ * @param management.observe - Backend registration for storage-level events, such as mutations made by other clients
44
+ * sharing the backend. Each observer is registered both with this option and locally, and a single detach call
45
+ * releases both registrations. The resource filter always arrives as an array of references, or as `undefined`
46
+ * for an unfiltered registration, so the option never has to handle bare references or single-pass iterables.
47
+ * Absent by default
48
+ * @param management.close - Exposed as is on the returned store. Defaults to a resolved no-op
49
+ *
50
+ * @returns An immutable {@link Store} serving data calls through the supplied `management` opts
51
+ */
52
+ export declare function createManagingStore({ observe, execute, close }: {
53
+ readonly observe?: Store["observe"];
54
+ readonly execute: Store["execute"];
55
+ readonly close?: Store["close"];
56
+ }): Store;
57
+ //# sourceMappingURL=managing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"managing.d.ts","sourceRoot":"","sources":["../../src/stores/managing.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAAE,KAAK,EAA8B,MAAM,aAAa,CAAC;AAGrE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,wBAAgB,mBAAmB,CAAC,EAEnC,OAAO,EACP,OAAO,EAEP,KAA+B,EAE/B,EAAE;IAEF,QAAQ,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,CAAA;IACnC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,CAAA;IAElC,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAA;CAE/B,GAAG,KAAK,CA2HR"}
@@ -0,0 +1,147 @@
1
+ /*
2
+ * Copyright © 2025-2026 Metreeca srl
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { some } from "@grafctory/core/arrays";
17
+ import { isNestedIRI } from "@grafctory/core/resource";
18
+ import { immutable } from "@grafctory/core/values";
19
+ /**
20
+ * Manages mutation events, transactional execution, and lifecycle for a connector's {@link StoreClient},
21
+ * exposing it as a full {@link Store}.
22
+ *
23
+ * A connector can implement only the {@link StoreClient} data surface and still offer the full {@link Store}
24
+ * contract. The connector supplies its transaction primitive through `management.execute`, which hands the
25
+ * connector's {@link StoreClient} to every data call. The option is required, since only the connector knows what
26
+ * atomicity its backend can provide. Backend primitives supplied through `management` may also back `observe` or
27
+ * `close`, and the wrapper fills in whatever is missing.
28
+ *
29
+ * Each standalone mutation call and each {@link Store.execute execute} call delivers a single filtered event to each
30
+ * matching {@link StoreObserver observer} once the call resolves. If the call rejects, its pending events are
31
+ * discarded and no observer is notified. Synchronous throws and asynchronous rejections from observers are caught and
32
+ * silently ignored, so one faulty observer cannot break delivery to others.
33
+ *
34
+ * All errors, including {@link !RangeError RangeError}, {@link @grafctory/core!TraceError | TraceError} and
35
+ * {@link @grafctory/http!Problem | Problem}, propagate as promise rejections, in line with the unified {@link Store}
36
+ * error channel.
37
+ *
38
+ * > [!IMPORTANT]
39
+ * > **Transaction Isolation** — Determined by the supplied `execute` option, typically through a backend
40
+ * > transaction primitive: the wrapper adds neither isolation nor atomicity of its own.
41
+ *
42
+ * > [!IMPORTANT]
43
+ * > **Mutation Events** — emits in-process observer events: each standalone mutation and each
44
+ * > {@link Store.execute execute} call delivers a single filtered batch to matching {@link StoreObserver observer}s
45
+ * > on resolve, and none on rejection. Mutations made by other clients reach local observers only if a
46
+ * > backend-bridging `observe` option is supplied through `management`.
47
+ *
48
+ * @param management - {@link Store} management methods backed by the connector: `execute` is required, and the
49
+ * wrapper fills in whatever else is missing
50
+ * @param management.execute - Transaction wrapper applied to every standalone StoreClient call and to the body of
51
+ * each {@link Store.execute execute} call, typically a backend transaction primitive (for example,
52
+ * `graph.execute` for a SPARQL connector) responsible for atomic commit and rollback. A backend with no
53
+ * transaction primitive supplies a wrapper applying the task directly to its StoreClient, and declares on its
54
+ * factory that a failing task neither rolls back nor isolates its mutations. The option MUST call each task it
55
+ * receives with a `scope` StoreClient dedicated to that call, so per-call state, such as a freshly bound graph
56
+ * buffer, never leaks across concurrent invocations; every data call within the transaction is routed through
57
+ * `scope`. Calls made by a user task inside {@link Store.execute execute} do not open further transactions: they
58
+ * share the outer one. The option MUST convert synchronous throws from the task into promise rejections, to
59
+ * preserve the unified Store error channel: lookups are routed through it with no additional guard
60
+ * @param management.observe - Backend registration for storage-level events, such as mutations made by other clients
61
+ * sharing the backend. Each observer is registered both with this option and locally, and a single detach call
62
+ * releases both registrations. The resource filter always arrives as an array of references, or as `undefined`
63
+ * for an unfiltered registration, so the option never has to handle bare references or single-pass iterables.
64
+ * Absent by default
65
+ * @param management.close - Exposed as is on the returned store. Defaults to a resolved no-op
66
+ *
67
+ * @returns An immutable {@link Store} serving data calls through the supplied `management` opts
68
+ */
69
+ export function createManagingStore({ observe, execute, close = () => Promise.resolve() }) {
70
+ const observers = new Map();
71
+ return immutable({
72
+ lookup: (request, opts) => execute(store => store.lookup(request, opts)),
73
+ create: request => notify(({ mutated }) => execute(store => store.create(request).then(mutated))),
74
+ update: request => notify(({ mutated }) => execute(store => store.update(request).then(mutated))),
75
+ delete: request => notify(({ deleted }) => execute(store => store.delete(request).then(deleted))),
76
+ insert: request => notify(({ mutated }) => execute(store => store.insert(request).then(mutated))),
77
+ remove: request => notify(({ deleted }) => execute(store => store.remove(request).then(deleted))),
78
+ observe(observer, resources) {
79
+ // normalise upfront: the filter is drawn from once, so a single-pass iterable is safely
80
+ // shared between the local registration and the delegate
81
+ const filter = resources === undefined ? undefined : some(resources);
82
+ if (filter?.length === 0) {
83
+ return observe?.(observer, []) ?? (() => { });
84
+ }
85
+ else {
86
+ const token = Symbol();
87
+ const detach = observe?.(observer, filter);
88
+ observers.set(token, { observer, resources: filter });
89
+ return () => {
90
+ try {
91
+ detach?.();
92
+ }
93
+ finally {
94
+ observers.delete(token);
95
+ }
96
+ };
97
+ }
98
+ },
99
+ execute(task) {
100
+ return notify(({ mutated, deleted }) => execute(store => task(immutable({
101
+ lookup: (request, opts) => store.lookup(request, opts),
102
+ create: request => store.create(request).then(mutated),
103
+ update: request => store.update(request).then(mutated),
104
+ delete: request => store.delete(request).then(deleted),
105
+ insert: request => store.insert(request).then(mutated),
106
+ remove: request => store.remove(request).then(deleted)
107
+ }))));
108
+ },
109
+ close
110
+ });
111
+ async function notify(task) {
112
+ const mutations = new Map();
113
+ const value = await task({
114
+ mutated: entry => {
115
+ if (entry !== undefined) {
116
+ mutations.set(entry, true);
117
+ }
118
+ return entry;
119
+ },
120
+ deleted: entry => {
121
+ if (entry !== undefined) {
122
+ mutations.set(entry, false);
123
+ }
124
+ return entry;
125
+ }
126
+ });
127
+ if (mutations.size > 0) {
128
+ observers.forEach(({ observer, resources }) => {
129
+ const event = {};
130
+ mutations.forEach((exists, id) => {
131
+ // `resources` is `undefined` for an unfiltered registration (fires for every mutation)
132
+ // and an array (possibly empty) for a filtered one
133
+ if (resources === undefined || resources.some(r => isNestedIRI(r, id))) {
134
+ event[id] = exists;
135
+ }
136
+ });
137
+ if (Object.keys(event).length > 0) {
138
+ Promise.resolve(event)
139
+ .then(observer)
140
+ .catch(() => { });
141
+ }
142
+ });
143
+ }
144
+ return value;
145
+ }
146
+ }
147
+ //# sourceMappingURL=managing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"managing.js","sourceRoot":"","sources":["../../src/stores/managing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAYH,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAOnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAEnC,OAAO,EACP,OAAO,EAEP,KAAK,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,EAS/B;IAEA,MAAM,SAAS,GAAG,IAAI,GAAG,EAKrB,CAAC;IAEL,OAAO,SAAS,CAAC;QAEhB,MAAM,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAExE,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CA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;oBAErC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;yBACpB,IAAI,CAAC,QAAQ,CAAC;yBACd,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;gBAEpB,CAAC;YAEF,CAAC,CAAC,CAAC;QAEJ,CAAC;QAED,OAAO,KAAK,CAAC;IAEd,CAAC;AAEF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,74 @@
1
1
  {
2
2
  "name": "@grafctory/keep",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.15.0",
4
+ "description": "Core model-driven storage API for @grafctory/keep.",
5
+ "keywords": [
6
+ "typescript",
7
+ "json-ld",
8
+ "model-driven",
9
+ "storage"
10
+ ],
11
+ "homepage": "https://grafctory.github.io/keep/",
12
+ "bugs": {
13
+ "url": "https://github.com/grafctory/keep/issues",
14
+ "email": "info@grafctory.dev"
15
+ },
16
+ "license": "Apache-2.0",
17
+ "author": {
18
+ "name": "Metreeca",
19
+ "email": "info@metreeca.com",
20
+ "url": "https://www.metreeca.com/"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/grafctory/keep.git",
25
+ "directory": "packages/components/keep"
26
+ },
27
+ "type": "module",
28
+ "sideEffects": false,
29
+ "exports": {
30
+ ".": {
31
+ "@grafctory/source": "./src/index.ts",
32
+ "default": "./dist/index.js"
33
+ },
34
+ "./validating": {
35
+ "@grafctory/source": "./src/clients/validating.ts",
36
+ "default": "./dist/clients/validating.js"
37
+ },
38
+ "./batching": {
39
+ "@grafctory/source": "./src/clients/batching.ts",
40
+ "default": "./dist/clients/batching.js"
41
+ },
42
+ "./caching": {
43
+ "@grafctory/source": "./src/stores/caching.ts",
44
+ "default": "./dist/stores/caching.js"
45
+ },
46
+ "./managing": {
47
+ "@grafctory/source": "./src/stores/managing.ts",
48
+ "default": "./dist/stores/managing.js"
49
+ }
50
+ },
51
+ "files": [
52
+ "README.md",
53
+ "LICENSE",
54
+ "dist"
55
+ ],
56
+ "engines": {
57
+ "node": ">=22.22.0"
58
+ },
59
+ "scripts": {
60
+ "clean": "ush rm dist docs node_modules",
61
+ "build": "ush rm dist && tsc -p tsconfig.build.json",
62
+ "check": "npx vitest --typecheck run"
63
+ },
64
+ "dependencies": {
65
+ "@grafctory/blue": "^0.16.0",
66
+ "@grafctory/core": "^0.14.0",
67
+ "@grafctory/http": "^0.6.0",
68
+ "@grafctory/qest": "^0.15.0"
69
+ },
70
+ "devDependencies": {
71
+ "typescript": "^6.0.3",
72
+ "vitest": "^4.0.13"
73
+ }
74
+ }