doxum 0.1.13 → 0.1.14

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 (41) hide show
  1. package/README.md +4 -0
  2. package/dist/advanced.cjs +1 -1
  3. package/dist/advanced.d.cts +1 -1
  4. package/dist/advanced.d.ts +1 -1
  5. package/dist/advanced.js +1 -1
  6. package/dist/{definition-177L4Amk.cjs → definition-BDW6i7fp.cjs} +8 -20
  7. package/dist/{definition-177L4Amk.cjs.map → definition-BDW6i7fp.cjs.map} +1 -1
  8. package/dist/{definition-kxnWUvX9.d.cts → definition-DN6yW2vi.d.cts} +37 -36
  9. package/dist/{definition-BlMeHwdz.d.ts → definition-Dr8tHwTD.d.ts} +37 -36
  10. package/dist/{definition-DXrKMVs7.js → definition-wOvuklwp.js} +9 -3
  11. package/dist/{definition-DXrKMVs7.js.map → definition-wOvuklwp.js.map} +1 -1
  12. package/dist/index.cjs +2 -2
  13. package/dist/index.d.cts +3 -3
  14. package/dist/index.d.ts +3 -3
  15. package/dist/index.js +2 -2
  16. package/dist/integration-WniqaEPW.cjs +30 -0
  17. package/dist/integration-WniqaEPW.cjs.map +1 -0
  18. package/dist/{integration-Bco8ZB16.js → integration-zB8e-uNP.js} +3 -7
  19. package/dist/integration-zB8e-uNP.js.map +1 -0
  20. package/dist/integration.cjs +2 -5
  21. package/dist/integration.d.cts +3 -7
  22. package/dist/integration.d.ts +3 -7
  23. package/dist/integration.js +3 -3
  24. package/dist/react.cjs +2 -2
  25. package/dist/react.js +2 -2
  26. package/dist/{store-DcDpDgjk.cjs → store-6wMvZthf.cjs} +4 -6
  27. package/dist/store-6wMvZthf.cjs.map +1 -0
  28. package/dist/{store-P5dJ7TVe.d.ts → store-BCR20XSb.d.ts} +2 -2
  29. package/dist/{store-CtgvCVFg.js → store-PLKs1KnS.js} +4 -6
  30. package/dist/store-PLKs1KnS.js.map +1 -0
  31. package/dist/{store-CDeqZEE3.d.cts → store-jJ3SNYKH.d.cts} +2 -2
  32. package/package.json +1 -1
  33. package/skills/doxum-runtime/references/guide.en.md +2 -1
  34. package/skills/doxum-runtime/references/guide.zh-CN.md +2 -1
  35. package/skills/doxum-runtime/references/projections.en.md +8 -1
  36. package/skills/doxum-runtime/references/projections.zh-CN.md +7 -1
  37. package/dist/integration-Bco8ZB16.js.map +0 -1
  38. package/dist/integration-CEUn96tx.cjs +0 -52
  39. package/dist/integration-CEUn96tx.cjs.map +0 -1
  40. package/dist/store-CtgvCVFg.js.map +0 -1
  41. package/dist/store-DcDpDgjk.cjs.map +0 -1
package/README.md CHANGED
@@ -234,6 +234,10 @@ Projection declarations are lazy and reusable. The only Runtime operations are
234
234
  state, publication and recovery stay inside the Runtime. Collection values are
235
235
  immutable `ReadonlyMap`-like snapshots, so callers do not hold lifecycle handles.
236
236
 
237
+ `observe` is the single source boundary for documents, Doxum `Readable` values,
238
+ and eventful external sources. External sources declare `kind: 'value'` or
239
+ `kind: 'collection'`; collection invalidation remains keyed internally.
240
+
237
241
  For retained state, reverse indexes and keyed patches, use the isolated advanced
238
242
  entry point. Whole-value processors use `incremental(...)`; keyed collection
239
243
  processors use `incremental.collection(...)`:
package/dist/advanced.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_definition = require("./definition-177L4Amk.cjs");
2
+ const require_definition = require("./definition-BDW6i7fp.cjs");
3
3
  //#region core/src/projection/advanced.ts
4
4
  const dependenciesOf = (dependencies) => Object.fromEntries(dependencies.map((dependency, index) => [`d${index}`, dependency]));
