@supatype/cli 0.1.0-alpha.6
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 +7 -0
- package/.turbo/turbo-typecheck.log +4 -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/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +55 -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 +270 -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 +235 -0
- package/dist/commands/app.js.map +1 -0
- package/dist/commands/cloud.d.ts +3 -0
- package/dist/commands/cloud.d.ts.map +1 -0
- package/dist/commands/cloud.js +256 -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 +123 -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 +14 -0
- package/dist/commands/deploy.d.ts.map +1 -0
- package/dist/commands/deploy.js +295 -0
- package/dist/commands/deploy.js.map +1 -0
- package/dist/commands/dev.d.ts +3 -0
- package/dist/commands/dev.d.ts.map +1 -0
- package/dist/commands/dev.js +428 -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 +39 -0
- package/dist/commands/diff.js.map +1 -0
- package/dist/commands/engine.d.ts +9 -0
- package/dist/commands/engine.d.ts.map +1 -0
- package/dist/commands/engine.js +99 -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 +762 -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 +28 -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 +515 -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.d.ts +3 -0
- package/dist/commands/migrate.d.ts.map +1 -0
- package/dist/commands/migrate.js +71 -0
- package/dist/commands/migrate.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 +73 -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 +87 -0
- package/dist/commands/push.js.map +1 -0
- package/dist/commands/seed.d.ts +3 -0
- package/dist/commands/seed.d.ts.map +1 -0
- package/dist/commands/seed.js +22 -0
- package/dist/commands/seed.js.map +1 -0
- package/dist/commands/self-host.d.ts +3 -0
- package/dist/commands/self-host.d.ts.map +1 -0
- package/dist/commands/self-host.js +796 -0
- package/dist/commands/self-host.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 +69 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/config.d.ts +106 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +66 -0
- package/dist/config.js.map +1 -0
- package/dist/engine/cache.d.ts +37 -0
- package/dist/engine/cache.d.ts.map +1 -0
- package/dist/engine/cache.js +121 -0
- package/dist/engine/cache.js.map +1 -0
- package/dist/engine/download.d.ts +19 -0
- package/dist/engine/download.d.ts.map +1 -0
- package/dist/engine/download.js +108 -0
- package/dist/engine/download.js.map +1 -0
- package/dist/engine/platform.d.ts +24 -0
- package/dist/engine/platform.d.ts.map +1 -0
- package/dist/engine/platform.js +50 -0
- package/dist/engine/platform.js.map +1 -0
- package/dist/engine/resolve.d.ts +37 -0
- package/dist/engine/resolve.d.ts.map +1 -0
- package/dist/engine/resolve.js +133 -0
- package/dist/engine/resolve.js.map +1 -0
- package/dist/engine/update-notify.d.ts +11 -0
- package/dist/engine/update-notify.d.ts.map +1 -0
- package/dist/engine/update-notify.js +43 -0
- package/dist/engine/update-notify.js.map +1 -0
- package/dist/engine/verify.d.ts +50 -0
- package/dist/engine/verify.d.ts.map +1 -0
- package/dist/engine/verify.js +161 -0
- package/dist/engine/verify.js.map +1 -0
- package/dist/engine-version.d.ts +35 -0
- package/dist/engine-version.d.ts.map +1 -0
- package/dist/engine-version.js +35 -0
- package/dist/engine-version.js.map +1 -0
- package/dist/engine.d.ts +34 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +76 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -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/pull-utils.d.ts +16 -0
- package/dist/pull-utils.d.ts.map +1 -0
- package/dist/pull-utils.js +65 -0
- package/dist/pull-utils.js.map +1 -0
- package/dist/scripts/postinstall.d.ts +12 -0
- package/dist/scripts/postinstall.d.ts.map +1 -0
- package/dist/scripts/postinstall.js +31 -0
- package/dist/scripts/postinstall.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 +62 -0
- package/dist/tsx-runner.js.map +1 -0
- package/package.json +36 -0
- package/src/app/framework.ts +249 -0
- package/src/cli.ts +58 -0
- package/src/commands/admin.ts +371 -0
- package/src/commands/app.ts +261 -0
- package/src/commands/cloud.ts +326 -0
- package/src/commands/db.ts +145 -0
- package/src/commands/deploy-types.ts +49 -0
- package/src/commands/deploy.ts +366 -0
- package/src/commands/dev.ts +477 -0
- package/src/commands/diff.ts +61 -0
- package/src/commands/engine.ts +133 -0
- package/src/commands/functions.ts +919 -0
- package/src/commands/generate.ts +31 -0
- package/src/commands/init.ts +532 -0
- package/src/commands/keys.ts +66 -0
- package/src/commands/logs.ts +58 -0
- package/src/commands/migrate.ts +83 -0
- package/src/commands/plugins.ts +508 -0
- package/src/commands/pull.ts +96 -0
- package/src/commands/push.ts +119 -0
- package/src/commands/seed.ts +26 -0
- package/src/commands/self-host.ts +932 -0
- package/src/commands/status.ts +83 -0
- package/src/config.ts +190 -0
- package/src/engine/cache.ts +135 -0
- package/src/engine/download.ts +143 -0
- package/src/engine/platform.ts +66 -0
- package/src/engine/resolve.ts +197 -0
- package/src/engine/update-notify.ts +50 -0
- package/src/engine/verify.ts +206 -0
- package/src/engine-version.ts +39 -0
- package/src/engine.ts +99 -0
- package/src/index.ts +19 -0
- package/src/jwt.ts +14 -0
- package/src/pull-utils.ts +57 -0
- package/src/scripts/postinstall.ts +40 -0
- package/src/tsx-runner.ts +79 -0
- package/tests/cli-help.test.ts +107 -0
- package/tests/config.test.ts +117 -0
- package/tests/engine-distribution.test.ts +418 -0
- package/tests/init.test.ts +184 -0
- package/tests/keys.test.ts +160 -0
- package/tests/pull-utils.test.ts +115 -0
- package/tests/tsx-runner.test.ts +66 -0
- package/tsconfig.json +10 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Postinstall script — downloads the correct engine binary for the current
|
|
3
|
+
* platform and caches it at ~/.supatype/engine/{version}/supatype-engine[.exe].
|
|
4
|
+
*
|
|
5
|
+
* Pattern: same as Prisma, esbuild, SWC, Turbo.
|
|
6
|
+
*
|
|
7
|
+
* The binary is verified via:
|
|
8
|
+
* 1. Minisign signature on checksums.sha256 (proves checksum file is authentic)
|
|
9
|
+
* 2. SHA256 checksum of binary (proves binary matches signed checksum)
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { ENGINE_VERSION } from "../engine-version.js"
|
|
13
|
+
import { detectPlatform } from "../engine/platform.js"
|
|
14
|
+
import { hasCachedBinary } from "../engine/cache.js"
|
|
15
|
+
import { resolveEngine } from "../engine/resolve.js"
|
|
16
|
+
|
|
17
|
+
async function main(): Promise<void> {
|
|
18
|
+
const platform = detectPlatform()
|
|
19
|
+
|
|
20
|
+
// Skip if already cached at the right version
|
|
21
|
+
if (hasCachedBinary(ENGINE_VERSION, platform)) {
|
|
22
|
+
console.log(`[supatype] Engine v${ENGINE_VERSION} already cached.`)
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
console.log(
|
|
27
|
+
`[supatype] Downloading engine v${ENGINE_VERSION} for ${platform.os}-${platform.arch}...`,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
const result = await resolveEngine(ENGINE_VERSION)
|
|
31
|
+
console.log(`[supatype] Engine installed at ${result.binaryPath}`)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
main().catch((err) => {
|
|
35
|
+
console.error("[supatype] Engine download failed:", err.message)
|
|
36
|
+
console.error(
|
|
37
|
+
"[supatype] You can still use the CLI — the engine will be downloaded on first use.",
|
|
38
|
+
)
|
|
39
|
+
// Don't exit(1) — let npm install succeed even if binary download fails.
|
|
40
|
+
})
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locates the tsx binary shipped with this package and provides a helper
|
|
3
|
+
* to run TypeScript files at runtime.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { spawnSync, type SpawnSyncOptions } from "node:child_process"
|
|
7
|
+
import { existsSync, readFileSync } from "node:fs"
|
|
8
|
+
import { resolve, dirname } from "node:path"
|
|
9
|
+
import { createRequire } from "node:module"
|
|
10
|
+
import { writeFileSync, unlinkSync } from "node:fs"
|
|
11
|
+
import { tmpdir } from "node:os"
|
|
12
|
+
|
|
13
|
+
const _require = createRequire(import.meta.url)
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Resolve the absolute path to the tsx CLI entry point.
|
|
17
|
+
* tsx is a direct dependency so this will always succeed after `npm install`.
|
|
18
|
+
*/
|
|
19
|
+
function findTsxBin(): string {
|
|
20
|
+
try {
|
|
21
|
+
const pkgPath = _require.resolve("tsx/package.json")
|
|
22
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8")) as {
|
|
23
|
+
bin?: string | Record<string, string>
|
|
24
|
+
}
|
|
25
|
+
const binRelative =
|
|
26
|
+
typeof pkg.bin === "string"
|
|
27
|
+
? pkg.bin
|
|
28
|
+
: (pkg.bin?.["tsx"] ?? "./dist/cli.mjs")
|
|
29
|
+
return resolve(dirname(pkgPath), binRelative)
|
|
30
|
+
} catch {
|
|
31
|
+
return "tsx" // last-resort: hope it's on PATH
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const TSX_BIN = findTsxBin()
|
|
36
|
+
|
|
37
|
+
export interface RunResult {
|
|
38
|
+
stdout: string
|
|
39
|
+
stderr: string
|
|
40
|
+
exitCode: number
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Run a TypeScript file with tsx and capture output. */
|
|
44
|
+
export function runTsFile(
|
|
45
|
+
filePath: string,
|
|
46
|
+
opts: SpawnSyncOptions = {},
|
|
47
|
+
): RunResult {
|
|
48
|
+
const result = spawnSync(process.execPath, [TSX_BIN, filePath], {
|
|
49
|
+
encoding: "utf8",
|
|
50
|
+
maxBuffer: 50 * 1024 * 1024,
|
|
51
|
+
...opts,
|
|
52
|
+
})
|
|
53
|
+
return {
|
|
54
|
+
stdout: String(result.stdout ?? ""),
|
|
55
|
+
stderr: String(result.stderr ?? ""),
|
|
56
|
+
exitCode: result.status ?? 1,
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Evaluate an ESM TypeScript snippet via tsx and return its stdout.
|
|
62
|
+
* The snippet should write JSON to process.stdout.
|
|
63
|
+
*/
|
|
64
|
+
export function evalTsSnippet(
|
|
65
|
+
snippet: string,
|
|
66
|
+
opts: SpawnSyncOptions = {},
|
|
67
|
+
): RunResult {
|
|
68
|
+
const tmpFile = resolve(tmpdir(), `supatype-eval-${Date.now()}.mts`)
|
|
69
|
+
writeFileSync(tmpFile, snippet, "utf8")
|
|
70
|
+
try {
|
|
71
|
+
return runTsFile(tmpFile, opts)
|
|
72
|
+
} finally {
|
|
73
|
+
try {
|
|
74
|
+
unlinkSync(tmpFile)
|
|
75
|
+
} catch {
|
|
76
|
+
// ignore cleanup errors
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subprocess tests — spawn the compiled CLI binary and verify commands are
|
|
3
|
+
* registered. Requires `pnpm build` to have run first (turbo handles this).
|
|
4
|
+
*/
|
|
5
|
+
import { describe, it, expect } from "vitest"
|
|
6
|
+
import { spawnSync } from "node:child_process"
|
|
7
|
+
import { resolve, dirname } from "node:path"
|
|
8
|
+
import { fileURLToPath } from "node:url"
|
|
9
|
+
|
|
10
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
11
|
+
const CLI_BIN = resolve(__dirname, "../bin/supatype.js")
|
|
12
|
+
const DIST_CLI = resolve(__dirname, "../dist/cli.js")
|
|
13
|
+
|
|
14
|
+
function runCli(args: string[]): { stdout: string; stderr: string; exitCode: number } {
|
|
15
|
+
const result = spawnSync(process.execPath, [CLI_BIN, ...args], {
|
|
16
|
+
encoding: "utf8",
|
|
17
|
+
timeout: 10_000,
|
|
18
|
+
})
|
|
19
|
+
return {
|
|
20
|
+
stdout: String(result.stdout ?? ""),
|
|
21
|
+
stderr: String(result.stderr ?? ""),
|
|
22
|
+
exitCode: result.status ?? 1,
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe("CLI binary (requires built dist/)", () => {
|
|
27
|
+
it("--help lists all top-level commands", () => {
|
|
28
|
+
const { stdout, exitCode } = runCli(["--help"])
|
|
29
|
+
expect(exitCode).toBe(0)
|
|
30
|
+
const commands = ["init", "dev", "push", "diff", "pull", "generate", "migrate", "rollback", "reset", "seed", "keys", "app", "self-host"]
|
|
31
|
+
for (const cmd of commands) {
|
|
32
|
+
expect(stdout, `Expected '${cmd}' in --help output`).toContain(cmd)
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it("--version prints a semver string", () => {
|
|
37
|
+
const { stdout, exitCode } = runCli(["--version"])
|
|
38
|
+
expect(exitCode).toBe(0)
|
|
39
|
+
expect(stdout.trim()).toMatch(/^\d+\.\d+\.\d+/)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it("init --help describes the init command", () => {
|
|
43
|
+
const { stdout, exitCode } = runCli(["init", "--help"])
|
|
44
|
+
expect(exitCode).toBe(0)
|
|
45
|
+
expect(stdout).toContain("Scaffold")
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it("push --help describes the push command and --yes flag", () => {
|
|
49
|
+
const { stdout, exitCode } = runCli(["push", "--help"])
|
|
50
|
+
expect(exitCode).toBe(0)
|
|
51
|
+
expect(stdout).toContain("--yes")
|
|
52
|
+
expect(stdout).toContain("--connection")
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it("diff --help describes the diff command", () => {
|
|
56
|
+
const { stdout, exitCode } = runCli(["diff", "--help"])
|
|
57
|
+
expect(exitCode).toBe(0)
|
|
58
|
+
expect(stdout).toContain("dry run")
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it("pull --help shows --output option", () => {
|
|
62
|
+
const { stdout, exitCode } = runCli(["pull", "--help"])
|
|
63
|
+
expect(exitCode).toBe(0)
|
|
64
|
+
expect(stdout).toContain("--output")
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it("reset --help shows --yes flag", () => {
|
|
68
|
+
const { stdout, exitCode } = runCli(["reset", "--help"])
|
|
69
|
+
expect(exitCode).toBe(0)
|
|
70
|
+
expect(stdout).toContain("--yes")
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it("app --help describes the app command with add/remove subcommands", () => {
|
|
74
|
+
const { stdout, exitCode } = runCli(["app", "--help"])
|
|
75
|
+
expect(exitCode).toBe(0)
|
|
76
|
+
expect(stdout).toContain("add")
|
|
77
|
+
expect(stdout).toContain("remove")
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it("app add --help shows --dockerfile and --port options", () => {
|
|
81
|
+
const { stdout, exitCode } = runCli(["app", "add", "--help"])
|
|
82
|
+
expect(exitCode).toBe(0)
|
|
83
|
+
expect(stdout).toContain("--dockerfile")
|
|
84
|
+
expect(stdout).toContain("--port")
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it("self-host --help describes the self-host command", () => {
|
|
88
|
+
const { stdout, exitCode } = runCli(["self-host", "--help"])
|
|
89
|
+
expect(exitCode).toBe(0)
|
|
90
|
+
expect(stdout).toContain("setup")
|
|
91
|
+
expect(stdout).toContain("status")
|
|
92
|
+
expect(stdout).toContain("logs")
|
|
93
|
+
expect(stdout).toContain("backup")
|
|
94
|
+
expect(stdout).toContain("update")
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it("self-host setup --help shows --domain option", () => {
|
|
98
|
+
const { stdout, exitCode } = runCli(["self-host", "setup", "--help"])
|
|
99
|
+
expect(exitCode).toBe(0)
|
|
100
|
+
expect(stdout).toContain("--domain")
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it("unknown command exits non-zero", () => {
|
|
104
|
+
const { exitCode } = runCli(["doesnotexist"])
|
|
105
|
+
expect(exitCode).not.toBe(0)
|
|
106
|
+
})
|
|
107
|
+
})
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from "vitest"
|
|
2
|
+
import { mkdirSync, rmSync, writeFileSync } from "node:fs"
|
|
3
|
+
import { join } from "node:path"
|
|
4
|
+
import { tmpdir } from "node:os"
|
|
5
|
+
import { defineConfig, loadConfig } from "../src/config.js"
|
|
6
|
+
import type { DefinatypeConfig } from "../src/config.js"
|
|
7
|
+
|
|
8
|
+
let counter = 0
|
|
9
|
+
let tmpDir: string
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
// Counter prevents timestamp collisions when tests run in rapid succession
|
|
13
|
+
tmpDir = join(tmpdir(), `dt-config-test-${Date.now()}-${++counter}`)
|
|
14
|
+
mkdirSync(tmpDir, { recursive: true })
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
rmSync(tmpDir, { recursive: true, force: true })
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
describe("defineConfig()", () => {
|
|
22
|
+
it("returns its argument unchanged (identity helper for type inference)", () => {
|
|
23
|
+
const cfg: DefinatypeConfig = {
|
|
24
|
+
connection: "postgresql://localhost/test",
|
|
25
|
+
schema: "./schema/index.ts",
|
|
26
|
+
}
|
|
27
|
+
expect(defineConfig(cfg)).toBe(cfg)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it("preserves optional output field", () => {
|
|
31
|
+
const cfg = defineConfig({
|
|
32
|
+
connection: "postgresql://localhost/test",
|
|
33
|
+
schema: "./schema/index.ts",
|
|
34
|
+
output: { types: "./src/types.d.ts", client: "./src/client.ts" },
|
|
35
|
+
})
|
|
36
|
+
expect(cfg.output?.types).toBe("./src/types.d.ts")
|
|
37
|
+
expect(cfg.output?.client).toBe("./src/client.ts")
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
describe("loadConfig()", () => {
|
|
42
|
+
it("throws when no config file exists in the directory", () => {
|
|
43
|
+
expect(() => loadConfig(tmpDir)).toThrow(/No supatype.config.ts found/)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it("loads a valid supatype.config.ts (plain export default, no package imports)", () => {
|
|
47
|
+
// Note: avoid importing @supatype/cli inside the temp config —
|
|
48
|
+
// the temp dir is outside the monorepo and can't resolve workspace packages.
|
|
49
|
+
writeFileSync(
|
|
50
|
+
join(tmpDir, "supatype.config.ts"),
|
|
51
|
+
`export default {
|
|
52
|
+
connection: "postgresql://localhost/mydb",
|
|
53
|
+
schema: "./schema/index.ts",
|
|
54
|
+
}
|
|
55
|
+
`,
|
|
56
|
+
)
|
|
57
|
+
const cfg = loadConfig(tmpDir)
|
|
58
|
+
expect(cfg.connection).toBe("postgresql://localhost/mydb")
|
|
59
|
+
expect(cfg.schema).toBe("./schema/index.ts")
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it("loads a supatype.config.js (plain ESM)", () => {
|
|
63
|
+
writeFileSync(
|
|
64
|
+
join(tmpDir, "supatype.config.js"),
|
|
65
|
+
`export default {
|
|
66
|
+
connection: "postgresql://localhost/jsdb",
|
|
67
|
+
schema: "./schema/index.ts",
|
|
68
|
+
}
|
|
69
|
+
`,
|
|
70
|
+
)
|
|
71
|
+
const cfg = loadConfig(tmpDir)
|
|
72
|
+
expect(cfg.connection).toBe("postgresql://localhost/jsdb")
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it("throws if config is missing the schema field", () => {
|
|
76
|
+
writeFileSync(
|
|
77
|
+
join(tmpDir, "supatype.config.ts"),
|
|
78
|
+
`export default { connection: "postgresql://localhost/test" }`,
|
|
79
|
+
)
|
|
80
|
+
expect(() => loadConfig(tmpDir)).toThrow(/must export/)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it("throws if config is missing the connection field", () => {
|
|
84
|
+
writeFileSync(
|
|
85
|
+
join(tmpDir, "supatype.config.ts"),
|
|
86
|
+
`export default { schema: "./schema/index.ts" }`,
|
|
87
|
+
)
|
|
88
|
+
expect(() => loadConfig(tmpDir)).toThrow(/must export/)
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it("prefers supatype.config.ts over supatype.config.js when both exist", () => {
|
|
92
|
+
writeFileSync(
|
|
93
|
+
join(tmpDir, "supatype.config.ts"),
|
|
94
|
+
`export default { connection: "postgresql://localhost/from-ts", schema: "./schema/index.ts" }`,
|
|
95
|
+
)
|
|
96
|
+
writeFileSync(
|
|
97
|
+
join(tmpDir, "supatype.config.js"),
|
|
98
|
+
`export default { connection: "postgresql://localhost/from-js", schema: "./schema/index.ts" }`,
|
|
99
|
+
)
|
|
100
|
+
const cfg = loadConfig(tmpDir)
|
|
101
|
+
expect(cfg.connection).toContain("from-ts")
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it("supports optional output field in config", () => {
|
|
105
|
+
writeFileSync(
|
|
106
|
+
join(tmpDir, "supatype.config.ts"),
|
|
107
|
+
`export default {
|
|
108
|
+
connection: "postgresql://localhost/test",
|
|
109
|
+
schema: "./schema/index.ts",
|
|
110
|
+
output: { types: "./src/types.d.ts" },
|
|
111
|
+
}
|
|
112
|
+
`,
|
|
113
|
+
)
|
|
114
|
+
const cfg = loadConfig(tmpDir)
|
|
115
|
+
expect(cfg.output?.types).toBe("./src/types.d.ts")
|
|
116
|
+
})
|
|
117
|
+
})
|