@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,104 @@
1
+ // The catalog (ADR-010 2.2): reads and read-modify-write updates of one file, each under the catalog lock.
2
+ // A write applies one change to the current file and replaces it whole. The lock is held for the file access only.
3
+ import { CATALOG_FORMAT } from "../config.js";
4
+ import { emptyCatalog, parseCatalog, serializeCatalog, validateEntry } from "./file.js";
5
+ /** The file cannot be written over: it does not parse, or a newer format wrote it. Nothing was changed. */
6
+ export class CatalogUnavailable extends Error {
7
+ reason;
8
+ constructor(reason, message) {
9
+ super(message);
10
+ this.name = "CatalogUnavailable";
11
+ this.reason = reason;
12
+ }
13
+ }
14
+ const KNOWN = new Set(["kind", "name", "state", "version", "target", "seeded", "revision", "updatedAt"]);
15
+ export class Catalog {
16
+ storage;
17
+ clock;
18
+ constructor(storage, clock = () => new Date()) {
19
+ this.storage = storage;
20
+ this.clock = clock;
21
+ }
22
+ /** The whole file, read under the shared lock. */
23
+ read() {
24
+ return this.storage.withLock("shared", async () => parseCatalog(await this.storage.read()));
25
+ }
26
+ /** One graph's entry, read under the shared lock. */
27
+ async lookup(store) {
28
+ const read = await this.read();
29
+ if (read.status === "unreadable")
30
+ return { status: "catalog-unreadable", message: read.message };
31
+ if (read.status === "newer")
32
+ return { status: "catalog-newer", format: read.format };
33
+ if (read.status === "missing")
34
+ return { status: "none" };
35
+ const raw = read.file.graphs[store];
36
+ if (raw === undefined)
37
+ return { status: "none" };
38
+ const check = validateEntry(store, raw);
39
+ return check.ok ? { status: "entry", entry: check.entry } : { status: "invalid", reason: check.reason };
40
+ }
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, change) {
43
+ return this.storage.withLock("exclusive", async () => {
44
+ const read = parseCatalog(await this.storage.read());
45
+ if (read.status === "unreadable")
46
+ throw new CatalogUnavailable("unreadable", read.message);
47
+ if (read.status === "newer")
48
+ throw new CatalogUnavailable("newer", `the catalog's format ${read.format} is newer than this code's ${CATALOG_FORMAT}`);
49
+ const file = read.status === "ok" ? read.file : emptyCatalog();
50
+ const raw = file.graphs[store];
51
+ const check = raw === undefined ? null : validateEntry(store, raw);
52
+ const current = check && check.ok ? check.entry : undefined;
53
+ const next = change(current, raw);
54
+ if (next === undefined)
55
+ return { changed: false, entry: current ?? null };
56
+ if (next === null) {
57
+ if (!(store in file.graphs))
58
+ return { changed: false, entry: null };
59
+ delete file.graphs[store];
60
+ await this.storage.replace(serializeCatalog(file));
61
+ return { changed: true, entry: null };
62
+ }
63
+ const entry = this.stamp(next, raw);
64
+ file.graphs[store] = entry;
65
+ await this.storage.replace(serializeCatalog(file));
66
+ return { changed: true, entry };
67
+ });
68
+ }
69
+ /** Write one entry whatever it was, and return it with its new `updatedAt`. */
70
+ async set(store, input) {
71
+ const { entry } = await this.update(store, () => input);
72
+ return entry;
73
+ }
74
+ /** Delete one entry (a missing one is not an error). */
75
+ async delete(store) {
76
+ await this.update(store, () => null);
77
+ }
78
+ /** Delete the catalog file and nothing else (ADR-010 2.5). Works on an unreadable file. Resolves to whether there was a file. */
79
+ reset() {
80
+ return this.storage.withLock("exclusive", async () => {
81
+ const had = (await this.storage.read()) !== null;
82
+ await this.storage.remove();
83
+ return had;
84
+ });
85
+ }
86
+ /** The entry with the time of this write, strictly later than the entry it replaces, and any field this code does not know kept. */
87
+ stamp(next, raw) {
88
+ const extras = {};
89
+ let previous = Number.NaN;
90
+ if (typeof raw === "object" && raw !== null && !Array.isArray(raw)) {
91
+ for (const [key, value] of Object.entries(raw))
92
+ if (!KNOWN.has(key))
93
+ extras[key] = value;
94
+ const at = raw.updatedAt;
95
+ if (typeof at === "string")
96
+ previous = Date.parse(at);
97
+ }
98
+ let now = this.clock().getTime();
99
+ if (Number.isFinite(previous) && now <= previous)
100
+ now = previous + 1;
101
+ return { ...extras, ...next, updatedAt: new Date(now).toISOString() };
102
+ }
103
+ }
104
+ //# sourceMappingURL=catalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../src/catalog/catalog.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,mHAAmH;AACnH,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAIxF,2GAA2G;AAC3G,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAClC,MAAM,CAAyB;IACxC,YAAY,MAA8B,EAAE,OAAe;QACzD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAqBD,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;AAEzG,MAAM,OAAO,OAAO;IAEC,OAAO;IACP,KAAK;IAFxB,YACmB,OAAuB,EACvB,KAAK,GAAe,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE;uBADpC,OAAO;qBACP,KAAK;IACr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AE,CAAC;QAC3C,IAAI,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC;QAC1B,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YACnE,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC;gBAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC;oBAAE,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACzF,MAAM,EAAE,GAAI,GAA+B,CAAC,SAAS,CAAC;YACtD,IAAI,OAAO,EAAE,KAAK,QAAQ;gBAAE,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACxD,CAAC;QACD,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,CAAC;QACjC,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI,QAAQ;YAAE,GAAG,GAAG,QAAQ,GAAG,CAAC,CAAC;QACrE,OAAO,EAAE,GAAG,MAAM,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAW,CAAC;IACjF,CAAC;CACF"}
@@ -0,0 +1,30 @@
1
+ import type { ListingItem, ReadResult } from "./types.js";
2
+ /** The names of the store directories under `relate/`, sorted. An origin that stored nothing has none. */
3
+ export declare function listStoreDirectories(): Promise<string[]>;
4
+ /** A store's size (the sum of its files, in bytes) and newest modification time. A file that cannot be read counts as nothing. */
5
+ export declare function readStoreSize(store: string): Promise<{
6
+ size: number;
7
+ modified: number;
8
+ }>;
9
+ /**
10
+ * Join the catalog's entries with the directories found, by store name. A directory with no entry is `unregistered`, an
11
+ * entry with no directory `missing`. A catalog that cannot be read or was written by a newer format lists the
12
+ * directories only, each `unregistered`: its entries are not interpreted.
13
+ */
14
+ export declare function reconcile(read: ReadResult, directories: string[]): ListingItem[];
15
+ /** Why a store directory could not be removed: another tab holds its files. */
16
+ export declare class StoreHeldError extends Error {
17
+ constructor(store: string);
18
+ }
19
+ /** What removal needs of the directories; the browser's is {@link opfsDirectories}, tests give their own. */
20
+ export interface StoreDirectories {
21
+ /**
22
+ * Run `job` while holding the right to remove or roll back this store, so two removals of one store never overlap, in
23
+ * this tab or another. It is a lock of its own: the catalog lock is never held across a directory operation.
24
+ */
25
+ serialize<T>(store: string, job: () => Promise<T>): Promise<T>;
26
+ exists(store: string): Promise<boolean>;
27
+ /** Remove `relate/<store>` and everything in it. Resolves false when there was none; throws {@link StoreHeldError} when it is held. */
28
+ remove(store: string): Promise<boolean>;
29
+ }
30
+ export declare const opfsDirectories: StoreDirectories;
@@ -0,0 +1,116 @@
1
+ // The engine's browser stores as the origin-private directory shows them (ADR-010 2.5, SPIKE-011): each store is a directory
2
+ // `relate/<store>` of slot files. Listing reads names, and, when asked, the files' sizes and modification times. Nothing here
3
+ // opens a store, so it works while another tab holds one. The layout is the engine's own; only the directory's name is used.
4
+ import { splitStoreName, validateEntry } from "./file.js";
5
+ /** The engine's directory at the origin-private root. */
6
+ const ENGINE_DIR = "relate";
7
+ const entriesOf = (dir) => dir.entries();
8
+ const isNotFound = (e) => typeof e === "object" && e !== null && e.name === "NotFoundError";
9
+ async function engineDirectory() {
10
+ try {
11
+ return await (await navigator.storage.getDirectory()).getDirectoryHandle(ENGINE_DIR);
12
+ }
13
+ catch (e) {
14
+ if (isNotFound(e))
15
+ return null;
16
+ throw e;
17
+ }
18
+ }
19
+ /** The names of the store directories under `relate/`, sorted. An origin that stored nothing has none. */
20
+ export async function listStoreDirectories() {
21
+ const dir = await engineDirectory();
22
+ if (!dir)
23
+ return [];
24
+ const names = [];
25
+ for await (const [name, handle] of entriesOf(dir))
26
+ if (handle.kind === "directory")
27
+ names.push(name);
28
+ return names.sort();
29
+ }
30
+ /** A store's size (the sum of its files, in bytes) and newest modification time. A file that cannot be read counts as nothing. */
31
+ export async function readStoreSize(store) {
32
+ let size = 0;
33
+ let modified = 0;
34
+ const base = await engineDirectory();
35
+ if (!base)
36
+ return { size, modified };
37
+ let dir;
38
+ try {
39
+ dir = await base.getDirectoryHandle(store);
40
+ }
41
+ catch {
42
+ return { size, modified };
43
+ }
44
+ for await (const [, handle] of entriesOf(dir)) {
45
+ if (handle.kind !== "file")
46
+ continue;
47
+ try {
48
+ const file = await handle.getFile();
49
+ size += file.size;
50
+ modified = Math.max(modified, file.lastModified);
51
+ }
52
+ catch {
53
+ /* a file another worker is replacing; it adds nothing */
54
+ }
55
+ }
56
+ return { size, modified };
57
+ }
58
+ /**
59
+ * Join the catalog's entries with the directories found, by store name. A directory with no entry is `unregistered`, an
60
+ * entry with no directory `missing`. A catalog that cannot be read or was written by a newer format lists the
61
+ * directories only, each `unregistered`: its entries are not interpreted.
62
+ */
63
+ export function reconcile(read, directories) {
64
+ const entries = read.status === "ok" ? read.file.graphs : {};
65
+ const present = new Set(directories);
66
+ const stores = [...new Set([...Object.keys(entries), ...directories])].sort();
67
+ return stores.map((store) => {
68
+ const here = present.has(store);
69
+ const raw = entries[store];
70
+ if (raw === undefined) {
71
+ const parts = splitStoreName(store);
72
+ return { store, ...(parts ?? {}), registered: false, present: true, status: "unregistered" };
73
+ }
74
+ const parts = splitStoreName(store);
75
+ const checked = validateEntry(store, raw);
76
+ const base = { store, ...(parts ?? {}), registered: true, present: here, status: here ? "ok" : "missing" };
77
+ if (!checked.ok)
78
+ return base;
79
+ const e = checked.entry;
80
+ return { ...base, kind: e.kind, name: e.name, state: e.state, ...(e.kind === "application" ? { version: e.version } : e.revision !== undefined ? { revision: e.revision } : {}) };
81
+ });
82
+ }
83
+ /** Why a store directory could not be removed: another tab holds its files. */
84
+ export class StoreHeldError extends Error {
85
+ constructor(store) {
86
+ super(`the files of ${store} are held by another tab`);
87
+ this.name = "StoreHeldError";
88
+ }
89
+ }
90
+ export const opfsDirectories = {
91
+ serialize(store, job) {
92
+ return navigator.locks.request(`relate-web:remove:${store}`, { mode: "exclusive" }, job);
93
+ },
94
+ async exists(store) {
95
+ return (await listStoreDirectories()).includes(store);
96
+ },
97
+ async remove(store) {
98
+ const base = await engineDirectory();
99
+ if (!base)
100
+ return false;
101
+ try {
102
+ await base.removeEntry(store, { recursive: true });
103
+ return true;
104
+ }
105
+ catch (e) {
106
+ const name = typeof e === "object" && e !== null ? e.name : undefined;
107
+ if (name === "NotFoundError")
108
+ return false;
109
+ // The browser refuses to remove files another tab holds open (measured in Chromium, Firefox and WebKit).
110
+ if (name === "NoModificationAllowedError" || name === "InvalidStateError")
111
+ throw new StoreHeldError(store);
112
+ throw e;
113
+ }
114
+ },
115
+ };
116
+ //# sourceMappingURL=directory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directory.js","sourceRoot":"","sources":["../../src/catalog/directory.ts"],"names":[],"mappings":"AAAA,6HAA6H;AAC7H,8HAA8H;AAC9H,6HAA6H;AAC7H,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAG1D,yDAAyD;AACzD,MAAM,UAAU,GAAG,QAAQ,CAAC;AAG5B,MAAM,SAAS,GAAG,CAAC,GAA8B,EAA6C,EAAE,CAAE,GAA0B,CAAC,OAAO,EAAE,CAAC;AAEvI,MAAM,UAAU,GAAG,CAAC,CAAU,EAAW,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAK,CAAuB,CAAC,IAAI,KAAK,eAAe,CAAC;AAErI,KAAK,UAAU,eAAe;IAC5B,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,SAAS,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;IACvF,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,UAAU,CAAC,CAAC,CAAC;YAA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IACxD,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,KAAK;QAChB,MAAM,IAAI,GAAG,MAAM,eAAe,EAAE,CAAC;QACrC,IAAI,CAAC,IAAI;YAAE,OAAO,KAAK,CAAC;QACxB,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YACnD,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,CAAE,CAAuB,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;YAC7F,IAAI,IAAI,KAAK,eAAe;gBAAE,OAAO,KAAK,CAAC;YAC3C,yGAAyG;YACzG,IAAI,IAAI,KAAK,4BAA4B,IAAI,IAAI,KAAK,mBAAmB;gBAAE,MAAM,IAAI,cAAc,CAAC,KAAK,CAAC,CAAC;YAC3G,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;CACF,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { type CatalogFile, type EntryCheck, type ReadResult } from "./types.js";
2
+ /** Parse the file's text. An absent file is `missing` (the caller passes `null`). */
3
+ export declare function parseCatalog(text: string | null): ReadResult;
4
+ export declare function serializeCatalog(file: CatalogFile): string;
5
+ export declare const emptyCatalog: () => CatalogFile;
6
+ /** The store name's kind and the name inside it, or null when the key is not a store name. */
7
+ export declare function splitStoreName(key: string): {
8
+ kind: "application" | "cache";
9
+ name: string;
10
+ } | null;
11
+ /** Check one entry as it is used. The same object is returned, so fields this code does not know survive a rewrite. */
12
+ export declare function validateEntry(key: string, raw: unknown): EntryCheck;
@@ -0,0 +1,84 @@
1
+ // Reading the catalog file (ADR-010 2.1, specs/007 research R6): the file is checked as a whole, and each entry only
2
+ // when it is used.
3
+ import { APP_NAME_PATTERN, CATALOG_FORMAT, ID_PATTERN } from "../config.js";
4
+ import { APPLICATION_STATES, CACHE_STATES, } from "./types.js";
5
+ const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
6
+ /** Parse the file's text. An absent file is `missing` (the caller passes `null`). */
7
+ export function parseCatalog(text) {
8
+ if (text === null)
9
+ return { status: "missing" };
10
+ let value;
11
+ try {
12
+ value = JSON.parse(text);
13
+ }
14
+ catch (e) {
15
+ return { status: "unreadable", message: `the catalog is not valid JSON (${e instanceof Error ? e.message : String(e)})` };
16
+ }
17
+ if (!isObject(value))
18
+ return { status: "unreadable", message: "the catalog is not a JSON object" };
19
+ const { format, graphs } = value;
20
+ if (typeof format !== "number" || !Number.isInteger(format) || format < 1)
21
+ return { status: "unreadable", message: "the catalog has no valid format" };
22
+ if (!isObject(graphs))
23
+ return { status: "unreadable", message: "the catalog has no graphs object" };
24
+ if (format > CATALOG_FORMAT)
25
+ return { status: "newer", format };
26
+ // The parsed object itself is kept, so a field this code does not know survives a rewrite.
27
+ return { status: "ok", file: value };
28
+ }
29
+ export function serializeCatalog(file) {
30
+ return JSON.stringify(file, null, 2) + "\n";
31
+ }
32
+ export const emptyCatalog = () => ({ format: CATALOG_FORMAT, graphs: {} });
33
+ /** The store name's kind and the name inside it, or null when the key is not a store name. */
34
+ export function splitStoreName(key) {
35
+ if (key.startsWith("app-")) {
36
+ const name = key.slice(4);
37
+ return APP_NAME_PATTERN.test(name) ? { kind: "application", name } : null;
38
+ }
39
+ if (key.startsWith("rel-")) {
40
+ const name = key.slice(4);
41
+ return ID_PATTERN.test(name) ? { kind: "cache", name } : null;
42
+ }
43
+ return null;
44
+ }
45
+ const positive = (n) => typeof n === "number" && Number.isInteger(n) && n >= 1;
46
+ /** Check one entry as it is used. The same object is returned, so fields this code does not know survive a rewrite. */
47
+ export function validateEntry(key, raw) {
48
+ const fail = (reason) => ({ ok: false, reason: `${key}: ${reason}` });
49
+ const parts = splitStoreName(key);
50
+ if (!parts)
51
+ return fail("not a store name");
52
+ if (!isObject(raw))
53
+ return fail("not an object");
54
+ if (raw.kind !== parts.kind)
55
+ return fail(`kind ${String(raw.kind)} does not match the store name`);
56
+ if (raw.name !== parts.name)
57
+ return fail("name does not match the store name");
58
+ if (typeof raw.updatedAt !== "string" || raw.updatedAt === "" || Number.isNaN(Date.parse(raw.updatedAt)))
59
+ return fail("updatedAt is not a time");
60
+ if (parts.kind === "application") {
61
+ if (!APPLICATION_STATES.includes(raw.state))
62
+ return fail(`unknown state ${String(raw.state)}`);
63
+ if (!positive(raw.version))
64
+ return fail("version is not a positive integer");
65
+ if (typeof raw.seeded !== "boolean")
66
+ return fail("seeded is not a boolean");
67
+ if (raw.state === "migrating") {
68
+ if (!positive(raw.target) || raw.target <= raw.version)
69
+ return fail("a migrating entry needs a target above its version");
70
+ }
71
+ else if (raw.target !== undefined) {
72
+ return fail("only a migrating entry has a target");
73
+ }
74
+ return { ok: true, entry: raw };
75
+ }
76
+ if (!CACHE_STATES.includes(raw.state))
77
+ return fail(`unknown state ${String(raw.state)}`);
78
+ if (raw.revision !== undefined && typeof raw.revision !== "string")
79
+ return fail("revision is not a string");
80
+ if (raw.state === "ready" && (typeof raw.revision !== "string" || raw.revision === ""))
81
+ return fail("a ready cache needs a revision");
82
+ return { ok: true, entry: raw };
83
+ }
84
+ //# sourceMappingURL=file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/catalog/file.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,mBAAmB;AACnB,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC5E,OAAO,EACL,kBAAkB,EAClB,YAAY,GAMb,MAAM,YAAY,CAAC;AAEpB,MAAM,QAAQ,GAAG,CAAC,CAAU,EAAgC,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAExH,qFA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;aAAM,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YACpC,OAAO,IAAI,CAAC,qCAAqC,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAkC,EAAE,CAAC;IACjE,CAAC;IAED,IAAI,CAAE,YAAmC,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC,iBAAiB,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACjH,IAAI,GAAG,CAAC,QAAQ,KAAK,SAAS,IAAI,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,0BAA0B,CAAC,CAAC;IAC5G,IAAI,GAAG,CAAC,KAAK,KAAK,OAAO,IAAI,CAAC,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,GAAG,CAAC,QAAQ,KAAK,EAAE,CAAC;QAAE,OAAO,IAAI,CAAC,gCAAgC,CAAC,CAAC;IACtI,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAA4B,EAAE,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { Catalog } from "./catalog.js";
2
+ export { Catalog, CatalogUnavailable } from "./catalog.js";
3
+ export { MemoryCatalogStorage } from "./memory-storage.js";
4
+ export { OpfsCatalogStorage, catalogSupported } from "./opfs-storage.js";
5
+ export { CatalogError, listGraphs, removeGraph, resetCatalog } from "./api.js";
6
+ export type { CatalogErrorReason, ListOptions, Listing, RemoveOptions, RemoveResult } from "./api.js";
7
+ export type { CatalogStorage, LockMode } from "./storage.js";
8
+ export type { ApplicationEntry, ApplicationState, CacheEntry, CacheState, Entry, EntryInput, ListingItem, State } from "./types.js";
9
+ /** The catalog a worker uses: the durable file under the Web Lock, or, for a client that runs in memory, one that lives in memory and writes nothing durable. */
10
+ export declare function openCatalog(durable: boolean): Catalog;
@@ -0,0 +1,12 @@
1
+ import { Catalog } from "./catalog.js";
2
+ import { MemoryCatalogStorage } from "./memory-storage.js";
3
+ import { OpfsCatalogStorage } from "./opfs-storage.js";
4
+ export { Catalog, CatalogUnavailable } from "./catalog.js";
5
+ export { MemoryCatalogStorage } from "./memory-storage.js";
6
+ export { OpfsCatalogStorage, catalogSupported } from "./opfs-storage.js";
7
+ export { CatalogError, listGraphs, removeGraph, resetCatalog } from "./api.js";
8
+ /** The catalog a worker uses: the durable file under the Web Lock, or, for a client that runs in memory, one that lives in memory and writes nothing durable. */
9
+ export function openCatalog(durable) {
10
+ return new Catalog(durable ? new OpfsCatalogStorage() : new MemoryCatalogStorage());
11
+ }
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/catalog/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAK/E,iKAAiK;AACjK,MAAM,UAAU,WAAW,CAAC,OAAgB;IAC1C,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,kBAAkB,EAAE,CAAC,CAAC,CAAC,IAAI,oBAAoB,EAAE,CAAC,CAAC;AACtF,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { CatalogStorage, LockMode } from "./storage.js";
2
+ export declare class MemoryCatalogStorage implements CatalogStorage {
3
+ private text;
4
+ private readers;
5
+ private writer;
6
+ private queue;
7
+ /** How many times the file was replaced, for tests. */
8
+ replaced: number;
9
+ constructor(initial?: string | null);
10
+ read(): Promise<string | null>;
11
+ replace(text: string): Promise<void>;
12
+ remove(): Promise<void>;
13
+ withLock<T>(mode: LockMode, fn: () => Promise<T>): Promise<T>;
14
+ /** Grant waiters in arrival order: any number of readers together, a writer alone. */
15
+ private pump;
16
+ }
@@ -0,0 +1,56 @@
1
+ export class MemoryCatalogStorage {
2
+ text;
3
+ readers = 0;
4
+ writer = false;
5
+ queue = [];
6
+ /** How many times the file was replaced, for tests. */
7
+ replaced = 0;
8
+ constructor(initial = null) {
9
+ this.text = initial;
10
+ }
11
+ async read() {
12
+ return this.text;
13
+ }
14
+ async replace(text) {
15
+ this.text = text;
16
+ this.replaced++;
17
+ }
18
+ async remove() {
19
+ this.text = null;
20
+ }
21
+ async withLock(mode, fn) {
22
+ await new Promise((grant) => {
23
+ this.queue.push({ mode, grant });
24
+ this.pump();
25
+ });
26
+ try {
27
+ return await fn();
28
+ }
29
+ finally {
30
+ if (mode === "exclusive")
31
+ this.writer = false;
32
+ else
33
+ this.readers--;
34
+ this.pump();
35
+ }
36
+ }
37
+ /** Grant waiters in arrival order: any number of readers together, a writer alone. */
38
+ pump() {
39
+ while (this.queue.length > 0) {
40
+ const next = this.queue[0];
41
+ if (this.writer)
42
+ return;
43
+ if (next.mode === "exclusive") {
44
+ if (this.readers > 0)
45
+ return;
46
+ this.writer = true;
47
+ }
48
+ else {
49
+ this.readers++;
50
+ }
51
+ this.queue.shift();
52
+ next.grant();
53
+ }
54
+ }
55
+ }
56
+ //# sourceMappingURL=memory-storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-storage.js","sourceRoot":"","sources":["../../src/catalog/memory-storage.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,oBAAoB;IACvB,IAAI,CAAgB;IACpB,OAAO,GAAG,CAAC,CAA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AI,CAAC,OAAO,GAAG,CAAC;oBAAE,OAAO;gBAC7B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;YACrB,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,CAAC;YACD,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACnB,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ import type { CatalogStorage, LockMode } from "./storage.js";
2
+ /** True when the browser offers both halves the catalog needs: the origin-private storage and Web Locks. */
3
+ export declare function catalogSupported(): boolean;
4
+ export declare class OpfsCatalogStorage implements CatalogStorage {
5
+ private directory;
6
+ read(): Promise<string | null>;
7
+ replace(text: string): Promise<void>;
8
+ remove(): Promise<void>;
9
+ withLock<T>(mode: LockMode, fn: () => Promise<T>): Promise<T>;
10
+ }
@@ -0,0 +1,71 @@
1
+ // The catalog file in the browser's origin-private storage, ordered by a Web Lock (ADR-010 2.2). Reading and replacing
2
+ // work from a page and from a worker. The replace goes through a writable stream, which swaps the file on close, and
3
+ // falls back to a synchronous access handle where the stream is absent. Under the lock the choice does not affect readers.
4
+ import { CATALOG_DIR, CATALOG_FILE, CATALOG_LOCK } from "../config.js";
5
+ const isNotFound = (e) => typeof e === "object" && e !== null && e.name === "NotFoundError";
6
+ /** True when the browser offers both halves the catalog needs: the origin-private storage and Web Locks. */
7
+ export function catalogSupported() {
8
+ const nav = globalThis.navigator;
9
+ return typeof nav?.storage?.getDirectory === "function" && typeof nav?.locks?.request === "function";
10
+ }
11
+ export class OpfsCatalogStorage {
12
+ async directory(create) {
13
+ try {
14
+ const root = await navigator.storage.getDirectory();
15
+ return await root.getDirectoryHandle(CATALOG_DIR, { create });
16
+ }
17
+ catch (e) {
18
+ if (!create && isNotFound(e))
19
+ return null;
20
+ throw e;
21
+ }
22
+ }
23
+ async read() {
24
+ const dir = await this.directory(false);
25
+ if (!dir)
26
+ return null;
27
+ try {
28
+ return await (await (await dir.getFileHandle(CATALOG_FILE)).getFile()).text();
29
+ }
30
+ catch (e) {
31
+ if (isNotFound(e))
32
+ return null;
33
+ throw e;
34
+ }
35
+ }
36
+ async replace(text) {
37
+ const dir = await this.directory(true);
38
+ const handle = await dir.getFileHandle(CATALOG_FILE, { create: true });
39
+ if (typeof handle.createWritable === "function") {
40
+ const writable = await handle.createWritable();
41
+ await writable.write(text);
42
+ await writable.close();
43
+ return;
44
+ }
45
+ const sync = await handle.createSyncAccessHandle();
46
+ try {
47
+ sync.truncate(0);
48
+ sync.write(new TextEncoder().encode(text), { at: 0 });
49
+ sync.flush();
50
+ }
51
+ finally {
52
+ sync.close();
53
+ }
54
+ }
55
+ async remove() {
56
+ const dir = await this.directory(false);
57
+ if (!dir)
58
+ return;
59
+ try {
60
+ await dir.removeEntry(CATALOG_FILE);
61
+ }
62
+ catch (e) {
63
+ if (!isNotFound(e))
64
+ throw e;
65
+ }
66
+ }
67
+ withLock(mode, fn) {
68
+ return navigator.locks.request(CATALOG_LOCK, { mode }, fn);
69
+ }
70
+ }
71
+ //# sourceMappingURL=opfs-storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opfs-storage.js","sourceRoot":"","sources":["../../src/catalog/opfs-storage.ts"],"names":[],"mappings":"AAAA,uHAAuH;AACvH,qHAAqH;AACrH,2HAA2H;AAC3H,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAavE,MAAM,UAAU,GAAG,CAAC,CAAU,EAAW,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAK,CAAuB,CAAC,IAAI,KAAK,eAAe,CAAC;AAErI,4GAA4G;AAC5G,MAAM,UAAU,gBAAgB;IAC9B,MAAM,GAAG,GAAI,UAAsG,CAAC,SAAS,CAAC;IAC9H,OAAO,OAAO,GAAG,EAAE,OAAO,EAAE,YAAY,KAAK,UAAU,IAAI,OAAO,G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EAAE,CAAC;YACvE,MAAM,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC3B,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC;YACvB,OAAO;QACT,CAAC;QACD,MAAM,IAAI,GAAG,MAAO,MAAyB,CAAC,sBAAsB,EAAE,CAAC;QACvE,IAAI,CAAC;YACH,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;YACjB,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;YACtD,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC;IACH,CAAC;IAED,KAAK,CAAC,MAAM;QACV,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACxC,IAAI,CAAC,GAAG;YAAE,OAAO;QACjB,IAAI,CAAC;YACH,MAAM,GAAG,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;QACtC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;gBAAE,MAAM,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,QAAQ,CAAI,IAAc,EAAE,EAAoB;QAC9C,OAAO,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAe,CAAC;IAC3E,CAAC;CACF"}
@@ -0,0 +1,21 @@
1
+ import { type Catalog } from "./catalog.js";
2
+ import { type StoreDirectories } from "./directory.js";
3
+ import type { Entry } from "./types.js";
4
+ export type RemoveFailure = "locked" | "kind-mismatch" | "not-a-store";
5
+ export declare class RemoveRefused extends Error {
6
+ readonly reason: RemoveFailure;
7
+ constructor(reason: RemoveFailure, message: string);
8
+ }
9
+ export interface RemoveOptions {
10
+ /** What the caller says it is removing: required, and an application graph's data cannot be removed without saying so. */
11
+ kind: "application" | "cache";
12
+ }
13
+ export interface RemoveResult {
14
+ store: string;
15
+ kind: "application" | "cache";
16
+ /** The entry as it was, or null when the store had none. */
17
+ entry: Entry | null;
18
+ /** What was discarded: the visitor's data, a cache, a directory the catalog did not know, or nothing at all. */
19
+ discarded: "application data" | "cache" | "unregistered directory" | "nothing";
20
+ }
21
+ export declare function performRemoval(catalog: Catalog, directories: StoreDirectories, store: string, options: RemoveOptions): Promise<RemoveResult>;