dal-code 1.0.44 → 1.0.45

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 (426) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/NOTICE +17 -0
  3. package/PRIVACY.md +159 -102
  4. package/dal-docs/README.md +1 -1
  5. package/dal-docs/keybindings.md +1 -0
  6. package/dal-docs/settings.md +5 -0
  7. package/dist/cli/credential-print.js +1 -1
  8. package/dist/config.d.ts +1 -0
  9. package/dist/config.js +1 -1
  10. package/dist/core/agent-session-runtime.js +1 -1
  11. package/dist/core/agent-session.d.ts +1 -1
  12. package/dist/core/agent-session.js +5 -5
  13. package/dist/core/auth-storage.js +1 -1
  14. package/dist/core/background-processes.js +7 -7
  15. package/dist/core/export-html/template.js +34 -34
  16. package/dist/core/extensions/runner.js +1 -1
  17. package/dist/core/extensions/types.d.ts +5 -1
  18. package/dist/core/key-id-schema.js +1 -0
  19. package/dist/core/keybindings-schema.js +1 -0
  20. package/dist/core/keybindings.d.ts +5 -0
  21. package/dist/core/keybindings.js +1 -1
  22. package/dist/core/model-config.d.ts +818 -99
  23. package/dist/core/model-config.js +5 -5
  24. package/dist/core/model-resolver.d.ts +30 -10
  25. package/dist/core/model-resolver.js +1 -1
  26. package/dist/core/model-runtime.d.ts +1 -0
  27. package/dist/core/model-runtime.js +2 -2
  28. package/dist/core/package-manager.d.ts +5 -0
  29. package/dist/core/package-manager.js +2 -2
  30. package/dist/core/permissions/shell-words.d.ts +26 -0
  31. package/dist/core/project-trust.js +2 -2
  32. package/dist/core/prompt-templates.js +2 -2
  33. package/dist/core/remote-catalog-provider.js +1 -1
  34. package/dist/core/resource-loader.js +1 -1
  35. package/dist/core/sandbox/libreoffice.js +1 -0
  36. package/dist/core/sandbox/runtime.d.ts +1 -0
  37. package/dist/core/sandbox/runtime.js +1 -1
  38. package/dist/core/sandbox/shell-sandbox.js +6 -6
  39. package/dist/core/sandbox/windows.js +4 -4
  40. package/dist/core/session-manager.d.ts +1 -0
  41. package/dist/core/session-manager.js +12 -12
  42. package/dist/core/settings-defaults.js +1 -0
  43. package/dist/core/settings-manager.d.ts +5 -0
  44. package/dist/core/settings-manager.js +1 -1
  45. package/dist/core/settings-schema.d.ts +229 -0
  46. package/dist/core/settings-schema.js +1 -0
  47. package/dist/core/tools/bash-read-only.d.ts +1 -0
  48. package/dist/core/tools/read.js +12 -12
  49. package/dist/core/tools/render-utils.d.ts +40 -0
  50. package/dist/core/tools/render-utils.js +7 -7
  51. package/dist/core/tools/renderers/read.js +8 -8
  52. package/dist/core/trust-manager.js +1 -1
  53. package/dist/core/workspace-lock.d.ts +6 -2
  54. package/dist/core/workspace-lock.js +3 -3
  55. package/dist/dal/extension-compat.js +4 -4
  56. package/dist/dal/hooks/config.d.ts +5 -1
  57. package/dist/dal/hooks/config.js +1 -1
  58. package/dist/dal/hooks/extension.js +3 -3
  59. package/dist/dal/hooks/index.d.ts +1 -1
  60. package/dist/dal/hooks/index.js +1 -1
  61. package/dist/dal/i18n.js +1 -1
  62. package/dist/dal/manifest.js +1 -1
  63. package/dist/extensions/codemode/execute.js +14 -13
  64. package/dist/extensions/codemode/index.js +1 -1
  65. package/dist/extensions/codemode/renderer.js +6 -6
  66. package/dist/extensions/codemode/tool.d.ts +2 -3
  67. package/dist/extensions/codemode/tool.js +9 -12
  68. package/dist/extensions/mcp/cli.js +4 -4
  69. package/dist/extensions/mcp/index.js +12 -12
  70. package/dist/extensions/mcp/resources.d.ts +0 -5
  71. package/dist/extensions/mcp/resources.js +1 -1
  72. package/dist/extensions/mcp/runtime.d.ts +1 -4
  73. package/dist/extensions/mcp/runtime.js +3 -3
  74. package/dist/extensions/mcp/tools.js +7 -7
  75. package/dist/extensions/tool-search/tool.js +3 -3
  76. package/dist/index.d.ts +5 -2
  77. package/dist/index.js +1 -1
  78. package/dist/main.js +3 -3
  79. package/dist/migrations.js +5 -5
  80. package/dist/modes/interactive/components/settings-selector.d.ts +3 -1
  81. package/dist/modes/interactive/components/settings-selector.js +1 -1
  82. package/dist/modes/interactive/components/status-indicator.d.ts +1 -1
  83. package/dist/modes/interactive/components/status-indicator.js +1 -1
  84. package/dist/modes/interactive/components/tree-selector.js +1 -1
  85. package/dist/modes/interactive/interactive-mode.js +17 -17
  86. package/dist/modes/interactive/session-share.js +2 -2
  87. package/dist/modes/interactive/theme/dark.json +1 -1
  88. package/dist/modes/interactive/theme/light.json +1 -1
  89. package/dist/modes/interactive/theme/theme-schema.d.ts +18 -0
  90. package/dist/modes/interactive/theme/theme-schema.js +12 -0
  91. package/dist/modes/interactive/theme/theme-tokens.d.ts +255 -0
  92. package/dist/modes/interactive/theme/theme-tokens.js +1 -0
  93. package/dist/modes/interactive/theme/theme.d.ts +7 -10
  94. package/dist/modes/interactive/theme/theme.js +5 -5
  95. package/dist/modes/rpc/rpc-client.d.ts +5 -1
  96. package/dist/modes/rpc/rpc-client.js +2 -2
  97. package/dist/modes/rpc/rpc-mode.js +1 -1
  98. package/dist/modes/rpc/rpc-types.d.ts +20 -0
  99. package/dist/node_modules/@dalcode/dal-advisor/package.json +3 -3
  100. package/dist/node_modules/@dalcode/dal-advisor/src/index.js +8 -8
  101. package/dist/node_modules/@dalcode/dal-awake/package.json +2 -2
  102. package/dist/node_modules/@dalcode/dal-bridge/package.json +2 -2
  103. package/dist/node_modules/@dalcode/dal-capabilities/package.json +4 -4
  104. package/dist/node_modules/@dalcode/dal-capabilities/src/index.js +10 -10
  105. package/dist/node_modules/@dalcode/dal-codeindex/package.json +34 -0
  106. package/dist/node_modules/@dalcode/dal-codeindex/src/extract.js +3 -0
  107. package/dist/node_modules/@dalcode/dal-codeindex/src/format.js +11 -0
  108. package/dist/node_modules/@dalcode/dal-codeindex/src/index.js +4 -0
  109. package/dist/node_modules/@dalcode/dal-codeindex/src/indexer.js +1 -0
  110. package/dist/node_modules/@dalcode/dal-codeindex/src/languages.js +176 -0
  111. package/dist/node_modules/@dalcode/dal-codeindex/src/project.js +1 -0
  112. package/dist/node_modules/@dalcode/dal-codeindex/src/query.js +2 -0
  113. package/dist/node_modules/@dalcode/dal-codeindex/src/runtime.js +1 -0
  114. package/dist/node_modules/@dalcode/dal-codeindex/src/scan.js +1 -0
  115. package/dist/node_modules/@dalcode/dal-codeindex/src/semantic.js +2 -0
  116. package/dist/node_modules/@dalcode/dal-codeindex/src/sqlite.js +1 -0
  117. package/dist/node_modules/@dalcode/dal-codeindex/src/store.js +33 -0
  118. package/dist/node_modules/@dalcode/dal-codeindex/src/worker.js +1 -0
  119. package/dist/node_modules/@dalcode/dal-compat/package.json +2 -2
  120. package/dist/node_modules/@dalcode/dal-dap/package.json +2 -2
  121. package/dist/node_modules/@dalcode/dal-gateway/package.json +2 -2
  122. package/dist/node_modules/@dalcode/dal-goal/package.json +3 -3
  123. package/dist/node_modules/@dalcode/dal-guard/package.json +4 -4
  124. package/dist/node_modules/@dalcode/dal-guard/src/index.js +4 -2
  125. package/dist/node_modules/@dalcode/dal-guard/src/mode.js +2 -2
  126. package/dist/node_modules/@dalcode/dal-guard/src/policy.js +1 -0
  127. package/dist/node_modules/@dalcode/dal-halo/package.json +1 -1
  128. package/dist/node_modules/@dalcode/dal-interactive/package.json +2 -2
  129. package/dist/node_modules/@dalcode/dal-lang/package.json +3 -3
  130. package/dist/node_modules/@dalcode/dal-learn/package.json +2 -2
  131. package/dist/node_modules/@dalcode/dal-lsp/package.json +3 -3
  132. package/dist/node_modules/@dalcode/dal-lsp/src/index.js +12 -10
  133. package/dist/node_modules/@dalcode/dal-mcp/package.json +7 -5
  134. package/dist/node_modules/@dalcode/dal-mcp/src/http-client.d.ts +9 -27
  135. package/dist/node_modules/@dalcode/dal-mcp/src/http-client.js +1 -2
  136. package/dist/node_modules/@dalcode/dal-mcp/src/index.js +17 -17
  137. package/dist/node_modules/@dalcode/dal-mcp/src/protocol-client.d.ts +38 -0
  138. package/dist/node_modules/@dalcode/dal-mcp/src/protocol-client.js +1 -0
  139. package/dist/node_modules/@dalcode/dal-mcp/src/proxy.js +6 -6
  140. package/dist/node_modules/@dalcode/dal-mcp/src/resources.js +1 -0
  141. package/dist/node_modules/@dalcode/dal-mcp/src/stdio-client.d.ts +9 -18
  142. package/dist/node_modules/@dalcode/dal-mcp/src/stdio-client.js +4 -5
  143. package/dist/node_modules/@dalcode/dal-mcp/src/types.d.ts +50 -5
  144. package/dist/node_modules/@dalcode/dal-mcp/src/types.js +1 -1
  145. package/dist/node_modules/@dalcode/dal-office/package.json +2 -2
  146. package/dist/node_modules/@dalcode/dal-office/src/index.d.ts +2 -2
  147. package/dist/node_modules/@dalcode/dal-office/src/index.js +1 -1
  148. package/dist/node_modules/@dalcode/dal-office/src/render/docx.js +1 -1
  149. package/dist/node_modules/@dalcode/dal-office/src/render/pptx.d.ts +8 -0
  150. package/dist/node_modules/@dalcode/dal-office/src/render/pptx.js +3 -3
  151. package/dist/node_modules/@dalcode/dal-office/src/render/xlsx.js +1 -1
  152. package/dist/node_modules/@dalcode/dal-office/src/themes.d.ts +2 -0
  153. package/dist/node_modules/@dalcode/dal-office/src/themes.js +1 -1
  154. package/dist/node_modules/@dalcode/dal-office/src/tools/ppt-generate.js +3 -2
  155. package/dist/node_modules/@dalcode/dal-office/src/tools/ppt-plan.js +2 -2
  156. package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +9 -3
  157. package/dist/node_modules/@dalcode/dal-pi-kit/dist/index.js +1 -1
  158. package/dist/node_modules/@dalcode/dal-pi-kit/dist/session-scope.js +1 -0
  159. package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
  160. package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.js +9 -3
  161. package/dist/node_modules/@dalcode/dal-pi-kit/src/index.js +1 -1
  162. package/dist/node_modules/@dalcode/dal-pi-kit/src/session-scope.js +1 -0
  163. package/dist/node_modules/@dalcode/dal-plugins/package.json +4 -4
  164. package/dist/node_modules/@dalcode/dal-plugins/src/brand.js +1 -1
  165. package/dist/node_modules/@dalcode/dal-plugins/src/index.js +11 -11
  166. package/dist/node_modules/@dalcode/dal-recall/package.json +2 -2
  167. package/dist/node_modules/@dalcode/dal-remote/package.json +2 -2
  168. package/dist/node_modules/@dalcode/dal-review/package.json +3 -3
  169. package/dist/node_modules/@dalcode/dal-rewind/package.json +2 -2
  170. package/dist/node_modules/@dalcode/dal-rewind/src/core.d.ts +0 -1
  171. package/dist/node_modules/@dalcode/dal-rewind/src/core.js +8 -8
  172. package/dist/node_modules/@dalcode/dal-rewind/src/index.js +1 -1
  173. package/dist/node_modules/@dalcode/dal-router/package.json +9 -5
  174. package/dist/node_modules/@dalcode/dal-router/src/advisor.js +1 -1
  175. package/dist/node_modules/@dalcode/dal-router/src/commands.js +8 -7
  176. package/dist/node_modules/@dalcode/dal-router/src/config.d.ts +11 -0
  177. package/dist/node_modules/@dalcode/dal-router/src/config.js +2 -2
  178. package/dist/node_modules/@dalcode/dal-router/src/index.js +4 -4
  179. package/dist/node_modules/@dalcode/dal-router/src/roles/changes.js +5 -0
  180. package/dist/node_modules/@dalcode/dal-router/src/roles/index.js +13 -0
  181. package/dist/node_modules/@dalcode/dal-router/src/roles/models.d.ts +50 -0
  182. package/dist/node_modules/@dalcode/dal-router/src/roles/models.js +1 -0
  183. package/dist/node_modules/@dalcode/dal-router/src/roles/prompts.js +40 -0
  184. package/dist/node_modules/@dalcode/dal-router/src/roles/signals.js +2 -0
  185. package/dist/node_modules/@dalcode/dal-router/src/runtime.d.ts +3 -0
  186. package/dist/node_modules/@dalcode/dal-router/src/runtime.js +1 -1
  187. package/dist/node_modules/@dalcode/dal-router/src/subagent.js +1 -1
  188. package/dist/node_modules/@dalcode/dal-rtk/package.json +2 -2
  189. package/dist/node_modules/@dalcode/dal-skills/package.json +3 -3
  190. package/dist/node_modules/@dalcode/dal-skills/src/bundled/dal-slides/SKILL.md +74 -0
  191. package/dist/node_modules/@dalcode/dal-skills/src/bundled.js +1 -1
  192. package/dist/node_modules/@dalcode/dal-skills/src/client.js +1 -1
  193. package/dist/node_modules/@dalcode/dal-skills/src/index.js +14 -14
  194. package/dist/node_modules/@dalcode/dal-skills/src/packages.js +3 -3
  195. package/dist/node_modules/@dalcode/dal-skills/src/search.js +1 -1
  196. package/dist/node_modules/@dalcode/dal-statusline/package.json +2 -2
  197. package/dist/node_modules/@dalcode/dal-structured/package.json +2 -2
  198. package/dist/node_modules/@dalcode/dal-subagent/package.json +5 -5
  199. package/dist/node_modules/@dalcode/dal-telemetry/package.json +3 -3
  200. package/dist/node_modules/@dalcode/dal-terminal/package.json +2 -2
  201. package/dist/node_modules/@dalcode/dal-tool-catalog/package.json +2 -2
  202. package/dist/node_modules/@dalcode/dal-tool-catalog/src/index.js +4 -4
  203. package/dist/node_modules/@dalcode/dal-usage/package.json +2 -2
  204. package/dist/node_modules/@dalcode/dal-web/package.json +3 -3
  205. package/dist/node_modules/@dalcode/dal-workflow/LICENSE +27 -0
  206. package/dist/node_modules/@dalcode/dal-workflow/package.json +2 -2
  207. package/dist/node_modules/@dalcode/dal-workflow/src/index.js +4 -4
  208. package/dist/node_modules/@dalcode/dal-workflow/src/plan-mode.js +13 -13
  209. package/dist/node_modules/@dalcode/dal-workflow/src/todo-snapshot.js +2 -0
  210. package/dist/node_modules/@dalcode/dal-workflow/src/todo.js +4 -4
  211. package/dist/node_modules/@dalcode/deepailab/package.json +3 -3
  212. package/dist/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
  213. package/dist/node_modules/@earendil-works/pi-ai/README.md +5 -34
  214. package/dist/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +5 -5
  215. package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-shared.js +1 -1
  216. package/dist/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js +4 -4
  217. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js +1 -1
  218. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js +6 -6
  219. package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js +2 -2
  220. package/dist/node_modules/@earendil-works/pi-ai/dist/index.d.ts +0 -1
  221. package/dist/node_modules/@earendil-works/pi-ai/dist/index.js +1 -1
  222. package/dist/node_modules/@earendil-works/pi-ai/dist/models.d.ts +1 -0
  223. package/dist/node_modules/@earendil-works/pi-ai/dist/models.js +1 -1
  224. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/compat-schema.d.ts +359 -0
  225. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/compat-schema.js +1 -0
  226. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  227. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
  228. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/anthropic.json +1 -1
  229. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/azure.json +1 -1
  230. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
  231. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/cerebras.json +1 -1
  232. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
  233. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-workers-ai.json +1 -1
  234. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
  235. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -1
  236. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/google.json +1 -1
  237. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/groq.json +1 -1
  238. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
  239. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/kimi-coding.json +1 -1
  240. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/minimax-cn.json +1 -1
  241. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/minimax.json +1 -1
  242. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/mistral.json +1 -1
  243. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/moonshotai-cn.json +1 -1
  244. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
  245. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openai-codex.json +1 -1
  246. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -1
  247. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
  248. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
  249. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  250. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-cn.json +1 -1
  251. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.json +1 -1
  252. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/radius.json +1 -1
  253. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/together.json +1 -1
  254. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  255. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xai.json +1 -1
  256. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-ams.json +1 -1
  257. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-cn.json +1 -1
  258. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-sgp.json +1 -1
  259. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi.json +1 -1
  260. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.js +1 -1
  261. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/model-schema.d.ts +90 -0
  262. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/model-schema.js +1 -0
  263. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/openrouter-api.js +1 -0
  264. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.js +1 -1
  265. package/dist/node_modules/@earendil-works/pi-ai/dist/types.d.ts +5 -146
  266. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +1 -1
  267. package/dist/node_modules/@earendil-works/pi-ai/package.json +2 -2
  268. package/dist/node_modules/@earendil-works/pi-codemode/README.md +195 -11
  269. package/dist/node_modules/@earendil-works/pi-codemode/dist/cloudflare.js +1 -0
  270. package/dist/node_modules/@earendil-works/pi-codemode/dist/declarations.d.ts +0 -2
  271. package/dist/node_modules/@earendil-works/pi-codemode/dist/declarations.js +9 -84
  272. package/dist/node_modules/@earendil-works/pi-codemode/dist/index.d.ts +5 -2
  273. package/dist/node_modules/@earendil-works/pi-codemode/dist/index.js +1 -1
  274. package/dist/node_modules/@earendil-works/pi-codemode/dist/portable.js +1 -0
  275. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/execution.d.ts +29 -0
  276. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/execution.js +1 -0
  277. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/host.d.ts +3 -16
  278. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/host.js +1 -1
  279. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/inline.d.ts +13 -0
  280. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/inline.js +1 -0
  281. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/prelude-source.js +14 -6
  282. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/protocol.d.ts +72 -0
  283. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/protocol.js +1 -1
  284. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/remote.d.ts +32 -0
  285. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/remote.js +1 -0
  286. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/vm.js +3 -0
  287. package/dist/node_modules/@earendil-works/pi-codemode/dist/runtime/worker.js +1 -3
  288. package/dist/node_modules/@earendil-works/pi-codemode/dist/source.js +4 -3
  289. package/dist/node_modules/@earendil-works/pi-codemode/dist/types.d.ts +51 -1
  290. package/dist/node_modules/@earendil-works/pi-codemode/package.json +14 -2
  291. package/dist/node_modules/@earendil-works/pi-coding-agent/package.json +1 -1
  292. package/dist/node_modules/@earendil-works/pi-mcp/CHANGELOG.md +13 -0
  293. package/dist/node_modules/@earendil-works/pi-mcp/dist/client.js +1 -1
  294. package/dist/node_modules/@earendil-works/pi-mcp/dist/index.d.ts +1 -1
  295. package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/errors.d.ts +2 -2
  296. package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/errors.js +1 -1
  297. package/dist/node_modules/@earendil-works/pi-mcp/dist/oauth/flow.js +1 -1
  298. package/dist/node_modules/@earendil-works/pi-mcp/dist/protocol/content.d.ts +1 -1
  299. package/dist/node_modules/@earendil-works/pi-mcp/dist/transports/streamable-http.d.ts +2 -2
  300. package/dist/node_modules/@earendil-works/pi-mcp/dist/transports/streamable-http.js +4 -4
  301. package/dist/node_modules/@earendil-works/pi-mcp/dist/transports/transport.d.ts +4 -1
  302. package/dist/node_modules/@earendil-works/pi-mcp/package.json +1 -1
  303. package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  304. package/dist/node_modules/@earendil-works/pi-tui/README.md +5 -3
  305. package/dist/node_modules/@earendil-works/pi-tui/dist/components/editor.js +6 -6
  306. package/dist/node_modules/@earendil-works/pi-tui/dist/components/input.js +2 -2
  307. package/dist/node_modules/@earendil-works/pi-tui/dist/index.d.ts +1 -1
  308. package/dist/node_modules/@earendil-works/pi-tui/dist/index.js +1 -1
  309. package/dist/node_modules/@earendil-works/pi-tui/dist/keys.js +5 -5
  310. package/dist/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.js +1 -1
  311. package/dist/node_modules/@earendil-works/pi-tui/dist/terminal-image.js +1 -1
  312. package/dist/node_modules/@earendil-works/pi-tui/dist/tui-alt-screen.js +3 -3
  313. package/dist/node_modules/@earendil-works/pi-tui/dist/tui-main-screen.js +1 -1
  314. package/dist/node_modules/@earendil-works/pi-tui/dist/tui.d.ts +4 -0
  315. package/dist/node_modules/@earendil-works/pi-tui/dist/tui.js +2 -2
  316. package/dist/node_modules/@earendil-works/pi-tui/dist/utils.js +1 -1
  317. package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
  318. package/dist/sdk/index.d.ts +3 -3
  319. package/dist/sdk/index.js +1 -1
  320. package/dist/sdk/rewind.d.ts +1 -1
  321. package/dist/sdk/rewind.js +1 -1
  322. package/dist/utils/clipboard.js +1 -1
  323. package/dist/utils/output-files.js +1 -1
  324. package/dist/utils/temp-files.js +1 -0
  325. package/docs/security.md +24 -7
  326. package/examples/README.md +0 -3
  327. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  328. package/examples/extensions/dynamic-resources/dynamic.json +1 -1
  329. package/examples/extensions/gondolin/package-lock.json +2 -2
  330. package/examples/extensions/gondolin/package.json +1 -1
  331. package/examples/extensions/minimal-mode.ts +4 -5
  332. package/examples/extensions/overlay-test.ts +2 -2
  333. package/examples/extensions/sandbox/package-lock.json +2 -2
  334. package/examples/extensions/sandbox/package.json +1 -1
  335. package/examples/extensions/subagent/index.ts +4 -6
  336. package/examples/extensions/with-deps/package-lock.json +2 -2
  337. package/examples/extensions/with-deps/package.json +1 -1
  338. package/npm-shrinkwrap.json +9 -460
  339. package/package.json +3 -12
  340. package/dist/modes/interactive/theme/theme-json.d.ts +0 -75
  341. package/dist/modes/interactive/theme/theme-json.js +0 -12
  342. package/dist/modes/interactive/theme/theme-schema.json +0 -361
  343. package/dist/node_modules/@earendil-works/chord/README.md +0 -264
  344. package/dist/node_modules/@earendil-works/chord/dist/api.js +0 -1
  345. package/dist/node_modules/@earendil-works/chord/dist/bundler.js +0 -1
  346. package/dist/node_modules/@earendil-works/chord/dist/context/index.js +0 -1
  347. package/dist/node_modules/@earendil-works/chord/dist/delta/apply-immutable-trusted.js +0 -1
  348. package/dist/node_modules/@earendil-works/chord/dist/delta/diff.js +0 -1
  349. package/dist/node_modules/@earendil-works/chord/dist/delta/draft.js +0 -0
  350. package/dist/node_modules/@earendil-works/chord/dist/delta/index.js +0 -1
  351. package/dist/node_modules/@earendil-works/chord/dist/delta/revision-validator.js +0 -1
  352. package/dist/node_modules/@earendil-works/chord/dist/delta/tracker.js +0 -1
  353. package/dist/node_modules/@earendil-works/chord/dist/facets/host.js +0 -1
  354. package/dist/node_modules/@earendil-works/chord/dist/facets/loader.js +0 -1
  355. package/dist/node_modules/@earendil-works/chord/dist/index.js +0 -1
  356. package/dist/node_modules/@earendil-works/chord/dist/json.js +0 -1
  357. package/dist/node_modules/@earendil-works/chord/dist/node/bundle-loader.js +0 -2
  358. package/dist/node_modules/@earendil-works/chord/dist/node/bundle.js +0 -4
  359. package/dist/node_modules/@earendil-works/chord/dist/node/manifest.js +0 -1
  360. package/dist/node_modules/@earendil-works/chord/dist/node/package.js +0 -1
  361. package/dist/node_modules/@earendil-works/chord/dist/node.js +0 -1
  362. package/dist/node_modules/@earendil-works/chord/dist/services/consumer.js +0 -1
  363. package/dist/node_modules/@earendil-works/chord/dist/services/errors.js +0 -1
  364. package/dist/node_modules/@earendil-works/chord/dist/services/handle.js +0 -1
  365. package/dist/node_modules/@earendil-works/chord/dist/services/instances.js +0 -1
  366. package/dist/node_modules/@earendil-works/chord/dist/services/loopback.js +0 -1
  367. package/dist/node_modules/@earendil-works/chord/dist/services/provider.js +0 -1
  368. package/dist/node_modules/@earendil-works/chord/dist/services/state-codec.js +0 -1
  369. package/dist/node_modules/@earendil-works/chord/dist/services/state-internals.js +0 -1
  370. package/dist/node_modules/@earendil-works/chord/dist/services/state.js +0 -1
  371. package/dist/node_modules/@earendil-works/chord/dist/services/wire.js +0 -1
  372. package/dist/node_modules/@earendil-works/chord/dist/types.js +0 -0
  373. package/dist/node_modules/@earendil-works/chord/package.json +0 -62
  374. package/dist/node_modules/@earendil-works/chord/src/delta/README.md +0 -191
  375. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/assistant-message-frame.d.ts +0 -63
  376. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/assistant-message-frame.js +0 -1
  377. package/dist/node_modules/@earendil-works/pi-client/CHANGELOG.md +0 -45
  378. package/dist/node_modules/@earendil-works/pi-client/LICENSE +0 -21
  379. package/dist/node_modules/@earendil-works/pi-client/README.md +0 -72
  380. package/dist/node_modules/@earendil-works/pi-client/dist/client.js +0 -1
  381. package/dist/node_modules/@earendil-works/pi-client/dist/connection.js +0 -1
  382. package/dist/node_modules/@earendil-works/pi-client/dist/errors.js +0 -1
  383. package/dist/node_modules/@earendil-works/pi-client/dist/index.js +0 -1
  384. package/dist/node_modules/@earendil-works/pi-client/dist/promise.js +0 -1
  385. package/dist/node_modules/@earendil-works/pi-client/dist/transport.js +0 -0
  386. package/dist/node_modules/@earendil-works/pi-client/dist/types.js +0 -0
  387. package/dist/node_modules/@earendil-works/pi-client/dist/unix.js +0 -1
  388. package/dist/node_modules/@earendil-works/pi-client/package.json +0 -46
  389. package/dist/node_modules/@earendil-works/pi-protocol/LICENSE +0 -21
  390. package/dist/node_modules/@earendil-works/pi-protocol/README.md +0 -41
  391. package/dist/node_modules/@earendil-works/pi-protocol/dist/cbor/decoder.js +0 -1
  392. package/dist/node_modules/@earendil-works/pi-protocol/dist/cbor/encoder.js +0 -1
  393. package/dist/node_modules/@earendil-works/pi-protocol/dist/cbor/index.js +0 -1
  394. package/dist/node_modules/@earendil-works/pi-protocol/dist/cbor/options.js +0 -1
  395. package/dist/node_modules/@earendil-works/pi-protocol/dist/codec.js +0 -1
  396. package/dist/node_modules/@earendil-works/pi-protocol/dist/framing.js +0 -1
  397. package/dist/node_modules/@earendil-works/pi-protocol/dist/index.js +0 -1
  398. package/dist/node_modules/@earendil-works/pi-protocol/dist/protocol.js +0 -1
  399. package/dist/node_modules/@earendil-works/pi-protocol/dist/schemas.js +0 -1
  400. package/dist/node_modules/@earendil-works/pi-protocol/package.json +0 -39
  401. package/dist/node_modules/@earendil-works/pi-server/CHANGELOG.md +0 -81
  402. package/dist/node_modules/@earendil-works/pi-server/LICENSE +0 -21
  403. package/dist/node_modules/@earendil-works/pi-server/README.md +0 -63
  404. package/dist/node_modules/@earendil-works/pi-server/dist/connection.js +0 -1
  405. package/dist/node_modules/@earendil-works/pi-server/dist/errors.js +0 -1
  406. package/dist/node_modules/@earendil-works/pi-server/dist/index.js +0 -1
  407. package/dist/node_modules/@earendil-works/pi-server/dist/listener.js +0 -0
  408. package/dist/node_modules/@earendil-works/pi-server/dist/server.js +0 -1
  409. package/dist/node_modules/@earendil-works/pi-server/dist/session-router.js +0 -1
  410. package/dist/node_modules/@earendil-works/pi-server/dist/testing/client.js +0 -1
  411. package/dist/node_modules/@earendil-works/pi-server/dist/testing/host.js +0 -1
  412. package/dist/node_modules/@earendil-works/pi-server/dist/testing/index.js +0 -1
  413. package/dist/node_modules/@earendil-works/pi-server/dist/testing/server.js +0 -1
  414. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/address.js +0 -1
  415. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/index.js +0 -1
  416. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/listener.js +0 -1
  417. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/preset.js +0 -1
  418. package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/types.js +0 -0
  419. package/dist/node_modules/@earendil-works/pi-server/dist/types.js +0 -0
  420. package/dist/node_modules/@earendil-works/pi-server/package.json +0 -45
  421. package/examples/plugins/pi-example-plugin/README.md +0 -38
  422. package/examples/plugins/pi-example-plugin/package.json +0 -10
  423. package/examples/plugins/pi-example-plugin/src/contract.ts +0 -13
  424. package/examples/plugins/pi-example-plugin/src/session.ts +0 -24
  425. package/examples/plugins/pi-example-plugin/src/tui.ts +0 -31
  426. /package/dist/node_modules/{@earendil-works/chord → @dalcode/dal-codeindex}/LICENSE +0 -0
