doxum 0.1.1

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 (36) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +218 -0
  3. package/dist/chunk-pbuEa-1d.js +13 -0
  4. package/dist/contract-DwNiKioc.d.ts +480 -0
  5. package/dist/contract-Otb5W6cQ.d.cts +480 -0
  6. package/dist/dependency-BdEMyquf.js +735 -0
  7. package/dist/dependency-BdEMyquf.js.map +1 -0
  8. package/dist/dependency-DLcCvNKq.cjs +1015 -0
  9. package/dist/dependency-DLcCvNKq.cjs.map +1 -0
  10. package/dist/index.cjs +2718 -0
  11. package/dist/index.cjs.map +1 -0
  12. package/dist/index.d.cts +89 -0
  13. package/dist/index.d.ts +87 -0
  14. package/dist/index.js +2689 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/integration.cjs +15 -0
  17. package/dist/integration.cjs.map +1 -0
  18. package/dist/integration.d.cts +11 -0
  19. package/dist/integration.d.ts +11 -0
  20. package/dist/integration.js +14 -0
  21. package/dist/integration.js.map +1 -0
  22. package/dist/react.cjs +99 -0
  23. package/dist/react.cjs.map +1 -0
  24. package/dist/react.d.cts +16 -0
  25. package/dist/react.d.ts +16 -0
  26. package/dist/react.js +96 -0
  27. package/dist/react.js.map +1 -0
  28. package/package.json +89 -0
  29. package/skills/doxum-runtime/SKILL.md +51 -0
  30. package/skills/doxum-runtime/agents/openai.yaml +4 -0
  31. package/skills/doxum-runtime/references/guide.en.md +295 -0
  32. package/skills/doxum-runtime/references/guide.zh-CN.md +240 -0
  33. package/skills/doxum-runtime/references/invariants.en.md +147 -0
  34. package/skills/doxum-runtime/references/invariants.zh-CN.md +97 -0
  35. package/skills/doxum-runtime/references/patterns.en.md +287 -0
  36. package/skills/doxum-runtime/references/patterns.zh-CN.md +240 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependency-DLcCvNKq.cjs","names":["isRecord","schemaRoot","readAddress","impactTarget.same"],"sources":["../core/src/schema.ts","../core/src/profile.ts","../core/src/address.ts","../core/src/impact-target.ts","../core/src/value/ownership.ts","../core/src/access/reader.ts","../core/src/runtime/contract.ts","../core/src/runtime/access.ts","../core/src/access/dependency.ts"],"sourcesContent":["export type DocumentAddress = readonly string[];\n\nexport type DocumentListConfig<TItem> = {\n readonly keyOf: (item: TItem) => string;\n};\nexport type DocumentTreeNode<TValue> = {\n readonly parentId?: string;\n readonly children: readonly string[];\n readonly value?: TValue;\n};\nexport type DocumentTreeValue<TValue> = {\n readonly rootId?: string;\n readonly nodes: Readonly<Record<string, DocumentTreeNode<TValue>>>;\n};\n\ntype BaseNode<K extends string> = { readonly kind: K };\nexport type FieldNode<T, Optional extends boolean = false> = BaseNode<'field'> & {\n readonly __value?: T;\n readonly optional?: Optional;\n};\nexport type OptionalNode<TNode extends DocumentNode> = TNode & {\n readonly optional: true;\n};\nexport interface ObjectShape {\n readonly [key: string]: DocumentNode;\n}\nexport type ObjectNode<TShape extends ObjectShape> = BaseNode<'object'> & {\n readonly shape: TShape;\n};\nexport interface VariantShape {\n readonly [key: string]: ObjectNode<ObjectShape>;\n}\nexport type VariantNode<\n TTag extends string,\n TVariants extends VariantShape,\n> = BaseNode<'variant'> & {\n readonly tag: TTag;\n readonly variants: TVariants;\n};\nexport type SingleNode<TValue extends ObjectNode<ObjectShape> | VariantNode<string, VariantShape>> =\n BaseNode<'single'> & {\n readonly value: TValue;\n };\nexport type TableNode<TValue extends ObjectNode<ObjectShape> | VariantNode<string, VariantShape>> =\n BaseNode<'table'> & {\n readonly value: TValue;\n };\nexport type MapNode<TValue extends ObjectNode<ObjectShape> | VariantNode<string, VariantShape>> =\n BaseNode<'map'> & {\n readonly value: TValue;\n };\nexport type RecordNode<TId extends string, TValue> = BaseNode<'record'> & {\n readonly __id?: TId;\n readonly __value?: TValue;\n};\nexport type DictNode<TKey extends string, TValue> = BaseNode<'dict'> & {\n readonly __key?: TKey;\n readonly __value?: TValue;\n};\nexport type ListNode<TItem> = BaseNode<'list'> & {\n readonly __item?: TItem;\n keyOf(item: TItem): string;\n};\nexport type TreeNode<TValue> = BaseNode<'tree'> & {\n readonly __value?: TValue;\n};\n\nexport type DocumentNode =\n | FieldNode<unknown, boolean>\n | ObjectNode<ObjectShape>\n | VariantNode<string, VariantShape>\n | SingleNode<ObjectNode<ObjectShape> | VariantNode<string, VariantShape>>\n | TableNode<ObjectNode<ObjectShape> | VariantNode<string, VariantShape>>\n | MapNode<ObjectNode<ObjectShape> | VariantNode<string, VariantShape>>\n | RecordNode<string, unknown>\n | DictNode<string, unknown>\n | ListNode<unknown>\n | TreeNode<unknown>;\n\ntype EntityValue<N extends ObjectNode<ObjectShape> | VariantNode<string, VariantShape>> =\n N extends ObjectNode<infer S>\n ? DocumentValueOfShape<S>\n : N extends VariantNode<infer T, infer V>\n ? {\n [K in keyof V & string]: { [P in T]: K } & DocumentValueOfShape<\n V[K] extends ObjectNode<infer S> ? S : never\n >;\n }[keyof V & string]\n : never;\n\nexport type DocumentValueOfNode<N> =\n N extends FieldNode<infer T, infer O>\n ? O extends true\n ? T | undefined\n : T\n : N extends ObjectNode<infer S>\n ? DocumentValueOfShape<S>\n : N extends VariantNode<infer T, infer V>\n ? EntityValue<VariantNode<T, V>>\n : N extends SingleNode<infer V>\n ? EntityValue<V>\n : N extends TableNode<infer V>\n ? {\n readonly ids: readonly string[];\n readonly byId: Readonly<Record<string, EntityValue<V>>>;\n }\n : N extends MapNode<infer V>\n ? Readonly<Record<string, EntityValue<V>>>\n : N extends RecordNode<infer I, infer T>\n ? Readonly<Record<I, T>>\n : N extends DictNode<infer K, infer T>\n ? Readonly<Partial<Record<K, T>>>\n : N extends ListNode<infer I>\n ? readonly I[]\n : N extends TreeNode<infer T>\n ? DocumentTreeValue<T>\n : never;\n\ntype OptionalKeys<S extends ObjectShape> = {\n [K in keyof S]: S[K] extends { readonly optional: true } ? K : never;\n}[keyof S];\ntype RequiredKeys<S extends ObjectShape> = Exclude<keyof S, OptionalKeys<S>>;\nexport type DocumentValueOfShape<S extends ObjectShape> = {\n readonly [K in RequiredKeys<S>]: DocumentValueOfNode<S[K]>;\n} & { readonly [K in OptionalKeys<S>]?: DocumentValueOfNode<S[K]> };\nexport type ReadonlyDocument<S extends DocumentSchema> = DocumentValueOfShape<S['shape']>;\n\nexport type CollectionSelector<TId extends string = string, TEntry = unknown> = {\n readonly kind: 'collection';\n readonly schema: DocumentSchema;\n readonly address: DocumentAddress;\n readonly __id?: TId;\n readonly __entry?: TEntry;\n};\nexport type ValueSelector<TResult = unknown> = {\n readonly kind: 'value';\n readonly schema: DocumentSchema;\n readonly address: DocumentAddress;\n readonly __value?: TResult;\n};\nexport type ImpactTarget<T = unknown> =\n | { readonly kind: 'value'; readonly at: DocumentAddress }\n | ValueSelector<T>\n | {\n readonly kind: 'collection';\n readonly at: DocumentAddress;\n readonly id?: string;\n }\n | CollectionSelector<string, T>;\ntype PathMarker<TValue> = { readonly __value?: TValue };\n\ntype SchemaPathFor<S extends ObjectShape = ObjectShape, TValue = unknown> = {\n readonly [K in keyof S]: PathValue<S[K]>;\n} & {\n readonly item: (id: string) => SchemaPathFor<{}, unknown>;\n} & PathMarker<TValue>;\n\nexport type DocumentSchema<TShape extends ObjectShape = {}> = {\n readonly kind: 'schema';\n readonly shape: TShape;\n collection<TPath extends PathMarker<unknown>>(\n pick: (path: SchemaPath<TShape>) => TPath\n ): CollectionSelector<CollectionId<TPath>, CollectionEntry<TPath>>;\n value<TPath extends PathMarker<unknown>>(\n pick: (path: SchemaPath<TShape>) => TPath\n ): ValueSelector<PathValueResult<TPath>>;\n};\n\nexport type SchemaPath<S extends ObjectShape = {}> = SchemaPathFor<S, DocumentValueOfShape<S>>;\n\ntype VariantKeys<V extends VariantShape> = {\n [K in keyof V & string]: keyof (V[K] extends ObjectNode<infer S> ? S : {});\n}[keyof V & string] &\n string;\ntype VariantFieldPath<V extends VariantShape, K extends string> = {\n [P in keyof V & string]: V[P] extends ObjectNode<infer S>\n ? K extends keyof S\n ? PathValue<S[K]>\n : never\n : never;\n}[keyof V & string];\ntype VariantPath<V extends VariantShape> = {\n readonly [K in VariantKeys<V>]: VariantFieldPath<V, K>;\n} & {\n readonly item: (id: string) => SchemaPathFor<{}, unknown>;\n} & PathMarker<EntityValue<VariantNode<string, V>>>;\ntype PathNodeValue<N extends DocumentNode> = N extends { readonly optional: true }\n ? DocumentValueOfNode<N> | undefined\n : DocumentValueOfNode<N>;\ntype EntityPath<N extends ObjectNode<ObjectShape> | VariantNode<string, VariantShape>> =\n N extends ObjectNode<infer S>\n ? SchemaPathFor<S, PathNodeValue<N>>\n : N extends VariantNode<string, infer V>\n ? VariantPath<V>\n : never;\ntype CollectionPath<N extends ObjectNode<ObjectShape> | VariantNode<string, VariantShape>> = Omit<\n EntityPath<N>,\n 'item'\n> & {\n readonly item: (id: string) => EntityPath<N>;\n readonly __collection?: {\n readonly id: string;\n readonly entry: DocumentValueOfNode<N>;\n };\n};\n\ntype PathValue<N extends DocumentNode> =\n N extends ObjectNode<infer S>\n ? SchemaPathFor<S, PathNodeValue<N>>\n : N extends VariantNode<infer _TTag, infer V>\n ? VariantPath<V>\n : N extends TableNode<infer V> | MapNode<infer V>\n ? CollectionPath<V>\n : N extends SingleNode<infer V>\n ? EntityPath<V>\n : SchemaPathFor<{}, PathNodeValue<N>>;\ntype CollectionInfo<T> = T extends {\n readonly __collection?: {\n readonly id: infer TId;\n readonly entry: infer TEntry;\n };\n}\n ? { readonly id: TId; readonly entry: TEntry }\n : never;\ntype CollectionId<T> =\n CollectionInfo<T> extends { readonly id: infer TId extends string } ? TId : string;\ntype CollectionEntry<T> =\n CollectionInfo<T> extends { readonly entry: infer TEntry } ? TEntry : never;\ntype PathValueResult<T> = T extends PathMarker<infer TValue> ? TValue : unknown;\n\nconst node = <T extends DocumentNode>(value: T): T => Object.freeze(value);\nexport const field = <T>(): FieldNode<T> => node({ kind: 'field' });\nexport const optional = <T extends DocumentNode>(value: T): OptionalNode<T> =>\n node({ ...value, optional: true } as OptionalNode<T>);\nexport const object = <S extends ObjectShape>(shape: S): ObjectNode<S> =>\n node({ kind: 'object', shape });\nexport const variant = <T extends string, V extends VariantShape>(\n tag: T,\n variants: V\n): VariantNode<T, V> => node({ kind: 'variant', tag, variants });\nexport const single = <V extends ObjectNode<ObjectShape> | VariantNode<string, VariantShape>>(\n value: V\n): SingleNode<V> => node({ kind: 'single', value });\nexport const table = <V extends ObjectNode<ObjectShape> | VariantNode<string, VariantShape>>(\n value: V\n): TableNode<V> => node({ kind: 'table', value });\nexport const map = <V extends ObjectNode<ObjectShape> | VariantNode<string, VariantShape>>(\n value: V\n): MapNode<V> => node({ kind: 'map', value });\nexport const record = <TId extends string = string, TValue = unknown>(): RecordNode<TId, TValue> =>\n node({ kind: 'record' });\nexport const dict = <TKey extends string = string, TValue = unknown>(): DictNode<TKey, TValue> =>\n node({ kind: 'dict' });\nexport const list = <TItem>(config: DocumentListConfig<TItem>): ListNode<TItem> =>\n ({ kind: 'list', keyOf: config.keyOf }) as ListNode<TItem>;\nexport const tree = <TValue = unknown>(): TreeNode<TValue> => node({ kind: 'tree' });\n\nconst pathProxy = (address: DocumentAddress): SchemaPath & { readonly address: DocumentAddress } =>\n new Proxy({ address } as SchemaPath & { readonly address: DocumentAddress }, {\n get: (_target, property: string | symbol) => {\n if (property === 'address') return address;\n if (property === 'item') return (id: string) => pathProxy([...address, id]);\n if (typeof property === 'symbol') return undefined;\n return pathProxy([...address, property]);\n },\n });\n\nconst select = <S extends ObjectShape>(\n owner: DocumentSchema<S>,\n kind: 'collection' | 'value',\n pick: (path: SchemaPath<S>) => unknown\n): CollectionSelector | ValueSelector => {\n const value = pick(pathProxy([]) as unknown as SchemaPath<S>);\n const selected = value as { readonly address?: DocumentAddress };\n return Object.freeze({\n kind,\n schema: owner,\n address: Object.freeze([...(selected.address ?? [])]),\n }) as CollectionSelector | ValueSelector;\n};\n\nexport const schema = <S extends ObjectShape>(shape: S): DocumentSchema<S> => {\n const result: DocumentSchema<S> = {\n kind: 'schema',\n shape,\n collection: <TPath extends PathMarker<unknown>>(pick: (path: SchemaPath<S>) => TPath) =>\n select(result, 'collection', pick) as CollectionSelector<\n CollectionId<TPath>,\n CollectionEntry<TPath>\n >,\n value: <TPath extends PathMarker<unknown>>(pick: (path: SchemaPath<S>) => TPath) =>\n select(result, 'value', pick) as ValueSelector<PathValueResult<TPath>>,\n };\n return Object.freeze(result);\n};\n","export type CloneReason =\n 'initial' | 'canonical' | 'commit' | 'inverse' | 'reader' | 'replace' | 'journal';\n\ntype CloneCounters = {\n calls: number;\n containers: number;\n nodes: Record<CloneReason, number>;\n deepEqual: { calls: number; containers: number };\n documents: { initial: number };\n};\ntype ProfileCounters = {\n clone: CloneCounters;\n mutation: { normalized: number; executed: number; inverseCreated: number };\n batch: {\n operations: number;\n entries: number;\n collectionsResolved: number;\n journalRecords: number;\n rejected: number;\n inverseOperations: number;\n payloadTransferred: number;\n payloadSnapshots: number;\n };\n journal: {\n subjects: number;\n comparisons: number;\n absorbed: number;\n orderSnapshots: number;\n orderItems: number;\n };\n address: {\n schemaSteps: number;\n documentSteps: number;\n prefixComparisons: number;\n segmentsCompared: number;\n arraysCopied: number;\n };\n impact: { affectsChecks: number };\n reader: {\n sessions: number;\n nodeLookups: number;\n collectionIds: number;\n structuralSnapshots: number;\n };\n collectionView: {\n mappedItems: number;\n idsScanned: number;\n arraysCopied: number;\n };\n materialized: {\n updated: number;\n skipped: number;\n rebuilt: number;\n sourceChanges: number;\n notifications: number;\n };\n};\n\nexport type ProfileSnapshot = Readonly<{\n clone: Readonly<{\n calls: number;\n containers: number;\n nodes: Readonly<Record<CloneReason, number>>;\n deepEqual: Readonly<{ calls: number; containers: number }>;\n documents: Readonly<{ initial: number }>;\n }>;\n mutation: Readonly<{\n normalized: number;\n executed: number;\n inverseCreated: number;\n }>;\n batch: Readonly<ProfileCounters['batch']>;\n journal: Readonly<ProfileCounters['journal']>;\n address: Readonly<ProfileCounters['address']>;\n impact: Readonly<ProfileCounters['impact']>;\n reader: Readonly<ProfileCounters['reader']>;\n collectionView: Readonly<ProfileCounters['collectionView']>;\n materialized: Readonly<ProfileCounters['materialized']>;\n}>;\n\nconst cloneReasons = (): Record<CloneReason, number> => ({\n initial: 0,\n canonical: 0,\n commit: 0,\n inverse: 0,\n reader: 0,\n replace: 0,\n journal: 0,\n});\n\nconst counters = (): ProfileCounters => ({\n clone: {\n calls: 0,\n containers: 0,\n nodes: cloneReasons(),\n deepEqual: { calls: 0, containers: 0 },\n documents: { initial: 0 },\n },\n mutation: { normalized: 0, executed: 0, inverseCreated: 0 },\n batch: {\n operations: 0,\n entries: 0,\n collectionsResolved: 0,\n journalRecords: 0,\n rejected: 0,\n inverseOperations: 0,\n payloadTransferred: 0,\n payloadSnapshots: 0,\n },\n journal: {\n subjects: 0,\n comparisons: 0,\n absorbed: 0,\n orderSnapshots: 0,\n orderItems: 0,\n },\n address: {\n schemaSteps: 0,\n documentSteps: 0,\n prefixComparisons: 0,\n segmentsCompared: 0,\n arraysCopied: 0,\n },\n impact: { affectsChecks: 0 },\n reader: {\n sessions: 0,\n nodeLookups: 0,\n collectionIds: 0,\n structuralSnapshots: 0,\n },\n collectionView: { mappedItems: 0, idsScanned: 0, arraysCopied: 0 },\n materialized: {\n updated: 0,\n skipped: 0,\n rebuilt: 0,\n sourceChanges: 0,\n notifications: 0,\n },\n});\n\n// Recorder calls are stable no-op-capable functions. Only this module owns the\n// mutable session counter tree; domain code never branches on profile state.\nconst active = { current: undefined as ProfileCounters | undefined };\n\n// Snapshot allocation is intentionally delayed until the caller asks for it.\nconst freezeSnapshot = (value: ProfileCounters): ProfileSnapshot =>\n Object.freeze({\n clone: Object.freeze({\n calls: value.clone.calls,\n containers: value.clone.containers,\n nodes: Object.freeze({ ...value.clone.nodes }),\n deepEqual: Object.freeze({ ...value.clone.deepEqual }),\n documents: Object.freeze({ ...value.clone.documents }),\n }),\n mutation: Object.freeze({ ...value.mutation }),\n batch: Object.freeze({ ...value.batch }),\n journal: Object.freeze({ ...value.journal }),\n address: Object.freeze({ ...value.address }),\n impact: Object.freeze({ ...value.impact }),\n reader: Object.freeze({ ...value.reader }),\n collectionView: Object.freeze({ ...value.collectionView }),\n materialized: Object.freeze({ ...value.materialized }),\n });\n\nexport const profile = {\n clone: {\n call: (): void => {\n const value = active.current;\n if (value) value.clone.calls += 1;\n },\n node: (reason: CloneReason): void => {\n const value = active.current;\n if (!value) return;\n value.clone.nodes[reason] += 1;\n },\n container: (): void => {\n const value = active.current;\n if (value) value.clone.containers += 1;\n },\n deepEqual: (): void => {\n const value = active.current;\n if (value) value.clone.deepEqual.calls += 1;\n },\n deepEqualContainer: (): void => {\n const value = active.current;\n if (value) value.clone.deepEqual.containers += 1;\n },\n initialDocument: (): void => {\n const value = active.current;\n if (value) value.clone.documents.initial += 1;\n },\n },\n mutation: {\n normalized: (): void => {\n const value = active.current;\n if (value) value.mutation.normalized += 1;\n },\n executed: (): void => {\n const value = active.current;\n if (value) value.mutation.executed += 1;\n },\n inverse: (): void => {\n const value = active.current;\n if (value) value.mutation.inverseCreated += 1;\n },\n },\n batch: {\n operation: (): void => {\n const value = active.current;\n if (value) value.batch.operations += 1;\n },\n entry: (amount = 1): void => {\n const value = active.current;\n if (value) value.batch.entries += amount;\n },\n collectionResolved: (): void => {\n const value = active.current;\n if (value) value.batch.collectionsResolved += 1;\n },\n journalRecord: (): void => {\n const value = active.current;\n if (value) value.batch.journalRecords += 1;\n },\n rejected: (): void => {\n const value = active.current;\n if (value) value.batch.rejected += 1;\n },\n inverse: (): void => {\n const value = active.current;\n if (value) value.batch.inverseOperations += 1;\n },\n payloadTransferred: (): void => {\n const value = active.current;\n if (value) value.batch.payloadTransferred += 1;\n },\n payloadSnapshot: (): void => {\n const value = active.current;\n if (value) value.batch.payloadSnapshots += 1;\n },\n },\n journal: {\n subject: (): void => {\n const value = active.current;\n if (value) value.journal.subjects += 1;\n },\n comparison: (): void => {\n const value = active.current;\n if (value) value.journal.comparisons += 1;\n },\n absorbed: (): void => {\n const value = active.current;\n if (value) value.journal.absorbed += 1;\n },\n orderSnapshot: (items: number): void => {\n const value = active.current;\n if (!value) return;\n value.journal.orderSnapshots += 1;\n value.journal.orderItems += items;\n },\n },\n address: {\n schemaStep: (): void => {\n const value = active.current;\n if (value) value.address.schemaSteps += 1;\n },\n documentStep: (): void => {\n const value = active.current;\n if (value) value.address.documentSteps += 1;\n },\n arrayCopied: (): void => {\n const value = active.current;\n if (value) value.address.arraysCopied += 1;\n },\n prefixComparison: (): void => {\n const value = active.current;\n if (value) value.address.prefixComparisons += 1;\n },\n segmentCompared: (): void => {\n const value = active.current;\n if (value) value.address.segmentsCompared += 1;\n },\n },\n impact: {\n affects: (): void => {\n const value = active.current;\n if (value) value.impact.affectsChecks += 1;\n },\n },\n reader: {\n session: (): void => {\n const value = active.current;\n if (value) value.reader.sessions += 1;\n },\n lookup: (): void => {\n const value = active.current;\n if (value) value.reader.nodeLookups += 1;\n },\n collectionIds: (amount = 1): void => {\n const value = active.current;\n if (value) value.reader.collectionIds += amount;\n },\n structuralSnapshot: (): void => {\n const value = active.current;\n if (value) value.reader.structuralSnapshots += 1;\n },\n },\n collectionView: {\n mapped: (): void => {\n const value = active.current;\n if (value) value.collectionView.mappedItems += 1;\n },\n idsScanned: (amount = 1): void => {\n const value = active.current;\n if (value) value.collectionView.idsScanned += amount;\n },\n arrayCopied: (): void => {\n const value = active.current;\n if (value) value.collectionView.arraysCopied += 1;\n },\n },\n materialized: {\n updated: (): void => {\n const value = active.current;\n if (value) value.materialized.updated += 1;\n },\n skipped: (): void => {\n const value = active.current;\n if (value) value.materialized.skipped += 1;\n },\n rebuilt: (): void => {\n const value = active.current;\n if (value) value.materialized.rebuilt += 1;\n },\n sourceChanged: (): void => {\n const value = active.current;\n if (value) value.materialized.sourceChanges += 1;\n },\n notification: (): void => {\n const value = active.current;\n if (value) value.materialized.notifications += 1;\n },\n },\n} as const;\n\nexport type ProfileSession = {\n readonly snapshot: () => ProfileSnapshot;\n readonly stop: () => ProfileSnapshot;\n};\n\nexport const startProfile = (): ProfileSession => {\n if (active.current) throw new Error('A document profile session is already active.');\n const value = counters();\n active.current = value;\n let stopped = false;\n const snapshot = (): ProfileSnapshot => freezeSnapshot(value);\n return {\n snapshot,\n stop: (): ProfileSnapshot => {\n if (!stopped) {\n stopped = true;\n active.current = undefined;\n }\n return snapshot();\n },\n };\n};\n\nexport const measureProfile = <T>(\n run: () => T\n): { readonly value: T; readonly profile: ProfileSnapshot } => {\n const session = startProfile();\n try {\n const value = run();\n return { value, profile: session.stop() };\n } catch (error) {\n session.stop();\n throw error;\n }\n};\n","import type { DocumentAddress, DocumentNode, DocumentSchema, ObjectShape } from './schema';\nimport { profile } from './profile';\n\n/** The only resolved address representation used inside the runtime. */\nexport type AddressRef = {\n readonly path: number;\n readonly address: DocumentAddress;\n};\n\ntype RegistryNode = {\n readonly static: Map<string, RegistryNode>;\n dynamic?: RegistryNode;\n path?: number;\n};\n\ntype Registry = {\n readonly root: RegistryNode;\n nextPath: number;\n};\n\nconst registries = new WeakMap<object, Registry>();\nconst registryNode = (): RegistryNode => ({ static: new Map() });\nconst registryFor = (schema: DocumentSchema): Registry => {\n const cached = registries.get(schema as object);\n if (cached) return cached;\n const registry: Registry = { root: registryNode(), nextPath: 0 };\n registries.set(schema as object, registry);\n return registry;\n};\n\nconst hashText = (value: string, seed: number): number => {\n let hash = seed;\n for (let index = 0; index < value.length; index += 1)\n hash = Math.imul(hash ^ value.charCodeAt(index), 16_777_619);\n return hash >>> 0;\n};\n\nconst appendAddressHash = (hash: number, segment: string): number =>\n hashText(segment, hashText('/', hash));\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nconst unwrap = (node: DocumentNode | undefined): DocumentNode | undefined => {\n let current = node;\n while (current?.kind === 'single') current = current.value;\n return current;\n};\n\nconst variantNode = (\n node: Extract<DocumentNode, { kind: 'variant' }>,\n value: unknown\n): DocumentNode | undefined => {\n const tag = isRecord(value) && typeof value[node.tag] === 'string' ? value[node.tag] : undefined;\n return node.variants[String(tag ?? Object.keys(node.variants)[0] ?? '')];\n};\n\nconst schemaRoot = (schema: DocumentSchema): DocumentNode => ({\n kind: 'object',\n shape: schema.shape,\n});\n\ntype Step = {\n readonly node: DocumentNode | undefined;\n readonly dynamic: boolean;\n};\n\nconst step = (nodeInput: DocumentNode | undefined, value: unknown, segment: string): Step => {\n let node = unwrap(nodeInput);\n if (!node) return { node: undefined, dynamic: false };\n if (node.kind === 'variant') {\n node = unwrap(variantNode(node, value));\n }\n if (!node) return { node: undefined, dynamic: false };\n if (node.kind === 'object') return { node: node.shape[segment], dynamic: false };\n if (node.kind === 'table' || node.kind === 'map') return { node: node.value, dynamic: true };\n // These nodes use operation-specific keys rather than address segments, but\n // accepting a dynamic step keeps address resolution total for user targets.\n if (\n node.kind === 'record' ||\n node.kind === 'dict' ||\n node.kind === 'list' ||\n node.kind === 'tree'\n )\n return { node, dynamic: true };\n return { node: undefined, dynamic: false };\n};\n\nconst pathFor = (\n schema: DocumentSchema,\n address: DocumentAddress,\n document?: unknown\n): number | undefined => {\n const registry = registryFor(schema);\n let trie = registry.root;\n let node: DocumentNode | undefined = schemaRoot(schema);\n let value: unknown = document;\n for (const segment of address) {\n profile.address.schemaStep();\n profile.address.documentStep();\n const resolved = step(node, value, segment);\n if (!resolved.node) return undefined;\n const next = resolved.dynamic\n ? (trie.dynamic ??= registryNode())\n : (() => {\n const existing = trie.static.get(segment);\n if (existing) return existing;\n const created = registryNode();\n trie.static.set(segment, created);\n return created;\n })();\n trie = next;\n node = resolved.node;\n value = readSegment(value, segment);\n }\n if (trie.path === undefined) trie.path = registry.nextPath++;\n return trie.path;\n};\n\nexport const resolveAddress = (\n schema: DocumentSchema,\n address: DocumentAddress,\n document?: unknown\n): AddressRef | undefined => {\n if (!Array.isArray(address)) return undefined;\n for (const segment of address) if (typeof segment !== 'string') return undefined;\n profile.address.arrayCopied();\n const owned = Object.freeze(address.slice()) as DocumentAddress;\n const path = pathFor(schema, owned, document);\n return path === undefined ? undefined : { path, address: owned };\n};\n\nexport const nodeAt = (\n schema: DocumentSchema,\n address: DocumentAddress,\n document?: unknown\n): DocumentNode | undefined => {\n let node: DocumentNode | undefined = schemaRoot(schema);\n let value = document;\n for (const segment of address) {\n const resolved = step(node, value, segment);\n node = resolved.node;\n value = readSegment(value, segment);\n if (!node) return undefined;\n }\n return unwrap(node);\n};\n\nexport const readSegment = (value: unknown, segment: string): unknown => {\n if (!isRecord(value) && !Array.isArray(value)) return undefined;\n if (isRecord(value) && 'byId' in value && isRecord(value.byId)) {\n const entity = value.byId[segment];\n if (entity !== undefined || Object.prototype.hasOwnProperty.call(value.byId, segment))\n return entity;\n }\n return (value as Record<string, unknown>)[segment];\n};\n\nexport const read = (root: unknown, address: DocumentAddress): unknown => {\n let value = root;\n for (const segment of address) {\n value = readSegment(value, segment);\n if (value === undefined) return undefined;\n }\n return value;\n};\n\nexport type Located = {\n readonly parent: Record<string, unknown> | unknown[];\n readonly key: string | number;\n readonly value: unknown;\n};\n\ntype ResolvedCollection = {\n readonly address: DocumentAddress;\n readonly addressHash: number;\n readonly id: string;\n readonly parent?: ResolvedCollection;\n};\n\nexport type ResolvedAddress = Located & {\n readonly addressHash: number;\n readonly node: DocumentNode;\n readonly collection?: ResolvedCollection;\n};\n\n/** Resolves schema and document location in one address traversal. */\nexport const resolveLocated = (\n schema: DocumentSchema,\n root: unknown,\n address: DocumentAddress\n): ResolvedAddress | undefined => {\n if (address.length === 0) return undefined;\n let node: DocumentNode | undefined = schemaRoot(schema);\n let current: unknown = root;\n let collection: ResolvedCollection | undefined;\n let addressHash = 2_166_136_261;\n for (let index = 0; index < address.length - 1; index += 1) {\n profile.address.schemaStep();\n profile.address.documentStep();\n const resolved = step(node, current, address[index]);\n if (!resolved.node) return undefined;\n if (node?.kind === 'table' || node?.kind === 'map')\n collection = {\n address: address.slice(0, index),\n addressHash,\n id: address[index],\n ...(collection ? { parent: collection } : {}),\n };\n addressHash = appendAddressHash(addressHash, address[index]);\n node = resolved.node;\n current = readSegment(current, address[index]);\n if (!node) return undefined;\n }\n profile.address.schemaStep();\n profile.address.documentStep();\n const last = address[address.length - 1];\n const resolved = step(node, current, last);\n if (!resolved.node || (!isRecord(current) && !Array.isArray(current))) return undefined;\n if (node?.kind === 'table' || node?.kind === 'map')\n collection = {\n address: address.slice(0, -1),\n addressHash,\n id: last,\n ...(collection ? { parent: collection } : {}),\n };\n addressHash = appendAddressHash(addressHash, last);\n if (isRecord(current) && 'byId' in current && isRecord(current.byId) && last in current.byId)\n return {\n addressHash,\n node: resolved.node,\n parent: current.byId,\n key: last,\n value: current.byId[last],\n ...(collection ? { collection } : {}),\n };\n return {\n addressHash,\n node: resolved.node,\n parent: current,\n key: Array.isArray(current) && /^\\d+$/.test(last) ? Number(last) : last,\n value: readSegment(current, last),\n ...(collection ? { collection } : {}),\n };\n};\n\nexport const locate = (root: unknown, address: DocumentAddress): Located | undefined => {\n if (address.length === 0) return undefined;\n let current: unknown = root;\n for (let index = 0; index < address.length - 1; index += 1)\n current = readSegment(current, address[index]);\n if (!isRecord(current) && !Array.isArray(current)) return undefined;\n const last = address[address.length - 1];\n if (isRecord(current) && 'byId' in current && isRecord(current.byId) && last in current.byId)\n return { parent: current.byId, key: last, value: current.byId[last] };\n return {\n parent: current,\n key: Array.isArray(current) && /^\\d+$/.test(last) ? Number(last) : last,\n value: readSegment(current, last),\n };\n};\n\nexport const set = (root: unknown, address: DocumentAddress, value: unknown): boolean => {\n const target = locate(root, address);\n if (!target) return false;\n (target.parent as Record<string | number, unknown>)[target.key] = value;\n return true;\n};\n\nexport const remove = (root: unknown, address: DocumentAddress): boolean => {\n const target = locate(root, address);\n if (!target || !Object.prototype.hasOwnProperty.call(target.parent, target.key)) return false;\n if (Array.isArray(target.parent)) target.parent.splice(Number(target.key), 1);\n else delete target.parent[String(target.key)];\n return true;\n};\n\nexport const contains = (parent: DocumentAddress, child: DocumentAddress): boolean => {\n profile.address.prefixComparison();\n if (parent.length > child.length) return false;\n for (let index = 0; index < parent.length; index += 1) {\n profile.address.segmentCompared();\n if (parent[index] !== child[index]) return false;\n }\n return true;\n};\n\nexport const overlaps = (a: DocumentAddress, b: DocumentAddress): boolean =>\n contains(a, b) || contains(b, a);\n\nexport const debugKey = (address: DocumentAddress): string => {\n let result = '';\n for (let index = 0; index < address.length; index += 1) {\n if (index > 0) result += '/';\n result += address[index].replaceAll('~', '~~').replaceAll('/', '~/');\n }\n return result;\n};\n\nexport const same = (a: AddressRef, b: AddressRef): boolean => {\n if (a.path !== b.path || a.address.length !== b.address.length) return false;\n for (let index = 0; index < a.address.length; index += 1) {\n profile.address.segmentCompared();\n if (a.address[index] !== b.address[index]) return false;\n }\n return true;\n};\n\nexport type { DocumentAddress } from './schema';\n","import type { DocumentAddress, DocumentSchema, ImpactTarget } from './schema';\n\nexport const address = (target: ImpactTarget<unknown>): DocumentAddress =>\n 'at' in target ? target.at : target.address;\n\nexport const id = (target: ImpactTarget<unknown>): string | undefined =>\n target.kind === 'collection' && 'id' in target ? target.id : undefined;\n\nexport const belongs = (target: ImpactTarget<unknown>, schema: DocumentSchema): boolean =>\n !('schema' in target) || target.schema === schema;\n\nexport const same = (left: ImpactTarget<unknown>, right: ImpactTarget<unknown>): boolean => {\n if (left.kind !== right.kind) return false;\n if ('schema' in left && 'schema' in right && left.schema !== right.schema) return false;\n const leftAddress = address(left);\n const rightAddress = address(right);\n if (leftAddress.length !== rightAddress.length) return false;\n for (let index = 0; index < leftAddress.length; index += 1)\n if (leftAddress[index] !== rightAddress[index]) return false;\n return left.kind !== 'collection' || id(left) === id(right);\n};\n\nexport const bucket = (target: ImpactTarget<unknown>): string | undefined => address(target)[0];\n","import type { DocumentOperationUnion } from '../operations';\nimport { profile } from '../profile';\n\nexport type CloneReason =\n 'initial' | 'canonical' | 'commit' | 'inverse' | 'reader' | 'replace' | 'journal';\n\nconst stablePayloads = new WeakSet<object>();\n\nconst markStablePayload = <T>(value: T): T => {\n if (Array.isArray(value) || isPlainObject(value)) stablePayloads.add(value as object);\n return value;\n};\n\nexport const isStablePayload = (value: unknown): boolean =>\n (Array.isArray(value) || isPlainObject(value)) && stablePayloads.has(value as object);\n\nexport const isPlainObject = (value: unknown): value is Record<string, unknown> => {\n if (value === null || typeof value !== 'object') return false;\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n};\n\nconst countCloneReason = (reason: CloneReason | undefined): void => {\n if (reason) profile.clone.node(reason);\n};\n\nexport const cloneValue = <T>(value: T, reason?: CloneReason): T => {\n profile.clone.call();\n countCloneReason(reason);\n if (Array.isArray(value)) {\n profile.clone.container();\n const result = new Array(value.length);\n for (let index = 0; index < value.length; index += 1)\n result[index] = cloneValue(value[index], reason);\n return (\n reason === 'commit' || reason === 'inverse'\n ? markStablePayload(Object.freeze(result))\n : result\n ) as T;\n }\n if (isPlainObject(value)) {\n profile.clone.container();\n const result: Record<string, unknown> = Object.create(Object.getPrototypeOf(value)) as Record<\n string,\n unknown\n >;\n for (const key in value) {\n if (Object.prototype.hasOwnProperty.call(value, key))\n result[key] = cloneValue(value[key], reason);\n }\n return (\n reason === 'commit' || reason === 'inverse'\n ? markStablePayload(Object.freeze(result))\n : result\n ) as T;\n }\n return value;\n};\n\n// Structural document values cross an ownership boundary by cloning. Atomic\n// values are shared because their schema contract treats them as immutable.\nexport const ownPayload = <T>(value: T, reason: CloneReason = 'canonical'): T =>\n Array.isArray(value) || isPlainObject(value) ? cloneValue(value, reason) : value;\n\n// The caller transfers structural ownership to the mutable canonical document.\n// Public commit/history boundaries use snapshotPayload instead.\nexport const transferPayload = <T>(value: T): T => {\n profile.batch.payloadTransferred();\n return value;\n};\nexport const snapshotPayload = <T>(value: T, reason: CloneReason = 'commit'): T => (\n profile.batch.payloadSnapshot(),\n ownPayload(value, reason)\n);\n\nexport const operationOwnsStructuralPayload = (operation: DocumentOperationUnion): boolean =>\n operation.type === 'variant.replace' ||\n operation.type === 'dict.replace' ||\n operation.type === 'entity.create' ||\n operation.type === 'list.insert' ||\n operation.type === 'list.replace' ||\n operation.type === 'tree.replace';\n\nexport const deepEqual = (left: unknown, right: unknown): boolean => {\n profile.clone.deepEqual();\n if (Object.is(left, right)) return true;\n if (Array.isArray(left) && Array.isArray(right)) {\n profile.clone.deepEqualContainer();\n if (left.length !== right.length) return false;\n for (let index = 0; index < left.length; index += 1)\n if (!deepEqual(left[index], right[index])) return false;\n return true;\n }\n if (isPlainObject(left) && isPlainObject(right)) {\n profile.clone.deepEqualContainer();\n const leftKeys = Object.keys(left);\n if (leftKeys.length !== Object.keys(right).length) return false;\n for (const key of leftKeys) {\n if (!Object.prototype.hasOwnProperty.call(right, key) || !deepEqual(left[key], right[key]))\n return false;\n }\n return true;\n }\n return false;\n};\n\nexport const sameStructuralValue = (left: unknown, right: unknown): boolean =>\n Object.is(left, right) ||\n ((Array.isArray(left) || isPlainObject(left)) && deepEqual(left, right));\n\nexport const isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n","import { object } from '../schema';\nimport type {\n DictNode,\n DocumentAddress,\n DocumentNode,\n DocumentSchema,\n DocumentValueOfNode,\n ImpactTarget,\n ListNode,\n MapNode,\n ObjectNode,\n ReadonlyDocument,\n SingleNode,\n TableNode,\n TreeNode,\n VariantNode,\n} from '../schema';\nimport { read as readAddress } from '../address';\nimport { cloneValue, isRecord } from '../value/ownership';\nimport { profile } from '../profile';\nimport type { DependencyTracker } from './dependency';\n\nexport type FieldReader<T> = { readonly get: () => T };\nexport type CollectionReader<TId, TEntry> = {\n readonly ids: () => readonly TId[];\n readonly has: (id: TId) => boolean;\n readonly get: (id: TId) => EntityReader<TEntry> | undefined;\n};\nexport type ListReader<T> = {\n readonly values: () => readonly T[];\n readonly length: () => number;\n readonly at: (index: number) => T | undefined;\n};\nexport type TreeReader<T> = {\n readonly rootId: () => string | undefined;\n readonly has: (id: string) => boolean;\n readonly value: (id: string) => T | undefined;\n readonly parent: (id: string) => string | undefined;\n readonly children: (id: string) => readonly string[];\n};\n\nexport type EntityReader<T> = T extends object\n ? { readonly [K in keyof T]: ReaderValue<T[K]> }\n : FieldReader<T>;\nexport type ReaderValue<T> = T extends readonly (infer TItem)[]\n ? ListReader<TItem>\n : T extends object\n ? EntityReader<T>\n : FieldReader<T>;\nexport type ReaderOfNode<TNode extends DocumentNode> = TNode extends {\n kind: 'field';\n}\n ? FieldReader<DocumentValueOfNode<TNode>>\n : TNode extends ObjectNode<infer TShape>\n ? { readonly [K in keyof TShape]: ReaderOfNode<TShape[K]> }\n : TNode extends VariantNode<string, infer TVariants>\n ? { readonly [K in keyof TVariants]: ReaderOfNode<TVariants[K]> }\n : TNode extends SingleNode<infer TValue>\n ? ReaderOfNode<TValue>\n : TNode extends TableNode<infer TValue>\n ? CollectionReader<string, DocumentValueOfNode<TValue>>\n : TNode extends MapNode<infer TValue>\n ? CollectionReader<string, DocumentValueOfNode<TValue>>\n : TNode extends DictNode<infer TKey, infer TValue>\n ? FieldReader<Readonly<Partial<Record<TKey, TValue>>>>\n : TNode extends ListNode<infer TItem>\n ? ListReader<TItem>\n : TNode extends TreeNode<infer TValue>\n ? TreeReader<TValue>\n : FieldReader<DocumentValueOfNode<TNode>>;\nexport type DocumentReader<TSchema extends DocumentSchema> = ReaderOfNode<\n ObjectNode<TSchema['shape']>\n>;\n\nexport type ReaderContext = {\n readonly root: () => unknown;\n readonly active: () => boolean;\n readonly dependencies?: DependencyTracker;\n};\n\nconst schemaRoot = (schema: DocumentSchema): DocumentNode => object(schema.shape);\n\nconst assertActive = (context: ReaderContext): void => {\n if (!context.active()) throw new Error('Document reader is no longer active.');\n};\n\nconst readAt = (context: ReaderContext, address: DocumentAddress): unknown => {\n assertActive(context);\n profile.reader.lookup();\n return readAddress(context.root(), address);\n};\n\nconst collectValue = (context: ReaderContext, address: DocumentAddress): void => {\n context.dependencies?.record({ kind: 'value', at: address });\n};\n\nconst collectCollection = (context: ReaderContext, address: DocumentAddress, id?: string): void => {\n const target: ImpactTarget<unknown> = {\n kind: 'collection',\n at: address,\n ...(id === undefined ? {} : { id }),\n };\n context.dependencies?.record(target);\n};\n\nexport const readerFor = (\n node: DocumentNode,\n context: ReaderContext,\n address: DocumentAddress = []\n): unknown => {\n if (node.kind === 'field')\n return {\n get: () => {\n collectValue(context, address);\n return readAt(context, address);\n },\n };\n if (node.kind === 'dict' || node.kind === 'record')\n return {\n get: () => {\n collectValue(context, address);\n profile.reader.structuralSnapshot();\n return cloneValue(readAt(context, address), 'reader');\n },\n };\n if (node.kind === 'list')\n return {\n values: () => {\n collectValue(context, address);\n const value = readAt(context, address);\n profile.reader.structuralSnapshot();\n return cloneValue(Array.isArray(value) ? value : [], 'reader');\n },\n length: () => {\n collectValue(context, address);\n const value = readAt(context, address);\n return Array.isArray(value) ? value.length : 0;\n },\n at: (index: number) => {\n collectValue(context, address);\n const value = readAt(context, address);\n profile.reader.structuralSnapshot();\n return cloneValue(Array.isArray(value) ? value[index] : undefined, 'reader');\n },\n };\n if (node.kind === 'tree')\n return {\n rootId: () => {\n collectValue(context, address);\n const value = readAt(context, address);\n return isRecord(value) && typeof value.rootId === 'string' ? value.rootId : undefined;\n },\n has: (id: string) => {\n collectValue(context, address);\n const value = readAt(context, address);\n return (\n isRecord(value) &&\n isRecord(value.nodes) &&\n Object.prototype.hasOwnProperty.call(value.nodes, id)\n );\n },\n value: (id: string) => {\n collectValue(context, address);\n const value = readAt(context, address);\n profile.reader.structuralSnapshot();\n return cloneValue(\n isRecord(value) && isRecord(value.nodes) && isRecord(value.nodes[id])\n ? value.nodes[id].value\n : undefined,\n 'reader'\n );\n },\n parent: (id: string) => {\n collectValue(context, address);\n const value = readAt(context, address);\n const entry = isRecord(value) && isRecord(value.nodes) ? value.nodes[id] : undefined;\n return isRecord(entry) && typeof entry.parentId === 'string' ? entry.parentId : undefined;\n },\n children: (id: string) => {\n collectValue(context, address);\n const value = readAt(context, address);\n const entry = isRecord(value) && isRecord(value.nodes) ? value.nodes[id] : undefined;\n return isRecord(entry) && Array.isArray(entry.children) ? [...entry.children] : [];\n },\n };\n if (node.kind === 'table' || node.kind === 'map') {\n let items: Map<string, unknown> | undefined;\n return {\n ids: () => {\n collectCollection(context, address);\n const value = readAt(context, address);\n const ids =\n node.kind === 'table' && isRecord(value) && Array.isArray(value.ids)\n ? [...value.ids]\n : isRecord(value)\n ? Object.keys(value)\n : [];\n profile.reader.collectionIds(ids.length);\n return ids;\n },\n has: (id: string) => {\n collectCollection(context, address, id);\n const value = readAt(context, address);\n const byId =\n node.kind === 'table' && isRecord(value) && isRecord(value.byId) ? value.byId : value;\n return isRecord(byId) && Object.prototype.hasOwnProperty.call(byId, id);\n },\n get: (id: string) => {\n collectCollection(context, address, id);\n const value = readAt(context, address);\n const byId =\n node.kind === 'table' && isRecord(value) && isRecord(value.byId) ? value.byId : value;\n if (!isRecord(byId) || !Object.prototype.hasOwnProperty.call(byId, id)) return undefined;\n const cached = items?.get(id);\n if (cached) return cached as EntityReader<unknown>;\n const reader = readerFor(node.value, context, [...address, id]);\n (items ??= new Map()).set(id, reader);\n return reader;\n },\n };\n }\n if (node.kind === 'single') return readerFor(node.value, context, address);\n if (node.kind === 'variant')\n return new Proxy(\n {},\n {\n get: (_target, property: string | symbol) => {\n if (typeof property === 'symbol') return undefined;\n const value = readAt(context, address);\n const tag =\n isRecord(value) && typeof value[node.tag] === 'string'\n ? String(value[node.tag])\n : undefined;\n const branch = tag ? node.variants[tag] : undefined;\n const child = branch?.shape[property];\n return child ? readerFor(child, context, [...address, property]) : undefined;\n },\n }\n );\n\n let children: Map<string, unknown> | undefined;\n return new Proxy(\n {},\n {\n get: (_target, property: string | symbol) => {\n if (typeof property === 'symbol') return undefined;\n const child = node.shape[property];\n if (!child) return undefined;\n const cached = children?.get(property);\n if (cached) return cached;\n const reader = readerFor(child, context, [...address, property]);\n (children ??= new Map()).set(property, reader);\n return reader;\n },\n }\n );\n};\n\nexport const documentReader = <TSchema extends DocumentSchema>(\n schema: TSchema,\n root: () => ReadonlyDocument<TSchema>,\n active: () => boolean,\n dependencies?: DependencyTracker\n): DocumentReader<TSchema> => {\n profile.reader.session();\n return readerFor(schemaRoot(schema), {\n root,\n active,\n dependencies,\n }) as DocumentReader<TSchema>;\n};\n","import type { DocumentAddress, DocumentSchema, ImpactTarget, ReadonlyDocument } from '../schema';\nimport type { AddressRef } from '../address';\nimport type { DocumentOperationUnion } from '../operations';\nimport type { DocumentImpact } from '../impact';\nimport type { DocumentReader } from '../access/reader';\nimport type { DocumentWriter } from '../access/writer';\nimport type { MutationIssue } from '../mutation/issue';\n\nexport type Unsubscribe = () => void;\nexport type CommitSource = 'local' | 'system' | 'history' | 'remote';\n\nexport class DocumentReentrancyError extends Error {\n constructor() {\n super('Document writes cannot be re-entered during an update or notification.');\n this.name = 'DocumentReentrancyError';\n }\n}\n\nexport class DocumentDisposedError extends Error {\n constructor() {\n super('Doxum runtime has been disposed.');\n this.name = 'DocumentDisposedError';\n }\n}\nexport type DocumentCommit<TSchema extends DocumentSchema> = {\n readonly revision: number;\n readonly kind: 'operations' | 'replace';\n readonly source: CommitSource;\n readonly operations: readonly DocumentOperationUnion<TSchema>[];\n readonly inverse: readonly DocumentOperationUnion<TSchema>[];\n readonly impact: DocumentImpact<TSchema>;\n};\nexport type DocumentDiagnostic = {\n readonly source: 'application';\n readonly code: string;\n readonly message: string;\n readonly address?: DocumentAddress;\n};\nexport type DocumentProblem = DocumentDiagnostic | MutationIssue;\nexport type ObserverError = {\n readonly phase: 'processor' | 'flush' | 'listener';\n readonly error: unknown;\n};\nexport type TransactionResult<TValue, TCommit> =\n | {\n readonly status: 'committed';\n readonly value: TValue;\n readonly commit: TCommit;\n readonly reports: readonly DocumentDiagnostic[];\n readonly observerErrors: readonly ObserverError[];\n }\n | {\n readonly status: 'unchanged';\n readonly value: TValue;\n readonly revision: number;\n readonly reports: readonly DocumentDiagnostic[];\n }\n | {\n readonly status: 'rejected';\n readonly issues: readonly DocumentProblem[];\n readonly revision: number;\n };\nexport type OperationResult<TCommit> =\n | {\n readonly status: 'committed';\n readonly commit: TCommit;\n readonly observerErrors: readonly ObserverError[];\n }\n | { readonly status: 'unchanged'; readonly revision: number }\n | {\n readonly status: 'rejected';\n readonly issues: readonly MutationIssue[];\n readonly revision: number;\n };\n\nexport type HistoryState = {\n readonly undoDepth: number;\n readonly redoDepth: number;\n};\nexport type LocalHistory<TCommit> = {\n current(): HistoryState;\n subscribe(listener: () => void): Unsubscribe;\n undo(): OperationResult<TCommit>;\n redo(): OperationResult<TCommit>;\n clear(): void;\n};\n\nexport type DocumentTransaction<TSchema extends DocumentSchema> = {\n readonly read: DocumentReader<TSchema>;\n readonly write: DocumentWriter<TSchema>;\n readonly reject: (issue: DocumentDiagnostic | readonly DocumentDiagnostic[]) => never;\n readonly report: (issue: DocumentDiagnostic) => void;\n};\nexport type CommitListener<TSchema extends DocumentSchema> = (\n commit: DocumentCommit<TSchema>\n) => void;\nexport type RuntimeProcessor<TSchema extends DocumentSchema> = {\n readonly process: (commit: DocumentCommit<TSchema>) => void;\n readonly flush: () => void;\n};\n\nexport type DocumentRuntime<TSchema extends DocumentSchema> = {\n readonly address: {\n readonly resolve: (address: DocumentAddress) => AddressRef | undefined;\n readonly read: (address: DocumentAddress) => unknown;\n readonly contains: (parent: DocumentAddress, child: DocumentAddress) => boolean;\n readonly overlaps: (left: DocumentAddress, right: DocumentAddress) => boolean;\n readonly debugKey: (address: DocumentAddress) => string;\n };\n revision(): number;\n update<TResult>(\n run: (transaction: DocumentTransaction<TSchema>) => TResult,\n options?: {\n readonly source?: Extract<CommitSource, 'local' | 'system'>;\n readonly history?: boolean;\n }\n ): TransactionResult<TResult, DocumentCommit<TSchema>>;\n apply(\n operations: unknown,\n options?: {\n readonly source?: Exclude<CommitSource, 'history'>;\n readonly history?: boolean;\n }\n ): OperationResult<DocumentCommit<TSchema>>;\n replace(\n document: ReadonlyDocument<TSchema>,\n options?: { readonly source?: Extract<CommitSource, 'system' | 'remote'> }\n ): OperationResult<DocumentCommit<TSchema>>;\n subscribe(listener: CommitListener<TSchema>): Unsubscribe;\n subscribe(\n target: ImpactTarget<unknown> | readonly [ImpactTarget<unknown>, ...ImpactTarget<unknown>[]],\n listener: CommitListener<TSchema>\n ): Unsubscribe;\n readonly history: LocalHistory<DocumentCommit<TSchema>>;\n dispose(): void;\n};\n","import type { DocumentSchema, ReadonlyDocument } from '../schema';\nimport type { DocumentReader } from '../access/reader';\nimport { documentReader } from '../access/reader';\nimport type { DependencyTracker } from '../access/dependency';\nimport { DocumentDisposedError } from './contract';\nimport type { DocumentRuntime } from './contract';\n\nexport type RuntimeAccessState<TSchema extends DocumentSchema> = {\n readonly schema: TSchema;\n document: ReadonlyDocument<TSchema>;\n disposed: boolean;\n};\n\nconst states = new WeakMap<object, RuntimeAccessState<DocumentSchema>>();\n\nexport const bindRuntimeAccess = <TSchema extends DocumentSchema>(\n runtime: DocumentRuntime<TSchema>,\n state: RuntimeAccessState<TSchema>\n): void => {\n states.set(runtime as object, state as RuntimeAccessState<DocumentSchema>);\n};\n\nexport const accessOf = <TSchema extends DocumentSchema>(\n runtime: DocumentRuntime<TSchema>\n): RuntimeAccessState<TSchema> => {\n const state = states.get(runtime as object);\n if (!state) throw new Error('Unknown Doxum runtime.');\n return state as RuntimeAccessState<TSchema>;\n};\n\nexport const schemaOf = <TSchema extends DocumentSchema>(\n runtime: DocumentRuntime<TSchema>\n): TSchema => accessOf(runtime).schema;\n\nexport const documentOf = <TSchema extends DocumentSchema>(\n runtime: DocumentRuntime<TSchema>\n): ReadonlyDocument<TSchema> => accessOf(runtime).document;\n\nexport const readWith = <TSchema extends DocumentSchema, TResult>(\n runtime: DocumentRuntime<TSchema>,\n run: (read: DocumentReader<TSchema>) => TResult,\n dependencies?: DependencyTracker\n): TResult => {\n const state = accessOf(runtime);\n if (state.disposed) throw new DocumentDisposedError();\n let active = true;\n const reader = documentReader(\n state.schema,\n () => state.document,\n () => active,\n dependencies\n );\n try {\n return run(reader);\n } finally {\n // Readers are transaction-scoped; retaining one cannot expose later\n // mutable canonical state outside the coordinating operation.\n active = false;\n }\n};\n","import type { ImpactTarget } from '../schema';\nimport * as impactTarget from '../impact-target';\n\nexport type DependencyTracker = {\n readonly record: (target: ImpactTarget<unknown>) => void;\n readonly clear: () => void;\n readonly size: () => number;\n readonly some: (test: (target: ImpactTarget<unknown>) => boolean) => boolean;\n readonly snapshot: () => readonly ImpactTarget<unknown>[];\n};\n\nexport const createDependencyTracker = (): DependencyTracker => {\n const targets: ImpactTarget<unknown>[] = [];\n return {\n record: value => {\n if (!targets.some(entry => impactTarget.same(entry, value))) targets.push(value);\n },\n clear: () => {\n targets.length = 0;\n },\n size: () => targets.length,\n some: test => targets.some(test),\n snapshot: () => Object.freeze(targets.slice()),\n };\n};\n"],"mappings":";;;;;;;;;;;;;AAsOA,MAAM,QAAgC,UAAgB,OAAO,OAAO,MAAM;AAC1E,MAAa,cAA+B,KAAK,EAAE,MAAM,SAAS,CAAC;AACnE,MAAa,YAAoC,UAC/C,KAAK;CAAE,GAAG;CAAO,UAAU;CAAM,CAAoB;AACvD,MAAa,UAAiC,UAC5C,KAAK;CAAE,MAAM;CAAU;CAAO,CAAC;AACjC,MAAa,WACX,KACA,aACsB,KAAK;CAAE,MAAM;CAAW;CAAK;CAAU,CAAC;AAChE,MAAa,UACX,UACkB,KAAK;CAAE,MAAM;CAAU;CAAO,CAAC;AACnD,MAAa,SACX,UACiB,KAAK;CAAE,MAAM;CAAS;CAAO,CAAC;AACjD,MAAa,OACX,UACe,KAAK;CAAE,MAAM;CAAO;CAAO,CAAC;AAC7C,MAAa,eACX,KAAK,EAAE,MAAM,UAAU,CAAC;AAC1B,MAAa,aACX,KAAK,EAAE,MAAM,QAAQ,CAAC;AACxB,MAAa,QAAe,YACzB;CAAE,MAAM;CAAQ,OAAO,OAAO;CAAO;AACxC,MAAa,aAAiD,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEpF,MAAM,aAAa,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