@supatype/cli 0.3.6 → 0.7.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/CHANGELOG.md +174 -1
- package/deno.d.ts +11 -0
- package/dist/adopt-columns.d.ts +157 -0
- package/dist/adopt-columns.d.ts.map +1 -0
- package/dist/adopt-columns.js +789 -0
- package/dist/adopt-columns.js.map +1 -0
- package/dist/adopt-walkthrough.d.ts +50 -15
- package/dist/adopt-walkthrough.d.ts.map +1 -1
- package/dist/adopt-walkthrough.js +93 -61
- package/dist/adopt-walkthrough.js.map +1 -1
- package/dist/api-config-cache.d.ts +3 -3
- package/dist/api-config-cache.d.ts.map +1 -1
- package/dist/api-config-cache.js +14 -20
- package/dist/api-config-cache.js.map +1 -1
- package/dist/app/framework.d.ts.map +1 -1
- package/dist/app/framework.js +5 -5
- package/dist/app/framework.js.map +1 -1
- package/dist/app/proxy-dev-app.d.ts.map +1 -1
- package/dist/app/proxy-dev-app.js +3 -2
- package/dist/app/proxy-dev-app.js.map +1 -1
- package/dist/ast-read.d.ts +17 -0
- package/dist/ast-read.d.ts.map +1 -0
- package/dist/ast-read.js +32 -0
- package/dist/ast-read.js.map +1 -0
- package/dist/augmentation-generator.d.ts +14 -2
- package/dist/augmentation-generator.d.ts.map +1 -1
- package/dist/augmentation-generator.js +194 -61
- package/dist/augmentation-generator.js.map +1 -1
- package/dist/augmentation-relationships.d.ts +32 -0
- package/dist/augmentation-relationships.d.ts.map +1 -0
- package/dist/augmentation-relationships.js +122 -0
- package/dist/augmentation-relationships.js.map +1 -0
- package/dist/auth-answer.d.ts +16 -0
- package/dist/auth-answer.d.ts.map +1 -0
- package/dist/auth-answer.js +21 -0
- package/dist/auth-answer.js.map +1 -0
- package/dist/auth-providers.d.ts +89 -0
- package/dist/auth-providers.d.ts.map +1 -0
- package/dist/auth-providers.js +243 -0
- package/dist/auth-providers.js.map +1 -0
- package/dist/binary-cache.d.ts +9 -6
- package/dist/binary-cache.d.ts.map +1 -1
- package/dist/binary-cache.js +150 -46
- package/dist/binary-cache.js.map +1 -1
- package/dist/binary-download-lock.d.ts.map +1 -1
- package/dist/binary-download-lock.js +13 -10
- package/dist/binary-download-lock.js.map +1 -1
- package/dist/byo-preflight.d.ts +26 -0
- package/dist/byo-preflight.d.ts.map +1 -0
- package/dist/byo-preflight.js +69 -0
- package/dist/byo-preflight.js.map +1 -0
- package/dist/cache-identity-scope.d.ts +7 -3
- package/dist/cache-identity-scope.d.ts.map +1 -1
- package/dist/cache-identity-scope.js +20 -10
- package/dist/cache-identity-scope.js.map +1 -1
- package/dist/cache-provider.d.ts +17 -18
- package/dist/cache-provider.d.ts.map +1 -1
- package/dist/cache-provider.js +27 -25
- package/dist/cache-provider.js.map +1 -1
- package/dist/cli-package-version.d.ts.map +1 -1
- package/dist/cli-package-version.js +2 -2
- package/dist/cli-package-version.js.map +1 -1
- package/dist/cli-standalone.d.ts.map +1 -1
- package/dist/cli-standalone.js +2 -6
- package/dist/cli-standalone.js.map +1 -1
- package/dist/cli-version-embedded.js +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +4 -0
- package/dist/cli.js.map +1 -1
- package/dist/client-generator.d.ts +5 -2
- package/dist/client-generator.d.ts.map +1 -1
- package/dist/client-generator.js +32 -22
- package/dist/client-generator.js.map +1 -1
- package/dist/cloud-credentials.d.ts.map +1 -1
- package/dist/cloud-credentials.js +32 -26
- package/dist/cloud-credentials.js.map +1 -1
- package/dist/commands/add.d.ts.map +1 -1
- package/dist/commands/add.js +3 -2
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/admin.d.ts +51 -16
- package/dist/commands/admin.d.ts.map +1 -1
- package/dist/commands/admin.js +162 -136
- package/dist/commands/admin.js.map +1 -1
- package/dist/commands/adopt.d.ts +23 -0
- package/dist/commands/adopt.d.ts.map +1 -1
- package/dist/commands/adopt.js +205 -42
- package/dist/commands/adopt.js.map +1 -1
- package/dist/commands/app.d.ts.map +1 -1
- package/dist/commands/app.js +4 -3
- package/dist/commands/app.js.map +1 -1
- package/dist/commands/cache.d.ts.map +1 -1
- package/dist/commands/cache.js +2 -1
- package/dist/commands/cache.js.map +1 -1
- package/dist/commands/cloud.d.ts +4 -1
- package/dist/commands/cloud.d.ts.map +1 -1
- package/dist/commands/cloud.js +47 -23
- package/dist/commands/cloud.js.map +1 -1
- package/dist/commands/db.d.ts.map +1 -1
- package/dist/commands/db.js +9 -7
- package/dist/commands/db.js.map +1 -1
- package/dist/commands/deploy.d.ts +6 -0
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +65 -17
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/dev.d.ts +8 -2
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +385 -268
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/doctor.d.ts +56 -8
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +180 -61
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/engine.d.ts +1 -1
- package/dist/commands/engine.d.ts.map +1 -1
- package/dist/commands/engine.js +14 -13
- package/dist/commands/engine.js.map +1 -1
- package/dist/commands/functions.d.ts.map +1 -1
- package/dist/commands/functions.js +85 -96
- package/dist/commands/functions.js.map +1 -1
- package/dist/commands/generate.d.ts +6 -0
- package/dist/commands/generate.d.ts.map +1 -1
- package/dist/commands/generate.js +20 -20
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/init.d.ts +19 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +105 -82
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/internal.d.ts.map +1 -1
- package/dist/commands/internal.js +3 -2
- package/dist/commands/internal.js.map +1 -1
- package/dist/commands/keys.js.map +1 -1
- package/dist/commands/link-helpers.d.ts.map +1 -1
- package/dist/commands/link-helpers.js +16 -8
- package/dist/commands/link-helpers.js.map +1 -1
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +2 -1
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/migrate.d.ts +43 -0
- package/dist/commands/migrate.d.ts.map +1 -1
- package/dist/commands/migrate.js +98 -47
- package/dist/commands/migrate.js.map +1 -1
- package/dist/commands/pg.d.ts.map +1 -1
- package/dist/commands/pg.js +24 -23
- package/dist/commands/pg.js.map +1 -1
- package/dist/commands/plugins.d.ts.map +1 -1
- package/dist/commands/plugins.js +36 -27
- package/dist/commands/plugins.js.map +1 -1
- package/dist/commands/pull.d.ts.map +1 -1
- package/dist/commands/pull.js +6 -5
- package/dist/commands/pull.js.map +1 -1
- package/dist/commands/push.d.ts +23 -0
- package/dist/commands/push.d.ts.map +1 -1
- package/dist/commands/push.js +249 -84
- package/dist/commands/push.js.map +1 -1
- package/dist/commands/rename.d.ts +20 -0
- package/dist/commands/rename.d.ts.map +1 -0
- package/dist/commands/rename.js +74 -0
- package/dist/commands/rename.js.map +1 -0
- package/dist/commands/seed.d.ts +12 -0
- package/dist/commands/seed.d.ts.map +1 -1
- package/dist/commands/seed.js +65 -12
- package/dist/commands/seed.js.map +1 -1
- package/dist/commands/self-host.d.ts.map +1 -1
- package/dist/commands/self-host.js +93 -27
- package/dist/commands/self-host.js.map +1 -1
- package/dist/commands/self-update.d.ts.map +1 -1
- package/dist/commands/self-update.js +2 -1
- package/dist/commands/self-update.js.map +1 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +16 -12
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/types.d.ts.map +1 -1
- package/dist/commands/types.js +9 -7
- package/dist/commands/types.js.map +1 -1
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +8 -4
- package/dist/commands/update.js.map +1 -1
- package/dist/compose-db-psql.d.ts +20 -0
- package/dist/compose-db-psql.d.ts.map +1 -0
- package/dist/compose-db-psql.js +30 -0
- package/dist/compose-db-psql.js.map +1 -0
- package/dist/compose-db-roles.d.ts +41 -0
- package/dist/compose-db-roles.d.ts.map +1 -0
- package/dist/compose-db-roles.js +118 -0
- package/dist/compose-db-roles.js.map +1 -0
- package/dist/compose-engine-run.d.ts +27 -0
- package/dist/compose-engine-run.d.ts.map +1 -0
- package/dist/compose-engine-run.js +61 -0
- package/dist/compose-engine-run.js.map +1 -0
- package/dist/compose-kong.d.ts +31 -0
- package/dist/compose-kong.d.ts.map +1 -0
- package/dist/compose-kong.js +145 -0
- package/dist/compose-kong.js.map +1 -0
- package/dist/compose-rename.d.ts.map +1 -1
- package/dist/compose-rename.js +2 -2
- package/dist/compose-rename.js.map +1 -1
- package/dist/compose-render-mode.d.ts +41 -0
- package/dist/compose-render-mode.d.ts.map +1 -0
- package/dist/compose-render-mode.js +70 -0
- package/dist/compose-render-mode.js.map +1 -0
- package/dist/compose-services.d.ts.map +1 -1
- package/dist/compose-services.js +3 -2
- package/dist/compose-services.js.map +1 -1
- package/dist/config.d.ts +18 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +50 -13
- package/dist/config.js.map +1 -1
- package/dist/db-port.d.ts +57 -13
- package/dist/db-port.d.ts.map +1 -1
- package/dist/db-port.js +78 -38
- package/dist/db-port.js.map +1 -1
- package/dist/db-preflight.d.ts +22 -8
- package/dist/db-preflight.d.ts.map +1 -1
- package/dist/db-preflight.js +86 -46
- package/dist/db-preflight.js.map +1 -1
- package/dist/db-rows.d.ts +20 -0
- package/dist/db-rows.d.ts.map +1 -0
- package/dist/db-rows.js +20 -0
- package/dist/db-rows.js.map +1 -0
- package/dist/destructive-consent.d.ts +88 -0
- package/dist/destructive-consent.d.ts.map +1 -0
- package/dist/destructive-consent.js +184 -0
- package/dist/destructive-consent.js.map +1 -0
- package/dist/dev-api-keys.d.ts +26 -0
- package/dist/dev-api-keys.d.ts.map +1 -0
- package/dist/dev-api-keys.js +52 -0
- package/dist/dev-api-keys.js.map +1 -0
- package/dist/dev-compose.d.ts +92 -15
- package/dist/dev-compose.d.ts.map +1 -1
- package/dist/dev-compose.js +676 -465
- package/dist/dev-compose.js.map +1 -1
- package/dist/dev-db-ready.d.ts +20 -0
- package/dist/dev-db-ready.d.ts.map +1 -0
- package/dist/dev-db-ready.js +21 -0
- package/dist/dev-db-ready.js.map +1 -0
- package/dist/dev-functions-watch.d.ts +24 -0
- package/dist/dev-functions-watch.d.ts.map +1 -0
- package/dist/dev-functions-watch.js +82 -0
- package/dist/dev-functions-watch.js.map +1 -0
- package/dist/dev-initial-push.d.ts +41 -6
- package/dist/dev-initial-push.d.ts.map +1 -1
- package/dist/dev-initial-push.js +84 -31
- package/dist/dev-initial-push.js.map +1 -1
- package/dist/dev-ports.d.ts +58 -6
- package/dist/dev-ports.d.ts.map +1 -1
- package/dist/dev-ports.js +157 -49
- package/dist/dev-ports.js.map +1 -1
- package/dist/dev-ready-panel.d.ts +5 -0
- package/dist/dev-ready-panel.d.ts.map +1 -1
- package/dist/dev-ready-panel.js +13 -0
- package/dist/dev-ready-panel.js.map +1 -1
- package/dist/dev-schema-watch.d.ts +19 -0
- package/dist/dev-schema-watch.d.ts.map +1 -0
- package/dist/dev-schema-watch.js +49 -0
- package/dist/dev-schema-watch.js.map +1 -0
- package/dist/dev-session-lock.d.ts +30 -1
- package/dist/dev-session-lock.d.ts.map +1 -1
- package/dist/dev-session-lock.js +83 -10
- package/dist/dev-session-lock.js.map +1 -1
- package/dist/dev-shutdown.d.ts +17 -3
- package/dist/dev-shutdown.d.ts.map +1 -1
- package/dist/dev-shutdown.js +48 -4
- package/dist/dev-shutdown.js.map +1 -1
- package/dist/diff-output.d.ts +71 -3
- package/dist/diff-output.d.ts.map +1 -1
- package/dist/diff-output.js +173 -18
- package/dist/diff-output.js.map +1 -1
- package/dist/docker-env.d.ts +16 -0
- package/dist/docker-env.d.ts.map +1 -0
- package/dist/docker-env.js +16 -0
- package/dist/docker-env.js.map +1 -0
- package/dist/docker-postgres.d.ts.map +1 -1
- package/dist/docker-postgres.js +14 -9
- package/dist/docker-postgres.js.map +1 -1
- package/dist/drift-consent.d.ts +36 -0
- package/dist/drift-consent.d.ts.map +1 -0
- package/dist/drift-consent.js +78 -0
- package/dist/drift-consent.js.map +1 -0
- package/dist/engine-answers.d.ts +51 -0
- package/dist/engine-answers.d.ts.map +1 -0
- package/dist/engine-answers.js +183 -0
- package/dist/engine-answers.js.map +1 -0
- package/dist/engine-client.d.ts +156 -9
- package/dist/engine-client.d.ts.map +1 -1
- package/dist/engine-client.js +315 -129
- package/dist/engine-client.js.map +1 -1
- package/dist/engine-floor.d.ts +10 -0
- package/dist/engine-floor.d.ts.map +1 -1
- package/dist/engine-floor.js +28 -0
- package/dist/engine-floor.js.map +1 -1
- package/dist/engine-json-line.d.ts +9 -0
- package/dist/engine-json-line.d.ts.map +1 -0
- package/dist/engine-json-line.js +23 -0
- package/dist/engine-json-line.js.map +1 -0
- package/dist/engine-ownership-gate.d.ts +79 -0
- package/dist/engine-ownership-gate.d.ts.map +1 -0
- package/dist/engine-ownership-gate.js +213 -0
- package/dist/engine-ownership-gate.js.map +1 -0
- package/dist/engine-push-output.d.ts +23 -2
- package/dist/engine-push-output.d.ts.map +1 -1
- package/dist/engine-push-output.js +22 -15
- package/dist/engine-push-output.js.map +1 -1
- package/dist/env-file.d.ts +15 -2
- package/dist/env-file.d.ts.map +1 -1
- package/dist/env-file.js +61 -22
- package/dist/env-file.js.map +1 -1
- package/dist/error-message.d.ts +5 -0
- package/dist/error-message.d.ts.map +1 -0
- package/dist/error-message.js +11 -0
- package/dist/error-message.js.map +1 -0
- package/dist/field-bounds.d.ts +8 -2
- package/dist/field-bounds.d.ts.map +1 -1
- package/dist/field-bounds.js +9 -15
- package/dist/field-bounds.js.map +1 -1
- package/dist/field-masking-tier.d.ts +4 -3
- package/dist/field-masking-tier.d.ts.map +1 -1
- package/dist/field-masking-tier.js +36 -13
- package/dist/field-masking-tier.js.map +1 -1
- package/dist/functions-deno-types.d.ts +8 -8
- package/dist/functions-deno-types.d.ts.map +1 -1
- package/dist/functions-deno-types.js +53 -25
- package/dist/functions-deno-types.js.map +1 -1
- package/dist/functions-router-gen.d.ts +21 -2
- package/dist/functions-router-gen.d.ts.map +1 -1
- package/dist/functions-router-gen.js +89 -18
- package/dist/functions-router-gen.js.map +1 -1
- package/dist/functions-template.d.ts +10 -0
- package/dist/functions-template.d.ts.map +1 -0
- package/dist/functions-template.js +39 -0
- package/dist/functions-template.js.map +1 -0
- package/dist/hooks-generator.d.ts.map +1 -1
- package/dist/hooks-generator.js +110 -83
- package/dist/hooks-generator.js.map +1 -1
- package/dist/host-database.d.ts +46 -5
- package/dist/host-database.d.ts.map +1 -1
- package/dist/host-database.js +72 -15
- package/dist/host-database.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/init-dependency-versions.d.ts.map +1 -1
- package/dist/init-dependency-versions.js +8 -1
- package/dist/init-dependency-versions.js.map +1 -1
- package/dist/init-project-detect.d.ts.map +1 -1
- package/dist/init-project-detect.js +3 -2
- package/dist/init-project-detect.js.map +1 -1
- package/dist/json-file.d.ts +15 -0
- package/dist/json-file.d.ts.map +1 -0
- package/dist/json-file.js +38 -0
- package/dist/json-file.js.map +1 -0
- package/dist/json-type-text.d.ts +18 -0
- package/dist/json-type-text.d.ts.map +1 -0
- package/dist/json-type-text.js +112 -0
- package/dist/json-type-text.js.map +1 -0
- package/dist/jwt-secret-length.d.ts +22 -0
- package/dist/jwt-secret-length.d.ts.map +1 -0
- package/dist/jwt-secret-length.js +36 -0
- package/dist/jwt-secret-length.js.map +1 -0
- package/dist/jwt.d.ts +5 -0
- package/dist/jwt.d.ts.map +1 -1
- package/dist/jwt.js +25 -1
- package/dist/jwt.js.map +1 -1
- package/dist/link.d.ts +5 -1
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +47 -5
- package/dist/link.js.map +1 -1
- package/dist/local-gateway.d.ts +9 -0
- package/dist/local-gateway.d.ts.map +1 -1
- package/dist/local-gateway.js +16 -0
- package/dist/local-gateway.js.map +1 -1
- package/dist/local-secrets.d.ts +84 -2
- package/dist/local-secrets.d.ts.map +1 -1
- package/dist/local-secrets.js +115 -5
- package/dist/local-secrets.js.map +1 -1
- package/dist/local-stack.d.ts +30 -0
- package/dist/local-stack.d.ts.map +1 -0
- package/dist/local-stack.js +81 -0
- package/dist/local-stack.js.map +1 -0
- package/dist/mailer-autoconfirm.d.ts +37 -0
- package/dist/mailer-autoconfirm.d.ts.map +1 -0
- package/dist/mailer-autoconfirm.js +69 -0
- package/dist/mailer-autoconfirm.js.map +1 -0
- package/dist/model-cache.d.ts +6 -2
- package/dist/model-cache.d.ts.map +1 -1
- package/dist/model-cache.js +33 -27
- package/dist/model-cache.js.map +1 -1
- package/dist/model-hooks.d.ts +7 -6
- package/dist/model-hooks.d.ts.map +1 -1
- package/dist/model-hooks.js +83 -138
- package/dist/model-hooks.js.map +1 -1
- package/dist/model-versioning.d.ts +7 -1
- package/dist/model-versioning.d.ts.map +1 -1
- package/dist/model-versioning.js +24 -27
- package/dist/model-versioning.js.map +1 -1
- package/dist/native-dev-env.d.ts +39 -0
- package/dist/native-dev-env.d.ts.map +1 -0
- package/dist/native-dev-env.js +50 -0
- package/dist/native-dev-env.js.map +1 -0
- package/dist/native-functions-watch.d.ts +11 -0
- package/dist/native-functions-watch.d.ts.map +1 -0
- package/dist/native-functions-watch.js +59 -0
- package/dist/native-functions-watch.js.map +1 -0
- package/dist/native-keyspace.d.ts +23 -0
- package/dist/native-keyspace.d.ts.map +1 -0
- package/dist/native-keyspace.js +53 -0
- package/dist/native-keyspace.js.map +1 -0
- package/dist/native-pg-auth.d.ts +46 -0
- package/dist/native-pg-auth.d.ts.map +1 -0
- package/dist/native-pg-auth.js +107 -0
- package/dist/native-pg-auth.js.map +1 -0
- package/dist/native-realtime.d.ts +26 -0
- package/dist/native-realtime.d.ts.map +1 -0
- package/dist/native-realtime.js +43 -0
- package/dist/native-realtime.js.map +1 -0
- package/dist/native-roles-sql.d.ts +27 -0
- package/dist/native-roles-sql.d.ts.map +1 -0
- package/dist/native-roles-sql.js +73 -0
- package/dist/native-roles-sql.js.map +1 -0
- package/dist/owner-default.d.ts +19 -0
- package/dist/owner-default.d.ts.map +1 -0
- package/dist/owner-default.js +42 -0
- package/dist/owner-default.js.map +1 -0
- package/dist/package-json.d.ts +20 -0
- package/dist/package-json.d.ts.map +1 -0
- package/dist/package-json.js +29 -0
- package/dist/package-json.js.map +1 -0
- package/dist/parent-watch.d.ts +40 -0
- package/dist/parent-watch.d.ts.map +1 -0
- package/dist/parent-watch.js +75 -0
- package/dist/parent-watch.js.map +1 -0
- package/dist/postgres-ctl.d.ts +29 -6
- package/dist/postgres-ctl.d.ts.map +1 -1
- package/dist/postgres-ctl.js +67 -17
- package/dist/postgres-ctl.js.map +1 -1
- package/dist/postgres-image.d.ts +35 -0
- package/dist/postgres-image.d.ts.map +1 -0
- package/dist/postgres-image.js +127 -0
- package/dist/postgres-image.js.map +1 -0
- package/dist/postgrest-release.d.ts +25 -0
- package/dist/postgrest-release.d.ts.map +1 -0
- package/dist/postgrest-release.js +35 -0
- package/dist/postgrest-release.js.map +1 -0
- package/dist/project-config.d.ts +145 -17
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +271 -115
- package/dist/project-config.js.map +1 -1
- package/dist/project-name-override.d.ts +25 -0
- package/dist/project-name-override.d.ts.map +1 -0
- package/dist/project-name-override.js +52 -0
- package/dist/project-name-override.js.map +1 -0
- package/dist/pull-utils.d.ts +26 -3
- package/dist/pull-utils.d.ts.map +1 -1
- package/dist/pull-utils.js +44 -5
- package/dist/pull-utils.js.map +1 -1
- package/dist/push-audit.d.ts +39 -0
- package/dist/push-audit.d.ts.map +1 -0
- package/dist/push-audit.js +116 -0
- package/dist/push-audit.js.map +1 -0
- package/dist/push-refusal.d.ts +94 -0
- package/dist/push-refusal.d.ts.map +1 -0
- package/dist/push-refusal.js +275 -0
- package/dist/push-refusal.js.map +1 -0
- package/dist/recorded-field-masking-tier.d.ts +43 -0
- package/dist/recorded-field-masking-tier.d.ts.map +1 -0
- package/dist/recorded-field-masking-tier.js +88 -0
- package/dist/recorded-field-masking-tier.js.map +1 -0
- package/dist/rename-journal.d.ts +54 -0
- package/dist/rename-journal.d.ts.map +1 -0
- package/dist/rename-journal.js +150 -0
- package/dist/rename-journal.js.map +1 -0
- package/dist/resolve-api-url.d.ts.map +1 -1
- package/dist/resolve-api-url.js +4 -3
- package/dist/resolve-api-url.js.map +1 -1
- package/dist/resolve-target.d.ts +85 -26
- package/dist/resolve-target.d.ts.map +1 -1
- package/dist/resolve-target.js +214 -62
- package/dist/resolve-target.js.map +1 -1
- package/dist/rest-cache-admin.d.ts +9 -8
- package/dist/rest-cache-admin.d.ts.map +1 -1
- package/dist/rest-cache-admin.js +32 -9
- package/dist/rest-cache-admin.js.map +1 -1
- package/dist/rest-ready.d.ts +28 -0
- package/dist/rest-ready.d.ts.map +1 -0
- package/dist/rest-ready.js +53 -0
- package/dist/rest-ready.js.map +1 -0
- package/dist/restore-system-relation-targets.d.ts.map +1 -1
- package/dist/restore-system-relation-targets.js +49 -31
- package/dist/restore-system-relation-targets.js.map +1 -1
- package/dist/route-manifest.d.ts.map +1 -1
- package/dist/route-manifest.js +4 -10
- package/dist/route-manifest.js.map +1 -1
- package/dist/runtime-routes.d.ts.map +1 -1
- package/dist/runtime-routes.js +23 -28
- package/dist/runtime-routes.js.map +1 -1
- package/dist/schema-ast-v2.d.ts +35 -1
- package/dist/schema-ast-v2.d.ts.map +1 -1
- package/dist/schema-ast-v2.js +22 -7
- package/dist/schema-ast-v2.js.map +1 -1
- package/dist/schema-push-lock.d.ts.map +1 -1
- package/dist/schema-push-lock.js +14 -37
- package/dist/schema-push-lock.js.map +1 -1
- package/dist/schema-sources.d.ts +7 -1
- package/dist/schema-sources.d.ts.map +1 -1
- package/dist/schema-sources.js +19 -8
- package/dist/schema-sources.js.map +1 -1
- package/dist/seed-ir.d.ts.map +1 -1
- package/dist/seed-ir.js +30 -9
- package/dist/seed-ir.js.map +1 -1
- package/dist/seed-runner.d.ts.map +1 -1
- package/dist/seed-runner.js +26 -3
- package/dist/seed-runner.js.map +1 -1
- package/dist/seed.d.ts +31 -4
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +3 -1
- package/dist/seed.js.map +1 -1
- package/dist/self-host-compose.d.ts +66 -4
- package/dist/self-host-compose.d.ts.map +1 -1
- package/dist/self-host-compose.js +326 -102
- package/dist/self-host-compose.js.map +1 -1
- package/dist/shell-ports.d.ts +26 -0
- package/dist/shell-ports.d.ts.map +1 -0
- package/dist/shell-ports.js +56 -0
- package/dist/shell-ports.js.map +1 -0
- package/dist/storage-provision.d.ts +21 -4
- package/dist/storage-provision.d.ts.map +1 -1
- package/dist/storage-provision.js +12 -0
- package/dist/storage-provision.js.map +1 -1
- package/dist/studio-admin-roles.d.ts.map +1 -1
- package/dist/studio-admin-roles.js +2 -1
- package/dist/studio-admin-roles.js.map +1 -1
- package/dist/studio-auth-config.d.ts +22 -0
- package/dist/studio-auth-config.d.ts.map +1 -0
- package/dist/studio-auth-config.js +45 -0
- package/dist/studio-auth-config.js.map +1 -0
- package/dist/studio-roles.d.ts +13 -0
- package/dist/studio-roles.d.ts.map +1 -0
- package/dist/studio-roles.js +12 -0
- package/dist/studio-roles.js.map +1 -0
- package/dist/target-client.d.ts +13 -2
- package/dist/target-client.d.ts.map +1 -1
- package/dist/target-client.js +56 -40
- package/dist/target-client.js.map +1 -1
- package/dist/tsx-runner.d.ts +13 -0
- package/dist/tsx-runner.d.ts.map +1 -1
- package/dist/tsx-runner.js +36 -19
- package/dist/tsx-runner.js.map +1 -1
- package/dist/type-extractor.d.ts +2 -0
- package/dist/type-extractor.d.ts.map +1 -1
- package/dist/type-extractor.js +400 -96
- package/dist/type-extractor.js.map +1 -1
- package/dist/type-generation.d.ts +35 -5
- package/dist/type-generation.d.ts.map +1 -1
- package/dist/type-generation.js +57 -27
- package/dist/type-generation.js.map +1 -1
- package/dist/type-resolver.d.ts.map +1 -1
- package/dist/type-resolver.js +8 -1
- package/dist/type-resolver.js.map +1 -1
- package/dist/ui/clack-api.d.ts +3 -0
- package/dist/ui/clack-api.d.ts.map +1 -1
- package/dist/ui/clack-api.js +14 -7
- package/dist/ui/clack-api.js.map +1 -1
- package/dist/ui/clack.d.ts.map +1 -1
- package/dist/ui/clack.js +9 -7
- package/dist/ui/clack.js.map +1 -1
- package/dist/ui/components/PromptPanel.d.ts +1 -0
- package/dist/ui/components/PromptPanel.d.ts.map +1 -1
- package/dist/ui/components/PromptPanel.js +2 -1
- package/dist/ui/components/PromptPanel.js.map +1 -1
- package/dist/ui/confirm.d.ts +8 -0
- package/dist/ui/confirm.d.ts.map +1 -1
- package/dist/ui/confirm.js +12 -0
- package/dist/ui/confirm.js.map +1 -1
- package/dist/ui/dev/DevDashboard.d.ts.map +1 -1
- package/dist/ui/dev/DevDashboard.js +19 -4
- package/dist/ui/dev/DevDashboard.js.map +1 -1
- package/dist/ui/flows/FlowApp.d.ts.map +1 -1
- package/dist/ui/flows/FlowApp.js +17 -1
- package/dist/ui/flows/FlowApp.js.map +1 -1
- package/dist/ui/flows/prompt-fields.d.ts +13 -0
- package/dist/ui/flows/prompt-fields.d.ts.map +1 -1
- package/dist/ui/flows/prompt-fields.js +17 -4
- package/dist/ui/flows/prompt-fields.js.map +1 -1
- package/dist/ui/flows/types.d.ts +2 -1
- package/dist/ui/flows/types.d.ts.map +1 -1
- package/dist/ui/runtime/cancel.d.ts +5 -0
- package/dist/ui/runtime/cancel.d.ts.map +1 -1
- package/dist/ui/runtime/cancel.js +7 -0
- package/dist/ui/runtime/cancel.js.map +1 -1
- package/dist/ui/runtime/dev-prompt-queue.d.ts +5 -4
- package/dist/ui/runtime/dev-prompt-queue.d.ts.map +1 -1
- package/dist/ui/runtime/dev-prompt-queue.js +2 -5
- package/dist/ui/runtime/dev-prompt-queue.js.map +1 -1
- package/dist/ui/runtime/run-clack-flow.js.map +1 -1
- package/dist/unique-file-token.d.ts +10 -0
- package/dist/unique-file-token.d.ts.map +1 -0
- package/dist/unique-file-token.js +13 -0
- package/dist/unique-file-token.js.map +1 -0
- package/package.json +14 -4
- package/.turbo/turbo-build.log +0 -4
- package/.turbo/turbo-test.log +0 -583
- package/.turbo/turbo-typecheck.log +0 -4
- package/assets/supatype-logo-wordmark.ascii.txt +0 -6
- package/bin/dev-entry.ts +0 -3
- package/dist/supatype-eval-1781522769253.d.mts +0 -2
- package/dist/supatype-eval-1781522769253.d.mts.map +0 -1
- package/dist/supatype-eval-1781522769253.mjs +0 -3
- package/dist/supatype-eval-1781522769253.mjs.map +0 -1
- package/scripts/build-release-artifacts.sh +0 -112
- package/scripts/generate-homebrew-formula.mjs +0 -123
- package/scripts/mirror-deno-release.sh +0 -76
- package/src/TYPE-RESOLUTION.md +0 -294
- package/src/adopt-walkthrough.ts +0 -142
- package/src/api-config-cache.ts +0 -172
- package/src/app/framework.ts +0 -247
- package/src/app/proxy-dev-app.ts +0 -175
- package/src/app-config.ts +0 -208
- package/src/app-vite-env.ts +0 -27
- package/src/augmentation-generator.ts +0 -279
- package/src/binary-cache.ts +0 -998
- package/src/binary-download-lock.ts +0 -124
- package/src/cache-clean.ts +0 -81
- package/src/cache-identity-scope.ts +0 -92
- package/src/cache-pins.ts +0 -243
- package/src/cache-provider.ts +0 -61
- package/src/cli-artifacts.ts +0 -65
- package/src/cli-install-method.ts +0 -98
- package/src/cli-package-version.ts +0 -19
- package/src/cli-standalone.ts +0 -144
- package/src/cli-version-embedded.ts +0 -12
- package/src/cli.ts +0 -87
- package/src/client-generator.ts +0 -122
- package/src/cloud-credentials.ts +0 -183
- package/src/commands/add.ts +0 -105
- package/src/commands/admin.ts +0 -819
- package/src/commands/adopt.ts +0 -81
- package/src/commands/app.ts +0 -100
- package/src/commands/cache.ts +0 -233
- package/src/commands/cloud.ts +0 -299
- package/src/commands/db.ts +0 -301
- package/src/commands/deploy-types.ts +0 -49
- package/src/commands/deploy.ts +0 -464
- package/src/commands/dev.ts +0 -1217
- package/src/commands/diff.ts +0 -73
- package/src/commands/doctor.ts +0 -197
- package/src/commands/engine.ts +0 -31
- package/src/commands/functions.ts +0 -1010
- package/src/commands/generate.ts +0 -45
- package/src/commands/hooks.ts +0 -138
- package/src/commands/init.ts +0 -1537
- package/src/commands/internal.ts +0 -60
- package/src/commands/introspect.ts +0 -48
- package/src/commands/keys.ts +0 -269
- package/src/commands/link-helpers.ts +0 -281
- package/src/commands/login.ts +0 -127
- package/src/commands/logs.ts +0 -56
- package/src/commands/migrate-from-v1.ts +0 -132
- package/src/commands/migrate.ts +0 -231
- package/src/commands/pg.ts +0 -128
- package/src/commands/plugins.ts +0 -517
- package/src/commands/pull.ts +0 -46
- package/src/commands/push.ts +0 -427
- package/src/commands/seed.ts +0 -319
- package/src/commands/self-host.ts +0 -404
- package/src/commands/self-update.ts +0 -89
- package/src/commands/status.ts +0 -117
- package/src/commands/types.ts +0 -77
- package/src/commands/update.ts +0 -172
- package/src/components.ts +0 -6
- package/src/compose-local-server-image.ts +0 -85
- package/src/compose-rename.ts +0 -73
- package/src/compose-services.ts +0 -175
- package/src/config.ts +0 -276
- package/src/db-port.ts +0 -99
- package/src/db-preflight.ts +0 -663
- package/src/dev-compose.ts +0 -1650
- package/src/dev-db-reset.ts +0 -95
- package/src/dev-initial-push.ts +0 -134
- package/src/dev-log-bus.ts +0 -121
- package/src/dev-log-filter.ts +0 -74
- package/src/dev-logo.ts +0 -61
- package/src/dev-ports.ts +0 -271
- package/src/dev-ready-panel.ts +0 -80
- package/src/dev-session-lock.ts +0 -98
- package/src/dev-session.ts +0 -210
- package/src/dev-shutdown.ts +0 -159
- package/src/dev-task-colors.ts +0 -66
- package/src/diff-output.ts +0 -90
- package/src/docker-postgres.ts +0 -295
- package/src/docker-runtime.ts +0 -151
- package/src/engine-client.ts +0 -350
- package/src/engine-floor.ts +0 -261
- package/src/engine-push-output.ts +0 -98
- package/src/ensure-binary.ts +0 -68
- package/src/ensure-component-binaries.ts +0 -71
- package/src/ensure-dev-api-config.ts +0 -18
- package/src/env-file.ts +0 -183
- package/src/field-bounds.ts +0 -359
- package/src/field-masking-tier.ts +0 -107
- package/src/functions-context-refresh.ts +0 -25
- package/src/functions-deno-types.ts +0 -258
- package/src/functions-router-gen.ts +0 -256
- package/src/gitignore.ts +0 -76
- package/src/hook-upload.ts +0 -107
- package/src/hooks-generator.ts +0 -444
- package/src/host-database.ts +0 -176
- package/src/index.ts +0 -11
- package/src/init-dependency-versions.ts +0 -69
- package/src/init-package-json.ts +0 -63
- package/src/init-project-detect.ts +0 -99
- package/src/jwt.ts +0 -14
- package/src/kong-config.ts +0 -116
- package/src/link.ts +0 -250
- package/src/local-gateway.ts +0 -9
- package/src/local-secrets.ts +0 -104
- package/src/local-storage.ts +0 -14
- package/src/main.ts +0 -20
- package/src/model-cache.ts +0 -122
- package/src/model-hooks.ts +0 -430
- package/src/model-versioning.ts +0 -167
- package/src/pgbouncer-userlist.ts +0 -15
- package/src/postgres-ctl.ts +0 -333
- package/src/preview-config-check.ts +0 -52
- package/src/process-manager.ts +0 -224
- package/src/project-config.ts +0 -939
- package/src/prompts.ts +0 -2
- package/src/pull-utils.ts +0 -275
- package/src/realtime-launch.ts +0 -52
- package/src/release-pins.ts +0 -31
- package/src/release-public-key.ts +0 -12
- package/src/required-host-components.ts +0 -37
- package/src/resolve-api-url.ts +0 -44
- package/src/resolve-target.ts +0 -480
- package/src/rest-cache-admin.ts +0 -141
- package/src/restore-system-relation-targets.ts +0 -45
- package/src/retired-no-cache.ts +0 -27
- package/src/route-manifest.ts +0 -17
- package/src/runtime-routes.ts +0 -298
- package/src/schema-ast-v2.ts +0 -488
- package/src/schema-push-lock.ts +0 -170
- package/src/schema-sources.ts +0 -248
- package/src/scripts/postinstall.ts +0 -20
- package/src/seed-ir.ts +0 -311
- package/src/seed-runner.ts +0 -109
- package/src/seed.ts +0 -451
- package/src/self-host-compose.ts +0 -1246
- package/src/service-role-check.ts +0 -111
- package/src/storage-provision.ts +0 -90
- package/src/strict.ts +0 -40
- package/src/studio-admin-roles.ts +0 -30
- package/src/studio-dev-server.ts +0 -70
- package/src/supatype-eval-1781522769253.mts +0 -1
- package/src/systemd.ts +0 -137
- package/src/target-client.ts +0 -127
- package/src/tsx-runner.ts +0 -128
- package/src/type-extractor.ts +0 -3365
- package/src/type-generation.ts +0 -169
- package/src/type-resolver.ts +0 -457
- package/src/ui/README.md +0 -21
- package/src/ui/brand.ts +0 -6
- package/src/ui/clack-api.ts +0 -123
- package/src/ui/clack.ts +0 -153
- package/src/ui/components/FlowSpinner.tsx +0 -15
- package/src/ui/components/LogoWordmark.tsx +0 -36
- package/src/ui/components/PromptPanel.tsx +0 -17
- package/src/ui/components/SelectField.tsx +0 -58
- package/src/ui/confirm.ts +0 -39
- package/src/ui/dev/DevDashboard.tsx +0 -223
- package/src/ui/dev/DevReadyPanelView.tsx +0 -134
- package/src/ui/fatal.ts +0 -38
- package/src/ui/flows/FlowApp.tsx +0 -69
- package/src/ui/flows/prompt-fields.tsx +0 -198
- package/src/ui/flows/types.ts +0 -50
- package/src/ui/index.ts +0 -8
- package/src/ui/interactive.ts +0 -4
- package/src/ui/messages.ts +0 -85
- package/src/ui/next-steps.ts +0 -10
- package/src/ui/progress.ts +0 -39
- package/src/ui/prompts.ts +0 -48
- package/src/ui/runtime/cancel.ts +0 -6
- package/src/ui/runtime/command-chrome.ts +0 -147
- package/src/ui/runtime/dev-prompt-queue.ts +0 -84
- package/src/ui/runtime/flow-session.ts +0 -11
- package/src/ui/runtime/run-clack-flow.tsx +0 -65
- package/src/ui/runtime/stdin-after-ink.ts +0 -20
- package/src/ui/theme.ts +0 -41
- package/src/valkey-sidecar.ts +0 -126
- package/tests/access-composition.test.ts +0 -790
- package/tests/admin-ensure.test.ts +0 -139
- package/tests/admin-studio-membership.test.ts +0 -121
- package/tests/adopt-result.test.ts +0 -27
- package/tests/adopt-walkthrough.test.ts +0 -129
- package/tests/api-config-cache-seed.test.ts +0 -180
- package/tests/api-schemas.test.ts +0 -83
- package/tests/app-command.test.ts +0 -64
- package/tests/archive-name-alias.test.ts +0 -42
- package/tests/ast-derived-outputs.test.ts +0 -92
- package/tests/augmentation-generator.test.ts +0 -393
- package/tests/binary-cache-cloud-overrides.test.ts +0 -123
- package/tests/binary-download-lock.test.ts +0 -41
- package/tests/cache-clean.test.ts +0 -206
- package/tests/cache-identity-scope.test.ts +0 -61
- package/tests/cache-provider-config.test.ts +0 -132
- package/tests/cached-artifact-format.test.ts +0 -84
- package/tests/cli-help.test.ts +0 -170
- package/tests/cli-install-method.test.ts +0 -66
- package/tests/cli-package-version.test.ts +0 -15
- package/tests/client-generator.test.ts +0 -103
- package/tests/command-chrome-coverage.test.ts +0 -154
- package/tests/command-chrome-wrap.test.ts +0 -52
- package/tests/compose-parsable-defaults.test.ts +0 -60
- package/tests/compose-services.test.ts +0 -144
- package/tests/config-load-failure.test.ts +0 -44
- package/tests/config.test.ts +0 -301
- package/tests/db-port.test.ts +0 -128
- package/tests/db-preflight.test.ts +0 -152
- package/tests/db-published-and-addressable.test.ts +0 -69
- package/tests/dev-db-reset.test.ts +0 -162
- package/tests/dev-initial-push.test.ts +0 -142
- package/tests/dev-ports-owner.test.ts +0 -40
- package/tests/dev-ports.test.ts +0 -41
- package/tests/dev-ready-panel.test.ts +0 -37
- package/tests/dev-session-lock.test.ts +0 -54
- package/tests/dev-ui.test.ts +0 -202
- package/tests/docker-postgres.test.ts +0 -39
- package/tests/docker-runtime.test.ts +0 -225
- package/tests/doctor-render.test.ts +0 -62
- package/tests/doctor-service-role.test.ts +0 -55
- package/tests/engine-floor.test.ts +0 -238
- package/tests/engine-push-output.test.ts +0 -96
- package/tests/ensure-binary.test.ts +0 -59
- package/tests/ensure-dev-api-config.test.ts +0 -22
- package/tests/env-file.test.ts +0 -121
- package/tests/external-database-compose.test.ts +0 -262
- package/tests/external-database-config.test.ts +0 -154
- package/tests/field-bounds-matrix.test.ts +0 -163
- package/tests/field-bounds.test.ts +0 -139
- package/tests/field-masking-tier.test.ts +0 -184
- package/tests/field-validators.test.ts +0 -139
- package/tests/fixtures/identity-scope-corpus.json +0 -42
- package/tests/fixtures/seed_golden_ir.json +0 -186
- package/tests/functions-concurrency.test.ts +0 -71
- package/tests/functions-context-refresh.test.ts +0 -86
- package/tests/functions-deno-types.test.ts +0 -197
- package/tests/gitignore-secrets.test.ts +0 -90
- package/tests/homebrew-formula.test.ts +0 -100
- package/tests/hook-upload.test.ts +0 -125
- package/tests/hooks-generator.test.ts +0 -298
- package/tests/host-connection-targets.test.ts +0 -84
- package/tests/host-database.test.ts +0 -176
- package/tests/init-dependency-versions.test.ts +0 -62
- package/tests/init-package-json.test.ts +0 -18
- package/tests/init-project-detect.test.ts +0 -53
- package/tests/init.test.ts +0 -369
- package/tests/keys-write.test.ts +0 -148
- package/tests/keys.test.ts +0 -166
- package/tests/link.test.ts +0 -148
- package/tests/local-secrets.test.ts +0 -92
- package/tests/local-server-image-env.test.ts +0 -93
- package/tests/migrate-from-v1.test.ts +0 -29
- package/tests/minisign.test.ts +0 -102
- package/tests/model-cache-declaration.test.ts +0 -229
- package/tests/model-cache-manifest.test.ts +0 -99
- package/tests/model-constraints.test.ts +0 -293
- package/tests/model-hooks.test.ts +0 -433
- package/tests/model-versions.test.ts +0 -229
- package/tests/native-keyspace.test.ts +0 -130
- package/tests/normalize-admin-config.test.ts +0 -48
- package/tests/pg-spawn-env.test.ts +0 -18
- package/tests/port-in-use.test.ts +0 -58
- package/tests/postgres-archive-tag.test.ts +0 -9
- package/tests/preview-config-check.test.ts +0 -104
- package/tests/proxy-dev-app.test.ts +0 -77
- package/tests/pull-utils.test.ts +0 -151
- package/tests/readiness-poll.test.ts +0 -84
- package/tests/realtime-launch.test.ts +0 -25
- package/tests/release-pins.test.ts +0 -28
- package/tests/required-host-components.test.ts +0 -53
- package/tests/resolve-api-url.test.ts +0 -23
- package/tests/rest-cache-admin.test.ts +0 -64
- package/tests/retired-no-cache.test.ts +0 -46
- package/tests/route-manifest.test.ts +0 -29
- package/tests/runtime-contract.test.ts +0 -948
- package/tests/schema-sources.test.ts +0 -119
- package/tests/seed-discover.test.ts +0 -31
- package/tests/seed-ir.test.ts +0 -436
- package/tests/self-host-keys.test.ts +0 -92
- package/tests/service-role-check.test.ts +0 -109
- package/tests/service-role-routes.test.ts +0 -51
- package/tests/stdin-after-ink.test.ts +0 -8
- package/tests/storage-provision.test.ts +0 -100
- package/tests/strict.test.ts +0 -78
- package/tests/studio-admin-roles.test.ts +0 -59
- package/tests/target-client-refresh.test.ts +0 -94
- package/tests/tsconfig.json +0 -15
- package/tests/tsx-runner.test.ts +0 -66
- package/tests/type-extractor.test.ts +0 -1601
- package/tests/type-resolver.test.ts +0 -59
- package/tests/ui-confirm.test.ts +0 -45
- package/tests/ui-messages.test.ts +0 -52
- package/tsconfig.json +0 -11
- package/tsconfig.tsbuildinfo +0 -1
- package/vitest.config.ts +0 -21
package/src/commands/dev.ts
DELETED
|
@@ -1,1217 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* supatype dev: start local Postgres, apply schema, run supatype-server.
|
|
3
|
-
*
|
|
4
|
-
* Runtime provider (top-level `provider` or legacy `database.provider`):
|
|
5
|
-
* native: host Postgres + host server + host engine (default)
|
|
6
|
-
* docker: full self-host Compose stack (Kong :18473); see dev-compose.ts
|
|
7
|
-
*
|
|
8
|
-
* Edge functions (when a functions/ dir exists): Deno is resolved from the CDN cache
|
|
9
|
-
* (auto-download on miss). Self-host/cloud Docker stacks use supatype-server in-container;
|
|
10
|
-
* Deno is not provisioned by the CLI on those paths.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { keyspaceInPostgres } from "../cache-provider.js"
|
|
14
|
-
import { printPushWarnings, type EnginePushResult } from "../engine-push-output.js"
|
|
15
|
-
import type { Command } from "commander"
|
|
16
|
-
import { spawnSync } from "node:child_process"
|
|
17
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"
|
|
18
|
-
import { homedir } from "node:os"
|
|
19
|
-
import { isAbsolute, join, relative, resolve } from "node:path"
|
|
20
|
-
import { loadConfig } from "../config.js"
|
|
21
|
-
import type { ExtractedSchemaAstV2 } from "../schema-ast-v2.js"
|
|
22
|
-
import {
|
|
23
|
-
apiSchemaList,
|
|
24
|
-
functionsPathCandidatesFromProject,
|
|
25
|
-
resolveRuntimeProvider,
|
|
26
|
-
schemaPathFromProject,
|
|
27
|
-
type SupatypeProjectConfig,
|
|
28
|
-
} from "../project-config.js"
|
|
29
|
-
import { discoverTsFunctionsInDir, writeDevFunctionsRouter } from "../functions-router-gen.js"
|
|
30
|
-
import { fieldMaskingTierFromProject } from "../field-masking-tier.js"
|
|
31
|
-
import { projectHasVersionedModels } from "../model-versioning.js"
|
|
32
|
-
import { signJwt } from "../jwt.js"
|
|
33
|
-
import {
|
|
34
|
-
devAuthenticatorPassword,
|
|
35
|
-
devJwtSecret,
|
|
36
|
-
devPostgresPassword,
|
|
37
|
-
secretFingerprint,
|
|
38
|
-
} from "../local-secrets.js"
|
|
39
|
-
import {
|
|
40
|
-
normalisePlatformPath,
|
|
41
|
-
cachePath,
|
|
42
|
-
currentPlatform,
|
|
43
|
-
hasMeaningfulOverrides,
|
|
44
|
-
describeActiveOverrides,
|
|
45
|
-
postgresArchiveTag,
|
|
46
|
-
} from "../binary-cache.js"
|
|
47
|
-
import { ensureBinary } from "../ensure-binary.js"
|
|
48
|
-
import { startProxyDevApp } from "../app/proxy-dev-app.js"
|
|
49
|
-
import { ProcessManager } from "../process-manager.js"
|
|
50
|
-
import { STUDIO_DEV_PORT, startStudioViteDevServer } from "../studio-dev-server.js"
|
|
51
|
-
import { restoreSystemRelationTargets } from "../restore-system-relation-targets.js"
|
|
52
|
-
import { localStorageEnv } from "../local-storage.js"
|
|
53
|
-
import { beginDevSession, endDevSession, resolveDevUiMode, startDevSession } from "../dev-session.js"
|
|
54
|
-
import { publishDevReady } from "../dev-ready-panel.js"
|
|
55
|
-
import { probeDockerDaemon, reportDockerUnavailable } from "../docker-runtime.js"
|
|
56
|
-
import { fatalError } from "../ui/fatal.js"
|
|
57
|
-
import { registerDevShutdown } from "../dev-shutdown.js"
|
|
58
|
-
import { patchRouteManifest } from "../route-manifest.js"
|
|
59
|
-
import { resolveRealtimeLaunch } from "../realtime-launch.js"
|
|
60
|
-
import { writeAppViteEnv } from "../app-vite-env.js"
|
|
61
|
-
import { ensureValkeySidecar, probeTcp, stopValkeySidecar } from "../valkey-sidecar.js"
|
|
62
|
-
import {
|
|
63
|
-
firstFreePort,
|
|
64
|
-
initdb,
|
|
65
|
-
KEYSPACE_PORT_BASE,
|
|
66
|
-
KEYSPACE_PORT_SPAN,
|
|
67
|
-
nativeKeyspaceLibraryPresent,
|
|
68
|
-
nativeMaskLibraryPresent,
|
|
69
|
-
start as pgStart,
|
|
70
|
-
stop as pgStop,
|
|
71
|
-
waitReady as pgWaitReady,
|
|
72
|
-
isPortInUse,
|
|
73
|
-
pgSpawnEnv,
|
|
74
|
-
} from "../postgres-ctl.js"
|
|
75
|
-
/** Map `email.smtp` from supatype.config.ts into SUPATYPE_SMTP_* for the embedded auth service. */
|
|
76
|
-
function authSMTPFromEmailConfig(email: SupatypeProjectConfig["email"] | undefined): Record<string, string> {
|
|
77
|
-
const s = email?.smtp
|
|
78
|
-
if (!s) return {}
|
|
79
|
-
const out: Record<string, string> = {}
|
|
80
|
-
const host = s.host?.trim()
|
|
81
|
-
if (host) out.SUPATYPE_SMTP_HOST = host
|
|
82
|
-
if (s.port !== undefined) out.SUPATYPE_SMTP_PORT = String(s.port)
|
|
83
|
-
const user = s.user?.trim()
|
|
84
|
-
if (user) out.SUPATYPE_SMTP_USER = user
|
|
85
|
-
if (s.pass !== undefined && s.pass !== "") out.SUPATYPE_SMTP_PASS = s.pass
|
|
86
|
-
const admin = s.admin_email?.trim()
|
|
87
|
-
if (admin) out.SUPATYPE_SMTP_ADMIN_EMAIL = admin
|
|
88
|
-
const sender = s.sender_name?.trim()
|
|
89
|
-
if (sender) out.SUPATYPE_SMTP_SENDER_NAME = sender
|
|
90
|
-
return out
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const NATIVE_PG_PORT = 5432
|
|
94
|
-
const REALTIME_PORT = "4000"
|
|
95
|
-
|
|
96
|
-
function portCheckCommand(port: number): string {
|
|
97
|
-
return process.platform === "win32"
|
|
98
|
-
? `netstat -ano | findstr :${port}`
|
|
99
|
-
: `lsof -i :${port}`
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async function assertNativeDevPortsFree(serverPort: number, postgrestPort: number): Promise<void> {
|
|
103
|
-
const brand = { intro: "Local development" }
|
|
104
|
-
if (await isPortInUse(NATIVE_PG_PORT)) {
|
|
105
|
-
fatalError(
|
|
106
|
-
`Port ${NATIVE_PG_PORT} is already in use.`,
|
|
107
|
-
["Another Postgres instance may be running.", `Check: ${portCheckCommand(NATIVE_PG_PORT)}`],
|
|
108
|
-
{ brand },
|
|
109
|
-
)
|
|
110
|
-
}
|
|
111
|
-
if (await isPortInUse(serverPort)) {
|
|
112
|
-
fatalError(
|
|
113
|
-
`Port ${serverPort} is already in use.`,
|
|
114
|
-
["Another supatype-server may be running.", `Check: ${portCheckCommand(serverPort)}`],
|
|
115
|
-
{ brand },
|
|
116
|
-
)
|
|
117
|
-
}
|
|
118
|
-
if (await isPortInUse(postgrestPort)) {
|
|
119
|
-
fatalError(
|
|
120
|
-
`Port ${postgrestPort} is already in use.`,
|
|
121
|
-
["Another service may be running.", `Check: ${portCheckCommand(postgrestPort)}`],
|
|
122
|
-
{ brand },
|
|
123
|
-
)
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export function registerDev(program: Command): void {
|
|
128
|
-
program
|
|
129
|
-
.command("dev")
|
|
130
|
-
.description("Start local Postgres, apply schema, and run supatype-server")
|
|
131
|
-
.option("--no-watch", "Start services but do not watch for schema changes")
|
|
132
|
-
.option("--stream", "Print interleaved logs instead of the interactive TUI")
|
|
133
|
-
.option("--port <port>", "Port for supatype-server (overrides config)", String)
|
|
134
|
-
.option("--reset-db", "Remove the local Postgres data volume before starting (asks first; storage is kept)")
|
|
135
|
-
.option("--yes", "Skip the --reset-db confirmation")
|
|
136
|
-
.action(async (opts: { watch: boolean; stream?: boolean; port?: string; resetDb?: boolean; yes?: boolean }) => {
|
|
137
|
-
const cwd = process.cwd()
|
|
138
|
-
|
|
139
|
-
// ── 1. Load project config (before TUI, fatal errors must hit real stderr) ──
|
|
140
|
-
const config = loadConfig(cwd)
|
|
141
|
-
const provider = resolveRuntimeProvider(config)
|
|
142
|
-
|
|
143
|
-
// The native provider keeps Postgres in a data directory, not a compose volume, and has
|
|
144
|
-
// nothing for this flag to remove. Saying so beats silently starting on the old data.
|
|
145
|
-
if (opts.resetDb === true && provider !== "docker") {
|
|
146
|
-
fatalError("--reset-db applies to the Docker provider only.", [
|
|
147
|
-
"This project runs Postgres natively, so there is no compose volume to remove.",
|
|
148
|
-
])
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (provider === "docker") {
|
|
152
|
-
const probe = probeDockerDaemon()
|
|
153
|
-
if (!probe.ok) {
|
|
154
|
-
reportDockerUnavailable(probe, { brand: { intro: "Local development" } })
|
|
155
|
-
process.exit(1)
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const projectName = config.project.name
|
|
160
|
-
const serverPort = opts.port ?? String(config.server.port ?? 54321)
|
|
161
|
-
const postgrestPort = String(config.server.postgrestPort ?? 3001)
|
|
162
|
-
|
|
163
|
-
if (provider !== "docker") {
|
|
164
|
-
await assertNativeDevPortsFree(Number(serverPort), Number(postgrestPort))
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
beginDevSession(resolveDevUiMode(opts.stream === true))
|
|
168
|
-
if (hasMeaningfulOverrides(config)) {
|
|
169
|
-
console.warn("[supatype] Local binary overrides active:")
|
|
170
|
-
for (const line of describeActiveOverrides(config)) {
|
|
171
|
-
console.warn(line)
|
|
172
|
-
}
|
|
173
|
-
console.warn("")
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (provider === "docker") {
|
|
177
|
-
const { runDevCompose } = await import("../dev-compose.js")
|
|
178
|
-
await runDevCompose(cwd, config, {
|
|
179
|
-
watch: opts.watch !== false,
|
|
180
|
-
resetDb: opts.resetDb === true,
|
|
181
|
-
yes: opts.yes === true,
|
|
182
|
-
})
|
|
183
|
-
return
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// ── 2. Resolve engine + server binaries ──────────────────────────────
|
|
187
|
-
console.log(`[supatype] Resolving component binaries for "${projectName}"...`)
|
|
188
|
-
const [engineBin, serverBin] = await Promise.all([
|
|
189
|
-
ensureBinary("engine", config),
|
|
190
|
-
ensureBinary("server", config),
|
|
191
|
-
])
|
|
192
|
-
|
|
193
|
-
// ── 3. Per-project state directories ─────────────────────────────────
|
|
194
|
-
const stateRoot = join(homedir(), ".supatype", "projects", projectName)
|
|
195
|
-
const pidDir = join(stateRoot, "pid")
|
|
196
|
-
const logsDir = join(stateRoot, "logs")
|
|
197
|
-
const tmpDir = join(stateRoot, "tmp")
|
|
198
|
-
|
|
199
|
-
for (const d of [pidDir, logsDir, tmpDir]) {
|
|
200
|
-
mkdirSync(d, { recursive: true })
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// ── 5–7. Start Postgres ───────────────────────────────────────────────
|
|
204
|
-
let dbURL: string
|
|
205
|
-
/** What PostgREST connects as, deliberately not `dbURL`, which is a superuser. */
|
|
206
|
-
let postgrestDbURL: string
|
|
207
|
-
let stopPostgres: () => void | Promise<void>
|
|
208
|
-
const pgPort = NATIVE_PG_PORT
|
|
209
|
-
const pgPassword = devPostgresPassword(cwd)
|
|
210
|
-
// Distinct from pgPassword even locally, so the split the other paths enforce is the
|
|
211
|
-
// one developers see. Read from .env when present so it matches a stack the user has
|
|
212
|
-
// already provisioned.
|
|
213
|
-
const authenticatorPassword = devAuthenticatorPassword(cwd)
|
|
214
|
-
// pgBinDir is set on the native path and used to add DLL search path for
|
|
215
|
-
// PostgREST on Windows (PostgREST links against libpq + SSL from MinGW).
|
|
216
|
-
let pgBinDir: string | null = null
|
|
217
|
-
// The port the native Postgres serves RESP on, or null when this archive
|
|
218
|
-
// has no pg_keyspace and the Valkey sidecar is what the cache talks to.
|
|
219
|
-
let keyspacePort: number | null = null
|
|
220
|
-
|
|
221
|
-
{
|
|
222
|
-
// native: resolve pg bin dir and manage with pg_ctl
|
|
223
|
-
pgBinDir = await resolvePgBinDir(config)
|
|
224
|
-
const dataDir = config.database.data_dir ?? join(stateRoot, "data")
|
|
225
|
-
mkdirSync(dataDir, { recursive: true })
|
|
226
|
-
// The RESP keyspace, when this archive carries it: one process instead
|
|
227
|
-
// of a Postgres and a Valkey container. The port is chosen rather than
|
|
228
|
-
// fixed because 6379 is the first thing a developer's own Redis or a
|
|
229
|
-
// leftover sidecar takes, and a keyspace that cannot bind its port
|
|
230
|
-
// fails inside the postmaster log where nobody is looking.
|
|
231
|
-
//
|
|
232
|
-
// `cache.provider: "valkey"` is honoured here too, and this is the only place it could
|
|
233
|
-
// be: the native path asks the archive what it carries rather than the config what it
|
|
234
|
-
// wants, so a project that deliberately kept the sidecar would otherwise find Postgres
|
|
235
|
-
// serving RESP anyway and the sidecar never started.
|
|
236
|
-
const wantsPgKeyspace = keyspaceInPostgres(config)
|
|
237
|
-
keyspacePort =
|
|
238
|
-
wantsPgKeyspace && nativeKeyspaceLibraryPresent(pgBinDir)
|
|
239
|
-
? await firstFreePort(KEYSPACE_PORT_BASE, KEYSPACE_PORT_SPAN)
|
|
240
|
-
: null
|
|
241
|
-
if (wantsPgKeyspace && nativeKeyspaceLibraryPresent(pgBinDir) && keyspacePort === null) {
|
|
242
|
-
console.warn(
|
|
243
|
-
`[supatype] ⚠ No free port in ${KEYSPACE_PORT_BASE}-${KEYSPACE_PORT_BASE + KEYSPACE_PORT_SPAN - 1} ` +
|
|
244
|
-
"for the Postgres keyspace, starting without it.",
|
|
245
|
-
)
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const pgOpts = {
|
|
249
|
-
pgBinDir,
|
|
250
|
-
dataDir,
|
|
251
|
-
port: pgPort,
|
|
252
|
-
logPath: join(logsDir, "postgres.log"),
|
|
253
|
-
...(keyspacePort !== null
|
|
254
|
-
? { keyspacePort, keyspaceDatabase: projectName }
|
|
255
|
-
: {}),
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
console.log("[supatype] Initialising Postgres data directory...")
|
|
259
|
-
initdb(pgOpts)
|
|
260
|
-
console.log("[supatype] Starting Postgres...")
|
|
261
|
-
pgStart(pgOpts)
|
|
262
|
-
await pgWaitReady(pgOpts, 15_000)
|
|
263
|
-
console.log("[supatype] Postgres is ready.")
|
|
264
|
-
dbURL = `postgres://postgres:${pgPassword}@127.0.0.1:${pgPort}/${projectName}?sslmode=disable`
|
|
265
|
-
postgrestDbURL = `postgres://authenticator:${authenticatorPassword}@127.0.0.1:${pgPort}/${projectName}?sslmode=disable`
|
|
266
|
-
stopPostgres = () => pgStop(pgOpts)
|
|
267
|
-
|
|
268
|
-
// Create project database if it doesn't exist (native only).
|
|
269
|
-
const psqlBin = join(pgBinDir, process.platform === "win32" ? "psql.exe" : "psql")
|
|
270
|
-
const createdbBin = join(pgBinDir, process.platform === "win32" ? "createdb.exe" : "createdb")
|
|
271
|
-
const pgConnArgs = ["-h", "127.0.0.1", "-p", String(pgPort), "-U", "postgres"]
|
|
272
|
-
const pgEnv = pgSpawnEnv(pgBinDir)
|
|
273
|
-
const createDbResult = spawnSync(
|
|
274
|
-
createdbBin,
|
|
275
|
-
[...pgConnArgs, projectName],
|
|
276
|
-
{ stdio: "pipe", encoding: "utf8", env: pgEnv },
|
|
277
|
-
)
|
|
278
|
-
if (createDbResult.status !== 0) {
|
|
279
|
-
const stderr = createDbResult.stderr ?? ""
|
|
280
|
-
if (!stderr.includes("already exists")) {
|
|
281
|
-
throw new Error(`Failed to create database "${projectName}": ${stderr}`)
|
|
282
|
-
}
|
|
283
|
-
} else {
|
|
284
|
-
console.log(`[supatype] Created database "${projectName}".`)
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
// Create roles required by PostgREST and grant them to postgres so
|
|
288
|
-
// PostgREST can SET ROLE when processing requests.
|
|
289
|
-
// anon – unauthenticated requests (RLS enforced)
|
|
290
|
-
// authenticated – signed-in user requests (RLS enforced)
|
|
291
|
-
// service_role – developer/admin bypass (BYPASSRLS)
|
|
292
|
-
// authenticator – the role PostgREST *connects* as, and nothing else
|
|
293
|
-
//
|
|
294
|
-
// `authenticator` is NOINHERIT and holds no privileges of its own: it can only
|
|
295
|
-
// SET ROLE to the three above. That containment is the point. Connecting as
|
|
296
|
-
// `postgres`: a superuser: meant a request whose JWT named *any* role in the
|
|
297
|
-
// cluster got it, because a superuser may SET ROLE to anything. Verified: as
|
|
298
|
-
// postgres, `SET ROLE supatype_replication_admin` succeeds; as authenticator the
|
|
299
|
-
// same statement is refused. Mirrors the image, which has had this role all along.
|
|
300
|
-
// Created here rather than during the push, because the engine chooses how to enforce field
|
|
301
|
-
// rules from the extensions present *when it diffs*. Creating it later would leave the tier
|
|
302
|
-
// decided against a database that no longer looks like that.
|
|
303
|
-
//
|
|
304
|
-
// Conditional on the library being bundled: an archive downloaded before it was would fail
|
|
305
|
-
// the CREATE, and there is nothing the developer could do about it from here.
|
|
306
|
-
const maskSql = nativeMaskLibraryPresent(pgBinDir)
|
|
307
|
-
? "CREATE EXTENSION IF NOT EXISTS supatype_mask;\n"
|
|
308
|
-
: ""
|
|
309
|
-
const rolesSql = `
|
|
310
|
-
${maskSql}CREATE SCHEMA IF NOT EXISTS auth;
|
|
311
|
-
DO $$ BEGIN
|
|
312
|
-
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'anon')
|
|
313
|
-
THEN CREATE ROLE anon NOLOGIN; END IF;
|
|
314
|
-
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'authenticated')
|
|
315
|
-
THEN CREATE ROLE authenticated NOLOGIN; END IF;
|
|
316
|
-
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'service_role')
|
|
317
|
-
THEN CREATE ROLE service_role NOLOGIN BYPASSRLS; END IF;
|
|
318
|
-
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'authenticator')
|
|
319
|
-
THEN CREATE ROLE authenticator LOGIN NOINHERIT PASSWORD '${authenticatorPassword}'; END IF;
|
|
320
|
-
END $$;
|
|
321
|
-
GRANT anon, authenticated, service_role TO postgres;
|
|
322
|
-
GRANT anon, authenticated, service_role TO authenticator;
|
|
323
|
-
GRANT USAGE ON SCHEMA public TO anon, authenticated, service_role;
|
|
324
|
-
-- Table-level privileges (RLS restricts rows; roles still need table access)
|
|
325
|
-
GRANT SELECT ON ALL TABLES IN SCHEMA public TO anon;
|
|
326
|
-
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO authenticated;
|
|
327
|
-
GRANT ALL ON ALL TABLES IN SCHEMA public TO service_role;
|
|
328
|
-
GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO authenticated, service_role;
|
|
329
|
-
-- Default privileges so tables created by the engine push inherit these grants
|
|
330
|
-
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO anon;
|
|
331
|
-
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO authenticated;
|
|
332
|
-
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO service_role;
|
|
333
|
-
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO authenticated, service_role;
|
|
334
|
-
`
|
|
335
|
-
spawnSync(psqlBin, [...pgConnArgs, "-d", projectName, "-c", rolesSql],
|
|
336
|
-
{ stdio: "pipe", encoding: "utf8", env: pgEnv })
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
const LOCAL_JWT_SECRET = devJwtSecret(cwd)
|
|
340
|
-
const authDbURL = dbURL.includes("?")
|
|
341
|
-
? `${dbURL}&search_path=auth`
|
|
342
|
-
: `${dbURL}?search_path=auth`
|
|
343
|
-
|
|
344
|
-
// ── 8. auth migrations (auth.users before engine studio SQL) ─────────
|
|
345
|
-
console.log("[supatype] Running auth migrations...")
|
|
346
|
-
const migrateEnv = authMigrateEnv(serverPort, dbURL, LOCAL_JWT_SECRET)
|
|
347
|
-
runAuthMigrations(serverBin, migrateEnv)
|
|
348
|
-
|
|
349
|
-
// ── 9. Engine: apply schema ───────────────────────────────────────────
|
|
350
|
-
const schemaPath = schemaPathFromProject(config, cwd)
|
|
351
|
-
const supatypeDir = join(cwd, ".supatype")
|
|
352
|
-
const manifestPath = join(supatypeDir, "manifest.json")
|
|
353
|
-
const adminConfigPath = join(supatypeDir, "admin-config.json")
|
|
354
|
-
mkdirSync(supatypeDir, { recursive: true })
|
|
355
|
-
|
|
356
|
-
const localStoragePath = config.storage?.provider !== "s3" ? join(stateRoot, "storage") : undefined
|
|
357
|
-
// Native Postgres builds don't include PostGIS, skip geo fields rather than failing.
|
|
358
|
-
const skipFieldKinds: ReadonlySet<string> = new Set(["geo", "vector"])
|
|
359
|
-
|
|
360
|
-
await runSchemaPush(cwd, engineBin, schemaPath, dbURL, manifestPath, adminConfigPath, localStoragePath, skipFieldKinds, config).catch(
|
|
361
|
-
(e: unknown) => console.error("[supatype] Initial schema push failed:", (e as Error).message),
|
|
362
|
-
)
|
|
363
|
-
|
|
364
|
-
const { ensureFirstAdminUser } = await import("./admin.js")
|
|
365
|
-
await ensureFirstAdminUser(dbURL, { cwd })
|
|
366
|
-
|
|
367
|
-
// ── 10. Spawn supatype-server ─────────────────────────────────────────
|
|
368
|
-
|
|
369
|
-
// Resolve edge functions config: only enable Deno if a functions dir exists.
|
|
370
|
-
const functionsDir = functionsPathCandidatesFromProject(config, cwd).find(dir => existsSync(dir))
|
|
371
|
-
const hasFunctionsDir = functionsDir !== undefined
|
|
372
|
-
/** Always set when a functions dir exists so Studio admin API can list functions; Deno runtime is separate. */
|
|
373
|
-
const denoFunctionsDir = hasFunctionsDir ? functionsDir : ""
|
|
374
|
-
const functionRoutes = hasFunctionsDir && functionsDir !== undefined
|
|
375
|
-
? discoverTsFunctionsInDir(functionsDir)
|
|
376
|
-
: []
|
|
377
|
-
const denoServeScriptAbs = hasFunctionsDir && functionsDir !== undefined
|
|
378
|
-
? (writeDevFunctionsRouter(cwd, functionsDir, functionRoutes) ?? "")
|
|
379
|
-
: ""
|
|
380
|
-
|
|
381
|
-
let denoBinPath: string | undefined
|
|
382
|
-
if (hasFunctionsDir) {
|
|
383
|
-
console.log(`[supatype] Edge functions enabled (${functionsDir})`)
|
|
384
|
-
try {
|
|
385
|
-
denoBinPath = await ensureBinary("deno", config)
|
|
386
|
-
const denoVersion = await (await import("../binary-cache.js")).resolveVersionFor("deno", config)
|
|
387
|
-
console.log(`[supatype] Deno runtime: ${denoBinPath} (v${denoVersion})`)
|
|
388
|
-
if (functionRoutes.length > 0) {
|
|
389
|
-
console.log(
|
|
390
|
-
`[supatype] Edge functions router: ${relative(cwd, denoServeScriptAbs) || ".supatype/functions-router.ts"} ` +
|
|
391
|
-
`(${functionRoutes.length} function(s): ${functionRoutes.map(fn => fn.name).join(", ")})`,
|
|
392
|
-
)
|
|
393
|
-
} else {
|
|
394
|
-
console.log("[supatype] Edge functions router not generated (no handler files discovered yet)")
|
|
395
|
-
}
|
|
396
|
-
} catch (err) {
|
|
397
|
-
console.warn(
|
|
398
|
-
`[supatype] ⚠ Found ${functionsDir} but could not provision Deno, edge functions will not run.\n` +
|
|
399
|
-
` ${(err as Error).message}\n` +
|
|
400
|
-
" (Functions still appear in Studio; invocations need Deno.)",
|
|
401
|
-
)
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
// Matches SUPATYPE_HOOK_SEND_EMAIL_SECRETS symmetric format (dev only). Override via .env.
|
|
406
|
-
const LOCAL_SEND_EMAIL_HOOK_SECRETS =
|
|
407
|
-
"v1,whsec_abcdefghijklmnopqrstuvwxyz01234567"
|
|
408
|
-
const now = Math.floor(Date.now() / 1000)
|
|
409
|
-
const jwtBase = { iss: "supatype", iat: now, exp: now + 315_360_000 }
|
|
410
|
-
const anonKey = signJwt({ ...jwtBase, role: "anon" }, LOCAL_JWT_SECRET)
|
|
411
|
-
const serviceRoleKey = signJwt({ ...jwtBase, role: "service_role" }, LOCAL_JWT_SECRET)
|
|
412
|
-
|
|
413
|
-
const realtimeUrl = `http://127.0.0.1:${REALTIME_PORT}`
|
|
414
|
-
patchRouteManifest(manifestPath, {
|
|
415
|
-
realtime_enabled: true,
|
|
416
|
-
realtime_url: realtimeUrl,
|
|
417
|
-
})
|
|
418
|
-
|
|
419
|
-
writeAppViteEnv(cwd, config, `http://localhost:${serverPort}`, anonKey)
|
|
420
|
-
|
|
421
|
-
let realtimeProc: ProcessManager | null = null
|
|
422
|
-
try {
|
|
423
|
-
const launch = await resolveRealtimeLaunch(config, cwd)
|
|
424
|
-
realtimeProc = new ProcessManager(launch.bin, launch.args, {
|
|
425
|
-
label: "realtime",
|
|
426
|
-
pidDir,
|
|
427
|
-
colour: "\x1b[35m",
|
|
428
|
-
env: {
|
|
429
|
-
DATABASE_URL: dbURL,
|
|
430
|
-
JWT_SECRET: LOCAL_JWT_SECRET,
|
|
431
|
-
PORT: REALTIME_PORT,
|
|
432
|
-
SLOT_NAME: "supatype_realtime",
|
|
433
|
-
PUBLICATION_NAME: "supatype_realtime",
|
|
434
|
-
},
|
|
435
|
-
})
|
|
436
|
-
realtimeProc.start()
|
|
437
|
-
console.log(`[supatype] Realtime service: ${realtimeUrl}`)
|
|
438
|
-
} catch (err) {
|
|
439
|
-
console.warn(
|
|
440
|
-
`[supatype] ⚠ Realtime unavailable, WebSocket subscriptions will not work.\n` +
|
|
441
|
-
` ${(err as Error).message}`,
|
|
442
|
-
)
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
const emailProvider = config.email?.provider ?? "console"
|
|
447
|
-
const authMailerProvider =
|
|
448
|
-
emailProvider === "console"
|
|
449
|
-
? "console"
|
|
450
|
-
: emailProvider === "resend"
|
|
451
|
-
? "resend"
|
|
452
|
-
: emailProvider === "ses"
|
|
453
|
-
? "ses"
|
|
454
|
-
: "smtp"
|
|
455
|
-
|
|
456
|
-
// Postgres serves RESP itself when the archive had pg_keyspace and the
|
|
457
|
-
// port came up. The probe is not ceremony: shared memory limits, a
|
|
458
|
-
// preload ordering mistake or a port taken between the check and the
|
|
459
|
-
// start all leave a Postgres that is running and a keyspace that is not,
|
|
460
|
-
// and the difference is a cache that silently never hits.
|
|
461
|
-
const nativeKeyspaceAddr =
|
|
462
|
-
keyspacePort !== null && (await probeTcp("127.0.0.1", keyspacePort))
|
|
463
|
-
? `127.0.0.1:${keyspacePort}`
|
|
464
|
-
: null
|
|
465
|
-
if (keyspacePort !== null && nativeKeyspaceAddr === null) {
|
|
466
|
-
console.warn(
|
|
467
|
-
`[supatype] ⚠ Postgres has pg_keyspace but is not serving RESP on :${keyspacePort}. ` +
|
|
468
|
-
"See logs/postgres.log. Falling back to the Valkey sidecar.",
|
|
469
|
-
)
|
|
470
|
-
}
|
|
471
|
-
if (nativeKeyspaceAddr) {
|
|
472
|
-
console.log(`[supatype] Keyspace served by Postgres (${nativeKeyspaceAddr}).`)
|
|
473
|
-
}
|
|
474
|
-
const valkeySidecar = nativeKeyspaceAddr
|
|
475
|
-
? { addr: nativeKeyspaceAddr, containerName: null, started: false }
|
|
476
|
-
: ensureValkeySidecar(projectName)
|
|
477
|
-
|
|
478
|
-
const serverEnv: Record<string, string> = {
|
|
479
|
-
// supatype-server outer layer
|
|
480
|
-
SUPATYPE_MODE: config.server.mode ?? "dev",
|
|
481
|
-
...(valkeySidecar.addr ? { SUPATYPE_VALKEY_ADDR: valkeySidecar.addr } : {}),
|
|
482
|
-
SUPATYPE_MANAGED_PROJECT_REF: projectName,
|
|
483
|
-
SUPATYPE_MANIFEST_PATH: manifestPath,
|
|
484
|
-
SUPATYPE_ADMIN_CONFIG_PATH: adminConfigPath,
|
|
485
|
-
SUPATYPE_POSTGREST_URL: `http://127.0.0.1:${postgrestPort}`,
|
|
486
|
-
SUPATYPE_DENO_FUNCTIONS_DIR: denoFunctionsDir,
|
|
487
|
-
...(denoFunctionsDir !== "" ? { SUPATYPE_SHARED_ENV_FILE: resolve(denoFunctionsDir, ".env.local") } : {}),
|
|
488
|
-
...(denoBinPath !== undefined ? { SUPATYPE_DENO_PATH: denoBinPath } : {}),
|
|
489
|
-
...(denoServeScriptAbs !== ""
|
|
490
|
-
? { SUPATYPE_DENO_SERVE_SCRIPT: denoServeScriptAbs }
|
|
491
|
-
: {}),
|
|
492
|
-
SUPATYPE_URL: `http://localhost:${serverPort}`,
|
|
493
|
-
SUPATYPE_REALTIME_URL: realtimeUrl,
|
|
494
|
-
SUPATYPE_ANON_KEY: anonKey,
|
|
495
|
-
SUPATYPE_SERVICE_ROLE_KEY: serviceRoleKey,
|
|
496
|
-
PORT: serverPort,
|
|
497
|
-
SUPATYPE_APP_MODE: config.app.mode ?? "none",
|
|
498
|
-
...(config.app.mode === "static" && config.app.static_dir?.trim()
|
|
499
|
-
? { SUPATYPE_APP_STATIC_DIR: resolve(cwd, config.app.static_dir.trim()) }
|
|
500
|
-
: {}),
|
|
501
|
-
...(config.app.mode === "proxy" && config.app.upstream?.trim()
|
|
502
|
-
? { SUPATYPE_APP_UPSTREAM: config.app.upstream.trim() }
|
|
503
|
-
: {}),
|
|
504
|
-
...(config.app.vite_dev_url !== undefined && config.app.vite_dev_url.trim() !== ""
|
|
505
|
-
? { SUPATYPE_VITE_DEV_URL: config.app.vite_dev_url.trim() }
|
|
506
|
-
: {}),
|
|
507
|
-
// Auth service required fields (sensible local-dev defaults)
|
|
508
|
-
SUPATYPE_DB_DATABASE_URL: authDbURL,
|
|
509
|
-
DATABASE_URL: authDbURL,
|
|
510
|
-
SUPATYPE_SQL_DATABASE_URL: dbURL,
|
|
511
|
-
PGSSLMODE: "disable",
|
|
512
|
-
SUPATYPE_DB_NAMESPACE: "auth",
|
|
513
|
-
SUPATYPE_DB_DRIVER: "postgres",
|
|
514
|
-
SUPATYPE_JWT_SECRET: LOCAL_JWT_SECRET,
|
|
515
|
-
SUPATYPE_JWT_EXP: "3600",
|
|
516
|
-
SUPATYPE_JWT_AUD: "authenticated",
|
|
517
|
-
SUPATYPE_JWT_ADMIN_ROLES: "supatype_admin,service_role",
|
|
518
|
-
SUPATYPE_API_EXTERNAL_URL: `http://localhost:${serverPort}/auth/v1`,
|
|
519
|
-
SUPATYPE_API_HOST: "localhost",
|
|
520
|
-
SUPATYPE_SITE_URL: `http://localhost:${serverPort}`,
|
|
521
|
-
SUPATYPE_MAILER_MAILER_PROVIDER: authMailerProvider,
|
|
522
|
-
SUPATYPE_MAILER_AUTOCONFIRM: "true",
|
|
523
|
-
SUPATYPE_LOG_LEVEL: "info",
|
|
524
|
-
SUPATYPE_DISABLE_SIGNUP: "false",
|
|
525
|
-
...(config.email?.resend_api_key !== undefined && config.email.resend_api_key !== ""
|
|
526
|
-
? { RESEND_API_KEY: config.email.resend_api_key }
|
|
527
|
-
: {}),
|
|
528
|
-
...(authMailerProvider === "resend" &&
|
|
529
|
-
config.email?.resend_from !== undefined &&
|
|
530
|
-
config.email.resend_from.trim() !== ""
|
|
531
|
-
? { RESEND_FROM: config.email.resend_from.trim() }
|
|
532
|
-
: {}),
|
|
533
|
-
...(authMailerProvider === "ses" &&
|
|
534
|
-
config.email?.ses_from !== undefined &&
|
|
535
|
-
config.email.ses_from.trim() !== ""
|
|
536
|
-
? { SES_FROM: config.email.ses_from.trim() }
|
|
537
|
-
: {}),
|
|
538
|
-
...(authMailerProvider === "smtp" ? authSMTPFromEmailConfig(config.email) : {}),
|
|
539
|
-
...(config.email?.send_email_hook === true
|
|
540
|
-
? {
|
|
541
|
-
SUPATYPE_HOOK_SEND_EMAIL_ENABLED: "true",
|
|
542
|
-
SUPATYPE_HOOK_SEND_EMAIL_URI:
|
|
543
|
-
config.email?.send_email_hook_uri !== undefined &&
|
|
544
|
-
config.email.send_email_hook_uri.trim() !== ""
|
|
545
|
-
? config.email.send_email_hook_uri.trim()
|
|
546
|
-
: `http://127.0.0.1:${serverPort}/internal/v0hooks/send-email`,
|
|
547
|
-
SUPATYPE_HOOK_SEND_EMAIL_SECRETS:
|
|
548
|
-
config.email?.send_email_hook_secrets !== undefined &&
|
|
549
|
-
config.email.send_email_hook_secrets.trim() !== ""
|
|
550
|
-
? config.email.send_email_hook_secrets.trim()
|
|
551
|
-
: LOCAL_SEND_EMAIL_HOOK_SECRETS,
|
|
552
|
-
}
|
|
553
|
-
: {}),
|
|
554
|
-
...(config.storage?.provider !== "s3" ? localStorageEnv(stateRoot) : {}),
|
|
555
|
-
...loadDotEnv(cwd),
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
const serverProc = new ProcessManager(serverBin, [], {
|
|
559
|
-
label: "server",
|
|
560
|
-
pidDir,
|
|
561
|
-
colour: "\x1b[32m",
|
|
562
|
-
env: serverEnv,
|
|
563
|
-
})
|
|
564
|
-
serverProc.start()
|
|
565
|
-
|
|
566
|
-
// ── 9b. PostgREST ────────────────────────────────────────────────────
|
|
567
|
-
let postgrestProc: ProcessManager | null = null
|
|
568
|
-
const postgrestBin = await resolvePostgrestBin(config.overrides?.postgrest)
|
|
569
|
-
if (postgrestBin) {
|
|
570
|
-
// Windows PostgREST builds are dynamically linked and require libpq/OpenSSL
|
|
571
|
-
// DLLs from a Postgres bin directory, even when the database runs in Docker.
|
|
572
|
-
let postgrestRuntimeBinDir = pgBinDir
|
|
573
|
-
if (process.platform === "win32" && postgrestRuntimeBinDir === null) {
|
|
574
|
-
try {
|
|
575
|
-
postgrestRuntimeBinDir = await resolvePgBinDir(config)
|
|
576
|
-
} catch (error) {
|
|
577
|
-
console.warn(
|
|
578
|
-
`[supatype] ⚠ Could not resolve Postgres runtime DLL directory for PostgREST: ${(error as Error).message}\n` +
|
|
579
|
-
" PostgREST may fail to start on Windows until Postgres binaries are available locally.",
|
|
580
|
-
)
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
const postgrestEnv: Record<string, string> = {
|
|
585
|
-
PGRST_DB_URI: postgrestDbURL,
|
|
586
|
-
// Derived from schema.pg_schema (or schema.api_schemas), a hardcoded "public" here meant
|
|
587
|
-
// a non-default pg_schema pushed correctly and then answered PGRST106 on every request.
|
|
588
|
-
// Native dev has no masking extension either, so a schema with field rules is served from
|
|
589
|
-
// `api` here too: the case an "is the database external" rule would have got wrong.
|
|
590
|
-
PGRST_DB_SCHEMA: apiSchemaList(config, {
|
|
591
|
-
// The installed archive decides: one downloaded before the masking library was bundled
|
|
592
|
-
// has no extension, so its field rules are enforced by views instead.
|
|
593
|
-
tier: fieldMaskingTierFromProject(cwd, config, nativeMaskLibraryPresent(pgBinDir)),
|
|
594
|
-
// A versioned model adds the generated `draft` schema, or `.draft()` would answer
|
|
595
|
-
// PGRST106 against a stack that had migrated the views into place.
|
|
596
|
-
drafts: projectHasVersionedModels(cwd, config),
|
|
597
|
-
}),
|
|
598
|
-
// Parity with self-host, which has always set this. Unqualified names in column defaults
|
|
599
|
-
// (`uuid_generate_v4()`) resolve here, and with a non-public pg_schema the request schema
|
|
600
|
-
// alone does not reach them.
|
|
601
|
-
PGRST_DB_EXTRA_SEARCH_PATH: "public,extensions",
|
|
602
|
-
PGRST_DB_ANON_ROLE: "anon",
|
|
603
|
-
PGRST_SERVER_PORT: postgrestPort,
|
|
604
|
-
PGRST_SERVER_HOST: "127.0.0.1",
|
|
605
|
-
PGRST_JWT_SECRET: serverEnv["SUPATYPE_JWT_SECRET"] ?? "",
|
|
606
|
-
PGRST_LOG_LEVEL: "warn",
|
|
607
|
-
// On Windows, PostgREST (MinGW/GHC binary) needs libpq.dll and
|
|
608
|
-
// OpenSSL DLLs. Prepend a Postgres bin dir which bundles these
|
|
609
|
-
// runtime dependencies.
|
|
610
|
-
...(process.platform === "win32" && postgrestRuntimeBinDir !== null
|
|
611
|
-
? { PATH: `${postgrestRuntimeBinDir};${process.env["PATH"] ?? ""}` }
|
|
612
|
-
: {}),
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
const preflight = spawnSync(
|
|
616
|
-
postgrestBin,
|
|
617
|
-
["--help"],
|
|
618
|
-
{ env: { ...process.env, ...postgrestEnv }, stdio: "pipe", encoding: "utf8" },
|
|
619
|
-
)
|
|
620
|
-
if (preflight.status !== 0) {
|
|
621
|
-
const detail = (preflight.stderr || preflight.stdout || "").trim()
|
|
622
|
-
console.warn(
|
|
623
|
-
`[supatype] ⚠ PostgREST failed preflight (exit ${preflight.status}). ` +
|
|
624
|
-
"Skipping /rest/v1 startup to avoid crash loop.",
|
|
625
|
-
)
|
|
626
|
-
if (detail) {
|
|
627
|
-
console.warn(`[supatype] PostgREST preflight output:\n${detail}`)
|
|
628
|
-
}
|
|
629
|
-
} else {
|
|
630
|
-
postgrestProc = new ProcessManager(postgrestBin, [], {
|
|
631
|
-
label: "postgrest",
|
|
632
|
-
pidDir,
|
|
633
|
-
colour: "\x1b[36m",
|
|
634
|
-
env: postgrestEnv,
|
|
635
|
-
})
|
|
636
|
-
postgrestProc.start()
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
// ── 9d. Studio (optional) ─────────────────────────────────────────────
|
|
641
|
-
const studioPort = STUDIO_DEV_PORT
|
|
642
|
-
let studioProc: ProcessManager | null = null
|
|
643
|
-
|
|
644
|
-
const studioOverride = config.overrides?.studio
|
|
645
|
-
if (studioOverride) {
|
|
646
|
-
studioProc = startStudioViteDevServer({
|
|
647
|
-
cwd,
|
|
648
|
-
studioOverride,
|
|
649
|
-
pidDir,
|
|
650
|
-
anonKey,
|
|
651
|
-
proxyTarget: `http://localhost:${serverPort}`,
|
|
652
|
-
viteSupatypeUrl: `http://localhost:${studioPort}`,
|
|
653
|
-
})
|
|
654
|
-
studioProc?.start()
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
const appProc = startProxyDevApp(cwd, config, pidDir)
|
|
658
|
-
|
|
659
|
-
const links = [
|
|
660
|
-
{ label: "API", url: `http://localhost:${serverPort}` },
|
|
661
|
-
{ label: "REST", url: `http://localhost:${serverPort}/rest/v1/` },
|
|
662
|
-
{ label: "Auth", url: `http://localhost:${serverPort}/auth/v1/` },
|
|
663
|
-
{ label: "Storage", url: `http://localhost:${serverPort}/storage/v1/` },
|
|
664
|
-
{ label: "Realtime", url: `ws://localhost:${serverPort}/realtime/v1/` },
|
|
665
|
-
]
|
|
666
|
-
if (studioProc) {
|
|
667
|
-
links.push({ label: "Studio", url: `http://localhost:${studioPort}` })
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
publishDevReady({
|
|
671
|
-
title: "Services running",
|
|
672
|
-
links,
|
|
673
|
-
anonKey,
|
|
674
|
-
serviceRoleKey,
|
|
675
|
-
hints: [`Postgres ${dbURL}`, `JWT secret: #${secretFingerprint(LOCAL_JWT_SECRET)} (in .env)`],
|
|
676
|
-
})
|
|
677
|
-
|
|
678
|
-
// ── Shutdown handler ──────────────────────────────────────────────────
|
|
679
|
-
registerDevShutdown(async () => {
|
|
680
|
-
console.log("[supatype] Shutting down...")
|
|
681
|
-
await Promise.all([
|
|
682
|
-
serverProc.stop(),
|
|
683
|
-
realtimeProc?.stop(),
|
|
684
|
-
postgrestProc?.stop(),
|
|
685
|
-
studioProc?.stop(),
|
|
686
|
-
appProc?.stop(),
|
|
687
|
-
])
|
|
688
|
-
stopValkeySidecar(valkeySidecar.containerName)
|
|
689
|
-
await stopPostgres()
|
|
690
|
-
})
|
|
691
|
-
|
|
692
|
-
// ── 10. Schema watch ──────────────────────────────────────────────────
|
|
693
|
-
if (opts.watch) {
|
|
694
|
-
const schemaDir = resolve(cwd, schemaPath, "..")
|
|
695
|
-
console.log(`[supatype] Watching ${schemaDir} for changes...`)
|
|
696
|
-
|
|
697
|
-
const { watch } = await import("node:fs")
|
|
698
|
-
// Debounce: Windows fs.watch fires multiple events per save.
|
|
699
|
-
// Wait 300 ms after the last event before pushing.
|
|
700
|
-
let debounceTimer: ReturnType<typeof setTimeout> | null = null
|
|
701
|
-
watch(schemaDir, { recursive: true }, (_eventType, filename) => {
|
|
702
|
-
if (!filename?.endsWith(".ts")) return
|
|
703
|
-
if (debounceTimer) clearTimeout(debounceTimer)
|
|
704
|
-
debounceTimer = setTimeout(() => {
|
|
705
|
-
debounceTimer = null
|
|
706
|
-
console.log(`\n[supatype] Change detected in ${filename}, checking schema...`)
|
|
707
|
-
runSchemaPush(cwd, engineBin, schemaPath, dbURL, manifestPath, adminConfigPath, localStoragePath, skipFieldKinds, config).catch((e: unknown) =>
|
|
708
|
-
console.error("[supatype] Schema push failed:", (e as Error).message),
|
|
709
|
-
)
|
|
710
|
-
}, 300)
|
|
711
|
-
})
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
// Block until killed.
|
|
715
|
-
await new Promise<never>(() => undefined)
|
|
716
|
-
})
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
// ---------------------------------------------------------------------------
|
|
720
|
-
// Schema push (engine subprocess)
|
|
721
|
-
// ---------------------------------------------------------------------------
|
|
722
|
-
|
|
723
|
-
// Last successfully-pushed AST JSON, used to skip no-op re-fires.
|
|
724
|
-
let _lastPushedAst: string | null = null
|
|
725
|
-
// AST that failed on its last attempt, always retried even if content is unchanged.
|
|
726
|
-
let _lastFailedAst: string | null = null
|
|
727
|
-
|
|
728
|
-
async function runSchemaPush(
|
|
729
|
-
cwd: string,
|
|
730
|
-
engineBin: string,
|
|
731
|
-
schemaPath: string,
|
|
732
|
-
dbURL: string,
|
|
733
|
-
manifestPath: string,
|
|
734
|
-
adminConfigPath?: string,
|
|
735
|
-
storagePath?: string,
|
|
736
|
-
skipFieldKinds?: ReadonlySet<string>,
|
|
737
|
-
config?: import("../project-config.js").SupatypeProjectConfig,
|
|
738
|
-
): Promise<void> {
|
|
739
|
-
// Build AST JSON from schema file.
|
|
740
|
-
const { loadSchemaAst } = await import("../config.js")
|
|
741
|
-
let ast = loadSchemaAst(schemaPath, cwd)
|
|
742
|
-
|
|
743
|
-
// Strip fields whose kind requires an unavailable Postgres extension.
|
|
744
|
-
if (skipFieldKinds && skipFieldKinds.size > 0) {
|
|
745
|
-
const { filtered, adapted } = adaptUnsupportedKinds(ast, skipFieldKinds)
|
|
746
|
-
ast = filtered
|
|
747
|
-
if (adapted.length > 0) {
|
|
748
|
-
console.warn(
|
|
749
|
-
`[supatype] ⚠ ${adapted.length} field(s) replaced with JSONB, required extensions not available:\n` +
|
|
750
|
-
adapted.map((s: string) => ` ${s}`).join("\n"),
|
|
751
|
-
)
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
const astJson = JSON.stringify(ast)
|
|
756
|
-
|
|
757
|
-
// Skip only when the last push of this exact AST succeeded.
|
|
758
|
-
// If it previously failed we always retry so the user can trigger a re-run
|
|
759
|
-
// by simply saving the file again without needing to make a content change.
|
|
760
|
-
if (astJson === _lastPushedAst && astJson !== _lastFailedAst) {
|
|
761
|
-
return
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
const astPath = join(cwd, ".supatype", "schema.ast.json")
|
|
765
|
-
writeFileSync(astPath, astJson)
|
|
766
|
-
|
|
767
|
-
// Push schema.
|
|
768
|
-
console.log("[supatype] Applying schema...")
|
|
769
|
-
const { ensureEngine, engineRequest } = await import("../engine-client.js")
|
|
770
|
-
const { writeSchemaSourcePushArtifacts } = await import("../schema-sources.js")
|
|
771
|
-
await ensureEngine()
|
|
772
|
-
const pgSchema = config?.schema?.pg_schema ?? "public"
|
|
773
|
-
const sources = writeSchemaSourcePushArtifacts(cwd)
|
|
774
|
-
try {
|
|
775
|
-
const result = await engineRequest<EnginePushResult>("/push", {
|
|
776
|
-
ast,
|
|
777
|
-
database_url: dbURL,
|
|
778
|
-
schema: pgSchema,
|
|
779
|
-
force: true,
|
|
780
|
-
...(sources
|
|
781
|
-
? {
|
|
782
|
-
schema_sources_gz_base64: sources.payload.dataBase64,
|
|
783
|
-
schema_sources_manifest: sources.payload.manifest,
|
|
784
|
-
}
|
|
785
|
-
: {}),
|
|
786
|
-
})
|
|
787
|
-
printPushWarnings(result)
|
|
788
|
-
} catch (err) {
|
|
789
|
-
_lastFailedAst = astJson
|
|
790
|
-
throw err
|
|
791
|
-
}
|
|
792
|
-
_lastPushedAst = astJson
|
|
793
|
-
_lastFailedAst = null
|
|
794
|
-
|
|
795
|
-
// Provision storage buckets declared in the schema.
|
|
796
|
-
if (storagePath) {
|
|
797
|
-
const parseResult = spawnSync(engineBin, ["parse", "-i", astPath], { cwd, stdio: "pipe", encoding: "utf8" })
|
|
798
|
-
if (parseResult.status === 0 && parseResult.stdout) {
|
|
799
|
-
try {
|
|
800
|
-
const resolvedAst = JSON.parse(parseResult.stdout) as {
|
|
801
|
-
storageBuckets?: Array<{
|
|
802
|
-
id: string
|
|
803
|
-
public: boolean
|
|
804
|
-
allowedMimeTypes?: string[]
|
|
805
|
-
fileSizeLimit?: number
|
|
806
|
-
accessMode?: string
|
|
807
|
-
s3BucketPolicy?: string | null
|
|
808
|
-
}>
|
|
809
|
-
}
|
|
810
|
-
if (resolvedAst.storageBuckets && resolvedAst.storageBuckets.length > 0) {
|
|
811
|
-
provisionStorageBuckets(resolvedAst.storageBuckets, storagePath)
|
|
812
|
-
}
|
|
813
|
-
} catch { /* ignore parse errors */ }
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
// Generate manifest.
|
|
818
|
-
const genResult = spawnSync(
|
|
819
|
-
engineBin,
|
|
820
|
-
["generate", "-i", astPath, "-o", manifestPath],
|
|
821
|
-
{ cwd, stdio: "pipe", encoding: "utf8" },
|
|
822
|
-
)
|
|
823
|
-
if (genResult.status !== 0) {
|
|
824
|
-
console.warn("[supatype] Manifest generation failed, server routing may be stale.")
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
// Generate admin config (for Studio). Engine writes to stdout.
|
|
828
|
-
if (adminConfigPath) {
|
|
829
|
-
const adminResult = spawnSync(
|
|
830
|
-
engineBin,
|
|
831
|
-
["admin", "-i", astPath],
|
|
832
|
-
{ cwd, stdio: "pipe", encoding: "utf8" },
|
|
833
|
-
)
|
|
834
|
-
if (adminResult.status === 0 && adminResult.stdout) {
|
|
835
|
-
const { withAdminRoles } = await import("../studio-admin-roles.js")
|
|
836
|
-
let admin: unknown
|
|
837
|
-
try {
|
|
838
|
-
admin = JSON.parse(adminResult.stdout) as unknown
|
|
839
|
-
} catch {
|
|
840
|
-
admin = adminResult.stdout
|
|
841
|
-
}
|
|
842
|
-
restoreSystemRelationTargets(admin, ast)
|
|
843
|
-
const merged = config ? withAdminRoles(admin, config) : admin
|
|
844
|
-
writeFileSync(adminConfigPath, `${JSON.stringify(merged, null, 2)}\n`)
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
console.log("[supatype] Schema applied.")
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
function provisionStorageBuckets(
|
|
852
|
-
declared: Array<{
|
|
853
|
-
id: string
|
|
854
|
-
public: boolean
|
|
855
|
-
allowedMimeTypes?: string[]
|
|
856
|
-
fileSizeLimit?: number
|
|
857
|
-
accessMode?: string
|
|
858
|
-
s3BucketPolicy?: string | null
|
|
859
|
-
}>,
|
|
860
|
-
storagePath: string,
|
|
861
|
-
): void {
|
|
862
|
-
const bucketsDir = join(storagePath, ".supatype")
|
|
863
|
-
const bucketsFile = join(bucketsDir, "buckets.json")
|
|
864
|
-
mkdirSync(bucketsDir, { recursive: true })
|
|
865
|
-
|
|
866
|
-
let existing: Array<Record<string, unknown>> = []
|
|
867
|
-
try {
|
|
868
|
-
existing = JSON.parse(readFileSync(bucketsFile, "utf8")) as Array<Record<string, unknown>>
|
|
869
|
-
} catch { /* file doesn't exist yet */ }
|
|
870
|
-
|
|
871
|
-
const existingIds = new Set(existing.map((b) => b["id"] as string))
|
|
872
|
-
let added = 0
|
|
873
|
-
|
|
874
|
-
for (const bucket of declared) {
|
|
875
|
-
if (existingIds.has(bucket.id)) continue
|
|
876
|
-
const now = new Date().toISOString()
|
|
877
|
-
existing.push({
|
|
878
|
-
id: bucket.id,
|
|
879
|
-
name: bucket.id,
|
|
880
|
-
public: bucket.public,
|
|
881
|
-
file_size_limit: bucket.fileSizeLimit ?? null,
|
|
882
|
-
allowed_mime_types: bucket.allowedMimeTypes ?? null,
|
|
883
|
-
access_mode:
|
|
884
|
-
bucket.accessMode ?? (bucket.public ? "public" : "private"),
|
|
885
|
-
s3_bucket_policy: bucket.s3BucketPolicy ?? null,
|
|
886
|
-
created_at: now,
|
|
887
|
-
updated_at: now,
|
|
888
|
-
})
|
|
889
|
-
mkdirSync(join(storagePath, bucket.id), { recursive: true })
|
|
890
|
-
added++
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
if (added > 0) {
|
|
894
|
-
writeFileSync(bucketsFile, JSON.stringify(existing, null, 2))
|
|
895
|
-
console.log(`[supatype] Storage: provisioned ${added} bucket(s).`)
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
// ---------------------------------------------------------------------------
|
|
900
|
-
// Resolve Postgres bin dir
|
|
901
|
-
// ---------------------------------------------------------------------------
|
|
902
|
-
|
|
903
|
-
async function resolvePgBinDir(config: Awaited<ReturnType<typeof loadConfig>>): Promise<string> {
|
|
904
|
-
const override = config.overrides?.postgres_dir
|
|
905
|
-
if (override) {
|
|
906
|
-
// Normalize Git Bash (/c/Users/...) paths to Win32 form (C:\Users\...) on Windows.
|
|
907
|
-
const normalised = normalisePlatformPath(override)
|
|
908
|
-
const resolved = resolve(process.cwd(), normalised)
|
|
909
|
-
const binDir = join(resolved, "bin")
|
|
910
|
-
if (!existsSync(binDir)) {
|
|
911
|
-
throw new Error(`[overrides] postgres_dir does not contain a bin/ directory: ${resolved}`)
|
|
912
|
-
}
|
|
913
|
-
console.warn(`\u26a0 Using local Postgres build: ${resolved}`)
|
|
914
|
-
return binDir
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
// Locate cached Postgres archive.
|
|
918
|
-
const { cachePath, currentPlatform, resolveVersionFor } = await import("../binary-cache.js")
|
|
919
|
-
const platform = currentPlatform()
|
|
920
|
-
const version = await resolveVersionFor("postgres", config)
|
|
921
|
-
|
|
922
|
-
const pgCacheDir = cachePath("postgres", version)
|
|
923
|
-
const extractedDir = join(pgCacheDir, `pg-${version}`)
|
|
924
|
-
|
|
925
|
-
const pgCtlName = platform.os === "windows" ? "pg_ctl.exe" : "pg_ctl"
|
|
926
|
-
if (!existsSync(join(extractedDir, "bin", pgCtlName))) {
|
|
927
|
-
// Try to extract the cached archive.
|
|
928
|
-
await extractPostgresArchive(pgCacheDir, version, platform, extractedDir)
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
return join(extractedDir, "bin")
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
async function extractPostgresArchive(
|
|
935
|
-
pgCacheDir: string,
|
|
936
|
-
version: string,
|
|
937
|
-
platform: { os: string; arch: string },
|
|
938
|
-
extractDir: string,
|
|
939
|
-
): Promise<void> {
|
|
940
|
-
const ext = platform.os === "windows" ? ".zip" : ".tar.gz"
|
|
941
|
-
const archiveName = `supatype-pg-${postgresArchiveTag(version)}-${platform.os}-${platform.arch}${ext}`
|
|
942
|
-
const archivePath = join(pgCacheDir, archiveName)
|
|
943
|
-
|
|
944
|
-
if (!existsSync(archivePath)) {
|
|
945
|
-
throw new Error(
|
|
946
|
-
`Postgres ${version} archive not found. Run: supatype update`,
|
|
947
|
-
)
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
mkdirSync(extractDir, { recursive: true })
|
|
951
|
-
|
|
952
|
-
// On Windows, Git Bash tar is typically first in PATH and chokes on drive-letter
|
|
953
|
-
// paths (C:\...). Use PowerShell's Expand-Archive instead, which handles Windows
|
|
954
|
-
// paths natively. On Linux/macOS, use tar as normal.
|
|
955
|
-
const result = platform.os === "windows"
|
|
956
|
-
? spawnSync(
|
|
957
|
-
"powershell.exe",
|
|
958
|
-
["-NoProfile", "-Command", `Expand-Archive -Path '${archivePath}' -DestinationPath '${extractDir}' -Force`],
|
|
959
|
-
{ stdio: "inherit" },
|
|
960
|
-
)
|
|
961
|
-
: spawnSync("tar", ["-xzf", archivePath, "-C", extractDir], { stdio: "inherit" })
|
|
962
|
-
|
|
963
|
-
if (result.status !== 0) {
|
|
964
|
-
throw new Error(`Failed to extract Postgres archive: ${archivePath}`)
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
// ---------------------------------------------------------------------------
|
|
969
|
-
// PostgREST resolver: downloads from GitHub releases if not cached
|
|
970
|
-
// ---------------------------------------------------------------------------
|
|
971
|
-
|
|
972
|
-
const POSTGREST_DEFAULT_VERSION = "12.2.3"
|
|
973
|
-
const POSTGREST_GITHUB = "https://github.com/PostgREST/postgrest/releases/download"
|
|
974
|
-
|
|
975
|
-
async function resolvePostgrestBin(overridePath?: string): Promise<string | null> {
|
|
976
|
-
// Honour local override (same pattern as engine/server).
|
|
977
|
-
if (overridePath) {
|
|
978
|
-
let p = resolve(process.cwd(), normalisePlatformPath(overridePath))
|
|
979
|
-
if (process.platform === "win32" && !p.endsWith(".exe") && !existsSync(p)) {
|
|
980
|
-
const withExe = p + ".exe"
|
|
981
|
-
if (existsSync(withExe)) p = withExe
|
|
982
|
-
}
|
|
983
|
-
if (existsSync(p)) return p
|
|
984
|
-
console.warn(`[supatype] ⚠ PostgREST override not found at ${p}`)
|
|
985
|
-
return null
|
|
986
|
-
}
|
|
987
|
-
|
|
988
|
-
const version = POSTGREST_DEFAULT_VERSION
|
|
989
|
-
const platform = currentPlatform()
|
|
990
|
-
const arch = platform.arch === "arm64" ? "aarch64" : "x86_64"
|
|
991
|
-
const binName = platform.os === "windows" ? "postgrest.exe" : "postgrest"
|
|
992
|
-
const cacheDir = cachePath("postgres", version).replace(/postgres/, "postgrest")
|
|
993
|
-
const binPath = join(cacheDir, binName)
|
|
994
|
-
const archiveName = platform.os === "windows"
|
|
995
|
-
? `postgrest-v${version}-windows-x64.zip`
|
|
996
|
-
: platform.os === "darwin"
|
|
997
|
-
? `postgrest-v${version}-macos-${arch}.tar.xz`
|
|
998
|
-
: `postgrest-v${version}-linux-static-${arch}.tar.xz`
|
|
999
|
-
const archivePath = join(cacheDir, archiveName)
|
|
1000
|
-
|
|
1001
|
-
if (existsSync(binPath)) {
|
|
1002
|
-
// Backfill DLLs for older cached Windows installs where only postgrest.exe
|
|
1003
|
-
// was copied from the release archive.
|
|
1004
|
-
if (platform.os === "windows" && !hasLikelyWindowsRuntimeDlls(cacheDir) && existsSync(archivePath)) {
|
|
1005
|
-
const repaired = repairWindowsPostgrestRuntime(cacheDir, archivePath, binPath)
|
|
1006
|
-
if (!repaired) {
|
|
1007
|
-
console.warn("[supatype] ⚠ PostgREST runtime DLL repair failed; REST API may be unavailable.")
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
1010
|
-
return binPath
|
|
1011
|
-
}
|
|
1012
|
-
|
|
1013
|
-
// Download from GitHub releases.
|
|
1014
|
-
const url = `${POSTGREST_GITHUB}/v${version}/${archiveName}`
|
|
1015
|
-
|
|
1016
|
-
console.log(`[supatype] Downloading PostgREST v${version}...`)
|
|
1017
|
-
mkdirSync(cacheDir, { recursive: true })
|
|
1018
|
-
|
|
1019
|
-
let resp: Response
|
|
1020
|
-
try {
|
|
1021
|
-
resp = await fetch(url)
|
|
1022
|
-
} catch (e) {
|
|
1023
|
-
console.warn(
|
|
1024
|
-
`[supatype] ⚠ Could not download PostgREST (${(e as Error).message}).\n` +
|
|
1025
|
-
` REST API (/rest/v1/) will be unavailable until the download succeeds.\n` +
|
|
1026
|
-
` Re-run 'supatype dev' once network access to github.com:443 is restored.`,
|
|
1027
|
-
)
|
|
1028
|
-
return null
|
|
1029
|
-
}
|
|
1030
|
-
if (!resp.ok) {
|
|
1031
|
-
console.warn(`[supatype] ⚠ Could not download PostgREST: HTTP ${resp.status}. REST API will be unavailable.`)
|
|
1032
|
-
return null
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
const buf = Buffer.from(await resp.arrayBuffer())
|
|
1036
|
-
writeFileSync(archivePath, buf)
|
|
1037
|
-
|
|
1038
|
-
// Extract. The Windows zip may nest postgrest.exe inside a subdirectory, so
|
|
1039
|
-
// after Expand-Archive we copy postgrest.exe and sibling DLLs to cacheDir.
|
|
1040
|
-
if (platform.os === "windows") {
|
|
1041
|
-
const r = spawnSync(
|
|
1042
|
-
"powershell.exe",
|
|
1043
|
-
[
|
|
1044
|
-
"-NoProfile", "-Command",
|
|
1045
|
-
`Expand-Archive -Path '${archivePath}' -DestinationPath '${cacheDir}' -Force; ` +
|
|
1046
|
-
`$exe = Get-ChildItem -Path '${cacheDir}' -Recurse -Filter 'postgrest.exe' | Select-Object -First 1; ` +
|
|
1047
|
-
`if ($exe) { ` +
|
|
1048
|
-
` Copy-Item -Path $exe.FullName -Destination '${binPath}' -Force; ` +
|
|
1049
|
-
` Get-ChildItem -Path $exe.Directory.FullName -Filter '*.dll' | ` +
|
|
1050
|
-
` ForEach-Object { Copy-Item -Path $_.FullName -Destination '${cacheDir}' -Force }; ` +
|
|
1051
|
-
`}`,
|
|
1052
|
-
],
|
|
1053
|
-
{ stdio: "pipe", encoding: "utf8" },
|
|
1054
|
-
)
|
|
1055
|
-
if (r.status !== 0) {
|
|
1056
|
-
console.warn(`[supatype] ⚠ PostgREST extraction failed: ${r.stderr?.trim() ?? "unknown error"}. REST API will be unavailable.`)
|
|
1057
|
-
return null
|
|
1058
|
-
}
|
|
1059
|
-
} else {
|
|
1060
|
-
const r = spawnSync("tar", ["-xJf", archivePath, "-C", cacheDir], { stdio: "pipe" })
|
|
1061
|
-
if (r.status !== 0) {
|
|
1062
|
-
console.warn("[supatype] ⚠ PostgREST extraction failed. REST API will be unavailable.")
|
|
1063
|
-
return null
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
|
|
1067
|
-
if (!existsSync(binPath)) {
|
|
1068
|
-
console.warn("[supatype] ⚠ PostgREST binary not found after extraction. REST API will be unavailable.")
|
|
1069
|
-
return null
|
|
1070
|
-
}
|
|
1071
|
-
|
|
1072
|
-
if (platform.os !== "windows") {
|
|
1073
|
-
const { chmod } = await import("node:fs/promises")
|
|
1074
|
-
await chmod(binPath, 0o755)
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
console.log(`[supatype] PostgREST v${version} ready.`)
|
|
1078
|
-
return binPath
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
function hasLikelyWindowsRuntimeDlls(dir: string): boolean {
|
|
1082
|
-
if (process.platform !== "win32") return true
|
|
1083
|
-
return (
|
|
1084
|
-
existsSync(join(dir, "libpq.dll")) ||
|
|
1085
|
-
existsSync(join(dir, "libpq-5.dll")) ||
|
|
1086
|
-
existsSync(join(dir, "libssl-3-x64.dll"))
|
|
1087
|
-
)
|
|
1088
|
-
}
|
|
1089
|
-
|
|
1090
|
-
function repairWindowsPostgrestRuntime(cacheDir: string, archivePath: string, binPath: string): boolean {
|
|
1091
|
-
const r = spawnSync(
|
|
1092
|
-
"powershell.exe",
|
|
1093
|
-
[
|
|
1094
|
-
"-NoProfile",
|
|
1095
|
-
"-Command",
|
|
1096
|
-
`Expand-Archive -Path '${archivePath}' -DestinationPath '${cacheDir}' -Force; ` +
|
|
1097
|
-
`$exe = Get-ChildItem -Path '${cacheDir}' -Recurse -Filter 'postgrest.exe' | Select-Object -First 1; ` +
|
|
1098
|
-
`if ($exe) { ` +
|
|
1099
|
-
` Copy-Item -Path $exe.FullName -Destination '${binPath}' -Force; ` +
|
|
1100
|
-
` Get-ChildItem -Path $exe.Directory.FullName -Filter '*.dll' | ` +
|
|
1101
|
-
` ForEach-Object { Copy-Item -Path $_.FullName -Destination '${cacheDir}' -Force }; ` +
|
|
1102
|
-
`}`,
|
|
1103
|
-
],
|
|
1104
|
-
{ stdio: "pipe", encoding: "utf8" },
|
|
1105
|
-
)
|
|
1106
|
-
return r.status === 0
|
|
1107
|
-
}
|
|
1108
|
-
|
|
1109
|
-
// ---------------------------------------------------------------------------
|
|
1110
|
-
// Local-dev JWT generator (no external dep, pure crypto)
|
|
1111
|
-
// ---------------------------------------------------------------------------
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
// ---------------------------------------------------------------------------
|
|
1115
|
-
// AST adaptation: replace extension-dependent fields with JSONB fallbacks
|
|
1116
|
-
// ---------------------------------------------------------------------------
|
|
1117
|
-
|
|
1118
|
-
interface AstField { kind: string; required?: boolean; [k: string]: unknown }
|
|
1119
|
-
interface AstModel { name: string; fields?: Record<string, AstField> }
|
|
1120
|
-
interface AstSchema { models?: AstModel[] }
|
|
1121
|
-
|
|
1122
|
-
// Field kinds that require Postgres extensions not available in all builds.
|
|
1123
|
-
// Maps kind → { extension name, JSONB fallback AST }
|
|
1124
|
-
const EXTENSION_FIELDS: Record<string, { ext: string; fallback: AstField }> = {
|
|
1125
|
-
geo: { ext: "PostGIS", fallback: { kind: "json", pgType: "JSONB" } },
|
|
1126
|
-
vector: { ext: "pgvector", fallback: { kind: "json", pgType: "JSONB" } },
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1129
|
-
function adaptUnsupportedKinds(
|
|
1130
|
-
ast: ExtractedSchemaAstV2,
|
|
1131
|
-
skipKinds: ReadonlySet<string>,
|
|
1132
|
-
): { filtered: ExtractedSchemaAstV2; adapted: string[] } {
|
|
1133
|
-
const adapted: string[] = []
|
|
1134
|
-
if (!ast || typeof ast !== "object") return { filtered: ast, adapted }
|
|
1135
|
-
const schema = ast as AstSchema
|
|
1136
|
-
if (!Array.isArray(schema.models)) return { filtered: ast, adapted }
|
|
1137
|
-
|
|
1138
|
-
const models = schema.models.map((model) => {
|
|
1139
|
-
const fields: Record<string, AstField> = {}
|
|
1140
|
-
for (const [name, field] of Object.entries(model.fields ?? {})) {
|
|
1141
|
-
const info = skipKinds.has(field.kind) ? EXTENSION_FIELDS[field.kind] : undefined
|
|
1142
|
-
if (info) {
|
|
1143
|
-
fields[name] = { ...info.fallback, required: field.required ?? false }
|
|
1144
|
-
adapted.push(`${model.name}.${name} (${info.ext} → JSONB)`)
|
|
1145
|
-
} else {
|
|
1146
|
-
fields[name] = field
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
return { ...model, fields }
|
|
1150
|
-
})
|
|
1151
|
-
|
|
1152
|
-
return { filtered: { ...schema, models } as ExtractedSchemaAstV2, adapted }
|
|
1153
|
-
}
|
|
1154
|
-
|
|
1155
|
-
// ---------------------------------------------------------------------------
|
|
1156
|
-
// .env loader
|
|
1157
|
-
// ---------------------------------------------------------------------------
|
|
1158
|
-
|
|
1159
|
-
/** Minimal auth env for `migrate` (matches required fields in serverEnv below). */
|
|
1160
|
-
function authMigrateEnv(
|
|
1161
|
-
serverPort: string,
|
|
1162
|
-
sqlDbURL: string,
|
|
1163
|
-
jwtSecret: string,
|
|
1164
|
-
): Record<string, string> {
|
|
1165
|
-
const base = `http://localhost:${serverPort}`
|
|
1166
|
-
return {
|
|
1167
|
-
// envconfig: the service prefix + DB.DATABASE_URL → SUPATYPE_DB_DATABASE_URL
|
|
1168
|
-
SUPATYPE_DB_DATABASE_URL: sqlDbURL,
|
|
1169
|
-
DATABASE_URL: sqlDbURL,
|
|
1170
|
-
SUPATYPE_DB_DRIVER: "postgres",
|
|
1171
|
-
SUPATYPE_DB_NAMESPACE: "auth",
|
|
1172
|
-
PGSSLMODE: "disable",
|
|
1173
|
-
SUPATYPE_JWT_SECRET: jwtSecret,
|
|
1174
|
-
SUPATYPE_API_EXTERNAL_URL: `${base}/auth/v1`,
|
|
1175
|
-
SUPATYPE_API_HOST: "localhost",
|
|
1176
|
-
SUPATYPE_SITE_URL: base,
|
|
1177
|
-
SUPATYPE_MAILER_AUTOCONFIRM: "true",
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1180
|
-
|
|
1181
|
-
/** Apply auth DDL (auth.users, etc.) before engine push references auth schema. */
|
|
1182
|
-
function runAuthMigrations(
|
|
1183
|
-
serverBin: string,
|
|
1184
|
-
migrateEnv: Record<string, string>,
|
|
1185
|
-
): void {
|
|
1186
|
-
const result = spawnSync(serverBin, ["migrate"], {
|
|
1187
|
-
stdio: "pipe",
|
|
1188
|
-
encoding: "utf8",
|
|
1189
|
-
env: {
|
|
1190
|
-
...process.env,
|
|
1191
|
-
...migrateEnv,
|
|
1192
|
-
},
|
|
1193
|
-
})
|
|
1194
|
-
if (result.status !== 0) {
|
|
1195
|
-
const detail = (result.stderr ?? result.stdout ?? "").trim()
|
|
1196
|
-
throw new Error(
|
|
1197
|
-
`auth migrations failed (exit ${result.status ?? "unknown"})` +
|
|
1198
|
-
(detail ? `:\n${detail}` : ""),
|
|
1199
|
-
)
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
|
-
|
|
1203
|
-
function loadDotEnv(cwd: string): Record<string, string> {
|
|
1204
|
-
const candidates = [resolve(cwd, ".env"), resolve(cwd, ".env.local")]
|
|
1205
|
-
const vars: Record<string, string> = {}
|
|
1206
|
-
for (const envPath of candidates) {
|
|
1207
|
-
if (!existsSync(envPath)) continue
|
|
1208
|
-
for (const line of readFileSync(envPath, "utf8").split("\n")) {
|
|
1209
|
-
const trimmed = line.trim()
|
|
1210
|
-
if (!trimmed || trimmed.startsWith("#")) continue
|
|
1211
|
-
const eq = trimmed.indexOf("=")
|
|
1212
|
-
if (eq === -1) continue
|
|
1213
|
-
vars[trimmed.slice(0, eq)] = trimmed.slice(eq + 1)
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
return vars
|
|
1217
|
-
}
|