@graphrefly/ts 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/LICENSE +21 -0
  2. package/dist/adapters/index.cjs +9015 -0
  3. package/dist/adapters/index.cjs.map +1 -0
  4. package/dist/adapters/index.d.cts +678 -0
  5. package/dist/adapters/index.d.ts +678 -0
  6. package/dist/adapters/index.js +2894 -0
  7. package/dist/adapters/index.js.map +1 -0
  8. package/dist/adapters/observe-storage.cjs +260 -0
  9. package/dist/adapters/observe-storage.cjs.map +1 -0
  10. package/dist/adapters/observe-storage.d.cts +77 -0
  11. package/dist/adapters/observe-storage.d.ts +77 -0
  12. package/dist/adapters/observe-storage.js +161 -0
  13. package/dist/adapters/observe-storage.js.map +1 -0
  14. package/dist/append-log-DisvEReb.d.cts +189 -0
  15. package/dist/append-log-DzKMmjxx.d.ts +189 -0
  16. package/dist/chunk-2ILL7HQI.js +1189 -0
  17. package/dist/chunk-2ILL7HQI.js.map +1 -0
  18. package/dist/chunk-4VLAQHZI.js +330 -0
  19. package/dist/chunk-4VLAQHZI.js.map +1 -0
  20. package/dist/chunk-6PHB5CJS.js +229 -0
  21. package/dist/chunk-6PHB5CJS.js.map +1 -0
  22. package/dist/chunk-COHO25CZ.js +2449 -0
  23. package/dist/chunk-COHO25CZ.js.map +1 -0
  24. package/dist/chunk-D6BG7U6A.js +161 -0
  25. package/dist/chunk-D6BG7U6A.js.map +1 -0
  26. package/dist/chunk-DJC4CHLQ.js +818 -0
  27. package/dist/chunk-DJC4CHLQ.js.map +1 -0
  28. package/dist/chunk-DK554R7P.js +67 -0
  29. package/dist/chunk-DK554R7P.js.map +1 -0
  30. package/dist/chunk-DKP56CSW.js +322 -0
  31. package/dist/chunk-DKP56CSW.js.map +1 -0
  32. package/dist/chunk-G4M3NHRJ.js +688 -0
  33. package/dist/chunk-G4M3NHRJ.js.map +1 -0
  34. package/dist/chunk-GAJW5I5P.js +1 -0
  35. package/dist/chunk-GAJW5I5P.js.map +1 -0
  36. package/dist/chunk-GDL26N2T.js +282 -0
  37. package/dist/chunk-GDL26N2T.js.map +1 -0
  38. package/dist/chunk-GTPCOEOZ.js +741 -0
  39. package/dist/chunk-GTPCOEOZ.js.map +1 -0
  40. package/dist/chunk-H2HTHFVN.js +1 -0
  41. package/dist/chunk-H2HTHFVN.js.map +1 -0
  42. package/dist/chunk-HDRL4VQQ.js +218 -0
  43. package/dist/chunk-HDRL4VQQ.js.map +1 -0
  44. package/dist/chunk-I3IHOHCJ.js +2267 -0
  45. package/dist/chunk-I3IHOHCJ.js.map +1 -0
  46. package/dist/chunk-JIMUDQN3.js +965 -0
  47. package/dist/chunk-JIMUDQN3.js.map +1 -0
  48. package/dist/chunk-JR4IKCR2.js +462 -0
  49. package/dist/chunk-JR4IKCR2.js.map +1 -0
  50. package/dist/chunk-K3FXTC3I.js +165 -0
  51. package/dist/chunk-K3FXTC3I.js.map +1 -0
  52. package/dist/chunk-OOEN33FB.js +65 -0
  53. package/dist/chunk-OOEN33FB.js.map +1 -0
  54. package/dist/chunk-PKVBHGBM.js +554 -0
  55. package/dist/chunk-PKVBHGBM.js.map +1 -0
  56. package/dist/chunk-RIIOUTGM.js +1857 -0
  57. package/dist/chunk-RIIOUTGM.js.map +1 -0
  58. package/dist/chunk-SCRFRCGR.js +33 -0
  59. package/dist/chunk-SCRFRCGR.js.map +1 -0
  60. package/dist/chunk-SWTLEQL6.js +53 -0
  61. package/dist/chunk-SWTLEQL6.js.map +1 -0
  62. package/dist/chunk-SZAETNNA.js +1 -0
  63. package/dist/chunk-SZAETNNA.js.map +1 -0
  64. package/dist/chunk-TEW47IVR.js +49 -0
  65. package/dist/chunk-TEW47IVR.js.map +1 -0
  66. package/dist/chunk-Y3ZLRGHC.js +1482 -0
  67. package/dist/chunk-Y3ZLRGHC.js.map +1 -0
  68. package/dist/chunk-Z2ANQ6JW.js +149 -0
  69. package/dist/chunk-Z2ANQ6JW.js.map +1 -0
  70. package/dist/codec-BB7p8fJc.d.cts +38 -0
  71. package/dist/codec-BB7p8fJc.d.ts +38 -0
  72. package/dist/composition/index.cjs +2505 -0
  73. package/dist/composition/index.cjs.map +1 -0
  74. package/dist/composition/index.d.cts +95 -0
  75. package/dist/composition/index.d.ts +95 -0
  76. package/dist/composition/index.js +19 -0
  77. package/dist/composition/index.js.map +1 -0
  78. package/dist/core/index.cjs +2475 -0
  79. package/dist/core/index.cjs.map +1 -0
  80. package/dist/core/index.d.cts +25 -0
  81. package/dist/core/index.d.ts +25 -0
  82. package/dist/core/index.js +74 -0
  83. package/dist/core/index.js.map +1 -0
  84. package/dist/cqrs/index.cjs +595 -0
  85. package/dist/cqrs/index.cjs.map +1 -0
  86. package/dist/cqrs/index.d.cts +200 -0
  87. package/dist/cqrs/index.d.ts +200 -0
  88. package/dist/cqrs/index.js +557 -0
  89. package/dist/cqrs/index.js.map +1 -0
  90. package/dist/data-structures/index.cjs +4277 -0
  91. package/dist/data-structures/index.cjs.map +1 -0
  92. package/dist/data-structures/index.d.cts +22 -0
  93. package/dist/data-structures/index.d.ts +22 -0
  94. package/dist/data-structures/index.js +31 -0
  95. package/dist/data-structures/index.js.map +1 -0
  96. package/dist/describe-BZb7AS2y.d.ts +57 -0
  97. package/dist/describe-Ciu8SUnN.d.cts +57 -0
  98. package/dist/graph/index.cjs +7832 -0
  99. package/dist/graph/index.cjs.map +1 -0
  100. package/dist/graph/index.d.cts +251 -0
  101. package/dist/graph/index.d.ts +251 -0
  102. package/dist/graph/index.js +131 -0
  103. package/dist/graph/index.js.map +1 -0
  104. package/dist/graph-DfdF9zy4.d.ts +666 -0
  105. package/dist/graph-s23RbbFO.d.cts +666 -0
  106. package/dist/index-CAEmLCYF.d.cts +166 -0
  107. package/dist/index-SnzZu3x7.d.ts +166 -0
  108. package/dist/index.cjs +15409 -0
  109. package/dist/index.cjs.map +1 -0
  110. package/dist/index.d.cts +23 -0
  111. package/dist/index.d.ts +23 -0
  112. package/dist/index.js +582 -0
  113. package/dist/index.js.map +1 -0
  114. package/dist/messages-BZqrGGm1.d.cts +55 -0
  115. package/dist/messages-BZqrGGm1.d.ts +55 -0
  116. package/dist/messaging/index.cjs +818 -0
  117. package/dist/messaging/index.cjs.map +1 -0
  118. package/dist/messaging/index.d.cts +235 -0
  119. package/dist/messaging/index.d.ts +235 -0
  120. package/dist/messaging/index.js +767 -0
  121. package/dist/messaging/index.js.map +1 -0
  122. package/dist/observe-event-log-0SVsx7JG.d.cts +88 -0
  123. package/dist/observe-event-log-Dnm76owp.d.ts +88 -0
  124. package/dist/operators/index.cjs +3774 -0
  125. package/dist/operators/index.cjs.map +1 -0
  126. package/dist/operators/index.d.cts +308 -0
  127. package/dist/operators/index.d.ts +308 -0
  128. package/dist/operators/index.js +112 -0
  129. package/dist/operators/index.js.map +1 -0
  130. package/dist/orchestration/index.cjs +3541 -0
  131. package/dist/orchestration/index.cjs.map +1 -0
  132. package/dist/orchestration/index.d.cts +302 -0
  133. package/dist/orchestration/index.d.ts +302 -0
  134. package/dist/orchestration/index.js +1004 -0
  135. package/dist/orchestration/index.js.map +1 -0
  136. package/dist/patterns/index.cjs +1045 -0
  137. package/dist/patterns/index.cjs.map +1 -0
  138. package/dist/patterns/index.d.cts +39 -0
  139. package/dist/patterns/index.d.ts +39 -0
  140. package/dist/patterns/index.js +33 -0
  141. package/dist/patterns/index.js.map +1 -0
  142. package/dist/reactive-collection-BxBqtIOE.d.cts +344 -0
  143. package/dist/reactive-collection-Cb1II1Fi.d.ts +344 -0
  144. package/dist/reactive-collection-storage-BNiEc-Gd.d.ts +217 -0
  145. package/dist/reactive-collection-storage-D-KmjE0J.d.cts +217 -0
  146. package/dist/reactive-map-BcB4KsQR.d.ts +256 -0
  147. package/dist/reactive-map-D-g3dv8I.d.cts +256 -0
  148. package/dist/read-through-B1CYPfq_.d.cts +82 -0
  149. package/dist/read-through-DwyJhGs1.d.ts +82 -0
  150. package/dist/render/index.cjs +250 -0
  151. package/dist/render/index.cjs.map +1 -0
  152. package/dist/render/index.d.cts +58 -0
  153. package/dist/render/index.d.ts +58 -0
  154. package/dist/render/index.js +20 -0
  155. package/dist/render/index.js.map +1 -0
  156. package/dist/resilience-Dig3Q7n0.d.cts +45 -0
  157. package/dist/resilience-Dig3Q7n0.d.ts +45 -0
  158. package/dist/semantic-memory-graph-BYoIlP35.d.cts +356 -0
  159. package/dist/semantic-memory-graph-CxyXLms3.d.ts +356 -0
  160. package/dist/solutions/index.cjs +3249 -0
  161. package/dist/solutions/index.cjs.map +1 -0
  162. package/dist/solutions/index.d.cts +520 -0
  163. package/dist/solutions/index.d.ts +520 -0
  164. package/dist/solutions/index.js +31 -0
  165. package/dist/solutions/index.js.map +1 -0
  166. package/dist/sources/browser.cjs +3095 -0
  167. package/dist/sources/browser.cjs.map +1 -0
  168. package/dist/sources/browser.d.cts +39 -0
  169. package/dist/sources/browser.d.ts +39 -0
  170. package/dist/sources/browser.js +137 -0
  171. package/dist/sources/browser.js.map +1 -0
  172. package/dist/sources/index.cjs +3021 -0
  173. package/dist/sources/index.cjs.map +1 -0
  174. package/dist/sources/index.d.cts +7 -0
  175. package/dist/sources/index.d.ts +7 -0
  176. package/dist/sources/index.js +63 -0
  177. package/dist/sources/index.js.map +1 -0
  178. package/dist/sources/node.cjs +675 -0
  179. package/dist/sources/node.cjs.map +1 -0
  180. package/dist/sources/node.d.cts +109 -0
  181. package/dist/sources/node.d.ts +109 -0
  182. package/dist/sources/node.js +639 -0
  183. package/dist/sources/node.js.map +1 -0
  184. package/dist/storage/browser.cjs +777 -0
  185. package/dist/storage/browser.cjs.map +1 -0
  186. package/dist/storage/browser.d.cts +40 -0
  187. package/dist/storage/browser.d.ts +40 -0
  188. package/dist/storage/browser.js +275 -0
  189. package/dist/storage/browser.js.map +1 -0
  190. package/dist/storage/index.cjs +1989 -0
  191. package/dist/storage/index.cjs.map +1 -0
  192. package/dist/storage/index.d.cts +92 -0
  193. package/dist/storage/index.d.ts +92 -0
  194. package/dist/storage/index.js +161 -0
  195. package/dist/storage/index.js.map +1 -0
  196. package/dist/storage/node.cjs +898 -0
  197. package/dist/storage/node.cjs.map +1 -0
  198. package/dist/storage/node.d.cts +66 -0
  199. package/dist/storage/node.d.ts +66 -0
  200. package/dist/storage/node.js +402 -0
  201. package/dist/storage/node.js.map +1 -0
  202. package/dist/testing/index.cjs +95 -0
  203. package/dist/testing/index.cjs.map +1 -0
  204. package/dist/testing/index.d.cts +20 -0
  205. package/dist/testing/index.d.ts +20 -0
  206. package/dist/testing/index.js +8 -0
  207. package/dist/testing/index.js.map +1 -0
  208. package/dist/types-bNMSWKqF.d.cts +732 -0
  209. package/dist/types-h12mNYbq.d.ts +732 -0
  210. package/package.json +250 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/messaging/index.ts"],"sourcesContent":["/**\n * Reusable application-infrastructure messaging namespace.\n *\n * Retained root messaging utilities land here only after B63 re-derives them\n * onto the D125 package DAG.\n */\n\nimport { depBatch, type NodeFn } from \"../ctx/types.js\";\nimport { type Graph, releaseGraphNodes } from \"../graph/graph.js\";\nimport type { Node } from \"../node/node.js\";\n\nexport interface MessageEnvelope<T = unknown> {\n\treadonly topic: string;\n\treadonly seq: number;\n\treadonly payload: T;\n\treadonly key?: string;\n\treadonly timestampMs: number;\n}\n\n/**\n * Minimal JSON Schema vocabulary for cross-graph/topic payload descriptions.\n *\n * D125/D132 keep this as passive messaging vocabulary: GraphReFly does not ship\n * a validator here and does not make schemas protocol messages.\n */\nexport interface JsonSchema {\n\treadonly type?:\n\t\t| \"string\"\n\t\t| \"number\"\n\t\t| \"integer\"\n\t\t| \"boolean\"\n\t\t| \"object\"\n\t\t| \"array\"\n\t\t| \"null\"\n\t\t| readonly (\"string\" | \"number\" | \"integer\" | \"boolean\" | \"object\" | \"array\" | \"null\")[];\n\treadonly properties?: Readonly<Record<string, JsonSchema>>;\n\treadonly required?: readonly string[];\n\treadonly additionalProperties?: boolean | JsonSchema;\n\treadonly items?: JsonSchema | readonly JsonSchema[];\n\treadonly enum?: readonly unknown[];\n\treadonly const?: unknown;\n\treadonly $ref?: string;\n\treadonly definitions?: Readonly<Record<string, JsonSchema>>;\n\treadonly description?: string;\n\treadonly title?: string;\n}\n\n/**\n * Recommended passive envelope for payloads that cross topic, agent, or graph\n * boundaries. It is an application fact shape, not a required protocol type.\n */\nexport interface TopicMessage<T = unknown> {\n\treadonly id: string;\n\treadonly schema?: JsonSchema;\n\treadonly expiresAt?: string;\n\treadonly correlationId?: string;\n\treadonly payload: T;\n}\n\nexport const PROMPTS_TOPIC = \"prompts\";\nexport const RESPONSES_TOPIC = \"responses\";\nexport const INJECTIONS_TOPIC = \"injections\";\nexport const DEFERRED_TOPIC = \"deferred\";\nexport const SPAWNS_TOPIC = \"spawns\";\nexport const CONTEXT_TOPIC = \"context\";\nexport const TODOS_TOPIC = \"todos\";\n\nexport const STANDARD_TOPICS = Object.freeze([\n\tPROMPTS_TOPIC,\n\tRESPONSES_TOPIC,\n\tINJECTIONS_TOPIC,\n\tDEFERRED_TOPIC,\n\tSPAWNS_TOPIC,\n\tCONTEXT_TOPIC,\n\tTODOS_TOPIC,\n] as const);\n\nexport type StandardTopic = (typeof STANDARD_TOPICS)[number];\n\nexport interface MessageBusEvent<T = unknown> {\n\treadonly kind: \"publish\" | \"complete\" | \"error\";\n\treadonly topic: string;\n\treadonly seq?: number;\n\treadonly payload?: T;\n\treadonly error?: unknown;\n}\n\nexport interface MessageBusOptions<TTopic extends string = string> {\n\treadonly topics: readonly TTopic[];\n\treadonly name?: string;\n\treadonly now?: () => number;\n}\n\nexport interface MessageBus<TTopic extends string = string> {\n\treadonly topics: readonly TTopic[];\n\ttopic<T = unknown>(name: TTopic): Node<MessageEnvelope<T>>;\n\tpublish<T = unknown>(name: TTopic, payload: T, opts?: { key?: string }): MessageEnvelope<T>;\n\thas(name: string): name is TTopic;\n}\n\ninterface MessageBusState<TTopic extends string> {\n\treadonly graph: Graph;\n\treadonly name: string;\n\treadonly now: () => number;\n\treadonly topics: readonly TTopic[];\n\treadonly records: Map<TTopic, TopicRecord>;\n\tseq: number;\n}\n\ntype ProducedTopicMessage<T = unknown> =\n\t| { readonly kind: \"publish\"; readonly envelope: MessageEnvelope<T> }\n\t| { readonly kind: \"error\"; readonly topic: string; readonly error: unknown };\n\ninterface TopicRecord {\n\treadonly node: Node<MessageEnvelope<unknown>>;\n\treadonly producers: Node<ProducedTopicMessage<unknown>>[];\n\treadonly body: NodeFn;\n}\n\nconst busStates = new WeakMap<MessageBus<string>, MessageBusState<string>>();\n\nexport interface ToTopicOptions {\n\treadonly name?: string;\n\treadonly keyOf?: (value: unknown) => string | undefined;\n}\n\nexport interface ToTopicBundle<T> {\n\treadonly events: Node<MessageBusEvent<T>>;\n}\n\nexport type DynamicHubUnknownTopicPolicy = \"drop\" | \"error\" | \"dead-letter\" | \"create-as-fact\";\n\nexport interface DynamicHubOptions {\n\treadonly name?: string;\n\treadonly topics?: readonly string[];\n\treadonly unknownTopic?: DynamicHubUnknownTopicPolicy;\n\treadonly deadLetter?: boolean;\n\treadonly maxTopics?: number;\n\treadonly maxTopicLength?: number;\n\treadonly now?: () => number;\n}\n\nexport interface DynamicHubMetadata {\n\treadonly seq: number;\n\treadonly cursor: number;\n\treadonly timestampMs: number;\n}\n\nexport type DynamicHubEventKind =\n\t| \"create\"\n\t| \"delete\"\n\t| \"message\"\n\t| \"subscribe\"\n\t| \"close\"\n\t| \"error\"\n\t| \"dead-letter\";\n\nexport type DynamicHubCommand<T = unknown> =\n\t| {\n\t\t\treadonly kind: \"create\";\n\t\t\treadonly topic: string;\n\t\t\treadonly key?: string;\n\t\t\treadonly payload?: T;\n\t }\n\t| {\n\t\t\treadonly kind: \"delete\";\n\t\t\treadonly topic: string;\n\t\t\treadonly key?: string;\n\t\t\treadonly payload?: T;\n\t }\n\t| {\n\t\t\treadonly kind: \"publish\";\n\t\t\treadonly topic: string;\n\t\t\treadonly payload: T;\n\t\t\treadonly key?: string;\n\t }\n\t| {\n\t\t\treadonly kind: \"subscribe\";\n\t\t\treadonly topic: string;\n\t\t\treadonly key?: string;\n\t\t\treadonly payload?: T;\n\t }\n\t| {\n\t\t\treadonly kind: \"close\";\n\t\t\treadonly key?: string;\n\t\t\treadonly payload?: T;\n\t };\n\nexport interface DynamicHubStatus {\n\treadonly open: boolean;\n\treadonly topics: readonly string[];\n\treadonly seq: number;\n\treadonly cursor: number;\n\treadonly lastEventKind?: DynamicHubEventKind;\n}\n\ninterface DynamicHubEventFrame {\n\treadonly meta: DynamicHubMetadata;\n\treadonly status: DynamicHubStatus;\n}\n\nexport type DynamicHubEvent<T = unknown> = DynamicHubEventFrame &\n\t(\n\t\t| {\n\t\t\t\treadonly kind: \"create\";\n\t\t\t\treadonly topic: string;\n\t\t\t\treadonly key?: string;\n\t\t\t\treadonly payload?: T;\n\t\t }\n\t\t| {\n\t\t\t\treadonly kind: \"delete\";\n\t\t\t\treadonly topic: string;\n\t\t\t\treadonly key?: string;\n\t\t\t\treadonly payload?: T;\n\t\t }\n\t\t| {\n\t\t\t\treadonly kind: \"message\";\n\t\t\t\treadonly topic: string;\n\t\t\t\treadonly payload: T;\n\t\t\t\treadonly key?: string;\n\t\t }\n\t\t| {\n\t\t\t\treadonly kind: \"subscribe\";\n\t\t\t\treadonly topic: string;\n\t\t\t\treadonly key?: string;\n\t\t\t\treadonly payload?: T;\n\t\t }\n\t\t| {\n\t\t\t\treadonly kind: \"close\";\n\t\t\t\treadonly key?: string;\n\t\t\t\treadonly payload?: T;\n\t\t }\n\t\t| {\n\t\t\t\treadonly kind: \"error\";\n\t\t\t\treadonly topic?: string;\n\t\t\t\treadonly error: string;\n\t\t\t\treadonly command: unknown;\n\t\t }\n\t\t| {\n\t\t\t\treadonly kind: \"dead-letter\";\n\t\t\t\treadonly topic?: string;\n\t\t\t\treadonly reason: string;\n\t\t\t\treadonly command: unknown;\n\t\t }\n\t);\n\nexport interface DynamicHubError {\n\treadonly topic?: string;\n\treadonly error: string;\n\treadonly command: unknown;\n\treadonly meta: DynamicHubMetadata;\n}\n\nexport interface DynamicHubDeadLetter {\n\treadonly topic?: string;\n\treadonly reason: string;\n\treadonly command: unknown;\n\treadonly meta: DynamicHubMetadata;\n}\n\nexport interface DynamicHub<T = unknown> {\n\treadonly command: Node<DynamicHubCommand<T>>;\n\treadonly events: Node<DynamicHubEvent<T>>;\n\treadonly status: Node<DynamicHubStatus>;\n\treadonly errors: Node<DynamicHubError>;\n\treadonly deadLetter?: Node<DynamicHubDeadLetter>;\n\tcreate(topic: string, opts?: { key?: string; payload?: T }): DynamicHubCommand<T>;\n\tdelete(topic: string, opts?: { key?: string; payload?: T }): DynamicHubCommand<T>;\n\tpublish(topic: string, payload: T, opts?: { key?: string }): DynamicHubCommand<T>;\n\tsubscribeTopic(topic: string, opts?: { key?: string; payload?: T }): DynamicHubCommand<T>;\n\tclose(opts?: { key?: string; payload?: T }): DynamicHubCommand<T>;\n}\n\nexport interface ToHubTopicOptions<T> {\n\treadonly name?: string;\n\treadonly keyOf?: (value: T) => string | undefined;\n}\n\nexport interface ToHubTopicBundle<T> {\n\treadonly commands: Node<DynamicHubCommand<T>>;\n}\n\ninterface DynamicHubState<T> {\n\treadonly graph: Graph;\n\treadonly name: string;\n\treadonly maxTopicLength: number;\n\treadonly commandSources: Node<DynamicHubCommand<T>>[];\n\treadonly commandBody: NodeFn;\n\treadonly releaseEventsRetain: () => void;\n}\n\ninterface DynamicHubRuntime {\n\ttopics: string[];\n\topen: boolean;\n\tseq: number;\n\tcursor: number;\n}\n\nconst dynamicHubStates = new WeakMap<DynamicHub<unknown>, DynamicHubState<unknown>>();\nconst DEFAULT_DYNAMIC_HUB_MAX_TOPICS = 1024;\nconst DEFAULT_DYNAMIC_HUB_MAX_TOPIC_LENGTH = 256;\n\nexport function messageBus<TTopic extends string>(\n\tgraph: Graph,\n\topts: MessageBusOptions<TTopic>,\n): MessageBus<TTopic> {\n\tconst unique = [...new Set(opts.topics)];\n\tif (unique.length !== opts.topics.length) throw new Error(\"messageBus: duplicate topic\");\n\tif (unique.length === 0) throw new Error(\"messageBus: at least one topic is required\");\n\tconst name = opts.name ?? \"messageBus\";\n\tconst state: MessageBusState<TTopic> = {\n\t\tgraph,\n\t\tname,\n\t\tnow: opts.now ?? Date.now,\n\t\ttopics: Object.freeze([...unique]),\n\t\trecords: new Map(),\n\t\tseq: 0,\n\t};\n\tfor (const topic of unique) {\n\t\tconst producers: Node<ProducedTopicMessage<unknown>>[] = [];\n\t\tconst body: NodeFn = (ctx) => {\n\t\t\tfor (let i = 0; i < producers.length; i++) {\n\t\t\t\tfor (const produced of depBatch(ctx, i) ?? []) {\n\t\t\t\t\tif ((produced as ProducedTopicMessage).kind === \"publish\") {\n\t\t\t\t\t\tctx.down([\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\tproduced as ProducedTopicMessage<unknown> & {\n\t\t\t\t\t\t\t\t\t\tkind: \"publish\";\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t).envelope,\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tconst node = graph.node<MessageEnvelope<unknown>>([], body, {\n\t\t\tname: `${name}/${topic}`,\n\t\t\tfactory: \"messageTopic\",\n\t\t\tmeta: { topic },\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t});\n\t\tstate.records.set(topic, { node, producers, body });\n\t}\n\tconst bus: MessageBus<TTopic> = {\n\t\ttopics: state.topics,\n\t\ttopic<T = unknown>(topic: TTopic): Node<MessageEnvelope<T>> {\n\t\t\treturn requireTopic(state, topic) as Node<MessageEnvelope<T>>;\n\t\t},\n\t\tpublish<T = unknown>(\n\t\t\ttopic: TTopic,\n\t\t\tpayload: T,\n\t\t\tpublishOpts: { key?: string } = {},\n\t\t): MessageEnvelope<T> {\n\t\t\tconst node = requireTopic(state, topic);\n\t\t\tconst envelope: MessageEnvelope<T> = {\n\t\t\t\ttopic,\n\t\t\t\tseq: ++state.seq,\n\t\t\t\tpayload,\n\t\t\t\ttimestampMs: state.now(),\n\t\t\t\t...(publishOpts.key === undefined ? {} : { key: publishOpts.key }),\n\t\t\t};\n\t\t\tnode.down([[\"DATA\", envelope as MessageEnvelope<unknown>]]);\n\t\t\treturn envelope;\n\t\t},\n\t\thas(topic: string): topic is TTopic {\n\t\t\treturn state.records.has(topic as TTopic);\n\t\t},\n\t};\n\tbusStates.set(bus as MessageBus<string>, state as unknown as MessageBusState<string>);\n\treturn bus;\n}\n\n/**\n * D135 dynamic messaging hub: topic lifecycle is DATA facts over fixed graph-visible\n * command/event/status/error nodes. Topic keys never create or delete graph nodes.\n */\nexport function dynamicHub<T = unknown>(graph: Graph, opts: DynamicHubOptions = {}): DynamicHub<T> {\n\tconst name = opts.name ?? \"dynamicHub\";\n\tconst unknownTopic = normalizeUnknownTopicPolicy(opts.unknownTopic);\n\tconst maxTopics = normalizeHubLimit(\n\t\topts.maxTopics,\n\t\tDEFAULT_DYNAMIC_HUB_MAX_TOPICS,\n\t\t\"dynamicHub: maxTopics\",\n\t);\n\tconst maxTopicLength = normalizeHubLimit(\n\t\topts.maxTopicLength,\n\t\tDEFAULT_DYNAMIC_HUB_MAX_TOPIC_LENGTH,\n\t\t\"dynamicHub: maxTopicLength\",\n\t);\n\tconst now = opts.now ?? Date.now;\n\tconst initialTopics = uniqueTopics(opts.topics ?? [], maxTopicLength);\n\tif (initialTopics.length > maxTopics) {\n\t\tthrow new Error(\"dynamicHub: topics exceed maxTopics\");\n\t}\n\tconst commandSources: Node<DynamicHubCommand<T>>[] = [];\n\tconst commandBody: NodeFn = (ctx) => {\n\t\tfor (let i = 0; i < commandSources.length; i++) {\n\t\t\tfor (const command of depBatch(ctx, i) ?? []) ctx.down([[\"DATA\", command]]);\n\t\t}\n\t};\n\tconst command = graph.node<DynamicHubCommand<T>>([], commandBody, {\n\t\tname: `${name}/command`,\n\t\tfactory: \"dynamicHubCommand\",\n\t\tcompleteWhenDepsComplete: false,\n\t\terrorWhenDepsError: false,\n\t});\n\tconst events = graph.node<DynamicHubEvent<T>>(\n\t\t[command],\n\t\t(ctx) => {\n\t\t\tconst runtime =\n\t\t\t\tctx.state.get<DynamicHubRuntime>() ??\n\t\t\t\t({\n\t\t\t\t\ttopics: [...initialTopics],\n\t\t\t\t\topen: true,\n\t\t\t\t\tseq: 0,\n\t\t\t\t\tcursor: 0,\n\t\t\t\t} satisfies DynamicHubRuntime);\n\t\t\tctx.state.persist(true);\n\t\t\tfor (const commandFact of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst parsed = parseDynamicHubCommand(commandFact);\n\t\t\t\tif (typeof parsed === \"string\") {\n\t\t\t\t\tctx.down([[\"DATA\", hubError(runtime, commandFact, parsed, timestampOrFallback(now))]]);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst reduced = reduceDynamicHubCommand(\n\t\t\t\t\truntime,\n\t\t\t\t\tparsed as DynamicHubCommand<T>,\n\t\t\t\t\tunknownTopic,\n\t\t\t\t\tmaxTopics,\n\t\t\t\t\tmaxTopicLength,\n\t\t\t\t\tnow,\n\t\t\t\t);\n\t\t\t\tfor (const event of reduced) ctx.down([[\"DATA\", event]]);\n\t\t\t}\n\t\t\tctx.state.set(runtime);\n\t\t},\n\t\t{\n\t\t\tname: `${name}/events`,\n\t\t\tfactory: \"dynamicHubEvents\",\n\t\t\tmeta: { unknownTopic },\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\tconst status = graph.node<DynamicHubStatus>(\n\t\t[events],\n\t\t(ctx) => {\n\t\t\tfor (const event of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst typed = event as DynamicHubEvent<T>;\n\t\t\t\tctx.down([[\"DATA\", typed.status]]);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname: `${name}/status`,\n\t\t\tfactory: \"dynamicHubStatus\",\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\tconst errors = graph.node<DynamicHubError>(\n\t\t[events],\n\t\t(ctx) => {\n\t\t\tfor (const event of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst typed = event as DynamicHubEvent<T>;\n\t\t\t\tif (typed.kind !== \"error\") continue;\n\t\t\t\tctx.down([\n\t\t\t\t\t[\n\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...(typed.topic === undefined ? {} : { topic: typed.topic }),\n\t\t\t\t\t\t\terror: typed.error,\n\t\t\t\t\t\t\tcommand: typed.command,\n\t\t\t\t\t\t\tmeta: typed.meta,\n\t\t\t\t\t\t} satisfies DynamicHubError,\n\t\t\t\t\t],\n\t\t\t\t]);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname: `${name}/errors`,\n\t\t\tfactory: \"dynamicHubErrors\",\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\tconst deadLetter =\n\t\topts.deadLetter === true || unknownTopic === \"dead-letter\"\n\t\t\t? graph.node<DynamicHubDeadLetter>(\n\t\t\t\t\t[events],\n\t\t\t\t\t(ctx) => {\n\t\t\t\t\t\tfor (const event of depBatch(ctx, 0) ?? []) {\n\t\t\t\t\t\t\tconst typed = event as DynamicHubEvent<T>;\n\t\t\t\t\t\t\tif (typed.kind !== \"dead-letter\") continue;\n\t\t\t\t\t\t\tctx.down([\n\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t...(typed.topic === undefined ? {} : { topic: typed.topic }),\n\t\t\t\t\t\t\t\t\t\treason: typed.reason,\n\t\t\t\t\t\t\t\t\t\tcommand: typed.command,\n\t\t\t\t\t\t\t\t\t\tmeta: typed.meta,\n\t\t\t\t\t\t\t\t\t} satisfies DynamicHubDeadLetter,\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t]);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: `${name}/deadLetter`,\n\t\t\t\t\t\tfactory: \"dynamicHubDeadLetter\",\n\t\t\t\t\t\tcompleteWhenDepsComplete: false,\n\t\t\t\t\t\terrorWhenDepsError: false,\n\t\t\t\t\t},\n\t\t\t\t)\n\t\t\t: undefined;\n\tconst releaseEventsRetain = graph.retain(events, { reason: `${name}.dynamicHub.events` });\n\tconst hub: DynamicHub<T> = {\n\t\tcommand,\n\t\tevents,\n\t\tstatus,\n\t\terrors,\n\t\t...(deadLetter === undefined ? {} : { deadLetter }),\n\t\tcreate(topic, commandOpts = {}) {\n\t\t\treturn publishHubCommand(command, {\n\t\t\t\tkind: \"create\",\n\t\t\t\ttopic,\n\t\t\t\t...(commandOpts.key === undefined ? {} : { key: commandOpts.key }),\n\t\t\t\t...(commandOpts.payload === undefined ? {} : { payload: commandOpts.payload }),\n\t\t\t} as DynamicHubCommand<T>);\n\t\t},\n\t\tdelete(topic, commandOpts = {}) {\n\t\t\treturn publishHubCommand(command, {\n\t\t\t\tkind: \"delete\",\n\t\t\t\ttopic,\n\t\t\t\t...(commandOpts.key === undefined ? {} : { key: commandOpts.key }),\n\t\t\t\t...(commandOpts.payload === undefined ? {} : { payload: commandOpts.payload }),\n\t\t\t} as DynamicHubCommand<T>);\n\t\t},\n\t\tpublish(topic, payload, commandOpts = {}) {\n\t\t\treturn publishHubCommand(command, {\n\t\t\t\tkind: \"publish\",\n\t\t\t\ttopic,\n\t\t\t\tpayload,\n\t\t\t\t...(commandOpts.key === undefined ? {} : { key: commandOpts.key }),\n\t\t\t});\n\t\t},\n\t\tsubscribeTopic(topic, commandOpts = {}) {\n\t\t\treturn publishHubCommand(command, {\n\t\t\t\tkind: \"subscribe\",\n\t\t\t\ttopic,\n\t\t\t\t...(commandOpts.key === undefined ? {} : { key: commandOpts.key }),\n\t\t\t\t...(commandOpts.payload === undefined ? {} : { payload: commandOpts.payload }),\n\t\t\t} as DynamicHubCommand<T>);\n\t\t},\n\t\tclose(commandOpts = {}) {\n\t\t\treturn publishHubCommand(command, {\n\t\t\t\tkind: \"close\",\n\t\t\t\t...(commandOpts.key === undefined ? {} : { key: commandOpts.key }),\n\t\t\t\t...(commandOpts.payload === undefined ? {} : { payload: commandOpts.payload }),\n\t\t\t} as DynamicHubCommand<T>);\n\t\t},\n\t};\n\tdynamicHubStates.set(hub as DynamicHub<unknown>, {\n\t\tgraph,\n\t\tname,\n\t\tmaxTopicLength,\n\t\tcommandSources: commandSources as Node<DynamicHubCommand<unknown>>[],\n\t\tcommandBody,\n\t\treleaseEventsRetain,\n\t});\n\treturn hub;\n}\n\n/** Static D135 projection over hub event facts for one topic key; no topic node is created. */\nexport function fromHubTopic<T = unknown>(\n\thub: DynamicHub<unknown>,\n\ttopic: string,\n\topts: { name?: string } = {},\n): Node<MessageEnvelope<T>> {\n\tconst state = requireDynamicHubState(hub);\n\tassertTopicKey(topic, \"fromHubTopic\", state.maxTopicLength);\n\treturn state.graph.node<MessageEnvelope<T>>(\n\t\t[hub.events],\n\t\t(ctx) => {\n\t\t\tfor (const event of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst typed = event as DynamicHubEvent<T>;\n\t\t\t\tif (typed.kind !== \"message\" || typed.topic !== topic) continue;\n\t\t\t\tctx.down([\n\t\t\t\t\t[\n\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttopic,\n\t\t\t\t\t\t\tseq: typed.meta.seq,\n\t\t\t\t\t\t\tpayload: typed.payload,\n\t\t\t\t\t\t\ttimestampMs: typed.meta.timestampMs,\n\t\t\t\t\t\t\t...(typed.key === undefined ? {} : { key: typed.key }),\n\t\t\t\t\t\t} satisfies MessageEnvelope<T>,\n\t\t\t\t\t],\n\t\t\t\t]);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname: opts.name ?? `${state.name}/${topic}/fromHubTopic`,\n\t\t\tfactory: \"fromHubTopic\",\n\t\t\tmeta: { topic },\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n}\n\n/** Static D135 command helper: source DATA becomes publish command facts for one topic key. */\nexport function toHubTopic<T>(\n\tgraph: Graph,\n\tsource: Node<T>,\n\thub: DynamicHub<unknown>,\n\ttopic: string,\n\topts: ToHubTopicOptions<T> = {},\n): ToHubTopicBundle<T> {\n\tconst state = requireDynamicHubState(hub);\n\tassertTopicKey(topic, \"toHubTopic\", state.maxTopicLength);\n\tif (state.graph !== graph) throw new Error(\"toHubTopic: hub and source graph must match\");\n\tif (isReachableUpstream(source as Node<unknown>, hub.command as Node<unknown>)) {\n\t\tthrow new Error(\"toHubTopic: source already depends on hub command path\");\n\t}\n\tconst commands = graph.node<DynamicHubCommand<T>>(\n\t\t[source],\n\t\t(ctx) => {\n\t\t\tfor (const value of depBatch(ctx, 0) ?? []) {\n\t\t\t\ttry {\n\t\t\t\t\tconst key = opts.keyOf?.(value as T);\n\t\t\t\t\tctx.down([\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tkind: \"publish\",\n\t\t\t\t\t\t\t\ttopic,\n\t\t\t\t\t\t\t\tpayload: value as T,\n\t\t\t\t\t\t\t\t...(key === undefined ? {} : { key }),\n\t\t\t\t\t\t\t} satisfies DynamicHubCommand<T>,\n\t\t\t\t\t\t],\n\t\t\t\t\t]);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tctx.down([\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tkind: \"invalid\",\n\t\t\t\t\t\t\t\ttopic,\n\t\t\t\t\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t\t\t} as unknown as DynamicHubCommand<T>,\n\t\t\t\t\t\t],\n\t\t\t\t\t]);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname: opts.name ?? `${state.name}/${topic}/toHubTopic`,\n\t\t\tfactory: \"toHubTopic\",\n\t\t\tmeta: { topic },\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\tconst commandSource = commands as Node<DynamicHubCommand<unknown>>;\n\tstate.commandSources.push(commandSource);\n\ttry {\n\t\thub.command.replaceDeps([...state.commandSources], state.commandBody);\n\t} catch (error) {\n\t\tstate.commandSources.splice(state.commandSources.indexOf(commandSource), 1);\n\t\treleaseGraphNodes(graph, [commands as Node<unknown>], {\n\t\t\treason: \"toHubTopic failed command wiring\",\n\t\t});\n\t\tthrow error;\n\t}\n\treturn { commands };\n}\n\nexport function fromTopic<T = unknown, TTopic extends string = string>(\n\tbus: MessageBus<TTopic>,\n\ttopic: TTopic,\n): Node<MessageEnvelope<T>> {\n\treturn bus.topic<T>(topic);\n}\n\nexport function toTopic<T, TTopic extends string>(\n\tgraph: Graph,\n\tsource: Node<T>,\n\tbus: MessageBus<TTopic>,\n\ttopic: TTopic,\n\topts: ToTopicOptions = {},\n): ToTopicBundle<T> {\n\tconst state = busStates.get(bus as MessageBus<string>) as MessageBusState<TTopic> | undefined;\n\tif (state === undefined) throw new Error(\"toTopic: unknown message bus implementation\");\n\tif (state.graph !== graph) throw new Error(\"toTopic: bus and source graph must match\");\n\tconst record = requireTopicRecord(state, topic);\n\tconst name = opts.name ?? `toTopic/${topic}`;\n\tconst producer = graph.node<ProducedTopicMessage<T>>(\n\t\t[source],\n\t\t(ctx) => {\n\t\t\tfor (const value of depBatch(ctx, 0) ?? []) {\n\t\t\t\ttry {\n\t\t\t\t\tconst key = opts.keyOf?.(value);\n\t\t\t\t\tconst envelope: MessageEnvelope<T> = {\n\t\t\t\t\t\ttopic,\n\t\t\t\t\t\tseq: ++state.seq,\n\t\t\t\t\t\tpayload: value as T,\n\t\t\t\t\t\ttimestampMs: state.now(),\n\t\t\t\t\t\t...(key === undefined ? {} : { key }),\n\t\t\t\t\t};\n\t\t\t\t\tctx.down([\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tkind: \"publish\",\n\t\t\t\t\t\t\t\tenvelope,\n\t\t\t\t\t\t\t} satisfies ProducedTopicMessage<T>,\n\t\t\t\t\t\t],\n\t\t\t\t\t]);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tctx.down([[\"DATA\", { kind: \"error\", topic, error } satisfies ProducedTopicMessage<T>]]);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname,\n\t\t\tfactory: \"toTopic\",\n\t\t\tmeta: { topic },\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\trecord.producers.push(producer as Node<ProducedTopicMessage<unknown>>);\n\trecord.node.replaceDeps([...record.producers], record.body);\n\tconst events = graph.node<MessageBusEvent<T>>(\n\t\t[producer, source],\n\t\t(ctx) => {\n\t\t\tfor (const produced of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst typed = produced as ProducedTopicMessage<T>;\n\t\t\t\tif (typed.kind === \"publish\") {\n\t\t\t\t\tctx.down([\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tkind: \"publish\",\n\t\t\t\t\t\t\t\ttopic,\n\t\t\t\t\t\t\t\tseq: typed.envelope.seq,\n\t\t\t\t\t\t\t\tpayload: typed.envelope.payload,\n\t\t\t\t\t\t\t} satisfies MessageBusEvent<T>,\n\t\t\t\t\t\t],\n\t\t\t\t\t]);\n\t\t\t\t} else {\n\t\t\t\t\tctx.down([\n\t\t\t\t\t\t[\"DATA\", { kind: \"error\", topic, error: typed.error } satisfies MessageBusEvent<T>],\n\t\t\t\t\t]);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst terminal = ctx.terminal[0];\n\t\t\tif (terminal !== false && terminal !== undefined && terminal !== true) {\n\t\t\t\tctx.down([\n\t\t\t\t\t[\"DATA\", { kind: \"error\", topic, error: terminal } satisfies MessageBusEvent<T>],\n\t\t\t\t]);\n\t\t\t}\n\t\t\tconst sourceTerminal = ctx.terminal[1];\n\t\t\tif (sourceTerminal === true) {\n\t\t\t\tctx.down([[\"DATA\", { kind: \"complete\", topic } satisfies MessageBusEvent<T>]]);\n\t\t\t} else if (sourceTerminal !== false && sourceTerminal !== undefined) {\n\t\t\t\tctx.down([\n\t\t\t\t\t[\"DATA\", { kind: \"error\", topic, error: sourceTerminal } satisfies MessageBusEvent<T>],\n\t\t\t\t]);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname: `${name}/events`,\n\t\t\tfactory: \"toTopicEvents\",\n\t\t\tmeta: { topic },\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t\tterminalAsRealInput: true,\n\t\t},\n\t);\n\treturn { events };\n}\n\nfunction requireTopic<TTopic extends string>(\n\tstate: MessageBusState<TTopic>,\n\ttopic: TTopic,\n): Node<MessageEnvelope<unknown>> {\n\treturn requireTopicRecord(state, topic).node;\n}\n\nfunction requireTopicRecord<TTopic extends string>(\n\tstate: MessageBusState<TTopic>,\n\ttopic: TTopic,\n): TopicRecord {\n\tconst record = state.records.get(topic);\n\tif (record === undefined) throw new Error(`messageBus: unknown topic '${topic}'`);\n\treturn record;\n}\n\nfunction uniqueTopics(topics: readonly string[], maxTopicLength: number): readonly string[] {\n\tconst unique = [...new Set(topics)];\n\tif (unique.length !== topics.length) throw new Error(\"dynamicHub: duplicate topic\");\n\tfor (const topic of unique) assertTopicKey(topic, \"dynamicHub\", maxTopicLength);\n\treturn Object.freeze(unique.sort());\n}\n\nfunction normalizeUnknownTopicPolicy(\n\tpolicy: DynamicHubOptions[\"unknownTopic\"],\n): DynamicHubUnknownTopicPolicy {\n\tif (policy === undefined) return \"error\";\n\tif (\n\t\tpolicy === \"drop\" ||\n\t\tpolicy === \"error\" ||\n\t\tpolicy === \"dead-letter\" ||\n\t\tpolicy === \"create-as-fact\"\n\t) {\n\t\treturn policy;\n\t}\n\tthrow new Error(\"dynamicHub: unknownTopic policy is not recognized\");\n}\n\nfunction normalizeHubLimit(value: number | undefined, fallback: number, owner: string): number {\n\tif (value === undefined) return fallback;\n\tif (!Number.isInteger(value) || value < 1) {\n\t\tthrow new Error(`${owner} must be a positive integer`);\n\t}\n\treturn value;\n}\n\nfunction publishHubCommand<T>(\n\tcommandNode: Node<DynamicHubCommand<T>>,\n\tcommand: DynamicHubCommand<T>,\n): DynamicHubCommand<T> {\n\tcommandNode.down([[\"DATA\", command]]);\n\treturn command;\n}\n\nfunction parseDynamicHubCommand(value: unknown): DynamicHubCommand<unknown> | string {\n\tif (!isObjectRecord(value)) return \"dynamicHub: command fact must be an object\";\n\tconst kind = value.kind;\n\tif (\n\t\tkind !== \"create\" &&\n\t\tkind !== \"delete\" &&\n\t\tkind !== \"publish\" &&\n\t\tkind !== \"subscribe\" &&\n\t\tkind !== \"close\"\n\t) {\n\t\treturn \"dynamicHub: command kind is not recognized\";\n\t}\n\tif (kind === \"close\") {\n\t\treturn {\n\t\t\tkind,\n\t\t\t...(typeof value.key === \"string\" ? { key: value.key } : {}),\n\t\t\t...(value.payload === undefined ? {} : { payload: value.payload }),\n\t\t};\n\t}\n\tconst topic = value.topic;\n\tif (typeof topic !== \"string\" || topic.length === 0) {\n\t\treturn \"dynamicHub: command topic must be a non-empty string\";\n\t}\n\tif (kind === \"publish\") {\n\t\tif (value.payload === undefined) return \"dynamicHub: publish command payload is required\";\n\t\treturn {\n\t\t\tkind,\n\t\t\ttopic,\n\t\t\tpayload: value.payload,\n\t\t\t...(typeof value.key === \"string\" ? { key: value.key } : {}),\n\t\t};\n\t}\n\treturn {\n\t\tkind,\n\t\ttopic,\n\t\t...(typeof value.key === \"string\" ? { key: value.key } : {}),\n\t\t...(value.payload === undefined ? {} : { payload: value.payload }),\n\t};\n}\n\nfunction isObjectRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction readHubTimestamp(now: () => number): number | string {\n\ttry {\n\t\tconst timestampMs = now();\n\t\treturn Number.isFinite(timestampMs)\n\t\t\t? timestampMs\n\t\t\t: \"dynamicHub: now() must return a finite number\";\n\t} catch (error) {\n\t\treturn `dynamicHub: now() threw: ${error instanceof Error ? error.message : String(error)}`;\n\t}\n}\n\nfunction timestampOrFallback(now: () => number): number {\n\tconst timestampMs = readHubTimestamp(now);\n\treturn typeof timestampMs === \"number\" ? timestampMs : Date.now();\n}\n\nfunction reduceDynamicHubCommand<T>(\n\truntime: DynamicHubRuntime,\n\tcommand: DynamicHubCommand<T>,\n\tunknownTopic: DynamicHubUnknownTopicPolicy,\n\tmaxTopics: number,\n\tmaxTopicLength: number,\n\tnow: () => number,\n): DynamicHubEvent<T>[] {\n\tconst topic = \"topic\" in command ? command.topic : undefined;\n\tif (topic !== undefined) {\n\t\tconst topicError = validateTopicKey(topic, \"dynamicHub\", maxTopicLength);\n\t\tif (topicError !== undefined) {\n\t\t\treturn [hubError(runtime, command, topicError, timestampOrFallback(now))];\n\t\t}\n\t}\n\tif (!runtime.open && command.kind !== \"close\") {\n\t\treturn [hubError(runtime, command, \"dynamicHub: hub is closed\", timestampOrFallback(now))];\n\t}\n\tswitch (command.kind) {\n\t\tcase \"create\": {\n\t\t\tconst capacityError = canAddHubTopic(runtime, command.topic, maxTopics);\n\t\t\tif (capacityError !== undefined) {\n\t\t\t\treturn [hubError(runtime, command, capacityError, timestampOrFallback(now))];\n\t\t\t}\n\t\t\tconst timestampMs = readHubTimestamp(now);\n\t\t\tif (typeof timestampMs === \"string\")\n\t\t\t\treturn [hubError(runtime, command, timestampMs, Date.now())];\n\t\t\taddHubTopic(runtime, command.topic);\n\t\t\treturn [hubEvent(runtime, timestampMs, command)];\n\t\t}\n\t\tcase \"delete\": {\n\t\t\tif (!hasHubTopic(runtime, command.topic)) {\n\t\t\t\treturn unknownHubTopic(runtime, command, unknownTopic, now);\n\t\t\t}\n\t\t\tconst timestampMs = readHubTimestamp(now);\n\t\t\tif (typeof timestampMs === \"string\")\n\t\t\t\treturn [hubError(runtime, command, timestampMs, Date.now())];\n\t\t\tdeleteHubTopic(runtime, command.topic);\n\t\t\treturn [hubEvent(runtime, timestampMs, command)];\n\t\t}\n\t\tcase \"publish\": {\n\t\t\tif (!hasHubTopic(runtime, command.topic)) {\n\t\t\t\tif (unknownTopic === \"create-as-fact\") {\n\t\t\t\t\tconst capacityError = canAddHubTopic(runtime, command.topic, maxTopics);\n\t\t\t\t\tif (capacityError !== undefined) {\n\t\t\t\t\t\treturn [hubError(runtime, command, capacityError, timestampOrFallback(now))];\n\t\t\t\t\t}\n\t\t\t\t\tconst createTimestampMs = readHubTimestamp(now);\n\t\t\t\t\tif (typeof createTimestampMs === \"string\") {\n\t\t\t\t\t\treturn [hubError(runtime, command, createTimestampMs, Date.now())];\n\t\t\t\t\t}\n\t\t\t\t\tconst messageTimestampMs = readHubTimestamp(now);\n\t\t\t\t\tif (typeof messageTimestampMs === \"string\") {\n\t\t\t\t\t\treturn [hubError(runtime, command, messageTimestampMs, Date.now())];\n\t\t\t\t\t}\n\t\t\t\t\taddHubTopic(runtime, command.topic);\n\t\t\t\t\treturn [\n\t\t\t\t\t\thubEvent(runtime, createTimestampMs, { kind: \"create\", topic: command.topic }),\n\t\t\t\t\t\thubEvent(runtime, messageTimestampMs, {\n\t\t\t\t\t\t\tkind: \"message\",\n\t\t\t\t\t\t\ttopic: command.topic,\n\t\t\t\t\t\t\tpayload: command.payload,\n\t\t\t\t\t\t\t...(command.key === undefined ? {} : { key: command.key }),\n\t\t\t\t\t\t}),\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t\treturn unknownHubTopic(runtime, command, unknownTopic, now);\n\t\t\t}\n\t\t\tconst timestampMs = readHubTimestamp(now);\n\t\t\tif (typeof timestampMs === \"string\")\n\t\t\t\treturn [hubError(runtime, command, timestampMs, Date.now())];\n\t\t\treturn [\n\t\t\t\thubEvent(runtime, timestampMs, {\n\t\t\t\t\tkind: \"message\",\n\t\t\t\t\ttopic: command.topic,\n\t\t\t\t\tpayload: command.payload,\n\t\t\t\t\t...(command.key === undefined ? {} : { key: command.key }),\n\t\t\t\t}),\n\t\t\t];\n\t\t}\n\t\tcase \"subscribe\": {\n\t\t\tif (!hasHubTopic(runtime, command.topic)) {\n\t\t\t\tif (unknownTopic === \"create-as-fact\") {\n\t\t\t\t\tconst capacityError = canAddHubTopic(runtime, command.topic, maxTopics);\n\t\t\t\t\tif (capacityError !== undefined) {\n\t\t\t\t\t\treturn [hubError(runtime, command, capacityError, timestampOrFallback(now))];\n\t\t\t\t\t}\n\t\t\t\t\tconst createTimestampMs = readHubTimestamp(now);\n\t\t\t\t\tif (typeof createTimestampMs === \"string\") {\n\t\t\t\t\t\treturn [hubError(runtime, command, createTimestampMs, Date.now())];\n\t\t\t\t\t}\n\t\t\t\t\tconst subscribeTimestampMs = readHubTimestamp(now);\n\t\t\t\t\tif (typeof subscribeTimestampMs === \"string\") {\n\t\t\t\t\t\treturn [hubError(runtime, command, subscribeTimestampMs, Date.now())];\n\t\t\t\t\t}\n\t\t\t\t\taddHubTopic(runtime, command.topic);\n\t\t\t\t\treturn [\n\t\t\t\t\t\thubEvent(runtime, createTimestampMs, { kind: \"create\", topic: command.topic }),\n\t\t\t\t\t\thubEvent(runtime, subscribeTimestampMs, command),\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t\treturn unknownHubTopic(runtime, command, unknownTopic, now);\n\t\t\t}\n\t\t\tconst timestampMs = readHubTimestamp(now);\n\t\t\tif (typeof timestampMs === \"string\")\n\t\t\t\treturn [hubError(runtime, command, timestampMs, Date.now())];\n\t\t\treturn [hubEvent(runtime, timestampMs, command)];\n\t\t}\n\t\tcase \"close\": {\n\t\t\tconst timestampMs = readHubTimestamp(now);\n\t\t\tif (typeof timestampMs === \"string\")\n\t\t\t\treturn [hubError(runtime, command, timestampMs, Date.now())];\n\t\t\truntime.open = false;\n\t\t\treturn [hubEvent(runtime, timestampMs, command)];\n\t\t}\n\t}\n}\n\nfunction hubEvent<T>(\n\truntime: DynamicHubRuntime,\n\ttimestampMs: number,\n\tevent: Record<string, unknown> & { readonly kind: DynamicHubEventKind },\n): DynamicHubEvent<T> {\n\tconst meta = nextHubMetadata(runtime, timestampMs);\n\treturn {\n\t\t...event,\n\t\tmeta,\n\t\tstatus: snapshotHubStatus(runtime, meta, event.kind),\n\t} as DynamicHubEvent<T>;\n}\n\nfunction hubError<T>(\n\truntime: DynamicHubRuntime,\n\tcommand: unknown,\n\terror: string,\n\ttimestampMs: number,\n): DynamicHubEvent<T> {\n\treturn hubEvent(runtime, timestampMs, {\n\t\tkind: \"error\",\n\t\t...(isObjectRecord(command) && typeof command.topic === \"string\"\n\t\t\t? { topic: command.topic }\n\t\t\t: {}),\n\t\terror,\n\t\tcommand,\n\t});\n}\n\nfunction unknownHubTopic<T>(\n\truntime: DynamicHubRuntime,\n\tcommand: DynamicHubCommand<T>,\n\tpolicy: DynamicHubUnknownTopicPolicy,\n\tnow: () => number,\n): DynamicHubEvent<T>[] {\n\tconst topic = \"topic\" in command ? command.topic : undefined;\n\tconst reason = `dynamicHub: unknown topic '${topic ?? \"\"}'`;\n\tif (policy === \"drop\") return [];\n\tif (policy === \"dead-letter\") {\n\t\treturn [\n\t\t\thubEvent(runtime, timestampOrFallback(now), {\n\t\t\t\tkind: \"dead-letter\",\n\t\t\t\t...(topic === undefined ? {} : { topic }),\n\t\t\t\treason,\n\t\t\t\tcommand,\n\t\t\t}),\n\t\t];\n\t}\n\treturn [hubError(runtime, command, reason, timestampOrFallback(now))];\n}\n\nfunction nextHubMetadata(runtime: DynamicHubRuntime, timestampMs: number): DynamicHubMetadata {\n\truntime.seq += 1;\n\truntime.cursor = runtime.seq;\n\treturn { seq: runtime.seq, cursor: runtime.cursor, timestampMs };\n}\n\nfunction snapshotHubStatus(\n\truntime: DynamicHubRuntime,\n\tmeta: DynamicHubMetadata,\n\tkind: DynamicHubEventKind,\n): DynamicHubStatus {\n\treturn {\n\t\topen: runtime.open,\n\t\ttopics: Object.freeze([...runtime.topics].sort()),\n\t\tseq: meta.seq,\n\t\tcursor: meta.cursor,\n\t\tlastEventKind: kind,\n\t};\n}\n\nfunction assertTopicKey(topic: string, owner: string, maxTopicLength: number): void {\n\tconst error = validateTopicKey(topic, owner, maxTopicLength);\n\tif (error !== undefined) throw new Error(error);\n}\n\nfunction validateTopicKey(\n\ttopic: string,\n\towner: string,\n\tmaxTopicLength: number,\n): string | undefined {\n\tif (typeof topic !== \"string\" || topic.length === 0) {\n\t\treturn `${owner}: topic must be a non-empty string`;\n\t}\n\tif (topic.length > maxTopicLength) {\n\t\treturn `${owner}: topic exceeds maxTopicLength`;\n\t}\n\treturn undefined;\n}\n\nfunction hasHubTopic(runtime: DynamicHubRuntime, topic: string): boolean {\n\treturn runtime.topics.includes(topic);\n}\n\nfunction addHubTopic(runtime: DynamicHubRuntime, topic: string): void {\n\tif (!hasHubTopic(runtime, topic)) runtime.topics = [...runtime.topics, topic];\n}\n\nfunction deleteHubTopic(runtime: DynamicHubRuntime, topic: string): void {\n\truntime.topics = runtime.topics.filter((existing) => existing !== topic);\n}\n\nfunction canAddHubTopic(\n\truntime: DynamicHubRuntime,\n\ttopic: string,\n\tmaxTopics: number,\n): string | undefined {\n\tif (hasHubTopic(runtime, topic)) return undefined;\n\treturn runtime.topics.length >= maxTopics\n\t\t? \"dynamicHub: topic count exceeds maxTopics\"\n\t\t: undefined;\n}\n\nfunction isReachableUpstream(from: Node<unknown>, target: Node<unknown>): boolean {\n\tconst seen = new Set<Node<unknown>>();\n\tconst stack: Node<unknown>[] = [from];\n\twhile (stack.length > 0) {\n\t\tconst node = stack.pop();\n\t\tif (node === undefined) continue;\n\t\tif (node === target) return true;\n\t\tif (seen.has(node)) continue;\n\t\tseen.add(node);\n\t\tfor (const dep of node.deps) stack.push(dep);\n\t}\n\treturn false;\n}\n\nfunction requireDynamicHubState(hub: DynamicHub<unknown>): DynamicHubState<unknown> {\n\tconst state = dynamicHubStates.get(hub);\n\tif (state === undefined) throw new Error(\"dynamicHub: unknown hub implementation\");\n\treturn state;\n}\n"],"mappings":";;;;;;;;;;;;AA2DO,IAAM,gBAAgB;AACtB,IAAM,kBAAkB;AACxB,IAAM,mBAAmB;AACzB,IAAM,iBAAiB;AACvB,IAAM,eAAe;AACrB,IAAM,gBAAgB;AACtB,IAAM,cAAc;AAEpB,IAAM,kBAAkB,OAAO,OAAO;AAAA,EAC5C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,CAAU;AA4CV,IAAM,YAAY,oBAAI,QAAqD;AAmL3E,IAAM,mBAAmB,oBAAI,QAAuD;AACpF,IAAM,iCAAiC;AACvC,IAAM,uCAAuC;AAEtC,SAAS,WACf,OACA,MACqB;AACrB,QAAM,SAAS,CAAC,GAAG,IAAI,IAAI,KAAK,MAAM,CAAC;AACvC,MAAI,OAAO,WAAW,KAAK,OAAO,OAAQ,OAAM,IAAI,MAAM,6BAA6B;AACvF,MAAI,OAAO,WAAW,EAAG,OAAM,IAAI,MAAM,4CAA4C;AACrF,QAAM,OAAO,KAAK,QAAQ;AAC1B,QAAM,QAAiC;AAAA,IACtC;AAAA,IACA;AAAA,IACA,KAAK,KAAK,OAAO,KAAK;AAAA,IACtB,QAAQ,OAAO,OAAO,CAAC,GAAG,MAAM,CAAC;AAAA,IACjC,SAAS,oBAAI,IAAI;AAAA,IACjB,KAAK;AAAA,EACN;AACA,aAAW,SAAS,QAAQ;AAC3B,UAAM,YAAmD,CAAC;AAC1D,UAAM,OAAe,CAAC,QAAQ;AAC7B,eAAS,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;AAC1C,mBAAW,YAA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ACJ;AAEA,SAAS,oBAAoB,MAAqB,QAAgC;AACjF,QAAM,OAAO,oBAAI,IAAmB;AACpC,QAAM,QAAyB,CAAC,IAAI;AACpC,SAAO,MAAM,SAAS,GAAG;AACxB,UAAM,OAAO,MAAM,IAAI;AACvB,QAAI,SAAS,OAAW;AACxB,QAAI,SAAS,OAAQ,QAAO;AAC5B,QAAI,KAAK,IAAI,IAAI,EAAG;AACpB,SAAK,IAAI,IAAI;AACb,eAAW,OAAO,KAAK,KAAM,OAAM,KAAK,GAAG;AAAA,EAC5C;AACA,SAAO;AACR;AAEA,SAAS,uBAAuB,KAAoD;AACnF,QAAM,QAAQ,iBAAiB,IAAI,GAAG;AACtC,MAAI,UAAU,OAAW,OAAM,IAAI,MAAM,wCAAwC;AACjF,SAAO;AACR;","names":["command"]}
