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.
Files changed (172) hide show
  1. package/README.md +7 -6
  2. package/bin/better-supabase.js +4 -0
  3. package/dist/{base64-CQeB1eSf.js → base64-D2gsioCY.js} +2 -2
  4. package/dist/claims-BAf6c7is.js +48 -0
  5. package/dist/cli/_format-Cax5EsM9.js +101 -0
  6. package/dist/cli/bin.d.ts +1 -0
  7. package/dist/cli/bin.js +48 -0
  8. package/dist/cli/command-CK14fP91.js +502 -0
  9. package/dist/cli/compare-BmIWVEui.js +9 -0
  10. package/dist/cli/config-D9R0o1LH.js +1895 -0
  11. package/dist/cli/config-SSKSTUl2.js +2 -0
  12. package/dist/cli/db-DOBPt660.js +52 -0
  13. package/dist/cli/dist-B1MvLv-M.js +129 -0
  14. package/dist/cli/dist-CFgGknmZ.js +1112 -0
  15. package/dist/cli/dist-Du7VnEUG.js +621 -0
  16. package/dist/cli/doctor-BOym3mbL.js +2382 -0
  17. package/dist/cli/env-BZ0uy8XK.js +108 -0
  18. package/dist/cli/env-jIFUADLY.js +511 -0
  19. package/dist/cli/errors-4v4DTtda.js +56 -0
  20. package/dist/cli/fastest-levenshtein-CFN-lNDv.js +120 -0
  21. package/dist/cli/gen-Ccn_p90L.js +2008 -0
  22. package/dist/cli/gen-D5cLCULx.js +2 -0
  23. package/dist/cli/index.d.ts +493 -0
  24. package/dist/cli/index.js +184 -0
  25. package/dist/cli/init-ClnxRYBF.js +550 -0
  26. package/dist/cli/introspect-DxqfkVIv.js +81 -0
  27. package/dist/cli/io-k41_z-jT.js +24 -0
  28. package/dist/cli/json5-ChRycquj.js +787 -0
  29. package/dist/cli/jsonc-BUniUpOk.js +2 -0
  30. package/dist/cli/jsonc-D5Fu67jw.js +45 -0
  31. package/dist/cli/keys-ByKHnvP9.js +83 -0
  32. package/dist/cli/ohash-D7bG_EOb.js +277 -0
  33. package/dist/cli/openapi-8WHjxiTJ.js +66 -0
  34. package/dist/cli/project-B_GeXyHh.js +70 -0
  35. package/dist/cli/prompts-BNcNfAve.js +1142 -0
  36. package/dist/cli/prompts-BTYQGunc.js +2 -0
  37. package/dist/cli/read-sets-CMa29t9a.js +971 -0
  38. package/dist/cli/rolldown-runtime-BPOCksWG.js +24 -0
  39. package/dist/cli/run-CP20LKk_.js +347 -0
  40. package/dist/cli/seed-5J6eu_Xg.js +98 -0
  41. package/dist/cli/skills-LJJIhLFR.js +137 -0
  42. package/dist/cli/sql-D4VbqmXi.js +199 -0
  43. package/dist/cli/style-C0NFdJRL.js +29 -0
  44. package/dist/cli/toml-DB-MNnFs.js +424 -0
  45. package/dist/cli/version-5mW_8sY1.js +4 -0
  46. package/dist/cli/yaml-CYCbJ6et.js +2252 -0
  47. package/dist/client/index.d.ts +2 -2
  48. package/dist/client/index.js +13 -13
  49. package/dist/{compiler-2zqGzxVZ.d.ts → compiler-DB3aSFOA.d.ts} +2 -2
  50. package/dist/config/index.js +4 -4
  51. package/dist/{config-Be4GwsqI.js → config-BpxDfnbg.js} +1 -1
  52. package/dist/{config-DOsGYSiT.js → config-CbvFmGD8.js} +1 -1
  53. package/dist/{define-DF341GDj.js → define-Bh0AqTik.js} +160 -79
  54. package/dist/{define-DUbydmJa.d.ts → define-CRS2MRV3.d.ts} +32 -28
  55. package/dist/edge/index.d.ts +8 -12
  56. package/dist/edge/index.js +50 -24
  57. package/dist/{entitlements-DvJXoI02.d.ts → entitlements-Dm-FHpNH.d.ts} +2 -2
  58. package/dist/{errors-Bl3rkOzo.js → errors-L0xK41y_.js} +1 -1
  59. package/dist/events/index.d.ts +1 -1
  60. package/dist/events/index.js +4 -4
  61. package/dist/{events-Do8jXh4D.d.ts → events-B21UOhvP.d.ts} +4 -4
  62. package/dist/{executor-DynmIWhq.d.ts → executor-B5IoUxLE.d.ts} +1 -1
  63. package/dist/{executor-C57jx2pn.js → executor-CVt6dD0B.js} +3 -3
  64. package/dist/{executor-B26lgbHD.d.ts → executor-CZ7ImRiD.d.ts} +2 -2
  65. package/dist/hono/index.d.ts +16 -23
  66. package/dist/hono/index.js +10 -10
  67. package/dist/{index-CTTMS6_1.d.ts → index-528Ugmyp.d.ts} +12 -3
  68. package/dist/{index-CADlNHK-.d.ts → index-BAy4tsAP.d.ts} +5 -5
  69. package/dist/{index-BNsABq7P.d.ts → index-BBdvo-5d.d.ts} +23 -25
  70. package/dist/{index-qriRM9cZ.d.ts → index-BhHEC04r.d.ts} +3 -3
  71. package/dist/{index-GV77NpRP.d.ts → index-D5IfUIDh.d.ts} +3 -3
  72. package/dist/{index-CriFFJ_p.d.ts → index-DFmOpBGC.d.ts} +11 -11
  73. package/dist/{index-UJ-LUxtI.d.ts → index-RlLXd8dL.d.ts} +12 -12
  74. package/dist/index.d.ts +15 -15
  75. package/dist/index.js +13 -13
  76. package/dist/{invalidate-DbxuL2jL.js → invalidate-CgxmRamI.js} +7 -1
  77. package/dist/jobs/index.d.ts +10 -4
  78. package/dist/jobs/index.js +32 -16
  79. package/dist/{json-schema--aOXAGfU.js → json-schema-DP6V7cbr.js} +1 -1
  80. package/dist/list/index.d.ts +1 -1
  81. package/dist/list/index.js +3 -3
  82. package/dist/{live-QE3UPbGm.d.ts → live-BHakSWWo.d.ts} +12 -12
  83. package/dist/{live-D8rV1Ldw.js → live-CdJBOc4f.js} +13 -9
  84. package/dist/lookup-BaP5bI27.js +18 -0
  85. package/dist/mcp/index.d.ts +18 -18
  86. package/dist/mcp/index.js +23 -18
  87. package/dist/{mfa-x3V3vGh-.d.ts → mfa-C7MNQ1Ob.d.ts} +1 -1
  88. package/dist/{mfa-BxoR1RkN.js → mfa-byfjruR9.js} +118 -29
  89. package/dist/next/image/index.js +6 -3
  90. package/dist/next/index.d.ts +38 -35
  91. package/dist/next/index.js +41 -33
  92. package/dist/openapi/index.d.ts +1 -1
  93. package/dist/openapi/index.js +6 -6
  94. package/dist/orpc/index.d.ts +17 -20
  95. package/dist/orpc/index.js +11 -11
  96. package/dist/otel/index.d.ts +5 -5
  97. package/dist/otel/index.js +81 -62
  98. package/dist/{permdock-sql-Bta_G0v-.js → permdock-sql-C4KFzLc9.js} +1 -1
  99. package/dist/{plugin-DVRB8qNE.d.ts → plugin-bNhvJwRh.d.ts} +2 -2
  100. package/dist/plugins/actor/index.d.ts +1 -1
  101. package/dist/plugins/actor/index.js +1 -1
  102. package/dist/plugins/rules/index.d.ts +2 -2
  103. package/dist/plugins/rules/index.js +42 -12
  104. package/dist/plugins/soft-delete/index.d.ts +2 -2
  105. package/dist/plugins/soft-delete/index.js +2 -2
  106. package/dist/plugins/tenant/index.d.ts +2 -2
  107. package/dist/plugins/tenant/index.js +10 -4
  108. package/dist/plugins/timestamps/index.d.ts +1 -1
  109. package/dist/plugins/timestamps/index.js +1 -1
  110. package/dist/plugins/validation/index.d.ts +2 -2
  111. package/dist/plugins/validation/index.js +3 -3
  112. package/dist/{pool-B9qsLyFR.d.ts → pool-DFwEQwmN.d.ts} +11 -4
  113. package/dist/postgres/index.d.ts +5 -5
  114. package/dist/postgres/index.js +3 -2
  115. package/dist/{postgrest-DmBlevh-.d.ts → postgrest-Bc-0Xw62.d.ts} +1 -1
  116. package/dist/{problem-CGt1ADix.js → problem-BihjPR0t.js} +1 -1
  117. package/dist/{problem-Z2RTQjZD.d.ts → problem-U8UEKccv.d.ts} +1 -1
  118. package/dist/query/index.d.ts +2 -2
  119. package/dist/query/index.js +2 -2
  120. package/dist/{query-BdKLTPlj.js → query-BMMSWbI7.js} +18 -18
  121. package/dist/react/index.d.ts +6 -6
  122. package/dist/react/index.js +1 -1
  123. package/dist/react/server.d.ts +5 -5
  124. package/dist/react/server.js +3 -3
  125. package/dist/react/session.d.ts +4 -4
  126. package/dist/react/session.js +2 -2
  127. package/dist/{react-DNBYNazu.js → react-CQHMaESR.js} +39 -39
  128. package/dist/{read-set-D0qBcboM.js → read-set-FWK8qQ58.js} +50 -15
  129. package/dist/realtime/index.d.ts +1 -1
  130. package/dist/realtime/index.js +13 -12
  131. package/dist/{index-kpgopLNv.d.ts → refresh-BwYkyNOQ.d.ts} +6 -3
  132. package/dist/{resolve-BRciX2jK.d.ts → resolve-BAqQcwMW.d.ts} +15 -10
  133. package/dist/{resource-CwVgiI5q.d.ts → resource-BJcaIfxi.d.ts} +5 -5
  134. package/dist/{resource-D30rp0GN.js → resource-My_y-Syh.js} +6 -6
  135. package/dist/{respond-DAkPIdTH.d.ts → respond-DgIbdrt8.d.ts} +31 -12
  136. package/dist/{result-DWXatkd6.js → result-Bj6yt33D.js} +2 -2
  137. package/dist/{result-c2OYgCV2.d.ts → result-CqEsbgYs.d.ts} +3 -3
  138. package/dist/server/index.d.ts +14 -14
  139. package/dist/server/index.js +12 -12
  140. package/dist/{respond-C44EZAJo.js → server-BA75B0mT.js} +139 -100
  141. package/dist/{shared-_6-uPL7E.js → shared-DnoCdMDr.js} +4 -3
  142. package/dist/{simplify-LakqK1vH.js → simplify-Cqvfr9dj.js} +67 -24
  143. package/dist/sql/index.d.ts +1 -1
  144. package/dist/sql/index.js +7 -7
  145. package/dist/{sql-BIgk12ew.js → sql-B34HU2DI.js} +3 -2
  146. package/dist/ssr/index.d.ts +4 -4
  147. package/dist/ssr/index.js +2 -2
  148. package/dist/{standard-FUi3Z3-7.js → standard-BRyBGTtp.js} +2 -2
  149. package/dist/{standard-eudBiRk1.d.ts → standard-BsaCYQJc.d.ts} +1 -1
  150. package/dist/{stats-D78UQ8Yu.js → stats-C_YxA2r1.js} +33 -8
  151. package/dist/storage/index.d.ts +2 -2
  152. package/dist/storage/index.js +26 -8
  153. package/dist/{tables-Dhha3BXM.js → tables-Cb-3_VWc.js} +14 -0
  154. package/dist/{temporal-required-CMxeSVPo.js → temporal-required-CBNHT6ni.js} +1 -1
  155. package/dist/testing/index.d.ts +20 -21
  156. package/dist/testing/index.js +45 -45
  157. package/dist/{version-BfpG2gks.js → version-Bmf7_FzM.js} +1 -1
  158. package/dist/{view-3Po_PVlr.d.ts → view-B64o81wp.d.ts} +5 -5
  159. package/dist/{view-wZ-9qIUz.js → view-BrJI2LKp.js} +1 -1
  160. package/dist/webhooks/index.d.ts +3 -3
  161. package/dist/webhooks/index.js +1 -1
  162. package/dist/{webhooks-CAIFQSTM.js → webhooks-Bh_Jf_-l.js} +37 -18
  163. package/package.json +36 -4
  164. package/skills/better-supabase/SKILL.md +57 -10
  165. package/skills/better-supabase/references/plugins.md +7 -11
  166. package/skills/better-supabase/references/troubleshooting.md +24 -4
  167. package/skills/better-supabase-api/SKILL.md +66 -18
  168. package/skills/better-supabase-api/references/adapters.md +44 -26
  169. package/skills/better-supabase-auth/SKILL.md +146 -0
  170. package/skills/better-supabase-auth/references/permdock.md +55 -0
  171. package/skills/better-supabase-testing/SKILL.md +58 -4
  172. package/dist/claims-CoTobNC-.js +0 -25
