drizzle-kit 0.20.0-5198fb7 → 0.20.0-78ed9a3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3353 @@
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) => {
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
+ tables[t.name] = (0, import_pg_core.pgTable)(t.name, columns, (cb) => {
1045
+ const res = {};
1046
+ Object.values(t.compositePrimaryKeys).forEach((cpk) => {
1047
+ const gh = cpk.columns.map((c) => cb[c]);
1048
+ res[cpk.name] = new import_pg_core.PrimaryKeyBuilder(
1049
+ gh,
1050
+ cpk.name
1051
+ );
1052
+ });
1053
+ return res;
1054
+ });
1055
+ });
1056
+ return tables;
1057
+ };
1058
+ }
1059
+ });
1060
+
1061
+ // src/serializer/sqliteSerializer.ts
1062
+ function mapSqlToSqliteType(sqlType) {
1063
+ if ([
1064
+ "int",
1065
+ "integer",
1066
+ "integer auto_increment",
1067
+ "tinyint",
1068
+ "smallint",
1069
+ "mediumint",
1070
+ "bigint",
1071
+ "unsigned big int",
1072
+ "int2",
1073
+ "int8"
1074
+ ].includes(sqlType.toLowerCase())) {
1075
+ return "integer";
1076
+ } else if ([
1077
+ "character",
1078
+ "varchar",
1079
+ "vatying character",
1080
+ "nchar",
1081
+ "native character",
1082
+ "nvarchar",
1083
+ "text",
1084
+ "clob"
1085
+ ].some((it) => it.startsWith(sqlType.toLowerCase()))) {
1086
+ return "text";
1087
+ } else if (sqlType.toLowerCase() === "blob") {
1088
+ return "blob";
1089
+ } else if (["real", "double", "double precision", "float"].includes(
1090
+ sqlType.toLowerCase()
1091
+ )) {
1092
+ return "real";
1093
+ } else {
1094
+ return "numeric";
1095
+ }
1096
+ }
1097
+ var import_drizzle_orm2, import_sqlite_core, dialect2, fromDatabase2, toDrizzle2;
1098
+ var init_sqliteSerializer = __esm({
1099
+ "src/serializer/sqliteSerializer.ts"() {
1100
+ import_drizzle_orm2 = require("drizzle-orm");
1101
+ import_sqlite_core = require("drizzle-orm/sqlite-core");
1102
+ init_serializer();
1103
+ init_outputs();
1104
+ init_source();
1105
+ dialect2 = new import_sqlite_core.SQLiteSyncDialect();
1106
+ fromDatabase2 = async (db, tablesFilter = (table) => true, progressCallback) => {
1107
+ const result = {};
1108
+ const columns = await db.query(
1109
+ `SELECT
1110
+ 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
1111
+ FROM sqlite_master AS m JOIN pragma_table_info(m.name) AS p
1112
+ 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';
1113
+ `
1114
+ );
1115
+ const tablesWithSeq = [];
1116
+ const seq = await db.query(
1117
+ `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[^'']*';`
1118
+ );
1119
+ for (const s of seq) {
1120
+ tablesWithSeq.push(s.name);
1121
+ }
1122
+ let columnsCount = 0;
1123
+ let tablesCount = /* @__PURE__ */ new Set();
1124
+ let indexesCount = 0;
1125
+ let foreignKeysCount = 0;
1126
+ const tableToPk = {};
1127
+ for (const column of columns) {
1128
+ if (!tablesFilter(column.tableName))
1129
+ continue;
1130
+ columnsCount += 1;
1131
+ if (progressCallback) {
1132
+ progressCallback("columns", columnsCount, "fetching");
1133
+ }
1134
+ const tableName = column.tableName;
1135
+ tablesCount.add(tableName);
1136
+ if (progressCallback) {
1137
+ progressCallback("tables", tablesCount.size, "fetching");
1138
+ }
1139
+ const columnName = column.columnName;
1140
+ const isNotNull = column.notNull === 1;
1141
+ const columnType = column.columnType;
1142
+ const isPrimary = column.pk !== 0;
1143
+ const columnDefault = column.defaultValue;
1144
+ const isAutoincrement = isPrimary && tablesWithSeq.includes(tableName);
1145
+ if (isPrimary) {
1146
+ if (typeof tableToPk[tableName] === "undefined") {
1147
+ tableToPk[tableName] = [columnName];
1148
+ } else {
1149
+ tableToPk[tableName].push(columnName);
1150
+ }
1151
+ }
1152
+ const table = result[tableName];
1153
+ const newColumn = {
1154
+ default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) ? Number(columnDefault) : ["CURRENT_TIME", "CURRENT_DATE", "CURRENT_TIMESTAMP"].includes(
1155
+ columnDefault
1156
+ ) ? `(${columnDefault})` : columnDefault === "false" ? false : columnDefault === "true" ? true : columnDefault.startsWith("'") && columnDefault.endsWith("'") ? columnDefault : (
1157
+ // ? columnDefault.substring(1, columnDefault.length - 1)
1158
+ `(${columnDefault})`
1159
+ ),
1160
+ autoincrement: isAutoincrement,
1161
+ name: columnName,
1162
+ type: mapSqlToSqliteType(columnType),
1163
+ primaryKey: false,
1164
+ notNull: isNotNull
1165
+ };
1166
+ if (!table) {
1167
+ result[tableName] = {
1168
+ name: tableName,
1169
+ columns: {
1170
+ [columnName]: newColumn
1171
+ },
1172
+ compositePrimaryKeys: {},
1173
+ indexes: {},
1174
+ foreignKeys: {},
1175
+ uniqueConstraints: {}
1176
+ };
1177
+ } else {
1178
+ result[tableName].columns[columnName] = newColumn;
1179
+ }
1180
+ }
1181
+ for (const [key, value] of Object.entries(tableToPk)) {
1182
+ if (value.length > 1) {
1183
+ value.sort();
1184
+ result[key].compositePrimaryKeys = {
1185
+ [`${key}_${value.join("_")}_pk`]: {
1186
+ columns: value,
1187
+ name: `${key}_${value.join("_")}_pk`
1188
+ }
1189
+ };
1190
+ } else if (value.length === 1) {
1191
+ result[key].columns[value[0]].primaryKey = true;
1192
+ } else {
1193
+ }
1194
+ }
1195
+ if (progressCallback) {
1196
+ progressCallback("columns", columnsCount, "done");
1197
+ progressCallback("tables", tablesCount.size, "done");
1198
+ }
1199
+ try {
1200
+ const fks = await db.query(
1201
+ `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"
1202
+ FROM sqlite_master m, pragma_foreign_key_list(m.name) as f;`
1203
+ );
1204
+ const fkByTableName = {};
1205
+ for (const fkRow of fks) {
1206
+ foreignKeysCount += 1;
1207
+ if (progressCallback) {
1208
+ progressCallback("fks", foreignKeysCount, "fetching");
1209
+ }
1210
+ const tableName = fkRow.tableFrom;
1211
+ const columnName = fkRow.from;
1212
+ const refTableName = fkRow.tableTo;
1213
+ const refColumnName = fkRow.to;
1214
+ const updateRule = fkRow.onUpdate;
1215
+ const deleteRule = fkRow.onDelete;
1216
+ const sequence = fkRow.seq;
1217
+ const id = fkRow.id;
1218
+ const tableInResult = result[tableName];
1219
+ if (typeof tableInResult === "undefined")
1220
+ continue;
1221
+ if (typeof fkByTableName[`${tableName}_${id}`] !== "undefined") {
1222
+ fkByTableName[`${tableName}_${id}`].columnsFrom.push(columnName);
1223
+ fkByTableName[`${tableName}_${id}`].columnsTo.push(refColumnName);
1224
+ } else {
1225
+ fkByTableName[`${tableName}_${id}`] = {
1226
+ name: "",
1227
+ tableFrom: tableName,
1228
+ tableTo: refTableName,
1229
+ columnsFrom: [columnName],
1230
+ columnsTo: [refColumnName],
1231
+ onDelete: deleteRule == null ? void 0 : deleteRule.toLowerCase(),
1232
+ onUpdate: updateRule == null ? void 0 : updateRule.toLowerCase()
1233
+ };
1234
+ }
1235
+ const columnsFrom = fkByTableName[`${tableName}_${id}`].columnsFrom;
1236
+ const columnsTo = fkByTableName[`${tableName}_${id}`].columnsTo;
1237
+ fkByTableName[`${tableName}_${id}`].name = `${tableName}_${columnsFrom.join(
1238
+ "_"
1239
+ )}_${refTableName}_${columnsTo.join("_")}_fk`;
1240
+ }
1241
+ for (const idx of Object.keys(fkByTableName)) {
1242
+ const value = fkByTableName[idx];
1243
+ result[value.tableFrom].foreignKeys[value.name] = value;
1244
+ }
1245
+ } catch (e) {
1246
+ }
1247
+ if (progressCallback) {
1248
+ progressCallback("fks", foreignKeysCount, "done");
1249
+ }
1250
+ const idxs = await db.query(
1251
+ `SELECT
1252
+ m.tbl_name as tableName,
1253
+ il.name as indexName,
1254
+ ii.name as columnName,
1255
+ il.[unique] as isUnique,
1256
+ il.seq as seq
1257
+ FROM sqlite_master AS m,
1258
+ pragma_index_list(m.name) AS il,
1259
+ pragma_index_info(il.name) AS ii
1260
+ WHERE
1261
+ m.type = 'table' and il.name NOT LIKE 'sqlite_autoindex_%';`
1262
+ );
1263
+ for (const idxRow of idxs) {
1264
+ const tableName = idxRow.tableName;
1265
+ const constraintName = idxRow.indexName;
1266
+ const columnName = idxRow.columnName;
1267
+ const isUnique = idxRow.isUnique === 1;
1268
+ const tableInResult = result[tableName];
1269
+ if (typeof tableInResult === "undefined")
1270
+ continue;
1271
+ indexesCount += 1;
1272
+ if (progressCallback) {
1273
+ progressCallback("indexes", indexesCount, "fetching");
1274
+ }
1275
+ if (typeof tableInResult.indexes[constraintName] !== "undefined") {
1276
+ tableInResult.indexes[constraintName].columns.push(columnName);
1277
+ } else {
1278
+ tableInResult.indexes[constraintName] = {
1279
+ name: constraintName,
1280
+ columns: [columnName],
1281
+ isUnique
1282
+ };
1283
+ }
1284
+ }
1285
+ if (progressCallback) {
1286
+ progressCallback("indexes", indexesCount, "done");
1287
+ progressCallback("enums", 0, "done");
1288
+ }
1289
+ return {
1290
+ version: "5",
1291
+ dialect: "sqlite",
1292
+ tables: result,
1293
+ enums: {},
1294
+ _meta: {
1295
+ tables: {},
1296
+ columns: {}
1297
+ }
1298
+ };
1299
+ };
1300
+ toDrizzle2 = (schema) => {
1301
+ const tables = {};
1302
+ Object.values(schema.tables).forEach((t) => {
1303
+ const columns = {};
1304
+ Object.values(t.columns).forEach((c) => {
1305
+ const columnName = c.name;
1306
+ const type = c.type;
1307
+ let columnBuilder;
1308
+ if (type === "integer") {
1309
+ columnBuilder = new import_sqlite_core.SQLiteIntegerBuilder(columnName);
1310
+ } else if (type === "text") {
1311
+ columnBuilder = new import_sqlite_core.SQLiteTextBuilder(columnName, {});
1312
+ } else if (type === "blob") {
1313
+ columnBuilder = new import_sqlite_core.SQLiteBlobBufferBuilder(columnName);
1314
+ } else if (type === "real") {
1315
+ columnBuilder = new import_sqlite_core.SQLiteRealBuilder(columnName);
1316
+ } else {
1317
+ columnBuilder = new import_sqlite_core.SQLiteNumericBuilder(columnName);
1318
+ }
1319
+ if (c.notNull) {
1320
+ columnBuilder = columnBuilder.notNull();
1321
+ }
1322
+ if (c.default) {
1323
+ columnBuilder = columnBuilder.default(c.default);
1324
+ }
1325
+ if (c.primaryKey) {
1326
+ columnBuilder = columnBuilder.primaryKey();
1327
+ }
1328
+ columns[columnName] = columnBuilder;
1329
+ });
1330
+ tables[t.name] = (0, import_sqlite_core.sqliteTable)(t.name, columns, (cb) => {
1331
+ const res = {};
1332
+ Object.values(t.compositePrimaryKeys).forEach((cpk) => {
1333
+ const gh = cpk.columns.map((c) => cb[c]);
1334
+ res[cpk.name] = new import_sqlite_core.PrimaryKeyBuilder(
1335
+ gh,
1336
+ cpk.name
1337
+ );
1338
+ });
1339
+ return res;
1340
+ });
1341
+ });
1342
+ return tables;
1343
+ };
1344
+ }
1345
+ });
1346
+
1347
+ // node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/readline.js
1348
+ var require_readline = __commonJS({
1349
+ "node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/readline.js"(exports) {
1350
+ "use strict";
1351
+ Object.defineProperty(exports, "__esModule", { value: true });
1352
+ exports.prepareReadLine = void 0;
1353
+ var prepareReadLine = () => {
1354
+ const stdin = process.stdin;
1355
+ const stdout = process.stdout;
1356
+ const readline = require("readline");
1357
+ const rl = readline.createInterface({
1358
+ input: stdin,
1359
+ escapeCodeTimeout: 50
1360
+ });
1361
+ readline.emitKeypressEvents(stdin, rl);
1362
+ return {
1363
+ stdin,
1364
+ stdout,
1365
+ closable: rl
1366
+ };
1367
+ };
1368
+ exports.prepareReadLine = prepareReadLine;
1369
+ }
1370
+ });
1371
+
1372
+ // node_modules/.pnpm/sisteransi@1.0.5/node_modules/sisteransi/src/index.js
1373
+ var require_src = __commonJS({
1374
+ "node_modules/.pnpm/sisteransi@1.0.5/node_modules/sisteransi/src/index.js"(exports, module2) {
1375
+ "use strict";
1376
+ var ESC = "\x1B";
1377
+ var CSI = `${ESC}[`;
1378
+ var beep = "\x07";
1379
+ var cursor = {
1380
+ to(x, y) {
1381
+ if (!y)
1382
+ return `${CSI}${x + 1}G`;
1383
+ return `${CSI}${y + 1};${x + 1}H`;
1384
+ },
1385
+ move(x, y) {
1386
+ let ret = "";
1387
+ if (x < 0)
1388
+ ret += `${CSI}${-x}D`;
1389
+ else if (x > 0)
1390
+ ret += `${CSI}${x}C`;
1391
+ if (y < 0)
1392
+ ret += `${CSI}${-y}A`;
1393
+ else if (y > 0)
1394
+ ret += `${CSI}${y}B`;
1395
+ return ret;
1396
+ },
1397
+ up: (count = 1) => `${CSI}${count}A`,
1398
+ down: (count = 1) => `${CSI}${count}B`,
1399
+ forward: (count = 1) => `${CSI}${count}C`,
1400
+ backward: (count = 1) => `${CSI}${count}D`,
1401
+ nextLine: (count = 1) => `${CSI}E`.repeat(count),
1402
+ prevLine: (count = 1) => `${CSI}F`.repeat(count),
1403
+ left: `${CSI}G`,
1404
+ hide: `${CSI}?25l`,
1405
+ show: `${CSI}?25h`,
1406
+ save: `${ESC}7`,
1407
+ restore: `${ESC}8`
1408
+ };
1409
+ var scroll = {
1410
+ up: (count = 1) => `${CSI}S`.repeat(count),
1411
+ down: (count = 1) => `${CSI}T`.repeat(count)
1412
+ };
1413
+ var erase = {
1414
+ screen: `${CSI}2J`,
1415
+ up: (count = 1) => `${CSI}1J`.repeat(count),
1416
+ down: (count = 1) => `${CSI}J`.repeat(count),
1417
+ line: `${CSI}2K`,
1418
+ lineEnd: `${CSI}K`,
1419
+ lineStart: `${CSI}1K`,
1420
+ lines(count) {
1421
+ let clear = "";
1422
+ for (let i = 0; i < count; i++)
1423
+ clear += this.line + (i < count - 1 ? cursor.up() : "");
1424
+ if (count)
1425
+ clear += cursor.left;
1426
+ return clear;
1427
+ }
1428
+ };
1429
+ module2.exports = { cursor, scroll, erase, beep };
1430
+ }
1431
+ });
1432
+
1433
+ // node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/utils.js
1434
+ var require_utils = __commonJS({
1435
+ "node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/utils.js"(exports) {
1436
+ "use strict";
1437
+ Object.defineProperty(exports, "__esModule", { value: true });
1438
+ exports.clear = void 0;
1439
+ var sisteransi_1 = require_src();
1440
+ var strip = (str) => {
1441
+ const pattern = [
1442
+ "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
1443
+ "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
1444
+ ].join("|");
1445
+ const RGX = new RegExp(pattern, "g");
1446
+ return typeof str === "string" ? str.replace(RGX, "") : str;
1447
+ };
1448
+ var stringWidth = (str) => [...strip(str)].length;
1449
+ var clear = function(prompt, perLine) {
1450
+ if (!perLine)
1451
+ return sisteransi_1.erase.line + sisteransi_1.cursor.to(0);
1452
+ let rows = 0;
1453
+ const lines = prompt.split(/\r?\n/);
1454
+ for (let line of lines) {
1455
+ rows += 1 + Math.floor(Math.max(stringWidth(line) - 1, 0) / perLine);
1456
+ }
1457
+ return sisteransi_1.erase.lines(rows);
1458
+ };
1459
+ exports.clear = clear;
1460
+ }
1461
+ });
1462
+
1463
+ // node_modules/.pnpm/lodash.throttle@4.1.1/node_modules/lodash.throttle/index.js
1464
+ var require_lodash = __commonJS({
1465
+ "node_modules/.pnpm/lodash.throttle@4.1.1/node_modules/lodash.throttle/index.js"(exports, module2) {
1466
+ var FUNC_ERROR_TEXT = "Expected a function";
1467
+ var NAN = 0 / 0;
1468
+ var symbolTag = "[object Symbol]";
1469
+ var reTrim = /^\s+|\s+$/g;
1470
+ var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
1471
+ var reIsBinary = /^0b[01]+$/i;
1472
+ var reIsOctal = /^0o[0-7]+$/i;
1473
+ var freeParseInt = parseInt;
1474
+ var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
1475
+ var freeSelf = typeof self == "object" && self && self.Object === Object && self;
1476
+ var root = freeGlobal || freeSelf || Function("return this")();
1477
+ var objectProto = Object.prototype;
1478
+ var objectToString = objectProto.toString;
1479
+ var nativeMax = Math.max;
1480
+ var nativeMin = Math.min;
1481
+ var now = function() {
1482
+ return root.Date.now();
1483
+ };
1484
+ function debounce(func, wait, options) {
1485
+ var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
1486
+ if (typeof func != "function") {
1487
+ throw new TypeError(FUNC_ERROR_TEXT);
1488
+ }
1489
+ wait = toNumber(wait) || 0;
1490
+ if (isObject(options)) {
1491
+ leading = !!options.leading;
1492
+ maxing = "maxWait" in options;
1493
+ maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
1494
+ trailing = "trailing" in options ? !!options.trailing : trailing;
1495
+ }
1496
+ function invokeFunc(time) {
1497
+ var args = lastArgs, thisArg = lastThis;
1498
+ lastArgs = lastThis = void 0;
1499
+ lastInvokeTime = time;
1500
+ result = func.apply(thisArg, args);
1501
+ return result;
1502
+ }
1503
+ function leadingEdge(time) {
1504
+ lastInvokeTime = time;
1505
+ timerId = setTimeout(timerExpired, wait);
1506
+ return leading ? invokeFunc(time) : result;
1507
+ }
1508
+ function remainingWait(time) {
1509
+ var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime, result2 = wait - timeSinceLastCall;
1510
+ return maxing ? nativeMin(result2, maxWait - timeSinceLastInvoke) : result2;
1511
+ }
1512
+ function shouldInvoke(time) {
1513
+ var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime;
1514
+ return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
1515
+ }
1516
+ function timerExpired() {
1517
+ var time = now();
1518
+ if (shouldInvoke(time)) {
1519
+ return trailingEdge(time);
1520
+ }
1521
+ timerId = setTimeout(timerExpired, remainingWait(time));
1522
+ }
1523
+ function trailingEdge(time) {
1524
+ timerId = void 0;
1525
+ if (trailing && lastArgs) {
1526
+ return invokeFunc(time);
1527
+ }
1528
+ lastArgs = lastThis = void 0;
1529
+ return result;
1530
+ }
1531
+ function cancel() {
1532
+ if (timerId !== void 0) {
1533
+ clearTimeout(timerId);
1534
+ }
1535
+ lastInvokeTime = 0;
1536
+ lastArgs = lastCallTime = lastThis = timerId = void 0;
1537
+ }
1538
+ function flush() {
1539
+ return timerId === void 0 ? result : trailingEdge(now());
1540
+ }
1541
+ function debounced() {
1542
+ var time = now(), isInvoking = shouldInvoke(time);
1543
+ lastArgs = arguments;
1544
+ lastThis = this;
1545
+ lastCallTime = time;
1546
+ if (isInvoking) {
1547
+ if (timerId === void 0) {
1548
+ return leadingEdge(lastCallTime);
1549
+ }
1550
+ if (maxing) {
1551
+ timerId = setTimeout(timerExpired, wait);
1552
+ return invokeFunc(lastCallTime);
1553
+ }
1554
+ }
1555
+ if (timerId === void 0) {
1556
+ timerId = setTimeout(timerExpired, wait);
1557
+ }
1558
+ return result;
1559
+ }
1560
+ debounced.cancel = cancel;
1561
+ debounced.flush = flush;
1562
+ return debounced;
1563
+ }
1564
+ function throttle(func, wait, options) {
1565
+ var leading = true, trailing = true;
1566
+ if (typeof func != "function") {
1567
+ throw new TypeError(FUNC_ERROR_TEXT);
1568
+ }
1569
+ if (isObject(options)) {
1570
+ leading = "leading" in options ? !!options.leading : leading;
1571
+ trailing = "trailing" in options ? !!options.trailing : trailing;
1572
+ }
1573
+ return debounce(func, wait, {
1574
+ "leading": leading,
1575
+ "maxWait": wait,
1576
+ "trailing": trailing
1577
+ });
1578
+ }
1579
+ function isObject(value) {
1580
+ var type = typeof value;
1581
+ return !!value && (type == "object" || type == "function");
1582
+ }
1583
+ function isObjectLike(value) {
1584
+ return !!value && typeof value == "object";
1585
+ }
1586
+ function isSymbol(value) {
1587
+ return typeof value == "symbol" || isObjectLike(value) && objectToString.call(value) == symbolTag;
1588
+ }
1589
+ function toNumber(value) {
1590
+ if (typeof value == "number") {
1591
+ return value;
1592
+ }
1593
+ if (isSymbol(value)) {
1594
+ return NAN;
1595
+ }
1596
+ if (isObject(value)) {
1597
+ var other = typeof value.valueOf == "function" ? value.valueOf() : value;
1598
+ value = isObject(other) ? other + "" : other;
1599
+ }
1600
+ if (typeof value != "string") {
1601
+ return value === 0 ? value : +value;
1602
+ }
1603
+ value = value.replace(reTrim, "");
1604
+ var isBinary = reIsBinary.test(value);
1605
+ return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
1606
+ }
1607
+ module2.exports = throttle;
1608
+ }
1609
+ });
1610
+
1611
+ // node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/index.js
1612
+ var require_hanji = __commonJS({
1613
+ "node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/index.js"(exports) {
1614
+ "use strict";
1615
+ var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
1616
+ function adopt(value) {
1617
+ return value instanceof P ? value : new P(function(resolve) {
1618
+ resolve(value);
1619
+ });
1620
+ }
1621
+ return new (P || (P = Promise))(function(resolve, reject) {
1622
+ function fulfilled(value) {
1623
+ try {
1624
+ step(generator.next(value));
1625
+ } catch (e) {
1626
+ reject(e);
1627
+ }
1628
+ }
1629
+ function rejected(value) {
1630
+ try {
1631
+ step(generator["throw"](value));
1632
+ } catch (e) {
1633
+ reject(e);
1634
+ }
1635
+ }
1636
+ function step(result) {
1637
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
1638
+ }
1639
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1640
+ });
1641
+ };
1642
+ var __importDefault = exports && exports.__importDefault || function(mod) {
1643
+ return mod && mod.__esModule ? mod : { "default": mod };
1644
+ };
1645
+ Object.defineProperty(exports, "__esModule", { value: true });
1646
+ exports.onTerminate = exports.renderWithTask = exports.render = exports.TaskTerminal = exports.TaskView = exports.Terminal = exports.deferred = exports.SelectState = exports.Prompt = void 0;
1647
+ var readline_1 = require_readline();
1648
+ var sisteransi_1 = require_src();
1649
+ var utils_1 = require_utils();
1650
+ var lodash_throttle_1 = __importDefault(require_lodash());
1651
+ var Prompt2 = class {
1652
+ constructor() {
1653
+ this.attachCallbacks = [];
1654
+ this.detachCallbacks = [];
1655
+ this.inputCallbacks = [];
1656
+ }
1657
+ requestLayout() {
1658
+ this.terminal.requestLayout();
1659
+ }
1660
+ on(type, callback) {
1661
+ if (type === "attach") {
1662
+ this.attachCallbacks.push(callback);
1663
+ } else if (type === "detach") {
1664
+ this.detachCallbacks.push(callback);
1665
+ } else if (type === "input") {
1666
+ this.inputCallbacks.push(callback);
1667
+ }
1668
+ }
1669
+ attach(terminal) {
1670
+ this.terminal = terminal;
1671
+ this.attachCallbacks.forEach((it) => it(terminal));
1672
+ }
1673
+ detach(terminal) {
1674
+ this.detachCallbacks.forEach((it) => it(terminal));
1675
+ this.terminal = void 0;
1676
+ }
1677
+ input(str, key) {
1678
+ this.inputCallbacks.forEach((it) => it(str, key));
1679
+ }
1680
+ };
1681
+ exports.Prompt = Prompt2;
1682
+ var SelectState2 = class {
1683
+ constructor(items) {
1684
+ this.items = items;
1685
+ this.selectedIdx = 0;
1686
+ }
1687
+ bind(prompt) {
1688
+ prompt.on("input", (str, key) => {
1689
+ const invalidate = this.consume(str, key);
1690
+ if (invalidate)
1691
+ prompt.requestLayout();
1692
+ });
1693
+ }
1694
+ consume(str, key) {
1695
+ if (!key)
1696
+ return false;
1697
+ if (key.name === "down") {
1698
+ this.selectedIdx = (this.selectedIdx + 1) % this.items.length;
1699
+ return true;
1700
+ }
1701
+ if (key.name === "up") {
1702
+ this.selectedIdx -= 1;
1703
+ this.selectedIdx = this.selectedIdx < 0 ? this.items.length - 1 : this.selectedIdx;
1704
+ return true;
1705
+ }
1706
+ return false;
1707
+ }
1708
+ };
1709
+ exports.SelectState = SelectState2;
1710
+ var deferred = () => {
1711
+ let resolve;
1712
+ let reject;
1713
+ const promise = new Promise((res, rej) => {
1714
+ resolve = res;
1715
+ reject = rej;
1716
+ });
1717
+ return {
1718
+ resolve,
1719
+ reject,
1720
+ promise
1721
+ };
1722
+ };
1723
+ exports.deferred = deferred;
1724
+ var Terminal = class {
1725
+ constructor(view, stdin, stdout, closable) {
1726
+ this.view = view;
1727
+ this.stdin = stdin;
1728
+ this.stdout = stdout;
1729
+ this.closable = closable;
1730
+ this.text = "";
1731
+ this.status = "idle";
1732
+ if (this.stdin.isTTY)
1733
+ this.stdin.setRawMode(true);
1734
+ const keypress = (str, key) => {
1735
+ if (key.name === "c" && key.ctrl === true) {
1736
+ this.requestLayout();
1737
+ this.view.detach(this);
1738
+ this.tearDown(keypress);
1739
+ if (terminateHandler) {
1740
+ terminateHandler(this.stdin, this.stdout);
1741
+ return;
1742
+ }
1743
+ this.stdout.write(`
1744
+ ^C
1745
+ `);
1746
+ process.exit(1);
1747
+ }
1748
+ if (key.name === "escape") {
1749
+ this.status = "aborted";
1750
+ this.requestLayout();
1751
+ this.view.detach(this);
1752
+ this.tearDown(keypress);
1753
+ this.resolve({ status: "aborted", data: void 0 });
1754
+ return;
1755
+ }
1756
+ if (key.name === "return") {
1757
+ this.status = "submitted";
1758
+ this.requestLayout();
1759
+ this.view.detach(this);
1760
+ this.tearDown(keypress);
1761
+ this.resolve({ status: "submitted", data: this.view.result() });
1762
+ return;
1763
+ }
1764
+ view.input(str, key);
1765
+ };
1766
+ this.stdin.on("keypress", keypress);
1767
+ this.view.attach(this);
1768
+ const { resolve, promise } = (0, exports.deferred)();
1769
+ this.resolve = resolve;
1770
+ this.promise = promise;
1771
+ this.renderFunc = (0, lodash_throttle_1.default)((str) => {
1772
+ this.stdout.write(str);
1773
+ });
1774
+ }
1775
+ tearDown(keypress) {
1776
+ this.stdout.write(sisteransi_1.cursor.show);
1777
+ this.stdin.removeListener("keypress", keypress);
1778
+ if (this.stdin.isTTY)
1779
+ this.stdin.setRawMode(false);
1780
+ this.closable.close();
1781
+ }
1782
+ result() {
1783
+ return this.promise;
1784
+ }
1785
+ toggleCursor(state) {
1786
+ if (state === "hide") {
1787
+ this.stdout.write(sisteransi_1.cursor.hide);
1788
+ } else {
1789
+ this.stdout.write(sisteransi_1.cursor.show);
1790
+ }
1791
+ }
1792
+ requestLayout() {
1793
+ const string = this.view.render(this.status);
1794
+ const clearPrefix = this.text ? (0, utils_1.clear)(this.text, this.stdout.columns) : "";
1795
+ this.text = string;
1796
+ this.renderFunc(`${clearPrefix}${string}`);
1797
+ }
1798
+ };
1799
+ exports.Terminal = Terminal;
1800
+ var TaskView2 = class {
1801
+ constructor() {
1802
+ this.attachCallbacks = [];
1803
+ this.detachCallbacks = [];
1804
+ }
1805
+ requestLayout() {
1806
+ this.terminal.requestLayout();
1807
+ }
1808
+ attach(terminal) {
1809
+ this.terminal = terminal;
1810
+ this.attachCallbacks.forEach((it) => it(terminal));
1811
+ }
1812
+ detach(terminal) {
1813
+ this.detachCallbacks.forEach((it) => it(terminal));
1814
+ this.terminal = void 0;
1815
+ }
1816
+ on(type, callback) {
1817
+ if (type === "attach") {
1818
+ this.attachCallbacks.push(callback);
1819
+ } else if (type === "detach") {
1820
+ this.detachCallbacks.push(callback);
1821
+ }
1822
+ }
1823
+ };
1824
+ exports.TaskView = TaskView2;
1825
+ var TaskTerminal = class {
1826
+ constructor(view, stdout) {
1827
+ this.view = view;
1828
+ this.stdout = stdout;
1829
+ this.text = "";
1830
+ this.view.attach(this);
1831
+ }
1832
+ requestLayout() {
1833
+ const string = this.view.render("pending");
1834
+ const clearPrefix = this.text ? (0, utils_1.clear)(this.text, this.stdout.columns) : "";
1835
+ this.text = string;
1836
+ this.stdout.write(`${clearPrefix}${string}`);
1837
+ }
1838
+ clear() {
1839
+ const string = this.view.render("done");
1840
+ this.view.detach(this);
1841
+ const clearPrefix = this.text ? (0, utils_1.clear)(this.text, this.stdout.columns) : "";
1842
+ this.stdout.write(`${clearPrefix}${string}`);
1843
+ }
1844
+ };
1845
+ exports.TaskTerminal = TaskTerminal;
1846
+ function render2(view) {
1847
+ const { stdin, stdout, closable } = (0, readline_1.prepareReadLine)();
1848
+ if (view instanceof Prompt2) {
1849
+ const terminal = new Terminal(view, stdin, stdout, closable);
1850
+ terminal.requestLayout();
1851
+ return terminal.result();
1852
+ }
1853
+ stdout.write(`${view}
1854
+ `);
1855
+ closable.close();
1856
+ return;
1857
+ }
1858
+ exports.render = render2;
1859
+ function renderWithTask3(view, task) {
1860
+ return __awaiter(this, void 0, void 0, function* () {
1861
+ const terminal = new TaskTerminal(view, process.stdout);
1862
+ terminal.requestLayout();
1863
+ const result = yield task;
1864
+ terminal.clear();
1865
+ return result;
1866
+ });
1867
+ }
1868
+ exports.renderWithTask = renderWithTask3;
1869
+ var terminateHandler;
1870
+ function onTerminate(callback) {
1871
+ terminateHandler = callback;
1872
+ }
1873
+ exports.onTerminate = onTerminate;
1874
+ }
1875
+ });
1876
+
1877
+ // src/cli/views.ts
1878
+ var import_hanji;
1879
+ var init_views = __esm({
1880
+ "src/cli/views.ts"() {
1881
+ init_source();
1882
+ import_hanji = __toESM(require_hanji());
1883
+ }
1884
+ });
1885
+
1886
+ // node_modules/.pnpm/balanced-match@1.0.2/node_modules/balanced-match/index.js
1887
+ var require_balanced_match = __commonJS({
1888
+ "node_modules/.pnpm/balanced-match@1.0.2/node_modules/balanced-match/index.js"(exports, module2) {
1889
+ "use strict";
1890
+ module2.exports = balanced;
1891
+ function balanced(a, b, str) {
1892
+ if (a instanceof RegExp)
1893
+ a = maybeMatch(a, str);
1894
+ if (b instanceof RegExp)
1895
+ b = maybeMatch(b, str);
1896
+ var r = range(a, b, str);
1897
+ return r && {
1898
+ start: r[0],
1899
+ end: r[1],
1900
+ pre: str.slice(0, r[0]),
1901
+ body: str.slice(r[0] + a.length, r[1]),
1902
+ post: str.slice(r[1] + b.length)
1903
+ };
1904
+ }
1905
+ function maybeMatch(reg, str) {
1906
+ var m = str.match(reg);
1907
+ return m ? m[0] : null;
1908
+ }
1909
+ balanced.range = range;
1910
+ function range(a, b, str) {
1911
+ var begs, beg, left, right, result;
1912
+ var ai = str.indexOf(a);
1913
+ var bi = str.indexOf(b, ai + 1);
1914
+ var i = ai;
1915
+ if (ai >= 0 && bi > 0) {
1916
+ if (a === b) {
1917
+ return [ai, bi];
1918
+ }
1919
+ begs = [];
1920
+ left = str.length;
1921
+ while (i >= 0 && !result) {
1922
+ if (i == ai) {
1923
+ begs.push(i);
1924
+ ai = str.indexOf(a, i + 1);
1925
+ } else if (begs.length == 1) {
1926
+ result = [begs.pop(), bi];
1927
+ } else {
1928
+ beg = begs.pop();
1929
+ if (beg < left) {
1930
+ left = beg;
1931
+ right = bi;
1932
+ }
1933
+ bi = str.indexOf(b, i + 1);
1934
+ }
1935
+ i = ai < bi && ai >= 0 ? ai : bi;
1936
+ }
1937
+ if (begs.length) {
1938
+ result = [left, right];
1939
+ }
1940
+ }
1941
+ return result;
1942
+ }
1943
+ }
1944
+ });
1945
+
1946
+ // node_modules/.pnpm/brace-expansion@2.0.1/node_modules/brace-expansion/index.js
1947
+ var require_brace_expansion = __commonJS({
1948
+ "node_modules/.pnpm/brace-expansion@2.0.1/node_modules/brace-expansion/index.js"(exports, module2) {
1949
+ var balanced = require_balanced_match();
1950
+ module2.exports = expandTop;
1951
+ var escSlash = "\0SLASH" + Math.random() + "\0";
1952
+ var escOpen = "\0OPEN" + Math.random() + "\0";
1953
+ var escClose = "\0CLOSE" + Math.random() + "\0";
1954
+ var escComma = "\0COMMA" + Math.random() + "\0";
1955
+ var escPeriod = "\0PERIOD" + Math.random() + "\0";
1956
+ function numeric(str) {
1957
+ return parseInt(str, 10) == str ? parseInt(str, 10) : str.charCodeAt(0);
1958
+ }
1959
+ function escapeBraces(str) {
1960
+ return str.split("\\\\").join(escSlash).split("\\{").join(escOpen).split("\\}").join(escClose).split("\\,").join(escComma).split("\\.").join(escPeriod);
1961
+ }
1962
+ function unescapeBraces(str) {
1963
+ return str.split(escSlash).join("\\").split(escOpen).join("{").split(escClose).join("}").split(escComma).join(",").split(escPeriod).join(".");
1964
+ }
1965
+ function parseCommaParts(str) {
1966
+ if (!str)
1967
+ return [""];
1968
+ var parts = [];
1969
+ var m = balanced("{", "}", str);
1970
+ if (!m)
1971
+ return str.split(",");
1972
+ var pre = m.pre;
1973
+ var body = m.body;
1974
+ var post = m.post;
1975
+ var p = pre.split(",");
1976
+ p[p.length - 1] += "{" + body + "}";
1977
+ var postParts = parseCommaParts(post);
1978
+ if (post.length) {
1979
+ p[p.length - 1] += postParts.shift();
1980
+ p.push.apply(p, postParts);
1981
+ }
1982
+ parts.push.apply(parts, p);
1983
+ return parts;
1984
+ }
1985
+ function expandTop(str) {
1986
+ if (!str)
1987
+ return [];
1988
+ if (str.substr(0, 2) === "{}") {
1989
+ str = "\\{\\}" + str.substr(2);
1990
+ }
1991
+ return expand2(escapeBraces(str), true).map(unescapeBraces);
1992
+ }
1993
+ function embrace(str) {
1994
+ return "{" + str + "}";
1995
+ }
1996
+ function isPadded(el) {
1997
+ return /^-?0\d/.test(el);
1998
+ }
1999
+ function lte(i, y) {
2000
+ return i <= y;
2001
+ }
2002
+ function gte(i, y) {
2003
+ return i >= y;
2004
+ }
2005
+ function expand2(str, isTop) {
2006
+ var expansions = [];
2007
+ var m = balanced("{", "}", str);
2008
+ if (!m)
2009
+ return [str];
2010
+ var pre = m.pre;
2011
+ var post = m.post.length ? expand2(m.post, false) : [""];
2012
+ if (/\$$/.test(m.pre)) {
2013
+ for (var k = 0; k < post.length; k++) {
2014
+ var expansion = pre + "{" + m.body + "}" + post[k];
2015
+ expansions.push(expansion);
2016
+ }
2017
+ } else {
2018
+ var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
2019
+ var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
2020
+ var isSequence = isNumericSequence || isAlphaSequence;
2021
+ var isOptions = m.body.indexOf(",") >= 0;
2022
+ if (!isSequence && !isOptions) {
2023
+ if (m.post.match(/,.*\}/)) {
2024
+ str = m.pre + "{" + m.body + escClose + m.post;
2025
+ return expand2(str);
2026
+ }
2027
+ return [str];
2028
+ }
2029
+ var n;
2030
+ if (isSequence) {
2031
+ n = m.body.split(/\.\./);
2032
+ } else {
2033
+ n = parseCommaParts(m.body);
2034
+ if (n.length === 1) {
2035
+ n = expand2(n[0], false).map(embrace);
2036
+ if (n.length === 1) {
2037
+ return post.map(function(p) {
2038
+ return m.pre + n[0] + p;
2039
+ });
2040
+ }
2041
+ }
2042
+ }
2043
+ var N;
2044
+ if (isSequence) {
2045
+ var x = numeric(n[0]);
2046
+ var y = numeric(n[1]);
2047
+ var width = Math.max(n[0].length, n[1].length);
2048
+ var incr = n.length == 3 ? Math.abs(numeric(n[2])) : 1;
2049
+ var test = lte;
2050
+ var reverse = y < x;
2051
+ if (reverse) {
2052
+ incr *= -1;
2053
+ test = gte;
2054
+ }
2055
+ var pad = n.some(isPadded);
2056
+ N = [];
2057
+ for (var i = x; test(i, y); i += incr) {
2058
+ var c;
2059
+ if (isAlphaSequence) {
2060
+ c = String.fromCharCode(i);
2061
+ if (c === "\\")
2062
+ c = "";
2063
+ } else {
2064
+ c = String(i);
2065
+ if (pad) {
2066
+ var need = width - c.length;
2067
+ if (need > 0) {
2068
+ var z = new Array(need + 1).join("0");
2069
+ if (i < 0)
2070
+ c = "-" + z + c.slice(1);
2071
+ else
2072
+ c = z + c;
2073
+ }
2074
+ }
2075
+ }
2076
+ N.push(c);
2077
+ }
2078
+ } else {
2079
+ N = [];
2080
+ for (var j = 0; j < n.length; j++) {
2081
+ N.push.apply(N, expand2(n[j], false));
2082
+ }
2083
+ }
2084
+ for (var j = 0; j < N.length; j++) {
2085
+ for (var k = 0; k < post.length; k++) {
2086
+ var expansion = pre + N[j] + post[k];
2087
+ if (!isTop || isSequence || expansion)
2088
+ expansions.push(expansion);
2089
+ }
2090
+ }
2091
+ }
2092
+ return expansions;
2093
+ }
2094
+ }
2095
+ });
2096
+
2097
+ // src/drivers/index.ts
2098
+ var import_drizzle_orm3, DrizzleDbClient, DrizzleORMPgClient;
2099
+ var init_drivers = __esm({
2100
+ "src/drivers/index.ts"() {
2101
+ import_drizzle_orm3 = require("drizzle-orm");
2102
+ DrizzleDbClient = class {
2103
+ constructor(db) {
2104
+ this.db = db;
2105
+ }
2106
+ };
2107
+ DrizzleORMPgClient = class extends DrizzleDbClient {
2108
+ async query(query, values) {
2109
+ const res = await this.db.execute(import_drizzle_orm3.sql.raw(query));
2110
+ return res.rows;
2111
+ }
2112
+ async run(query) {
2113
+ const res = await this.db.execute(import_drizzle_orm3.sql.raw(query));
2114
+ return res.rows;
2115
+ }
2116
+ };
2117
+ }
2118
+ });
2119
+
2120
+ // src/utils-studio.ts
2121
+ var utils_studio_exports = {};
2122
+ __export(utils_studio_exports, {
2123
+ DrizzleORMPgClient: () => DrizzleORMPgClient,
2124
+ drizzleSchemaPg: () => toDrizzle,
2125
+ drizzleSchemaSQLite: () => toDrizzle2,
2126
+ pgPushIntrospect: () => pgPushIntrospect,
2127
+ sqlitePushIntrospect: () => sqlitePushIntrospect
2128
+ });
2129
+ module.exports = __toCommonJS(utils_studio_exports);
2130
+ init_pgSerializer();
2131
+ init_sqliteSerializer();
2132
+
2133
+ // src/cli/commands/sqliteIntrospect.ts
2134
+ init_views();
2135
+
2136
+ // src/global.ts
2137
+ var originUUID = "00000000-0000-0000-0000-000000000000";
2138
+
2139
+ // src/cli/commands/sqliteIntrospect.ts
2140
+ init_sqliteSerializer();
2141
+
2142
+ // node_modules/.pnpm/camelcase@7.0.1/node_modules/camelcase/index.js
2143
+ var UPPERCASE = /[\p{Lu}]/u;
2144
+ var LOWERCASE = /[\p{Ll}]/u;
2145
+ var LEADING_CAPITAL = /^[\p{Lu}](?![\p{Lu}])/gu;
2146
+ var IDENTIFIER = /([\p{Alpha}\p{N}_]|$)/u;
2147
+ var SEPARATORS = /[_.\- ]+/;
2148
+ var LEADING_SEPARATORS = new RegExp("^" + SEPARATORS.source);
2149
+ var SEPARATORS_AND_IDENTIFIER = new RegExp(SEPARATORS.source + IDENTIFIER.source, "gu");
2150
+ var NUMBERS_AND_IDENTIFIER = new RegExp("\\d+" + IDENTIFIER.source, "gu");
2151
+ var preserveCamelCase = (string, toLowerCase, toUpperCase, preserveConsecutiveUppercase2) => {
2152
+ let isLastCharLower = false;
2153
+ let isLastCharUpper = false;
2154
+ let isLastLastCharUpper = false;
2155
+ let isLastLastCharPreserved = false;
2156
+ for (let index = 0; index < string.length; index++) {
2157
+ const character = string[index];
2158
+ isLastLastCharPreserved = index > 2 ? string[index - 3] === "-" : true;
2159
+ if (isLastCharLower && UPPERCASE.test(character)) {
2160
+ string = string.slice(0, index) + "-" + string.slice(index);
2161
+ isLastCharLower = false;
2162
+ isLastLastCharUpper = isLastCharUpper;
2163
+ isLastCharUpper = true;
2164
+ index++;
2165
+ } else if (isLastCharUpper && isLastLastCharUpper && LOWERCASE.test(character) && (!isLastLastCharPreserved || preserveConsecutiveUppercase2)) {
2166
+ string = string.slice(0, index - 1) + "-" + string.slice(index - 1);
2167
+ isLastLastCharUpper = isLastCharUpper;
2168
+ isLastCharUpper = false;
2169
+ isLastCharLower = true;
2170
+ } else {
2171
+ isLastCharLower = toLowerCase(character) === character && toUpperCase(character) !== character;
2172
+ isLastLastCharUpper = isLastCharUpper;
2173
+ isLastCharUpper = toUpperCase(character) === character && toLowerCase(character) !== character;
2174
+ }
2175
+ }
2176
+ return string;
2177
+ };
2178
+ var preserveConsecutiveUppercase = (input, toLowerCase) => {
2179
+ LEADING_CAPITAL.lastIndex = 0;
2180
+ return input.replace(LEADING_CAPITAL, (m1) => toLowerCase(m1));
2181
+ };
2182
+ var postProcess = (input, toUpperCase) => {
2183
+ SEPARATORS_AND_IDENTIFIER.lastIndex = 0;
2184
+ NUMBERS_AND_IDENTIFIER.lastIndex = 0;
2185
+ return input.replace(SEPARATORS_AND_IDENTIFIER, (_, identifier) => toUpperCase(identifier)).replace(NUMBERS_AND_IDENTIFIER, (m) => toUpperCase(m));
2186
+ };
2187
+ function camelCase(input, options) {
2188
+ if (!(typeof input === "string" || Array.isArray(input))) {
2189
+ throw new TypeError("Expected the input to be `string | string[]`");
2190
+ }
2191
+ options = {
2192
+ pascalCase: false,
2193
+ preserveConsecutiveUppercase: false,
2194
+ ...options
2195
+ };
2196
+ if (Array.isArray(input)) {
2197
+ input = input.map((x) => x.trim()).filter((x) => x.length).join("-");
2198
+ } else {
2199
+ input = input.trim();
2200
+ }
2201
+ if (input.length === 0) {
2202
+ return "";
2203
+ }
2204
+ const toLowerCase = options.locale === false ? (string) => string.toLowerCase() : (string) => string.toLocaleLowerCase(options.locale);
2205
+ const toUpperCase = options.locale === false ? (string) => string.toUpperCase() : (string) => string.toLocaleUpperCase(options.locale);
2206
+ if (input.length === 1) {
2207
+ if (SEPARATORS.test(input)) {
2208
+ return "";
2209
+ }
2210
+ return options.pascalCase ? toUpperCase(input) : toLowerCase(input);
2211
+ }
2212
+ const hasUpperCase = input !== toLowerCase(input);
2213
+ if (hasUpperCase) {
2214
+ input = preserveCamelCase(input, toLowerCase, toUpperCase, options.preserveConsecutiveUppercase);
2215
+ }
2216
+ input = input.replace(LEADING_SEPARATORS, "");
2217
+ input = options.preserveConsecutiveUppercase ? preserveConsecutiveUppercase(input, toLowerCase) : toLowerCase(input);
2218
+ if (options.pascalCase) {
2219
+ input = toUpperCase(input.charAt(0)) + input.slice(1);
2220
+ }
2221
+ return postProcess(input, toUpperCase);
2222
+ }
2223
+
2224
+ // src/@types/utils.ts
2225
+ String.prototype.trimChar = function(char) {
2226
+ let start = 0;
2227
+ let end = this.length;
2228
+ while (start < end && this[start] === char)
2229
+ ++start;
2230
+ while (end > start && this[end - 1] === char)
2231
+ --end;
2232
+ return start > 0 || end < this.length ? this.substring(start, end) : this.toString();
2233
+ };
2234
+ String.prototype.squashSpaces = function() {
2235
+ return this.replace(/ +/g, " ").trim();
2236
+ };
2237
+ String.prototype.camelCase = function() {
2238
+ return camelCase(String(this));
2239
+ };
2240
+ String.prototype.concatIf = function(it, condition) {
2241
+ return condition ? `${this}${it}` : this;
2242
+ };
2243
+ Array.prototype.random = function() {
2244
+ return this[~~(Math.random() * this.length)];
2245
+ };
2246
+
2247
+ // node_modules/.pnpm/minimatch@7.4.3/node_modules/minimatch/dist/mjs/index.js
2248
+ var import_brace_expansion = __toESM(require_brace_expansion(), 1);
2249
+
2250
+ // node_modules/.pnpm/minimatch@7.4.3/node_modules/minimatch/dist/mjs/brace-expressions.js
2251
+ var posixClasses = {
2252
+ "[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}", true],
2253
+ "[:alpha:]": ["\\p{L}\\p{Nl}", true],
2254
+ "[:ascii:]": ["\\x00-\\x7f", false],
2255
+ "[:blank:]": ["\\p{Zs}\\t", true],
2256
+ "[:cntrl:]": ["\\p{Cc}", true],
2257
+ "[:digit:]": ["\\p{Nd}", true],
2258
+ "[:graph:]": ["\\p{Z}\\p{C}", true, true],
2259
+ "[:lower:]": ["\\p{Ll}", true],
2260
+ "[:print:]": ["\\p{C}", true],
2261
+ "[:punct:]": ["\\p{P}", true],
2262
+ "[:space:]": ["\\p{Z}\\t\\r\\n\\v\\f", true],
2263
+ "[:upper:]": ["\\p{Lu}", true],
2264
+ "[:word:]": ["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}", true],
2265
+ "[:xdigit:]": ["A-Fa-f0-9", false]
2266
+ };
2267
+ var braceEscape = (s) => s.replace(/[[\]\\-]/g, "\\$&");
2268
+ var regexpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
2269
+ var rangesToString = (ranges) => ranges.join("");
2270
+ var parseClass = (glob2, position) => {
2271
+ const pos = position;
2272
+ if (glob2.charAt(pos) !== "[") {
2273
+ throw new Error("not in a brace expression");
2274
+ }
2275
+ const ranges = [];
2276
+ const negs = [];
2277
+ let i = pos + 1;
2278
+ let sawStart = false;
2279
+ let uflag = false;
2280
+ let escaping = false;
2281
+ let negate = false;
2282
+ let endPos = pos;
2283
+ let rangeStart = "";
2284
+ WHILE:
2285
+ while (i < glob2.length) {
2286
+ const c = glob2.charAt(i);
2287
+ if ((c === "!" || c === "^") && i === pos + 1) {
2288
+ negate = true;
2289
+ i++;
2290
+ continue;
2291
+ }
2292
+ if (c === "]" && sawStart && !escaping) {
2293
+ endPos = i + 1;
2294
+ break;
2295
+ }
2296
+ sawStart = true;
2297
+ if (c === "\\") {
2298
+ if (!escaping) {
2299
+ escaping = true;
2300
+ i++;
2301
+ continue;
2302
+ }
2303
+ }
2304
+ if (c === "[" && !escaping) {
2305
+ for (const [cls, [unip, u, neg]] of Object.entries(posixClasses)) {
2306
+ if (glob2.startsWith(cls, i)) {
2307
+ if (rangeStart) {
2308
+ return ["$.", false, glob2.length - pos, true];
2309
+ }
2310
+ i += cls.length;
2311
+ if (neg)
2312
+ negs.push(unip);
2313
+ else
2314
+ ranges.push(unip);
2315
+ uflag = uflag || u;
2316
+ continue WHILE;
2317
+ }
2318
+ }
2319
+ }
2320
+ escaping = false;
2321
+ if (rangeStart) {
2322
+ if (c > rangeStart) {
2323
+ ranges.push(braceEscape(rangeStart) + "-" + braceEscape(c));
2324
+ } else if (c === rangeStart) {
2325
+ ranges.push(braceEscape(c));
2326
+ }
2327
+ rangeStart = "";
2328
+ i++;
2329
+ continue;
2330
+ }
2331
+ if (glob2.startsWith("-]", i + 1)) {
2332
+ ranges.push(braceEscape(c + "-"));
2333
+ i += 2;
2334
+ continue;
2335
+ }
2336
+ if (glob2.startsWith("-", i + 1)) {
2337
+ rangeStart = c;
2338
+ i += 2;
2339
+ continue;
2340
+ }
2341
+ ranges.push(braceEscape(c));
2342
+ i++;
2343
+ }
2344
+ if (endPos < i) {
2345
+ return ["", false, 0, false];
2346
+ }
2347
+ if (!ranges.length && !negs.length) {
2348
+ return ["$.", false, glob2.length - pos, true];
2349
+ }
2350
+ if (negs.length === 0 && ranges.length === 1 && /^\\?.$/.test(ranges[0]) && !negate) {
2351
+ const r = ranges[0].length === 2 ? ranges[0].slice(-1) : ranges[0];
2352
+ return [regexpEscape(r), false, endPos - pos, false];
2353
+ }
2354
+ const sranges = "[" + (negate ? "^" : "") + rangesToString(ranges) + "]";
2355
+ const snegs = "[" + (negate ? "" : "^") + rangesToString(negs) + "]";
2356
+ const comb = ranges.length && negs.length ? "(" + sranges + "|" + snegs + ")" : ranges.length ? sranges : snegs;
2357
+ return [comb, uflag, endPos - pos, true];
2358
+ };
2359
+
2360
+ // node_modules/.pnpm/minimatch@7.4.3/node_modules/minimatch/dist/mjs/escape.js
2361
+ var escape = (s, { windowsPathsNoEscape = false } = {}) => {
2362
+ return windowsPathsNoEscape ? s.replace(/[?*()[\]]/g, "[$&]") : s.replace(/[?*()[\]\\]/g, "\\$&");
2363
+ };
2364
+
2365
+ // node_modules/.pnpm/minimatch@7.4.3/node_modules/minimatch/dist/mjs/unescape.js
2366
+ var unescape = (s, { windowsPathsNoEscape = false } = {}) => {
2367
+ return windowsPathsNoEscape ? s.replace(/\[([^\/\\])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^\/\\])\]/g, "$1$2").replace(/\\([^\/])/g, "$1");
2368
+ };
2369
+
2370
+ // node_modules/.pnpm/minimatch@7.4.3/node_modules/minimatch/dist/mjs/index.js
2371
+ var minimatch = (p, pattern, options = {}) => {
2372
+ assertValidPattern(pattern);
2373
+ if (!options.nocomment && pattern.charAt(0) === "#") {
2374
+ return false;
2375
+ }
2376
+ return new Minimatch(pattern, options).match(p);
2377
+ };
2378
+ var starDotExtRE = /^\*+([^+@!?\*\[\(]*)$/;
2379
+ var starDotExtTest = (ext2) => (f) => !f.startsWith(".") && f.endsWith(ext2);
2380
+ var starDotExtTestDot = (ext2) => (f) => f.endsWith(ext2);
2381
+ var starDotExtTestNocase = (ext2) => {
2382
+ ext2 = ext2.toLowerCase();
2383
+ return (f) => !f.startsWith(".") && f.toLowerCase().endsWith(ext2);
2384
+ };
2385
+ var starDotExtTestNocaseDot = (ext2) => {
2386
+ ext2 = ext2.toLowerCase();
2387
+ return (f) => f.toLowerCase().endsWith(ext2);
2388
+ };
2389
+ var starDotStarRE = /^\*+\.\*+$/;
2390
+ var starDotStarTest = (f) => !f.startsWith(".") && f.includes(".");
2391
+ var starDotStarTestDot = (f) => f !== "." && f !== ".." && f.includes(".");
2392
+ var dotStarRE = /^\.\*+$/;
2393
+ var dotStarTest = (f) => f !== "." && f !== ".." && f.startsWith(".");
2394
+ var starRE = /^\*+$/;
2395
+ var starTest = (f) => f.length !== 0 && !f.startsWith(".");
2396
+ var starTestDot = (f) => f.length !== 0 && f !== "." && f !== "..";
2397
+ var qmarksRE = /^\?+([^+@!?\*\[\(]*)?$/;
2398
+ var qmarksTestNocase = ([$0, ext2 = ""]) => {
2399
+ const noext = qmarksTestNoExt([$0]);
2400
+ if (!ext2)
2401
+ return noext;
2402
+ ext2 = ext2.toLowerCase();
2403
+ return (f) => noext(f) && f.toLowerCase().endsWith(ext2);
2404
+ };
2405
+ var qmarksTestNocaseDot = ([$0, ext2 = ""]) => {
2406
+ const noext = qmarksTestNoExtDot([$0]);
2407
+ if (!ext2)
2408
+ return noext;
2409
+ ext2 = ext2.toLowerCase();
2410
+ return (f) => noext(f) && f.toLowerCase().endsWith(ext2);
2411
+ };
2412
+ var qmarksTestDot = ([$0, ext2 = ""]) => {
2413
+ const noext = qmarksTestNoExtDot([$0]);
2414
+ return !ext2 ? noext : (f) => noext(f) && f.endsWith(ext2);
2415
+ };
2416
+ var qmarksTest = ([$0, ext2 = ""]) => {
2417
+ const noext = qmarksTestNoExt([$0]);
2418
+ return !ext2 ? noext : (f) => noext(f) && f.endsWith(ext2);
2419
+ };
2420
+ var qmarksTestNoExt = ([$0]) => {
2421
+ const len = $0.length;
2422
+ return (f) => f.length === len && !f.startsWith(".");
2423
+ };
2424
+ var qmarksTestNoExtDot = ([$0]) => {
2425
+ const len = $0.length;
2426
+ return (f) => f.length === len && f !== "." && f !== "..";
2427
+ };
2428
+ var defaultPlatform = typeof process === "object" && process ? typeof process.env === "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix";
2429
+ var path = {
2430
+ win32: { sep: "\\" },
2431
+ posix: { sep: "/" }
2432
+ };
2433
+ var sep = defaultPlatform === "win32" ? path.win32.sep : path.posix.sep;
2434
+ minimatch.sep = sep;
2435
+ var GLOBSTAR = Symbol("globstar **");
2436
+ minimatch.GLOBSTAR = GLOBSTAR;
2437
+ var plTypes = {
2438
+ "!": { open: "(?:(?!(?:", close: "))[^/]*?)" },
2439
+ "?": { open: "(?:", close: ")?" },
2440
+ "+": { open: "(?:", close: ")+" },
2441
+ "*": { open: "(?:", close: ")*" },
2442
+ "@": { open: "(?:", close: ")" }
2443
+ };
2444
+ var qmark = "[^/]";
2445
+ var star = qmark + "*?";
2446
+ var twoStarDot = "(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?";
2447
+ var twoStarNoDot = "(?:(?!(?:\\/|^)\\.).)*?";
2448
+ var charSet = (s) => s.split("").reduce((set, c) => {
2449
+ set[c] = true;
2450
+ return set;
2451
+ }, {});
2452
+ var reSpecials = charSet("().*{}+?[]^$\\!");
2453
+ var addPatternStartSet = charSet("[.(");
2454
+ var filter = (pattern, options = {}) => (p) => minimatch(p, pattern, options);
2455
+ minimatch.filter = filter;
2456
+ var ext = (a, b = {}) => Object.assign({}, a, b);
2457
+ var defaults = (def) => {
2458
+ if (!def || typeof def !== "object" || !Object.keys(def).length) {
2459
+ return minimatch;
2460
+ }
2461
+ const orig = minimatch;
2462
+ const m = (p, pattern, options = {}) => orig(p, pattern, ext(def, options));
2463
+ return Object.assign(m, {
2464
+ Minimatch: class Minimatch extends orig.Minimatch {
2465
+ constructor(pattern, options = {}) {
2466
+ super(pattern, ext(def, options));
2467
+ }
2468
+ static defaults(options) {
2469
+ return orig.defaults(ext(def, options)).Minimatch;
2470
+ }
2471
+ },
2472
+ unescape: (s, options = {}) => orig.unescape(s, ext(def, options)),
2473
+ escape: (s, options = {}) => orig.escape(s, ext(def, options)),
2474
+ filter: (pattern, options = {}) => orig.filter(pattern, ext(def, options)),
2475
+ defaults: (options) => orig.defaults(ext(def, options)),
2476
+ makeRe: (pattern, options = {}) => orig.makeRe(pattern, ext(def, options)),
2477
+ braceExpand: (pattern, options = {}) => orig.braceExpand(pattern, ext(def, options)),
2478
+ match: (list, pattern, options = {}) => orig.match(list, pattern, ext(def, options)),
2479
+ sep: orig.sep,
2480
+ GLOBSTAR
2481
+ });
2482
+ };
2483
+ minimatch.defaults = defaults;
2484
+ var braceExpand = (pattern, options = {}) => {
2485
+ assertValidPattern(pattern);
2486
+ if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) {
2487
+ return [pattern];
2488
+ }
2489
+ return (0, import_brace_expansion.default)(pattern);
2490
+ };
2491
+ minimatch.braceExpand = braceExpand;
2492
+ var MAX_PATTERN_LENGTH = 1024 * 64;
2493
+ var assertValidPattern = (pattern) => {
2494
+ if (typeof pattern !== "string") {
2495
+ throw new TypeError("invalid pattern");
2496
+ }
2497
+ if (pattern.length > MAX_PATTERN_LENGTH) {
2498
+ throw new TypeError("pattern is too long");
2499
+ }
2500
+ };
2501
+ var makeRe = (pattern, options = {}) => new Minimatch(pattern, options).makeRe();
2502
+ minimatch.makeRe = makeRe;
2503
+ var match = (list, pattern, options = {}) => {
2504
+ const mm = new Minimatch(pattern, options);
2505
+ list = list.filter((f) => mm.match(f));
2506
+ if (mm.options.nonull && !list.length) {
2507
+ list.push(pattern);
2508
+ }
2509
+ return list;
2510
+ };
2511
+ minimatch.match = match;
2512
+ var globUnescape = (s) => s.replace(/\\(.)/g, "$1");
2513
+ var globMagic = /[?*]|[+@!]\(.*?\)|\[|\]/;
2514
+ var regExpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
2515
+ var Minimatch = class {
2516
+ options;
2517
+ set;
2518
+ pattern;
2519
+ windowsPathsNoEscape;
2520
+ nonegate;
2521
+ negate;
2522
+ comment;
2523
+ empty;
2524
+ preserveMultipleSlashes;
2525
+ partial;
2526
+ globSet;
2527
+ globParts;
2528
+ nocase;
2529
+ isWindows;
2530
+ platform;
2531
+ windowsNoMagicRoot;
2532
+ regexp;
2533
+ constructor(pattern, options = {}) {
2534
+ assertValidPattern(pattern);
2535
+ options = options || {};
2536
+ this.options = options;
2537
+ this.pattern = pattern;
2538
+ this.platform = options.platform || defaultPlatform;
2539
+ this.isWindows = this.platform === "win32";
2540
+ this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || options.allowWindowsEscape === false;
2541
+ if (this.windowsPathsNoEscape) {
2542
+ this.pattern = this.pattern.replace(/\\/g, "/");
2543
+ }
2544
+ this.preserveMultipleSlashes = !!options.preserveMultipleSlashes;
2545
+ this.regexp = null;
2546
+ this.negate = false;
2547
+ this.nonegate = !!options.nonegate;
2548
+ this.comment = false;
2549
+ this.empty = false;
2550
+ this.partial = !!options.partial;
2551
+ this.nocase = !!this.options.nocase;
2552
+ this.windowsNoMagicRoot = options.windowsNoMagicRoot !== void 0 ? options.windowsNoMagicRoot : !!(this.isWindows && this.nocase);
2553
+ this.globSet = [];
2554
+ this.globParts = [];
2555
+ this.set = [];
2556
+ this.make();
2557
+ }
2558
+ hasMagic() {
2559
+ if (this.options.magicalBraces && this.set.length > 1) {
2560
+ return true;
2561
+ }
2562
+ for (const pattern of this.set) {
2563
+ for (const part of pattern) {
2564
+ if (typeof part !== "string")
2565
+ return true;
2566
+ }
2567
+ }
2568
+ return false;
2569
+ }
2570
+ debug(..._) {
2571
+ }
2572
+ make() {
2573
+ const pattern = this.pattern;
2574
+ const options = this.options;
2575
+ if (!options.nocomment && pattern.charAt(0) === "#") {
2576
+ this.comment = true;
2577
+ return;
2578
+ }
2579
+ if (!pattern) {
2580
+ this.empty = true;
2581
+ return;
2582
+ }
2583
+ this.parseNegate();
2584
+ this.globSet = [...new Set(this.braceExpand())];
2585
+ if (options.debug) {
2586
+ this.debug = (...args) => console.error(...args);
2587
+ }
2588
+ this.debug(this.pattern, this.globSet);
2589
+ const rawGlobParts = this.globSet.map((s) => this.slashSplit(s));
2590
+ this.globParts = this.preprocess(rawGlobParts);
2591
+ this.debug(this.pattern, this.globParts);
2592
+ let set = this.globParts.map((s, _, __) => {
2593
+ if (this.isWindows && this.windowsNoMagicRoot) {
2594
+ const isUNC = s[0] === "" && s[1] === "" && (s[2] === "?" || !globMagic.test(s[2])) && !globMagic.test(s[3]);
2595
+ const isDrive = /^[a-z]:/i.test(s[0]);
2596
+ if (isUNC) {
2597
+ return [...s.slice(0, 4), ...s.slice(4).map((ss) => this.parse(ss))];
2598
+ } else if (isDrive) {
2599
+ return [s[0], ...s.slice(1).map((ss) => this.parse(ss))];
2600
+ }
2601
+ }
2602
+ return s.map((ss) => this.parse(ss));
2603
+ });
2604
+ this.debug(this.pattern, set);
2605
+ this.set = set.filter((s) => s.indexOf(false) === -1);
2606
+ if (this.isWindows) {
2607
+ for (let i = 0; i < this.set.length; i++) {
2608
+ const p = this.set[i];
2609
+ if (p[0] === "" && p[1] === "" && this.globParts[i][2] === "?" && typeof p[3] === "string" && /^[a-z]:$/i.test(p[3])) {
2610
+ p[2] = "?";
2611
+ }
2612
+ }
2613
+ }
2614
+ this.debug(this.pattern, this.set);
2615
+ }
2616
+ // various transforms to equivalent pattern sets that are
2617
+ // faster to process in a filesystem walk. The goal is to
2618
+ // eliminate what we can, and push all ** patterns as far
2619
+ // to the right as possible, even if it increases the number
2620
+ // of patterns that we have to process.
2621
+ preprocess(globParts) {
2622
+ if (this.options.noglobstar) {
2623
+ for (let i = 0; i < globParts.length; i++) {
2624
+ for (let j = 0; j < globParts[i].length; j++) {
2625
+ if (globParts[i][j] === "**") {
2626
+ globParts[i][j] = "*";
2627
+ }
2628
+ }
2629
+ }
2630
+ }
2631
+ const { optimizationLevel = 1 } = this.options;
2632
+ if (optimizationLevel >= 2) {
2633
+ globParts = this.firstPhasePreProcess(globParts);
2634
+ globParts = this.secondPhasePreProcess(globParts);
2635
+ } else if (optimizationLevel >= 1) {
2636
+ globParts = this.levelOneOptimize(globParts);
2637
+ } else {
2638
+ globParts = this.adjascentGlobstarOptimize(globParts);
2639
+ }
2640
+ return globParts;
2641
+ }
2642
+ // just get rid of adjascent ** portions
2643
+ adjascentGlobstarOptimize(globParts) {
2644
+ return globParts.map((parts) => {
2645
+ let gs = -1;
2646
+ while (-1 !== (gs = parts.indexOf("**", gs + 1))) {
2647
+ let i = gs;
2648
+ while (parts[i + 1] === "**") {
2649
+ i++;
2650
+ }
2651
+ if (i !== gs) {
2652
+ parts.splice(gs, i - gs);
2653
+ }
2654
+ }
2655
+ return parts;
2656
+ });
2657
+ }
2658
+ // get rid of adjascent ** and resolve .. portions
2659
+ levelOneOptimize(globParts) {
2660
+ return globParts.map((parts) => {
2661
+ parts = parts.reduce((set, part) => {
2662
+ const prev = set[set.length - 1];
2663
+ if (part === "**" && prev === "**") {
2664
+ return set;
2665
+ }
2666
+ if (part === "..") {
2667
+ if (prev && prev !== ".." && prev !== "." && prev !== "**") {
2668
+ set.pop();
2669
+ return set;
2670
+ }
2671
+ }
2672
+ set.push(part);
2673
+ return set;
2674
+ }, []);
2675
+ return parts.length === 0 ? [""] : parts;
2676
+ });
2677
+ }
2678
+ levelTwoFileOptimize(parts) {
2679
+ if (!Array.isArray(parts)) {
2680
+ parts = this.slashSplit(parts);
2681
+ }
2682
+ let didSomething = false;
2683
+ do {
2684
+ didSomething = false;
2685
+ if (!this.preserveMultipleSlashes) {
2686
+ for (let i = 1; i < parts.length - 1; i++) {
2687
+ const p = parts[i];
2688
+ if (i === 1 && p === "" && parts[0] === "")
2689
+ continue;
2690
+ if (p === "." || p === "") {
2691
+ didSomething = true;
2692
+ parts.splice(i, 1);
2693
+ i--;
2694
+ }
2695
+ }
2696
+ if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
2697
+ didSomething = true;
2698
+ parts.pop();
2699
+ }
2700
+ }
2701
+ let dd = 0;
2702
+ while (-1 !== (dd = parts.indexOf("..", dd + 1))) {
2703
+ const p = parts[dd - 1];
2704
+ if (p && p !== "." && p !== ".." && p !== "**") {
2705
+ didSomething = true;
2706
+ parts.splice(dd - 1, 2);
2707
+ dd -= 2;
2708
+ }
2709
+ }
2710
+ } while (didSomething);
2711
+ return parts.length === 0 ? [""] : parts;
2712
+ }
2713
+ // First phase: single-pattern processing
2714
+ // <pre> is 1 or more portions
2715
+ // <rest> is 1 or more portions
2716
+ // <p> is any portion other than ., .., '', or **
2717
+ // <e> is . or ''
2718
+ //
2719
+ // **/.. is *brutal* for filesystem walking performance, because
2720
+ // it effectively resets the recursive walk each time it occurs,
2721
+ // and ** cannot be reduced out by a .. pattern part like a regexp
2722
+ // or most strings (other than .., ., and '') can be.
2723
+ //
2724
+ // <pre>/**/../<p>/<p>/<rest> -> {<pre>/../<p>/<p>/<rest>,<pre>/**/<p>/<p>/<rest>}
2725
+ // <pre>/<e>/<rest> -> <pre>/<rest>
2726
+ // <pre>/<p>/../<rest> -> <pre>/<rest>
2727
+ // **/**/<rest> -> **/<rest>
2728
+ //
2729
+ // **/*/<rest> -> */**/<rest> <== not valid because ** doesn't follow
2730
+ // this WOULD be allowed if ** did follow symlinks, or * didn't
2731
+ firstPhasePreProcess(globParts) {
2732
+ let didSomething = false;
2733
+ do {
2734
+ didSomething = false;
2735
+ for (let parts of globParts) {
2736
+ let gs = -1;
2737
+ while (-1 !== (gs = parts.indexOf("**", gs + 1))) {
2738
+ let gss = gs;
2739
+ while (parts[gss + 1] === "**") {
2740
+ gss++;
2741
+ }
2742
+ if (gss > gs) {
2743
+ parts.splice(gs + 1, gss - gs);
2744
+ }
2745
+ let next = parts[gs + 1];
2746
+ const p = parts[gs + 2];
2747
+ const p2 = parts[gs + 3];
2748
+ if (next !== "..")
2749
+ continue;
2750
+ if (!p || p === "." || p === ".." || !p2 || p2 === "." || p2 === "..") {
2751
+ continue;
2752
+ }
2753
+ didSomething = true;
2754
+ parts.splice(gs, 1);
2755
+ const other = parts.slice(0);
2756
+ other[gs] = "**";
2757
+ globParts.push(other);
2758
+ gs--;
2759
+ }
2760
+ if (!this.preserveMultipleSlashes) {
2761
+ for (let i = 1; i < parts.length - 1; i++) {
2762
+ const p = parts[i];
2763
+ if (i === 1 && p === "" && parts[0] === "")
2764
+ continue;
2765
+ if (p === "." || p === "") {
2766
+ didSomething = true;
2767
+ parts.splice(i, 1);
2768
+ i--;
2769
+ }
2770
+ }
2771
+ if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
2772
+ didSomething = true;
2773
+ parts.pop();
2774
+ }
2775
+ }
2776
+ let dd = 0;
2777
+ while (-1 !== (dd = parts.indexOf("..", dd + 1))) {
2778
+ const p = parts[dd - 1];
2779
+ if (p && p !== "." && p !== ".." && p !== "**") {
2780
+ didSomething = true;
2781
+ const needDot = dd === 1 && parts[dd + 1] === "**";
2782
+ const splin = needDot ? ["."] : [];
2783
+ parts.splice(dd - 1, 2, ...splin);
2784
+ if (parts.length === 0)
2785
+ parts.push("");
2786
+ dd -= 2;
2787
+ }
2788
+ }
2789
+ }
2790
+ } while (didSomething);
2791
+ return globParts;
2792
+ }
2793
+ // second phase: multi-pattern dedupes
2794
+ // {<pre>/*/<rest>,<pre>/<p>/<rest>} -> <pre>/*/<rest>
2795
+ // {<pre>/<rest>,<pre>/<rest>} -> <pre>/<rest>
2796
+ // {<pre>/**/<rest>,<pre>/<rest>} -> <pre>/**/<rest>
2797
+ //
2798
+ // {<pre>/**/<rest>,<pre>/**/<p>/<rest>} -> <pre>/**/<rest>
2799
+ // ^-- not valid because ** doens't follow symlinks
2800
+ secondPhasePreProcess(globParts) {
2801
+ for (let i = 0; i < globParts.length - 1; i++) {
2802
+ for (let j = i + 1; j < globParts.length; j++) {
2803
+ const matched = this.partsMatch(globParts[i], globParts[j], !this.preserveMultipleSlashes);
2804
+ if (!matched)
2805
+ continue;
2806
+ globParts[i] = matched;
2807
+ globParts[j] = [];
2808
+ }
2809
+ }
2810
+ return globParts.filter((gs) => gs.length);
2811
+ }
2812
+ partsMatch(a, b, emptyGSMatch = false) {
2813
+ let ai = 0;
2814
+ let bi = 0;
2815
+ let result = [];
2816
+ let which = "";
2817
+ while (ai < a.length && bi < b.length) {
2818
+ if (a[ai] === b[bi]) {
2819
+ result.push(which === "b" ? b[bi] : a[ai]);
2820
+ ai++;
2821
+ bi++;
2822
+ } else if (emptyGSMatch && a[ai] === "**" && b[bi] === a[ai + 1]) {
2823
+ result.push(a[ai]);
2824
+ ai++;
2825
+ } else if (emptyGSMatch && b[bi] === "**" && a[ai] === b[bi + 1]) {
2826
+ result.push(b[bi]);
2827
+ bi++;
2828
+ } else if (a[ai] === "*" && b[bi] && (this.options.dot || !b[bi].startsWith(".")) && b[bi] !== "**") {
2829
+ if (which === "b")
2830
+ return false;
2831
+ which = "a";
2832
+ result.push(a[ai]);
2833
+ ai++;
2834
+ bi++;
2835
+ } else if (b[bi] === "*" && a[ai] && (this.options.dot || !a[ai].startsWith(".")) && a[ai] !== "**") {
2836
+ if (which === "a")
2837
+ return false;
2838
+ which = "b";
2839
+ result.push(b[bi]);
2840
+ ai++;
2841
+ bi++;
2842
+ } else {
2843
+ return false;
2844
+ }
2845
+ }
2846
+ return a.length === b.length && result;
2847
+ }
2848
+ parseNegate() {
2849
+ if (this.nonegate)
2850
+ return;
2851
+ const pattern = this.pattern;
2852
+ let negate = false;
2853
+ let negateOffset = 0;
2854
+ for (let i = 0; i < pattern.length && pattern.charAt(i) === "!"; i++) {
2855
+ negate = !negate;
2856
+ negateOffset++;
2857
+ }
2858
+ if (negateOffset)
2859
+ this.pattern = pattern.slice(negateOffset);
2860
+ this.negate = negate;
2861
+ }
2862
+ // set partial to true to test if, for example,
2863
+ // "/a/b" matches the start of "/*/b/*/d"
2864
+ // Partial means, if you run out of file before you run
2865
+ // out of pattern, then that's fine, as long as all
2866
+ // the parts match.
2867
+ matchOne(file, pattern, partial = false) {
2868
+ const options = this.options;
2869
+ if (this.isWindows) {
2870
+ const fileUNC = file[0] === "" && file[1] === "" && file[2] === "?" && typeof file[3] === "string" && /^[a-z]:$/i.test(file[3]);
2871
+ const patternUNC = pattern[0] === "" && pattern[1] === "" && pattern[2] === "?" && typeof pattern[3] === "string" && /^[a-z]:$/i.test(pattern[3]);
2872
+ if (fileUNC && patternUNC) {
2873
+ const fd = file[3];
2874
+ const pd = pattern[3];
2875
+ if (fd.toLowerCase() === pd.toLowerCase()) {
2876
+ file[3] = pd;
2877
+ }
2878
+ } else if (patternUNC && typeof file[0] === "string") {
2879
+ const pd = pattern[3];
2880
+ const fd = file[0];
2881
+ if (pd.toLowerCase() === fd.toLowerCase()) {
2882
+ pattern[3] = fd;
2883
+ pattern = pattern.slice(3);
2884
+ }
2885
+ } else if (fileUNC && typeof pattern[0] === "string") {
2886
+ const fd = file[3];
2887
+ if (fd.toLowerCase() === pattern[0].toLowerCase()) {
2888
+ pattern[0] = fd;
2889
+ file = file.slice(3);
2890
+ }
2891
+ }
2892
+ }
2893
+ const { optimizationLevel = 1 } = this.options;
2894
+ if (optimizationLevel >= 2) {
2895
+ file = this.levelTwoFileOptimize(file);
2896
+ }
2897
+ this.debug("matchOne", this, { file, pattern });
2898
+ this.debug("matchOne", file.length, pattern.length);
2899
+ for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
2900
+ this.debug("matchOne loop");
2901
+ var p = pattern[pi];
2902
+ var f = file[fi];
2903
+ this.debug(pattern, p, f);
2904
+ if (p === false) {
2905
+ return false;
2906
+ }
2907
+ if (p === GLOBSTAR) {
2908
+ this.debug("GLOBSTAR", [pattern, p, f]);
2909
+ var fr = fi;
2910
+ var pr = pi + 1;
2911
+ if (pr === pl) {
2912
+ this.debug("** at the end");
2913
+ for (; fi < fl; fi++) {
2914
+ if (file[fi] === "." || file[fi] === ".." || !options.dot && file[fi].charAt(0) === ".")
2915
+ return false;
2916
+ }
2917
+ return true;
2918
+ }
2919
+ while (fr < fl) {
2920
+ var swallowee = file[fr];
2921
+ this.debug("\nglobstar while", file, fr, pattern, pr, swallowee);
2922
+ if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
2923
+ this.debug("globstar found match!", fr, fl, swallowee);
2924
+ return true;
2925
+ } else {
2926
+ if (swallowee === "." || swallowee === ".." || !options.dot && swallowee.charAt(0) === ".") {
2927
+ this.debug("dot detected!", file, fr, pattern, pr);
2928
+ break;
2929
+ }
2930
+ this.debug("globstar swallow a segment, and continue");
2931
+ fr++;
2932
+ }
2933
+ }
2934
+ if (partial) {
2935
+ this.debug("\n>>> no match, partial?", file, fr, pattern, pr);
2936
+ if (fr === fl) {
2937
+ return true;
2938
+ }
2939
+ }
2940
+ return false;
2941
+ }
2942
+ let hit;
2943
+ if (typeof p === "string") {
2944
+ hit = f === p;
2945
+ this.debug("string match", p, f, hit);
2946
+ } else {
2947
+ hit = p.test(f);
2948
+ this.debug("pattern match", p, f, hit);
2949
+ }
2950
+ if (!hit)
2951
+ return false;
2952
+ }
2953
+ if (fi === fl && pi === pl) {
2954
+ return true;
2955
+ } else if (fi === fl) {
2956
+ return partial;
2957
+ } else if (pi === pl) {
2958
+ return fi === fl - 1 && file[fi] === "";
2959
+ } else {
2960
+ throw new Error("wtf?");
2961
+ }
2962
+ }
2963
+ braceExpand() {
2964
+ return braceExpand(this.pattern, this.options);
2965
+ }
2966
+ parse(pattern) {
2967
+ assertValidPattern(pattern);
2968
+ const options = this.options;
2969
+ if (pattern === "**")
2970
+ return GLOBSTAR;
2971
+ if (pattern === "")
2972
+ return "";
2973
+ let m;
2974
+ let fastTest = null;
2975
+ if (m = pattern.match(starRE)) {
2976
+ fastTest = options.dot ? starTestDot : starTest;
2977
+ } else if (m = pattern.match(starDotExtRE)) {
2978
+ fastTest = (options.nocase ? options.dot ? starDotExtTestNocaseDot : starDotExtTestNocase : options.dot ? starDotExtTestDot : starDotExtTest)(m[1]);
2979
+ } else if (m = pattern.match(qmarksRE)) {
2980
+ fastTest = (options.nocase ? options.dot ? qmarksTestNocaseDot : qmarksTestNocase : options.dot ? qmarksTestDot : qmarksTest)(m);
2981
+ } else if (m = pattern.match(starDotStarRE)) {
2982
+ fastTest = options.dot ? starDotStarTestDot : starDotStarTest;
2983
+ } else if (m = pattern.match(dotStarRE)) {
2984
+ fastTest = dotStarTest;
2985
+ }
2986
+ let re = "";
2987
+ let hasMagic = false;
2988
+ let escaping = false;
2989
+ const patternListStack = [];
2990
+ const negativeLists = [];
2991
+ let stateChar = false;
2992
+ let uflag = false;
2993
+ let pl;
2994
+ let dotTravAllowed = pattern.charAt(0) === ".";
2995
+ let dotFileAllowed = options.dot || dotTravAllowed;
2996
+ const patternStart = () => dotTravAllowed ? "" : dotFileAllowed ? "(?!(?:^|\\/)\\.{1,2}(?:$|\\/))" : "(?!\\.)";
2997
+ const subPatternStart = (p) => p.charAt(0) === "." ? "" : options.dot ? "(?!(?:^|\\/)\\.{1,2}(?:$|\\/))" : "(?!\\.)";
2998
+ const clearStateChar = () => {
2999
+ if (stateChar) {
3000
+ switch (stateChar) {
3001
+ case "*":
3002
+ re += star;
3003
+ hasMagic = true;
3004
+ break;
3005
+ case "?":
3006
+ re += qmark;
3007
+ hasMagic = true;
3008
+ break;
3009
+ default:
3010
+ re += "\\" + stateChar;
3011
+ break;
3012
+ }
3013
+ this.debug("clearStateChar %j %j", stateChar, re);
3014
+ stateChar = false;
3015
+ }
3016
+ };
3017
+ for (let i = 0, c; i < pattern.length && (c = pattern.charAt(i)); i++) {
3018
+ this.debug("%s %s %s %j", pattern, i, re, c);
3019
+ if (escaping) {
3020
+ if (c === "/") {
3021
+ return false;
3022
+ }
3023
+ if (reSpecials[c]) {
3024
+ re += "\\";
3025
+ }
3026
+ re += c;
3027
+ escaping = false;
3028
+ continue;
3029
+ }
3030
+ switch (c) {
3031
+ case "/": {
3032
+ return false;
3033
+ }
3034
+ case "\\":
3035
+ clearStateChar();
3036
+ escaping = true;
3037
+ continue;
3038
+ case "?":
3039
+ case "*":
3040
+ case "+":
3041
+ case "@":
3042
+ case "!":
3043
+ this.debug("%s %s %s %j <-- stateChar", pattern, i, re, c);
3044
+ this.debug("call clearStateChar %j", stateChar);
3045
+ clearStateChar();
3046
+ stateChar = c;
3047
+ if (options.noext)
3048
+ clearStateChar();
3049
+ continue;
3050
+ case "(": {
3051
+ if (!stateChar) {
3052
+ re += "\\(";
3053
+ continue;
3054
+ }
3055
+ const plEntry = {
3056
+ type: stateChar,
3057
+ start: i - 1,
3058
+ reStart: re.length,
3059
+ open: plTypes[stateChar].open,
3060
+ close: plTypes[stateChar].close
3061
+ };
3062
+ this.debug(this.pattern, " ", plEntry);
3063
+ patternListStack.push(plEntry);
3064
+ re += plEntry.open;
3065
+ if (plEntry.start === 0 && plEntry.type !== "!") {
3066
+ dotTravAllowed = true;
3067
+ re += subPatternStart(pattern.slice(i + 1));
3068
+ }
3069
+ this.debug("plType %j %j", stateChar, re);
3070
+ stateChar = false;
3071
+ continue;
3072
+ }
3073
+ case ")": {
3074
+ const plEntry = patternListStack[patternListStack.length - 1];
3075
+ if (!plEntry) {
3076
+ re += "\\)";
3077
+ continue;
3078
+ }
3079
+ patternListStack.pop();
3080
+ clearStateChar();
3081
+ hasMagic = true;
3082
+ pl = plEntry;
3083
+ re += pl.close;
3084
+ if (pl.type === "!") {
3085
+ negativeLists.push(Object.assign(pl, { reEnd: re.length }));
3086
+ }
3087
+ continue;
3088
+ }
3089
+ case "|": {
3090
+ const plEntry = patternListStack[patternListStack.length - 1];
3091
+ if (!plEntry) {
3092
+ re += "\\|";
3093
+ continue;
3094
+ }
3095
+ clearStateChar();
3096
+ re += "|";
3097
+ if (plEntry.start === 0 && plEntry.type !== "!") {
3098
+ dotTravAllowed = true;
3099
+ re += subPatternStart(pattern.slice(i + 1));
3100
+ }
3101
+ continue;
3102
+ }
3103
+ case "[":
3104
+ clearStateChar();
3105
+ const [src, needUflag, consumed, magic] = parseClass(pattern, i);
3106
+ if (consumed) {
3107
+ re += src;
3108
+ uflag = uflag || needUflag;
3109
+ i += consumed - 1;
3110
+ hasMagic = hasMagic || magic;
3111
+ } else {
3112
+ re += "\\[";
3113
+ }
3114
+ continue;
3115
+ case "]":
3116
+ re += "\\" + c;
3117
+ continue;
3118
+ default:
3119
+ clearStateChar();
3120
+ re += regExpEscape(c);
3121
+ break;
3122
+ }
3123
+ }
3124
+ for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
3125
+ let tail;
3126
+ tail = re.slice(pl.reStart + pl.open.length);
3127
+ this.debug(this.pattern, "setting tail", re, pl);
3128
+ tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, (_, $1, $2) => {
3129
+ if (!$2) {
3130
+ $2 = "\\";
3131
+ }
3132
+ return $1 + $1 + $2 + "|";
3133
+ });
3134
+ this.debug("tail=%j\n %s", tail, tail, pl, re);
3135
+ const t = pl.type === "*" ? star : pl.type === "?" ? qmark : "\\" + pl.type;
3136
+ hasMagic = true;
3137
+ re = re.slice(0, pl.reStart) + t + "\\(" + tail;
3138
+ }
3139
+ clearStateChar();
3140
+ if (escaping) {
3141
+ re += "\\\\";
3142
+ }
3143
+ const addPatternStart = addPatternStartSet[re.charAt(0)];
3144
+ for (let n = negativeLists.length - 1; n > -1; n--) {
3145
+ const nl = negativeLists[n];
3146
+ const nlBefore = re.slice(0, nl.reStart);
3147
+ const nlFirst = re.slice(nl.reStart, nl.reEnd - 8);
3148
+ let nlAfter = re.slice(nl.reEnd);
3149
+ const nlLast = re.slice(nl.reEnd - 8, nl.reEnd) + nlAfter;
3150
+ const closeParensBefore = nlBefore.split(")").length;
3151
+ const openParensBefore = nlBefore.split("(").length - closeParensBefore;
3152
+ let cleanAfter = nlAfter;
3153
+ for (let i = 0; i < openParensBefore; i++) {
3154
+ cleanAfter = cleanAfter.replace(/\)[+*?]?/, "");
3155
+ }
3156
+ nlAfter = cleanAfter;
3157
+ const dollar = nlAfter === "" ? "(?:$|\\/)" : "";
3158
+ re = nlBefore + nlFirst + nlAfter + dollar + nlLast;
3159
+ }
3160
+ if (re !== "" && hasMagic) {
3161
+ re = "(?=.)" + re;
3162
+ }
3163
+ if (addPatternStart) {
3164
+ re = patternStart() + re;
3165
+ }
3166
+ if (options.nocase && !hasMagic && !options.nocaseMagicOnly) {
3167
+ hasMagic = pattern.toUpperCase() !== pattern.toLowerCase();
3168
+ }
3169
+ if (!hasMagic) {
3170
+ return globUnescape(re);
3171
+ }
3172
+ const flags = (options.nocase ? "i" : "") + (uflag ? "u" : "");
3173
+ try {
3174
+ const ext2 = fastTest ? {
3175
+ _glob: pattern,
3176
+ _src: re,
3177
+ test: fastTest
3178
+ } : {
3179
+ _glob: pattern,
3180
+ _src: re
3181
+ };
3182
+ return Object.assign(new RegExp("^" + re + "$", flags), ext2);
3183
+ } catch (er) {
3184
+ this.debug("invalid regexp", er);
3185
+ return new RegExp("$.");
3186
+ }
3187
+ }
3188
+ makeRe() {
3189
+ if (this.regexp || this.regexp === false)
3190
+ return this.regexp;
3191
+ const set = this.set;
3192
+ if (!set.length) {
3193
+ this.regexp = false;
3194
+ return this.regexp;
3195
+ }
3196
+ const options = this.options;
3197
+ const twoStar = options.noglobstar ? star : options.dot ? twoStarDot : twoStarNoDot;
3198
+ const flags = options.nocase ? "i" : "";
3199
+ let re = set.map((pattern) => {
3200
+ const pp = pattern.map((p) => typeof p === "string" ? regExpEscape(p) : p === GLOBSTAR ? GLOBSTAR : p._src);
3201
+ pp.forEach((p, i) => {
3202
+ const next = pp[i + 1];
3203
+ const prev = pp[i - 1];
3204
+ if (p !== GLOBSTAR || prev === GLOBSTAR) {
3205
+ return;
3206
+ }
3207
+ if (prev === void 0) {
3208
+ if (next !== void 0 && next !== GLOBSTAR) {
3209
+ pp[i + 1] = "(?:\\/|" + twoStar + "\\/)?" + next;
3210
+ } else {
3211
+ pp[i] = twoStar;
3212
+ }
3213
+ } else if (next === void 0) {
3214
+ pp[i - 1] = prev + "(?:\\/|" + twoStar + ")?";
3215
+ } else if (next !== GLOBSTAR) {
3216
+ pp[i - 1] = prev + "(?:\\/|\\/" + twoStar + "\\/)" + next;
3217
+ pp[i + 1] = GLOBSTAR;
3218
+ }
3219
+ });
3220
+ return pp.filter((p) => p !== GLOBSTAR).join("/");
3221
+ }).join("|");
3222
+ re = "^(?:" + re + ")$";
3223
+ if (this.negate)
3224
+ re = "^(?!" + re + ").*$";
3225
+ try {
3226
+ this.regexp = new RegExp(re, flags);
3227
+ } catch (ex) {
3228
+ this.regexp = false;
3229
+ }
3230
+ return this.regexp;
3231
+ }
3232
+ slashSplit(p) {
3233
+ if (this.preserveMultipleSlashes) {
3234
+ return p.split("/");
3235
+ } else if (this.isWindows && /^\/\/[^\/]+/.test(p)) {
3236
+ return ["", ...p.split(/\/+/)];
3237
+ } else {
3238
+ return p.split(/\/+/);
3239
+ }
3240
+ }
3241
+ match(f, partial = this.partial) {
3242
+ this.debug("match", f, this.pattern);
3243
+ if (this.comment) {
3244
+ return false;
3245
+ }
3246
+ if (this.empty) {
3247
+ return f === "";
3248
+ }
3249
+ if (f === "/" && partial) {
3250
+ return true;
3251
+ }
3252
+ const options = this.options;
3253
+ if (this.isWindows) {
3254
+ f = f.split("\\").join("/");
3255
+ }
3256
+ const ff = this.slashSplit(f);
3257
+ this.debug(this.pattern, "split", ff);
3258
+ const set = this.set;
3259
+ this.debug(this.pattern, "set", set);
3260
+ let filename = ff[ff.length - 1];
3261
+ if (!filename) {
3262
+ for (let i = ff.length - 2; !filename && i >= 0; i--) {
3263
+ filename = ff[i];
3264
+ }
3265
+ }
3266
+ for (let i = 0; i < set.length; i++) {
3267
+ const pattern = set[i];
3268
+ let file = ff;
3269
+ if (options.matchBase && pattern.length === 1) {
3270
+ file = [filename];
3271
+ }
3272
+ const hit = this.matchOne(file, pattern, partial);
3273
+ if (hit) {
3274
+ if (options.flipNegate) {
3275
+ return true;
3276
+ }
3277
+ return !this.negate;
3278
+ }
3279
+ }
3280
+ if (options.flipNegate) {
3281
+ return false;
3282
+ }
3283
+ return this.negate;
3284
+ }
3285
+ static defaults(def) {
3286
+ return minimatch.defaults(def).Minimatch;
3287
+ }
3288
+ };
3289
+ minimatch.Minimatch = Minimatch;
3290
+ minimatch.escape = escape;
3291
+ minimatch.unescape = unescape;
3292
+
3293
+ // src/cli/commands/sqliteIntrospect.ts
3294
+ var import_hanji2 = __toESM(require_hanji());
3295
+ var sqlitePushIntrospect = async (client, filters) => {
3296
+ const matchers = filters.map((it) => {
3297
+ return new Minimatch(it);
3298
+ });
3299
+ const filter2 = (tableName) => {
3300
+ if (matchers.length === 0)
3301
+ return true;
3302
+ for (let i = 0; i < matchers.length; i++) {
3303
+ const matcher = matchers[i];
3304
+ if (matcher.match(tableName))
3305
+ return true;
3306
+ }
3307
+ return false;
3308
+ };
3309
+ const res = await fromDatabase2(client, filter2);
3310
+ const schema = { id: originUUID, prevId: "", ...res };
3311
+ return { schema };
3312
+ };
3313
+
3314
+ // src/cli/commands/pgIntrospect.ts
3315
+ var import_hanji3 = __toESM(require_hanji());
3316
+ init_views();
3317
+ init_pgSerializer();
3318
+
3319
+ // src/introspect.ts
3320
+ init_pgSerializer();
3321
+
3322
+ // src/cli/commands/pgIntrospect.ts
3323
+ var pgPushIntrospect = async (connection, filters, schemaFilters) => {
3324
+ const { client } = connection;
3325
+ const matchers = filters.map((it) => {
3326
+ return new Minimatch(it);
3327
+ });
3328
+ const filter2 = (tableName) => {
3329
+ if (matchers.length === 0)
3330
+ return true;
3331
+ for (let i = 0; i < matchers.length; i++) {
3332
+ const matcher = matchers[i];
3333
+ if (matcher.match(tableName))
3334
+ return true;
3335
+ }
3336
+ return false;
3337
+ };
3338
+ const res = await fromDatabase(client, filter2, schemaFilters);
3339
+ const schema = { id: originUUID, prevId: "", ...res };
3340
+ const { internal, ...schemaWithoutInternals } = schema;
3341
+ return { schema: schemaWithoutInternals };
3342
+ };
3343
+
3344
+ // src/utils-studio.ts
3345
+ init_drivers();
3346
+ // Annotate the CommonJS export names for ESM import in node:
3347
+ 0 && (module.exports = {
3348
+ DrizzleORMPgClient,
3349
+ drizzleSchemaPg,
3350
+ drizzleSchemaSQLite,
3351
+ pgPushIntrospect,
3352
+ sqlitePushIntrospect
3353
+ });