@carllee1983/dbcli 9.1.1 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.cursor/rules/dbcli.mdc +55 -17
- package/.cursor/skills/dbcli/reference.md +71 -18
- package/.cursor-plugin/plugin.json +1 -1
- package/.github/skills/dbcli/SKILL.md +55 -17
- package/.github/skills/dbcli/reference.md +71 -18
- package/CHANGELOG.md +157 -0
- package/README.dev.md +19 -6
- package/README.md +68 -56
- package/README.zh-TW.md +45 -12
- package/assets/SKILL.md +55 -17
- package/assets/reference.md +71 -18
- package/assets/ui-template.html +24 -24
- package/dist/agent-core.mjs +5 -5
- package/dist/cli-runtime.mjs +2683 -3425
- package/dist/cli.mjs +5 -7
- package/dist/core.d.ts +7 -9
- package/dist/core.mjs +537 -1537
- package/gemini-extension.json +1 -1
- package/package.json +3 -5
- package/plugins/dbcli-agent/.codex-plugin/plugin.json +1 -1
- package/plugins/dbcli-agent/skills/dbcli/SKILL.md +55 -17
- package/plugins/dbcli-agent/skills/dbcli/reference.md +71 -18
- package/scripts/postinstall-check-bun.mjs +1 -1
- package/skills/dbcli/SKILL.md +55 -17
- package/skills/dbcli/reference.md +71 -18
- package/.agents/skills/story-development/SKILL.md +0 -70
package/dist/core.mjs
CHANGED
|
@@ -1,141 +1,36 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
-
var canCache = mod != null && typeof mod === "object";
|
|
14
|
-
if (canCache) {
|
|
15
|
-
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
-
var cached = cache.get(mod);
|
|
17
|
-
if (cached)
|
|
18
|
-
return cached;
|
|
19
|
-
}
|
|
20
|
-
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
21
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
|
-
for (let key of __getOwnPropNames(mod))
|
|
23
|
-
if (!__hasOwnProp.call(to, key))
|
|
24
|
-
__defProp(to, key, {
|
|
25
|
-
get: __accessProp.bind(mod, key),
|
|
26
|
-
enumerable: true
|
|
27
|
-
});
|
|
28
|
-
if (canCache)
|
|
29
|
-
cache.set(mod, to);
|
|
30
|
-
return to;
|
|
31
|
-
};
|
|
32
|
-
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
33
|
-
var __returnValue = (v) => v;
|
|
34
|
-
function __exportSetter(name, newValue) {
|
|
35
|
-
this[name] = __returnValue.bind(null, newValue);
|
|
36
|
-
}
|
|
37
|
-
var __export = (target, all) => {
|
|
38
|
-
for (var name in all)
|
|
39
|
-
__defProp(target, name, {
|
|
40
|
-
get: all[name],
|
|
41
|
-
enumerable: true,
|
|
42
|
-
configurable: true,
|
|
43
|
-
set: __exportSetter.bind(all, name)
|
|
44
|
-
});
|
|
2
|
+
var __esm = (fn, res, err) => () => {
|
|
3
|
+
if (fn)
|
|
4
|
+
try {
|
|
5
|
+
res = fn(fn = 0);
|
|
6
|
+
} catch (e) {
|
|
7
|
+
err = [e];
|
|
8
|
+
}
|
|
9
|
+
if (err)
|
|
10
|
+
throw err[0];
|
|
11
|
+
return res;
|
|
45
12
|
};
|
|
46
|
-
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
47
|
-
var __require = import.meta.require;
|
|
48
|
-
|
|
49
|
-
// node_modules/picocolors/picocolors.js
|
|
50
|
-
var require_picocolors = __commonJS((exports, module) => {
|
|
51
|
-
var p = process || {};
|
|
52
|
-
var argv = p.argv || [];
|
|
53
|
-
var env = p.env || {};
|
|
54
|
-
var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
55
|
-
var formatter = (open, close, replace = open) => (input) => {
|
|
56
|
-
let string = "" + input, index = string.indexOf(close, open.length);
|
|
57
|
-
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
58
|
-
};
|
|
59
|
-
var replaceClose = (string, close, replace, index) => {
|
|
60
|
-
let result = "", cursor = 0;
|
|
61
|
-
do {
|
|
62
|
-
result += string.substring(cursor, index) + replace;
|
|
63
|
-
cursor = index + close.length;
|
|
64
|
-
index = string.indexOf(close, cursor);
|
|
65
|
-
} while (~index);
|
|
66
|
-
return result + string.substring(cursor);
|
|
67
|
-
};
|
|
68
|
-
var createColors = (enabled = isColorSupported) => {
|
|
69
|
-
let f = enabled ? formatter : () => String;
|
|
70
|
-
return {
|
|
71
|
-
isColorSupported: enabled,
|
|
72
|
-
reset: f("\x1B[0m", "\x1B[0m"),
|
|
73
|
-
bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
74
|
-
dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
75
|
-
italic: f("\x1B[3m", "\x1B[23m"),
|
|
76
|
-
underline: f("\x1B[4m", "\x1B[24m"),
|
|
77
|
-
inverse: f("\x1B[7m", "\x1B[27m"),
|
|
78
|
-
hidden: f("\x1B[8m", "\x1B[28m"),
|
|
79
|
-
strikethrough: f("\x1B[9m", "\x1B[29m"),
|
|
80
|
-
black: f("\x1B[30m", "\x1B[39m"),
|
|
81
|
-
red: f("\x1B[31m", "\x1B[39m"),
|
|
82
|
-
green: f("\x1B[32m", "\x1B[39m"),
|
|
83
|
-
yellow: f("\x1B[33m", "\x1B[39m"),
|
|
84
|
-
blue: f("\x1B[34m", "\x1B[39m"),
|
|
85
|
-
magenta: f("\x1B[35m", "\x1B[39m"),
|
|
86
|
-
cyan: f("\x1B[36m", "\x1B[39m"),
|
|
87
|
-
white: f("\x1B[37m", "\x1B[39m"),
|
|
88
|
-
gray: f("\x1B[90m", "\x1B[39m"),
|
|
89
|
-
bgBlack: f("\x1B[40m", "\x1B[49m"),
|
|
90
|
-
bgRed: f("\x1B[41m", "\x1B[49m"),
|
|
91
|
-
bgGreen: f("\x1B[42m", "\x1B[49m"),
|
|
92
|
-
bgYellow: f("\x1B[43m", "\x1B[49m"),
|
|
93
|
-
bgBlue: f("\x1B[44m", "\x1B[49m"),
|
|
94
|
-
bgMagenta: f("\x1B[45m", "\x1B[49m"),
|
|
95
|
-
bgCyan: f("\x1B[46m", "\x1B[49m"),
|
|
96
|
-
bgWhite: f("\x1B[47m", "\x1B[49m"),
|
|
97
|
-
blackBright: f("\x1B[90m", "\x1B[39m"),
|
|
98
|
-
redBright: f("\x1B[91m", "\x1B[39m"),
|
|
99
|
-
greenBright: f("\x1B[92m", "\x1B[39m"),
|
|
100
|
-
yellowBright: f("\x1B[93m", "\x1B[39m"),
|
|
101
|
-
blueBright: f("\x1B[94m", "\x1B[39m"),
|
|
102
|
-
magentaBright: f("\x1B[95m", "\x1B[39m"),
|
|
103
|
-
cyanBright: f("\x1B[96m", "\x1B[39m"),
|
|
104
|
-
whiteBright: f("\x1B[97m", "\x1B[39m"),
|
|
105
|
-
bgBlackBright: f("\x1B[100m", "\x1B[49m"),
|
|
106
|
-
bgRedBright: f("\x1B[101m", "\x1B[49m"),
|
|
107
|
-
bgGreenBright: f("\x1B[102m", "\x1B[49m"),
|
|
108
|
-
bgYellowBright: f("\x1B[103m", "\x1B[49m"),
|
|
109
|
-
bgBlueBright: f("\x1B[104m", "\x1B[49m"),
|
|
110
|
-
bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
|
|
111
|
-
bgCyanBright: f("\x1B[106m", "\x1B[49m"),
|
|
112
|
-
bgWhiteBright: f("\x1B[107m", "\x1B[49m")
|
|
113
|
-
};
|
|
114
|
-
};
|
|
115
|
-
module.exports = createColors();
|
|
116
|
-
module.exports.createColors = createColors;
|
|
117
|
-
});
|
|
118
13
|
|
|
119
14
|
// node_modules/lru-cache/dist/esm/node/index.min.js
|
|
120
15
|
import { tracingChannel as j, channel as G } from "diagnostics_channel";
|
|
121
|
-
var w, W, C, D = () => w.hasSubscribers || W.hasSubscribers, I, L, P = (u, e,
|
|
122
|
-
typeof L.emitWarning == "function" ? L.emitWarning(u, e,
|
|
16
|
+
var w, W, C, D = () => w.hasSubscribers || W.hasSubscribers, I, L, P = (u, e, t, i) => {
|
|
17
|
+
typeof L.emitWarning == "function" ? L.emitWarning(u, e, t, i) : console.error(`[${t}] ${e}: ${u}`);
|
|
123
18
|
}, H = (u) => !I.has(u), T = (u) => !!u && u === Math.floor(u) && u > 0 && isFinite(u), U = (u) => T(u) ? u <= Math.pow(2, 8) ? Uint8Array : u <= Math.pow(2, 16) ? Uint16Array : u <= Math.pow(2, 32) ? Uint32Array : u <= Number.MAX_SAFE_INTEGER ? O : null : null, O, R = class u {
|
|
124
19
|
heap;
|
|
125
20
|
length;
|
|
126
21
|
static #o = false;
|
|
127
22
|
static create(e) {
|
|
128
|
-
let
|
|
129
|
-
if (!
|
|
23
|
+
let t = U(e);
|
|
24
|
+
if (!t)
|
|
130
25
|
return [];
|
|
131
26
|
u.#o = true;
|
|
132
|
-
let i = new u(e,
|
|
27
|
+
let i = new u(e, t);
|
|
133
28
|
return u.#o = false, i;
|
|
134
29
|
}
|
|
135
|
-
constructor(e,
|
|
30
|
+
constructor(e, t) {
|
|
136
31
|
if (!u.#o)
|
|
137
32
|
throw new TypeError("instantiate Stack using Stack.create(n)");
|
|
138
|
-
this.heap = new
|
|
33
|
+
this.heap = new t(e), this.length = 0;
|
|
139
34
|
}
|
|
140
35
|
push(e) {
|
|
141
36
|
this.heap[this.length++] = e;
|
|
@@ -155,7 +50,7 @@ var init_index_min = __esm(() => {
|
|
|
155
50
|
super(e), this.fill(0);
|
|
156
51
|
}
|
|
157
52
|
};
|
|
158
|
-
M = class
|
|
53
|
+
M = class u {
|
|
159
54
|
#o;
|
|
160
55
|
#c;
|
|
161
56
|
#w;
|
|
@@ -206,7 +101,7 @@ var init_index_min = __esm(() => {
|
|
|
206
101
|
return e.#a;
|
|
207
102
|
}, get tail() {
|
|
208
103
|
return e.#h;
|
|
209
|
-
}, free: e.#y, isBackgroundFetch: (
|
|
104
|
+
}, free: e.#y, isBackgroundFetch: (t) => e.#e(t), backgroundFetch: (t, i, s, n) => e.#P(t, i, s, n), moveToTail: (t) => e.#L(t), indexes: (t) => e.#A(t), rindexes: (t) => e.#z(t), isStale: (t) => e.#p(t) };
|
|
210
105
|
}
|
|
211
106
|
get max() {
|
|
212
107
|
return this.#o;
|
|
@@ -236,15 +131,15 @@ var init_index_min = __esm(() => {
|
|
|
236
131
|
return this.#S;
|
|
237
132
|
}
|
|
238
133
|
constructor(e) {
|
|
239
|
-
let { max:
|
|
134
|
+
let { max: t = 0, ttl: i, ttlResolution: s = 1, ttlAutopurge: n, updateAgeOnGet: r, updateAgeOnHas: h, allowStale: a, dispose: o, onInsert: p, disposeAfter: m, noDisposeOnSet: _, noUpdateTTL: c, maxSize: d = 0, maxEntrySize: f = 0, sizeCalculation: y, fetchMethod: l, memoMethod: S, noDeleteOnFetchRejection: F, noDeleteOnStaleGet: b, allowStaleOnFetchRejection: g, allowStaleOnFetchAbort: A, ignoreFetchAbort: z, perf: x } = e;
|
|
240
135
|
if (x !== undefined && typeof x?.now != "function")
|
|
241
136
|
throw new TypeError("perf option must have a now() method if specified");
|
|
242
|
-
if (this.#m = x ?? C,
|
|
137
|
+
if (this.#m = x ?? C, t !== 0 && !T(t))
|
|
243
138
|
throw new TypeError("max option must be a nonnegative integer");
|
|
244
|
-
let E =
|
|
139
|
+
let E = t ? U(t) : Array;
|
|
245
140
|
if (!E)
|
|
246
|
-
throw new Error("invalid max value: " +
|
|
247
|
-
if (this.#o =
|
|
141
|
+
throw new Error("invalid max value: " + t);
|
|
142
|
+
if (this.#o = t, this.#c = d, this.maxEntrySize = f || this.#c, this.sizeCalculation = y, this.sizeCalculation) {
|
|
248
143
|
if (!this.#c && !this.maxEntrySize)
|
|
249
144
|
throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
|
|
250
145
|
if (typeof this.sizeCalculation != "function")
|
|
@@ -254,7 +149,7 @@ var init_index_min = __esm(() => {
|
|
|
254
149
|
throw new TypeError("memoMethod must be a function if defined");
|
|
255
150
|
if (this.#I = S, l !== undefined && typeof l != "function")
|
|
256
151
|
throw new TypeError("fetchMethod must be a function if specified");
|
|
257
|
-
if (this.#M = l, this.#U = !!l, this.#s = new Map, this.#i = Array.from({ length:
|
|
152
|
+
if (this.#M = l, this.#U = !!l, this.#s = new Map, this.#i = Array.from({ length: t }).fill(undefined), this.#t = Array.from({ length: t }).fill(undefined), this.#l = new E(t), this.#u = new E(t), this.#a = 0, this.#h = 0, this.#y = R.create(t), this.#n = 0, this.#b = 0, typeof o == "function" && (this.#w = o), typeof p == "function" && (this.#O = p), typeof m == "function" ? (this.#S = m, this.#r = []) : (this.#S = undefined, this.#r = undefined), this.#T = !!this.#w, this.#x = !!this.#O, this.#f = !!this.#S, this.noDisposeOnSet = !!_, this.noUpdateTTL = !!c, this.noDeleteOnFetchRejection = !!F, this.allowStaleOnFetchRejection = !!g, this.allowStaleOnFetchAbort = !!A, this.ignoreFetchAbort = !!z, this.maxEntrySize !== 0) {
|
|
258
153
|
if (this.#c !== 0 && !T(this.#c))
|
|
259
154
|
throw new TypeError("maxSize must be a positive integer if specified");
|
|
260
155
|
if (!T(this.maxEntrySize))
|
|
@@ -270,20 +165,20 @@ var init_index_min = __esm(() => {
|
|
|
270
165
|
throw new TypeError("At least one of max, maxSize, or ttl is required");
|
|
271
166
|
if (!this.ttlAutopurge && !this.#o && !this.#c) {
|
|
272
167
|
let v = "LRU_CACHE_UNBOUNDED";
|
|
273
|
-
H(v) && (I.add(v), P("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.", "UnboundedCacheWarning", v,
|
|
168
|
+
H(v) && (I.add(v), P("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.", "UnboundedCacheWarning", v, u));
|
|
274
169
|
}
|
|
275
170
|
}
|
|
276
171
|
getRemainingTTL(e) {
|
|
277
172
|
return this.#s.has(e) ? 1 / 0 : 0;
|
|
278
173
|
}
|
|
279
174
|
#H() {
|
|
280
|
-
let e = new O(this.#o),
|
|
281
|
-
this.#d = e, this.#F =
|
|
175
|
+
let e = new O(this.#o), t = new O(this.#o);
|
|
176
|
+
this.#d = e, this.#F = t;
|
|
282
177
|
let i = this.ttlAutopurge ? Array.from({ length: this.#o }) : undefined;
|
|
283
178
|
this.#g = i, this.#N = (h, a, o = this.#m.now()) => {
|
|
284
|
-
|
|
179
|
+
t[h] = a !== 0 ? o : 0, e[h] = a, s(h, a);
|
|
285
180
|
}, this.#D = (h) => {
|
|
286
|
-
|
|
181
|
+
t[h] = e[h] !== 0 ? this.#m.now() : 0, s(h, e[h]);
|
|
287
182
|
};
|
|
288
183
|
let s = this.ttlAutopurge ? (h, a) => {
|
|
289
184
|
if (i?.[h] && (clearTimeout(i[h]), i[h] = undefined), a && a !== 0 && i) {
|
|
@@ -295,7 +190,7 @@ var init_index_min = __esm(() => {
|
|
|
295
190
|
} : () => {};
|
|
296
191
|
this.#v = (h, a) => {
|
|
297
192
|
if (e[a]) {
|
|
298
|
-
let o = e[a], p =
|
|
193
|
+
let o = e[a], p = t[a];
|
|
299
194
|
if (!o || !p)
|
|
300
195
|
return;
|
|
301
196
|
h.ttl = o, h.start = p, h.now = n || r();
|
|
@@ -316,13 +211,13 @@ var init_index_min = __esm(() => {
|
|
|
316
211
|
let a = this.#s.get(h);
|
|
317
212
|
if (a === undefined)
|
|
318
213
|
return 0;
|
|
319
|
-
let o = e[a], p =
|
|
214
|
+
let o = e[a], p = t[a];
|
|
320
215
|
if (!o || !p)
|
|
321
216
|
return 1 / 0;
|
|
322
217
|
let m = (n || r()) - p;
|
|
323
218
|
return o - m;
|
|
324
219
|
}, this.#p = (h) => {
|
|
325
|
-
let a =
|
|
220
|
+
let a = t[h], o = e[h];
|
|
326
221
|
return !!o && !!a && (n || r()) - a > o;
|
|
327
222
|
};
|
|
328
223
|
}
|
|
@@ -332,45 +227,45 @@ var init_index_min = __esm(() => {
|
|
|
332
227
|
#p = () => false;
|
|
333
228
|
#X() {
|
|
334
229
|
let e = new O(this.#o);
|
|
335
|
-
this.#b = 0, this.#_ = e, this.#R = (
|
|
336
|
-
this.#b -= e[
|
|
337
|
-
}, this.#V = (
|
|
230
|
+
this.#b = 0, this.#_ = e, this.#R = (t) => {
|
|
231
|
+
this.#b -= e[t], e[t] = 0;
|
|
232
|
+
}, this.#V = (t, i, s, n) => {
|
|
338
233
|
if (this.#e(i))
|
|
339
234
|
return 0;
|
|
340
235
|
if (!T(s))
|
|
341
236
|
if (n) {
|
|
342
237
|
if (typeof n != "function")
|
|
343
238
|
throw new TypeError("sizeCalculation must be a function");
|
|
344
|
-
if (s = n(i,
|
|
239
|
+
if (s = n(i, t), !T(s))
|
|
345
240
|
throw new TypeError("sizeCalculation return invalid (expect positive integer)");
|
|
346
241
|
} else
|
|
347
242
|
throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");
|
|
348
243
|
return s;
|
|
349
|
-
}, this.#j = (
|
|
350
|
-
if (e[
|
|
351
|
-
let n = this.#c - e[
|
|
244
|
+
}, this.#j = (t, i, s) => {
|
|
245
|
+
if (e[t] = i, this.#c) {
|
|
246
|
+
let n = this.#c - e[t];
|
|
352
247
|
for (;this.#b > n; )
|
|
353
248
|
this.#G(true);
|
|
354
249
|
}
|
|
355
|
-
this.#b += e[
|
|
250
|
+
this.#b += e[t], s && (s.entrySize = i, s.totalCalculatedSize = this.#b);
|
|
356
251
|
};
|
|
357
252
|
}
|
|
358
253
|
#R = (e) => {};
|
|
359
|
-
#j = (e,
|
|
360
|
-
#V = (e,
|
|
254
|
+
#j = (e, t, i) => {};
|
|
255
|
+
#V = (e, t, i, s) => {
|
|
361
256
|
if (i || s)
|
|
362
257
|
throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");
|
|
363
258
|
return 0;
|
|
364
259
|
};
|
|
365
260
|
*#A({ allowStale: e = this.allowStale } = {}) {
|
|
366
261
|
if (this.#n)
|
|
367
|
-
for (let
|
|
368
|
-
|
|
262
|
+
for (let t = this.#h;this.#B(t) && ((e || !this.#p(t)) && (yield t), t !== this.#a); )
|
|
263
|
+
t = this.#u[t];
|
|
369
264
|
}
|
|
370
265
|
*#z({ allowStale: e = this.allowStale } = {}) {
|
|
371
266
|
if (this.#n)
|
|
372
|
-
for (let
|
|
373
|
-
|
|
267
|
+
for (let t = this.#a;this.#B(t) && ((e || !this.#p(t)) && (yield t), t !== this.#h); )
|
|
268
|
+
t = this.#l[t];
|
|
374
269
|
}
|
|
375
270
|
#B(e) {
|
|
376
271
|
return e !== undefined && this.#s.get(this.#i[e]) === e;
|
|
@@ -385,14 +280,14 @@ var init_index_min = __esm(() => {
|
|
|
385
280
|
}
|
|
386
281
|
*keys() {
|
|
387
282
|
for (let e of this.#A()) {
|
|
388
|
-
let
|
|
389
|
-
|
|
283
|
+
let t = this.#i[e];
|
|
284
|
+
t !== undefined && !this.#e(this.#t[e]) && (yield t);
|
|
390
285
|
}
|
|
391
286
|
}
|
|
392
287
|
*rkeys() {
|
|
393
288
|
for (let e of this.#z()) {
|
|
394
|
-
let
|
|
395
|
-
|
|
289
|
+
let t = this.#i[e];
|
|
290
|
+
t !== undefined && !this.#e(this.#t[e]) && (yield t);
|
|
396
291
|
}
|
|
397
292
|
}
|
|
398
293
|
*values() {
|
|
@@ -407,109 +302,109 @@ var init_index_min = __esm(() => {
|
|
|
407
302
|
return this.entries();
|
|
408
303
|
}
|
|
409
304
|
[Symbol.toStringTag] = "LRUCache";
|
|
410
|
-
find(e,
|
|
305
|
+
find(e, t = {}) {
|
|
411
306
|
for (let i of this.#A()) {
|
|
412
307
|
let s = this.#t[i], n = this.#e(s) ? s.__staleWhileFetching : s;
|
|
413
308
|
if (n !== undefined && e(n, this.#i[i], this))
|
|
414
|
-
return this.#C(this.#i[i],
|
|
309
|
+
return this.#C(this.#i[i], t);
|
|
415
310
|
}
|
|
416
311
|
}
|
|
417
|
-
forEach(e,
|
|
312
|
+
forEach(e, t = this) {
|
|
418
313
|
for (let i of this.#A()) {
|
|
419
314
|
let s = this.#t[i], n = this.#e(s) ? s.__staleWhileFetching : s;
|
|
420
|
-
n !== undefined && e.call(
|
|
315
|
+
n !== undefined && e.call(t, n, this.#i[i], this);
|
|
421
316
|
}
|
|
422
317
|
}
|
|
423
|
-
rforEach(e,
|
|
318
|
+
rforEach(e, t = this) {
|
|
424
319
|
for (let i of this.#z()) {
|
|
425
320
|
let s = this.#t[i], n = this.#e(s) ? s.__staleWhileFetching : s;
|
|
426
|
-
n !== undefined && e.call(
|
|
321
|
+
n !== undefined && e.call(t, n, this.#i[i], this);
|
|
427
322
|
}
|
|
428
323
|
}
|
|
429
324
|
purgeStale() {
|
|
430
325
|
let e = false;
|
|
431
|
-
for (let
|
|
432
|
-
this.#p(
|
|
326
|
+
for (let t of this.#z({ allowStale: true }))
|
|
327
|
+
this.#p(t) && (this.#E(this.#i[t], "expire"), e = true);
|
|
433
328
|
return e;
|
|
434
329
|
}
|
|
435
330
|
info(e) {
|
|
436
|
-
let
|
|
437
|
-
if (
|
|
331
|
+
let t = this.#s.get(e);
|
|
332
|
+
if (t === undefined)
|
|
438
333
|
return;
|
|
439
|
-
let i = this.#t[
|
|
334
|
+
let i = this.#t[t], s = this.#e(i) ? i.__staleWhileFetching : i;
|
|
440
335
|
if (s === undefined)
|
|
441
336
|
return;
|
|
442
337
|
let n = { value: s };
|
|
443
338
|
if (this.#d && this.#F) {
|
|
444
|
-
let r = this.#d[
|
|
339
|
+
let r = this.#d[t], h = this.#F[t];
|
|
445
340
|
if (r && h) {
|
|
446
341
|
let a = r - (this.#m.now() - h);
|
|
447
342
|
n.ttl = a, n.start = Date.now();
|
|
448
343
|
}
|
|
449
344
|
}
|
|
450
|
-
return this.#_ && (n.size = this.#_[
|
|
345
|
+
return this.#_ && (n.size = this.#_[t]), n;
|
|
451
346
|
}
|
|
452
347
|
dump() {
|
|
453
348
|
let e = [];
|
|
454
|
-
for (let
|
|
455
|
-
let i = this.#i[
|
|
349
|
+
for (let t of this.#A({ allowStale: true })) {
|
|
350
|
+
let i = this.#i[t], s = this.#t[t], n = this.#e(s) ? s.__staleWhileFetching : s;
|
|
456
351
|
if (n === undefined || i === undefined)
|
|
457
352
|
continue;
|
|
458
353
|
let r = { value: n };
|
|
459
354
|
if (this.#d && this.#F) {
|
|
460
|
-
r.ttl = this.#d[
|
|
461
|
-
let h = this.#m.now() - this.#F[
|
|
355
|
+
r.ttl = this.#d[t];
|
|
356
|
+
let h = this.#m.now() - this.#F[t];
|
|
462
357
|
r.start = Math.floor(Date.now() - h);
|
|
463
358
|
}
|
|
464
|
-
this.#_ && (r.size = this.#_[
|
|
359
|
+
this.#_ && (r.size = this.#_[t]), e.unshift([i, r]);
|
|
465
360
|
}
|
|
466
361
|
return e;
|
|
467
362
|
}
|
|
468
363
|
load(e) {
|
|
469
364
|
this.clear();
|
|
470
|
-
for (let [
|
|
365
|
+
for (let [t, i] of e) {
|
|
471
366
|
if (i.start) {
|
|
472
367
|
let s = Date.now() - i.start;
|
|
473
368
|
i.start = this.#m.now() - s;
|
|
474
369
|
}
|
|
475
|
-
this.#W(
|
|
370
|
+
this.#W(t, i.value, i);
|
|
476
371
|
}
|
|
477
372
|
}
|
|
478
|
-
set(e,
|
|
373
|
+
set(e, t, i = {}) {
|
|
479
374
|
let { status: s = w.hasSubscribers ? {} : undefined } = i;
|
|
480
|
-
i.status = s, s && (s.op = "set", s.key = e,
|
|
481
|
-
let n = this.#W(e,
|
|
375
|
+
i.status = s, s && (s.op = "set", s.key = e, t !== undefined && (s.value = t), s.cache = this);
|
|
376
|
+
let n = this.#W(e, t, i);
|
|
482
377
|
return s && w.hasSubscribers && w.publish(s), n;
|
|
483
378
|
}
|
|
484
|
-
#W(e,
|
|
379
|
+
#W(e, t, i, s) {
|
|
485
380
|
let { ttl: n = this.ttl, start: r, noDisposeOnSet: h = this.noDisposeOnSet, sizeCalculation: a = this.sizeCalculation, status: o } = i;
|
|
486
|
-
if (
|
|
381
|
+
if (t === undefined)
|
|
487
382
|
return o && (o.set = "deleted"), this.delete(e), this;
|
|
488
|
-
let { noUpdateTTL: p = this.noUpdateTTL } = i, m = this.#e(
|
|
489
|
-
o && !m && (o.value =
|
|
490
|
-
let _ = this.#V(e,
|
|
383
|
+
let { noUpdateTTL: p = this.noUpdateTTL } = i, m = this.#e(t);
|
|
384
|
+
o && !m && (o.value = t);
|
|
385
|
+
let _ = this.#V(e, t, i.size || 0, a, o);
|
|
491
386
|
if (this.maxEntrySize && _ > this.maxEntrySize)
|
|
492
387
|
return this.#E(e, "set"), o && (o.set = "miss", o.maxEntrySizeExceeded = true), this;
|
|
493
388
|
let c = this.#n === 0 ? undefined : this.#s.get(e);
|
|
494
389
|
if (c === undefined)
|
|
495
|
-
c = this.#n === 0 ? this.#h : this.#y.length !== 0 ? this.#y.pop() : this.#n === this.#o ? this.#G(false) : this.#n, this.#i[c] = e, this.#t[c] =
|
|
390
|
+
c = this.#n === 0 ? this.#h : this.#y.length !== 0 ? this.#y.pop() : this.#n === this.#o ? this.#G(false) : this.#n, this.#i[c] = e, this.#t[c] = t, this.#s.set(e, c), this.#l[this.#h] = c, this.#u[c] = this.#h, this.#h = c, this.#n++, this.#j(c, _, o), o && (o.set = "add"), p = false, this.#x && !m && this.#O?.(t, e, "add");
|
|
496
391
|
else {
|
|
497
392
|
this.#L(c);
|
|
498
393
|
let d = this.#t[c];
|
|
499
|
-
if (
|
|
394
|
+
if (t !== d) {
|
|
500
395
|
if (!h)
|
|
501
396
|
if (this.#e(d)) {
|
|
502
397
|
d !== s && d.__abortController.abort(new Error("replaced"));
|
|
503
398
|
let { __staleWhileFetching: f } = d;
|
|
504
|
-
f !== undefined && f !==
|
|
399
|
+
f !== undefined && f !== t && (this.#T && this.#w?.(f, e, "set"), this.#f && this.#r?.push([f, e, "set"]));
|
|
505
400
|
} else
|
|
506
401
|
this.#T && this.#w?.(d, e, "set"), this.#f && this.#r?.push([d, e, "set"]);
|
|
507
|
-
if (this.#R(c), this.#j(c, _, o), this.#t[c] =
|
|
508
|
-
let f = d && this.#e(d) ? d.__staleWhileFetching : d, y = f === undefined ? "add" :
|
|
509
|
-
o && (o.set = y, f !== undefined && (o.oldValue = f)), this.#x && this.onInsert?.(
|
|
402
|
+
if (this.#R(c), this.#j(c, _, o), this.#t[c] = t, !m) {
|
|
403
|
+
let f = d && this.#e(d) ? d.__staleWhileFetching : d, y = f === undefined ? "add" : t !== f ? "replace" : "update";
|
|
404
|
+
o && (o.set = y, f !== undefined && (o.oldValue = f)), this.#x && this.onInsert?.(t, e, y);
|
|
510
405
|
}
|
|
511
406
|
} else
|
|
512
|
-
m || (o && (o.set = "update"), this.#x && this.onInsert?.(
|
|
407
|
+
m || (o && (o.set = "update"), this.#x && this.onInsert?.(t, e, "update"));
|
|
513
408
|
}
|
|
514
409
|
if (n !== 0 && !this.#d && this.#H(), this.#d && (p || this.#N(c, n, r), o && this.#v(o, c)), !h && this.#f && this.#r) {
|
|
515
410
|
let d = this.#r, f;
|
|
@@ -530,26 +425,26 @@ var init_index_min = __esm(() => {
|
|
|
530
425
|
}
|
|
531
426
|
} finally {
|
|
532
427
|
if (this.#f && this.#r) {
|
|
533
|
-
let e = this.#r,
|
|
534
|
-
for (;
|
|
535
|
-
this.#S?.(...
|
|
428
|
+
let e = this.#r, t;
|
|
429
|
+
for (;t = e?.shift(); )
|
|
430
|
+
this.#S?.(...t);
|
|
536
431
|
}
|
|
537
432
|
}
|
|
538
433
|
}
|
|
539
434
|
#G(e) {
|
|
540
|
-
let
|
|
435
|
+
let t = this.#a, i = this.#i[t], s = this.#t[t], n = this.#e(s);
|
|
541
436
|
n && s.__abortController.abort(new Error("evicted"));
|
|
542
437
|
let r = n ? s.__staleWhileFetching : s;
|
|
543
|
-
return (this.#T || this.#f) && r !== undefined && (this.#T && this.#w?.(r, i, "evict"), this.#f && this.#r?.push([r, i, "evict"])), this.#R(
|
|
438
|
+
return (this.#T || this.#f) && r !== undefined && (this.#T && this.#w?.(r, i, "evict"), this.#f && this.#r?.push([r, i, "evict"])), this.#R(t), this.#g?.[t] && (clearTimeout(this.#g[t]), this.#g[t] = undefined), e && (this.#i[t] = undefined, this.#t[t] = undefined, this.#y.push(t)), this.#n === 1 ? (this.#a = this.#h = 0, this.#y.length = 0) : this.#a = this.#l[t], this.#s.delete(i), this.#n--, t;
|
|
544
439
|
}
|
|
545
|
-
has(e,
|
|
546
|
-
let { status: i = w.hasSubscribers ? {} : undefined } =
|
|
547
|
-
|
|
548
|
-
let s = this.#Y(e,
|
|
440
|
+
has(e, t = {}) {
|
|
441
|
+
let { status: i = w.hasSubscribers ? {} : undefined } = t;
|
|
442
|
+
t.status = i, i && (i.op = "has", i.key = e, i.cache = this);
|
|
443
|
+
let s = this.#Y(e, t);
|
|
549
444
|
return w.hasSubscribers && w.publish(i), s;
|
|
550
445
|
}
|
|
551
|
-
#Y(e,
|
|
552
|
-
let { updateAgeOnHas: i = this.updateAgeOnHas, status: s } =
|
|
446
|
+
#Y(e, t = {}) {
|
|
447
|
+
let { updateAgeOnHas: i = this.updateAgeOnHas, status: s } = t, n = this.#s.get(e);
|
|
553
448
|
if (n !== undefined) {
|
|
554
449
|
let r = this.#t[n];
|
|
555
450
|
if (this.#e(r) && r.__staleWhileFetching === undefined)
|
|
@@ -562,14 +457,14 @@ var init_index_min = __esm(() => {
|
|
|
562
457
|
s && (s.has = "miss");
|
|
563
458
|
return false;
|
|
564
459
|
}
|
|
565
|
-
peek(e,
|
|
566
|
-
let { status: i = D() ? {} : undefined } =
|
|
567
|
-
i && (i.op = "peek", i.key = e, i.cache = this),
|
|
568
|
-
let s = this.#J(e,
|
|
460
|
+
peek(e, t = {}) {
|
|
461
|
+
let { status: i = D() ? {} : undefined } = t;
|
|
462
|
+
i && (i.op = "peek", i.key = e, i.cache = this), t.status = i;
|
|
463
|
+
let s = this.#J(e, t);
|
|
569
464
|
return w.hasSubscribers && w.publish(i), s;
|
|
570
465
|
}
|
|
571
|
-
#J(e,
|
|
572
|
-
let { status: i, allowStale: s = this.allowStale } =
|
|
466
|
+
#J(e, t) {
|
|
467
|
+
let { status: i, allowStale: s = this.allowStale } = t, n = this.#s.get(e);
|
|
573
468
|
if (n === undefined || !s && this.#p(n)) {
|
|
574
469
|
i && (i.peek = n === undefined ? "miss" : "stale");
|
|
575
470
|
return;
|
|
@@ -577,8 +472,8 @@ var init_index_min = __esm(() => {
|
|
|
577
472
|
let r = this.#t[n], h = this.#e(r) ? r.__staleWhileFetching : r;
|
|
578
473
|
return i && (h !== undefined ? (i.peek = "hit", i.value = h) : i.peek = "miss"), h;
|
|
579
474
|
}
|
|
580
|
-
#P(e,
|
|
581
|
-
let n =
|
|
475
|
+
#P(e, t, i, s) {
|
|
476
|
+
let n = t === undefined ? undefined : this.#t[t];
|
|
582
477
|
if (this.#e(n))
|
|
583
478
|
return n;
|
|
584
479
|
let r = new AbortController, { signal: h } = i;
|
|
@@ -587,11 +482,11 @@ var init_index_min = __esm(() => {
|
|
|
587
482
|
let { aborted: l } = r.signal, S = i.ignoreFetchAbort && f !== undefined, F = i.ignoreFetchAbort || !!(i.allowStaleOnFetchAbort && f !== undefined);
|
|
588
483
|
if (i.status && (l && !y ? (i.status.fetchAborted = true, i.status.fetchError = r.signal.reason, S && (i.status.fetchAbortIgnored = true)) : i.status.fetchResolved = true), l && !S && !y)
|
|
589
484
|
return m(r.signal.reason, F);
|
|
590
|
-
let b = c, g = this.#t[
|
|
591
|
-
return (g === c || g === undefined && S && y) && (f === undefined ? b.__staleWhileFetching !== undefined ? this.#t[
|
|
485
|
+
let b = c, g = this.#t[t];
|
|
486
|
+
return (g === c || g === undefined && S && y) && (f === undefined ? b.__staleWhileFetching !== undefined ? this.#t[t] = b.__staleWhileFetching : this.#E(e, "fetch") : (i.status && (i.status.fetchUpdated = true), this.#W(e, f, a.options, b))), f;
|
|
592
487
|
}, p = (f) => (i.status && (i.status.fetchRejected = true, i.status.fetchError = f), m(f, false)), m = (f, y) => {
|
|
593
488
|
let { aborted: l } = r.signal, S = l && i.allowStaleOnFetchAbort, F = S || i.allowStaleOnFetchRejection, b = F || i.noDeleteOnFetchRejection, g = c;
|
|
594
|
-
if (this.#t[
|
|
489
|
+
if (this.#t[t] === c && (!b || !y && g.__staleWhileFetching === undefined ? this.#E(e, "fetch") : S || (this.#t[t] = g.__staleWhileFetching)), F)
|
|
595
490
|
return i.status && g.__staleWhileFetching !== undefined && (i.status.returnedStale = true), g.__staleWhileFetching;
|
|
596
491
|
if (g.__returned === g)
|
|
597
492
|
throw f;
|
|
@@ -603,22 +498,22 @@ var init_index_min = __esm(() => {
|
|
|
603
498
|
};
|
|
604
499
|
i.status && (i.status.fetchDispatched = true);
|
|
605
500
|
let c = new Promise(_).then(o, p), d = Object.assign(c, { __abortController: r, __staleWhileFetching: n, __returned: undefined });
|
|
606
|
-
return
|
|
501
|
+
return t === undefined ? (this.#W(e, d, { ...a.options, status: undefined }), t = this.#s.get(e)) : this.#t[t] = d, d;
|
|
607
502
|
}
|
|
608
503
|
#e(e) {
|
|
609
504
|
if (!this.#U)
|
|
610
505
|
return false;
|
|
611
|
-
let
|
|
612
|
-
return !!
|
|
506
|
+
let t = e;
|
|
507
|
+
return !!t && t instanceof Promise && t.hasOwnProperty("__staleWhileFetching") && t.__abortController instanceof AbortController;
|
|
613
508
|
}
|
|
614
|
-
fetch(e,
|
|
615
|
-
let i = W.hasSubscribers, { status: s = D() ? {} : undefined } =
|
|
616
|
-
|
|
617
|
-
let n = this.#k(e,
|
|
509
|
+
fetch(e, t = {}) {
|
|
510
|
+
let i = W.hasSubscribers, { status: s = D() ? {} : undefined } = t;
|
|
511
|
+
t.status = s, s && t.context && (s.context = t.context);
|
|
512
|
+
let n = this.#k(e, t);
|
|
618
513
|
return s && i && (s.trace = true, W.tracePromise(() => n, s).catch(() => {})), n;
|
|
619
514
|
}
|
|
620
|
-
async#k(e,
|
|
621
|
-
let { allowStale: i = this.allowStale, updateAgeOnGet: s = this.updateAgeOnGet, noDeleteOnStaleGet: n = this.noDeleteOnStaleGet, ttl: r = this.ttl, noDisposeOnSet: h = this.noDisposeOnSet, size: a = 0, sizeCalculation: o = this.sizeCalculation, noUpdateTTL: p = this.noUpdateTTL, noDeleteOnFetchRejection: m = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection: _ = this.allowStaleOnFetchRejection, ignoreFetchAbort: c = this.ignoreFetchAbort, allowStaleOnFetchAbort: d = this.allowStaleOnFetchAbort, context: f, forceRefresh: y = false, status: l, signal: S } =
|
|
515
|
+
async#k(e, t = {}) {
|
|
516
|
+
let { allowStale: i = this.allowStale, updateAgeOnGet: s = this.updateAgeOnGet, noDeleteOnStaleGet: n = this.noDeleteOnStaleGet, ttl: r = this.ttl, noDisposeOnSet: h = this.noDisposeOnSet, size: a = 0, sizeCalculation: o = this.sizeCalculation, noUpdateTTL: p = this.noUpdateTTL, noDeleteOnFetchRejection: m = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection: _ = this.allowStaleOnFetchRejection, ignoreFetchAbort: c = this.ignoreFetchAbort, allowStaleOnFetchAbort: d = this.allowStaleOnFetchAbort, context: f, forceRefresh: y = false, status: l, signal: S } = t;
|
|
622
517
|
if (l && (l.op = "fetch", l.key = e, y && (l.forceRefresh = true), l.cache = this), !this.#U)
|
|
623
518
|
return l && (l.fetch = "get"), this.#C(e, { allowStale: i, updateAgeOnGet: s, noDeleteOnStaleGet: n, status: l });
|
|
624
519
|
let F = { allowStale: i, updateAgeOnGet: s, noDeleteOnStaleGet: n, ttl: r, noDisposeOnSet: h, size: a, sizeCalculation: o, noUpdateTTL: p, noDeleteOnFetchRejection: m, allowStaleOnFetchRejection: _, allowStaleOnFetchAbort: d, ignoreFetchAbort: c, status: l, signal: S }, b = this.#s.get(e);
|
|
@@ -639,29 +534,29 @@ var init_index_min = __esm(() => {
|
|
|
639
534
|
return l && (l.fetch = A ? "stale" : "refresh", E && A && (l.returnedStale = true)), E ? z.__staleWhileFetching : z.__returned = z;
|
|
640
535
|
}
|
|
641
536
|
}
|
|
642
|
-
forceFetch(e,
|
|
643
|
-
let i = W.hasSubscribers, { status: s = D() ? {} : undefined } =
|
|
644
|
-
|
|
645
|
-
let n = this.#K(e,
|
|
537
|
+
forceFetch(e, t = {}) {
|
|
538
|
+
let i = W.hasSubscribers, { status: s = D() ? {} : undefined } = t;
|
|
539
|
+
t.status = s, s && t.context && (s.context = t.context);
|
|
540
|
+
let n = this.#K(e, t);
|
|
646
541
|
return s && i && (s.trace = true, W.tracePromise(() => n, s).catch(() => {})), n;
|
|
647
542
|
}
|
|
648
|
-
async#K(e,
|
|
649
|
-
let i = await this.#k(e,
|
|
543
|
+
async#K(e, t = {}) {
|
|
544
|
+
let i = await this.#k(e, t);
|
|
650
545
|
if (i === undefined)
|
|
651
546
|
throw new Error("fetch() returned undefined");
|
|
652
547
|
return i;
|
|
653
548
|
}
|
|
654
|
-
memo(e,
|
|
655
|
-
let { status: i = w.hasSubscribers ? {} : undefined } =
|
|
656
|
-
|
|
657
|
-
let s = this.#Q(e,
|
|
549
|
+
memo(e, t = {}) {
|
|
550
|
+
let { status: i = w.hasSubscribers ? {} : undefined } = t;
|
|
551
|
+
t.status = i, i && (i.op = "memo", i.key = e, t.context && (i.context = t.context), i.cache = this);
|
|
552
|
+
let s = this.#Q(e, t);
|
|
658
553
|
return i && (i.value = s), w.hasSubscribers && w.publish(i), s;
|
|
659
554
|
}
|
|
660
|
-
#Q(e,
|
|
555
|
+
#Q(e, t = {}) {
|
|
661
556
|
let i = this.#I;
|
|
662
557
|
if (!i)
|
|
663
558
|
throw new Error("no memoMethod provided to constructor");
|
|
664
|
-
let { context: s, status: n, forceRefresh: r, ...h } =
|
|
559
|
+
let { context: s, status: n, forceRefresh: r, ...h } = t;
|
|
665
560
|
n && r && (n.forceRefresh = true);
|
|
666
561
|
let a = this.#C(e, h), o = r || a === undefined;
|
|
667
562
|
if (n && (n.memo = o ? "miss" : "hit", o || (n.value = a)), !o)
|
|
@@ -669,14 +564,14 @@ var init_index_min = __esm(() => {
|
|
|
669
564
|
let p = i(e, a, { options: h, context: s });
|
|
670
565
|
return n && (n.value = p), this.#W(e, p, h), p;
|
|
671
566
|
}
|
|
672
|
-
get(e,
|
|
673
|
-
let { status: i = w.hasSubscribers ? {} : undefined } =
|
|
674
|
-
|
|
675
|
-
let s = this.#C(e,
|
|
567
|
+
get(e, t = {}) {
|
|
568
|
+
let { status: i = w.hasSubscribers ? {} : undefined } = t;
|
|
569
|
+
t.status = i, i && (i.op = "get", i.key = e, i.cache = this);
|
|
570
|
+
let s = this.#C(e, t);
|
|
676
571
|
return i && (s !== undefined && (i.value = s), w.hasSubscribers && w.publish(i)), s;
|
|
677
572
|
}
|
|
678
|
-
#C(e,
|
|
679
|
-
let { allowStale: i = this.allowStale, updateAgeOnGet: s = this.updateAgeOnGet, noDeleteOnStaleGet: n = this.noDeleteOnStaleGet, status: r } =
|
|
573
|
+
#C(e, t = {}) {
|
|
574
|
+
let { allowStale: i = this.allowStale, updateAgeOnGet: s = this.updateAgeOnGet, noDeleteOnStaleGet: n = this.noDeleteOnStaleGet, status: r } = t, h = this.#s.get(e);
|
|
680
575
|
if (h === undefined) {
|
|
681
576
|
r && (r.get = "miss");
|
|
682
577
|
return;
|
|
@@ -684,8 +579,8 @@ var init_index_min = __esm(() => {
|
|
|
684
579
|
let a = this.#t[h], o = this.#e(a);
|
|
685
580
|
return r && this.#v(r, h), this.#p(h) ? o ? (r && (r.get = "stale-fetching"), i && a.__staleWhileFetching !== undefined ? (r && (r.returnedStale = true), a.__staleWhileFetching) : undefined) : (n || this.#E(e, "expire"), r && (r.get = "stale"), i ? (r && (r.returnedStale = true), a) : undefined) : (r && (r.get = o ? "fetching" : "hit"), this.#L(h), s && this.#D(h), o ? a.__staleWhileFetching : a);
|
|
686
581
|
}
|
|
687
|
-
#$(e,
|
|
688
|
-
this.#u[
|
|
582
|
+
#$(e, t) {
|
|
583
|
+
this.#u[t] = e, this.#l[e] = t;
|
|
689
584
|
}
|
|
690
585
|
#L(e) {
|
|
691
586
|
e !== this.#h && (e === this.#a ? this.#a = this.#l[e] : this.#$(this.#u[e], this.#l[e]), this.#$(this.#h, e), this.#h = e);
|
|
@@ -693,18 +588,18 @@ var init_index_min = __esm(() => {
|
|
|
693
588
|
delete(e) {
|
|
694
589
|
return this.#E(e, "delete");
|
|
695
590
|
}
|
|
696
|
-
#E(e,
|
|
697
|
-
w.hasSubscribers && w.publish({ op: "delete", delete:
|
|
591
|
+
#E(e, t) {
|
|
592
|
+
w.hasSubscribers && w.publish({ op: "delete", delete: t, key: e, cache: this });
|
|
698
593
|
let i = false;
|
|
699
594
|
if (this.#n !== 0) {
|
|
700
595
|
let s = this.#s.get(e);
|
|
701
596
|
if (s !== undefined)
|
|
702
597
|
if (this.#g?.[s] && (clearTimeout(this.#g?.[s]), this.#g[s] = undefined), i = true, this.#n === 1)
|
|
703
|
-
this.#q(
|
|
598
|
+
this.#q(t);
|
|
704
599
|
else {
|
|
705
600
|
this.#R(s);
|
|
706
601
|
let n = this.#t[s];
|
|
707
|
-
if (this.#e(n) ? n.__abortController.abort(new Error("deleted")) : (this.#T || this.#f) && (this.#T && this.#w?.(n, e,
|
|
602
|
+
if (this.#e(n) ? n.__abortController.abort(new Error("deleted")) : (this.#T || this.#f) && (this.#T && this.#w?.(n, e, t), this.#f && this.#r?.push([n, e, t])), this.#s.delete(e), this.#i[s] = undefined, this.#t[s] = undefined, s === this.#h)
|
|
708
603
|
this.#h = this.#u[s];
|
|
709
604
|
else if (s === this.#a)
|
|
710
605
|
this.#a = this.#l[s];
|
|
@@ -728,24 +623,24 @@ var init_index_min = __esm(() => {
|
|
|
728
623
|
return this.#q("delete");
|
|
729
624
|
}
|
|
730
625
|
#q(e) {
|
|
731
|
-
for (let
|
|
732
|
-
let i = this.#t[
|
|
626
|
+
for (let t of this.#z({ allowStale: true })) {
|
|
627
|
+
let i = this.#t[t];
|
|
733
628
|
if (this.#e(i))
|
|
734
629
|
i.__abortController.abort(new Error("deleted"));
|
|
735
630
|
else {
|
|
736
|
-
let s = this.#i[
|
|
631
|
+
let s = this.#i[t];
|
|
737
632
|
this.#T && this.#w?.(i, s, e), this.#f && this.#r?.push([i, s, e]);
|
|
738
633
|
}
|
|
739
634
|
}
|
|
740
635
|
if (this.#s.clear(), this.#t.fill(undefined), this.#i.fill(undefined), this.#d && this.#F) {
|
|
741
636
|
this.#d.fill(0), this.#F.fill(0);
|
|
742
|
-
for (let
|
|
743
|
-
|
|
637
|
+
for (let t of this.#g ?? [])
|
|
638
|
+
t !== undefined && clearTimeout(t);
|
|
744
639
|
this.#g?.fill(undefined);
|
|
745
640
|
}
|
|
746
641
|
if (this.#_ && this.#_.fill(0), this.#a = 0, this.#h = 0, this.#y.length = 0, this.#b = 0, this.#n = 0, this.#f && this.#r) {
|
|
747
|
-
let
|
|
748
|
-
for (;i =
|
|
642
|
+
let t = this.#r, i;
|
|
643
|
+
for (;i = t?.shift(); )
|
|
749
644
|
this.#S?.(...i);
|
|
750
645
|
}
|
|
751
646
|
}
|
|
@@ -976,10 +871,6 @@ var init_schema_index = __esm(() => {
|
|
|
976
871
|
});
|
|
977
872
|
|
|
978
873
|
// src/core/schema-loader.ts
|
|
979
|
-
var exports_schema_loader = {};
|
|
980
|
-
__export(exports_schema_loader, {
|
|
981
|
-
SchemaLayeredLoader: () => SchemaLayeredLoader
|
|
982
|
-
});
|
|
983
874
|
import { join as join4 } from "path";
|
|
984
875
|
|
|
985
876
|
class SchemaLayeredLoader {
|
|
@@ -1352,267 +1243,6 @@ var ENGINE_CAPABILITIES = Object.freeze({
|
|
|
1352
1243
|
shell: cap("limited", "interactive", "Dedicated Kibana Dev Tools-style REPL (method/path + JSON body, blank-line submit); read-focused.")
|
|
1353
1244
|
})
|
|
1354
1245
|
});
|
|
1355
|
-
// src/adapters/error-mapper.ts
|
|
1356
|
-
var TRANSPORT_CODES = {
|
|
1357
|
-
ECONNREFUSED: "ECONNREFUSED",
|
|
1358
|
-
ETIMEDOUT: "ETIMEDOUT",
|
|
1359
|
-
ESOCKETTIMEDOUT: "ETIMEDOUT",
|
|
1360
|
-
ENOTFOUND: "ENOTFOUND",
|
|
1361
|
-
EAI_AGAIN: "ENOTFOUND",
|
|
1362
|
-
PROTOCOL_CONNECTION_LOST: "CONNECTION_LOST",
|
|
1363
|
-
PROTOCOL_SEQUENCE_TIMEOUT: "ETIMEDOUT",
|
|
1364
|
-
ECONNRESET: "CONNECTION_LOST",
|
|
1365
|
-
EPIPE: "CONNECTION_LOST",
|
|
1366
|
-
ECONNABORTED: "CONNECTION_LOST",
|
|
1367
|
-
EHOSTUNREACH: "EHOSTUNREACH",
|
|
1368
|
-
ENETUNREACH: "EHOSTUNREACH",
|
|
1369
|
-
ENETDOWN: "EHOSTUNREACH"
|
|
1370
|
-
};
|
|
1371
|
-
function isTransportDriverCode(code) {
|
|
1372
|
-
return TLS_CODE_PREFIX.test(code) || TRANSPORT_CODES[code] !== undefined;
|
|
1373
|
-
}
|
|
1374
|
-
var TLS_CODE_PREFIX = /^(CERT_|SELF_SIGNED_|DEPTH_ZERO_|UNABLE_TO_(?:GET|VERIFY)_|ERR_TLS_|ERR_SSL_)/;
|
|
1375
|
-
var MYSQL_CODES = {
|
|
1376
|
-
ER_NO_SUCH_TABLE: "TABLE_NOT_FOUND",
|
|
1377
|
-
ER_BAD_FIELD_ERROR: "COLUMN_NOT_FOUND",
|
|
1378
|
-
ER_PARSE_ERROR: "SQL_SYNTAX_ERROR",
|
|
1379
|
-
ER_ACCESS_DENIED_ERROR: "AUTH_FAILED",
|
|
1380
|
-
ER_DBACCESS_DENIED_ERROR: "AUTH_FAILED",
|
|
1381
|
-
ER_NOT_SUPPORTED_AUTH_MODE: "AUTH_FAILED",
|
|
1382
|
-
ER_MUST_CHANGE_PASSWORD_LOGIN: "AUTH_FAILED",
|
|
1383
|
-
ER_QUERY_TIMEOUT: "STATEMENT_TIMEOUT",
|
|
1384
|
-
ER_STATEMENT_TIMEOUT: "STATEMENT_TIMEOUT",
|
|
1385
|
-
ER_CON_COUNT_ERROR: "TOO_MANY_CONNECTIONS",
|
|
1386
|
-
ER_SERVER_SHUTDOWN: "CONNECTION_LOST"
|
|
1387
|
-
};
|
|
1388
|
-
var MYSQL_ERRNOS = {
|
|
1389
|
-
1045: "AUTH_FAILED",
|
|
1390
|
-
1044: "AUTH_FAILED",
|
|
1391
|
-
1054: "COLUMN_NOT_FOUND",
|
|
1392
|
-
1064: "SQL_SYNTAX_ERROR",
|
|
1393
|
-
1146: "TABLE_NOT_FOUND",
|
|
1394
|
-
1251: "AUTH_FAILED",
|
|
1395
|
-
1698: "AUTH_FAILED",
|
|
1396
|
-
1040: "TOO_MANY_CONNECTIONS",
|
|
1397
|
-
1053: "CONNECTION_LOST",
|
|
1398
|
-
2006: "CONNECTION_LOST",
|
|
1399
|
-
2013: "CONNECTION_LOST",
|
|
1400
|
-
1969: "STATEMENT_TIMEOUT",
|
|
1401
|
-
3024: "STATEMENT_TIMEOUT"
|
|
1402
|
-
};
|
|
1403
|
-
var SQLSTATES = {
|
|
1404
|
-
"28000": "AUTH_FAILED",
|
|
1405
|
-
"28P01": "AUTH_FAILED",
|
|
1406
|
-
"42601": "SQL_SYNTAX_ERROR",
|
|
1407
|
-
"42P01": "TABLE_NOT_FOUND",
|
|
1408
|
-
"42703": "COLUMN_NOT_FOUND",
|
|
1409
|
-
"57014": "STATEMENT_TIMEOUT",
|
|
1410
|
-
"08000": "CONNECTION_LOST",
|
|
1411
|
-
"08003": "CONNECTION_LOST",
|
|
1412
|
-
"08006": "CONNECTION_LOST",
|
|
1413
|
-
"08001": "ECONNREFUSED",
|
|
1414
|
-
"08004": "CONNECTION_REJECTED",
|
|
1415
|
-
"53300": "TOO_MANY_CONNECTIONS",
|
|
1416
|
-
"57P01": "CONNECTION_LOST",
|
|
1417
|
-
"57P02": "CONNECTION_LOST",
|
|
1418
|
-
"57P03": "SERVER_NOT_READY"
|
|
1419
|
-
};
|
|
1420
|
-
var REDIS_PREFIXES = {
|
|
1421
|
-
NOAUTH: "AUTH_FAILED",
|
|
1422
|
-
WRONGPASS: "AUTH_FAILED"
|
|
1423
|
-
};
|
|
1424
|
-
var FALLBACK_PATTERNS = [
|
|
1425
|
-
[/connection refused/i, "ECONNREFUSED"],
|
|
1426
|
-
[/\bECONNREFUSED\b/, "ECONNREFUSED"],
|
|
1427
|
-
[/connect(?:ion)? time(?:d )?out/i, "ETIMEDOUT"],
|
|
1428
|
-
[/timeout exceeded/i, "ETIMEDOUT"],
|
|
1429
|
-
[/timed out/i, "ETIMEDOUT"],
|
|
1430
|
-
[/connection terminated/i, "CONNECTION_LOST"],
|
|
1431
|
-
[/server closed the connection/i, "CONNECTION_LOST"],
|
|
1432
|
-
[/server has gone away/i, "CONNECTION_LOST"],
|
|
1433
|
-
[/lost connection to \S+ server/i, "CONNECTION_LOST"],
|
|
1434
|
-
[/getaddrinfo/i, "ENOTFOUND"],
|
|
1435
|
-
[/authentication failed/i, "AUTH_FAILED"],
|
|
1436
|
-
[/access denied for user/i, "AUTH_FAILED"],
|
|
1437
|
-
[/no pg_hba\.conf entry/i, "AUTH_FAILED"],
|
|
1438
|
-
[/role\s+".*?"\s+does not exist/i, "AUTH_FAILED"],
|
|
1439
|
-
[/password supplied/i, "AUTH_FAILED"]
|
|
1440
|
-
];
|
|
1441
|
-
var PG_CANCEL_BY_TIMEOUT = /statement timeout/i;
|
|
1442
|
-
function categorize(errCode, errno, errMsg, system) {
|
|
1443
|
-
if (errCode) {
|
|
1444
|
-
if (TLS_CODE_PREFIX.test(errCode))
|
|
1445
|
-
return "TLS_ERROR";
|
|
1446
|
-
const known = TRANSPORT_CODES[errCode] ?? MYSQL_CODES[errCode] ?? SQLSTATES[errCode] ?? REDIS_PREFIXES[errCode];
|
|
1447
|
-
if (known === "STATEMENT_TIMEOUT" && errCode === "57014" && !PG_CANCEL_BY_TIMEOUT.test(errMsg)) {
|
|
1448
|
-
return null;
|
|
1449
|
-
}
|
|
1450
|
-
if (known)
|
|
1451
|
-
return known;
|
|
1452
|
-
}
|
|
1453
|
-
const isMysqlFamily = system === "mysql" || system === "mariadb";
|
|
1454
|
-
if (isMysqlFamily && typeof errno === "number" && MYSQL_ERRNOS[errno]) {
|
|
1455
|
-
return MYSQL_ERRNOS[errno];
|
|
1456
|
-
}
|
|
1457
|
-
const redisPrefix = errMsg.match(/^([A-Z]+)\s/)?.[1];
|
|
1458
|
-
if (redisPrefix && REDIS_PREFIXES[redisPrefix])
|
|
1459
|
-
return REDIS_PREFIXES[redisPrefix];
|
|
1460
|
-
if (errCode || isMysqlFamily && typeof errno === "number")
|
|
1461
|
-
return null;
|
|
1462
|
-
for (const [pattern, category] of FALLBACK_PATTERNS) {
|
|
1463
|
-
if (pattern.test(errMsg))
|
|
1464
|
-
return category;
|
|
1465
|
-
}
|
|
1466
|
-
return null;
|
|
1467
|
-
}
|
|
1468
|
-
var SYSTEM_FACTS = {
|
|
1469
|
-
postgresql: {
|
|
1470
|
-
serviceCheck: "systemctl status postgresql",
|
|
1471
|
-
defaultPort: "default 5432",
|
|
1472
|
-
firewallRule: "allow TCP 5432",
|
|
1473
|
-
client: "psql",
|
|
1474
|
-
logFile: "postgresql.log"
|
|
1475
|
-
},
|
|
1476
|
-
mysql: {
|
|
1477
|
-
serviceCheck: "systemctl status mysql",
|
|
1478
|
-
defaultPort: "default 3306",
|
|
1479
|
-
firewallRule: "allow TCP 3306",
|
|
1480
|
-
client: "mysql",
|
|
1481
|
-
logFile: "mysql.log"
|
|
1482
|
-
},
|
|
1483
|
-
mariadb: {
|
|
1484
|
-
serviceCheck: "systemctl status mariadb",
|
|
1485
|
-
defaultPort: "default 3306",
|
|
1486
|
-
firewallRule: "allow TCP 3306",
|
|
1487
|
-
client: "mariadb",
|
|
1488
|
-
logFile: "mariadb.log"
|
|
1489
|
-
},
|
|
1490
|
-
redis: {
|
|
1491
|
-
serviceCheck: "redis-cli ping",
|
|
1492
|
-
defaultPort: "default 6379",
|
|
1493
|
-
firewallRule: "allow TCP 6379",
|
|
1494
|
-
client: "redis-cli",
|
|
1495
|
-
logFile: "redis.log"
|
|
1496
|
-
}
|
|
1497
|
-
};
|
|
1498
|
-
function serviceHints(system, options) {
|
|
1499
|
-
const facts = SYSTEM_FACTS[system];
|
|
1500
|
-
return [
|
|
1501
|
-
`Check that the ${system} service is running: ${facts.serviceCheck}`,
|
|
1502
|
-
`Verify the port is correct: ${facts.defaultPort}`,
|
|
1503
|
-
`Check that ${options.host} is reachable: ping ${options.host} or telnet ${options.host} ${options.port}`
|
|
1504
|
-
];
|
|
1505
|
-
}
|
|
1506
|
-
function mapError(error, system, options) {
|
|
1507
|
-
if (error instanceof ConnectionError)
|
|
1508
|
-
return error;
|
|
1509
|
-
const err = error;
|
|
1510
|
-
const errMsg = String(err?.message || String(error));
|
|
1511
|
-
const errCode = String(err?.code || "");
|
|
1512
|
-
const errno = err?.errno;
|
|
1513
|
-
switch (categorize(errCode, errno, errMsg, system)) {
|
|
1514
|
-
case "ECONNREFUSED":
|
|
1515
|
-
return new ConnectionError("ECONNREFUSED", `Cannot connect to ${options.host}:${options.port} \u2014 server is not running or not listening on this port`, serviceHints(system, options));
|
|
1516
|
-
case "ETIMEDOUT":
|
|
1517
|
-
return new ConnectionError("ETIMEDOUT", `Connection timed out (${options.timeout || 5000}ms) \u2014 may be blocked by a firewall or slow network`, [
|
|
1518
|
-
`Check firewall rules: ${SYSTEM_FACTS[system].firewallRule}`,
|
|
1519
|
-
`Increase timeout: edit .dbcli and add "timeout": 15000`,
|
|
1520
|
-
`Verify network connectivity: ping ${options.host} -c 3`
|
|
1521
|
-
]);
|
|
1522
|
-
case "CONNECTION_LOST":
|
|
1523
|
-
return new ConnectionError("CONNECTION_LOST", `Connection to ${options.host}:${options.port} was lost mid-session \u2014 the server closed it or the network dropped`, [
|
|
1524
|
-
"Re-run the command: a dropped connection is often transient",
|
|
1525
|
-
`Check whether the server restarted or is cycling: ${SYSTEM_FACTS[system].logFile}`,
|
|
1526
|
-
"If it happens on long-running work, look at the server idle/wait timeout"
|
|
1527
|
-
]);
|
|
1528
|
-
case "SERVER_NOT_READY":
|
|
1529
|
-
return new ConnectionError("SERVER_NOT_READY", `${options.host}:${options.port} is not accepting connections yet \u2014 the server is starting up or recovering`, [
|
|
1530
|
-
"Retry shortly: this clears on its own once startup or recovery finishes",
|
|
1531
|
-
`Watch progress in the server log: ${SYSTEM_FACTS[system].logFile}`,
|
|
1532
|
-
"On a replica, this also appears while it catches up with the primary"
|
|
1533
|
-
]);
|
|
1534
|
-
case "CONNECTION_REJECTED":
|
|
1535
|
-
return new ConnectionError("CONNECTION_REJECTED", `${options.host}:${options.port} answered but rejected the connection attempt`, [
|
|
1536
|
-
"Check the server access rules (pg_hba.conf) for this user, database, and client address",
|
|
1537
|
-
"If a pooler (pgbouncer / ProxySQL) sits in front, check its own rules and limits",
|
|
1538
|
-
"Check whether the connection limit for this user or database is exhausted"
|
|
1539
|
-
]);
|
|
1540
|
-
case "TOO_MANY_CONNECTIONS":
|
|
1541
|
-
return new ConnectionError("TOO_MANY_CONNECTIONS", `${options.host}:${options.port} refused the connection \u2014 the server has no connection slots left`, [
|
|
1542
|
-
"Wait and retry: the limit is on concurrent connections, not on you",
|
|
1543
|
-
system === "postgresql" ? "Inspect usage: SELECT count(*) FROM pg_stat_activity \u2014 compare against max_connections" : 'Inspect usage: SHOW STATUS LIKE "Threads_connected" \u2014 compare against max_connections',
|
|
1544
|
-
"Close idle sessions, or raise max_connections if the load is legitimate"
|
|
1545
|
-
]);
|
|
1546
|
-
case "EHOSTUNREACH":
|
|
1547
|
-
return new ConnectionError("EHOSTUNREACH", `No route to ${options.host} \u2014 the name resolved, but the host or network is unreachable`, [
|
|
1548
|
-
"Check that you are on the right network or VPN",
|
|
1549
|
-
`Check routing and firewall between here and ${options.host}`,
|
|
1550
|
-
`Confirm the address is the one you meant: ${options.host}:${options.port}`
|
|
1551
|
-
]);
|
|
1552
|
-
case "TLS_ERROR":
|
|
1553
|
-
return new ConnectionError("TLS_ERROR", `TLS handshake failed: ${errMsg}`, [
|
|
1554
|
-
'Point the connection at the right CA bundle: set "caPath" in .dbcli',
|
|
1555
|
-
'For a self-signed certificate in a trusted network, set "rejectUnauthorized": false',
|
|
1556
|
-
`Confirm the certificate covers the host you connected to: ${options.host}`
|
|
1557
|
-
]);
|
|
1558
|
-
case "ENOTFOUND":
|
|
1559
|
-
return new ConnectionError("ENOTFOUND", `Host not found: ${options.host}`, [
|
|
1560
|
-
`Check the hostname spelling: ${options.host}`,
|
|
1561
|
-
`Verify DNS resolution: nslookup ${options.host}`,
|
|
1562
|
-
`If using localhost, try 127.0.0.1 (IPv4 vs IPv6 issue)`
|
|
1563
|
-
]);
|
|
1564
|
-
case "AUTH_FAILED":
|
|
1565
|
-
return new ConnectionError("AUTH_FAILED", `Authentication failed \u2014 check your username or password`, [
|
|
1566
|
-
`Verify credentials: ${SYSTEM_FACTS[system].client} ${system === "postgresql" ? "-U" : "-u"} ${options.user} -h ${options.host}`,
|
|
1567
|
-
`Check pg_hba.conf (PostgreSQL) or user privileges (MySQL)`,
|
|
1568
|
-
`Re-run dbcli init to update credentials`
|
|
1569
|
-
]);
|
|
1570
|
-
case "TABLE_NOT_FOUND": {
|
|
1571
|
-
const mysqlMatch = errMsg.match(/Table\s+'(?:[^.']+\.)?([^']+)'/i);
|
|
1572
|
-
const pgMatch = errMsg.match(/relation\s+"([^"]+)"/i);
|
|
1573
|
-
const tableName = mysqlMatch?.[1] || pgMatch?.[1] || "unknown";
|
|
1574
|
-
return new ConnectionError("TABLE_NOT_FOUND", `Table '${tableName}' not found in database '${options.database || "unknown"}'`, [
|
|
1575
|
-
"Run `dbcli list` to see available tables",
|
|
1576
|
-
"Run `dbcli schema <table>` to confirm the exact name (ORM export names may differ from DB table names)"
|
|
1577
|
-
]);
|
|
1578
|
-
}
|
|
1579
|
-
case "COLUMN_NOT_FOUND": {
|
|
1580
|
-
const mysqlMatch = errMsg.match(/Unknown column\s+'([^']+)'/i);
|
|
1581
|
-
const pgMatch = errMsg.match(/column\s+"([^"]+)"\s+does not exist/i);
|
|
1582
|
-
const columnName = mysqlMatch?.[1] || pgMatch?.[1] || "unknown";
|
|
1583
|
-
return new ConnectionError("COLUMN_NOT_FOUND", `Column '${columnName}' not found`, [
|
|
1584
|
-
"Run `dbcli schema <table>` to see the actual column names",
|
|
1585
|
-
"Column names are case-sensitive on some databases (PostgreSQL with quoted identifiers)"
|
|
1586
|
-
]);
|
|
1587
|
-
}
|
|
1588
|
-
case "STATEMENT_TIMEOUT": {
|
|
1589
|
-
const limitMs = options.statementTimeout ?? options.timeout;
|
|
1590
|
-
return new ConnectionError("STATEMENT_TIMEOUT", `Statement timed out${limitMs ? ` (${limitMs}ms)` : ""} \u2014 the server canceled this query before it finished`, [
|
|
1591
|
-
'Inspect the query plan: dbcli explain "<sql>"',
|
|
1592
|
-
"Raise the ceiling for this run: dbcli --statement-timeout <ms> \u2026 (0 removes it)",
|
|
1593
|
-
"Narrow the query: add WHERE filters, reduce the LIMIT, or index the scanned columns"
|
|
1594
|
-
], limitMs);
|
|
1595
|
-
}
|
|
1596
|
-
case "SQL_SYNTAX_ERROR":
|
|
1597
|
-
return new ConnectionError("SQL_SYNTAX_ERROR", `SQL syntax error: ${errMsg}`, [
|
|
1598
|
-
"Check your SQL syntax near the position reported above",
|
|
1599
|
-
"In query-only mode, dbcli auto-appends LIMIT 1000; use --no-limit to disable",
|
|
1600
|
-
"For SHOW/DESCRIBE/EXPLAIN statements, LIMIT is not allowed \u2014 these are not auto-limited"
|
|
1601
|
-
]);
|
|
1602
|
-
}
|
|
1603
|
-
const reportedCode = errCode || (typeof errno === "number" ? String(errno) : "");
|
|
1604
|
-
if (reportedCode) {
|
|
1605
|
-
return new ConnectionError("UNKNOWN", `Database error (${reportedCode}): ${errMsg}`, [
|
|
1606
|
-
"Run `dbcli schema <table>` to confirm the objects referenced by this statement",
|
|
1607
|
-
`Look up ${reportedCode} in the ${system} error reference for the exact cause`
|
|
1608
|
-
]);
|
|
1609
|
-
}
|
|
1610
|
-
return new ConnectionError("UNKNOWN", `Connection failed: ${errMsg}`, [
|
|
1611
|
-
`Check connection parameters: host=${options.host}, port=${options.port}, user=${options.user}`,
|
|
1612
|
-
`View server logs: ${SYSTEM_FACTS[system].logFile}`,
|
|
1613
|
-
`Try connecting directly with the ${SYSTEM_FACTS[system].client} command-line tool`
|
|
1614
|
-
]);
|
|
1615
|
-
}
|
|
1616
1246
|
// resources/lang/en/messages.json
|
|
1617
1247
|
var messages_default = {
|
|
1618
1248
|
cli: {
|
|
@@ -1621,6 +1251,8 @@ var messages_default = {
|
|
|
1621
1251
|
init: {
|
|
1622
1252
|
description: "Initialize dbcli configuration with .env parsing and interactive prompts",
|
|
1623
1253
|
welcome: "Welcome to dbcli",
|
|
1254
|
+
prompt_connection_name: "Connection name",
|
|
1255
|
+
connection_name_required: "Connection name is required. Provide --conn-name <name> (this is separate from the database --name).",
|
|
1624
1256
|
select_system: "Select database system:",
|
|
1625
1257
|
prompt_host: "Database host: ",
|
|
1626
1258
|
prompt_port: "Database port: ",
|
|
@@ -1645,7 +1277,7 @@ var messages_default = {
|
|
|
1645
1277
|
config_exists_use_force: ".dbcli exists. Use --force option to overwrite.",
|
|
1646
1278
|
connection_added: "Connection '{name}' added",
|
|
1647
1279
|
connection_removed: "Connection '{name}' removed",
|
|
1648
|
-
|
|
1280
|
+
connection_removed_default_cleared: "Connection '{name}' removed. Default connection cleared. Specify --use <name> or DBCLI_CONNECTION for database commands.",
|
|
1649
1281
|
connection_renamed: "Connection '{oldName}' renamed to '{newName}'",
|
|
1650
1282
|
v1_migration_prompt: "Detected old config format. Create new format and import existing connection as 'default'?",
|
|
1651
1283
|
config_saved_v2: "V2 configuration saved to .dbcli",
|
|
@@ -1683,6 +1315,9 @@ var messages_default = {
|
|
|
1683
1315
|
description: "Switch or display the default database connection",
|
|
1684
1316
|
switched: "Switched default connection to {name}",
|
|
1685
1317
|
current: "Current default connection: {name}",
|
|
1318
|
+
current_none: "No default connection. Specify --use <name> or DBCLI_CONNECTION.",
|
|
1319
|
+
unset: "Default connection cleared. Specify --use <name> or DBCLI_CONNECTION for database commands.",
|
|
1320
|
+
unset_conflict: "--unset cannot be combined with a connection name, --list, --confirm-production, or --format json",
|
|
1686
1321
|
requires_v2: "This feature requires v2 config format. Use 'dbcli init --conn-name <name>' to create one",
|
|
1687
1322
|
available: "Available connections"
|
|
1688
1323
|
},
|
|
@@ -1953,6 +1588,8 @@ var messages_default2 = {
|
|
|
1953
1588
|
init: {
|
|
1954
1589
|
description: "\u521D\u59CB\u5316 dbcli \u914D\u7F6E\uFF0C\u89E3\u6790 .env \u4E26\u9032\u884C\u4E92\u52D5\u5F0F\u63D0\u793A",
|
|
1955
1590
|
welcome: "\u6B61\u8FCE\u4F7F\u7528 dbcli",
|
|
1591
|
+
prompt_connection_name: "\u9023\u7DDA\u540D\u7A31",
|
|
1592
|
+
connection_name_required: "\u9023\u7DDA\u540D\u7A31\u4E0D\u53EF\u7A7A\u767D\uFF0C\u8ACB\u63D0\u4F9B --conn-name <name>\uFF08\u8207\u8CC7\u6599\u5EAB\u540D\u7A31 --name \u4E0D\u540C\uFF09\u3002",
|
|
1956
1593
|
select_system: "\u9078\u64C7\u8CC7\u6599\u5EAB\u7CFB\u7D71\uFF1A",
|
|
1957
1594
|
prompt_host: "\u8CC7\u6599\u5EAB\u4E3B\u6A5F\uFF1A",
|
|
1958
1595
|
prompt_port: "\u8CC7\u6599\u5EAB\u57E0\u865F\uFF1A",
|
|
@@ -1977,7 +1614,7 @@ var messages_default2 = {
|
|
|
1977
1614
|
config_exists_use_force: ".dbcli \u5DF2\u5B58\u5728\u3002\u4F7F\u7528 --force \u9078\u9805\u8986\u84CB\u3002",
|
|
1978
1615
|
connection_added: "\u5DF2\u65B0\u589E\u9023\u7DDA '{name}'",
|
|
1979
1616
|
connection_removed: "\u5DF2\u79FB\u9664\u9023\u7DDA '{name}'",
|
|
1980
|
-
|
|
1617
|
+
connection_removed_default_cleared: "\u5DF2\u79FB\u9664\u9023\u7DDA '{name}'\uFF0C\u9810\u8A2D\u9023\u7DDA\u5DF2\u6E05\u7A7A\u3002\u57F7\u884C\u8CC7\u6599\u5EAB\u6307\u4EE4\u6642\u8ACB\u4F7F\u7528 --use <name> \u6216\u8A2D\u5B9A DBCLI_CONNECTION\u3002",
|
|
1981
1618
|
connection_renamed: "\u5DF2\u5C07\u9023\u7DDA '{oldName}' \u91CD\u65B0\u547D\u540D\u70BA '{newName}'",
|
|
1982
1619
|
v1_migration_prompt: "\u5075\u6E2C\u5230\u820A\u683C\u5F0F\u8A2D\u5B9A\uFF0C\u5C07\u5EFA\u7ACB\u65B0\u683C\u5F0F\u4E26\u5C07\u73FE\u6709\u9023\u7DDA\u532F\u5165\u70BA 'default'\uFF0C\u662F\u5426\u7E7C\u7E8C\uFF1F",
|
|
1983
1620
|
config_saved_v2: "V2 \u8A2D\u5B9A\u5DF2\u5132\u5B58\u81F3 .dbcli",
|
|
@@ -2015,6 +1652,9 @@ var messages_default2 = {
|
|
|
2015
1652
|
description: "\u5207\u63DB\u6216\u986F\u793A\u9810\u8A2D\u8CC7\u6599\u5EAB\u9023\u7DDA",
|
|
2016
1653
|
switched: "\u5DF2\u5207\u63DB\u9810\u8A2D\u9023\u7DDA\u70BA {name}",
|
|
2017
1654
|
current: "\u76EE\u524D\u7684\u9810\u8A2D\u9023\u7DDA\uFF1A{name}",
|
|
1655
|
+
current_none: "\u76EE\u524D\u6C92\u6709\u9810\u8A2D\u9023\u7DDA\u3002\u8ACB\u4F7F\u7528 --use <name> \u6216\u8A2D\u5B9A DBCLI_CONNECTION\u3002",
|
|
1656
|
+
unset: "\u9810\u8A2D\u9023\u7DDA\u5DF2\u6E05\u7A7A\u3002\u57F7\u884C\u8CC7\u6599\u5EAB\u6307\u4EE4\u6642\u8ACB\u4F7F\u7528 --use <name> \u6216\u8A2D\u5B9A DBCLI_CONNECTION\u3002",
|
|
1657
|
+
unset_conflict: "--unset \u4E0D\u53EF\u8207\u9023\u7DDA\u540D\u7A31\u3001--list\u3001--confirm-production \u6216 --format json \u540C\u6642\u4F7F\u7528",
|
|
2018
1658
|
requires_v2: "\u6B64\u529F\u80FD\u9700\u8981\u65B0\u683C\u5F0F\u8A2D\u5B9A\u3002\u8ACB\u4F7F\u7528 dbcli init --conn-name <\u540D\u7A31> \u5EFA\u7ACB\u591A\u9023\u7DDA\u8A2D\u5B9A",
|
|
2019
1659
|
available: "\u53EF\u7528\u9023\u7DDA"
|
|
2020
1660
|
},
|
|
@@ -2528,495 +2168,6 @@ var messageLoader = MessageLoader.getInstance();
|
|
|
2528
2168
|
var t = (key) => messageLoader.t(key);
|
|
2529
2169
|
var t_vars = (key, vars) => messageLoader.interpolate(key, vars);
|
|
2530
2170
|
|
|
2531
|
-
// src/adapters/sql-adapter-utils.ts
|
|
2532
|
-
function queryOnlyBoundaryError(system, error) {
|
|
2533
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
2534
|
-
return new ConnectionError("QUERY_ONLY_BOUNDARY_FAILED", t_vars("errors.query_only_boundary_failed", { system, detail }), [
|
|
2535
|
-
t_vars("errors.query_only_boundary_verify", { system }),
|
|
2536
|
-
t_vars("errors.query_only_boundary_not_executed", {})
|
|
2537
|
-
]);
|
|
2538
|
-
}
|
|
2539
|
-
function queryOnlyCleanupError(system, error, targetCompleted) {
|
|
2540
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
2541
|
-
return new ConnectionError("CONNECTION_LOST", targetCompleted ? t_vars("errors.query_only_cleanup_completed", { system, detail }) : t_vars("errors.query_only_cleanup_uncertain", { system, detail }), [
|
|
2542
|
-
targetCompleted ? t_vars("errors.query_only_cleanup_completed_retry", {}) : t_vars("errors.query_only_cleanup_uncertain_retry", {}),
|
|
2543
|
-
t_vars("errors.query_only_cleanup_reconnect", {})
|
|
2544
|
-
], undefined, false);
|
|
2545
|
-
}
|
|
2546
|
-
function requireConnected(connection) {
|
|
2547
|
-
if (!connection) {
|
|
2548
|
-
throw new ConnectionError("UNKNOWN", "Database connection not established", [
|
|
2549
|
-
"Call connect() to establish a connection"
|
|
2550
|
-
]);
|
|
2551
|
-
}
|
|
2552
|
-
return connection;
|
|
2553
|
-
}
|
|
2554
|
-
async function withMappedConnectionError(system, options, operation) {
|
|
2555
|
-
try {
|
|
2556
|
-
return await operation();
|
|
2557
|
-
} catch (error) {
|
|
2558
|
-
throw mapError(error, system, options);
|
|
2559
|
-
}
|
|
2560
|
-
}
|
|
2561
|
-
|
|
2562
|
-
// src/utils/colors.ts
|
|
2563
|
-
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
2564
|
-
var colors = {
|
|
2565
|
-
success: (text) => import_picocolors.default.green(text),
|
|
2566
|
-
error: (text) => import_picocolors.default.red(text),
|
|
2567
|
-
warn: (text) => import_picocolors.default.yellow(text),
|
|
2568
|
-
info: (text) => import_picocolors.default.blue(text),
|
|
2569
|
-
dim: (text) => import_picocolors.default.dim(text),
|
|
2570
|
-
bold: (text) => import_picocolors.default.bold(text),
|
|
2571
|
-
keyword: (text) => import_picocolors.default.blue(import_picocolors.default.bold(text))
|
|
2572
|
-
};
|
|
2573
|
-
|
|
2574
|
-
// src/utils/db-version-check.ts
|
|
2575
|
-
var MIN_SUPPORTED_VERSIONS = {
|
|
2576
|
-
postgresql: "12.0",
|
|
2577
|
-
mysql: "8.0",
|
|
2578
|
-
mariadb: "10.5",
|
|
2579
|
-
elasticsearch: "7.10"
|
|
2580
|
-
};
|
|
2581
|
-
function parseVersionSegments(version) {
|
|
2582
|
-
const match = version.match(/^(\d+(?:\.\d+)*)/);
|
|
2583
|
-
if (!match)
|
|
2584
|
-
return [];
|
|
2585
|
-
return (match[1] ?? "").split(".").map(Number);
|
|
2586
|
-
}
|
|
2587
|
-
function isMariaDBVersion(versionString) {
|
|
2588
|
-
return /mariadb/i.test(versionString);
|
|
2589
|
-
}
|
|
2590
|
-
function extractMariaDBVersion(versionString) {
|
|
2591
|
-
const match = versionString.match(/(\d+\.\d+\.\d+)-MariaDB/i);
|
|
2592
|
-
if (match)
|
|
2593
|
-
return match[1] ?? versionString;
|
|
2594
|
-
const prefixMatch = versionString.match(/^5\.5\.5-(\d+\.\d+\.\d+)/);
|
|
2595
|
-
if (prefixMatch)
|
|
2596
|
-
return prefixMatch[1] ?? versionString;
|
|
2597
|
-
return versionString;
|
|
2598
|
-
}
|
|
2599
|
-
function compareVersions(a, b) {
|
|
2600
|
-
const segA = parseVersionSegments(a);
|
|
2601
|
-
const segB = parseVersionSegments(b);
|
|
2602
|
-
const len = Math.max(segA.length, segB.length);
|
|
2603
|
-
for (let i = 0;i < len; i++) {
|
|
2604
|
-
const diff = (segA[i] ?? 0) - (segB[i] ?? 0);
|
|
2605
|
-
if (diff !== 0)
|
|
2606
|
-
return diff;
|
|
2607
|
-
}
|
|
2608
|
-
return 0;
|
|
2609
|
-
}
|
|
2610
|
-
function checkDbVersion(rawVersion, declaredSystem) {
|
|
2611
|
-
const isMariaDB = isMariaDBVersion(rawVersion);
|
|
2612
|
-
const system = isMariaDB ? "mariadb" : declaredSystem;
|
|
2613
|
-
const serverVersion = isMariaDB ? extractMariaDBVersion(rawVersion) : rawVersion;
|
|
2614
|
-
const minVersion = MIN_SUPPORTED_VERSIONS[system];
|
|
2615
|
-
const supported = compareVersions(serverVersion, minVersion ?? "0") >= 0;
|
|
2616
|
-
return {
|
|
2617
|
-
serverVersion,
|
|
2618
|
-
system,
|
|
2619
|
-
supported,
|
|
2620
|
-
minVersion: minVersion ?? "0"
|
|
2621
|
-
};
|
|
2622
|
-
}
|
|
2623
|
-
function warnIfUnsupported(result) {
|
|
2624
|
-
if (result.supported)
|
|
2625
|
-
return;
|
|
2626
|
-
const message = t_vars("version.unsupported_warning", {
|
|
2627
|
-
system: result.system,
|
|
2628
|
-
version: result.serverVersion,
|
|
2629
|
-
minVersion: result.minVersion
|
|
2630
|
-
});
|
|
2631
|
-
process.stderr.write(colors.warn(`\u26A0 ${message}`) + `
|
|
2632
|
-
`);
|
|
2633
|
-
}
|
|
2634
|
-
|
|
2635
|
-
// src/utils/encoding.ts
|
|
2636
|
-
var CP1252_REVERSE = {
|
|
2637
|
-
8364: 128,
|
|
2638
|
-
8218: 130,
|
|
2639
|
-
402: 131,
|
|
2640
|
-
8222: 132,
|
|
2641
|
-
8230: 133,
|
|
2642
|
-
8224: 134,
|
|
2643
|
-
8225: 135,
|
|
2644
|
-
710: 136,
|
|
2645
|
-
8240: 137,
|
|
2646
|
-
352: 138,
|
|
2647
|
-
8249: 139,
|
|
2648
|
-
338: 140,
|
|
2649
|
-
381: 142,
|
|
2650
|
-
8216: 145,
|
|
2651
|
-
8217: 146,
|
|
2652
|
-
8220: 147,
|
|
2653
|
-
8221: 148,
|
|
2654
|
-
8226: 149,
|
|
2655
|
-
8211: 150,
|
|
2656
|
-
8212: 151,
|
|
2657
|
-
732: 152,
|
|
2658
|
-
8482: 153,
|
|
2659
|
-
353: 154,
|
|
2660
|
-
8250: 155,
|
|
2661
|
-
339: 156,
|
|
2662
|
-
382: 158,
|
|
2663
|
-
376: 159
|
|
2664
|
-
};
|
|
2665
|
-
function fixDoubleEncodedUtf8(str) {
|
|
2666
|
-
if (!str)
|
|
2667
|
-
return str;
|
|
2668
|
-
const bytes = [];
|
|
2669
|
-
for (const char of str) {
|
|
2670
|
-
const code = char.codePointAt(0);
|
|
2671
|
-
if (code < 128) {
|
|
2672
|
-
bytes.push(code);
|
|
2673
|
-
} else if (code <= 255) {
|
|
2674
|
-
bytes.push(code);
|
|
2675
|
-
} else {
|
|
2676
|
-
const cp1252Byte = CP1252_REVERSE[code];
|
|
2677
|
-
if (cp1252Byte !== undefined) {
|
|
2678
|
-
bytes.push(cp1252Byte);
|
|
2679
|
-
} else {
|
|
2680
|
-
return str;
|
|
2681
|
-
}
|
|
2682
|
-
}
|
|
2683
|
-
}
|
|
2684
|
-
try {
|
|
2685
|
-
const decoded = new TextDecoder("utf-8", { fatal: true }).decode(new Uint8Array(bytes));
|
|
2686
|
-
if (decoded !== str) {
|
|
2687
|
-
return decoded;
|
|
2688
|
-
}
|
|
2689
|
-
} catch {}
|
|
2690
|
-
return str;
|
|
2691
|
-
}
|
|
2692
|
-
|
|
2693
|
-
// src/adapters/identifier-quote.ts
|
|
2694
|
-
function quoteCharFor(dialect) {
|
|
2695
|
-
return dialect === "postgresql" || dialect === "sqlite" ? '"' : "`";
|
|
2696
|
-
}
|
|
2697
|
-
function assertQuotable(name, what) {
|
|
2698
|
-
if (name.length === 0) {
|
|
2699
|
-
throw new Error(`${what} must not be empty`);
|
|
2700
|
-
}
|
|
2701
|
-
if (name.includes(String.fromCharCode(0))) {
|
|
2702
|
-
throw new Error(`${what} must not contain a NUL character`);
|
|
2703
|
-
}
|
|
2704
|
-
}
|
|
2705
|
-
function quoteIdentifier(name, dialect) {
|
|
2706
|
-
assertQuotable(name, "identifier");
|
|
2707
|
-
const q = quoteCharFor(dialect);
|
|
2708
|
-
return `${q}${name.split(q).join(q + q)}${q}`;
|
|
2709
|
-
}
|
|
2710
|
-
|
|
2711
|
-
// src/adapters/timeout-policy.ts
|
|
2712
|
-
var DEFAULT_CONNECT_TIMEOUT_MS = 5000;
|
|
2713
|
-
function resolveTimeoutPolicy(options) {
|
|
2714
|
-
return {
|
|
2715
|
-
connectMs: options.timeout ?? DEFAULT_CONNECT_TIMEOUT_MS,
|
|
2716
|
-
statementMs: options.statementTimeout ?? options.timeout
|
|
2717
|
-
};
|
|
2718
|
-
}
|
|
2719
|
-
function statementTimeoutSql(system, ms) {
|
|
2720
|
-
if (system === "mariadb") {
|
|
2721
|
-
return `SET SESSION max_statement_time = ${ms / 1000}`;
|
|
2722
|
-
}
|
|
2723
|
-
return `SET SESSION max_execution_time = ${Math.round(ms)}`;
|
|
2724
|
-
}
|
|
2725
|
-
|
|
2726
|
-
// src/utils/connection-error-message.ts
|
|
2727
|
-
var IS_TRANSPORT_FAILURE = {
|
|
2728
|
-
ECONNREFUSED: true,
|
|
2729
|
-
ETIMEDOUT: true,
|
|
2730
|
-
AUTH_FAILED: true,
|
|
2731
|
-
ENOTFOUND: true,
|
|
2732
|
-
EHOSTUNREACH: true,
|
|
2733
|
-
CONNECTION_LOST: true,
|
|
2734
|
-
TOO_MANY_CONNECTIONS: true,
|
|
2735
|
-
TLS_ERROR: true,
|
|
2736
|
-
SERVER_NOT_READY: true,
|
|
2737
|
-
CONNECTION_REJECTED: true,
|
|
2738
|
-
STATEMENT_TIMEOUT: false,
|
|
2739
|
-
SQL_SYNTAX_ERROR: false,
|
|
2740
|
-
TABLE_NOT_FOUND: false,
|
|
2741
|
-
COLUMN_NOT_FOUND: false,
|
|
2742
|
-
QUERY_ONLY_BOUNDARY_FAILED: false,
|
|
2743
|
-
UNKNOWN: false
|
|
2744
|
-
};
|
|
2745
|
-
function isTransportFailure(error) {
|
|
2746
|
-
if (error instanceof ConnectionError)
|
|
2747
|
-
return IS_TRANSPORT_FAILURE[error.code];
|
|
2748
|
-
const raw = error?.code;
|
|
2749
|
-
return typeof raw === "string" && isTransportDriverCode(raw);
|
|
2750
|
-
}
|
|
2751
|
-
|
|
2752
|
-
// src/adapters/mysql-adapter.ts
|
|
2753
|
-
function parseEnumValues(columnType) {
|
|
2754
|
-
const match = columnType.match(/^enum\((.+)\)$/i);
|
|
2755
|
-
if (!match)
|
|
2756
|
-
return;
|
|
2757
|
-
return (match[1] ?? "").split(",").map((v) => v.trim().replace(/^'|'$/g, ""));
|
|
2758
|
-
}
|
|
2759
|
-
|
|
2760
|
-
class MySQLAdapter {
|
|
2761
|
-
db = null;
|
|
2762
|
-
executionTail = Promise.resolve();
|
|
2763
|
-
options;
|
|
2764
|
-
system;
|
|
2765
|
-
constructor(options) {
|
|
2766
|
-
this.options = options;
|
|
2767
|
-
this.system = options.system === "mariadb" ? "mariadb" : "mysql";
|
|
2768
|
-
if (options.port < 1 || options.port > 65535) {
|
|
2769
|
-
throw new Error(`Invalid port number: ${options.port}`);
|
|
2770
|
-
}
|
|
2771
|
-
}
|
|
2772
|
-
async connect() {
|
|
2773
|
-
await withMappedConnectionError(this.system, this.options, async () => {
|
|
2774
|
-
const timeouts = resolveTimeoutPolicy(this.options);
|
|
2775
|
-
const { default: driver } = await import("mysql2/promise");
|
|
2776
|
-
this.db = await driver.createConnection({
|
|
2777
|
-
host: this.options.host,
|
|
2778
|
-
port: this.options.port,
|
|
2779
|
-
user: this.options.user,
|
|
2780
|
-
password: this.options.password || undefined,
|
|
2781
|
-
database: this.options.database,
|
|
2782
|
-
charset: "utf8mb4",
|
|
2783
|
-
connectTimeout: timeouts.connectMs
|
|
2784
|
-
});
|
|
2785
|
-
await this.db.execute("SET NAMES utf8mb4");
|
|
2786
|
-
if (timeouts.statementMs !== undefined) {
|
|
2787
|
-
try {
|
|
2788
|
-
await this.db.query(statementTimeoutSql(this.system, timeouts.statementMs));
|
|
2789
|
-
} catch {}
|
|
2790
|
-
}
|
|
2791
|
-
await this.testConnection();
|
|
2792
|
-
try {
|
|
2793
|
-
const rawVersion = await this.getServerVersion();
|
|
2794
|
-
const result = checkDbVersion(rawVersion, this.system);
|
|
2795
|
-
warnIfUnsupported(result);
|
|
2796
|
-
} catch {}
|
|
2797
|
-
});
|
|
2798
|
-
}
|
|
2799
|
-
async disconnect() {
|
|
2800
|
-
try {
|
|
2801
|
-
if (this.db) {
|
|
2802
|
-
await this.db.end();
|
|
2803
|
-
this.db = null;
|
|
2804
|
-
}
|
|
2805
|
-
} catch {}
|
|
2806
|
-
}
|
|
2807
|
-
async testConnection() {
|
|
2808
|
-
requireConnected(this.db);
|
|
2809
|
-
return withMappedConnectionError(this.system, this.options, async () => {
|
|
2810
|
-
const result = await this.execute("SELECT 1 as count");
|
|
2811
|
-
return result.rows.length > 0;
|
|
2812
|
-
});
|
|
2813
|
-
}
|
|
2814
|
-
async execute(sql, params, options) {
|
|
2815
|
-
const db = requireConnected(this.db);
|
|
2816
|
-
return withMappedConnectionError(this.system, this.options, async () => {
|
|
2817
|
-
const execution = this.executionTail.then(async () => {
|
|
2818
|
-
if (options?.sqlMode === "native-read-only") {
|
|
2819
|
-
return this.executeReadOnly(db, sql, params);
|
|
2820
|
-
}
|
|
2821
|
-
const [result] = params ? await db.execute(sql, params) : await db.execute(sql);
|
|
2822
|
-
if (Array.isArray(result)) {
|
|
2823
|
-
return {
|
|
2824
|
-
rows: result,
|
|
2825
|
-
affectedRows: result.length
|
|
2826
|
-
};
|
|
2827
|
-
}
|
|
2828
|
-
const header = result;
|
|
2829
|
-
return {
|
|
2830
|
-
rows: [],
|
|
2831
|
-
affectedRows: header.affectedRows || 0,
|
|
2832
|
-
lastInsertId: header.insertId
|
|
2833
|
-
};
|
|
2834
|
-
});
|
|
2835
|
-
this.executionTail = execution.then(() => {
|
|
2836
|
-
return;
|
|
2837
|
-
}, () => {
|
|
2838
|
-
return;
|
|
2839
|
-
});
|
|
2840
|
-
return execution;
|
|
2841
|
-
});
|
|
2842
|
-
}
|
|
2843
|
-
async executeReadOnly(db, sql, params) {
|
|
2844
|
-
let primaryError;
|
|
2845
|
-
let cleanupError;
|
|
2846
|
-
let executionResult;
|
|
2847
|
-
let transactionStarted = false;
|
|
2848
|
-
try {
|
|
2849
|
-
try {
|
|
2850
|
-
await db.query("START TRANSACTION READ ONLY");
|
|
2851
|
-
transactionStarted = true;
|
|
2852
|
-
} catch (error) {
|
|
2853
|
-
const mapped = mapError(error, this.system, this.options);
|
|
2854
|
-
if (isTransportFailure(mapped))
|
|
2855
|
-
throw mapped;
|
|
2856
|
-
throw queryOnlyBoundaryError(this.system, error);
|
|
2857
|
-
}
|
|
2858
|
-
const [result] = params ? await db.execute(sql, params) : await db.execute(sql);
|
|
2859
|
-
if (Array.isArray(result)) {
|
|
2860
|
-
executionResult = { rows: result, affectedRows: result.length };
|
|
2861
|
-
} else {
|
|
2862
|
-
const header = result;
|
|
2863
|
-
executionResult = {
|
|
2864
|
-
rows: [],
|
|
2865
|
-
affectedRows: header.affectedRows || 0,
|
|
2866
|
-
lastInsertId: header.insertId
|
|
2867
|
-
};
|
|
2868
|
-
}
|
|
2869
|
-
} catch (error) {
|
|
2870
|
-
primaryError = error;
|
|
2871
|
-
} finally {
|
|
2872
|
-
if (transactionStarted) {
|
|
2873
|
-
try {
|
|
2874
|
-
await db.query("ROLLBACK");
|
|
2875
|
-
} catch (error) {
|
|
2876
|
-
db.destroy();
|
|
2877
|
-
this.db = null;
|
|
2878
|
-
cleanupError = error;
|
|
2879
|
-
}
|
|
2880
|
-
}
|
|
2881
|
-
}
|
|
2882
|
-
if (cleanupError !== undefined) {
|
|
2883
|
-
throw queryOnlyCleanupError(this.system, cleanupError, primaryError === undefined);
|
|
2884
|
-
}
|
|
2885
|
-
if (primaryError !== undefined)
|
|
2886
|
-
throw primaryError;
|
|
2887
|
-
return executionResult;
|
|
2888
|
-
}
|
|
2889
|
-
async getServerVersion() {
|
|
2890
|
-
const result = await this.execute("SELECT VERSION() as version");
|
|
2891
|
-
return result.rows[0]?.version ?? "unknown";
|
|
2892
|
-
}
|
|
2893
|
-
async listTables() {
|
|
2894
|
-
requireConnected(this.db);
|
|
2895
|
-
return withMappedConnectionError(this.system, this.options, async () => {
|
|
2896
|
-
const query = `
|
|
2897
|
-
SELECT
|
|
2898
|
-
t.TABLE_NAME as table_name,
|
|
2899
|
-
t.TABLE_ROWS as row_count,
|
|
2900
|
-
t.ENGINE as engine,
|
|
2901
|
-
t.TABLE_TYPE as table_type,
|
|
2902
|
-
COUNT(c.COLUMN_NAME) as column_count
|
|
2903
|
-
FROM information_schema.TABLES t
|
|
2904
|
-
LEFT JOIN information_schema.COLUMNS c
|
|
2905
|
-
ON t.TABLE_SCHEMA = c.TABLE_SCHEMA AND t.TABLE_NAME = c.TABLE_NAME
|
|
2906
|
-
WHERE t.TABLE_SCHEMA = DATABASE()
|
|
2907
|
-
GROUP BY t.TABLE_NAME, t.TABLE_ROWS, t.ENGINE, t.TABLE_TYPE
|
|
2908
|
-
ORDER BY t.TABLE_NAME
|
|
2909
|
-
`;
|
|
2910
|
-
const result = await this.execute(query);
|
|
2911
|
-
return result.rows.map((row) => ({
|
|
2912
|
-
name: row.table_name,
|
|
2913
|
-
columns: [],
|
|
2914
|
-
columnCount: row.column_count,
|
|
2915
|
-
rowCount: row.row_count || 0,
|
|
2916
|
-
engine: row.engine,
|
|
2917
|
-
estimatedRowCount: row.row_count || 0,
|
|
2918
|
-
tableType: row.table_type === "VIEW" ? "view" : "table"
|
|
2919
|
-
}));
|
|
2920
|
-
});
|
|
2921
|
-
}
|
|
2922
|
-
async getTableSchema(tableName, options) {
|
|
2923
|
-
requireConnected(this.db);
|
|
2924
|
-
return withMappedConnectionError(this.system, this.options, async () => {
|
|
2925
|
-
const columnQuery = `
|
|
2926
|
-
SELECT
|
|
2927
|
-
COLUMN_NAME as name,
|
|
2928
|
-
COLUMN_TYPE as type,
|
|
2929
|
-
IS_NULLABLE = 'YES' as nullable,
|
|
2930
|
-
COLUMN_DEFAULT as default_value,
|
|
2931
|
-
COLUMN_KEY = 'PRI' as is_primary_key,
|
|
2932
|
-
EXTRA LIKE '%auto_increment%' as auto_increment,
|
|
2933
|
-
COLUMN_COMMENT as comment
|
|
2934
|
-
FROM information_schema.COLUMNS
|
|
2935
|
-
WHERE TABLE_SCHEMA = DATABASE()
|
|
2936
|
-
AND TABLE_NAME = ?
|
|
2937
|
-
ORDER BY ORDINAL_POSITION
|
|
2938
|
-
`;
|
|
2939
|
-
const columnResult = await this.execute(columnQuery, [tableName]);
|
|
2940
|
-
const columns = columnResult.rows;
|
|
2941
|
-
const fkQuery = `
|
|
2942
|
-
SELECT
|
|
2943
|
-
rc.CONSTRAINT_NAME as name,
|
|
2944
|
-
GROUP_CONCAT(kcu.COLUMN_NAME) as columns,
|
|
2945
|
-
rc.REFERENCED_TABLE_NAME as ref_table,
|
|
2946
|
-
GROUP_CONCAT(kcu.REFERENCED_COLUMN_NAME) as ref_columns
|
|
2947
|
-
FROM information_schema.REFERENTIAL_CONSTRAINTS rc
|
|
2948
|
-
JOIN information_schema.KEY_COLUMN_USAGE kcu
|
|
2949
|
-
ON rc.CONSTRAINT_NAME = kcu.CONSTRAINT_NAME AND rc.TABLE_NAME = kcu.TABLE_NAME
|
|
2950
|
-
WHERE kcu.TABLE_NAME = ? AND rc.CONSTRAINT_SCHEMA = DATABASE()
|
|
2951
|
-
GROUP BY rc.CONSTRAINT_NAME, rc.REFERENCED_TABLE_NAME
|
|
2952
|
-
`;
|
|
2953
|
-
const fkResult = await this.execute(fkQuery, [tableName]);
|
|
2954
|
-
const fkResults = fkResult.rows;
|
|
2955
|
-
const fkMap = new Map;
|
|
2956
|
-
for (const fk of fkResults) {
|
|
2957
|
-
const cols = fk.columns.split(",").map((c) => c.trim());
|
|
2958
|
-
const refCols = fk.ref_columns.split(",").map((c) => c.trim());
|
|
2959
|
-
if (cols.length === 1 && refCols.length === 1) {
|
|
2960
|
-
fkMap.set(cols[0], { table: fk.ref_table, column: refCols[0] });
|
|
2961
|
-
}
|
|
2962
|
-
}
|
|
2963
|
-
const primaryKeyColumns = columns.filter((col) => col.is_primary_key).map((col) => col.name);
|
|
2964
|
-
const indexQuery = `
|
|
2965
|
-
SELECT
|
|
2966
|
-
INDEX_NAME as name,
|
|
2967
|
-
GROUP_CONCAT(COLUMN_NAME ORDER BY SEQ_IN_INDEX) as columns,
|
|
2968
|
-
NOT NON_UNIQUE as is_unique
|
|
2969
|
-
FROM information_schema.STATISTICS
|
|
2970
|
-
WHERE TABLE_SCHEMA = DATABASE()
|
|
2971
|
-
AND TABLE_NAME = ?
|
|
2972
|
-
AND INDEX_NAME != 'PRIMARY'
|
|
2973
|
-
GROUP BY INDEX_NAME, NON_UNIQUE
|
|
2974
|
-
`;
|
|
2975
|
-
const indexResult = await this.execute(indexQuery, [tableName]);
|
|
2976
|
-
const indexResults = indexResult.rows;
|
|
2977
|
-
const tableMetaQuery = `
|
|
2978
|
-
SELECT ENGINE as engine, TABLE_ROWS as estimated_rows
|
|
2979
|
-
FROM information_schema.TABLES
|
|
2980
|
-
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ?
|
|
2981
|
-
`;
|
|
2982
|
-
const tableMetaResult = await this.execute(tableMetaQuery, [tableName]);
|
|
2983
|
-
const tableMeta = tableMetaResult.rows[0];
|
|
2984
|
-
const estimatedRowCount = Math.max(0, tableMeta?.estimated_rows || 0);
|
|
2985
|
-
const exactRowCount = options?.exactRowCount === false ? undefined : (await this.execute(`SELECT COUNT(*) as count FROM ${quoteIdentifier(tableName, this.system)}`)).rows[0]?.count;
|
|
2986
|
-
const schema = {
|
|
2987
|
-
name: tableName,
|
|
2988
|
-
columns: columns.map((col) => ({
|
|
2989
|
-
name: col.name,
|
|
2990
|
-
type: col.type,
|
|
2991
|
-
nullable: col.nullable,
|
|
2992
|
-
default: col.default_value || undefined,
|
|
2993
|
-
primaryKey: col.is_primary_key,
|
|
2994
|
-
foreignKey: fkMap.get(col.name),
|
|
2995
|
-
autoIncrement: col.auto_increment,
|
|
2996
|
-
comment: col.comment ? fixDoubleEncodedUtf8(col.comment) : null,
|
|
2997
|
-
enumValues: parseEnumValues(col.type)
|
|
2998
|
-
})),
|
|
2999
|
-
rowCount: exactRowCount ?? estimatedRowCount,
|
|
3000
|
-
engine: tableMeta?.engine || "MySQL",
|
|
3001
|
-
primaryKey: primaryKeyColumns,
|
|
3002
|
-
foreignKeys: fkResults.map((fk) => ({
|
|
3003
|
-
name: fk.name,
|
|
3004
|
-
columns: fk.columns.split(",").map((c) => c.trim()),
|
|
3005
|
-
refTable: fk.ref_table,
|
|
3006
|
-
refColumns: fk.ref_columns.split(",").map((c) => c.trim())
|
|
3007
|
-
})),
|
|
3008
|
-
indexes: indexResults.map((idx) => ({
|
|
3009
|
-
name: idx.name,
|
|
3010
|
-
columns: idx.columns.split(",").map((c) => c.trim()),
|
|
3011
|
-
unique: idx.is_unique
|
|
3012
|
-
})),
|
|
3013
|
-
estimatedRowCount
|
|
3014
|
-
};
|
|
3015
|
-
return schema;
|
|
3016
|
-
});
|
|
3017
|
-
}
|
|
3018
|
-
}
|
|
3019
|
-
|
|
3020
2171
|
// src/utils/case-fold.ts
|
|
3021
2172
|
function foldCase(text) {
|
|
3022
2173
|
const lowered = (text.includes("\u0130") ? text.replaceAll("\u0130", "i") : text).toLowerCase();
|
|
@@ -4444,10 +3595,10 @@ async function suggestTableName(errorMessage, adapter) {
|
|
|
4444
3595
|
try {
|
|
4445
3596
|
const extractedTableName = extractTableNameFromError(errorMessage);
|
|
4446
3597
|
if (!extractedTableName) {
|
|
4447
|
-
const
|
|
3598
|
+
const allTables = await getAllTablesFromAdapter(adapter);
|
|
4448
3599
|
return {
|
|
4449
3600
|
suggestions: [],
|
|
4450
|
-
tables:
|
|
3601
|
+
tables: allTables
|
|
4451
3602
|
};
|
|
4452
3603
|
}
|
|
4453
3604
|
const allTables = await getAllTablesFromAdapter(adapter);
|
|
@@ -4495,7 +3646,7 @@ function extractTableNameFromError(errorMessage) {
|
|
|
4495
3646
|
async function getAllTablesFromAdapter(adapter) {
|
|
4496
3647
|
try {
|
|
4497
3648
|
const tables = await adapter.listTables();
|
|
4498
|
-
return tables.map((
|
|
3649
|
+
return tables.map((t) => t.name);
|
|
4499
3650
|
} catch (error) {
|
|
4500
3651
|
console.warn("Failed to list tables for suggestions:", error);
|
|
4501
3652
|
return [];
|
|
@@ -5519,149 +4670,37 @@ class DataExecutor {
|
|
|
5519
4670
|
// src/core/public.ts
|
|
5520
4671
|
init_schema_loader();
|
|
5521
4672
|
|
|
5522
|
-
// node_modules/zod/v3/external.js
|
|
5523
|
-
var exports_external = {};
|
|
5524
|
-
__export(exports_external, {
|
|
5525
|
-
void: () => voidType,
|
|
5526
|
-
util: () => util,
|
|
5527
|
-
unknown: () => unknownType,
|
|
5528
|
-
union: () => unionType,
|
|
5529
|
-
undefined: () => undefinedType,
|
|
5530
|
-
tuple: () => tupleType,
|
|
5531
|
-
transformer: () => effectsType,
|
|
5532
|
-
symbol: () => symbolType,
|
|
5533
|
-
string: () => stringType,
|
|
5534
|
-
strictObject: () => strictObjectType,
|
|
5535
|
-
setErrorMap: () => setErrorMap,
|
|
5536
|
-
set: () => setType,
|
|
5537
|
-
record: () => recordType,
|
|
5538
|
-
quotelessJson: () => quotelessJson,
|
|
5539
|
-
promise: () => promiseType,
|
|
5540
|
-
preprocess: () => preprocessType,
|
|
5541
|
-
pipeline: () => pipelineType,
|
|
5542
|
-
ostring: () => ostring,
|
|
5543
|
-
optional: () => optionalType,
|
|
5544
|
-
onumber: () => onumber,
|
|
5545
|
-
oboolean: () => oboolean,
|
|
5546
|
-
objectUtil: () => objectUtil,
|
|
5547
|
-
object: () => objectType,
|
|
5548
|
-
number: () => numberType,
|
|
5549
|
-
nullable: () => nullableType,
|
|
5550
|
-
null: () => nullType,
|
|
5551
|
-
never: () => neverType,
|
|
5552
|
-
nativeEnum: () => nativeEnumType,
|
|
5553
|
-
nan: () => nanType,
|
|
5554
|
-
map: () => mapType,
|
|
5555
|
-
makeIssue: () => makeIssue,
|
|
5556
|
-
literal: () => literalType,
|
|
5557
|
-
lazy: () => lazyType,
|
|
5558
|
-
late: () => late,
|
|
5559
|
-
isValid: () => isValid,
|
|
5560
|
-
isDirty: () => isDirty,
|
|
5561
|
-
isAsync: () => isAsync,
|
|
5562
|
-
isAborted: () => isAborted,
|
|
5563
|
-
intersection: () => intersectionType,
|
|
5564
|
-
instanceof: () => instanceOfType,
|
|
5565
|
-
getParsedType: () => getParsedType,
|
|
5566
|
-
getErrorMap: () => getErrorMap,
|
|
5567
|
-
function: () => functionType,
|
|
5568
|
-
enum: () => enumType,
|
|
5569
|
-
effect: () => effectsType,
|
|
5570
|
-
discriminatedUnion: () => discriminatedUnionType,
|
|
5571
|
-
defaultErrorMap: () => en_default,
|
|
5572
|
-
datetimeRegex: () => datetimeRegex,
|
|
5573
|
-
date: () => dateType,
|
|
5574
|
-
custom: () => custom,
|
|
5575
|
-
coerce: () => coerce,
|
|
5576
|
-
boolean: () => booleanType,
|
|
5577
|
-
bigint: () => bigIntType,
|
|
5578
|
-
array: () => arrayType,
|
|
5579
|
-
any: () => anyType,
|
|
5580
|
-
addIssueToContext: () => addIssueToContext,
|
|
5581
|
-
ZodVoid: () => ZodVoid,
|
|
5582
|
-
ZodUnknown: () => ZodUnknown,
|
|
5583
|
-
ZodUnion: () => ZodUnion,
|
|
5584
|
-
ZodUndefined: () => ZodUndefined,
|
|
5585
|
-
ZodType: () => ZodType,
|
|
5586
|
-
ZodTuple: () => ZodTuple,
|
|
5587
|
-
ZodTransformer: () => ZodEffects,
|
|
5588
|
-
ZodSymbol: () => ZodSymbol,
|
|
5589
|
-
ZodString: () => ZodString,
|
|
5590
|
-
ZodSet: () => ZodSet,
|
|
5591
|
-
ZodSchema: () => ZodType,
|
|
5592
|
-
ZodRecord: () => ZodRecord,
|
|
5593
|
-
ZodReadonly: () => ZodReadonly,
|
|
5594
|
-
ZodPromise: () => ZodPromise,
|
|
5595
|
-
ZodPipeline: () => ZodPipeline,
|
|
5596
|
-
ZodParsedType: () => ZodParsedType,
|
|
5597
|
-
ZodOptional: () => ZodOptional,
|
|
5598
|
-
ZodObject: () => ZodObject,
|
|
5599
|
-
ZodNumber: () => ZodNumber,
|
|
5600
|
-
ZodNullable: () => ZodNullable,
|
|
5601
|
-
ZodNull: () => ZodNull,
|
|
5602
|
-
ZodNever: () => ZodNever,
|
|
5603
|
-
ZodNativeEnum: () => ZodNativeEnum,
|
|
5604
|
-
ZodNaN: () => ZodNaN,
|
|
5605
|
-
ZodMap: () => ZodMap,
|
|
5606
|
-
ZodLiteral: () => ZodLiteral,
|
|
5607
|
-
ZodLazy: () => ZodLazy,
|
|
5608
|
-
ZodIssueCode: () => ZodIssueCode,
|
|
5609
|
-
ZodIntersection: () => ZodIntersection,
|
|
5610
|
-
ZodFunction: () => ZodFunction,
|
|
5611
|
-
ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
|
|
5612
|
-
ZodError: () => ZodError,
|
|
5613
|
-
ZodEnum: () => ZodEnum,
|
|
5614
|
-
ZodEffects: () => ZodEffects,
|
|
5615
|
-
ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
|
|
5616
|
-
ZodDefault: () => ZodDefault,
|
|
5617
|
-
ZodDate: () => ZodDate,
|
|
5618
|
-
ZodCatch: () => ZodCatch,
|
|
5619
|
-
ZodBranded: () => ZodBranded,
|
|
5620
|
-
ZodBoolean: () => ZodBoolean,
|
|
5621
|
-
ZodBigInt: () => ZodBigInt,
|
|
5622
|
-
ZodArray: () => ZodArray,
|
|
5623
|
-
ZodAny: () => ZodAny,
|
|
5624
|
-
Schema: () => ZodType,
|
|
5625
|
-
ParseStatus: () => ParseStatus,
|
|
5626
|
-
OK: () => OK,
|
|
5627
|
-
NEVER: () => NEVER,
|
|
5628
|
-
INVALID: () => INVALID,
|
|
5629
|
-
EMPTY_PATH: () => EMPTY_PATH,
|
|
5630
|
-
DIRTY: () => DIRTY,
|
|
5631
|
-
BRAND: () => BRAND
|
|
5632
|
-
});
|
|
5633
|
-
|
|
5634
4673
|
// node_modules/zod/v3/helpers/util.js
|
|
5635
4674
|
var util;
|
|
5636
|
-
(function(
|
|
5637
|
-
|
|
4675
|
+
(function(util) {
|
|
4676
|
+
util.assertEqual = (_) => {};
|
|
5638
4677
|
function assertIs(_arg) {}
|
|
5639
|
-
|
|
4678
|
+
util.assertIs = assertIs;
|
|
5640
4679
|
function assertNever(_x) {
|
|
5641
4680
|
throw new Error;
|
|
5642
4681
|
}
|
|
5643
|
-
|
|
5644
|
-
|
|
4682
|
+
util.assertNever = assertNever;
|
|
4683
|
+
util.arrayToEnum = (items) => {
|
|
5645
4684
|
const obj = {};
|
|
5646
4685
|
for (const item of items) {
|
|
5647
4686
|
obj[item] = item;
|
|
5648
4687
|
}
|
|
5649
4688
|
return obj;
|
|
5650
4689
|
};
|
|
5651
|
-
|
|
5652
|
-
const validKeys =
|
|
4690
|
+
util.getValidEnumValues = (obj) => {
|
|
4691
|
+
const validKeys = util.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
|
5653
4692
|
const filtered = {};
|
|
5654
4693
|
for (const k of validKeys) {
|
|
5655
4694
|
filtered[k] = obj[k];
|
|
5656
4695
|
}
|
|
5657
|
-
return
|
|
4696
|
+
return util.objectValues(filtered);
|
|
5658
4697
|
};
|
|
5659
|
-
|
|
5660
|
-
return
|
|
4698
|
+
util.objectValues = (obj) => {
|
|
4699
|
+
return util.objectKeys(obj).map(function(e) {
|
|
5661
4700
|
return obj[e];
|
|
5662
4701
|
});
|
|
5663
4702
|
};
|
|
5664
|
-
|
|
4703
|
+
util.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
|
|
5665
4704
|
const keys = [];
|
|
5666
4705
|
for (const key in object) {
|
|
5667
4706
|
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
@@ -5670,19 +4709,19 @@ var util;
|
|
|
5670
4709
|
}
|
|
5671
4710
|
return keys;
|
|
5672
4711
|
};
|
|
5673
|
-
|
|
4712
|
+
util.find = (arr, checker) => {
|
|
5674
4713
|
for (const item of arr) {
|
|
5675
4714
|
if (checker(item))
|
|
5676
4715
|
return item;
|
|
5677
4716
|
}
|
|
5678
4717
|
return;
|
|
5679
4718
|
};
|
|
5680
|
-
|
|
4719
|
+
util.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
|
|
5681
4720
|
function joinValues(array, separator = " | ") {
|
|
5682
4721
|
return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
|
|
5683
4722
|
}
|
|
5684
|
-
|
|
5685
|
-
|
|
4723
|
+
util.joinValues = joinValues;
|
|
4724
|
+
util.jsonStringifyReplacer = (_, value) => {
|
|
5686
4725
|
if (typeof value === "bigint") {
|
|
5687
4726
|
return value.toString();
|
|
5688
4727
|
}
|
|
@@ -5690,8 +4729,8 @@ var util;
|
|
|
5690
4729
|
};
|
|
5691
4730
|
})(util || (util = {}));
|
|
5692
4731
|
var objectUtil;
|
|
5693
|
-
(function(
|
|
5694
|
-
|
|
4732
|
+
(function(objectUtil) {
|
|
4733
|
+
objectUtil.mergeShapes = (first, second) => {
|
|
5695
4734
|
return {
|
|
5696
4735
|
...first,
|
|
5697
4736
|
...second
|
|
@@ -5721,8 +4760,8 @@ var ZodParsedType = util.arrayToEnum([
|
|
|
5721
4760
|
"set"
|
|
5722
4761
|
]);
|
|
5723
4762
|
var getParsedType = (data) => {
|
|
5724
|
-
const
|
|
5725
|
-
switch (
|
|
4763
|
+
const t = typeof data;
|
|
4764
|
+
switch (t) {
|
|
5726
4765
|
case "undefined":
|
|
5727
4766
|
return ZodParsedType.undefined;
|
|
5728
4767
|
case "string":
|
|
@@ -5781,11 +4820,6 @@ var ZodIssueCode = util.arrayToEnum([
|
|
|
5781
4820
|
"not_multiple_of",
|
|
5782
4821
|
"not_finite"
|
|
5783
4822
|
]);
|
|
5784
|
-
var quotelessJson = (obj) => {
|
|
5785
|
-
const json = JSON.stringify(obj, null, 2);
|
|
5786
|
-
return json.replace(/"([^"]+)":/g, "$1:");
|
|
5787
|
-
};
|
|
5788
|
-
|
|
5789
4823
|
class ZodError extends Error {
|
|
5790
4824
|
get errors() {
|
|
5791
4825
|
return this.issues;
|
|
@@ -5986,12 +5020,10 @@ var en_default = errorMap;
|
|
|
5986
5020
|
|
|
5987
5021
|
// node_modules/zod/v3/errors.js
|
|
5988
5022
|
var overrideErrorMap = en_default;
|
|
5989
|
-
function setErrorMap(map) {
|
|
5990
|
-
overrideErrorMap = map;
|
|
5991
|
-
}
|
|
5992
5023
|
function getErrorMap() {
|
|
5993
5024
|
return overrideErrorMap;
|
|
5994
5025
|
}
|
|
5026
|
+
|
|
5995
5027
|
// node_modules/zod/v3/helpers/parseUtil.js
|
|
5996
5028
|
var makeIssue = (params) => {
|
|
5997
5029
|
const { data, path, errorMaps, issueData } = params;
|
|
@@ -6018,7 +5050,6 @@ var makeIssue = (params) => {
|
|
|
6018
5050
|
message: errorMessage
|
|
6019
5051
|
};
|
|
6020
5052
|
};
|
|
6021
|
-
var EMPTY_PATH = [];
|
|
6022
5053
|
function addIssueToContext(ctx, issueData) {
|
|
6023
5054
|
const overrideMap = getErrorMap();
|
|
6024
5055
|
const issue = makeIssue({
|
|
@@ -6098,11 +5129,12 @@ var isAborted = (x) => x.status === "aborted";
|
|
|
6098
5129
|
var isDirty = (x) => x.status === "dirty";
|
|
6099
5130
|
var isValid = (x) => x.status === "valid";
|
|
6100
5131
|
var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
5132
|
+
|
|
6101
5133
|
// node_modules/zod/v3/helpers/errorUtil.js
|
|
6102
5134
|
var errorUtil;
|
|
6103
|
-
(function(
|
|
6104
|
-
|
|
6105
|
-
|
|
5135
|
+
(function(errorUtil) {
|
|
5136
|
+
errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
5137
|
+
errorUtil.toString = (message) => typeof message === "string" ? message : message?.message;
|
|
6106
5138
|
})(errorUtil || (errorUtil = {}));
|
|
6107
5139
|
|
|
6108
5140
|
// node_modules/zod/v3/types.js
|
|
@@ -6147,12 +5179,12 @@ var handleResult = (ctx, result) => {
|
|
|
6147
5179
|
function processCreateParams(params) {
|
|
6148
5180
|
if (!params)
|
|
6149
5181
|
return {};
|
|
6150
|
-
const { errorMap
|
|
6151
|
-
if (
|
|
5182
|
+
const { errorMap, invalid_type_error, required_error, description } = params;
|
|
5183
|
+
if (errorMap && (invalid_type_error || required_error)) {
|
|
6152
5184
|
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
6153
5185
|
}
|
|
6154
|
-
if (
|
|
6155
|
-
return { errorMap
|
|
5186
|
+
if (errorMap)
|
|
5187
|
+
return { errorMap, description };
|
|
6156
5188
|
const customMap = (iss, ctx) => {
|
|
6157
5189
|
const { message } = params;
|
|
6158
5190
|
if (iss.code === "invalid_enum_value") {
|
|
@@ -6539,11 +5571,11 @@ class ZodString extends ZodType {
|
|
|
6539
5571
|
}
|
|
6540
5572
|
const parsedType = this._getType(input);
|
|
6541
5573
|
if (parsedType !== ZodParsedType.string) {
|
|
6542
|
-
const
|
|
6543
|
-
addIssueToContext(
|
|
5574
|
+
const ctx = this._getOrReturnCtx(input);
|
|
5575
|
+
addIssueToContext(ctx, {
|
|
6544
5576
|
code: ZodIssueCode.invalid_type,
|
|
6545
5577
|
expected: ZodParsedType.string,
|
|
6546
|
-
received:
|
|
5578
|
+
received: ctx.parsedType
|
|
6547
5579
|
});
|
|
6548
5580
|
return INVALID;
|
|
6549
5581
|
}
|
|
@@ -7097,11 +6129,11 @@ class ZodNumber extends ZodType {
|
|
|
7097
6129
|
}
|
|
7098
6130
|
const parsedType = this._getType(input);
|
|
7099
6131
|
if (parsedType !== ZodParsedType.number) {
|
|
7100
|
-
const
|
|
7101
|
-
addIssueToContext(
|
|
6132
|
+
const ctx = this._getOrReturnCtx(input);
|
|
6133
|
+
addIssueToContext(ctx, {
|
|
7102
6134
|
code: ZodIssueCode.invalid_type,
|
|
7103
6135
|
expected: ZodParsedType.number,
|
|
7104
|
-
received:
|
|
6136
|
+
received: ctx.parsedType
|
|
7105
6137
|
});
|
|
7106
6138
|
return INVALID;
|
|
7107
6139
|
}
|
|
@@ -7523,17 +6555,17 @@ class ZodDate extends ZodType {
|
|
|
7523
6555
|
}
|
|
7524
6556
|
const parsedType = this._getType(input);
|
|
7525
6557
|
if (parsedType !== ZodParsedType.date) {
|
|
7526
|
-
const
|
|
7527
|
-
addIssueToContext(
|
|
6558
|
+
const ctx = this._getOrReturnCtx(input);
|
|
6559
|
+
addIssueToContext(ctx, {
|
|
7528
6560
|
code: ZodIssueCode.invalid_type,
|
|
7529
6561
|
expected: ZodParsedType.date,
|
|
7530
|
-
received:
|
|
6562
|
+
received: ctx.parsedType
|
|
7531
6563
|
});
|
|
7532
6564
|
return INVALID;
|
|
7533
6565
|
}
|
|
7534
6566
|
if (Number.isNaN(input.data.getTime())) {
|
|
7535
|
-
const
|
|
7536
|
-
addIssueToContext(
|
|
6567
|
+
const ctx = this._getOrReturnCtx(input);
|
|
6568
|
+
addIssueToContext(ctx, {
|
|
7537
6569
|
code: ZodIssueCode.invalid_date
|
|
7538
6570
|
});
|
|
7539
6571
|
return INVALID;
|
|
@@ -7821,8 +6853,8 @@ class ZodArray extends ZodType {
|
|
|
7821
6853
|
if (ctx.common.async) {
|
|
7822
6854
|
return Promise.all([...ctx.data].map((item, i) => {
|
|
7823
6855
|
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
7824
|
-
})).then((
|
|
7825
|
-
return ParseStatus.mergeArray(status,
|
|
6856
|
+
})).then((result) => {
|
|
6857
|
+
return ParseStatus.mergeArray(status, result);
|
|
7826
6858
|
});
|
|
7827
6859
|
}
|
|
7828
6860
|
const result = [...ctx.data].map((item, i) => {
|
|
@@ -7910,11 +6942,11 @@ class ZodObject extends ZodType {
|
|
|
7910
6942
|
_parse(input) {
|
|
7911
6943
|
const parsedType = this._getType(input);
|
|
7912
6944
|
if (parsedType !== ZodParsedType.object) {
|
|
7913
|
-
const
|
|
7914
|
-
addIssueToContext(
|
|
6945
|
+
const ctx = this._getOrReturnCtx(input);
|
|
6946
|
+
addIssueToContext(ctx, {
|
|
7915
6947
|
code: ZodIssueCode.invalid_type,
|
|
7916
6948
|
expected: ZodParsedType.object,
|
|
7917
|
-
received:
|
|
6949
|
+
received: ctx.parsedType
|
|
7918
6950
|
});
|
|
7919
6951
|
return INVALID;
|
|
7920
6952
|
}
|
|
@@ -8218,7 +7250,7 @@ class ZodUnion extends ZodType {
|
|
|
8218
7250
|
ctx.common.issues.push(...dirty.ctx.common.issues);
|
|
8219
7251
|
return dirty.result;
|
|
8220
7252
|
}
|
|
8221
|
-
const unionErrors = issues.map((
|
|
7253
|
+
const unionErrors = issues.map((issues) => new ZodError(issues));
|
|
8222
7254
|
addIssueToContext(ctx, {
|
|
8223
7255
|
code: ZodIssueCode.invalid_union,
|
|
8224
7256
|
unionErrors
|
|
@@ -8658,9 +7690,9 @@ class ZodSet extends ZodType {
|
|
|
8658
7690
|
}
|
|
8659
7691
|
}
|
|
8660
7692
|
const valueType = this._def.valueType;
|
|
8661
|
-
function finalizeSet(
|
|
7693
|
+
function finalizeSet(elements) {
|
|
8662
7694
|
const parsedSet = new Set;
|
|
8663
|
-
for (const element of
|
|
7695
|
+
for (const element of elements) {
|
|
8664
7696
|
if (element.status === "aborted")
|
|
8665
7697
|
return INVALID;
|
|
8666
7698
|
if (element.status === "dirty")
|
|
@@ -8671,7 +7703,7 @@ class ZodSet extends ZodType {
|
|
|
8671
7703
|
}
|
|
8672
7704
|
const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
8673
7705
|
if (ctx.common.async) {
|
|
8674
|
-
return Promise.all(elements).then((
|
|
7706
|
+
return Promise.all(elements).then((elements) => finalizeSet(elements));
|
|
8675
7707
|
} else {
|
|
8676
7708
|
return finalizeSet(elements);
|
|
8677
7709
|
}
|
|
@@ -9024,11 +8056,11 @@ class ZodEffects extends ZodType {
|
|
|
9024
8056
|
if (effect.type === "preprocess") {
|
|
9025
8057
|
const processed = effect.transform(ctx.data, checkCtx);
|
|
9026
8058
|
if (ctx.common.async) {
|
|
9027
|
-
return Promise.resolve(processed).then(async (
|
|
8059
|
+
return Promise.resolve(processed).then(async (processed) => {
|
|
9028
8060
|
if (status.value === "aborted")
|
|
9029
8061
|
return INVALID;
|
|
9030
8062
|
const result = await this._def.schema._parseAsync({
|
|
9031
|
-
data:
|
|
8063
|
+
data: processed,
|
|
9032
8064
|
path: ctx.path,
|
|
9033
8065
|
parent: ctx
|
|
9034
8066
|
});
|
|
@@ -9220,10 +8252,10 @@ class ZodCatch extends ZodType {
|
|
|
9220
8252
|
}
|
|
9221
8253
|
});
|
|
9222
8254
|
if (isAsync(result)) {
|
|
9223
|
-
return result.then((
|
|
8255
|
+
return result.then((result) => {
|
|
9224
8256
|
return {
|
|
9225
8257
|
status: "valid",
|
|
9226
|
-
value:
|
|
8258
|
+
value: result.status === "valid" ? result.value : this._def.catchValue({
|
|
9227
8259
|
get error() {
|
|
9228
8260
|
return new ZodError(newCtx.common.issues);
|
|
9229
8261
|
},
|
|
@@ -9372,78 +8404,48 @@ ZodReadonly.create = (type, params) => {
|
|
|
9372
8404
|
...processCreateParams(params)
|
|
9373
8405
|
});
|
|
9374
8406
|
};
|
|
9375
|
-
function cleanParams(params, data) {
|
|
9376
|
-
const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
|
|
9377
|
-
const p2 = typeof p === "string" ? { message: p } : p;
|
|
9378
|
-
return p2;
|
|
9379
|
-
}
|
|
9380
|
-
function custom(check, _params = {}, fatal) {
|
|
9381
|
-
if (check)
|
|
9382
|
-
return ZodAny.create().superRefine((data, ctx) => {
|
|
9383
|
-
const r = check(data);
|
|
9384
|
-
if (r instanceof Promise) {
|
|
9385
|
-
return r.then((r2) => {
|
|
9386
|
-
if (!r2) {
|
|
9387
|
-
const params = cleanParams(_params, data);
|
|
9388
|
-
const _fatal = params.fatal ?? fatal ?? true;
|
|
9389
|
-
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
9390
|
-
}
|
|
9391
|
-
});
|
|
9392
|
-
}
|
|
9393
|
-
if (!r) {
|
|
9394
|
-
const params = cleanParams(_params, data);
|
|
9395
|
-
const _fatal = params.fatal ?? fatal ?? true;
|
|
9396
|
-
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
9397
|
-
}
|
|
9398
|
-
return;
|
|
9399
|
-
});
|
|
9400
|
-
return ZodAny.create();
|
|
9401
|
-
}
|
|
9402
8407
|
var late = {
|
|
9403
8408
|
object: ZodObject.lazycreate
|
|
9404
8409
|
};
|
|
9405
8410
|
var ZodFirstPartyTypeKind;
|
|
9406
|
-
(function(
|
|
9407
|
-
|
|
9408
|
-
|
|
9409
|
-
|
|
9410
|
-
|
|
9411
|
-
|
|
9412
|
-
|
|
9413
|
-
|
|
9414
|
-
|
|
9415
|
-
|
|
9416
|
-
|
|
9417
|
-
|
|
9418
|
-
|
|
9419
|
-
|
|
9420
|
-
|
|
9421
|
-
|
|
9422
|
-
|
|
9423
|
-
|
|
9424
|
-
|
|
9425
|
-
|
|
9426
|
-
|
|
9427
|
-
|
|
9428
|
-
|
|
9429
|
-
|
|
9430
|
-
|
|
9431
|
-
|
|
9432
|
-
|
|
9433
|
-
|
|
9434
|
-
|
|
9435
|
-
|
|
9436
|
-
|
|
9437
|
-
|
|
9438
|
-
|
|
9439
|
-
|
|
9440
|
-
|
|
9441
|
-
|
|
9442
|
-
|
|
8411
|
+
(function(ZodFirstPartyTypeKind) {
|
|
8412
|
+
ZodFirstPartyTypeKind["ZodString"] = "ZodString";
|
|
8413
|
+
ZodFirstPartyTypeKind["ZodNumber"] = "ZodNumber";
|
|
8414
|
+
ZodFirstPartyTypeKind["ZodNaN"] = "ZodNaN";
|
|
8415
|
+
ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
|
|
8416
|
+
ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
|
|
8417
|
+
ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
|
|
8418
|
+
ZodFirstPartyTypeKind["ZodSymbol"] = "ZodSymbol";
|
|
8419
|
+
ZodFirstPartyTypeKind["ZodUndefined"] = "ZodUndefined";
|
|
8420
|
+
ZodFirstPartyTypeKind["ZodNull"] = "ZodNull";
|
|
8421
|
+
ZodFirstPartyTypeKind["ZodAny"] = "ZodAny";
|
|
8422
|
+
ZodFirstPartyTypeKind["ZodUnknown"] = "ZodUnknown";
|
|
8423
|
+
ZodFirstPartyTypeKind["ZodNever"] = "ZodNever";
|
|
8424
|
+
ZodFirstPartyTypeKind["ZodVoid"] = "ZodVoid";
|
|
8425
|
+
ZodFirstPartyTypeKind["ZodArray"] = "ZodArray";
|
|
8426
|
+
ZodFirstPartyTypeKind["ZodObject"] = "ZodObject";
|
|
8427
|
+
ZodFirstPartyTypeKind["ZodUnion"] = "ZodUnion";
|
|
8428
|
+
ZodFirstPartyTypeKind["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
|
|
8429
|
+
ZodFirstPartyTypeKind["ZodIntersection"] = "ZodIntersection";
|
|
8430
|
+
ZodFirstPartyTypeKind["ZodTuple"] = "ZodTuple";
|
|
8431
|
+
ZodFirstPartyTypeKind["ZodRecord"] = "ZodRecord";
|
|
8432
|
+
ZodFirstPartyTypeKind["ZodMap"] = "ZodMap";
|
|
8433
|
+
ZodFirstPartyTypeKind["ZodSet"] = "ZodSet";
|
|
8434
|
+
ZodFirstPartyTypeKind["ZodFunction"] = "ZodFunction";
|
|
8435
|
+
ZodFirstPartyTypeKind["ZodLazy"] = "ZodLazy";
|
|
8436
|
+
ZodFirstPartyTypeKind["ZodLiteral"] = "ZodLiteral";
|
|
8437
|
+
ZodFirstPartyTypeKind["ZodEnum"] = "ZodEnum";
|
|
8438
|
+
ZodFirstPartyTypeKind["ZodEffects"] = "ZodEffects";
|
|
8439
|
+
ZodFirstPartyTypeKind["ZodNativeEnum"] = "ZodNativeEnum";
|
|
8440
|
+
ZodFirstPartyTypeKind["ZodOptional"] = "ZodOptional";
|
|
8441
|
+
ZodFirstPartyTypeKind["ZodNullable"] = "ZodNullable";
|
|
8442
|
+
ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
|
|
8443
|
+
ZodFirstPartyTypeKind["ZodCatch"] = "ZodCatch";
|
|
8444
|
+
ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
|
|
8445
|
+
ZodFirstPartyTypeKind["ZodBranded"] = "ZodBranded";
|
|
8446
|
+
ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
|
|
8447
|
+
ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
|
|
9443
8448
|
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
9444
|
-
var instanceOfType = (cls, params = {
|
|
9445
|
-
message: `Input not instance of ${cls.name}`
|
|
9446
|
-
}) => custom((data) => data instanceof cls, params);
|
|
9447
8449
|
var stringType = ZodString.create;
|
|
9448
8450
|
var numberType = ZodNumber.create;
|
|
9449
8451
|
var nanType = ZodNaN.create;
|
|
@@ -9478,56 +8480,42 @@ var optionalType = ZodOptional.create;
|
|
|
9478
8480
|
var nullableType = ZodNullable.create;
|
|
9479
8481
|
var preprocessType = ZodEffects.createWithPreprocess;
|
|
9480
8482
|
var pipelineType = ZodPipeline.create;
|
|
9481
|
-
var ostring = () => stringType().optional();
|
|
9482
|
-
var onumber = () => numberType().optional();
|
|
9483
|
-
var oboolean = () => booleanType().optional();
|
|
9484
|
-
var coerce = {
|
|
9485
|
-
string: (arg) => ZodString.create({ ...arg, coerce: true }),
|
|
9486
|
-
number: (arg) => ZodNumber.create({ ...arg, coerce: true }),
|
|
9487
|
-
boolean: (arg) => ZodBoolean.create({
|
|
9488
|
-
...arg,
|
|
9489
|
-
coerce: true
|
|
9490
|
-
}),
|
|
9491
|
-
bigint: (arg) => ZodBigInt.create({ ...arg, coerce: true }),
|
|
9492
|
-
date: (arg) => ZodDate.create({ ...arg, coerce: true })
|
|
9493
|
-
};
|
|
9494
|
-
var NEVER = INVALID;
|
|
9495
8483
|
// src/utils/validation.ts
|
|
9496
|
-
var EnvRefSchema =
|
|
9497
|
-
$env:
|
|
8484
|
+
var EnvRefSchema = objectType({
|
|
8485
|
+
$env: stringType()
|
|
9498
8486
|
}).strict();
|
|
9499
|
-
var StringOrEnvRef =
|
|
9500
|
-
var NumberOrEnvRef =
|
|
9501
|
-
var OptStringOrEnvRef =
|
|
9502
|
-
var OptNumberOrEnvRef =
|
|
8487
|
+
var StringOrEnvRef = unionType([stringType().min(1), EnvRefSchema]);
|
|
8488
|
+
var NumberOrEnvRef = unionType([numberType().int().min(1).max(65535), EnvRefSchema]);
|
|
8489
|
+
var OptStringOrEnvRef = unionType([stringType(), EnvRefSchema]).optional().default("");
|
|
8490
|
+
var OptNumberOrEnvRef = unionType([numberType().int(), EnvRefSchema]).optional().default(27017);
|
|
9503
8491
|
var MIN_CONNECTION_TIMEOUT_MS = 100;
|
|
9504
8492
|
var MAX_CONNECTION_TIMEOUT_MS = 600000;
|
|
9505
8493
|
var MIN_STATEMENT_TIMEOUT_MS = 0;
|
|
9506
8494
|
var MAX_STATEMENT_TIMEOUT_MS = 3600000;
|
|
9507
8495
|
var TimeoutField = {
|
|
9508
|
-
timeout:
|
|
9509
|
-
statementTimeout:
|
|
8496
|
+
timeout: numberType().int().min(MIN_CONNECTION_TIMEOUT_MS).max(MAX_CONNECTION_TIMEOUT_MS).optional(),
|
|
8497
|
+
statementTimeout: numberType().int().min(MIN_STATEMENT_TIMEOUT_MS).max(MAX_STATEMENT_TIMEOUT_MS).optional()
|
|
9510
8498
|
};
|
|
9511
|
-
var MongoDBConnectionConfigSchema =
|
|
9512
|
-
system:
|
|
9513
|
-
uri:
|
|
8499
|
+
var MongoDBConnectionConfigSchema = objectType({
|
|
8500
|
+
system: literalType("mongodb"),
|
|
8501
|
+
uri: unionType([stringType(), EnvRefSchema]).optional(),
|
|
9514
8502
|
host: OptStringOrEnvRef,
|
|
9515
8503
|
port: OptNumberOrEnvRef,
|
|
9516
8504
|
user: OptStringOrEnvRef,
|
|
9517
8505
|
password: OptStringOrEnvRef,
|
|
9518
8506
|
database: OptStringOrEnvRef,
|
|
9519
|
-
authSource:
|
|
9520
|
-
replicaSet:
|
|
9521
|
-
tls:
|
|
9522
|
-
srv:
|
|
8507
|
+
authSource: unionType([stringType(), EnvRefSchema]).optional(),
|
|
8508
|
+
replicaSet: unionType([stringType(), EnvRefSchema]).optional(),
|
|
8509
|
+
tls: booleanType().optional(),
|
|
8510
|
+
srv: booleanType().optional().default(false),
|
|
9523
8511
|
...TimeoutField
|
|
9524
8512
|
});
|
|
9525
|
-
var SqlConnectionConfigSchema =
|
|
9526
|
-
system:
|
|
8513
|
+
var SqlConnectionConfigSchema = objectType({
|
|
8514
|
+
system: enumType(["postgresql", "mysql", "mariadb"]),
|
|
9527
8515
|
host: StringOrEnvRef,
|
|
9528
8516
|
port: NumberOrEnvRef,
|
|
9529
8517
|
user: StringOrEnvRef,
|
|
9530
|
-
password:
|
|
8518
|
+
password: unionType([stringType(), EnvRefSchema]).default(""),
|
|
9531
8519
|
database: StringOrEnvRef,
|
|
9532
8520
|
...TimeoutField
|
|
9533
8521
|
});
|
|
@@ -9546,58 +8534,58 @@ function isSqliteMemoryTarget(value) {
|
|
|
9546
8534
|
const query = queryStart === -1 ? "" : withoutScheme.slice(queryStart + 1);
|
|
9547
8535
|
return new URLSearchParams(query).get("mode")?.toLowerCase() === "memory";
|
|
9548
8536
|
}
|
|
9549
|
-
var SqliteConnectionConfigSchema =
|
|
9550
|
-
system:
|
|
9551
|
-
file:
|
|
8537
|
+
var SqliteConnectionConfigSchema = objectType({
|
|
8538
|
+
system: literalType("sqlite"),
|
|
8539
|
+
file: unionType([stringType().min(1), EnvRefSchema]).superRefine((value, ctx) => {
|
|
9552
8540
|
if (typeof value === "string" && isSqliteMemoryTarget(value)) {
|
|
9553
|
-
ctx.addIssue({ code:
|
|
8541
|
+
ctx.addIssue({ code: ZodIssueCode.custom, message: SQLITE_MEMORY_TARGET_MESSAGE });
|
|
9554
8542
|
}
|
|
9555
8543
|
}),
|
|
9556
8544
|
host: OptStringOrEnvRef,
|
|
9557
|
-
port:
|
|
8545
|
+
port: unionType([numberType().int(), EnvRefSchema]).optional().default(0),
|
|
9558
8546
|
user: OptStringOrEnvRef,
|
|
9559
|
-
password:
|
|
8547
|
+
password: unionType([stringType(), EnvRefSchema]).optional().default(""),
|
|
9560
8548
|
database: OptStringOrEnvRef,
|
|
9561
8549
|
...TimeoutField
|
|
9562
8550
|
});
|
|
9563
|
-
var RedisConnectionConfigSchema =
|
|
9564
|
-
system:
|
|
8551
|
+
var RedisConnectionConfigSchema = objectType({
|
|
8552
|
+
system: literalType("redis"),
|
|
9565
8553
|
host: StringOrEnvRef,
|
|
9566
8554
|
port: NumberOrEnvRef,
|
|
9567
8555
|
user: OptStringOrEnvRef,
|
|
9568
|
-
password:
|
|
8556
|
+
password: unionType([stringType(), EnvRefSchema]).optional().default(""),
|
|
9569
8557
|
database: OptStringOrEnvRef,
|
|
9570
8558
|
...TimeoutField
|
|
9571
8559
|
});
|
|
9572
|
-
var ElasticsearchConnectionConfigSchema =
|
|
9573
|
-
system:
|
|
9574
|
-
protocol:
|
|
8560
|
+
var ElasticsearchConnectionConfigSchema = objectType({
|
|
8561
|
+
system: literalType("elasticsearch"),
|
|
8562
|
+
protocol: enumType(["http", "https"]).optional().default("https"),
|
|
9575
8563
|
host: OptStringOrEnvRef,
|
|
9576
|
-
port:
|
|
8564
|
+
port: unionType([numberType().int(), EnvRefSchema]).optional().default(9200),
|
|
9577
8565
|
user: OptStringOrEnvRef,
|
|
9578
|
-
password:
|
|
8566
|
+
password: unionType([stringType(), EnvRefSchema]).optional().default(""),
|
|
9579
8567
|
database: OptStringOrEnvRef,
|
|
9580
|
-
nodes:
|
|
9581
|
-
cloudId:
|
|
9582
|
-
apiKey:
|
|
9583
|
-
caPath:
|
|
9584
|
-
rejectUnauthorized:
|
|
8568
|
+
nodes: arrayType(stringType()).optional(),
|
|
8569
|
+
cloudId: unionType([stringType(), EnvRefSchema]).optional(),
|
|
8570
|
+
apiKey: unionType([stringType(), EnvRefSchema]).optional(),
|
|
8571
|
+
caPath: stringType().optional(),
|
|
8572
|
+
rejectUnauthorized: booleanType().optional().default(true),
|
|
9585
8573
|
...TimeoutField
|
|
9586
8574
|
});
|
|
9587
|
-
var ConnectionConfigSchema =
|
|
8575
|
+
var ConnectionConfigSchema = unionType([
|
|
9588
8576
|
SqlConnectionConfigSchema,
|
|
9589
8577
|
SqliteConnectionConfigSchema,
|
|
9590
8578
|
MongoDBConnectionConfigSchema,
|
|
9591
8579
|
RedisConnectionConfigSchema,
|
|
9592
8580
|
ElasticsearchConnectionConfigSchema
|
|
9593
8581
|
]);
|
|
9594
|
-
var PermissionSchema =
|
|
9595
|
-
var EnvironmentLabelSchema =
|
|
9596
|
-
var MetadataSchema =
|
|
9597
|
-
createdAt:
|
|
9598
|
-
version:
|
|
9599
|
-
schemaLastUpdated:
|
|
9600
|
-
schemaTableCount:
|
|
8582
|
+
var PermissionSchema = enumType(["query-only", "read-write", "data-admin", "admin"]).default("query-only");
|
|
8583
|
+
var EnvironmentLabelSchema = stringType().trim().transform((value) => value || undefined).optional();
|
|
8584
|
+
var MetadataSchema = objectType({
|
|
8585
|
+
createdAt: stringType().datetime().optional(),
|
|
8586
|
+
version: stringType().default("1.0"),
|
|
8587
|
+
schemaLastUpdated: stringType().datetime().optional(),
|
|
8588
|
+
schemaTableCount: numberType().int().nonnegative().optional()
|
|
9601
8589
|
}).optional().default({});
|
|
9602
8590
|
var BLACKLIST_KEY_ALIASES = {
|
|
9603
8591
|
indices: "tables",
|
|
@@ -9605,35 +8593,35 @@ var BLACKLIST_KEY_ALIASES = {
|
|
|
9605
8593
|
fields: "columns",
|
|
9606
8594
|
keys: "tables"
|
|
9607
8595
|
};
|
|
9608
|
-
var BlacklistConfigSchema =
|
|
9609
|
-
tables:
|
|
9610
|
-
columns:
|
|
8596
|
+
var BlacklistConfigSchema = objectType({
|
|
8597
|
+
tables: arrayType(stringType()).default([]),
|
|
8598
|
+
columns: recordType(arrayType(stringType())).default({})
|
|
9611
8599
|
}).passthrough().superRefine((value, ctx) => {
|
|
9612
8600
|
for (const [wrong, right] of Object.entries(BLACKLIST_KEY_ALIASES)) {
|
|
9613
8601
|
if (wrong in value) {
|
|
9614
8602
|
ctx.addIssue({
|
|
9615
|
-
code:
|
|
8603
|
+
code: ZodIssueCode.custom,
|
|
9616
8604
|
path: [wrong],
|
|
9617
8605
|
message: `blacklist.${wrong} is not a setting and would be silently ignored \u2014 did you mean blacklist.${right}?`
|
|
9618
8606
|
});
|
|
9619
8607
|
}
|
|
9620
8608
|
}
|
|
9621
8609
|
}).transform((value) => ({ tables: value.tables, columns: value.columns })).optional().default({ tables: [], columns: {} });
|
|
9622
|
-
var RedisMaskRuleSchema =
|
|
9623
|
-
keyPattern:
|
|
9624
|
-
fields:
|
|
8610
|
+
var RedisMaskRuleSchema = objectType({
|
|
8611
|
+
keyPattern: stringType().min(1),
|
|
8612
|
+
fields: arrayType(stringType()).optional()
|
|
9625
8613
|
});
|
|
9626
|
-
var RedisConfigSchema =
|
|
9627
|
-
mask:
|
|
8614
|
+
var RedisConfigSchema = objectType({
|
|
8615
|
+
mask: arrayType(RedisMaskRuleSchema).default([])
|
|
9628
8616
|
}).optional();
|
|
9629
8617
|
var DEFAULT_AUDIT_ROTATION = { max_bytes: 10485760, max_entries: 1e4 };
|
|
9630
|
-
var AuditRotationConfigSchema =
|
|
9631
|
-
max_bytes:
|
|
9632
|
-
max_entries:
|
|
8618
|
+
var AuditRotationConfigSchema = objectType({
|
|
8619
|
+
max_bytes: numberType().int().positive().default(DEFAULT_AUDIT_ROTATION.max_bytes),
|
|
8620
|
+
max_entries: numberType().int().positive().default(DEFAULT_AUDIT_ROTATION.max_entries)
|
|
9633
8621
|
}).optional().default({ ...DEFAULT_AUDIT_ROTATION });
|
|
9634
|
-
var AuditConfigSchema =
|
|
9635
|
-
enabled:
|
|
9636
|
-
strict:
|
|
8622
|
+
var AuditConfigSchema = objectType({
|
|
8623
|
+
enabled: booleanType().default(true),
|
|
8624
|
+
strict: booleanType().default(false),
|
|
9637
8625
|
rotation: AuditRotationConfigSchema
|
|
9638
8626
|
}).refine((audit) => !(audit.strict && !audit.enabled), {
|
|
9639
8627
|
message: "audit.strict requires audit.enabled: with audit off there is nothing to write, so " + "strict would refuse nothing. Enable audit, or turn strict off.",
|
|
@@ -9643,10 +8631,10 @@ var AuditConfigSchema = exports_external.object({
|
|
|
9643
8631
|
strict: false,
|
|
9644
8632
|
rotation: { ...DEFAULT_AUDIT_ROTATION }
|
|
9645
8633
|
});
|
|
9646
|
-
var DbcliConfigSchema =
|
|
8634
|
+
var DbcliConfigSchema = objectType({
|
|
9647
8635
|
connection: ConnectionConfigSchema,
|
|
9648
8636
|
permission: PermissionSchema,
|
|
9649
|
-
schema:
|
|
8637
|
+
schema: recordType(anyType()).optional().default({}),
|
|
9650
8638
|
metadata: MetadataSchema,
|
|
9651
8639
|
blacklist: BlacklistConfigSchema,
|
|
9652
8640
|
audit: AuditConfigSchema,
|
|
@@ -9654,41 +8642,41 @@ var DbcliConfigSchema = exports_external.object({
|
|
|
9654
8642
|
});
|
|
9655
8643
|
var SqlNamedConnectionSchema = SqlConnectionConfigSchema.extend({
|
|
9656
8644
|
permission: PermissionSchema,
|
|
9657
|
-
envFile:
|
|
8645
|
+
envFile: stringType().optional(),
|
|
9658
8646
|
environment: EnvironmentLabelSchema
|
|
9659
8647
|
});
|
|
9660
8648
|
var SqliteNamedConnectionSchema = SqliteConnectionConfigSchema.extend({
|
|
9661
8649
|
permission: PermissionSchema,
|
|
9662
|
-
envFile:
|
|
8650
|
+
envFile: stringType().optional(),
|
|
9663
8651
|
environment: EnvironmentLabelSchema
|
|
9664
8652
|
});
|
|
9665
8653
|
var MongoDBNamedConnectionSchema = MongoDBConnectionConfigSchema.extend({
|
|
9666
8654
|
permission: PermissionSchema,
|
|
9667
|
-
envFile:
|
|
8655
|
+
envFile: stringType().optional(),
|
|
9668
8656
|
environment: EnvironmentLabelSchema
|
|
9669
8657
|
});
|
|
9670
8658
|
var RedisNamedConnectionSchema = RedisConnectionConfigSchema.extend({
|
|
9671
8659
|
permission: PermissionSchema,
|
|
9672
|
-
envFile:
|
|
8660
|
+
envFile: stringType().optional(),
|
|
9673
8661
|
environment: EnvironmentLabelSchema
|
|
9674
8662
|
});
|
|
9675
8663
|
var ElasticsearchNamedConnectionSchema = ElasticsearchConnectionConfigSchema.extend({
|
|
9676
8664
|
permission: PermissionSchema,
|
|
9677
|
-
envFile:
|
|
8665
|
+
envFile: stringType().optional(),
|
|
9678
8666
|
environment: EnvironmentLabelSchema
|
|
9679
8667
|
});
|
|
9680
|
-
var NamedConnectionUnion =
|
|
8668
|
+
var NamedConnectionUnion = unionType([
|
|
9681
8669
|
SqlNamedConnectionSchema,
|
|
9682
8670
|
SqliteNamedConnectionSchema,
|
|
9683
8671
|
MongoDBNamedConnectionSchema,
|
|
9684
8672
|
RedisNamedConnectionSchema,
|
|
9685
8673
|
ElasticsearchNamedConnectionSchema
|
|
9686
8674
|
]);
|
|
9687
|
-
var NamedConnectionSchema =
|
|
8675
|
+
var NamedConnectionSchema = preprocessType((raw, ctx) => {
|
|
9688
8676
|
if (raw !== null && typeof raw === "object" && !Array.isArray(raw)) {
|
|
9689
8677
|
if ("blacklist" in raw) {
|
|
9690
8678
|
ctx.addIssue({
|
|
9691
|
-
code:
|
|
8679
|
+
code: ZodIssueCode.custom,
|
|
9692
8680
|
path: ["blacklist"],
|
|
9693
8681
|
message: "blacklist is configured once at the top level, not per connection \u2014 a blacklist here " + "would be ignored. Move it to the top-level blacklist."
|
|
9694
8682
|
});
|
|
@@ -9696,19 +8684,19 @@ var NamedConnectionSchema = exports_external.preprocess((raw, ctx) => {
|
|
|
9696
8684
|
}
|
|
9697
8685
|
return raw;
|
|
9698
8686
|
}, NamedConnectionUnion);
|
|
9699
|
-
var DbcliConfigV2Schema =
|
|
9700
|
-
version:
|
|
9701
|
-
default:
|
|
9702
|
-
connections:
|
|
8687
|
+
var DbcliConfigV2Schema = objectType({
|
|
8688
|
+
version: literalType(2),
|
|
8689
|
+
default: stringType().min(1).optional(),
|
|
8690
|
+
connections: recordType(NamedConnectionSchema).refine((conns) => Object.keys(conns).length > 0, {
|
|
9703
8691
|
message: "At least one connection is required"
|
|
9704
8692
|
}),
|
|
9705
|
-
schema:
|
|
9706
|
-
schemas:
|
|
8693
|
+
schema: recordType(anyType()).optional().default({}),
|
|
8694
|
+
schemas: recordType(recordType(anyType())).optional().default({}),
|
|
9707
8695
|
metadata: MetadataSchema,
|
|
9708
8696
|
blacklist: BlacklistConfigSchema,
|
|
9709
8697
|
audit: AuditConfigSchema,
|
|
9710
8698
|
redis: RedisConfigSchema
|
|
9711
|
-
}).refine((config) =>
|
|
8699
|
+
}).refine((config) => config.default === undefined || Object.hasOwn(config.connections, config.default), {
|
|
9712
8700
|
message: "Default connection must exist in connections",
|
|
9713
8701
|
path: ["default"]
|
|
9714
8702
|
});
|
|
@@ -9846,16 +8834,16 @@ async function snapshot(path) {
|
|
|
9846
8834
|
const file = Bun.file(path);
|
|
9847
8835
|
return { path, content: await file.exists() ? await file.text() : null };
|
|
9848
8836
|
}
|
|
9849
|
-
async function restore(
|
|
9850
|
-
if (
|
|
9851
|
-
await unlink(
|
|
8837
|
+
async function restore(snapshot) {
|
|
8838
|
+
if (snapshot.content === null) {
|
|
8839
|
+
await unlink(snapshot.path).catch(() => {
|
|
9852
8840
|
return;
|
|
9853
8841
|
});
|
|
9854
8842
|
return;
|
|
9855
8843
|
}
|
|
9856
|
-
const temporary = `${
|
|
9857
|
-
await Bun.write(temporary,
|
|
9858
|
-
await rename(temporary,
|
|
8844
|
+
const temporary = `${snapshot.path}.rollback-${process.pid}-${randomUUID()}`;
|
|
8845
|
+
await Bun.write(temporary, snapshot.content);
|
|
8846
|
+
await rename(temporary, snapshot.path);
|
|
9859
8847
|
}
|
|
9860
8848
|
async function writeConfigWithIntegrity(storagePath, configContent) {
|
|
9861
8849
|
await writeProtectedFileWithIntegrity(storagePath, "config.json", configContent, INTEGRITY_FILE);
|
|
@@ -9971,8 +8959,8 @@ function isGlobalConfigPath(path) {
|
|
|
9971
8959
|
function getProjectStoragePath(projectPath) {
|
|
9972
8960
|
const normalizedProjectPath = resolve2(projectPath);
|
|
9973
8961
|
const projectName = basename(normalizedProjectPath) || "project";
|
|
9974
|
-
const
|
|
9975
|
-
return join6(getDbcliHomeRoot(), "projects", `${projectName}-${
|
|
8962
|
+
const hash = createHash2("sha1").update(normalizedProjectPath).digest("hex").slice(0, 12);
|
|
8963
|
+
return join6(getDbcliHomeRoot(), "projects", `${projectName}-${hash}`);
|
|
9976
8964
|
}
|
|
9977
8965
|
var _bindingCache = new Map;
|
|
9978
8966
|
function bindingCacheKey(projectPath) {
|
|
@@ -10059,14 +9047,26 @@ function findSimilarConnectionNames(requestedName, availableNames) {
|
|
|
10059
9047
|
}).filter(({ isSimilar }) => isSimilar).sort((a, b) => a.distance - b.distance || a.name.localeCompare(b.name)).slice(0, 3).map(({ name }) => name);
|
|
10060
9048
|
}
|
|
10061
9049
|
function connectionNotFoundMessage(requestedName, availableNames) {
|
|
9050
|
+
if (requestedName === undefined) {
|
|
9051
|
+
return "\u5C1A\u672A\u8A2D\u5B9A\u9810\u8A2D\u9023\u7DDA\u3002\u8ACB\u4F7F\u7528 --use <name> \u6216\u8A2D\u5B9A DBCLI_CONNECTION \u660E\u78BA\u6307\u5B9A\u9023\u7DDA\u3002" + ` \u53EF\u7528\u9023\u7DDA\uFF1A${availableNames.join(", ")}`;
|
|
9052
|
+
}
|
|
10062
9053
|
const suggestions = findSimilarConnectionNames(requestedName, availableNames);
|
|
10063
9054
|
const suggestion = suggestions.length > 0 ? ` \u4F60\u662F\u5426\u8981\u4F7F\u7528\uFF1A${suggestions.join("\u3001")}\uFF1F` : "";
|
|
10064
9055
|
return `\u9023\u7DDA '${requestedName}' \u4E0D\u5B58\u5728\u3002${suggestion} \u53EF\u7528\u9023\u7DDA\uFF1A${availableNames.join(", ")}`;
|
|
10065
9056
|
}
|
|
9057
|
+
|
|
9058
|
+
class ConnectionSelectionRequiredError extends ConfigError {
|
|
9059
|
+
constructor(availableNames) {
|
|
9060
|
+
super(connectionNotFoundMessage(undefined, availableNames));
|
|
9061
|
+
}
|
|
9062
|
+
}
|
|
10066
9063
|
function resolveConnection(config, name) {
|
|
10067
9064
|
const connectionName = name ?? config.default;
|
|
9065
|
+
if (connectionName === undefined) {
|
|
9066
|
+
throw new ConnectionSelectionRequiredError(Object.keys(config.connections));
|
|
9067
|
+
}
|
|
10068
9068
|
const conn = config.connections[connectionName];
|
|
10069
|
-
if (!conn) {
|
|
9069
|
+
if (!Object.hasOwn(config.connections, connectionName) || !conn) {
|
|
10070
9070
|
throw new ConfigError(connectionNotFoundMessage(connectionName, Object.keys(config.connections)));
|
|
10071
9071
|
}
|
|
10072
9072
|
const { permission, envFile, environment, ...connectionFields } = conn;
|
|
@@ -10084,7 +9084,7 @@ async function loadConnectionEnv(resolved, basePath) {
|
|
|
10084
9084
|
await loadEnvFile(envPath);
|
|
10085
9085
|
}
|
|
10086
9086
|
}
|
|
10087
|
-
async function
|
|
9087
|
+
async function readV2ConfigDocument(path) {
|
|
10088
9088
|
const storagePath = await resolveConfigStoragePath(path);
|
|
10089
9089
|
const configPath = join7(storagePath, "config.json");
|
|
10090
9090
|
const file = Bun.file(configPath);
|
|
@@ -10094,8 +9094,10 @@ async function readV2Config(path) {
|
|
|
10094
9094
|
await assertAgentReadableFile(configPath);
|
|
10095
9095
|
const content = await file.text();
|
|
10096
9096
|
await assertConfigIntegrity(storagePath, content, { requireRecord: true });
|
|
10097
|
-
|
|
10098
|
-
|
|
9097
|
+
return JSON.parse(content);
|
|
9098
|
+
}
|
|
9099
|
+
async function readV2Config(path) {
|
|
9100
|
+
return DbcliConfigV2Schema.parse(await readV2ConfigDocument(path));
|
|
10099
9101
|
}
|
|
10100
9102
|
async function writeV2Config(path, config) {
|
|
10101
9103
|
assertConfigMutationApproved();
|
|
@@ -10126,18 +9128,20 @@ function envVarNameFor(connName, field) {
|
|
|
10126
9128
|
return `DBCLI_${slug}_${field.toUpperCase()}`;
|
|
10127
9129
|
}
|
|
10128
9130
|
function removeConnection(config, name) {
|
|
10129
|
-
if (!(
|
|
9131
|
+
if (!Object.hasOwn(config.connections, name))
|
|
10130
9132
|
throw new Error(`\u9023\u7DDA '${name}' \u4E0D\u5B58\u5728`);
|
|
10131
9133
|
const rest = { ...config.connections };
|
|
10132
9134
|
delete rest[name];
|
|
10133
9135
|
const remaining = Object.keys(rest);
|
|
10134
9136
|
if (remaining.length === 0)
|
|
10135
9137
|
throw new Error("\u7121\u6CD5\u522A\u9664\u6700\u5F8C\u4E00\u689D\u9023\u7DDA");
|
|
10136
|
-
const
|
|
10137
|
-
|
|
9138
|
+
const updated = { ...config, connections: rest };
|
|
9139
|
+
if (config.default === name)
|
|
9140
|
+
delete updated.default;
|
|
9141
|
+
return updated;
|
|
10138
9142
|
}
|
|
10139
9143
|
function setDefaultConnection(config, name) {
|
|
10140
|
-
if (!(
|
|
9144
|
+
if (!Object.hasOwn(config.connections, name))
|
|
10141
9145
|
throw new Error(`\u9023\u7DDA '${name}' \u4E0D\u5B58\u5728`);
|
|
10142
9146
|
return { ...config, default: name };
|
|
10143
9147
|
}
|
|
@@ -10249,8 +9253,8 @@ async function resolvePasswordTarget(projectPath, connectionName) {
|
|
|
10249
9253
|
if (connectionName && connectionName !== V1_CONNECTION_NAME) {
|
|
10250
9254
|
throw new ConfigError(`\u9019\u662F v1 \u8A2D\u5B9A\uFF0C\u53EA\u6709\u4E00\u689D\u9023\u7DDA\uFF0C\u7121\u6CD5\u6307\u5B9A\u9023\u7DDA\u540D\u7A31 '${connectionName}'\u3002` + `\u9700\u8981\u591A\u9023\u7DDA\u8ACB\u5148\u7528 dbcli init --conn-name <name> \u5347\u7D1A\u5230 v2\u3002`);
|
|
10251
9255
|
}
|
|
10252
|
-
const
|
|
10253
|
-
const customRef = envRefName(
|
|
9256
|
+
const connection = raw.connection ?? {};
|
|
9257
|
+
const customRef = envRefName(connection.password);
|
|
10254
9258
|
if (customRef !== undefined && customRef !== V1_VAR_NAME) {
|
|
10255
9259
|
throw new ConfigError(`\u9019\u500B v1 \u8A2D\u5B9A\u7684\u5BC6\u78BC\u4F86\u81EA\u74B0\u5883\u8B8A\u6578 '${customRef}'\uFF0Cdbcli \u7121\u6CD5\u4EE3\u70BA\u8F2A\u66FF\u3002` + `\u8ACB\u76F4\u63A5\u66F4\u65B0\u8A72\u74B0\u5883\u8B8A\u6578\uFF0C\u6216\u7528 dbcli init --conn-name <name> \u5347\u7D1A\u5230 v2 \u5F8C\u518D\u8F2A\u66FF\u3002`);
|
|
10256
9260
|
}
|
|
@@ -10262,15 +9266,11 @@ async function resolvePasswordTarget(projectPath, connectionName) {
|
|
|
10262
9266
|
};
|
|
10263
9267
|
}
|
|
10264
9268
|
const config = await readV2Config(projectPath);
|
|
10265
|
-
const targetName
|
|
10266
|
-
const connection = config.connections[targetName];
|
|
10267
|
-
if (!connection) {
|
|
10268
|
-
throw new ConfigError(connectionNotFoundMessage(targetName, Object.keys(config.connections)));
|
|
10269
|
-
}
|
|
9269
|
+
const { name: targetName, connection, envFile } = resolveConnection(config, connectionName);
|
|
10270
9270
|
const referencedVar = envRefName(connection.password);
|
|
10271
9271
|
return {
|
|
10272
9272
|
connection: targetName,
|
|
10273
|
-
envFile:
|
|
9273
|
+
envFile: envFile ?? DEFAULT_ENV_FILE,
|
|
10274
9274
|
varName: referencedVar ?? envVarNameFor(targetName, "password"),
|
|
10275
9275
|
convertedToEnvRef: referencedVar === undefined
|
|
10276
9276
|
};
|
|
@@ -10532,8 +9532,8 @@ var configModule = {
|
|
|
10532
9532
|
let schema = (v2Config.schemas ?? {})[resolved.name] ?? v2Config.schema;
|
|
10533
9533
|
if (options.loadLayeredSchema !== false) {
|
|
10534
9534
|
try {
|
|
10535
|
-
|
|
10536
|
-
const loader = new
|
|
9535
|
+
await Promise.resolve().then(() => init_schema_loader());
|
|
9536
|
+
const loader = new SchemaLayeredLoader(storagePath, {
|
|
10537
9537
|
connectionName: resolved.name
|
|
10538
9538
|
});
|
|
10539
9539
|
const { cache, index } = await loader.initialize();
|
|
@@ -11341,10 +10341,10 @@ class CapabilityContractError extends Error {
|
|
|
11341
10341
|
Object.setPrototypeOf(this, CapabilityContractError.prototype);
|
|
11342
10342
|
}
|
|
11343
10343
|
}
|
|
11344
|
-
var PermissionSchema2 =
|
|
11345
|
-
var EngineSchema =
|
|
11346
|
-
var RiskSchema =
|
|
11347
|
-
var SideEffectSchema =
|
|
10344
|
+
var PermissionSchema2 = enumType(["query-only", "read-write", "data-admin", "admin"]);
|
|
10345
|
+
var EngineSchema = enumType(DATABASE_SYSTEMS);
|
|
10346
|
+
var RiskSchema = enumType(["readonly", "dry-run", "write", "unknown"]);
|
|
10347
|
+
var SideEffectSchema = enumType([
|
|
11348
10348
|
"readonly",
|
|
11349
10349
|
"dry-run",
|
|
11350
10350
|
"local-write",
|
|
@@ -11353,42 +10353,42 @@ var SideEffectSchema = exports_external.enum([
|
|
|
11353
10353
|
"none"
|
|
11354
10354
|
]);
|
|
11355
10355
|
var CAPABILITY_ID_PATTERN = /^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)+$/;
|
|
11356
|
-
var CapabilityIdSchema =
|
|
10356
|
+
var CapabilityIdSchema = stringType().regex(CAPABILITY_ID_PATTERN, {
|
|
11357
10357
|
message: "capability id must be dotted lower-case segments, e.g. schema.read"
|
|
11358
10358
|
});
|
|
11359
10359
|
var CAPABILITY_COMMAND_PATTERN = /^[a-z][a-z0-9]*(?: [a-z][a-z0-9]*)*$/;
|
|
11360
|
-
var CapabilityCommandSchema =
|
|
10360
|
+
var CapabilityCommandSchema = stringType().regex(CAPABILITY_COMMAND_PATTERN, {
|
|
11361
10361
|
message: "capability command must be space-separated lower-case CLI command segments"
|
|
11362
10362
|
});
|
|
11363
|
-
var CapabilitySchema =
|
|
10363
|
+
var CapabilitySchema = objectType({
|
|
11364
10364
|
id: CapabilityIdSchema,
|
|
11365
|
-
description:
|
|
10365
|
+
description: stringType().min(1),
|
|
11366
10366
|
command: CapabilityCommandSchema,
|
|
11367
10367
|
risk: RiskSchema,
|
|
11368
10368
|
sideEffect: SideEffectSchema,
|
|
11369
|
-
engines:
|
|
11370
|
-
limitedEngines:
|
|
11371
|
-
engineIndependent:
|
|
10369
|
+
engines: arrayType(EngineSchema),
|
|
10370
|
+
limitedEngines: arrayType(EngineSchema),
|
|
10371
|
+
engineIndependent: booleanType(),
|
|
11372
10372
|
minimumPermission: PermissionSchema2,
|
|
11373
|
-
requiresConnection:
|
|
11374
|
-
mutatesConfiguration:
|
|
11375
|
-
supportsJson:
|
|
11376
|
-
supportsEvidence:
|
|
10373
|
+
requiresConnection: booleanType(),
|
|
10374
|
+
mutatesConfiguration: booleanType(),
|
|
10375
|
+
supportsJson: booleanType(),
|
|
10376
|
+
supportsEvidence: booleanType()
|
|
11377
10377
|
}).strict();
|
|
11378
|
-
var CapabilityCatalogSchema =
|
|
11379
|
-
schemaVersion:
|
|
11380
|
-
capabilities:
|
|
10378
|
+
var CapabilityCatalogSchema = objectType({
|
|
10379
|
+
schemaVersion: literalType(CAPABILITY_CONTRACT_SCHEMA_VERSION),
|
|
10380
|
+
capabilities: arrayType(CapabilitySchema)
|
|
11381
10381
|
}).strict();
|
|
11382
|
-
var CheckContextSchema =
|
|
10382
|
+
var CheckContextSchema = objectType({
|
|
11383
10383
|
engine: EngineSchema,
|
|
11384
10384
|
permission: PermissionSchema2,
|
|
11385
|
-
connectionName:
|
|
11386
|
-
agentMode:
|
|
10385
|
+
connectionName: stringType().max(200).nullable(),
|
|
10386
|
+
agentMode: booleanType()
|
|
11387
10387
|
}).strict();
|
|
11388
|
-
var CheckResultSchema =
|
|
11389
|
-
id:
|
|
11390
|
-
status:
|
|
11391
|
-
reason:
|
|
10388
|
+
var CheckResultSchema = objectType({
|
|
10389
|
+
id: stringType().min(1),
|
|
10390
|
+
status: enumType(["available", "unavailable", "unknown"]),
|
|
10391
|
+
reason: enumType([
|
|
11392
10392
|
"unknown-capability",
|
|
11393
10393
|
"context-unavailable",
|
|
11394
10394
|
"context-unresolvable",
|
|
@@ -11397,13 +10397,13 @@ var CheckResultSchema = exports_external.object({
|
|
|
11397
10397
|
"permission"
|
|
11398
10398
|
]).nullable()
|
|
11399
10399
|
}).strict();
|
|
11400
|
-
var CapabilityCheckReportSchema =
|
|
11401
|
-
schemaVersion:
|
|
11402
|
-
ok:
|
|
11403
|
-
required:
|
|
10400
|
+
var CapabilityCheckReportSchema = objectType({
|
|
10401
|
+
schemaVersion: literalType(CAPABILITY_CONTRACT_SCHEMA_VERSION),
|
|
10402
|
+
ok: booleanType(),
|
|
10403
|
+
required: arrayType(stringType().min(1)),
|
|
11404
10404
|
context: CheckContextSchema.nullable(),
|
|
11405
|
-
results:
|
|
11406
|
-
warnings:
|
|
10405
|
+
results: arrayType(CheckResultSchema),
|
|
10406
|
+
warnings: arrayType(stringType())
|
|
11407
10407
|
}).strict();
|
|
11408
10408
|
function parse(schema, value, what) {
|
|
11409
10409
|
const result = schema.safeParse(value);
|
|
@@ -11438,8 +10438,8 @@ var MAX_BRANCH_STEPS = 6;
|
|
|
11438
10438
|
var MAX_BRANCH_COUNT = 8;
|
|
11439
10439
|
|
|
11440
10440
|
// src/core/recovery/envelope-schema.ts
|
|
11441
|
-
var recoveryCodeSchema =
|
|
11442
|
-
var recoveryCategorySchema =
|
|
10441
|
+
var recoveryCodeSchema = enumType(RECOVERY_CODES);
|
|
10442
|
+
var recoveryCategorySchema = enumType([
|
|
11443
10443
|
"config",
|
|
11444
10444
|
"connection",
|
|
11445
10445
|
"permission",
|
|
@@ -11448,30 +10448,30 @@ var recoveryCategorySchema = exports_external.enum([
|
|
|
11448
10448
|
"schema-cache",
|
|
11449
10449
|
"unknown"
|
|
11450
10450
|
]);
|
|
11451
|
-
var guideRiskSchema =
|
|
11452
|
-
var branchIdSchema =
|
|
11453
|
-
var guideStepSchema =
|
|
11454
|
-
order:
|
|
11455
|
-
command:
|
|
11456
|
-
rationale:
|
|
10451
|
+
var guideRiskSchema = enumType(["readonly", "dry-run", "write", "unknown"]);
|
|
10452
|
+
var branchIdSchema = stringType().min(1).max(64).regex(/^[a-z0-9-]+$/, "branchId must match /^[a-z0-9-]+$/");
|
|
10453
|
+
var guideStepSchema = objectType({
|
|
10454
|
+
order: numberType().int(),
|
|
10455
|
+
command: stringType().min(1),
|
|
10456
|
+
rationale: stringType(),
|
|
11457
10457
|
risk: guideRiskSchema,
|
|
11458
|
-
expects:
|
|
11459
|
-
snippet:
|
|
11460
|
-
intent:
|
|
11461
|
-
interactive:
|
|
11462
|
-
dbWrite:
|
|
11463
|
-
placeholders:
|
|
10458
|
+
expects: stringType(),
|
|
10459
|
+
snippet: stringType().optional(),
|
|
10460
|
+
intent: stringType().optional(),
|
|
10461
|
+
interactive: booleanType().optional(),
|
|
10462
|
+
dbWrite: booleanType().optional(),
|
|
10463
|
+
placeholders: arrayType(stringType()).optional(),
|
|
11464
10464
|
branchId: branchIdSchema.optional()
|
|
11465
10465
|
}).strict();
|
|
11466
|
-
var branchPlanSchema =
|
|
11467
|
-
description:
|
|
11468
|
-
steps:
|
|
10466
|
+
var branchPlanSchema = objectType({
|
|
10467
|
+
description: stringType().min(1),
|
|
10468
|
+
steps: arrayType(guideStepSchema).min(1).max(MAX_BRANCH_STEPS)
|
|
11469
10469
|
}).strict();
|
|
11470
|
-
var branchesSchema =
|
|
10470
|
+
var branchesSchema = recordType(branchIdSchema, branchPlanSchema).superRefine((map, ctx) => {
|
|
11471
10471
|
const keys = Object.keys(map);
|
|
11472
10472
|
if (keys.length > MAX_BRANCH_COUNT) {
|
|
11473
10473
|
ctx.addIssue({
|
|
11474
|
-
code:
|
|
10474
|
+
code: ZodIssueCode.custom,
|
|
11475
10475
|
message: `branches has ${keys.length} entries; cap is ${MAX_BRANCH_COUNT}`
|
|
11476
10476
|
});
|
|
11477
10477
|
}
|
|
@@ -11479,36 +10479,36 @@ var branchesSchema = exports_external.record(branchIdSchema, branchPlanSchema).s
|
|
|
11479
10479
|
for (const step of plan.steps) {
|
|
11480
10480
|
if (step.branchId !== undefined && step.branchId !== id) {
|
|
11481
10481
|
ctx.addIssue({
|
|
11482
|
-
code:
|
|
10482
|
+
code: ZodIssueCode.custom,
|
|
11483
10483
|
message: `step.branchId '${step.branchId}' does not match enclosing key '${id}'`
|
|
11484
10484
|
});
|
|
11485
10485
|
}
|
|
11486
10486
|
}
|
|
11487
10487
|
}
|
|
11488
10488
|
});
|
|
11489
|
-
var branchForkSchema =
|
|
11490
|
-
after:
|
|
11491
|
-
branchIds:
|
|
10489
|
+
var branchForkSchema = objectType({
|
|
10490
|
+
after: numberType().int().min(1),
|
|
10491
|
+
branchIds: arrayType(branchIdSchema).min(1)
|
|
11492
10492
|
}).strict();
|
|
11493
|
-
var recoveryEnvelopeSchema =
|
|
11494
|
-
schemaVersion:
|
|
11495
|
-
generatedAt:
|
|
11496
|
-
ok:
|
|
11497
|
-
error:
|
|
10493
|
+
var recoveryEnvelopeSchema = objectType({
|
|
10494
|
+
schemaVersion: literalType(1),
|
|
10495
|
+
generatedAt: stringType().min(1),
|
|
10496
|
+
ok: literalType(false),
|
|
10497
|
+
error: objectType({
|
|
11498
10498
|
code: recoveryCodeSchema,
|
|
11499
10499
|
category: recoveryCategorySchema,
|
|
11500
|
-
message:
|
|
11501
|
-
details:
|
|
11502
|
-
table:
|
|
11503
|
-
columns:
|
|
11504
|
-
requiredPermission:
|
|
11505
|
-
connectionCode:
|
|
11506
|
-
snippet:
|
|
11507
|
-
intent:
|
|
11508
|
-
paramName:
|
|
10500
|
+
message: stringType(),
|
|
10501
|
+
details: objectType({
|
|
10502
|
+
table: stringType().optional(),
|
|
10503
|
+
columns: stringType().optional(),
|
|
10504
|
+
requiredPermission: stringType().optional(),
|
|
10505
|
+
connectionCode: stringType().optional(),
|
|
10506
|
+
snippet: stringType().optional(),
|
|
10507
|
+
intent: stringType().optional(),
|
|
10508
|
+
paramName: stringType().optional()
|
|
11509
10509
|
}).strict().optional()
|
|
11510
10510
|
}).strict(),
|
|
11511
|
-
recovery:
|
|
10511
|
+
recovery: arrayType(guideStepSchema),
|
|
11512
10512
|
verify: guideStepSchema.optional(),
|
|
11513
10513
|
branches: branchesSchema.optional(),
|
|
11514
10514
|
branchFork: branchForkSchema.optional()
|
|
@@ -11517,7 +10517,7 @@ var recoveryEnvelopeSchema = exports_external.object({
|
|
|
11517
10517
|
const hasFork = env.branchFork !== undefined;
|
|
11518
10518
|
if (hasBranches !== hasFork) {
|
|
11519
10519
|
ctx.addIssue({
|
|
11520
|
-
code:
|
|
10520
|
+
code: ZodIssueCode.custom,
|
|
11521
10521
|
message: "branches and branchFork must be set together (or both omitted)"
|
|
11522
10522
|
});
|
|
11523
10523
|
return;
|
|
@@ -11527,19 +10527,19 @@ var recoveryEnvelopeSchema = exports_external.object({
|
|
|
11527
10527
|
const ids = [...env.branchFork.branchIds].sort();
|
|
11528
10528
|
if (keys.length !== ids.length || keys.some((k, i) => k !== ids[i])) {
|
|
11529
10529
|
ctx.addIssue({
|
|
11530
|
-
code:
|
|
10530
|
+
code: ZodIssueCode.custom,
|
|
11531
10531
|
message: "branchFork.branchIds must equal Object.keys(branches)"
|
|
11532
10532
|
});
|
|
11533
10533
|
}
|
|
11534
10534
|
}
|
|
11535
10535
|
});
|
|
11536
|
-
var savedRecoveryEnvelopeSchema =
|
|
11537
|
-
schemaVersion:
|
|
11538
|
-
id:
|
|
11539
|
-
audit_ref:
|
|
11540
|
-
savedAt:
|
|
11541
|
-
command:
|
|
11542
|
-
cwd:
|
|
10536
|
+
var savedRecoveryEnvelopeSchema = objectType({
|
|
10537
|
+
schemaVersion: literalType(1),
|
|
10538
|
+
id: stringType().optional(),
|
|
10539
|
+
audit_ref: stringType().optional(),
|
|
10540
|
+
savedAt: stringType().min(1),
|
|
10541
|
+
command: stringType(),
|
|
10542
|
+
cwd: stringType().min(1),
|
|
11543
10543
|
envelope: recoveryEnvelopeSchema
|
|
11544
10544
|
}).strict();
|
|
11545
10545
|
|
|
@@ -11557,21 +10557,21 @@ var OPERATION_ID = /^[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)*$/;
|
|
|
11557
10557
|
var CODE = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;
|
|
11558
10558
|
var EVIDENCE_ID = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,159}$/;
|
|
11559
10559
|
var SHA256_DIGEST = /^sha256:[a-f0-9]{64}$/;
|
|
11560
|
-
var identifierSchema =
|
|
10560
|
+
var identifierSchema = stringType().min(1).max(MAX_OPERATION_ENVELOPE_IDENTIFIER_LENGTH);
|
|
11561
10561
|
var capabilityIdSchema = identifierSchema.regex(CAPABILITY_ID_PATTERN, "capability id must be dotted lower-case segments");
|
|
11562
10562
|
var codeSchema = identifierSchema.regex(CODE, "code must be an uppercase snake-case identifier");
|
|
11563
|
-
var messageSchema =
|
|
11564
|
-
var contextSchema =
|
|
11565
|
-
engine:
|
|
11566
|
-
permission:
|
|
10563
|
+
var messageSchema = stringType().min(1).max(MAX_MESSAGE_LENGTH);
|
|
10564
|
+
var contextSchema = objectType({
|
|
10565
|
+
engine: enumType(DATABASE_SYSTEMS),
|
|
10566
|
+
permission: enumType(["query-only", "read-write", "data-admin", "admin"]),
|
|
11567
10567
|
connectionName: identifierSchema.nullable(),
|
|
11568
|
-
agentMode:
|
|
11569
|
-
correlationId:
|
|
10568
|
+
agentMode: booleanType(),
|
|
10569
|
+
correlationId: stringType().regex(CORRELATION_ID_PATTERN, "invalid correlation id").optional()
|
|
11570
10570
|
}).strict();
|
|
11571
|
-
var resultSchema =
|
|
10571
|
+
var resultSchema = objectType({
|
|
11572
10572
|
id: capabilityIdSchema,
|
|
11573
|
-
status:
|
|
11574
|
-
reason:
|
|
10573
|
+
status: enumType(["available", "unavailable", "unknown"]),
|
|
10574
|
+
reason: enumType([
|
|
11575
10575
|
"unknown-capability",
|
|
11576
10576
|
"context-unavailable",
|
|
11577
10577
|
"context-unresolvable",
|
|
@@ -11582,50 +10582,50 @@ var resultSchema = exports_external.object({
|
|
|
11582
10582
|
}).strict().superRefine((result, ctx) => {
|
|
11583
10583
|
if (result.status === "available" && result.reason !== null) {
|
|
11584
10584
|
ctx.addIssue({
|
|
11585
|
-
code:
|
|
10585
|
+
code: ZodIssueCode.custom,
|
|
11586
10586
|
message: "available results require reason null"
|
|
11587
10587
|
});
|
|
11588
10588
|
}
|
|
11589
10589
|
if (result.status === "unknown" && result.reason !== "unknown-capability") {
|
|
11590
10590
|
ctx.addIssue({
|
|
11591
|
-
code:
|
|
10591
|
+
code: ZodIssueCode.custom,
|
|
11592
10592
|
message: "unknown results require reason unknown-capability"
|
|
11593
10593
|
});
|
|
11594
10594
|
}
|
|
11595
10595
|
if (result.status === "unavailable" && (result.reason === null || result.reason === "unknown-capability")) {
|
|
11596
10596
|
ctx.addIssue({
|
|
11597
|
-
code:
|
|
10597
|
+
code: ZodIssueCode.custom,
|
|
11598
10598
|
message: "unavailable results require an availability reason"
|
|
11599
10599
|
});
|
|
11600
10600
|
}
|
|
11601
10601
|
});
|
|
11602
|
-
var capabilitiesCheckDataSchema =
|
|
11603
|
-
required:
|
|
11604
|
-
results:
|
|
10602
|
+
var capabilitiesCheckDataSchema = objectType({
|
|
10603
|
+
required: arrayType(capabilityIdSchema).min(1).max(MAX_OPERATION_ENVELOPE_ITEMS),
|
|
10604
|
+
results: arrayType(resultSchema).min(1).max(MAX_OPERATION_ENVELOPE_ITEMS)
|
|
11605
10605
|
}).strict().superRefine((data, ctx) => {
|
|
11606
10606
|
if (new Set(data.required).size !== data.required.length) {
|
|
11607
10607
|
ctx.addIssue({
|
|
11608
|
-
code:
|
|
10608
|
+
code: ZodIssueCode.custom,
|
|
11609
10609
|
message: "required capability ids must be unique"
|
|
11610
10610
|
});
|
|
11611
10611
|
}
|
|
11612
10612
|
if (data.required.length !== data.results.length || data.required.some((id, index) => data.results[index]?.id !== id)) {
|
|
11613
10613
|
ctx.addIssue({
|
|
11614
|
-
code:
|
|
10614
|
+
code: ZodIssueCode.custom,
|
|
11615
10615
|
message: "results must match required capability ids in order"
|
|
11616
10616
|
});
|
|
11617
10617
|
}
|
|
11618
10618
|
});
|
|
11619
|
-
var warningSchema =
|
|
10619
|
+
var warningSchema = objectType({
|
|
11620
10620
|
code: codeSchema,
|
|
11621
10621
|
message: messageSchema
|
|
11622
10622
|
}).strict();
|
|
11623
|
-
var evidenceSchema =
|
|
11624
|
-
kind:
|
|
11625
|
-
id:
|
|
11626
|
-
digest:
|
|
10623
|
+
var evidenceSchema = objectType({
|
|
10624
|
+
kind: enumType(["receipt", "audit", "verification-artifact"]),
|
|
10625
|
+
id: stringType().regex(EVIDENCE_ID, "invalid evidence id"),
|
|
10626
|
+
digest: stringType().regex(SHA256_DIGEST, "invalid evidence digest").optional()
|
|
11627
10627
|
}).strict();
|
|
11628
|
-
var errorSchema =
|
|
10628
|
+
var errorSchema = objectType({
|
|
11629
10629
|
code: codeSchema,
|
|
11630
10630
|
message: messageSchema
|
|
11631
10631
|
}).strict();
|
|
@@ -11638,21 +10638,21 @@ function hasOversizedRecoveryString(value) {
|
|
|
11638
10638
|
return false;
|
|
11639
10639
|
return Object.values(value).some(hasOversizedRecoveryString);
|
|
11640
10640
|
}
|
|
11641
|
-
var operationEnvelopeFieldSchema =
|
|
11642
|
-
schemaVersion:
|
|
11643
|
-
ok:
|
|
11644
|
-
operation:
|
|
11645
|
-
status:
|
|
10641
|
+
var operationEnvelopeFieldSchema = objectType({
|
|
10642
|
+
schemaVersion: literalType(OPERATION_ENVELOPE_SCHEMA_VERSION),
|
|
10643
|
+
ok: booleanType(),
|
|
10644
|
+
operation: enumType(["capabilities.check", "capabilities.list"]).refine((value) => value.length <= MAX_OPERATION_ENVELOPE_IDENTIFIER_LENGTH && OPERATION_ID.test(value)),
|
|
10645
|
+
status: enumType(["succeeded", "failed"]),
|
|
11646
10646
|
context: contextSchema.nullable(),
|
|
11647
|
-
data:
|
|
11648
|
-
warnings:
|
|
11649
|
-
evidence:
|
|
10647
|
+
data: unionType([capabilitiesCheckDataSchema, CapabilityCatalogSchema]).nullable(),
|
|
10648
|
+
warnings: arrayType(warningSchema).max(MAX_OPERATION_ENVELOPE_ITEMS),
|
|
10649
|
+
evidence: arrayType(evidenceSchema).max(MAX_EVIDENCE_ITEMS),
|
|
11650
10650
|
recovery: recoveryEnvelopeSchema.nullable(),
|
|
11651
10651
|
error: errorSchema.nullable()
|
|
11652
10652
|
}).strict().superRefine((envelope, ctx) => {
|
|
11653
10653
|
if (envelope.ok !== (envelope.status === "succeeded")) {
|
|
11654
10654
|
ctx.addIssue({
|
|
11655
|
-
code:
|
|
10655
|
+
code: ZodIssueCode.custom,
|
|
11656
10656
|
message: 'ok must equal (status === "succeeded")'
|
|
11657
10657
|
});
|
|
11658
10658
|
}
|
|
@@ -11660,41 +10660,41 @@ var operationEnvelopeFieldSchema = exports_external.object({
|
|
|
11660
10660
|
if (envelope.status === "succeeded") {
|
|
11661
10661
|
if (envelope.error !== null) {
|
|
11662
10662
|
ctx.addIssue({
|
|
11663
|
-
code:
|
|
10663
|
+
code: ZodIssueCode.custom,
|
|
11664
10664
|
message: "successful envelopes require error null"
|
|
11665
10665
|
});
|
|
11666
10666
|
}
|
|
11667
10667
|
if (envelope.data === null) {
|
|
11668
10668
|
ctx.addIssue({
|
|
11669
|
-
code:
|
|
10669
|
+
code: ZodIssueCode.custom,
|
|
11670
10670
|
message: "successful capabilities.check envelopes require data"
|
|
11671
10671
|
});
|
|
11672
10672
|
} else if ("results" in envelope.data) {
|
|
11673
10673
|
if (envelope.data.results.some((result) => result.status !== "available")) {
|
|
11674
10674
|
ctx.addIssue({
|
|
11675
|
-
code:
|
|
10675
|
+
code: ZodIssueCode.custom,
|
|
11676
10676
|
message: "successful capabilities.check results must all be available"
|
|
11677
10677
|
});
|
|
11678
10678
|
}
|
|
11679
10679
|
} else {
|
|
11680
10680
|
ctx.addIssue({
|
|
11681
|
-
code:
|
|
10681
|
+
code: ZodIssueCode.custom,
|
|
11682
10682
|
message: "capabilities.check requires capabilitiesCheckDataSchema shape"
|
|
11683
10683
|
});
|
|
11684
10684
|
}
|
|
11685
10685
|
} else if (envelope.error === null) {
|
|
11686
|
-
ctx.addIssue({ code:
|
|
10686
|
+
ctx.addIssue({ code: ZodIssueCode.custom, message: "failed envelopes require an error" });
|
|
11687
10687
|
}
|
|
11688
10688
|
const completedNegative = envelope.error?.code === "CAPABILITY_REQUIREMENTS_UNMET";
|
|
11689
10689
|
if (envelope.status === "failed" && completedNegative !== (envelope.data !== null)) {
|
|
11690
10690
|
ctx.addIssue({
|
|
11691
|
-
code:
|
|
10691
|
+
code: ZodIssueCode.custom,
|
|
11692
10692
|
message: "only completed negative capability results retain data"
|
|
11693
10693
|
});
|
|
11694
10694
|
}
|
|
11695
10695
|
if (completedNegative && envelope.data !== null && "results" in envelope.data && envelope.data.results.every((result) => result.status === "available")) {
|
|
11696
10696
|
ctx.addIssue({
|
|
11697
|
-
code:
|
|
10697
|
+
code: ZodIssueCode.custom,
|
|
11698
10698
|
message: "completed negative capability results require an unmet result"
|
|
11699
10699
|
});
|
|
11700
10700
|
}
|
|
@@ -11702,55 +10702,55 @@ var operationEnvelopeFieldSchema = exports_external.object({
|
|
|
11702
10702
|
if (envelope.status === "succeeded") {
|
|
11703
10703
|
if (envelope.context !== null) {
|
|
11704
10704
|
ctx.addIssue({
|
|
11705
|
-
code:
|
|
10705
|
+
code: ZodIssueCode.custom,
|
|
11706
10706
|
message: "successful capabilities.list envelopes require context null"
|
|
11707
10707
|
});
|
|
11708
10708
|
}
|
|
11709
10709
|
if (envelope.warnings.length !== 0) {
|
|
11710
10710
|
ctx.addIssue({
|
|
11711
|
-
code:
|
|
10711
|
+
code: ZodIssueCode.custom,
|
|
11712
10712
|
message: "successful capabilities.list envelopes require warnings empty"
|
|
11713
10713
|
});
|
|
11714
10714
|
}
|
|
11715
10715
|
if (envelope.evidence.length !== 0) {
|
|
11716
10716
|
ctx.addIssue({
|
|
11717
|
-
code:
|
|
10717
|
+
code: ZodIssueCode.custom,
|
|
11718
10718
|
message: "successful capabilities.list envelopes require evidence empty"
|
|
11719
10719
|
});
|
|
11720
10720
|
}
|
|
11721
10721
|
if (envelope.recovery !== null) {
|
|
11722
10722
|
ctx.addIssue({
|
|
11723
|
-
code:
|
|
10723
|
+
code: ZodIssueCode.custom,
|
|
11724
10724
|
message: "successful capabilities.list envelopes require recovery null"
|
|
11725
10725
|
});
|
|
11726
10726
|
}
|
|
11727
10727
|
if (envelope.error !== null) {
|
|
11728
10728
|
ctx.addIssue({
|
|
11729
|
-
code:
|
|
10729
|
+
code: ZodIssueCode.custom,
|
|
11730
10730
|
message: "successful envelopes require error null"
|
|
11731
10731
|
});
|
|
11732
10732
|
}
|
|
11733
10733
|
if (envelope.data === null) {
|
|
11734
10734
|
ctx.addIssue({
|
|
11735
|
-
code:
|
|
10735
|
+
code: ZodIssueCode.custom,
|
|
11736
10736
|
message: "successful capabilities.list envelopes require data"
|
|
11737
10737
|
});
|
|
11738
10738
|
} else if (!("capabilities" in envelope.data)) {
|
|
11739
10739
|
ctx.addIssue({
|
|
11740
|
-
code:
|
|
10740
|
+
code: ZodIssueCode.custom,
|
|
11741
10741
|
message: "capabilities.list requires CapabilityCatalogSchema shape"
|
|
11742
10742
|
});
|
|
11743
10743
|
}
|
|
11744
10744
|
} else {
|
|
11745
10745
|
if (envelope.error === null) {
|
|
11746
10746
|
ctx.addIssue({
|
|
11747
|
-
code:
|
|
10747
|
+
code: ZodIssueCode.custom,
|
|
11748
10748
|
message: "failed envelopes require an error"
|
|
11749
10749
|
});
|
|
11750
10750
|
}
|
|
11751
10751
|
if (envelope.data !== null) {
|
|
11752
10752
|
ctx.addIssue({
|
|
11753
|
-
code:
|
|
10753
|
+
code: ZodIssueCode.custom,
|
|
11754
10754
|
message: "failed capabilities.list envelopes require data null"
|
|
11755
10755
|
});
|
|
11756
10756
|
}
|
|
@@ -11759,13 +10759,13 @@ var operationEnvelopeFieldSchema = exports_external.object({
|
|
|
11759
10759
|
if (envelope.recovery !== null) {
|
|
11760
10760
|
if (envelope.error === null || envelope.recovery.error.code !== envelope.error.code || envelope.recovery.error.message !== envelope.error.message) {
|
|
11761
10761
|
ctx.addIssue({
|
|
11762
|
-
code:
|
|
10762
|
+
code: ZodIssueCode.custom,
|
|
11763
10763
|
message: "recovery error code and message must match the envelope error"
|
|
11764
10764
|
});
|
|
11765
10765
|
}
|
|
11766
10766
|
if (hasOversizedRecoveryString(envelope.recovery)) {
|
|
11767
10767
|
ctx.addIssue({
|
|
11768
|
-
code:
|
|
10768
|
+
code: ZodIssueCode.custom,
|
|
11769
10769
|
message: `recovery strings must be at most ${MAX_MESSAGE_LENGTH} characters`
|
|
11770
10770
|
});
|
|
11771
10771
|
}
|
|
@@ -11933,11 +10933,11 @@ class BlacklistValidator {
|
|
|
11933
10933
|
return;
|
|
11934
10934
|
}
|
|
11935
10935
|
if (this.manager.canOverrideBlacklist()) {
|
|
11936
|
-
const
|
|
10936
|
+
const message = t_vars("warnings.blacklist_override_used", {
|
|
11937
10937
|
operation,
|
|
11938
10938
|
table: tables.join(", ")
|
|
11939
10939
|
});
|
|
11940
|
-
console.error(
|
|
10940
|
+
console.error(message);
|
|
11941
10941
|
return;
|
|
11942
10942
|
}
|
|
11943
10943
|
const blocked = tables.filter((table) => this.manager.isTableBlacklisted(table));
|
|
@@ -12203,44 +11203,44 @@ class BlacklistValidator {
|
|
|
12203
11203
|
// src/core/public.ts
|
|
12204
11204
|
var readConfig = (path, connectionName) => configModule.read(path, connectionName);
|
|
12205
11205
|
export {
|
|
12206
|
-
|
|
12207
|
-
writeProjectBinding,
|
|
12208
|
-
upsertConnection,
|
|
12209
|
-
setDefaultConnection,
|
|
12210
|
-
setConnectionPassword,
|
|
12211
|
-
resolvePasswordTarget,
|
|
12212
|
-
resolveConnection,
|
|
12213
|
-
resolveConfigStoragePath,
|
|
12214
|
-
removeConnection,
|
|
12215
|
-
readV2Config,
|
|
12216
|
-
readConfig,
|
|
12217
|
-
parseRequirements,
|
|
12218
|
-
parseOperationEnvelope,
|
|
12219
|
-
parseCapabilityCheckReport,
|
|
12220
|
-
parseCapabilityCatalog,
|
|
12221
|
-
migrateV1ToV2,
|
|
12222
|
-
loadConnectionEnv,
|
|
12223
|
-
listConnections,
|
|
12224
|
-
listCapabilityIds,
|
|
12225
|
-
isGlobalConfigPath,
|
|
12226
|
-
getProjectStoragePath,
|
|
12227
|
-
getGlobalConfigPath,
|
|
12228
|
-
getDbcliConfigHome,
|
|
12229
|
-
findCapability,
|
|
12230
|
-
envVarNameFor,
|
|
12231
|
-
detectConfigVersion,
|
|
12232
|
-
checkCapabilities,
|
|
12233
|
-
buildCapabilityCatalog,
|
|
12234
|
-
SchemaLayeredLoader,
|
|
12235
|
-
QueryExecutor,
|
|
12236
|
-
OPERATION_ENVELOPE_SCHEMA_VERSION,
|
|
12237
|
-
DataExecutor,
|
|
12238
|
-
ConnectionError,
|
|
12239
|
-
CapabilityRequirementError,
|
|
12240
|
-
CapabilityContractError,
|
|
12241
|
-
CAPABILITY_CONTRACT_SCHEMA_VERSION,
|
|
12242
|
-
CAPABILITIES,
|
|
12243
|
-
BlacklistValidator,
|
|
11206
|
+
BlacklistError,
|
|
12244
11207
|
BlacklistManager,
|
|
12245
|
-
|
|
11208
|
+
BlacklistValidator,
|
|
11209
|
+
CAPABILITIES,
|
|
11210
|
+
CAPABILITY_CONTRACT_SCHEMA_VERSION,
|
|
11211
|
+
CapabilityContractError,
|
|
11212
|
+
CapabilityRequirementError,
|
|
11213
|
+
ConnectionError,
|
|
11214
|
+
DataExecutor,
|
|
11215
|
+
OPERATION_ENVELOPE_SCHEMA_VERSION,
|
|
11216
|
+
QueryExecutor,
|
|
11217
|
+
SchemaLayeredLoader,
|
|
11218
|
+
buildCapabilityCatalog,
|
|
11219
|
+
checkCapabilities,
|
|
11220
|
+
detectConfigVersion,
|
|
11221
|
+
envVarNameFor,
|
|
11222
|
+
findCapability,
|
|
11223
|
+
getDbcliConfigHome,
|
|
11224
|
+
getGlobalConfigPath,
|
|
11225
|
+
getProjectStoragePath,
|
|
11226
|
+
isGlobalConfigPath,
|
|
11227
|
+
listCapabilityIds,
|
|
11228
|
+
listConnections,
|
|
11229
|
+
loadConnectionEnv,
|
|
11230
|
+
migrateV1ToV2,
|
|
11231
|
+
parseCapabilityCatalog,
|
|
11232
|
+
parseCapabilityCheckReport,
|
|
11233
|
+
parseOperationEnvelope,
|
|
11234
|
+
parseRequirements,
|
|
11235
|
+
readConfig,
|
|
11236
|
+
readV2Config,
|
|
11237
|
+
removeConnection,
|
|
11238
|
+
resolveConfigStoragePath,
|
|
11239
|
+
resolveConnection,
|
|
11240
|
+
resolvePasswordTarget,
|
|
11241
|
+
setConnectionPassword,
|
|
11242
|
+
setDefaultConnection,
|
|
11243
|
+
upsertConnection,
|
|
11244
|
+
writeProjectBinding,
|
|
11245
|
+
writeV2Config
|
|
12246
11246
|
};
|