@supatype/cli 0.1.6 → 0.1.7
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 +144 -94
- package/.turbo/turbo-typecheck.log +1 -1
- package/deno.d.ts +52 -0
- package/dist/augmentation-generator.d.ts +22 -0
- package/dist/augmentation-generator.d.ts.map +1 -1
- package/dist/augmentation-generator.js +18 -4
- package/dist/augmentation-generator.js.map +1 -1
- package/dist/binary-cache.d.ts +14 -0
- package/dist/binary-cache.d.ts.map +1 -1
- package/dist/binary-cache.js +33 -13
- package/dist/binary-cache.js.map +1 -1
- package/dist/cache-clean.d.ts +15 -0
- package/dist/cache-clean.d.ts.map +1 -0
- package/dist/cache-clean.js +76 -0
- package/dist/cache-clean.js.map +1 -0
- package/dist/cache-pins.d.ts +51 -0
- package/dist/cache-pins.d.ts.map +1 -0
- package/dist/cache-pins.js +184 -0
- package/dist/cache-pins.js.map +1 -0
- package/dist/cli-install-method.d.ts +19 -0
- package/dist/cli-install-method.d.ts.map +1 -0
- package/dist/cli-install-method.js +60 -0
- package/dist/cli-install-method.js.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +6 -0
- package/dist/cli.js.map +1 -1
- package/dist/cloud-credentials.d.ts +34 -0
- package/dist/cloud-credentials.d.ts.map +1 -0
- package/dist/cloud-credentials.js +139 -0
- package/dist/cloud-credentials.js.map +1 -0
- package/dist/commands/admin.d.ts +11 -0
- package/dist/commands/admin.d.ts.map +1 -1
- package/dist/commands/admin.js +121 -19
- package/dist/commands/admin.js.map +1 -1
- package/dist/commands/cache.d.ts.map +1 -1
- package/dist/commands/cache.js +67 -71
- package/dist/commands/cache.js.map +1 -1
- package/dist/commands/cloud.d.ts.map +1 -1
- package/dist/commands/cloud.js +32 -8
- package/dist/commands/cloud.js.map +1 -1
- package/dist/commands/db.d.ts +1 -0
- package/dist/commands/db.d.ts.map +1 -1
- package/dist/commands/db.js +147 -1
- package/dist/commands/db.js.map +1 -1
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +50 -10
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/doctor.d.ts +28 -0
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +60 -3
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/functions.d.ts +7 -0
- package/dist/commands/functions.d.ts.map +1 -1
- package/dist/commands/functions.js +40 -6
- package/dist/commands/functions.js.map +1 -1
- package/dist/commands/generate.d.ts.map +1 -1
- package/dist/commands/generate.js +5 -1
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/hooks.d.ts +12 -0
- package/dist/commands/hooks.d.ts.map +1 -0
- package/dist/commands/hooks.js +118 -0
- package/dist/commands/hooks.js.map +1 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +41 -7
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/internal.d.ts +6 -0
- package/dist/commands/internal.d.ts.map +1 -0
- package/dist/commands/internal.js +22 -0
- package/dist/commands/internal.js.map +1 -0
- package/dist/commands/link-helpers.d.ts.map +1 -1
- package/dist/commands/link-helpers.js +8 -2
- package/dist/commands/link-helpers.js.map +1 -1
- package/dist/commands/login.d.ts +7 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +110 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/push.d.ts.map +1 -1
- package/dist/commands/push.js +110 -7
- package/dist/commands/push.js.map +1 -1
- package/dist/commands/self-update.d.ts +7 -0
- package/dist/commands/self-update.d.ts.map +1 -1
- package/dist/commands/self-update.js +18 -11
- package/dist/commands/self-update.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +18 -3
- package/dist/config.js.map +1 -1
- package/dist/db-preflight.d.ts +78 -0
- package/dist/db-preflight.d.ts.map +1 -0
- package/dist/db-preflight.js +452 -0
- package/dist/db-preflight.js.map +1 -0
- package/dist/dev-compose.d.ts +1 -1
- package/dist/dev-compose.d.ts.map +1 -1
- package/dist/dev-compose.js +127 -72
- package/dist/dev-compose.js.map +1 -1
- package/dist/env-file.d.ts +40 -2
- package/dist/env-file.d.ts.map +1 -1
- package/dist/env-file.js +132 -11
- package/dist/env-file.js.map +1 -1
- package/dist/field-masking-tier.d.ts +50 -0
- package/dist/field-masking-tier.d.ts.map +1 -0
- package/dist/field-masking-tier.js +91 -0
- package/dist/field-masking-tier.js.map +1 -0
- package/dist/functions-deno-types.d.ts +24 -0
- package/dist/functions-deno-types.d.ts.map +1 -0
- package/dist/functions-deno-types.js +155 -0
- package/dist/functions-deno-types.js.map +1 -0
- package/dist/hook-upload.d.ts +30 -0
- package/dist/hook-upload.d.ts.map +1 -0
- package/dist/hook-upload.js +86 -0
- package/dist/hook-upload.js.map +1 -0
- package/dist/hooks-generator.d.ts +8 -0
- package/dist/hooks-generator.d.ts.map +1 -0
- package/dist/hooks-generator.js +332 -0
- package/dist/hooks-generator.js.map +1 -0
- package/dist/link.d.ts +4 -0
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +2 -0
- package/dist/link.js.map +1 -1
- package/dist/local-secrets.d.ts +71 -0
- package/dist/local-secrets.d.ts.map +1 -0
- package/dist/local-secrets.js +100 -0
- package/dist/local-secrets.js.map +1 -0
- package/dist/model-hooks.d.ts +73 -0
- package/dist/model-hooks.d.ts.map +1 -0
- package/dist/model-hooks.js +211 -0
- package/dist/model-hooks.js.map +1 -0
- package/dist/postgres-ctl.d.ts +11 -0
- package/dist/postgres-ctl.d.ts.map +1 -1
- package/dist/postgres-ctl.js +25 -2
- package/dist/postgres-ctl.js.map +1 -1
- package/dist/project-config.d.ts +121 -1
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +150 -1
- package/dist/project-config.js.map +1 -1
- package/dist/resolve-target.d.ts +4 -0
- package/dist/resolve-target.d.ts.map +1 -1
- package/dist/resolve-target.js +69 -73
- package/dist/resolve-target.js.map +1 -1
- package/dist/schema-ast-v2.d.ts +2 -1
- package/dist/schema-ast-v2.d.ts.map +1 -1
- package/dist/schema-ast-v2.js +4 -2
- package/dist/schema-ast-v2.js.map +1 -1
- package/dist/schema-push-lock.d.ts.map +1 -1
- package/dist/schema-push-lock.js +43 -16
- package/dist/schema-push-lock.js.map +1 -1
- package/dist/self-host-compose.d.ts +24 -0
- package/dist/self-host-compose.d.ts.map +1 -1
- package/dist/self-host-compose.js +301 -69
- package/dist/self-host-compose.js.map +1 -1
- package/dist/service-role-check.d.ts +21 -0
- package/dist/service-role-check.d.ts.map +1 -0
- package/dist/service-role-check.js +85 -0
- package/dist/service-role-check.js.map +1 -0
- package/dist/target-client.d.ts +17 -0
- package/dist/target-client.d.ts.map +1 -1
- package/dist/target-client.js +69 -17
- package/dist/target-client.js.map +1 -1
- package/dist/type-extractor.d.ts.map +1 -1
- package/dist/type-extractor.js +736 -32
- package/dist/type-extractor.js.map +1 -1
- package/dist/ui/runtime/command-chrome.js +1 -1
- package/dist/ui/runtime/command-chrome.js.map +1 -1
- package/dist/ui/runtime/stdin-after-ink.d.ts.map +1 -1
- package/dist/ui/runtime/stdin-after-ink.js +3 -1
- package/dist/ui/runtime/stdin-after-ink.js.map +1 -1
- package/package.json +4 -1
- package/scripts/generate-homebrew-formula.mjs +121 -0
- package/src/augmentation-generator.ts +18 -5
- package/src/binary-cache.ts +47 -15
- package/src/cache-clean.ts +81 -0
- package/src/cache-pins.ts +243 -0
- package/src/cli-install-method.ts +67 -0
- package/src/cli.ts +6 -0
- package/src/cloud-credentials.ts +183 -0
- package/src/commands/admin.ts +140 -25
- package/src/commands/cache.ts +90 -75
- package/src/commands/cloud.ts +32 -8
- package/src/commands/db.ts +162 -1
- package/src/commands/dev.ts +57 -8
- package/src/commands/doctor.ts +69 -3
- package/src/commands/functions.ts +42 -5
- package/src/commands/generate.ts +5 -1
- package/src/commands/hooks.ts +138 -0
- package/src/commands/init.ts +42 -8
- package/src/commands/internal.ts +23 -0
- package/src/commands/link-helpers.ts +9 -2
- package/src/commands/login.ts +127 -0
- package/src/commands/push.ts +124 -7
- package/src/commands/self-update.ts +85 -13
- package/src/config.ts +22 -3
- package/src/db-preflight.ts +575 -0
- package/src/dev-compose.ts +142 -73
- package/src/env-file.ts +157 -11
- package/src/field-masking-tier.ts +107 -0
- package/src/functions-deno-types.ts +188 -0
- package/src/hook-upload.ts +107 -0
- package/src/hooks-generator.ts +352 -0
- package/src/link.ts +7 -0
- package/src/local-secrets.ts +104 -0
- package/src/model-hooks.ts +260 -0
- package/src/postgres-ctl.ts +29 -2
- package/src/project-config.ts +236 -2
- package/src/resolve-target.ts +113 -68
- package/src/schema-ast-v2.ts +5 -2
- package/src/schema-push-lock.ts +56 -17
- package/src/self-host-compose.ts +344 -68
- package/src/service-role-check.ts +111 -0
- package/src/target-client.ts +105 -18
- package/src/type-extractor.ts +883 -28
- package/src/ui/runtime/command-chrome.ts +1 -1
- package/src/ui/runtime/stdin-after-ink.ts +3 -1
- package/tests/access-composition.test.ts +667 -0
- package/tests/admin-studio-membership.test.ts +121 -0
- package/tests/api-schemas.test.ts +83 -0
- package/tests/archive-name-alias.test.ts +42 -0
- package/tests/augmentation-generator.test.ts +28 -0
- package/tests/cache-clean.test.ts +206 -0
- package/tests/cli-help.test.ts +3 -0
- package/tests/cli-install-method.test.ts +66 -0
- package/tests/command-chrome-coverage.test.ts +31 -26
- package/tests/command-chrome-wrap.test.ts +1 -0
- package/tests/db-preflight.test.ts +72 -0
- package/tests/doctor-render.test.ts +62 -0
- package/tests/doctor-service-role.test.ts +55 -0
- package/tests/env-file.test.ts +121 -0
- package/tests/external-database-compose.test.ts +184 -0
- package/tests/external-database-config.test.ts +154 -0
- package/tests/field-masking-tier.test.ts +184 -0
- package/tests/functions-deno-types.test.ts +197 -0
- package/tests/homebrew-formula.test.ts +58 -0
- package/tests/hook-upload.test.ts +125 -0
- package/tests/hooks-generator.test.ts +212 -0
- package/tests/init.test.ts +3 -0
- package/tests/local-secrets.test.ts +92 -0
- package/tests/model-hooks.test.ts +322 -0
- package/tests/runtime-contract.test.ts +113 -1
- package/tests/service-role-check.test.ts +109 -0
- package/tests/service-role-routes.test.ts +51 -0
- package/tests/target-client-refresh.test.ts +94 -0
- package/tests/type-extractor.test.ts +187 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/tests/engine-distribution.test.ts +0 -418
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export interface DeclaredHook {
|
|
2
|
+
model: string;
|
|
3
|
+
event: string;
|
|
4
|
+
function: string;
|
|
5
|
+
}
|
|
6
|
+
/** Every hook declared across the schema, in a stable order for reporting. */
|
|
7
|
+
export declare function declaredHooks(ast: unknown): DeclaredHook[];
|
|
8
|
+
/**
|
|
9
|
+
* Lines describing every hook whose function is missing, empty when all resolve.
|
|
10
|
+
*
|
|
11
|
+
* Returns the message rather than throwing so the caller decides how to fail: `push` stops, while
|
|
12
|
+
* `doctor` can report several problems at once.
|
|
13
|
+
*/
|
|
14
|
+
export declare function validateModelHooks(ast: unknown, functionsDir: string, cwd: string): string[];
|
|
15
|
+
/**
|
|
16
|
+
* Write `functions/_supatype/hooks.ts`, or remove a stale one when no hooks remain.
|
|
17
|
+
*
|
|
18
|
+
* Removal matters as much as writing: deleting the last hook from a schema should leave no typed
|
|
19
|
+
* module behind claiming tables are hooked, and a handler importing it should start failing to
|
|
20
|
+
* compile rather than sitting there dead.
|
|
21
|
+
*
|
|
22
|
+
* Returns the project-relative path written, or null when there was nothing to write.
|
|
23
|
+
*/
|
|
24
|
+
export declare function writeHooksModule(cwd: string, functionsDir: string, ast: unknown): string | null;
|
|
25
|
+
/** Per-table hook config, in the shape `proxy.RouteManifest` reads. */
|
|
26
|
+
export interface ManifestHookEntry {
|
|
27
|
+
function: string;
|
|
28
|
+
timeout?: number;
|
|
29
|
+
onUnavailable?: "reject" | "log";
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The hook map for `.supatype/manifest.json`, keyed by **table name** — because that is what the
|
|
33
|
+
* server matches a request path against, not the model name.
|
|
34
|
+
*
|
|
35
|
+
* Defaults are resolved here rather than in the server: one place decides that a `before*` hook
|
|
36
|
+
* rejects when it cannot be reached and an `after*` hook only logs, so the two implementations
|
|
37
|
+
* cannot disagree about the safe direction.
|
|
38
|
+
*/
|
|
39
|
+
export declare function manifestHooks(ast: unknown): Record<string, Record<string, ManifestHookEntry>>;
|
|
40
|
+
/** Well below the 10s edge-function ceiling, so a hung hook fails fast instead of holding a slot. */
|
|
41
|
+
export declare const DEFAULT_HOOK_TIMEOUT_MS = 2000;
|
|
42
|
+
/**
|
|
43
|
+
* Merge the hook map into an existing `.supatype/manifest.json`.
|
|
44
|
+
*
|
|
45
|
+
* **Only updates a manifest that is already there.** Creating one from scratch here would be a
|
|
46
|
+
* hazard: `functions_enabled` is a plain bool on the server's side, so a manifest carrying only
|
|
47
|
+
* hooks would read as functions *disabled* — the exact defect this repo fixed a commit ago, arriving
|
|
48
|
+
* by a different door. The compose path owns creation; this owns one key.
|
|
49
|
+
*
|
|
50
|
+
* Returns true when the file was rewritten.
|
|
51
|
+
*/
|
|
52
|
+
export declare function syncManifestHooks(cwd: string, ast: unknown): boolean;
|
|
53
|
+
export interface HooksReport {
|
|
54
|
+
declared: DeclaredHook[];
|
|
55
|
+
/** Hooks whose function directory is missing. */
|
|
56
|
+
missing: DeclaredHook[];
|
|
57
|
+
/** True when a manifest exists and says the functions subsystem is off. */
|
|
58
|
+
functionsDisabled: boolean;
|
|
59
|
+
/** True when a manifest exists but carries no hook map, so the server has nothing to call. */
|
|
60
|
+
mapMissing: boolean;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* What `supatype doctor` needs to answer "will my hooks actually run?".
|
|
64
|
+
*
|
|
65
|
+
* Local facts only — the schema, the functions on disk, and the manifest the server reads. No probe
|
|
66
|
+
* of a running worker, so the answer is the same whether or not the stack is up, and a report that
|
|
67
|
+
* needs a stack is a report nobody runs before deploying.
|
|
68
|
+
*
|
|
69
|
+
* The case worth catching: hooks declared while `functions_enabled` is false. Nothing fails, no error
|
|
70
|
+
* appears, and every hook silently never fires.
|
|
71
|
+
*/
|
|
72
|
+
export declare function hooksReport(cwd: string, functionsDir: string, ast: unknown): HooksReport;
|
|
73
|
+
//# sourceMappingURL=model-hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-hooks.d.ts","sourceRoot":"","sources":["../src/model-hooks.ts"],"names":[],"mappings":"AAcA,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,8EAA8E;AAC9E,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,YAAY,EAAE,CAqB1D;AAeD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,OAAO,EACZ,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,MAAM,GACV,MAAM,EAAE,CAoBV;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAa/F;AAED,uEAAuE;AACvE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,aAAa,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAA;CACjC;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAoC7F;AAED,qGAAqG;AACrG,eAAO,MAAM,uBAAuB,OAAO,CAAA;AAE3C;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,OAAO,CAwBpE;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,YAAY,EAAE,CAAA;IACxB,iDAAiD;IACjD,OAAO,EAAE,YAAY,EAAE,CAAA;IACvB,2EAA2E;IAC3E,iBAAiB,EAAE,OAAO,CAAA;IAC1B,8FAA8F;IAC9F,UAAU,EAAE,OAAO,CAAA;CACpB;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,WAAW,CAkCxF"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate the lifecycle hooks a schema declares against the functions that exist.
|
|
3
|
+
*
|
|
4
|
+
* A hook names a function directory. If the name is wrong, the honest failure is at push time with
|
|
5
|
+
* the path we searched — not at runtime, where the symptom is a hook that never fires and a write
|
|
6
|
+
* that quietly succeeds unvalidated. That silence is the whole reason this check exists.
|
|
7
|
+
*
|
|
8
|
+
* Kept out of the extractor on purpose: resolving the functions directory needs the project config,
|
|
9
|
+
* and the extractor is a leaf that reads type syntax and nothing else.
|
|
10
|
+
*/
|
|
11
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
12
|
+
import { join, relative } from "node:path";
|
|
13
|
+
import { generateHooksModule } from "./hooks-generator.js";
|
|
14
|
+
/** Every hook declared across the schema, in a stable order for reporting. */
|
|
15
|
+
export function declaredHooks(ast) {
|
|
16
|
+
const models = ast?.models;
|
|
17
|
+
if (!Array.isArray(models))
|
|
18
|
+
return [];
|
|
19
|
+
const out = [];
|
|
20
|
+
for (const model of models) {
|
|
21
|
+
const shaped = model;
|
|
22
|
+
const hooks = shaped.annotations?.platform?.hooks;
|
|
23
|
+
if (typeof hooks !== "object" || hooks === null)
|
|
24
|
+
continue;
|
|
25
|
+
for (const [event, value] of Object.entries(hooks)) {
|
|
26
|
+
const fn = value?.function;
|
|
27
|
+
if (typeof fn === "string" && fn.length > 0) {
|
|
28
|
+
out.push({ model: shaped.name ?? "?", event, function: fn });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return out.sort((a, b) => `${a.model}.${a.event}`.localeCompare(`${b.model}.${b.event}`));
|
|
33
|
+
}
|
|
34
|
+
/** Function directory names available to be used as hooks. */
|
|
35
|
+
function availableFunctions(functionsDir) {
|
|
36
|
+
if (!existsSync(functionsDir))
|
|
37
|
+
return [];
|
|
38
|
+
return readdirSync(functionsDir)
|
|
39
|
+
.filter((entry) => !entry.startsWith("_") && !entry.startsWith("."))
|
|
40
|
+
.filter((entry) => {
|
|
41
|
+
const full = join(functionsDir, entry);
|
|
42
|
+
// A function is a directory with an index.ts, matching how the worker discovers them.
|
|
43
|
+
return statSync(full).isDirectory() && existsSync(join(full, "index.ts"));
|
|
44
|
+
})
|
|
45
|
+
.sort();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Lines describing every hook whose function is missing, empty when all resolve.
|
|
49
|
+
*
|
|
50
|
+
* Returns the message rather than throwing so the caller decides how to fail: `push` stops, while
|
|
51
|
+
* `doctor` can report several problems at once.
|
|
52
|
+
*/
|
|
53
|
+
export function validateModelHooks(ast, functionsDir, cwd) {
|
|
54
|
+
const hooks = declaredHooks(ast);
|
|
55
|
+
if (hooks.length === 0)
|
|
56
|
+
return [];
|
|
57
|
+
const available = availableFunctions(functionsDir);
|
|
58
|
+
const known = new Set(available);
|
|
59
|
+
const missing = hooks.filter((hook) => !known.has(hook.function));
|
|
60
|
+
if (missing.length === 0)
|
|
61
|
+
return [];
|
|
62
|
+
const where = relative(cwd, functionsDir) || functionsDir;
|
|
63
|
+
const lines = missing.map((hook) => ` ${hook.model}.${hook.event} → "${hook.function}" (no ${where}/${hook.function}/index.ts)`);
|
|
64
|
+
lines.push("");
|
|
65
|
+
lines.push(available.length > 0
|
|
66
|
+
? `Hooks found in ${where}: ${available.join(", ")}`
|
|
67
|
+
: `No hooks found in ${where}. Create one with: supatype hooks new <name>`);
|
|
68
|
+
return lines;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Write `functions/_supatype/hooks.ts`, or remove a stale one when no hooks remain.
|
|
72
|
+
*
|
|
73
|
+
* Removal matters as much as writing: deleting the last hook from a schema should leave no typed
|
|
74
|
+
* module behind claiming tables are hooked, and a handler importing it should start failing to
|
|
75
|
+
* compile rather than sitting there dead.
|
|
76
|
+
*
|
|
77
|
+
* Returns the project-relative path written, or null when there was nothing to write.
|
|
78
|
+
*/
|
|
79
|
+
export function writeHooksModule(cwd, functionsDir, ast) {
|
|
80
|
+
const module = generateHooksModule(ast);
|
|
81
|
+
const dir = join(functionsDir, "_supatype");
|
|
82
|
+
const file = join(dir, "hooks.ts");
|
|
83
|
+
if (module === null) {
|
|
84
|
+
if (existsSync(file))
|
|
85
|
+
rmSync(file, { force: true });
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
mkdirSync(dir, { recursive: true });
|
|
89
|
+
writeFileSync(file, module, "utf8");
|
|
90
|
+
return relative(cwd, file) || file;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The hook map for `.supatype/manifest.json`, keyed by **table name** — because that is what the
|
|
94
|
+
* server matches a request path against, not the model name.
|
|
95
|
+
*
|
|
96
|
+
* Defaults are resolved here rather than in the server: one place decides that a `before*` hook
|
|
97
|
+
* rejects when it cannot be reached and an `after*` hook only logs, so the two implementations
|
|
98
|
+
* cannot disagree about the safe direction.
|
|
99
|
+
*/
|
|
100
|
+
export function manifestHooks(ast) {
|
|
101
|
+
const models = ast?.models;
|
|
102
|
+
if (!Array.isArray(models))
|
|
103
|
+
return {};
|
|
104
|
+
const out = {};
|
|
105
|
+
for (const model of models) {
|
|
106
|
+
const shaped = model;
|
|
107
|
+
const table = shaped.annotations?.db?.tableName;
|
|
108
|
+
const hooks = shaped.annotations?.platform?.hooks;
|
|
109
|
+
if (typeof table !== "string" || table.length === 0)
|
|
110
|
+
continue;
|
|
111
|
+
if (typeof hooks !== "object" || hooks === null)
|
|
112
|
+
continue;
|
|
113
|
+
const entries = {};
|
|
114
|
+
for (const [event, value] of Object.entries(hooks)) {
|
|
115
|
+
const fn = value?.function;
|
|
116
|
+
if (typeof fn !== "string" || fn.length === 0)
|
|
117
|
+
continue;
|
|
118
|
+
const onUnavailable = value.onUnavailable === "reject" || value.onUnavailable === "log"
|
|
119
|
+
? value.onUnavailable
|
|
120
|
+
: event.startsWith("before")
|
|
121
|
+
? "reject"
|
|
122
|
+
: "log";
|
|
123
|
+
entries[event] = {
|
|
124
|
+
function: fn,
|
|
125
|
+
timeout: typeof value.timeout === "number" ? value.timeout : DEFAULT_HOOK_TIMEOUT_MS,
|
|
126
|
+
onUnavailable,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
if (Object.keys(entries).length > 0)
|
|
130
|
+
out[table] = entries;
|
|
131
|
+
}
|
|
132
|
+
return out;
|
|
133
|
+
}
|
|
134
|
+
/** Well below the 10s edge-function ceiling, so a hung hook fails fast instead of holding a slot. */
|
|
135
|
+
export const DEFAULT_HOOK_TIMEOUT_MS = 2000;
|
|
136
|
+
/**
|
|
137
|
+
* Merge the hook map into an existing `.supatype/manifest.json`.
|
|
138
|
+
*
|
|
139
|
+
* **Only updates a manifest that is already there.** Creating one from scratch here would be a
|
|
140
|
+
* hazard: `functions_enabled` is a plain bool on the server's side, so a manifest carrying only
|
|
141
|
+
* hooks would read as functions *disabled* — the exact defect this repo fixed a commit ago, arriving
|
|
142
|
+
* by a different door. The compose path owns creation; this owns one key.
|
|
143
|
+
*
|
|
144
|
+
* Returns true when the file was rewritten.
|
|
145
|
+
*/
|
|
146
|
+
export function syncManifestHooks(cwd, ast) {
|
|
147
|
+
const manifestPath = join(cwd, ".supatype", "manifest.json");
|
|
148
|
+
if (!existsSync(manifestPath))
|
|
149
|
+
return false;
|
|
150
|
+
let parsed;
|
|
151
|
+
try {
|
|
152
|
+
parsed = JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
return false; // Malformed: the server will complain about it far more clearly than we can here.
|
|
156
|
+
}
|
|
157
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
158
|
+
return false;
|
|
159
|
+
const hooks = manifestHooks(ast);
|
|
160
|
+
const next = JSON.stringify(hooks);
|
|
161
|
+
const current = JSON.stringify(parsed["hooks"] ?? {});
|
|
162
|
+
if (next === current)
|
|
163
|
+
return false;
|
|
164
|
+
if (Object.keys(hooks).length === 0) {
|
|
165
|
+
delete parsed["hooks"];
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
parsed["hooks"] = hooks;
|
|
169
|
+
}
|
|
170
|
+
writeFileSync(manifestPath, `${JSON.stringify(parsed, null, 2)}\n`, "utf8");
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* What `supatype doctor` needs to answer "will my hooks actually run?".
|
|
175
|
+
*
|
|
176
|
+
* Local facts only — the schema, the functions on disk, and the manifest the server reads. No probe
|
|
177
|
+
* of a running worker, so the answer is the same whether or not the stack is up, and a report that
|
|
178
|
+
* needs a stack is a report nobody runs before deploying.
|
|
179
|
+
*
|
|
180
|
+
* The case worth catching: hooks declared while `functions_enabled` is false. Nothing fails, no error
|
|
181
|
+
* appears, and every hook silently never fires.
|
|
182
|
+
*/
|
|
183
|
+
export function hooksReport(cwd, functionsDir, ast) {
|
|
184
|
+
const declared = declaredHooks(ast);
|
|
185
|
+
const manifestPath = join(cwd, ".supatype", "manifest.json");
|
|
186
|
+
let functionsDisabled = false;
|
|
187
|
+
let mapMissing = false;
|
|
188
|
+
if (declared.length > 0 && existsSync(manifestPath)) {
|
|
189
|
+
try {
|
|
190
|
+
const parsed = JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
191
|
+
functionsDisabled = parsed["functions_enabled"] === false;
|
|
192
|
+
mapMissing = parsed["hooks"] === undefined;
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
// Unparseable: the server reports that far better than a doctor line could.
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const known = new Set(existsSync(functionsDir)
|
|
199
|
+
? readdirSync(functionsDir).filter((entry) => !entry.startsWith("_") &&
|
|
200
|
+
!entry.startsWith(".") &&
|
|
201
|
+
statSync(join(functionsDir, entry)).isDirectory() &&
|
|
202
|
+
existsSync(join(functionsDir, entry, "index.ts")))
|
|
203
|
+
: []);
|
|
204
|
+
return {
|
|
205
|
+
declared,
|
|
206
|
+
missing: declared.filter((hook) => !known.has(hook.function)),
|
|
207
|
+
functionsDisabled,
|
|
208
|
+
mapMissing,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=model-hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-hooks.js","sourceRoot":"","sources":["../src/model-hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC3G,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAQ1D,8EAA8E;AAC9E,MAAM,UAAU,aAAa,CAAC,GAAY;IACxC,MAAM,MAAM,GAAI,GAA8B,EAAE,MAAM,CAAA;IACtD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,OAAO,EAAE,CAAA;IAErC,MAAM,GAAG,GAAmB,EAAE,CAAA;IAC9B,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,MAAM,GAAG,KAGd,CAAA;QACD,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,EAAE,QAAQ,EAAE,KAAK,CA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AAC,YAAY,CAAC,EAAE,CAAC;QACpD,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,YAAY,EAAE,MAAM,CAAC,CAA4B,CAAA;YACxF,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,KAAK,KAAK,CAAA;YACzD,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,SAAS,CAAA;QAC5C,CAAC;QAAC,MAAM,CAAC;YACP,4EAA4E;QAC9E,CAAC;IACH,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,GAAG,CACnB,UAAU,CAAC,YAAY,CAAC;QACtB,CAAC,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,MAAM,CAC9B,CAAC,KAAK,EAAE,EAAE,CACR,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;YACtB,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;YACtB,QAAQ,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,CAAC,WAAW,EAAE;YACjD,UAAU,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CACpD;QACH,CAAC,CAAC,EAAE,CACP,CAAA;IAED,OAAO;QACL,QAAQ;QACR,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC7D,iBAAiB;QACjB,UAAU;KACX,CAAA;AACH,CAAC"}
|
package/dist/postgres-ctl.d.ts
CHANGED
|
@@ -26,6 +26,17 @@ export declare function initdb(opts: PgOptions): void;
|
|
|
26
26
|
* Start Postgres using pg_ctl.
|
|
27
27
|
* Returns immediately once pg_ctl has handed off to the server process.
|
|
28
28
|
*/
|
|
29
|
+
/**
|
|
30
|
+
* Whether a native Postgres install carries the masking library.
|
|
31
|
+
*
|
|
32
|
+
* Asked of the filesystem rather than assumed from the provider, because a developer with an archive
|
|
33
|
+
* downloaded before the library was bundled has a native Postgres *without* it. Assuming otherwise
|
|
34
|
+
* would select tier 1 and their next push would be refused by the capability probe.
|
|
35
|
+
*
|
|
36
|
+
* Two layouts: Linux and macOS put extension libraries in `lib/`, the Windows archive in
|
|
37
|
+
* `lib/postgresql/`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function nativeMaskLibraryPresent(pgBinDir: string | null | undefined): boolean;
|
|
29
40
|
export declare function start(opts: PgOptions): void;
|
|
30
41
|
/**
|
|
31
42
|
* Stop Postgres using pg_ctl (fast mode).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-ctl.d.ts","sourceRoot":"","sources":["../src/postgres-ctl.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,MAAM,WAAW,SAAS;IACxB,2EAA2E;IAC3E,QAAQ,EAAE,MAAM,CAAA;IAChB,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAA;IACf,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAA;IACZ,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,QAAQ,EAAE,MAAM,EAChB,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAC3C,MAAM,CAAC,UAAU,CAWnB;AAMD;;;GAGG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,CAgB5C;AAMD;;;GAGG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"postgres-ctl.d.ts","sourceRoot":"","sources":["../src/postgres-ctl.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,MAAM,WAAW,SAAS;IACxB,2EAA2E;IAC3E,QAAQ,EAAE,MAAM,CAAA;IAChB,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAA;IACf,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAA;IACZ,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,QAAQ,EAAE,MAAM,EAChB,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAC3C,MAAM,CAAC,UAAU,CAWnB;AAMD;;;GAGG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,CAgB5C;AAMD;;;GAGG;AACH;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAOrF;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,CA4B3C;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,CAS1C;AAMD;;;;GAIG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBlF;AAMD;;GAEG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAahE"}
|
package/dist/postgres-ctl.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { spawnSync } from "node:child_process";
|
|
6
6
|
import { existsSync, mkdirSync } from "node:fs";
|
|
7
|
-
import { dirname, join } from "node:path";
|
|
7
|
+
import { dirname, join, resolve as resolvePath } from "node:path";
|
|
8
8
|
/**
|
|
9
9
|
* Native Postgres bundles are built with prefix /usr/local/supatype-pg; dyld/ld
|
|
10
10
|
* must load libpq and friends from the extracted lib/ next to bin/.
|
|
@@ -51,14 +51,37 @@ export function initdb(opts) {
|
|
|
51
51
|
* Start Postgres using pg_ctl.
|
|
52
52
|
* Returns immediately once pg_ctl has handed off to the server process.
|
|
53
53
|
*/
|
|
54
|
+
/**
|
|
55
|
+
* Whether a native Postgres install carries the masking library.
|
|
56
|
+
*
|
|
57
|
+
* Asked of the filesystem rather than assumed from the provider, because a developer with an archive
|
|
58
|
+
* downloaded before the library was bundled has a native Postgres *without* it. Assuming otherwise
|
|
59
|
+
* would select tier 1 and their next push would be refused by the capability probe.
|
|
60
|
+
*
|
|
61
|
+
* Two layouts: Linux and macOS put extension libraries in `lib/`, the Windows archive in
|
|
62
|
+
* `lib/postgresql/`.
|
|
63
|
+
*/
|
|
64
|
+
export function nativeMaskLibraryPresent(pgBinDir) {
|
|
65
|
+
if (!pgBinDir)
|
|
66
|
+
return false;
|
|
67
|
+
const prefix = resolvePath(pgBinDir, "..");
|
|
68
|
+
return ["supatype_mask.so", "supatype_mask.dylib", "supatype_mask.dll"].some((lib) => existsSync(join(prefix, "lib", lib)) || existsSync(join(prefix, "lib", "postgresql", lib)));
|
|
69
|
+
}
|
|
54
70
|
export function start(opts) {
|
|
55
71
|
const bin = pgBin(opts.pgBinDir, "pg_ctl");
|
|
56
72
|
const logPath = opts.logPath ?? join(opts.dataDir, "postgres.log");
|
|
73
|
+
// `supatype_mask` is a planner hook, so it has to be preloaded — `CREATE EXTENSION` alone does
|
|
74
|
+
// nothing without it. Only when the archive actually carries the library: an install downloaded
|
|
75
|
+
// before it was bundled would fail to start with "could not access file".
|
|
76
|
+
//
|
|
77
|
+
// Native Postgres was started with no preloaded libraries at all until now, which is why field
|
|
78
|
+
// rules could not be enforced on the default `supatype dev`.
|
|
79
|
+
const preload = nativeMaskLibraryPresent(opts.pgBinDir) ? " -c shared_preload_libraries=supatype_mask" : "";
|
|
57
80
|
const args = [
|
|
58
81
|
"start",
|
|
59
82
|
"-D", opts.dataDir,
|
|
60
83
|
"-l", logPath,
|
|
61
|
-
"-o", `-p ${opts.port}`,
|
|
84
|
+
"-o", `-p ${opts.port}${preload}`,
|
|
62
85
|
"--wait",
|
|
63
86
|
];
|
|
64
87
|
const result = spawnSync(bin, args, {
|
package/dist/postgres-ctl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-ctl.js","sourceRoot":"","sources":["../src/postgres-ctl.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"postgres-ctl.js","sourceRoot":"","sources":["../src/postgres-ctl.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,WAAW,CAAA;AAajE;;;GAGG;AACH,MAAM,UAAU,UAAU,CACxB,QAAgB,EAChB,WAA4B,OAAO,CAAC,QAAQ;IAE5C,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,CAAA;IAC7C,MAAM,GAAG,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,EAAuB,CAAA;IACnD,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC1B,MAAM,IAAI,GAAG,GAAG,CAAC,iBAAiB,IAAI,EAAE,CAAA;QACxC,GAAG,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,MAAM,CAAA;IAC7D,CAAC;SAAM,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;QAChC,MAAM,IAAI,GAAG,GAAG,CAAC,eAAe,IAAI,EAAE,CAAA;QACtC,GAAG,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC,CAAC,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AAC,IAAY;IAC5C,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,CAAA;IACjD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,MAAM,GAAG,YAAY,EAAE,CAAA;QAC7B,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,GAA0B,EAAE,EAAE;YAClD,sFAAsF;YACtF,OAAO,CAAC,GAAG,CAAC,IAAI,KAAK,YAAY,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAA;QAC7D,CAAC,CAAC,CAAA;QACF,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE;YAC5B,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;QACpC,CAAC,CAAC,CAAA;QACF,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,CAAA;IAClC,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAA;AAC1D,CAAC;AAED,6EAA6E;AAC7E,SAAS,KAAK,CAAC,MAAc,EAAE,IAAY;IACzC,OAAO,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;AAC1E,CAAC"}
|
package/dist/project-config.d.ts
CHANGED
|
@@ -24,8 +24,38 @@ export interface SupatypeProjectConfig {
|
|
|
24
24
|
* Database backend.
|
|
25
25
|
* "native" = supatype manages a native Postgres binary (downloaded from CDN).
|
|
26
26
|
* "docker" = supatype runs supatype/postgres via Docker (includes all extensions).
|
|
27
|
+
*
|
|
28
|
+
* Omitted when `external` is set — there is no backend for Supatype to choose.
|
|
27
29
|
*/
|
|
28
|
-
provider
|
|
30
|
+
provider?: "native" | "docker";
|
|
31
|
+
/**
|
|
32
|
+
* Point the stack at a Postgres that already exists, instead of provisioning one.
|
|
33
|
+
*
|
|
34
|
+
* The presence of this block is the switch: with it, no `db` service is generated and every
|
|
35
|
+
* service connects here. Deliberately not an overload of `connection`, which means something
|
|
36
|
+
* narrower (a DSN for CLI commands) and would become the third setting meaning two things.
|
|
37
|
+
*
|
|
38
|
+
* **Self-host only.** On the cloud path the database is part of what is being provided, so the
|
|
39
|
+
* block is rejected rather than ignored.
|
|
40
|
+
*/
|
|
41
|
+
external?: {
|
|
42
|
+
/**
|
|
43
|
+
* Postgres URL for every service in the stack.
|
|
44
|
+
*
|
|
45
|
+
* The role in it owns the schema and runs migrations. PostgREST connects as `authenticator`
|
|
46
|
+
* separately — see `supatype db check`, which reports what this database is missing.
|
|
47
|
+
*/
|
|
48
|
+
url: string;
|
|
49
|
+
/**
|
|
50
|
+
* Force realtime off.
|
|
51
|
+
*
|
|
52
|
+
* Realtime needs logical replication (`wal_level = logical`, a replication slot, and
|
|
53
|
+
* `wal2json`), which a managed provider may not offer. Left unset, the stack probes for the
|
|
54
|
+
* capability and records the answer, so this is only for overriding a probe that says yes when
|
|
55
|
+
* you would rather it did not run.
|
|
56
|
+
*/
|
|
57
|
+
realtime?: boolean;
|
|
58
|
+
};
|
|
29
59
|
/**
|
|
30
60
|
* Directory where Postgres stores its data files (provider=native).
|
|
31
61
|
* Defaults to ~/.supatype/projects/{name}/data when omitted.
|
|
@@ -175,10 +205,36 @@ export interface SupatypeProjectConfig {
|
|
|
175
205
|
path?: string;
|
|
176
206
|
/** Postgres schema name. Defaults to "public". */
|
|
177
207
|
pg_schema?: string;
|
|
208
|
+
/**
|
|
209
|
+
* Schemas the REST API exposes, in order (`PGRST_DB_SCHEMA`).
|
|
210
|
+
*
|
|
211
|
+
* Defaults to `pg_schema` plus the ones the stack needs for itself — `supatype` for Studio's
|
|
212
|
+
* views, `graphql_public`, `auth` — so setting `pg_schema` alone does the sensible thing.
|
|
213
|
+
*
|
|
214
|
+
* It used to be a hardcoded literal, which meant choosing a non-`public` `pg_schema` gave you
|
|
215
|
+
* a correct push and an API that answered `PGRST106` for everything: the engine had moved and
|
|
216
|
+
* PostgREST had not been told. State this explicitly when you need a different set — an extra
|
|
217
|
+
* schema of your own, or to stop exposing one.
|
|
218
|
+
*/
|
|
219
|
+
api_schemas?: readonly string[];
|
|
178
220
|
};
|
|
179
221
|
functions?: {
|
|
180
222
|
/** Path to edge functions directory, relative to `supatype.root` when not absolute. */
|
|
181
223
|
path?: string;
|
|
224
|
+
/**
|
|
225
|
+
* **Public functions** allowed to see the service-role key, which reads and writes past every
|
|
226
|
+
* access rule.
|
|
227
|
+
*
|
|
228
|
+
* Empty by default, and that default is the point: a function is a public endpoint anyone holding
|
|
229
|
+
* the anon key can invoke, so an ambient admin credential made every one of them able to read the
|
|
230
|
+
* whole database. Naming one here is a reviewable line in a diff; ambient privilege is not.
|
|
231
|
+
*
|
|
232
|
+
* **Model hooks are not listed here and do not need to be.** A hook is procedural: only the API
|
|
233
|
+
* server calls it, around a write the caller was already permitted to make, and the gateway
|
|
234
|
+
* refuses its route from outside — so there is no attacker to withhold it from, and the trust is
|
|
235
|
+
* the same a trigger already has.
|
|
236
|
+
*/
|
|
237
|
+
serviceRole?: readonly string[];
|
|
182
238
|
};
|
|
183
239
|
output?: {
|
|
184
240
|
/** Path for generated TypeScript types. */
|
|
@@ -237,6 +293,15 @@ export declare function schemaPathFromProject(cfg: SupatypeProjectConfig, cwd: s
|
|
|
237
293
|
export declare function projectRootFromConfig(cfg: SupatypeProjectConfig, cwd: string): string;
|
|
238
294
|
/** Candidate functions directories in lookup order. */
|
|
239
295
|
export declare function functionsPathCandidatesFromProject(cfg: SupatypeProjectConfig, cwd: string): string[];
|
|
296
|
+
/**
|
|
297
|
+
* Directory holding **model hooks** — procedural handlers the API calls around a write.
|
|
298
|
+
*
|
|
299
|
+
* Separate from `functions/` because the two have different trust models: a function is a public
|
|
300
|
+
* endpoint anyone with the anon key may invoke, while a hook is only ever called by the server. One
|
|
301
|
+
* worker serves both, and the gateway refuses the hook namespace from outside — so keeping them in
|
|
302
|
+
* separate directories is what makes that boundary structural rather than a list to maintain.
|
|
303
|
+
*/
|
|
304
|
+
export declare function hooksPathFromProject(cfg: SupatypeProjectConfig, cwd: string): string;
|
|
240
305
|
/** Preferred default functions path (used when creating new functions). */
|
|
241
306
|
export declare function preferredFunctionsPathFromProject(cfg: SupatypeProjectConfig, cwd: string): string;
|
|
242
307
|
/**
|
|
@@ -252,6 +317,18 @@ export declare function serverBaseUrl(cfg: SupatypeProjectConfig): string | unde
|
|
|
252
317
|
export declare function selfHostTlsEnabled(cfg: SupatypeProjectConfig, devLocal?: boolean): boolean;
|
|
253
318
|
/** Resolved runtime provider (`config.provider` ?? `database.provider` ?? native). */
|
|
254
319
|
export declare function resolveRuntimeProvider(cfg: SupatypeProjectConfig): "native" | "docker";
|
|
320
|
+
/**
|
|
321
|
+
* Routes entitled to the service-role key, as the worker's env expects them.
|
|
322
|
+
*
|
|
323
|
+
* Resolved here rather than in the compose template so there is one definition of the format.
|
|
324
|
+
*
|
|
325
|
+
* This does **not** check that the names exist — it cannot, since it has only the config. An earlier
|
|
326
|
+
* version of this comment claimed a typo was "visible in one place rather than silently granting
|
|
327
|
+
* nothing", which was false: nothing read the list except the two callers that turn it into an env var.
|
|
328
|
+
* `checkServiceRoleRoutes` in `service-role-check.ts` is what actually resolves the names, and `push`
|
|
329
|
+
* refuses on it.
|
|
330
|
+
*/
|
|
331
|
+
export declare function serviceRoleRoutes(cfg: SupatypeProjectConfig): string[];
|
|
255
332
|
/** Kong gateway port when `provider: docker` (self-host compose dev). */
|
|
256
333
|
export declare const COMPOSE_DEV_KONG_PORT = 18473;
|
|
257
334
|
/** The local Postgres DSN derived from project name (dev default). */
|
|
@@ -261,4 +338,47 @@ export declare function localDSN(cfg: SupatypeProjectConfig): string;
|
|
|
261
338
|
* Prefers optional `connection` in config, then `DATABASE_URL` env, then a local default DSN.
|
|
262
339
|
*/
|
|
263
340
|
export declare function connectionString(cfg: SupatypeProjectConfig): string;
|
|
341
|
+
/** True when the project points at a Postgres it does not manage. */
|
|
342
|
+
export declare function usesExternalDatabase(cfg: SupatypeProjectConfig): boolean;
|
|
343
|
+
/**
|
|
344
|
+
* The external Postgres URL, or undefined for a managed one.
|
|
345
|
+
*
|
|
346
|
+
* Ahead of `connection` and `DATABASE_URL` in [`connectionString`] on purpose: a stated external
|
|
347
|
+
* database is the whole stack's database, and a CLI command that pushed somewhere else while the
|
|
348
|
+
* services read from here would look exactly like data loss.
|
|
349
|
+
*/
|
|
350
|
+
export declare function externalDatabaseUrl(cfg: SupatypeProjectConfig): string | undefined;
|
|
351
|
+
/**
|
|
352
|
+
* Whether realtime should run.
|
|
353
|
+
*
|
|
354
|
+
* `false` only when stated. An external database that cannot support logical replication is detected
|
|
355
|
+
* rather than declared — the capability record is what Studio and `doctor` read, so an operator who
|
|
356
|
+
* has not thought about it gets a truthful answer instead of a silent default.
|
|
357
|
+
*/
|
|
358
|
+
export declare function realtimeEnabled(cfg: SupatypeProjectConfig): boolean;
|
|
359
|
+
/** The Postgres schema Supatype manages. */
|
|
360
|
+
export declare function pgSchema(cfg: SupatypeProjectConfig): string;
|
|
361
|
+
/**
|
|
362
|
+
* Schemas the stack exposes for its own sake, beyond the one Supatype manages.
|
|
363
|
+
*
|
|
364
|
+
* Dev used to omit `auth` while self-host exposed it, so the same request could work against a
|
|
365
|
+
* self-hosted stack and 404 locally. One list for both.
|
|
366
|
+
*/
|
|
367
|
+
export declare const STACK_API_SCHEMAS: readonly ["supatype", "graphql_public", "auth"];
|
|
368
|
+
/**
|
|
369
|
+
* Schemas to expose over REST, as `PGRST_DB_SCHEMA` wants them.
|
|
370
|
+
*
|
|
371
|
+
* The managed schema first, then what the stack needs for itself. Derived rather than hardcoded
|
|
372
|
+
* because the literal version silently ignored `pg_schema`: the engine would migrate into `app`
|
|
373
|
+
* while PostgREST kept serving `public`, so every request answered `PGRST106` and nothing in the
|
|
374
|
+
* output mentioned the setting that caused it.
|
|
375
|
+
*
|
|
376
|
+
* `api_schemas` replaces the whole list when stated — including the stack schemas, so dropping
|
|
377
|
+
* `supatype` from it is a supported way to stop exposing Studio's views. Order is preserved and
|
|
378
|
+
* duplicates removed: PostgREST serves the first entry as the default profile, so the managed
|
|
379
|
+
* schema has to lead.
|
|
380
|
+
*/
|
|
381
|
+
export declare function apiSchemas(cfg: SupatypeProjectConfig, tier?: "none" | "extension" | "views"): string[];
|
|
382
|
+
/** `PGRST_DB_SCHEMA` value: comma-separated, in order. */
|
|
383
|
+
export declare function apiSchemaList(cfg: SupatypeProjectConfig, tier?: "none" | "extension" | "views"): string;
|
|
264
384
|
//# sourceMappingURL=project-config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-config.d.ts","sourceRoot":"","sources":["../src/project-config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAMxD,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAC9B,QAAQ,CAAC,EAAE;QACT;;;WAGG;QACH,IAAI,CAAC,EAAE,MAAM,CAAA;KACd,CAAA;IACD,OAAO,EAAE;QACP,kEAAkE;QAClE,IAAI,EAAE,MAAM,CAAA;QACZ,wDAAwD;QACxD,GAAG,CAAC,EAAE,MAAM,CAAA;KACb,CAAA;IACD,QAAQ,EAAE;QACR
|
|
1
|
+
{"version":3,"file":"project-config.d.ts","sourceRoot":"","sources":["../src/project-config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAMxD,MAAM,WAAW,qBAAqB;IAC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