@@ -0,0 +1,1895 @@
1
+ import { n as CliError } from "./errors-4v4DTtda.js";
2
+ import { t as display } from "./io-k41_z-jT.js";
3
+ import { c as resolve$1, i as extname, n as basename$1, o as join$1, r as dirname$1, s as normalize$1, t as resolveModulePath } from "./dist-CFgGknmZ.js";
4
+ import { a as literal, c as picklist, d as safeParse, f as strictObject, h as unknown, i as getDotPath, m as union, n as boolean, o as number, p as string, r as custom, s as optional, t as array, u as record } from "./dist-Du7VnEUG.js";
5
+ import * as nodeUtil from "node:util";
6
+ import { join, posix, resolve } from "node:path";
7
+ import { existsSync, readFileSync, statSync } from "node:fs";
8
+ import { glob, readFile, rm } from "node:fs/promises";
9
+ import { pathToFileURL } from "node:url";
10
+ import { homedir } from "node:os";
11
+ import { resolveConfig } from "better-supabase/config";
12
+ //#region ../../node_modules/.pnpm/rc9@3.1.0/node_modules/rc9/dist/_chunks/libs/flat.mjs
13
+ function isBuffer(obj) {
14
+ return obj && obj.constructor && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
15
+ }
16
+ function keyIdentity(key) {
17
+ return key;
18
+ }
19
+ function flatten(target, opts) {
20
+ opts = opts || {};
21
+ const delimiter = opts.delimiter || ".";
22
+ const maxDepth = opts.maxDepth;
23
+ const transformKey = opts.transformKey || keyIdentity;
24
+ const output = {};
25
+ function step(object, prev, currentDepth) {
26
+ currentDepth = currentDepth || 1;
27
+ Object.keys(object).forEach(function(key) {
28
+ const value = object[key];
29
+ const isarray = opts.safe && Array.isArray(value);
30
+ const type = Object.prototype.toString.call(value);
31
+ const isbuffer = isBuffer(value);
32
+ const isobject = type === "[object Object]" || type === "[object Array]";
33
+ const newKey = prev ? prev + delimiter + transformKey(key) : transformKey(key);
34
+ if (!isarray && !isbuffer && isobject && Object.keys(value).length && (!opts.maxDepth || currentDepth < maxDepth)) return step(value, newKey, currentDepth + 1);
35
+ output[newKey] = value;
36
+ });
37
+ }
38
+ step(target);
39
+ return output;
40
+ }
41
+ function unflatten(target, opts) {
42
+ opts = opts || {};
43
+ const delimiter = opts.delimiter || ".";
44
+ const overwrite = opts.overwrite || false;
45
+ const transformKey = opts.transformKey || keyIdentity;
46
+ const result = {};
47
+ if (isBuffer(target) || Object.prototype.toString.call(target) !== "[object Object]") return target;
48
+ function getkey(key) {
49
+ const parsedKey = Number(key);
50
+ return isNaN(parsedKey) || key.indexOf(".") !== -1 || opts.object ? key : parsedKey;
51
+ }
52
+ function addKeys(keyPrefix, recipient, target) {
53
+ return Object.keys(target).reduce(function(result, key) {
54
+ result[keyPrefix + delimiter + key] = target[key];
55
+ return result;
56
+ }, recipient);
57
+ }
58
+ function isEmpty(val) {
59
+ const type = Object.prototype.toString.call(val);
60
+ const isArray = type === "[object Array]";
61
+ const isObject = type === "[object Object]";
62
+ if (!val) return true;
63
+ else if (isArray) return !val.length;
64
+ else if (isObject) return !Object.keys(val).length;
65
+ }
66
+ target = Object.keys(target).reduce(function(result, key) {
67
+ const type = Object.prototype.toString.call(target[key]);
68
+ if (!(type === "[object Object]" || type === "[object Array]") || isEmpty(target[key])) {
69
+ result[key] = target[key];
70
+ return result;
71
+ } else return addKeys(key, result, flatten(target[key], opts));
72
+ }, {});
73
+ Object.keys(target).forEach(function(key) {
74
+ const split = key.split(delimiter).map(transformKey);
75
+ let key1 = getkey(split.shift());
76
+ let key2 = getkey(split[0]);
77
+ let recipient = result;
78
+ while (key2 !== void 0) {
79
+ if (key1 === "__proto__") return;
80
+ const type = Object.prototype.toString.call(recipient[key1]);
81
+ const isobject = type === "[object Object]" || type === "[object Array]";
82
+ if (!overwrite && !isobject && typeof recipient[key1] !== "undefined") return;
83
+ if (overwrite && !isobject || !overwrite && recipient[key1] == null) recipient[key1] = typeof key2 === "number" && !opts.object ? [] : {};
84
+ recipient = recipient[key1];
85
+ if (split.length > 0) {
86
+ key1 = getkey(split.shift());
87
+ key2 = getkey(split[0]);
88
+ }
89
+ }
90
+ recipient[key1] = unflatten(target[key], opts);
91
+ });
92
+ return result;
93
+ }
94
+ //#endregion
95
+ //#region ../../node_modules/.pnpm/destr@2.0.5/node_modules/destr/dist/index.mjs
96
+ const suspectProtoRx = /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/;
97
+ const suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
98
+ const JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
99
+ function jsonParseTransform(key, value) {
100
+ if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
101
+ warnKeyDropped(key);
102
+ return;
103
+ }
104
+ return value;
105
+ }
106
+ function warnKeyDropped(key) {
107
+ console.warn(`[destr] Dropping "${key}" key to prevent prototype pollution.`);
108
+ }
109
+ function destr(value, options = {}) {
110
+ if (typeof value !== "string") return value;
111
+ if (value[0] === "\"" && value[value.length - 1] === "\"" && value.indexOf("\\") === -1) return value.slice(1, -1);
112
+ const _value = value.trim();
113
+ if (_value.length <= 9) switch (_value.toLowerCase()) {
114
+ case "true": return true;
115
+ case "false": return false;
116
+ case "undefined": return;
117
+ case "null": return null;
118
+ case "nan": return NaN;
119
+ case "infinity": return Number.POSITIVE_INFINITY;
120
+ case "-infinity": return Number.NEGATIVE_INFINITY;
121
+ }
122
+ if (!JsonSigRx.test(value)) {
123
+ if (options.strict) throw new SyntaxError("[destr] Invalid JSON");
124
+ return value;
125
+ }
126
+ try {
127
+ if (suspectProtoRx.test(value) || suspectConstructorRx.test(value)) {
128
+ if (options.strict) throw new Error("[destr] Possible prototype pollution");
129
+ return JSON.parse(value, jsonParseTransform);
130
+ }
131
+ return JSON.parse(value);
132
+ } catch (error) {
133
+ if (options.strict) throw error;
134
+ return value;
135
+ }
136
+ }
137
+ //#endregion
138
+ //#region ../../node_modules/.pnpm/defu@6.1.7/node_modules/defu/dist/defu.mjs
139
+ function isPlainObject(value) {
140
+ if (value === null || typeof value !== "object") return false;
141
+ const prototype = Object.getPrototypeOf(value);
142
+ if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) return false;
143
+ if (Symbol.iterator in value) return false;
144
+ if (Symbol.toStringTag in value) return Object.prototype.toString.call(value) === "[object Module]";
145
+ return true;
146
+ }
147
+ function _defu(baseObject, defaults, namespace = ".", merger) {
148
+ if (!isPlainObject(defaults)) return _defu(baseObject, {}, namespace, merger);
149
+ const object = { ...defaults };
150
+ for (const key of Object.keys(baseObject)) {
151
+ if (key === "__proto__" || key === "constructor") continue;
152
+ const value = baseObject[key];
153
+ if (value === null || value === void 0) continue;
154
+ if (merger && merger(object, key, value, namespace)) continue;
155
+ if (Array.isArray(value) && Array.isArray(object[key])) object[key] = [...value, ...object[key]];
156
+ else if (isPlainObject(value) && isPlainObject(object[key])) object[key] = _defu(value, object[key], (namespace ? `${namespace}.` : "") + key.toString(), merger);
157
+ else object[key] = value;
158
+ }
159
+ return object;
160
+ }
161
+ function createDefu(merger) {
162
+ return (...arguments_) => arguments_.reduce((p, c) => _defu(p, c, "", merger), {});
163
+ }
164
+ const defu = createDefu();
165
+ //#endregion
166
+ //#region ../../node_modules/.pnpm/rc9@3.1.0/node_modules/rc9/dist/index.mjs
167
+ const RE_KEY_VAL = /^\s*([^\s=]+)\s*=\s*(.*)?\s*$/;
168
+ const RE_LINES = /\n|\r|\r\n/;
169
+ const defaults = {
170
+ name: ".conf",
171
+ dir: process.cwd(),
172
+ flat: false
173
+ };
174
+ function withDefaults(options) {
175
+ if (typeof options === "string") options = { name: options };
176
+ return {
177
+ ...defaults,
178
+ ...options
179
+ };
180
+ }
181
+ function parse$1(contents, options = {}) {
182
+ const config = {};
183
+ const lines = contents.split(RE_LINES);
184
+ for (const line of lines) {
185
+ const match = line.match(RE_KEY_VAL);
186
+ if (!match) continue;
187
+ const key = match[1];
188
+ if (!key || key === "__proto__" || key === "constructor") continue;
189
+ const value = destr((match[2] || "").trim());
190
+ if (key.endsWith("[]")) {
191
+ const nkey = key.slice(0, Math.max(0, key.length - 2));
192
+ config[nkey] = (config[nkey] || []).concat(value);
193
+ continue;
194
+ }
195
+ config[key] = value;
196
+ }
197
+ return options.flat ? config : unflatten(config, { overwrite: true });
198
+ }
199
+ function parseFile(path, options) {
200
+ if (!existsSync(path)) return {};
201
+ return parse$1(readFileSync(path, "utf8"), options);
202
+ }
203
+ function read(options) {
204
+ options = withDefaults(options);
205
+ return parseFile(resolve(options.dir, options.name), options);
206
+ }
207
+ function userConfigDir() {
208
+ return process.env.XDG_CONFIG_HOME || resolve(homedir(), ".config");
209
+ }
210
+ function readUserConfig(options) {
211
+ options = withDefaults(options);
212
+ options.dir = userConfigDir();
213
+ return read(options);
214
+ }
215
+ //#endregion
216
+ //#region ../../node_modules/.pnpm/c12@4.0.0-rc.2_dotenv@17.4.2_jiti@2.7.0_magicast@0.5.5/node_modules/c12/dist/index.mjs
217
+ async function setupDotenv(options) {
218
+ const targetEnvironment = options.env ?? process.env;
219
+ const environment = await loadDotenv({
220
+ cwd: options.cwd,
221
+ fileName: options.fileName ?? ".env",
222
+ env: targetEnvironment,
223
+ interpolate: options.interpolate ?? true,
224
+ expandFileReferences: options.expandFileReferences ?? false,
225
+ parse: options.parse
226
+ });
227
+ const dotenvVars = getDotEnvVars(targetEnvironment);
228
+ for (const key in environment) {
229
+ if (key.startsWith("_")) continue;
230
+ if (targetEnvironment[key] === void 0 || dotenvVars.has(key)) targetEnvironment[key] = environment[key];
231
+ }
232
+ return environment;
233
+ }
234
+ async function loadDotenv(options) {
235
+ const environment = Object.create(null);
236
+ const cwd = resolve$1(options.cwd || ".");
237
+ const _fileName = options.fileName || ".env";
238
+ const dotenvFiles = typeof _fileName === "string" ? [_fileName] : _fileName;
239
+ const dotenvVars = getDotEnvVars(options.env || {});
240
+ Object.assign(environment, options.env);
241
+ for (const file of dotenvFiles) {
242
+ const dotenvFile = resolve$1(cwd, file);
243
+ if (!statSync(dotenvFile, { throwIfNoEntry: false })?.isFile()) continue;
244
+ const parsed = await readEnvFile(dotenvFile, options.parse);
245
+ for (const key in parsed) {
246
+ if (key in environment && !dotenvVars.has(key)) continue;
247
+ environment[key] = parsed[key];
248
+ dotenvVars.add(key);
249
+ }
250
+ }
251
+ if (options.expandFileReferences) {
252
+ for (const key in environment) if (key.endsWith("_FILE")) {
253
+ const targetKey = key.slice(0, -5);
254
+ if (environment[targetKey] === void 0) {
255
+ const filePath = environment[key];
256
+ if (filePath && statSync(filePath, { throwIfNoEntry: false })?.isFile()) {
257
+ environment[targetKey] = readFileSync(filePath, "utf8").trim();
258
+ dotenvVars.add(targetKey);
259
+ }
260
+ }
261
+ }
262
+ }
263
+ if (options.interpolate) interpolate(environment);
264
+ return environment;
265
+ }
266
+ let _parseEnv = nodeUtil.parseEnv;
267
+ async function readEnvFile(path, parse) {
268
+ const src = readFileSync(path, "utf8");
269
+ if (parse) return parse(src);
270
+ if (!_parseEnv) try {
271
+ const dotenv = await import("dotenv");
272
+ _parseEnv = (src) => dotenv.parse(src);
273
+ } catch {
274
+ throw new Error("Failed to parse .env file: `node:util.parseEnv` is not available and `dotenv` package is not installed. Please upgrade your runtime, install `dotenv` as a dependency or provide a custom `parse` option.");
275
+ }
276
+ return _parseEnv(src);
277
+ }
278
+ function interpolate(target, source = {}, parse = (v) => v) {
279
+ function getValue(key) {
280
+ return source[key] === void 0 ? target[key] : source[key];
281
+ }
282
+ function interpolate(value, parents = []) {
283
+ if (typeof value !== "string") return value;
284
+ let result = "";
285
+ let index = 0;
286
+ while (index < value.length) {
287
+ const char = value[index];
288
+ if (char === "\\" && value[index + 1] === "$") {
289
+ result += "$";
290
+ index += 2;
291
+ continue;
292
+ }
293
+ const ref = char === "$" ? parseRef(value, index) : void 0;
294
+ if (!ref) {
295
+ result += char;
296
+ index++;
297
+ continue;
298
+ }
299
+ if (parents.includes(ref.key)) {
300
+ if (ref.defaultValue !== void 0) {
301
+ result += interpolate(ref.defaultValue, parents);
302
+ index = ref.end;
303
+ continue;
304
+ }
305
+ console.warn(`Please avoid recursive environment variables ( loop: ${parents.join(" > ")} > ${ref.key} )`);
306
+ return "";
307
+ }
308
+ let resolved = interpolate(getValue(ref.key), [...parents, ref.key]);
309
+ if (ref.defaultValue !== void 0 && (resolved === void 0 || ref.operator === ":-" && resolved === "")) resolved = interpolate(ref.defaultValue, parents);
310
+ result += resolved === void 0 ? value.slice(index, ref.end) : resolved;
311
+ index = ref.end;
312
+ }
313
+ return parse(result);
314
+ }
315
+ for (const key in target) target[key] = interpolate(getValue(key));
316
+ }
317
+ const REF_NAME_RE = /\w+/y;
318
+ const BRACED_REF_NAME_RE = /[\w:]+/y;
319
+ function parseRef(input, start) {
320
+ let index = start + 1;
321
+ const braced = input[index] === "{";
322
+ if (braced) index++;
323
+ const nameRe = braced ? BRACED_REF_NAME_RE : REF_NAME_RE;
324
+ nameRe.lastIndex = index;
325
+ const name = nameRe.exec(input);
326
+ if (!name) return;
327
+ let key = name[0];
328
+ index = nameRe.lastIndex;
329
+ if (!braced) return {
330
+ key,
331
+ end: index
332
+ };
333
+ if (input[index] === "}") return {
334
+ key,
335
+ end: index + 1
336
+ };
337
+ if (input[index] === "-") {
338
+ let operator = "-";
339
+ if (key.endsWith(":")) {
340
+ key = key.slice(0, -1);
341
+ operator = ":-";
342
+ }
343
+ const defaultValue = key ? readDefault(input, index + 1) : void 0;
344
+ if (!defaultValue) return;
345
+ return {
346
+ key,
347
+ operator,
348
+ defaultValue: defaultValue.value,
349
+ end: defaultValue.end
350
+ };
351
+ }
352
+ return {
353
+ key,
354
+ end: index
355
+ };
356
+ }
357
+ function readDefault(input, start) {
358
+ let value = "";
359
+ let depth = 1;
360
+ for (let index = start; index < input.length; index++) {
361
+ const char = input[index];
362
+ if (char === "\\" && index + 1 < input.length) {
363
+ const next = input[index + 1];
364
+ value += next === "{" || next === "}" ? next : char + next;
365
+ index++;
366
+ continue;
367
+ }
368
+ if (char === "$" && input[index + 1] === "{") {
369
+ depth++;
370
+ value += "${";
371
+ index++;
372
+ continue;
373
+ }
374
+ if (char === "{") depth++;
375
+ if (char === "}") {
376
+ depth--;
377
+ if (depth === 0) return {
378
+ value,
379
+ end: index + 1
380
+ };
381
+ }
382
+ value += char;
383
+ }
384
+ }
385
+ function getDotEnvVars(targetEnvironment) {
386
+ const globalRegistry = globalThis.__c12_dotenv_vars__ ||= /* @__PURE__ */ new Map();
387
+ if (!globalRegistry.has(targetEnvironment)) globalRegistry.set(targetEnvironment, /* @__PURE__ */ new Set());
388
+ return globalRegistry.get(targetEnvironment);
389
+ }
390
+ const _normalize = (p) => p?.replace(/\\/g, "/");
391
+ let importCounter = 0;
392
+ const ASYNC_LOADERS = {
393
+ ".json": () => JSON.parse,
394
+ ".yaml": () => import("./yaml-CYCbJ6et.js").then((r) => r.parseYAML),
395
+ ".yml": () => import("./yaml-CYCbJ6et.js").then((r) => r.parseYAML),
396
+ ".jsonc": () => import("./jsonc-BUniUpOk.js").then((r) => (source) => r.parseJSONC(source, { allowTrailingComma: true })),
397
+ ".json5": () => import("./json5-ChRycquj.js").then((r) => r.parseJSON5),
398
+ ".toml": () => import("./toml-DB-MNnFs.js").then((r) => r.parseTOML)
399
+ };
400
+ const SUPPORTED_EXTENSIONS = Object.freeze([
401
+ ".js",
402
+ ".ts",
403
+ ".mjs",
404
+ ".cjs",
405
+ ".mts",
406
+ ".cts",
407
+ ".json",
408
+ ".jsonc",
409
+ ".json5",
410
+ ".yaml",
411
+ ".yml",
412
+ ".toml"
413
+ ]);
414
+ async function loadConfig$1(options) {
415
+ options.cwd = resolve$1(process.cwd(), options.cwd || ".");
416
+ options.name = options.name || "config";
417
+ options.envName = options.envName ?? process.env.NODE_ENV;
418
+ options.configFile = options.configFile ?? (options.name === "config" ? "config" : `${options.name}.config`);
419
+ options.rcFile = options.rcFile ?? `.${options.name}rc`;
420
+ if (options.extend !== false) options.extend = {
421
+ extendKey: "extends",
422
+ ...options.extend
423
+ };
424
+ const _merger = options.merger || defu;
425
+ const r = {
426
+ config: {},
427
+ cwd: options.cwd,
428
+ configFile: resolve$1(options.cwd, options.configFile),
429
+ layers: [],
430
+ _configFile: void 0
431
+ };
432
+ const rawConfigs = {
433
+ overrides: options.overrides,
434
+ main: void 0,
435
+ rc: void 0,
436
+ packageJson: void 0,
437
+ defaultConfig: options.defaultConfig
438
+ };
439
+ if (options.dotenv) await setupDotenv({
440
+ cwd: options.cwd,
441
+ ...options.dotenv === true ? {} : options.dotenv
442
+ });
443
+ const _mainConfig = await resolveConfig$1(".", options);
444
+ if (_mainConfig.configFile) {
445
+ rawConfigs.main = _mainConfig.config;
446
+ r.configFile = _mainConfig.configFile;
447
+ r._configFile = _mainConfig._configFile;
448
+ }
449
+ if (_mainConfig.meta) r.meta = _mainConfig.meta;
450
+ if (options.rcFile) {
451
+ const rcSources = [];
452
+ rcSources.push(read({
453
+ name: options.rcFile,
454
+ dir: options.cwd
455
+ }));
456
+ if (options.globalRc) {
457
+ const { findWorkspaceDir } = await import("./dist-B1MvLv-M.js");
458
+ const workspaceDir = await findWorkspaceDir(options.cwd).catch(() => {});
459
+ if (workspaceDir) rcSources.push(read({
460
+ name: options.rcFile,
461
+ dir: workspaceDir
462
+ }));
463
+ rcSources.push(readUserConfig({ name: options.rcFile }));
464
+ rcSources.push(read({
465
+ name: options.rcFile,
466
+ dir: homedir()
467
+ }));
468
+ }
469
+ rawConfigs.rc = _merger({}, ...rcSources);
470
+ }
471
+ if (options.packageJson) {
472
+ const keys = (Array.isArray(options.packageJson) ? options.packageJson : [typeof options.packageJson === "string" ? options.packageJson : options.name]).filter((t) => t && typeof t === "string");
473
+ const { readPackageJSON } = await import("./dist-B1MvLv-M.js");
474
+ const pkgJsonFile = await readPackageJSON(options.cwd).catch(() => {});
475
+ rawConfigs.packageJson = _merger({}, ...keys.map((key) => pkgJsonFile?.[key]));
476
+ }
477
+ const configs = {};
478
+ for (const key in rawConfigs) {
479
+ const value = rawConfigs[key];
480
+ configs[key] = await (typeof value === "function" ? value({
481
+ configs,
482
+ rawConfigs
483
+ }) : value);
484
+ }
485
+ if (Array.isArray(configs.main)) r.config = configs.main;
486
+ else {
487
+ r.config = _merger(configs.overrides, configs.main, configs.rc, configs.packageJson, configs.defaultConfig);
488
+ if (options.extend) {
489
+ await extendConfig(r.config, options);
490
+ r.layers = r.config._layers;
491
+ delete r.config._layers;
492
+ r.config = _merger(r.config, ...r.layers.map((e) => e.config));
493
+ }
494
+ }
495
+ r.layers = [...[
496
+ configs.overrides && {
497
+ config: configs.overrides,
498
+ configFile: void 0,
499
+ cwd: void 0
500
+ },
501
+ {
502
+ config: configs.main,
503
+ configFile: options.configFile,
504
+ cwd: options.cwd
505
+ },
506
+ configs.rc && {
507
+ config: configs.rc,
508
+ configFile: options.rcFile
509
+ },
510
+ configs.packageJson && {
511
+ config: configs.packageJson,
512
+ configFile: "package.json"
513
+ }
514
+ ].filter((l) => l && l.config), ...r.layers];
515
+ if (options.defaults) r.config = _merger(r.config, options.defaults);
516
+ if (options.omit$Keys) {
517
+ for (const key in r.config) if (key.startsWith("$")) delete r.config[key];
518
+ }
519
+ if (options.configFileRequired && !r._configFile) throw new Error(`Required config (${r.configFile}) cannot be resolved.`);
520
+ if (options.schema != null) r.config = await validateConfig(r.config, options.schema);
521
+ return r;
522
+ }
523
+ async function extendConfig(config, options) {
524
+ config._layers = config._layers || [];
525
+ if (!options.extend) return;
526
+ let keys = options.extend.extendKey;
527
+ if (typeof keys === "string") keys = [keys];
528
+ const extendSources = [];
529
+ for (const key of keys) {
530
+ extendSources.push(...(Array.isArray(config[key]) ? config[key] : [config[key]]).filter(Boolean));
531
+ delete config[key];
532
+ }
533
+ for (let extendSource of extendSources) {
534
+ const originalExtendSource = extendSource;
535
+ let sourceOptions = {};
536
+ if (extendSource.source) {
537
+ sourceOptions = extendSource.options || {};
538
+ extendSource = extendSource.source;
539
+ }
540
+ if (Array.isArray(extendSource)) {
541
+ sourceOptions = extendSource[1] || {};
542
+ extendSource = extendSource[0];
543
+ }
544
+ if (typeof extendSource !== "string") {
545
+ console.warn(`Cannot extend config from \`${JSON.stringify(originalExtendSource)}\` in ${options.cwd}`);
546
+ continue;
547
+ }
548
+ const _config = await resolveConfig$1(extendSource, options, sourceOptions);
549
+ if (!_config.config) {
550
+ console.warn(`Cannot extend config from \`${extendSource}\` in ${options.cwd}`);
551
+ continue;
552
+ }
553
+ await extendConfig(_config.config, {
554
+ ...options,
555
+ cwd: _config.cwd
556
+ });
557
+ config._layers.push(_config);
558
+ if (_config.config._layers) {
559
+ config._layers.push(..._config.config._layers);
560
+ delete _config.config._layers;
561
+ }
562
+ }
563
+ }
564
+ const GIGET_PREFIXES = [
565
+ "gh:",
566
+ "github:",
567
+ "gitlab:",
568
+ "bitbucket:",
569
+ "https://",
570
+ "http://"
571
+ ];
572
+ const NPM_PACKAGE_RE = /^(@[\da-z~-][\d._a-z~-]*\/)?[\da-z~-][\d._a-z~-]*($|\/.*)/;
573
+ async function resolveConfig$1(source, options, sourceOptions = {}) {
574
+ if (options.resolve) {
575
+ const res = await options.resolve(source, options);
576
+ if (res) return res;
577
+ }
578
+ const _merger = options.merger || defu;
579
+ const customProviderKeys = Object.keys(sourceOptions.giget?.providers || {}).map((key) => `${key}:`);
580
+ const gigetPrefixes = customProviderKeys.length > 0 ? [.../* @__PURE__ */ new Set([...customProviderKeys, ...GIGET_PREFIXES])] : GIGET_PREFIXES;
581
+ if (options.giget !== false && gigetPrefixes.some((prefix) => source.startsWith(prefix))) {
582
+ const { downloadTemplate } = await import("giget").catch((error) => {
583
+ throw new Error(`Extending config from \`${source}\` requires \`giget\` peer dependency to be installed.\n\nInstall it with: \`npx nypm i giget\``, { cause: error });
584
+ });
585
+ const { digest } = await import("./ohash-D7bG_EOb.js").then((n) => n.dist_exports);
586
+ const cloneName = source.replace(/\W+/g, "_").split("_").splice(0, 3).join("_") + "_" + digest(source).slice(0, 10).replace(/[-_]/g, "");
587
+ let cloneDir;
588
+ const localNodeModules = resolve$1(options.cwd, "node_modules");
589
+ const parentDir = dirname$1(options.cwd);
590
+ if (basename$1(parentDir) === ".c12") cloneDir = join$1(parentDir, cloneName);
591
+ else if (existsSync(localNodeModules)) cloneDir = join$1(localNodeModules, ".c12", cloneName);
592
+ else cloneDir = process.env.XDG_CACHE_HOME ? resolve$1(process.env.XDG_CACHE_HOME, "c12", cloneName) : resolve$1(homedir(), ".cache/c12", cloneName);
593
+ const install = sourceOptions.install ? defu(sourceOptions.install === true ? {} : sourceOptions.install, { ignoreWorkspace: true }) : false;
594
+ if (existsSync(cloneDir) && !install) await rm(cloneDir, { recursive: true });
595
+ source = (await downloadTemplate(source, {
596
+ dir: cloneDir,
597
+ install,
598
+ force: Boolean(install),
599
+ auth: sourceOptions.auth,
600
+ ...options.giget,
601
+ ...sourceOptions.giget
602
+ })).dir;
603
+ }
604
+ if (NPM_PACKAGE_RE.test(source)) source = tryResolve(source, options) || source;
605
+ const ext = extname(source);
606
+ const isDir = _isDirectory(resolve$1(options.cwd, source)) ?? (!ext || ext === basename$1(source));
607
+ const cwd = resolve$1(options.cwd, isDir ? source : dirname$1(source));
608
+ if (isDir) source = options.configFile;
609
+ const res = {
610
+ config: void 0,
611
+ configFile: void 0,
612
+ cwd,
613
+ source,
614
+ sourceOptions
615
+ };
616
+ res.configFile = tryResolve(resolve$1(cwd, source), options) || tryResolve(resolve$1(cwd, ".config", source.replace(/\.config$/, "")), options) || tryResolve(resolve$1(cwd, ".config", source), options) || source;
617
+ if (!existsSync(res.configFile)) return res;
618
+ res._configFile = res.configFile;
619
+ const configFileExt = extname(res.configFile) || "";
620
+ if (configFileExt in ASYNC_LOADERS) res.config = (await ASYNC_LOADERS[configFileExt]())(await readFile(res.configFile, "utf8"));
621
+ else {
622
+ const _resolveModule = options.resolveModule || ((mod) => mod.default || mod);
623
+ if (options.import) res.config = _resolveModule(await options.import(res.configFile));
624
+ else {
625
+ const _configURL = pathToFileURL(res.configFile);
626
+ _configURL.search = `_${++importCounter}`;
627
+ res.config = await import(_configURL.href).then(_resolveModule, async (error) => {
628
+ const { createJiti } = await import("jiti").catch(() => {
629
+ throw new Error(`Failed to load config file \`${res.configFile}\`: ${error?.message}. Hint install \`jiti\` for compatibility.`, { cause: error });
630
+ });
631
+ const jiti = createJiti(join$1(options.cwd || ".", options.configFile || "/"), {
632
+ interopDefault: true,
633
+ moduleCache: false,
634
+ extensions: [...SUPPORTED_EXTENSIONS],
635
+ ...options.jitiOptions
636
+ });
637
+ options.import = (id) => jiti.import(id);
638
+ return _resolveModule(await options.import(res.configFile));
639
+ });
640
+ }
641
+ }
642
+ if (typeof res.config === "function") res.config = await res.config(options.context);
643
+ if (res.config && typeof res.config === "object" && !Array.isArray(res.config) && !Object.isExtensible(res.config)) res.config = { ...res.config };
644
+ const envConfigs = (Array.isArray(options.envName) ? options.envName : [options.envName]).filter(Boolean).reverse().flatMap((envName) => [res.config.$env?.[envName], res.config["$" + envName]]).filter((c) => c && Object.keys(c).length > 0);
645
+ if (envConfigs.length > 0) res.config = (options.envMerger || _merger)({}, ...envConfigs, res.config);
646
+ res.meta = defu(res.sourceOptions.meta, res.config.$meta);
647
+ delete res.config.$meta;
648
+ if (res.sourceOptions.overrides) res.config = _merger(res.sourceOptions.overrides, res.config);
649
+ res.configFile = _normalize(res.configFile);
650
+ res.source = _normalize(res.source);
651
+ return res;
652
+ }
653
+ async function validateConfig(config, schema) {
654
+ if (typeof schema?.["~standard"]?.validate !== "function") throw new TypeError("Invalid `schema` option: expected a Standard Schema (https://standardschema.dev).");
655
+ const result = await schema["~standard"].validate(config);
656
+ if (result.issues) {
657
+ const messages = result.issues.map((issue) => {
658
+ const path = issue.path?.map((p) => String(typeof p === "object" ? p.key : p)).join(".");
659
+ return ` - ${path ? `${path}: ` : ""}${issue.message}`;
660
+ });
661
+ throw new Error(`Config validation failed (${schema["~standard"].vendor}):\n${messages.join("\n")}`, { cause: result.issues });
662
+ }
663
+ return result.value;
664
+ }
665
+ function tryResolve(id, options) {
666
+ const res = resolveModulePath(id, {
667
+ try: true,
668
+ from: pathToFileURL(join$1(options.cwd || ".", options.configFile || "/")),
669
+ suffixes: ["", "/index"],
670
+ extensions: SUPPORTED_EXTENSIONS,
671
+ cache: false
672
+ });
673
+ return res ? normalize$1(res) : void 0;
674
+ }
675
+ function _isDirectory(path) {
676
+ try {
677
+ return statSync(path).isDirectory();
678
+ } catch {
679
+ return null;
680
+ }
681
+ }
682
+ //#endregion
683
+ //#region src/cli/config-schema.ts
684
+ const strings = array(string());
685
+ const stringRecord = record(string(), string());
686
+ const privileges = array(picklist([
687
+ "select",
688
+ "insert",
689
+ "update",
690
+ "delete"
691
+ ]));
692
+ const pluginFlag = union([boolean(), record(string(), unknown())]);
693
+ const isGenerator = (value) => typeof value === "object" && value !== null && "name" in value && typeof value.name === "string" && "generate" in value && typeof value.generate === "function";
694
+ /**
695
+ * The top level of `better-supabase.config.*`. It rejects unknown keys and
696
+ * checks the leaves a typo or an old value breaks; nested objects the
697
+ * library reads loosely stay loose.
698
+ */
699
+ const ConfigSchema = strictObject({
700
+ $schema: optional(string()),
701
+ source: optional(strictObject({
702
+ dbUrl: optional(string()),
703
+ projectRef: optional(string()),
704
+ accessToken: optional(string()),
705
+ snapshot: optional(string())
706
+ })),
707
+ schemas: optional(strings),
708
+ casing: optional(picklist(["snake", "camel"])),
709
+ tables: optional(record(string(), strictObject({
710
+ casing: optional(picklist(["snake", "camel"])),
711
+ exclude: optional(boolean()),
712
+ relations: optional(stringRecord)
713
+ }))),
714
+ output: optional(string()),
715
+ postgrestVersion: optional(string()),
716
+ json: optional(record(string(), unknown())),
717
+ codecs: optional(strictObject({
718
+ timestamptz: optional(picklist(["string", "instant"])),
719
+ int8: optional(picklist([
720
+ "number",
721
+ "string",
722
+ "bigint"
723
+ ])),
724
+ numeric: optional(picklist(["number", "string"]))
725
+ })),
726
+ sensitive: optional(strings),
727
+ storagePaths: optional(stringRecord),
728
+ expose: optional(record(string(), union([privileges, strictObject({
729
+ anon: optional(privileges),
730
+ authenticated: optional(privileges)
731
+ })]))),
732
+ readSets: optional(strings),
733
+ generators: optional(array(custom(isGenerator, "must be a generator: { name, generate(input) }"))),
734
+ plugins: optional(strictObject({
735
+ timestamps: optional(pluginFlag),
736
+ softDelete: optional(pluginFlag),
737
+ tenant: optional(pluginFlag),
738
+ actor: optional(pluginFlag)
739
+ })),
740
+ claims: optional(strictObject({
741
+ tenant: optional(string()),
742
+ scope: optional(string()),
743
+ features: optional(string())
744
+ })),
745
+ buckets: optional(record(string(), record(string(), unknown()))),
746
+ topics: optional(stringRecord),
747
+ realtime: optional(strictObject({ tables: optional(strings) })),
748
+ entitlements: optional(strictObject({
749
+ customer: optional(string()),
750
+ key: optional(string()),
751
+ permdock: optional(union([literal(false), strictObject({ scope: optional(string()) })]))
752
+ })),
753
+ permdock: optional(strictObject({
754
+ manifest: optional(string()),
755
+ catalog: optional(string())
756
+ })),
757
+ vectorSearch: optional(record(string(), union([string(), strictObject({
758
+ column: string(),
759
+ distance: optional(picklist([
760
+ "cosine",
761
+ "l2",
762
+ "inner_product"
763
+ ]))
764
+ })]))),
765
+ sql: optional(strictObject({
766
+ dir: optional(string()),
767
+ prefix: optional(string()),
768
+ testsDir: optional(string()),
769
+ kit: optional(strings)
770
+ })),
771
+ seed: optional(strictObject({
772
+ entry: optional(string()),
773
+ output: optional(string())
774
+ })),
775
+ openapi: optional(strictObject({
776
+ entry: optional(string()),
777
+ output: optional(string())
778
+ })),
779
+ doctor: optional(strictObject({
780
+ ignore: optional(strings),
781
+ strict: optional(boolean()),
782
+ sources: optional(strings),
783
+ policyHelperLimit: optional(number()),
784
+ claimsLimit: optional(number())
785
+ }))
786
+ });
787
+ /** Each issue as `path: message`, the path in config keys. */
788
+ function configIssues(value) {
789
+ const result = safeParse(ConfigSchema, value);
790
+ if (result.success) return [];
791
+ return result.issues.map((issue) => {
792
+ const path = getDotPath(issue);
793
+ return path ? `${path}: ${issue.message}` : issue.message;
794
+ });
795
+ }
796
+ //#endregion
797
+ //#region ../../node_modules/.pnpm/smol-toml@1.9.0/node_modules/smol-toml/dist/error.js
798
+ /*!
799
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
800
+ * SPDX-License-Identifier: BSD-3-Clause
801
+ *
802
+ * Redistribution and use in source and binary forms, with or without
803
+ * modification, are permitted provided that the following conditions are met:
804
+ *
805
+ * 1. Redistributions of source code must retain the above copyright notice, this
806
+ * list of conditions and the following disclaimer.
807
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
808
+ * this list of conditions and the following disclaimer in the
809
+ * documentation and/or other materials provided with the distribution.
810
+ * 3. Neither the name of the copyright holder nor the names of its contributors
811
+ * may be used to endorse or promote products derived from this software without
812
+ * specific prior written permission.
813
+ *
814
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
815
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
816
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
817
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
818
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
819
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
820
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
821
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
822
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
823
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
824
+ */
825
+ function getLineColFromPtr(string, ptr) {
826
+ let lines = string.slice(0, ptr).split(/\r?\n/);
827
+ return [lines.length, lines.pop().length + 1];
828
+ }
829
+ function makeCodeBlock(string, line, column) {
830
+ let lines = string.split(/\r?\n/);
831
+ let codeblock = "";
832
+ let numberLen = (Math.log10(line + 1) | 0) + 1;
833
+ for (let i = line - 1; i <= line + 1; i++) {
834
+ let l = lines[i - 1];
835
+ if (!l) continue;
836
+ codeblock += i.toString().padEnd(numberLen, " ");
837
+ codeblock += ": ";
838
+ codeblock += l;
839
+ codeblock += "\n";
840
+ if (i === line) {
841
+ codeblock += " ".repeat(numberLen + column + 2);
842
+ codeblock += "^\n";
843
+ }
844
+ }
845
+ return codeblock;
846
+ }
847
+ var TomlError = class TomlError extends Error {
848
+ line;
849
+ column;
850
+ codeblock;
851
+ constructor(message, options) {
852
+ const [line, column] = getLineColFromPtr(options.toml, options.ptr);
853
+ const codeblock = makeCodeBlock(options.toml, line, column);
854
+ super(`Invalid TOML document: ${message}\n\n${codeblock}`, options);
855
+ this.line = line;
856
+ this.column = column;
857
+ this.codeblock = codeblock;
858
+ }
859
+ /** @internal */
860
+ static x(message, ctx, ptr) {
861
+ throw new TomlError(message, {
862
+ toml: ctx.s,
863
+ ptr: ptr ?? ctx.p
864
+ });
865
+ }
866
+ };
867
+ //#endregion
868
+ //#region ../../node_modules/.pnpm/smol-toml@1.9.0/node_modules/smol-toml/dist/primitive.js
869
+ /*!
870
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
871
+ * SPDX-License-Identifier: BSD-3-Clause
872
+ *
873
+ * Redistribution and use in source and binary forms, with or without
874
+ * modification, are permitted provided that the following conditions are met:
875
+ *
876
+ * 1. Redistributions of source code must retain the above copyright notice, this
877
+ * list of conditions and the following disclaimer.
878
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
879
+ * this list of conditions and the following disclaimer in the
880
+ * documentation and/or other materials provided with the distribution.
881
+ * 3. Neither the name of the copyright holder nor the names of its contributors
882
+ * may be used to endorse or promote products derived from this software without
883
+ * specific prior written permission.
884
+ *
885
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
886
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
887
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
888
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
889
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
890
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
891
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
892
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
893
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
894
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
895
+ */
896
+ /** @internal */
897
+ function parseString(ctx) {
898
+ let startPtr = ctx.p;
899
+ let c = ctx.s.charCodeAt(ctx.p++);
900
+ let first = c;
901
+ let isLiteral = c === 39;
902
+ let isMultiline = c === ctx.s.charCodeAt(ctx.p) && c === ctx.s.charCodeAt(ctx.p + 1);
903
+ if (isMultiline) {
904
+ if ((c = ctx.s.charCodeAt(ctx.p += 2)) === 10) ctx.p++;
905
+ else if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10) ctx.p += 2;
906
+ }
907
+ let parsed = "";
908
+ let sliceStart = ctx.p;
909
+ let state = 0;
910
+ for (; ctx.p < ctx.s.length; ctx.p++) {
911
+ c = ctx.s.charCodeAt(ctx.p);
912
+ if (isMultiline && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)) state = state && 3;
913
+ else if (c < 32 && c !== 9 || c === 127) TomlError.x("control characters are not allowed in strings", ctx);
914
+ else if ((!state || state === 3) && c === first && (!isMultiline || ctx.s.charCodeAt(ctx.p + 1) === first && ctx.s.charCodeAt(ctx.p + 2) === first)) {
915
+ if (isMultiline) {
916
+ if (ctx.s.charCodeAt(ctx.p + 3) === first) ctx.p++;
917
+ if (ctx.s.charCodeAt(ctx.p + 3) === first) ctx.p++;
918
+ }
919
+ if (!state) {
920
+ let s = ctx.s.slice(sliceStart, ctx.p);
921
+ parsed = parsed ? parsed + s : s;
922
+ }
923
+ ctx.p += isMultiline ? 3 : 1;
924
+ return parsed;
925
+ } else if (!state) {
926
+ if (!isLiteral && c === 92) {
927
+ parsed += ctx.s.slice(sliceStart, sliceStart = ctx.p);
928
+ state = 1;
929
+ }
930
+ } else if (state === 1) {
931
+ if (c === 120 || c === 117 || c === 85) {
932
+ let errPtr = ctx.p++ - 1;
933
+ let value = 0;
934
+ let len = c === 120 ? 2 : c === 117 ? 4 : 8;
935
+ for (let j = 0; j < len; j++, ctx.p++) {
936
+ let hex = ctx.s.charCodeAt(ctx.p);
937
+ let digit = hex >= 48 && hex <= 57 ? hex - 48 : hex >= 65 && hex <= 70 ? hex - 65 + 10 : hex >= 97 && hex <= 102 ? hex - 97 + 10 : -1;
938
+ if (digit < 0) TomlError.x("invalid non-hex character in unicode escape", ctx);
939
+ value = value << 4 | digit;
940
+ }
941
+ if (value < 0 || value > 1114111 || value >= 55296 && value <= 57343) TomlError.x("invalid unicode escape", ctx, errPtr);
942
+ parsed += String.fromCodePoint(value);
943
+ sliceStart = ctx.p--;
944
+ state = 0;
945
+ } else if (isMultiline && (c === 32 || c === 9)) state = 2;
946
+ else {
947
+ if (c === 98) parsed += "\b";
948
+ else if (c === 116) parsed += " ";
949
+ else if (c === 110) parsed += "\n";
950
+ else if (c === 102) parsed += "\f";
951
+ else if (c === 114) parsed += "\r";
952
+ else if (c === 101) parsed += "\x1B";
953
+ else if (c === 34) parsed += "\"";
954
+ else if (c === 92) parsed += "\\";
955
+ else TomlError.x("unrecognised escape sequence", ctx);
956
+ sliceStart = ctx.p + 1;
957
+ state = 0;
958
+ }
959
+ } else if (c !== 32 && c !== 9) {
960
+ if (state === 2) TomlError.x("invalid escape: only line-ending whitespace may be escaped", ctx, sliceStart);
961
+ state = !isLiteral && c === 92 ? 1 : 0;
962
+ sliceStart = ctx.p;
963
+ }
964
+ }
965
+ TomlError.x("unfinished string", ctx, startPtr);
966
+ }
967
+ //#endregion
968
+ //#region ../../node_modules/.pnpm/smol-toml@1.9.0/node_modules/smol-toml/dist/date.js
969
+ /*!
970
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
971
+ * SPDX-License-Identifier: BSD-3-Clause
972
+ *
973
+ * Redistribution and use in source and binary forms, with or without
974
+ * modification, are permitted provided that the following conditions are met:
975
+ *
976
+ * 1. Redistributions of source code must retain the above copyright notice, this
977
+ * list of conditions and the following disclaimer.
978
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
979
+ * this list of conditions and the following disclaimer in the
980
+ * documentation and/or other materials provided with the distribution.
981
+ * 3. Neither the name of the copyright holder nor the names of its contributors
982
+ * may be used to endorse or promote products derived from this software without
983
+ * specific prior written permission.
984
+ *
985
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
986
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
987
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
988
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
989
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
990
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
991
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
992
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
993
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
994
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
995
+ */
996
+ let DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i;
997
+ var TomlDate = class TomlDate extends Date {
998
+ #hasDate = false;
999
+ #hasTime = false;
1000
+ #offset = null;
1001
+ constructor(date, fasttype, unsafeDelim) {
1002
+ let hasDate = true;
1003
+ let hasTime = true;
1004
+ let offset = "Z";
1005
+ let c;
1006
+ if (typeof date === "string") {
1007
+ if (fasttype) prep: {
1008
+ if (fasttype < 3) {
1009
+ if (+date.slice(11, 13) > 23) {
1010
+ date = "";
1011
+ break prep;
1012
+ }
1013
+ if (fasttype === 2) {
1014
+ offset = null;
1015
+ date += "Z";
1016
+ } else if ((c = date.charCodeAt(date.length - 1)) !== 90 && c !== 122) offset = date.slice(date.length - 6);
1017
+ if (unsafeDelim) date = date.slice(0, 10) + "T" + date.slice(11);
1018
+ } else if (fasttype === 4) date = +date.slice(0, 2) > 23 ? "" : `0000-01-01T${date}Z`;
1019
+ hasDate = fasttype !== 4;
1020
+ hasTime = fasttype !== 3;
1021
+ }
1022
+ else {
1023
+ let match = date.match(DATE_TIME_RE);
1024
+ if (match) {
1025
+ if (!match[1]) {
1026
+ hasDate = false;
1027
+ date = `0000-01-01T${date}`;
1028
+ }
1029
+ hasTime = !!match[2];
1030
+ hasTime && date[10] === " " && (date = date.replace(" ", "T"));
1031
+ if (match[2] && +match[2] > 23) date = "";
1032
+ else {
1033
+ offset = match[3] || null;
1034
+ if (!offset && hasTime) date += "Z";
1035
+ }
1036
+ } else date = "";
1037
+ }
1038
+ }
1039
+ super(date);
1040
+ if (!isNaN(this.getTime())) {
1041
+ this.#hasDate = hasDate;
1042
+ this.#hasTime = hasTime;
1043
+ this.#offset = offset;
1044
+ }
1045
+ }
1046
+ isDateTime() {
1047
+ return this.#hasDate && this.#hasTime;
1048
+ }
1049
+ isLocal() {
1050
+ return !this.#hasDate || !this.#hasTime || !this.#offset;
1051
+ }
1052
+ isDate() {
1053
+ return this.#hasDate && !this.#hasTime;
1054
+ }
1055
+ isTime() {
1056
+ return this.#hasTime && !this.#hasDate;
1057
+ }
1058
+ isValid() {
1059
+ return this.#hasDate || this.#hasTime;
1060
+ }
1061
+ toISOString() {
1062
+ let iso = super.toISOString();
1063
+ if (this.isDate()) return iso.slice(0, 10);
1064
+ if (this.isTime()) return iso.slice(11, 23);
1065
+ if (this.#offset === null) return iso.slice(0, -1);
1066
+ if (this.#offset === "Z" || this.#offset === "z") return iso;
1067
+ let offset = +this.#offset.slice(1, 3) * 60 + +this.#offset.slice(4, 6);
1068
+ offset = this.#offset[0] === "-" ? offset : -offset;
1069
+ return (/* @__PURE__ */ new Date(this.getTime() - offset * 6e4)).toISOString().slice(0, -1) + this.#offset;
1070
+ }
1071
+ static wrapAsOffsetDateTime(jsDate, offset = "Z") {
1072
+ let date = new TomlDate(jsDate);
1073
+ date.#offset = offset;
1074
+ return date;
1075
+ }
1076
+ static wrapAsLocalDateTime(jsDate) {
1077
+ let date = new TomlDate(jsDate);
1078
+ date.#offset = null;
1079
+ return date;
1080
+ }
1081
+ static wrapAsLocalDate(jsDate) {
1082
+ let date = new TomlDate(jsDate);
1083
+ date.#hasTime = false;
1084
+ date.#offset = null;
1085
+ return date;
1086
+ }
1087
+ static wrapAsLocalTime(jsDate) {
1088
+ let date = new TomlDate(jsDate);
1089
+ date.#hasDate = false;
1090
+ date.#offset = null;
1091
+ return date;
1092
+ }
1093
+ };
1094
+ //#endregion
1095
+ //#region ../../node_modules/.pnpm/smol-toml@1.9.0/node_modules/smol-toml/dist/extract.js
1096
+ /*!
1097
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
1098
+ * SPDX-License-Identifier: BSD-3-Clause
1099
+ *
1100
+ * Redistribution and use in source and binary forms, with or without
1101
+ * modification, are permitted provided that the following conditions are met:
1102
+ *
1103
+ * 1. Redistributions of source code must retain the above copyright notice, this
1104
+ * list of conditions and the following disclaimer.
1105
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
1106
+ * this list of conditions and the following disclaimer in the
1107
+ * documentation and/or other materials provided with the distribution.
1108
+ * 3. Neither the name of the copyright holder nor the names of its contributors
1109
+ * may be used to endorse or promote products derived from this software without
1110
+ * specific prior written permission.
1111
+ *
1112
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1113
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1114
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1115
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
1116
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1117
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1118
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1119
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1120
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1121
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1122
+ */
1123
+ function isDigit(char, base = 10) {
1124
+ return base === 16 ? char > 47 && char < 58 || char > 64 && char < 71 || char > 96 && char < 103 : char > 47 && char < 48 + base;
1125
+ }
1126
+ function isEndOfValue(char, delim) {
1127
+ return char === 32 || char === 9 || char === 10 || char === 13 || delim && (char === delim || char === 44) || char === 35;
1128
+ }
1129
+ /** @internal */
1130
+ function extractValue(ctx, end) {
1131
+ let errPtr = ctx.p;
1132
+ let c = ctx.s.charCodeAt(ctx.p);
1133
+ if (c === 91 || c === 123) {
1134
+ ctx.d-- || TomlError.x("document contains excessively nested structures. aborting.", ctx);
1135
+ let value = c === 91 ? parseArray(ctx) : parseInlineTable(ctx);
1136
+ ctx.d++;
1137
+ return value;
1138
+ }
1139
+ if (c === 34 || c === 39) return parseString(ctx);
1140
+ if (c === 116) {
1141
+ if (ctx.s.charCodeAt(++ctx.p) !== 114 || ctx.s.charCodeAt(++ctx.p) !== 117 || ctx.s.charCodeAt(++ctx.p) !== 101) TomlError.x("invalid value", ctx, errPtr);
1142
+ return ctx.p++, true;
1143
+ }
1144
+ if (c === 102) {
1145
+ if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 108 || ctx.s.charCodeAt(++ctx.p) !== 115 || ctx.s.charCodeAt(++ctx.p) !== 101) TomlError.x("invalid value", ctx, errPtr);
1146
+ return ctx.p++, false;
1147
+ }
1148
+ if (c === 43 || c === 45) return parseNumber(ctx, ctx.p, ctx.s.charCodeAt(++ctx.p), 44 - c, end);
1149
+ if (ctx.s.charCodeAt(ctx.p + 4) === 45 && ctx.s.charCodeAt(ctx.p + 7) === 45) return parseDate(ctx, c, end);
1150
+ if (ctx.s.charCodeAt(ctx.p + 2) === 58) return parseTime(ctx, c, end);
1151
+ return parseNumber(ctx, ctx.p, c, 0, end);
1152
+ }
1153
+ function parseNumber(ctx, startPtr, startChr, sign, endChr) {
1154
+ let c = startChr;
1155
+ let state = 0;
1156
+ let hasUnderscores = false;
1157
+ if (c === 105) {
1158
+ if (ctx.s.charCodeAt(++ctx.p) !== 110 || ctx.s.charCodeAt(++ctx.p) !== 102) TomlError.x("invalid value", ctx, startPtr);
1159
+ return ctx.p++, (sign || 1) / 0;
1160
+ }
1161
+ if (c === 110) {
1162
+ if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 110) TomlError.x("invalid value", ctx, startPtr);
1163
+ return ctx.p++, NaN;
1164
+ }
1165
+ if (c === 48) {
1166
+ if (++ctx.p >= ctx.s.length || isEndOfValue(c = ctx.s.charCodeAt(ctx.p), endChr)) return ctx.bi === true ? 0n : 0;
1167
+ if (!sign) {
1168
+ if (c === 120) return parseIntegerBaseN(ctx, startPtr, 16, endChr);
1169
+ else if (c === 98) return parseIntegerBaseN(ctx, startPtr, 2, endChr);
1170
+ else if (c === 111) return parseIntegerBaseN(ctx, startPtr, 8, endChr);
1171
+ }
1172
+ if (c === 46) state = 2;
1173
+ else if (c === 101 || c === 69) state = 4;
1174
+ else TomlError.x("illegal leading zero", ctx, startPtr);
1175
+ } else if (!isDigit(c)) TomlError.x("invalid value", ctx, startPtr);
1176
+ while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) {
1177
+ if (!state) state = 1;
1178
+ if (c === 95) {
1179
+ if (!(state & 1)) TomlError.x("illegal underscore", ctx);
1180
+ state += 11;
1181
+ hasUnderscores = true;
1182
+ } else if (state === 1 && c === 46) state = 2;
1183
+ else if ((state === 1 || state === 3) && (c === 101 || c === 69)) state = 4;
1184
+ else if (state === 4 && (c === 43 || c === 45)) {} else if (!isDigit(c)) TomlError.x(`illegal character in numeric literal`, ctx);
1185
+ else if (state > 9) state -= 11;
1186
+ else if (!(state & 1)) state++;
1187
+ }
1188
+ if (!state) {
1189
+ let val = (startChr - 48) * (sign || 1);
1190
+ return ctx.bi === true ? BigInt(val) : val;
1191
+ }
1192
+ if (!(state & 1)) TomlError.x("unfinished numeric value", ctx, startPtr);
1193
+ let str = ctx.s.slice(startPtr, ctx.p);
1194
+ if (hasUnderscores) str = str.replaceAll("_", "");
1195
+ return state > 1 ? parseFloat(str) : parseInteger(ctx, str, 10, startPtr);
1196
+ }
1197
+ function parseIntegerBaseN(ctx, startPtr, base, endChr) {
1198
+ let c, underscore = 1;
1199
+ while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) if (c === 95) {
1200
+ if (underscore & 1) TomlError.x("illegal underscore", ctx);
1201
+ underscore = 3;
1202
+ } else if (!isDigit(c, base)) TomlError.x(`illegal character in numeric literal`, ctx);
1203
+ else if (underscore & 1) underscore--;
1204
+ if (underscore & 1) TomlError.x("unfinished numeric value", ctx);
1205
+ let str = ctx.s.slice(startPtr + 2, ctx.p);
1206
+ if (underscore) str = str.replaceAll("_", "");
1207
+ return parseInteger(ctx, str, base, startPtr);
1208
+ }
1209
+ function parseInteger(ctx, str, base, startPtr) {
1210
+ if (ctx.bi !== true) int: {
1211
+ let val = parseInt(str, base);
1212
+ if (!Number.isSafeInteger(val)) {
1213
+ if (ctx.bi) break int;
1214
+ TomlError.x("integer value cannot be represented losslessly", ctx, startPtr);
1215
+ }
1216
+ return val;
1217
+ }
1218
+ return base === 10 ? BigInt(str) : BigInt((base === 2 ? "0b" : base === 8 ? "0o" : "0x") + str);
1219
+ }
1220
+ function parseDate(ctx, c, endChr) {
1221
+ let startPtr = ctx.p++, unsafeSeparator;
1222
+ if (!isDigit(c) || !isDigit(ctx.s.charCodeAt(ctx.p++)) || !isDigit(ctx.s.charCodeAt(ctx.p++)) || !isDigit(ctx.s.charCodeAt(ctx.p++))) return parseNumber(ctx, ctx.p = startPtr, c, 0, endChr);
1223
+ ctx.p += 5;
1224
+ if (!isDigit(ctx.s.charCodeAt(ctx.p++))) TomlError.x("invalid date-time: date part is malformed", ctx, startPtr);
1225
+ if (ctx.p >= ctx.s.length || ((c = ctx.s.charCodeAt(ctx.p)) !== 32 || (unsafeSeparator = true, !isDigit(ctx.s.charCodeAt(ctx.p + 1)))) && c !== 84 && c !== 116) return readDate(ctx, ctx.s.slice(startPtr, ctx.p), 3, false, startPtr);
1226
+ if (ctx.s.charCodeAt(ctx.p += 3) !== 58) TomlError.x("invalid date-time: time part is malformed", ctx, startPtr);
1227
+ if (ctx.s.charCodeAt(ctx.p += 3) === 58) ctx.p += 3;
1228
+ if (ctx.s.charCodeAt(ctx.p) === 46) while (isDigit(ctx.s.charCodeAt(++ctx.p)));
1229
+ if (c = ctx.s.charCodeAt(ctx.p)) {
1230
+ if (c === 90 || c === 122) return readDate(ctx, ctx.s.slice(startPtr, ++ctx.p), 1, unsafeSeparator, startPtr, "[+00:00]");
1231
+ if (c === 43 || c === 45) return readDate(ctx, ctx.s.slice(startPtr, ctx.p += 6), 1, unsafeSeparator, startPtr, !ctx.ld && "[" + ctx.s.slice(ctx.p - 6, ctx.p) + "]");
1232
+ }
1233
+ return readDate(ctx, ctx.s.slice(startPtr, ctx.p), 2, unsafeSeparator, startPtr);
1234
+ }
1235
+ function parseTime(ctx, c, endChr) {
1236
+ let start = ctx.p;
1237
+ if (!isDigit(c) || !isDigit(ctx.s.charCodeAt(++ctx.p))) return parseNumber(ctx, --ctx.p, c, 0, endChr);
1238
+ if (ctx.s.charCodeAt(ctx.p += 4) === 58) ctx.p += 3;
1239
+ if (ctx.s.charCodeAt(ctx.p) === 46) while (isDigit(ctx.s.charCodeAt(++ctx.p)));
1240
+ return readDate(ctx, ctx.s.slice(start, ctx.p), 4, false, start);
1241
+ }
1242
+ function readDate(ctx, str, type, unsafeDelim, errPtr, temporalSuffix) {
1243
+ if (ctx.ld) {
1244
+ let date = new TomlDate(str, type, unsafeDelim);
1245
+ if (!date.isValid()) TomlError.x("invalid date", ctx, errPtr);
1246
+ return date;
1247
+ }
1248
+ try {
1249
+ if (temporalSuffix) str += temporalSuffix;
1250
+ switch (type) {
1251
+ case 1: return Temporal.ZonedDateTime.from(str);
1252
+ case 2: return Temporal.PlainDateTime.from(str);
1253
+ case 3: return Temporal.PlainDate.from(str);
1254
+ case 4: return Temporal.PlainTime.from(str);
1255
+ }
1256
+ } catch (e) {
1257
+ TomlError.x(e instanceof Error ? e.message : "" + e, ctx, errPtr);
1258
+ }
1259
+ }
1260
+ //#endregion
1261
+ //#region ../../node_modules/.pnpm/smol-toml@1.9.0/node_modules/smol-toml/dist/util.js
1262
+ /*!
1263
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
1264
+ * SPDX-License-Identifier: BSD-3-Clause
1265
+ *
1266
+ * Redistribution and use in source and binary forms, with or without
1267
+ * modification, are permitted provided that the following conditions are met:
1268
+ *
1269
+ * 1. Redistributions of source code must retain the above copyright notice, this
1270
+ * list of conditions and the following disclaimer.
1271
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
1272
+ * this list of conditions and the following disclaimer in the
1273
+ * documentation and/or other materials provided with the distribution.
1274
+ * 3. Neither the name of the copyright holder nor the names of its contributors
1275
+ * may be used to endorse or promote products derived from this software without
1276
+ * specific prior written permission.
1277
+ *
1278
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1279
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1280
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1281
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
1282
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1283
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1284
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1285
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1286
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1287
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1288
+ */
1289
+ /** @internal */
1290
+ function skipComment(ctx) {
1291
+ for (; ctx.p < ctx.s.length; ctx.p++) {
1292
+ let c = ctx.s.charCodeAt(ctx.p);
1293
+ if (c === 10) break;
1294
+ if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10) {
1295
+ ctx.p++;
1296
+ break;
1297
+ }
1298
+ if (c < 32 && c !== 9 || c === 127) TomlError.x("control characters are not allowed in comments", ctx);
1299
+ }
1300
+ }
1301
+ /** @internal */
1302
+ function skipVoid(ctx, banNewLines, banComments) {
1303
+ let c;
1304
+ while (ctx.p < ctx.s.length) {
1305
+ while (ctx.p < ctx.s.length && ((c = ctx.s.charCodeAt(ctx.p)) === 32 || c === 9 || !banNewLines && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10))) ctx.p++;
1306
+ if (banComments || c !== 35) break;
1307
+ skipComment(ctx);
1308
+ }
1309
+ }
1310
+ //#endregion
1311
+ //#region ../../node_modules/.pnpm/smol-toml@1.9.0/node_modules/smol-toml/dist/struct.js
1312
+ /*!
1313
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
1314
+ * SPDX-License-Identifier: BSD-3-Clause
1315
+ *
1316
+ * Redistribution and use in source and binary forms, with or without
1317
+ * modification, are permitted provided that the following conditions are met:
1318
+ *
1319
+ * 1. Redistributions of source code must retain the above copyright notice, this
1320
+ * list of conditions and the following disclaimer.
1321
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
1322
+ * this list of conditions and the following disclaimer in the
1323
+ * documentation and/or other materials provided with the distribution.
1324
+ * 3. Neither the name of the copyright holder nor the names of its contributors
1325
+ * may be used to endorse or promote products derived from this software without
1326
+ * specific prior written permission.
1327
+ *
1328
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1329
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1330
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1331
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
1332
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1333
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1334
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1335
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1336
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1337
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1338
+ */
1339
+ /** @internal */
1340
+ function parseKey(ctx, end = 61) {
1341
+ let startPtr;
1342
+ let state = 0;
1343
+ let parsed = [];
1344
+ let sliceStart;
1345
+ let c = ctx.s.charCodeAt(startPtr = ctx.p);
1346
+ do
1347
+ if (c === end) {
1348
+ if (!state) TomlError.x("unexpected end of key", ctx);
1349
+ if (state === 1) parsed.push(ctx.s.slice(sliceStart, ctx.p));
1350
+ return ctx.p++, parsed;
1351
+ } else if (c === 46) {
1352
+ if (!state) TomlError.x("illegal empty bare key", ctx);
1353
+ if (state === 1) parsed.push(ctx.s.slice(sliceStart, ctx.p));
1354
+ state = 0;
1355
+ } else if (!state && (c === 34 || c === 39)) {
1356
+ if (c === ctx.s.charCodeAt(ctx.p + 1) && c === ctx.s.charCodeAt(ctx.p + 2)) TomlError.x("illegal quoted key: multiline strings are not allowed", ctx);
1357
+ parsed.push(parseString(ctx));
1358
+ state = 2;
1359
+ ctx.p--;
1360
+ } else if (c === 32 || c === 9) {
1361
+ if (state === 1) {
1362
+ parsed.push(ctx.s.slice(sliceStart, ctx.p));
1363
+ state = 2;
1364
+ }
1365
+ } else if (state === 2 || c < 48 && c !== 45 || c > 57 && c < 65 || c > 90 && c < 97 && c !== 95 || c > 122) TomlError.x("illegal character in key", ctx);
1366
+ else if (!state) {
1367
+ state = 1;
1368
+ sliceStart = ctx.p;
1369
+ }
1370
+ while (c = ctx.s.charCodeAt(++ctx.p));
1371
+ TomlError.x("incomplete key-value: cannot find end of key", ctx, startPtr);
1372
+ }
1373
+ /** @internal */
1374
+ function parseInlineTable(ctx) {
1375
+ let startPtr = ctx.p++;
1376
+ let res = Object.create(null);
1377
+ let seen = /* @__PURE__ */ new Set();
1378
+ let c;
1379
+ while (ctx.p < ctx.s.length) {
1380
+ skipVoid(ctx);
1381
+ if ((c = ctx.s.charCodeAt(ctx.p)) === 125) {
1382
+ ctx.p++;
1383
+ return res;
1384
+ }
1385
+ let k;
1386
+ let t = res;
1387
+ let hasOwn = false;
1388
+ let errPtr = ctx.p;
1389
+ let key = parseKey(ctx);
1390
+ for (let i = 0; i < key.length; i++) {
1391
+ if (i) t = hasOwn ? t[k] : t[k] = Object.create(null);
1392
+ k = key[i];
1393
+ if ((hasOwn = Object.hasOwn(t, k)) && (typeof t[k] !== "object" || seen.has(t[k]))) TomlError.x("trying to redefine an already defined value", ctx, errPtr);
1394
+ let unsafe = k === "__proto__";
1395
+ if (ctx.uk && (unsafe || k === "constructor")) {
1396
+ t = ctx.uk !== 1 && TomlError.x("document contains an unsafe property", ctx, errPtr);
1397
+ break;
1398
+ }
1399
+ if (!hasOwn && unsafe) Object.defineProperty(t, k, {
1400
+ enumerable: true,
1401
+ configurable: true,
1402
+ writable: true
1403
+ });
1404
+ }
1405
+ if (hasOwn) TomlError.x("trying to redefine an already defined value", ctx, errPtr);
1406
+ skipVoid(ctx, true, true);
1407
+ let value = extractValue(ctx, 125);
1408
+ if (t && typeof (t[k] = value) === "object") seen.add(value);
1409
+ skipVoid(ctx);
1410
+ if ((c = ctx.s.charCodeAt(ctx.p++)) === 125) return res;
1411
+ if (c !== 44) TomlError.x("expected comma or end of structure", ctx, ctx.p - 1);
1412
+ }
1413
+ TomlError.x("unfinished table", ctx, startPtr);
1414
+ }
1415
+ /** @internal */
1416
+ function parseArray(ctx) {
1417
+ let startPtr = ctx.p++;
1418
+ let res = [];
1419
+ let c;
1420
+ while (ctx.p < ctx.s.length) {
1421
+ skipVoid(ctx);
1422
+ if ((c = ctx.s.charCodeAt(ctx.p)) === 93) {
1423
+ ctx.p++;
1424
+ return res;
1425
+ }
1426
+ res.push(extractValue(ctx, 93));
1427
+ skipVoid(ctx);
1428
+ if ((c = ctx.s.charCodeAt(ctx.p++)) === 93) return res;
1429
+ if (c !== 44) TomlError.x("expected comma or end of structure", ctx, ctx.p - 1);
1430
+ }
1431
+ TomlError.x("unfinished array", ctx, startPtr);
1432
+ }
1433
+ //#endregion
1434
+ //#region ../../node_modules/.pnpm/smol-toml@1.9.0/node_modules/smol-toml/dist/parse.js
1435
+ /*!
1436
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
1437
+ * SPDX-License-Identifier: BSD-3-Clause
1438
+ *
1439
+ * Redistribution and use in source and binary forms, with or without
1440
+ * modification, are permitted provided that the following conditions are met:
1441
+ *
1442
+ * 1. Redistributions of source code must retain the above copyright notice, this
1443
+ * list of conditions and the following disclaimer.
1444
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
1445
+ * this list of conditions and the following disclaimer in the
1446
+ * documentation and/or other materials provided with the distribution.
1447
+ * 3. Neither the name of the copyright holder nor the names of its contributors
1448
+ * may be used to endorse or promote products derived from this software without
1449
+ * specific prior written permission.
1450
+ *
1451
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1452
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1453
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1454
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
1455
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1456
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1457
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1458
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1459
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1460
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1461
+ */
1462
+ function peekTable(ctx, key, table, meta, type) {
1463
+ let t = table;
1464
+ let m = meta;
1465
+ let k;
1466
+ let hasOwn = false;
1467
+ let state;
1468
+ for (let i = 0; i < key.length; i++) {
1469
+ if (i) {
1470
+ t = hasOwn ? t[k] : t[k] = Object.create(null);
1471
+ m = (state = m[k]).c;
1472
+ if (type === 0 && (state.t === 1 || state.t === 2)) return null;
1473
+ if (state.t === 2) {
1474
+ let l = t.length - 1;
1475
+ t = t[l];
1476
+ m = m[l].c;
1477
+ }
1478
+ }
1479
+ k = key[i];
1480
+ if ((hasOwn = Object.hasOwn(t, k)) && m[k]?.t === 0 && m[k]?.d) return null;
1481
+ if (!hasOwn) {
1482
+ let unsafe = k === "__proto__";
1483
+ if (ctx.uk && (unsafe || k === "constructor")) return false;
1484
+ if (unsafe) {
1485
+ Object.defineProperty(t, k, {
1486
+ enumerable: true,
1487
+ configurable: true,
1488
+ writable: true
1489
+ });
1490
+ Object.defineProperty(m, k, {
1491
+ enumerable: true,
1492
+ configurable: true,
1493
+ writable: true
1494
+ });
1495
+ }
1496
+ m[k] = {
1497
+ t: i < key.length - 1 && type === 2 ? 3 : type,
1498
+ d: false,
1499
+ i: 0,
1500
+ c: Object.create(null)
1501
+ };
1502
+ }
1503
+ }
1504
+ state = m[k];
1505
+ if (state.t !== type && !(type === 1 && state.t === 3)) return null;
1506
+ if (type === 2) {
1507
+ if (!state.d) {
1508
+ state.d = true;
1509
+ t[k] = [];
1510
+ }
1511
+ t[k].push(t = Object.create(null));
1512
+ state.c[state.i++] = state = {
1513
+ t: 1,
1514
+ d: false,
1515
+ i: 0,
1516
+ c: Object.create(null)
1517
+ };
1518
+ }
1519
+ if (state.d) return null;
1520
+ state.d = true;
1521
+ if (type === 1) t = hasOwn ? t[k] : t[k] = Object.create(null);
1522
+ else if (type === 0 && hasOwn) return null;
1523
+ return [
1524
+ k,
1525
+ t,
1526
+ state.c
1527
+ ];
1528
+ }
1529
+ function validateTablePeek(ctx, peek, ptr) {
1530
+ if (peek === null || ctx.uk === 2) TomlError.x(peek === null ? "trying to redefine an already defined table or value" : "document contains an unsafe property", ctx, ptr);
1531
+ }
1532
+ function parse(toml, options = {}) {
1533
+ let ctx = {
1534
+ s: toml,
1535
+ p: 0,
1536
+ d: options.maxDepth ?? 1e3,
1537
+ bi: options.integersAsBigInt ?? false,
1538
+ ld: options.useLegacyDate ?? true,
1539
+ uk: options.unsafeKeyBehaviour === "throw" ? 2 : options.unsafeKeyBehaviour === "drop" ? 1 : 0
1540
+ };
1541
+ let res = Object.create(null);
1542
+ let meta = Object.create(null);
1543
+ let tmp;
1544
+ let skipping = false;
1545
+ let tbl = res;
1546
+ let m = meta;
1547
+ if (toml.charCodeAt(0) === 65279) ctx.p++;
1548
+ skipVoid(ctx);
1549
+ while (ctx.p < toml.length) {
1550
+ if (toml.charCodeAt(ctx.p) === 91) {
1551
+ let isTableArray = toml.charCodeAt(++ctx.p) === 91;
1552
+ tmp = ctx.p += +isTableArray;
1553
+ skipping = false;
1554
+ let k = parseKey(ctx, 93);
1555
+ if (isTableArray) {
1556
+ if (toml.charCodeAt(ctx.p) !== 93) TomlError.x("expected end of table array declaration", ctx);
1557
+ ctx.p++;
1558
+ }
1559
+ let p = peekTable(ctx, k, res, meta, isTableArray ? 2 : 1);
1560
+ if (!p) {
1561
+ validateTablePeek(ctx, p, tmp);
1562
+ skipping = true;
1563
+ } else {
1564
+ m = p[2];
1565
+ tbl = p[1];
1566
+ }
1567
+ } else {
1568
+ tmp = ctx.p;
1569
+ let p = peekTable(ctx, parseKey(ctx), tbl, m, 0);
1570
+ if (!p && !skipping) validateTablePeek(ctx, p, tmp);
1571
+ skipVoid(ctx, true, true);
1572
+ let v = extractValue(ctx, void 0);
1573
+ if (p && !skipping) p[1][p[0]] = v;
1574
+ }
1575
+ skipVoid(ctx, true);
1576
+ if (ctx.p < toml.length && (tmp = toml.charCodeAt(ctx.p)) !== 10 && (tmp !== 13 || toml.charCodeAt(ctx.p + 1) !== 10)) TomlError.x("each key-value declaration must be followed by an end-of-line", ctx);
1577
+ skipVoid(ctx);
1578
+ }
1579
+ return res;
1580
+ }
1581
+ /*!
1582
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
1583
+ * SPDX-License-Identifier: BSD-3-Clause
1584
+ *
1585
+ * Redistribution and use in source and binary forms, with or without
1586
+ * modification, are permitted provided that the following conditions are met:
1587
+ *
1588
+ * 1. Redistributions of source code must retain the above copyright notice, this
1589
+ * list of conditions and the following disclaimer.
1590
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
1591
+ * this list of conditions and the following disclaimer in the
1592
+ * documentation and/or other materials provided with the distribution.
1593
+ * 3. Neither the name of the copyright holder nor the names of its contributors
1594
+ * may be used to endorse or promote products derived from this software without
1595
+ * specific prior written permission.
1596
+ *
1597
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1598
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1599
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1600
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
1601
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1602
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1603
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1604
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1605
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1606
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1607
+ */
1608
+ "".isWellFormed;
1609
+ //#endregion
1610
+ //#region ../../node_modules/.pnpm/smol-toml@1.9.0/node_modules/smol-toml/dist/index.js
1611
+ /*!
1612
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
1613
+ * SPDX-License-Identifier: BSD-3-Clause
1614
+ *
1615
+ * Redistribution and use in source and binary forms, with or without
1616
+ * modification, are permitted provided that the following conditions are met:
1617
+ *
1618
+ * 1. Redistributions of source code must retain the above copyright notice, this
1619
+ * list of conditions and the following disclaimer.
1620
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
1621
+ * this list of conditions and the following disclaimer in the
1622
+ * documentation and/or other materials provided with the distribution.
1623
+ * 3. Neither the name of the copyright holder nor the names of its contributors
1624
+ * may be used to endorse or promote products derived from this software without
1625
+ * specific prior written permission.
1626
+ *
1627
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1628
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1629
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1630
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
1631
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1632
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1633
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1634
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1635
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1636
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1637
+ */
1638
+ //#endregion
1639
+ //#region src/cli/supabase-toml.ts
1640
+ const CONFIG_TOML = "supabase/config.toml";
1641
+ /**
1642
+ * `@supabase/config` is an optional peer (it needs `effect` and
1643
+ * `@effect/platform-node`), so it is imported lazily through a variable:
1644
+ * projects without it get smol-toml instead of a load error.
1645
+ */
1646
+ async function loadSupabaseConfig() {
1647
+ const specifier = "@supabase/config/io";
1648
+ try {
1649
+ return await import(specifier);
1650
+ } catch {
1651
+ return;
1652
+ }
1653
+ }
1654
+ function toTomlValue(value) {
1655
+ if (Array.isArray(value)) return value.map(toTomlValue);
1656
+ if (value instanceof Date) return value.toISOString();
1657
+ if (typeof value === "bigint") return Number(value);
1658
+ if (typeof value === "object" && value !== null) return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, toTomlValue(item)]));
1659
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") return value;
1660
+ return String(value);
1661
+ }
1662
+ /** `text` as TOML, with dates as ISO strings; an empty table when it does not parse. */
1663
+ function parseToml(text) {
1664
+ try {
1665
+ return Object.fromEntries(Object.entries(parse(text)).map(([key, value]) => [key, toTomlValue(value)]));
1666
+ } catch {
1667
+ return {};
1668
+ }
1669
+ }
1670
+ const parsed = /* @__PURE__ */ new Map();
1671
+ /**
1672
+ * Reads `supabase/config.toml`. A file with `env()` values goes through
1673
+ * `@supabase/config` when it is installed, which resolves them; any other
1674
+ * file, or a project without it, is parsed with smol-toml, since loading
1675
+ * `@supabase/config` costs hundreds of milliseconds. Parses are reused while
1676
+ * the file's text is unchanged.
1677
+ */
1678
+ async function readSupabaseToml(root) {
1679
+ const absolute = join(root, CONFIG_TOML);
1680
+ if (!existsSync(absolute)) return void 0;
1681
+ const text = await readFile(absolute, "utf8");
1682
+ const cached = parsed.get(absolute);
1683
+ if (cached?.text === text) return cached.toml;
1684
+ const toml = parseSupabaseToml(root, text);
1685
+ parsed.set(absolute, {
1686
+ text,
1687
+ toml
1688
+ });
1689
+ return toml;
1690
+ }
1691
+ async function parseSupabaseToml(root, text) {
1692
+ const io = text.includes("env(") ? await loadSupabaseConfig() : void 0;
1693
+ if (io) try {
1694
+ const loaded = await io.loadCliConfig(root, {
1695
+ tomlOnly: true,
1696
+ search: false
1697
+ });
1698
+ if (loaded?.document) return {
1699
+ path: CONFIG_TOML,
1700
+ text,
1701
+ document: loaded.document,
1702
+ parser: "@supabase/config"
1703
+ };
1704
+ } catch {}
1705
+ return {
1706
+ path: CONFIG_TOML,
1707
+ text,
1708
+ document: parseToml(text),
1709
+ parser: "smol-toml"
1710
+ };
1711
+ }
1712
+ /** The value at `path` (`['auth', 'jwt_expiry']`), if present. */
1713
+ function tomlGet(document, path) {
1714
+ let value = document;
1715
+ for (const key of path) {
1716
+ if (typeof value !== "object" || Array.isArray(value)) return void 0;
1717
+ value = value[key];
1718
+ }
1719
+ return value;
1720
+ }
1721
+ function tomlNumber(document, path) {
1722
+ const value = tomlGet(document, path);
1723
+ if (typeof value === "number") return value;
1724
+ if (typeof value === "string" && value.trim() !== "" && Number.isFinite(Number(value))) return Number(value);
1725
+ }
1726
+ /** `pg-functions://postgres/<schema>/<function>` as schema and name. */
1727
+ function parsePgFunctionUri(uri) {
1728
+ const match = /^pg-functions:\/\/[^/]+\/([^/]+)\/([^/?#]+)$/.exec(uri.trim());
1729
+ return match ? {
1730
+ schema: match[1],
1731
+ name: match[2]
1732
+ } : void 0;
1733
+ }
1734
+ /** The enabled Auth hooks with a `pg-functions://` URI, by hook name. */
1735
+ function pgFunctionHooks(document) {
1736
+ const hooks = tomlGet(document, ["auth", "hook"]);
1737
+ if (typeof hooks !== "object" || Array.isArray(hooks)) return [];
1738
+ return Object.entries(hooks).flatMap(([hook, table]) => {
1739
+ if (typeof table !== "object" || Array.isArray(table)) return [];
1740
+ const { enabled, uri } = table;
1741
+ if (enabled !== true && enabled !== "true" || typeof uri !== "string") return [];
1742
+ const target = parsePgFunctionUri(uri);
1743
+ return target ? [{
1744
+ hook,
1745
+ uri,
1746
+ ...target
1747
+ }] : [];
1748
+ });
1749
+ }
1750
+ /** pg-delta when `[experimental.pgdelta] enabled = true`, otherwise the legacy migra engine. */
1751
+ function diffEngine(toml) {
1752
+ const enabled = tomlGet(toml?.document ?? {}, [
1753
+ "experimental",
1754
+ "pgdelta",
1755
+ "enabled"
1756
+ ]);
1757
+ return enabled === true || enabled === "true" ? "pg-delta" : "migra";
1758
+ }
1759
+ /** The command that writes a migration (named `name`, when given) from `supabase/schemas`. */
1760
+ function migrationCommand(toml, name) {
1761
+ const command = diffEngine(toml) === "pg-delta" ? "supabase db schema declarative sync" : "supabase db diff";
1762
+ return name === void 0 ? command : `${command} -f ${name}`;
1763
+ }
1764
+ const SCHEMAS_DIR = "supabase/schemas";
1765
+ /** `experimental.pgdelta.declarative_schema_path` (relative to `supabase/`), or `./schemas`. */
1766
+ function pgDeltaSchemasDir(toml) {
1767
+ const dir = tomlGet(toml?.document ?? {}, [
1768
+ "experimental",
1769
+ "pgdelta",
1770
+ "declarative_schema_path"
1771
+ ]);
1772
+ const relative = typeof dir === "string" && dir.trim() !== "" ? dir : "schemas";
1773
+ return posix.join("supabase", relative.replace(/^\.\//, "").replace(/\/$/, ""));
1774
+ }
1775
+ async function expand(cwd, pattern) {
1776
+ const matched = [];
1777
+ for await (const path of glob(pattern.replace(/^\.\//, ""), { cwd })) if (path.endsWith(".sql")) matched.push(path.replaceAll("\\", "/"));
1778
+ return matched.sort();
1779
+ }
1780
+ /**
1781
+ * `[db.migrations] schema_paths` (relative to `supabase/`) with each glob
1782
+ * expanded in name order and the entries kept in their listed order, then
1783
+ * the `supabase/schemas` files no entry matches. Without `schema_paths`, the
1784
+ * `supabase/schemas` files in name order, as the Supabase CLI reads them.
1785
+ * pg-delta ignores `schema_paths` and orders by dependency, so under it every
1786
+ * file in its schema directory counts, in name order.
1787
+ */
1788
+ async function schemaPaths(root, toml) {
1789
+ if (diffEngine(toml) === "pg-delta") {
1790
+ const dir = pgDeltaSchemasDir(toml);
1791
+ return {
1792
+ files: existsSync(join(root, dir)) ? await expand(root, `${dir}/**/*.sql`) : [],
1793
+ unlisted: [],
1794
+ configured: false
1795
+ };
1796
+ }
1797
+ const supabase = join(root, "supabase");
1798
+ const all = existsSync(join(root, SCHEMAS_DIR)) ? (await expand(supabase, "schemas/**/*.sql")).map((path) => posix.join("supabase", path)) : [];
1799
+ const entries = tomlGet(toml?.document ?? {}, [
1800
+ "db",
1801
+ "migrations",
1802
+ "schema_paths"
1803
+ ]);
1804
+ const patterns = Array.isArray(entries) ? entries.filter((entry) => typeof entry === "string") : [];
1805
+ if (patterns.length === 0) return {
1806
+ files: all,
1807
+ unlisted: [],
1808
+ configured: false
1809
+ };
1810
+ const listed = /* @__PURE__ */ new Set();
1811
+ for (const pattern of patterns) for (const path of await expand(supabase, pattern)) listed.add(posix.join("supabase", path));
1812
+ const unlisted = all.filter((path) => !listed.has(path));
1813
+ return {
1814
+ files: [...listed, ...unlisted],
1815
+ unlisted,
1816
+ configured: true
1817
+ };
1818
+ }
1819
+ //#endregion
1820
+ //#region src/cli/config.ts
1821
+ const CONFIG_FILES = [
1822
+ "better-supabase.config.ts",
1823
+ "better-supabase.config.mts",
1824
+ "better-supabase.config.js",
1825
+ "better-supabase.config.mjs",
1826
+ "better-supabase.config.json"
1827
+ ];
1828
+ function findConfig(cwd, explicit) {
1829
+ if (explicit) return resolve(cwd, explicit);
1830
+ for (const name of CONFIG_FILES) {
1831
+ const path = join(cwd, name);
1832
+ if (existsSync(path)) return path;
1833
+ }
1834
+ }
1835
+ /** Imports a project module fresh, so watch loops and tests see edits. */
1836
+ async function importModule(path) {
1837
+ return await import(`${pathToFileURL(path).href}?t=${Date.now()}`);
1838
+ }
1839
+ /** The named export, then `default`, of a project module. */
1840
+ async function importExport(path, name) {
1841
+ if (!existsSync(path)) throw new Error(`Module not found: ${path}`);
1842
+ const loaded = await importModule(path);
1843
+ return loaded[name] ?? loaded["default"];
1844
+ }
1845
+ function isConfig(value) {
1846
+ return configIssues(value).length === 0;
1847
+ }
1848
+ /**
1849
+ * Loads `better-supabase.config.*` with c12 and checks it against the config
1850
+ * schema. c12 imports `.ts` natively (Node 24 strips the types), so no
1851
+ * loader is needed; rc files, `package.json`, env overrides and `extends`
1852
+ * are off so the one file is the whole config.
1853
+ */
1854
+ async function loadConfig(cwd, explicit) {
1855
+ const path = findConfig(cwd, explicit);
1856
+ if (!path) return resolveConfig({}, cwd);
1857
+ if (!existsSync(path)) throw new CliError("config_not_found", `Config file not found: ${path}`);
1858
+ const { config } = await loadConfig$1({
1859
+ cwd,
1860
+ configFile: path,
1861
+ rcFile: false,
1862
+ globalRc: false,
1863
+ packageJson: false,
1864
+ dotenv: false,
1865
+ envName: false,
1866
+ extend: false,
1867
+ giget: false
1868
+ });
1869
+ if (!isConfig(config)) {
1870
+ const issues = configIssues(config);
1871
+ throw new CliError("config_invalid", `${display(cwd, path)} is not a valid config:\n${issues.map((issue) => ` ${issue}`).join("\n")}`, { issues });
1872
+ }
1873
+ return resolveConfig(config, cwd);
1874
+ }
1875
+ /** `[db] port` or `[api] port` from `supabase/config.toml`. */
1876
+ async function readSupabasePort(root, section) {
1877
+ const toml = await readSupabaseToml(root);
1878
+ return toml ? tomlNumber(toml.document, [section, "port"]) : void 0;
1879
+ }
1880
+ /** The connection string piped in for `--db-url-stdin`, when it was passed. */
1881
+ async function stdinDatabaseUrl(enabled, io) {
1882
+ if (enabled !== true) return void 0;
1883
+ const url = (await io.stdin?.())?.trim();
1884
+ if (!url) throw new CliError("missing_value", "--db-url-stdin read nothing from stdin. Pipe the connection string: printf %s \"$URL\" | better-supabase <command> --db-url-stdin", { flag: "--db-url-stdin" });
1885
+ return url;
1886
+ }
1887
+ /** Connection string: stdin, config, `$DATABASE_URL`, then the local stack. */
1888
+ async function databaseUrl(config, env, fromStdin) {
1889
+ if (fromStdin) return fromStdin;
1890
+ if (config.source.dbUrl) return config.source.dbUrl;
1891
+ if (env.DATABASE_URL) return env.DATABASE_URL;
1892
+ return `postgresql://postgres:postgres@127.0.0.1:${await readSupabasePort(config.root, "db") ?? 54322}/postgres`;
1893
+ }
1894
+ //#endregion
1895
+ export { loadConfig as a, diffEngine as c, readSupabaseToml as d, schemaPaths as f, importModule as i, migrationCommand as l, findConfig as n, readSupabasePort as o, tomlGet as p, importExport as r, stdinDatabaseUrl as s, databaseUrl as t, pgFunctionHooks as u };