@supatype/cli 0.1.0-alpha.9 → 0.1.1
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/.turbo/turbo-build.log +2 -2
- package/.turbo/turbo-test.log +285 -69
- package/.turbo/turbo-typecheck.log +1 -1
- package/assets/supatype-logo-wordmark.ascii.txt +6 -0
- package/bin/dev-entry.ts +2 -1
- package/dist/app/framework.js +1 -3
- package/dist/app/framework.js.map +1 -1
- package/dist/app/proxy-dev-app.d.ts +14 -0
- package/dist/app/proxy-dev-app.d.ts.map +1 -1
- package/dist/app/proxy-dev-app.js +110 -6
- package/dist/app/proxy-dev-app.js.map +1 -1
- package/dist/app-config.d.ts +10 -0
- package/dist/app-config.d.ts.map +1 -1
- package/dist/app-config.js +72 -0
- package/dist/app-config.js.map +1 -1
- package/dist/assets/supatype-logo-wordmark.ascii.txt +6 -0
- package/dist/binary-cache.d.ts +19 -7
- package/dist/binary-cache.d.ts.map +1 -1
- package/dist/binary-cache.js +92 -46
- package/dist/binary-cache.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +17 -2
- package/dist/cli.js.map +1 -1
- package/dist/commands/add.d.ts +3 -0
- package/dist/commands/add.d.ts.map +1 -0
- package/dist/commands/add.js +86 -0
- package/dist/commands/add.js.map +1 -0
- package/dist/commands/admin.d.ts +28 -1
- package/dist/commands/admin.d.ts.map +1 -1
- package/dist/commands/admin.js +297 -149
- package/dist/commands/admin.js.map +1 -1
- package/dist/commands/adopt.d.ts +3 -0
- package/dist/commands/adopt.d.ts.map +1 -0
- package/dist/commands/adopt.js +55 -0
- package/dist/commands/adopt.js.map +1 -0
- package/dist/commands/app.d.ts.map +1 -1
- package/dist/commands/app.js +20 -17
- package/dist/commands/app.js.map +1 -1
- package/dist/commands/cache.d.ts.map +1 -1
- package/dist/commands/cache.js +11 -10
- package/dist/commands/cache.js.map +1 -1
- package/dist/commands/cloud.d.ts +4 -9
- package/dist/commands/cloud.d.ts.map +1 -1
- package/dist/commands/cloud.js +75 -125
- package/dist/commands/cloud.js.map +1 -1
- package/dist/commands/db.d.ts.map +1 -1
- package/dist/commands/db.js +37 -58
- package/dist/commands/db.js.map +1 -1
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +140 -96
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +74 -39
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/diff.d.ts.map +1 -1
- package/dist/commands/diff.js +39 -39
- package/dist/commands/diff.js.map +1 -1
- package/dist/commands/doctor.d.ts +3 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +78 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/engine.d.ts.map +1 -1
- package/dist/commands/engine.js +5 -4
- package/dist/commands/engine.js.map +1 -1
- package/dist/commands/functions.d.ts.map +1 -1
- package/dist/commands/functions.js +172 -119
- package/dist/commands/functions.js.map +1 -1
- package/dist/commands/generate.d.ts.map +1 -1
- package/dist/commands/generate.js +5 -4
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/init.d.ts +35 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +883 -107
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/introspect.d.ts +3 -0
- package/dist/commands/introspect.d.ts.map +1 -0
- package/dist/commands/introspect.js +35 -0
- package/dist/commands/introspect.js.map +1 -0
- package/dist/commands/keys.d.ts +15 -1
- package/dist/commands/keys.d.ts.map +1 -1
- package/dist/commands/keys.js +46 -10
- package/dist/commands/keys.js.map +1 -1
- package/dist/commands/link-helpers.d.ts +15 -0
- package/dist/commands/link-helpers.d.ts.map +1 -0
- package/dist/commands/link-helpers.js +225 -0
- package/dist/commands/link-helpers.js.map +1 -0
- 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-from-v1.d.ts.map +1 -1
- package/dist/commands/migrate-from-v1.js +3 -2
- package/dist/commands/migrate-from-v1.js.map +1 -1
- package/dist/commands/migrate.d.ts.map +1 -1
- package/dist/commands/migrate.js +119 -26
- package/dist/commands/migrate.js.map +1 -1
- package/dist/commands/pg.d.ts.map +1 -1
- package/dist/commands/pg.js +11 -12
- package/dist/commands/pg.js.map +1 -1
- package/dist/commands/plugins.d.ts.map +1 -1
- package/dist/commands/plugins.js +55 -46
- package/dist/commands/plugins.js.map +1 -1
- package/dist/commands/pull.d.ts.map +1 -1
- package/dist/commands/pull.js +33 -5
- package/dist/commands/pull.js.map +1 -1
- package/dist/commands/push.d.ts.map +1 -1
- package/dist/commands/push.js +111 -138
- package/dist/commands/push.js.map +1 -1
- package/dist/commands/seed.d.ts.map +1 -1
- package/dist/commands/seed.js +4 -3
- package/dist/commands/seed.js.map +1 -1
- package/dist/commands/self-host.d.ts +2 -2
- package/dist/commands/self-host.d.ts.map +1 -1
- package/dist/commands/self-host.js +65 -50
- 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 +3 -2
- package/dist/commands/self-update.js.map +1 -1
- package/dist/commands/status.d.ts +1 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +95 -29
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/types.d.ts.map +1 -1
- package/dist/commands/types.js +3 -2
- package/dist/commands/types.js.map +1 -1
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +54 -21
- package/dist/commands/update.js.map +1 -1
- package/dist/compose-rename.d.ts +10 -0
- package/dist/compose-rename.d.ts.map +1 -0
- package/dist/compose-rename.js +67 -0
- package/dist/compose-rename.js.map +1 -0
- package/dist/config.d.ts +2 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/dev-compose.d.ts +26 -0
- package/dist/dev-compose.d.ts.map +1 -1
- package/dist/dev-compose.js +357 -79
- package/dist/dev-compose.js.map +1 -1
- package/dist/dev-log-bus.d.ts +30 -0
- package/dist/dev-log-bus.d.ts.map +1 -0
- package/dist/dev-log-bus.js +87 -0
- package/dist/dev-log-bus.js.map +1 -0
- package/dist/dev-log-filter.d.ts +10 -0
- package/dist/dev-log-filter.d.ts.map +1 -0
- package/dist/dev-log-filter.js +36 -0
- package/dist/dev-log-filter.js.map +1 -0
- package/dist/dev-logo.d.ts +12 -0
- package/dist/dev-logo.d.ts.map +1 -0
- package/dist/dev-logo.js +56 -0
- package/dist/dev-logo.js.map +1 -0
- package/dist/dev-ports.d.ts +27 -0
- package/dist/dev-ports.d.ts.map +1 -0
- package/dist/dev-ports.js +171 -0
- package/dist/dev-ports.js.map +1 -0
- package/dist/dev-session-lock.d.ts +25 -0
- package/dist/dev-session-lock.d.ts.map +1 -0
- package/dist/dev-session-lock.js +81 -0
- package/dist/dev-session-lock.js.map +1 -0
- package/dist/dev-session.d.ts +26 -0
- package/dist/dev-session.d.ts.map +1 -0
- package/dist/dev-session.js +106 -0
- package/dist/dev-session.js.map +1 -0
- package/dist/dev-shutdown.d.ts +25 -0
- package/dist/dev-shutdown.d.ts.map +1 -0
- package/dist/dev-shutdown.js +114 -0
- package/dist/dev-shutdown.js.map +1 -0
- package/dist/dev-task-colors.d.ts +13 -0
- package/dist/dev-task-colors.d.ts.map +1 -0
- package/dist/dev-task-colors.js +43 -0
- package/dist/dev-task-colors.js.map +1 -0
- package/dist/dev-tui.d.ts +24 -0
- package/dist/dev-tui.d.ts.map +1 -0
- package/dist/dev-tui.js +188 -0
- package/dist/dev-tui.js.map +1 -0
- package/dist/diff-output.d.ts +5 -1
- package/dist/diff-output.d.ts.map +1 -1
- package/dist/diff-output.js +69 -0
- package/dist/diff-output.js.map +1 -1
- package/dist/docker-runtime.d.ts +30 -0
- package/dist/docker-runtime.d.ts.map +1 -0
- package/dist/docker-runtime.js +118 -0
- package/dist/docker-runtime.js.map +1 -0
- package/dist/engine-client.d.ts +10 -1
- package/dist/engine-client.d.ts.map +1 -1
- package/dist/engine-client.js +76 -17
- package/dist/engine-client.js.map +1 -1
- package/dist/engine-push-output.d.ts +17 -0
- package/dist/engine-push-output.d.ts.map +1 -0
- package/dist/engine-push-output.js +64 -0
- package/dist/engine-push-output.js.map +1 -0
- package/dist/ensure-binary.js +2 -2
- package/dist/ensure-binary.js.map +1 -1
- package/dist/env-file.d.ts +5 -0
- package/dist/env-file.d.ts.map +1 -0
- package/dist/env-file.js +33 -0
- package/dist/env-file.js.map +1 -0
- package/dist/gitignore.d.ts +8 -0
- package/dist/gitignore.d.ts.map +1 -0
- package/dist/gitignore.js +41 -0
- package/dist/gitignore.js.map +1 -0
- package/dist/kong-config.d.ts +9 -0
- package/dist/kong-config.d.ts.map +1 -1
- package/dist/kong-config.js +18 -1
- package/dist/kong-config.js.map +1 -1
- package/dist/link.d.ts +66 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +160 -0
- package/dist/link.js.map +1 -0
- package/dist/process-manager.d.ts +8 -0
- package/dist/process-manager.d.ts.map +1 -1
- package/dist/process-manager.js +53 -9
- package/dist/process-manager.js.map +1 -1
- package/dist/project-config.d.ts +30 -3
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +37 -4
- package/dist/project-config.js.map +1 -1
- package/dist/prompts.d.ts +3 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +3 -0
- package/dist/prompts.js.map +1 -0
- package/dist/pull-utils.d.ts +50 -14
- package/dist/pull-utils.d.ts.map +1 -1
- package/dist/pull-utils.js +152 -12
- package/dist/pull-utils.js.map +1 -1
- package/dist/resolve-target.d.ts +86 -0
- package/dist/resolve-target.d.ts.map +1 -0
- package/dist/resolve-target.js +291 -0
- package/dist/resolve-target.js.map +1 -0
- package/dist/restore-system-relation-targets.d.ts +3 -0
- package/dist/restore-system-relation-targets.d.ts.map +1 -0
- package/dist/restore-system-relation-targets.js +45 -0
- package/dist/restore-system-relation-targets.js.map +1 -0
- package/dist/runtime-routes.d.ts.map +1 -1
- package/dist/runtime-routes.js +7 -0
- package/dist/runtime-routes.js.map +1 -1
- package/dist/schema-ast-v2.d.ts +1 -1
- package/dist/schema-ast-v2.d.ts.map +1 -1
- package/dist/schema-ast-v2.js +2 -2
- package/dist/schema-ast-v2.js.map +1 -1
- package/dist/schema-sources.d.ts +40 -0
- package/dist/schema-sources.d.ts.map +1 -0
- package/dist/schema-sources.js +183 -0
- package/dist/schema-sources.js.map +1 -0
- package/dist/scripts/postinstall.js +5 -1
- package/dist/scripts/postinstall.js.map +1 -1
- package/dist/self-host-compose.d.ts +37 -1
- package/dist/self-host-compose.d.ts.map +1 -1
- package/dist/self-host-compose.js +234 -43
- package/dist/self-host-compose.js.map +1 -1
- package/dist/storage-provision.d.ts +4 -0
- package/dist/storage-provision.d.ts.map +1 -1
- package/dist/storage-provision.js +24 -2
- package/dist/storage-provision.js.map +1 -1
- package/dist/supatype-eval-1781522769253.d.mts +2 -0
- package/dist/supatype-eval-1781522769253.d.mts.map +1 -0
- package/dist/supatype-eval-1781522769253.mjs +3 -0
- package/dist/supatype-eval-1781522769253.mjs.map +1 -0
- package/dist/systemd.js +2 -2
- package/dist/systemd.js.map +1 -1
- package/dist/target-client.d.ts +10 -0
- package/dist/target-client.d.ts.map +1 -0
- package/dist/target-client.js +22 -0
- package/dist/target-client.js.map +1 -0
- package/dist/type-extractor.d.ts +11 -0
- package/dist/type-extractor.d.ts.map +1 -1
- package/dist/type-extractor.js +95 -8
- package/dist/type-extractor.js.map +1 -1
- package/dist/ui/brand.d.ts +9 -0
- package/dist/ui/brand.d.ts.map +1 -0
- package/dist/ui/brand.js +11 -0
- package/dist/ui/brand.js.map +1 -0
- package/dist/ui/confirm.d.ts +12 -0
- package/dist/ui/confirm.d.ts.map +1 -0
- package/dist/ui/confirm.js +28 -0
- package/dist/ui/confirm.js.map +1 -0
- package/dist/ui/fatal.d.ts +10 -0
- package/dist/ui/fatal.d.ts.map +1 -0
- package/dist/ui/fatal.js +34 -0
- package/dist/ui/fatal.js.map +1 -0
- package/dist/ui/index.d.ts +9 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +9 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/interactive.d.ts +3 -0
- package/dist/ui/interactive.d.ts.map +1 -0
- package/dist/ui/interactive.js +5 -0
- package/dist/ui/interactive.js.map +1 -0
- package/dist/ui/messages.d.ts +10 -0
- package/dist/ui/messages.d.ts.map +1 -0
- package/dist/ui/messages.js +35 -0
- package/dist/ui/messages.js.map +1 -0
- package/dist/ui/next-steps.d.ts +3 -0
- package/dist/ui/next-steps.d.ts.map +1 -0
- package/dist/ui/next-steps.js +10 -0
- package/dist/ui/next-steps.js.map +1 -0
- package/dist/ui/progress.d.ts +5 -0
- package/dist/ui/progress.d.ts.map +1 -0
- package/dist/ui/progress.js +24 -0
- package/dist/ui/progress.js.map +1 -0
- package/dist/ui/prompts.d.ts +14 -0
- package/dist/ui/prompts.d.ts.map +1 -0
- package/dist/ui/prompts.js +34 -0
- package/dist/ui/prompts.js.map +1 -0
- package/package.json +5 -2
- package/src/app/framework.ts +1 -3
- package/src/app/proxy-dev-app.ts +114 -6
- package/src/app-config.ts +80 -0
- package/src/binary-cache.ts +102 -52
- package/src/cli.ts +16 -2
- package/src/commands/add.ts +97 -0
- package/src/commands/admin.ts +381 -190
- package/src/commands/adopt.ts +82 -0
- package/src/commands/app.ts +20 -17
- package/src/commands/cache.ts +11 -10
- package/src/commands/cloud.ts +91 -142
- package/src/commands/db.ts +40 -63
- package/src/commands/deploy.ts +186 -126
- package/src/commands/dev.ts +98 -55
- package/src/commands/diff.ts +52 -43
- package/src/commands/doctor.ts +103 -0
- package/src/commands/engine.ts +5 -4
- package/src/commands/functions.ts +187 -123
- package/src/commands/generate.ts +5 -4
- package/src/commands/init.ts +1087 -104
- package/src/commands/introspect.ts +48 -0
- package/src/commands/keys.ts +56 -14
- package/src/commands/link-helpers.ts +273 -0
- package/src/commands/logs.ts +5 -4
- package/src/commands/migrate-from-v1.ts +3 -2
- package/src/commands/migrate.ts +167 -27
- package/src/commands/pg.ts +13 -18
- package/src/commands/plugins.ts +55 -46
- package/src/commands/pull.ts +38 -9
- package/src/commands/push.ts +148 -175
- package/src/commands/seed.ts +5 -4
- package/src/commands/self-host.ts +85 -54
- package/src/commands/self-update.ts +3 -2
- package/src/commands/status.ts +102 -33
- package/src/commands/types.ts +3 -2
- package/src/commands/update.ts +59 -23
- package/src/compose-rename.ts +76 -0
- package/src/config.ts +2 -1
- package/src/dev-compose.ts +462 -76
- package/src/dev-log-bus.ts +101 -0
- package/src/dev-log-filter.ts +32 -0
- package/src/dev-logo.ts +61 -0
- package/src/dev-ports.ts +212 -0
- package/src/dev-session-lock.ts +101 -0
- package/src/dev-session.ts +130 -0
- package/src/dev-shutdown.ts +147 -0
- package/src/dev-task-colors.ts +47 -0
- package/src/dev-tui.ts +232 -0
- package/src/diff-output.ts +79 -1
- package/src/docker-runtime.ts +151 -0
- package/src/engine-client.ts +81 -17
- package/src/engine-push-output.ts +75 -0
- package/src/ensure-binary.ts +2 -2
- package/src/env-file.ts +37 -0
- package/src/gitignore.ts +48 -0
- package/src/kong-config.ts +24 -1
- package/src/link.ts +243 -0
- package/src/process-manager.ts +66 -10
- package/src/project-config.ts +62 -7
- package/src/prompts.ts +2 -0
- package/src/pull-utils.ts +217 -23
- package/src/resolve-target.ts +419 -0
- package/src/restore-system-relation-targets.ts +45 -0
- package/src/runtime-routes.ts +7 -0
- package/src/schema-ast-v2.ts +2 -1
- package/src/schema-sources.ts +248 -0
- package/src/scripts/postinstall.ts +7 -1
- package/src/self-host-compose.ts +262 -46
- package/src/storage-provision.ts +33 -1
- package/src/supatype-eval-1781522769253.mts +1 -0
- package/src/systemd.ts +2 -2
- package/src/target-client.ts +40 -0
- package/src/type-extractor.ts +124 -11
- package/src/ui/README.md +17 -0
- package/src/ui/brand.ts +12 -0
- package/src/ui/confirm.ts +38 -0
- package/src/ui/fatal.ts +43 -0
- package/src/ui/index.ts +8 -0
- package/src/ui/interactive.ts +4 -0
- package/src/ui/messages.ts +43 -0
- package/src/ui/next-steps.ts +10 -0
- package/src/ui/progress.ts +28 -0
- package/src/ui/prompts.ts +40 -0
- package/tests/admin-ensure.test.ts +59 -0
- package/tests/cli-help.test.ts +27 -2
- package/tests/config.test.ts +29 -2
- package/tests/dev-ports.test.ts +41 -0
- package/tests/dev-session-lock.test.ts +54 -0
- package/tests/dev-ui.test.ts +162 -0
- package/tests/docker-runtime.test.ts +236 -0
- package/tests/engine-push-output.test.ts +67 -0
- package/tests/init.test.ts +197 -18
- package/tests/link.test.ts +148 -0
- package/tests/minisign.test.ts +102 -0
- package/tests/proxy-dev-app.test.ts +45 -1
- package/tests/pull-utils.test.ts +5 -4
- package/tests/runtime-contract.test.ts +186 -2
- package/tests/schema-sources.test.ts +119 -0
- package/tests/storage-provision.test.ts +100 -0
- package/tests/ui-confirm.test.ts +41 -0
- package/tests/ui-messages.test.ts +66 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs"
|
|
2
|
+
import { resolve } from "node:path"
|
|
3
|
+
import { loadConfig } from "./config.js"
|
|
4
|
+
import type { DiffResult } from "./engine-client.js"
|
|
5
|
+
import { ensureEngine, engineRequest } from "./engine-client.js"
|
|
6
|
+
import type { SchemaSourcesPayload } from "./schema-sources.js"
|
|
7
|
+
import {
|
|
8
|
+
connectionString,
|
|
9
|
+
resolveRuntimeProvider,
|
|
10
|
+
schemaPathFromProject,
|
|
11
|
+
serverBaseUrl,
|
|
12
|
+
} from "./project-config.js"
|
|
13
|
+
import {
|
|
14
|
+
getEnvironmentTarget,
|
|
15
|
+
loadLocalEnvironment,
|
|
16
|
+
loadProjectLink,
|
|
17
|
+
resolveEnvironmentName,
|
|
18
|
+
resolveEnvironmentToken,
|
|
19
|
+
type BranchContext,
|
|
20
|
+
type LocalEnvironment,
|
|
21
|
+
type ProjectLink,
|
|
22
|
+
} from "./link.js"
|
|
23
|
+
import { targetFetch } from "./target-client.js"
|
|
24
|
+
|
|
25
|
+
export interface ResolveTargetFlags {
|
|
26
|
+
env?: string | undefined
|
|
27
|
+
direct?: boolean
|
|
28
|
+
local?: boolean
|
|
29
|
+
connection?: string | undefined
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type TargetMode = "cloud" | "self-host" | "local" | "direct"
|
|
33
|
+
|
|
34
|
+
export interface DeployTarget {
|
|
35
|
+
mode: TargetMode
|
|
36
|
+
environment: string
|
|
37
|
+
projectRef: string
|
|
38
|
+
apiBaseUrl: string
|
|
39
|
+
apiPrefix: "/api/v1" | "/platform/v1"
|
|
40
|
+
token?: string | undefined
|
|
41
|
+
orgId?: string | undefined
|
|
42
|
+
link: ProjectLink | null
|
|
43
|
+
/** Engine subprocess path when mode is direct or local without control plane. */
|
|
44
|
+
databaseUrl?: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function loadLocalEnvironmentFile(cwd: string): LocalEnvironment | null {
|
|
48
|
+
return loadLocalEnvironment(cwd)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function readServiceRoleKey(cwd: string): string | undefined {
|
|
52
|
+
return process.env["SERVICE_ROLE_KEY"] ?? process.env["SUPATYPE_SERVICE_ROLE_KEY"]
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function resolveLocalToken(cwd: string): string | undefined {
|
|
56
|
+
return readServiceRoleKey(cwd)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function loadBranchContext(cwd: string): BranchContext | null {
|
|
60
|
+
const path = resolve(cwd, ".supatype/branch.json")
|
|
61
|
+
if (!existsSync(path)) return null
|
|
62
|
+
return JSON.parse(readFileSync(path, "utf8")) as BranchContext
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function resolveBranchDefaults(cwd: string, configEnvDefault?: string): string | undefined {
|
|
66
|
+
if (configEnvDefault) return configEnvDefault
|
|
67
|
+
try {
|
|
68
|
+
const config = loadConfig(cwd)
|
|
69
|
+
const branchDefaults = config.environments?.branchDefaults
|
|
70
|
+
if (!branchDefaults) return undefined
|
|
71
|
+
const { execSync } = require("node:child_process") as typeof import("node:child_process")
|
|
72
|
+
const branch = execSync("git rev-parse --abbrev-ref HEAD", { cwd, encoding: "utf8" }).trim()
|
|
73
|
+
return branchDefaults[branch]
|
|
74
|
+
} catch {
|
|
75
|
+
return undefined
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function resolveTarget(cwd: string, flags: ResolveTargetFlags = {}): DeployTarget {
|
|
80
|
+
const config = loadConfig(cwd)
|
|
81
|
+
const projectRef = config.project?.name ?? config.project?.ref ?? "project"
|
|
82
|
+
const branchCtx = loadBranchContext(cwd)
|
|
83
|
+
|
|
84
|
+
if (branchCtx) {
|
|
85
|
+
return {
|
|
86
|
+
mode: "self-host",
|
|
87
|
+
environment: `branch:${branchCtx.branchId}`,
|
|
88
|
+
projectRef,
|
|
89
|
+
apiBaseUrl: branchCtx.apiUrl.replace(/\/$/, ""),
|
|
90
|
+
apiPrefix: "/platform/v1",
|
|
91
|
+
token: branchCtx.token,
|
|
92
|
+
link: loadProjectLink(cwd),
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (flags.direct || flags.local) {
|
|
97
|
+
const localEnv = loadLocalEnvironment(cwd)
|
|
98
|
+
return {
|
|
99
|
+
mode: "direct",
|
|
100
|
+
environment: "local",
|
|
101
|
+
projectRef,
|
|
102
|
+
apiBaseUrl: (serverBaseUrl(config) ?? "").replace(/\/$/, ""),
|
|
103
|
+
apiPrefix: "/platform/v1",
|
|
104
|
+
link: null,
|
|
105
|
+
databaseUrl:
|
|
106
|
+
flags.connection ??
|
|
107
|
+
localEnv?.databaseUrl ??
|
|
108
|
+
connectionString(config),
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const link = loadProjectLink(cwd)
|
|
113
|
+
const localEnv = loadLocalEnvironment(cwd)
|
|
114
|
+
|
|
115
|
+
if (!link) {
|
|
116
|
+
if (localEnv && resolveRuntimeProvider(config) === "docker") {
|
|
117
|
+
return {
|
|
118
|
+
mode: "local",
|
|
119
|
+
environment: "local",
|
|
120
|
+
projectRef: localEnv.projectRef,
|
|
121
|
+
apiBaseUrl: localEnv.apiUrl.replace(/\/$/, ""),
|
|
122
|
+
apiPrefix: "/platform/v1",
|
|
123
|
+
token: resolveLocalToken(cwd),
|
|
124
|
+
link: null,
|
|
125
|
+
databaseUrl: localEnv.databaseUrl,
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
mode: "direct",
|
|
130
|
+
environment: "local",
|
|
131
|
+
projectRef,
|
|
132
|
+
apiBaseUrl: (serverBaseUrl(config) ?? "").replace(/\/$/, ""),
|
|
133
|
+
apiPrefix: "/platform/v1",
|
|
134
|
+
link: null,
|
|
135
|
+
databaseUrl: flags.connection ?? connectionString(config),
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const envName = resolveEnvironmentName(
|
|
140
|
+
link,
|
|
141
|
+
flags.env ?? resolveBranchDefaults(cwd, config.environments?.default),
|
|
142
|
+
)
|
|
143
|
+
const envTarget = getEnvironmentTarget(link, envName)
|
|
144
|
+
if (!envTarget) {
|
|
145
|
+
throw new Error(
|
|
146
|
+
`Environment "${envName}" not linked. Run: supatype link --env ${envName} ... or supatype envs list`,
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const token = resolveEnvironmentToken(link, envTarget)
|
|
151
|
+
if (!token) {
|
|
152
|
+
throw new Error(`No token for environment "${envName}". Re-run supatype link --token ...`)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (link.kind === "cloud") {
|
|
156
|
+
return {
|
|
157
|
+
mode: "cloud",
|
|
158
|
+
environment: envName,
|
|
159
|
+
projectRef: link.projectRef,
|
|
160
|
+
apiBaseUrl: (link.cloudApiUrl ?? envTarget.apiUrl).replace(/\/$/, ""),
|
|
161
|
+
apiPrefix: "/api/v1",
|
|
162
|
+
token,
|
|
163
|
+
link,
|
|
164
|
+
...(link.orgId !== undefined ? { orgId: link.orgId } : {}),
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
mode: link.kind === "local" ? "local" : "self-host",
|
|
170
|
+
environment: envName,
|
|
171
|
+
projectRef: link.projectRef,
|
|
172
|
+
apiBaseUrl: envTarget.apiUrl.replace(/\/$/, ""),
|
|
173
|
+
apiPrefix: "/platform/v1",
|
|
174
|
+
token,
|
|
175
|
+
link,
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function projectPath(target: DeployTarget, subpath: string): string {
|
|
180
|
+
return `/projects/${target.projectRef}${subpath}`
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export async function targetSchemaDiff(
|
|
184
|
+
target: DeployTarget,
|
|
185
|
+
ast: unknown,
|
|
186
|
+
opts?: { schema?: string },
|
|
187
|
+
): Promise<DiffResult> {
|
|
188
|
+
if (target.mode === "direct" || (target.mode === "local" && !target.token)) {
|
|
189
|
+
await ensureEngine()
|
|
190
|
+
return engineRequest<DiffResult>("/diff", {
|
|
191
|
+
ast,
|
|
192
|
+
database_url: target.databaseUrl!,
|
|
193
|
+
schema: opts?.schema ?? "public",
|
|
194
|
+
})
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return targetFetch<DiffResult>(target.apiBaseUrl, target.apiPrefix, {
|
|
198
|
+
method: "POST",
|
|
199
|
+
path: projectPath(target, "/schema/diff"),
|
|
200
|
+
body: { ast, schema: opts?.schema ?? "public" },
|
|
201
|
+
token: target.token!,
|
|
202
|
+
orgId: target.orgId,
|
|
203
|
+
environment: target.mode === "cloud" ? target.environment : undefined,
|
|
204
|
+
})
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export async function targetSchemaPush(
|
|
208
|
+
target: DeployTarget,
|
|
209
|
+
ast: unknown,
|
|
210
|
+
opts?: { force?: boolean; schema?: string; schemaSources?: SchemaSourcesPayload | null },
|
|
211
|
+
): Promise<{ message?: string; status?: string; name?: string }> {
|
|
212
|
+
if (target.mode === "direct" || (target.mode === "local" && !target.token)) {
|
|
213
|
+
await ensureEngine()
|
|
214
|
+
const body: Record<string, unknown> = {
|
|
215
|
+
ast,
|
|
216
|
+
database_url: target.databaseUrl!,
|
|
217
|
+
schema: opts?.schema ?? "public",
|
|
218
|
+
force: opts?.force ?? true,
|
|
219
|
+
}
|
|
220
|
+
if (opts?.schemaSources) {
|
|
221
|
+
body["schema_sources_gz_base64"] = opts.schemaSources.dataBase64
|
|
222
|
+
body["schema_sources_manifest"] = opts.schemaSources.manifest
|
|
223
|
+
}
|
|
224
|
+
return engineRequest("/push", body)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const pushBody: Record<string, unknown> = {
|
|
228
|
+
ast,
|
|
229
|
+
force: opts?.force ?? true,
|
|
230
|
+
schema: opts?.schema ?? "public",
|
|
231
|
+
}
|
|
232
|
+
if (opts?.schemaSources) {
|
|
233
|
+
pushBody["schemaSources"] = {
|
|
234
|
+
manifest: opts.schemaSources.manifest,
|
|
235
|
+
dataBase64: opts.schemaSources.dataBase64,
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return targetFetch(target.apiBaseUrl, target.apiPrefix, {
|
|
240
|
+
method: "POST",
|
|
241
|
+
path: projectPath(target, "/schema/push"),
|
|
242
|
+
body: pushBody,
|
|
243
|
+
token: target.token!,
|
|
244
|
+
orgId: target.orgId,
|
|
245
|
+
environment: target.mode === "cloud" ? target.environment : undefined,
|
|
246
|
+
})
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export interface SchemaRollbackResult {
|
|
250
|
+
status: string
|
|
251
|
+
name: string
|
|
252
|
+
message: string
|
|
253
|
+
restoredMigrationName?: string
|
|
254
|
+
schemaSourcesManifest?: SchemaSourcesManifestSummary
|
|
255
|
+
schemaSourcesBase64?: string
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export interface SchemaSourcesManifestSummary {
|
|
259
|
+
entryPoint?: string
|
|
260
|
+
fileCount?: number
|
|
261
|
+
compressedBytes?: number
|
|
262
|
+
pushedBy?: string
|
|
263
|
+
files?: Array<{ path: string }>
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export interface MigrationListEntry {
|
|
267
|
+
id: number
|
|
268
|
+
name: string
|
|
269
|
+
hash: string
|
|
270
|
+
appliedAt: string
|
|
271
|
+
rolledBack: boolean
|
|
272
|
+
engineVersion: string
|
|
273
|
+
status: string
|
|
274
|
+
schemaSourcesManifest?: SchemaSourcesManifestSummary | null
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export async function targetSchemaRollback(
|
|
278
|
+
target: DeployTarget,
|
|
279
|
+
opts?: { schema?: string },
|
|
280
|
+
): Promise<SchemaRollbackResult> {
|
|
281
|
+
if (target.mode === "direct" || (target.mode === "local" && !target.token)) {
|
|
282
|
+
await ensureEngine()
|
|
283
|
+
return engineRequest<SchemaRollbackResult>("/rollback", {
|
|
284
|
+
database_url: target.databaseUrl!,
|
|
285
|
+
schema: opts?.schema ?? "public",
|
|
286
|
+
})
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return targetFetch<SchemaRollbackResult>(target.apiBaseUrl, target.apiPrefix, {
|
|
290
|
+
method: "POST",
|
|
291
|
+
path: projectPath(target, "/schema/rollback"),
|
|
292
|
+
body: { schema: opts?.schema ?? "public" },
|
|
293
|
+
token: target.token!,
|
|
294
|
+
orgId: target.orgId,
|
|
295
|
+
environment: target.mode === "cloud" ? target.environment : undefined,
|
|
296
|
+
})
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export async function targetListMigrations(
|
|
300
|
+
target: DeployTarget,
|
|
301
|
+
): Promise<MigrationListEntry[]> {
|
|
302
|
+
if (target.mode === "direct" || (target.mode === "local" && !target.token)) {
|
|
303
|
+
await ensureEngine()
|
|
304
|
+
const result = await engineRequest<{ migrations?: MigrationListEntry[] } | MigrationListEntry[]>(
|
|
305
|
+
"/migrations",
|
|
306
|
+
{ database_url: target.databaseUrl!, action: "list" },
|
|
307
|
+
)
|
|
308
|
+
return Array.isArray(result) ? result : (result.migrations ?? [])
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return targetFetch<MigrationListEntry[]>(target.apiBaseUrl, target.apiPrefix, {
|
|
312
|
+
method: "GET",
|
|
313
|
+
path: projectPath(target, "/schema/migrations"),
|
|
314
|
+
token: target.token!,
|
|
315
|
+
orgId: target.orgId,
|
|
316
|
+
environment: target.mode === "cloud" ? target.environment : undefined,
|
|
317
|
+
})
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export async function targetSchemaDoctor(
|
|
321
|
+
target: DeployTarget,
|
|
322
|
+
ast: unknown,
|
|
323
|
+
opts?: { noCache?: boolean | undefined; schema?: string },
|
|
324
|
+
): Promise<unknown> {
|
|
325
|
+
if (target.mode === "direct" || (target.mode === "local" && !target.token)) {
|
|
326
|
+
await ensureEngine()
|
|
327
|
+
return engineRequest("/doctor", {
|
|
328
|
+
ast,
|
|
329
|
+
database_url: target.databaseUrl!,
|
|
330
|
+
schema: opts?.schema ?? "public",
|
|
331
|
+
no_cache: opts?.noCache ?? false,
|
|
332
|
+
})
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return targetFetch(target.apiBaseUrl, target.apiPrefix, {
|
|
336
|
+
method: "POST",
|
|
337
|
+
path: projectPath(target, "/schema/doctor"),
|
|
338
|
+
body: { ast, no_cache: opts?.noCache ?? false, schema: opts?.schema ?? "public" },
|
|
339
|
+
token: target.token!,
|
|
340
|
+
orgId: target.orgId,
|
|
341
|
+
environment: target.mode === "cloud" ? target.environment : undefined,
|
|
342
|
+
})
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export async function targetSchemaIntrospect(
|
|
346
|
+
target: DeployTarget,
|
|
347
|
+
opts?: { schema?: string },
|
|
348
|
+
): Promise<unknown> {
|
|
349
|
+
if (target.mode === "direct" || (target.mode === "local" && !target.token)) {
|
|
350
|
+
await ensureEngine()
|
|
351
|
+
return engineRequest("/introspect", {
|
|
352
|
+
database_url: target.databaseUrl!,
|
|
353
|
+
schema: opts?.schema ?? "public",
|
|
354
|
+
})
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
return targetFetch(target.apiBaseUrl, target.apiPrefix, {
|
|
358
|
+
method: "POST",
|
|
359
|
+
path: projectPath(target, "/schema/introspect"),
|
|
360
|
+
body: { schema: opts?.schema ?? "public" },
|
|
361
|
+
token: target.token!,
|
|
362
|
+
orgId: target.orgId,
|
|
363
|
+
environment: target.mode === "cloud" ? target.environment : undefined,
|
|
364
|
+
})
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
export async function targetSchemaAdopt(
|
|
368
|
+
target: DeployTarget,
|
|
369
|
+
ast: unknown,
|
|
370
|
+
opts?: { names?: string[]; schema?: string; yes?: boolean; noCache?: boolean },
|
|
371
|
+
): Promise<unknown> {
|
|
372
|
+
if (target.mode === "direct" || (target.mode === "local" && !target.token)) {
|
|
373
|
+
await ensureEngine()
|
|
374
|
+
return engineRequest("/adopt", {
|
|
375
|
+
ast,
|
|
376
|
+
database_url: target.databaseUrl!,
|
|
377
|
+
schema: opts?.schema ?? "public",
|
|
378
|
+
names: opts?.names,
|
|
379
|
+
yes: opts?.yes ?? false,
|
|
380
|
+
no_cache: opts?.noCache ?? false,
|
|
381
|
+
})
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
return targetFetch(target.apiBaseUrl, target.apiPrefix, {
|
|
385
|
+
method: "POST",
|
|
386
|
+
path: projectPath(target, "/schema/adopt"),
|
|
387
|
+
body: {
|
|
388
|
+
ast,
|
|
389
|
+
schema: opts?.schema ?? "public",
|
|
390
|
+
yes: opts?.yes ?? false,
|
|
391
|
+
no_cache: opts?.noCache ?? false,
|
|
392
|
+
...(opts?.names !== undefined ? { names: opts.names } : {}),
|
|
393
|
+
},
|
|
394
|
+
token: target.token!,
|
|
395
|
+
orgId: target.orgId,
|
|
396
|
+
environment: target.mode === "cloud" ? target.environment : undefined,
|
|
397
|
+
})
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export async function targetStatus(target: DeployTarget): Promise<unknown> {
|
|
401
|
+
if (target.mode === "direct") {
|
|
402
|
+
return { mode: "direct", environment: target.environment }
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
return targetFetch(target.apiBaseUrl, target.apiPrefix, {
|
|
406
|
+
method: "GET",
|
|
407
|
+
path: projectPath(target, "/status"),
|
|
408
|
+
token: target.token!,
|
|
409
|
+
orgId: target.orgId,
|
|
410
|
+
environment: target.mode === "cloud" ? target.environment : undefined,
|
|
411
|
+
})
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
export function schemaPgSchema(cwd: string): string {
|
|
415
|
+
const config = loadConfig(cwd)
|
|
416
|
+
return config.schema?.pg_schema ?? "public"
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
export { schemaPathFromProject }
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** Restore system relation targets (e.g. supatype:user) in engine-generated admin config. */
|
|
2
|
+
|
|
3
|
+
function fieldNameToForeignKey(fieldName: string): string {
|
|
4
|
+
return fieldName
|
|
5
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2")
|
|
6
|
+
.replace(/([a-z\d])([A-Z])/g, "$1_$2")
|
|
7
|
+
.toLowerCase() + "_id"
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function restoreSystemRelationTargets(admin: unknown, ast: unknown): void {
|
|
11
|
+
if (typeof admin !== "object" || admin === null || typeof ast !== "object" || ast === null) return
|
|
12
|
+
const astObj = ast as { models?: Array<{ name: string; fields?: Record<string, { kind: string; target?: string }> }> }
|
|
13
|
+
if (!astObj.models) return
|
|
14
|
+
const cfg = admin as {
|
|
15
|
+
models?: Array<{
|
|
16
|
+
tableName: string
|
|
17
|
+
fields: Array<{ name: string; widget: string; options?: Record<string, unknown> }>
|
|
18
|
+
}>
|
|
19
|
+
}
|
|
20
|
+
if (!Array.isArray(cfg.models)) return
|
|
21
|
+
|
|
22
|
+
const systemTargets = new Map<string, Map<string, string>>()
|
|
23
|
+
for (const model of astObj.models) {
|
|
24
|
+
if (!model.fields) continue
|
|
25
|
+
for (const [fieldName, field] of Object.entries(model.fields)) {
|
|
26
|
+
if (field.kind === "relation" && field.target?.includes(":")) {
|
|
27
|
+
const key = model.name.toLowerCase()
|
|
28
|
+
if (!systemTargets.has(key)) systemTargets.set(key, new Map())
|
|
29
|
+
systemTargets.get(key)!.set(fieldNameToForeignKey(fieldName), field.target)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
for (const model of cfg.models) {
|
|
35
|
+
const modelTargets = systemTargets.get(model.tableName)
|
|
36
|
+
if (!modelTargets) continue
|
|
37
|
+
for (const field of model.fields) {
|
|
38
|
+
if (field.widget !== "relation" || !field.options) continue
|
|
39
|
+
const explicitFk = (field.options["foreignKey"] as string) ?? ""
|
|
40
|
+
const fk = explicitFk || fieldNameToForeignKey(field.name)
|
|
41
|
+
const systemTarget = modelTargets.get(fk)
|
|
42
|
+
if (systemTarget) field.options["target"] = systemTarget
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/runtime-routes.ts
CHANGED
|
@@ -92,6 +92,13 @@ function runtimeRouteSpecUnified(opts: RuntimeRouteOptions): RuntimeRoute[] {
|
|
|
92
92
|
paths: ["/functions/v1/"],
|
|
93
93
|
stripPath: false,
|
|
94
94
|
},
|
|
95
|
+
{
|
|
96
|
+
name: "platform-v1",
|
|
97
|
+
serviceName: "supatype-server-platform",
|
|
98
|
+
serviceUrl: SERVER_GATEWAY,
|
|
99
|
+
paths: ["/platform/v1/"],
|
|
100
|
+
stripPath: false,
|
|
101
|
+
},
|
|
95
102
|
{
|
|
96
103
|
name: "graphql-v1",
|
|
97
104
|
serviceName: "postgrest-graphql",
|
package/src/schema-ast-v2.ts
CHANGED
|
@@ -293,13 +293,14 @@ export function emitModel(
|
|
|
293
293
|
options: Record<string, unknown>,
|
|
294
294
|
tableName: string,
|
|
295
295
|
access: Record<string, unknown>,
|
|
296
|
+
indexes: unknown[] = [],
|
|
296
297
|
): ModelAstV2 {
|
|
297
298
|
return {
|
|
298
299
|
name,
|
|
299
300
|
fields,
|
|
300
301
|
options,
|
|
301
302
|
annotations: {
|
|
302
|
-
db: { tableName, indexes
|
|
303
|
+
db: { tableName, indexes },
|
|
303
304
|
platform: { access },
|
|
304
305
|
},
|
|
305
306
|
}
|