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,870 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The typed database handle's generated declarations — #3182 phase 4.
|
|
3
|
+
*
|
|
4
|
+
* The intent settles what the handle is before unified-schemas: "generated at
|
|
5
|
+
* push time from the database type's TOML schema (js-bao's
|
|
6
|
+
* `loadSchemaFromTomlString`; not the client's runtime Yjs discovery): model
|
|
7
|
+
* names and field types in phase 2". So this is a THIRD renderer over the same
|
|
8
|
+
* `describeDbType` IR the TypeScript and Swift client generators already share
|
|
9
|
+
* — not a second parser and not a second idea of what a model is. Inline
|
|
10
|
+
* filter typing waits for unified-schemas, as the intent says.
|
|
11
|
+
*
|
|
12
|
+
* ── Why these files, in `functions/` ─────────────────────────────────────
|
|
13
|
+
*
|
|
14
|
+
* A generated declaration nothing loads is decoration (D3182-006). Function
|
|
15
|
+
* sources live under an environment- and app-specific config-tree path, the
|
|
16
|
+
* CLI's esbuild step never typechecks, and a project's own `tsconfig.json`
|
|
17
|
+
* commonly includes only `src`. So `config push` writes, beside the sources it
|
|
18
|
+
* serves:
|
|
19
|
+
*
|
|
20
|
+
* - `primitive-db-types.d.ts` — the app's database types, and the module
|
|
21
|
+
* augmentation that binds them to `ctx.db`;
|
|
22
|
+
* - `primitive-functions.d.ts` — the SDK's own types. The package is not on
|
|
23
|
+
* npm yet, and even when it is, a config tree is not an npm project:
|
|
24
|
+
* without this the bare `primitive-functions` specifier every function
|
|
25
|
+
* imports would not resolve at all, and the augmentation would have
|
|
26
|
+
* nothing to augment;
|
|
27
|
+
* - `primitive-function-types.d.ts` (#3281, rendered by
|
|
28
|
+
* `function-schema-codegen.ts`) — every function's `<Key>Input` and
|
|
29
|
+
* `<Key>Output` from its declared schemas, and the `FunctionSchemas`
|
|
30
|
+
* augmentation that types `defineFunction("<key>", handler)`;
|
|
31
|
+
* - `primitive-document-types.d.ts` (#3281, rendered by
|
|
32
|
+
* `function-document-types.ts`) — the project's document models from
|
|
33
|
+
* `models/models.toml`, and the `DocumentSchemas` augmentation that types
|
|
34
|
+
* `ctx.doc(documentId).model("<Model>")`; open when the project has none;
|
|
35
|
+
* - `generated/<key>.generated.ts` (#3281, same renderer) — the per-key
|
|
36
|
+
* CLIENT invoker, carrying every verb since #3482. Excluded from
|
|
37
|
+
* the scaffolded program (it imports `js-bao-wss-client`), and written to
|
|
38
|
+
* `-o <dir>` instead when `functions codegen` is told so;
|
|
39
|
+
* - `tsconfig.json` — the wiring, so an editor and a bare `tsc` both see the
|
|
40
|
+
* declarations with nothing for an author to configure.
|
|
41
|
+
*
|
|
42
|
+
* The `.d.ts` files and the invokers are GENERATED and rewritten on every
|
|
43
|
+
* push; an invoker whose TOML is gone is removed with it. The tsconfig
|
|
44
|
+
* is SCAFFOLDED once and then left to its author, because it is the file an
|
|
45
|
+
* author has a legitimate reason to adjust — with one exception: the two facts
|
|
46
|
+
* that make the wiring work at all (the `primitive-functions` path mapping and
|
|
47
|
+
* the declarations being in the program) are repaired when they are missing,
|
|
48
|
+
* so a tsconfig written by hand, or scaffolded before the #3209 rename, does
|
|
49
|
+
* not leave push reporting success over a program no compiler can load
|
|
50
|
+
* (SO3182-004). Everything else in the file is left exactly as written.
|
|
51
|
+
*
|
|
52
|
+
* None of the three is part of the pushed envelope: they are regenerated, not
|
|
53
|
+
* round-tripped, and the bundler never sees them (types are erased, and the
|
|
54
|
+
* tsconfig is not a module).
|
|
55
|
+
*/
|
|
56
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync, } from "fs";
|
|
57
|
+
import { basename, dirname, join, relative, resolve, sep } from "path";
|
|
58
|
+
import { parseConfigToml } from "./config-toml.js";
|
|
59
|
+
import { FUNCTION_INVOKERS_DIR, FUNCTION_TYPES_DECLARATION_FILE, GENERATED_FILE_SUFFIX, functionSchemaSources, renderFunctionInvokers, renderFunctionSchemasDeclaration, } from "./function-schema-codegen.js";
|
|
60
|
+
import { DOCUMENT_TYPES_DECLARATION_FILE, DOCUMENT_SCHEMA_TREE_FILE, resolveDocumentSchema, renderDocumentTypesDeclaration, } from "./function-document-types.js";
|
|
61
|
+
import { AGENT_CLIENT_FILE_SUFFIX, PROMPT_TYPES_DECLARATION_FILE, promptSchemaSources, renderAgentClientFiles, renderPromptSchemasDeclaration, } from "./prompt-schema-codegen.js";
|
|
62
|
+
import { describeDbType } from "./db-codegen/dbTypeIR.js";
|
|
63
|
+
import { tsTypeForDbFieldType } from "./db-codegen/dbTsTypes.js";
|
|
64
|
+
import { objectPropertyKey } from "./db-codegen/dbNaming.js";
|
|
65
|
+
import { SDK_TYPES_SOURCE } from "./generated-sdk-types.js";
|
|
66
|
+
export const DB_TYPES_DECLARATION_FILE = "primitive-db-types.d.ts";
|
|
67
|
+
export const SDK_TYPES_FILE = "primitive-functions.d.ts";
|
|
68
|
+
export const FUNCTIONS_TSCONFIG_FILE = "tsconfig.json";
|
|
69
|
+
/**
|
|
70
|
+
* Every regenerated declaration a `functions/tsconfig.json` has to load, in
|
|
71
|
+
* the order the scaffold lists them (#3281, D3281-SO-004). The inspection
|
|
72
|
+
* requires each of these in an explicit `include`/`files` list — a tree that
|
|
73
|
+
* customized its list to name only the two #3182 wrote would otherwise
|
|
74
|
+
* generate the newer ones and never load them.
|
|
75
|
+
*/
|
|
76
|
+
export const REGENERATED_DECLARATIONS = [
|
|
77
|
+
DB_TYPES_DECLARATION_FILE,
|
|
78
|
+
SDK_TYPES_FILE,
|
|
79
|
+
FUNCTION_TYPES_DECLARATION_FILE,
|
|
80
|
+
DOCUMENT_TYPES_DECLARATION_FILE,
|
|
81
|
+
// #3330 — the prompt output types, from the tree's `prompts/*.toml`.
|
|
82
|
+
PROMPT_TYPES_DECLARATION_FILE,
|
|
83
|
+
];
|
|
84
|
+
/** The scaffold's exclusion for the client invokers (#3281). */
|
|
85
|
+
export const GENERATED_EXCLUDE = `${FUNCTION_INVOKERS_DIR}/**`;
|
|
86
|
+
const HEADER = `// GENERATED by \`primitive config push\` from database-type-configs/*.toml.
|
|
87
|
+
// DO NOT EDIT — your changes are overwritten on the next push.
|
|
88
|
+
//
|
|
89
|
+
// It gives \`ctx.db(databaseId, "<type>").model("<Model>")\` the model names and
|
|
90
|
+
// field types this app's database types declare. Inline filter typing arrives
|
|
91
|
+
// with unified schemas; until then a filter is an ordinary object.
|
|
92
|
+
//
|
|
93
|
+
// A row a READ hands back also carries \`id: string\` — the record identity the
|
|
94
|
+
// platform owns rather than the schema, added by the SDK's own row type, so it
|
|
95
|
+
// is not repeated per model here whether or not a model declares one.
|
|
96
|
+
`;
|
|
97
|
+
function quote(value) {
|
|
98
|
+
return JSON.stringify(value);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* A model or field name as a TYPE member key.
|
|
102
|
+
*
|
|
103
|
+
* Model and field names are whatever the TOML says — js-bao preserves them
|
|
104
|
+
* verbatim — so `Order-Item` and `first-name` are ordinary schemas and are not
|
|
105
|
+
* TypeScript identifiers. Emitting one raw makes the whole declaration a syntax
|
|
106
|
+
* error, which breaks the editor and `tsc` wiring for every OTHER type in the
|
|
107
|
+
* tree too. The client generators' own `objectPropertyKey` answers this,
|
|
108
|
+
* except that its `__proto__` case is a computed key — legal in an object
|
|
109
|
+
* literal, not in a type member — so that one is quoted instead.
|
|
110
|
+
*/
|
|
111
|
+
function memberKey(name) {
|
|
112
|
+
const key = objectPropertyKey(name);
|
|
113
|
+
return key.startsWith("[") ? quote(name) : key;
|
|
114
|
+
}
|
|
115
|
+
/** A TS string-literal union, or `string` when there is nothing to narrow to. */
|
|
116
|
+
function fieldType(type, enumValues) {
|
|
117
|
+
if (type === "string" && Array.isArray(enumValues) && enumValues.length > 0) {
|
|
118
|
+
return enumValues.map((v) => quote(v)).join(" | ");
|
|
119
|
+
}
|
|
120
|
+
return tsTypeForDbFieldType(type);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The declaration for a whole config tree's database types.
|
|
124
|
+
*
|
|
125
|
+
* Sorted by type and by model so the bytes depend on the SCHEMAS and not on
|
|
126
|
+
* the order the files were read in — push rewrites this on every run, and
|
|
127
|
+
* unstable output would be a permanent diff in a developer's repository.
|
|
128
|
+
*/
|
|
129
|
+
export function renderDbTypesDeclaration(sources) {
|
|
130
|
+
const types = [...sources].sort((a, b) => a.databaseType < b.databaseType ? -1 : a.databaseType > b.databaseType ? 1 : 0);
|
|
131
|
+
const lines = [HEADER, "export interface PrimitiveDatabaseSchemas {"];
|
|
132
|
+
for (const source of types) {
|
|
133
|
+
let records = [];
|
|
134
|
+
try {
|
|
135
|
+
const ir = describeDbType({
|
|
136
|
+
databaseType: source.databaseType,
|
|
137
|
+
tomlPath: source.tomlPath,
|
|
138
|
+
tomlContent: source.tomlContent,
|
|
139
|
+
});
|
|
140
|
+
records = [...ir.records]
|
|
141
|
+
.sort((a, b) => (a.modelName < b.modelName ? -1 : 1))
|
|
142
|
+
.map((record) => {
|
|
143
|
+
const declared = new Set();
|
|
144
|
+
const members = [];
|
|
145
|
+
for (const field of record.fields) {
|
|
146
|
+
declared.add(field.name);
|
|
147
|
+
members.push(` ${memberKey(field.name)}${field.required ? "" : "?"}: ${fieldType(field.type, field.enum)};`);
|
|
148
|
+
}
|
|
149
|
+
// Server-stamped fields exist on a read row but not on one a
|
|
150
|
+
// function just built, so they are optional — the same call the
|
|
151
|
+
// client renderer makes.
|
|
152
|
+
for (const stamped of [...ir.stampedFields].sort()) {
|
|
153
|
+
if (declared.has(stamped))
|
|
154
|
+
continue;
|
|
155
|
+
declared.add(stamped);
|
|
156
|
+
members.push(` ${memberKey(stamped)}?: string;`);
|
|
157
|
+
}
|
|
158
|
+
return { modelName: record.modelName, members };
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
// A type whose TOML this renderer cannot describe contributes no models
|
|
163
|
+
// rather than failing the push: its own preflight reports the file, and
|
|
164
|
+
// an untyped handle is what a schemaless type gets anyway.
|
|
165
|
+
records = [];
|
|
166
|
+
}
|
|
167
|
+
if (records.length === 0) {
|
|
168
|
+
lines.push(` ${quote(source.databaseType)}: {};`);
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
lines.push(` ${quote(source.databaseType)}: {`);
|
|
172
|
+
for (const record of records) {
|
|
173
|
+
if (record.members.length === 0) {
|
|
174
|
+
lines.push(` ${memberKey(record.modelName)}: Record<string, unknown>;`);
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
lines.push(` ${memberKey(record.modelName)}: {`);
|
|
178
|
+
lines.push(...record.members);
|
|
179
|
+
lines.push(` };`);
|
|
180
|
+
}
|
|
181
|
+
lines.push(` };`);
|
|
182
|
+
}
|
|
183
|
+
lines.push("}");
|
|
184
|
+
lines.push("");
|
|
185
|
+
// The augmentation. Only emitted when there is something to bind: an empty
|
|
186
|
+
// one would claim the app has no database types, and `ctx.db` would stop
|
|
187
|
+
// accepting any type key at all rather than staying open.
|
|
188
|
+
if (types.length > 0) {
|
|
189
|
+
lines.push(`declare module "primitive-functions" {`);
|
|
190
|
+
lines.push(` interface DatabaseSchemas extends PrimitiveDatabaseSchemas {}`);
|
|
191
|
+
lines.push(`}`);
|
|
192
|
+
lines.push("");
|
|
193
|
+
}
|
|
194
|
+
return lines.join("\n");
|
|
195
|
+
}
|
|
196
|
+
/** The scaffolded compiler wiring. Written once; an author owns it after. */
|
|
197
|
+
export function renderFunctionsTsconfig() {
|
|
198
|
+
return (JSON.stringify({
|
|
199
|
+
// Scaffolded by `primitive config push` (#3182). Yours to adjust — push
|
|
200
|
+
// writes it once and then leaves it alone. What it must keep doing is
|
|
201
|
+
// pointing `primitive-functions` at the generated declaration beside
|
|
202
|
+
// it, so
|
|
203
|
+
// your editor and `tsc` type your functions with no other setup.
|
|
204
|
+
compilerOptions: {
|
|
205
|
+
target: "ES2022",
|
|
206
|
+
module: "ESNext",
|
|
207
|
+
moduleResolution: "Bundler",
|
|
208
|
+
// A function runs in a Worker, so the globals it may use are the
|
|
209
|
+
// worker ones: `fetch`, `Response`, `URL`, `crypto`, `console`, the
|
|
210
|
+
// timers. `ES2022` alone typechecks the language and none of the
|
|
211
|
+
// runtime, so ordinary deployed code reports "Cannot find name
|
|
212
|
+
// 'fetch'" — which reads as broken types and is fixed by editing
|
|
213
|
+
// this file, the one thing the scaffold exists to avoid
|
|
214
|
+
// (F3182-003).
|
|
215
|
+
lib: ["ES2022", "WebWorker"],
|
|
216
|
+
strict: true,
|
|
217
|
+
noEmit: true,
|
|
218
|
+
skipLibCheck: true,
|
|
219
|
+
types: [],
|
|
220
|
+
paths: {
|
|
221
|
+
"primitive-functions": [`./${SDK_TYPES_FILE}`],
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
include: ["**/*.ts", ...REGENERATED_DECLARATIONS.map((file) => `./${file}`)],
|
|
225
|
+
// The client invokers (#3281) import `js-bao-wss-client`, which a
|
|
226
|
+
// config tree does not install: they are for the app's client code,
|
|
227
|
+
// and an editor program that swept them in would report every one of
|
|
228
|
+
// them as a broken import.
|
|
229
|
+
exclude: [GENERATED_EXCLUDE],
|
|
230
|
+
}, null, 2) + "\n");
|
|
231
|
+
}
|
|
232
|
+
/** The bare specifier every function imports, and the tsconfig must resolve. */
|
|
233
|
+
export const SDK_MODULE_SPECIFIER = "primitive-functions";
|
|
234
|
+
/** The include entry that covers every source AND both declarations. */
|
|
235
|
+
const SOURCES_INCLUDE = "**/*.ts";
|
|
236
|
+
/**
|
|
237
|
+
* A tsconfig's contents with `//` and block comments blanked out.
|
|
238
|
+
*
|
|
239
|
+
* A tsconfig is JSONC — comments are legal and common — and the difference
|
|
240
|
+
* matters twice: push must not reformat a commented file out from under its
|
|
241
|
+
* author, and it must still be able to READ one well enough to say whether the
|
|
242
|
+
* typed handle will load. Blanking rather than deleting keeps the text length
|
|
243
|
+
* (and so any offsets) intact; only `JSON.parse` ever sees the result.
|
|
244
|
+
*/
|
|
245
|
+
function stripJsonComments(text) {
|
|
246
|
+
let out = "";
|
|
247
|
+
let inString = false;
|
|
248
|
+
let escaped = false;
|
|
249
|
+
let inLine = false;
|
|
250
|
+
let inBlock = false;
|
|
251
|
+
for (let i = 0; i < text.length; i++) {
|
|
252
|
+
const ch = text[i];
|
|
253
|
+
const next = text[i + 1];
|
|
254
|
+
if (inLine) {
|
|
255
|
+
if (ch === "\n") {
|
|
256
|
+
inLine = false;
|
|
257
|
+
out += ch;
|
|
258
|
+
}
|
|
259
|
+
else
|
|
260
|
+
out += " ";
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
if (inBlock) {
|
|
264
|
+
if (ch === "*" && next === "/") {
|
|
265
|
+
inBlock = false;
|
|
266
|
+
out += " ";
|
|
267
|
+
i++;
|
|
268
|
+
}
|
|
269
|
+
else
|
|
270
|
+
out += ch === "\n" ? ch : " ";
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
if (inString) {
|
|
274
|
+
out += ch;
|
|
275
|
+
if (escaped)
|
|
276
|
+
escaped = false;
|
|
277
|
+
else if (ch === "\\")
|
|
278
|
+
escaped = true;
|
|
279
|
+
else if (ch === '"')
|
|
280
|
+
inString = false;
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
if (ch === '"') {
|
|
284
|
+
inString = true;
|
|
285
|
+
out += ch;
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (ch === "/" && next === "/") {
|
|
289
|
+
inLine = true;
|
|
290
|
+
out += " ";
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
if (ch === "/" && next === "*") {
|
|
294
|
+
inBlock = true;
|
|
295
|
+
out += " ";
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
out += ch;
|
|
299
|
+
}
|
|
300
|
+
return out;
|
|
301
|
+
}
|
|
302
|
+
function isGlobEntry(entry) {
|
|
303
|
+
return typeof entry === "string" && entry.includes("*");
|
|
304
|
+
}
|
|
305
|
+
function isDeclarationEntry(entry, file) {
|
|
306
|
+
return entry === `./${file}` || entry === file;
|
|
307
|
+
}
|
|
308
|
+
/** `"./**\/*.ts"` and `"**\/*.ts"` name the same set; read them the same way. */
|
|
309
|
+
function normalizeEntry(entry) {
|
|
310
|
+
return entry.startsWith("./") ? entry.slice(2) : entry;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Does this `include` entry cover a `.ts` file sitting BESIDE the tsconfig —
|
|
314
|
+
* which is where every regenerated declaration goes?
|
|
315
|
+
*
|
|
316
|
+
* TypeScript matches a `.d.ts` file with a `*.ts` pattern, and both the
|
|
317
|
+
* top-level `"*.ts"` and the recursive `"**\/*.ts"` reach the directory's own
|
|
318
|
+
* files. Recognizing only the scaffold's literal `"**\/*.ts"` reported an
|
|
319
|
+
* author's equivalent glob as missing every declaration (CR3281-003).
|
|
320
|
+
*/
|
|
321
|
+
function coversDeclarations(entry) {
|
|
322
|
+
if (typeof entry !== "string")
|
|
323
|
+
return false;
|
|
324
|
+
const normalized = normalizeEntry(entry);
|
|
325
|
+
if (normalized === "**")
|
|
326
|
+
return true;
|
|
327
|
+
const slash = normalized.lastIndexOf("/");
|
|
328
|
+
const dir = slash < 0 ? "" : normalized.slice(0, slash + 1);
|
|
329
|
+
if (dir !== "" && dir !== "**/")
|
|
330
|
+
return false;
|
|
331
|
+
const leaf = normalized.slice(slash + 1);
|
|
332
|
+
return leaf === "*" || leaf === "*.ts" || leaf === "*.d.ts";
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Does this `include` entry reach BELOW the tsconfig's own directory — and so
|
|
336
|
+
* sweep the generated client invokers into the program?
|
|
337
|
+
*
|
|
338
|
+
* Any `**` segment does, as does an entry that names the generated directory
|
|
339
|
+
* itself. A top-level `"*.ts"` does not, which is why this is a separate
|
|
340
|
+
* question from {@link coversDeclarations} (CR3281-003).
|
|
341
|
+
*/
|
|
342
|
+
function coversSubdirectories(entry) {
|
|
343
|
+
if (typeof entry !== "string")
|
|
344
|
+
return false;
|
|
345
|
+
const normalized = normalizeEntry(entry);
|
|
346
|
+
return (normalized === "**" ||
|
|
347
|
+
normalized.startsWith("**/") ||
|
|
348
|
+
normalized.includes("/**") ||
|
|
349
|
+
normalized.startsWith(`${FUNCTION_INVOKERS_DIR}/`));
|
|
350
|
+
}
|
|
351
|
+
function isSourceEntry(entry) {
|
|
352
|
+
if (typeof entry !== "string")
|
|
353
|
+
return false;
|
|
354
|
+
if (REGENERATED_DECLARATIONS.some((file) => isDeclarationEntry(entry, file))) {
|
|
355
|
+
return false;
|
|
356
|
+
}
|
|
357
|
+
return isGlobEntry(entry) || entry.endsWith(".ts");
|
|
358
|
+
}
|
|
359
|
+
/** Does an `exclude` list keep `generated/` out of the program? */
|
|
360
|
+
function excludesGenerated(exclude) {
|
|
361
|
+
// Any entry rooted at the directory keeps it out — `generated`,
|
|
362
|
+
// `generated/`, `generated/**` and `generated/**/*` all do — so an author's
|
|
363
|
+
// own spelling is honoured rather than repaired into a duplicate.
|
|
364
|
+
return exclude.some((entry) => {
|
|
365
|
+
if (typeof entry !== "string")
|
|
366
|
+
return false;
|
|
367
|
+
const normalized = normalizeEntry(entry);
|
|
368
|
+
return (normalized === FUNCTION_INVOKERS_DIR ||
|
|
369
|
+
normalized.startsWith(`${FUNCTION_INVOKERS_DIR}/`));
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* The gaps in an already-parsed tsconfig object.
|
|
374
|
+
*
|
|
375
|
+
* Three separate facts, because two of them used to be one: a config that
|
|
376
|
+
* listed the two declarations and nothing else counted as "covered" while no
|
|
377
|
+
* function source was in the program at all, so `tsc` typechecked the
|
|
378
|
+
* declarations against themselves and push reported success (CR3182-003).
|
|
379
|
+
*/
|
|
380
|
+
function tsconfigWiringGaps(parsed, context) {
|
|
381
|
+
const compilerOptions = parsed.compilerOptions && typeof parsed.compilerOptions === "object"
|
|
382
|
+
? parsed.compilerOptions
|
|
383
|
+
: {};
|
|
384
|
+
const paths = compilerOptions.paths && typeof compilerOptions.paths === "object"
|
|
385
|
+
? compilerOptions.paths
|
|
386
|
+
: {};
|
|
387
|
+
const mapped = Array.isArray(paths[SDK_MODULE_SPECIFIER])
|
|
388
|
+
? paths[SDK_MODULE_SPECIFIER]
|
|
389
|
+
: [];
|
|
390
|
+
const include = Array.isArray(parsed.include) ? parsed.include : [];
|
|
391
|
+
const files = Array.isArray(parsed.files) ? parsed.files : [];
|
|
392
|
+
// With neither `include` nor `files`, TypeScript takes every file under the
|
|
393
|
+
// directory — sources and declarations alike — so there is nothing to add.
|
|
394
|
+
const implicitlyAll = parsed.include === undefined && parsed.files === undefined;
|
|
395
|
+
const listed = [...include, ...files];
|
|
396
|
+
// Two separate questions, because an author's glob can answer them
|
|
397
|
+
// differently: `"*.ts"` covers the declarations without reaching
|
|
398
|
+
// `generated/`, and `"generated/**"` the reverse (CR3281-003).
|
|
399
|
+
const declarationsCovered = listed.some(coversDeclarations);
|
|
400
|
+
const reachesSubdirectories = listed.some(coversSubdirectories);
|
|
401
|
+
const exclude = Array.isArray(parsed.exclude) ? parsed.exclude : [];
|
|
402
|
+
return {
|
|
403
|
+
mapping: !mapped.includes(`./${SDK_TYPES_FILE}`),
|
|
404
|
+
missingDeclarations: implicitlyAll || declarationsCovered
|
|
405
|
+
? []
|
|
406
|
+
: REGENERATED_DECLARATIONS.filter((file) => !listed.some((entry) => isDeclarationEntry(entry, file))),
|
|
407
|
+
sources: !implicitlyAll && !declarationsCovered && !listed.some(isSourceEntry),
|
|
408
|
+
// Only a program that would SEE the directory needs the exclusion: an
|
|
409
|
+
// explicit list that reaches no subdirectory never sweeps it in.
|
|
410
|
+
generatedExclusion: context.generatedDirExists &&
|
|
411
|
+
(implicitlyAll || reachesSubdirectories) &&
|
|
412
|
+
!excludesGenerated(exclude),
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
function hasGaps(gaps) {
|
|
416
|
+
return (gaps.mapping || gaps.missingDeclarations.length > 0 || gaps.sources || gaps.generatedExclusion);
|
|
417
|
+
}
|
|
418
|
+
function describeGaps(gaps) {
|
|
419
|
+
const problems = [];
|
|
420
|
+
if (gaps.mapping) {
|
|
421
|
+
problems.push(`\`compilerOptions.paths\` does not map "${SDK_MODULE_SPECIFIER}" to ` +
|
|
422
|
+
`"./${SDK_TYPES_FILE}", so a function's import of the SDK does not resolve`);
|
|
423
|
+
}
|
|
424
|
+
if (gaps.missingDeclarations.length > 0) {
|
|
425
|
+
problems.push(`\`include\` does not cover ${gaps.missingDeclarations
|
|
426
|
+
.map((file) => `"./${file}"`)
|
|
427
|
+
.join(", ")}, so the generated augmentation(s) there are never loaded`);
|
|
428
|
+
}
|
|
429
|
+
if (gaps.sources) {
|
|
430
|
+
problems.push("`include` covers no function source, so `tsc` typechecks none of them");
|
|
431
|
+
}
|
|
432
|
+
if (gaps.generatedExclusion) {
|
|
433
|
+
problems.push(`\`exclude\` does not cover "${GENERATED_EXCLUDE}", so the generated client ` +
|
|
434
|
+
"invokers (which import `js-bao-wss-client`) are swept into the program");
|
|
435
|
+
}
|
|
436
|
+
return problems;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Whether an existing tsconfig still carries the wiring the handle needs — the
|
|
440
|
+
* repaired document when push can fix it, and the problems when it cannot.
|
|
441
|
+
*
|
|
442
|
+
* The scaffold is written once and then belongs to its author, but "belongs to
|
|
443
|
+
* its author" cannot mean "silently stops working": a tree scaffolded before
|
|
444
|
+
* the `primitive-functions` rename (#3209) points at a declaration push no
|
|
445
|
+
* longer writes, and a tsconfig an author wrote by hand never had the wiring at
|
|
446
|
+
* all. Either way push claims success while no compiler can load the
|
|
447
|
+
* augmentation (SO3182-004).
|
|
448
|
+
*
|
|
449
|
+
* So the three REQUIRED facts — the module path mapping, the declarations being
|
|
450
|
+
* in the program, and the SOURCES being in the program — are repaired in a
|
|
451
|
+
* plain-JSON file, and everything else in it is left exactly as written. The
|
|
452
|
+
* mapping is APPENDED to any the author already has, so a deliberate mapping
|
|
453
|
+
* still wins and ours is only the fallback.
|
|
454
|
+
*
|
|
455
|
+
* A JSONC file (comments are legal in a tsconfig) is never rewritten —
|
|
456
|
+
* reformatting an author's file is worse than leaving it — but it IS read, and
|
|
457
|
+
* anything missing is reported instead of passing in silence (CR3182-003).
|
|
458
|
+
*/
|
|
459
|
+
export function inspectFunctionsTsconfig(existing, context = { generatedDirExists: false }) {
|
|
460
|
+
if (existing === null) {
|
|
461
|
+
return { repaired: renderFunctionsTsconfig(), problems: [] };
|
|
462
|
+
}
|
|
463
|
+
let parsed;
|
|
464
|
+
let plainJson = true;
|
|
465
|
+
try {
|
|
466
|
+
parsed = JSON.parse(existing);
|
|
467
|
+
}
|
|
468
|
+
catch {
|
|
469
|
+
plainJson = false;
|
|
470
|
+
try {
|
|
471
|
+
parsed = JSON.parse(stripJsonComments(existing));
|
|
472
|
+
}
|
|
473
|
+
catch {
|
|
474
|
+
return {
|
|
475
|
+
repaired: null,
|
|
476
|
+
problems: [
|
|
477
|
+
"it is not valid JSON or JSONC, so neither push nor a compiler can " +
|
|
478
|
+
"read it — fix the syntax, or delete it and let push scaffold a new one",
|
|
479
|
+
],
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
484
|
+
return {
|
|
485
|
+
repaired: null,
|
|
486
|
+
problems: ["it is not a JSON object, so it configures no compiler"],
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
const gaps = tsconfigWiringGaps(parsed, context);
|
|
490
|
+
if (!hasGaps(gaps)) {
|
|
491
|
+
return { repaired: null, problems: [] };
|
|
492
|
+
}
|
|
493
|
+
if (!plainJson) {
|
|
494
|
+
// Comments are the author's; repairing would strip them. Say what is
|
|
495
|
+
// missing instead of reporting success over a program that cannot load the
|
|
496
|
+
// handle.
|
|
497
|
+
return { repaired: null, problems: describeGaps(gaps) };
|
|
498
|
+
}
|
|
499
|
+
const compilerOptions = parsed.compilerOptions && typeof parsed.compilerOptions === "object"
|
|
500
|
+
? parsed.compilerOptions
|
|
501
|
+
: (parsed.compilerOptions = {});
|
|
502
|
+
const paths = compilerOptions.paths && typeof compilerOptions.paths === "object"
|
|
503
|
+
? compilerOptions.paths
|
|
504
|
+
: (compilerOptions.paths = {});
|
|
505
|
+
if (gaps.mapping) {
|
|
506
|
+
const mapped = Array.isArray(paths[SDK_MODULE_SPECIFIER])
|
|
507
|
+
? paths[SDK_MODULE_SPECIFIER]
|
|
508
|
+
: [];
|
|
509
|
+
paths[SDK_MODULE_SPECIFIER] = [...mapped, `./${SDK_TYPES_FILE}`];
|
|
510
|
+
}
|
|
511
|
+
if (gaps.missingDeclarations.length > 0 || gaps.sources) {
|
|
512
|
+
const include = Array.isArray(parsed.include) ? parsed.include : [];
|
|
513
|
+
const added = [];
|
|
514
|
+
// The sources come back through the same wildcard the scaffold uses, which
|
|
515
|
+
// covers the declarations too — so it is added first and the explicit
|
|
516
|
+
// declaration entries only when it is not. Only the MISSING declarations
|
|
517
|
+
// are added, beside the ones the author already named (#3281).
|
|
518
|
+
if (gaps.sources)
|
|
519
|
+
added.push(SOURCES_INCLUDE);
|
|
520
|
+
else
|
|
521
|
+
added.push(...gaps.missingDeclarations.map((file) => `./${file}`));
|
|
522
|
+
parsed.include = [...include, ...added];
|
|
523
|
+
}
|
|
524
|
+
if (gaps.generatedExclusion ||
|
|
525
|
+
// The wildcard just added sweeps `generated/` in too.
|
|
526
|
+
(gaps.sources && context.generatedDirExists && !excludesGenerated(parsed.exclude ?? []))) {
|
|
527
|
+
const exclude = Array.isArray(parsed.exclude) ? parsed.exclude : [];
|
|
528
|
+
parsed.exclude = [...exclude, GENERATED_EXCLUDE];
|
|
529
|
+
}
|
|
530
|
+
return { repaired: JSON.stringify(parsed, null, 2) + "\n", problems: [] };
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* The repaired document alone, or null to leave the file alone.
|
|
534
|
+
*
|
|
535
|
+
* Kept as the narrow answer `planFunctionTypeArtifacts` needs; the problems a
|
|
536
|
+
* repair cannot cover travel through `inspectFunctionsTsconfig`.
|
|
537
|
+
*/
|
|
538
|
+
export function reconcileFunctionsTsconfig(existing, context = { generatedDirExists: false }) {
|
|
539
|
+
return inspectFunctionsTsconfig(existing, context).repaired;
|
|
540
|
+
}
|
|
541
|
+
/** The invoker directory a plan writes to, absolute. */
|
|
542
|
+
export function functionInvokerDir(configDir, options = {}) {
|
|
543
|
+
return options.invokerDir
|
|
544
|
+
? resolve(options.invokerDir)
|
|
545
|
+
: join(configDir, "functions", FUNCTION_INVOKERS_DIR);
|
|
546
|
+
}
|
|
547
|
+
/** A path as the plan reports it: tree-relative POSIX when inside the tree. */
|
|
548
|
+
function reportedPath(configDir, absolute) {
|
|
549
|
+
const rel = relative(resolve(configDir), absolute);
|
|
550
|
+
if (rel && !rel.startsWith(".."))
|
|
551
|
+
return rel.split(sep).join("/");
|
|
552
|
+
return absolute;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Every database-type TOML in the tree, read once.
|
|
556
|
+
*
|
|
557
|
+
* The type KEY is the one push and the grant preflight use — `[type]
|
|
558
|
+
* databaseType` when the file declares it, the file name only as the fallback.
|
|
559
|
+
* Taking the file name unconditionally would type the handle under a key the
|
|
560
|
+
* platform never hears about, so `ctx.db(id, "<declared-type>")` — the key the
|
|
561
|
+
* grant names — would not compile while a wrong one would (SO3182-003).
|
|
562
|
+
*
|
|
563
|
+
* Every `.toml` here is a database type. The generated document-schema copy is
|
|
564
|
+
* a rule about `functions/`, so it is not filtered out here (CR3455-003): a
|
|
565
|
+
* type that happens to share its base name is this directory's own business.
|
|
566
|
+
*/
|
|
567
|
+
export function databaseTypeSources(configDir) {
|
|
568
|
+
const dir = join(configDir, "database-type-configs");
|
|
569
|
+
if (!existsSync(dir))
|
|
570
|
+
return [];
|
|
571
|
+
const sources = [];
|
|
572
|
+
for (const file of readdirSync(dir).filter((f) => f.endsWith(".toml"))) {
|
|
573
|
+
const tomlPath = join(dir, file);
|
|
574
|
+
let tomlContent;
|
|
575
|
+
try {
|
|
576
|
+
tomlContent = readFileSync(tomlPath, "utf-8");
|
|
577
|
+
}
|
|
578
|
+
catch {
|
|
579
|
+
continue;
|
|
580
|
+
}
|
|
581
|
+
let declared = null;
|
|
582
|
+
try {
|
|
583
|
+
const parsed = parseConfigToml(tomlContent);
|
|
584
|
+
if (parsed?.type?.databaseType)
|
|
585
|
+
declared = String(parsed.type.databaseType);
|
|
586
|
+
}
|
|
587
|
+
catch {
|
|
588
|
+
// A file that does not parse is reported by its own preflight; the
|
|
589
|
+
// renderer falls back to the name push would fall back to.
|
|
590
|
+
}
|
|
591
|
+
sources.push({
|
|
592
|
+
databaseType: declared || basename(file, ".toml"),
|
|
593
|
+
tomlPath,
|
|
594
|
+
tomlContent,
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
return sources;
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Whether the tree has a `functions/` directory of its own — one holding
|
|
601
|
+
* anything besides the `generated/` directory codegen itself writes.
|
|
602
|
+
*
|
|
603
|
+
* #3798, DSO-3798-005 — a tree whose only generated output is an agent's
|
|
604
|
+
* client artifact gets `functions/generated/` created FOR it; that directory
|
|
605
|
+
* must not then count as function sources to serve, or the next run would
|
|
606
|
+
* start writing declarations and a tsconfig for functions that do not exist.
|
|
607
|
+
*/
|
|
608
|
+
export function treeHasFunctionsDir(configDir) {
|
|
609
|
+
const functionsDir = join(configDir, "functions");
|
|
610
|
+
if (!existsSync(functionsDir))
|
|
611
|
+
return false;
|
|
612
|
+
// An EMPTY `functions/` is the author's own and keeps its meaning; only one
|
|
613
|
+
// holding nothing but `generated/` is codegen's.
|
|
614
|
+
const entries = readdirSync(functionsDir);
|
|
615
|
+
return entries.length === 0 || entries.some((entry) => entry !== FUNCTION_INVOKERS_DIR);
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* The client-side artifact of every agent prompt in the tree (#3798), where
|
|
619
|
+
* the invokers go.
|
|
620
|
+
*/
|
|
621
|
+
function planAgentClientArtifacts(configDir, options) {
|
|
622
|
+
const dir = functionInvokerDir(configDir, options);
|
|
623
|
+
return renderAgentClientFiles(promptSchemaSources(configDir)).map((file) => {
|
|
624
|
+
const absolute = join(dir, file.fileName);
|
|
625
|
+
return {
|
|
626
|
+
relative: reportedPath(configDir, absolute),
|
|
627
|
+
absolute,
|
|
628
|
+
contents: file.content,
|
|
629
|
+
regenerated: true,
|
|
630
|
+
};
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* What push would write, without writing it.
|
|
635
|
+
*
|
|
636
|
+
* Only the agents' client artifacts when the tree has no `functions/`
|
|
637
|
+
* directory (#3798, DSO-3798-005), and nothing at all when it has neither:
|
|
638
|
+
* the other artifacts exist to type function sources, and a tree with none
|
|
639
|
+
* needs no compiler wiring.
|
|
640
|
+
*/
|
|
641
|
+
export function planFunctionTypeArtifacts(configDir, sdkTypes, options = {}) {
|
|
642
|
+
const functionsDir = join(configDir, "functions");
|
|
643
|
+
const agentArtifacts = planAgentClientArtifacts(configDir, options);
|
|
644
|
+
if (!treeHasFunctionsDir(configDir))
|
|
645
|
+
return agentArtifacts;
|
|
646
|
+
// #3455 — one resolution for both the declaration below and the tree copy.
|
|
647
|
+
const documentSchema = resolveDocumentSchema(configDir);
|
|
648
|
+
const declaration = renderDbTypesDeclaration(databaseTypeSources(configDir));
|
|
649
|
+
// #3281 — the functions declaration and the per-key invokers, from the same
|
|
650
|
+
// `functions/*.toml`. A malformed schema throws naming the file: the honest
|
|
651
|
+
// `unknown` is for an absent schema, and typing a broken one as anything
|
|
652
|
+
// would be a declaration that lies.
|
|
653
|
+
const functionSources = functionSchemaSources(configDir);
|
|
654
|
+
const functionsDeclaration = renderFunctionSchemasDeclaration(functionSources);
|
|
655
|
+
const invokerDir = functionInvokerDir(configDir, options);
|
|
656
|
+
const invokers = renderFunctionInvokers(functionSources);
|
|
657
|
+
const artifacts = [
|
|
658
|
+
{
|
|
659
|
+
relative: `functions/${DB_TYPES_DECLARATION_FILE}`,
|
|
660
|
+
absolute: join(functionsDir, DB_TYPES_DECLARATION_FILE),
|
|
661
|
+
contents: declaration,
|
|
662
|
+
regenerated: true,
|
|
663
|
+
},
|
|
664
|
+
{
|
|
665
|
+
relative: `functions/${SDK_TYPES_FILE}`,
|
|
666
|
+
absolute: join(functionsDir, SDK_TYPES_FILE),
|
|
667
|
+
contents: sdkTypes ?? loadSdkTypes(),
|
|
668
|
+
regenerated: true,
|
|
669
|
+
},
|
|
670
|
+
{
|
|
671
|
+
relative: `functions/${FUNCTION_TYPES_DECLARATION_FILE}`,
|
|
672
|
+
absolute: join(functionsDir, FUNCTION_TYPES_DECLARATION_FILE),
|
|
673
|
+
contents: functionsDeclaration,
|
|
674
|
+
regenerated: true,
|
|
675
|
+
},
|
|
676
|
+
// #3281 — the document handle's declaration, from the project's
|
|
677
|
+
// `models/models.toml` (open when the project has none).
|
|
678
|
+
//
|
|
679
|
+
// #3455 (D3455-009) — through the SAME resolution push and diff use, so a
|
|
680
|
+
// tree pulled into a project with no `models/models.toml` is typed from
|
|
681
|
+
// the schema its active version was pushed with rather than losing its
|
|
682
|
+
// types the moment it is pulled.
|
|
683
|
+
{
|
|
684
|
+
relative: `functions/${DOCUMENT_TYPES_DECLARATION_FILE}`,
|
|
685
|
+
absolute: join(functionsDir, DOCUMENT_TYPES_DECLARATION_FILE),
|
|
686
|
+
contents: renderDocumentTypesDeclaration(documentSchema.declarationSource),
|
|
687
|
+
regenerated: true,
|
|
688
|
+
},
|
|
689
|
+
// #3330 — `ctx.prompts.run`'s output types, from this tree's
|
|
690
|
+
// `prompts/*.toml` (open when the tree declares none).
|
|
691
|
+
{
|
|
692
|
+
relative: `functions/${PROMPT_TYPES_DECLARATION_FILE}`,
|
|
693
|
+
absolute: join(functionsDir, PROMPT_TYPES_DECLARATION_FILE),
|
|
694
|
+
contents: renderPromptSchemasDeclaration(promptSchemaSources(configDir)),
|
|
695
|
+
regenerated: true,
|
|
696
|
+
},
|
|
697
|
+
// #3455 (D3455-009) — the project's document schema, copied into the tree
|
|
698
|
+
// so a fresh `config pull` into a project that has no `models/models.toml`
|
|
699
|
+
// still rebuilds the same envelope and reads Synced.
|
|
700
|
+
//
|
|
701
|
+
// Regenerated from the PROJECT file whenever there is one, and otherwise
|
|
702
|
+
// left exactly alone: when the copy is itself what the resolution answered
|
|
703
|
+
// (rule 2) it IS the source, and rewriting a file from itself would be the
|
|
704
|
+
// second source of truth the fixed precedence exists to avoid.
|
|
705
|
+
...(documentSchema.origin === "project" && documentSchema.source
|
|
706
|
+
? [
|
|
707
|
+
{
|
|
708
|
+
relative: `functions/${DOCUMENT_SCHEMA_TREE_FILE}`,
|
|
709
|
+
absolute: join(functionsDir, DOCUMENT_SCHEMA_TREE_FILE),
|
|
710
|
+
contents: documentSchema.source.content,
|
|
711
|
+
regenerated: true,
|
|
712
|
+
},
|
|
713
|
+
]
|
|
714
|
+
: []),
|
|
715
|
+
...invokers.map((invoker) => {
|
|
716
|
+
const absolute = join(invokerDir, invoker.fileName);
|
|
717
|
+
return {
|
|
718
|
+
relative: reportedPath(configDir, absolute),
|
|
719
|
+
absolute,
|
|
720
|
+
contents: invoker.content,
|
|
721
|
+
regenerated: true,
|
|
722
|
+
};
|
|
723
|
+
}),
|
|
724
|
+
// #3798 — each agent's client-side types, beside the invokers and owned
|
|
725
|
+
// by the same plan (so the orphan sweep keeps them while the agent does).
|
|
726
|
+
...agentArtifacts,
|
|
727
|
+
];
|
|
728
|
+
// The tsconfig is planned against what is on disk: scaffolded when absent,
|
|
729
|
+
// repaired when its wiring is missing, and left alone otherwise — so an
|
|
730
|
+
// author's own edits survive a push and a broken program does not.
|
|
731
|
+
const tsconfigPath = join(functionsDir, FUNCTIONS_TSCONFIG_FILE);
|
|
732
|
+
let onDisk = null;
|
|
733
|
+
if (existsSync(tsconfigPath)) {
|
|
734
|
+
try {
|
|
735
|
+
onDisk = readFileSync(tsconfigPath, "utf-8");
|
|
736
|
+
}
|
|
737
|
+
catch {
|
|
738
|
+
onDisk = null;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
const tsconfig = reconcileFunctionsTsconfig(onDisk, tsconfigContext(configDir, options));
|
|
742
|
+
if (tsconfig !== null) {
|
|
743
|
+
artifacts.push({
|
|
744
|
+
relative: `functions/${FUNCTIONS_TSCONFIG_FILE}`,
|
|
745
|
+
absolute: tsconfigPath,
|
|
746
|
+
contents: tsconfig,
|
|
747
|
+
regenerated: false,
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
return artifacts;
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* The tsconfig wiring push could not repair, phrased for the author.
|
|
754
|
+
*
|
|
755
|
+
* Push repairs a plain-JSON tsconfig in place, but it will not rewrite one that
|
|
756
|
+
* carries comments and it cannot read one that is broken. Reporting is what is
|
|
757
|
+
* left, and it is not optional: a typed handle that no compiler loads is the
|
|
758
|
+
* failure mode this whole artifact exists to prevent, and staying silent about
|
|
759
|
+
* it is how it reaches an author as "my types just don't work" (CR3182-003).
|
|
760
|
+
*/
|
|
761
|
+
export function functionTypeWiringProblems(configDir, options = {}) {
|
|
762
|
+
const functionsDir = join(configDir, "functions");
|
|
763
|
+
if (!treeHasFunctionsDir(configDir))
|
|
764
|
+
return [];
|
|
765
|
+
const tsconfigPath = join(functionsDir, FUNCTIONS_TSCONFIG_FILE);
|
|
766
|
+
if (!existsSync(tsconfigPath))
|
|
767
|
+
return [];
|
|
768
|
+
let onDisk;
|
|
769
|
+
try {
|
|
770
|
+
onDisk = readFileSync(tsconfigPath, "utf-8");
|
|
771
|
+
}
|
|
772
|
+
catch {
|
|
773
|
+
return [];
|
|
774
|
+
}
|
|
775
|
+
return inspectFunctionsTsconfig(onDisk, tsconfigContext(configDir, options)).problems;
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* What the inspection knows about the directory: whether `generated/` will
|
|
779
|
+
* exist beside the tsconfig once this plan is written (it exists now, or this
|
|
780
|
+
* plan writes an invoker into the default location).
|
|
781
|
+
*/
|
|
782
|
+
function tsconfigContext(configDir, options) {
|
|
783
|
+
const defaultDir = join(configDir, "functions", FUNCTION_INVOKERS_DIR);
|
|
784
|
+
const writesThere = functionInvokerDir(configDir, options) === defaultDir &&
|
|
785
|
+
functionSchemaSources(configDir).length > 0;
|
|
786
|
+
return { generatedDirExists: existsSync(defaultDir) || writesThere };
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* Invokers in the plan's directory that the plan no longer writes — a
|
|
790
|
+
* function whose TOML was removed. Owned by the `.generated.ts` suffix, the
|
|
791
|
+
* rule the other two generators apply to their own `generated/` directories.
|
|
792
|
+
*/
|
|
793
|
+
function orphanedInvokers(configDir, planned, options) {
|
|
794
|
+
const dir = functionInvokerDir(configDir, options);
|
|
795
|
+
if (!existsSync(dir))
|
|
796
|
+
return [];
|
|
797
|
+
const keep = new Set(planned.map((a) => a.absolute));
|
|
798
|
+
// #3798 (CSO-3798-003) — with no `functions/` at all, an agent's client
|
|
799
|
+
// artifact is the only thing a run could have written here (an `-o`
|
|
800
|
+
// directory the functions run never owned before), so only those are swept.
|
|
801
|
+
const suffix = existsSync(join(configDir, "functions"))
|
|
802
|
+
? GENERATED_FILE_SUFFIX
|
|
803
|
+
: AGENT_CLIENT_FILE_SUFFIX;
|
|
804
|
+
return readdirSync(dir)
|
|
805
|
+
.filter((f) => f.endsWith(suffix))
|
|
806
|
+
.map((f) => join(dir, f))
|
|
807
|
+
.filter((absolute) => !keep.has(absolute));
|
|
808
|
+
}
|
|
809
|
+
/** Write them, and report the tree-relative paths that changed on disk. */
|
|
810
|
+
export function writeFunctionTypeArtifacts(configDir, sdkTypes, options = {}) {
|
|
811
|
+
// No early return for an empty plan (CSO-3798-003): removing a tree's last
|
|
812
|
+
// agent (or its last function) plans nothing, and its artifacts still go.
|
|
813
|
+
const artifacts = planFunctionTypeArtifacts(configDir, sdkTypes, options);
|
|
814
|
+
const written = [];
|
|
815
|
+
for (const artifact of artifacts) {
|
|
816
|
+
const exists = existsSync(artifact.absolute);
|
|
817
|
+
if (exists && readFileSync(artifact.absolute, "utf-8") === artifact.contents) {
|
|
818
|
+
written.push(artifact.relative);
|
|
819
|
+
continue;
|
|
820
|
+
}
|
|
821
|
+
mkdirSync(dirname(artifact.absolute), { recursive: true });
|
|
822
|
+
writeFileSync(artifact.absolute, artifact.contents);
|
|
823
|
+
written.push(artifact.relative);
|
|
824
|
+
}
|
|
825
|
+
// A removed function's invoker goes with it (#3281): a stale generated file
|
|
826
|
+
// an app still imports is a compile error naming a function that no longer
|
|
827
|
+
// exists, which is the right failure, but one left behind forever is not.
|
|
828
|
+
for (const orphan of orphanedInvokers(configDir, artifacts, options)) {
|
|
829
|
+
rmSync(orphan, { force: true });
|
|
830
|
+
}
|
|
831
|
+
return written;
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* The artifacts a `--check` run would rewrite: the freshness answer for CI and
|
|
835
|
+
* for an editor that wants to know its types are current.
|
|
836
|
+
*
|
|
837
|
+
* The tsconfig is only ever planned when it is missing or its wiring is (see
|
|
838
|
+
* `reconcileFunctionsTsconfig`), so a hand-edited but correctly wired one is
|
|
839
|
+
* never reported — and one that would leave the declarations unloadable always
|
|
840
|
+
* is.
|
|
841
|
+
*/
|
|
842
|
+
export function staleFunctionTypeArtifacts(configDir, options = {}) {
|
|
843
|
+
const stale = [];
|
|
844
|
+
const planned = planFunctionTypeArtifacts(configDir, undefined, options);
|
|
845
|
+
for (const artifact of planned) {
|
|
846
|
+
if (!existsSync(artifact.absolute)) {
|
|
847
|
+
stale.push(artifact.relative);
|
|
848
|
+
continue;
|
|
849
|
+
}
|
|
850
|
+
if (readFileSync(artifact.absolute, "utf-8") !== artifact.contents) {
|
|
851
|
+
stale.push(artifact.relative);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
for (const orphan of orphanedInvokers(configDir, planned, options)) {
|
|
855
|
+
stale.push(reportedPath(configDir, orphan));
|
|
856
|
+
}
|
|
857
|
+
return stale;
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* The SDK's own declaration, as the CLI ships it.
|
|
861
|
+
*
|
|
862
|
+
* Vendored at build time by `cli/scripts/gen-sdk-types.mjs` from
|
|
863
|
+
* `packages/primitive-functions/index.d.ts` — the file `pnpm functions:profile`
|
|
864
|
+
* generates — so the types a config tree gets are the types the platform bakes
|
|
865
|
+
* into the sandbox, and the CLI still imports server source at build time only.
|
|
866
|
+
*/
|
|
867
|
+
function loadSdkTypes() {
|
|
868
|
+
return SDK_TYPES_SOURCE;
|
|
869
|
+
}
|
|
870
|
+
//# sourceMappingURL=function-db-types.js.map
|