@vibesdotdev/storage 0.0.1
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/README.md +75 -0
- package/SPEC.md +60 -0
- package/dist/adapters/index.d.ts +14 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +15 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/bridge/index.d.ts +3 -0
- package/dist/bridge/index.d.ts.map +1 -0
- package/dist/bridge/index.js +2 -0
- package/dist/bridge/index.js.map +1 -0
- package/dist/bridge/storage-kind-bridge.d.ts +27 -0
- package/dist/bridge/storage-kind-bridge.d.ts.map +1 -0
- package/dist/bridge/storage-kind-bridge.js +110 -0
- package/dist/bridge/storage-kind-bridge.js.map +1 -0
- package/dist/bridge/types.d.ts +45 -0
- package/dist/bridge/types.d.ts.map +1 -0
- package/dist/bridge/types.js +8 -0
- package/dist/bridge/types.js.map +1 -0
- package/dist/cli/commands/list/storage.list.cli-command.descriptor.d.ts +4 -0
- package/dist/cli/commands/list/storage.list.cli-command.descriptor.d.ts.map +1 -0
- package/dist/cli/commands/list/storage.list.cli-command.descriptor.js +18 -0
- package/dist/cli/commands/list/storage.list.cli-command.descriptor.js.map +1 -0
- package/dist/cli/commands/list/storage.list.cli-command.impl.d.ts +11 -0
- package/dist/cli/commands/list/storage.list.cli-command.impl.d.ts.map +1 -0
- package/dist/cli/commands/list/storage.list.cli-command.impl.js +48 -0
- package/dist/cli/commands/list/storage.list.cli-command.impl.js.map +1 -0
- package/dist/cli/commands/sync/pull/storage.sync.pull.cli-command.descriptor.d.ts +4 -0
- package/dist/cli/commands/sync/pull/storage.sync.pull.cli-command.descriptor.d.ts.map +1 -0
- package/dist/cli/commands/sync/pull/storage.sync.pull.cli-command.descriptor.js +26 -0
- package/dist/cli/commands/sync/pull/storage.sync.pull.cli-command.descriptor.js.map +1 -0
- package/dist/cli/commands/sync/pull/storage.sync.pull.cli-command.impl.d.ts +13 -0
- package/dist/cli/commands/sync/pull/storage.sync.pull.cli-command.impl.d.ts.map +1 -0
- package/dist/cli/commands/sync/pull/storage.sync.pull.cli-command.impl.js +136 -0
- package/dist/cli/commands/sync/pull/storage.sync.pull.cli-command.impl.js.map +1 -0
- package/dist/cli/commands/sync/push/storage.sync.push.cli-command.descriptor.d.ts +4 -0
- package/dist/cli/commands/sync/push/storage.sync.push.cli-command.descriptor.d.ts.map +1 -0
- package/dist/cli/commands/sync/push/storage.sync.push.cli-command.descriptor.js +26 -0
- package/dist/cli/commands/sync/push/storage.sync.push.cli-command.descriptor.js.map +1 -0
- package/dist/cli/commands/sync/push/storage.sync.push.cli-command.impl.d.ts +13 -0
- package/dist/cli/commands/sync/push/storage.sync.push.cli-command.impl.d.ts.map +1 -0
- package/dist/cli/commands/sync/push/storage.sync.push.cli-command.impl.js +165 -0
- package/dist/cli/commands/sync/push/storage.sync.push.cli-command.impl.js.map +1 -0
- package/dist/cli/commands/sync/resolve/storage.sync.resolve.cli-command.descriptor.d.ts +4 -0
- package/dist/cli/commands/sync/resolve/storage.sync.resolve.cli-command.descriptor.d.ts.map +1 -0
- package/dist/cli/commands/sync/resolve/storage.sync.resolve.cli-command.descriptor.js +20 -0
- package/dist/cli/commands/sync/resolve/storage.sync.resolve.cli-command.descriptor.js.map +1 -0
- package/dist/cli/commands/sync/resolve/storage.sync.resolve.cli-command.impl.d.ts +12 -0
- package/dist/cli/commands/sync/resolve/storage.sync.resolve.cli-command.impl.d.ts.map +1 -0
- package/dist/cli/commands/sync/resolve/storage.sync.resolve.cli-command.impl.js +95 -0
- package/dist/cli/commands/sync/resolve/storage.sync.resolve.cli-command.impl.js.map +1 -0
- package/dist/cli/commands/sync/status/storage.sync.status.cli-command.descriptor.d.ts +4 -0
- package/dist/cli/commands/sync/status/storage.sync.status.cli-command.descriptor.d.ts.map +1 -0
- package/dist/cli/commands/sync/status/storage.sync.status.cli-command.descriptor.js +15 -0
- package/dist/cli/commands/sync/status/storage.sync.status.cli-command.descriptor.js.map +1 -0
- package/dist/cli/commands/sync/status/storage.sync.status.cli-command.impl.d.ts +13 -0
- package/dist/cli/commands/sync/status/storage.sync.status.cli-command.impl.d.ts.map +1 -0
- package/dist/cli/commands/sync/status/storage.sync.status.cli-command.impl.js +150 -0
- package/dist/cli/commands/sync/status/storage.sync.status.cli-command.impl.js.map +1 -0
- package/dist/cli/context.consumer.d.ts +26 -0
- package/dist/cli/context.consumer.d.ts.map +1 -0
- package/dist/cli/context.consumer.js +164 -0
- package/dist/cli/context.consumer.js.map +1 -0
- package/dist/cli/storage.cli-group.descriptor.d.ts +4 -0
- package/dist/cli/storage.cli-group.descriptor.d.ts.map +1 -0
- package/dist/cli/storage.cli-group.descriptor.js +11 -0
- package/dist/cli/storage.cli-group.descriptor.js.map +1 -0
- package/dist/cli/storage.sync.cli-group.descriptor.d.ts +4 -0
- package/dist/cli/storage.sync.cli-group.descriptor.d.ts.map +1 -0
- package/dist/cli/storage.sync.cli-group.descriptor.js +12 -0
- package/dist/cli/storage.sync.cli-group.descriptor.js.map +1 -0
- package/dist/cli/types.d.ts +26 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +11 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/client/index.d.ts +10 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +10 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/list-browsable-adapters.d.ts +31 -0
- package/dist/client/list-browsable-adapters.d.ts.map +1 -0
- package/dist/client/list-browsable-adapters.js +40 -0
- package/dist/client/list-browsable-adapters.js.map +1 -0
- package/dist/daemon/commands/sync.d.ts +23 -0
- package/dist/daemon/commands/sync.d.ts.map +1 -0
- package/dist/daemon/commands/sync.js +169 -0
- package/dist/daemon/commands/sync.js.map +1 -0
- package/dist/docs/adapters.docs.descriptor.d.ts +4 -0
- package/dist/docs/adapters.docs.descriptor.d.ts.map +1 -0
- package/dist/docs/adapters.docs.descriptor.js +223 -0
- package/dist/docs/adapters.docs.descriptor.js.map +1 -0
- package/dist/docs/manifests.docs.descriptor.d.ts +4 -0
- package/dist/docs/manifests.docs.descriptor.d.ts.map +1 -0
- package/dist/docs/manifests.docs.descriptor.js +316 -0
- package/dist/docs/manifests.docs.descriptor.js.map +1 -0
- package/dist/docs/records.docs.descriptor.d.ts +4 -0
- package/dist/docs/records.docs.descriptor.d.ts.map +1 -0
- package/dist/docs/records.docs.descriptor.js +269 -0
- package/dist/docs/records.docs.descriptor.js.map +1 -0
- package/dist/docs/sync.docs.descriptor.d.ts +4 -0
- package/dist/docs/sync.docs.descriptor.d.ts.map +1 -0
- package/dist/docs/sync.docs.descriptor.js +279 -0
- package/dist/docs/sync.docs.descriptor.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/adapter.d.ts +382 -0
- package/dist/interfaces/adapter.d.ts.map +1 -0
- package/dist/interfaces/adapter.js +11 -0
- package/dist/interfaces/adapter.js.map +1 -0
- package/dist/interfaces/document-store.d.ts +62 -0
- package/dist/interfaces/document-store.d.ts.map +1 -0
- package/dist/interfaces/document-store.js +8 -0
- package/dist/interfaces/document-store.js.map +1 -0
- package/dist/interfaces/index.d.ts +17 -0
- package/dist/interfaces/index.d.ts.map +1 -0
- package/dist/interfaces/index.js +24 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interfaces/key-value.d.ts +95 -0
- package/dist/interfaces/key-value.d.ts.map +1 -0
- package/dist/interfaces/key-value.js +8 -0
- package/dist/interfaces/key-value.js.map +1 -0
- package/dist/interfaces/query-builder.d.ts +31 -0
- package/dist/interfaces/query-builder.d.ts.map +1 -0
- package/dist/interfaces/query-builder.js +11 -0
- package/dist/interfaces/query-builder.js.map +1 -0
- package/dist/interfaces/record/index.d.ts +7 -0
- package/dist/interfaces/record/index.d.ts.map +1 -0
- package/dist/interfaces/record/index.js +7 -0
- package/dist/interfaces/record/index.js.map +1 -0
- package/dist/interfaces/record/interface.d.ts +593 -0
- package/dist/interfaces/record/interface.d.ts.map +1 -0
- package/dist/interfaces/record/interface.js +49 -0
- package/dist/interfaces/record/interface.js.map +1 -0
- package/dist/interfaces/repository.d.ts +262 -0
- package/dist/interfaces/repository.d.ts.map +1 -0
- package/dist/interfaces/repository.js +8 -0
- package/dist/interfaces/repository.js.map +1 -0
- package/dist/interfaces/schema/index.d.ts +8 -0
- package/dist/interfaces/schema/index.d.ts.map +1 -0
- package/dist/interfaces/schema/index.js +10 -0
- package/dist/interfaces/schema/index.js.map +1 -0
- package/dist/interfaces/schema/schema-interface.d.ts +516 -0
- package/dist/interfaces/schema/schema-interface.d.ts.map +1 -0
- package/dist/interfaces/schema/schema-interface.js +31 -0
- package/dist/interfaces/schema/schema-interface.js.map +1 -0
- package/dist/interfaces/schema/table-interface.d.ts +250 -0
- package/dist/interfaces/schema/table-interface.d.ts.map +1 -0
- package/dist/interfaces/schema/table-interface.js +31 -0
- package/dist/interfaces/schema/table-interface.js.map +1 -0
- package/dist/interfaces/storage-consumer-fs.d.ts +40 -0
- package/dist/interfaces/storage-consumer-fs.d.ts.map +1 -0
- package/dist/interfaces/storage-consumer-fs.js +42 -0
- package/dist/interfaces/storage-consumer-fs.js.map +1 -0
- package/dist/manifest/base.d.ts +187 -0
- package/dist/manifest/base.d.ts.map +1 -0
- package/dist/manifest/base.js +516 -0
- package/dist/manifest/base.js.map +1 -0
- package/dist/manifest/cloud-sync.consumer.d.ts +7 -0
- package/dist/manifest/cloud-sync.consumer.d.ts.map +1 -0
- package/dist/manifest/cloud-sync.consumer.js +82 -0
- package/dist/manifest/cloud-sync.consumer.js.map +1 -0
- package/dist/manifest/index.d.ts +7 -0
- package/dist/manifest/index.d.ts.map +1 -0
- package/dist/manifest/index.js +7 -0
- package/dist/manifest/index.js.map +1 -0
- package/dist/manifest/source-policy.d.ts +8 -0
- package/dist/manifest/source-policy.d.ts.map +1 -0
- package/dist/manifest/source-policy.js +62 -0
- package/dist/manifest/source-policy.js.map +1 -0
- package/dist/paths.d.ts +6 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +152 -0
- package/dist/paths.js.map +1 -0
- package/dist/policy/context.d.ts +9 -0
- package/dist/policy/context.d.ts.map +1 -0
- package/dist/policy/context.js +29 -0
- package/dist/policy/context.js.map +1 -0
- package/dist/policy/index.d.ts +4 -0
- package/dist/policy/index.d.ts.map +1 -0
- package/dist/policy/index.js +4 -0
- package/dist/policy/index.js.map +1 -0
- package/dist/policy/overrides.d.ts +40 -0
- package/dist/policy/overrides.d.ts.map +1 -0
- package/dist/policy/overrides.js +37 -0
- package/dist/policy/overrides.js.map +1 -0
- package/dist/policy/persistence.d.ts +38 -0
- package/dist/policy/persistence.d.ts.map +1 -0
- package/dist/policy/persistence.js +65 -0
- package/dist/policy/persistence.js.map +1 -0
- package/dist/policy/types.d.ts +21 -0
- package/dist/policy/types.d.ts.map +1 -0
- package/dist/policy/types.js +7 -0
- package/dist/policy/types.js.map +1 -0
- package/dist/record/base.d.ts +186 -0
- package/dist/record/base.d.ts.map +1 -0
- package/dist/record/base.js +1437 -0
- package/dist/record/base.js.map +1 -0
- package/dist/record/events.d.ts +71 -0
- package/dist/record/events.d.ts.map +1 -0
- package/dist/record/events.js +52 -0
- package/dist/record/events.js.map +1 -0
- package/dist/record/extensions.d.ts +51 -0
- package/dist/record/extensions.d.ts.map +1 -0
- package/dist/record/extensions.js +222 -0
- package/dist/record/extensions.js.map +1 -0
- package/dist/record/index.d.ts +7 -0
- package/dist/record/index.d.ts.map +1 -0
- package/dist/record/index.js +7 -0
- package/dist/record/index.js.map +1 -0
- package/dist/resolver/storage-backed-resolver.d.ts +23 -0
- package/dist/resolver/storage-backed-resolver.d.ts.map +1 -0
- package/dist/resolver/storage-backed-resolver.js +187 -0
- package/dist/resolver/storage-backed-resolver.js.map +1 -0
- package/dist/schemas/adapter-descriptor.d.ts +108 -0
- package/dist/schemas/adapter-descriptor.d.ts.map +1 -0
- package/dist/schemas/adapter-descriptor.js +101 -0
- package/dist/schemas/adapter-descriptor.js.map +1 -0
- package/dist/schemas/index.d.ts +14 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +12 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/manifest-descriptor.d.ts +110 -0
- package/dist/schemas/manifest-descriptor.d.ts.map +1 -0
- package/dist/schemas/manifest-descriptor.js +114 -0
- package/dist/schemas/manifest-descriptor.js.map +1 -0
- package/dist/schemas/record/descriptor.d.ts +570 -0
- package/dist/schemas/record/descriptor.d.ts.map +1 -0
- package/dist/schemas/record/descriptor.js +389 -0
- package/dist/schemas/record/descriptor.js.map +1 -0
- package/dist/schemas/record/index.d.ts +8 -0
- package/dist/schemas/record/index.d.ts.map +1 -0
- package/dist/schemas/record/index.js +7 -0
- package/dist/schemas/record/index.js.map +1 -0
- package/dist/schemas/record/relation.d.ts +36 -0
- package/dist/schemas/record/relation.d.ts.map +1 -0
- package/dist/schemas/record/relation.js +37 -0
- package/dist/schemas/record/relation.js.map +1 -0
- package/dist/schemas/schema/descriptor.d.ts +231 -0
- package/dist/schemas/schema/descriptor.d.ts.map +1 -0
- package/dist/schemas/schema/descriptor.js +205 -0
- package/dist/schemas/schema/descriptor.js.map +1 -0
- package/dist/schemas/schema/index.d.ts +7 -0
- package/dist/schemas/schema/index.d.ts.map +1 -0
- package/dist/schemas/schema/index.js +7 -0
- package/dist/schemas/schema/index.js.map +1 -0
- package/dist/schemas/sync-bridge-descriptor.d.ts +124 -0
- package/dist/schemas/sync-bridge-descriptor.d.ts.map +1 -0
- package/dist/schemas/sync-bridge-descriptor.js +67 -0
- package/dist/schemas/sync-bridge-descriptor.js.map +1 -0
- package/dist/server/manifest-route.d.ts +92 -0
- package/dist/server/manifest-route.d.ts.map +1 -0
- package/dist/server/manifest-route.js +226 -0
- package/dist/server/manifest-route.js.map +1 -0
- package/dist/storage-policy.context.descriptor.d.ts +16 -0
- package/dist/storage-policy.context.descriptor.d.ts.map +1 -0
- package/dist/storage-policy.context.descriptor.js +16 -0
- package/dist/storage-policy.context.descriptor.js.map +1 -0
- package/dist/storage-policy.context.server.d.ts +14 -0
- package/dist/storage-policy.context.server.d.ts.map +1 -0
- package/dist/storage-policy.context.server.js +27 -0
- package/dist/storage-policy.context.server.js.map +1 -0
- package/dist/storage.plugin.d.ts +38 -0
- package/dist/storage.plugin.d.ts.map +1 -0
- package/dist/storage.plugin.js +204 -0
- package/dist/storage.plugin.js.map +1 -0
- package/dist/sync/cloud-pull.d.ts +15 -0
- package/dist/sync/cloud-pull.d.ts.map +1 -0
- package/dist/sync/cloud-pull.js +130 -0
- package/dist/sync/cloud-pull.js.map +1 -0
- package/dist/sync/cloud-record-crud-config.d.ts +19 -0
- package/dist/sync/cloud-record-crud-config.d.ts.map +1 -0
- package/dist/sync/cloud-record-crud-config.js +22 -0
- package/dist/sync/cloud-record-crud-config.js.map +1 -0
- package/dist/sync/record-sync-bridge.d.ts +5 -0
- package/dist/sync/record-sync-bridge.d.ts.map +1 -0
- package/dist/sync/record-sync-bridge.js +121 -0
- package/dist/sync/record-sync-bridge.js.map +1 -0
- package/dist/sync/resolve-sync-target.d.ts +23 -0
- package/dist/sync/resolve-sync-target.d.ts.map +1 -0
- package/dist/sync/resolve-sync-target.js +45 -0
- package/dist/sync/resolve-sync-target.js.map +1 -0
- package/dist/sync/schemas/cloud-pull.d.ts +25 -0
- package/dist/sync/schemas/cloud-pull.d.ts.map +1 -0
- package/dist/sync/schemas/cloud-pull.js +7 -0
- package/dist/sync/schemas/cloud-pull.js.map +1 -0
- package/dist/sync/schemas/index.d.ts +9 -0
- package/dist/sync/schemas/index.d.ts.map +1 -0
- package/dist/sync/schemas/index.js +9 -0
- package/dist/sync/schemas/index.js.map +1 -0
- package/dist/sync/schemas/sync-helpers.d.ts +17 -0
- package/dist/sync/schemas/sync-helpers.d.ts.map +1 -0
- package/dist/sync/schemas/sync-helpers.js +7 -0
- package/dist/sync/schemas/sync-helpers.js.map +1 -0
- package/dist/sync/schemas/sync-state.d.ts +65 -0
- package/dist/sync/schemas/sync-state.d.ts.map +1 -0
- package/dist/sync/schemas/sync-state.js +32 -0
- package/dist/sync/schemas/sync-state.js.map +1 -0
- package/dist/sync/sync-bridge.d.ts +80 -0
- package/dist/sync/sync-bridge.d.ts.map +1 -0
- package/dist/sync/sync-bridge.js +617 -0
- package/dist/sync/sync-bridge.js.map +1 -0
- package/dist/sync/sync-manifest.d.ts +20 -0
- package/dist/sync/sync-manifest.d.ts.map +1 -0
- package/dist/sync/sync-manifest.js +140 -0
- package/dist/sync/sync-manifest.js.map +1 -0
- package/dist/sync/sync-state.consumer.d.ts +23 -0
- package/dist/sync/sync-state.consumer.d.ts.map +1 -0
- package/dist/sync/sync-state.consumer.js +111 -0
- package/dist/sync/sync-state.consumer.js.map +1 -0
- package/dist/transform/index.d.ts +75 -0
- package/dist/transform/index.d.ts.map +1 -0
- package/dist/transform/index.js +81 -0
- package/dist/transform/index.js.map +1 -0
- package/dist/transform/transform-descriptor.d.ts +51 -0
- package/dist/transform/transform-descriptor.d.ts.map +1 -0
- package/dist/transform/transform-descriptor.js +30 -0
- package/dist/transform/transform-descriptor.js.map +1 -0
- package/dist/tui/storage-explorer.descriptor.d.ts +14 -0
- package/dist/tui/storage-explorer.descriptor.d.ts.map +1 -0
- package/dist/tui/storage-explorer.descriptor.js +29 -0
- package/dist/tui/storage-explorer.descriptor.js.map +1 -0
- package/dist/tui/storage-explorer.impl.consumer.d.ts +11 -0
- package/dist/tui/storage-explorer.impl.consumer.d.ts.map +1 -0
- package/dist/tui/storage-explorer.impl.consumer.js +13 -0
- package/dist/tui/storage-explorer.impl.consumer.js.map +1 -0
- package/dist/tui/storage-open.descriptor.d.ts +14 -0
- package/dist/tui/storage-open.descriptor.d.ts.map +1 -0
- package/dist/tui/storage-open.descriptor.js +28 -0
- package/dist/tui/storage-open.descriptor.js.map +1 -0
- package/dist/tui/storage-open.impl.consumer.d.ts +11 -0
- package/dist/tui/storage-open.impl.consumer.d.ts.map +1 -0
- package/dist/tui/storage-open.impl.consumer.js +13 -0
- package/dist/tui/storage-open.impl.consumer.js.map +1 -0
- package/dist/utils/error-context.d.ts +2 -0
- package/dist/utils/error-context.d.ts.map +1 -0
- package/dist/utils/error-context.js +17 -0
- package/dist/utils/error-context.js.map +1 -0
- package/package.json +241 -0
- package/src/adapters/index.ts +13 -0
- package/src/bridge/index.ts +2 -0
- package/src/bridge/storage-kind-bridge.ts +131 -0
- package/src/bridge/types.ts +46 -0
- package/src/cli/commands/list/storage.list.cli-command.descriptor.ts +20 -0
- package/src/cli/commands/list/storage.list.cli-command.impl.ts +72 -0
- package/src/cli/commands/sync/pull/storage.sync.pull.cli-command.descriptor.ts +28 -0
- package/src/cli/commands/sync/pull/storage.sync.pull.cli-command.impl.ts +171 -0
- package/src/cli/commands/sync/push/storage.sync.push.cli-command.descriptor.ts +28 -0
- package/src/cli/commands/sync/push/storage.sync.push.cli-command.impl.ts +213 -0
- package/src/cli/commands/sync/resolve/storage.sync.resolve.cli-command.descriptor.ts +22 -0
- package/src/cli/commands/sync/resolve/storage.sync.resolve.cli-command.impl.ts +129 -0
- package/src/cli/commands/sync/status/storage.sync.status.cli-command.descriptor.ts +17 -0
- package/src/cli/commands/sync/status/storage.sync.status.cli-command.impl.ts +192 -0
- package/src/cli/context.consumer.ts +195 -0
- package/src/cli/storage.cli-group.descriptor.ts +13 -0
- package/src/cli/storage.sync.cli-group.descriptor.ts +14 -0
- package/src/cli/types.ts +25 -0
- package/src/client/index.ts +10 -0
- package/src/client/list-browsable-adapters.ts +42 -0
- package/src/daemon/commands/sync.ts +225 -0
- package/src/docs/adapters.docs.descriptor.ts +225 -0
- package/src/docs/manifests.docs.descriptor.ts +318 -0
- package/src/docs/records.docs.descriptor.ts +271 -0
- package/src/docs/sync.docs.descriptor.ts +281 -0
- package/src/index.ts +109 -0
- package/src/interfaces/adapter.ts +451 -0
- package/src/interfaces/document-store.ts +74 -0
- package/src/interfaces/index.ts +117 -0
- package/src/interfaces/key-value.ts +112 -0
- package/src/interfaces/query-builder.ts +31 -0
- package/src/interfaces/record/index.ts +58 -0
- package/src/interfaces/record/interface.ts +723 -0
- package/src/interfaces/repository.ts +300 -0
- package/src/interfaces/schema/index.ts +37 -0
- package/src/interfaces/schema/schema-interface.ts +586 -0
- package/src/interfaces/schema/table-interface.ts +314 -0
- package/src/interfaces/storage-consumer-fs.ts +66 -0
- package/src/manifest/base.ts +594 -0
- package/src/manifest/cloud-sync.consumer.ts +120 -0
- package/src/manifest/index.ts +7 -0
- package/src/manifest/source-policy.ts +74 -0
- package/src/paths.ts +171 -0
- package/src/policy/context.ts +30 -0
- package/src/policy/index.ts +20 -0
- package/src/policy/overrides.ts +46 -0
- package/src/policy/persistence.ts +117 -0
- package/src/policy/types.ts +28 -0
- package/src/record/base.ts +1872 -0
- package/src/record/events.ts +56 -0
- package/src/record/extensions.ts +308 -0
- package/src/record/index.ts +7 -0
- package/src/resolver/storage-backed-resolver.ts +255 -0
- package/src/schemas/adapter-descriptor.ts +128 -0
- package/src/schemas/index.ts +104 -0
- package/src/schemas/manifest-descriptor.ts +143 -0
- package/src/schemas/record/descriptor.ts +621 -0
- package/src/schemas/record/index.ts +60 -0
- package/src/schemas/record/relation.ts +49 -0
- package/src/schemas/schema/descriptor.ts +278 -0
- package/src/schemas/schema/index.ts +14 -0
- package/src/schemas/sync-bridge-descriptor.ts +143 -0
- package/src/server/manifest-route.ts +319 -0
- package/src/storage-policy.context.descriptor.ts +17 -0
- package/src/storage-policy.context.server.ts +34 -0
- package/src/storage.plugin.ts +264 -0
- package/src/sync/cloud-pull.ts +202 -0
- package/src/sync/cloud-record-crud-config.ts +41 -0
- package/src/sync/record-sync-bridge.ts +183 -0
- package/src/sync/resolve-sync-target.ts +57 -0
- package/src/sync/schemas/cloud-pull.ts +26 -0
- package/src/sync/schemas/index.ts +18 -0
- package/src/sync/schemas/sync-helpers.ts +18 -0
- package/src/sync/schemas/sync-state.ts +41 -0
- package/src/sync/sync-bridge.ts +763 -0
- package/src/sync/sync-manifest.ts +212 -0
- package/src/sync/sync-state.consumer.ts +144 -0
- package/src/transform/index.ts +130 -0
- package/src/transform/transform-descriptor.ts +53 -0
- package/src/tui/storage-explorer.descriptor.ts +32 -0
- package/src/tui/storage-explorer.impl.consumer.ts +14 -0
- package/src/tui/storage-open.descriptor.ts +31 -0
- package/src/tui/storage-open.impl.consumer.ts +14 -0
- package/src/utils/error-context.ts +19 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage Record Lifecycle Events
|
|
3
|
+
*
|
|
4
|
+
* Declares runtime/event descriptors for StorageRecord CRUD operations.
|
|
5
|
+
* These are automatically emitted by StorageRecord — no manual emission needed.
|
|
6
|
+
*
|
|
7
|
+
* Subscribe to these events via runtime/subscription descriptors:
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* createRuntimeAsset({
|
|
11
|
+
* kind: 'runtime/subscription',
|
|
12
|
+
* id: 'my-feature.on-record-created',
|
|
13
|
+
* event: 'storage.record.afterCreate',
|
|
14
|
+
* handler: 'my-feature.process-new-record',
|
|
15
|
+
* filter: { recordKind: 'knowledge.items' }
|
|
16
|
+
* })
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { createRuntimeAsset } from '@vibesdotdev/runtime';
|
|
21
|
+
|
|
22
|
+
export const storageRecordCreatedEvent = createRuntimeAsset({
|
|
23
|
+
kind: 'runtime/event' as const,
|
|
24
|
+
id: 'storage.record.afterCreate',
|
|
25
|
+
name: 'Storage Record Created',
|
|
26
|
+
description: 'Emitted after a StorageRecord creates a new record',
|
|
27
|
+
trigger: 'lifecycle' as const,
|
|
28
|
+
source: 'storage/record',
|
|
29
|
+
lifecycle: 'afterCreate' as const
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export const storageRecordUpdatedEvent = createRuntimeAsset({
|
|
33
|
+
kind: 'runtime/event' as const,
|
|
34
|
+
id: 'storage.record.afterUpdate',
|
|
35
|
+
name: 'Storage Record Updated',
|
|
36
|
+
description: 'Emitted after a StorageRecord updates an existing record',
|
|
37
|
+
trigger: 'lifecycle' as const,
|
|
38
|
+
source: 'storage/record',
|
|
39
|
+
lifecycle: 'afterUpdate' as const
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export const storageRecordDeletedEvent = createRuntimeAsset({
|
|
43
|
+
kind: 'runtime/event' as const,
|
|
44
|
+
id: 'storage.record.afterDelete',
|
|
45
|
+
name: 'Storage Record Deleted',
|
|
46
|
+
description: 'Emitted after a StorageRecord deletes a record (soft or hard)',
|
|
47
|
+
trigger: 'lifecycle' as const,
|
|
48
|
+
source: 'storage/record',
|
|
49
|
+
lifecycle: 'afterDelete' as const
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export const storageRecordEvents = [
|
|
53
|
+
storageRecordCreatedEvent,
|
|
54
|
+
storageRecordUpdatedEvent,
|
|
55
|
+
storageRecordDeletedEvent
|
|
56
|
+
];
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StorageRecord Extended Methods
|
|
3
|
+
*
|
|
4
|
+
* Additional methods for FTS, hierarchy, computed fields, side effects, and raw queries.
|
|
5
|
+
* These are mixed into the StorageRecord class.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { SqlDatabaseHandle } from '../interfaces/adapter';
|
|
9
|
+
import { getLogger } from '@vibesdotdev/logging';
|
|
10
|
+
import { toErrorContext } from '../utils/error-context';
|
|
11
|
+
|
|
12
|
+
import type { StorageRecordDescriptor, StorageSideEffect } from '../schemas/record';
|
|
13
|
+
|
|
14
|
+
const logger = getLogger('storage:record');
|
|
15
|
+
import type {
|
|
16
|
+
SearchOptions,
|
|
17
|
+
SearchResult,
|
|
18
|
+
HierarchyOptions,
|
|
19
|
+
TreeNode,
|
|
20
|
+
RawQueryOptions,
|
|
21
|
+
QueryOptions,
|
|
22
|
+
QueryResult
|
|
23
|
+
} from '../interfaces/record';
|
|
24
|
+
import type { VibesRuntime } from '@vibesdotdev/runtime';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Extended StorageRecord methods interface
|
|
28
|
+
*/
|
|
29
|
+
export interface StorageRecordExtensions<T> {
|
|
30
|
+
// FTS
|
|
31
|
+
search(query: string, options?: SearchOptions<T>): Promise<SearchResult<T>>;
|
|
32
|
+
|
|
33
|
+
// Hierarchy
|
|
34
|
+
getDescendants(
|
|
35
|
+
id: string,
|
|
36
|
+
options?: HierarchyOptions<T>
|
|
37
|
+
): Promise<QueryResult<T & { depth: number; path?: string[] }>>;
|
|
38
|
+
getAncestors(id: string, options?: QueryOptions<T>): Promise<T[]>;
|
|
39
|
+
getTree(options?: HierarchyOptions<T>): Promise<TreeNode<T>[]>;
|
|
40
|
+
|
|
41
|
+
// Raw
|
|
42
|
+
raw<R>(sql: string, ...params: unknown[]): Promise<R[]>;
|
|
43
|
+
queryRaw<R>(options: RawQueryOptions<R>): Promise<R[]>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Create FTS table and triggers for SQLite
|
|
48
|
+
*/
|
|
49
|
+
export function createFtsTable(
|
|
50
|
+
db: SqlDatabaseHandle,
|
|
51
|
+
tableName: string,
|
|
52
|
+
ftsFields: string[],
|
|
53
|
+
ftsTableName?: string,
|
|
54
|
+
tokenizer?: string
|
|
55
|
+
): void {
|
|
56
|
+
const ftsTable = ftsTableName || `${tableName}_fts`;
|
|
57
|
+
const tokenizerConfig = tokenizer || 'unicode61';
|
|
58
|
+
const fields = ftsFields.join(', ');
|
|
59
|
+
|
|
60
|
+
db.exec(`
|
|
61
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS ${ftsTable} USING fts5(
|
|
62
|
+
${fields},
|
|
63
|
+
content='${tableName}',
|
|
64
|
+
tokenize='${tokenizerConfig}'
|
|
65
|
+
)
|
|
66
|
+
`);
|
|
67
|
+
|
|
68
|
+
db.exec(`
|
|
69
|
+
CREATE TRIGGER IF NOT EXISTS ${tableName}_fts_insert AFTER INSERT ON ${tableName}
|
|
70
|
+
BEGIN
|
|
71
|
+
INSERT INTO ${ftsTable}(rowid, ${fields})
|
|
72
|
+
SELECT NEW.rowid, ${ftsFields.map((f) => `NEW.${f}`).join(', ')}
|
|
73
|
+
FROM ${tableName} WHERE rowid = NEW.rowid;
|
|
74
|
+
END
|
|
75
|
+
`);
|
|
76
|
+
|
|
77
|
+
db.exec(`
|
|
78
|
+
CREATE TRIGGER IF NOT EXISTS ${tableName}_fts_delete AFTER DELETE ON ${tableName}
|
|
79
|
+
BEGIN
|
|
80
|
+
INSERT INTO ${ftsTable}(${ftsTable}, rowid, ${fields})
|
|
81
|
+
VALUES('delete', OLD.rowid, ${ftsFields.map(() => 'NULL').join(', ')});
|
|
82
|
+
END
|
|
83
|
+
`);
|
|
84
|
+
|
|
85
|
+
db.exec(`
|
|
86
|
+
CREATE TRIGGER IF NOT EXISTS ${tableName}_fts_update AFTER UPDATE ON ${tableName}
|
|
87
|
+
BEGIN
|
|
88
|
+
INSERT INTO ${ftsTable}(${ftsTable}, rowid, ${fields})
|
|
89
|
+
VALUES('delete', OLD.rowid, ${ftsFields.map(() => 'NULL').join(', ')});
|
|
90
|
+
INSERT INTO ${ftsTable}(rowid, ${fields})
|
|
91
|
+
SELECT NEW.rowid, ${ftsFields.map((f) => `NEW.${f}`).join(', ')}
|
|
92
|
+
FROM ${tableName} WHERE rowid = NEW.rowid;
|
|
93
|
+
END
|
|
94
|
+
`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Build FTS search query for SQLite
|
|
99
|
+
*/
|
|
100
|
+
export function buildFtsSearchQuery(
|
|
101
|
+
tableName: string,
|
|
102
|
+
ftsFields: string[],
|
|
103
|
+
query: string,
|
|
104
|
+
options?: SearchOptions<unknown>
|
|
105
|
+
): { sql: string; params: unknown[] } {
|
|
106
|
+
const ftsTable = `${tableName}_fts`;
|
|
107
|
+
|
|
108
|
+
const escapedQuery = `"${query.replace(/"/g, '""')}"`;
|
|
109
|
+
|
|
110
|
+
let sql = `
|
|
111
|
+
SELECT
|
|
112
|
+
${tableName}.*,
|
|
113
|
+
${ftsTable}.rank as _rank
|
|
114
|
+
FROM ${tableName}
|
|
115
|
+
JOIN ${ftsTable} ON ${ftsTable}.rowid = ${tableName}.rowid
|
|
116
|
+
WHERE ${ftsTable} MATCH ?
|
|
117
|
+
`;
|
|
118
|
+
|
|
119
|
+
const params: unknown[] = [escapedQuery];
|
|
120
|
+
|
|
121
|
+
if (options?.where) {
|
|
122
|
+
const conditions = Object.entries(options.where).map(([field, value]) => {
|
|
123
|
+
params.push(value);
|
|
124
|
+
return `json_extract(${tableName}.data, '$.${field}') = ?`;
|
|
125
|
+
});
|
|
126
|
+
if (conditions.length > 0) {
|
|
127
|
+
sql += ` AND ${conditions.join(' AND ')}`;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (options?.rankByRelevance !== false) {
|
|
132
|
+
sql += ` ORDER BY ${ftsTable}.rank`;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return { sql, params };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Build recursive CTE for hierarchy queries
|
|
140
|
+
*/
|
|
141
|
+
export function buildRecursiveCTE(
|
|
142
|
+
tableName: string,
|
|
143
|
+
parentField: string,
|
|
144
|
+
primaryKey: string,
|
|
145
|
+
rootId: string,
|
|
146
|
+
options?: HierarchyOptions<unknown>
|
|
147
|
+
): { sql: string; params: unknown[] } {
|
|
148
|
+
const maxDepth = options?.maxDepth || 1000;
|
|
149
|
+
const includePath = options?.includePath !== false;
|
|
150
|
+
|
|
151
|
+
const pathArray = includePath
|
|
152
|
+
? `, CASE WHEN depth = 0 THEN json_array(id) ELSE json_insert(path, '$[#]', id) END`
|
|
153
|
+
: '';
|
|
154
|
+
|
|
155
|
+
const sql = `
|
|
156
|
+
WITH RECURSIVE hierarchy AS (
|
|
157
|
+
SELECT
|
|
158
|
+
*,
|
|
159
|
+
0 as depth
|
|
160
|
+
${pathArray}
|
|
161
|
+
FROM ${tableName}
|
|
162
|
+
WHERE ${primaryKey} = ?
|
|
163
|
+
|
|
164
|
+
UNION ALL
|
|
165
|
+
|
|
166
|
+
SELECT
|
|
167
|
+
t.*,
|
|
168
|
+
h.depth + 1 as depth
|
|
169
|
+
${pathArray}
|
|
170
|
+
FROM ${tableName} t
|
|
171
|
+
INNER JOIN hierarchy h ON t.${parentField} = h.${primaryKey}
|
|
172
|
+
WHERE h.depth < ?
|
|
173
|
+
)
|
|
174
|
+
SELECT * FROM hierarchy ORDER BY depth, ${primaryKey}
|
|
175
|
+
`;
|
|
176
|
+
|
|
177
|
+
return { sql, params: [rootId, maxDepth] };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Execute side effects
|
|
182
|
+
*/
|
|
183
|
+
export async function executeSideEffects(
|
|
184
|
+
sideEffects: StorageSideEffect[],
|
|
185
|
+
sourceRecord: Record<string, unknown>,
|
|
186
|
+
runtime?: VibesRuntime,
|
|
187
|
+
db?: SqlDatabaseHandle
|
|
188
|
+
): Promise<void> {
|
|
189
|
+
for (const effect of sideEffects) {
|
|
190
|
+
try {
|
|
191
|
+
// Get target ID from foreign key
|
|
192
|
+
const targetId = effect.foreignKey ? sourceRecord[effect.foreignKey] : null;
|
|
193
|
+
|
|
194
|
+
if (!targetId && !effect.ignoreMissing) {
|
|
195
|
+
logger.warn(`[SideEffects] No target ID for effect on ${effect.target}`);
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Calculate value
|
|
200
|
+
let value: unknown;
|
|
201
|
+
if (effect.valueFn) {
|
|
202
|
+
value = (effect.valueFn as Function)(sourceRecord);
|
|
203
|
+
} else if (effect.value !== undefined) {
|
|
204
|
+
value = effect.value;
|
|
205
|
+
} else if (effect.operation === 'touch') {
|
|
206
|
+
value = new Date().toISOString();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Execute update
|
|
210
|
+
if (db && targetId) {
|
|
211
|
+
const _setClause = effect.field ? `json_set(data, '$.${effect.field}', ?)` : '?';
|
|
212
|
+
|
|
213
|
+
if (effect.operation === 'increment' && effect.field) {
|
|
214
|
+
db.query(
|
|
215
|
+
`
|
|
216
|
+
UPDATE ${effect.target.split('.')[1] || effect.target}
|
|
217
|
+
SET data = json_set(data, '$.${effect.field}',
|
|
218
|
+
COALESCE(json_extract(data, '$.${effect.field}'), 0) + 1)
|
|
219
|
+
WHERE id = ?
|
|
220
|
+
`
|
|
221
|
+
).run(targetId as string);
|
|
222
|
+
} else if (effect.operation === 'decrement' && effect.field) {
|
|
223
|
+
db.query(
|
|
224
|
+
`
|
|
225
|
+
UPDATE ${effect.target.split('.')[1] || effect.target}
|
|
226
|
+
SET data = json_set(data, '$.${effect.field}',
|
|
227
|
+
COALESCE(json_extract(data, '$.${effect.field}'), 0) - 1)
|
|
228
|
+
WHERE id = ?
|
|
229
|
+
`
|
|
230
|
+
).run(targetId as string);
|
|
231
|
+
} else if (effect.field) {
|
|
232
|
+
db.query(
|
|
233
|
+
`
|
|
234
|
+
UPDATE ${effect.target.split('.')[1] || effect.target}
|
|
235
|
+
SET data = json_set(data, '$.${effect.field}', ?)
|
|
236
|
+
WHERE id = ?
|
|
237
|
+
`
|
|
238
|
+
).run(value as string, targetId as string);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
} catch (error) {
|
|
242
|
+
logger.error(`[SideEffects] Failed to execute effect:`, toErrorContext(error));
|
|
243
|
+
if (!effect.ignoreMissing) {
|
|
244
|
+
throw error;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Build computed field subquery
|
|
252
|
+
*/
|
|
253
|
+
export function buildComputedFieldSubquery(
|
|
254
|
+
descriptor: StorageRecordDescriptor,
|
|
255
|
+
fieldName: string,
|
|
256
|
+
computedField: NonNullable<StorageRecordDescriptor['computedFields']>[string]
|
|
257
|
+
): string {
|
|
258
|
+
const relation = descriptor.relations?.[computedField.relation];
|
|
259
|
+
if (!relation) return '0';
|
|
260
|
+
|
|
261
|
+
const targetTable = relation.target.split('.')[1] || relation.target;
|
|
262
|
+
const foreignKey = relation.foreignKey || `${descriptor.tableName.slice(0, -1)}_id`;
|
|
263
|
+
|
|
264
|
+
let aggregation: string;
|
|
265
|
+
switch (computedField.type) {
|
|
266
|
+
case 'count':
|
|
267
|
+
aggregation = 'COUNT(*)';
|
|
268
|
+
break;
|
|
269
|
+
case 'sum':
|
|
270
|
+
aggregation = computedField.field
|
|
271
|
+
? `SUM(CAST(json_extract(data, '$.${computedField.field}') AS REAL))`
|
|
272
|
+
: '0';
|
|
273
|
+
break;
|
|
274
|
+
case 'avg':
|
|
275
|
+
aggregation = computedField.field
|
|
276
|
+
? `AVG(CAST(json_extract(data, '$.${computedField.field}') AS REAL))`
|
|
277
|
+
: '0';
|
|
278
|
+
break;
|
|
279
|
+
case 'min':
|
|
280
|
+
aggregation = computedField.field
|
|
281
|
+
? `MIN(json_extract(data, '$.${computedField.field}'))`
|
|
282
|
+
: 'NULL';
|
|
283
|
+
break;
|
|
284
|
+
case 'max':
|
|
285
|
+
aggregation = computedField.field
|
|
286
|
+
? `MAX(json_extract(data, '$.${computedField.field}'))`
|
|
287
|
+
: 'NULL';
|
|
288
|
+
break;
|
|
289
|
+
case 'exists':
|
|
290
|
+
aggregation = 'CASE WHEN EXISTS(SELECT 1) THEN 1 ELSE 0 END';
|
|
291
|
+
break;
|
|
292
|
+
default:
|
|
293
|
+
aggregation = '0';
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const whereClause = computedField.where
|
|
297
|
+
? Object.entries(computedField.where)
|
|
298
|
+
.map(([field, value]) => `json_extract(data, '$.${field}') = '${value}'`)
|
|
299
|
+
.join(' AND ')
|
|
300
|
+
: '';
|
|
301
|
+
|
|
302
|
+
return `(
|
|
303
|
+
SELECT ${aggregation}
|
|
304
|
+
FROM ${targetTable}
|
|
305
|
+
WHERE ${foreignKey} = ${descriptor.tableName}.${descriptor.primaryKey}
|
|
306
|
+
${whereClause ? `AND ${whereClause}` : ''}
|
|
307
|
+
) as ${fieldName}`;
|
|
308
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import type { RuntimeDescriptor } from '@vibesdotdev/runtime/schemas/descriptor';
|
|
2
|
+
import type {
|
|
3
|
+
RuntimeResolverDescriptor,
|
|
4
|
+
RuntimeResolverFetchAllOptions,
|
|
5
|
+
RuntimeResolverFetchOptions,
|
|
6
|
+
RuntimeResolverInterface
|
|
7
|
+
} from '@vibesdotdev/runtime/schemas/resolver';
|
|
8
|
+
import type { StorageManifestDescriptor } from '../schemas/manifest-descriptor';
|
|
9
|
+
import type { StorageKindBridgeConfig } from '../bridge/types';
|
|
10
|
+
import type { KindContext } from '@vibesdotdev/runtime/schemas/kind';
|
|
11
|
+
import { StorageManifest } from '../manifest/base';
|
|
12
|
+
import {
|
|
13
|
+
resolveAdapterOrderBySource,
|
|
14
|
+
resolveScopeForSource,
|
|
15
|
+
resolveSourceFromAdapter,
|
|
16
|
+
type ManifestDataSource
|
|
17
|
+
} from '../manifest/source-policy';
|
|
18
|
+
|
|
19
|
+
interface SourcedManifestItem {
|
|
20
|
+
item: unknown;
|
|
21
|
+
source: ManifestDataSource | null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type ManifestDescriptor = StorageManifestDescriptor;
|
|
25
|
+
|
|
26
|
+
export class StorageBackedResolver implements RuntimeResolverInterface {
|
|
27
|
+
private readonly manifestId: string;
|
|
28
|
+
private readonly manifestKind: 'storage/manifest' | 'config/manifest';
|
|
29
|
+
private readonly targetKind: string;
|
|
30
|
+
|
|
31
|
+
constructor(
|
|
32
|
+
descriptor: RuntimeResolverDescriptor,
|
|
33
|
+
private context: KindContext
|
|
34
|
+
) {
|
|
35
|
+
this.manifestId = descriptor.manifestId;
|
|
36
|
+
this.manifestKind = descriptor.manifestKind ?? 'storage/manifest';
|
|
37
|
+
this.targetKind = descriptor.targetKind;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async fetch(
|
|
41
|
+
id: string,
|
|
42
|
+
options?: RuntimeResolverFetchOptions
|
|
43
|
+
): Promise<RuntimeDescriptor | null> {
|
|
44
|
+
const cached = options?.cache?.getDescriptors()?.find((descriptor: RuntimeDescriptor) => descriptor.id === id);
|
|
45
|
+
if (cached) return cached;
|
|
46
|
+
|
|
47
|
+
const bridgeConfig = this.getBridgeConfig();
|
|
48
|
+
if (!bridgeConfig) return null;
|
|
49
|
+
|
|
50
|
+
const items = await this.loadItems(bridgeConfig);
|
|
51
|
+
if (!items) return null;
|
|
52
|
+
|
|
53
|
+
let resolved: RuntimeDescriptor | null = null;
|
|
54
|
+
for (const sourced of items) {
|
|
55
|
+
if (bridgeConfig.filter && !bridgeConfig.filter(sourced.item)) continue;
|
|
56
|
+
|
|
57
|
+
const descriptor = bridgeConfig.toDescriptor(sourced.item);
|
|
58
|
+
if (descriptor.id === id) {
|
|
59
|
+
resolved = this.withRuntimeSource(descriptor, sourced.source);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (resolved && options?.cache) {
|
|
64
|
+
const cacheLimit = options.maxCacheSize ?? 1000;
|
|
65
|
+
const descriptors = await this.fetchAll({ maxCacheSize: cacheLimit });
|
|
66
|
+
if (descriptors.length <= cacheLimit) options.cache.setDescriptors(descriptors);
|
|
67
|
+
}
|
|
68
|
+
return resolved;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async fetchAll(options?: RuntimeResolverFetchAllOptions): Promise<RuntimeDescriptor[]> {
|
|
72
|
+
const cached = options?.cache?.getDescriptors();
|
|
73
|
+
if (cached) return this.applyLimit(cached, options?.limit);
|
|
74
|
+
|
|
75
|
+
const bridgeConfig = this.getBridgeConfig();
|
|
76
|
+
if (!bridgeConfig) return [];
|
|
77
|
+
|
|
78
|
+
const items = await this.loadItems(bridgeConfig);
|
|
79
|
+
if (!items) return [];
|
|
80
|
+
|
|
81
|
+
const descriptorsById = new Map<string, RuntimeDescriptor>();
|
|
82
|
+
for (const sourced of items) {
|
|
83
|
+
if (bridgeConfig.filter && !bridgeConfig.filter(sourced.item)) continue;
|
|
84
|
+
const descriptor = bridgeConfig.toDescriptor(sourced.item);
|
|
85
|
+
descriptorsById.set(descriptor.id, this.withRuntimeSource(descriptor, sourced.source));
|
|
86
|
+
}
|
|
87
|
+
const descriptors = [...descriptorsById.values()];
|
|
88
|
+
const cacheLimit = options?.maxCacheSize ?? 1000;
|
|
89
|
+
if (options?.cache && descriptors.length <= cacheLimit) {
|
|
90
|
+
options.cache.setDescriptors(descriptors);
|
|
91
|
+
}
|
|
92
|
+
return this.applyLimit(descriptors, options?.limit);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private applyLimit(
|
|
96
|
+
descriptors: RuntimeDescriptor[],
|
|
97
|
+
limit: number | undefined
|
|
98
|
+
): RuntimeDescriptor[] {
|
|
99
|
+
if (!limit || limit < 1) return descriptors;
|
|
100
|
+
return descriptors.slice(0, limit);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private async loadItems(
|
|
104
|
+
_bridgeConfig: StorageKindBridgeConfig
|
|
105
|
+
): Promise<SourcedManifestItem[] | null> {
|
|
106
|
+
const manifestDescriptor = this.getManifestDescriptor();
|
|
107
|
+
if (!manifestDescriptor) return null;
|
|
108
|
+
|
|
109
|
+
const adapterIds = this.getOrderedAdapters(manifestDescriptor);
|
|
110
|
+
if (adapterIds.length === 0) return null;
|
|
111
|
+
|
|
112
|
+
const sourceData = await Promise.all(
|
|
113
|
+
adapterIds.map(async (adapterId) => ({
|
|
114
|
+
source: resolveSourceFromAdapter(adapterId),
|
|
115
|
+
data: await this.loadFromAdapter(manifestDescriptor, adapterId)
|
|
116
|
+
}))
|
|
117
|
+
);
|
|
118
|
+
const items = this.mergeSourcedItems(sourceData);
|
|
119
|
+
if (items.length === 0) return null;
|
|
120
|
+
|
|
121
|
+
return items;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private getManifestDescriptor(): ManifestDescriptor | null {
|
|
125
|
+
const runtime = this.context.runtime as {
|
|
126
|
+
hasKind(kind: string): boolean;
|
|
127
|
+
assets(kind: string): { descriptor(id: string): unknown };
|
|
128
|
+
};
|
|
129
|
+
if (!runtime.hasKind(this.manifestKind)) return null;
|
|
130
|
+
|
|
131
|
+
const descriptor = runtime.assets(this.manifestKind).descriptor(this.manifestId);
|
|
132
|
+
if (!descriptor || typeof descriptor !== 'object') return null;
|
|
133
|
+
return descriptor as ManifestDescriptor;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private getOrderedAdapters(descriptor: ManifestDescriptor): string[] {
|
|
137
|
+
return resolveAdapterOrderBySource(
|
|
138
|
+
Array.isArray(descriptor.allowedAdapters) ? descriptor.allowedAdapters : []
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private async loadFromAdapter(
|
|
143
|
+
descriptor: ManifestDescriptor,
|
|
144
|
+
adapterId: string
|
|
145
|
+
): Promise<unknown | null> {
|
|
146
|
+
try {
|
|
147
|
+
const patched = this.patchDescriptorForAdapter(descriptor, adapterId);
|
|
148
|
+
const manifest = new StorageManifest(patched as StorageManifestDescriptor, this.context);
|
|
149
|
+
return await manifest.load();
|
|
150
|
+
} catch {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
private patchDescriptorForAdapter(
|
|
156
|
+
descriptor: ManifestDescriptor,
|
|
157
|
+
adapterId: string
|
|
158
|
+
): ManifestDescriptor {
|
|
159
|
+
const source = resolveSourceFromAdapter(adapterId);
|
|
160
|
+
const allowedAdapters = [
|
|
161
|
+
adapterId,
|
|
162
|
+
...(descriptor.allowedAdapters ?? []).filter((id: string) => id !== adapterId)
|
|
163
|
+
];
|
|
164
|
+
const adapterConfig = { ...descriptor.adapterConfig };
|
|
165
|
+
if (adapterId === 'storage.json') {
|
|
166
|
+
const jsonConfig = adapterConfig['storage.json'];
|
|
167
|
+
if (!jsonConfig || typeof jsonConfig !== 'object') {
|
|
168
|
+
adapterConfig['storage.json'] = { filename: `${descriptor.namespace}.json` };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const scopePaths = descriptor.scopePaths ? { ...descriptor.scopePaths } : undefined;
|
|
172
|
+
if (source === 'project-file' && adapterId === 'storage.json') {
|
|
173
|
+
const nextScopePaths = scopePaths ?? {};
|
|
174
|
+
nextScopePaths.project = '{workspace}';
|
|
175
|
+
nextScopePaths.local = '{workspace}';
|
|
176
|
+
return {
|
|
177
|
+
...descriptor,
|
|
178
|
+
allowedAdapters,
|
|
179
|
+
defaultAdapter: adapterId,
|
|
180
|
+
scope: resolveScopeForSource(source, descriptor.scope),
|
|
181
|
+
scopePaths: nextScopePaths,
|
|
182
|
+
adapterConfig
|
|
183
|
+
} as ManifestDescriptor;
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
...descriptor,
|
|
187
|
+
allowedAdapters,
|
|
188
|
+
defaultAdapter: adapterId,
|
|
189
|
+
scope: source ? resolveScopeForSource(source, descriptor.scope) : descriptor.scope,
|
|
190
|
+
scopePaths,
|
|
191
|
+
adapterConfig
|
|
192
|
+
} as ManifestDescriptor;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
private mergeSourcedItems(
|
|
196
|
+
values: Array<{ source: ManifestDataSource | null; data: unknown | null }>
|
|
197
|
+
): SourcedManifestItem[] {
|
|
198
|
+
const byId = new Map<string, SourcedManifestItem>();
|
|
199
|
+
const loose: SourcedManifestItem[] = [];
|
|
200
|
+
|
|
201
|
+
for (const entry of values) {
|
|
202
|
+
if (entry.data === null || entry.data === undefined) continue;
|
|
203
|
+
for (const item of this.asItems(entry.data)) {
|
|
204
|
+
if (item && typeof item === 'object' && typeof (item as { id?: unknown }).id === 'string') {
|
|
205
|
+
const id = (item as { id: string }).id;
|
|
206
|
+
if (!byId.has(id)) byId.set(id, { item, source: entry.source });
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
loose.push({ item, source: entry.source });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return [...loose, ...byId.values()];
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private asItems(data: unknown): unknown[] {
|
|
217
|
+
if (!data) return [];
|
|
218
|
+
if (Array.isArray(data)) return data;
|
|
219
|
+
if (typeof data === 'object' && data !== null && data.constructor === Object) {
|
|
220
|
+
return Object.values(data);
|
|
221
|
+
}
|
|
222
|
+
return [data];
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
private withRuntimeSource(
|
|
226
|
+
descriptor: RuntimeDescriptor,
|
|
227
|
+
source: ManifestDataSource | null
|
|
228
|
+
): RuntimeDescriptor {
|
|
229
|
+
if (!source) return descriptor;
|
|
230
|
+
return Object.assign({}, descriptor, { runtimeSource: source }) as RuntimeDescriptor;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
private getBridgeConfig(): StorageKindBridgeConfig | null {
|
|
234
|
+
const runtime = this.context.runtime as {
|
|
235
|
+
hasKind(kind: string): boolean;
|
|
236
|
+
assets(kind: string): {
|
|
237
|
+
descriptor(id: string): StorageManifestDescriptor | undefined;
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
if (!runtime.hasKind(this.manifestKind)) return null;
|
|
242
|
+
|
|
243
|
+
const manifestDescriptor = runtime.assets(this.manifestKind).descriptor(this.manifestId) as
|
|
244
|
+
| StorageManifestDescriptor
|
|
245
|
+
| undefined;
|
|
246
|
+
|
|
247
|
+
if (!manifestDescriptor?.providesRuntimeKinds) return null;
|
|
248
|
+
|
|
249
|
+
return (
|
|
250
|
+
(manifestDescriptor.providesRuntimeKinds as Record<string, StorageKindBridgeConfig>)[
|
|
251
|
+
this.targetKind
|
|
252
|
+
] ?? null
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
}
|