5
5
  const sourceChange = (sources) => {
@@ -1,4 +1,4 @@
1
- import { i as PublicCollection, l as CollectionDraft, n as Projection, r as ProjectionValues, u as CollectionRead } from "./definition-kxnWUvX9.cjs";
1
+ import { i as PublicCollection, l as CollectionDraft, n as Projection, r as ProjectionValues, u as CollectionRead } from "./definition-DN6yW2vi.cjs";
2
2
 
3
3
  //#region core/src/projection/advanced.d.ts
4
4
  type IncrementalState = Record<string, unknown>;
@@ -1,4 +1,4 @@
1
- import { i as PublicCollection, l as CollectionDraft, n as Projection, r as ProjectionValues, u as CollectionRead } from "./definition-BlMeHwdz.js";
1
+ import { i as PublicCollection, l as CollectionDraft, n as Projection, r as ProjectionValues, u as CollectionRead } from "./definition-Dr8tHwTD.js";
2
2
 
3
3
  //#region core/src/projection/advanced.d.ts
4
4
  type IncrementalState = Record<string, unknown>;
package/dist/advanced.js CHANGED
@@ -1,4 +1,4 @@
1
- import { i as defineIncrementalValue, p as snapshot, r as defineIncrementalCollection } from "./definition-DXrKMVs7.js";
1
+ import { n as defineIncrementalValue, t as defineIncrementalCollection, u as snapshot } from "./definition-wOvuklwp.js";
2
2
  //#region core/src/projection/advanced.ts
3
3
  const dependenciesOf = (dependencies) => Object.fromEntries(dependencies.map((dependency, index) => [`d${index}`, dependency]));
4
4
  const sourceChange = (sources) => {
@@ -735,6 +735,7 @@ const input = (initial, equality = Object.is) => define({
735
735
  isEqual: equality
736
736
  });
737
737
  function observe(document, selector) {
738
+ if (isExternalSource(document)) return document.kind === "collection" ? defineExternalCollection(document) : defineExternalValue(document);
738
739
  if ("current" in document && typeof document.current === "function") return defineReadable(document);
739
740
  return define({
740
741
  kind: "document",
@@ -742,6 +743,11 @@ function observe(document, selector) {
742
743
  selector
743
744
  });
744
745
  }
746
+ const isExternalSource = (source) => {
747
+ if (!source || typeof source !== "object") return false;
748
+ const candidate = source;
749
+ return (candidate.kind === "value" || candidate.kind === "collection") && typeof candidate.current === "function" && typeof candidate.revision === "function" && typeof candidate.subscribe === "function";
750
+ };
745
751
  function derive(dependencies, compute, equality = Object.is) {
746
752
  if (!Array.isArray(dependencies) || dependencies.some((value) => !definitions.has(value))) throw new TypeError("derive dependencies must be projections.");
747
753
  return define({
@@ -751,7 +757,7 @@ function derive(dependencies, compute, equality = Object.is) {
751
757
  isEqual: equality
752
758
  });
753
759
  }
754
- /** Internal adapters used by the integration boundary, not exported publicly. */
760
+ /** Internal source adapters used by observe, not exported publicly. */
755
761
  const defineReadable = (readable, equality = Object.is) => define({
756
762
  kind: "readable",
757
763
  readable,
@@ -816,18 +822,6 @@ Object.defineProperty(exports, "createAccess", {
816
822
  return createAccess;
817
823
  }
818
824
  });
819
- Object.defineProperty(exports, "defineExternalCollection", {
820
- enumerable: true,
821
- get: function() {
822
- return defineExternalCollection;
823
- }
824
- });
825
- Object.defineProperty(exports, "defineExternalValue", {
826
- enumerable: true,
827
- get: function() {
828
- return defineExternalValue;
829
- }
830
- });
831
825
  Object.defineProperty(exports, "defineIncrementalCollection", {
832
826
  enumerable: true,
833
827
  get: function() {
@@ -840,12 +834,6 @@ Object.defineProperty(exports, "defineIncrementalValue", {
840
834
  return defineIncrementalValue;
841
835
  }
842
836
  });
843
- Object.defineProperty(exports, "defineReadable", {
844
- enumerable: true,
845
- get: function() {
846
- return defineReadable;
847
- }
848
- });
849
837
  Object.defineProperty(exports, "definitionOf", {
850
838
  enumerable: true,
851
839
  get: function() {
@@ -895,4 +883,4 @@ Object.defineProperty(exports, "snapshot", {
895
883
  }
896
884
  });
897
885
 
898
- //# sourceMappingURL=definition-177L4Amk.cjs.map
886
+ //# sourceMappingURL=definition-BDW6i7fp.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"definition-177L4Amk.cjs","names":["isRecord","isPlainObject","compiledShape","validTree","fail","remove","fail","index","remove","replace","insert","fail","keys","replace","remove","fail","contains","replace","move","fail","keys","resolveChild","resolveLocated","nodeAt","compiledShape","children"],"sources":["../core/src/schema-value.ts","../core/src/mutation/operations/map.ts","../core/src/mutation/operations/table.ts","../core/src/mutation/operations/list.ts","../core/src/mutation/operations/tree.ts","../core/src/mutation/operations/order.ts","../core/src/access/scope.ts","../core/src/projection/definition.ts"],"sourcesContent":["import type { DocumentAddress, DocumentNode, Infer } from './schema';\nimport { compiledShape } from './address';\nimport { isPlainObject, isRecord } from './value/ownership';\nimport { validate as validTree } from './mutation/tree';\nimport * as anchor from './mutation/anchor';\nimport { profile } from './profile';\n\n/** Pure synchronous validation. Successful output is ignored; input is never transformed. */\nexport type Validator<T> =\n | ((value: unknown) => T)\n | {\n readonly '~standard': {\n readonly version: 1;\n readonly vendor: string;\n readonly types?: { readonly input: unknown; readonly output: T };\n validate(value: unknown):\n | { readonly value: T; readonly issues?: undefined }\n | {\n readonly issues: readonly {\n readonly message: string;\n readonly path?: readonly (PropertyKey | { readonly key: PropertyKey })[];\n }[];\n }\n | PromiseLike<unknown>;\n };\n };\n\nexport type ParseIssue = {\n readonly address: DocumentAddress;\n readonly code: 'invalid-value' | 'invalid-key' | 'missing-validator' | 'invalid-tree';\n readonly message: string;\n};\nexport class ParseError extends TypeError {\n readonly issues: readonly ParseIssue[];\n constructor(issue: ParseIssue) {\n super(`${issue.message} at ${JSON.stringify(issue.address)}`);\n this.name = 'ParseError';\n this.issues = Object.freeze([\n Object.freeze({ ...issue, address: Object.freeze([...issue.address]) }),\n ]);\n }\n}\n\nconst issue = (\n address: DocumentAddress,\n message: string,\n code: ParseIssue['code'] = 'invalid-value'\n): ParseIssue => ({ address, message, code });\n\nexport const checkScalar = (\n validator: Validator<unknown> | undefined,\n value: unknown,\n address: DocumentAddress,\n strict: boolean\n): ParseIssue | undefined => {\n if (!validator)\n return strict\n ? issue(address, 'A validator is required to parse an opaque value.', 'missing-validator')\n : undefined;\n try {\n const result =\n typeof validator === 'function' ? validator(value) : validator['~standard'].validate(value);\n if (\n result &&\n (typeof result === 'object' || typeof result === 'function') &&\n 'then' in result &&\n typeof result.then === 'function'\n )\n return issue(address, 'Validators must be synchronous.');\n if (typeof validator !== 'function') {\n if (!isRecord(result)) return issue(address, 'Malformed validator result.');\n if (Array.isArray(result.issues)) {\n const first = result.issues[0];\n return issue(\n [\n ...address,\n ...(first?.path ?? []).map((part: PropertyKey | { key: PropertyKey }) =>\n String(typeof part === 'object' ? part.key : part)\n ),\n ],\n first?.message ?? 'Value validation failed.'\n );\n }\n if (!Object.hasOwn(result, 'value')) return issue(address, 'Malformed validator result.');\n }\n return undefined;\n } catch (error) {\n return issue(address, error instanceof Error ? error.message : 'Value validation failed.');\n }\n};\n\nexport const checkKey = (\n validator: Validator<string> | undefined,\n value: unknown,\n address: DocumentAddress\n): ParseIssue | undefined => {\n if (typeof value !== 'string')\n return issue(address, 'Collection keys must be strings.', 'invalid-key');\n const failure = checkScalar(validator, value, address, false);\n return failure ? { ...failure, code: 'invalid-key' } : undefined;\n};\n\nexport const checkValue = (\n node: DocumentNode,\n value: unknown,\n address: DocumentAddress = [],\n strict = false\n): ParseIssue | undefined => {\n if (node.optional && value === undefined) return undefined;\n if (node.kind === 'field') return checkScalar(node.validator, value, address, strict);\n if (node.kind === 'object' || node.kind === 'variant') {\n if (!isPlainObject(value)) return issue(address, 'Expected an object.');\n if (node.kind === 'variant') {\n const tag = value[node.tag];\n if (\n !Object.hasOwn(value, node.tag) ||\n typeof tag !== 'string' ||\n !Object.hasOwn(node.variants, tag)\n )\n return issue([...address, node.tag], 'Unknown variant tag.');\n }\n const { members } = compiledShape(node, value)!;\n for (const key of Reflect.ownKeys(value)) {\n if (node.kind === 'variant' && key === node.tag) continue;\n if (typeof key !== 'string' || !members.has(key))\n return issue([...address, String(key)], 'Property is not declared in the object schema.');\n }\n for (const [key, member] of members) {\n const child = member.node;\n if (!Object.prototype.hasOwnProperty.call(value, key) && !child.optional)\n return issue([...address, key], 'Required property is missing.');\n const failure = checkValue(child, value[key], [...address, key], strict);\n if (failure) return failure;\n }\n return undefined;\n }\n if (node.kind === 'table' || node.kind === 'map') {\n if (!isPlainObject(value)) return issue(address, 'Expected a collection object.');\n const entries = node.kind === 'table' ? value.byId : value;\n if (!isPlainObject(entries)) return issue(address, 'Expected a byId object.');\n if (node.kind === 'table') {\n if (!Array.isArray(value.ids) || value.ids.length !== Object.keys(entries).length)\n return issue(address, 'Table ids and entries must agree.');\n const seen = new Set<string>();\n for (const id of value.ids) {\n const failure = checkKey(node.key, id, address);\n if (failure) return failure;\n if (seen.has(id) || !Object.prototype.hasOwnProperty.call(entries, id))\n return issue(address, 'Table ids must be unique and reference existing entries.');\n seen.add(id);\n }\n }\n for (const id of Object.keys(entries)) {\n const failure =\n checkKey(node.key, id, [...address, id]) ??\n checkValue(node.value, entries[id], [...address, id], strict);\n if (failure) return failure;\n }\n return undefined;\n }\n if (node.kind === 'list') {\n if (!Array.isArray(value)) return issue(address, 'Expected a list.');\n const seen = new Set<string>();\n const order = anchor.keys(value, node.keyOf);\n for (let i = 0; i < value.length; i++) {\n const failure = checkValue(node.value, value[i], [...address, String(i)], strict);\n if (failure) return failure;\n let key: unknown;\n try {\n key = order.at(i);\n } catch {\n return issue(address, 'List keyOf failed.');\n }\n if (typeof key !== 'string' || seen.has(key))\n return issue(address, 'List keys must be unique strings.', 'invalid-key');\n seen.add(key);\n }\n return undefined;\n }\n if (!validTree(value)) return issue(address, 'Invalid tree structure.', 'invalid-tree');\n if (isRecord(value) && isRecord(value.nodes)) {\n for (const id of Object.keys(value.nodes)) {\n const entry = value.nodes[id];\n if (isRecord(entry) && Object.prototype.hasOwnProperty.call(entry, 'value')) {\n const failure = checkValue(node.value, entry.value, [...address, id], strict);\n if (failure) return failure;\n }\n }\n }\n return undefined;\n};\n\n/** Copy editable structure; atomic payloads retain their immutable ownership contract. */\nexport const copyValue = (node: DocumentNode, value: unknown): unknown => {\n if (value === undefined || node.kind === 'field') return value;\n profile.copy.structure();\n if ((node.kind === 'object' || node.kind === 'variant') && isRecord(value)) {\n const result = Object.create(Object.getPrototypeOf(value));\n const { members } = compiledShape(node, value)!;\n for (const key of Object.getOwnPropertyNames(value)) {\n Object.defineProperty(result, key, {\n value:\n node.kind === 'variant' && key === node.tag\n ? value[key]\n : copyValue(members.get(key)!.node, value[key]),\n writable: true,\n enumerable: Object.getOwnPropertyDescriptor(value, key)?.enumerable,\n configurable: true,\n });\n }\n return result;\n }\n if ((node.kind === 'table' || node.kind === 'map') && isRecord(value)) {\n const entries = (node.kind === 'table' ? value.byId : value) as Record<string, unknown>;\n const result = Object.fromEntries(\n Object.keys(entries).map(id => [id, copyValue(node.value, entries[id])])\n );\n return node.kind === 'table' ? { ids: [...(value.ids as string[])], byId: result } : result;\n }\n if (node.kind === 'list') return [...(value as unknown[])];\n if (node.kind === 'tree' && isRecord(value)) {\n const entries = value.nodes as Record<string, { children: readonly string[] }>;\n return {\n ...value,\n nodes: Object.fromEntries(\n Object.entries(entries).map(([id, n]) => [id, { ...n, children: [...n.children] }])\n ),\n };\n }\n return value;\n};\n\nexport const equalValue = (node: DocumentNode, left: unknown, right: unknown): boolean => {\n if (Object.is(left, right)) return true;\n if (node.kind === 'field' || left === undefined || right === undefined) return false;\n if ((node.kind === 'object' || node.kind === 'variant') && isRecord(left) && isRecord(right)) {\n if (node.kind === 'variant' && left[node.tag] !== right[node.tag]) return false;\n for (const [key, member] of compiledShape(node, left)!.members) {\n if (Object.hasOwn(left, key) !== Object.hasOwn(right, key)) return false;\n if (!equalValue(member.node, left[key], right[key])) return false;\n }\n return true;\n }\n if (node.kind === 'list' && Array.isArray(left) && Array.isArray(right))\n return (\n left.length === right.length && left.every((v, i) => equalValue(node.value, v, right[i]))\n );\n if (node.kind === 'table' && isRecord(left) && isRecord(right))\n return (\n anchor.equal(left.ids as string[], right.ids as string[]) &&\n equalValue({ kind: 'map', value: node.value }, left.byId, right.byId)\n );\n if (node.kind === 'tree' && isRecord(left) && isRecord(right)) {\n if (left.rootId !== right.rootId) return false;\n const a = left.nodes as Record<\n string,\n { parentId?: string; children: string[]; value?: unknown }\n >,\n b = right.nodes as typeof a;\n return (\n Object.keys(a).length === Object.keys(b).length &&\n Object.keys(a).every(\n id =>\n Object.hasOwn(b, id) &&\n a[id].parentId === b[id].parentId &&\n anchor.equal(a[id].children, b[id].children) &&\n Object.hasOwn(a[id], 'value') === Object.hasOwn(b[id], 'value') &&\n equalValue(node.value, a[id].value, b[id].value)\n )\n );\n }\n if (node.kind === 'map' && isRecord(left) && isRecord(right)) {\n const keys = Object.keys(left);\n return (\n keys.length === Object.keys(right).length &&\n keys.every(key => Object.hasOwn(right, key) && equalValue(node.value, left[key], right[key]))\n );\n }\n return false;\n};\n\nexport const parse = <N extends DocumentNode>(node: N, input: unknown): Infer<N> => {\n const valueNode: DocumentNode = node;\n const failure = checkValue(valueNode, input, [], true);\n if (failure) throw new ParseError(failure);\n return copyValue(valueNode, input) as Infer<N>;\n};\n","import type { MutationSession } from '../session';\nimport type { ResolvedContainer } from '../../address';\nimport { fail } from '../issue';\n\nexport function put(\n session: MutationSession,\n container: ResolvedContainer,\n id: string,\n value: unknown\n): void {\n if (container.node.kind !== 'map')\n return fail(container.at, 'invalid-collection', 'Expected a map.');\n session.writeMember(container, id, value, 'set');\n}\n\nexport function remove(session: MutationSession, container: ResolvedContainer, id: string): void {\n if (container.node.kind !== 'map')\n return fail(container.at, 'invalid-collection', 'Expected a map.');\n session.writeMember(container, id, undefined, 'remove');\n}\n","import type { DocumentAnchor } from '../../schema';\nimport type { MutationSession } from '../session';\nimport type { ResolvedContainer } from '../../address';\nimport * as anchor from '../anchor';\nimport { fail } from '../issue';\nexport function create(\n session: MutationSession,\n container: ResolvedContainer,\n entries: readonly { id: string; value: unknown }[],\n position?: DocumentAnchor\n): void {\n const { at, node, value } = container;\n if (node.kind !== 'table') return fail(at, 'invalid-collection', 'Expected a table.');\n const table = value as { ids: string[]; byId: Record<string, unknown> };\n if (!anchor.valid(table.ids, position))\n return fail(at, 'invalid-anchor', 'Unknown table anchor.');\n const ids = new Set<string>();\n for (const entry of entries) {\n if (Object.hasOwn(table.byId, entry.id) || ids.has(entry.id))\n return fail(at, 'duplicate-entity', 'Table key already exists.');\n ids.add(entry.id);\n }\n if (!entries.length) return;\n const index = anchor.index(table.ids, position);\n for (const entry of entries) session.writeMember(container, entry.id, entry.value, 'set');\n const length = table.ids.length;\n table.ids.length += entries.length;\n table.ids.copyWithin(index + entries.length, index, length);\n for (let i = 0; i < entries.length; i++) table.ids[index + i] = entries[i].id;\n}\nexport function remove(\n session: MutationSession,\n container: ResolvedContainer,\n ids: readonly string[]\n): void {\n const { at, node, value } = container;\n if (node.kind !== 'table') return fail(at, 'invalid-collection', 'Expected a table.');\n const table = value as { ids: string[]; byId: Record<string, unknown> };\n for (const id of ids)\n if (!Object.hasOwn(table.byId, id))\n return fail(at, 'missing-entity', 'Table key does not exist.');\n if (!ids.length) return;\n const removed = new Set(ids);\n for (const id of removed) session.writeMember(container, id, undefined, 'remove');\n table.ids = table.ids.filter(id => !removed.has(id));\n}\n\nexport function replace(\n session: MutationSession,\n container: ResolvedContainer,\n id: string,\n value: unknown\n): void {\n const { at, node, value: tableValue } = container;\n if (node.kind !== 'table') return fail(at, 'invalid-collection', 'Expected a table.');\n const table = tableValue as { byId: Record<string, unknown> };\n if (!Object.hasOwn(table.byId, id))\n return fail(at.concat(id), 'missing-entity', 'Table key does not exist.');\n session.writeMember(container, id, value, 'set');\n}\n","import type { DocumentAnchor } from '../../schema';\nimport type { MutationSession } from '../session';\nimport type { ResolvedContainer } from '../../address';\nimport * as anchor from '../anchor';\nimport { fail } from '../issue';\nexport function insert(\n session: MutationSession,\n container: ResolvedContainer,\n value: unknown,\n position?: DocumentAnchor\n): void {\n const { at, node, value: current } = container;\n if (node.kind !== 'list') return fail(at, 'invalid-list-key', 'Expected a list.');\n session.validate(node.value, value, at);\n const id = node.keyOf(value);\n if (typeof id !== 'string') return fail(at, 'invalid-list-key', 'List key must be a string.');\n const items = current as unknown[],\n keys = anchor.keys(items, node.keyOf);\n if (keys.index(id) >= 0) return fail(at, 'duplicate-list-item', 'List key already exists.');\n if (!anchor.valid(keys, position)) return fail(at, 'invalid-anchor', 'Unknown list anchor.');\n session.recorder.order(container);\n session.recorder.member(container, id, session.definition(container, id), -1);\n anchor.insert(items, anchor.index(keys, position), value);\n session.invalidate();\n}\nexport function replace(\n session: MutationSession,\n container: ResolvedContainer,\n id: string,\n value: unknown\n): void {\n const { at, node, value: items } = container;\n if (node.kind !== 'list') return fail(at, 'invalid-list-key', 'Expected a list.');\n const index = anchor.indexedKeys(items as unknown[], node.keyOf).index(id);\n if (index < 0) return fail(at, 'missing-list-item', 'List key does not exist.');\n session.writeMember(container, id, value, 'set', index);\n}\nexport function remove(session: MutationSession, container: ResolvedContainer, id: string): void {\n const { at, node, value } = container;\n if (node.kind !== 'list') return fail(at, 'missing-list-item', 'List key does not exist.');\n const index = anchor.keys(value as unknown[], node.keyOf).index(id);\n if (index < 0) return fail(at, 'missing-list-item', 'List key does not exist.');\n session.writeMember(container, id, undefined, 'remove', index);\n}\n","import type { DocumentAddress } from '../../schema';\nimport type { ResolvedTreeContainer } from '../../address';\nimport type { MutationSession } from '../session';\nimport { contains, type MutableTree, type TreePosition } from '../tree';\nimport { fail } from '../issue';\nconst node = (tree: MutableTree, id: string) =>\n Object.hasOwn(tree.nodes, id) ? tree.nodes[id] : undefined;\nconst positionIndex = (index: number | undefined, length: number, at: DocumentAddress): number => {\n if (index !== undefined && (!Number.isInteger(index) || index < 0))\n return fail(at, 'invalid-tree-index', 'Tree index must be nonnegative.');\n return Math.min(index ?? length, length);\n};\nexport const insert = (\n session: MutationSession,\n container: ResolvedTreeContainer,\n id: string,\n value: unknown,\n position: TreePosition | undefined\n): void => {\n const { at, node: schema, value: tree } = container;\n if (typeof id !== 'string') return fail(at, 'invalid-key', 'Tree keys must be strings.');\n if (contains(tree, id)) return fail(at, 'duplicate-tree-node', 'Tree node already exists.');\n const parentId = position?.parentId;\n const parent = parentId === undefined ? undefined : node(tree, parentId);\n if (\n (tree.rootId !== undefined && !parent) ||\n (tree.rootId === undefined && parentId !== undefined)\n )\n return fail(at, 'missing-tree-parent', 'A nonempty tree requires an existing parent.');\n const index = positionIndex(position?.index, parent?.children.length ?? 0, at);\n session.validate(schema.value, value, at.concat(id));\n session.recorder.tree(container, id);\n if (parentId !== undefined) session.recorder.tree(container, parentId);\n Object.defineProperty(tree.nodes, id, {\n value: { ...(parentId === undefined ? {} : { parentId }), children: [], value },\n writable: true,\n configurable: true,\n enumerable: true,\n });\n if (parent) parent.children.splice(index, 0, id);\n else tree.rootId = id;\n session.invalidate();\n};\nexport const replace = (\n session: MutationSession,\n container: ResolvedTreeContainer,\n id: string,\n value: unknown\n): void => {\n const { at, node: schema, value: tree } = container;\n const entry = node(tree, id);\n if (!entry) return fail(at, 'missing-tree-node', 'Tree node does not exist.');\n if (Object.is(entry.value, value) && Object.hasOwn(entry, 'value')) return;\n session.validate(schema.value, value, at.concat(id));\n session.recorder.tree(container, id);\n entry.value = value;\n};\nexport const remove = (\n session: MutationSession,\n container: ResolvedTreeContainer,\n id: string\n): void => {\n const { at, value: tree } = container;\n const entry = node(tree, id);\n if (!entry) return fail(at, 'missing-tree-node', 'Tree node does not exist.');\n const ids: string[] = [],\n stack = [id];\n while (stack.length) {\n const current = stack.pop()!;\n ids.push(current);\n for (const child of tree.nodes[current].children) stack.push(child);\n }\n for (const key of ids) session.recorder.tree(container, key);\n if (entry.parentId !== undefined) session.recorder.tree(container, entry.parentId);\n if (entry.parentId === undefined) delete tree.rootId;\n else {\n const children = tree.nodes[entry.parentId].children;\n children.splice(children.indexOf(id), 1);\n }\n for (const key of ids) delete tree.nodes[key];\n session.invalidate();\n};\nexport const move = (\n session: MutationSession,\n container: ResolvedTreeContainer,\n id: string,\n position: TreePosition | undefined\n): void => {\n const { at, value: tree } = container;\n const entry = node(tree, id),\n parentId = position?.parentId;\n if (!entry) return fail(at, 'missing-tree-node', 'Tree node does not exist.');\n if (entry.parentId === undefined || parentId === undefined || !contains(tree, parentId))\n return fail(\n at,\n 'missing-tree-parent',\n 'Moving requires a non-root node and an existing parent.'\n );\n for (\n let ancestor: string | undefined = parentId;\n ancestor !== undefined;\n ancestor = tree.nodes[ancestor].parentId\n )\n if (ancestor === id) return fail(at, 'tree-cycle', 'Cannot move a node under its descendant.');\n const old = tree.nodes[entry.parentId],\n next = tree.nodes[parentId];\n const index = positionIndex(position?.index, next.children.length - (old === next ? 1 : 0), at);\n const previous = old.children.indexOf(id);\n if (old === next && previous === index) return;\n session.recorder.tree(container, id);\n session.recorder.tree(container, entry.parentId);\n session.recorder.tree(container, parentId);\n old.children.splice(previous, 1);\n next.children.splice(index, 0, id);\n entry.parentId = parentId;\n session.invalidate();\n};\n","import type { DocumentAnchor } from '../../schema';\nimport type { MutationSession } from '../session';\nimport type { ResolvedContainer } from '../../address';\nimport * as anchor from '../anchor';\nimport { fail } from '../issue';\nexport function move(\n session: MutationSession,\n container: ResolvedContainer,\n id: string,\n position?: DocumentAnchor\n): void {\n const { at, node, value } = container;\n if (node.kind !== 'table' && node.kind !== 'list')\n return fail(at, 'invalid-collection', 'Expected an ordered container.');\n const items = node.kind === 'table' ? (value as { ids: string[] }).ids : (value as unknown[]);\n const keys = node.kind === 'table' ? (items as string[]) : anchor.keys(items, node.keyOf);\n const index =\n node.kind === 'table' ? (items as string[]).indexOf(id) : (keys as anchor.KeyOrder).index(id);\n if (index < 0) return fail(at, 'missing-entity', 'Ordered key does not exist.');\n if (!anchor.valid(keys, position)) return fail(at, 'invalid-anchor', 'Unknown order anchor.');\n const next = anchor.afterRemove(keys, index, position);\n if (next === index) return;\n session.recorder.order(container);\n anchor.move(items, index, next);\n session.invalidate();\n}\n","import type {\n DocumentAddress,\n DocumentAnchor,\n DocumentNode,\n DocumentTreeValue,\n FieldNode,\n Infer,\n ListNode,\n MapNode,\n ObjectNode,\n ObjectShape,\n ReadonlyValue,\n TableNode,\n TreeNode,\n ValueSchemaNode,\n VariantNode,\n} from '../schema';\nimport {\n nodeAt,\n resolveChild,\n resolveLocated,\n compiledShape,\n type FixedMember,\n type ResolvedContainer,\n type ResolvedTreeContainer,\n} from '../address';\nimport { copyValue } from '../schema-value';\nimport type { DependencyTracker } from './dependency';\nimport type { CanonicalState } from '../mutation/state';\nimport type { MutationSession } from '../mutation/session';\nimport * as mapOperations from '../mutation/operations/map';\nimport * as tableOperations from '../mutation/operations/table';\nimport * as listOperations from '../mutation/operations/list';\nimport * as treeOperations from '../mutation/operations/tree';\nimport * as orderOperations from '../mutation/operations/order';\nimport * as tree from '../mutation/tree';\nimport * as anchor from '../mutation/anchor';\nimport { profile } from '../profile';\n\ndeclare const scopeValue: unique symbol;\ntype Scoped<N extends DocumentNode, W extends boolean, V = Infer<N>> = {\n readonly [scopeValue]?: readonly [node: N, writable: W, value: V];\n};\ntype ShapeAccess<S extends ObjectShape, W extends boolean> = W extends true\n ? { -readonly [K in keyof S]: Access<S[K], W> }\n : { readonly [K in keyof S]: Access<S[K], W> };\ntype MapAccess<K extends string, N extends ValueSchemaNode, W extends boolean> = {\n get(id: K): Access<N, W> | undefined;\n has(id: K): boolean;\n ids(): readonly K[];\n} & (W extends true\n ? {\n put(id: K, value: Infer<N>): void;\n remove(id: K): void;\n replace(value: Readonly<Record<K, Infer<N>>>): void;\n }\n : {});\ntype TableAccess<K extends string, N extends ValueSchemaNode, W extends boolean> = {\n get(id: K): Access<N, W> | undefined;\n has(id: K): boolean;\n ids(): readonly K[];\n} & (W extends true\n ? {\n create(id: K, value: Infer<N>, anchor?: DocumentAnchor<K>): void;\n create(\n entries: readonly { readonly id: K; readonly value: Infer<N> }[],\n anchor?: DocumentAnchor<K>\n ): void;\n remove(ids: K | readonly K[]): void;\n move(id: K, anchor?: DocumentAnchor<K>): void;\n replace(value: {\n readonly ids: readonly K[];\n readonly byId: Readonly<Record<K, Infer<N>>>;\n }): void;\n replace(id: K, value: Infer<N>): void;\n }\n : {});\ntype ListAccess<T, W extends boolean> = {\n get(key: string): ReadonlyValue<T> | undefined;\n has(key: string): boolean;\n ids(): readonly string[];\n} & (W extends true\n ? {\n insert(value: ReadonlyValue<T>, anchor?: DocumentAnchor): void;\n remove(key: string): void;\n move(key: string, anchor?: DocumentAnchor): void;\n replace(value: readonly ReadonlyValue<T>[]): void;\n replace(key: string, value: ReadonlyValue<T>): void;\n }\n : {});\ntype TreeAccess<T, W extends boolean> = {\n rootId(): string | undefined;\n get(id: string): ReadonlyValue<T> | undefined;\n has(id: string): boolean;\n parent(id: string): string | undefined;\n children(id: string): readonly string[] | undefined;\n} & (W extends true\n ? {\n insert(id: string, value: ReadonlyValue<T>, position?: tree.TreePosition): void;\n move(id: string, position?: tree.TreePosition): void;\n remove(id: string): void;\n replace(value: DocumentTreeValue<T>): void;\n replace(id: string, value: ReadonlyValue<T>): void;\n }\n : {});\ntype NodeAccess<N extends DocumentNode, W extends boolean> =\n N extends FieldNode<infer T, boolean>\n ? ReadonlyValue<T>\n : N extends ObjectNode<infer S>\n ? ShapeAccess<S, W> & Scoped<N, W>\n : N extends VariantNode<infer Tag, infer V>\n ? {\n [K in keyof V & string]: ShapeAccess<V[K]['shape'], W> & {\n readonly [P in Tag]: K;\n } & Scoped<N, W, Extract<Infer<N>, Record<Tag, K>>>;\n }[keyof V & string]\n : N extends MapNode<infer V, infer K>\n ? MapAccess<K, V, W> & Scoped<N, W>\n : N extends TableNode<infer V, infer K>\n ? TableAccess<K, V, W> & Scoped<N, W>\n : N extends ListNode<infer T>\n ? ListAccess<T, W> & Scoped<N, W>\n : N extends TreeNode<infer T>\n ? TreeAccess<T, W> & Scoped<N, W>\n : never;\ntype Access<N extends DocumentNode, W extends boolean> = N extends { readonly optional: true }\n ? NodeAccess<N, W> | undefined\n : NodeAccess<N, W>;\nexport type Read<N extends DocumentNode> = Access<N, false>;\nexport type Draft<N extends DocumentNode> = Access<N, true>;\ntype Snapshot<T> = T extends {\n readonly [scopeValue]?: readonly [DocumentNode, boolean, infer V];\n}\n ? V\n : ReadonlyValue<T>;\ntype Target = {\n at?: DocumentAddress;\n parent?: Target;\n key: string;\n node: DocumentNode | undefined;\n value: unknown;\n generation: number;\n children:\n | { kind: 'fixed'; schema: DocumentNode; slots: (Target | undefined)[] }\n | { kind: 'dynamic'; keys: Map<string, Target> }\n | undefined;\n proxy: object | undefined;\n container?: ResolvedContainer | ResolvedTreeContainer;\n};\ntype Location = { readonly context: AccessContext; readonly target: Target };\nconst locations = new WeakMap<object, Location>();\nconst locationOf = (value: object): Location | undefined => locations.get(value);\nconst addressOf = (target: Target): DocumentAddress => {\n if (target.at) return target.at;\n profile.access('addresses');\n return (target.at = addressOf(target.parent!).concat(target.key));\n};\nexport type AccessContext = {\n readonly state: CanonicalState;\n /** Omitted for borrowed synchronous Draft and readers that must not escape. */\n readonly active?: () => boolean;\n readonly dependencies?: DependencyTracker;\n readonly session?: MutationSession;\n};\nconst assertActive = (context: AccessContext) => {\n if (context.active && !context.active()) throw new Error('Document access scope has expired.');\n};\nconst collect = (\n context: AccessContext,\n at: DocumentAddress,\n kind: 'value' | 'collection' = 'value',\n id?: string\n) => {\n context.dependencies?.record(\n kind === 'value' ? { kind, at } : { kind, at, ...(id === undefined ? {} : { id }) }\n );\n};\nexport const snapshot = <T>(value: T): Snapshot<T> => {\n const location = value && typeof value === 'object' ? locationOf(value) : undefined;\n if (!location) return value as Snapshot<T>;\n const { context } = location;\n const at = addressOf(location.target);\n profile.access('snapshots');\n collect(context, at);\n const resolved = resolve(context, location.target);\n if (!resolved.node) throw new Error('The selected schema address no longer exists.');\n return copyValue(resolved.node, resolved.value) as Snapshot<T>;\n};\n/** Replace a member with its plain Infer value through the owning draft session. */\ntype ReplaceParentAccess = {\n readonly [scopeValue]?: readonly [\n Extract<DocumentNode, { readonly kind: 'object' | 'variant' }>,\n true,\n unknown,\n ];\n};\nexport const replace = <T extends object & ReplaceParentAccess, K extends keyof Snapshot<T>>(\n container: T,\n key: K,\n value: NoInfer<Snapshot<T>[K]>\n): void => {\n const location = locationOf(container);\n if (!location) throw new TypeError('replace requires scoped document access.');\n if (typeof key !== 'string') throw new TypeError('Document keys must be strings.');\n Reflect.set(container, key, value);\n};\n/** Projection collection contexts use the same scoped access, with explicit collection tools. */\nexport type CollectionAccess<K extends string, N extends ValueSchemaNode> = TableAccess<\n K,\n N,\n false\n>;\nconst resolve = (context: AccessContext, target: Target): Target => {\n assertActive(context);\n const generation = context.session?.generation ?? 0;\n if (target.generation !== generation) {\n profile.access('resolutions');\n if (!target.parent && !target.at!.length) {\n target.node = context.state.schema;\n target.value = context.state.document;\n } else {\n const parent = target.parent && resolve(context, target.parent);\n const location = parent\n ? resolveChild(parent.node, parent.value, target.key)\n : resolveLocated(context.state.schema, context.state.document, target.at!);\n target.node =\n location?.node ?? nodeAt(context.state.schema, addressOf(target), context.state.document);\n target.value =\n location && Object.hasOwn(location.parent, location.key)\n ? (location.parent as Record<string | number, unknown>)[location.key]\n : undefined;\n }\n target.generation = generation;\n }\n return target;\n};\n\nexport const createAccess = (context: AccessContext, initial: DocumentAddress = []): unknown => {\n profile.access('scopes');\n const mutable = (): MutationSession => {\n assertActive(context);\n if (!context.session) throw new TypeError('Cannot modify read-only document access.');\n return context.session;\n };\n const writableContainer = (target: Target, session: MutationSession): ResolvedContainer => {\n if (target.container?.generation === session.generation && 'layout' in target.container)\n return target.container;\n return (target.container = session.bind(addressOf(target), target.node, target.value));\n };\n const childAt = (target: Target, key: string): DocumentAddress => {\n profile.access('addresses');\n return addressOf(target).concat(key);\n };\n const access = (target: Target): unknown => {\n if (target.proxy) return target.proxy;\n const proxy = new Proxy(target, handler);\n profile.access('proxies');\n locations.set(proxy, { context, target });\n target.proxy = proxy;\n return proxy;\n };\n const createTarget = (\n at: DocumentAddress | undefined,\n parent: Target | undefined,\n key: string\n ): Target => ({\n at,\n parent,\n key,\n node: undefined,\n value: undefined,\n generation: -1,\n children: undefined,\n proxy: undefined,\n });\n const childAccess = (\n target: Target,\n member: string | FixedMember,\n node: DocumentNode,\n value: unknown\n ) => {\n const key = typeof member === 'string' ? member : member.key;\n if (node.kind === 'field' || value === undefined) {\n if (context.dependencies) collect(context, childAt(target, key));\n return value;\n }\n let children = target.children;\n let child: Target;\n if (typeof member !== 'string') {\n if (children?.kind !== 'fixed' || children.schema !== target.node)\n children = {\n kind: 'fixed',\n schema: target.node!,\n slots: new Array(compiledShape(target.node!, target.value)!.members.size),\n };\n child = children.slots[member.slot] ??= createTarget(undefined, target, key);\n } else {\n if (children?.kind !== 'dynamic') children = { kind: 'dynamic', keys: new Map() };\n const retained = children.keys.get(key);\n child = retained ?? createTarget(undefined, target, key);\n if (!retained) children.keys.set(key, child);\n }\n target.children = children;\n if (child.generation === target.generation) return child.proxy;\n child.node = node;\n child.value = value;\n child.generation = target.generation;\n return access(child);\n };\n const collectionValue = (target: Target, node: DocumentNode) => {\n const current = resolve(context, target);\n if (current.node !== node || current.value === undefined)\n throw new TypeError('The collection method belongs to a replaced schema branch.');\n return current.value;\n };\n const writableCollection = (target: Target, node: DocumentNode): ResolvedContainer => {\n const session = mutable();\n collectionValue(target, node);\n return writableContainer(target, session);\n };\n const writableTree = (target: Target, node: DocumentNode): ResolvedTreeContainer => {\n const session = mutable();\n collectionValue(target, node);\n if (target.container?.generation === session.generation && !('layout' in target.container))\n return target.container;\n return (target.container = session.bindTree(addressOf(target), target.node, target.value));\n };\n const replaceCollection = (target: Target, node: DocumentNode, value: unknown) => {\n const session = mutable();\n collectionValue(target, node);\n session.replace(addressOf(target), value);\n };\n const mapMethod = (\n target: Target,\n property: string,\n node: Extract<DocumentNode, { kind: 'map' }>\n ): unknown => {\n if (property === 'ids')\n return () => {\n const current = collectionValue(target, node) as Record<string, unknown>;\n if (context.dependencies) collect(context, addressOf(target), 'collection');\n return Object.keys(current);\n };\n if (property === 'has')\n return (id: string) => {\n const current = collectionValue(target, node) as Record<string, unknown>;\n if (context.dependencies) collect(context, addressOf(target), 'collection', id);\n return Object.hasOwn(current, id);\n };\n if (property === 'get')\n return (id: string) => {\n const current = collectionValue(target, node) as Record<string, unknown>;\n if (context.dependencies) collect(context, addressOf(target), 'collection', id);\n if (!Object.hasOwn(current, id)) return undefined;\n if (node.value.kind === 'field') {\n if (context.dependencies) collect(context, childAt(target, id));\n return current[id];\n }\n return childAccess(target, id, node.value, current[id]);\n };\n if (property === 'put')\n return (id: string, value: unknown) => {\n const writable = writableCollection(target, node);\n mapOperations.put(context.session!, writable, id, value);\n };\n if (property === 'remove')\n return (id: string) => {\n const writable = writableCollection(target, node);\n mapOperations.remove(context.session!, writable, id);\n };\n if (property === 'replace') return (value: unknown) => replaceCollection(target, node, value);\n return undefined;\n };\n const orderedMethod = (\n target: Target,\n property: string,\n node: Extract<DocumentNode, { kind: 'table' | 'list' }>\n ): unknown => {\n const at = addressOf(target);\n if (property === 'ids')\n return () => {\n const current = collectionValue(target, node);\n collect(context, at, 'collection');\n return node.kind === 'table'\n ? [...(current as { ids: string[] }).ids]\n : (current as unknown[]).map(node.keyOf);\n };\n if (property === 'has')\n return (id: string) => {\n const current = collectionValue(target, node);\n collect(context, at, 'collection', id);\n return node.kind === 'table'\n ? Object.hasOwn((current as { byId: object }).byId, id)\n : anchor.indexedKeys(current as unknown[], node.keyOf).index(id) >= 0;\n };\n if (property === 'get')\n return (id: string) => {\n const current = collectionValue(target, node);\n collect(context, at, 'collection', id);\n const location = resolveChild(node, current, id);\n if (!location || !Object.hasOwn(location.parent, location.key)) return undefined;\n return childAccess(\n target,\n id,\n location.node,\n (location.parent as Record<string | number, unknown>)[location.key]\n );\n };\n if (property === 'move')\n return (id: string, position?: DocumentAnchor) => {\n const writable = writableCollection(target, node);\n orderOperations.move(context.session!, writable, id, position);\n };\n return undefined;\n };\n const tableMethod = (\n target: Target,\n property: string,\n node: Extract<DocumentNode, { kind: 'table' }>\n ): unknown => {\n if (property === 'create')\n return (\n input: string | readonly { id: string; value: unknown }[],\n valueOrPosition?: unknown,\n position?: DocumentAnchor\n ) => {\n const writable = writableCollection(target, node);\n tableOperations.create(\n context.session!,\n writable,\n Array.isArray(input) ? input : [{ id: input as string, value: valueOrPosition }],\n Array.isArray(input) ? (valueOrPosition as DocumentAnchor | undefined) : position\n );\n };\n if (property === 'remove')\n return (ids: string | readonly string[]) => {\n const writable = writableCollection(target, node);\n tableOperations.remove(context.session!, writable, typeof ids === 'string' ? [ids] : ids);\n };\n if (property === 'replace')\n return (...args: [unknown, unknown?]) => {\n const [valueOrId, value] = args;\n if (args.length === 1) return replaceCollection(target, node, valueOrId);\n const writable = writableCollection(target, node);\n tableOperations.replace(context.session!, writable, valueOrId as string, value);\n };\n return orderedMethod(target, property, node);\n };\n const listMethod = (\n target: Target,\n property: string,\n node: Extract<DocumentNode, { kind: 'list' }>\n ): unknown => {\n if (property === 'insert')\n return (value: unknown, position?: DocumentAnchor) => {\n const writable = writableCollection(target, node);\n listOperations.insert(context.session!, writable, value, position);\n };\n if (property === 'remove')\n return (id: string) => {\n const writable = writableCollection(target, node);\n listOperations.remove(context.session!, writable, id);\n };\n if (property === 'replace')\n return (...args: [unknown, unknown?]) => {\n const [valueOrId, value] = args;\n if (args.length === 1) return replaceCollection(target, node, valueOrId);\n const writable = writableCollection(target, node);\n listOperations.replace(context.session!, writable, valueOrId as string, value);\n };\n return orderedMethod(target, property, node);\n };\n const treeMethod = (\n target: Target,\n property: string,\n node: Extract<DocumentNode, { kind: 'tree' }>\n ): unknown => {\n const at = addressOf(target);\n if (property === 'insert')\n return (id: string, value: unknown, position?: tree.TreePosition) => {\n const writable = writableTree(target, node);\n treeOperations.insert(context.session!, writable, id, value, position);\n };\n if (property === 'remove')\n return (id: string) => {\n const writable = writableTree(target, node);\n treeOperations.remove(context.session!, writable, id);\n };\n if (property === 'move')\n return (id: string, position?: tree.TreePosition) => {\n const writable = writableTree(target, node);\n treeOperations.move(context.session!, writable, id, position);\n };\n if (property === 'replace')\n return (...args: [unknown, unknown?]) => {\n const [valueOrId, value] = args;\n if (args.length === 1) return replaceCollection(target, node, valueOrId);\n const writable = writableTree(target, node);\n treeOperations.replace(context.session!, writable, valueOrId as string, value);\n };\n const current = () => {\n collect(context, at);\n return collectionValue(target, node) as tree.MutableTree;\n };\n if (property === 'rootId') return () => current().rootId;\n if (property === 'get')\n return (id: string) => {\n const value = current();\n return tree.contains(value, id) ? value.nodes[id].value : undefined;\n };\n if (property === 'has') return (id: string) => tree.contains(current(), id);\n if (property === 'parent') return (id: string) => tree.parent(current(), id);\n if (property === 'children')\n return (id: string) => {\n const children = tree.children(current(), id);\n return children ? [...children] : undefined;\n };\n return undefined;\n };\n const handler: ProxyHandler<Target> = {\n get: (target, property) => {\n const { node, value } = resolve(context, target);\n if (!node || value === undefined) return undefined;\n if (typeof property !== 'string') return undefined;\n if (node.kind === 'map') return mapMethod(target, property, node);\n if (node.kind === 'table') return tableMethod(target, property, node);\n if (node.kind === 'list') return listMethod(target, property, node);\n if (node.kind === 'tree') return treeMethod(target, property, node);\n if (node.kind === 'variant' && property === node.tag) {\n collect(context, childAt(target, property));\n return (value as Record<string, unknown>)[property];\n }\n const member = compiledShape(node, value)?.members.get(property);\n if (!member) return undefined;\n if (member.field) {\n if (context.dependencies) collect(context, childAt(target, property));\n return (value as Record<string, unknown>)[property];\n }\n return childAccess(\n target,\n node.kind === 'object' ? member : property,\n member.node,\n (value as Record<string, unknown>)[property]\n );\n },\n set: (target, property, value) => {\n const session = mutable(),\n { node } = resolve(context, target);\n if (\n typeof property !== 'string' ||\n !node ||\n (node.kind !== 'object' && node.kind !== 'variant')\n )\n throw new TypeError('Invalid structural assignment.');\n if (node.kind === 'variant' && node.tag === property)\n throw new TypeError('Variant discriminants are read-only.');\n session.assignMember(writableContainer(target, session), property, value);\n return true;\n },\n deleteProperty: (target, property) => {\n const session = mutable(),\n { node } = resolve(context, target);\n if (\n typeof property !== 'string' ||\n node?.kind === 'map' ||\n (node?.kind === 'variant' && node.tag === property)\n )\n throw new TypeError('Invalid structural deletion.');\n session.removeMember(writableContainer(target, session), property);\n return true;\n },\n has: (target, property) => {\n const { node, value } = resolve(context, target);\n if (typeof property !== 'string') return false;\n if (node?.kind === 'map') return false;\n collect(context, addressOf(target));\n return value !== undefined && Object.hasOwn(value as object, property);\n },\n ownKeys: target => {\n const { node, value } = resolve(context, target);\n if (node?.kind === 'map') return [];\n if (context.dependencies) collect(context, addressOf(target));\n return value && typeof value === 'object' ? Object.keys(value) : [];\n },\n getOwnPropertyDescriptor: (target, property) => {\n const { node, value } = resolve(context, target);\n if (node?.kind === 'map') return undefined;\n return value && Object.hasOwn(value as object, property)\n ? { enumerable: true, configurable: true }\n : undefined;\n },\n defineProperty: () => {\n assertActive(context);\n throw new TypeError('Use schema assignments.');\n },\n setPrototypeOf: () => {\n assertActive(context);\n throw new TypeError('Document prototypes are immutable.');\n },\n preventExtensions: () => {\n assertActive(context);\n throw new TypeError('Document access cannot be frozen.');\n },\n };\n const root = resolve(context, createTarget(initial, undefined, ''));\n if (!root.node || root.node.kind === 'field' || root.value === undefined) {\n if (context.dependencies) collect(context, initial);\n return root.value;\n }\n return access(root);\n};\nexport const collectionAccess = (\n context: AccessContext,\n at: DocumentAddress\n): CollectionAccess<string, ValueSchemaNode> => {\n const value = createAccess(context, at);\n if (value === undefined)\n return {\n get: () => {\n assertActive(context);\n return undefined;\n },\n has: () => {\n assertActive(context);\n return false;\n },\n ids: () => {\n assertActive(context);\n return [];\n },\n };\n return value as CollectionAccess<string, ValueSchemaNode>;\n};\n","import type { DocumentReadable, Synchronous } from '../runtime/contract';\nimport type {\n CollectionId,\n CollectionPath,\n CollectionNode as SchemaCollectionNode,\n Infer,\n ObjectNode,\n ReadonlyValue,\n SchemaPath,\n PathValueOf,\n} from '../schema';\nimport type { Readable } from './readable';\nimport type {\n BatchContext,\n Cause,\n CollectionContext,\n CollectionDraft,\n CollectionRead,\n CollectionEntryTransition,\n DocumentContext,\n ExternalCollectionSource,\n ExternalValueSource,\n GraphSources,\n InputHandles,\n NodeUpdate,\n ValueContext,\n} from './contract';\n\ndeclare const projectionDefinition: unique symbol;\ndeclare const writableInput: unique symbol;\n\n/** A lazy, reusable projection definition. Its value is materialized per runtime. */\nexport type Projection<T> = {\n readonly [projectionDefinition]: T;\n};\n\n/** A runtime-local writable projection definition. */\nexport type Input<T> = Projection<T> & { readonly [writableInput]: true };\n\nexport type ProjectionValues<D extends readonly Projection<unknown>[]> = {\n readonly [K in keyof D]: D[K] extends Projection<infer T> ? T : never;\n};\n\nexport type PublicCollection<K extends string, V> = ReadonlyMap<K, V>;\ntype ObservedCollection<P extends CollectionPath> = PublicCollection<\n CollectionId<P>,\n ReadonlyValue<Infer<SchemaCollectionNode<P>>>\n>;\n\ntype Equality = (a: unknown, b: unknown) => boolean;\ntype PathSelector<S extends ObjectNode> = (path: SchemaPath<S['shape']>) => unknown;\n\ntype Definition =\n | { readonly kind: 'input'; readonly initial: unknown; readonly isEqual?: Equality }\n | { readonly kind: 'readable'; readonly readable: Readable<unknown>; readonly isEqual?: Equality }\n | { readonly kind: 'source-value'; readonly source: ExternalValueSource<unknown, unknown> }\n | {\n readonly kind: 'source-collection';\n readonly source: ExternalCollectionSource<string, unknown, unknown>;\n }\n | {\n readonly kind: 'document';\n readonly document: DocumentReadable<ObjectNode>;\n readonly selector?: PathSelector<ObjectNode>;\n }\n | {\n readonly kind: 'derive';\n readonly dependencies: readonly Projection<unknown>[];\n readonly compute: (...values: readonly unknown[]) => unknown;\n readonly isEqual?: Equality;\n }\n | {\n readonly kind: 'incremental-value';\n readonly dependencies: GraphSources;\n readonly build: (...args: never[]) => unknown;\n readonly isEqual?: Equality;\n readonly name?: string;\n }\n | {\n readonly kind: 'incremental-collection';\n readonly dependencies: GraphSources;\n readonly build: (...args: never[]) => unknown;\n readonly isEqual?: Equality;\n readonly name?: string;\n };\n\ntype DefinitionProjection = Projection<unknown>;\nconst definitions = new WeakMap<object, Definition>();\n\nconst define = <T>(definition: Definition): Projection<T> => {\n const handle = Object.freeze({}) as Projection<T>;\n definitions.set(handle, definition);\n return handle;\n};\n\nexport const definitionOf = (projection: DefinitionProjection): Definition => {\n const definition = definitions.get(projection);\n if (!definition) throw new TypeError('Unknown projection definition.');\n return definition;\n};\n\nexport const input = <T>(\n initial: T,\n equality: (previous: T, next: T) => boolean = Object.is\n): Input<T> => define<T>({ kind: 'input', initial, isEqual: equality as Equality }) as Input<T>;\n\n/**\n * Establishes a reactive boundary from a document. The selector is compiled\n * when the definition is materialized, so declarations stay lazy and reusable.\n */\nexport function observe<S extends ObjectNode>(document: DocumentReadable<S>): Projection<Infer<S>>;\nexport function observe<T>(readable: Readable<T>): Projection<T>;\nexport function observe<S extends ObjectNode, P extends CollectionPath>(\n document: DocumentReadable<S>,\n selector: (path: SchemaPath<S['shape']>) => P\n): Projection<ObservedCollection<P>>;\nexport function observe<S extends ObjectNode, P>(\n document: DocumentReadable<S>,\n selector: (path: SchemaPath<S['shape']>) => P\n): Projection<PathValueOf<P>>;\nexport function observe<S extends ObjectNode>(\n document: DocumentReadable<S> | Readable<unknown>,\n selector?: PathSelector<S>\n): Projection<unknown> {\n if ('current' in document && typeof document.current === 'function')\n return defineReadable(document as Readable<unknown>);\n return define({\n kind: 'document',\n document: document as DocumentReadable<ObjectNode>,\n selector: selector as PathSelector<ObjectNode> | undefined,\n });\n}\n\nexport function derive<const D extends readonly Projection<unknown>[], T>(\n dependencies: D,\n compute: (...values: ProjectionValues<D>) => Synchronous<T>,\n equality: (previous: T, next: T) => boolean = Object.is\n): Projection<T> {\n if (!Array.isArray(dependencies) || dependencies.some(value => !definitions.has(value)))\n throw new TypeError('derive dependencies must be projections.');\n const frozen = Object.freeze([...dependencies]) as readonly Projection<unknown>[];\n return define<T>({\n kind: 'derive',\n dependencies: frozen,\n compute: compute as (...values: readonly unknown[]) => unknown,\n isEqual: equality as Equality,\n });\n}\n\n/** Internal adapters used by the integration boundary, not exported publicly. */\nexport const defineReadable = <T>(\n readable: Readable<T>,\n equality: (a: T, b: T) => boolean = Object.is\n): Projection<T> => define<T>({ kind: 'readable', readable, isEqual: equality as Equality });\n\nexport const defineExternalValue = <T, D>(source: ExternalValueSource<T, D>): Projection<T> =>\n define<T>({ kind: 'source-value', source: source as never });\n\nexport const defineExternalCollection = <K extends string, V, D>(\n source: ExternalCollectionSource<K, V, D>\n): Projection<PublicCollection<K, V>> =>\n define<PublicCollection<K, V>>({ kind: 'source-collection', source: source as never });\n\nexport type IncrementalValueDefinition = Extract<Definition, { kind: 'incremental-value' }>;\nexport type IncrementalCollectionDefinition = Extract<\n Definition,\n { kind: 'incremental-collection' }\n>;\n\nexport const defineIncrementalValue = <T>(definition: {\n readonly dependencies: GraphSources;\n readonly build: (...args: never[]) => unknown;\n readonly isEqual?: (a: T, b: T) => boolean;\n readonly name?: string;\n}): Projection<T> =>\n define<T>({\n kind: 'incremental-value',\n dependencies: definition.dependencies,\n build: definition.build,\n isEqual: definition.isEqual as Equality | undefined,\n name: definition.name,\n });\n\nexport const defineIncrementalCollection = <K extends string, V>(definition: {\n readonly dependencies: GraphSources;\n readonly build: (...args: never[]) => unknown;\n readonly isEqual?: (a: V, b: V) => boolean;\n readonly name?: string;\n}): Projection<PublicCollection<K, V>> =>\n define<PublicCollection<K, V>>({\n kind: 'incremental-collection',\n dependencies: definition.dependencies,\n build: definition.build,\n isEqual: definition.isEqual as Equality | undefined,\n name: definition.name,\n });\n\n// Internal event names remain private implementation detail and are not root exports.\nexport type InternalDocumentEvent<S extends ObjectNode> = DocumentContext<S>;\nexport type InternalValueEvent<T, D = unknown> = ValueContext<T, D>;\nexport type InternalCollectionEvent<K extends string, V, D = unknown> = CollectionContext<K, V, D>;\nexport type InternalCollectionTransition<K extends string, V> = CollectionEntryTransition<K, V>;\nexport type InternalCollectionDraft<K extends string, V> = CollectionDraft<K, V>;\nexport type InternalBatchContext = BatchContext;\nexport type InternalCause = Cause;\nexport type InternalInputHandles<S extends GraphSources> = InputHandles<S>;\nexport type InternalNodeUpdate<T> = NodeUpdate<T>;\nexport type InternalCollectionRead<K extends string, V> = CollectionRead<K, V>;\n"],"mappings":";;AAgCA,IAAa,aAAb,cAAgC,UAAU;CACxC;CACA,YAAY,OAAmB;AAC7B,QAAM,GAAG,MAAM,QAAQ,MAAM,KAAK,UAAU,MAAM,QAAQ,GAAG;AAC7D,OAAK,OAAO;AACZ,OAAK,SAAS,OAAO,OAAO,CAC1B,OAAO,OAAO;GAAE,GAAG;GAAO,SAAS,OAAO,OAAO,CAAC,GAAG,MAAM,QAAQ,CAAC;GAAE,CAAC,CACxE,CAAC;;;AAIN,MAAM,SACJ,SACA,SACA,OAA2B,qBACX;CAAE;CAAS;CAAS;CAAM;AAE5C,MAAa,eACX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ACrF,OAAM,IAAI,UAAU,2CAA2C;AAEjE,QAAO,OAAU;EACf,MAAM;EACN,cAHa,OAAO,OAAO,CAAC,GAAG,aAAa,CAGxB;EACX;EACT,SAAS;EACV,CAAC;;;AAIJ,MAAa,kBACX,UACA,WAAoC,OAAO,OACzB,OAAU;CAAE,MAAM;CAAY;CAAU,SAAS;CAAsB,CAAC;AAE5F,MAAa,uBAA6B,WACxC,OAAU;CAAE,MAAM;CAAwB;CAAiB,CAAC;AAE9D,MAAa,4BACX,WAEA,OAA+B;CAAE,MAAM;CAA6B;CAAiB,CAAC;AAQxF,MAAa,0BAA6B,eAMxC,OAAU;CACR,MAAM;CACN,cAAc,WAAW;CACzB,OAAO,WAAW;CAClB,SAAS,WAAW;CACpB,MAAM,WAAW;CAClB,CAAC;AAEJ,MAAa,+BAAoD,eAM/D,OAA+B;CAC7B,MAAM;CACN,cAAc,WAAW;CACzB,OAAO,WAAW;CAClB,SAAS,WAAW;CACpB,MAAM,WAAW;CAClB,CAAC"}
1
+ {"version":3,"file":"definition-BDW6i7fp.cjs","names":["isRecord","isPlainObject","compiledShape","validTree","fail","remove","fail","index","remove","replace","insert","fail","keys","replace","remove","fail","contains","replace","move","fail","keys","resolveChild","resolveLocated","nodeAt","compiledShape","children"],"sources":["../core/src/schema-value.ts","../core/src/mutation/operations/map.ts","../core/src/mutation/operations/table.ts","../core/src/mutation/operations/list.ts","../core/src/mutation/operations/tree.ts","../core/src/mutation/operations/order.ts","../core/src/access/scope.ts","../core/src/projection/definition.ts"],"sourcesContent":["import type { DocumentAddress, DocumentNode, Infer } from './schema';\nimport { compiledShape } from './address';\nimport { isPlainObject, isRecord } from './value/ownership';\nimport { validate as validTree } from './mutation/tree';\nimport * as anchor from './mutation/anchor';\nimport { profile } from './profile';\n\n/** Pure synchronous validation. Successful output is ignored; input is never transformed. */\nexport type Validator<T> =\n | ((value: unknown) => T)\n | {\n readonly '~standard': {\n readonly version: 1;\n readonly vendor: string;\n readonly types?: { readonly input: unknown; readonly output: T };\n validate(value: unknown):\n | { readonly value: T; readonly issues?: undefined }\n | {\n readonly issues: readonly {\n readonly message: string;\n readonly path?: readonly (PropertyKey | { readonly key: PropertyKey })[];\n }[];\n }\n | PromiseLike<unknown>;\n };\n };\n\nexport type ParseIssue = {\n readonly address: DocumentAddress;\n readonly code: 'invalid-value' | 'invalid-key' | 'missing-validator' | 'invalid-tree';\n readonly message: string;\n};\nexport class ParseError extends TypeError {\n readonly issues: readonly ParseIssue[];\n constructor(issue: ParseIssue) {\n super(`${issue.message} at ${JSON.stringify(issue.address)}`);\n this.name = 'ParseError';\n this.issues = Object.freeze([\n Object.freeze({ ...issue, address: Object.freeze([...issue.address]) }),\n ]);\n }\n}\n\nconst issue = (\n address: DocumentAddress,\n message: string,\n code: ParseIssue['code'] = 'invalid-value'\n): ParseIssue => ({ address, message, code });\n\nexport const checkScalar = (\n validator: Validator<unknown> | undefined,\n value: unknown,\n address: DocumentAddress,\n strict: boolean\n): ParseIssue | undefined => {\n if (!validator)\n return strict\n ? issue(address, 'A validator is required to parse an opaque value.', 'missing-validator')\n : undefined;\n try {\n const result =\n typeof validator === 'function' ? validator(value) : validator['~standard'].validate(value);\n if (\n result &&\n (typeof result === 'object' || typeof result === 'function') &&\n 'then' in result &&\n typeof result.then === 'function'\n )\n return issue(address, 'Validators must be synchronous.');\n if (typeof validator !== 'function') {\n if (!isRecord(result)) return issue(address, 'Malformed validator result.');\n if (Array.isArray(result.issues)) {\n const first = result.issues[0];\n return issue(\n [\n ...address,\n ...(first?.path ?? []).map((part: PropertyKey | { key: PropertyKey }) =>\n String(typeof part === 'object' ? part.key : part)\n ),\n ],\n first?.message ?? 'Value validation failed.'\n );\n }\n if (!Object.hasOwn(result, 'value')) return issue(address, 'Malformed validator result.');\n }\n return undefined;\n } catch (error) {\n return issue(address, error instanceof Error ? error.message : 'Value validation failed.');\n }\n};\n\nexport const checkKey = (\n validator: Validator<string> | undefined,\n value: unknown,\n address: DocumentAddress\n): ParseIssue | undefined => {\n if (typeof value !== 'string')\n return issue(address, 'Collection keys must be strings.', 'invalid-key');\n const failure = checkScalar(validator, value, address, false);\n return failure ? { ...failure, code: 'invalid-key' } : undefined;\n};\n\nexport const checkValue = (\n node: DocumentNode,\n value: unknown,\n address: DocumentAddress = [],\n strict = false\n): ParseIssue | undefined => {\n if (node.optional && value === undefined) return undefined;\n if (node.kind === 'field') return checkScalar(node.validator, value, address, strict);\n if (node.kind === 'object' || node.kind === 'variant') {\n if (!isPlainObject(value)) return issue(address, 'Expected an object.');\n if (node.kind === 'variant') {\n const tag = value[node.tag];\n if (\n !Object.hasOwn(value, node.tag) ||\n typeof tag !== 'string' ||\n !Object.hasOwn(node.variants, tag)\n )\n return issue([...address, node.tag], 'Unknown variant tag.');\n }\n const { members } = compiledShape(node, value)!;\n for (const key of Reflect.ownKeys(value)) {\n if (node.kind === 'variant' && key === node.tag) continue;\n if (typeof key !== 'string' || !members.has(key))\n return issue([...address, String(key)], 'Property is not declared in the object schema.');\n }\n for (const [key, member] of members) {\n const child = member.node;\n if (!Object.prototype.hasOwnProperty.call(value, key) && !child.optional)\n return issue([...address, key], 'Required property is missing.');\n const failure = checkValue(child, value[key], [...address, key], strict);\n if (failure) return failure;\n }\n return undefined;\n }\n if (node.kind === 'table' || node.kind === 'map') {\n if (!isPlainObject(value)) return issue(address, 'Expected a collection object.');\n const entries = node.kind === 'table' ? value.byId : value;\n if (!isPlainObject(entries)) return issue(address, 'Expected a byId object.');\n if (node.kind === 'table') {\n if (!Array.isArray(value.ids) || value.ids.length !== Object.keys(entries).length)\n return issue(address, 'Table ids and entries must agree.');\n const seen = new Set<string>();\n for (const id of value.ids) {\n const failure = checkKey(node.key, id, address);\n if (failure) return failure;\n if (seen.has(id) || !Object.prototype.hasOwnProperty.call(entries, id))\n return issue(address, 'Table ids must be unique and reference existing entries.');\n seen.add(id);\n }\n }\n for (const id of Object.keys(entries)) {\n const failure =\n checkKey(node.key, id, [...address, id]) ??\n checkValue(node.value, entries[id], [...address, id], strict);\n if (failure) return failure;\n }\n return undefined;\n }\n if (node.kind === 'list') {\n if (!Array.isArray(value)) return issue(address, 'Expected a list.');\n const seen = new Set<string>();\n const order = anchor.keys(value, node.keyOf);\n for (let i = 0; i < value.length; i++) {\n const failure = checkValue(node.value, value[i], [...address, String(i)], strict);\n if (failure) return failure;\n let key: unknown;\n try {\n key = order.at(i);\n } catch {\n return issue(address, 'List keyOf failed.');\n }\n if (typeof key !== 'string' || seen.has(key))\n return issue(address, 'List keys must be unique strings.', 'invalid-key');\n seen.add(key);\n }\n return undefined;\n }\n if (!validTree(value)) return issue(address, 'Invalid tree structure.', 'invalid-tree');\n if (isRecord(value) && isRecord(value.nodes)) {\n for (const id of Object.keys(value.nodes)) {\n const entry = value.nodes[id];\n if (isRecord(entry) && Object.prototype.hasOwnProperty.call(entry, 'value')) {\n const failure = checkValue(node.value, entry.value, [...address, id], strict);\n if (failure) return failure;\n }\n }\n }\n return undefined;\n};\n\n/** Copy editable structure; atomic payloads retain their immutable ownership contract. */\nexport const copyValue = (node: DocumentNode, value: unknown): unknown => {\n if (value === undefined || node.kind === 'field') return value;\n profile.copy.structure();\n if ((node.kind === 'object' || node.kind === 'variant') && isRecord(value)) {\n const result = Object.create(Object.getPrototypeOf(value));\n const { members } = compiledShape(node, value)!;\n for (const key of Object.getOwnPropertyNames(value)) {\n Object.defineProperty(result, key, {\n value:\n node.kind === 'variant' && key === node.tag\n ? value[key]\n : copyValue(members.get(key)!.node, value[key]),\n writable: true,\n enumerable: Object.getOwnPropertyDescriptor(value, key)?.enumerable,\n configurable: true,\n });\n }\n return result;\n }\n if ((node.kind === 'table' || node.kind === 'map') && isRecord(value)) {\n const entries = (node.kind === 'table' ? value.byId : value) as Record<string, unknown>;\n const result = Object.fromEntries(\n Object.keys(entries).map(id => [id, copyValue(node.value, entries[id])])\n );\n return node.kind === 'table' ? { ids: [...(value.ids as string[])], byId: result } : result;\n }\n if (node.kind === 'list') return [...(value as unknown[])];\n if (node.kind === 'tree' && isRecord(value)) {\n const entries = value.nodes as Record<string, { children: readonly string[] }>;\n return {\n ...value,\n nodes: Object.fromEntries(\n Object.entries(entries).map(([id, n]) => [id, { ...n, children: [...n.children] }])\n ),\n };\n }\n return value;\n};\n\nexport const equalValue = (node: DocumentNode, left: unknown, right: unknown): boolean => {\n if (Object.is(left, right)) return true;\n if (node.kind === 'field' || left === undefined || right === undefined) return false;\n if ((node.kind === 'object' || node.kind === 'variant') && isRecord(left) && isRecord(right)) {\n if (node.kind === 'variant' && left[node.tag] !== right[node.tag]) return false;\n for (const [key, member] of compiledShape(node, left)!.members) {\n if (Object.hasOwn(left, key) !== Object.hasOwn(right, key)) return false;\n if (!equalValue(member.node, left[key], right[key])) return false;\n }\n return true;\n }\n if (node.kind === 'list' && Array.isArray(left) && Array.isArray(right))\n return (\n left.length === right.length && left.every((v, i) => equalValue(node.value, v, right[i]))\n );\n if (node.kind === 'table' && isRecord(left) && isRecord(right))\n return (\n anchor.equal(left.ids as string[], right.ids as string[]) &&\n equalValue({ kind: 'map', value: node.value }, left.byId, right.byId)\n );\n if (node.kind === 'tree' && isRecord(left) && isRecord(right)) {\n if (left.rootId !== right.rootId) return false;\n const a = left.nodes as Record<\n string,\n { parentId?: string; children: string[]; value?: unknown }\n >,\n b = right.nodes as typeof a;\n return (\n Object.keys(a).length === Object.keys(b).length &&\n Object.keys(a).every(\n id =>\n Object.hasOwn(b, id) &&\n a[id].parentId === b[id].parentId &&\n anchor.equal(a[id].children, b[id].children) &&\n Object.hasOwn(a[id], 'value') === Object.hasOwn(b[id], 'value') &&\n equalValue(node.value, a[id].value, b[id].value)\n )\n );\n }\n if (node.kind === 'map' && isRecord(left) && isRecord(right)) {\n const keys = Object.keys(left);\n return (\n keys.length === Object.keys(right).length &&\n keys.every(key => Object.hasOwn(right, key) && equalValue(node.value, left[key], right[key]))\n );\n }\n return false;\n};\n\nexport const parse = <N extends DocumentNode>(node: N, input: unknown): Infer<N> => {\n const valueNode: DocumentNode = node;\n const failure = checkValue(valueNode, input, [], true);\n if (failure) throw new ParseError(failure);\n return copyValue(valueNode, input) as Infer<N>;\n};\n","import type { MutationSession } from '../session';\nimport type { ResolvedContainer } from '../../address';\nimport { fail } from '../issue';\n\nexport function put(\n session: MutationSession,\n container: ResolvedContainer,\n id: string,\n value: unknown\n): void {\n if (container.node.kind !== 'map')\n return fail(container.at, 'invalid-collection', 'Expected a map.');\n session.writeMember(container, id, value, 'set');\n}\n\nexport function remove(session: MutationSession, container: ResolvedContainer, id: string): void {\n if (container.node.kind !== 'map')\n return fail(container.at, 'invalid-collection', 'Expected a map.');\n session.writeMember(container, id, undefined, 'remove');\n}\n","import type { DocumentAnchor } from '../../schema';\nimport type { MutationSession } from '../session';\nimport type { ResolvedContainer } from '../../address';\nimport * as anchor from '../anchor';\nimport { fail } from '../issue';\nexport function create(\n session: MutationSession,\n container: ResolvedContainer,\n entries: readonly { id: string; value: unknown }[],\n position?: DocumentAnchor\n): void {\n const { at, node, value } = container;\n if (node.kind !== 'table') return fail(at, 'invalid-collection', 'Expected a table.');\n const table = value as { ids: string[]; byId: Record<string, unknown> };\n if (!anchor.valid(table.ids, position))\n return fail(at, 'invalid-anchor', 'Unknown table anchor.');\n const ids = new Set<string>();\n for (const entry of entries) {\n if (Object.hasOwn(table.byId, entry.id) || ids.has(entry.id))\n return fail(at, 'duplicate-entity', 'Table key already exists.');\n ids.add(entry.id);\n }\n if (!entries.length) return;\n const index = anchor.index(table.ids, position);\n for (const entry of entries) session.writeMember(container, entry.id, entry.value, 'set');\n const length = table.ids.length;\n table.ids.length += entries.length;\n table.ids.copyWithin(index + entries.length, index, length);\n for (let i = 0; i < entries.length; i++) table.ids[index + i] = entries[i].id;\n}\nexport function remove(\n session: MutationSession,\n container: ResolvedContainer,\n ids: readonly string[]\n): void {\n const { at, node, value } = container;\n if (node.kind !== 'table') return fail(at, 'invalid-collection', 'Expected a table.');\n const table = value as { ids: string[]; byId: Record<string, unknown> };\n for (const id of ids)\n if (!Object.hasOwn(table.byId, id))\n return fail(at, 'missing-entity', 'Table key does not exist.');\n if (!ids.length) return;\n const removed = new Set(ids);\n for (const id of removed) session.writeMember(container, id, undefined, 'remove');\n table.ids = table.ids.filter(id => !removed.has(id));\n}\n\nexport function replace(\n session: MutationSession,\n container: ResolvedContainer,\n id: string,\n value: unknown\n): void {\n const { at, node, value: tableValue } = container;\n if (node.kind !== 'table') return fail(at, 'invalid-collection', 'Expected a table.');\n const table = tableValue as { byId: Record<string, unknown> };\n if (!Object.hasOwn(table.byId, id))\n return fail(at.concat(id), 'missing-entity', 'Table key does not exist.');\n session.writeMember(container, id, value, 'set');\n}\n","import type { DocumentAnchor } from '../../schema';\nimport type { MutationSession } from '../session';\nimport type { ResolvedContainer } from '../../address';\nimport * as anchor from '../anchor';\nimport { fail } from '../issue';\nexport function insert(\n session: MutationSession,\n container: ResolvedContainer,\n value: unknown,\n position?: DocumentAnchor\n): void {\n const { at, node, value: current } = container;\n if (node.kind !== 'list') return fail(at, 'invalid-list-key', 'Expected a list.');\n session.validate(node.value, value, at);\n const id = node.keyOf(value);\n if (typeof id !== 'string') return fail(at, 'invalid-list-key', 'List key must be a string.');\n const items = current as unknown[],\n keys = anchor.keys(items, node.keyOf);\n if (keys.index(id) >= 0) return fail(at, 'duplicate-list-item', 'List key already exists.');\n if (!anchor.valid(keys, position)) return fail(at, 'invalid-anchor', 'Unknown list anchor.');\n session.recorder.order(container);\n session.recorder.member(container, id, session.definition(container, id), -1);\n anchor.insert(items, anchor.index(keys, position), value);\n session.invalidate();\n}\nexport function replace(\n session: MutationSession,\n container: ResolvedContainer,\n id: string,\n value: unknown\n): void {\n const { at, node, value: items } = container;\n if (node.kind !== 'list') return fail(at, 'invalid-list-key', 'Expected a list.');\n const index = anchor.indexedKeys(items as unknown[], node.keyOf).index(id);\n if (index < 0) return fail(at, 'missing-list-item', 'List key does not exist.');\n session.writeMember(container, id, value, 'set', index);\n}\nexport function remove(session: MutationSession, container: ResolvedContainer, id: string): void {\n const { at, node, value } = container;\n if (node.kind !== 'list') return fail(at, 'missing-list-item', 'List key does not exist.');\n const index = anchor.keys(value as unknown[], node.keyOf).index(id);\n if (index < 0) return fail(at, 'missing-list-item', 'List key does not exist.');\n session.writeMember(container, id, undefined, 'remove', index);\n}\n","import type { DocumentAddress } from '../../schema';\nimport type { ResolvedTreeContainer } from '../../address';\nimport type { MutationSession } from '../session';\nimport { contains, type MutableTree, type TreePosition } from '../tree';\nimport { fail } from '../issue';\nconst node = (tree: MutableTree, id: string) =>\n Object.hasOwn(tree.nodes, id) ? tree.nodes[id] : undefined;\nconst positionIndex = (index: number | undefined, length: number, at: DocumentAddress): number => {\n if (index !== undefined && (!Number.isInteger(index) || index < 0))\n return fail(at, 'invalid-tree-index', 'Tree index must be nonnegative.');\n return Math.min(index ?? length, length);\n};\nexport const insert = (\n session: MutationSession,\n container: ResolvedTreeContainer,\n id: string,\n value: unknown,\n position: TreePosition | undefined\n): void => {\n const { at, node: schema, value: tree } = container;\n if (typeof id !== 'string') return fail(at, 'invalid-key', 'Tree keys must be strings.');\n if (contains(tree, id)) return fail(at, 'duplicate-tree-node', 'Tree node already exists.');\n const parentId = position?.parentId;\n const parent = parentId === undefined ? undefined : node(tree, parentId);\n if (\n (tree.rootId !== undefined && !parent) ||\n (tree.rootId === undefined && parentId !== undefined)\n )\n return fail(at, 'missing-tree-parent', 'A nonempty tree requires an existing parent.');\n const index = positionIndex(position?.index, parent?.children.length ?? 0, at);\n session.validate(schema.value, value, at.concat(id));\n session.recorder.tree(container, id);\n if (parentId !== undefined) session.recorder.tree(container, parentId);\n Object.defineProperty(tree.nodes, id, {\n value: { ...(parentId === undefined ? {} : { parentId }), children: [], value },\n writable: true,\n configurable: true,\n enumerable: true,\n });\n if (parent) parent.children.splice(index, 0, id);\n else tree.rootId = id;\n session.invalidate();\n};\nexport const replace = (\n session: MutationSession,\n container: ResolvedTreeContainer,\n id: string,\n value: unknown\n): void => {\n const { at, node: schema, value: tree } = container;\n const entry = node(tree, id);\n if (!entry) return fail(at, 'missing-tree-node', 'Tree node does not exist.');\n if (Object.is(entry.value, value) && Object.hasOwn(entry, 'value')) return;\n session.validate(schema.value, value, at.concat(id));\n session.recorder.tree(container, id);\n entry.value = value;\n};\nexport const remove = (\n session: MutationSession,\n container: ResolvedTreeContainer,\n id: string\n): void => {\n const { at, value: tree } = container;\n const entry = node(tree, id);\n if (!entry) return fail(at, 'missing-tree-node', 'Tree node does not exist.');\n const ids: string[] = [],\n stack = [id];\n while (stack.length) {\n const current = stack.pop()!;\n ids.push(current);\n for (const child of tree.nodes[current].children) stack.push(child);\n }\n for (const key of ids) session.recorder.tree(container, key);\n if (entry.parentId !== undefined) session.recorder.tree(container, entry.parentId);\n if (entry.parentId === undefined) delete tree.rootId;\n else {\n const children = tree.nodes[entry.parentId].children;\n children.splice(children.indexOf(id), 1);\n }\n for (const key of ids) delete tree.nodes[key];\n session.invalidate();\n};\nexport const move = (\n session: MutationSession,\n container: ResolvedTreeContainer,\n id: string,\n position: TreePosition | undefined\n): void => {\n const { at, value: tree } = container;\n const entry = node(tree, id),\n parentId = position?.parentId;\n if (!entry) return fail(at, 'missing-tree-node', 'Tree node does not exist.');\n if (entry.parentId === undefined || parentId === undefined || !contains(tree, parentId))\n return fail(\n at,\n 'missing-tree-parent',\n 'Moving requires a non-root node and an existing parent.'\n );\n for (\n let ancestor: string | undefined = parentId;\n ancestor !== undefined;\n ancestor = tree.nodes[ancestor].parentId\n )\n if (ancestor === id) return fail(at, 'tree-cycle', 'Cannot move a node under its descendant.');\n const old = tree.nodes[entry.parentId],\n next = tree.nodes[parentId];\n const index = positionIndex(position?.index, next.children.length - (old === next ? 1 : 0), at);\n const previous = old.children.indexOf(id);\n if (old === next && previous === index) return;\n session.recorder.tree(container, id);\n session.recorder.tree(container, entry.parentId);\n session.recorder.tree(container, parentId);\n old.children.splice(previous, 1);\n next.children.splice(index, 0, id);\n entry.parentId = parentId;\n session.invalidate();\n};\n","import type { DocumentAnchor } from '../../schema';\nimport type { MutationSession } from '../session';\nimport type { ResolvedContainer } from '../../address';\nimport * as anchor from '../anchor';\nimport { fail } from '../issue';\nexport function move(\n session: MutationSession,\n container: ResolvedContainer,\n id: string,\n position?: DocumentAnchor\n): void {\n const { at, node, value } = container;\n if (node.kind !== 'table' && node.kind !== 'list')\n return fail(at, 'invalid-collection', 'Expected an ordered container.');\n const items = node.kind === 'table' ? (value as { ids: string[] }).ids : (value as unknown[]);\n const keys = node.kind === 'table' ? (items as string[]) : anchor.keys(items, node.keyOf);\n const index =\n node.kind === 'table' ? (items as string[]).indexOf(id) : (keys as anchor.KeyOrder).index(id);\n if (index < 0) return fail(at, 'missing-entity', 'Ordered key does not exist.');\n if (!anchor.valid(keys, position)) return fail(at, 'invalid-anchor', 'Unknown order anchor.');\n const next = anchor.afterRemove(keys, index, position);\n if (next === index) return;\n session.recorder.order(container);\n anchor.move(items, index, next);\n session.invalidate();\n}\n","import type {\n DocumentAddress,\n DocumentAnchor,\n DocumentNode,\n DocumentTreeValue,\n FieldNode,\n Infer,\n ListNode,\n MapNode,\n ObjectNode,\n ObjectShape,\n ReadonlyValue,\n TableNode,\n TreeNode,\n ValueSchemaNode,\n VariantNode,\n} from '../schema';\nimport {\n nodeAt,\n resolveChild,\n resolveLocated,\n compiledShape,\n type FixedMember,\n type ResolvedContainer,\n type ResolvedTreeContainer,\n} from '../address';\nimport { copyValue } from '../schema-value';\nimport type { DependencyTracker } from './dependency';\nimport type { CanonicalState } from '../mutation/state';\nimport type { MutationSession } from '../mutation/session';\nimport * as mapOperations from '../mutation/operations/map';\nimport * as tableOperations from '../mutation/operations/table';\nimport * as listOperations from '../mutation/operations/list';\nimport * as treeOperations from '../mutation/operations/tree';\nimport * as orderOperations from '../mutation/operations/order';\nimport * as tree from '../mutation/tree';\nimport * as anchor from '../mutation/anchor';\nimport { profile } from '../profile';\n\ndeclare const scopeValue: unique symbol;\ntype Scoped<N extends DocumentNode, W extends boolean, V = Infer<N>> = {\n readonly [scopeValue]?: readonly [node: N, writable: W, value: V];\n};\ntype ShapeAccess<S extends ObjectShape, W extends boolean> = W extends true\n ? { -readonly [K in keyof S]: Access<S[K], W> }\n : { readonly [K in keyof S]: Access<S[K], W> };\ntype MapAccess<K extends string, N extends ValueSchemaNode, W extends boolean> = {\n get(id: K): Access<N, W> | undefined;\n has(id: K): boolean;\n ids(): readonly K[];\n} & (W extends true\n ? {\n put(id: K, value: Infer<N>): void;\n remove(id: K): void;\n replace(value: Readonly<Record<K, Infer<N>>>): void;\n }\n : {});\ntype TableAccess<K extends string, N extends ValueSchemaNode, W extends boolean> = {\n get(id: K): Access<N, W> | undefined;\n has(id: K): boolean;\n ids(): readonly K[];\n} & (W extends true\n ? {\n create(id: K, value: Infer<N>, anchor?: DocumentAnchor<K>): void;\n create(\n entries: readonly { readonly id: K; readonly value: Infer<N> }[],\n anchor?: DocumentAnchor<K>\n ): void;\n remove(ids: K | readonly K[]): void;\n move(id: K, anchor?: DocumentAnchor<K>): void;\n replace(value: {\n readonly ids: readonly K[];\n readonly byId: Readonly<Record<K, Infer<N>>>;\n }): void;\n replace(id: K, value: Infer<N>): void;\n }\n : {});\ntype ListAccess<T, W extends boolean> = {\n get(key: string): ReadonlyValue<T> | undefined;\n has(key: string): boolean;\n ids(): readonly string[];\n} & (W extends true\n ? {\n insert(value: ReadonlyValue<T>, anchor?: DocumentAnchor): void;\n remove(key: string): void;\n move(key: string, anchor?: DocumentAnchor): void;\n replace(value: readonly ReadonlyValue<T>[]): void;\n replace(key: string, value: ReadonlyValue<T>): void;\n }\n : {});\ntype TreeAccess<T, W extends boolean> = {\n rootId(): string | undefined;\n get(id: string): ReadonlyValue<T> | undefined;\n has(id: string): boolean;\n parent(id: string): string | undefined;\n children(id: string): readonly string[] | undefined;\n} & (W extends true\n ? {\n insert(id: string, value: ReadonlyValue<T>, position?: tree.TreePosition): void;\n move(id: string, position?: tree.TreePosition): void;\n remove(id: string): void;\n replace(value: DocumentTreeValue<T>): void;\n replace(id: string, value: ReadonlyValue<T>): void;\n }\n : {});\ntype NodeAccess<N extends DocumentNode, W extends boolean> =\n N extends FieldNode<infer T, boolean>\n ? ReadonlyValue<T>\n : N extends ObjectNode<infer S>\n ? ShapeAccess<S, W> & Scoped<N, W>\n : N extends VariantNode<infer Tag, infer V>\n ? {\n [K in keyof V & string]: ShapeAccess<V[K]['shape'], W> & {\n readonly [P in Tag]: K;\n } & Scoped<N, W, Extract<Infer<N>, Record<Tag, K>>>;\n }[keyof V & string]\n : N extends MapNode<infer V, infer K>\n ? MapAccess<K, V, W> & Scoped<N, W>\n : N extends TableNode<infer V, infer K>\n ? TableAccess<K, V, W> & Scoped<N, W>\n : N extends ListNode<infer T>\n ? ListAccess<T, W> & Scoped<N, W>\n : N extends TreeNode<infer T>\n ? TreeAccess<T, W> & Scoped<N, W>\n : never;\ntype Access<N extends DocumentNode, W extends boolean> = N extends { readonly optional: true }\n ? NodeAccess<N, W> | undefined\n : NodeAccess<N, W>;\nexport type Read<N extends DocumentNode> = Access<N, false>;\nexport type Draft<N extends DocumentNode> = Access<N, true>;\ntype Snapshot<T> = T extends {\n readonly [scopeValue]?: readonly [DocumentNode, boolean, infer V];\n}\n ? V\n : ReadonlyValue<T>;\ntype Target = {\n at?: DocumentAddress;\n parent?: Target;\n key: string;\n node: DocumentNode | undefined;\n value: unknown;\n generation: number;\n children:\n | { kind: 'fixed'; schema: DocumentNode; slots: (Target | undefined)[] }\n | { kind: 'dynamic'; keys: Map<string, Target> }\n | undefined;\n proxy: object | undefined;\n container?: ResolvedContainer | ResolvedTreeContainer;\n};\ntype Location = { readonly context: AccessContext; readonly target: Target };\nconst locations = new WeakMap<object, Location>();\nconst locationOf = (value: object): Location | undefined => locations.get(value);\nconst addressOf = (target: Target): DocumentAddress => {\n if (target.at) return target.at;\n profile.access('addresses');\n return (target.at = addressOf(target.parent!).concat(target.key));\n};\nexport type AccessContext = {\n readonly state: CanonicalState;\n /** Omitted for borrowed synchronous Draft and readers that must not escape. */\n readonly active?: () => boolean;\n readonly dependencies?: DependencyTracker;\n readonly session?: MutationSession;\n};\nconst assertActive = (context: AccessContext) => {\n if (context.active && !context.active()) throw new Error('Document access scope has expired.');\n};\nconst collect = (\n context: AccessContext,\n at: DocumentAddress,\n kind: 'value' | 'collection' = 'value',\n id?: string\n) => {\n context.dependencies?.record(\n kind === 'value' ? { kind, at } : { kind, at, ...(id === undefined ? {} : { id }) }\n );\n};\nexport const snapshot = <T>(value: T): Snapshot<T> => {\n const location = value && typeof value === 'object' ? locationOf(value) : undefined;\n if (!location) return value as Snapshot<T>;\n const { context } = location;\n const at = addressOf(location.target);\n profile.access('snapshots');\n collect(context, at);\n const resolved = resolve(context, location.target);\n if (!resolved.node) throw new Error('The selected schema address no longer exists.');\n return copyValue(resolved.node, resolved.value) as Snapshot<T>;\n};\n/** Replace a member with its plain Infer value through the owning draft session. */\ntype ReplaceParentAccess = {\n readonly [scopeValue]?: readonly [\n Extract<DocumentNode, { readonly kind: 'object' | 'variant' }>,\n true,\n unknown,\n ];\n};\nexport const replace = <T extends object & ReplaceParentAccess, K extends keyof Snapshot<T>>(\n container: T,\n key: K,\n value: NoInfer<Snapshot<T>[K]>\n): void => {\n const location = locationOf(container);\n if (!location) throw new TypeError('replace requires scoped document access.');\n if (typeof key !== 'string') throw new TypeError('Document keys must be strings.');\n Reflect.set(container, key, value);\n};\n/** Projection collection contexts use the same scoped access, with explicit collection tools. */\nexport type CollectionAccess<K extends string, N extends ValueSchemaNode> = TableAccess<\n K,\n N,\n false\n>;\nconst resolve = (context: AccessContext, target: Target): Target => {\n assertActive(context);\n const generation = context.session?.generation ?? 0;\n if (target.generation !== generation) {\n profile.access('resolutions');\n if (!target.parent && !target.at!.length) {\n target.node = context.state.schema;\n target.value = context.state.document;\n } else {\n const parent = target.parent && resolve(context, target.parent);\n const location = parent\n ? resolveChild(parent.node, parent.value, target.key)\n : resolveLocated(context.state.schema, context.state.document, target.at!);\n target.node =\n location?.node ?? nodeAt(context.state.schema, addressOf(target), context.state.document);\n target.value =\n location && Object.hasOwn(location.parent, location.key)\n ? (location.parent as Record<string | number, unknown>)[location.key]\n : undefined;\n }\n target.generation = generation;\n }\n return target;\n};\n\nexport const createAccess = (context: AccessContext, initial: DocumentAddress = []): unknown => {\n profile.access('scopes');\n const mutable = (): MutationSession => {\n assertActive(context);\n if (!context.session) throw new TypeError('Cannot modify read-only document access.');\n return context.session;\n };\n const writableContainer = (target: Target, session: MutationSession): ResolvedContainer => {\n if (target.container?.generation === session.generation && 'layout' in target.container)\n return target.container;\n return (target.container = session.bind(addressOf(target), target.node, target.value));\n };\n const childAt = (target: Target, key: string): DocumentAddress => {\n profile.access('addresses');\n return addressOf(target).concat(key);\n };\n const access = (target: Target): unknown => {\n if (target.proxy) return target.proxy;\n const proxy = new Proxy(target, handler);\n profile.access('proxies');\n locations.set(proxy, { context, target });\n target.proxy = proxy;\n return proxy;\n };\n const createTarget = (\n at: DocumentAddress | undefined,\n parent: Target | undefined,\n key: string\n ): Target => ({\n at,\n parent,\n key,\n node: undefined,\n value: undefined,\n generation: -1,\n children: undefined,\n proxy: undefined,\n });\n const childAccess = (\n target: Target,\n member: string | FixedMember,\n node: DocumentNode,\n value: unknown\n ) => {\n const key = typeof member === 'string' ? member : member.key;\n if (node.kind === 'field' || value === undefined) {\n if (context.dependencies) collect(context, childAt(target, key));\n return value;\n }\n let children = target.children;\n let child: Target;\n if (typeof member !== 'string') {\n if (children?.kind !== 'fixed' || children.schema !== target.node)\n children = {\n kind: 'fixed',\n schema: target.node!,\n slots: new Array(compiledShape(target.node!, target.value)!.members.size),\n };\n child = children.slots[member.slot] ??= createTarget(undefined, target, key);\n } else {\n if (children?.kind !== 'dynamic') children = { kind: 'dynamic', keys: new Map() };\n const retained = children.keys.get(key);\n child = retained ?? createTarget(undefined, target, key);\n if (!retained) children.keys.set(key, child);\n }\n target.children = children;\n if (child.generation === target.generation) return child.proxy;\n child.node = node;\n child.value = value;\n child.generation = target.generation;\n return access(child);\n };\n const collectionValue = (target: Target, node: DocumentNode) => {\n const current = resolve(context, target);\n if (current.node !== node || current.value === undefined)\n throw new TypeError('The collection method belongs to a replaced schema branch.');\n return current.value;\n };\n const writableCollection = (target: Target, node: DocumentNode): ResolvedContainer => {\n const session = mutable();\n collectionValue(target, node);\n return writableContainer(target, session);\n };\n const writableTree = (target: Target, node: DocumentNode): ResolvedTreeContainer => {\n const session = mutable();\n collectionValue(target, node);\n if (target.container?.generation === session.generation && !('layout' in target.container))\n return target.container;\n return (target.container = session.bindTree(addressOf(target), target.node, target.value));\n };\n const replaceCollection = (target: Target, node: DocumentNode, value: unknown) => {\n const session = mutable();\n collectionValue(target, node);\n session.replace(addressOf(target), value);\n };\n const mapMethod = (\n target: Target,\n property: string,\n node: Extract<DocumentNode, { kind: 'map' }>\n ): unknown => {\n if (property === 'ids')\n return () => {\n const current = collectionValue(target, node) as Record<string, unknown>;\n if (context.dependencies) collect(context, addressOf(target), 'collection');\n return Object.keys(current);\n };\n if (property === 'has')\n return (id: string) => {\n const current = collectionValue(target, node) as Record<string, unknown>;\n if (context.dependencies) collect(context, addressOf(target), 'collection', id);\n return Object.hasOwn(current, id);\n };\n if (property === 'get')\n return (id: string) => {\n const current = collectionValue(target, node) as Record<string, unknown>;\n if (context.dependencies) collect(context, addressOf(target), 'collection', id);\n if (!Object.hasOwn(current, id)) return undefined;\n if (node.value.kind === 'field') {\n if (context.dependencies) collect(context, childAt(target, id));\n return current[id];\n }\n return childAccess(target, id, node.value, current[id]);\n };\n if (property === 'put')\n return (id: string, value: unknown) => {\n const writable = writableCollection(target, node);\n mapOperations.put(context.session!, writable, id, value);\n };\n if (property === 'remove')\n return (id: string) => {\n const writable = writableCollection(target, node);\n mapOperations.remove(context.session!, writable, id);\n };\n if (property === 'replace') return (value: unknown) => replaceCollection(target, node, value);\n return undefined;\n };\n const orderedMethod = (\n target: Target,\n property: string,\n node: Extract<DocumentNode, { kind: 'table' | 'list' }>\n ): unknown => {\n const at = addressOf(target);\n if (property === 'ids')\n return () => {\n const current = collectionValue(target, node);\n collect(context, at, 'collection');\n return node.kind === 'table'\n ? [...(current as { ids: string[] }).ids]\n : (current as unknown[]).map(node.keyOf);\n };\n if (property === 'has')\n return (id: string) => {\n const current = collectionValue(target, node);\n collect(context, at, 'collection', id);\n return node.kind === 'table'\n ? Object.hasOwn((current as { byId: object }).byId, id)\n : anchor.indexedKeys(current as unknown[], node.keyOf).index(id) >= 0;\n };\n if (property === 'get')\n return (id: string) => {\n const current = collectionValue(target, node);\n collect(context, at, 'collection', id);\n const location = resolveChild(node, current, id);\n if (!location || !Object.hasOwn(location.parent, location.key)) return undefined;\n return childAccess(\n target,\n id,\n location.node,\n (location.parent as Record<string | number, unknown>)[location.key]\n );\n };\n if (property === 'move')\n return (id: string, position?: DocumentAnchor) => {\n const writable = writableCollection(target, node);\n orderOperations.move(context.session!, writable, id, position);\n };\n return undefined;\n };\n const tableMethod = (\n target: Target,\n property: string,\n node: Extract<DocumentNode, { kind: 'table' }>\n ): unknown => {\n if (property === 'create')\n return (\n input: string | readonly { id: string; value: unknown }[],\n valueOrPosition?: unknown,\n position?: DocumentAnchor\n ) => {\n const writable = writableCollection(target, node);\n tableOperations.create(\n context.session!,\n writable,\n Array.isArray(input) ? input : [{ id: input as string, value: valueOrPosition }],\n Array.isArray(input) ? (valueOrPosition as DocumentAnchor | undefined) : position\n );\n };\n if (property === 'remove')\n return (ids: string | readonly string[]) => {\n const writable = writableCollection(target, node);\n tableOperations.remove(context.session!, writable, typeof ids === 'string' ? [ids] : ids);\n };\n if (property === 'replace')\n return (...args: [unknown, unknown?]) => {\n const [valueOrId, value] = args;\n if (args.length === 1) return replaceCollection(target, node, valueOrId);\n const writable = writableCollection(target, node);\n tableOperations.replace(context.session!, writable, valueOrId as string, value);\n };\n return orderedMethod(target, property, node);\n };\n const listMethod = (\n target: Target,\n property: string,\n node: Extract<DocumentNode, { kind: 'list' }>\n ): unknown => {\n if (property === 'insert')\n return (value: unknown, position?: DocumentAnchor) => {\n const writable = writableCollection(target, node);\n listOperations.insert(context.session!, writable, value, position);\n };\n if (property === 'remove')\n return (id: string) => {\n const writable = writableCollection(target, node);\n listOperations.remove(context.session!, writable, id);\n };\n if (property === 'replace')\n return (...args: [unknown, unknown?]) => {\n const [valueOrId, value] = args;\n if (args.length === 1) return replaceCollection(target, node, valueOrId);\n const writable = writableCollection(target, node);\n listOperations.replace(context.session!, writable, valueOrId as string, value);\n };\n return orderedMethod(target, property, node);\n };\n const treeMethod = (\n target: Target,\n property: string,\n node: Extract<DocumentNode, { kind: 'tree' }>\n ): unknown => {\n const at = addressOf(target);\n if (property === 'insert')\n return (id: string, value: unknown, position?: tree.TreePosition) => {\n const writable = writableTree(target, node);\n treeOperations.insert(context.session!, writable, id, value, position);\n };\n if (property === 'remove')\n return (id: string) => {\n const writable = writableTree(target, node);\n treeOperations.remove(context.session!, writable, id);\n };\n if (property === 'move')\n return (id: string, position?: tree.TreePosition) => {\n const writable = writableTree(target, node);\n treeOperations.move(context.session!, writable, id, position);\n };\n if (property === 'replace')\n return (...args: [unknown, unknown?]) => {\n const [valueOrId, value] = args;\n if (args.length === 1) return replaceCollection(target, node, valueOrId);\n const writable = writableTree(target, node);\n treeOperations.replace(context.session!, writable, valueOrId as string, value);\n };\n const current = () => {\n collect(context, at);\n return collectionValue(target, node) as tree.MutableTree;\n };\n if (property === 'rootId') return () => current().rootId;\n if (property === 'get')\n return (id: string) => {\n const value = current();\n return tree.contains(value, id) ? value.nodes[id].value : undefined;\n };\n if (property === 'has') return (id: string) => tree.contains(current(), id);\n if (property === 'parent') return (id: string) => tree.parent(current(), id);\n if (property === 'children')\n return (id: string) => {\n const children = tree.children(current(), id);\n return children ? [...children] : undefined;\n };\n return undefined;\n };\n const handler: ProxyHandler<Target> = {\n get: (target, property) => {\n const { node, value } = resolve(context, target);\n if (!node || value === undefined) return undefined;\n if (typeof property !== 'string') return undefined;\n if (node.kind === 'map') return mapMethod(target, property, node);\n if (node.kind === 'table') return tableMethod(target, property, node);\n if (node.kind === 'list') return listMethod(target, property, node);\n if (node.kind === 'tree') return treeMethod(target, property, node);\n if (node.kind === 'variant' && property === node.tag) {\n collect(context, childAt(target, property));\n return (value as Record<string, unknown>)[property];\n }\n const member = compiledShape(node, value)?.members.get(property);\n if (!member) return undefined;\n if (member.field) {\n if (context.dependencies) collect(context, childAt(target, property));\n return (value as Record<string, unknown>)[property];\n }\n return childAccess(\n target,\n node.kind === 'object' ? member : property,\n member.node,\n (value as Record<string, unknown>)[property]\n );\n },\n set: (target, property, value) => {\n const session = mutable(),\n { node } = resolve(context, target);\n if (\n typeof property !== 'string' ||\n !node ||\n (node.kind !== 'object' && node.kind !== 'variant')\n )\n throw new TypeError('Invalid structural assignment.');\n if (node.kind === 'variant' && node.tag === property)\n throw new TypeError('Variant discriminants are read-only.');\n session.assignMember(writableContainer(target, session), property, value);\n return true;\n },\n deleteProperty: (target, property) => {\n const session = mutable(),\n { node } = resolve(context, target);\n if (\n typeof property !== 'string' ||\n node?.kind === 'map' ||\n (node?.kind === 'variant' && node.tag === property)\n )\n throw new TypeError('Invalid structural deletion.');\n session.removeMember(writableContainer(target, session), property);\n return true;\n },\n has: (target, property) => {\n const { node, value } = resolve(context, target);\n if (typeof property !== 'string') return false;\n if (node?.kind === 'map') return false;\n collect(context, addressOf(target));\n return value !== undefined && Object.hasOwn(value as object, property);\n },\n ownKeys: target => {\n const { node, value } = resolve(context, target);\n if (node?.kind === 'map') return [];\n if (context.dependencies) collect(context, addressOf(target));\n return value && typeof value === 'object' ? Object.keys(value) : [];\n },\n getOwnPropertyDescriptor: (target, property) => {\n const { node, value } = resolve(context, target);\n if (node?.kind === 'map') return undefined;\n return value && Object.hasOwn(value as object, property)\n ? { enumerable: true, configurable: true }\n : undefined;\n },\n defineProperty: () => {\n assertActive(context);\n throw new TypeError('Use schema assignments.');\n },\n setPrototypeOf: () => {\n assertActive(context);\n throw new TypeError('Document prototypes are immutable.');\n },\n preventExtensions: () => {\n assertActive(context);\n throw new TypeError('Document access cannot be frozen.');\n },\n };\n const root = resolve(context, createTarget(initial, undefined, ''));\n if (!root.node || root.node.kind === 'field' || root.value === undefined) {\n if (context.dependencies) collect(context, initial);\n return root.value;\n }\n return access(root);\n};\nexport const collectionAccess = (\n context: AccessContext,\n at: DocumentAddress\n): CollectionAccess<string, ValueSchemaNode> => {\n const value = createAccess(context, at);\n if (value === undefined)\n return {\n get: () => {\n assertActive(context);\n return undefined;\n },\n has: () => {\n assertActive(context);\n return false;\n },\n ids: () => {\n assertActive(context);\n return [];\n },\n };\n return value as CollectionAccess<string, ValueSchemaNode>;\n};\n","import type { DocumentReadable, Synchronous } from '../runtime/contract';\nimport type {\n CollectionId,\n CollectionPath,\n CollectionNode as SchemaCollectionNode,\n Infer,\n ObjectNode,\n ReadonlyValue,\n SchemaPath,\n PathValueOf,\n} from '../schema';\nimport type { Readable } from './readable';\nimport type {\n BatchContext,\n Cause,\n CollectionContext,\n CollectionDraft,\n CollectionRead,\n CollectionEntryTransition,\n DocumentContext,\n ExternalCollectionSource,\n ExternalValueSource,\n GraphSources,\n InputHandles,\n NodeUpdate,\n ValueContext,\n} from './contract';\n\ndeclare const projectionDefinition: unique symbol;\ndeclare const writableInput: unique symbol;\n\n/** A lazy, reusable projection definition. Its value is materialized per runtime. */\nexport type Projection<T> = {\n readonly [projectionDefinition]: T;\n};\n\n/** A runtime-local writable projection definition. */\nexport type Input<T> = Projection<T> & { readonly [writableInput]: true };\n\nexport type ProjectionValues<D extends readonly Projection<unknown>[]> = {\n readonly [K in keyof D]: D[K] extends Projection<infer T> ? T : never;\n};\n\nexport type PublicCollection<K extends string, V> = ReadonlyMap<K, V>;\ntype ObservedCollection<P extends CollectionPath> = PublicCollection<\n CollectionId<P>,\n ReadonlyValue<Infer<SchemaCollectionNode<P>>>\n>;\n\ntype Equality = (a: unknown, b: unknown) => boolean;\ntype PathSelector<S extends ObjectNode> = (path: SchemaPath<S['shape']>) => unknown;\n\ntype Definition =\n | { readonly kind: 'input'; readonly initial: unknown; readonly isEqual?: Equality }\n | { readonly kind: 'readable'; readonly readable: Readable<unknown>; readonly isEqual?: Equality }\n | { readonly kind: 'source-value'; readonly source: ExternalValueSource<unknown, unknown> }\n | {\n readonly kind: 'source-collection';\n readonly source: ExternalCollectionSource<string, unknown, unknown>;\n }\n | {\n readonly kind: 'document';\n readonly document: DocumentReadable<ObjectNode>;\n readonly selector?: PathSelector<ObjectNode>;\n }\n | {\n readonly kind: 'derive';\n readonly dependencies: readonly Projection<unknown>[];\n readonly compute: (...values: readonly unknown[]) => unknown;\n readonly isEqual?: Equality;\n }\n | {\n readonly kind: 'incremental-value';\n readonly dependencies: GraphSources;\n readonly build: (...args: never[]) => unknown;\n readonly isEqual?: Equality;\n readonly name?: string;\n }\n | {\n readonly kind: 'incremental-collection';\n readonly dependencies: GraphSources;\n readonly build: (...args: never[]) => unknown;\n readonly isEqual?: Equality;\n readonly name?: string;\n };\n\ntype DefinitionProjection = Projection<unknown>;\nconst definitions = new WeakMap<object, Definition>();\n\nconst define = <T>(definition: Definition): Projection<T> => {\n const handle = Object.freeze({}) as Projection<T>;\n definitions.set(handle, definition);\n return handle;\n};\n\nexport const definitionOf = (projection: DefinitionProjection): Definition => {\n const definition = definitions.get(projection);\n if (!definition) throw new TypeError('Unknown projection definition.');\n return definition;\n};\n\nexport const input = <T>(\n initial: T,\n equality: (previous: T, next: T) => boolean = Object.is\n): Input<T> => define<T>({ kind: 'input', initial, isEqual: equality as Equality }) as Input<T>;\n\n/**\n * Establishes a reactive boundary from a document, readable, or external\n * source. The selector is compiled when the definition is materialized, so\n * declarations stay lazy and reusable.\n */\nexport function observe<S extends ObjectNode>(document: DocumentReadable<S>): Projection<Infer<S>>;\nexport function observe<T, D>(source: ExternalValueSource<T, D>): Projection<T>;\nexport function observe<K extends string, V, D>(\n source: ExternalCollectionSource<K, V, D>\n): Projection<PublicCollection<K, V>>;\nexport function observe<T>(readable: Readable<T>): Projection<T>;\nexport function observe<S extends ObjectNode, P extends CollectionPath>(\n document: DocumentReadable<S>,\n selector: (path: SchemaPath<S['shape']>) => P\n): Projection<ObservedCollection<P>>;\nexport function observe<S extends ObjectNode, P>(\n document: DocumentReadable<S>,\n selector: (path: SchemaPath<S['shape']>) => P\n): Projection<PathValueOf<P>>;\nexport function observe<S extends ObjectNode>(\n document:\n | DocumentReadable<S>\n | Readable<unknown>\n | ExternalValueSource<unknown, unknown>\n | ExternalCollectionSource<string, unknown, unknown>,\n selector?: PathSelector<S>\n): Projection<unknown> {\n if (isExternalSource(document))\n return document.kind === 'collection'\n ? defineExternalCollection(document)\n : defineExternalValue(document);\n if ('current' in document && typeof document.current === 'function')\n return defineReadable(document as Readable<unknown>);\n return define({\n kind: 'document',\n document: document as DocumentReadable<ObjectNode>,\n selector: selector as PathSelector<ObjectNode> | undefined,\n });\n}\n\nconst isExternalSource = (\n source: unknown\n): source is\n ExternalValueSource<unknown, unknown> | ExternalCollectionSource<string, unknown, unknown> => {\n if (!source || typeof source !== 'object') return false;\n const candidate = source as {\n readonly kind?: unknown;\n readonly current?: unknown;\n readonly revision?: unknown;\n readonly subscribe?: unknown;\n };\n return (\n (candidate.kind === 'value' || candidate.kind === 'collection') &&\n typeof candidate.current === 'function' &&\n typeof candidate.revision === 'function' &&\n typeof candidate.subscribe === 'function'\n );\n};\n\nexport function derive<const D extends readonly Projection<unknown>[], T>(\n dependencies: D,\n compute: (...values: ProjectionValues<D>) => Synchronous<T>,\n equality: (previous: T, next: T) => boolean = Object.is\n): Projection<T> {\n if (!Array.isArray(dependencies) || dependencies.some(value => !definitions.has(value)))\n throw new TypeError('derive dependencies must be projections.');\n const frozen = Object.freeze([...dependencies]) as readonly Projection<unknown>[];\n return define<T>({\n kind: 'derive',\n dependencies: frozen,\n compute: compute as (...values: readonly unknown[]) => unknown,\n isEqual: equality as Equality,\n });\n}\n\n/** Internal source adapters used by observe, not exported publicly. */\nexport const defineReadable = <T>(\n readable: Readable<T>,\n equality: (a: T, b: T) => boolean = Object.is\n): Projection<T> => define<T>({ kind: 'readable', readable, isEqual: equality as Equality });\n\nexport const defineExternalValue = <T, D>(source: ExternalValueSource<T, D>): Projection<T> =>\n define<T>({ kind: 'source-value', source: source as never });\n\nexport const defineExternalCollection = <K extends string, V, D>(\n source: ExternalCollectionSource<K, V, D>\n): Projection<PublicCollection<K, V>> =>\n define<PublicCollection<K, V>>({ kind: 'source-collection', source: source as never });\n\nexport type IncrementalValueDefinition = Extract<Definition, { kind: 'incremental-value' }>;\nexport type IncrementalCollectionDefinition = Extract<\n Definition,\n { kind: 'incremental-collection' }\n>;\n\nexport const defineIncrementalValue = <T>(definition: {\n readonly dependencies: GraphSources;\n readonly build: (...args: never[]) => unknown;\n readonly isEqual?: (a: T, b: T) => boolean;\n readonly name?: string;\n}): Projection<T> =>\n define<T>({\n kind: 'incremental-value',\n dependencies: definition.dependencies,\n build: definition.build,\n isEqual: definition.isEqual as Equality | undefined,\n name: definition.name,\n });\n\nexport const defineIncrementalCollection = <K extends string, V>(definition: {\n readonly dependencies: GraphSources;\n readonly build: (...args: never[]) => unknown;\n readonly isEqual?: (a: V, b: V) => boolean;\n readonly name?: string;\n}): Projection<PublicCollection<K, V>> =>\n define<PublicCollection<K, V>>({\n kind: 'incremental-collection',\n dependencies: definition.dependencies,\n build: definition.build,\n isEqual: definition.isEqual as Equality | undefined,\n name: definition.name,\n });\n\n// Internal event names remain private implementation detail and are not root exports.\nexport type InternalDocumentEvent<S extends ObjectNode> = DocumentContext<S>;\nexport type InternalValueEvent<T, D = unknown> = ValueContext<T, D>;\nexport type InternalCollectionEvent<K extends string, V, D = unknown> = CollectionContext<K, V, D>;\nexport type InternalCollectionTransition<K extends string, V> = CollectionEntryTransition<K, V>;\nexport type InternalCollectionDraft<K extends string, V> = CollectionDraft<K, V>;\nexport type InternalBatchContext = BatchContext;\nexport type InternalCause = Cause;\nexport type InternalInputHandles<S extends GraphSources> = InputHandles<S>;\nexport type InternalNodeUpdate<T> = NodeUpdate<T>;\nexport type InternalCollectionRead<K extends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