@bungres/kit 0.6.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -3
- package/dist/cli.js +2660 -1132
- package/dist/commands/drop.d.ts.map +1 -1
- package/dist/commands/generate.d.ts.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/migrate.d.ts.map +1 -1
- package/dist/commands/push.d.ts.map +1 -1
- package/dist/commands/rollback.d.ts +3 -0
- package/dist/commands/rollback.d.ts.map +1 -0
- package/dist/commands/seed.d.ts.map +1 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/studio.d.ts.map +1 -1
- package/dist/commands/template.d.ts +2 -0
- package/dist/commands/template.d.ts.map +1 -0
- package/dist/commands/tusky.d.ts.map +1 -1
- package/dist/index.js +1955 -175
- package/package.json +4 -2
- package/dist/utils/colors.d.ts +0 -2
- package/dist/utils/colors.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,165 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
function __accessProp(key) {
|
|
8
|
+
return this[key];
|
|
9
|
+
}
|
|
10
|
+
var __toESMCache_node;
|
|
11
|
+
var __toESMCache_esm;
|
|
12
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
+
var canCache = mod != null && typeof mod === "object";
|
|
14
|
+
if (canCache) {
|
|
15
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
+
var cached = cache.get(mod);
|
|
17
|
+
if (cached)
|
|
18
|
+
return cached;
|
|
19
|
+
}
|
|
20
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
21
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
|
+
for (let key of __getOwnPropNames(mod))
|
|
23
|
+
if (!__hasOwnProp.call(to, key))
|
|
24
|
+
__defProp(to, key, {
|
|
25
|
+
get: __accessProp.bind(mod, key),
|
|
26
|
+
enumerable: true
|
|
27
|
+
});
|
|
28
|
+
if (canCache)
|
|
29
|
+
cache.set(mod, to);
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
33
|
+
var __require = import.meta.require;
|
|
34
|
+
|
|
35
|
+
// ../../node_modules/.bun/sisteransi@1.0.5/node_modules/sisteransi/src/index.js
|
|
36
|
+
var require_src = __commonJS((exports, module) => {
|
|
37
|
+
var ESC2 = "\x1B";
|
|
38
|
+
var CSI2 = `${ESC2}[`;
|
|
39
|
+
var beep = "\x07";
|
|
40
|
+
var cursor = {
|
|
41
|
+
to(x, y) {
|
|
42
|
+
if (!y)
|
|
43
|
+
return `${CSI2}${x + 1}G`;
|
|
44
|
+
return `${CSI2}${y + 1};${x + 1}H`;
|
|
45
|
+
},
|
|
46
|
+
move(x, y) {
|
|
47
|
+
let ret = "";
|
|
48
|
+
if (x < 0)
|
|
49
|
+
ret += `${CSI2}${-x}D`;
|
|
50
|
+
else if (x > 0)
|
|
51
|
+
ret += `${CSI2}${x}C`;
|
|
52
|
+
if (y < 0)
|
|
53
|
+
ret += `${CSI2}${-y}A`;
|
|
54
|
+
else if (y > 0)
|
|
55
|
+
ret += `${CSI2}${y}B`;
|
|
56
|
+
return ret;
|
|
57
|
+
},
|
|
58
|
+
up: (count = 1) => `${CSI2}${count}A`,
|
|
59
|
+
down: (count = 1) => `${CSI2}${count}B`,
|
|
60
|
+
forward: (count = 1) => `${CSI2}${count}C`,
|
|
61
|
+
backward: (count = 1) => `${CSI2}${count}D`,
|
|
62
|
+
nextLine: (count = 1) => `${CSI2}E`.repeat(count),
|
|
63
|
+
prevLine: (count = 1) => `${CSI2}F`.repeat(count),
|
|
64
|
+
left: `${CSI2}G`,
|
|
65
|
+
hide: `${CSI2}?25l`,
|
|
66
|
+
show: `${CSI2}?25h`,
|
|
67
|
+
save: `${ESC2}7`,
|
|
68
|
+
restore: `${ESC2}8`
|
|
69
|
+
};
|
|
70
|
+
var scroll = {
|
|
71
|
+
up: (count = 1) => `${CSI2}S`.repeat(count),
|
|
72
|
+
down: (count = 1) => `${CSI2}T`.repeat(count)
|
|
73
|
+
};
|
|
74
|
+
var erase = {
|
|
75
|
+
screen: `${CSI2}2J`,
|
|
76
|
+
up: (count = 1) => `${CSI2}1J`.repeat(count),
|
|
77
|
+
down: (count = 1) => `${CSI2}J`.repeat(count),
|
|
78
|
+
line: `${CSI2}2K`,
|
|
79
|
+
lineEnd: `${CSI2}K`,
|
|
80
|
+
lineStart: `${CSI2}1K`,
|
|
81
|
+
lines(count) {
|
|
82
|
+
let clear = "";
|
|
83
|
+
for (let i = 0;i < count; i++)
|
|
84
|
+
clear += this.line + (i < count - 1 ? cursor.up() : "");
|
|
85
|
+
if (count)
|
|
86
|
+
clear += cursor.left;
|
|
87
|
+
return clear;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
module.exports = { cursor, scroll, erase, beep };
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// ../../node_modules/.bun/picocolors@1.1.1/node_modules/picocolors/picocolors.js
|
|
94
|
+
var require_picocolors = __commonJS((exports, module) => {
|
|
95
|
+
var p2 = process || {};
|
|
96
|
+
var argv = p2.argv || [];
|
|
97
|
+
var env = p2.env || {};
|
|
98
|
+
var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p2.platform === "win32" || (p2.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
99
|
+
var formatter = (open, close, replace = open) => (input) => {
|
|
100
|
+
let string = "" + input, index = string.indexOf(close, open.length);
|
|
101
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
102
|
+
};
|
|
103
|
+
var replaceClose = (string, close, replace, index) => {
|
|
104
|
+
let result = "", cursor3 = 0;
|
|
105
|
+
do {
|
|
106
|
+
result += string.substring(cursor3, index) + replace;
|
|
107
|
+
cursor3 = index + close.length;
|
|
108
|
+
index = string.indexOf(close, cursor3);
|
|
109
|
+
} while (~index);
|
|
110
|
+
return result + string.substring(cursor3);
|
|
111
|
+
};
|
|
112
|
+
var createColors = (enabled = isColorSupported) => {
|
|
113
|
+
let f2 = enabled ? formatter : () => String;
|
|
114
|
+
return {
|
|
115
|
+
isColorSupported: enabled,
|
|
116
|
+
reset: f2("\x1B[0m", "\x1B[0m"),
|
|
117
|
+
bold: f2("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
118
|
+
dim: f2("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
119
|
+
italic: f2("\x1B[3m", "\x1B[23m"),
|
|
120
|
+
underline: f2("\x1B[4m", "\x1B[24m"),
|
|
121
|
+
inverse: f2("\x1B[7m", "\x1B[27m"),
|
|
122
|
+
hidden: f2("\x1B[8m", "\x1B[28m"),
|
|
123
|
+
strikethrough: f2("\x1B[9m", "\x1B[29m"),
|
|
124
|
+
black: f2("\x1B[30m", "\x1B[39m"),
|
|
125
|
+
red: f2("\x1B[31m", "\x1B[39m"),
|
|
126
|
+
green: f2("\x1B[32m", "\x1B[39m"),
|
|
127
|
+
yellow: f2("\x1B[33m", "\x1B[39m"),
|
|
128
|
+
blue: f2("\x1B[34m", "\x1B[39m"),
|
|
129
|
+
magenta: f2("\x1B[35m", "\x1B[39m"),
|
|
130
|
+
cyan: f2("\x1B[36m", "\x1B[39m"),
|
|
131
|
+
white: f2("\x1B[37m", "\x1B[39m"),
|
|
132
|
+
gray: f2("\x1B[90m", "\x1B[39m"),
|
|
133
|
+
bgBlack: f2("\x1B[40m", "\x1B[49m"),
|
|
134
|
+
bgRed: f2("\x1B[41m", "\x1B[49m"),
|
|
135
|
+
bgGreen: f2("\x1B[42m", "\x1B[49m"),
|
|
136
|
+
bgYellow: f2("\x1B[43m", "\x1B[49m"),
|
|
137
|
+
bgBlue: f2("\x1B[44m", "\x1B[49m"),
|
|
138
|
+
bgMagenta: f2("\x1B[45m", "\x1B[49m"),
|
|
139
|
+
bgCyan: f2("\x1B[46m", "\x1B[49m"),
|
|
140
|
+
bgWhite: f2("\x1B[47m", "\x1B[49m"),
|
|
141
|
+
blackBright: f2("\x1B[90m", "\x1B[39m"),
|
|
142
|
+
redBright: f2("\x1B[91m", "\x1B[39m"),
|
|
143
|
+
greenBright: f2("\x1B[92m", "\x1B[39m"),
|
|
144
|
+
yellowBright: f2("\x1B[93m", "\x1B[39m"),
|
|
145
|
+
blueBright: f2("\x1B[94m", "\x1B[39m"),
|
|
146
|
+
magentaBright: f2("\x1B[95m", "\x1B[39m"),
|
|
147
|
+
cyanBright: f2("\x1B[96m", "\x1B[39m"),
|
|
148
|
+
whiteBright: f2("\x1B[97m", "\x1B[39m"),
|
|
149
|
+
bgBlackBright: f2("\x1B[100m", "\x1B[49m"),
|
|
150
|
+
bgRedBright: f2("\x1B[101m", "\x1B[49m"),
|
|
151
|
+
bgGreenBright: f2("\x1B[102m", "\x1B[49m"),
|
|
152
|
+
bgYellowBright: f2("\x1B[103m", "\x1B[49m"),
|
|
153
|
+
bgBlueBright: f2("\x1B[104m", "\x1B[49m"),
|
|
154
|
+
bgMagentaBright: f2("\x1B[105m", "\x1B[49m"),
|
|
155
|
+
bgCyanBright: f2("\x1B[106m", "\x1B[49m"),
|
|
156
|
+
bgWhiteBright: f2("\x1B[107m", "\x1B[49m")
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
module.exports = createColors();
|
|
160
|
+
module.exports.createColors = createColors;
|
|
161
|
+
});
|
|
162
|
+
|
|
2
163
|
// src/config.ts
|
|
3
164
|
import { join, resolve } from "path";
|
|
4
165
|
var CONFIG_FILES = [
|
|
@@ -41,7 +202,7 @@ async function loadConfig(cwd = process.cwd()) {
|
|
|
41
202
|
// src/schema-loader.ts
|
|
42
203
|
import { resolve as resolve2, join as join2 } from "path";
|
|
43
204
|
|
|
44
|
-
// ../bungres-orm/
|
|
205
|
+
// ../bungres-orm/dist/index.js
|
|
45
206
|
var TableConfigSymbol = Symbol.for("BungresTableConfig");
|
|
46
207
|
function getTableConfig(table) {
|
|
47
208
|
return table[TableConfigSymbol];
|
|
@@ -111,7 +272,6 @@ var table = createTableFactory("snake");
|
|
|
111
272
|
var snakeCase = { table: createTableFactory("snake") };
|
|
112
273
|
var camelCase = { table: createTableFactory("camel") };
|
|
113
274
|
var noCasing = { table: createTableFactory("none") };
|
|
114
|
-
// ../bungres-orm/src/schema/columns.ts
|
|
115
275
|
function buildColumn(dataType, nameOrOpts, opts) {
|
|
116
276
|
let name = "";
|
|
117
277
|
let options = opts;
|
|
@@ -140,6 +300,13 @@ function buildColumn(dataType, nameOrOpts, opts) {
|
|
|
140
300
|
return Object.assign(config, {
|
|
141
301
|
as(alias) {
|
|
142
302
|
return Object.assign({}, this, { alias });
|
|
303
|
+
},
|
|
304
|
+
array() {
|
|
305
|
+
return Object.assign({}, this, { dataType: `${this.dataType}[]` });
|
|
306
|
+
},
|
|
307
|
+
generatedAlwaysAs(expr) {
|
|
308
|
+
const sqlStr = typeof expr === "string" ? expr : expr.sql;
|
|
309
|
+
return Object.assign({}, this, { generatedAs: sqlStr });
|
|
143
310
|
}
|
|
144
311
|
});
|
|
145
312
|
}
|
|
@@ -169,7 +336,6 @@ var textArray = col("text[]");
|
|
|
169
336
|
var integerArray = col("integer[]");
|
|
170
337
|
var varcharArray = col("varchar[]");
|
|
171
338
|
var uuidArray = col("uuid[]");
|
|
172
|
-
// ../bungres-orm/src/core/sql.ts
|
|
173
339
|
function sql(strings, ...values) {
|
|
174
340
|
let query = "";
|
|
175
341
|
const params = [];
|
|
@@ -212,7 +378,6 @@ function colName(c) {
|
|
|
212
378
|
return c.sql;
|
|
213
379
|
return c.tableName ? `${c.tableName}."${c.name}"` : `"${c.name}"`;
|
|
214
380
|
}
|
|
215
|
-
// ../bungres-orm/src/core/conditions.ts
|
|
216
381
|
function isColumnConfig(val) {
|
|
217
382
|
return val !== null && typeof val === "object" && "name" in val && "dataType" in val;
|
|
218
383
|
}
|
|
@@ -366,14 +531,13 @@ function parseOrderByObject(tableConfig, orderByObj) {
|
|
|
366
531
|
}
|
|
367
532
|
return parts;
|
|
368
533
|
}
|
|
369
|
-
|
|
370
|
-
// ../bungres-orm/src/builders/delete.ts
|
|
371
534
|
class DeleteBuilder {
|
|
372
535
|
_table;
|
|
373
536
|
_executor;
|
|
374
537
|
_where = [];
|
|
375
538
|
_returning;
|
|
376
539
|
_comment;
|
|
540
|
+
_with = [];
|
|
377
541
|
constructor(table2, executor) {
|
|
378
542
|
this._table = table2;
|
|
379
543
|
this._executor = executor;
|
|
@@ -392,6 +556,10 @@ class DeleteBuilder {
|
|
|
392
556
|
}
|
|
393
557
|
return this;
|
|
394
558
|
}
|
|
559
|
+
with(...ctes) {
|
|
560
|
+
this._with.push(...ctes);
|
|
561
|
+
return this;
|
|
562
|
+
}
|
|
395
563
|
returning(...columns) {
|
|
396
564
|
this._returning = columns.length > 0 ? columns : ["*"];
|
|
397
565
|
return this;
|
|
@@ -401,8 +569,20 @@ class DeleteBuilder {
|
|
|
401
569
|
return this;
|
|
402
570
|
}
|
|
403
571
|
toSQL() {
|
|
404
|
-
|
|
572
|
+
const tConfig = getTableConfig(this._table);
|
|
405
573
|
const params = [];
|
|
574
|
+
let prefix = "";
|
|
575
|
+
if (this._with.length > 0) {
|
|
576
|
+
const cteStrs = [];
|
|
577
|
+
for (const cte of this._with) {
|
|
578
|
+
const chunk = cte.query.toSQL();
|
|
579
|
+
const offset = params.length;
|
|
580
|
+
params.push(...chunk.params);
|
|
581
|
+
cteStrs.push(`"${cte.alias}" AS (${chunk.sql.replace(/\$(\d+)/g, (_, n) => `$${parseInt(n) + offset}`)})`);
|
|
582
|
+
}
|
|
583
|
+
prefix = `WITH ${cteStrs.join(", ")} `;
|
|
584
|
+
}
|
|
585
|
+
let query = `DELETE FROM ${tConfig.qualifiedName}`;
|
|
406
586
|
if (this._where.length > 0) {
|
|
407
587
|
const combined = sqlJoin(this._where, " AND ");
|
|
408
588
|
query += " WHERE " + combined.sql;
|
|
@@ -414,17 +594,19 @@ class DeleteBuilder {
|
|
|
414
594
|
if (this._comment) {
|
|
415
595
|
query += ` /* ${this._comment.replace(/\*\//g, "")} */`;
|
|
416
596
|
}
|
|
417
|
-
return { sql: query, params };
|
|
597
|
+
return { sql: prefix + query, params };
|
|
418
598
|
}
|
|
419
599
|
}
|
|
420
|
-
|
|
600
|
+
|
|
421
601
|
class InsertBuilder {
|
|
422
602
|
_table;
|
|
423
603
|
_executor;
|
|
424
604
|
_values = [];
|
|
425
605
|
_onConflict;
|
|
606
|
+
_onConflictUpdateConfig;
|
|
426
607
|
_returning;
|
|
427
608
|
_comment;
|
|
609
|
+
_with = [];
|
|
428
610
|
constructor(table2, executor) {
|
|
429
611
|
this._table = table2;
|
|
430
612
|
this._executor = executor;
|
|
@@ -451,6 +633,14 @@ class InsertBuilder {
|
|
|
451
633
|
this._onConflict = clause;
|
|
452
634
|
return this;
|
|
453
635
|
}
|
|
636
|
+
onConflictDoUpdate(config) {
|
|
637
|
+
this._onConflictUpdateConfig = config;
|
|
638
|
+
return this;
|
|
639
|
+
}
|
|
640
|
+
with(...ctes) {
|
|
641
|
+
this._with.push(...ctes);
|
|
642
|
+
return this;
|
|
643
|
+
}
|
|
454
644
|
returning(...columns) {
|
|
455
645
|
this._returning = columns.length > 0 ? columns : ["*"];
|
|
456
646
|
return this;
|
|
@@ -476,6 +666,17 @@ class InsertBuilder {
|
|
|
476
666
|
}
|
|
477
667
|
const columnsStr = keys.map((k) => `"${tConfig.columns[k]?.name ?? k}"`).join(", ");
|
|
478
668
|
const params = [];
|
|
669
|
+
let prefix = "";
|
|
670
|
+
if (this._with.length > 0) {
|
|
671
|
+
const cteStrs = [];
|
|
672
|
+
for (const cte of this._with) {
|
|
673
|
+
const chunk = cte.query.toSQL();
|
|
674
|
+
const offset = params.length;
|
|
675
|
+
params.push(...chunk.params);
|
|
676
|
+
cteStrs.push(`"${cte.alias}" AS (${chunk.sql.replace(/\$(\d+)/g, (_, n) => `$${parseInt(n) + offset}`)})`);
|
|
677
|
+
}
|
|
678
|
+
prefix = `WITH ${cteStrs.join(", ")} `;
|
|
679
|
+
}
|
|
479
680
|
const valuesStrs = this._values.map((v) => {
|
|
480
681
|
const vals = keys.map((k) => {
|
|
481
682
|
const val = v[k];
|
|
@@ -519,6 +720,52 @@ class InsertBuilder {
|
|
|
519
720
|
query += " " + this._onConflict.sql.replace(/\$(\d+)/g, (_, n) => `$${parseInt(n) + offset}`);
|
|
520
721
|
params.push(...this._onConflict.params);
|
|
521
722
|
}
|
|
723
|
+
} else if (this._onConflictUpdateConfig) {
|
|
724
|
+
const config = this._onConflictUpdateConfig;
|
|
725
|
+
const targets = Array.isArray(config.target) ? config.target : [config.target];
|
|
726
|
+
const targetStrs = [];
|
|
727
|
+
for (const t of targets) {
|
|
728
|
+
if (typeof t === "string") {
|
|
729
|
+
targetStrs.push(`"${tConfig.columns[t]?.name ?? t}"`);
|
|
730
|
+
} else {
|
|
731
|
+
const offset = params.length;
|
|
732
|
+
targetStrs.push(t.sql.replace(/\$(\d+)/g, (_, n) => `$${parseInt(n) + offset}`));
|
|
733
|
+
params.push(...t.params);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
const setEntries = Object.entries(config.set);
|
|
737
|
+
if (setEntries.length === 0)
|
|
738
|
+
throw new Error("InsertBuilder: onConflictDoUpdate requires 'set' fields");
|
|
739
|
+
const setClauses = setEntries.map(([key, value]) => {
|
|
740
|
+
const dbCol = tConfig.columns[key]?.name ?? key;
|
|
741
|
+
if (value && typeof value === "object" && "sql" in value && "params" in value) {
|
|
742
|
+
const chunk = value;
|
|
743
|
+
const offset = params.length;
|
|
744
|
+
params.push(...chunk.params);
|
|
745
|
+
return `"${dbCol}" = ${chunk.sql.replace(/\$(\d+)/g, (_, n) => `$${parseInt(n) + offset}`)}`;
|
|
746
|
+
}
|
|
747
|
+
if (value && typeof value === "object" && !(value instanceof Date)) {
|
|
748
|
+
const colType = tConfig.columns[key]?.dataType;
|
|
749
|
+
if (colType === "json" || colType === "jsonb") {
|
|
750
|
+
params.push(value);
|
|
751
|
+
} else if (Array.isArray(value)) {
|
|
752
|
+
const pgArray = "{" + value.map((item) => {
|
|
753
|
+
if (item === null || item === undefined)
|
|
754
|
+
return "NULL";
|
|
755
|
+
if (typeof item === "string")
|
|
756
|
+
return '"' + item.replace(/"/g, "\\\"") + '"';
|
|
757
|
+
return typeof item === "object" ? '"' + JSON.stringify(item).replace(/"/g, "\\\"") + '"' : String(item);
|
|
758
|
+
}).join(",") + "}";
|
|
759
|
+
params.push(pgArray);
|
|
760
|
+
} else {
|
|
761
|
+
params.push(JSON.stringify(value));
|
|
762
|
+
}
|
|
763
|
+
return `"${dbCol}" = $${params.length}`;
|
|
764
|
+
}
|
|
765
|
+
params.push(value);
|
|
766
|
+
return `"${dbCol}" = $${params.length}`;
|
|
767
|
+
});
|
|
768
|
+
query += ` ON CONFLICT (${targetStrs.join(", ")}) DO UPDATE SET ${setClauses.join(", ")}`;
|
|
522
769
|
}
|
|
523
770
|
if (this._returning) {
|
|
524
771
|
query += " RETURNING " + (this._returning[0] === "*" ? Object.keys(tConfig.columns).map((c) => `"${tConfig.columns[c].name}" AS "${c}"`).join(", ") : this._returning.map((c) => `"${tConfig.columns[c]?.name ?? c}" AS "${c}"`).join(", "));
|
|
@@ -526,10 +773,10 @@ class InsertBuilder {
|
|
|
526
773
|
if (this._comment) {
|
|
527
774
|
query += ` /* ${this._comment.replace(/\*\//g, "")} */`;
|
|
528
775
|
}
|
|
529
|
-
return { sql: query, params };
|
|
776
|
+
return { sql: prefix + query, params };
|
|
530
777
|
}
|
|
531
778
|
}
|
|
532
|
-
|
|
779
|
+
|
|
533
780
|
class SelectBuilder {
|
|
534
781
|
_table;
|
|
535
782
|
_executor;
|
|
@@ -542,6 +789,8 @@ class SelectBuilder {
|
|
|
542
789
|
_select;
|
|
543
790
|
_selection;
|
|
544
791
|
_joins = [];
|
|
792
|
+
_with = [];
|
|
793
|
+
_setOperations = [];
|
|
545
794
|
_comment;
|
|
546
795
|
constructor(table2, executor, selection) {
|
|
547
796
|
this._table = table2;
|
|
@@ -552,12 +801,35 @@ class SelectBuilder {
|
|
|
552
801
|
return this._executor.execute(this).then(onfulfilled, onrejected);
|
|
553
802
|
}
|
|
554
803
|
async single() {
|
|
804
|
+
if (this._limit === undefined) {
|
|
805
|
+
this.limit(1);
|
|
806
|
+
}
|
|
555
807
|
return this._executor.executeSingle(this);
|
|
556
808
|
}
|
|
557
809
|
select(...columns) {
|
|
558
810
|
this._select = columns;
|
|
559
811
|
return this;
|
|
560
812
|
}
|
|
813
|
+
with(...ctes) {
|
|
814
|
+
this._with.push(...ctes);
|
|
815
|
+
return this;
|
|
816
|
+
}
|
|
817
|
+
union(other) {
|
|
818
|
+
this._setOperations.push({ type: "UNION", builder: other });
|
|
819
|
+
return this;
|
|
820
|
+
}
|
|
821
|
+
unionAll(other) {
|
|
822
|
+
this._setOperations.push({ type: "UNION ALL", builder: other });
|
|
823
|
+
return this;
|
|
824
|
+
}
|
|
825
|
+
intersect(other) {
|
|
826
|
+
this._setOperations.push({ type: "INTERSECT", builder: other });
|
|
827
|
+
return this;
|
|
828
|
+
}
|
|
829
|
+
except(other) {
|
|
830
|
+
this._setOperations.push({ type: "EXCEPT", builder: other });
|
|
831
|
+
return this;
|
|
832
|
+
}
|
|
561
833
|
comment(tag) {
|
|
562
834
|
this._comment = tag;
|
|
563
835
|
return this;
|
|
@@ -660,7 +932,23 @@ class SelectBuilder {
|
|
|
660
932
|
}).join(", ");
|
|
661
933
|
} else {
|
|
662
934
|
const qName = getTableConfig(this._table).qualifiedName;
|
|
663
|
-
|
|
935
|
+
const colsKeys = Object.keys(getTableConfig(this._table).columns);
|
|
936
|
+
if (colsKeys.length === 0) {
|
|
937
|
+
cols = "*";
|
|
938
|
+
} else {
|
|
939
|
+
cols = colsKeys.map((c) => `${qName}."${getTableConfig(this._table).columns[c].name}" AS "${c}"`).join(", ");
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
let prefix = "";
|
|
943
|
+
if (this._with.length > 0) {
|
|
944
|
+
const cteStrs = [];
|
|
945
|
+
for (const cte of this._with) {
|
|
946
|
+
const chunk = cte.query.toSQL();
|
|
947
|
+
const offset = params.length;
|
|
948
|
+
params.push(...chunk.params);
|
|
949
|
+
cteStrs.push(`"${cte.alias}" AS (${chunk.sql.replace(/\$(\d+)/g, (_, n) => `$${parseInt(n) + offset}`)})`);
|
|
950
|
+
}
|
|
951
|
+
prefix = `WITH ${cteStrs.join(", ")} `;
|
|
664
952
|
}
|
|
665
953
|
let query = `SELECT ${cols} FROM ${getTableConfig(this._table).qualifiedName}`;
|
|
666
954
|
if (this._joins.length > 0) {
|
|
@@ -720,10 +1008,18 @@ class SelectBuilder {
|
|
|
720
1008
|
params.push(this._offset);
|
|
721
1009
|
query += ` OFFSET $${params.length}`;
|
|
722
1010
|
}
|
|
1011
|
+
if (this._setOperations.length > 0) {
|
|
1012
|
+
for (const op of this._setOperations) {
|
|
1013
|
+
const chunk = op.builder.toSQL();
|
|
1014
|
+
const offset = params.length;
|
|
1015
|
+
params.push(...chunk.params);
|
|
1016
|
+
query += ` ${op.type} ${chunk.sql.replace(/\$(\d+)/g, (_, n) => `$${parseInt(n) + offset}`)}`;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
723
1019
|
if (this._comment) {
|
|
724
1020
|
query += ` /* ${this._comment.replace(/\*\//g, "")} */`;
|
|
725
1021
|
}
|
|
726
|
-
return { sql: query, params };
|
|
1022
|
+
return { sql: prefix + query, params };
|
|
727
1023
|
}
|
|
728
1024
|
}
|
|
729
1025
|
|
|
@@ -738,7 +1034,7 @@ class SelectBuilderIntermediate {
|
|
|
738
1034
|
return new SelectBuilder(table2, this._executor, this._selection);
|
|
739
1035
|
}
|
|
740
1036
|
}
|
|
741
|
-
|
|
1037
|
+
|
|
742
1038
|
class UpdateBuilder {
|
|
743
1039
|
_table;
|
|
744
1040
|
_executor;
|
|
@@ -746,6 +1042,7 @@ class UpdateBuilder {
|
|
|
746
1042
|
_where = [];
|
|
747
1043
|
_returning;
|
|
748
1044
|
_comment;
|
|
1045
|
+
_with = [];
|
|
749
1046
|
constructor(table2, executor) {
|
|
750
1047
|
this._table = table2;
|
|
751
1048
|
this._executor = executor;
|
|
@@ -768,6 +1065,10 @@ class UpdateBuilder {
|
|
|
768
1065
|
}
|
|
769
1066
|
return this;
|
|
770
1067
|
}
|
|
1068
|
+
with(...ctes) {
|
|
1069
|
+
this._with.push(...ctes);
|
|
1070
|
+
return this;
|
|
1071
|
+
}
|
|
771
1072
|
returning(...columns) {
|
|
772
1073
|
this._returning = columns.length > 0 ? columns : ["*"];
|
|
773
1074
|
return this;
|
|
@@ -782,6 +1083,17 @@ class UpdateBuilder {
|
|
|
782
1083
|
throw new Error("UpdateBuilder: no fields to set");
|
|
783
1084
|
}
|
|
784
1085
|
const params = [];
|
|
1086
|
+
let prefix = "";
|
|
1087
|
+
if (this._with.length > 0) {
|
|
1088
|
+
const cteStrs = [];
|
|
1089
|
+
for (const cte of this._with) {
|
|
1090
|
+
const chunk = cte.query.toSQL();
|
|
1091
|
+
const offset = params.length;
|
|
1092
|
+
params.push(...chunk.params);
|
|
1093
|
+
cteStrs.push(`"${cte.alias}" AS (${chunk.sql.replace(/\$(\d+)/g, (_, n) => `$${parseInt(n) + offset}`)})`);
|
|
1094
|
+
}
|
|
1095
|
+
prefix = `WITH ${cteStrs.join(", ")} `;
|
|
1096
|
+
}
|
|
785
1097
|
const setClauses = entries.map(([key, value]) => {
|
|
786
1098
|
const dbCol = getTableConfig(this._table).columns[key]?.name ?? key;
|
|
787
1099
|
if (value && typeof value === "object" && "sql" in value && "params" in value) {
|
|
@@ -824,10 +1136,9 @@ class UpdateBuilder {
|
|
|
824
1136
|
if (this._comment) {
|
|
825
1137
|
query += ` /* ${this._comment.replace(/\*\//g, "")} */`;
|
|
826
1138
|
}
|
|
827
|
-
return { sql: query, params };
|
|
1139
|
+
return { sql: prefix + query, params };
|
|
828
1140
|
}
|
|
829
1141
|
}
|
|
830
|
-
// ../bungres-orm/src/builders/relational.ts
|
|
831
1142
|
function getPkColumn(tableConfig) {
|
|
832
1143
|
if (tableConfig.primaryKeys?.length > 0)
|
|
833
1144
|
return tableConfig.primaryKeys[0];
|
|
@@ -1085,8 +1396,6 @@ class RelationalQueryBuilder {
|
|
|
1085
1396
|
return { sql: sql2, params };
|
|
1086
1397
|
}
|
|
1087
1398
|
}
|
|
1088
|
-
|
|
1089
|
-
// ../bungres-orm/src/core/db.ts
|
|
1090
1399
|
function parseDBName(url) {
|
|
1091
1400
|
try {
|
|
1092
1401
|
return new URL(url).pathname.slice(1);
|
|
@@ -1195,6 +1504,7 @@ class BungresDB {
|
|
|
1195
1504
|
|
|
1196
1505
|
class BungresTransaction {
|
|
1197
1506
|
_sql;
|
|
1507
|
+
_savepointCounter = 0;
|
|
1198
1508
|
constructor(sql2) {
|
|
1199
1509
|
this._sql = sql2;
|
|
1200
1510
|
}
|
|
@@ -1229,6 +1539,19 @@ class BungresTransaction {
|
|
|
1229
1539
|
const result = await this._sql.unsafe(query, params);
|
|
1230
1540
|
return Array.from(result);
|
|
1231
1541
|
}
|
|
1542
|
+
async transaction(fn) {
|
|
1543
|
+
this._savepointCounter++;
|
|
1544
|
+
const spName = `sp_${this._savepointCounter}`;
|
|
1545
|
+
await this._sql.unsafe(`SAVEPOINT ${spName}`);
|
|
1546
|
+
try {
|
|
1547
|
+
const result = await fn(this);
|
|
1548
|
+
await this._sql.unsafe(`RELEASE SAVEPOINT ${spName}`);
|
|
1549
|
+
return result;
|
|
1550
|
+
} catch (e) {
|
|
1551
|
+
await this._sql.unsafe(`ROLLBACK TO SAVEPOINT ${spName}`);
|
|
1552
|
+
throw e;
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1232
1555
|
}
|
|
1233
1556
|
function bungres(config) {
|
|
1234
1557
|
const db = new BungresDB(config);
|
|
@@ -1252,7 +1575,6 @@ function bungres(config) {
|
|
|
1252
1575
|
}
|
|
1253
1576
|
return db;
|
|
1254
1577
|
}
|
|
1255
|
-
// ../bungres-orm/src/ddl.ts
|
|
1256
1578
|
function generateCreateTable(config, ifNotExists = true) {
|
|
1257
1579
|
const tableName = config.schema ? `"${config.schema}"."${config.name}"` : `"${config.name}"`;
|
|
1258
1580
|
const exists = ifNotExists ? " IF NOT EXISTS" : "";
|
|
@@ -1262,8 +1584,8 @@ function generateCreateTable(config, ifNotExists = true) {
|
|
|
1262
1584
|
columnDefs.push(`PRIMARY KEY (${pkCols})`);
|
|
1263
1585
|
}
|
|
1264
1586
|
if (config.checks) {
|
|
1265
|
-
for (const
|
|
1266
|
-
columnDefs.push(`CHECK (${
|
|
1587
|
+
for (const check2 of config.checks) {
|
|
1588
|
+
columnDefs.push(`CHECK (${check2})`);
|
|
1267
1589
|
}
|
|
1268
1590
|
}
|
|
1269
1591
|
let sql2 = `CREATE TABLE${exists} ${tableName} (
|
|
@@ -1301,7 +1623,9 @@ function buildColumnDDL(key, col2, tableName) {
|
|
|
1301
1623
|
if (col2.unique && !col2.primaryKey) {
|
|
1302
1624
|
parts.push("UNIQUE");
|
|
1303
1625
|
}
|
|
1304
|
-
if (col2.
|
|
1626
|
+
if (col2.generatedAs) {
|
|
1627
|
+
parts.push(`GENERATED ALWAYS AS (${col2.generatedAs}) STORED`);
|
|
1628
|
+
} else if (col2.defaultFn) {
|
|
1305
1629
|
parts.push(`DEFAULT ${col2.defaultFn}`);
|
|
1306
1630
|
} else if (col2.defaultValue !== undefined) {
|
|
1307
1631
|
parts.push(`DEFAULT ${formatDefaultValue(col2.defaultValue, col2.dataType)}`);
|
|
@@ -1322,6 +1646,13 @@ function buildColumnDDL(key, col2, tableName) {
|
|
|
1322
1646
|
return parts.join(" ");
|
|
1323
1647
|
}
|
|
1324
1648
|
function buildType(col2) {
|
|
1649
|
+
if (col2.enumConfig) {
|
|
1650
|
+
return `"${col2.enumConfig.enumName}"`;
|
|
1651
|
+
}
|
|
1652
|
+
if (col2.dataType.endsWith("[]")) {
|
|
1653
|
+
const baseType = buildType({ ...col2, dataType: col2.dataType.slice(0, -2) });
|
|
1654
|
+
return `${baseType}[]`;
|
|
1655
|
+
}
|
|
1325
1656
|
switch (col2.dataType) {
|
|
1326
1657
|
case "varchar":
|
|
1327
1658
|
return col2.length ? `VARCHAR(${col2.length})` : "VARCHAR";
|
|
@@ -1356,12 +1687,12 @@ function formatDefaultValue(value, dataType) {
|
|
|
1356
1687
|
}
|
|
1357
1688
|
function buildIndex(table2, idx) {
|
|
1358
1689
|
const tableName = table2.schema ? `"${table2.schema}"."${table2.name}"` : `"${table2.name}"`;
|
|
1359
|
-
const
|
|
1690
|
+
const unique2 = idx.unique ? "UNIQUE " : "";
|
|
1360
1691
|
const using = idx.using ? ` USING ${idx.using.toUpperCase()}` : "";
|
|
1361
1692
|
const cols = idx.columns.map((c) => `"${c}"`).join(", ");
|
|
1362
1693
|
const where = idx.where ? ` WHERE ${idx.where}` : "";
|
|
1363
1694
|
const idxName = idx.name ?? `idx_${table2.name}_${idx.columns.join("_")}`;
|
|
1364
|
-
return `CREATE ${
|
|
1695
|
+
return `CREATE ${unique2}INDEX IF NOT EXISTS "${idxName}" ON ${tableName}${using} (${cols})${where};`;
|
|
1365
1696
|
}
|
|
1366
1697
|
function generateAddColumn(tableName, schema, key, col2) {
|
|
1367
1698
|
const tbl = schema ? `"${schema}"."${tableName}"` : `"${tableName}"`;
|
|
@@ -1371,6 +1702,7 @@ function generateDropColumn(tableName, schema, columnName) {
|
|
|
1371
1702
|
const tbl = schema ? `"${schema}"."${tableName}"` : `"${tableName}"`;
|
|
1372
1703
|
return `ALTER TABLE ${tbl} DROP COLUMN IF EXISTS "${columnName}";`;
|
|
1373
1704
|
}
|
|
1705
|
+
|
|
1374
1706
|
// src/schema-loader.ts
|
|
1375
1707
|
async function loadSchemas(patterns, cwd = process.cwd()) {
|
|
1376
1708
|
const globs = Array.isArray(patterns) ? patterns : [patterns];
|
|
@@ -1397,9 +1729,6 @@ async function loadSchemas(patterns, cwd = process.cwd()) {
|
|
|
1397
1729
|
function isTable(value) {
|
|
1398
1730
|
return typeof value === "object" && value !== null && TableConfigSymbol in value;
|
|
1399
1731
|
}
|
|
1400
|
-
// src/commands/push.ts
|
|
1401
|
-
import * as fs from "fs";
|
|
1402
|
-
|
|
1403
1732
|
// src/differ.ts
|
|
1404
1733
|
function diffSchemas(prev, next) {
|
|
1405
1734
|
const statements = [];
|
|
@@ -1485,11 +1814,11 @@ function diffSchemas(prev, next) {
|
|
|
1485
1814
|
const idxName = idx.name ?? `idx_${tableName}_${idx.columns.join("_")}`;
|
|
1486
1815
|
if (!prevIdxNames.has(idxName)) {
|
|
1487
1816
|
const tbl = nextConfig.schema ? `"${nextConfig.schema}"."${tableName}"` : `"${tableName}"`;
|
|
1488
|
-
const
|
|
1817
|
+
const unique = idx.unique ? "UNIQUE " : "";
|
|
1489
1818
|
const using = idx.using ? ` USING ${idx.using.toUpperCase()}` : "";
|
|
1490
1819
|
const cols = idx.columns.map((c) => `"${c}"`).join(", ");
|
|
1491
1820
|
const where = idx.where ? ` WHERE ${idx.where}` : "";
|
|
1492
|
-
statements.push(`CREATE ${
|
|
1821
|
+
statements.push(`CREATE ${unique}INDEX IF NOT EXISTS "${idxName}" ON ${tbl}${using} (${cols})${where};`);
|
|
1493
1822
|
summary.push(`CREATE INDEX ${idxName} ON ${tableName}`);
|
|
1494
1823
|
}
|
|
1495
1824
|
}
|
|
@@ -1573,15 +1902,1382 @@ function formatDefault(value, dataType) {
|
|
|
1573
1902
|
return `'${JSON.stringify(value)}'`;
|
|
1574
1903
|
}
|
|
1575
1904
|
|
|
1905
|
+
// ../../node_modules/.bun/@clack+core@1.4.3/node_modules/@clack/core/dist/index.mjs
|
|
1906
|
+
import { styleText } from "util";
|
|
1907
|
+
import { stdout, stdin } from "process";
|
|
1908
|
+
import * as l from "readline";
|
|
1909
|
+
import l__default from "readline";
|
|
1910
|
+
|
|
1911
|
+
// ../../node_modules/.bun/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/utils.js
|
|
1912
|
+
var getCodePointsLength = (() => {
|
|
1913
|
+
const SURROGATE_PAIR_RE = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
|
1914
|
+
return (input) => {
|
|
1915
|
+
let surrogatePairsNr = 0;
|
|
1916
|
+
SURROGATE_PAIR_RE.lastIndex = 0;
|
|
1917
|
+
while (SURROGATE_PAIR_RE.test(input)) {
|
|
1918
|
+
surrogatePairsNr += 1;
|
|
1919
|
+
}
|
|
1920
|
+
return input.length - surrogatePairsNr;
|
|
1921
|
+
};
|
|
1922
|
+
})();
|
|
1923
|
+
var isFullWidth = (x) => {
|
|
1924
|
+
return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
|
|
1925
|
+
};
|
|
1926
|
+
var isWideNotCJKTNotEmoji = (x) => {
|
|
1927
|
+
return x === 8987 || x === 9001 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12441 && x <= 12543 || x >= 12549 && x <= 12591 || x >= 12593 && x <= 12686 || x >= 12688 && x <= 12771 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && x <= 19903 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
|
|
1928
|
+
};
|
|
1929
|
+
|
|
1930
|
+
// ../../node_modules/.bun/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/index.js
|
|
1931
|
+
var ANSI_RE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y;
|
|
1932
|
+
var CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
|
|
1933
|
+
var CJKT_WIDE_RE = /(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu;
|
|
1934
|
+
var TAB_RE = /\t{1,1000}/y;
|
|
1935
|
+
var EMOJI_RE = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu;
|
|
1936
|
+
var LATIN_RE = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
|
|
1937
|
+
var MODIFIER_RE = /\p{M}+/gu;
|
|
1938
|
+
var NO_TRUNCATION = { limit: Infinity, ellipsis: "" };
|
|
1939
|
+
var getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {}) => {
|
|
1940
|
+
const LIMIT = truncationOptions.limit ?? Infinity;
|
|
1941
|
+
const ELLIPSIS = truncationOptions.ellipsis ?? "";
|
|
1942
|
+
const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth(ELLIPSIS, NO_TRUNCATION, widthOptions).width : 0);
|
|
1943
|
+
const ANSI_WIDTH = 0;
|
|
1944
|
+
const CONTROL_WIDTH = widthOptions.controlWidth ?? 0;
|
|
1945
|
+
const TAB_WIDTH = widthOptions.tabWidth ?? 8;
|
|
1946
|
+
const EMOJI_WIDTH = widthOptions.emojiWidth ?? 2;
|
|
1947
|
+
const FULL_WIDTH_WIDTH = 2;
|
|
1948
|
+
const REGULAR_WIDTH = widthOptions.regularWidth ?? 1;
|
|
1949
|
+
const WIDE_WIDTH = widthOptions.wideWidth ?? FULL_WIDTH_WIDTH;
|
|
1950
|
+
const PARSE_BLOCKS = [
|
|
1951
|
+
[LATIN_RE, REGULAR_WIDTH],
|
|
1952
|
+
[ANSI_RE, ANSI_WIDTH],
|
|
1953
|
+
[CONTROL_RE, CONTROL_WIDTH],
|
|
1954
|
+
[TAB_RE, TAB_WIDTH],
|
|
1955
|
+
[EMOJI_RE, EMOJI_WIDTH],
|
|
1956
|
+
[CJKT_WIDE_RE, WIDE_WIDTH]
|
|
1957
|
+
];
|
|
1958
|
+
let indexPrev = 0;
|
|
1959
|
+
let index = 0;
|
|
1960
|
+
let length = input.length;
|
|
1961
|
+
let lengthExtra = 0;
|
|
1962
|
+
let truncationEnabled = false;
|
|
1963
|
+
let truncationIndex = length;
|
|
1964
|
+
let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH);
|
|
1965
|
+
let unmatchedStart = 0;
|
|
1966
|
+
let unmatchedEnd = 0;
|
|
1967
|
+
let width = 0;
|
|
1968
|
+
let widthExtra = 0;
|
|
1969
|
+
outer:
|
|
1970
|
+
while (true) {
|
|
1971
|
+
if (unmatchedEnd > unmatchedStart || index >= length && index > indexPrev) {
|
|
1972
|
+
const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
|
|
1973
|
+
lengthExtra = 0;
|
|
1974
|
+
for (const char of unmatched.replaceAll(MODIFIER_RE, "")) {
|
|
1975
|
+
const codePoint = char.codePointAt(0) || 0;
|
|
1976
|
+
if (isFullWidth(codePoint)) {
|
|
1977
|
+
widthExtra = FULL_WIDTH_WIDTH;
|
|
1978
|
+
} else if (isWideNotCJKTNotEmoji(codePoint)) {
|
|
1979
|
+
widthExtra = WIDE_WIDTH;
|
|
1980
|
+
} else {
|
|
1981
|
+
widthExtra = REGULAR_WIDTH;
|
|
1982
|
+
}
|
|
1983
|
+
if (width + widthExtra > truncationLimit) {
|
|
1984
|
+
truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
|
|
1985
|
+
}
|
|
1986
|
+
if (width + widthExtra > LIMIT) {
|
|
1987
|
+
truncationEnabled = true;
|
|
1988
|
+
break outer;
|
|
1989
|
+
}
|
|
1990
|
+
lengthExtra += char.length;
|
|
1991
|
+
width += widthExtra;
|
|
1992
|
+
}
|
|
1993
|
+
unmatchedStart = unmatchedEnd = 0;
|
|
1994
|
+
}
|
|
1995
|
+
if (index >= length) {
|
|
1996
|
+
break outer;
|
|
1997
|
+
}
|
|
1998
|
+
for (let i = 0, l = PARSE_BLOCKS.length;i < l; i++) {
|
|
1999
|
+
const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[i];
|
|
2000
|
+
BLOCK_RE.lastIndex = index;
|
|
2001
|
+
if (BLOCK_RE.test(input)) {
|
|
2002
|
+
lengthExtra = BLOCK_RE === CJKT_WIDE_RE ? getCodePointsLength(input.slice(index, BLOCK_RE.lastIndex)) : BLOCK_RE === EMOJI_RE ? 1 : BLOCK_RE.lastIndex - index;
|
|
2003
|
+
widthExtra = lengthExtra * BLOCK_WIDTH;
|
|
2004
|
+
if (width + widthExtra > truncationLimit) {
|
|
2005
|
+
truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / BLOCK_WIDTH));
|
|
2006
|
+
}
|
|
2007
|
+
if (width + widthExtra > LIMIT) {
|
|
2008
|
+
truncationEnabled = true;
|
|
2009
|
+
break outer;
|
|
2010
|
+
}
|
|
2011
|
+
width += widthExtra;
|
|
2012
|
+
unmatchedStart = indexPrev;
|
|
2013
|
+
unmatchedEnd = index;
|
|
2014
|
+
index = indexPrev = BLOCK_RE.lastIndex;
|
|
2015
|
+
continue outer;
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
index += 1;
|
|
2019
|
+
}
|
|
2020
|
+
return {
|
|
2021
|
+
width: truncationEnabled ? truncationLimit : width,
|
|
2022
|
+
index: truncationEnabled ? truncationIndex : length,
|
|
2023
|
+
truncated: truncationEnabled,
|
|
2024
|
+
ellipsed: truncationEnabled && LIMIT >= ELLIPSIS_WIDTH
|
|
2025
|
+
};
|
|
2026
|
+
};
|
|
2027
|
+
var dist_default = getStringTruncatedWidth;
|
|
2028
|
+
|
|
2029
|
+
// ../../node_modules/.bun/fast-string-width@3.0.2/node_modules/fast-string-width/dist/index.js
|
|
2030
|
+
var NO_TRUNCATION2 = {
|
|
2031
|
+
limit: Infinity,
|
|
2032
|
+
ellipsis: "",
|
|
2033
|
+
ellipsisWidth: 0
|
|
2034
|
+
};
|
|
2035
|
+
var fastStringWidth = (input, options = {}) => {
|
|
2036
|
+
return dist_default(input, NO_TRUNCATION2, options).width;
|
|
2037
|
+
};
|
|
2038
|
+
var dist_default2 = fastStringWidth;
|
|
2039
|
+
|
|
2040
|
+
// ../../node_modules/.bun/fast-wrap-ansi@0.2.2/node_modules/fast-wrap-ansi/lib/main.js
|
|
2041
|
+
var ESC = "\x1B";
|
|
2042
|
+
var CSI = "\x9B";
|
|
2043
|
+
var END_CODE = 39;
|
|
2044
|
+
var ANSI_ESCAPE_BELL = "\x07";
|
|
2045
|
+
var ANSI_CSI = "[";
|
|
2046
|
+
var ANSI_OSC = "]";
|
|
2047
|
+
var ANSI_SGR_TERMINATOR = "m";
|
|
2048
|
+
var ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
|
|
2049
|
+
var GROUP_REGEX = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`, "y");
|
|
2050
|
+
var getClosingCode = (openingCode) => {
|
|
2051
|
+
if (openingCode >= 30 && openingCode <= 37)
|
|
2052
|
+
return 39;
|
|
2053
|
+
if (openingCode >= 90 && openingCode <= 97)
|
|
2054
|
+
return 39;
|
|
2055
|
+
if (openingCode >= 40 && openingCode <= 47)
|
|
2056
|
+
return 49;
|
|
2057
|
+
if (openingCode >= 100 && openingCode <= 107)
|
|
2058
|
+
return 49;
|
|
2059
|
+
if (openingCode === 1 || openingCode === 2)
|
|
2060
|
+
return 22;
|
|
2061
|
+
if (openingCode === 3)
|
|
2062
|
+
return 23;
|
|
2063
|
+
if (openingCode === 4)
|
|
2064
|
+
return 24;
|
|
2065
|
+
if (openingCode === 7)
|
|
2066
|
+
return 27;
|
|
2067
|
+
if (openingCode === 8)
|
|
2068
|
+
return 28;
|
|
2069
|
+
if (openingCode === 9)
|
|
2070
|
+
return 29;
|
|
2071
|
+
if (openingCode === 0)
|
|
2072
|
+
return 0;
|
|
2073
|
+
return;
|
|
2074
|
+
};
|
|
2075
|
+
var wrapAnsiCode = (code) => `${ESC}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
|
|
2076
|
+
var wrapAnsiHyperlink = (url) => `${ESC}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
|
|
2077
|
+
var wrapWord = (rows, word, columns) => {
|
|
2078
|
+
const characters = word[Symbol.iterator]();
|
|
2079
|
+
let isInsideEscape = false;
|
|
2080
|
+
let isInsideLinkEscape = false;
|
|
2081
|
+
let lastRow = rows.at(-1);
|
|
2082
|
+
let visible = lastRow === undefined ? 0 : dist_default2(lastRow);
|
|
2083
|
+
let currentCharacter = characters.next();
|
|
2084
|
+
let nextCharacter = characters.next();
|
|
2085
|
+
let rawCharacterIndex = 0;
|
|
2086
|
+
while (!currentCharacter.done) {
|
|
2087
|
+
const character = currentCharacter.value;
|
|
2088
|
+
const characterLength = dist_default2(character);
|
|
2089
|
+
if (visible + characterLength <= columns) {
|
|
2090
|
+
rows[rows.length - 1] += character;
|
|
2091
|
+
} else {
|
|
2092
|
+
rows.push(character);
|
|
2093
|
+
visible = 0;
|
|
2094
|
+
}
|
|
2095
|
+
if (character === ESC || character === CSI) {
|
|
2096
|
+
isInsideEscape = true;
|
|
2097
|
+
isInsideLinkEscape = word.startsWith(ANSI_ESCAPE_LINK, rawCharacterIndex + 1);
|
|
2098
|
+
}
|
|
2099
|
+
if (isInsideEscape) {
|
|
2100
|
+
if (isInsideLinkEscape) {
|
|
2101
|
+
if (character === ANSI_ESCAPE_BELL) {
|
|
2102
|
+
isInsideEscape = false;
|
|
2103
|
+
isInsideLinkEscape = false;
|
|
2104
|
+
}
|
|
2105
|
+
} else if (character === ANSI_SGR_TERMINATOR) {
|
|
2106
|
+
isInsideEscape = false;
|
|
2107
|
+
}
|
|
2108
|
+
} else {
|
|
2109
|
+
visible += characterLength;
|
|
2110
|
+
if (visible === columns && !nextCharacter.done) {
|
|
2111
|
+
rows.push("");
|
|
2112
|
+
visible = 0;
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
currentCharacter = nextCharacter;
|
|
2116
|
+
nextCharacter = characters.next();
|
|
2117
|
+
rawCharacterIndex += character.length;
|
|
2118
|
+
}
|
|
2119
|
+
lastRow = rows.at(-1);
|
|
2120
|
+
if (!visible && lastRow !== undefined && lastRow.length && rows.length > 1) {
|
|
2121
|
+
rows[rows.length - 2] += rows.pop();
|
|
2122
|
+
}
|
|
2123
|
+
};
|
|
2124
|
+
var stringVisibleTrimSpacesRight = (string) => {
|
|
2125
|
+
const words = string.split(" ");
|
|
2126
|
+
let last = words.length;
|
|
2127
|
+
while (last) {
|
|
2128
|
+
if (dist_default2(words[last - 1])) {
|
|
2129
|
+
break;
|
|
2130
|
+
}
|
|
2131
|
+
last--;
|
|
2132
|
+
}
|
|
2133
|
+
if (last === words.length) {
|
|
2134
|
+
return string;
|
|
2135
|
+
}
|
|
2136
|
+
return words.slice(0, last).join(" ") + words.slice(last).join("");
|
|
2137
|
+
};
|
|
2138
|
+
var exec = (string, columns, options = {}) => {
|
|
2139
|
+
if (options.trim !== false && string.trim() === "") {
|
|
2140
|
+
return "";
|
|
2141
|
+
}
|
|
2142
|
+
let returnValue = "";
|
|
2143
|
+
let escapeCode;
|
|
2144
|
+
let escapeUrl;
|
|
2145
|
+
const words = string.split(" ");
|
|
2146
|
+
let rows = [""];
|
|
2147
|
+
let rowLength = 0;
|
|
2148
|
+
for (let index = 0;index < words.length; index++) {
|
|
2149
|
+
const word = words[index];
|
|
2150
|
+
if (options.trim !== false) {
|
|
2151
|
+
const row = rows.at(-1) ?? "";
|
|
2152
|
+
const trimmed = row.trimStart();
|
|
2153
|
+
if (row.length !== trimmed.length) {
|
|
2154
|
+
rows[rows.length - 1] = trimmed;
|
|
2155
|
+
rowLength = dist_default2(trimmed);
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
if (index !== 0) {
|
|
2159
|
+
if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
|
|
2160
|
+
rows.push("");
|
|
2161
|
+
rowLength = 0;
|
|
2162
|
+
}
|
|
2163
|
+
if (rowLength || options.trim === false) {
|
|
2164
|
+
rows[rows.length - 1] += " ";
|
|
2165
|
+
rowLength++;
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
const wordLength = dist_default2(word);
|
|
2169
|
+
if (options.hard && wordLength > columns) {
|
|
2170
|
+
const remainingColumns = columns - rowLength;
|
|
2171
|
+
const breaksStartingThisLine = 1 + Math.floor((wordLength - remainingColumns - 1) / columns);
|
|
2172
|
+
const breaksStartingNextLine = Math.floor((wordLength - 1) / columns);
|
|
2173
|
+
if (breaksStartingNextLine < breaksStartingThisLine) {
|
|
2174
|
+
rows.push("");
|
|
2175
|
+
}
|
|
2176
|
+
wrapWord(rows, word, columns);
|
|
2177
|
+
rowLength = dist_default2(rows.at(-1) ?? "");
|
|
2178
|
+
continue;
|
|
2179
|
+
}
|
|
2180
|
+
if (rowLength + wordLength > columns && rowLength && wordLength) {
|
|
2181
|
+
if (options.wordWrap === false && rowLength < columns) {
|
|
2182
|
+
wrapWord(rows, word, columns);
|
|
2183
|
+
rowLength = dist_default2(rows.at(-1) ?? "");
|
|
2184
|
+
continue;
|
|
2185
|
+
}
|
|
2186
|
+
rows.push("");
|
|
2187
|
+
rowLength = 0;
|
|
2188
|
+
}
|
|
2189
|
+
if (rowLength + wordLength > columns && options.wordWrap === false) {
|
|
2190
|
+
wrapWord(rows, word, columns);
|
|
2191
|
+
rowLength = dist_default2(rows.at(-1) ?? "");
|
|
2192
|
+
continue;
|
|
2193
|
+
}
|
|
2194
|
+
rows[rows.length - 1] += word;
|
|
2195
|
+
rowLength += wordLength;
|
|
2196
|
+
}
|
|
2197
|
+
if (options.trim !== false) {
|
|
2198
|
+
rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
|
|
2199
|
+
}
|
|
2200
|
+
const preString = rows.join(`
|
|
2201
|
+
`);
|
|
2202
|
+
let inSurrogate = false;
|
|
2203
|
+
for (let i = 0;i < preString.length; i++) {
|
|
2204
|
+
const character = preString[i];
|
|
2205
|
+
returnValue += character;
|
|
2206
|
+
if (!inSurrogate) {
|
|
2207
|
+
inSurrogate = character >= "\uD800" && character <= "\uDBFF";
|
|
2208
|
+
if (inSurrogate) {
|
|
2209
|
+
continue;
|
|
2210
|
+
}
|
|
2211
|
+
} else {
|
|
2212
|
+
inSurrogate = false;
|
|
2213
|
+
}
|
|
2214
|
+
if (character === ESC || character === CSI) {
|
|
2215
|
+
GROUP_REGEX.lastIndex = i + 1;
|
|
2216
|
+
const groupsResult = GROUP_REGEX.exec(preString);
|
|
2217
|
+
const groups = groupsResult?.groups;
|
|
2218
|
+
if (groups?.code !== undefined) {
|
|
2219
|
+
const code = Number.parseFloat(groups.code);
|
|
2220
|
+
escapeCode = code === END_CODE ? undefined : code;
|
|
2221
|
+
} else if (groups?.uri !== undefined) {
|
|
2222
|
+
escapeUrl = groups.uri.length === 0 ? undefined : groups.uri;
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
if (preString[i + 1] === `
|
|
2226
|
+
`) {
|
|
2227
|
+
if (escapeUrl) {
|
|
2228
|
+
returnValue += wrapAnsiHyperlink("");
|
|
2229
|
+
}
|
|
2230
|
+
const closingCode = escapeCode ? getClosingCode(escapeCode) : undefined;
|
|
2231
|
+
if (escapeCode && closingCode) {
|
|
2232
|
+
returnValue += wrapAnsiCode(closingCode);
|
|
2233
|
+
}
|
|
2234
|
+
} else if (character === `
|
|
2235
|
+
`) {
|
|
2236
|
+
if (escapeCode && getClosingCode(escapeCode)) {
|
|
2237
|
+
returnValue += wrapAnsiCode(escapeCode);
|
|
2238
|
+
}
|
|
2239
|
+
if (escapeUrl) {
|
|
2240
|
+
returnValue += wrapAnsiHyperlink(escapeUrl);
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
return returnValue;
|
|
2245
|
+
};
|
|
2246
|
+
var CRLF_OR_LF = /\r?\n/;
|
|
2247
|
+
function wrapAnsi(string, columns, options) {
|
|
2248
|
+
return String(string).normalize().split(CRLF_OR_LF).map((line) => exec(line, columns, options)).join(`
|
|
2249
|
+
`);
|
|
2250
|
+
}
|
|
2251
|
+
|
|
2252
|
+
// ../../node_modules/.bun/@clack+core@1.4.3/node_modules/@clack/core/dist/index.mjs
|
|
2253
|
+
var import_sisteransi = __toESM(require_src(), 1);
|
|
2254
|
+
import { ReadStream } from "tty";
|
|
2255
|
+
function findCursor(s, o, l2) {
|
|
2256
|
+
if (!l2.some((r) => !r.disabled))
|
|
2257
|
+
return s;
|
|
2258
|
+
const t = s + o, n = Math.max(l2.length - 1, 0), e = t < 0 ? n : t > n ? 0 : t;
|
|
2259
|
+
return l2[e]?.disabled ? findCursor(e, o < 0 ? -1 : 1, l2) : e;
|
|
2260
|
+
}
|
|
2261
|
+
function findTextCursor(s, o, l2, i) {
|
|
2262
|
+
const t = i.split(`
|
|
2263
|
+
`);
|
|
2264
|
+
let n = 0, e = s;
|
|
2265
|
+
for (const r of t) {
|
|
2266
|
+
if (e <= r.length)
|
|
2267
|
+
break;
|
|
2268
|
+
e -= r.length + 1, n++;
|
|
2269
|
+
}
|
|
2270
|
+
for (n = Math.max(0, Math.min(t.length - 1, n + l2)), e = Math.min(e, t[n].length) + o;e < 0 && n > 0; )
|
|
2271
|
+
n--, e += t[n].length + 1;
|
|
2272
|
+
for (;e > t[n].length && n < t.length - 1; )
|
|
2273
|
+
e -= t[n].length + 1, n++;
|
|
2274
|
+
e = Math.max(0, Math.min(t[n].length, e));
|
|
2275
|
+
let h = 0;
|
|
2276
|
+
for (let r = 0;r < n; r++)
|
|
2277
|
+
h += t[r].length + 1;
|
|
2278
|
+
return h + e;
|
|
2279
|
+
}
|
|
2280
|
+
var a$1 = ["up", "down", "left", "right", "space", "enter", "cancel"];
|
|
2281
|
+
var t = [
|
|
2282
|
+
"January",
|
|
2283
|
+
"February",
|
|
2284
|
+
"March",
|
|
2285
|
+
"April",
|
|
2286
|
+
"May",
|
|
2287
|
+
"June",
|
|
2288
|
+
"July",
|
|
2289
|
+
"August",
|
|
2290
|
+
"September",
|
|
2291
|
+
"October",
|
|
2292
|
+
"November",
|
|
2293
|
+
"December"
|
|
2294
|
+
];
|
|
2295
|
+
var settings = {
|
|
2296
|
+
actions: new Set(a$1),
|
|
2297
|
+
aliases: /* @__PURE__ */ new Map([
|
|
2298
|
+
["k", "up"],
|
|
2299
|
+
["j", "down"],
|
|
2300
|
+
["h", "left"],
|
|
2301
|
+
["l", "right"],
|
|
2302
|
+
["\x03", "cancel"],
|
|
2303
|
+
["escape", "cancel"]
|
|
2304
|
+
]),
|
|
2305
|
+
messages: {
|
|
2306
|
+
cancel: "Canceled",
|
|
2307
|
+
error: "Something went wrong"
|
|
2308
|
+
},
|
|
2309
|
+
withGuide: true,
|
|
2310
|
+
date: {
|
|
2311
|
+
monthNames: [...t],
|
|
2312
|
+
messages: {
|
|
2313
|
+
required: "Please enter a valid date",
|
|
2314
|
+
invalidMonth: "There are only 12 months in a year",
|
|
2315
|
+
invalidDay: (n, e) => `There are only ${n} days in ${e}`,
|
|
2316
|
+
afterMin: (n) => `Date must be on or after ${n.toISOString().slice(0, 10)}`,
|
|
2317
|
+
beforeMax: (n) => `Date must be on or before ${n.toISOString().slice(0, 10)}`
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
};
|
|
2321
|
+
function isActionKey(n, e) {
|
|
2322
|
+
if (typeof n == "string")
|
|
2323
|
+
return settings.aliases.get(n) === e;
|
|
2324
|
+
for (const s of n)
|
|
2325
|
+
if (s !== undefined && isActionKey(s, e))
|
|
2326
|
+
return true;
|
|
2327
|
+
return false;
|
|
2328
|
+
}
|
|
2329
|
+
function diffLines(i, s) {
|
|
2330
|
+
if (i === s)
|
|
2331
|
+
return;
|
|
2332
|
+
const e = i.split(`
|
|
2333
|
+
`), t2 = s.split(`
|
|
2334
|
+
`), r = Math.max(e.length, t2.length), f = [];
|
|
2335
|
+
for (let n = 0;n < r; n++)
|
|
2336
|
+
e[n] !== t2[n] && f.push(n);
|
|
2337
|
+
return {
|
|
2338
|
+
lines: f,
|
|
2339
|
+
numLinesBefore: e.length,
|
|
2340
|
+
numLinesAfter: t2.length,
|
|
2341
|
+
numLines: r
|
|
2342
|
+
};
|
|
2343
|
+
}
|
|
2344
|
+
var R = globalThis.process.platform.startsWith("win");
|
|
2345
|
+
var CANCEL_SYMBOL = Symbol("clack:cancel");
|
|
2346
|
+
function isCancel(e) {
|
|
2347
|
+
return e === CANCEL_SYMBOL;
|
|
2348
|
+
}
|
|
2349
|
+
function setRawMode(e, r) {
|
|
2350
|
+
const o = e;
|
|
2351
|
+
o.isTTY && o.setRawMode(r);
|
|
2352
|
+
}
|
|
2353
|
+
function block({
|
|
2354
|
+
input: e = stdin,
|
|
2355
|
+
output: r = stdout,
|
|
2356
|
+
overwrite: o = true,
|
|
2357
|
+
hideCursor: t2 = true
|
|
2358
|
+
} = {}) {
|
|
2359
|
+
const s = l.createInterface({
|
|
2360
|
+
input: e,
|
|
2361
|
+
output: r,
|
|
2362
|
+
prompt: "",
|
|
2363
|
+
tabSize: 1
|
|
2364
|
+
});
|
|
2365
|
+
l.emitKeypressEvents(e, s), e instanceof ReadStream && e.isTTY && e.setRawMode(true);
|
|
2366
|
+
const n = (f, { name: a, sequence: p }) => {
|
|
2367
|
+
const c = String(f);
|
|
2368
|
+
if (isActionKey([c, a, p], "cancel")) {
|
|
2369
|
+
t2 && r.write(import_sisteransi.cursor.show), process.exit(0);
|
|
2370
|
+
return;
|
|
2371
|
+
}
|
|
2372
|
+
if (!o)
|
|
2373
|
+
return;
|
|
2374
|
+
const i = a === "return" ? 0 : -1, m = a === "return" ? -1 : 0;
|
|
2375
|
+
l.moveCursor(r, i, m, () => {
|
|
2376
|
+
l.clearLine(r, 1, () => {
|
|
2377
|
+
e.once("keypress", n);
|
|
2378
|
+
});
|
|
2379
|
+
});
|
|
2380
|
+
};
|
|
2381
|
+
return t2 && r.write(import_sisteransi.cursor.hide), e.once("keypress", n), () => {
|
|
2382
|
+
e.off("keypress", n), t2 && r.write(import_sisteransi.cursor.show), e instanceof ReadStream && e.isTTY && !R && e.setRawMode(false), s.terminal = false, s.close();
|
|
2383
|
+
};
|
|
2384
|
+
}
|
|
2385
|
+
var getColumns = (e) => ("columns" in e) && typeof e.columns == "number" ? e.columns : 80;
|
|
2386
|
+
var getRows = (e) => ("rows" in e) && typeof e.rows == "number" ? e.rows : 20;
|
|
2387
|
+
function wrapTextWithPrefix(e, r, o, t2 = o, s = o, n) {
|
|
2388
|
+
const f = getColumns(e ?? stdout);
|
|
2389
|
+
return wrapAnsi(r, f - o.length, {
|
|
2390
|
+
hard: true,
|
|
2391
|
+
trim: false
|
|
2392
|
+
}).split(`
|
|
2393
|
+
`).map((c, i, m) => {
|
|
2394
|
+
const d = n ? n(c, i) : c;
|
|
2395
|
+
return i === 0 ? `${t2}${d}` : i === m.length - 1 ? `${s}${d}` : `${o}${d}`;
|
|
2396
|
+
}).join(`
|
|
2397
|
+
`);
|
|
2398
|
+
}
|
|
2399
|
+
function runValidation(e, n) {
|
|
2400
|
+
if ("~standard" in e) {
|
|
2401
|
+
const a = e["~standard"].validate(n);
|
|
2402
|
+
if (a instanceof Promise)
|
|
2403
|
+
throw new TypeError("Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic.");
|
|
2404
|
+
return a.issues?.at(0)?.message;
|
|
2405
|
+
}
|
|
2406
|
+
return e(n);
|
|
2407
|
+
}
|
|
2408
|
+
|
|
2409
|
+
class V {
|
|
2410
|
+
input;
|
|
2411
|
+
output;
|
|
2412
|
+
_abortSignal;
|
|
2413
|
+
rl;
|
|
2414
|
+
opts;
|
|
2415
|
+
_render;
|
|
2416
|
+
_track = false;
|
|
2417
|
+
_prevFrame = "";
|
|
2418
|
+
_subscribers = /* @__PURE__ */ new Map;
|
|
2419
|
+
_cursor = 0;
|
|
2420
|
+
state = "initial";
|
|
2421
|
+
error = "";
|
|
2422
|
+
value;
|
|
2423
|
+
userInput = "";
|
|
2424
|
+
constructor(t2, e = true) {
|
|
2425
|
+
const { input: i = stdin, output: n = stdout, render: s, signal: r, ...o } = t2;
|
|
2426
|
+
this.opts = o, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = s.bind(this), this._track = e, this._abortSignal = r, this.input = i, this.output = n;
|
|
2427
|
+
}
|
|
2428
|
+
unsubscribe() {
|
|
2429
|
+
this._subscribers.clear();
|
|
2430
|
+
}
|
|
2431
|
+
setSubscriber(t2, e) {
|
|
2432
|
+
const i = this._subscribers.get(t2) ?? [];
|
|
2433
|
+
i.push(e), this._subscribers.set(t2, i);
|
|
2434
|
+
}
|
|
2435
|
+
on(t2, e) {
|
|
2436
|
+
this.setSubscriber(t2, { cb: e });
|
|
2437
|
+
}
|
|
2438
|
+
once(t2, e) {
|
|
2439
|
+
this.setSubscriber(t2, { cb: e, once: true });
|
|
2440
|
+
}
|
|
2441
|
+
emit(t2, ...e) {
|
|
2442
|
+
const i = this._subscribers.get(t2) ?? [], n = [];
|
|
2443
|
+
for (const s of i)
|
|
2444
|
+
s.cb(...e), s.once && n.push(() => i.splice(i.indexOf(s), 1));
|
|
2445
|
+
for (const s of n)
|
|
2446
|
+
s();
|
|
2447
|
+
}
|
|
2448
|
+
prompt() {
|
|
2449
|
+
return new Promise((t2) => {
|
|
2450
|
+
if (this._abortSignal) {
|
|
2451
|
+
if (this._abortSignal.aborted)
|
|
2452
|
+
return this.state = "cancel", this.close(), t2(CANCEL_SYMBOL);
|
|
2453
|
+
this._abortSignal.addEventListener("abort", () => {
|
|
2454
|
+
this.state = "cancel", this.close();
|
|
2455
|
+
}, { once: true });
|
|
2456
|
+
}
|
|
2457
|
+
this.rl = l__default.createInterface({
|
|
2458
|
+
input: this.input,
|
|
2459
|
+
tabSize: 2,
|
|
2460
|
+
prompt: "",
|
|
2461
|
+
escapeCodeTimeout: 50,
|
|
2462
|
+
terminal: true
|
|
2463
|
+
}), this.rl.prompt(), this.opts.initialUserInput !== undefined && this._setUserInput(this.opts.initialUserInput, true), this.input.on("keypress", this.onKeypress), setRawMode(this.input, true), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
|
|
2464
|
+
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t2(this.value);
|
|
2465
|
+
}), this.once("cancel", () => {
|
|
2466
|
+
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t2(CANCEL_SYMBOL);
|
|
2467
|
+
});
|
|
2468
|
+
});
|
|
2469
|
+
}
|
|
2470
|
+
_isActionKey(t2, e) {
|
|
2471
|
+
return t2 === "\t";
|
|
2472
|
+
}
|
|
2473
|
+
_shouldSubmit(t2, e) {
|
|
2474
|
+
return true;
|
|
2475
|
+
}
|
|
2476
|
+
_setValue(t2) {
|
|
2477
|
+
this.value = t2, this.emit("value", this.value);
|
|
2478
|
+
}
|
|
2479
|
+
_setUserInput(t2, e) {
|
|
2480
|
+
this.userInput = t2 ?? "", this.emit("userInput", this.userInput), e && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
|
|
2481
|
+
}
|
|
2482
|
+
_clearUserInput() {
|
|
2483
|
+
this.rl?.write(null, { ctrl: true, name: "u" }), this._setUserInput("");
|
|
2484
|
+
}
|
|
2485
|
+
onKeypress(t2, e) {
|
|
2486
|
+
if (this._track && e.name !== "return" && (e.name && this._isActionKey(t2, e) && this.rl?.write(null, { ctrl: true, name: "h" }), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), e?.name && (!this._track && settings.aliases.has(e.name) && this.emit("cursor", settings.aliases.get(e.name)), settings.actions.has(e.name) && this.emit("cursor", e.name)), t2 && (t2.toLowerCase() === "y" || t2.toLowerCase() === "n") && this.emit("confirm", t2.toLowerCase() === "y"), this.emit("key", t2, e), e?.name === "return" && this._shouldSubmit(t2, e)) {
|
|
2487
|
+
if (this.opts.validate) {
|
|
2488
|
+
const i = runValidation(this.opts.validate, this.value);
|
|
2489
|
+
i && (this.error = i instanceof Error ? i.message : i, this.state = "error", this.rl?.write(this.userInput));
|
|
2490
|
+
}
|
|
2491
|
+
this.state !== "error" && (this.state = "submit");
|
|
2492
|
+
}
|
|
2493
|
+
isActionKey([t2, e?.name, e?.sequence], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
|
|
2494
|
+
}
|
|
2495
|
+
close() {
|
|
2496
|
+
this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
|
|
2497
|
+
`), setRawMode(this.input, false), this.rl?.close(), this.rl = undefined, this.emit(`${this.state}`, this.value), this.unsubscribe();
|
|
2498
|
+
}
|
|
2499
|
+
restoreCursor() {
|
|
2500
|
+
const t2 = wrapAnsi(this._prevFrame, process.stdout.columns, { hard: true, trim: false }).split(`
|
|
2501
|
+
`).length - 1;
|
|
2502
|
+
this.output.write(import_sisteransi.cursor.move(-999, t2 * -1));
|
|
2503
|
+
}
|
|
2504
|
+
render() {
|
|
2505
|
+
const t2 = wrapAnsi(this._render(this) ?? "", process.stdout.columns, {
|
|
2506
|
+
hard: true,
|
|
2507
|
+
trim: false
|
|
2508
|
+
});
|
|
2509
|
+
if (t2 !== this._prevFrame) {
|
|
2510
|
+
if (this.state === "initial")
|
|
2511
|
+
this.output.write(import_sisteransi.cursor.hide);
|
|
2512
|
+
else {
|
|
2513
|
+
const e = diffLines(this._prevFrame, t2), i = getRows(this.output);
|
|
2514
|
+
if (this.restoreCursor(), e) {
|
|
2515
|
+
const n = Math.max(0, e.numLinesAfter - i), s = Math.max(0, e.numLinesBefore - i);
|
|
2516
|
+
let r = e.lines.find((o) => o >= n);
|
|
2517
|
+
if (r === undefined) {
|
|
2518
|
+
this._prevFrame = t2;
|
|
2519
|
+
return;
|
|
2520
|
+
}
|
|
2521
|
+
if (e.lines.length === 1) {
|
|
2522
|
+
this.output.write(import_sisteransi.cursor.move(0, r - s)), this.output.write(import_sisteransi.erase.lines(1));
|
|
2523
|
+
const o = t2.split(`
|
|
2524
|
+
`);
|
|
2525
|
+
this.output.write(o[r]), this._prevFrame = t2, this.output.write(import_sisteransi.cursor.move(0, o.length - r - 1));
|
|
2526
|
+
return;
|
|
2527
|
+
} else if (e.lines.length > 1) {
|
|
2528
|
+
if (n < s)
|
|
2529
|
+
r = n;
|
|
2530
|
+
else {
|
|
2531
|
+
const h = r - s;
|
|
2532
|
+
h > 0 && this.output.write(import_sisteransi.cursor.move(0, h));
|
|
2533
|
+
}
|
|
2534
|
+
this.output.write(import_sisteransi.erase.down());
|
|
2535
|
+
const f = t2.split(`
|
|
2536
|
+
`).slice(r);
|
|
2537
|
+
this.output.write(f.join(`
|
|
2538
|
+
`)), this._prevFrame = t2;
|
|
2539
|
+
return;
|
|
2540
|
+
}
|
|
2541
|
+
}
|
|
2542
|
+
this.output.write(import_sisteransi.erase.down());
|
|
2543
|
+
}
|
|
2544
|
+
this.output.write(t2), this.state === "initial" && (this.state = "active"), this._prevFrame = t2;
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2548
|
+
function p$1(l2, e) {
|
|
2549
|
+
if (l2 === undefined || e.length === 0)
|
|
2550
|
+
return 0;
|
|
2551
|
+
const i = e.findIndex((s) => s.value === l2);
|
|
2552
|
+
return i !== -1 ? i : 0;
|
|
2553
|
+
}
|
|
2554
|
+
function g(l2, e) {
|
|
2555
|
+
return (e.label ?? String(e.value)).toLowerCase().includes(l2.toLowerCase());
|
|
2556
|
+
}
|
|
2557
|
+
function m(l2, e) {
|
|
2558
|
+
if (e)
|
|
2559
|
+
return l2 ? e : e[0];
|
|
2560
|
+
}
|
|
2561
|
+
var T$1 = class T extends V {
|
|
2562
|
+
filteredOptions;
|
|
2563
|
+
multiple;
|
|
2564
|
+
isNavigating = false;
|
|
2565
|
+
selectedValues = [];
|
|
2566
|
+
focusedValue;
|
|
2567
|
+
#e = 0;
|
|
2568
|
+
#s = "";
|
|
2569
|
+
#t;
|
|
2570
|
+
#i;
|
|
2571
|
+
#n;
|
|
2572
|
+
get cursor() {
|
|
2573
|
+
return this.#e;
|
|
2574
|
+
}
|
|
2575
|
+
get userInputWithCursor() {
|
|
2576
|
+
if (!this.userInput)
|
|
2577
|
+
return styleText(["inverse", "hidden"], "_");
|
|
2578
|
+
if (this._cursor >= this.userInput.length)
|
|
2579
|
+
return `${this.userInput}\u2588`;
|
|
2580
|
+
const e = this.userInput.slice(0, this.cursor), t2 = this.userInput.slice(this.cursor, this.cursor + 1), i = this.userInput.slice(this.cursor + 1);
|
|
2581
|
+
return `${e}${styleText("inverse", t2)}${i}`;
|
|
2582
|
+
}
|
|
2583
|
+
get options() {
|
|
2584
|
+
return typeof this.#i == "function" ? this.#i() : this.#i;
|
|
2585
|
+
}
|
|
2586
|
+
constructor(e) {
|
|
2587
|
+
super(e), this.#i = e.options, this.#n = e.placeholder;
|
|
2588
|
+
const t2 = this.options;
|
|
2589
|
+
this.filteredOptions = [...t2], this.multiple = e.multiple === true, this.#t = typeof e.options == "function" ? e.filter : e.filter ?? g;
|
|
2590
|
+
let i;
|
|
2591
|
+
if (e.initialValue && Array.isArray(e.initialValue) ? this.multiple ? i = e.initialValue : i = e.initialValue.slice(0, 1) : !this.multiple && this.options.length > 0 && (i = [this.options[0]?.value]), i)
|
|
2592
|
+
for (const s of i) {
|
|
2593
|
+
const n = t2.findIndex((o) => o.value === s);
|
|
2594
|
+
n !== -1 && (this.toggleSelected(s), this.#e = n);
|
|
2595
|
+
}
|
|
2596
|
+
this.focusedValue = this.options[this.#e]?.value, this.on("key", (s, n) => this.#l(s, n)), this.on("userInput", (s) => this.#u(s));
|
|
2597
|
+
}
|
|
2598
|
+
_isActionKey(e, t2) {
|
|
2599
|
+
return e === "\t" || this.multiple && this.isNavigating && t2.name === "space" && e !== undefined && e !== "";
|
|
2600
|
+
}
|
|
2601
|
+
#l(e, t2) {
|
|
2602
|
+
const i = t2.name === "up", s = t2.name === "down", n = t2.name === "return", o = this.userInput === "" || this.userInput === "\t", u = this.#n, a = this.options, f = u !== undefined && u !== "" && a.some((r) => !r.disabled && (this.#t ? this.#t(u, r) : true));
|
|
2603
|
+
if (t2.name === "tab" && o && f) {
|
|
2604
|
+
this.userInput === "\t" && this._clearUserInput(), this._setUserInput(u, true), this.isNavigating = false;
|
|
2605
|
+
return;
|
|
2606
|
+
}
|
|
2607
|
+
i || s ? (this.#e = findCursor(this.#e, i ? -1 : 1, this.filteredOptions), this.focusedValue = this.filteredOptions[this.#e]?.value, this.multiple || (this.selectedValues = [this.focusedValue]), this.isNavigating = true) : n ? this.value = m(this.multiple, this.selectedValues) : this.multiple ? this.focusedValue !== undefined && (t2.name === "tab" || this.isNavigating && t2.name === "space") ? this.toggleSelected(this.focusedValue) : this.isNavigating = false : (this.focusedValue && (this.selectedValues = [this.focusedValue]), this.isNavigating = false);
|
|
2608
|
+
}
|
|
2609
|
+
deselectAll() {
|
|
2610
|
+
this.selectedValues = [];
|
|
2611
|
+
}
|
|
2612
|
+
toggleSelected(e) {
|
|
2613
|
+
this.filteredOptions.length !== 0 && (this.multiple ? this.selectedValues.includes(e) ? this.selectedValues = this.selectedValues.filter((t2) => t2 !== e) : this.selectedValues = [...this.selectedValues, e] : this.selectedValues = [e]);
|
|
2614
|
+
}
|
|
2615
|
+
#u(e) {
|
|
2616
|
+
if (e !== this.#s) {
|
|
2617
|
+
this.#s = e;
|
|
2618
|
+
const t2 = this.options;
|
|
2619
|
+
e && this.#t ? this.filteredOptions = t2.filter((n) => this.#t?.(e, n)) : this.filteredOptions = [...t2];
|
|
2620
|
+
const i = p$1(this.focusedValue, this.filteredOptions);
|
|
2621
|
+
this.#e = findCursor(i, 0, this.filteredOptions);
|
|
2622
|
+
const s = this.filteredOptions[this.#e];
|
|
2623
|
+
s && !s.disabled ? this.focusedValue = s.value : this.focusedValue = undefined, this.multiple || (this.focusedValue !== undefined ? this.toggleSelected(this.focusedValue) : this.deselectAll());
|
|
2624
|
+
}
|
|
2625
|
+
}
|
|
2626
|
+
};
|
|
2627
|
+
|
|
2628
|
+
class r extends V {
|
|
2629
|
+
get cursor() {
|
|
2630
|
+
return this.value ? 0 : 1;
|
|
2631
|
+
}
|
|
2632
|
+
get _value() {
|
|
2633
|
+
return this.cursor === 0;
|
|
2634
|
+
}
|
|
2635
|
+
constructor(t2) {
|
|
2636
|
+
super(t2, false), this.value = !!t2.initialValue, this.on("userInput", () => {
|
|
2637
|
+
this.value = this._value;
|
|
2638
|
+
}), this.on("confirm", (i) => {
|
|
2639
|
+
this.output.write(import_sisteransi.cursor.move(0, -1)), this.value = i, this.state = "submit", this.close();
|
|
2640
|
+
}), this.on("cursor", () => {
|
|
2641
|
+
this.value = !this.value;
|
|
2642
|
+
});
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2645
|
+
var _ = {
|
|
2646
|
+
Y: { type: "year", len: 4 },
|
|
2647
|
+
M: { type: "month", len: 2 },
|
|
2648
|
+
D: { type: "day", len: 2 }
|
|
2649
|
+
};
|
|
2650
|
+
function M(r2) {
|
|
2651
|
+
return [...r2].map((t2) => _[t2]);
|
|
2652
|
+
}
|
|
2653
|
+
function P(r2) {
|
|
2654
|
+
const i = new Intl.DateTimeFormat(r2, {
|
|
2655
|
+
year: "numeric",
|
|
2656
|
+
month: "2-digit",
|
|
2657
|
+
day: "2-digit"
|
|
2658
|
+
}).formatToParts(new Date(2000, 0, 15)), s = [];
|
|
2659
|
+
let n = "/";
|
|
2660
|
+
for (const e of i)
|
|
2661
|
+
e.type === "literal" ? n = e.value.trim() || e.value : (e.type === "year" || e.type === "month" || e.type === "day") && s.push({ type: e.type, len: e.type === "year" ? 4 : 2 });
|
|
2662
|
+
return { segments: s, separator: n };
|
|
2663
|
+
}
|
|
2664
|
+
function p(r2) {
|
|
2665
|
+
return Number.parseInt((r2 || "0").replace(/_/g, "0"), 10) || 0;
|
|
2666
|
+
}
|
|
2667
|
+
function f(r2) {
|
|
2668
|
+
return {
|
|
2669
|
+
year: p(r2.year),
|
|
2670
|
+
month: p(r2.month),
|
|
2671
|
+
day: p(r2.day)
|
|
2672
|
+
};
|
|
2673
|
+
}
|
|
2674
|
+
function c(r2, t2) {
|
|
2675
|
+
return new Date(r2 || 2001, t2 || 1, 0).getDate();
|
|
2676
|
+
}
|
|
2677
|
+
function b(r2) {
|
|
2678
|
+
const { year: t2, month: i, day: s } = f(r2);
|
|
2679
|
+
if (!t2 || t2 < 0 || t2 > 9999 || !i || i < 1 || i > 12 || !s || s < 1)
|
|
2680
|
+
return;
|
|
2681
|
+
const n = new Date(Date.UTC(t2, i - 1, s));
|
|
2682
|
+
if (!(n.getUTCFullYear() !== t2 || n.getUTCMonth() !== i - 1 || n.getUTCDate() !== s))
|
|
2683
|
+
return { year: t2, month: i, day: s };
|
|
2684
|
+
}
|
|
2685
|
+
function C(r2) {
|
|
2686
|
+
const t2 = b(r2);
|
|
2687
|
+
return t2 ? new Date(Date.UTC(t2.year, t2.month - 1, t2.day)) : undefined;
|
|
2688
|
+
}
|
|
2689
|
+
function T2(r2, t2, i, s) {
|
|
2690
|
+
const n = i ? {
|
|
2691
|
+
year: i.getUTCFullYear(),
|
|
2692
|
+
month: i.getUTCMonth() + 1,
|
|
2693
|
+
day: i.getUTCDate()
|
|
2694
|
+
} : null, e = s ? {
|
|
2695
|
+
year: s.getUTCFullYear(),
|
|
2696
|
+
month: s.getUTCMonth() + 1,
|
|
2697
|
+
day: s.getUTCDate()
|
|
2698
|
+
} : null;
|
|
2699
|
+
return r2 === "year" ? { min: n?.year ?? 1, max: e?.year ?? 9999 } : r2 === "month" ? {
|
|
2700
|
+
min: n && t2.year === n.year ? n.month : 1,
|
|
2701
|
+
max: e && t2.year === e.year ? e.month : 12
|
|
2702
|
+
} : {
|
|
2703
|
+
min: n && t2.year === n.year && t2.month === n.month ? n.day : 1,
|
|
2704
|
+
max: e && t2.year === e.year && t2.month === e.month ? e.day : c(t2.year, t2.month)
|
|
2705
|
+
};
|
|
2706
|
+
}
|
|
2707
|
+
|
|
2708
|
+
class U extends V {
|
|
2709
|
+
#i;
|
|
2710
|
+
#o;
|
|
2711
|
+
#t;
|
|
2712
|
+
#h;
|
|
2713
|
+
#u;
|
|
2714
|
+
#e = { segmentIndex: 0, positionInSegment: 0 };
|
|
2715
|
+
#n = true;
|
|
2716
|
+
#s = null;
|
|
2717
|
+
inlineError = "";
|
|
2718
|
+
get segmentCursor() {
|
|
2719
|
+
return { ...this.#e };
|
|
2720
|
+
}
|
|
2721
|
+
get segmentValues() {
|
|
2722
|
+
return { ...this.#t };
|
|
2723
|
+
}
|
|
2724
|
+
get segments() {
|
|
2725
|
+
return this.#i;
|
|
2726
|
+
}
|
|
2727
|
+
get separator() {
|
|
2728
|
+
return this.#o;
|
|
2729
|
+
}
|
|
2730
|
+
get formattedValue() {
|
|
2731
|
+
return this.#l(this.#t);
|
|
2732
|
+
}
|
|
2733
|
+
#l(t2) {
|
|
2734
|
+
return this.#i.map((i) => t2[i.type]).join(this.#o);
|
|
2735
|
+
}
|
|
2736
|
+
#r() {
|
|
2737
|
+
this._setUserInput(this.#l(this.#t)), this._setValue(C(this.#t) ?? undefined);
|
|
2738
|
+
}
|
|
2739
|
+
constructor(t2) {
|
|
2740
|
+
const i = t2.format ? { segments: M(t2.format), separator: t2.separator ?? "/" } : P(t2.locale), s = t2.separator ?? i.separator, n = t2.format ? M(t2.format) : i.segments, e = t2.initialValue ?? t2.defaultValue, m2 = e ? {
|
|
2741
|
+
year: String(e.getUTCFullYear()).padStart(4, "0"),
|
|
2742
|
+
month: String(e.getUTCMonth() + 1).padStart(2, "0"),
|
|
2743
|
+
day: String(e.getUTCDate()).padStart(2, "0")
|
|
2744
|
+
} : { year: "____", month: "__", day: "__" }, o = n.map((a) => m2[a.type]).join(s);
|
|
2745
|
+
super({ ...t2, initialUserInput: o }, false), this.#i = n, this.#o = s, this.#t = m2, this.#h = t2.minDate, this.#u = t2.maxDate, this.#r(), this.on("cursor", (a) => this.#f(a)), this.on("key", (a, u) => this.#y(a, u)), this.on("finalize", () => this.#p(t2));
|
|
2746
|
+
}
|
|
2747
|
+
#a() {
|
|
2748
|
+
const t2 = Math.max(0, Math.min(this.#e.segmentIndex, this.#i.length - 1)), i = this.#i[t2];
|
|
2749
|
+
if (i)
|
|
2750
|
+
return this.#e.positionInSegment = Math.max(0, Math.min(this.#e.positionInSegment, i.len - 1)), { segment: i, index: t2 };
|
|
2751
|
+
}
|
|
2752
|
+
#m(t2) {
|
|
2753
|
+
this.inlineError = "", this.#s = null;
|
|
2754
|
+
const i = this.#a();
|
|
2755
|
+
i && (this.#e.segmentIndex = Math.max(0, Math.min(this.#i.length - 1, i.index + t2)), this.#e.positionInSegment = 0, this.#n = true);
|
|
2756
|
+
}
|
|
2757
|
+
#d(t2) {
|
|
2758
|
+
const i = this.#a();
|
|
2759
|
+
if (!i)
|
|
2760
|
+
return;
|
|
2761
|
+
const { segment: s } = i, n = this.#t[s.type], e = !n || n.replace(/_/g, "") === "", m2 = Number.parseInt((n || "0").replace(/_/g, "0"), 10) || 0, o = T2(s.type, f(this.#t), this.#h, this.#u);
|
|
2762
|
+
let a;
|
|
2763
|
+
e ? a = t2 === 1 ? o.min : o.max : a = Math.max(Math.min(o.max, m2 + t2), o.min), this.#t = {
|
|
2764
|
+
...this.#t,
|
|
2765
|
+
[s.type]: a.toString().padStart(s.len, "0")
|
|
2766
|
+
}, this.#n = true, this.#s = null, this.#r();
|
|
2767
|
+
}
|
|
2768
|
+
#f(t2) {
|
|
2769
|
+
if (t2)
|
|
2770
|
+
switch (t2) {
|
|
2771
|
+
case "right":
|
|
2772
|
+
return this.#m(1);
|
|
2773
|
+
case "left":
|
|
2774
|
+
return this.#m(-1);
|
|
2775
|
+
case "up":
|
|
2776
|
+
return this.#d(1);
|
|
2777
|
+
case "down":
|
|
2778
|
+
return this.#d(-1);
|
|
2779
|
+
}
|
|
2780
|
+
}
|
|
2781
|
+
#y(t2, i) {
|
|
2782
|
+
if (i?.name === "backspace" || i?.sequence === "\x7F" || i?.sequence === "\b" || t2 === "\x7F" || t2 === "\b") {
|
|
2783
|
+
this.inlineError = "";
|
|
2784
|
+
const n = this.#a();
|
|
2785
|
+
if (!n)
|
|
2786
|
+
return;
|
|
2787
|
+
if (!this.#t[n.segment.type].replace(/_/g, "")) {
|
|
2788
|
+
this.#m(-1);
|
|
2789
|
+
return;
|
|
2790
|
+
}
|
|
2791
|
+
this.#t[n.segment.type] = "_".repeat(n.segment.len), this.#n = true, this.#e.positionInSegment = 0, this.#r();
|
|
2792
|
+
return;
|
|
2793
|
+
}
|
|
2794
|
+
if (i?.name === "tab") {
|
|
2795
|
+
this.inlineError = "";
|
|
2796
|
+
const n = this.#a();
|
|
2797
|
+
if (!n)
|
|
2798
|
+
return;
|
|
2799
|
+
const e = i.shift ? -1 : 1, m2 = n.index + e;
|
|
2800
|
+
m2 >= 0 && m2 < this.#i.length && (this.#e.segmentIndex = m2, this.#e.positionInSegment = 0, this.#n = true);
|
|
2801
|
+
return;
|
|
2802
|
+
}
|
|
2803
|
+
if (t2 && /^[0-9]$/.test(t2)) {
|
|
2804
|
+
const n = this.#a();
|
|
2805
|
+
if (!n)
|
|
2806
|
+
return;
|
|
2807
|
+
const { segment: e } = n, m2 = !this.#t[e.type].replace(/_/g, "");
|
|
2808
|
+
if (this.#n && this.#s !== null && !m2) {
|
|
2809
|
+
const h = this.#s + t2, d = { ...this.#t, [e.type]: h }, g2 = this.#g(d, e);
|
|
2810
|
+
if (g2) {
|
|
2811
|
+
this.inlineError = g2, this.#s = null, this.#n = false;
|
|
2812
|
+
return;
|
|
2813
|
+
}
|
|
2814
|
+
this.inlineError = "", this.#t[e.type] = h, this.#s = null, this.#n = false, this.#r(), n.index < this.#i.length - 1 && (this.#e.segmentIndex = n.index + 1, this.#e.positionInSegment = 0, this.#n = true);
|
|
2815
|
+
return;
|
|
2816
|
+
}
|
|
2817
|
+
this.#n && !m2 && (this.#t[e.type] = "_".repeat(e.len), this.#e.positionInSegment = 0), this.#n = false, this.#s = null;
|
|
2818
|
+
const o = this.#t[e.type], a = o.indexOf("_"), u = a >= 0 ? a : Math.min(this.#e.positionInSegment, e.len - 1);
|
|
2819
|
+
if (u < 0 || u >= e.len)
|
|
2820
|
+
return;
|
|
2821
|
+
let l2 = o.slice(0, u) + t2 + o.slice(u + 1), D = false;
|
|
2822
|
+
if (u === 0 && o === "__" && (e.type === "month" || e.type === "day")) {
|
|
2823
|
+
const h = Number.parseInt(t2, 10);
|
|
2824
|
+
l2 = `0${t2}`, D = h <= (e.type === "month" ? 1 : 2);
|
|
2825
|
+
}
|
|
2826
|
+
if (e.type === "year" && (l2 = (o.replace(/_/g, "") + t2).padStart(e.len, "_")), !l2.includes("_")) {
|
|
2827
|
+
const h = { ...this.#t, [e.type]: l2 }, d = this.#g(h, e);
|
|
2828
|
+
if (d) {
|
|
2829
|
+
this.inlineError = d;
|
|
2830
|
+
return;
|
|
2831
|
+
}
|
|
2832
|
+
}
|
|
2833
|
+
this.inlineError = "", this.#t[e.type] = l2;
|
|
2834
|
+
const y = l2.includes("_") ? undefined : b(this.#t);
|
|
2835
|
+
if (y) {
|
|
2836
|
+
const { year: h, month: d } = y, g2 = c(h, d);
|
|
2837
|
+
this.#t = {
|
|
2838
|
+
year: String(Math.max(0, Math.min(9999, h))).padStart(4, "0"),
|
|
2839
|
+
month: String(Math.max(1, Math.min(12, d))).padStart(2, "0"),
|
|
2840
|
+
day: String(Math.max(1, Math.min(g2, y.day))).padStart(2, "0")
|
|
2841
|
+
};
|
|
2842
|
+
}
|
|
2843
|
+
this.#r();
|
|
2844
|
+
const S = l2.indexOf("_");
|
|
2845
|
+
D ? (this.#n = true, this.#s = t2) : S >= 0 ? this.#e.positionInSegment = S : a >= 0 && n.index < this.#i.length - 1 ? (this.#e.segmentIndex = n.index + 1, this.#e.positionInSegment = 0, this.#n = true) : this.#e.positionInSegment = Math.min(u + 1, e.len - 1);
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
#g(t2, i) {
|
|
2849
|
+
const { month: s, day: n } = f(t2);
|
|
2850
|
+
if (i.type === "month" && (s < 0 || s > 12))
|
|
2851
|
+
return settings.date.messages.invalidMonth;
|
|
2852
|
+
if (i.type === "day" && (n < 0 || n > 31))
|
|
2853
|
+
return settings.date.messages.invalidDay(31, "any month");
|
|
2854
|
+
}
|
|
2855
|
+
#p(t2) {
|
|
2856
|
+
const { year: i, month: s, day: n } = f(this.#t);
|
|
2857
|
+
if (i && s && n) {
|
|
2858
|
+
const e = c(i, s);
|
|
2859
|
+
this.#t = {
|
|
2860
|
+
...this.#t,
|
|
2861
|
+
day: String(Math.min(n, e)).padStart(2, "0")
|
|
2862
|
+
};
|
|
2863
|
+
}
|
|
2864
|
+
this.value = C(this.#t) ?? t2.defaultValue ?? undefined;
|
|
2865
|
+
}
|
|
2866
|
+
}
|
|
2867
|
+
var u$2 = class u extends V {
|
|
2868
|
+
options;
|
|
2869
|
+
cursor = 0;
|
|
2870
|
+
#t;
|
|
2871
|
+
getGroupItems(t2) {
|
|
2872
|
+
return this.options.filter((r2) => r2.group === t2);
|
|
2873
|
+
}
|
|
2874
|
+
isGroupSelected(t2) {
|
|
2875
|
+
const r2 = this.getGroupItems(t2), e = this.value;
|
|
2876
|
+
return e === undefined ? false : r2.every((s) => e.includes(s.value));
|
|
2877
|
+
}
|
|
2878
|
+
toggleValue() {
|
|
2879
|
+
const t2 = this.options[this.cursor];
|
|
2880
|
+
if (t2 !== undefined)
|
|
2881
|
+
if (this.value === undefined && (this.value = []), t2.group === true) {
|
|
2882
|
+
const r2 = t2.value, e = this.getGroupItems(r2);
|
|
2883
|
+
this.isGroupSelected(r2) ? this.value = this.value.filter((s) => e.findIndex((i) => i.value === s) === -1) : this.value = [...this.value, ...e.map((s) => s.value)], this.value = Array.from(new Set(this.value));
|
|
2884
|
+
} else {
|
|
2885
|
+
const r2 = this.value.includes(t2.value);
|
|
2886
|
+
this.value = r2 ? this.value.filter((e) => e !== t2.value) : [...this.value, t2.value];
|
|
2887
|
+
}
|
|
2888
|
+
}
|
|
2889
|
+
constructor(t2) {
|
|
2890
|
+
super(t2, false);
|
|
2891
|
+
const { options: r2 } = t2;
|
|
2892
|
+
this.#t = t2.selectableGroups !== false, this.options = Object.entries(r2).flatMap(([e, s]) => [
|
|
2893
|
+
{ value: e, group: true, label: e },
|
|
2894
|
+
...s.map((i) => ({ ...i, group: e }))
|
|
2895
|
+
]), this.value = [...t2.initialValues ?? []], this.cursor = Math.max(this.options.findIndex(({ value: e }) => e === t2.cursorAt), this.#t ? 0 : 1), this.on("cursor", (e) => {
|
|
2896
|
+
switch (e) {
|
|
2897
|
+
case "left":
|
|
2898
|
+
case "up": {
|
|
2899
|
+
this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
|
|
2900
|
+
const s = this.options[this.cursor]?.group === true;
|
|
2901
|
+
!this.#t && s && (this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1);
|
|
2902
|
+
break;
|
|
2903
|
+
}
|
|
2904
|
+
case "down":
|
|
2905
|
+
case "right": {
|
|
2906
|
+
this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
|
|
2907
|
+
const s = this.options[this.cursor]?.group === true;
|
|
2908
|
+
!this.#t && s && (this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1);
|
|
2909
|
+
break;
|
|
2910
|
+
}
|
|
2911
|
+
case "space":
|
|
2912
|
+
this.toggleValue();
|
|
2913
|
+
break;
|
|
2914
|
+
}
|
|
2915
|
+
});
|
|
2916
|
+
}
|
|
2917
|
+
};
|
|
2918
|
+
var o = /* @__PURE__ */ new Set(["up", "down", "left", "right"]);
|
|
2919
|
+
|
|
2920
|
+
class h extends V {
|
|
2921
|
+
#t = false;
|
|
2922
|
+
#s;
|
|
2923
|
+
focused = "editor";
|
|
2924
|
+
get userInputWithCursor() {
|
|
2925
|
+
if (this.state === "submit")
|
|
2926
|
+
return this.userInput;
|
|
2927
|
+
const t2 = this.userInput;
|
|
2928
|
+
if (this.cursor >= t2.length)
|
|
2929
|
+
return `${t2}\u2588`;
|
|
2930
|
+
const s = t2.slice(0, this.cursor), r2 = t2.slice(this.cursor, this.cursor + 1), i = t2.slice(this.cursor + 1);
|
|
2931
|
+
return r2 === `
|
|
2932
|
+
` ? `${s}\u2588
|
|
2933
|
+
${i}` : `${s}${styleText("inverse", r2)}${i}`;
|
|
2934
|
+
}
|
|
2935
|
+
get cursor() {
|
|
2936
|
+
return this._cursor;
|
|
2937
|
+
}
|
|
2938
|
+
#r(t2) {
|
|
2939
|
+
if (this.userInput.length === 0) {
|
|
2940
|
+
this._setUserInput(t2);
|
|
2941
|
+
return;
|
|
2942
|
+
}
|
|
2943
|
+
this._setUserInput(this.userInput.slice(0, this.cursor) + t2 + this.userInput.slice(this.cursor));
|
|
2944
|
+
}
|
|
2945
|
+
#i(t2) {
|
|
2946
|
+
const s = this.value ?? "";
|
|
2947
|
+
switch (t2) {
|
|
2948
|
+
case "up":
|
|
2949
|
+
this._cursor = findTextCursor(this._cursor, 0, -1, s);
|
|
2950
|
+
return;
|
|
2951
|
+
case "down":
|
|
2952
|
+
this._cursor = findTextCursor(this._cursor, 0, 1, s);
|
|
2953
|
+
return;
|
|
2954
|
+
case "left":
|
|
2955
|
+
this._cursor = findTextCursor(this._cursor, -1, 0, s);
|
|
2956
|
+
return;
|
|
2957
|
+
case "right":
|
|
2958
|
+
this._cursor = findTextCursor(this._cursor, 1, 0, s);
|
|
2959
|
+
return;
|
|
2960
|
+
}
|
|
2961
|
+
}
|
|
2962
|
+
_shouldSubmit(t2, s) {
|
|
2963
|
+
if (this.#s)
|
|
2964
|
+
return this.focused === "submit" ? true : (this.#r(`
|
|
2965
|
+
`), this._cursor++, false);
|
|
2966
|
+
const r2 = this.#t;
|
|
2967
|
+
return this.#t = true, r2 && this.cursor === this.userInput.length ? (this.userInput[this.cursor - 1] === `
|
|
2968
|
+
` && (this._setUserInput(this.userInput.slice(0, this.cursor - 1) + this.userInput.slice(this.cursor)), this._cursor--), true) : (this.#r(`
|
|
2969
|
+
`), this._cursor++, false);
|
|
2970
|
+
}
|
|
2971
|
+
constructor(t2) {
|
|
2972
|
+
const s = t2.initialUserInput ?? t2.initialValue;
|
|
2973
|
+
super({
|
|
2974
|
+
...t2,
|
|
2975
|
+
initialUserInput: s
|
|
2976
|
+
}, false), s !== undefined && (this._cursor = s.length), this.#s = t2.showSubmit ?? false, this.on("key", (r2, i) => {
|
|
2977
|
+
if (i?.name && o.has(i.name)) {
|
|
2978
|
+
this.#t = false, this.#i(i.name);
|
|
2979
|
+
return;
|
|
2980
|
+
}
|
|
2981
|
+
if (r2 === "\t" && this.#s) {
|
|
2982
|
+
this.focused = this.focused === "editor" ? "submit" : "editor";
|
|
2983
|
+
return;
|
|
2984
|
+
}
|
|
2985
|
+
if (i?.name !== "return") {
|
|
2986
|
+
if (this.#t = false, i?.name === "backspace" && this.cursor > 0) {
|
|
2987
|
+
this._setUserInput(this.userInput.slice(0, this.cursor - 1) + this.userInput.slice(this.cursor)), this._cursor--;
|
|
2988
|
+
return;
|
|
2989
|
+
}
|
|
2990
|
+
if (i?.name === "delete" && this.cursor < this.userInput.length) {
|
|
2991
|
+
this._setUserInput(this.userInput.slice(0, this.cursor) + this.userInput.slice(this.cursor + 1));
|
|
2992
|
+
return;
|
|
2993
|
+
}
|
|
2994
|
+
r2 && (this.#s && this.focused === "submit" && (this.focused = "editor"), this.#r(r2 ?? ""), this._cursor++);
|
|
2995
|
+
}
|
|
2996
|
+
}), this.on("userInput", (r2) => {
|
|
2997
|
+
this._setValue(r2);
|
|
2998
|
+
}), this.on("finalize", () => {
|
|
2999
|
+
this.value || (this.value = t2.defaultValue), this.value === undefined && (this.value = "");
|
|
3000
|
+
});
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
|
|
3004
|
+
// ../../node_modules/.bun/@clack+prompts@1.7.0/node_modules/@clack/prompts/dist/index.mjs
|
|
3005
|
+
import { styleText as styleText2, stripVTControlCharacters } from "util";
|
|
3006
|
+
import process$1 from "process";
|
|
3007
|
+
var import_sisteransi2 = __toESM(require_src(), 1);
|
|
3008
|
+
function isUnicodeSupported() {
|
|
3009
|
+
if (process$1.platform !== "win32") {
|
|
3010
|
+
return process$1.env.TERM !== "linux";
|
|
3011
|
+
}
|
|
3012
|
+
return Boolean(process$1.env.CI) || Boolean(process$1.env.WT_SESSION) || Boolean(process$1.env.TERMINUS_SUBLIME) || process$1.env.ConEmuTask === "{cmd::Cmder}" || process$1.env.TERM_PROGRAM === "Terminus-Sublime" || process$1.env.TERM_PROGRAM === "vscode" || process$1.env.TERM === "xterm-256color" || process$1.env.TERM === "alacritty" || process$1.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
3013
|
+
}
|
|
3014
|
+
var unicode = isUnicodeSupported();
|
|
3015
|
+
var isCI = () => process.env.CI === "true";
|
|
3016
|
+
var unicodeOr = (o2, e) => unicode ? o2 : e;
|
|
3017
|
+
var S_STEP_ACTIVE = unicodeOr("\u25C6", "*");
|
|
3018
|
+
var S_STEP_CANCEL = unicodeOr("\u25A0", "x");
|
|
3019
|
+
var S_STEP_ERROR = unicodeOr("\u25B2", "x");
|
|
3020
|
+
var S_STEP_SUBMIT = unicodeOr("\u25C7", "o");
|
|
3021
|
+
var S_BAR_START = unicodeOr("\u250C", "T");
|
|
3022
|
+
var S_BAR = unicodeOr("\u2502", "|");
|
|
3023
|
+
var S_BAR_END = unicodeOr("\u2514", "\u2014");
|
|
3024
|
+
var S_BAR_START_RIGHT = unicodeOr("\u2510", "T");
|
|
3025
|
+
var S_BAR_END_RIGHT = unicodeOr("\u2518", "\u2014");
|
|
3026
|
+
var S_RADIO_ACTIVE = unicodeOr("\u25CF", ">");
|
|
3027
|
+
var S_RADIO_INACTIVE = unicodeOr("\u25CB", " ");
|
|
3028
|
+
var S_CHECKBOX_ACTIVE = unicodeOr("\u25FB", "[\u2022]");
|
|
3029
|
+
var S_CHECKBOX_SELECTED = unicodeOr("\u25FC", "[+]");
|
|
3030
|
+
var S_CHECKBOX_INACTIVE = unicodeOr("\u25FB", "[ ]");
|
|
3031
|
+
var S_PASSWORD_MASK = unicodeOr("\u25AA", "\u2022");
|
|
3032
|
+
var S_BAR_H = unicodeOr("\u2500", "-");
|
|
3033
|
+
var S_CORNER_TOP_RIGHT = unicodeOr("\u256E", "+");
|
|
3034
|
+
var S_CONNECT_LEFT = unicodeOr("\u251C", "+");
|
|
3035
|
+
var S_CORNER_BOTTOM_RIGHT = unicodeOr("\u256F", "+");
|
|
3036
|
+
var S_CORNER_BOTTOM_LEFT = unicodeOr("\u2570", "+");
|
|
3037
|
+
var S_CORNER_TOP_LEFT = unicodeOr("\u256D", "+");
|
|
3038
|
+
var S_INFO = unicodeOr("\u25CF", "\u2022");
|
|
3039
|
+
var S_SUCCESS = unicodeOr("\u25C6", "*");
|
|
3040
|
+
var S_WARN = unicodeOr("\u25B2", "!");
|
|
3041
|
+
var S_ERROR = unicodeOr("\u25A0", "x");
|
|
3042
|
+
var symbol = (o2) => {
|
|
3043
|
+
switch (o2) {
|
|
3044
|
+
case "initial":
|
|
3045
|
+
case "active":
|
|
3046
|
+
return styleText2("cyan", S_STEP_ACTIVE);
|
|
3047
|
+
case "cancel":
|
|
3048
|
+
return styleText2("red", S_STEP_CANCEL);
|
|
3049
|
+
case "error":
|
|
3050
|
+
return styleText2("yellow", S_STEP_ERROR);
|
|
3051
|
+
case "submit":
|
|
3052
|
+
return styleText2("green", S_STEP_SUBMIT);
|
|
3053
|
+
}
|
|
3054
|
+
};
|
|
3055
|
+
var confirm = (i) => {
|
|
3056
|
+
const a2 = i.active ?? "Yes", s = i.inactive ?? "No";
|
|
3057
|
+
return new r({
|
|
3058
|
+
active: a2,
|
|
3059
|
+
inactive: s,
|
|
3060
|
+
signal: i.signal,
|
|
3061
|
+
input: i.input,
|
|
3062
|
+
output: i.output,
|
|
3063
|
+
initialValue: i.initialValue ?? true,
|
|
3064
|
+
render() {
|
|
3065
|
+
const e = i.withGuide ?? settings.withGuide, u3 = `${symbol(this.state)} `, l2 = e ? `${styleText2("gray", S_BAR)} ` : "", f2 = wrapTextWithPrefix(i.output, i.message, l2, u3), o2 = `${e ? `${styleText2("gray", S_BAR)}
|
|
3066
|
+
` : ""}${f2}
|
|
3067
|
+
`, c2 = this.value ? a2 : s;
|
|
3068
|
+
switch (this.state) {
|
|
3069
|
+
case "submit": {
|
|
3070
|
+
const r2 = e ? `${styleText2("gray", S_BAR)} ` : "";
|
|
3071
|
+
return `${o2}${r2}${styleText2("dim", c2)}`;
|
|
3072
|
+
}
|
|
3073
|
+
case "cancel": {
|
|
3074
|
+
const r2 = e ? `${styleText2("gray", S_BAR)} ` : "";
|
|
3075
|
+
return `${o2}${r2}${styleText2(["strikethrough", "dim"], c2)}${e ? `
|
|
3076
|
+
${styleText2("gray", S_BAR)}` : ""}`;
|
|
3077
|
+
}
|
|
3078
|
+
default: {
|
|
3079
|
+
const r2 = e ? `${styleText2("cyan", S_BAR)} ` : "", g2 = e ? styleText2("cyan", S_BAR_END) : "";
|
|
3080
|
+
return `${o2}${r2}${this.value ? `${styleText2("green", S_RADIO_ACTIVE)} ${a2}` : `${styleText2("dim", S_RADIO_INACTIVE)} ${styleText2("dim", a2)}`}${i.vertical ? e ? `
|
|
3081
|
+
${styleText2("cyan", S_BAR)} ` : `
|
|
3082
|
+
` : ` ${styleText2("dim", "/")} `}${this.value ? `${styleText2("dim", S_RADIO_INACTIVE)} ${styleText2("dim", s)}` : `${styleText2("green", S_RADIO_ACTIVE)} ${s}`}
|
|
3083
|
+
${g2}
|
|
3084
|
+
`;
|
|
3085
|
+
}
|
|
3086
|
+
}
|
|
3087
|
+
}
|
|
3088
|
+
}).prompt();
|
|
3089
|
+
};
|
|
3090
|
+
var MULTISELECT_INSTRUCTIONS = [
|
|
3091
|
+
`${styleText2("dim", "\u2191/\u2193")} to navigate`,
|
|
3092
|
+
`${styleText2("dim", "Space:")} select`,
|
|
3093
|
+
`${styleText2("dim", "Enter:")} confirm`
|
|
3094
|
+
];
|
|
3095
|
+
var log = {
|
|
3096
|
+
message: (s = [], {
|
|
3097
|
+
symbol: e = styleText2("gray", S_BAR),
|
|
3098
|
+
secondarySymbol: r2 = styleText2("gray", S_BAR),
|
|
3099
|
+
output: m2 = process.stdout,
|
|
3100
|
+
spacing: l2 = 1,
|
|
3101
|
+
withGuide: c2
|
|
3102
|
+
} = {}) => {
|
|
3103
|
+
const t2 = [], o2 = c2 ?? settings.withGuide, f2 = o2 ? r2 : "", O = o2 ? `${e} ` : "", u3 = o2 ? `${r2} ` : "";
|
|
3104
|
+
for (let i = 0;i < l2; i++)
|
|
3105
|
+
t2.push(f2);
|
|
3106
|
+
const g2 = Array.isArray(s) ? s : s.split(`
|
|
3107
|
+
`);
|
|
3108
|
+
if (g2.length > 0) {
|
|
3109
|
+
const [i, ...y] = g2;
|
|
3110
|
+
i.length > 0 ? t2.push(`${O}${i}`) : t2.push(o2 ? e : "");
|
|
3111
|
+
for (const p2 of y)
|
|
3112
|
+
p2.length > 0 ? t2.push(`${u3}${p2}`) : t2.push(o2 ? r2 : "");
|
|
3113
|
+
}
|
|
3114
|
+
m2.write(`${t2.join(`
|
|
3115
|
+
`)}
|
|
3116
|
+
`);
|
|
3117
|
+
},
|
|
3118
|
+
info: (s, e) => {
|
|
3119
|
+
log.message(s, { ...e, symbol: styleText2("blue", S_INFO) });
|
|
3120
|
+
},
|
|
3121
|
+
success: (s, e) => {
|
|
3122
|
+
log.message(s, { ...e, symbol: styleText2("green", S_SUCCESS) });
|
|
3123
|
+
},
|
|
3124
|
+
step: (s, e) => {
|
|
3125
|
+
log.message(s, { ...e, symbol: styleText2("green", S_STEP_SUBMIT) });
|
|
3126
|
+
},
|
|
3127
|
+
warn: (s, e) => {
|
|
3128
|
+
log.message(s, { ...e, symbol: styleText2("yellow", S_WARN) });
|
|
3129
|
+
},
|
|
3130
|
+
warning: (s, e) => {
|
|
3131
|
+
log.warn(s, e);
|
|
3132
|
+
},
|
|
3133
|
+
error: (s, e) => {
|
|
3134
|
+
log.message(s, { ...e, symbol: styleText2("red", S_ERROR) });
|
|
3135
|
+
}
|
|
3136
|
+
};
|
|
3137
|
+
var intro = (o2 = "", t2) => {
|
|
3138
|
+
const i = t2?.output ?? process.stdout, e = t2?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR_START)} ` : "";
|
|
3139
|
+
i.write(`${e}${o2}
|
|
3140
|
+
`);
|
|
3141
|
+
};
|
|
3142
|
+
var outro = (o2 = "", t2) => {
|
|
3143
|
+
const i = t2?.output ?? process.stdout, e = t2?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR)}
|
|
3144
|
+
${styleText2("gray", S_BAR_END)} ` : "";
|
|
3145
|
+
i.write(`${e}${o2}
|
|
3146
|
+
|
|
3147
|
+
`);
|
|
3148
|
+
};
|
|
3149
|
+
var W$1 = (o2) => o2;
|
|
3150
|
+
var C2 = (o2, e, s) => {
|
|
3151
|
+
const a2 = {
|
|
3152
|
+
hard: true,
|
|
3153
|
+
trim: false
|
|
3154
|
+
}, i = wrapAnsi(o2, e, a2).split(`
|
|
3155
|
+
`), c2 = i.reduce((n2, t2) => Math.max(dist_default2(t2), n2), 0), u3 = i.map(s).reduce((n2, t2) => Math.max(dist_default2(t2), n2), 0), g2 = e - (u3 - c2);
|
|
3156
|
+
return wrapAnsi(o2, g2, a2);
|
|
3157
|
+
};
|
|
3158
|
+
var note = (o2 = "", e = "", s) => {
|
|
3159
|
+
const a2 = s?.output ?? process$1.stdout, i = s?.withGuide ?? settings.withGuide, c2 = s?.format ?? W$1, g2 = ["", ...C2(o2, getColumns(a2) - 6, c2).split(`
|
|
3160
|
+
`).map(c2), ""], n2 = dist_default2(e), t2 = Math.max(g2.reduce((m2, F) => {
|
|
3161
|
+
const O = dist_default2(F);
|
|
3162
|
+
return O > m2 ? O : m2;
|
|
3163
|
+
}, 0), n2) + 2, h2 = g2.map((m2) => `${styleText2("gray", S_BAR)} ${m2}${" ".repeat(t2 - dist_default2(m2))}${styleText2("gray", S_BAR)}`).join(`
|
|
3164
|
+
`), T3 = i ? `${styleText2("gray", S_BAR)}
|
|
3165
|
+
` : "", l$1 = i ? S_CONNECT_LEFT : S_CORNER_BOTTOM_LEFT;
|
|
3166
|
+
a2.write(`${T3}${styleText2("green", S_STEP_SUBMIT)} ${styleText2("reset", e)} ${styleText2("gray", S_BAR_H.repeat(Math.max(t2 - n2 - 1, 1)) + S_CORNER_TOP_RIGHT)}
|
|
3167
|
+
${h2}
|
|
3168
|
+
${styleText2("gray", l$1 + S_BAR_H.repeat(t2 + 2) + S_CORNER_BOTTOM_RIGHT)}
|
|
3169
|
+
`);
|
|
3170
|
+
};
|
|
3171
|
+
var W = (l2) => styleText2("magenta", l2);
|
|
3172
|
+
var spinner = ({
|
|
3173
|
+
indicator: l2 = "dots",
|
|
3174
|
+
onCancel: h2,
|
|
3175
|
+
output: n2 = process.stdout,
|
|
3176
|
+
cancelMessage: G,
|
|
3177
|
+
errorMessage: O,
|
|
3178
|
+
frames: E = unicode ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"],
|
|
3179
|
+
delay: F = unicode ? 80 : 120,
|
|
3180
|
+
signal: m2,
|
|
3181
|
+
...I
|
|
3182
|
+
} = {}) => {
|
|
3183
|
+
const u3 = isCI();
|
|
3184
|
+
let M2, T3, d = false, S = false, s = "", p2, w = performance.now();
|
|
3185
|
+
const x = getColumns(n2), k = I?.styleFrame ?? W, g2 = (e) => {
|
|
3186
|
+
const r2 = e > 1 ? O ?? settings.messages.error : G ?? settings.messages.cancel;
|
|
3187
|
+
S = e === 1, d && (a2(r2, e), S && typeof h2 == "function" && h2());
|
|
3188
|
+
}, f2 = () => g2(2), i = () => g2(1), A = () => {
|
|
3189
|
+
process.on("uncaughtExceptionMonitor", f2), process.on("unhandledRejection", f2), process.on("SIGINT", i), process.on("SIGTERM", i), process.on("exit", g2), m2 && m2.addEventListener("abort", i);
|
|
3190
|
+
}, H = () => {
|
|
3191
|
+
process.removeListener("uncaughtExceptionMonitor", f2), process.removeListener("unhandledRejection", f2), process.removeListener("SIGINT", i), process.removeListener("SIGTERM", i), process.removeListener("exit", g2), m2 && m2.removeEventListener("abort", i);
|
|
3192
|
+
}, y = () => {
|
|
3193
|
+
if (p2 === undefined)
|
|
3194
|
+
return;
|
|
3195
|
+
u3 && n2.write(`
|
|
3196
|
+
`);
|
|
3197
|
+
const r2 = wrapAnsi(p2, x, {
|
|
3198
|
+
hard: true,
|
|
3199
|
+
trim: false
|
|
3200
|
+
}).split(`
|
|
3201
|
+
`);
|
|
3202
|
+
r2.length > 1 && n2.write(import_sisteransi2.cursor.up(r2.length - 1)), n2.write(import_sisteransi2.cursor.to(0)), n2.write(import_sisteransi2.erase.down());
|
|
3203
|
+
}, C3 = (e) => e.replace(/\.+$/, ""), _2 = (e) => {
|
|
3204
|
+
const r2 = (performance.now() - e) / 1000, t2 = Math.floor(r2 / 60), o2 = Math.floor(r2 % 60);
|
|
3205
|
+
return t2 > 0 ? `[${t2}m ${o2}s]` : `[${o2}s]`;
|
|
3206
|
+
}, N = I.withGuide ?? settings.withGuide, P2 = (e = "") => {
|
|
3207
|
+
d = true, M2 = block({ output: n2 }), s = C3(e), w = performance.now(), N && n2.write(`${styleText2("gray", S_BAR)}
|
|
3208
|
+
`);
|
|
3209
|
+
let r2 = 0, t2 = 0;
|
|
3210
|
+
A(), T3 = setInterval(() => {
|
|
3211
|
+
if (u3 && s === p2)
|
|
3212
|
+
return;
|
|
3213
|
+
y(), p2 = s;
|
|
3214
|
+
const o2 = k(E[r2]);
|
|
3215
|
+
let v;
|
|
3216
|
+
if (u3)
|
|
3217
|
+
v = `${o2} ${s}...`;
|
|
3218
|
+
else if (l2 === "timer")
|
|
3219
|
+
v = `${o2} ${s} ${_2(w)}`;
|
|
3220
|
+
else {
|
|
3221
|
+
const B = ".".repeat(Math.floor(t2)).slice(0, 3);
|
|
3222
|
+
v = `${o2} ${s}${B}`;
|
|
3223
|
+
}
|
|
3224
|
+
const j = wrapAnsi(v, x, {
|
|
3225
|
+
hard: true,
|
|
3226
|
+
trim: false
|
|
3227
|
+
});
|
|
3228
|
+
n2.write(j), r2 = r2 + 1 < E.length ? r2 + 1 : 0, t2 = t2 < 4 ? t2 + 0.125 : 0;
|
|
3229
|
+
}, F);
|
|
3230
|
+
}, a2 = (e = "", r2 = 0, t2 = false) => {
|
|
3231
|
+
if (!d)
|
|
3232
|
+
return;
|
|
3233
|
+
d = false, clearInterval(T3), y();
|
|
3234
|
+
const o2 = r2 === 0 ? styleText2("green", S_STEP_SUBMIT) : r2 === 1 ? styleText2("red", S_STEP_CANCEL) : styleText2("red", S_STEP_ERROR);
|
|
3235
|
+
s = e ?? s, t2 || (l2 === "timer" ? n2.write(`${o2} ${s} ${_2(w)}
|
|
3236
|
+
`) : n2.write(`${o2} ${s}
|
|
3237
|
+
`)), H(), M2();
|
|
3238
|
+
};
|
|
3239
|
+
return {
|
|
3240
|
+
start: P2,
|
|
3241
|
+
stop: (e = "") => a2(e, 0),
|
|
3242
|
+
message: (e = "") => {
|
|
3243
|
+
s = C3(e ?? s);
|
|
3244
|
+
},
|
|
3245
|
+
cancel: (e = "") => a2(e, 1),
|
|
3246
|
+
error: (e = "") => a2(e, 2),
|
|
3247
|
+
clear: () => a2("", 0, true),
|
|
3248
|
+
get isCancelled() {
|
|
3249
|
+
return S;
|
|
3250
|
+
}
|
|
3251
|
+
};
|
|
3252
|
+
};
|
|
3253
|
+
var u3 = {
|
|
3254
|
+
light: unicodeOr("\u2500", "-"),
|
|
3255
|
+
heavy: unicodeOr("\u2501", "="),
|
|
3256
|
+
block: unicodeOr("\u2588", "#")
|
|
3257
|
+
};
|
|
3258
|
+
var SELECT_INSTRUCTIONS = [
|
|
3259
|
+
`${styleText2("dim", "\u2191/\u2193")} to navigate`,
|
|
3260
|
+
`${styleText2("dim", "Enter:")} confirm`
|
|
3261
|
+
];
|
|
3262
|
+
var i = `${styleText2("gray", S_BAR)} `;
|
|
3263
|
+
|
|
1576
3264
|
// src/commands/push.ts
|
|
3265
|
+
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
1577
3266
|
async function runPush(config, opts = {}) {
|
|
1578
|
-
|
|
3267
|
+
intro(import_picocolors.default.bgCyan(import_picocolors.default.black(" @bungres/kit push ")));
|
|
3268
|
+
const s = spinner();
|
|
3269
|
+
s.start("Loading schemas...");
|
|
1579
3270
|
const schemas = await loadSchemas(config.schema);
|
|
1580
3271
|
if (schemas.length === 0) {
|
|
1581
|
-
|
|
3272
|
+
s.stop("No schemas found.");
|
|
3273
|
+
log.warn(import_picocolors.default.yellow("No table definitions found. Check your schema glob pattern."));
|
|
3274
|
+
outro("Failed.");
|
|
1582
3275
|
return;
|
|
1583
3276
|
}
|
|
3277
|
+
s.stop(`Loaded ${schemas.length} schemas.`);
|
|
1584
3278
|
const sql2 = new Bun.SQL(config.dbUrl);
|
|
3279
|
+
const ms = spinner();
|
|
3280
|
+
ms.start("Computing diff from database...");
|
|
1585
3281
|
try {
|
|
1586
3282
|
await sql2.unsafe(`CREATE SCHEMA IF NOT EXISTS "${config.migrationsSchema}";`);
|
|
1587
3283
|
const qualifiedPush = `"${config.migrationsSchema}"."__bungres_push"`;
|
|
@@ -1596,79 +3292,96 @@ async function runPush(config, opts = {}) {
|
|
|
1596
3292
|
if (rows.length > 0) {
|
|
1597
3293
|
prevSnapshot = typeof rows[0].snapshot === "string" ? JSON.parse(rows[0].snapshot) : rows[0].snapshot;
|
|
1598
3294
|
}
|
|
1599
|
-
const currentSnapshot = Object.fromEntries(schemas.map((
|
|
3295
|
+
const currentSnapshot = Object.fromEntries(schemas.map((schemaEntry) => [schemaEntry.config.name, schemaEntry.config]));
|
|
1600
3296
|
const diff = diffSchemas(prevSnapshot, currentSnapshot);
|
|
1601
3297
|
if (diff.statements.length === 0) {
|
|
1602
|
-
|
|
1603
|
-
No schema changes detected. Database is up to date
|
|
3298
|
+
ms.stop("Up to date.");
|
|
3299
|
+
log.success(import_picocolors.default.green("No schema changes detected. Database is up to date."));
|
|
3300
|
+
outro("Done.");
|
|
1604
3301
|
return;
|
|
1605
3302
|
}
|
|
1606
|
-
|
|
1607
|
-
Changes to apply
|
|
1608
|
-
for (const
|
|
1609
|
-
|
|
3303
|
+
ms.stop(`Computed ${diff.statements.length} statements.`);
|
|
3304
|
+
log.message(import_picocolors.default.bold("Changes to apply:"));
|
|
3305
|
+
for (const change of diff.summary) {
|
|
3306
|
+
if (change.startsWith("CREATE") || change.startsWith("ALTER TABLE") && change.includes("ADD")) {
|
|
3307
|
+
log.success(import_picocolors.default.green(` + ${change}`));
|
|
3308
|
+
} else if (change.startsWith("DROP") || change.startsWith("ALTER TABLE") && change.includes("DROP")) {
|
|
3309
|
+
log.error(import_picocolors.default.red(` - ${change}`));
|
|
3310
|
+
} else {
|
|
3311
|
+
log.info(import_picocolors.default.blue(` ~ ${change}`));
|
|
3312
|
+
}
|
|
3313
|
+
}
|
|
1610
3314
|
if (diff.warnings && diff.warnings.length > 0) {
|
|
1611
|
-
|
|
1612
|
-
\u26A0\uFE0F WARNING: Data Loss Detected!`);
|
|
3315
|
+
log.warn(import_picocolors.default.bgRed(import_picocolors.default.white(" \u26A0\uFE0F DATA LOSS DETECTED ")));
|
|
1613
3316
|
for (const w of diff.warnings)
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
These changes will be immediately executed against the database!`);
|
|
3317
|
+
log.warn(import_picocolors.default.red(` ! ${w}`));
|
|
3318
|
+
log.warn(import_picocolors.default.yellow("These changes will be immediately executed against the database!"));
|
|
1617
3319
|
}
|
|
1618
3320
|
if (!opts.force) {
|
|
1619
|
-
|
|
1620
|
-
Are you sure you want to push these changes?
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
3321
|
+
const confirm2 = await confirm({
|
|
3322
|
+
message: "Are you sure you want to push these changes?",
|
|
3323
|
+
initialValue: true
|
|
3324
|
+
});
|
|
3325
|
+
if (isCancel(confirm2) || !confirm2) {
|
|
3326
|
+
outro(import_picocolors.default.gray("Push aborted."));
|
|
1624
3327
|
return;
|
|
1625
3328
|
}
|
|
1626
3329
|
}
|
|
1627
|
-
|
|
1628
|
-
Pushing changes
|
|
3330
|
+
const exSpinner = spinner();
|
|
3331
|
+
exSpinner.start("Pushing changes...");
|
|
1629
3332
|
for (const stmt of diff.statements) {
|
|
1630
3333
|
if (config.verbose) {
|
|
1631
|
-
|
|
3334
|
+
log.info(import_picocolors.default.gray(`-- ${stmt}`));
|
|
1632
3335
|
}
|
|
1633
3336
|
await sql2.unsafe(stmt);
|
|
1634
3337
|
}
|
|
1635
3338
|
await sql2.unsafe(`INSERT INTO ${qualifiedPush} (snapshot) VALUES ($1);`, [JSON.stringify(currentSnapshot)]);
|
|
1636
|
-
|
|
1637
|
-
Push complete
|
|
3339
|
+
exSpinner.stop(import_picocolors.default.green("Changes applied successfully."));
|
|
3340
|
+
outro(import_picocolors.default.cyan("\u2728 Push complete."));
|
|
3341
|
+
} catch (err) {
|
|
3342
|
+
log.error(import_picocolors.default.red(`Push failed: ${err.message}`));
|
|
3343
|
+
outro("Failed.");
|
|
1638
3344
|
} finally {
|
|
1639
3345
|
await sql2.end();
|
|
1640
3346
|
}
|
|
1641
3347
|
}
|
|
1642
|
-
async function readLine() {
|
|
1643
|
-
const buf = Buffer.alloc(256);
|
|
1644
|
-
const n = fs.readSync(0, buf, 0, 256, null);
|
|
1645
|
-
return buf.subarray(0, n).toString().trim();
|
|
1646
|
-
}
|
|
1647
3348
|
// src/commands/generate.ts
|
|
1648
3349
|
import { join as join3, resolve as resolve3 } from "path";
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
function colorize(text, color) {
|
|
1652
|
-
const code = Bun.color(color, "ansi");
|
|
1653
|
-
return code ? `${code}${text}\x1B[0m` : text;
|
|
1654
|
-
}
|
|
1655
|
-
|
|
1656
|
-
// src/commands/generate.ts
|
|
1657
|
-
var SNAPSHOT_FILE = ".snapshot.json";
|
|
3350
|
+
import { readdirSync } from "fs";
|
|
3351
|
+
var import_picocolors2 = __toESM(require_picocolors(), 1);
|
|
1658
3352
|
async function runGenerate(config, name) {
|
|
1659
|
-
|
|
3353
|
+
intro(import_picocolors2.default.bgCyan(import_picocolors2.default.black(" @bungres/kit generate ")));
|
|
3354
|
+
const s = spinner();
|
|
3355
|
+
s.start("Loading schemas...");
|
|
1660
3356
|
const schemas = await loadSchemas(config.schema);
|
|
1661
3357
|
if (schemas.length === 0) {
|
|
1662
|
-
|
|
3358
|
+
s.stop("No table definitions found.");
|
|
3359
|
+
log.warn(import_picocolors2.default.yellow("Check your schema glob pattern."));
|
|
3360
|
+
outro("Failed.");
|
|
1663
3361
|
return;
|
|
1664
3362
|
}
|
|
3363
|
+
s.stop(`Loaded ${schemas.length} schemas.`);
|
|
1665
3364
|
const migrationsDir = resolve3(config.out);
|
|
3365
|
+
const metaDir = join3(migrationsDir, "meta");
|
|
1666
3366
|
await Bun.$`mkdir -p ${migrationsDir}`.quiet();
|
|
1667
|
-
|
|
1668
|
-
const
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
3367
|
+
await Bun.$`mkdir -p ${metaDir}`.quiet();
|
|
3368
|
+
const currentSnapshot = Object.fromEntries(schemas.map((s2) => [s2.config.name, s2.config]));
|
|
3369
|
+
let prevSnapshot = {};
|
|
3370
|
+
let isFirstMigration = true;
|
|
3371
|
+
try {
|
|
3372
|
+
const files = readdirSync(metaDir).filter((f2) => f2.endsWith("_snapshot.json")).sort();
|
|
3373
|
+
if (files.length > 0) {
|
|
3374
|
+
const latest = files[files.length - 1];
|
|
3375
|
+
prevSnapshot = JSON.parse(await Bun.file(join3(metaDir, latest)).text());
|
|
3376
|
+
isFirstMigration = false;
|
|
3377
|
+
} else {
|
|
3378
|
+
const legacyFile2 = Bun.file(join3(migrationsDir, ".snapshot.json"));
|
|
3379
|
+
if (await legacyFile2.exists()) {
|
|
3380
|
+
prevSnapshot = JSON.parse(await legacyFile2.text());
|
|
3381
|
+
isFirstMigration = false;
|
|
3382
|
+
}
|
|
3383
|
+
}
|
|
3384
|
+
} catch (e) {}
|
|
1672
3385
|
const now = new Date;
|
|
1673
3386
|
const yyyy = now.getUTCFullYear();
|
|
1674
3387
|
const mm = String(now.getUTCMonth() + 1).padStart(2, "0");
|
|
@@ -1679,60 +3392,86 @@ async function runGenerate(config, name) {
|
|
|
1679
3392
|
const prefix = `${yyyy}_${mm}_${dd}_${HH}${MM}${SS}`;
|
|
1680
3393
|
const filename = name ? `${prefix}_${name}.sql` : `${prefix}.sql`;
|
|
1681
3394
|
const outPath = join3(migrationsDir, filename);
|
|
1682
|
-
let
|
|
3395
|
+
let upStatements;
|
|
3396
|
+
let downStatements;
|
|
1683
3397
|
let summary;
|
|
1684
3398
|
let warnings = [];
|
|
1685
3399
|
if (isFirstMigration) {
|
|
1686
3400
|
const sorted = topoSort(schemas);
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
3401
|
+
upStatements = sorted.flatMap((entry) => [
|
|
3402
|
+
`-- ${entry.exportName}`,
|
|
3403
|
+
generateCreateTable(entry.config, true),
|
|
3404
|
+
``
|
|
3405
|
+
]);
|
|
3406
|
+
downStatements = [...sorted].reverse().flatMap((entry) => {
|
|
3407
|
+
const tbl = entry.config.schema ? `"${entry.config.schema}"."${entry.config.name}"` : `"${entry.config.name}"`;
|
|
3408
|
+
return [`DROP TABLE IF EXISTS ${tbl};`];
|
|
3409
|
+
});
|
|
3410
|
+
summary = sorted.map((s2) => `CREATE TABLE ${s2.config.name}`);
|
|
1695
3411
|
} else {
|
|
1696
|
-
const
|
|
1697
|
-
if (
|
|
1698
|
-
|
|
1699
|
-
|
|
3412
|
+
const upDiff = diffSchemas(prevSnapshot, currentSnapshot);
|
|
3413
|
+
if (upDiff.statements.length === 0) {
|
|
3414
|
+
log.warn(import_picocolors2.default.yellow("No schema changes detected. Nothing to generate."));
|
|
3415
|
+
outro("Done.");
|
|
1700
3416
|
return;
|
|
1701
3417
|
}
|
|
1702
|
-
|
|
1703
|
-
summary =
|
|
1704
|
-
warnings =
|
|
3418
|
+
upStatements = upDiff.statements;
|
|
3419
|
+
summary = upDiff.summary;
|
|
3420
|
+
warnings = upDiff.warnings;
|
|
3421
|
+
const downDiff = diffSchemas(currentSnapshot, prevSnapshot);
|
|
3422
|
+
downStatements = downDiff.statements;
|
|
3423
|
+
}
|
|
3424
|
+
log.message(import_picocolors2.default.bold("Schema changes detected:"));
|
|
3425
|
+
for (const s2 of summary) {
|
|
3426
|
+
if (s2.startsWith("CREATE") || s2.startsWith("ALTER TABLE") && s2.includes("ADD")) {
|
|
3427
|
+
log.success(import_picocolors2.default.green(` + ${s2}`));
|
|
3428
|
+
} else if (s2.startsWith("DROP") || s2.startsWith("ALTER TABLE") && s2.includes("DROP")) {
|
|
3429
|
+
log.error(import_picocolors2.default.red(` - ${s2}`));
|
|
3430
|
+
} else {
|
|
3431
|
+
log.info(import_picocolors2.default.blue(` ~ ${s2}`));
|
|
3432
|
+
}
|
|
3433
|
+
}
|
|
3434
|
+
if (warnings.length > 0) {
|
|
3435
|
+
log.warn(import_picocolors2.default.bgRed(import_picocolors2.default.white(" \u26A0\uFE0F DATA LOSS DETECTED ")));
|
|
3436
|
+
for (const w of warnings)
|
|
3437
|
+
log.warn(import_picocolors2.default.red(` ! ${w}`));
|
|
3438
|
+
}
|
|
3439
|
+
const shouldGenerate = await confirm({
|
|
3440
|
+
message: "Generate this migration?",
|
|
3441
|
+
initialValue: true
|
|
3442
|
+
});
|
|
3443
|
+
if (isCancel(shouldGenerate) || !shouldGenerate) {
|
|
3444
|
+
outro(import_picocolors2.default.gray("Generation cancelled."));
|
|
3445
|
+
return;
|
|
1705
3446
|
}
|
|
3447
|
+
s.start("Writing files...");
|
|
1706
3448
|
const lines = [
|
|
1707
3449
|
`-- Migration: ${filename}`,
|
|
1708
3450
|
`-- Generated by @bungres/kit at ${new Date().toISOString()}`,
|
|
1709
3451
|
`-- Changes: ${summary.join(", ")}`,
|
|
1710
3452
|
``,
|
|
1711
|
-
|
|
3453
|
+
`-- ==== UP ====`,
|
|
3454
|
+
...upStatements,
|
|
3455
|
+
``,
|
|
3456
|
+
`-- ==== DOWN ====`,
|
|
3457
|
+
...downStatements,
|
|
3458
|
+
``
|
|
1712
3459
|
];
|
|
1713
3460
|
await Bun.write(outPath, lines.join(`
|
|
1714
3461
|
`));
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
\u26A0\uFE0F WARNING: Data Loss Detected!`, "red"));
|
|
1724
|
-
for (const w of warnings)
|
|
1725
|
-
console.warn(colorize(` ! ${w}`, "red"));
|
|
1726
|
-
console.warn(colorize(` Please review the generated migration carefully before applying it.
|
|
1727
|
-
`, "yellow"));
|
|
1728
|
-
}
|
|
1729
|
-
console.log(colorize(`
|
|
1730
|
-
Run \`bungres migrate\` to apply it.`, "cyan"));
|
|
3462
|
+
const metaPath = join3(metaDir, `${prefix}_snapshot.json`);
|
|
3463
|
+
await Bun.write(metaPath, JSON.stringify(currentSnapshot, null, 2));
|
|
3464
|
+
const legacyFile = Bun.file(join3(migrationsDir, ".snapshot.json"));
|
|
3465
|
+
if (await legacyFile.exists()) {
|
|
3466
|
+
await Bun.$`rm ${legacyFile.name}`.quiet();
|
|
3467
|
+
}
|
|
3468
|
+
s.stop(`Generated ${import_picocolors2.default.cyan(filename)}`);
|
|
3469
|
+
outro(`Run ${import_picocolors2.default.green("bungres migrate")} to apply it.`);
|
|
1731
3470
|
}
|
|
1732
3471
|
function topoSort(schemas) {
|
|
1733
3472
|
const byName = new Map(schemas.map((s) => [s.config.name, s]));
|
|
1734
3473
|
function deps(config) {
|
|
1735
|
-
return Object.values(config.columns).map((col2) => col2.references?.table).filter((
|
|
3474
|
+
return Object.values(config.columns).map((col2) => col2.references?.table).filter((t2) => t2 !== undefined && byName.has(t2) && t2 !== config.name);
|
|
1736
3475
|
}
|
|
1737
3476
|
const visited = new Set;
|
|
1738
3477
|
const result = [];
|
|
@@ -1753,7 +3492,9 @@ function topoSort(schemas) {
|
|
|
1753
3492
|
}
|
|
1754
3493
|
// src/commands/migrate.ts
|
|
1755
3494
|
import { join as join4, resolve as resolve4 } from "path";
|
|
3495
|
+
var import_picocolors3 = __toESM(require_picocolors(), 1);
|
|
1756
3496
|
async function runMigrate(config) {
|
|
3497
|
+
intro(import_picocolors3.default.bgCyan(import_picocolors3.default.black(" @bungres/kit migrate ")));
|
|
1757
3498
|
const migrationsDir = resolve4(config.out);
|
|
1758
3499
|
const sql2 = new Bun.SQL(config.dbUrl);
|
|
1759
3500
|
const table2 = config.migrationsTable;
|
|
@@ -1766,6 +3507,8 @@ CREATE TABLE IF NOT EXISTS ${qualifiedTable} (
|
|
|
1766
3507
|
name TEXT NOT NULL UNIQUE,
|
|
1767
3508
|
applied_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
1768
3509
|
);`.trim();
|
|
3510
|
+
const s = spinner();
|
|
3511
|
+
s.start("Checking pending migrations...");
|
|
1769
3512
|
try {
|
|
1770
3513
|
await sql2.unsafe(createSchema);
|
|
1771
3514
|
await sql2.unsafe(createMigrationsTable);
|
|
@@ -1776,38 +3519,49 @@ CREATE TABLE IF NOT EXISTS ${qualifiedTable} (
|
|
|
1776
3519
|
}
|
|
1777
3520
|
files.sort();
|
|
1778
3521
|
if (files.length === 0) {
|
|
1779
|
-
|
|
1780
|
-
|
|
3522
|
+
s.stop("No files found.");
|
|
3523
|
+
log.warn(import_picocolors3.default.yellow(`No migration files found in ${migrationsDir}`));
|
|
3524
|
+
log.info(`Run ${import_picocolors3.default.green("bungres generate")} first.`);
|
|
3525
|
+
outro("Done.");
|
|
1781
3526
|
return;
|
|
1782
3527
|
}
|
|
1783
3528
|
const applied = await sql2.unsafe(`SELECT name FROM ${qualifiedTable}`);
|
|
1784
|
-
const appliedSet = new Set(applied.map((
|
|
1785
|
-
const pending = files.filter((
|
|
3529
|
+
const appliedSet = new Set(applied.map((r2) => r2.name));
|
|
3530
|
+
const pending = files.filter((f2) => !appliedSet.has(f2));
|
|
1786
3531
|
if (pending.length === 0) {
|
|
1787
|
-
|
|
3532
|
+
s.stop("Up to date.");
|
|
3533
|
+
log.success(import_picocolors3.default.green("Everything is up to date."));
|
|
3534
|
+
outro("Done.");
|
|
1788
3535
|
return;
|
|
1789
3536
|
}
|
|
1790
|
-
|
|
1791
|
-
Running ${pending.length} pending migration(s)...
|
|
1792
|
-
`, "cyan"));
|
|
3537
|
+
s.stop(`Found ${pending.length} pending migration(s).`);
|
|
1793
3538
|
for (const file of pending) {
|
|
3539
|
+
const ms = spinner();
|
|
3540
|
+
ms.start(`Applying ${file}...`);
|
|
1794
3541
|
const content = await Bun.file(join4(migrationsDir, file)).text();
|
|
3542
|
+
let upContent = content;
|
|
3543
|
+
const upMatch = content.match(/-- ==== UP ====([\s\S]*?)(?:-- ==== DOWN ====|$)/i);
|
|
3544
|
+
if (upMatch) {
|
|
3545
|
+
upContent = upMatch[1].trim();
|
|
3546
|
+
}
|
|
1795
3547
|
if (config.verbose) {
|
|
1796
|
-
|
|
1797
|
-
${
|
|
1798
|
-
`);
|
|
3548
|
+
log.info(import_picocolors3.default.gray(`-- ${file} --
|
|
3549
|
+
${upContent}
|
|
3550
|
+
`));
|
|
1799
3551
|
}
|
|
1800
3552
|
await sql2.transaction(async (txSql) => {
|
|
1801
|
-
const statements = config.breakpoints ?
|
|
3553
|
+
const statements = config.breakpoints ? upContent.split(/-->statement-breakpoint/g).flatMap((chunk) => chunk.split(";").map((s2) => s2.trim()).filter(Boolean)) : upContent.split(";").map((s2) => s2.trim()).filter(Boolean);
|
|
1802
3554
|
for (const stmt of statements) {
|
|
1803
3555
|
await txSql.unsafe(stmt + ";");
|
|
1804
3556
|
}
|
|
1805
3557
|
await txSql.unsafe(`INSERT INTO ${qualifiedTable} (name) VALUES ($1)`, [file]);
|
|
1806
3558
|
});
|
|
1807
|
-
|
|
3559
|
+
ms.stop(import_picocolors3.default.green(`\u2713 Applied ${file}`));
|
|
1808
3560
|
}
|
|
1809
|
-
|
|
1810
|
-
|
|
3561
|
+
outro(import_picocolors3.default.cyan("\u2728 All migrations applied successfully."));
|
|
3562
|
+
} catch (err) {
|
|
3563
|
+
log.error(import_picocolors3.default.red(`Migration failed: ${err.message}`));
|
|
3564
|
+
outro("Failed.");
|
|
1811
3565
|
} finally {
|
|
1812
3566
|
await sql2.end();
|
|
1813
3567
|
}
|
|
@@ -1815,7 +3569,7 @@ Done.`, "green"));
|
|
|
1815
3569
|
// src/commands/pull.ts
|
|
1816
3570
|
import { resolve as resolve5, join as join5 } from "path";
|
|
1817
3571
|
async function introspectDb(sql2, dbSchema) {
|
|
1818
|
-
const
|
|
3572
|
+
const columns = await sql2.unsafe(`SELECT
|
|
1819
3573
|
c.table_name,
|
|
1820
3574
|
c.column_name,
|
|
1821
3575
|
c.data_type,
|
|
@@ -1849,7 +3603,7 @@ async function introspectDb(sql2, dbSchema) {
|
|
|
1849
3603
|
const indexes = await sql2.unsafe(`SELECT tablename, indexname, indexdef
|
|
1850
3604
|
FROM pg_indexes
|
|
1851
3605
|
WHERE schemaname = $1`, [dbSchema]);
|
|
1852
|
-
return groupByTable(
|
|
3606
|
+
return groupByTable(columns, constraints, indexes);
|
|
1853
3607
|
}
|
|
1854
3608
|
async function runPull(config) {
|
|
1855
3609
|
console.log("@bungres/kit pull: introspecting database...");
|
|
@@ -1872,20 +3626,20 @@ async function runPull(config) {
|
|
|
1872
3626
|
await sql2.end();
|
|
1873
3627
|
}
|
|
1874
3628
|
}
|
|
1875
|
-
function groupByTable(
|
|
3629
|
+
function groupByTable(columns, constraints, indexes) {
|
|
1876
3630
|
const map = new Map;
|
|
1877
|
-
for (const col2 of
|
|
3631
|
+
for (const col2 of columns) {
|
|
1878
3632
|
if (!map.has(col2.table_name)) {
|
|
1879
3633
|
map.set(col2.table_name, {
|
|
1880
3634
|
tableName: col2.table_name,
|
|
1881
3635
|
columns: [],
|
|
1882
|
-
indexes: indexes.filter((
|
|
3636
|
+
indexes: indexes.filter((i2) => i2.tablename === col2.table_name)
|
|
1883
3637
|
});
|
|
1884
3638
|
}
|
|
1885
|
-
const tableConstraints = constraints.filter((
|
|
1886
|
-
const pkConstraint = tableConstraints.find((
|
|
1887
|
-
const uniqueConstraint = tableConstraints.find((
|
|
1888
|
-
const fkConstraint = tableConstraints.find((
|
|
3639
|
+
const tableConstraints = constraints.filter((c2) => c2.table_name === col2.table_name && c2.column_name === col2.column_name);
|
|
3640
|
+
const pkConstraint = tableConstraints.find((c2) => c2.constraint_type === "PRIMARY KEY");
|
|
3641
|
+
const uniqueConstraint = tableConstraints.find((c2) => c2.constraint_type === "UNIQUE");
|
|
3642
|
+
const fkConstraint = tableConstraints.find((c2) => c2.constraint_type === "FOREIGN KEY");
|
|
1889
3643
|
map.get(col2.table_name).columns.push({
|
|
1890
3644
|
name: col2.column_name,
|
|
1891
3645
|
dataType: col2.data_type,
|
|
@@ -1934,19 +3688,19 @@ function generateSchemaTS(tableMap, dbSchema) {
|
|
|
1934
3688
|
if (table2.indexes.length > 0) {
|
|
1935
3689
|
const idxLines = [];
|
|
1936
3690
|
for (const idx of table2.indexes) {
|
|
1937
|
-
const
|
|
1938
|
-
if (
|
|
1939
|
-
const isUnique = !!
|
|
1940
|
-
const name =
|
|
3691
|
+
const m2 = idx.indexdef.match(/CREATE (UNIQUE )?INDEX (.+) ON (.+) USING (\w+) \((.+)\)(?: WHERE (.+))?/i);
|
|
3692
|
+
if (m2) {
|
|
3693
|
+
const isUnique = !!m2[1];
|
|
3694
|
+
const name = m2[2].trim().replace(/^"|"$/g, "");
|
|
1941
3695
|
if (name.endsWith("_pkey") || name.endsWith("_key"))
|
|
1942
3696
|
continue;
|
|
1943
|
-
const using =
|
|
1944
|
-
const cols =
|
|
3697
|
+
const using = m2[4].toLowerCase();
|
|
3698
|
+
const cols = m2[5].split(",").map((c2) => `"${c2.trim().replace(/^"|"$/g, "")}"`);
|
|
1945
3699
|
let idxStr = `{ name: "${name}", columns: [${cols.join(", ")}], using: "${using}"`;
|
|
1946
3700
|
if (isUnique)
|
|
1947
3701
|
idxStr += `, unique: true`;
|
|
1948
|
-
if (
|
|
1949
|
-
idxStr += `, where: \`${
|
|
3702
|
+
if (m2[6])
|
|
3703
|
+
idxStr += `, where: \`${m2[6].trim()}\``;
|
|
1950
3704
|
idxStr += ` }`;
|
|
1951
3705
|
idxLines.push(idxStr);
|
|
1952
3706
|
}
|
|
@@ -2065,16 +3819,20 @@ function pgTypeToBungresBuilderName(col2) {
|
|
|
2065
3819
|
return "text";
|
|
2066
3820
|
}
|
|
2067
3821
|
function toCamelCase(str) {
|
|
2068
|
-
return str.replace(/_([a-z])/g, (
|
|
3822
|
+
return str.replace(/_([a-z])/g, (_2, c2) => c2.toUpperCase());
|
|
2069
3823
|
}
|
|
2070
3824
|
// src/commands/status.ts
|
|
2071
3825
|
import { resolve as resolve6 } from "path";
|
|
3826
|
+
var import_picocolors4 = __toESM(require_picocolors(), 1);
|
|
2072
3827
|
async function runStatus(config) {
|
|
3828
|
+
intro(import_picocolors4.default.bgCyan(import_picocolors4.default.black(" @bungres/kit status ")));
|
|
2073
3829
|
const migrationsDir = resolve6(config.out);
|
|
2074
3830
|
const sql2 = new Bun.SQL(config.dbUrl);
|
|
2075
3831
|
const table2 = config.migrationsTable;
|
|
2076
3832
|
const schema = config.migrationsSchema;
|
|
2077
3833
|
const qualifiedTable = `"${schema}"."${table2}"`;
|
|
3834
|
+
const s = spinner();
|
|
3835
|
+
s.start("Checking migration status...");
|
|
2078
3836
|
try {
|
|
2079
3837
|
const tableCheck = await sql2.unsafe(`SELECT EXISTS (
|
|
2080
3838
|
SELECT 1 FROM information_schema.tables
|
|
@@ -2088,44 +3846,59 @@ async function runStatus(config) {
|
|
|
2088
3846
|
}
|
|
2089
3847
|
files.sort();
|
|
2090
3848
|
if (files.length === 0) {
|
|
2091
|
-
|
|
3849
|
+
s.stop("No files found.");
|
|
3850
|
+
log.warn(import_picocolors4.default.yellow("No migration files found."));
|
|
3851
|
+
log.info(`Run ${import_picocolors4.default.green("bungres generate")} first.`);
|
|
3852
|
+
outro("Done.");
|
|
2092
3853
|
return;
|
|
2093
3854
|
}
|
|
2094
3855
|
let appliedSet = new Set;
|
|
2095
3856
|
if (trackingExists) {
|
|
2096
3857
|
const applied = await sql2.unsafe(`SELECT name FROM ${qualifiedTable} ORDER BY applied_at`);
|
|
2097
|
-
appliedSet = new Set(applied.map((
|
|
3858
|
+
appliedSet = new Set(applied.map((r2) => r2.name));
|
|
2098
3859
|
}
|
|
2099
|
-
|
|
2100
|
-
Migration status:
|
|
2101
|
-
`, "cyan"));
|
|
3860
|
+
s.stop("Status check complete.");
|
|
3861
|
+
log.message(import_picocolors4.default.bold("Migration status:"));
|
|
2102
3862
|
let pendingCount = 0;
|
|
2103
3863
|
for (const file of files) {
|
|
2104
3864
|
const isApplied = appliedSet.has(file);
|
|
2105
|
-
|
|
2106
|
-
|
|
3865
|
+
if (isApplied) {
|
|
3866
|
+
log.success(`${import_picocolors4.default.green("\u2713 applied ")} ${file}`);
|
|
3867
|
+
} else {
|
|
2107
3868
|
pendingCount++;
|
|
2108
|
-
|
|
3869
|
+
log.warn(`${import_picocolors4.default.yellow("\u2717 pending ")} ${file}`);
|
|
3870
|
+
}
|
|
2109
3871
|
}
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
3872
|
+
log.info(`${import_picocolors4.default.green(appliedSet.size.toString())} applied, ${import_picocolors4.default.yellow(pendingCount.toString())} pending.`);
|
|
3873
|
+
outro("Done.");
|
|
3874
|
+
} catch (err) {
|
|
3875
|
+
log.error(import_picocolors4.default.red(`Status check failed: ${err.message}`));
|
|
3876
|
+
outro("Failed.");
|
|
2113
3877
|
} finally {
|
|
2114
3878
|
await sql2.end();
|
|
2115
3879
|
}
|
|
2116
3880
|
}
|
|
2117
3881
|
// src/commands/drop.ts
|
|
3882
|
+
var import_picocolors5 = __toESM(require_picocolors(), 1);
|
|
2118
3883
|
async function runDrop(config, opts = {}) {
|
|
3884
|
+
intro(import_picocolors5.default.bgCyan(import_picocolors5.default.black(" @bungres/kit drop ")));
|
|
3885
|
+
const s = spinner();
|
|
3886
|
+
s.start("Loading schemas...");
|
|
2119
3887
|
const schemas = await loadSchemas(config.schema);
|
|
2120
3888
|
if (schemas.length === 0) {
|
|
2121
|
-
|
|
3889
|
+
s.stop("No schemas found.");
|
|
3890
|
+
log.warn(import_picocolors5.default.yellow("No table definitions found in schema files."));
|
|
3891
|
+
outro("Failed.");
|
|
2122
3892
|
return;
|
|
2123
3893
|
}
|
|
3894
|
+
s.stop(`Loaded ${schemas.length} schemas.`);
|
|
3895
|
+
const ms = spinner();
|
|
3896
|
+
ms.start("Checking database tables...");
|
|
2124
3897
|
const sql2 = new Bun.SQL(config.dbUrl);
|
|
2125
3898
|
try {
|
|
2126
3899
|
const userSchema = config.dbSchema;
|
|
2127
3900
|
const existingUserTablesResult = await sql2.unsafe(`SELECT table_name FROM information_schema.tables WHERE table_schema = $1`, [userSchema]);
|
|
2128
|
-
const existingTableNames = new Set(existingUserTablesResult.map((
|
|
3901
|
+
const existingTableNames = new Set(existingUserTablesResult.map((r2) => r2.table_name));
|
|
2129
3902
|
const migTableCheck = await sql2.unsafe(`SELECT EXISTS (
|
|
2130
3903
|
SELECT 1 FROM information_schema.tables
|
|
2131
3904
|
WHERE table_schema = $1 AND table_name = $2
|
|
@@ -2136,12 +3909,15 @@ async function runDrop(config, opts = {}) {
|
|
|
2136
3909
|
WHERE table_schema = $1 AND table_name = $2
|
|
2137
3910
|
) AS exists`, [config.migrationsSchema, "__bungres_push"]);
|
|
2138
3911
|
const pushTableExists = pushTableCheck[0]?.exists ?? false;
|
|
2139
|
-
const tablesToDrop = schemas.filter((
|
|
3912
|
+
const tablesToDrop = schemas.filter((sch) => existingTableNames.has(sch.config.name));
|
|
2140
3913
|
if (tablesToDrop.length === 0 && !migrationTableExists && !pushTableExists) {
|
|
2141
|
-
|
|
3914
|
+
ms.stop("Nothing to do.");
|
|
3915
|
+
log.success(import_picocolors5.default.green("No tables to drop (they either don't exist or were already dropped)."));
|
|
3916
|
+
outro("Done.");
|
|
2142
3917
|
return;
|
|
2143
3918
|
}
|
|
2144
|
-
|
|
3919
|
+
ms.stop("Database check complete.");
|
|
3920
|
+
const tableNamesToPrint = tablesToDrop.map((sch) => (sch.config.schema ? sch.config.schema + "." : "") + sch.config.name);
|
|
2145
3921
|
if (migrationTableExists) {
|
|
2146
3922
|
tableNamesToPrint.push(`${config.migrationsSchema}.${config.migrationsTable}`);
|
|
2147
3923
|
}
|
|
@@ -2149,37 +3925,41 @@ async function runDrop(config, opts = {}) {
|
|
|
2149
3925
|
tableNamesToPrint.push(`${config.migrationsSchema}.__bungres_push`);
|
|
2150
3926
|
}
|
|
2151
3927
|
if (!opts.force) {
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
Are you sure
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
break;
|
|
3928
|
+
log.warn(import_picocolors5.default.bgRed(import_picocolors5.default.white(" \u26A0\uFE0F WARNING ")));
|
|
3929
|
+
log.message(import_picocolors5.default.bold(import_picocolors5.default.red("This will drop the following tables and ALL their data:")));
|
|
3930
|
+
for (const name of tableNamesToPrint) {
|
|
3931
|
+
log.info(import_picocolors5.default.yellow(` - ${name}`));
|
|
3932
|
+
}
|
|
3933
|
+
const confirm2 = await confirm({
|
|
3934
|
+
message: "Are you sure you want to proceed?",
|
|
3935
|
+
initialValue: false
|
|
3936
|
+
});
|
|
3937
|
+
if (isCancel(confirm2) || !confirm2) {
|
|
3938
|
+
outro(import_picocolors5.default.gray("Drop aborted."));
|
|
3939
|
+
return;
|
|
2165
3940
|
}
|
|
2166
3941
|
}
|
|
3942
|
+
const exSpinner = spinner();
|
|
3943
|
+
exSpinner.start("Dropping tables...");
|
|
2167
3944
|
for (const entry of tablesToDrop) {
|
|
2168
3945
|
const ddl = `DROP TABLE IF EXISTS "${entry.config.name}" CASCADE;`;
|
|
2169
3946
|
await sql2.unsafe(ddl);
|
|
2170
|
-
|
|
3947
|
+
log.step(import_picocolors5.default.gray(`Dropped ${entry.config.name}`));
|
|
2171
3948
|
}
|
|
2172
3949
|
if (migrationTableExists) {
|
|
2173
3950
|
const qualifiedMigTable = `"${config.migrationsSchema}"."${config.migrationsTable}"`;
|
|
2174
3951
|
await sql2.unsafe(`DROP TABLE IF EXISTS ${qualifiedMigTable} CASCADE`);
|
|
2175
|
-
|
|
3952
|
+
log.step(import_picocolors5.default.gray(`Dropped ${config.migrationsSchema}.${config.migrationsTable}`));
|
|
2176
3953
|
}
|
|
2177
3954
|
if (pushTableExists) {
|
|
2178
3955
|
await sql2.unsafe(`DROP TABLE IF EXISTS "${config.migrationsSchema}"."__bungres_push" CASCADE`);
|
|
2179
|
-
|
|
3956
|
+
log.step(import_picocolors5.default.gray(`Dropped ${config.migrationsSchema}.__bungres_push`));
|
|
2180
3957
|
}
|
|
2181
|
-
|
|
2182
|
-
Drop complete
|
|
3958
|
+
exSpinner.stop("Tables dropped.");
|
|
3959
|
+
outro(import_picocolors5.default.cyan("\u2728 Drop complete."));
|
|
3960
|
+
} catch (err) {
|
|
3961
|
+
log.error(import_picocolors5.default.red(`Drop failed: ${err.message}`));
|
|
3962
|
+
outro("Failed.");
|
|
2183
3963
|
} finally {
|
|
2184
3964
|
await sql2.end();
|
|
2185
3965
|
}
|