primitive-admin 1.1.0-alpha.9 → 1.1.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 +523 -109
- package/assets/skill/skills/primitive-platform/SKILL.md +289 -0
- package/dist/bin/primitive.d.ts +2 -0
- package/dist/bin/primitive.js +372 -21
- package/dist/bin/primitive.js.map +1 -1
- package/dist/src/commands/admins.d.ts +2 -0
- package/dist/src/commands/admins.js +136 -30
- package/dist/src/commands/admins.js.map +1 -1
- package/dist/src/commands/analytics.d.ts +2 -0
- package/dist/src/commands/analytics.js +713 -55
- package/dist/src/commands/analytics.js.map +1 -1
- package/dist/src/commands/apps.d.ts +2 -0
- package/dist/src/commands/apps.js +65 -100
- 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.d.ts +2 -0
- package/dist/src/commands/auth.js +238 -108
- package/dist/src/commands/auth.js.map +1 -1
- package/dist/src/commands/blob-buckets.d.ts +2 -0
- package/dist/src/commands/blob-buckets.js +331 -0
- package/dist/src/commands/blob-buckets.js.map +1 -0
- package/dist/src/commands/catalog.d.ts +2 -0
- package/dist/src/commands/catalog.js +63 -48
- package/dist/src/commands/catalog.js.map +1 -1
- package/dist/src/commands/collection-type-configs.d.ts +2 -0
- package/dist/src/commands/collection-type-configs.js +85 -0
- package/dist/src/commands/collection-type-configs.js.map +1 -0
- package/dist/src/commands/collections.d.ts +2 -0
- package/dist/src/commands/collections.js +1282 -0
- package/dist/src/commands/collections.js.map +1 -0
- package/dist/src/commands/comparisons.d.ts +2 -0
- package/dist/src/commands/comparisons.js +6 -6
- package/dist/src/commands/comparisons.js.map +1 -1
- package/dist/src/commands/config.d.ts +46 -0
- package/dist/src/commands/config.js +465 -0
- package/dist/src/commands/config.js.map +1 -0
- package/dist/src/commands/connections.d.ts +2 -0
- package/dist/src/commands/connections.js +99 -0
- package/dist/src/commands/connections.js.map +1 -0
- package/dist/src/commands/cron-triggers.d.ts +2 -0
- package/dist/src/commands/cron-triggers.js +266 -0
- package/dist/src/commands/cron-triggers.js.map +1 -0
- package/dist/src/commands/database-type-configs.d.ts +2 -0
- package/dist/src/commands/database-type-configs.js +164 -0
- package/dist/src/commands/database-type-configs.js.map +1 -0
- package/dist/src/commands/database-types.d.ts +2 -0
- package/dist/src/commands/database-types.js +471 -0
- package/dist/src/commands/database-types.js.map +1 -0
- package/dist/src/commands/databases.d.ts +65 -0
- package/dist/src/commands/databases.js +1887 -243
- package/dist/src/commands/databases.js.map +1 -1
- package/dist/src/commands/documents.d.ts +60 -0
- package/dist/src/commands/documents.js +2888 -22
- package/dist/src/commands/documents.js.map +1 -1
- package/dist/src/commands/email-templates.d.ts +2 -0
- package/dist/src/commands/email-templates.js +175 -0
- package/dist/src/commands/email-templates.js.map +1 -0
- package/dist/src/commands/env.d.ts +23 -0
- package/dist/src/commands/env.js +395 -0
- package/dist/src/commands/env.js.map +1 -0
- package/dist/src/commands/feature-flags.d.ts +14 -0
- package/dist/src/commands/feature-flags.js +117 -0
- package/dist/src/commands/feature-flags.js.map +1 -0
- 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.d.ts +2 -0
- package/dist/src/commands/group-type-configs.js +87 -0
- package/dist/src/commands/group-type-configs.js.map +1 -0
- package/dist/src/commands/groups.d.ts +2 -0
- package/dist/src/commands/groups.js +65 -113
- package/dist/src/commands/groups.js.map +1 -1
- package/dist/src/commands/guides.d.ts +223 -0
- package/dist/src/commands/guides.js +627 -69
- package/dist/src/commands/guides.js.map +1 -1
- package/dist/src/commands/init.d.ts +37 -0
- package/dist/src/commands/init.js +1693 -208
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/integrations.d.ts +2 -0
- package/dist/src/commands/integrations.js +428 -187
- package/dist/src/commands/integrations.js.map +1 -1
- package/dist/src/commands/llm.d.ts +2 -0
- package/dist/src/commands/llm.js +4 -2
- package/dist/src/commands/llm.js.map +1 -1
- package/dist/src/commands/locks.d.ts +8 -0
- package/dist/src/commands/locks.js +175 -0
- package/dist/src/commands/locks.js.map +1 -0
- package/dist/src/commands/metadata-category-configs.d.ts +12 -0
- package/dist/src/commands/metadata-category-configs.js +113 -0
- package/dist/src/commands/metadata-category-configs.js.map +1 -0
- package/dist/src/commands/metadata.d.ts +2 -0
- package/dist/src/commands/metadata.js +288 -0
- package/dist/src/commands/metadata.js.map +1 -0
- package/dist/src/commands/prompts.d.ts +2 -0
- package/dist/src/commands/prompts.js +322 -634
- package/dist/src/commands/prompts.js.map +1 -1
- package/dist/src/commands/rule-sets.d.ts +3 -0
- package/dist/src/commands/rule-sets.js +139 -148
- package/dist/src/commands/rule-sets.js.map +1 -1
- package/dist/src/commands/scripts.d.ts +30 -0
- package/dist/src/commands/scripts.js +688 -0
- package/dist/src/commands/scripts.js.map +1 -0
- package/dist/src/commands/secrets.d.ts +2 -0
- package/dist/src/commands/secrets.js +109 -0
- package/dist/src/commands/secrets.js.map +1 -0
- package/dist/src/commands/sessions.d.ts +2 -0
- package/dist/src/commands/sessions.js +76 -0
- package/dist/src/commands/sessions.js.map +1 -0
- package/dist/src/commands/skill.d.ts +2 -0
- package/dist/src/commands/skill.js +29 -0
- package/dist/src/commands/skill.js.map +1 -0
- package/dist/src/commands/sync-app-settings.d.ts +158 -0
- package/dist/src/commands/sync-app-settings.js +328 -0
- package/dist/src/commands/sync-app-settings.js.map +1 -0
- package/dist/src/commands/sync.d.ts +2670 -0
- package/dist/src/commands/sync.js +17144 -834
- package/dist/src/commands/sync.js.map +1 -1
- package/dist/src/commands/tokens.d.ts +2 -0
- package/dist/src/commands/tokens.js +132 -22
- package/dist/src/commands/tokens.js.map +1 -1
- package/dist/src/commands/users.d.ts +2 -0
- package/dist/src/commands/users.js +542 -24
- package/dist/src/commands/users.js.map +1 -1
- package/dist/src/commands/vars.d.ts +8 -0
- package/dist/src/commands/vars.js +97 -0
- package/dist/src/commands/vars.js.map +1 -0
- package/dist/src/commands/waitlist.d.ts +2 -0
- package/dist/src/commands/waitlist.js +12 -11
- package/dist/src/commands/waitlist.js.map +1 -1
- package/dist/src/commands/webhooks.d.ts +31 -0
- package/dist/src/commands/webhooks.js +633 -0
- package/dist/src/commands/webhooks.js.map +1 -0
- package/dist/src/commands/workflows.d.ts +88 -0
- package/dist/src/commands/workflows.js +1568 -742
- package/dist/src/commands/workflows.js.map +1 -1
- package/dist/src/lib/access-rule-display.d.ts +21 -0
- package/dist/src/lib/access-rule-display.js +34 -0
- package/dist/src/lib/access-rule-display.js.map +1 -0
- package/dist/src/lib/api-client.d.ts +2550 -0
- package/dist/src/lib/api-client.js +2503 -160
- package/dist/src/lib/api-client.js.map +1 -1
- package/dist/src/lib/app-settings-descriptor.d.ts +263 -0
- package/dist/src/lib/app-settings-descriptor.js +583 -0
- package/dist/src/lib/app-settings-descriptor.js.map +1 -0
- package/dist/src/lib/auth-flow.d.ts +8 -0
- package/dist/src/lib/batch.d.ts +26 -0
- package/dist/src/lib/batch.js +32 -0
- package/dist/src/lib/batch.js.map +1 -0
- package/dist/src/lib/block-layout.d.ts +160 -0
- package/dist/src/lib/block-layout.js +451 -0
- package/dist/src/lib/block-layout.js.map +1 -0
- 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/canonical-json.d.ts +12 -0
- package/dist/src/lib/canonical-json.js +35 -0
- package/dist/src/lib/canonical-json.js.map +1 -0
- package/dist/src/lib/channel.d.ts +30 -0
- package/dist/src/lib/channel.js +68 -0
- package/dist/src/lib/channel.js.map +1 -0
- package/dist/src/lib/cli-manifest.d.ts +68 -0
- package/dist/src/lib/cli-manifest.js +71 -0
- package/dist/src/lib/cli-manifest.js.map +1 -0
- package/dist/src/lib/codegen-shared/generatedFiles.d.ts +101 -0
- package/dist/src/lib/codegen-shared/generatedFiles.js +191 -0
- package/dist/src/lib/codegen-shared/generatedFiles.js.map +1 -0
- package/dist/src/lib/codegen-shared/prettierStable.d.ts +262 -0
- package/dist/src/lib/codegen-shared/prettierStable.js +610 -0
- package/dist/src/lib/codegen-shared/prettierStable.js.map +1 -0
- package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.d.ts +38 -0
- package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js +46 -0
- package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js.map +1 -0
- 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.d.ts +127 -0
- package/dist/src/lib/config-object-descriptor.js +740 -0
- package/dist/src/lib/config-object-descriptor.js.map +1 -0
- package/dist/src/lib/config-payload.d.ts +92 -0
- package/dist/src/lib/config-payload.js +161 -0
- package/dist/src/lib/config-payload.js.map +1 -0
- package/dist/src/lib/config-surface.d.ts +141 -0
- package/dist/src/lib/config-surface.js +368 -0
- package/dist/src/lib/config-surface.js.map +1 -0
- package/dist/src/lib/config-toml.d.ts +10 -0
- package/dist/src/lib/config-toml.js +42 -0
- package/dist/src/lib/config-toml.js.map +1 -0
- package/dist/src/lib/config.d.ts +71 -0
- package/dist/src/lib/config.js +71 -68
- package/dist/src/lib/config.js.map +1 -1
- package/dist/src/lib/confirm-prompt.d.ts +83 -0
- package/dist/src/lib/confirm-prompt.js +110 -0
- package/dist/src/lib/confirm-prompt.js.map +1 -0
- package/dist/src/lib/constants.d.ts +11 -0
- package/dist/src/lib/constants.js +12 -0
- package/dist/src/lib/constants.js.map +1 -0
- package/dist/src/lib/crash-handlers.d.ts +20 -0
- package/dist/src/lib/crash-handlers.js +49 -0
- package/dist/src/lib/crash-handlers.js.map +1 -0
- package/dist/src/lib/credentials-store.d.ts +104 -0
- package/dist/src/lib/credentials-store.js +336 -0
- package/dist/src/lib/credentials-store.js.map +1 -0
- package/dist/src/lib/csv.d.ts +47 -0
- package/dist/src/lib/csv.js +172 -0
- package/dist/src/lib/csv.js.map +1 -0
- package/dist/src/lib/data-input.d.ts +23 -0
- package/dist/src/lib/data-input.js +50 -0
- package/dist/src/lib/data-input.js.map +1 -0
- package/dist/src/lib/db-codegen/dbFingerprint.d.ts +10 -0
- package/dist/src/lib/db-codegen/dbFingerprint.js +17 -0
- package/dist/src/lib/db-codegen/dbFingerprint.js.map +1 -0
- package/dist/src/lib/db-codegen/dbGenerator.d.ts +67 -0
- package/dist/src/lib/db-codegen/dbGenerator.js +170 -0
- package/dist/src/lib/db-codegen/dbGenerator.js.map +1 -0
- package/dist/src/lib/db-codegen/dbNaming.d.ts +87 -0
- package/dist/src/lib/db-codegen/dbNaming.js +180 -0
- package/dist/src/lib/db-codegen/dbNaming.js.map +1 -0
- package/dist/src/lib/db-codegen/dbTemplates.d.ts +272 -0
- package/dist/src/lib/db-codegen/dbTemplates.js +480 -0
- package/dist/src/lib/db-codegen/dbTemplates.js.map +1 -0
- package/dist/src/lib/db-codegen/dbTsTypes.d.ts +73 -0
- package/dist/src/lib/db-codegen/dbTsTypes.js +139 -0
- package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -0
- package/dist/src/lib/db-codegen/dbTypeIR.d.ts +146 -0
- package/dist/src/lib/db-codegen/dbTypeIR.js +525 -0
- package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -0
- package/dist/src/lib/db-codegen/generated-operation-def-descriptor.d.ts +112 -0
- package/dist/src/lib/db-codegen/generated-operation-def-descriptor.js +211 -0
- package/dist/src/lib/db-codegen/generated-operation-def-descriptor.js.map +1 -0
- 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 +258 -0
- package/dist/src/lib/env-resolver-core.js +447 -0
- package/dist/src/lib/env-resolver-core.js.map +1 -0
- package/dist/src/lib/env-resolver.d.ts +99 -0
- package/dist/src/lib/env-resolver.js +153 -0
- package/dist/src/lib/env-resolver.js.map +1 -0
- package/dist/src/lib/fetch.d.ts +5 -0
- 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.d.ts +28 -0
- package/dist/src/lib/generated-allowlist.js +281 -0
- package/dist/src/lib/generated-allowlist.js.map +1 -0
- package/dist/src/lib/generated-config-surfaces.d.ts +2936 -0
- package/dist/src/lib/generated-config-surfaces.js +10569 -0
- package/dist/src/lib/generated-config-surfaces.js.map +1 -0
- 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/generated-template-lint.d.ts +212 -0
- package/dist/src/lib/generated-template-lint.js +624 -0
- package/dist/src/lib/generated-template-lint.js.map +1 -0
- package/dist/src/lib/init-adopt.d.ts +16 -0
- package/dist/src/lib/init-adopt.js +34 -0
- package/dist/src/lib/init-adopt.js.map +1 -0
- package/dist/src/lib/init-assets.d.ts +39 -0
- package/dist/src/lib/init-assets.js +97 -0
- package/dist/src/lib/init-assets.js.map +1 -0
- 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 +98 -0
- package/dist/src/lib/init-config.js +186 -0
- package/dist/src/lib/init-config.js.map +1 -0
- 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 +91 -0
- package/dist/src/lib/init-ios-links.js +219 -0
- package/dist/src/lib/init-ios-links.js.map +1 -0
- package/dist/src/lib/init-plan.d.ts +80 -0
- package/dist/src/lib/init-plan.js +95 -0
- package/dist/src/lib/init-plan.js.map +1 -0
- package/dist/src/lib/init-production-env.d.ts +48 -0
- package/dist/src/lib/init-production-env.js +59 -0
- package/dist/src/lib/init-production-env.js.map +1 -0
- package/dist/src/lib/init-schema.d.ts +74 -0
- package/dist/src/lib/init-schema.js +358 -0
- package/dist/src/lib/init-schema.js.map +1 -0
- package/dist/src/lib/init-xcode.d.ts +34 -0
- package/dist/src/lib/init-xcode.js +138 -0
- package/dist/src/lib/init-xcode.js.map +1 -0
- package/dist/src/lib/integration-request-config.d.ts +30 -0
- package/dist/src/lib/integration-request-config.js +145 -0
- package/dist/src/lib/integration-request-config.js.map +1 -0
- 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 +55 -0
- package/dist/src/lib/local-state.js +167 -0
- package/dist/src/lib/local-state.js.map +1 -0
- 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 +715 -0
- package/dist/src/lib/log-inspection.js +816 -0
- package/dist/src/lib/log-inspection.js.map +1 -0
- 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/migration-nag.d.ts +49 -0
- package/dist/src/lib/migration-nag.js +163 -0
- package/dist/src/lib/migration-nag.js.map +1 -0
- package/dist/src/lib/object-status-filter.d.ts +22 -0
- package/dist/src/lib/object-status-filter.js +45 -0
- package/dist/src/lib/object-status-filter.js.map +1 -0
- package/dist/src/lib/output.d.ts +124 -0
- package/dist/src/lib/output.js +219 -8
- package/dist/src/lib/output.js.map +1 -1
- package/dist/src/lib/package-manager.d.ts +140 -0
- package/dist/src/lib/package-manager.js +305 -0
- package/dist/src/lib/package-manager.js.map +1 -0
- package/dist/src/lib/paginate.d.ts +98 -0
- package/dist/src/lib/paginate.js +112 -0
- package/dist/src/lib/paginate.js.map +1 -0
- package/dist/src/lib/platform-owned.d.ts +63 -0
- package/dist/src/lib/platform-owned.js +85 -0
- package/dist/src/lib/platform-owned.js.map +1 -0
- package/dist/src/lib/project-config.d.ts +122 -0
- package/dist/src/lib/project-config.js +244 -0
- package/dist/src/lib/project-config.js.map +1 -0
- 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/query-operators.d.ts +43 -0
- package/dist/src/lib/query-operators.js +80 -0
- package/dist/src/lib/query-operators.js.map +1 -0
- package/dist/src/lib/record-filter.d.ts +18 -0
- package/dist/src/lib/record-filter.js +55 -0
- package/dist/src/lib/record-filter.js.map +1 -0
- package/dist/src/lib/refresh-admin-credentials.d.ts +73 -0
- package/dist/src/lib/refresh-admin-credentials.js +123 -0
- package/dist/src/lib/refresh-admin-credentials.js.map +1 -0
- package/dist/src/lib/resolve-init-dev-port.d.ts +56 -0
- package/dist/src/lib/resolve-init-dev-port.js +55 -0
- package/dist/src/lib/resolve-init-dev-port.js.map +1 -0
- package/dist/src/lib/resolve-init-server.d.ts +64 -0
- package/dist/src/lib/resolve-init-server.js +77 -0
- package/dist/src/lib/resolve-init-server.js.map +1 -0
- 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/resolve-platform.d.ts +74 -0
- package/dist/src/lib/resolve-platform.js +105 -0
- package/dist/src/lib/resolve-platform.js.map +1 -0
- package/dist/src/lib/run-status.d.ts +19 -0
- package/dist/src/lib/run-status.generated.d.ts +39 -0
- package/dist/src/lib/run-status.generated.js +66 -0
- package/dist/src/lib/run-status.generated.js.map +1 -0
- package/dist/src/lib/run-status.js +19 -0
- package/dist/src/lib/run-status.js.map +1 -0
- package/dist/src/lib/server-text-normalization.d.ts +51 -0
- package/dist/src/lib/server-text-normalization.js +90 -0
- package/dist/src/lib/server-text-normalization.js.map +1 -0
- package/dist/src/lib/server-url.d.ts +22 -0
- package/dist/src/lib/server-url.js +33 -0
- package/dist/src/lib/server-url.js.map +1 -0
- package/dist/src/lib/signing-secret-status.d.ts +81 -0
- package/dist/src/lib/signing-secret-status.js +116 -0
- package/dist/src/lib/signing-secret-status.js.map +1 -0
- package/dist/src/lib/skill-installer.d.ts +71 -0
- package/dist/src/lib/skill-installer.js +441 -0
- package/dist/src/lib/skill-installer.js.map +1 -0
- 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 +98 -0
- package/dist/src/lib/snapshots.js +294 -0
- package/dist/src/lib/snapshots.js.map +1 -0
- 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.d.ts +113 -0
- package/dist/src/lib/swift-codegen/dbGenerator.js +926 -0
- package/dist/src/lib/swift-codegen/dbGenerator.js.map +1 -0
- package/dist/src/lib/swift-codegen/dbSwiftTypes.d.ts +42 -0
- package/dist/src/lib/swift-codegen/dbSwiftTypes.js +100 -0
- package/dist/src/lib/swift-codegen/dbSwiftTypes.js.map +1 -0
- 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 +100 -0
- package/dist/src/lib/swift-codegen/generator.js +457 -0
- package/dist/src/lib/swift-codegen/generator.js.map +1 -0
- package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +87 -0
- package/dist/src/lib/swift-codegen/schemaToSwift.js +661 -0
- package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -0
- package/dist/src/lib/swift-codegen/siblingSymbols.d.ts +94 -0
- package/dist/src/lib/swift-codegen/siblingSymbols.js +155 -0
- package/dist/src/lib/swift-codegen/siblingSymbols.js.map +1 -0
- package/dist/src/lib/swift-codegen/swiftNaming.d.ts +85 -0
- package/dist/src/lib/swift-codegen/swiftNaming.js +198 -0
- package/dist/src/lib/swift-codegen/swiftNaming.js.map +1 -0
- package/dist/src/lib/sync-dir-selector.d.ts +21 -0
- package/dist/src/lib/sync-dir-selector.js +30 -0
- package/dist/src/lib/sync-dir-selector.js.map +1 -0
- package/dist/src/lib/sync-paths.d.ts +128 -0
- package/dist/src/lib/sync-paths.js +195 -0
- package/dist/src/lib/sync-paths.js.map +1 -0
- package/dist/src/lib/sync-resource-types.d.ts +563 -0
- package/dist/src/lib/sync-resource-types.js +1073 -0
- package/dist/src/lib/sync-resource-types.js.map +1 -0
- package/dist/src/lib/sync-selectors.d.ts +138 -0
- package/dist/src/lib/sync-selectors.js +289 -0
- package/dist/src/lib/sync-selectors.js.map +1 -0
- package/dist/src/lib/template.d.ts +170 -0
- package/dist/src/lib/template.js +484 -68
- package/dist/src/lib/template.js.map +1 -1
- 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 +29 -0
- package/dist/src/lib/test-case-keys.js +55 -0
- package/dist/src/lib/test-case-keys.js.map +1 -0
- package/dist/src/lib/test-case-variables.d.ts +29 -0
- package/dist/src/lib/test-case-variables.js +71 -0
- package/dist/src/lib/test-case-variables.js.map +1 -0
- package/dist/src/lib/token-inject.d.ts +56 -0
- package/dist/src/lib/token-inject.js +204 -0
- package/dist/src/lib/token-inject.js.map +1 -0
- package/dist/src/lib/toml-database-config.d.ts +123 -0
- package/dist/src/lib/toml-database-config.js +544 -0
- package/dist/src/lib/toml-database-config.js.map +1 -0
- package/dist/src/lib/toml-metadata-config.d.ts +151 -0
- package/dist/src/lib/toml-metadata-config.js +476 -0
- package/dist/src/lib/toml-metadata-config.js.map +1 -0
- package/dist/src/lib/toml-native-form.d.ts +46 -0
- package/dist/src/lib/toml-native-form.js +78 -0
- package/dist/src/lib/toml-native-form.js.map +1 -0
- package/dist/src/lib/toml-params-validator.d.ts +129 -0
- package/dist/src/lib/toml-params-validator.js +298 -0
- package/dist/src/lib/toml-params-validator.js.map +1 -0
- package/dist/src/lib/toml-scalar-edit.d.ts +43 -0
- package/dist/src/lib/toml-scalar-edit.js +283 -0
- package/dist/src/lib/toml-scalar-edit.js.map +1 -0
- package/dist/src/lib/user-selector.d.ts +24 -0
- package/dist/src/lib/user-selector.js +33 -0
- package/dist/src/lib/user-selector.js.map +1 -0
- package/dist/src/lib/version-check.d.ts +35 -0
- package/dist/src/lib/version-check.js +241 -0
- package/dist/src/lib/version-check.js.map +1 -0
- package/dist/src/lib/watch.d.ts +121 -0
- package/dist/src/lib/watch.js +169 -0
- package/dist/src/lib/watch.js.map +1 -0
- 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-apply.d.ts +110 -0
- package/dist/src/lib/workflow-apply.js +164 -0
- package/dist/src/lib/workflow-apply.js.map +1 -0
- package/dist/src/lib/workflow-codegen/generated-schema-descriptor.d.ts +129 -0
- package/dist/src/lib/workflow-codegen/generated-schema-descriptor.js +269 -0
- package/dist/src/lib/workflow-codegen/generated-schema-descriptor.js.map +1 -0
- package/dist/src/lib/workflow-codegen/generator.d.ts +96 -0
- package/dist/src/lib/workflow-codegen/generator.js +361 -0
- package/dist/src/lib/workflow-codegen/generator.js.map +1 -0
- package/dist/src/lib/workflow-codegen/invokerIR.d.ts +94 -0
- package/dist/src/lib/workflow-codegen/invokerIR.js +76 -0
- package/dist/src/lib/workflow-codegen/invokerIR.js.map +1 -0
- package/dist/src/lib/workflow-codegen/naming.d.ts +33 -0
- package/dist/src/lib/workflow-codegen/naming.js +81 -0
- package/dist/src/lib/workflow-codegen/naming.js.map +1 -0
- package/dist/src/lib/workflow-codegen/schemaToTs.d.ts +80 -0
- package/dist/src/lib/workflow-codegen/schemaToTs.js +303 -0
- package/dist/src/lib/workflow-codegen/schemaToTs.js.map +1 -0
- package/dist/src/lib/workflow-config-apply.d.ts +70 -0
- package/dist/src/lib/workflow-config-apply.js +137 -0
- package/dist/src/lib/workflow-config-apply.js.map +1 -0
- package/dist/src/lib/workflow-config-sidecar.d.ts +63 -0
- package/dist/src/lib/workflow-config-sidecar.js +96 -0
- package/dist/src/lib/workflow-config-sidecar.js.map +1 -0
- package/dist/src/lib/workflow-defaults.d.ts +29 -0
- package/dist/src/lib/workflow-defaults.js +41 -0
- package/dist/src/lib/workflow-defaults.js.map +1 -0
- package/dist/src/lib/workflow-fragments.d.ts +64 -0
- package/dist/src/lib/workflow-fragments.js +342 -0
- package/dist/src/lib/workflow-fragments.js.map +1 -0
- package/dist/src/lib/workflow-include-preserve.d.ts +76 -0
- package/dist/src/lib/workflow-include-preserve.js +286 -0
- package/dist/src/lib/workflow-include-preserve.js.map +1 -0
- package/dist/src/lib/workflow-payload.d.ts +98 -0
- package/dist/src/lib/workflow-payload.js +178 -0
- package/dist/src/lib/workflow-payload.js.map +1 -0
- package/dist/src/lib/workflow-toml-validator.d.ts +211 -0
- package/dist/src/lib/workflow-toml-validator.js +770 -0
- package/dist/src/lib/workflow-toml-validator.js.map +1 -0
- 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 +591 -0
- package/dist/src/validators.d.ts +65 -0
- package/dist/src/validators.js +64 -0
- package/dist/src/validators.js.map +1 -0
- package/package.json +34 -9
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credentials storage with dual-mode support.
|
|
3
|
+
*
|
|
4
|
+
* Credentials are tokens and who they belong to, and nothing else: the app an
|
|
5
|
+
* invocation runs against is the resolved environment's `appId` (#3152), never
|
|
6
|
+
* a slot in this file.
|
|
7
|
+
*
|
|
8
|
+
* Mode A (project mode): credentials live at
|
|
9
|
+
* <projectRoot>/.primitive/credentials.json
|
|
10
|
+
* with per-environment slots:
|
|
11
|
+
* {
|
|
12
|
+
* "environments": {
|
|
13
|
+
* "dev": { "accessToken": "...", "refreshToken": "...", ... },
|
|
14
|
+
* "prod": { ... }
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* Mode B (global mode): no primitive/config.json in scope, so we fall back to
|
|
19
|
+
* ~/.primitive/credentials.json
|
|
20
|
+
* with the flat Credentials shape the CLI has always used.
|
|
21
|
+
*
|
|
22
|
+
* Mode B is NOT a default any more (#3154, intent criterion 5). It used to be
|
|
23
|
+
* the silent answer for every command run outside a project, which is how an
|
|
24
|
+
* app-scoped command could quietly operate against whatever server the last
|
|
25
|
+
* `login` happened to target. Now a command has to say out loud that it may
|
|
26
|
+
* work outside a project, by calling `allowGlobalCredentials()` in its own
|
|
27
|
+
* action; every other command gets `missing-config` here instead of a file.
|
|
28
|
+
*
|
|
29
|
+
* Exactly four commands say it: `login`, which creates the file; `logout`,
|
|
30
|
+
* which is the only way to clear what login wrote; `init`, which must call the
|
|
31
|
+
* API before a project can exist; and `bootstrap`, which creates the first
|
|
32
|
+
* super-admin on an empty no-OAuth database and therefore cannot be inside a
|
|
33
|
+
* project either. The last two are the divergence from the intent's "login and
|
|
34
|
+
* init and nothing else", adjudicated on #3154 as finding F1.
|
|
35
|
+
*
|
|
36
|
+
* The opt-in is per ACTION, not per argv: `primitive --env prod login` and
|
|
37
|
+
* `primitive login` reach the same line, so there is no flag shape for a
|
|
38
|
+
* pre-parse to miss. And it only PERMITS the global file — inside a project
|
|
39
|
+
* all four still use the per-environment slots.
|
|
40
|
+
*/
|
|
41
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync, } from "fs";
|
|
42
|
+
import { homedir } from "os";
|
|
43
|
+
import { join } from "path";
|
|
44
|
+
import { getCurrentEnvironment, getProjectConfig } from "./env-resolver.js";
|
|
45
|
+
import { missingConfigMessage, PrimitiveEnvError } from "./env-resolver-core.js";
|
|
46
|
+
export const PROJECT_LOCAL_DIR = ".primitive";
|
|
47
|
+
export const PROJECT_CREDENTIALS_FILENAME = "credentials.json";
|
|
48
|
+
/**
|
|
49
|
+
* Resolves the legacy config dir on each call (rather than capturing it
|
|
50
|
+
* at module load) so tests and environment variables can override it
|
|
51
|
+
* after the module has already been imported.
|
|
52
|
+
*/
|
|
53
|
+
function getLegacyConfigDir() {
|
|
54
|
+
return process.env.PRIMITIVE_CONFIG_DIR || join(homedir(), ".primitive");
|
|
55
|
+
}
|
|
56
|
+
function getLegacyCredentialsFile() {
|
|
57
|
+
return join(getLegacyConfigDir(), PROJECT_CREDENTIALS_FILENAME);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The keys the retired per-machine "current app" wrote (#3152).
|
|
61
|
+
*
|
|
62
|
+
* Dropping the fields from the types is not enough to stop them being written:
|
|
63
|
+
* project-mode saves preserve the environment slots they are not touching, and
|
|
64
|
+
* a legacy refresh spreads the credentials it loaded. So the keys are scrubbed
|
|
65
|
+
* where every path meets — on READ — and the legacy file is serialized from an
|
|
66
|
+
* explicit shape rather than from whatever object the caller handed over. An
|
|
67
|
+
* existing file's values stay readable to a human looking for the app id their
|
|
68
|
+
* environment should name; no code path carries them forward.
|
|
69
|
+
*/
|
|
70
|
+
const RETIRED_CURRENT_APP_KEYS = ["currentAppId", "currentAppName"];
|
|
71
|
+
function stripRetiredCurrentApp(value) {
|
|
72
|
+
if (value && typeof value === "object") {
|
|
73
|
+
for (const key of RETIRED_CURRENT_APP_KEYS) {
|
|
74
|
+
delete value[key];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
/** Returns true when a primitive/config.json is in scope (project mode active). */
|
|
80
|
+
export function isProjectMode() {
|
|
81
|
+
return getProjectConfig() !== null;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Returns the path to the credentials file that will be used, based on
|
|
85
|
+
* whether we're in project mode or legacy mode.
|
|
86
|
+
*/
|
|
87
|
+
export function getCredentialsFilePath() {
|
|
88
|
+
const env = resolveCurrentEnvironment();
|
|
89
|
+
if (env) {
|
|
90
|
+
return join(env.projectRoot, PROJECT_LOCAL_DIR, PROJECT_CREDENTIALS_FILENAME);
|
|
91
|
+
}
|
|
92
|
+
return getLegacyCredentialsFile();
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Set by the four actions that may read or write the global credentials file
|
|
96
|
+
* with no project in scope. Process-wide, because one invocation runs one
|
|
97
|
+
* command; never reset, because a command does not stop being `login`.
|
|
98
|
+
*/
|
|
99
|
+
let globalCredentialsAllowed = false;
|
|
100
|
+
/**
|
|
101
|
+
* Declare that THIS command may fall back to `~/.primitive/credentials.json`
|
|
102
|
+
* when no project is in scope. Called at the top of `login`, `logout`, `init`
|
|
103
|
+
* and `bootstrap`, and nowhere else.
|
|
104
|
+
*/
|
|
105
|
+
export function allowGlobalCredentials() {
|
|
106
|
+
globalCredentialsAllowed = true;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Drop the declaration again. One invocation runs one command, so nothing in
|
|
110
|
+
* the CLI calls this — it exists so a test file can exercise both sides of the
|
|
111
|
+
* boundary in one process, the way `resetEnvResolver()` does for the resolver.
|
|
112
|
+
*/
|
|
113
|
+
export function resetGlobalCredentialsAllowance() {
|
|
114
|
+
globalCredentialsAllowed = false;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Resolves the current environment. If an environment CAN'T be resolved
|
|
118
|
+
* (e.g. --env points at an unknown name), this throws — we never silently
|
|
119
|
+
* fall back to global credentials because a typo in the env name must not
|
|
120
|
+
* cause the CLI to operate against the wrong app/server.
|
|
121
|
+
*
|
|
122
|
+
* Returns null only when there is no project config at all AND the running
|
|
123
|
+
* command declared itself allowed to work there; otherwise that case is the
|
|
124
|
+
* one refusal (#3154).
|
|
125
|
+
*/
|
|
126
|
+
function resolveCurrentEnvironment() {
|
|
127
|
+
const env = getCurrentEnvironment();
|
|
128
|
+
if (env)
|
|
129
|
+
return env;
|
|
130
|
+
if (globalCredentialsAllowed)
|
|
131
|
+
return null;
|
|
132
|
+
throw new PrimitiveEnvError("missing-config", missingConfigMessage(process.cwd()));
|
|
133
|
+
}
|
|
134
|
+
function ensureDir(dir) {
|
|
135
|
+
if (!existsSync(dir)) {
|
|
136
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function readJsonFile(path) {
|
|
140
|
+
try {
|
|
141
|
+
if (!existsSync(path))
|
|
142
|
+
return null;
|
|
143
|
+
const data = readFileSync(path, "utf-8");
|
|
144
|
+
return JSON.parse(data);
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Loads a legacy (global) credentials file. Used for backwards compat.
|
|
152
|
+
*/
|
|
153
|
+
function loadLegacyCredentials() {
|
|
154
|
+
return stripRetiredCurrentApp(readJsonFile(getLegacyCredentialsFile()));
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* The legacy file's shape, field by field. Serializing the passed object
|
|
158
|
+
* wholesale is what let a token refresh write an old file's retired keys back
|
|
159
|
+
* out; an explicit record can only ever contain what credentials are.
|
|
160
|
+
*/
|
|
161
|
+
function legacyCredentialsRecord(credentials) {
|
|
162
|
+
return {
|
|
163
|
+
serverUrl: credentials.serverUrl,
|
|
164
|
+
accessToken: credentials.accessToken,
|
|
165
|
+
refreshToken: credentials.refreshToken,
|
|
166
|
+
expiresAt: credentials.expiresAt,
|
|
167
|
+
adminId: credentials.adminId,
|
|
168
|
+
email: credentials.email,
|
|
169
|
+
role: credentials.role,
|
|
170
|
+
name: credentials.name,
|
|
171
|
+
globalAdminAppId: credentials.globalAdminAppId,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Loads the project credentials file, if present. Never throws — returns
|
|
176
|
+
* an empty shape when the file is missing or unreadable.
|
|
177
|
+
*/
|
|
178
|
+
function loadProjectCredentialsFile(projectRoot) {
|
|
179
|
+
const path = join(projectRoot, PROJECT_LOCAL_DIR, PROJECT_CREDENTIALS_FILENAME);
|
|
180
|
+
const data = readJsonFile(path);
|
|
181
|
+
if (!data || typeof data !== "object" || !data.environments) {
|
|
182
|
+
return { environments: {} };
|
|
183
|
+
}
|
|
184
|
+
// EVERY slot, not just the one about to be written: each write reserializes
|
|
185
|
+
// the whole file, so a stale key anywhere would survive forever.
|
|
186
|
+
for (const slot of Object.values(data.environments)) {
|
|
187
|
+
stripRetiredCurrentApp(slot);
|
|
188
|
+
}
|
|
189
|
+
return data;
|
|
190
|
+
}
|
|
191
|
+
function writeProjectCredentialsFile(projectRoot, file) {
|
|
192
|
+
const dir = join(projectRoot, PROJECT_LOCAL_DIR);
|
|
193
|
+
ensureDir(dir);
|
|
194
|
+
const path = join(dir, PROJECT_CREDENTIALS_FILENAME);
|
|
195
|
+
writeFileSync(path, JSON.stringify(file, null, 2), { mode: 0o600 });
|
|
196
|
+
try {
|
|
197
|
+
chmodSync(path, 0o600);
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
// Best-effort on Windows / weird filesystems
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Reads credentials for the current environment (project mode) or the
|
|
205
|
+
* legacy global file. Returns the standard Credentials shape so existing
|
|
206
|
+
* callers don't need to change.
|
|
207
|
+
*
|
|
208
|
+
* In project mode, we blend the per-env stored creds with the serverUrl
|
|
209
|
+
* and appId from primitive/config.json to produce the Credentials the rest of
|
|
210
|
+
* the CLI expects.
|
|
211
|
+
*/
|
|
212
|
+
export function loadCredentialsStore() {
|
|
213
|
+
const env = resolveCurrentEnvironment();
|
|
214
|
+
if (!env) {
|
|
215
|
+
return loadLegacyCredentials();
|
|
216
|
+
}
|
|
217
|
+
const file = loadProjectCredentialsFile(env.projectRoot);
|
|
218
|
+
const stored = file.environments[env.name];
|
|
219
|
+
if (!stored)
|
|
220
|
+
return null;
|
|
221
|
+
return {
|
|
222
|
+
serverUrl: env.config.apiUrl,
|
|
223
|
+
accessToken: stored.accessToken,
|
|
224
|
+
refreshToken: stored.refreshToken,
|
|
225
|
+
expiresAt: stored.expiresAt,
|
|
226
|
+
adminId: stored.adminId,
|
|
227
|
+
email: stored.email,
|
|
228
|
+
role: stored.role,
|
|
229
|
+
name: stored.name,
|
|
230
|
+
globalAdminAppId: stored.globalAdminAppId,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Saves credentials. In project mode, writes to the per-env slot in the
|
|
235
|
+
* project credentials file. In legacy mode, writes the global file.
|
|
236
|
+
*
|
|
237
|
+
* The serverUrl on the incoming Credentials is used as-is for legacy
|
|
238
|
+
* mode, and ignored in project mode (the env's apiUrl is canonical).
|
|
239
|
+
*/
|
|
240
|
+
export function saveCredentialsStore(credentials) {
|
|
241
|
+
const env = resolveCurrentEnvironment();
|
|
242
|
+
if (!env) {
|
|
243
|
+
ensureDir(getLegacyConfigDir());
|
|
244
|
+
writeFileSync(getLegacyCredentialsFile(), JSON.stringify(legacyCredentialsRecord(credentials), null, 2), { mode: 0o600 });
|
|
245
|
+
try {
|
|
246
|
+
chmodSync(getLegacyCredentialsFile(), 0o600);
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
// Best-effort
|
|
250
|
+
}
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
const file = loadProjectCredentialsFile(env.projectRoot);
|
|
254
|
+
file.environments[env.name] = {
|
|
255
|
+
accessToken: credentials.accessToken,
|
|
256
|
+
refreshToken: credentials.refreshToken,
|
|
257
|
+
expiresAt: credentials.expiresAt,
|
|
258
|
+
adminId: credentials.adminId,
|
|
259
|
+
email: credentials.email,
|
|
260
|
+
role: credentials.role,
|
|
261
|
+
name: credentials.name,
|
|
262
|
+
globalAdminAppId: credentials.globalAdminAppId,
|
|
263
|
+
};
|
|
264
|
+
writeProjectCredentialsFile(env.projectRoot, file);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Clears credentials for the current environment (project mode) or
|
|
268
|
+
* deletes the legacy file (legacy mode).
|
|
269
|
+
*/
|
|
270
|
+
export function clearCredentialsStore() {
|
|
271
|
+
const env = resolveCurrentEnvironment();
|
|
272
|
+
if (!env) {
|
|
273
|
+
try {
|
|
274
|
+
if (existsSync(getLegacyCredentialsFile())) {
|
|
275
|
+
unlinkSync(getLegacyCredentialsFile());
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
catch {
|
|
279
|
+
// Ignore
|
|
280
|
+
}
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
const file = loadProjectCredentialsFile(env.projectRoot);
|
|
284
|
+
delete file.environments[env.name];
|
|
285
|
+
writeProjectCredentialsFile(env.projectRoot, file);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Removes the credentials slot for the named environment in a specific
|
|
289
|
+
* project's credentials file. Used by `env remove` so stale tokens from a
|
|
290
|
+
* previously-removed environment can never be silently re-used if the same
|
|
291
|
+
* name is later added back. Never throws.
|
|
292
|
+
*/
|
|
293
|
+
export function clearCredentialsForEnvInProject(projectRoot, envName) {
|
|
294
|
+
try {
|
|
295
|
+
const file = loadProjectCredentialsFile(projectRoot);
|
|
296
|
+
if (file.environments[envName]) {
|
|
297
|
+
delete file.environments[envName];
|
|
298
|
+
writeProjectCredentialsFile(projectRoot, file);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
catch {
|
|
302
|
+
// Best-effort — removal is not a hard requirement for env removal to succeed.
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Writes the credentials slot for the named environment in a specific
|
|
307
|
+
* project's credentials file. Used by `primitive init` to carry the session
|
|
308
|
+
* it just authenticated into the freshly scaffolded project, so the first
|
|
309
|
+
* in-project CLI command works without a second `primitive login`.
|
|
310
|
+
*/
|
|
311
|
+
export function seedCredentialsForEnvInProject(projectRoot, envName, credentials) {
|
|
312
|
+
const file = loadProjectCredentialsFile(projectRoot);
|
|
313
|
+
file.environments[envName] = {
|
|
314
|
+
accessToken: credentials.accessToken,
|
|
315
|
+
refreshToken: credentials.refreshToken,
|
|
316
|
+
expiresAt: credentials.expiresAt,
|
|
317
|
+
adminId: credentials.adminId,
|
|
318
|
+
email: credentials.email,
|
|
319
|
+
role: credentials.role,
|
|
320
|
+
name: credentials.name,
|
|
321
|
+
globalAdminAppId: credentials.globalAdminAppId,
|
|
322
|
+
};
|
|
323
|
+
writeProjectCredentialsFile(projectRoot, file);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Lists all environments that have stored credentials in project mode.
|
|
327
|
+
* Returns an empty array in legacy mode.
|
|
328
|
+
*/
|
|
329
|
+
export function listAuthenticatedEnvironments() {
|
|
330
|
+
const env = resolveCurrentEnvironment();
|
|
331
|
+
if (!env)
|
|
332
|
+
return [];
|
|
333
|
+
const file = loadProjectCredentialsFile(env.projectRoot);
|
|
334
|
+
return Object.keys(file.environments);
|
|
335
|
+
}
|
|
336
|
+
//# sourceMappingURL=credentials-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials-store.js","sourceRoot":"","sources":["../../../src/lib/credentials-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,EACL,SAAS,EACT,UAAU,EACV,SAAS,EACT,YAAY,EACZ,UAAU,EACV,aAAa,GACd,MAAM,IAAI,CAAC;AACZ,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEjF,MAAM,CAAC,MAAM,iBAAiB,GAAG,YAAY,CAAC;AAC9C,MAAM,CAAC,MAAM,4BAA4B,GAAG,kBAAkB,CAAC;AAE/D;;;;GAIG;AACH,SAAS,kBAAkB;IACzB,OAAO,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,YAAY,CAAC,CAAC;AAC3E,CAAC;AAED,SAAS,wBAAwB;IAC/B,OAAO,IAAI,CAAC,kBAAkB,EAAE,EAAE,4BAA4B,CAAC,CAAC;AAClE,CA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AW;QACpC,YAAY,EAAE,WAAW,CAAC,YAAY;QACtC,SAAS,EAAE,WAAW,CAAC,SAAS;QAChC,OAAO,EAAE,WAAW,CAAC,OAAO;QAC5B,KAAK,EAAE,WAAW,CAAC,KAAK;QACxB,IAAI,EAAE,WAAW,CAAC,IAAI;QACtB,IAAI,EAAE,WAAW,CAAC,IAAI;QACtB,gBAAgB,EAAE,WAAW,CAAC,gBAAgB;KAC/C,CAAC;IACF,2BAA2B,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;AACjD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,6BAA6B;IAC3C,MAAM,GAAG,GAAG,yBAAyB,EAAE,CAAC;IACxC,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC;IACpB,MAAM,IAAI,GAAG,0BAA0B,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACzD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a CSV string into an array of row objects keyed by header.
|
|
3
|
+
*
|
|
4
|
+
* Quote-aware: respects double-quoted fields that may contain the delimiter,
|
|
5
|
+
* embedded newlines, and escaped double-quotes (`""`). Empty-string cells are
|
|
6
|
+
* omitted from the row object (matching the client). Headers-only / empty
|
|
7
|
+
* input yields `[]`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function parseCsv(csv: string, delimiter?: string): Record<string, string>[];
|
|
10
|
+
/**
|
|
11
|
+
* Coerce a string cell to a target type. Mirrors the client's `coerceValue`:
|
|
12
|
+
* a failed number coercion returns the original string (so the server's
|
|
13
|
+
* schema validation surfaces a precise error rather than a silent bad write).
|
|
14
|
+
*/
|
|
15
|
+
export declare function coerceValue(value: string, type: string): any;
|
|
16
|
+
/**
|
|
17
|
+
* Rename row keys per a `{ "CSV Header": "fieldName" }` map. Keys not present
|
|
18
|
+
* in the map are preserved. No-op when `map` is undefined.
|
|
19
|
+
*/
|
|
20
|
+
export declare function applyColumnMap(rows: Record<string, any>[], map: Record<string, string> | undefined): Record<string, any>[];
|
|
21
|
+
export interface BuildRowsOptions {
|
|
22
|
+
/** Model name passed in each batch item's params. */
|
|
23
|
+
modelName: string;
|
|
24
|
+
/** Type coercion overrides keyed by (post-column-map) field name. */
|
|
25
|
+
types?: Record<string, string>;
|
|
26
|
+
/** CSV column whose value to use as the record id (else a ULID is generated). */
|
|
27
|
+
idColumn?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface BatchItem {
|
|
30
|
+
params: {
|
|
31
|
+
modelName: string;
|
|
32
|
+
id: string;
|
|
33
|
+
data: Record<string, any>;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export interface BuildRowsResult {
|
|
37
|
+
batch: BatchItem[];
|
|
38
|
+
rowCount: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Apply type coercion, assign each row an id (from `idColumn` or a generated
|
|
42
|
+
* ULID), and shape rows into `executeBatch` items
|
|
43
|
+
* (`{ params: { modelName, id, data } }`). Mirrors steps 5–7 of the client's
|
|
44
|
+
* `importCsv`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function buildRows(rows: Record<string, any>[], options: BuildRowsOptions): BuildRowsResult;
|
|
47
|
+
export { chunk } from "./batch.js";
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSV parsing + value coercion for `primitive databases import-csv`.
|
|
3
|
+
*
|
|
4
|
+
* This is a **thin port** of the client library's reference implementation
|
|
5
|
+
* (`src/client/api/databasesApi.ts` `parseCsv` :21 / `coerceValue` :94) so the
|
|
6
|
+
* CLI's import semantics match the client's `importCsv` exactly. It is a
|
|
7
|
+
* conscious 4th copy of the parser (client, web-admin, sample helper, now CLI);
|
|
8
|
+
* the shared-core extraction (design Option C) is deferred. **Parser edge-case
|
|
9
|
+
* fixes must be replicated across all copies** — see the plan-of-record
|
|
10
|
+
* duplication note (#145 Codex finding (b)).
|
|
11
|
+
*
|
|
12
|
+
* Zero dependencies beyond `ulid` (already a repo dependency).
|
|
13
|
+
*/
|
|
14
|
+
import { ulid } from "ulid";
|
|
15
|
+
/**
|
|
16
|
+
* Parse a CSV string into an array of row objects keyed by header.
|
|
17
|
+
*
|
|
18
|
+
* Quote-aware: respects double-quoted fields that may contain the delimiter,
|
|
19
|
+
* embedded newlines, and escaped double-quotes (`""`). Empty-string cells are
|
|
20
|
+
* omitted from the row object (matching the client). Headers-only / empty
|
|
21
|
+
* input yields `[]`.
|
|
22
|
+
*/
|
|
23
|
+
export function parseCsv(csv, delimiter = ",") {
|
|
24
|
+
// Split into lines respecting quoted fields (which may contain newlines).
|
|
25
|
+
const lines = [];
|
|
26
|
+
let current = "";
|
|
27
|
+
let inQuotes = false;
|
|
28
|
+
for (let i = 0; i < csv.length; i++) {
|
|
29
|
+
const ch = csv[i];
|
|
30
|
+
if (ch === '"') {
|
|
31
|
+
if (inQuotes && i + 1 < csv.length && csv[i + 1] === '"') {
|
|
32
|
+
current += '"';
|
|
33
|
+
i++;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
inQuotes = !inQuotes;
|
|
37
|
+
}
|
|
38
|
+
current += ch;
|
|
39
|
+
}
|
|
40
|
+
else if ((ch === "\n" || ch === "\r") && !inQuotes) {
|
|
41
|
+
lines.push(current);
|
|
42
|
+
current = "";
|
|
43
|
+
if (ch === "\r" && i + 1 < csv.length && csv[i + 1] === "\n")
|
|
44
|
+
i++;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
current += ch;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (current.length > 0)
|
|
51
|
+
lines.push(current);
|
|
52
|
+
const result = [];
|
|
53
|
+
if (lines.length === 0)
|
|
54
|
+
return result;
|
|
55
|
+
const parseRow = (line) => {
|
|
56
|
+
const fields = [];
|
|
57
|
+
let field = "";
|
|
58
|
+
let q = false;
|
|
59
|
+
let wasQuoted = false;
|
|
60
|
+
for (let i = 0; i < line.length; i++) {
|
|
61
|
+
const ch = line[i];
|
|
62
|
+
if (ch === '"') {
|
|
63
|
+
if (q && i + 1 < line.length && line[i + 1] === '"') {
|
|
64
|
+
field += '"';
|
|
65
|
+
i++;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
q = !q;
|
|
69
|
+
if (q)
|
|
70
|
+
wasQuoted = true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else if (ch === delimiter && !q) {
|
|
74
|
+
fields.push(wasQuoted ? field : field.trim());
|
|
75
|
+
field = "";
|
|
76
|
+
wasQuoted = false;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
field += ch;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
fields.push(wasQuoted ? field : field.trim());
|
|
83
|
+
return fields;
|
|
84
|
+
};
|
|
85
|
+
const headers = parseRow(lines[0]);
|
|
86
|
+
for (let i = 1; i < lines.length; i++) {
|
|
87
|
+
const line = lines[i].trim();
|
|
88
|
+
if (!line)
|
|
89
|
+
continue;
|
|
90
|
+
const values = parseRow(line);
|
|
91
|
+
const row = {};
|
|
92
|
+
headers.forEach((h, idx) => {
|
|
93
|
+
if (values[idx] !== undefined && values[idx] !== "") {
|
|
94
|
+
row[h] = values[idx];
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
if (Object.keys(row).length > 0) {
|
|
98
|
+
result.push(row);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Coerce a string cell to a target type. Mirrors the client's `coerceValue`:
|
|
105
|
+
* a failed number coercion returns the original string (so the server's
|
|
106
|
+
* schema validation surfaces a precise error rather than a silent bad write).
|
|
107
|
+
*/
|
|
108
|
+
export function coerceValue(value, type) {
|
|
109
|
+
switch (type) {
|
|
110
|
+
case "number": {
|
|
111
|
+
const n = Number(value);
|
|
112
|
+
return isNaN(n) ? value : n;
|
|
113
|
+
}
|
|
114
|
+
case "boolean":
|
|
115
|
+
return value === "true" || value === "1" || value === "yes";
|
|
116
|
+
default:
|
|
117
|
+
return value;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Rename row keys per a `{ "CSV Header": "fieldName" }` map. Keys not present
|
|
122
|
+
* in the map are preserved. No-op when `map` is undefined.
|
|
123
|
+
*/
|
|
124
|
+
export function applyColumnMap(rows, map) {
|
|
125
|
+
if (!map)
|
|
126
|
+
return rows;
|
|
127
|
+
return rows.map((row) => {
|
|
128
|
+
const mapped = {};
|
|
129
|
+
for (const [key, value] of Object.entries(row)) {
|
|
130
|
+
const newKey = map[key] ?? key;
|
|
131
|
+
mapped[newKey] = value;
|
|
132
|
+
}
|
|
133
|
+
return mapped;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Apply type coercion, assign each row an id (from `idColumn` or a generated
|
|
138
|
+
* ULID), and shape rows into `executeBatch` items
|
|
139
|
+
* (`{ params: { modelName, id, data } }`). Mirrors steps 5–7 of the client's
|
|
140
|
+
* `importCsv`.
|
|
141
|
+
*/
|
|
142
|
+
export function buildRows(rows, options) {
|
|
143
|
+
const typeMap = options.types ?? {};
|
|
144
|
+
const batch = [];
|
|
145
|
+
for (const original of rows) {
|
|
146
|
+
const row = { ...original };
|
|
147
|
+
// Type coercion (only string cells, only declared types).
|
|
148
|
+
for (const [field, targetType] of Object.entries(typeMap)) {
|
|
149
|
+
if (field in row && typeof row[field] === "string") {
|
|
150
|
+
row[field] = coerceValue(row[field], targetType);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// Assign id.
|
|
154
|
+
let id;
|
|
155
|
+
if (options.idColumn && row[options.idColumn] != null) {
|
|
156
|
+
id = String(row[options.idColumn]);
|
|
157
|
+
}
|
|
158
|
+
else if (row.id != null) {
|
|
159
|
+
id = String(row.id);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
id = ulid();
|
|
163
|
+
}
|
|
164
|
+
row.id = id;
|
|
165
|
+
batch.push({ params: { modelName: options.modelName, id, data: row } });
|
|
166
|
+
}
|
|
167
|
+
return { batch, rowCount: batch.length };
|
|
168
|
+
}
|
|
169
|
+
// `chunk()` moved to ./batch.ts (shared with `databases import`). Re-exported
|
|
170
|
+
// here so existing `import { chunk } from "../lib/csv.js"` callers keep working.
|
|
171
|
+
export { chunk } from "./batch.js";
|
|
172
|
+
//# sourceMappingURL=csv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csv.js","sourceRoot":"","sources":["../../../src/lib/csv.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CACtB,GAAW,EACX,SAAS,GAAG,GAAG;IAEf,0EAA0E;IAC1E,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;QAClB,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YACf,IAAI,QAAQ,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;gBACzD,OAAO,IAAI,GAAG,CAAC;gBACf,CAAC,EAAE,CAAC;YACN,CAAC;iBAAM,CAAC;gBACN,QAAQ,GAAG,CAAC,QAAQ,CAAC;YACvB,CAAC;YACD,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;aAAM,IAAI,CAAC,EAAE,KAA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 -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse the `--data <json>` / `--data-file <path>` pair into a JSON object
|
|
3
|
+
* (#1969). Extracted from `commands/metadata.ts` so every write verb that takes
|
|
4
|
+
* a JSON body (metadata, database records save/patch, …) shares one
|
|
5
|
+
* resource-neutral parser and identical diagnostics.
|
|
6
|
+
*
|
|
7
|
+
* Exactly one of `--data` (inline JSON) or `--data-file` (a path to read) is
|
|
8
|
+
* expected; `--data-file` wins when both are given. On bad input — no value, an
|
|
9
|
+
* unreadable file, invalid JSON, or a non-object (array/scalar) — it prints a
|
|
10
|
+
* clear message and exits the process.
|
|
11
|
+
*
|
|
12
|
+
* @param label human-readable name of what is being provided, used in the "no
|
|
13
|
+
* value" message (e.g. "metadata object", "record"). Defaults to "data".
|
|
14
|
+
* @param opts `allowArray` also accepts a bare JSON array, for the surfaces
|
|
15
|
+
* whose payload is a list rather than an object (`documents records bulk`
|
|
16
|
+
* takes either `{ operations: [...] }` or a bare operations array).
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseDataOption(options: {
|
|
19
|
+
data?: string;
|
|
20
|
+
dataFile?: string;
|
|
21
|
+
}, label?: string, opts?: {
|
|
22
|
+
allowArray?: boolean;
|
|
23
|
+
}): Record<string, any>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { readFileSync } from "fs";
|
|
2
|
+
import { error } from "./output.js";
|
|
3
|
+
/**
|
|
4
|
+
* Parse the `--data <json>` / `--data-file <path>` pair into a JSON object
|
|
5
|
+
* (#1969). Extracted from `commands/metadata.ts` so every write verb that takes
|
|
6
|
+
* a JSON body (metadata, database records save/patch, …) shares one
|
|
7
|
+
* resource-neutral parser and identical diagnostics.
|
|
8
|
+
*
|
|
9
|
+
* Exactly one of `--data` (inline JSON) or `--data-file` (a path to read) is
|
|
10
|
+
* expected; `--data-file` wins when both are given. On bad input — no value, an
|
|
11
|
+
* unreadable file, invalid JSON, or a non-object (array/scalar) — it prints a
|
|
12
|
+
* clear message and exits the process.
|
|
13
|
+
*
|
|
14
|
+
* @param label human-readable name of what is being provided, used in the "no
|
|
15
|
+
* value" message (e.g. "metadata object", "record"). Defaults to "data".
|
|
16
|
+
* @param opts `allowArray` also accepts a bare JSON array, for the surfaces
|
|
17
|
+
* whose payload is a list rather than an object (`documents records bulk`
|
|
18
|
+
* takes either `{ operations: [...] }` or a bare operations array).
|
|
19
|
+
*/
|
|
20
|
+
export function parseDataOption(options, label = "data", opts = {}) {
|
|
21
|
+
let raw = options.data;
|
|
22
|
+
if (options.dataFile) {
|
|
23
|
+
try {
|
|
24
|
+
raw = readFileSync(options.dataFile, "utf-8");
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
error(`Could not read --data-file: ${err.message}`);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (!raw) {
|
|
32
|
+
error(`Provide the ${label} via --data '<json>' or --data-file <path>.`);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const parsed = JSON.parse(raw);
|
|
37
|
+
if (!parsed || typeof parsed !== "object") {
|
|
38
|
+
throw new Error("expected a JSON object");
|
|
39
|
+
}
|
|
40
|
+
if (Array.isArray(parsed) && !opts.allowArray) {
|
|
41
|
+
throw new Error("expected a JSON object");
|
|
42
|
+
}
|
|
43
|
+
return parsed;
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
error(`Invalid JSON for --data: ${err.message}`);
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=data-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-input.js","sourceRoot":"","sources":["../../../src/lib/data-input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC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
|
+
* Short fingerprint for a database-type TOML string (issue #814).
|
|
3
|
+
*
|
|
4
|
+
* Stamped in the header of every generated file so a human (or the
|
|
5
|
+
* `--check` CI guard) can tell at a glance whether the source TOML and the
|
|
6
|
+
* generated output are in sync. Mirrors codegen-v2's `fingerprintToml`
|
|
7
|
+
* (`packages/js-bao/src/cli/v2/fingerprint.ts`): 16 hex chars of SHA-256 —
|
|
8
|
+
* enough for a sanity check, short enough to fit on one comment line.
|
|
9
|
+
*/
|
|
10
|
+
export declare function fingerprintToml(tomlContent: string): string;
|