@oliasoft-open-source/node-json-migrator 5.5.0 → 5.6.0-beta-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,8 +1,5 @@
1
1
  import path from "path";
2
2
  import { lstatSync, promises, readdir, readdirSync, readlinkSync, realpathSync } from "fs";
3
- import process$1 from "node:process";
4
- import os from "node:os";
5
- import tty from "node:tty";
6
3
  import vm from "node:vm";
7
4
  import { produce } from "immer";
8
5
  import { createHash } from "crypto";
@@ -13,1148 +10,463 @@ import { lstat, readdir as readdir$1, readlink, realpath } from "node:fs/promise
13
10
  import { EventEmitter } from "node:events";
14
11
  import Pe from "node:stream";
15
12
  import { StringDecoder } from "node:string_decoder";
13
+ import process$1 from "node:process";
14
+ import os from "node:os";
15
+ import tty from "node:tty";
16
16
  import process$2 from "process";
17
17
  import { execSync, spawn } from "child_process";
18
- //#region node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.js
19
- const ANSI_BACKGROUND_OFFSET = 10;
20
- const wrapAnsi16 = (offset = 0) => (code) => `\u001B[${code + offset}m`;
21
- const wrapAnsi256 = (offset = 0) => (code) => `\u001B[${38 + offset};5;${code}m`;
22
- const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u001B[${38 + offset};2;${red};${green};${blue}m`;
23
- const styles$1 = {
24
- modifier: {
25
- reset: [0, 0],
26
- bold: [1, 22],
27
- dim: [2, 22],
28
- italic: [3, 23],
29
- underline: [4, 24],
30
- overline: [53, 55],
31
- inverse: [7, 27],
32
- hidden: [8, 28],
33
- strikethrough: [9, 29]
34
- },
35
- color: {
36
- black: [30, 39],
37
- red: [31, 39],
38
- green: [32, 39],
39
- yellow: [33, 39],
40
- blue: [34, 39],
41
- magenta: [35, 39],
42
- cyan: [36, 39],
43
- white: [37, 39],
44
- blackBright: [90, 39],
45
- gray: [90, 39],
46
- grey: [90, 39],
47
- redBright: [91, 39],
48
- greenBright: [92, 39],
49
- yellowBright: [93, 39],
50
- blueBright: [94, 39],
51
- magentaBright: [95, 39],
52
- cyanBright: [96, 39],
53
- whiteBright: [97, 39]
54
- },
55
- bgColor: {
56
- bgBlack: [40, 49],
57
- bgRed: [41, 49],
58
- bgGreen: [42, 49],
59
- bgYellow: [43, 49],
60
- bgBlue: [44, 49],
61
- bgMagenta: [45, 49],
62
- bgCyan: [46, 49],
63
- bgWhite: [47, 49],
64
- bgBlackBright: [100, 49],
65
- bgGray: [100, 49],
66
- bgGrey: [100, 49],
67
- bgRedBright: [101, 49],
68
- bgGreenBright: [102, 49],
69
- bgYellowBright: [103, 49],
70
- bgBlueBright: [104, 49],
71
- bgMagentaBright: [105, 49],
72
- bgCyanBright: [106, 49],
73
- bgWhiteBright: [107, 49]
74
- }
75
- };
76
- Object.keys(styles$1.modifier);
77
- const foregroundColorNames = Object.keys(styles$1.color);
78
- const backgroundColorNames = Object.keys(styles$1.bgColor);
79
- [...foregroundColorNames, ...backgroundColorNames];
80
- function assembleStyles() {
81
- const codes = /* @__PURE__ */ new Map();
82
- for (const [groupName, group] of Object.entries(styles$1)) {
83
- for (const [styleName, style] of Object.entries(group)) {
84
- styles$1[styleName] = {
85
- open: `\u001B[${style[0]}m`,
86
- close: `\u001B[${style[1]}m`
87
- };
88
- group[styleName] = styles$1[styleName];
89
- codes.set(style[0], style[1]);
90
- }
91
- Object.defineProperty(styles$1, groupName, {
92
- value: group,
93
- enumerable: false
94
- });
95
- }
96
- Object.defineProperty(styles$1, "codes", {
97
- value: codes,
98
- enumerable: false
99
- });
100
- styles$1.color.close = "\x1B[39m";
101
- styles$1.bgColor.close = "\x1B[49m";
102
- styles$1.color.ansi = wrapAnsi16();
103
- styles$1.color.ansi256 = wrapAnsi256();
104
- styles$1.color.ansi16m = wrapAnsi16m();
105
- styles$1.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
106
- styles$1.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
107
- styles$1.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
108
- Object.defineProperties(styles$1, {
109
- rgbToAnsi256: {
110
- value(red, green, blue) {
111
- if (red === green && green === blue) {
112
- if (red < 8) return 16;
113
- if (red > 248) return 231;
114
- return Math.round((red - 8) / 247 * 24) + 232;
115
- }
116
- return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
117
- },
118
- enumerable: false
119
- },
120
- hexToRgb: {
121
- value(hex) {
122
- const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
123
- if (!matches) return [
124
- 0,
125
- 0,
126
- 0
127
- ];
128
- let [colorString] = matches;
129
- if (colorString.length === 3) colorString = [...colorString].map((character) => character + character).join("");
130
- const integer = Number.parseInt(colorString, 16);
131
- return [
132
- integer >> 16 & 255,
133
- integer >> 8 & 255,
134
- integer & 255
135
- ];
136
- },
137
- enumerable: false
138
- },
139
- hexToAnsi256: {
140
- value: (hex) => styles$1.rgbToAnsi256(...styles$1.hexToRgb(hex)),
141
- enumerable: false
142
- },
143
- ansi256ToAnsi: {
144
- value(code) {
145
- if (code < 8) return 30 + code;
146
- if (code < 16) return 90 + (code - 8);
147
- let red;
148
- let green;
149
- let blue;
150
- if (code >= 232) {
151
- red = ((code - 232) * 10 + 8) / 255;
152
- green = red;
153
- blue = red;
154
- } else {
155
- code -= 16;
156
- const remainder = code % 36;
157
- red = Math.floor(code / 36) / 5;
158
- green = Math.floor(remainder / 6) / 5;
159
- blue = remainder % 6 / 5;
160
- }
161
- const value = Math.max(red, green, blue) * 2;
162
- if (value === 0) return 30;
163
- let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
164
- if (value === 2) result += 60;
165
- return result;
166
- },
167
- enumerable: false
168
- },
169
- rgbToAnsi: {
170
- value: (red, green, blue) => styles$1.ansi256ToAnsi(styles$1.rgbToAnsi256(red, green, blue)),
171
- enumerable: false
172
- },
173
- hexToAnsi: {
174
- value: (hex) => styles$1.ansi256ToAnsi(styles$1.hexToAnsi256(hex)),
175
- enumerable: false
18
+ //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/array/difference.mjs
19
+ function difference(firstArr, secondArr) {
20
+ const secondSet = new Set(secondArr);
21
+ return firstArr.filter((item) => !secondSet.has(item));
22
+ }
23
+ //#endregion
24
+ //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/array/flatten.mjs
25
+ function flatten(arr, depth = 1) {
26
+ const result = [];
27
+ const flooredDepth = Math.floor(depth);
28
+ const recursive = (arr, currentDepth) => {
29
+ for (let i = 0; i < arr.length; i++) {
30
+ const item = arr[i];
31
+ if (Array.isArray(item) && currentDepth < flooredDepth) recursive(item, currentDepth + 1);
32
+ else result.push(item);
176
33
  }
177
- });
178
- return styles$1;
34
+ };
35
+ recursive(arr, 0);
36
+ return result;
179
37
  }
180
- const ansiStyles = assembleStyles();
181
38
  //#endregion
182
- //#region node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/supports-color/index.js
183
- function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process$1.argv) {
184
- const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
185
- const position = argv.indexOf(prefix + flag);
186
- const terminatorPosition = argv.indexOf("--");
187
- return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
39
+ //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/array/intersection.mjs
40
+ function intersection(firstArr, secondArr) {
41
+ const secondSet = new Set(secondArr);
42
+ return firstArr.filter((item) => secondSet.has(item));
188
43
  }
189
- const { env } = process$1;
190
- let flagForceColor;
191
- if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) flagForceColor = 0;
192
- else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) flagForceColor = 1;
193
- function envForceColor() {
194
- if ("FORCE_COLOR" in env) {
195
- if (env.FORCE_COLOR === "true") return 1;
196
- if (env.FORCE_COLOR === "false") return 0;
197
- return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
198
- }
44
+ //#endregion
45
+ //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/compat/predicate/isSymbol.mjs
46
+ function isSymbol(value) {
47
+ return typeof value === "symbol" || value instanceof Symbol;
199
48
  }
200
- function translateLevel(level) {
201
- if (level === 0) return false;
202
- return {
203
- level,
204
- hasBasic: true,
205
- has256: level >= 2,
206
- has16m: level >= 3
49
+ //#endregion
50
+ //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/array/uniq.mjs
51
+ function uniq(arr) {
52
+ return [...new Set(arr)];
53
+ }
54
+ //#endregion
55
+ //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/array/union.mjs
56
+ function union(arr1, arr2) {
57
+ return uniq(arr1.concat(arr2));
58
+ }
59
+ //#endregion
60
+ //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/array/xor.mjs
61
+ function xor(arr1, arr2) {
62
+ return difference(union(arr1, arr2), intersection(arr1, arr2));
63
+ }
64
+ //#endregion
65
+ //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/function/memoize.mjs
66
+ function memoize(fn, options = {}) {
67
+ const { cache = /* @__PURE__ */ new Map(), getCacheKey } = options;
68
+ const memoizedFn = function(arg) {
69
+ const key = getCacheKey ? getCacheKey(arg) : arg;
70
+ if (cache.has(key)) return cache.get(key);
71
+ const result = fn.call(this, arg);
72
+ cache.set(key, result);
73
+ return result;
207
74
  };
75
+ memoizedFn.cache = cache;
76
+ return memoizedFn;
208
77
  }
209
- function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
210
- const noFlagForceColor = envForceColor();
211
- if (noFlagForceColor !== void 0) flagForceColor = noFlagForceColor;
212
- const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
213
- if (forceColor === 0) return 0;
214
- if (sniffFlags) {
215
- if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) return 3;
216
- if (hasFlag("color=256")) return 2;
217
- }
218
- if ("TF_BUILD" in env && "AGENT_NAME" in env) return 1;
219
- if (haveStream && !streamIsTTY && forceColor === void 0) return 0;
220
- const min = forceColor || 0;
221
- if (env.TERM === "dumb") return min;
222
- if (process$1.platform === "win32") {
223
- const osRelease = os.release().split(".");
224
- if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) return Number(osRelease[2]) >= 14931 ? 3 : 2;
225
- return 1;
226
- }
227
- if ("CI" in env) {
228
- if ([
229
- "GITHUB_ACTIONS",
230
- "GITEA_ACTIONS",
231
- "CIRCLECI"
232
- ].some((key) => key in env)) return 3;
233
- if ([
234
- "TRAVIS",
235
- "APPVEYOR",
236
- "GITLAB_CI",
237
- "BUILDKITE",
238
- "DRONE"
239
- ].some((sign) => sign in env) || env.CI_NAME === "codeship") return 1;
240
- return min;
241
- }
242
- if ("TEAMCITY_VERSION" in env) return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
243
- if (env.COLORTERM === "truecolor") return 3;
244
- if (env.TERM === "xterm-kitty") return 3;
245
- if (env.TERM === "xterm-ghostty") return 3;
246
- if (env.TERM === "wezterm") return 3;
247
- if ("TERM_PROGRAM" in env) {
248
- const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
249
- switch (env.TERM_PROGRAM) {
250
- case "iTerm.app": return version >= 3 ? 3 : 2;
251
- case "Apple_Terminal": return 2;
252
- }
253
- }
254
- if (/-256(color)?$/i.test(env.TERM)) return 2;
255
- if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) return 1;
256
- if ("COLORTERM" in env) return 1;
257
- return min;
258
- }
259
- function createSupportsColor(stream, options = {}) {
260
- return translateLevel(_supportsColor(stream, {
261
- streamIsTTY: stream && stream.isTTY,
262
- ...options
263
- }));
264
- }
265
- const supportsColor = {
266
- stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
267
- stderr: createSupportsColor({ isTTY: tty.isatty(2) })
268
- };
269
78
  //#endregion
270
- //#region node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/utilities.js
271
- function stringReplaceAll(string, substring, replacer) {
272
- let index = string.indexOf(substring);
273
- if (index === -1) return string;
274
- const substringLength = substring.length;
275
- let endIndex = 0;
276
- let returnValue = "";
277
- do {
278
- returnValue += string.slice(endIndex, index) + substring + replacer;
279
- endIndex = index + substringLength;
280
- index = string.indexOf(substring, endIndex);
281
- } while (index !== -1);
282
- returnValue += string.slice(endIndex);
283
- return returnValue;
284
- }
285
- function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
286
- let endIndex = 0;
287
- let returnValue = "";
288
- do {
289
- const gotCR = string[index - 1] === "\r";
290
- returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
291
- endIndex = index + 1;
292
- index = string.indexOf("\n", endIndex);
293
- } while (index !== -1);
294
- returnValue += string.slice(endIndex);
295
- return returnValue;
79
+ //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/function/noop.mjs
80
+ function noop() {}
81
+ //#endregion
82
+ //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/predicate/isPlainObject.mjs
83
+ function isPlainObject(value) {
84
+ if (!value || typeof value !== "object") return false;
85
+ const proto = Object.getPrototypeOf(value);
86
+ if (!(proto === null || proto === Object.prototype || Object.getPrototypeOf(proto) === null)) return false;
87
+ return Object.prototype.toString.call(value) === "[object Object]";
296
88
  }
297
89
  //#endregion
298
- //#region node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/index.js
299
- const { stdout: stdoutColor, stderr: stderrColor } = supportsColor;
300
- const GENERATOR = Symbol("GENERATOR");
301
- const STYLER = Symbol("STYLER");
302
- const IS_EMPTY = Symbol("IS_EMPTY");
303
- const levelMapping = [
304
- "ansi",
305
- "ansi",
306
- "ansi256",
307
- "ansi16m"
308
- ];
309
- const styles = Object.create(null);
310
- const applyOptions = (object, options = {}) => {
311
- if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) throw new Error("The `level` option should be an integer from 0 to 3");
312
- const colorLevel = stdoutColor ? stdoutColor.level : 0;
313
- object.level = options.level === void 0 ? colorLevel : options.level;
314
- };
315
- const chalkFactory = (options) => {
316
- const chalk = (...strings) => strings.join(" ");
317
- applyOptions(chalk, options);
318
- Object.setPrototypeOf(chalk, createChalk.prototype);
319
- return chalk;
320
- };
321
- function createChalk(options) {
322
- return chalkFactory(options);
90
+ //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/_internal/isUnsafeProperty.mjs
91
+ function isUnsafeProperty(key) {
92
+ return key === "__proto__";
323
93
  }
324
- Object.setPrototypeOf(createChalk.prototype, Function.prototype);
325
- for (const [styleName, style] of Object.entries(ansiStyles)) styles[styleName] = { get() {
326
- const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
327
- Object.defineProperty(this, styleName, { value: builder });
328
- return builder;
329
- } };
330
- styles.visible = { get() {
331
- const builder = createBuilder(this, this[STYLER], true);
332
- Object.defineProperty(this, "visible", { value: builder });
333
- return builder;
334
- } };
335
- const getModelAnsi = (model, level, type, ...arguments_) => {
336
- if (model === "rgb") {
337
- if (level === "ansi16m") return ansiStyles[type].ansi16m(...arguments_);
338
- if (level === "ansi256") return ansiStyles[type].ansi256(ansiStyles.rgbToAnsi256(...arguments_));
339
- return ansiStyles[type].ansi(ansiStyles.rgbToAnsi(...arguments_));
94
+ //#endregion
95
+ //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/object/merge.mjs
96
+ function merge(target, source) {
97
+ const sourceKeys = Object.keys(source);
98
+ for (let i = 0; i < sourceKeys.length; i++) {
99
+ const key = sourceKeys[i];
100
+ if (isUnsafeProperty(key)) continue;
101
+ const sourceValue = source[key];
102
+ const targetValue = target[key];
103
+ if (isMergeableValue(sourceValue) && isMergeableValue(targetValue)) target[key] = merge(targetValue, sourceValue);
104
+ else if (Array.isArray(sourceValue)) target[key] = merge([], sourceValue);
105
+ else if (isPlainObject(sourceValue)) target[key] = merge({}, sourceValue);
106
+ else if (targetValue === void 0 || sourceValue !== void 0) target[key] = sourceValue;
340
107
  }
341
- if (model === "hex") return getModelAnsi("rgb", level, type, ...ansiStyles.hexToRgb(...arguments_));
342
- return ansiStyles[type][model](...arguments_);
343
- };
344
- for (const model of [
345
- "rgb",
346
- "hex",
347
- "ansi256"
348
- ]) {
349
- styles[model] = { get() {
350
- const { level } = this;
351
- return function(...arguments_) {
352
- const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansiStyles.color.close, this[STYLER]);
353
- return createBuilder(this, styler, this[IS_EMPTY]);
354
- };
355
- } };
356
- const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
357
- styles[bgModel] = { get() {
358
- const { level } = this;
359
- return function(...arguments_) {
360
- const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansiStyles.bgColor.close, this[STYLER]);
361
- return createBuilder(this, styler, this[IS_EMPTY]);
362
- };
363
- } };
108
+ return target;
364
109
  }
365
- const proto = Object.defineProperties(() => {}, {
366
- ...styles,
367
- level: {
368
- enumerable: true,
369
- get() {
370
- return this[GENERATOR].level;
371
- },
372
- set(level) {
373
- this[GENERATOR].level = level;
374
- }
375
- }
376
- });
377
- const createStyler = (open, close, parent) => {
378
- let openAll;
379
- let closeAll;
380
- if (parent === void 0) {
381
- openAll = open;
382
- closeAll = close;
383
- } else {
384
- openAll = parent.openAll + open;
385
- closeAll = close + parent.closeAll;
386
- }
387
- return {
388
- open,
389
- close,
390
- openAll,
391
- closeAll,
392
- parent
393
- };
394
- };
395
- const createBuilder = (self, _styler, _isEmpty) => {
396
- const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
397
- Object.setPrototypeOf(builder, proto);
398
- builder[GENERATOR] = self;
399
- builder[STYLER] = _styler;
400
- builder[IS_EMPTY] = _isEmpty;
401
- return builder;
402
- };
403
- const applyStyle = (self, string) => {
404
- if (self.level <= 0 || !string) return self[IS_EMPTY] ? "" : string;
405
- let styler = self[STYLER];
406
- if (styler === void 0) return string;
407
- const { openAll, closeAll } = styler;
408
- if (string.includes("\x1B")) while (styler !== void 0) {
409
- string = stringReplaceAll(string, styler.close, styler.open);
410
- styler = styler.parent;
411
- }
412
- const lfIndex = string.indexOf("\n");
413
- if (lfIndex !== -1) string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
414
- return openAll + string + closeAll;
415
- };
416
- Object.defineProperties(createChalk.prototype, styles);
417
- const chalk = createChalk();
418
- createChalk({ level: stderrColor ? stderrColor.level : 0 });
419
- //#endregion
420
- //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/array/difference.mjs
421
- function difference(firstArr, secondArr) {
422
- const secondSet = new Set(secondArr);
423
- return firstArr.filter((item) => !secondSet.has(item));
110
+ function isMergeableValue(value) {
111
+ return isPlainObject(value) || Array.isArray(value);
424
112
  }
425
113
  //#endregion
426
- //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/array/flatten.mjs
427
- function flatten(arr, depth = 1) {
428
- const result = [];
429
- const flooredDepth = Math.floor(depth);
430
- const recursive = (arr, currentDepth) => {
431
- for (let i = 0; i < arr.length; i++) {
432
- const item = arr[i];
433
- if (Array.isArray(item) && currentDepth < flooredDepth) recursive(item, currentDepth + 1);
434
- else result.push(item);
435
- }
436
- };
437
- recursive(arr, 0);
114
+ //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/object/omit.mjs
115
+ function omit(obj, keys) {
116
+ const result = { ...obj };
117
+ for (let i = 0; i < keys.length; i++) {
118
+ const key = keys[i];
119
+ delete result[key];
120
+ }
438
121
  return result;
439
122
  }
440
123
  //#endregion
441
- //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/array/intersection.mjs
442
- function intersection(firstArr, secondArr) {
443
- const secondSet = new Set(secondArr);
444
- return firstArr.filter((item) => secondSet.has(item));
124
+ //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/_internal/isEqualsSameValueZero.mjs
125
+ function isEqualsSameValueZero(value, other) {
126
+ return value === other || Number.isNaN(value) && Number.isNaN(other);
445
127
  }
446
128
  //#endregion
447
- //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/compat/predicate/isSymbol.mjs
448
- function isSymbol(value) {
449
- return typeof value === "symbol" || value instanceof Symbol;
129
+ //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/predicate/isLength.mjs
130
+ function isLength(value) {
131
+ return Number.isSafeInteger(value) && value >= 0;
450
132
  }
451
133
  //#endregion
452
- //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/array/uniq.mjs
453
- function uniq(arr) {
454
- return [...new Set(arr)];
134
+ //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/predicate/isString.mjs
135
+ function isString(value) {
136
+ return typeof value === "string";
455
137
  }
456
138
  //#endregion
457
- //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/array/union.mjs
458
- function union(arr1, arr2) {
459
- return uniq(arr1.concat(arr2));
460
- }
139
+ //#region src/plan/loader-module.ts
140
+ const lazyImportMigration = (script) => {
141
+ if (!script) return noop;
142
+ const patchedScript = script.replace(/import\s+\{?\s*produce\s*}?\s+from\s+['"]immer['"];?/, "").replace(/export\s+default\s+/, "const migration = ").replace(/export\s+(const|function|async function)\s+/g, "$1 ");
143
+ return (payload, metaData) => {
144
+ const context = {
145
+ payload,
146
+ metaData,
147
+ produce
148
+ };
149
+ return vm.runInNewContext(`${patchedScript}; migration(payload, metaData);`, context);
150
+ };
151
+ };
152
+ const LoaderModule = { lazyImportMigration };
461
153
  //#endregion
462
- //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/array/xor.mjs
463
- function xor(arr1, arr2) {
464
- return difference(union(arr1, arr2), intersection(arr1, arr2));
465
- }
154
+ //#region src/hash/hash.ts
155
+ /**
156
+ * Generate SHA256 hash from a string
157
+ */
158
+ const hash = (string) => createHash("sha256").update(string).digest("hex");
466
159
  //#endregion
467
- //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/function/memoize.mjs
468
- function memoize(fn, options = {}) {
469
- const { cache = /* @__PURE__ */ new Map(), getCacheKey } = options;
470
- const memoizedFn = function(arg) {
471
- const key = getCacheKey ? getCacheKey(arg) : arg;
472
- if (cache.has(key)) return cache.get(key);
473
- const result = fn.call(this, arg);
474
- cache.set(key, result);
475
- return result;
160
+ //#region node_modules/.pnpm/glob@13.0.6/node_modules/glob/dist/esm/index.min.js
161
+ var Gt = (n, t, e) => {
162
+ let s = n instanceof RegExp ? ce(n, e) : n, i = t instanceof RegExp ? ce(t, e) : t, r = s !== null && i != null && ss(s, i, e);
163
+ return r && {
164
+ start: r[0],
165
+ end: r[1],
166
+ pre: e.slice(0, r[0]),
167
+ body: e.slice(r[0] + s.length, r[1]),
168
+ post: e.slice(r[1] + i.length)
476
169
  };
477
- memoizedFn.cache = cache;
478
- return memoizedFn;
170
+ }, ce = (n, t) => {
171
+ let e = t.match(n);
172
+ return e ? e[0] : null;
173
+ }, ss = (n, t, e) => {
174
+ let s, i, r, o, h, a = e.indexOf(n), l = e.indexOf(t, a + 1), u = a;
175
+ if (a >= 0 && l > 0) {
176
+ if (n === t) return [a, l];
177
+ for (s = [], r = e.length; u >= 0 && !h;) {
178
+ if (u === a) s.push(u), a = e.indexOf(n, u + 1);
179
+ else if (s.length === 1) {
180
+ let c = s.pop();
181
+ c !== void 0 && (h = [c, l]);
182
+ } else i = s.pop(), i !== void 0 && i < r && (r = i, o = l), l = e.indexOf(t, u + 1);
183
+ u = a < l && a >= 0 ? a : l;
184
+ }
185
+ s.length && o !== void 0 && (h = [r, o]);
186
+ }
187
+ return h;
188
+ };
189
+ var fe = "\0SLASH" + Math.random() + "\0", ue = "\0OPEN" + Math.random() + "\0", qt = "\0CLOSE" + Math.random() + "\0", de = "\0COMMA" + Math.random() + "\0", pe = "\0PERIOD" + Math.random() + "\0", is = new RegExp(fe, "g"), rs = new RegExp(ue, "g"), ns = new RegExp(qt, "g"), os$1 = new RegExp(de, "g"), hs = new RegExp(pe, "g"), as = /\\\\/g, ls = /\\{/g, cs = /\\}/g, fs = /\\,/g, us = /\\./g, ds = 1e5;
190
+ function Ht(n) {
191
+ return isNaN(n) ? n.charCodeAt(0) : parseInt(n, 10);
479
192
  }
480
- //#endregion
481
- //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/function/noop.mjs
482
- function noop() {}
483
- //#endregion
484
- //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/predicate/isPlainObject.mjs
485
- function isPlainObject(value) {
486
- if (!value || typeof value !== "object") return false;
487
- const proto = Object.getPrototypeOf(value);
488
- if (!(proto === null || proto === Object.prototype || Object.getPrototypeOf(proto) === null)) return false;
489
- return Object.prototype.toString.call(value) === "[object Object]";
193
+ function ps(n) {
194
+ return n.replace(as, fe).replace(ls, ue).replace(cs, qt).replace(fs, de).replace(us, pe);
490
195
  }
491
- //#endregion
492
- //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/_internal/isUnsafeProperty.mjs
493
- function isUnsafeProperty(key) {
494
- return key === "__proto__";
196
+ function ms(n) {
197
+ return n.replace(is, "\\").replace(rs, "{").replace(ns, "}").replace(os$1, ",").replace(hs, ".");
495
198
  }
496
- //#endregion
497
- //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/object/merge.mjs
498
- function merge(target, source) {
499
- const sourceKeys = Object.keys(source);
500
- for (let i = 0; i < sourceKeys.length; i++) {
501
- const key = sourceKeys[i];
502
- if (isUnsafeProperty(key)) continue;
503
- const sourceValue = source[key];
504
- const targetValue = target[key];
505
- if (isMergeableValue(sourceValue) && isMergeableValue(targetValue)) target[key] = merge(targetValue, sourceValue);
506
- else if (Array.isArray(sourceValue)) target[key] = merge([], sourceValue);
507
- else if (isPlainObject(sourceValue)) target[key] = merge({}, sourceValue);
508
- else if (targetValue === void 0 || sourceValue !== void 0) target[key] = sourceValue;
509
- }
510
- return target;
199
+ function me(n) {
200
+ if (!n) return [""];
201
+ let t = [], e = Gt("{", "}", n);
202
+ if (!e) return n.split(",");
203
+ let { pre: s, body: i, post: r } = e, o = s.split(",");
204
+ o[o.length - 1] += "{" + i + "}";
205
+ let h = me(r);
206
+ return r.length && (o[o.length - 1] += h.shift(), o.push.apply(o, h)), t.push.apply(t, o), t;
511
207
  }
512
- function isMergeableValue(value) {
513
- return isPlainObject(value) || Array.isArray(value);
208
+ function ge(n, t = {}) {
209
+ if (!n) return [];
210
+ let { max: e = ds } = t;
211
+ return n.slice(0, 2) === "{}" && (n = "\\{\\}" + n.slice(2)), ht(ps(n), e, !0).map(ms);
514
212
  }
515
- //#endregion
516
- //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/object/omit.mjs
517
- function omit(obj, keys) {
518
- const result = { ...obj };
519
- for (let i = 0; i < keys.length; i++) {
520
- const key = keys[i];
521
- delete result[key];
522
- }
523
- return result;
213
+ function gs(n) {
214
+ return "{" + n + "}";
524
215
  }
525
- //#endregion
526
- //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/_internal/isEqualsSameValueZero.mjs
527
- function isEqualsSameValueZero(value, other) {
528
- return value === other || Number.isNaN(value) && Number.isNaN(other);
216
+ function ws(n) {
217
+ return /^-?0\d/.test(n);
529
218
  }
530
- //#endregion
531
- //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/predicate/isLength.mjs
532
- function isLength(value) {
533
- return Number.isSafeInteger(value) && value >= 0;
219
+ function ys(n, t) {
220
+ return n <= t;
534
221
  }
535
- //#endregion
536
- //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/predicate/isString.mjs
537
- function isString(value) {
538
- return typeof value === "string";
222
+ function bs(n, t) {
223
+ return n >= t;
539
224
  }
540
- //#endregion
541
- //#region src/validator/ajv-validators.ts
542
- const planSchemaValidator = validate14;
543
- const schema32 = {
544
- "type": "array",
545
- "items": {
546
- "type": "object",
547
- "properties": {
548
- "fileHash": { "type": ["string"] },
549
- "fileName": { "type": "string" },
550
- "sequence": {
551
- "type": "string",
552
- "pattern": "^[1-9][0-9]*(.[1-9][0-9]*)*$"
225
+ function ht(n, t, e) {
226
+ let s = [], i = Gt("{", "}", n);
227
+ if (!i) return [n];
228
+ let r = i.pre, o = i.post.length ? ht(i.post, t, !1) : [""];
229
+ if (/\$$/.test(i.pre)) for (let h = 0; h < o.length && h < t; h++) {
230
+ let a = r + "{" + i.body + "}" + o[h];
231
+ s.push(a);
232
+ }
233
+ else {
234
+ let h = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(i.body), a = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(i.body), l = h || a, u = i.body.indexOf(",") >= 0;
235
+ if (!l && !u) return i.post.match(/,(?!,).*\}/) ? (n = i.pre + "{" + i.body + qt + i.post, ht(n, t, !0)) : [n];
236
+ let c;
237
+ if (l) c = i.body.split(/\.\./);
238
+ else if (c = me(i.body), c.length === 1 && c[0] !== void 0 && (c = ht(c[0], t, !1).map(gs), c.length === 1)) return o.map((f) => i.pre + c[0] + f);
239
+ let d;
240
+ if (l && c[0] !== void 0 && c[1] !== void 0) {
241
+ let f = Ht(c[0]), m = Ht(c[1]), p = Math.max(c[0].length, c[1].length), w = c.length === 3 && c[2] !== void 0 ? Math.abs(Ht(c[2])) : 1, g = ys;
242
+ m < f && (w *= -1, g = bs);
243
+ let E = c.some(ws);
244
+ d = [];
245
+ for (let y = f; g(y, m); y += w) {
246
+ let b;
247
+ if (a) b = String.fromCharCode(y), b === "\\" && (b = "");
248
+ else if (b = String(y), E) {
249
+ let z = p - b.length;
250
+ if (z > 0) {
251
+ let $ = new Array(z + 1).join("0");
252
+ y < 0 ? b = "-" + $ + b.slice(1) : b = $ + b;
253
+ }
254
+ }
255
+ d.push(b);
553
256
  }
554
- },
555
- "required": [
556
- "fileHash",
557
- "fileName",
558
- "sequence"
559
- ],
560
- "additionalProperties": false
257
+ } else {
258
+ d = [];
259
+ for (let f = 0; f < c.length; f++) d.push.apply(d, ht(c[f], t, !1));
260
+ }
261
+ for (let f = 0; f < d.length; f++) for (let m = 0; m < o.length && s.length < t; m++) {
262
+ let p = r + d[f] + o[m];
263
+ (!e || l || p) && s.push(p);
264
+ }
561
265
  }
266
+ return s;
267
+ }
268
+ var at = (n) => {
269
+ if (typeof n != "string") throw new TypeError("invalid pattern");
270
+ if (n.length > 65536) throw new TypeError("pattern is too long");
562
271
  };
563
- const pattern0 = /* @__PURE__ */ new RegExp("^[1-9][0-9]*(.[1-9][0-9]*)*$", "u");
564
- function validate14(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
565
- let vErrors = null;
566
- let errors = 0;
567
- if (Array.isArray(data)) {
568
- const len0 = data.length;
569
- for (let i0 = 0; i0 < len0; i0++) {
570
- let data0 = data[i0];
571
- if (data0 && typeof data0 == "object" && !Array.isArray(data0)) {
572
- if (data0.fileHash === void 0) {
573
- const err0 = {
574
- instancePath: instancePath + "/" + i0,
575
- schemaPath: "#/items/required",
576
- keyword: "required",
577
- params: { missingProperty: "fileHash" },
578
- message: "must have required property 'fileHash'"
579
- };
580
- if (vErrors === null) vErrors = [err0];
581
- else vErrors.push(err0);
582
- errors++;
583
- }
584
- if (data0.fileName === void 0) {
585
- const err1 = {
586
- instancePath: instancePath + "/" + i0,
587
- schemaPath: "#/items/required",
588
- keyword: "required",
589
- params: { missingProperty: "fileName" },
590
- message: "must have required property 'fileName'"
591
- };
592
- if (vErrors === null) vErrors = [err1];
593
- else vErrors.push(err1);
594
- errors++;
595
- }
596
- if (data0.sequence === void 0) {
597
- const err2 = {
598
- instancePath: instancePath + "/" + i0,
599
- schemaPath: "#/items/required",
600
- keyword: "required",
601
- params: { missingProperty: "sequence" },
602
- message: "must have required property 'sequence'"
603
- };
604
- if (vErrors === null) vErrors = [err2];
605
- else vErrors.push(err2);
606
- errors++;
607
- }
608
- for (const key0 in data0) if (!(key0 === "fileHash" || key0 === "fileName" || key0 === "sequence")) {
609
- const err3 = {
610
- instancePath: instancePath + "/" + i0,
611
- schemaPath: "#/items/additionalProperties",
612
- keyword: "additionalProperties",
613
- params: { additionalProperty: key0 },
614
- message: "must NOT have additional properties"
615
- };
616
- if (vErrors === null) vErrors = [err3];
617
- else vErrors.push(err3);
618
- errors++;
619
- }
620
- if (data0.fileHash !== void 0) {
621
- if (typeof data0.fileHash !== "string") {
622
- const err4 = {
623
- instancePath: instancePath + "/" + i0 + "/fileHash",
624
- schemaPath: "#/items/properties/fileHash/type",
625
- keyword: "type",
626
- params: { type: schema32.items.properties.fileHash.type },
627
- message: "must be string"
628
- };
629
- if (vErrors === null) vErrors = [err4];
630
- else vErrors.push(err4);
631
- errors++;
632
- }
633
- }
634
- if (data0.fileName !== void 0) {
635
- if (typeof data0.fileName !== "string") {
636
- const err5 = {
637
- instancePath: instancePath + "/" + i0 + "/fileName",
638
- schemaPath: "#/items/properties/fileName/type",
639
- keyword: "type",
640
- params: { type: "string" },
641
- message: "must be string"
642
- };
643
- if (vErrors === null) vErrors = [err5];
644
- else vErrors.push(err5);
645
- errors++;
646
- }
647
- }
648
- if (data0.sequence !== void 0) {
649
- let data3 = data0.sequence;
650
- if (typeof data3 === "string") {
651
- if (!pattern0.test(data3)) {
652
- const err6 = {
653
- instancePath: instancePath + "/" + i0 + "/sequence",
654
- schemaPath: "#/items/properties/sequence/pattern",
655
- keyword: "pattern",
656
- params: { pattern: "^[1-9][0-9]*(.[1-9][0-9]*)*$" },
657
- message: "must match pattern \"^[1-9][0-9]*(.[1-9][0-9]*)*$\""
658
- };
659
- if (vErrors === null) vErrors = [err6];
660
- else vErrors.push(err6);
661
- errors++;
662
- }
663
- } else {
664
- const err7 = {
665
- instancePath: instancePath + "/" + i0 + "/sequence",
666
- schemaPath: "#/items/properties/sequence/type",
667
- keyword: "type",
668
- params: { type: "string" },
669
- message: "must be string"
670
- };
671
- if (vErrors === null) vErrors = [err7];
672
- else vErrors.push(err7);
673
- errors++;
674
- }
675
- }
676
- } else {
677
- const err8 = {
678
- instancePath: instancePath + "/" + i0,
679
- schemaPath: "#/items/type",
680
- keyword: "type",
681
- params: { type: "object" },
682
- message: "must be object"
683
- };
684
- if (vErrors === null) vErrors = [err8];
685
- else vErrors.push(err8);
686
- errors++;
272
+ var Ss = {
273
+ "[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}", !0],
274
+ "[:alpha:]": ["\\p{L}\\p{Nl}", !0],
275
+ "[:ascii:]": ["\\x00-\\x7f", !1],
276
+ "[:blank:]": ["\\p{Zs}\\t", !0],
277
+ "[:cntrl:]": ["\\p{Cc}", !0],
278
+ "[:digit:]": ["\\p{Nd}", !0],
279
+ "[:graph:]": [
280
+ "\\p{Z}\\p{C}",
281
+ !0,
282
+ !0
283
+ ],
284
+ "[:lower:]": ["\\p{Ll}", !0],
285
+ "[:print:]": ["\\p{C}", !0],
286
+ "[:punct:]": ["\\p{P}", !0],
287
+ "[:space:]": ["\\p{Z}\\t\\r\\n\\v\\f", !0],
288
+ "[:upper:]": ["\\p{Lu}", !0],
289
+ "[:word:]": ["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}", !0],
290
+ "[:xdigit:]": ["A-Fa-f0-9", !1]
291
+ }, lt = (n) => n.replace(/[[\]\\-]/g, "\\$&"), Es = (n) => n.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), we = (n) => n.join(""), ye = (n, t) => {
292
+ let e = t;
293
+ if (n.charAt(e) !== "[") throw new Error("not in a brace expression");
294
+ let s = [], i = [], r = e + 1, o = !1, h = !1, a = !1, l = !1, u = e, c = "";
295
+ t: for (; r < n.length;) {
296
+ let p = n.charAt(r);
297
+ if ((p === "!" || p === "^") && r === e + 1) {
298
+ l = !0, r++;
299
+ continue;
300
+ }
301
+ if (p === "]" && o && !a) {
302
+ u = r + 1;
303
+ break;
304
+ }
305
+ if (o = !0, p === "\\" && !a) {
306
+ a = !0, r++;
307
+ continue;
308
+ }
309
+ if (p === "[" && !a) {
310
+ for (let [w, [g, S, E]] of Object.entries(Ss)) if (n.startsWith(w, r)) {
311
+ if (c) return [
312
+ "$.",
313
+ !1,
314
+ n.length - e,
315
+ !0
316
+ ];
317
+ r += w.length, E ? i.push(g) : s.push(g), h = h || S;
318
+ continue t;
687
319
  }
688
320
  }
689
- } else {
690
- const err9 = {
691
- instancePath,
692
- schemaPath: "#/type",
693
- keyword: "type",
694
- params: { type: "array" },
695
- message: "must be array"
696
- };
697
- if (vErrors === null) vErrors = [err9];
698
- else vErrors.push(err9);
699
- errors++;
321
+ if (a = !1, c) {
322
+ p > c ? s.push(lt(c) + "-" + lt(p)) : p === c && s.push(lt(p)), c = "", r++;
323
+ continue;
324
+ }
325
+ if (n.startsWith("-]", r + 1)) {
326
+ s.push(lt(p + "-")), r += 2;
327
+ continue;
328
+ }
329
+ if (n.startsWith("-", r + 1)) {
330
+ c = p, r += 2;
331
+ continue;
332
+ }
333
+ s.push(lt(p)), r++;
700
334
  }
701
- validate14.errors = vErrors;
702
- return errors === 0;
703
- }
704
- //#endregion
705
- //#region src/validator/validator.ts
706
- const isNonEmptyString = (input) => isString(input) && input.length > 0;
707
- /**
708
- * Validates if a plan matches the schema
709
- */
710
- const validatePlan = (plan) => {
711
- const valid = planSchemaValidator(plan);
712
- const errors = planSchemaValidator.errors;
713
- if (errors?.length) errors.forEach((e) => console.error(`${e.message}${e.instancePath ? `at ${e.instancePath}` : ""}`));
714
- return valid;
715
- };
716
- /**
717
- * Validates if file description format is valid
718
- */
719
- const validateFileDescription = (description) => {
720
- if (!description) return false;
721
- return /^([a-z]+|(([a-z]+-)+[a-z]+))$/g.test(description);
722
- };
723
- /**
724
- * Validates if fileName format is valid
725
- */
726
- const validateFileName = (fileName) => {
727
- return /^([a-z]+|(([a-z]+-)+[a-z]+))(.js|.skip.js)$/g.test(fileName);
335
+ if (u < r) return [
336
+ "",
337
+ !1,
338
+ 0,
339
+ !1
340
+ ];
341
+ if (!s.length && !i.length) return [
342
+ "$.",
343
+ !1,
344
+ n.length - e,
345
+ !0
346
+ ];
347
+ if (i.length === 0 && s.length === 1 && /^\\?.$/.test(s[0]) && !l) return [
348
+ Es(s[0].length === 2 ? s[0].slice(-1) : s[0]),
349
+ !1,
350
+ u - e,
351
+ !1
352
+ ];
353
+ let d = "[" + (l ? "^" : "") + we(s) + "]", f = "[" + (l ? "" : "^") + we(i) + "]";
354
+ return [
355
+ s.length && i.length ? "(" + d + "|" + f + ")" : s.length ? d : f,
356
+ h,
357
+ u - e,
358
+ !0
359
+ ];
728
360
  };
729
- /**
730
- * Throws if file names are invalid
731
- */
732
- const throwIfFileNamesInvalid = (fileEntries) => {
733
- const invalidFileNames = fileEntries.filter((f) => !f.isValidFileName).map((f) => f.fileName);
734
- if (invalidFileNames.length) {
735
- invalidFileNames.forEach((name) => console.error(chalk.red(name)));
736
- throw new Error("Invalid migration filename format (use kebab-case)");
361
+ var W = (n, { windowsPathsNoEscape: t = !1, magicalBraces: e = !0 } = {}) => e ? t ? n.replace(/\[([^\/\\])\]/g, "$1") : n.replace(/((?!\\).|^)\[([^\/\\])\]/g, "$1$2").replace(/\\([^\/])/g, "$1") : t ? n.replace(/\[([^\/\\{}])\]/g, "$1") : n.replace(/((?!\\).|^)\[([^\/\\{}])\]/g, "$1$2").replace(/\\([^\/{}])/g, "$1");
362
+ var xs = new Set([
363
+ "!",
364
+ "?",
365
+ "+",
366
+ "*",
367
+ "@"
368
+ ]), be = (n) => xs.has(n), vs = "(?!(?:^|/)\\.\\.?(?:$|/))", Ct = "(?!\\.)", Cs = new Set(["[", "."]), Ts = new Set(["..", "."]), As = /* @__PURE__ */ new Set("().*{}+?[]^$\\!"), ks = (n) => n.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), Kt = "[^/]", Se = Kt + "*?", Ee = Kt + "+?", Q = class n {
369
+ type;
370
+ #t;
371
+ #s;
372
+ #n = !1;
373
+ #r = [];
374
+ #o;
375
+ #S;
376
+ #w;
377
+ #c = !1;
378
+ #h;
379
+ #u;
380
+ #f = !1;
381
+ constructor(t, e, s = {}) {
382
+ this.type = t, t && (this.#s = !0), this.#o = e, this.#t = this.#o ? this.#o.#t : this, this.#h = this.#t === this ? s : this.#t.#h, this.#w = this.#t === this ? [] : this.#t.#w, t === "!" && !this.#t.#c && this.#w.push(this), this.#S = this.#o ? this.#o.#r.length : 0;
737
383
  }
738
- };
739
- /**
740
- * Warns if files have been removed
741
- */
742
- const warnIfFilesHaveBeenRemovedFromPlan = (migrationEntries, historicalMigrations) => {
743
- const fileNames = migrationEntries.map((f) => f.fileName);
744
- const deletedFilesNames = historicalMigrations.filter((e) => !fileNames.includes(e.fileName)).map((e) => e.fileName);
745
- if (deletedFilesNames.length) {
746
- deletedFilesNames.forEach((name) => console.warn(chalk.yellow(name)));
747
- console.warn(chalk.yellow("Previously executed migration files have been deleted from plan.json (rename file to .skip.js and replace with a new file instead)"));
384
+ get hasMagic() {
385
+ if (this.#s !== void 0) return this.#s;
386
+ for (let t of this.#r) if (typeof t != "string" && (t.type || t.hasMagic)) return this.#s = !0;
387
+ return this.#s;
748
388
  }
749
- };
750
- /**
751
- * Throws error if any pre-existing file has changed
752
- */
753
- const throwIfFilesHaveChanged = (migrationEntries) => {
754
- const changedFilesNames = migrationEntries.filter((m) => {
755
- const { fileHash, fileHashFromPlan, fileHashFromHistory, skippedFileHashes } = m;
756
- const matchesHistory = !isNonEmptyString(fileHashFromHistory) || [fileHash].concat(skippedFileHashes).includes(fileHashFromHistory);
757
- const matchesPlan = !isNonEmptyString(fileHashFromPlan) || [fileHash].concat(skippedFileHashes).includes(fileHashFromPlan);
758
- return !(matchesHistory && matchesPlan);
759
- }).map((f) => f.fileName);
760
- if (changedFilesNames.length) {
761
- changedFilesNames.forEach((name) => console.error(chalk.red(name)));
762
- throw new Error("Not allowed to change migration files (for unreleased local work, you can use the `force` option)");
763
- }
764
- };
765
- /**
766
- * Throws error if previous sequence numbers have changed
767
- */
768
- const throwIfSequenceHasChanged = (migrationEntries) => {
769
- const changeSequences = migrationEntries.filter((m) => {
770
- const { sequence, sequenceFromHistory } = m;
771
- return isString(sequenceFromHistory) && sequenceFromHistory !== sequence;
772
- }).map((f) => f.fileName);
773
- if (changeSequences.length) {
774
- changeSequences.forEach((name) => console.error(chalk.red(name)));
775
- throw new Error("Not allowed to change migration sequences in plan.json");
389
+ toString() {
390
+ return this.#u !== void 0 ? this.#u : this.type ? this.#u = this.type + "(" + this.#r.map((t) => String(t)).join("|") + ")" : this.#u = this.#r.map((t) => String(t)).join("");
776
391
  }
777
- };
778
- /**
779
- * Throws error if sequence numbers are not unique
780
- */
781
- const throwIfSequenceNotUnique = (migrationEntries) => {
782
- const repeatedSequenceNumbers = migrationEntries.map((f) => f.sequence).filter(((s) => (v) => s.has(v) || !s.add(v))(/* @__PURE__ */ new Set()));
783
- const duplicates = migrationEntries.filter((f) => repeatedSequenceNumbers.includes(f.sequence)).map((f) => f.fileName);
784
- if (duplicates.length) {
785
- duplicates.forEach((fileName) => console.error(chalk.red(fileName)));
786
- throw new Error("Migrations must have unique sequence numbers in plan.json");
392
+ #a() {
393
+ if (this !== this.#t) throw new Error("should only call on root");
394
+ if (this.#c) return this;
395
+ this.toString(), this.#c = !0;
396
+ let t;
397
+ for (; t = this.#w.pop();) {
398
+ if (t.type !== "!") continue;
399
+ let e = t, s = e.#o;
400
+ for (; s;) {
401
+ for (let i = e.#S + 1; !s.type && i < s.#r.length; i++) for (let r of t.#r) {
402
+ if (typeof r == "string") throw new Error("string part in extglob AST??");
403
+ r.copyIn(s.#r[i]);
404
+ }
405
+ e = s, s = e.#o;
406
+ }
407
+ }
408
+ return this;
787
409
  }
788
- };
789
- /**
790
- * Throws error if sequence numbers are not unique
791
- */
792
- const throwIfSequenceHasIntegerGaps = (migrationEntries) => {
793
- const toInteger = (sequence) => parseInt(sequence.split(".")[0], 10);
794
- const unique = (arr) => Array.from(new Set(arr));
795
- const orderedUniqueSequenceIntegers = unique(migrationEntries.map((s) => s.sequence).map((s) => toInteger(s))).sort((a, b) => a - b);
796
- const max = orderedUniqueSequenceIntegers[orderedUniqueSequenceIntegers.length - 1];
797
- const missing = xor(orderedUniqueSequenceIntegers, Array.from({ length: max }, (_v, k) => k + 1));
798
- if (missing.length) throw new Error(`Migration sequence numbers in plan.json have unexpected gaps: ${missing.join(", ")}`);
799
- };
800
- /**
801
- * Throws error if file names are not unique
802
- */
803
- const throwIfFileNamesNotUnique = (migrationEntries) => {
804
- const repeatedFileNames = migrationEntries.map((f) => f.fileName).filter(((s) => (v) => s.has(v) || !s.add(v))(/* @__PURE__ */ new Set()));
805
- if (repeatedFileNames.length) {
806
- repeatedFileNames.forEach((fileName) => console.error(chalk.red(fileName)));
807
- throw new Error("Migration file names must be unique");
410
+ push(...t) {
411
+ for (let e of t) if (e !== "") {
412
+ if (typeof e != "string" && !(e instanceof n && e.#o === this)) throw new Error("invalid part: " + e);
413
+ this.#r.push(e);
414
+ }
808
415
  }
809
- };
810
- /**
811
- * Throws error if files listed in plan.json are found
812
- */
813
- const throwIfFilesNotFound = (migrationEntries) => {
814
- const migrationsWithoutFiles = migrationEntries.filter((m) => !m.script || !m.script && !m.migrator);
815
- if (migrationsWithoutFiles.length) {
816
- migrationsWithoutFiles.forEach((migration) => console.error(chalk.red(migration.fileName)));
817
- throw new Error("Migration files from plan.json are missing from filesystem");
416
+ toJSON() {
417
+ let t = this.type === null ? this.#r.slice().map((e) => typeof e == "string" ? e : e.toJSON()) : [this.type, ...this.#r.map((e) => e.toJSON())];
418
+ return this.isStart() && !this.type && t.unshift([]), this.isEnd() && (this === this.#t || this.#t.#c && this.#o?.type === "!") && t.push({}), t;
818
419
  }
819
- };
820
- //#endregion
821
- //#region src/helpers/helpers.ts
822
- const capitalize = (word) => {
823
- if (!word) return "";
824
- return word[0].toUpperCase() + word.slice(1);
825
- };
826
- //#endregion
827
- //#region src/plan/loader-module.ts
828
- const lazyImportMigration = (script) => {
829
- if (!script) return noop;
830
- const patchedScript = script.replace(/import\s+\{?\s*produce\s*}?\s+from\s+['"]immer['"];?/, "").replace(/export\s+default\s+/, "const migration = ").replace(/export\s+(const|function|async function)\s+/g, "$1 ");
831
- return (payload, metaData) => {
832
- const context = {
833
- payload,
834
- metaData,
835
- produce
836
- };
837
- return vm.runInNewContext(`${patchedScript}; migration(payload, metaData);`, context);
838
- };
839
- };
840
- const LoaderModule = { lazyImportMigration };
841
- //#endregion
842
- //#region src/hash/hash.ts
843
- /**
844
- * Generate SHA256 hash from a string
845
- */
846
- const hash = (string) => createHash("sha256").update(string).digest("hex");
847
- //#endregion
848
- //#region node_modules/.pnpm/glob@13.0.6/node_modules/glob/dist/esm/index.min.js
849
- var Gt = (n, t, e) => {
850
- let s = n instanceof RegExp ? ce(n, e) : n, i = t instanceof RegExp ? ce(t, e) : t, r = s !== null && i != null && ss(s, i, e);
851
- return r && {
852
- start: r[0],
853
- end: r[1],
854
- pre: e.slice(0, r[0]),
855
- body: e.slice(r[0] + s.length, r[1]),
856
- post: e.slice(r[1] + i.length)
857
- };
858
- }, ce = (n, t) => {
859
- let e = t.match(n);
860
- return e ? e[0] : null;
861
- }, ss = (n, t, e) => {
862
- let s, i, r, o, h, a = e.indexOf(n), l = e.indexOf(t, a + 1), u = a;
863
- if (a >= 0 && l > 0) {
864
- if (n === t) return [a, l];
865
- for (s = [], r = e.length; u >= 0 && !h;) {
866
- if (u === a) s.push(u), a = e.indexOf(n, u + 1);
867
- else if (s.length === 1) {
868
- let c = s.pop();
869
- c !== void 0 && (h = [c, l]);
870
- } else i = s.pop(), i !== void 0 && i < r && (r = i, o = l), l = e.indexOf(t, u + 1);
871
- u = a < l && a >= 0 ? a : l;
420
+ isStart() {
421
+ if (this.#t === this) return !0;
422
+ if (!this.#o?.isStart()) return !1;
423
+ if (this.#S === 0) return !0;
424
+ let t = this.#o;
425
+ for (let e = 0; e < this.#S; e++) {
426
+ let s = t.#r[e];
427
+ if (!(s instanceof n && s.type === "!")) return !1;
872
428
  }
873
- s.length && o !== void 0 && (h = [r, o]);
429
+ return !0;
874
430
  }
875
- return h;
876
- };
877
- var fe = "\0SLASH" + Math.random() + "\0", ue = "\0OPEN" + Math.random() + "\0", qt = "\0CLOSE" + Math.random() + "\0", de = "\0COMMA" + Math.random() + "\0", pe = "\0PERIOD" + Math.random() + "\0", is = new RegExp(fe, "g"), rs = new RegExp(ue, "g"), ns = new RegExp(qt, "g"), os$1 = new RegExp(de, "g"), hs = new RegExp(pe, "g"), as = /\\\\/g, ls = /\\{/g, cs = /\\}/g, fs = /\\,/g, us = /\\./g, ds = 1e5;
878
- function Ht(n) {
879
- return isNaN(n) ? n.charCodeAt(0) : parseInt(n, 10);
880
- }
881
- function ps(n) {
882
- return n.replace(as, fe).replace(ls, ue).replace(cs, qt).replace(fs, de).replace(us, pe);
883
- }
884
- function ms(n) {
885
- return n.replace(is, "\\").replace(rs, "{").replace(ns, "}").replace(os$1, ",").replace(hs, ".");
886
- }
887
- function me(n) {
888
- if (!n) return [""];
889
- let t = [], e = Gt("{", "}", n);
890
- if (!e) return n.split(",");
891
- let { pre: s, body: i, post: r } = e, o = s.split(",");
892
- o[o.length - 1] += "{" + i + "}";
893
- let h = me(r);
894
- return r.length && (o[o.length - 1] += h.shift(), o.push.apply(o, h)), t.push.apply(t, o), t;
895
- }
896
- function ge(n, t = {}) {
897
- if (!n) return [];
898
- let { max: e = ds } = t;
899
- return n.slice(0, 2) === "{}" && (n = "\\{\\}" + n.slice(2)), ht(ps(n), e, !0).map(ms);
900
- }
901
- function gs(n) {
902
- return "{" + n + "}";
903
- }
904
- function ws(n) {
905
- return /^-?0\d/.test(n);
906
- }
907
- function ys(n, t) {
908
- return n <= t;
909
- }
910
- function bs(n, t) {
911
- return n >= t;
912
- }
913
- function ht(n, t, e) {
914
- let s = [], i = Gt("{", "}", n);
915
- if (!i) return [n];
916
- let r = i.pre, o = i.post.length ? ht(i.post, t, !1) : [""];
917
- if (/\$$/.test(i.pre)) for (let h = 0; h < o.length && h < t; h++) {
918
- let a = r + "{" + i.body + "}" + o[h];
919
- s.push(a);
431
+ isEnd() {
432
+ if (this.#t === this || this.#o?.type === "!") return !0;
433
+ if (!this.#o?.isEnd()) return !1;
434
+ if (!this.type) return this.#o?.isEnd();
435
+ let t = this.#o ? this.#o.#r.length : 0;
436
+ return this.#S === t - 1;
920
437
  }
921
- else {
922
- let h = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(i.body), a = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(i.body), l = h || a, u = i.body.indexOf(",") >= 0;
923
- if (!l && !u) return i.post.match(/,(?!,).*\}/) ? (n = i.pre + "{" + i.body + qt + i.post, ht(n, t, !0)) : [n];
924
- let c;
925
- if (l) c = i.body.split(/\.\./);
926
- else if (c = me(i.body), c.length === 1 && c[0] !== void 0 && (c = ht(c[0], t, !1).map(gs), c.length === 1)) return o.map((f) => i.pre + c[0] + f);
927
- let d;
928
- if (l && c[0] !== void 0 && c[1] !== void 0) {
929
- let f = Ht(c[0]), m = Ht(c[1]), p = Math.max(c[0].length, c[1].length), w = c.length === 3 && c[2] !== void 0 ? Math.abs(Ht(c[2])) : 1, g = ys;
930
- m < f && (w *= -1, g = bs);
931
- let E = c.some(ws);
932
- d = [];
933
- for (let y = f; g(y, m); y += w) {
934
- let b;
935
- if (a) b = String.fromCharCode(y), b === "\\" && (b = "");
936
- else if (b = String(y), E) {
937
- let z = p - b.length;
938
- if (z > 0) {
939
- let $ = new Array(z + 1).join("0");
940
- y < 0 ? b = "-" + $ + b.slice(1) : b = $ + b;
941
- }
438
+ copyIn(t) {
439
+ typeof t == "string" ? this.push(t) : this.push(t.clone(this));
440
+ }
441
+ clone(t) {
442
+ let e = new n(this.type, t);
443
+ for (let s of this.#r) e.copyIn(s);
444
+ return e;
445
+ }
446
+ static #i(t, e, s, i) {
447
+ let r = !1, o = !1, h = -1, a = !1;
448
+ if (e.type === null) {
449
+ let f = s, m = "";
450
+ for (; f < t.length;) {
451
+ let p = t.charAt(f++);
452
+ if (r || p === "\\") {
453
+ r = !r, m += p;
454
+ continue;
942
455
  }
943
- d.push(b);
944
- }
945
- } else {
946
- d = [];
947
- for (let f = 0; f < c.length; f++) d.push.apply(d, ht(c[f], t, !1));
948
- }
949
- for (let f = 0; f < d.length; f++) for (let m = 0; m < o.length && s.length < t; m++) {
950
- let p = r + d[f] + o[m];
951
- (!e || l || p) && s.push(p);
952
- }
953
- }
954
- return s;
955
- }
956
- var at = (n) => {
957
- if (typeof n != "string") throw new TypeError("invalid pattern");
958
- if (n.length > 65536) throw new TypeError("pattern is too long");
959
- };
960
- var Ss = {
961
- "[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}", !0],
962
- "[:alpha:]": ["\\p{L}\\p{Nl}", !0],
963
- "[:ascii:]": ["\\x00-\\x7f", !1],
964
- "[:blank:]": ["\\p{Zs}\\t", !0],
965
- "[:cntrl:]": ["\\p{Cc}", !0],
966
- "[:digit:]": ["\\p{Nd}", !0],
967
- "[:graph:]": [
968
- "\\p{Z}\\p{C}",
969
- !0,
970
- !0
971
- ],
972
- "[:lower:]": ["\\p{Ll}", !0],
973
- "[:print:]": ["\\p{C}", !0],
974
- "[:punct:]": ["\\p{P}", !0],
975
- "[:space:]": ["\\p{Z}\\t\\r\\n\\v\\f", !0],
976
- "[:upper:]": ["\\p{Lu}", !0],
977
- "[:word:]": ["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}", !0],
978
- "[:xdigit:]": ["A-Fa-f0-9", !1]
979
- }, lt = (n) => n.replace(/[[\]\\-]/g, "\\$&"), Es = (n) => n.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), we = (n) => n.join(""), ye = (n, t) => {
980
- let e = t;
981
- if (n.charAt(e) !== "[") throw new Error("not in a brace expression");
982
- let s = [], i = [], r = e + 1, o = !1, h = !1, a = !1, l = !1, u = e, c = "";
983
- t: for (; r < n.length;) {
984
- let p = n.charAt(r);
985
- if ((p === "!" || p === "^") && r === e + 1) {
986
- l = !0, r++;
987
- continue;
988
- }
989
- if (p === "]" && o && !a) {
990
- u = r + 1;
991
- break;
992
- }
993
- if (o = !0, p === "\\" && !a) {
994
- a = !0, r++;
995
- continue;
996
- }
997
- if (p === "[" && !a) {
998
- for (let [w, [g, S, E]] of Object.entries(Ss)) if (n.startsWith(w, r)) {
999
- if (c) return [
1000
- "$.",
1001
- !1,
1002
- n.length - e,
1003
- !0
1004
- ];
1005
- r += w.length, E ? i.push(g) : s.push(g), h = h || S;
1006
- continue t;
1007
- }
1008
- }
1009
- if (a = !1, c) {
1010
- p > c ? s.push(lt(c) + "-" + lt(p)) : p === c && s.push(lt(p)), c = "", r++;
1011
- continue;
1012
- }
1013
- if (n.startsWith("-]", r + 1)) {
1014
- s.push(lt(p + "-")), r += 2;
1015
- continue;
1016
- }
1017
- if (n.startsWith("-", r + 1)) {
1018
- c = p, r += 2;
1019
- continue;
1020
- }
1021
- s.push(lt(p)), r++;
1022
- }
1023
- if (u < r) return [
1024
- "",
1025
- !1,
1026
- 0,
1027
- !1
1028
- ];
1029
- if (!s.length && !i.length) return [
1030
- "$.",
1031
- !1,
1032
- n.length - e,
1033
- !0
1034
- ];
1035
- if (i.length === 0 && s.length === 1 && /^\\?.$/.test(s[0]) && !l) return [
1036
- Es(s[0].length === 2 ? s[0].slice(-1) : s[0]),
1037
- !1,
1038
- u - e,
1039
- !1
1040
- ];
1041
- let d = "[" + (l ? "^" : "") + we(s) + "]", f = "[" + (l ? "" : "^") + we(i) + "]";
1042
- return [
1043
- s.length && i.length ? "(" + d + "|" + f + ")" : s.length ? d : f,
1044
- h,
1045
- u - e,
1046
- !0
1047
- ];
1048
- };
1049
- var W = (n, { windowsPathsNoEscape: t = !1, magicalBraces: e = !0 } = {}) => e ? t ? n.replace(/\[([^\/\\])\]/g, "$1") : n.replace(/((?!\\).|^)\[([^\/\\])\]/g, "$1$2").replace(/\\([^\/])/g, "$1") : t ? n.replace(/\[([^\/\\{}])\]/g, "$1") : n.replace(/((?!\\).|^)\[([^\/\\{}])\]/g, "$1$2").replace(/\\([^\/{}])/g, "$1");
1050
- var xs = new Set([
1051
- "!",
1052
- "?",
1053
- "+",
1054
- "*",
1055
- "@"
1056
- ]), be = (n) => xs.has(n), vs = "(?!(?:^|/)\\.\\.?(?:$|/))", Ct = "(?!\\.)", Cs = new Set(["[", "."]), Ts = new Set(["..", "."]), As = /* @__PURE__ */ new Set("().*{}+?[]^$\\!"), ks = (n) => n.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), Kt = "[^/]", Se = Kt + "*?", Ee = Kt + "+?", Q = class n {
1057
- type;
1058
- #t;
1059
- #s;
1060
- #n = !1;
1061
- #r = [];
1062
- #o;
1063
- #S;
1064
- #w;
1065
- #c = !1;
1066
- #h;
1067
- #u;
1068
- #f = !1;
1069
- constructor(t, e, s = {}) {
1070
- this.type = t, t && (this.#s = !0), this.#o = e, this.#t = this.#o ? this.#o.#t : this, this.#h = this.#t === this ? s : this.#t.#h, this.#w = this.#t === this ? [] : this.#t.#w, t === "!" && !this.#t.#c && this.#w.push(this), this.#S = this.#o ? this.#o.#r.length : 0;
1071
- }
1072
- get hasMagic() {
1073
- if (this.#s !== void 0) return this.#s;
1074
- for (let t of this.#r) if (typeof t != "string" && (t.type || t.hasMagic)) return this.#s = !0;
1075
- return this.#s;
1076
- }
1077
- toString() {
1078
- return this.#u !== void 0 ? this.#u : this.type ? this.#u = this.type + "(" + this.#r.map((t) => String(t)).join("|") + ")" : this.#u = this.#r.map((t) => String(t)).join("");
1079
- }
1080
- #a() {
1081
- if (this !== this.#t) throw new Error("should only call on root");
1082
- if (this.#c) return this;
1083
- this.toString(), this.#c = !0;
1084
- let t;
1085
- for (; t = this.#w.pop();) {
1086
- if (t.type !== "!") continue;
1087
- let e = t, s = e.#o;
1088
- for (; s;) {
1089
- for (let i = e.#S + 1; !s.type && i < s.#r.length; i++) for (let r of t.#r) {
1090
- if (typeof r == "string") throw new Error("string part in extglob AST??");
1091
- r.copyIn(s.#r[i]);
1092
- }
1093
- e = s, s = e.#o;
1094
- }
1095
- }
1096
- return this;
1097
- }
1098
- push(...t) {
1099
- for (let e of t) if (e !== "") {
1100
- if (typeof e != "string" && !(e instanceof n && e.#o === this)) throw new Error("invalid part: " + e);
1101
- this.#r.push(e);
1102
- }
1103
- }
1104
- toJSON() {
1105
- let t = this.type === null ? this.#r.slice().map((e) => typeof e == "string" ? e : e.toJSON()) : [this.type, ...this.#r.map((e) => e.toJSON())];
1106
- return this.isStart() && !this.type && t.unshift([]), this.isEnd() && (this === this.#t || this.#t.#c && this.#o?.type === "!") && t.push({}), t;
1107
- }
1108
- isStart() {
1109
- if (this.#t === this) return !0;
1110
- if (!this.#o?.isStart()) return !1;
1111
- if (this.#S === 0) return !0;
1112
- let t = this.#o;
1113
- for (let e = 0; e < this.#S; e++) {
1114
- let s = t.#r[e];
1115
- if (!(s instanceof n && s.type === "!")) return !1;
1116
- }
1117
- return !0;
1118
- }
1119
- isEnd() {
1120
- if (this.#t === this || this.#o?.type === "!") return !0;
1121
- if (!this.#o?.isEnd()) return !1;
1122
- if (!this.type) return this.#o?.isEnd();
1123
- let t = this.#o ? this.#o.#r.length : 0;
1124
- return this.#S === t - 1;
1125
- }
1126
- copyIn(t) {
1127
- typeof t == "string" ? this.push(t) : this.push(t.clone(this));
1128
- }
1129
- clone(t) {
1130
- let e = new n(this.type, t);
1131
- for (let s of this.#r) e.copyIn(s);
1132
- return e;
1133
- }
1134
- static #i(t, e, s, i) {
1135
- let r = !1, o = !1, h = -1, a = !1;
1136
- if (e.type === null) {
1137
- let f = s, m = "";
1138
- for (; f < t.length;) {
1139
- let p = t.charAt(f++);
1140
- if (r || p === "\\") {
1141
- r = !r, m += p;
1142
- continue;
1143
- }
1144
- if (o) {
1145
- f === h + 1 ? (p === "^" || p === "!") && (a = !0) : p === "]" && !(f === h + 2 && a) && (o = !1), m += p;
1146
- continue;
1147
- } else if (p === "[") {
1148
- o = !0, h = f, a = !1, m += p;
1149
- continue;
1150
- }
1151
- if (!i.noext && be(p) && t.charAt(f) === "(") {
1152
- e.push(m), m = "";
1153
- let w = new n(p, e);
1154
- f = n.#i(t, w, f, i), e.push(w);
1155
- continue;
1156
- }
1157
- m += p;
456
+ if (o) {
457
+ f === h + 1 ? (p === "^" || p === "!") && (a = !0) : p === "]" && !(f === h + 2 && a) && (o = !1), m += p;
458
+ continue;
459
+ } else if (p === "[") {
460
+ o = !0, h = f, a = !1, m += p;
461
+ continue;
462
+ }
463
+ if (!i.noext && be(p) && t.charAt(f) === "(") {
464
+ e.push(m), m = "";
465
+ let w = new n(p, e);
466
+ f = n.#i(t, w, f, i), e.push(w);
467
+ continue;
468
+ }
469
+ m += p;
1158
470
  }
1159
471
  return e.push(m), f;
1160
472
  }
@@ -4045,142 +3357,824 @@ function isIndex(value, length = Number.MAX_SAFE_INTEGER) {
4045
3357
  }
4046
3358
  }
4047
3359
  //#endregion
4048
- //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/compat/_internal/isIterateeCall.mjs
4049
- function isIterateeCall(value, index, object) {
4050
- if (!isObject(object)) return false;
4051
- if (typeof index === "number" && isArrayLike(object) && isIndex(index) && index < object.length || typeof index === "string" && index in object) return isEqualsSameValueZero(object[index], value);
4052
- return false;
4053
- }
4054
- //#endregion
4055
- //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/compat/_internal/compareValues.mjs
4056
- function getPriority(a) {
4057
- if (typeof a === "symbol") return 1;
4058
- if (a === null) return 2;
4059
- if (a === void 0) return 3;
4060
- if (a !== a) return 4;
4061
- return 0;
4062
- }
4063
- const compareValues = (a, b, order) => {
4064
- if (a !== b) {
4065
- const aPriority = getPriority(a);
4066
- const bPriority = getPriority(b);
4067
- if (aPriority === bPriority && aPriority === 0) {
4068
- if (a < b) return order === "desc" ? 1 : -1;
4069
- if (a > b) return order === "desc" ? -1 : 1;
4070
- }
4071
- return order === "desc" ? bPriority - aPriority : aPriority - bPriority;
3360
+ //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/compat/_internal/isIterateeCall.mjs
3361
+ function isIterateeCall(value, index, object) {
3362
+ if (!isObject(object)) return false;
3363
+ if (typeof index === "number" && isArrayLike(object) && isIndex(index) && index < object.length || typeof index === "string" && index in object) return isEqualsSameValueZero(object[index], value);
3364
+ return false;
3365
+ }
3366
+ //#endregion
3367
+ //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/compat/_internal/compareValues.mjs
3368
+ function getPriority(a) {
3369
+ if (typeof a === "symbol") return 1;
3370
+ if (a === null) return 2;
3371
+ if (a === void 0) return 3;
3372
+ if (a !== a) return 4;
3373
+ return 0;
3374
+ }
3375
+ const compareValues = (a, b, order) => {
3376
+ if (a !== b) {
3377
+ const aPriority = getPriority(a);
3378
+ const bPriority = getPriority(b);
3379
+ if (aPriority === bPriority && aPriority === 0) {
3380
+ if (a < b) return order === "desc" ? 1 : -1;
3381
+ if (a > b) return order === "desc" ? -1 : 1;
3382
+ }
3383
+ return order === "desc" ? bPriority - aPriority : aPriority - bPriority;
3384
+ }
3385
+ return 0;
3386
+ };
3387
+ //#endregion
3388
+ //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/compat/_internal/isKey.mjs
3389
+ const regexIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
3390
+ const regexIsPlainProp = /^\w*$/;
3391
+ function isKey(value, object) {
3392
+ if (Array.isArray(value)) return false;
3393
+ if (typeof value === "number" || typeof value === "boolean" || value == null || isSymbol(value)) return true;
3394
+ return typeof value === "string" && (regexIsPlainProp.test(value) || !regexIsDeepProp.test(value)) || object != null && Object.hasOwn(object, value);
3395
+ }
3396
+ //#endregion
3397
+ //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/compat/array/orderBy.mjs
3398
+ function orderBy(collection, criteria, orders, guard) {
3399
+ if (collection == null) return [];
3400
+ orders = guard ? void 0 : orders;
3401
+ if (!Array.isArray(collection)) collection = Object.values(collection);
3402
+ if (!Array.isArray(criteria)) criteria = criteria == null ? [null] : [criteria];
3403
+ if (criteria.length === 0) criteria = [null];
3404
+ if (!Array.isArray(orders)) orders = orders == null ? [] : [orders];
3405
+ orders = orders.map((order) => String(order));
3406
+ const getValueByNestedPath = (object, path) => {
3407
+ let target = object;
3408
+ for (let i = 0; i < path.length && target != null; ++i) target = target[path[i]];
3409
+ return target;
3410
+ };
3411
+ const getValueByCriterion = (criterion, object) => {
3412
+ if (object == null || criterion == null) return object;
3413
+ if (typeof criterion === "object" && "key" in criterion) {
3414
+ if (Object.hasOwn(object, criterion.key)) return object[criterion.key];
3415
+ return getValueByNestedPath(object, criterion.path);
3416
+ }
3417
+ if (typeof criterion === "function") return criterion(object);
3418
+ if (Array.isArray(criterion)) return getValueByNestedPath(object, criterion);
3419
+ if (typeof object === "object") return object[criterion];
3420
+ return object;
3421
+ };
3422
+ const preparedCriteria = criteria.map((criterion) => {
3423
+ if (Array.isArray(criterion) && criterion.length === 1) criterion = criterion[0];
3424
+ if (criterion == null || typeof criterion === "function" || Array.isArray(criterion) || isKey(criterion)) return criterion;
3425
+ return {
3426
+ key: criterion,
3427
+ path: toPath(criterion)
3428
+ };
3429
+ });
3430
+ return collection.map((item) => ({
3431
+ original: item,
3432
+ criteria: preparedCriteria.map((criterion) => getValueByCriterion(criterion, item))
3433
+ })).slice().sort((a, b) => {
3434
+ for (let i = 0; i < preparedCriteria.length; i++) {
3435
+ const comparedResult = compareValues(a.criteria[i], b.criteria[i], orders[i]);
3436
+ if (comparedResult !== 0) return comparedResult;
3437
+ }
3438
+ return 0;
3439
+ }).map((item) => item.original);
3440
+ }
3441
+ //#endregion
3442
+ //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/compat/array/sortBy.mjs
3443
+ function sortBy(collection, ...criteria) {
3444
+ const length = criteria.length;
3445
+ if (length > 1 && isIterateeCall(collection, criteria[0], criteria[1])) criteria = [];
3446
+ else if (length > 2 && isIterateeCall(criteria[0], criteria[1], criteria[2])) criteria = [criteria[0]];
3447
+ return orderBy(collection, flatten(criteria), ["asc"]);
3448
+ }
3449
+ //#endregion
3450
+ //#region src/glob/glob.ts
3451
+ /**
3452
+ * Sorts migration file paths
3453
+ *
3454
+ * @param {Array<String>} filePaths
3455
+ * @returns {Array<String>} sorted files
3456
+ */
3457
+ const sortFilePathsByFilename = (filePaths) => sortBy(filePaths, (file) => {
3458
+ return path.parse(file).base;
3459
+ });
3460
+ /**
3461
+ * Gets paths to entity migrations in a directory
3462
+ *
3463
+ * @param {String} pathToMigrations
3464
+ * @returns {Promise<Array<String>>} matching migration filePaths
3465
+ */
3466
+ const getMigrationFilePaths = async (pathToMigrations) => {
3467
+ const filePath = (pattern) => `${pathToMigrations}${pattern}`;
3468
+ return sortFilePathsByFilename(await Ze(filePath("/**/*.js"), { ignore: [
3469
+ filePath("/**/*.skip?([0-9]*).js"),
3470
+ filePath("/**/index.js"),
3471
+ filePath("/**/plan.json"),
3472
+ filePath("/**/*.bundle.js"),
3473
+ filePath("/**/*.test.js"),
3474
+ filePath("/**/*.spec.js"),
3475
+ filePath("/**/__tests__/*"),
3476
+ filePath("/**/__test__/*")
3477
+ ] }));
3478
+ };
3479
+ /**
3480
+ * Gets paths to skipped migrations in a directory
3481
+ *
3482
+ * @param {String} pathToMigrations
3483
+ * @returns {Promise<Array<String>>} skipped migration filePaths
3484
+ */
3485
+ const getSkippedFilePaths = async (pathToMigrations) => {
3486
+ const filePath = (pattern) => `${pathToMigrations}${pattern}`;
3487
+ return sortFilePathsByFilename(await Ze(filePath("/**/*.skip?([0-9]*).js"), { ignore: [
3488
+ filePath("/**/index.js"),
3489
+ filePath("/**/plan.json"),
3490
+ filePath("/**/*.bundle.js"),
3491
+ filePath("/**/*.test.js"),
3492
+ filePath("/**/*.spec.js"),
3493
+ filePath("/**/__tests__/*"),
3494
+ filePath("/**/__test__/*")
3495
+ ] }));
3496
+ };
3497
+ //#endregion
3498
+ //#region node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.js
3499
+ const ANSI_BACKGROUND_OFFSET = 10;
3500
+ const wrapAnsi16 = (offset = 0) => (code) => `\u001B[${code + offset}m`;
3501
+ const wrapAnsi256 = (offset = 0) => (code) => `\u001B[${38 + offset};5;${code}m`;
3502
+ const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u001B[${38 + offset};2;${red};${green};${blue}m`;
3503
+ const styles$1 = {
3504
+ modifier: {
3505
+ reset: [0, 0],
3506
+ bold: [1, 22],
3507
+ dim: [2, 22],
3508
+ italic: [3, 23],
3509
+ underline: [4, 24],
3510
+ overline: [53, 55],
3511
+ inverse: [7, 27],
3512
+ hidden: [8, 28],
3513
+ strikethrough: [9, 29]
3514
+ },
3515
+ color: {
3516
+ black: [30, 39],
3517
+ red: [31, 39],
3518
+ green: [32, 39],
3519
+ yellow: [33, 39],
3520
+ blue: [34, 39],
3521
+ magenta: [35, 39],
3522
+ cyan: [36, 39],
3523
+ white: [37, 39],
3524
+ blackBright: [90, 39],
3525
+ gray: [90, 39],
3526
+ grey: [90, 39],
3527
+ redBright: [91, 39],
3528
+ greenBright: [92, 39],
3529
+ yellowBright: [93, 39],
3530
+ blueBright: [94, 39],
3531
+ magentaBright: [95, 39],
3532
+ cyanBright: [96, 39],
3533
+ whiteBright: [97, 39]
3534
+ },
3535
+ bgColor: {
3536
+ bgBlack: [40, 49],
3537
+ bgRed: [41, 49],
3538
+ bgGreen: [42, 49],
3539
+ bgYellow: [43, 49],
3540
+ bgBlue: [44, 49],
3541
+ bgMagenta: [45, 49],
3542
+ bgCyan: [46, 49],
3543
+ bgWhite: [47, 49],
3544
+ bgBlackBright: [100, 49],
3545
+ bgGray: [100, 49],
3546
+ bgGrey: [100, 49],
3547
+ bgRedBright: [101, 49],
3548
+ bgGreenBright: [102, 49],
3549
+ bgYellowBright: [103, 49],
3550
+ bgBlueBright: [104, 49],
3551
+ bgMagentaBright: [105, 49],
3552
+ bgCyanBright: [106, 49],
3553
+ bgWhiteBright: [107, 49]
3554
+ }
3555
+ };
3556
+ Object.keys(styles$1.modifier);
3557
+ const foregroundColorNames = Object.keys(styles$1.color);
3558
+ const backgroundColorNames = Object.keys(styles$1.bgColor);
3559
+ [...foregroundColorNames, ...backgroundColorNames];
3560
+ function assembleStyles() {
3561
+ const codes = /* @__PURE__ */ new Map();
3562
+ for (const [groupName, group] of Object.entries(styles$1)) {
3563
+ for (const [styleName, style] of Object.entries(group)) {
3564
+ styles$1[styleName] = {
3565
+ open: `\u001B[${style[0]}m`,
3566
+ close: `\u001B[${style[1]}m`
3567
+ };
3568
+ group[styleName] = styles$1[styleName];
3569
+ codes.set(style[0], style[1]);
3570
+ }
3571
+ Object.defineProperty(styles$1, groupName, {
3572
+ value: group,
3573
+ enumerable: false
3574
+ });
3575
+ }
3576
+ Object.defineProperty(styles$1, "codes", {
3577
+ value: codes,
3578
+ enumerable: false
3579
+ });
3580
+ styles$1.color.close = "\x1B[39m";
3581
+ styles$1.bgColor.close = "\x1B[49m";
3582
+ styles$1.color.ansi = wrapAnsi16();
3583
+ styles$1.color.ansi256 = wrapAnsi256();
3584
+ styles$1.color.ansi16m = wrapAnsi16m();
3585
+ styles$1.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
3586
+ styles$1.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
3587
+ styles$1.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
3588
+ Object.defineProperties(styles$1, {
3589
+ rgbToAnsi256: {
3590
+ value(red, green, blue) {
3591
+ if (red === green && green === blue) {
3592
+ if (red < 8) return 16;
3593
+ if (red > 248) return 231;
3594
+ return Math.round((red - 8) / 247 * 24) + 232;
3595
+ }
3596
+ return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
3597
+ },
3598
+ enumerable: false
3599
+ },
3600
+ hexToRgb: {
3601
+ value(hex) {
3602
+ const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
3603
+ if (!matches) return [
3604
+ 0,
3605
+ 0,
3606
+ 0
3607
+ ];
3608
+ let [colorString] = matches;
3609
+ if (colorString.length === 3) colorString = [...colorString].map((character) => character + character).join("");
3610
+ const integer = Number.parseInt(colorString, 16);
3611
+ return [
3612
+ integer >> 16 & 255,
3613
+ integer >> 8 & 255,
3614
+ integer & 255
3615
+ ];
3616
+ },
3617
+ enumerable: false
3618
+ },
3619
+ hexToAnsi256: {
3620
+ value: (hex) => styles$1.rgbToAnsi256(...styles$1.hexToRgb(hex)),
3621
+ enumerable: false
3622
+ },
3623
+ ansi256ToAnsi: {
3624
+ value(code) {
3625
+ if (code < 8) return 30 + code;
3626
+ if (code < 16) return 90 + (code - 8);
3627
+ let red;
3628
+ let green;
3629
+ let blue;
3630
+ if (code >= 232) {
3631
+ red = ((code - 232) * 10 + 8) / 255;
3632
+ green = red;
3633
+ blue = red;
3634
+ } else {
3635
+ code -= 16;
3636
+ const remainder = code % 36;
3637
+ red = Math.floor(code / 36) / 5;
3638
+ green = Math.floor(remainder / 6) / 5;
3639
+ blue = remainder % 6 / 5;
3640
+ }
3641
+ const value = Math.max(red, green, blue) * 2;
3642
+ if (value === 0) return 30;
3643
+ let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
3644
+ if (value === 2) result += 60;
3645
+ return result;
3646
+ },
3647
+ enumerable: false
3648
+ },
3649
+ rgbToAnsi: {
3650
+ value: (red, green, blue) => styles$1.ansi256ToAnsi(styles$1.rgbToAnsi256(red, green, blue)),
3651
+ enumerable: false
3652
+ },
3653
+ hexToAnsi: {
3654
+ value: (hex) => styles$1.ansi256ToAnsi(styles$1.hexToAnsi256(hex)),
3655
+ enumerable: false
3656
+ }
3657
+ });
3658
+ return styles$1;
3659
+ }
3660
+ const ansiStyles = assembleStyles();
3661
+ //#endregion
3662
+ //#region node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/supports-color/index.js
3663
+ function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process$1.argv) {
3664
+ const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
3665
+ const position = argv.indexOf(prefix + flag);
3666
+ const terminatorPosition = argv.indexOf("--");
3667
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
3668
+ }
3669
+ const { env } = process$1;
3670
+ let flagForceColor;
3671
+ if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) flagForceColor = 0;
3672
+ else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) flagForceColor = 1;
3673
+ function envForceColor() {
3674
+ if ("FORCE_COLOR" in env) {
3675
+ if (env.FORCE_COLOR === "true") return 1;
3676
+ if (env.FORCE_COLOR === "false") return 0;
3677
+ return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
3678
+ }
3679
+ }
3680
+ function translateLevel(level) {
3681
+ if (level === 0) return false;
3682
+ return {
3683
+ level,
3684
+ hasBasic: true,
3685
+ has256: level >= 2,
3686
+ has16m: level >= 3
3687
+ };
3688
+ }
3689
+ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
3690
+ const noFlagForceColor = envForceColor();
3691
+ if (noFlagForceColor !== void 0) flagForceColor = noFlagForceColor;
3692
+ const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
3693
+ if (forceColor === 0) return 0;
3694
+ if (sniffFlags) {
3695
+ if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) return 3;
3696
+ if (hasFlag("color=256")) return 2;
3697
+ }
3698
+ if ("TF_BUILD" in env && "AGENT_NAME" in env) return 1;
3699
+ if (haveStream && !streamIsTTY && forceColor === void 0) return 0;
3700
+ const min = forceColor || 0;
3701
+ if (env.TERM === "dumb") return min;
3702
+ if (process$1.platform === "win32") {
3703
+ const osRelease = os.release().split(".");
3704
+ if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) return Number(osRelease[2]) >= 14931 ? 3 : 2;
3705
+ return 1;
3706
+ }
3707
+ if ("CI" in env) {
3708
+ if ([
3709
+ "GITHUB_ACTIONS",
3710
+ "GITEA_ACTIONS",
3711
+ "CIRCLECI"
3712
+ ].some((key) => key in env)) return 3;
3713
+ if ([
3714
+ "TRAVIS",
3715
+ "APPVEYOR",
3716
+ "GITLAB_CI",
3717
+ "BUILDKITE",
3718
+ "DRONE"
3719
+ ].some((sign) => sign in env) || env.CI_NAME === "codeship") return 1;
3720
+ return min;
3721
+ }
3722
+ if ("TEAMCITY_VERSION" in env) return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
3723
+ if (env.COLORTERM === "truecolor") return 3;
3724
+ if (env.TERM === "xterm-kitty") return 3;
3725
+ if (env.TERM === "xterm-ghostty") return 3;
3726
+ if (env.TERM === "wezterm") return 3;
3727
+ if ("TERM_PROGRAM" in env) {
3728
+ const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
3729
+ switch (env.TERM_PROGRAM) {
3730
+ case "iTerm.app": return version >= 3 ? 3 : 2;
3731
+ case "Apple_Terminal": return 2;
3732
+ }
3733
+ }
3734
+ if (/-256(color)?$/i.test(env.TERM)) return 2;
3735
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) return 1;
3736
+ if ("COLORTERM" in env) return 1;
3737
+ return min;
3738
+ }
3739
+ function createSupportsColor(stream, options = {}) {
3740
+ return translateLevel(_supportsColor(stream, {
3741
+ streamIsTTY: stream && stream.isTTY,
3742
+ ...options
3743
+ }));
3744
+ }
3745
+ const supportsColor = {
3746
+ stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
3747
+ stderr: createSupportsColor({ isTTY: tty.isatty(2) })
3748
+ };
3749
+ //#endregion
3750
+ //#region node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/utilities.js
3751
+ function stringReplaceAll(string, substring, replacer) {
3752
+ let index = string.indexOf(substring);
3753
+ if (index === -1) return string;
3754
+ const substringLength = substring.length;
3755
+ let endIndex = 0;
3756
+ let returnValue = "";
3757
+ do {
3758
+ returnValue += string.slice(endIndex, index) + substring + replacer;
3759
+ endIndex = index + substringLength;
3760
+ index = string.indexOf(substring, endIndex);
3761
+ } while (index !== -1);
3762
+ returnValue += string.slice(endIndex);
3763
+ return returnValue;
3764
+ }
3765
+ function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
3766
+ let endIndex = 0;
3767
+ let returnValue = "";
3768
+ do {
3769
+ const gotCR = string[index - 1] === "\r";
3770
+ returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
3771
+ endIndex = index + 1;
3772
+ index = string.indexOf("\n", endIndex);
3773
+ } while (index !== -1);
3774
+ returnValue += string.slice(endIndex);
3775
+ return returnValue;
3776
+ }
3777
+ //#endregion
3778
+ //#region node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/index.js
3779
+ const { stdout: stdoutColor, stderr: stderrColor } = supportsColor;
3780
+ const GENERATOR = Symbol("GENERATOR");
3781
+ const STYLER = Symbol("STYLER");
3782
+ const IS_EMPTY = Symbol("IS_EMPTY");
3783
+ const levelMapping = [
3784
+ "ansi",
3785
+ "ansi",
3786
+ "ansi256",
3787
+ "ansi16m"
3788
+ ];
3789
+ const styles = Object.create(null);
3790
+ const applyOptions = (object, options = {}) => {
3791
+ if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) throw new Error("The `level` option should be an integer from 0 to 3");
3792
+ const colorLevel = stdoutColor ? stdoutColor.level : 0;
3793
+ object.level = options.level === void 0 ? colorLevel : options.level;
3794
+ };
3795
+ const chalkFactory = (options) => {
3796
+ const chalk = (...strings) => strings.join(" ");
3797
+ applyOptions(chalk, options);
3798
+ Object.setPrototypeOf(chalk, createChalk.prototype);
3799
+ return chalk;
3800
+ };
3801
+ function createChalk(options) {
3802
+ return chalkFactory(options);
3803
+ }
3804
+ Object.setPrototypeOf(createChalk.prototype, Function.prototype);
3805
+ for (const [styleName, style] of Object.entries(ansiStyles)) styles[styleName] = { get() {
3806
+ const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
3807
+ Object.defineProperty(this, styleName, { value: builder });
3808
+ return builder;
3809
+ } };
3810
+ styles.visible = { get() {
3811
+ const builder = createBuilder(this, this[STYLER], true);
3812
+ Object.defineProperty(this, "visible", { value: builder });
3813
+ return builder;
3814
+ } };
3815
+ const getModelAnsi = (model, level, type, ...arguments_) => {
3816
+ if (model === "rgb") {
3817
+ if (level === "ansi16m") return ansiStyles[type].ansi16m(...arguments_);
3818
+ if (level === "ansi256") return ansiStyles[type].ansi256(ansiStyles.rgbToAnsi256(...arguments_));
3819
+ return ansiStyles[type].ansi(ansiStyles.rgbToAnsi(...arguments_));
3820
+ }
3821
+ if (model === "hex") return getModelAnsi("rgb", level, type, ...ansiStyles.hexToRgb(...arguments_));
3822
+ return ansiStyles[type][model](...arguments_);
3823
+ };
3824
+ for (const model of [
3825
+ "rgb",
3826
+ "hex",
3827
+ "ansi256"
3828
+ ]) {
3829
+ styles[model] = { get() {
3830
+ const { level } = this;
3831
+ return function(...arguments_) {
3832
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansiStyles.color.close, this[STYLER]);
3833
+ return createBuilder(this, styler, this[IS_EMPTY]);
3834
+ };
3835
+ } };
3836
+ const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
3837
+ styles[bgModel] = { get() {
3838
+ const { level } = this;
3839
+ return function(...arguments_) {
3840
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansiStyles.bgColor.close, this[STYLER]);
3841
+ return createBuilder(this, styler, this[IS_EMPTY]);
3842
+ };
3843
+ } };
3844
+ }
3845
+ const proto = Object.defineProperties(() => {}, {
3846
+ ...styles,
3847
+ level: {
3848
+ enumerable: true,
3849
+ get() {
3850
+ return this[GENERATOR].level;
3851
+ },
3852
+ set(level) {
3853
+ this[GENERATOR].level = level;
3854
+ }
3855
+ }
3856
+ });
3857
+ const createStyler = (open, close, parent) => {
3858
+ let openAll;
3859
+ let closeAll;
3860
+ if (parent === void 0) {
3861
+ openAll = open;
3862
+ closeAll = close;
3863
+ } else {
3864
+ openAll = parent.openAll + open;
3865
+ closeAll = close + parent.closeAll;
3866
+ }
3867
+ return {
3868
+ open,
3869
+ close,
3870
+ openAll,
3871
+ closeAll,
3872
+ parent
3873
+ };
3874
+ };
3875
+ const createBuilder = (self, _styler, _isEmpty) => {
3876
+ const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
3877
+ Object.setPrototypeOf(builder, proto);
3878
+ builder[GENERATOR] = self;
3879
+ builder[STYLER] = _styler;
3880
+ builder[IS_EMPTY] = _isEmpty;
3881
+ return builder;
3882
+ };
3883
+ const applyStyle = (self, string) => {
3884
+ if (self.level <= 0 || !string) return self[IS_EMPTY] ? "" : string;
3885
+ let styler = self[STYLER];
3886
+ if (styler === void 0) return string;
3887
+ const { openAll, closeAll } = styler;
3888
+ if (string.includes("\x1B")) while (styler !== void 0) {
3889
+ string = stringReplaceAll(string, styler.close, styler.open);
3890
+ styler = styler.parent;
3891
+ }
3892
+ const lfIndex = string.indexOf("\n");
3893
+ if (lfIndex !== -1) string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
3894
+ return openAll + string + closeAll;
3895
+ };
3896
+ Object.defineProperties(createChalk.prototype, styles);
3897
+ const chalk = createChalk();
3898
+ createChalk({ level: stderrColor ? stderrColor.level : 0 });
3899
+ //#endregion
3900
+ //#region src/validator/ajv-validators.ts
3901
+ const planSchemaValidator = validate14;
3902
+ const schema32 = {
3903
+ "type": "array",
3904
+ "items": {
3905
+ "type": "object",
3906
+ "properties": {
3907
+ "fileHash": { "type": ["string"] },
3908
+ "fileName": { "type": "string" },
3909
+ "sequence": {
3910
+ "type": "string",
3911
+ "pattern": "^[1-9][0-9]*(.[1-9][0-9]*)*$"
3912
+ }
3913
+ },
3914
+ "required": [
3915
+ "fileHash",
3916
+ "fileName",
3917
+ "sequence"
3918
+ ],
3919
+ "additionalProperties": false
3920
+ }
3921
+ };
3922
+ const pattern0 = /* @__PURE__ */ new RegExp("^[1-9][0-9]*(.[1-9][0-9]*)*$", "u");
3923
+ function validate14(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
3924
+ let vErrors = null;
3925
+ let errors = 0;
3926
+ if (Array.isArray(data)) {
3927
+ const len0 = data.length;
3928
+ for (let i0 = 0; i0 < len0; i0++) {
3929
+ let data0 = data[i0];
3930
+ if (data0 && typeof data0 == "object" && !Array.isArray(data0)) {
3931
+ if (data0.fileHash === void 0) {
3932
+ const err0 = {
3933
+ instancePath: instancePath + "/" + i0,
3934
+ schemaPath: "#/items/required",
3935
+ keyword: "required",
3936
+ params: { missingProperty: "fileHash" },
3937
+ message: "must have required property 'fileHash'"
3938
+ };
3939
+ if (vErrors === null) vErrors = [err0];
3940
+ else vErrors.push(err0);
3941
+ errors++;
3942
+ }
3943
+ if (data0.fileName === void 0) {
3944
+ const err1 = {
3945
+ instancePath: instancePath + "/" + i0,
3946
+ schemaPath: "#/items/required",
3947
+ keyword: "required",
3948
+ params: { missingProperty: "fileName" },
3949
+ message: "must have required property 'fileName'"
3950
+ };
3951
+ if (vErrors === null) vErrors = [err1];
3952
+ else vErrors.push(err1);
3953
+ errors++;
3954
+ }
3955
+ if (data0.sequence === void 0) {
3956
+ const err2 = {
3957
+ instancePath: instancePath + "/" + i0,
3958
+ schemaPath: "#/items/required",
3959
+ keyword: "required",
3960
+ params: { missingProperty: "sequence" },
3961
+ message: "must have required property 'sequence'"
3962
+ };
3963
+ if (vErrors === null) vErrors = [err2];
3964
+ else vErrors.push(err2);
3965
+ errors++;
3966
+ }
3967
+ for (const key0 in data0) if (!(key0 === "fileHash" || key0 === "fileName" || key0 === "sequence")) {
3968
+ const err3 = {
3969
+ instancePath: instancePath + "/" + i0,
3970
+ schemaPath: "#/items/additionalProperties",
3971
+ keyword: "additionalProperties",
3972
+ params: { additionalProperty: key0 },
3973
+ message: "must NOT have additional properties"
3974
+ };
3975
+ if (vErrors === null) vErrors = [err3];
3976
+ else vErrors.push(err3);
3977
+ errors++;
3978
+ }
3979
+ if (data0.fileHash !== void 0) {
3980
+ if (typeof data0.fileHash !== "string") {
3981
+ const err4 = {
3982
+ instancePath: instancePath + "/" + i0 + "/fileHash",
3983
+ schemaPath: "#/items/properties/fileHash/type",
3984
+ keyword: "type",
3985
+ params: { type: schema32.items.properties.fileHash.type },
3986
+ message: "must be string"
3987
+ };
3988
+ if (vErrors === null) vErrors = [err4];
3989
+ else vErrors.push(err4);
3990
+ errors++;
3991
+ }
3992
+ }
3993
+ if (data0.fileName !== void 0) {
3994
+ if (typeof data0.fileName !== "string") {
3995
+ const err5 = {
3996
+ instancePath: instancePath + "/" + i0 + "/fileName",
3997
+ schemaPath: "#/items/properties/fileName/type",
3998
+ keyword: "type",
3999
+ params: { type: "string" },
4000
+ message: "must be string"
4001
+ };
4002
+ if (vErrors === null) vErrors = [err5];
4003
+ else vErrors.push(err5);
4004
+ errors++;
4005
+ }
4006
+ }
4007
+ if (data0.sequence !== void 0) {
4008
+ let data3 = data0.sequence;
4009
+ if (typeof data3 === "string") {
4010
+ if (!pattern0.test(data3)) {
4011
+ const err6 = {
4012
+ instancePath: instancePath + "/" + i0 + "/sequence",
4013
+ schemaPath: "#/items/properties/sequence/pattern",
4014
+ keyword: "pattern",
4015
+ params: { pattern: "^[1-9][0-9]*(.[1-9][0-9]*)*$" },
4016
+ message: "must match pattern \"^[1-9][0-9]*(.[1-9][0-9]*)*$\""
4017
+ };
4018
+ if (vErrors === null) vErrors = [err6];
4019
+ else vErrors.push(err6);
4020
+ errors++;
4021
+ }
4022
+ } else {
4023
+ const err7 = {
4024
+ instancePath: instancePath + "/" + i0 + "/sequence",
4025
+ schemaPath: "#/items/properties/sequence/type",
4026
+ keyword: "type",
4027
+ params: { type: "string" },
4028
+ message: "must be string"
4029
+ };
4030
+ if (vErrors === null) vErrors = [err7];
4031
+ else vErrors.push(err7);
4032
+ errors++;
4033
+ }
4034
+ }
4035
+ } else {
4036
+ const err8 = {
4037
+ instancePath: instancePath + "/" + i0,
4038
+ schemaPath: "#/items/type",
4039
+ keyword: "type",
4040
+ params: { type: "object" },
4041
+ message: "must be object"
4042
+ };
4043
+ if (vErrors === null) vErrors = [err8];
4044
+ else vErrors.push(err8);
4045
+ errors++;
4046
+ }
4047
+ }
4048
+ } else {
4049
+ const err9 = {
4050
+ instancePath,
4051
+ schemaPath: "#/type",
4052
+ keyword: "type",
4053
+ params: { type: "array" },
4054
+ message: "must be array"
4055
+ };
4056
+ if (vErrors === null) vErrors = [err9];
4057
+ else vErrors.push(err9);
4058
+ errors++;
4059
+ }
4060
+ validate14.errors = vErrors;
4061
+ return errors === 0;
4062
+ }
4063
+ //#endregion
4064
+ //#region src/validator/validator.ts
4065
+ const isNonEmptyString = (input) => isString(input) && input.length > 0;
4066
+ /**
4067
+ * Validates if a plan matches the schema
4068
+ */
4069
+ const validatePlan = (plan) => {
4070
+ const valid = planSchemaValidator(plan);
4071
+ const errors = planSchemaValidator.errors;
4072
+ if (errors?.length) errors.forEach((e) => console.error(`${e.message}${e.instancePath ? `at ${e.instancePath}` : ""}`));
4073
+ return valid;
4074
+ };
4075
+ /**
4076
+ * Validates if file description format is valid
4077
+ */
4078
+ const validateFileDescription = (description) => {
4079
+ if (!description) return false;
4080
+ return /^([a-z]+|(([a-z]+-)+[a-z]+))$/g.test(description);
4081
+ };
4082
+ /**
4083
+ * Validates if fileName format is valid
4084
+ */
4085
+ const validateFileName = (fileName) => {
4086
+ return /^([a-z]+|(([a-z]+-)+[a-z]+))(.js|.skip.js)$/g.test(fileName);
4087
+ };
4088
+ /**
4089
+ * Throws if file names are invalid
4090
+ */
4091
+ const throwIfFileNamesInvalid = (fileEntries) => {
4092
+ const invalidFileNames = fileEntries.filter((f) => !f.isValidFileName).map((f) => f.fileName);
4093
+ if (invalidFileNames.length) {
4094
+ invalidFileNames.forEach((name) => console.error(chalk.red(name)));
4095
+ throw new Error("Invalid migration filename format (use kebab-case)");
4072
4096
  }
4073
- return 0;
4074
4097
  };
