@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,64 @@
1
+ // Checks the `application` option when the client is created (ADR-009 2.1). Throws an Error naming the field and
2
+ // the rule, before anything is started.
3
+ import { APP_NAME_PATTERN } from "../config.js";
4
+ import { inRanges } from "./ranges.js";
5
+ const oneOf = (field, value, allowed, fallback) => {
6
+ if (value === undefined)
7
+ return fallback;
8
+ if (!allowed.includes(value))
9
+ throw new Error(`application.${field} must be ${allowed.map((a) => `"${a}"`).join(" or ")}`);
10
+ return value;
11
+ };
12
+ export function validateApplication(options) {
13
+ if (options === null || typeof options !== "object")
14
+ throw new Error("application must be an object");
15
+ const { name, version, seed } = options;
16
+ if (typeof name !== "string" || !APP_NAME_PATTERN.test(name)) {
17
+ throw new Error(`application.name must match ${APP_NAME_PATTERN.source} (1 to 60 letters, digits, dash or underscore)`);
18
+ }
19
+ if (!Number.isInteger(version) || version < 1)
20
+ throw new Error("application.version must be a positive integer");
21
+ if (seed === undefined || seed === null || seed === "")
22
+ throw new Error("application.seed is required: a graph data document, a descriptor or a URL");
23
+ const migrations = {};
24
+ const given = options.migrations ?? {};
25
+ const keys = Object.keys(given).map((k) => {
26
+ if (!/^\d+$/.test(k))
27
+ throw new Error(`application.migrations key "${k}" must be a version number`);
28
+ return Number(k);
29
+ });
30
+ for (const key of keys) {
31
+ if (key < 2)
32
+ throw new Error(`application.migrations has an entry for version ${key}; the first version is the seed, so entries start at 2`);
33
+ if (key > version)
34
+ throw new Error(`application.migrations has an entry for version ${key}, above the application's version ${version}`);
35
+ }
36
+ keys.sort((a, b) => a - b);
37
+ keys.forEach((key, i) => {
38
+ if (key !== i + 2)
39
+ throw new Error(`application.migrations must be consecutive from 2; version ${i + 2} is missing before ${key}`);
40
+ });
41
+ for (const key of keys) {
42
+ const steps = given[key];
43
+ if (!Array.isArray(steps) || steps.length === 0)
44
+ throw new Error(`application.migrations[${key}] must be a non-empty list of statements`);
45
+ migrations[String(key)] = steps.map((step, i) => {
46
+ if (typeof step === "string")
47
+ return step;
48
+ if (step && typeof step === "object" && step.kind === "ranges")
49
+ return inRanges(step); // re-checks a step built by hand
50
+ throw new Error(`application.migrations[${key}][${i}] must be a statement or a step made by inRanges`);
51
+ });
52
+ }
53
+ return {
54
+ name,
55
+ version,
56
+ seed,
57
+ indexes: options.indexes ?? [],
58
+ migrations,
59
+ onUnavailable: oneOf("onUnavailable", options.onUnavailable, ["memory", "fail"], "memory"),
60
+ onError: oneOf("onError", options.onError, ["fail", "memory"], "fail"),
61
+ whenLocked: oneOf("whenLocked", options.whenLocked, ["wait", "memory"], "wait"),
62
+ };
63
+ }
64
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/application/options.ts"],"names":[],"mappings":"AAAA,iHAAiH;AACjH,wCAAwC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAWvC,MAAM,KAAK,GAAG,CAAmB,KAAa,EAAE,KAAc,EAAE,OAAqB,EAAE,QAAW,EAAK,EAAE;IACvG,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC;IACzC,IAAI,CAAC,O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CAAC,CAAC,iCAAiC;YACxH,MAAM,IAAI,KAAK,CAAC,0BAA0B,GAAG,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACzG,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,IAAI;QACJ,OAAO;QACP,IAAI;QACJ,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE;QAC9B,UAAU;QACV,aAAa,EAAE,KAAK,CAAC,eAAe,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC;QAC1F,OAAO,EAAE,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QACtE,UAAU,EAAE,KAAK,CAAC,YAAY,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;KAChF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { RangeStep } from "./types.js";
2
+ export declare function inRanges(step: {
3
+ label: string;
4
+ property: string;
5
+ step: number;
6
+ statement: string;
7
+ }): RangeStep;
@@ -0,0 +1,14 @@
1
+ export function inRanges(step) {
2
+ const { label, property, statement } = step;
3
+ if (typeof label !== "string" || label === "")
4
+ throw new Error("inRanges: label must be a non-empty string");
5
+ if (typeof property !== "string" || property === "")
6
+ throw new Error("inRanges: property must be a non-empty string");
7
+ if (!Number.isInteger(step.step) || step.step < 1)
8
+ throw new Error("inRanges: step must be a positive integer");
9
+ if (typeof statement !== "string" || !statement.includes("$from") || !statement.includes("$to")) {
10
+ throw new Error("inRanges: the statement must use the parameters $from (inclusive) and $to (exclusive)");
11
+ }
12
+ return { kind: "ranges", label, property, step: step.step, statement };
13
+ }
14
+ //# sourceMappingURL=ranges.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ranges.js","sourceRoot":"","sources":["../../src/application/ranges.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,QAAQ,CAAC,IAA0E;IACjG,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IAC5C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAC7G,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACtH,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAChH,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAChG,MAAM,IAAI,KAAK,CAAC,uFAAuF,CAAC,CAAC;IAC3G,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC;AACzE,CAAC"}
@@ -0,0 +1,34 @@
1
+ import type { StorageStatus } from "./types.js";
2
+ export declare class StorageHolder {
3
+ private readonly onChange;
4
+ private current;
5
+ constructor(onChange: (status: StorageStatus) => void);
6
+ get value(): StorageStatus;
7
+ /**
8
+ * The worker reported where the data is. A client in memory never becomes durable (it would need a new client),
9
+ * so a later `durable` report is ignored. Returns true when the status changed.
10
+ */
11
+ apply(report: {
12
+ kind: StorageStatus["kind"];
13
+ reason?: StorageStatus["reason"];
14
+ }): boolean;
15
+ setPersisted(persisted: boolean | null): boolean;
16
+ private set;
17
+ }
18
+ interface StorageManagerLike {
19
+ persist?: () => Promise<boolean>;
20
+ persisted?: () => Promise<boolean>;
21
+ estimate?: () => Promise<{
22
+ usage?: number;
23
+ quota?: number;
24
+ }>;
25
+ }
26
+ /** The browser's answer to `persisted()`, or null when the page cannot ask. */
27
+ export declare function readPersisted(storage?: StorageManagerLike | undefined): Promise<boolean | null>;
28
+ /** Ask the browser for persistent storage. Only ever called from the application's own action; false when absent or refused. */
29
+ export declare function requestPersistence(storage?: StorageManagerLike | undefined): Promise<boolean>;
30
+ export declare function storageEstimate(storage?: StorageManagerLike | undefined): Promise<{
31
+ usage: number | null;
32
+ quota: number | null;
33
+ }>;
34
+ export {};
@@ -0,0 +1,60 @@
1
+ export class StorageHolder {
2
+ onChange;
3
+ current = { kind: "waiting", persisted: null };
4
+ constructor(onChange) {
5
+ this.onChange = onChange;
6
+ }
7
+ get value() {
8
+ return this.current;
9
+ }
10
+ /**
11
+ * The worker reported where the data is. A client in memory never becomes durable (it would need a new client),
12
+ * so a later `durable` report is ignored. Returns true when the status changed.
13
+ */
14
+ apply(report) {
15
+ if (this.current.kind === "memory" && report.kind === "durable")
16
+ return false;
17
+ const next = { kind: report.kind, persisted: this.current.persisted, ...(report.reason ? { reason: report.reason } : {}) };
18
+ return this.set(next);
19
+ }
20
+ setPersisted(persisted) {
21
+ return this.set({ ...this.current, persisted });
22
+ }
23
+ set(next) {
24
+ const a = this.current;
25
+ if (a.kind === next.kind && a.reason === next.reason && a.persisted === next.persisted)
26
+ return false;
27
+ this.current = next;
28
+ this.onChange(next);
29
+ return true;
30
+ }
31
+ }
32
+ const browserStorage = () => globalThis.navigator?.storage;
33
+ /** The browser's answer to `persisted()`, or null when the page cannot ask. */
34
+ export async function readPersisted(storage = browserStorage()) {
35
+ try {
36
+ return storage?.persisted ? await storage.persisted() : null;
37
+ }
38
+ catch {
39
+ return null;
40
+ }
41
+ }
42
+ /** Ask the browser for persistent storage. Only ever called from the application's own action; false when absent or refused. */
43
+ export async function requestPersistence(storage = browserStorage()) {
44
+ try {
45
+ return storage?.persist ? Boolean(await storage.persist()) : false;
46
+ }
47
+ catch {
48
+ return false;
49
+ }
50
+ }
51
+ export async function storageEstimate(storage = browserStorage()) {
52
+ try {
53
+ const e = storage?.estimate ? await storage.estimate() : undefined;
54
+ return { usage: e?.usage ?? null, quota: e?.quota ?? null };
55
+ }
56
+ catch {
57
+ return { usage: null, quota: null };
58
+ }
59
+ }
60
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/application/storage.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,aAAa;IAGK,QAAQ;IAF7B,OAAO,GAAkB,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAEtE,YAA6B,QAAyC;wBAAzC,QAAQ;IAAoC,CAAC;IAE1E,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,MAAyE;QAC7E,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC;QAC9E,MAAM,IAAI,GAAkB,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;QAC1I,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,YAAY,CAAC,SAAyB;QACpC,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;IAClD,CAAC;IAEO,GAAG,CAAC,IAAmB;QAC7B,MAAM,CAAC,GAAG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AAE,CAAC,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,IAAI,IAAI,EAAE,CAAC;IAC9D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACtC,CAAC;AACH,CAAC"}
@@ -0,0 +1,49 @@
1
+ import type { Descriptor, GraphDocument, IndexSpec } from "../data/types.js";
2
+ /** A migration step that runs a statement over successive bounded windows of a numeric property (made by `inRanges`). */
3
+ export interface RangeStep {
4
+ kind: "ranges";
5
+ label: string;
6
+ property: string;
7
+ /** Width of one window; a positive integer. */
8
+ step: number;
9
+ /** Cypher using `$from` (inclusive) and `$to` (exclusive) and a filter that makes running it again harmless. */
10
+ statement: string;
11
+ }
12
+ /** One statement of a migration: Cypher text, or a range step. */
13
+ export type MigrationStep = string | RangeStep;
14
+ export interface ApplicationOptions {
15
+ /** `[A-Za-z0-9_-]{1,60}`; the store is `app-<name>`. */
16
+ name: string;
17
+ /** The schema version this code expects; a positive integer. */
18
+ version: number;
19
+ /** A graph data document or descriptor, as data or as a URL; loaded once, on first run. */
20
+ seed: GraphDocument | Descriptor | string;
21
+ /** Indexes to create on first run when the seed is a plain document. */
22
+ indexes?: IndexSpec[];
23
+ /** Target version to the ordered steps that take stored data to it. */
24
+ migrations?: Record<number, MigrationStep[]>;
25
+ onUnavailable?: "memory" | "fail";
26
+ onError?: "fail" | "memory";
27
+ whenLocked?: "wait" | "memory";
28
+ }
29
+ export interface StorageStatus {
30
+ kind: "durable" | "memory" | "waiting";
31
+ reason?: "unavailable" | "locked" | "error";
32
+ /** The browser's answer to `navigator.storage.persisted()`, or null when it cannot be asked. */
33
+ persisted: boolean | null;
34
+ }
35
+ export type LossKind = "integer-beyond-2^53" | "whole-number-float" | "date" | "duration" | "point" | "empty-list" | "node-without-string-id";
36
+ export type LossReport = Array<{
37
+ kind: LossKind;
38
+ count: number;
39
+ droppedLinks?: number;
40
+ }>;
41
+ export interface ExportEnvelope {
42
+ format: "relate-application-export";
43
+ version: 1;
44
+ application: {
45
+ name: string;
46
+ version: number;
47
+ };
48
+ document: GraphDocument;
49
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/application/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import type { GraphDocument } from "../validate.js";
2
+ /** The document as text that does not depend on the order of keys, nodes or links; any `revision` it carries is dropped. */
3
+ export declare function canonicalText(document: GraphDocument): string;
4
+ /** The first 12 hexadecimal digits of the SHA-256 of the canonical text. */
5
+ export declare function revisionOf(text: string): Promise<string>;
@@ -0,0 +1,26 @@
1
+ const sortKeys = (value) => {
2
+ if (Array.isArray(value))
3
+ return value.map(sortKeys); // the order of an array property is data
4
+ if (value !== null && typeof value === "object") {
5
+ return Object.fromEntries(Object.keys(value)
6
+ .sort()
7
+ .map((k) => [k, sortKeys(value[k])]));
8
+ }
9
+ return value;
10
+ };
11
+ /** The document as text that does not depend on the order of keys, nodes or links; any `revision` it carries is dropped. */
12
+ export function canonicalText(document) {
13
+ const nodes = [...document.nodes].map((n) => sortKeys(n)).sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
14
+ const key = (l) => JSON.stringify([l.source, l.target, l.type, sortKeys(l.properties ?? {})]);
15
+ const links = [...document.links].map((l) => sortKeys(l)).sort((a, b) => (key(a) < key(b) ? -1 : key(a) > key(b) ? 1 : 0));
16
+ return JSON.stringify({ version: 1, nodes, links });
17
+ }
18
+ /** The first 12 hexadecimal digits of the SHA-256 of the canonical text. */
19
+ export async function revisionOf(text) {
20
+ const digest = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(text));
21
+ let hex = "";
22
+ for (const byte of new Uint8Array(digest).subarray(0, 6))
23
+ hex += byte.toString(16).padStart(2, "0");
24
+ return hex;
25
+ }
26
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AAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC9H,MAAM,KAAK,GAAG,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAmC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7J,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;AACtD,CAAC;AAED,4EAA4E;AAC5E,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,IAAY;IAC3C,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAChG,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,MAAM,IAAI,IAAI,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;QAAE,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACpG,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { IndexSpec } from "../validate.js";
2
+ import type { Evaluated } from "./prepare.js";
3
+ /** The base path of a site joined with a path of the adapter's, without a doubled slash. */
4
+ export declare const withBase: (base: string, path: string) => string;
5
+ /** `dataPath` is the published location of the data file, without the base path. */
6
+ export declare function descriptorOf(name: string, evaluated: Evaluated, indexes: IndexSpec[], base: string, dataPath: string): {
7
+ version: 1;
8
+ id: string;
9
+ revision: string;
10
+ data: {
11
+ url: string;
12
+ nodes: number;
13
+ links: number;
14
+ };
15
+ indexes?: IndexSpec[] | undefined;
16
+ };
@@ -0,0 +1,13 @@
1
+ /** The base path of a site joined with a path of the adapter's, without a doubled slash. */
2
+ export const withBase = (base, path) => `${base.replace(/\/+$/, "")}${path}`;
3
+ /** `dataPath` is the published location of the data file, without the base path. */
4
+ export function descriptorOf(name, evaluated, indexes, base, dataPath) {
5
+ return {
6
+ version: 1,
7
+ id: name,
8
+ revision: evaluated.revision,
9
+ data: { url: withBase(base, dataPath), nodes: evaluated.nodes, links: evaluated.links },
10
+ ...(indexes.length ? { indexes } : {}),
11
+ };
12
+ }
13
+ //# sourceMappingURL=descriptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"descriptor.js","sourceRoot":"","sources":["../../src/build/descriptor.ts"],"names":[],"mappings":"AAIA,4FAA4F;AAC5F,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,IAAY,EAAU,EAAE,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC;AAErG,oFAAoF;AACpF,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,SAAoB,EAAE,OAAoB,EAAE,IAAY,EAAE,QAAgB;IACnH,OAAO;QACL,OAAO,EAAE,CAAU;QACnB,EAAE,EAAE,IAAI;QACR,QAAQ,EAAE,SAAS,CAAC,QAAQ;QAC5B,IAAI,EAAE,EAAE,GAAG,EAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE;QACvF,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACvC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { canonicalText, revisionOf } from "./canonical.js";
2
+ export { prepare, evaluate } from "./prepare.js";
3
+ export type { Evaluated } from "./prepare.js";
4
+ export { descriptorOf, withBase } from "./descriptor.js";
5
+ export { checkInline, escapeJson } from "./inline.js";
6
+ export type { InlineConfig, InlineGraph } from "./inline.js";
@@ -0,0 +1,6 @@
1
+ // `@relate/contrib-web/build`: the build-time code every adapter shares (ADR-005 §2.2). Needs no DOM, no Node-only module and no framework.
2
+ export { canonicalText, revisionOf } from "./canonical.js";
3
+ export { prepare, evaluate } from "./prepare.js";
4
+ export { descriptorOf, withBase } from "./descriptor.js";
5
+ export { checkInline, escapeJson } from "./inline.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/build/index.ts"],"names":[],"mappings":"AAAA,4IAA4I;AAC5I,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { GraphDocument, IndexSpec } from "../validate.js";
2
+ export interface InlineConfig {
3
+ /** Indexes the core creates before the nodes. The one place for later per-graph settings. */
4
+ indexes?: IndexSpec[];
5
+ }
6
+ export interface InlineGraph {
7
+ document: GraphDocument;
8
+ config: InlineConfig;
9
+ }
10
+ /** JSON that is safe inside a <script> element: nothing in it can close the element or open a comment. */
11
+ export declare function escapeJson(value: unknown): string;
12
+ /**
13
+ * Validate an inline graph. `seen` holds the names already used on this page; `registered` the registered names.
14
+ * Throws an error that names the owner, the page, the graph and the first problem.
15
+ */
16
+ export declare function checkInline(owner: string, page: string, id: string, document: unknown, config: InlineConfig | undefined, seen: Set<string>, registered: string[]): InlineGraph;
@@ -0,0 +1,44 @@
1
+ // Checking and serializing an inline graph (ADR-004 §2.2, ADR-005 §2.3). Used at render time by an adapter's component.
2
+ import { validate, validateDescriptor } from "../validate.js";
3
+ const fail = (owner, page, id, detail) => {
4
+ throw new Error(`${owner}: ${page}: inline graph "${id}": ${detail}`);
5
+ };
6
+ /** JSON that is safe inside a <script> element: nothing in it can close the element or open a comment. */
7
+ export function escapeJson(value) {
8
+ return JSON.stringify(value)
9
+ .replaceAll("<", "\\u003c")
10
+ .replaceAll(">", "\\u003e")
11
+ .replaceAll("&", "\\u0026")
12
+ .replaceAll("
", "\\u2028")
13
+ .replaceAll("
", "\\u2029");
14
+ }
15
+ /**
16
+ * Validate an inline graph. `seen` holds the names already used on this page; `registered` the registered names.
17
+ * Throws an error that names the owner, the page, the graph and the first problem.
18
+ */
19
+ export function checkInline(owner, page, id, document, config, seen, registered) {
20
+ const probeBase = { version: 1, id, revision: "0", data: { url: "/x", nodes: 0, links: 0 } };
21
+ const name = validateDescriptor(probeBase);
22
+ if (!name.ok)
23
+ fail(owner, page, String(id), `${name.path}: ${name.message}`);
24
+ if (seen.has(id))
25
+ fail(owner, page, id, "the name is used twice on this page");
26
+ if (registered.includes(id))
27
+ fail(owner, page, id, "the name is also a registered graph; use one or the other");
28
+ const result = validate(document);
29
+ if (!result.ok)
30
+ fail(owner, page, id, `${result.path ? `${result.path}: ` : ""}${result.message}`);
31
+ const settings = config ?? {};
32
+ for (const key of Object.keys(settings)) {
33
+ if (key !== "indexes")
34
+ fail(owner, page, id, `config.${key}: unknown setting`);
35
+ }
36
+ if (settings.indexes !== undefined) {
37
+ const probe = validateDescriptor({ ...probeBase, indexes: settings.indexes });
38
+ if (!probe.ok)
39
+ fail(owner, page, id, `config.${probe.path}: ${probe.message}`);
40
+ }
41
+ seen.add(id);
42
+ return { document: result.document, config: settings };
43
+ }
44
+ //# sourceMappingURL=inline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline.js","sourceRoot":"","sources":["../../src/build/inline.ts"],"names":[],"mappings":"AAAA,wHAAwH;AACxH,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAa9D,MAAM,IAAI,GAAG,CAAC,KAAa,EAAE,IAAY,EAAE,EAAU,EAAE,MAAc,EAAS,EAAE;IAC9E,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,KAAK,IAAI,mBAAmB,EAAE,MAAM,MAAM,EAAE,CAAC,CAAC;AACxE,CAAC,CAAC;AAEF,0GAA0G;AAC1G,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;SACzB,UAAU,CAAC,GAAG,EAAE,SAAS,CAAC;SAC1B,UAAU,CAAC,GAAG,EAAE,SAAS,CAAC;SAC1B,UAAU,CAAC,GAAG,EAAE,SAAS,CAAC;SAC1B,UAAU,CAAC;CACf,EAAE,SAAS,CAAC;SACR,UAAU,CAAC;CACf,EAAE,SAAS,CAAC,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,IAAY,EAAE,EAAU,EAAE,QAAiB,EAAE,MAAgC,EAAE,IAAiB,EAAE,UAAoB;IAC/J,MAAM,SAAS,GAAG,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAW,CAAC;IACtG,MAAM,IAAI,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAC3C,IAAI,CAAC,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,KA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C;IACjF,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACb,OAAO,EAAE,QAAQ,EAAG,MAAsC,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AAC1F,CAAC"}
@@ -0,0 +1,11 @@
1
+ export interface Evaluated {
2
+ /** The canonical text of the document, which is what is served and what the revision is the hash of. */
3
+ text: string;
4
+ revision: string;
5
+ nodes: number;
6
+ links: number;
7
+ }
8
+ /** Validate and canonicalize a source's output. The error message names the graph and the path of the first problem. */
9
+ export declare function prepare(owner: string, name: string, raw: unknown): Promise<Evaluated>;
10
+ /** Call a source, then prepare its output. */
11
+ export declare function evaluate(owner: string, name: string, load: () => unknown): Promise<Evaluated>;
@@ -0,0 +1,25 @@
1
+ // Evaluating a graph source: validation, the canonical form and the revision. `owner` is the adapter's name and begins every
2
+ // error message, so a message names the package that raised it.
3
+ import { validate } from "../validate.js";
4
+ import { canonicalText, revisionOf } from "./canonical.js";
5
+ /** Validate and canonicalize a source's output. The error message names the graph and the path of the first problem. */
6
+ export async function prepare(owner, name, raw) {
7
+ const result = validate(raw);
8
+ if (!result.ok) {
9
+ throw new Error(`${owner}: graph "${name}": ${result.path ? `${result.path}: ` : ""}${result.message}`);
10
+ }
11
+ const text = canonicalText(result.document);
12
+ return { text, revision: await revisionOf(text), nodes: result.document.nodes.length, links: result.document.links.length };
13
+ }
14
+ /** Call a source, then prepare its output. */
15
+ export async function evaluate(owner, name, load) {
16
+ let raw;
17
+ try {
18
+ raw = await load();
19
+ }
20
+ catch (e) {
21
+ throw new Error(`${owner}: graph "${name}": the source failed: ${e instanceof Error ? e.message : String(e)}`);
22
+ }
23
+ return prepare(owner, name, raw);
24
+ }
25
+ //# sourceMappingURL=prepare.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepare.js","sourceRoot":"","sources":["../../src/build/prepare.ts"],"names":[],"mappings":"AAAA,6HAA6H;AAC7H,gEAAgE;AAChE,OAAO,EAAE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E,GAAG,CAAC,CAAC;AACnC,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { type RemoveOptions, type RemoveResult } from "./remove.js";
2
+ import type { ListingItem } from "./types.js";
3
+ /** Why a catalog operation was refused. */
4
+ export type CatalogErrorReason = "unavailable" | "locked" | "kind-mismatch" | "not-a-store";
5
+ export declare class CatalogError extends Error {
6
+ readonly reason: CatalogErrorReason;
7
+ constructor(reason: CatalogErrorReason, message: string);
8
+ }
9
+ export interface ListOptions {
10
+ /** Add each store's size and last-modified time, read from its files. Costs a file read per slot file. */
11
+ sizes?: boolean;
12
+ }
13
+ export interface Listing {
14
+ /** The state of the catalog file: `missing` for an origin that stored nothing. */
15
+ catalog: "ok" | "missing" | "unreadable" | "newer";
16
+ items: ListingItem[];
17
+ }
18
+ /** Every graph the origin has persisted: the catalog's entries joined with the store directories. Opens no store. */
19
+ export declare function listGraphs(options?: ListOptions): Promise<Listing>;
20
+ export type { RemoveOptions, RemoveResult } from "./remove.js";
21
+ /**
22
+ * Remove one graph by its store name: write `removing`, remove the directory `relate/<store>`, delete the entry. A store
23
+ * another tab holds is refused with reason `locked` and its entry is as its holder left it. Removing an application graph
24
+ * discards the visitor's data, so `options.kind` must say so.
25
+ */
26
+ export declare function removeGraph(store: string, options: RemoveOptions): Promise<RemoveResult>;
27
+ /** Delete the catalog file and nothing else: the way out of a catalog that does not parse. No store is touched. */
28
+ export declare function resetCatalog(): Promise<{
29
+ deleted: boolean;
30
+ }>;
@@ -0,0 +1,56 @@
1
+ // The catalog operations a page calls (ADR-010 2.5, specs/007 contracts/catalog-api.md). They run on the page's main thread or in
2
+ // any worker of the origin, need the origin-private storage and Web Locks, and open no engine store.
3
+ import { Catalog } from "./catalog.js";
4
+ import { listStoreDirectories, opfsDirectories, readStoreSize, reconcile } from "./directory.js";
5
+ import { catalogSupported, OpfsCatalogStorage } from "./opfs-storage.js";
6
+ import { performRemoval, RemoveRefused } from "./remove.js";
7
+ export class CatalogError extends Error {
8
+ reason;
9
+ constructor(reason, message) {
10
+ super(message);
11
+ this.name = "CatalogError";
12
+ this.reason = reason;
13
+ }
14
+ }
15
+ function requireStorage() {
16
+ if (!catalogSupported())
17
+ throw new CatalogError("unavailable", "this browser does not offer the origin-private storage and Web Locks the catalog needs");
18
+ }
19
+ /** Every graph the origin has persisted: the catalog's entries joined with the store directories. Opens no store. */
20
+ export async function listGraphs(options = {}) {
21
+ requireStorage();
22
+ const read = await new Catalog(new OpfsCatalogStorage()).read();
23
+ const items = reconcile(read, await listStoreDirectories());
24
+ if (options.sizes) {
25
+ for (const item of items) {
26
+ if (!item.present)
27
+ continue;
28
+ const { size, modified } = await readStoreSize(item.store);
29
+ item.size = size;
30
+ item.modified = modified;
31
+ }
32
+ }
33
+ return { catalog: read.status, items };
34
+ }
35
+ /**
36
+ * Remove one graph by its store name: write `removing`, remove the directory `relate/<store>`, delete the entry. A store
37
+ * another tab holds is refused with reason `locked` and its entry is as its holder left it. Removing an application graph
38
+ * discards the visitor's data, so `options.kind` must say so.
39
+ */
40
+ export async function removeGraph(store, options) {
41
+ requireStorage();
42
+ try {
43
+ return await performRemoval(new Catalog(new OpfsCatalogStorage()), opfsDirectories, store, options);
44
+ }
45
+ catch (e) {
46
+ if (e instanceof RemoveRefused)
47
+ throw new CatalogError(e.reason, e.message);
48
+ throw e;
49
+ }
50
+ }
51
+ /** Delete the catalog file and nothing else: the way out of a catalog that does not parse. No store is touched. */
52
+ export async function resetCatalog() {
53
+ requireStorage();
54
+ return { deleted: await new Catalog(new OpfsCatalogStorage()).reset() };
55
+ }
56
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/catalog/api.ts"],"names":[],"mappings":"AAAA,kIAAkI;AAClI,qGAAqG;AACrG,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,gBAAgB,C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AAK,UAAU,WAAW,CAAC,KAAa,EAAE,OAAsB;IACrE,cAAc,EAAE,CAAC;IACjB,IAAI,CAAC;QACH,OAAO,MAAM,cAAc,CAAC,IAAI,OAAO,CAAC,IAAI,kBAAkB,EAAE,CAAC,EAAE,eAAe,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IACtG,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,CAAC,YAAY,aAAa;YAAE,MAAM,IAAI,YAAY,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;QAC5E,MAAM,CAAC,CAAC;IACV,CAAC;AACH,CAAC;AAED,mHAAmH;AACnH,MAAM,CAAC,KAAK,UAAU,YAAY;IAChC,cAAc,EAAE,CAAC;IACjB,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,OAAO,CAAC,IAAI,kBAAkB,EAAE,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;AAC1E,CAAC"}
@@ -0,0 +1,51 @@
1
+ import type { CatalogStorage } from "./storage.js";
2
+ import type { Entry, EntryInput, ReadResult } from "./types.js";
3
+ /** The file cannot be written over: it does not parse, or a newer format wrote it. Nothing was changed. */
4
+ export declare class CatalogUnavailable extends Error {
5
+ readonly reason: "unreadable" | "newer";
6
+ constructor(reason: "unreadable" | "newer", message: string);
7
+ }
8
+ export type Lookup = {
9
+ status: "none";
10
+ } | {
11
+ status: "entry";
12
+ entry: Entry;
13
+ } | {
14
+ status: "invalid";
15
+ reason: string;
16
+ } | {
17
+ status: "catalog-unreadable";
18
+ message: string;
19
+ } | {
20
+ status: "catalog-newer";
21
+ format: number;
22
+ };
23
+ /**
24
+ * What to do with one entry: return the new entry (without `updatedAt`), `null` to delete it, or `undefined` to leave
25
+ * the file alone. `raw` is the stored value, which is `undefined` when there is none and differs from `current` when
26
+ * the stored entry is malformed.
27
+ */
28
+ export type Change = (current: Entry | undefined, raw: unknown) => EntryInput | null | undefined;
29
+ export interface UpdateResult {
30
+ changed: boolean;
31
+ entry: Entry | null;
32
+ }
33
+ export declare class Catalog {
34
+ private readonly storage;
35
+ private readonly clock;
36
+ constructor(storage: CatalogStorage, clock?: () => Date);
37
+ /** The whole file, read under the shared lock. */
38
+ read(): Promise<ReadResult>;
39
+ /** One graph's entry, read under the shared lock. */
40
+ lookup(store: string): Promise<Lookup>;
41
+ /** Apply one change to one entry inside the exclusive lock. Rejects with {@link CatalogUnavailable} for a file it must not overwrite. */
42
+ update(store: string, change: Change): Promise<UpdateResult>;
43
+ /** Write one entry whatever it was, and return it with its new `updatedAt`. */
44
+ set(store: string, input: EntryInput): Promise<Entry>;
45
+ /** Delete one entry (a missing one is not an error). */
46
+ delete(store: string): Promise<void>;
47
+ /** Delete the catalog file and nothing else (ADR-010 2.5). Works on an unreadable file. Resolves to whether there was a file. */
48
+ reset(): Promise<boolean>;
49
+ /** The entry with the time of this write, strictly later than the entry it replaces, and any field this code does not know kept. */
50
+ private stamp;
51
+ }