@@ -1,264 +0,0 @@
1
- # @earendil-works/chord
2
-
3
- Chord is an application-composition runtime for systems assembled from
4
- plugins/extensions. It provides facets, services, replicated state, and a
5
- pluggable remote-service boundary. It is developed as a standalone package in
6
- the Pi monorepo, but it is not a Pi package: it does not depend on any other Pi
7
- workspace package and can be used by unrelated applications.
8
-
9
- ## What Chord is for
10
-
11
- A single application feature may need to run in several environments: for
12
- example, an agent worker, a terminal UI, and a remote WebUI. Chord provides the
13
- generic machinery to write such extensions in a way that is both delightful for
14
- humans as well as agents.
15
-
16
- The design has a few connected pieces:
17
-
18
- - **Plugins** are synchronous setup units that declare the services they provide
19
- and require. After every plugin has declared its shape, a host validates the
20
- complete dependency graph, binds services, activates providers before consumers,
21
- and disposes resources in reverse dependency order. These units are called
22
- *facets*.
23
-
24
- - **Facets** are parts of a plugin. Each facet is bundled up separately and runs
25
- in the process or environment where it's supposed to run. You can use facets
26
- to split a plugin into separate pieces that need to be loaded into different
27
- processes and environments (think backend, browser, TUI etc.)
28
-
29
- - **Services** are typed, stable tokens with either one provider (**singleton**)
30
- or dynamic keyed instances (**keyed**). A service can be process-local, with
31
- an unrestricted JavaScript contract, or remotely exposable. Consumers retain a
32
- stable facade while a provider disconnects or is replaced.
33
-
34
- - **Replicated state** exposes authoritative state to local and remote
35
- connected consumers. Producers publish atomic overlay transactions with
36
- `change(context, callback)`; consumers receive complete immutable values. Draft
37
- proxies exist only during the callback and become unusable afterward. Preparation
38
- materializes a structurally shared immutable candidate and one exact decoded
39
- operation batch, while each remote client/state stream owns independent path-codec
40
- state. Replicas become unready on disconnect or replacement until rehydrated.
41
-
42
- - **Delta tracking** records and coalesces operations over tracked plain JSON.
43
- It preserves common string and array operations, supports durable base
44
- batches, and validates untrusted operations as they are applied. Batches
45
- guarantee convergence but are not canonical or necessarily minimal.
46
-
47
- - **Remote service sources** advertise services available outside a facet host
48
- and open bindings for the services its facets require. Bindings carry logical
49
- calls and subscriptions through an application-supplied adapter. Chord
50
- requires strict-JSON arguments, results, snapshots, updates, and catalogues,
51
- but does not prescribe framing, routing, transport, or an application wire
52
- envelope. `JsonRepresentation<T>` derives a wire-safe type for application data
53
- with unknown payloads, while `isJsonValue()` validates received values at an
54
- adapter boundary. Symmetric RPC peers are planned as one optional
55
- implementation of this boundary.
56
-
57
- - **Context** Chord provides a Go-like context system for cancellation and
58
- invocation-scoped application values. Applications can carry permissions or
59
- telemetry through those values without Chord depending on either.
60
-
61
- The current runtime exports service tokens, singleton and keyed providers,
62
- remote bindings, replicated state, facet hosts, and facet loaders from
63
- `@earendil-works/chord`. Import public types and general runtime APIs from the
64
- package root. Context constants and functions live in
65
- `@earendil-works/chord/context` because their generic names should not pollute
66
- the root API.
67
- Chord-owned identifiers use the `chord.*` namespace and its reserved service
68
- prefix is `$chord.*`.
69
-
70
- ## Remote service adapters
71
-
72
- Chord owns its transport-independent service wire grammar. Consumer adapters
73
- use `createServiceCatalogueCall()`, `createServiceSubscribeCall()`, and
74
- `createServiceUnsubscribeCall()` for `$chord.service` control calls.
75
- `createRemoteServiceEndpoint()` handles those calls for one provider consumer,
76
- including subscription activation and cleanup. `parseServiceCall()`,
77
- `parseServiceCatalogue()`, and the decoded/wire snapshot and update parsers
78
- validate Chord semantics after an adapter has established a strict-JSON
79
- boundary. `RemoteServiceErrorCode` and `REMOTE_SERVICE_ERROR_CODES` define the
80
- service errors that may cross that boundary.
81
-
82
- Replicated state operations use one `createServiceStateEncoder()` at the
83
- provider side and one `createServiceStateDecoder()` at the consumer side for
84
- each subscription. Those registries create an independent Delta path dictionary
85
- for every instance/member state and reset it on replacement, unavailability,
86
- close, or fresh hydration. Applications may place these values inside any
87
- routing, request, response, or event envelope; Chord does not prescribe that
88
- outer protocol.
89
-
90
- Provider subscriptions atomically capture a snapshot and buffer subsequent
91
- updates until activation. Activation and reentrant publication use the same FIFO.
92
- The provider retains at most 100 pending updates per subscription, excluding the
93
- running delivery. Adding update 101 replaces the entire pending queue with
94
- `{ type: "reset", snapshot }`: a current full subscription snapshot whose state
95
- members contain `[["r", value]]` and their new sequence baselines. It also captures
96
- current instance membership, so discarded spawn/close/replacement events cannot
97
- leave stale instances behind. Live keyed generations retain their existing handles.
98
- The reset carries the context of the publication that triggered overflow.
99
-
100
- Consumers and codecs must handle this explicit reset before accepting subsequent
101
- ordinary deltas. A root operation in an ordinary `state` update does **not** permit
102
- a sequence gap. Resets restart the subscription's path dictionaries, and later
103
- deltas must be contiguous from each reset baseline. Transport adapters must
104
- preserve snapshot/reset/update order; they must not drop encoded delta batches or
105
- assume their own asynchronous queues are bounded by the provider's queue.
106
-
107
- ## Tracking JSON deltas
108
-
109
- Import the standalone transactional tracker from `@earendil-works/chord/delta`:
110
-
111
- ```ts
112
- import { applyImmutable, track } from "@earendil-works/chord/delta";
113
-
114
- const tracker = track({ output: "", count: 0 });
115
- const change = tracker.beginChange();
116
- change.state.output += "done\n";
117
- change.state.count += 1;
118
- const prepared = change.prepare();
119
-
120
- tracker.adopt(prepared);
121
- const replica = applyImmutable(prepared.base, prepared.ops);
122
- ```
123
-
124
- `tracker.value` is always the latest adopted immutable revision. Preparation does
125
- not change authority; adoption validates the preparation and swaps the root pointer.
126
- Assigned containers are copied by value and unchanged subtrees may be shared between
127
- revisions.
128
-
129
- The tracker uses trusted immutable ownership rather than defensive copying or
130
- freezing. `track(initial)`, `prepareReplace(value)`, `replicatedState(initial)`, and
131
- `replace(context, value)` take ownership of alias-free strict-JSON roots without
132
- walking them. Callers must not mutate transferred or published data. Values placed
133
- through drafts are already copied, so that walk also rejects non-strict JSON before
134
- the draft changes. Published values are not frozen. In-process loopback consumers
135
- may share their containers with the provider; mutating a consumed value violates
136
- the contract and can corrupt authority. Clone or serialize at any mutable trust
137
- boundary.
138
-
139
- Replicated state provides the same model through a callback:
140
-
141
- ```ts
142
- const initial = { output: "", count: 0 };
143
- const status = env.replicatedState(initial); // transfers ownership of initial
144
- status.change(context, (draft) => {
145
- draft.output += "done\n";
146
- draft.count += 1;
147
- });
148
- ```
149
-
150
- A successful `change()` publishes exactly one atomic revision. If its callback
151
- throws, the original value and sequence remain unchanged. Draft handles become
152
- unusable when the callback returns. Chord emits string append and front-truncate
153
- operations, array splices and permutations, sets, and deletes; large edit sets may
154
- fold into a complete replacement. Remote connection plumbing encodes each batch
155
- independently for every client/state pairing.
156
-
157
- ### Public state subscriptions
158
-
159
- `state.subscribe(async (value, context, delivery) => { ... })` serializes callbacks
160
- independently for each subscription. Hydration starts immediately when a value is
161
- available, and its returned promise must settle before updates start. Synchronous
162
- callbacks still run synchronously. Read the captured `value` inside an asynchronous
163
- callback: `state.value` may already refer to a later revision.
164
-
165
- Each subscription retains at most 100 pending complete-value deliveries, excluding
166
- the running callback. On overflow, only the newest pending value, context, and
167
- delivery metadata are retained; a not-yet-started initial hydration is preserved.
168
- Thus public delivery sequences may skip. This is a frame-count policy, not a byte
169
- limit. Internal exact-operation subscriptions remain synchronous and receive every
170
- revision, independently of slow public callbacks.
171
-
172
- The returned unsubscribe function immediately discards pending work and prevents
173
- new callbacks. It neither aborts nor waits for the running callback. Synchronous
174
- throws and promise rejections are observed, reported, and do not stop other
175
- subscriptions or subsequent callbacks. Attached sources and remote bindings use
176
- their `onError` handler; local mutable states (and attached sources without a
177
- handler) report failures by throwing in a microtask. Unsubscribing does not hide a
178
- later rejection from the running callback.
179
-
180
- The standalone [Delta guide](src/delta/README.md) defines the complete ownership,
181
- lifecycle, operation, and replica contracts.
182
-
183
- ## Bundling and loading facets
184
-
185
- `@earendil-works/chord/bundler` uses esbuild to turn ESM or TypeScript application
186
- entries into independent, content-addressed CommonJS files. The package-level API
187
- reads plugin identity and build configuration from `package.json`, then applies
188
- facet path conventions supplied by the host application:
189
-
190
- ```json
191
- {
192
- "name": "@example/my-plugin",
193
- "version": "1.0.0",
194
- "type": "module",
195
- "peerDependencies": {
196
- "@earendil-works/chord": "^0.84.4"
197
- },
198
- "chord": {
199
- "facets": {
200
- "worker": "./src/custom-worker.ts",
201
- "presentation": false
202
- }
203
- }
204
- }
205
- ```
206
-
207
- ```ts
208
- import { bundleFacetPackage } from "@earendil-works/chord/bundler";
209
-
210
- await bundleFacetPackage({
211
- packagePath: "/path/to/my-plugin",
212
- outdir: "/application-owned/plugin-builds/my-plugin",
213
- defaultFacets: {
214
- worker: "src/worker.ts",
215
- presentation: "src/presentation.ts",
216
- },
217
- });
218
- ```
219
-
220
- Existing conventional files become entries unless `chord.facets` overrides or
221
- disables them. Peer dependencies are externalized and resolved against the host
222
- when loading. Chord never installs dependencies or runs package lifecycle
223
- scripts. `bundleFacets()` remains available as the lower-level API for callers
224
- that already have explicit plugin identity and entry mappings.
225
-
226
- The output directory contains one `.cjs` file per entry plus
227
- `chord-facets.json`. Load one application-selected entry through the Node-only
228
- loader:
229
-
230
- ```ts
231
- import { createFacetBundleLoader } from "@earendil-works/chord/node";
232
-
233
- const loader = createFacetBundleLoader({
234
- manifestPath: "/application-owned/plugin-builds/my-plugin/chord-facets.json",
235
- entry: "worker",
236
- resolveExternal: (specifier) => import.meta.resolve(specifier),
237
- });
238
- const loaded = await loader.load();
239
- ```
240
-
241
- Each `load()` verifies SHA-256 integrity and compiles the CommonJS body directly
242
- with `node:vm` instead of putting the plugin into Node's CommonJS or ESM module
243
- cache. Externals are resolved by the host and loaded through a restricted
244
- `require`; esbuild lowers dynamic imports so they use the same path. Disposing a
245
- retired generation releases the loader's facet references, making its compiled
246
- code eligible for garbage collection once plugin-owned resources are also gone.
247
-
248
- For transport to another Node host, `readFacetBundleArtifact()` packages one
249
- verified manifest entry with its source, and `createFacetBundleArtifactLoader()`
250
- materializes fresh temporary generations while resolving externals against the
251
- receiving host.
252
-
253
- To reload, load a candidate, pass its facets to `FacetHost.reload()`, dispose the
254
- candidate on failure, and dispose the retired `LoadedFacets` only after a
255
- successful cutover. The host activates and validates the candidate while the
256
- currently active providers remain routed, then replaces each singleton directly
257
- without an unavailable interval. Stable service handles therefore do not become
258
- disconnected during an ordinary reload. Keyed instances
259
- remain incarnation-specific and replacements receive fresh generations. The
260
- bundler writes a complete temporary directory before replacing the previous
261
- output, so loaders do not observe partially built generations.
262
-
263
- See [PLANNING.md](PLANNING.md) for the broader RPC and generation-loading
264
- architecture.
@@ -1 +0,0 @@
1
- var i=Object.defineProperty;var o=(e,t)=>i(e,"name",{value:t,configurable:!0});import{FacetKernel as s}from"./facets/host.js";import{disposeLoadedFacets as c}from"./facets/loader.js";import{RemoteServiceBindingImpl as d}from"./services/consumer.js";import{attachReplicatedStateSource as f,MutableReplicatedStateImpl as l}from"./services/state.js";async function v(e){const t=new s(e);return await t.activate(),Object.freeze({services:t.provider,reload:o(a=>t.reload(a),"reload"),dispose:o(()=>t.dispose(),"dispose")})}o(v,"createFacetHost");function y(e){const t=Object.freeze([...e]);return{async load(){return{facets:t,async dispose(){}}}}}o(y,"createStaticFacetLoader");function S(e){return{async load(){const t=[];try{for(const r of e)t.push(await r.load())}catch(r){const n=await c(t.reverse());throw n.length>0?new AggregateError([r,...n],"Facet loading and cleanup failed"):r}let a=!1;return{facets:Object.freeze(t.flatMap(({facets:r})=>r)),async dispose(){if(a)return;a=!0;const r=await c([...t].reverse());if(r.length===1)throw r[0];if(r.length>1)throw new AggregateError(r,"Failed to dispose loaded facets")}}}}}o(S,"combineFacetLoaders");function F(e){return e}o(F,"defineFacet");function b(e,t){if(e.length===0)throw new TypeError("Service ID must not be empty");if(e.startsWith("$chord."))throw new TypeError("Service IDs beginning with $chord. are reserved");return Object.freeze({id:e,local:t?.local??!1})}o(b,"defineService");function x(e){return new d(e)}o(x,"createRemoteServiceBinding");function E(e,t){return p(e)?f(e,t):new l(e)}o(E,"replicatedState");function p(e){return typeof e.attach=="function"}o(p,"isReplicatedStateSource");export{S as combineFacetLoaders,v as createFacetHost,x as createRemoteServiceBinding,y as createStaticFacetLoader,F as defineFacet,b as defineService,E as replicatedState};
@@ -1 +0,0 @@
1
- import{bundleFacets as o}from"./node/bundle.js";import{bundleFacetPackage as t}from"./node/package.js";export{t as bundleFacetPackage,o as bundleFacets};
@@ -1 +0,0 @@
1
- var x=Object.defineProperty;var r=(e,t)=>x(e,"name",{value:t,configurable:!0});const s=Object.freeze({token:Symbol("chord.abortSignal")});class c{static{r(this,"BaseContext")}get abortSignal(){return this.value(s)}}class l extends c{static{r(this,"EmptyContext")}#t;constructor(t){super(),this.#t=t}value(t){}toString(){return this.#t}}class d extends c{static{r(this,"ContextValue")}#t;#e;#n;constructor(t,n,o){super(),this.#t=t,this.#e=n,this.#n=o}value(t){return t.token===this.#e.token?this.#n:this.#t.value(t)}toString(){return`${this.#t}.WithValue(${this.#e.token.description??"anonymous"})`}}const p=new l("[Context BACKGROUND_CONTEXT]"),O=new l("[Context TODO_CONTEXT]");function E(e){return Object.freeze({token:Symbol(e)})}r(E,"createContextKey");function b(e,t,n){return new d(n,e,t)}r(b,"withContextValue");function f(e,t){const n=t.abortSignal,o=n===void 0?e:AbortSignal.any([n,e]);return b(s,o,t)}r(f,"withAbortSignal");function T(e){return b(s,void 0,e)}r(T,"withoutAbortSignal");function S(e){const t=new AbortController;return{context:f(t.signal,e),cancel:r(n=>t.abort(n),"cancel")}}r(S,"withCancel");function g(e,t){const n=t.abortSignal;return n===void 0?e:n.aborted?Promise.reject(h(n)):new Promise((o,u)=>{const i=r(()=>u(h(n)),"onAbort");n.addEventListener("abort",i,{once:!0}),e.then(a=>{n.removeEventListener("abort",i),o(a)},a=>{n.removeEventListener("abort",i),u(a)})})}r(g,"awaitWithContext");function h(e){const t=e.reason;return t instanceof Error?t:new DOMException("The operation was aborted","AbortError")}r(h,"abortError");export{p as BACKGROUND_CONTEXT,O as TODO_CONTEXT,g as awaitWithContext,E as createContextKey,f as withAbortSignal,S as withCancel,b as withContextValue,T as withoutAbortSignal};
@@ -1 +0,0 @@
1
- var w=Object.defineProperty;var l=(e,r)=>w(e,"name",{value:r,configurable:!0});const p={value:void 0,writable:!0,enumerable:!0,configurable:!0};function A(e,r){let n=e;const o=new WeakSet;for(const t of r){if(t[0]==="r"){n=t[1];continue}if(t[0]==="p"||t[0]==="m"){const a=d(n,t[1],t[1].length,o);if(n=a.root,!Array.isArray(a.target))throw new TypeError("Trusted array operation target is not an array");t[0]==="p"?g(a.target,t[2],t[3],t[4]):b(a.target,t[2]);continue}const c=t[1],i=d(n,c,c.length-1,o);n=i.root;const s=c[c.length-1];switch(t[0]){case"s":f(i.target,s,t[2]);break;case"d":if(Array.isArray(i.target)){if(typeof s!="number")throw new TypeError("Trusted array deletion key is not numeric");g(i.target,s,1,[])}else Reflect.deleteProperty(i.target,s);break;case"a":{const a=y(i.target,s);if(typeof a!="string")throw new TypeError("Trusted append target is not a string");f(i.target,s,`${a}${t[2]}`);break}case"t":{const a=y(i.target,s);if(typeof a!="string")throw new TypeError("Trusted truncate target is not a string");f(i.target,s,a.slice(t[2]));break}}}return n}l(A,"applyImmutableTrusted");function d(e,r,n,o){if(!T(e))throw new TypeError("Trusted operation root is not a container");let t=e;o.has(e)||(t=h(e),o.add(t));let c=t;for(let i=0;i<n;i++){const s=r[i],a=y(c,s);if(!T(a))throw new TypeError("Trusted operation path is not a container");if(o.has(a)){c=a;continue}const u=h(a);f(c,s,u),o.add(u),c=u}return{root:t,target:c}}l(d,"copyPath");function h(e){if(Array.isArray(e))return Array.from(e);const r=Object.create(Object.getPrototypeOf(e)===null?null:Object.prototype);for(const n of Object.keys(e))f(r,n,e[n]);return r}l(h,"shallowCopy");function y(e,r){return e[r]}l(y,"read");function f(e,r,n){p.value=n,Object.defineProperty(e,r,p),p.value=void 0}l(f,"defineData");function g(e,r,n,o){const t=e.length,c=o.length-n;c>0?(e.length=t+c,e.copyWithin(r+o.length,r+n,t)):c<0&&(e.copyWithin(r+o.length,r+n,t),e.length=t+c);for(let i=0;i<o.length;i++)f(e,r+i,o[i])}l(g,"spliceTrusted");function b(e,r){if(e.length!==r.length)throw new TypeError("Trusted permutation length mismatch");const n=e.slice();for(let o=0;o<r.length;o++)e[o]=n[r[o]]}l(b,"permuteTrusted");function T(e){return e!==null&&typeof e=="object"}l(T,"isContainer");export{A as applyImmutableTrusted};
@@ -1 +0,0 @@
1
- var X=Object.defineProperty;var A=(n,s)=>X(n,"name",{value:s,configurable:!0});import{overlap as q,RESERVED_SEGMENTS as B}from"./index.js";const K=65536,U=4096,O=new WeakSet,w=A((n,s)=>{if(!O.has(n)){if(n.length>=U){O.add(n);return}n.push(s)}},"emitOperation"),I=A(n=>n!==null&&typeof n=="object","isContainer"),R=A((n,s,c)=>{n.length===0?w(c,["r",s]):w(c,["s",n,s])},"emitSet"),M=A((n,s)=>{if(n===s)return!0;if(!I(n)||!I(s)||Array.isArray(n)!==Array.isArray(s))return!1;if(Array.isArray(n)){const i=s;if(n.length!==i.length)return!1;for(let e=0;e<n.length;e++)if(!M(n[e],i[e]))return!1;return!0}const c=s,l=Object.keys(n);if(l.length!==Object.keys(c).length)return!1;for(const i of l)if(!Object.hasOwn(c,i)||!M(n[i],c[i]))return!1;return!0},"equalJson"),F=A((n,s)=>{if(n.length!==s.length)return;const c=new Map;for(let i=0;i<n.length;i++){const e=n[i],u=c.get(e);u===void 0?c.set(e,{indices:[i],used:0}):u.indices.push(i)}const l=new Array(s.length);for(let i=0;i<s.length;i++){const e=c.get(s[i]);if(e===void 0||e.used===e.indices.length)return;l[i]=e.indices[e.used++]}return l},"permutation"),G=A((n,s,c,l)=>{if(n===s)return;if(s.length>n.length&&s.slice(0,n.length)===n){w(l,["a",c,s.slice(n.length)]);return}const i=q(n,s,K);if(i===0){w(l,["s",c,s]);return}w(l,["t",c,n.length-i]),s.length>i&&w(l,["a",c,s.slice(i)])},"emitString"),J=2e5,W=65536,j=A((n,s)=>n===s||M(n,s),"sameValue"),Y=A((n,s,c,l)=>{if(n.length===0||s.length===0)return[];if(n.length*s.length>l)return;const i=s.length+1,e=new Uint32Array((n.length+1)*i);for(let t=n.length-1;t>=0;t--)for(let d=s.length-1;d>=0;d--){const m=t*i+d;e[m]=c(n[t],s[d])?e[(t+1)*i+d+1]+1:Math.max(e[(t+1)*i+d],e[t*i+d+1])}const u=[];let h=0,g=0;for(;h<n.length&&g<s.length;)c(n[h],s[g])&&e[h*i+g]===e[(h+1)*i+g+1]+1?u.push([h++,g++]):e[(h+1)*i+g]>=e[h*i+g+1]?h+=1:g+=1;return u},"lcsMatches"),z=A((n,s)=>{if(j(n,s))return!0;if(!I(n)||!I(s)||Array.isArray(n)!==Array.isArray(s))return!1;if(Array.isArray(n)&&Array.isArray(s))return n.length!==s.length?!1:n.some((i,e)=>I(i)&&i===s[e]);const c=n,l=s;for(const i of Object.keys(c)){const e=c[i];if(I(e)&&Object.hasOwn(l,i)&&e===l[i])return!0}return!1},"semanticallyAligned"),V=A((n,s)=>{let c=0,l=n.length;for(;c<l;){const i=c+l>>>1;n[i]<s?c=i+1:l=i}return c},"lowerBound"),H=A((n,s,c,l,i,e)=>{const u=c-s,h=e-i,g=[];if(h<u){let t=s;for(let d=i;d<e;d++){for(;t<c&&n[t]!==l[d];)t+=1;if(t===c)return;g.push([t++,d])}return g}if(u<h){let t=i;for(let d=s;d<c;d++){for(;t<e&&n[d]!==l[t];)t+=1;if(t===e)return;g.push([d,t++])}return g}},"identitySubsequence"),Q=A((n,s,c,l)=>{const i=[];let e=-1;for(let u=c;u<l;u++){const h=n.get(s[u]);if(h===void 0)continue;const g=V(h,e+1),t=h[g];t!==void 0&&(i.push([t,u]),e=t)}return i},"greedyIdentityAnchors"),Z=A((n,s,c,l,i,e)=>{const u=new Map;for(let y=s;y<c;y++){const o=n[y],r=u.get(o);r===void 0?u.set(o,[y]):r.push(y)}let h=0;for(let y=i;y<e;y++)if(h+=u.get(l[y])?.length??0,h>J)return Q(u,l,i,e);if(h===0)return[];const g=[],t=[],d=[];for(let y=i;y<e;y++){const o=u.get(l[y]);if(o!==void 0)for(let r=o.length-1;r>=0;r--){const k=o[r],T=V(d,k),P=g.length;g.push({before:k,after:y,previous:T===0?-1:t[T-1]}),t[T]=P,d[T]=k}}const m=[];let x=t[t.length-1]??-1;for(;x>=0;){const y=g[x];m.push([y.before,y.after]),x=y.previous}return m.reverse(),m},"identityAnchors"),D=A((n,s,c,l,i,e,u,h,g,t)=>{let d=i,m=u,x=g;for(const[y,o]of t){if(O.has(l))return;L(n,s,c,l,d,y,m,o,x),x+=o-m,j(n[y],s[o])||N(n[y],s[o],[...c,x],l),x+=1,d=y+1,m=o+1}O.has(l)||L(n,s,c,l,d,e,m,h,x)},"processArrayMatches");function L(n,s,c,l,i,e,u,h,g){if(O.has(l))return;for(;i<e&&u<h&&j(n[i],s[u]);)i+=1,u+=1,g+=1;for(;i<e&&u<h&&j(n[e-1],s[h-1]);)e-=1,h-=1;const t=e-i,d=h-u;if(t===0&&d===0)return;if(t===0||d===0){w(l,["p",c,g,t,s.slice(u,h)]);return}if(t===d){const o=[];for(let r=0;r<t;r++)j(n[i+r],s[u+r])&&o.push([i+r,u+r]);if(o.length>0){D(n,s,c,l,i,e,u,h,g,o);return}}const m=H(n,i,e,s,u,h);if(m!==void 0&&m.length>0){D(n,s,c,l,i,e,u,h,g,m);return}const x=Z(n,i,e,s,u,h);if(x.length>0){D(n,s,c,l,i,e,u,h,g,x);return}const y=Y(n.slice(i,e),s.slice(u,h),z,W);if(y!==void 0&&y.length>0){const o=y.map(([r,k])=>[i+r,u+k]);D(n,s,c,l,i,e,u,h,g,o);return}if(t===1&&d===1){N(n[i],s[u],[...c,g],l);return}w(l,["p",c,g,t,s.slice(u,h)])}A(L,"diffArrayRegion");const $=A((n,s,c,l)=>{if(!(n===s||M(n,s))){if(n.length===s.length&&n.length>1&&!j(n[0],s[0])&&!j(n[n.length-1],s[s.length-1])){const i=F(n,s);if(i!==void 0){w(l,["m",c,i]);return}}L(n,s,c,l,0,n.length,0,s.length,0)}},"diffArray"),v=A((n,s,c,l)=>{const i=Object.keys(n),e=Object.keys(s);if([...i,...e].some(u=>B.has(u))){M(n,s)||R(c,s,l);return}for(const u of e){if(O.has(l))return;Object.hasOwn(n,u)?N(n[u],s[u],[...c,u],l):R([...c,u],s[u],l)}for(const u of i){if(O.has(l))return;Object.hasOwn(s,u)||w(l,["d",[...c,u]])}},"diffObject"),N=A((n,s,c,l)=>{if(!(n===s||O.has(l))){if(typeof n=="string"&&typeof s=="string"&&c.length>0){G(n,s,c,l);return}if(Array.isArray(n)&&Array.isArray(s)){$(n,s,c,l);return}if(I(n)&&I(s)&&!Array.isArray(n)&&!Array.isArray(s)){v(n,s,c,l);return}R(c,s,l)}},"diffValue"),C=A(n=>{if(n===null)return 4;if(typeof n=="string")return n.length+2;if(typeof n=="number")return String(n).length;if(typeof n=="boolean")return n?4:5;if(Array.isArray(n)){let l=2;for(let i=0;i<n.length;i++)l+=C(n[i])+(i===0?0:1);return l}let s=2,c=0;for(const l of Object.keys(n))s+=l.length+3+C(n[l])+(c++===0?0:1);return s},"jsonCost"),_=A(n=>{let s=2;for(let c=0;c<n.length;c++){const l=n[c];s+=(typeof l=="string"?l.length+2:String(l).length)+(c===0?0:1)}return s},"pathCost"),f=A(n=>{switch(n[0]){case"r":return 6+C(n[1]);case"s":return 7+_(n[1])+C(n[2]);case"d":return 6+_(n[1]);case"a":return 7+_(n[1])+n[2].length+2;case"t":return 7+_(n[1])+String(n[2]).length;case"p":return 10+_(n[1])+String(n[2]).length+String(n[3]).length+C(n[4]);case"m":return 7+_(n[1])+C(n[2])}},"operationCost");function p(n,s){const c=[];if(N(n,s,[],c),O.has(c))return[["r",s]];if(c.length===0||c[0]?.[0]==="r")return c;let l=2;for(const e of c)l+=f(e)+1;if(l<65536)return c;const i=C(s)+6;return l>=i?[["r",s]]:c}A(p,"diffRevisions");export{p as diffRevisions};
@@ -1 +0,0 @@
1
- var k=Object.defineProperty;var c=(e,n)=>k(e,"name",{value:n,configurable:!0});const g=c(e=>e!==null&&typeof e=="object","isObj"),v=c(e=>e[0]==="r","isReplace"),_=c(e=>e.length>0&&e[0][0]==="r","isBase");function R(e,n,i,o=64,r=8){if(e.length===0||n.length===0||i===0)return 0;const s=e.length>i?e.slice(e.length-i):e;for(const t of[Math.min(o,n.length),1]){const f=n.slice(0,t);let h=0;for(let a=s.indexOf(f);a!==-1&&!(++h>r);a=s.indexOf(f,a+1)){const w=s.length-a;if(w<=n.length&&s.slice(a)===n.slice(0,w))return w}if(t===1)break}return 0}c(R,"overlap");import{diffRevisions as J}from"./diff.js";import{track as z}from"./tracker.js";const A=new Set(["__proto__","constructor","prototype"]);class y extends Error{static{c(this,"UnsafePathError")}segment;constructor(n){super(`unsafe path segment: ${String(n)}`),this.segment=n,this.name="UnsafePathError"}}function m(e){if(!Array.isArray(e)||e.length===0)throw new TypeError("op is not a tuple");switch(e[0]){case"r":if(e.length!==2)throw new TypeError("r arity");return;case"s":if(e.length!==3)throw new TypeError("s arity");p(e[1],!0);return;case"d":if(e.length!==2)throw new TypeError("d arity");p(e[1],!0);return;case"a":if(e.length!==3||typeof e[2]!="string")throw new TypeError("a shape");p(e[1],!0);return;case"t":if(e.length!==3||!Number.isInteger(e[2])||e[2]<0)throw new TypeError("t shape");p(e[1],!0);return;case"p":{if(e.length!==5)throw new TypeError("p arity");if(p(e[1]),!Number.isInteger(e[2])||e[2]<0)throw new TypeError("p index");if(!Number.isInteger(e[3])||e[3]<0)throw new TypeError("p remove");if(!Array.isArray(e[4]))throw new TypeError("p items");return}case"m":if(e.length!==3)throw new TypeError("m arity");p(e[1]),E(e[2]);return;default:throw new TypeError(`unknown op verb: ${String(e[0])}`)}}c(m,"assertValidOp");function p(e,n=!1){if(!Array.isArray(e))throw new TypeError("path is not an array");if(n&&e.length===0)throw new TypeError("path is empty");d(e)}c(p,"assertPathArg");function E(e){if(!Array.isArray(e))throw new TypeError("m permutation is not an array");const n=new Uint8Array(e.length);for(const i of e){if(!Number.isInteger(i)||i<0||i>=e.length||n[i]!==0)throw new TypeError("m permutation is not a bijection");n[i]=1}}c(E,"assertPermutation");function x(e){if(!Array.isArray(e)||e.length===0)throw new TypeError("op is not a tuple");const[n]=e,i=c(o=>{if(typeof o=="number"){if(!Number.isInteger(o)||o<0)throw new TypeError("bad path id");return}if(!Array.isArray(o))throw new TypeError("path is not an array");d(o)},"okRef");switch(n){case"r":if(e.length!==2)throw new TypeError("r arity");return;case"s":if(e.length===3)i(e[1]);else if(e.length!==2)throw new TypeError("s arity");return;case"d":if(e.length===2)i(e[1]);else if(e.length!==1)throw new TypeError("d arity");return;case"a":if(e.length===3){if(i(e[1]),typeof e[2]!="string")throw new TypeError("a value")}else if(e.length===2){if(typeof e[1]!="string")throw new TypeError("a value")}else throw new TypeError("a arity");return;case"t":if(e.length===3){if(i(e[1]),!Number.isInteger(e[2])||e[2]<0)throw new TypeError("t count")}else if(e.length===2){if(!Number.isInteger(e[1])||e[1]<0)throw new TypeError("t count")}else throw new TypeError("t arity");return;case"p":{const[o,r,s]=e.length===5?[e[2],e[3],e[4]]:e.length===4?[e[1],e[2],e[3]]:[];if(s===void 0)throw new TypeError("p arity");if(e.length===5&&i(e[1]),!Number.isInteger(o)||o<0)throw new TypeError("p index");if(!Number.isInteger(r)||r<0)throw new TypeError("p remove");if(!Array.isArray(s))throw new TypeError("p items");return}case"m":if(e.length===3)i(e[1]);else if(e.length!==2)throw new TypeError("m arity");E(e[e.length-1]);return;case"#":{if(e.length!==3||!Number.isInteger(e[1])||e[1]<0||!Array.isArray(e[2]))throw new TypeError("# shape");d(e[2]);return}default:throw new TypeError(`unknown op verb: ${String(n)}`)}}c(x,"assertValidWireOp");function d(e){for(const n of e)if(typeof n=="string"){if(A.has(n))throw new y(n)}else if(!Number.isInteger(n)||n<0)throw new y(n)}c(d,"assertSafePath");function O(e,n){if(n>e.length)throw new y(n)}c(O,"assertIndexInRange");class u extends Error{static{c(this,"PathError")}path;constructor(n){super(`unresolvable path: ${JSON.stringify(n)}`),this.path=n,this.name="PathError"}}function $(e,n){return T(e,n)}c($,"apply");function T(e,n){let i=e;for(const o of n){if(m(o),o[0]==="r"){i=o[1];continue}const r=o[1];if(d(r),o[0]==="p"){const a=r.length===0?i:b(i,r);if(!Array.isArray(a))throw new u(r);a.splice(o[2],o[3]);const w=1e3;for(let l=0;l<o[4].length;l+=w)a.splice(o[2]+l,0,...o[4].slice(l,l+w));continue}if(o[0]==="m"){const a=r.length===0?i:b(i,r);if(!Array.isArray(a)||a.length!==o[2].length)throw new u(r);const w=a.slice();for(let l=0;l<o[2].length;l++)a[l]=w[o[2][l]];continue}const s=b(i,r.slice(0,-1)),t=r[r.length-1];if(Array.isArray(s)){if(typeof t!="number")throw new y(t);O(s,t)}const f=c(a=>{Object.defineProperty(s,t,{value:a,writable:!0,enumerable:!0,configurable:!0})},"write"),h=c(()=>Object.hasOwn(s,t)?s[t]:void 0,"read");switch(o[0]){case"s":f(o[2]);break;case"d":if(Array.isArray(s)){if(typeof t!="number"||t>=s.length)throw new u(r);s.splice(t,1)}else delete s[t];break;case"a":{const a=h();if(typeof a!="string")throw new u(r);f(`${a}${o[2]}`);break}case"t":{const a=h();if(typeof a!="string")throw new u(r);f(a.slice(o[2]));break}}}return i}c(T,"applyOps");function M(e,n){return I(e,[n])}c(M,"applyImmutable");function I(e,n){let i=e;const o=new WeakSet;for(const r of n)for(const s of r){if(m(s),s[0]==="r"){i=s[1];continue}i=N(i,s[0]==="p"||s[0]==="m"?s[1]:s[1].slice(0,-1),o),i=T(i,[s])}return i}c(I,"applyImmutableBatches");function N(e,n,i){const o=c(t=>{if(Array.isArray(t))return t.slice();if(!g(t))throw new u(n);const f=Object.create(Object.getPrototypeOf(t)===null?null:Object.prototype);for(const h of Object.keys(t))Object.defineProperty(f,h,{value:t[h],writable:!0,enumerable:!0,configurable:!0});return f},"copy");if(!g(e))throw new u(n);let r;i.has(e)?r=e:(r=o(e),i.add(r));let s=r;for(const t of n){if(!Object.hasOwn(s,t))throw new u(n);if(Array.isArray(s)&&typeof t!="number")throw new y(t);const f=s[t];if(!g(f))throw new u(n);if(i.has(f)){s=f;continue}const h=o(f);Object.defineProperty(s,t,{value:h,writable:!0,enumerable:!0,configurable:!0}),i.add(h),s=h}return r}c(N,"copyContainers");function j(e,n){let i=e;for(const o of n){if(!g(i))throw new u(n);if(Array.isArray(i)&&typeof o!="number")throw new y(o);if(!Object.hasOwn(i,o))throw new u(n);i=i[o]}return i}c(j,"resolveValue");function b(e,n){const i=j(e,n);if(!g(i))throw new u(n);return i}c(b,"resolve");const S=c(e=>JSON.stringify(e),"pathKey");function V(){const e=new Set,n=new Map;let i=0,o;return{encode(r){o=void 0;const s=[];for(const t of r){if(t[0]==="r"){s.push(t),e.clear(),n.clear(),i=0,o=void 0;continue}const f=t[1],h=S(f);if(h===o){switch(t[0]){case"s":s.push(["s",t[2]]);break;case"d":s.push(["d"]);break;case"a":s.push(["a",t[2]]);break;case"t":s.push(["t",t[2]]);break;case"p":s.push(["p",t[2],t[3],t[4]]);break;case"m":s.push(["m",t[2]]);break}continue}let a=f;const w=n.get(h);if(w!==void 0)a=w;else if(e.has(h)){const l=i++;n.set(h,l),s.push(["#",l,f]),a=l}else e.add(h);switch(t[0]){case"s":s.push(["s",a,t[2]]);break;case"d":s.push(["d",a]);break;case"a":s.push(["a",a,t[2]]);break;case"t":s.push(["t",a,t[2]]);break;case"p":s.push(["p",a,t[2],t[3],t[4]]);break;case"m":s.push(["m",a,t[2]]);break}o=h}return s}}}c(V,"encoder");function U(){const e=new Map;return{decode(n){let i;const o=[];for(const r of n){if(x(r),r[0]==="#"){d(r[2]),e.set(r[1],r[2]);continue}if(r[0]==="r"){o.push(r),e.clear(),i=void 0;continue}const s=r[0]==="d"&&r.length===1||r[0]!=="d"&&r[0]!=="p"&&r.length===2||r[0]==="p"&&r.length===4;let t;if(s){if(i===void 0)throw new u([]);t=i}else{const f=r[1];if(typeof f=="number"){const h=e.get(f);if(h===void 0)throw new u(f);t=h}else t=f;i=t}if(r[0]!=="p"&&r[0]!=="m"&&t.length===0)throw new u(t);switch(r[0]){case"s":o.push(["s",t,s?r[1]:r[2]]);break;case"d":o.push(["d",t]);break;case"a":o.push(["a",t,s?r[1]:r[2]]);break;case"t":o.push(["t",t,s?r[1]:r[2]]);break;case"p":{const[f,h,a]=s?[r[1],r[2],r[3]]:[r[2],r[3],r[4]];o.push(["p",t,f,h,a]);break}case"m":o.push(["m",t,s?r[1]:r[2]]);break}}return o}}}c(U,"decoder");export{u as PathError,A as RESERVED_SEGMENTS,y as UnsafePathError,$ as apply,M as applyImmutable,I as applyImmutableBatches,d as assertSafePath,m as assertValidOp,x as assertValidWireOp,U as decoder,J as diffRevisions,V as encoder,_ as isBase,v as isReplace,R as overlap,z as track};
@@ -1 +0,0 @@
1
- var a=Object.defineProperty;var i=(t,e)=>a(t,"name",{value:e,configurable:!0});const p=i(t=>typeof t=="object"&&t!==null,"isContainer");class w{static{i(this,"JsonRevisionValidator")}#t=new WeakSet;validate(e){return this.#e(e,new Set,new WeakSet)}#e(e,r,n){if(!p(e)||this.#t.has(e))return p(e)?e:c(e);if(n.has(e))return e;if(r.has(e))throw new TypeError("Replicated state cannot contain cycles");r.add(e);try{if(Array.isArray(e)){y(e);for(let o=0;o<e.length;o++)this.#e(e[o],r,n)}else{d(e);for(const o of Reflect.ownKeys(e)){if(typeof o=="symbol")throw new TypeError("Replicated state cannot contain symbol properties");const s=Object.getOwnPropertyDescriptor(e,o);if(s===void 0||!s.enumerable||!("value"in s))throw new TypeError("Replicated state objects must contain enumerable data properties");this.#e(s.value,r,n)}}return n.add(e),this.#t.add(e),e}finally{r.delete(e)}}}function c(t){if(t===null||typeof t=="string"||typeof t=="boolean"||typeof t=="number"&&Number.isFinite(t))return t;throw new TypeError("Replicated state values must be strict JSON")}i(c,"assertPrimitive");function d(t){const e=Object.getPrototypeOf(t);if(e!==Object.prototype&&e!==null)throw new TypeError("Replicated state containers must be plain objects or arrays")}i(d,"assertPlainObject");function y(t){const e=Reflect.ownKeys(t);if(e.length!==t.length+1||e.some(r=>typeof r!="string"))throw new TypeError("Replicated state arrays must be dense and contain only indexed entries");for(let r=0;r<t.length;r++){const n=Object.getOwnPropertyDescriptor(t,String(r));if(n===void 0||!n.enumerable||!("value"in n)||n.value===void 0)throw new TypeError("Replicated state arrays must contain enumerable indexed data properties with defined values")}}i(y,"assertDenseArray");export{w as JsonRevisionValidator};
@@ -1 +0,0 @@
1
- var Ze=Object.defineProperty;var f=(e,t)=>Ze(e,"name",{value:t,configurable:!0});import{copyJson as ce}from"../json.js";import{applyImmutableTrusted as $e}from"./apply-immutable-trusted.js";import{applyImmutable as et,overlap as tt,RESERVED_SEGMENTS as T}from"./index.js";const D=Symbol("chord.delta.overlay.node"),me=new WeakMap,ie={},nt=new Set(["push","pop","shift","unshift","splice","reverse","sort","fill","copyWithin"]),K=4096,rt=128,de={value:void 0,writable:!0,enumerable:!0,configurable:!0};class st{static{f(this,"PreparedImpl")}#e;value;base;ops;constructor(t,n,r){this.#e=t,this.value=n,this.base=t.baseValue,this.ops=r,me.set(this,t)}get baseRevision(){return this.#e.baseRevision}abort(){qe(this.#e)}}class it{static{f(this,"ChangeImpl")}#e;#t;#n=!1;constructor(t){this.#e=t}get state(){const t=this.#e?.root?.proxy;if(t===void 0)throw new TypeError("Cannot use a settled overlay");return t}prepare(){if(this.#n)throw new Error("Change has already been settled");const t=this.#e;L(t),t.status.value="prepared";try{t.replacement||(t.ops=t.dirty.length===0?[]:_e(t));const n=Oe(t);return this.#t=t.status,this.#n=!0,n}catch(n){throw t.status.value="aborted",re(t),this.#n=!0,n}finally{this.#e=void 0}}abort(){if(this.#n){this.#t?.value==="prepared"&&(this.#t.value="aborted"),this.#t=void 0;return}this.#n=!0,qe(this.#e),this.#e=void 0}}class ut{static{f(this,"TrackerImpl")}#e={};#t=new Set;#n;#r;#s=0;#i=256;constructor(t){this.#r=t,this.#n=new WeakRef(this)}get value(){return this.#r}get revision(){return this.#s}beginChange(){const t=xe(this.#n,this.#e,this.#s,this.#r,!1,this.#r);return this.#u(t),new it(t)}prepareReplace(t){const n=xe(this.#n,this.#e,this.#s,t,!0,this.#r);n.status.value="prepared",this.#u(n);try{return Oe(n)}catch(r){throw n.status.value="aborted",re(n),r}}adopt(t){const n=me.get(t);if(n?.owner!==this.#e)throw new Error("Prepared change belongs to a different tracker");if(n.status.value==="consumed")throw new Error("Prepared change has already been used");if(n.status.value==="aborted")throw new Error("Prepared change has been aborted");if(n.status.value==="stale")throw new Error("Prepared change is stale");if(n.status.value!=="prepared")throw new Error("Prepared change is not ready");if(n.baseRevision!==this.#s)throw n.status.value="stale",re(n),new Error("Prepared change is stale");if(this.#r!==t.base)throw n.status.value="stale",new Error("Prepared change is stale");this.#r=t.value,n.status.value="consumed",this.#s+=1,this.#a(n)}releaseContext(t){t.registryRef!==void 0&&this.#t.delete(t.registryRef),t.registryRef=void 0}#u(t){const n=new WeakRef(t);t.registryRef=n,this.#t.add(n),this.#i-=1,this.#i===0&&(this.#f(),this.#i=Math.max(256,this.#t.size))}#f(){for(const t of this.#t)t.deref()===void 0&&this.#t.delete(t)}#a(t){for(const n of this.#t){const r=n.deref();r===void 0||r===t||((r.status.value==="open"||r.status.value==="prepared")&&(r.status.value="stale"),Qe(r))}this.#t.clear(),this.#i=256}replacementBase(t){return t.baseRevision===this.#s?this.#r:void 0}}function Jt(e){return new ut(e)}f(Jt,"track");function Oe(e){const t=zt(e),n=e.baseValue,r=t.length===0?n:e.simpleObjectMaterialization?ne(e.root):ft(n,t),s=new st(e,r,t);return e.nodes.length>4096?Qe(e):re(e),s}f(Oe,"materializePrepared");function ft(e,t){for(const n of t)if(n[0]==="p"||n[0]==="m")return et(e,t);return $e(e,t)}f(ft,"materializeOperations");function xe(e,t,n,r,s,u){const i={owner:t,tracker:e,baseRevision:n,status:{value:"open"},root:void 0,bases:[],stored:[],dirty:[],nodes:[],rawNodes:new WeakMap,ops:void 0,replacement:s,replacementNoop:!1,baseValue:u,overlayReleased:!1,simpleObjectMaterialization:!1,registryRef:void 0};return i.root=ue(i,r,void 0),i}f(xe,"createContext");const ve={deleteProperty(e,t){return Re(A(e),t)},defineProperty(e){throw L(A(e).context),new TypeError("Defining overlay properties is not supported")},get(e,t){if(t==="then"){const r=e[D];if(r===void 0||Ae(r.context))return}const n=A(e);return t===D?n:Pe(n,t)},getOwnPropertyDescriptor(e,t){return dt(A(e),t)},getPrototypeOf(e){const t=A(e);return S(t.context),Object.getPrototypeOf(h(t))},has(e,t){return ct(A(e),t)},isExtensible(e){return S(A(e).context),!0},ownKeys(e){return le(A(e))},preventExtensions(e){throw L(A(e).context),new TypeError("Overlays cannot be made non-extensible")},set(e,t,n){return ot(A(e),t,n)},setPrototypeOf(e){throw L(A(e).context),new TypeError("Changing an overlay prototype is not supported")}},at=ve;function ue(e,t,n,r=0,s="",u=void 0,i=!1){const a=e.rawNodes.get(t);if(a!==void 0)return a;const o=Array.isArray(t)?[]:{},l=e.bases.length,d=n?.baseIndex??-1;e.bases.push(t);const c={context:e,baseIndex:l,parentIndex:d,parentKind:r,parentKey:s,parentPlacement:i,target:o,proxy:o};return u!==void 0&&(c.parentSource=u),o[D]=c,c.proxy=new Proxy(o,Array.isArray(t)?at:ve),e.rawNodes.set(t,c),e.nodes.push(c),c}f(ue,"createNode");function h(e){return e.context.bases[e.baseIndex]}f(h,"nodeBase");function O(e){return e.parentIndex<0?void 0:e.context.nodes[e.parentIndex]}f(O,"nodeParent");function k(e,t){if(!w(t))return t;const n=e.stored.length;return e.stored.push(t),{index:n}}f(k,"storeValue");function v(e,t){return typeof t=="object"&&t!==null?e.stored[t.index]:t}f(v,"storedValue");function z(e,t,n){return w(n)?typeof t=="object"&&t!==null?(e.stored[t.index]=n,t):k(e,n):(typeof t=="object"&&t!==null&&(e.stored[t.index]=ie),n)}f(z,"replaceStoredValue");function W(e,t){typeof t=="object"&&t!==null&&(e.stored[t.index]=ie)}f(W,"releaseStoredValue");function A(e){const t=e[D];if(t===void 0)throw new TypeError("Cannot use a settled overlay");return t}f(A,"nodeForTarget");function Ae(e){return e.overlayReleased||e.status.value==="consumed"||e.status.value==="aborted"||e.status.value==="stale"}f(Ae,"isSettledContext");function S(e){if(Ae(e))throw new TypeError("Cannot use a settled overlay")}f(S,"assertReadable");function L(e){if(S(e),e.status.value!=="open")throw new TypeError("Prepared overlays are read-only")}f(L,"assertWritable");function Pe(e,t){if(S(e.context),Array.isArray(h(e))){const s=g(e);if(t==="length")return m(s);if(nt.has(t))return At[t];const u=$(t);return u!==void 0?Y(e,u):Reflect.get(Array.prototype,t,e.proxy)}if(typeof t=="symbol")return Reflect.get(h(e),t,e.proxy);const n=String(t);if(!q(e,n))return fe(e,n)||Object.hasOwn(h(e),n)?void 0:Reflect.get(h(e),t,e.proxy);const r=F(e,n);return w(r)?ue(e.context,r,e,0,n,void 0,ke(e,n)).proxy:r}f(Pe,"getProperty");function Y(e,t){const n=g(e);if(t>=m(n))return;const r=Z(n,t),s=r.start+r.step*n.locatedOffset,u=j(e,r,s);return w(u)?ue(e.context,u,e,r.kind==="base"?1:2,s,r.kind==="insert"?r.source:void 0,r.kind==="insert"||mt(n,r,s)).proxy:u}f(Y,"getArrayIndex");function ot(e,t,n){if(L(e.context),typeof t=="symbol")throw new TypeError("Symbol writes are not supported");if(Array.isArray(h(e))){if(t==="length")return Te(e,vt(n)),!0;const a=$(t);if(a===void 0)throw new TypeError("Only array indices and length can be written");if(a>m(g(e)))throw new TypeError("Overlay arrays cannot contain holes");return xt(e,a,te(n)),!0}const r=String(t);if(n===void 0)return Re(e,r);const s=te(n),u=F(e,r),i=fe(e,r);return!i&&!w(s)&&u===s||(lt(e,r,s),i&&Object.hasOwn(h(e),r)&&(e.readded===void 0&&(e.readded=new Set),e.readded.add(r)),gt(e,r),V(e)),!0}f(ot,"setProperty");function Re(e,t){if(L(e.context),typeof t=="symbol")throw new TypeError("Symbol writes are not supported");if(Array.isArray(h(e)))throw new TypeError("Overlay arrays cannot contain holes");const n=String(t);return q(e,n)&&(ht(e,n),e.readded?.delete(n),pt(e,n),V(e)),!0}f(Re,"deleteProperty");function ct(e,t){if(S(e.context),Array.isArray(h(e))){if(t==="length")return!0;const n=$(t);return n!==void 0?n<m(g(e)):t in Array.prototype}return typeof t=="symbol"?t in h(e):q(e,String(t))}f(ct,"hasProperty");function le(e){if(S(e.context),Array.isArray(h(e))){const i=m(g(e)),a=new Array(i+1);for(let o=0;o<i;o++)a[o]=String(o);return a[i]="length",a}let t=e.deleteKey===void 0&&e.deletes===void 0&&e.readded===void 0&&(e.writeKey===void 0||Object.hasOwn(h(e),e.writeKey));if(t&&e.writes!==void 0){for(const i of e.writes.keys())if(!Object.hasOwn(h(e),i)){t=!1;break}}if(t)return Object.keys(h(e));const n=Object.keys(h(e)).filter(i=>!fe(e,i)&&!e.readded?.has(i)),r=new Set(n);if(e.writeKey!==void 0&&!r.has(e.writeKey)&&(n.push(e.writeKey),r.add(e.writeKey)),e.writes!==void 0)for(const i of e.writes.keys())r.has(i)||(n.push(i),r.add(i));const s=[],u=[];for(const i of n){const a=$(i);a===void 0?u.push(i):s.push(a)}return s.sort((i,a)=>i-a),[...s.map(String),...u]}f(le,"ownKeys");function dt(e,t){if(S(e.context),Array.isArray(h(e))){if(t==="length"){const r=m(g(e));return e.target.length=r,Reflect.getOwnPropertyDescriptor(e.target,"length")}const n=$(t);if(n===void 0||n>=m(g(e)))return}else if(typeof t=="symbol"||!q(e,String(t)))return;return{configurable:!0,enumerable:!0,writable:e.context.status.value==="open",value:Pe(e,t)}}f(dt,"getDescriptor");function ke(e,t){return e.writeKey===t||(e.writes?.has(t)??!1)}f(ke,"hasObjectWrite");function lt(e,t,n){if(e.writes!==void 0){const r=e.writes.get(t);e.writes.set(t,r===void 0?k(e.context,n):z(e.context,r,n));return}if(e.writeKey===void 0||e.writeKey===t){e.writeKey=t,e.writeValue=e.writeValue===void 0?k(e.context,n):z(e.context,e.writeValue,n);return}e.writes=new Map,e.writes.set(e.writeKey,e.writeValue),e.writes.set(t,k(e.context,n)),e.writeKey=void 0,e.writeValue=void 0}f(lt,"setObjectWrite");function ht(e,t){if(e.writeKey===t)e.writeKey=void 0,W(e.context,e.writeValue),e.writeValue=void 0;else{const n=e.writes?.get(t);n!==void 0&&W(e.context,n),e.writes?.delete(t)}}f(ht,"deleteObjectWrite");function fe(e,t){return e.deleteKey===t||(e.deletes?.has(t)??!1)}f(fe,"isObjectDeleted");function pt(e,t){if(e.deletes!==void 0){e.deletes.add(t);return}if(e.deleteKey===void 0||e.deleteKey===t){e.deleteKey=t;return}e.deletes=new Set,e.deletes.add(e.deleteKey),e.deletes.add(t),e.deleteKey=void 0}f(pt,"setObjectDeletion");function gt(e,t){e.deleteKey===t?e.deleteKey=void 0:e.deletes?.delete(t)}f(gt,"deleteObjectDeletion");function q(e,t){return fe(e,t)?!1:ke(e,t)||Object.hasOwn(h(e),t)}f(q,"objectHas");function F(e,t){if(e.writeKey===t)return v(e.context,e.writeValue);const n=e.writes?.get(t);return n!==void 0?v(e.context,n):h(e)[t]}f(F,"objectValue");function V(e){if(!e.dirty){e.dirty=!0,e.context.dirty.push(e);for(let t=O(e);t!==void 0;t=O(t))t.subtreeDirty=!0}}f(V,"markDirty");function g(e){if(e.array!==void 0)return e.array;const t=h(e),n={root:void 0,pieces:void 0,baseOverrides:void 0,insertOverrides:void 0,structural:!1,generation:0,plan:void 0,seed:2654435769,locatedOffset:0,baseLocations:void 0,insertLocations:void 0};return t.length>0&&(n.root=Q(n,{kind:"base",start:0,length:t.length,step:1})),e.array=n,n}f(g,"arrayOverlay");function Se(e){return e.baseOverrides===void 0&&(e.baseOverrides=new Map),e.baseOverrides}f(Se,"baseOverridesForWrite");function Ie(e){return e.insertOverrides===void 0&&(e.insertOverrides=new Map),e.insertOverrides}f(Ie,"insertOverridesForWrite");function yt(e){let t=e.seed;return t^=t<<13,t^=t>>>17,t^=t<<5,e.seed=t>>>0,e.seed}f(yt,"nextPiecePriority");function B(e){return e?.elements??0}f(B,"treeElements");function C(e){e.elements=B(e.left)+e.piece.length+B(e.right)}f(C,"updatePieceNode");function Q(e,t){return{piece:t,left:void 0,right:void 0,priority:yt(e),elements:t.length}}f(Q,"createPieceNode");function H(e,t){return e===void 0?t:t===void 0?e:e.priority>=t.priority?(e.right=H(e.right,t),C(e),e):(t.left=H(e,t.left),C(t),t)}f(H,"mergePieceTrees");function J(e,t,n){if(t===void 0)return[void 0,void 0];const r=B(t.left);if(n<r){const[o,l]=J(e,t.left,n);return t.left=l,C(t),[o,t]}const s=r+t.piece.length;if(n>s){const[o,l]=J(e,t.right,n-s);return t.right=o,C(t),[t,l]}if(n===r){const o=t.left;return t.left=void 0,C(t),[o,t]}if(n===s){const o=t.right;return t.right=void 0,C(t),[t,o]}const u=n-r,i={...t.piece,length:u},a={...t.piece,start:t.piece.start+t.piece.step*u,length:t.piece.length-u};return[H(t.left,Q(e,i)),H(Q(e,a),t.right)]}f(J,"splitPieceTree");function bt(e){for(;e.left!==void 0;)e=e.left;return e}f(bt,"leftmostPieceNode");function Ee(e){for(;e.right!==void 0;)e=e.right;return e}f(Ee,"rightmostPieceNode");function wt(e,t){return e.kind!==t.kind||e.kind==="insert"&&e.source!==t.source?!1:e.length===1&&t.length===1?Math.abs(t.start-e.start)===1:e.step===t.step&&e.start+e.step*e.length===t.start}f(wt,"mergeablePieces");function ae(e,t,n){if(t===void 0)return n;if(n===void 0)return t;const r=Ee(t).piece,s=bt(n).piece;if(!wt(r,s))return H(t,n);const[u]=J(e,t,B(t)-r.length),[,i]=J(e,n,s.length),a=r.length===1?s.start-r.start:r.step,o=r.kind==="base"?{kind:"base",start:r.start,length:r.length+s.length,step:a}:{kind:"insert",source:r.source,start:r.start,length:r.length+s.length,step:a};return ae(e,ae(e,u,Q(e,o)),i)}f(ae,"joinNormalized");function he(e,t){e!==void 0&&(he(e.left,t),t.push(e.piece),he(e.right,t))}f(he,"flattenPieceTree");function M(e){return e.pieces===void 0&&(e.pieces=[],he(e.root,e.pieces)),e.pieces}f(M,"piecesOf");function Ke(e,t){Ot(t);let n;for(const r of t)n=H(n,Q(e,r));return n}f(Ke,"treeFromPieces");function Me(e,t){e.root=Ke(e,t),e.pieces=void 0,e.baseLocations=void 0,e.insertLocations=void 0}f(Me,"replaceAllPieces");function m(e){return B(e.root)}f(m,"arrayLength");function Z(e,t){let n=e.root;for(;n!==void 0;){const r=B(n.left);if(t<r)n=n.left;else if(t>=r+n.piece.length)t-=r+n.piece.length,n=n.right;else return e.locatedOffset=t-r,n.piece}throw new RangeError("Array overlay index is out of range")}f(Z,"locatePiece");function $(e){if(typeof e!="string"||e.length===0||e.length>10)return;if(e==="0")return 0;const t=e.charCodeAt(0);if(t<49||t>57)return;let n=t-48;for(let r=1;r<e.length;r++){const s=e.charCodeAt(r)-48;if(s<0||s>9||(n=n*10+s,n>=4294967295))return}return n}f($,"arrayIndex");function j(e,t,n){const r=g(e);if(t.kind==="base"){const i=r.baseOverrides?.get(n);return i===void 0?h(e)[n]:v(e.context,i)}const s=r.insertOverrides?.get(t.source),u=s?.has(n)?s.get(n):t.source.refs[n];return v(e.context,u)}f(j,"entryValueAt");function mt(e,t,n){return t.kind==="base"?e.baseOverrides?.has(n)??!1:e.insertOverrides?.get(t.source)?.has(n)??!1}f(mt,"hasEntryOverrideAt");function je(e,t){e.right!==void 0?je(e.right,t):e.piece.length+=t,C(e)}f(je,"extendRightmostPiece");function Ne(e){e.pieces=void 0,e.baseLocations=void 0,e.insertLocations=void 0,e.plan=void 0}f(Ne,"invalidatePieceCaches");function P(e,t,n,r){if(n===0&&r.length===0)return;const s=g(e);if(n===0&&t===m(s)&&r.length===1&&s.root!==void 0){const l=r[0],d=Ee(s.root).piece;if(l.kind==="insert"&&d.kind==="insert"&&d.step===1&&d.start+d.length===d.source.refs.length){for(let c=0;c<l.length;c++)d.source.refs.push(l.source.refs[l.start+c]);je(s.root,l.length),Ne(s),s.structural=!0,s.generation+=1,V(e);return}}const[u,i]=J(s,s.root,t),[,a]=J(s,i,n),o=Ke(s,r);s.root=ae(s,ae(s,u,o),a),Ne(s),s.structural=!0,s.generation+=1,V(e)}f(P,"replacePieceRange");function Ot(e){for(let t=1;t<e.length;){const n=e[t-1],r=e[t],s=n.kind===r.kind&&(n.kind==="base"||n.source===r.source);s&&n.length===1&&r.length===1&&Math.abs(r.start-n.start)===1?(n.step=r.start-n.start,n.length=2,e.splice(t,1)):s&&n.step===r.step&&n.start+n.step*n.length===r.start?(n.length+=r.length,e.splice(t,1)):t+=1}}f(Ot,"mergePieces");function ee(e,t,n=0){if(t.length===n)return[];const r=[];for(let s=n;s<t.length;s++)r.push(k(e.context,t[s]));return[{kind:"insert",source:{refs:r},start:0,length:r.length,step:1}]}f(ee,"insertPiece");function pe(e,t,n=0){if(t.length===n)return[];const r=e.context.stored.length;try{for(let s=n;s<t.length;s++)t[s]=k(e.context,te(t[s]))}catch(s){throw e.context.stored.length=r,s}return[{kind:"insert",source:{refs:t},start:n,length:t.length-n,step:1}]}f(pe,"insertPlacementPiece");function xt(e,t,n){const r=g(e),s=m(r);if(t===s){P(e,s,0,ee(e,[n]));return}const u=Z(r,t),i=u.start+u.step*r.locatedOffset,a=j(e,u,i);if(!(!w(n)&&a===n)){if(u.kind==="base"){const o=r.baseOverrides?.get(i);!w(n)&&n===h(e)[i]?(o!==void 0&&W(e.context,o),r.baseOverrides?.delete(i)):o===void 0?Se(r).set(i,k(e.context,n)):r.baseOverrides.set(i,z(e.context,o,n))}else{let o=r.insertOverrides?.get(u.source);const l=o?.get(i);!w(n)&&n===v(e.context,u.source.refs[i])?(l!==void 0&&W(e.context,l),o?.delete(i),o?.size===0&&r.insertOverrides?.delete(u.source)):(o===void 0&&(o=new Map,Ie(r).set(u.source,o)),l===void 0?o.set(i,k(e.context,n)):o.set(i,z(e.context,l,n)))}V(e)}}f(xt,"setArrayIndex");function Te(e,t){const n=m(g(e));t!==n&&(t<n?P(e,t,n-t,[]):P(e,n,0,ee(e,Array.from({length:t-n},()=>null))))}f(Te,"setArrayLength");function vt(e){const t=Number(e);if(!Number.isInteger(t)||t<0||t>=4294967296)throw new RangeError("Invalid array length");return t}f(vt,"toArrayLength");function _(e){const t=Number(e);return Number.isNaN(t)||t===0?0:Number.isFinite(t)?Math.trunc(t):t}f(_,"toIntegerOrInfinity");function U(e,t){return e===Number.NEGATIVE_INFINITY?0:e<0?Math.max(t+e,0):Math.min(e,t)}f(U,"clampIndex");function E(e){if(!w(e))return;const t=Reflect.get(e,D);if(t!==void 0){if(!Array.isArray(h(t)))throw new TypeError("Array mutator called on incompatible receiver");return L(t.context),t}}f(E,"mutatorNode");const At={push(...e){const t=E(this);if(t===void 0)return Reflect.apply(Array.prototype.push,this,e);const n=m(g(t));return P(t,n,0,pe(t,e)),n+e.length},pop(){const e=E(this);if(e===void 0)return Reflect.apply(Array.prototype.pop,this,[]);const t=m(g(e));if(t===0)return;const n=Y(e,t-1);return P(e,t-1,1,[]),n},shift(){const e=E(this);if(e===void 0)return Reflect.apply(Array.prototype.shift,this,[]);if(m(g(e))===0)return;const n=Y(e,0);return P(e,0,1,[]),n},unshift(...e){const t=E(this);return t===void 0?Reflect.apply(Array.prototype.unshift,this,e):(P(t,0,0,pe(t,e)),m(g(t)))},splice(...e){const t=E(this);if(t===void 0)return Reflect.apply(Array.prototype.splice,this,e);const n=m(g(t)),r=e.length===0?0:U(_(e[0]),n),s=e.length===0?0:e.length===1?n-r:Math.min(Math.max(_(e[1]),0),n-r),u=Array.from({length:s},(o,l)=>Y(t,r+l)),i=Math.min(2,e.length),a=Math.max(e.length-2,0);return P(t,r,s,pe(t,e,i)),Te(t,n-s+a),u},reverse(){const e=E(this);if(e===void 0)return Reflect.apply(Array.prototype.reverse,this,[]);const t=g(e);if(m(t)<2)return e.proxy;const n=[...M(t)].reverse();for(const r of n)r.start+=r.step*(r.length-1),r.step=r.step===1?-1:1;return Me(t,n),t.structural=!0,t.generation+=1,t.plan=void 0,V(e),e.proxy},sort(e){const t=E(this);if(t===void 0)return Reflect.apply(Array.prototype.sort,this,[e]);if(e!==void 0&&typeof e!="function")throw new TypeError("Comparator must be a function");const n=g(t),r=[],s=[],u=[],i=new Array(h(t).length),a=[];for(const b of M(n))for(let x=0;x<b.length;x++){const R=b.start+b.step*x;if(b.kind==="base")a.push(R),i[R]=De(t,R,r,s);else{r.push(b.source),s.push(R);const N=-r.length;a.push(N),u.push(De(t,N,r,s))}}const o=new Map;for(const[b,x]of n.baseOverrides??[])o.set(b,v(t.context,x));const l=new Map;for(const[b,x]of n.insertOverrides??[]){const R=new Map;for(const[N,se]of x)R.set(N,v(t.context,se));l.set(b,R)}const d=n.generation;if(a.sort((b,x)=>{const R=b<0?u[-b-1]:i[b],N=x<0?u[-x-1]:i[x];if(typeof e=="function")return Number(e(R,N));const se=String(R),we=String(N);return se<we?-1:se>we?1:0}),o.size>0||l.size>0||(n.baseOverrides?.size??0)>0||(n.insertOverrides?.size??0)>0)for(const b of a)Pt(t,b,r,s,o,l);const c=n.generation!==d,p=m(n);return p>=a.length&&a.every((b,x)=>Rt(n,x,b,r,s))||P(t,0,Math.min(a.length,p),St(a,r,s)),c&&kt(t),t.proxy},fill(e,t,n){const r=E(this);if(r===void 0)return Reflect.apply(Array.prototype.fill,this,[e,t,n]);const s=m(g(r)),u=t===void 0?0:U(_(t),s),i=n===void 0?s:U(_(n),s);if(i<=u)return r.proxy;const a=Array.from({length:i-u},()=>te(e));return P(r,u,i-u,ee(r,a)),r.proxy},copyWithin(e,t,n){const r=E(this);if(r===void 0)return Reflect.apply(Array.prototype.copyWithin,this,[e,t,n]);const s=m(g(r)),u=U(_(e),s),i=U(_(t),s),a=n===void 0?s:U(_(n),s),o=Math.min(Math.max(a-i,0),s-u),l=Array.from({length:o},(d,c)=>te(Y(r,i+c)));return P(r,u,o,ee(r,l)),r.proxy}};function ge(e,t){return e<0?t[-e-1]:void 0}f(ge,"sortTokenSource");function ye(e,t){return e<0?t[-e-1]:e}f(ye,"sortTokenIndex");function De(e,t,n,r){const s=g(e),u=ge(t,n),i=ye(t,r),a=u===void 0?s.baseOverrides?.get(i):s.insertOverrides?.get(u)?.get(i),o=a!==void 0?v(e.context,a):u===void 0?h(e)[i]:v(e.context,u.refs[i]);return w(o)?ue(e.context,o,e,u===void 0?1:2,i,u,u!==void 0||(s.baseOverrides?.has(i)??!1)).proxy:o}f(De,"publicSortValue");function Pt(e,t,n,r,s,u){const i=g(e),a=ge(t,n),o=ye(t,r);if(a===void 0){const p=i.baseOverrides?.get(o),y=s.get(o);y!==void 0?p===void 0?Se(i).set(o,k(e.context,y)):i.baseOverrides.set(o,z(e.context,p,y)):(p!==void 0&&W(e.context,p),i.baseOverrides?.delete(o));return}let l=i.insertOverrides?.get(a);const d=l?.get(o),c=u.get(a)?.get(o);c!==void 0?(l===void 0&&(l=new Map,Ie(i).set(a,l)),d===void 0?l.set(o,k(e.context,c)):l.set(o,z(e.context,d,c))):(d!==void 0&&W(e.context,d),l?.delete(o),l?.size===0&&i.insertOverrides?.delete(a))}f(Pt,"restoreSortOverride");function Rt(e,t,n,r,s){const u=Z(e,t),i=u.start+u.step*e.locatedOffset,a=ge(n,r);return i===ye(n,s)&&(u.kind==="base"&&a===void 0||u.kind==="insert"&&u.source===a)}f(Rt,"sameSortTokenAt");function kt(e){const t=g(e),n=new Set,r=new Map,s=[];let u=!1;for(const i of M(t))for(let a=0;a<i.length;a++){const o=i.start+i.step*a;let l;if(i.kind==="base")l=n.has(o),n.add(o);else{let d=r.get(i.source);d===void 0&&(d=new Set,r.set(i.source,d)),l=d.has(o),d.add(o)}l?(u=!0,Le(s,ee(e,[be(j(e,i,o),e.context)])[0])):Le(s,It(i,o))}u&&(Me(t,s),t.structural=!0,t.generation+=1,t.plan=void 0,V(e))}f(kt,"deduplicateArrayEntries");function St(e,t,n){const r=[];for(const s of e){const u=s<0?t[-s-1]:void 0,i=s<0?n[-s-1]:s,a=r.at(-1),o=a!==void 0&&(u===void 0&&a.kind==="base"||u!==void 0&&a.kind==="insert"&&a.source===u);if(a!==void 0&&o){if(a.length===1){const l=i-a.start;if(l===1||l===-1){a.step=l,a.length=2;continue}}else if(a.start+a.step*a.length===i){a.length+=1;continue}}r.push(u===void 0?{kind:"base",start:i,length:1,step:1}:{kind:"insert",source:u,start:i,length:1,step:1})}return r}f(St,"piecesFromSortOrder");function Le(e,t){const n=e.at(-1),r=n!==void 0&&n.kind===t.kind&&(n.kind==="base"||n.source===t.source);if(n!==void 0&&r&&n.length===1&&t.length===1){const s=t.start-n.start;if(s===1||s===-1){n.step=s,n.length=2;return}}n!==void 0&&r&&n.step===t.step&&n.start+n.step*n.length===t.start?n.length+=t.length:e.push(t)}f(Le,"appendMergedPiece");function It(e,t){return e.kind==="base"?{kind:"base",start:t,length:1,step:1}:{kind:"insert",source:e.source,start:t,length:1,step:1}}f(It,"singletonPiece");function te(e){const t=w(e)?Reflect.get(e,D):void 0;return t===void 0?ce(e):Ve(t)}f(te,"clonePlacement");function ne(e){if(S(e.context),Array.isArray(h(e))){const n=g(e),r=[];for(const s of M(n))for(let u=0;u<s.length;u++){const i=s.start+s.step*u;r.push(G(j(e,s,i),e.context))}return r}const t=Object.create(Object.getPrototypeOf(h(e)));for(const n of le(e))Ce(t,n,G(F(e,n),e.context));return t}f(ne,"cloneNode");function G(e,t){if(!w(e))return e;const n=t.rawNodes.get(e);return n===void 0||!n.dirty&&!n.subtreeDirty?e:ne(n)}f(G,"cloneStored");function Ve(e){if(S(e.context),Array.isArray(h(e))){const n=g(e),r=[];for(const s of M(n))for(let u=0;u<s.length;u++){const i=s.start+s.step*u;r.push(be(j(e,s,i),e.context))}return r}const t=Object.create(Object.getPrototypeOf(h(e)));for(const n of le(e))Ce(t,n,be(F(e,n),e.context));return t}f(Ve,"clonePlacementNode");function be(e,t){if(!w(e))return ce(e);const n=t.rawNodes.get(e);return n===void 0?ce(e):Ve(n)}f(be,"clonePlacementStored");function Ce(e,t,n){de.value=n,Object.defineProperty(e,t,de),de.value=void 0}f(Ce,"defineData");function _e(e){const t=Et(e);if(t!==void 0)return t;const n=[],r=new Map,s=new Map,u=new Map;for(const d of e.dirty)if(Mt(d,u),Array.isArray(h(d))){const c=g(d);if(!c.structural&&(c.baseOverrides?.size??0)>0){let p=u.get(d);p===void 0&&(p={indices:[],bits:void 0,length:h(d).length},u.set(d,p));for(const y of c.baseOverrides.keys())Fe(p,y)}}const i=new Map;for(const[d,c]of u){const p=X(d);if(p===void 0||p.some(b=>typeof b=="string"&&T.has(b)))continue;const y=jt(c);y.length>0&&i.set(d,y)}for(const d of e.dirty){const c=X(d);if(c===void 0||We(d,c,i))continue;s.set(d,c),!Array.isArray(h(d))&&He(d)&&r.set(d,c);const p=c.findIndex(y=>typeof y=="string"&&T.has(y));if(p>=0){let y=d;for(let b=c.length;b>p;b--)y=O(y);r.set(y,c.slice(0,p))}}for(const[d,c]of r)s.set(d,c);for(const d of i.keys()){const c=X(d);c!==void 0&&!We(d,c,i)&&s.set(d,c)}let a=0;for(const d of s.values())a=Math.max(a,d.length);const o=Array.from({length:a+1},()=>[]);for(const[d,c]of s)o[c.length].push(d);const l=new Set;for(const d of o)for(const c of d){const p=s.get(c);if(!(Je(c)||Nt(c,l))){if(r.has(c)){Ct(n,p,ne(c)),l.add(c);continue}if(Array.isArray(h(c))?Lt(c,p,n,i.get(c)):Ge(c,p,n),n.length>K)return I=void 0,[["r",ne(e.root)]]}}return I=void 0,n}f(_e,"emitOperations");function Et(e){const t=[];for(const s of e.dirty){if(Array.isArray(h(s))||He(s)||Je(s))return;for(let i=O(s);i!==void 0;i=O(i))if(Array.isArray(h(i)))return;const u=X(s);if(u!==void 0){for(const i of u)if(typeof i=="string"&&T.has(i))return;if(t.push(s),t.length>rt)return}}for(let s=1;s<t.length;s++){const u=t[s],i=u.preparedPath.length;let a=s;for(;a>0&&t[a-1].preparedPath.length>i;)t[a]=t[a-1],a-=1;t[a]=u}const n=[];let r=!0;for(const s of t)if(Ge(s,s.preparedPath,n)&&(r=!1),n.length>K)return[["r",ne(e.root)]];return e.simpleObjectMaterialization=r,n}f(Et,"emitSimpleObjectOperations");let I,ze=0;function Kt(e){let t=e;for(let n=O(t);n!==void 0;n=O(t)){if(Array.isArray(h(n))){const r=g(n);if(t.parentKind!==1||r.structural)return!1;const s=t.parentKey,u=r.baseOverrides?.get(s);return(u===void 0?h(n)[s]:v(n.context,u))!==h(t)?!1:(I=n,ze=s,!0)}t=n}return!1}f(Kt,"locateDenseArrayPosition");function We(e,t,n){for(let r=O(e);r!==void 0;r=O(r)){const s=n.get(r);if(s===void 0)continue;const u=X(r);if(u===void 0||t.length<=u.length)continue;let i=!0;for(let o=0;o<u.length;o++)if(t[o]!==u[o]){i=!1;break}if(!i)continue;const a=t[u.length];if(typeof a=="number"&&Be(s,a))return!0}return!1}f(We,"hasCoveringDenseRegion");function Fe(e,t){if(e.bits!==void 0){e.bits[t]=1;return}if(e.indices.push(t),!(e.indices.length<256)){e.bits=new Uint8Array(e.length);for(const n of e.indices)e.bits[n]=1;e.indices.length=0}}f(Fe,"addDenseCandidate");function Mt(e,t){if(!Kt(e))return;let n=t.get(I);n===void 0&&(n={indices:[],bits:void 0,length:h(I).length},t.set(I,n)),Fe(n,ze)}f(Mt,"recordDenseArrayPosition");function jt(e){if(e.bits===void 0)return[];const t=[],n=e.bits;for(let r=0;r<n.length;){for(;r<n.length&&n[r]===0;)r+=1;if(r===n.length)break;const s=r;let u=r,i=0,a=0;for(;r<n.length;){if(n[r]!==0)i+=1,u=r,a=0;else if(++a>1)break;r+=1}const o=u-s+1;i>=256&&i*2>=o&&t.push({start:s,length:o})}return t}f(jt,"buildDenseRegions");function Be(e,t){for(const n of e)if(t>=n.start&&t<n.start+n.length)return!0;return!1}f(Be,"regionContaining");function He(e){if(e.writeKey!==void 0&&T.has(e.writeKey)||e.deleteKey!==void 0&&T.has(e.deleteKey))return!0;if(e.writes!==void 0){for(const t of e.writes.keys())if(T.has(t))return!0}if(e.deletes!==void 0){for(const t of e.deletes)if(T.has(t))return!0}return!1}f(He,"hasReservedMutation");function Nt(e,t){for(let n=O(e);n!==void 0;n=O(n))if(t.has(n))return!0;return!1}f(Nt,"hasFoldedAncestor");function Je(e){for(let t=e;t!==void 0;t=O(t))if(O(t)!==void 0&&t.parentPlacement)return!0;return!1}f(Je,"hasPlacementAncestor");function Ue(e,t,n,r,s){const u=[...t,r],i=e.readded?.has(r)||!Object.hasOwn(h(e),r)?void 0:h(e)[r],a=G(s,e.context),o=Xe(n,u,i,a);return w(i)&&w(a)&&!o}f(Ue,"emitObjectWrite");function Ge(e,t,n){if(e.readded!==void 0)for(const s of e.readded)Object.hasOwn(h(e),s)&&n.push(["d",[...t,s]]);let r=!1;if(e.writeKey!==void 0&&(r=Ue(e,t,n,e.writeKey,F(e,e.writeKey))),e.writes!==void 0)for(const[s,u]of e.writes){if(n.length>K)return r;Ue(e,t,n,s,v(e.context,u))&&(r=!0)}if(e.deleteKey!==void 0&&Object.hasOwn(h(e),e.deleteKey)&&n.push(["d",[...t,e.deleteKey]]),e.deletes!==void 0)for(const s of e.deletes){if(n.length>K)return r;Object.hasOwn(h(e),s)&&n.push(["d",[...t,s]])}return r}f(Ge,"emitObjectOperations");function Tt(e){const t=g(e);if(t.plan!==void 0)return t.plan;const n=h(e),r=M(t),s=new Uint8Array(n.length),u=[];for(const c of r)if(c.kind==="base")for(let p=0;p<c.length;p++){const y=c.start+c.step*p;s[y]=1,u.push(y)}const i=[];for(let c=n.length;c>0;){if(s[c-1]!==0){c-=1;continue}let p=c-1;for(;p>0&&s[p-1]===0;)p-=1;i.push(p,c-p),c=p}const a=[];for(let c=0;c<s.length;c++)s[c]!==0&&a.push(c);let o;if(u.some((c,p)=>c!==a[p])){const c=new Map(a.map((p,y)=>[p,y]));o=u.map(p=>c.get(p))}const l=[];let d=0;for(let c=0;c<r.length;){const p=r[c];if(p.kind==="base"){d+=p.length,c+=1;continue}const y=c;for(;c<r.length&&r[c].kind==="insert";)d+=r[c].length,c+=1;l.push(d-Dt(r,y,c),y,c)}return t.plan={removeRuns:i,permutation:o,insertRuns:l},t.plan}f(Tt,"buildArrayPlan");function Dt(e,t,n){let r=0;for(let s=t;s<n;s++)r+=e[s].length;return r}f(Dt,"rangeLength");function Lt(e,t,n,r){const s=g(e),u=h(e);if(r!==void 0)for(const i of r){if(n.length>K)return;n.push(["p",t,i.start,i.length,Vt(e,i)])}if(s.structural){const i=Tt(e);for(let o=0;o<i.removeRuns.length;o+=2){if(n.length>K)return;n.push(["p",t,i.removeRuns[o],i.removeRuns[o+1],[]])}i.permutation!==void 0&&n.push(["m",t,i.permutation]);const a=M(s);for(let o=0;o<i.insertRuns.length;o+=3){if(n.length>K)return;const l=i.insertRuns[o],d=[];for(let c=i.insertRuns[o+1];c<i.insertRuns[o+2];c++){const p=a[c];for(let y=0;y<p.length;y++){const b=p.start+p.step*y;d.push(G(j(e,p,b),e.context))}}n.push(["p",t,l,0,d])}}for(const[i,a]of s.baseOverrides??[]){if(n.length>K)return;const o=Ye(s,1,i,void 0);o===void 0||r!==void 0&&Be(r,o)||Xe(n,[...t,o],u[i],G(v(e.context,a),e.context))}}f(Lt,"emitArrayOperations");function Vt(e,t){const n=g(e),r=[];for(let s=t.start;s<t.start+t.length;s++){const u=Z(n,s),i=u.start+u.step*n.locatedOffset;r.push(G(j(e,u,i),e.context))}return r}f(Vt,"cloneArrayRegion");function Xe(e,t,n,r){if(!w(r)&&n===r||w(n)&&w(r)&&oe(n,r))return!1;if(typeof n=="string"&&typeof r=="string"){if(r.length>n.length&&r.slice(0,n.length)===n)return e.push(["a",t,r.slice(n.length)]),!0;const s=tt(n,r,65536);if(s>0)return e.push(["t",t,n.length-s]),r.length>s&&e.push(["a",t,r.slice(s)]),!0}return e.push(["s",t,r]),!0}f(Xe,"emitChangedValue");function Ct(e,t,n){t.length===0?e.push(["r",n]):e.push(["s",t,n])}f(Ct,"emitSet");function X(e){if(e.preparedPath!==void 0)return e.preparedPath;const t=O(e);if(t===void 0)return e.preparedPath=[],e.preparedPath;const n=X(t);if(n===void 0)return;if(e.parentKind===0){const i=e.parentKey;return!q(t,i)||F(t,i)!==h(e)?void 0:(e.preparedPath=[...n,i],e.preparedPath)}const r=g(t),s=Ye(r,e.parentKind,e.parentKey,e.parentSource);if(s===void 0)return;const u=Z(r,s);if(j(t,u,e.parentKey)===h(e))return e.preparedPath=[...n,s],e.preparedPath}f(X,"resolvePath");function _t(e){if(e.baseLocations!==void 0)return;e.baseLocations=[],e.insertLocations=new Map;let t=0;for(const r of M(e)){const s=r.start+r.step*(r.length-1),u={piece:r,logicalStart:t,minimum:Math.min(r.start,s),maximum:Math.max(r.start,s)};if(r.kind==="base")e.baseLocations.push(u);else{let i=e.insertLocations.get(r.source);i===void 0&&(i=[],e.insertLocations.set(r.source,i)),i.push(u)}t+=r.length}const n=f((r,s)=>r.minimum-s.minimum,"byMinimum");e.baseLocations.sort(n);for(const r of e.insertLocations.values())r.sort(n)}f(_t,"ensurePieceLocations");function Ye(e,t,n,r){if(t===1&&!e.structural)return n;_t(e);const s=t===1?e.baseLocations:e.insertLocations.get(r);if(s===void 0)return;let u=0,i=s.length;for(;u<i;){const l=u+i>>>1;s[l].minimum<=n?u=l+1:i=l}const a=s[u-1];if(a===void 0||n>a.maximum)return;const o=(n-a.piece.start)/a.piece.step;return o>=0&&o<a.piece.length?a.logicalStart+o:void 0}f(Ye,"findEntryIndex");function zt(e){if(e.ops!==void 0)return e.ops;if(S(e),e.replacement){const t=e.tracker.deref()?.replacementBase(e);e.replacementNoop=t!==void 0&&oe(t,h(e.root)),e.ops=e.replacementNoop?[]:[["r",h(e.root)]]}else e.ops=_e(e);return e.ops}f(zt,"ensureOperations");function oe(e,t){if(e===t)return!0;if(!w(e)||!w(t)||Array.isArray(e)!==Array.isArray(t))return!1;if(Array.isArray(e)){const s=t;if(e.length!==s.length)return!1;for(let u=0;u<e.length;u++)if(!oe(e[u],s[u]))return!1;return!0}const n=t,r=Object.keys(e);if(r.length!==Object.keys(n).length)return!1;for(const s of r)if(!Object.hasOwn(n,s)||!oe(e[s],n[s]))return!1;return!0}f(oe,"equalTrustedJson");function qe(e){e.status.value==="aborted"||e.status.value==="consumed"||e.status.value==="stale"||(e.status.value="aborted",re(e))}f(qe,"abortContext");function Qe(e){e.tracker.deref()?.releaseContext(e),I?.context===e&&(I=void 0),e.overlayReleased=!0,e.dirty.length=0,e.nodes.length=0,e.rawNodes=void 0,e.ops=void 0,e.root=void 0,e.bases=void 0,e.stored=void 0,e.baseValue=void 0}f(Qe,"releaseOverlayReferences");function re(e){e.tracker.deref()?.releaseContext(e),I?.context===e&&(I=void 0);for(const t of e.nodes)Array.isArray(t.target)&&(t.target.length=0),Reflect.deleteProperty(t.target,D),t.writes?.clear(),t.deletes?.clear(),t.readded?.clear(),t.array?.pieces!==void 0&&(t.array.pieces.length=0),t.array!==void 0&&(t.array.root=void 0,t.array.baseLocations=void 0,t.array.insertLocations=void 0),t.array?.baseOverrides?.clear(),t.array?.insertOverrides?.clear(),t.parentSource=void 0,t.target=ie,t.proxy=ie,t.writeKey=void 0,t.writeValue=void 0,t.writes=void 0,t.deleteKey=void 0,t.deletes=void 0,t.readded=void 0,t.array=void 0,t.subtreeDirty=void 0,t.preparedPath=void 0;e.dirty.length=0,e.nodes.length=0,e.rawNodes=void 0,e.ops=void 0,e.root=void 0,e.bases=void 0,e.stored=void 0,e.baseValue=void 0,e.overlayReleased=!0}f(re,"clearContext");function w(e){return e!==null&&typeof e=="object"}f(w,"isContainer");export{Jt as track};
@@ -1 +0,0 @@
1
- var y=Object.defineProperty;var h=(d,e)=>y(d,"name",{value:e,configurable:!0});import{BACKGROUND_CONTEXT as v}from"../context/index.js";import{RemoteServiceBindingImpl as m}from"../services/consumer.js";import{ServiceSlot as u}from"../services/handle.js";import{InstanceDirectory as b}from"../services/instances.js";import{createLoopbackServiceTransport as S}from"../services/loopback.js";import{RemoteServiceProvider as E,validateRemoteServiceImplementation as I}from"../services/provider.js";import{MutableReplicatedStateImpl as $}from"../services/state.js";class F{static{h(this,"FacetLifecycle")}id;#t=[];#r=[];#i=[];#e="setting_up";#o=!1;constructor(e){this.id=e}assertSettingUp(e){if(this.#e!=="setting_up")throw new Error(`Facet ${this.id} can ${e} only during setup`)}assertRunning(e){if(this.#e!=="setting_up"&&this.#e!=="active")throw new Error(`Facet ${this.id} cannot ${e} while ${this.#e}`)}assertActive(e){if(this.#e!=="active")throw new Error(`Facet ${this.id} can ${e} only while active`)}assertServiceAccess(){if(!this.#o)throw new Error(`Facet ${this.id} service handles cannot be used while ${this.#e}`)}revoke(){this.#o=!1}own(e){this.assertRunning("own resources"),this.#t.push(e)}observe(e){this.assertSettingUp("observe services"),this.#r.push(e)}onActivate(e){this.assertSettingUp("register activation callbacks"),this.#i.push(e)}prepared(){this.assertSettingUp("finish setup"),this.#e="prepared"}async activate(){if(this.#e!=="prepared")throw new Error(`Facet ${this.id} is not prepared`);this.#e="active",this.#o=!0;for(const e of this.#r)this.#t.push(e());for(const e of this.#i)await e()}async dispose(){if(this.#e==="dead")return;this.#e="disposing";const e=[];for(const t of this.#t.splice(0).reverse())try{await t()}catch(s){e.push(s)}if(this.#r.length=0,this.#i.length=0,this.#o=!1,this.#e="dead",e.length===1)throw e[0];if(e.length>1)throw new AggregateError(e,`Failed to dispose facet ${this.id}`)}}class A{static{h(this,"LocalKeyedServiceRegistry")}#t=new Map;#r=!1;constructor(e,t){const s=e.map(({id:i})=>i);if(new Set(s).size!==s.length)throw new TypeError("Local keyed service registry has duplicate IDs");for(const i of s)this.#t.set(i,{generations:new Map,directory:new b({ready:!0,onError:t})})}spawn(e,t,s){if(this.#e(),t.length===0)throw new TypeError("Local service instance key must not be empty");if(typeof s!="object"||s===null||Array.isArray(s))throw new TypeError(`Local service ${e.id} implementation must be an object`);const i=this.#i(e.id);if(i.directory.get(t)!==void 0)throw new Error(`Local service ${e.id} already has a live instance with key ${t}`);const n=(i.generations.get(t)??0)+1;i.generations.set(t,n);const r={key:t,generation:n,service:s,deactivate(){}};i.directory.insert(r);let c=!1;return()=>{c||(c=!0,i.directory.remove(r))}}observe(e,t){return this.#e(),this.#i(e.id).directory.observe(t)}dispose(){if(!this.#r){this.#r=!0;for(const e of this.#t.values())e.directory.dispose();this.#t.clear()}}#i(e){const t=this.#t.get(e);if(t===void 0)throw new Error(`Local keyed service ${e} is not registered`);return t}#e(){if(this.#r)throw new Error("Local keyed service registry is disposed")}}class M{static{h(this,"HostServiceSlots")}#t=new Map;#r=new Map;getSingleton(e,t){let s=this.#t.get(e.id);return s===void 0&&(s=new u(e.id,!e.local),this.#t.set(e.id,s)),s.view(t)}hasSingleton(e){return this.#t.has(e)}observe(e,t,s){const i=this.#r.get(e.id);if(i===void 0)throw new Error(`Service ${e.id} is disconnected`);let n=!1;const r=i.observe(e,(c,o)=>{const a=new u(e.id,!e.local);return a.bind(c),s(a.view(()=>{if(t(),n||o.abortSignal?.aborted)throw new Error(`Keyed service ${e.id} observation is closed`)}),o)});return()=>{n||(n=!0,r())}}bindSingleton(e,t){this.#t.get(e)?.bind(t)}bindKeyed(e,t){this.#r.set(e,t)}dispose(){for(const e of this.#t.values())e.unbind();this.#t.clear(),this.#r.clear()}}class R{static{h(this,"StagedServiceSpawner")}#t;#r;#i=new Map;#e;constructor(e,t){this.#t=e,this.#r=t}connect(e){if(this.#e!==void 0)throw new Error("Facet service provider is already connected");this.#e=e;for(const t of this.#i.values())t.release=e(t.key,t.implementation)}spawn(e,t){if(this.#t.assertActive("spawn service instances"),this.#r(e,t),this.#i.has(e))throw new Error(`Facet service already has a live instance with key ${e}`);const s={key:e,implementation:t};this.#i.set(e,s),this.#e!==void 0&&(s.release=this.#e(e,t));const i=h(()=>{this.#i.get(e)===s&&(this.#i.delete(e),s.release?.())},"close");return this.#t.own(i),i}}class _{static{h(this,"FacetKernel")}#t;#r;#i;#e=new Map;#o;#c=new Map;#a=[];#h;#n;#d;#s="setup";constructor(e){const t=e.facets.map(s=>s.id);if(t.some(s=>s.length===0))throw new Error("Facet ID must not be empty");if(new Set(t).size!==t.length)throw new Error("Facet IDs must be unique within a generation");this.#t=e.facets,this.#r=e.serviceSources??[],this.#i=e.onError??(()=>{}),this.#o=new M}get provider(){if(this.#h===void 0)throw new Error("Facet service provider is not assembled");return this.#h}#v(e){return{facetId:e,requires:[],provides:[],lifecycle:new F(e),provisions:[],singletonViews:new Map}}#u(e,t){const s=e.setup(this.#b(t));if(K(s))throw Promise.resolve(s).catch(()=>{}),new Error(`Facet ${e.id} setup must be synchronous`);t.lifecycle.prepared()}async activate(){const e=[];try{for(const s of this.#t){const i=this.#v(s.id);this.#e.set(s.id,i),this.#u(s,i),e.push(i)}this.#s="assembling";const t=await this.#S(e);this.#a=k(e,t),this.#E(),this.#I(t),this.#s="connecting",await Promise.all([...this.#c.values(),this.#f].map(s=>s.ready(v))),this.#s="activating";for(const s of this.#a)await this.#e.get(s).lifecycle.activate();this.#s="active"}catch(t){const s=await this.#p();throw s.length>0?new AggregateError([t,...s],"Facet generation startup and cleanup failed"):t}}async reload(e){if(this.#s!=="active")throw new Error(`Facet host cannot reload while ${this.#s}`);const t=e.map(({id:o})=>o);if(t.some(o=>o.length===0))throw new Error("Facet ID must not be empty");if(new Set(t).size!==t.length)throw new Error("Reloaded facet IDs must be unique");for(const o of t)if(!this.#e.has(o))throw new Error(`Facet ${o} is not active`);this.#s="reloading";const s=[],i=[];try{for(const o of e){const a=this.#v(o.id);s.push(a),this.#u(o,a);const f=this.#e.get(o.id);if(!L(f,a))throw new Error(`Reloaded facet ${o.id} must preserve its service requirements and provisions`);this.#w(a.provisions),i.push(a)}}catch(o){const a=await l(s.reverse());if(a.length>0){const f=await this.#l();throw new AggregateError([o,...a,...f],"Facet reload setup and cleanup failed")}throw this.#s="active",o}const n=new Map(i.map(o=>[o.facetId,o])),r=this.#a.flatMap(o=>{const a=n.get(o);return a===void 0?[]:[a]});try{for(const o of r)await o.lifecycle.activate();for(const o of r)this.#w(o.provisions)}catch(o){const a=await l([...r].reverse());if(a.length>0){const f=await this.#l();throw new AggregateError([o,...a,...f],"Facet reload activation and cleanup failed")}throw this.#s="active",o}const c=r.map(({facetId:o})=>this.#e.get(o));for(const o of r)this.#e.set(o.facetId,o);try{for(const a of r)for(const f of a.provisions)f.kind==="singleton"&&(f.service.local?this.#o.bindSingleton(f.service.id,f.implementation):f.replace(this.provider));const o=await l(c.reverse());if(o.length===1)throw o[0];if(o.length>1)throw new AggregateError(o,"Failed to retire replaced facets");for(const a of r)for(const f of a.provisions)f.kind==="keyed"&&(f.service.local?f.connectLocal(this.#y):f.connectRemote(this.provider))}catch(o){const a=await this.#l(c);throw new AggregateError([o,...a],"Facet reload failed after cutover")}this.#s="active"}async dispose(){if(this.#s==="dead")return;if(this.#s!=="active")throw new Error(`Facet host cannot be disposed while ${this.#s}`);const e=await this.#p();if(e.length===1)throw e[0];if(e.length>1)throw new AggregateError(e,"Failed to dispose facet generation")}#w(e){for(const t of e)t.kind!=="singleton"||t.service.local||t.validateReplacement(this.provider)}#b(e){const{lifecycle:t,provisions:s}=e;return{provide:h((i,n)=>{if(t.assertSettingUp("provide services"),typeof n!="object"||n===null||Array.isArray(n))throw new TypeError(`Service ${i.id} implementation must be an object`);p(e.provides,i,"singleton"),s.push({kind:"singleton",service:i,implementation:n,install:h(r=>r.provide(i,n),"install"),validateReplacement:h(r=>r.validateReplacement(i,n),"validateReplacement"),replace:h(r=>r.replace(i,n),"replace")})},"provide"),provideMany:h(i=>{t.assertSettingUp("provide service instances"),p(e.provides,i,"keyed");const n=new R(t,(r,c)=>{if(r.length===0)throw new TypeError("Facet service instance key must not be empty");if(typeof c!="object"||c===null||Array.isArray(c))throw new TypeError(`Facet service ${i.id} implementation must be an object`);i.local||I(i.id,c)});return s.push({kind:"keyed",service:i,connectLocal:h(r=>n.connect((c,o)=>r.spawn(i,c,o)),"connectLocal"),connectRemote:h(r=>n.connect((c,o)=>r.spawn(i,c,o)),"connectRemote")}),n},"provideMany"),use:h(i=>{t.assertSettingUp("acquire services"),p(e.requires,i,"singleton");let n=e.singletonViews.get(i.id);return n===void 0&&(n=this.#o.getSingleton(i,()=>t.assertServiceAccess()),e.singletonViews.set(i.id,n)),n},"use"),observe:h((i,n)=>{t.assertSettingUp("observe services"),p(e.requires,i,"keyed"),t.observe(()=>this.#o.observe(i,()=>t.assertServiceAccess(),n))},"observe"),replicatedState:h(i=>(t.assertRunning("create replicated state"),new $(i)),"replicatedState"),own:h(i=>t.own(i),"own"),onActivate:h(i=>t.onActivate(i),"onActivate"),onDeactivate:h(i=>t.own(i),"onDeactivate")}}async#S(e){const t=await Promise.all(this.#r.map(async c=>({source:c,entries:await c.catalogue(v)}))),s=new Map;for(const{source:c,entries:o}of t)for(const{serviceId:a,mode:f}of o){if(s.has(a))throw new Error(`Facet host service ${a} is offered by more than one source`);s.set(a,{mode:f,source:c})}const i=new Set(e.flatMap(({provides:c})=>c.map(({serviceId:o})=>o))),n=new Map;for(const{requires:c}of e)for(const o of c){if(i.has(o.serviceId)||n.has(o.serviceId))continue;let a=s.get(o.serviceId);if(a===void 0){const f=this.#r.filter(({acceptsUnavailableServices:g})=>g);if(f.length>1)throw new Error(`Facet host service ${o.serviceId} has more than one deferred source`);f.length===1&&(a={mode:o.mode,source:f[0]})}a!==void 0&&n.set(o.serviceId,{...a,service:o.service})}const r=new Map;for(const[c,{source:o}]of n){let a=r.get(o);a===void 0&&(a=[],r.set(o,a)),a.push(c)}for(const[c,o]of r)this.#c.set(c,c.open({services:o.map(a=>({id:a})),assertAccess:h(()=>this.#m(),"assertAccess"),onError:this.#i}));return n}#E(){const e=this.#g(),t=e.filter(({service:r})=>!r.local),s=new E(t.map(({service:r,kind:c})=>({service:r,mode:c}))),i=new m({services:t.map(({service:r})=>r),transport:S(s),assertAccess:h(()=>this.#m(),"assertAccess"),onError:this.#i}),n=new A(e.flatMap(r=>r.kind==="keyed"&&r.service.local?[r.service]:[]),this.#i);this.#h=s,this.#n=i,this.#d=n;for(const r of e)r.kind==="singleton"?r.service.local||r.install(s):r.service.local?r.connectLocal(n):r.connectRemote(s)}#I(e){for(const t of this.#g())if(t.kind==="singleton"){if(!this.#o.hasSingleton(t.service.id))continue;const s=t.service.local?t.implementation:this.#f.use(t.service);this.#o.bindSingleton(t.service.id,s)}else this.#o.bindKeyed(t.service.id,t.service.local?this.#y:this.#f);for(const[t,{service:s,mode:i,source:n}]of e){const r=this.#c.get(n);if(r===void 0)throw new Error(`Service source for ${t} is not open`);i==="singleton"?this.#o.bindSingleton(t,r.use(s)):this.#o.bindKeyed(t,r)}}#g(){return[...this.#e.values()].flatMap(({provisions:e})=>e)}get#y(){if(this.#d===void 0)throw new Error("Facet keyed services are not assembled");return this.#d}get#f(){if(this.#n===void 0)throw new Error("Facet remote services are not assembled");return this.#n}async#$(){const e=[...this.#c.values()];return this.#c.clear(),this.#n!==void 0&&e.push(this.#n),this.#n=void 0,(await Promise.allSettled(e.map(s=>s.dispose(v)))).flatMap(s=>s.status==="rejected"?[s.reason]:[])}#m(){if(this.#s!=="activating"&&this.#s!=="active"&&this.#s!=="reloading"&&this.#s!=="disposing")throw new Error(`Facet service targets cannot be used during ${this.#s}`)}async#l(e=[]){for(const t of this.#e.values())t.lifecycle.revoke();for(const t of e)t.lifecycle.revoke();return this.#p(e)}async#p(e=[]){this.#s="disposing";const t=await this.#F();t.push(...await l([...e].reverse()));try{this.#d?.dispose()}catch(s){t.push(s)}this.#d=void 0,t.push(...await this.#$());try{this.#o.dispose()}catch(s){t.push(s)}try{this.#h?.dispose()}catch(s){t.push(s)}return this.#s="dead",t}async#F(){const e=[],t=this.#a.length>0?[...this.#a].reverse():[...this.#e.keys()].reverse();for(const s of t){const i=this.#e.get(s);if(i!==void 0){this.#e.delete(s);try{await i.lifecycle.dispose()}catch(n){e.push(n)}}}return e}}async function l(d){const e=[];for(const t of d)try{await t.lifecycle.dispose()}catch(s){e.push(s)}return e}h(l,"disposeFacetRecords");function k(d,e){const t=new Map;for(const[n,{mode:r}]of e)t.set(n,{facetId:void 0,mode:r});for(const n of d)for(const r of n.provides){const c=t.get(r.serviceId);if(c!==void 0)throw c.mode!==void 0&&c.mode!==r.mode?new Error(`Service ${r.serviceId} is provided as both singleton and keyed`):c.facetId===void 0?new Error(`Service ${r.serviceId} is provided by both the host and ${n.facetId}`):new Error(`Service ${r.serviceId} is provided by both ${c.facetId} and ${n.facetId}`);t.set(r.serviceId,{facetId:n.facetId,mode:r.mode})}const s=new Map(d.map(n=>[n.facetId,new Set])),i=new Map(d.map(n=>[n.facetId,new Set]));for(const n of d)for(const r of n.requires){const c=t.get(r.serviceId);if(c===void 0)throw new Error(`Facet ${n.facetId} requires local/${r.serviceId}/${r.mode}, but no facet provides it`);if(c.mode!==void 0&&c.mode!==r.mode)throw new Error(`Facet ${n.facetId} requires ${r.serviceId} as ${r.mode}, but ${c.facetId??"the host"} provides it as ${c.mode}`);c.facetId===void 0||c.facetId===n.facetId||(s.get(n.facetId).add(c.facetId),i.get(c.facetId).add(n.facetId))}return q(d,s,i)}h(k,"validateFacets");function q(d,e,t){const s=new Map([...e].map(([r,c])=>[r,c.size])),i=d.map(r=>r.facetId).filter(r=>s.get(r)===0),n=[];for(;i.length>0;){const r=i.shift();n.push(r);for(const c of t.get(r)??[]){const o=s.get(c)-1;s.set(c,o),o===0&&i.push(c)}}if(n.length!==d.length){const r=d.map(c=>c.facetId).filter(c=>s.get(c)>0);throw new Error(`Facet dependency cycle: ${r.join(", ")}`)}return n}h(q,"topologicalOrder");function p(d,e,t){d.some(s=>s.serviceId===e.id&&s.mode===t)||d.push({serviceId:e.id,service:e,mode:t})}h(p,"recordServiceReference");function L(d,e){return w(d.requires,e.requires)&&w(d.provides,e.provides)}h(L,"sameFacetShape");function w(d,e){return d.length===e.length&&d.every(t=>e.some(s=>s.serviceId===t.serviceId&&s.mode===t.mode))}h(w,"sameReferences");function K(d){return typeof d=="object"&&d!==null&&"then"in d&&typeof d.then=="function"}h(K,"isPromiseLike");export{_ as FacetKernel};
@@ -1 +0,0 @@
1
- var o=Object.defineProperty;var a=(s,t)=>o(s,"name",{value:t,configurable:!0});async function d(s){return(await Promise.allSettled(s.map(e=>e.dispose()))).flatMap(e=>e.status==="rejected"?[e.reason]:[])}a(d,"disposeLoadedFacets");export{d as disposeLoadedFacets};
@@ -1 +0,0 @@
1
- import{combineFacetLoaders as t,createFacetHost as c,createRemoteServiceBinding as o,createStaticFacetLoader as a,defineFacet as i,defineService as S,replicatedState as p}from"./api.js";import{copyJson as s,isJsonValue as d}from"./json.js";import{isRemoteServiceErrorCode as l,REMOTE_SERVICE_ERROR_CODES as m,RemoteServiceError as C}from"./services/errors.js";import{createRemoteServiceEndpoint as R,RemoteServiceProvider as f}from"./services/provider.js";import{createServiceStateDecoder as u,createServiceStateEncoder as x}from"./services/state-codec.js";import{createServiceCatalogueCall as g,createServiceSubscribeCall as O,createServiceUnsubscribeCall as P,decodeServiceControlCall as U,parseServiceCall as _,parseServiceCatalogue as h,parseServiceProviderUpdate as D,parseServiceSubscriptionSnapshot as J,parseWireServiceProviderUpdate as L,parseWireServiceSubscriptionSnapshot as V}from"./services/wire.js";export{m as REMOTE_SERVICE_ERROR_CODES,C as RemoteServiceError,f as RemoteServiceProvider,t as combineFacetLoaders,s as copyJson,c as createFacetHost,o as createRemoteServiceBinding,R as createRemoteServiceEndpoint,g as createServiceCatalogueCall,u as createServiceStateDecoder,x as createServiceStateEncoder,O as createServiceSubscribeCall,P as createServiceUnsubscribeCall,a as createStaticFacetLoader,U as decodeServiceControlCall,i as defineFacet,S as defineService,d as isJsonValue,l as isRemoteServiceErrorCode,_ as parseServiceCall,h as parseServiceCatalogue,D as parseServiceProviderUpdate,J as parseServiceSubscriptionSnapshot,L as parseWireServiceProviderUpdate,V as parseWireServiceSubscriptionSnapshot,p as replicatedState};
@@ -1 +0,0 @@
1
- var d=Object.defineProperty;var c=(e,t)=>d(e,"name",{value:t,configurable:!0});const p={value:void 0,writable:!0,enumerable:!0,configurable:!0};function O(e,t){return u(e,void 0,t?.omitUndefinedProperties===!0)}c(O,"copyJson");function u(e,t,i){if(e===null||typeof e=="string"||typeof e=="boolean")return e;if(typeof e=="number"){if(Number.isFinite(e))return e;throw new TypeError("Value contains a non-finite number and is not strict JSON")}if(typeof e!="object")throw new TypeError(`Value contains a non-JSON ${typeof e}; expected strict JSON`);const r=t??new Set;if(r.has(e))throw new TypeError("Value contains cycles and is not strict JSON");r.add(e);try{if(Array.isArray(e)){if(Object.getPrototypeOf(e)!==Array.prototype||Reflect.ownKeys(e).length!==e.length+1)throw new TypeError("Value must contain strict JSON dense plain arrays");const s=new Array(e.length);for(let o=0;o<e.length;o++){const y=Object.getOwnPropertyDescriptor(e,o);if(y===void 0||!y.enumerable||!("value"in y))throw new TypeError("Value must contain strict JSON enumerable indexed data properties");a(s,String(o),u(y.value,r,i))}return s}const n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==null)throw new TypeError("Value must contain strict JSON plain objects or arrays");const f=Object.create(n);for(const s of Reflect.ownKeys(e)){if(typeof s=="symbol")throw new TypeError("Value contains a symbol key and is not strict JSON");const o=Object.getOwnPropertyDescriptor(e,s);if(!o.enumerable||!("value"in o))throw new TypeError("Value must contain strict JSON enumerable data properties");o.value===void 0&&i||a(f,s,u(o.value,r,i))}return f}finally{r.delete(e)}}c(u,"copy");function a(e,t,i){p.value=i,Object.defineProperty(e,t,p),p.value=void 0}c(a,"defineData");function w(e){return l(e,new Set)}c(w,"isJsonValue");function l(e,t){if(e===null||typeof e=="string"||typeof e=="boolean")return!0;if(typeof e=="number")return Number.isFinite(e);if(Array.isArray(e)){if(Object.getPrototypeOf(e)!==Array.prototype)return!1;const r=Reflect.ownKeys(e);if(r.length!==e.length+1||r.some(n=>typeof n!="string")||t.has(e))return!1;t.add(e);try{for(let n=0;n<e.length;n++){const f=Object.getOwnPropertyDescriptor(e,String(n));if(f===void 0||!f.enumerable||!("value"in f)||!l(f.value,t))return!1}return!0}finally{t.delete(e)}}if(typeof e!="object"||e===null)return!1;const i=Object.getPrototypeOf(e);if(i!==Object.prototype&&i!==null||Reflect.ownKeys(e).some(r=>typeof r!="string")||t.has(e))return!1;t.add(e);try{for(const r of Object.values(Object.getOwnPropertyDescriptors(e)))if(!r.enumerable||!("value"in r)||!l(r.value,t))return!1;return!0}finally{t.delete(e)}}c(l,"check");export{O as copyJson,w as isJsonValue};
@@ -1,2 +0,0 @@
1
- var I=Object.defineProperty;var s=(e,t)=>I(e,"name",{value:t,configurable:!0});import{createHash as z}from"node:crypto";import{mkdir as S,mkdtemp as U,readFile as p,rm as M,writeFile as w}from"node:fs/promises";import{createRequire as B,isBuiltin as A}from"node:module";import{tmpdir as P}from"node:os";import{basename as k,dirname as O,isAbsolute as T,join as l,resolve as g}from"node:path";import{fileURLToPath as _}from"node:url";import{compileFunction as V}from"node:vm";import{FACET_BUNDLE_ARTIFACT_FORMAT as b,FACET_BUNDLE_ARTIFACT_FORMAT_VERSION as E,FACET_BUNDLE_FORMAT as h,FACET_BUNDLE_FORMAT_VERSION as y,FACET_BUNDLE_MANIFEST_FILE as R}from"./manifest.js";async function C(e){const t=F(e);let n;try{n=JSON.parse(await p(t,"utf8"))}catch(r){throw new Error(`Could not read facet bundle manifest ${t}`,{cause:r})}return N(n,t)}s(C,"readFacetBundleManifest");async function ie(e){if(e.entry.length===0)throw new TypeError("Facet bundle entry name must not be empty");const t=F(e.manifestPath),n=await C(t),r=n.entries[e.entry];if(r===void 0)throw new Error(`Facet bundle ${n.plugin.id} has no entry named ${e.entry}`);const o=m(t,r.file,"entry"),i=await p(o,"utf8");$(i,r);const a=r.sourceMap===void 0?void 0:await p(m(t,r.sourceMap,"source map"),"utf8");return Object.freeze({format:b,formatVersion:E,plugin:n.plugin,entryName:e.entry,entry:r,source:i,...a===void 0?{}:{sourceMapContents:a}})}s(ie,"readFacetBundleArtifact");function ae(e){const t=J(e.artifact),n=g(e.temporaryDirectory??P());return{async load(){await S(n,{recursive:!0});const r=await U(l(n,"chord-facet-"));try{await H(r,t);const o=await D({manifestPath:l(r,R),entry:t.entryName,resolveExternal:e.resolveExternal}).load();let i=!1;return{get facets(){return o.facets},async dispose(){if(i)return;i=!0;const a=[];try{await o.dispose()}catch(c){a.push(c)}try{await M(r,{force:!0,recursive:!0})}catch(c){a.push(c)}if(a.length===1)throw a[0];if(a.length>1)throw new AggregateError(a,"Failed to dispose facet bundle artifact")}}}catch(o){try{await M(r,{force:!0,recursive:!0})}catch(i){throw new AggregateError([o,i],"Facet bundle artifact loading and cleanup failed")}throw o}}}}s(ae,"createFacetBundleArtifactLoader");function D(e){if(e.entry.length===0)throw new TypeError("Facet bundle entry name must not be empty");const t=F(e.manifestPath);return{async load(){const n=await C(t),r=n.entries[e.entry];if(r===void 0)throw new Error(`Facet bundle ${n.plugin.id} has no entry named ${e.entry}`);const o=m(t,r.file,"entry");try{const i=await p(o,"utf8");e.verifyIntegrity!==!1&&$(i,r);const a=q(i,o,r.externalImports,e.resolveExternal);let c=v(a,n.plugin.id,e.entry),u=!1;return{get facets(){return c},async dispose(){u||(u=!0,c=Object.freeze([]))}}}catch(i){const a=i instanceof Error?`: ${i.message}`:"";throw new Error(`Could not load facet bundle entry ${n.plugin.id}/${e.entry}${a}`,{cause:i})}}}}s(D,"createFacetBundleLoader");function q(e,t,n,r){const o=B(t),i=new Map;for(const f of n)A(f)||K(f),i.set(f,W(G(f,r)));const a=s(f=>{const x=i.get(f);if(x===void 0)throw new Error(`Facet bundle required undeclared external import: ${f}`);return x},"targetFor"),c=Object.assign(f=>o(a(f)),{resolve:s(f=>o.resolve(a(f)),"resolve")}),u={exports:Object.create(null)},L=V(e,["exports","require","module","__filename","__dirname"],{filename:t});return Reflect.apply(L,u.exports,[u.exports,c,u,t,O(t)]),u.exports}s(q,"executeCommonJsModule");function W(e){if(T(e)||A(e))return e;let t;try{t=new URL(e)}catch{return e}if(t.protocol==="file:")return _(t);if(t.protocol==="node:")return t.href;throw new Error(`Facet bundle external target must be a file, package, or built-in module: ${e}`)}s(W,"toRequireSpecifier");function F(e){if(typeof e=="string")return g(e);if(e.protocol!=="file:")throw new TypeError(`Facet bundle manifest must be a file URL, not ${e.protocol}`);return _(e)}s(F,"toFilePath");function m(e,t,n){if(t.length===0||T(t)||k(t)!==t||t==="."||t==="..")throw new Error(`Facet bundle ${n} must be a filename relative to its manifest`);return g(O(e),t)}s(m,"resolveBundleFile");function $(e,t){const n=j(t.integrity);if(z("sha256").update(e,"utf8").digest("base64")!==n)throw new Error(`Facet bundle integrity check failed for ${t.file}`)}s($,"verifySource");function j(e){const t="sha256-";if(!e.startsWith(t)||e.length===t.length)throw new Error("Facet bundle entry has an invalid SHA-256 integrity value");return e.slice(t.length)}s(j,"parseIntegrity");function v(e,t,n){if(!d(e))throw new Error(`Facet bundle entry ${t}/${n} did not export a module`);const r=e.default,o=Array.isArray(r)?r:[r];if(o.length===0)throw new Error(`Facet bundle entry ${t}/${n} exported no facets`);const i=[];for(const c of o){if(!d(c)||typeof c.id!="string"||c.id.length===0)throw new Error(`Facet bundle entry ${t}/${n} has a facet with an invalid ID`);if(typeof c.setup!="function")throw new Error(`Facet bundle entry ${t}/${n} facet ${c.id} has no setup function`);i.push(c)}const a=i.map(({id:c})=>c);if(new Set(a).size!==a.length)throw new Error(`Facet bundle entry ${t}/${n} exports duplicate facet IDs`);return Object.freeze(i)}s(v,"facetsFromModule");function J(e){if(!d(e)||e.format!==b||e.formatVersion!==E||typeof e.entryName!="string"||e.entryName.length===0||typeof e.source!="string")throw new Error("Invalid facet bundle artifact");const t=N({format:h,formatVersion:y,plugin:e.plugin,entries:{[e.entryName]:e.entry}},"facet bundle artifact"),n=t.entries[e.entryName];if(n.sourceMap===void 0){if(e.sourceMapContents!==void 0)throw new Error("Facet bundle artifact has source map contents without a source map")}else if(typeof e.sourceMapContents!="string")throw new Error("Facet bundle artifact is missing its source map contents");return $(e.source,n),Object.freeze({format:b,formatVersion:E,plugin:t.plugin,entryName:e.entryName,entry:n,source:e.source,...e.sourceMapContents===void 0?{}:{sourceMapContents:e.sourceMapContents}})}s(J,"validateArtifact");async function H(e,t){const n={format:h,formatVersion:y,plugin:t.plugin,entries:{[t.entryName]:t.entry}};await Promise.all([w(l(e,t.entry.file),t.source,"utf8"),w(l(e,R),`${JSON.stringify(n,null,2)}
2
- `,"utf8"),...t.entry.sourceMap===void 0?[]:[w(l(e,t.entry.sourceMap),t.sourceMapContents,"utf8")]])}s(H,"materializeArtifact");function G(e,t){const n=t?.(e);if(n!==void 0)return typeof n=="string"?n:n.href;const r=import.meta.url.endsWith(".ts")?"ts":"js";return e==="@earendil-works/chord"?new URL(`../index.${r}`,import.meta.url).href:e==="@earendil-works/chord/context"?new URL(`../context/index.${r}`,import.meta.url).href:e==="@earendil-works/chord/node"?new URL(`../node.${r}`,import.meta.url).href:import.meta.resolve(e)}s(G,"resolveExternalTarget");function K(e){const t=e.split("/"),n=e.startsWith("@")?2:1;if(e.startsWith(".")||e.startsWith("/")||e.startsWith("#")||e.includes(":")||e.includes("\\")||t.length<n||t.some(r=>r.length===0||r==="."||r===".."))throw new Error(`Facet bundle artifact has an unsupported external import: ${e}`)}s(K,"validatePackageSpecifier");function N(e,t){if(!d(e)||e.format!==h)throw new Error(`Invalid facet bundle manifest format in ${t}`);if(e.formatVersion!==y)throw new Error(`Unsupported facet bundle manifest version in ${t}: ${String(e.formatVersion)}`);if(!d(e.plugin)||typeof e.plugin.id!="string"||e.plugin.id.length===0)throw new Error(`Facet bundle manifest has an invalid plugin identity in ${t}`);if(e.plugin.version!==void 0&&(typeof e.plugin.version!="string"||e.plugin.version.length===0))throw new Error(`Facet bundle manifest has an invalid plugin version in ${t}`);if(!d(e.entries)||Object.keys(e.entries).length===0)throw new Error(`Facet bundle manifest has no entries in ${t}`);const n={};for(const[r,o]of Object.entries(e.entries)){if(r.length===0||!d(o))throw new Error(`Facet bundle manifest has an invalid entry in ${t}`);if(typeof o.file!="string")throw new Error(`Facet bundle entry ${r} has no file`);if(m(t,o.file,`entry ${r}`),typeof o.integrity!="string")throw new Error(`Facet bundle entry ${r} has no integrity`);if(j(o.integrity),!Array.isArray(o.externalImports)||o.externalImports.some(a=>typeof a!="string"))throw new Error(`Facet bundle entry ${r} has invalid external imports`);const i=Object.freeze([...o.externalImports]);if(new Set(i).size!==i.length)throw new Error(`Facet bundle entry ${r} has duplicate external imports`);if(o.sourceMap!==void 0){if(typeof o.sourceMap!="string")throw new Error(`Facet bundle entry ${r} has an invalid source map`);m(t,o.sourceMap,`entry ${r} source map`)}n[r]=Object.freeze({file:o.file,integrity:o.integrity,externalImports:i,...o.sourceMap===void 0?{}:{sourceMap:o.sourceMap}})}return Object.freeze({format:h,formatVersion:y,plugin:Object.freeze({id:e.plugin.id,...e.plugin.version===void 0?{}:{version:e.plugin.version}}),entries:Object.freeze(n)})}s(N,"validateManifest");function d(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}s(d,"isRecord");export{ae as createFacetBundleArtifactLoader,D as createFacetBundleLoader,ie as readFacetBundleArtifact,C as readFacetBundleManifest};
@@ -1,4 +0,0 @@
1
- var v=Object.defineProperty;var a=(e,t)=>v(e,"name",{value:t,configurable:!0});import{createHash as E,randomUUID as $}from"node:crypto";import{mkdir as O,readFile as T,rename as g,rm as F,stat as k,writeFile as M}from"node:fs/promises";import{basename as x,dirname as A,extname as P,join as d,relative as S,resolve as m,sep as _}from"node:path";import{build as z}from"esbuild";import{FACET_BUNDLE_FORMAT as C,FACET_BUNDLE_FORMAT_VERSION as I,FACET_BUNDLE_MANIFEST_FILE as j}from"./manifest.js";async function ee(e){U(e);const t=m(e.workingDirectory??process.cwd()),r=m(t,e.outdir),i=A(r);await O(i,{recursive:!0});const n=d(i,`.${x(r)}.tmp-${$()}`);await O(n);try{const s={};for(const[y,h]of Object.entries(e.entries).sort(([f],[c])=>f.localeCompare(c)))s[y]=await L({entryName:y,source:m(t,h),temporaryDirectory:n,workingDirectory:t,options:e});const u=Object.freeze({format:C,formatVersion:I,plugin:Object.freeze({id:e.plugin.id,...e.plugin.version===void 0?{}:{version:e.plugin.version}}),entries:Object.freeze(s)});return await M(d(n,j),`${JSON.stringify(u,null,2)}
2
- `),await R(n,r),Object.freeze({manifest:u,manifestPath:d(r,j)})}catch(s){throw await F(n,{force:!0,recursive:!0}),s}}a(ee,"bundleFacets");async function L(e){const t=`facet-${B(e.entryName)}`,r=e.options.platform??"node",i={absWorkingDir:e.workingDirectory,banner:{js:'"use strict";'},bundle:!0,define:e.options.define,entryNames:`${t}-[hash]`,entryPoints:[e.source],external:[...new Set(["@earendil-works/chord","@earendil-works/chord/*",...e.options.external??[]])],format:"cjs",legalComments:"none",logLevel:"silent",metafile:!0,minify:e.options.minify??!1,outdir:e.temporaryDirectory,outExtension:{".js":".cjs"},platform:r,sourcemap:e.options.sourceMap===!0?"external":!1,supported:{"dynamic-import":!1},target:e.options.target===void 0?r==="node"?"node22.19":"es2022":typeof e.options.target=="string"?e.options.target:[...e.options.target],write:!0};let n;try{n=await z(i)}catch(o){const p=J(o),N=p.length===0?"":`
3
- ${p.join(`
4
- `)}`;throw new Error(`Could not bundle facet entry ${e.entryName}${N}`,{cause:o})}const s=n.metafile;if(s===void 0)throw new Error(`Facet entry ${e.entryName} produced no build metadata`);const u=Object.entries(s.outputs).filter(([o,p])=>p.entryPoint!==void 0&&P(o)===".cjs");if(u.length!==1)throw new Error(`Facet entry ${e.entryName} did not produce exactly one JavaScript file`);const[y,h]=u[0],f=m(e.workingDirectory,y),c=S(e.temporaryDirectory,f);if(c.length===0||c.startsWith(`..${_}`)||x(c)!==c)throw new Error(`Facet entry ${e.entryName} produced an invalid output path`);const l=e.options.sourceMap===!0?`${c}.map`:void 0,b=new Set([f]);if(l!==void 0&&b.add(d(e.temporaryDirectory,l)),Object.keys(s.outputs).map(o=>m(e.workingDirectory,o)).filter(o=>!b.has(o)).length>0)throw new Error(`Facet entry ${e.entryName} produced files other than its JavaScript bundle and source map`);const D=await T(f);return l!==void 0&&await k(d(e.temporaryDirectory,l)),Object.freeze({file:c,integrity:`sha256-${E("sha256").update(D).digest("base64")}`,externalImports:Object.freeze([...new Set(h.imports.filter(({external:o})=>o).map(({path:o})=>o))].sort()),...l===void 0?{}:{sourceMap:l}})}a(L,"bundleEntry");function U(e){if(e.plugin.id.length===0)throw new TypeError("Facet bundle plugin ID must not be empty");if(e.plugin.version!==void 0&&e.plugin.version.length===0)throw new TypeError("Facet bundle plugin version must not be empty");const t=Object.entries(e.entries);if(t.length===0)throw new TypeError("Facet bundle must contain at least one entry");for(const[r,i]of t){if(r.length===0)throw new TypeError("Facet bundle entry name must not be empty");if(i.length===0)throw new TypeError(`Facet bundle entry ${r} must have a source path`)}for(const r of e.external??[])if(r.length===0)throw new TypeError("Facet bundle external import must not be empty")}a(U,"validateOptions");async function R(e,t){const r=`${t}.old-${$()}`;let i=!1;try{await g(t,r),i=!0}catch(n){if(!W(n))throw n}try{await g(e,t)}catch(n){throw i&&await g(r,t),n}i&&await F(r,{force:!0,recursive:!0})}a(R,"replaceDirectory");function B(e){return E("sha256").update(e).digest("hex").slice(0,12)}a(B,"shortHash");function J(e){return!w(e)||!Array.isArray(e.errors)?[]:e.errors.flatMap(t=>V(t)?[H(t)]:[])}a(J,"esbuildMessages");function H(e){const t=e.location;return t===null?e.text:`${t.file}:${t.line}:${t.column+1}: ${e.text}`}a(H,"formatEsbuildMessage");function V(e){return w(e)&&typeof e.text=="string"&&(e.location===null||w(e.location))}a(V,"isEsbuildMessage");function W(e){return w(e)&&e.code==="ENOENT"}a(W,"isMissingPath");function w(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}a(w,"isRecord");export{ee as bundleFacets};
@@ -1 +0,0 @@
1
- const t="chord.facet-bundle",_=2,o="chord-facets.json",A="chord.facet-bundle-artifact",E=2;export{A as FACET_BUNDLE_ARTIFACT_FORMAT,E as FACET_BUNDLE_ARTIFACT_FORMAT_VERSION,t as FACET_BUNDLE_FORMAT,_ as FACET_BUNDLE_FORMAT_VERSION,o as FACET_BUNDLE_MANIFEST_FILE};
@@ -1 +0,0 @@
1
- var b=Object.defineProperty;var c=(e,r)=>b(e,"name",{value:r,configurable:!0});import{readFile as F,realpath as h,stat as u}from"node:fs/promises";import{basename as $,dirname as E,isAbsolute as g,join as j,relative as w,resolve as d,sep as l}from"node:path";import{bundleFacets as O}from"./bundle.js";async function N(e){const r=await D(e.packagePath),o=await P(r,e.defaultFacets??{}),t=[...r.peerDependencies,...r.external].flatMap(n=>[n,`${n}/*`]),a=await O({plugin:{id:r.name,version:r.version},entries:o,outdir:e.outdir,workingDirectory:r.packageDirectory,external:t,sourceMap:r.sourceMap});return Object.freeze({...a,packageDirectory:r.packageDirectory,packageJsonPath:r.packageJsonPath})}c(N,"bundleFacetPackage");async function D(e){if(e.length===0)throw new TypeError("Facet package path must not be empty");const r=d(e);let o,t,a;try{a=await u(r)}catch(f){throw new Error(`Could not access facet package ${r}`,{cause:f})}if(a.isDirectory())o=await h(r),t=j(o,"package.json");else if(a.isFile()&&$(r)==="package.json")t=await h(r),o=E(t);else throw new Error(`Facet package path must name a directory or package.json: ${r}`);let n;try{n=JSON.parse(await F(t,"utf8"))}catch(f){throw new Error(`Could not read facet package metadata ${t}`,{cause:f})}if(!p(n))throw new Error(`Facet package metadata must be an object: ${t}`);if(typeof n.name!="string"||n.name.length===0)throw new Error(`Facet package must have a non-empty name: ${t}`);if(typeof n.version!="string"||n.version.length===0)throw new Error(`Facet package must have a non-empty version: ${t}`);const s=M(n.peerDependencies,t),i=x(n.chord,t);return{packageDirectory:o,packageJsonPath:t,name:n.name,version:n.version,peerDependencies:s,configuredFacets:i.facets,external:i.external,sourceMap:i.sourceMap}}c(D,"readFacetPackageMetadata");function M(e,r){if(e===void 0)return[];if(!p(e)||Object.entries(e).some(([o,t])=>o.length===0||typeof t!="string"))throw new Error(`Facet package has invalid peerDependencies: ${r}`);return Object.freeze(Object.keys(e).sort())}c(M,"parsePeerDependencies");function x(e,r){if(e===void 0)return{facets:Object.freeze({}),external:Object.freeze([]),sourceMap:!0};if(!p(e))throw new Error(`Facet package chord configuration must be an object: ${r}`);if(Object.keys(e).some(a=>a!=="facets"&&a!=="external"&&a!=="sourceMap"))throw new Error(`Facet package chord configuration has an unknown field: ${r}`);const o={};if(e.facets!==void 0){if(!p(e.facets))throw new Error(`Facet package chord.facets must be an object: ${r}`);for(const[a,n]of Object.entries(e.facets)){if(a.length===0||typeof n!="string"&&n!==!1||n==="")throw new Error(`Facet package has an invalid chord.facets entry: ${r}`);o[a]=n}}let t=[];if(e.external!==void 0){if(!Array.isArray(e.external)||e.external.some(a=>typeof a!="string"||a.length===0))throw new Error(`Facet package chord.external must contain non-empty strings: ${r}`);t=Object.freeze([...new Set(e.external)].sort())}if(e.sourceMap!==void 0&&typeof e.sourceMap!="boolean")throw new Error(`Facet package chord.sourceMap must be a boolean: ${r}`);return{facets:Object.freeze(o),external:t,sourceMap:e.sourceMap??!0}}c(x,"parseChordConfiguration");async function P(e,r){const o={};for(const[t,a]of Object.entries(r)){y(t,a,"default");const n=k(e.packageDirectory,a,t);try{if(!(await u(n)).isFile())throw new Error(`Default facet entry ${t} is not a file: ${n}`);const i=await h(n);m(e.packageDirectory,i,t),o[t]=i}catch(s){if(z(s))continue;throw s}}for(const[t,a]of Object.entries(e.configuredFacets)){if(a===!1){delete o[t];continue}y(t,a,"configured");const n=k(e.packageDirectory,a,t);let s;try{s=await u(n)}catch(f){throw new Error(`Could not access configured facet entry ${t}: ${n}`,{cause:f})}if(!s.isFile())throw new Error(`Configured facet entry ${t} is not a file: ${n}`);const i=await h(n);m(e.packageDirectory,i,t),o[t]=i}if(Object.keys(o).length===0)throw new Error(`Facet package ${e.name} has no configured or conventional facet entries`);return Object.freeze(o)}c(P,"resolveFacetEntries");function y(e,r,o){if(e.length===0)throw new Error(`Facet package ${o} entry name must not be empty`);if(r.length===0)throw new Error(`Facet package ${o} entry ${e} must have a source path`)}c(y,"validateFacetMapping");function k(e,r,o){if(g(r))throw new Error(`Facet package entry ${o} must be relative to the package directory`);const t=d(e,r),a=w(e,t);if(a.length===0||a===".."||a.startsWith(`..${l}`)||g(a))throw new Error(`Facet package entry ${o} escapes the package directory`);return t}c(k,"resolvePackageEntry");function m(e,r,o){const t=w(e,r);if(t===".."||t.startsWith(`..${l}`)||g(t))throw new Error(`Facet package entry ${o} resolves outside the package directory`)}c(m,"validateCanonicalPackageEntry");function z(e){return p(e)&&e.code==="ENOENT"}c(z,"isMissingPath");function p(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}c(p,"isRecord");export{N as bundleFacetPackage};
@@ -1 +0,0 @@
1
- import{createFacetBundleArtifactLoader as A,createFacetBundleLoader as _,readFacetBundleArtifact as E,readFacetBundleManifest as T}from"./node/bundle-loader.js";import{FACET_BUNDLE_ARTIFACT_FORMAT as t,FACET_BUNDLE_ARTIFACT_FORMAT_VERSION as r,FACET_BUNDLE_FORMAT as B,FACET_BUNDLE_FORMAT_VERSION as c,FACET_BUNDLE_MANIFEST_FILE as d}from"./node/manifest.js";export{t as FACET_BUNDLE_ARTIFACT_FORMAT,r as FACET_BUNDLE_ARTIFACT_FORMAT_VERSION,B as FACET_BUNDLE_FORMAT,c as FACET_BUNDLE_FORMAT_VERSION,d as FACET_BUNDLE_MANIFEST_FILE,A as createFacetBundleArtifactLoader,_ as createFacetBundleLoader,E as readFacetBundleArtifact,T as readFacetBundleManifest};
@@ -1 +0,0 @@
1
- var g=Object.defineProperty;var a=(o,e)=>g(o,"name",{value:e,configurable:!0});import{awaitWithContext as b,BACKGROUND_CONTEXT as l}from"../context/index.js";import{RemoteServiceError as d}from"./errors.js";import{ServiceSlot as y}from"./handle.js";import{InstanceDirectory as R}from"./instances.js";import{ReplicatedStateReplica as E,serviceDeliveryContext as m}from"./state.js";class k{static{a(this,"MemberSlot")}#s;#o;#a;#c;#h;#e;value;#i;#t;constructor(e,s,t,i,n,r){this.#s=e,this.#o=s,this.#a=t,this.#h=i,this.#e=n,this.#c=new E(r);const c=a(()=>{},"callable");this.value=new Proxy(c,{apply:a((h,f,p)=>this.#r(p),"apply"),get:a((h,f)=>{if(f==="value")return this.#e(),this.#d("state"),this.#c.value;if(f==="subscribe")return this.#n.bind(this);if(f===Symbol.toStringTag)return"RemoteServiceMember"},"get")})}setDescription(e){if(this.#i!==void 0&&this.#i!==e)throw new Error(`Remote service member ${this.#s}.${this.#o} changed kind`);if(this.#i=e,this.#t!==void 0&&this.#t!==e)throw new d("service_member_mismatch",`Remote service member ${this.#s}.${this.#o} is ${e}, not ${this.#t}`)}hydrate(e,s,t){this.setDescription("state"),this.#c.hydrate(e,s,t)}update(e,s,t){this.setDescription("state"),this.#c.update(e,s,t)}clear(){this.#c.clear()}#n(e){if(this.#e(),typeof e!="function")throw new TypeError("Replicated state subscription listener must be a function");return this.#d("state"),this.#c.subscribe(e)}#d(e){if(this.#t!==void 0&&this.#t!==e)throw new d("service_member_mismatch",`Remote service member ${this.#s}.${this.#o} was used as two different kinds`);if(this.#t=e,this.#i!==void 0&&this.#i!==e)throw new d("service_member_mismatch",`Remote service member ${this.#s}.${this.#o} is ${this.#i}, not ${e}`)}#r(e){if(this.#e(),this.#d("method"),!this.#h())return Promise.reject(new d("service_stale_instance",`Remote service ${this.#s} binding is closed`));const s=e.at(-1);if(!A(s))return Promise.reject(new d("service_invalid_value",`Remote service method ${this.#s}.${this.#o} requires a trailing Context`));const t=e.slice(0,-1);return this.#a(t,s)}}class w{static{a(this,"ServiceFacade")}#s;#o;#a;#c;#h=new Map;#e=new Map;#i;#t;proxy;constructor(e,s,t,i,n,r){this.#s=e,this.#o=s,this.#a=t,this.#i=i,this.#t=n,this.#c=r,this.proxy=new Proxy(Object.create(null),{get:a((c,h)=>{if(typeof h=="string")return this.#n(h).value},"get")})}install(e,s){if(!S(e.instance,this.#o))throw new Error("Remote service snapshot has the wrong address");const t=$(e.members);for(const i of this.#h.keys())if(!t.has(i))throw new d("service_member_not_found",`Unknown remote service member ${this.#s}.${i}`);this.#e.clear();for(const[i,n]of t)this.#e.set(i,n.kind);for(const i of t.values()){const n=this.#h.get(i.name);i.kind==="state"?(n??this.#n(i.name)).hydrate(i.sequence,i.ops,s):n?.setDescription(i.kind)}}update(e,s,t,i){if(this.#e.get(e)!=="state")throw new Error(`Remote service update targets non-state member ${this.#s}.${e}`);this.#n(e).update(s,t,i)}clear(){for(const e of this.#h.values())e.clear()}#n(e){let s=this.#h.get(e);if(s!==void 0)return s;s=new k(this.#s,e,(i,n)=>this.#a.invoke({serviceId:this.#s,...this.#o===void 0?{}:{instance:this.#o},member:e,args:i},n),this.#i,this.#t,this.#c);const t=this.#e.get(e);return t!==void 0&&s.setDescription(t),this.#h.set(e,s),s}}class _{static{a(this,"KeyedBinding")}#s;#o;#a;#c;#h;#e;#i;#t;#n=!1;#d;#r=0;constructor(e,s,t,i,n,r){this.#s=e,this.#o=s,this.#a=t,this.#c=i,this.#h=n,this.#d=r,this.#e=new R({ready:!1,onError:t})}observe(e){if(this.#n)throw new Error("Remote keyed service binding is closed");let s=!1;const t=this.#e.observe((i,n)=>{const r=new y(this.#s.id,!0);return r.bind(i),e(r.view(()=>{if(this.#c(),s||n.abortSignal?.aborted)throw new d("service_stale_instance",`Remote service ${this.#s.id} observation is closed`)}),n)});if(this.#d&&this.#t===void 0){const i=this.#r,n=this.#u(i);this.#t=n,n.catch(r=>{!this.#n&&this.#r===i&&this.#d&&this.#a(u(r))})}return()=>{s||(s=!0,t(),this.#e.observerCount===0&&this.#h())}}async rebind(e,s){if(this.#n)return;this.#d=e;const t=++this.#r;if(await this.#l(s,!1),!(this.#n||this.#r!==t||this.#d!==e)&&e&&this.#e.observerCount>0){const i=this.#u(t);this.#t=i,await i}}ready(){return this.#t??Promise.resolve()}async close(e){this.#n||(this.#n=!0,this.#r+=1,await this.#l(e,!0),this.#e.dispose())}async#l(e,s){this.#e.reset();const t=this.#t;this.#t=void 0;const i=this.#i;this.#i=void 0,await Promise.all([s?t?.catch(()=>{}):void 0,i===void 0?void 0:i.close(e)])}async#u(e){const s=await this.#o.subscribe(this.#s.id,"keyed",(t,i)=>{this.#r===e&&this.#m(t,i)},l);if(this.#n||!this.#d||this.#r!==e){await s.close(l);return}if(this.#i=s,s.snapshot.mode!=="keyed"||s.snapshot.serviceId!==this.#s.id)throw new Error(`Remote service ${this.#s.id} returned the wrong keyed snapshot`);for(const t of s.snapshot.instances)this.#f(t,m());s.activate(),this.#e.ready()}#m(e,s){if(!this.#n)try{switch(e.type){case"reset":{v(e.snapshot,this.#s.id,"keyed");const t=new Map(e.snapshot.instances.map(i=>[i.instance.key,i]));for(const i of[...this.#e.values()])t.get(i.key)?.instance?.generation!==i.generation&&this.#e.remove(i);for(const i of t.values()){const n=this.#e.get(i.instance.key);n===void 0?this.#f(i,s):n.facade.install(i,s)}break}case"unavailable":case"replaced":throw new Error("Keyed service received a singleton lifecycle update");case"spawned":this.#f(e.instance,s);break;case"closed":{const t=this.#e.get(e.instance.key);t?.generation===e.instance.generation&&this.#e.remove(t);break}case"state":{if(e.instance===void 0)throw new Error("Keyed state update has no instance address");const t=this.#e.get(e.instance.key);if(t?.generation!==e.instance.generation)return;t.facade.update(e.member,e.sequence,e.ops,s);break}}}catch(t){this.#a(u(t))}}#f(e,s){const t=e.instance;if(t===void 0)throw new Error("Keyed service instance snapshot has no address");let i=!0;const n=new w(this.#s.id,t,this.#o,()=>i&&!this.#n,this.#c,this.#a);n.install(e,s),this.#e.replace({key:t.key,generation:t.generation,service:n.proxy,facade:n,deactivate:a(()=>{i=!1,n.clear()},"deactivate")})}}class K{static{a(this,"RemoteServiceBindingImpl")}#s;#o=new Set;#a;#c=new Map;#h;#e=new Map;#i=new Map;#t;#n=0;#d=Promise.resolve();#r=!1;constructor(e){this.#s=e.transport;const s=e.services.map(({id:t})=>t);if(new Set(s).size!==s.length)throw new TypeError("Remote service binding has duplicate service IDs");for(const t of s)this.#o.add(t);this.#a=e.onError??(()=>{}),this.#h=e.assertAccess??(()=>{}),this.#t=e.bound??!0}use(e){this.#m(e),this.#f(e.id,"singleton");let s=this.#e.get(e.id);if(s!==void 0)return s.facade.proxy;if(s={facade:void 0,active:!0,revision:0},s.facade=new w(e.id,void 0,this.#s,()=>s.active&&!this.#r&&this.#t,()=>this.#u(),this.#a),this.#e.set(e.id,s),this.#n+=1,this.#t){const t=s.revision,i=this.#l(e.id,s,t);s.starting=i,i.catch(n=>{s.active&&s.revision===t&&!this.#r&&this.#t&&this.#a(u(n))})}return s.facade.proxy}observe(e,s){this.#m(e),this.#f(e.id,"keyed");let t=this.#i.get(e.id);return t===void 0&&(t=new _(e,this.#s,this.#a,()=>this.#u(),()=>{this.#i.get(e.id)===t&&(this.#i.delete(e.id),this.#n+=1,t.close(l).catch(this.#a))},this.#t),this.#i.set(e.id,t),this.#n+=1),t.observe(s)}async ready(e){if(this.#r)throw new Error("Remote service binding is disposed");for(;;){const s=this.#n,t=[this.#d,...[...this.#e.values()].flatMap(i=>i.starting===void 0?[]:[i.starting]),...[...this.#i.values()].map(i=>i.ready())];if(await b(Promise.all(t).then(()=>{}),e),this.#r)throw new Error("Remote service binding is disposed");if(s===this.#n)return}}async rebind(e,s){if(this.#r)throw new Error("Remote service binding is disposed");this.#t=e,this.#n+=1;const t=[];for(const[n,r]of this.#e){r.revision+=1,r.facade.clear();const c=r.subscription;delete r.subscription;const h=r.revision,f=(async()=>{await c?.close(s),e&&await this.#l(n,r,h)})();r.starting=f,t.push(f)}for(const n of this.#i.values())t.push(n.rebind(e,s));const i=(async()=>{const r=(await Promise.allSettled(t)).filter(c=>c.status==="rejected");if(r.length>0)throw new AggregateError(r.map(({reason:c})=>c),"Failed to rebind services")})();this.#d=i,await i}async dispose(e){if(this.#r)return;this.#r=!0;const s=[];for(const n of this.#e.values())n.active=!1,n.facade.clear(),n.starting&&s.push(n.starting.catch(()=>{})),n.subscription&&s.push(Promise.resolve(n.subscription.close(e)));for(const n of this.#i.values())s.push(n.close(e));this.#e.clear(),this.#i.clear();const i=(await Promise.allSettled(s)).filter(n=>n.status==="rejected");if(i.length>0)throw new AggregateError(i.map(({reason:n})=>n),"Failed to dispose services")}async#l(e,s,t){const i=await this.#s.subscribe(e,"singleton",(r,c)=>{if(!(!s.active||s.revision!==t))try{if(r.type==="reset"){v(r.snapshot,e,"singleton");const h=r.snapshot.instances[0];h===void 0?s.facade.clear():s.facade.install(h,c)}else if(r.type==="unavailable")s.facade.clear();else if(r.type==="replaced"){if(r.snapshot.instance!==void 0)throw new Error("Singleton replacement has an instance address");s.facade.install(r.snapshot,c)}else r.type==="state"&&r.instance===void 0&&s.facade.update(r.member,r.sequence,r.ops,c)}catch(h){this.#a(u(h))}},l);if(!s.active||this.#r||!this.#t||s.revision!==t){await i.close(l);return}s.subscription=i;const n=i.snapshot;if(n.mode!=="singleton"||n.serviceId!==e||n.instances.length!==1)throw new Error(`Remote service ${e} returned an invalid singleton snapshot`);s.facade.install(n.instances[0],m()),i.activate()}#u(){if(this.#r)throw new Error("Remote service binding is disposed");this.#h()}#m(e){if(e.local)throw new d("service_not_allowed",`Service ${e.id} is process-local`)}#f(e,s){if(this.#r)throw new Error("Remote service binding is disposed");if(!this.#o.has(e))throw new d("service_not_allowed",`Remote service ${e} is not allowlisted`);const t=this.#c.get(e);if(t!==void 0&&t!==s)throw new d("service_mode_mismatch",`Remote service ${e} is already used as ${t}`);this.#c.set(e,s)}}function v(o,e,s){if(o.serviceId!==e||o.mode!==s||s==="singleton"&&o.instances.length>1)throw new Error("Remote service reset has the wrong service or mode");const t=new Set;for(const i of o.instances){if(s==="singleton"?i.instance!==void 0:i.instance===void 0)throw new Error("Remote service reset has an invalid instance address");if(i.instance!==void 0){if(t.has(i.instance.key))throw new Error("Remote service reset repeats an instance key");t.add(i.instance.key)}for(const n of i.members)if(n.kind==="state"&&(n.ops.length!==1||n.ops[0]?.[0]!=="r"))throw new Error("Remote service reset must contain full root replacements")}}a(v,"validateResetSnapshot");function $(o){const e=new Map;for(const s of o){if(s.name.length===0||e.has(s.name))throw new Error("Remote service has invalid member descriptions");e.set(s.name,s)}return e}a($,"validateMembers");function S(o,e){return o===void 0||e===void 0?o===e:o.key===e.key&&o.generation===e.generation}a(S,"sameAddress");function A(o){if(typeof o!="object"||o===null)return!1;const e=o;return typeof e.value=="function"&&typeof e.toString=="function"}a(A,"isContext");function u(o){return o instanceof Error?o:new Error(String(o))}a(u,"toError");export{K as RemoteServiceBindingImpl};
@@ -1 +0,0 @@
1
- var s=Object.defineProperty;var o=(e,r)=>s(e,"name",{value:r,configurable:!0});const c=["service_not_allowed","service_not_found","service_mode_mismatch","service_member_not_found","service_member_mismatch","service_instance_not_found","service_stale_instance","service_invalid_value"];function n(e){return typeof e=="string"&&c.includes(e)}o(n,"isRemoteServiceErrorCode");class _ extends Error{static{o(this,"RemoteServiceError")}code;constructor(r,t){super(t),this.name="RemoteServiceError",this.code=r}}export{c as REMOTE_SERVICE_ERROR_CODES,_ as RemoteServiceError,n as isRemoteServiceErrorCode};
@@ -1 +0,0 @@
1
- var a=Object.defineProperty;var n=(o,e)=>a(o,"name",{value:e,configurable:!0});var c;class p{static{n(this,"ServiceSlot")}#e;#t;#r;constructor(e,r){this.#e=e,this.#t=r}view(e){return new f(this,e,this.#t).proxy}bind(e){this.#r=e}unbind(){this.#r=void 0}resolve(e,r){r();const t=this.#r;if(t===void 0)throw new Error(`Service ${this.#e} is disconnected`);return{value:Reflect.get(t,e,t),receiver:t}}}class f{static{n(this,"ServiceView")}#e;#t;#r;#i=new Map;proxy;constructor(e,r,t){this.#e=e,this.#t=r,this.#r=t,this.proxy=new Proxy(Object.create(null),{get:n((i,s)=>this.#n(s),"get")})}#n(e){const r=n(()=>this.#e.resolve(e,this.#t),"resolve"),t=r().value;if(!u(t)||typeof t!="function"&&!this.#r)return t;let i=this.#i.get(e);return i===void 0&&(i=new l(r,typeof t=="function"),this.#i.set(e,i)),i.proxy}}class l{static{n(this,"ValueView")}#e;#t=new Map;proxy;constructor(e,r){this.#e=e;const t=r?()=>{}:Object.create(null);this.proxy=new Proxy(t,{apply:n((i,s,h)=>this.#r(h),"apply"),get:n((i,s)=>this.#i(s),"get")})}#r(e){const{value:r,receiver:t}=this.#e();if(typeof r!="function")throw new TypeError("Service member is not callable");return Reflect.apply(r,t,e)}#i(e){const r=n(()=>{const s=this.#e();if(!u(s.value))throw new TypeError("Service member does not have properties");return{value:Reflect.get(s.value,e,s.value),receiver:s.value}},"resolve"),t=r().value;if(typeof t!="function")return t;let i=this.#t.get(e);return i===void 0&&(i=new c(r,!0),this.#t.set(e,i)),i.proxy}}c=l;function u(o){return typeof o=="object"&&o!==null||typeof o=="function"}n(u,"isObject");export{p as ServiceSlot};
@@ -1 +0,0 @@
1
- var c=Object.defineProperty;var o=(r,e)=>c(r,"name",{value:e,configurable:!0});import{BACKGROUND_CONTEXT as n,withCancel as f}from"../context/index.js";class u{static{o(this,"InstanceDirectory")}#e=new Map;#s=new Set;#o;#t;#r=!1;constructor(e){this.#t=e.ready,this.#o=e.onError}get observerCount(){return this.#s.size}values(){return this.#e.values()}get(e){return this.#e.get(e)}insert(e){if(this.#i(),this.#e.has(e.key))throw new Error(`Keyed service already has a live instance with key ${e.key}`);this.#e.set(e.key,e),this.#t&&this.#h(e)}replace(e){this.#i();const s=this.#e.get(e.key);if(s!==void 0){if(s.generation===e.generation)throw new Error("Keyed service repeated a live generation");this.#a(s)}this.#e.set(e.key,e),this.#t&&this.#h(e)}remove(e){this.#e.get(e.key)===e&&this.#a(e)}ready(){if(this.#i(),!this.#t){this.#t=!0;for(const e of this.#e.values())this.#h(e)}}reset(){if(!this.#r){this.#t=!1;for(const e of[...this.#e.values()])this.#a(e)}}observe(e){this.#i();const s={handler:e,tasks:new Map,closed:!1};if(this.#s.add(s),this.#t)for(const t of this.#e.values())this.#c(s,t);return()=>{if(!s.closed){s.closed=!0;for(const t of s.tasks.values())t.cancel();s.tasks.clear(),this.#s.delete(s)}}}dispose(){if(!this.#r){this.#r=!0;for(const e of this.#s){e.closed=!0;for(const s of e.tasks.values())s.cancel();e.tasks.clear()}this.#s.clear();for(const e of[...this.#e.values()])e.deactivate();this.#e.clear()}}#a(e){if(this.#e.get(e.key)===e){this.#e.delete(e.key),e.deactivate();for(const s of this.#s)s.tasks.get(e)?.cancel(),s.tasks.delete(e)}}#h(e){for(const s of this.#s)this.#c(s,e)}#c(e,s){if(e.closed||e.tasks.has(s))return;const{context:t,cancel:h}=f(n);e.tasks.set(s,{cancel:h});try{Promise.resolve(e.handler(s.service,t)).catch(i=>{t.abortSignal?.aborted||this.#o(a(i))})}catch(i){t.abortSignal?.aborted||this.#o(a(i))}}#i(){if(this.#r)throw new Error("Keyed service directory is disposed")}}function a(r){return r instanceof Error?r:new Error(String(r))}o(a,"toError");export{u as InstanceDirectory};