@treenity/core 1.0.47 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chain.d.ts +20 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +59 -0
- package/dist/chain.js.map +1 -0
- package/dist/client/handle.d.ts +13 -0
- package/dist/client/handle.d.ts.map +1 -0
- package/dist/client/handle.js +46 -0
- package/dist/client/handle.js.map +1 -0
- package/dist/client/index.d.ts +21 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +5 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/trpc.d.ts +13 -0
- package/dist/client/trpc.d.ts.map +1 -0
- package/dist/client/trpc.js +78 -0
- package/dist/client/trpc.js.map +1 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +2 -0
- package/dist/client.js.map +1 -0
- package/dist/comp/handle.d.ts +14 -0
- package/dist/comp/handle.d.ts.map +1 -0
- package/dist/comp/handle.js +21 -0
- package/dist/comp/handle.js.map +1 -0
- package/dist/comp/index.d.ts +42 -0
- package/dist/comp/index.d.ts.map +1 -0
- package/dist/comp/index.js +126 -0
- package/dist/comp/index.js.map +1 -0
- package/dist/comp/needs.d.ts +26 -0
- package/dist/comp/needs.d.ts.map +1 -0
- package/dist/comp/needs.js +101 -0
- package/dist/comp/needs.js.map +1 -0
- package/dist/comp/validate.d.ts +13 -0
- package/dist/comp/validate.d.ts.map +1 -0
- package/dist/comp/validate.js +117 -0
- package/dist/comp/validate.js.map +1 -0
- package/dist/comp.d.ts +2 -0
- package/dist/comp.d.ts.map +1 -0
- package/dist/comp.js +2 -0
- package/dist/comp.js.map +1 -0
- package/dist/contexts/schema/index.d.ts +7 -0
- package/dist/contexts/schema/index.d.ts.map +1 -0
- package/dist/contexts/schema/index.js +2 -0
- package/dist/contexts/schema/index.js.map +1 -0
- package/dist/contexts/schema.d.ts +2 -0
- package/dist/contexts/schema.d.ts.map +1 -0
- package/dist/contexts/schema.js +2 -0
- package/dist/contexts/schema.js.map +1 -0
- package/dist/contexts/service/index.d.ts +31 -0
- package/dist/contexts/service/index.d.ts.map +1 -0
- package/dist/contexts/service/index.js +16 -0
- package/dist/contexts/service/index.js.map +1 -0
- package/dist/contexts/service.d.ts +1 -14
- package/dist/contexts/service.d.ts.map +1 -1
- package/dist/contexts/service.js +2 -0
- package/dist/contexts/service.js.map +1 -0
- package/dist/contexts/telegram/index.d.ts +19 -0
- package/dist/contexts/telegram/index.d.ts.map +1 -0
- package/dist/contexts/telegram/index.js +89 -0
- package/dist/contexts/telegram/index.js.map +1 -0
- package/dist/contexts/text/index.d.ts +7 -0
- package/dist/contexts/text/index.d.ts.map +1 -0
- package/dist/contexts/text/index.js +9 -0
- package/dist/contexts/text/index.js.map +1 -0
- package/dist/contexts/text.d.ts +2 -0
- package/dist/contexts/text.d.ts.map +1 -0
- package/dist/contexts/text.js +2 -0
- package/dist/contexts/text.js.map +1 -0
- package/dist/core/component.d.ts +41 -0
- package/dist/core/component.d.ts.map +1 -0
- package/dist/core/component.js +105 -0
- package/dist/core/component.js.map +1 -0
- package/dist/core/context.d.ts +5 -0
- package/dist/core/context.d.ts.map +1 -0
- package/dist/core/context.js +3 -0
- package/dist/core/context.js.map +1 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +8 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/path.d.ts +7 -0
- package/dist/core/path.d.ts.map +1 -0
- package/dist/core/path.js +37 -0
- package/dist/core/path.js.map +1 -0
- package/dist/core/registry.d.ts +16 -0
- package/dist/core/registry.d.ts.map +1 -0
- package/dist/core/registry.js +100 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/core.d.ts +2 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +2 -0
- package/dist/core.js.map +1 -0
- package/dist/log.d.ts +8 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +31 -0
- package/dist/log.js.map +1 -0
- package/dist/mod/discover.d.ts +4 -0
- package/dist/mod/discover.d.ts.map +1 -0
- package/dist/mod/discover.js +103 -0
- package/dist/mod/discover.js.map +1 -0
- package/dist/mod/examples/ticker/seed.d.ts +3 -0
- package/dist/mod/examples/ticker/seed.d.ts.map +1 -0
- package/dist/mod/examples/ticker/seed.js +16 -0
- package/dist/mod/examples/ticker/seed.js.map +1 -0
- package/dist/mod/examples/ticker/service.d.ts +2 -0
- package/dist/mod/examples/ticker/service.d.ts.map +1 -0
- package/dist/mod/examples/ticker/service.js +18 -0
- package/dist/mod/examples/ticker/service.js.map +1 -0
- package/dist/mod/examples/ticker/types.d.ts +16 -0
- package/dist/mod/examples/ticker/types.d.ts.map +1 -0
- package/dist/mod/examples/ticker/types.js +20 -0
- package/dist/mod/examples/ticker/types.js.map +1 -0
- package/dist/mod/examples/ticker/view.d.ts +2 -0
- package/dist/mod/examples/ticker/view.d.ts.map +1 -0
- package/dist/mod/examples/ticker/view.js +10 -0
- package/dist/mod/examples/ticker/view.js.map +1 -0
- package/dist/mod/index.d.ts +11 -0
- package/dist/mod/index.d.ts.map +1 -0
- package/dist/mod/index.js +8 -0
- package/dist/mod/index.js.map +1 -0
- package/dist/mod/loader.d.ts +18 -0
- package/dist/mod/loader.d.ts.map +1 -0
- package/dist/mod/loader.js +154 -0
- package/dist/mod/loader.js.map +1 -0
- package/dist/mod/optimistic.d.ts +34 -0
- package/dist/mod/optimistic.d.ts.map +1 -0
- package/dist/mod/optimistic.js +176 -0
- package/dist/mod/optimistic.js.map +1 -0
- package/dist/mod/prefab.d.ts +18 -0
- package/dist/mod/prefab.d.ts.map +1 -0
- package/dist/mod/prefab.js +42 -0
- package/dist/mod/prefab.js.map +1 -0
- package/dist/mod/tracking.d.ts +8 -0
- package/dist/mod/tracking.d.ts.map +1 -0
- package/dist/mod/tracking.js +44 -0
- package/dist/mod/tracking.js.map +1 -0
- package/dist/mod/types.d.ts +31 -0
- package/dist/mod/types.d.ts.map +1 -0
- package/dist/mod/types.js +5 -0
- package/dist/mod/types.js.map +1 -0
- package/dist/mod.d.ts +2 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +2 -0
- package/dist/mod.js.map +1 -0
- package/dist/mods/autostart/server.d.ts +2 -0
- package/dist/mods/autostart/server.d.ts.map +1 -0
- package/dist/mods/autostart/server.js +2 -0
- package/dist/mods/autostart/server.js.map +1 -0
- package/dist/mods/autostart/service.d.ts +14 -0
- package/dist/mods/autostart/service.d.ts.map +1 -0
- package/dist/mods/autostart/service.js +88 -0
- package/dist/mods/autostart/service.js.map +1 -0
- package/dist/mods/llm/index.d.ts +13 -0
- package/dist/mods/llm/index.d.ts.map +1 -0
- package/dist/mods/llm/index.js +43 -0
- package/dist/mods/llm/index.js.map +1 -0
- package/dist/mods/llm/server.d.ts +2 -0
- package/dist/mods/llm/server.d.ts.map +1 -0
- package/dist/mods/llm/server.js +2 -0
- package/dist/mods/llm/server.js.map +1 -0
- package/dist/mods/mcp/server.d.ts +3 -0
- package/dist/mods/mcp/server.d.ts.map +1 -0
- package/dist/mods/mcp/server.js +3 -0
- package/dist/mods/mcp/server.js.map +1 -0
- package/dist/mods/mcp/service.d.ts +2 -0
- package/dist/mods/mcp/service.d.ts.map +1 -0
- package/dist/mods/mcp/service.js +17 -0
- package/dist/mods/mcp/service.js.map +1 -0
- package/dist/mods/mcp/types.d.ts +5 -0
- package/dist/mods/mcp/types.d.ts.map +1 -0
- package/dist/mods/mcp/types.js +7 -0
- package/dist/mods/mcp/types.js.map +1 -0
- package/dist/mods/treenity/agent-port.d.ts +2 -0
- package/dist/mods/treenity/agent-port.d.ts.map +1 -0
- package/dist/mods/treenity/agent-port.js +76 -0
- package/dist/mods/treenity/agent-port.js.map +1 -0
- package/dist/mods/treenity/groups.d.ts +2 -0
- package/dist/mods/treenity/groups.d.ts.map +1 -0
- package/dist/mods/treenity/groups.js +18 -0
- package/dist/mods/treenity/groups.js.map +1 -0
- package/dist/mods/treenity/mod-type.d.ts +2 -0
- package/dist/mods/treenity/mod-type.d.ts.map +1 -0
- package/dist/mods/treenity/mod-type.js +9 -0
- package/dist/mods/treenity/mod-type.js.map +1 -0
- package/dist/mods/treenity/seed.d.ts +2 -0
- package/dist/mods/treenity/seed.d.ts.map +1 -0
- package/dist/mods/treenity/seed.js +53 -0
- package/dist/mods/treenity/seed.js.map +1 -0
- package/dist/mods/treenity/server.d.ts +5 -0
- package/dist/mods/treenity/server.d.ts.map +1 -0
- package/dist/mods/treenity/server.js +5 -0
- package/dist/mods/treenity/server.js.map +1 -0
- package/dist/mods/treenity/system.d.ts +36 -0
- package/dist/mods/treenity/system.d.ts.map +1 -0
- package/dist/mods/treenity/system.js +61 -0
- package/dist/mods/treenity/system.js.map +1 -0
- package/dist/mods/uix/client.d.ts +3 -0
- package/dist/mods/uix/client.d.ts.map +1 -0
- package/dist/mods/uix/client.js +96 -0
- package/dist/mods/uix/client.js.map +1 -0
- package/dist/mods/uix/compile.d.ts +7 -0
- package/dist/mods/uix/compile.d.ts.map +1 -0
- package/dist/mods/uix/compile.js +94 -0
- package/dist/mods/uix/compile.js.map +1 -0
- package/dist/mods/uix/jsx-parser.d.ts +2 -0
- package/dist/mods/uix/jsx-parser.d.ts.map +1 -0
- package/dist/mods/uix/jsx-parser.js +565 -0
- package/dist/mods/uix/jsx-parser.js.map +1 -0
- package/dist/mods/uix/verify.d.ts +7 -0
- package/dist/mods/uix/verify.d.ts.map +1 -0
- package/dist/mods/uix/verify.js +59 -0
- package/dist/mods/uix/verify.js.map +1 -0
- package/dist/schema/catalog.d.ts +23 -0
- package/dist/schema/catalog.d.ts.map +1 -0
- package/dist/schema/catalog.js +82 -0
- package/dist/schema/catalog.js.map +1 -0
- package/dist/schema/extract-schemas.d.ts +5 -0
- package/dist/schema/extract-schemas.d.ts.map +1 -0
- package/dist/schema/extract-schemas.js +444 -0
- package/dist/schema/extract-schemas.js.map +1 -0
- package/dist/schema/load.d.ts +2 -0
- package/dist/schema/load.d.ts.map +1 -0
- package/dist/schema/load.js +23 -0
- package/dist/schema/load.js.map +1 -0
- package/dist/schema/test-fixture.types.d.ts +2 -0
- package/dist/schema/test-fixture.types.d.ts.map +1 -0
- package/dist/schema/test-fixture.types.js +19 -0
- package/dist/schema/test-fixture.types.js.map +1 -0
- package/dist/schema/test-opaque.d.ts +3 -0
- package/dist/schema/test-opaque.d.ts.map +1 -0
- package/dist/schema/test-opaque.js +43 -0
- package/dist/schema/test-opaque.js.map +1 -0
- package/dist/schema/types.d.ts +37 -0
- package/dist/schema/types.d.ts.map +1 -0
- package/dist/schema/types.js +3 -0
- package/dist/schema/types.js.map +1 -0
- package/dist/server/actions.d.ts +35 -0
- package/dist/server/actions.d.ts.map +1 -0
- package/dist/server/actions.js +170 -0
- package/dist/server/actions.js.map +1 -0
- package/dist/server/agent.d.ts +6 -0
- package/dist/server/agent.d.ts.map +1 -0
- package/dist/server/agent.js +15 -0
- package/dist/server/agent.js.map +1 -0
- package/dist/server/auth.d.ts +39 -0
- package/dist/server/auth.d.ts.map +1 -0
- package/dist/server/auth.js +335 -0
- package/dist/server/auth.js.map +1 -0
- package/dist/server/client.d.ts +183 -0
- package/dist/server/client.d.ts.map +1 -0
- package/dist/server/client.js +22 -0
- package/dist/server/client.js.map +1 -0
- package/dist/server/cookies.d.ts +5 -0
- package/dist/server/cookies.d.ts.map +1 -0
- package/dist/server/cookies.js +24 -0
- package/dist/server/cookies.js.map +1 -0
- package/dist/server/doc-index.d.ts +38 -0
- package/dist/server/doc-index.d.ts.map +1 -0
- package/dist/server/doc-index.js +244 -0
- package/dist/server/doc-index.js.map +1 -0
- package/dist/server/errors.d.ts +7 -0
- package/dist/server/errors.d.ts.map +1 -0
- package/dist/server/errors.js +11 -0
- package/dist/server/errors.js.map +1 -0
- package/dist/server/factory.d.ts +23 -0
- package/dist/server/factory.d.ts.map +1 -0
- package/dist/server/factory.js +70 -0
- package/dist/server/factory.js.map +1 -0
- package/dist/server/main.d.ts +6 -0
- package/dist/server/main.d.ts.map +1 -0
- package/dist/server/main.js +45 -0
- package/dist/server/main.js.map +1 -0
- package/dist/server/mcp.d.ts +5 -0
- package/dist/server/mcp.d.ts.map +1 -0
- package/dist/server/mcp.js +280 -0
- package/dist/server/mcp.js.map +1 -0
- package/dist/server/migrate.d.ts +3 -0
- package/dist/server/migrate.d.ts.map +1 -0
- package/dist/server/migrate.js +56 -0
- package/dist/server/migrate.js.map +1 -0
- package/dist/server/mod-catalog.d.ts +14 -0
- package/dist/server/mod-catalog.d.ts.map +1 -0
- package/dist/server/mod-catalog.js +40 -0
- package/dist/server/mod-catalog.js.map +1 -0
- package/dist/server/mods-mount.d.ts +4 -0
- package/dist/server/mods-mount.d.ts.map +1 -0
- package/dist/server/mods-mount.js +169 -0
- package/dist/server/mods-mount.js.map +1 -0
- package/dist/server/mount-adapters.d.ts +9 -0
- package/dist/server/mount-adapters.d.ts.map +1 -0
- package/dist/server/mount-adapters.js +75 -0
- package/dist/server/mount-adapters.js.map +1 -0
- package/dist/server/mount.d.ts +3 -0
- package/dist/server/mount.d.ts.map +1 -0
- package/dist/server/mount.js +195 -0
- package/dist/server/mount.js.map +1 -0
- package/dist/server/prefab.d.ts +18 -0
- package/dist/server/prefab.d.ts.map +1 -0
- package/dist/server/prefab.js +70 -0
- package/dist/server/prefab.js.map +1 -0
- package/dist/server/seed/index.d.ts +6 -0
- package/dist/server/seed/index.d.ts.map +1 -0
- package/dist/server/seed/index.js +16 -0
- package/dist/server/seed/index.js.map +1 -0
- package/dist/server/server.d.ts +28 -0
- package/dist/server/server.d.ts.map +1 -0
- package/dist/server/server.js +117 -0
- package/dist/server/server.js.map +1 -0
- package/dist/server/sub.d.ts +34 -0
- package/dist/server/sub.d.ts.map +1 -0
- package/dist/server/sub.js +174 -0
- package/dist/server/sub.js.map +1 -0
- package/dist/server/trpc.d.ts +192 -0
- package/dist/server/trpc.d.ts.map +1 -0
- package/dist/server/trpc.js +319 -0
- package/dist/server/trpc.js.map +1 -0
- package/dist/server/types-mount.d.ts +3 -0
- package/dist/server/types-mount.d.ts.map +1 -0
- package/dist/server/types-mount.js +144 -0
- package/dist/server/types-mount.js.map +1 -0
- package/dist/server/validate.d.ts +3 -0
- package/dist/server/validate.d.ts.map +1 -0
- package/dist/server/validate.js +20 -0
- package/dist/server/validate.js.map +1 -0
- package/dist/server/volatile.d.ts +11 -0
- package/dist/server/volatile.d.ts.map +1 -0
- package/dist/server/volatile.js +26 -0
- package/dist/server/volatile.js.map +1 -0
- package/dist/server/watch.d.ts +23 -0
- package/dist/server/watch.d.ts.map +1 -0
- package/dist/server/watch.js +178 -0
- package/dist/server/watch.js.map +1 -0
- package/dist/tree/cache.d.ts +3 -0
- package/dist/tree/cache.d.ts.map +1 -0
- package/dist/tree/cache.js +48 -0
- package/dist/tree/cache.js.map +1 -0
- package/dist/tree/fs.d.ts +3 -0
- package/dist/tree/fs.d.ts.map +1 -0
- package/dist/tree/fs.js +274 -0
- package/dist/tree/fs.js.map +1 -0
- package/dist/tree/index.d.ts +38 -0
- package/dist/tree/index.d.ts.map +1 -0
- package/dist/tree/index.js +182 -0
- package/dist/tree/index.js.map +1 -0
- package/dist/tree/inflight.d.ts +2 -0
- package/dist/tree/inflight.d.ts.map +1 -0
- package/dist/tree/inflight.js +15 -0
- package/dist/tree/inflight.js.map +1 -0
- package/dist/tree/json-codec.d.ts +2 -0
- package/dist/tree/json-codec.d.ts.map +1 -0
- package/dist/tree/json-codec.js +13 -0
- package/dist/tree/json-codec.js.map +1 -0
- package/dist/tree/mimefs.d.ts +13 -0
- package/dist/tree/mimefs.d.ts.map +1 -0
- package/dist/tree/mimefs.js +124 -0
- package/dist/tree/mimefs.js.map +1 -0
- package/dist/tree/mongo.d.ts +5 -0
- package/dist/tree/mongo.d.ts.map +1 -0
- package/dist/tree/mongo.js +110 -0
- package/dist/tree/mongo.js.map +1 -0
- package/dist/tree/patch.d.ts +30 -0
- package/dist/tree/patch.d.ts.map +1 -0
- package/dist/tree/patch.js +112 -0
- package/dist/tree/patch.js.map +1 -0
- package/dist/tree/query.d.ts +12 -0
- package/dist/tree/query.d.ts.map +1 -0
- package/dist/tree/query.js +61 -0
- package/dist/tree/query.js.map +1 -0
- package/dist/tree/repath.d.ts +3 -0
- package/dist/tree/repath.d.ts.map +1 -0
- package/dist/tree/repath.js +38 -0
- package/dist/tree/repath.js.map +1 -0
- package/dist/tree-chain.d.ts +18 -0
- package/dist/tree-chain.d.ts.map +1 -0
- package/dist/tree-chain.js +109 -0
- package/dist/tree-chain.js.map +1 -0
- package/dist/tree.d.ts +2 -0
- package/dist/tree.d.ts.map +1 -0
- package/dist/tree.js +2 -0
- package/dist/tree.js.map +1 -0
- package/dist/uri.d.ts +11 -0
- package/dist/uri.d.ts.map +1 -0
- package/dist/uri.js +79 -0
- package/dist/uri.js.map +1 -0
- package/package.json +39 -40
- package/src/chain.test.ts +190 -0
- package/src/chain.ts +82 -0
- package/src/client/client.test.ts +192 -0
- package/src/client/handle.ts +53 -0
- package/src/client/index.ts +18 -0
- package/src/client/trpc.ts +91 -0
- package/src/client.ts +1 -0
- package/src/comp/CLAUDE.md +14 -0
- package/src/comp/handle.ts +36 -0
- package/src/comp/index.test.ts +129 -0
- package/src/comp/index.ts +175 -0
- package/src/comp/needs.test.ts +499 -0
- package/src/comp/needs.ts +113 -0
- package/src/comp/validate.test.ts +304 -0
- package/src/comp/validate.ts +125 -0
- package/src/comp.ts +1 -0
- package/src/contexts/schema/index.ts +7 -0
- package/src/contexts/schema.ts +1 -0
- package/src/contexts/service/index.test.ts +323 -0
- package/src/contexts/service/index.ts +43 -0
- package/src/contexts/service.ts +1 -0
- package/src/contexts/telegram/index.ts +115 -0
- package/src/contexts/text/index.test.ts +31 -0
- package/src/contexts/text/index.ts +18 -0
- package/src/contexts/text.ts +1 -0
- package/src/core/component.ts +151 -0
- package/src/core/context.ts +14 -0
- package/src/core/index.test.ts +203 -0
- package/src/core/index.ts +9 -0
- package/src/core/path.ts +35 -0
- package/src/core/registry.ts +115 -0
- package/src/core.ts +1 -0
- package/src/log.test.ts +70 -0
- package/src/log.ts +28 -0
- package/src/mod/discover.test.ts +133 -0
- package/src/mod/discover.ts +100 -0
- package/src/mod/docs/00-index.md +19 -0
- package/src/mod/docs/01-primitives.md +38 -0
- package/src/mod/docs/02-core-api.md +68 -0
- package/src/mod/docs/03-registry.md +30 -0
- package/src/mod/docs/04-store.md +62 -0
- package/src/mod/docs/05-comp.md +111 -0
- package/src/mod/docs/06-actions.md +193 -0
- package/src/mod/docs/07-realtime.md +100 -0
- package/src/mod/docs/08-services.md +33 -0
- package/src/mod/docs/09-mounts.md +43 -0
- package/src/mod/docs/10-acl.md +60 -0
- package/src/mod/docs/11-server.md +62 -0
- package/src/mod/docs/12-conventions.md +65 -0
- package/src/mod/docs/13-example.md +132 -0
- package/src/mod/docs/14-mod-format.md +304 -0
- package/src/mod/docs/15-documenting-types.md +156 -0
- package/src/mod/examples/ticker/seed.ts +19 -0
- package/src/mod/examples/ticker/service.ts +20 -0
- package/src/mod/examples/ticker/ticker.test.ts +18 -0
- package/src/mod/examples/ticker/types.ts +22 -0
- package/src/mod/examples/ticker/view.tsx +19 -0
- package/src/mod/index.ts +12 -0
- package/src/mod/loader.test.ts +168 -0
- package/src/mod/loader.ts +174 -0
- package/src/mod/optimistic.test.ts +446 -0
- package/src/mod/optimistic.ts +210 -0
- package/src/mod/prefab.ts +62 -0
- package/src/mod/tracking.test.ts +59 -0
- package/src/mod/tracking.ts +51 -0
- package/src/mod/types.ts +40 -0
- package/src/mod.ts +1 -0
- package/src/mods/autostart/CLAUDE.md +6 -0
- package/src/mods/autostart/autostart.test.ts +85 -0
- package/src/mods/autostart/server.ts +1 -0
- package/src/mods/autostart/service.ts +98 -0
- package/src/mods/llm/CLAUDE.md +6 -0
- package/src/mods/llm/index.ts +57 -0
- package/src/mods/llm/llm.test.ts +109 -0
- package/src/mods/llm/server.ts +1 -0
- package/src/mods/mcp/CLAUDE.md +6 -0
- package/src/mods/mcp/server.ts +2 -0
- package/src/mods/mcp/service.ts +19 -0
- package/src/mods/mcp/types.ts +7 -0
- package/src/mods/treenity/agent-port.ts +93 -0
- package/src/mods/treenity/groups.ts +19 -0
- package/src/mods/treenity/mod-type.ts +10 -0
- package/src/mods/treenity/seed.ts +56 -0
- package/src/mods/treenity/server.ts +4 -0
- package/src/mods/treenity/system.ts +70 -0
- package/src/mods/uix/CLAUDE.md +7 -0
- package/src/mods/uix/client.ts +117 -0
- package/src/mods/uix/compile.test.ts +228 -0
- package/src/mods/uix/compile.ts +110 -0
- package/src/mods/uix/jsx-parser.test.ts +554 -0
- package/src/mods/uix/jsx-parser.ts +489 -0
- package/src/mods/uix/lazy-load.test.ts +261 -0
- package/src/mods/uix/uix-repomix.md +3509 -0
- package/src/mods/uix/verify.ts +68 -0
- package/src/schema/CLAUDE.md +13 -0
- package/src/schema/catalog.ts +101 -0
- package/src/schema/extract-schemas.test.ts +84 -0
- package/src/schema/extract-schemas.ts +462 -0
- package/src/schema/generated/autostart.json +44 -0
- package/src/schema/generated/board.column.json +25 -0
- package/src/schema/generated/board.task.json +147 -0
- package/src/schema/generated/brahman.action.back.json +12 -0
- package/src/schema/generated/brahman.action.broadcast.json +31 -0
- package/src/schema/generated/brahman.action.call.json +57 -0
- package/src/schema/generated/brahman.action.emittext.json +23 -0
- package/src/schema/generated/brahman.action.eval.json +23 -0
- package/src/schema/generated/brahman.action.file.json +28 -0
- package/src/schema/generated/brahman.action.forward.json +29 -0
- package/src/schema/generated/brahman.action.getvalue.json +28 -0
- package/src/schema/generated/brahman.action.ifelse.json +42 -0
- package/src/schema/generated/brahman.action.keywordselect.json +46 -0
- package/src/schema/generated/brahman.action.message.json +127 -0
- package/src/schema/generated/brahman.action.onerror.json +29 -0
- package/src/schema/generated/brahman.action.page.json +22 -0
- package/src/schema/generated/brahman.action.params.json +36 -0
- package/src/schema/generated/brahman.action.question.json +43 -0
- package/src/schema/generated/brahman.action.remove.json +12 -0
- package/src/schema/generated/brahman.action.resethistory.json +12 -0
- package/src/schema/generated/brahman.action.resetsession.json +12 -0
- package/src/schema/generated/brahman.action.selectlang.json +20 -0
- package/src/schema/generated/brahman.action.setvalue.json +27 -0
- package/src/schema/generated/brahman.action.tag.json +27 -0
- package/src/schema/generated/brahman.bot.json +68 -0
- package/src/schema/generated/brahman.page.json +25 -0
- package/src/schema/generated/brahman.session.json +29 -0
- package/src/schema/generated/brahman.user.json +58 -0
- package/src/schema/generated/cafe.contact.json +56 -0
- package/src/schema/generated/cafe.mail.json +29 -0
- package/src/schema/generated/default.json +15 -0
- package/src/schema/generated/doc.page.json +23 -0
- package/src/schema/generated/examples.demo.generator.json +16 -0
- package/src/schema/generated/examples.demo.sensor.json +35 -0
- package/src/schema/generated/groups.json +20 -0
- package/src/schema/generated/launcher.json +91 -0
- package/src/schema/generated/mcp.server.json +15 -0
- package/src/schema/generated/mindmap.map.json +22 -0
- package/src/schema/generated/sim.agent.json +24 -0
- package/src/schema/generated/sim.ai.json +24 -0
- package/src/schema/generated/sim.config.json +38 -0
- package/src/schema/generated/sim.descriptive.json +26 -0
- package/src/schema/generated/sim.events.json +47 -0
- package/src/schema/generated/sim.item.json +20 -0
- package/src/schema/generated/sim.memory.json +17 -0
- package/src/schema/generated/sim.nearby.json +17 -0
- package/src/schema/generated/sim.position.json +25 -0
- package/src/schema/generated/sim.round.json +64 -0
- package/src/schema/generated/sim.world.json +32 -0
- package/src/schema/generated/t.agent.port.json +74 -0
- package/src/schema/generated/t.llm.json +20 -0
- package/src/schema/generated/t.mod.json +27 -0
- package/src/schema/generated/t3d.animator.json +46 -0
- package/src/schema/generated/t3d.audio.json +58 -0
- package/src/schema/generated/t3d.camera.json +50 -0
- package/src/schema/generated/t3d.collider.json +84 -0
- package/src/schema/generated/t3d.light.json +90 -0
- package/src/schema/generated/t3d.line.json +47 -0
- package/src/schema/generated/t3d.lod.json +28 -0
- package/src/schema/generated/t3d.material.json +131 -0
- package/src/schema/generated/t3d.mesh.json +65 -0
- package/src/schema/generated/t3d.object.json +64 -0
- package/src/schema/generated/t3d.particles.json +109 -0
- package/src/schema/generated/t3d.rigidbody.json +81 -0
- package/src/schema/generated/t3d.scene.json +7 -0
- package/src/schema/generated/t3d.script.json +23 -0
- package/src/schema/generated/t3d.text.json +86 -0
- package/src/schema/generated/t3d.trail.json +45 -0
- package/src/schema/generated/task.json +96 -0
- package/src/schema/generated/test.fixture.json +43 -0
- package/src/schema/generated/ticker.config.json +43 -0
- package/src/schema/generated/ticker.price.json +20 -0
- package/src/schema/generated/todo.item.json +25 -0
- package/src/schema/generated/todo.list.json +33 -0
- package/src/schema/generated/treenity.system.json +259 -0
- package/src/schema/generated/whisper.audio.json +25 -0
- package/src/schema/generated/whisper.checklist.json +17 -0
- package/src/schema/generated/whisper.config.json +30 -0
- package/src/schema/generated/whisper.inbox.json +24 -0
- package/src/schema/generated/whisper.meta.json +35 -0
- package/src/schema/generated/whisper.text.json +16 -0
- package/src/schema/load.ts +24 -0
- package/src/schema/schema.test.ts +86 -0
- package/src/schema/test-fixture.types.ts +21 -0
- package/src/schema/test-opaque.ts +42 -0
- package/src/schema/types.ts +33 -0
- package/src/server/CLAUDE.md +26 -0
- package/src/server/actions.test.ts +272 -0
- package/src/server/actions.ts +274 -0
- package/src/server/agent-sub.test.ts +90 -0
- package/src/server/agent.test.ts +305 -0
- package/src/server/agent.ts +17 -0
- package/src/server/api.test.ts +454 -0
- package/src/server/auth.test.ts +441 -0
- package/src/server/auth.ts +386 -0
- package/src/server/client.ts +24 -0
- package/src/server/conditions.test.ts +128 -0
- package/src/server/cookies.ts +25 -0
- package/src/server/coverage.test.ts +827 -0
- package/src/server/doc-index.ts +286 -0
- package/src/server/e2e.test.ts +966 -0
- package/src/server/errors.ts +11 -0
- package/src/server/factory.ts +99 -0
- package/src/server/main.ts +56 -0
- package/src/server/mcp.ts +326 -0
- package/src/server/migrate.test.ts +123 -0
- package/src/server/migrate.ts +62 -0
- package/src/server/mod-catalog.ts +59 -0
- package/src/server/mods-mount.ts +179 -0
- package/src/server/mount-adapters.ts +82 -0
- package/src/server/mount.parametrized.test.ts +52 -0
- package/src/server/mount.query.test.ts +127 -0
- package/src/server/mount.test.ts +497 -0
- package/src/server/mount.ts +208 -0
- package/src/server/prefab.test.ts +415 -0
- package/src/server/prefab.ts +104 -0
- package/src/server/seed/index.ts +24 -0
- package/src/server/server.ts +153 -0
- package/src/server/stress.test.ts +844 -0
- package/src/server/sub.test.ts +55 -0
- package/src/server/sub.ts +224 -0
- package/src/server/trpc.ts +369 -0
- package/src/server/types-mount.ts +142 -0
- package/src/server/validate.test.ts +91 -0
- package/src/server/validate.ts +22 -0
- package/src/server/volatile.test.ts +140 -0
- package/src/server/volatile.ts +32 -0
- package/src/server/watch.test.ts +594 -0
- package/src/server/watch.ts +202 -0
- package/src/server/workflow.test.ts +82 -0
- package/src/tree/CLAUDE.md +13 -0
- package/src/tree/cache.test.ts +213 -0
- package/src/tree/cache.ts +51 -0
- package/src/tree/fs.test.ts +247 -0
- package/src/tree/fs.ts +251 -0
- package/src/tree/index.test.ts +164 -0
- package/src/tree/index.ts +216 -0
- package/src/tree/inflight.ts +15 -0
- package/src/tree/json-codec.ts +16 -0
- package/src/tree/mimefs.test.ts +289 -0
- package/src/tree/mimefs.ts +142 -0
- package/src/tree/mongo.ts +125 -0
- package/src/tree/patch.test.ts +192 -0
- package/src/tree/patch.ts +133 -0
- package/src/tree/query.test.ts +110 -0
- package/src/tree/query.ts +70 -0
- package/src/tree/repath.test.ts +86 -0
- package/src/tree/repath.ts +53 -0
- package/src/tree-chain.test.ts +723 -0
- package/src/tree-chain.ts +144 -0
- package/src/tree.ts +1 -0
- package/src/uri.test.ts +86 -0
- package/src/uri.ts +82 -0
- package/CHANGELOG.md +0 -305
- package/README.md +0 -18
- package/dist/context.d.ts +0 -41
- package/dist/context.d.ts.map +0 -1
- package/dist/context.mjs +0 -81
- package/dist/context.mjs.map +0 -1
- package/dist/contexts/node-engine.d.ts +0 -12
- package/dist/contexts/node-engine.d.ts.map +0 -1
- package/dist/contexts/node-engine.mjs +0 -7
- package/dist/contexts/node-engine.mjs.map +0 -1
- package/dist/contexts/noflo/types.d.ts +0 -20
- package/dist/contexts/noflo/types.d.ts.map +0 -1
- package/dist/contexts/object.d.ts +0 -11
- package/dist/contexts/object.d.ts.map +0 -1
- package/dist/contexts/object.mjs +0 -15
- package/dist/contexts/object.mjs.map +0 -1
- package/dist/contexts/proto.d.ts +0 -11
- package/dist/contexts/proto.d.ts.map +0 -1
- package/dist/contexts/proto.mjs +0 -7
- package/dist/contexts/proto.mjs.map +0 -1
- package/dist/contexts/react-context.d.ts +0 -21
- package/dist/contexts/react-context.d.ts.map +0 -1
- package/dist/contexts/react-context.mjs +0 -24
- package/dist/contexts/react-context.mjs.map +0 -1
- package/dist/contexts/service.mjs +0 -7
- package/dist/contexts/service.mjs.map +0 -1
- package/dist/get-type-cache.d.ts +0 -2
- package/dist/get-type-cache.d.ts.map +0 -1
- package/dist/get-type-cache.mjs +0 -7
- package/dist/get-type-cache.mjs.map +0 -1
- package/dist/index.d.ts +0 -13
- package/dist/index.d.ts.map +0 -1
- package/dist/index.mjs +0 -10
- package/dist/index.mjs.map +0 -1
- package/dist/link/link.d.ts +0 -25
- package/dist/link/link.d.ts.map +0 -1
- package/dist/link/link.mjs +0 -72
- package/dist/link/link.mjs.map +0 -1
- package/dist/link/link.test.d.ts +0 -2
- package/dist/link/link.test.d.ts.map +0 -1
- package/dist/loading.d.ts +0 -9
- package/dist/loading.d.ts.map +0 -1
- package/dist/meta-type.d.ts +0 -58
- package/dist/meta-type.d.ts.map +0 -1
- package/dist/meta-type.mjs +0 -104
- package/dist/meta-type.mjs.map +0 -1
- package/dist/meta.d.ts +0 -20
- package/dist/meta.d.ts.map +0 -1
- package/dist/meta.mjs +0 -16
- package/dist/meta.mjs.map +0 -1
- package/dist/node/index.d.ts +0 -2
- package/dist/node/index.d.ts.map +0 -1
- package/dist/node/types.d.ts +0 -37
- package/dist/node/types.d.ts.map +0 -1
- package/dist/test/context.test.d.ts +0 -2
- package/dist/test/context.test.d.ts.map +0 -1
- package/dist/types.d.ts +0 -14
- package/dist/types.d.ts.map +0 -1
- package/dist/types.mjs +0 -16
- package/dist/types.mjs.map +0 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { createNode } from '#core';
|
|
2
|
+
import { createMemoryTree } from '#tree';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import { describe, it } from 'node:test';
|
|
5
|
+
import { type NodeEvent, withSubscriptions } from './sub';
|
|
6
|
+
|
|
7
|
+
describe('Subscriptions', () => {
|
|
8
|
+
it('emits on set (children)', async () => {
|
|
9
|
+
const store = withSubscriptions(createMemoryTree());
|
|
10
|
+
const events: NodeEvent[] = [];
|
|
11
|
+
store.subscribe('/bot', (e) => events.push(e), { children: true });
|
|
12
|
+
|
|
13
|
+
await store.set(createNode('/bot/commands/start', 'page'));
|
|
14
|
+
assert.equal(events.length, 1);
|
|
15
|
+
assert.equal(events[0].type, 'set');
|
|
16
|
+
assert.equal(events[0].path, '/bot/commands/start');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('emits on remove (children)', async () => {
|
|
20
|
+
const store = withSubscriptions(createMemoryTree());
|
|
21
|
+
const events: NodeEvent[] = [];
|
|
22
|
+
await store.set(createNode('/bot/x', 'page'));
|
|
23
|
+
store.subscribe('/bot', (e) => events.push(e), { children: true });
|
|
24
|
+
await store.remove('/bot/x');
|
|
25
|
+
assert.equal(events.length, 1);
|
|
26
|
+
assert.equal(events[0].type, 'remove');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('does not emit for unrelated paths', async () => {
|
|
30
|
+
const store = withSubscriptions(createMemoryTree());
|
|
31
|
+
const events: NodeEvent[] = [];
|
|
32
|
+
store.subscribe('/bot', (e) => events.push(e), { children: true });
|
|
33
|
+
await store.set(createNode('/users/1', 'user'));
|
|
34
|
+
assert.equal(events.length, 0);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('emits for exact path match', async () => {
|
|
38
|
+
const store = withSubscriptions(createMemoryTree());
|
|
39
|
+
const events: NodeEvent[] = [];
|
|
40
|
+
store.subscribe('/bot', (e) => events.push(e));
|
|
41
|
+
await store.set(createNode('/bot', 'bot'));
|
|
42
|
+
assert.equal(events.length, 1);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('unsubscribe stops events (children)', async () => {
|
|
46
|
+
const store = withSubscriptions(createMemoryTree());
|
|
47
|
+
const events: NodeEvent[] = [];
|
|
48
|
+
const unsub = store.subscribe('/bot', (e) => events.push(e), { children: true });
|
|
49
|
+
await store.set(createNode('/bot/x', 'page'));
|
|
50
|
+
assert.equal(events.length, 1);
|
|
51
|
+
unsub();
|
|
52
|
+
await store.set(createNode('/bot/y', 'page'));
|
|
53
|
+
assert.equal(events.length, 1);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// Treenity Subscriptions — Layer 3
|
|
2
|
+
// Wraps any Tree, emits events on set/remove.
|
|
3
|
+
// No dependencies beyond Tree + core types.
|
|
4
|
+
|
|
5
|
+
import { type SubscribeOpts } from '#contexts/service/index';
|
|
6
|
+
import { type NodeData } from '#core';
|
|
7
|
+
import { type PatchOp, toRfc6902, type Tree } from '#tree';
|
|
8
|
+
import { createSiftTest, mapNodeForSift } from '#tree/query';
|
|
9
|
+
import type { Operation } from 'fast-json-patch';
|
|
10
|
+
import fjp from 'fast-json-patch';
|
|
11
|
+
import { type Patch } from 'immer';
|
|
12
|
+
|
|
13
|
+
const { compare } = fjp;
|
|
14
|
+
|
|
15
|
+
// Immer Patch {path: ['a','b']} → RFC 6902 Operation {path: '/a/b'}
|
|
16
|
+
function immerToRfc(patches: Patch[]): Operation[] {
|
|
17
|
+
return patches.map(p => ({ ...p, path: '/' + p.path.join('/') }) as Operation);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// ── Event types ──
|
|
21
|
+
|
|
22
|
+
export type NodeEvent =
|
|
23
|
+
| { type: 'set'; path: string; node: Omit<NodeData, '$path'>; addVps?: string[]; rmVps?: string[] }
|
|
24
|
+
| { type: 'patch'; path: string; patches: Operation[]; addVps?: string[]; rmVps?: string[] }
|
|
25
|
+
| { type: 'remove'; path: string; rmVps?: string[] }
|
|
26
|
+
| { type: 'reconnect'; preserved: boolean };
|
|
27
|
+
|
|
28
|
+
// Strip empty arrays and $path from node to keep wire format clean
|
|
29
|
+
function cleanEvent(event: NodeEvent): NodeEvent {
|
|
30
|
+
const e = { ...event };
|
|
31
|
+
if ('addVps' in e && e.addVps && e.addVps.length === 0) delete e.addVps;
|
|
32
|
+
if ('rmVps' in e && e.rmVps && e.rmVps.length === 0) delete e.rmVps;
|
|
33
|
+
return e;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type Listener = (event: NodeEvent) => void;
|
|
37
|
+
|
|
38
|
+
// ── Query Registry ──
|
|
39
|
+
// Stores active queries (mounts) for CDC evaluation
|
|
40
|
+
type QueryEntry = {
|
|
41
|
+
vp: string; // Virtual parent path (e.g. /orders/incoming)
|
|
42
|
+
source: string; // Source collection path (e.g. /orders/data)
|
|
43
|
+
test: (node: Record<string, unknown>) => boolean; // Sift compiled query
|
|
44
|
+
users: Set<string>; // Who is watching this vp
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const activeQueries: QueryEntry[] = [];
|
|
48
|
+
|
|
49
|
+
export function watchQuery(vp: string, source: string, match: Record<string, unknown>, userId: string) {
|
|
50
|
+
let entry = activeQueries.find(q => q.vp === vp);
|
|
51
|
+
if (!entry) {
|
|
52
|
+
entry = { vp, source, test: createSiftTest(match), users: new Set() };
|
|
53
|
+
activeQueries.push(entry);
|
|
54
|
+
}
|
|
55
|
+
entry.users.add(userId);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function unwatchQuery(vp: string, userId: string) {
|
|
59
|
+
const idx = activeQueries.findIndex(q => q.vp === vp);
|
|
60
|
+
if (idx === -1) return;
|
|
61
|
+
const entry = activeQueries[idx];
|
|
62
|
+
entry.users.delete(userId);
|
|
63
|
+
if (entry.users.size === 0) activeQueries.splice(idx, 1);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function unwatchAllQueries(userId: string) {
|
|
67
|
+
for (let i = activeQueries.length - 1; i >= 0; i--) {
|
|
68
|
+
activeQueries[i].users.delete(userId);
|
|
69
|
+
if (activeQueries[i].users.size === 0) activeQueries.splice(i, 1);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function getActiveQueryCount(): number {
|
|
74
|
+
return activeQueries.length;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ── Reactive store wrapper ──
|
|
78
|
+
|
|
79
|
+
export interface ReactiveTree extends Tree {
|
|
80
|
+
subscribe(path: string, listener: Listener, opts?: SubscribeOpts): () => void;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function withSubscriptions(
|
|
84
|
+
store: Tree,
|
|
85
|
+
onEvent?: (event: NodeEvent) => void,
|
|
86
|
+
): ReactiveTree {
|
|
87
|
+
const exactListeners = new Map<string, Set<Listener>>();
|
|
88
|
+
const prefixListeners = new Map<string, Set<Listener>>();
|
|
89
|
+
|
|
90
|
+
type DataEvent = Exclude<NodeEvent, { type: 'reconnect' }>;
|
|
91
|
+
|
|
92
|
+
function emit(raw: DataEvent) {
|
|
93
|
+
const event = cleanEvent(raw) as DataEvent;
|
|
94
|
+
|
|
95
|
+
const exact = exactListeners.get(event.path);
|
|
96
|
+
if (exact) for (const fn of exact) fn(event);
|
|
97
|
+
|
|
98
|
+
for (const [prefix, subs] of prefixListeners) {
|
|
99
|
+
if (event.path === prefix || event.path.startsWith(prefix === '/' ? '/' : prefix + '/')) {
|
|
100
|
+
for (const fn of subs) fn(event);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
onEvent?.(event);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
get: store.get.bind(store),
|
|
109
|
+
getChildren: store.getChildren.bind(store),
|
|
110
|
+
|
|
111
|
+
async set(node) {
|
|
112
|
+
const patches = node['$patches'] as Patch[] | undefined;
|
|
113
|
+
if (patches) {
|
|
114
|
+
node = { ...node };
|
|
115
|
+
delete node['$patches'];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const oldNode = await store.get(node.$path);
|
|
119
|
+
|
|
120
|
+
// CDC Matrix Evaluation
|
|
121
|
+
const addVps: string[] = [];
|
|
122
|
+
const rmVps: string[] = [];
|
|
123
|
+
|
|
124
|
+
const newNodeSift = mapNodeForSift(node);
|
|
125
|
+
const oldNodeSift = oldNode ? mapNodeForSift(oldNode) : null;
|
|
126
|
+
|
|
127
|
+
for (const q of activeQueries) {
|
|
128
|
+
// Only evaluate if node is a direct child of the query's source
|
|
129
|
+
const prefix = q.source === '/' ? '/' : q.source + '/';
|
|
130
|
+
if (node.$path.startsWith(prefix) && node.$path.slice(prefix.length).indexOf('/') === -1) {
|
|
131
|
+
const wasIn = oldNodeSift ? q.test(oldNodeSift) : false;
|
|
132
|
+
const isIn = q.test(newNodeSift);
|
|
133
|
+
|
|
134
|
+
if (!wasIn && isIn) addVps.push(q.vp);
|
|
135
|
+
if (wasIn && !isIn) rmVps.push(q.vp);
|
|
136
|
+
// If wasIn && isIn, it's an update, which is handled by exact path watch
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
await store.set(node);
|
|
141
|
+
|
|
142
|
+
const { $path, ...body } = node;
|
|
143
|
+
|
|
144
|
+
if (patches && patches.length > 0) {
|
|
145
|
+
// Immer patches from actions → convert to RFC 6902
|
|
146
|
+
emit({ type: 'patch', path: $path, patches: immerToRfc(patches), addVps, rmVps });
|
|
147
|
+
} else if (oldNode) {
|
|
148
|
+
// Compute minimal RFC 6902 patches via deep comparison
|
|
149
|
+
const computed = compare(oldNode, node);
|
|
150
|
+
emit(computed.length > 0
|
|
151
|
+
? { type: 'patch', path: $path, patches: computed, addVps, rmVps }
|
|
152
|
+
: { type: 'set', path: $path, node: body, addVps, rmVps });
|
|
153
|
+
} else {
|
|
154
|
+
// New node — no old state to diff against
|
|
155
|
+
emit({ type: 'set', path: $path, node: body, addVps, rmVps });
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
async remove(path) {
|
|
160
|
+
const oldNode = await store.get(path);
|
|
161
|
+
const result = await store.remove(path);
|
|
162
|
+
|
|
163
|
+
if (result && oldNode) {
|
|
164
|
+
const rmVps: string[] = [];
|
|
165
|
+
const oldNodeSift = mapNodeForSift(oldNode);
|
|
166
|
+
|
|
167
|
+
for (const q of activeQueries) {
|
|
168
|
+
const prefix = q.source === '/' ? '/' : q.source + '/';
|
|
169
|
+
if (path.startsWith(prefix) && path.slice(prefix.length).indexOf('/') === -1) {
|
|
170
|
+
if (q.test(oldNodeSift)) {
|
|
171
|
+
rmVps.push(q.vp);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
emit({ type: 'remove', path, ...(rmVps.length > 0 ? { rmVps } : {}) });
|
|
176
|
+
}
|
|
177
|
+
return result;
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
async patch(path, ops, ctx) {
|
|
181
|
+
const oldNode = await store.get(path);
|
|
182
|
+
|
|
183
|
+
await store.patch(path, ops, ctx);
|
|
184
|
+
|
|
185
|
+
// CDC Matrix — read new state to check virtual path changes
|
|
186
|
+
const newNode = await store.get(path);
|
|
187
|
+
const addVps: string[] = [];
|
|
188
|
+
const rmVps: string[] = [];
|
|
189
|
+
|
|
190
|
+
if (oldNode && newNode) {
|
|
191
|
+
const oldSift = mapNodeForSift(oldNode);
|
|
192
|
+
const newSift = mapNodeForSift(newNode);
|
|
193
|
+
for (const q of activeQueries) {
|
|
194
|
+
const prefix = q.source === '/' ? '/' : q.source + '/';
|
|
195
|
+
if (path.startsWith(prefix) && path.slice(prefix.length).indexOf('/') === -1) {
|
|
196
|
+
const wasIn = q.test(oldSift);
|
|
197
|
+
const isIn = q.test(newSift);
|
|
198
|
+
if (!wasIn && isIn) addVps.push(q.vp);
|
|
199
|
+
if (wasIn && !isIn) rmVps.push(q.vp);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Emit only mutation ops (filter out test ops)
|
|
205
|
+
const mutations = ops.filter((o): o is Exclude<PatchOp, readonly ['t', ...any]> => o[0] !== 't');
|
|
206
|
+
if (mutations.length > 0) {
|
|
207
|
+
emit({ type: 'patch', path, patches: toRfc6902(mutations) as Operation[], addVps, rmVps });
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
|
|
211
|
+
subscribe(path, listener, opts) {
|
|
212
|
+
const map = opts?.children ? prefixListeners : exactListeners;
|
|
213
|
+
if (!map.has(path)) map.set(path, new Set());
|
|
214
|
+
map.get(path)!.add(listener);
|
|
215
|
+
return () => {
|
|
216
|
+
const subs = map.get(path);
|
|
217
|
+
if (subs) {
|
|
218
|
+
subs.delete(listener);
|
|
219
|
+
if (subs.size === 0) map.delete(path);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
},
|
|
223
|
+
};
|
|
224
|
+
}
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
// Treenity tRPC Router — Layer 4
|
|
2
|
+
// Thin transport wrapper over shared ops (actions.ts).
|
|
3
|
+
// Responsibilities: input validation (Zod), error mapping (OpError → TRPCError), watch wiring.
|
|
4
|
+
|
|
5
|
+
import { createNode, getComponentField, isComponent, type NodeData, R, resolve, S, W } from '#core';
|
|
6
|
+
import { initTRPC, TRPCError } from '@trpc/server';
|
|
7
|
+
import { observable } from '@trpc/server/observable';
|
|
8
|
+
import { randomBytes } from 'node:crypto';
|
|
9
|
+
import { z } from 'zod';
|
|
10
|
+
import {
|
|
11
|
+
type ActionCtx,
|
|
12
|
+
applyTemplate as applyTemplateOp,
|
|
13
|
+
executeAction,
|
|
14
|
+
serverNodeHandle,
|
|
15
|
+
setComponent as setComponentOp,
|
|
16
|
+
} from './actions';
|
|
17
|
+
import {
|
|
18
|
+
buildClaims,
|
|
19
|
+
createSession,
|
|
20
|
+
DUMMY_HASH,
|
|
21
|
+
hashPassword,
|
|
22
|
+
revokeSession,
|
|
23
|
+
type Session,
|
|
24
|
+
verifyPassword,
|
|
25
|
+
withAcl,
|
|
26
|
+
} from './auth';
|
|
27
|
+
import { AGENT_SESSION_TTL, hashAgentKey, timingSafeCompare } from './agent';
|
|
28
|
+
import { OpError } from './errors';
|
|
29
|
+
import { deployPrefab as deployPrefabOp } from './prefab';
|
|
30
|
+
import { type NodeEvent, type ReactiveTree, unwatchQuery, watchQuery } from './sub';
|
|
31
|
+
import { extractPaths } from './volatile';
|
|
32
|
+
import { type WatchManager } from './watch';
|
|
33
|
+
|
|
34
|
+
export type TrpcContext = { session: Session | null; token: string | null };
|
|
35
|
+
|
|
36
|
+
// ── Rate limiter (in-memory, per key) ──
|
|
37
|
+
|
|
38
|
+
const rateBuckets = new Map<string, { count: number; resetAt: number }>();
|
|
39
|
+
const RATE_WINDOW_MS = 60_000;
|
|
40
|
+
const RATE_LIMIT_AUTH = 10; // max attempts per key per minute
|
|
41
|
+
|
|
42
|
+
function checkRate(key: string, limit = RATE_LIMIT_AUTH): void {
|
|
43
|
+
const now = Date.now();
|
|
44
|
+
const bucket = rateBuckets.get(key);
|
|
45
|
+
if (!bucket || now > bucket.resetAt) {
|
|
46
|
+
rateBuckets.set(key, { count: 1, resetAt: now + RATE_WINDOW_MS });
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (bucket.count >= limit) throw new TRPCError({ code: 'TOO_MANY_REQUESTS', message: 'Too many requests' });
|
|
50
|
+
bucket.count++;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Periodic cleanup (every 5 min)
|
|
54
|
+
setInterval(() => {
|
|
55
|
+
const now = Date.now();
|
|
56
|
+
for (const [k, v] of rateBuckets) if (now > v.resetAt) rateBuckets.delete(k);
|
|
57
|
+
}, 5 * 60_000).unref();
|
|
58
|
+
|
|
59
|
+
export function createTreeRouter(baseStore: ReactiveTree, watcher: WatchManager) {
|
|
60
|
+
const t = initTRPC.context<TrpcContext>().create();
|
|
61
|
+
|
|
62
|
+
// Map domain errors → TRPCError by inspecting result.error.cause
|
|
63
|
+
// tRPC v11 middleware: next() returns { ok, error } — doesn't throw
|
|
64
|
+
const authed = t.procedure.use(async ({ ctx, next }) => {
|
|
65
|
+
const userId = ctx.session?.userId ?? null;
|
|
66
|
+
// Session-level claims (agents) override dynamic buildClaims (users)
|
|
67
|
+
const claims = ctx.session?.claims ?? (userId ? await buildClaims(baseStore, userId) : ['public']);
|
|
68
|
+
const store = withAcl(baseStore, userId, claims);
|
|
69
|
+
const result = await next({ ctx: { ...ctx, store } });
|
|
70
|
+
|
|
71
|
+
if (!result.ok) {
|
|
72
|
+
const cause = result.error.cause;
|
|
73
|
+
if (cause instanceof Error) {
|
|
74
|
+
if (cause.name === 'OpError')
|
|
75
|
+
throw new TRPCError({ code: (cause as OpError).code, message: cause.message });
|
|
76
|
+
if (cause.message.startsWith('Access denied'))
|
|
77
|
+
throw new TRPCError({ code: 'FORBIDDEN', message: cause.message });
|
|
78
|
+
if (cause.message.startsWith('OptimisticConcurrencyError'))
|
|
79
|
+
throw new TRPCError({ code: 'CONFLICT', message: cause.message });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return t.router({
|
|
86
|
+
get: authed
|
|
87
|
+
.input(z.object({ path: z.string(), watch: z.boolean().optional() }))
|
|
88
|
+
.query(async ({ input, ctx }) => {
|
|
89
|
+
const node = await ctx.store.get(input.path);
|
|
90
|
+
if (input.watch && ctx.session && (await ctx.store.getPerm(input.path)) & S)
|
|
91
|
+
watcher.watch(ctx.session.userId, [input.path]);
|
|
92
|
+
return node;
|
|
93
|
+
}),
|
|
94
|
+
|
|
95
|
+
getChildren: authed
|
|
96
|
+
.input(
|
|
97
|
+
z.object({
|
|
98
|
+
path: z.string(),
|
|
99
|
+
limit: z.number().optional().default(100),
|
|
100
|
+
offset: z.number().optional(),
|
|
101
|
+
depth: z.number().optional(),
|
|
102
|
+
watch: z.boolean().optional(),
|
|
103
|
+
watchNew: z.boolean().optional(),
|
|
104
|
+
}),
|
|
105
|
+
)
|
|
106
|
+
.query(async ({ input, ctx }) => {
|
|
107
|
+
const result = await ctx.store.getChildren(input.path, {
|
|
108
|
+
limit: input.limit,
|
|
109
|
+
offset: input.offset,
|
|
110
|
+
depth: input.depth,
|
|
111
|
+
}, { ...ctx, queryContextPath: input.path });
|
|
112
|
+
|
|
113
|
+
if (ctx.session) {
|
|
114
|
+
if (input.watch) {
|
|
115
|
+
const watchable: string[] = [];
|
|
116
|
+
for (const n of result.items)
|
|
117
|
+
if ((await ctx.store.getPerm(n.$path)) & S) watchable.push(n.$path);
|
|
118
|
+
if (watchable.length) watcher.watch(ctx.session.userId, watchable);
|
|
119
|
+
}
|
|
120
|
+
if (input.watchNew) {
|
|
121
|
+
if (result.queryMount) {
|
|
122
|
+
const q = result.queryMount;
|
|
123
|
+
watchQuery(input.path, q.source, q.match, ctx.session.userId);
|
|
124
|
+
}
|
|
125
|
+
watcher.watch(ctx.session.userId, [input.path], { children: true, autoWatch: input.watch });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}),
|
|
130
|
+
|
|
131
|
+
set: authed
|
|
132
|
+
.input(z.object({ node: z.record(z.string(), z.unknown()) }))
|
|
133
|
+
.mutation(({ input, ctx }) => ctx.store.set(input.node as NodeData)),
|
|
134
|
+
|
|
135
|
+
setComponent: authed
|
|
136
|
+
.input(
|
|
137
|
+
z.object({ path: z.string(), name: z.string(), data: z.record(z.string(), z.unknown()), rev: z.number().optional() }),
|
|
138
|
+
)
|
|
139
|
+
.mutation(({ input, ctx }) => setComponentOp(ctx.store, input.path, input.name, input.data, input.rev)),
|
|
140
|
+
|
|
141
|
+
remove: authed
|
|
142
|
+
.input(z.object({ path: z.string() }))
|
|
143
|
+
.mutation(({ input, ctx }) => ctx.store.remove(input.path)),
|
|
144
|
+
|
|
145
|
+
execute: authed
|
|
146
|
+
.input(
|
|
147
|
+
z.object({
|
|
148
|
+
path: z.string(),
|
|
149
|
+
type: z.string().optional(), // $type for component verification
|
|
150
|
+
key: z.string().optional(), // field key for component selection
|
|
151
|
+
action: z.string(),
|
|
152
|
+
data: z.unknown().optional(),
|
|
153
|
+
watch: z.boolean().optional(), // subscribe to paths returned in result
|
|
154
|
+
}),
|
|
155
|
+
)
|
|
156
|
+
.mutation(async ({ input, ctx }) => {
|
|
157
|
+
const result = await executeAction(ctx.store, input.path, input.type, input.key, input.action, input.data);
|
|
158
|
+
if (input.watch && ctx.session) {
|
|
159
|
+
const paths = extractPaths(result);
|
|
160
|
+
if (paths.length) watcher.watch(ctx.session.userId, paths);
|
|
161
|
+
}
|
|
162
|
+
return result;
|
|
163
|
+
}),
|
|
164
|
+
|
|
165
|
+
getTemplates: authed.query(
|
|
166
|
+
async ({ ctx }) => (await ctx.store.getChildren('/templates')).items,
|
|
167
|
+
),
|
|
168
|
+
|
|
169
|
+
applyTemplate: authed
|
|
170
|
+
.input(z.object({ templatePath: z.string(), targetPath: z.string() }))
|
|
171
|
+
.mutation(({ input, ctx }) => applyTemplateOp(ctx.store, input.templatePath, input.targetPath)),
|
|
172
|
+
|
|
173
|
+
deployPrefab: authed
|
|
174
|
+
.input(z.object({
|
|
175
|
+
source: z.string(),
|
|
176
|
+
target: z.string(),
|
|
177
|
+
allowAbsolute: z.boolean().optional(),
|
|
178
|
+
params: z.any().optional(),
|
|
179
|
+
}))
|
|
180
|
+
.mutation(({ input, ctx }) =>
|
|
181
|
+
deployPrefabOp(ctx.store, input.source, input.target, {
|
|
182
|
+
allowAbsolute: input.allowAbsolute,
|
|
183
|
+
params: input.params,
|
|
184
|
+
})),
|
|
185
|
+
|
|
186
|
+
register: t.procedure
|
|
187
|
+
.input(z.object({ userId: z.string().min(1), password: z.string().min(1) }))
|
|
188
|
+
.mutation(async ({ input }) => {
|
|
189
|
+
checkRate(`register:${input.userId}`);
|
|
190
|
+
if (/[/\\\0]/.test(input.userId)) throw new TRPCError({ code: 'BAD_REQUEST', message: 'Invalid userId' });
|
|
191
|
+
const userPath = `/auth/users/${input.userId}`;
|
|
192
|
+
const existing = await baseStore.get(userPath);
|
|
193
|
+
if (existing) throw new TRPCError({ code: 'CONFLICT', message: 'User already exists' });
|
|
194
|
+
const hash = await hashPassword(input.password);
|
|
195
|
+
const node = createNode(userPath, 'user', {}, {
|
|
196
|
+
credentials: { $type: 'credentials', hash },
|
|
197
|
+
groups: { $type: 'groups', list: [] },
|
|
198
|
+
});
|
|
199
|
+
node.$owner = input.userId;
|
|
200
|
+
node.$acl = [
|
|
201
|
+
{ g: 'owner', p: R | W },
|
|
202
|
+
{ g: 'authenticated', p: 0 },
|
|
203
|
+
];
|
|
204
|
+
await baseStore.set(node);
|
|
205
|
+
const token = await createSession(baseStore, input.userId);
|
|
206
|
+
return { token, userId: input.userId };
|
|
207
|
+
}),
|
|
208
|
+
|
|
209
|
+
login: t.procedure
|
|
210
|
+
.input(z.object({ userId: z.string().min(1), password: z.string().min(1) }))
|
|
211
|
+
.mutation(async ({ input }) => {
|
|
212
|
+
checkRate(`login:${input.userId}`);
|
|
213
|
+
if (/[/\\\0]/.test(input.userId)) throw new TRPCError({ code: 'BAD_REQUEST', message: 'Invalid userId' });
|
|
214
|
+
const userPath = `/auth/users/${input.userId}`;
|
|
215
|
+
const user = await baseStore.get(userPath);
|
|
216
|
+
const cv = user ? user['credentials'] : undefined;
|
|
217
|
+
const creds = isComponent(cv) ? cv as { $type: string; hash?: string } : undefined;
|
|
218
|
+
// Always run scrypt to prevent timing-based user enumeration
|
|
219
|
+
const ok = await verifyPassword(input.password, creds?.hash ?? DUMMY_HASH);
|
|
220
|
+
if (!user || !creds?.hash || !ok) throw new TRPCError({ code: 'UNAUTHORIZED', message: 'Invalid credentials' });
|
|
221
|
+
const token = await createSession(baseStore, input.userId);
|
|
222
|
+
return { token, userId: input.userId };
|
|
223
|
+
}),
|
|
224
|
+
|
|
225
|
+
me: authed.query(({ ctx }) => {
|
|
226
|
+
if (!ctx.session) return null;
|
|
227
|
+
return { userId: ctx.session.userId };
|
|
228
|
+
}),
|
|
229
|
+
|
|
230
|
+
logout: authed.mutation(async ({ ctx }) => {
|
|
231
|
+
if (!ctx.session || !ctx.token) return { ok: false };
|
|
232
|
+
await revokeSession(baseStore, ctx.token);
|
|
233
|
+
return { ok: true };
|
|
234
|
+
}),
|
|
235
|
+
|
|
236
|
+
// Agent TOFU handshake — public endpoint (no auth required)
|
|
237
|
+
agentConnect: t.procedure
|
|
238
|
+
.input(z.object({ path: z.string().min(1), key: z.string().min(1) }))
|
|
239
|
+
.mutation(async ({ input }) => {
|
|
240
|
+
checkRate(`agent:${input.path}`);
|
|
241
|
+
const node = await baseStore.get(input.path);
|
|
242
|
+
if (!node) throw new TRPCError({ code: 'NOT_FOUND', message: 'Agent port not found' });
|
|
243
|
+
if (node.$type !== 't.agent.port') throw new TRPCError({ code: 'BAD_REQUEST', message: 'Not an agent port' });
|
|
244
|
+
|
|
245
|
+
const keyHash = hashAgentKey(input.key);
|
|
246
|
+
const status = (node as any).status as string ?? 'idle';
|
|
247
|
+
|
|
248
|
+
if (status === 'revoked')
|
|
249
|
+
throw new TRPCError({ code: 'FORBIDDEN', message: 'Agent access revoked' });
|
|
250
|
+
|
|
251
|
+
// TOFU: first key presented goes to pending
|
|
252
|
+
if (status === 'idle') {
|
|
253
|
+
await baseStore.set({ ...node, status: 'pending', pendingKey: keyHash });
|
|
254
|
+
return { status: 'pending' as const };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Pending: same key = still waiting, different key = reject
|
|
258
|
+
if (status === 'pending') {
|
|
259
|
+
if (!timingSafeCompare(keyHash, (node as any).pendingKey))
|
|
260
|
+
throw new TRPCError({ code: 'FORBIDDEN', message: 'Key mismatch' });
|
|
261
|
+
return { status: 'pending' as const };
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Approved: verify key, create session
|
|
265
|
+
if (status === 'approved') {
|
|
266
|
+
if (!timingSafeCompare(keyHash, (node as any).approvedKey))
|
|
267
|
+
throw new TRPCError({ code: 'FORBIDDEN', message: 'Key mismatch' });
|
|
268
|
+
|
|
269
|
+
const agentUserId = `agent:${input.path}`;
|
|
270
|
+
const token = await createSession(baseStore, agentUserId, { ttlMs: AGENT_SESSION_TTL });
|
|
271
|
+
|
|
272
|
+
// Mark connected
|
|
273
|
+
await baseStore.set({ ...node, connected: true, connectedAt: Date.now() });
|
|
274
|
+
|
|
275
|
+
return { status: 'approved' as const, token, userId: agentUserId };
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
throw new TRPCError({ code: 'BAD_REQUEST', message: `Unknown agent status: ${status}` });
|
|
279
|
+
}),
|
|
280
|
+
|
|
281
|
+
unwatch: authed.input(z.object({ paths: z.array(z.string()) })).mutation(({ input, ctx }) => {
|
|
282
|
+
if (ctx.session) watcher.unwatch(ctx.session.userId, input.paths);
|
|
283
|
+
}),
|
|
284
|
+
|
|
285
|
+
unwatchChildren: authed
|
|
286
|
+
.input(z.object({ paths: z.array(z.string()) }))
|
|
287
|
+
.mutation(({ input, ctx }) => {
|
|
288
|
+
if (ctx.session) {
|
|
289
|
+
watcher.unwatch(ctx.session.userId, input.paths, { children: true });
|
|
290
|
+
for (const p of input.paths) unwatchQuery(p, ctx.session.userId);
|
|
291
|
+
}
|
|
292
|
+
}),
|
|
293
|
+
|
|
294
|
+
anonLogin: t.procedure.mutation(async () => {
|
|
295
|
+
checkRate('anonLogin', 30);
|
|
296
|
+
const userId = `anon:${randomBytes(16).toString('hex')}`;
|
|
297
|
+
const token = await createSession(baseStore, userId);
|
|
298
|
+
return { token, userId };
|
|
299
|
+
}),
|
|
300
|
+
|
|
301
|
+
streamAction: authed
|
|
302
|
+
.input(z.object({ path: z.string(), type: z.string().optional(), key: z.string().optional(), action: z.string(), data: z.unknown().optional() }))
|
|
303
|
+
.subscription(({ input, ctx }) => {
|
|
304
|
+
return observable<unknown>((emit) => {
|
|
305
|
+
const ac = new AbortController();
|
|
306
|
+
(async () => {
|
|
307
|
+
const node = await ctx.store.get(input.path);
|
|
308
|
+
if (!node) {
|
|
309
|
+
emit.error(new OpError('NOT_FOUND', `Node not found: ${input.path}`));
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Resolve handler: key → type lookup, type scan, node type, component scan
|
|
314
|
+
let handler: any;
|
|
315
|
+
let comp: { $type: string; [k: string]: unknown } | undefined;
|
|
316
|
+
|
|
317
|
+
const [found] = getComponentField(node, input.type ?? 't.any', input.key) ?? [];
|
|
318
|
+
if (input.key && !found) {
|
|
319
|
+
emit.error(new OpError('NOT_FOUND', `Component "${input.key}" not found`));
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
if (input.type && !found) {
|
|
323
|
+
emit.error(new OpError('NOT_FOUND', `Component "${input.type}" not found`));
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
comp = found as typeof comp;
|
|
327
|
+
handler = resolve((comp ?? node).$type, `action:${input.action}`);
|
|
328
|
+
|
|
329
|
+
if (!handler) {
|
|
330
|
+
emit.error(new OpError('BAD_REQUEST', `No action "${input.action}" for type "${node.$type}"`));
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
const actx: ActionCtx = { node, comp, store: ctx.store, signal: ac.signal, nc: serverNodeHandle(ctx.store) };
|
|
334
|
+
const result = handler(actx, input.data);
|
|
335
|
+
if (
|
|
336
|
+
result &&
|
|
337
|
+
typeof result === 'object' &&
|
|
338
|
+
Symbol.asyncIterator in (result as object)
|
|
339
|
+
) {
|
|
340
|
+
for await (const item of result as AsyncIterable<unknown>) {
|
|
341
|
+
if (ac.signal.aborted) break;
|
|
342
|
+
emit.next(item);
|
|
343
|
+
}
|
|
344
|
+
} else {
|
|
345
|
+
const resolved = await result;
|
|
346
|
+
emit.next(resolved);
|
|
347
|
+
}
|
|
348
|
+
emit.complete();
|
|
349
|
+
})().catch((err) => {
|
|
350
|
+
if (!ac.signal.aborted) emit.error(err);
|
|
351
|
+
});
|
|
352
|
+
return () => ac.abort();
|
|
353
|
+
});
|
|
354
|
+
}),
|
|
355
|
+
|
|
356
|
+
events: authed.subscription(({ ctx }) => {
|
|
357
|
+
return observable<NodeEvent>((emit) => {
|
|
358
|
+
const userId = ctx.session?.userId;
|
|
359
|
+
if (!userId) return () => {};
|
|
360
|
+
const connId = `${userId}:${Date.now()}:${Math.random().toString(36).slice(2, 8)}`;
|
|
361
|
+
const preserved = watcher.connect(connId, userId, (event) => emit.next(event));
|
|
362
|
+
emit.next({ type: 'reconnect', preserved });
|
|
363
|
+
return () => watcher.disconnect(connId);
|
|
364
|
+
});
|
|
365
|
+
}),
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export type TreeRouter = ReturnType<typeof createTreeRouter>;
|