4075
- //#endregion
4076
- //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/compat/_internal/isKey.mjs
4077
- const regexIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
4078
- const regexIsPlainProp = /^\w*$/;
4079
- function isKey(value, object) {
4080
- if (Array.isArray(value)) return false;
4081
- if (typeof value === "number" || typeof value === "boolean" || value == null || isSymbol(value)) return true;
4082
- return typeof value === "string" && (regexIsPlainProp.test(value) || !regexIsDeepProp.test(value)) || object != null && Object.hasOwn(object, value);
4083
- }
4084
- //#endregion
4085
- //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/compat/array/orderBy.mjs
4086
- function orderBy(collection, criteria, orders, guard) {
4087
- if (collection == null) return [];
4088
- orders = guard ? void 0 : orders;
4089
- if (!Array.isArray(collection)) collection = Object.values(collection);
4090
- if (!Array.isArray(criteria)) criteria = criteria == null ? [null] : [criteria];
4091
- if (criteria.length === 0) criteria = [null];
4092
- if (!Array.isArray(orders)) orders = orders == null ? [] : [orders];
4093
- orders = orders.map((order) => String(order));
4094
- const getValueByNestedPath = (object, path) => {
4095
- let target = object;
4096
- for (let i = 0; i < path.length && target != null; ++i) target = target[path[i]];
4097
- return target;
4098
- };
4099
- const getValueByCriterion = (criterion, object) => {
4100
- if (object == null || criterion == null) return object;
4101
- if (typeof criterion === "object" && "key" in criterion) {
4102
- if (Object.hasOwn(object, criterion.key)) return object[criterion.key];
4103
- return getValueByNestedPath(object, criterion.path);
4104
- }
4105
- if (typeof criterion === "function") return criterion(object);
4106
- if (Array.isArray(criterion)) return getValueByNestedPath(object, criterion);
4107
- if (typeof object === "object") return object[criterion];
4108
- return object;
4109
- };
4110
- const preparedCriteria = criteria.map((criterion) => {
4111
- if (Array.isArray(criterion) && criterion.length === 1) criterion = criterion[0];
4112
- if (criterion == null || typeof criterion === "function" || Array.isArray(criterion) || isKey(criterion)) return criterion;
4113
- return {
4114
- key: criterion,
4115
- path: toPath(criterion)
4116
- };
4117
- });
4118
- return collection.map((item) => ({
4119
- original: item,
4120
- criteria: preparedCriteria.map((criterion) => getValueByCriterion(criterion, item))
4121
- })).slice().sort((a, b) => {
4122
- for (let i = 0; i < preparedCriteria.length; i++) {
4123
- const comparedResult = compareValues(a.criteria[i], b.criteria[i], orders[i]);
4124
- if (comparedResult !== 0) return comparedResult;
4125
- }
4126
- return 0;
4127
- }).map((item) => item.original);
4128
- }
4129
- //#endregion
4130
- //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/compat/array/sortBy.mjs
4131
- function sortBy(collection, ...criteria) {
4132
- const length = criteria.length;
4133
- if (length > 1 && isIterateeCall(collection, criteria[0], criteria[1])) criteria = [];
4134
- else if (length > 2 && isIterateeCall(criteria[0], criteria[1], criteria[2])) criteria = [criteria[0]];
4135
- return orderBy(collection, flatten(criteria), ["asc"]);
4136
- }
4137
- //#endregion
4138
- //#region src/glob/glob.ts
4139
4098
  /**
4140
- * Sorts migration file paths
4141
- *
4142
- * @param {Array<String>} filePaths
4143
- * @returns {Array<String>} sorted files
4099
+ * Warns if files have been removed
4144
4100
  */
