primitive-admin 1.0.62 → 1.0.64
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 +132 -42
- package/assets/skill/skills/primitive-platform/SKILL.md +142 -661
- package/dist/bin/primitive.js +121 -41
- package/dist/bin/primitive.js.map +1 -1
- package/dist/src/commands/admins.js +37 -50
- package/dist/src/commands/admins.js.map +1 -1
- package/dist/src/commands/analytics.js +178 -9
- package/dist/src/commands/analytics.js.map +1 -1
- package/dist/src/commands/apps.js +17 -7
- package/dist/src/commands/apps.js.map +1 -1
- package/dist/src/commands/auth-sessions.d.ts +7 -0
- package/dist/src/commands/auth-sessions.js +144 -0
- package/dist/src/commands/auth-sessions.js.map +1 -0
- package/dist/src/commands/auth.js +76 -116
- package/dist/src/commands/auth.js.map +1 -1
- package/dist/src/commands/blob-buckets.js +2 -1
- package/dist/src/commands/blob-buckets.js.map +1 -1
- package/dist/src/commands/catalog.js +26 -10
- package/dist/src/commands/catalog.js.map +1 -1
- package/dist/src/commands/collection-type-configs.js +3 -10
- package/dist/src/commands/collection-type-configs.js.map +1 -1
- package/dist/src/commands/collections.js +736 -19
- package/dist/src/commands/collections.js.map +1 -1
- package/dist/src/commands/config.js +13 -27
- package/dist/src/commands/config.js.map +1 -1
- package/dist/src/commands/connections.js +8 -9
- package/dist/src/commands/connections.js.map +1 -1
- package/dist/src/commands/cron-triggers.js +2 -1
- package/dist/src/commands/cron-triggers.js.map +1 -1
- package/dist/src/commands/database-type-configs.js +5 -12
- package/dist/src/commands/database-type-configs.js.map +1 -1
- package/dist/src/commands/databases.js +59 -72
- package/dist/src/commands/databases.js.map +1 -1
- package/dist/src/commands/documents.d.ts +58 -0
- package/dist/src/commands/documents.js +1623 -95
- package/dist/src/commands/documents.js.map +1 -1
- package/dist/src/commands/email-templates.js +5 -4
- package/dist/src/commands/email-templates.js.map +1 -1
- package/dist/src/commands/env.d.ts +1 -1
- package/dist/src/commands/env.js +106 -44
- package/dist/src/commands/env.js.map +1 -1
- package/dist/src/commands/feature-flags.js +2 -1
- package/dist/src/commands/feature-flags.js.map +1 -1
- package/dist/src/commands/functions.d.ts +20 -0
- package/dist/src/commands/functions.js +1630 -0
- package/dist/src/commands/functions.js.map +1 -0
- package/dist/src/commands/group-type-configs.js +2 -1
- package/dist/src/commands/group-type-configs.js.map +1 -1
- package/dist/src/commands/groups.js +30 -17
- package/dist/src/commands/groups.js.map +1 -1
- package/dist/src/commands/guides.js +17 -11
- package/dist/src/commands/guides.js.map +1 -1
- package/dist/src/commands/init.d.ts +24 -12
- package/dist/src/commands/init.js +198 -110
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/integrations.js +65 -26
- package/dist/src/commands/integrations.js.map +1 -1
- package/dist/src/commands/locks.js +17 -2
- package/dist/src/commands/locks.js.map +1 -1
- package/dist/src/commands/metadata-category-configs.js +2 -1
- package/dist/src/commands/metadata-category-configs.js.map +1 -1
- package/dist/src/commands/metadata.js +8 -1
- package/dist/src/commands/metadata.js.map +1 -1
- package/dist/src/commands/prompts.js +106 -59
- package/dist/src/commands/prompts.js.map +1 -1
- package/dist/src/commands/rule-sets.js +3 -10
- package/dist/src/commands/rule-sets.js.map +1 -1
- package/dist/src/commands/scripts.d.ts +10 -0
- package/dist/src/commands/scripts.js +159 -25
- package/dist/src/commands/scripts.js.map +1 -1
- package/dist/src/commands/secrets.js +2 -1
- package/dist/src/commands/secrets.js.map +1 -1
- package/dist/src/commands/sessions.js +10 -9
- package/dist/src/commands/sessions.js.map +1 -1
- package/dist/src/commands/sync-app-settings.js +3 -5
- package/dist/src/commands/sync-app-settings.js.map +1 -1
- package/dist/src/commands/sync.d.ts +391 -44
- package/dist/src/commands/sync.js +2622 -534
- package/dist/src/commands/sync.js.map +1 -1
- package/dist/src/commands/tokens.js +2 -1
- package/dist/src/commands/tokens.js.map +1 -1
- package/dist/src/commands/users.js +19 -10
- package/dist/src/commands/users.js.map +1 -1
- package/dist/src/commands/vars.js +2 -1
- package/dist/src/commands/vars.js.map +1 -1
- package/dist/src/commands/waitlist.js +2 -1
- package/dist/src/commands/waitlist.js.map +1 -1
- package/dist/src/commands/webhooks.d.ts +29 -0
- package/dist/src/commands/webhooks.js +135 -64
- package/dist/src/commands/webhooks.js.map +1 -1
- package/dist/src/commands/workflows.d.ts +1 -29
- package/dist/src/commands/workflows.js +113 -179
- package/dist/src/commands/workflows.js.map +1 -1
- package/dist/src/lib/api-client.d.ts +628 -14
- package/dist/src/lib/api-client.js +776 -70
- 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 +9 -1
- package/dist/src/lib/app-settings-descriptor.js.map +1 -1
- package/dist/src/lib/block-selector.d.ts +58 -0
- package/dist/src/lib/block-selector.js +92 -0
- package/dist/src/lib/block-selector.js.map +1 -0
- package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.d.ts +24 -54
- package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js +31 -153
- package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js.map +1 -1
- package/dist/src/lib/collection-export.d.ts +184 -0
- package/dist/src/lib/collection-export.js +252 -0
- package/dist/src/lib/collection-export.js.map +1 -0
- package/dist/src/lib/config-json-field.d.ts +28 -0
- package/dist/src/lib/config-json-field.js +56 -0
- package/dist/src/lib/config-json-field.js.map +1 -0
- package/dist/src/lib/config-object-descriptor.js +88 -6
- package/dist/src/lib/config-object-descriptor.js.map +1 -1
- package/dist/src/lib/config-payload.d.ts +8 -1
- package/dist/src/lib/config-payload.js +49 -4
- package/dist/src/lib/config-payload.js.map +1 -1
- package/dist/src/lib/config-surface.d.ts +12 -1
- package/dist/src/lib/config-surface.js +71 -3
- package/dist/src/lib/config-surface.js.map +1 -1
- package/dist/src/lib/config.d.ts +31 -13
- package/dist/src/lib/config.js +34 -70
- package/dist/src/lib/config.js.map +1 -1
- package/dist/src/lib/credentials-store.d.ts +37 -22
- package/dist/src/lib/credentials-store.js +103 -97
- package/dist/src/lib/credentials-store.js.map +1 -1
- package/dist/src/lib/db-codegen/dbTypeIR.js +8 -0
- package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -1
- package/dist/src/lib/deprecation.d.ts +22 -0
- package/dist/src/lib/deprecation.js +43 -0
- package/dist/src/lib/deprecation.js.map +1 -0
- package/dist/src/lib/document-export-permissions.d.ts +30 -0
- package/dist/src/lib/document-export-permissions.js +54 -0
- package/dist/src/lib/document-export-permissions.js.map +1 -0
- package/dist/src/lib/document-ingest-artifact.d.ts +120 -0
- package/dist/src/lib/document-ingest-artifact.js +505 -0
- package/dist/src/lib/document-ingest-artifact.js.map +1 -0
- package/dist/src/lib/document-ingest-input.d.ts +51 -0
- package/dist/src/lib/document-ingest-input.js +132 -0
- package/dist/src/lib/document-ingest-input.js.map +1 -0
- package/dist/src/lib/document-ingest-rows.d.ts +137 -0
- package/dist/src/lib/document-ingest-rows.js +181 -0
- package/dist/src/lib/document-ingest-rows.js.map +1 -0
- package/dist/src/lib/document-ingest.d.ts +101 -0
- package/dist/src/lib/document-ingest.js +384 -0
- package/dist/src/lib/document-ingest.js.map +1 -0
- package/dist/src/lib/env-resolver-core.d.ts +128 -17
- package/dist/src/lib/env-resolver-core.js +204 -22
- package/dist/src/lib/env-resolver-core.js.map +1 -1
- package/dist/src/lib/env-resolver.d.ts +18 -3
- package/dist/src/lib/env-resolver.js +23 -3
- package/dist/src/lib/env-resolver.js.map +1 -1
- package/dist/src/lib/function-bundle.d.ts +147 -0
- package/dist/src/lib/function-bundle.js +341 -0
- package/dist/src/lib/function-bundle.js.map +1 -0
- package/dist/src/lib/function-collect.d.ts +123 -0
- package/dist/src/lib/function-collect.js +610 -0
- package/dist/src/lib/function-collect.js.map +1 -0
- package/dist/src/lib/function-db-types.d.ts +202 -0
- package/dist/src/lib/function-db-types.js +870 -0
- package/dist/src/lib/function-db-types.js.map +1 -0
- package/dist/src/lib/function-document-types.d.ts +144 -0
- package/dist/src/lib/function-document-types.js +370 -0
- package/dist/src/lib/function-document-types.js.map +1 -0
- package/dist/src/lib/function-grants-preflight.d.ts +64 -0
- package/dist/src/lib/function-grants-preflight.js +105 -0
- package/dist/src/lib/function-grants-preflight.js.map +1 -0
- package/dist/src/lib/function-log-lines.d.ts +76 -0
- package/dist/src/lib/function-log-lines.js +160 -0
- package/dist/src/lib/function-log-lines.js.map +1 -0
- package/dist/src/lib/function-log-row.d.ts +29 -0
- package/dist/src/lib/function-log-row.js +73 -0
- package/dist/src/lib/function-log-row.js.map +1 -0
- package/dist/src/lib/function-log-tail.d.ts +132 -0
- package/dist/src/lib/function-log-tail.js +262 -0
- package/dist/src/lib/function-log-tail.js.map +1 -0
- package/dist/src/lib/function-run.d.ts +289 -0
- package/dist/src/lib/function-run.js +389 -0
- package/dist/src/lib/function-run.js.map +1 -0
- package/dist/src/lib/function-schema-codegen.d.ts +143 -0
- package/dist/src/lib/function-schema-codegen.js +420 -0
- package/dist/src/lib/function-schema-codegen.js.map +1 -0
- package/dist/src/lib/function-sync.d.ts +459 -0
- package/dist/src/lib/function-sync.js +1258 -0
- package/dist/src/lib/function-sync.js.map +1 -0
- package/dist/src/lib/function-trigger-listing.d.ts +27 -0
- package/dist/src/lib/function-trigger-listing.js +70 -0
- package/dist/src/lib/function-trigger-listing.js.map +1 -0
- package/dist/src/lib/function-typecheck.d.ts +86 -0
- package/dist/src/lib/function-typecheck.js +370 -0
- package/dist/src/lib/function-typecheck.js.map +1 -0
- package/dist/src/lib/function-versions.d.ts +122 -0
- package/dist/src/lib/function-versions.js +182 -0
- package/dist/src/lib/function-versions.js.map +1 -0
- package/dist/src/lib/generated-allowlist.js +4 -0
- package/dist/src/lib/generated-allowlist.js.map +1 -1
- package/dist/src/lib/generated-config-surfaces.d.ts +2332 -78
- package/dist/src/lib/generated-config-surfaces.js +6979 -468
- package/dist/src/lib/generated-config-surfaces.js.map +1 -1
- package/dist/src/lib/generated-sdk-types.d.ts +12 -0
- package/dist/src/lib/generated-sdk-types.js +13 -0
- package/dist/src/lib/generated-sdk-types.js.map +1 -0
- package/dist/src/lib/init-adopt.js +2 -2
- package/dist/src/lib/init-adopt.js.map +1 -1
- package/dist/src/lib/init-assets.js +3 -3
- package/dist/src/lib/init-client-platforms.d.ts +14 -0
- package/dist/src/lib/init-client-platforms.js +71 -0
- package/dist/src/lib/init-client-platforms.js.map +1 -0
- package/dist/src/lib/init-config.d.ts +1 -1
- package/dist/src/lib/init-email-redirect-uris.d.ts +37 -0
- package/dist/src/lib/init-email-redirect-uris.js +46 -0
- package/dist/src/lib/init-email-redirect-uris.js.map +1 -0
- package/dist/src/lib/init-ios-links.d.ts +41 -0
- package/dist/src/lib/init-ios-links.js +67 -1
- package/dist/src/lib/init-ios-links.js.map +1 -1
- package/dist/src/lib/init-plan.d.ts +1 -1
- package/dist/src/lib/init-plan.js +1 -1
- package/dist/src/lib/init-xcode.d.ts +6 -5
- package/dist/src/lib/init-xcode.js +34 -10
- package/dist/src/lib/init-xcode.js.map +1 -1
- package/dist/src/lib/integration-selector.d.ts +42 -0
- package/dist/src/lib/integration-selector.js +46 -0
- package/dist/src/lib/integration-selector.js.map +1 -0
- package/dist/src/lib/ios-app-id.d.ts +34 -0
- package/dist/src/lib/ios-app-id.js +69 -0
- package/dist/src/lib/ios-app-id.js.map +1 -0
- package/dist/src/lib/list-options.d.ts +68 -0
- package/dist/src/lib/list-options.js +89 -0
- package/dist/src/lib/list-options.js.map +1 -0
- package/dist/src/lib/local-state.d.ts +1 -1
- package/dist/src/lib/local-state.js +1 -1
- package/dist/src/lib/local-test-cases.d.ts +63 -0
- package/dist/src/lib/local-test-cases.js +136 -0
- package/dist/src/lib/local-test-cases.js.map +1 -0
- package/dist/src/lib/log-inspection.d.ts +152 -5
- package/dist/src/lib/log-inspection.js +179 -2
- package/dist/src/lib/log-inspection.js.map +1 -1
- package/dist/src/lib/logout-admin-session.d.ts +33 -0
- package/dist/src/lib/logout-admin-session.js +70 -0
- package/dist/src/lib/logout-admin-session.js.map +1 -0
- package/dist/src/lib/output.d.ts +15 -0
- package/dist/src/lib/output.js +28 -0
- package/dist/src/lib/output.js.map +1 -1
- package/dist/src/lib/paginate.d.ts +15 -0
- package/dist/src/lib/paginate.js +17 -0
- package/dist/src/lib/paginate.js.map +1 -1
- package/dist/src/lib/project-config.d.ts +46 -21
- package/dist/src/lib/project-config.js +74 -47
- package/dist/src/lib/project-config.js.map +1 -1
- package/dist/src/lib/prompt-cost-format.d.ts +11 -0
- package/dist/src/lib/prompt-cost-format.js +41 -0
- package/dist/src/lib/prompt-cost-format.js.map +1 -0
- package/dist/src/lib/prompt-schema-codegen.d.ts +147 -0
- package/dist/src/lib/prompt-schema-codegen.js +462 -0
- package/dist/src/lib/prompt-schema-codegen.js.map +1 -0
- package/dist/src/lib/refresh-admin-credentials.d.ts +9 -1
- package/dist/src/lib/refresh-admin-credentials.js +22 -2
- package/dist/src/lib/refresh-admin-credentials.js.map +1 -1
- package/dist/src/lib/resolve-owner.d.ts +19 -0
- package/dist/src/lib/resolve-owner.js +20 -0
- package/dist/src/lib/resolve-owner.js.map +1 -0
- package/dist/src/lib/skill-installer.d.ts +49 -3
- package/dist/src/lib/skill-installer.js +275 -100
- package/dist/src/lib/skill-installer.js.map +1 -1
- package/dist/src/lib/snapshot-audit-source.d.ts +45 -0
- package/dist/src/lib/snapshot-audit-source.js +58 -0
- package/dist/src/lib/snapshot-audit-source.js.map +1 -0
- package/dist/src/lib/snapshot-audit-store.d.ts +52 -0
- package/dist/src/lib/snapshot-audit-store.js +196 -0
- package/dist/src/lib/snapshot-audit-store.js.map +1 -0
- package/dist/src/lib/snapshot-audit.d.ts +207 -0
- package/dist/src/lib/snapshot-audit.js +431 -0
- package/dist/src/lib/snapshot-audit.js.map +1 -0
- package/dist/src/lib/snapshot-build-rows.d.ts +60 -0
- package/dist/src/lib/snapshot-build-rows.js +87 -0
- package/dist/src/lib/snapshot-build-rows.js.map +1 -0
- package/dist/src/lib/snapshot-build.d.ts +50 -0
- package/dist/src/lib/snapshot-build.js +111 -0
- package/dist/src/lib/snapshot-build.js.map +1 -0
- package/dist/src/lib/snapshot-manifest-layout.d.ts +61 -0
- package/dist/src/lib/snapshot-manifest-layout.js +70 -0
- package/dist/src/lib/snapshot-manifest-layout.js.map +1 -0
- package/dist/src/lib/snapshots.d.ts +8 -9
- package/dist/src/lib/snapshots.js +20 -83
- package/dist/src/lib/snapshots.js.map +1 -1
- package/dist/src/lib/step-run-table.d.ts +43 -0
- package/dist/src/lib/step-run-table.js +129 -0
- package/dist/src/lib/step-run-table.js.map +1 -0
- package/dist/src/lib/storage-pending-retry.d.ts +26 -0
- package/dist/src/lib/storage-pending-retry.js +42 -0
- package/dist/src/lib/storage-pending-retry.js.map +1 -0
- package/dist/src/lib/swift-codegen/agentGenerator.d.ts +42 -0
- package/dist/src/lib/swift-codegen/agentGenerator.js +118 -0
- package/dist/src/lib/swift-codegen/agentGenerator.js.map +1 -0
- package/dist/src/lib/swift-codegen/banners.d.ts +24 -0
- package/dist/src/lib/swift-codegen/banners.js +25 -0
- package/dist/src/lib/swift-codegen/banners.js.map +1 -0
- package/dist/src/lib/swift-codegen/dbGenerator.js +19 -7
- package/dist/src/lib/swift-codegen/dbGenerator.js.map +1 -1
- package/dist/src/lib/swift-codegen/functionGenerator.d.ts +139 -0
- package/dist/src/lib/swift-codegen/functionGenerator.js +462 -0
- package/dist/src/lib/swift-codegen/functionGenerator.js.map +1 -0
- package/dist/src/lib/swift-codegen/generator.d.ts +7 -1
- package/dist/src/lib/swift-codegen/generator.js +28 -11
- package/dist/src/lib/swift-codegen/generator.js.map +1 -1
- package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +15 -0
- package/dist/src/lib/swift-codegen/schemaToSwift.js +21 -4
- package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -1
- package/dist/src/lib/sync-paths.d.ts +72 -55
- package/dist/src/lib/sync-paths.js +97 -100
- package/dist/src/lib/sync-paths.js.map +1 -1
- package/dist/src/lib/sync-resource-types.d.ts +23 -4
- package/dist/src/lib/sync-resource-types.js +106 -8
- package/dist/src/lib/sync-resource-types.js.map +1 -1
- package/dist/src/lib/sync-selectors.d.ts +45 -2
- package/dist/src/lib/sync-selectors.js +66 -5
- package/dist/src/lib/sync-selectors.js.map +1 -1
- package/dist/src/lib/template.d.ts +2 -2
- package/dist/src/lib/template.js +2 -2
- package/dist/src/lib/test-case-file-names.d.ts +40 -0
- package/dist/src/lib/test-case-file-names.js +91 -0
- package/dist/src/lib/test-case-file-names.js.map +1 -0
- package/dist/src/lib/test-case-keys.d.ts +1 -1
- package/dist/src/lib/test-case-keys.js +1 -1
- package/dist/src/lib/test-case-variables.d.ts +14 -0
- package/dist/src/lib/test-case-variables.js +42 -0
- package/dist/src/lib/test-case-variables.js.map +1 -1
- package/dist/src/lib/toml-database-config.js +19 -2
- package/dist/src/lib/toml-database-config.js.map +1 -1
- package/dist/src/lib/web-url.d.ts +40 -0
- package/dist/src/lib/web-url.js +76 -0
- package/dist/src/lib/web-url.js.map +1 -0
- package/dist/src/lib/webhook-deliver.d.ts +209 -0
- package/dist/src/lib/webhook-deliver.js +519 -0
- package/dist/src/lib/webhook-deliver.js.map +1 -0
- package/dist/src/lib/workflow-codegen/generator.d.ts +1 -1
- package/dist/src/lib/workflow-codegen/generator.js +1 -1
- package/dist/src/lib/workflow-toml-validator.d.ts +17 -8
- package/dist/src/lib/workflow-toml-validator.js +25 -12
- package/dist/src/lib/workflow-toml-validator.js.map +1 -1
- package/dist/src/lib/workflow-usage.d.ts +196 -0
- package/dist/src/lib/workflow-usage.js +310 -0
- package/dist/src/lib/workflow-usage.js.map +1 -0
- package/dist/src/types/index.d.ts +12 -2
- package/package.json +5 -4
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve the identifier the `prompts tests` and `workflows tests` verbs take
|
|
3
|
+
* (issue #3249).
|
|
4
|
+
*
|
|
5
|
+
* The block-testing endpoints key on the composite `<type>#<blockId>` and
|
|
6
|
+
* never check that the block exists, so an identifier that names no prompt or
|
|
7
|
+
* workflow came back as an empty page rather than a 404: `tests list <key>`
|
|
8
|
+
* printed "No test cases found." and exited 0, and a checked-in
|
|
9
|
+
* `prompts/<key>.tests/` sidecar looked unregistered until the id was tried.
|
|
10
|
+
* The key is what an author has to hand — `prompts list` prints it beside the
|
|
11
|
+
* id, and the config tree, `config push` and the test sidecars are all
|
|
12
|
+
* key-addressed — so a wrong identifier was indistinguishable from a block
|
|
13
|
+
* with no cases.
|
|
14
|
+
*
|
|
15
|
+
* Resolving here — against the app's own list — is what makes an empty
|
|
16
|
+
* listing mean "this block exists and has no cases", the same answer #3000
|
|
17
|
+
* gave the integration verbs (`integration-selector.ts`). The list is the one
|
|
18
|
+
* call that can answer both halves: it maps a key to its id and it proves the
|
|
19
|
+
* identifier belongs to THIS app. It is drained across every page, because
|
|
20
|
+
* the server pages prompts at 50 and workflows at 25 by default. Archived
|
|
21
|
+
* blocks are included, because their cases stay inspectable.
|
|
22
|
+
*
|
|
23
|
+
* Keys are matched exactly first. The server does not lowercase prompt or
|
|
24
|
+
* workflow keys on write, so a case-insensitive match is a fallback that
|
|
25
|
+
* resolves only when it is unambiguous — two keys differing only in case are
|
|
26
|
+
* refused by name rather than picked between (the `resolveScript` rule in
|
|
27
|
+
* `scripts.ts`).
|
|
28
|
+
*/
|
|
29
|
+
import { paginateAll } from "./paginate.js";
|
|
30
|
+
const PROMPT_KIND = {
|
|
31
|
+
noun: "prompt",
|
|
32
|
+
idField: "promptId",
|
|
33
|
+
keyField: "promptKey",
|
|
34
|
+
listCommand: "primitive prompts list",
|
|
35
|
+
};
|
|
36
|
+
const WORKFLOW_KIND = {
|
|
37
|
+
noun: "workflow",
|
|
38
|
+
idField: "workflowId",
|
|
39
|
+
keyField: "workflowKey",
|
|
40
|
+
listCommand: "primitive workflows list",
|
|
41
|
+
};
|
|
42
|
+
/** The largest page the list endpoints accept (#1316), so a drain is few calls. */
|
|
43
|
+
const PAGE_LIMIT = 100;
|
|
44
|
+
/**
|
|
45
|
+
* Map a prompt ID or key to its prompt ID.
|
|
46
|
+
*
|
|
47
|
+
* Throws — naming the identifier — when nothing in the app matches, so the
|
|
48
|
+
* caller's existing catch prints the message and exits non-zero.
|
|
49
|
+
*/
|
|
50
|
+
export function resolvePromptSelector(client, appId, selector) {
|
|
51
|
+
return resolveBlockSelector(PROMPT_KIND, (params) => client.listPrompts(appId, params), appId, selector);
|
|
52
|
+
}
|
|
53
|
+
/** The same resolution for a workflow ID or key. */
|
|
54
|
+
export function resolveWorkflowSelector(client, appId, selector) {
|
|
55
|
+
return resolveBlockSelector(WORKFLOW_KIND, (params) => client.listWorkflows(appId, params), appId, selector);
|
|
56
|
+
}
|
|
57
|
+
async function resolveBlockSelector(kind, list, appId, selector) {
|
|
58
|
+
const identifier = (selector ?? "").trim();
|
|
59
|
+
if (!identifier) {
|
|
60
|
+
throw new Error(`A ${kind.noun} ID or key is required.`);
|
|
61
|
+
}
|
|
62
|
+
const items = await paginateAll((cursor) => list(cursor ? { cursor, limit: PAGE_LIMIT } : { limit: PAGE_LIMIT }));
|
|
63
|
+
const keyOf = (item) => typeof item?.[kind.keyField] === "string" ? item[kind.keyField] : undefined;
|
|
64
|
+
let match = items.find((item) => item?.[kind.idField] === identifier) ??
|
|
65
|
+
items.find((item) => keyOf(item) === identifier);
|
|
66
|
+
if (!match) {
|
|
67
|
+
const lowered = identifier.toLowerCase();
|
|
68
|
+
const ci = items.filter((item) => keyOf(item)?.toLowerCase() === lowered);
|
|
69
|
+
if (ci.length > 1) {
|
|
70
|
+
const candidates = ci
|
|
71
|
+
.map((item) => keyOf(item))
|
|
72
|
+
.sort()
|
|
73
|
+
.join(", ");
|
|
74
|
+
throw new Error(`${capitalize(kind.noun)} key is ambiguous: ${identifier}. Did you mean: ${candidates}? ` +
|
|
75
|
+
`Keys differing only in case must be given exactly, or by ID.`);
|
|
76
|
+
}
|
|
77
|
+
match = ci[0];
|
|
78
|
+
}
|
|
79
|
+
if (!match) {
|
|
80
|
+
throw new Error(`No ${kind.noun} '${identifier}' in app ${appId}. ` +
|
|
81
|
+
`Pass a ${kind.noun} key or ID from '${kind.listCommand}'.`);
|
|
82
|
+
}
|
|
83
|
+
const blockKey = keyOf(match);
|
|
84
|
+
return {
|
|
85
|
+
blockId: match[kind.idField] ?? identifier,
|
|
86
|
+
...(blockKey ? { blockKey } : {}),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function capitalize(word) {
|
|
90
|
+
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=block-selector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-selector.js","sourceRoot":"","sources":["../../../src/lib/block-selector.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,68 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared source-directory resolution for the CLI codegen commands
|
|
3
|
-
* (`workflows codegen` #1442
|
|
3
|
+
* (`workflows codegen` #1442, `databases codegen` #814, `databases schema
|
|
4
|
+
* generate` #666, issue #1510).
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
-
* (`workflows
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* run.
|
|
6
|
+
* Each of them reads a set of `*.toml` schemas out of one synced sub-directory
|
|
7
|
+
* (`workflows/`, `database-type-configs/`) and renders `*.generated.ts` beside
|
|
8
|
+
* them. It used to take four branches to say which directory that was: a
|
|
9
|
+
* `--dir` override, the resolved environment, an `--app`-alone fallback, and —
|
|
10
|
+
* when none of those answered — a SCAN of every `primitive/<env>/<subdir>` that resolved
|
|
11
|
+
* if exactly one environment happened to have the directory. The scan is how
|
|
12
|
+
* `PRIMITIVE_ENV=dev workflows codegen` could generate from the `alpha` TOML,
|
|
13
|
+
* and how two codegen commands in one run could read two different
|
|
14
|
+
* environments.
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* collection, type filtering/dedup, and output-dir defaulting stay in each
|
|
21
|
-
* command.
|
|
16
|
+
* There is one branch now (#3154, intent criterion 4): the sub-directory of
|
|
17
|
+
* the environment's own tree. `resolveSyncDir()` refuses rather than guesses,
|
|
18
|
+
* so an ambiguous project, an unknown `--env` and no project at all each reach
|
|
19
|
+
* the user as themselves.
|
|
22
20
|
*
|
|
23
|
-
* Design notes
|
|
24
|
-
* - Call `getCurrentEnvironment()` DIRECTLY when no `--dir` override is given.
|
|
25
|
-
* `resolveSyncDir()`'s internal `safeEnv()` swallows the resolver's
|
|
26
|
-
* ambiguity error and falls back to `./config`, so genuine ambiguity must
|
|
27
|
-
* be surfaced here, not through `resolveSyncDir()`.
|
|
21
|
+
* Design notes that survive:
|
|
28
22
|
* - Throw plain `Error`s; the calling commands keep their existing
|
|
29
|
-
* `error(); process.exit(1)` convention (they catch at the boundary).
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* -
|
|
33
|
-
*
|
|
34
|
-
* is no project config / legacy bare-dir mode), scan
|
|
35
|
-
* `.primitive/sync/<env>/<app>/<subdir>` for that specific app, resolving
|
|
36
|
-
* when it appears under exactly one env and erroring (naming the candidate
|
|
37
|
-
* envs) when it appears under more than one. This keeps the existing
|
|
38
|
-
* integration contract
|
|
39
|
-
* (`cli/tests/integration/workflows-codegen.test.ts`) intact.
|
|
40
|
-
* - Do NOT fall through to that scan when an environment WAS explicitly named
|
|
41
|
-
* (`--env` or `PRIMITIVE_ENV`) but is invalid/unknown: surface the
|
|
42
|
-
* resolver's error instead, so an explicit env selection never silently
|
|
43
|
-
* generates code from a different synced environment.
|
|
23
|
+
* `error(); process.exit(1)` convention (they catch at the boundary). A
|
|
24
|
+
* `PrimitiveEnvError` from the resolver is an Error too, and its message is
|
|
25
|
+
* already the one the user needs.
|
|
26
|
+
* - Do NOT use `resolveAppId()` — it is auth-oriented, and codegen is
|
|
27
|
+
* offline.
|
|
44
28
|
*/
|
|
45
|
-
export interface ResolveCodegenSourceDirOptions {
|
|
46
|
-
/** `--app <app-id>` override, if the user passed it. */
|
|
47
|
-
app?: string;
|
|
48
|
-
/** The resolved sync-directory override (`--dir <path>`), if the user passed it. */
|
|
49
|
-
syncDir?: string;
|
|
50
|
-
}
|
|
51
29
|
export interface ResolveCodegenSourceDirArgs {
|
|
52
30
|
/** The synced sub-directory to resolve, e.g. "workflows" or "database-type-configs". */
|
|
53
31
|
subdir: string;
|
|
54
|
-
/** Parsed command options (`--app`, plus the resolved `--dir` override). */
|
|
55
|
-
options: ResolveCodegenSourceDirOptions;
|
|
56
|
-
/**
|
|
57
|
-
* Working directory the legacy scan is rooted at. Defaults to
|
|
58
|
-
* `process.cwd()`; parameterised so unit tests can point it at a tmp tree
|
|
59
|
-
* (vitest workers can't `chdir`).
|
|
60
|
-
*/
|
|
61
|
-
cwd?: string;
|
|
62
32
|
}
|
|
63
33
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
34
|
+
* The single source directory a codegen command reads its `*.toml` schemas
|
|
35
|
+
* from. Throws with a user-facing message when the environment cannot be
|
|
36
|
+
* resolved or the directory is not there.
|
|
67
37
|
*/
|
|
68
38
|
export declare function resolveCodegenSourceDir(args: ResolveCodegenSourceDirArgs): string;
|
|
@@ -1,168 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared source-directory resolution for the CLI codegen commands
|
|
3
|
-
* (`workflows codegen` #1442
|
|
3
|
+
* (`workflows codegen` #1442, `databases codegen` #814, `databases schema
|
|
4
|
+
* generate` #666, issue #1510).
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
-
* (`workflows
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* run.
|
|
6
|
+
* Each of them reads a set of `*.toml` schemas out of one synced sub-directory
|
|
7
|
+
* (`workflows/`, `database-type-configs/`) and renders `*.generated.ts` beside
|
|
8
|
+
* them. It used to take four branches to say which directory that was: a
|
|
9
|
+
* `--dir` override, the resolved environment, an `--app`-alone fallback, and —
|
|
10
|
+
* when none of those answered — a SCAN of every `primitive/<env>/<subdir>` that resolved
|
|
11
|
+
* if exactly one environment happened to have the directory. The scan is how
|
|
12
|
+
* `PRIMITIVE_ENV=dev workflows codegen` could generate from the `alpha` TOML,
|
|
13
|
+
* and how two codegen commands in one run could read two different
|
|
14
|
+
* environments.
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* collection, type filtering/dedup, and output-dir defaulting stay in each
|
|
21
|
-
* command.
|
|
16
|
+
* There is one branch now (#3154, intent criterion 4): the sub-directory of
|
|
17
|
+
* the environment's own tree. `resolveSyncDir()` refuses rather than guesses,
|
|
18
|
+
* so an ambiguous project, an unknown `--env` and no project at all each reach
|
|
19
|
+
* the user as themselves.
|
|
22
20
|
*
|
|
23
|
-
* Design notes
|
|
24
|
-
* - Call `getCurrentEnvironment()` DIRECTLY when no `--dir` override is given.
|
|
25
|
-
* `resolveSyncDir()`'s internal `safeEnv()` swallows the resolver's
|
|
26
|
-
* ambiguity error and falls back to `./config`, so genuine ambiguity must
|
|
27
|
-
* be surfaced here, not through `resolveSyncDir()`.
|
|
21
|
+
* Design notes that survive:
|
|
28
22
|
* - Throw plain `Error`s; the calling commands keep their existing
|
|
29
|
-
* `error(); process.exit(1)` convention (they catch at the boundary).
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* -
|
|
33
|
-
*
|
|
34
|
-
* is no project config / legacy bare-dir mode), scan
|
|
35
|
-
* `.primitive/sync/<env>/<app>/<subdir>` for that specific app, resolving
|
|
36
|
-
* when it appears under exactly one env and erroring (naming the candidate
|
|
37
|
-
* envs) when it appears under more than one. This keeps the existing
|
|
38
|
-
* integration contract
|
|
39
|
-
* (`cli/tests/integration/workflows-codegen.test.ts`) intact.
|
|
40
|
-
* - Do NOT fall through to that scan when an environment WAS explicitly named
|
|
41
|
-
* (`--env` or `PRIMITIVE_ENV`) but is invalid/unknown: surface the
|
|
42
|
-
* resolver's error instead, so an explicit env selection never silently
|
|
43
|
-
* generates code from a different synced environment.
|
|
23
|
+
* `error(); process.exit(1)` convention (they catch at the boundary). A
|
|
24
|
+
* `PrimitiveEnvError` from the resolver is an Error too, and its message is
|
|
25
|
+
* already the one the user needs.
|
|
26
|
+
* - Do NOT use `resolveAppId()` — it is auth-oriented, and codegen is
|
|
27
|
+
* offline.
|
|
44
28
|
*/
|
|
45
|
-
import { existsSync
|
|
46
|
-
import {
|
|
47
|
-
import {
|
|
48
|
-
import { getCurrentAppId } from "../config.js";
|
|
49
|
-
import { resolveSyncDir, assertSafePathComponent } from "../sync-paths.js";
|
|
29
|
+
import { existsSync } from "fs";
|
|
30
|
+
import { join } from "path";
|
|
31
|
+
import { resolveSyncDir } from "../sync-paths.js";
|
|
50
32
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
33
|
+
* The single source directory a codegen command reads its `*.toml` schemas
|
|
34
|
+
* from. Throws with a user-facing message when the environment cannot be
|
|
35
|
+
* resolved or the directory is not there.
|
|
54
36
|
*/
|
|
55
37
|
export function resolveCodegenSourceDir(args) {
|
|
56
|
-
const { subdir
|
|
57
|
-
const
|
|
58
|
-
// 1. --dir is an explicit override: use <dir>/<subdir> verbatim.
|
|
59
|
-
if (options.syncDir) {
|
|
60
|
-
return requireExisting(join(options.syncDir, subdir), subdir, undefined);
|
|
61
|
-
}
|
|
62
|
-
// 2. Resolve the active environment. Call getCurrentEnvironment() directly
|
|
63
|
-
// (not via resolveSyncDir/safeEnv) so a genuinely ambiguous project
|
|
64
|
-
// surfaces the resolver's "No environment selected… Available: …" error
|
|
65
|
-
// with a non-zero exit — unless the caller narrowed the target with
|
|
66
|
-
// --app AND did not name an environment, in which case we fall back to the
|
|
67
|
-
// legacy per-app scan.
|
|
68
|
-
//
|
|
69
|
-
// The `--app`-alone fallback only applies when NO environment was
|
|
70
|
-
// explicitly requested (neither `--env` nor `PRIMITIVE_ENV`). When the
|
|
71
|
-
// user DID name an env but it's invalid/unknown, getCurrentEnvironment()
|
|
72
|
-
// throws; we must surface that error (non-zero exit) rather than silently
|
|
73
|
-
// scanning the app under some OTHER synced environment — that would
|
|
74
|
-
// generate code from the wrong env instead of honoring the explicit
|
|
75
|
-
// selection.
|
|
76
|
-
const explicitEnvRequested = getExplicitEnvName() !== null || !!process.env.PRIMITIVE_ENV;
|
|
77
|
-
let env;
|
|
78
|
-
try {
|
|
79
|
-
env = getCurrentEnvironment();
|
|
80
|
-
}
|
|
81
|
-
catch (err) {
|
|
82
|
-
if (options.app && !explicitEnvRequested) {
|
|
83
|
-
return scanSyncTree({ subdir, appId: options.app, cwd });
|
|
84
|
-
}
|
|
85
|
-
throw err;
|
|
86
|
-
}
|
|
87
|
-
// 3. Project mode: resolve the app id and build the env/app-scoped path.
|
|
88
|
-
if (env) {
|
|
89
|
-
const appId = options.app ?? env.config.appId ?? getCurrentAppId();
|
|
90
|
-
if (!appId) {
|
|
91
|
-
throw new Error(`No app configured for environment "${env.name}" in .primitive/config.json ` +
|
|
92
|
-
`and no --app given. Add "appId" to the environment or pass --app <app-id>.`);
|
|
93
|
-
}
|
|
94
|
-
// resolveSyncDir re-reads the (cached) resolved env and guards appId via
|
|
95
|
-
// assertSafePathComponent, so an unsafe --app is rejected here.
|
|
96
|
-
const dir = join(resolveSyncDir({ appId }), subdir);
|
|
97
|
-
return requireExisting(dir, subdir, appId);
|
|
98
|
-
}
|
|
99
|
-
// 4. Legacy / bare-dir mode (no .primitive/config.json): scan the sync tree,
|
|
100
|
-
// filtered to --app when given. This preserves the pre-#1510 behavior.
|
|
101
|
-
return scanSyncTree({ subdir, appId: options.app, cwd });
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Legacy fallback: scan `<cwd>/.primitive/sync/<env>/<app>/<subdir>` for a
|
|
105
|
-
* source directory. When `appId` is given, only that app's slots are
|
|
106
|
-
* considered. Resolves to the single match; errors clearly on zero or on
|
|
107
|
-
* ambiguity (naming the candidate apps or envs).
|
|
108
|
-
*/
|
|
109
|
-
function scanSyncTree(args) {
|
|
110
|
-
const { subdir, appId, cwd } = args;
|
|
111
|
-
// Defence-in-depth: an --app value flows into a file-system path below, so
|
|
112
|
-
// reject separators / `..` before using it.
|
|
113
|
-
if (appId)
|
|
114
|
-
assertSafePathComponent(appId, "appId");
|
|
115
|
-
const root = join(cwd, ".primitive", "sync");
|
|
116
|
-
const found = [];
|
|
117
|
-
if (existsSync(root)) {
|
|
118
|
-
for (const envName of readdirSync(root)) {
|
|
119
|
-
const envDir = join(root, envName);
|
|
120
|
-
try {
|
|
121
|
-
for (const app of readdirSync(envDir)) {
|
|
122
|
-
if (appId && app !== appId)
|
|
123
|
-
continue;
|
|
124
|
-
const candidate = join(envDir, app, subdir);
|
|
125
|
-
if (existsSync(candidate))
|
|
126
|
-
found.push(candidate);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
catch {
|
|
130
|
-
// Not a directory (or unreadable) — skip.
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
if (found.length === 0) {
|
|
135
|
-
throw new Error(notFoundMessage(subdir, appId));
|
|
136
|
-
}
|
|
137
|
-
if (found.length > 1) {
|
|
138
|
-
if (appId) {
|
|
139
|
-
const envs = [
|
|
140
|
-
...new Set(found.map((d) => basename(dirname(dirname(d))))),
|
|
141
|
-
];
|
|
142
|
-
throw new Error(`App "${appId}" has a ${subdir}/ directory under multiple environments: ` +
|
|
143
|
-
`${envs.join(", ")}.\n` +
|
|
144
|
-
found.map((d) => ` ${d}`).join("\n") +
|
|
145
|
-
`\nPass --env <name> or --dir to select one.`);
|
|
146
|
-
}
|
|
147
|
-
const apps = [...new Set(found.map((d) => basename(dirname(d))))];
|
|
148
|
-
throw new Error(`Found ${subdir}/ directories for more than one app/env:\n` +
|
|
149
|
-
found.map((d) => ` ${d}`).join("\n") +
|
|
150
|
-
`\nCodegen writes into one output dir, so it must run against one app. ` +
|
|
151
|
-
`Pass --app <app-id> (found: ${apps.join(", ")}) or --dir to select one.`);
|
|
152
|
-
}
|
|
153
|
-
return found[0];
|
|
154
|
-
}
|
|
155
|
-
/** Verifies `dir` exists, throwing the standard "no source dir" error otherwise. */
|
|
156
|
-
function requireExisting(dir, subdir, appId) {
|
|
38
|
+
const { subdir } = args;
|
|
39
|
+
const dir = join(resolveSyncDir(), subdir);
|
|
157
40
|
if (!existsSync(dir)) {
|
|
158
|
-
throw new Error(
|
|
41
|
+
throw new Error(`No ${subdir}/ directory in ${dir}. Run \`primitive config pull\` first, ` +
|
|
42
|
+
`or select another environment with --env <name>.`);
|
|
159
43
|
}
|
|
160
44
|
return dir;
|
|
161
45
|
}
|
|
162
|
-
function notFoundMessage(subdir, appId) {
|
|
163
|
-
return appId
|
|
164
|
-
? `No ${subdir}/ directory found for app "${appId}" under .primitive/sync/. ` +
|
|
165
|
-
`Check the --app id, pass --dir, or run \`primitive config pull\` first.`
|
|
166
|
-
: `No ${subdir}/ directory found. Pass --dir or run \`primitive config pull\` first.`;
|
|
167
|
-
}
|
|
168
46
|
//# sourceMappingURL=resolveCodegenSourceDir.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveCodegenSourceDir.js","sourceRoot":"","sources":["../../../../src/lib/codegen-shared/resolveCodegenSourceDir.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"resolveCodegenSourceDir.js","sourceRoot":"","sources":["../../../../src/lib/codegen-shared/resolveCodegenSourceDir.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAOlD;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAiC;IACvE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACxB,MAAM,GAAG,GAAG,IAAI,CAAC,cAAc,EAAE,EAAE,MAAM,CAAC,CAAC;IAC3C,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,MAAM,MAAM,kBAAkB,GAAG,yCAAyC;YACxE,kDAAkD,CACrD,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `collections.json` artifact, and the decisions an import makes from it
|
|
3
|
+
* (#3643).
|
|
4
|
+
*
|
|
5
|
+
* `documents export-all` / `documents import` carry Yjs state, blobs,
|
|
6
|
+
* permissions and aliases, but nothing about collections: which exist, what
|
|
7
|
+
* each contains, who its members are and at what level, its group grants, and
|
|
8
|
+
* who owns it. This module is the half of `collections export` /
|
|
9
|
+
* `collections import` that needs no server — the file's shape, the plan the
|
|
10
|
+
* import builds from it, the comparisons that plan rests on, and the exit
|
|
11
|
+
* rule — so each is checkable on its own, as `document-ingest-rows` and
|
|
12
|
+
* `snapshot-build-rows` are for their commands.
|
|
13
|
+
*
|
|
14
|
+
* The one thing that does NOT live here is resolution: which userId an email
|
|
15
|
+
* answers to, whether a document exists, whether a group exists. Those are
|
|
16
|
+
* reads against a real server, they are the facts the plan is built from, and
|
|
17
|
+
* the command performs them and hands the answers in.
|
|
18
|
+
*/
|
|
19
|
+
/** The only file version this CLI reads or writes. */
|
|
20
|
+
export declare const COLLECTION_EXPORT_VERSION = 1;
|
|
21
|
+
/** Its name inside an export directory, beside `manifest.json`. */
|
|
22
|
+
export declare const COLLECTION_EXPORT_FILENAME = "collections.json";
|
|
23
|
+
export type CollectionPermission = "reader" | "read-write";
|
|
24
|
+
export interface ExportedOwner {
|
|
25
|
+
/** The SOURCE app's userId. Meaningful in the target only for a same-app import. */
|
|
26
|
+
userId: string;
|
|
27
|
+
/** Present when the source server could resolve it; the only cross-app identity. */
|
|
28
|
+
email?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface ExportedMember extends ExportedOwner {
|
|
31
|
+
permission: CollectionPermission;
|
|
32
|
+
}
|
|
33
|
+
export interface ExportedGroupGrant {
|
|
34
|
+
groupType: string;
|
|
35
|
+
groupId: string;
|
|
36
|
+
permission: CollectionPermission;
|
|
37
|
+
}
|
|
38
|
+
export interface ExportedCollectionDocument {
|
|
39
|
+
documentId: string;
|
|
40
|
+
addedAt?: string | null;
|
|
41
|
+
}
|
|
42
|
+
export interface ExportedCollection {
|
|
43
|
+
collectionId: string;
|
|
44
|
+
name: string;
|
|
45
|
+
description: string | null;
|
|
46
|
+
collectionType: string | null;
|
|
47
|
+
contextId: string | null;
|
|
48
|
+
createdAt: string | null;
|
|
49
|
+
owner: ExportedOwner | null;
|
|
50
|
+
documents: ExportedCollectionDocument[];
|
|
51
|
+
members: ExportedMember[];
|
|
52
|
+
groups: ExportedGroupGrant[];
|
|
53
|
+
}
|
|
54
|
+
export interface CollectionExportFile {
|
|
55
|
+
version: number;
|
|
56
|
+
exportedAt: string;
|
|
57
|
+
sourceAppId: string;
|
|
58
|
+
collectionCount: number;
|
|
59
|
+
collections: ExportedCollection[];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Resolve the `<path>` an import was given to the file it must read.
|
|
63
|
+
*
|
|
64
|
+
* Both forms work: an export DIRECTORY (the one `documents export-all` also
|
|
65
|
+
* wrote into) and the file itself.
|
|
66
|
+
*/
|
|
67
|
+
export declare function resolveCollectionExportPath(inputPath: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* Read and validate `collections.json`.
|
|
70
|
+
*
|
|
71
|
+
* Every refusal here happens BEFORE any request: a file this CLI cannot read
|
|
72
|
+
* is not a reason to start writing collections into the target app.
|
|
73
|
+
*/
|
|
74
|
+
export declare function readCollectionExportFile(inputPath: string): CollectionExportFile;
|
|
75
|
+
export type CollectionImportAction = "create" | "merge" | "skip" | "refused";
|
|
76
|
+
/** Which part of a collection a per-item problem is about. */
|
|
77
|
+
export type CollectionProblemKind = "owner" | "collection" | "document" | "member" | "group";
|
|
78
|
+
export interface CollectionImportProblem {
|
|
79
|
+
sourceCollectionId: string;
|
|
80
|
+
name: string;
|
|
81
|
+
kind: CollectionProblemKind;
|
|
82
|
+
/** The offending identity: a userId, an email, a documentId, `type/id`. */
|
|
83
|
+
id: string;
|
|
84
|
+
reason: string;
|
|
85
|
+
}
|
|
86
|
+
/** The target collection a name match found, as far as compatibility cares. */
|
|
87
|
+
export interface ExistingTargetCollection {
|
|
88
|
+
collectionId: string;
|
|
89
|
+
createdBy: string;
|
|
90
|
+
collectionType: string | null;
|
|
91
|
+
contextId: string | null;
|
|
92
|
+
}
|
|
93
|
+
export interface CollectionResolution {
|
|
94
|
+
/** The userId the owner resolved to in the TARGET app, or null. */
|
|
95
|
+
ownerUserId: string | null;
|
|
96
|
+
/** Why the owner could not be resolved — becomes the refusal's reason. */
|
|
97
|
+
ownerReason?: string;
|
|
98
|
+
/** The target collection carrying this exact name, if any. */
|
|
99
|
+
existing?: ExistingTargetCollection | null;
|
|
100
|
+
/** The source id of an earlier collection in the same file with this name. */
|
|
101
|
+
duplicateOfSourceId?: string | null;
|
|
102
|
+
}
|
|
103
|
+
export interface CollectionPlanRow {
|
|
104
|
+
sourceCollectionId: string;
|
|
105
|
+
name: string;
|
|
106
|
+
action: CollectionImportAction;
|
|
107
|
+
/** Why it was refused or skipped. Absent for `create`/`merge`. */
|
|
108
|
+
reason?: string;
|
|
109
|
+
/** Where it lands: known up front only for a `merge`. */
|
|
110
|
+
targetCollectionId?: string;
|
|
111
|
+
/** The resolved owner, for a `create`. */
|
|
112
|
+
ownerUserId?: string;
|
|
113
|
+
/** A refusal that must also be REPORTED as a problem carries it here. */
|
|
114
|
+
problem?: Omit<CollectionImportProblem, "sourceCollectionId" | "name">;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Which of `createdBy`, `collectionType` and `contextId` a name match differs
|
|
118
|
+
* on — the fields the server will never let an update change
|
|
119
|
+
* (`collections-controller.ts` rejects type and context; `createdBy` is
|
|
120
|
+
* immutable), so a difference cannot be merged away (F2).
|
|
121
|
+
*
|
|
122
|
+
* Returns null when the match is compatible.
|
|
123
|
+
*/
|
|
124
|
+
export declare function incompatibleField(collection: Pick<ExportedCollection, "collectionType" | "contextId">, existing: ExistingTargetCollection, ownerUserId: string): "owner" | "collectionType" | "contextId" | null;
|
|
125
|
+
/** What to do about one recorded group grant, given the target's grants. */
|
|
126
|
+
export type GrantDisposition = "grant" | "already-applied" | "update";
|
|
127
|
+
/**
|
|
128
|
+
* Compare a recorded grant with the target's.
|
|
129
|
+
*
|
|
130
|
+
* A grant already at the recorded level counts as applied without a write. A
|
|
131
|
+
* grant at a DIFFERENT level is sent: #3163 recomputes each document's
|
|
132
|
+
* materialized `DocumentGroupPermission` from its live sources on every
|
|
133
|
+
* collection-wide change, so the new level reaches what the group's members can
|
|
134
|
+
* actually do. Before that it did not — `materializeDGP` left an existing row
|
|
135
|
+
* alone once the collection was one of its sources — which is why the import
|
|
136
|
+
* used to report such a grant instead of changing it (F3).
|
|
137
|
+
*/
|
|
138
|
+
export declare function grantDisposition(wanted: ExportedGroupGrant, targetGrants: ExportedGroupGrant[]): GrantDisposition;
|
|
139
|
+
/** The line a level change is announced with, named from and to. */
|
|
140
|
+
export declare function grantUpdateLine(groupLabel: string, existingPermission: string, wantedPermission: string): string;
|
|
141
|
+
/**
|
|
142
|
+
* What a server refusal reads as in a per-item problem.
|
|
143
|
+
*
|
|
144
|
+
* The prose alone is not enough to act on. `COLLECTION_FANOUT_LIMIT` is the
|
|
145
|
+
* case that matters here: past `COLLECTION_GROUP_FANOUT_MAX` documents the
|
|
146
|
+
* server refuses a collection-wide group change whole (#3163), and the remedy —
|
|
147
|
+
* split the collection, or grant its documents one at a time — is nothing like
|
|
148
|
+
* the remedy for a 404 group. Carrying the code makes the two tellable apart by
|
|
149
|
+
* a script as well as by a reader.
|
|
150
|
+
*/
|
|
151
|
+
export declare function serverReason(err: any): string;
|
|
152
|
+
/**
|
|
153
|
+
* Decide what happens to one collection, from the facts the resolve phase read.
|
|
154
|
+
*
|
|
155
|
+
* Nothing here talks to a server: every input is already an answer.
|
|
156
|
+
*/
|
|
157
|
+
export declare function planCollection(collection: ExportedCollection, resolution: CollectionResolution, options: {
|
|
158
|
+
overwrite: boolean;
|
|
159
|
+
}): CollectionPlanRow;
|
|
160
|
+
/**
|
|
161
|
+
* The source ids of earlier same-named collections, keyed by source id.
|
|
162
|
+
*
|
|
163
|
+
* The FIRST collection with a name is the one that may land; every later one
|
|
164
|
+
* maps to it here and is refused.
|
|
165
|
+
*/
|
|
166
|
+
export declare function duplicateNameSources(collections: ExportedCollection[]): Map<string, string>;
|
|
167
|
+
export interface CollectionImportSummary {
|
|
168
|
+
created: number;
|
|
169
|
+
merged: number;
|
|
170
|
+
skipped: number;
|
|
171
|
+
refused: number;
|
|
172
|
+
groupsGranted: number;
|
|
173
|
+
membersAdded: number;
|
|
174
|
+
documentsAdded: number;
|
|
175
|
+
}
|
|
176
|
+
export declare function emptyImportSummary(): CollectionImportSummary;
|
|
177
|
+
/**
|
|
178
|
+
* The exit rule, in one place: 1 when any per-item problem was reported.
|
|
179
|
+
*
|
|
180
|
+
* A skip for a name collision is NOT a problem — it is the documented way to
|
|
181
|
+
* re-run an import without `--overwrite`. A refusal is, because something the
|
|
182
|
+
* operator asked for did not happen.
|
|
183
|
+
*/
|
|
184
|
+
export declare function importExitCode(problems: CollectionImportProblem[]): number;
|