@supatype/cli 0.7.0 → 0.9.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 +314 -0
- package/bin/supatype.js +40 -4
- package/deno.d.ts +1 -1
- package/dist/admin-prompt-state.d.ts +13 -0
- package/dist/admin-prompt-state.d.ts.map +1 -0
- package/dist/admin-prompt-state.js +30 -0
- package/dist/admin-prompt-state.js.map +1 -0
- package/dist/adopt-columns.d.ts.map +1 -1
- package/dist/adopt-columns.js +13 -17
- package/dist/adopt-columns.js.map +1 -1
- package/dist/after-hooks-health.d.ts +19 -0
- package/dist/after-hooks-health.d.ts.map +1 -0
- package/dist/after-hooks-health.js +69 -0
- package/dist/after-hooks-health.js.map +1 -0
- package/dist/app-config.d.ts +1 -1
- package/dist/app-config.d.ts.map +1 -1
- package/dist/app-config.js +103 -144
- package/dist/app-config.js.map +1 -1
- package/dist/app-vite-env.d.ts +5 -1
- package/dist/app-vite-env.d.ts.map +1 -1
- package/dist/app-vite-env.js +9 -15
- package/dist/app-vite-env.js.map +1 -1
- package/dist/applied-ast-artifacts.d.ts +16 -0
- package/dist/applied-ast-artifacts.d.ts.map +1 -0
- package/dist/applied-ast-artifacts.js +37 -0
- package/dist/applied-ast-artifacts.js.map +1 -0
- package/dist/archive-extract.d.ts +3 -0
- package/dist/archive-extract.d.ts.map +1 -0
- package/dist/archive-extract.js +19 -0
- package/dist/archive-extract.js.map +1 -0
- package/dist/augmentation-generator.d.ts +5 -0
- package/dist/augmentation-generator.d.ts.map +1 -1
- package/dist/augmentation-generator.js +13 -4
- package/dist/augmentation-generator.js.map +1 -1
- package/dist/binary-cache.d.ts +27 -3
- package/dist/binary-cache.d.ts.map +1 -1
- package/dist/binary-cache.js +117 -85
- package/dist/binary-cache.js.map +1 -1
- package/dist/binary-download-lock.d.ts.map +1 -1
- package/dist/binary-download-lock.js +1 -3
- package/dist/binary-download-lock.js.map +1 -1
- package/dist/byo-preflight.d.ts.map +1 -1
- package/dist/byo-preflight.js +2 -10
- package/dist/byo-preflight.js.map +1 -1
- package/dist/byte-size.d.ts +9 -0
- package/dist/byte-size.d.ts.map +1 -0
- package/dist/byte-size.js +36 -0
- package/dist/byte-size.js.map +1 -0
- package/dist/cache-clean.d.ts +0 -2
- package/dist/cache-clean.d.ts.map +1 -1
- package/dist/cache-clean.js +1 -27
- package/dist/cache-clean.js.map +1 -1
- package/dist/cache-pins.d.ts.map +1 -1
- package/dist/cache-pins.js +3 -20
- package/dist/cache-pins.js.map +1 -1
- package/dist/cache-root.d.ts +7 -0
- package/dist/cache-root.d.ts.map +1 -0
- package/dist/cache-root.js +11 -0
- package/dist/cache-root.js.map +1 -0
- package/dist/cli-artifacts.d.ts.map +1 -1
- package/dist/cli-artifacts.js +2 -1
- package/dist/cli-artifacts.js.map +1 -1
- package/dist/cli-install-method.d.ts.map +1 -1
- package/dist/cli-install-method.js +7 -1
- package/dist/cli-install-method.js.map +1 -1
- package/dist/cli-launcher.d.ts +21 -0
- package/dist/cli-launcher.d.ts.map +1 -0
- package/dist/cli-launcher.js +112 -0
- package/dist/cli-launcher.js.map +1 -0
- package/dist/cli-old-versions.d.ts +44 -0
- package/dist/cli-old-versions.d.ts.map +1 -0
- package/dist/cli-old-versions.js +83 -0
- package/dist/cli-old-versions.js.map +1 -0
- package/dist/cli-program-path.d.ts +20 -0
- package/dist/cli-program-path.d.ts.map +1 -0
- package/dist/cli-program-path.js +41 -0
- package/dist/cli-program-path.js.map +1 -0
- package/dist/cli-standalone.d.ts +2 -3
- package/dist/cli-standalone.d.ts.map +1 -1
- package/dist/cli-standalone.js +51 -24
- package/dist/cli-standalone.js.map +1 -1
- package/dist/cli-version-embedded.js +1 -1
- package/dist/cloud-credentials.d.ts +6 -0
- package/dist/cloud-credentials.d.ts.map +1 -1
- package/dist/cloud-credentials.js +13 -0
- package/dist/cloud-credentials.js.map +1 -1
- package/dist/commands/admin.d.ts.map +1 -1
- package/dist/commands/admin.js +18 -18
- package/dist/commands/admin.js.map +1 -1
- package/dist/commands/app.d.ts.map +1 -1
- package/dist/commands/app.js +27 -8
- package/dist/commands/app.js.map +1 -1
- package/dist/commands/cache.d.ts.map +1 -1
- package/dist/commands/cache.js +37 -11
- package/dist/commands/cache.js.map +1 -1
- package/dist/commands/cloud.js +2 -4
- package/dist/commands/cloud.js.map +1 -1
- package/dist/commands/db.d.ts.map +1 -1
- package/dist/commands/db.js +116 -106
- package/dist/commands/db.js.map +1 -1
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +3 -3
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/dev.d.ts +50 -4
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +276 -267
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/doctor.d.ts +32 -0
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +66 -1
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/functions.d.ts +30 -0
- package/dist/commands/functions.d.ts.map +1 -1
- package/dist/commands/functions.js +503 -507
- package/dist/commands/functions.js.map +1 -1
- package/dist/commands/generate.d.ts.map +1 -1
- package/dist/commands/generate.js +11 -8
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/hooks.d.ts.map +1 -1
- package/dist/commands/hooks.js +46 -23
- package/dist/commands/hooks.js.map +1 -1
- package/dist/commands/init.d.ts +37 -4
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +509 -386
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/internal.d.ts.map +1 -1
- package/dist/commands/internal.js +2 -1
- package/dist/commands/internal.js.map +1 -1
- package/dist/commands/keys.d.ts +46 -20
- package/dist/commands/keys.d.ts.map +1 -1
- package/dist/commands/keys.js +196 -156
- package/dist/commands/keys.js.map +1 -1
- package/dist/commands/link-helpers.d.ts.map +1 -1
- package/dist/commands/link-helpers.js +30 -11
- package/dist/commands/link-helpers.js.map +1 -1
- package/dist/commands/logs.d.ts.map +1 -1
- package/dist/commands/logs.js +5 -4
- package/dist/commands/logs.js.map +1 -1
- package/dist/commands/migrate.js +1 -1
- package/dist/commands/migrate.js.map +1 -1
- package/dist/commands/pg.js +2 -0
- package/dist/commands/pg.js.map +1 -1
- package/dist/commands/plugins.d.ts.map +1 -1
- package/dist/commands/plugins.js +17 -7
- package/dist/commands/plugins.js.map +1 -1
- package/dist/commands/push.d.ts +39 -0
- package/dist/commands/push.d.ts.map +1 -1
- package/dist/commands/push.js +221 -77
- package/dist/commands/push.js.map +1 -1
- package/dist/commands/seed.d.ts +35 -0
- package/dist/commands/seed.d.ts.map +1 -1
- package/dist/commands/seed.js +72 -38
- package/dist/commands/seed.js.map +1 -1
- package/dist/commands/self-host.d.ts.map +1 -1
- package/dist/commands/self-host.js +71 -42
- 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 +9 -3
- package/dist/commands/self-update.js.map +1 -1
- package/dist/commands/status.js +5 -5
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/types.js +2 -5
- package/dist/commands/types.js.map +1 -1
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +212 -101
- package/dist/commands/update.js.map +1 -1
- package/dist/component-launch.d.ts +11 -0
- package/dist/component-launch.d.ts.map +1 -0
- package/dist/component-launch.js +35 -0
- package/dist/component-launch.js.map +1 -0
- package/dist/components.d.ts +7 -2
- package/dist/components.d.ts.map +1 -1
- package/dist/components.js +7 -2
- package/dist/components.js.map +1 -1
- package/dist/compose-db-roles.d.ts.map +1 -1
- package/dist/compose-db-roles.js +5 -14
- package/dist/compose-db-roles.js.map +1 -1
- package/dist/compose-engine-run.d.ts +6 -5
- package/dist/compose-engine-run.d.ts.map +1 -1
- package/dist/compose-engine-run.js +44 -37
- package/dist/compose-engine-run.js.map +1 -1
- package/dist/compose-engine-service.d.ts +10 -0
- package/dist/compose-engine-service.d.ts.map +1 -0
- package/dist/compose-engine-service.js +16 -0
- package/dist/compose-engine-service.js.map +1 -0
- package/dist/compose-host-path.d.ts +14 -0
- package/dist/compose-host-path.d.ts.map +1 -0
- package/dist/compose-host-path.js +18 -0
- package/dist/compose-host-path.js.map +1 -0
- package/dist/compose-image-pull.d.ts +43 -0
- package/dist/compose-image-pull.d.ts.map +1 -0
- package/dist/compose-image-pull.js +27 -0
- package/dist/compose-image-pull.js.map +1 -0
- package/dist/compose-kong.d.ts +4 -0
- package/dist/compose-kong.d.ts.map +1 -1
- package/dist/compose-kong.js +23 -9
- package/dist/compose-kong.js.map +1 -1
- package/dist/compose-local-server-image.d.ts.map +1 -1
- package/dist/compose-local-server-image.js +7 -3
- package/dist/compose-local-server-image.js.map +1 -1
- package/dist/compose-render-mode.d.ts.map +1 -1
- package/dist/compose-render-mode.js +7 -4
- package/dist/compose-render-mode.js.map +1 -1
- package/dist/compose-services.d.ts +12 -2
- package/dist/compose-services.d.ts.map +1 -1
- package/dist/compose-services.js +27 -12
- package/dist/compose-services.js.map +1 -1
- package/dist/config-snapshot.d.ts +6 -0
- package/dist/config-snapshot.d.ts.map +1 -0
- package/dist/config-snapshot.js +23 -0
- package/dist/config-snapshot.js.map +1 -0
- package/dist/config.d.ts +11 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +20 -3
- package/dist/config.js.map +1 -1
- package/dist/database-url-owner.d.ts +59 -0
- package/dist/database-url-owner.d.ts.map +1 -0
- package/dist/database-url-owner.js +133 -0
- package/dist/database-url-owner.js.map +1 -0
- package/dist/db-port-offer.d.ts +18 -0
- package/dist/db-port-offer.d.ts.map +1 -0
- package/dist/db-port-offer.js +68 -0
- package/dist/db-port-offer.js.map +1 -0
- package/dist/db-port.d.ts +42 -18
- package/dist/db-port.d.ts.map +1 -1
- package/dist/db-port.js +34 -32
- package/dist/db-port.js.map +1 -1
- package/dist/db-preflight.d.ts +37 -0
- package/dist/db-preflight.d.ts.map +1 -1
- package/dist/db-preflight.js +219 -77
- package/dist/db-preflight.js.map +1 -1
- package/dist/db-rows.d.ts +11 -0
- package/dist/db-rows.d.ts.map +1 -1
- package/dist/db-rows.js +27 -0
- package/dist/db-rows.js.map +1 -1
- package/dist/debounce.d.ts +11 -0
- package/dist/debounce.d.ts.map +1 -0
- package/dist/debounce.js +23 -0
- package/dist/debounce.js.map +1 -0
- package/dist/dev-api-keys.d.ts +12 -2
- package/dist/dev-api-keys.d.ts.map +1 -1
- package/dist/dev-api-keys.js +33 -17
- package/dist/dev-api-keys.js.map +1 -1
- package/dist/dev-compose.d.ts +10 -12
- package/dist/dev-compose.d.ts.map +1 -1
- package/dist/dev-compose.js +252 -288
- package/dist/dev-compose.js.map +1 -1
- package/dist/dev-db-ready.d.ts.map +1 -1
- package/dist/dev-db-ready.js +2 -1
- package/dist/dev-db-ready.js.map +1 -1
- package/dist/dev-db-reset.d.ts.map +1 -1
- package/dist/dev-db-reset.js +5 -4
- package/dist/dev-db-reset.js.map +1 -1
- package/dist/dev-functions-watch.d.ts.map +1 -1
- package/dist/dev-functions-watch.js +5 -16
- package/dist/dev-functions-watch.js.map +1 -1
- package/dist/dev-log-bus.d.ts +8 -0
- package/dist/dev-log-bus.d.ts.map +1 -1
- package/dist/dev-log-bus.js +13 -0
- package/dist/dev-log-bus.js.map +1 -1
- package/dist/dev-ports.d.ts +27 -7
- package/dist/dev-ports.d.ts.map +1 -1
- package/dist/dev-ports.js +68 -41
- package/dist/dev-ports.js.map +1 -1
- package/dist/dev-schema-watch.d.ts.map +1 -1
- package/dist/dev-schema-watch.js +7 -12
- package/dist/dev-schema-watch.js.map +1 -1
- package/dist/dev-session-lock.js +4 -3
- package/dist/dev-session-lock.js.map +1 -1
- package/dist/dev-session.d.ts +15 -0
- package/dist/dev-session.d.ts.map +1 -1
- package/dist/dev-session.js +27 -1
- package/dist/dev-session.js.map +1 -1
- package/dist/dev-shutdown.d.ts +45 -0
- package/dist/dev-shutdown.d.ts.map +1 -1
- package/dist/dev-shutdown.js +221 -33
- package/dist/dev-shutdown.js.map +1 -1
- package/dist/diff-output.d.ts +7 -1
- package/dist/diff-output.d.ts.map +1 -1
- package/dist/diff-output.js +91 -2
- package/dist/diff-output.js.map +1 -1
- package/dist/docker-address-pool.d.ts +23 -0
- package/dist/docker-address-pool.d.ts.map +1 -0
- package/dist/docker-address-pool.js +56 -0
- package/dist/docker-address-pool.js.map +1 -0
- package/dist/docker-exec.d.ts +92 -0
- package/dist/docker-exec.d.ts.map +1 -0
- package/dist/docker-exec.js +139 -0
- package/dist/docker-exec.js.map +1 -0
- package/dist/docker-postgres.d.ts +1 -6
- package/dist/docker-postgres.d.ts.map +1 -1
- package/dist/docker-postgres.js +67 -85
- package/dist/docker-postgres.js.map +1 -1
- package/dist/docker-runtime.d.ts +14 -1
- package/dist/docker-runtime.d.ts.map +1 -1
- package/dist/docker-runtime.js +55 -24
- package/dist/docker-runtime.js.map +1 -1
- package/dist/dotenv-parse.d.ts +22 -0
- package/dist/dotenv-parse.d.ts.map +1 -0
- package/dist/dotenv-parse.js +63 -0
- package/dist/dotenv-parse.js.map +1 -0
- package/dist/engine-answers.d.ts +0 -2
- package/dist/engine-answers.d.ts.map +1 -1
- package/dist/engine-answers.js +4 -3
- package/dist/engine-answers.js.map +1 -1
- package/dist/engine-client.d.ts.map +1 -1
- package/dist/engine-client.js +13 -12
- package/dist/engine-client.js.map +1 -1
- package/dist/engine-floor.d.ts +29 -0
- package/dist/engine-floor.d.ts.map +1 -1
- package/dist/engine-floor.js +56 -0
- package/dist/engine-floor.js.map +1 -1
- package/dist/engine-ownership-gate.d.ts +13 -1
- package/dist/engine-ownership-gate.d.ts.map +1 -1
- package/dist/engine-ownership-gate.js +36 -6
- package/dist/engine-ownership-gate.js.map +1 -1
- package/dist/ensure-binary.d.ts +9 -0
- package/dist/ensure-binary.d.ts.map +1 -1
- package/dist/ensure-binary.js +38 -5
- package/dist/ensure-binary.js.map +1 -1
- package/dist/ensure-component-binaries.d.ts.map +1 -1
- package/dist/ensure-component-binaries.js +2 -1
- package/dist/ensure-component-binaries.js.map +1 -1
- package/dist/env-file.d.ts +30 -8
- package/dist/env-file.d.ts.map +1 -1
- package/dist/env-file.js +84 -57
- package/dist/env-file.js.map +1 -1
- package/dist/env-lines.d.ts +11 -0
- package/dist/env-lines.d.ts.map +1 -0
- package/dist/env-lines.js +36 -0
- package/dist/env-lines.js.map +1 -0
- package/dist/error-message.d.ts +34 -1
- package/dist/error-message.d.ts.map +1 -1
- package/dist/error-message.js +102 -2
- package/dist/error-message.js.map +1 -1
- package/dist/fetch-within.d.ts +10 -0
- package/dist/fetch-within.d.ts.map +1 -0
- package/dist/fetch-within.js +12 -0
- package/dist/fetch-within.js.map +1 -0
- package/dist/field-masking-tier.d.ts.map +1 -1
- package/dist/field-masking-tier.js +7 -5
- package/dist/field-masking-tier.js.map +1 -1
- package/dist/frontend-env.d.ts +43 -0
- package/dist/frontend-env.d.ts.map +1 -0
- package/dist/frontend-env.js +81 -0
- package/dist/frontend-env.js.map +1 -0
- package/dist/functions-context-refresh.d.ts +6 -2
- package/dist/functions-context-refresh.d.ts.map +1 -1
- package/dist/functions-context-refresh.js +11 -3
- package/dist/functions-context-refresh.js.map +1 -1
- package/dist/functions-deno-types.d.ts.map +1 -1
- package/dist/functions-deno-types.js +9 -2
- package/dist/functions-deno-types.js.map +1 -1
- package/dist/{functions-router-gen.d.ts → functions-discovery.d.ts} +8 -10
- package/dist/functions-discovery.d.ts.map +1 -0
- package/dist/functions-discovery.js +87 -0
- package/dist/functions-discovery.js.map +1 -0
- package/dist/functions-template.d.ts.map +1 -1
- package/dist/functions-template.js +20 -12
- package/dist/functions-template.js.map +1 -1
- package/dist/functions-worker-files.d.ts +55 -0
- package/dist/functions-worker-files.d.ts.map +1 -0
- package/dist/functions-worker-files.js +149 -0
- package/dist/functions-worker-files.js.map +1 -0
- package/dist/generated/functions-worker-source.d.ts +2 -0
- package/dist/generated/functions-worker-source.d.ts.map +1 -0
- package/dist/generated/functions-worker-source.js +12 -0
- package/dist/generated/functions-worker-source.js.map +1 -0
- package/dist/generated/release-images.d.ts +18 -0
- package/dist/generated/release-images.d.ts.map +1 -0
- package/dist/generated/release-images.js +8 -0
- package/dist/generated/release-images.js.map +1 -0
- package/dist/generated-files-engine.d.ts +33 -0
- package/dist/generated-files-engine.d.ts.map +1 -0
- package/dist/generated-files-engine.js +45 -0
- package/dist/generated-files-engine.js.map +1 -0
- package/dist/hook-actor.d.ts +17 -0
- package/dist/hook-actor.d.ts.map +1 -0
- package/dist/hook-actor.js +37 -0
- package/dist/hook-actor.js.map +1 -0
- package/dist/hook-columns.d.ts +30 -0
- package/dist/hook-columns.d.ts.map +1 -0
- package/dist/hook-columns.js +77 -0
- package/dist/hook-columns.js.map +1 -0
- package/dist/hook-events.d.ts +11 -0
- package/dist/hook-events.d.ts.map +1 -0
- package/dist/hook-events.js +11 -0
- package/dist/hook-events.js.map +1 -0
- package/dist/hook-upload.d.ts +29 -15
- package/dist/hook-upload.d.ts.map +1 -1
- package/dist/hook-upload.js +88 -59
- package/dist/hook-upload.js.map +1 -1
- package/dist/hooks-generator.d.ts +5 -0
- package/dist/hooks-generator.d.ts.map +1 -1
- package/dist/hooks-generator.js +92 -21
- package/dist/hooks-generator.js.map +1 -1
- package/dist/host-database.d.ts.map +1 -1
- package/dist/host-database.js +31 -4
- package/dist/host-database.js.map +1 -1
- package/dist/init-dependency-versions.d.ts +3 -1
- package/dist/init-dependency-versions.d.ts.map +1 -1
- package/dist/init-dependency-versions.js +32 -6
- package/dist/init-dependency-versions.js.map +1 -1
- package/dist/init-example.d.ts +48 -0
- package/dist/init-example.d.ts.map +1 -0
- package/dist/init-example.js +110 -0
- package/dist/init-example.js.map +1 -0
- package/dist/init-package-json.d.ts +38 -1
- package/dist/init-package-json.d.ts.map +1 -1
- package/dist/init-package-json.js +150 -37
- package/dist/init-package-json.js.map +1 -1
- package/dist/init-setup-steps.d.ts +37 -0
- package/dist/init-setup-steps.d.ts.map +1 -0
- package/dist/init-setup-steps.js +118 -0
- package/dist/init-setup-steps.js.map +1 -0
- package/dist/jwt-secret-length.d.ts +5 -13
- package/dist/jwt-secret-length.d.ts.map +1 -1
- package/dist/jwt-secret-length.js +7 -22
- package/dist/jwt-secret-length.js.map +1 -1
- package/dist/jwt-secret-rules.d.ts +24 -0
- package/dist/jwt-secret-rules.d.ts.map +1 -0
- package/dist/jwt-secret-rules.js +46 -0
- package/dist/jwt-secret-rules.js.map +1 -0
- package/dist/local-gateway.d.ts +3 -6
- package/dist/local-gateway.d.ts.map +1 -1
- package/dist/local-gateway.js +7 -9
- package/dist/local-gateway.js.map +1 -1
- package/dist/local-secrets.d.ts +95 -11
- package/dist/local-secrets.d.ts.map +1 -1
- package/dist/local-secrets.js +153 -18
- package/dist/local-secrets.js.map +1 -1
- package/dist/local-stack.d.ts.map +1 -1
- package/dist/local-stack.js +2 -7
- package/dist/local-stack.js.map +1 -1
- package/dist/local-storage.d.ts +7 -2
- package/dist/local-storage.d.ts.map +1 -1
- package/dist/local-storage.js +11 -3
- package/dist/local-storage.js.map +1 -1
- package/dist/mailer-env.d.ts +37 -0
- package/dist/mailer-env.d.ts.map +1 -0
- package/dist/mailer-env.js +98 -0
- package/dist/mailer-env.js.map +1 -0
- package/dist/model-cache.d.ts +4 -8
- package/dist/model-cache.d.ts.map +1 -1
- package/dist/model-cache.js.map +1 -1
- package/dist/model-hooks.d.ts +21 -7
- package/dist/model-hooks.d.ts.map +1 -1
- package/dist/model-hooks.js +62 -39
- package/dist/model-hooks.js.map +1 -1
- package/dist/native-dev-env.d.ts +37 -1
- package/dist/native-dev-env.d.ts.map +1 -1
- package/dist/native-dev-env.js +64 -2
- package/dist/native-dev-env.js.map +1 -1
- package/dist/native-functions-watch.d.ts +56 -5
- package/dist/native-functions-watch.d.ts.map +1 -1
- package/dist/native-functions-watch.js +119 -38
- package/dist/native-functions-watch.js.map +1 -1
- package/dist/native-keyspace.d.ts.map +1 -1
- package/dist/native-keyspace.js +2 -2
- package/dist/native-keyspace.js.map +1 -1
- package/dist/native-realtime.d.ts +11 -3
- package/dist/native-realtime.d.ts.map +1 -1
- package/dist/native-realtime.js +162 -10
- package/dist/native-realtime.js.map +1 -1
- package/dist/native-roles-sql.d.ts +14 -0
- package/dist/native-roles-sql.d.ts.map +1 -1
- package/dist/native-roles-sql.js +82 -1
- package/dist/native-roles-sql.js.map +1 -1
- package/dist/native-storage-import.d.ts +19 -0
- package/dist/native-storage-import.d.ts.map +1 -0
- package/dist/native-storage-import.js +327 -0
- package/dist/native-storage-import.js.map +1 -0
- package/dist/native-storage.d.ts +45 -0
- package/dist/native-storage.d.ts.map +1 -0
- package/dist/native-storage.js +140 -0
- package/dist/native-storage.js.map +1 -0
- package/dist/native-worker.d.ts +26 -0
- package/dist/native-worker.d.ts.map +1 -0
- package/dist/native-worker.js +63 -0
- package/dist/native-worker.js.map +1 -0
- package/dist/owner-default.d.ts +9 -1
- package/dist/owner-default.d.ts.map +1 -1
- package/dist/owner-default.js +17 -4
- package/dist/owner-default.js.map +1 -1
- package/dist/post-apply.d.ts +3 -0
- package/dist/post-apply.d.ts.map +1 -0
- package/dist/post-apply.js +17 -0
- package/dist/post-apply.js.map +1 -0
- package/dist/postgres-ctl.d.ts +98 -7
- package/dist/postgres-ctl.d.ts.map +1 -1
- package/dist/postgres-ctl.js +273 -40
- package/dist/postgres-ctl.js.map +1 -1
- package/dist/postgres-image.d.ts +15 -3
- package/dist/postgres-image.d.ts.map +1 -1
- package/dist/postgres-image.js +18 -15
- package/dist/postgres-image.js.map +1 -1
- package/dist/postgrest-release.d.ts +9 -0
- package/dist/postgrest-release.d.ts.map +1 -1
- package/dist/postgrest-release.js +23 -0
- package/dist/postgrest-release.js.map +1 -1
- package/dist/process-manager.d.ts.map +1 -1
- package/dist/process-manager.js +3 -1
- package/dist/process-manager.js.map +1 -1
- package/dist/project-config.d.ts +44 -7
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +48 -4
- package/dist/project-config.js.map +1 -1
- package/dist/pull-utils.d.ts +15 -0
- package/dist/pull-utils.d.ts.map +1 -1
- package/dist/pull-utils.js +149 -23
- package/dist/pull-utils.js.map +1 -1
- package/dist/push-refusal.d.ts.map +1 -1
- package/dist/push-refusal.js +3 -2
- package/dist/push-refusal.js.map +1 -1
- package/dist/realtime-launch.d.ts +2 -5
- package/dist/realtime-launch.d.ts.map +1 -1
- package/dist/realtime-launch.js +6 -23
- package/dist/realtime-launch.js.map +1 -1
- package/dist/recorded-field-masking-tier.d.ts.map +1 -1
- package/dist/recorded-field-masking-tier.js +4 -3
- package/dist/recorded-field-masking-tier.js.map +1 -1
- package/dist/release-images.d.ts +31 -0
- package/dist/release-images.d.ts.map +1 -0
- package/dist/release-images.js +90 -0
- package/dist/release-images.js.map +1 -0
- package/dist/required-host-components.d.ts.map +1 -1
- package/dist/required-host-components.js +4 -0
- package/dist/required-host-components.js.map +1 -1
- package/dist/resolve-api-url.d.ts +17 -3
- package/dist/resolve-api-url.d.ts.map +1 -1
- package/dist/resolve-api-url.js +71 -30
- package/dist/resolve-api-url.js.map +1 -1
- package/dist/resolve-target.d.ts +64 -0
- package/dist/resolve-target.d.ts.map +1 -1
- package/dist/resolve-target.js +75 -27
- package/dist/resolve-target.js.map +1 -1
- package/dist/rest-ready.d.ts.map +1 -1
- package/dist/rest-ready.js +2 -1
- package/dist/rest-ready.js.map +1 -1
- package/dist/route-manifest.d.ts +25 -2
- package/dist/route-manifest.d.ts.map +1 -1
- package/dist/route-manifest.js +48 -4
- package/dist/route-manifest.js.map +1 -1
- package/dist/run-until-stopped.d.ts +12 -0
- package/dist/run-until-stopped.d.ts.map +1 -0
- package/dist/run-until-stopped.js +42 -0
- package/dist/run-until-stopped.js.map +1 -0
- package/dist/schema-ast-v2.d.ts +2 -1
- package/dist/schema-ast-v2.d.ts.map +1 -1
- 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 +59 -46
- package/dist/schema-push-lock.js.map +1 -1
- package/dist/schema-sources.d.ts +19 -4
- package/dist/schema-sources.d.ts.map +1 -1
- package/dist/schema-sources.js +56 -35
- package/dist/schema-sources.js.map +1 -1
- package/dist/seed-auth-connect.d.ts +14 -0
- package/dist/seed-auth-connect.d.ts.map +1 -0
- package/dist/seed-auth-connect.js +97 -0
- package/dist/seed-auth-connect.js.map +1 -0
- package/dist/seed-runner.d.ts.map +1 -1
- package/dist/seed-runner.js +22 -1
- package/dist/seed-runner.js.map +1 -1
- package/dist/seed.d.ts +6 -3
- package/dist/seed.d.ts.map +1 -1
- package/dist/self-host-compose.d.ts +44 -29
- package/dist/self-host-compose.d.ts.map +1 -1
- package/dist/self-host-compose.js +311 -159
- package/dist/self-host-compose.js.map +1 -1
- package/dist/service-role-key-file.d.ts +32 -0
- package/dist/service-role-key-file.d.ts.map +1 -0
- package/dist/service-role-key-file.js +90 -0
- package/dist/service-role-key-file.js.map +1 -0
- package/dist/shell-ports.d.ts +13 -2
- package/dist/shell-ports.d.ts.map +1 -1
- package/dist/shell-ports.js +20 -15
- package/dist/shell-ports.js.map +1 -1
- package/dist/stop-signals.d.ts +7 -0
- package/dist/stop-signals.d.ts.map +1 -0
- package/dist/stop-signals.js +12 -0
- package/dist/stop-signals.js.map +1 -0
- package/dist/storage-launch.d.ts +11 -0
- package/dist/storage-launch.d.ts.map +1 -0
- package/dist/storage-launch.js +41 -0
- package/dist/storage-launch.js.map +1 -0
- package/dist/storage-provision.d.ts +50 -5
- package/dist/storage-provision.d.ts.map +1 -1
- package/dist/storage-provision.js +101 -33
- package/dist/storage-provision.js.map +1 -1
- package/dist/systemd.d.ts +1 -1
- package/dist/systemd.d.ts.map +1 -1
- package/dist/systemd.js +26 -11
- package/dist/systemd.js.map +1 -1
- package/dist/tar-reader.d.ts +29 -0
- package/dist/tar-reader.d.ts.map +1 -0
- package/dist/tar-reader.js +99 -0
- package/dist/tar-reader.js.map +1 -0
- package/dist/target-client.d.ts +14 -1
- package/dist/target-client.d.ts.map +1 -1
- package/dist/target-client.js +134 -23
- package/dist/target-client.js.map +1 -1
- package/dist/target-request.d.ts +25 -0
- package/dist/target-request.d.ts.map +1 -0
- package/dist/target-request.js +33 -0
- package/dist/target-request.js.map +1 -0
- package/dist/target-warning.d.ts +7 -0
- package/dist/target-warning.d.ts.map +1 -0
- package/dist/target-warning.js +12 -0
- package/dist/target-warning.js.map +1 -0
- package/dist/tsx-runner.d.ts.map +1 -1
- package/dist/tsx-runner.js +2 -1
- package/dist/tsx-runner.js.map +1 -1
- package/dist/type-extractor.d.ts +6 -0
- package/dist/type-extractor.d.ts.map +1 -1
- package/dist/type-extractor.js +138 -70
- package/dist/type-extractor.js.map +1 -1
- package/dist/ui/clack.d.ts.map +1 -1
- package/dist/ui/clack.js +11 -1
- package/dist/ui/clack.js.map +1 -1
- package/dist/ui/dev/DevDashboard.d.ts.map +1 -1
- package/dist/ui/dev/DevDashboard.js +13 -5
- package/dist/ui/dev/DevDashboard.js.map +1 -1
- package/dist/ui/fatal.d.ts.map +1 -1
- package/dist/ui/fatal.js +6 -7
- package/dist/ui/fatal.js.map +1 -1
- package/dist/ui/flows/FlowApp.d.ts.map +1 -1
- package/dist/ui/flows/FlowApp.js +16 -1
- package/dist/ui/flows/FlowApp.js.map +1 -1
- package/dist/ui/flows/prompt-fields.d.ts +16 -6
- package/dist/ui/flows/prompt-fields.d.ts.map +1 -1
- package/dist/ui/flows/prompt-fields.js +19 -9
- package/dist/ui/flows/prompt-fields.js.map +1 -1
- package/dist/ui/messages.d.ts +6 -0
- package/dist/ui/messages.d.ts.map +1 -1
- package/dist/ui/messages.js +17 -0
- package/dist/ui/messages.js.map +1 -1
- package/dist/ui/progress.d.ts +7 -0
- package/dist/ui/progress.d.ts.map +1 -1
- package/dist/ui/progress.js +22 -8
- package/dist/ui/progress.js.map +1 -1
- package/dist/ui/runtime/command-chrome.d.ts.map +1 -1
- package/dist/ui/runtime/command-chrome.js +2 -0
- package/dist/ui/runtime/command-chrome.js.map +1 -1
- package/dist/ui/runtime/prompt-interrupt.d.ts +10 -0
- package/dist/ui/runtime/prompt-interrupt.d.ts.map +1 -0
- package/dist/ui/runtime/prompt-interrupt.js +24 -0
- package/dist/ui/runtime/prompt-interrupt.js.map +1 -0
- package/dist/ui/runtime/run-clack-flow.d.ts.map +1 -1
- package/dist/ui/runtime/run-clack-flow.js +5 -2
- package/dist/ui/runtime/run-clack-flow.js.map +1 -1
- package/dist/ui/runtime/stdin-after-ink.d.ts +14 -1
- package/dist/ui/runtime/stdin-after-ink.d.ts.map +1 -1
- package/dist/ui/runtime/stdin-after-ink.js +44 -3
- package/dist/ui/runtime/stdin-after-ink.js.map +1 -1
- package/dist/url-safe-passwords.d.ts +25 -0
- package/dist/url-safe-passwords.d.ts.map +1 -0
- package/dist/url-safe-passwords.js +70 -0
- package/dist/url-safe-passwords.js.map +1 -0
- package/dist/valkey-sidecar.d.ts +33 -6
- package/dist/valkey-sidecar.d.ts.map +1 -1
- package/dist/valkey-sidecar.js +90 -61
- package/dist/valkey-sidecar.js.map +1 -1
- package/dist/worker-module-files.d.ts +3 -0
- package/dist/worker-module-files.d.ts.map +1 -0
- package/dist/worker-module-files.js +18 -0
- package/dist/worker-module-files.js.map +1 -0
- package/package.json +22 -16
- package/dist/functions-router-gen.d.ts.map +0 -1
- package/dist/functions-router-gen.js +0 -302
- package/dist/functions-router-gen.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hook-columns.js","sourceRoot":"","sources":["../src/hook-columns.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,YAAY,EAAkD,MAAM,kBAAkB,CAAA;AAC/F,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,gBAAgB,EAAiB,MAAM,6BAA6B,CAAA;AAGxG,OAAO,EAAE,gBAAgB,EAAuB,MAAM,kBAAkB,CAAA;AAUxE,+EAA+E;AAC/E,MAAM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model hook events, in one module with no imports, so the schema extractor and the hook
|
|
3
|
+
* generators can share them without the extractor loading the generators' dependencies.
|
|
4
|
+
*/
|
|
5
|
+
/** Every event a model's `hooks` may declare. */
|
|
6
|
+
export declare const HOOK_EVENTS: readonly ["beforeChange", "afterChange", "beforeDelete", "afterDelete"];
|
|
7
|
+
/** The after-hook events, the only ones `columns` applies to. */
|
|
8
|
+
export type AfterHookEvent = "afterChange" | "afterDelete";
|
|
9
|
+
/** Whether a hook event runs after the write, from the change log, rather than before it. */
|
|
10
|
+
export declare function isAfterHookEvent(event: string): event is AfterHookEvent;
|
|
11
|
+
//# sourceMappingURL=hook-events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hook-events.d.ts","sourceRoot":"","sources":["../src/hook-events.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,iDAAiD;AACjD,eAAO,MAAM,WAAW,yEAA0E,CAAA;AAElG,iEAAiE;AACjE,MAAM,MAAM,cAAc,GAAG,aAAa,GAAG,aAAa,CAAA;AAE1D,6FAA6F;AAC7F,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,cAAc,CAEvE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model hook events, in one module with no imports, so the schema extractor and the hook
|
|
3
|
+
* generators can share them without the extractor loading the generators' dependencies.
|
|
4
|
+
*/
|
|
5
|
+
/** Every event a model's `hooks` may declare. */
|
|
6
|
+
export const HOOK_EVENTS = ["beforeChange", "afterChange", "beforeDelete", "afterDelete"];
|
|
7
|
+
/** Whether a hook event runs after the write, from the change log, rather than before it. */
|
|
8
|
+
export function isAfterHookEvent(event) {
|
|
9
|
+
return event === "afterChange" || event === "afterDelete";
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=hook-events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hook-events.js","sourceRoot":"","sources":["../src/hook-events.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,iDAAiD;AACjD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,CAAU,CAAA;AAKlG,6FAA6F;AAC7F,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,OAAO,KAAK,KAAK,aAAa,IAAI,KAAK,KAAK,aAAa,CAAA;AAC3D,CAAC"}
|
package/dist/hook-upload.d.ts
CHANGED
|
@@ -1,27 +1,41 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { type HookMap } from "@supatype/shared";
|
|
2
|
+
import type { HookFiles } from "./resolve-target.js";
|
|
3
|
+
/** One handler as the deploy body carries it: its entry, flattened, and for a server every file of it. */
|
|
4
|
+
export interface HookHandlerUpload {
|
|
5
|
+
name: string;
|
|
6
|
+
/** The entry module, flattened and import-rewritten. */
|
|
7
|
+
source: string;
|
|
8
|
+
/** Every file of the hook's directory by its `/` path, as the project keeps it (a server only). */
|
|
9
|
+
files?: Record<string, string>;
|
|
10
|
+
}
|
|
11
|
+
/** A hook that failed the checks before upload, and why, said for the person who pushed it. */
|
|
12
|
+
export interface HookFailure {
|
|
13
|
+
name: string;
|
|
14
|
+
reason: string;
|
|
15
|
+
}
|
|
4
16
|
export interface HookUpload {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/** table → event → config, exactly as the manifest would carry it. */
|
|
11
|
-
map: Record<string, Record<string, ManifestHookEntry>>;
|
|
17
|
+
handlers: HookHandlerUpload[];
|
|
18
|
+
/** table → event → config, exactly as the manifest would carry it: every hook, failed or not. */
|
|
19
|
+
map: HookMap;
|
|
20
|
+
/** The hooks that failed the checks, which the deploy keeps on the target as they are. */
|
|
21
|
+
failed: HookFailure[];
|
|
12
22
|
}
|
|
13
23
|
/**
|
|
14
|
-
* Read the hooks a schema actually names, ready to upload
|
|
24
|
+
* Read the hooks a schema actually names, and the functions its validators name, ready to upload
|
|
25
|
+
* to a target that takes hooks as `hookFiles` says. Validators name functions in the same directory
|
|
26
|
+
* as hooks, and a stack whose map names a validator it was never sent refuses every write to that
|
|
27
|
+
* column.
|
|
15
28
|
*
|
|
16
29
|
* **Named-only**, not every directory under `hooks/`: an unnamed handler would sit on the worker
|
|
17
30
|
* holding the service-role key with nothing able to call it. Uploading it buys nothing and widens what
|
|
18
31
|
* runs with that credential.
|
|
19
32
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* the
|
|
33
|
+
* Each hook is checked on its own. One that cannot be uploaded faithfully (no index.ts, a file it
|
|
34
|
+
* imports that would not be sent, a file that cannot be read) is in `failed` with why, said for a
|
|
35
|
+
* terminal, and the others are still sent: uploading it anyway would deploy a hook that fails to
|
|
36
|
+
* import, which reads to the caller as the table's writes being broken for no visible reason.
|
|
23
37
|
*/
|
|
24
|
-
export declare function readHookUpload(cwd: string, hooksDir: string, ast: unknown): HookUpload | null;
|
|
38
|
+
export declare function readHookUpload(cwd: string, hooksDir: string, ast: unknown, hookFiles: HookFiles): HookUpload | null;
|
|
25
39
|
/** The generated adapter as a handler-shaped entry, so it travels with them. */
|
|
26
40
|
export declare function adapterEntry(module: string): {
|
|
27
41
|
name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook-upload.d.ts","sourceRoot":"","sources":["../src/hook-upload.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hook-upload.d.ts","sourceRoot":"","sources":["../src/hook-upload.ts"],"names":[],"mappings":"AAcA,OAAO,EAA6E,KAAK,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAE1H,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAGpD,0GAA0G;AAC1G,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,wDAAwD;IACxD,MAAM,EAAE,MAAM,CAAA;IACd,mGAAmG;IACnG,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC/B;AAED,+FAA+F;AAC/F,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,iBAAiB,EAAE,CAAA;IAC7B,iGAAiG;IACjG,GAAG,EAAE,OAAO,CAAA;IACZ,0FAA0F;IAC1F,MAAM,EAAE,WAAW,EAAE,CAAA;CACtB;AAiBD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,OAAO,EACZ,SAAS,EAAE,SAAS,GACnB,UAAU,GAAG,IAAI,CAgBnB;AAiED,gFAAgF;AAChF,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAE7E"}
|
package/dist/hook-upload.js
CHANGED
|
@@ -1,86 +1,115 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Package a project's hooks for a
|
|
2
|
+
* Package a project's hooks, and the functions its validators name, for a stack the push reaches over
|
|
3
|
+
* the network: Cloud, or a linked self-host stack (whose control plane writes them back into the
|
|
4
|
+
* project's layout).
|
|
3
5
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* explained, rather than in the deploy route where a dropped file would be silent.
|
|
6
|
+
* What a hook may be depends on the target (`targetHookSupport`). A managed project
|
|
7
|
+
* has no directory, its worker reads a ConfigMap, whose keys may only contain alphanumerics, `-`,
|
|
8
|
+
* `_` and `.`, so Cloud takes each hook as its one module, flattened here, where it can be checked
|
|
9
|
+
* and explained, rather than in the deploy route where a dropped file would be silent. A server
|
|
10
|
+
* writes the hook's directory back as the project keeps it, so it takes every file the worker loads.
|
|
8
11
|
*/
|
|
9
12
|
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
10
|
-
import { join, relative } from "node:path";
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Rewrite the one import a hook handler is generated to make.
|
|
18
|
-
*
|
|
19
|
-
* `../_supatype/hooks.ts` is a path that cannot survive flattening, and it is the specifier our own
|
|
20
|
-
* scaffold writes: so it is rewritten rather than refused. Any *other* relative import is refused
|
|
21
|
-
* below: it would resolve to nothing on the worker, and a hook that fails to import is a hooked table
|
|
22
|
-
* whose writes all start failing.
|
|
23
|
-
*/
|
|
24
|
-
function rewriteAdapterImport(source) {
|
|
25
|
-
return source.split(ADAPTER_IMPORT).join(`./${ADAPTER_KEY}`);
|
|
26
|
-
}
|
|
27
|
-
/** Relative specifiers a flattened layout cannot honour, so the caller can refuse with a real reason. */
|
|
28
|
-
function unsupportedImports(source) {
|
|
13
|
+
import { join, posix, relative } from "node:path";
|
|
14
|
+
import { ADAPTER_IMPORT, ADAPTER_NAME, FLATTENED_ADAPTER_IMPORT, flattenHookSource } from "@supatype/shared";
|
|
15
|
+
import { declaredHooks, declaredValidators, manifestHooks } from "./model-hooks.js";
|
|
16
|
+
import { readWorkerFiles } from "./worker-module-files.js";
|
|
17
|
+
/** Relative specifiers in `source`: `from "./…"` and `import("./…")`, every form resolved against the file's own path. */
|
|
18
|
+
function relativeSpecifiers(source) {
|
|
29
19
|
const found = new Set();
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const specifier = match[1];
|
|
33
|
-
if (specifier === ADAPTER_IMPORT || specifier === `./${ADAPTER_KEY}`)
|
|
34
|
-
continue;
|
|
35
|
-
found.add(specifier);
|
|
36
|
-
}
|
|
20
|
+
for (const match of source.matchAll(/(?:from|import)\s*\(?\s*["'](\.[^"']*)["']/g))
|
|
21
|
+
found.add(match[1]);
|
|
37
22
|
return [...found].sort();
|
|
38
23
|
}
|
|
39
24
|
/**
|
|
40
|
-
* Read the hooks a schema actually names, ready to upload
|
|
25
|
+
* Read the hooks a schema actually names, and the functions its validators name, ready to upload
|
|
26
|
+
* to a target that takes hooks as `hookFiles` says. Validators name functions in the same directory
|
|
27
|
+
* as hooks, and a stack whose map names a validator it was never sent refuses every write to that
|
|
28
|
+
* column.
|
|
41
29
|
*
|
|
42
30
|
* **Named-only**, not every directory under `hooks/`: an unnamed handler would sit on the worker
|
|
43
31
|
* holding the service-role key with nothing able to call it. Uploading it buys nothing and widens what
|
|
44
32
|
* runs with that credential.
|
|
45
33
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* the
|
|
34
|
+
* Each hook is checked on its own. One that cannot be uploaded faithfully (no index.ts, a file it
|
|
35
|
+
* imports that would not be sent, a file that cannot be read) is in `failed` with why, said for a
|
|
36
|
+
* terminal, and the others are still sent: uploading it anyway would deploy a hook that fails to
|
|
37
|
+
* import, which reads to the caller as the table's writes being broken for no visible reason.
|
|
49
38
|
*/
|
|
50
|
-
export function readHookUpload(cwd, hooksDir, ast) {
|
|
51
|
-
const declared = declaredHooks(ast);
|
|
39
|
+
export function readHookUpload(cwd, hooksDir, ast, hookFiles) {
|
|
40
|
+
const declared = [...declaredHooks(ast), ...declaredValidators(ast)];
|
|
52
41
|
if (declared.length === 0)
|
|
53
42
|
return null;
|
|
54
43
|
const names = [...new Set(declared.map((hook) => hook.function))].sort();
|
|
55
|
-
const
|
|
44
|
+
const root = relative(cwd, hooksDir) || hooksDir;
|
|
56
45
|
const handlers = [];
|
|
46
|
+
const failed = [];
|
|
57
47
|
for (const name of names) {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
throw new Error(`Hook "${name}" has no ${where}/${name}/index.ts`);
|
|
62
|
-
}
|
|
63
|
-
const extra = readdirSync(dir)
|
|
64
|
-
.filter((file) => file !== "index.ts")
|
|
65
|
-
.filter((file) => statSync(join(dir, file)).isFile() || !file.startsWith("."));
|
|
66
|
-
if (extra.length > 0) {
|
|
67
|
-
throw new Error(`Hook "${name}" has more than one file (${extra.join(", ")}).\n` +
|
|
68
|
-
`A managed stack serves each hook as a single module today, so the others would not be ` +
|
|
69
|
-
`uploaded and the hook would fail to import.\nMove what it needs into index.ts, or run this ` +
|
|
70
|
-
`hook on a self-hosted stack, which mounts the directory as it is.`);
|
|
48
|
+
const hook = { name, dir: join(hooksDir, name), where: posix.join(root.replace(/\\/g, "/"), name) };
|
|
49
|
+
try {
|
|
50
|
+
handlers.push(checkedHandler(hook, hookFiles));
|
|
71
51
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (unsupported.length > 0) {
|
|
75
|
-
throw new Error(`Hook "${name}" imports ${unsupported.join(", ")}, which a managed stack cannot resolve.\n` +
|
|
76
|
-
`Only the generated ${ADAPTER_IMPORT} survives upload; bare specifiers and URLs are fine.`);
|
|
52
|
+
catch (err) {
|
|
53
|
+
failed.push({ name, reason: err instanceof Error ? err.message : String(err) });
|
|
77
54
|
}
|
|
78
|
-
handlers.push({ name, source: rewriteAdapterImport(source) });
|
|
79
55
|
}
|
|
80
|
-
return { handlers, map: manifestHooks(ast) };
|
|
56
|
+
return { handlers, map: manifestHooks(ast), failed };
|
|
57
|
+
}
|
|
58
|
+
/** One hook as `hookFiles` says the target takes it; throws why when it cannot be uploaded faithfully. */
|
|
59
|
+
function checkedHandler(hook, hookFiles) {
|
|
60
|
+
if (!existsSync(join(hook.dir, "index.ts")))
|
|
61
|
+
throw new Error(`Hook "${hook.name}" has no ${hook.where}/index.ts`);
|
|
62
|
+
return hookFiles === "directory" ? directoryHandler(hook) : entryHandler(hook);
|
|
63
|
+
}
|
|
64
|
+
/** A hook as Supatype Cloud takes it: its index.ts alone, refused when it needs anything beside it. */
|
|
65
|
+
function entryHandler(hook) {
|
|
66
|
+
const extra = readdirSync(hook.dir)
|
|
67
|
+
.filter((file) => file !== "index.ts")
|
|
68
|
+
.filter((file) => statSync(join(hook.dir, file)).isFile() || !file.startsWith("."));
|
|
69
|
+
if (extra.length > 0) {
|
|
70
|
+
throw new Error(`Hook "${hook.name}" has more than one file (${extra.join(", ")}).\n` +
|
|
71
|
+
"Supatype Cloud serves each hook as its one module, so the others would not be uploaded and " +
|
|
72
|
+
`the hook would fail to import.\nMove what it needs into ${hook.where}/index.ts, or import it ` +
|
|
73
|
+
"by package or URL (npm:, jsr:, https:).");
|
|
74
|
+
}
|
|
75
|
+
const source = readFileSync(join(hook.dir, "index.ts"), "utf8");
|
|
76
|
+
// `../_supatype/hooks.ts` cannot survive flattening, and it is the specifier our own scaffold
|
|
77
|
+
// writes, so it is rewritten (@supatype/shared); any other relative import is refused.
|
|
78
|
+
const unsupported = relativeSpecifiers(source).filter((s) => s !== ADAPTER_IMPORT && s !== FLATTENED_ADAPTER_IMPORT);
|
|
79
|
+
if (unsupported.length > 0) {
|
|
80
|
+
throw new Error(`Hook "${hook.name}" imports ${unsupported.join(", ")}, which Supatype Cloud cannot resolve: it ` +
|
|
81
|
+
`serves each hook as its one module.\nOnly the generated ${ADAPTER_IMPORT} survives upload; ` +
|
|
82
|
+
"move the rest into index.ts, or import it by package or URL (npm:, jsr:, https:).");
|
|
83
|
+
}
|
|
84
|
+
return { name: hook.name, source: flattenHookSource(source) };
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* A hook as a server takes it: every file of its directory the worker loads, written back as the
|
|
88
|
+
* project keeps it. Refused when a file imports one outside the directory, which is not sent; the
|
|
89
|
+
* generated adapter beside it is.
|
|
90
|
+
*/
|
|
91
|
+
function directoryHandler(hook) {
|
|
92
|
+
const files = readWorkerFiles(hook.dir);
|
|
93
|
+
const outside = Object.entries(files).flatMap(([path, source]) => importsNotSent(path, source, files));
|
|
94
|
+
if (outside.length > 0) {
|
|
95
|
+
throw new Error(`Hook "${hook.name}" imports ${outside.join(", ")}, outside ${hook.where}/, which is not uploaded ` +
|
|
96
|
+
"with it.\nMove what it needs into the hook's directory, or import it by package or URL (npm:, jsr:, https:).");
|
|
97
|
+
}
|
|
98
|
+
return { name: hook.name, source: flattenHookSource(files["index.ts"] ?? ""), files };
|
|
99
|
+
}
|
|
100
|
+
/** Where the generated adapter is, from the hook's directory: sent with every deploy that has hooks. */
|
|
101
|
+
const ADAPTER_FROM_HOOK = posix.normalize(ADAPTER_IMPORT);
|
|
102
|
+
/** The relative imports of the file at `path` that resolve to no file sent with it, each named with the file it is in. */
|
|
103
|
+
function importsNotSent(path, source, files) {
|
|
104
|
+
return relativeSpecifiers(source)
|
|
105
|
+
.filter((specifier) => {
|
|
106
|
+
const resolved = posix.normalize(posix.join(posix.dirname(path), specifier));
|
|
107
|
+
return resolved !== ADAPTER_FROM_HOOK && files[resolved] === undefined;
|
|
108
|
+
})
|
|
109
|
+
.map((specifier) => (path === "index.ts" ? specifier : `${specifier} (in ${path})`));
|
|
81
110
|
}
|
|
82
111
|
/** The generated adapter as a handler-shaped entry, so it travels with them. */
|
|
83
112
|
export function adapterEntry(module) {
|
|
84
|
-
return { name:
|
|
113
|
+
return { name: ADAPTER_NAME, source: module };
|
|
85
114
|
}
|
|
86
115
|
//# sourceMappingURL=hook-upload.js.map
|
package/dist/hook-upload.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook-upload.js","sourceRoot":"","sources":["../src/hook-upload.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"hook-upload.js","sourceRoot":"","sources":["../src/hook-upload.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AACzE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEjD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,wBAAwB,EAAE,iBAAiB,EAAgB,MAAM,kBAAkB,CAAA;AAC1H,OAAO,EAAE,aAAa,E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are function generateHooksModule(ast: unknown): string | null;
|
|
8
|
+
/**
|
|
9
|
+
* The module source for `ast`, with no table when no model declares a hook: what a handler just
|
|
10
|
+
* scaffolded imports, so it loads before the push that wires it writes the tables.
|
|
11
|
+
*/
|
|
12
|
+
export declare function hooksModuleSource(ast: unknown): string;
|
|
8
13
|
//# sourceMappingURL=hooks-generator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks-generator.d.ts","sourceRoot":"","sources":["../src/hooks-generator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hooks-generator.d.ts","sourceRoot":"","sources":["../src/hooks-generator.ts"],"names":[],"mappings":"AA+DA;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAG/D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAEtD"}
|
package/dist/hooks-generator.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import { isNonEmptyObject, objectAt } from "./ast-read.js";
|
|
12
12
|
import { fieldsWithCallerDefaults } from "./owner-default.js";
|
|
13
13
|
import { astModelsOf, generateInsertType, generateRowType, generateUpdateType, resolveTableName, } from "./augmentation-generator.js";
|
|
14
|
+
import { hiddenColumns, modelHookColumns } from "./hook-columns.js";
|
|
14
15
|
/** Tables that declare at least one hook, sorted for a stable file. */
|
|
15
16
|
function hookedModels(ast) {
|
|
16
17
|
return astModelsOf(ast)
|
|
@@ -21,9 +22,30 @@ function hookedModels(ast) {
|
|
|
21
22
|
return isNonEmptyObject(platform?.["hooks"]) || isNonEmptyObject(platform?.["validate"]);
|
|
22
23
|
})
|
|
23
24
|
// Fields as the engine writes them: an owner auth user id defaults to the caller (C9).
|
|
24
|
-
.map((model) => ({
|
|
25
|
+
.map((model) => ({
|
|
26
|
+
table: resolveTableName(model),
|
|
27
|
+
fields: fieldsWithCallerDefaults(model),
|
|
28
|
+
columns: modelHookColumns(model),
|
|
29
|
+
}))
|
|
25
30
|
.sort((a, b) => a.table.localeCompare(b.table));
|
|
26
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* One table's entry in `HookTables`. `AfterHookHidden` names, per after-hook, the restricted columns
|
|
34
|
+
* its rows leave out (`never` when it declared `columns: "all"`), so the types match what the server
|
|
35
|
+
* sends rather than claiming a column the hook never receives.
|
|
36
|
+
*/
|
|
37
|
+
function tableEntry(model) {
|
|
38
|
+
const hidden = (event) => {
|
|
39
|
+
const names = hiddenColumns(model.columns, event);
|
|
40
|
+
return names.length === 0 ? "never" : names.map((name) => JSON.stringify(name)).join(" | ");
|
|
41
|
+
};
|
|
42
|
+
return ` ${JSON.stringify(model.table)}: {
|
|
43
|
+
Row: ${indent(denoSafe(generateRowType(model.fields)), 4)}
|
|
44
|
+
Insert: ${indent(denoSafe(generateInsertType(model.fields)), 4)}
|
|
45
|
+
Update: ${indent(denoSafe(generateUpdateType(model.fields)), 4)}
|
|
46
|
+
AfterHookHidden: { afterChange: ${hidden("afterChange")}; afterDelete: ${hidden("afterDelete")} }
|
|
47
|
+
}`;
|
|
48
|
+
}
|
|
27
49
|
/**
|
|
28
50
|
* The module source, or `null` when no model declares a hook or a field validator.
|
|
29
51
|
*
|
|
@@ -32,15 +54,17 @@ function hookedModels(ast) {
|
|
|
32
54
|
*/
|
|
33
55
|
export function generateHooksModule(ast) {
|
|
34
56
|
const models = hookedModels(ast);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
57
|
+
return models.length === 0 ? null : moduleSource(models);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The module source for `ast`, with no table when no model declares a hook: what a handler just
|
|
61
|
+
* scaffolded imports, so it loads before the push that wires it writes the tables.
|
|
62
|
+
*/
|
|
63
|
+
export function hooksModuleSource(ast) {
|
|
64
|
+
return moduleSource(hookedModels(ast));
|
|
65
|
+
}
|
|
66
|
+
function moduleSource(models) {
|
|
67
|
+
const tableEntries = models.map(tableEntry).join("\n");
|
|
44
68
|
return `// Generated by supatype CLI, do not edit manually.
|
|
45
69
|
//
|
|
46
70
|
// Typed handlers for the models that declare \`hooks\`. Import from a function beside it:
|
|
@@ -102,7 +126,10 @@ export type HookedTable = keyof HookTables & string
|
|
|
102
126
|
|
|
103
127
|
interface HookBase {
|
|
104
128
|
readonly table: string
|
|
105
|
-
/**
|
|
129
|
+
/**
|
|
130
|
+
* Claims from the JWT the server already verified. \`null\` for an anonymous caller, and for an
|
|
131
|
+
* after-hook on a write made outside the API (SQL, a migration), which has no caller.
|
|
132
|
+
*/
|
|
106
133
|
readonly user: { readonly sub: string; readonly role: string; readonly email?: string } | null
|
|
107
134
|
/** Correlates this hook with the request in server logs. */
|
|
108
135
|
readonly requestId: string
|
|
@@ -111,10 +138,11 @@ interface HookBase {
|
|
|
111
138
|
/**
|
|
112
139
|
* The rows this request is about to overwrite, fetched only if you ask.
|
|
113
140
|
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
141
|
+
* The rows the write will change: the server selects them by the request's own filter plus the
|
|
142
|
+
* caller's own update or delete rule, so you cannot widen the filter. They are returned as stored,
|
|
143
|
+
* with no field masking, so do not echo them into a rejection message, which reaches the caller.
|
|
144
|
+
* Capped: \`truncated\` is true when there were more, in which case acting on what you got means
|
|
145
|
+
* acting on a prefix you did not choose.
|
|
118
146
|
*/
|
|
119
147
|
export type PreviousRows<T extends HookedTable> = () => Promise<{
|
|
120
148
|
rows: HookTables[T]["Row"][]
|
|
@@ -137,15 +165,54 @@ export type BeforeDeleteContext<T extends HookedTable> = HookBase & {
|
|
|
137
165
|
readonly previous: PreviousRows<T>
|
|
138
166
|
}
|
|
139
167
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
168
|
+
/**
|
|
169
|
+
* A row as an after-hook receives it: every column with a field \`read\` rule is left out, unless
|
|
170
|
+
* the hook declared \`columns: "all"\`.
|
|
171
|
+
*/
|
|
172
|
+
export type AfterChangeRow<T extends HookedTable> = Omit<
|
|
173
|
+
HookTables[T]["Row"],
|
|
174
|
+
HookTables[T]["AfterHookHidden"]["afterChange"]
|
|
175
|
+
>
|
|
176
|
+
export type AfterDeleteRow<T extends HookedTable> = Omit<
|
|
177
|
+
HookTables[T]["Row"],
|
|
178
|
+
HookTables[T]["AfterHookHidden"]["afterDelete"]
|
|
179
|
+
>
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* An after-hook runs once the write has committed, for every writer: the API, Studio, SQL and
|
|
183
|
+
* functions alike. One call carries every row one transaction changed in one table with one
|
|
184
|
+
* operation, so a bulk insert arrives as a single call.
|
|
185
|
+
*
|
|
186
|
+
* Values are in the JSON shape PostgREST returns for the same row.
|
|
187
|
+
*
|
|
188
|
+
* Delivery is at least once, so the same call can arrive twice.
|
|
189
|
+
*/
|
|
190
|
+
interface AfterHookBase extends HookBase {
|
|
191
|
+
/**
|
|
192
|
+
* \`commitLSN:schema.table:operation\`: the same for every delivery of one call. Keep the ones you
|
|
193
|
+
* have handled and drop a repeat.
|
|
194
|
+
*/
|
|
195
|
+
readonly deliveryId: string
|
|
144
196
|
}
|
|
145
197
|
|
|
146
|
-
export type
|
|
198
|
+
export type AfterChangeContext<T extends HookedTable> =
|
|
199
|
+
| (AfterHookBase & {
|
|
200
|
+
readonly operation: "insert"
|
|
201
|
+
/** Every row the transaction inserted into this table. */
|
|
202
|
+
readonly rows: AfterChangeRow<T>[]
|
|
203
|
+
})
|
|
204
|
+
| (AfterHookBase & {
|
|
205
|
+
readonly operation: "update"
|
|
206
|
+
/** Every row the transaction updated in this table, as it is now. */
|
|
207
|
+
readonly rows: AfterChangeRow<T>[]
|
|
208
|
+
/** Aligned by index: \`old[i]\` is \`rows[i]\` as it was before the update. */
|
|
209
|
+
readonly old: AfterChangeRow<T>[]
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
export type AfterDeleteContext<T extends HookedTable> = AfterHookBase & {
|
|
147
213
|
readonly operation: "delete"
|
|
148
|
-
|
|
214
|
+
/** Every row the transaction deleted from this table, as it was. */
|
|
215
|
+
readonly old: AfterDeleteRow<T>[]
|
|
149
216
|
}
|
|
150
217
|
|
|
151
218
|
/** Reject with a message, or with a status of your choosing. */
|
|
@@ -283,16 +350,20 @@ type AnyHandler = (ctx: never) => unknown
|
|
|
283
350
|
* A hook's context from the server's payload. \`previousPath\` is the server callback **path** for
|
|
284
351
|
* pre-write rows, absent when there are none to fetch: a path rather than a URL because the server
|
|
285
352
|
* does not know its own in-network address, while this worker is already told how to reach the stack.
|
|
353
|
+
* \`old\` and \`deliveryId\` come only to an after-hook.
|
|
286
354
|
*/
|
|
287
355
|
function hookContext(wire: Record<string, unknown>, signature: string | null): Record<string, unknown> {
|
|
288
356
|
const filter = text(wire, "filter")
|
|
289
357
|
const previousPath = text(wire, "previousPath")
|
|
358
|
+
const deliveryId = text(wire, "deliveryId")
|
|
290
359
|
return {
|
|
291
360
|
table: text(wire, "table") ?? "",
|
|
292
361
|
operation: text(wire, "operation") ?? "",
|
|
293
362
|
user: wire["user"] ?? null,
|
|
294
363
|
requestId: text(wire, "requestId") ?? "",
|
|
364
|
+
...(deliveryId !== undefined && { deliveryId }),
|
|
295
365
|
...(wire["rows"] !== undefined && { rows: wire["rows"] }),
|
|
366
|
+
...(wire["old"] !== undefined && { old: wire["old"] }),
|
|
296
367
|
...(wire["patch"] !== undefined && { patch: wire["patch"] }),
|
|
297
368
|
...(filter !== undefined && { filter }),
|
|
298
369
|
...(previousPath !== undefined && { previous: () => fetchPrevious(previousPath, signature) }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks-generator.js","sourceRoot":"","sources":["../src/hooks-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,gBAAgB,EAAE,QAA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AAG,GAAG,IAAI,EAAE,CAAC,CAAC;SACpD,IAAI,CAAC,IAAI,CAAC,CAAA;AACf,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host-database.d.ts","sourceRoot":"","sources":["../src/host-database.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAoB,KAAK,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"host-database.d.ts","sourceRoot":"","sources":["../src/host-database.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAoB,KAAK,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAKnF,OAAO,EAKL,KAAK,qBAAqB,EAC3B,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAElD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,GAAG,MAAM,CAG9E;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAE3E;AAED,8EAA8E;AAC9E,qBAAa,cAAe,SAAQ,KAAK;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM;gBAAnB,WAAW,EAAE,MAAM;CAMzC;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,iBAAiB,CAIvF;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAEvE;AAeD,uGAAuG;AACvG,eAAO,MAAM,kBAAkB,qCAAqC,CAAA;AAEpE,0DAA0D;AAC1D,MAAM,WAAW,SAAS;IACxB,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAA;IACZ,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,OAAO,CAAA;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAA;IACX,6CAA6C;IAC7C,MAAM,EAAE,MAAM,CAAA;IACd,uDAAuD;IACvD,KAAK,EAAE,SAAS,SAAS,EAAE,CAAA;CAC5B;AAED,yDAAyD;AACzD,qBAAa,WAAY,SAAQ,KAAK;IACxB,QAAQ,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE;gBAA3B,KAAK,EAAE,SAAS,SAAS,EAAE;CAQjD;AAED,MAAM,WAAW,cAAc;IAC7B,4EAA4E;IAC5E,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,qBAAqB,EAC7B,OAAO,GAAE,cAAmB,GAC3B,WAAW,CAwDb;AAqCD;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE1C;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAIxF"}
|
package/dist/host-database.js
CHANGED
|
@@ -17,8 +17,9 @@ import { existsSync } from "node:fs";
|
|
|
17
17
|
import { join } from "node:path";
|
|
18
18
|
import { runningStackMode } from "./compose-render-mode.js";
|
|
19
19
|
import { composeDbPublish } from "./db-port.js";
|
|
20
|
-
import { readComposeEnvInt
|
|
20
|
+
import { readComposeEnvInt } from "./env-file.js";
|
|
21
21
|
import { devDatabaseUrl, devPostgresPassword } from "./local-secrets.js";
|
|
22
|
+
import { databaseUrlState } from "./database-url-owner.js";
|
|
22
23
|
import { externalDatabaseUrl, localDSN, projectRootFromConfig, resolveRuntimeProvider, } from "./project-config.js";
|
|
23
24
|
export { COMPOSE_DEV_DB_PORT } from "./db-port.js";
|
|
24
25
|
/**
|
|
@@ -106,7 +107,6 @@ export class DsnNotFound extends Error {
|
|
|
106
107
|
export function resolveHostDatabaseUrl(cwd, config, options = {}) {
|
|
107
108
|
const root = projectRootFromConfig(config, cwd);
|
|
108
109
|
const envPath = join(root, ".env");
|
|
109
|
-
const fromFile = readEnvFile(root);
|
|
110
110
|
const tried = [];
|
|
111
111
|
const candidate = (name, value, absent) => {
|
|
112
112
|
const trimmed = value?.trim();
|
|
@@ -135,11 +135,12 @@ export function resolveHostDatabaseUrl(cwd, config, options = {}) {
|
|
|
135
135
|
return { dsn: fromEnv, source: "DATABASE_URL in the environment", tried };
|
|
136
136
|
}
|
|
137
137
|
const fileLabel = `DATABASE_URL in ${envPath}`;
|
|
138
|
-
const
|
|
138
|
+
const fromEnvFile = existsSync(envPath) ? envFileDatabaseUrl(root, config, options) : { skipped: "no .env file" };
|
|
139
|
+
const fileValue = candidate(fileLabel, fromEnvFile.url, fromEnvFile.skipped ?? "");
|
|
139
140
|
if (fileValue !== undefined)
|
|
140
141
|
return { dsn: fileValue, source: fileLabel, tried };
|
|
141
142
|
if (options.allowDerived === true) {
|
|
142
|
-
const derived = derivedDsn(root, config);
|
|
143
|
+
const derived = fromEnvFile.own ?? derivedDsn(root, config);
|
|
143
144
|
tried.push({ name: DERIVED_DSN_SOURCE, detail: redact(derived), found: true });
|
|
144
145
|
return { dsn: derived, source: DERIVED_DSN_SOURCE, tried };
|
|
145
146
|
}
|
|
@@ -150,6 +151,32 @@ export function resolveHostDatabaseUrl(cwd, config, options = {}) {
|
|
|
150
151
|
});
|
|
151
152
|
throw new DsnNotFound(tried);
|
|
152
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* `.env`'s DATABASE_URL as this project should use it (the rule is database-url-owner.ts's). One
|
|
156
|
+
* that is yours is used as written. One the CLI owns names whichever provider and port the project
|
|
157
|
+
* ran when it was written, so a command that may fall back to the project's own database uses the
|
|
158
|
+
* one it runs now: `init` writes the Docker URL, and `push` after switching to native went to it
|
|
159
|
+
* (local test N1). A Docker project with no stack running has no port in use, so the CLI's URL
|
|
160
|
+
* stands.
|
|
161
|
+
*/
|
|
162
|
+
function envFileDatabaseUrl(root, config, options) {
|
|
163
|
+
const state = databaseUrlState(root);
|
|
164
|
+
if (state.url === undefined)
|
|
165
|
+
return { skipped: "the file has no DATABASE_URL" };
|
|
166
|
+
if (state.owner !== "cli" || options.allowDerived !== true)
|
|
167
|
+
return { url: state.url };
|
|
168
|
+
const own = runningDatabaseUrl(root, config);
|
|
169
|
+
if (own === undefined || own === state.url)
|
|
170
|
+
return { url: state.url };
|
|
171
|
+
return { skipped: "written by the CLI for a provider or port the project no longer runs", own };
|
|
172
|
+
}
|
|
173
|
+
/** The project's own database as it runs now; undefined for a Docker project with no stack running. */
|
|
174
|
+
function runningDatabaseUrl(root, config) {
|
|
175
|
+
if (resolveRuntimeProvider(config) !== "docker")
|
|
176
|
+
return derivedDsn(root, config);
|
|
177
|
+
const mode = runningStackMode(root, config.project.name);
|
|
178
|
+
return mode === undefined ? undefined : hostComposeDbUrl(root, composeDbHostPort(root, mode));
|
|
179
|
+
}
|
|
153
180
|
/**
|
|
154
181
|
* A connection string with its password removed.
|
|
155
182
|
*
|