@relate/contrib-web 0.0.0-stage → 0.1.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.
Files changed (191) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +242 -2
  3. package/conformance/example-site/blank.html +2 -0
  4. package/conformance/example-site/broken.html +35 -0
  5. package/conformance/example-site/index.html +35 -0
  6. package/conformance/example-site/notes.html +35 -0
  7. package/conformance/example-site/page-1.html +35 -0
  8. package/conformance/example-site/page-2.html +35 -0
  9. package/conformance/example-site/public/descriptor-b.json +16 -0
  10. package/conformance/example-site/public/descriptor-broken.json +16 -0
  11. package/conformance/example-site/public/descriptor-mismatch.json +16 -0
  12. package/conformance/example-site/public/descriptor.json +16 -0
  13. package/conformance/example-site/public/graph-b.json +14408 -0
  14. package/conformance/example-site/public/graph.json +10808 -0
  15. package/conformance/example-site/rel-page.ts +147 -0
  16. package/conformance/example-site/vite.config.ts +23 -0
  17. package/conformance/make-example.ts +22 -0
  18. package/conformance/run.ts +152 -0
  19. package/conformance/scenarios.ts +285 -0
  20. package/dist/application/options.d.ts +9 -0
  21. package/dist/application/options.js +64 -0
  22. package/dist/application/options.js.map +1 -0
  23. package/dist/application/ranges.d.ts +7 -0
  24. package/dist/application/ranges.js +14 -0
  25. package/dist/application/ranges.js.map +1 -0
  26. package/dist/application/storage.d.ts +34 -0
  27. package/dist/application/storage.js +60 -0
  28. package/dist/application/storage.js.map +1 -0
  29. package/dist/application/types.d.ts +49 -0
  30. package/dist/application/types.js +2 -0
  31. package/dist/application/types.js.map +1 -0
  32. package/dist/build/canonical.d.ts +5 -0
  33. package/dist/build/canonical.js +26 -0
  34. package/dist/build/canonical.js.map +1 -0
  35. package/dist/build/descriptor.d.ts +16 -0
  36. package/dist/build/descriptor.js +13 -0
  37. package/dist/build/descriptor.js.map +1 -0
  38. package/dist/build/index.d.ts +6 -0
  39. package/dist/build/index.js +6 -0
  40. package/dist/build/index.js.map +1 -0
  41. package/dist/build/inline.d.ts +16 -0
  42. package/dist/build/inline.js +44 -0
  43. package/dist/build/inline.js.map +1 -0
  44. package/dist/build/prepare.d.ts +11 -0
  45. package/dist/build/prepare.js +25 -0
  46. package/dist/build/prepare.js.map +1 -0
  47. package/dist/catalog/api.d.ts +30 -0
  48. package/dist/catalog/api.js +56 -0
  49. package/dist/catalog/api.js.map +1 -0
  50. package/dist/catalog/catalog.d.ts +51 -0
  51. package/dist/catalog/catalog.js +104 -0
  52. package/dist/catalog/catalog.js.map +1 -0
  53. package/dist/catalog/directory.d.ts +30 -0
  54. package/dist/catalog/directory.js +116 -0
  55. package/dist/catalog/directory.js.map +1 -0
  56. package/dist/catalog/file.d.ts +12 -0
  57. package/dist/catalog/file.js +84 -0
  58. package/dist/catalog/file.js.map +1 -0
  59. package/dist/catalog/index.d.ts +10 -0
  60. package/dist/catalog/index.js +12 -0
  61. package/dist/catalog/index.js.map +1 -0
  62. package/dist/catalog/memory-storage.d.ts +16 -0
  63. package/dist/catalog/memory-storage.js +56 -0
  64. package/dist/catalog/memory-storage.js.map +1 -0
  65. package/dist/catalog/opfs-storage.d.ts +10 -0
  66. package/dist/catalog/opfs-storage.js +71 -0
  67. package/dist/catalog/opfs-storage.js.map +1 -0
  68. package/dist/catalog/remove.d.ts +21 -0
  69. package/dist/catalog/remove.js +85 -0
  70. package/dist/catalog/remove.js.map +1 -0
  71. package/dist/catalog/storage.d.ts +11 -0
  72. package/dist/catalog/storage.js +4 -0
  73. package/dist/catalog/storage.js.map +1 -0
  74. package/dist/catalog/types.d.ts +68 -0
  75. package/dist/catalog/types.js +4 -0
  76. package/dist/catalog/types.js.map +1 -0
  77. package/dist/client/application.d.ts +32 -0
  78. package/dist/client/application.js +99 -0
  79. package/dist/client/application.js.map +1 -0
  80. package/dist/client/client.d.ts +2 -0
  81. package/dist/client/client.js +445 -0
  82. package/dist/client/client.js.map +1 -0
  83. package/dist/client/diagnostic.d.ts +6 -0
  84. package/dist/client/diagnostic.js +35 -0
  85. package/dist/client/diagnostic.js.map +1 -0
  86. package/dist/client/events.d.ts +27 -0
  87. package/dist/client/events.js +31 -0
  88. package/dist/client/events.js.map +1 -0
  89. package/dist/client/failure.d.ts +13 -0
  90. package/dist/client/failure.js +40 -0
  91. package/dist/client/failure.js.map +1 -0
  92. package/dist/client/scope.d.ts +15 -0
  93. package/dist/client/scope.js +39 -0
  94. package/dist/client/scope.js.map +1 -0
  95. package/dist/client/status.d.ts +14 -0
  96. package/dist/client/status.js +34 -0
  97. package/dist/client/status.js.map +1 -0
  98. package/dist/client/subscriptions.d.ts +31 -0
  99. package/dist/client/subscriptions.js +64 -0
  100. package/dist/client/subscriptions.js.map +1 -0
  101. package/dist/client/types.d.ts +82 -0
  102. package/dist/client/types.js +2 -0
  103. package/dist/client/types.js.map +1 -0
  104. package/dist/config.d.ts +30 -0
  105. package/dist/config.js +28 -0
  106. package/dist/config.js.map +1 -0
  107. package/dist/conformance/run.d.ts +61 -0
  108. package/dist/conformance/run.js +121 -0
  109. package/dist/conformance/run.js.map +1 -0
  110. package/dist/conformance/scenarios.d.ts +25 -0
  111. package/dist/conformance/scenarios.js +257 -0
  112. package/dist/conformance/scenarios.js.map +1 -0
  113. package/dist/data/descriptor.d.ts +20 -0
  114. package/dist/data/descriptor.js +75 -0
  115. package/dist/data/descriptor.js.map +1 -0
  116. package/dist/data/types.d.ts +41 -0
  117. package/dist/data/types.js +3 -0
  118. package/dist/data/types.js.map +1 -0
  119. package/dist/data/validate.d.ts +22 -0
  120. package/dist/data/validate.js +118 -0
  121. package/dist/data/validate.js.map +1 -0
  122. package/dist/errors.d.ts +9 -0
  123. package/dist/errors.js +14 -0
  124. package/dist/errors.js.map +1 -0
  125. package/dist/index.d.ts +17 -0
  126. package/dist/index.js +8 -0
  127. package/dist/index.js.map +1 -0
  128. package/dist/profiles/index.d.ts +5 -0
  129. package/dist/profiles/index.js +9 -0
  130. package/dist/profiles/index.js.map +1 -0
  131. package/dist/profiles/per-page.d.ts +2 -0
  132. package/dist/profiles/per-page.js +11 -0
  133. package/dist/profiles/per-page.js.map +1 -0
  134. package/dist/profiles/persistent.d.ts +5 -0
  135. package/dist/profiles/persistent.js +14 -0
  136. package/dist/profiles/persistent.js.map +1 -0
  137. package/dist/validate.d.ts +5 -0
  138. package/dist/validate.js +4 -0
  139. package/dist/validate.js.map +1 -0
  140. package/dist/worker/application/classify.d.ts +30 -0
  141. package/dist/worker/application/classify.js +57 -0
  142. package/dist/worker/application/classify.js.map +1 -0
  143. package/dist/worker/application/init.d.ts +12 -0
  144. package/dist/worker/application/init.js +64 -0
  145. package/dist/worker/application/init.js.map +1 -0
  146. package/dist/worker/application/lifecycle.d.ts +29 -0
  147. package/dist/worker/application/lifecycle.js +86 -0
  148. package/dist/worker/application/lifecycle.js.map +1 -0
  149. package/dist/worker/application/losses.d.ts +11 -0
  150. package/dist/worker/application/losses.js +61 -0
  151. package/dist/worker/application/losses.js.map +1 -0
  152. package/dist/worker/application/migrate.d.ts +16 -0
  153. package/dist/worker/application/migrate.js +54 -0
  154. package/dist/worker/application/migrate.js.map +1 -0
  155. package/dist/worker/application/open-store.d.ts +31 -0
  156. package/dist/worker/application/open-store.js +60 -0
  157. package/dist/worker/application/open-store.js.map +1 -0
  158. package/dist/worker/application/seed.d.ts +14 -0
  159. package/dist/worker/application/seed.js +50 -0
  160. package/dist/worker/application/seed.js.map +1 -0
  161. package/dist/worker/application/transfer.d.ts +31 -0
  162. package/dist/worker/application/transfer.js +134 -0
  163. package/dist/worker/application/transfer.js.map +1 -0
  164. package/dist/worker/cache.d.ts +15 -0
  165. package/dist/worker/cache.js +45 -0
  166. package/dist/worker/cache.js.map +1 -0
  167. package/dist/worker/encode.d.ts +1 -0
  168. package/dist/worker/encode.js +43 -0
  169. package/dist/worker/encode.js.map +1 -0
  170. package/dist/worker/engine.d.ts +35 -0
  171. package/dist/worker/engine.js +99 -0
  172. package/dist/worker/engine.js.map +1 -0
  173. package/dist/worker/legacy-copy.d.ts +2 -0
  174. package/dist/worker/legacy-copy.js +19 -0
  175. package/dist/worker/legacy-copy.js.map +1 -0
  176. package/dist/worker/loader.d.ts +40 -0
  177. package/dist/worker/loader.js +96 -0
  178. package/dist/worker/loader.js.map +1 -0
  179. package/dist/worker/protocol.d.ts +121 -0
  180. package/dist/worker/protocol.js +2 -0
  181. package/dist/worker/protocol.js.map +1 -0
  182. package/dist/worker/store.d.ts +12 -0
  183. package/dist/worker/store.js +39 -0
  184. package/dist/worker/store.js.map +1 -0
  185. package/dist/worker/sweep.d.ts +8 -0
  186. package/dist/worker/sweep.js +21 -0
  187. package/dist/worker/sweep.js.map +1 -0
  188. package/dist/worker/worker.d.ts +1 -0
  189. package/dist/worker/worker.js +198 -0
  190. package/dist/worker/worker.js.map +1 -0
  191. package/package.json +81 -3
