better-supabase 0.2.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 +37 -33
- package/dist/base64-D2gsioCY.js +42 -0
- package/dist/claims-BAf6c7is.js +48 -0
- package/dist/cli/_format-Cax5EsM9.js +101 -0
- package/dist/cli/bin.js +39 -6
- 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 +295 -28
- package/dist/cli/index.js +184 -3
- 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/{version-Cqq1m3UY.js → cli/version-5mW_8sY1.js} +1 -1
- package/dist/cli/yaml-CYCbJ6et.js +2252 -0
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.js +15 -25
- package/dist/{compiler-CZ9nIuqy.d.ts → compiler-DB3aSFOA.d.ts} +2 -2
- package/dist/config/index.d.ts +4 -3
- package/dist/config/index.js +5 -3
- package/dist/config-BpxDfnbg.js +129 -0
- package/dist/{index-DOsjFvMf.d.ts → config-C1CYcm6o.d.ts} +49 -49
- package/dist/{config-ClDXmVtY.js → config-CbvFmGD8.js} +14 -137
- package/dist/{define-BXMYD9AY.js → define-Bh0AqTik.js} +221 -120
- package/dist/{define-e3zI4_4g.d.ts → define-CRS2MRV3.d.ts} +36 -31
- package/dist/edge/index.d.ts +9 -13
- package/dist/edge/index.js +51 -25
- package/dist/{entitlements-Dng-ctuT.d.ts → entitlements-Dm-FHpNH.d.ts} +2 -2
- package/dist/env/index.js +203 -1
- package/dist/{errors-Bl3rkOzo.js → errors-L0xK41y_.js} +1 -1
- package/dist/events/index.d.ts +1 -1
- package/dist/events/index.js +139 -1
- package/dist/{events-DOt3nSO-.d.ts → events-B21UOhvP.d.ts} +4 -4
- package/dist/{executor-CGdNQ27g.d.ts → executor-B5IoUxLE.d.ts} +2 -2
- package/dist/{executor-DeppvirK.js → executor-CVt6dD0B.js} +9 -4
- package/dist/{executor-BYXQ9AGn.d.ts → executor-CZ7ImRiD.d.ts} +2 -2
- package/dist/hono/index.d.ts +17 -24
- package/dist/hono/index.js +11 -11
- package/dist/{index-DuP14VHo.d.ts → index-528Ugmyp.d.ts} +30 -10
- package/dist/{index-Bw1bwtC0.d.ts → index-BAy4tsAP.d.ts} +28 -15
- package/dist/{index-CBDufH1M.d.ts → index-BBdvo-5d.d.ts} +24 -26
- package/dist/{index-DbxFr7XG.d.ts → index-BhHEC04r.d.ts} +9 -4
- package/dist/index-Cf-D2jk1.d.ts +50 -0
- package/dist/{index-Ciu5Xlml.d.ts → index-D5IfUIDh.d.ts} +6 -5
- package/dist/{index-K-3WM2Hp.d.ts → index-DFmOpBGC.d.ts} +13 -13
- package/dist/{index-D4v7sncu.d.ts → index-RlLXd8dL.d.ts} +13 -13
- package/dist/index.d.ts +17 -17
- package/dist/index.js +23 -14
- package/dist/{invalidate-DbxuL2jL.js → invalidate-CgxmRamI.js} +7 -1
- package/dist/jobs/index.d.ts +33 -26
- package/dist/jobs/index.js +44 -22
- package/dist/{json-schema-BpYqkCKf.js → json-schema-DP6V7cbr.js} +8 -3
- package/dist/lint/index.js +1 -1
- package/dist/list/index.d.ts +2 -2
- package/dist/list/index.js +131 -96
- package/dist/{live-DJyZMD6w.d.ts → live-BHakSWWo.d.ts} +26 -16
- package/dist/{live-D8rV1Ldw.js → live-CdJBOc4f.js} +13 -9
- package/dist/lookup-BaP5bI27.js +18 -0
- package/dist/mcp/index.d.ts +34 -27
- package/dist/mcp/index.js +59 -25
- package/dist/{mfa-TVia554c.d.ts → mfa-C7MNQ1Ob.d.ts} +1 -1
- package/dist/{mfa-CpLfJSde.js → mfa-byfjruR9.js} +190 -46
- package/dist/next/image/index.js +6 -3
- package/dist/next/index.d.ts +64 -48
- package/dist/next/index.js +63 -50
- package/dist/openapi/index.d.ts +1 -1
- package/dist/openapi/index.js +61 -38
- package/dist/orpc/index.d.ts +18 -21
- package/dist/orpc/index.js +12 -12
- package/dist/otel/index.d.ts +5 -5
- package/dist/otel/index.js +84 -63
- package/dist/{permdock-sql-CghlHPuH.js → permdock-sql-C4KFzLc9.js} +12 -7
- package/dist/permdock-sql-DImJULY-.d.ts +17 -0
- package/dist/{plugin-C4TR9J0Z.d.ts → plugin-bNhvJwRh.d.ts} +5 -4
- 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 +46 -16
- package/dist/plugins/soft-delete/index.d.ts +3 -3
- package/dist/plugins/soft-delete/index.js +4 -4
- package/dist/plugins/tenant/index.d.ts +3 -3
- package/dist/plugins/tenant/index.js +10 -4
- package/dist/plugins/timestamps/index.d.ts +1 -1
- package/dist/plugins/timestamps/index.js +2 -2
- package/dist/plugins/validation/index.d.ts +2 -2
- package/dist/plugins/validation/index.js +3 -3
- package/dist/pool-DFwEQwmN.d.ts +78 -0
- package/dist/postgres/index.d.ts +10 -5
- package/dist/postgres/index.js +37 -16
- package/dist/{postgrest-cAEQ_IQN.d.ts → postgrest-Bc-0Xw62.d.ts} +1 -1
- package/dist/{problem-BTkTtRV9.js → problem-BihjPR0t.js} +11 -5
- package/dist/{problem-DlgB0lYl.d.ts → problem-U8UEKccv.d.ts} +6 -4
- package/dist/query/index.d.ts +2 -2
- package/dist/query/index.js +2 -2
- package/dist/{query-ChvDbsDE.js → query-BMMSWbI7.js} +19 -19
- package/dist/react/index.d.ts +7 -7
- package/dist/react/index.js +2 -2
- package/dist/react/server.d.ts +6 -6
- package/dist/react/server.js +3 -3
- package/dist/react/session.d.ts +21 -2
- package/dist/react/session.js +19 -1
- package/dist/{react-C83BdBGt.js → react-CQHMaESR.js} +59 -55
- package/dist/{read-set-4lI3W_gZ.js → read-set-FWK8qQ58.js} +51 -16
- package/dist/realtime/index.d.ts +4 -3
- package/dist/realtime/index.js +19 -17
- package/dist/{index-CG69s15v.d.ts → refresh-BwYkyNOQ.d.ts} +7 -3
- package/dist/{resolve-CjHILk2w.d.ts → resolve-BAqQcwMW.d.ts} +17 -11
- package/dist/{resource-CgZa3YG_.d.ts → resource-BJcaIfxi.d.ts} +17 -8
- package/dist/{resource-BHEWmQJK.js → resource-My_y-Syh.js} +43 -21
- package/dist/{respond-Dne1ARSa.d.ts → respond-DgIbdrt8.d.ts} +39 -14
- package/dist/{result-DWXatkd6.js → result-Bj6yt33D.js} +2 -2
- package/dist/{result-CTkCZ6JA.d.ts → result-CqEsbgYs.d.ts} +16 -11
- package/dist/server/index.d.ts +38 -13
- package/dist/server/index.js +43 -14
- package/dist/{respond-DMcbQwfN.js → server-BA75B0mT.js} +151 -96
- package/dist/{shared-_6-uPL7E.js → shared-DnoCdMDr.js} +4 -3
- package/dist/{simplify-bwJpLnaS.js → simplify-Cqvfr9dj.js} +76 -39
- package/dist/sql/index.d.ts +139 -0
- package/dist/sql/index.js +1983 -0
- package/dist/{sql-DTjA1LPj.js → sql-B34HU2DI.js} +74 -17
- 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-CyhRzctb.d.ts → standard-BsaCYQJc.d.ts} +1 -1
- package/dist/{stats-C5W-rBfR.js → stats-C_YxA2r1.js} +40 -14
- package/dist/storage/index.d.ts +4 -3
- package/dist/storage/index.js +548 -1
- package/dist/{tables-rZxRxNPW.js → tables-Cb-3_VWc.js} +19 -5
- package/dist/temporal-BwshQk0W.js +27 -0
- package/dist/temporal-required-CBNHT6ni.js +19 -0
- package/dist/testing/index.d.ts +25 -24
- package/dist/testing/index.js +165 -66
- package/dist/{types-C83v5SQz.d.ts → types-DONv9SHN.d.ts} +14 -11
- package/dist/version-Bmf7_FzM.js +4 -0
- package/dist/{view-D1s0wa0T.d.ts → view-B64o81wp.d.ts} +36 -6
- package/dist/{view-aOYizTeE.js → view-BrJI2LKp.js} +11 -2
- package/dist/webhooks/index.d.ts +19 -17
- package/dist/webhooks/index.js +1 -1
- package/dist/{webhooks-DMipjhSP.js → webhooks-Bh_Jf_-l.js} +45 -24
- package/package.json +50 -22
- package/schemas/config-v1.json +31 -1
- package/schemas/doctor-report-v1.json +17 -1
- package/schemas/snapshot-v2.json +35 -0
- package/skills/better-supabase/SKILL.md +77 -18
- package/skills/better-supabase/references/plugins.md +21 -22
- package/skills/better-supabase/references/troubleshooting.md +38 -18
- package/skills/better-supabase-api/SKILL.md +66 -18
- package/skills/better-supabase-api/references/adapters.md +64 -41
- 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 +68 -11
- package/dist/casing-da0uRTqt.js +0 -14
- package/dist/claims-CoTobNC-.js +0 -25
- package/dist/cli-DrSgDOQC.js +0 -6646
- package/dist/env-BEToab0I.js +0 -204
- package/dist/events-BuzTgn2D.js +0 -135
- package/dist/pool-R2m_DkXi.d.ts +0 -37
- package/dist/seed-CzecODcJ.js +0 -101
- package/dist/session-C3LxnQ0e.d.ts +0 -22
- package/dist/session-CqEwzVup.js +0 -20
- package/dist/storage-DuGn38fr.js +0 -527
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
//#region ../../node_modules/.pnpm/citty@0.2.2/node_modules/citty/dist/_chunks/libs/scule.mjs
|
|
3
|
+
const NUMBER_CHAR_RE = /\d/;
|
|
4
|
+
const STR_SPLITTERS = [
|
|
5
|
+
"-",
|
|
6
|
+
"_",
|
|
7
|
+
"/",
|
|
8
|
+
"."
|
|
9
|
+
];
|
|
10
|
+
function isUppercase(char = "") {
|
|
11
|
+
if (NUMBER_CHAR_RE.test(char)) return;
|
|
12
|
+
return char !== char.toLowerCase();
|
|
13
|
+
}
|
|
14
|
+
function splitByCase(str, separators) {
|
|
15
|
+
const splitters = separators ?? STR_SPLITTERS;
|
|
16
|
+
const parts = [];
|
|
17
|
+
if (!str || typeof str !== "string") return parts;
|
|
18
|
+
let buff = "";
|
|
19
|
+
let previousUpper;
|
|
20
|
+
let previousSplitter;
|
|
21
|
+
for (const char of str) {
|
|
22
|
+
const isSplitter = splitters.includes(char);
|
|
23
|
+
if (isSplitter === true) {
|
|
24
|
+
parts.push(buff);
|
|
25
|
+
buff = "";
|
|
26
|
+
previousUpper = void 0;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const isUpper = isUppercase(char);
|
|
30
|
+
if (previousSplitter === false) {
|
|
31
|
+
if (previousUpper === false && isUpper === true) {
|
|
32
|
+
parts.push(buff);
|
|
33
|
+
buff = char;
|
|
34
|
+
previousUpper = isUpper;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (previousUpper === true && isUpper === false && buff.length > 1) {
|
|
38
|
+
const lastChar = buff.at(-1);
|
|
39
|
+
parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
|
|
40
|
+
buff = lastChar + char;
|
|
41
|
+
previousUpper = isUpper;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
buff += char;
|
|
46
|
+
previousUpper = isUpper;
|
|
47
|
+
previousSplitter = isSplitter;
|
|
48
|
+
}
|
|
49
|
+
parts.push(buff);
|
|
50
|
+
return parts;
|
|
51
|
+
}
|
|
52
|
+
function upperFirst(str) {
|
|
53
|
+
return str ? str[0].toUpperCase() + str.slice(1) : "";
|
|
54
|
+
}
|
|
55
|
+
function lowerFirst(str) {
|
|
56
|
+
return str ? str[0].toLowerCase() + str.slice(1) : "";
|
|
57
|
+
}
|
|
58
|
+
function pascalCase(str, opts) {
|
|
59
|
+
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("") : "";
|
|
60
|
+
}
|
|
61
|
+
function camelCase(str, opts) {
|
|
62
|
+
return lowerFirst(pascalCase(str || "", opts));
|
|
63
|
+
}
|
|
64
|
+
function kebabCase(str, joiner) {
|
|
65
|
+
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
|
|
66
|
+
}
|
|
67
|
+
function snakeCase(str) {
|
|
68
|
+
return kebabCase(str || "", "_");
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region ../../node_modules/.pnpm/citty@0.2.2/node_modules/citty/dist/index.mjs
|
|
72
|
+
function toArray(val) {
|
|
73
|
+
if (Array.isArray(val)) return val;
|
|
74
|
+
return val === void 0 ? [] : [val];
|
|
75
|
+
}
|
|
76
|
+
function formatLineColumns(lines, linePrefix = "") {
|
|
77
|
+
const maxLength = [];
|
|
78
|
+
for (const line of lines) for (const [i, element] of line.entries()) maxLength[i] = Math.max(maxLength[i] || 0, element.length);
|
|
79
|
+
return lines.map((l) => l.map((c, i) => linePrefix + c[i === 0 ? "padStart" : "padEnd"](maxLength[i])).join(" ")).join("\n");
|
|
80
|
+
}
|
|
81
|
+
function resolveValue(input) {
|
|
82
|
+
return typeof input === "function" ? input() : input;
|
|
83
|
+
}
|
|
84
|
+
var CLIError = class extends Error {
|
|
85
|
+
code;
|
|
86
|
+
constructor(message, code) {
|
|
87
|
+
super(message);
|
|
88
|
+
this.name = "CLIError";
|
|
89
|
+
this.code = code;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
function parseRawArgs(args = [], opts = {}) {
|
|
93
|
+
const booleans = new Set(opts.boolean || []);
|
|
94
|
+
const strings = new Set(opts.string || []);
|
|
95
|
+
const aliasMap = opts.alias || {};
|
|
96
|
+
const defaults = opts.default || {};
|
|
97
|
+
const aliasToMain = /* @__PURE__ */ new Map();
|
|
98
|
+
const mainToAliases = /* @__PURE__ */ new Map();
|
|
99
|
+
for (const [key, value] of Object.entries(aliasMap)) {
|
|
100
|
+
const targets = value;
|
|
101
|
+
for (const target of targets) {
|
|
102
|
+
aliasToMain.set(key, target);
|
|
103
|
+
if (!mainToAliases.has(target)) mainToAliases.set(target, []);
|
|
104
|
+
mainToAliases.get(target).push(key);
|
|
105
|
+
aliasToMain.set(target, key);
|
|
106
|
+
if (!mainToAliases.has(key)) mainToAliases.set(key, []);
|
|
107
|
+
mainToAliases.get(key).push(target);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const options = {};
|
|
111
|
+
function getType(name) {
|
|
112
|
+
if (booleans.has(name)) return "boolean";
|
|
113
|
+
const aliases = mainToAliases.get(name) || [];
|
|
114
|
+
for (const alias of aliases) if (booleans.has(alias)) return "boolean";
|
|
115
|
+
return "string";
|
|
116
|
+
}
|
|
117
|
+
function isStringType(name) {
|
|
118
|
+
if (strings.has(name)) return true;
|
|
119
|
+
const aliases = mainToAliases.get(name) || [];
|
|
120
|
+
for (const alias of aliases) if (strings.has(alias)) return true;
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
const allOptions = /* @__PURE__ */ new Set([
|
|
124
|
+
...booleans,
|
|
125
|
+
...strings,
|
|
126
|
+
...Object.keys(aliasMap),
|
|
127
|
+
...Object.values(aliasMap).flat(),
|
|
128
|
+
...Object.keys(defaults)
|
|
129
|
+
]);
|
|
130
|
+
for (const name of allOptions) if (!options[name]) options[name] = {
|
|
131
|
+
type: getType(name),
|
|
132
|
+
default: defaults[name]
|
|
133
|
+
};
|
|
134
|
+
for (const [alias, main] of aliasToMain.entries()) if (alias.length === 1 && options[main] && !options[main].short) options[main].short = alias;
|
|
135
|
+
const processedArgs = [];
|
|
136
|
+
const negatedFlags = {};
|
|
137
|
+
for (let i = 0; i < args.length; i++) {
|
|
138
|
+
const arg = args[i];
|
|
139
|
+
if (arg === "--") {
|
|
140
|
+
processedArgs.push(...args.slice(i));
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
if (arg.startsWith("--no-")) {
|
|
144
|
+
const flagName = arg.slice(5);
|
|
145
|
+
negatedFlags[flagName] = true;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
processedArgs.push(arg);
|
|
149
|
+
}
|
|
150
|
+
let parsed;
|
|
151
|
+
try {
|
|
152
|
+
parsed = parseArgs({
|
|
153
|
+
args: processedArgs,
|
|
154
|
+
options: Object.keys(options).length > 0 ? options : void 0,
|
|
155
|
+
allowPositionals: true,
|
|
156
|
+
strict: false
|
|
157
|
+
});
|
|
158
|
+
} catch {
|
|
159
|
+
parsed = {
|
|
160
|
+
values: {},
|
|
161
|
+
positionals: processedArgs
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const out = { _: [] };
|
|
165
|
+
out._ = parsed.positionals;
|
|
166
|
+
for (const [key, value] of Object.entries(parsed.values)) {
|
|
167
|
+
let coerced = value;
|
|
168
|
+
if (getType(key) === "boolean" && typeof value === "string") coerced = value !== "false";
|
|
169
|
+
else if (isStringType(key) && typeof value === "boolean") coerced = "";
|
|
170
|
+
out[key] = coerced;
|
|
171
|
+
}
|
|
172
|
+
for (const [name] of Object.entries(negatedFlags)) {
|
|
173
|
+
out[name] = false;
|
|
174
|
+
const mainName = aliasToMain.get(name);
|
|
175
|
+
if (mainName) out[mainName] = false;
|
|
176
|
+
const aliases = mainToAliases.get(name);
|
|
177
|
+
if (aliases) for (const alias of aliases) out[alias] = false;
|
|
178
|
+
}
|
|
179
|
+
for (const [alias, main] of aliasToMain.entries()) {
|
|
180
|
+
if (out[alias] !== void 0 && out[main] === void 0) out[main] = out[alias];
|
|
181
|
+
if (out[main] !== void 0 && out[alias] === void 0) out[alias] = out[main];
|
|
182
|
+
if (out[alias] !== out[main] && defaults[main] === out[main]) out[main] = out[alias];
|
|
183
|
+
}
|
|
184
|
+
return out;
|
|
185
|
+
}
|
|
186
|
+
const noColor = /* @__PURE__ */ (() => {
|
|
187
|
+
const env = globalThis.process?.env ?? {};
|
|
188
|
+
return env.NO_COLOR === "1" || env.TERM === "dumb" || env.TEST || env.CI;
|
|
189
|
+
})();
|
|
190
|
+
const _c = (c, r = 39) => (t) => noColor ? t : `\u001B[${c}m${t}\u001B[${r}m`;
|
|
191
|
+
const bold = /* @__PURE__ */ _c(1, 22);
|
|
192
|
+
const cyan = /* @__PURE__ */ _c(36);
|
|
193
|
+
const gray = /* @__PURE__ */ _c(90);
|
|
194
|
+
const underline = /* @__PURE__ */ _c(4, 24);
|
|
195
|
+
function parseArgs$1(rawArgs, argsDef) {
|
|
196
|
+
const parseOptions = {
|
|
197
|
+
boolean: [],
|
|
198
|
+
string: [],
|
|
199
|
+
alias: {},
|
|
200
|
+
default: {}
|
|
201
|
+
};
|
|
202
|
+
const args = resolveArgs(argsDef);
|
|
203
|
+
for (const arg of args) {
|
|
204
|
+
if (arg.type === "positional") continue;
|
|
205
|
+
if (arg.type === "string" || arg.type === "enum") parseOptions.string.push(arg.name);
|
|
206
|
+
else if (arg.type === "boolean") parseOptions.boolean.push(arg.name);
|
|
207
|
+
if (arg.default !== void 0) parseOptions.default[arg.name] = arg.default;
|
|
208
|
+
if (arg.alias) parseOptions.alias[arg.name] = arg.alias;
|
|
209
|
+
const camelName = camelCase(arg.name);
|
|
210
|
+
const kebabName = kebabCase(arg.name);
|
|
211
|
+
if (camelName !== arg.name || kebabName !== arg.name) {
|
|
212
|
+
const existingAliases = toArray(parseOptions.alias[arg.name] || []);
|
|
213
|
+
if (camelName !== arg.name && !existingAliases.includes(camelName)) existingAliases.push(camelName);
|
|
214
|
+
if (kebabName !== arg.name && !existingAliases.includes(kebabName)) existingAliases.push(kebabName);
|
|
215
|
+
if (existingAliases.length > 0) parseOptions.alias[arg.name] = existingAliases;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
const parsed = parseRawArgs(rawArgs, parseOptions);
|
|
219
|
+
const [ ...positionalArguments] = parsed._;
|
|
220
|
+
const parsedArgsProxy = new Proxy(parsed, { get(target, prop) {
|
|
221
|
+
return target[prop] ?? target[camelCase(prop)] ?? target[kebabCase(prop)];
|
|
222
|
+
} });
|
|
223
|
+
for (const [, arg] of args.entries()) if (arg.type === "positional") {
|
|
224
|
+
const nextPositionalArgument = positionalArguments.shift();
|
|
225
|
+
if (nextPositionalArgument !== void 0) parsedArgsProxy[arg.name] = nextPositionalArgument;
|
|
226
|
+
else if (arg.default === void 0 && arg.required !== false) throw new CLIError(`Missing required positional argument: ${arg.name.toUpperCase()}`, "EARG");
|
|
227
|
+
else parsedArgsProxy[arg.name] = arg.default;
|
|
228
|
+
} else if (arg.type === "enum") {
|
|
229
|
+
const argument = parsedArgsProxy[arg.name];
|
|
230
|
+
const options = arg.options || [];
|
|
231
|
+
if (argument !== void 0 && options.length > 0 && !options.includes(argument)) throw new CLIError(`Invalid value for argument: ${cyan(`--${arg.name}`)} (${cyan(argument)}). Expected one of: ${options.map((o) => cyan(o)).join(", ")}.`, "EARG");
|
|
232
|
+
} else if (arg.required && parsedArgsProxy[arg.name] === void 0) throw new CLIError(`Missing required argument: --${arg.name}`, "EARG");
|
|
233
|
+
return parsedArgsProxy;
|
|
234
|
+
}
|
|
235
|
+
function resolveArgs(argsDef) {
|
|
236
|
+
const args = [];
|
|
237
|
+
for (const [name, argDef] of Object.entries(argsDef || {})) args.push({
|
|
238
|
+
...argDef,
|
|
239
|
+
name,
|
|
240
|
+
alias: toArray(argDef.alias)
|
|
241
|
+
});
|
|
242
|
+
return args;
|
|
243
|
+
}
|
|
244
|
+
async function resolvePlugins(plugins) {
|
|
245
|
+
return Promise.all(plugins.map((p) => resolveValue(p)));
|
|
246
|
+
}
|
|
247
|
+
function defineCommand(def) {
|
|
248
|
+
return def;
|
|
249
|
+
}
|
|
250
|
+
async function runCommand(cmd, opts) {
|
|
251
|
+
const cmdArgs = await resolveValue(cmd.args || {});
|
|
252
|
+
const parsedArgs = parseArgs$1(opts.rawArgs, cmdArgs);
|
|
253
|
+
const context = {
|
|
254
|
+
rawArgs: opts.rawArgs,
|
|
255
|
+
args: parsedArgs,
|
|
256
|
+
data: opts.data,
|
|
257
|
+
cmd
|
|
258
|
+
};
|
|
259
|
+
const plugins = await resolvePlugins(cmd.plugins ?? []);
|
|
260
|
+
let result;
|
|
261
|
+
let runError;
|
|
262
|
+
try {
|
|
263
|
+
for (const plugin of plugins) await plugin.setup?.(context);
|
|
264
|
+
if (typeof cmd.setup === "function") await cmd.setup(context);
|
|
265
|
+
const subCommands = await resolveValue(cmd.subCommands);
|
|
266
|
+
if (subCommands && Object.keys(subCommands).length > 0) {
|
|
267
|
+
const subCommandArgIndex = findSubCommandIndex(opts.rawArgs, cmdArgs);
|
|
268
|
+
const explicitName = opts.rawArgs[subCommandArgIndex];
|
|
269
|
+
if (explicitName) {
|
|
270
|
+
const subCommand = await _findSubCommand(subCommands, explicitName);
|
|
271
|
+
if (!subCommand) throw new CLIError(`Unknown command ${cyan(explicitName)}`, "E_UNKNOWN_COMMAND");
|
|
272
|
+
await runCommand(subCommand, { rawArgs: opts.rawArgs.slice(subCommandArgIndex + 1) });
|
|
273
|
+
} else {
|
|
274
|
+
const defaultSubCommand = await resolveValue(cmd.default);
|
|
275
|
+
if (defaultSubCommand) {
|
|
276
|
+
if (cmd.run) throw new CLIError(`Cannot specify both 'run' and 'default' on the same command.`, "E_DEFAULT_CONFLICT");
|
|
277
|
+
const subCommand = await _findSubCommand(subCommands, defaultSubCommand);
|
|
278
|
+
if (!subCommand) throw new CLIError(`Default sub command ${cyan(defaultSubCommand)} not found in subCommands.`, "E_UNKNOWN_COMMAND");
|
|
279
|
+
await runCommand(subCommand, { rawArgs: opts.rawArgs });
|
|
280
|
+
} else if (!cmd.run) throw new CLIError(`No command specified.`, "E_NO_COMMAND");
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (typeof cmd.run === "function") result = await cmd.run(context);
|
|
284
|
+
} catch (error) {
|
|
285
|
+
runError = error;
|
|
286
|
+
}
|
|
287
|
+
const cleanupErrors = [];
|
|
288
|
+
if (typeof cmd.cleanup === "function") try {
|
|
289
|
+
await cmd.cleanup(context);
|
|
290
|
+
} catch (error) {
|
|
291
|
+
cleanupErrors.push(error);
|
|
292
|
+
}
|
|
293
|
+
for (const plugin of [...plugins].reverse()) try {
|
|
294
|
+
await plugin.cleanup?.(context);
|
|
295
|
+
} catch (error) {
|
|
296
|
+
cleanupErrors.push(error);
|
|
297
|
+
}
|
|
298
|
+
if (runError) throw runError;
|
|
299
|
+
if (cleanupErrors.length === 1) throw cleanupErrors[0];
|
|
300
|
+
if (cleanupErrors.length > 1) throw new Error("Multiple cleanup errors", { cause: cleanupErrors });
|
|
301
|
+
return { result };
|
|
302
|
+
}
|
|
303
|
+
async function _findSubCommand(subCommands, name) {
|
|
304
|
+
if (name in subCommands) return resolveValue(subCommands[name]);
|
|
305
|
+
for (const sub of Object.values(subCommands)) {
|
|
306
|
+
const resolved = await resolveValue(sub);
|
|
307
|
+
const meta = await resolveValue(resolved?.meta);
|
|
308
|
+
if (meta?.alias) {
|
|
309
|
+
if (toArray(meta.alias).includes(name)) return resolved;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
function findSubCommandIndex(rawArgs, argsDef) {
|
|
314
|
+
for (let i = 0; i < rawArgs.length; i++) {
|
|
315
|
+
const arg = rawArgs[i];
|
|
316
|
+
if (arg === "--") return -1;
|
|
317
|
+
if (arg.startsWith("-")) {
|
|
318
|
+
if (!arg.includes("=") && _isValueFlag(arg, argsDef)) i++;
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
return i;
|
|
322
|
+
}
|
|
323
|
+
return -1;
|
|
324
|
+
}
|
|
325
|
+
function _isValueFlag(flag, argsDef) {
|
|
326
|
+
const name = flag.replace(/^-{1,2}/, "");
|
|
327
|
+
const normalized = camelCase(name);
|
|
328
|
+
for (const [key, def] of Object.entries(argsDef)) {
|
|
329
|
+
if (def.type !== "string" && def.type !== "enum") continue;
|
|
330
|
+
if (normalized === camelCase(key)) return true;
|
|
331
|
+
if ((Array.isArray(def.alias) ? def.alias : def.alias ? [def.alias] : []).includes(name)) return true;
|
|
332
|
+
}
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
const negativePrefixRe = /^no[-A-Z]/;
|
|
336
|
+
async function renderUsage(cmd, parent) {
|
|
337
|
+
const cmdMeta = await resolveValue(cmd.meta || {});
|
|
338
|
+
const cmdArgs = resolveArgs(await resolveValue(cmd.args || {}));
|
|
339
|
+
const parentMeta = await resolveValue(parent?.meta || {});
|
|
340
|
+
const commandName = `${parentMeta.name ? `${parentMeta.name} ` : ""}` + (cmdMeta.name || process.argv[1]);
|
|
341
|
+
const argLines = [];
|
|
342
|
+
const posLines = [];
|
|
343
|
+
const commandsLines = [];
|
|
344
|
+
const usageLine = [];
|
|
345
|
+
for (const arg of cmdArgs) if (arg.type === "positional") {
|
|
346
|
+
const name = arg.name.toUpperCase();
|
|
347
|
+
const isRequired = arg.required !== false && arg.default === void 0;
|
|
348
|
+
posLines.push([cyan(name + renderValueHint(arg)), renderDescription(arg, isRequired)]);
|
|
349
|
+
usageLine.push(isRequired ? `<${name}>` : `[${name}]`);
|
|
350
|
+
} else {
|
|
351
|
+
const isRequired = arg.required === true && arg.default === void 0;
|
|
352
|
+
const argStr = [...(arg.alias || []).map((a) => `-${a}`), `--${arg.name}`].join(", ") + renderValueHint(arg);
|
|
353
|
+
argLines.push([cyan(argStr), renderDescription(arg, isRequired)]);
|
|
354
|
+
/**
|
|
355
|
+
* print negative boolean arg variant usage when
|
|
356
|
+
* - enabled by default or has `negativeDescription`
|
|
357
|
+
* - not prefixed with `no-` or `no[A-Z]`
|
|
358
|
+
*/
|
|
359
|
+
if (arg.type === "boolean" && (arg.default === true || arg.negativeDescription) && !negativePrefixRe.test(arg.name)) {
|
|
360
|
+
const negativeArgStr = [...(arg.alias || []).map((a) => `--no-${a}`), `--no-${arg.name}`].join(", ");
|
|
361
|
+
argLines.push([cyan(negativeArgStr), [arg.negativeDescription, isRequired ? gray("(Required)") : ""].filter(Boolean).join(" ")]);
|
|
362
|
+
}
|
|
363
|
+
if (isRequired) usageLine.push(`--${arg.name}` + renderValueHint(arg));
|
|
364
|
+
}
|
|
365
|
+
if (cmd.subCommands) {
|
|
366
|
+
const commandNames = [];
|
|
367
|
+
const subCommands = await resolveValue(cmd.subCommands);
|
|
368
|
+
for (const [name, sub] of Object.entries(subCommands)) {
|
|
369
|
+
const meta = await resolveValue((await resolveValue(sub))?.meta);
|
|
370
|
+
if (meta?.hidden) continue;
|
|
371
|
+
const aliases = toArray(meta?.alias);
|
|
372
|
+
const label = [name, ...aliases].join(", ");
|
|
373
|
+
commandsLines.push([cyan(label), meta?.description || ""]);
|
|
374
|
+
commandNames.push(name, ...aliases);
|
|
375
|
+
}
|
|
376
|
+
usageLine.push(commandNames.join("|"));
|
|
377
|
+
}
|
|
378
|
+
const usageLines = [];
|
|
379
|
+
const version = cmdMeta.version || parentMeta.version;
|
|
380
|
+
usageLines.push(gray(`${cmdMeta.description} (${commandName + (version ? ` v${version}` : "")})`), "");
|
|
381
|
+
const hasOptions = argLines.length > 0 || posLines.length > 0;
|
|
382
|
+
usageLines.push(`${underline(bold("USAGE"))} ${cyan(`${commandName}${hasOptions ? " [OPTIONS]" : ""} ${usageLine.join(" ")}`)}`, "");
|
|
383
|
+
if (posLines.length > 0) {
|
|
384
|
+
usageLines.push(underline(bold("ARGUMENTS")), "");
|
|
385
|
+
usageLines.push(formatLineColumns(posLines, " "));
|
|
386
|
+
usageLines.push("");
|
|
387
|
+
}
|
|
388
|
+
if (argLines.length > 0) {
|
|
389
|
+
usageLines.push(underline(bold("OPTIONS")), "");
|
|
390
|
+
usageLines.push(formatLineColumns(argLines, " "));
|
|
391
|
+
usageLines.push("");
|
|
392
|
+
}
|
|
393
|
+
if (commandsLines.length > 0) {
|
|
394
|
+
usageLines.push(underline(bold("COMMANDS")), "");
|
|
395
|
+
usageLines.push(formatLineColumns(commandsLines, " "));
|
|
396
|
+
usageLines.push("", `Use ${cyan(`${commandName} <command> --help`)} for more information about a command.`);
|
|
397
|
+
}
|
|
398
|
+
return usageLines.filter((l) => typeof l === "string").join("\n");
|
|
399
|
+
}
|
|
400
|
+
function renderValueHint(arg) {
|
|
401
|
+
const valueHint = arg.valueHint ? `=<${arg.valueHint}>` : "";
|
|
402
|
+
const fallbackValueHint = valueHint || `=<${snakeCase(arg.name)}>`;
|
|
403
|
+
if (!arg.type || arg.type === "positional" || arg.type === "boolean") return valueHint;
|
|
404
|
+
if (arg.type === "enum" && arg.options?.length) return `=<${arg.options.join("|")}>`;
|
|
405
|
+
return fallbackValueHint;
|
|
406
|
+
}
|
|
407
|
+
function renderDescription(arg, required) {
|
|
408
|
+
const requiredHint = required ? gray("(Required)") : "";
|
|
409
|
+
const defaultHint = arg.default === void 0 ? "" : gray(`(Default: ${arg.default})`);
|
|
410
|
+
return [
|
|
411
|
+
arg.description,
|
|
412
|
+
requiredHint,
|
|
413
|
+
defaultHint
|
|
414
|
+
].filter(Boolean).join(" ");
|
|
415
|
+
}
|
|
416
|
+
//#endregion
|
|
417
|
+
//#region src/cli/command.ts
|
|
418
|
+
/** Options every command accepts; `run()` reads them before the command starts. */
|
|
419
|
+
const GLOBAL_ARGS = {
|
|
420
|
+
cwd: {
|
|
421
|
+
type: "string",
|
|
422
|
+
description: "Project directory",
|
|
423
|
+
valueHint: "dir"
|
|
424
|
+
},
|
|
425
|
+
config: {
|
|
426
|
+
type: "string",
|
|
427
|
+
description: "Config file, relative to --cwd",
|
|
428
|
+
valueHint: "file"
|
|
429
|
+
},
|
|
430
|
+
json: {
|
|
431
|
+
type: "boolean",
|
|
432
|
+
description: "Print one JSON document on stdout; errors as Problem Details"
|
|
433
|
+
},
|
|
434
|
+
yes: {
|
|
435
|
+
type: "boolean",
|
|
436
|
+
alias: "y",
|
|
437
|
+
description: "Ask nothing; use the flags and the defaults"
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
const LISTS = /* @__PURE__ */ new WeakMap();
|
|
441
|
+
/** A citty command that receives the `CliContext` and returns a `CommandResult`. */
|
|
442
|
+
function defineCliCommand(def) {
|
|
443
|
+
const command = defineCommand({
|
|
444
|
+
meta: def.meta,
|
|
445
|
+
args: {
|
|
446
|
+
...def.args,
|
|
447
|
+
...GLOBAL_ARGS
|
|
448
|
+
},
|
|
449
|
+
run: ({ args, data }) => def.run(args, cliContext(data))
|
|
450
|
+
});
|
|
451
|
+
LISTS.set(command, def.lists ?? []);
|
|
452
|
+
return command;
|
|
453
|
+
}
|
|
454
|
+
/** The list options a command declared through `defineCliCommand`. */
|
|
455
|
+
function listArgs(command) {
|
|
456
|
+
return LISTS.get(command) ?? [];
|
|
457
|
+
}
|
|
458
|
+
/** Splits a comma-separated option into its trimmed, non-empty parts. */
|
|
459
|
+
function list(value) {
|
|
460
|
+
return (value ?? "").split(",").map((item) => item.trim()).filter(Boolean);
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Joins repeated list options (`--only a --only b`) into one comma-separated
|
|
464
|
+
* value, because citty keeps only the last occurrence.
|
|
465
|
+
*/
|
|
466
|
+
function joinRepeated(argv, names) {
|
|
467
|
+
if (names.length === 0) return [...argv];
|
|
468
|
+
const lists = new Set(names);
|
|
469
|
+
const values = /* @__PURE__ */ new Map();
|
|
470
|
+
const rest = [];
|
|
471
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
472
|
+
const token = argv[index];
|
|
473
|
+
if (token === "--") {
|
|
474
|
+
rest.push(...argv.slice(index));
|
|
475
|
+
break;
|
|
476
|
+
}
|
|
477
|
+
const match = /^--([^=]+)(?:=(.*))?$/.exec(token);
|
|
478
|
+
const name = match?.[1];
|
|
479
|
+
if (name === void 0 || !lists.has(name)) {
|
|
480
|
+
rest.push(token);
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
let value = match?.[2];
|
|
484
|
+
if (value === void 0) {
|
|
485
|
+
const next = argv[index + 1];
|
|
486
|
+
if (next === void 0 || next.startsWith("-")) continue;
|
|
487
|
+
value = next;
|
|
488
|
+
index += 1;
|
|
489
|
+
}
|
|
490
|
+
values.set(name, [...values.get(name) ?? [], value]);
|
|
491
|
+
}
|
|
492
|
+
return [...[...values].map(([name, parts]) => `--${name}=${parts.join(",")}`), ...rest];
|
|
493
|
+
}
|
|
494
|
+
function isCliContext(value) {
|
|
495
|
+
return typeof value === "object" && value !== null && "config" in value && "io" in value && "env" in value && "json" in value;
|
|
496
|
+
}
|
|
497
|
+
function cliContext(data) {
|
|
498
|
+
if (!isCliContext(data)) throw new TypeError("better-supabase commands run through run() from better-supabase/cli");
|
|
499
|
+
return data;
|
|
500
|
+
}
|
|
501
|
+
//#endregion
|
|
502
|
+
export { list as a, parseArgs$1 as c, joinRepeated as i, renderUsage as l, cliContext as n, listArgs as o, defineCliCommand as r, defineCommand as s, GLOBAL_ARGS as t, runCommand as u };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/cli/compare.ts
|
|
2
|
+
/**
|
|
3
|
+
* Orders strings by UTF-16 code unit, the order `Array.prototype.sort` uses.
|
|
4
|
+
* Unlike `localeCompare`, the result does not depend on the machine's locale,
|
|
5
|
+
* so generated files and reports are byte-identical everywhere.
|
|
6
|
+
*/
|
|
7
|
+
const byCodePoint = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { byCodePoint as t };
|