@supatype/cli 0.1.0-alpha.10
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 +4 -0
- package/.turbo/turbo-test.log +221 -0
- package/.turbo/turbo-typecheck.log +4 -0
- package/assets/supatype-logo-wordmark.ascii.txt +6 -0
- package/bin/dev-entry.ts +2 -0
- package/bin/supatype.js +5 -0
- package/dist/app/framework.d.ts +44 -0
- package/dist/app/framework.d.ts.map +1 -0
- package/dist/app/framework.js +200 -0
- package/dist/app/framework.js.map +1 -0
- package/dist/app/proxy-dev-app.d.ts +13 -0
- package/dist/app/proxy-dev-app.d.ts.map +1 -0
- package/dist/app/proxy-dev-app.js +54 -0
- package/dist/app/proxy-dev-app.js.map +1 -0
- package/dist/app-config.d.ts +7 -0
- package/dist/app-config.d.ts.map +1 -0
- package/dist/app-config.js +113 -0
- package/dist/app-config.js.map +1 -0
- package/dist/assets/supatype-logo-wordmark.ascii.txt +6 -0
- package/dist/augmentation-generator.d.ts +2 -0
- package/dist/augmentation-generator.d.ts.map +1 -0
- package/dist/augmentation-generator.js +111 -0
- package/dist/augmentation-generator.js.map +1 -0
- package/dist/binary-cache.d.ts +98 -0
- package/dist/binary-cache.d.ts.map +1 -0
- package/dist/binary-cache.js +687 -0
- package/dist/binary-cache.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +61 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/admin.d.ts +4 -0
- package/dist/commands/admin.d.ts.map +1 -0
- package/dist/commands/admin.js +271 -0
- package/dist/commands/admin.js.map +1 -0
- package/dist/commands/app.d.ts +3 -0
- package/dist/commands/app.d.ts.map +1 -0
- package/dist/commands/app.js +82 -0
- package/dist/commands/app.js.map +1 -0
- package/dist/commands/cache.d.ts +6 -0
- package/dist/commands/cache.d.ts.map +1 -0
- package/dist/commands/cache.js +105 -0
- package/dist/commands/cache.js.map +1 -0
- package/dist/commands/cloud.d.ts +23 -0
- package/dist/commands/cloud.d.ts.map +1 -0
- package/dist/commands/cloud.js +254 -0
- package/dist/commands/cloud.js.map +1 -0
- package/dist/commands/db.d.ts +8 -0
- package/dist/commands/db.d.ts.map +1 -0
- package/dist/commands/db.js +116 -0
- package/dist/commands/db.js.map +1 -0
- package/dist/commands/deploy-types.d.ts +14 -0
- package/dist/commands/deploy-types.d.ts.map +1 -0
- package/dist/commands/deploy-types.js +38 -0
- package/dist/commands/deploy-types.js.map +1 -0
- package/dist/commands/deploy.d.ts +15 -0
- package/dist/commands/deploy.d.ts.map +1 -0
- package/dist/commands/deploy.js +322 -0
- package/dist/commands/deploy.js.map +1 -0
- package/dist/commands/dev.d.ts +14 -0
- package/dist/commands/dev.d.ts.map +1 -0
- package/dist/commands/dev.js +806 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/diff.d.ts +3 -0
- package/dist/commands/diff.d.ts.map +1 -0
- package/dist/commands/diff.js +54 -0
- package/dist/commands/diff.js.map +1 -0
- package/dist/commands/engine.d.ts +7 -0
- package/dist/commands/engine.d.ts.map +1 -0
- package/dist/commands/engine.js +27 -0
- package/dist/commands/engine.js.map +1 -0
- package/dist/commands/functions.d.ts +3 -0
- package/dist/commands/functions.d.ts.map +1 -0
- package/dist/commands/functions.js +749 -0
- package/dist/commands/functions.js.map +1 -0
- package/dist/commands/generate.d.ts +3 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/generate.js +38 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/init.d.ts +7 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +228 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/keys.d.ts +4 -0
- package/dist/commands/keys.d.ts.map +1 -0
- package/dist/commands/keys.js +57 -0
- package/dist/commands/keys.js.map +1 -0
- package/dist/commands/logs.d.ts +6 -0
- package/dist/commands/logs.d.ts.map +1 -0
- package/dist/commands/logs.js +52 -0
- package/dist/commands/logs.js.map +1 -0
- package/dist/commands/migrate-from-v1.d.ts +5 -0
- package/dist/commands/migrate-from-v1.d.ts.map +1 -0
- package/dist/commands/migrate-from-v1.js +125 -0
- package/dist/commands/migrate-from-v1.js.map +1 -0
- package/dist/commands/migrate.d.ts +3 -0
- package/dist/commands/migrate.d.ts.map +1 -0
- package/dist/commands/migrate.js +75 -0
- package/dist/commands/migrate.js.map +1 -0
- package/dist/commands/pg.d.ts +8 -0
- package/dist/commands/pg.d.ts.map +1 -0
- package/dist/commands/pg.js +102 -0
- package/dist/commands/pg.js.map +1 -0
- package/dist/commands/plugins.d.ts +3 -0
- package/dist/commands/plugins.d.ts.map +1 -0
- package/dist/commands/plugins.js +431 -0
- package/dist/commands/plugins.js.map +1 -0
- package/dist/commands/pull.d.ts +3 -0
- package/dist/commands/pull.d.ts.map +1 -0
- package/dist/commands/pull.js +12 -0
- package/dist/commands/pull.js.map +1 -0
- package/dist/commands/push.d.ts +3 -0
- package/dist/commands/push.d.ts.map +1 -0
- package/dist/commands/push.js +179 -0
- package/dist/commands/push.js.map +1 -0
- package/dist/commands/seed.d.ts +5 -0
- package/dist/commands/seed.d.ts.map +1 -0
- package/dist/commands/seed.js +55 -0
- package/dist/commands/seed.js.map +1 -0
- package/dist/commands/self-host.d.ts +9 -0
- package/dist/commands/self-host.d.ts.map +1 -0
- package/dist/commands/self-host.js +310 -0
- package/dist/commands/self-host.js.map +1 -0
- package/dist/commands/self-update.d.ts +9 -0
- package/dist/commands/self-update.d.ts.map +1 -0
- package/dist/commands/self-update.js +33 -0
- package/dist/commands/self-update.js.map +1 -0
- package/dist/commands/status.d.ts +6 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +70 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/types.d.ts +3 -0
- package/dist/commands/types.d.ts.map +1 -0
- package/dist/commands/types.js +62 -0
- package/dist/commands/types.js.map +1 -0
- package/dist/commands/update.d.ts +7 -0
- package/dist/commands/update.d.ts.map +1 -0
- package/dist/commands/update.js +118 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/components.d.ts +5 -0
- package/dist/components.d.ts.map +1 -0
- package/dist/components.js +3 -0
- package/dist/components.js.map +1 -0
- package/dist/config.d.ts +65 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +134 -0
- package/dist/config.js.map +1 -0
- package/dist/dev-compose.d.ts +19 -0
- package/dist/dev-compose.d.ts.map +1 -0
- package/dist/dev-compose.js +468 -0
- package/dist/dev-compose.js.map +1 -0
- 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 +57 -0
- package/dist/dev-logo.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 +9 -0
- package/dist/dev-shutdown.d.ts.map +1 -0
- package/dist/dev-shutdown.js +50 -0
- package/dist/dev-shutdown.js.map +1 -0
- package/dist/dev-task-colors.d.ts +14 -0
- package/dist/dev-task-colors.d.ts.map +1 -0
- package/dist/dev-task-colors.js +44 -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 +4 -0
- package/dist/diff-output.d.ts.map +1 -0
- package/dist/diff-output.js +12 -0
- package/dist/diff-output.js.map +1 -0
- package/dist/docker-postgres.d.ts +57 -0
- package/dist/docker-postgres.d.ts.map +1 -0
- package/dist/docker-postgres.js +208 -0
- package/dist/docker-postgres.js.map +1 -0
- package/dist/engine-client.d.ts +69 -0
- package/dist/engine-client.d.ts.map +1 -0
- package/dist/engine-client.js +157 -0
- package/dist/engine-client.js.map +1 -0
- package/dist/engine-push-output.d.ts +16 -0
- package/dist/engine-push-output.d.ts.map +1 -0
- package/dist/engine-push-output.js +61 -0
- package/dist/engine-push-output.js.map +1 -0
- package/dist/ensure-binary.d.ts +7 -0
- package/dist/ensure-binary.d.ts.map +1 -0
- package/dist/ensure-binary.js +17 -0
- package/dist/ensure-binary.js.map +1 -0
- package/dist/functions-router-gen.d.ts +14 -0
- package/dist/functions-router-gen.d.ts.map +1 -0
- package/dist/functions-router-gen.js +199 -0
- package/dist/functions-router-gen.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/jwt.d.ts +3 -0
- package/dist/jwt.d.ts.map +1 -0
- package/dist/jwt.js +13 -0
- package/dist/jwt.js.map +1 -0
- package/dist/kong-config.d.ts +25 -0
- package/dist/kong-config.d.ts.map +1 -0
- package/dist/kong-config.js +71 -0
- package/dist/kong-config.js.map +1 -0
- package/dist/local-gateway.d.ts +7 -0
- package/dist/local-gateway.d.ts.map +1 -0
- package/dist/local-gateway.js +9 -0
- package/dist/local-gateway.js.map +1 -0
- package/dist/local-storage.d.ts +8 -0
- package/dist/local-storage.d.ts.map +1 -0
- package/dist/local-storage.js +14 -0
- package/dist/local-storage.js.map +1 -0
- package/dist/pgbouncer-userlist.d.ts +5 -0
- package/dist/pgbouncer-userlist.d.ts.map +1 -0
- package/dist/pgbouncer-userlist.js +14 -0
- package/dist/pgbouncer-userlist.js.map +1 -0
- package/dist/postgres-ctl.d.ts +44 -0
- package/dist/postgres-ctl.d.ts.map +1 -0
- package/dist/postgres-ctl.js +137 -0
- package/dist/postgres-ctl.js.map +1 -0
- package/dist/process-manager.d.ts +49 -0
- package/dist/process-manager.d.ts.map +1 -0
- package/dist/process-manager.js +177 -0
- package/dist/process-manager.js.map +1 -0
- package/dist/project-config.d.ts +238 -0
- package/dist/project-config.d.ts.map +1 -0
- package/dist/project-config.js +159 -0
- package/dist/project-config.js.map +1 -0
- package/dist/pull-utils.d.ts +31 -0
- package/dist/pull-utils.d.ts.map +1 -0
- package/dist/pull-utils.js +77 -0
- package/dist/pull-utils.js.map +1 -0
- package/dist/release-pins.d.ts +7 -0
- package/dist/release-pins.d.ts.map +1 -0
- package/dist/release-pins.js +27 -0
- package/dist/release-pins.js.map +1 -0
- package/dist/release-public-key.d.ts +8 -0
- package/dist/release-public-key.d.ts.map +1 -0
- package/dist/release-public-key.js +13 -0
- package/dist/release-public-key.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 +34 -0
- package/dist/runtime-routes.d.ts.map +1 -0
- package/dist/runtime-routes.js +252 -0
- package/dist/runtime-routes.js.map +1 -0
- package/dist/schema-ast-v2.d.ts +127 -0
- package/dist/schema-ast-v2.d.ts.map +1 -0
- package/dist/schema-ast-v2.js +226 -0
- package/dist/schema-ast-v2.js.map +1 -0
- package/dist/scripts/postinstall.d.ts +11 -0
- package/dist/scripts/postinstall.d.ts.map +1 -0
- package/dist/scripts/postinstall.js +47 -0
- package/dist/scripts/postinstall.js.map +1 -0
- package/dist/seed.d.ts +8 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +32 -0
- package/dist/seed.js.map +1 -0
- package/dist/self-host-compose.d.ts +43 -0
- package/dist/self-host-compose.d.ts.map +1 -0
- package/dist/self-host-compose.js +400 -0
- package/dist/self-host-compose.js.map +1 -0
- package/dist/storage-provision.d.ts +24 -0
- package/dist/storage-provision.d.ts.map +1 -0
- package/dist/storage-provision.js +44 -0
- package/dist/storage-provision.js.map +1 -0
- package/dist/studio-admin-roles.d.ts +7 -0
- package/dist/studio-admin-roles.d.ts.map +1 -0
- package/dist/studio-admin-roles.js +14 -0
- package/dist/studio-admin-roles.js.map +1 -0
- package/dist/studio-dev-server.d.ts +22 -0
- package/dist/studio-dev-server.d.ts.map +1 -0
- package/dist/studio-dev-server.js +28 -0
- package/dist/studio-dev-server.js.map +1 -0
- 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.d.ts +26 -0
- package/dist/systemd.d.ts.map +1 -0
- package/dist/systemd.js +102 -0
- package/dist/systemd.js.map +1 -0
- package/dist/tsx-runner.d.ts +18 -0
- package/dist/tsx-runner.d.ts.map +1 -0
- package/dist/tsx-runner.js +69 -0
- package/dist/tsx-runner.js.map +1 -0
- package/dist/type-extractor.d.ts +4 -0
- package/dist/type-extractor.d.ts.map +1 -0
- package/dist/type-extractor.js +1213 -0
- package/dist/type-extractor.js.map +1 -0
- package/dist/type-resolver.d.ts +33 -0
- package/dist/type-resolver.d.ts.map +1 -0
- package/dist/type-resolver.js +338 -0
- package/dist/type-resolver.js.map +1 -0
- package/package.json +41 -0
- package/releases/deno/VERSION +1 -0
- package/scripts/mirror-deno-release.sh +76 -0
- package/src/TYPE-RESOLUTION.md +294 -0
- package/src/app/framework.ts +249 -0
- package/src/app/proxy-dev-app.ts +68 -0
- package/src/app-config.ts +128 -0
- package/src/augmentation-generator.ts +126 -0
- package/src/binary-cache.ts +845 -0
- package/src/cli.ts +63 -0
- package/src/commands/admin.ts +372 -0
- package/src/commands/app.ts +97 -0
- package/src/commands/cache.ts +117 -0
- package/src/commands/cloud.ts +325 -0
- package/src/commands/db.ts +136 -0
- package/src/commands/deploy-types.ts +49 -0
- package/src/commands/deploy.ts +400 -0
- package/src/commands/dev.ts +1009 -0
- package/src/commands/diff.ts +63 -0
- package/src/commands/engine.ts +30 -0
- package/src/commands/functions.ts +901 -0
- package/src/commands/generate.ts +44 -0
- package/src/commands/init.ts +253 -0
- package/src/commands/keys.ts +66 -0
- package/src/commands/logs.ts +58 -0
- package/src/commands/migrate-from-v1.ts +131 -0
- package/src/commands/migrate.ts +87 -0
- package/src/commands/pg.ts +133 -0
- package/src/commands/plugins.ts +508 -0
- package/src/commands/pull.ts +17 -0
- package/src/commands/push.ts +226 -0
- package/src/commands/seed.ts +68 -0
- package/src/commands/self-host.ts +364 -0
- package/src/commands/self-update.ts +45 -0
- package/src/commands/status.ts +84 -0
- package/src/commands/types.ts +76 -0
- package/src/commands/update.ts +136 -0
- package/src/components.ts +6 -0
- package/src/config.ts +223 -0
- package/src/dev-compose.ts +583 -0
- package/src/dev-log-bus.ts +101 -0
- package/src/dev-log-filter.ts +32 -0
- package/src/dev-logo.ts +62 -0
- package/src/dev-session.ts +130 -0
- package/src/dev-shutdown.ts +54 -0
- package/src/dev-task-colors.ts +47 -0
- package/src/dev-tui.ts +232 -0
- package/src/diff-output.ts +12 -0
- package/src/docker-postgres.ts +295 -0
- package/src/engine-client.ts +236 -0
- package/src/engine-push-output.ts +71 -0
- package/src/ensure-binary.ts +28 -0
- package/src/functions-router-gen.ts +224 -0
- package/src/index.ts +11 -0
- package/src/jwt.ts +14 -0
- package/src/kong-config.ts +93 -0
- package/src/local-gateway.ts +9 -0
- package/src/local-storage.ts +14 -0
- package/src/pgbouncer-userlist.ts +15 -0
- package/src/postgres-ctl.ts +171 -0
- package/src/process-manager.ts +220 -0
- package/src/project-config.ts +388 -0
- package/src/pull-utils.ts +81 -0
- package/src/release-pins.ts +31 -0
- package/src/release-public-key.ts +12 -0
- package/src/restore-system-relation-targets.ts +45 -0
- package/src/runtime-routes.ts +291 -0
- package/src/schema-ast-v2.ts +324 -0
- package/src/scripts/postinstall.ts +51 -0
- package/src/seed.ts +43 -0
- package/src/self-host-compose.ts +452 -0
- package/src/storage-provision.ts +58 -0
- package/src/studio-admin-roles.ts +16 -0
- package/src/studio-dev-server.ts +53 -0
- package/src/supatype-eval-1781522769253.mts +1 -0
- package/src/systemd.ts +137 -0
- package/src/tsx-runner.ts +89 -0
- package/src/type-extractor.ts +1479 -0
- package/src/type-resolver.ts +457 -0
- package/tests/app-command.test.ts +54 -0
- package/tests/augmentation-generator.test.ts +59 -0
- package/tests/binary-cache-cloud-overrides.test.ts +123 -0
- package/tests/cached-artifact-format.test.ts +84 -0
- package/tests/cli-help.test.ts +133 -0
- package/tests/config.test.ts +252 -0
- package/tests/dev-ui.test.ts +139 -0
- package/tests/docker-postgres.test.ts +39 -0
- package/tests/engine-distribution.test.ts +418 -0
- package/tests/engine-push-output.test.ts +67 -0
- package/tests/ensure-binary.test.ts +59 -0
- package/tests/init.test.ts +127 -0
- package/tests/keys.test.ts +160 -0
- package/tests/migrate-from-v1.test.ts +29 -0
- package/tests/normalize-admin-config.test.ts +48 -0
- package/tests/pg-spawn-env.test.ts +18 -0
- package/tests/postgres-archive-tag.test.ts +9 -0
- package/tests/proxy-dev-app.test.ts +33 -0
- package/tests/pull-utils.test.ts +150 -0
- package/tests/release-pins.test.ts +28 -0
- package/tests/runtime-contract.test.ts +370 -0
- package/tests/seed-discover.test.ts +31 -0
- package/tests/studio-admin-roles.test.ts +27 -0
- package/tests/tsconfig.json +9 -0
- package/tests/tsx-runner.test.ts +66 -0
- package/tests/type-extractor.test.ts +985 -0
- package/tests/type-resolver.test.ts +59 -0
- package/tsconfig.json +10 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/vitest.config.ts +12 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for `supatype keys` — JWT generation command.
|
|
3
|
+
* Uses subprocess tests (requires built dist/) for the CLI integration,
|
|
4
|
+
* plus direct module tests for the signing logic.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect } from "vitest"
|
|
7
|
+
import { spawnSync } from "node:child_process"
|
|
8
|
+
import { resolve, dirname } from "node:path"
|
|
9
|
+
import { fileURLToPath } from "node:url"
|
|
10
|
+
import { mkdtempSync, writeFileSync, rmSync } from "node:fs"
|
|
11
|
+
import { tmpdir } from "node:os"
|
|
12
|
+
import { join } from "node:path"
|
|
13
|
+
|
|
14
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
15
|
+
const CLI_BIN = resolve(__dirname, "../bin/supatype.js")
|
|
16
|
+
|
|
17
|
+
function runCli(
|
|
18
|
+
args: string[],
|
|
19
|
+
opts: { cwd?: string; env?: NodeJS.ProcessEnv } = {},
|
|
20
|
+
): { stdout: string; stderr: string; exitCode: number } {
|
|
21
|
+
const result = spawnSync(process.execPath, [CLI_BIN, ...args], {
|
|
22
|
+
encoding: "utf8",
|
|
23
|
+
timeout: 10_000,
|
|
24
|
+
cwd: opts.cwd,
|
|
25
|
+
env: { ...process.env, ...opts.env },
|
|
26
|
+
})
|
|
27
|
+
return {
|
|
28
|
+
stdout: String(result.stdout ?? ""),
|
|
29
|
+
stderr: String(result.stderr ?? ""),
|
|
30
|
+
exitCode: result.status ?? 1,
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
|
35
|
+
|
|
36
|
+
function decodeJwtPart(part: string): Record<string, unknown> {
|
|
37
|
+
return JSON.parse(Buffer.from(part, "base64url").toString("utf8")) as Record<string, unknown>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function parseJwt(token: string): { header: Record<string, unknown>; payload: Record<string, unknown> } {
|
|
41
|
+
const parts = token.split(".")
|
|
42
|
+
expect(parts).toHaveLength(3)
|
|
43
|
+
return {
|
|
44
|
+
header: decodeJwtPart(parts[0]!),
|
|
45
|
+
payload: decodeJwtPart(parts[1]!),
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// ─── Tests ────────────────────────────────────────────────────────────────────
|
|
50
|
+
|
|
51
|
+
describe("supatype keys (CLI subprocess)", () => {
|
|
52
|
+
const SECRET = "my-test-jwt-secret-that-is-32-chars!"
|
|
53
|
+
|
|
54
|
+
it("exits 0 with --secret", () => {
|
|
55
|
+
const { exitCode } = runCli(["keys", "--secret", SECRET])
|
|
56
|
+
expect(exitCode).toBe(0)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it("outputs ANON_KEY= line", () => {
|
|
60
|
+
const { stdout } = runCli(["keys", "--secret", SECRET])
|
|
61
|
+
expect(stdout).toContain("ANON_KEY=")
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it("outputs SERVICE_ROLE_KEY= line", () => {
|
|
65
|
+
const { stdout } = runCli(["keys", "--secret", SECRET])
|
|
66
|
+
expect(stdout).toContain("SERVICE_ROLE_KEY=")
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it("ANON_KEY is a valid three-part JWT", () => {
|
|
70
|
+
const { stdout } = runCli(["keys", "--secret", SECRET])
|
|
71
|
+
const line = stdout.split("\n").find((l) => l.startsWith("ANON_KEY="))!
|
|
72
|
+
const token = line.replace("ANON_KEY=", "").trim()
|
|
73
|
+
const { header, payload } = parseJwt(token)
|
|
74
|
+
expect(header["alg"]).toBe("HS256")
|
|
75
|
+
expect(header["typ"]).toBe("JWT")
|
|
76
|
+
expect(payload["role"]).toBe("anon")
|
|
77
|
+
expect(payload["iss"]).toBe("supatype")
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it("SERVICE_ROLE_KEY payload has role: service_role", () => {
|
|
81
|
+
const { stdout } = runCli(["keys", "--secret", SECRET])
|
|
82
|
+
const line = stdout.split("\n").find((l) => l.startsWith("SERVICE_ROLE_KEY="))!
|
|
83
|
+
const token = line.replace("SERVICE_ROLE_KEY=", "").trim()
|
|
84
|
+
const { payload } = parseJwt(token)
|
|
85
|
+
expect(payload["role"]).toBe("service_role")
|
|
86
|
+
expect(payload["iss"]).toBe("supatype")
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it("JWT has exp in the future", () => {
|
|
90
|
+
const { stdout } = runCli(["keys", "--secret", SECRET])
|
|
91
|
+
const line = stdout.split("\n").find((l) => l.startsWith("ANON_KEY="))!
|
|
92
|
+
const token = line.replace("ANON_KEY=", "").trim()
|
|
93
|
+
const { payload } = parseJwt(token)
|
|
94
|
+
const exp = payload["exp"] as number
|
|
95
|
+
expect(exp).toBeGreaterThan(Math.floor(Date.now() / 1000))
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it("--exp-years changes the expiry window", () => {
|
|
99
|
+
const short = runCli(["keys", "--secret", SECRET, "--exp-years", "1"])
|
|
100
|
+
const long = runCli(["keys", "--secret", SECRET, "--exp-years", "50"])
|
|
101
|
+
|
|
102
|
+
const getExp = (stdout: string): number => {
|
|
103
|
+
const line = stdout.split("\n").find((l) => l.startsWith("ANON_KEY="))!
|
|
104
|
+
const token = line.replace("ANON_KEY=", "").trim()
|
|
105
|
+
return (parseJwt(token).payload["exp"]) as number
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
expect(getExp(long.stdout)).toBeGreaterThan(getExp(short.stdout))
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it("reads JWT_SECRET from environment variable", () => {
|
|
112
|
+
const tmpDir = mkdtempSync(join(tmpdir(), "st-keys-env-"))
|
|
113
|
+
try {
|
|
114
|
+
const { exitCode, stdout } = runCli(["keys"], {
|
|
115
|
+
cwd: tmpDir,
|
|
116
|
+
env: { JWT_SECRET: SECRET },
|
|
117
|
+
})
|
|
118
|
+
expect(exitCode).toBe(0)
|
|
119
|
+
expect(stdout).toContain("ANON_KEY=")
|
|
120
|
+
} finally {
|
|
121
|
+
rmSync(tmpDir, { recursive: true, force: true })
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
it("reads JWT_SECRET from .env file", () => {
|
|
126
|
+
const tmpDir = mkdtempSync(join(tmpdir(), "st-keys-env-"))
|
|
127
|
+
try {
|
|
128
|
+
writeFileSync(join(tmpDir, ".env"), `JWT_SECRET=${SECRET}\n`, "utf8")
|
|
129
|
+
const { exitCode, stdout } = runCli(["keys"], {
|
|
130
|
+
cwd: tmpDir,
|
|
131
|
+
env: { JWT_SECRET: undefined as unknown as string },
|
|
132
|
+
})
|
|
133
|
+
expect(exitCode).toBe(0)
|
|
134
|
+
expect(stdout).toContain("ANON_KEY=")
|
|
135
|
+
} finally {
|
|
136
|
+
rmSync(tmpDir, { recursive: true, force: true })
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
it("exits non-zero when no secret is available", () => {
|
|
141
|
+
const tmpDir = mkdtempSync(join(tmpdir(), "st-keys-nosecret-"))
|
|
142
|
+
try {
|
|
143
|
+
const { exitCode, stderr } = runCli(["keys"], {
|
|
144
|
+
cwd: tmpDir,
|
|
145
|
+
env: { JWT_SECRET: undefined as unknown as string },
|
|
146
|
+
})
|
|
147
|
+
expect(exitCode).not.toBe(0)
|
|
148
|
+
expect(stderr).toContain("JWT_SECRET")
|
|
149
|
+
} finally {
|
|
150
|
+
rmSync(tmpDir, { recursive: true, force: true })
|
|
151
|
+
}
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
it("keys --help shows --secret and --exp-years options", () => {
|
|
155
|
+
const { stdout, exitCode } = runCli(["keys", "--help"])
|
|
156
|
+
expect(exitCode).toBe(0)
|
|
157
|
+
expect(stdout).toContain("--secret")
|
|
158
|
+
expect(stdout).toContain("--exp-years")
|
|
159
|
+
})
|
|
160
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import ts from "typescript"
|
|
2
|
+
import { describe, expect, it } from "vitest"
|
|
3
|
+
import { codemodSource } from "../src/commands/migrate-from-v1.js"
|
|
4
|
+
|
|
5
|
+
describe("migrate-from-v1 codemod", () => {
|
|
6
|
+
it("converts exported model() declarations into Model<> aliases", () => {
|
|
7
|
+
const source = ts.createSourceFile(
|
|
8
|
+
"schema.ts",
|
|
9
|
+
`
|
|
10
|
+
import { model, field } from "@supatype/schema"
|
|
11
|
+
export const User = model("user", {
|
|
12
|
+
fields: {
|
|
13
|
+
id: field.uuid({ required: true }),
|
|
14
|
+
email: field.email({ required: true, unique: true }),
|
|
15
|
+
name: field.text({ required: true }),
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
`,
|
|
19
|
+
ts.ScriptTarget.Latest,
|
|
20
|
+
true,
|
|
21
|
+
ts.ScriptKind.TS,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
const out = codemodSource(source)
|
|
25
|
+
expect(out).toContain("export type User = Model<")
|
|
26
|
+
expect(out).toContain("id: UUID")
|
|
27
|
+
expect(out).toContain("email: string")
|
|
28
|
+
})
|
|
29
|
+
})
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest"
|
|
2
|
+
import { normalizeAdminConfig } from "../../studio/src/lib/normalize-admin-config.js"
|
|
3
|
+
|
|
4
|
+
describe("normalizeAdminConfig", () => {
|
|
5
|
+
it("maps global fields and Settings navigation items", () => {
|
|
6
|
+
const config = normalizeAdminConfig({
|
|
7
|
+
localization: { locales: ["en"], defaultLocale: "en" },
|
|
8
|
+
navigation: [
|
|
9
|
+
{
|
|
10
|
+
group: "Content",
|
|
11
|
+
items: [{ label: "Post", model: "posts" }],
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
group: "Settings",
|
|
15
|
+
items: [{ label: "Site Settings", global: "_global_site_settings" }],
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
models: [
|
|
19
|
+
{
|
|
20
|
+
name: "Post",
|
|
21
|
+
tableName: "posts",
|
|
22
|
+
fields: [{ name: "title", widget: "text", required: true }],
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
globals: [
|
|
26
|
+
{
|
|
27
|
+
name: "SiteSettings",
|
|
28
|
+
tableName: "_global_site_settings",
|
|
29
|
+
singleton: true,
|
|
30
|
+
fields: [{ name: "site_name", widget: "text", required: true }],
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
expect(config.globals).toHaveLength(1)
|
|
36
|
+
expect(config.globals[0]?.tableName).toBe("_global_site_settings")
|
|
37
|
+
expect(config.globals[0]?.apiPath).toBe("/rest/v1/_global_site_settings")
|
|
38
|
+
expect(config.globals[0]?.fields).toHaveLength(1)
|
|
39
|
+
expect(config.globals[0]?.fields[0]?.name).toBe("site_name")
|
|
40
|
+
|
|
41
|
+
const settingsNav = config.navigation.find((g) => g.label === "Settings")
|
|
42
|
+
expect(settingsNav?.items[0]).toMatchObject({
|
|
43
|
+
type: "global",
|
|
44
|
+
href: "/models/globals/SiteSettings",
|
|
45
|
+
label: "Site Settings",
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest"
|
|
2
|
+
import { join } from "node:path"
|
|
3
|
+
import { pgSpawnEnv } from "../src/postgres-ctl.js"
|
|
4
|
+
|
|
5
|
+
const PG_BIN = "/cache/postgres/17.2/pg-17.2/bin"
|
|
6
|
+
const PG_LIB = join("/cache/postgres/17.2/pg-17.2", "lib")
|
|
7
|
+
|
|
8
|
+
describe("pgSpawnEnv", () => {
|
|
9
|
+
it("prepends lib dir to DYLD_LIBRARY_PATH on darwin", () => {
|
|
10
|
+
const env = pgSpawnEnv(PG_BIN, "darwin")
|
|
11
|
+
expect(env.DYLD_LIBRARY_PATH).toContain(PG_LIB)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it("prepends lib dir to LD_LIBRARY_PATH on linux", () => {
|
|
15
|
+
const env = pgSpawnEnv(PG_BIN, "linux")
|
|
16
|
+
expect(env.LD_LIBRARY_PATH).toContain(PG_LIB)
|
|
17
|
+
})
|
|
18
|
+
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest"
|
|
2
|
+
import { postgresArchiveTag } from "../src/binary-cache.js"
|
|
3
|
+
|
|
4
|
+
describe("postgresArchiveTag", () => {
|
|
5
|
+
it("uses PG major only for CDN archive basenames", () => {
|
|
6
|
+
expect(postgresArchiveTag("17.2")).toBe("17")
|
|
7
|
+
expect(postgresArchiveTag("17")).toBe("17")
|
|
8
|
+
})
|
|
9
|
+
})
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest"
|
|
2
|
+
import { resolveProxyDevScript } from "../src/app/proxy-dev-app.js"
|
|
3
|
+
import type { SupatypeProjectConfig } from "../src/project-config.js"
|
|
4
|
+
|
|
5
|
+
const base = {
|
|
6
|
+
project: { name: "test" },
|
|
7
|
+
database: { provider: "native" as const },
|
|
8
|
+
server: { mode: "dev" as const },
|
|
9
|
+
versions: { engine: "latest", server: "latest", postgres: "latest", deno: "latest" },
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
describe("resolveProxyDevScript()", () => {
|
|
13
|
+
it("returns null when app.mode is not proxy", () => {
|
|
14
|
+
const config = { ...base, app: { mode: "static" as const } } satisfies SupatypeProjectConfig
|
|
15
|
+
expect(resolveProxyDevScript(config)).toBeNull()
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it("defaults to start when proxy mode and app.start omitted", () => {
|
|
19
|
+
const config = {
|
|
20
|
+
...base,
|
|
21
|
+
app: { mode: "proxy" as const, upstream: "http://127.0.0.1:4321" },
|
|
22
|
+
} satisfies SupatypeProjectConfig
|
|
23
|
+
expect(resolveProxyDevScript(config)).toBe("start")
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it("uses app.start when set", () => {
|
|
27
|
+
const config = {
|
|
28
|
+
...base,
|
|
29
|
+
app: { mode: "proxy" as const, upstream: "http://127.0.0.1:4321", start: "dev:site" },
|
|
30
|
+
} satisfies SupatypeProjectConfig
|
|
31
|
+
expect(resolveProxyDevScript(config)).toBe("dev:site")
|
|
32
|
+
})
|
|
33
|
+
})
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest"
|
|
2
|
+
import {
|
|
3
|
+
introspectColumnToColumnInfo,
|
|
4
|
+
pgTypeToField,
|
|
5
|
+
toCamelCase,
|
|
6
|
+
type ColumnInfo,
|
|
7
|
+
} from "../src/pull-utils.js"
|
|
8
|
+
|
|
9
|
+
function col(overrides: Partial<ColumnInfo> & { pgType: string }): ColumnInfo {
|
|
10
|
+
return {
|
|
11
|
+
name: "col",
|
|
12
|
+
nullable: true,
|
|
13
|
+
isPrimary: false,
|
|
14
|
+
isUnique: false,
|
|
15
|
+
hasDefault: false,
|
|
16
|
+
...overrides,
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe("pgTypeToField()", () => {
|
|
21
|
+
it.each([
|
|
22
|
+
["uuid", "field.uuid("],
|
|
23
|
+
["text", "field.text("],
|
|
24
|
+
["varchar(255)", "field.text("],
|
|
25
|
+
["character varying", "field.text("],
|
|
26
|
+
["int4", "field.integer("],
|
|
27
|
+
["integer", "field.integer("],
|
|
28
|
+
["int8", "field.bigInt("],
|
|
29
|
+
["bigint", "field.bigInt("],
|
|
30
|
+
["int2", "field.smallInt("],
|
|
31
|
+
["smallint", "field.smallInt("],
|
|
32
|
+
["float8", "field.float("],
|
|
33
|
+
["double precision", "field.float("],
|
|
34
|
+
["real", "field.float("],
|
|
35
|
+
["numeric", "field.decimal("],
|
|
36
|
+
["decimal", "field.decimal("],
|
|
37
|
+
["bool", "field.boolean("],
|
|
38
|
+
["boolean", "field.boolean("],
|
|
39
|
+
["date", "field.date("],
|
|
40
|
+
["timestamp", "field.timestamp("],
|
|
41
|
+
["timestamptz", "field.datetime("],
|
|
42
|
+
["timestamp with time zone", "field.datetime("],
|
|
43
|
+
["json", "field.json("],
|
|
44
|
+
["jsonb", "field.json("],
|
|
45
|
+
["inet", "field.ip("],
|
|
46
|
+
["cidr", "field.cidr("],
|
|
47
|
+
["macaddr", "field.macaddr("],
|
|
48
|
+
["bytea", "field.bytea("],
|
|
49
|
+
["money", "field.money("],
|
|
50
|
+
["xml", "field.xml("],
|
|
51
|
+
["interval", "field.interval("],
|
|
52
|
+
["tsvector", "field.tsvector("],
|
|
53
|
+
["tsquery", "field.tsquery("],
|
|
54
|
+
])("maps %s → %s call", (pgType, expectedPrefix) => {
|
|
55
|
+
const result = pgTypeToField(col({ pgType }))
|
|
56
|
+
expect(result).toContain(expectedPrefix)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it("unknown types fall back to field.text with a TODO comment", () => {
|
|
60
|
+
const result = pgTypeToField(col({ pgType: "some_custom_type" }))
|
|
61
|
+
expect(result).toContain("field.text(")
|
|
62
|
+
expect(result).toContain("TODO")
|
|
63
|
+
expect(result).toContain("some_custom_type")
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it("nullable column sets required: false", () => {
|
|
67
|
+
const result = pgTypeToField(col({ pgType: "text", nullable: true }))
|
|
68
|
+
expect(result).toContain('"required":false')
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it("non-nullable column sets required: true", () => {
|
|
72
|
+
const result = pgTypeToField(col({ pgType: "text", nullable: false }))
|
|
73
|
+
expect(result).toContain('"required":true')
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it("primary key column sets primaryKey: true", () => {
|
|
77
|
+
const result = pgTypeToField(
|
|
78
|
+
col({ pgType: "uuid", isPrimary: true, nullable: false }),
|
|
79
|
+
)
|
|
80
|
+
expect(result).toContain('"primaryKey":true')
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it("unique (non-PK) column sets unique: true", () => {
|
|
84
|
+
const result = pgTypeToField(
|
|
85
|
+
col({ pgType: "text", isUnique: true, isPrimary: false }),
|
|
86
|
+
)
|
|
87
|
+
expect(result).toContain('"unique":true')
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it("primary key column does not also set unique (redundant)", () => {
|
|
91
|
+
const result = pgTypeToField(
|
|
92
|
+
col({ pgType: "uuid", isPrimary: true, isUnique: true }),
|
|
93
|
+
)
|
|
94
|
+
expect(result).not.toContain('"unique"')
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it("jsonb column includes jsonb: true spread", () => {
|
|
98
|
+
const result = pgTypeToField(col({ pgType: "jsonb" }))
|
|
99
|
+
expect(result).toContain("jsonb: true")
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it("plain json column does not include jsonb spread", () => {
|
|
103
|
+
const result = pgTypeToField(col({ pgType: "json" }))
|
|
104
|
+
expect(result).not.toContain("jsonb")
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
describe("introspectColumnToColumnInfo()", () => {
|
|
109
|
+
it("maps engine type → pgType and flags", () => {
|
|
110
|
+
const out = introspectColumnToColumnInfo({
|
|
111
|
+
name: "id",
|
|
112
|
+
type: "uuid",
|
|
113
|
+
nullable: false,
|
|
114
|
+
primaryKey: true,
|
|
115
|
+
default: "gen_random_uuid()",
|
|
116
|
+
})
|
|
117
|
+
expect(out).toEqual({
|
|
118
|
+
name: "id",
|
|
119
|
+
pgType: "uuid",
|
|
120
|
+
nullable: false,
|
|
121
|
+
isPrimary: true,
|
|
122
|
+
isUnique: false,
|
|
123
|
+
hasDefault: true,
|
|
124
|
+
})
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
it("treats empty default as no default", () => {
|
|
128
|
+
const out = introspectColumnToColumnInfo({
|
|
129
|
+
name: "x",
|
|
130
|
+
type: "text",
|
|
131
|
+
nullable: true,
|
|
132
|
+
default: "",
|
|
133
|
+
})
|
|
134
|
+
expect(out.hasDefault).toBe(false)
|
|
135
|
+
})
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
describe("toCamelCase()", () => {
|
|
139
|
+
it.each([
|
|
140
|
+
["user", "User"],
|
|
141
|
+
["blog_post", "BlogPost"],
|
|
142
|
+
["order_line_item", "OrderLineItem"],
|
|
143
|
+
["saas_tenant", "SaasTenant"],
|
|
144
|
+
["alreadyCamel", "AlreadyCamel"],
|
|
145
|
+
["a", "A"],
|
|
146
|
+
["api_key", "ApiKey"],
|
|
147
|
+
])("converts %s → %s", (input, expected) => {
|
|
148
|
+
expect(toCamelCase(input)).toBe(expected)
|
|
149
|
+
})
|
|
150
|
+
})
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs"
|
|
2
|
+
import { join, resolve } from "node:path"
|
|
3
|
+
import { describe, expect, it } from "vitest"
|
|
4
|
+
import { DENO_RELEASE_PIN } from "../src/release-pins.js"
|
|
5
|
+
|
|
6
|
+
const CLI_ROOT = resolve(import.meta.dirname, "..")
|
|
7
|
+
const REPO_ROOT = resolve(CLI_ROOT, "../..")
|
|
8
|
+
|
|
9
|
+
const EXAMPLE_CONFIGS = [
|
|
10
|
+
"examples/blog/supatype.config.ts",
|
|
11
|
+
"examples/self-host/supatype.config.ts",
|
|
12
|
+
"tests/integration/supatype.config.ts",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
describe("release-pins", () => {
|
|
16
|
+
it("DENO_RELEASE_PIN matches releases/deno/VERSION", () => {
|
|
17
|
+
const file = join(CLI_ROOT, "releases", "deno", "VERSION")
|
|
18
|
+
expect(DENO_RELEASE_PIN).toBe(readFileSync(file, "utf8").trim())
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it("example configs use the same deno pin", () => {
|
|
22
|
+
const needle = `deno: "${DENO_RELEASE_PIN}"`
|
|
23
|
+
for (const rel of EXAMPLE_CONFIGS) {
|
|
24
|
+
const content = readFileSync(join(REPO_ROOT, rel), "utf8")
|
|
25
|
+
expect(content, rel).toContain(needle)
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
})
|