@@ -0,0 +1,60 @@
1
+ // Opening an application's store (ADR-009 2.4): the bounded retry of ADR-001, then waiting (or memory) for a locked
2
+ // store, memory or failure for a browser with no store, and failure by default for any other open error.
3
+ import { catalogSupported } from "../../catalog/opfs-storage.js";
4
+ import { APP_STORE_PREFIX, WAIT_RETRY_MS } from "../../config.js";
5
+ import { Engine, StorageLockedError } from "../engine.js";
6
+ import { retryWaits } from "../store.js";
7
+ const defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
8
+ /** True when the browser gives this worker an origin-private file system and Web Locks, which the catalog needs (ADR-010 2.2). */
9
+ export async function storageAvailable() {
10
+ try {
11
+ if (!catalogSupported())
12
+ return false;
13
+ await navigator.storage.getDirectory();
14
+ return true;
15
+ }
16
+ catch {
17
+ return false;
18
+ }
19
+ }
20
+ const messageOf = (e) => (e instanceof Error ? e.message : String(e));
21
+ export async function openApplicationStore(app, hooks) {
22
+ const open = hooks.open ?? ((name) => Engine.store(name, APP_STORE_PREFIX));
23
+ const sleep = hooks.sleep ?? defaultSleep;
24
+ if (!(await (hooks.hasStorage ?? storageAvailable)())) {
25
+ if (app.onUnavailable === "fail")
26
+ return { fail: "unavailable", message: "the browser offers no storage for this application" };
27
+ return { engine: Engine.memory(), storage: { kind: "memory", reason: "unavailable" } };
28
+ }
29
+ const attempt = async () => {
30
+ try {
31
+ return { engine: await open(app.name), storage: { kind: "durable" } };
32
+ }
33
+ catch (e) {
34
+ if (e instanceof StorageLockedError)
35
+ return "locked";
36
+ if (app.onError === "memory")
37
+ return { engine: Engine.memory(), storage: { kind: "memory", reason: "error" } };
38
+ return { fail: "store-unreadable", message: messageOf(e) };
39
+ }
40
+ };
41
+ let outcome = await attempt();
42
+ for (const wait of hooks.waits ? hooks.waits() : retryWaits()) {
43
+ if (outcome !== "locked")
44
+ return outcome;
45
+ await sleep(wait);
46
+ outcome = await attempt();
47
+ }
48
+ if (outcome !== "locked")
49
+ return outcome;
50
+ if (app.whenLocked === "memory")
51
+ return { engine: Engine.memory(), storage: { kind: "memory", reason: "locked" } };
52
+ hooks.report({ kind: "waiting", reason: "locked" });
53
+ for (;;) {
54
+ await sleep(WAIT_RETRY_MS);
55
+ outcome = await attempt();
56
+ if (outcome !== "locked")
57
+ return outcome;
58
+ }
59
+ }
60
+ //# sourceMappingURL=open-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"open-store.js","sourceRoot":"","sources":["../../../src/worker/application/open-store.ts"],"names":[],"mappings":"AAAA,oHAAoH;AACpH,yGAAyG;AACzG,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAElE,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAiBzC,MAAM,YAAY,GAAG,CAAC,EAAU,EAAiB,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAEtG,kIAAkI;AAClI,MAAM,CAAC,KAAK,UA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AO,OAAO,CAAC;IAC3C,CAAC;AACH,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { Descriptor } from "../../data/types.js";
2
+ import type { ApplicationInit } from "../protocol.js";
3
+ /** The seed could not be read; `reason` is the init failure to report. */
4
+ export declare class SeedError extends Error {
5
+ readonly reason: "worker-error" | "invalid-descriptor";
6
+ constructor(reason: "worker-error" | "invalid-descriptor", message: string);
7
+ }
8
+ /** The descriptor of a seed given as a URL, without fetching its data; null when the URL holds a plain document. */
9
+ export declare function seedDescriptor(seed: ApplicationInit["seed"]): Promise<Descriptor | null>;
10
+ /** The seed's data document and, when it has one, its descriptor. */
11
+ export declare function loadSeed(seed: ApplicationInit["seed"]): Promise<{
12
+ document: unknown;
13
+ descriptor: Descriptor | null;
14
+ }>;
@@ -0,0 +1,50 @@
1
+ // Resolving an application's seed in the worker, only when a store needs one (ADR-009 2.2). A seed is inline data, a
2
+ // descriptor whose data is fetched, or a URL of either; fetching waits until the lifecycle says a seed is needed.
3
+ import { validateDescriptor } from "../../data/descriptor.js";
4
+ /** The seed could not be read; `reason` is the init failure to report. */
5
+ export class SeedError extends Error {
6
+ reason;
7
+ constructor(reason, message) {
8
+ super(message);
9
+ this.reason = reason;
10
+ this.name = "SeedError";
11
+ }
12
+ }
13
+ async function fetchJson(url, what) {
14
+ const response = await fetch(url);
15
+ if (!response.ok)
16
+ throw new SeedError("worker-error", `the ${what} could not be fetched: ${response.status} ${response.statusText}`);
17
+ return response.json();
18
+ }
19
+ const isDocument = (v) => Boolean(v) && typeof v === "object" && "nodes" in v;
20
+ function checkedDescriptor(value) {
21
+ const checked = validateDescriptor(value);
22
+ if (!checked.ok)
23
+ throw new SeedError("invalid-descriptor", `${checked.path}: ${checked.message}`);
24
+ return checked.descriptor;
25
+ }
26
+ /** The descriptor of a seed given as a URL, without fetching its data; null when the URL holds a plain document. */
27
+ export async function seedDescriptor(seed) {
28
+ if (seed.descriptor)
29
+ return seed.descriptor;
30
+ if (!seed.url)
31
+ return null;
32
+ const value = await fetchJson(seed.url, "seed");
33
+ return isDocument(value) ? null : checkedDescriptor(value);
34
+ }
35
+ /** The seed's data document and, when it has one, its descriptor. */
36
+ export async function loadSeed(seed) {
37
+ if (seed.document)
38
+ return { document: seed.document, descriptor: null };
39
+ if (seed.descriptor && seed.dataUrl)
40
+ return { document: await fetchJson(seed.dataUrl, "seed data"), descriptor: seed.descriptor };
41
+ if (!seed.url)
42
+ throw new SeedError("worker-error", "no seed location was given");
43
+ const value = await fetchJson(seed.url, "seed");
44
+ if (isDocument(value))
45
+ return { document: value, descriptor: null };
46
+ const descriptor = checkedDescriptor(value);
47
+ const dataUrl = new URL(descriptor.data.url, seed.url).href;
48
+ return { document: await fetchJson(dataUrl, "seed data"), descriptor };
49
+ }
50
+ //# sourceMappingURL=seed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seed.js","sourceRoot":"","sources":["../../../src/worker/application/seed.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,kHAAkH;AAClH,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAI9D,0EAA0E;AAC1E,MAAM,OAAO,SAAU,SAAQ,KAAK;IACb,MAAM;IAA3B,YAAqB,MAA6C,EAAE,OAAe;QACjF,KAAK,CAAC,OAAO,CAAC,CAAC;sBADI,MAAM;QAEzB,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;IAC1B,CAAC;CACF;AAED,KAAK,UAAU,SAAS,CAAC,GAAW,EAAE,IAAY;IAChD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,CAAC,QAAQ,CAAC,EAAE;QAAE,MAAM,IAAI,SAAS,CAAC,cAAc,EAAE,OAAO,IAAI,0BAA0B,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;IACrI,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,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,cAAc,EAAE,4BAA4B,CAAC,CAAC;IACjF,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAChD,IAAI,UAAU,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;IACpE,MAAM,UAAU,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;IAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC,OAAO,EAAE,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;AACzE,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { ExportEnvelope, LossReport, MigrationStep } from "../../application/types.js";
2
+ import type { Catalog } from "../../catalog/catalog.js";
3
+ import type { GraphDocument, IndexSpec } from "../../data/types.js";
4
+ import type { Engine } from "../engine.js";
5
+ /** The envelope or the document was refused before the store was touched. */
6
+ export declare class ImportRejected extends Error {
7
+ constructor(message: string);
8
+ }
9
+ /** Read every node and relationship into an ADR-002 document, counting what it cannot carry. */
10
+ export declare function readDocument(engine: Engine): {
11
+ document: GraphDocument;
12
+ losses: LossReport;
13
+ };
14
+ export declare function exportApplication(engine: Engine, application: {
15
+ name: string;
16
+ version: number;
17
+ }, allowLoss: boolean): {
18
+ envelope: ExportEnvelope | null;
19
+ losses: LossReport;
20
+ };
21
+ export interface ImportContext {
22
+ catalog: Catalog;
23
+ store: string;
24
+ name: string;
25
+ version: number;
26
+ indexes: IndexSpec[];
27
+ migrations: Record<string, MigrationStep[]>;
28
+ }
29
+ /** Check an envelope against this application before anything is written. Throws ImportRejected. */
30
+ export declare function checkEnvelope(envelope: unknown, ctx: Pick<ImportContext, "name" | "version">): ExportEnvelope;
31
+ export declare function importApplication(engine: Engine, ctx: ImportContext, input: unknown): Promise<void>;
@@ -0,0 +1,134 @@
1
+ import { BATCH_SIZE } from "../../config.js";
2
+ import { validate } from "../../data/validate.js";
3
+ import { loadGraph, prepare, run } from "../loader.js";
4
+ import { migrate } from "./migrate.js";
5
+ import { convert } from "./losses.js";
6
+ /** The envelope or the document was refused before the store was touched. */
7
+ export class ImportRejected extends Error {
8
+ constructor(message) {
9
+ super(message);
10
+ this.name = "ImportRejected";
11
+ }
12
+ }
13
+ const NODE_PAGE = "MATCH (n) WITH n ORDER BY elementId(n) SKIP $skip LIMIT $limit " +
14
+ "RETURN elementId(n) AS e, labels(n) AS labels, properties(n) AS p, [k IN keys(n) | [k, valueType(n[k]), toString(n[k])]] AS t";
15
+ const LINK_PAGE = "MATCH (a)-[r]->(b) WITH a, r, b ORDER BY elementId(r) SKIP $skip LIMIT $limit " +
16
+ "RETURN elementId(a) AS s, elementId(b) AS t, type(r) AS type, properties(r) AS p, [k IN keys(r) | [k, valueType(r[k]), toString(r[k])]] AS tv";
17
+ const ORDER = ["integer-beyond-2^53", "whole-number-float", "date", "duration", "point", "empty-list", "node-without-string-id"];
18
+ class Losses {
19
+ counts = new Map();
20
+ droppedLinks = 0;
21
+ add(kind) {
22
+ this.counts.set(kind, (this.counts.get(kind) ?? 0) + 1);
23
+ }
24
+ report() {
25
+ return ORDER.filter((k) => this.counts.has(k)).map((kind) => ({
26
+ kind,
27
+ count: this.counts.get(kind),
28
+ ...(kind === "node-without-string-id" && this.droppedLinks > 0 ? { droppedLinks: this.droppedLinks } : {}),
29
+ }));
30
+ }
31
+ }
32
+ function properties(json, typed, skip, losses) {
33
+ const out = {};
34
+ for (const [key, type, text] of typed) {
35
+ if (key === skip)
36
+ continue;
37
+ const c = convert(type, text, json[key]);
38
+ if (c.loss)
39
+ losses.add(c.loss);
40
+ if (c.keep)
41
+ out[key] = c.value;
42
+ }
43
+ return out;
44
+ }
45
+ /** Read every node and relationship into an ADR-002 document, counting what it cannot carry. */
46
+ export function readDocument(engine) {
47
+ const losses = new Losses();
48
+ const ids = new Map(); // element id -> document id, for the nodes that have one
49
+ const nodes = [];
50
+ for (let skip = 0;; skip += BATCH_SIZE) {
51
+ const page = run(engine, NODE_PAGE, { skip, limit: BATCH_SIZE }).rows;
52
+ for (const row of page) {
53
+ const typed = row.t;
54
+ const id = typed.find(([k]) => k === "id");
55
+ if (!id || !id[1].startsWith("STRING") || id[2] === "") {
56
+ losses.add("node-without-string-id");
57
+ continue;
58
+ }
59
+ const labels = row.labels;
60
+ ids.set(row.e, id[2]);
61
+ nodes.push({ id: id[2], ...(labels.length ? { labels } : {}), properties: properties(row.p, typed, "id", losses) });
62
+ }
63
+ if (page.length < BATCH_SIZE)
64
+ break;
65
+ }
66
+ const links = [];
67
+ for (let skip = 0;; skip += BATCH_SIZE) {
68
+ const page = run(engine, LINK_PAGE, { skip, limit: BATCH_SIZE }).rows;
69
+ for (const row of page) {
70
+ const source = ids.get(row.s);
71
+ const target = ids.get(row.t);
72
+ if (!source || !target) {
73
+ losses.droppedLinks++;
74
+ continue;
75
+ }
76
+ const props = properties(row.p, row.tv, null, losses);
77
+ links.push({ source, target, type: row.type, ...(Object.keys(props).length ? { properties: props } : {}) });
78
+ }
79
+ if (page.length < BATCH_SIZE)
80
+ break;
81
+ }
82
+ // The engine's element ids differ between a store and its import, so the document is put in a fixed order:
83
+ // an export, an import and an export give the same document (FR-023).
84
+ const byText = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
85
+ nodes.sort((a, b) => byText(a.id, b.id));
86
+ const linkKey = (l) => `${l.source}\u0000${l.target}\u0000${l.type}\u0000${JSON.stringify(l.properties ?? {})}`;
87
+ links.sort((a, b) => byText(linkKey(a), linkKey(b)));
88
+ return { document: { version: 1, nodes, links }, losses: losses.report() };
89
+ }
90
+ export function exportApplication(engine, application, allowLoss) {
91
+ const { document, losses } = readDocument(engine);
92
+ if (losses.length > 0 && !allowLoss)
93
+ return { envelope: null, losses };
94
+ const checked = validate(document, { scoped: false });
95
+ if (!checked.ok)
96
+ throw new ImportRejected(`the graph cannot be written in the data format: ${checked.path}: ${checked.message}`);
97
+ // A client that is ready has been carried to the code's version, so that is the version the data is at.
98
+ return {
99
+ envelope: {
100
+ format: "relate-application-export",
101
+ version: 1,
102
+ application: { name: application.name, version: application.version },
103
+ document,
104
+ },
105
+ losses,
106
+ };
107
+ }
108
+ /** Check an envelope against this application before anything is written. Throws ImportRejected. */
109
+ export function checkEnvelope(envelope, ctx) {
110
+ const e = envelope;
111
+ if (!e || typeof e !== "object" || e.format !== "relate-application-export")
112
+ throw new ImportRejected('the envelope is not a "relate-application-export"');
113
+ if (e.version !== 1)
114
+ throw new ImportRejected(`the envelope's format version ${String(e.version)} is not one this code reads (1)`);
115
+ const app = e.application;
116
+ if (!app || typeof app.name !== "string" || !Number.isInteger(app.version) || app.version < 1)
117
+ throw new ImportRejected("the envelope has no valid application name and version");
118
+ if (app.name !== ctx.name)
119
+ throw new ImportRejected(`the envelope is for the application "${app.name}", not "${ctx.name}"`);
120
+ if (app.version > ctx.version)
121
+ throw new ImportRejected(`the envelope's version ${app.version} is newer than this code's ${ctx.version}`);
122
+ return e;
123
+ }
124
+ export async function importApplication(engine, ctx, input) {
125
+ const envelope = checkEnvelope(input, ctx);
126
+ const document = prepare(envelope.document); // validates the whole document before any write
127
+ const base = { kind: "application", name: ctx.name, version: envelope.application.version, seeded: document.nodes.length > 0 };
128
+ await ctx.catalog.set(ctx.store, { ...base, state: "importing" });
129
+ engine.reset();
130
+ loadGraph(engine, document, { indexes: ctx.indexes });
131
+ await ctx.catalog.set(ctx.store, { ...base, state: "ready" });
132
+ await migrate(engine, ctx, envelope.application.version, ctx.version, ctx.migrations);
133
+ }
134
+ //# sourceMappingURL=transfer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transfer.js","sourceRoot":"","sources":["../../../src/worker/application/transfer.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;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CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC;IAClE,MAAM,CAAC,KAAK,EAAE,CAAC;IACf,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;IACtD,MAAM,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;IAC9D,MAAM,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC;AACxF,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { Catalog } from "../catalog/catalog.js";
2
+ import type { Descriptor } from "../data/types.js";
3
+ import type { Engine } from "./engine.js";
4
+ /** A cache's name in the catalog, as the engine names its store. */
5
+ export declare const cacheStoreName: (id: string) => string;
6
+ /** A store can be used as it is when its entry is `ready` at the descriptor's revision and it holds all the nodes. */
7
+ export declare function canRestore(opened: Engine, catalog: Catalog, descriptor: Descriptor): Promise<boolean>;
8
+ /**
9
+ * Prepare a store for a rebuild: write `loading` (intent first), then reset the store if it holds anything. When the
10
+ * catalog cannot take the write, the store is left exactly as it is and this returns false: an entry that still says
11
+ * `ready` at an older revision would otherwise describe the rebuilt data wrongly. The caller then loads in memory.
12
+ */
13
+ export declare function beginRebuild(opened: Engine, catalog: Catalog, descriptor: Descriptor): Promise<boolean>;
14
+ /** After a complete load: write `ready` with the revision, last. */
15
+ export declare function finishRebuild(catalog: Catalog, descriptor: Descriptor): Promise<void>;
@@ -0,0 +1,45 @@
1
+ import { isEmpty, nodeCount, sweepScoped } from "./sweep.js";
2
+ /** A cache's name in the catalog, as the engine names its store. */
3
+ export const cacheStoreName = (id) => `rel-${id}`;
4
+ /** A store can be used as it is when its entry is `ready` at the descriptor's revision and it holds all the nodes. */
5
+ export async function canRestore(opened, catalog, descriptor) {
6
+ let found;
7
+ try {
8
+ found = await catalog.lookup(cacheStoreName(descriptor.id));
9
+ }
10
+ catch {
11
+ return false; // the file storage failed under the catalog: the cache is rebuilt, never failed over its record
12
+ }
13
+ if (found.status !== "entry" || found.entry.kind !== "cache")
14
+ return false;
15
+ if (found.entry.state !== "ready" || found.entry.revision !== descriptor.revision)
16
+ return false;
17
+ sweepScoped(opened);
18
+ return nodeCount(opened) === descriptor.data.nodes;
19
+ }
20
+ /**
21
+ * Prepare a store for a rebuild: write `loading` (intent first), then reset the store if it holds anything. When the
22
+ * catalog cannot take the write, the store is left exactly as it is and this returns false: an entry that still says
23
+ * `ready` at an older revision would otherwise describe the rebuilt data wrongly. The caller then loads in memory.
24
+ */
25
+ export async function beginRebuild(opened, catalog, descriptor) {
26
+ try {
27
+ await catalog.set(cacheStoreName(descriptor.id), { kind: "cache", name: descriptor.id, state: "loading", revision: descriptor.revision });
28
+ }
29
+ catch {
30
+ return false;
31
+ }
32
+ if (!isEmpty(opened))
33
+ opened.reset();
34
+ return true;
35
+ }
36
+ /** After a complete load: write `ready` with the revision, last. */
37
+ export async function finishRebuild(catalog, descriptor) {
38
+ try {
39
+ await catalog.set(cacheStoreName(descriptor.id), { kind: "cache", name: descriptor.id, state: "ready", revision: descriptor.revision });
40
+ }
41
+ catch {
42
+ /* the cache works without its entry; the next open rebuilds */
43
+ }
44
+ }
45
+ //# sourceMappingURL=cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/worker/cache.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE7D,oEAAoE;AACpE,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,EAAU,EAAU,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC;AAElE,sHAA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C,OAAgB,EAAE,UAAsB;IAC1E,IAAI,CAAC;QACH,MAAM,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,CAAC,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC1I,CAAC;IAAC,MAAM,CAAC;QACP,+DAA+D;IACjE,CAAC;AACH,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function encodeParams(value: unknown): string;
@@ -0,0 +1,43 @@
1
+ // Writes the parameters of a statement as JSON text. The engine reads a whole number as an integer and a
2
+ // number with a decimal point as a float, and rejects a list that mixes the two, so a number array that
3
+ // contains any fractional item is written with every item as a float (`1.0`), which JSON.stringify cannot do.
4
+ function floatText(n) {
5
+ const s = Object.is(n, -0) ? "-0" : String(n);
6
+ return /[eE.]/.test(s) ? s : `${s}.0`;
7
+ }
8
+ function numberText(n) {
9
+ if (!Number.isFinite(n))
10
+ throw new Error("cannot encode a number that is not finite");
11
+ return String(n);
12
+ }
13
+ export function encodeParams(value) {
14
+ if (value === null)
15
+ return "null";
16
+ switch (typeof value) {
17
+ case "string":
18
+ return JSON.stringify(value);
19
+ case "boolean":
20
+ return value ? "true" : "false";
21
+ case "number":
22
+ return numberText(value);
23
+ case "object":
24
+ break;
25
+ default:
26
+ throw new Error(`cannot encode a value of type ${typeof value}`);
27
+ }
28
+ if (Array.isArray(value)) {
29
+ const allNumbers = value.length > 0 && value.every((v) => typeof v === "number");
30
+ if (allNumbers && value.some((v) => !Number.isInteger(v))) {
31
+ return `[${value.map((v) => (numberText(v), floatText(v))).join(",")}]`;
32
+ }
33
+ return `[${value.map(encodeParams).join(",")}]`;
34
+ }
35
+ const parts = [];
36
+ for (const [key, v] of Object.entries(value)) {
37
+ if (v === undefined)
38
+ continue;
39
+ parts.push(`${JSON.stringify(key)}:${encodeParams(v)}`);
40
+ }
41
+ return `{${parts.join(",")}}`;
42
+ }
43
+ //# sourceMappingURL=encode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode.js","sourceRoot":"","sources":["../../src/worker/encode.ts"],"names":[],"mappings":"AAAA,yGAAyG;AACzG,wGAAwG;AACxG,8GAA8G;AAE9G,SAAS,SAAS,CAAC,CAAS;IAC1B,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC9C,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC;AACxC,CAAC;AAED,SAAS,UAAU,CAAC,CAAS;IAC3B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IACtF,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAClC,QAAQ,OAAO,KAAK,EAAE,CAAC;QACrB,KAAK,QAAQ;YACX,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC/B,KAAK,SAAS;YACZ,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;QAClC,KAAK,QAAQ;YACX,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC;QAC3B,KAAK,QAAQ;YACX,MAAM;QACR;YACE,MAAM,IAAI,KAAK,CAAC,iCAAiC,OAAO,KAAK,EAAE,CAAC,CAAC;IACrE,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC;QACjF,IAAI,UAAU,IAAK,KAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACxE,OAAO,IAAK,KAAkB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;QACxF,CAAC;QACD,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAClD,CAAC;IACD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAgC,CAAC,EAAE,CAAC;QACxE,IAAI,CAAC,KAAK,SAAS;YAAE,SAAS;QAC9B,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC1D,CAAC;IACD,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AAChC,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { RelateDb } from "@relate/relate-wasm";
2
+ /**
3
+ * Whether an error thrown by a call into the engine means the instance can no longer be used. The engine's own `isWasmTrap`
4
+ * knows a WebAssembly trap and the stack-exhaustion wording of Chromium and WebKit; it misses Firefox's ("too much
5
+ * recursion") and the "recursive use of an object" an instance throws once an earlier call overflowed the stack (the
6
+ * borrow was never released). Both mean the same: replace the instance.
7
+ */
8
+ export declare function isEngineTrap(err: unknown): boolean;
9
+ export declare class TrapError extends Error {
10
+ constructor(message?: string);
11
+ }
12
+ /** The store is held by another worker or tab (the engine reports `storage locked`). */
13
+ export declare class StorageLockedError extends Error {
14
+ constructor(message: string);
15
+ }
16
+ export declare class Engine {
17
+ private readonly db;
18
+ private dead;
19
+ private constructor();
20
+ /** Initialise the engine's WebAssembly module from its binary's URL. Call once per worker. */
21
+ static load(engineUrl: string): Promise<void>;
22
+ static memory(): Engine;
23
+ /** Wrap an engine instance that is already initialised (a seam for tests; not part of the package interface). */
24
+ static fromDb(db: RelateDb): Engine;
25
+ /** Open the durable store `<prefix><id>` (`rel-` for a content cache, `app-` for an application). Works only in a dedicated worker. */
26
+ static store(id: string, prefix?: string): Promise<Engine>;
27
+ get isDead(): boolean;
28
+ /** Run one statement. Returns the envelope text unaltered. Throws TrapError once the instance has trapped. */
29
+ execute(statement: string, paramsJson?: string | null): string;
30
+ /** Drop the database; for a store this wipes it and reopens it. */
31
+ reset(): void;
32
+ /** Let the database go (it releases a store's lock) and refuse every later call. */
33
+ release(): void;
34
+ private guard;
35
+ }
@@ -0,0 +1,99 @@
1
+ // Wrapper around the engine's browser build. It keeps the engine's result text unaltered, marks the instance
2
+ // dead at the first trap (the engine's own classifier misses the second error a dead instance throws), and
3
+ // answers every later call as a trap.
4
+ import init, { RelateDb } from "@relate/relate-wasm";
5
+ import { isWasmTrap } from "@relate/relate-wasm/trap.js";
6
+ import { STORE_PREFIX } from "../config.js";
7
+ /**
8
+ * Whether an error thrown by a call into the engine means the instance can no longer be used. The engine's own `isWasmTrap`
9
+ * knows a WebAssembly trap and the stack-exhaustion wording of Chromium and WebKit; it misses Firefox's ("too much
10
+ * recursion") and the "recursive use of an object" an instance throws once an earlier call overflowed the stack (the
11
+ * borrow was never released). Both mean the same: replace the instance.
12
+ */
13
+ export function isEngineTrap(err) {
14
+ if (isWasmTrap(err))
15
+ return true;
16
+ const message = err instanceof Error ? err.message : String(err);
17
+ return /too much recursion|recursive use of an object/i.test(message);
18
+ }
19
+ export class TrapError extends Error {
20
+ constructor(message = "the instance is unusable after a trap") {
21
+ super(message);
22
+ this.name = "TrapError";
23
+ }
24
+ }
25
+ /** The store is held by another worker or tab (the engine reports `storage locked`). */
26
+ export class StorageLockedError extends Error {
27
+ constructor(message) {
28
+ super(message);
29
+ this.name = "StorageLockedError";
30
+ }
31
+ }
32
+ const messageOf = (e) => (e instanceof Error ? e.message : String(e));
33
+ export class Engine {
34
+ db;
35
+ dead = false;
36
+ constructor(db) {
37
+ this.db = db;
38
+ }
39
+ /** Initialise the engine's WebAssembly module from its binary's URL. Call once per worker. */
40
+ static async load(engineUrl) {
41
+ await init({ module_or_path: engineUrl });
42
+ }
43
+ static memory() {
44
+ return new Engine(new RelateDb());
45
+ }
46
+ /** Wrap an engine instance that is already initialised (a seam for tests; not part of the package interface). */
47
+ static fromDb(db) {
48
+ return new Engine(db);
49
+ }
50
+ /** Open the durable store `<prefix><id>` (`rel-` for a content cache, `app-` for an application). Works only in a dedicated worker. */
51
+ static async store(id, prefix = STORE_PREFIX) {
52
+ try {
53
+ return new Engine(await RelateDb.open(`opfs://${prefix}${id}`));
54
+ }
55
+ catch (e) {
56
+ if (/storage locked/i.test(messageOf(e)))
57
+ throw new StorageLockedError(messageOf(e));
58
+ throw e;
59
+ }
60
+ }
61
+ get isDead() {
62
+ return this.dead;
63
+ }
64
+ /** Run one statement. Returns the envelope text unaltered. Throws TrapError once the instance has trapped. */
65
+ execute(statement, paramsJson = null) {
66
+ return this.guard(() => this.db.execute(statement, paramsJson));
67
+ }
68
+ /** Drop the database; for a store this wipes it and reopens it. */
69
+ reset() {
70
+ this.guard(() => this.db.reset());
71
+ }
72
+ /** Let the database go (it releases a store's lock) and refuse every later call. */
73
+ release() {
74
+ if (this.dead)
75
+ return;
76
+ this.dead = true;
77
+ try {
78
+ this.db.free();
79
+ }
80
+ catch {
81
+ /* the instance was already unusable */
82
+ }
83
+ }
84
+ guard(call) {
85
+ if (this.dead)
86
+ throw new TrapError();
87
+ try {
88
+ return call();
89
+ }
90
+ catch (e) {
91
+ if (isEngineTrap(e)) {
92
+ this.dead = true;
93
+ throw new TrapError(messageOf(e));
94
+ }
95
+ throw e;
96
+ }
97
+ }
98
+ }
99
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/worker/engine.ts"],"names":[],"mappings":"AAAA,6GAA6G;AAC7G,2GAA2G;AAC3G,sCAAsC;AACtC,OAAO,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,GAAY;IACvC,IAAI,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IACjC,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjE,OAAO,gDAAgD,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,OAAO,SAAU,SAAQ,KAAK;IAClC,YAAY,OAAO,GAAG,uCAAuC;QAC3D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;IAC1B,CAAC;CACF;AAED,wFAAwF;AACxF,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AAED,MAAM,SAAS,GAAG,CAAC,CAAU,EAAU,EAAE,CAAC,CAAC,CAAC,YAAY,KAAK,CAAC,CAAC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AAC;IAClE,CAAC;IAED,mEAAmE;IACnE,KAAK;QACH,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC;IACpC,CAAC;IAED,oFAAoF;IACpF,OAAO;QACL,IAAI,IAAI,CAAC,IAAI;YAAE,OAAO;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC;YACH,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;QACjB,CAAC;QAAC,MAAM,CAAC;YACP,uCAAuC;QACzC,CAAC;IACH,CAAC;IAEO,KAAK,CAAI,IAAa;QAC5B,IAAI,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,SAAS,EAAE,CAAC;QACrC,IAAI,CAAC;YACH,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;gBACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;gBACjB,MAAM,IAAI,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;YACpC,CAAC;YACD,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ /** Remove `relate-web/<id>.json` if it is there. Absence, or no storage at all, is not an error. */
2
+ export declare function removeLegacyCopy(id: string): Promise<void>;
@@ -0,0 +1,19 @@
1
+ // The stored copy of a descriptor, the file an earlier form of this package kept for each content cache at
2
+ // `relate-web/<id>.json` (ADR-003 2.5). The catalog entry replaced it (ADR-010 2.4); the file is only removed, when its
3
+ // cache is next opened, so no copy lingers in a visitor's storage.
4
+ import { CATALOG_DIR, CATALOG_FILE } from "../config.js";
5
+ /** Remove `relate-web/<id>.json` if it is there. Absence, or no storage at all, is not an error. */
6
+ export async function removeLegacyCopy(id) {
7
+ // A descriptor `id` of "catalog" would name the catalog itself: that file is never a stored copy.
8
+ if (`${id}.json` === CATALOG_FILE)
9
+ return;
10
+ try {
11
+ const root = await navigator.storage.getDirectory();
12
+ const dir = await root.getDirectoryHandle(CATALOG_DIR);
13
+ await dir.removeEntry(`${id}.json`);
14
+ }
15
+ catch {
16
+ /* there was no copy */
17
+ }
18
+ }
19
+ //# sourceMappingURL=legacy-copy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy-copy.js","sourceRoot":"","sources":["../../src/worker/legacy-copy.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,wHAAwH;AACxH,mEAAmE;AACnE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEzD,oGAAoG;AACpG,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,EAAU;IAC/C,kGAAkG;IAClG,IAAI,GAAG,EAAE,OAAO,KAAK,YAAY;QAAE,OAAO;IAC1C,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;QACpD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC;QACvD,MAAM,GAAG,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;IAAC,MAAM,CAAC;QACP,uBAAuB;IACzB,CAAC;AACH,CAAC"}