better-supabase 0.3.0 → 0.4.0
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/README.md +7 -6
- package/bin/better-supabase.js +4 -0
- package/dist/{base64-CQeB1eSf.js → base64-D2gsioCY.js} +2 -2
- package/dist/claims-BAf6c7is.js +48 -0
- package/dist/cli/_format-Cax5EsM9.js +101 -0
- package/dist/cli/bin.d.ts +1 -0
- package/dist/cli/bin.js +48 -0
- package/dist/cli/command-CK14fP91.js +502 -0
- package/dist/cli/compare-BmIWVEui.js +9 -0
- package/dist/cli/config-D9R0o1LH.js +1895 -0
- package/dist/cli/config-SSKSTUl2.js +2 -0
- package/dist/cli/db-DOBPt660.js +52 -0
- package/dist/cli/dist-B1MvLv-M.js +129 -0
- package/dist/cli/dist-CFgGknmZ.js +1112 -0
- package/dist/cli/dist-Du7VnEUG.js +621 -0
- package/dist/cli/doctor-BOym3mbL.js +2382 -0
- package/dist/cli/env-BZ0uy8XK.js +108 -0
- package/dist/cli/env-jIFUADLY.js +511 -0
- package/dist/cli/errors-4v4DTtda.js +56 -0
- package/dist/cli/fastest-levenshtein-CFN-lNDv.js +120 -0
- package/dist/cli/gen-Ccn_p90L.js +2008 -0
- package/dist/cli/gen-D5cLCULx.js +2 -0
- package/dist/cli/index.d.ts +493 -0
- package/dist/cli/index.js +184 -0
- package/dist/cli/init-ClnxRYBF.js +550 -0
- package/dist/cli/introspect-DxqfkVIv.js +81 -0
- package/dist/cli/io-k41_z-jT.js +24 -0
- package/dist/cli/json5-ChRycquj.js +787 -0
- package/dist/cli/jsonc-BUniUpOk.js +2 -0
- package/dist/cli/jsonc-D5Fu67jw.js +45 -0
- package/dist/cli/keys-ByKHnvP9.js +83 -0
- package/dist/cli/ohash-D7bG_EOb.js +277 -0
- package/dist/cli/openapi-8WHjxiTJ.js +66 -0
- package/dist/cli/project-B_GeXyHh.js +70 -0
- package/dist/cli/prompts-BNcNfAve.js +1142 -0
- package/dist/cli/prompts-BTYQGunc.js +2 -0
- package/dist/cli/read-sets-CMa29t9a.js +971 -0
- package/dist/cli/rolldown-runtime-BPOCksWG.js +24 -0
- package/dist/cli/run-CP20LKk_.js +347 -0
- package/dist/cli/seed-5J6eu_Xg.js +98 -0
- package/dist/cli/skills-LJJIhLFR.js +137 -0
- package/dist/cli/sql-D4VbqmXi.js +199 -0
- package/dist/cli/style-C0NFdJRL.js +29 -0
- package/dist/cli/toml-DB-MNnFs.js +424 -0
- package/dist/cli/version-5mW_8sY1.js +4 -0
- package/dist/cli/yaml-CYCbJ6et.js +2252 -0
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.js +13 -13
- package/dist/{compiler-2zqGzxVZ.d.ts → compiler-DB3aSFOA.d.ts} +2 -2
- package/dist/config/index.js +4 -4
- package/dist/{config-Be4GwsqI.js → config-BpxDfnbg.js} +1 -1
- package/dist/{config-DOsGYSiT.js → config-CbvFmGD8.js} +1 -1
- package/dist/{define-DF341GDj.js → define-Bh0AqTik.js} +160 -79
- package/dist/{define-DUbydmJa.d.ts → define-CRS2MRV3.d.ts} +32 -28
- package/dist/edge/index.d.ts +8 -12
- package/dist/edge/index.js +50 -24
- package/dist/{entitlements-DvJXoI02.d.ts → entitlements-Dm-FHpNH.d.ts} +2 -2
- package/dist/{errors-Bl3rkOzo.js → errors-L0xK41y_.js} +1 -1
- package/dist/events/index.d.ts +1 -1
- package/dist/events/index.js +4 -4
- package/dist/{events-Do8jXh4D.d.ts → events-B21UOhvP.d.ts} +4 -4
- package/dist/{executor-DynmIWhq.d.ts → executor-B5IoUxLE.d.ts} +1 -1
- package/dist/{executor-C57jx2pn.js → executor-CVt6dD0B.js} +3 -3
- package/dist/{executor-B26lgbHD.d.ts → executor-CZ7ImRiD.d.ts} +2 -2
- package/dist/hono/index.d.ts +16 -23
- package/dist/hono/index.js +10 -10
- package/dist/{index-CTTMS6_1.d.ts → index-528Ugmyp.d.ts} +12 -3
- package/dist/{index-CADlNHK-.d.ts → index-BAy4tsAP.d.ts} +5 -5
- package/dist/{index-BNsABq7P.d.ts → index-BBdvo-5d.d.ts} +23 -25
- package/dist/{index-qriRM9cZ.d.ts → index-BhHEC04r.d.ts} +3 -3
- package/dist/{index-GV77NpRP.d.ts → index-D5IfUIDh.d.ts} +3 -3
- package/dist/{index-CriFFJ_p.d.ts → index-DFmOpBGC.d.ts} +11 -11
- package/dist/{index-UJ-LUxtI.d.ts → index-RlLXd8dL.d.ts} +12 -12
- package/dist/index.d.ts +15 -15
- package/dist/index.js +13 -13
- package/dist/{invalidate-DbxuL2jL.js → invalidate-CgxmRamI.js} +7 -1
- package/dist/jobs/index.d.ts +10 -4
- package/dist/jobs/index.js +32 -16
- package/dist/{json-schema--aOXAGfU.js → json-schema-DP6V7cbr.js} +1 -1
- package/dist/list/index.d.ts +1 -1
- package/dist/list/index.js +3 -3
- package/dist/{live-QE3UPbGm.d.ts → live-BHakSWWo.d.ts} +12 -12
- package/dist/{live-D8rV1Ldw.js → live-CdJBOc4f.js} +13 -9
- package/dist/lookup-BaP5bI27.js +18 -0
- package/dist/mcp/index.d.ts +18 -18
- package/dist/mcp/index.js +23 -18
- package/dist/{mfa-x3V3vGh-.d.ts → mfa-C7MNQ1Ob.d.ts} +1 -1
- package/dist/{mfa-BxoR1RkN.js → mfa-byfjruR9.js} +118 -29
- package/dist/next/image/index.js +6 -3
- package/dist/next/index.d.ts +38 -35
- package/dist/next/index.js +41 -33
- package/dist/openapi/index.d.ts +1 -1
- package/dist/openapi/index.js +6 -6
- package/dist/orpc/index.d.ts +17 -20
- package/dist/orpc/index.js +11 -11
- package/dist/otel/index.d.ts +5 -5
- package/dist/otel/index.js +81 -62
- package/dist/{permdock-sql-Bta_G0v-.js → permdock-sql-C4KFzLc9.js} +1 -1
- package/dist/{plugin-DVRB8qNE.d.ts → plugin-bNhvJwRh.d.ts} +2 -2
- package/dist/plugins/actor/index.d.ts +1 -1
- package/dist/plugins/actor/index.js +1 -1
- package/dist/plugins/rules/index.d.ts +2 -2
- package/dist/plugins/rules/index.js +42 -12
- package/dist/plugins/soft-delete/index.d.ts +2 -2
- package/dist/plugins/soft-delete/index.js +2 -2
- package/dist/plugins/tenant/index.d.ts +2 -2
- package/dist/plugins/tenant/index.js +10 -4
- package/dist/plugins/timestamps/index.d.ts +1 -1
- package/dist/plugins/timestamps/index.js +1 -1
- package/dist/plugins/validation/index.d.ts +2 -2
- package/dist/plugins/validation/index.js +3 -3
- package/dist/{pool-B9qsLyFR.d.ts → pool-DFwEQwmN.d.ts} +11 -4
- package/dist/postgres/index.d.ts +5 -5
- package/dist/postgres/index.js +3 -2
- package/dist/{postgrest-DmBlevh-.d.ts → postgrest-Bc-0Xw62.d.ts} +1 -1
- package/dist/{problem-CGt1ADix.js → problem-BihjPR0t.js} +1 -1
- package/dist/{problem-Z2RTQjZD.d.ts → problem-U8UEKccv.d.ts} +1 -1
- package/dist/query/index.d.ts +2 -2
- package/dist/query/index.js +2 -2
- package/dist/{query-BdKLTPlj.js → query-BMMSWbI7.js} +18 -18
- package/dist/react/index.d.ts +6 -6
- package/dist/react/index.js +1 -1
- package/dist/react/server.d.ts +5 -5
- package/dist/react/server.js +3 -3
- package/dist/react/session.d.ts +4 -4
- package/dist/react/session.js +2 -2
- package/dist/{react-DNBYNazu.js → react-CQHMaESR.js} +39 -39
- package/dist/{read-set-D0qBcboM.js → read-set-FWK8qQ58.js} +50 -15
- package/dist/realtime/index.d.ts +1 -1
- package/dist/realtime/index.js +13 -12
- package/dist/{index-kpgopLNv.d.ts → refresh-BwYkyNOQ.d.ts} +6 -3
- package/dist/{resolve-BRciX2jK.d.ts → resolve-BAqQcwMW.d.ts} +15 -10
- package/dist/{resource-CwVgiI5q.d.ts → resource-BJcaIfxi.d.ts} +5 -5
- package/dist/{resource-D30rp0GN.js → resource-My_y-Syh.js} +6 -6
- package/dist/{respond-DAkPIdTH.d.ts → respond-DgIbdrt8.d.ts} +31 -12
- package/dist/{result-DWXatkd6.js → result-Bj6yt33D.js} +2 -2
- package/dist/{result-c2OYgCV2.d.ts → result-CqEsbgYs.d.ts} +3 -3
- package/dist/server/index.d.ts +14 -14
- package/dist/server/index.js +12 -12
- package/dist/{respond-C44EZAJo.js → server-BA75B0mT.js} +139 -100
- package/dist/{shared-_6-uPL7E.js → shared-DnoCdMDr.js} +4 -3
- package/dist/{simplify-LakqK1vH.js → simplify-Cqvfr9dj.js} +67 -24
- package/dist/sql/index.d.ts +1 -1
- package/dist/sql/index.js +7 -7
- package/dist/{sql-BIgk12ew.js → sql-B34HU2DI.js} +3 -2
- package/dist/ssr/index.d.ts +4 -4
- package/dist/ssr/index.js +2 -2
- package/dist/{standard-FUi3Z3-7.js → standard-BRyBGTtp.js} +2 -2
- package/dist/{standard-eudBiRk1.d.ts → standard-BsaCYQJc.d.ts} +1 -1
- package/dist/{stats-D78UQ8Yu.js → stats-C_YxA2r1.js} +33 -8
- package/dist/storage/index.d.ts +2 -2
- package/dist/storage/index.js +26 -8
- package/dist/{tables-Dhha3BXM.js → tables-Cb-3_VWc.js} +14 -0
- package/dist/{temporal-required-CMxeSVPo.js → temporal-required-CBNHT6ni.js} +1 -1
- package/dist/testing/index.d.ts +20 -21
- package/dist/testing/index.js +45 -45
- package/dist/{version-BfpG2gks.js → version-Bmf7_FzM.js} +1 -1
- package/dist/{view-3Po_PVlr.d.ts → view-B64o81wp.d.ts} +5 -5
- package/dist/{view-wZ-9qIUz.js → view-BrJI2LKp.js} +1 -1
- package/dist/webhooks/index.d.ts +3 -3
- package/dist/webhooks/index.js +1 -1
- package/dist/{webhooks-CAIFQSTM.js → webhooks-Bh_Jf_-l.js} +37 -18
- package/package.json +36 -4
- package/skills/better-supabase/SKILL.md +57 -10
- package/skills/better-supabase/references/plugins.md +7 -11
- package/skills/better-supabase/references/troubleshooting.md +24 -4
- package/skills/better-supabase-api/SKILL.md +66 -18
- package/skills/better-supabase-api/references/adapters.md +44 -26
- package/skills/better-supabase-auth/SKILL.md +146 -0
- package/skills/better-supabase-auth/references/permdock.md +55 -0
- package/skills/better-supabase-testing/SKILL.md +58 -4
- package/dist/claims-CoTobNC-.js +0 -25
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
import { styleText } from "node:util";
|
|
2
|
+
import { Catalog, CatalogCheck, CatalogColumn, CatalogColumnGrant, CatalogEnum, CatalogForeignKey, CatalogFunction, CatalogFunctionArg, CatalogGrant, CatalogIndex, CatalogPolicy, CatalogTable, CatalogTrigger, CatalogUnique, ExtrasFunction, ExtrasHook, ExtrasHookFunction, ExtrasTable, ForeignKeyAction, GeneratedFile, GeneratorMetadata, ResolvedConfig, Snapshot, SnapshotBucket, SnapshotExtras } from "better-supabase/config";
|
|
3
|
+
import { Casing, Codec, FunctionMeta, RelationMeta, SchemaMeta, TableMeta } from "better-supabase";
|
|
4
|
+
import { GeneratorMetadata as GeneratorMetadata$1, Queryable } from "@supabase/postgrest-typegen";
|
|
5
|
+
//#region ../../node_modules/.pnpm/citty@0.2.2/node_modules/citty/dist/index.d.mts
|
|
6
|
+
//#region src/types.d.ts
|
|
7
|
+
type ArgType = "boolean" | "string" | "enum" | "positional" | undefined;
|
|
8
|
+
type _ArgDef<T extends ArgType, VT extends boolean | number | string> = {
|
|
9
|
+
type?: T;
|
|
10
|
+
description?: string;
|
|
11
|
+
valueHint?: string;
|
|
12
|
+
alias?: string | string[];
|
|
13
|
+
default?: VT;
|
|
14
|
+
required?: boolean;
|
|
15
|
+
options?: string[];
|
|
16
|
+
};
|
|
17
|
+
type BooleanArgDef = Omit<_ArgDef<"boolean", boolean>, "options"> & {
|
|
18
|
+
negativeDescription?: string;
|
|
19
|
+
};
|
|
20
|
+
type StringArgDef = Omit<_ArgDef<"string", string>, "options">;
|
|
21
|
+
type EnumArgDef = _ArgDef<"enum", string>;
|
|
22
|
+
type PositionalArgDef = Omit<_ArgDef<"positional", string>, "alias" | "options">;
|
|
23
|
+
type ArgDef = BooleanArgDef | StringArgDef | PositionalArgDef | EnumArgDef;
|
|
24
|
+
type ArgsDef = Record<string, ArgDef>;
|
|
25
|
+
type ResolveParsedArgType<T extends ArgDef, VT> = T extends {
|
|
26
|
+
default?: any;
|
|
27
|
+
required?: boolean;
|
|
28
|
+
} ? T["default"] extends NonNullable<VT> ? VT : T["required"] extends true ? VT : VT | undefined : VT | undefined;
|
|
29
|
+
type ParsedPositionalArg<T extends ArgDef> = T extends {
|
|
30
|
+
type: "positional";
|
|
31
|
+
} ? ResolveParsedArgType<T, string> : never;
|
|
32
|
+
type ParsedStringArg<T extends ArgDef> = T extends {
|
|
33
|
+
type: "string";
|
|
34
|
+
} ? ResolveParsedArgType<T, string> : never;
|
|
35
|
+
type ParsedBooleanArg<T extends ArgDef> = T extends {
|
|
36
|
+
type: "boolean";
|
|
37
|
+
} ? ResolveParsedArgType<T, boolean> : never;
|
|
38
|
+
type ParsedEnumArg<T extends ArgDef> = T extends {
|
|
39
|
+
type: "enum";
|
|
40
|
+
options: infer U;
|
|
41
|
+
} ? U extends Array<any> ? ResolveParsedArgType<T, U[number]> : never : never;
|
|
42
|
+
type RawArgs = {
|
|
43
|
+
_: string[];
|
|
44
|
+
};
|
|
45
|
+
type ParsedArg<T extends ArgDef> = T["type"] extends "positional" ? ParsedPositionalArg<T> : T["type"] extends "boolean" ? ParsedBooleanArg<T> : T["type"] extends "string" ? ParsedStringArg<T> : T["type"] extends "enum" ? ParsedEnumArg<T> : never;
|
|
46
|
+
type ParsedArgs$1<T extends ArgsDef = ArgsDef> = RawArgs & { [K in keyof T]: ParsedArg<T[K]>; } & { [K in keyof T as T[K] extends {
|
|
47
|
+
alias: string;
|
|
48
|
+
} ? T[K]["alias"] : never]: ParsedArg<T[K]>; } & { [K in keyof T as T[K] extends {
|
|
49
|
+
alias: string[];
|
|
50
|
+
} ? T[K]["alias"][number] : never]: ParsedArg<T[K]>; } & Record<string, string | number | boolean | string[]>;
|
|
51
|
+
interface CommandMeta {
|
|
52
|
+
name?: string;
|
|
53
|
+
version?: string;
|
|
54
|
+
description?: string;
|
|
55
|
+
hidden?: boolean;
|
|
56
|
+
alias?: string | string[];
|
|
57
|
+
}
|
|
58
|
+
type SubCommandsDef = Record<string, Resolvable<CommandDef<any>>>;
|
|
59
|
+
type CommandDef<T extends ArgsDef = ArgsDef> = {
|
|
60
|
+
meta?: Resolvable<CommandMeta>;
|
|
61
|
+
args?: Resolvable<T>;
|
|
62
|
+
default?: Resolvable<string>;
|
|
63
|
+
subCommands?: Resolvable<SubCommandsDef>;
|
|
64
|
+
plugins?: Resolvable<CittyPlugin>[];
|
|
65
|
+
setup?: (context: CommandContext$1<T>) => any | Promise<any>;
|
|
66
|
+
cleanup?: (context: CommandContext$1<T>) => any | Promise<any>;
|
|
67
|
+
run?: (context: CommandContext$1<T>) => any | Promise<any>;
|
|
68
|
+
};
|
|
69
|
+
type CommandContext$1<T extends ArgsDef = ArgsDef> = {
|
|
70
|
+
rawArgs: string[];
|
|
71
|
+
args: ParsedArgs$1<T>;
|
|
72
|
+
cmd: CommandDef<T>;
|
|
73
|
+
subCommand?: CommandDef<T>;
|
|
74
|
+
data?: any;
|
|
75
|
+
};
|
|
76
|
+
type CittyPlugin = {
|
|
77
|
+
name: string;
|
|
78
|
+
setup?(context: CommandContext$1<any>): void | Promise<void>;
|
|
79
|
+
cleanup?(context: CommandContext$1<any>): void | Promise<void>;
|
|
80
|
+
};
|
|
81
|
+
type Resolvable<T> = T | Promise<T> | (() => T) | (() => Promise<T>);
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/cli/env.d.ts
|
|
84
|
+
/** The environment variables the CLI reads, validated once per run. */
|
|
85
|
+
interface CliEnv {
|
|
86
|
+
/** Postgres connection string for gen, introspect, doctor and seed. */
|
|
87
|
+
readonly DATABASE_URL?: string | undefined;
|
|
88
|
+
/** Personal access token for reading a hosted project. */
|
|
89
|
+
readonly SUPABASE_ACCESS_TOKEN?: string | undefined;
|
|
90
|
+
/** Management API base URL; defaults to https://api.supabase.com. */
|
|
91
|
+
readonly SUPABASE_API_URL?: string | undefined;
|
|
92
|
+
/** The Supabase CLI to run instead of `supabase` on the PATH. */
|
|
93
|
+
readonly SUPABASE_BIN?: string | undefined;
|
|
94
|
+
/** Home directory for `skills install --global`. */
|
|
95
|
+
readonly HOME?: string | undefined;
|
|
96
|
+
/** Set in CI; prompts never run there. */
|
|
97
|
+
readonly CI?: string | undefined;
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/cli/prompts.d.ts
|
|
101
|
+
interface Choice<T extends string> {
|
|
102
|
+
readonly value: T;
|
|
103
|
+
readonly label: string;
|
|
104
|
+
readonly hint?: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Questions and progress for a person at a terminal. `run()` only gets one
|
|
108
|
+
* from the bin on a TTY outside CI; every method resolves `undefined` when the
|
|
109
|
+
* person cancels.
|
|
110
|
+
*/
|
|
111
|
+
interface Prompter {
|
|
112
|
+
readonly select: <T extends string>(message: string, choices: readonly Choice<T>[], initial: T) => Promise<T | undefined>;
|
|
113
|
+
readonly multiselect: <T extends string>(message: string, choices: readonly Choice<T>[], initial: readonly T[]) => Promise<T[] | undefined>;
|
|
114
|
+
readonly confirm: (message: string) => Promise<boolean | undefined>;
|
|
115
|
+
/** Shows `message` with a spinner until the returned function is called. */
|
|
116
|
+
readonly spinner: (message: string) => () => void;
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/cli/io.d.ts
|
|
120
|
+
interface CliIo {
|
|
121
|
+
readonly stdout: (text: string) => void;
|
|
122
|
+
readonly stderr: (text: string) => void;
|
|
123
|
+
/** All of stdin, for the `--*-stdin` flags that keep secrets out of arguments. */
|
|
124
|
+
readonly stdin?: () => Promise<string>;
|
|
125
|
+
/** Color the output with ANSI escapes. Off unless set. */
|
|
126
|
+
readonly color?: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Prompts and spinners for a person at a terminal. `run()` drops them in
|
|
129
|
+
* CI and under `--json` or `--yes`, and without them commands never ask.
|
|
130
|
+
*/
|
|
131
|
+
readonly prompts?: Prompter;
|
|
132
|
+
}
|
|
133
|
+
interface RunResult {
|
|
134
|
+
readonly code: number;
|
|
135
|
+
readonly stdout: string;
|
|
136
|
+
readonly stderr: string;
|
|
137
|
+
}
|
|
138
|
+
interface CommandResult {
|
|
139
|
+
readonly code: number;
|
|
140
|
+
readonly output?: string;
|
|
141
|
+
readonly error?: string;
|
|
142
|
+
/** The JSON document `--json` prints instead of `output`. */
|
|
143
|
+
readonly data?: unknown;
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/cli/command.d.ts
|
|
147
|
+
/** What `run()` hands every command next to its parsed arguments. */
|
|
148
|
+
interface CliContext {
|
|
149
|
+
readonly cwd: string;
|
|
150
|
+
readonly config: ResolvedConfig;
|
|
151
|
+
/** `prompts` is unset in CI and under `--json` or `--yes`. */
|
|
152
|
+
readonly io: CliIo;
|
|
153
|
+
readonly env: CliEnv;
|
|
154
|
+
/** `--json`: return `data`, which `run()` prints as the one JSON document. */
|
|
155
|
+
readonly json: boolean;
|
|
156
|
+
readonly signal: AbortSignal | undefined;
|
|
157
|
+
}
|
|
158
|
+
/** Options every command accepts; `run()` reads them before the command starts. */
|
|
159
|
+
declare const GLOBAL_ARGS: {
|
|
160
|
+
readonly cwd: {
|
|
161
|
+
readonly type: "string";
|
|
162
|
+
readonly description: "Project directory";
|
|
163
|
+
readonly valueHint: "dir";
|
|
164
|
+
};
|
|
165
|
+
readonly config: {
|
|
166
|
+
readonly type: "string";
|
|
167
|
+
readonly description: "Config file, relative to --cwd";
|
|
168
|
+
readonly valueHint: "file";
|
|
169
|
+
};
|
|
170
|
+
readonly json: {
|
|
171
|
+
readonly type: "boolean";
|
|
172
|
+
readonly description: "Print one JSON document on stdout; errors as Problem Details";
|
|
173
|
+
};
|
|
174
|
+
readonly yes: {
|
|
175
|
+
readonly type: "boolean";
|
|
176
|
+
readonly alias: "y";
|
|
177
|
+
readonly description: "Ask nothing; use the flags and the defaults";
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
type CliArgs<T extends ArgsDef> = ParsedArgs$1<T & typeof GLOBAL_ARGS>;
|
|
181
|
+
interface CliCommandDef<T extends ArgsDef> {
|
|
182
|
+
readonly meta: CommandMeta & {
|
|
183
|
+
readonly name: string;
|
|
184
|
+
};
|
|
185
|
+
readonly args: T;
|
|
186
|
+
/** String options that take a list: comma-separated, repeated, or both. */
|
|
187
|
+
readonly lists?: readonly (keyof T & string)[];
|
|
188
|
+
readonly run: (args: CliArgs<T>, context: CliContext) => Promise<CommandResult>;
|
|
189
|
+
}
|
|
190
|
+
/** Any citty command, whatever its arguments. */
|
|
191
|
+
type AnyCommand = Exclude<SubCommandsDef[string], Promise<unknown> | (() => unknown)>;
|
|
192
|
+
/** A citty command that receives the `CliContext` and returns a `CommandResult`. */
|
|
193
|
+
export declare function defineCliCommand<const T extends ArgsDef>(def: CliCommandDef<T>): AnyCommand;
|
|
194
|
+
/** Splits a comma-separated option into its trimmed, non-empty parts. */
|
|
195
|
+
export declare function list(value: string | undefined): string[];
|
|
196
|
+
//#endregion
|
|
197
|
+
//#region src/cli/legacy.d.ts
|
|
198
|
+
type FlagValue = string | boolean | readonly string[];
|
|
199
|
+
/** The arguments of a `(context) => CommandResult` command, parsed the 0.2 way. */
|
|
200
|
+
interface ParsedArgs {
|
|
201
|
+
readonly command: string | undefined;
|
|
202
|
+
readonly rest: readonly string[];
|
|
203
|
+
readonly flags: Readonly<Record<string, FlagValue>>;
|
|
204
|
+
}
|
|
205
|
+
/** What a `(context) => CommandResult` command receives. */
|
|
206
|
+
interface CommandContext {
|
|
207
|
+
readonly args: ParsedArgs;
|
|
208
|
+
readonly cwd: string;
|
|
209
|
+
readonly config: ResolvedConfig;
|
|
210
|
+
readonly io: CliIo;
|
|
211
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
212
|
+
readonly signal: AbortSignal | undefined;
|
|
213
|
+
}
|
|
214
|
+
/** The command shape before 0.3; `registerCommand` still accepts it, deprecated. */
|
|
215
|
+
type Command = (context: CommandContext) => Promise<CommandResult>;
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region src/cli/run.d.ts
|
|
218
|
+
/** Registers a citty command; `defineCliCommand` gives it the `CliContext`. */
|
|
219
|
+
export declare function registerCommand(name: string, command: AnyCommand): void;
|
|
220
|
+
/** @deprecated Pass a citty `CommandDef` from `defineCliCommand` instead. */
|
|
221
|
+
export declare function registerCommand(name: string, command: Command, help?: string): void;
|
|
222
|
+
/** The usage text for the CLI, or for one command; plain unless `color` is set. */
|
|
223
|
+
export declare function help(command?: string, color?: boolean): Promise<string>;
|
|
224
|
+
interface RunOptions {
|
|
225
|
+
/** Directory `--cwd` is relative to. */
|
|
226
|
+
readonly cwd?: string;
|
|
227
|
+
/** Environment variables. Empty unless passed; the bin passes `process.env`. */
|
|
228
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
229
|
+
readonly io?: CliIo;
|
|
230
|
+
readonly signal?: AbortSignal;
|
|
231
|
+
}
|
|
232
|
+
/** The names `run()` dispatches, registered commands included. */
|
|
233
|
+
export declare function commandNames(): string[];
|
|
234
|
+
/** Runs the CLI. Never exits the process; returns the exit code and output. */
|
|
235
|
+
export declare function run(argv: readonly string[], options?: RunOptions): Promise<RunResult>;
|
|
236
|
+
//#endregion
|
|
237
|
+
//#region src/cli/errors.d.ts
|
|
238
|
+
/** `1` for a failure, `2` for a usage error the caller can fix by changing the command. */
|
|
239
|
+
type ExitCode = 1 | 2;
|
|
240
|
+
type CliErrorCode = "usage" | "unknown_command" | "missing_value" | "config_not_found" | "config_invalid" | "env_invalid" | "failed" | "internal";
|
|
241
|
+
/** Each code has a heading on this page, so `type` links to its explanation. */
|
|
242
|
+
export declare const CLI_ERRORS_URL = "https://bettersupabase.com/docs/cli/errors";
|
|
243
|
+
/** RFC 9457 Problem Details for a CLI error. `--json` prints it on stdout. */
|
|
244
|
+
interface CliProblem {
|
|
245
|
+
readonly type: string;
|
|
246
|
+
readonly title: string;
|
|
247
|
+
readonly detail: string;
|
|
248
|
+
readonly code: CliErrorCode;
|
|
249
|
+
readonly exitCode: number;
|
|
250
|
+
/** The closest command, for `unknown_command`. */
|
|
251
|
+
readonly suggestion?: string;
|
|
252
|
+
/** The flag that supplies the value, for `missing_value`. */
|
|
253
|
+
readonly flag?: string;
|
|
254
|
+
/** One line per problem, for `config_invalid` and `env_invalid`. */
|
|
255
|
+
readonly issues?: readonly string[];
|
|
256
|
+
}
|
|
257
|
+
type CliProblemExtensions = Pick<CliProblem, "suggestion" | "flag" | "issues">;
|
|
258
|
+
interface CliErrorOptions extends CliProblemExtensions {
|
|
259
|
+
readonly exitCode?: number;
|
|
260
|
+
readonly cause?: unknown;
|
|
261
|
+
}
|
|
262
|
+
/** An error the CLI reports as text, or as Problem Details under `--json`. */
|
|
263
|
+
export declare class CliError extends Error {
|
|
264
|
+
override readonly name = "CliError";
|
|
265
|
+
readonly code: CliErrorCode;
|
|
266
|
+
readonly exitCode: number;
|
|
267
|
+
readonly problem: CliProblem;
|
|
268
|
+
constructor(code: CliErrorCode, message: string, options?: CliErrorOptions);
|
|
269
|
+
}
|
|
270
|
+
//#endregion
|
|
271
|
+
//#region src/cli/style.d.ts
|
|
272
|
+
type Format = Parameters<typeof styleText>[0];
|
|
273
|
+
/** Styles text, or returns it unchanged when colors are off. */
|
|
274
|
+
type Paint = (format: Format, text: string) => string;
|
|
275
|
+
//#endregion
|
|
276
|
+
//#region src/cli/db.d.ts
|
|
277
|
+
/** The subset of `pg.Client` the CLI uses. */
|
|
278
|
+
interface PgQueryable {
|
|
279
|
+
query<R = Record<string, unknown>>(text: string, values?: readonly unknown[]): Promise<{
|
|
280
|
+
rows: R[];
|
|
281
|
+
}>;
|
|
282
|
+
}
|
|
283
|
+
interface ConnectOptions {
|
|
284
|
+
/** Opens a pool of this many connections, for callers that query concurrently. */
|
|
285
|
+
readonly pool?: number;
|
|
286
|
+
/** Server-side limit for each statement, in milliseconds. */
|
|
287
|
+
readonly statementTimeout?: number;
|
|
288
|
+
/** Ends the connection when aborted, so Ctrl-C stops a running query. */
|
|
289
|
+
readonly signal?: AbortSignal;
|
|
290
|
+
}
|
|
291
|
+
/** A connection that queues its queries, or a pool that runs them concurrently. */
|
|
292
|
+
interface PgConnection {
|
|
293
|
+
readonly client: PgQueryable;
|
|
294
|
+
readonly pooled?: boolean;
|
|
295
|
+
close: () => Promise<void>;
|
|
296
|
+
describe: string;
|
|
297
|
+
}
|
|
298
|
+
/** Opens a `pg` connection. `pg` is an optional peer, loaded on demand. */
|
|
299
|
+
declare function connect(url: string, load?: () => Promise<unknown>, options?: ConnectOptions): Promise<PgConnection>;
|
|
300
|
+
//#endregion
|
|
301
|
+
//#region src/cli/introspect/source.d.ts
|
|
302
|
+
/** A connection introspection can query, plus how to release it. */
|
|
303
|
+
interface IntrospectionSource {
|
|
304
|
+
readonly queryable: Queryable;
|
|
305
|
+
readonly describe: string;
|
|
306
|
+
close(): Promise<void>;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* A small `pg` pool, since introspection issues its queries concurrently. A
|
|
310
|
+
* `connect` that returns a single client gets its queries queued, because one
|
|
311
|
+
* `pg.Client` runs them one at a time.
|
|
312
|
+
*/
|
|
313
|
+
export declare function pgSource(url: string, open?: typeof connect, signal?: AbortSignal): Promise<IntrospectionSource>;
|
|
314
|
+
interface ManagementSourceOptions {
|
|
315
|
+
readonly projectRef: string;
|
|
316
|
+
readonly accessToken: string;
|
|
317
|
+
/** Defaults to `https://api.supabase.com`. */
|
|
318
|
+
readonly apiUrl?: string;
|
|
319
|
+
readonly fetch?: typeof fetch;
|
|
320
|
+
/** Cancels in-flight queries (Ctrl-C). */
|
|
321
|
+
readonly signal?: AbortSignal;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Runs introspection SQL through the Supabase Management API as the
|
|
325
|
+
* read-only database user, so hosted projects need no database password.
|
|
326
|
+
*/
|
|
327
|
+
export declare function managementSource(options: ManagementSourceOptions): IntrospectionSource;
|
|
328
|
+
//#endregion
|
|
329
|
+
//#region src/cli/commands/snapshot.d.ts
|
|
330
|
+
interface SnapshotSource {
|
|
331
|
+
readonly snapshotPath?: string;
|
|
332
|
+
readonly dbUrl?: string;
|
|
333
|
+
readonly projectRef?: string;
|
|
334
|
+
/** Ignore `source.snapshot` and read the database. */
|
|
335
|
+
readonly live?: boolean;
|
|
336
|
+
/** Ends the database connection or Management API request (Ctrl-C). */
|
|
337
|
+
readonly signal?: AbortSignal;
|
|
338
|
+
/** Reuses the snapshot cached for an unchanged catalog fingerprint. */
|
|
339
|
+
readonly cache?: boolean;
|
|
340
|
+
}
|
|
341
|
+
type Env = CliEnv;
|
|
342
|
+
/**
|
|
343
|
+
* Loads a saved snapshot or introspects the database. With `shared`, it
|
|
344
|
+
* introspects over that source and leaves closing it to the caller, so later
|
|
345
|
+
* queries reuse the connection.
|
|
346
|
+
*/
|
|
347
|
+
export declare function loadSnapshot(config: ResolvedConfig, env: Env, source: SnapshotSource, open?: typeof connect, shared?: () => Promise<IntrospectionSource>): Promise<Snapshot>;
|
|
348
|
+
/** Validates a parsed snapshot document. */
|
|
349
|
+
export declare function parseSnapshot(data: unknown, label?: string): Promise<Snapshot>;
|
|
350
|
+
export declare function serializeSnapshot(snapshot: Snapshot): string;
|
|
351
|
+
//#endregion
|
|
352
|
+
//#region src/cli/commands/gen.d.ts
|
|
353
|
+
interface GenOptions extends SnapshotSource {
|
|
354
|
+
readonly config: ResolvedConfig;
|
|
355
|
+
readonly env: CliEnv;
|
|
356
|
+
readonly check: boolean;
|
|
357
|
+
/** Colors the `--check` diffs. */
|
|
358
|
+
readonly paint?: Paint;
|
|
359
|
+
/** Pre-loaded snapshot (tests, watch mode). */
|
|
360
|
+
readonly snapshot?: Snapshot;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Renders every generated file for a snapshot, without touching disk:
|
|
364
|
+
* `database.types.ts` (what `supabase gen types` prints), the main module,
|
|
365
|
+
* then each configured generator's files.
|
|
366
|
+
*/
|
|
367
|
+
export declare function renderFiles(config: ResolvedConfig, snapshot: Snapshot): Promise<GeneratedFile[]>;
|
|
368
|
+
export declare function runGen(options: GenOptions): Promise<CommandResult>;
|
|
369
|
+
//#endregion
|
|
370
|
+
//#region src/cli/introspect/extras.d.ts
|
|
371
|
+
/** A hook function to introspect: `[auth.hook.<hook>]` pointing at `schema.name`. */
|
|
372
|
+
interface HookTarget {
|
|
373
|
+
readonly hook: string;
|
|
374
|
+
readonly schema: string;
|
|
375
|
+
readonly name: string;
|
|
376
|
+
}
|
|
377
|
+
//#endregion
|
|
378
|
+
//#region src/cli/introspect/catalog.d.ts
|
|
379
|
+
/** Joins the typegen metadata and the extras into one record per object. */
|
|
380
|
+
export declare function toCatalog(snapshot: Snapshot): Catalog;
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region src/cli/introspect/index.d.ts
|
|
383
|
+
interface IntrospectOptions {
|
|
384
|
+
/** Auth hook functions to read too, in any schema (`[auth.hook.*]`). */
|
|
385
|
+
readonly hooks?: readonly HookTarget[];
|
|
386
|
+
}
|
|
387
|
+
/** Reads a v2 snapshot: typegen metadata plus the extras. */
|
|
388
|
+
export declare function introspect(db: Queryable, schemas: readonly string[], options?: IntrospectOptions): Promise<Snapshot>;
|
|
389
|
+
//#endregion
|
|
390
|
+
//#region src/cli/introspect/from-catalog.d.ts
|
|
391
|
+
/**
|
|
392
|
+
* Builds a snapshot from catalog records: the inverse of `toCatalog`. Tests
|
|
393
|
+
* and benchmarks describe schemas as tables and functions; this produces the
|
|
394
|
+
* typegen metadata and extras those records imply.
|
|
395
|
+
*/
|
|
396
|
+
export declare function fromCatalog(catalog: Catalog): Snapshot;
|
|
397
|
+
//#endregion
|
|
398
|
+
//#region src/cli/gen/model.d.ts
|
|
399
|
+
interface ColumnModel {
|
|
400
|
+
readonly app: string;
|
|
401
|
+
readonly db: string;
|
|
402
|
+
readonly snapshot: CatalogColumn;
|
|
403
|
+
/** TypeScript type without `| null`. */
|
|
404
|
+
readonly tsType: string;
|
|
405
|
+
readonly nullable: boolean;
|
|
406
|
+
/** Optional on insert. */
|
|
407
|
+
readonly optional: boolean;
|
|
408
|
+
/** Not writable (generated always / identity always). */
|
|
409
|
+
readonly readonly: boolean;
|
|
410
|
+
readonly values: readonly string[] | undefined;
|
|
411
|
+
readonly json: boolean;
|
|
412
|
+
readonly codec: Codec | undefined;
|
|
413
|
+
/** Bucket id from `config.storagePaths`. */
|
|
414
|
+
readonly storage: string | undefined;
|
|
415
|
+
readonly insertable: boolean;
|
|
416
|
+
readonly updatable: boolean;
|
|
417
|
+
}
|
|
418
|
+
interface RelationModel {
|
|
419
|
+
readonly name: string;
|
|
420
|
+
readonly meta: RelationMeta;
|
|
421
|
+
}
|
|
422
|
+
interface TableModel {
|
|
423
|
+
readonly key: string;
|
|
424
|
+
readonly snapshot: CatalogTable;
|
|
425
|
+
readonly casing: Casing;
|
|
426
|
+
readonly columns: readonly ColumnModel[];
|
|
427
|
+
readonly relations: readonly RelationModel[];
|
|
428
|
+
readonly meta: TableMeta;
|
|
429
|
+
}
|
|
430
|
+
interface EnumModel {
|
|
431
|
+
readonly schema: string;
|
|
432
|
+
readonly name: string;
|
|
433
|
+
/** Constant name for the value array, e.g. `noteKindValues`. */
|
|
434
|
+
readonly constant: string;
|
|
435
|
+
readonly values: readonly string[];
|
|
436
|
+
}
|
|
437
|
+
interface FunctionModel {
|
|
438
|
+
readonly key: string;
|
|
439
|
+
readonly meta: FunctionMeta;
|
|
440
|
+
readonly args: readonly {
|
|
441
|
+
name: string;
|
|
442
|
+
tsType: string;
|
|
443
|
+
optional: boolean;
|
|
444
|
+
}[];
|
|
445
|
+
readonly returns: string;
|
|
446
|
+
}
|
|
447
|
+
interface JsonImport {
|
|
448
|
+
readonly name: string;
|
|
449
|
+
/** Path relative to the project root, without the `#Name` part. */
|
|
450
|
+
readonly from: string;
|
|
451
|
+
}
|
|
452
|
+
interface Model {
|
|
453
|
+
readonly tables: readonly TableModel[];
|
|
454
|
+
readonly enums: readonly EnumModel[];
|
|
455
|
+
readonly functions: readonly FunctionModel[];
|
|
456
|
+
readonly jsonImports: readonly JsonImport[];
|
|
457
|
+
readonly meta: SchemaMeta;
|
|
458
|
+
readonly config: ResolvedConfig;
|
|
459
|
+
readonly catalog: Catalog;
|
|
460
|
+
/** Typegen metadata restricted to the configured schemas. */
|
|
461
|
+
readonly introspection: GeneratorMetadata$1;
|
|
462
|
+
}
|
|
463
|
+
/** Builds the codegen model from a snapshot and config. */
|
|
464
|
+
export declare function buildModel(snapshot: Snapshot, config: ResolvedConfig): Model;
|
|
465
|
+
//#endregion
|
|
466
|
+
//#region src/cli/gen/emit.d.ts
|
|
467
|
+
export declare const GENERATED_HEADER = "// @generated by better-supabase gen. Do not edit; run `better-supabase gen` instead.";
|
|
468
|
+
interface EmitOptions {
|
|
469
|
+
/** Import path from the generated module to `better-supabase`. */
|
|
470
|
+
readonly runtimeImport?: string;
|
|
471
|
+
/** Import path from the generated module to `database.types.ts`. */
|
|
472
|
+
readonly databaseTypesImport?: string;
|
|
473
|
+
/** Import path for each JSON type import, keyed by the configured path. */
|
|
474
|
+
readonly importPathFor: (from: string) => string;
|
|
475
|
+
/** Import path from the generated module to the metadata module (`emitMeta`). */
|
|
476
|
+
readonly metaImport?: string;
|
|
477
|
+
}
|
|
478
|
+
/** Renders the generated module. */
|
|
479
|
+
export declare function emitModule(model: Model, options: EmitOptions): string;
|
|
480
|
+
//#endregion
|
|
481
|
+
//#region src/cli/config.d.ts
|
|
482
|
+
/**
|
|
483
|
+
* Loads `better-supabase.config.*` with c12 and checks it against the config
|
|
484
|
+
* schema. c12 imports `.ts` natively (Node 24 strips the types), so no
|
|
485
|
+
* loader is needed; rc files, `package.json`, env overrides and `extends`
|
|
486
|
+
* are off so the one file is the whole config.
|
|
487
|
+
*/
|
|
488
|
+
export declare function loadConfig(cwd: string, explicit?: string): Promise<ResolvedConfig>;
|
|
489
|
+
//#endregion
|
|
490
|
+
//#region src/cli/version.d.ts
|
|
491
|
+
export declare const VERSION = "0.4.0";
|
|
492
|
+
//#endregion
|
|
493
|
+
export type { Catalog, CatalogCheck, CatalogColumn, CatalogColumnGrant, CatalogEnum, CatalogForeignKey, CatalogFunction, CatalogFunctionArg, CatalogGrant, CatalogIndex, CatalogPolicy, CatalogTable, CatalogTrigger, CatalogUnique, CliArgs, CliCommandDef, CliContext, CliEnv, CliErrorCode, CliErrorOptions, CliIo, CliProblem, CliProblemExtensions, Command, CommandContext, CommandResult, ExitCode, ExtrasFunction, ExtrasHook, ExtrasHookFunction, ExtrasTable, ForeignKeyAction, GeneratorMetadata, IntrospectionSource, ManagementSourceOptions, ParsedArgs, Queryable, RunOptions, RunResult, Snapshot, SnapshotBucket, SnapshotExtras };
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { a as list, r as defineCliCommand } from "./command-CK14fP91.js";
|
|
2
|
+
import { n as CliError, t as CLI_ERRORS_URL } from "./errors-4v4DTtda.js";
|
|
3
|
+
import { i as run, n as help, r as registerCommand, t as commandNames } from "./run-CP20LKk_.js";
|
|
4
|
+
import { t as VERSION } from "./version-5mW_8sY1.js";
|
|
5
|
+
import { a as loadConfig } from "./config-D9R0o1LH.js";
|
|
6
|
+
import { b as emitModule, f as introspect, g as buildModel, i as runGen, k as toCatalog, l as parseSnapshot, m as pgSource, o as loadSnapshot, p as managementSource, r as renderFiles, u as serializeSnapshot, y as GENERATED_HEADER } from "./gen-Ccn_p90L.js";
|
|
7
|
+
//#region src/cli/introspect/from-catalog.ts
|
|
8
|
+
/**
|
|
9
|
+
* Builds a snapshot from catalog records: the inverse of `toCatalog`. Tests
|
|
10
|
+
* and benchmarks describe schemas as tables and functions; this produces the
|
|
11
|
+
* typegen metadata and extras those records imply.
|
|
12
|
+
*/
|
|
13
|
+
function fromCatalog(catalog) {
|
|
14
|
+
const schemas = [.../* @__PURE__ */ new Set([...catalog.schemas, ...catalog.tables.map((table) => table.schema)])].sort();
|
|
15
|
+
const meta = {
|
|
16
|
+
version: 1,
|
|
17
|
+
schemas: schemas.map((name, index) => ({
|
|
18
|
+
id: 4e6 + index,
|
|
19
|
+
name,
|
|
20
|
+
owner: "postgres"
|
|
21
|
+
})),
|
|
22
|
+
tables: [],
|
|
23
|
+
foreignTables: [],
|
|
24
|
+
views: [],
|
|
25
|
+
materializedViews: [],
|
|
26
|
+
columns: [],
|
|
27
|
+
primaryKeys: [],
|
|
28
|
+
relationships: [],
|
|
29
|
+
functions: [],
|
|
30
|
+
types: []
|
|
31
|
+
};
|
|
32
|
+
const typeIds = /* @__PURE__ */ new Map();
|
|
33
|
+
const typeId = (schema, name) => {
|
|
34
|
+
const key = `${schema}.${name}`;
|
|
35
|
+
let id = typeIds.get(key);
|
|
36
|
+
if (id === void 0) {
|
|
37
|
+
id = 2e6 + typeIds.size;
|
|
38
|
+
typeIds.set(key, id);
|
|
39
|
+
meta.types.push({
|
|
40
|
+
id,
|
|
41
|
+
name,
|
|
42
|
+
schema,
|
|
43
|
+
format: name,
|
|
44
|
+
enums: [],
|
|
45
|
+
attributes: [],
|
|
46
|
+
comment: null,
|
|
47
|
+
type_relation_id: null
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return id;
|
|
51
|
+
};
|
|
52
|
+
const enums = new Map(catalog.enums.map((entry) => [`${entry.schema}.${entry.name}`, entry]));
|
|
53
|
+
for (const entry of catalog.enums) {
|
|
54
|
+
const id = typeId(entry.schema, entry.name);
|
|
55
|
+
const type = meta.types.find((candidate) => candidate.id === id);
|
|
56
|
+
type.enums = [...entry.values];
|
|
57
|
+
}
|
|
58
|
+
const column = (table, id, entry, index) => ({
|
|
59
|
+
table_id: id,
|
|
60
|
+
schema: table.schema,
|
|
61
|
+
table: table.name,
|
|
62
|
+
id: `${id}.${index + 1}`,
|
|
63
|
+
ordinal_position: index + 1,
|
|
64
|
+
name: entry.name,
|
|
65
|
+
default_value: entry.default,
|
|
66
|
+
data_type: entry.isArray ? "ARRAY" : entry.isEnum ? "USER-DEFINED" : entry.udt,
|
|
67
|
+
format: entry.format,
|
|
68
|
+
type_schema: entry.typeSchema,
|
|
69
|
+
is_identity: entry.identity !== null,
|
|
70
|
+
identity_generation: entry.identity === "always" ? "ALWAYS" : entry.identity === "by default" ? "BY DEFAULT" : null,
|
|
71
|
+
is_generated: entry.generated,
|
|
72
|
+
is_nullable: entry.nullable,
|
|
73
|
+
is_updatable: entry.updatable,
|
|
74
|
+
is_unique: false,
|
|
75
|
+
enums: entry.isEnum ? [...enums.get(`${entry.typeSchema}.${entry.udt}`)?.values ?? []] : [],
|
|
76
|
+
check: null,
|
|
77
|
+
comment: entry.comment
|
|
78
|
+
});
|
|
79
|
+
catalog.tables.forEach((table, index) => {
|
|
80
|
+
const id = table.id || 1e6 + index;
|
|
81
|
+
if (table.kind === "table") meta.tables.push({
|
|
82
|
+
id,
|
|
83
|
+
schema: table.schema,
|
|
84
|
+
name: table.name,
|
|
85
|
+
rls_enabled: table.rls,
|
|
86
|
+
rls_forced: table.forceRls,
|
|
87
|
+
replica_identity: table.replicaIdentity ?? "DEFAULT",
|
|
88
|
+
bytes: 0,
|
|
89
|
+
size: "0 bytes",
|
|
90
|
+
live_rows_estimate: 0,
|
|
91
|
+
dead_rows_estimate: 0,
|
|
92
|
+
comment: table.comment
|
|
93
|
+
});
|
|
94
|
+
else meta.views.push({
|
|
95
|
+
id,
|
|
96
|
+
schema: table.schema,
|
|
97
|
+
name: table.name,
|
|
98
|
+
is_updatable: table.insertable || table.updatable,
|
|
99
|
+
is_insert_enabled: table.insertable,
|
|
100
|
+
is_update_enabled: table.updatable,
|
|
101
|
+
comment: table.comment
|
|
102
|
+
});
|
|
103
|
+
for (const [position, entry] of table.columns.entries()) meta.columns.push(column(table, id, entry, position));
|
|
104
|
+
for (const name of table.primaryKey) meta.primaryKeys.push({
|
|
105
|
+
schema: table.schema,
|
|
106
|
+
table_name: table.name,
|
|
107
|
+
name,
|
|
108
|
+
table_id: id
|
|
109
|
+
});
|
|
110
|
+
for (const fk of table.foreignKeys) meta.relationships.push({
|
|
111
|
+
foreign_key_name: fk.name,
|
|
112
|
+
schema: table.schema,
|
|
113
|
+
relation: table.name,
|
|
114
|
+
columns: [...fk.columns],
|
|
115
|
+
is_one_to_one: fk.oneToOne,
|
|
116
|
+
referenced_schema: fk.refSchema,
|
|
117
|
+
referenced_relation: fk.refTable,
|
|
118
|
+
referenced_columns: [...fk.refColumns]
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
const relationIds = new Map([...meta.tables, ...meta.views].map((entry) => [`${entry.schema}.${entry.name}`, entry.id]));
|
|
122
|
+
const argType = (schema, udt) => typeId(enums.has(`${schema}.${udt}`) ? schema : "pg_catalog", udt);
|
|
123
|
+
catalog.functions.forEach((fn, index) => {
|
|
124
|
+
const args = [...fn.args.map((arg) => ({
|
|
125
|
+
mode: "in",
|
|
126
|
+
name: arg.name,
|
|
127
|
+
type_id: argType(fn.schema, arg.isArray ? `_${arg.udt}` : arg.udt),
|
|
128
|
+
has_default: arg.hasDefault
|
|
129
|
+
})), ...(fn.returnsTable ?? []).map((entry) => ({
|
|
130
|
+
mode: "table",
|
|
131
|
+
name: entry.name,
|
|
132
|
+
type_id: argType(fn.schema, entry.udt),
|
|
133
|
+
has_default: false
|
|
134
|
+
}))];
|
|
135
|
+
meta.functions.push({
|
|
136
|
+
id: 3e6 + index,
|
|
137
|
+
schema: fn.schema,
|
|
138
|
+
name: fn.name,
|
|
139
|
+
language: fn.language,
|
|
140
|
+
definition: "",
|
|
141
|
+
complete_statement: "",
|
|
142
|
+
args,
|
|
143
|
+
argument_types: fn.signature,
|
|
144
|
+
identity_argument_types: fn.signature,
|
|
145
|
+
return_type_id: fn.returnsRelation ? typeId(fn.returnsRelation.split(".")[0], fn.returns) : argType(fn.schema, fn.returns),
|
|
146
|
+
return_type: fn.returns,
|
|
147
|
+
return_type_relation_id: fn.returnsRelation ? relationIds.get(fn.returnsRelation) ?? null : null,
|
|
148
|
+
is_set_returning_function: fn.returnsSet,
|
|
149
|
+
prorows: null,
|
|
150
|
+
behavior: fn.volatility.toUpperCase(),
|
|
151
|
+
security_definer: fn.securityDefiner,
|
|
152
|
+
config_params: fn.searchPath === null ? null : { search_path: fn.searchPath === "" ? "\"\"" : fn.searchPath }
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
return {
|
|
156
|
+
version: 2,
|
|
157
|
+
schemas,
|
|
158
|
+
generator: meta,
|
|
159
|
+
extras: {
|
|
160
|
+
tables: catalog.tables.map((table, index) => ({
|
|
161
|
+
id: table.id || 1e6 + index,
|
|
162
|
+
schema: table.schema,
|
|
163
|
+
name: table.name,
|
|
164
|
+
primaryKey: table.primaryKey,
|
|
165
|
+
uniques: table.uniques,
|
|
166
|
+
foreignKeys: table.foreignKeys.map((fk) => ({
|
|
167
|
+
name: fk.name,
|
|
168
|
+
onDelete: fk.onDelete,
|
|
169
|
+
onUpdate: fk.onUpdate
|
|
170
|
+
})),
|
|
171
|
+
checks: table.checks,
|
|
172
|
+
indexes: table.indexes,
|
|
173
|
+
policies: table.policies,
|
|
174
|
+
triggers: table.triggers,
|
|
175
|
+
grants: table.grants,
|
|
176
|
+
...table.columnGrants ? { columnGrants: table.columnGrants } : {}
|
|
177
|
+
})),
|
|
178
|
+
buckets: catalog.buckets,
|
|
179
|
+
realtime: catalog.realtime
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
//#endregion
|
|
184
|
+
export { CLI_ERRORS_URL, CliError, GENERATED_HEADER, VERSION, buildModel, commandNames, defineCliCommand, emitModule, fromCatalog, help, introspect, list, loadConfig, loadSnapshot, managementSource, parseSnapshot, pgSource, registerCommand, renderFiles, run, runGen, serializeSnapshot, toCatalog };
|