drizzle-kit 0.20.0-c31f6ba → 0.20.0-ca89eb7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3367 @@
1
+ #!/usr/bin/env node
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
11
+ var __commonJS = (cb, mod) => function __require() {
12
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13
+ };
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27
+ // If the importer is in node compatibility mode or this is not an ESM
28
+ // file that has been converted to a CommonJS file using a Babel-
29
+ // compatible transform (i.e. "__esModule" has not been set), then set
30
+ // "default" to the CommonJS "module.exports" for node compatibility.
31
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
32
+ mod
33
+ ));
34
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
+
36
+ // node_modules/.pnpm/chalk@5.2.0/node_modules/chalk/source/vendor/ansi-styles/index.js
37
+ function assembleStyles() {
38
+ const codes = /* @__PURE__ */ new Map();
39
+ for (const [groupName, group] of Object.entries(styles)) {
40
+ for (const [styleName, style] of Object.entries(group)) {
41
+ styles[styleName] = {
42
+ open: `\x1B[${style[0]}m`,
43
+ close: `\x1B[${style[1]}m`
44
+ };
45
+ group[styleName] = styles[styleName];
46
+ codes.set(style[0], style[1]);
47
+ }
48
+ Object.defineProperty(styles, groupName, {
49
+ value: group,
50
+ enumerable: false
51
+ });
52
+ }
53
+ Object.defineProperty(styles, "codes", {
54
+ value: codes,
55
+ enumerable: false
56
+ });
57
+ styles.color.close = "\x1B[39m";
58
+ styles.bgColor.close = "\x1B[49m";
59
+ styles.color.ansi = wrapAnsi16();
60
+ styles.color.ansi256 = wrapAnsi256();
61
+ styles.color.ansi16m = wrapAnsi16m();
62
+ styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
63
+ styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
64
+ styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
65
+ Object.defineProperties(styles, {
66
+ rgbToAnsi256: {
67
+ value(red, green, blue) {
68
+ if (red === green && green === blue) {
69
+ if (red < 8) {
70
+ return 16;
71
+ }
72
+ if (red > 248) {
73
+ return 231;
74
+ }
75
+ return Math.round((red - 8) / 247 * 24) + 232;
76
+ }
77
+ return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
78
+ },
79
+ enumerable: false
80
+ },
81
+ hexToRgb: {
82
+ value(hex) {
83
+ const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
84
+ if (!matches) {
85
+ return [0, 0, 0];
86
+ }
87
+ let [colorString] = matches;
88
+ if (colorString.length === 3) {
89
+ colorString = [...colorString].map((character) => character + character).join("");
90
+ }
91
+ const integer = Number.parseInt(colorString, 16);
92
+ return [
93
+ /* eslint-disable no-bitwise */
94
+ integer >> 16 & 255,
95
+ integer >> 8 & 255,
96
+ integer & 255
97
+ /* eslint-enable no-bitwise */
98
+ ];
99
+ },
100
+ enumerable: false
101
+ },
102
+ hexToAnsi256: {
103
+ value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
104
+ enumerable: false
105
+ },
106
+ ansi256ToAnsi: {
107
+ value(code) {
108
+ if (code < 8) {
109
+ return 30 + code;
110
+ }
111
+ if (code < 16) {
112
+ return 90 + (code - 8);
113
+ }
114
+ let red;
115
+ let green;
116
+ let blue;
117
+ if (code >= 232) {
118
+ red = ((code - 232) * 10 + 8) / 255;
119
+ green = red;
120
+ blue = red;
121
+ } else {
122
+ code -= 16;
123
+ const remainder = code % 36;
124
+ red = Math.floor(code / 36) / 5;
125
+ green = Math.floor(remainder / 6) / 5;
126
+ blue = remainder % 6 / 5;
127
+ }
128
+ const value = Math.max(red, green, blue) * 2;
129
+ if (value === 0) {
130
+ return 30;
131
+ }
132
+ let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
133
+ if (value === 2) {
134
+ result += 60;
135
+ }
136
+ return result;
137
+ },
138
+ enumerable: false
139
+ },
140
+ rgbToAnsi: {
141
+ value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
142
+ enumerable: false
143
+ },
144
+ hexToAnsi: {
145
+ value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
146
+ enumerable: false
147
+ }
148
+ });
149
+ return styles;
150
+ }
151
+ var ANSI_BACKGROUND_OFFSET, wrapAnsi16, wrapAnsi256, wrapAnsi16m, styles, modifierNames, foregroundColorNames, backgroundColorNames, colorNames, ansiStyles, ansi_styles_default;
152
+ var init_ansi_styles = __esm({
153
+ "node_modules/.pnpm/chalk@5.2.0/node_modules/chalk/source/vendor/ansi-styles/index.js"() {
154
+ ANSI_BACKGROUND_OFFSET = 10;
155
+ wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
156
+ wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
157
+ wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
158
+ styles = {
159
+ modifier: {
160
+ reset: [0, 0],
161
+ // 21 isn't widely supported and 22 does the same thing
162
+ bold: [1, 22],
163
+ dim: [2, 22],
164
+ italic: [3, 23],
165
+ underline: [4, 24],
166
+ overline: [53, 55],
167
+ inverse: [7, 27],
168
+ hidden: [8, 28],
169
+ strikethrough: [9, 29]
170
+ },
171
+ color: {
172
+ black: [30, 39],
173
+ red: [31, 39],
174
+ green: [32, 39],
175
+ yellow: [33, 39],
176
+ blue: [34, 39],
177
+ magenta: [35, 39],
178
+ cyan: [36, 39],
179
+ white: [37, 39],
180
+ // Bright color
181
+ blackBright: [90, 39],
182
+ gray: [90, 39],
183
+ // Alias of `blackBright`
184
+ grey: [90, 39],
185
+ // Alias of `blackBright`
186
+ redBright: [91, 39],
187
+ greenBright: [92, 39],
188
+ yellowBright: [93, 39],
189
+ blueBright: [94, 39],
190
+ magentaBright: [95, 39],
191
+ cyanBright: [96, 39],
192
+ whiteBright: [97, 39]
193
+ },
194
+ bgColor: {
195
+ bgBlack: [40, 49],
196
+ bgRed: [41, 49],
197
+ bgGreen: [42, 49],
198
+ bgYellow: [43, 49],
199
+ bgBlue: [44, 49],
200
+ bgMagenta: [45, 49],
201
+ bgCyan: [46, 49],
202
+ bgWhite: [47, 49],
203
+ // Bright color
204
+ bgBlackBright: [100, 49],
205
+ bgGray: [100, 49],
206
+ // Alias of `bgBlackBright`
207
+ bgGrey: [100, 49],
208
+ // Alias of `bgBlackBright`
209
+ bgRedBright: [101, 49],
210
+ bgGreenBright: [102, 49],
211
+ bgYellowBright: [103, 49],
212
+ bgBlueBright: [104, 49],
213
+ bgMagentaBright: [105, 49],
214
+ bgCyanBright: [106, 49],
215
+ bgWhiteBright: [107, 49]
216
+ }
217
+ };
218
+ modifierNames = Object.keys(styles.modifier);
219
+ foregroundColorNames = Object.keys(styles.color);
220
+ backgroundColorNames = Object.keys(styles.bgColor);
221
+ colorNames = [...foregroundColorNames, ...backgroundColorNames];
222
+ ansiStyles = assembleStyles();
223
+ ansi_styles_default = ansiStyles;
224
+ }
225
+ });
226
+
227
+ // node_modules/.pnpm/chalk@5.2.0/node_modules/chalk/source/vendor/supports-color/index.js
228
+ function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : import_node_process.default.argv) {
229
+ const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
230
+ const position = argv.indexOf(prefix + flag);
231
+ const terminatorPosition = argv.indexOf("--");
232
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
233
+ }
234
+ function envForceColor() {
235
+ if ("FORCE_COLOR" in env) {
236
+ if (env.FORCE_COLOR === "true") {
237
+ return 1;
238
+ }
239
+ if (env.FORCE_COLOR === "false") {
240
+ return 0;
241
+ }
242
+ return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
243
+ }
244
+ }
245
+ function translateLevel(level) {
246
+ if (level === 0) {
247
+ return false;
248
+ }
249
+ return {
250
+ level,
251
+ hasBasic: true,
252
+ has256: level >= 2,
253
+ has16m: level >= 3
254
+ };
255
+ }
256
+ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
257
+ const noFlagForceColor = envForceColor();
258
+ if (noFlagForceColor !== void 0) {
259
+ flagForceColor = noFlagForceColor;
260
+ }
261
+ const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
262
+ if (forceColor === 0) {
263
+ return 0;
264
+ }
265
+ if (sniffFlags) {
266
+ if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
267
+ return 3;
268
+ }
269
+ if (hasFlag("color=256")) {
270
+ return 2;
271
+ }
272
+ }
273
+ if ("TF_BUILD" in env && "AGENT_NAME" in env) {
274
+ return 1;
275
+ }
276
+ if (haveStream && !streamIsTTY && forceColor === void 0) {
277
+ return 0;
278
+ }
279
+ const min = forceColor || 0;
280
+ if (env.TERM === "dumb") {
281
+ return min;
282
+ }
283
+ if (import_node_process.default.platform === "win32") {
284
+ const osRelease = import_node_os.default.release().split(".");
285
+ if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
286
+ return Number(osRelease[2]) >= 14931 ? 3 : 2;
287
+ }
288
+ return 1;
289
+ }
290
+ if ("CI" in env) {
291
+ if ("GITHUB_ACTIONS" in env) {
292
+ return 3;
293
+ }
294
+ if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
295
+ return 1;
296
+ }
297
+ return min;
298
+ }
299
+ if ("TEAMCITY_VERSION" in env) {
300
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
301
+ }
302
+ if (env.COLORTERM === "truecolor") {
303
+ return 3;
304
+ }
305
+ if (env.TERM === "xterm-kitty") {
306
+ return 3;
307
+ }
308
+ if ("TERM_PROGRAM" in env) {
309
+ const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
310
+ switch (env.TERM_PROGRAM) {
311
+ case "iTerm.app": {
312
+ return version >= 3 ? 3 : 2;
313
+ }
314
+ case "Apple_Terminal": {
315
+ return 2;
316
+ }
317
+ }
318
+ }
319
+ if (/-256(color)?$/i.test(env.TERM)) {
320
+ return 2;
321
+ }
322
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
323
+ return 1;
324
+ }
325
+ if ("COLORTERM" in env) {
326
+ return 1;
327
+ }
328
+ return min;
329
+ }
330
+ function createSupportsColor(stream, options = {}) {
331
+ const level = _supportsColor(stream, {
332
+ streamIsTTY: stream && stream.isTTY,
333
+ ...options
334
+ });
335
+ return translateLevel(level);
336
+ }
337
+ var import_node_process, import_node_os, import_node_tty, env, flagForceColor, supportsColor, supports_color_default;
338
+ var init_supports_color = __esm({
339
+ "node_modules/.pnpm/chalk@5.2.0/node_modules/chalk/source/vendor/supports-color/index.js"() {
340
+ import_node_process = __toESM(require("node:process"), 1);
341
+ import_node_os = __toESM(require("node:os"), 1);
342
+ import_node_tty = __toESM(require("node:tty"), 1);
343
+ ({ env } = import_node_process.default);
344
+ if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
345
+ flagForceColor = 0;
346
+ } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
347
+ flagForceColor = 1;
348
+ }
349
+ supportsColor = {
350
+ stdout: createSupportsColor({ isTTY: import_node_tty.default.isatty(1) }),
351
+ stderr: createSupportsColor({ isTTY: import_node_tty.default.isatty(2) })
352
+ };
353
+ supports_color_default = supportsColor;
354
+ }
355
+ });
356
+
357
+ // node_modules/.pnpm/chalk@5.2.0/node_modules/chalk/source/utilities.js
358
+ function stringReplaceAll(string, substring, replacer) {
359
+ let index = string.indexOf(substring);
360
+ if (index === -1) {
361
+ return string;
362
+ }
363
+ const substringLength = substring.length;
364
+ let endIndex = 0;
365
+ let returnValue = "";
366
+ do {
367
+ returnValue += string.slice(endIndex, index) + substring + replacer;
368
+ endIndex = index + substringLength;
369
+ index = string.indexOf(substring, endIndex);
370
+ } while (index !== -1);
371
+ returnValue += string.slice(endIndex);
372
+ return returnValue;
373
+ }
374
+ function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
375
+ let endIndex = 0;
376
+ let returnValue = "";
377
+ do {
378
+ const gotCR = string[index - 1] === "\r";
379
+ returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
380
+ endIndex = index + 1;
381
+ index = string.indexOf("\n", endIndex);
382
+ } while (index !== -1);
383
+ returnValue += string.slice(endIndex);
384
+ return returnValue;
385
+ }
386
+ var init_utilities = __esm({
387
+ "node_modules/.pnpm/chalk@5.2.0/node_modules/chalk/source/utilities.js"() {
388
+ }
389
+ });
390
+
391
+ // node_modules/.pnpm/chalk@5.2.0/node_modules/chalk/source/index.js
392
+ function createChalk(options) {
393
+ return chalkFactory(options);
394
+ }
395
+ var stdoutColor, stderrColor, GENERATOR, STYLER, IS_EMPTY, levelMapping, styles2, applyOptions, chalkFactory, getModelAnsi, usedModels, proto, createStyler, createBuilder, applyStyle, chalk, chalkStderr;
396
+ var init_source = __esm({
397
+ "node_modules/.pnpm/chalk@5.2.0/node_modules/chalk/source/index.js"() {
398
+ init_ansi_styles();
399
+ init_supports_color();
400
+ init_utilities();
401
+ init_ansi_styles();
402
+ ({ stdout: stdoutColor, stderr: stderrColor } = supports_color_default);
403
+ GENERATOR = Symbol("GENERATOR");
404
+ STYLER = Symbol("STYLER");
405
+ IS_EMPTY = Symbol("IS_EMPTY");
406
+ levelMapping = [
407
+ "ansi",
408
+ "ansi",
409
+ "ansi256",
410
+ "ansi16m"
411
+ ];
412
+ styles2 = /* @__PURE__ */ Object.create(null);
413
+ applyOptions = (object, options = {}) => {
414
+ if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
415
+ throw new Error("The `level` option should be an integer from 0 to 3");
416
+ }
417
+ const colorLevel = stdoutColor ? stdoutColor.level : 0;
418
+ object.level = options.level === void 0 ? colorLevel : options.level;
419
+ };
420
+ chalkFactory = (options) => {
421
+ const chalk2 = (...strings) => strings.join(" ");
422
+ applyOptions(chalk2, options);
423
+ Object.setPrototypeOf(chalk2, createChalk.prototype);
424
+ return chalk2;
425
+ };
426
+ Object.setPrototypeOf(createChalk.prototype, Function.prototype);
427
+ for (const [styleName, style] of Object.entries(ansi_styles_default)) {
428
+ styles2[styleName] = {
429
+ get() {
430
+ const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
431
+ Object.defineProperty(this, styleName, { value: builder });
432
+ return builder;
433
+ }
434
+ };
435
+ }
436
+ styles2.visible = {
437
+ get() {
438
+ const builder = createBuilder(this, this[STYLER], true);
439
+ Object.defineProperty(this, "visible", { value: builder });
440
+ return builder;
441
+ }
442
+ };
443
+ getModelAnsi = (model, level, type, ...arguments_) => {
444
+ if (model === "rgb") {
445
+ if (level === "ansi16m") {
446
+ return ansi_styles_default[type].ansi16m(...arguments_);
447
+ }
448
+ if (level === "ansi256") {
449
+ return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
450
+ }
451
+ return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
452
+ }
453
+ if (model === "hex") {
454
+ return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
455
+ }
456
+ return ansi_styles_default[type][model](...arguments_);
457
+ };
458
+ usedModels = ["rgb", "hex", "ansi256"];
459
+ for (const model of usedModels) {
460
+ styles2[model] = {
461
+ get() {
462
+ const { level } = this;
463
+ return function(...arguments_) {
464
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
465
+ return createBuilder(this, styler, this[IS_EMPTY]);
466
+ };
467
+ }
468
+ };
469
+ const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
470
+ styles2[bgModel] = {
471
+ get() {
472
+ const { level } = this;
473
+ return function(...arguments_) {
474
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
475
+ return createBuilder(this, styler, this[IS_EMPTY]);
476
+ };
477
+ }
478
+ };
479
+ }
480
+ proto = Object.defineProperties(() => {
481
+ }, {
482
+ ...styles2,
483
+ level: {
484
+ enumerable: true,
485
+ get() {
486
+ return this[GENERATOR].level;
487
+ },
488
+ set(level) {
489
+ this[GENERATOR].level = level;
490
+ }
491
+ }
492
+ });
493
+ createStyler = (open, close, parent) => {
494
+ let openAll;
495
+ let closeAll;
496
+ if (parent === void 0) {
497
+ openAll = open;
498
+ closeAll = close;
499
+ } else {
500
+ openAll = parent.openAll + open;
501
+ closeAll = close + parent.closeAll;
502
+ }
503
+ return {
504
+ open,
505
+ close,
506
+ openAll,
507
+ closeAll,
508
+ parent
509
+ };
510
+ };
511
+ createBuilder = (self2, _styler, _isEmpty) => {
512
+ const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
513
+ Object.setPrototypeOf(builder, proto);
514
+ builder[GENERATOR] = self2;
515
+ builder[STYLER] = _styler;
516
+ builder[IS_EMPTY] = _isEmpty;
517
+ return builder;
518
+ };
519
+ applyStyle = (self2, string) => {
520
+ if (self2.level <= 0 || !string) {
521
+ return self2[IS_EMPTY] ? "" : string;
522
+ }
523
+ let styler = self2[STYLER];
524
+ if (styler === void 0) {
525
+ return string;
526
+ }
527
+ const { openAll, closeAll } = styler;
528
+ if (string.includes("\x1B")) {
529
+ while (styler !== void 0) {
530
+ string = stringReplaceAll(string, styler.close, styler.open);
531
+ styler = styler.parent;
532
+ }
533
+ }
534
+ const lfIndex = string.indexOf("\n");
535
+ if (lfIndex !== -1) {
536
+ string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
537
+ }
538
+ return openAll + string + closeAll;
539
+ };
540
+ Object.defineProperties(createChalk.prototype, styles2);
541
+ chalk = createChalk();
542
+ chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
543
+ }
544
+ });
545
+
546
+ // src/serializer/index.ts
547
+ var glob;
548
+ var init_serializer = __esm({
549
+ "src/serializer/index.ts"() {
550
+ glob = __toESM(require("glob"));
551
+ init_source();
552
+ }
553
+ });
554
+
555
+ // src/cli/validations/outputs.ts
556
+ var init_outputs = __esm({
557
+ "src/cli/validations/outputs.ts"() {
558
+ init_source();
559
+ }
560
+ });
561
+
562
+ // src/serializer/pgSerializer.ts
563
+ var import_pg_core, import_pg_core2, import_drizzle_orm, dialect, trimChar, fromDatabase, columnToDefault, defaultForColumn, toDrizzle;
564
+ var init_pgSerializer = __esm({
565
+ "src/serializer/pgSerializer.ts"() {
566
+ import_pg_core = require("drizzle-orm/pg-core");
567
+ import_pg_core2 = require("drizzle-orm/pg-core");
568
+ import_drizzle_orm = require("drizzle-orm");
569
+ init_serializer();
570
+ init_source();
571
+ init_outputs();
572
+ dialect = new import_pg_core.PgDialect();
573
+ trimChar = (str, char) => {
574
+ let start = 0;
575
+ let end = str.length;
576
+ while (start < end && str[start] === char)
577
+ ++start;
578
+ while (end > start && str[end - 1] === char)
579
+ --end;
580
+ return start > 0 || end < str.length ? str.substring(start, end) : str.toString();
581
+ };
582
+ fromDatabase = async (db, tablesFilter = (table) => true, schemaFilters, progressCallback) => {
583
+ const result = {};
584
+ const internals = { tables: {} };
585
+ const where = schemaFilters.map((t) => `table_schema = '${t}'`).join(" or ");
586
+ const allTables = await db.query(
587
+ `SELECT table_schema, table_name FROM information_schema.tables WHERE ${where};`
588
+ );
589
+ const schemas = new Set(allTables.map((it) => it.table_schema));
590
+ schemas.delete("public");
591
+ const allSchemas = await db.query(`select s.nspname as table_schema
592
+ from pg_catalog.pg_namespace s
593
+ join pg_catalog.pg_user u on u.usesysid = s.nspowner
594
+ where nspname not in ('information_schema', 'pg_catalog', 'public')
595
+ and nspname not like 'pg_toast%'
596
+ and nspname not like 'pg_temp_%'
597
+ order by table_schema;`);
598
+ allSchemas.forEach((item) => {
599
+ if (schemaFilters.includes(item.table_schema)) {
600
+ schemas.add(item.table_schema);
601
+ }
602
+ });
603
+ let columnsCount = 0;
604
+ let indexesCount = 0;
605
+ let foreignKeysCount = 0;
606
+ let tableCount = 0;
607
+ const all = allTables.map((row) => {
608
+ return new Promise(async (res, rej) => {
609
+ const tableName = row.table_name;
610
+ if (!tablesFilter(tableName))
611
+ return res("");
612
+ tableCount += 1;
613
+ const tableSchema = row.table_schema;
614
+ try {
615
+ const columnToReturn = {};
616
+ const indexToReturn = {};
617
+ const foreignKeysToReturn = {};
618
+ const primaryKeys = {};
619
+ const uniqueConstrains = {};
620
+ const tableResponse = await db.query(
621
+ `SELECT a.attrelid::regclass::text, a.attname, is_nullable, a.attndims as array_dimensions
622
+ , CASE WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[])
623
+ AND EXISTS (
624
+ SELECT FROM pg_attrdef ad
625
+ WHERE ad.adrelid = a.attrelid
626
+ AND ad.adnum = a.attnum
627
+ AND pg_get_expr(ad.adbin, ad.adrelid)
628
+ = 'nextval('''
629
+ || (pg_get_serial_sequence (a.attrelid::regclass::text
630
+ , a.attname))::regclass
631
+ || '''::regclass)'
632
+ )
633
+ THEN CASE a.atttypid
634
+ WHEN 'int'::regtype THEN 'serial'
635
+ WHEN 'int8'::regtype THEN 'bigserial'
636
+ WHEN 'int2'::regtype THEN 'smallserial'
637
+ END
638
+ ELSE format_type(a.atttypid, a.atttypmod)
639
+ END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name, INFORMATION_SCHEMA.COLUMNS.column_name, INFORMATION_SCHEMA.COLUMNS.column_default, INFORMATION_SCHEMA.COLUMNS.data_type as additional_dt
640
+ FROM pg_attribute a
641
+ JOIN INFORMATION_SCHEMA.COLUMNS ON INFORMATION_SCHEMA.COLUMNS.column_name = a.attname
642
+ WHERE a.attrelid = '"${tableSchema}"."${tableName}"'::regclass and INFORMATION_SCHEMA.COLUMNS.table_name = '${tableName}'
643
+ AND a.attnum > 0
644
+ AND NOT a.attisdropped
645
+ ORDER BY a.attnum;`
646
+ );
647
+ const tableConstraints = await db.query(
648
+ `SELECT c.column_name, c.data_type, constraint_type, constraint_name, constraint_schema
649
+ FROM information_schema.table_constraints tc
650
+ JOIN information_schema.constraint_column_usage AS ccu USING (constraint_schema, constraint_name)
651
+ JOIN information_schema.columns AS c ON c.table_schema = tc.constraint_schema
652
+ AND tc.table_name = c.table_name AND ccu.column_name = c.column_name
653
+ WHERE tc.table_name = '${tableName}' and constraint_schema = '${tableSchema}';`
654
+ );
655
+ columnsCount += tableResponse.length;
656
+ if (progressCallback) {
657
+ progressCallback("columns", columnsCount, "fetching");
658
+ }
659
+ const tableForeignKeys = await db.query(
660
+ `SELECT
661
+ tc.table_schema,
662
+ tc.constraint_name,
663
+ tc.table_name,
664
+ kcu.column_name,
665
+ ccu.table_schema AS foreign_table_schema,
666
+ ccu.table_name AS foreign_table_name,
667
+ ccu.column_name AS foreign_column_name,
668
+ rc.delete_rule, rc.update_rule
669
+ FROM
670
+ information_schema.table_constraints AS tc
671
+ JOIN information_schema.key_column_usage AS kcu
672
+ ON tc.constraint_name = kcu.constraint_name
673
+ AND tc.table_schema = kcu.table_schema
674
+ JOIN information_schema.constraint_column_usage AS ccu
675
+ ON ccu.constraint_name = tc.constraint_name
676
+ AND ccu.table_schema = tc.table_schema
677
+ JOIN information_schema.referential_constraints AS rc
678
+ ON ccu.constraint_name = rc.constraint_name
679
+ WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name='${tableName}' and tc.table_schema='${tableSchema}';`
680
+ );
681
+ foreignKeysCount += tableForeignKeys.length;
682
+ if (progressCallback) {
683
+ progressCallback("fks", foreignKeysCount, "fetching");
684
+ }
685
+ for (const fk of tableForeignKeys) {
686
+ const columnFrom = fk.column_name;
687
+ const tableTo = fk.foreign_table_name;
688
+ const columnTo = fk.foreign_column_name;
689
+ const foreignKeyName = fk.constraint_name;
690
+ const onUpdate = fk.update_rule.toLowerCase();
691
+ const onDelete = fk.delete_rule.toLowerCase();
692
+ if (typeof foreignKeysToReturn[foreignKeyName] !== "undefined") {
693
+ foreignKeysToReturn[foreignKeyName].columnsFrom.push(columnFrom);
694
+ foreignKeysToReturn[foreignKeyName].columnsTo.push(columnTo);
695
+ } else {
696
+ foreignKeysToReturn[foreignKeyName] = {
697
+ name: foreignKeyName,
698
+ tableFrom: tableName,
699
+ tableTo,
700
+ columnsFrom: [columnFrom],
701
+ columnsTo: [columnTo],
702
+ onDelete,
703
+ onUpdate
704
+ };
705
+ }
706
+ foreignKeysToReturn[foreignKeyName].columnsFrom = [
707
+ ...new Set(foreignKeysToReturn[foreignKeyName].columnsFrom)
708
+ ];
709
+ foreignKeysToReturn[foreignKeyName].columnsTo = [
710
+ ...new Set(foreignKeysToReturn[foreignKeyName].columnsTo)
711
+ ];
712
+ }
713
+ const uniqueConstrainsRows = tableConstraints.filter(
714
+ (mapRow) => mapRow.constraint_type === "UNIQUE"
715
+ );
716
+ for (const unqs of uniqueConstrainsRows) {
717
+ const columnName = unqs.column_name;
718
+ const constraintName = unqs.constraint_name;
719
+ if (typeof uniqueConstrains[constraintName] !== "undefined") {
720
+ uniqueConstrains[constraintName].columns.push(columnName);
721
+ } else {
722
+ uniqueConstrains[constraintName] = {
723
+ columns: [columnName],
724
+ nullsNotDistinct: false,
725
+ name: constraintName
726
+ };
727
+ }
728
+ }
729
+ for (const columnResponse of tableResponse) {
730
+ const columnName = columnResponse.attname;
731
+ const columnAdditionalDT = columnResponse.additional_dt;
732
+ const columnDimensions = columnResponse.array_dimensions;
733
+ let columnType = columnResponse.data_type;
734
+ const primaryKey = tableConstraints.filter(
735
+ (mapRow) => columnName === mapRow.column_name && mapRow.constraint_type === "PRIMARY KEY"
736
+ );
737
+ const cprimaryKey = tableConstraints.filter(
738
+ (mapRow) => mapRow.constraint_type === "PRIMARY KEY"
739
+ );
740
+ if (cprimaryKey.length > 1) {
741
+ const tableCompositePkName = await db.query(
742
+ `SELECT conname AS primary_key
743
+ FROM pg_constraint
744
+ WHERE contype = 'p'
745
+ AND connamespace = '${tableSchema}'::regnamespace
746
+ AND (conrelid::regclass::text = '"${tableName}"' OR conrelid::regclass::text = '${tableName}');`
747
+ );
748
+ primaryKeys[`${tableName}_${cprimaryKey.map((pk) => pk.column_name).join("_")}`] = {
749
+ name: tableCompositePkName[0].primary_key,
750
+ columns: cprimaryKey.map((c) => c.column_name)
751
+ };
752
+ }
753
+ const defaultValue = defaultForColumn(columnResponse);
754
+ const isSerial = columnType === "serial";
755
+ let columnTypeMapped = columnType;
756
+ if (columnTypeMapped.startsWith("numeric(")) {
757
+ columnTypeMapped = columnTypeMapped.replace(",", ", ");
758
+ }
759
+ if (columnAdditionalDT === "ARRAY") {
760
+ if (typeof internals.tables[tableName] === "undefined") {
761
+ internals.tables[tableName] = {
762
+ columns: {
763
+ [columnName]: {
764
+ isArray: true,
765
+ dimensions: columnDimensions,
766
+ rawType: columnTypeMapped.substring(
767
+ 0,
768
+ columnTypeMapped.length - 2
769
+ )
770
+ }
771
+ }
772
+ };
773
+ } else {
774
+ if (typeof internals.tables[tableName].columns[columnName] === "undefined") {
775
+ internals.tables[tableName].columns[columnName] = {
776
+ isArray: true,
777
+ dimensions: columnDimensions,
778
+ rawType: columnTypeMapped.substring(
779
+ 0,
780
+ columnTypeMapped.length - 2
781
+ )
782
+ };
783
+ }
784
+ }
785
+ }
786
+ if (columnAdditionalDT === "ARRAY") {
787
+ for (let i = 1; i < Number(columnDimensions); i++) {
788
+ columnTypeMapped += "[]";
789
+ }
790
+ }
791
+ columnTypeMapped = columnTypeMapped.replace("character varying", "varchar").replace(" without time zone", "").replace("character", "char");
792
+ columnTypeMapped = trimChar(columnTypeMapped, '"');
793
+ columnToReturn[columnName] = {
794
+ name: columnName,
795
+ type: columnTypeMapped,
796
+ primaryKey: primaryKey.length === 1 && cprimaryKey.length < 2,
797
+ // default: isSerial ? undefined : defaultValue,
798
+ notNull: columnResponse.is_nullable === "NO"
799
+ };
800
+ if (!isSerial && typeof defaultValue !== "undefined") {
801
+ columnToReturn[columnName].default = defaultValue;
802
+ }
803
+ }
804
+ const dbIndexes = await db.query(
805
+ `SELECT t.relname as table_name, i.relname AS index_name, ix.indisunique AS is_unique, a.attname AS column_name
806
+ FROM pg_class t
807
+ JOIN pg_index ix ON t.oid = ix.indrelid
808
+ JOIN pg_class i ON i.oid = ix.indexrelid
809
+ JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = ANY(ix.indkey)
810
+ JOIN pg_namespace ns ON ns.oid = t.relnamespace
811
+ WHERE ns.nspname = '${tableSchema}'
812
+ AND t.relname = '${tableName}'
813
+ and ix.indisprimary = false;`
814
+ );
815
+ const dbIndexFromConstraint = await db.query(
816
+ `SELECT
817
+ idx.indexrelname AS index_name,
818
+ idx.relname AS table_name,
819
+ schemaname,
820
+ CASE WHEN con.conname IS NOT NULL THEN 1 ELSE 0 END AS generated_by_constraint
821
+ FROM
822
+ pg_stat_user_indexes idx
823
+ LEFT JOIN
824
+ pg_constraint con ON con.conindid = idx.indexrelid
825
+ WHERE idx.relname = '${tableName}' and schemaname = '${tableSchema}'
826
+ group by index_name, table_name,schemaname, generated_by_constraint;`
827
+ );
828
+ const idxsInConsteraint = dbIndexFromConstraint.filter((it) => it.generated_by_constraint === 1).map((it) => it.index_name);
829
+ for (const dbIndex of dbIndexes) {
830
+ const indexName2 = dbIndex.index_name;
831
+ const indexColumnName = dbIndex.column_name;
832
+ const indexIsUnique = dbIndex.is_unique;
833
+ if (idxsInConsteraint.includes(indexName2))
834
+ continue;
835
+ if (typeof indexToReturn[indexName2] !== "undefined") {
836
+ indexToReturn[indexName2].columns.push(indexColumnName);
837
+ } else {
838
+ indexToReturn[indexName2] = {
839
+ name: indexName2,
840
+ columns: [indexColumnName],
841
+ isUnique: indexIsUnique
842
+ };
843
+ }
844
+ }
845
+ indexesCount += Object.keys(indexToReturn).length;
846
+ if (progressCallback) {
847
+ progressCallback("indexes", indexesCount, "fetching");
848
+ }
849
+ result[tableName] = {
850
+ name: tableName,
851
+ schema: tableSchema !== "public" ? tableSchema : "",
852
+ columns: columnToReturn,
853
+ indexes: indexToReturn,
854
+ foreignKeys: foreignKeysToReturn,
855
+ compositePrimaryKeys: primaryKeys,
856
+ uniqueConstraints: uniqueConstrains
857
+ };
858
+ } catch (e) {
859
+ rej(e);
860
+ return;
861
+ }
862
+ res("");
863
+ });
864
+ });
865
+ if (progressCallback) {
866
+ progressCallback("tables", tableCount, "done");
867
+ }
868
+ for await (const _ of all) {
869
+ }
870
+ if (progressCallback) {
871
+ progressCallback("columns", columnsCount, "done");
872
+ progressCallback("indexes", indexesCount, "done");
873
+ progressCallback("fks", foreignKeysCount, "done");
874
+ }
875
+ const allEnums = await db.query(
876
+ `select n.nspname as enum_schema,
877
+ t.typname as enum_name,
878
+ e.enumlabel as enum_value
879
+ from pg_type t
880
+ join pg_enum e on t.oid = e.enumtypid
881
+ join pg_catalog.pg_namespace n ON n.oid = t.typnamespace;`
882
+ );
883
+ const enumsToReturn = {};
884
+ for (const dbEnum of allEnums) {
885
+ const enumName = dbEnum.enum_name;
886
+ const enumValue = dbEnum.enum_value;
887
+ if (enumsToReturn[enumName] !== void 0 && enumsToReturn[enumName] !== null) {
888
+ enumsToReturn[enumName].values[enumValue] = enumValue;
889
+ } else {
890
+ enumsToReturn[enumName] = {
891
+ name: enumName,
892
+ values: { [enumValue]: enumValue }
893
+ };
894
+ }
895
+ }
896
+ if (progressCallback) {
897
+ progressCallback("enums", Object.keys(enumsToReturn).length, "done");
898
+ }
899
+ const schemasObject = Object.fromEntries([...schemas].map((it) => [it, it]));
900
+ return {
901
+ version: "5",
902
+ dialect: "pg",
903
+ tables: result,
904
+ enums: enumsToReturn,
905
+ schemas: schemasObject,
906
+ _meta: {
907
+ schemas: {},
908
+ tables: {},
909
+ columns: {}
910
+ },
911
+ internal: internals
912
+ };
913
+ };
914
+ columnToDefault = {
915
+ "numeric(": "::numeric",
916
+ // text: "::text",
917
+ // "character varying": "::character varying",
918
+ // "double precision": "::double precision",
919
+ // "time with time zone": "::time with time zone",
920
+ "time without time zone": "::time without time zone",
921
+ // "timestamp with time zone": "::timestamp with time zone",
922
+ "timestamp without time zone": "::timestamp without time zone",
923
+ // date: "::date",
924
+ // interval: "::interval",
925
+ // character: "::bpchar",
926
+ // macaddr8: "::macaddr8",
927
+ // macaddr: "::macaddr",
928
+ // inet: "::inet",
929
+ // cidr: "::cidr",
930
+ // jsonb: "::jsonb",
931
+ // json: "::json",
932
+ "character(": "::bpchar"
933
+ };
934
+ defaultForColumn = (column) => {
935
+ if (column.data_type === "serial" || column.data_type === "smallserial" || column.data_type === "bigserial") {
936
+ return void 0;
937
+ }
938
+ const hasDifferentDefaultCast = Object.keys(columnToDefault).find(
939
+ (it) => column.data_type.startsWith(it)
940
+ );
941
+ if (column.column_default === null) {
942
+ return void 0;
943
+ }
944
+ const columnDefaultAsString = column.column_default.toString();
945
+ if (columnDefaultAsString.endsWith(
946
+ hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : column.data_type
947
+ )) {
948
+ const nonPrefixPart = column.column_default.length - (hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column.data_type}`).length - 1;
949
+ const rt = column.column_default.toString().substring(1, nonPrefixPart);
950
+ if (/^-?[\d.]+(?:e-?\d+)?$/.test(rt) && !column.data_type.startsWith("numeric")) {
951
+ return Number(rt);
952
+ } else if (column.data_type === "json" || column.data_type === "jsonb") {
953
+ const jsonWithoutSpaces = JSON.stringify(JSON.parse(rt));
954
+ return `'${jsonWithoutSpaces}'${hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column.data_type}`}`;
955
+ } else if (column.data_type === "boolean") {
956
+ return column.column_default === "true";
957
+ } else {
958
+ return `'${rt}'`;
959
+ }
960
+ } else {
961
+ if (/^-?[\d.]+(?:e-?\d+)?$/.test(columnDefaultAsString) && !column.data_type.startsWith("numeric")) {
962
+ return Number(columnDefaultAsString);
963
+ } else if (column.data_type === "boolean") {
964
+ return column.column_default === "true";
965
+ } else {
966
+ return `${columnDefaultAsString}`;
967
+ }
968
+ }
969
+ };
970
+ toDrizzle = (schema, schemaName) => {
971
+ const tables = {};
972
+ Object.values(schema.tables).forEach((t) => {
973
+ const columns = {};
974
+ Object.values(t.columns).forEach((c) => {
975
+ const columnName = c.name;
976
+ const type = c.type;
977
+ let columnBuilder;
978
+ if (type === "bigint") {
979
+ columnBuilder = new import_pg_core.PgBigInt53Builder(columnName);
980
+ } else if (type === "bigserial") {
981
+ columnBuilder = new import_pg_core.PgBigSerial53Builder(columnName);
982
+ } else if (type === "boolean") {
983
+ columnBuilder = new import_pg_core.PgBooleanBuilder(columnName);
984
+ } else if (type === "cidr") {
985
+ columnBuilder = new import_pg_core.PgCidrBuilder(columnName);
986
+ } else if (type === "date") {
987
+ columnBuilder = new import_pg_core.PgDateBuilder(columnName);
988
+ } else if (type === "double precision") {
989
+ columnBuilder = new import_pg_core.PgDoublePrecisionBuilder(columnName);
990
+ } else if (type === "inet") {
991
+ columnBuilder = new import_pg_core.PgInetBuilder(columnName);
992
+ } else if (type === "integer") {
993
+ columnBuilder = new import_pg_core.PgIntegerBuilder(columnName);
994
+ } else if (type === "interval" || type.startsWith("interval ")) {
995
+ columnBuilder = new import_pg_core.PgIntervalBuilder(columnName, {});
996
+ } else if (type === "json") {
997
+ columnBuilder = new import_pg_core.PgJsonBuilder(columnName);
998
+ } else if (type === "jsonb") {
999
+ columnBuilder = new import_pg_core.PgJsonbBuilder(columnName);
1000
+ } else if (type === "macaddr") {
1001
+ columnBuilder = new import_pg_core.PgMacaddrBuilder(columnName);
1002
+ } else if (type === "macaddr8") {
1003
+ columnBuilder = new import_pg_core.PgMacaddr8Builder(columnName);
1004
+ } else if (type === "numeric" || type.startsWith("numeric(")) {
1005
+ columnBuilder = new import_pg_core.PgNumericBuilder(columnName);
1006
+ } else if (type === "real") {
1007
+ columnBuilder = new import_pg_core.PgRealBuilder(columnName);
1008
+ } else if (type === "serial") {
1009
+ columnBuilder = new import_pg_core.PgSerialBuilder(columnName);
1010
+ } else if (type === "smallint") {
1011
+ columnBuilder = new import_pg_core.PgSmallIntBuilder(columnName);
1012
+ } else if (type === "smallserial") {
1013
+ columnBuilder = new import_pg_core.PgSmallSerialBuilder(columnName);
1014
+ } else if (type === "text") {
1015
+ columnBuilder = new import_pg_core.PgTextBuilder(columnName, {});
1016
+ } else if (type === "time" || type.startsWith("time(") || type === "time with time zone") {
1017
+ columnBuilder = new import_pg_core.PgTimeBuilder(columnName, false, void 0);
1018
+ } else if (type === "timestamp" || type.startsWith("timestamp(") || type === "timestamp with time zone") {
1019
+ columnBuilder = new import_pg_core.PgTimestampBuilder(columnName, false, void 0);
1020
+ } else if (type === "uuid") {
1021
+ columnBuilder = new import_pg_core.PgUUIDBuilder(columnName);
1022
+ } else if (type === "varchar" || type.startsWith("varchar(")) {
1023
+ columnBuilder = new import_pg_core.PgVarcharBuilder(columnName, {});
1024
+ } else if (type === "char" || type.startsWith("char(")) {
1025
+ columnBuilder = new import_pg_core.PgCharBuilder(columnName, {});
1026
+ } else {
1027
+ columnBuilder = (0, import_pg_core.customType)({
1028
+ dataType() {
1029
+ return type;
1030
+ }
1031
+ })(columnName);
1032
+ }
1033
+ if (c.notNull) {
1034
+ columnBuilder = columnBuilder.notNull();
1035
+ }
1036
+ if (c.default) {
1037
+ columnBuilder = columnBuilder.default(c.default);
1038
+ }
1039
+ if (c.primaryKey) {
1040
+ columnBuilder = columnBuilder.primaryKey();
1041
+ }
1042
+ columns[columnName] = columnBuilder;
1043
+ });
1044
+ if (schemaName === "public") {
1045
+ tables[t.name] = (0, import_pg_core.pgTable)(t.name, columns, (cb) => {
1046
+ const res = {};
1047
+ Object.values(t.compositePrimaryKeys).forEach((cpk) => {
1048
+ const gh = cpk.columns.map((c) => cb[c]);
1049
+ res[cpk.name] = new import_pg_core.PrimaryKeyBuilder(
1050
+ gh,
1051
+ cpk.name
1052
+ );
1053
+ });
1054
+ return res;
1055
+ });
1056
+ } else {
1057
+ tables[t.name] = (0, import_pg_core.pgSchema)(schemaName).table(t.name, columns, (cb) => {
1058
+ const res = {};
1059
+ Object.values(t.compositePrimaryKeys).forEach((cpk) => {
1060
+ const gh = cpk.columns.map((c) => cb[c]);
1061
+ res[cpk.name] = new import_pg_core.PrimaryKeyBuilder(
1062
+ gh,
1063
+ cpk.name
1064
+ );
1065
+ });
1066
+ return res;
1067
+ });
1068
+ }
1069
+ });
1070
+ return tables;
1071
+ };
1072
+ }
1073
+ });
1074
+
1075
+ // src/serializer/sqliteSerializer.ts
1076
+ function mapSqlToSqliteType(sqlType) {
1077
+ if ([
1078
+ "int",
1079
+ "integer",
1080
+ "integer auto_increment",
1081
+ "tinyint",
1082
+ "smallint",
1083
+ "mediumint",
1084
+ "bigint",
1085
+ "unsigned big int",
1086
+ "int2",
1087
+ "int8"
1088
+ ].includes(sqlType.toLowerCase())) {
1089
+ return "integer";
1090
+ } else if ([
1091
+ "character",
1092
+ "varchar",
1093
+ "vatying character",
1094
+ "nchar",
1095
+ "native character",
1096
+ "nvarchar",
1097
+ "text",
1098
+ "clob"
1099
+ ].some((it) => it.startsWith(sqlType.toLowerCase()))) {
1100
+ return "text";
1101
+ } else if (sqlType.toLowerCase() === "blob") {
1102
+ return "blob";
1103
+ } else if (["real", "double", "double precision", "float"].includes(
1104
+ sqlType.toLowerCase()
1105
+ )) {
1106
+ return "real";
1107
+ } else {
1108
+ return "numeric";
1109
+ }
1110
+ }
1111
+ var import_drizzle_orm2, import_sqlite_core, dialect2, fromDatabase2, toDrizzle2;
1112
+ var init_sqliteSerializer = __esm({
1113
+ "src/serializer/sqliteSerializer.ts"() {
1114
+ import_drizzle_orm2 = require("drizzle-orm");
1115
+ import_sqlite_core = require("drizzle-orm/sqlite-core");
1116
+ init_serializer();
1117
+ init_outputs();
1118
+ init_source();
1119
+ dialect2 = new import_sqlite_core.SQLiteSyncDialect();
1120
+ fromDatabase2 = async (db, tablesFilter = (table) => true, progressCallback) => {
1121
+ const result = {};
1122
+ const columns = await db.query(
1123
+ `SELECT
1124
+ m.name as "tableName", p.name as "columnName", p.type as "columnType", p."notnull" as "notNull", p.dflt_value as "defaultValue", p.pk as pk
1125
+ FROM sqlite_master AS m JOIN pragma_table_info(m.name) AS p
1126
+ WHERE m.type = 'table' and m.tbl_name != 'sqlite_sequence' and m.tbl_name != 'sqlite_stat1' and m.tbl_name != '_litestream_seq' and m.tbl_name != '_litestream_lock' and m.tbl_name != 'libsql_wasm_func_table';
1127
+ `
1128
+ );
1129
+ const tablesWithSeq = [];
1130
+ const seq = await db.query(
1131
+ `SELECT * FROM sqlite_master WHERE name != 'sqlite_sequence' and name != 'sqlite_stat1' and name != '_litestream_seq' and name != '_litestream_lock' and sql GLOB '*[ *' || CHAR(9) || CHAR(10) || CHAR(13) || ']AUTOINCREMENT[^'']*';`
1132
+ );
1133
+ for (const s of seq) {
1134
+ tablesWithSeq.push(s.name);
1135
+ }
1136
+ let columnsCount = 0;
1137
+ let tablesCount = /* @__PURE__ */ new Set();
1138
+ let indexesCount = 0;
1139
+ let foreignKeysCount = 0;
1140
+ const tableToPk = {};
1141
+ for (const column of columns) {
1142
+ if (!tablesFilter(column.tableName))
1143
+ continue;
1144
+ columnsCount += 1;
1145
+ if (progressCallback) {
1146
+ progressCallback("columns", columnsCount, "fetching");
1147
+ }
1148
+ const tableName = column.tableName;
1149
+ tablesCount.add(tableName);
1150
+ if (progressCallback) {
1151
+ progressCallback("tables", tablesCount.size, "fetching");
1152
+ }
1153
+ const columnName = column.columnName;
1154
+ const isNotNull = column.notNull === 1;
1155
+ const columnType = column.columnType;
1156
+ const isPrimary = column.pk !== 0;
1157
+ const columnDefault = column.defaultValue;
1158
+ const isAutoincrement = isPrimary && tablesWithSeq.includes(tableName);
1159
+ if (isPrimary) {
1160
+ if (typeof tableToPk[tableName] === "undefined") {
1161
+ tableToPk[tableName] = [columnName];
1162
+ } else {
1163
+ tableToPk[tableName].push(columnName);
1164
+ }
1165
+ }
1166
+ const table = result[tableName];
1167
+ const newColumn = {
1168
+ default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) ? Number(columnDefault) : ["CURRENT_TIME", "CURRENT_DATE", "CURRENT_TIMESTAMP"].includes(
1169
+ columnDefault
1170
+ ) ? `(${columnDefault})` : columnDefault === "false" ? false : columnDefault === "true" ? true : columnDefault.startsWith("'") && columnDefault.endsWith("'") ? columnDefault : (
1171
+ // ? columnDefault.substring(1, columnDefault.length - 1)
1172
+ `(${columnDefault})`
1173
+ ),
1174
+ autoincrement: isAutoincrement,
1175
+ name: columnName,
1176
+ type: mapSqlToSqliteType(columnType),
1177
+ primaryKey: false,
1178
+ notNull: isNotNull
1179
+ };
1180
+ if (!table) {
1181
+ result[tableName] = {
1182
+ name: tableName,
1183
+ columns: {
1184
+ [columnName]: newColumn
1185
+ },
1186
+ compositePrimaryKeys: {},
1187
+ indexes: {},
1188
+ foreignKeys: {},
1189
+ uniqueConstraints: {}
1190
+ };
1191
+ } else {
1192
+ result[tableName].columns[columnName] = newColumn;
1193
+ }
1194
+ }
1195
+ for (const [key, value] of Object.entries(tableToPk)) {
1196
+ if (value.length > 1) {
1197
+ value.sort();
1198
+ result[key].compositePrimaryKeys = {
1199
+ [`${key}_${value.join("_")}_pk`]: {
1200
+ columns: value,
1201
+ name: `${key}_${value.join("_")}_pk`
1202
+ }
1203
+ };
1204
+ } else if (value.length === 1) {
1205
+ result[key].columns[value[0]].primaryKey = true;
1206
+ } else {
1207
+ }
1208
+ }
1209
+ if (progressCallback) {
1210
+ progressCallback("columns", columnsCount, "done");
1211
+ progressCallback("tables", tablesCount.size, "done");
1212
+ }
1213
+ try {
1214
+ const fks = await db.query(
1215
+ `SELECT m.name as "tableFrom", f.id as "id", f."table" as "tableTo", f."from", f."to", f."on_update" as "onUpdate", f."on_delete" as "onDelete", f.seq as "seq"
1216
+ FROM sqlite_master m, pragma_foreign_key_list(m.name) as f;`
1217
+ );
1218
+ const fkByTableName = {};
1219
+ for (const fkRow of fks) {
1220
+ foreignKeysCount += 1;
1221
+ if (progressCallback) {
1222
+ progressCallback("fks", foreignKeysCount, "fetching");
1223
+ }
1224
+ const tableName = fkRow.tableFrom;
1225
+ const columnName = fkRow.from;
1226
+ const refTableName = fkRow.tableTo;
1227
+ const refColumnName = fkRow.to;
1228
+ const updateRule = fkRow.onUpdate;
1229
+ const deleteRule = fkRow.onDelete;
1230
+ const sequence = fkRow.seq;
1231
+ const id = fkRow.id;
1232
+ const tableInResult = result[tableName];
1233
+ if (typeof tableInResult === "undefined")
1234
+ continue;
1235
+ if (typeof fkByTableName[`${tableName}_${id}`] !== "undefined") {
1236
+ fkByTableName[`${tableName}_${id}`].columnsFrom.push(columnName);
1237
+ fkByTableName[`${tableName}_${id}`].columnsTo.push(refColumnName);
1238
+ } else {
1239
+ fkByTableName[`${tableName}_${id}`] = {
1240
+ name: "",
1241
+ tableFrom: tableName,
1242
+ tableTo: refTableName,
1243
+ columnsFrom: [columnName],
1244
+ columnsTo: [refColumnName],
1245
+ onDelete: deleteRule == null ? void 0 : deleteRule.toLowerCase(),
1246
+ onUpdate: updateRule == null ? void 0 : updateRule.toLowerCase()
1247
+ };
1248
+ }
1249
+ const columnsFrom = fkByTableName[`${tableName}_${id}`].columnsFrom;
1250
+ const columnsTo = fkByTableName[`${tableName}_${id}`].columnsTo;
1251
+ fkByTableName[`${tableName}_${id}`].name = `${tableName}_${columnsFrom.join(
1252
+ "_"
1253
+ )}_${refTableName}_${columnsTo.join("_")}_fk`;
1254
+ }
1255
+ for (const idx of Object.keys(fkByTableName)) {
1256
+ const value = fkByTableName[idx];
1257
+ result[value.tableFrom].foreignKeys[value.name] = value;
1258
+ }
1259
+ } catch (e) {
1260
+ }
1261
+ if (progressCallback) {
1262
+ progressCallback("fks", foreignKeysCount, "done");
1263
+ }
1264
+ const idxs = await db.query(
1265
+ `SELECT
1266
+ m.tbl_name as tableName,
1267
+ il.name as indexName,
1268
+ ii.name as columnName,
1269
+ il.[unique] as isUnique,
1270
+ il.seq as seq
1271
+ FROM sqlite_master AS m,
1272
+ pragma_index_list(m.name) AS il,
1273
+ pragma_index_info(il.name) AS ii
1274
+ WHERE
1275
+ m.type = 'table' and il.name NOT LIKE 'sqlite_autoindex_%';`
1276
+ );
1277
+ for (const idxRow of idxs) {
1278
+ const tableName = idxRow.tableName;
1279
+ const constraintName = idxRow.indexName;
1280
+ const columnName = idxRow.columnName;
1281
+ const isUnique = idxRow.isUnique === 1;
1282
+ const tableInResult = result[tableName];
1283
+ if (typeof tableInResult === "undefined")
1284
+ continue;
1285
+ indexesCount += 1;
1286
+ if (progressCallback) {
1287
+ progressCallback("indexes", indexesCount, "fetching");
1288
+ }
1289
+ if (typeof tableInResult.indexes[constraintName] !== "undefined") {
1290
+ tableInResult.indexes[constraintName].columns.push(columnName);
1291
+ } else {
1292
+ tableInResult.indexes[constraintName] = {
1293
+ name: constraintName,
1294
+ columns: [columnName],
1295
+ isUnique
1296
+ };
1297
+ }
1298
+ }
1299
+ if (progressCallback) {
1300
+ progressCallback("indexes", indexesCount, "done");
1301
+ progressCallback("enums", 0, "done");
1302
+ }
1303
+ return {
1304
+ version: "5",
1305
+ dialect: "sqlite",
1306
+ tables: result,
1307
+ enums: {},
1308
+ _meta: {
1309
+ tables: {},
1310
+ columns: {}
1311
+ }
1312
+ };
1313
+ };
1314
+ toDrizzle2 = (schema) => {
1315
+ const tables = {};
1316
+ Object.values(schema.tables).forEach((t) => {
1317
+ const columns = {};
1318
+ Object.values(t.columns).forEach((c) => {
1319
+ const columnName = c.name;
1320
+ const type = c.type;
1321
+ let columnBuilder;
1322
+ if (type === "integer") {
1323
+ columnBuilder = new import_sqlite_core.SQLiteIntegerBuilder(columnName);
1324
+ } else if (type === "text") {
1325
+ columnBuilder = new import_sqlite_core.SQLiteTextBuilder(columnName, {});
1326
+ } else if (type === "blob") {
1327
+ columnBuilder = new import_sqlite_core.SQLiteBlobBufferBuilder(columnName);
1328
+ } else if (type === "real") {
1329
+ columnBuilder = new import_sqlite_core.SQLiteRealBuilder(columnName);
1330
+ } else {
1331
+ columnBuilder = new import_sqlite_core.SQLiteNumericBuilder(columnName);
1332
+ }
1333
+ if (c.notNull) {
1334
+ columnBuilder = columnBuilder.notNull();
1335
+ }
1336
+ if (c.default) {
1337
+ columnBuilder = columnBuilder.default(c.default);
1338
+ }
1339
+ if (c.primaryKey) {
1340
+ columnBuilder = columnBuilder.primaryKey();
1341
+ }
1342
+ columns[columnName] = columnBuilder;
1343
+ });
1344
+ tables[t.name] = (0, import_sqlite_core.sqliteTable)(t.name, columns, (cb) => {
1345
+ const res = {};
1346
+ Object.values(t.compositePrimaryKeys).forEach((cpk) => {
1347
+ const gh = cpk.columns.map((c) => cb[c]);
1348
+ res[cpk.name] = new import_sqlite_core.PrimaryKeyBuilder(
1349
+ gh,
1350
+ cpk.name
1351
+ );
1352
+ });
1353
+ return res;
1354
+ });
1355
+ });
1356
+ return tables;
1357
+ };
1358
+ }
1359
+ });
1360
+
1361
+ // node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/readline.js
1362
+ var require_readline = __commonJS({
1363
+ "node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/readline.js"(exports) {
1364
+ "use strict";
1365
+ Object.defineProperty(exports, "__esModule", { value: true });
1366
+ exports.prepareReadLine = void 0;
1367
+ var prepareReadLine = () => {
1368
+ const stdin = process.stdin;
1369
+ const stdout = process.stdout;
1370
+ const readline = require("readline");
1371
+ const rl = readline.createInterface({
1372
+ input: stdin,
1373
+ escapeCodeTimeout: 50
1374
+ });
1375
+ readline.emitKeypressEvents(stdin, rl);
1376
+ return {
1377
+ stdin,
1378
+ stdout,
1379
+ closable: rl
1380
+ };
1381
+ };
1382
+ exports.prepareReadLine = prepareReadLine;
1383
+ }
1384
+ });
1385
+
1386
+ // node_modules/.pnpm/sisteransi@1.0.5/node_modules/sisteransi/src/index.js
1387
+ var require_src = __commonJS({
1388
+ "node_modules/.pnpm/sisteransi@1.0.5/node_modules/sisteransi/src/index.js"(exports, module2) {
1389
+ "use strict";
1390
+ var ESC = "\x1B";
1391
+ var CSI = `${ESC}[`;
1392
+ var beep = "\x07";
1393
+ var cursor = {
1394
+ to(x, y) {
1395
+ if (!y)
1396
+ return `${CSI}${x + 1}G`;
1397
+ return `${CSI}${y + 1};${x + 1}H`;
1398
+ },
1399
+ move(x, y) {
1400
+ let ret = "";
1401
+ if (x < 0)
1402
+ ret += `${CSI}${-x}D`;
1403
+ else if (x > 0)
1404
+ ret += `${CSI}${x}C`;
1405
+ if (y < 0)
1406
+ ret += `${CSI}${-y}A`;
1407
+ else if (y > 0)
1408
+ ret += `${CSI}${y}B`;
1409
+ return ret;
1410
+ },
1411
+ up: (count = 1) => `${CSI}${count}A`,
1412
+ down: (count = 1) => `${CSI}${count}B`,
1413
+ forward: (count = 1) => `${CSI}${count}C`,
1414
+ backward: (count = 1) => `${CSI}${count}D`,
1415
+ nextLine: (count = 1) => `${CSI}E`.repeat(count),
1416
+ prevLine: (count = 1) => `${CSI}F`.repeat(count),
1417
+ left: `${CSI}G`,
1418
+ hide: `${CSI}?25l`,
1419
+ show: `${CSI}?25h`,
1420
+ save: `${ESC}7`,
1421
+ restore: `${ESC}8`
1422
+ };
1423
+ var scroll = {
1424
+ up: (count = 1) => `${CSI}S`.repeat(count),
1425
+ down: (count = 1) => `${CSI}T`.repeat(count)
1426
+ };
1427
+ var erase = {
1428
+ screen: `${CSI}2J`,
1429
+ up: (count = 1) => `${CSI}1J`.repeat(count),
1430
+ down: (count = 1) => `${CSI}J`.repeat(count),
1431
+ line: `${CSI}2K`,
1432
+ lineEnd: `${CSI}K`,
1433
+ lineStart: `${CSI}1K`,
1434
+ lines(count) {
1435
+ let clear = "";
1436
+ for (let i = 0; i < count; i++)
1437
+ clear += this.line + (i < count - 1 ? cursor.up() : "");
1438
+ if (count)
1439
+ clear += cursor.left;
1440
+ return clear;
1441
+ }
1442
+ };
1443
+ module2.exports = { cursor, scroll, erase, beep };
1444
+ }
1445
+ });
1446
+
1447
+ // node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/utils.js
1448
+ var require_utils = __commonJS({
1449
+ "node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/utils.js"(exports) {
1450
+ "use strict";
1451
+ Object.defineProperty(exports, "__esModule", { value: true });
1452
+ exports.clear = void 0;
1453
+ var sisteransi_1 = require_src();
1454
+ var strip = (str) => {
1455
+ const pattern = [
1456
+ "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
1457
+ "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
1458
+ ].join("|");
1459
+ const RGX = new RegExp(pattern, "g");
1460
+ return typeof str === "string" ? str.replace(RGX, "") : str;
1461
+ };
1462
+ var stringWidth = (str) => [...strip(str)].length;
1463
+ var clear = function(prompt, perLine) {
1464
+ if (!perLine)
1465
+ return sisteransi_1.erase.line + sisteransi_1.cursor.to(0);
1466
+ let rows = 0;
1467
+ const lines = prompt.split(/\r?\n/);
1468
+ for (let line of lines) {
1469
+ rows += 1 + Math.floor(Math.max(stringWidth(line) - 1, 0) / perLine);
1470
+ }
1471
+ return sisteransi_1.erase.lines(rows);
1472
+ };
1473
+ exports.clear = clear;
1474
+ }
1475
+ });
1476
+
1477
+ // node_modules/.pnpm/lodash.throttle@4.1.1/node_modules/lodash.throttle/index.js
1478
+ var require_lodash = __commonJS({
1479
+ "node_modules/.pnpm/lodash.throttle@4.1.1/node_modules/lodash.throttle/index.js"(exports, module2) {
1480
+ var FUNC_ERROR_TEXT = "Expected a function";
1481
+ var NAN = 0 / 0;
1482
+ var symbolTag = "[object Symbol]";
1483
+ var reTrim = /^\s+|\s+$/g;
1484
+ var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
1485
+ var reIsBinary = /^0b[01]+$/i;
1486
+ var reIsOctal = /^0o[0-7]+$/i;
1487
+ var freeParseInt = parseInt;
1488
+ var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
1489
+ var freeSelf = typeof self == "object" && self && self.Object === Object && self;
1490
+ var root = freeGlobal || freeSelf || Function("return this")();
1491
+ var objectProto = Object.prototype;
1492
+ var objectToString = objectProto.toString;
1493
+ var nativeMax = Math.max;
1494
+ var nativeMin = Math.min;
1495
+ var now = function() {
1496
+ return root.Date.now();
1497
+ };
1498
+ function debounce(func, wait, options) {
1499
+ var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
1500
+ if (typeof func != "function") {
1501
+ throw new TypeError(FUNC_ERROR_TEXT);
1502
+ }
1503
+ wait = toNumber(wait) || 0;
1504
+ if (isObject(options)) {
1505
+ leading = !!options.leading;
1506
+ maxing = "maxWait" in options;
1507
+ maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
1508
+ trailing = "trailing" in options ? !!options.trailing : trailing;
1509
+ }
1510
+ function invokeFunc(time) {
1511
+ var args = lastArgs, thisArg = lastThis;
1512
+ lastArgs = lastThis = void 0;
1513
+ lastInvokeTime = time;
1514
+ result = func.apply(thisArg, args);
1515
+ return result;
1516
+ }
1517
+ function leadingEdge(time) {
1518
+ lastInvokeTime = time;
1519
+ timerId = setTimeout(timerExpired, wait);
1520
+ return leading ? invokeFunc(time) : result;
1521
+ }
1522
+ function remainingWait(time) {
1523
+ var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime, result2 = wait - timeSinceLastCall;
1524
+ return maxing ? nativeMin(result2, maxWait - timeSinceLastInvoke) : result2;
1525
+ }
1526
+ function shouldInvoke(time) {
1527
+ var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime;
1528
+ return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
1529
+ }
1530
+ function timerExpired() {
1531
+ var time = now();
1532
+ if (shouldInvoke(time)) {
1533
+ return trailingEdge(time);
1534
+ }
1535
+ timerId = setTimeout(timerExpired, remainingWait(time));
1536
+ }
1537
+ function trailingEdge(time) {
1538
+ timerId = void 0;
1539
+ if (trailing && lastArgs) {
1540
+ return invokeFunc(time);
1541
+ }
1542
+ lastArgs = lastThis = void 0;
1543
+ return result;
1544
+ }
1545
+ function cancel() {
1546
+ if (timerId !== void 0) {
1547
+ clearTimeout(timerId);
1548
+ }
1549
+ lastInvokeTime = 0;
1550
+ lastArgs = lastCallTime = lastThis = timerId = void 0;
1551
+ }
1552
+ function flush() {
1553
+ return timerId === void 0 ? result : trailingEdge(now());
1554
+ }
1555
+ function debounced() {
1556
+ var time = now(), isInvoking = shouldInvoke(time);
1557
+ lastArgs = arguments;
1558
+ lastThis = this;
1559
+ lastCallTime = time;
1560
+ if (isInvoking) {
1561
+ if (timerId === void 0) {
1562
+ return leadingEdge(lastCallTime);
1563
+ }
1564
+ if (maxing) {
1565
+ timerId = setTimeout(timerExpired, wait);
1566
+ return invokeFunc(lastCallTime);
1567
+ }
1568
+ }
1569
+ if (timerId === void 0) {
1570
+ timerId = setTimeout(timerExpired, wait);
1571
+ }
1572
+ return result;
1573
+ }
1574
+ debounced.cancel = cancel;
1575
+ debounced.flush = flush;
1576
+ return debounced;
1577
+ }
1578
+ function throttle(func, wait, options) {
1579
+ var leading = true, trailing = true;
1580
+ if (typeof func != "function") {
1581
+ throw new TypeError(FUNC_ERROR_TEXT);
1582
+ }
1583
+ if (isObject(options)) {
1584
+ leading = "leading" in options ? !!options.leading : leading;
1585
+ trailing = "trailing" in options ? !!options.trailing : trailing;
1586
+ }
1587
+ return debounce(func, wait, {
1588
+ "leading": leading,
1589
+ "maxWait": wait,
1590
+ "trailing": trailing
1591
+ });
1592
+ }
1593
+ function isObject(value) {
1594
+ var type = typeof value;
1595
+ return !!value && (type == "object" || type == "function");
1596
+ }
1597
+ function isObjectLike(value) {
1598
+ return !!value && typeof value == "object";
1599
+ }
1600
+ function isSymbol(value) {
1601
+ return typeof value == "symbol" || isObjectLike(value) && objectToString.call(value) == symbolTag;
1602
+ }
1603
+ function toNumber(value) {
1604
+ if (typeof value == "number") {
1605
+ return value;
1606
+ }
1607
+ if (isSymbol(value)) {
1608
+ return NAN;
1609
+ }
1610
+ if (isObject(value)) {
1611
+ var other = typeof value.valueOf == "function" ? value.valueOf() : value;
1612
+ value = isObject(other) ? other + "" : other;
1613
+ }
1614
+ if (typeof value != "string") {
1615
+ return value === 0 ? value : +value;
1616
+ }
1617
+ value = value.replace(reTrim, "");
1618
+ var isBinary = reIsBinary.test(value);
1619
+ return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
1620
+ }
1621
+ module2.exports = throttle;
1622
+ }
1623
+ });
1624
+
1625
+ // node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/index.js
1626
+ var require_hanji = __commonJS({
1627
+ "node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/index.js"(exports) {
1628
+ "use strict";
1629
+ var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
1630
+ function adopt(value) {
1631
+ return value instanceof P ? value : new P(function(resolve) {
1632
+ resolve(value);
1633
+ });
1634
+ }
1635
+ return new (P || (P = Promise))(function(resolve, reject) {
1636
+ function fulfilled(value) {
1637
+ try {
1638
+ step(generator.next(value));
1639
+ } catch (e) {
1640
+ reject(e);
1641
+ }
1642
+ }
1643
+ function rejected(value) {
1644
+ try {
1645
+ step(generator["throw"](value));
1646
+ } catch (e) {
1647
+ reject(e);
1648
+ }
1649
+ }
1650
+ function step(result) {
1651
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
1652
+ }
1653
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1654
+ });
1655
+ };
1656
+ var __importDefault = exports && exports.__importDefault || function(mod) {
1657
+ return mod && mod.__esModule ? mod : { "default": mod };
1658
+ };
1659
+ Object.defineProperty(exports, "__esModule", { value: true });
1660
+ exports.onTerminate = exports.renderWithTask = exports.render = exports.TaskTerminal = exports.TaskView = exports.Terminal = exports.deferred = exports.SelectState = exports.Prompt = void 0;
1661
+ var readline_1 = require_readline();
1662
+ var sisteransi_1 = require_src();
1663
+ var utils_1 = require_utils();
1664
+ var lodash_throttle_1 = __importDefault(require_lodash());
1665
+ var Prompt2 = class {
1666
+ constructor() {
1667
+ this.attachCallbacks = [];
1668
+ this.detachCallbacks = [];
1669
+ this.inputCallbacks = [];
1670
+ }
1671
+ requestLayout() {
1672
+ this.terminal.requestLayout();
1673
+ }
1674
+ on(type, callback) {
1675
+ if (type === "attach") {
1676
+ this.attachCallbacks.push(callback);
1677
+ } else if (type === "detach") {
1678
+ this.detachCallbacks.push(callback);
1679
+ } else if (type === "input") {
1680
+ this.inputCallbacks.push(callback);
1681
+ }
1682
+ }
1683
+ attach(terminal) {
1684
+ this.terminal = terminal;
1685
+ this.attachCallbacks.forEach((it) => it(terminal));
1686
+ }
1687
+ detach(terminal) {
1688
+ this.detachCallbacks.forEach((it) => it(terminal));
1689
+ this.terminal = void 0;
1690
+ }
1691
+ input(str, key) {
1692
+ this.inputCallbacks.forEach((it) => it(str, key));
1693
+ }
1694
+ };
1695
+ exports.Prompt = Prompt2;
1696
+ var SelectState2 = class {
1697
+ constructor(items) {
1698
+ this.items = items;
1699
+ this.selectedIdx = 0;
1700
+ }
1701
+ bind(prompt) {
1702
+ prompt.on("input", (str, key) => {
1703
+ const invalidate = this.consume(str, key);
1704
+ if (invalidate)
1705
+ prompt.requestLayout();
1706
+ });
1707
+ }
1708
+ consume(str, key) {
1709
+ if (!key)
1710
+ return false;
1711
+ if (key.name === "down") {
1712
+ this.selectedIdx = (this.selectedIdx + 1) % this.items.length;
1713
+ return true;
1714
+ }
1715
+ if (key.name === "up") {
1716
+ this.selectedIdx -= 1;
1717
+ this.selectedIdx = this.selectedIdx < 0 ? this.items.length - 1 : this.selectedIdx;
1718
+ return true;
1719
+ }
1720
+ return false;
1721
+ }
1722
+ };
1723
+ exports.SelectState = SelectState2;
1724
+ var deferred = () => {
1725
+ let resolve;
1726
+ let reject;
1727
+ const promise = new Promise((res, rej) => {
1728
+ resolve = res;
1729
+ reject = rej;
1730
+ });
1731
+ return {
1732
+ resolve,
1733
+ reject,
1734
+ promise
1735
+ };
1736
+ };
1737
+ exports.deferred = deferred;
1738
+ var Terminal = class {
1739
+ constructor(view, stdin, stdout, closable) {
1740
+ this.view = view;
1741
+ this.stdin = stdin;
1742
+ this.stdout = stdout;
1743
+ this.closable = closable;
1744
+ this.text = "";
1745
+ this.status = "idle";
1746
+ if (this.stdin.isTTY)
1747
+ this.stdin.setRawMode(true);
1748
+ const keypress = (str, key) => {
1749
+ if (key.name === "c" && key.ctrl === true) {
1750
+ this.requestLayout();
1751
+ this.view.detach(this);
1752
+ this.tearDown(keypress);
1753
+ if (terminateHandler) {
1754
+ terminateHandler(this.stdin, this.stdout);
1755
+ return;
1756
+ }
1757
+ this.stdout.write(`
1758
+ ^C
1759
+ `);
1760
+ process.exit(1);
1761
+ }
1762
+ if (key.name === "escape") {
1763
+ this.status = "aborted";
1764
+ this.requestLayout();
1765
+ this.view.detach(this);
1766
+ this.tearDown(keypress);
1767
+ this.resolve({ status: "aborted", data: void 0 });
1768
+ return;
1769
+ }
1770
+ if (key.name === "return") {
1771
+ this.status = "submitted";
1772
+ this.requestLayout();
1773
+ this.view.detach(this);
1774
+ this.tearDown(keypress);
1775
+ this.resolve({ status: "submitted", data: this.view.result() });
1776
+ return;
1777
+ }
1778
+ view.input(str, key);
1779
+ };
1780
+ this.stdin.on("keypress", keypress);
1781
+ this.view.attach(this);
1782
+ const { resolve, promise } = (0, exports.deferred)();
1783
+ this.resolve = resolve;
1784
+ this.promise = promise;
1785
+ this.renderFunc = (0, lodash_throttle_1.default)((str) => {
1786
+ this.stdout.write(str);
1787
+ });
1788
+ }
1789
+ tearDown(keypress) {
1790
+ this.stdout.write(sisteransi_1.cursor.show);
1791
+ this.stdin.removeListener("keypress", keypress);
1792
+ if (this.stdin.isTTY)
1793
+ this.stdin.setRawMode(false);
1794
+ this.closable.close();
1795
+ }
1796
+ result() {
1797
+ return this.promise;
1798
+ }
1799
+ toggleCursor(state) {
1800
+ if (state === "hide") {
1801
+ this.stdout.write(sisteransi_1.cursor.hide);
1802
+ } else {
1803
+ this.stdout.write(sisteransi_1.cursor.show);
1804
+ }
1805
+ }
1806
+ requestLayout() {
1807
+ const string = this.view.render(this.status);
1808
+ const clearPrefix = this.text ? (0, utils_1.clear)(this.text, this.stdout.columns) : "";
1809
+ this.text = string;
1810
+ this.renderFunc(`${clearPrefix}${string}`);
1811
+ }
1812
+ };
1813
+ exports.Terminal = Terminal;
1814
+ var TaskView2 = class {
1815
+ constructor() {
1816
+ this.attachCallbacks = [];
1817
+ this.detachCallbacks = [];
1818
+ }
1819
+ requestLayout() {
1820
+ this.terminal.requestLayout();
1821
+ }
1822
+ attach(terminal) {
1823
+ this.terminal = terminal;
1824
+ this.attachCallbacks.forEach((it) => it(terminal));
1825
+ }
1826
+ detach(terminal) {
1827
+ this.detachCallbacks.forEach((it) => it(terminal));
1828
+ this.terminal = void 0;
1829
+ }
1830
+ on(type, callback) {
1831
+ if (type === "attach") {
1832
+ this.attachCallbacks.push(callback);
1833
+ } else if (type === "detach") {
1834
+ this.detachCallbacks.push(callback);
1835
+ }
1836
+ }
1837
+ };
1838
+ exports.TaskView = TaskView2;
1839
+ var TaskTerminal = class {
1840
+ constructor(view, stdout) {
1841
+ this.view = view;
1842
+ this.stdout = stdout;
1843
+ this.text = "";
1844
+ this.view.attach(this);
1845
+ }
1846
+ requestLayout() {
1847
+ const string = this.view.render("pending");
1848
+ const clearPrefix = this.text ? (0, utils_1.clear)(this.text, this.stdout.columns) : "";
1849
+ this.text = string;
1850
+ this.stdout.write(`${clearPrefix}${string}`);
1851
+ }
1852
+ clear() {
1853
+ const string = this.view.render("done");
1854
+ this.view.detach(this);
1855
+ const clearPrefix = this.text ? (0, utils_1.clear)(this.text, this.stdout.columns) : "";
1856
+ this.stdout.write(`${clearPrefix}${string}`);
1857
+ }
1858
+ };
1859
+ exports.TaskTerminal = TaskTerminal;
1860
+ function render2(view) {
1861
+ const { stdin, stdout, closable } = (0, readline_1.prepareReadLine)();
1862
+ if (view instanceof Prompt2) {
1863
+ const terminal = new Terminal(view, stdin, stdout, closable);
1864
+ terminal.requestLayout();
1865
+ return terminal.result();
1866
+ }
1867
+ stdout.write(`${view}
1868
+ `);
1869
+ closable.close();
1870
+ return;
1871
+ }
1872
+ exports.render = render2;
1873
+ function renderWithTask3(view, task) {
1874
+ return __awaiter(this, void 0, void 0, function* () {
1875
+ const terminal = new TaskTerminal(view, process.stdout);
1876
+ terminal.requestLayout();
1877
+ const result = yield task;
1878
+ terminal.clear();
1879
+ return result;
1880
+ });
1881
+ }
1882
+ exports.renderWithTask = renderWithTask3;
1883
+ var terminateHandler;
1884
+ function onTerminate(callback) {
1885
+ terminateHandler = callback;
1886
+ }
1887
+ exports.onTerminate = onTerminate;
1888
+ }
1889
+ });
1890
+
1891
+ // src/cli/views.ts
1892
+ var import_hanji;
1893
+ var init_views = __esm({
1894
+ "src/cli/views.ts"() {
1895
+ init_source();
1896
+ import_hanji = __toESM(require_hanji());
1897
+ }
1898
+ });
1899
+
1900
+ // node_modules/.pnpm/balanced-match@1.0.2/node_modules/balanced-match/index.js
1901
+ var require_balanced_match = __commonJS({
1902
+ "node_modules/.pnpm/balanced-match@1.0.2/node_modules/balanced-match/index.js"(exports, module2) {
1903
+ "use strict";
1904
+ module2.exports = balanced;
1905
+ function balanced(a, b, str) {
1906
+ if (a instanceof RegExp)
1907
+ a = maybeMatch(a, str);
1908
+ if (b instanceof RegExp)
1909
+ b = maybeMatch(b, str);
1910
+ var r = range(a, b, str);
1911
+ return r && {
1912
+ start: r[0],
1913
+ end: r[1],
1914
+ pre: str.slice(0, r[0]),
1915
+ body: str.slice(r[0] + a.length, r[1]),
1916
+ post: str.slice(r[1] + b.length)
1917
+ };
1918
+ }
1919
+ function maybeMatch(reg, str) {
1920
+ var m = str.match(reg);
1921
+ return m ? m[0] : null;
1922
+ }
1923
+ balanced.range = range;
1924
+ function range(a, b, str) {
1925
+ var begs, beg, left, right, result;
1926
+ var ai = str.indexOf(a);
1927
+ var bi = str.indexOf(b, ai + 1);
1928
+ var i = ai;
1929
+ if (ai >= 0 && bi > 0) {
1930
+ if (a === b) {
1931
+ return [ai, bi];
1932
+ }
1933
+ begs = [];
1934
+ left = str.length;
1935
+ while (i >= 0 && !result) {
1936
+ if (i == ai) {
1937
+ begs.push(i);
1938
+ ai = str.indexOf(a, i + 1);
1939
+ } else if (begs.length == 1) {
1940
+ result = [begs.pop(), bi];
1941
+ } else {
1942
+ beg = begs.pop();
1943
+ if (beg < left) {
1944
+ left = beg;
1945
+ right = bi;
1946
+ }
1947
+ bi = str.indexOf(b, i + 1);
1948
+ }
1949
+ i = ai < bi && ai >= 0 ? ai : bi;
1950
+ }
1951
+ if (begs.length) {
1952
+ result = [left, right];
1953
+ }
1954
+ }
1955
+ return result;
1956
+ }
1957
+ }
1958
+ });
1959
+
1960
+ // node_modules/.pnpm/brace-expansion@2.0.1/node_modules/brace-expansion/index.js
1961
+ var require_brace_expansion = __commonJS({
1962
+ "node_modules/.pnpm/brace-expansion@2.0.1/node_modules/brace-expansion/index.js"(exports, module2) {
1963
+ var balanced = require_balanced_match();
1964
+ module2.exports = expandTop;
1965
+ var escSlash = "\0SLASH" + Math.random() + "\0";
1966
+ var escOpen = "\0OPEN" + Math.random() + "\0";
1967
+ var escClose = "\0CLOSE" + Math.random() + "\0";
1968
+ var escComma = "\0COMMA" + Math.random() + "\0";
1969
+ var escPeriod = "\0PERIOD" + Math.random() + "\0";
1970
+ function numeric(str) {
1971
+ return parseInt(str, 10) == str ? parseInt(str, 10) : str.charCodeAt(0);
1972
+ }
1973
+ function escapeBraces(str) {
1974
+ return str.split("\\\\").join(escSlash).split("\\{").join(escOpen).split("\\}").join(escClose).split("\\,").join(escComma).split("\\.").join(escPeriod);
1975
+ }
1976
+ function unescapeBraces(str) {
1977
+ return str.split(escSlash).join("\\").split(escOpen).join("{").split(escClose).join("}").split(escComma).join(",").split(escPeriod).join(".");
1978
+ }
1979
+ function parseCommaParts(str) {
1980
+ if (!str)
1981
+ return [""];
1982
+ var parts = [];
1983
+ var m = balanced("{", "}", str);
1984
+ if (!m)
1985
+ return str.split(",");
1986
+ var pre = m.pre;
1987
+ var body = m.body;
1988
+ var post = m.post;
1989
+ var p = pre.split(",");
1990
+ p[p.length - 1] += "{" + body + "}";
1991
+ var postParts = parseCommaParts(post);
1992
+ if (post.length) {
1993
+ p[p.length - 1] += postParts.shift();
1994
+ p.push.apply(p, postParts);
1995
+ }
1996
+ parts.push.apply(parts, p);
1997
+ return parts;
1998
+ }
1999
+ function expandTop(str) {
2000
+ if (!str)
2001
+ return [];
2002
+ if (str.substr(0, 2) === "{}") {
2003
+ str = "\\{\\}" + str.substr(2);
2004
+ }
2005
+ return expand2(escapeBraces(str), true).map(unescapeBraces);
2006
+ }
2007
+ function embrace(str) {
2008
+ return "{" + str + "}";
2009
+ }
2010
+ function isPadded(el) {
2011
+ return /^-?0\d/.test(el);
2012
+ }
2013
+ function lte(i, y) {
2014
+ return i <= y;
2015
+ }
2016
+ function gte(i, y) {
2017
+ return i >= y;
2018
+ }
2019
+ function expand2(str, isTop) {
2020
+ var expansions = [];
2021
+ var m = balanced("{", "}", str);
2022
+ if (!m)
2023
+ return [str];
2024
+ var pre = m.pre;
2025
+ var post = m.post.length ? expand2(m.post, false) : [""];
2026
+ if (/\$$/.test(m.pre)) {
2027
+ for (var k = 0; k < post.length; k++) {
2028
+ var expansion = pre + "{" + m.body + "}" + post[k];
2029
+ expansions.push(expansion);
2030
+ }
2031
+ } else {
2032
+ var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
2033
+ var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
2034
+ var isSequence = isNumericSequence || isAlphaSequence;
2035
+ var isOptions = m.body.indexOf(",") >= 0;
2036
+ if (!isSequence && !isOptions) {
2037
+ if (m.post.match(/,.*\}/)) {
2038
+ str = m.pre + "{" + m.body + escClose + m.post;
2039
+ return expand2(str);
2040
+ }
2041
+ return [str];
2042
+ }
2043
+ var n;
2044
+ if (isSequence) {
2045
+ n = m.body.split(/\.\./);
2046
+ } else {
2047
+ n = parseCommaParts(m.body);
2048
+ if (n.length === 1) {
2049
+ n = expand2(n[0], false).map(embrace);
2050
+ if (n.length === 1) {
2051
+ return post.map(function(p) {
2052
+ return m.pre + n[0] + p;
2053
+ });
2054
+ }
2055
+ }
2056
+ }
2057
+ var N;
2058
+ if (isSequence) {
2059
+ var x = numeric(n[0]);
2060
+ var y = numeric(n[1]);
2061
+ var width = Math.max(n[0].length, n[1].length);
2062
+ var incr = n.length == 3 ? Math.abs(numeric(n[2])) : 1;
2063
+ var test = lte;
2064
+ var reverse = y < x;
2065
+ if (reverse) {
2066
+ incr *= -1;
2067
+ test = gte;
2068
+ }
2069
+ var pad = n.some(isPadded);
2070
+ N = [];
2071
+ for (var i = x; test(i, y); i += incr) {
2072
+ var c;
2073
+ if (isAlphaSequence) {
2074
+ c = String.fromCharCode(i);
2075
+ if (c === "\\")
2076
+ c = "";
2077
+ } else {
2078
+ c = String(i);
2079
+ if (pad) {
2080
+ var need = width - c.length;
2081
+ if (need > 0) {
2082
+ var z = new Array(need + 1).join("0");
2083
+ if (i < 0)
2084
+ c = "-" + z + c.slice(1);
2085
+ else
2086
+ c = z + c;
2087
+ }
2088
+ }
2089
+ }
2090
+ N.push(c);
2091
+ }
2092
+ } else {
2093
+ N = [];
2094
+ for (var j = 0; j < n.length; j++) {
2095
+ N.push.apply(N, expand2(n[j], false));
2096
+ }
2097
+ }
2098
+ for (var j = 0; j < N.length; j++) {
2099
+ for (var k = 0; k < post.length; k++) {
2100
+ var expansion = pre + N[j] + post[k];
2101
+ if (!isTop || isSequence || expansion)
2102
+ expansions.push(expansion);
2103
+ }
2104
+ }
2105
+ }
2106
+ return expansions;
2107
+ }
2108
+ }
2109
+ });
2110
+
2111
+ // src/drivers/index.ts
2112
+ var import_drizzle_orm3, DrizzleDbClient, DrizzleORMPgClient;
2113
+ var init_drivers = __esm({
2114
+ "src/drivers/index.ts"() {
2115
+ import_drizzle_orm3 = require("drizzle-orm");
2116
+ DrizzleDbClient = class {
2117
+ constructor(db) {
2118
+ this.db = db;
2119
+ }
2120
+ };
2121
+ DrizzleORMPgClient = class extends DrizzleDbClient {
2122
+ async query(query, values) {
2123
+ const res = await this.db.execute(import_drizzle_orm3.sql.raw(query));
2124
+ return res.rows;
2125
+ }
2126
+ async run(query) {
2127
+ const res = await this.db.execute(import_drizzle_orm3.sql.raw(query));
2128
+ return res.rows;
2129
+ }
2130
+ };
2131
+ }
2132
+ });
2133
+
2134
+ // src/utils-studio.ts
2135
+ var utils_studio_exports = {};
2136
+ __export(utils_studio_exports, {
2137
+ DrizzleORMPgClient: () => DrizzleORMPgClient,
2138
+ drizzleSchemaPg: () => toDrizzle,
2139
+ drizzleSchemaSQLite: () => toDrizzle2,
2140
+ pgPushIntrospect: () => pgPushIntrospect,
2141
+ sqlitePushIntrospect: () => sqlitePushIntrospect
2142
+ });
2143
+ module.exports = __toCommonJS(utils_studio_exports);
2144
+ init_pgSerializer();
2145
+ init_sqliteSerializer();
2146
+
2147
+ // src/cli/commands/sqliteIntrospect.ts
2148
+ init_views();
2149
+
2150
+ // src/global.ts
2151
+ var originUUID = "00000000-0000-0000-0000-000000000000";
2152
+
2153
+ // src/cli/commands/sqliteIntrospect.ts
2154
+ init_sqliteSerializer();
2155
+
2156
+ // node_modules/.pnpm/camelcase@7.0.1/node_modules/camelcase/index.js
2157
+ var UPPERCASE = /[\p{Lu}]/u;
2158
+ var LOWERCASE = /[\p{Ll}]/u;
2159
+ var LEADING_CAPITAL = /^[\p{Lu}](?![\p{Lu}])/gu;
2160
+ var IDENTIFIER = /([\p{Alpha}\p{N}_]|$)/u;
2161
+ var SEPARATORS = /[_.\- ]+/;
2162
+ var LEADING_SEPARATORS = new RegExp("^" + SEPARATORS.source);
2163
+ var SEPARATORS_AND_IDENTIFIER = new RegExp(SEPARATORS.source + IDENTIFIER.source, "gu");
2164
+ var NUMBERS_AND_IDENTIFIER = new RegExp("\\d+" + IDENTIFIER.source, "gu");
2165
+ var preserveCamelCase = (string, toLowerCase, toUpperCase, preserveConsecutiveUppercase2) => {
2166
+ let isLastCharLower = false;
2167
+ let isLastCharUpper = false;
2168
+ let isLastLastCharUpper = false;
2169
+ let isLastLastCharPreserved = false;
2170
+ for (let index = 0; index < string.length; index++) {
2171
+ const character = string[index];
2172
+ isLastLastCharPreserved = index > 2 ? string[index - 3] === "-" : true;
2173
+ if (isLastCharLower && UPPERCASE.test(character)) {
2174
+ string = string.slice(0, index) + "-" + string.slice(index);
2175
+ isLastCharLower = false;
2176
+ isLastLastCharUpper = isLastCharUpper;
2177
+ isLastCharUpper = true;
2178
+ index++;
2179
+ } else if (isLastCharUpper && isLastLastCharUpper && LOWERCASE.test(character) && (!isLastLastCharPreserved || preserveConsecutiveUppercase2)) {
2180
+ string = string.slice(0, index - 1) + "-" + string.slice(index - 1);
2181
+ isLastLastCharUpper = isLastCharUpper;
2182
+ isLastCharUpper = false;
2183
+ isLastCharLower = true;
2184
+ } else {
2185
+ isLastCharLower = toLowerCase(character) === character && toUpperCase(character) !== character;
2186
+ isLastLastCharUpper = isLastCharUpper;
2187
+ isLastCharUpper = toUpperCase(character) === character && toLowerCase(character) !== character;
2188
+ }
2189
+ }
2190
+ return string;
2191
+ };
2192
+ var preserveConsecutiveUppercase = (input, toLowerCase) => {
2193
+ LEADING_CAPITAL.lastIndex = 0;
2194
+ return input.replace(LEADING_CAPITAL, (m1) => toLowerCase(m1));
2195
+ };
2196
+ var postProcess = (input, toUpperCase) => {
2197
+ SEPARATORS_AND_IDENTIFIER.lastIndex = 0;
2198
+ NUMBERS_AND_IDENTIFIER.lastIndex = 0;
2199
+ return input.replace(SEPARATORS_AND_IDENTIFIER, (_, identifier) => toUpperCase(identifier)).replace(NUMBERS_AND_IDENTIFIER, (m) => toUpperCase(m));
2200
+ };
2201
+ function camelCase(input, options) {
2202
+ if (!(typeof input === "string" || Array.isArray(input))) {
2203
+ throw new TypeError("Expected the input to be `string | string[]`");
2204
+ }
2205
+ options = {
2206
+ pascalCase: false,
2207
+ preserveConsecutiveUppercase: false,
2208
+ ...options
2209
+ };
2210
+ if (Array.isArray(input)) {
2211
+ input = input.map((x) => x.trim()).filter((x) => x.length).join("-");
2212
+ } else {
2213
+ input = input.trim();
2214
+ }
2215
+ if (input.length === 0) {
2216
+ return "";
2217
+ }
2218
+ const toLowerCase = options.locale === false ? (string) => string.toLowerCase() : (string) => string.toLocaleLowerCase(options.locale);
2219
+ const toUpperCase = options.locale === false ? (string) => string.toUpperCase() : (string) => string.toLocaleUpperCase(options.locale);
2220
+ if (input.length === 1) {
2221
+ if (SEPARATORS.test(input)) {
2222
+ return "";
2223
+ }
2224
+ return options.pascalCase ? toUpperCase(input) : toLowerCase(input);
2225
+ }
2226
+ const hasUpperCase = input !== toLowerCase(input);
2227
+ if (hasUpperCase) {
2228
+ input = preserveCamelCase(input, toLowerCase, toUpperCase, options.preserveConsecutiveUppercase);
2229
+ }
2230
+ input = input.replace(LEADING_SEPARATORS, "");
2231
+ input = options.preserveConsecutiveUppercase ? preserveConsecutiveUppercase(input, toLowerCase) : toLowerCase(input);
2232
+ if (options.pascalCase) {
2233
+ input = toUpperCase(input.charAt(0)) + input.slice(1);
2234
+ }
2235
+ return postProcess(input, toUpperCase);
2236
+ }
2237
+
2238
+ // src/@types/utils.ts
2239
+ String.prototype.trimChar = function(char) {
2240
+ let start = 0;
2241
+ let end = this.length;
2242
+ while (start < end && this[start] === char)
2243
+ ++start;
2244
+ while (end > start && this[end - 1] === char)
2245
+ --end;
2246
+ return start > 0 || end < this.length ? this.substring(start, end) : this.toString();
2247
+ };
2248
+ String.prototype.squashSpaces = function() {
2249
+ return this.replace(/ +/g, " ").trim();
2250
+ };
2251
+ String.prototype.camelCase = function() {
2252
+ return camelCase(String(this));
2253
+ };
2254
+ String.prototype.concatIf = function(it, condition) {
2255
+ return condition ? `${this}${it}` : this;
2256
+ };
2257
+ Array.prototype.random = function() {
2258
+ return this[~~(Math.random() * this.length)];
2259
+ };
2260
+
2261
+ // node_modules/.pnpm/minimatch@7.4.3/node_modules/minimatch/dist/mjs/index.js
2262
+ var import_brace_expansion = __toESM(require_brace_expansion(), 1);
2263
+
2264
+ // node_modules/.pnpm/minimatch@7.4.3/node_modules/minimatch/dist/mjs/brace-expressions.js
2265
+ var posixClasses = {
2266
+ "[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}", true],
2267
+ "[:alpha:]": ["\\p{L}\\p{Nl}", true],
2268
+ "[:ascii:]": ["\\x00-\\x7f", false],
2269
+ "[:blank:]": ["\\p{Zs}\\t", true],
2270
+ "[:cntrl:]": ["\\p{Cc}", true],
2271
+ "[:digit:]": ["\\p{Nd}", true],
2272
+ "[:graph:]": ["\\p{Z}\\p{C}", true, true],
2273
+ "[:lower:]": ["\\p{Ll}", true],
2274
+ "[:print:]": ["\\p{C}", true],
2275
+ "[:punct:]": ["\\p{P}", true],
2276
+ "[:space:]": ["\\p{Z}\\t\\r\\n\\v\\f", true],
2277
+ "[:upper:]": ["\\p{Lu}", true],
2278
+ "[:word:]": ["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}", true],
2279
+ "[:xdigit:]": ["A-Fa-f0-9", false]
2280
+ };
2281
+ var braceEscape = (s) => s.replace(/[[\]\\-]/g, "\\$&");
2282
+ var regexpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
2283
+ var rangesToString = (ranges) => ranges.join("");
2284
+ var parseClass = (glob2, position) => {
2285
+ const pos = position;
2286
+ if (glob2.charAt(pos) !== "[") {
2287
+ throw new Error("not in a brace expression");
2288
+ }
2289
+ const ranges = [];
2290
+ const negs = [];
2291
+ let i = pos + 1;
2292
+ let sawStart = false;
2293
+ let uflag = false;
2294
+ let escaping = false;
2295
+ let negate = false;
2296
+ let endPos = pos;
2297
+ let rangeStart = "";
2298
+ WHILE:
2299
+ while (i < glob2.length) {
2300
+ const c = glob2.charAt(i);
2301
+ if ((c === "!" || c === "^") && i === pos + 1) {
2302
+ negate = true;
2303
+ i++;
2304
+ continue;
2305
+ }
2306
+ if (c === "]" && sawStart && !escaping) {
2307
+ endPos = i + 1;
2308
+ break;
2309
+ }
2310
+ sawStart = true;
2311
+ if (c === "\\") {
2312
+ if (!escaping) {
2313
+ escaping = true;
2314
+ i++;
2315
+ continue;
2316
+ }
2317
+ }
2318
+ if (c === "[" && !escaping) {
2319
+ for (const [cls, [unip, u, neg]] of Object.entries(posixClasses)) {
2320
+ if (glob2.startsWith(cls, i)) {
2321
+ if (rangeStart) {
2322
+ return ["$.", false, glob2.length - pos, true];
2323
+ }
2324
+ i += cls.length;
2325
+ if (neg)
2326
+ negs.push(unip);
2327
+ else
2328
+ ranges.push(unip);
2329
+ uflag = uflag || u;
2330
+ continue WHILE;
2331
+ }
2332
+ }
2333
+ }
2334
+ escaping = false;
2335
+ if (rangeStart) {
2336
+ if (c > rangeStart) {
2337
+ ranges.push(braceEscape(rangeStart) + "-" + braceEscape(c));
2338
+ } else if (c === rangeStart) {
2339
+ ranges.push(braceEscape(c));
2340
+ }
2341
+ rangeStart = "";
2342
+ i++;
2343
+ continue;
2344
+ }
2345
+ if (glob2.startsWith("-]", i + 1)) {
2346
+ ranges.push(braceEscape(c + "-"));
2347
+ i += 2;
2348
+ continue;
2349
+ }
2350
+ if (glob2.startsWith("-", i + 1)) {
2351
+ rangeStart = c;
2352
+ i += 2;
2353
+ continue;
2354
+ }
2355
+ ranges.push(braceEscape(c));
2356
+ i++;
2357
+ }
2358
+ if (endPos < i) {
2359
+ return ["", false, 0, false];
2360
+ }
2361
+ if (!ranges.length && !negs.length) {
2362
+ return ["$.", false, glob2.length - pos, true];
2363
+ }
2364
+ if (negs.length === 0 && ranges.length === 1 && /^\\?.$/.test(ranges[0]) && !negate) {
2365
+ const r = ranges[0].length === 2 ? ranges[0].slice(-1) : ranges[0];
2366
+ return [regexpEscape(r), false, endPos - pos, false];
2367
+ }
2368
+ const sranges = "[" + (negate ? "^" : "") + rangesToString(ranges) + "]";
2369
+ const snegs = "[" + (negate ? "" : "^") + rangesToString(negs) + "]";
2370
+ const comb = ranges.length && negs.length ? "(" + sranges + "|" + snegs + ")" : ranges.length ? sranges : snegs;
2371
+ return [comb, uflag, endPos - pos, true];
2372
+ };
2373
+
2374
+ // node_modules/.pnpm/minimatch@7.4.3/node_modules/minimatch/dist/mjs/escape.js
2375
+ var escape = (s, { windowsPathsNoEscape = false } = {}) => {
2376
+ return windowsPathsNoEscape ? s.replace(/[?*()[\]]/g, "[$&]") : s.replace(/[?*()[\]\\]/g, "\\$&");
2377
+ };
2378
+
2379
+ // node_modules/.pnpm/minimatch@7.4.3/node_modules/minimatch/dist/mjs/unescape.js
2380
+ var unescape = (s, { windowsPathsNoEscape = false } = {}) => {
2381
+ return windowsPathsNoEscape ? s.replace(/\[([^\/\\])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^\/\\])\]/g, "$1$2").replace(/\\([^\/])/g, "$1");
2382
+ };
2383
+
2384
+ // node_modules/.pnpm/minimatch@7.4.3/node_modules/minimatch/dist/mjs/index.js
2385
+ var minimatch = (p, pattern, options = {}) => {
2386
+ assertValidPattern(pattern);
2387
+ if (!options.nocomment && pattern.charAt(0) === "#") {
2388
+ return false;
2389
+ }
2390
+ return new Minimatch(pattern, options).match(p);
2391
+ };
2392
+ var starDotExtRE = /^\*+([^+@!?\*\[\(]*)$/;
2393
+ var starDotExtTest = (ext2) => (f) => !f.startsWith(".") && f.endsWith(ext2);
2394
+ var starDotExtTestDot = (ext2) => (f) => f.endsWith(ext2);
2395
+ var starDotExtTestNocase = (ext2) => {
2396
+ ext2 = ext2.toLowerCase();
2397
+ return (f) => !f.startsWith(".") && f.toLowerCase().endsWith(ext2);
2398
+ };
2399
+ var starDotExtTestNocaseDot = (ext2) => {
2400
+ ext2 = ext2.toLowerCase();
2401
+ return (f) => f.toLowerCase().endsWith(ext2);
2402
+ };
2403
+ var starDotStarRE = /^\*+\.\*+$/;
2404
+ var starDotStarTest = (f) => !f.startsWith(".") && f.includes(".");
2405
+ var starDotStarTestDot = (f) => f !== "." && f !== ".." && f.includes(".");
2406
+ var dotStarRE = /^\.\*+$/;
2407
+ var dotStarTest = (f) => f !== "." && f !== ".." && f.startsWith(".");
2408
+ var starRE = /^\*+$/;
2409
+ var starTest = (f) => f.length !== 0 && !f.startsWith(".");
2410
+ var starTestDot = (f) => f.length !== 0 && f !== "." && f !== "..";
2411
+ var qmarksRE = /^\?+([^+@!?\*\[\(]*)?$/;
2412
+ var qmarksTestNocase = ([$0, ext2 = ""]) => {
2413
+ const noext = qmarksTestNoExt([$0]);
2414
+ if (!ext2)
2415
+ return noext;
2416
+ ext2 = ext2.toLowerCase();
2417
+ return (f) => noext(f) && f.toLowerCase().endsWith(ext2);
2418
+ };
2419
+ var qmarksTestNocaseDot = ([$0, ext2 = ""]) => {
2420
+ const noext = qmarksTestNoExtDot([$0]);
2421
+ if (!ext2)
2422
+ return noext;
2423
+ ext2 = ext2.toLowerCase();
2424
+ return (f) => noext(f) && f.toLowerCase().endsWith(ext2);
2425
+ };
2426
+ var qmarksTestDot = ([$0, ext2 = ""]) => {
2427
+ const noext = qmarksTestNoExtDot([$0]);
2428
+ return !ext2 ? noext : (f) => noext(f) && f.endsWith(ext2);
2429
+ };
2430
+ var qmarksTest = ([$0, ext2 = ""]) => {
2431
+ const noext = qmarksTestNoExt([$0]);
2432
+ return !ext2 ? noext : (f) => noext(f) && f.endsWith(ext2);
2433
+ };
2434
+ var qmarksTestNoExt = ([$0]) => {
2435
+ const len = $0.length;
2436
+ return (f) => f.length === len && !f.startsWith(".");
2437
+ };
2438
+ var qmarksTestNoExtDot = ([$0]) => {
2439
+ const len = $0.length;
2440
+ return (f) => f.length === len && f !== "." && f !== "..";
2441
+ };
2442
+ var defaultPlatform = typeof process === "object" && process ? typeof process.env === "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix";
2443
+ var path = {
2444
+ win32: { sep: "\\" },
2445
+ posix: { sep: "/" }
2446
+ };
2447
+ var sep = defaultPlatform === "win32" ? path.win32.sep : path.posix.sep;
2448
+ minimatch.sep = sep;
2449
+ var GLOBSTAR = Symbol("globstar **");
2450
+ minimatch.GLOBSTAR = GLOBSTAR;
2451
+ var plTypes = {
2452
+ "!": { open: "(?:(?!(?:", close: "))[^/]*?)" },
2453
+ "?": { open: "(?:", close: ")?" },
2454
+ "+": { open: "(?:", close: ")+" },
2455
+ "*": { open: "(?:", close: ")*" },
2456
+ "@": { open: "(?:", close: ")" }
2457
+ };
2458
+ var qmark = "[^/]";
2459
+ var star = qmark + "*?";
2460
+ var twoStarDot = "(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?";
2461
+ var twoStarNoDot = "(?:(?!(?:\\/|^)\\.).)*?";
2462
+ var charSet = (s) => s.split("").reduce((set, c) => {
2463
+ set[c] = true;
2464
+ return set;
2465
+ }, {});
2466
+ var reSpecials = charSet("().*{}+?[]^$\\!");
2467
+ var addPatternStartSet = charSet("[.(");
2468
+ var filter = (pattern, options = {}) => (p) => minimatch(p, pattern, options);
2469
+ minimatch.filter = filter;
2470
+ var ext = (a, b = {}) => Object.assign({}, a, b);
2471
+ var defaults = (def) => {
2472
+ if (!def || typeof def !== "object" || !Object.keys(def).length) {
2473
+ return minimatch;
2474
+ }
2475
+ const orig = minimatch;
2476
+ const m = (p, pattern, options = {}) => orig(p, pattern, ext(def, options));
2477
+ return Object.assign(m, {
2478
+ Minimatch: class Minimatch extends orig.Minimatch {
2479
+ constructor(pattern, options = {}) {
2480
+ super(pattern, ext(def, options));
2481
+ }
2482
+ static defaults(options) {
2483
+ return orig.defaults(ext(def, options)).Minimatch;
2484
+ }
2485
+ },
2486
+ unescape: (s, options = {}) => orig.unescape(s, ext(def, options)),
2487
+ escape: (s, options = {}) => orig.escape(s, ext(def, options)),
2488
+ filter: (pattern, options = {}) => orig.filter(pattern, ext(def, options)),
2489
+ defaults: (options) => orig.defaults(ext(def, options)),
2490
+ makeRe: (pattern, options = {}) => orig.makeRe(pattern, ext(def, options)),
2491
+ braceExpand: (pattern, options = {}) => orig.braceExpand(pattern, ext(def, options)),
2492
+ match: (list, pattern, options = {}) => orig.match(list, pattern, ext(def, options)),
2493
+ sep: orig.sep,
2494
+ GLOBSTAR
2495
+ });
2496
+ };
2497
+ minimatch.defaults = defaults;
2498
+ var braceExpand = (pattern, options = {}) => {
2499
+ assertValidPattern(pattern);
2500
+ if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) {
2501
+ return [pattern];
2502
+ }
2503
+ return (0, import_brace_expansion.default)(pattern);
2504
+ };
2505
+ minimatch.braceExpand = braceExpand;
2506
+ var MAX_PATTERN_LENGTH = 1024 * 64;
2507
+ var assertValidPattern = (pattern) => {
2508
+ if (typeof pattern !== "string") {
2509
+ throw new TypeError("invalid pattern");
2510
+ }
2511
+ if (pattern.length > MAX_PATTERN_LENGTH) {
2512
+ throw new TypeError("pattern is too long");
2513
+ }
2514
+ };
2515
+ var makeRe = (pattern, options = {}) => new Minimatch(pattern, options).makeRe();
2516
+ minimatch.makeRe = makeRe;
2517
+ var match = (list, pattern, options = {}) => {
2518
+ const mm = new Minimatch(pattern, options);
2519
+ list = list.filter((f) => mm.match(f));
2520
+ if (mm.options.nonull && !list.length) {
2521
+ list.push(pattern);
2522
+ }
2523
+ return list;
2524
+ };
2525
+ minimatch.match = match;
2526
+ var globUnescape = (s) => s.replace(/\\(.)/g, "$1");
2527
+ var globMagic = /[?*]|[+@!]\(.*?\)|\[|\]/;
2528
+ var regExpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
2529
+ var Minimatch = class {
2530
+ options;
2531
+ set;
2532
+ pattern;
2533
+ windowsPathsNoEscape;
2534
+ nonegate;
2535
+ negate;
2536
+ comment;
2537
+ empty;
2538
+ preserveMultipleSlashes;
2539
+ partial;
2540
+ globSet;
2541
+ globParts;
2542
+ nocase;
2543
+ isWindows;
2544
+ platform;
2545
+ windowsNoMagicRoot;
2546
+ regexp;
2547
+ constructor(pattern, options = {}) {
2548
+ assertValidPattern(pattern);
2549
+ options = options || {};
2550
+ this.options = options;
2551
+ this.pattern = pattern;
2552
+ this.platform = options.platform || defaultPlatform;
2553
+ this.isWindows = this.platform === "win32";
2554
+ this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || options.allowWindowsEscape === false;
2555
+ if (this.windowsPathsNoEscape) {
2556
+ this.pattern = this.pattern.replace(/\\/g, "/");
2557
+ }
2558
+ this.preserveMultipleSlashes = !!options.preserveMultipleSlashes;
2559
+ this.regexp = null;
2560
+ this.negate = false;
2561
+ this.nonegate = !!options.nonegate;
2562
+ this.comment = false;
2563
+ this.empty = false;
2564
+ this.partial = !!options.partial;
2565
+ this.nocase = !!this.options.nocase;
2566
+ this.windowsNoMagicRoot = options.windowsNoMagicRoot !== void 0 ? options.windowsNoMagicRoot : !!(this.isWindows && this.nocase);
2567
+ this.globSet = [];
2568
+ this.globParts = [];
2569
+ this.set = [];
2570
+ this.make();
2571
+ }
2572
+ hasMagic() {
2573
+ if (this.options.magicalBraces && this.set.length > 1) {
2574
+ return true;
2575
+ }
2576
+ for (const pattern of this.set) {
2577
+ for (const part of pattern) {
2578
+ if (typeof part !== "string")
2579
+ return true;
2580
+ }
2581
+ }
2582
+ return false;
2583
+ }
2584
+ debug(..._) {
2585
+ }
2586
+ make() {
2587
+ const pattern = this.pattern;
2588
+ const options = this.options;
2589
+ if (!options.nocomment && pattern.charAt(0) === "#") {
2590
+ this.comment = true;
2591
+ return;
2592
+ }
2593
+ if (!pattern) {
2594
+ this.empty = true;
2595
+ return;
2596
+ }
2597
+ this.parseNegate();
2598
+ this.globSet = [...new Set(this.braceExpand())];
2599
+ if (options.debug) {
2600
+ this.debug = (...args) => console.error(...args);
2601
+ }
2602
+ this.debug(this.pattern, this.globSet);
2603
+ const rawGlobParts = this.globSet.map((s) => this.slashSplit(s));
2604
+ this.globParts = this.preprocess(rawGlobParts);
2605
+ this.debug(this.pattern, this.globParts);
2606
+ let set = this.globParts.map((s, _, __) => {
2607
+ if (this.isWindows && this.windowsNoMagicRoot) {
2608
+ const isUNC = s[0] === "" && s[1] === "" && (s[2] === "?" || !globMagic.test(s[2])) && !globMagic.test(s[3]);
2609
+ const isDrive = /^[a-z]:/i.test(s[0]);
2610
+ if (isUNC) {
2611
+ return [...s.slice(0, 4), ...s.slice(4).map((ss) => this.parse(ss))];
2612
+ } else if (isDrive) {
2613
+ return [s[0], ...s.slice(1).map((ss) => this.parse(ss))];
2614
+ }
2615
+ }
2616
+ return s.map((ss) => this.parse(ss));
2617
+ });
2618
+ this.debug(this.pattern, set);
2619
+ this.set = set.filter((s) => s.indexOf(false) === -1);
2620
+ if (this.isWindows) {
2621
+ for (let i = 0; i < this.set.length; i++) {
2622
+ const p = this.set[i];
2623
+ if (p[0] === "" && p[1] === "" && this.globParts[i][2] === "?" && typeof p[3] === "string" && /^[a-z]:$/i.test(p[3])) {
2624
+ p[2] = "?";
2625
+ }
2626
+ }
2627
+ }
2628
+ this.debug(this.pattern, this.set);
2629
+ }
2630
+ // various transforms to equivalent pattern sets that are
2631
+ // faster to process in a filesystem walk. The goal is to
2632
+ // eliminate what we can, and push all ** patterns as far
2633
+ // to the right as possible, even if it increases the number
2634
+ // of patterns that we have to process.
2635
+ preprocess(globParts) {
2636
+ if (this.options.noglobstar) {
2637
+ for (let i = 0; i < globParts.length; i++) {
2638
+ for (let j = 0; j < globParts[i].length; j++) {
2639
+ if (globParts[i][j] === "**") {
2640
+ globParts[i][j] = "*";
2641
+ }
2642
+ }
2643
+ }
2644
+ }
2645
+ const { optimizationLevel = 1 } = this.options;
2646
+ if (optimizationLevel >= 2) {
2647
+ globParts = this.firstPhasePreProcess(globParts);
2648
+ globParts = this.secondPhasePreProcess(globParts);
2649
+ } else if (optimizationLevel >= 1) {
2650
+ globParts = this.levelOneOptimize(globParts);
2651
+ } else {
2652
+ globParts = this.adjascentGlobstarOptimize(globParts);
2653
+ }
2654
+ return globParts;
2655
+ }
2656
+ // just get rid of adjascent ** portions
2657
+ adjascentGlobstarOptimize(globParts) {
2658
+ return globParts.map((parts) => {
2659
+ let gs = -1;
2660
+ while (-1 !== (gs = parts.indexOf("**", gs + 1))) {
2661
+ let i = gs;
2662
+ while (parts[i + 1] === "**") {
2663
+ i++;
2664
+ }
2665
+ if (i !== gs) {
2666
+ parts.splice(gs, i - gs);
2667
+ }
2668
+ }
2669
+ return parts;
2670
+ });
2671
+ }
2672
+ // get rid of adjascent ** and resolve .. portions
2673
+ levelOneOptimize(globParts) {
2674
+ return globParts.map((parts) => {
2675
+ parts = parts.reduce((set, part) => {
2676
+ const prev = set[set.length - 1];
2677
+ if (part === "**" && prev === "**") {
2678
+ return set;
2679
+ }
2680
+ if (part === "..") {
2681
+ if (prev && prev !== ".." && prev !== "." && prev !== "**") {
2682
+ set.pop();
2683
+ return set;
2684
+ }
2685
+ }
2686
+ set.push(part);
2687
+ return set;
2688
+ }, []);
2689
+ return parts.length === 0 ? [""] : parts;
2690
+ });
2691
+ }
2692
+ levelTwoFileOptimize(parts) {
2693
+ if (!Array.isArray(parts)) {
2694
+ parts = this.slashSplit(parts);
2695
+ }
2696
+ let didSomething = false;
2697
+ do {
2698
+ didSomething = false;
2699
+ if (!this.preserveMultipleSlashes) {
2700
+ for (let i = 1; i < parts.length - 1; i++) {
2701
+ const p = parts[i];
2702
+ if (i === 1 && p === "" && parts[0] === "")
2703
+ continue;
2704
+ if (p === "." || p === "") {
2705
+ didSomething = true;
2706
+ parts.splice(i, 1);
2707
+ i--;
2708
+ }
2709
+ }
2710
+ if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
2711
+ didSomething = true;
2712
+ parts.pop();
2713
+ }
2714
+ }
2715
+ let dd = 0;
2716
+ while (-1 !== (dd = parts.indexOf("..", dd + 1))) {
2717
+ const p = parts[dd - 1];
2718
+ if (p && p !== "." && p !== ".." && p !== "**") {
2719
+ didSomething = true;
2720
+ parts.splice(dd - 1, 2);
2721
+ dd -= 2;
2722
+ }
2723
+ }
2724
+ } while (didSomething);
2725
+ return parts.length === 0 ? [""] : parts;
2726
+ }
2727
+ // First phase: single-pattern processing
2728
+ // <pre> is 1 or more portions
2729
+ // <rest> is 1 or more portions
2730
+ // <p> is any portion other than ., .., '', or **
2731
+ // <e> is . or ''
2732
+ //
2733
+ // **/.. is *brutal* for filesystem walking performance, because
2734
+ // it effectively resets the recursive walk each time it occurs,
2735
+ // and ** cannot be reduced out by a .. pattern part like a regexp
2736
+ // or most strings (other than .., ., and '') can be.
2737
+ //
2738
+ // <pre>/**/../<p>/<p>/<rest> -> {<pre>/../<p>/<p>/<rest>,<pre>/**/<p>/<p>/<rest>}
2739
+ // <pre>/<e>/<rest> -> <pre>/<rest>
2740
+ // <pre>/<p>/../<rest> -> <pre>/<rest>
2741
+ // **/**/<rest> -> **/<rest>
2742
+ //
2743
+ // **/*/<rest> -> */**/<rest> <== not valid because ** doesn't follow
2744
+ // this WOULD be allowed if ** did follow symlinks, or * didn't
2745
+ firstPhasePreProcess(globParts) {
2746
+ let didSomething = false;
2747
+ do {
2748
+ didSomething = false;
2749
+ for (let parts of globParts) {
2750
+ let gs = -1;
2751
+ while (-1 !== (gs = parts.indexOf("**", gs + 1))) {
2752
+ let gss = gs;
2753
+ while (parts[gss + 1] === "**") {
2754
+ gss++;
2755
+ }
2756
+ if (gss > gs) {
2757
+ parts.splice(gs + 1, gss - gs);
2758
+ }
2759
+ let next = parts[gs + 1];
2760
+ const p = parts[gs + 2];
2761
+ const p2 = parts[gs + 3];
2762
+ if (next !== "..")
2763
+ continue;
2764
+ if (!p || p === "." || p === ".." || !p2 || p2 === "." || p2 === "..") {
2765
+ continue;
2766
+ }
2767
+ didSomething = true;
2768
+ parts.splice(gs, 1);
2769
+ const other = parts.slice(0);
2770
+ other[gs] = "**";
2771
+ globParts.push(other);
2772
+ gs--;
2773
+ }
2774
+ if (!this.preserveMultipleSlashes) {
2775
+ for (let i = 1; i < parts.length - 1; i++) {
2776
+ const p = parts[i];
2777
+ if (i === 1 && p === "" && parts[0] === "")
2778
+ continue;
2779
+ if (p === "." || p === "") {
2780
+ didSomething = true;
2781
+ parts.splice(i, 1);
2782
+ i--;
2783
+ }
2784
+ }
2785
+ if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
2786
+ didSomething = true;
2787
+ parts.pop();
2788
+ }
2789
+ }
2790
+ let dd = 0;
2791
+ while (-1 !== (dd = parts.indexOf("..", dd + 1))) {
2792
+ const p = parts[dd - 1];
2793
+ if (p && p !== "." && p !== ".." && p !== "**") {
2794
+ didSomething = true;
2795
+ const needDot = dd === 1 && parts[dd + 1] === "**";
2796
+ const splin = needDot ? ["."] : [];
2797
+ parts.splice(dd - 1, 2, ...splin);
2798
+ if (parts.length === 0)
2799
+ parts.push("");
2800
+ dd -= 2;
2801
+ }
2802
+ }
2803
+ }
2804
+ } while (didSomething);
2805
+ return globParts;
2806
+ }
2807
+ // second phase: multi-pattern dedupes
2808
+ // {<pre>/*/<rest>,<pre>/<p>/<rest>} -> <pre>/*/<rest>
2809
+ // {<pre>/<rest>,<pre>/<rest>} -> <pre>/<rest>
2810
+ // {<pre>/**/<rest>,<pre>/<rest>} -> <pre>/**/<rest>
2811
+ //
2812
+ // {<pre>/**/<rest>,<pre>/**/<p>/<rest>} -> <pre>/**/<rest>
2813
+ // ^-- not valid because ** doens't follow symlinks
2814
+ secondPhasePreProcess(globParts) {
2815
+ for (let i = 0; i < globParts.length - 1; i++) {
2816
+ for (let j = i + 1; j < globParts.length; j++) {
2817
+ const matched = this.partsMatch(globParts[i], globParts[j], !this.preserveMultipleSlashes);
2818
+ if (!matched)
2819
+ continue;
2820
+ globParts[i] = matched;
2821
+ globParts[j] = [];
2822
+ }
2823
+ }
2824
+ return globParts.filter((gs) => gs.length);
2825
+ }
2826
+ partsMatch(a, b, emptyGSMatch = false) {
2827
+ let ai = 0;
2828
+ let bi = 0;
2829
+ let result = [];
2830
+ let which = "";
2831
+ while (ai < a.length && bi < b.length) {
2832
+ if (a[ai] === b[bi]) {
2833
+ result.push(which === "b" ? b[bi] : a[ai]);
2834
+ ai++;
2835
+ bi++;
2836
+ } else if (emptyGSMatch && a[ai] === "**" && b[bi] === a[ai + 1]) {
2837
+ result.push(a[ai]);
2838
+ ai++;
2839
+ } else if (emptyGSMatch && b[bi] === "**" && a[ai] === b[bi + 1]) {
2840
+ result.push(b[bi]);
2841
+ bi++;
2842
+ } else if (a[ai] === "*" && b[bi] && (this.options.dot || !b[bi].startsWith(".")) && b[bi] !== "**") {
2843
+ if (which === "b")
2844
+ return false;
2845
+ which = "a";
2846
+ result.push(a[ai]);
2847
+ ai++;
2848
+ bi++;
2849
+ } else if (b[bi] === "*" && a[ai] && (this.options.dot || !a[ai].startsWith(".")) && a[ai] !== "**") {
2850
+ if (which === "a")
2851
+ return false;
2852
+ which = "b";
2853
+ result.push(b[bi]);
2854
+ ai++;
2855
+ bi++;
2856
+ } else {
2857
+ return false;
2858
+ }
2859
+ }
2860
+ return a.length === b.length && result;
2861
+ }
2862
+ parseNegate() {
2863
+ if (this.nonegate)
2864
+ return;
2865
+ const pattern = this.pattern;
2866
+ let negate = false;
2867
+ let negateOffset = 0;
2868
+ for (let i = 0; i < pattern.length && pattern.charAt(i) === "!"; i++) {
2869
+ negate = !negate;
2870
+ negateOffset++;
2871
+ }
2872
+ if (negateOffset)
2873
+ this.pattern = pattern.slice(negateOffset);
2874
+ this.negate = negate;
2875
+ }
2876
+ // set partial to true to test if, for example,
2877
+ // "/a/b" matches the start of "/*/b/*/d"
2878
+ // Partial means, if you run out of file before you run
2879
+ // out of pattern, then that's fine, as long as all
2880
+ // the parts match.
2881
+ matchOne(file, pattern, partial = false) {
2882
+ const options = this.options;
2883
+ if (this.isWindows) {
2884
+ const fileUNC = file[0] === "" && file[1] === "" && file[2] === "?" && typeof file[3] === "string" && /^[a-z]:$/i.test(file[3]);
2885
+ const patternUNC = pattern[0] === "" && pattern[1] === "" && pattern[2] === "?" && typeof pattern[3] === "string" && /^[a-z]:$/i.test(pattern[3]);
2886
+ if (fileUNC && patternUNC) {
2887
+ const fd = file[3];
2888
+ const pd = pattern[3];
2889
+ if (fd.toLowerCase() === pd.toLowerCase()) {
2890
+ file[3] = pd;
2891
+ }
2892
+ } else if (patternUNC && typeof file[0] === "string") {
2893
+ const pd = pattern[3];
2894
+ const fd = file[0];
2895
+ if (pd.toLowerCase() === fd.toLowerCase()) {
2896
+ pattern[3] = fd;
2897
+ pattern = pattern.slice(3);
2898
+ }
2899
+ } else if (fileUNC && typeof pattern[0] === "string") {
2900
+ const fd = file[3];
2901
+ if (fd.toLowerCase() === pattern[0].toLowerCase()) {
2902
+ pattern[0] = fd;
2903
+ file = file.slice(3);
2904
+ }
2905
+ }
2906
+ }
2907
+ const { optimizationLevel = 1 } = this.options;
2908
+ if (optimizationLevel >= 2) {
2909
+ file = this.levelTwoFileOptimize(file);
2910
+ }
2911
+ this.debug("matchOne", this, { file, pattern });
2912
+ this.debug("matchOne", file.length, pattern.length);
2913
+ for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
2914
+ this.debug("matchOne loop");
2915
+ var p = pattern[pi];
2916
+ var f = file[fi];
2917
+ this.debug(pattern, p, f);
2918
+ if (p === false) {
2919
+ return false;
2920
+ }
2921
+ if (p === GLOBSTAR) {
2922
+ this.debug("GLOBSTAR", [pattern, p, f]);
2923
+ var fr = fi;
2924
+ var pr = pi + 1;
2925
+ if (pr === pl) {
2926
+ this.debug("** at the end");
2927
+ for (; fi < fl; fi++) {
2928
+ if (file[fi] === "." || file[fi] === ".." || !options.dot && file[fi].charAt(0) === ".")
2929
+ return false;
2930
+ }
2931
+ return true;
2932
+ }
2933
+ while (fr < fl) {
2934
+ var swallowee = file[fr];
2935
+ this.debug("\nglobstar while", file, fr, pattern, pr, swallowee);
2936
+ if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
2937
+ this.debug("globstar found match!", fr, fl, swallowee);
2938
+ return true;
2939
+ } else {
2940
+ if (swallowee === "." || swallowee === ".." || !options.dot && swallowee.charAt(0) === ".") {
2941
+ this.debug("dot detected!", file, fr, pattern, pr);
2942
+ break;
2943
+ }
2944
+ this.debug("globstar swallow a segment, and continue");
2945
+ fr++;
2946
+ }
2947
+ }
2948
+ if (partial) {
2949
+ this.debug("\n>>> no match, partial?", file, fr, pattern, pr);
2950
+ if (fr === fl) {
2951
+ return true;
2952
+ }
2953
+ }
2954
+ return false;
2955
+ }
2956
+ let hit;
2957
+ if (typeof p === "string") {
2958
+ hit = f === p;
2959
+ this.debug("string match", p, f, hit);
2960
+ } else {
2961
+ hit = p.test(f);
2962
+ this.debug("pattern match", p, f, hit);
2963
+ }
2964
+ if (!hit)
2965
+ return false;
2966
+ }
2967
+ if (fi === fl && pi === pl) {
2968
+ return true;
2969
+ } else if (fi === fl) {
2970
+ return partial;
2971
+ } else if (pi === pl) {
2972
+ return fi === fl - 1 && file[fi] === "";
2973
+ } else {
2974
+ throw new Error("wtf?");
2975
+ }
2976
+ }
2977
+ braceExpand() {
2978
+ return braceExpand(this.pattern, this.options);
2979
+ }
2980
+ parse(pattern) {
2981
+ assertValidPattern(pattern);
2982
+ const options = this.options;
2983
+ if (pattern === "**")
2984
+ return GLOBSTAR;
2985
+ if (pattern === "")
2986
+ return "";
2987
+ let m;
2988
+ let fastTest = null;
2989
+ if (m = pattern.match(starRE)) {
2990
+ fastTest = options.dot ? starTestDot : starTest;
2991
+ } else if (m = pattern.match(starDotExtRE)) {
2992
+ fastTest = (options.nocase ? options.dot ? starDotExtTestNocaseDot : starDotExtTestNocase : options.dot ? starDotExtTestDot : starDotExtTest)(m[1]);
2993
+ } else if (m = pattern.match(qmarksRE)) {
2994
+ fastTest = (options.nocase ? options.dot ? qmarksTestNocaseDot : qmarksTestNocase : options.dot ? qmarksTestDot : qmarksTest)(m);
2995
+ } else if (m = pattern.match(starDotStarRE)) {
2996
+ fastTest = options.dot ? starDotStarTestDot : starDotStarTest;
2997
+ } else if (m = pattern.match(dotStarRE)) {
2998
+ fastTest = dotStarTest;
2999
+ }
3000
+ let re = "";
3001
+ let hasMagic = false;
3002
+ let escaping = false;
3003
+ const patternListStack = [];
3004
+ const negativeLists = [];
3005
+ let stateChar = false;
3006
+ let uflag = false;
3007
+ let pl;
3008
+ let dotTravAllowed = pattern.charAt(0) === ".";
3009
+ let dotFileAllowed = options.dot || dotTravAllowed;
3010
+ const patternStart = () => dotTravAllowed ? "" : dotFileAllowed ? "(?!(?:^|\\/)\\.{1,2}(?:$|\\/))" : "(?!\\.)";
3011
+ const subPatternStart = (p) => p.charAt(0) === "." ? "" : options.dot ? "(?!(?:^|\\/)\\.{1,2}(?:$|\\/))" : "(?!\\.)";
3012
+ const clearStateChar = () => {
3013
+ if (stateChar) {
3014
+ switch (stateChar) {
3015
+ case "*":
3016
+ re += star;
3017
+ hasMagic = true;
3018
+ break;
3019
+ case "?":
3020
+ re += qmark;
3021
+ hasMagic = true;
3022
+ break;
3023
+ default:
3024
+ re += "\\" + stateChar;
3025
+ break;
3026
+ }
3027
+ this.debug("clearStateChar %j %j", stateChar, re);
3028
+ stateChar = false;
3029
+ }
3030
+ };
3031
+ for (let i = 0, c; i < pattern.length && (c = pattern.charAt(i)); i++) {
3032
+ this.debug("%s %s %s %j", pattern, i, re, c);
3033
+ if (escaping) {
3034
+ if (c === "/") {
3035
+ return false;
3036
+ }
3037
+ if (reSpecials[c]) {
3038
+ re += "\\";
3039
+ }
3040
+ re += c;
3041
+ escaping = false;
3042
+ continue;
3043
+ }
3044
+ switch (c) {
3045
+ case "/": {
3046
+ return false;
3047
+ }
3048
+ case "\\":
3049
+ clearStateChar();
3050
+ escaping = true;
3051
+ continue;
3052
+ case "?":
3053
+ case "*":
3054
+ case "+":
3055
+ case "@":
3056
+ case "!":
3057
+ this.debug("%s %s %s %j <-- stateChar", pattern, i, re, c);
3058
+ this.debug("call clearStateChar %j", stateChar);
3059
+ clearStateChar();
3060
+ stateChar = c;
3061
+ if (options.noext)
3062
+ clearStateChar();
3063
+ continue;
3064
+ case "(": {
3065
+ if (!stateChar) {
3066
+ re += "\\(";
3067
+ continue;
3068
+ }
3069
+ const plEntry = {
3070
+ type: stateChar,
3071
+ start: i - 1,
3072
+ reStart: re.length,
3073
+ open: plTypes[stateChar].open,
3074
+ close: plTypes[stateChar].close
3075
+ };
3076
+ this.debug(this.pattern, " ", plEntry);
3077
+ patternListStack.push(plEntry);
3078
+ re += plEntry.open;
3079
+ if (plEntry.start === 0 && plEntry.type !== "!") {
3080
+ dotTravAllowed = true;
3081
+ re += subPatternStart(pattern.slice(i + 1));
3082
+ }
3083
+ this.debug("plType %j %j", stateChar, re);
3084
+ stateChar = false;
3085
+ continue;
3086
+ }
3087
+ case ")": {
3088
+ const plEntry = patternListStack[patternListStack.length - 1];
3089
+ if (!plEntry) {
3090
+ re += "\\)";
3091
+ continue;
3092
+ }
3093
+ patternListStack.pop();
3094
+ clearStateChar();
3095
+ hasMagic = true;
3096
+ pl = plEntry;
3097
+ re += pl.close;
3098
+ if (pl.type === "!") {
3099
+ negativeLists.push(Object.assign(pl, { reEnd: re.length }));
3100
+ }
3101
+ continue;
3102
+ }
3103
+ case "|": {
3104
+ const plEntry = patternListStack[patternListStack.length - 1];
3105
+ if (!plEntry) {
3106
+ re += "\\|";
3107
+ continue;
3108
+ }
3109
+ clearStateChar();
3110
+ re += "|";
3111
+ if (plEntry.start === 0 && plEntry.type !== "!") {
3112
+ dotTravAllowed = true;
3113
+ re += subPatternStart(pattern.slice(i + 1));
3114
+ }
3115
+ continue;
3116
+ }
3117
+ case "[":
3118
+ clearStateChar();
3119
+ const [src, needUflag, consumed, magic] = parseClass(pattern, i);
3120
+ if (consumed) {
3121
+ re += src;
3122
+ uflag = uflag || needUflag;
3123
+ i += consumed - 1;
3124
+ hasMagic = hasMagic || magic;
3125
+ } else {
3126
+ re += "\\[";
3127
+ }
3128
+ continue;
3129
+ case "]":
3130
+ re += "\\" + c;
3131
+ continue;
3132
+ default:
3133
+ clearStateChar();
3134
+ re += regExpEscape(c);
3135
+ break;
3136
+ }
3137
+ }
3138
+ for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
3139
+ let tail;
3140
+ tail = re.slice(pl.reStart + pl.open.length);
3141
+ this.debug(this.pattern, "setting tail", re, pl);
3142
+ tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, (_, $1, $2) => {
3143
+ if (!$2) {
3144
+ $2 = "\\";
3145
+ }
3146
+ return $1 + $1 + $2 + "|";
3147
+ });
3148
+ this.debug("tail=%j\n %s", tail, tail, pl, re);
3149
+ const t = pl.type === "*" ? star : pl.type === "?" ? qmark : "\\" + pl.type;
3150
+ hasMagic = true;
3151
+ re = re.slice(0, pl.reStart) + t + "\\(" + tail;
3152
+ }
3153
+ clearStateChar();
3154
+ if (escaping) {
3155
+ re += "\\\\";
3156
+ }
3157
+ const addPatternStart = addPatternStartSet[re.charAt(0)];
3158
+ for (let n = negativeLists.length - 1; n > -1; n--) {
3159
+ const nl = negativeLists[n];
3160
+ const nlBefore = re.slice(0, nl.reStart);
3161
+ const nlFirst = re.slice(nl.reStart, nl.reEnd - 8);
3162
+ let nlAfter = re.slice(nl.reEnd);
3163
+ const nlLast = re.slice(nl.reEnd - 8, nl.reEnd) + nlAfter;
3164
+ const closeParensBefore = nlBefore.split(")").length;
3165
+ const openParensBefore = nlBefore.split("(").length - closeParensBefore;
3166
+ let cleanAfter = nlAfter;
3167
+ for (let i = 0; i < openParensBefore; i++) {
3168
+ cleanAfter = cleanAfter.replace(/\)[+*?]?/, "");
3169
+ }
3170
+ nlAfter = cleanAfter;
3171
+ const dollar = nlAfter === "" ? "(?:$|\\/)" : "";
3172
+ re = nlBefore + nlFirst + nlAfter + dollar + nlLast;
3173
+ }
3174
+ if (re !== "" && hasMagic) {
3175
+ re = "(?=.)" + re;
3176
+ }
3177
+ if (addPatternStart) {
3178
+ re = patternStart() + re;
3179
+ }
3180
+ if (options.nocase && !hasMagic && !options.nocaseMagicOnly) {
3181
+ hasMagic = pattern.toUpperCase() !== pattern.toLowerCase();
3182
+ }
3183
+ if (!hasMagic) {
3184
+ return globUnescape(re);
3185
+ }
3186
+ const flags = (options.nocase ? "i" : "") + (uflag ? "u" : "");
3187
+ try {
3188
+ const ext2 = fastTest ? {
3189
+ _glob: pattern,
3190
+ _src: re,
3191
+ test: fastTest
3192
+ } : {
3193
+ _glob: pattern,
3194
+ _src: re
3195
+ };
3196
+ return Object.assign(new RegExp("^" + re + "$", flags), ext2);
3197
+ } catch (er) {
3198
+ this.debug("invalid regexp", er);
3199
+ return new RegExp("$.");
3200
+ }
3201
+ }
3202
+ makeRe() {
3203
+ if (this.regexp || this.regexp === false)
3204
+ return this.regexp;
3205
+ const set = this.set;
3206
+ if (!set.length) {
3207
+ this.regexp = false;
3208
+ return this.regexp;
3209
+ }
3210
+ const options = this.options;
3211
+ const twoStar = options.noglobstar ? star : options.dot ? twoStarDot : twoStarNoDot;
3212
+ const flags = options.nocase ? "i" : "";
3213
+ let re = set.map((pattern) => {
3214
+ const pp = pattern.map((p) => typeof p === "string" ? regExpEscape(p) : p === GLOBSTAR ? GLOBSTAR : p._src);
3215
+ pp.forEach((p, i) => {
3216
+ const next = pp[i + 1];
3217
+ const prev = pp[i - 1];
3218
+ if (p !== GLOBSTAR || prev === GLOBSTAR) {
3219
+ return;
3220
+ }
3221
+ if (prev === void 0) {
3222
+ if (next !== void 0 && next !== GLOBSTAR) {
3223
+ pp[i + 1] = "(?:\\/|" + twoStar + "\\/)?" + next;
3224
+ } else {
3225
+ pp[i] = twoStar;
3226
+ }
3227
+ } else if (next === void 0) {
3228
+ pp[i - 1] = prev + "(?:\\/|" + twoStar + ")?";
3229
+ } else if (next !== GLOBSTAR) {
3230
+ pp[i - 1] = prev + "(?:\\/|\\/" + twoStar + "\\/)" + next;
3231
+ pp[i + 1] = GLOBSTAR;
3232
+ }
3233
+ });
3234
+ return pp.filter((p) => p !== GLOBSTAR).join("/");
3235
+ }).join("|");
3236
+ re = "^(?:" + re + ")$";
3237
+ if (this.negate)
3238
+ re = "^(?!" + re + ").*$";
3239
+ try {
3240
+ this.regexp = new RegExp(re, flags);
3241
+ } catch (ex) {
3242
+ this.regexp = false;
3243
+ }
3244
+ return this.regexp;
3245
+ }
3246
+ slashSplit(p) {
3247
+ if (this.preserveMultipleSlashes) {
3248
+ return p.split("/");
3249
+ } else if (this.isWindows && /^\/\/[^\/]+/.test(p)) {
3250
+ return ["", ...p.split(/\/+/)];
3251
+ } else {
3252
+ return p.split(/\/+/);
3253
+ }
3254
+ }
3255
+ match(f, partial = this.partial) {
3256
+ this.debug("match", f, this.pattern);
3257
+ if (this.comment) {
3258
+ return false;
3259
+ }
3260
+ if (this.empty) {
3261
+ return f === "";
3262
+ }
3263
+ if (f === "/" && partial) {
3264
+ return true;
3265
+ }
3266
+ const options = this.options;
3267
+ if (this.isWindows) {
3268
+ f = f.split("\\").join("/");
3269
+ }
3270
+ const ff = this.slashSplit(f);
3271
+ this.debug(this.pattern, "split", ff);
3272
+ const set = this.set;
3273
+ this.debug(this.pattern, "set", set);
3274
+ let filename = ff[ff.length - 1];
3275
+ if (!filename) {
3276
+ for (let i = ff.length - 2; !filename && i >= 0; i--) {
3277
+ filename = ff[i];
3278
+ }
3279
+ }
3280
+ for (let i = 0; i < set.length; i++) {
3281
+ const pattern = set[i];
3282
+ let file = ff;
3283
+ if (options.matchBase && pattern.length === 1) {
3284
+ file = [filename];
3285
+ }
3286
+ const hit = this.matchOne(file, pattern, partial);
3287
+ if (hit) {
3288
+ if (options.flipNegate) {
3289
+ return true;
3290
+ }
3291
+ return !this.negate;
3292
+ }
3293
+ }
3294
+ if (options.flipNegate) {
3295
+ return false;
3296
+ }
3297
+ return this.negate;
3298
+ }
3299
+ static defaults(def) {
3300
+ return minimatch.defaults(def).Minimatch;
3301
+ }
3302
+ };
3303
+ minimatch.Minimatch = Minimatch;
3304
+ minimatch.escape = escape;
3305
+ minimatch.unescape = unescape;
3306
+
3307
+ // src/cli/commands/sqliteIntrospect.ts
3308
+ var import_hanji2 = __toESM(require_hanji());
3309
+ var sqlitePushIntrospect = async (client, filters) => {
3310
+ const matchers = filters.map((it) => {
3311
+ return new Minimatch(it);
3312
+ });
3313
+ const filter2 = (tableName) => {
3314
+ if (matchers.length === 0)
3315
+ return true;
3316
+ for (let i = 0; i < matchers.length; i++) {
3317
+ const matcher = matchers[i];
3318
+ if (matcher.match(tableName))
3319
+ return true;
3320
+ }
3321
+ return false;
3322
+ };
3323
+ const res = await fromDatabase2(client, filter2);
3324
+ const schema = { id: originUUID, prevId: "", ...res };
3325
+ return { schema };
3326
+ };
3327
+
3328
+ // src/cli/commands/pgIntrospect.ts
3329
+ var import_hanji3 = __toESM(require_hanji());
3330
+ init_views();
3331
+ init_pgSerializer();
3332
+
3333
+ // src/introspect.ts
3334
+ init_pgSerializer();
3335
+
3336
+ // src/cli/commands/pgIntrospect.ts
3337
+ var pgPushIntrospect = async (connection, filters, schemaFilters) => {
3338
+ const { client } = connection;
3339
+ const matchers = filters.map((it) => {
3340
+ return new Minimatch(it);
3341
+ });
3342
+ const filter2 = (tableName) => {
3343
+ if (matchers.length === 0)
3344
+ return true;
3345
+ for (let i = 0; i < matchers.length; i++) {
3346
+ const matcher = matchers[i];
3347
+ if (matcher.match(tableName))
3348
+ return true;
3349
+ }
3350
+ return false;
3351
+ };
3352
+ const res = await fromDatabase(client, filter2, schemaFilters);
3353
+ const schema = { id: originUUID, prevId: "", ...res };
3354
+ const { internal, ...schemaWithoutInternals } = schema;
3355
+ return { schema: schemaWithoutInternals };
3356
+ };
3357
+
3358
+ // src/utils-studio.ts
3359
+ init_drivers();
3360
+ // Annotate the CommonJS export names for ESM import in node:
3361
+ 0 && (module.exports = {
3362
+ DrizzleORMPgClient,
3363
+ drizzleSchemaPg,
3364
+ drizzleSchemaSQLite,
3365
+ pgPushIntrospect,
3366
+ sqlitePushIntrospect
3367
+ });