drizzle-kit 0.19.13 → 0.20.0-029419a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. package/@types/utils.d.ts +12 -0
  2. package/cli/commands/migrate.d.ts +260 -0
  3. package/cli/commands/mysqlUp.d.ts +4 -0
  4. package/cli/commands/pgConnect.d.ts +5 -0
  5. package/cli/commands/pgIntrospect.d.ts +115 -0
  6. package/cli/commands/pgPushUtils.d.ts +14 -0
  7. package/cli/commands/pgUp.d.ts +4 -0
  8. package/cli/commands/sqliteIntrospect.d.ts +102 -0
  9. package/cli/commands/sqliteUtils.d.ts +162 -0
  10. package/cli/commands/upFolders.d.ts +27 -0
  11. package/cli/commands/utils.d.ts +265 -0
  12. package/cli/selector-ui.d.ts +13 -0
  13. package/cli/validations/common.d.ts +13 -0
  14. package/cli/validations/mysql.d.ts +414 -0
  15. package/cli/validations/outputs.d.ts +40 -0
  16. package/cli/validations/pg.d.ts +438 -0
  17. package/cli/validations/sqlite.d.ts +220 -0
  18. package/cli/validations/studio.d.ts +548 -0
  19. package/cli/views.d.ts +61 -0
  20. package/drivers/index.d.ts +25 -0
  21. package/global.d.ts +2 -0
  22. package/index.cjs +39100 -31603
  23. package/index.d.ts +53 -0
  24. package/introspect.d.ts +4 -0
  25. package/jsonDiffer.d.ts +76 -0
  26. package/jsonStatements.d.ts +349 -0
  27. package/migrationPreparator.d.ts +35 -0
  28. package/orm-extenstions/d1-driver/driver.d.ts +8 -0
  29. package/orm-extenstions/d1-driver/session.d.ts +52 -0
  30. package/orm-extenstions/d1-driver/wrangler-client.d.ts +3 -0
  31. package/package.json +7 -4
  32. package/schemaValidator.d.ts +1306 -0
  33. package/serializer/index.d.ts +9 -0
  34. package/serializer/mysqlImports.d.ts +6 -0
  35. package/serializer/mysqlSchema.d.ts +3833 -0
  36. package/serializer/mysqlSerializer.d.ts +7 -0
  37. package/serializer/pgImports.d.ts +11 -0
  38. package/serializer/pgSchema.d.ts +4244 -0
  39. package/serializer/pgSerializer.d.ts +9 -0
  40. package/serializer/sqliteImports.d.ts +5 -0
  41. package/serializer/sqliteSchema.d.ts +3227 -0
  42. package/serializer/sqliteSerializer.d.ts +8 -0
  43. package/serializer/studioUtils.d.ts +35 -0
  44. package/snapshotsDiffer.d.ts +2660 -0
  45. package/sqlgenerator.d.ts +33 -0
  46. package/sqlite-introspect.d.ts +5 -0
  47. package/utils/words.d.ts +7 -0
  48. package/utils-studio.d.ts +2 -0
  49. package/utils-studio.js +3008 -0
  50. package/utils.d.ts +232 -0
  51. package/utils.js +51716 -11731
  52. package/loader.mjs +0 -57
