primitive-admin 1.2.0-alpha.9 → 1.3.0-alpha.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/README.md +258 -186
- package/assets/skill/skills/primitive-platform/SKILL.md +93 -27
- package/dist/bin/primitive.js +15 -89
- package/dist/bin/primitive.js.map +1 -1
- package/dist/src/commands/admins.js +80 -17
- package/dist/src/commands/admins.js.map +1 -1
- package/dist/src/commands/agent-sessions.d.ts +129 -0
- package/dist/src/commands/agent-sessions.js +532 -20
- package/dist/src/commands/agent-sessions.js.map +1 -1
- package/dist/src/commands/analytics.js +207 -155
- package/dist/src/commands/analytics.js.map +1 -1
- package/dist/src/commands/apps-children.js +3 -0
- package/dist/src/commands/apps-children.js.map +1 -1
- package/dist/src/commands/apps-transitions.d.ts +39 -0
- package/dist/src/commands/apps-transitions.js +198 -0
- package/dist/src/commands/apps-transitions.js.map +1 -0
- package/dist/src/commands/apps.d.ts +17 -0
- package/dist/src/commands/apps.js +108 -3
- package/dist/src/commands/apps.js.map +1 -1
- package/dist/src/commands/auth-sessions.js +2 -0
- package/dist/src/commands/auth-sessions.js.map +1 -1
- package/dist/src/commands/auth.js +138 -44
- package/dist/src/commands/auth.js.map +1 -1
- package/dist/src/commands/blob-buckets.js +2 -0
- package/dist/src/commands/blob-buckets.js.map +1 -1
- package/dist/src/commands/collections.js +318 -256
- package/dist/src/commands/collections.js.map +1 -1
- package/dist/src/commands/comparisons.js +2 -0
- package/dist/src/commands/comparisons.js.map +1 -1
- package/dist/src/commands/config.d.ts +2 -2
- package/dist/src/commands/config.js +59 -33
- package/dist/src/commands/config.js.map +1 -1
- package/dist/src/commands/connections.js +2 -0
- package/dist/src/commands/connections.js.map +1 -1
- package/dist/src/commands/database-type-configs.js +5 -3
- package/dist/src/commands/database-type-configs.js.map +1 -1
- package/dist/src/commands/databases.js +6 -4
- package/dist/src/commands/databases.js.map +1 -1
- package/dist/src/commands/db3-types.d.ts +15 -0
- package/dist/src/commands/db3-types.js +159 -0
- package/dist/src/commands/db3-types.js.map +1 -0
- package/dist/src/commands/db3.d.ts +24 -0
- package/dist/src/commands/db3.js +1444 -0
- package/dist/src/commands/db3.js.map +1 -0
- package/dist/src/commands/documents.d.ts +110 -10
- package/dist/src/commands/documents.js +1012 -748
- package/dist/src/commands/documents.js.map +1 -1
- package/dist/src/commands/email-templates.js +74 -0
- package/dist/src/commands/email-templates.js.map +1 -1
- package/dist/src/commands/env.js +8 -4
- package/dist/src/commands/env.js.map +1 -1
- package/dist/src/commands/function-trigger-commands.d.ts +28 -0
- package/dist/src/commands/function-trigger-commands.js +341 -0
- package/dist/src/commands/function-trigger-commands.js.map +1 -0
- package/dist/src/commands/functions.js +376 -30
- package/dist/src/commands/functions.js.map +1 -1
- package/dist/src/commands/groups.js +168 -50
- package/dist/src/commands/groups.js.map +1 -1
- package/dist/src/commands/guides.js +7 -5
- package/dist/src/commands/guides.js.map +1 -1
- package/dist/src/commands/hosting.d.ts +8 -0
- package/dist/src/commands/hosting.js +346 -0
- package/dist/src/commands/hosting.js.map +1 -0
- package/dist/src/commands/init.js +129 -38
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/integrations.js +82 -53
- package/dist/src/commands/integrations.js.map +1 -1
- package/dist/src/commands/locks.d.ts +5 -3
- package/dist/src/commands/locks.js +19 -61
- package/dist/src/commands/locks.js.map +1 -1
- package/dist/src/commands/metadata-category-configs.d.ts +2 -2
- package/dist/src/commands/metadata-category-configs.js +4 -2
- package/dist/src/commands/metadata-category-configs.js.map +1 -1
- package/dist/src/commands/metadata.js +41 -0
- package/dist/src/commands/metadata.js.map +1 -1
- package/dist/src/commands/prompts.js +75 -52
- package/dist/src/commands/prompts.js.map +1 -1
- package/dist/src/commands/rate-counters.d.ts +19 -0
- package/dist/src/commands/rate-counters.js +104 -0
- package/dist/src/commands/rate-counters.js.map +1 -0
- package/dist/src/commands/rule-sets.d.ts +1 -1
- package/dist/src/commands/rule-sets.js +2 -1
- package/dist/src/commands/rule-sets.js.map +1 -1
- package/dist/src/commands/schemas.d.ts +15 -0
- package/dist/src/commands/schemas.js +122 -0
- package/dist/src/commands/schemas.js.map +1 -0
- package/dist/src/commands/scripts.d.ts +9 -17
- package/dist/src/commands/scripts.js +24 -479
- package/dist/src/commands/scripts.js.map +1 -1
- package/dist/src/commands/secrets.js +47 -3
- package/dist/src/commands/secrets.js.map +1 -1
- package/dist/src/commands/sessions.js +2 -0
- package/dist/src/commands/sessions.js.map +1 -1
- package/dist/src/commands/skill.js +2 -0
- package/dist/src/commands/skill.js.map +1 -1
- package/dist/src/commands/sync-schemas.d.ts +202 -0
- package/dist/src/commands/sync-schemas.js +629 -0
- package/dist/src/commands/sync-schemas.js.map +1 -0
- package/dist/src/commands/sync-user-properties.d.ts +118 -0
- package/dist/src/commands/sync-user-properties.js +276 -0
- package/dist/src/commands/sync-user-properties.js.map +1 -0
- package/dist/src/commands/sync.d.ts +518 -546
- package/dist/src/commands/sync.js +3010 -4877
- package/dist/src/commands/sync.js.map +1 -1
- package/dist/src/commands/tokens.js +5 -3
- package/dist/src/commands/tokens.js.map +1 -1
- package/dist/src/commands/transitions.d.ts +54 -0
- package/dist/src/commands/transitions.js +418 -0
- package/dist/src/commands/transitions.js.map +1 -0
- package/dist/src/commands/usage.d.ts +18 -0
- package/dist/src/commands/usage.js +343 -0
- package/dist/src/commands/usage.js.map +1 -0
- package/dist/src/commands/user-properties.d.ts +14 -0
- package/dist/src/commands/user-properties.js +79 -0
- package/dist/src/commands/user-properties.js.map +1 -0
- package/dist/src/commands/users.js +911 -18
- package/dist/src/commands/users.js.map +1 -1
- package/dist/src/commands/vars.js +2 -0
- package/dist/src/commands/vars.js.map +1 -1
- package/dist/src/commands/waitlist.js +39 -4
- package/dist/src/commands/waitlist.js.map +1 -1
- package/dist/src/commands/workflows.d.ts +5 -83
- package/dist/src/commands/workflows.js +57 -2282
- package/dist/src/commands/workflows.js.map +1 -1
- package/dist/src/lib/analytics-query.d.ts +58 -0
- package/dist/src/lib/analytics-query.js +134 -0
- package/dist/src/lib/analytics-query.js.map +1 -0
- package/dist/src/lib/api-client.d.ts +1818 -438
- package/dist/src/lib/api-client.js +965 -544
- package/dist/src/lib/api-client.js.map +1 -1
- package/dist/src/lib/app-settings-descriptor.d.ts +1 -1
- package/dist/src/lib/app-settings-descriptor.js +6 -0
- package/dist/src/lib/app-settings-descriptor.js.map +1 -1
- package/dist/src/lib/auth-fixtures.d.ts +44 -0
- package/dist/src/lib/auth-fixtures.js +61 -0
- package/dist/src/lib/auth-fixtures.js.map +1 -0
- package/dist/src/lib/auth-flow.d.ts +34 -1
- package/dist/src/lib/auth-flow.js +429 -13
- package/dist/src/lib/auth-flow.js.map +1 -1
- package/dist/src/lib/block-layout.d.ts +12 -23
- package/dist/src/lib/block-layout.js +26 -92
- package/dist/src/lib/block-layout.js.map +1 -1
- package/dist/src/lib/block-selector.d.ts +8 -14
- package/dist/src/lib/block-selector.js +8 -19
- package/dist/src/lib/block-selector.js.map +1 -1
- package/dist/src/lib/child-apps-local.d.ts +3 -1
- package/dist/src/lib/child-apps-local.js +9 -1
- package/dist/src/lib/child-apps-local.js.map +1 -1
- package/dist/src/lib/cli-manifest.d.ts +9 -0
- package/dist/src/lib/cli-manifest.js +10 -1
- package/dist/src/lib/cli-manifest.js.map +1 -1
- package/dist/src/lib/cli-version.d.ts +14 -0
- package/dist/src/lib/cli-version.js +38 -0
- package/dist/src/lib/cli-version.js.map +1 -0
- package/dist/src/lib/codegen-shared/prettierStable.d.ts +41 -0
- package/dist/src/lib/codegen-shared/prettierStable.js +146 -24
- package/dist/src/lib/codegen-shared/prettierStable.js.map +1 -1
- package/dist/src/lib/collection-export.d.ts +76 -15
- package/dist/src/lib/collection-export.js +116 -23
- package/dist/src/lib/collection-export.js.map +1 -1
- package/dist/src/lib/collection-principal.d.ts +22 -0
- package/dist/src/lib/collection-principal.js +35 -0
- package/dist/src/lib/collection-principal.js.map +1 -0
- package/dist/src/lib/command-groups.d.ts +30 -0
- package/dist/src/lib/command-groups.js +109 -0
- package/dist/src/lib/command-groups.js.map +1 -0
- package/dist/src/lib/command-status.d.ts +147 -0
- package/dist/src/lib/command-status.js +266 -0
- package/dist/src/lib/command-status.js.map +1 -0
- package/dist/src/lib/config-object-descriptor.d.ts +9 -22
- package/dist/src/lib/config-object-descriptor.js +107 -276
- package/dist/src/lib/config-object-descriptor.js.map +1 -1
- package/dist/src/lib/config-surface.d.ts +3 -7
- package/dist/src/lib/config-surface.js +9 -13
- package/dist/src/lib/config-surface.js.map +1 -1
- package/dist/src/lib/config-toml.d.ts +11 -2
- package/dist/src/lib/config-toml.js +25 -2
- package/dist/src/lib/config-toml.js.map +1 -1
- package/dist/src/lib/credentials-home.d.ts +7 -0
- package/dist/src/lib/credentials-home.js +45 -10
- package/dist/src/lib/credentials-home.js.map +1 -1
- package/dist/src/lib/credentials-lock.d.ts +14 -6
- package/dist/src/lib/credentials-lock.js +90 -10
- package/dist/src/lib/credentials-lock.js.map +1 -1
- package/dist/src/lib/credentials-store.d.ts +123 -70
- package/dist/src/lib/credentials-store.js +358 -113
- package/dist/src/lib/credentials-store.js.map +1 -1
- package/dist/src/lib/custodian.d.ts +8 -0
- package/dist/src/lib/custodian.js +18 -0
- package/dist/src/lib/custodian.js.map +1 -0
- package/dist/src/lib/data-input.d.ts +1 -1
- package/dist/src/lib/data-input.js +1 -1
- package/dist/src/lib/db-codegen/dbTsTypes.d.ts +1 -1
- package/dist/src/lib/db-codegen/dbTsTypes.js +3 -0
- package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -1
- package/dist/src/lib/db-codegen/dbTypeIR.d.ts +38 -1
- package/dist/src/lib/db-codegen/dbTypeIR.js +29 -7
- package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -1
- package/dist/src/lib/db-type-records.d.ts +106 -0
- package/dist/src/lib/db-type-records.js +224 -0
- package/dist/src/lib/db-type-records.js.map +1 -0
- package/dist/src/lib/db3-export.d.ts +287 -0
- package/dist/src/lib/db3-export.js +647 -0
- package/dist/src/lib/db3-export.js.map +1 -0
- package/dist/src/lib/db3-index-output.d.ts +116 -0
- package/dist/src/lib/db3-index-output.js +223 -0
- package/dist/src/lib/db3-index-output.js.map +1 -0
- package/dist/src/lib/db3-type-models.d.ts +134 -0
- package/dist/src/lib/db3-type-models.js +452 -0
- package/dist/src/lib/db3-type-models.js.map +1 -0
- package/dist/src/lib/deprecation.d.ts +2 -2
- package/dist/src/lib/deprecation.js +2 -2
- package/dist/src/lib/document-ingest-artifact.d.ts +13 -0
- package/dist/src/lib/document-ingest-artifact.js +36 -6
- package/dist/src/lib/document-ingest-artifact.js.map +1 -1
- package/dist/src/lib/document-ingest-format2.d.ts +36 -0
- package/dist/src/lib/document-ingest-format2.js +78 -0
- package/dist/src/lib/document-ingest-format2.js.map +1 -0
- package/dist/src/lib/document-ingest-input.d.ts +9 -0
- package/dist/src/lib/document-ingest-input.js +28 -1
- package/dist/src/lib/document-ingest-input.js.map +1 -1
- package/dist/src/lib/document-ingest.d.ts +11 -1
- package/dist/src/lib/document-ingest.js +16 -0
- package/dist/src/lib/document-ingest.js.map +1 -1
- package/dist/src/lib/document-schema-rows.d.ts +42 -0
- package/dist/src/lib/document-schema-rows.js +53 -0
- package/dist/src/lib/document-schema-rows.js.map +1 -0
- package/dist/src/lib/experimental-apis.d.ts +36 -0
- package/dist/src/lib/experimental-apis.js +46 -0
- package/dist/src/lib/experimental-apis.js.map +1 -0
- package/dist/src/lib/file-attachment.d.ts +24 -0
- package/dist/src/lib/file-attachment.js +31 -0
- package/dist/src/lib/file-attachment.js.map +1 -0
- package/dist/src/lib/function-authorize-check.d.ts +142 -0
- package/dist/src/lib/function-authorize-check.js +311 -0
- package/dist/src/lib/function-authorize-check.js.map +1 -0
- package/dist/src/lib/function-authorize-view.d.ts +27 -0
- package/dist/src/lib/function-authorize-view.js +88 -0
- package/dist/src/lib/function-authorize-view.js.map +1 -0
- package/dist/src/lib/function-bundle.d.ts +27 -5
- package/dist/src/lib/function-bundle.js +142 -7
- package/dist/src/lib/function-bundle.js.map +1 -1
- package/dist/src/lib/function-collect.d.ts +90 -12
- package/dist/src/lib/function-collect.js +482 -12
- package/dist/src/lib/function-collect.js.map +1 -1
- package/dist/src/lib/function-db-types.d.ts +65 -11
- package/dist/src/lib/function-db-types.js +297 -157
- package/dist/src/lib/function-db-types.js.map +1 -1
- package/dist/src/lib/function-document-types.d.ts +19 -7
- package/dist/src/lib/function-document-types.js +24 -12
- package/dist/src/lib/function-document-types.js.map +1 -1
- package/dist/src/lib/function-lint.d.ts +57 -0
- package/dist/src/lib/function-lint.js +234 -0
- package/dist/src/lib/function-lint.js.map +1 -0
- package/dist/src/lib/function-log-row.js +21 -2
- package/dist/src/lib/function-log-row.js.map +1 -1
- package/dist/src/lib/function-run.d.ts +13 -21
- package/dist/src/lib/function-run.js +14 -27
- package/dist/src/lib/function-run.js.map +1 -1
- package/dist/src/lib/function-schema-codegen.d.ts +86 -22
- package/dist/src/lib/function-schema-codegen.js +194 -88
- package/dist/src/lib/function-schema-codegen.js.map +1 -1
- package/dist/src/lib/function-schema-refs.d.ts +98 -0
- package/dist/src/lib/function-schema-refs.js +177 -0
- package/dist/src/lib/function-schema-refs.js.map +1 -0
- package/dist/src/lib/function-sync.d.ts +109 -6
- package/dist/src/lib/function-sync.js +179 -26
- package/dist/src/lib/function-sync.js.map +1 -1
- package/dist/src/lib/function-trigger-listing.d.ts +11 -6
- package/dist/src/lib/function-trigger-listing.js +32 -11
- package/dist/src/lib/function-trigger-listing.js.map +1 -1
- package/dist/src/lib/function-typecheck.d.ts +52 -0
- package/dist/src/lib/function-typecheck.js +174 -54
- package/dist/src/lib/function-typecheck.js.map +1 -1
- package/dist/src/lib/function-versions.d.ts +2 -0
- package/dist/src/lib/function-versions.js +1 -0
- package/dist/src/lib/function-versions.js.map +1 -1
- package/dist/src/lib/generated-build-flags.d.ts +13 -0
- package/dist/src/lib/generated-build-flags.js +14 -0
- package/dist/src/lib/generated-build-flags.js.map +1 -0
- package/dist/src/lib/generated-command-status.d.ts +6 -0
- package/dist/src/lib/generated-command-status.js +469 -0
- package/dist/src/lib/generated-command-status.js.map +1 -0
- package/dist/src/lib/generated-config-surfaces.d.ts +538 -141
- package/dist/src/lib/generated-config-surfaces.js +1772 -1854
- package/dist/src/lib/generated-config-surfaces.js.map +1 -1
- package/dist/src/lib/generated-sdk-types.d.ts +1 -1
- package/dist/src/lib/generated-sdk-types.js +1 -1
- package/dist/src/lib/generated-sdk-types.js.map +1 -1
- package/dist/src/lib/hosting-build.d.ts +97 -0
- package/dist/src/lib/hosting-build.js +204 -0
- package/dist/src/lib/hosting-build.js.map +1 -0
- package/dist/src/lib/hosting-client.d.ts +167 -0
- package/dist/src/lib/hosting-client.js +340 -0
- package/dist/src/lib/hosting-client.js.map +1 -0
- package/dist/src/lib/hosting-environments.d.ts +32 -0
- package/dist/src/lib/hosting-environments.js +74 -0
- package/dist/src/lib/hosting-environments.js.map +1 -0
- package/dist/src/lib/hosting-errors.d.ts +30 -0
- package/dist/src/lib/hosting-errors.js +43 -0
- package/dist/src/lib/hosting-errors.js.map +1 -0
- package/dist/src/lib/hosting-token.d.ts +46 -0
- package/dist/src/lib/hosting-token.js +60 -0
- package/dist/src/lib/hosting-token.js.map +1 -0
- package/dist/src/lib/hosting-wait.d.ts +42 -0
- package/dist/src/lib/hosting-wait.js +84 -0
- package/dist/src/lib/hosting-wait.js.map +1 -0
- package/dist/src/lib/hosting-wfp-upload.d.ts +86 -0
- package/dist/src/lib/hosting-wfp-upload.js +149 -0
- package/dist/src/lib/hosting-wfp-upload.js.map +1 -0
- package/dist/src/lib/init-assets.d.ts +2 -6
- package/dist/src/lib/init-assets.js +11 -27
- package/dist/src/lib/init-assets.js.map +1 -1
- package/dist/src/lib/init-ios-links.d.ts +11 -7
- package/dist/src/lib/init-ios-links.js +28 -22
- package/dist/src/lib/init-ios-links.js.map +1 -1
- package/dist/src/lib/init-login-note.d.ts +13 -0
- package/dist/src/lib/init-login-note.js +22 -0
- package/dist/src/lib/init-login-note.js.map +1 -0
- package/dist/src/lib/init-schema.d.ts +15 -0
- package/dist/src/lib/init-schema.js +54 -0
- package/dist/src/lib/init-schema.js.map +1 -1
- package/dist/src/lib/integration-test-request.d.ts +54 -0
- package/dist/src/lib/integration-test-request.js +207 -0
- package/dist/src/lib/integration-test-request.js.map +1 -0
- package/dist/src/lib/invoker-shared-enums.d.ts +35 -0
- package/dist/src/lib/invoker-shared-enums.js +98 -0
- package/dist/src/lib/invoker-shared-enums.js.map +1 -0
- package/dist/src/lib/json-value.d.ts +6 -0
- package/dist/src/lib/json-value.js +13 -0
- package/dist/src/lib/json-value.js.map +1 -0
- package/dist/src/lib/load-routes.d.ts +33 -0
- package/dist/src/lib/load-routes.js +35 -0
- package/dist/src/lib/load-routes.js.map +1 -0
- package/dist/src/lib/log-inspection.d.ts +23 -4
- package/dist/src/lib/log-inspection.js +14 -5
- package/dist/src/lib/log-inspection.js.map +1 -1
- package/dist/src/lib/login-exchange-check.d.ts +18 -0
- package/dist/src/lib/login-exchange-check.js +27 -0
- package/dist/src/lib/login-exchange-check.js.map +1 -0
- package/dist/src/lib/login-scope-lines.d.ts +17 -7
- package/dist/src/lib/login-scope-lines.js +33 -10
- package/dist/src/lib/login-scope-lines.js.map +1 -1
- package/dist/src/lib/metadata-report.d.ts +85 -0
- package/dist/src/lib/metadata-report.js +81 -0
- package/dist/src/lib/metadata-report.js.map +1 -0
- package/dist/src/lib/object-status-filter.d.ts +9 -1
- package/dist/src/lib/object-status-filter.js +9 -1
- package/dist/src/lib/object-status-filter.js.map +1 -1
- package/dist/src/lib/output.d.ts +1 -1
- package/dist/src/lib/output.js +3 -1
- package/dist/src/lib/output.js.map +1 -1
- package/dist/src/lib/pin-refusal-hint.d.ts +12 -0
- package/dist/src/lib/pin-refusal-hint.js +35 -0
- package/dist/src/lib/pin-refusal-hint.js.map +1 -0
- package/dist/src/lib/platform-owned.js +5 -0
- package/dist/src/lib/platform-owned.js.map +1 -1
- package/dist/src/lib/primitive-declaration-names.d.ts +21 -0
- package/dist/src/lib/primitive-declaration-names.js +22 -0
- package/dist/src/lib/primitive-declaration-names.js.map +1 -0
- package/dist/src/lib/primitive-declaration.d.ts +174 -0
- package/dist/src/lib/primitive-declaration.js +792 -0
- package/dist/src/lib/primitive-declaration.js.map +1 -0
- package/dist/src/lib/primitive-env-plugin.d.ts +99 -0
- package/dist/src/lib/primitive-env-plugin.js +408 -0
- package/dist/src/lib/primitive-env-plugin.js.map +1 -0
- package/dist/src/lib/project-login-apps.d.ts +8 -0
- package/dist/src/lib/project-login-apps.js +27 -0
- package/dist/src/lib/project-login-apps.js.map +1 -0
- package/dist/src/lib/prompt-schema-codegen.d.ts +36 -12
- package/dist/src/lib/prompt-schema-codegen.js +96 -100
- package/dist/src/lib/prompt-schema-codegen.js.map +1 -1
- package/dist/src/lib/prompt-schema-document.d.ts +35 -0
- package/dist/src/lib/prompt-schema-document.js +92 -0
- package/dist/src/lib/prompt-schema-document.js.map +1 -0
- package/dist/src/lib/prompt-schema-refs.d.ts +173 -0
- package/dist/src/lib/prompt-schema-refs.js +478 -0
- package/dist/src/lib/prompt-schema-refs.js.map +1 -0
- package/dist/src/lib/records-verbs.d.ts +79 -0
- package/dist/src/lib/records-verbs.js +45 -0
- package/dist/src/lib/records-verbs.js.map +1 -0
- package/dist/src/lib/register-commands.d.ts +36 -0
- package/dist/src/lib/register-commands.js +37 -0
- package/dist/src/lib/register-commands.js.map +1 -0
- package/dist/src/lib/retired-imports.d.ts +53 -0
- package/dist/src/lib/retired-imports.js +120 -0
- package/dist/src/lib/retired-imports.js.map +1 -0
- package/dist/src/lib/run-status.d.ts +1 -1
- package/dist/src/lib/run-status.generated.d.ts +2 -2
- package/dist/src/lib/run-status.generated.js +3 -1
- package/dist/src/lib/run-status.generated.js.map +1 -1
- package/dist/src/lib/run-status.js +1 -1
- package/dist/src/lib/schema-codegen/compiledSpace.d.ts +62 -0
- package/dist/src/lib/schema-codegen/compiledSpace.js +103 -0
- package/dist/src/lib/schema-codegen/compiledSpace.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-db3-bridge.d.ts +86 -0
- package/dist/src/lib/schema-codegen/generated-db3-bridge.js +227 -0
- package/dist/src/lib/schema-codegen/generated-db3-bridge.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.d.ts +85 -0
- package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js +86 -0
- package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-field-grammar.d.ts +218 -0
- package/dist/src/lib/schema-codegen/generated-field-grammar.js +397 -0
- package/dist/src/lib/schema-codegen/generated-field-grammar.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-field-table.d.ts +80 -0
- package/dist/src/lib/schema-codegen/generated-field-table.js +542 -0
- package/dist/src/lib/schema-codegen/generated-field-table.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-prompt-schemas.d.ts +195 -0
- package/dist/src/lib/schema-codegen/generated-prompt-schemas.js +503 -0
- package/dist/src/lib/schema-codegen/generated-prompt-schemas.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-schema-descriptor.d.ts +258 -0
- package/dist/src/lib/schema-codegen/generated-schema-descriptor.js +422 -0
- package/dist/src/lib/schema-codegen/generated-schema-descriptor.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-schema-file.d.ts +129 -0
- package/dist/src/lib/schema-codegen/generated-schema-file.js +475 -0
- package/dist/src/lib/schema-codegen/generated-schema-file.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-schema-provenance.d.ts +115 -0
- package/dist/src/lib/schema-codegen/generated-schema-provenance.js +274 -0
- package/dist/src/lib/schema-codegen/generated-schema-provenance.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-schema-refs.d.ts +366 -0
- package/dist/src/lib/schema-codegen/generated-schema-refs.js +1789 -0
- package/dist/src/lib/schema-codegen/generated-schema-refs.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-schema-shape.d.ts +27 -0
- package/dist/src/lib/schema-codegen/generated-schema-shape.js +126 -0
- package/dist/src/lib/schema-codegen/generated-schema-shape.js.map +1 -0
- package/dist/src/lib/schema-codegen/namedRefs.d.ts +56 -0
- package/dist/src/lib/schema-codegen/namedRefs.js +143 -0
- package/dist/src/lib/schema-codegen/namedRefs.js.map +1 -0
- package/dist/src/lib/schema-codegen/naming.d.ts +35 -0
- package/dist/src/lib/schema-codegen/naming.js +83 -0
- package/dist/src/lib/schema-codegen/naming.js.map +1 -0
- package/dist/src/lib/schema-codegen/schemaChanges.d.ts +74 -0
- package/dist/src/lib/schema-codegen/schemaChanges.js +277 -0
- package/dist/src/lib/schema-codegen/schemaChanges.js.map +1 -0
- package/dist/src/lib/schema-codegen/schemaDocs.d.ts +69 -0
- package/dist/src/lib/schema-codegen/schemaDocs.js +219 -0
- package/dist/src/lib/schema-codegen/schemaDocs.js.map +1 -0
- package/dist/src/lib/schema-codegen/schemaIR.d.ts +158 -0
- package/dist/src/lib/schema-codegen/schemaIR.js +279 -0
- package/dist/src/lib/schema-codegen/schemaIR.js.map +1 -0
- package/dist/src/lib/schema-codegen/schemaToTs.d.ts +109 -0
- package/dist/src/lib/schema-codegen/schemaToTs.js +269 -0
- package/dist/src/lib/schema-codegen/schemaToTs.js.map +1 -0
- package/dist/src/lib/schema-codegen/valuesLists.d.ts +48 -0
- package/dist/src/lib/schema-codegen/valuesLists.js +144 -0
- package/dist/src/lib/schema-codegen/valuesLists.js.map +1 -0
- package/dist/src/lib/schema-family-index.d.ts +228 -0
- package/dist/src/lib/schema-family-index.js +813 -0
- package/dist/src/lib/schema-family-index.js.map +1 -0
- package/dist/src/lib/schema-pins.d.ts +82 -0
- package/dist/src/lib/schema-pins.js +198 -0
- package/dist/src/lib/schema-pins.js.map +1 -0
- package/dist/src/lib/schema-preview.d.ts +244 -0
- package/dist/src/lib/schema-preview.js +498 -0
- package/dist/src/lib/schema-preview.js.map +1 -0
- package/dist/src/lib/scope-request.d.ts +23 -11
- package/dist/src/lib/scope-request.js +69 -31
- package/dist/src/lib/scope-request.js.map +1 -1
- package/dist/src/lib/session-scope.d.ts +26 -0
- package/dist/src/lib/session-scope.js +58 -0
- package/dist/src/lib/session-scope.js.map +1 -0
- package/dist/src/lib/skill-installer.d.ts +2 -2
- package/dist/src/lib/skill-installer.js +2 -21
- package/dist/src/lib/skill-installer.js.map +1 -1
- package/dist/src/lib/step-run-table.d.ts +1 -2
- package/dist/src/lib/step-run-table.js +1 -2
- package/dist/src/lib/step-run-table.js.map +1 -1
- package/dist/src/lib/swift-codegen/agentGenerator.d.ts +2 -1
- package/dist/src/lib/swift-codegen/agentGenerator.js +25 -23
- package/dist/src/lib/swift-codegen/agentGenerator.js.map +1 -1
- package/dist/src/lib/swift-codegen/banners.d.ts +12 -0
- package/dist/src/lib/swift-codegen/banners.js +12 -0
- package/dist/src/lib/swift-codegen/banners.js.map +1 -1
- package/dist/src/lib/swift-codegen/functionGenerator.d.ts +36 -1
- package/dist/src/lib/swift-codegen/functionGenerator.js +169 -51
- package/dist/src/lib/swift-codegen/functionGenerator.js.map +1 -1
- package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +33 -9
- package/dist/src/lib/swift-codegen/schemaToSwift.js +215 -179
- package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -1
- package/dist/src/lib/swift-codegen/sharedGenerator.d.ts +45 -0
- package/dist/src/lib/swift-codegen/sharedGenerator.js +165 -0
- package/dist/src/lib/swift-codegen/sharedGenerator.js.map +1 -0
- package/dist/src/lib/swift-codegen/swiftKeys.d.ts +19 -0
- package/dist/src/lib/swift-codegen/swiftKeys.js +31 -0
- package/dist/src/lib/swift-codegen/swiftKeys.js.map +1 -0
- package/dist/src/lib/swift-codegen/userPropertiesGenerator.d.ts +30 -0
- package/dist/src/lib/swift-codegen/userPropertiesGenerator.js +69 -0
- package/dist/src/lib/swift-codegen/userPropertiesGenerator.js.map +1 -0
- package/dist/src/lib/sync-resource-types.d.ts +117 -31
- package/dist/src/lib/sync-resource-types.js +197 -189
- package/dist/src/lib/sync-resource-types.js.map +1 -1
- package/dist/src/lib/sync-selectors.d.ts +7 -0
- package/dist/src/lib/sync-selectors.js +22 -2
- package/dist/src/lib/sync-selectors.js.map +1 -1
- package/dist/src/lib/template.d.ts +39 -3
- package/dist/src/lib/template.js +103 -14
- package/dist/src/lib/template.js.map +1 -1
- package/dist/src/lib/test-case-file-names.d.ts +3 -5
- package/dist/src/lib/test-case-file-names.js +3 -5
- package/dist/src/lib/test-case-file-names.js.map +1 -1
- package/dist/src/lib/test-runs.d.ts +45 -0
- package/dist/src/lib/test-runs.js +150 -0
- package/dist/src/lib/test-runs.js.map +1 -0
- package/dist/src/lib/test-users.d.ts +25 -0
- package/dist/src/lib/test-users.js +36 -0
- package/dist/src/lib/test-users.js.map +1 -0
- package/dist/src/lib/toml-database-config.d.ts +4 -2
- package/dist/src/lib/toml-database-config.js +11 -6
- package/dist/src/lib/toml-database-config.js.map +1 -1
- package/dist/src/lib/toml-scalar-edit.js +6 -4
- package/dist/src/lib/toml-scalar-edit.js.map +1 -1
- package/dist/src/lib/transition-warnings.d.ts +21 -0
- package/dist/src/lib/transition-warnings.js +49 -0
- package/dist/src/lib/transition-warnings.js.map +1 -0
- package/dist/src/lib/user-index.d.ts +80 -0
- package/dist/src/lib/user-index.js +166 -0
- package/dist/src/lib/user-index.js.map +1 -0
- package/dist/src/lib/user-properties/generated-properties-schema.d.ts +159 -0
- package/dist/src/lib/user-properties/generated-properties-schema.js +471 -0
- package/dist/src/lib/user-properties/generated-properties-schema.js.map +1 -0
- package/dist/src/lib/user-properties/user-properties-codegen.d.ts +55 -0
- package/dist/src/lib/user-properties/user-properties-codegen.js +129 -0
- package/dist/src/lib/user-properties/user-properties-codegen.js.map +1 -0
- package/dist/src/lib/user-walk.d.ts +31 -0
- package/dist/src/lib/user-walk.js +102 -0
- package/dist/src/lib/user-walk.js.map +1 -0
- package/dist/src/lib/webhook-capture.d.ts +43 -0
- package/dist/src/lib/webhook-capture.js +91 -0
- package/dist/src/lib/webhook-capture.js.map +1 -0
- package/dist/src/lib/webhook-deliver.d.ts +18 -20
- package/dist/src/lib/webhook-deliver.js +34 -89
- package/dist/src/lib/webhook-deliver.js.map +1 -1
- package/dist/src/lib/webhook-test-run.d.ts +32 -0
- package/dist/src/lib/webhook-test-run.js +108 -0
- package/dist/src/lib/webhook-test-run.js.map +1 -0
- package/dist/src/lib/worker-perf-format.d.ts +22 -0
- package/dist/src/lib/worker-perf-format.js +27 -0
- package/dist/src/lib/worker-perf-format.js.map +1 -0
- package/dist/src/types/index.d.ts +20 -65
- package/dist/src/validators.d.ts +7 -55
- package/dist/src/validators.js +7 -53
- package/dist/src/validators.js.map +1 -1
- package/dist/src/vite.d.ts +17 -0
- package/dist/src/vite.js +18 -0
- package/dist/src/vite.js.map +1 -0
- package/package.json +20 -9
|
@@ -0,0 +1,647 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `primitive db3 export` and `primitive db3 import` (#4889): a db3 written
|
|
3
|
+
* to a directory, and a directory loaded into a db3.
|
|
4
|
+
*
|
|
5
|
+
* An export is a directory holding `db3.json` (the manifest: the db3's id,
|
|
6
|
+
* title and tags, its type by name and revision, its declaration as
|
|
7
|
+
* `GET db3/:id/schema` answers it, the indexes registered through the index
|
|
8
|
+
* routes, the log number the rows are at), the rows under `snapshot/` and
|
|
9
|
+
* `chain.json` as `documents export` writes a record-log document's, and
|
|
10
|
+
* the blobs under `blobs/`. It carries no grant, custody, sync state or alias:
|
|
11
|
+
* those belong to the app the db3 lives in.
|
|
12
|
+
*
|
|
13
|
+
* An import does every check before any write: the manifest's type must be
|
|
14
|
+
* one the app has, with an equal declaration (or `--untyped`); a `--into`
|
|
15
|
+
* target must be of the manifest's type and declare its models alike; and
|
|
16
|
+
* blobs are imported under their ids, so the source db3 must be gone from the
|
|
17
|
+
* app first. Then it creates the db3 (or confirms `--into`), registers the
|
|
18
|
+
* indexes an untyped target needs before any row, loads the rows through the
|
|
19
|
+
* db3's bulk-load session and uploads the blobs.
|
|
20
|
+
*
|
|
21
|
+
* The planner (`planDb3Import`) and the comparison (`compareDeclarations`)
|
|
22
|
+
* are pure; the verbs in `../commands/db3.ts` read what they need and drive
|
|
23
|
+
* the steps.
|
|
24
|
+
*/
|
|
25
|
+
import fs from "fs";
|
|
26
|
+
import path from "path";
|
|
27
|
+
import { loadSchemaFromTomlString } from "js-bao";
|
|
28
|
+
import { db3IndexKindAndPlacement } from "./db3-index-output.js";
|
|
29
|
+
import { exportRecordLogDocument } from "./document-export-record-log.js";
|
|
30
|
+
import { discoverIngestInput } from "./document-ingest-input.js";
|
|
31
|
+
import { buildIngestArtifact, ingestSchemaFromIntrospection } from "./document-ingest-artifact.js";
|
|
32
|
+
import { driveDocumentIngest } from "./document-ingest.js";
|
|
33
|
+
/** The manifest file an export writes and an import reads. */
|
|
34
|
+
export const DB3_MANIFEST = "db3.json";
|
|
35
|
+
const isText = (registration) => registration.kind === "text";
|
|
36
|
+
/**
|
|
37
|
+
* The indexes an export records, out of the db3's index list: each one a
|
|
38
|
+
* registration keeps, with the registration's own uniqueness (a
|
|
39
|
+
* declaration's unique on the same index is the declaration's),
|
|
40
|
+
* `members: true` on a member index, its `kind` and `on` as the list
|
|
41
|
+
* gives them (#5220), and a text index's options (#5222).
|
|
42
|
+
*/
|
|
43
|
+
export function exportedIndexesOf(listed) {
|
|
44
|
+
return listed.flatMap((index) => {
|
|
45
|
+
const named = (index.origins ?? []).find((origin) => origin?.kind === "named");
|
|
46
|
+
if (!named)
|
|
47
|
+
return [];
|
|
48
|
+
const row = {
|
|
49
|
+
name: index.name,
|
|
50
|
+
model: index.model,
|
|
51
|
+
fields: [...index.fields],
|
|
52
|
+
unique: named.unique === true,
|
|
53
|
+
...(index.members === true ? { members: true } : {}),
|
|
54
|
+
...(typeof index.kind === "string" ? { kind: index.kind } : {}),
|
|
55
|
+
...(typeof index.on === "string" ? { on: index.on } : {}),
|
|
56
|
+
...(index.kind === "text" && index.text && typeof index.text === "object"
|
|
57
|
+
? {
|
|
58
|
+
text: {
|
|
59
|
+
tokenizer: index.text.tokenizer,
|
|
60
|
+
prefix: [...(index.text.prefix ?? [])],
|
|
61
|
+
weights: { ...(index.text.weights ?? {}) },
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
: {}),
|
|
65
|
+
};
|
|
66
|
+
return [row];
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/** `index`'s kind and placement as the export recorded them, for its registration. */
|
|
70
|
+
const placedOf = (index) => ({
|
|
71
|
+
...(index.kind !== undefined ? { kind: index.kind } : {}),
|
|
72
|
+
...(index.on !== undefined ? { on: index.on } : {}),
|
|
73
|
+
});
|
|
74
|
+
/** A model's declaration out of a schema answer's model: its fields and constraints, without `observed`. */
|
|
75
|
+
function modelDeclaration(model) {
|
|
76
|
+
const fields = {};
|
|
77
|
+
for (const [name, options] of Object.entries(model?.fields ?? {}))
|
|
78
|
+
fields[name] = { ...(options ?? {}) };
|
|
79
|
+
const constraints = {};
|
|
80
|
+
for (const [name, c] of Object.entries(model?.constraints ?? {})) {
|
|
81
|
+
if (c && Array.isArray(c.fields))
|
|
82
|
+
constraints[name] = { type: "unique", fields: [...c.fields] };
|
|
83
|
+
}
|
|
84
|
+
return { fields, ...(Object.keys(constraints).length ? { constraints } : {}) };
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The declaration `GET db3/:id/schema` answers. The answer gives a declared
|
|
88
|
+
* model with no fields and a live undeclared model alike, `{ fields: {} }`,
|
|
89
|
+
* so such a model is kept only when `declaredModels` names it: the models a
|
|
90
|
+
* typed db3's type declares ({@link declaredModelNames}). A type that
|
|
91
|
+
* declares no models holds any model undeclared, and an untyped db3
|
|
92
|
+
* declares none.
|
|
93
|
+
*/
|
|
94
|
+
export function declarationOfSchemaAnswer(answer, options = {}) {
|
|
95
|
+
const declaredModels = new Set(options.declaredModels ?? []);
|
|
96
|
+
const models = {};
|
|
97
|
+
for (const [name, model] of Object.entries(answer?.schema?.models ?? {})) {
|
|
98
|
+
const declaration = modelDeclaration(model);
|
|
99
|
+
const declared = declaredModels.has(name) && model && typeof model === "object" && "fields" in model;
|
|
100
|
+
if (declared || Object.keys(declaration.fields).length || declaration.constraints)
|
|
101
|
+
models[name] = declaration;
|
|
102
|
+
}
|
|
103
|
+
return { models };
|
|
104
|
+
}
|
|
105
|
+
/** The models a db3 type's schema TOML declares, by name. */
|
|
106
|
+
export function declaredModelNames(schema) {
|
|
107
|
+
return Object.keys(declarationOfTypeSchema(schema).models);
|
|
108
|
+
}
|
|
109
|
+
/** The declaration a db3 type's schema TOML installs (`GET db3-types/:name`'s `schema`). */
|
|
110
|
+
export function declarationOfTypeSchema(schema) {
|
|
111
|
+
if (typeof schema !== "string" || !schema.trim())
|
|
112
|
+
return { models: {} };
|
|
113
|
+
const defined = loadSchemaFromTomlString(schema, { strict: false, rejectUniqueStringset: false, vectors: true });
|
|
114
|
+
const models = {};
|
|
115
|
+
for (const model of defined) {
|
|
116
|
+
const fields = {};
|
|
117
|
+
for (const [field, options] of Object.entries(model.fields ?? {})) {
|
|
118
|
+
const kept = {};
|
|
119
|
+
for (const [key, value] of Object.entries(options ?? {})) {
|
|
120
|
+
if (value !== undefined && typeof value !== "function")
|
|
121
|
+
kept[key] = value;
|
|
122
|
+
}
|
|
123
|
+
fields[field] = kept;
|
|
124
|
+
}
|
|
125
|
+
const constraints = {};
|
|
126
|
+
for (const c of model.options?.uniqueConstraints ?? [])
|
|
127
|
+
constraints[c.name] = { type: "unique", fields: [...c.fields] };
|
|
128
|
+
models[model.name] = { fields, ...(Object.keys(constraints).length ? { constraints } : {}) };
|
|
129
|
+
}
|
|
130
|
+
return { models };
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* What a field's declaration is compared by: its kind and its two index
|
|
134
|
+
* flags, and a vector field's encoding too (#5225), which two encodings of
|
|
135
|
+
* the same byte length would otherwise hide.
|
|
136
|
+
*/
|
|
137
|
+
function fieldShape(options) {
|
|
138
|
+
return JSON.stringify({
|
|
139
|
+
type: options?.type ?? null,
|
|
140
|
+
indexed: options?.indexed === true,
|
|
141
|
+
unique: options?.unique === true,
|
|
142
|
+
...(options?.type === "vector" ? { dims: options.dims ?? null, element: options.element ?? null } : {}),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/** A field's declaration as a difference line names it: a vector field by its encoding (`2 × f32`), any other by its shape. */
|
|
146
|
+
function fieldText(options) {
|
|
147
|
+
if (options?.type !== "vector")
|
|
148
|
+
return fieldShape(options);
|
|
149
|
+
const flags = [options.indexed === true ? "indexed" : "", options.unique === true ? "unique" : ""].filter(Boolean);
|
|
150
|
+
return `a vector of ${String(options.dims)} × ${String(options.element)}${flags.length ? ` (${flags.join(", ")})` : ""}`;
|
|
151
|
+
}
|
|
152
|
+
/** A model's compound constraints, compared by their fields in any order. */
|
|
153
|
+
function constraintKeys(model) {
|
|
154
|
+
return Object.values(model?.constraints ?? {})
|
|
155
|
+
.map((c) => `unique(${[...c.fields].sort().join(", ")})`)
|
|
156
|
+
.sort();
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* The differences between the declaration an export holds and the one a
|
|
160
|
+
* type or a target installs, one line per model, field or constraint; none
|
|
161
|
+
* when they are equal. Order is ignored: of models, fields, constraints and
|
|
162
|
+
* a constraint's fields. A field compares by its kind and its `indexed` and
|
|
163
|
+
* `unique` flags. With `only: "installed"`, only the models `installed`
|
|
164
|
+
* declares are compared (an `--untyped` import into a target that already
|
|
165
|
+
* declares some of them).
|
|
166
|
+
*/
|
|
167
|
+
export function compareDeclarations(exported, installed, options = {}) {
|
|
168
|
+
const where = options.installedName ?? "the target";
|
|
169
|
+
const lines = [];
|
|
170
|
+
const models = new Set([...Object.keys(installed.models), ...(options.only === "installed" ? [] : Object.keys(exported.models))]);
|
|
171
|
+
for (const name of [...models].sort()) {
|
|
172
|
+
const mine = exported.models[name];
|
|
173
|
+
const theirs = installed.models[name];
|
|
174
|
+
if (!theirs) {
|
|
175
|
+
lines.push(`model ${name}: declared by the export, not by ${where}`);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (!mine) {
|
|
179
|
+
lines.push(`model ${name}: declared by ${where}, not by the export`);
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
const fields = new Set([...Object.keys(mine.fields), ...Object.keys(theirs.fields)]);
|
|
183
|
+
for (const field of [...fields].sort()) {
|
|
184
|
+
if (!(field in theirs.fields))
|
|
185
|
+
lines.push(`model ${name} field ${field}: declared by the export, not by ${where}`);
|
|
186
|
+
else if (!(field in mine.fields))
|
|
187
|
+
lines.push(`model ${name} field ${field}: declared by ${where}, not by the export`);
|
|
188
|
+
else if (fieldShape(mine.fields[field]) !== fieldShape(theirs.fields[field])) {
|
|
189
|
+
lines.push(`model ${name} field ${field}: the export has ${fieldText(mine.fields[field])}, ${where} has ${fieldText(theirs.fields[field])}`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const a = constraintKeys(mine);
|
|
193
|
+
const b = constraintKeys(theirs);
|
|
194
|
+
for (const key of a)
|
|
195
|
+
if (!b.includes(key))
|
|
196
|
+
lines.push(`model ${name} constraint ${key}: declared by the export, not by ${where}`);
|
|
197
|
+
for (const key of b)
|
|
198
|
+
if (!a.includes(key))
|
|
199
|
+
lines.push(`model ${name} constraint ${key}: declared by ${where}, not by the export`);
|
|
200
|
+
}
|
|
201
|
+
return lines;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* The index registrations that install `declaration`'s indexes and uniques,
|
|
205
|
+
* and `indexes`, on an untyped db3: one per model and set of fields, unique
|
|
206
|
+
* when either source holds it unique (a registration over the same fields
|
|
207
|
+
* replaces the earlier one's uniqueness, so a later non-unique one would
|
|
208
|
+
* lift it), each compound name a valid identifier no other of the model's
|
|
209
|
+
* registrations takes. A member index wins its field over a declaration's
|
|
210
|
+
* field index, as the room keeps the member row and builds no index for the
|
|
211
|
+
* declaration (#5150); so does an index placed `server` or `device` over a
|
|
212
|
+
* declaration's field index, for the same reason (#5220). A text index
|
|
213
|
+
* stands beside any other kind over the same fields (#5222): it is keyed
|
|
214
|
+
* apart, keeps its fields' order, and is registered with no name or unique.
|
|
215
|
+
* So does a `vector` index (#5225).
|
|
216
|
+
*/
|
|
217
|
+
export function registrationsFor(declaration, indexes = []) {
|
|
218
|
+
const out = [];
|
|
219
|
+
const byFields = new Map();
|
|
220
|
+
const names = new Map();
|
|
221
|
+
const add = (registration) => {
|
|
222
|
+
// A `text` or `vector` index stands beside another kind over the same
|
|
223
|
+
// fields (#5222, #5225), so its key names its kind; a scalar and a member
|
|
224
|
+
// index share one, a member index winning its field.
|
|
225
|
+
const kind = registrationPlacement(registration).kind;
|
|
226
|
+
const key = JSON.stringify([registration.model, [...fieldsOf(registration)].sort(), ...(kind === "text" || kind === "vector" ? [kind] : [])]);
|
|
227
|
+
const at = byFields.get(key);
|
|
228
|
+
if (at !== undefined) {
|
|
229
|
+
const held = out[at];
|
|
230
|
+
if ("members" in registration && !("members" in held)) {
|
|
231
|
+
out[at] = registration;
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const wanted = registrationPlacement(registration);
|
|
235
|
+
const holding = registrationPlacement(held);
|
|
236
|
+
if (registration.on !== undefined && wanted.kind === holding.kind && wanted.on !== holding.on) {
|
|
237
|
+
out[at] = registration;
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const uniqueWanted = "unique" in registration && registration.unique === true;
|
|
241
|
+
if (uniqueWanted && "field" in held && !("members" in held) && !isText(held) && held.unique !== true)
|
|
242
|
+
out[at] = { ...held, unique: true };
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
if ("name" in registration) {
|
|
246
|
+
const taken = names.get(registration.model) ?? new Set();
|
|
247
|
+
names.set(registration.model, taken);
|
|
248
|
+
// The physical name lower-cases the registration's, so two names a case apart would collide.
|
|
249
|
+
let name = registration.name;
|
|
250
|
+
for (let n = 2; taken.has(name.toLowerCase()); n++)
|
|
251
|
+
name = `${registration.name}_${n}`;
|
|
252
|
+
taken.add(name.toLowerCase());
|
|
253
|
+
registration = { ...registration, name };
|
|
254
|
+
}
|
|
255
|
+
byFields.set(key, out.length);
|
|
256
|
+
out.push(registration);
|
|
257
|
+
};
|
|
258
|
+
for (const model of Object.keys(declaration.models).sort()) {
|
|
259
|
+
const declared = declaration.models[model];
|
|
260
|
+
for (const field of Object.keys(declared.fields).sort()) {
|
|
261
|
+
const options = declared.fields[field];
|
|
262
|
+
// The primary key serves `id`, and a set field takes no index: the room refuses both.
|
|
263
|
+
if (field === "id" || options.type === "stringset")
|
|
264
|
+
continue;
|
|
265
|
+
if (options.unique === true)
|
|
266
|
+
add({ model, field, unique: true });
|
|
267
|
+
else if (options.indexed === true)
|
|
268
|
+
add({ model, field });
|
|
269
|
+
}
|
|
270
|
+
for (const name of Object.keys(declared.constraints ?? {}).sort()) {
|
|
271
|
+
const fields = declared.constraints[name].fields;
|
|
272
|
+
if (fields.length === 1 && fields[0] === "id")
|
|
273
|
+
continue;
|
|
274
|
+
if (fields.length === 1)
|
|
275
|
+
add({ model, field: fields[0], unique: true });
|
|
276
|
+
else
|
|
277
|
+
add({ model, fields: [...fields], name: registrationName(model, name), unique: true });
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
for (const index of indexes) {
|
|
281
|
+
const placed = placedOf(index);
|
|
282
|
+
if (index.kind === "text") {
|
|
283
|
+
const covered = index.fields.length === 1 ? { field: index.fields[0] } : { fields: [...index.fields] };
|
|
284
|
+
add({ model: index.model, ...covered, kind: "text", ...(index.on !== undefined ? { on: index.on } : {}), ...(index.text ? { text: index.text } : {}) });
|
|
285
|
+
}
|
|
286
|
+
else if (index.members === true)
|
|
287
|
+
add({ model: index.model, field: index.fields[0], members: true, ...placed });
|
|
288
|
+
else if (index.fields.length === 1) {
|
|
289
|
+
add(index.unique ? { model: index.model, field: index.fields[0], unique: true, ...placed } : { model: index.model, field: index.fields[0], ...placed });
|
|
290
|
+
}
|
|
291
|
+
else
|
|
292
|
+
add({ model: index.model, fields: [...index.fields], name: registrationName(index.model, index.name), unique: true, ...placed });
|
|
293
|
+
}
|
|
294
|
+
return out;
|
|
295
|
+
}
|
|
296
|
+
/** The physical name a registration named `name` on `model` gets (`idx_named_<model>_<name>`, lower-cased). */
|
|
297
|
+
const namedIndexPrefix = (model) => `idx_named_${model.toLowerCase()}_`;
|
|
298
|
+
/**
|
|
299
|
+
* The name to register an index under: the name it was registered with,
|
|
300
|
+
* read back out of the physical name the index list answers; a constraint's
|
|
301
|
+
* own name with the characters an index name cannot hold replaced, and
|
|
302
|
+
* `c_` before one that would not start with a letter or `_` (as the room
|
|
303
|
+
* names a constraint's own index).
|
|
304
|
+
*/
|
|
305
|
+
function registrationName(model, name) {
|
|
306
|
+
const prefix = namedIndexPrefix(model);
|
|
307
|
+
const bare = name.startsWith(prefix) && name.length > prefix.length ? name.slice(prefix.length) : name;
|
|
308
|
+
const replaced = bare.replace(/[^A-Za-z0-9_]/g, "_");
|
|
309
|
+
return /^[A-Za-z_]/.test(replaced) ? replaced : `c_${replaced}`;
|
|
310
|
+
}
|
|
311
|
+
const fieldsOf = (registration) => ("fields" in registration ? registration.fields : [registration.field]);
|
|
312
|
+
const sameFields = (a, b) => a.length === b.length && [...a].sort().join("\0") === [...b].sort().join("\0");
|
|
313
|
+
/** A registration's kind and placement, its defaults filled in as the room fills them. */
|
|
314
|
+
function registrationPlacement(registration) {
|
|
315
|
+
return db3IndexKindAndPlacement({ members: "members" in registration, kind: registration.kind, on: registration.on });
|
|
316
|
+
}
|
|
317
|
+
/** Whether two kinds may index the same fields side by side: a `text` or `vector` index beside another kind (#5220). */
|
|
318
|
+
const coexist = (a, b) => a !== b && (a === "text" || a === "vector" || b === "text" || b === "vector");
|
|
319
|
+
/**
|
|
320
|
+
* `register` against the indexes a target already has: a registration an
|
|
321
|
+
* index of its kind over the same fields already serves, as unique or more,
|
|
322
|
+
* is left out (so an existing unique index is never registered again
|
|
323
|
+
* without `unique`, which would lift it, and a constraint the target holds
|
|
324
|
+
* is not registered a second time under another name); a named
|
|
325
|
+
* registration whose name the target gives an index over other fields is a
|
|
326
|
+
* conflict. A member index is served only by a member index on its field,
|
|
327
|
+
* and a field index only by a field index: a target holding the other kind
|
|
328
|
+
* on the field is a conflict. So is a holder of the same kind placed
|
|
329
|
+
* elsewhere (#5220): a placement changes only by drop and register. A
|
|
330
|
+
* registration is pending beside a holder only when their kinds may index
|
|
331
|
+
* the same fields side by side.
|
|
332
|
+
*/
|
|
333
|
+
export function pendingRegistrations(register, existing) {
|
|
334
|
+
const out = [];
|
|
335
|
+
const kept = [];
|
|
336
|
+
const conflicts = [];
|
|
337
|
+
for (const registration of register) {
|
|
338
|
+
const fields = fieldsOf(registration);
|
|
339
|
+
// A model has one text index (#5222): the target's over other fields is a conflict.
|
|
340
|
+
const otherText = isText(registration)
|
|
341
|
+
? existing.find((index) => index.model === registration.model && index.kind === "text" && !sameFields(index.fields, fields))
|
|
342
|
+
: undefined;
|
|
343
|
+
if (otherText) {
|
|
344
|
+
conflicts.push(`${registration.model} (${fields.join(", ")}): the export's text index; the target's ${otherText.name} is over (${otherText.fields.join(", ")}), ` +
|
|
345
|
+
"and a model has one text index");
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
const wanted = "unique" in registration && registration.unique === true;
|
|
349
|
+
const placement = registrationPlacement(registration);
|
|
350
|
+
const holders = existing.filter((index) => index.model === registration.model && sameFields(index.fields, fields));
|
|
351
|
+
const clash = holders.find((index) => {
|
|
352
|
+
const kind = db3IndexKindAndPlacement(index).kind;
|
|
353
|
+
return kind !== placement.kind && !coexist(kind, placement.kind);
|
|
354
|
+
});
|
|
355
|
+
if (clash) {
|
|
356
|
+
const members = placement.kind === "members";
|
|
357
|
+
conflicts.push(`${registration.model} (${fields.join(", ")}): the export's is ${members ? "a set-element index" : "a field index"}, ` +
|
|
358
|
+
`the target's ${clash.name} ${clash.members === true ? "a set-element index" : "a field index"}`);
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
const holder = holders.find((index) => db3IndexKindAndPlacement(index).kind === placement.kind);
|
|
362
|
+
const held = holder ? db3IndexKindAndPlacement(holder) : null;
|
|
363
|
+
if (holder && held.on !== placement.on) {
|
|
364
|
+
conflicts.push(`${registration.model} (${fields.join(", ")}): the export's is placed ${placement.on}, the target's ${holder.name} ${held.on}; ` +
|
|
365
|
+
"a placement changes only by dropping the index and registering it again");
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
if (holder && (holder.unique || !wanted)) {
|
|
369
|
+
kept.push(`${registration.model} (${fields.join(", ")}): the target's ${holder.name} already ` +
|
|
370
|
+
`${holder.unique ? "enforces it as unique" : "indexes it"}; not registered again.`);
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
if ("name" in registration) {
|
|
374
|
+
const physical = `${namedIndexPrefix(registration.model)}${registration.name.toLowerCase()}`;
|
|
375
|
+
const taken = existing.find((index) => index.model === registration.model && index.name === physical && !sameFields(index.fields, fields));
|
|
376
|
+
if (taken) {
|
|
377
|
+
conflicts.push(`${registration.model} index ${registration.name}: the export's is over (${fields.join(", ")}), ` +
|
|
378
|
+
`the target's over (${taken.fields.join(", ")})`);
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
out.push(registration);
|
|
383
|
+
}
|
|
384
|
+
return { register: out, kept, conflicts };
|
|
385
|
+
}
|
|
386
|
+
/** The type name an import resolves: `--type`, else the manifest's; none under `--untyped` without one. */
|
|
387
|
+
export function resolvedTypeName(manifest, flags) {
|
|
388
|
+
return flags.type ?? manifest.type?.name ?? null;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Decide an import from what was read, before any write: a refusal naming
|
|
392
|
+
* what to do, or the steps.
|
|
393
|
+
*/
|
|
394
|
+
export function planDb3Import(manifest, flags, facts) {
|
|
395
|
+
const named = resolvedTypeName(manifest, flags);
|
|
396
|
+
const typeName = flags.untyped && !flags.into ? null : named;
|
|
397
|
+
const notes = [];
|
|
398
|
+
if (flags.keepId && flags.into) {
|
|
399
|
+
return {
|
|
400
|
+
ok: false,
|
|
401
|
+
refusal: "--keep-id creates a db3 under the export's id, and --into loads into one that exists: pass one of them. Nothing was written.",
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
if (flags.keepId && facts.sourceExists) {
|
|
405
|
+
return {
|
|
406
|
+
ok: false,
|
|
407
|
+
refusal: `This app already holds a db3 with the export's id ${manifest.id}. Delete it first, import into another app, ` +
|
|
408
|
+
"or import without --keep-id to create it under a new id. Nothing was written.",
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
if (named && !flags.untyped) {
|
|
412
|
+
if (!facts.type) {
|
|
413
|
+
return {
|
|
414
|
+
ok: false,
|
|
415
|
+
refusal: `This app has no db3 type ${JSON.stringify(named)}. Push it first (primitive db3-types push), ` +
|
|
416
|
+
"or import the rows into an untyped db3 with --untyped. Nothing was written.",
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
const exportedHash = manifest.type?.revision?.hash;
|
|
420
|
+
const currentHash = facts.type.revision?.hash;
|
|
421
|
+
if (exportedHash && currentHash && exportedHash !== currentHash) {
|
|
422
|
+
notes.push(`The export was taken at type revision ${exportedHash}; the app's ${named} is at ${currentHash}.`);
|
|
423
|
+
}
|
|
424
|
+
if (!flags.into) {
|
|
425
|
+
const lines = compareDeclarations(manifest.declaration, declarationOfTypeSchema(facts.type.schema), {
|
|
426
|
+
installedName: `type ${named}`,
|
|
427
|
+
});
|
|
428
|
+
if (lines.length) {
|
|
429
|
+
return {
|
|
430
|
+
ok: false,
|
|
431
|
+
refusal: `The export's declaration differs from type ${named}'s. Nothing was written; ` +
|
|
432
|
+
"re-run with --untyped to load the rows into an untyped db3.",
|
|
433
|
+
lines,
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
if (flags.into) {
|
|
439
|
+
const target = facts.target;
|
|
440
|
+
if (!target)
|
|
441
|
+
return { ok: false, refusal: `The target db3 ${flags.into} could not be read. Nothing was written.` };
|
|
442
|
+
if (!flags.untyped) {
|
|
443
|
+
const theirs = target.row?.type ?? null;
|
|
444
|
+
if (theirs !== (named ?? null)) {
|
|
445
|
+
return {
|
|
446
|
+
ok: false,
|
|
447
|
+
refusal: `The target db3 ${flags.into} is ${theirs ? `of type ${theirs}` : "untyped"}; the export is ` +
|
|
448
|
+
`${named ? `of type ${named}` : "untyped"}. Nothing was written.`,
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
const lines = compareDeclarations(manifest.declaration, target.declaration, {
|
|
453
|
+
...(flags.untyped ? { only: "installed" } : {}),
|
|
454
|
+
installedName: `db3 ${flags.into}`,
|
|
455
|
+
});
|
|
456
|
+
if (lines.length) {
|
|
457
|
+
return { ok: false, refusal: `The export's declaration differs from db3 ${flags.into}'s. Nothing was written.`, lines };
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
const blobs = !flags.noBlobs && facts.blobCount > 0;
|
|
461
|
+
if (blobs && facts.sourceExists) {
|
|
462
|
+
return {
|
|
463
|
+
ok: false,
|
|
464
|
+
refusal: `The export's db3 ${manifest.id} is still in this app, and its blobs would collide with theirs under their ids. ` +
|
|
465
|
+
"Delete it first, import into another app, or re-run with --no-blobs. Nothing was written.",
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
const untypedTarget = flags.into ? !(facts.target?.row?.type) : !typeName;
|
|
469
|
+
// A vector index needs its field declared `vector`, and only a type declares one over HTTP (#5225).
|
|
470
|
+
const vectorIndexes = untypedTarget
|
|
471
|
+
? (manifest.indexes ?? [])
|
|
472
|
+
.filter((index) => index.kind === "vector")
|
|
473
|
+
.map((index) => `${index.model}.${index.fields.join(", ")}: a vector index`)
|
|
474
|
+
.sort()
|
|
475
|
+
: [];
|
|
476
|
+
if (vectorIndexes.length) {
|
|
477
|
+
return {
|
|
478
|
+
ok: false,
|
|
479
|
+
refusal: `The export holds vector indexes, and ${flags.into ? `db3 ${flags.into}` : "the db3 this import would create"} is untyped: ` +
|
|
480
|
+
"a vector index covers a field a type declares vector. Import with --type <name>, a type declaring the model, " +
|
|
481
|
+
"or --into a db3 typed with the model. Nothing was written.",
|
|
482
|
+
lines: vectorIndexes,
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
let register = untypedTarget
|
|
486
|
+
? registrationsFor(manifest.declaration, manifest.indexes ?? [])
|
|
487
|
+
: registrationsFor({ models: {} }, manifest.indexes ?? []);
|
|
488
|
+
if (flags.into && facts.target?.indexes) {
|
|
489
|
+
const pending = pendingRegistrations(register, facts.target.indexes);
|
|
490
|
+
if (pending.conflicts.length) {
|
|
491
|
+
return {
|
|
492
|
+
ok: false,
|
|
493
|
+
refusal: `The export's indexes clash with db3 ${flags.into}'s by name. Nothing was written.`,
|
|
494
|
+
lines: pending.conflicts,
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
register = pending.register;
|
|
498
|
+
notes.push(...pending.kept);
|
|
499
|
+
}
|
|
500
|
+
return {
|
|
501
|
+
ok: true,
|
|
502
|
+
typeName,
|
|
503
|
+
...(flags.into
|
|
504
|
+
? { into: flags.into }
|
|
505
|
+
: {
|
|
506
|
+
create: {
|
|
507
|
+
title: flags.title ?? manifest.title ?? "Imported db3",
|
|
508
|
+
...(typeName ? { type: typeName } : {}),
|
|
509
|
+
tags: [...(manifest.tags ?? [])],
|
|
510
|
+
...(flags.keepId ? { id: manifest.id } : {}),
|
|
511
|
+
},
|
|
512
|
+
}),
|
|
513
|
+
register,
|
|
514
|
+
blobs,
|
|
515
|
+
notes,
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
/** Read `<dir>/db3.json`, or `null` when the directory has none. */
|
|
519
|
+
export function readDb3Manifest(dir) {
|
|
520
|
+
const file = path.join(dir, DB3_MANIFEST);
|
|
521
|
+
if (!fs.existsSync(file))
|
|
522
|
+
return null;
|
|
523
|
+
const manifest = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
524
|
+
if (manifest?.kind !== "db3-export")
|
|
525
|
+
throw new Error(`${file} is not a db3 export's manifest (kind ${JSON.stringify(manifest?.kind)}).`);
|
|
526
|
+
return manifest;
|
|
527
|
+
}
|
|
528
|
+
/** The blobs `<dir>/blobs/index.json` lists; none without one. */
|
|
529
|
+
export function readExportedBlobs(dir) {
|
|
530
|
+
const file = path.join(dir, "blobs", "index.json");
|
|
531
|
+
if (!fs.existsSync(file))
|
|
532
|
+
return [];
|
|
533
|
+
const listed = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
534
|
+
return Array.isArray(listed) ? listed : [];
|
|
535
|
+
}
|
|
536
|
+
/** Every blob of a db3, page by page. */
|
|
537
|
+
async function listAllDb3Blobs(client, appId, db3Id) {
|
|
538
|
+
const blobs = [];
|
|
539
|
+
const seen = new Set();
|
|
540
|
+
let cursor;
|
|
541
|
+
for (;;) {
|
|
542
|
+
const page = await client.listDb3Blobs(appId, db3Id, cursor ? { cursor } : undefined);
|
|
543
|
+
if (Array.isArray(page))
|
|
544
|
+
return [...blobs, ...page];
|
|
545
|
+
blobs.push(...(page?.items ?? page?.blobs ?? []));
|
|
546
|
+
if (!page?.hasMore)
|
|
547
|
+
return blobs;
|
|
548
|
+
cursor = page?.nextCursor || undefined;
|
|
549
|
+
if (!cursor || seen.has(cursor))
|
|
550
|
+
throw new Error(`db3 ${db3Id}: its blob list said more follow but gave no new cursor; nothing was exported.`);
|
|
551
|
+
seen.add(cursor);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Write db3 `db3Id` to `dir`: the rows (a segment export, as `documents
|
|
556
|
+
* export` writes a record-log document's), `chain.json`, the blobs unless
|
|
557
|
+
* `blobs` is false, and `db3.json` last, so a directory with a manifest is a
|
|
558
|
+
* finished export.
|
|
559
|
+
*/
|
|
560
|
+
export async function exportDb3(client, appId, db3Id, dir, options) {
|
|
561
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
562
|
+
fs.rmSync(path.join(dir, DB3_MANIFEST), { force: true });
|
|
563
|
+
const row = await client.getDb3(appId, db3Id);
|
|
564
|
+
const type = await client.getDb3Type(appId, db3Id);
|
|
565
|
+
const declaredModels = type?.type ? declaredModelNames((await client.getDb3TypeConfig(appId, String(type.type)))?.schema) : [];
|
|
566
|
+
const declaration = declarationOfSchemaAnswer(await client.getDb3Schema(appId, db3Id), { declaredModels });
|
|
567
|
+
const listed = await client.listDb3Indexes(appId, db3Id);
|
|
568
|
+
// The registered origin's own uniqueness: a declaration's unique on the same index is the declaration's.
|
|
569
|
+
const indexes = exportedIndexesOf(listed?.indexes ?? []);
|
|
570
|
+
const exported = await exportRecordLogDocument({
|
|
571
|
+
client: {
|
|
572
|
+
requestSegment: () => client.requestDb3Snapshot(appId, db3Id),
|
|
573
|
+
getSegment: (segmentId) => client.getDb3Snapshot(appId, db3Id, segmentId),
|
|
574
|
+
listSegments: () => client.listDb3Snapshots(appId, db3Id, { limit: 100 }),
|
|
575
|
+
exportChain: () => client.exportDb3Chain(appId, db3Id),
|
|
576
|
+
download: (artifactPath) => client.downloadDocumentArtifact(appId, artifactPath),
|
|
577
|
+
},
|
|
578
|
+
documentId: db3Id,
|
|
579
|
+
docDir: dir,
|
|
580
|
+
onProgress: options.onProgress,
|
|
581
|
+
});
|
|
582
|
+
let blobCount = 0;
|
|
583
|
+
fs.rmSync(path.join(dir, "blobs"), { recursive: true, force: true });
|
|
584
|
+
if (options.blobs) {
|
|
585
|
+
const blobs = await listAllDb3Blobs(client, appId, db3Id);
|
|
586
|
+
const blobsDir = path.join(dir, "blobs");
|
|
587
|
+
fs.mkdirSync(blobsDir, { recursive: true });
|
|
588
|
+
const index = blobs.map((b) => ({
|
|
589
|
+
blobId: b.blobId,
|
|
590
|
+
filename: b.filename,
|
|
591
|
+
contentType: b.contentType,
|
|
592
|
+
sha256: b.sha256,
|
|
593
|
+
numBytes: b.numBytes,
|
|
594
|
+
}));
|
|
595
|
+
fs.writeFileSync(path.join(blobsDir, "index.json"), JSON.stringify(index, null, 2));
|
|
596
|
+
for (const blob of index) {
|
|
597
|
+
fs.writeFileSync(path.join(blobsDir, `${blob.blobId}.bin`), await client.downloadDb3Blob(appId, db3Id, blob.blobId));
|
|
598
|
+
}
|
|
599
|
+
blobCount = index.length;
|
|
600
|
+
}
|
|
601
|
+
const manifest = {
|
|
602
|
+
kind: "db3-export",
|
|
603
|
+
version: 1,
|
|
604
|
+
id: row.id ?? db3Id,
|
|
605
|
+
title: row.title ?? null,
|
|
606
|
+
tags: Array.isArray(row.tags) ? row.tags : [],
|
|
607
|
+
type: type?.type ? { name: String(type.type), revision: type.revision ?? null } : null,
|
|
608
|
+
declaration,
|
|
609
|
+
indexes,
|
|
610
|
+
lsn: exported.lsn,
|
|
611
|
+
exportedAt: new Date().toISOString(),
|
|
612
|
+
};
|
|
613
|
+
fs.writeFileSync(path.join(dir, DB3_MANIFEST), JSON.stringify(manifest, null, 2));
|
|
614
|
+
return { manifest, dir, rows: exported.segment.rows, blobs: blobCount };
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Load an export's rows into `db3Id` through its bulk-load session (merge,
|
|
618
|
+
* the epoch reserved at open), waited to a terminal state. Answers the
|
|
619
|
+
* session's outcome, or `null` when the export holds no rows.
|
|
620
|
+
*/
|
|
621
|
+
export async function loadDb3Rows(client, appId, db3Id, dir, onProgress) {
|
|
622
|
+
const input = discoverIngestInput(dir, db3Id);
|
|
623
|
+
const schema = ingestSchemaFromIntrospection(await client.getDb3Schema(appId, db3Id));
|
|
624
|
+
const plan = await buildIngestArtifact({ input, schema, open: true });
|
|
625
|
+
try {
|
|
626
|
+
if (plan.rows === 0)
|
|
627
|
+
return null;
|
|
628
|
+
return await driveDocumentIngest({
|
|
629
|
+
client: {
|
|
630
|
+
createIngest: (id) => client.createDb3Ingest(appId, id, {}),
|
|
631
|
+
uploadIngestChunk: (id, sessionId, chunk) => client.uploadDb3IngestChunk(appId, id, sessionId, chunk),
|
|
632
|
+
commitIngest: (id, sessionId) => client.commitDb3Ingest(appId, id, sessionId),
|
|
633
|
+
abortIngest: (id, sessionId) => client.abortDb3Ingest(appId, id, sessionId),
|
|
634
|
+
getIngest: (id, sessionId) => client.getDb3Ingest(appId, id, sessionId),
|
|
635
|
+
},
|
|
636
|
+
documentId: db3Id,
|
|
637
|
+
plan,
|
|
638
|
+
wait: true,
|
|
639
|
+
timeoutMs: null,
|
|
640
|
+
onProgress,
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
finally {
|
|
644
|
+
await plan.cleanup().catch(() => undefined);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
//# sourceMappingURL=db3-export.js.map
|