4145
- const sortFilePathsByFilename = (filePaths) => sortBy(filePaths, (file) => {
4146
- return path.parse(file).base;
4147
- });
4101
+ const warnIfFilesHaveBeenRemovedFromPlan = (migrationEntries, historicalMigrations) => {
4102
+ const fileNames = migrationEntries.map((f) => f.fileName);
4103
+ const deletedFilesNames = historicalMigrations.filter((e) => !fileNames.includes(e.fileName)).map((e) => e.fileName);
4104
+ if (deletedFilesNames.length) {
4105
+ deletedFilesNames.forEach((name) => console.warn(chalk.yellow(name)));
4106
+ console.warn(chalk.yellow("Previously executed migration files have been deleted from plan.json (rename file to .skip.js and replace with a new file instead)"));
4107
+ }
4108
+ };
4148
4109
  /**
4149
- * Gets paths to entity migrations in a directory
4150
- *
4151
- * @param {String} pathToMigrations
4152
- * @returns {Promise<Array<String>>} matching migration filePaths
4110
+ * Throws error if any pre-existing file has changed
4153
4111
  */
4154
- const getMigrationFilePaths = async (pathToMigrations) => {
4155
- const filePath = (pattern) => `${pathToMigrations}${pattern}`;
4156
- return sortFilePathsByFilename(await Ze(filePath("/**/*.js"), { ignore: [
4157
- filePath("/**/*.skip?([0-9]*).js"),
4158
- filePath("/**/index.js"),
4159
- filePath("/**/plan.json"),
4160
- filePath("/**/*.bundle.js"),
4161
- filePath("/**/*.test.js"),
4162
- filePath("/**/*.spec.js"),
4163
- filePath("/**/__tests__/*"),
4164
- filePath("/**/__test__/*")
4165
- ] }));
4112
+ const throwIfFilesHaveChanged = (migrationEntries) => {
4113
+ const changedFilesNames = migrationEntries.filter((m) => {
4114
+ const { fileHash, fileHashFromPlan, fileHashFromHistory, skippedFileHashes } = m;
4115
+ const matchesHistory = !isNonEmptyString(fileHashFromHistory) || [fileHash].concat(skippedFileHashes).includes(fileHashFromHistory);
4116
+ const matchesPlan = !isNonEmptyString(fileHashFromPlan) || [fileHash].concat(skippedFileHashes).includes(fileHashFromPlan);
4117
+ return !(matchesHistory && matchesPlan);
4118
+ }).map((f) => f.fileName);
4119
+ if (changedFilesNames.length) {
4120
+ changedFilesNames.forEach((name) => console.error(chalk.red(name)));
4121
+ throw new Error("Not allowed to change migration files (for unreleased local work, you can use the `force` option)");
4122
+ }
4166
4123
  };
4167
4124
  /**
4168
- * Gets paths to skipped migrations in a directory
4169
- *
4170
- * @param {String} pathToMigrations
4171
- * @returns {Promise<Array<String>>} skipped migration filePaths
4125
+ * Throws error if previous sequence numbers have changed
4172
4126
  */
4173
- const getSkippedFilePaths = async (pathToMigrations) => {
4174
- const filePath = (pattern) => `${pathToMigrations}${pattern}`;
4175
- return sortFilePathsByFilename(await Ze(filePath("/**/*.skip?([0-9]*).js"), { ignore: [
4176
- filePath("/**/index.js"),
4177
- filePath("/**/plan.json"),
4178
- filePath("/**/*.bundle.js"),
4179
- filePath("/**/*.test.js"),
4180
- filePath("/**/*.spec.js"),
4181
- filePath("/**/__tests__/*"),
4182
- filePath("/**/__test__/*")
4183
- ] }));
4127
+ const throwIfSequenceHasChanged = (migrationEntries) => {
4128
+ const changeSequences = migrationEntries.filter((m) => {
4129
+ const { sequence, sequenceFromHistory } = m;
4130
+ return isString(sequenceFromHistory) && sequenceFromHistory !== sequence;
4131
+ }).map((f) => f.fileName);
4132
+ if (changeSequences.length) {
4133
+ changeSequences.forEach((name) => console.error(chalk.red(name)));
4134
+ throw new Error("Not allowed to change migration sequences in plan.json");
4135
+ }
4136
+ };
4137
+ /**
4138
+ * Throws error if sequence numbers are not unique
4139
+ */
4140
+ const throwIfSequenceNotUnique = (migrationEntries) => {
4141
+ const repeatedSequenceNumbers = migrationEntries.map((f) => f.sequence).filter(((s) => (v) => s.has(v) || !s.add(v))(/* @__PURE__ */ new Set()));
4142
+ const duplicates = migrationEntries.filter((f) => repeatedSequenceNumbers.includes(f.sequence)).map((f) => f.fileName);
4143
+ if (duplicates.length) {
4144
+ duplicates.forEach((fileName) => console.error(chalk.red(fileName)));
4145
+ throw new Error("Migrations must have unique sequence numbers in plan.json");
4146
+ }
4147
+ };
4148
+ /**
4149
+ * Throws error if sequence numbers are not unique
4150
+ */
4151
+ const throwIfSequenceHasIntegerGaps = (migrationEntries) => {
4152
+ const toInteger = (sequence) => parseInt(sequence.split(".")[0], 10);
4153
+ const unique = (arr) => Array.from(new Set(arr));
4154
+ const orderedUniqueSequenceIntegers = unique(migrationEntries.map((s) => s.sequence).map((s) => toInteger(s))).sort((a, b) => a - b);
4155
+ const max = orderedUniqueSequenceIntegers[orderedUniqueSequenceIntegers.length - 1];
4156
+ const missing = xor(orderedUniqueSequenceIntegers, Array.from({ length: max }, (_v, k) => k + 1));
4157
+ if (missing.length) throw new Error(`Migration sequence numbers in plan.json have unexpected gaps: ${missing.join(", ")}`);
4158
+ };
4159
+ /**
4160
+ * Throws error if file names are not unique
4161
+ */
4162
+ const throwIfFileNamesNotUnique = (migrationEntries) => {
4163
+ const repeatedFileNames = migrationEntries.map((f) => f.fileName).filter(((s) => (v) => s.has(v) || !s.add(v))(/* @__PURE__ */ new Set()));
4164
+ if (repeatedFileNames.length) {
4165
+ repeatedFileNames.forEach((fileName) => console.error(chalk.red(fileName)));
4166
+ throw new Error("Migration file names must be unique");
4167
+ }
4168
+ };
4169
+ /**
4170
+ * Throws error if files listed in plan.json are found
4171
+ */
4172
+ const throwIfFilesNotFound = (migrationEntries) => {
4173
+ const migrationsWithoutFiles = migrationEntries.filter((m) => !m.script || !m.script && !m.migrator);
4174
+ if (migrationsWithoutFiles.length) {
4175
+ migrationsWithoutFiles.forEach((migration) => console.error(chalk.red(migration.fileName)));
4176
+ throw new Error("Migration files from plan.json are missing from filesystem");
4177
+ }
4184
4178
  };
4185
4179
  //#endregion
4186
4180
  //#region src/database/database.ts
@@ -4444,12 +4438,21 @@ const getPlannedMigrations = async ({ config }) => {
4444
4438
  if (!await migrationTablesExist(database, entity)) await createMigrationsTables(database, entity);
4445
4439
  }
4446
4440
  const rawPlan = await readPlan(directory);
4447
- const plannedMigrations = parsePlan$1(rawPlan).map((m) => ({
4441
+ const parsedPlan = parsePlan$1(rawPlan);
4442
+ const plannedMigrations = parsedPlan.map((m) => ({
4448
4443
  fileHashFromPlan: m.fileHash,
4449
4444
  fileName: m.fileName,
4450
4445
  sequence: m.sequence
4451
4446
  }));
4452
4447
  const filePaths = await getMigrationFilePaths(directory);
4448
+ const missingFileNames = filePaths.map((filePath) => {
4449
+ return path.basename(filePath);
4450
+ }).filter((fileName) => {
4451
+ return !parsedPlan.some((entry) => {
4452
+ return entry.fileName === fileName;
4453
+ });
4454
+ });
4455
+ if (missingFileNames.length) throw new Error(`Migration files are missing from plan.json: ${missingFileNames.join(", ")}. Add them to plan.json and re-run the migrator.`);
4453
4456
  const skippedFilePaths = await getSkippedFilePaths(directory);
4454
4457
  const plannedMigrationsWithFileEntries = await Promise.all(plannedMigrations.map(async (m) => {
4455
4458
  const { fileName } = m;
@@ -4498,7 +4501,8 @@ const getPlannedMigrations = async ({ config }) => {
4498
4501
  const validatedPlannedMigrations = generatePlanEntries(plannedMigrationsWithHistory);
4499
4502
  const validatedPlan = JSON.stringify(validatedPlannedMigrations, null, 2);
4500
4503
  const nextVersion = hash(validatedPlan);
4501
- if (!dry && validatedPlan !== rawPlan) await writePlan(directory, validatedPlan);
4504
+ const planHasChanged = validatedPlan !== rawPlan;
4505
+ if (!dry && planHasChanged) await writePlan(directory, validatedPlan);
4502
4506
  if (database && !dry) {
4503
4507
  await replaceMigrationsRecords(database, pgpHelpers, entity, validatedPlannedMigrations);
4504
4508
  await insertVersions(database, pgpHelpers, entity, [{
@@ -4509,11 +4513,28 @@ const getPlannedMigrations = async ({ config }) => {
4509
4513
  return {
4510
4514
  validatedPlan: validatedPlannedMigrations,
4511
4515
  plannedMigrations: await loadMigrationFunctions(plannedMigrationsWithHistory),
4512
- nextVersion
4516
+ nextVersion,
4517
+ planHasChanged
4513
4518
  };
4514
4519
  };
4515
4520
  const PlanModule = { getPlannedMigrations };
4516
4521
  //#endregion
4522
+ //#region src/plan/check-migration-plan.ts
4523
+ /** Check the plan as a real migrator run would, without modifying files or accessing a database. */
4524
+ const checkMigrationPlan = async ({ directory }) => {
4525
+ const { planHasChanged } = await getPlannedMigrations({ config: {
4526
+ directory,
4527
+ dry: true
4528
+ } });
4529
+ if (planHasChanged) throw new Error("Migration plan is out of date. Re-run migrator to update plan.json, and commit it.");
4530
+ };
4531
+ //#endregion
4532
+ //#region src/helpers/helpers.ts
4533
+ const capitalize = (word) => {
4534
+ if (!word) return "";
4535
+ return word[0].toUpperCase() + word.slice(1);
4536
+ };
4537
+ //#endregion
4517
4538
  //#region src/create/create.ts
4518
4539
  const templateMigrationFileWithMetaDataLegacy = (entity) => `import produce from 'immer';
4519
4540
  //other imports not allowed
@@ -4978,4 +4999,4 @@ const printVersionHistory = async ({ config }) => {
4978
4999
  }
4979
5000
  };
4980
5001
  //#endregion
4981
- export { createMigration, getPlannedMigrations, getPlannedVersion, getVersions, migrate, migrateAll, pipe, printVersionHistory };
5002
+ export { checkMigrationPlan, createMigration, getPlannedMigrations, getPlannedVersion, getVersions, migrate, migrateAll, pipe, printVersionHistory };