@procedures/store 0.8.0 → 0.8.1

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +88 -0
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/indexeddb/sync-state-store.d.ts +40 -0
  5. package/dist/indexeddb/sync-state-store.d.ts.map +1 -0
  6. package/dist/indexeddb/sync-state-store.js +94 -0
  7. package/dist/indexeddb/sync-state-store.js.map +1 -0
  8. package/dist/indexeddb.d.ts +7 -2
  9. package/dist/indexeddb.d.ts.map +1 -1
  10. package/dist/indexeddb.js +6 -2
  11. package/dist/indexeddb.js.map +1 -1
  12. package/dist/storage/api.d.ts +84 -11
  13. package/dist/storage/api.d.ts.map +1 -1
  14. package/dist/storage/api.js +148 -25
  15. package/dist/storage/api.js.map +1 -1
  16. package/dist/storage/feed.d.ts +133 -0
  17. package/dist/storage/feed.d.ts.map +1 -0
  18. package/dist/storage/feed.js +159 -0
  19. package/dist/storage/feed.js.map +1 -0
  20. package/dist/storage/hybrid.d.ts +367 -20
  21. package/dist/storage/hybrid.d.ts.map +1 -1
  22. package/dist/storage/hybrid.js +1295 -206
  23. package/dist/storage/hybrid.js.map +1 -1
  24. package/dist/storage/index.d.ts +6 -2
  25. package/dist/storage/index.d.ts.map +1 -1
  26. package/dist/storage/index.js +6 -1
  27. package/dist/storage/index.js.map +1 -1
  28. package/dist/storage/sync-state.d.ts +56 -0
  29. package/dist/storage/sync-state.d.ts.map +1 -0
  30. package/dist/storage/sync-state.js +58 -0
  31. package/dist/storage/sync-state.js.map +1 -0
  32. package/dist/storage/synced-registry.d.ts +22 -4
  33. package/dist/storage/synced-registry.d.ts.map +1 -1
  34. package/dist/storage/synced-registry.js +63 -31
  35. package/dist/storage/synced-registry.js.map +1 -1
  36. package/dist/storage/types.d.ts +22 -1
  37. package/dist/storage/types.d.ts.map +1 -1
  38. package/package.json +4 -3
  39. package/src/indexeddb/sync-state-store.ts +101 -0
  40. package/src/indexeddb.ts +7 -2
  41. package/src/storage/api.ts +210 -29
  42. package/src/storage/feed.ts +251 -0
  43. package/src/storage/hybrid.ts +1404 -211
  44. package/src/storage/index.ts +17 -0
  45. package/src/storage/sync-state.ts +89 -0
  46. package/src/storage/synced-registry.ts +76 -31
  47. package/src/storage/types.ts +25 -1
@@ -6,13 +6,31 @@
6
6
  *
7
7
  * This is the KEY integration between Collections and Universal Client!
8
8
  */
9
- import { optionalMs } from "@procedures/client";
9
+ import { QUERY_OPERATORS, patchProblems, queryEntries, queryOptionsProblems, selectorProblems, } from "@procedures/client/query";
10
+ import { optionalMs, realClock } from "@procedures/client";
11
+ import { backoffDelay } from "@mark1russell7/service/backoff";
12
+ /**
13
+ * The policy of a query that only the server limits: each operator, and no limit of size. The form
14
+ * of the selector must still be correct.
15
+ */
16
+ const FORM_ONLY = Object.freeze({
17
+ operators: QUERY_OPERATORS,
18
+ maxRegexLength: Number.POSITIVE_INFINITY,
19
+ maxClauses: Number.POSITIVE_INFINITY,
20
+ maxDepth: Number.POSITIVE_INFINITY,
21
+ maxListLength: Number.POSITIVE_INFINITY,
22
+ });
10
23
  /** An error that says whether another attempt can succeed (a ClientError does). */
11
24
  function isRetryable(error) {
12
25
  return (typeof error === "object" &&
13
26
  error !== null &&
14
27
  error.retryable === true);
15
28
  }
29
+ /** The wait that an error asks for before a retry, in milliseconds, or 0. */
30
+ function retryAfterOf(error) {
31
+ const value = error?.retryAfterMs;
32
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
33
+ }
16
34
  /** A promise that rejects when the signal aborts first. */