@@ -0,0 +1,3008 @@
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, import_drizzle_orm2, 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
+ import_drizzle_orm2 = require("drizzle-orm");
570
+ init_serializer();
571
+ init_source();
572
+ init_outputs();
573
+ dialect = new import_pg_core.PgDialect();
574
+ trimChar = (str, char) => {
575
+ let start = 0;
576
+ let end = str.length;
577
+ while (start < end && str[start] === char)
578
+ ++start;
579
+ while (end > start && str[end - 1] === char)
580
+ --end;
581
+ return start > 0 || end < str.length ? str.substring(start, end) : str.toString();
582
+ };
583
+ fromDatabase = async (db, tablesFilter = (table) => true, schemaFilters, progressCallback) => {
584
+ const result = {};
585
+ const internals = { tables: {} };
586
+ const where = schemaFilters.map((t) => `table_schema = '${t}'`).join(" or ");
587
+ const allTables = await db.query(
588
+ `SELECT table_schema, table_name FROM information_schema.tables WHERE ${where};`
589
+ );
590
+ const schemas = new Set(allTables.map((it) => it.table_schema));
591
+ schemas.delete("public");
592
+ const allSchemas = await db.query(`select s.nspname as table_schema
593
+ from pg_catalog.pg_namespace s
594
+ join pg_catalog.pg_user u on u.usesysid = s.nspowner
595
+ where nspname not in ('information_schema', 'pg_catalog', 'public')
596
+ and nspname not like 'pg_toast%'
597
+ and nspname not like 'pg_temp_%'
598
+ order by table_schema;`);
599
+ allSchemas.forEach((item) => {
600
+ if (schemaFilters.includes(item.table_schema)) {
601
+ schemas.add(item.table_schema);
602
+ }
603
+ });
604
+ let columnsCount = 0;
605
+ let indexesCount = 0;
606
+ let foreignKeysCount = 0;
607
+ let tableCount = 0;
608
+ const all = allTables.map((row) => {
609
+ return new Promise(async (res, rej) => {
610
+ const tableName = row.table_name;
611
+ if (!tablesFilter(tableName))
612
+ return res("");
613
+ tableCount += 1;
614
+ const tableSchema = row.table_schema;
615
+ try {
616
+ const columnToReturn = {};
617
+ const indexToReturn = {};
618
+ const foreignKeysToReturn = {};
619
+ const primaryKeys = {};
620
+ const uniqueConstrains = {};
621
+ const tableResponse = await db.query(
622
+ `SELECT a.attrelid::regclass::text, a.attname, is_nullable, a.attndims as array_dimensions
623
+ , CASE WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[])
624
+ AND EXISTS (
625
+ SELECT FROM pg_attrdef ad
626
+ WHERE ad.adrelid = a.attrelid
627
+ AND ad.adnum = a.attnum
628
+ AND pg_get_expr(ad.adbin, ad.adrelid)
629
+ = 'nextval('''
630
+ || (pg_get_serial_sequence (a.attrelid::regclass::text
631
+ , a.attname))::regclass
632
+ || '''::regclass)'
633
+ )
634
+ THEN CASE a.atttypid
635
+ WHEN 'int'::regtype THEN 'serial'
636
+ WHEN 'int8'::regtype THEN 'bigserial'
637
+ WHEN 'int2'::regtype THEN 'smallserial'
638
+ END
639
+ ELSE format_type(a.atttypid, a.atttypmod)
640
+ 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
641
+ FROM pg_attribute a
642
+ JOIN INFORMATION_SCHEMA.COLUMNS ON INFORMATION_SCHEMA.COLUMNS.column_name = a.attname
643
+ WHERE a.attrelid = '"${tableSchema}"."${tableName}"'::regclass and INFORMATION_SCHEMA.COLUMNS.table_name = '${tableName}'
644
+ AND a.attnum > 0
645
+ AND NOT a.attisdropped
646
+ ORDER BY a.attnum;`
647
+ );
648
+ const tableConstraints = await db.query(
649
+ `SELECT c.column_name, c.data_type, constraint_type, constraint_name, constraint_schema
650
+ FROM information_schema.table_constraints tc
651
+ JOIN information_schema.constraint_column_usage AS ccu USING (constraint_schema, constraint_name)
652
+ JOIN information_schema.columns AS c ON c.table_schema = tc.constraint_schema
653
+ AND tc.table_name = c.table_name AND ccu.column_name = c.column_name
654
+ WHERE tc.table_name = '${tableName}' and constraint_schema = '${tableSchema}';`
655
+ );
656
+ columnsCount += tableResponse.length;
657
+ if (progressCallback) {
658
+ progressCallback("columns", columnsCount, "fetching");
659
+ }
660
+ const tableForeignKeys = await db.query(
661
+ `SELECT
662
+ tc.table_schema,
663
+ tc.constraint_name,
664
+ tc.table_name,
665
+ kcu.column_name,
666
+ ccu.table_schema AS foreign_table_schema,
667
+ ccu.table_name AS foreign_table_name,
668
+ ccu.column_name AS foreign_column_name,
669
+ rc.delete_rule, rc.update_rule
670
+ FROM
671
+ information_schema.table_constraints AS tc
672
+ JOIN information_schema.key_column_usage AS kcu
673
+ ON tc.constraint_name = kcu.constraint_name
674
+ AND tc.table_schema = kcu.table_schema
675
+ JOIN information_schema.constraint_column_usage AS ccu
676
+ ON ccu.constraint_name = tc.constraint_name
677
+ AND ccu.table_schema = tc.table_schema
678
+ JOIN information_schema.referential_constraints AS rc
679
+ ON ccu.constraint_name = rc.constraint_name
680
+ WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name='${tableName}' and tc.table_schema='${tableSchema}';`
681
+ );
682
+ foreignKeysCount += tableForeignKeys.length;
683
+ if (progressCallback) {
684
+ progressCallback("fks", foreignKeysCount, "fetching");
685
+ }
686
+ for (const fk of tableForeignKeys) {
687
+ const columnFrom = fk.column_name;
688
+ const tableTo = fk.foreign_table_name;
689
+ const columnTo = fk.foreign_column_name;
690
+ const foreignKeyName = fk.constraint_name;
691
+ const onUpdate = fk.update_rule.toLowerCase();
692
+ const onDelete = fk.delete_rule.toLowerCase();
693
+ if (typeof foreignKeysToReturn[foreignKeyName] !== "undefined") {
694
+ foreignKeysToReturn[foreignKeyName].columnsFrom.push(columnFrom);
695
+ foreignKeysToReturn[foreignKeyName].columnsTo.push(columnTo);
696
+ } else {
697
+ foreignKeysToReturn[foreignKeyName] = {
698
+ name: foreignKeyName,
699
+ tableFrom: tableName,
700
+ tableTo,
701
+ columnsFrom: [columnFrom],
702
+ columnsTo: [columnTo],
703
+ onDelete,
704
+ onUpdate
705
+ };
706
+ }
707
+ foreignKeysToReturn[foreignKeyName].columnsFrom = [
708
+ ...new Set(foreignKeysToReturn[foreignKeyName].columnsFrom)
709
+ ];
710
+ foreignKeysToReturn[foreignKeyName].columnsTo = [
711
+ ...new Set(foreignKeysToReturn[foreignKeyName].columnsTo)
712
+ ];
713
+ }
714
+ const uniqueConstrainsRows = tableConstraints.filter(
715
+ (mapRow) => mapRow.constraint_type === "UNIQUE"
716
+ );
717
+ for (const unqs of uniqueConstrainsRows) {
718
+ const columnName = unqs.column_name;
719
+ const constraintName = unqs.constraint_name;
720
+ if (typeof uniqueConstrains[constraintName] !== "undefined") {
721
+ uniqueConstrains[constraintName].columns.push(columnName);
722
+ } else {
723
+ uniqueConstrains[constraintName] = {
724
+ columns: [columnName],
725
+ nullsNotDistinct: false,
726
+ name: constraintName
727
+ };
728
+ }
729
+ }
730
+ for (const columnResponse of tableResponse) {
731
+ const columnName = columnResponse.attname;
732
+ const columnAdditionalDT = columnResponse.additional_dt;
733
+ const columnDimensions = columnResponse.array_dimensions;
734
+ let columnType = columnResponse.data_type;
735
+ const primaryKey = tableConstraints.filter(
736
+ (mapRow) => columnName === mapRow.column_name && mapRow.constraint_type === "PRIMARY KEY"
737
+ );
738
+ const cprimaryKey = tableConstraints.filter(
739
+ (mapRow) => mapRow.constraint_type === "PRIMARY KEY"
740
+ );
741
+ if (cprimaryKey.length > 1) {
742
+ const tableCompositePkName = await db.query(
743
+ `SELECT conname AS primary_key
744
+ FROM pg_constraint
745
+ WHERE contype = 'p'
746
+ AND connamespace = '${tableSchema}'::regnamespace
747
+ AND (conrelid::regclass::text = '"${tableName}"' OR conrelid::regclass::text = '${tableName}');`
748
+ );
749
+ primaryKeys[`${tableName}_${cprimaryKey.map((pk) => pk.column_name).join("_")}`] = {
750
+ name: tableCompositePkName[0].primary_key,
751
+ columns: cprimaryKey.map((c) => c.column_name)
752
+ };
753
+ }
754
+ const defaultValue = defaultForColumn(columnResponse);
755
+ const isSerial = columnType === "serial";
756
+ let columnTypeMapped = columnType;
757
+ if (columnTypeMapped.startsWith("numeric(")) {
758
+ columnTypeMapped = columnTypeMapped.replace(",", ", ");
759
+ }
760
+ if (columnAdditionalDT === "ARRAY") {
761
+ if (typeof internals.tables[tableName] === "undefined") {
762
+ internals.tables[tableName] = {
763
+ columns: {
764
+ [columnName]: {
765
+ isArray: true,
766
+ dimensions: columnDimensions,
767
+ rawType: columnTypeMapped.substring(
768
+ 0,
769
+ columnTypeMapped.length - 2
770
+ )
771
+ }
772
+ }
773
+ };
774
+ } else {
775
+ if (typeof internals.tables[tableName].columns[columnName] === "undefined") {
776
+ internals.tables[tableName].columns[columnName] = {
777
+ isArray: true,
778
+ dimensions: columnDimensions,
779
+ rawType: columnTypeMapped.substring(
780
+ 0,
781
+ columnTypeMapped.length - 2
782
+ )
783
+ };
784
+ }
785
+ }
786
+ }
787
+ if (columnAdditionalDT === "ARRAY") {
788
+ for (let i = 1; i < Number(columnDimensions); i++) {
789
+ columnTypeMapped += "[]";
790
+ }
791
+ }
792
+ columnTypeMapped = columnTypeMapped.replace("character varying", "varchar").replace(" without time zone", "").replace("character", "char");
793
+ columnTypeMapped = trimChar(columnTypeMapped, '"');
794
+ columnToReturn[columnName] = {
795
+ name: columnName,
796
+ type: columnTypeMapped,
797
+ primaryKey: primaryKey.length === 1 && cprimaryKey.length < 2,
798
+ // default: isSerial ? undefined : defaultValue,
799
+ notNull: columnResponse.is_nullable === "NO"
800
+ };
801
+ if (!isSerial && typeof defaultValue !== "undefined") {
802
+ columnToReturn[columnName].default = defaultValue;
803
+ }
804
+ }
805
+ const dbIndexes = await db.query(
806
+ `SELECT t.relname as table_name, i.relname AS index_name, ix.indisunique AS is_unique, a.attname AS column_name
807
+ FROM pg_class t
808
+ JOIN pg_index ix ON t.oid = ix.indrelid
809
+ JOIN pg_class i ON i.oid = ix.indexrelid
810
+ JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = ANY(ix.indkey)
811
+ JOIN pg_namespace ns ON ns.oid = t.relnamespace
812
+ WHERE ns.nspname = '${tableSchema}'
813
+ AND t.relname = '${tableName}'
814
+ and ix.indisprimary = false;`
815
+ );
816
+ const dbIndexFromConstraint = await db.query(
817
+ `SELECT
818
+ idx.indexrelname AS index_name,
819
+ idx.relname AS table_name,
820
+ schemaname,
821
+ CASE WHEN con.conname IS NOT NULL THEN 1 ELSE 0 END AS generated_by_constraint
822
+ FROM
823
+ pg_stat_user_indexes idx
824
+ LEFT JOIN
825
+ pg_constraint con ON con.conindid = idx.indexrelid
826
+ WHERE idx.relname = '${tableName}' and schemaname = '${tableSchema}'
827
+ group by index_name, table_name,schemaname, generated_by_constraint;`
828
+ );
829
+ const idxsInConsteraint = dbIndexFromConstraint.filter((it) => it.generated_by_constraint === 1).map((it) => it.index_name);
830
+ for (const dbIndex of dbIndexes) {
831
+ const indexName2 = dbIndex.index_name;
832
+ const indexColumnName = dbIndex.column_name;
833
+ const indexIsUnique = dbIndex.is_unique;
834
+ if (idxsInConsteraint.includes(indexName2))
835
+ continue;
836
+ if (typeof indexToReturn[indexName2] !== "undefined") {
837
+ indexToReturn[indexName2].columns.push(indexColumnName);
838
+ } else {
839
+ indexToReturn[indexName2] = {
840
+ name: indexName2,
841
+ columns: [indexColumnName],
842
+ isUnique: indexIsUnique
843
+ };
844
+ }
845
+ }
846
+ indexesCount += Object.keys(indexToReturn).length;
847
+ if (progressCallback) {
848
+ progressCallback("indexes", indexesCount, "fetching");
849
+ }
850
+ result[tableName] = {
851
+ name: tableName,
852
+ schema: tableSchema !== "public" ? tableSchema : "",
853
+ columns: columnToReturn,
854
+ indexes: indexToReturn,
855
+ foreignKeys: foreignKeysToReturn,
856
+ compositePrimaryKeys: primaryKeys,
857
+ uniqueConstraints: uniqueConstrains
858
+ };
859
+ } catch (e) {
860
+ rej(e);
861
+ return;
862
+ }
863
+ res("");
864
+ });
865
+ });
866
+ if (progressCallback) {
867
+ progressCallback("tables", tableCount, "done");
868
+ }
869
+ for await (const _ of all) {
870
+ }
871
+ if (progressCallback) {
872
+ progressCallback("columns", columnsCount, "done");
873
+ progressCallback("indexes", indexesCount, "done");
874
+ progressCallback("fks", foreignKeysCount, "done");
875
+ }
876
+ const allEnums = await db.query(
877
+ `select n.nspname as enum_schema,
878
+ t.typname as enum_name,
879
+ e.enumlabel as enum_value
880
+ from pg_type t
881
+ join pg_enum e on t.oid = e.enumtypid
882
+ join pg_catalog.pg_namespace n ON n.oid = t.typnamespace;`
883
+ );
884
+ const enumsToReturn = {};
885
+ for (const dbEnum of allEnums) {
886
+ const enumName = dbEnum.enum_name;
887
+ const enumValue = dbEnum.enum_value;
888
+ if (enumsToReturn[enumName] !== void 0 && enumsToReturn[enumName] !== null) {
889
+ enumsToReturn[enumName].values[enumValue] = enumValue;
890
+ } else {
891
+ enumsToReturn[enumName] = {
892
+ name: enumName,
893
+ values: { [enumValue]: enumValue }
894
+ };
895
+ }
896
+ }
897
+ if (progressCallback) {
898
+ progressCallback("enums", Object.keys(enumsToReturn).length, "done");
899
+ }
900
+ const schemasObject = Object.fromEntries([...schemas].map((it) => [it, it]));
901
+ return {
902
+ version: "5",
903
+ dialect: "pg",
904
+ tables: result,
905
+ enums: enumsToReturn,
906
+ schemas: schemasObject,
907
+ _meta: {
908
+ schemas: {},
909
+ tables: {},
910
+ columns: {}
911
+ },
912
+ internal: internals
913
+ };
914
+ };
915
+ columnToDefault = {
916
+ "numeric(": "::numeric",
917
+ // text: "::text",
918
+ // "character varying": "::character varying",
919
+ // "double precision": "::double precision",
920
+ // "time with time zone": "::time with time zone",
921
+ "time without time zone": "::time without time zone",
922
+ // "timestamp with time zone": "::timestamp with time zone",
923
+ "timestamp without time zone": "::timestamp without time zone",
924
+ // date: "::date",
925
+ // interval: "::interval",
926
+ // character: "::bpchar",
927
+ // macaddr8: "::macaddr8",
928
+ // macaddr: "::macaddr",
929
+ // inet: "::inet",
930
+ // cidr: "::cidr",
931
+ // jsonb: "::jsonb",
932
+ // json: "::json",
933
+ "character(": "::bpchar"
934
+ };
935
+ defaultForColumn = (column) => {
936
+ if (column.data_type === "serial" || column.data_type === "smallserial" || column.data_type === "bigserial") {
937
+ return void 0;
938
+ }
939
+ const hasDifferentDefaultCast = Object.keys(columnToDefault).find(
940
+ (it) => column.data_type.startsWith(it)
941
+ );
942
+ if (column.column_default === null) {
943
+ return void 0;
944
+ }
945
+ const columnDefaultAsString = column.column_default.toString();
946
+ if (columnDefaultAsString.endsWith(
947
+ hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : column.data_type
948
+ )) {
949
+ const nonPrefixPart = column.column_default.length - (hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column.data_type}`).length - 1;
950
+ const rt = column.column_default.toString().substring(1, nonPrefixPart);
951
+ if (/^-?[\d.]+(?:e-?\d+)?$/.test(rt) && !column.data_type.startsWith("numeric")) {
952
+ return Number(rt);
953
+ } else if (column.data_type === "json" || column.data_type === "jsonb") {
954
+ const jsonWithoutSpaces = JSON.stringify(JSON.parse(rt));
955
+ return `'${jsonWithoutSpaces}'${hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column.data_type}`}`;
956
+ } else if (column.data_type === "boolean") {
957
+ return column.column_default === "true";
958
+ } else {
959
+ return `'${rt}'`;
960
+ }
961
+ } else {
962
+ if (/^-?[\d.]+(?:e-?\d+)?$/.test(columnDefaultAsString) && !column.data_type.startsWith("numeric")) {
963
+ return Number(columnDefaultAsString);
964
+ } else if (column.data_type === "boolean") {
965
+ return column.column_default === "true";
966
+ } else {
967
+ return `${columnDefaultAsString}`;
968
+ }
969
+ }
970
+ };
971
+ toDrizzle = (schema) => {
972
+ const tables = {};
973
+ Object.values(schema.tables).forEach((t) => {
974
+ const columns = {};
975
+ Object.values(t.columns).forEach((c) => {
976
+ const columnName = c.name;
977
+ const type = c.type;
978
+ let columnBuilder;
979
+ if (type === "bigint") {
980
+ columnBuilder = new import_pg_core.PgBigInt53Builder(columnName);
981
+ } else if (type === "bigserial") {
982
+ columnBuilder = new import_pg_core.PgBigSerial53Builder(columnName);
983
+ } else if (type === "boolean") {
984
+ columnBuilder = new import_pg_core.PgBooleanBuilder(columnName);
985
+ } else if (type === "cidr") {
986
+ columnBuilder = new import_pg_core.PgCidrBuilder(columnName);
987
+ } else if (type === "date") {
988
+ columnBuilder = new import_pg_core.PgDateBuilder(columnName);
989
+ } else if (type === "double precision") {
990
+ columnBuilder = new import_pg_core.PgDoublePrecisionBuilder(columnName);
991
+ } else if (type === "inet") {
992
+ columnBuilder = new import_pg_core.PgInetBuilder(columnName);
993
+ } else if (type === "integer") {
994
+ columnBuilder = new import_pg_core.PgIntegerBuilder(columnName);
995
+ } else if (type === "interval" || type.startsWith("interval ")) {
996
+ columnBuilder = new import_pg_core.PgIntervalBuilder(columnName, {});
997
+ } else if (type === "json") {
998
+ columnBuilder = new import_pg_core.PgJsonBuilder(columnName);
999
+ } else if (type === "jsonb") {
1000
+ columnBuilder = new import_pg_core.PgJsonbBuilder(columnName);
1001
+ } else if (type === "macaddr") {
1002
+ columnBuilder = new import_pg_core.PgMacaddrBuilder(columnName);
1003
+ } else if (type === "macaddr8") {
1004
+ columnBuilder = new import_pg_core.PgMacaddr8Builder(columnName);
1005
+ } else if (type === "numeric" || type.startsWith("numeric(")) {
1006
+ columnBuilder = new import_pg_core.PgNumericBuilder(columnName);
1007
+ } else if (type === "real") {
1008
+ columnBuilder = new import_pg_core.PgRealBuilder(columnName);
1009
+ } else if (type === "serial") {
1010
+ columnBuilder = new import_pg_core.PgSerialBuilder(columnName);
1011
+ } else if (type === "smallint") {
1012
+ columnBuilder = new import_pg_core.PgSmallIntBuilder(columnName);
1013
+ } else if (type === "smallserial") {
1014
+ columnBuilder = new import_pg_core.PgSmallSerialBuilder(columnName);
1015
+ } else if (type === "text") {
1016
+ columnBuilder = new import_pg_core.PgTextBuilder(columnName, {});
1017
+ } else if (type === "time" || type.startsWith("time(") || type === "time with time zone") {
1018
+ columnBuilder = new import_pg_core.PgTimeBuilder(columnName, false, void 0);
1019
+ } else if (type === "timestamp" || type.startsWith("timestamp(") || type === "timestamp with time zone") {
1020
+ columnBuilder = new import_pg_core.PgTimestampBuilder(columnName, false, void 0);
1021
+ } else if (type === "uuid") {
1022
+ columnBuilder = new import_pg_core.PgUUIDBuilder(columnName);
1023
+ } else if (type === "varchar" || type.startsWith("varchar(")) {
1024
+ columnBuilder = new import_pg_core.PgVarcharBuilder(columnName, {});
1025
+ } else if (type === "char" || type.startsWith("char(")) {
1026
+ columnBuilder = new import_pg_core.PgCharBuilder(columnName, {});
1027
+ } else {
1028
+ columnBuilder = (0, import_pg_core.customType)({
1029
+ dataType() {
1030
+ return type;
1031
+ }
1032
+ })(columnName);
1033
+ }
1034
+ if (c.notNull) {
1035
+ columnBuilder = columnBuilder.notNull();
1036
+ }
1037
+ if (c.default) {
1038
+ columnBuilder = columnBuilder.default(c.default);
1039
+ }
1040
+ if (c.primaryKey) {
1041
+ columnBuilder = columnBuilder.primaryKey();
1042
+ }
1043
+ columns[columnName] = columnBuilder;
1044
+ });
1045
+ tables[t.name] = (0, import_pg_core.pgTable)(t.name, columns, (cb) => {
1046
+ const res = {};
1047
+ Object.values(t.compositePrimaryKeys).forEach((cpk) => {
1048
+ const gh = cpk.columns.map((c) => cb[c]);
1049
+ res[cpk.name] = new import_pg_core.PrimaryKeyBuilder(
1050
+ gh,
1051
+ cpk.name
1052
+ );
1053
+ });
1054
+ return res;
1055
+ });
1056
+ });
1057
+ return tables;
1058
+ };
1059
+ }
1060
+ });
1061
+
1062
+ // node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/readline.js
1063
+ var require_readline = __commonJS({
1064
+ "node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/readline.js"(exports) {
1065
+ "use strict";
1066
+ Object.defineProperty(exports, "__esModule", { value: true });
1067
+ exports.prepareReadLine = void 0;
1068
+ var prepareReadLine = () => {
1069
+ const stdin = process.stdin;
1070
+ const stdout = process.stdout;
1071
+ const readline = require("readline");
1072
+ const rl = readline.createInterface({
1073
+ input: stdin,
1074
+ escapeCodeTimeout: 50
1075
+ });
1076
+ readline.emitKeypressEvents(stdin, rl);
1077
+ return {
1078
+ stdin,
1079
+ stdout,
1080
+ closable: rl
1081
+ };
1082
+ };
1083
+ exports.prepareReadLine = prepareReadLine;
1084
+ }
1085
+ });
1086
+
1087
+ // node_modules/.pnpm/sisteransi@1.0.5/node_modules/sisteransi/src/index.js
1088
+ var require_src = __commonJS({
1089
+ "node_modules/.pnpm/sisteransi@1.0.5/node_modules/sisteransi/src/index.js"(exports, module2) {
1090
+ "use strict";
1091
+ var ESC = "\x1B";
1092
+ var CSI = `${ESC}[`;
1093
+ var beep = "\x07";
1094
+ var cursor = {
1095
+ to(x, y) {
1096
+ if (!y)
1097
+ return `${CSI}${x + 1}G`;
1098
+ return `${CSI}${y + 1};${x + 1}H`;
1099
+ },
1100
+ move(x, y) {
1101
+ let ret = "";
1102
+ if (x < 0)
1103
+ ret += `${CSI}${-x}D`;
1104
+ else if (x > 0)
1105
+ ret += `${CSI}${x}C`;
1106
+ if (y < 0)
1107
+ ret += `${CSI}${-y}A`;
1108
+ else if (y > 0)
1109
+ ret += `${CSI}${y}B`;
1110
+ return ret;
1111
+ },
1112
+ up: (count = 1) => `${CSI}${count}A`,
1113
+ down: (count = 1) => `${CSI}${count}B`,
1114
+ forward: (count = 1) => `${CSI}${count}C`,
1115
+ backward: (count = 1) => `${CSI}${count}D`,
1116
+ nextLine: (count = 1) => `${CSI}E`.repeat(count),
1117
+ prevLine: (count = 1) => `${CSI}F`.repeat(count),
1118
+ left: `${CSI}G`,
1119
+ hide: `${CSI}?25l`,
1120
+ show: `${CSI}?25h`,
1121
+ save: `${ESC}7`,
1122
+ restore: `${ESC}8`
1123
+ };
1124
+ var scroll = {
1125
+ up: (count = 1) => `${CSI}S`.repeat(count),
1126
+ down: (count = 1) => `${CSI}T`.repeat(count)
1127
+ };
1128
+ var erase = {
1129
+ screen: `${CSI}2J`,
1130
+ up: (count = 1) => `${CSI}1J`.repeat(count),
1131
+ down: (count = 1) => `${CSI}J`.repeat(count),
1132
+ line: `${CSI}2K`,
1133
+ lineEnd: `${CSI}K`,
1134
+ lineStart: `${CSI}1K`,
1135
+ lines(count) {
1136
+ let clear = "";
1137
+ for (let i = 0; i < count; i++)
1138
+ clear += this.line + (i < count - 1 ? cursor.up() : "");
1139
+ if (count)
1140
+ clear += cursor.left;
1141
+ return clear;
1142
+ }
1143
+ };
1144
+ module2.exports = { cursor, scroll, erase, beep };
1145
+ }
1146
+ });
1147
+
1148
+ // node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/utils.js
1149
+ var require_utils = __commonJS({
1150
+ "node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/utils.js"(exports) {
1151
+ "use strict";
1152
+ Object.defineProperty(exports, "__esModule", { value: true });
1153
+ exports.clear = void 0;
1154
+ var sisteransi_1 = require_src();
1155
+ var strip = (str) => {
1156
+ const pattern = [
1157
+ "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
1158
+ "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
1159
+ ].join("|");
1160
+ const RGX = new RegExp(pattern, "g");
1161
+ return typeof str === "string" ? str.replace(RGX, "") : str;
1162
+ };
1163
+ var stringWidth = (str) => [...strip(str)].length;
1164
+ var clear = function(prompt, perLine) {
1165
+ if (!perLine)
1166
+ return sisteransi_1.erase.line + sisteransi_1.cursor.to(0);
1167
+ let rows = 0;
1168
+ const lines = prompt.split(/\r?\n/);
1169
+ for (let line of lines) {
1170
+ rows += 1 + Math.floor(Math.max(stringWidth(line) - 1, 0) / perLine);
1171
+ }
1172
+ return sisteransi_1.erase.lines(rows);
1173
+ };
1174
+ exports.clear = clear;
1175
+ }
1176
+ });
1177
+
1178
+ // node_modules/.pnpm/lodash.throttle@4.1.1/node_modules/lodash.throttle/index.js
1179
+ var require_lodash = __commonJS({
1180
+ "node_modules/.pnpm/lodash.throttle@4.1.1/node_modules/lodash.throttle/index.js"(exports, module2) {
1181
+ var FUNC_ERROR_TEXT = "Expected a function";
1182
+ var NAN = 0 / 0;
1183
+ var symbolTag = "[object Symbol]";
1184
+ var reTrim = /^\s+|\s+$/g;
1185
+ var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
1186
+ var reIsBinary = /^0b[01]+$/i;
1187
+ var reIsOctal = /^0o[0-7]+$/i;
1188
+ var freeParseInt = parseInt;
1189
+ var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
1190
+ var freeSelf = typeof self == "object" && self && self.Object === Object && self;
1191
+ var root = freeGlobal || freeSelf || Function("return this")();
1192
+ var objectProto = Object.prototype;
1193
+ var objectToString = objectProto.toString;
1194
+ var nativeMax = Math.max;
1195
+ var nativeMin = Math.min;
1196
+ var now = function() {
1197
+ return root.Date.now();
1198
+ };
1199
+ function debounce(func, wait, options) {
1200
+ var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
1201
+ if (typeof func != "function") {
1202
+ throw new TypeError(FUNC_ERROR_TEXT);
1203
+ }
1204
+ wait = toNumber(wait) || 0;
1205
+ if (isObject(options)) {
1206
+ leading = !!options.leading;
1207
+ maxing = "maxWait" in options;
1208
+ maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
1209
+ trailing = "trailing" in options ? !!options.trailing : trailing;
1210
+ }
1211
+ function invokeFunc(time) {
1212
+ var args = lastArgs, thisArg = lastThis;
1213
+ lastArgs = lastThis = void 0;
1214
+ lastInvokeTime = time;
1215
+ result = func.apply(thisArg, args);
1216
+ return result;
1217
+ }
1218
+ function leadingEdge(time) {
1219
+ lastInvokeTime = time;
1220
+ timerId = setTimeout(timerExpired, wait);
1221
+ return leading ? invokeFunc(time) : result;
1222
+ }
1223
+ function remainingWait(time) {
1224
+ var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime, result2 = wait - timeSinceLastCall;
1225
+ return maxing ? nativeMin(result2, maxWait - timeSinceLastInvoke) : result2;
1226
+ }
1227
+ function shouldInvoke(time) {
1228
+ var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime;
1229
+ return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
1230
+ }
1231
+ function timerExpired() {
1232
+ var time = now();
1233
+ if (shouldInvoke(time)) {
1234
+ return trailingEdge(time);
1235
+ }
1236
+ timerId = setTimeout(timerExpired, remainingWait(time));
1237
+ }
1238
+ function trailingEdge(time) {
1239
+ timerId = void 0;
1240
+ if (trailing && lastArgs) {
1241
+ return invokeFunc(time);
1242
+ }
1243
+ lastArgs = lastThis = void 0;
1244
+ return result;
1245
+ }
1246
+ function cancel() {
1247
+ if (timerId !== void 0) {
1248
+ clearTimeout(timerId);
1249
+ }
1250
+ lastInvokeTime = 0;
1251
+ lastArgs = lastCallTime = lastThis = timerId = void 0;
1252
+ }
1253
+ function flush() {
1254
+ return timerId === void 0 ? result : trailingEdge(now());
1255
+ }
1256
+ function debounced() {
1257
+ var time = now(), isInvoking = shouldInvoke(time);
1258
+ lastArgs = arguments;
1259
+ lastThis = this;
1260
+ lastCallTime = time;
1261
+ if (isInvoking) {
1262
+ if (timerId === void 0) {
1263
+ return leadingEdge(lastCallTime);
1264
+ }
1265
+ if (maxing) {
1266
+ timerId = setTimeout(timerExpired, wait);
1267
+ return invokeFunc(lastCallTime);
1268
+ }
1269
+ }
1270
+ if (timerId === void 0) {
1271
+ timerId = setTimeout(timerExpired, wait);
1272
+ }
1273
+ return result;
1274
+ }
1275
+ debounced.cancel = cancel;
1276
+ debounced.flush = flush;
1277
+ return debounced;
1278
+ }
1279
+ function throttle(func, wait, options) {
1280
+ var leading = true, trailing = true;
1281
+ if (typeof func != "function") {
1282
+ throw new TypeError(FUNC_ERROR_TEXT);
1283
+ }
1284
+ if (isObject(options)) {
1285
+ leading = "leading" in options ? !!options.leading : leading;
1286
+ trailing = "trailing" in options ? !!options.trailing : trailing;
1287
+ }
1288
+ return debounce(func, wait, {
1289
+ "leading": leading,
1290
+ "maxWait": wait,
1291
+ "trailing": trailing
1292
+ });
1293
+ }
1294
+ function isObject(value) {
1295
+ var type = typeof value;
1296
+ return !!value && (type == "object" || type == "function");
1297
+ }
1298
+ function isObjectLike(value) {
1299
+ return !!value && typeof value == "object";
1300
+ }
1301
+ function isSymbol(value) {
1302
+ return typeof value == "symbol" || isObjectLike(value) && objectToString.call(value) == symbolTag;
1303
+ }
1304
+ function toNumber(value) {
1305
+ if (typeof value == "number") {
1306
+ return value;
1307
+ }
1308
+ if (isSymbol(value)) {
1309
+ return NAN;
1310
+ }
1311
+ if (isObject(value)) {
1312
+ var other = typeof value.valueOf == "function" ? value.valueOf() : value;
1313
+ value = isObject(other) ? other + "" : other;
1314
+ }
1315
+ if (typeof value != "string") {
1316
+ return value === 0 ? value : +value;
1317
+ }
1318
+ value = value.replace(reTrim, "");
1319
+ var isBinary = reIsBinary.test(value);
1320
+ return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
1321
+ }
1322
+ module2.exports = throttle;
1323
+ }
1324
+ });
1325
+
1326
+ // node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/index.js
1327
+ var require_hanji = __commonJS({
1328
+ "node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/index.js"(exports) {
1329
+ "use strict";
1330
+ var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
1331
+ function adopt(value) {
1332
+ return value instanceof P ? value : new P(function(resolve) {
1333
+ resolve(value);
1334
+ });
1335
+ }
1336
+ return new (P || (P = Promise))(function(resolve, reject) {
1337
+ function fulfilled(value) {
1338
+ try {
1339
+ step(generator.next(value));
1340
+ } catch (e) {
1341
+ reject(e);
1342
+ }
1343
+ }
1344
+ function rejected(value) {
1345
+ try {
1346
+ step(generator["throw"](value));
1347
+ } catch (e) {
1348
+ reject(e);
1349
+ }
1350
+ }
1351
+ function step(result) {
1352
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
1353
+ }
1354
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1355
+ });
1356
+ };
1357
+ var __importDefault = exports && exports.__importDefault || function(mod) {
1358
+ return mod && mod.__esModule ? mod : { "default": mod };
1359
+ };
1360
+ Object.defineProperty(exports, "__esModule", { value: true });
1361
+ exports.onTerminate = exports.renderWithTask = exports.render = exports.TaskTerminal = exports.TaskView = exports.Terminal = exports.deferred = exports.SelectState = exports.Prompt = void 0;
1362
+ var readline_1 = require_readline();
1363
+ var sisteransi_1 = require_src();
1364
+ var utils_1 = require_utils();
1365
+ var lodash_throttle_1 = __importDefault(require_lodash());
1366
+ var Prompt2 = class {
1367
+ constructor() {
1368
+ this.attachCallbacks = [];
1369
+ this.detachCallbacks = [];
1370
+ this.inputCallbacks = [];
1371
+ }
1372
+ requestLayout() {
1373
+ this.terminal.requestLayout();
1374
+ }
1375
+ on(type, callback) {
1376
+ if (type === "attach") {
1377
+ this.attachCallbacks.push(callback);
1378
+ } else if (type === "detach") {
1379
+ this.detachCallbacks.push(callback);
1380
+ } else if (type === "input") {
1381
+ this.inputCallbacks.push(callback);
1382
+ }
1383
+ }
1384
+ attach(terminal) {
1385
+ this.terminal = terminal;
1386
+ this.attachCallbacks.forEach((it) => it(terminal));
1387
+ }
1388
+ detach(terminal) {
1389
+ this.detachCallbacks.forEach((it) => it(terminal));
1390
+ this.terminal = void 0;
1391
+ }
1392
+ input(str, key) {
1393
+ this.inputCallbacks.forEach((it) => it(str, key));
1394
+ }
1395
+ };
1396
+ exports.Prompt = Prompt2;
1397
+ var SelectState2 = class {
1398
+ constructor(items) {
1399
+ this.items = items;
1400
+ this.selectedIdx = 0;
1401
+ }
1402
+ bind(prompt) {
1403
+ prompt.on("input", (str, key) => {
1404
+ const invalidate = this.consume(str, key);
1405
+ if (invalidate)
1406
+ prompt.requestLayout();
1407
+ });
1408
+ }
1409
+ consume(str, key) {
1410
+ if (!key)
1411
+ return false;
1412
+ if (key.name === "down") {
1413
+ this.selectedIdx = (this.selectedIdx + 1) % this.items.length;
1414
+ return true;
1415
+ }
1416
+ if (key.name === "up") {
1417
+ this.selectedIdx -= 1;
1418
+ this.selectedIdx = this.selectedIdx < 0 ? this.items.length - 1 : this.selectedIdx;
1419
+ return true;
1420
+ }
1421
+ return false;
1422
+ }
1423
+ };
1424
+ exports.SelectState = SelectState2;
1425
+ var deferred = () => {
1426
+ let resolve;
1427
+ let reject;
1428
+ const promise = new Promise((res, rej) => {
1429
+ resolve = res;
1430
+ reject = rej;
1431
+ });
1432
+ return {
1433
+ resolve,
1434
+ reject,
1435
+ promise
1436
+ };
1437
+ };
1438
+ exports.deferred = deferred;
1439
+ var Terminal = class {
1440
+ constructor(view, stdin, stdout, closable) {
1441
+ this.view = view;
1442
+ this.stdin = stdin;
1443
+ this.stdout = stdout;
1444
+ this.closable = closable;
1445
+ this.text = "";
1446
+ this.status = "idle";
1447
+ if (this.stdin.isTTY)
1448
+ this.stdin.setRawMode(true);
1449
+ const keypress = (str, key) => {
1450
+ if (key.name === "c" && key.ctrl === true) {
1451
+ this.requestLayout();
1452
+ this.view.detach(this);
1453
+ this.tearDown(keypress);
1454
+ if (terminateHandler) {
1455
+ terminateHandler(this.stdin, this.stdout);
1456
+ return;
1457
+ }
1458
+ this.stdout.write(`
1459
+ ^C
1460
+ `);
1461
+ process.exit(1);
1462
+ }
1463
+ if (key.name === "escape") {
1464
+ this.status = "aborted";
1465
+ this.requestLayout();
1466
+ this.view.detach(this);
1467
+ this.tearDown(keypress);
1468
+ this.resolve({ status: "aborted", data: void 0 });
1469
+ return;
1470
+ }
1471
+ if (key.name === "return") {
1472
+ this.status = "submitted";
1473
+ this.requestLayout();
1474
+ this.view.detach(this);
1475
+ this.tearDown(keypress);
1476
+ this.resolve({ status: "submitted", data: this.view.result() });
1477
+ return;
1478
+ }
1479
+ view.input(str, key);
1480
+ };
1481
+ this.stdin.on("keypress", keypress);
1482
+ this.view.attach(this);
1483
+ const { resolve, promise } = (0, exports.deferred)();
1484
+ this.resolve = resolve;
1485
+ this.promise = promise;
1486
+ this.renderFunc = (0, lodash_throttle_1.default)((str) => {
1487
+ this.stdout.write(str);
1488
+ });
1489
+ }
1490
+ tearDown(keypress) {
1491
+ this.stdout.write(sisteransi_1.cursor.show);
1492
+ this.stdin.removeListener("keypress", keypress);
1493
+ if (this.stdin.isTTY)
1494
+ this.stdin.setRawMode(false);
1495
+ this.closable.close();
1496
+ }
1497
+ result() {
1498
+ return this.promise;
1499
+ }
1500
+ toggleCursor(state) {
1501
+ if (state === "hide") {
1502
+ this.stdout.write(sisteransi_1.cursor.hide);
1503
+ } else {
1504
+ this.stdout.write(sisteransi_1.cursor.show);
1505
+ }
1506
+ }
1507
+ requestLayout() {
1508
+ const string = this.view.render(this.status);
1509
+ const clearPrefix = this.text ? (0, utils_1.clear)(this.text, this.stdout.columns) : "";
1510
+ this.text = string;
1511
+ this.renderFunc(`${clearPrefix}${string}`);
1512
+ }
1513
+ };
1514
+ exports.Terminal = Terminal;
1515
+ var TaskView2 = class {
1516
+ constructor() {
1517
+ this.attachCallbacks = [];
1518
+ this.detachCallbacks = [];
1519
+ }
1520
+ requestLayout() {
1521
+ this.terminal.requestLayout();
1522
+ }
1523
+ attach(terminal) {
1524
+ this.terminal = terminal;
1525
+ this.attachCallbacks.forEach((it) => it(terminal));
1526
+ }
1527
+ detach(terminal) {
1528
+ this.detachCallbacks.forEach((it) => it(terminal));
1529
+ this.terminal = void 0;
1530
+ }
1531
+ on(type, callback) {
1532
+ if (type === "attach") {
1533
+ this.attachCallbacks.push(callback);
1534
+ } else if (type === "detach") {
1535
+ this.detachCallbacks.push(callback);
1536
+ }
1537
+ }
1538
+ };
1539
+ exports.TaskView = TaskView2;
1540
+ var TaskTerminal = class {
1541
+ constructor(view, stdout) {
1542
+ this.view = view;
1543
+ this.stdout = stdout;
1544
+ this.text = "";
1545
+ this.view.attach(this);
1546
+ }
1547
+ requestLayout() {
1548
+ const string = this.view.render("pending");
1549
+ const clearPrefix = this.text ? (0, utils_1.clear)(this.text, this.stdout.columns) : "";
1550
+ this.text = string;
1551
+ this.stdout.write(`${clearPrefix}${string}`);
1552
+ }
1553
+ clear() {
1554
+ const string = this.view.render("done");
1555
+ this.view.detach(this);
1556
+ const clearPrefix = this.text ? (0, utils_1.clear)(this.text, this.stdout.columns) : "";
1557
+ this.stdout.write(`${clearPrefix}${string}`);
1558
+ }
1559
+ };
1560
+ exports.TaskTerminal = TaskTerminal;
1561
+ function render2(view) {
1562
+ const { stdin, stdout, closable } = (0, readline_1.prepareReadLine)();
1563
+ if (view instanceof Prompt2) {
1564
+ const terminal = new Terminal(view, stdin, stdout, closable);
1565
+ terminal.requestLayout();
1566
+ return terminal.result();
1567
+ }
1568
+ stdout.write(`${view}
1569
+ `);
1570
+ closable.close();
1571
+ return;
1572
+ }
1573
+ exports.render = render2;
1574
+ function renderWithTask2(view, task) {
1575
+ return __awaiter(this, void 0, void 0, function* () {
1576
+ const terminal = new TaskTerminal(view, process.stdout);
1577
+ terminal.requestLayout();
1578
+ const result = yield task;
1579
+ terminal.clear();
1580
+ return result;
1581
+ });
1582
+ }
1583
+ exports.renderWithTask = renderWithTask2;
1584
+ var terminateHandler;
1585
+ function onTerminate(callback) {
1586
+ terminateHandler = callback;
1587
+ }
1588
+ exports.onTerminate = onTerminate;
1589
+ }
1590
+ });
1591
+
1592
+ // src/cli/views.ts
1593
+ var import_hanji;
1594
+ var init_views = __esm({
1595
+ "src/cli/views.ts"() {
1596
+ init_source();
1597
+ import_hanji = __toESM(require_hanji());
1598
+ }
1599
+ });
1600
+
1601
+ // node_modules/.pnpm/balanced-match@1.0.2/node_modules/balanced-match/index.js
1602
+ var require_balanced_match = __commonJS({
1603
+ "node_modules/.pnpm/balanced-match@1.0.2/node_modules/balanced-match/index.js"(exports, module2) {
1604
+ "use strict";
1605
+ module2.exports = balanced;
1606
+ function balanced(a, b, str) {
1607
+ if (a instanceof RegExp)
1608
+ a = maybeMatch(a, str);
1609
+ if (b instanceof RegExp)
1610
+ b = maybeMatch(b, str);
1611
+ var r = range(a, b, str);
1612
+ return r && {
1613
+ start: r[0],
1614
+ end: r[1],
1615
+ pre: str.slice(0, r[0]),
1616
+ body: str.slice(r[0] + a.length, r[1]),
1617
+ post: str.slice(r[1] + b.length)
1618
+ };
1619
+ }
1620
+ function maybeMatch(reg, str) {
1621
+ var m = str.match(reg);
1622
+ return m ? m[0] : null;
1623
+ }
1624
+ balanced.range = range;
1625
+ function range(a, b, str) {
1626
+ var begs, beg, left, right, result;
1627
+ var ai = str.indexOf(a);
1628
+ var bi = str.indexOf(b, ai + 1);
1629
+ var i = ai;
1630
+ if (ai >= 0 && bi > 0) {
1631
+ if (a === b) {
1632
+ return [ai, bi];
1633
+ }
1634
+ begs = [];
1635
+ left = str.length;
1636
+ while (i >= 0 && !result) {
1637
+ if (i == ai) {
1638
+ begs.push(i);
1639
+ ai = str.indexOf(a, i + 1);
1640
+ } else if (begs.length == 1) {
1641
+ result = [begs.pop(), bi];
1642
+ } else {
1643
+ beg = begs.pop();
1644
+ if (beg < left) {
1645
+ left = beg;
1646
+ right = bi;
1647
+ }
1648
+ bi = str.indexOf(b, i + 1);
1649
+ }
1650
+ i = ai < bi && ai >= 0 ? ai : bi;
1651
+ }
1652
+ if (begs.length) {
1653
+ result = [left, right];
1654
+ }
1655
+ }
1656
+ return result;
1657
+ }
1658
+ }
1659
+ });
1660
+
1661
+ // node_modules/.pnpm/brace-expansion@2.0.1/node_modules/brace-expansion/index.js
1662
+ var require_brace_expansion = __commonJS({
1663
+ "node_modules/.pnpm/brace-expansion@2.0.1/node_modules/brace-expansion/index.js"(exports, module2) {
1664
+ var balanced = require_balanced_match();
1665
+ module2.exports = expandTop;
1666
+ var escSlash = "\0SLASH" + Math.random() + "\0";
1667
+ var escOpen = "\0OPEN" + Math.random() + "\0";
1668
+ var escClose = "\0CLOSE" + Math.random() + "\0";
1669
+ var escComma = "\0COMMA" + Math.random() + "\0";
1670
+ var escPeriod = "\0PERIOD" + Math.random() + "\0";
1671
+ function numeric(str) {
1672
+ return parseInt(str, 10) == str ? parseInt(str, 10) : str.charCodeAt(0);
1673
+ }
1674
+ function escapeBraces(str) {
1675
+ return str.split("\\\\").join(escSlash).split("\\{").join(escOpen).split("\\}").join(escClose).split("\\,").join(escComma).split("\\.").join(escPeriod);
1676
+ }
1677
+ function unescapeBraces(str) {
1678
+ return str.split(escSlash).join("\\").split(escOpen).join("{").split(escClose).join("}").split(escComma).join(",").split(escPeriod).join(".");
1679
+ }
1680
+ function parseCommaParts(str) {
1681
+ if (!str)
1682
+ return [""];
1683
+ var parts = [];
1684
+ var m = balanced("{", "}", str);
1685
+ if (!m)
1686
+ return str.split(",");
1687
+ var pre = m.pre;
1688
+ var body = m.body;
1689
+ var post = m.post;
1690
+ var p = pre.split(",");
1691
+ p[p.length - 1] += "{" + body + "}";
1692
+ var postParts = parseCommaParts(post);
1693
+ if (post.length) {
1694
+ p[p.length - 1] += postParts.shift();
1695
+ p.push.apply(p, postParts);
1696
+ }
1697
+ parts.push.apply(parts, p);
1698
+ return parts;
1699
+ }
1700
+ function expandTop(str) {
1701
+ if (!str)
1702
+ return [];
1703
+ if (str.substr(0, 2) === "{}") {
1704
+ str = "\\{\\}" + str.substr(2);
1705
+ }
1706
+ return expand2(escapeBraces(str), true).map(unescapeBraces);
1707
+ }
1708
+ function embrace(str) {
1709
+ return "{" + str + "}";
1710
+ }
1711
+ function isPadded(el) {
1712
+ return /^-?0\d/.test(el);
1713
+ }
1714
+ function lte(i, y) {
1715
+ return i <= y;
1716
+ }
1717
+ function gte(i, y) {
1718
+ return i >= y;
1719
+ }
1720
+ function expand2(str, isTop) {
1721
+ var expansions = [];
1722
+ var m = balanced("{", "}", str);
1723
+ if (!m)
1724
+ return [str];
1725
+ var pre = m.pre;
1726
+ var post = m.post.length ? expand2(m.post, false) : [""];
1727
+ if (/\$$/.test(m.pre)) {
1728
+ for (var k = 0; k < post.length; k++) {
1729
+ var expansion = pre + "{" + m.body + "}" + post[k];
1730
+ expansions.push(expansion);
1731
+ }
1732
+ } else {
1733
+ var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
1734
+ var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
1735
+ var isSequence = isNumericSequence || isAlphaSequence;
1736
+ var isOptions = m.body.indexOf(",") >= 0;
1737
+ if (!isSequence && !isOptions) {
1738
+ if (m.post.match(/,.*\}/)) {
1739
+ str = m.pre + "{" + m.body + escClose + m.post;
1740
+ return expand2(str);
1741
+ }
1742
+ return [str];
1743
+ }
1744
+ var n;
1745
+ if (isSequence) {
1746
+ n = m.body.split(/\.\./);
1747
+ } else {
1748
+ n = parseCommaParts(m.body);
1749
+ if (n.length === 1) {
1750
+ n = expand2(n[0], false).map(embrace);
1751
+ if (n.length === 1) {
1752
+ return post.map(function(p) {
1753
+ return m.pre + n[0] + p;
1754
+ });
1755
+ }
1756
+ }
1757
+ }
1758
+ var N;
1759
+ if (isSequence) {
1760
+ var x = numeric(n[0]);
1761
+ var y = numeric(n[1]);
1762
+ var width = Math.max(n[0].length, n[1].length);
1763
+ var incr = n.length == 3 ? Math.abs(numeric(n[2])) : 1;
1764
+ var test = lte;
1765
+ var reverse = y < x;
1766
+ if (reverse) {
1767
+ incr *= -1;
1768
+ test = gte;
1769
+ }
1770
+ var pad = n.some(isPadded);
1771
+ N = [];
1772
+ for (var i = x; test(i, y); i += incr) {
1773
+ var c;
1774
+ if (isAlphaSequence) {
1775
+ c = String.fromCharCode(i);
1776
+ if (c === "\\")
1777
+ c = "";
1778
+ } else {
1779
+ c = String(i);
1780
+ if (pad) {
1781
+ var need = width - c.length;
1782
+ if (need > 0) {
1783
+ var z = new Array(need + 1).join("0");
1784
+ if (i < 0)
1785
+ c = "-" + z + c.slice(1);
1786
+ else
1787
+ c = z + c;
1788
+ }
1789
+ }
1790
+ }
1791
+ N.push(c);
1792
+ }
1793
+ } else {
1794
+ N = [];
1795
+ for (var j = 0; j < n.length; j++) {
1796
+ N.push.apply(N, expand2(n[j], false));
1797
+ }
1798
+ }
1799
+ for (var j = 0; j < N.length; j++) {
1800
+ for (var k = 0; k < post.length; k++) {
1801
+ var expansion = pre + N[j] + post[k];
1802
+ if (!isTop || isSequence || expansion)
1803
+ expansions.push(expansion);
1804
+ }
1805
+ }
1806
+ }
1807
+ return expansions;
1808
+ }
1809
+ }
1810
+ });
1811
+
1812
+ // src/utils-studio.ts
1813
+ var utils_studio_exports = {};
1814
+ __export(utils_studio_exports, {
1815
+ drizzleSchemaPg: () => toDrizzle,
1816
+ pgPushIntrospect: () => pgPushIntrospect
1817
+ });
1818
+ module.exports = __toCommonJS(utils_studio_exports);
1819
+ init_pgSerializer();
1820
+
1821
+ // src/cli/commands/pgIntrospect.ts
1822
+ var import_hanji2 = __toESM(require_hanji());
1823
+ init_views();
1824
+ init_pgSerializer();
1825
+
1826
+ // node_modules/.pnpm/camelcase@7.0.1/node_modules/camelcase/index.js
1827
+ var UPPERCASE = /[\p{Lu}]/u;
1828
+ var LOWERCASE = /[\p{Ll}]/u;
1829
+ var LEADING_CAPITAL = /^[\p{Lu}](?![\p{Lu}])/gu;
1830
+ var IDENTIFIER = /([\p{Alpha}\p{N}_]|$)/u;
1831
+ var SEPARATORS = /[_.\- ]+/;
1832
+ var LEADING_SEPARATORS = new RegExp("^" + SEPARATORS.source);
1833
+ var SEPARATORS_AND_IDENTIFIER = new RegExp(SEPARATORS.source + IDENTIFIER.source, "gu");
1834
+ var NUMBERS_AND_IDENTIFIER = new RegExp("\\d+" + IDENTIFIER.source, "gu");
1835
+ var preserveCamelCase = (string, toLowerCase, toUpperCase, preserveConsecutiveUppercase2) => {
1836
+ let isLastCharLower = false;
1837
+ let isLastCharUpper = false;
1838
+ let isLastLastCharUpper = false;
1839
+ let isLastLastCharPreserved = false;
1840
+ for (let index = 0; index < string.length; index++) {
1841
+ const character = string[index];
1842
+ isLastLastCharPreserved = index > 2 ? string[index - 3] === "-" : true;
1843
+ if (isLastCharLower && UPPERCASE.test(character)) {
1844
+ string = string.slice(0, index) + "-" + string.slice(index);
1845
+ isLastCharLower = false;
1846
+ isLastLastCharUpper = isLastCharUpper;
1847
+ isLastCharUpper = true;
1848
+ index++;
1849
+ } else if (isLastCharUpper && isLastLastCharUpper && LOWERCASE.test(character) && (!isLastLastCharPreserved || preserveConsecutiveUppercase2)) {
1850
+ string = string.slice(0, index - 1) + "-" + string.slice(index - 1);
1851
+ isLastLastCharUpper = isLastCharUpper;
1852
+ isLastCharUpper = false;
1853
+ isLastCharLower = true;
1854
+ } else {
1855
+ isLastCharLower = toLowerCase(character) === character && toUpperCase(character) !== character;
1856
+ isLastLastCharUpper = isLastCharUpper;
1857
+ isLastCharUpper = toUpperCase(character) === character && toLowerCase(character) !== character;
1858
+ }
1859
+ }
1860
+ return string;
1861
+ };
1862
+ var preserveConsecutiveUppercase = (input, toLowerCase) => {
1863
+ LEADING_CAPITAL.lastIndex = 0;
1864
+ return input.replace(LEADING_CAPITAL, (m1) => toLowerCase(m1));
1865
+ };
1866
+ var postProcess = (input, toUpperCase) => {
1867
+ SEPARATORS_AND_IDENTIFIER.lastIndex = 0;
1868
+ NUMBERS_AND_IDENTIFIER.lastIndex = 0;
1869
+ return input.replace(SEPARATORS_AND_IDENTIFIER, (_, identifier) => toUpperCase(identifier)).replace(NUMBERS_AND_IDENTIFIER, (m) => toUpperCase(m));
1870
+ };
1871
+ function camelCase(input, options) {
1872
+ if (!(typeof input === "string" || Array.isArray(input))) {
1873
+ throw new TypeError("Expected the input to be `string | string[]`");
1874
+ }
1875
+ options = {
1876
+ pascalCase: false,
1877
+ preserveConsecutiveUppercase: false,
1878
+ ...options
1879
+ };
1880
+ if (Array.isArray(input)) {
1881
+ input = input.map((x) => x.trim()).filter((x) => x.length).join("-");
1882
+ } else {
1883
+ input = input.trim();
1884
+ }
1885
+ if (input.length === 0) {
1886
+ return "";
1887
+ }
1888
+ const toLowerCase = options.locale === false ? (string) => string.toLowerCase() : (string) => string.toLocaleLowerCase(options.locale);
1889
+ const toUpperCase = options.locale === false ? (string) => string.toUpperCase() : (string) => string.toLocaleUpperCase(options.locale);
1890
+ if (input.length === 1) {
1891
+ if (SEPARATORS.test(input)) {
1892
+ return "";
1893
+ }
1894
+ return options.pascalCase ? toUpperCase(input) : toLowerCase(input);
1895
+ }
1896
+ const hasUpperCase = input !== toLowerCase(input);
1897
+ if (hasUpperCase) {
1898
+ input = preserveCamelCase(input, toLowerCase, toUpperCase, options.preserveConsecutiveUppercase);
1899
+ }
1900
+ input = input.replace(LEADING_SEPARATORS, "");
1901
+ input = options.preserveConsecutiveUppercase ? preserveConsecutiveUppercase(input, toLowerCase) : toLowerCase(input);
1902
+ if (options.pascalCase) {
1903
+ input = toUpperCase(input.charAt(0)) + input.slice(1);
1904
+ }
1905
+ return postProcess(input, toUpperCase);
1906
+ }
1907
+
1908
+ // src/@types/utils.ts
1909
+ String.prototype.trimChar = function(char) {
1910
+ let start = 0;
1911
+ let end = this.length;
1912
+ while (start < end && this[start] === char)
1913
+ ++start;
1914
+ while (end > start && this[end - 1] === char)
1915
+ --end;
1916
+ return start > 0 || end < this.length ? this.substring(start, end) : this.toString();
1917
+ };
1918
+ String.prototype.squashSpaces = function() {
1919
+ return this.replace(/ +/g, " ").trim();
1920
+ };
1921
+ String.prototype.camelCase = function() {
1922
+ return camelCase(String(this));
1923
+ };
1924
+ String.prototype.concatIf = function(it, condition) {
1925
+ return condition ? `${this}${it}` : this;
1926
+ };
1927
+ Array.prototype.random = function() {
1928
+ return this[~~(Math.random() * this.length)];
1929
+ };
1930
+
1931
+ // src/introspect.ts
1932
+ init_pgSerializer();
1933
+
1934
+ // src/global.ts
1935
+ var originUUID = "00000000-0000-0000-0000-000000000000";
1936
+
1937
+ // node_modules/.pnpm/minimatch@7.4.3/node_modules/minimatch/dist/mjs/index.js
1938
+ var import_brace_expansion = __toESM(require_brace_expansion(), 1);
1939
+
1940
+ // node_modules/.pnpm/minimatch@7.4.3/node_modules/minimatch/dist/mjs/brace-expressions.js
1941
+ var posixClasses = {
1942
+ "[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}", true],
1943
+ "[:alpha:]": ["\\p{L}\\p{Nl}", true],
1944
+ "[:ascii:]": ["\\x00-\\x7f", false],
1945
+ "[:blank:]": ["\\p{Zs}\\t", true],
1946
+ "[:cntrl:]": ["\\p{Cc}", true],
1947
+ "[:digit:]": ["\\p{Nd}", true],
1948
+ "[:graph:]": ["\\p{Z}\\p{C}", true, true],
1949
+ "[:lower:]": ["\\p{Ll}", true],
1950
+ "[:print:]": ["\\p{C}", true],
1951
+ "[:punct:]": ["\\p{P}", true],
1952
+ "[:space:]": ["\\p{Z}\\t\\r\\n\\v\\f", true],
1953
+ "[:upper:]": ["\\p{Lu}", true],
1954
+ "[:word:]": ["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}", true],
1955
+ "[:xdigit:]": ["A-Fa-f0-9", false]
1956
+ };
1957
+ var braceEscape = (s) => s.replace(/[[\]\\-]/g, "\\$&");
1958
+ var regexpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
1959
+ var rangesToString = (ranges) => ranges.join("");
1960
+ var parseClass = (glob2, position) => {
1961
+ const pos = position;
1962
+ if (glob2.charAt(pos) !== "[") {
1963
+ throw new Error("not in a brace expression");
1964
+ }
1965
+ const ranges = [];
1966
+ const negs = [];
1967
+ let i = pos + 1;
1968
+ let sawStart = false;
1969
+ let uflag = false;
1970
+ let escaping = false;
1971
+ let negate = false;
1972
+ let endPos = pos;
1973
+ let rangeStart = "";
1974
+ WHILE:
1975
+ while (i < glob2.length) {
1976
+ const c = glob2.charAt(i);
1977
+ if ((c === "!" || c === "^") && i === pos + 1) {
1978
+ negate = true;
1979
+ i++;
1980
+ continue;
1981
+ }
1982
+ if (c === "]" && sawStart && !escaping) {
1983
+ endPos = i + 1;
1984
+ break;
1985
+ }
1986
+ sawStart = true;
1987
+ if (c === "\\") {
1988
+ if (!escaping) {
1989
+ escaping = true;
1990
+ i++;
1991
+ continue;
1992
+ }
1993
+ }
1994
+ if (c === "[" && !escaping) {
1995
+ for (const [cls, [unip, u, neg]] of Object.entries(posixClasses)) {
1996
+ if (glob2.startsWith(cls, i)) {
1997
+ if (rangeStart) {
1998
+ return ["$.", false, glob2.length - pos, true];
1999
+ }
2000
+ i += cls.length;
2001
+ if (neg)
2002
+ negs.push(unip);
2003
+ else
2004
+ ranges.push(unip);
2005
+ uflag = uflag || u;
2006
+ continue WHILE;
2007
+ }
2008
+ }
2009
+ }
2010
+ escaping = false;
2011
+ if (rangeStart) {
2012
+ if (c > rangeStart) {
2013
+ ranges.push(braceEscape(rangeStart) + "-" + braceEscape(c));
2014
+ } else if (c === rangeStart) {
2015
+ ranges.push(braceEscape(c));
2016
+ }
2017
+ rangeStart = "";
2018
+ i++;
2019
+ continue;
2020
+ }
2021
+ if (glob2.startsWith("-]", i + 1)) {
2022
+ ranges.push(braceEscape(c + "-"));
2023
+ i += 2;
2024
+ continue;
2025
+ }
2026
+ if (glob2.startsWith("-", i + 1)) {
2027
+ rangeStart = c;
2028
+ i += 2;
2029
+ continue;
2030
+ }
2031
+ ranges.push(braceEscape(c));
2032
+ i++;
2033
+ }
2034
+ if (endPos < i) {
2035
+ return ["", false, 0, false];
2036
+ }
2037
+ if (!ranges.length && !negs.length) {
2038
+ return ["$.", false, glob2.length - pos, true];
2039
+ }
2040
+ if (negs.length === 0 && ranges.length === 1 && /^\\?.$/.test(ranges[0]) && !negate) {
2041
+ const r = ranges[0].length === 2 ? ranges[0].slice(-1) : ranges[0];
2042
+ return [regexpEscape(r), false, endPos - pos, false];
2043
+ }
2044
+ const sranges = "[" + (negate ? "^" : "") + rangesToString(ranges) + "]";
2045
+ const snegs = "[" + (negate ? "" : "^") + rangesToString(negs) + "]";
2046
+ const comb = ranges.length && negs.length ? "(" + sranges + "|" + snegs + ")" : ranges.length ? sranges : snegs;
2047
+ return [comb, uflag, endPos - pos, true];
2048
+ };
2049
+
2050
+ // node_modules/.pnpm/minimatch@7.4.3/node_modules/minimatch/dist/mjs/escape.js
2051
+ var escape = (s, { windowsPathsNoEscape = false } = {}) => {
2052
+ return windowsPathsNoEscape ? s.replace(/[?*()[\]]/g, "[$&]") : s.replace(/[?*()[\]\\]/g, "\\$&");
2053
+ };
2054
+
2055
+ // node_modules/.pnpm/minimatch@7.4.3/node_modules/minimatch/dist/mjs/unescape.js
2056
+ var unescape = (s, { windowsPathsNoEscape = false } = {}) => {
2057
+ return windowsPathsNoEscape ? s.replace(/\[([^\/\\])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^\/\\])\]/g, "$1$2").replace(/\\([^\/])/g, "$1");
2058
+ };
2059
+
2060
+ // node_modules/.pnpm/minimatch@7.4.3/node_modules/minimatch/dist/mjs/index.js
2061
+ var minimatch = (p, pattern, options = {}) => {
2062
+ assertValidPattern(pattern);
2063
+ if (!options.nocomment && pattern.charAt(0) === "#") {
2064
+ return false;
2065
+ }
2066
+ return new Minimatch(pattern, options).match(p);
2067
+ };
2068
+ var starDotExtRE = /^\*+([^+@!?\*\[\(]*)$/;
2069
+ var starDotExtTest = (ext2) => (f) => !f.startsWith(".") && f.endsWith(ext2);
2070
+ var starDotExtTestDot = (ext2) => (f) => f.endsWith(ext2);
2071
+ var starDotExtTestNocase = (ext2) => {
2072
+ ext2 = ext2.toLowerCase();
2073
+ return (f) => !f.startsWith(".") && f.toLowerCase().endsWith(ext2);
2074
+ };
2075
+ var starDotExtTestNocaseDot = (ext2) => {
2076
+ ext2 = ext2.toLowerCase();
2077
+ return (f) => f.toLowerCase().endsWith(ext2);
2078
+ };
2079
+ var starDotStarRE = /^\*+\.\*+$/;
2080
+ var starDotStarTest = (f) => !f.startsWith(".") && f.includes(".");
2081
+ var starDotStarTestDot = (f) => f !== "." && f !== ".." && f.includes(".");
2082
+ var dotStarRE = /^\.\*+$/;
2083
+ var dotStarTest = (f) => f !== "." && f !== ".." && f.startsWith(".");
2084
+ var starRE = /^\*+$/;
2085
+ var starTest = (f) => f.length !== 0 && !f.startsWith(".");
2086
+ var starTestDot = (f) => f.length !== 0 && f !== "." && f !== "..";
2087
+ var qmarksRE = /^\?+([^+@!?\*\[\(]*)?$/;
2088
+ var qmarksTestNocase = ([$0, ext2 = ""]) => {
2089
+ const noext = qmarksTestNoExt([$0]);
2090
+ if (!ext2)
2091
+ return noext;
2092
+ ext2 = ext2.toLowerCase();
2093
+ return (f) => noext(f) && f.toLowerCase().endsWith(ext2);
2094
+ };
2095
+ var qmarksTestNocaseDot = ([$0, ext2 = ""]) => {
2096
+ const noext = qmarksTestNoExtDot([$0]);
2097
+ if (!ext2)
2098
+ return noext;
2099
+ ext2 = ext2.toLowerCase();
2100
+ return (f) => noext(f) && f.toLowerCase().endsWith(ext2);
2101
+ };
2102
+ var qmarksTestDot = ([$0, ext2 = ""]) => {
2103
+ const noext = qmarksTestNoExtDot([$0]);
2104
+ return !ext2 ? noext : (f) => noext(f) && f.endsWith(ext2);
2105
+ };
2106
+ var qmarksTest = ([$0, ext2 = ""]) => {
2107
+ const noext = qmarksTestNoExt([$0]);
2108
+ return !ext2 ? noext : (f) => noext(f) && f.endsWith(ext2);
2109
+ };
2110
+ var qmarksTestNoExt = ([$0]) => {
2111
+ const len = $0.length;
2112
+ return (f) => f.length === len && !f.startsWith(".");
2113
+ };
2114
+ var qmarksTestNoExtDot = ([$0]) => {
2115
+ const len = $0.length;
2116
+ return (f) => f.length === len && f !== "." && f !== "..";
2117
+ };
2118
+ var defaultPlatform = typeof process === "object" && process ? typeof process.env === "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix";
2119
+ var path = {
2120
+ win32: { sep: "\\" },
2121
+ posix: { sep: "/" }
2122
+ };
2123
+ var sep = defaultPlatform === "win32" ? path.win32.sep : path.posix.sep;
2124
+ minimatch.sep = sep;
2125
+ var GLOBSTAR = Symbol("globstar **");
2126
+ minimatch.GLOBSTAR = GLOBSTAR;
2127
+ var plTypes = {
2128
+ "!": { open: "(?:(?!(?:", close: "))[^/]*?)" },
2129
+ "?": { open: "(?:", close: ")?" },
2130
+ "+": { open: "(?:", close: ")+" },
2131
+ "*": { open: "(?:", close: ")*" },
2132
+ "@": { open: "(?:", close: ")" }
2133
+ };
2134
+ var qmark = "[^/]";
2135
+ var star = qmark + "*?";
2136
+ var twoStarDot = "(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?";
2137
+ var twoStarNoDot = "(?:(?!(?:\\/|^)\\.).)*?";
2138
+ var charSet = (s) => s.split("").reduce((set, c) => {
2139
+ set[c] = true;
2140
+ return set;
2141
+ }, {});
2142
+ var reSpecials = charSet("().*{}+?[]^$\\!");
2143
+ var addPatternStartSet = charSet("[.(");
2144
+ var filter = (pattern, options = {}) => (p) => minimatch(p, pattern, options);
2145
+ minimatch.filter = filter;
2146
+ var ext = (a, b = {}) => Object.assign({}, a, b);
2147
+ var defaults = (def) => {
2148
+ if (!def || typeof def !== "object" || !Object.keys(def).length) {
2149
+ return minimatch;
2150
+ }
2151
+ const orig = minimatch;
2152
+ const m = (p, pattern, options = {}) => orig(p, pattern, ext(def, options));
2153
+ return Object.assign(m, {
2154
+ Minimatch: class Minimatch extends orig.Minimatch {
2155
+ constructor(pattern, options = {}) {
2156
+ super(pattern, ext(def, options));
2157
+ }
2158
+ static defaults(options) {
2159
+ return orig.defaults(ext(def, options)).Minimatch;
2160
+ }
2161
+ },
2162
+ unescape: (s, options = {}) => orig.unescape(s, ext(def, options)),
2163
+ escape: (s, options = {}) => orig.escape(s, ext(def, options)),
2164
+ filter: (pattern, options = {}) => orig.filter(pattern, ext(def, options)),
2165
+ defaults: (options) => orig.defaults(ext(def, options)),
2166
+ makeRe: (pattern, options = {}) => orig.makeRe(pattern, ext(def, options)),
2167
+ braceExpand: (pattern, options = {}) => orig.braceExpand(pattern, ext(def, options)),
2168
+ match: (list, pattern, options = {}) => orig.match(list, pattern, ext(def, options)),
2169
+ sep: orig.sep,
2170
+ GLOBSTAR
2171
+ });
2172
+ };
2173
+ minimatch.defaults = defaults;
2174
+ var braceExpand = (pattern, options = {}) => {
2175
+ assertValidPattern(pattern);
2176
+ if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) {
2177
+ return [pattern];
2178
+ }
2179
+ return (0, import_brace_expansion.default)(pattern);
2180
+ };
2181
+ minimatch.braceExpand = braceExpand;
2182
+ var MAX_PATTERN_LENGTH = 1024 * 64;
2183
+ var assertValidPattern = (pattern) => {
2184
+ if (typeof pattern !== "string") {
2185
+ throw new TypeError("invalid pattern");
2186
+ }
2187
+ if (pattern.length > MAX_PATTERN_LENGTH) {
2188
+ throw new TypeError("pattern is too long");
2189
+ }
2190
+ };
2191
+ var makeRe = (pattern, options = {}) => new Minimatch(pattern, options).makeRe();
2192
+ minimatch.makeRe = makeRe;
2193
+ var match = (list, pattern, options = {}) => {
2194
+ const mm = new Minimatch(pattern, options);
2195
+ list = list.filter((f) => mm.match(f));
2196
+ if (mm.options.nonull && !list.length) {
2197
+ list.push(pattern);
2198
+ }
2199
+ return list;
2200
+ };
2201
+ minimatch.match = match;
2202
+ var globUnescape = (s) => s.replace(/\\(.)/g, "$1");
2203
+ var globMagic = /[?*]|[+@!]\(.*?\)|\[|\]/;
2204
+ var regExpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
2205
+ var Minimatch = class {
2206
+ options;
2207
+ set;
2208
+ pattern;
2209
+ windowsPathsNoEscape;
2210
+ nonegate;
2211
+ negate;
2212
+ comment;
2213
+ empty;
2214
+ preserveMultipleSlashes;
2215
+ partial;
2216
+ globSet;
2217
+ globParts;
2218
+ nocase;
2219
+ isWindows;
2220
+ platform;
2221
+ windowsNoMagicRoot;
2222
+ regexp;
2223
+ constructor(pattern, options = {}) {
2224
+ assertValidPattern(pattern);
2225
+ options = options || {};
2226
+ this.options = options;
2227
+ this.pattern = pattern;
2228
+ this.platform = options.platform || defaultPlatform;
2229
+ this.isWindows = this.platform === "win32";
2230
+ this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || options.allowWindowsEscape === false;
2231
+ if (this.windowsPathsNoEscape) {
2232
+ this.pattern = this.pattern.replace(/\\/g, "/");
2233
+ }
2234
+ this.preserveMultipleSlashes = !!options.preserveMultipleSlashes;
2235
+ this.regexp = null;
2236
+ this.negate = false;
2237
+ this.nonegate = !!options.nonegate;
2238
+ this.comment = false;
2239
+ this.empty = false;
2240
+ this.partial = !!options.partial;
2241
+ this.nocase = !!this.options.nocase;
2242
+ this.windowsNoMagicRoot = options.windowsNoMagicRoot !== void 0 ? options.windowsNoMagicRoot : !!(this.isWindows && this.nocase);
2243
+ this.globSet = [];
2244
+ this.globParts = [];
2245
+ this.set = [];
2246
+ this.make();
2247
+ }
2248
+ hasMagic() {
2249
+ if (this.options.magicalBraces && this.set.length > 1) {
2250
+ return true;
2251
+ }
2252
+ for (const pattern of this.set) {
2253
+ for (const part of pattern) {
2254
+ if (typeof part !== "string")
2255
+ return true;
2256
+ }
2257
+ }
2258
+ return false;
2259
+ }
2260
+ debug(..._) {
2261
+ }
2262
+ make() {
2263
+ const pattern = this.pattern;
2264
+ const options = this.options;
2265
+ if (!options.nocomment && pattern.charAt(0) === "#") {
2266
+ this.comment = true;
2267
+ return;
2268
+ }
2269
+ if (!pattern) {
2270
+ this.empty = true;
2271
+ return;
2272
+ }
2273
+ this.parseNegate();
2274
+ this.globSet = [...new Set(this.braceExpand())];
2275
+ if (options.debug) {
2276
+ this.debug = (...args) => console.error(...args);
2277
+ }
2278
+ this.debug(this.pattern, this.globSet);
2279
+ const rawGlobParts = this.globSet.map((s) => this.slashSplit(s));
2280
+ this.globParts = this.preprocess(rawGlobParts);
2281
+ this.debug(this.pattern, this.globParts);
2282
+ let set = this.globParts.map((s, _, __) => {
2283
+ if (this.isWindows && this.windowsNoMagicRoot) {
2284
+ const isUNC = s[0] === "" && s[1] === "" && (s[2] === "?" || !globMagic.test(s[2])) && !globMagic.test(s[3]);
2285
+ const isDrive = /^[a-z]:/i.test(s[0]);
2286
+ if (isUNC) {
2287
+ return [...s.slice(0, 4), ...s.slice(4).map((ss) => this.parse(ss))];
2288
+ } else if (isDrive) {
2289
+ return [s[0], ...s.slice(1).map((ss) => this.parse(ss))];
2290
+ }
2291
+ }
2292
+ return s.map((ss) => this.parse(ss));
2293
+ });
2294
+ this.debug(this.pattern, set);
2295
+ this.set = set.filter((s) => s.indexOf(false) === -1);
2296
+ if (this.isWindows) {
2297
+ for (let i = 0; i < this.set.length; i++) {
2298
+ const p = this.set[i];
2299
+ if (p[0] === "" && p[1] === "" && this.globParts[i][2] === "?" && typeof p[3] === "string" && /^[a-z]:$/i.test(p[3])) {
2300
+ p[2] = "?";
2301
+ }
2302
+ }
2303
+ }
2304
+ this.debug(this.pattern, this.set);
2305
+ }
2306
+ // various transforms to equivalent pattern sets that are
2307
+ // faster to process in a filesystem walk. The goal is to
2308
+ // eliminate what we can, and push all ** patterns as far
2309
+ // to the right as possible, even if it increases the number
2310
+ // of patterns that we have to process.
2311
+ preprocess(globParts) {
2312
+ if (this.options.noglobstar) {
2313
+ for (let i = 0; i < globParts.length; i++) {
2314
+ for (let j = 0; j < globParts[i].length; j++) {
2315
+ if (globParts[i][j] === "**") {
2316
+ globParts[i][j] = "*";
2317
+ }
2318
+ }
2319
+ }
2320
+ }
2321
+ const { optimizationLevel = 1 } = this.options;
2322
+ if (optimizationLevel >= 2) {
2323
+ globParts = this.firstPhasePreProcess(globParts);
2324
+ globParts = this.secondPhasePreProcess(globParts);
2325
+ } else if (optimizationLevel >= 1) {
2326
+ globParts = this.levelOneOptimize(globParts);
2327
+ } else {
2328
+ globParts = this.adjascentGlobstarOptimize(globParts);
2329
+ }
2330
+ return globParts;
2331
+ }
2332
+ // just get rid of adjascent ** portions
2333
+ adjascentGlobstarOptimize(globParts) {
2334
+ return globParts.map((parts) => {
2335
+ let gs = -1;
2336
+ while (-1 !== (gs = parts.indexOf("**", gs + 1))) {
2337
+ let i = gs;
2338
+ while (parts[i + 1] === "**") {
2339
+ i++;
2340
+ }
2341
+ if (i !== gs) {
2342
+ parts.splice(gs, i - gs);
2343
+ }
2344
+ }
2345
+ return parts;
2346
+ });
2347
+ }
2348
+ // get rid of adjascent ** and resolve .. portions
2349
+ levelOneOptimize(globParts) {
2350
+ return globParts.map((parts) => {
2351
+ parts = parts.reduce((set, part) => {
2352
+ const prev = set[set.length - 1];
2353
+ if (part === "**" && prev === "**") {
2354
+ return set;
2355
+ }
2356
+ if (part === "..") {
2357
+ if (prev && prev !== ".." && prev !== "." && prev !== "**") {
2358
+ set.pop();
2359
+ return set;
2360
+ }
2361
+ }
2362
+ set.push(part);
2363
+ return set;
2364
+ }, []);
2365
+ return parts.length === 0 ? [""] : parts;
2366
+ });
2367
+ }
2368
+ levelTwoFileOptimize(parts) {
2369
+ if (!Array.isArray(parts)) {
2370
+ parts = this.slashSplit(parts);
2371
+ }
2372
+ let didSomething = false;
2373
+ do {
2374
+ didSomething = false;
2375
+ if (!this.preserveMultipleSlashes) {
2376
+ for (let i = 1; i < parts.length - 1; i++) {
2377
+ const p = parts[i];
2378
+ if (i === 1 && p === "" && parts[0] === "")
2379
+ continue;
2380
+ if (p === "." || p === "") {
2381
+ didSomething = true;
2382
+ parts.splice(i, 1);
2383
+ i--;
2384
+ }
2385
+ }
2386
+ if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
2387
+ didSomething = true;
2388
+ parts.pop();
2389
+ }
2390
+ }
2391
+ let dd = 0;
2392
+ while (-1 !== (dd = parts.indexOf("..", dd + 1))) {
2393
+ const p = parts[dd - 1];
2394
+ if (p && p !== "." && p !== ".." && p !== "**") {
2395
+ didSomething = true;
2396
+ parts.splice(dd - 1, 2);
2397
+ dd -= 2;
2398
+ }
2399
+ }
2400
+ } while (didSomething);
2401
+ return parts.length === 0 ? [""] : parts;
2402
+ }
2403
+ // First phase: single-pattern processing
2404
+ // <pre> is 1 or more portions
2405
+ // <rest> is 1 or more portions
2406
+ // <p> is any portion other than ., .., '', or **
2407
+ // <e> is . or ''
2408
+ //
2409
+ // **/.. is *brutal* for filesystem walking performance, because
2410
+ // it effectively resets the recursive walk each time it occurs,
2411
+ // and ** cannot be reduced out by a .. pattern part like a regexp
2412
+ // or most strings (other than .., ., and '') can be.
2413
+ //
2414
+ // <pre>/**/../<p>/<p>/<rest> -> {<pre>/../<p>/<p>/<rest>,<pre>/**/<p>/<p>/<rest>}
2415
+ // <pre>/<e>/<rest> -> <pre>/<rest>
2416
+ // <pre>/<p>/../<rest> -> <pre>/<rest>
2417
+ // **/**/<rest> -> **/<rest>
2418
+ //
2419
+ // **/*/<rest> -> */**/<rest> <== not valid because ** doesn't follow
2420
+ // this WOULD be allowed if ** did follow symlinks, or * didn't
2421
+ firstPhasePreProcess(globParts) {
2422
+ let didSomething = false;
2423
+ do {
2424
+ didSomething = false;
2425
+ for (let parts of globParts) {
2426
+ let gs = -1;
2427
+ while (-1 !== (gs = parts.indexOf("**", gs + 1))) {
2428
+ let gss = gs;
2429
+ while (parts[gss + 1] === "**") {
2430
+ gss++;
2431
+ }
2432
+ if (gss > gs) {
2433
+ parts.splice(gs + 1, gss - gs);
2434
+ }
2435
+ let next = parts[gs + 1];
2436
+ const p = parts[gs + 2];
2437
+ const p2 = parts[gs + 3];
2438
+ if (next !== "..")
2439
+ continue;
2440
+ if (!p || p === "." || p === ".." || !p2 || p2 === "." || p2 === "..") {
2441
+ continue;
2442
+ }
2443
+ didSomething = true;
2444
+ parts.splice(gs, 1);
2445
+ const other = parts.slice(0);
2446
+ other[gs] = "**";
2447
+ globParts.push(other);
2448
+ gs--;
2449
+ }
2450
+ if (!this.preserveMultipleSlashes) {
2451
+ for (let i = 1; i < parts.length - 1; i++) {
2452
+ const p = parts[i];
2453
+ if (i === 1 && p === "" && parts[0] === "")
2454
+ continue;
2455
+ if (p === "." || p === "") {
2456
+ didSomething = true;
2457
+ parts.splice(i, 1);
2458
+ i--;
2459
+ }
2460
+ }
2461
+ if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
2462
+ didSomething = true;
2463
+ parts.pop();
2464
+ }
2465
+ }
2466
+ let dd = 0;
2467
+ while (-1 !== (dd = parts.indexOf("..", dd + 1))) {
2468
+ const p = parts[dd - 1];
2469
+ if (p && p !== "." && p !== ".." && p !== "**") {
2470
+ didSomething = true;
2471
+ const needDot = dd === 1 && parts[dd + 1] === "**";
2472
+ const splin = needDot ? ["."] : [];
2473
+ parts.splice(dd - 1, 2, ...splin);
2474
+ if (parts.length === 0)
2475
+ parts.push("");
2476
+ dd -= 2;
2477
+ }
2478
+ }
2479
+ }
2480
+ } while (didSomething);
2481
+ return globParts;
2482
+ }
2483
+ // second phase: multi-pattern dedupes
2484
+ // {<pre>/*/<rest>,<pre>/<p>/<rest>} -> <pre>/*/<rest>
2485
+ // {<pre>/<rest>,<pre>/<rest>} -> <pre>/<rest>
2486
+ // {<pre>/**/<rest>,<pre>/<rest>} -> <pre>/**/<rest>
2487
+ //
2488
+ // {<pre>/**/<rest>,<pre>/**/<p>/<rest>} -> <pre>/**/<rest>
2489
+ // ^-- not valid because ** doens't follow symlinks
2490
+ secondPhasePreProcess(globParts) {
2491
+ for (let i = 0; i < globParts.length - 1; i++) {
2492
+ for (let j = i + 1; j < globParts.length; j++) {
2493
+ const matched = this.partsMatch(globParts[i], globParts[j], !this.preserveMultipleSlashes);
2494
+ if (!matched)
2495
+ continue;
2496
+ globParts[i] = matched;
2497
+ globParts[j] = [];
2498
+ }
2499
+ }
2500
+ return globParts.filter((gs) => gs.length);
2501
+ }
2502
+ partsMatch(a, b, emptyGSMatch = false) {
2503
+ let ai = 0;
2504
+ let bi = 0;
2505
+ let result = [];
2506
+ let which = "";
2507
+ while (ai < a.length && bi < b.length) {
2508
+ if (a[ai] === b[bi]) {
2509
+ result.push(which === "b" ? b[bi] : a[ai]);
2510
+ ai++;
2511
+ bi++;
2512
+ } else if (emptyGSMatch && a[ai] === "**" && b[bi] === a[ai + 1]) {
2513
+ result.push(a[ai]);
2514
+ ai++;
2515
+ } else if (emptyGSMatch && b[bi] === "**" && a[ai] === b[bi + 1]) {
2516
+ result.push(b[bi]);
2517
+ bi++;
2518
+ } else if (a[ai] === "*" && b[bi] && (this.options.dot || !b[bi].startsWith(".")) && b[bi] !== "**") {
2519
+ if (which === "b")
2520
+ return false;
2521
+ which = "a";
2522
+ result.push(a[ai]);
2523
+ ai++;
2524
+ bi++;
2525
+ } else if (b[bi] === "*" && a[ai] && (this.options.dot || !a[ai].startsWith(".")) && a[ai] !== "**") {
2526
+ if (which === "a")
2527
+ return false;
2528
+ which = "b";
2529
+ result.push(b[bi]);
2530
+ ai++;
2531
+ bi++;
2532
+ } else {
2533
+ return false;
2534
+ }
2535
+ }
2536
+ return a.length === b.length && result;
2537
+ }
2538
+ parseNegate() {
2539
+ if (this.nonegate)
2540
+ return;
2541
+ const pattern = this.pattern;
2542
+ let negate = false;
2543
+ let negateOffset = 0;
2544
+ for (let i = 0; i < pattern.length && pattern.charAt(i) === "!"; i++) {
2545
+ negate = !negate;
2546
+ negateOffset++;
2547
+ }
2548
+ if (negateOffset)
2549
+ this.pattern = pattern.slice(negateOffset);
2550
+ this.negate = negate;
2551
+ }
2552
+ // set partial to true to test if, for example,
2553
+ // "/a/b" matches the start of "/*/b/*/d"
2554
+ // Partial means, if you run out of file before you run
2555
+ // out of pattern, then that's fine, as long as all
2556
+ // the parts match.
2557
+ matchOne(file, pattern, partial = false) {
2558
+ const options = this.options;
2559
+ if (this.isWindows) {
2560
+ const fileUNC = file[0] === "" && file[1] === "" && file[2] === "?" && typeof file[3] === "string" && /^[a-z]:$/i.test(file[3]);
2561
+ const patternUNC = pattern[0] === "" && pattern[1] === "" && pattern[2] === "?" && typeof pattern[3] === "string" && /^[a-z]:$/i.test(pattern[3]);
2562
+ if (fileUNC && patternUNC) {
2563
+ const fd = file[3];
2564
+ const pd = pattern[3];
2565
+ if (fd.toLowerCase() === pd.toLowerCase()) {
2566
+ file[3] = pd;
2567
+ }
2568
+ } else if (patternUNC && typeof file[0] === "string") {
2569
+ const pd = pattern[3];
2570
+ const fd = file[0];
2571
+ if (pd.toLowerCase() === fd.toLowerCase()) {
2572
+ pattern[3] = fd;
2573
+ pattern = pattern.slice(3);
2574
+ }
2575
+ } else if (fileUNC && typeof pattern[0] === "string") {
2576
+ const fd = file[3];
2577
+ if (fd.toLowerCase() === pattern[0].toLowerCase()) {
2578
+ pattern[0] = fd;
2579
+ file = file.slice(3);
2580
+ }
2581
+ }
2582
+ }
2583
+ const { optimizationLevel = 1 } = this.options;
2584
+ if (optimizationLevel >= 2) {
2585
+ file = this.levelTwoFileOptimize(file);
2586
+ }
2587
+ this.debug("matchOne", this, { file, pattern });
2588
+ this.debug("matchOne", file.length, pattern.length);
2589
+ for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
2590
+ this.debug("matchOne loop");
2591
+ var p = pattern[pi];
2592
+ var f = file[fi];
2593
+ this.debug(pattern, p, f);
2594
+ if (p === false) {
2595
+ return false;
2596
+ }
2597
+ if (p === GLOBSTAR) {
2598
+ this.debug("GLOBSTAR", [pattern, p, f]);
2599
+ var fr = fi;
2600
+ var pr = pi + 1;
2601
+ if (pr === pl) {
2602
+ this.debug("** at the end");
2603
+ for (; fi < fl; fi++) {
2604
+ if (file[fi] === "." || file[fi] === ".." || !options.dot && file[fi].charAt(0) === ".")
2605
+ return false;
2606
+ }
2607
+ return true;
2608
+ }
2609
+ while (fr < fl) {
2610
+ var swallowee = file[fr];
2611
+ this.debug("\nglobstar while", file, fr, pattern, pr, swallowee);
2612
+ if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
2613
+ this.debug("globstar found match!", fr, fl, swallowee);
2614
+ return true;
2615
+ } else {
2616
+ if (swallowee === "." || swallowee === ".." || !options.dot && swallowee.charAt(0) === ".") {
2617
+ this.debug("dot detected!", file, fr, pattern, pr);
2618
+ break;
2619
+ }
2620
+ this.debug("globstar swallow a segment, and continue");
2621
+ fr++;
2622
+ }
2623
+ }
2624
+ if (partial) {
2625
+ this.debug("\n>>> no match, partial?", file, fr, pattern, pr);
2626
+ if (fr === fl) {
2627
+ return true;
2628
+ }
2629
+ }
2630
+ return false;
2631
+ }
2632
+ let hit;
2633
+ if (typeof p === "string") {
2634
+ hit = f === p;
2635
+ this.debug("string match", p, f, hit);
2636
+ } else {
2637
+ hit = p.test(f);
2638
+ this.debug("pattern match", p, f, hit);
2639
+ }
2640
+ if (!hit)
2641
+ return false;
2642
+ }
2643
+ if (fi === fl && pi === pl) {
2644
+ return true;
2645
+ } else if (fi === fl) {
2646
+ return partial;
2647
+ } else if (pi === pl) {
2648
+ return fi === fl - 1 && file[fi] === "";
2649
+ } else {
2650
+ throw new Error("wtf?");
2651
+ }
2652
+ }
2653
+ braceExpand() {
2654
+ return braceExpand(this.pattern, this.options);
2655
+ }
2656
+ parse(pattern) {
2657
+ assertValidPattern(pattern);
2658
+ const options = this.options;
2659
+ if (pattern === "**")
2660
+ return GLOBSTAR;
2661
+ if (pattern === "")
2662
+ return "";
2663
+ let m;
2664
+ let fastTest = null;
2665
+ if (m = pattern.match(starRE)) {
2666
+ fastTest = options.dot ? starTestDot : starTest;
2667
+ } else if (m = pattern.match(starDotExtRE)) {
2668
+ fastTest = (options.nocase ? options.dot ? starDotExtTestNocaseDot : starDotExtTestNocase : options.dot ? starDotExtTestDot : starDotExtTest)(m[1]);
2669
+ } else if (m = pattern.match(qmarksRE)) {
2670
+ fastTest = (options.nocase ? options.dot ? qmarksTestNocaseDot : qmarksTestNocase : options.dot ? qmarksTestDot : qmarksTest)(m);
2671
+ } else if (m = pattern.match(starDotStarRE)) {
2672
+ fastTest = options.dot ? starDotStarTestDot : starDotStarTest;
2673
+ } else if (m = pattern.match(dotStarRE)) {
2674
+ fastTest = dotStarTest;
2675
+ }
2676
+ let re = "";
2677
+ let hasMagic = false;
2678
+ let escaping = false;
2679
+ const patternListStack = [];
2680
+ const negativeLists = [];
2681
+ let stateChar = false;
2682
+ let uflag = false;
2683
+ let pl;
2684
+ let dotTravAllowed = pattern.charAt(0) === ".";
2685
+ let dotFileAllowed = options.dot || dotTravAllowed;
2686
+ const patternStart = () => dotTravAllowed ? "" : dotFileAllowed ? "(?!(?:^|\\/)\\.{1,2}(?:$|\\/))" : "(?!\\.)";
2687
+ const subPatternStart = (p) => p.charAt(0) === "." ? "" : options.dot ? "(?!(?:^|\\/)\\.{1,2}(?:$|\\/))" : "(?!\\.)";
2688
+ const clearStateChar = () => {
2689
+ if (stateChar) {
2690
+ switch (stateChar) {
2691
+ case "*":
2692
+ re += star;
2693
+ hasMagic = true;
2694
+ break;
2695
+ case "?":
2696
+ re += qmark;
2697
+ hasMagic = true;
2698
+ break;
2699
+ default:
2700
+ re += "\\" + stateChar;
2701
+ break;
2702
+ }
2703
+ this.debug("clearStateChar %j %j", stateChar, re);
2704
+ stateChar = false;
2705
+ }
2706
+ };
2707
+ for (let i = 0, c; i < pattern.length && (c = pattern.charAt(i)); i++) {
2708
+ this.debug("%s %s %s %j", pattern, i, re, c);
2709
+ if (escaping) {
2710
+ if (c === "/") {
2711
+ return false;
2712
+ }
2713
+ if (reSpecials[c]) {
2714
+ re += "\\";
2715
+ }
2716
+ re += c;
2717
+ escaping = false;
2718
+ continue;
2719
+ }
2720
+ switch (c) {
2721
+ case "/": {
2722
+ return false;
2723
+ }
2724
+ case "\\":
2725
+ clearStateChar();
2726
+ escaping = true;
2727
+ continue;
2728
+ case "?":
2729
+ case "*":
2730
+ case "+":
2731
+ case "@":
2732
+ case "!":
2733
+ this.debug("%s %s %s %j <-- stateChar", pattern, i, re, c);
2734
+ this.debug("call clearStateChar %j", stateChar);
2735
+ clearStateChar();
2736
+ stateChar = c;
2737
+ if (options.noext)
2738
+ clearStateChar();
2739
+ continue;
2740
+ case "(": {
2741
+ if (!stateChar) {
2742
+ re += "\\(";
2743
+ continue;
2744
+ }
2745
+ const plEntry = {
2746
+ type: stateChar,
2747
+ start: i - 1,
2748
+ reStart: re.length,
2749
+ open: plTypes[stateChar].open,
2750
+ close: plTypes[stateChar].close
2751
+ };
2752
+ this.debug(this.pattern, " ", plEntry);
2753
+ patternListStack.push(plEntry);
2754
+ re += plEntry.open;
2755
+ if (plEntry.start === 0 && plEntry.type !== "!") {
2756
+ dotTravAllowed = true;
2757
+ re += subPatternStart(pattern.slice(i + 1));
2758
+ }
2759
+ this.debug("plType %j %j", stateChar, re);
2760
+ stateChar = false;
2761
+ continue;
2762
+ }
2763
+ case ")": {
2764
+ const plEntry = patternListStack[patternListStack.length - 1];
2765
+ if (!plEntry) {
2766
+ re += "\\)";
2767
+ continue;
2768
+ }
2769
+ patternListStack.pop();
2770
+ clearStateChar();
2771
+ hasMagic = true;
2772
+ pl = plEntry;
2773
+ re += pl.close;
2774
+ if (pl.type === "!") {
2775
+ negativeLists.push(Object.assign(pl, { reEnd: re.length }));
2776
+ }
2777
+ continue;
2778
+ }
2779
+ case "|": {
2780
+ const plEntry = patternListStack[patternListStack.length - 1];
2781
+ if (!plEntry) {
2782
+ re += "\\|";
2783
+ continue;
2784
+ }
2785
+ clearStateChar();
2786
+ re += "|";
2787
+ if (plEntry.start === 0 && plEntry.type !== "!") {
2788
+ dotTravAllowed = true;
2789
+ re += subPatternStart(pattern.slice(i + 1));
2790
+ }
2791
+ continue;
2792
+ }
2793
+ case "[":
2794
+ clearStateChar();
2795
+ const [src, needUflag, consumed, magic] = parseClass(pattern, i);
2796
+ if (consumed) {
2797
+ re += src;
2798
+ uflag = uflag || needUflag;
2799
+ i += consumed - 1;
2800
+ hasMagic = hasMagic || magic;
2801
+ } else {
2802
+ re += "\\[";
2803
+ }
2804
+ continue;
2805
+ case "]":
2806
+ re += "\\" + c;
2807
+ continue;
2808
+ default:
2809
+ clearStateChar();
2810
+ re += regExpEscape(c);
2811
+ break;
2812
+ }
2813
+ }
2814
+ for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
2815
+ let tail;
2816
+ tail = re.slice(pl.reStart + pl.open.length);
2817
+ this.debug(this.pattern, "setting tail", re, pl);
2818
+ tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, (_, $1, $2) => {
2819
+ if (!$2) {
2820
+ $2 = "\\";
2821
+ }
2822
+ return $1 + $1 + $2 + "|";
2823
+ });
2824
+ this.debug("tail=%j\n %s", tail, tail, pl, re);
2825
+ const t = pl.type === "*" ? star : pl.type === "?" ? qmark : "\\" + pl.type;
2826
+ hasMagic = true;
2827
+ re = re.slice(0, pl.reStart) + t + "\\(" + tail;
2828
+ }
2829
+ clearStateChar();
2830
+ if (escaping) {
2831
+ re += "\\\\";
2832
+ }
2833
+ const addPatternStart = addPatternStartSet[re.charAt(0)];
2834
+ for (let n = negativeLists.length - 1; n > -1; n--) {
2835
+ const nl = negativeLists[n];
2836
+ const nlBefore = re.slice(0, nl.reStart);
2837
+ const nlFirst = re.slice(nl.reStart, nl.reEnd - 8);
2838
+ let nlAfter = re.slice(nl.reEnd);
2839
+ const nlLast = re.slice(nl.reEnd - 8, nl.reEnd) + nlAfter;
2840
+ const closeParensBefore = nlBefore.split(")").length;
2841
+ const openParensBefore = nlBefore.split("(").length - closeParensBefore;
2842
+ let cleanAfter = nlAfter;
2843
+ for (let i = 0; i < openParensBefore; i++) {
2844
+ cleanAfter = cleanAfter.replace(/\)[+*?]?/, "");
2845
+ }
2846
+ nlAfter = cleanAfter;
2847
+ const dollar = nlAfter === "" ? "(?:$|\\/)" : "";
2848
+ re = nlBefore + nlFirst + nlAfter + dollar + nlLast;
2849
+ }
2850
+ if (re !== "" && hasMagic) {
2851
+ re = "(?=.)" + re;
2852
+ }
2853
+ if (addPatternStart) {
2854
+ re = patternStart() + re;
2855
+ }
2856
+ if (options.nocase && !hasMagic && !options.nocaseMagicOnly) {
2857
+ hasMagic = pattern.toUpperCase() !== pattern.toLowerCase();
2858
+ }
2859
+ if (!hasMagic) {
2860
+ return globUnescape(re);
2861
+ }
2862
+ const flags = (options.nocase ? "i" : "") + (uflag ? "u" : "");
2863
+ try {
2864
+ const ext2 = fastTest ? {
2865
+ _glob: pattern,
2866
+ _src: re,
2867
+ test: fastTest
2868
+ } : {
2869
+ _glob: pattern,
2870
+ _src: re
2871
+ };
2872
+ return Object.assign(new RegExp("^" + re + "$", flags), ext2);
2873
+ } catch (er) {
2874
+ this.debug("invalid regexp", er);
2875
+ return new RegExp("$.");
2876
+ }
2877
+ }
2878
+ makeRe() {
2879
+ if (this.regexp || this.regexp === false)
2880
+ return this.regexp;
2881
+ const set = this.set;
2882
+ if (!set.length) {
2883
+ this.regexp = false;
2884
+ return this.regexp;
2885
+ }
2886
+ const options = this.options;
2887
+ const twoStar = options.noglobstar ? star : options.dot ? twoStarDot : twoStarNoDot;
2888
+ const flags = options.nocase ? "i" : "";
2889
+ let re = set.map((pattern) => {
2890
+ const pp = pattern.map((p) => typeof p === "string" ? regExpEscape(p) : p === GLOBSTAR ? GLOBSTAR : p._src);
2891
+ pp.forEach((p, i) => {
2892
+ const next = pp[i + 1];
2893
+ const prev = pp[i - 1];
2894
+ if (p !== GLOBSTAR || prev === GLOBSTAR) {
2895
+ return;
2896
+ }
2897
+ if (prev === void 0) {
2898
+ if (next !== void 0 && next !== GLOBSTAR) {
2899
+ pp[i + 1] = "(?:\\/|" + twoStar + "\\/)?" + next;
2900
+ } else {
2901
+ pp[i] = twoStar;
2902
+ }
2903
+ } else if (next === void 0) {
2904
+ pp[i - 1] = prev + "(?:\\/|" + twoStar + ")?";
2905
+ } else if (next !== GLOBSTAR) {
2906
+ pp[i - 1] = prev + "(?:\\/|\\/" + twoStar + "\\/)" + next;
2907
+ pp[i + 1] = GLOBSTAR;
2908
+ }
2909
+ });
2910
+ return pp.filter((p) => p !== GLOBSTAR).join("/");
2911
+ }).join("|");
2912
+ re = "^(?:" + re + ")$";
2913
+ if (this.negate)
2914
+ re = "^(?!" + re + ").*$";
2915
+ try {
2916
+ this.regexp = new RegExp(re, flags);
2917
+ } catch (ex) {
2918
+ this.regexp = false;
2919
+ }
2920
+ return this.regexp;
2921
+ }
2922
+ slashSplit(p) {
2923
+ if (this.preserveMultipleSlashes) {
2924
+ return p.split("/");
2925
+ } else if (this.isWindows && /^\/\/[^\/]+/.test(p)) {
2926
+ return ["", ...p.split(/\/+/)];
2927
+ } else {
2928
+ return p.split(/\/+/);
2929
+ }
2930
+ }
2931
+ match(f, partial = this.partial) {
2932
+ this.debug("match", f, this.pattern);
2933
+ if (this.comment) {
2934
+ return false;
2935
+ }
2936
+ if (this.empty) {
2937
+ return f === "";
2938
+ }
2939
+ if (f === "/" && partial) {
2940
+ return true;
2941
+ }
2942
+ const options = this.options;
2943
+ if (this.isWindows) {
2944
+ f = f.split("\\").join("/");
2945
+ }
2946
+ const ff = this.slashSplit(f);
2947
+ this.debug(this.pattern, "split", ff);
2948
+ const set = this.set;
2949
+ this.debug(this.pattern, "set", set);
2950
+ let filename = ff[ff.length - 1];
2951
+ if (!filename) {
2952
+ for (let i = ff.length - 2; !filename && i >= 0; i--) {
2953
+ filename = ff[i];
2954
+ }
2955
+ }
2956
+ for (let i = 0; i < set.length; i++) {
2957
+ const pattern = set[i];
2958
+ let file = ff;
2959
+ if (options.matchBase && pattern.length === 1) {
2960
+ file = [filename];
2961
+ }
2962
+ const hit = this.matchOne(file, pattern, partial);
2963
+ if (hit) {
2964
+ if (options.flipNegate) {
2965
+ return true;
2966
+ }
2967
+ return !this.negate;
2968
+ }
2969
+ }
2970
+ if (options.flipNegate) {
2971
+ return false;
2972
+ }
2973
+ return this.negate;
2974
+ }
2975
+ static defaults(def) {
2976
+ return minimatch.defaults(def).Minimatch;
2977
+ }
2978
+ };
2979
+ minimatch.Minimatch = Minimatch;
2980
+ minimatch.escape = escape;
2981
+ minimatch.unescape = unescape;
2982
+
2983
+ // src/cli/commands/pgIntrospect.ts
2984
+ var pgPushIntrospect = async (connection, filters, schemaFilters) => {
2985
+ const { client } = connection;
2986
+ const matchers = filters.map((it) => {
2987
+ return new Minimatch(it);
2988
+ });
2989
+ const filter2 = (tableName) => {
2990
+ if (matchers.length === 0)
2991
+ return true;
2992
+ for (let i = 0; i < matchers.length; i++) {
2993
+ const matcher = matchers[i];
2994
+ if (matcher.match(tableName))
2995
+ return true;
2996
+ }
2997
+ return false;
2998
+ };
2999
+ const res = await fromDatabase(client, filter2, schemaFilters);
3000
+ const schema = { id: originUUID, prevId: "", ...res };
3001
+ const { internal, ...schemaWithoutInternals } = schema;
3002
+ return { schema: schemaWithoutInternals };
3003
+ };
3004
+ // Annotate the CommonJS export names for ESM import in node:
3005
+ 0 && (module.exports = {
3006
+ drizzleSchemaPg,
3007
+ pgPushIntrospect
3008
+ });