@docs-sdk-dev/reader 0.0.0-stage → 0.4.0-next.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 (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +97 -2
  3. package/dist/annotation-projection.d.ts +35 -0
  4. package/dist/annotation-projection.js +78 -0
  5. package/dist/annotation-projection.js.map +1 -0
  6. package/dist/artifacts.d.ts +19 -0
  7. package/dist/artifacts.js +33 -0
  8. package/dist/artifacts.js.map +1 -0
  9. package/dist/ask.d.ts +41 -0
  10. package/dist/ask.js +89 -0
  11. package/dist/ask.js.map +1 -0
  12. package/dist/collection-view.d.ts +190 -0
  13. package/dist/collection-view.js +170 -0
  14. package/dist/collection-view.js.map +1 -0
  15. package/dist/composition.d.ts +199 -0
  16. package/dist/composition.js +473 -0
  17. package/dist/composition.js.map +1 -0
  18. package/dist/condition.d.ts +17 -0
  19. package/dist/condition.js +61 -0
  20. package/dist/condition.js.map +1 -0
  21. package/dist/content-schema.d.ts +182 -0
  22. package/dist/content-schema.js +288 -0
  23. package/dist/content-schema.js.map +1 -0
  24. package/dist/context-search.d.ts +168 -0
  25. package/dist/context-search.js +73 -0
  26. package/dist/context-search.js.map +1 -0
  27. package/dist/context-store.d.ts +93 -0
  28. package/dist/context-store.js +438 -0
  29. package/dist/context-store.js.map +1 -0
  30. package/dist/dimension-runtime.d.ts +203 -0
  31. package/dist/dimension-runtime.js +737 -0
  32. package/dist/dimension-runtime.js.map +1 -0
  33. package/dist/dimensions.d.ts +84 -0
  34. package/dist/dimensions.js +136 -0
  35. package/dist/dimensions.js.map +1 -0
  36. package/dist/directory-navigation.d.ts +60 -0
  37. package/dist/directory-navigation.js +41 -0
  38. package/dist/directory-navigation.js.map +1 -0
  39. package/dist/directory-sections.d.ts +9 -0
  40. package/dist/directory-sections.js +76 -0
  41. package/dist/directory-sections.js.map +1 -0
  42. package/dist/document-reader.d.ts +1017 -0
  43. package/dist/document-reader.js +396 -0
  44. package/dist/document-reader.js.map +1 -0
  45. package/dist/document-selection.d.ts +412 -0
  46. package/dist/document-selection.js +45 -0
  47. package/dist/document-selection.js.map +1 -0
  48. package/dist/evidence.d.ts +102 -0
  49. package/dist/evidence.js +104 -0
  50. package/dist/evidence.js.map +1 -0
  51. package/dist/index.d.ts +19 -0
  52. package/dist/index.js +23 -0
  53. package/dist/model.d.ts +89 -0
  54. package/dist/model.js +31 -0
  55. package/dist/model.js.map +1 -0
  56. package/dist/module.d.ts +657 -0
  57. package/dist/module.js +199 -0
  58. package/dist/module.js.map +1 -0
  59. package/dist/navigation-view.d.ts +33 -0
  60. package/dist/navigation-view.js +68 -0
  61. package/dist/navigation-view.js.map +1 -0
  62. package/dist/node.d.ts +2004 -0
  63. package/dist/node.js +210 -0
  64. package/dist/node.js.map +1 -0
  65. package/dist/open-docs.d.ts +1396 -0
  66. package/dist/open-docs.js +198 -0
  67. package/dist/open-docs.js.map +1 -0
  68. package/dist/outline.d.ts +97 -0
  69. package/dist/outline.js +171 -0
  70. package/dist/outline.js.map +1 -0
  71. package/dist/persistence.d.ts +82 -0
  72. package/dist/persistence.js +377 -0
  73. package/dist/persistence.js.map +1 -0
  74. package/dist/projection-catalog.d.ts +23 -0
  75. package/dist/projection-catalog.js +45 -0
  76. package/dist/projection-catalog.js.map +1 -0
  77. package/dist/publication.d.ts +59 -0
  78. package/dist/publication.js +11 -0
  79. package/dist/publication.js.map +1 -0
  80. package/dist/reader.d.ts +236 -0
  81. package/dist/reader.js +400 -0
  82. package/dist/reader.js.map +1 -0
  83. package/dist/references.d.ts +54 -0
  84. package/dist/references.js +70 -0
  85. package/dist/references.js.map +1 -0
  86. package/dist/retrieval.d.ts +82 -0
  87. package/dist/retrieval.js +135 -0
  88. package/dist/retrieval.js.map +1 -0
  89. package/dist/search-view.d.ts +11 -0
  90. package/dist/search-view.js +30 -0
  91. package/dist/search-view.js.map +1 -0
  92. package/dist/search.d.ts +95 -0
  93. package/dist/search.js +234 -0
  94. package/dist/search.js.map +1 -0
  95. package/dist/semantic.d.ts +177 -0
  96. package/dist/semantic.js +104 -0
  97. package/dist/semantic.js.map +1 -0
  98. package/dist/skills.d.ts +21 -0
  99. package/dist/skills.js +42 -0
  100. package/dist/skills.js.map +1 -0
  101. package/docs/index.md +10 -0
  102. package/docs/sdk/composition.md +72 -0
  103. package/docs/sdk/reader-storage.md +70 -0
  104. package/docs/sdk/reader.md +99 -0
  105. package/docs/zh-CN/sdk/composition.md +72 -0
  106. package/docs/zh-CN/sdk/reader-storage.md +70 -0
  107. package/docs/zh-CN/sdk/reader.md +99 -0
  108. package/package.json +69 -4
@@ -0,0 +1,377 @@
1
+ import { isJsonValue } from "./content-schema.js";
2
+
3
+ // src/persistence.ts
4
+ /** Project IDs may also use an installed package's scoped npm name. */
5
+ function validPersistenceId(value) {
6
+ return typeof value === "string" && value.length <= 128 && /^(?:[a-zA-Z0-9][a-zA-Z0-9._/-]*|@[a-zA-Z0-9][a-zA-Z0-9._-]*\/[a-zA-Z0-9][a-zA-Z0-9._-]*)$/.test(value);
7
+ }
8
+ function validPersistencePolicy(policy, portable = false) {
9
+ if (typeof policy === "string") return !!policy.trim();
10
+ if (!policy || typeof policy !== "object" || Array.isArray(policy)) return false;
11
+ const { adapter, sync, version, migrate, expiration } = policy;
12
+ return Object.keys(policy).every((key) => [
13
+ "adapter",
14
+ "sync",
15
+ "version",
16
+ "migrate",
17
+ "expiration"
18
+ ].includes(key)) && typeof adapter === "string" && !!adapter.trim() && (sync === void 0 || typeof sync === "boolean") && (version === void 0 || Number.isSafeInteger(version) && version > 0) && (migrate === void 0 || typeof migrate === "string" && !!migrate.trim() || !portable && typeof migrate === "function") && (expiration === void 0 || Number.isSafeInteger(expiration) && expiration > 0);
19
+ }
20
+ function definePersistenceAdapter(adapter) {
21
+ return adapter;
22
+ }
23
+ function contextScopeAddress(kind, identity) {
24
+ if (kind === "project") return ["project"];
25
+ const scope = identity?.scope ?? identity?.document?.scope;
26
+ if (!scope || identity?.document && identity.document.scope !== scope) return;
27
+ if (kind === "scope") return ["scope", scope];
28
+ const document = identity?.document?.id;
29
+ if (!document) return;
30
+ if (kind === "document") return [
31
+ "document",
32
+ scope,
33
+ document
34
+ ];
35
+ if (kind === "section") return identity.section ? [
36
+ "section",
37
+ scope,
38
+ document,
39
+ identity.section
40
+ ] : void 0;
41
+ return identity.example ? [
42
+ "example",
43
+ scope,
44
+ document,
45
+ identity.section ?? null,
46
+ identity.example
47
+ ] : void 0;
48
+ }
49
+ function decode(raw) {
50
+ const record = JSON.parse(raw);
51
+ if (!record || typeof record !== "object" || Array.isArray(record)) throw new TypeError("Invalid persistence record.");
52
+ const { version, value, expiresAt } = record;
53
+ if (!Number.isSafeInteger(version) || version < 1 || !isJsonValue(value) || expiresAt !== void 0 && (!Number.isFinite(expiresAt) || expiresAt < 0)) throw new TypeError("Invalid persistence record.");
54
+ return {
55
+ version,
56
+ value,
57
+ expiresAt
58
+ };
59
+ }
60
+ function pending(result) {
61
+ return !!result && typeof result.then === "function";
62
+ }
63
+ function createPersistenceRuntime(options) {
64
+ if (!validPersistenceId(options.projectId)) throw new TypeError("Persistence requires a valid, stable project ID.");
65
+ const adapters = /* @__PURE__ */ new Map();
66
+ const memory = /* @__PURE__ */ new Map();
67
+ for (const adapter of options.adapters ?? []) {
68
+ if (!adapter.id.trim() || adapters.has(adapter.id)) throw new TypeError("Invalid or duplicate persistence adapter: " + adapter.id);
69
+ adapters.set(adapter.id, adapter);
70
+ }
71
+ if (!adapters.has("memory")) adapters.set("memory", definePersistenceAdapter({
72
+ id: "memory",
73
+ read: (key) => memory.get(key),
74
+ write(key, value) {
75
+ memory.set(key, value);
76
+ },
77
+ remove(key) {
78
+ memory.delete(key);
79
+ }
80
+ }));
81
+ const slots = /* @__PURE__ */ new Map();
82
+ const now = options.now ?? Date.now;
83
+ let ready = !options.defer;
84
+ let disposed = false;
85
+ let depth = 0;
86
+ const notifications = /* @__PURE__ */ new Set();
87
+ function batch(work) {
88
+ depth++;
89
+ try {
90
+ work();
91
+ } finally {
92
+ if (--depth === 0) {
93
+ const pending = [...notifications];
94
+ notifications.clear();
95
+ for (const listener of pending) listener();
96
+ }
97
+ }
98
+ }
99
+ function report(info) {
100
+ try {
101
+ options.onError?.(info);
102
+ } catch {}
103
+ }
104
+ function channel(key, binding, durable) {
105
+ const policy = typeof binding.policy === "string" ? { adapter: binding.policy } : binding.policy;
106
+ const adapter = durable && policy ? adapters.get(policy.adapter) : void 0;
107
+ const version = policy?.version ?? 1;
108
+ const controller = new AbortController();
109
+ const context = { signal: controller.signal };
110
+ const listeners = /* @__PURE__ */ new Set();
111
+ const validate = binding.validate;
112
+ let selected;
113
+ let remembered;
114
+ let loaded = false;
115
+ let generation = 0;
116
+ let read;
117
+ let writes;
118
+ let unsubscribe;
119
+ let timer;
120
+ const diagnose = (code, cause) => report({
121
+ code,
122
+ adapter: policy?.adapter,
123
+ key,
124
+ cause
125
+ });
126
+ if (durable && policy && !adapter) diagnose("unknown-adapter");
127
+ const current = (epoch) => !disposed && epoch === generation;
128
+ const fresh = (record) => record && (record.expiresAt === void 0 || record.expiresAt > now()) ? record : void 0;
129
+ const value = () => fresh(selected ?? remembered)?.value;
130
+ function scheduleExpiration() {
131
+ clearTimeout(timer);
132
+ timer = void 0;
133
+ const record = fresh(selected ?? remembered);
134
+ if (!listeners.size || record?.expiresAt === void 0) return;
135
+ const previous = record.value;
136
+ timer = setTimeout(() => {
137
+ if (!fresh(record)) publish(previous);
138
+ else scheduleExpiration();
139
+ }, Math.min(record.expiresAt - now(), 0x7fffffff));
140
+ if (typeof timer === "object" && "unref" in timer) timer.unref();
141
+ }
142
+ function publish(previous) {
143
+ scheduleExpiration();
144
+ if (!Object.is(previous, value()) && JSON.stringify(previous) !== JSON.stringify(value())) for (const listener of [...listeners]) if (depth) notifications.add(listener);
145
+ else listener();
146
+ }
147
+ const snapshot = options.initial?.[key];
148
+ if (snapshot !== void 0 && durable && policy) try {
149
+ const record = fresh(decode(snapshot));
150
+ if (record?.version === version) remembered = {
151
+ ...record,
152
+ value: validate(record.value)
153
+ };
154
+ } catch (cause) {
155
+ diagnose("invalid-record", cause);
156
+ }
157
+ function attempt(run, accept = () => {}, failed = (cause) => diagnose("adapter", cause)) {
158
+ try {
159
+ const result = run();
160
+ if (pending(result)) return Promise.resolve(result).then(accept).catch(failed);
161
+ const applied = accept(result);
162
+ if (pending(applied)) return Promise.resolve(applied).catch(failed);
163
+ } catch (cause) {
164
+ failed(cause);
165
+ }
166
+ }
167
+ function persist(record, epoch) {
168
+ if (!adapter) return;
169
+ const run = () => {
170
+ if (!current(epoch)) return;
171
+ return attempt(() => record ? adapter.write(key, JSON.stringify(record), context) : adapter.remove(key, context), () => {
172
+ if (!current(epoch)) return;
173
+ remembered = record;
174
+ });
175
+ };
176
+ const task = writes ? writes.then(run) : run();
177
+ if (task) {
178
+ const done = task.finally(() => {
179
+ if (writes === done) writes = void 0;
180
+ });
181
+ writes = done;
182
+ }
183
+ }
184
+ function restore(force = false) {
185
+ if (disposed || !adapter || !ready || loaded && !force) return read;
186
+ if (writes) {
187
+ const waiting = generation;
188
+ return writes.then(() => {
189
+ if (current(waiting)) return restore(force);
190
+ });
191
+ }
192
+ loaded = true;
193
+ const epoch = ++generation;
194
+ function accept(record) {
195
+ if (!current(epoch)) return;
196
+ const previous = value();
197
+ selected = void 0;
198
+ remembered = record;
199
+ publish(previous);
200
+ }
201
+ function restoreRecord(record) {
202
+ if (!current(epoch)) return;
203
+ if (!fresh(record)) {
204
+ accept();
205
+ return;
206
+ }
207
+ const apply = (next) => {
208
+ if (!current(epoch)) return;
209
+ if (next === void 0) return accept();
210
+ try {
211
+ const valid = {
212
+ ...record,
213
+ version,
214
+ value: validate(next)
215
+ };
216
+ accept(valid);
217
+ if (record.version !== version) persist(valid, epoch);
218
+ } catch (cause) {
219
+ diagnose("invalid-record", cause);
220
+ accept();
221
+ }
222
+ };
223
+ if (record.version === version) return apply(record.value);
224
+ if (record.version > version) return accept();
225
+ const migrate = typeof policy?.migrate === "string" ? Object.hasOwn(options.migrations ?? {}, policy.migrate) ? options.migrations?.[policy.migrate] : void 0 : policy?.migrate;
226
+ if (!migrate) {
227
+ if (policy?.migrate) diagnose("migration");
228
+ return accept();
229
+ }
230
+ return attempt(() => migrate(record.value, record.version), apply, (cause) => {
231
+ diagnose("migration", cause);
232
+ accept();
233
+ });
234
+ }
235
+ function run() {
236
+ if (!adapter || !current(epoch)) return;
237
+ return attempt(() => adapter.read(key, context), (raw) => {
238
+ if (!current(epoch)) return;
239
+ if (raw === void 0) return accept();
240
+ try {
241
+ return restoreRecord(decode(raw));
242
+ } catch (cause) {
243
+ diagnose("invalid-record", cause);
244
+ accept();
245
+ }
246
+ });
247
+ }
248
+ const task = run();
249
+ if (task) {
250
+ const done = task.finally(() => {
251
+ if (read === done) read = void 0;
252
+ });
253
+ read = done;
254
+ }
255
+ return read;
256
+ }
257
+ function expiry() {
258
+ return policy?.expiration === void 0 ? {} : { expiresAt: now() + policy.expiration };
259
+ }
260
+ const slot = {
261
+ value,
262
+ persisted: () => fresh(remembered)?.value,
263
+ record() {
264
+ const record = fresh(remembered);
265
+ return record ? [key, JSON.stringify(record)] : void 0;
266
+ },
267
+ set(next) {
268
+ if (disposed) return false;
269
+ const previous = value();
270
+ const record = next === void 0 ? void 0 : {
271
+ version,
272
+ value: validate(next),
273
+ ...expiry()
274
+ };
275
+ if (record && fresh(selected ?? remembered) && Object.is(previous, record.value) && record.expiresAt === (selected ?? remembered)?.expiresAt && !writes && !read && (adapter === void 0 || Object.is(fresh(remembered)?.value, record.value))) return false;
276
+ const epoch = ++generation;
277
+ loaded = true;
278
+ selected = record;
279
+ if (record === void 0) remembered = void 0;
280
+ persist(record, epoch);
281
+ publish(previous);
282
+ return !Object.is(previous, value());
283
+ },
284
+ subscribe(listener) {
285
+ listeners.add(listener);
286
+ scheduleExpiration();
287
+ try {
288
+ if (listeners.size === 1 && ready && policy?.sync && adapter?.subscribe) unsubscribe = adapter.subscribe(key, () => {
289
+ restore(true);
290
+ });
291
+ } catch (cause) {
292
+ diagnose("adapter", cause);
293
+ }
294
+ return () => {
295
+ listeners.delete(listener);
296
+ if (!listeners.size) stop();
297
+ };
298
+ }
299
+ };
300
+ function stop() {
301
+ clearTimeout(timer);
302
+ timer = void 0;
303
+ try {
304
+ unsubscribe?.();
305
+ } catch (cause) {
306
+ diagnose("adapter", cause);
307
+ }
308
+ unsubscribe = void 0;
309
+ }
310
+ return {
311
+ slot,
312
+ restore() {
313
+ try {
314
+ if (!unsubscribe && listeners.size && policy?.sync && adapter?.subscribe) unsubscribe = adapter.subscribe(key, () => {
315
+ restore(true);
316
+ });
317
+ } catch (cause) {
318
+ diagnose("adapter", cause);
319
+ }
320
+ return restore();
321
+ },
322
+ dispose() {
323
+ controller.abort();
324
+ stop();
325
+ listeners.clear();
326
+ }
327
+ };
328
+ }
329
+ return {
330
+ batch,
331
+ bind(binding) {
332
+ const placement = contextScopeAddress(binding.scope ?? "project", binding.identity);
333
+ if (!placement) {
334
+ if (binding.policy) report({
335
+ code: "missing-identity",
336
+ key: binding.id
337
+ });
338
+ return channel(binding.id, binding, false).slot;
339
+ }
340
+ const key = "docs:v1:" + JSON.stringify([
341
+ options.projectId,
342
+ options.namespace ?? null,
343
+ options.account ?? null,
344
+ placement,
345
+ binding.id
346
+ ]);
347
+ let entry = slots.get(key);
348
+ if (!entry) {
349
+ entry = channel(key, binding, true);
350
+ slots.set(key, entry);
351
+ if (ready) entry.restore();
352
+ }
353
+ return entry.slot;
354
+ },
355
+ async restore() {
356
+ if (disposed) return;
357
+ ready = true;
358
+ await Promise.all([...slots.values()].map((entry) => entry.restore()));
359
+ },
360
+ snapshot() {
361
+ return Object.fromEntries([...slots.values()].flatMap(({ slot }) => {
362
+ const record = slot.record();
363
+ return record ? [record] : [];
364
+ }));
365
+ },
366
+ dispose() {
367
+ if (disposed) return;
368
+ disposed = true;
369
+ for (const entry of slots.values()) entry.dispose();
370
+ slots.clear();
371
+ memory.clear();
372
+ }
373
+ };
374
+ }
375
+
376
+ export { contextScopeAddress, createPersistenceRuntime, definePersistenceAdapter, validPersistenceId, validPersistencePolicy };
377
+ //# sourceMappingURL=persistence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persistence.js","names":[],"sources":["../src/persistence.ts"],"sourcesContent":["import { isJsonValue, type JsonValue } from \"./content-schema.js\"\nimport type { Identity } from \"./model.js\"\n\ntype Awaitable<T> = T | PromiseLike<T>\n/** Project IDs may also use an installed package's scoped npm name. */\nexport function validPersistenceId(value: unknown): value is string {\n return (\n typeof value === \"string\" &&\n value.length <= 128 &&\n /^(?:[a-zA-Z0-9][a-zA-Z0-9._/-]*|@[a-zA-Z0-9][a-zA-Z0-9._-]*\\/[a-zA-Z0-9][a-zA-Z0-9._-]*)$/.test(\n value,\n )\n )\n}\n\nexport type PersistenceAdapterId = \"memory\" | \"local\" | \"session\" | \"cookie\" | (string & {})\nexport type PersistenceMigration<T extends JsonValue = JsonValue> = (\n value: unknown,\n fromVersion: number,\n) => Awaitable<T | undefined>\n\nexport interface PersistenceOptions<Migration = string> {\n adapter: PersistenceAdapterId\n sync?: boolean\n version?: number\n migrate?: Migration\n /** Time to live in milliseconds, measured from the last explicit selection. */\n expiration?: number\n}\nexport type PublishedPersistencePolicy = PersistenceAdapterId | PersistenceOptions\nexport type PersistencePolicy<T extends JsonValue = JsonValue> =\n PersistenceAdapterId | PersistenceOptions<string | PersistenceMigration<T>>\n\nexport function validPersistencePolicy(\n policy: unknown,\n portable = false,\n): policy is PersistencePolicy {\n if (typeof policy === \"string\") return !!policy.trim()\n if (!policy || typeof policy !== \"object\" || Array.isArray(policy)) return false\n const { adapter, sync, version, migrate, expiration } = policy as PersistenceOptions<unknown>\n return (\n Object.keys(policy).every((key) =>\n [\"adapter\", \"sync\", \"version\", \"migrate\", \"expiration\"].includes(key),\n ) &&\n typeof adapter === \"string\" &&\n !!adapter.trim() &&\n (sync === undefined || typeof sync === \"boolean\") &&\n (version === undefined || (Number.isSafeInteger(version) && version > 0)) &&\n (migrate === undefined ||\n (typeof migrate === \"string\" && !!migrate.trim()) ||\n (!portable && typeof migrate === \"function\")) &&\n (expiration === undefined || (Number.isSafeInteger(expiration) && expiration > 0))\n )\n}\n\nexport type ContextScopeKind = \"project\" | \"scope\" | \"document\" | \"section\" | \"example\"\nexport interface ContextScopeIdentity {\n scope?: string\n document?: Identity\n section?: string\n example?: string\n}\nexport interface PersistenceAdapterContext {\n signal: AbortSignal\n}\nexport interface PersistenceAdapter<Id extends string = string> {\n id: Id\n read(key: string, context: PersistenceAdapterContext): Awaitable<string | undefined>\n write(key: string, record: string, context: PersistenceAdapterContext): Awaitable<void>\n remove(key: string, context: PersistenceAdapterContext): Awaitable<void>\n subscribe?(key: string, invalidate: () => void): () => void\n}\nexport function definePersistenceAdapter<const Id extends string>(\n adapter: PersistenceAdapter<Id>,\n): PersistenceAdapter<Id> {\n return adapter\n}\n\n/** Serialized, validated preference records for the initial server and client render. */\nexport type PersistenceSnapshot = Readonly<Record<string, string>>\nexport interface PersistenceDiagnostic {\n code: \"unknown-adapter\" | \"missing-identity\" | \"invalid-record\" | \"migration\" | \"adapter\"\n key: string\n adapter?: string\n cause?: unknown\n}\nexport interface PersistenceRuntimeOptions {\n projectId: string\n namespace?: string\n account?: string\n adapters?: readonly PersistenceAdapter[]\n migrations?: Readonly<Record<string, PersistenceMigration>>\n initial?: PersistenceSnapshot\n defer?: boolean\n onError?(diagnostic: PersistenceDiagnostic): void\n now?(): number\n}\nexport interface ContextPersistenceBinding {\n id: string\n scope?: ContextScopeKind\n identity?: ContextScopeIdentity\n policy?: PublishedPersistencePolicy\n}\ntype Binding = Omit<ContextPersistenceBinding, \"policy\"> & {\n policy?: PersistencePolicy\n validate(value: JsonValue): JsonValue\n}\ninterface PreferenceRecord {\n version: number\n value: JsonValue\n expiresAt?: number\n}\n\nexport function contextScopeAddress(kind: ContextScopeKind, identity?: ContextScopeIdentity) {\n if (kind === \"project\") return [\"project\"]\n const scope = identity?.scope ?? identity?.document?.scope\n if (!scope || (identity?.document && identity.document.scope !== scope)) return\n if (kind === \"scope\") return [\"scope\", scope]\n const document = identity?.document?.id\n if (!document) return\n if (kind === \"document\") return [\"document\", scope, document]\n if (kind === \"section\")\n return identity.section ? [\"section\", scope, document, identity.section] : undefined\n return identity.example\n ? [\"example\", scope, document, identity.section ?? null, identity.example]\n : undefined\n}\n\nfunction decode(raw: string): PreferenceRecord {\n const record: unknown = JSON.parse(raw)\n if (!record || typeof record !== \"object\" || Array.isArray(record))\n throw new TypeError(\"Invalid persistence record.\")\n const { version, value, expiresAt } = record as PreferenceRecord\n if (\n !Number.isSafeInteger(version) ||\n version < 1 ||\n !isJsonValue(value) ||\n (expiresAt !== undefined && (!Number.isFinite(expiresAt) || expiresAt < 0))\n )\n throw new TypeError(\"Invalid persistence record.\")\n return { version, value, expiresAt }\n}\n\nfunction pending<T>(result: Awaitable<T>): result is PromiseLike<T> {\n return !!result && typeof (result as PromiseLike<T>).then === \"function\"\n}\n\nexport interface PersistenceSlot {\n value(): JsonValue | undefined\n persisted(): JsonValue | undefined\n record(): readonly [key: string, record: string] | undefined\n set(value: JsonValue | undefined): boolean\n subscribe(listener: () => void): () => void\n}\n\nexport function createPersistenceRuntime(options: PersistenceRuntimeOptions) {\n if (!validPersistenceId(options.projectId))\n throw new TypeError(\"Persistence requires a valid, stable project ID.\")\n const adapters = new Map<string, PersistenceAdapter>()\n const memory = new Map<string, string>()\n for (const adapter of options.adapters ?? []) {\n if (!adapter.id.trim() || adapters.has(adapter.id))\n throw new TypeError(\"Invalid or duplicate persistence adapter: \" + adapter.id)\n adapters.set(adapter.id, adapter)\n }\n if (!adapters.has(\"memory\"))\n adapters.set(\n \"memory\",\n definePersistenceAdapter({\n id: \"memory\",\n read: (key) => memory.get(key),\n write(key, value) {\n memory.set(key, value)\n },\n remove(key) {\n memory.delete(key)\n },\n }),\n )\n const slots = new Map<string, ReturnType<typeof channel>>()\n const now = options.now ?? Date.now\n let ready = !options.defer\n let disposed = false\n let depth = 0\n const notifications = new Set<() => void>()\n function batch(work: () => void) {\n depth++\n try {\n work()\n } finally {\n if (--depth === 0) {\n const pending = [...notifications]\n notifications.clear()\n for (const listener of pending) listener()\n }\n }\n }\n function report(info: PersistenceDiagnostic) {\n try {\n options.onError?.(info)\n } catch {\n /* Diagnostics must not disrupt reading. */\n }\n }\n\n function channel(key: string, binding: Binding, durable: boolean) {\n const policy = typeof binding.policy === \"string\" ? { adapter: binding.policy } : binding.policy\n const adapter = durable && policy ? adapters.get(policy.adapter) : undefined\n const version = policy?.version ?? 1\n const controller = new AbortController()\n const context = { signal: controller.signal }\n const listeners = new Set<() => void>()\n const validate = binding.validate\n let selected: PreferenceRecord | undefined\n let remembered: PreferenceRecord | undefined\n let loaded = false\n let generation = 0\n let read: Promise<void> | undefined\n let writes: Promise<void> | undefined\n let unsubscribe: (() => void) | undefined\n let timer: ReturnType<typeof setTimeout> | undefined\n const diagnose = (code: PersistenceDiagnostic[\"code\"], cause?: unknown) =>\n report({ code, adapter: policy?.adapter, key, cause })\n if (durable && policy && !adapter) diagnose(\"unknown-adapter\")\n const current = (epoch: number) => !disposed && epoch === generation\n const fresh = (record?: PreferenceRecord) =>\n record && (record.expiresAt === undefined || record.expiresAt > now()) ? record : undefined\n const value = () => fresh(selected ?? remembered)?.value\n function scheduleExpiration() {\n clearTimeout(timer)\n timer = undefined\n const record = fresh(selected ?? remembered)\n if (!listeners.size || record?.expiresAt === undefined) return\n const previous = record.value\n timer = setTimeout(\n () => {\n if (!fresh(record)) publish(previous)\n else scheduleExpiration()\n },\n Math.min(record.expiresAt - now(), 2_147_483_647),\n )\n if (typeof timer === \"object\" && \"unref\" in timer) timer.unref()\n }\n function publish(previous: JsonValue | undefined) {\n scheduleExpiration()\n if (!Object.is(previous, value()) && JSON.stringify(previous) !== JSON.stringify(value()))\n for (const listener of [...listeners]) {\n if (depth) notifications.add(listener)\n else listener()\n }\n }\n\n const snapshot = options.initial?.[key]\n if (snapshot !== undefined && durable && policy) {\n try {\n const record = fresh(decode(snapshot))\n if (record?.version === version) remembered = { ...record, value: validate(record.value) }\n } catch (cause) {\n diagnose(\"invalid-record\", cause)\n }\n }\n\n function attempt<T>(\n run: () => Awaitable<T>,\n accept: (value: T) => Awaitable<void> = () => {},\n failed: (cause: unknown) => void = (cause) => diagnose(\"adapter\", cause),\n ): void | Promise<void> {\n try {\n const result = run()\n if (pending(result)) return Promise.resolve(result).then(accept).catch(failed)\n const applied = accept(result)\n if (pending(applied)) return Promise.resolve(applied).catch(failed)\n } catch (cause) {\n failed(cause)\n }\n }\n\n function persist(record: PreferenceRecord | undefined, epoch: number) {\n if (!adapter) return\n const run = () => {\n if (!current(epoch)) return\n return attempt(\n () =>\n record\n ? adapter.write(key, JSON.stringify(record), context)\n : adapter.remove(key, context),\n () => {\n if (!current(epoch)) return\n remembered = record\n },\n )\n }\n const task = writes ? writes.then(run) : run()\n if (task) {\n const done = task.finally(() => {\n if (writes === done) writes = undefined\n })\n writes = done\n }\n }\n\n function restore(force = false): Promise<void> | undefined {\n if (disposed || !adapter || !ready || (loaded && !force)) return read\n if (writes) {\n const waiting = generation\n return writes.then(() => {\n if (current(waiting)) return restore(force)\n })\n }\n loaded = true\n const epoch = ++generation\n function accept(record?: PreferenceRecord) {\n if (!current(epoch)) return\n const previous = value()\n selected = undefined\n remembered = record\n publish(previous)\n }\n function restoreRecord(record: PreferenceRecord) {\n if (!current(epoch)) return\n if (!fresh(record)) {\n accept()\n return\n }\n const apply = (next: JsonValue | undefined) => {\n if (!current(epoch)) return\n if (next === undefined) return accept()\n try {\n const valid = { ...record, version, value: validate(next) }\n accept(valid)\n if (record.version !== version) persist(valid, epoch)\n } catch (cause) {\n diagnose(\"invalid-record\", cause)\n accept()\n }\n }\n if (record.version === version) return apply(record.value)\n if (record.version > version) return accept()\n const migrate =\n typeof policy?.migrate === \"string\"\n ? Object.hasOwn(options.migrations ?? {}, policy.migrate)\n ? options.migrations?.[policy.migrate]\n : undefined\n : policy?.migrate\n if (!migrate) {\n if (policy?.migrate) diagnose(\"migration\")\n return accept()\n }\n return attempt(\n () => migrate(record.value, record.version),\n apply,\n (cause) => {\n diagnose(\"migration\", cause)\n accept()\n },\n )\n }\n function run() {\n if (!adapter || !current(epoch)) return\n return attempt(\n () => adapter.read(key, context),\n (raw) => {\n if (!current(epoch)) return\n if (raw === undefined) return accept()\n try {\n return restoreRecord(decode(raw))\n } catch (cause) {\n diagnose(\"invalid-record\", cause)\n accept()\n }\n },\n )\n }\n const task = run()\n if (task) {\n const done = task.finally(() => {\n if (read === done) read = undefined\n })\n read = done\n }\n return read\n }\n\n function expiry() {\n return policy?.expiration === undefined ? {} : { expiresAt: now() + policy.expiration }\n }\n const slot: PersistenceSlot = {\n value,\n persisted: () => fresh(remembered)?.value,\n record() {\n const record = fresh(remembered)\n return record ? [key, JSON.stringify(record)] : undefined\n },\n set(next) {\n if (disposed) return false\n const previous = value()\n const record =\n next === undefined ? undefined : { version, value: validate(next), ...expiry() }\n if (\n record &&\n fresh(selected ?? remembered) &&\n Object.is(previous, record.value) &&\n record.expiresAt === (selected ?? remembered)?.expiresAt &&\n !writes &&\n !read &&\n (adapter === undefined || Object.is(fresh(remembered)?.value, record.value))\n )\n return false\n const epoch = ++generation\n loaded = true\n selected = record\n if (record === undefined) remembered = undefined\n persist(record, epoch)\n publish(previous)\n return !Object.is(previous, value())\n },\n subscribe(listener) {\n listeners.add(listener)\n scheduleExpiration()\n try {\n if (listeners.size === 1 && ready && policy?.sync && adapter?.subscribe)\n unsubscribe = adapter.subscribe(key, () => {\n void restore(true)\n })\n } catch (cause) {\n diagnose(\"adapter\", cause)\n }\n return () => {\n listeners.delete(listener)\n if (!listeners.size) stop()\n }\n },\n }\n function stop() {\n clearTimeout(timer)\n timer = undefined\n try {\n unsubscribe?.()\n } catch (cause) {\n diagnose(\"adapter\", cause)\n }\n unsubscribe = undefined\n }\n return {\n slot,\n restore() {\n try {\n if (!unsubscribe && listeners.size && policy?.sync && adapter?.subscribe)\n unsubscribe = adapter.subscribe(key, () => {\n void restore(true)\n })\n } catch (cause) {\n diagnose(\"adapter\", cause)\n }\n return restore()\n },\n dispose() {\n controller.abort()\n stop()\n listeners.clear()\n },\n }\n }\n\n return {\n batch,\n bind(binding: Binding): PersistenceSlot {\n const placement = contextScopeAddress(binding.scope ?? \"project\", binding.identity)\n if (!placement) {\n if (binding.policy) report({ code: \"missing-identity\", key: binding.id })\n return channel(binding.id, binding, false).slot\n }\n const key =\n \"docs:v1:\" +\n JSON.stringify([\n options.projectId,\n options.namespace ?? null,\n options.account ?? null,\n placement,\n binding.id,\n ])\n let entry = slots.get(key)\n if (!entry) {\n entry = channel(key, binding, true)\n slots.set(key, entry)\n if (ready) void entry.restore()\n }\n return entry.slot\n },\n async restore() {\n if (disposed) return\n ready = true\n await Promise.all([...slots.values()].map((entry) => entry.restore()))\n },\n snapshot(): PersistenceSnapshot {\n return Object.fromEntries(\n [...slots.values()].flatMap(({ slot }) => {\n const record = slot.record()\n return record ? [record] : []\n }),\n )\n },\n dispose() {\n if (disposed) return\n disposed = true\n for (const entry of slots.values()) entry.dispose()\n slots.clear()\n memory.clear()\n },\n }\n}\nexport type PersistenceRuntime = ReturnType<typeof createPersistenceRuntime>\n"],"mappings":";;;;AAKA,SAAgB,mBAAmB,OAAiC;CAClE,OACE,OAAO,UAAU,YACjB,MAAM,UAAU,OAChB,4FAA4F,KAC1F,KACF;AAEJ;AAoBA,SAAgB,uBACd,QACA,WAAW,OACkB;CAC7B,IAAI,OAAO,WAAW,UAAU,OAAO,CAAC,CAAC,OAAO,KAAK;CACrD,IAAI,CAAC,UAAU,OAAO,WAAW,YAAY,MAAM,QAAQ,MAAM,GAAG,OAAO;CAC3E,MAAM,EAAE,SAAS,MAAM,SAAS,SAAS,eAAe;CACxD,OACE,OAAO,KAAK,MAAM,CAAC,CAAC,OAAO,QACzB;EAAC;EAAW;EAAQ;EAAW;EAAW;CAAY,CAAC,CAAC,SAAS,GAA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ClC,MAAM,IAAI,KAAK,KAAK;IACpB,IAAI,OAAY,MAAM,QAAQ;GAChC;GACA,OAAO,MAAM;EACf;EACA,MAAM,UAAU;GACd,IAAI,UAAU;GACd,QAAQ;GACR,MAAM,QAAQ,IAAI,CAAC,GAAG,MAAM,OAAO,CAAC,CAAC,CAAC,KAAK,UAAU,MAAM,QAAQ,CAAC,CAAC;EACvE;EACA,WAAgC;GAC9B,OAAO,OAAO,YACZ,CAAC,GAAG,MAAM,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,WAAW;IACxC,MAAM,SAAS,KAAK,OAAO;IAC3B,OAAO,SAAS,CAAC,MAAM,IAAI,CAAC;GAC9B,CAAC,CACH;EACF;EACA,UAAU;GACR,IAAI,UAAU;GACd,WAAW;GACX,KAAK,MAAM,SAAS,MAAM,OAAO,GAAG,MAAM,QAAQ;GAClD,MAAM,MAAM;GACZ,OAAO,MAAM;EACf;CACF;AACF"}
@@ -0,0 +1,23 @@
1
+ import type { CodeSearchPolicy } from "./publication.js";
2
+ export interface PublicationProjection {
3
+ target: "web" | "markdown" | "semantic" | "search";
4
+ entityTypes: "indexed" | readonly ("document" | "section")[];
5
+ relations: "content-links" | "indexed" | "omitted";
6
+ context: "document-edition" | "entity-variant" | "section-edition";
7
+ requiredManifestFields: readonly ("documents" | "semantic" | "search")[];
8
+ sourceEvidence: "manifest-provenance" | "semantic-provenance" | "source-paths";
9
+ recordsDocumentLosses?: true;
10
+ codeBlocks?: CodeSearchPolicy;
11
+ }
12
+ export interface PublicationProjectionCatalog {
13
+ schemaVersion: 1;
14
+ deliveries?: readonly {
15
+ id: string;
16
+ version: string;
17
+ requires?: readonly PublicationProjection["target"][];
18
+ files: readonly string[];
19
+ }[];
20
+ targets: readonly PublicationProjection[];
21
+ }
22
+ /** Delivery contracts for the standard static publisher. */
23
+ export declare function createPublicationProjectionCatalog(codeBlocks?: CodeSearchPolicy): PublicationProjectionCatalog;
@@ -0,0 +1,45 @@
1
+ // src/projection-catalog.ts
2
+ /** Delivery contracts for the standard static publisher. */
3
+ function createPublicationProjectionCatalog(codeBlocks = "exclude") {
4
+ const document = {
5
+ entityTypes: ["document", "section"],
6
+ relations: "content-links",
7
+ context: "document-edition",
8
+ requiredManifestFields: ["documents"],
9
+ sourceEvidence: "manifest-provenance",
10
+ recordsDocumentLosses: true
11
+ };
12
+ return {
13
+ schemaVersion: 1,
14
+ targets: [
15
+ {
16
+ target: "web",
17
+ ...document
18
+ },
19
+ {
20
+ target: "markdown",
21
+ ...document
22
+ },
23
+ {
24
+ target: "semantic",
25
+ entityTypes: "indexed",
26
+ relations: "indexed",
27
+ context: "entity-variant",
28
+ requiredManifestFields: ["semantic"],
29
+ sourceEvidence: "semantic-provenance"
30
+ },
31
+ {
32
+ target: "search",
33
+ entityTypes: ["section"],
34
+ relations: "omitted",
35
+ context: "section-edition",
36
+ requiredManifestFields: ["search"],
37
+ sourceEvidence: "source-paths",
38
+ codeBlocks
39
+ }
40
+ ]
41
+ };
42
+ }
43
+
44
+ export { createPublicationProjectionCatalog };
45
+ //# sourceMappingURL=projection-catalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projection-catalog.js","names":[],"sources":["../src/projection-catalog.ts"],"sourcesContent":["import type { CodeSearchPolicy } from \"./publication.js\"\n\nexport interface PublicationProjection {\n target: \"web\" | \"markdown\" | \"semantic\" | \"search\"\n entityTypes: \"indexed\" | readonly (\"document\" | \"section\")[]\n relations: \"content-links\" | \"indexed\" | \"omitted\"\n context: \"document-edition\" | \"entity-variant\" | \"section-edition\"\n requiredManifestFields: readonly (\"documents\" | \"semantic\" | \"search\")[]\n sourceEvidence: \"manifest-provenance\" | \"semantic-provenance\" | \"source-paths\"\n recordsDocumentLosses?: true\n codeBlocks?: CodeSearchPolicy\n}\nexport interface PublicationProjectionCatalog {\n schemaVersion: 1\n deliveries?: readonly {\n id: string\n version: string\n requires?: readonly PublicationProjection[\"target\"][]\n files: readonly string[]\n }[]\n targets: readonly PublicationProjection[]\n}\n\n/** Delivery contracts for the standard static publisher. */\nexport function createPublicationProjectionCatalog(\n codeBlocks: CodeSearchPolicy = \"exclude\",\n): PublicationProjectionCatalog {\n const document = {\n entityTypes: [\"document\", \"section\"],\n relations: \"content-links\",\n context: \"document-edition\",\n requiredManifestFields: [\"documents\"],\n sourceEvidence: \"manifest-provenance\",\n recordsDocumentLosses: true,\n } as const\n return {\n schemaVersion: 1,\n targets: [\n { target: \"web\", ...document },\n { target: \"markdown\", ...document },\n {\n target: \"semantic\",\n entityTypes: \"indexed\",\n relations: \"indexed\",\n context: \"entity-variant\",\n requiredManifestFields: [\"semantic\"],\n sourceEvidence: \"semantic-provenance\",\n },\n {\n target: \"search\",\n entityTypes: [\"section\"],\n relations: \"omitted\",\n context: \"section-edition\",\n requiredManifestFields: [\"search\"],\n sourceEvidence: \"source-paths\",\n codeBlocks,\n },\n ],\n }\n}\n"],"mappings":";;AAwBA,SAAgB,mCACd,aAA+B,WACD;CAC9B,MAAM,WAAW;EACf,aAAa,CAAC,YAAY,SAAS;EACnC,WAAW;EACX,SAAS;EACT,wBAAwB,CAAC,WAAW;EACpC,gBAAgB;EAChB,uBAAuB;CACzB;CACA,OAAO;EACL,eAAe;EACf,SAAS;GACP;IAAE,QAAQ;IAAO,GAAG;GAAS;GAC7B;IAAE,QAAQ;IAAY,GAAG;GAAS;GAClC;IACE,QAAQ;IACR,aAAa;IACb,WAAW;IACX,SAAS;IACT,wBAAwB,CAAC,UAAU;IACnC,gBAAgB;GAClB;GACA;IACE,QAAQ;IACR,aAAa,CAAC,SAAS;IACvB,WAAW;IACX,SAAS;IACT,wBAAwB,CAAC,QAAQ;IACjC,gBAAgB;IAChB;GACF;EACF;CACF;AACF"}
@@ -0,0 +1,59 @@
1
+ import type { Provenance } from "./model.js";
2
+ export interface SourceDiagnostic {
3
+ code: string;
4
+ severity: "warning" | "error";
5
+ message: string;
6
+ source?: string;
7
+ line?: number;
8
+ }
9
+ export declare const sourceOutputKinds: readonly ["records", "facts", "relations", "assets", "diagnostics"];
10
+ export interface SourceDeclaration {
11
+ outputs: readonly (typeof sourceOutputKinds)[number][];
12
+ entityTypes?: readonly string[];
13
+ runtime?: string;
14
+ credentialNames?: readonly string[];
15
+ }
16
+ export type SourceRole = "toolchain" | "project" | "projection";
17
+ export type CodeSearchPolicy = "include" | "exclude";
18
+ /** Producer-side evidence, excluding raw record values and credential values. */
19
+ export interface SourceReceipt {
20
+ adapter: string;
21
+ implementationRevision?: string;
22
+ declaration?: SourceDeclaration;
23
+ scope: string;
24
+ consumers: string[];
25
+ reads: {
26
+ path: string;
27
+ revision: string;
28
+ git?: Provenance["git"];
29
+ }[];
30
+ missing: string[];
31
+ globs: {
32
+ pattern: string;
33
+ exclude: readonly string[];
34
+ members: readonly string[];
35
+ }[];
36
+ selectionRevision?: string;
37
+ appliedSelection?: readonly "where"[];
38
+ accessRevision?: string;
39
+ upstream?: {
40
+ source: string;
41
+ revision: string;
42
+ }[];
43
+ fileInventoryRevision?: string;
44
+ facts?: {
45
+ variant: string;
46
+ revision: string;
47
+ }[];
48
+ assets?: {
49
+ path: string;
50
+ bytes: number;
51
+ revision: string;
52
+ }[];
53
+ diagnostics?: readonly SourceDiagnostic[];
54
+ records: {
55
+ id: string;
56
+ context: Record<string, string>;
57
+ revision: string;
58
+ }[];
59
+ }
@@ -0,0 +1,11 @@
1
+ // src/publication.ts
2
+ const sourceOutputKinds = [
3
+ "records",
4
+ "facts",
5
+ "relations",
6
+ "assets",
7
+ "diagnostics"
8
+ ];
9
+
10
+ export { sourceOutputKinds };
11
+ //# sourceMappingURL=publication.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publication.js","names":[],"sources":["../src/publication.ts"],"sourcesContent":["import type { Provenance } from \"./model.js\"\n\nexport interface SourceDiagnostic {\n code: string\n severity: \"warning\" | \"error\"\n message: string\n source?: string\n line?: number\n}\nexport const sourceOutputKinds = [\"records\", \"facts\", \"relations\", \"assets\", \"diagnostics\"] as const\nexport interface SourceDeclaration {\n outputs: readonly (typeof sourceOutputKinds)[number][]\n entityTypes?: readonly string[]\n runtime?: string\n credentialNames?: readonly string[]\n}\n\nexport type SourceRole = \"toolchain\" | \"project\" | \"projection\"\nexport type CodeSearchPolicy = \"include\" | \"exclude\"\n\n/** Producer-side evidence, excluding raw record values and credential values. */\nexport interface SourceReceipt {\n adapter: string\n implementationRevision?: string\n declaration?: SourceDeclaration\n scope: string\n consumers: string[]\n reads: { path: string; revision: string; git?: Provenance[\"git\"] }[]\n missing: string[]\n globs: { pattern: string; exclude: readonly string[]; members: readonly string[] }[]\n selectionRevision?: string\n appliedSelection?: readonly \"where\"[]\n accessRevision?: string\n upstream?: { source: string; revision: string }[]\n fileInventoryRevision?: string\n facts?: { variant: string; revision: string }[]\n assets?: { path: string; bytes: number; revision: string }[]\n diagnostics?: readonly SourceDiagnostic[]\n records: { id: string; context: Record<string, string>; revision: string }[]\n}\n"],"mappings":";AASA,MAAa,oBAAoB;CAAC;CAAW;CAAS;CAAa;CAAU;AAAa"}