dal-code 1.0.8 → 1.0.10
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.
- package/CHANGELOG.md +39 -53
- package/dist/core/keybindings.d.ts +1 -1
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +1 -1
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-config.d.ts +85 -0
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +19 -14
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/session-manager.d.ts +7 -0
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +28 -0
- package/dist/core/session-manager.js.map +1 -1
- package/dist/extensions/llama/client.d.ts +2 -0
- package/dist/extensions/llama/client.d.ts.map +1 -1
- package/dist/extensions/llama/client.js +7 -3
- package/dist/extensions/llama/client.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +20 -5
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +5 -6
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +2 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +31 -21
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/node_modules/@dalcode/dal-bridge/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-gateway/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-guard/package.json +5 -5
- package/dist/node_modules/@dalcode/dal-halo/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-lang/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-lsp/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-mcp/package.json +6 -6
- package/dist/node_modules/@dalcode/dal-office/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-skills/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-subagent/package.json +6 -6
- package/dist/node_modules/@dalcode/dal-telemetry/package.json +3 -3
- package/dist/node_modules/@dalcode/deepailab/package.json +4 -4
- package/dist/node_modules/@earendil-works/chord/LICENSE +21 -0
- package/dist/node_modules/@earendil-works/chord/README.md +205 -0
- package/dist/node_modules/@earendil-works/chord/dist/api.d.ts +15 -0
- package/dist/node_modules/@earendil-works/chord/dist/api.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/api.js +72 -0
- package/dist/node_modules/@earendil-works/chord/dist/api.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/bundler.d.ts +6 -0
- package/dist/node_modules/@earendil-works/chord/dist/bundler.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/bundler.js +3 -0
- package/dist/node_modules/@earendil-works/chord/dist/bundler.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/context/index.d.ts +24 -0
- package/dist/node_modules/@earendil-works/chord/dist/context/index.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/context/index.js +97 -0
- package/dist/node_modules/@earendil-works/chord/dist/context/index.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/delta/index.d.ts +119 -0
- package/dist/node_modules/@earendil-works/chord/dist/delta/index.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/delta/index.js +1906 -0
- package/dist/node_modules/@earendil-works/chord/dist/delta/index.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/facets/host.d.ts +12 -0
- package/dist/node_modules/@earendil-works/chord/dist/facets/host.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/facets/host.js +763 -0
- package/dist/node_modules/@earendil-works/chord/dist/facets/host.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/facets/loader.d.ts +3 -0
- package/dist/node_modules/@earendil-works/chord/dist/facets/loader.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/facets/loader.js +5 -0
- package/dist/node_modules/@earendil-works/chord/dist/facets/loader.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/index.d.ts +11 -0
- package/dist/node_modules/@earendil-works/chord/dist/index.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/index.js +10 -0
- package/dist/node_modules/@earendil-works/chord/dist/index.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/json.d.ts +4 -0
- package/dist/node_modules/@earendil-works/chord/dist/json.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/json.js +57 -0
- package/dist/node_modules/@earendil-works/chord/dist/json.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/bundle-loader.d.ts +30 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/bundle-loader.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/bundle-loader.js +377 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/bundle-loader.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/bundle.d.ts +26 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/bundle.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/bundle.js +183 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/bundle.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/manifest.d.ts +36 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/manifest.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/manifest.js +6 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/manifest.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/package.d.ts +15 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/package.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/package.js +199 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/package.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/node.d.ts +5 -0
- package/dist/node_modules/@earendil-works/chord/dist/node.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/node.js +3 -0
- package/dist/node_modules/@earendil-works/chord/dist/node.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/consumer.d.ts +11 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/consumer.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/consumer.js +537 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/consumer.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/errors.d.ts +8 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/errors.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/errors.js +22 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/errors.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/handle.d.ts +15 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/handle.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/handle.js +99 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/handle.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/instances.d.ts +25 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/instances.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/instances.js +137 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/instances.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/loopback.d.ts +5 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/loopback.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/loopback.js +15 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/loopback.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/provider.d.ts +37 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/provider.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/provider.js +472 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/provider.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state-codec.d.ts +15 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state-codec.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state-codec.js +115 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state-codec.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state-internals.d.ts +11 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state-internals.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state-internals.js +10 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state-internals.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state.d.ts +23 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state.js +124 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/wire.d.ts +60 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/wire.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/wire.js +173 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/wire.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/types.d.ts +203 -0
- package/dist/node_modules/@earendil-works/chord/dist/types.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/types.js +2 -0
- package/dist/node_modules/@earendil-works/chord/dist/types.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/package.json +62 -0
- package/dist/node_modules/@earendil-works/chord/src/delta/README.md +404 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-ai/README.md +3 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +15 -6
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.js +9 -66
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-shared.d.ts +12 -3
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-shared.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-shared.js +50 -3
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-shared.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js +13 -58
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js +5 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js +6 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts +30 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +34 -4
- package/dist/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/deepseek.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openai-codex.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-cn.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/zai.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/types.d.ts +4 -2
- package/dist/node_modules/@earendil-works/pi-ai/dist/types.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/types.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/overflow.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +8 -3
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +2 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/retry.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-client/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-protocol/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-server/CHANGELOG.md +57 -0
- package/dist/node_modules/@earendil-works/pi-server/LICENSE +21 -0
- package/dist/node_modules/@earendil-works/pi-server/README.md +79 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/cli.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/cli.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/cli.js +136 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/cli.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/config.d.ts +12 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/config.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/config.js +55 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/config.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/connection.d.ts +35 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/connection.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/connection.js +4 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/connection.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/errors.d.ts +25 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/errors.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/errors.js +41 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/errors.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/handler.d.ts +14 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/handler.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/handler.js +105 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/handler.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/index.d.ts +5 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/index.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/index.js +5 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/index.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/client.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/client.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/client.js +56 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/client.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/protocol.d.ts +99 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/protocol.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/protocol.js +12 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/protocol.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/server.d.ts +20 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/server.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/server.js +145 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/server.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/listener.d.ts +8 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/listener.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/listener.js +2 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/listener.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/protocol.d.ts +22 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/protocol.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/protocol.js +266 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/protocol.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/radius.d.ts +36 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/radius.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/radius.js +360 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/radius.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/rpc-process.d.ts +31 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/rpc-process.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/rpc-process.js +168 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/rpc-process.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/serve.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/serve.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/serve.js +70 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/serve.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/server.d.ts +46 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/server.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/server.js +549 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/server.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/session-router.d.ts +40 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/session-router.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/session-router.js +264 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/session-router.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/sessions.d.ts +2195 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/sessions.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/sessions.js +332 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/sessions.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/snapshots.d.ts +24 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/snapshots.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/snapshots.js +39 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/snapshots.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/storage.d.ts +10 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/storage.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/storage.js +58 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/storage.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/supervisor.d.ts +34 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/supervisor.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/supervisor.js +290 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/supervisor.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/client.d.ts +35 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/client.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/client.js +138 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/client.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/host.d.ts +57 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/host.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/host.js +189 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/host.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/index.d.ts +6 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/index.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/index.js +4 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/index.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/server.d.ts +13 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/server.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/server.js +17 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/server.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/service.d.ts +66 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/service.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/service.js +254 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/service.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/address.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/address.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/address.js +9 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/address.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/index.d.ts +5 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/index.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/index.js +4 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/index.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/listener.d.ts +24 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/listener.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/listener.js +421 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/listener.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/preset.d.ts +7 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/preset.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/preset.js +22 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/preset.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/types.d.ts +15 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/types.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/types.js +2 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/types.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/types.d.ts +49 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/types.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/types.js +2 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/types.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/package.json +45 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/CHANGELOG.md +46 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/LICENSE +21 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/README.md +33 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/index.d.ts +6 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/index.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/index.js +103 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/index.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/branch-cache.d.ts +6 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/branch-cache.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/branch-cache.js +70 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/branch-cache.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/index.d.ts +5 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/index.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/index.js +4 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/index.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/migrations/001_initial.sql +121 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/migrations.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/migrations.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/migrations.js +7 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/migrations.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/repo.d.ts +41 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/repo.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/repo.js +408 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/repo.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/search-backend.d.ts +14 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/search-backend.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/search-backend.js +153 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/search-backend.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/branch-entries.d.ts +6 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/branch-entries.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/branch-entries.js +213 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/branch-entries.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/entries.d.ts +24 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/entries.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/entries.js +126 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/entries.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-row.d.ts +23 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-row.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-row.js +69 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-row.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-sequences.d.ts +4 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-sequences.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-sequences.js +13 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-sequences.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-stats.d.ts +6 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-stats.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-stats.js +39 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-stats.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/usage-ledger.d.ts +20 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/usage-ledger.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/usage-ledger.js +50 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/usage-ledger.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/values.d.ts +23 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/values.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/values.js +91 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/values.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session.d.ts +42 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session.js +163 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/sql.d.ts +19 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/sql.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/sql.js +58 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/sql.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-entries.d.ts +41 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-entries.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-entries.js +112 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-entries.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-tips.d.ts +7 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-tips.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-tips.js +22 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-tips.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/entries.d.ts +34 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/entries.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/entries.js +37 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/entries.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/facts.d.ts +20 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/facts.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/facts.js +38 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/facts.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/lanes.d.ts +35 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/lanes.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/lanes.js +95 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/lanes.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/records.d.ts +38 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/records.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/records.js +49 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/records.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-sequences.d.ts +7 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-sequences.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-sequences.js +22 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-sequences.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-stats.d.ts +17 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-stats.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-stats.js +40 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-stats.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/sessions.d.ts +26 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/sessions.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/sessions.js +99 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/sessions.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/writer-leases.d.ts +15 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/writer-leases.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/writer-leases.js +31 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/writer-leases.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage.d.ts +38 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage.js +161 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/types.d.ts +29 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/types.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/types.js +2 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/types.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/package.json +33 -0
- package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/official/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/plugins/pi-example-plugin/package.json +1 -1
- package/npm-shrinkwrap.json +3 -14
- package/package.json +2 -2
|
@@ -0,0 +1,1906 @@
|
|
|
1
|
+
// ─── Classification ──────────────────────────────────────────────────────────
|
|
2
|
+
export const isReplace = (op) => op[0] === "r";
|
|
3
|
+
/**
|
|
4
|
+
* A batch begins with a replacement. Flush guarantees `r` is at index 0 or absent,
|
|
5
|
+
* so this is exact rather than a heuristic.
|
|
6
|
+
*/
|
|
7
|
+
export const isBase = (ops) => ops.length > 0 && ops[0][0] === "r";
|
|
8
|
+
// ─── Overlap ─────────────────────────────────────────────────────────────────
|
|
9
|
+
/**
|
|
10
|
+
* Longest suffix of `a` that is a prefix of `b`. Probes with indexOf and verifies
|
|
11
|
+
* exact substring equality, so the hot loops are native. A hand-written KMP is
|
|
12
|
+
* asymptotically equivalent and much slower in practice.
|
|
13
|
+
*
|
|
14
|
+
* Always correct: the returned n satisfies a.slice(a.length - n) === b.slice(0, n).
|
|
15
|
+
*/
|
|
16
|
+
export function overlap(a, b, scan, probe = 64, maxCandidates = 8) {
|
|
17
|
+
if (a.length === 0 || b.length === 0 || scan === 0)
|
|
18
|
+
return 0;
|
|
19
|
+
const tail = a.length > scan ? a.slice(a.length - scan) : a;
|
|
20
|
+
// A probe of length h can only find overlaps of at least h — the head must
|
|
21
|
+
// actually occur in `a`. So try a long head first (few candidates, and it
|
|
22
|
+
// catches the large overlaps a rolling window produces), then fall back to one
|
|
23
|
+
// character, which finds any overlap at the cost of more candidates.
|
|
24
|
+
//
|
|
25
|
+
// Candidates are bounded because repetitive output — a build log, or any run of
|
|
26
|
+
// one character — makes a long head match at thousands of positions. Giving up
|
|
27
|
+
// returns 0, which emits a set: larger, never wrong.
|
|
28
|
+
for (const h of [Math.min(probe, b.length), 1]) {
|
|
29
|
+
const head = b.slice(0, h);
|
|
30
|
+
let tried = 0;
|
|
31
|
+
for (let k = tail.indexOf(head); k !== -1; k = tail.indexOf(head, k + 1)) {
|
|
32
|
+
if (++tried > maxCandidates)
|
|
33
|
+
break;
|
|
34
|
+
const n = tail.length - k;
|
|
35
|
+
if (n <= b.length && tail.slice(k) === b.slice(0, n))
|
|
36
|
+
return n;
|
|
37
|
+
}
|
|
38
|
+
if (h === 1)
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
return 0;
|
|
42
|
+
}
|
|
43
|
+
const isObj = (value) => value !== null && typeof value === "object";
|
|
44
|
+
const cloneJson = (value) => {
|
|
45
|
+
if (!isObj(value))
|
|
46
|
+
return value;
|
|
47
|
+
if (Array.isArray(value))
|
|
48
|
+
return value.map((item) => cloneJson(item));
|
|
49
|
+
// Spread preserves compact object layouts instead of reserving extra slots
|
|
50
|
+
// while growing an empty object. Both branches create own writable properties.
|
|
51
|
+
const result = (Object.getPrototypeOf(value) === null ? Object.assign(Object.create(null), value) : { ...value });
|
|
52
|
+
for (const key of Object.keys(result)) {
|
|
53
|
+
const child = result[key];
|
|
54
|
+
if (isObj(child))
|
|
55
|
+
result[key] = cloneJson(child);
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
};
|
|
59
|
+
const INDEX = /^(?:0|[1-9]\d*)$/;
|
|
60
|
+
const norm = (target, key) => typeof key === "symbol" ? key : Array.isArray(target) && INDEX.test(key) ? Number(key) : key;
|
|
61
|
+
const MUTATORS = new Set(["push", "pop", "shift", "unshift", "splice", "sort", "reverse", "fill", "copyWithin"]);
|
|
62
|
+
const MISSING = Symbol("missing");
|
|
63
|
+
const spliceItems = (target, index, remove, items) => {
|
|
64
|
+
const removed = Reflect.apply(Array.prototype.splice, target, [index, remove]);
|
|
65
|
+
// 1_000-item chunks: apply() argument counts past ~5-10k overflow the call
|
|
66
|
+
// stack on arm64 (CI runners), well before V8's documented 65k limit.
|
|
67
|
+
const chunkSize = 1_000;
|
|
68
|
+
for (let offset = 0; offset < items.length; offset += chunkSize) {
|
|
69
|
+
Reflect.apply(Array.prototype.splice, target, [index + offset, 0, ...items.slice(offset, offset + chunkSize)]);
|
|
70
|
+
}
|
|
71
|
+
return removed;
|
|
72
|
+
};
|
|
73
|
+
const jsonEqual = (left, right) => {
|
|
74
|
+
if (left === right)
|
|
75
|
+
return true;
|
|
76
|
+
if (!isObj(left) || !isObj(right) || Array.isArray(left) !== Array.isArray(right))
|
|
77
|
+
return false;
|
|
78
|
+
if (Array.isArray(left) && Array.isArray(right)) {
|
|
79
|
+
if (left.length !== right.length)
|
|
80
|
+
return false;
|
|
81
|
+
for (let index = 0; index < left.length; index++) {
|
|
82
|
+
if (!jsonEqual(left[index], right[index]))
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
const leftObject = left;
|
|
88
|
+
const rightObject = right;
|
|
89
|
+
const leftKeys = Object.keys(leftObject);
|
|
90
|
+
const rightKeys = Object.keys(rightObject);
|
|
91
|
+
if (leftKeys.length !== rightKeys.length)
|
|
92
|
+
return false;
|
|
93
|
+
for (const key of leftKeys) {
|
|
94
|
+
if (!Object.hasOwn(rightObject, key) || !jsonEqual(leftObject[key], rightObject[key]))
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
return true;
|
|
98
|
+
};
|
|
99
|
+
const emitSet = (path, value, out) => {
|
|
100
|
+
const snapshot = cloneJson(value);
|
|
101
|
+
if (path.length === 0)
|
|
102
|
+
out.push(["r", snapshot]);
|
|
103
|
+
else
|
|
104
|
+
out.push(["s", [...path], snapshot]);
|
|
105
|
+
};
|
|
106
|
+
const emitDelete = (path, out) => {
|
|
107
|
+
if (path.length === 0)
|
|
108
|
+
throw new TypeError("the tracked root cannot be deleted");
|
|
109
|
+
out.push(["d", [...path]]);
|
|
110
|
+
};
|
|
111
|
+
const diffString = (before, after, path, scan, out) => {
|
|
112
|
+
if (before === after)
|
|
113
|
+
return;
|
|
114
|
+
if (path.length === 0) {
|
|
115
|
+
emitSet(path, after, out);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const at = [...path];
|
|
119
|
+
// NOT `after.startsWith(before)`. `after` is usually a cons string — the
|
|
120
|
+
// producer just did `s += chunk` — and V8's startsWith walks a cons char by
|
|
121
|
+
// char. `slice(...) === before` flattens once and compares with memcmp.
|
|
122
|
+
// Measured on a 200 KB string growing by 8 bytes per flush: 845 us -> 42 us.
|
|
123
|
+
if (after.length > before.length && after.slice(0, before.length) === before) {
|
|
124
|
+
out.push(["a", at, after.slice(before.length)]);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const shared = overlap(before, after, scan);
|
|
128
|
+
if (shared === 0) {
|
|
129
|
+
out.push(["s", at, after]);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
out.push(["t", at, before.length - shared]);
|
|
133
|
+
if (after.length > shared)
|
|
134
|
+
out.push(["a", at, after.slice(shared)]);
|
|
135
|
+
};
|
|
136
|
+
const diffValue = (before, after, path, scan, out) => {
|
|
137
|
+
if (before === MISSING) {
|
|
138
|
+
if (after !== MISSING)
|
|
139
|
+
emitSet(path, after, out);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (after === MISSING) {
|
|
143
|
+
emitDelete(path, out);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (before === after)
|
|
147
|
+
return;
|
|
148
|
+
if (typeof before === "string" && typeof after === "string") {
|
|
149
|
+
diffString(before, after, path, scan, out);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (Array.isArray(before) && Array.isArray(after)) {
|
|
153
|
+
diffArray(before, after, path, scan, out);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (isObj(before) && isObj(after) && !Array.isArray(before) && !Array.isArray(after)) {
|
|
157
|
+
diffObject(before, after, path, scan, out);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
emitSet(path, after, out);
|
|
161
|
+
};
|
|
162
|
+
function diffObject(before, after, path, scan, out) {
|
|
163
|
+
if ([...Object.keys(before), ...Object.keys(after)].some((key) => RESERVED_SEGMENTS.has(key))) {
|
|
164
|
+
emitSet(path, after, out);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
for (const key of Object.keys(after)) {
|
|
168
|
+
diffValue(Object.hasOwn(before, key) ? before[key] : MISSING, after[key], [...path, key], scan, out);
|
|
169
|
+
}
|
|
170
|
+
for (const key of Object.keys(before)) {
|
|
171
|
+
if (!Object.hasOwn(after, key))
|
|
172
|
+
emitDelete([...path, key], out);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function diffArray(before, after, path, scan, out) {
|
|
176
|
+
if (before.length === after.length) {
|
|
177
|
+
for (let index = 0; index < after.length; index++) {
|
|
178
|
+
diffValue(before[index], after[index], [...path, index], scan, out);
|
|
179
|
+
}
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
let prefix = 0;
|
|
183
|
+
while (prefix < before.length && prefix < after.length && jsonEqual(before[prefix], after[prefix]))
|
|
184
|
+
prefix++;
|
|
185
|
+
let suffix = 0;
|
|
186
|
+
while (suffix < before.length - prefix &&
|
|
187
|
+
suffix < after.length - prefix &&
|
|
188
|
+
jsonEqual(before[before.length - 1 - suffix], after[after.length - 1 - suffix])) {
|
|
189
|
+
suffix++;
|
|
190
|
+
}
|
|
191
|
+
const shorter = Math.min(before.length, after.length);
|
|
192
|
+
if (prefix + suffix === shorter) {
|
|
193
|
+
const remove = before.length - prefix - suffix;
|
|
194
|
+
const items = after.slice(prefix, after.length - suffix);
|
|
195
|
+
if (prefix === 0 && remove === before.length)
|
|
196
|
+
emitSet(path, after, out);
|
|
197
|
+
else
|
|
198
|
+
out.push(["p", [...path], prefix, remove, cloneJson(items)]);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
// Structural movement combined with retained-index edits has no unique
|
|
202
|
+
// alignment. Preserve the retained index deltas and express only the tail
|
|
203
|
+
// length change structurally. It may be broader than the producer's intent,
|
|
204
|
+
// but never degrades those edits to a whole-array replacement.
|
|
205
|
+
for (let index = 0; index < shorter; index++) {
|
|
206
|
+
diffValue(before[index], after[index], [...path, index], scan, out);
|
|
207
|
+
}
|
|
208
|
+
if (after.length > before.length) {
|
|
209
|
+
out.push(["p", [...path], before.length, 0, cloneJson(after.slice(before.length))]);
|
|
210
|
+
}
|
|
211
|
+
else if (before.length > after.length) {
|
|
212
|
+
if (after.length === 0)
|
|
213
|
+
emitSet(path, after, out);
|
|
214
|
+
else
|
|
215
|
+
out.push(["p", [...path], after.length, before.length - after.length, []]);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
export function track(root, options = {}) {
|
|
219
|
+
const scan = options.maxOverlapScan ?? 65_536;
|
|
220
|
+
let log = [];
|
|
221
|
+
let trie = {};
|
|
222
|
+
let nextOrder = 0;
|
|
223
|
+
let tombstones = 0;
|
|
224
|
+
let liveSlots = 0;
|
|
225
|
+
let nodeCount = 1;
|
|
226
|
+
let lastAddedSlot;
|
|
227
|
+
let hasPending = false;
|
|
228
|
+
let forceBase = true;
|
|
229
|
+
const clearPending = () => {
|
|
230
|
+
log = [];
|
|
231
|
+
trie = {};
|
|
232
|
+
nextOrder = 0;
|
|
233
|
+
tombstones = 0;
|
|
234
|
+
liveSlots = 0;
|
|
235
|
+
nodeCount = 1;
|
|
236
|
+
lastAddedSlot = undefined;
|
|
237
|
+
hasPending = false;
|
|
238
|
+
};
|
|
239
|
+
const logNode = (path) => {
|
|
240
|
+
let at = trie;
|
|
241
|
+
for (const segment of path) {
|
|
242
|
+
if (!at.kids)
|
|
243
|
+
at.kids = new Map();
|
|
244
|
+
let next = at.kids.get(segment);
|
|
245
|
+
if (next === undefined) {
|
|
246
|
+
next = {};
|
|
247
|
+
at.kids.set(segment, next);
|
|
248
|
+
nodeCount++;
|
|
249
|
+
}
|
|
250
|
+
at = next;
|
|
251
|
+
}
|
|
252
|
+
return at;
|
|
253
|
+
};
|
|
254
|
+
const findLogNode = (path) => {
|
|
255
|
+
let at = trie;
|
|
256
|
+
for (const segment of path) {
|
|
257
|
+
const next = at.kids?.get(segment);
|
|
258
|
+
if (next === undefined)
|
|
259
|
+
return undefined;
|
|
260
|
+
at = next;
|
|
261
|
+
}
|
|
262
|
+
return at;
|
|
263
|
+
};
|
|
264
|
+
const compactLog = () => {
|
|
265
|
+
if (tombstones < 1_024 || tombstones * 2 < log.length)
|
|
266
|
+
return;
|
|
267
|
+
const compacted = [];
|
|
268
|
+
for (const slot of log) {
|
|
269
|
+
if (slot === undefined)
|
|
270
|
+
continue;
|
|
271
|
+
slot.index = compacted.length;
|
|
272
|
+
compacted.push(slot);
|
|
273
|
+
}
|
|
274
|
+
log = compacted;
|
|
275
|
+
tombstones = 0;
|
|
276
|
+
};
|
|
277
|
+
const killSlot = (slot) => {
|
|
278
|
+
if (slot.dead)
|
|
279
|
+
return;
|
|
280
|
+
slot.dead = true;
|
|
281
|
+
liveSlots--;
|
|
282
|
+
if (log[slot.index] === slot) {
|
|
283
|
+
log[slot.index] = undefined;
|
|
284
|
+
tombstones++;
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
const liveSlot = (at) => {
|
|
288
|
+
const slots = at.slots;
|
|
289
|
+
if (slots === undefined)
|
|
290
|
+
return undefined;
|
|
291
|
+
while (slots.length > 0 && slots[slots.length - 1].dead)
|
|
292
|
+
slots.pop();
|
|
293
|
+
if (slots.length === 0) {
|
|
294
|
+
at.slots = undefined;
|
|
295
|
+
return undefined;
|
|
296
|
+
}
|
|
297
|
+
return slots[slots.length - 1];
|
|
298
|
+
};
|
|
299
|
+
const killHere = (at) => {
|
|
300
|
+
if (at.slots === undefined)
|
|
301
|
+
return;
|
|
302
|
+
for (const slot of at.slots)
|
|
303
|
+
killSlot(slot);
|
|
304
|
+
at.slots = undefined;
|
|
305
|
+
};
|
|
306
|
+
const addSlot = (at, slot) => {
|
|
307
|
+
compactLog();
|
|
308
|
+
slot.order = nextOrder++;
|
|
309
|
+
slot.index = log.length;
|
|
310
|
+
at.lastOrder = slot.order;
|
|
311
|
+
if (at.slots === undefined)
|
|
312
|
+
at.slots = [];
|
|
313
|
+
at.slots.push(slot);
|
|
314
|
+
log.push(slot);
|
|
315
|
+
liveSlots++;
|
|
316
|
+
lastAddedSlot = slot;
|
|
317
|
+
};
|
|
318
|
+
const collapsePending = () => {
|
|
319
|
+
// Long mutation windows can otherwise retain operations and retired path
|
|
320
|
+
// generations indefinitely. Fall back to a complete snapshot once either
|
|
321
|
+
// history exceeds a bounded coalescing window. Payload bytes and transient
|
|
322
|
+
// allocation remain workload-dependent.
|
|
323
|
+
if (forceBase || (liveSlots <= 4_096 && nodeCount <= 4_096))
|
|
324
|
+
return;
|
|
325
|
+
const value = cloneJson(root);
|
|
326
|
+
clearPending();
|
|
327
|
+
hasPending = true;
|
|
328
|
+
addSlot(trie, { op: ["r", value], dead: false, order: 0, index: 0 });
|
|
329
|
+
};
|
|
330
|
+
const killSubtree = (at) => {
|
|
331
|
+
killHere(at);
|
|
332
|
+
if (at.kids !== undefined) {
|
|
333
|
+
for (const child of at.kids.values())
|
|
334
|
+
killSubtree(child);
|
|
335
|
+
at.kids = undefined;
|
|
336
|
+
}
|
|
337
|
+
if (at.retiredKids !== undefined) {
|
|
338
|
+
for (const generation of at.retiredKids) {
|
|
339
|
+
for (const child of generation.values())
|
|
340
|
+
killSubtree(child);
|
|
341
|
+
}
|
|
342
|
+
at.retiredKids = undefined;
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
const retireKids = (at) => {
|
|
346
|
+
if (at.kids === undefined)
|
|
347
|
+
return;
|
|
348
|
+
if (at.retiredKids === undefined)
|
|
349
|
+
at.retiredKids = [];
|
|
350
|
+
at.retiredKids.push(at.kids);
|
|
351
|
+
at.kids = undefined;
|
|
352
|
+
};
|
|
353
|
+
// Deepest live ancestor op carrying a payload we can fold a later write into.
|
|
354
|
+
// `s`/`r` carry the whole subtree; `p` carries the items it inserted, so a
|
|
355
|
+
// write to one of those indices belongs inside the payload rather than after it.
|
|
356
|
+
const foldTarget = (path) => {
|
|
357
|
+
let at = trie;
|
|
358
|
+
let found;
|
|
359
|
+
let ancestorMax = -1;
|
|
360
|
+
for (let depth = 0; depth < path.length; depth++) {
|
|
361
|
+
if (found !== undefined && at.lastOrder !== undefined && at.lastOrder > found.slot.order) {
|
|
362
|
+
found = undefined;
|
|
363
|
+
}
|
|
364
|
+
const slot = liveSlot(at);
|
|
365
|
+
// A fold is sound only if nothing has been recorded at this path or above it
|
|
366
|
+
// since: a later op there (a splice on the same array, a replacement of an
|
|
367
|
+
// ancestor) would have to apply after this write, not before it. Writes to
|
|
368
|
+
// other branches are irrelevant, which is why this is not "the most recent op".
|
|
369
|
+
if (slot !== undefined && slot.order >= ancestorMax && at.lastOrder === slot.order) {
|
|
370
|
+
if (slot.op[0] === "s" || slot.op[0] === "r")
|
|
371
|
+
found = { slot, depth };
|
|
372
|
+
else if (slot.op[0] === "p") {
|
|
373
|
+
const index = path[depth];
|
|
374
|
+
const items = slot.op[4];
|
|
375
|
+
if (typeof index === "number" && index >= slot.op[2] && index < slot.op[2] + items.length) {
|
|
376
|
+
found = { slot, depth: depth + 1, item: index - slot.op[2] };
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if (at.lastOrder !== undefined && at.lastOrder > ancestorMax)
|
|
381
|
+
ancestorMax = at.lastOrder;
|
|
382
|
+
const next = at.kids?.get(path[depth]);
|
|
383
|
+
if (next === undefined)
|
|
384
|
+
break;
|
|
385
|
+
at = next;
|
|
386
|
+
}
|
|
387
|
+
if (found === undefined)
|
|
388
|
+
return undefined;
|
|
389
|
+
return { slot: found.slot, rest: path.slice(found.depth), item: found.item };
|
|
390
|
+
};
|
|
391
|
+
const foldInto = (container, rest, op) => {
|
|
392
|
+
if (rest.length === 0)
|
|
393
|
+
return false;
|
|
394
|
+
let target = container;
|
|
395
|
+
for (let index = 0; index < rest.length - 1; index++) {
|
|
396
|
+
if (!isObj(target))
|
|
397
|
+
return false;
|
|
398
|
+
target = target[rest[index]];
|
|
399
|
+
}
|
|
400
|
+
if (!isObj(target))
|
|
401
|
+
return false;
|
|
402
|
+
const key = rest[rest.length - 1];
|
|
403
|
+
const holder = target;
|
|
404
|
+
const write = (value) => {
|
|
405
|
+
Object.defineProperty(holder, key, { value, writable: true, enumerable: true, configurable: true });
|
|
406
|
+
};
|
|
407
|
+
switch (op[0]) {
|
|
408
|
+
case "s":
|
|
409
|
+
if (key === "__proto__")
|
|
410
|
+
return false;
|
|
411
|
+
write(cloneJson(op[2]));
|
|
412
|
+
return true;
|
|
413
|
+
case "d":
|
|
414
|
+
delete holder[key];
|
|
415
|
+
return true;
|
|
416
|
+
case "a": {
|
|
417
|
+
const value = holder[key];
|
|
418
|
+
if (typeof value !== "string")
|
|
419
|
+
return false;
|
|
420
|
+
write(value + op[2]);
|
|
421
|
+
return true;
|
|
422
|
+
}
|
|
423
|
+
case "t": {
|
|
424
|
+
const value = holder[key];
|
|
425
|
+
if (typeof value !== "string")
|
|
426
|
+
return false;
|
|
427
|
+
write(value.slice(op[2]));
|
|
428
|
+
return true;
|
|
429
|
+
}
|
|
430
|
+
case "p": {
|
|
431
|
+
const value = holder[key];
|
|
432
|
+
if (!Array.isArray(value))
|
|
433
|
+
return false;
|
|
434
|
+
spliceItems(value, op[2], op[3], cloneJson(op[4]));
|
|
435
|
+
return true;
|
|
436
|
+
}
|
|
437
|
+
default:
|
|
438
|
+
return false;
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
const recordString = (path, previous, value) => {
|
|
442
|
+
if (forceBase)
|
|
443
|
+
return;
|
|
444
|
+
hasPending = true;
|
|
445
|
+
// a string inside a pending payload belongs in that payload, as for any write
|
|
446
|
+
const fold = foldTarget(path);
|
|
447
|
+
if (fold !== undefined) {
|
|
448
|
+
const op = ["s", path, value];
|
|
449
|
+
if (fold.item !== undefined) {
|
|
450
|
+
const items = fold.slot.op[4];
|
|
451
|
+
if (fold.rest.length === 0) {
|
|
452
|
+
items[fold.item] = value;
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
if (foldInto(items[fold.item], fold.rest, op))
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
else {
|
|
459
|
+
const payload = fold.slot.op[0] === "r" ? fold.slot.op[1] : fold.slot.op[2];
|
|
460
|
+
if (foldInto(payload, fold.rest, op))
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
const at = logNode(path);
|
|
465
|
+
const live = liveSlot(at);
|
|
466
|
+
if (live?.str !== undefined) {
|
|
467
|
+
live.str.value = value;
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
if (live !== undefined) {
|
|
471
|
+
// a pending set or delete at this path already replaced the value; keep that
|
|
472
|
+
// op and carry the new value in it rather than anchoring to it
|
|
473
|
+
if (live.op[0] === "s" || live.op[0] === "r") {
|
|
474
|
+
live.op = live.op[0] === "r" ? ["r", value] : ["s", live.op[1], value];
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
if (live.op[0] === "d") {
|
|
478
|
+
killHere(at);
|
|
479
|
+
addSlot(at, {
|
|
480
|
+
op: ["s", path, value],
|
|
481
|
+
dead: false,
|
|
482
|
+
order: 0,
|
|
483
|
+
index: 0,
|
|
484
|
+
});
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
// a truncate/append pair from an earlier string diff: both must go
|
|
488
|
+
killHere(at);
|
|
489
|
+
}
|
|
490
|
+
killSubtree(at);
|
|
491
|
+
addSlot(at, {
|
|
492
|
+
op: ["s", path, value],
|
|
493
|
+
dead: false,
|
|
494
|
+
order: 0,
|
|
495
|
+
index: 0,
|
|
496
|
+
str: { anchor: previous, value },
|
|
497
|
+
});
|
|
498
|
+
};
|
|
499
|
+
const record = (op) => {
|
|
500
|
+
if (forceBase)
|
|
501
|
+
return;
|
|
502
|
+
hasPending = true;
|
|
503
|
+
const path = (op[0] === "r" ? [] : op[1]);
|
|
504
|
+
const existing = findLogNode(path);
|
|
505
|
+
const anchored = existing === undefined ? undefined : liveSlot(existing);
|
|
506
|
+
if (anchored?.str !== undefined) {
|
|
507
|
+
switch (op[0]) {
|
|
508
|
+
case "a":
|
|
509
|
+
anchored.str.value += op[2];
|
|
510
|
+
return;
|
|
511
|
+
case "t":
|
|
512
|
+
anchored.str.value = anchored.str.value.slice(op[2]);
|
|
513
|
+
return;
|
|
514
|
+
case "s":
|
|
515
|
+
if (typeof op[2] === "string") {
|
|
516
|
+
anchored.str.value = op[2];
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
if (existing !== undefined)
|
|
521
|
+
killSubtree(existing);
|
|
522
|
+
}
|
|
523
|
+
else if (existing !== undefined && (op[0] === "s" || op[0] === "d" || op[0] === "r")) {
|
|
524
|
+
// A replacement absorbed into an ancestor payload must still invalidate
|
|
525
|
+
// operations already recorded at and below its destination.
|
|
526
|
+
killSubtree(existing);
|
|
527
|
+
}
|
|
528
|
+
if (path.length > 0) {
|
|
529
|
+
const fold = foldTarget(path);
|
|
530
|
+
if (fold !== undefined) {
|
|
531
|
+
if (fold.item !== undefined) {
|
|
532
|
+
const items = fold.slot.op[4];
|
|
533
|
+
if (fold.rest.length === 0) {
|
|
534
|
+
if (op[0] === "s") {
|
|
535
|
+
items[fold.item] = cloneJson(op[2]);
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
else if (foldInto(items[fold.item], fold.rest, op))
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
else {
|
|
543
|
+
const payload = fold.slot.op[0] === "r" ? fold.slot.op[1] : fold.slot.op[2];
|
|
544
|
+
if (foldInto(payload, fold.rest, op))
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
const at = logNode(path);
|
|
550
|
+
const live = liveSlot(at);
|
|
551
|
+
if (live !== undefined) {
|
|
552
|
+
const previous = live.op;
|
|
553
|
+
if (op[0] === "a" && previous[0] === "a") {
|
|
554
|
+
live.op = ["a", previous[1], previous[2] + op[2]];
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
if (op[0] === "a" && (previous[0] === "s" || previous[0] === "r")) {
|
|
558
|
+
const value = previous[0] === "r" ? previous[1] : previous[2];
|
|
559
|
+
if (typeof value === "string") {
|
|
560
|
+
live.op = previous[0] === "r" ? ["r", value + op[2]] : ["s", previous[1], value + op[2]];
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
if (op[0] === "t" && (previous[0] === "s" || previous[0] === "r")) {
|
|
565
|
+
const value = previous[0] === "r" ? previous[1] : previous[2];
|
|
566
|
+
if (typeof value === "string") {
|
|
567
|
+
const cut = value.slice(op[2]);
|
|
568
|
+
live.op = previous[0] === "r" ? ["r", cut] : ["s", previous[1], cut];
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
if (op[0] === "p" && previous[0] === "p") {
|
|
573
|
+
const previousItems = previous[4];
|
|
574
|
+
// These rewrites are sound only for adjacent recorded operations. A
|
|
575
|
+
// tombstoned operation remains a barrier through lastAddedSlot.
|
|
576
|
+
if (previous[3] === 0 &&
|
|
577
|
+
op[3] === 0 &&
|
|
578
|
+
previous[2] + previousItems.length === op[2] &&
|
|
579
|
+
lastAddedSlot === live) {
|
|
580
|
+
const items = op[4];
|
|
581
|
+
for (let index = 0; index < items.length; index++)
|
|
582
|
+
previousItems.push(items[index]);
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
if (previous[3] === 0 &&
|
|
586
|
+
lastAddedSlot === live &&
|
|
587
|
+
op[2] >= previous[2] &&
|
|
588
|
+
op[2] + op[3] <= previous[2] + previousItems.length) {
|
|
589
|
+
spliceItems(previousItems, op[2] - previous[2], op[3], op[4]);
|
|
590
|
+
if (previousItems.length === 0 && previous[3] === 0)
|
|
591
|
+
killSlot(live);
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
if (op[3] > 0 &&
|
|
595
|
+
op[4].length === 0 &&
|
|
596
|
+
previousItems.length > 0 &&
|
|
597
|
+
lastAddedSlot === live) {
|
|
598
|
+
const from = op[2] - previous[2];
|
|
599
|
+
if (from >= 0 && from + op[3] === previousItems.length) {
|
|
600
|
+
previousItems.length = from;
|
|
601
|
+
if (previousItems.length === 0 && previous[3] === 0)
|
|
602
|
+
killSlot(live);
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
if (op[0] === "s" || op[0] === "d" || op[0] === "r")
|
|
608
|
+
killHere(at);
|
|
609
|
+
}
|
|
610
|
+
if (op[0] === "s" || op[0] === "r" || op[0] === "d") {
|
|
611
|
+
// Replacements dominate all earlier descendants, including generations
|
|
612
|
+
// detached by array splices.
|
|
613
|
+
killSubtree(at);
|
|
614
|
+
}
|
|
615
|
+
else if (op[0] === "p") {
|
|
616
|
+
// Splices preserve earlier writes but form a barrier for later folding.
|
|
617
|
+
retireKids(at);
|
|
618
|
+
}
|
|
619
|
+
addSlot(at, { op, dead: false, order: 0, index: 0 });
|
|
620
|
+
};
|
|
621
|
+
// Local diff, used when a whole container is assigned: keeps op quality
|
|
622
|
+
// without a baseline by comparing the outgoing value with the incoming one at
|
|
623
|
+
// the moment of the write. String leaves go through recordString so every
|
|
624
|
+
// string path keeps a single anchored slot; otherwise a later write to the
|
|
625
|
+
// same string would have to supersede ops whose starting value it no longer
|
|
626
|
+
// knows.
|
|
627
|
+
const diffInto = (before, after, at) => {
|
|
628
|
+
if (forceBase)
|
|
629
|
+
return;
|
|
630
|
+
hasPending = true;
|
|
631
|
+
if (before === after)
|
|
632
|
+
return;
|
|
633
|
+
if (typeof before === "string" && typeof after === "string") {
|
|
634
|
+
recordString(at.slice(), before, after);
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
if (Array.isArray(before) && Array.isArray(after) && before.length === after.length) {
|
|
638
|
+
for (let index = 0; index < after.length; index++) {
|
|
639
|
+
at.push(index);
|
|
640
|
+
diffInto(before[index], after[index], at);
|
|
641
|
+
at.pop();
|
|
642
|
+
}
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
if (isObj(before) && isObj(after) && !Array.isArray(before) && !Array.isArray(after)) {
|
|
646
|
+
const beforeObject = before;
|
|
647
|
+
const afterObject = after;
|
|
648
|
+
const beforeKeys = Object.keys(beforeObject);
|
|
649
|
+
const afterKeys = Object.keys(afterObject);
|
|
650
|
+
if ([...beforeKeys, ...afterKeys].some((key) => RESERVED_SEGMENTS.has(key))) {
|
|
651
|
+
record(["s", at.slice(), cloneJson(after)]);
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
for (const key of afterKeys) {
|
|
655
|
+
at.push(key);
|
|
656
|
+
if (Object.hasOwn(beforeObject, key))
|
|
657
|
+
diffInto(beforeObject[key], afterObject[key], at);
|
|
658
|
+
else
|
|
659
|
+
record(["s", at.slice(), cloneJson(afterObject[key])]);
|
|
660
|
+
at.pop();
|
|
661
|
+
}
|
|
662
|
+
for (const key of beforeKeys) {
|
|
663
|
+
if (!Object.hasOwn(afterObject, key))
|
|
664
|
+
record(["d", [...at, key]]);
|
|
665
|
+
}
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
// arrays of differing length, and everything else: chord's own diff
|
|
669
|
+
const out = [];
|
|
670
|
+
diffValue(before, after, at, scan, out);
|
|
671
|
+
for (const op of out)
|
|
672
|
+
record(op);
|
|
673
|
+
};
|
|
674
|
+
const guard = (segment) => {
|
|
675
|
+
if (typeof segment === "symbol")
|
|
676
|
+
throw new UnsafePathError(String(segment));
|
|
677
|
+
if (typeof segment === "string" && RESERVED_SEGMENTS.has(segment))
|
|
678
|
+
throw new UnsafePathError(segment);
|
|
679
|
+
return segment;
|
|
680
|
+
};
|
|
681
|
+
const integer = (value) => {
|
|
682
|
+
const number = Number(value);
|
|
683
|
+
if (Number.isNaN(number) || number === 0)
|
|
684
|
+
return 0;
|
|
685
|
+
return Number.isFinite(number) ? Math.trunc(number) : number;
|
|
686
|
+
};
|
|
687
|
+
const spliceRange = (length, args) => {
|
|
688
|
+
const rawStart = args.length === 0 ? 0 : integer(args[0]);
|
|
689
|
+
const index = rawStart < 0 ? Math.max(0, length + rawStart) : Math.min(rawStart, length);
|
|
690
|
+
const remove = args.length === 0
|
|
691
|
+
? 0
|
|
692
|
+
: args.length === 1
|
|
693
|
+
? length - index
|
|
694
|
+
: Math.max(0, Math.min(integer(args[1]), length - index));
|
|
695
|
+
return { index, remove };
|
|
696
|
+
};
|
|
697
|
+
// Paths are walked from placement cells rather than baked into proxies. A held
|
|
698
|
+
// descendant keeps its cells and their owner entries alive, so an ancestor can
|
|
699
|
+
// be re-created after GC without losing array-renumbering metadata. Entries keep
|
|
700
|
+
// only weak references to public proxies; parent caches keep only weak cells.
|
|
701
|
+
let shape = 0;
|
|
702
|
+
// Ordinary tree entries are weak values. Explicit aliases are sparse and stay
|
|
703
|
+
// strong while their raw weak key is alive so alias locations survive a period
|
|
704
|
+
// in which no public proxy exists.
|
|
705
|
+
const entries = new WeakMap();
|
|
706
|
+
const aliases = new WeakMap();
|
|
707
|
+
// A live public proxy retains its entry through this ephemeron. Raw proxy RHS
|
|
708
|
+
// values can therefore be unwrapped before they are written into plain targets.
|
|
709
|
+
const proxyEntries = new WeakMap();
|
|
710
|
+
// WeakRef targets already stay alive through the current JavaScript job. These
|
|
711
|
+
// strong job-local caches avoid repeated deref bookkeeping without extending
|
|
712
|
+
// that lifetime; one microtask drops both maps before the next job.
|
|
713
|
+
let jobCells = new WeakMap();
|
|
714
|
+
let jobProxies = new WeakMap();
|
|
715
|
+
let jobCleanupScheduled = false;
|
|
716
|
+
const scheduleJobCleanup = () => {
|
|
717
|
+
if (jobCleanupScheduled)
|
|
718
|
+
return;
|
|
719
|
+
jobCleanupScheduled = true;
|
|
720
|
+
queueMicrotask(() => {
|
|
721
|
+
jobCells = new WeakMap();
|
|
722
|
+
jobProxies = new WeakMap();
|
|
723
|
+
jobCleanupScheduled = false;
|
|
724
|
+
});
|
|
725
|
+
};
|
|
726
|
+
const keepCellForJob = (ref, cell) => {
|
|
727
|
+
jobCells.set(ref, cell);
|
|
728
|
+
scheduleJobCleanup();
|
|
729
|
+
};
|
|
730
|
+
const derefCell = (ref) => {
|
|
731
|
+
const cached = jobCells.get(ref);
|
|
732
|
+
if (cached !== undefined)
|
|
733
|
+
return cached;
|
|
734
|
+
const cell = ref.deref();
|
|
735
|
+
if (cell !== undefined)
|
|
736
|
+
keepCellForJob(ref, cell);
|
|
737
|
+
return cell;
|
|
738
|
+
};
|
|
739
|
+
const entryFinalizer = new FinalizationRegistry(({ target, token }) => {
|
|
740
|
+
const raw = target.deref();
|
|
741
|
+
if (raw !== undefined && entries.get(raw)?.token === token)
|
|
742
|
+
entries.delete(raw);
|
|
743
|
+
});
|
|
744
|
+
const cellFinalizer = new FinalizationRegistry(({ owner, key, ref }) => {
|
|
745
|
+
const entry = owner.deref();
|
|
746
|
+
if (entry === undefined)
|
|
747
|
+
return;
|
|
748
|
+
if (key !== undefined && entry.childProxies?.get(key) === ref)
|
|
749
|
+
entry.childProxies.delete(key);
|
|
750
|
+
entry.childCells?.delete(ref);
|
|
751
|
+
});
|
|
752
|
+
// Almost no document ever puts one object at two positions. Until one does,
|
|
753
|
+
// every write has exactly one path, so the per-write cell walk is skipped.
|
|
754
|
+
let aliased = false;
|
|
755
|
+
const isDetached = (cell) => {
|
|
756
|
+
for (let c = cell; c !== undefined; c = c.parent)
|
|
757
|
+
if (c.dead)
|
|
758
|
+
return true;
|
|
759
|
+
return false;
|
|
760
|
+
};
|
|
761
|
+
const pathOf = (cell) => {
|
|
762
|
+
if (cell.at === shape && cell.cached !== undefined)
|
|
763
|
+
return cell.cached;
|
|
764
|
+
const out = [];
|
|
765
|
+
for (let c = cell; c !== undefined && c.parent !== undefined; c = c.parent)
|
|
766
|
+
out.push(c.seg);
|
|
767
|
+
out.reverse();
|
|
768
|
+
cell.at = shape;
|
|
769
|
+
cell.cached = out;
|
|
770
|
+
return out;
|
|
771
|
+
};
|
|
772
|
+
const liveCells = (entry) => {
|
|
773
|
+
const out = [];
|
|
774
|
+
for (const cell of entry.cells)
|
|
775
|
+
if (!isDetached(cell))
|
|
776
|
+
out.push(cell);
|
|
777
|
+
return out;
|
|
778
|
+
};
|
|
779
|
+
const primary = (entry) => (aliased ? (liveCells(entry)[0] ?? entry.fallback) : entry.fallback);
|
|
780
|
+
const pathNow = (entry) => pathOf(primary(entry));
|
|
781
|
+
const findEntry = (target) => {
|
|
782
|
+
const alias = aliases.get(target);
|
|
783
|
+
if (alias !== undefined)
|
|
784
|
+
return alias;
|
|
785
|
+
const slot = entries.get(target);
|
|
786
|
+
const entry = slot?.ref.deref();
|
|
787
|
+
if (slot !== undefined && entry === undefined)
|
|
788
|
+
entries.delete(target);
|
|
789
|
+
return entry;
|
|
790
|
+
};
|
|
791
|
+
const indexEntry = (entry) => {
|
|
792
|
+
const token = {};
|
|
793
|
+
entries.set(entry.target, { ref: new WeakRef(entry), token });
|
|
794
|
+
entryFinalizer.register(entry, { target: new WeakRef(entry.target), token });
|
|
795
|
+
};
|
|
796
|
+
const addPlacement = (entry, cell) => {
|
|
797
|
+
if (entry.cells.has(cell))
|
|
798
|
+
return;
|
|
799
|
+
let hasLive = false;
|
|
800
|
+
for (const existing of entry.cells) {
|
|
801
|
+
if (!isDetached(existing)) {
|
|
802
|
+
hasLive = true;
|
|
803
|
+
break;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
cell.entry = entry;
|
|
807
|
+
cell.target = entry.target;
|
|
808
|
+
entry.cells.add(cell);
|
|
809
|
+
if (!hasLive) {
|
|
810
|
+
const previous = entry.fallback;
|
|
811
|
+
entry.fallback = cell;
|
|
812
|
+
if (previous !== cell) {
|
|
813
|
+
shape++;
|
|
814
|
+
// Reattaching a held container moves every known immediate child to
|
|
815
|
+
// its new placement. Array registrations survive cache clears.
|
|
816
|
+
const children = new Set();
|
|
817
|
+
for (const ref of entry.childProxies?.values() ?? []) {
|
|
818
|
+
const child = derefCell(ref);
|
|
819
|
+
if (child !== undefined)
|
|
820
|
+
children.add(child);
|
|
821
|
+
}
|
|
822
|
+
for (const ref of entry.childCells ?? []) {
|
|
823
|
+
const child = derefCell(ref);
|
|
824
|
+
if (child !== undefined)
|
|
825
|
+
children.add(child);
|
|
826
|
+
}
|
|
827
|
+
for (const child of children) {
|
|
828
|
+
if (!child.dead && child.parent === previous)
|
|
829
|
+
child.parent = cell;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
else if (entry.blocked === undefined) {
|
|
834
|
+
aliased = true;
|
|
835
|
+
aliases.set(entry.target, entry);
|
|
836
|
+
}
|
|
837
|
+
};
|
|
838
|
+
const cachePlacement = (owner, key, cell) => {
|
|
839
|
+
let cleanup = cell.cleanup;
|
|
840
|
+
if (cleanup === undefined) {
|
|
841
|
+
cleanup = { owner: new WeakRef(owner), key: undefined, ref: new WeakRef(cell) };
|
|
842
|
+
cell.cleanup = cleanup;
|
|
843
|
+
cellFinalizer.register(cell, cleanup);
|
|
844
|
+
}
|
|
845
|
+
keepCellForJob(cleanup.ref, cell);
|
|
846
|
+
if (cleanup.key !== undefined && cleanup.key !== key && owner.childProxies?.get(cleanup.key) === cleanup.ref) {
|
|
847
|
+
owner.childProxies.delete(cleanup.key);
|
|
848
|
+
}
|
|
849
|
+
if (owner.childProxies === undefined)
|
|
850
|
+
owner.childProxies = new Map();
|
|
851
|
+
owner.childProxies.set(key, cleanup.ref);
|
|
852
|
+
cleanup.key = key;
|
|
853
|
+
if (Array.isArray(owner.target)) {
|
|
854
|
+
if (owner.childCells === undefined)
|
|
855
|
+
owner.childCells = new Set();
|
|
856
|
+
owner.childCells.add(cleanup.ref);
|
|
857
|
+
}
|
|
858
|
+
};
|
|
859
|
+
const findPlacement = (owner, parent, segment, target, blocked) => {
|
|
860
|
+
if (blocked === undefined) {
|
|
861
|
+
const known = findEntry(target);
|
|
862
|
+
if (known !== undefined) {
|
|
863
|
+
for (const cell of known.cells) {
|
|
864
|
+
if (!cell.dead && cell.owner === owner && cell.parent === parent && cell.seg === segment)
|
|
865
|
+
return cell;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
return undefined;
|
|
869
|
+
}
|
|
870
|
+
// Blocked views are intentionally absent from the ordinary raw-entry index.
|
|
871
|
+
for (const ref of owner.childCells ?? []) {
|
|
872
|
+
const cell = derefCell(ref);
|
|
873
|
+
if (cell !== undefined &&
|
|
874
|
+
!cell.dead &&
|
|
875
|
+
cell.target === target &&
|
|
876
|
+
cell.entry?.blocked === blocked &&
|
|
877
|
+
cell.parent === parent &&
|
|
878
|
+
cell.seg === segment) {
|
|
879
|
+
return cell;
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
return undefined;
|
|
883
|
+
};
|
|
884
|
+
const unwrap = (value) => (isObj(value) ? (proxyEntries.get(value)?.target ?? value) : value);
|
|
885
|
+
const adoptItems = (values) => values.map(unwrap);
|
|
886
|
+
// Every operation is emitted once per live location of an explicitly aliased
|
|
887
|
+
// object. Alias cells are independent of public proxy lifetimes.
|
|
888
|
+
const emit = (entry, op) => {
|
|
889
|
+
record(op);
|
|
890
|
+
if (!aliased)
|
|
891
|
+
return;
|
|
892
|
+
const live = liveCells(entry);
|
|
893
|
+
if (live.length <= 1)
|
|
894
|
+
return;
|
|
895
|
+
const base = pathNow(entry);
|
|
896
|
+
const head = primary(entry);
|
|
897
|
+
for (const cell of live) {
|
|
898
|
+
if (cell === head || op[0] === "r")
|
|
899
|
+
continue;
|
|
900
|
+
const rest = op[1].slice(base.length);
|
|
901
|
+
const cloned = [...op];
|
|
902
|
+
cloned[1] = [...pathOf(cell), ...rest];
|
|
903
|
+
record(cloned);
|
|
904
|
+
}
|
|
905
|
+
};
|
|
906
|
+
// Structural mutation updates every still-live placement cell, including cells
|
|
907
|
+
// retained only by held descendants. Dead weak registrations are pruned lazily;
|
|
908
|
+
// finalizers keep idle live parents from accumulating them indefinitely.
|
|
909
|
+
const renumber = (entry, key, before, after, spliceAt, spliceRemove, spliceInsert) => {
|
|
910
|
+
shape++;
|
|
911
|
+
const childCells = entry.childCells;
|
|
912
|
+
if (key === "push" || !Array.isArray(entry.target) || childCells === undefined || childCells.size === 0)
|
|
913
|
+
return;
|
|
914
|
+
let index;
|
|
915
|
+
let remove = 0;
|
|
916
|
+
let insert = 0;
|
|
917
|
+
if (key === "pop") {
|
|
918
|
+
index = before - 1;
|
|
919
|
+
remove = before > 0 ? 1 : 0;
|
|
920
|
+
}
|
|
921
|
+
else if (key === "shift") {
|
|
922
|
+
index = 0;
|
|
923
|
+
remove = before > 0 ? 1 : 0;
|
|
924
|
+
}
|
|
925
|
+
else if (key === "unshift") {
|
|
926
|
+
index = 0;
|
|
927
|
+
insert = after - before;
|
|
928
|
+
}
|
|
929
|
+
else if (key === "splice") {
|
|
930
|
+
index = spliceAt;
|
|
931
|
+
remove = spliceRemove;
|
|
932
|
+
insert = spliceInsert;
|
|
933
|
+
}
|
|
934
|
+
else {
|
|
935
|
+
for (const ref of [...childCells]) {
|
|
936
|
+
const cell = derefCell(ref);
|
|
937
|
+
if (cell === undefined) {
|
|
938
|
+
childCells.delete(ref);
|
|
939
|
+
continue;
|
|
940
|
+
}
|
|
941
|
+
const at = entry.target.indexOf(cell.target);
|
|
942
|
+
if (at < 0) {
|
|
943
|
+
cell.dead = true;
|
|
944
|
+
childCells.delete(ref);
|
|
945
|
+
}
|
|
946
|
+
else
|
|
947
|
+
cell.seg = at;
|
|
948
|
+
}
|
|
949
|
+
entry.childProxies?.clear();
|
|
950
|
+
return;
|
|
951
|
+
}
|
|
952
|
+
const delta = insert - remove;
|
|
953
|
+
for (const ref of [...childCells]) {
|
|
954
|
+
const cell = derefCell(ref);
|
|
955
|
+
if (cell === undefined) {
|
|
956
|
+
childCells.delete(ref);
|
|
957
|
+
continue;
|
|
958
|
+
}
|
|
959
|
+
const at = cell.seg;
|
|
960
|
+
if (typeof at !== "number")
|
|
961
|
+
continue;
|
|
962
|
+
if (at >= index && at < index + remove) {
|
|
963
|
+
cell.dead = true;
|
|
964
|
+
childCells.delete(ref);
|
|
965
|
+
}
|
|
966
|
+
else if (at >= index + remove)
|
|
967
|
+
cell.seg = at + delta;
|
|
968
|
+
}
|
|
969
|
+
entry.childProxies?.clear();
|
|
970
|
+
};
|
|
971
|
+
const wrap = (object, cell, blockedSegment) => {
|
|
972
|
+
const placed = cell.entry;
|
|
973
|
+
if (placed !== undefined && placed.target === object && placed.blocked === blockedSegment) {
|
|
974
|
+
return proxyFor(placed);
|
|
975
|
+
}
|
|
976
|
+
const existing = blockedSegment === undefined ? findEntry(object) : undefined;
|
|
977
|
+
if (existing !== undefined) {
|
|
978
|
+
addPlacement(existing, cell);
|
|
979
|
+
return proxyFor(existing);
|
|
980
|
+
}
|
|
981
|
+
const entry = {
|
|
982
|
+
target: object,
|
|
983
|
+
cells: new Set(),
|
|
984
|
+
fallback: cell,
|
|
985
|
+
blocked: blockedSegment,
|
|
986
|
+
proxy: undefined,
|
|
987
|
+
childProxies: undefined,
|
|
988
|
+
childCells: undefined,
|
|
989
|
+
};
|
|
990
|
+
addPlacement(entry, cell);
|
|
991
|
+
if (blockedSegment === undefined)
|
|
992
|
+
indexEntry(entry);
|
|
993
|
+
return proxyFor(entry);
|
|
994
|
+
};
|
|
995
|
+
const handlerPrototype = {
|
|
996
|
+
get(target, key, receiver) {
|
|
997
|
+
const entry = this.entry;
|
|
998
|
+
if (Array.isArray(target) && typeof key === "string" && MUTATORS.has(key)) {
|
|
999
|
+
return (...args) => {
|
|
1000
|
+
if (entry.blocked !== undefined)
|
|
1001
|
+
throw new UnsafePathError(entry.blocked);
|
|
1002
|
+
const detached = aliased ? liveCells(entry).length === 0 : isDetached(entry.fallback);
|
|
1003
|
+
if (detached) {
|
|
1004
|
+
return Reflect.apply(Array.prototype[key], target, args.map(unwrap));
|
|
1005
|
+
}
|
|
1006
|
+
const before = target.length;
|
|
1007
|
+
let spliceAt = -1;
|
|
1008
|
+
let spliceRemove = 0;
|
|
1009
|
+
let spliceInsert = 0;
|
|
1010
|
+
let insertAt = -1;
|
|
1011
|
+
let insertCount = 0;
|
|
1012
|
+
let result;
|
|
1013
|
+
switch (key) {
|
|
1014
|
+
case "push": {
|
|
1015
|
+
const items = adoptItems(args);
|
|
1016
|
+
if (items.length > 0)
|
|
1017
|
+
emit(entry, ["p", [...pathNow(entry)], before, 0, cloneJson(items)]);
|
|
1018
|
+
insertAt = before;
|
|
1019
|
+
insertCount = items.length;
|
|
1020
|
+
spliceItems(target, before, 0, items);
|
|
1021
|
+
result = target.length;
|
|
1022
|
+
break;
|
|
1023
|
+
}
|
|
1024
|
+
case "unshift": {
|
|
1025
|
+
const items = adoptItems(args);
|
|
1026
|
+
if (items.length > 0)
|
|
1027
|
+
emit(entry, ["p", [...pathNow(entry)], 0, 0, cloneJson(items)]);
|
|
1028
|
+
insertAt = 0;
|
|
1029
|
+
insertCount = items.length;
|
|
1030
|
+
spliceItems(target, 0, 0, items);
|
|
1031
|
+
result = target.length;
|
|
1032
|
+
break;
|
|
1033
|
+
}
|
|
1034
|
+
case "pop":
|
|
1035
|
+
if (before > 0)
|
|
1036
|
+
emit(entry, ["p", [...pathNow(entry)], before - 1, 1, []]);
|
|
1037
|
+
result = Reflect.apply(Array.prototype.pop, target, args);
|
|
1038
|
+
break;
|
|
1039
|
+
case "shift":
|
|
1040
|
+
if (before > 0)
|
|
1041
|
+
emit(entry, ["p", [...pathNow(entry)], 0, 1, []]);
|
|
1042
|
+
result = Reflect.apply(Array.prototype.shift, target, args);
|
|
1043
|
+
break;
|
|
1044
|
+
case "splice": {
|
|
1045
|
+
const items = adoptItems(args.slice(2));
|
|
1046
|
+
const { index, remove } = spliceRange(before, args);
|
|
1047
|
+
spliceAt = index;
|
|
1048
|
+
spliceRemove = remove;
|
|
1049
|
+
spliceInsert = items.length;
|
|
1050
|
+
insertAt = index;
|
|
1051
|
+
insertCount = items.length;
|
|
1052
|
+
if (remove > 0 || items.length > 0) {
|
|
1053
|
+
if (index === 0 && remove === before) {
|
|
1054
|
+
if (pathNow(entry).length === 0)
|
|
1055
|
+
emit(entry, ["r", cloneJson(items)]);
|
|
1056
|
+
else
|
|
1057
|
+
emit(entry, [
|
|
1058
|
+
"s",
|
|
1059
|
+
[...pathNow(entry)],
|
|
1060
|
+
cloneJson(items),
|
|
1061
|
+
]);
|
|
1062
|
+
}
|
|
1063
|
+
else
|
|
1064
|
+
emit(entry, ["p", [...pathNow(entry)], index, remove, cloneJson(items)]);
|
|
1065
|
+
}
|
|
1066
|
+
result = spliceItems(target, index, remove, items);
|
|
1067
|
+
break;
|
|
1068
|
+
}
|
|
1069
|
+
default: {
|
|
1070
|
+
result = Reflect.apply(Array.prototype[key], target, args.map(unwrap));
|
|
1071
|
+
if (pathNow(entry).length === 0)
|
|
1072
|
+
emit(entry, ["r", cloneJson(target)]);
|
|
1073
|
+
else
|
|
1074
|
+
emit(entry, [
|
|
1075
|
+
"s",
|
|
1076
|
+
[...pathNow(entry)],
|
|
1077
|
+
cloneJson(target),
|
|
1078
|
+
]);
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
collapsePending();
|
|
1082
|
+
renumber(entry, key, before, target.length, spliceAt, spliceRemove, spliceInsert);
|
|
1083
|
+
for (let index = insertAt; insertCount > 0 && index < insertAt + insertCount; index++) {
|
|
1084
|
+
const item = target[index];
|
|
1085
|
+
if (!isObj(item))
|
|
1086
|
+
continue;
|
|
1087
|
+
const known = findEntry(item);
|
|
1088
|
+
if (known === undefined || known.target === entry.target)
|
|
1089
|
+
continue;
|
|
1090
|
+
const parent = primary(entry);
|
|
1091
|
+
let seen = false;
|
|
1092
|
+
for (const existingCell of known.cells) {
|
|
1093
|
+
if (!existingCell.dead && existingCell.parent === parent && existingCell.seg === index)
|
|
1094
|
+
seen = true;
|
|
1095
|
+
}
|
|
1096
|
+
if (!seen) {
|
|
1097
|
+
const inserted = {
|
|
1098
|
+
parent,
|
|
1099
|
+
owner: entry,
|
|
1100
|
+
entry: undefined,
|
|
1101
|
+
target: item,
|
|
1102
|
+
seg: index,
|
|
1103
|
+
dead: false,
|
|
1104
|
+
};
|
|
1105
|
+
addPlacement(known, inserted);
|
|
1106
|
+
cachePlacement(entry, String(index), inserted);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
return key === "sort" || key === "reverse" || key === "fill" || key === "copyWithin" ? receiver : result;
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
1112
|
+
const value = Reflect.get(target, key, receiver);
|
|
1113
|
+
if (!isObj(value))
|
|
1114
|
+
return value;
|
|
1115
|
+
const cachedRef = entry.childProxies?.get(key);
|
|
1116
|
+
const cached = cachedRef === undefined ? undefined : derefCell(cachedRef);
|
|
1117
|
+
if (cached !== undefined && cached.target === value && cached.entry !== undefined) {
|
|
1118
|
+
return proxyFor(cached.entry);
|
|
1119
|
+
}
|
|
1120
|
+
if (cachedRef !== undefined && cached === undefined && entry.childProxies?.get(key) === cachedRef) {
|
|
1121
|
+
entry.childProxies?.delete(key);
|
|
1122
|
+
}
|
|
1123
|
+
const rawSegment = norm(target, key);
|
|
1124
|
+
let segment;
|
|
1125
|
+
let childBlocked = entry.blocked;
|
|
1126
|
+
if (entry.blocked !== undefined) {
|
|
1127
|
+
if (typeof rawSegment === "symbol")
|
|
1128
|
+
throw new UnsafePathError(String(rawSegment));
|
|
1129
|
+
segment = rawSegment;
|
|
1130
|
+
}
|
|
1131
|
+
else if (typeof rawSegment === "string" && RESERVED_SEGMENTS.has(rawSegment) && Object.hasOwn(target, key)) {
|
|
1132
|
+
segment = rawSegment;
|
|
1133
|
+
childBlocked = rawSegment;
|
|
1134
|
+
}
|
|
1135
|
+
else
|
|
1136
|
+
segment = guard(rawSegment);
|
|
1137
|
+
const parent = primary(entry);
|
|
1138
|
+
const existingCell = findPlacement(entry, parent, segment, value, childBlocked);
|
|
1139
|
+
if (existingCell?.entry !== undefined) {
|
|
1140
|
+
cachePlacement(entry, key, existingCell);
|
|
1141
|
+
return proxyFor(existingCell.entry);
|
|
1142
|
+
}
|
|
1143
|
+
const childCell = {
|
|
1144
|
+
parent,
|
|
1145
|
+
owner: entry,
|
|
1146
|
+
entry: undefined,
|
|
1147
|
+
target: value,
|
|
1148
|
+
seg: segment,
|
|
1149
|
+
dead: false,
|
|
1150
|
+
};
|
|
1151
|
+
const child = wrap(value, childCell, childBlocked);
|
|
1152
|
+
cachePlacement(entry, key, childCell);
|
|
1153
|
+
return child;
|
|
1154
|
+
},
|
|
1155
|
+
set(target, key, value) {
|
|
1156
|
+
const entry = this.entry;
|
|
1157
|
+
if (entry.blocked !== undefined)
|
|
1158
|
+
throw new UnsafePathError(entry.blocked);
|
|
1159
|
+
const rawValue = unwrap(value);
|
|
1160
|
+
if (aliased ? liveCells(entry).length === 0 : isDetached(entry.fallback)) {
|
|
1161
|
+
return Reflect.set(target, key, rawValue);
|
|
1162
|
+
}
|
|
1163
|
+
if (Array.isArray(target) && key === "length") {
|
|
1164
|
+
const before = target.length;
|
|
1165
|
+
const next = Number(rawValue);
|
|
1166
|
+
if (!Number.isSafeInteger(next) || next < 0 || next > 4_294_967_295) {
|
|
1167
|
+
return Reflect.set(target, key, rawValue);
|
|
1168
|
+
}
|
|
1169
|
+
if (next < before) {
|
|
1170
|
+
if (next === 0) {
|
|
1171
|
+
if (pathNow(entry).length === 0)
|
|
1172
|
+
emit(entry, ["r", []]);
|
|
1173
|
+
else
|
|
1174
|
+
emit(entry, ["s", [...pathNow(entry)], []]);
|
|
1175
|
+
}
|
|
1176
|
+
else
|
|
1177
|
+
emit(entry, ["p", [...pathNow(entry)], next, before - next, []]);
|
|
1178
|
+
Reflect.set(target, key, next);
|
|
1179
|
+
renumber(entry, "splice", before, next, next, before - next, 0);
|
|
1180
|
+
entry.childProxies?.clear();
|
|
1181
|
+
}
|
|
1182
|
+
else if (next > before) {
|
|
1183
|
+
target.length = next;
|
|
1184
|
+
target.fill(null, before);
|
|
1185
|
+
const grown = new Array(next - before).fill(null);
|
|
1186
|
+
emit(entry, ["p", [...pathNow(entry)], before, 0, grown]);
|
|
1187
|
+
}
|
|
1188
|
+
collapsePending();
|
|
1189
|
+
return true;
|
|
1190
|
+
}
|
|
1191
|
+
const segment = guard(norm(target, key));
|
|
1192
|
+
if (Array.isArray(target)) {
|
|
1193
|
+
if (typeof segment !== "number")
|
|
1194
|
+
throw new UnsafePathError(segment);
|
|
1195
|
+
if (segment > target.length)
|
|
1196
|
+
throw new UnsafePathError(segment);
|
|
1197
|
+
}
|
|
1198
|
+
const at = [...pathNow(entry), segment];
|
|
1199
|
+
if (rawValue === undefined) {
|
|
1200
|
+
if (Array.isArray(target))
|
|
1201
|
+
throw new TypeError("undefined would create a sparse array; use splice instead");
|
|
1202
|
+
if (Object.hasOwn(target, key))
|
|
1203
|
+
emit(entry, ["d", at]);
|
|
1204
|
+
entry.childProxies?.delete(key);
|
|
1205
|
+
const deleted = Reflect.deleteProperty(target, key);
|
|
1206
|
+
if (deleted)
|
|
1207
|
+
collapsePending();
|
|
1208
|
+
return deleted;
|
|
1209
|
+
}
|
|
1210
|
+
const previous = target[key];
|
|
1211
|
+
if (previous === rawValue)
|
|
1212
|
+
return true;
|
|
1213
|
+
if (Array.isArray(target) && segment === target.length) {
|
|
1214
|
+
emit(entry, ["p", [...pathNow(entry)], target.length, 0, [cloneJson(rawValue)]]);
|
|
1215
|
+
}
|
|
1216
|
+
else if (isObj(previous) && isObj(rawValue)) {
|
|
1217
|
+
diffInto(previous, rawValue, [...pathNow(entry), segment]);
|
|
1218
|
+
}
|
|
1219
|
+
else if (typeof previous === "string" && typeof rawValue === "string") {
|
|
1220
|
+
if (!aliased)
|
|
1221
|
+
recordString([...pathNow(entry), segment], previous, rawValue);
|
|
1222
|
+
else
|
|
1223
|
+
for (const cell of liveCells(entry))
|
|
1224
|
+
recordString([...pathOf(cell), segment], previous, rawValue);
|
|
1225
|
+
}
|
|
1226
|
+
else {
|
|
1227
|
+
emit(entry, ["s", at, cloneJson(rawValue)]);
|
|
1228
|
+
}
|
|
1229
|
+
entry.childProxies?.delete(key);
|
|
1230
|
+
const updated = Reflect.set(target, key, rawValue);
|
|
1231
|
+
if (updated) {
|
|
1232
|
+
if (isObj(rawValue)) {
|
|
1233
|
+
const known = findEntry(rawValue);
|
|
1234
|
+
if (known !== undefined) {
|
|
1235
|
+
const placement = {
|
|
1236
|
+
parent: primary(entry),
|
|
1237
|
+
owner: entry,
|
|
1238
|
+
entry: undefined,
|
|
1239
|
+
target: rawValue,
|
|
1240
|
+
seg: segment,
|
|
1241
|
+
dead: false,
|
|
1242
|
+
};
|
|
1243
|
+
addPlacement(known, placement);
|
|
1244
|
+
cachePlacement(entry, key, placement);
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
collapsePending();
|
|
1248
|
+
}
|
|
1249
|
+
return updated;
|
|
1250
|
+
},
|
|
1251
|
+
deleteProperty(target, key) {
|
|
1252
|
+
const entry = this.entry;
|
|
1253
|
+
if (entry.blocked !== undefined)
|
|
1254
|
+
throw new UnsafePathError(entry.blocked);
|
|
1255
|
+
if (aliased ? liveCells(entry).length === 0 : isDetached(entry.fallback)) {
|
|
1256
|
+
return Reflect.deleteProperty(target, key);
|
|
1257
|
+
}
|
|
1258
|
+
const segment = guard(norm(target, key));
|
|
1259
|
+
if (Array.isArray(target)) {
|
|
1260
|
+
if (typeof segment !== "number")
|
|
1261
|
+
throw new UnsafePathError(segment);
|
|
1262
|
+
throw new TypeError("delete would create a sparse array; use splice instead");
|
|
1263
|
+
}
|
|
1264
|
+
if (Object.hasOwn(target, key))
|
|
1265
|
+
emit(entry, ["d", [...pathNow(entry), segment]]);
|
|
1266
|
+
entry.childProxies?.delete(key);
|
|
1267
|
+
const deleted = Reflect.deleteProperty(target, key);
|
|
1268
|
+
if (deleted)
|
|
1269
|
+
collapsePending();
|
|
1270
|
+
return deleted;
|
|
1271
|
+
},
|
|
1272
|
+
defineProperty() {
|
|
1273
|
+
throw new TypeError("defineProperty is not supported on tracked state; use assignment");
|
|
1274
|
+
},
|
|
1275
|
+
setPrototypeOf() {
|
|
1276
|
+
throw new TypeError("setPrototypeOf is not supported on tracked state");
|
|
1277
|
+
},
|
|
1278
|
+
preventExtensions() {
|
|
1279
|
+
throw new TypeError("preventExtensions is not supported on tracked state");
|
|
1280
|
+
},
|
|
1281
|
+
};
|
|
1282
|
+
function proxyFor(entry) {
|
|
1283
|
+
const cached = jobProxies.get(entry);
|
|
1284
|
+
if (cached !== undefined)
|
|
1285
|
+
return cached;
|
|
1286
|
+
const existing = entry.proxy?.deref();
|
|
1287
|
+
if (existing !== undefined) {
|
|
1288
|
+
jobProxies.set(entry, existing);
|
|
1289
|
+
scheduleJobCleanup();
|
|
1290
|
+
return existing;
|
|
1291
|
+
}
|
|
1292
|
+
const handler = Object.create(handlerPrototype);
|
|
1293
|
+
handler.entry = entry;
|
|
1294
|
+
const proxy = new Proxy(entry.target, handler);
|
|
1295
|
+
entry.proxy = new WeakRef(proxy);
|
|
1296
|
+
jobProxies.set(entry, proxy);
|
|
1297
|
+
scheduleJobCleanup();
|
|
1298
|
+
proxyEntries.set(proxy, entry);
|
|
1299
|
+
return proxy;
|
|
1300
|
+
}
|
|
1301
|
+
const rootCell = {
|
|
1302
|
+
parent: undefined,
|
|
1303
|
+
owner: undefined,
|
|
1304
|
+
entry: undefined,
|
|
1305
|
+
target: root,
|
|
1306
|
+
seg: "",
|
|
1307
|
+
dead: false,
|
|
1308
|
+
};
|
|
1309
|
+
let state = wrap(root, rootCell);
|
|
1310
|
+
return {
|
|
1311
|
+
get state() {
|
|
1312
|
+
return state;
|
|
1313
|
+
},
|
|
1314
|
+
get target() {
|
|
1315
|
+
return root;
|
|
1316
|
+
},
|
|
1317
|
+
set state(next) {
|
|
1318
|
+
const rawNext = unwrap(next);
|
|
1319
|
+
if (rawNext === root) {
|
|
1320
|
+
clearPending();
|
|
1321
|
+
forceBase = true;
|
|
1322
|
+
return;
|
|
1323
|
+
}
|
|
1324
|
+
clearPending();
|
|
1325
|
+
root = rawNext;
|
|
1326
|
+
state = wrap(root, {
|
|
1327
|
+
parent: undefined,
|
|
1328
|
+
owner: undefined,
|
|
1329
|
+
entry: undefined,
|
|
1330
|
+
target: root,
|
|
1331
|
+
seg: "",
|
|
1332
|
+
dead: false,
|
|
1333
|
+
});
|
|
1334
|
+
forceBase = true;
|
|
1335
|
+
},
|
|
1336
|
+
rebase() {
|
|
1337
|
+
clearPending();
|
|
1338
|
+
forceBase = true;
|
|
1339
|
+
},
|
|
1340
|
+
get dirty() {
|
|
1341
|
+
// conservative: true if anything was written since the last flush, even
|
|
1342
|
+
// if the writes cancelled out
|
|
1343
|
+
return forceBase || hasPending;
|
|
1344
|
+
},
|
|
1345
|
+
discard() {
|
|
1346
|
+
clearPending();
|
|
1347
|
+
},
|
|
1348
|
+
flush() {
|
|
1349
|
+
if (forceBase) {
|
|
1350
|
+
const value = cloneJson(root);
|
|
1351
|
+
forceBase = false;
|
|
1352
|
+
clearPending();
|
|
1353
|
+
return [["r", value]];
|
|
1354
|
+
}
|
|
1355
|
+
if (!hasPending)
|
|
1356
|
+
return [];
|
|
1357
|
+
const out = [];
|
|
1358
|
+
for (const slot of log) {
|
|
1359
|
+
if (slot === undefined || slot.dead)
|
|
1360
|
+
continue;
|
|
1361
|
+
if (slot.str !== undefined) {
|
|
1362
|
+
diffValue(slot.str.anchor, slot.str.value, slot.op[1], scan, out);
|
|
1363
|
+
continue;
|
|
1364
|
+
}
|
|
1365
|
+
out.push(slot.op);
|
|
1366
|
+
}
|
|
1367
|
+
clearPending();
|
|
1368
|
+
return out;
|
|
1369
|
+
},
|
|
1370
|
+
};
|
|
1371
|
+
}
|
|
1372
|
+
// ─── Path safety ─────────────────────────────────────────────────────────────
|
|
1373
|
+
/**
|
|
1374
|
+
* Segments that reach the prototype chain.
|
|
1375
|
+
*
|
|
1376
|
+
* `JSON.parse` is safe on its own — it makes `__proto__` an own property. What is
|
|
1377
|
+
* not safe is `parent[key] = value`, which is exactly what an applier does, and
|
|
1378
|
+
* paths are data: `["s", ["__proto__", "isAdmin"], true]` pollutes
|
|
1379
|
+
* `Object.prototype` for the whole process.
|
|
1380
|
+
*
|
|
1381
|
+
* Ops arrive from a facet, a plugin compartment, or a tool whose details may echo
|
|
1382
|
+
* model output, so none of it is trusted input.
|
|
1383
|
+
*/
|
|
1384
|
+
export const RESERVED_SEGMENTS = new Set(["__proto__", "constructor", "prototype"]);
|
|
1385
|
+
export class UnsafePathError extends Error {
|
|
1386
|
+
// Not a parameter property: Node's --experimental-strip-types rejects those,
|
|
1387
|
+
// and these files are meant to run under it directly.
|
|
1388
|
+
segment;
|
|
1389
|
+
constructor(segment) {
|
|
1390
|
+
super(`unsafe path segment: ${String(segment)}`);
|
|
1391
|
+
this.segment = segment;
|
|
1392
|
+
this.name = "UnsafePathError";
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
/**
|
|
1396
|
+
* Verb, arity and payload shape for a **decoded** op: paths inline, no `#`, no
|
|
1397
|
+
* short forms. `apply` uses this.
|
|
1398
|
+
*
|
|
1399
|
+
* Validating `Op` against the wire grammar would be laxer than the type: a
|
|
1400
|
+
* two-element `["s", value]` would pass, and `apply` would then read the value as
|
|
1401
|
+
* a path. Each vocabulary gets the validator that matches it.
|
|
1402
|
+
*/
|
|
1403
|
+
export function assertValidOp(op) {
|
|
1404
|
+
if (!Array.isArray(op) || op.length === 0)
|
|
1405
|
+
throw new TypeError("op is not a tuple");
|
|
1406
|
+
switch (op[0]) {
|
|
1407
|
+
case "r":
|
|
1408
|
+
if (op.length !== 2)
|
|
1409
|
+
throw new TypeError("r arity");
|
|
1410
|
+
return;
|
|
1411
|
+
case "s":
|
|
1412
|
+
if (op.length !== 3)
|
|
1413
|
+
throw new TypeError("s arity");
|
|
1414
|
+
assertPathArg(op[1], true);
|
|
1415
|
+
return;
|
|
1416
|
+
case "d":
|
|
1417
|
+
if (op.length !== 2)
|
|
1418
|
+
throw new TypeError("d arity");
|
|
1419
|
+
assertPathArg(op[1], true);
|
|
1420
|
+
return;
|
|
1421
|
+
case "a":
|
|
1422
|
+
if (op.length !== 3 || typeof op[2] !== "string")
|
|
1423
|
+
throw new TypeError("a shape");
|
|
1424
|
+
assertPathArg(op[1], true);
|
|
1425
|
+
return;
|
|
1426
|
+
case "t":
|
|
1427
|
+
if (op.length !== 3 || !Number.isInteger(op[2]) || op[2] < 0)
|
|
1428
|
+
throw new TypeError("t shape");
|
|
1429
|
+
assertPathArg(op[1], true);
|
|
1430
|
+
return;
|
|
1431
|
+
case "p": {
|
|
1432
|
+
if (op.length !== 5)
|
|
1433
|
+
throw new TypeError("p arity");
|
|
1434
|
+
assertPathArg(op[1]);
|
|
1435
|
+
if (!Number.isInteger(op[2]) || op[2] < 0)
|
|
1436
|
+
throw new TypeError("p index");
|
|
1437
|
+
if (!Number.isInteger(op[3]) || op[3] < 0)
|
|
1438
|
+
throw new TypeError("p remove");
|
|
1439
|
+
if (!Array.isArray(op[4]))
|
|
1440
|
+
throw new TypeError("p items");
|
|
1441
|
+
return;
|
|
1442
|
+
}
|
|
1443
|
+
// Silently skipping an unknown verb is how a newer producer's op vanishes.
|
|
1444
|
+
default:
|
|
1445
|
+
throw new TypeError(`unknown op verb: ${String(op[0])}`);
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
function assertPathArg(p, nonEmpty = false) {
|
|
1449
|
+
if (!Array.isArray(p))
|
|
1450
|
+
throw new TypeError("path is not an array");
|
|
1451
|
+
if (nonEmpty && p.length === 0)
|
|
1452
|
+
throw new TypeError("path is empty");
|
|
1453
|
+
assertSafePath(p);
|
|
1454
|
+
}
|
|
1455
|
+
/** The same, for the wire grammar: ids and short forms are legal here. */
|
|
1456
|
+
export function assertValidWireOp(op) {
|
|
1457
|
+
if (!Array.isArray(op) || op.length === 0)
|
|
1458
|
+
throw new TypeError("op is not a tuple");
|
|
1459
|
+
const [verb] = op;
|
|
1460
|
+
const okRef = (r) => {
|
|
1461
|
+
if (typeof r === "number") {
|
|
1462
|
+
if (!Number.isInteger(r) || r < 0)
|
|
1463
|
+
throw new TypeError("bad path id");
|
|
1464
|
+
return;
|
|
1465
|
+
}
|
|
1466
|
+
// A string is not a path. Unchecked, `"a".slice(0, -1)` is `""`, so it
|
|
1467
|
+
// resolves to the ROOT and writes there — a path that is not a path, accepted.
|
|
1468
|
+
if (!Array.isArray(r))
|
|
1469
|
+
throw new TypeError("path is not an array");
|
|
1470
|
+
assertSafePath(r);
|
|
1471
|
+
};
|
|
1472
|
+
switch (verb) {
|
|
1473
|
+
case "r":
|
|
1474
|
+
if (op.length !== 2)
|
|
1475
|
+
throw new TypeError("r arity");
|
|
1476
|
+
return;
|
|
1477
|
+
case "s":
|
|
1478
|
+
if (op.length === 3)
|
|
1479
|
+
okRef(op[1]);
|
|
1480
|
+
else if (op.length !== 2)
|
|
1481
|
+
throw new TypeError("s arity");
|
|
1482
|
+
return;
|
|
1483
|
+
case "d":
|
|
1484
|
+
if (op.length === 2)
|
|
1485
|
+
okRef(op[1]);
|
|
1486
|
+
else if (op.length !== 1)
|
|
1487
|
+
throw new TypeError("d arity");
|
|
1488
|
+
return;
|
|
1489
|
+
case "a":
|
|
1490
|
+
if (op.length === 3) {
|
|
1491
|
+
okRef(op[1]);
|
|
1492
|
+
if (typeof op[2] !== "string")
|
|
1493
|
+
throw new TypeError("a value");
|
|
1494
|
+
}
|
|
1495
|
+
else if (op.length === 2) {
|
|
1496
|
+
if (typeof op[1] !== "string")
|
|
1497
|
+
throw new TypeError("a value");
|
|
1498
|
+
}
|
|
1499
|
+
else
|
|
1500
|
+
throw new TypeError("a arity");
|
|
1501
|
+
return;
|
|
1502
|
+
case "t":
|
|
1503
|
+
if (op.length === 3) {
|
|
1504
|
+
okRef(op[1]);
|
|
1505
|
+
if (!Number.isInteger(op[2]) || op[2] < 0)
|
|
1506
|
+
throw new TypeError("t count");
|
|
1507
|
+
}
|
|
1508
|
+
else if (op.length === 2) {
|
|
1509
|
+
if (!Number.isInteger(op[1]) || op[1] < 0)
|
|
1510
|
+
throw new TypeError("t count");
|
|
1511
|
+
}
|
|
1512
|
+
else
|
|
1513
|
+
throw new TypeError("t arity");
|
|
1514
|
+
return;
|
|
1515
|
+
case "p": {
|
|
1516
|
+
const [i, r, items] = op.length === 5 ? [op[2], op[3], op[4]] : op.length === 4 ? [op[1], op[2], op[3]] : [];
|
|
1517
|
+
if (items === undefined)
|
|
1518
|
+
throw new TypeError("p arity");
|
|
1519
|
+
if (op.length === 5)
|
|
1520
|
+
okRef(op[1]);
|
|
1521
|
+
if (!Number.isInteger(i) || i < 0)
|
|
1522
|
+
throw new TypeError("p index");
|
|
1523
|
+
if (!Number.isInteger(r) || r < 0)
|
|
1524
|
+
throw new TypeError("p remove");
|
|
1525
|
+
if (!Array.isArray(items))
|
|
1526
|
+
throw new TypeError("p items");
|
|
1527
|
+
return;
|
|
1528
|
+
}
|
|
1529
|
+
case "#": {
|
|
1530
|
+
if (op.length !== 3 || !Number.isInteger(op[1]) || op[1] < 0 || !Array.isArray(op[2])) {
|
|
1531
|
+
throw new TypeError("# shape");
|
|
1532
|
+
}
|
|
1533
|
+
assertSafePath(op[2]);
|
|
1534
|
+
return;
|
|
1535
|
+
}
|
|
1536
|
+
// Silently skipping an unknown verb is how a newer producer's op vanishes.
|
|
1537
|
+
default:
|
|
1538
|
+
throw new TypeError(`unknown op verb: ${String(verb)}`);
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
export function assertSafePath(path) {
|
|
1542
|
+
for (const seg of path) {
|
|
1543
|
+
if (typeof seg === "string") {
|
|
1544
|
+
if (RESERVED_SEGMENTS.has(seg))
|
|
1545
|
+
throw new UnsafePathError(seg);
|
|
1546
|
+
}
|
|
1547
|
+
else if (!Number.isInteger(seg) || seg < 0) {
|
|
1548
|
+
throw new UnsafePathError(seg);
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
/**
|
|
1553
|
+
* An index may address an existing element or append exactly one past the end.
|
|
1554
|
+
*
|
|
1555
|
+
* This is not an arbitrary cap — it is what keeps the value a `JsonValue`. A
|
|
1556
|
+
* sparse array does not survive a JSON round trip: holes serialise to `null` and
|
|
1557
|
+
* return as real properties, so `arr[7] = x` on a length-3 array already produces
|
|
1558
|
+
* state a replica cannot match. Rejecting the write is more honest than silently
|
|
1559
|
+
* diverging.
|
|
1560
|
+
*
|
|
1561
|
+
* It also removes the denial of service it would otherwise permit:
|
|
1562
|
+
* `["s", ["xs", 4294967290], 1]` allocates a 4.29-billion-entry array from one op.
|
|
1563
|
+
* Growth stays possible and stays proportional — the tracker already emits
|
|
1564
|
+
* `arr.length = n` as a splice of explicit nulls, whose op size grows with the
|
|
1565
|
+
* gap, so a large growth costs a large op rather than a small one.
|
|
1566
|
+
*/
|
|
1567
|
+
function assertIndexInRange(parent, index) {
|
|
1568
|
+
if (index > parent.length)
|
|
1569
|
+
throw new UnsafePathError(index);
|
|
1570
|
+
}
|
|
1571
|
+
// ─── Applier ─────────────────────────────────────────────────────────────────
|
|
1572
|
+
export class PathError extends Error {
|
|
1573
|
+
path;
|
|
1574
|
+
constructor(path) {
|
|
1575
|
+
super(`unresolvable path: ${JSON.stringify(path)}`);
|
|
1576
|
+
this.path = path;
|
|
1577
|
+
this.name = "PathError";
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
/**
|
|
1581
|
+
* Apply ops to a plain mutable value. Returns the value, because `r` replaces it
|
|
1582
|
+
* outright and cannot be done in place.
|
|
1583
|
+
*
|
|
1584
|
+
* Takes decoded ops. Path ids and omitted paths are a wire concern — run
|
|
1585
|
+
* `decode` first if the ops came from a boundary.
|
|
1586
|
+
*/
|
|
1587
|
+
export function apply(target, ops) {
|
|
1588
|
+
return applyOps(target, ops);
|
|
1589
|
+
}
|
|
1590
|
+
function applyOps(target, ops) {
|
|
1591
|
+
let root = target;
|
|
1592
|
+
for (const op of ops) {
|
|
1593
|
+
assertValidOp(op);
|
|
1594
|
+
if (op[0] === "r") {
|
|
1595
|
+
// Adopted, not copied. The consumer owns the batch it was handed.
|
|
1596
|
+
//
|
|
1597
|
+
// Fanning one batch out to several consumers in-process therefore makes
|
|
1598
|
+
// their replicas alias each other. That is an ownership rule, not a
|
|
1599
|
+
// defect: copy the batch at the fan-out point, or let each consumer
|
|
1600
|
+
// decode its own. A batch that crosses a real boundary is already
|
|
1601
|
+
// distinct, because serialisation produces fresh objects.
|
|
1602
|
+
root = op[1];
|
|
1603
|
+
continue;
|
|
1604
|
+
}
|
|
1605
|
+
const path = op[1];
|
|
1606
|
+
assertSafePath(path);
|
|
1607
|
+
if (op[0] === "p") {
|
|
1608
|
+
const target_ = path.length === 0 ? root : resolve(root, path);
|
|
1609
|
+
if (!Array.isArray(target_))
|
|
1610
|
+
throw new PathError(path);
|
|
1611
|
+
target_.splice(op[2], op[3]);
|
|
1612
|
+
const chunkSize = 10_000;
|
|
1613
|
+
for (let offset = 0; offset < op[4].length; offset += chunkSize) {
|
|
1614
|
+
target_.splice(op[2] + offset, 0, ...op[4].slice(offset, offset + chunkSize));
|
|
1615
|
+
}
|
|
1616
|
+
continue;
|
|
1617
|
+
}
|
|
1618
|
+
// s/d/a/t can never target the root — the type forbids it.
|
|
1619
|
+
const parent = resolve(root, path.slice(0, -1));
|
|
1620
|
+
const key = path[path.length - 1];
|
|
1621
|
+
if (Array.isArray(parent)) {
|
|
1622
|
+
if (typeof key !== "number")
|
|
1623
|
+
throw new UnsafePathError(key);
|
|
1624
|
+
assertIndexInRange(parent, key);
|
|
1625
|
+
}
|
|
1626
|
+
// defineProperty rather than assignment: a setter inherited from the prototype
|
|
1627
|
+
// chain would otherwise run on write.
|
|
1628
|
+
const write = (value) => {
|
|
1629
|
+
Object.defineProperty(parent, key, { value, writable: true, enumerable: true, configurable: true });
|
|
1630
|
+
};
|
|
1631
|
+
const read = () => (Object.hasOwn(parent, key) ? parent[key] : undefined);
|
|
1632
|
+
switch (op[0]) {
|
|
1633
|
+
case "s":
|
|
1634
|
+
write(op[2]);
|
|
1635
|
+
break;
|
|
1636
|
+
case "d":
|
|
1637
|
+
if (Array.isArray(parent)) {
|
|
1638
|
+
if (typeof key !== "number" || key >= parent.length)
|
|
1639
|
+
throw new PathError(path);
|
|
1640
|
+
parent.splice(key, 1);
|
|
1641
|
+
}
|
|
1642
|
+
else
|
|
1643
|
+
delete parent[key];
|
|
1644
|
+
break;
|
|
1645
|
+
case "a": {
|
|
1646
|
+
const current = read();
|
|
1647
|
+
if (typeof current !== "string")
|
|
1648
|
+
throw new PathError(path);
|
|
1649
|
+
write(`${current}${op[2]}`);
|
|
1650
|
+
break;
|
|
1651
|
+
}
|
|
1652
|
+
case "t": {
|
|
1653
|
+
const current = read();
|
|
1654
|
+
if (typeof current !== "string")
|
|
1655
|
+
throw new PathError(path);
|
|
1656
|
+
write(current.slice(op[2]));
|
|
1657
|
+
break;
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
return root;
|
|
1662
|
+
}
|
|
1663
|
+
/** Apply decoded operations without mutating the previous immutable value. */
|
|
1664
|
+
export function applyImmutable(target, ops) {
|
|
1665
|
+
let root = target;
|
|
1666
|
+
for (const op of ops) {
|
|
1667
|
+
if (op[0] === "r") {
|
|
1668
|
+
assertValidOp(op);
|
|
1669
|
+
root = op[1];
|
|
1670
|
+
continue;
|
|
1671
|
+
}
|
|
1672
|
+
root = copyContainers(root, op[0] === "p" ? op[1] : op[1].slice(0, -1));
|
|
1673
|
+
root = applyOps(root, [op]);
|
|
1674
|
+
}
|
|
1675
|
+
return root;
|
|
1676
|
+
}
|
|
1677
|
+
function copyContainers(root, path) {
|
|
1678
|
+
const copy = (value) => {
|
|
1679
|
+
if (Array.isArray(value))
|
|
1680
|
+
return value.slice();
|
|
1681
|
+
if (!isObj(value))
|
|
1682
|
+
throw new PathError(path);
|
|
1683
|
+
const result = Object.create(Object.getPrototypeOf(value) === null ? null : Object.prototype);
|
|
1684
|
+
for (const key of Object.keys(value)) {
|
|
1685
|
+
Object.defineProperty(result, key, {
|
|
1686
|
+
value: value[key],
|
|
1687
|
+
writable: true,
|
|
1688
|
+
enumerable: true,
|
|
1689
|
+
configurable: true,
|
|
1690
|
+
});
|
|
1691
|
+
}
|
|
1692
|
+
return result;
|
|
1693
|
+
};
|
|
1694
|
+
const copiedRoot = copy(root);
|
|
1695
|
+
let source = root;
|
|
1696
|
+
let destination = copiedRoot;
|
|
1697
|
+
for (const segment of path) {
|
|
1698
|
+
if (!isObj(source) || !Object.hasOwn(source, segment))
|
|
1699
|
+
throw new PathError(path);
|
|
1700
|
+
if (Array.isArray(source) && typeof segment !== "number")
|
|
1701
|
+
throw new UnsafePathError(segment);
|
|
1702
|
+
const child = source[segment];
|
|
1703
|
+
const copiedChild = copy(child);
|
|
1704
|
+
Object.defineProperty(destination, segment, {
|
|
1705
|
+
value: copiedChild,
|
|
1706
|
+
writable: true,
|
|
1707
|
+
enumerable: true,
|
|
1708
|
+
configurable: true,
|
|
1709
|
+
});
|
|
1710
|
+
source = child;
|
|
1711
|
+
destination = copiedChild;
|
|
1712
|
+
}
|
|
1713
|
+
return copiedRoot;
|
|
1714
|
+
}
|
|
1715
|
+
function resolveValue(root, path) {
|
|
1716
|
+
let node = root;
|
|
1717
|
+
for (const seg of path) {
|
|
1718
|
+
if (!isObj(node))
|
|
1719
|
+
throw new PathError(path);
|
|
1720
|
+
if (Array.isArray(node) && typeof seg !== "number")
|
|
1721
|
+
throw new UnsafePathError(seg);
|
|
1722
|
+
// Own properties only: an inherited getter must not run, and a walk must not
|
|
1723
|
+
// escape the value into the prototype chain.
|
|
1724
|
+
if (!Object.hasOwn(node, seg))
|
|
1725
|
+
throw new PathError(path);
|
|
1726
|
+
node = node[seg];
|
|
1727
|
+
}
|
|
1728
|
+
return node;
|
|
1729
|
+
}
|
|
1730
|
+
function resolve(root, path) {
|
|
1731
|
+
const node = resolveValue(root, path);
|
|
1732
|
+
if (!isObj(node))
|
|
1733
|
+
throw new PathError(path);
|
|
1734
|
+
return node;
|
|
1735
|
+
}
|
|
1736
|
+
// ─── Codec ───────────────────────────────────────────────────────────────────
|
|
1737
|
+
//
|
|
1738
|
+
// Path interning and arity omission live between the tracker and a boundary;
|
|
1739
|
+
// `Op` and `apply` know nothing about them.
|
|
1740
|
+
//
|
|
1741
|
+
// ONE PAIR PER INDEPENDENT STATE STREAM. Every decoder must observe exactly the
|
|
1742
|
+
// batches encoded by its matching encoder, beginning with that state's base.
|
|
1743
|
+
// Sharing a transport connection does not make separately hydrated states one
|
|
1744
|
+
// stream.
|
|
1745
|
+
const pathKey = (path) => JSON.stringify(path);
|
|
1746
|
+
/**
|
|
1747
|
+
* Intern on SECOND use. A definition costs more than the path it replaces, so
|
|
1748
|
+
* interning on first use loses on the many paths written exactly once.
|
|
1749
|
+
*/
|
|
1750
|
+
export function encoder() {
|
|
1751
|
+
const seen = new Set();
|
|
1752
|
+
const ids = new Map();
|
|
1753
|
+
let nextId = 0;
|
|
1754
|
+
let previous; // last path in THIS batch
|
|
1755
|
+
return {
|
|
1756
|
+
encode(ops) {
|
|
1757
|
+
// Arity omission is scoped to a batch. Letting it span batches would make
|
|
1758
|
+
// a batch's first op depend on the previous batch's last one, so a reader
|
|
1759
|
+
// that skips or reorders a batch decodes into the wrong path. Ids are the
|
|
1760
|
+
// only cross-batch state, and the dictionary makes those explicit.
|
|
1761
|
+
previous = undefined;
|
|
1762
|
+
const out = [];
|
|
1763
|
+
for (const op of ops) {
|
|
1764
|
+
if (op[0] === "r") {
|
|
1765
|
+
out.push(op);
|
|
1766
|
+
// A base batch is a RECOVERY POINT: a reader replays from the last one
|
|
1767
|
+
// with a fresh decoder. So everything after it must be self-contained.
|
|
1768
|
+
// Keeping ids across a replacement emits references to definitions the
|
|
1769
|
+
// reader never saw — recovery fails with an unresolvable path id.
|
|
1770
|
+
seen.clear();
|
|
1771
|
+
ids.clear();
|
|
1772
|
+
nextId = 0;
|
|
1773
|
+
previous = undefined;
|
|
1774
|
+
continue;
|
|
1775
|
+
}
|
|
1776
|
+
const path = op[1];
|
|
1777
|
+
const key = pathKey(path);
|
|
1778
|
+
// Same path as the previous op: drop the ref entirely.
|
|
1779
|
+
if (key === previous) {
|
|
1780
|
+
switch (op[0]) {
|
|
1781
|
+
case "s":
|
|
1782
|
+
out.push(["s", op[2]]);
|
|
1783
|
+
break;
|
|
1784
|
+
case "d":
|
|
1785
|
+
out.push(["d"]);
|
|
1786
|
+
break;
|
|
1787
|
+
case "a":
|
|
1788
|
+
out.push(["a", op[2]]);
|
|
1789
|
+
break;
|
|
1790
|
+
case "t":
|
|
1791
|
+
out.push(["t", op[2]]);
|
|
1792
|
+
break;
|
|
1793
|
+
case "p":
|
|
1794
|
+
out.push(["p", op[2], op[3], op[4]]);
|
|
1795
|
+
break;
|
|
1796
|
+
}
|
|
1797
|
+
continue;
|
|
1798
|
+
}
|
|
1799
|
+
let ref = path;
|
|
1800
|
+
const existing = ids.get(key);
|
|
1801
|
+
if (existing !== undefined) {
|
|
1802
|
+
ref = existing;
|
|
1803
|
+
}
|
|
1804
|
+
else if (seen.has(key)) {
|
|
1805
|
+
const id = nextId++;
|
|
1806
|
+
ids.set(key, id);
|
|
1807
|
+
out.push(["#", id, path]); // second use: define, then reference
|
|
1808
|
+
ref = id;
|
|
1809
|
+
}
|
|
1810
|
+
else {
|
|
1811
|
+
seen.add(key); // first use: inline
|
|
1812
|
+
}
|
|
1813
|
+
switch (op[0]) {
|
|
1814
|
+
case "s":
|
|
1815
|
+
out.push(["s", ref, op[2]]);
|
|
1816
|
+
break;
|
|
1817
|
+
case "d":
|
|
1818
|
+
out.push(["d", ref]);
|
|
1819
|
+
break;
|
|
1820
|
+
case "a":
|
|
1821
|
+
out.push(["a", ref, op[2]]);
|
|
1822
|
+
break;
|
|
1823
|
+
case "t":
|
|
1824
|
+
out.push(["t", ref, op[2]]);
|
|
1825
|
+
break;
|
|
1826
|
+
case "p":
|
|
1827
|
+
out.push(["p", ref, op[2], op[3], op[4]]);
|
|
1828
|
+
break;
|
|
1829
|
+
}
|
|
1830
|
+
previous = key;
|
|
1831
|
+
}
|
|
1832
|
+
return out;
|
|
1833
|
+
},
|
|
1834
|
+
};
|
|
1835
|
+
}
|
|
1836
|
+
export function decoder() {
|
|
1837
|
+
const paths = new Map();
|
|
1838
|
+
return {
|
|
1839
|
+
decode(wire) {
|
|
1840
|
+
let previous; // scoped to the batch, as in encode
|
|
1841
|
+
const out = [];
|
|
1842
|
+
for (const op of wire) {
|
|
1843
|
+
assertValidWireOp(op);
|
|
1844
|
+
if (op[0] === "#") {
|
|
1845
|
+
assertSafePath(op[2]);
|
|
1846
|
+
paths.set(op[1], op[2]);
|
|
1847
|
+
continue;
|
|
1848
|
+
}
|
|
1849
|
+
if (op[0] === "r") {
|
|
1850
|
+
out.push(op);
|
|
1851
|
+
paths.clear();
|
|
1852
|
+
previous = undefined;
|
|
1853
|
+
continue;
|
|
1854
|
+
}
|
|
1855
|
+
// Arity tells us whether a ref is present: the short forms omit it.
|
|
1856
|
+
const short = (op[0] === "d" && op.length === 1) ||
|
|
1857
|
+
(op[0] !== "d" && op[0] !== "p" && op.length === 2) ||
|
|
1858
|
+
(op[0] === "p" && op.length === 4);
|
|
1859
|
+
let path;
|
|
1860
|
+
if (short) {
|
|
1861
|
+
if (previous === undefined)
|
|
1862
|
+
throw new PathError([]);
|
|
1863
|
+
path = previous;
|
|
1864
|
+
}
|
|
1865
|
+
else {
|
|
1866
|
+
const ref = op[1];
|
|
1867
|
+
if (typeof ref === "number") {
|
|
1868
|
+
const resolved = paths.get(ref);
|
|
1869
|
+
if (resolved === undefined)
|
|
1870
|
+
throw new PathError(ref);
|
|
1871
|
+
path = resolved;
|
|
1872
|
+
}
|
|
1873
|
+
else {
|
|
1874
|
+
path = ref;
|
|
1875
|
+
}
|
|
1876
|
+
previous = path;
|
|
1877
|
+
}
|
|
1878
|
+
if (op[0] !== "p" && path.length === 0)
|
|
1879
|
+
throw new PathError(path);
|
|
1880
|
+
switch (op[0]) {
|
|
1881
|
+
case "s":
|
|
1882
|
+
out.push(["s", path, (short ? op[1] : op[2])]);
|
|
1883
|
+
break;
|
|
1884
|
+
case "d":
|
|
1885
|
+
out.push(["d", path]);
|
|
1886
|
+
break;
|
|
1887
|
+
case "a":
|
|
1888
|
+
out.push(["a", path, (short ? op[1] : op[2])]);
|
|
1889
|
+
break;
|
|
1890
|
+
case "t":
|
|
1891
|
+
out.push(["t", path, (short ? op[1] : op[2])]);
|
|
1892
|
+
break;
|
|
1893
|
+
case "p": {
|
|
1894
|
+
const [i, r, items] = short
|
|
1895
|
+
? [op[1], op[2], op[3]]
|
|
1896
|
+
: [op[2], op[3], op[4]];
|
|
1897
|
+
out.push(["p", path, i, r, items]);
|
|
1898
|
+
break;
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
return out;
|
|
1903
|
+
},
|
|
1904
|
+
};
|
|
1905
|
+
}
|
|
1906
|
+
//# sourceMappingURL=index.js.map
|