doxum 0.1.28 → 0.1.29

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.
@@ -1 +0,0 @@
1
- {"version":3,"file":"driver-BL91gn7_.cjs","names":["isRecord","isPlainObject","issue.fail","tree.validNode"],"sources":["../core/src/tree/topology.ts","../core/src/mutation/issue.ts","../core/src/address/index.ts","../core/src/mutation/changes.ts","../core/src/runtime/context.ts","../core/src/runtime/driver.ts"],"sourcesContent":["import { isRecord } from '@/value/record';\nexport type MutableTreeNode = { parentId?: string; children: string[]; value?: unknown };\nexport type MutableTree = { rootId?: string; nodes: Record<string, MutableTreeNode> };\nconst node = (tree: MutableTree, id: string) =>\n Object.hasOwn(tree.nodes, id) ? tree.nodes[id] : undefined;\nexport const is = (value: unknown): value is MutableTree =>\n isRecord(value) && isRecord(value.nodes);\n\nexport const validNode = (value: unknown): value is MutableTreeNode => {\n if (!isRecord(value) || !Array.isArray(value.children)) return false;\n if (value.parentId !== undefined && typeof value.parentId !== 'string') return false;\n const children = new Set<string>();\n for (const id of value.children) {\n if (typeof id !== 'string' || children.has(id)) return false;\n children.add(id);\n }\n return true;\n};\n\nexport const contains = (tree: MutableTree, id: string): boolean => Object.hasOwn(tree.nodes, id);\n\nexport const parent = (tree: MutableTree, id: string): string | undefined =>\n node(tree, id)?.parentId;\n\nexport const children = (tree: MutableTree, id: string): readonly string[] | undefined =>\n node(tree, id)?.children;\n\nexport const validate = (value: unknown): value is MutableTree => {\n if (!is(value)) return false;\n const ids = Object.keys(value.nodes);\n if (ids.length === 0) return value.rootId === undefined;\n if (typeof value.rootId !== 'string' || !Object.hasOwn(value.nodes, value.rootId)) return false;\n\n for (const id of ids) {\n const entry = value.nodes[id];\n if (!validNode(entry)) return false;\n if (id === value.rootId) {\n if (entry.parentId !== undefined) return false;\n } else if (entry.parentId === undefined || !Object.hasOwn(value.nodes, entry.parentId))\n return false;\n for (const child of entry.children) {\n const childNode = value.nodes[child];\n if (!childNode || childNode.parentId !== id) return false;\n }\n }\n\n const seen = new Set<string>();\n const stack = [value.rootId];\n while (stack.length) {\n const id = stack.pop() as string;\n if (seen.has(id)) return false;\n seen.add(id);\n const entry = value.nodes[id];\n if (!entry) return false;\n for (const child of entry.children) stack.push(child);\n }\n return seen.size === ids.length;\n};\n\nexport type TreePosition = { readonly parentId?: string; readonly index?: number };\n","import type { DocumentAddress } from '@/schema/model';\nimport type { ParseIssue } from '@/schema/value';\n\nexport type MutationIssueCode =\n | 'invalid-address'\n | 'invalid-value'\n | 'invalid-key'\n | 'invalid-changes'\n | 'baseline-mismatch'\n | 'required-field'\n | 'invalid-anchor'\n | 'duplicate-entity'\n | 'missing-entity'\n | 'invalid-collection'\n | 'invalid-list-keys'\n | 'invalid-list-key'\n | 'duplicate-list-item'\n | 'missing-list-item'\n | 'invalid-tree'\n | 'duplicate-tree-node'\n | 'missing-tree-parent'\n | 'invalid-tree-index'\n | 'missing-tree-node'\n | 'tree-cycle';\nexport type MutationIssue = {\n readonly source: 'mutation';\n readonly code: MutationIssueCode;\n readonly address: DocumentAddress;\n readonly message: string;\n};\nexport const at = (\n address: DocumentAddress,\n code: MutationIssueCode,\n message: string\n): MutationIssue =>\n Object.freeze({ source: 'mutation', code, address: Object.freeze([...address]), message });\nexport class MutationRejected extends Error {\n constructor(readonly issue: MutationIssue) {\n super(issue.message);\n }\n}\nexport const fail = (address: DocumentAddress, code: MutationIssueCode, message: string): never => {\n throw new MutationRejected(at(address, code, message));\n};\n\nexport const invalidValue = (issue: ParseIssue, address = issue.address): never =>\n fail(address, issue.code === 'missing-validator' ? 'invalid-value' : issue.code, issue.message);\n","import type { DocumentAddress } from '@/schema/model';\n\ntype AddressIndexNode<T> = {\n readonly children: Map<string, AddressIndexNode<T>>;\n readonly values: Set<T>;\n};\n\nexport class AddressIndex<T> {\n private readonly root: AddressIndexNode<T> = { children: new Map(), values: new Set() };\n\n add(address: DocumentAddress, value: T, member?: string): void {\n let node = this.root;\n for (let index = 0; index < address.length + (member === undefined ? 0 : 1); index++) {\n const segment = index < address.length ? address[index] : member!;\n let child = node.children.get(segment);\n if (!child) {\n child = { children: new Map(), values: new Set() };\n node.children.set(segment, child);\n }\n node = child;\n }\n node.values.add(value);\n }\n\n delete(address: DocumentAddress, value: T, member?: string): void {\n const parents: AddressIndexNode<T>[] = [];\n let node = this.root;\n const segments = member === undefined ? address : [...address, member];\n for (const segment of segments) {\n const child = node.children.get(segment);\n if (!child) return;\n parents.push(node);\n node = child;\n }\n node.values.delete(value);\n for (\n let index = segments.length - 1;\n index >= 0 && !node.values.size && !node.children.size;\n index--\n ) {\n node = parents[index];\n node.children.delete(segments[index]);\n }\n }\n\n exact(address: DocumentAddress): ReadonlySet<T> | undefined {\n let node = this.root;\n for (const segment of address) {\n const child = node.children.get(segment);\n if (!child) return undefined;\n node = child;\n }\n return node.values;\n }\n\n hasAncestor(address: DocumentAddress, strict = false): boolean {\n let node = this.root;\n for (let index = 0; index < address.length; index++) {\n if (node.values.size) return true;\n const child = node.children.get(address[index]);\n if (!child) return false;\n node = child;\n }\n return !strict && node.values.size > 0;\n }\n\n someAncestor(address: DocumentAddress, predicate: (value: T) => boolean): boolean {\n let node = this.root;\n for (let index = 0; ; index++) {\n for (const value of node.values) if (predicate(value)) return true;\n if (index === address.length) return false;\n const child = node.children.get(address[index]);\n if (!child) return false;\n node = child;\n }\n }\n\n overlaps(address: DocumentAddress): boolean {\n let node = this.root;\n for (const segment of address) {\n if (node.values.size) return true;\n const child = node.children.get(segment);\n if (!child) return false;\n node = child;\n }\n return node.values.size > 0 || node.children.size > 0;\n }\n\n hasDescendant(address: DocumentAddress): boolean {\n let node = this.root;\n for (const segment of address) {\n const child = node.children.get(segment);\n if (!child) return false;\n node = child;\n }\n return node.values.size > 0 || node.children.size > 0;\n }\n\n query(\n visit: (value: T) => void,\n relation: 'overlap' | 'ancestors' | 'descendants' = 'overlap'\n ): (address: DocumentAddress, members?: readonly { readonly key: string }[]) => void {\n const visited = new Set<AddressIndexNode<T>>();\n const subtrees = new Set<AddressIndexNode<T>>();\n const values = (node: AddressIndexNode<T>) => {\n if (visited.has(node)) return;\n visited.add(node);\n node.values.forEach(visit);\n };\n const descend = (current: AddressIndexNode<T>): void => {\n if (subtrees.has(current)) return;\n subtrees.add(current);\n values(current);\n current.children.forEach(descend);\n };\n const terminal = (node: AddressIndexNode<T>) =>\n relation === 'ancestors' ? values(node) : descend(node);\n return (address, members) => {\n let node = this.root;\n for (const segment of address) {\n if (subtrees.has(node)) return;\n if (relation !== 'descendants') values(node);\n const child = node.children.get(segment);\n if (!child) return;\n node = child;\n }\n if (!members) terminal(node);\n else {\n if (relation !== 'descendants') values(node);\n for (const member of members) {\n const child = node.children.get(member.key);\n if (child) terminal(child);\n }\n }\n };\n }\n\n clear(): void {\n this.root.values.clear();\n this.root.children.clear();\n }\n}\n","import type { Change, ChangeSet, MemberChange, ValueTransition } from '@/changes';\nimport { AddressIndex } from '@/address/index';\nimport { isPlainObject } from '@/value/record';\nimport * as issue from './issue';\nimport * as tree from '@/tree/topology';\n\nconst validated = new WeakSet<ChangeSet>();\n\nconst compareChanges = (a: Change, b: Change): number => {\n if (a.kind === 'reset' || b.kind === 'reset')\n return a.kind === b.kind ? 0 : a.kind === 'reset' ? -1 : 1;\n const length = Math.min(a.at.length, b.at.length);\n for (let i = 0; i < length; i++) if (a.at[i] !== b.at[i]) return lexical(a.at[i], b.at[i]);\n return a.at.length - b.at.length || lexical(a.kind, b.kind);\n};\n\nconst publication = (changes: Change[]): ChangeSet => {\n const result = { changes };\n validated.add(result);\n return result;\n};\n\n/** Register complete recorder groups; unknown input is validated separately. */\nexport const sealChanges = (changes: Change[]): ChangeSet => {\n changes.sort(compareChanges);\n return publication(changes);\n};\n\nconst keys = (value: Record<string, unknown>, expected: readonly string[]) =>\n Object.keys(value).every(key => expected.includes(key));\nconst strings = (value: unknown): value is readonly string[] => {\n if (!Array.isArray(value)) return false;\n for (const item of value) if (typeof item !== 'string') return false;\n return true;\n};\nconst order = (value: unknown): value is readonly string[] =>\n strings(value) && new Set(value).size === value.length;\nconst transition = (\n value: unknown,\n key: 'key' | 'id'\n): value is ValueTransition & Record<string, unknown> => {\n if (!isPlainObject(value) || typeof value[key] !== 'string') return false;\n if (value.kind === 'added')\n return keys(value, ['kind', key, 'after']) && Object.hasOwn(value, 'after');\n if (value.kind === 'removed')\n return keys(value, ['kind', key, 'before']) && Object.hasOwn(value, 'before');\n return (\n value.kind === 'updated' &&\n keys(value, ['kind', key, 'before', 'after']) &&\n Object.hasOwn(value, 'before') &&\n Object.hasOwn(value, 'after')\n );\n};\nconst lexical = (a: string, b: string) => (a < b ? -1 : a === b ? 0 : 1);\n\n/** The sole unknown ChangeSet boundary, including normalized logical-address conflicts. */\nexport const decodeChanges = (input: unknown): ChangeSet => {\n if (typeof input === 'object' && input !== null && validated.has(input as ChangeSet))\n return input as ChangeSet;\n if (!isPlainObject(input) || !keys(input, ['changes']) || !Array.isArray(input.changes))\n return issue.fail([], 'invalid-changes', 'Expected a ChangeSet.');\n const result: Change[] = [];\n for (const entry of input.changes) {\n if (!isPlainObject(entry)) return issue.fail([], 'invalid-changes', 'Expected a change.');\n if (entry.kind === 'reset') {\n if (\n input.changes.length !== 1 ||\n !keys(entry, ['kind', 'before', 'after']) ||\n !Object.hasOwn(entry, 'before') ||\n !Object.hasOwn(entry, 'after')\n )\n return issue.fail(\n [],\n 'invalid-changes',\n 'A reset must be the only change and contain both values.'\n );\n return sealChanges([{ kind: 'reset', before: entry.before, after: entry.after }]);\n }\n if (!strings(entry.at))\n return issue.fail([], 'invalid-changes', 'Change addresses must contain strings.');\n const at = entry.at;\n if (\n entry.kind === 'members' &&\n keys(entry, ['kind', 'at', 'members', 'order']) &&\n Array.isArray(entry.members) &&\n (entry.members.length || Object.hasOwn(entry, 'order'))\n ) {\n const seen = new Set<string>();\n const members: MemberChange[] = [];\n for (const member of entry.members) {\n if (!transition(member, 'key') || typeof member.key !== 'string' || seen.has(member.key))\n return issue.fail(at, 'invalid-changes', 'Malformed or duplicate member transition.');\n seen.add(member.key);\n members.push({ ...member, key: member.key });\n }\n const change: Extract<Change, { kind: 'members' }> = {\n kind: 'members',\n at,\n members: members.sort((a, b) => lexical(a.key, b.key)),\n };\n if (Object.hasOwn(entry, 'order')) {\n if (\n !isPlainObject(entry.order) ||\n !keys(entry.order, ['before', 'after']) ||\n !order(entry.order.before) ||\n !order(entry.order.after)\n )\n return issue.fail(at, 'invalid-changes', 'Malformed container order.');\n result.push({ ...change, order: { before: entry.order.before, after: entry.order.after } });\n } else result.push(change);\n } else if (\n entry.kind === 'tree' &&\n keys(entry, ['kind', 'at', 'before', 'after', 'nodes']) &&\n (entry.before === null || typeof entry.before === 'string') &&\n (entry.after === null || typeof entry.after === 'string') &&\n Array.isArray(entry.nodes)\n ) {\n const seen = new Set<string>();\n for (const node of entry.nodes) {\n if (\n !transition(node, 'id') ||\n typeof node.id !== 'string' ||\n seen.has(node.id) ||\n (node.kind !== 'added' && !tree.validNode(node.before)) ||\n (node.kind !== 'removed' && !tree.validNode(node.after))\n )\n return issue.fail(at, 'invalid-changes', 'Malformed or duplicate tree transition.');\n seen.add(node.id);\n }\n const nodes = entry.nodes as Extract<Change, { kind: 'tree' }>['nodes'];\n result.push({\n kind: 'tree',\n at,\n before: entry.before,\n after: entry.after,\n nodes: [...nodes].sort((a, b) => lexical(a.id, b.id)),\n });\n } else return issue.fail(at, 'invalid-changes', 'Unknown or malformed change.');\n }\n return publication(normalizeChanges(result));\n};\n\nconst normalizeChanges = (changes: Change[]): Change[] => {\n const sorted = changes.sort(compareChanges);\n const groups = new AddressIndex<true>();\n const replacements = new AddressIndex<true>();\n const orders = new AddressIndex<true>();\n for (const change of sorted) {\n if (change.kind === 'reset') continue;\n if (change.kind === 'members') {\n if (groups.exact(change.at)?.size)\n return issue.fail(change.at, 'invalid-changes', 'Duplicate member group.');\n groups.add(change.at, true);\n if (change.order) {\n if (replacements.hasAncestor(change.at))\n return issue.fail(change.at, 'invalid-changes', 'Overlapping container order.');\n orders.add(change.at, true);\n }\n for (const member of change.members) {\n const at = change.at.concat(member.key);\n if (replacements.overlaps(at) || orders.hasDescendant(at))\n return issue.fail(at, 'invalid-changes', 'Overlapping member transitions.');\n replacements.add(at, true);\n }\n } else if (change.kind === 'tree') {\n if (replacements.overlaps(change.at) || orders.hasDescendant(change.at))\n return issue.fail(change.at, 'invalid-changes', 'Overlapping tree transitions.');\n replacements.add(change.at, true);\n }\n }\n return sorted;\n};\n\nexport const changeCount = (changes: ChangeSet): number => {\n let count = 0;\n for (const change of changes.changes)\n count +=\n change.kind === 'members'\n ? change.members.length + (change.order ? 1 : 0)\n : change.kind === 'tree'\n ? 1 + change.nodes.length\n : 1;\n return count;\n};\n","import type { Infer, ObjectSchema, RootNodeOf } from '@/schema/model';\nimport type { DocumentRuntime } from './contract';\nimport type { RuntimeWriteDriver } from './driver';\nimport type { NotificationCenter } from './notification';\n\nexport type RuntimeState<TSchema extends ObjectSchema<object>> = {\n readonly schema: RootNodeOf<TSchema>;\n document: Infer<TSchema>;\n disposed: boolean;\n projectionLocks: number;\n};\n\nexport type RuntimeContext<TSchema extends ObjectSchema<object>> = {\n readonly state: RuntimeState<TSchema>;\n readonly owner: DocumentRuntime<TSchema>;\n readonly notifications: NotificationCenter<TSchema>;\n driver: RuntimeWriteDriver | undefined;\n bypassDepth: number;\n};\n\nconst contexts = new WeakMap<object, RuntimeContext<ObjectSchema<object>>>();\n\nexport const bindContext = <TSchema extends ObjectSchema<object>>(\n subject: object,\n context: RuntimeContext<TSchema>\n): void => {\n contexts.set(subject, context as unknown as RuntimeContext<ObjectSchema<object>>);\n};\n\nexport function contextOf<TSchema extends ObjectSchema<object>>(\n subject: object,\n required?: true\n): RuntimeContext<TSchema>;\nexport function contextOf<TSchema extends ObjectSchema<object>>(\n subject: object,\n required: false\n): RuntimeContext<TSchema> | undefined;\nexport function contextOf<TSchema extends ObjectSchema<object>>(\n subject: object,\n required = true\n): RuntimeContext<TSchema> | undefined {\n const context = contexts.get(subject);\n if (!context && required) throw new Error('Unknown Doxum runtime.');\n return context as unknown as RuntimeContext<TSchema> | undefined;\n}\n","import type { CommitSource, DocumentRuntime } from './contract';\nimport type { ObjectSchema } from '@/schema/model';\nimport { contextOf } from './context';\n\nexport type RuntimeWriteIntent =\n | { readonly kind: 'update'; readonly source: Extract<CommitSource, 'local' | 'system'> }\n | { readonly kind: 'apply'; readonly source: CommitSource }\n | { readonly kind: 'replace'; readonly source: Extract<CommitSource, 'system' | 'remote'> };\n\nexport type RuntimeWriteDriver = {\n readonly assertWritable: (intent: RuntimeWriteIntent) => void;\n};\n\nexport type RuntimeWriteDriverLease = {\n readonly run: <TResult>(run: () => TResult) => TResult;\n readonly dispose: () => void;\n};\n\nexport const assertRuntimeWritable = (runtime: object, intent: RuntimeWriteIntent): void => {\n const context = contextOf(runtime);\n if (context.bypassDepth === 0) context.driver?.assertWritable(intent);\n};\n\nexport const installRuntimeWriteDriver = <TSchema extends ObjectSchema<object>>(\n runtime: DocumentRuntime<TSchema>,\n driver: RuntimeWriteDriver\n): RuntimeWriteDriverLease => {\n const context = contextOf(runtime);\n if (context.driver) throw new Error('Doxum runtime already has a write driver.');\n context.driver = driver;\n let active = true;\n return Object.freeze({\n run: <TResult>(run: () => TResult): TResult => {\n if (!active) throw new Error('Doxum runtime write driver is no longer active.');\n context.bypassDepth += 1;\n try {\n return run();\n } finally {\n context.bypassDepth -= 1;\n }\n },\n dispose: (): void => {\n if (!active) return;\n active = false;\n if (context.driver === driver) context.driver = undefined;\n },\n });\n};\n"],"mappings":";;AAGA,MAAM,QAAQ,MAAmB,OAC/B,OAAO,OAAO,KAAK,OAAO,GAAG,GAAG,KAAK,MAAM,MAAM,KAAA;AACnD,MAAa,MAAM,UACjBA,eAAAA,SAAS,MAAM,IAAIA,eAAAA,SAAS,MAAM,MAAM;AAE1C,MAAa,aAAa,UAA6C;AACrE,KAAI,CAACA,eAAAA,SAAS,MAAM,IAAI,CAAC,MAAM,QA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B,OAAI,CAAC,OAAQ;AACb,YAAS;AACT,OAAI,QAAQ,WAAW,OAAQ,SAAQ,SAAS,KAAA;;EAEnD,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"transform-B4T3AcJr.js","names":[],"sources":["../core/src/profile.ts","../core/src/projection/definition.ts","../core/src/projection/collection/view.ts","../core/src/projection/dependency.ts","../core/src/projection/collection/change.ts","../core/src/projection/contract.ts","../core/src/projection/graph/scheduler.ts","../core/src/projection/keyed/relation.ts","../core/src/projection/keyed/dependency.ts","../core/src/projection/keyed/transform.ts"],"sourcesContent":["const counters = () => ({\n projection: {\n sourceEvents: 0,\n scheduledNodes: 0,\n processedNodes: 0,\n touchedKeys: 0,\n changedKeys: 0,\n publishedNodes: 0,\n flushes: 0,\n },\n copy: { structures: 0, treeNodes: 0, shallowRecordItems: 0 },\n equality: { calls: 0, containers: 0 },\n recorder: {\n facts: 0,\n groups: 0,\n transitions: 0,\n absorbed: 0,\n orderSnapshots: 0,\n orderCaptures: 0,\n orderItems: 0,\n publishedOrderItems: 0,\n treeNodes: 0,\n sealed: 0,\n indexedGroups: 0,\n },\n access: { scopes: 0, proxies: 0, snapshots: 0, addresses: 0, resolutions: 0 },\n address: {\n schemaSteps: 0,\n documentSteps: 0,\n prefixComparisons: 0,\n segmentsCompared: 0,\n listIndexes: 0,\n listItems: 0,\n },\n impact: { affectsChecks: 0, indexes: 0 },\n dependency: { comparisons: 0, segmentsCompared: 0 },\n collectionIndex: { nodes: 0, builds: 0, builtItems: 0 },\n collectionView: { mappedItems: 0, idsScanned: 0, arraysCopied: 0 },\n materialized: { updated: 0, rebuilt: 0, notifications: 0 },\n});\ntype Counters = ReturnType<typeof counters>;\ntype DeepReadonly<T> = { readonly [K in keyof T]: T[K] extends object ? DeepReadonly<T[K]> : T[K] };\nexport type ProfileSnapshot = DeepReadonly<Counters>;\nlet active: Counters | undefined;\nconst freeze = <T extends object>(value: T): DeepReadonly<T> => {\n Object.values(value).forEach(child => {\n if (child && typeof child === 'object') freeze(child);\n });\n return Object.freeze(value) as DeepReadonly<T>;\n};\nexport const profile = {\n projection: (key: keyof Counters['projection'], amount = 1) => {\n if (active) active.projection[key] += amount;\n },\n recorder: (key: keyof Counters['recorder'], amount = 1) => {\n if (active) active.recorder[key] += amount;\n },\n access: (key: keyof Counters['access']) => {\n if (active) active.access[key]++;\n },\n copy: {\n structure: () => {\n if (active) active.copy.structures++;\n },\n treeNode: () => {\n if (active) active.copy.treeNodes++;\n },\n shallowRecord: (items: number) => {\n if (active) active.copy.shallowRecordItems += items;\n },\n },\n equality: {\n call: () => {\n if (active) active.equality.calls++;\n },\n container: () => {\n if (active) active.equality.containers++;\n },\n },\n address: {\n listIndex: (items: number) => {\n if (active) {\n active.address.listIndexes++;\n active.address.listItems += items;\n }\n },\n schemaStep: () => {\n if (active) active.address.schemaSteps++;\n },\n documentStep: () => {\n if (active) active.address.documentSteps++;\n },\n prefixComparison: () => {\n if (active) active.address.prefixComparisons++;\n },\n segmentCompared: () => {\n if (active) active.address.segmentsCompared++;\n },\n },\n impact: {\n index: () => {\n if (active) active.impact.indexes++;\n },\n affects: () => {\n if (active) active.impact.affectsChecks++;\n },\n },\n dependency: {\n comparison: () => {\n if (active) active.dependency.comparisons++;\n },\n segmentCompared: () => {\n if (active) active.dependency.segmentsCompared++;\n },\n },\n collectionIndex: {\n node: () => {\n if (active) active.collectionIndex.nodes++;\n },\n build: (items: number) => {\n if (active) {\n active.collectionIndex.builds++;\n active.collectionIndex.builtItems += items;\n }\n },\n },\n collectionView: {\n mapped: () => {\n if (active) active.collectionView.mappedItems++;\n },\n idsScanned: (amount = 1) => {\n if (active) active.collectionView.idsScanned += amount;\n },\n arrayCopied: () => {\n if (active) active.collectionView.arraysCopied++;\n },\n },\n materialized: {\n updated: () => {\n if (active) active.materialized.updated++;\n },\n rebuilt: () => {\n if (active) active.materialized.rebuilt++;\n },\n notification: () => {\n if (active) active.materialized.notifications++;\n },\n },\n};\nexport type ProfileSession = { snapshot(): ProfileSnapshot; stop(): ProfileSnapshot };\nexport const startProfile = (): ProfileSession => {\n if (active) throw new Error('A document profile session is already active.');\n const value = counters();\n active = value;\n const snapshot = () => freeze(structuredClone(value));\n return {\n snapshot,\n stop: () => {\n if (active === value) active = undefined;\n return snapshot();\n },\n };\n};\nexport const measureProfile = <T>(run: () => T): { value: T; profile: ProfileSnapshot } => {\n const session = startProfile();\n try {\n return { value: run(), profile: session.stop() };\n } finally {\n session.stop();\n }\n};\n","import type { ReadonlyDocument } from '@/runtime/contract';\nimport type { ObjectSchema } from '@/schema/model';\nimport type { CollectionSelector, ValueSelector } from '@/schema/path';\nimport type {\n CollectionChange,\n CollectionDraft,\n CollectionRead,\n ExternalCollectionSource,\n ExternalValueSource,\n SourceContext,\n} from './contract';\nimport type { Readable } from '@/readable';\n\ndeclare const projectionDefinition: unique symbol;\ndeclare const keyedProjection: unique symbol;\ndeclare const writableInput: unique symbol;\ndeclare const writableCollectionInput: unique symbol;\n\n/** A lazy output reference with no materialized Runtime state. */\nexport type Projection<T> = {\n readonly [projectionDefinition]: T;\n};\n\n/** A projection whose output is a keyed collection with per-key change semantics. */\nexport type KeyedProjection<K extends string, V> = Projection<ReadonlyMap<K, V>> & {\n readonly [keyedProjection]: { readonly key: K; readonly value: V };\n};\n\n/** A writable source projection. */\nexport type Input<T> = Projection<T> & { readonly [writableInput]: true };\n\n/** A writable keyed collection source projection. */\nexport type CollectionInput<K extends string, V> = KeyedProjection<K, V> & {\n readonly [writableCollectionInput]: { readonly key: K; readonly value: V };\n};\n\nexport type CollectionInputDraft<K extends string, V> = {\n get(key: K): V | undefined;\n has(key: K): boolean;\n set(key: K, value: V): void;\n remove(key: K): void;\n};\n\nexport type ProjectionChange<P> =\n P extends KeyedProjection<infer K, infer V> ? CollectionChange<K, V> : undefined;\n\nexport type Equality = (a: unknown, b: unknown) => boolean;\n\nexport type OutputDefinition =\n | {\n readonly kind: 'value';\n readonly equality: Equality;\n readonly path?: readonly string[];\n }\n | {\n readonly kind: 'collection';\n readonly equality: Equality;\n readonly path?: readonly string[];\n };\n\nexport type ValueOutputEvaluation = {\n readonly kind: 'value';\n readonly previous: unknown;\n readonly next: () => unknown;\n readonly output: { set(value: unknown): void };\n};\n\nexport type CollectionOutputEvaluation = {\n readonly kind: 'collection';\n readonly previous: CollectionRead<string, unknown>;\n readonly next: CollectionRead<string, unknown>;\n readonly output: CollectionDraft<string, unknown>;\n};\n\nexport type OutputEvaluation = ValueOutputEvaluation | CollectionOutputEvaluation;\n\nexport type ProcessorEvaluation = {\n readonly reset: boolean;\n readonly cause: unknown;\n readonly sources: readonly SourceContext[];\n readonly outputs: readonly OutputEvaluation[];\n};\n\nexport type ProcessorInstance = {\n evaluate(input: ProcessorEvaluation): void;\n release?(): void;\n};\n\nexport type SourceAdapter =\n | {\n readonly kind: 'value-input';\n readonly initial: unknown;\n readonly equality: Equality;\n }\n | {\n readonly kind: 'collection-input';\n readonly initial: ReadonlyMap<string, unknown>;\n readonly equality: Equality;\n }\n | {\n readonly kind: 'readable';\n readonly readable: Readable<unknown>;\n readonly equality: Equality;\n }\n | {\n readonly kind: 'external-value';\n readonly source: ExternalValueSource<unknown>;\n readonly equality: Equality;\n }\n | {\n readonly kind: 'external-collection';\n readonly source: ExternalCollectionSource<string, unknown>;\n }\n | {\n readonly kind: 'document';\n readonly document: ReadonlyDocument<ObjectSchema<object>>;\n readonly selector: ValueSelector | CollectionSelector;\n };\n\nexport type SourceDefinition = {\n readonly kind: 'source';\n readonly source: SourceAdapter;\n readonly output: OutputDefinition;\n owner?: object;\n materialized?: true;\n};\n\nexport type ProcessorDefinition = {\n readonly kind: 'processor';\n readonly dependencies: readonly Projection<unknown>[];\n readonly outputs: readonly OutputDefinition[];\n readonly create: () => ProcessorInstance;\n readonly name?: string;\n owner?: object;\n materialized?: true;\n};\n\nexport type ProducerDefinition = SourceDefinition | ProcessorDefinition;\n\nexport type ProjectionRef = {\n readonly producer: ProducerDefinition;\n readonly output: number;\n};\n\nconst projections = new WeakMap<object, ProjectionRef>();\n\nconst defineRef = <T>(producer: ProducerDefinition, output: number): Projection<T> => {\n const handle = Object.freeze({}) as Projection<T>;\n projections.set(handle, Object.freeze({ producer, output }));\n return handle;\n};\n\nexport const projectionRef = (projection: Projection<unknown>): ProjectionRef => {\n const ref = projections.get(projection);\n if (!ref) throw new TypeError('Unknown projection definition.');\n return ref;\n};\n\nexport const producerOf = (projection: Projection<unknown>): ProducerDefinition =>\n projectionRef(projection).producer;\n\n/** Resolves the immutable output description owned by a projection definition. */\nexport const outputDefinitionOf = (projection: Projection<unknown>): OutputDefinition => {\n const ref = projectionRef(projection);\n const producer = ref.producer;\n const output = producer.kind === 'source' ? producer.output : producer.outputs[ref.output];\n if (!output) throw new TypeError('Projection output does not exist.');\n return output;\n};\n\nexport const isProjection = (value: unknown): value is Projection<unknown> =>\n value !== null && typeof value === 'object' && projections.has(value);\n\nexport const ownProjections = (\n projections: readonly Projection<unknown>[],\n owner: object\n): void => {\n const producers = new Set(projections.map(producerOf));\n for (const producer of producers) {\n if (producer.owner !== undefined && producer.owner !== owner)\n throw new TypeError('Projection producer already belongs to another scope.');\n if (producer.owner === undefined && producer.materialized)\n throw new TypeError('A materialized root projection cannot become scope-owned.');\n if (producer.kind !== 'processor') continue;\n for (const dependency of producer.dependencies) {\n const dependencyOwner = producerOf(dependency).owner;\n if (dependencyOwner !== undefined && dependencyOwner !== owner)\n throw new TypeError('A scope cannot depend on another scope.');\n }\n }\n for (const producer of producers) producer.owner = owner;\n};\n\nconst freezeOutput = (output: OutputDefinition): OutputDefinition =>\n Object.freeze({\n kind: output.kind,\n equality: output.equality,\n ...(output.path ? { path: Object.freeze([...output.path]) } : {}),\n });\n\nexport const defineProcessor = (definition: {\n readonly dependencies: readonly Projection<unknown>[];\n readonly outputs: readonly OutputDefinition[];\n readonly create: () => ProcessorInstance;\n readonly name?: string;\n}): readonly Projection<unknown>[] => {\n if (!Array.isArray(definition.dependencies))\n throw new TypeError('Projection dependencies must be an array.');\n definition.dependencies.forEach(projectionRef);\n if (!definition.outputs.length) throw new TypeError('Projection processor requires an output.');\n const producer: ProcessorDefinition = {\n kind: 'processor',\n dependencies: Object.freeze([...definition.dependencies]),\n outputs: Object.freeze(definition.outputs.map(freezeOutput)),\n create: definition.create,\n ...(definition.name ? { name: definition.name } : {}),\n };\n return Object.freeze(producer.outputs.map((_, output) => defineRef<unknown>(producer, output)));\n};\n\nexport const defineSource = <T>(source: SourceAdapter, output: OutputDefinition): Projection<T> => {\n const producer: SourceDefinition = {\n kind: 'source',\n source,\n output: freezeOutput(output),\n };\n return defineRef<T>(producer, 0);\n};\n","import type { CollectionRead } from '@/projection/contract';\n\nexport const mapRead = <K extends string, V>(value: ReadonlyMap<K, V>): CollectionRead<K, V> => ({\n get: key => value.get(key),\n has: key => value.has(key),\n ids: () => Object.freeze([...value.keys()]),\n});\n\n/** Immutable map-like view over a CollectionRead. */\nexport const collectionView = <K extends string, V>(\n read: CollectionRead<K, V>\n): ReadonlyMap<K, V> => {\n const ids = read.ids();\n const entries = function* (): IterableIterator<[K, V]> {\n for (const key of ids) yield [key, read.get(key) as V];\n };\n const values = function* (): IterableIterator<V> {\n for (const key of ids) yield read.get(key) as V;\n };\n const view: ReadonlyMap<K, V> = {\n get: key => read.get(key),\n has: key => read.has(key),\n get size() {\n return ids.length;\n },\n keys: () => ids[Symbol.iterator](),\n values,\n entries,\n forEach: (callback, thisArg) => {\n for (const key of ids) callback.call(thisArg, read.get(key) as V, key, view);\n },\n [Symbol.iterator]: entries,\n };\n return Object.freeze(view);\n};\n\n/** Eager durable view used when a processor result may retain its dependency value. */\nexport const snapshotCollectionView = <K extends string, V>(\n read: CollectionRead<K, V>\n): ReadonlyMap<K, V> => {\n const ids = read.ids();\n const values = new Map<K, V>();\n for (const key of ids) values.set(key, read.get(key) as V);\n return collectionView(mapRead(values));\n};\n","import { isPlainObject } from '@/value/record';\nimport { snapshotCollectionView } from '@/projection/collection/view';\nimport type { SourceContext } from './contract';\nimport { isProjection, projectionRef, type Projection } from './definition';\n\nexport type CompiledProjectionDependencies = {\n readonly names: readonly string[];\n readonly projections: readonly Projection<unknown>[];\n};\n\nexport type NamedDependencyEntry = {\n readonly name: string;\n readonly value: unknown;\n};\n\n/** Owns validation of the shared named dependency object shape. */\nexport const readNamedDependencyEntries = (\n dependencies: unknown,\n label: string\n): readonly NamedDependencyEntry[] => {\n if (!isPlainObject(dependencies) || isProjection(dependencies))\n throw new TypeError(`${label} dependencies must be a plain object.`);\n const entries: NamedDependencyEntry[] = [];\n for (const name of Reflect.ownKeys(dependencies)) {\n if (typeof name !== 'string') throw new TypeError(`${label} dependency names must be strings.`);\n const descriptor = Object.getOwnPropertyDescriptor(dependencies, name);\n if (!descriptor?.enumerable || !('value' in descriptor))\n throw new TypeError(`${label} dependencies must be enumerable data properties.`);\n entries.push(Object.freeze({ name, value: descriptor.value }));\n }\n return Object.freeze(entries);\n};\n\n/** Creates the durable dependency value exposed to pure derive callbacks. */\nexport const snapshotDependencyValue = (source: SourceContext): unknown =>\n source.kind === 'value' ? source.value : snapshotCollectionView(source.read);\n\n/** Compiles the shared named Projection dependency declaration contract. */\nexport const compileProjectionDependencies = (\n dependencies: unknown,\n label: string\n): CompiledProjectionDependencies => {\n const names: string[] = [];\n const projections: Projection<unknown>[] = [];\n for (const { name, value } of readNamedDependencyEntries(dependencies, label)) {\n const projection = value as Projection<unknown>;\n projectionRef(projection);\n names.push(name);\n projections.push(projection);\n }\n return Object.freeze({\n names: Object.freeze(names),\n projections: Object.freeze(projections),\n });\n};\n","import type { CollectionChange } from '@/projection/contract';\n\ntype Added<K extends string, V> = { readonly key: K; readonly after: V };\ntype Updated<K extends string, V> = {\n readonly key: K;\n readonly before: V;\n readonly after: V;\n};\ntype Removed<K extends string, V> = { readonly key: K; readonly before: V };\n\nconst commonOrderChanged = <K extends string>(\n before: readonly K[],\n after: readonly K[],\n added: ReadonlySet<K>,\n removed: ReadonlySet<K>\n): boolean => {\n const beforeCommon = before.filter(key => !removed.has(key));\n const afterCommon = after.filter(key => !added.has(key));\n return beforeCommon.some((key, index) => afterCommon[index] !== key);\n};\n\n/** Builds the canonical incremental CollectionChange from already-known net transitions. */\nexport const createCollectionChange = <K extends string, V>(input: {\n readonly added: readonly Added<K, V>[];\n readonly updated: readonly Updated<K, V>[];\n readonly removed: readonly Removed<K, V>[];\n readonly beforeOrder: readonly K[];\n readonly afterOrder: readonly K[];\n}): CollectionChange<K, V> | undefined => {\n const addedKeys = new Set(input.added.map(entry => entry.key));\n const removedKeys = new Set(input.removed.map(entry => entry.key));\n const orderChanged =\n input.beforeOrder !== input.afterOrder &&\n commonOrderChanged(input.beforeOrder, input.afterOrder, addedKeys, removedKeys);\n if (!input.added.length && !input.updated.length && !input.removed.length && !orderChanged)\n return undefined;\n return Object.freeze({\n kind: 'incremental' as const,\n added: Object.freeze([...input.added]),\n updated: Object.freeze([...input.updated]),\n removed: Object.freeze([...input.removed]),\n ...(orderChanged\n ? {\n order: Object.freeze({\n before: Object.freeze([...input.beforeOrder]),\n after: Object.freeze([...input.afterOrder]),\n }),\n }\n : {}),\n });\n};\n\n/** Exact fallback diff between two published map-like snapshots. */\nexport const diffCollection = <K extends string, V>(\n previous: ReadonlyMap<K, V>,\n current: ReadonlyMap<K, V>,\n isEqual: (previous: V, next: V) => boolean = Object.is\n): CollectionChange<K, V> | undefined => {\n const added: Added<K, V>[] = [];\n const updated: Updated<K, V>[] = [];\n const removed: Removed<K, V>[] = [];\n for (const [key, before] of previous) {\n if (!current.has(key)) removed.push({ key, before });\n else {\n const after = current.get(key) as V;\n if (!isEqual(before, after)) updated.push({ key, before, after });\n }\n }\n for (const [key, after] of current) if (!previous.has(key)) added.push({ key, after });\n return createCollectionChange({\n added,\n updated,\n removed,\n beforeOrder: [...previous.keys()],\n afterOrder: [...current.keys()],\n });\n};\n\nconst changedKeys = function* <K extends string, V>(\n change: Extract<CollectionChange<K, V>, { readonly kind: 'incremental' }>\n): IterableIterator<K> {\n if ((change as CollectionChange<K, V>).kind !== 'incremental')\n throw new TypeError('collectionChange.keys requires an incremental CollectionChange.');\n for (const entry of change.added) yield entry.key;\n for (const entry of change.updated) yield entry.key;\n for (const entry of change.removed) yield entry.key;\n};\n\nexport const collectionChange: {\n readonly keys: <K extends string, V>(\n change: Extract<CollectionChange<K, V>, { readonly kind: 'incremental' }>\n ) => Iterable<K>;\n} = Object.freeze({ keys: changedKeys });\n\nexport const collectionHasStructuralChange = <K extends string, V>(\n change: CollectionChange<K, V>\n): boolean =>\n change.kind === 'reset' || Boolean(change.added.length || change.removed.length || change.order);\n","import type { CollectionImpact } from '@/impact';\nimport type { Unsubscribe } from '@/runtime/contract';\n\n/** Scheduler-owned metadata for one Runtime batch. */\nexport type BatchContext = {\n readonly id: number;\n readonly cause?: unknown;\n};\n\n/** The one processor-facing collection transition protocol. */\nexport type CollectionChange<K extends string, V> =\n | { readonly kind: 'reset' }\n | {\n readonly kind: 'incremental';\n readonly added: readonly { readonly key: K; readonly after: V }[];\n readonly updated: readonly {\n readonly key: K;\n readonly before: V;\n readonly after: V;\n }[];\n readonly removed: readonly { readonly key: K; readonly before: V }[];\n readonly order?: {\n readonly before: readonly K[];\n readonly after: readonly K[];\n };\n };\n\nexport type ValueContext<T> = {\n readonly kind: 'value';\n readonly value: T;\n readonly revision: number;\n readonly reset: boolean;\n readonly cause?: unknown;\n};\n\nexport type CollectionRead<K extends string, V> = {\n get(key: K): V | undefined;\n has(key: K): boolean;\n ids(): readonly K[];\n};\n\nexport type ExternalCollectionRead<K extends string, V> = {\n readonly get: (key: K) => V | undefined;\n readonly has: (key: K) => boolean;\n readonly ids: () => readonly K[];\n};\n\nexport type CollectionContext<K extends string, V> = {\n readonly kind: 'collection';\n readonly read: CollectionRead<K, V>;\n readonly change: CollectionChange<K, V> | undefined;\n readonly revision: number;\n readonly reset: boolean;\n readonly cause?: unknown;\n};\n\nexport type SourceContext = ValueContext<unknown> | CollectionContext<string, unknown>;\n\nexport type ExternalValueSource<T> = {\n readonly kind: 'value';\n current(): T;\n revision(): number;\n subscribe(listener: (event: ExternalValueEvent<T>) => void): Unsubscribe;\n};\n\nexport type ExternalCollectionSource<K extends string, V> = {\n readonly kind: 'collection';\n current(): ExternalCollectionRead<K, V>;\n revision(): number;\n subscribe(listener: (event: ExternalCollectionEvent<K, V>) => void): Unsubscribe;\n};\n\nexport type ExternalValueEvent<T> = {\n readonly value: T;\n readonly revision: number;\n readonly reset?: boolean;\n readonly cause?: unknown;\n};\n\nexport type ExternalCollectionEvent<K extends string, V> = {\n /** Stable read from the source before this event or external batch. */\n readonly previous: ExternalCollectionRead<K, V>;\n readonly revision: number;\n /** Optional document-style hint; the adapter resolves the canonical change. */\n readonly impact?: CollectionImpact<K>;\n readonly cause?: unknown;\n};\n\nexport type CollectionDraft<K extends string, V> = {\n set(key: K, value: V): void;\n remove(key: K): void;\n order(ids: readonly K[]): void;\n};\n\nexport class ProjectionError extends Error {\n readonly cause: unknown;\n\n constructor(\n readonly phase: 'processor' | 'listener' | 'source' | 'blocked',\n cause: unknown\n ) {\n super(`Projection ${phase} failed.`, { cause });\n this.name = 'ProjectionError';\n this.cause = cause;\n }\n}\n\nexport class ProjectionDisposedError extends Error {\n constructor() {\n super('Projection has been disposed.');\n this.name = 'ProjectionDisposedError';\n }\n}\n","import { profile } from '@/profile';\nimport type { ObserverError, Unsubscribe } from '@/runtime/contract';\nimport type { BatchContext, CollectionChange, SourceContext } from '@/projection/contract';\nimport { ProjectionDisposedError, ProjectionError } from '@/projection/contract';\n\ntype BatchOptions = { readonly cause?: unknown };\n\ntype ProducerBase = {\n readonly name: string;\n readonly outputs: readonly OutputRecord[];\n fault: ProjectionError | undefined;\n disposed: boolean;\n clear(): void;\n release(): void;\n};\n\nexport type OutputListener = (change?: CollectionChange<string, unknown>) => void;\n\nexport type OutputRecord = {\n readonly kind: 'value' | 'collection';\n readonly owner: ProducerRecord;\n context(active: () => boolean): SourceContext;\n current(): unknown;\n revision(): number;\n reset(): boolean;\n subscribe(listener: OutputListener): Unsubscribe;\n emit(call: (listener: OutputListener, change?: CollectionChange<string, unknown>) => void): void;\n hasConsumers(): boolean;\n forEachConsumer(run: (consumer: ProcessorRecord) => void): void;\n attachConsumer(consumer: ProcessorRecord): void;\n detachConsumer(consumer: ProcessorRecord): void;\n clear(): void;\n release(): void;\n};\n\nexport type SourceBoundaryRecord = ProducerBase & {\n readonly kind: 'source';\n readonly outputs: readonly [OutputRecord];\n pendingCause(): unknown;\n recovering(): boolean;\n prepare(cause: unknown): { readonly changed: boolean; readonly force: boolean };\n publish(): void;\n};\n\nexport type ProcessorRecord = ProducerBase & {\n readonly kind: 'processor';\n readonly dependencies: readonly OutputRecord[];\n readonly order: number;\n evaluate(reset: boolean, cause: unknown, recreate?: boolean): readonly OutputRecord[];\n publish(): void;\n};\n\nexport type ProducerRecord = SourceBoundaryRecord | ProcessorRecord;\n\nexport const createScheduler = (onError: (error: ProjectionError) => void) => {\n let disposed = false;\n let depth = 0;\n let batchSequence = 0;\n let activeBatch: BatchContext | undefined;\n let phase: 'idle' | 'compute' | 'notify' = 'idle';\n let sequence = 0;\n const sources = new Set<SourceBoundaryRecord>();\n const processors = new Set<ProcessorRecord>();\n const pendingSources = new Set<SourceBoundaryRecord>();\n const heap: ProcessorRecord[] = [];\n const queued = new Set<ProcessorRecord>();\n const completed = new Set<ProcessorRecord>();\n const emissions = new Set<OutputRecord>();\n const errors: ProjectionError[] = [];\n let reportingFailures: unknown[] = [];\n const guards = new Set<(locked: boolean) => void>();\n\n const assertActive = () => {\n if (disposed) throw new ProjectionDisposedError();\n };\n const assertIdle = () => {\n assertActive();\n if (phase !== 'idle')\n throw new Error('Projection cannot be re-entered during processing or notification.');\n };\n const lock = (value: boolean) => guards.forEach(guard => guard(value));\n\n const enqueue = (processor: ProcessorRecord) => {\n if (processor.disposed || queued.has(processor)) return;\n queued.add(processor);\n profile.projection('scheduledNodes');\n let index = heap.length;\n heap.push(processor);\n while (index > 0) {\n const parent = (index - 1) >> 1;\n if (heap[parent].order < processor.order) break;\n heap[index] = heap[parent];\n index = parent;\n }\n heap[index] = processor;\n };\n\n const pop = (): ProcessorRecord => {\n const first = heap[0];\n const last = heap.pop()!;\n if (heap.length) {\n let index = 0;\n while (index * 2 + 1 < heap.length) {\n let child = index * 2 + 1;\n if (child + 1 < heap.length && heap[child + 1].order < heap[child].order) child++;\n if (last.order < heap[child].order) break;\n heap[index] = heap[child];\n index = child;\n }\n heap[index] = last;\n }\n return first;\n };\n\n const errorFor = (\n producer: ProducerRecord,\n cause: unknown,\n kind: ProjectionError['phase'] = producer.kind === 'source' ? 'source' : 'processor'\n ) => new ProjectionError(kind, cause);\n\n const capture = (source: SourceBoundaryRecord) => {\n if (disposed) return;\n if (phase !== 'idle') {\n source.fault = errorFor(\n source,\n new Error('Source changed while projection was running.'),\n 'source'\n );\n errors.push(source.fault);\n throw source.fault;\n }\n pendingSources.add(source);\n profile.projection('sourceEvents');\n if (source.fault) errors.push(source.fault);\n };\n\n const settleCause = (): unknown => {\n if (activeBatch?.cause !== undefined) return activeBatch.cause;\n for (const source of pendingSources) {\n const cause = source.pendingCause();\n if (cause !== undefined) return cause;\n }\n return undefined;\n };\n\n const settle = () => {\n if (disposed || depth || phase !== 'idle') return;\n phase = 'compute';\n lock(true);\n const cause = settleCause();\n try {\n for (const source of pendingSources) {\n if (source.disposed) continue;\n const wasFaulted = source.fault !== undefined;\n let changed = false;\n let force = false;\n if (!source.fault || source.recovering()) {\n try {\n const prepared = source.prepare(cause);\n changed = prepared.changed;\n force = prepared.force;\n source.fault = undefined;\n } catch (failure) {\n source.fault = errorFor(source, failure, 'source');\n errors.push(source.fault);\n }\n }\n const recovered = wasFaulted && !source.fault;\n if (changed) source.publish();\n if (source.fault || changed || force || recovered) {\n const output = source.outputs[0];\n emissions.add(output);\n output.forEachConsumer(enqueue);\n }\n }\n\n while (heap.length) {\n const processor = pop();\n if (processor.disposed) continue;\n const wasFaulted = processor.fault !== undefined;\n profile.projection('processedNodes');\n let changedOutputs: readonly OutputRecord[] = Object.freeze([]);\n const blocked = processor.dependencies.find(\n output => output.owner.fault || output.owner.disposed\n );\n if (blocked) {\n processor.fault = errorFor(\n processor,\n blocked.owner.fault ?? new ProjectionDisposedError(),\n 'blocked'\n );\n } else {\n const reset = wasFaulted || processor.dependencies.some(output => output.reset());\n try {\n changedOutputs = processor.evaluate(reset, cause, wasFaulted);\n const dependencyFailure = processor.dependencies.find(output => output.owner.fault)\n ?.owner.fault;\n if (dependencyFailure) throw dependencyFailure;\n processor.fault = undefined;\n } catch (failure) {\n const error = errorFor(processor, failure);\n processor.fault = error;\n if (!reset) {\n try {\n changedOutputs = processor.evaluate(true, cause, true);\n const dependencyFailure = processor.dependencies.find(output => output.owner.fault)\n ?.owner.fault;\n if (dependencyFailure) throw dependencyFailure;\n processor.fault = undefined;\n errors.push(error);\n } catch (rebuildFailure) {\n processor.fault = errorFor(processor, rebuildFailure);\n errors.push(processor.fault);\n }\n } else errors.push(error);\n }\n }\n completed.add(processor);\n const recovered = wasFaulted && !processor.fault;\n if (processor.fault) {\n processor.outputs.forEach(output => {\n emissions.add(output);\n output.forEachConsumer(enqueue);\n });\n } else {\n if (changedOutputs.length) {\n processor.publish();\n changedOutputs.forEach(output => emissions.add(output));\n }\n const propagated = recovered ? processor.outputs : changedOutputs;\n propagated.forEach(output => output.forEachConsumer(enqueue));\n }\n if (processor.fault || changedOutputs.length) {\n profile.projection('publishedNodes');\n }\n }\n } finally {\n lock(false);\n phase = 'idle';\n }\n };\n\n const flush = (): readonly ObserverError[] => {\n if (disposed || depth) return [];\n if (pendingSources.size || completed.size) profile.projection('flushes');\n phase = 'notify';\n lock(true);\n const reportFailures: unknown[] = [];\n try {\n emissions.forEach(output =>\n output.emit((listener, change) => {\n try {\n listener(change);\n } catch (cause) {\n errors.push(errorFor(output.owner, cause, 'listener'));\n }\n })\n );\n for (const error of errors.slice()) {\n try {\n onError(error);\n } catch (cause) {\n reportFailures.push(cause);\n }\n }\n return Object.freeze([\n ...errors.map(error =>\n Object.freeze({\n phase: error.phase === 'listener' ? ('listener' as const) : ('processor' as const),\n error,\n })\n ),\n ...reportFailures.map(error => Object.freeze({ phase: 'listener' as const, error })),\n ]);\n } finally {\n pendingSources.forEach(source => source.clear());\n completed.forEach(processor => processor.clear());\n pendingSources.clear();\n queued.clear();\n completed.clear();\n emissions.clear();\n errors.length = 0;\n reportingFailures = reportFailures;\n lock(false);\n phase = 'idle';\n }\n };\n\n const run = () => {\n settle();\n const result = flush();\n const failures = reportingFailures;\n reportingFailures = [];\n if (failures.length) throw new AggregateError(failures, 'Projection error reporter failed.');\n return result;\n };\n\n const batch = <T>(callback: () => T, options?: BatchOptions): T => {\n assertIdle();\n const outer = depth === 0;\n if (outer)\n activeBatch = Object.freeze({\n id: ++batchSequence,\n ...(options?.cause === undefined ? {} : { cause: options.cause }),\n });\n depth++;\n let failed = false;\n try {\n const value = callback();\n assertSynchronous(value);\n return value;\n } catch (error) {\n failed = true;\n throw error;\n } finally {\n depth--;\n if (!depth) {\n try {\n if (failed) {\n try {\n run();\n } catch {\n /* The original application error retains priority. */\n }\n } else run();\n } finally {\n activeBatch = undefined;\n }\n }\n }\n };\n\n const releaseProducer = (producer: ProducerRecord) => {\n assertIdle();\n if (producer.outputs.some(output => output.hasConsumers()))\n throw new Error('Projection producer is still used by another processor.');\n producer.disposed = true;\n if (producer.kind === 'processor') {\n producer.dependencies.forEach(output => output.detachConsumer(producer));\n processors.delete(producer);\n queued.delete(producer);\n completed.delete(producer);\n } else {\n sources.delete(producer);\n pendingSources.delete(producer);\n }\n const failures: unknown[] = [];\n try {\n producer.release();\n } catch (error) {\n failures.push(error);\n }\n try {\n producer.clear();\n } catch (error) {\n failures.push(error);\n }\n producer.outputs.forEach(output => emissions.delete(output));\n if (failures.length) throw failures[0];\n };\n\n return {\n assertActive,\n assertIdle,\n capture,\n settle,\n flush,\n run,\n registerGuard(guard: (locked: boolean) => void): Unsubscribe {\n assertActive();\n guards.add(guard);\n let registered = true;\n return () => {\n if (!registered) return;\n registered = false;\n guards.delete(guard);\n };\n },\n get active() {\n return !disposed;\n },\n addSource(source: SourceBoundaryRecord) {\n assertIdle();\n sources.add(source);\n },\n addProcessor(processor: ProcessorRecord) {\n assertIdle();\n processors.add(processor);\n processor.dependencies.forEach(output => output.attachConsumer(processor));\n },\n releaseProducer,\n order: () => sequence++,\n initialize<T>(callback: () => T): T {\n assertIdle();\n phase = 'compute';\n lock(true);\n try {\n return callback();\n } finally {\n lock(false);\n phase = 'idle';\n }\n },\n batch,\n batchContext: () => activeBatch,\n dispose() {\n if (disposed) return;\n assertIdle();\n disposed = true;\n const failures: unknown[] = [];\n processors.forEach(processor => {\n processor.disposed = true;\n try {\n processor.release();\n } catch (error) {\n failures.push(error);\n }\n });\n sources.forEach(source => {\n source.disposed = true;\n try {\n source.release();\n } catch (error) {\n failures.push(error);\n }\n });\n processors.clear();\n sources.clear();\n pendingSources.clear();\n heap.length = 0;\n queued.clear();\n completed.clear();\n emissions.clear();\n guards.clear();\n errors.length = 0;\n reportingFailures = [];\n if (failures.length) throw new AggregateError(failures, 'Projection cleanup failed.');\n },\n };\n};\n\nexport type Scheduler = ReturnType<typeof createScheduler>;\n\nexport const assertSynchronous = (value: unknown): void => {\n if (\n value != null &&\n (typeof value === 'object' || typeof value === 'function') &&\n 'then' in value &&\n typeof value.then === 'function'\n )\n throw new TypeError('Projection callbacks must be synchronous.');\n};\n\nexport const assertScope = (active: () => boolean) => {\n if (!active()) throw new Error('Projection reader or writer is no longer active.');\n};\n","export type KeyRelation = {\n replace(left: string, right: readonly string[]): boolean;\n delete(left: string): boolean;\n forward(left: string): readonly string[] | undefined;\n reverse(right: string): ReadonlySet<string> | undefined;\n lefts(): IterableIterator<string>;\n rights(): IterableIterator<string>;\n clear(): void;\n};\n\n/** Runtime-local domain-neutral many-to-many keyed relation. */\nexport const createKeyRelation = (): KeyRelation => {\n const forward = new Map<string, readonly string[]>();\n const reverse = new Map<string, Set<string>>();\n\n const detach = (left: string, right: readonly string[]): void => {\n for (const key of right) {\n const dependents = reverse.get(key);\n dependents?.delete(left);\n if (dependents?.size === 0) reverse.delete(key);\n }\n };\n\n const attach = (left: string, right: readonly string[]): void => {\n for (const key of right) {\n const dependents = reverse.get(key);\n if (dependents) dependents.add(left);\n else reverse.set(key, new Set([left]));\n }\n };\n\n return {\n replace(left, right) {\n const previous = forward.get(left) ?? Object.freeze([]);\n if (previous.length === right.length && previous.every((key, index) => key === right[index]))\n return false;\n detach(left, previous);\n if (!right.length) {\n forward.delete(left);\n return true;\n }\n const next = Object.freeze([...right]);\n forward.set(left, next);\n attach(left, next);\n return true;\n },\n delete(left) {\n const previous = forward.get(left);\n if (!previous) return false;\n detach(left, previous);\n forward.delete(left);\n return true;\n },\n forward: left => forward.get(left),\n reverse: right => reverse.get(right),\n lefts: () => forward.keys(),\n rights: () => reverse.keys(),\n clear() {\n forward.clear();\n reverse.clear();\n },\n };\n};\n","import type { Synchronous } from '@/runtime/contract';\nimport { isPlainObject } from '@/value/record';\nimport { collectionView, mapRead } from '@/projection/collection/view';\nimport { collectionChange } from '@/projection/collection/change';\nimport type { SourceContext } from '@/projection/contract';\nimport { readNamedDependencyEntries, snapshotDependencyValue } from '@/projection/dependency';\nimport {\n isProjection,\n outputDefinitionOf,\n type KeyedProjection,\n type Projection,\n} from '@/projection/definition';\nimport { assertSynchronous } from '@/projection/graph/scheduler';\nimport { createKeyRelation, type KeyRelation } from './relation';\n\nexport type SingularKeyedDependency<\n DriverKey extends string,\n DriverValue,\n SourceKey extends string,\n SourceValue,\n> = {\n readonly source: KeyedProjection<SourceKey, SourceValue>;\n readonly key: (value: DriverValue, key: DriverKey) => Synchronous<SourceKey | undefined>;\n readonly keys?: never;\n};\n\nexport type PluralKeyedDependency<\n DriverKey extends string,\n DriverValue,\n SourceKey extends string,\n SourceValue,\n> = {\n readonly source: KeyedProjection<SourceKey, SourceValue>;\n readonly keys: (value: DriverValue, key: DriverKey) => Synchronous<readonly SourceKey[]>;\n readonly key?: never;\n};\n\nexport type KeyedDependency<DriverKey extends string, DriverValue> =\n | (Projection<unknown> & {\n readonly source?: never;\n readonly key?: never;\n readonly keys?: never;\n })\n | SingularKeyedDependency<DriverKey, DriverValue, string, unknown>\n | PluralKeyedDependency<DriverKey, DriverValue, string, unknown>;\n\nexport type KeyedDependencyRecord<DriverKey extends string, DriverValue> = Readonly<\n Record<string, KeyedDependency<DriverKey, DriverValue>>\n>;\n\nexport type KeyedDependencies<DriverKey extends string, DriverValue, D extends object> = {\n readonly [P in keyof D]: P extends string ? KeyedDependency<DriverKey, DriverValue> : never;\n};\n\nexport type KeyedDependencyValues<D extends object> = {\n readonly [P in keyof D]: D[P] extends {\n readonly source: KeyedProjection<infer K extends string, infer V>;\n readonly keys: (...args: never[]) => unknown;\n }\n ? ReadonlyMap<K, V>\n : D[P] extends {\n readonly source: KeyedProjection<infer _K extends string, infer V>;\n }\n ? V | undefined\n : D[P] extends Projection<infer T>\n ? T\n : never;\n};\n\ntype CompiledDynamicKeyedDependency =\n | {\n readonly kind: 'one';\n readonly projection: Projection<unknown>;\n readonly select: (value: unknown, key: string) => unknown;\n }\n | {\n readonly kind: 'many';\n readonly projection: Projection<unknown>;\n readonly select: (value: unknown, key: string) => unknown;\n };\n\ntype CompiledKeyedDependency =\n | {\n readonly name: string;\n readonly kind: 'global';\n readonly projection: Projection<unknown>;\n }\n | ({ readonly name: string } & CompiledDynamicKeyedDependency);\n\nexport type CompiledKeyedDependencies = {\n readonly entries: readonly CompiledKeyedDependency[];\n readonly projections: readonly Projection<unknown>[];\n};\n\nexport const outputKind = (projection: Projection<unknown>): 'value' | 'collection' =>\n outputDefinitionOf(projection).kind;\n\nexport const assertKeyedProjection = (projection: Projection<unknown>, role: string): void => {\n if (outputKind(projection) !== 'collection')\n throw new TypeError(`${role} must be a keyed collection projection.`);\n};\n\nconst compileDynamicDependency = (\n value: unknown,\n label: string\n): CompiledDynamicKeyedDependency => {\n if (!isPlainObject(value) || isProjection(value))\n throw new TypeError(\n `${label} dependencies must be projections or singular/plural keyed lookups.`\n );\n const candidate: { source?: unknown; key?: unknown; keys?: unknown } = {};\n const allowed = new Set(['source', 'key', 'keys']);\n let hasKey = false;\n let hasKeys = false;\n for (const name of Reflect.ownKeys(value)) {\n if (typeof name !== 'string' || !allowed.has(name))\n throw new TypeError(`${label} dynamic keyed dependency contains an unknown property.`);\n const descriptor = Object.getOwnPropertyDescriptor(value, name);\n if (!descriptor?.enumerable || !('value' in descriptor))\n throw new TypeError(`${label} dynamic keyed dependency must use enumerable data properties.`);\n candidate[name as 'source' | 'key' | 'keys'] = descriptor.value;\n if (name === 'key') hasKey = true;\n if (name === 'keys') hasKeys = true;\n }\n if (!isProjection(candidate.source))\n throw new TypeError(`${label} dynamic keyed dependency source must be a projection.`);\n if (hasKey === hasKeys)\n throw new TypeError(\n `${label} dynamic keyed dependency must declare exactly one of key or keys.`\n );\n const singular = hasKey;\n const selector = singular ? candidate.key : candidate.keys;\n if (typeof selector !== 'function')\n throw new TypeError(`${label} dynamic keyed dependency selector must be a function.`);\n assertKeyedProjection(candidate.source, `${label} dynamic keyed dependency source`);\n return singular\n ? {\n kind: 'one',\n projection: candidate.source,\n select: selector as (value: unknown, key: string) => unknown,\n }\n : {\n kind: 'many',\n projection: candidate.source,\n select: selector as (value: unknown, key: string) => unknown,\n };\n};\n\nexport const compileKeyedDependencies = (\n driver: Projection<unknown>,\n dependencySpecs: KeyedDependencyRecord<string, unknown> | undefined,\n label: string\n): CompiledKeyedDependencies => {\n const entries: CompiledKeyedDependency[] = [];\n const projections: Projection<unknown>[] = [driver];\n if (dependencySpecs === undefined)\n return Object.freeze({\n entries: Object.freeze(entries),\n projections: Object.freeze(projections),\n });\n for (const { name, value: dependency } of readNamedDependencyEntries(dependencySpecs, label)) {\n if (isProjection(dependency)) {\n entries.push(Object.freeze({ name, kind: 'global' as const, projection: dependency }));\n projections.push(dependency);\n continue;\n }\n const dynamic = compileDynamicDependency(dependency, label);\n entries.push(Object.freeze({ name, ...dynamic }));\n projections.push(dynamic.projection);\n }\n return Object.freeze({\n entries: Object.freeze(entries),\n projections: Object.freeze(projections),\n });\n};\n\nconst selectedKeys = (\n dependency: CompiledDynamicKeyedDependency,\n value: unknown,\n key: string\n): readonly string[] => {\n const result = dependency.select(value, key);\n assertSynchronous(result);\n if (dependency.kind === 'one') {\n if (result === undefined) return Object.freeze([]);\n if (typeof result !== 'string')\n throw new TypeError('Dynamic keyed dependency key must be a string or undefined.');\n return Object.freeze([result]);\n }\n if (!Array.isArray(result))\n throw new TypeError('Dynamic keyed dependency keys must be an array of strings.');\n const seen = new Set<string>();\n const keys: string[] = [];\n for (const selected of result) {\n if (typeof selected !== 'string')\n throw new TypeError('Dynamic keyed dependency keys must contain only strings.');\n if (seen.has(selected))\n throw new TypeError('Dynamic keyed dependency keys must not contain duplicates.');\n seen.add(selected);\n keys.push(selected);\n }\n return Object.freeze(keys);\n};\n\nexport type KeyedDependencyRuntime = {\n prepare(sources: readonly SourceContext[], reset: boolean): void;\n resolve(\n driverValue: unknown,\n driverKey: string,\n sources: readonly SourceContext[]\n ): Readonly<Record<string, unknown>>;\n driverChanged(source: SourceContext): boolean;\n collectInvalidated(sources: readonly SourceContext[], dirty: Set<string>): boolean;\n remove(driverKey: string): void;\n clearBindings(): void;\n remember(sources: readonly SourceContext[]): void;\n release(): void;\n};\n\nconst emptyValues: Readonly<Record<string, unknown>> = Object.freeze(\n Object.create(null) as Record<string, unknown>\n);\n\nexport const createKeyedDependencyRuntime = (\n compiled: CompiledKeyedDependencies\n): KeyedDependencyRuntime => {\n type GlobalDependencyState = {\n readonly kind: 'global';\n readonly entry: Extract<CompiledKeyedDependency, { readonly kind: 'global' }>;\n readonly sourceIndex: number;\n revision: number;\n globalValue: unknown;\n };\n type DynamicDependencyState = {\n readonly kind: 'dynamic';\n readonly entry: Exclude<CompiledKeyedDependency, { readonly kind: 'global' }>;\n readonly sourceIndex: number;\n readonly relation: KeyRelation;\n revision: number;\n };\n type DependencyState = GlobalDependencyState | DynamicDependencyState;\n const states: DependencyState[] = compiled.entries.map((entry, index) =>\n entry.kind === 'global'\n ? { kind: 'global', entry, sourceIndex: index + 1, revision: -1, globalValue: undefined }\n : {\n kind: 'dynamic',\n entry,\n sourceIndex: index + 1,\n relation: createKeyRelation(),\n revision: -1,\n }\n );\n let driverRevision = -1;\n\n return {\n prepare(sources, reset) {\n for (const state of states) {\n if (state.kind !== 'global') continue;\n const source = sources[state.sourceIndex];\n if (reset || state.revision !== source.revision)\n state.globalValue = snapshotDependencyValue(source);\n }\n },\n resolve(driverValue, driverKey, sources) {\n if (!states.length) return emptyValues;\n const values = Object.create(null) as Record<string, unknown>;\n for (const state of states) {\n if (state.kind === 'global') {\n values[state.entry.name] = state.globalValue;\n continue;\n }\n const dependency = state.entry;\n const source = sources[state.sourceIndex];\n if (source.kind !== 'collection')\n throw new TypeError('Dynamic keyed dependency resolved to a non-collection source.');\n const keys = selectedKeys(dependency, driverValue, driverKey);\n state.relation.replace(driverKey, keys);\n if (dependency.kind === 'one') {\n const selected = keys[0];\n values[dependency.name] = selected === undefined ? undefined : source.read.get(selected);\n continue;\n }\n const selected = new Map<string, unknown>();\n for (const key of keys) if (source.read.has(key)) selected.set(key, source.read.get(key));\n values[dependency.name] = collectionView(mapRead(selected));\n }\n return Object.freeze(values);\n },\n driverChanged(source) {\n return driverRevision !== source.revision;\n },\n collectInvalidated(sources, dirty) {\n let all = false;\n for (const state of states) {\n const source = sources[state.sourceIndex];\n if (state.revision === source.revision) continue;\n const dependency = state.entry;\n if (state.kind === 'global') {\n all = true;\n continue;\n }\n if (source.kind !== 'collection' || !source.change || source.change.kind === 'reset') {\n all = true;\n continue;\n }\n for (const sourceKey of collectionChange.keys(source.change))\n for (const dependent of state.relation.reverse(sourceKey) ?? []) dirty.add(dependent);\n }\n return all;\n },\n remove(driverKey) {\n for (const state of states) if (state.kind === 'dynamic') state.relation.delete(driverKey);\n },\n clearBindings() {\n for (const state of states) if (state.kind === 'dynamic') state.relation.clear();\n },\n remember(sources) {\n driverRevision = sources[0]?.revision ?? -1;\n for (const state of states) state.revision = sources[state.sourceIndex].revision;\n },\n release() {\n for (const state of states) {\n state.revision = -1;\n if (state.kind === 'global') state.globalValue = undefined;\n else state.relation.clear();\n }\n driverRevision = -1;\n },\n };\n};\n","import type { CollectionRead, SourceContext } from '@/projection/contract';\nimport { defineProcessor, type KeyedProjection } from '@/projection/definition';\nimport { assertSynchronous } from '@/projection/graph/scheduler';\nimport {\n assertKeyedProjection,\n compileKeyedDependencies,\n createKeyedDependencyRuntime,\n type KeyedDependencyRecord,\n} from './dependency';\n\nexport const keyedAbsent = Symbol('keyed-transform-absent');\nexport type KeyedTransformResult<T> = T | typeof keyedAbsent;\n\nexport type KeyedTransformContext<K extends string, V, State> = {\n readonly key: K;\n readonly value: V;\n readonly dependencies: Readonly<Record<string, unknown>>;\n readonly state: State;\n readonly reset: boolean;\n readonly cause: unknown;\n};\n\nexport type KeyedTransformDefinition<K extends string, V, T, State> = {\n readonly source: KeyedProjection<K, V>;\n readonly dependencies?: KeyedDependencyRecord<K, V>;\n readonly equality?: (previous: T, next: T) => boolean;\n readonly name: string;\n readonly state?: (value: V, key: K) => State;\n readonly evaluate: (context: KeyedTransformContext<K, V, State>) => KeyedTransformResult<T>;\n};\n\n/** Shared driver-keyed lifecycle for pure and retained keyed transforms. */\nexport const createKeyedTransform = <K extends string, V, T, State = undefined>(\n definition: KeyedTransformDefinition<K, V, T, State>\n): KeyedProjection<K, T> => {\n assertKeyedProjection(definition.source, `${definition.name} source`);\n const compiled = compileKeyedDependencies(\n definition.source,\n definition.dependencies as KeyedDependencyRecord<string, unknown> | undefined,\n definition.name\n );\n const [projection] = defineProcessor({\n dependencies: compiled.projections,\n outputs: [\n {\n kind: 'collection',\n equality: (definition.equality ?? Object.is) as (\n previous: unknown,\n next: unknown\n ) => boolean,\n },\n ],\n create: () => {\n const dependencies = createKeyedDependencyRuntime(compiled);\n const states = new Map<string, State>();\n\n const dropState = (key: string): void => {\n states.delete(key);\n dependencies.remove(key);\n };\n\n return {\n evaluate: evaluation => {\n const driver = evaluation.sources[0];\n const output = evaluation.outputs[0];\n if (driver.kind !== 'collection' || output.kind !== 'collection')\n throw new Error(`${definition.name} requires collection input and output.`);\n dependencies.prepare(evaluation.sources, evaluation.reset);\n\n const stateFor = (key: string, value: V): State => {\n if (states.has(key)) return states.get(key) as State;\n const state = definition.state\n ? definition.state(value, key as K)\n : (undefined as State);\n assertSynchronous(state);\n if (definition.state) states.set(key, state);\n return state;\n };\n\n const project = (key: string): boolean => {\n if (!driver.read.has(key)) return false;\n const value = driver.read.get(key) as V;\n const beforePresent = output.previous.has(key);\n const next = definition.evaluate({\n key: key as K,\n value,\n dependencies: dependencies.resolve(value, key, evaluation.sources),\n state: stateFor(key, value),\n reset: evaluation.reset,\n cause: evaluation.cause,\n });\n assertSynchronous(next);\n if (next === keyedAbsent) output.output.remove(key);\n else output.output.set(key, next);\n return beforePresent !== output.next.has(key);\n };\n\n if (evaluation.reset) {\n dependencies.clearBindings();\n const ids = driver.read.ids();\n const present = new Set(ids);\n for (const key of [...states.keys()]) if (!present.has(key)) states.delete(key);\n for (const key of ids) project(key);\n output.output.order(ids.filter(key => output.next.has(key)));\n dependencies.remember(evaluation.sources);\n return;\n }\n\n const dirty = new Set<string>();\n let all = false;\n let updateOrder = false;\n let membershipChanged = false;\n if (dependencies.driverChanged(driver)) {\n const change = driver.change;\n if (!change || change.kind === 'reset') {\n all = true;\n updateOrder = true;\n for (const key of output.previous.ids()) {\n if (driver.read.has(key)) continue;\n output.output.remove(key);\n dropState(key);\n membershipChanged = true;\n }\n } else {\n for (const entry of change.removed) {\n membershipChanged ||= output.previous.has(entry.key);\n output.output.remove(entry.key);\n dropState(entry.key);\n dirty.delete(entry.key);\n }\n for (const entry of change.added) dirty.add(entry.key);\n for (const entry of change.updated) dirty.add(entry.key);\n updateOrder = Boolean(change.order);\n }\n }\n\n all ||= dependencies.collectInvalidated(evaluation.sources, dirty);\n if (all) for (const key of driver.read.ids()) dirty.add(key);\n for (const key of dirty) {\n const changedMembership = project(key);\n membershipChanged ||= changedMembership;\n }\n if (updateOrder || membershipChanged)\n output.output.order(driver.read.ids().filter(key => output.next.has(key)));\n dependencies.remember(evaluation.sources);\n },\n release: () => {\n states.clear();\n dependencies.release();\n },\n };\n },\n name: definition.name,\n });\n return projection as KeyedProjection<K, T>;\n};\n"],"mappings":";AAkDA,MAAa,UAAU;CACrB,aAAa,KAAmC,SAAS,MAAM;CAG/D,WAAW,KAAiC,SAAS,MAAM;CAG3D,SAAS,QAAkC;CAG3C,MAAM;EACJ,iBAAiB;EAGjB,gBAAgB;EAGhB,gBAAgB,UAAkB;EAGnC;CACD,UAAU;EACR,YAAY;EAGZ,iBAAiB;EAGlB;CACD,SAAS;EACP,YAAY,UAAkB;EAM9B,kBAAkB;EAGlB,oBAAoB;EAGpB,wBAAwB;EAGxB,uBAAuB;EAGxB;CACD,QAAQ;EACN,aAAa;EAGb,eAAe;EAGhB;CACD,YAAY;EACV,kBAAkB;EAGlB,uBAAuB;EAGxB;CACD,iBAAiB;EACf,YAAY;EAGZ,QAAQ,UAAkB;EAM3B;CACD,gBAAgB;EACd,cAAc;EAGd,aAAa,SAAS,MAAM;EAG5B,mBAAmB;EAGpB;CACD,cAAc;EACZ,eAAe;EAGf,eAAe;EAGf,oBAAoB;EAGrB;CACF;;;ACJD,MAAM,8BAAc,IAAI,SAAgC;AAExD,MAAM,aAAgB,UAA8B,WAAkC;CACpF,MAAM,SAAS,OAAO,OAAO,EAAE,CAAC;AAChC,aAAY,IAAI,QAAQ,OAAO,OAAO;EAAE;EAAU;EAAQ,CAAC,CAAC;AAC5D,QAAO;;AAGT,MAAa,iBAAiB,eAAmD;CAC/E,MAAM,MAAM,YAAY,IAAI,WAAW;AACvC,KAAI,CAAC,IAAK,OAAM,IAAI,UAAU,iCAAiC;AAC/D,QAAO;;AAGT,MAAa,cAAc,eACzB,cAAc,WAAW,CAAC;;AAG5B,MAAa,s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,QAAQ;;IAE3C,eAAe;AACb,YAAO,OAAO;AACd,kBAAa,SAAS;;IAEzB;;EAEH,MAAM,WAAW;EAClB,CAAC;AACF,QAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"transform-DUleAsG0.cjs","names":["isPlainObject","isPlainObject"],"sources":["../core/src/profile.ts","../core/src/projection/definition.ts","../core/src/projection/collection/view.ts","../core/src/projection/dependency.ts","../core/src/projection/collection/change.ts","../core/src/projection/contract.ts","../core/src/projection/graph/scheduler.ts","../core/src/projection/keyed/relation.ts","../core/src/projection/keyed/dependency.ts","../core/src/projection/keyed/transform.ts"],"sourcesContent":["const counters = () => ({\n projection: {\n sourceEvents: 0,\n scheduledNodes: 0,\n processedNodes: 0,\n touchedKeys: 0,\n changedKeys: 0,\n publishedNodes: 0,\n flushes: 0,\n },\n copy: { structures: 0, treeNodes: 0, shallowRecordItems: 0 },\n equality: { calls: 0, containers: 0 },\n recorder: {\n facts: 0,\n groups: 0,\n transitions: 0,\n absorbed: 0,\n orderSnapshots: 0,\n orderCaptures: 0,\n orderItems: 0,\n publishedOrderItems: 0,\n treeNodes: 0,\n sealed: 0,\n indexedGroups: 0,\n },\n access: { scopes: 0, proxies: 0, snapshots: 0, addresses: 0, resolutions: 0 },\n address: {\n schemaSteps: 0,\n documentSteps: 0,\n prefixComparisons: 0,\n segmentsCompared: 0,\n listIndexes: 0,\n listItems: 0,\n },\n impact: { affectsChecks: 0, indexes: 0 },\n dependency: { comparisons: 0, segmentsCompared: 0 },\n collectionIndex: { nodes: 0, builds: 0, builtItems: 0 },\n collectionView: { mappedItems: 0, idsScanned: 0, arraysCopied: 0 },\n materialized: { updated: 0, rebuilt: 0, notifications: 0 },\n});\ntype Counters = ReturnType<typeof counters>;\ntype DeepReadonly<T> = { readonly [K in keyof T]: T[K] extends object ? DeepReadonly<T[K]> : T[K] };\nexport type ProfileSnapshot = DeepReadonly<Counters>;\nlet active: Counters | undefined;\nconst freeze = <T extends object>(value: T): DeepReadonly<T> => {\n Object.values(value).forEach(child => {\n if (child && typeof child === 'object') freeze(child);\n });\n return Object.freeze(value) as DeepReadonly<T>;\n};\nexport const profile = {\n projection: (key: keyof Counters['projection'], amount = 1) => {\n if (active) active.projection[key] += amount;\n },\n recorder: (key: keyof Counters['recorder'], amount = 1) => {\n if (active) active.recorder[key] += amount;\n },\n access: (key: keyof Counters['access']) => {\n if (active) active.access[key]++;\n },\n copy: {\n structure: () => {\n if (active) active.copy.structures++;\n },\n treeNode: () => {\n if (active) active.copy.treeNodes++;\n },\n shallowRecord: (items: number) => {\n if (active) active.copy.shallowRecordItems += items;\n },\n },\n equality: {\n call: () => {\n if (active) active.equality.calls++;\n },\n container: () => {\n if (active) active.equality.containers++;\n },\n },\n address: {\n listIndex: (items: number) => {\n if (active) {\n active.address.listIndexes++;\n active.address.listItems += items;\n }\n },\n schemaStep: () => {\n if (active) active.address.schemaSteps++;\n },\n documentStep: () => {\n if (active) active.address.documentSteps++;\n },\n prefixComparison: () => {\n if (active) active.address.prefixComparisons++;\n },\n segmentCompared: () => {\n if (active) active.address.segmentsCompared++;\n },\n },\n impact: {\n index: () => {\n if (active) active.impact.indexes++;\n },\n affects: () => {\n if (active) active.impact.affectsChecks++;\n },\n },\n dependency: {\n comparison: () => {\n if (active) active.dependency.comparisons++;\n },\n segmentCompared: () => {\n if (active) active.dependency.segmentsCompared++;\n },\n },\n collectionIndex: {\n node: () => {\n if (active) active.collectionIndex.nodes++;\n },\n build: (items: number) => {\n if (active) {\n active.collectionIndex.builds++;\n active.collectionIndex.builtItems += items;\n }\n },\n },\n collectionView: {\n mapped: () => {\n if (active) active.collectionView.mappedItems++;\n },\n idsScanned: (amount = 1) => {\n if (active) active.collectionView.idsScanned += amount;\n },\n arrayCopied: () => {\n if (active) active.collectionView.arraysCopied++;\n },\n },\n materialized: {\n updated: () => {\n if (active) active.materialized.updated++;\n },\n rebuilt: () => {\n if (active) active.materialized.rebuilt++;\n },\n notification: () => {\n if (active) active.materialized.notifications++;\n },\n },\n};\nexport type ProfileSession = { snapshot(): ProfileSnapshot; stop(): ProfileSnapshot };\nexport const startProfile = (): ProfileSession => {\n if (active) throw new Error('A document profile session is already active.');\n const value = counters();\n active = value;\n const snapshot = () => freeze(structuredClone(value));\n return {\n snapshot,\n stop: () => {\n if (active === value) active = undefined;\n return snapshot();\n },\n };\n};\nexport const measureProfile = <T>(run: () => T): { value: T; profile: ProfileSnapshot } => {\n const session = startProfile();\n try {\n return { value: run(), profile: session.stop() };\n } finally {\n session.stop();\n }\n};\n","import type { ReadonlyDocument } from '@/runtime/contract';\nimport type { ObjectSchema } from '@/schema/model';\nimport type { CollectionSelector, ValueSelector } from '@/schema/path';\nimport type {\n CollectionChange,\n CollectionDraft,\n CollectionRead,\n ExternalCollectionSource,\n ExternalValueSource,\n SourceContext,\n} from './contract';\nimport type { Readable } from '@/readable';\n\ndeclare const projectionDefinition: unique symbol;\ndeclare const keyedProjection: unique symbol;\ndeclare const writableInput: unique symbol;\ndeclare const writableCollectionInput: unique symbol;\n\n/** A lazy output reference with no materialized Runtime state. */\nexport type Projection<T> = {\n readonly [projectionDefinition]: T;\n};\n\n/** A projection whose output is a keyed collection with per-key change semantics. */\nexport type KeyedProjection<K extends string, V> = Projection<ReadonlyMap<K, V>> & {\n readonly [keyedProjection]: { readonly key: K; readonly value: V };\n};\n\n/** A writable source projection. */\nexport type Input<T> = Projection<T> & { readonly [writableInput]: true };\n\n/** A writable keyed collection source projection. */\nexport type CollectionInput<K extends string, V> = KeyedProjection<K, V> & {\n readonly [writableCollectionInput]: { readonly key: K; readonly value: V };\n};\n\nexport type CollectionInputDraft<K extends string, V> = {\n get(key: K): V | undefined;\n has(key: K): boolean;\n set(key: K, value: V): void;\n remove(key: K): void;\n};\n\nexport type ProjectionChange<P> =\n P extends KeyedProjection<infer K, infer V> ? CollectionChange<K, V> : undefined;\n\nexport type Equality = (a: unknown, b: unknown) => boolean;\n\nexport type OutputDefinition =\n | {\n readonly kind: 'value';\n readonly equality: Equality;\n readonly path?: readonly string[];\n }\n | {\n readonly kind: 'collection';\n readonly equality: Equality;\n readonly path?: readonly string[];\n };\n\nexport type ValueOutputEvaluation = {\n readonly kind: 'value';\n readonly previous: unknown;\n readonly next: () => unknown;\n readonly output: { set(value: unknown): void };\n};\n\nexport type CollectionOutputEvaluation = {\n readonly kind: 'collection';\n readonly previous: CollectionRead<string, unknown>;\n readonly next: CollectionRead<string, unknown>;\n readonly output: CollectionDraft<string, unknown>;\n};\n\nexport type OutputEvaluation = ValueOutputEvaluation | CollectionOutputEvaluation;\n\nexport type ProcessorEvaluation = {\n readonly reset: boolean;\n readonly cause: unknown;\n readonly sources: readonly SourceContext[];\n readonly outputs: readonly OutputEvaluation[];\n};\n\nexport type ProcessorInstance = {\n evaluate(input: ProcessorEvaluation): void;\n release?(): void;\n};\n\nexport type SourceAdapter =\n | {\n readonly kind: 'value-input';\n readonly initial: unknown;\n readonly equality: Equality;\n }\n | {\n readonly kind: 'collection-input';\n readonly initial: ReadonlyMap<string, unknown>;\n readonly equality: Equality;\n }\n | {\n readonly kind: 'readable';\n readonly readable: Readable<unknown>;\n readonly equality: Equality;\n }\n | {\n readonly kind: 'external-value';\n readonly source: ExternalValueSource<unknown>;\n readonly equality: Equality;\n }\n | {\n readonly kind: 'external-collection';\n readonly source: ExternalCollectionSource<string, unknown>;\n }\n | {\n readonly kind: 'document';\n readonly document: ReadonlyDocument<ObjectSchema<object>>;\n readonly selector: ValueSelector | CollectionSelector;\n };\n\nexport type SourceDefinition = {\n readonly kind: 'source';\n readonly source: SourceAdapter;\n readonly output: OutputDefinition;\n owner?: object;\n materialized?: true;\n};\n\nexport type ProcessorDefinition = {\n readonly kind: 'processor';\n readonly dependencies: readonly Projection<unknown>[];\n readonly outputs: readonly OutputDefinition[];\n readonly create: () => ProcessorInstance;\n readonly name?: string;\n owner?: object;\n materialized?: true;\n};\n\nexport type ProducerDefinition = SourceDefinition | ProcessorDefinition;\n\nexport type ProjectionRef = {\n readonly producer: ProducerDefinition;\n readonly output: number;\n};\n\nconst projections = new WeakMap<object, ProjectionRef>();\n\nconst defineRef = <T>(producer: ProducerDefinition, output: number): Projection<T> => {\n const handle = Object.freeze({}) as Projection<T>;\n projections.set(handle, Object.freeze({ producer, output }));\n return handle;\n};\n\nexport const projectionRef = (projection: Projection<unknown>): ProjectionRef => {\n const ref = projections.get(projection);\n if (!ref) throw new TypeError('Unknown projection definition.');\n return ref;\n};\n\nexport const producerOf = (projection: Projection<unknown>): ProducerDefinition =>\n projectionRef(projection).producer;\n\n/** Resolves the immutable output description owned by a projection definition. */\nexport const outputDefinitionOf = (projection: Projection<unknown>): OutputDefinition => {\n const ref = projectionRef(projection);\n const producer = ref.producer;\n const output = producer.kind === 'source' ? producer.output : producer.outputs[ref.output];\n if (!output) throw new TypeError('Projection output does not exist.');\n return output;\n};\n\nexport const isProjection = (value: unknown): value is Projection<unknown> =>\n value !== null && typeof value === 'object' && projections.has(value);\n\nexport const ownProjections = (\n projections: readonly Projection<unknown>[],\n owner: object\n): void => {\n const producers = new Set(projections.map(producerOf));\n for (const producer of producers) {\n if (producer.owner !== undefined && producer.owner !== owner)\n throw new TypeError('Projection producer already belongs to another scope.');\n if (producer.owner === undefined && producer.materialized)\n throw new TypeError('A materialized root projection cannot become scope-owned.');\n if (producer.kind !== 'processor') continue;\n for (const dependency of producer.dependencies) {\n const dependencyOwner = producerOf(dependency).owner;\n if (dependencyOwner !== undefined && dependencyOwner !== owner)\n throw new TypeError('A scope cannot depend on another scope.');\n }\n }\n for (const producer of producers) producer.owner = owner;\n};\n\nconst freezeOutput = (output: OutputDefinition): OutputDefinition =>\n Object.freeze({\n kind: output.kind,\n equality: output.equality,\n ...(output.path ? { path: Object.freeze([...output.path]) } : {}),\n });\n\nexport const defineProcessor = (definition: {\n readonly dependencies: readonly Projection<unknown>[];\n readonly outputs: readonly OutputDefinition[];\n readonly create: () => ProcessorInstance;\n readonly name?: string;\n}): readonly Projection<unknown>[] => {\n if (!Array.isArray(definition.dependencies))\n throw new TypeError('Projection dependencies must be an array.');\n definition.dependencies.forEach(projectionRef);\n if (!definition.outputs.length) throw new TypeError('Projection processor requires an output.');\n const producer: ProcessorDefinition = {\n kind: 'processor',\n dependencies: Object.freeze([...definition.dependencies]),\n outputs: Object.freeze(definition.outputs.map(freezeOutput)),\n create: definition.create,\n ...(definition.name ? { name: definition.name } : {}),\n };\n return Object.freeze(producer.outputs.map((_, output) => defineRef<unknown>(producer, output)));\n};\n\nexport const defineSource = <T>(source: SourceAdapter, output: OutputDefinition): Projection<T> => {\n const producer: SourceDefinition = {\n kind: 'source',\n source,\n output: freezeOutput(output),\n };\n return defineRef<T>(producer, 0);\n};\n","import type { CollectionRead } from '@/projection/contract';\n\nexport const mapRead = <K extends string, V>(value: ReadonlyMap<K, V>): CollectionRead<K, V> => ({\n get: key => value.get(key),\n has: key => value.has(key),\n ids: () => Object.freeze([...value.keys()]),\n});\n\n/** Immutable map-like view over a CollectionRead. */\nexport const collectionView = <K extends string, V>(\n read: CollectionRead<K, V>\n): ReadonlyMap<K, V> => {\n const ids = read.ids();\n const entries = function* (): IterableIterator<[K, V]> {\n for (const key of ids) yield [key, read.get(key) as V];\n };\n const values = function* (): IterableIterator<V> {\n for (const key of ids) yield read.get(key) as V;\n };\n const view: ReadonlyMap<K, V> = {\n get: key => read.get(key),\n has: key => read.has(key),\n get size() {\n return ids.length;\n },\n keys: () => ids[Symbol.iterator](),\n values,\n entries,\n forEach: (callback, thisArg) => {\n for (const key of ids) callback.call(thisArg, read.get(key) as V, key, view);\n },\n [Symbol.iterator]: entries,\n };\n return Object.freeze(view);\n};\n\n/** Eager durable view used when a processor result may retain its dependency value. */\nexport const snapshotCollectionView = <K extends string, V>(\n read: CollectionRead<K, V>\n): ReadonlyMap<K, V> => {\n const ids = read.ids();\n const values = new Map<K, V>();\n for (const key of ids) values.set(key, read.get(key) as V);\n return collectionView(mapRead(values));\n};\n","import { isPlainObject } from '@/value/record';\nimport { snapshotCollectionView } from '@/projection/collection/view';\nimport type { SourceContext } from './contract';\nimport { isProjection, projectionRef, type Projection } from './definition';\n\nexport type CompiledProjectionDependencies = {\n readonly names: readonly string[];\n readonly projections: readonly Projection<unknown>[];\n};\n\nexport type NamedDependencyEntry = {\n readonly name: string;\n readonly value: unknown;\n};\n\n/** Owns validation of the shared named dependency object shape. */\nexport const readNamedDependencyEntries = (\n dependencies: unknown,\n label: string\n): readonly NamedDependencyEntry[] => {\n if (!isPlainObject(dependencies) || isProjection(dependencies))\n throw new TypeError(`${label} dependencies must be a plain object.`);\n const entries: NamedDependencyEntry[] = [];\n for (const name of Reflect.ownKeys(dependencies)) {\n if (typeof name !== 'string') throw new TypeError(`${label} dependency names must be strings.`);\n const descriptor = Object.getOwnPropertyDescriptor(dependencies, name);\n if (!descriptor?.enumerable || !('value' in descriptor))\n throw new TypeError(`${label} dependencies must be enumerable data properties.`);\n entries.push(Object.freeze({ name, value: descriptor.value }));\n }\n return Object.freeze(entries);\n};\n\n/** Creates the durable dependency value exposed to pure derive callbacks. */\nexport const snapshotDependencyValue = (source: SourceContext): unknown =>\n source.kind === 'value' ? source.value : snapshotCollectionView(source.read);\n\n/** Compiles the shared named Projection dependency declaration contract. */\nexport const compileProjectionDependencies = (\n dependencies: unknown,\n label: string\n): CompiledProjectionDependencies => {\n const names: string[] = [];\n const projections: Projection<unknown>[] = [];\n for (const { name, value } of readNamedDependencyEntries(dependencies, label)) {\n const projection = value as Projection<unknown>;\n projectionRef(projection);\n names.push(name);\n projections.push(projection);\n }\n return Object.freeze({\n names: Object.freeze(names),\n projections: Object.freeze(projections),\n });\n};\n","import type { CollectionChange } from '@/projection/contract';\n\ntype Added<K extends string, V> = { readonly key: K; readonly after: V };\ntype Updated<K extends string, V> = {\n readonly key: K;\n readonly before: V;\n readonly after: V;\n};\ntype Removed<K extends string, V> = { readonly key: K; readonly before: V };\n\nconst commonOrderChanged = <K extends string>(\n before: readonly K[],\n after: readonly K[],\n added: ReadonlySet<K>,\n removed: ReadonlySet<K>\n): boolean => {\n const beforeCommon = before.filter(key => !removed.has(key));\n const afterCommon = after.filter(key => !added.has(key));\n return beforeCommon.some((key, index) => afterCommon[index] !== key);\n};\n\n/** Builds the canonical incremental CollectionChange from already-known net transitions. */\nexport const createCollectionChange = <K extends string, V>(input: {\n readonly added: readonly Added<K, V>[];\n readonly updated: readonly Updated<K, V>[];\n readonly removed: readonly Removed<K, V>[];\n readonly beforeOrder: readonly K[];\n readonly afterOrder: readonly K[];\n}): CollectionChange<K, V> | undefined => {\n const addedKeys = new Set(input.added.map(entry => entry.key));\n const removedKeys = new Set(input.removed.map(entry => entry.key));\n const orderChanged =\n input.beforeOrder !== input.afterOrder &&\n commonOrderChanged(input.beforeOrder, input.afterOrder, addedKeys, removedKeys);\n if (!input.added.length && !input.updated.length && !input.removed.length && !orderChanged)\n return undefined;\n return Object.freeze({\n kind: 'incremental' as const,\n added: Object.freeze([...input.added]),\n updated: Object.freeze([...input.updated]),\n removed: Object.freeze([...input.removed]),\n ...(orderChanged\n ? {\n order: Object.freeze({\n before: Object.freeze([...input.beforeOrder]),\n after: Object.freeze([...input.afterOrder]),\n }),\n }\n : {}),\n });\n};\n\n/** Exact fallback diff between two published map-like snapshots. */\nexport const diffCollection = <K extends string, V>(\n previous: ReadonlyMap<K, V>,\n current: ReadonlyMap<K, V>,\n isEqual: (previous: V, next: V) => boolean = Object.is\n): CollectionChange<K, V> | undefined => {\n const added: Added<K, V>[] = [];\n const updated: Updated<K, V>[] = [];\n const removed: Removed<K, V>[] = [];\n for (const [key, before] of previous) {\n if (!current.has(key)) removed.push({ key, before });\n else {\n const after = current.get(key) as V;\n if (!isEqual(before, after)) updated.push({ key, before, after });\n }\n }\n for (const [key, after] of current) if (!previous.has(key)) added.push({ key, after });\n return createCollectionChange({\n added,\n updated,\n removed,\n beforeOrder: [...previous.keys()],\n afterOrder: [...current.keys()],\n });\n};\n\nconst changedKeys = function* <K extends string, V>(\n change: Extract<CollectionChange<K, V>, { readonly kind: 'incremental' }>\n): IterableIterator<K> {\n if ((change as CollectionChange<K, V>).kind !== 'incremental')\n throw new TypeError('collectionChange.keys requires an incremental CollectionChange.');\n for (const entry of change.added) yield entry.key;\n for (const entry of change.updated) yield entry.key;\n for (const entry of change.removed) yield entry.key;\n};\n\nexport const collectionChange: {\n readonly keys: <K extends string, V>(\n change: Extract<CollectionChange<K, V>, { readonly kind: 'incremental' }>\n ) => Iterable<K>;\n} = Object.freeze({ keys: changedKeys });\n\nexport const collectionHasStructuralChange = <K extends string, V>(\n change: CollectionChange<K, V>\n): boolean =>\n change.kind === 'reset' || Boolean(change.added.length || change.removed.length || change.order);\n","import type { CollectionImpact } from '@/impact';\nimport type { Unsubscribe } from '@/runtime/contract';\n\n/** Scheduler-owned metadata for one Runtime batch. */\nexport type BatchContext = {\n readonly id: number;\n readonly cause?: unknown;\n};\n\n/** The one processor-facing collection transition protocol. */\nexport type CollectionChange<K extends string, V> =\n | { readonly kind: 'reset' }\n | {\n readonly kind: 'incremental';\n readonly added: readonly { readonly key: K; readonly after: V }[];\n readonly updated: readonly {\n readonly key: K;\n readonly before: V;\n readonly after: V;\n }[];\n readonly removed: readonly { readonly key: K; readonly before: V }[];\n readonly order?: {\n readonly before: readonly K[];\n readonly after: readonly K[];\n };\n };\n\nexport type ValueContext<T> = {\n readonly kind: 'value';\n readonly value: T;\n readonly revision: number;\n readonly reset: boolean;\n readonly cause?: unknown;\n};\n\nexport type CollectionRead<K extends string, V> = {\n get(key: K): V | undefined;\n has(key: K): boolean;\n ids(): readonly K[];\n};\n\nexport type ExternalCollectionRead<K extends string, V> = {\n readonly get: (key: K) => V | undefined;\n readonly has: (key: K) => boolean;\n readonly ids: () => readonly K[];\n};\n\nexport type CollectionContext<K extends string, V> = {\n readonly kind: 'collection';\n readonly read: CollectionRead<K, V>;\n readonly change: CollectionChange<K, V> | undefined;\n readonly revision: number;\n readonly reset: boolean;\n readonly cause?: unknown;\n};\n\nexport type SourceContext = ValueContext<unknown> | CollectionContext<string, unknown>;\n\nexport type ExternalValueSource<T> = {\n readonly kind: 'value';\n current(): T;\n revision(): number;\n subscribe(listener: (event: ExternalValueEvent<T>) => void): Unsubscribe;\n};\n\nexport type ExternalCollectionSource<K extends string, V> = {\n readonly kind: 'collection';\n current(): ExternalCollectionRead<K, V>;\n revision(): number;\n subscribe(listener: (event: ExternalCollectionEvent<K, V>) => void): Unsubscribe;\n};\n\nexport type ExternalValueEvent<T> = {\n readonly value: T;\n readonly revision: number;\n readonly reset?: boolean;\n readonly cause?: unknown;\n};\n\nexport type ExternalCollectionEvent<K extends string, V> = {\n /** Stable read from the source before this event or external batch. */\n readonly previous: ExternalCollectionRead<K, V>;\n readonly revision: number;\n /** Optional document-style hint; the adapter resolves the canonical change. */\n readonly impact?: CollectionImpact<K>;\n readonly cause?: unknown;\n};\n\nexport type CollectionDraft<K extends string, V> = {\n set(key: K, value: V): void;\n remove(key: K): void;\n order(ids: readonly K[]): void;\n};\n\nexport class ProjectionError extends Error {\n readonly cause: unknown;\n\n constructor(\n readonly phase: 'processor' | 'listener' | 'source' | 'blocked',\n cause: unknown\n ) {\n super(`Projection ${phase} failed.`, { cause });\n this.name = 'ProjectionError';\n this.cause = cause;\n }\n}\n\nexport class ProjectionDisposedError extends Error {\n constructor() {\n super('Projection has been disposed.');\n this.name = 'ProjectionDisposedError';\n }\n}\n","import { profile } from '@/profile';\nimport type { ObserverError, Unsubscribe } from '@/runtime/contract';\nimport type { BatchContext, CollectionChange, SourceContext } from '@/projection/contract';\nimport { ProjectionDisposedError, ProjectionError } from '@/projection/contract';\n\ntype BatchOptions = { readonly cause?: unknown };\n\ntype ProducerBase = {\n readonly name: string;\n readonly outputs: readonly OutputRecord[];\n fault: ProjectionError | undefined;\n disposed: boolean;\n clear(): void;\n release(): void;\n};\n\nexport type OutputListener = (change?: CollectionChange<string, unknown>) => void;\n\nexport type OutputRecord = {\n readonly kind: 'value' | 'collection';\n readonly owner: ProducerRecord;\n context(active: () => boolean): SourceContext;\n current(): unknown;\n revision(): number;\n reset(): boolean;\n subscribe(listener: OutputListener): Unsubscribe;\n emit(call: (listener: OutputListener, change?: CollectionChange<string, unknown>) => void): void;\n hasConsumers(): boolean;\n forEachConsumer(run: (consumer: ProcessorRecord) => void): void;\n attachConsumer(consumer: ProcessorRecord): void;\n detachConsumer(consumer: ProcessorRecord): void;\n clear(): void;\n release(): void;\n};\n\nexport type SourceBoundaryRecord = ProducerBase & {\n readonly kind: 'source';\n readonly outputs: readonly [OutputRecord];\n pendingCause(): unknown;\n recovering(): boolean;\n prepare(cause: unknown): { readonly changed: boolean; readonly force: boolean };\n publish(): void;\n};\n\nexport type ProcessorRecord = ProducerBase & {\n readonly kind: 'processor';\n readonly dependencies: readonly OutputRecord[];\n readonly order: number;\n evaluate(reset: boolean, cause: unknown, recreate?: boolean): readonly OutputRecord[];\n publish(): void;\n};\n\nexport type ProducerRecord = SourceBoundaryRecord | ProcessorRecord;\n\nexport const createScheduler = (onError: (error: ProjectionError) => void) => {\n let disposed = false;\n let depth = 0;\n let batchSequence = 0;\n let activeBatch: BatchContext | undefined;\n let phase: 'idle' | 'compute' | 'notify' = 'idle';\n let sequence = 0;\n const sources = new Set<SourceBoundaryRecord>();\n const processors = new Set<ProcessorRecord>();\n const pendingSources = new Set<SourceBoundaryRecord>();\n const heap: ProcessorRecord[] = [];\n const queued = new Set<ProcessorRecord>();\n const completed = new Set<ProcessorRecord>();\n const emissions = new Set<OutputRecord>();\n const errors: ProjectionError[] = [];\n let reportingFailures: unknown[] = [];\n const guards = new Set<(locked: boolean) => void>();\n\n const assertActive = () => {\n if (disposed) throw new ProjectionDisposedError();\n };\n const assertIdle = () => {\n assertActive();\n if (phase !== 'idle')\n throw new Error('Projection cannot be re-entered during processing or notification.');\n };\n const lock = (value: boolean) => guards.forEach(guard => guard(value));\n\n const enqueue = (processor: ProcessorRecord) => {\n if (processor.disposed || queued.has(processor)) return;\n queued.add(processor);\n profile.projection('scheduledNodes');\n let index = heap.length;\n heap.push(processor);\n while (index > 0) {\n const parent = (index - 1) >> 1;\n if (heap[parent].order < processor.order) break;\n heap[index] = heap[parent];\n index = parent;\n }\n heap[index] = processor;\n };\n\n const pop = (): ProcessorRecord => {\n const first = heap[0];\n const last = heap.pop()!;\n if (heap.length) {\n let index = 0;\n while (index * 2 + 1 < heap.length) {\n let child = index * 2 + 1;\n if (child + 1 < heap.length && heap[child + 1].order < heap[child].order) child++;\n if (last.order < heap[child].order) break;\n heap[index] = heap[child];\n index = child;\n }\n heap[index] = last;\n }\n return first;\n };\n\n const errorFor = (\n producer: ProducerRecord,\n cause: unknown,\n kind: ProjectionError['phase'] = producer.kind === 'source' ? 'source' : 'processor'\n ) => new ProjectionError(kind, cause);\n\n const capture = (source: SourceBoundaryRecord) => {\n if (disposed) return;\n if (phase !== 'idle') {\n source.fault = errorFor(\n source,\n new Error('Source changed while projection was running.'),\n 'source'\n );\n errors.push(source.fault);\n throw source.fault;\n }\n pendingSources.add(source);\n profile.projection('sourceEvents');\n if (source.fault) errors.push(source.fault);\n };\n\n const settleCause = (): unknown => {\n if (activeBatch?.cause !== undefined) return activeBatch.cause;\n for (const source of pendingSources) {\n const cause = source.pendingCause();\n if (cause !== undefined) return cause;\n }\n return undefined;\n };\n\n const settle = () => {\n if (disposed || depth || phase !== 'idle') return;\n phase = 'compute';\n lock(true);\n const cause = settleCause();\n try {\n for (const source of pendingSources) {\n if (source.disposed) continue;\n const wasFaulted = source.fault !== undefined;\n let changed = false;\n let force = false;\n if (!source.fault || source.recovering()) {\n try {\n const prepared = source.prepare(cause);\n changed = prepared.changed;\n force = prepared.force;\n source.fault = undefined;\n } catch (failure) {\n source.fault = errorFor(source, failure, 'source');\n errors.push(source.fault);\n }\n }\n const recovered = wasFaulted && !source.fault;\n if (changed) source.publish();\n if (source.fault || changed || force || recovered) {\n const output = source.outputs[0];\n emissions.add(output);\n output.forEachConsumer(enqueue);\n }\n }\n\n while (heap.length) {\n const processor = pop();\n if (processor.disposed) continue;\n const wasFaulted = processor.fault !== undefined;\n profile.projection('processedNodes');\n let changedOutputs: readonly OutputRecord[] = Object.freeze([]);\n const blocked = processor.dependencies.find(\n output => output.owner.fault || output.owner.disposed\n );\n if (blocked) {\n processor.fault = errorFor(\n processor,\n blocked.owner.fault ?? new ProjectionDisposedError(),\n 'blocked'\n );\n } else {\n const reset = wasFaulted || processor.dependencies.some(output => output.reset());\n try {\n changedOutputs = processor.evaluate(reset, cause, wasFaulted);\n const dependencyFailure = processor.dependencies.find(output => output.owner.fault)\n ?.owner.fault;\n if (dependencyFailure) throw dependencyFailure;\n processor.fault = undefined;\n } catch (failure) {\n const error = errorFor(processor, failure);\n processor.fault = error;\n if (!reset) {\n try {\n changedOutputs = processor.evaluate(true, cause, true);\n const dependencyFailure = processor.dependencies.find(output => output.owner.fault)\n ?.owner.fault;\n if (dependencyFailure) throw dependencyFailure;\n processor.fault = undefined;\n errors.push(error);\n } catch (rebuildFailure) {\n processor.fault = errorFor(processor, rebuildFailure);\n errors.push(processor.fault);\n }\n } else errors.push(error);\n }\n }\n completed.add(processor);\n const recovered = wasFaulted && !processor.fault;\n if (processor.fault) {\n processor.outputs.forEach(output => {\n emissions.add(output);\n output.forEachConsumer(enqueue);\n });\n } else {\n if (changedOutputs.length) {\n processor.publish();\n changedOutputs.forEach(output => emissions.add(output));\n }\n const propagated = recovered ? processor.outputs : changedOutputs;\n propagated.forEach(output => output.forEachConsumer(enqueue));\n }\n if (processor.fault || changedOutputs.length) {\n profile.projection('publishedNodes');\n }\n }\n } finally {\n lock(false);\n phase = 'idle';\n }\n };\n\n const flush = (): readonly ObserverError[] => {\n if (disposed || depth) return [];\n if (pendingSources.size || completed.size) profile.projection('flushes');\n phase = 'notify';\n lock(true);\n const reportFailures: unknown[] = [];\n try {\n emissions.forEach(output =>\n output.emit((listener, change) => {\n try {\n listener(change);\n } catch (cause) {\n errors.push(errorFor(output.owner, cause, 'listener'));\n }\n })\n );\n for (const error of errors.slice()) {\n try {\n onError(error);\n } catch (cause) {\n reportFailures.push(cause);\n }\n }\n return Object.freeze([\n ...errors.map(error =>\n Object.freeze({\n phase: error.phase === 'listener' ? ('listener' as const) : ('processor' as const),\n error,\n })\n ),\n ...reportFailures.map(error => Object.freeze({ phase: 'listener' as const, error })),\n ]);\n } finally {\n pendingSources.forEach(source => source.clear());\n completed.forEach(processor => processor.clear());\n pendingSources.clear();\n queued.clear();\n completed.clear();\n emissions.clear();\n errors.length = 0;\n reportingFailures = reportFailures;\n lock(false);\n phase = 'idle';\n }\n };\n\n const run = () => {\n settle();\n const result = flush();\n const failures = reportingFailures;\n reportingFailures = [];\n if (failures.length) throw new AggregateError(failures, 'Projection error reporter failed.');\n return result;\n };\n\n const batch = <T>(callback: () => T, options?: BatchOptions): T => {\n assertIdle();\n const outer = depth === 0;\n if (outer)\n activeBatch = Object.freeze({\n id: ++batchSequence,\n ...(options?.cause === undefined ? {} : { cause: options.cause }),\n });\n depth++;\n let failed = false;\n try {\n const value = callback();\n assertSynchronous(value);\n return value;\n } catch (error) {\n failed = true;\n throw error;\n } finally {\n depth--;\n if (!depth) {\n try {\n if (failed) {\n try {\n run();\n } catch {\n /* The original application error retains priority. */\n }\n } else run();\n } finally {\n activeBatch = undefined;\n }\n }\n }\n };\n\n const releaseProducer = (producer: ProducerRecord) => {\n assertIdle();\n if (producer.outputs.some(output => output.hasConsumers()))\n throw new Error('Projection producer is still used by another processor.');\n producer.disposed = true;\n if (producer.kind === 'processor') {\n producer.dependencies.forEach(output => output.detachConsumer(producer));\n processors.delete(producer);\n queued.delete(producer);\n completed.delete(producer);\n } else {\n sources.delete(producer);\n pendingSources.delete(producer);\n }\n const failures: unknown[] = [];\n try {\n producer.release();\n } catch (error) {\n failures.push(error);\n }\n try {\n producer.clear();\n } catch (error) {\n failures.push(error);\n }\n producer.outputs.forEach(output => emissions.delete(output));\n if (failures.length) throw failures[0];\n };\n\n return {\n assertActive,\n assertIdle,\n capture,\n settle,\n flush,\n run,\n registerGuard(guard: (locked: boolean) => void): Unsubscribe {\n assertActive();\n guards.add(guard);\n let registered = true;\n return () => {\n if (!registered) return;\n registered = false;\n guards.delete(guard);\n };\n },\n get active() {\n return !disposed;\n },\n addSource(source: SourceBoundaryRecord) {\n assertIdle();\n sources.add(source);\n },\n addProcessor(processor: ProcessorRecord) {\n assertIdle();\n processors.add(processor);\n processor.dependencies.forEach(output => output.attachConsumer(processor));\n },\n releaseProducer,\n order: () => sequence++,\n initialize<T>(callback: () => T): T {\n assertIdle();\n phase = 'compute';\n lock(true);\n try {\n return callback();\n } finally {\n lock(false);\n phase = 'idle';\n }\n },\n batch,\n batchContext: () => activeBatch,\n dispose() {\n if (disposed) return;\n assertIdle();\n disposed = true;\n const failures: unknown[] = [];\n processors.forEach(processor => {\n processor.disposed = true;\n try {\n processor.release();\n } catch (error) {\n failures.push(error);\n }\n });\n sources.forEach(source => {\n source.disposed = true;\n try {\n source.release();\n } catch (error) {\n failures.push(error);\n }\n });\n processors.clear();\n sources.clear();\n pendingSources.clear();\n heap.length = 0;\n queued.clear();\n completed.clear();\n emissions.clear();\n guards.clear();\n errors.length = 0;\n reportingFailures = [];\n if (failures.length) throw new AggregateError(failures, 'Projection cleanup failed.');\n },\n };\n};\n\nexport type Scheduler = ReturnType<typeof createScheduler>;\n\nexport const assertSynchronous = (value: unknown): void => {\n if (\n value != null &&\n (typeof value === 'object' || typeof value === 'function') &&\n 'then' in value &&\n typeof value.then === 'function'\n )\n throw new TypeError('Projection callbacks must be synchronous.');\n};\n\nexport const assertScope = (active: () => boolean) => {\n if (!active()) throw new Error('Projection reader or writer is no longer active.');\n};\n","export type KeyRelation = {\n replace(left: string, right: readonly string[]): boolean;\n delete(left: string): boolean;\n forward(left: string): readonly string[] | undefined;\n reverse(right: string): ReadonlySet<string> | undefined;\n lefts(): IterableIterator<string>;\n rights(): IterableIterator<string>;\n clear(): void;\n};\n\n/** Runtime-local domain-neutral many-to-many keyed relation. */\nexport const createKeyRelation = (): KeyRelation => {\n const forward = new Map<string, readonly string[]>();\n const reverse = new Map<string, Set<string>>();\n\n const detach = (left: string, right: readonly string[]): void => {\n for (const key of right) {\n const dependents = reverse.get(key);\n dependents?.delete(left);\n if (dependents?.size === 0) reverse.delete(key);\n }\n };\n\n const attach = (left: string, right: readonly string[]): void => {\n for (const key of right) {\n const dependents = reverse.get(key);\n if (dependents) dependents.add(left);\n else reverse.set(key, new Set([left]));\n }\n };\n\n return {\n replace(left, right) {\n const previous = forward.get(left) ?? Object.freeze([]);\n if (previous.length === right.length && previous.every((key, index) => key === right[index]))\n return false;\n detach(left, previous);\n if (!right.length) {\n forward.delete(left);\n return true;\n }\n const next = Object.freeze([...right]);\n forward.set(left, next);\n attach(left, next);\n return true;\n },\n delete(left) {\n const previous = forward.get(left);\n if (!previous) return false;\n detach(left, previous);\n forward.delete(left);\n return true;\n },\n forward: left => forward.get(left),\n reverse: right => reverse.get(right),\n lefts: () => forward.keys(),\n rights: () => reverse.keys(),\n clear() {\n forward.clear();\n reverse.clear();\n },\n };\n};\n","import type { Synchronous } from '@/runtime/contract';\nimport { isPlainObject } from '@/value/record';\nimport { collectionView, mapRead } from '@/projection/collection/view';\nimport { collectionChange } from '@/projection/collection/change';\nimport type { SourceContext } from '@/projection/contract';\nimport { readNamedDependencyEntries, snapshotDependencyValue } from '@/projection/dependency';\nimport {\n isProjection,\n outputDefinitionOf,\n type KeyedProjection,\n type Projection,\n} from '@/projection/definition';\nimport { assertSynchronous } from '@/projection/graph/scheduler';\nimport { createKeyRelation, type KeyRelation } from './relation';\n\nexport type SingularKeyedDependency<\n DriverKey extends string,\n DriverValue,\n SourceKey extends string,\n SourceValue,\n> = {\n readonly source: KeyedProjection<SourceKey, SourceValue>;\n readonly key: (value: DriverValue, key: DriverKey) => Synchronous<SourceKey | undefined>;\n readonly keys?: never;\n};\n\nexport type PluralKeyedDependency<\n DriverKey extends string,\n DriverValue,\n SourceKey extends string,\n SourceValue,\n> = {\n readonly source: KeyedProjection<SourceKey, SourceValue>;\n readonly keys: (value: DriverValue, key: DriverKey) => Synchronous<readonly SourceKey[]>;\n readonly key?: never;\n};\n\nexport type KeyedDependency<DriverKey extends string, DriverValue> =\n | (Projection<unknown> & {\n readonly source?: never;\n readonly key?: never;\n readonly keys?: never;\n })\n | SingularKeyedDependency<DriverKey, DriverValue, string, unknown>\n | PluralKeyedDependency<DriverKey, DriverValue, string, unknown>;\n\nexport type KeyedDependencyRecord<DriverKey extends string, DriverValue> = Readonly<\n Record<string, KeyedDependency<DriverKey, DriverValue>>\n>;\n\nexport type KeyedDependencies<DriverKey extends string, DriverValue, D extends object> = {\n readonly [P in keyof D]: P extends string ? KeyedDependency<DriverKey, DriverValue> : never;\n};\n\nexport type KeyedDependencyValues<D extends object> = {\n readonly [P in keyof D]: D[P] extends {\n readonly source: KeyedProjection<infer K extends string, infer V>;\n readonly keys: (...args: never[]) => unknown;\n }\n ? ReadonlyMap<K, V>\n : D[P] extends {\n readonly source: KeyedProjection<infer _K extends string, infer V>;\n }\n ? V | undefined\n : D[P] extends Projection<infer T>\n ? T\n : never;\n};\n\ntype CompiledDynamicKeyedDependency =\n | {\n readonly kind: 'one';\n readonly projection: Projection<unknown>;\n readonly select: (value: unknown, key: string) => unknown;\n }\n | {\n readonly kind: 'many';\n readonly projection: Projection<unknown>;\n readonly select: (value: unknown, key: string) => unknown;\n };\n\ntype CompiledKeyedDependency =\n | {\n readonly name: string;\n readonly kind: 'global';\n readonly projection: Projection<unknown>;\n }\n | ({ readonly name: string } & CompiledDynamicKeyedDependency);\n\nexport type CompiledKeyedDependencies = {\n readonly entries: readonly CompiledKeyedDependency[];\n readonly projections: readonly Projection<unknown>[];\n};\n\nexport const outputKind = (projection: Projection<unknown>): 'value' | 'collection' =>\n outputDefinitionOf(projection).kind;\n\nexport const assertKeyedProjection = (projection: Projection<unknown>, role: string): void => {\n if (outputKind(projection) !== 'collection')\n throw new TypeError(`${role} must be a keyed collection projection.`);\n};\n\nconst compileDynamicDependency = (\n value: unknown,\n label: string\n): CompiledDynamicKeyedDependency => {\n if (!isPlainObject(value) || isProjection(value))\n throw new TypeError(\n `${label} dependencies must be projections or singular/plural keyed lookups.`\n );\n const candidate: { source?: unknown; key?: unknown; keys?: unknown } = {};\n const allowed = new Set(['source', 'key', 'keys']);\n let hasKey = false;\n let hasKeys = false;\n for (const name of Reflect.ownKeys(value)) {\n if (typeof name !== 'string' || !allowed.has(name))\n throw new TypeError(`${label} dynamic keyed dependency contains an unknown property.`);\n const descriptor = Object.getOwnPropertyDescriptor(value, name);\n if (!descriptor?.enumerable || !('value' in descriptor))\n throw new TypeError(`${label} dynamic keyed dependency must use enumerable data properties.`);\n candidate[name as 'source' | 'key' | 'keys'] = descriptor.value;\n if (name === 'key') hasKey = true;\n if (name === 'keys') hasKeys = true;\n }\n if (!isProjection(candidate.source))\n throw new TypeError(`${label} dynamic keyed dependency source must be a projection.`);\n if (hasKey === hasKeys)\n throw new TypeError(\n `${label} dynamic keyed dependency must declare exactly one of key or keys.`\n );\n const singular = hasKey;\n const selector = singular ? candidate.key : candidate.keys;\n if (typeof selector !== 'function')\n throw new TypeError(`${label} dynamic keyed dependency selector must be a function.`);\n assertKeyedProjection(candidate.source, `${label} dynamic keyed dependency source`);\n return singular\n ? {\n kind: 'one',\n projection: candidate.source,\n select: selector as (value: unknown, key: string) => unknown,\n }\n : {\n kind: 'many',\n projection: candidate.source,\n select: selector as (value: unknown, key: string) => unknown,\n };\n};\n\nexport const compileKeyedDependencies = (\n driver: Projection<unknown>,\n dependencySpecs: KeyedDependencyRecord<string, unknown> | undefined,\n label: string\n): CompiledKeyedDependencies => {\n const entries: CompiledKeyedDependency[] = [];\n const projections: Projection<unknown>[] = [driver];\n if (dependencySpecs === undefined)\n return Object.freeze({\n entries: Object.freeze(entries),\n projections: Object.freeze(projections),\n });\n for (const { name, value: dependency } of readNamedDependencyEntries(dependencySpecs, label)) {\n if (isProjection(dependency)) {\n entries.push(Object.freeze({ name, kind: 'global' as const, projection: dependency }));\n projections.push(dependency);\n continue;\n }\n const dynamic = compileDynamicDependency(dependency, label);\n entries.push(Object.freeze({ name, ...dynamic }));\n projections.push(dynamic.projection);\n }\n return Object.freeze({\n entries: Object.freeze(entries),\n projections: Object.freeze(projections),\n });\n};\n\nconst selectedKeys = (\n dependency: CompiledDynamicKeyedDependency,\n value: unknown,\n key: string\n): readonly string[] => {\n const result = dependency.select(value, key);\n assertSynchronous(result);\n if (dependency.kind === 'one') {\n if (result === undefined) return Object.freeze([]);\n if (typeof result !== 'string')\n throw new TypeError('Dynamic keyed dependency key must be a string or undefined.');\n return Object.freeze([result]);\n }\n if (!Array.isArray(result))\n throw new TypeError('Dynamic keyed dependency keys must be an array of strings.');\n const seen = new Set<string>();\n const keys: string[] = [];\n for (const selected of result) {\n if (typeof selected !== 'string')\n throw new TypeError('Dynamic keyed dependency keys must contain only strings.');\n if (seen.has(selected))\n throw new TypeError('Dynamic keyed dependency keys must not contain duplicates.');\n seen.add(selected);\n keys.push(selected);\n }\n return Object.freeze(keys);\n};\n\nexport type KeyedDependencyRuntime = {\n prepare(sources: readonly SourceContext[], reset: boolean): void;\n resolve(\n driverValue: unknown,\n driverKey: string,\n sources: readonly SourceContext[]\n ): Readonly<Record<string, unknown>>;\n driverChanged(source: SourceContext): boolean;\n collectInvalidated(sources: readonly SourceContext[], dirty: Set<string>): boolean;\n remove(driverKey: string): void;\n clearBindings(): void;\n remember(sources: readonly SourceContext[]): void;\n release(): void;\n};\n\nconst emptyValues: Readonly<Record<string, unknown>> = Object.freeze(\n Object.create(null) as Record<string, unknown>\n);\n\nexport const createKeyedDependencyRuntime = (\n compiled: CompiledKeyedDependencies\n): KeyedDependencyRuntime => {\n type GlobalDependencyState = {\n readonly kind: 'global';\n readonly entry: Extract<CompiledKeyedDependency, { readonly kind: 'global' }>;\n readonly sourceIndex: number;\n revision: number;\n globalValue: unknown;\n };\n type DynamicDependencyState = {\n readonly kind: 'dynamic';\n readonly entry: Exclude<CompiledKeyedDependency, { readonly kind: 'global' }>;\n readonly sourceIndex: number;\n readonly relation: KeyRelation;\n revision: number;\n };\n type DependencyState = GlobalDependencyState | DynamicDependencyState;\n const states: DependencyState[] = compiled.entries.map((entry, index) =>\n entry.kind === 'global'\n ? { kind: 'global', entry, sourceIndex: index + 1, revision: -1, globalValue: undefined }\n : {\n kind: 'dynamic',\n entry,\n sourceIndex: index + 1,\n relation: createKeyRelation(),\n revision: -1,\n }\n );\n let driverRevision = -1;\n\n return {\n prepare(sources, reset) {\n for (const state of states) {\n if (state.kind !== 'global') continue;\n const source = sources[state.sourceIndex];\n if (reset || state.revision !== source.revision)\n state.globalValue = snapshotDependencyValue(source);\n }\n },\n resolve(driverValue, driverKey, sources) {\n if (!states.length) return emptyValues;\n const values = Object.create(null) as Record<string, unknown>;\n for (const state of states) {\n if (state.kind === 'global') {\n values[state.entry.name] = state.globalValue;\n continue;\n }\n const dependency = state.entry;\n const source = sources[state.sourceIndex];\n if (source.kind !== 'collection')\n throw new TypeError('Dynamic keyed dependency resolved to a non-collection source.');\n const keys = selectedKeys(dependency, driverValue, driverKey);\n state.relation.replace(driverKey, keys);\n if (dependency.kind === 'one') {\n const selected = keys[0];\n values[dependency.name] = selected === undefined ? undefined : source.read.get(selected);\n continue;\n }\n const selected = new Map<string, unknown>();\n for (const key of keys) if (source.read.has(key)) selected.set(key, source.read.get(key));\n values[dependency.name] = collectionView(mapRead(selected));\n }\n return Object.freeze(values);\n },\n driverChanged(source) {\n return driverRevision !== source.revision;\n },\n collectInvalidated(sources, dirty) {\n let all = false;\n for (const state of states) {\n const source = sources[state.sourceIndex];\n if (state.revision === source.revision) continue;\n const dependency = state.entry;\n if (state.kind === 'global') {\n all = true;\n continue;\n }\n if (source.kind !== 'collection' || !source.change || source.change.kind === 'reset') {\n all = true;\n continue;\n }\n for (const sourceKey of collectionChange.keys(source.change))\n for (const dependent of state.relation.reverse(sourceKey) ?? []) dirty.add(dependent);\n }\n return all;\n },\n remove(driverKey) {\n for (const state of states) if (state.kind === 'dynamic') state.relation.delete(driverKey);\n },\n clearBindings() {\n for (const state of states) if (state.kind === 'dynamic') state.relation.clear();\n },\n remember(sources) {\n driverRevision = sources[0]?.revision ?? -1;\n for (const state of states) state.revision = sources[state.sourceIndex].revision;\n },\n release() {\n for (const state of states) {\n state.revision = -1;\n if (state.kind === 'global') state.globalValue = undefined;\n else state.relation.clear();\n }\n driverRevision = -1;\n },\n };\n};\n","import type { CollectionRead, SourceContext } from '@/projection/contract';\nimport { defineProcessor, type KeyedProjection } from '@/projection/definition';\nimport { assertSynchronous } from '@/projection/graph/scheduler';\nimport {\n assertKeyedProjection,\n compileKeyedDependencies,\n createKeyedDependencyRuntime,\n type KeyedDependencyRecord,\n} from './dependency';\n\nexport const keyedAbsent = Symbol('keyed-transform-absent');\nexport type KeyedTransformResult<T> = T | typeof keyedAbsent;\n\nexport type KeyedTransformContext<K extends string, V, State> = {\n readonly key: K;\n readonly value: V;\n readonly dependencies: Readonly<Record<string, unknown>>;\n readonly state: State;\n readonly reset: boolean;\n readonly cause: unknown;\n};\n\nexport type KeyedTransformDefinition<K extends string, V, T, State> = {\n readonly source: KeyedProjection<K, V>;\n readonly dependencies?: KeyedDependencyRecord<K, V>;\n readonly equality?: (previous: T, next: T) => boolean;\n readonly name: string;\n readonly state?: (value: V, key: K) => State;\n readonly evaluate: (context: KeyedTransformContext<K, V, State>) => KeyedTransformResult<T>;\n};\n\n/** Shared driver-keyed lifecycle for pure and retained keyed transforms. */\nexport const createKeyedTransform = <K extends string, V, T, State = undefined>(\n definition: KeyedTransformDefinition<K, V, T, State>\n): KeyedProjection<K, T> => {\n assertKeyedProjection(definition.source, `${definition.name} source`);\n const compiled = compileKeyedDependencies(\n definition.source,\n definition.dependencies as KeyedDependencyRecord<string, unknown> | undefined,\n definition.name\n );\n const [projection] = defineProcessor({\n dependencies: compiled.projections,\n outputs: [\n {\n kind: 'collection',\n equality: (definition.equality ?? Object.is) as (\n previous: unknown,\n next: unknown\n ) => boolean,\n },\n ],\n create: () => {\n const dependencies = createKeyedDependencyRuntime(compiled);\n const states = new Map<string, State>();\n\n const dropState = (key: string): void => {\n states.delete(key);\n dependencies.remove(key);\n };\n\n return {\n evaluate: evaluation => {\n const driver = evaluation.sources[0];\n const output = evaluation.outputs[0];\n if (driver.kind !== 'collection' || output.kind !== 'collection')\n throw new Error(`${definition.name} requires collection input and output.`);\n dependencies.prepare(evaluation.sources, evaluation.reset);\n\n const stateFor = (key: string, value: V): State => {\n if (states.has(key)) return states.get(key) as State;\n const state = definition.state\n ? definition.state(value, key as K)\n : (undefined as State);\n assertSynchronous(state);\n if (definition.state) states.set(key, state);\n return state;\n };\n\n const project = (key: string): boolean => {\n if (!driver.read.has(key)) return false;\n const value = driver.read.get(key) as V;\n const beforePresent = output.previous.has(key);\n const next = definition.evaluate({\n key: key as K,\n value,\n dependencies: dependencies.resolve(value, key, evaluation.sources),\n state: stateFor(key, value),\n reset: evaluation.reset,\n cause: evaluation.cause,\n });\n assertSynchronous(next);\n if (next === keyedAbsent) output.output.remove(key);\n else output.output.set(key, next);\n return beforePresent !== output.next.has(key);\n };\n\n if (evaluation.reset) {\n dependencies.clearBindings();\n const ids = driver.read.ids();\n const present = new Set(ids);\n for (const key of [...states.keys()]) if (!present.has(key)) states.delete(key);\n for (const key of ids) project(key);\n output.output.order(ids.filter(key => output.next.has(key)));\n dependencies.remember(evaluation.sources);\n return;\n }\n\n const dirty = new Set<string>();\n let all = false;\n let updateOrder = false;\n let membershipChanged = false;\n if (dependencies.driverChanged(driver)) {\n const change = driver.change;\n if (!change || change.kind === 'reset') {\n all = true;\n updateOrder = true;\n for (const key of output.previous.ids()) {\n if (driver.read.has(key)) continue;\n output.output.remove(key);\n dropState(key);\n membershipChanged = true;\n }\n } else {\n for (const entry of change.removed) {\n membershipChanged ||= output.previous.has(entry.key);\n output.output.remove(entry.key);\n dropState(entry.key);\n dirty.delete(entry.key);\n }\n for (const entry of change.added) dirty.add(entry.key);\n for (const entry of change.updated) dirty.add(entry.key);\n updateOrder = Boolean(change.order);\n }\n }\n\n all ||= dependencies.collectInvalidated(evaluation.sources, dirty);\n if (all) for (const key of driver.read.ids()) dirty.add(key);\n for (const key of dirty) {\n const changedMembership = project(key);\n membershipChanged ||= changedMembership;\n }\n if (updateOrder || membershipChanged)\n output.output.order(driver.read.ids().filter(key => output.next.has(key)));\n dependencies.remember(evaluation.sources);\n },\n release: () => {\n states.clear();\n dependencies.release();\n },\n };\n },\n name: definition.name,\n });\n return projection as KeyedProjection<K, T>;\n};\n"],"mappings":";AAkDA,MAAa,UAAU;CACrB,aAAa,KAAmC,SAAS,MAAM;CAG/D,WAAW,KAAiC,SAAS,MAAM;CAG3D,SAAS,QAAkC;CAG3C,MAAM;EACJ,iBAAiB;EAGjB,gBAAgB;EAGhB,gBAAgB,UAAkB;EAGnC;CACD,UAAU;EACR,YAAY;EAGZ,iBAAiB;EAGlB;CACD,SAAS;EACP,YAAY,UAAkB;EAM9B,kBAAkB;EAGlB,oBAAoB;EAGpB,wBAAwB;EAGxB,uBAAuB;EAGxB;CACD,QAAQ;EACN,aAAa;EAGb,eAAe;EAGhB;CACD,YAAY;EACV,kBAAkB;EAGlB,uBAAuB;EAGxB;CACD,iBAAiB;EACf,YAAY;EAGZ,QAAQ,UAAkB;EAM3B;CACD,gBAAgB;EACd,cAAc;EAGd,aAAa,SAAS,MAAM;EAG5B,mBAAmB;EAGpB;CACD,cAAc;EACZ,eAAe;EAGf,eAAe;EAGf,oBAAoB;EAGrB;CACF;;;ACJD,MAAM,8BAAc,IAAI,SAAgC;AAExD,MAAM,aAAgB,UAA8B,WAAkC;CACpF,MAAM,SAAS,OAAO,OAAO,EAAE,CAAC;AAChC,aAAY,IAAI,QAAQ,OAAO,OAAO;EAAE;EAAU;EAAQ,CAAC,CAAC;AAC5D,QAAO;;AAGT,MAAa,iBAAiB,eAAmD;CAC/E,MAAM,MAAM,YAAY,IAAI,WAAW;AACvC,KAAI,CAAC,IAAK,OAAM,IAAI,UAAU,iCAAiC;AAC/D,QAAO;;AAGT,MAAa,cAAc,eACzB,cAAc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