@@ -0,0 +1,88 @@
1
+ import { b as AppendLogPage, d as AppendLogStorageTier, c as AppendLogReadOptions } from './append-log-DisvEReb.cjs';
2
+ import { C as Codec } from './codec-BB7p8fJc.cjs';
3
+
4
+ /**
5
+ * Storage scalar helpers (D88): host BigInt in memory, canonical decimal strings on JSON/storage.
6
+ */
7
+ /** Canonical decimal integer string; no leading zeroes, and no negative zero. */
8
+ type DecimalIntegerString = string;
9
+ /** Canonical non-negative decimal integer string. */
10
+ type NonNegativeDecimalIntegerString = DecimalIntegerString;
11
+ /** Test whether a value is a canonical decimal integer string. */
12
+ declare function isDecimalIntegerString(value: unknown): value is DecimalIntegerString;
13
+ /** Test whether a value is a canonical non-negative decimal integer string. */
14
+ declare function isNonNegativeDecimalIntegerString(value: unknown): value is NonNegativeDecimalIntegerString;
15
+ /** Assert a canonical decimal integer string and return it typed. */
16
+ declare function assertDecimalIntegerString(value: unknown, label?: string): DecimalIntegerString;
17
+ /** Assert a canonical non-negative decimal integer string and return it typed. */
18
+ declare function assertNonNegativeDecimalIntegerString(value: unknown, label?: string): NonNegativeDecimalIntegerString;
19
+ /** Convert a host BigInt to the canonical decimal storage scalar. */
20
+ declare function bigIntToDecimalString(value: bigint): DecimalIntegerString;
21
+ /** Convert a non-negative host BigInt to the canonical non-negative decimal storage scalar. */
22
+ declare function bigIntToNonNegativeDecimalString(value: bigint): NonNegativeDecimalIntegerString;
23
+ /** Parse a canonical decimal storage scalar into host BigInt. */
24
+ declare function decimalStringToBigInt(value: DecimalIntegerString): bigint;
25
+ /** Parse a canonical non-negative decimal storage scalar into host BigInt. */
26
+ declare function nonNegativeDecimalStringToBigInt(value: NonNegativeDecimalIntegerString): bigint;
27
+
28
+ /**
29
+ * Storage change envelopes (D82): persistence framing for raw graph/data-structure deltas.
30
+ */
31
+
32
+ /** Storage-side lifecycle namespace for change envelopes; presentation framing only. */
33
+ type ChangeLifecycle = "spec" | "data" | "ownership";
34
+ /** D84 cross-runtime wall-clock nanosecond metadata: canonical non-negative decimal string. */
35
+ type StorageTimestampNs = NonNegativeDecimalIntegerString;
36
+ /** Persistence envelope for raw graph/data-structure deltas (D82), not restore semantics. */
37
+ interface ChangeEnvelope<T = unknown> {
38
+ readonly lifecycle: ChangeLifecycle;
39
+ readonly structure: string;
40
+ readonly version: number | string;
41
+ readonly t_ns: StorageTimestampNs;
42
+ readonly seq?: number;
43
+ readonly change: T;
44
+ }
45
+ /** Options for wrapping a raw change in a storage envelope. */
46
+ interface ChangeEnvelopeOptions {
47
+ lifecycle?: ChangeLifecycle;
48
+ structure: string;
49
+ version?: number | string;
50
+ t_ns?: StorageTimestampNs;
51
+ seq?: number;
52
+ }
53
+ /** Wall-clock nanoseconds for storage metadata. */
54
+ declare function nowNs(): StorageTimestampNs;
55
+ /** Wrap a raw change payload in a D82 storage envelope. */
56
+ declare function envelopeChange<T>(change: T, opts: ChangeEnvelopeOptions): ChangeEnvelope<T>;
57
+ /** Validate a decoded D82 change envelope and return it with typed payload. */
58
+ declare function assertChangeEnvelope<T = unknown>(value: unknown): ChangeEnvelope<T>;
59
+ /** Stable JSON codec for D82 change envelopes, with strict framing checks. */
60
+ declare function changeEnvelopeCodec<T = unknown>(): Codec<ChangeEnvelope<T>>;
61
+
62
+ interface ObserveEventLike {
63
+ readonly seq: number;
64
+ readonly path: string;
65
+ }
66
+ /** Storage frame for one Graph.observe() event, preserving graph observe sequence. */
67
+ interface ObserveEventFrame<T = unknown> extends ChangeEnvelope<T> {
68
+ readonly structure: "observe-event";
69
+ readonly observeSeq: number;
70
+ readonly path: string;
71
+ readonly stream?: string;
72
+ }
73
+ /** One ordered observe-event log page. It is not graph projection or restore replay. */
74
+ type ObserveEventLogPage<T = unknown> = AppendLogPage<ObserveEventFrame<T>>;
75
+ /** Create a storage frame from one observe event and mapped payload. */
76
+ declare function observeEventFrame<T>(event: ObserveEventLike, value: T, opts?: {
77
+ stream?: string;
78
+ }): ObserveEventFrame<T>;
79
+ /** Validate a decoded D82 observe-event storage frame. */
80
+ declare function assertObserveEventFrame<T = unknown>(value: unknown): ObserveEventFrame<T>;
81
+ /** Stable JSON codec for D82 observe-event frames, not restore records. */
82
+ declare function observeEventFrameCodec<T = unknown>(): Codec<ObserveEventFrame<T>>;
83
+ /**
84
+ * Read one ordered observe-event log page without projecting it into graph state.
85
+ */
86
+ declare function readObserveEventLogPage<T = unknown>(log: AppendLogStorageTier<ObserveEventFrame<T>>, opts?: AppendLogReadOptions): Promise<ObserveEventLogPage<T>>;
87
+
88
+ export { type ChangeEnvelope as C, type DecimalIntegerString as D, type NonNegativeDecimalIntegerString as N, type ObserveEventFrame as O, type StorageTimestampNs as S, type ChangeEnvelopeOptions as a, type ChangeLifecycle as b, type ObserveEventLogPage as c, assertChangeEnvelope as d, assertDecimalIntegerString as e, assertNonNegativeDecimalIntegerString as f, assertObserveEventFrame as g, bigIntToDecimalString as h, bigIntToNonNegativeDecimalString as i, changeEnvelopeCodec as j, decimalStringToBigInt as k, envelopeChange as l, isDecimalIntegerString as m, isNonNegativeDecimalIntegerString as n, nonNegativeDecimalStringToBigInt as o, nowNs as p, observeEventFrame as q, observeEventFrameCodec as r, readObserveEventLogPage as s };
@@ -0,0 +1,88 @@
1
+ import { b as AppendLogPage, d as AppendLogStorageTier, c as AppendLogReadOptions } from './append-log-DzKMmjxx.js';
2
+ import { C as Codec } from './codec-BB7p8fJc.js';
3
+
4
+ /**
5
+ * Storage scalar helpers (D88): host BigInt in memory, canonical decimal strings on JSON/storage.
6
+ */
7
+ /** Canonical decimal integer string; no leading zeroes, and no negative zero. */
8
+ type DecimalIntegerString = string;
9
+ /** Canonical non-negative decimal integer string. */
10
+ type NonNegativeDecimalIntegerString = DecimalIntegerString;
11
+ /** Test whether a value is a canonical decimal integer string. */
12
+ declare function isDecimalIntegerString(value: unknown): value is DecimalIntegerString;
13
+ /** Test whether a value is a canonical non-negative decimal integer string. */
14
+ declare function isNonNegativeDecimalIntegerString(value: unknown): value is NonNegativeDecimalIntegerString;
15
+ /** Assert a canonical decimal integer string and return it typed. */
16
+ declare function assertDecimalIntegerString(value: unknown, label?: string): DecimalIntegerString;
17
+ /** Assert a canonical non-negative decimal integer string and return it typed. */
18
+ declare function assertNonNegativeDecimalIntegerString(value: unknown, label?: string): NonNegativeDecimalIntegerString;
19
+ /** Convert a host BigInt to the canonical decimal storage scalar. */
20
+ declare function bigIntToDecimalString(value: bigint): DecimalIntegerString;
21
+ /** Convert a non-negative host BigInt to the canonical non-negative decimal storage scalar. */
22
+ declare function bigIntToNonNegativeDecimalString(value: bigint): NonNegativeDecimalIntegerString;
23
+ /** Parse a canonical decimal storage scalar into host BigInt. */
24
+ declare function decimalStringToBigInt(value: DecimalIntegerString): bigint;
25
+ /** Parse a canonical non-negative decimal storage scalar into host BigInt. */
26
+ declare function nonNegativeDecimalStringToBigInt(value: NonNegativeDecimalIntegerString): bigint;
27
+
28
+ /**
29
+ * Storage change envelopes (D82): persistence framing for raw graph/data-structure deltas.
30
+ */
31
+
32
+ /** Storage-side lifecycle namespace for change envelopes; presentation framing only. */
33
+ type ChangeLifecycle = "spec" | "data" | "ownership";
34
+ /** D84 cross-runtime wall-clock nanosecond metadata: canonical non-negative decimal string. */
35
+ type StorageTimestampNs = NonNegativeDecimalIntegerString;
36
+ /** Persistence envelope for raw graph/data-structure deltas (D82), not restore semantics. */
37
+ interface ChangeEnvelope<T = unknown> {
38
+ readonly lifecycle: ChangeLifecycle;
39
+ readonly structure: string;
40
+ readonly version: number | string;
41
+ readonly t_ns: StorageTimestampNs;
42
+ readonly seq?: number;
43
+ readonly change: T;
44
+ }
45
+ /** Options for wrapping a raw change in a storage envelope. */
46
+ interface ChangeEnvelopeOptions {
47
+ lifecycle?: ChangeLifecycle;
48
+ structure: string;
49
+ version?: number | string;
50
+ t_ns?: StorageTimestampNs;
51
+ seq?: number;
52
+ }
53
+ /** Wall-clock nanoseconds for storage metadata. */
54
+ declare function nowNs(): StorageTimestampNs;
55
+ /** Wrap a raw change payload in a D82 storage envelope. */
56
+ declare function envelopeChange<T>(change: T, opts: ChangeEnvelopeOptions): ChangeEnvelope<T>;
57
+ /** Validate a decoded D82 change envelope and return it with typed payload. */
58
+ declare function assertChangeEnvelope<T = unknown>(value: unknown): ChangeEnvelope<T>;
59
+ /** Stable JSON codec for D82 change envelopes, with strict framing checks. */
60
+ declare function changeEnvelopeCodec<T = unknown>(): Codec<ChangeEnvelope<T>>;
61
+
62
+ interface ObserveEventLike {
63
+ readonly seq: number;
64
+ readonly path: string;
65
+ }
66
+ /** Storage frame for one Graph.observe() event, preserving graph observe sequence. */
67
+ interface ObserveEventFrame<T = unknown> extends ChangeEnvelope<T> {
68
+ readonly structure: "observe-event";
69
+ readonly observeSeq: number;
70
+ readonly path: string;
71
+ readonly stream?: string;
72
+ }
73
+ /** One ordered observe-event log page. It is not graph projection or restore replay. */
74
+ type ObserveEventLogPage<T = unknown> = AppendLogPage<ObserveEventFrame<T>>;
75
+ /** Create a storage frame from one observe event and mapped payload. */
76
+ declare function observeEventFrame<T>(event: ObserveEventLike, value: T, opts?: {
77
+ stream?: string;
78
+ }): ObserveEventFrame<T>;
79
+ /** Validate a decoded D82 observe-event storage frame. */
80
+ declare function assertObserveEventFrame<T = unknown>(value: unknown): ObserveEventFrame<T>;
81
+ /** Stable JSON codec for D82 observe-event frames, not restore records. */
82
+ declare function observeEventFrameCodec<T = unknown>(): Codec<ObserveEventFrame<T>>;
83
+ /**
84
+ * Read one ordered observe-event log page without projecting it into graph state.
85
+ */
86
+ declare function readObserveEventLogPage<T = unknown>(log: AppendLogStorageTier<ObserveEventFrame<T>>, opts?: AppendLogReadOptions): Promise<ObserveEventLogPage<T>>;
87
+
88
+ export { type ChangeEnvelope as C, type DecimalIntegerString as D, type NonNegativeDecimalIntegerString as N, type ObserveEventFrame as O, type StorageTimestampNs as S, type ChangeEnvelopeOptions as a, type ChangeLifecycle as b, type ObserveEventLogPage as c, assertChangeEnvelope as d, assertDecimalIntegerString as e, assertNonNegativeDecimalIntegerString as f, assertObserveEventFrame as g, bigIntToDecimalString as h, bigIntToNonNegativeDecimalString as i, changeEnvelopeCodec as j, decimalStringToBigInt as k, envelopeChange as l, isDecimalIntegerString as m, isNonNegativeDecimalIntegerString as n, nonNegativeDecimalStringToBigInt as o, nowNs as p, observeEventFrame as q, observeEventFrameCodec as r, readObserveEventLogPage as s };