@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
|
@@ -1,22 +1,31 @@
|
|
|
1
1
|
import { errorMessage } from "../error-message.js";
|
|
2
|
-
import { existsSync, mkdirSync, readFileSync,
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync, } from "node:fs";
|
|
3
3
|
import { resolve, join, relative, isAbsolute } from "node:path";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { runUntilStopped } from "../run-until-stopped.js";
|
|
5
|
+
import { fetchWithin } from "../fetch-within.js";
|
|
6
|
+
import { targetRequest, targetStreamRequest } from "../target-request.js";
|
|
7
|
+
import { parseEnvText } from "../dotenv-parse.js";
|
|
8
|
+
import { withEnvValue, withoutEnvValue } from "../env-lines.js";
|
|
9
|
+
import { STOP_SIGNALS } from "../stop-signals.js";
|
|
10
|
+
import { sayTargetWarning } from "../target-warning.js";
|
|
6
11
|
import { resolveProjectApiUrl } from "../resolve-api-url.js";
|
|
7
12
|
import { loadConfig, rethrowIfConfigBroken } from "../config.js";
|
|
8
13
|
import { ensureBinary } from "../ensure-binary.js";
|
|
9
|
-
import { functionsPathCandidatesFromProject, preferredFunctionsPathFromProject, serviceRoleRoutes, } from "../project-config.js";
|
|
10
|
-
import { discoverFunctionsOrExit, functionNameProblem
|
|
14
|
+
import { FUNCTIONS_SERVE_PORT, functionsPathCandidatesFromProject, hooksPathFromProject, preferredFunctionsPathFromProject, serviceRoleRoutes, } from "../project-config.js";
|
|
15
|
+
import { discoverFunctionsOrExit, functionNameProblem } from "../functions-discovery.js";
|
|
16
|
+
import { functionsServeDenoArgs, functionsWorkerEnv, installFunctionsWorker, } from "../functions-worker-files.js";
|
|
17
|
+
import { functionsServeKeyPath, sweepStaleServeKeyFiles, writeServiceRoleKeyFileUntilExit } from "../service-role-key-file.js";
|
|
11
18
|
import { loadProjectLink } from "../link.js";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import { isArrayOf, isJsonObject, isNumber, isShape, isString, nullable, optional, readJson } from "@supatype/shared";
|
|
19
|
+
import { resolveTarget, targetFunctions } from "../resolve-target.js";
|
|
20
|
+
import { targetFetch, targetStream } from "../target-client.js";
|
|
21
|
+
import { isArrayOf, isJsonObject, isNumber, isShape, isString, isUnknown, nullable, optional } from "@supatype/shared";
|
|
16
22
|
import { ensureFunctionsDenoTypes, sharedFunctionsReadmeSource, } from "../functions-deno-types.js";
|
|
17
23
|
import { functionTemplateSource } from "../functions-template.js";
|
|
24
|
+
import { readWorkerFiles } from "../worker-module-files.js";
|
|
18
25
|
import { error, info, plain } from "../ui/messages.js";
|
|
26
|
+
import { withSpinner } from "../ui/progress.js";
|
|
19
27
|
import { nextSteps } from "../ui/next-steps.js";
|
|
28
|
+
import { DENO_ENV } from "../native-dev-env.js";
|
|
20
29
|
// ─── Constants ───────────────────────────────────────────────────────────────
|
|
21
30
|
const SHARED_DIR = "_shared";
|
|
22
31
|
const ENV_LOCAL = ".env.local";
|
|
@@ -24,11 +33,18 @@ const ENV_PRODUCTION = ".env.production";
|
|
|
24
33
|
// The commands that exist: there is no `supatype cloud` group, login and link are top level.
|
|
25
34
|
const NOT_LOGGED_IN = "Not logged in. Run: supatype login";
|
|
26
35
|
const NOT_LINKED = "No linked project. Run: supatype link";
|
|
36
|
+
/**
|
|
37
|
+
* Where a function reads its env values, said in every help that sets them: a function reading
|
|
38
|
+
* `Deno.env.get` finds nothing, and help is where a user looks first.
|
|
39
|
+
*/
|
|
40
|
+
const ENV_HELP = "Values set with `functions env set`, in .env.local or in .env.<name>.local arrive in `ctx.env` " +
|
|
41
|
+
"on each call, never in Deno.env, which every call running at once shares.";
|
|
27
42
|
// ─── Registration ────────────────────────────────────────────────────────────
|
|
28
43
|
export function registerFunctions(program) {
|
|
29
44
|
const fnCmd = program
|
|
30
45
|
.command("functions")
|
|
31
|
-
.
|
|
46
|
+
.summary("Manage Supatype Edge Functions (Deno-based serverless TypeScript)")
|
|
47
|
+
.description(`Manage Supatype Edge Functions (Deno-based serverless TypeScript).\n\n${ENV_HELP}`);
|
|
32
48
|
fnCmd
|
|
33
49
|
.command("new <name>")
|
|
34
50
|
.description("Scaffold a new edge function")
|
|
@@ -38,7 +54,8 @@ export function registerFunctions(program) {
|
|
|
38
54
|
fnCmd
|
|
39
55
|
.command("serve")
|
|
40
56
|
.description("Start a local Deno server that serves all functions with hot reload")
|
|
41
|
-
.option("--port <port>", "Port to serve on",
|
|
57
|
+
.option("--port <port>", "Port to serve on", String(FUNCTIONS_SERVE_PORT))
|
|
58
|
+
.option("--host <host>", "Address to listen on (0.0.0.0 to be reachable from other machines)", "127.0.0.1")
|
|
42
59
|
.option("--env-file <path>", "Path to env file", ENV_LOCAL)
|
|
43
60
|
.action(async (opts) => {
|
|
44
61
|
await serve(process.cwd(), opts);
|
|
@@ -75,14 +92,16 @@ export function registerFunctions(program) {
|
|
|
75
92
|
.command("invoke <name>")
|
|
76
93
|
.description("Invoke a local or deployed function")
|
|
77
94
|
.option("--data <json>", "JSON body to send", "{}")
|
|
78
|
-
.option("--auth", "
|
|
79
|
-
.option("--local", "Invoke the
|
|
95
|
+
.option("--auth", "Send a token: your Cloud session on a Cloud link, a test JWT on this machine; refused for a self-hosted server")
|
|
96
|
+
.option("--local", "Invoke locally: a running `functions serve` on --port if one answers, otherwise the dev API (the default when no Cloud project is linked)")
|
|
97
|
+
.option("--port <port>", "Port of the local `functions serve` to try first", String(FUNCTIONS_SERVE_PORT))
|
|
80
98
|
.action(async (name, opts) => {
|
|
81
99
|
await invoke(process.cwd(), name, opts);
|
|
82
100
|
});
|
|
83
101
|
const envCmd = fnCmd
|
|
84
102
|
.command("env")
|
|
85
|
-
.
|
|
103
|
+
.summary("Manage function environment variables")
|
|
104
|
+
.description(`Manage function environment variables: on the linked project, else in the functions directory's .env.local.\n\n${ENV_HELP}`);
|
|
86
105
|
envCmd
|
|
87
106
|
.command("list")
|
|
88
107
|
.description("List environment variables (values masked)")
|
|
@@ -91,7 +110,8 @@ export function registerFunctions(program) {
|
|
|
91
110
|
});
|
|
92
111
|
envCmd
|
|
93
112
|
.command("set <keyvalue>")
|
|
94
|
-
.
|
|
113
|
+
.summary("Set an environment variable (KEY=value)")
|
|
114
|
+
.description(`Set an environment variable (KEY=value).\n\n${ENV_HELP}`)
|
|
95
115
|
.action(async (keyvalue) => {
|
|
96
116
|
await envSet(process.cwd(), keyvalue);
|
|
97
117
|
});
|
|
@@ -186,28 +206,10 @@ function discoverFunctions(cwd) {
|
|
|
186
206
|
async function serve(cwd, opts) {
|
|
187
207
|
const config = loadConfig(cwd);
|
|
188
208
|
const functionsDir = resolveFunctionsDir(cwd, "read");
|
|
189
|
-
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
error("Create one with: npx supatype functions new <name>");
|
|
194
|
-
process.exit(1);
|
|
195
|
-
}
|
|
196
|
-
plain(`Discovered ${routes.length} function(s):`);
|
|
197
|
-
for (const fn of routes) {
|
|
198
|
-
plain(` /${fn.name} → ${relative(cwd, fn.entrypoint)}`);
|
|
199
|
-
}
|
|
200
|
-
plain();
|
|
201
|
-
// Generate a Deno entry script that routes requests to the correct function
|
|
202
|
-
const routerPath = resolve(functionsDir, ".serve-router.ts");
|
|
203
|
-
const routerScript = generateFunctionsRouterSource(routerPath, routes);
|
|
204
|
-
writeFileSync(routerPath, routerScript, "utf8");
|
|
205
|
-
const envFilePath = resolveEnvFilePath(cwd, functionsDir, opts.envFile);
|
|
206
|
-
const envArgs = [];
|
|
207
|
-
if (existsSync(envFilePath)) {
|
|
208
|
-
envArgs.push("--env-file", envFilePath);
|
|
209
|
-
}
|
|
210
|
-
info(`Serving functions at http://localhost:${opts.port}/functions/v1/`);
|
|
209
|
+
listServeFunctions(cwd, functionsDir);
|
|
210
|
+
const project = { cwd, config, functionsDir, keyPath: writeServeKeyFile(cwd) };
|
|
211
|
+
const envArgs = denoEnvFileArgs(resolveEnvFilePath(cwd, functionsDir, opts.envFile));
|
|
212
|
+
info(`Serving functions at ${serveDisplayUrl(opts.host, opts.port)}`);
|
|
211
213
|
info("Watching for changes...");
|
|
212
214
|
plain();
|
|
213
215
|
let denoBin;
|
|
@@ -218,37 +220,96 @@ async function serve(cwd, opts) {
|
|
|
218
220
|
error(`Could not provision Deno: ${errorMessage(err)}`);
|
|
219
221
|
process.exit(1);
|
|
220
222
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
SUPATYPE_SERVICE_ROLE_KEY: process.env["SUPATYPE_SERVICE_ROLE_KEY"] ?? "",
|
|
241
|
-
},
|
|
242
|
-
});
|
|
243
|
-
// Clean up router script
|
|
223
|
+
// The functions and hooks directories are watched too, so a function added while it serves is found.
|
|
224
|
+
const watchDirs = [functionsDir, hooksPathFromProject(config, cwd)].filter((dir) => existsSync(dir));
|
|
225
|
+
await runDenoServe(denoBin, functionsServeDenoArgs(installFunctionsWorker(), watchDirs, envArgs), { cwd, env: denoServeEnv(project, opts) });
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Deno's flag for `envFilePath`, or nothing when there is no such file. One argument: `--env-file`
|
|
229
|
+
* takes an optional value, which Deno reads only after `=`, so with the path as its own argument
|
|
230
|
+
* Deno loaded `.env` and ran the env file as the script.
|
|
231
|
+
*/
|
|
232
|
+
export function denoEnvFileArgs(envFilePath) {
|
|
233
|
+
return existsSync(envFilePath) ? [`--env-file=${envFilePath}`] : [];
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Runs the serve's Deno until it stops, then ends the command, with an error when it failed. It
|
|
237
|
+
* exits on a clean stop too, in the same turn: a Ctrl+C heard once the stop listeners are gone
|
|
238
|
+
* would kill the CLI without the `exit` that removes the key file.
|
|
239
|
+
*/
|
|
240
|
+
async function runDenoServe(denoBin, args, opts) {
|
|
241
|
+
let status;
|
|
244
242
|
try {
|
|
245
|
-
|
|
243
|
+
status = await runUntilStopped(denoBin, args, opts);
|
|
244
|
+
}
|
|
245
|
+
catch (err) {
|
|
246
|
+
error(`Could not start Deno: ${errorMessage(err)}`);
|
|
247
|
+
process.exit(1);
|
|
246
248
|
}
|
|
247
|
-
|
|
248
|
-
if (result.status !== 0) {
|
|
249
|
+
if (status !== 0)
|
|
249
250
|
error("Function server exited with errors.");
|
|
250
|
-
|
|
251
|
+
process.exit(status);
|
|
252
|
+
}
|
|
253
|
+
/** The functions under `functionsDir`, listed for the terminal, ending the command when there are none. */
|
|
254
|
+
function listServeFunctions(cwd, functionsDir) {
|
|
255
|
+
const routes = discoverFunctionsOrExit(functionsDir);
|
|
256
|
+
if (routes.length === 0) {
|
|
257
|
+
error(`No functions found in ${relativeFunctionsDir(cwd, functionsDir)}/`);
|
|
258
|
+
error("Create one with: npx supatype functions new <name>");
|
|
259
|
+
process.exit(1);
|
|
251
260
|
}
|
|
261
|
+
plain(`Discovered ${routes.length} function(s):`);
|
|
262
|
+
for (const fn of routes) {
|
|
263
|
+
plain(` /${fn.name} → ${relative(cwd, fn.entrypoint)}`);
|
|
264
|
+
}
|
|
265
|
+
plain();
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Writes this serve's key file when the shell gave a key, removed when the serve stops, and returns
|
|
269
|
+
* its path. The worker reads the key from that file, as it still can after a --watch reload, and
|
|
270
|
+
* grants it only to the routes SUPATYPE_SERVICE_ROLE_ROUTES names. Key files of serves killed
|
|
271
|
+
* outright are swept first.
|
|
272
|
+
*/
|
|
273
|
+
function writeServeKeyFile(cwd) {
|
|
274
|
+
sweepStaleServeKeyFiles(cwd);
|
|
275
|
+
const serviceRoleKey = process.env["SUPATYPE_SERVICE_ROLE_KEY"] ?? "";
|
|
276
|
+
if (serviceRoleKey === "")
|
|
277
|
+
return undefined;
|
|
278
|
+
const keyPath = functionsServeKeyPath(cwd);
|
|
279
|
+
writeServiceRoleKeyFileUntilExit(keyPath, serviceRoleKey);
|
|
280
|
+
return keyPath;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* The address `functions serve` announces for `host`: localhost for a wildcard bind (`0.0.0.0`, `::`),
|
|
284
|
+
* which is no address a browser can open, and an IPv6 host in brackets, as a URL writes it.
|
|
285
|
+
*/
|
|
286
|
+
export function serveDisplayUrl(host, port) {
|
|
287
|
+
const bare = unbracketedHost(host);
|
|
288
|
+
const shown = bare === "0.0.0.0" || bare === "::" ? "localhost" : bare.includes(":") ? `[${bare}]` : bare;
|
|
289
|
+
return `http://${shown}:${port}/functions/v1/`;
|
|
290
|
+
}
|
|
291
|
+
/** `host` without the brackets a URL puts round an IPv6 address: `[::1]` is `::1`, as Deno binds it. */
|
|
292
|
+
function unbracketedHost(host) {
|
|
293
|
+
return host.startsWith("[") && host.endsWith("]") ? host.slice(1, -1) : host;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* The environment the serve's Deno runs with: this shell's, uncoloured, plus the worker's for
|
|
297
|
+
* `project`, listening where `listen` says. Handlers reach the project's API where it answers
|
|
298
|
+
* (resolve-api-url.ts): the native server for a native project, never a gateway a Docker run left
|
|
299
|
+
* in `.env`.
|
|
300
|
+
*/
|
|
301
|
+
export function denoServeEnv(project, listen) {
|
|
302
|
+
const apiUrl = resolveProjectApiUrl(project.cwd, project.config);
|
|
303
|
+
return {
|
|
304
|
+
...process.env,
|
|
305
|
+
...DENO_ENV,
|
|
306
|
+
PORT: listen.port,
|
|
307
|
+
SUPATYPE_FUNCTIONS_HOST: unbracketedHost(listen.host),
|
|
308
|
+
SUPATYPE_URL: process.env["SUPATYPE_URL"] ?? apiUrl,
|
|
309
|
+
SUPATYPE_PUBLIC_URL: process.env["SUPATYPE_PUBLIC_URL"] ?? apiUrl,
|
|
310
|
+
SUPATYPE_ANON_KEY: process.env["SUPATYPE_ANON_KEY"] ?? "",
|
|
311
|
+
...functionsWorkerEnv(project),
|
|
312
|
+
};
|
|
252
313
|
}
|
|
253
314
|
// ─── Deploy ──────────────────────────────────────────────────────────────────
|
|
254
315
|
async function deploy(cwd, opts) {
|
|
@@ -275,34 +336,31 @@ async function deploy(cwd, opts) {
|
|
|
275
336
|
plain(`\nTotal: ${fns.length} function(s)`);
|
|
276
337
|
return;
|
|
277
338
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
catch {
|
|
288
|
-
/* fall through to compose/local */
|
|
289
|
-
}
|
|
339
|
+
// Ended outside the target's lookup: a failed deploy must not be taken for one, and deployed
|
|
340
|
+
// again another way.
|
|
341
|
+
const target = linkedTarget(cwd, opts.env);
|
|
342
|
+
if (target !== null) {
|
|
343
|
+
finishDeploy(fns.length, await deployViaTarget(cwd, target, fns));
|
|
344
|
+
info(`Invoke: ${targetFunctions(target).invokeBase}/<name>`);
|
|
345
|
+
return;
|
|
290
346
|
}
|
|
291
347
|
const { selfHostComposePaths } = await import("../self-host-compose.js");
|
|
292
348
|
if (existsSync(selfHostComposePaths(cwd).composePath)) {
|
|
293
|
-
deploySelfHosted(cwd, fns, FUNCTIONS_WORKER_RESTART_COMMAND);
|
|
349
|
+
deploySelfHosted(cwd, resolveFunctionsDir(cwd, "read"), fns, FUNCTIONS_WORKER_RESTART_COMMAND);
|
|
294
350
|
return;
|
|
295
351
|
}
|
|
296
|
-
|
|
352
|
+
error(NOT_LINKED);
|
|
353
|
+
process.exit(1);
|
|
297
354
|
}
|
|
298
355
|
/**
|
|
299
356
|
* The command that restarts this project's functions worker: the CLI's own, which recreates it
|
|
300
357
|
* with the current config and .env under the right project name, wherever it is run from.
|
|
301
358
|
*/
|
|
302
359
|
const FUNCTIONS_WORKER_RESTART_COMMAND = "supatype self-host compose restart functions-worker";
|
|
303
|
-
function deploySelfHosted(cwd, fns, restartCommand) {
|
|
360
|
+
function deploySelfHosted(cwd, functionsDir, fns, restartCommand) {
|
|
304
361
|
info("Self-host Compose deployment.");
|
|
305
|
-
|
|
362
|
+
// The directory functions.path names, which the stack mounts; it is not always functions/.
|
|
363
|
+
plain(`Functions are served from ${relativeFunctionsDir(cwd, functionsDir)}/ in your project (no bundle step).\n`);
|
|
306
364
|
for (const fn of fns) {
|
|
307
365
|
plain(` ${fn.name} → ${relative(cwd, fn.entrypoint)}`);
|
|
308
366
|
}
|
|
@@ -311,93 +369,104 @@ function deploySelfHosted(cwd, fns, restartCommand) {
|
|
|
311
369
|
plain(` ${restartCommand}`);
|
|
312
370
|
plain("\nKong → supatype-server → functions-worker (per-project worker).");
|
|
313
371
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
source,
|
|
328
|
-
entrypoint: `${fn.name}/index.ts`,
|
|
329
|
-
}],
|
|
330
|
-
// Sent every deploy, and replaced wholesale by the platform: the config file is the whole
|
|
331
|
-
// truth, so a name removed from it must stop being entitled to the service-role key.
|
|
332
|
-
serviceRole: serviceRoleRoutesFor(cwd),
|
|
333
|
-
},
|
|
334
|
-
token: target.token,
|
|
335
|
-
orgId: target.orgId,
|
|
336
|
-
environment: target.mode === "cloud" ? target.environment : undefined,
|
|
337
|
-
});
|
|
338
|
-
const duration = Date.now() - start;
|
|
339
|
-
plain(` ${fn.name} ✓ deployed (${duration}ms)`);
|
|
340
|
-
}
|
|
341
|
-
catch (err) {
|
|
342
|
-
plain(` ${fn.name} ✗ ${err instanceof Error ? err.message : "unknown error"}`);
|
|
343
|
-
}
|
|
372
|
+
/**
|
|
373
|
+
* The linked project's target, or null when the project is not linked. A link that cannot be used,
|
|
374
|
+
* with no session or an environment that is not linked, ends the command and says why: it is never
|
|
375
|
+
* taken for no link, which would send the work somewhere else. `needsToken` false is for invoke,
|
|
376
|
+
* which calls a public function and needs no session.
|
|
377
|
+
*/
|
|
378
|
+
function linkedTarget(cwd, env, needsToken = true) {
|
|
379
|
+
try {
|
|
380
|
+
return resolveLinkedTarget(cwd, env, needsToken);
|
|
381
|
+
}
|
|
382
|
+
catch (err) {
|
|
383
|
+
error(errorMessage(err));
|
|
384
|
+
process.exit(1);
|
|
344
385
|
}
|
|
345
|
-
info(`Deployed ${fns.length} function(s)`);
|
|
346
|
-
void cwd;
|
|
347
386
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
387
|
+
/** {@link linkedTarget}, throwing rather than ending the command, for work under a spinner. */
|
|
388
|
+
function resolveLinkedTarget(cwd, env, needsToken) {
|
|
389
|
+
if (!loadProjectLink(cwd))
|
|
390
|
+
return null;
|
|
391
|
+
const target = resolveTarget(cwd, { env, tokenOptional: !needsToken });
|
|
392
|
+
if (needsToken && !target.token)
|
|
393
|
+
throw new Error(NOT_LOGGED_IN);
|
|
394
|
+
return target;
|
|
395
|
+
}
|
|
396
|
+
/** {@link linkedTarget}, ending the command when the project is not linked. */
|
|
397
|
+
function requireLinkedTarget(cwd) {
|
|
398
|
+
const target = linkedTarget(cwd, undefined);
|
|
399
|
+
if (target === null) {
|
|
352
400
|
error(NOT_LINKED);
|
|
353
401
|
process.exit(1);
|
|
354
402
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
403
|
+
return target;
|
|
404
|
+
}
|
|
405
|
+
/** Asks `target` for `subpath` of its project, ending the command with `what` and the reason when it fails. */
|
|
406
|
+
async function askTarget(target, what, call, guard) {
|
|
407
|
+
try {
|
|
408
|
+
const answer = await targetFetch(target.apiBaseUrl, target.apiPrefix, targetRequest(target, call), guard);
|
|
409
|
+
sayTargetWarning(answer);
|
|
410
|
+
return answer;
|
|
411
|
+
}
|
|
412
|
+
catch (err) {
|
|
413
|
+
error(`${what}: ${errorMessage(err)}`);
|
|
358
414
|
process.exit(1);
|
|
359
415
|
}
|
|
360
|
-
|
|
361
|
-
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Deploys through the linked target in one request carrying every function, so a self-hosted worker
|
|
419
|
+
* restarts once a deploy rather than once a function; saying how each went. A refused request fails
|
|
420
|
+
* every function it carried. Returns the names that failed.
|
|
421
|
+
*/
|
|
422
|
+
async function deployViaTarget(cwd, target, fns) {
|
|
423
|
+
info(`Deploying to ${target.mode} project: ${target.projectRef} (${target.environment})`);
|
|
362
424
|
plain();
|
|
425
|
+
const serviceRole = serviceRoleRoutesFor(cwd);
|
|
426
|
+
const { sent, failed } = readSources(fns);
|
|
427
|
+
if (sent.length === 0)
|
|
428
|
+
return failed;
|
|
429
|
+
const start = Date.now();
|
|
430
|
+
const body = { functions: sent, ...(serviceRole !== undefined && { serviceRole }) };
|
|
431
|
+
try {
|
|
432
|
+
const call = { method: "POST", subpath: "/functions/deploy", body, restartsWorker: true, handlers: sent.length };
|
|
433
|
+
sayTargetWarning(await targetFetch(target.apiBaseUrl, target.apiPrefix, targetRequest(target, call)));
|
|
434
|
+
}
|
|
435
|
+
catch (err) {
|
|
436
|
+
for (const fn of sent)
|
|
437
|
+
plain(` ${fn.name} ✗ ${errorMessage(err)}`);
|
|
438
|
+
return [...failed, ...sent.map((fn) => fn.name)];
|
|
439
|
+
}
|
|
440
|
+
for (const fn of sent)
|
|
441
|
+
plain(` ${fn.name} ✓ deployed (${Date.now() - start}ms)`);
|
|
442
|
+
return failed;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Each function's source, as the deploy request carries it; one that cannot be read is said and
|
|
446
|
+
* failed here, and the rest are still sent.
|
|
447
|
+
*/
|
|
448
|
+
function readSources(fns) {
|
|
449
|
+
const sent = [];
|
|
450
|
+
const failed = [];
|
|
363
451
|
for (const fn of fns) {
|
|
364
|
-
const start = Date.now();
|
|
365
|
-
// Read source code
|
|
366
|
-
const source = readFunctionSource(fn);
|
|
367
452
|
try {
|
|
368
|
-
|
|
369
|
-
method: "POST",
|
|
370
|
-
headers: {
|
|
371
|
-
Authorization: `Bearer ${token}`,
|
|
372
|
-
"Content-Type": "application/json",
|
|
373
|
-
"X-Org-Id": linked.orgId ?? "",
|
|
374
|
-
},
|
|
375
|
-
body: JSON.stringify({
|
|
376
|
-
functions: [{
|
|
377
|
-
name: fn.name,
|
|
378
|
-
source,
|
|
379
|
-
entrypoint: `${fn.name}/index.ts`,
|
|
380
|
-
}],
|
|
381
|
-
// Same grants as the target path: both reach the same endpoint, and a project deployed one
|
|
382
|
-
// way must not end up with a different credential surface than the other.
|
|
383
|
-
serviceRole: serviceRoleRoutesFor(cwd),
|
|
384
|
-
}),
|
|
385
|
-
signal: AbortSignal.timeout(60_000),
|
|
386
|
-
});
|
|
387
|
-
if (!res.ok) {
|
|
388
|
-
const reason = await failureReason(res);
|
|
389
|
-
plain(` ${fn.name} ✗ ${reason}`);
|
|
390
|
-
continue;
|
|
391
|
-
}
|
|
392
|
-
const duration = Date.now() - start;
|
|
393
|
-
plain(` ${fn.name} ✓ deployed (${duration}ms)`);
|
|
453
|
+
sent.push({ name: fn.name, entrypoint: `${fn.name}/index.ts`, ...readFunctionFiles(fn) });
|
|
394
454
|
}
|
|
395
455
|
catch (err) {
|
|
396
|
-
|
|
456
|
+
failed.push(fn.name);
|
|
457
|
+
plain(` ${fn.name} ✗ ${errorMessage(err)}`);
|
|
397
458
|
}
|
|
398
459
|
}
|
|
399
|
-
|
|
400
|
-
|
|
460
|
+
return { sent, failed };
|
|
461
|
+
}
|
|
462
|
+
/** Says how many deployed, or names those that failed and ends non-zero. */
|
|
463
|
+
function finishDeploy(total, failed) {
|
|
464
|
+
if (failed.length === 0) {
|
|
465
|
+
info(`Deployed ${total} function(s)`);
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
error(`${failed.length} of ${total} function(s) failed to deploy: ${failed.join(", ")}`);
|
|
469
|
+
process.exit(1);
|
|
401
470
|
}
|
|
402
471
|
/**
|
|
403
472
|
* The project's `functions.serviceRole` list, or undefined when the config cannot be read.
|
|
@@ -414,293 +483,271 @@ export function serviceRoleRoutesFor(cwd) {
|
|
|
414
483
|
return undefined;
|
|
415
484
|
}
|
|
416
485
|
}
|
|
417
|
-
/** The control plane's reason for a refusal: its `message`, else the status text. */
|
|
418
|
-
async function failureReason(res) {
|
|
419
|
-
const body = await res.json().catch(() => ({}));
|
|
420
|
-
const message = isJsonObject(body) ? body["message"] : undefined;
|
|
421
|
-
return typeof message === "string" ? message : res.statusText;
|
|
422
|
-
}
|
|
423
486
|
/** `GET /functions`: each deployed function, with its last day's use. */
|
|
424
|
-
const isDeployedFunctions = isShape({
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
})),
|
|
431
|
-
});
|
|
487
|
+
const isDeployedFunctions = isArrayOf(isShape({
|
|
488
|
+
name: isString,
|
|
489
|
+
deployedAt: optional(nullable(isString)),
|
|
490
|
+
invocations24h: optional(nullable(isNumber)),
|
|
491
|
+
avgDurationMs: optional(nullable(isNumber)),
|
|
492
|
+
}));
|
|
432
493
|
/** `GET /functions/:name/logs`: the newest entries first. */
|
|
433
|
-
const isFunctionLogs = isShape({
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
function
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
const files =
|
|
443
|
-
|
|
444
|
-
for (const entry of entries) {
|
|
445
|
-
const fullPath = join(fn.path, entry);
|
|
446
|
-
if (statSync(fullPath).isFile() && (entry.endsWith(".ts") || entry.endsWith(".js"))) {
|
|
447
|
-
files[entry] = readFileSync(fullPath, "utf8");
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
return JSON.stringify(files);
|
|
494
|
+
const isFunctionLogs = isArrayOf(isShape({ timestamp: isString, level: isString, message: optional(nullable(isString)) }));
|
|
495
|
+
/**
|
|
496
|
+
* A function's source as the deploy request carries it. A file function is its own entry. A
|
|
497
|
+
* directory function's entry is its index.ts, and every file under it the worker loads
|
|
498
|
+
* ({@link readWorkerFiles}) goes in `files`, by a path with `/` on every OS.
|
|
499
|
+
*/
|
|
500
|
+
function readFunctionFiles(fn) {
|
|
501
|
+
if (statSync(fn.path).isFile())
|
|
502
|
+
return { source: readFileSync(fn.path, "utf8") };
|
|
503
|
+
const files = readWorkerFiles(fn.path);
|
|
504
|
+
return { source: files["index.ts"] ?? "", files };
|
|
451
505
|
}
|
|
452
506
|
// ─── List ────────────────────────────────────────────────────────────────────
|
|
453
507
|
async function listFunctions(cwd) {
|
|
454
|
-
const
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
info("No functions found locally or remotely.");
|
|
461
|
-
return;
|
|
462
|
-
}
|
|
463
|
-
plain("Local functions (not linked to a cloud project):\n");
|
|
464
|
-
for (const fn of fns) {
|
|
465
|
-
plain(` ${fn.name.padEnd(30)} ${relative(cwd, fn.entrypoint)}`);
|
|
466
|
-
}
|
|
508
|
+
const target = linkedTarget(cwd, undefined);
|
|
509
|
+
if (target === null)
|
|
510
|
+
return listLocalFunctions(cwd);
|
|
511
|
+
const data = await askTarget(target, "Failed to list functions", { method: "GET", subpath: "/functions" }, isDeployedFunctions);
|
|
512
|
+
if (data.length === 0) {
|
|
513
|
+
info("No deployed functions.");
|
|
467
514
|
return;
|
|
468
515
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
const res = await fetch(`${getCloudApiUrl(cwd)}/api/v1/projects/${linked.ref}/functions`, {
|
|
476
|
-
headers: {
|
|
477
|
-
Authorization: `Bearer ${token}`,
|
|
478
|
-
"X-Org-Id": linked.orgId ?? "",
|
|
479
|
-
},
|
|
480
|
-
signal: AbortSignal.timeout(10_000),
|
|
481
|
-
});
|
|
482
|
-
if (!res.ok) {
|
|
483
|
-
error(`Failed to list functions: ${res.statusText}`);
|
|
484
|
-
process.exit(1);
|
|
485
|
-
}
|
|
486
|
-
const { data } = await readJson(res, isDeployedFunctions);
|
|
487
|
-
if (data.length === 0) {
|
|
488
|
-
info("No deployed functions.");
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
491
|
-
plain("Deployed functions:\n");
|
|
492
|
-
plain(` ${"Name".padEnd(28)} ${"Last Deployed".padEnd(24)} ${"Invocations (24h)".padEnd(20)} Avg Duration`);
|
|
493
|
-
plain(` ${"─".repeat(28)} ${"─".repeat(24)} ${"─".repeat(20)} ${"─".repeat(12)}`);
|
|
494
|
-
for (const fn of data) {
|
|
495
|
-
const deployed = fn.deployedAt ? new Date(fn.deployedAt).toLocaleString() : "-";
|
|
496
|
-
plain(` ${fn.name.padEnd(28)} ${deployed.padEnd(24)} ${String(fn.invocations24h ?? 0).padEnd(20)} ${fn.avgDurationMs ?? 0}ms`);
|
|
497
|
-
}
|
|
516
|
+
plain("Deployed functions:\n");
|
|
517
|
+
plain(` ${"Name".padEnd(28)} ${"Last Deployed".padEnd(24)} ${"Invocations (24h)".padEnd(20)} Avg Duration`);
|
|
518
|
+
plain(` ${"─".repeat(28)} ${"─".repeat(24)} ${"─".repeat(20)} ${"─".repeat(12)}`);
|
|
519
|
+
for (const fn of data) {
|
|
520
|
+
const deployed = fn.deployedAt ? new Date(fn.deployedAt).toLocaleString() : "-";
|
|
521
|
+
plain(` ${fn.name.padEnd(28)} ${deployed.padEnd(24)} ${String(fn.invocations24h ?? 0).padEnd(20)} ${fn.avgDurationMs ?? 0}ms`);
|
|
498
522
|
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
523
|
+
}
|
|
524
|
+
/** The functions on disk, for a project that is not linked. */
|
|
525
|
+
function listLocalFunctions(cwd) {
|
|
526
|
+
const fns = discoverFunctions(cwd);
|
|
527
|
+
if (fns.length === 0) {
|
|
528
|
+
info("No functions found locally or remotely.");
|
|
529
|
+
return;
|
|
502
530
|
}
|
|
531
|
+
plain("Local functions (not linked to a project):\n");
|
|
532
|
+
for (const fn of fns)
|
|
533
|
+
plain(` ${fn.name.padEnd(30)} ${relative(cwd, fn.entrypoint)}`);
|
|
503
534
|
}
|
|
504
535
|
// ─── Delete ──────────────────────────────────────────────────────────────────
|
|
505
536
|
async function deleteFunction(cwd, name) {
|
|
506
|
-
const
|
|
507
|
-
const
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
537
|
+
const target = requireLinkedTarget(cwd);
|
|
538
|
+
const call = { method: "DELETE", subpath: `/functions/${encodeURIComponent(name)}`, restartsWorker: true };
|
|
539
|
+
await askTarget(target, `Failed to delete "${name}"`, call, isUnknown);
|
|
540
|
+
info(`Function "${name}" deleted. It will return 404 immediately.`);
|
|
541
|
+
}
|
|
542
|
+
// ─── Logs ────────────────────────────────────────────────────────────────────
|
|
543
|
+
/**
|
|
544
|
+
* A function's logs from the linked target: a window of past lines from Supatype Cloud, or the
|
|
545
|
+
* worker's live stream from a server, tailed until Ctrl+C.
|
|
546
|
+
*/
|
|
547
|
+
async function functionLogs(cwd, name, opts) {
|
|
548
|
+
const target = requireLinkedTarget(cwd);
|
|
549
|
+
const { logs } = targetFunctions(target);
|
|
550
|
+
if (logs.kind === "tail")
|
|
551
|
+
return tailServerLogs(target, logs.tail, name);
|
|
552
|
+
const subpath = `/functions/${encodeURIComponent(name)}/logs?since=${encodeURIComponent(opts.since)}`;
|
|
553
|
+
const lines = await askTarget(target, "Failed to fetch logs", { method: "GET", subpath }, isFunctionLogs);
|
|
554
|
+
if (lines.length === 0)
|
|
555
|
+
info(`No logs for "${name}" in the last ${opts.since}.`);
|
|
556
|
+
for (const entry of lines)
|
|
557
|
+
plain(formatLogLine(entry));
|
|
558
|
+
}
|
|
559
|
+
/** Tails the linked server's relay of the worker's log stream at `tail`, printing `name`'s lines. */
|
|
560
|
+
async function tailServerLogs(target, tail, name) {
|
|
561
|
+
info(`Tailing logs for "${name}" on ${tail.baseUrl}. Press Ctrl+C to stop.`);
|
|
562
|
+
let body;
|
|
563
|
+
try {
|
|
564
|
+
body = await targetStream(tail.baseUrl, tail.apiPrefix, targetStreamRequest(target, tail.path));
|
|
511
565
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
error(NOT_LOGGED_IN);
|
|
566
|
+
catch (err) {
|
|
567
|
+
error(`Failed to tail logs: ${errorMessage(err)}`);
|
|
515
568
|
process.exit(1);
|
|
516
569
|
}
|
|
570
|
+
await printLogStream(body, name);
|
|
571
|
+
}
|
|
572
|
+
/** Prints `name`'s lines from a server-sent event stream as they arrive, until it ends. */
|
|
573
|
+
async function printLogStream(body, name) {
|
|
574
|
+
const reader = body.getReader();
|
|
575
|
+
// Ctrl+C closes the stream and the command ends by itself, with exit 0, rather than being killed.
|
|
576
|
+
const stop = () => void reader.cancel().catch(() => undefined);
|
|
577
|
+
for (const signal of STOP_SIGNALS)
|
|
578
|
+
process.on(signal, stop);
|
|
517
579
|
try {
|
|
518
|
-
|
|
519
|
-
method: "DELETE",
|
|
520
|
-
headers: {
|
|
521
|
-
Authorization: `Bearer ${token}`,
|
|
522
|
-
"X-Org-Id": linked.orgId ?? "",
|
|
523
|
-
},
|
|
524
|
-
signal: AbortSignal.timeout(10_000),
|
|
525
|
-
});
|
|
526
|
-
if (!res.ok) {
|
|
527
|
-
const reason = await failureReason(res);
|
|
528
|
-
error(`Failed to delete "${name}": ${reason}`);
|
|
529
|
-
process.exit(1);
|
|
530
|
-
}
|
|
531
|
-
info(`Function "${name}" deleted. It will return 404 immediately.`);
|
|
580
|
+
await printEvents(reader, name);
|
|
532
581
|
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
582
|
+
finally {
|
|
583
|
+
for (const signal of STOP_SIGNALS)
|
|
584
|
+
process.off(signal, stop);
|
|
536
585
|
}
|
|
537
586
|
}
|
|
538
|
-
|
|
539
|
-
async function
|
|
540
|
-
const
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
587
|
+
/** Prints `name`'s lines from `reader` until the stream ends or is cancelled. */
|
|
588
|
+
async function printEvents(reader, name) {
|
|
589
|
+
const decoder = new TextDecoder();
|
|
590
|
+
let pending = "";
|
|
591
|
+
// A reader rather than `for await`: the DOM lib the integration package compiles against gives a
|
|
592
|
+
// ReadableStream no async iterator.
|
|
593
|
+
for (let chunk = await reader.read(); !chunk.done; chunk = await reader.read()) {
|
|
594
|
+
pending += decoder.decode(chunk.value, { stream: true });
|
|
595
|
+
const lines = pending.split("\n");
|
|
596
|
+
pending = lines.pop() ?? "";
|
|
597
|
+
for (const line of lines)
|
|
598
|
+
printLogEvent(line, name);
|
|
599
|
+
}
|
|
600
|
+
printLogEvent(pending, name);
|
|
601
|
+
}
|
|
602
|
+
const isLogEvent = isShape({ timestamp: isString, level: isString, message: optional(nullable(isString)), function: optional(isString) });
|
|
603
|
+
/** One `data:` line of the worker's stream, printed when it is `name`'s. Others are skipped. */
|
|
604
|
+
function printLogEvent(line, name) {
|
|
605
|
+
if (!line.startsWith("data: "))
|
|
606
|
+
return;
|
|
607
|
+
let event;
|
|
608
|
+
try {
|
|
609
|
+
event = JSON.parse(line.slice("data: ".length));
|
|
545
610
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
error(NOT_LOGGED_IN);
|
|
549
|
-
process.exit(1);
|
|
611
|
+
catch {
|
|
612
|
+
return;
|
|
550
613
|
}
|
|
614
|
+
if (isLogEvent(event) && event.function === name)
|
|
615
|
+
plain(formatLogLine(event));
|
|
616
|
+
}
|
|
617
|
+
/** A log line as both paths print it: time of day, level, message. */
|
|
618
|
+
function formatLogLine(entry) {
|
|
619
|
+
const ts = new Date(entry.timestamp).toISOString().slice(11, 23);
|
|
620
|
+
return `${ts} [${entry.level.toUpperCase().padEnd(5)}] ${entry.message ?? ""}`;
|
|
621
|
+
}
|
|
622
|
+
async function invoke(cwd, name, opts) {
|
|
623
|
+
const body = jsonBodyOrExit(opts.data);
|
|
624
|
+
const { url, headers } = await invokeRequest(cwd, name, opts);
|
|
551
625
|
try {
|
|
552
|
-
const
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
},
|
|
557
|
-
signal: AbortSignal.timeout(10_000),
|
|
558
|
-
});
|
|
559
|
-
if (!res.ok) {
|
|
560
|
-
error(`Failed to fetch logs: ${res.statusText}`);
|
|
561
|
-
process.exit(1);
|
|
562
|
-
}
|
|
563
|
-
const { data } = await readJson(res, isFunctionLogs);
|
|
564
|
-
if (data.length === 0) {
|
|
565
|
-
info(`No logs for "${name}" in the last ${opts.since}.`);
|
|
566
|
-
return;
|
|
567
|
-
}
|
|
568
|
-
for (const entry of data) {
|
|
569
|
-
const ts = new Date(entry.timestamp).toISOString().slice(11, 23);
|
|
570
|
-
const level = entry.level.toUpperCase().padEnd(5);
|
|
571
|
-
plain(`${ts} [${level}] ${entry.message}`);
|
|
572
|
-
}
|
|
626
|
+
const start = Date.now();
|
|
627
|
+
const res = await fetchWithin(url, 30_000, { method: "POST", headers, body });
|
|
628
|
+
const duration = Date.now() - start;
|
|
629
|
+
printInvokeAnswer(res.status, duration, await res.text());
|
|
573
630
|
}
|
|
574
631
|
catch (err) {
|
|
575
|
-
|
|
632
|
+
reportInvokeFailure(url, err);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
/** `data` when it is JSON; otherwise the command ends saying so. */
|
|
636
|
+
function jsonBodyOrExit(data) {
|
|
637
|
+
try {
|
|
638
|
+
JSON.parse(data);
|
|
639
|
+
return data;
|
|
640
|
+
}
|
|
641
|
+
catch {
|
|
642
|
+
error("Invalid JSON data. Use --data '{\"key\": \"value\"}'");
|
|
576
643
|
process.exit(1);
|
|
577
644
|
}
|
|
578
645
|
}
|
|
579
|
-
|
|
580
|
-
async function
|
|
581
|
-
|
|
646
|
+
/** Where the function is, the linked target's or this machine's, and the headers to send it. */
|
|
647
|
+
async function invokeRequest(cwd, name, opts) {
|
|
648
|
+
const target = opts.local ? null : linkedTarget(cwd, undefined, false);
|
|
649
|
+
const url = target === null
|
|
650
|
+
? `${await localFunctionsBase(cwd, opts.port)}/${name}`
|
|
651
|
+
: `${targetFunctions(target).invokeBase}/${name}`;
|
|
582
652
|
const headers = { "Content-Type": "application/json" };
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
653
|
+
if (opts.auth)
|
|
654
|
+
headers["Authorization"] = `Bearer ${target === null ? LOCAL_TEST_JWT : invokeToken(target)}`;
|
|
655
|
+
return { url, headers };
|
|
656
|
+
}
|
|
657
|
+
/** The status, how long it took, and the body, as JSON when it is. */
|
|
658
|
+
function printInvokeAnswer(status, duration, responseBody) {
|
|
659
|
+
plain(`Status: ${status} (${duration}ms)`);
|
|
660
|
+
plain();
|
|
661
|
+
try {
|
|
662
|
+
const json = JSON.parse(responseBody);
|
|
663
|
+
plain(JSON.stringify(json, null, 2));
|
|
588
664
|
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
const linked = getLinkedProject(cwd);
|
|
592
|
-
if (linked) {
|
|
593
|
-
url = `https://${linked.ref}.supatype.dev/functions/v1/${name}`;
|
|
594
|
-
const token = getCloudToken(cwd);
|
|
595
|
-
if (token && opts.auth) {
|
|
596
|
-
headers["Authorization"] = `Bearer ${token}`;
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
else {
|
|
600
|
-
url = localUrl;
|
|
601
|
-
}
|
|
665
|
+
catch {
|
|
666
|
+
plain(responseBody);
|
|
602
667
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
668
|
+
}
|
|
669
|
+
/** Ends the command with why the function could not be called. */
|
|
670
|
+
function reportInvokeFailure(url, err) {
|
|
671
|
+
if (err instanceof TypeError && errorMessage(err).includes("fetch")) {
|
|
672
|
+
error(`Cannot reach ${url}`);
|
|
673
|
+
error("Is the function server running? Start it with: npx supatype functions serve");
|
|
674
|
+
}
|
|
675
|
+
else {
|
|
676
|
+
error(`Error: ${errorMessage(err)}`);
|
|
606
677
|
}
|
|
678
|
+
process.exit(1);
|
|
679
|
+
}
|
|
680
|
+
/** A placeholder user token for a function served on this machine; never sent to a linked server. */
|
|
681
|
+
const LOCAL_TEST_JWT = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0LXVzZXIiLCJyb2xlIjoiYXV0aGVudGljYXRlZCIsImlhdCI6MTcwMDAwMDAwMH0.test";
|
|
682
|
+
/**
|
|
683
|
+
* The token `invoke --auth` sends to a linked target ({@link targetFunctions}), or the command ends
|
|
684
|
+
* saying why there is none. A self-hosted server gets neither the placeholder nor the link's
|
|
685
|
+
* service-role key.
|
|
686
|
+
*/
|
|
687
|
+
function invokeToken(target) {
|
|
688
|
+
const token = targetFunctions(target).invokeToken;
|
|
689
|
+
if (token !== undefined)
|
|
690
|
+
return token;
|
|
691
|
+
if (target.mode === "cloud")
|
|
692
|
+
error(`--auth sends your Supatype Cloud session. ${NOT_LOGGED_IN}`);
|
|
693
|
+
else
|
|
694
|
+
error(`--auth has no user token for ${target.apiBaseUrl}. Call the function with a signed-in user's access token instead.`);
|
|
695
|
+
process.exit(1);
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* An env command's work under one spinner, from the start (reading the link and the config, which
|
|
699
|
+
* runs it in a child process) to the target's answer, for every target: on a self-hosted stack it
|
|
700
|
+
* takes seconds, and nothing on screen said it was working. A failure ends the command once the
|
|
701
|
+
* spinner has stopped, saying what failed and why.
|
|
702
|
+
*/
|
|
703
|
+
async function envWork(cwd, work) {
|
|
704
|
+
let outcome;
|
|
607
705
|
try {
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
error("Invalid JSON data. Use --data '{\"key\": \"value\"}'");
|
|
615
|
-
process.exit(1);
|
|
616
|
-
}
|
|
617
|
-
const start = Date.now();
|
|
618
|
-
const res = await fetch(url, {
|
|
619
|
-
method: "POST",
|
|
620
|
-
headers,
|
|
621
|
-
body,
|
|
622
|
-
signal: AbortSignal.timeout(30_000),
|
|
706
|
+
outcome = await withSpinner(work.spinner, async () => {
|
|
707
|
+
const target = resolveLinkedTarget(cwd, undefined, true);
|
|
708
|
+
if (target === null)
|
|
709
|
+
return { kind: "local", functionsDir: resolveFunctionsDir(cwd, work.local) };
|
|
710
|
+
const answer = await targetFetch(target.apiBaseUrl, target.apiPrefix, targetRequest(target, work.call), work.guard);
|
|
711
|
+
return { kind: "target", target, answer };
|
|
623
712
|
});
|
|
624
|
-
const duration = Date.now() - start;
|
|
625
|
-
const responseBody = await res.text();
|
|
626
|
-
plain(`Status: ${res.status} (${duration}ms)`);
|
|
627
|
-
plain();
|
|
628
|
-
// Try to pretty-print JSON
|
|
629
|
-
try {
|
|
630
|
-
const json = JSON.parse(responseBody);
|
|
631
|
-
plain(JSON.stringify(json, null, 2));
|
|
632
|
-
}
|
|
633
|
-
catch {
|
|
634
|
-
plain(responseBody);
|
|
635
|
-
}
|
|
636
713
|
}
|
|
637
714
|
catch (err) {
|
|
638
|
-
|
|
639
|
-
error(`Cannot reach ${url}`);
|
|
640
|
-
error("Is the function server running? Start it with: npx supatype functions serve");
|
|
641
|
-
}
|
|
642
|
-
else {
|
|
643
|
-
error(`Error: ${err instanceof Error ? err.message : "unknown"}`);
|
|
644
|
-
}
|
|
715
|
+
error(`${work.failed}: ${errorMessage(err)}`);
|
|
645
716
|
process.exit(1);
|
|
646
717
|
}
|
|
718
|
+
if (outcome.kind === "target")
|
|
719
|
+
sayTargetWarning(outcome.answer);
|
|
720
|
+
return outcome;
|
|
647
721
|
}
|
|
648
|
-
// ─── Env management ──────────────────────────────────────────────────────────
|
|
649
722
|
async function envList(cwd) {
|
|
650
|
-
const {
|
|
651
|
-
const
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
for (const line of lines) {
|
|
662
|
-
const trimmed = line.trim();
|
|
663
|
-
if (!trimmed || trimmed.startsWith("#"))
|
|
664
|
-
continue;
|
|
665
|
-
const eqIdx = trimmed.indexOf("=");
|
|
666
|
-
if (eqIdx > 0) {
|
|
667
|
-
const key = trimmed.slice(0, eqIdx);
|
|
668
|
-
plain(` ${key} = ••••••••`);
|
|
669
|
-
}
|
|
670
|
-
}
|
|
723
|
+
const call = { method: "GET", subpath: "/functions/env" };
|
|
724
|
+
const work = { spinner: "Listing environment variables", failed: "Failed to list env vars", call, guard: isEnvListing, local: "read" };
|
|
725
|
+
const outcome = await envWork(cwd, work);
|
|
726
|
+
if (outcome.kind === "local")
|
|
727
|
+
return listLocalEnv(outcome.functionsDir);
|
|
728
|
+
const listed = outcome.answer;
|
|
729
|
+
// Every target lists the names. An older self-hosted control plane answers a map of names to
|
|
730
|
+
// values, read here for its names alone.
|
|
731
|
+
const keys = Array.isArray(listed) ? listed : Object.keys(listed);
|
|
732
|
+
if (keys.length === 0) {
|
|
733
|
+
info("No environment variables set.");
|
|
671
734
|
return;
|
|
672
735
|
}
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
signal: AbortSignal.timeout(10_000),
|
|
685
|
-
});
|
|
686
|
-
if (!res.ok) {
|
|
687
|
-
error(`Failed to list env vars: ${res.statusText}`);
|
|
688
|
-
process.exit(1);
|
|
689
|
-
}
|
|
690
|
-
const { data } = await readJson(res, isShape({ data: isArrayOf(isString) }));
|
|
691
|
-
if (data.length === 0) {
|
|
692
|
-
info("No environment variables set.");
|
|
693
|
-
return;
|
|
694
|
-
}
|
|
695
|
-
plain("Environment variables (values masked):\n");
|
|
696
|
-
for (const key of data) {
|
|
697
|
-
plain(` ${key} = ••••••••`);
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
catch (err) {
|
|
701
|
-
error(`Error: ${err instanceof Error ? err.message : "unknown"}`);
|
|
702
|
-
process.exit(1);
|
|
736
|
+
plain("Environment variables (values masked):\n");
|
|
737
|
+
for (const key of keys)
|
|
738
|
+
plain(` ${key} = ••••••••`);
|
|
739
|
+
}
|
|
740
|
+
const isEnvListing = (value) => isArrayOf(isString)(value) || isJsonObject(value);
|
|
741
|
+
/** The variables in the functions' local env file, for a project that is not linked. */
|
|
742
|
+
function listLocalEnv(functionsDir) {
|
|
743
|
+
const envPath = resolve(functionsDir, ENV_LOCAL);
|
|
744
|
+
if (!existsSync(envPath)) {
|
|
745
|
+
info("No environment variables configured.");
|
|
746
|
+
return;
|
|
703
747
|
}
|
|
748
|
+
plain("Local environment variables:\n");
|
|
749
|
+
for (const key of Object.keys(parseEnvText(readFileSync(envPath, "utf8"))))
|
|
750
|
+
plain(` ${key} = ••••••••`);
|
|
704
751
|
}
|
|
705
752
|
async function envSet(cwd, keyvalue) {
|
|
706
753
|
const eqIdx = keyvalue.indexOf("=");
|
|
@@ -710,121 +757,70 @@ async function envSet(cwd, keyvalue) {
|
|
|
710
757
|
}
|
|
711
758
|
const key = keyvalue.slice(0, eqIdx);
|
|
712
759
|
const value = keyvalue.slice(eqIdx + 1);
|
|
713
|
-
const {
|
|
714
|
-
const
|
|
715
|
-
if (
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
content = content.trimEnd() + `\n${key}=${value}\n`;
|
|
726
|
-
}
|
|
727
|
-
writeFileSync(envPath, content, "utf8");
|
|
728
|
-
info(`Set ${key} in local env file.`);
|
|
729
|
-
return;
|
|
730
|
-
}
|
|
731
|
-
const token = getCloudToken(cwd);
|
|
732
|
-
if (!token) {
|
|
733
|
-
error(NOT_LOGGED_IN);
|
|
734
|
-
process.exit(1);
|
|
735
|
-
}
|
|
736
|
-
try {
|
|
737
|
-
const res = await fetch(`${getCloudApiUrl(cwd)}/api/v1/projects/${linked.ref}/functions/env`, {
|
|
738
|
-
method: "POST",
|
|
739
|
-
headers: {
|
|
740
|
-
Authorization: `Bearer ${token}`,
|
|
741
|
-
"Content-Type": "application/json",
|
|
742
|
-
"X-Org-Id": linked.orgId ?? "",
|
|
743
|
-
},
|
|
744
|
-
body: JSON.stringify({ key, value }),
|
|
745
|
-
signal: AbortSignal.timeout(10_000),
|
|
746
|
-
});
|
|
747
|
-
if (!res.ok) {
|
|
748
|
-
const reason = await failureReason(res);
|
|
749
|
-
error(`Failed to set env var: ${reason}`);
|
|
750
|
-
process.exit(1);
|
|
751
|
-
}
|
|
752
|
-
info(`Set ${key} for project ${linked.ref}.`);
|
|
753
|
-
}
|
|
754
|
-
catch (err) {
|
|
755
|
-
error(`Error: ${err instanceof Error ? err.message : "unknown"}`);
|
|
756
|
-
process.exit(1);
|
|
757
|
-
}
|
|
760
|
+
const call = { method: "POST", subpath: "/functions/env", body: { key, value }, restartsWorker: true };
|
|
761
|
+
const outcome = await envWork(cwd, { spinner: `Setting ${key}`, failed: "Failed to set env var", call, guard: isUnknown, local: "write" });
|
|
762
|
+
if (outcome.kind === "local")
|
|
763
|
+
return setLocalEnv(outcome.functionsDir, key, value);
|
|
764
|
+
info(`Set ${key} for project ${outcome.target.projectRef}.`);
|
|
765
|
+
}
|
|
766
|
+
/** Sets `key` in the functions' local env file, replacing its line or adding one. */
|
|
767
|
+
function setLocalEnv(functionsDir, key, value) {
|
|
768
|
+
const envPath = resolve(functionsDir, ENV_LOCAL);
|
|
769
|
+
const content = existsSync(envPath) ? readFileSync(envPath, "utf8") : "";
|
|
770
|
+
writeFileSync(envPath, withEnvValue(content, key, value), "utf8");
|
|
771
|
+
info(`Set ${key} in local env file.`);
|
|
758
772
|
}
|
|
759
773
|
async function envUnset(cwd, key) {
|
|
760
|
-
const {
|
|
761
|
-
const
|
|
762
|
-
if (
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
if (!token) {
|
|
777
|
-
error(NOT_LOGGED_IN);
|
|
774
|
+
const call = { method: "DELETE", subpath: `/functions/env/${encodeURIComponent(key)}`, restartsWorker: true };
|
|
775
|
+
const outcome = await envWork(cwd, { spinner: `Removing ${key}`, failed: "Failed to unset env var", call, guard: isUnknown, local: "read" });
|
|
776
|
+
if (outcome.kind === "local")
|
|
777
|
+
return unsetLocalEnv(outcome.functionsDir, key);
|
|
778
|
+
const { answer, target } = outcome;
|
|
779
|
+
// A self-hosted server says whether the key was there to remove.
|
|
780
|
+
if (isJsonObject(answer) && answer["removed"] === false)
|
|
781
|
+
info(`${key} was not set for project ${target.projectRef}.`);
|
|
782
|
+
else
|
|
783
|
+
info(`Removed ${key} for project ${target.projectRef}.`);
|
|
784
|
+
}
|
|
785
|
+
/** Removes `key` from the functions' local env file. */
|
|
786
|
+
function unsetLocalEnv(functionsDir, key) {
|
|
787
|
+
const envPath = resolve(functionsDir, ENV_LOCAL);
|
|
788
|
+
if (!existsSync(envPath)) {
|
|
789
|
+
error("No local env file found.");
|
|
778
790
|
process.exit(1);
|
|
779
791
|
}
|
|
792
|
+
const { text, removed } = withoutEnvValue(readFileSync(envPath, "utf8"), key);
|
|
793
|
+
if (!removed) {
|
|
794
|
+
info(`${key} was not set in the local env file.`);
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
writeFileSync(envPath, text, "utf8");
|
|
798
|
+
info(`Removed ${key} from local env file.`);
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* Where a local invoke goes: a running `functions serve` on `port` when one answers, otherwise the
|
|
802
|
+
* project's own dev API, as every other command that calls the API finds it. A fixed localhost port
|
|
803
|
+
* reached whatever else on the machine listened there.
|
|
804
|
+
*/
|
|
805
|
+
async function localFunctionsBase(cwd, port) {
|
|
806
|
+
return (await runningServeBase(port)) ?? `${resolveProjectApiUrl(cwd)}/functions/v1`;
|
|
807
|
+
}
|
|
808
|
+
/** The functions worker's answer to a bare request: a 404 listing the functions it serves. */
|
|
809
|
+
const isServeListing = isShape({ available: isArrayOf(isString) });
|
|
810
|
+
/**
|
|
811
|
+
* The base URL of the `functions serve` listening on `port`, or undefined when none answers. A bare
|
|
812
|
+
* request is how the worker is recognised: it answers 404 with the list of functions it serves,
|
|
813
|
+
* which nothing else on that port would.
|
|
814
|
+
*/
|
|
815
|
+
export async function runningServeBase(port) {
|
|
816
|
+
const base = `http://127.0.0.1:${port}/functions/v1`;
|
|
780
817
|
try {
|
|
781
|
-
const res = await
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
Authorization: `Bearer ${token}`,
|
|
785
|
-
"X-Org-Id": linked.orgId ?? "",
|
|
786
|
-
},
|
|
787
|
-
signal: AbortSignal.timeout(10_000),
|
|
788
|
-
});
|
|
789
|
-
if (!res.ok) {
|
|
790
|
-
const reason = await failureReason(res);
|
|
791
|
-
error(`Failed to unset env var: ${reason}`);
|
|
792
|
-
process.exit(1);
|
|
793
|
-
}
|
|
794
|
-
info(`Removed ${key} for project ${linked.ref}.`);
|
|
818
|
+
const res = await fetchWithin(`${base}/`, 1000);
|
|
819
|
+
const body = await res.json();
|
|
820
|
+
return isServeListing(body) ? base : undefined;
|
|
795
821
|
}
|
|
796
|
-
catch
|
|
797
|
-
|
|
798
|
-
process.exit(1);
|
|
822
|
+
catch {
|
|
823
|
+
return undefined;
|
|
799
824
|
}
|
|
800
825
|
}
|
|
801
|
-
async function loadCloudHelpers() {
|
|
802
|
-
return {
|
|
803
|
-
getLinkedProject(cwd) {
|
|
804
|
-
const link = loadProjectLink(cwd);
|
|
805
|
-
if (!link?.projectRef)
|
|
806
|
-
return null;
|
|
807
|
-
return {
|
|
808
|
-
ref: link.projectRef,
|
|
809
|
-
kind: link.kind,
|
|
810
|
-
...(link.orgId !== undefined ? { orgId: link.orgId } : {}),
|
|
811
|
-
};
|
|
812
|
-
},
|
|
813
|
-
getCloudToken(cwd) {
|
|
814
|
-
if (process.env["SUPATYPE_ACCESS_TOKEN"]) {
|
|
815
|
-
return process.env["SUPATYPE_ACCESS_TOKEN"];
|
|
816
|
-
}
|
|
817
|
-
// The link's own token, else the session `supatype login` saved. This used to read
|
|
818
|
-
// ~/.supatype/token, which nothing writes, so a fresh login still read as logged out.
|
|
819
|
-
const link = loadProjectLink(cwd);
|
|
820
|
-
return link === null ? null : resolveCloudAccessToken(link) ?? null;
|
|
821
|
-
},
|
|
822
|
-
getCloudApiUrl(cwd) {
|
|
823
|
-
const link = loadProjectLink(cwd);
|
|
824
|
-
if (link?.cloudApiUrl)
|
|
825
|
-
return link.cloudApiUrl;
|
|
826
|
-
return process.env["SUPATYPE_API_URL"] ?? "https://api.supatype.com";
|
|
827
|
-
},
|
|
828
|
-
};
|
|
829
|
-
}
|
|
830
826
|
//# sourceMappingURL=functions.js.map
|