17
35
  function untilAborted(promise, signal, describe) {
18
36
  if (!signal)
@@ -31,6 +49,24 @@ function untilAborted(promise, signal, describe) {
31
49
  });
32
50
  });
33
51
  }
52
+ /** A wait on the clock. The signal stops the wait and its timer. */
53
+ function wait(clock, ms, signal, describe) {
54
+ return new Promise((resolve, reject) => {
55
+ if (signal?.aborted) {
56
+ reject(describe());
57
+ return;
58
+ }
59
+ const onAbort = () => {
60
+ cancel();
61
+ reject(describe());
62
+ };
63
+ const cancel = clock.after(ms, () => {
64
+ signal?.removeEventListener("abort", onAbort);
65
+ resolve();
66
+ });
67
+ signal?.addEventListener("abort", onAbort, { once: true });
68
+ });
69
+ }
34
70
  /** True when the server does not know a procedure: an older server without `ids`. */
35
71
  function isNotFound(error) {
36
72
  return typeof error === "object" && error !== null && error.code === "NOT_FOUND";
@@ -45,6 +81,13 @@ function isFoundOutput(value) {
45
81
  const record = value;
46
82
  return typeof record["found"] === "boolean" && Object.keys(record).every((key) => key === "found" || key === "value");
47
83
  }
84
+ /** The entries of the output `[{ id, value }]` of `entries` or `find`. */
85
+ function entriesOf(output, label) {
86
+ if (!Array.isArray(output) || !output.every((entry) => typeof entry === "object" && entry !== null && typeof entry.id === "string")) {
87
+ throw new Error(`${label} did not return an array of { id, value }`);
88
+ }
89
+ return output.map((entry) => [entry.id, entry.value]);
90
+ }
48
91
  /**
49
92
  * API storage backed by universal client.
50
93
  *
@@ -54,11 +97,16 @@ function isFoundOutput(value) {
54
97
  * - set(id, value) → `collections.<collection>.set` with `{ id, value }`
55
98
  * - setBatch(items) → `collections.<collection>.setBatch` with `{ items: [{ id, value }] }`
56
99
  * - getIds() → `collections.<collection>.ids` with `{}`, or the entries of an older server
100
+ * - query(selector, options) → `collections.<collection>.find` with `{ selector, sort, skip, limit }`
101
+ * - patch(id, fields) → `collections.<collection>.patch` with `{ id, fields }`
57
102
  * - etc.
58
103
  *
59
104
  * Before, the class expected a `{ data }` envelope and called `<service>.get`: no core
60
105
  * procedure matched, and every read was undefined (deep dive CORE-9, DATA-9).
61
106
  *
107
+ * The retries wait with `backoffDelay` of `@mark1russell7/service/backoff` on the clock of the
108
+ * options, with full jitter by default. Before, the waits had no jitter, and they used the timers of the platform directly.
109
+ *
62
110
  * @example
63
111
  * ```typescript
64
112
  * // Create API storage
@@ -71,6 +119,7 @@ function isFoundOutput(value) {
71
119
  * // Operations are automatically sent to server
72
120
  * await storage.set("123", { name: "John" });
73
121
  * const user = await storage.get("123"); // Fetched from server
122
+ * const admins = await storage.query({ role: "admin" }, { sort: { name: 1 }, limit: 50 }); // Runs on the server
74
123
  * ```
75
124
  */
76
125
  export class ApiStorage {
@@ -79,11 +128,19 @@ export class ApiStorage {
79
128
  closed = false;
80
129
  /** True when the server does not know the procedure `ids`: `getIds()` reads the entries */
81
130
  idsUnsupported = false;
131
+ /** True when the server does not know the procedure `find`: `query()` reads the entries */
132
+ findUnsupported = false;
82
133
  constructor(client, options) {
83
134
  const service = options.service ?? (options.collection !== undefined ? `collections.${options.collection}` : undefined);
84
135
  if (!service) {
85
136
  throw new Error("ApiStorage requires a collection or a service");
86
137
  }
138
+ const jitter = options.retryJitter ?? 1;
139
+ if (!(jitter >= 0 && jitter <= 1))
140
+ throw new RangeError(`retryJitter must be from 0 to 1, not ${jitter}`);
141
+ const factor = options.retryFactor ?? 2;
142
+ if (!(Number.isFinite(factor) && factor >= 1))
143
+ throw new RangeError(`retryFactor must be a number of 1 or more, not ${factor}`);
87
144
  this.client = client;
88
145
  this.options = {
89
146
  service,
@@ -95,6 +152,7 @@ export class ApiStorage {
95
152
  ids: "ids",
96
153
  changes: "changes",
97
154
  find: "find",
155
+ patch: "patch",
98
156
  has: "has",
99
157
  size: "size",
100
158
  set: "set",
@@ -107,11 +165,21 @@ export class ApiStorage {
107
165
  },
108
166
  timeout: optionalMs(options.timeout, "timeout") ?? 30000,
109
167
  attempts: options.retry === false ? 1 : options.retry === true || options.retry === undefined ? 3 : Math.max(1, options.retry),
110
- retryDelay: optionalMs(options.retryDelay, "retryDelay") ?? 100,
168
+ backoff: {
169
+ base: optionalMs(options.retryDelay, "retryDelay") ?? 100,
170
+ factor,
171
+ cap: optionalMs(options.maxRetryDelay, "maxRetryDelay") ?? 30000,
172
+ jitter: jitter === 0 ? { kind: "none" } : { kind: "subtract", fraction: jitter },
173
+ },
174
+ clock: options.clock ?? realClock,
175
+ random: options.random ?? Math.random,
176
+ queryPolicy: options.queryPolicy ?? FORM_ONLY,
111
177
  ...(options.signal !== undefined && { signal: options.signal }),
112
178
  closeClient: options.closeClient ?? false,
113
179
  // A custom service can refuse an unknown input field: it gets the input { id }
114
180
  askFound: options.service === undefined && (options.operations?.get ?? "get") === "get",
181
+ // A custom service can refuse an unknown input field: it gets no origin
182
+ sendOrigin: options.service === undefined,
115
183
  };
116
184
  }
117
185
  //
@@ -141,11 +209,7 @@ export class ApiStorage {
141
209
  }
142
210
  /** Every item with its id, from the `entries` procedure of the collection (roadmap R2). */
143
211
  async getEntries() {
144
- const entries = await this.call("entries", {});
145
- if (!Array.isArray(entries)) {
146
- throw new Error(`${this.options.service}.entries did not return an array`);
147
- }
148
- return entries.map((entry) => [entry.id, entry.value]);
212
+ return entriesOf(await this.call("entries", {}), `${this.options.service}.entries`);
149
213
  }
150
214
  /**
151
215
  * The ids of the items in the order of the entries, from the `ids` procedure of the collection.
@@ -187,11 +251,47 @@ export class ApiStorage {
187
251
  deleted: result.deleted,
188
252
  };
189
253
  }
254
+ /**
255
+ * The items for which the predicate gives true. A function cannot go over the network, so this
256
+ * method reads all items and filters here. `query()` sends a JSON selector to the server.
257
+ */
190
258
  async find(predicate) {
191
- // A predicate cannot go over the network: read all items, then filter here
192
259
  const all = await this.getAll();
193
260
  return all.filter(predicate);
194
261
  }
262
+ /**
263
+ * The entries whose items match the selector, from the `find` procedure of the collection: the
264
+ * server runs the selector, the order, the skip and the limit (roadmap CLI-14), under its own
265
+ * query policy. An older server without the procedure answers `NOT_FOUND`. Then this call and
266
+ * each later call read the entries and run the query here, with the same result.
267
+ *
268
+ * @param policy - The policy that the storage applies before it sends the query. The default is
269
+ * the option `queryPolicy`. The server applies its own policy too.
270
+ */
271
+ async query(selector, options = {}, policy) {
272
+ // A selector with a problem does not go to the server: the server would refuse it
273
+ const limits = policy ?? this.options.queryPolicy;
274
+ const problems = [...selectorProblems(selector, limits), ...queryOptionsProblems(options, limits)];
275
+ if (problems.length > 0)
276
+ throw new TypeError(`The query is not correct: ${problems.join(". ")}`);
277
+ if (!this.findUnsupported) {
278
+ const input = {
279
+ selector,
280
+ ...(options.sort !== undefined && { sort: options.sort }),
281
+ ...(options.skip !== undefined && { skip: options.skip }),
282
+ ...(options.limit !== undefined && { limit: options.limit }),
283
+ };
284
+ try {
285
+ return entriesOf(await this.call("find", input), `${this.options.service}.find`);
286
+ }
287
+ catch (error) {
288
+ if (!isNotFound(error))
289
+ throw error;
290
+ this.findUnsupported = true;
291
+ }
292
+ }
293
+ return queryEntries(await this.getEntries(), selector, options, limits);
294
+ }
195
295
  async has(id) {
196
296
  return (await this.call("has", { id })) === true;
197
297
  }
@@ -201,24 +301,42 @@ export class ApiStorage {
201
301
  //
202
302
  // ═══ Write Operations ═══
203
303
  //
204
- async set(id, value) {
205
- await this.call("set", { id, value });
304
+ /**
305
+ * This method sets an item on the server. The origin of the options goes to the procedure `set`,
306
+ * so the storage of the server and the change event of the write have it (roadmap CLI-15).
307
+ */
308
+ async set(id, value, options) {
309
+ await this.call("set", { id, value, ...this.originOf(options) });
206
310
  }
207
- async delete(id) {
208
- return (await this.call("delete", { id })) === true;
311
+ async delete(id, options) {
312
+ return (await this.call("delete", { id, ...this.originOf(options) })) === true;
209
313
  }
210
- async clear() {
211
- await this.call("clear", {});
314
+ async clear(options) {
315
+ await this.call("clear", { ...this.originOf(options) });
316
+ }
317
+ /**
318
+ * This method changes an item on the server in one step: the `patch` procedure of the collection
319
+ * (roadmap CLI-14). The fields are a JSON Merge Patch, or the operations `$set` and `$unset`.
320
+ * It gives the new item, or undefined for a missing id.
321
+ */
322
+ async patch(id, fields, options) {
323
+ const [problem] = patchProblems(fields);
324
+ if (problem !== undefined)
325
+ throw new TypeError(`The patch of ${id} is not correct: ${problem}`);
326
+ const result = await this.call("patch", { id, fields, ...this.originOf(options) });
327
+ if (!isFoundOutput(result))
328
+ throw new Error(`${this.options.service}.patch did not return { found, value }`);
329
+ return result.found ? result.value : undefined;
212
330
  }
213
331
  //
214
332
  // ═══ Bulk Operations ═══
215
333
  //
216
- async setBatch(items) {
334
+ async setBatch(items, options) {
217
335
  // The collection procedure takes objects, not tuples
218
- await this.call("setBatch", { items: items.map(([id, value]) => ({ id, value })) });
336
+ await this.call("setBatch", { items: items.map(([id, value]) => ({ id, value })), ...this.originOf(options) });
219
337
  }
220
- async deleteBatch(ids) {
221
- return Number(await this.call("deleteBatch", { ids }));
338
+ async deleteBatch(ids, options) {
339
+ return Number(await this.call("deleteBatch", { ids, ...this.originOf(options) }));
222
340
  }
223
341
  async getBatch(ids) {
224
342
  const values = (await this.call("getBatch", { ids })) ?? {};
@@ -260,8 +378,14 @@ export class ApiStorage {
260
378
  //
261
379
  // ═══ Internal Helpers ═══
262
380
  //
381
+ /** The field `origin` of a write input, or no field: a custom service gets no origin. */
382
+ originOf(options) {
383
+ return this.options.sendOrigin && options?.origin !== undefined ? { origin: options.origin } : {};
384
+ }
263
385
  /**
264
- * Make an RPC call via the universal client, with the timeout, the signal and the retries.
386
+ * Make an RPC call via the universal client, with the timeout, the signal and the retries. The
387
+ * wait before retry `n` is `backoffDelay(backoff, n)`, or the wait that the error asks for when
388
+ * it is longer.
265
389
  */
266
390
  async call(operation, payload) {
267
391
  if (this.closed)
@@ -280,8 +404,8 @@ export class ApiStorage {
280
404
  if (attempt >= this.options.attempts || !isRetryable(error) || this.options.signal?.aborted) {
281
405
  throw error;
282
406
  }
283
- const delay = this.options.retryDelay * 2 ** (attempt - 1);
284
- await untilAborted(new Promise((resolve) => setTimeout(resolve, delay)), this.options.signal, () => error);
407
+ const delay = Math.max(backoffDelay(this.options.backoff, attempt, this.options.random), retryAfterOf(error));
408
+ await wait(this.options.clock, delay, this.options.signal, () => error);
285
409
  }
286
410
  }
287
411
  }
@@ -291,9 +415,9 @@ export class ApiStorage {
291
415
  if (this.options.signal)
292
416
  signals.push(this.options.signal);
293
417
  const timer = this.options.timeout > 0 ? new AbortController() : undefined;
294
- let timeoutHandle;
418
+ let cancelTimeout;
295
419
  if (timer) {
296
- timeoutHandle = setTimeout(() => timer.abort(), this.options.timeout);
420
+ cancelTimeout = this.options.clock.after(this.options.timeout, () => timer.abort());
297
421
  signals.push(timer.signal);
298
422
  }
299
423
  const signal = signals.length === 0 ? undefined : signals.length === 1 ? signals[0] : AbortSignal.any(signals);
@@ -306,8 +430,7 @@ export class ApiStorage {
306
430
  callOptions.signal = signal;
307
431
  const call = this.client.call(method, payload, callOptions);
308
432
  return untilAborted(call, signal, () => timer?.signal.aborted ? new Error(`${label} timed out after ${this.options.timeout} ms`) : new Error(`${label} was aborted`)).finally(() => {
309
- if (timeoutHandle !== undefined)
310
- clearTimeout(timeoutHandle);
433
+ cancelTimeout?.();
311
434
  });
312
435
  }
313
436
  }
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/storage/api.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,EAAE,UAAU,EAAiB,MAAM,oBAAoB,CAAC;AA6E/D,mFAAmF;AACnF,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACb,KAAiC,CAAC,SAAS,KAAK,IAAI,CACtD,CAAC;AACJ,CAAC;AAED,2DAA2D;AAC3D,SAAS,YAAY,CAAI,OAAmB,EAAE,MAA+B,EAAE,QAAqB;IAClG,IAAI,CAAC,MAAM;QAAE,OAAO,OAAO,CAAC;IAC5B,IAAI,MAAM,CAAC,OAAO;QAAE,OAAO,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;IACtD,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACxC,MAAM,OAAO,GAAG,GAAS,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC/C,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,I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,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC7B,CAAC;QACD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAE/G,2FAA2F;QAC3F,6EAA6E;QAC7E,8FAA8F;QAC9F,sDAAsD;QACtD,MAAM,WAAW,GAAyB,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;QACrF,IAAI,MAAM;YAAE,WAAW,CAAC,MAAM,GAAG,MAAM,CAAC;QACxC,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAgB,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;QAC3E,OAAO,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CACrC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,GAAG,KAAK,oBAAoB,IAAI,CAAC,OAAO,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,GAAG,KAAK,cAAc,CAAC,CAC7H,CAAC,OAAO,CAAC,GAAG,EAAE;YACb,aAAa,EAAE,EAAE,CAAC;QACpB,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,133 @@
1
+ /**
2
+ * The push feed of the remote changes of a `HybridStorage` (roadmap CLI-21, CLI-15).
3
+ *
4
+ * A `RemoteChangeFeed` pushes the deltas of the remote. When the `since` of a delta is the cursor
5
+ * of the storage, the storage applies the delta without a read. A gap, a lost event or a new
6
+ * subscription makes the storage read the changes since its cursor. Thus the feed replaces most
7
+ * of the periodic pulls, and the pulls stay correct when the feed loses an event.
8
+ *
9
+ * `EventsChangeFeed` is the feed of the change events of the core collection procedures: the topic
10
+ * `collections.<name>` of `events.subscribe` (`documentation/EVENTS.md`). By default, an event has
11
+ * only the ids and the versions: the feed gives it as a hint, and the storage reads the values
12
+ * with a pull, through the checks of a read. The file imports no module of Node, so it runs in a
13
+ * browser.
14
+ */
15
+ import type { StorageChanges } from "@procedures/collections";
16
+ import { type RemoteEvent, type SubscribeOptions, type Subscription, type SubscriptionError } from "@procedures/client";
17
+ import type { EventTransport } from "@procedures/client/events";
18
+ /**
19
+ * A delta of the remote that a feed pushes: the changes between two versions of the remote. The
20
+ * changes have the form of `getChangesSince()`.
21
+ */
22
+ export interface RemoteChanges<T> extends StorageChanges<T> {
23
+ /**
24
+ * The version of the remote before the changes. A storage applies the delta without a read only
25
+ * when this version is its cursor. Without it, the storage reads the changes.
26
+ */
27
+ readonly since?: string | undefined;
28
+ /** The origin of the writes of the delta, when one origin made all of them. */
29
+ readonly origin?: string | undefined;
30
+ }
31
+ /**
32
+ * A hint of the remote (roadmap CLI-15): the ids that changed between two versions, without their
33
+ * values. A value reaches a subscriber only through a read, with the checks of a read.
34
+ */
35
+ export interface RemoteChangeHint {
36
+ /** The version of the remote before the changes, or undefined when the chain of versions starts. */
37
+ readonly since?: string | undefined;
38
+ /** The version of the remote after the changes, or undefined for a remote without a change log. */
39
+ readonly version?: string | undefined;
40
+ /** The ids of the items that changed: the listener reads their values. */
41
+ readonly changed: readonly string[];
42
+ /** The ids that were deleted. A delete needs no value. */
43
+ readonly deleted: readonly string[];
44
+ /** The origin of the writes, when one origin made all of them. */
45
+ readonly origin?: string | undefined;
46
+ }
47
+ /** The functions that get the pushes of a feed. */
48
+ export interface RemoteChangeListener<T> {
49
+ /** This function gets a delta of the remote with its values. The listener applies it, or reads the changes. */
50
+ onChanges(changes: RemoteChanges<T>): void;
51
+ /**
52
+ * This function gets a hint without values. The listener reads the changes, or applies the
53
+ * deletes when no value changed. Without it, a hint goes to `onGap()`.
54
+ */
55
+ onHint?(hint: RemoteChangeHint): void;
56
+ /**
57
+ * This function tells that the feed can have lost changes: a gap of the events, a lost event, or
58
+ * a new subscription. The listener reads the changes since its cursor.
59
+ */
60
+ onGap(): void;
61
+ /** This function gets the error that stops the feed. The listener then reads the changes only with its pulls. */
62
+ onError?(error: unknown): void;
63
+ }
64
+ /** A push feed of the changes of a remote storage (roadmap CLI-21). */
65
+ export interface RemoteChangeFeed<T> {
66
+ /**
67
+ * This method starts to push the changes to a listener. Each new subscription calls `onGap()`
68
+ * when it starts, so the listener reads the changes that came before it.
69
+ *
70
+ * @returns The function that stops the pushes. A second use of it does nothing.
71
+ */
72
+ subscribe(listener: RemoteChangeListener<T>): () => void;
73
+ }
74
+ /**
75
+ * An object that subscribes to the topics of the event bus of a server: a `Client`, or a
76
+ * `WebSocketTransport` of `@procedures/client`.
77
+ */
78
+ export interface EventSubscriber {
79
+ subscribe<E = unknown>(topics: string | readonly string[], handler: (data: E, event: RemoteEvent<E>) => void | Promise<void>, options?: SubscribeOptions): Subscription;
80
+ }
81
+ /** The source of the events of an `EventsChangeFeed`: an `EventSubscriber`, or a transport. */
82
+ export type ChangeEventSource = EventSubscriber | EventTransport;
83
+ /** The options of an `EventsChangeFeed`. */
84
+ export interface EventsChangeFeedOptions {
85
+ /** The collection of the core collection procedures. The topic is `collections.<collection>`. */
86
+ collection?: string | undefined;
87
+ /** The topic of the change events, for example with a partition. It comes before `collection`. */
88
+ topic?: string | undefined;
89
+ /**
90
+ * The options of the subscription: the resubscribe rules, the backoff, the clock and the
91
+ * metadata of the call. The feed gives `onSubscribed` and `onError` itself.
92
+ * @default `{ maxAttempts: Infinity }`: the feed resubscribes until it stops
93
+ */
94
+ subscription?: Omit<SubscribeOptions, "onSubscribed" | "onError"> | undefined;
95
+ /** This function gets the error that ends the subscription, for example `TOPIC_NOT_FOUND`. */
96
+ onError?: ((error: SubscriptionError) => void) | undefined;
97
+ }
98
+ /**
99
+ * The push feed of the change events of the core collection procedures (roadmap CLI-15). It
100
+ * subscribes to the topic `collections.<name>` with `events.subscribe`. The delivery of the events
101
+ * is at most once, so the feed treats them as hints:
102
+ *
103
+ * - An event without values (the default of the procedures) or with withheld values goes to
104
+ * `onHint()`. The storage reads the values with a pull, so each value passes the checks of a
105
+ * read. A hint with only deletes applies without a pull when `since` is the cursor.
106
+ * - An event with the values of each changed id (the option `values` of the procedures) goes to
107
+ * `onChanges()`. The storage applies it without a read when `since` is its cursor.
108
+ * - A gap of the numbers of the events, a lost event (`dropped`), an event of another form, and
109
+ * each confirmation of the subscription (the first one and each resubscribe) call `onGap()`.
110
+ * - The error that ends the subscription goes to `onError` of the options and of the listener.
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * const users = new HybridStorage(new ApiStorage(client, { collection: "users" }), {
115
+ * versionOf: (user) => user.rev,
116
+ * feed: new EventsChangeFeed(client, { collection: "users" }),
117
+ * });
118
+ * ```
119
+ */
120
+ export declare class EventsChangeFeed<T> implements RemoteChangeFeed<T> {
121
+ /** The topic of the change events. */
122
+ readonly topic: string;
123
+ private readonly source;
124
+ private readonly subscription;
125
+ private readonly onError;
126
+ /**
127
+ * @param source - A `Client` or a `WebSocketTransport`, or another transport of the client
128
+ * @param options - The collection or the topic, and the options of the subscription
129
+ */
130
+ constructor(source: ChangeEventSource, options: EventsChangeFeedOptions);
131
+ subscribe(listener: RemoteChangeListener<T>): () => void;
132
+ }
133
+ //# sourceMappingURL=feed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feed.d.ts","sourceRoot":"","sources":["../../src/storage/feed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,cAAc,EAA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ote changes of a `HybridStorage` (roadmap CLI-21, CLI-15).
3
+ *
4
+ * A `RemoteChangeFeed` pushes the deltas of the remote. When the `since` of a delta is the cursor
5
+ * of the storage, the storage applies the delta without a read. A gap, a lost event or a new
6
+ * subscription makes the storage read the changes since its cursor. Thus the feed replaces most
7
+ * of the periodic pulls, and the pulls stay correct when the feed loses an event.
8
+ *
9
+ * `EventsChangeFeed` is the feed of the change events of the core collection procedures: the topic
10
+ * `collections.<name>` of `events.subscribe` (`documentation/EVENTS.md`). By default, an event has
11
+ * only the ids and the versions: the feed gives it as a hint, and the storage reads the values
12
+ * with a pull, through the checks of a read. The file imports no module of Node, so it runs in a
13
+ * browser.
14
+ */
15
+ import { collectionChangeTopic, subscribeRemote, } from "@procedures/client";
16
+ /** True for a source with `subscribe()`: it subscribes itself. */
17
+ function isSubscriber(source) {
18
+ return typeof source.subscribe === "function";
19
+ }
20
+ /** True for a string, or for no value. */
21
+ const optionalString = (value) => value === undefined || typeof value === "string";
22
+ /** True for a list of ids. */
23
+ const isIds = (value) => Array.isArray(value) && value.every((id) => typeof id === "string");
24
+ /**
25
+ * The delta or the hint of a change event of the collection procedures, or undefined for an
26
+ * event of another form. The event comes over the wire: the function examines each field.
27
+ *
28
+ * - An event with `since`, `version` and a value for each changed id is a delta: `changes`.
29
+ * - Each other event is a hint: an event without values, an event with withheld values (the
30
+ * filter of the host refused them), or a hint of a storage without a change log.
31
+ */
32
+ function eventOf(data) {
33
+ if (typeof data !== "object" || data === null)
34
+ return undefined;
35
+ const event = data;
36
+ const { since, version, origin } = event;
37
+ if (!optionalString(since) || !optionalString(version) || !optionalString(origin))
38
+ return undefined;
39
+ if (!isIds(event.changed) || !isIds(event.deleted) || (event.withheld !== undefined && !isIds(event.withheld)))
40
+ return undefined;
41
+ let values;
42
+ if (event.values !== undefined) {
43
+ if (!Array.isArray(event.values))
44
+ return undefined;
45
+ values = [];
46
+ for (const value of event.values) {
47
+ const entry = value;
48
+ if (typeof entry !== "object" || entry === null || typeof entry.id !== "string" || !("value" in entry))
49
+ return undefined;
50
+ values.push([entry.id, entry.value]);
51
+ }
52
+ }
53
+ const withOrigin = origin !== undefined ? { origin } : {};
54
+ const valued = new Set(values?.map(([id]) => id));
55
+ const withheld = event.withheld ?? [];
56
+ const complete = values !== undefined && withheld.length === 0 && event.changed.every((id) => valued.has(id));
57
+ if (since !== undefined && version !== undefined && complete) {
58
+ return { changes: { since, version, full: false, changed: values, deleted: event.deleted, ...withOrigin } };
59
+ }
60
+ return {
61
+ hint: {
62
+ ...(since !== undefined && { since }),
63
+ ...(version !== undefined && { version }),
64
+ changed: event.changed,
65
+ deleted: event.deleted,
66
+ ...withOrigin,
67
+ },
68
+ };
69
+ }
70
+ /**
71
+ * The push feed of the change events of the core collection procedures (roadmap CLI-15). It
72
+ * subscribes to the topic `collections.<name>` with `events.subscribe`. The delivery of the events
73
+ * is at most once, so the feed treats them as hints:
74
+ *
75
+ * - An event without values (the default of the procedures) or with withheld values goes to
76
+ * `onHint()`. The storage reads the values with a pull, so each value passes the checks of a
77
+ * read. A hint with only deletes applies without a pull when `since` is the cursor.
78
+ * - An event with the values of each changed id (the option `values` of the procedures) goes to
79
+ * `onChanges()`. The storage applies it without a read when `since` is its cursor.
80
+ * - A gap of the numbers of the events, a lost event (`dropped`), an event of another form, and
81
+ * each confirmation of the subscription (the first one and each resubscribe) call `onGap()`.
82
+ * - The error that ends the subscription goes to `onError` of the options and of the listener.
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * const users = new HybridStorage(new ApiStorage(client, { collection: "users" }), {
87
+ * versionOf: (user) => user.rev,
88
+ * feed: new EventsChangeFeed(client, { collection: "users" }),
89
+ * });
90
+ * ```
91
+ */
92
+ export class EventsChangeFeed {
93
+ /** The topic of the change events. */
94
+ topic;
95
+ source;
96
+ subscription;
97
+ onError;
98
+ /**
99
+ * @param source - A `Client` or a `WebSocketTransport`, or another transport of the client
100
+ * @param options - The collection or the topic, and the options of the subscription
101
+ */
102
+ constructor(source, options) {
103
+ const topic = options.topic ?? (options.collection !== undefined ? collectionChangeTopic(options.collection) : undefined);
104
+ if (topic === undefined || topic === "")
105
+ throw new TypeError("EventsChangeFeed needs a collection or a topic");
106
+ this.topic = topic;
107
+ this.source = source;
108
+ this.subscription = { maxAttempts: Number.POSITIVE_INFINITY, ...options.subscription };
109
+ this.onError = options.onError;
110
+ }
111
+ subscribe(listener) {
112
+ /** The number of the next event: a resubscribe starts again at 1 */
113
+ let next = 1;
114
+ let stopped = false;
115
+ const handler = (data, event) => {
116
+ if (stopped)
117
+ return;
118
+ const lost = event.dropped > 0 || event.seq !== next;
119
+ next = event.seq + 1;
120
+ if (lost)
121
+ listener.onGap();
122
+ const parsed = eventOf(data);
123
+ if (parsed === undefined)
124
+ listener.onGap();
125
+ else if ("changes" in parsed)
126
+ listener.onChanges(parsed.changes);
127
+ // A hint: the listener reads the values with a read of its own
128
+ else if (listener.onHint)
129
+ listener.onHint(parsed.hint);
130
+ else
131
+ listener.onGap();
132
+ };
133
+ const options = {
134
+ ...this.subscription,
135
+ onSubscribed: () => {
136
+ if (stopped)
137
+ return;
138
+ next = 1;
139
+ listener.onGap();
140
+ },
141
+ onError: (error) => {
142
+ if (stopped)
143
+ return;
144
+ this.onError?.(error);
145
+ listener.onError?.(error);
146
+ },
147
+ };
148
+ const unsubscribe = isSubscriber(this.source)
149
+ ? this.source.subscribe(this.topic, handler, options)
150
+ : subscribeRemote(this.source, this.topic, handler, options);
151
+ return () => {
152
+ if (stopped)
153
+ return;
154
+ stopped = true;
155
+ unsubscribe();
156
+ };
157
+ }
158
+ }
159
+ //# sourceMappingURL=feed.js.map