@supatype/cli 0.3.0 → 0.3.2
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 +1 -1
- package/.turbo/turbo-test.log +161 -154
- package/.turbo/turbo-typecheck.log +1 -1
- package/dist/api-config-cache.d.ts +20 -0
- package/dist/api-config-cache.d.ts.map +1 -1
- package/dist/api-config-cache.js +27 -0
- package/dist/api-config-cache.js.map +1 -1
- package/dist/augmentation-generator.d.ts.map +1 -1
- package/dist/augmentation-generator.js +63 -18
- package/dist/augmentation-generator.js.map +1 -1
- package/dist/cli-version-embedded.js +1 -1
- package/dist/client-generator.d.ts +3 -0
- package/dist/client-generator.d.ts.map +1 -0
- package/dist/client-generator.js +108 -0
- package/dist/client-generator.js.map +1 -0
- package/dist/commands/admin.d.ts.map +1 -1
- package/dist/commands/admin.js +21 -4
- package/dist/commands/admin.js.map +1 -1
- package/dist/commands/functions.d.ts.map +1 -1
- package/dist/commands/functions.js +2 -2
- package/dist/commands/functions.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +7 -10
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/keys.d.ts +35 -0
- package/dist/commands/keys.d.ts.map +1 -1
- package/dist/commands/keys.js +90 -6
- package/dist/commands/keys.js.map +1 -1
- package/dist/commands/push.d.ts.map +1 -1
- package/dist/commands/push.js +23 -13
- package/dist/commands/push.js.map +1 -1
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +19 -1
- package/dist/commands/update.js.map +1 -1
- package/dist/db-port.d.ts +36 -0
- package/dist/db-port.d.ts.map +1 -0
- package/dist/db-port.js +90 -0
- package/dist/db-port.js.map +1 -0
- package/dist/dev-compose.d.ts +13 -0
- package/dist/dev-compose.d.ts.map +1 -1
- package/dist/dev-compose.js +205 -18
- package/dist/dev-compose.js.map +1 -1
- package/dist/functions-context-refresh.d.ts +4 -0
- package/dist/functions-context-refresh.d.ts.map +1 -0
- package/dist/functions-context-refresh.js +26 -0
- package/dist/functions-context-refresh.js.map +1 -0
- package/dist/functions-deno-types.d.ts +9 -0
- package/dist/functions-deno-types.d.ts.map +1 -1
- package/dist/functions-deno-types.js +21 -1
- package/dist/functions-deno-types.js.map +1 -1
- package/dist/gitignore.d.ts +3 -1
- package/dist/gitignore.d.ts.map +1 -1
- package/dist/gitignore.js +28 -6
- package/dist/gitignore.js.map +1 -1
- package/dist/model-cache.d.ts +27 -0
- package/dist/model-cache.d.ts.map +1 -1
- package/dist/model-cache.js +61 -0
- package/dist/model-cache.js.map +1 -1
- package/dist/schema-ast-v2.d.ts.map +1 -1
- package/dist/schema-ast-v2.js +17 -8
- package/dist/schema-ast-v2.js.map +1 -1
- package/dist/self-host-compose.d.ts +10 -2
- package/dist/self-host-compose.d.ts.map +1 -1
- package/dist/self-host-compose.js +114 -9
- package/dist/self-host-compose.js.map +1 -1
- package/dist/strict.d.ts +29 -0
- package/dist/strict.d.ts.map +1 -0
- package/dist/strict.js +37 -0
- package/dist/strict.js.map +1 -0
- package/dist/studio-dev-server.d.ts +12 -2
- package/dist/studio-dev-server.d.ts.map +1 -1
- package/dist/studio-dev-server.js +12 -2
- package/dist/studio-dev-server.js.map +1 -1
- package/dist/type-extractor.d.ts.map +1 -1
- package/dist/type-extractor.js +8 -2
- package/dist/type-extractor.js.map +1 -1
- package/dist/type-generation.d.ts +14 -0
- package/dist/type-generation.d.ts.map +1 -1
- package/dist/type-generation.js +41 -2
- package/dist/type-generation.js.map +1 -1
- package/package.json +2 -2
- package/src/api-config-cache.ts +30 -0
- package/src/augmentation-generator.ts +75 -18
- package/src/cli-version-embedded.ts +1 -1
- package/src/client-generator.ts +122 -0
- package/src/commands/admin.ts +23 -6
- package/src/commands/functions.ts +5 -2
- package/src/commands/init.ts +10 -10
- package/src/commands/keys.ts +112 -7
- package/src/commands/push.ts +25 -15
- package/src/commands/update.ts +20 -1
- package/src/db-port.ts +99 -0
- package/src/dev-compose.ts +244 -19
- package/src/functions-context-refresh.ts +25 -0
- package/src/functions-deno-types.ts +24 -1
- package/src/gitignore.ts +31 -10
- package/src/model-cache.ts +48 -0
- package/src/schema-ast-v2.ts +17 -8
- package/src/self-host-compose.ts +115 -9
- package/src/strict.ts +40 -0
- package/src/studio-dev-server.ts +12 -2
- package/src/type-extractor.ts +8 -2
- package/src/type-generation.ts +47 -2
- package/tests/ast-derived-outputs.test.ts +92 -0
- package/tests/augmentation-generator.test.ts +127 -1
- package/tests/client-generator.test.ts +103 -0
- package/tests/db-port.test.ts +128 -0
- package/tests/external-database-compose.test.ts +8 -1
- package/tests/functions-context-refresh.test.ts +86 -0
- package/tests/gitignore-secrets.test.ts +90 -0
- package/tests/keys-write.test.ts +148 -0
- package/tests/runtime-contract.test.ts +115 -2
- package/tests/strict.test.ts +78 -0
- package/tests/type-extractor.test.ts +34 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../src/commands/update.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACjE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,8BAA8B,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AACvJ,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,sBAAsB,EAAE,aAAa,EAAkB,MAAM,oBAAoB,CAAA;AACrH,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,m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,GAAG,GAAG,GAAG,CAAC,EAAE,CAAC;gBAC7B,IAAI,GAAG,IAAI,CAAC,OAAO,CACjB,IAAI,MAAM,CAAC,IAAI,GAAG,4BAA4B,CAAC,EAC/C,KAAK,EAAE,IAAI,CACZ,CAAA;YACH,CAAC;iBAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;gBACtC,IAAI,GAAG,IAAI,CAAC,OAAO,CACjB,2BAA2B,EAC3B,YAAY,GAAG,MAAM,EAAE,KAAK,CAC7B,CAAA;YACH,CAAC;iBAAM,CAAC;gBACN,IAAI,GAAG,IAAI,CAAC,OAAO,CACjB,oCAAoC,EACpC,wBAAwB,GAAG,MAAM,EAAE,gBAAgB,CACpD,CAAA;YACH,CAAC;QACH,CAAC;QAED,aAAa,CAAC,UAAU,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;QACvC,IAAI,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,WAAW,CAAC,CAAA;QACxC,YAAY,EAAE,CAAA;IAChB,CAAC,CAAC,CAAA;AACN,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** The `.env` key that moves the published Postgres port for a self-host stack. */
|
|
2
|
+
export declare const DB_PORT_ENV = "SUPATYPE_DB_PORT";
|
|
3
|
+
/**
|
|
4
|
+
* The `.env` key that moves it for a dev-local stack, and which takes precedence.
|
|
5
|
+
*
|
|
6
|
+
* Two variables, two deployment shapes: an ordinary self-host stack publishes Postgres at
|
|
7
|
+
* `SUPATYPE_DB_PORT`, and a project with `overrides.engine` publishes it at
|
|
8
|
+
* `SUPATYPE_DEV_DB_PORT` so the host-side engine binary can reach it. Its presence is what marks
|
|
9
|
+
* the second shape, so it wins where both are set.
|
|
10
|
+
*
|
|
11
|
+
* Learned the hard way. The first cut of this file read only `SUPATYPE_DB_PORT`, so on a project
|
|
12
|
+
* with `SUPATYPE_DEV_DB_PORT=54330` it rewrote a correct `DATABASE_URL` to 5432, where nothing was
|
|
13
|
+
* listening. It fixed the bug it was written for and reintroduced it through the other door, which
|
|
14
|
+
* is the exact failure this file exists to prevent.
|
|
15
|
+
*/
|
|
16
|
+
export declare const DEV_DB_PORT_ENV = "SUPATYPE_DEV_DB_PORT";
|
|
17
|
+
/** What compose binds when neither variable is set, and what `init` writes into the URL. */
|
|
18
|
+
export declare const DEFAULT_DB_PORT = 5432;
|
|
19
|
+
/** The port Postgres is published on for this project, from `.env`. */
|
|
20
|
+
export declare function publishedDbPort(env: Record<string, string>): number;
|
|
21
|
+
/** What changed, for the caller to report. */
|
|
22
|
+
export interface DbPortSync {
|
|
23
|
+
from: string;
|
|
24
|
+
to: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Rewrite `DATABASE_URL`'s port to match `SUPATYPE_DB_PORT`, and report it.
|
|
28
|
+
*
|
|
29
|
+
* Returns null when there is nothing to do, which is the common case.
|
|
30
|
+
*
|
|
31
|
+
* Only touches a URL pointing at this machine. A project whose `DATABASE_URL` names a managed
|
|
32
|
+
* Postgres elsewhere has a port that is nothing to do with our compose mapping, and rewriting it
|
|
33
|
+
* would repoint the whole project at a database that does not exist.
|
|
34
|
+
*/
|
|
35
|
+
export declare function syncDatabaseUrlPort(cwd: string): DbPortSync | null;
|
|
36
|
+
//# sourceMappingURL=db-port.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-port.d.ts","sourceRoot":"","sources":["../src/db-port.ts"],"names":[],"mappings":"AAsBA,mFAAmF;AACnF,eAAO,MAAM,WAAW,qBAAqB,CAAA;AAE7C;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,eAAe,yBAAyB,CAAA;AAErD,4FAA4F;AAC5F,eAAO,MAAM,eAAe,OAAO,CAAA;AAKnC,uEAAuE;AACvE,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAWnE;AAED,8CAA8C;AAC9C,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,MAAM,CAAA;CACX;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAuBlE"}
|
package/dist/db-port.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keep `DATABASE_URL` pointing at the port Postgres is actually published on.
|
|
3
|
+
*
|
|
4
|
+
* `SUPATYPE_DB_PORT` moves the host side of the compose port mapping, so a second project on one
|
|
5
|
+
* machine can avoid a clash. `DATABASE_URL` is what every host-side script uses: seeds, one-off
|
|
6
|
+
* psql, `supatype admin create-user --connection`. `init` writes the URL with 5432 in it and
|
|
7
|
+
* nothing has ever reconciled the two.
|
|
8
|
+
*
|
|
9
|
+
* The result is a project that starts cleanly, serves every request, and fails the first time
|
|
10
|
+
* someone runs `npm run seed`:
|
|
11
|
+
*
|
|
12
|
+
* AggregateError [ECONNREFUSED]: connect ECONNREFUSED 127.0.0.1:5432
|
|
13
|
+
*
|
|
14
|
+
* with the database listening on 5433 and nothing connecting the error to the port variable the
|
|
15
|
+
* person set half an hour earlier. The generated `.env` even carries a comment conceding the
|
|
16
|
+
* assumption: "Self-host compose uses the same DATABASE_URL when Postgres is published on
|
|
17
|
+
* localhost:5432."
|
|
18
|
+
*
|
|
19
|
+
* `SUPATYPE_DB_PORT` is the source of truth, because it is what compose binds. The URL follows it.
|
|
20
|
+
*/
|
|
21
|
+
import { readEnvFile, upsertEnvFile } from "./env-file.js";
|
|
22
|
+
/** The `.env` key that moves the published Postgres port for a self-host stack. */
|
|
23
|
+
export const DB_PORT_ENV = "SUPATYPE_DB_PORT";
|
|
24
|
+
/**
|
|
25
|
+
* The `.env` key that moves it for a dev-local stack, and which takes precedence.
|
|
26
|
+
*
|
|
27
|
+
* Two variables, two deployment shapes: an ordinary self-host stack publishes Postgres at
|
|
28
|
+
* `SUPATYPE_DB_PORT`, and a project with `overrides.engine` publishes it at
|
|
29
|
+
* `SUPATYPE_DEV_DB_PORT` so the host-side engine binary can reach it. Its presence is what marks
|
|
30
|
+
* the second shape, so it wins where both are set.
|
|
31
|
+
*
|
|
32
|
+
* Learned the hard way. The first cut of this file read only `SUPATYPE_DB_PORT`, so on a project
|
|
33
|
+
* with `SUPATYPE_DEV_DB_PORT=54330` it rewrote a correct `DATABASE_URL` to 5432, where nothing was
|
|
34
|
+
* listening. It fixed the bug it was written for and reintroduced it through the other door, which
|
|
35
|
+
* is the exact failure this file exists to prevent.
|
|
36
|
+
*/
|
|
37
|
+
export const DEV_DB_PORT_ENV = "SUPATYPE_DEV_DB_PORT";
|
|
38
|
+
/** What compose binds when neither variable is set, and what `init` writes into the URL. */
|
|
39
|
+
export const DEFAULT_DB_PORT = 5432;
|
|
40
|
+
/** Hosts whose port is ours to correct. Anything else is somebody else's database. */
|
|
41
|
+
const LOCAL_HOSTS = new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
|
|
42
|
+
/** The port Postgres is published on for this project, from `.env`. */
|
|
43
|
+
export function publishedDbPort(env) {
|
|
44
|
+
// Dev-local first: its presence is what says this project publishes for a host-side engine.
|
|
45
|
+
for (const key of [DEV_DB_PORT_ENV, DB_PORT_ENV]) {
|
|
46
|
+
const raw = (env[key] ?? "").trim();
|
|
47
|
+
if (raw === "")
|
|
48
|
+
continue;
|
|
49
|
+
const port = Number(raw);
|
|
50
|
+
// A non-numeric or out-of-range value is the operator's to fix, and compose reports it far
|
|
51
|
+
// better than we can. Falling through keeps this from inventing a port nothing listens on.
|
|
52
|
+
if (Number.isInteger(port) && port > 0 && port < 65536)
|
|
53
|
+
return port;
|
|
54
|
+
}
|
|
55
|
+
return DEFAULT_DB_PORT;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Rewrite `DATABASE_URL`'s port to match `SUPATYPE_DB_PORT`, and report it.
|
|
59
|
+
*
|
|
60
|
+
* Returns null when there is nothing to do, which is the common case.
|
|
61
|
+
*
|
|
62
|
+
* Only touches a URL pointing at this machine. A project whose `DATABASE_URL` names a managed
|
|
63
|
+
* Postgres elsewhere has a port that is nothing to do with our compose mapping, and rewriting it
|
|
64
|
+
* would repoint the whole project at a database that does not exist.
|
|
65
|
+
*/
|
|
66
|
+
export function syncDatabaseUrlPort(cwd) {
|
|
67
|
+
const env = readEnvFile(cwd);
|
|
68
|
+
const raw = (env["DATABASE_URL"] ?? "").trim();
|
|
69
|
+
if (raw === "")
|
|
70
|
+
return null;
|
|
71
|
+
let url;
|
|
72
|
+
try {
|
|
73
|
+
url = new URL(raw);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// Malformed, so not ours to rewrite: a partial edit here would turn a typo into a URL that
|
|
77
|
+
// parses and points somewhere wrong, which is harder to spot than the typo.
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
if (!LOCAL_HOSTS.has(url.hostname))
|
|
81
|
+
return null;
|
|
82
|
+
const wanted = String(publishedDbPort(env));
|
|
83
|
+
const current = url.port === "" ? String(DEFAULT_DB_PORT) : url.port;
|
|
84
|
+
if (current === wanted)
|
|
85
|
+
return null;
|
|
86
|
+
url.port = wanted;
|
|
87
|
+
upsertEnvFile(cwd, { DATABASE_URL: url.toString() });
|
|
88
|
+
return { from: current, to: wanted };
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=db-port.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-port.js","sourceRoot":"","sources":["../src/db-port.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAE1D,mFAAmF;AACnF,MAAM,CAAC,MAAM,WAAW,GAAG,kBAAkB,CAAA;AAE7C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,sBAAsB,CAAA;AAErD,4FAA4F;AAC5F,MAAM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AAI,CAAA;IAE/C,MAAM,MAAM,GAAG,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAA;IAC3C,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAA;IACpE,IAAI,OAAO,KAAK,MAAM;QAAE,OAAO,IAAI,CAAA;IAEnC,GAAG,CAAC,IAAI,GAAG,MAAM,CAAA;IACjB,aAAa,CAAC,GAAG,EAAE,EAAE,YAAY,EAAE,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IACpD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,CAAA;AACtC,CAAC"}
|
package/dist/dev-compose.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* `supatype dev` when `provider: docker`, full self-host Compose stack (Kong gateway).
|
|
3
3
|
*/
|
|
4
4
|
import { type SupatypeProjectConfig } from "./project-config.js";
|
|
5
|
+
import { type SelfHostComposePaths } from "./self-host-compose.js";
|
|
5
6
|
import type { DockerBrandOptions } from "./docker-runtime.js";
|
|
6
7
|
import { type DiffResult } from "./engine-client.js";
|
|
7
8
|
/** Sync optional Docker image pins from config into `.env` (no JWT rotation). */
|
|
@@ -41,4 +42,16 @@ export declare function diffSchemaDocker(cwd: string, config: SupatypeProjectCon
|
|
|
41
42
|
*/
|
|
42
43
|
export declare function pushSchemaDocker(cwd: string, config: SupatypeProjectConfig): Promise<void>;
|
|
43
44
|
export declare function runDevCompose(cwd: string, config: SupatypeProjectConfig, opts: DevComposeOptions): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Write `admin-config.json` and the generated types using the in-compose engine.
|
|
47
|
+
*
|
|
48
|
+
* The fallback for a host engine that could not be fetched. Without it, a `supatype dev` that
|
|
49
|
+
* applied the schema perfectly well still left no `admin-config.json`, and Studio reads that file
|
|
50
|
+
* to decide whether a schema exists: the stack came up, every table was live, the API served them,
|
|
51
|
+
* and Studio said **"No schema has been pushed yet."** The warning that preceded it named the
|
|
52
|
+
* download, not the consequence, so nothing connected the two.
|
|
53
|
+
*
|
|
54
|
+
* Returns true when the admin config was written, which is the file Studio actually needs.
|
|
55
|
+
*/
|
|
56
|
+
export declare function generateViaComposeEngine(paths: SelfHostComposePaths, cwd: string, composeProject: string, config: SupatypeProjectConfig, ast: unknown, adminConfigPath: string): Promise<boolean>;
|
|
44
57
|
//# sourceMappingURL=dev-compose.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-compose.d.ts","sourceRoot":"","sources":["../src/dev-compose.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"dev-compose.d.ts","sourceRoot":"","sources":["../src/dev-compose.ts"],"names":[],"mappings":"AAAA;;GAEG;AAWH,OAAO,EAQL,KAAK,qBAAqB,EAC3B,MAAM,qBAAqB,CAAA;AAc5B,OAAO,EASL,KAAK,oBAAoB,EAC1B,MAAM,wBAAwB,CAAA;AAC/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAQ7D,OAAO,EAA+B,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAA;AA4BjF,iFAAiF;AACjF,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,qBAAqB,GAAG,IAAI,CASrF;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,OAAO,CAAA;CACf;AAED,kEAAkE;AAClE,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIhD;AA+BD;;;GAGG;AACH,wBAAsB,oCAAoC,CACxD,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,qBAAqB,EAC7B,KAAK,CAAC,EAAE,kBAAkB,GACzB,OAAO,CAAC,IAAI,CAAC,CAuBf;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,qBAAqB,EAC7B,kBAAkB,CAAC,EAAE,MAAM,GAC1B,OAAO,CAOT;AAED;;;;GAIG;AACH,wBAAsB,4BAA4B,CAChD,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,qBAAqB,EAC7B,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC,CAQjB;AAoED,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,qBAAqB,EAC7B,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,GACjB,IAAI,CAiFN;AAwlBD;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,UAAU,CAAC,CA+DtG;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CA8ChG;AAED,wBAAsB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,qBAAqB,EAAE,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAsRtH;AA+ID;;;;;;;;;;GAUG;AACH,wBAAsB,wBAAwB,CAC5C,KAAK,EAAE,oBAAoB,EAC3B,GAAG,EAAE,MAAM,EACX,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,qBAAqB,EAC7B,GAAG,EAAE,OAAO,EACZ,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,OAAO,CAAC,CAwClB"}
|
package/dist/dev-compose.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `supatype dev` when `provider: docker`, full self-host Compose stack (Kong gateway).
|
|
3
3
|
*/
|
|
4
|
+
import { writeAstDerivedOutputs } from "./type-generation.js";
|
|
4
5
|
import { withPublishing } from "./model-versioning.js";
|
|
5
6
|
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
6
7
|
import { homedir } from "node:os";
|
|
@@ -11,13 +12,19 @@ import { loadSchemaAst } from "./config.js";
|
|
|
11
12
|
import { withComposeSchemaPushLock } from "./schema-push-lock.js";
|
|
12
13
|
import { connectionString, projectRootFromConfig, resolveRuntimeProvider, hooksPathFromProject, schemaPathFromProject, usesExternalDatabase, } from "./project-config.js";
|
|
13
14
|
import { syncManifestHooks, writeHooksModule } from "./model-hooks.js";
|
|
15
|
+
import { syncRowCacheEnv } from "./model-cache.js";
|
|
16
|
+
import { anonKeyEnvUpdates } from "./commands/keys.js";
|
|
14
17
|
import { signJwt } from "./jwt.js";
|
|
15
18
|
import { ensureDevDbPort, ensureKongPort } from "./dev-ports.js";
|
|
16
19
|
import { handleComposeProjectRename } from "./compose-rename.js";
|
|
17
20
|
import { recoverStaleDevSession, writeDevSessionLock } from "./dev-session-lock.js";
|
|
18
21
|
import { endDevSession, startDevSession } from "./dev-session.js";
|
|
19
22
|
import { ensureDevApiConfig } from "./ensure-dev-api-config.js";
|
|
20
|
-
import {
|
|
23
|
+
import { cacheSeedingNotes } from "./api-config-cache.js";
|
|
24
|
+
import { refreshFunctionsContext } from "./functions-context-refresh.js";
|
|
25
|
+
import { DB_PORT_ENV, syncDatabaseUrlPort } from "./db-port.js";
|
|
26
|
+
import { degraded } from "./strict.js";
|
|
27
|
+
import { COMPOSE_PINNED_IMAGE_ENV_KEYS, composeDockerImageEnv, composeProjectName, exitComposeFailed, runDockerCompose, schemaEngineImageForPush, writeSelfHostCompose, selfHostComposePaths, } from "./self-host-compose.js";
|
|
21
28
|
import { hasEngineOverride } from "./binary-cache.js";
|
|
22
29
|
import { STUDIO_DEV_PORT, startStudioViteDevServer } from "./studio-dev-server.js";
|
|
23
30
|
import { ensureLocalServerDockerImage, usesLocalServerImage, LOCAL_SERVER_DOCKER_IMAGE, } from "./compose-local-server-image.js";
|
|
@@ -214,13 +221,13 @@ export function upsertDevComposeEnv(cwd, config, anonKey, serviceRoleKey, kongPo
|
|
|
214
221
|
...seedMissingLocalSecrets(cwd),
|
|
215
222
|
// Project configuration, seeded not overwritten, see seedMissingDatabaseIdentity.
|
|
216
223
|
...seedMissingDatabaseIdentity(cwd),
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
+
// Shared with `supatype keys --write`, so a front end's prefix cannot be written by one and
|
|
225
|
+
// forgotten by the other. See `anonKeyEnvUpdates`.
|
|
226
|
+
//
|
|
227
|
+
// This list used to live here as well, and the two had already drifted: `dev` wrote
|
|
228
|
+
// PUBLIC_ and EXPO_PUBLIC_ URLs and no VITE_SUPATYPE_URL, so a Vite app whose `.env` had only
|
|
229
|
+
// ever been touched by `supatype dev` built against an empty string.
|
|
230
|
+
...anonKeyEnvUpdates(anonKey, serviceRoleKey, apiUrl),
|
|
224
231
|
SUPATYPE_KONG_PORT: String(kongPort),
|
|
225
232
|
API_EXTERNAL_URL: apiUrl,
|
|
226
233
|
SITE_URL: apiUrl,
|
|
@@ -284,7 +291,17 @@ async function waitComposeHealthy(paths, cwd, maxMs, composeProject) {
|
|
|
284
291
|
baseArgs.push("--env-file", envFile);
|
|
285
292
|
const deadline = Date.now() + maxMs;
|
|
286
293
|
while (Date.now() < deadline) {
|
|
287
|
-
const ready = spawnSync("docker",
|
|
294
|
+
const ready = spawnSync("docker",
|
|
295
|
+
// Over TCP, deliberately, not the Unix socket.
|
|
296
|
+
//
|
|
297
|
+
// On a first run the Postgres entrypoint starts a temporary server with `listen_addresses=''`
|
|
298
|
+
// to run the init scripts, then shuts it down and starts the real one. That temporary server
|
|
299
|
+
// answers on the socket, so a socket `pg_isready` reports ready during init and the very next
|
|
300
|
+
// thing to connect meets "the database system is shutting down". It is why the initial push
|
|
301
|
+
// failed three times in a row on a clean machine while a warm one was fine.
|
|
302
|
+
//
|
|
303
|
+
// TCP is the distinction the entrypoint itself draws: the init server does not listen on it.
|
|
304
|
+
[...baseArgs, "exec", "-T", "db", "pg_isready", "-h", "127.0.0.1", "-U", "supatype_admin"], { cwd: composeDir, encoding: "utf8" });
|
|
288
305
|
if (ready.status === 0)
|
|
289
306
|
return;
|
|
290
307
|
await new Promise((r) => setTimeout(r, 2000));
|
|
@@ -466,14 +483,58 @@ async function refreshSchemaArtifacts(cwd, config, ast) {
|
|
|
466
483
|
const hooksModule = writeHooksModule(cwd, hooksPathFromProject(config, cwd), ast);
|
|
467
484
|
if (hooksModule !== null)
|
|
468
485
|
console.log(`[supatype] Hook handler types written to ${hooksModule}`);
|
|
486
|
+
// And the context module, on the same terms. `init` and `functions new` wrote it and nothing
|
|
487
|
+
// else did, so a project that already had functions when the two-argument contract landed never
|
|
488
|
+
// received one: its handlers had no `FunctionContext` to import.
|
|
489
|
+
if (refreshFunctionsContext(cwd, config)) {
|
|
490
|
+
console.log("[supatype] Function context type written to functions/_shared/context.ts");
|
|
491
|
+
}
|
|
469
492
|
if (syncManifestHooks(cwd, ast)) {
|
|
470
493
|
console.log("[supatype] Hook and validator maps written to .supatype/manifest.json");
|
|
471
494
|
}
|
|
495
|
+
// Written before the stack comes up, so a first run with a row cache declared starts with it on
|
|
496
|
+
// rather than needing a second `supatype dev`.
|
|
497
|
+
const rowCache = syncRowCacheEnv(cwd, ast);
|
|
498
|
+
if (rowCache !== null) {
|
|
499
|
+
console.log(`[supatype] Row cache switched ${rowCache} in .env (pg_keyspace Mode B).`);
|
|
500
|
+
}
|
|
501
|
+
// SUPATYPE_DB_PORT moves what compose binds; DATABASE_URL is what seeds and psql use. Nothing
|
|
502
|
+
// reconciled them, so a project moved off 5432 to avoid a clash came up perfectly and then
|
|
503
|
+
// failed on `npm run seed` with ECONNREFUSED against a port nothing was listening on.
|
|
504
|
+
const dbPort = syncDatabaseUrlPort(cwd);
|
|
505
|
+
if (dbPort !== null) {
|
|
506
|
+
console.log(`[supatype] DATABASE_URL port ${dbPort.from} -> ${dbPort.to} in .env, ` +
|
|
507
|
+
`to match ${DB_PORT_ENV}.`);
|
|
508
|
+
}
|
|
509
|
+
// The declaration is a ceiling and the allowlist is what is actually on, and only `push` ever
|
|
510
|
+
// seeded the allowlist. So a stack brought up with `supatype dev` alone had every model's
|
|
511
|
+
// `cache` block declared and nothing switched on: `.cache({ server: true })` answered BYPASS,
|
|
512
|
+
// and the only way to find out why was to open Studio and tick a box the schema had already
|
|
513
|
+
// justified.
|
|
514
|
+
for (const note of cacheSeedingNotes(cwd, ast))
|
|
515
|
+
console.log(`[supatype] ${note}`);
|
|
472
516
|
try {
|
|
473
517
|
await ensureEngine();
|
|
474
518
|
}
|
|
475
519
|
catch (err) {
|
|
476
|
-
|
|
520
|
+
// The host engine is a CDN download and this machine could not complete it. The schema is
|
|
521
|
+
// already applied, so fall back to the engine in compose rather than giving up: without
|
|
522
|
+
// admin-config.json Studio reports "No schema has been pushed yet" on a stack whose schema is
|
|
523
|
+
// entirely live, which reads as a failed push rather than a missing binary.
|
|
524
|
+
const paths = selfHostComposePaths(cwd);
|
|
525
|
+
const composeProject = composeProjectName(config.project.name);
|
|
526
|
+
const wrote = await generateViaComposeEngine(paths, cwd, composeProject, config, ast, adminConfigPath).catch(() => false);
|
|
527
|
+
if (wrote) {
|
|
528
|
+
// Reported through `degraded` rather than warned: the in-compose engine writes the admin
|
|
529
|
+
// config but never reaches the type generation below, so a run that takes this path has
|
|
530
|
+
// stale generated types and says so only in a line that scrolls past. In CI that is the
|
|
531
|
+
// difference between testing the host engine path and never touching it.
|
|
532
|
+
degraded("Host engine unavailable, used the in-compose engine instead", err.message);
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
degraded("Host engine unavailable, admin config and types not refreshed", `${err.message}\n` +
|
|
536
|
+
"[supatype] Studio will report no schema until this succeeds, even though the schema is " +
|
|
537
|
+
"applied. Retry with the stack up, or run `supatype push`.");
|
|
477
538
|
return;
|
|
478
539
|
}
|
|
479
540
|
const typesPath = config.output?.types;
|
|
@@ -500,6 +561,23 @@ async function refreshSchemaArtifacts(cwd, config, ast) {
|
|
|
500
561
|
console.warn(`[supatype] Type generation failed: ${err.message}`);
|
|
501
562
|
}
|
|
502
563
|
}
|
|
564
|
+
// Needs no engine, so it is written whether or not the types step above ran or succeeded. This
|
|
565
|
+
// is what `dev` never did: a project developed entirely through `supatype dev` received neither
|
|
566
|
+
// `index.d.ts`, which is what makes `createClient` typed without a generic, nor the field kinds
|
|
567
|
+
// the client reads to keep bigInt, decimal and money columns exact.
|
|
568
|
+
try {
|
|
569
|
+
for (const message of writeAstDerivedOutputs({
|
|
570
|
+
cwd,
|
|
571
|
+
ast,
|
|
572
|
+
...(config.output?.types !== undefined && { typesPath: config.output.types }),
|
|
573
|
+
...(config.output?.client !== undefined && { clientPath: config.output.client }),
|
|
574
|
+
})) {
|
|
575
|
+
console.log(`[supatype] ${message}`);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
catch (err) {
|
|
579
|
+
console.warn(`[supatype] Generated output failed: ${err.message}`);
|
|
580
|
+
}
|
|
503
581
|
try {
|
|
504
582
|
const admin = withAdminRoles(await engineRequest("/admin", { ast }), config);
|
|
505
583
|
restoreSystemRelationTargets(admin, ast);
|
|
@@ -721,7 +799,14 @@ export async function diffSchemaDocker(cwd, config) {
|
|
|
721
799
|
throw new Error(detail || `Engine schema diff failed (exit ${result.status})`);
|
|
722
800
|
}
|
|
723
801
|
if (!result.diff) {
|
|
724
|
-
|
|
802
|
+
// The engine exited 0 and produced nothing this could parse, which is a different failure from
|
|
803
|
+
// the engine exiting non-zero and is the harder one to act on. "Engine diff returned no result"
|
|
804
|
+
// named only the symptom, and running the same compose command by hand gave a clear error in
|
|
805
|
+
// one go, so the message was the only thing standing between the reader and the answer.
|
|
806
|
+
const output = (filterComposeNoise(result.output) || result.output || "").trim();
|
|
807
|
+
throw new Error(output === ""
|
|
808
|
+
? "The schema engine exited 0 and printed nothing. Run `supatype self-host compose run --rm schema-engine diff` to see what it does."
|
|
809
|
+
: `The schema engine exited 0 but its output could not be parsed as a diff:\n${output}`);
|
|
725
810
|
}
|
|
726
811
|
return result.diff;
|
|
727
812
|
}
|
|
@@ -887,13 +972,21 @@ export async function runDevCompose(cwd, config, opts) {
|
|
|
887
972
|
exitComposeFailed(recreateStatus, "Could not recreate the server container with the local image.", devBrand);
|
|
888
973
|
}
|
|
889
974
|
}
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
975
|
+
// A service whose image is pinned in `.env` is recreated once the stack is up, so a contributor
|
|
976
|
+
// can point at a build from this checkout rather than the published tag.
|
|
977
|
+
//
|
|
978
|
+
// Storage was missing from this list, which is why a storage bug survived: there was no way to
|
|
979
|
+
// run the suite against a local storage build, so every integration run tested the last release
|
|
980
|
+
// no matter what the working tree said.
|
|
981
|
+
for (const service of ["realtime", "storage"]) {
|
|
982
|
+
const variable = `SUPATYPE_${service.toUpperCase()}_IMAGE`;
|
|
983
|
+
if (readEnvValue(cwd, variable, "").trim() === "")
|
|
984
|
+
continue;
|
|
985
|
+
console.log(`[supatype] Recreating ${service} with pinned image...`);
|
|
986
|
+
const status = runDockerCompose(paths.composePath, ["up", "-d", "--force-recreate", "--no-deps", service], cwd, project, { quiet: true, brand: devBrand });
|
|
987
|
+
if (status !== 0) {
|
|
895
988
|
endDevSession();
|
|
896
|
-
exitComposeFailed(
|
|
989
|
+
exitComposeFailed(status, `Could not recreate the ${service} container.`, devBrand);
|
|
897
990
|
}
|
|
898
991
|
}
|
|
899
992
|
console.log("[supatype] Waiting for API gateway...");
|
|
@@ -1038,7 +1131,16 @@ function reconcileAuthenticatorPassword(paths, cwd, composeProject) {
|
|
|
1038
1131
|
].join("\n"),
|
|
1039
1132
|
});
|
|
1040
1133
|
if (result.status !== 0) {
|
|
1041
|
-
|
|
1134
|
+
// The cause, not just the consequence. This warned that REST "may answer 502" and said nothing
|
|
1135
|
+
// about why, so when the supabucks e2e then failed its only API assertion with a 502, the
|
|
1136
|
+
// warning twenty lines earlier read as unrelated noise. A message that predicts a failure and
|
|
1137
|
+
// withholds its reason costs more than one that says nothing.
|
|
1138
|
+
const detail = [result.stderr, result.error?.message]
|
|
1139
|
+
.map((s) => (s ?? "").trim())
|
|
1140
|
+
.filter((s) => s.length > 0)
|
|
1141
|
+
.join("\n");
|
|
1142
|
+
console.warn(`[supatype] Could not set the authenticator password, so the REST API will answer 502.\n` +
|
|
1143
|
+
(detail === "" ? "[supatype] docker gave no output." : detail));
|
|
1042
1144
|
}
|
|
1043
1145
|
}
|
|
1044
1146
|
function grantAuthSchemaAccess(paths, cwd, composeProject) {
|
|
@@ -1054,4 +1156,89 @@ function grantAuthSchemaAccess(paths, cwd, composeProject) {
|
|
|
1054
1156
|
console.warn("[supatype] Could not grant service_role access to auth.users, Studio relation preview may fail.");
|
|
1055
1157
|
}
|
|
1056
1158
|
}
|
|
1159
|
+
/**
|
|
1160
|
+
* Run one read-only generator in the in-compose schema-engine and return its stdout.
|
|
1161
|
+
*
|
|
1162
|
+
* The same image and the same bind mount the push just used, so if the schema could be applied
|
|
1163
|
+
* this can run. It exists because the host engine is a separate binary fetched from a CDN, and a
|
|
1164
|
+
* machine that cannot fetch it is not a machine that cannot generate: the schema is already
|
|
1165
|
+
* applied, the AST is already on disk, and the container that did it is one `docker compose run`
|
|
1166
|
+
* away.
|
|
1167
|
+
*/
|
|
1168
|
+
async function runComposeEngineGenerator(paths, cwd, composeProject, config, args) {
|
|
1169
|
+
const envFile = resolve(cwd, ".env");
|
|
1170
|
+
const composeArgs = ["compose", "--progress", "quiet"];
|
|
1171
|
+
if (composeProject)
|
|
1172
|
+
composeArgs.push("-p", composeProject);
|
|
1173
|
+
composeArgs.push("--project-directory", cwd);
|
|
1174
|
+
composeArgs.push("-f", paths.composePath);
|
|
1175
|
+
if (existsSync(envFile))
|
|
1176
|
+
composeArgs.push("--env-file", envFile);
|
|
1177
|
+
composeArgs.push("--profile", "tools", "run", "--rm", "-T", "schema-engine", ...args, "-i", "/project/.supatype/schema.ast.json");
|
|
1178
|
+
const env = { ...process.env, COMPOSE_PROGRESS: "quiet" };
|
|
1179
|
+
const engineImage = await schemaEngineImageForPush(config);
|
|
1180
|
+
if (engineImage)
|
|
1181
|
+
env.SUPATYPE_ENGINE_IMAGE = engineImage;
|
|
1182
|
+
const result = spawnSync("docker", composeArgs, {
|
|
1183
|
+
cwd,
|
|
1184
|
+
encoding: "utf8",
|
|
1185
|
+
maxBuffer: 20 * 1024 * 1024,
|
|
1186
|
+
env,
|
|
1187
|
+
});
|
|
1188
|
+
if ((result.status ?? 1) !== 0)
|
|
1189
|
+
return null;
|
|
1190
|
+
return String(result.stdout ?? "");
|
|
1191
|
+
}
|
|
1192
|
+
/**
|
|
1193
|
+
* Write `admin-config.json` and the generated types using the in-compose engine.
|
|
1194
|
+
*
|
|
1195
|
+
* The fallback for a host engine that could not be fetched. Without it, a `supatype dev` that
|
|
1196
|
+
* applied the schema perfectly well still left no `admin-config.json`, and Studio reads that file
|
|
1197
|
+
* to decide whether a schema exists: the stack came up, every table was live, the API served them,
|
|
1198
|
+
* and Studio said **"No schema has been pushed yet."** The warning that preceded it named the
|
|
1199
|
+
* download, not the consequence, so nothing connected the two.
|
|
1200
|
+
*
|
|
1201
|
+
* Returns true when the admin config was written, which is the file Studio actually needs.
|
|
1202
|
+
*/
|
|
1203
|
+
export async function generateViaComposeEngine(paths, cwd, composeProject, config, ast, adminConfigPath) {
|
|
1204
|
+
const typesPath = config.output?.types;
|
|
1205
|
+
if (typeof typesPath === "string" && typesPath.trim().length > 0) {
|
|
1206
|
+
const out = await runComposeEngineGenerator(paths, cwd, composeProject, config, ["generate"]);
|
|
1207
|
+
const marker = out?.indexOf("// Generated by supatype-engine") ?? -1;
|
|
1208
|
+
if (out && out.includes("export type")) {
|
|
1209
|
+
const ts = (marker >= 0 ? out.slice(marker) : out).trimStart();
|
|
1210
|
+
const hostPath = join(cwd, typesPath);
|
|
1211
|
+
mkdirSync(dirname(hostPath), { recursive: true });
|
|
1212
|
+
writeFileSync(hostPath, ts);
|
|
1213
|
+
console.log(`[supatype] Types written to ${typesPath} (in-compose engine).`);
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
// The same AST-derived files as the host path. This is the fallback used when the host engine
|
|
1217
|
+
// could not be fetched, and these need no engine at all, so there is no reason for a project on
|
|
1218
|
+
// this path to end up with fewer generated files than one on the other.
|
|
1219
|
+
try {
|
|
1220
|
+
for (const message of writeAstDerivedOutputs({
|
|
1221
|
+
cwd,
|
|
1222
|
+
ast,
|
|
1223
|
+
...(config.output?.types !== undefined && { typesPath: config.output.types }),
|
|
1224
|
+
...(config.output?.client !== undefined && { clientPath: config.output.client }),
|
|
1225
|
+
})) {
|
|
1226
|
+
console.log(`[supatype] ${message} (in-compose engine).`);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
catch (err) {
|
|
1230
|
+
console.warn(`[supatype] Generated output failed: ${err.message}`);
|
|
1231
|
+
}
|
|
1232
|
+
const adminOut = await runComposeEngineGenerator(paths, cwd, composeProject, config, ["admin"]);
|
|
1233
|
+
if (!adminOut)
|
|
1234
|
+
return false;
|
|
1235
|
+
const parsed = parseEngineJsonOutput(adminOut);
|
|
1236
|
+
if (parsed === null)
|
|
1237
|
+
return false;
|
|
1238
|
+
const admin = withAdminRoles(parsed, config);
|
|
1239
|
+
restoreSystemRelationTargets(admin, ast);
|
|
1240
|
+
writeFileSync(adminConfigPath, `${JSON.stringify(admin, null, 2)}\n`);
|
|
1241
|
+
console.log("[supatype] Admin config written to .supatype/admin-config.json (in-compose engine).");
|
|
1242
|
+
return true;
|
|
1243
|
+
}
|
|
1057
1244
|
//# sourceMappingURL=dev-compose.js.map
|