@bungres/kit 0.6.1 → 0.7.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/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: (count2 = 1) => `${CSI2}${count2}A`,
59
+ down: (count2 = 1) => `${CSI2}${count2}B`,
60
+ forward: (count2 = 1) => `${CSI2}${count2}C`,
61
+ backward: (count2 = 1) => `${CSI2}${count2}D`,
62
+ nextLine: (count2 = 1) => `${CSI2}E`.repeat(count2),
63
+ prevLine: (count2 = 1) => `${CSI2}F`.repeat(count2),
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: (count2 = 1) => `${CSI2}S`.repeat(count2),
72
+ down: (count2 = 1) => `${CSI2}T`.repeat(count2)
73
+ };
74
+ var erase = {
75
+ screen: `${CSI2}2J`,
76
+ up: (count2 = 1) => `${CSI2}1J`.repeat(count2),
77
+ down: (count2 = 1) => `${CSI2}J`.repeat(count2),
78
+ line: `${CSI2}2K`,
79
+ lineEnd: `${CSI2}K`,
80
+ lineStart: `${CSI2}1K`,
81
+ lines(count2) {
82
+ let clear = "";
83
+ for (let i = 0;i < count2; i++)
84
+ clear += this.line + (i < count2 - 1 ? cursor.up() : "");
85
+ if (count2)
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, index2 = string.indexOf(close, open.length);
101
+ return ~index2 ? open + replaceClose(string, close, replace, index2) + close : open + string + close;
102
+ };
103
+ var replaceClose = (string, close, replace, index2) => {
104
+ let result = "", cursor3 = 0;
105
+ do {
106
+ result += string.substring(cursor3, index2) + replace;
107
+ cursor3 = index2 + close.length;
108
+ index2 = string.indexOf(close, cursor3);
109
+ } while (~index2);
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 = [
@@ -1397,9 +1558,6 @@ async function loadSchemas(patterns, cwd = process.cwd()) {
1397
1558
  function isTable(value) {
1398
1559
  return typeof value === "object" && value !== null && TableConfigSymbol in value;
1399
1560
  }
1400
- // src/commands/push.ts
1401
- import * as fs from "fs";
1402
-
1403
1561
  // src/differ.ts
1404
1562
  function diffSchemas(prev, next) {
1405
1563
  const statements = [];
@@ -1573,15 +1731,1382 @@ function formatDefault(value, dataType) {
1573
1731
  return `'${JSON.stringify(value)}'`;
1574
1732
  }
1575
1733
 
1734
+ // ../../node_modules/.bun/@clack+core@1.4.3/node_modules/@clack/core/dist/index.mjs
1735
+ import { styleText } from "util";
1736
+ import { stdout, stdin } from "process";
1737
+ import * as l from "readline";
1738
+ import l__default from "readline";
1739
+
1740
+ // ../../node_modules/.bun/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/utils.js
1741
+ var getCodePointsLength = (() => {
1742
+ const SURROGATE_PAIR_RE = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
1743
+ return (input) => {
1744
+ let surrogatePairsNr = 0;
1745
+ SURROGATE_PAIR_RE.lastIndex = 0;
1746
+ while (SURROGATE_PAIR_RE.test(input)) {
1747
+ surrogatePairsNr += 1;
1748
+ }
1749
+ return input.length - surrogatePairsNr;
1750
+ };
1751
+ })();
1752
+ var isFullWidth = (x) => {
1753
+ return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
1754
+ };
1755
+ var isWideNotCJKTNotEmoji = (x) => {
1756
+ 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;
1757
+ };
1758
+
1759
+ // ../../node_modules/.bun/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/index.js
1760
+ var ANSI_RE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y;
1761
+ var CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
1762
+ 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;
1763
+ var TAB_RE = /\t{1,1000}/y;
1764
+ 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;
1765
+ var LATIN_RE = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
1766
+ var MODIFIER_RE = /\p{M}+/gu;
1767
+ var NO_TRUNCATION = { limit: Infinity, ellipsis: "" };
1768
+ var getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {}) => {
1769
+ const LIMIT = truncationOptions.limit ?? Infinity;
1770
+ const ELLIPSIS = truncationOptions.ellipsis ?? "";
1771
+ const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth(ELLIPSIS, NO_TRUNCATION, widthOptions).width : 0);
1772
+ const ANSI_WIDTH = 0;
1773
+ const CONTROL_WIDTH = widthOptions.controlWidth ?? 0;
1774
+ const TAB_WIDTH = widthOptions.tabWidth ?? 8;
1775
+ const EMOJI_WIDTH = widthOptions.emojiWidth ?? 2;
1776
+ const FULL_WIDTH_WIDTH = 2;
1777
+ const REGULAR_WIDTH = widthOptions.regularWidth ?? 1;
1778
+ const WIDE_WIDTH = widthOptions.wideWidth ?? FULL_WIDTH_WIDTH;
1779
+ const PARSE_BLOCKS = [
1780
+ [LATIN_RE, REGULAR_WIDTH],
1781
+ [ANSI_RE, ANSI_WIDTH],
1782
+ [CONTROL_RE, CONTROL_WIDTH],
1783
+ [TAB_RE, TAB_WIDTH],
1784
+ [EMOJI_RE, EMOJI_WIDTH],
1785
+ [CJKT_WIDE_RE, WIDE_WIDTH]
1786
+ ];
1787
+ let indexPrev = 0;
1788
+ let index2 = 0;
1789
+ let length = input.length;
1790
+ let lengthExtra = 0;
1791
+ let truncationEnabled = false;
1792
+ let truncationIndex = length;
1793
+ let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH);
1794
+ let unmatchedStart = 0;
1795
+ let unmatchedEnd = 0;
1796
+ let width = 0;
1797
+ let widthExtra = 0;
1798
+ outer:
1799
+ while (true) {
1800
+ if (unmatchedEnd > unmatchedStart || index2 >= length && index2 > indexPrev) {
1801
+ const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index2);
1802
+ lengthExtra = 0;
1803
+ for (const char of unmatched.replaceAll(MODIFIER_RE, "")) {
1804
+ const codePoint = char.codePointAt(0) || 0;
1805
+ if (isFullWidth(codePoint)) {
1806
+ widthExtra = FULL_WIDTH_WIDTH;
1807
+ } else if (isWideNotCJKTNotEmoji(codePoint)) {
1808
+ widthExtra = WIDE_WIDTH;
1809
+ } else {
1810
+ widthExtra = REGULAR_WIDTH;
1811
+ }
1812
+ if (width + widthExtra > truncationLimit) {
1813
+ truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
1814
+ }
1815
+ if (width + widthExtra > LIMIT) {
1816
+ truncationEnabled = true;
1817
+ break outer;
1818
+ }
1819
+ lengthExtra += char.length;
1820
+ width += widthExtra;
1821
+ }
1822
+ unmatchedStart = unmatchedEnd = 0;
1823
+ }
1824
+ if (index2 >= length) {
1825
+ break outer;
1826
+ }
1827
+ for (let i = 0, l = PARSE_BLOCKS.length;i < l; i++) {
1828
+ const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[i];
1829
+ BLOCK_RE.lastIndex = index2;
1830
+ if (BLOCK_RE.test(input)) {
1831
+ lengthExtra = BLOCK_RE === CJKT_WIDE_RE ? getCodePointsLength(input.slice(index2, BLOCK_RE.lastIndex)) : BLOCK_RE === EMOJI_RE ? 1 : BLOCK_RE.lastIndex - index2;
1832
+ widthExtra = lengthExtra * BLOCK_WIDTH;
1833
+ if (width + widthExtra > truncationLimit) {
1834
+ truncationIndex = Math.min(truncationIndex, index2 + Math.floor((truncationLimit - width) / BLOCK_WIDTH));
1835
+ }
1836
+ if (width + widthExtra > LIMIT) {
1837
+ truncationEnabled = true;
1838
+ break outer;
1839
+ }
1840
+ width += widthExtra;
1841
+ unmatchedStart = indexPrev;
1842
+ unmatchedEnd = index2;
1843
+ index2 = indexPrev = BLOCK_RE.lastIndex;
1844
+ continue outer;
1845
+ }
1846
+ }
1847
+ index2 += 1;
1848
+ }
1849
+ return {
1850
+ width: truncationEnabled ? truncationLimit : width,
1851
+ index: truncationEnabled ? truncationIndex : length,
1852
+ truncated: truncationEnabled,
1853
+ ellipsed: truncationEnabled && LIMIT >= ELLIPSIS_WIDTH
1854
+ };
1855
+ };
1856
+ var dist_default = getStringTruncatedWidth;
1857
+
1858
+ // ../../node_modules/.bun/fast-string-width@3.0.2/node_modules/fast-string-width/dist/index.js
1859
+ var NO_TRUNCATION2 = {
1860
+ limit: Infinity,
1861
+ ellipsis: "",
1862
+ ellipsisWidth: 0
1863
+ };
1864
+ var fastStringWidth = (input, options = {}) => {
1865
+ return dist_default(input, NO_TRUNCATION2, options).width;
1866
+ };
1867
+ var dist_default2 = fastStringWidth;
1868
+
1869
+ // ../../node_modules/.bun/fast-wrap-ansi@0.2.2/node_modules/fast-wrap-ansi/lib/main.js
1870
+ var ESC = "\x1B";
1871
+ var CSI = "\x9B";
1872
+ var END_CODE = 39;
1873
+ var ANSI_ESCAPE_BELL = "\x07";
1874
+ var ANSI_CSI = "[";
1875
+ var ANSI_OSC = "]";
1876
+ var ANSI_SGR_TERMINATOR = "m";
1877
+ var ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
1878
+ var GROUP_REGEX = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`, "y");
1879
+ var getClosingCode = (openingCode) => {
1880
+ if (openingCode >= 30 && openingCode <= 37)
1881
+ return 39;
1882
+ if (openingCode >= 90 && openingCode <= 97)
1883
+ return 39;
1884
+ if (openingCode >= 40 && openingCode <= 47)
1885
+ return 49;
1886
+ if (openingCode >= 100 && openingCode <= 107)
1887
+ return 49;
1888
+ if (openingCode === 1 || openingCode === 2)
1889
+ return 22;
1890
+ if (openingCode === 3)
1891
+ return 23;
1892
+ if (openingCode === 4)
1893
+ return 24;
1894
+ if (openingCode === 7)
1895
+ return 27;
1896
+ if (openingCode === 8)
1897
+ return 28;
1898
+ if (openingCode === 9)
1899
+ return 29;
1900
+ if (openingCode === 0)
1901
+ return 0;
1902
+ return;
1903
+ };
1904
+ var wrapAnsiCode = (code) => `${ESC}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
1905
+ var wrapAnsiHyperlink = (url) => `${ESC}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
1906
+ var wrapWord = (rows, word, columns2) => {
1907
+ const characters = word[Symbol.iterator]();
1908
+ let isInsideEscape = false;
1909
+ let isInsideLinkEscape = false;
1910
+ let lastRow = rows.at(-1);
1911
+ let visible = lastRow === undefined ? 0 : dist_default2(lastRow);
1912
+ let currentCharacter = characters.next();
1913
+ let nextCharacter = characters.next();
1914
+ let rawCharacterIndex = 0;
1915
+ while (!currentCharacter.done) {
1916
+ const character = currentCharacter.value;
1917
+ const characterLength = dist_default2(character);
1918
+ if (visible + characterLength <= columns2) {
1919
+ rows[rows.length - 1] += character;
1920
+ } else {
1921
+ rows.push(character);
1922
+ visible = 0;
1923
+ }
1924
+ if (character === ESC || character === CSI) {
1925
+ isInsideEscape = true;
1926
+ isInsideLinkEscape = word.startsWith(ANSI_ESCAPE_LINK, rawCharacterIndex + 1);
1927
+ }
1928
+ if (isInsideEscape) {
1929
+ if (isInsideLinkEscape) {
1930
+ if (character === ANSI_ESCAPE_BELL) {
1931
+ isInsideEscape = false;
1932
+ isInsideLinkEscape = false;
1933
+ }
1934
+ } else if (character === ANSI_SGR_TERMINATOR) {
1935
+ isInsideEscape = false;
1936
+ }
1937
+ } else {
1938
+ visible += characterLength;
1939
+ if (visible === columns2 && !nextCharacter.done) {
1940
+ rows.push("");
1941
+ visible = 0;
1942
+ }
1943
+ }
1944
+ currentCharacter = nextCharacter;
1945
+ nextCharacter = characters.next();
1946
+ rawCharacterIndex += character.length;
1947
+ }
1948
+ lastRow = rows.at(-1);
1949
+ if (!visible && lastRow !== undefined && lastRow.length && rows.length > 1) {
1950
+ rows[rows.length - 2] += rows.pop();
1951
+ }
1952
+ };
1953
+ var stringVisibleTrimSpacesRight = (string) => {
1954
+ const words = string.split(" ");
1955
+ let last = words.length;
1956
+ while (last) {
1957
+ if (dist_default2(words[last - 1])) {
1958
+ break;
1959
+ }
1960
+ last--;
1961
+ }
1962
+ if (last === words.length) {
1963
+ return string;
1964
+ }
1965
+ return words.slice(0, last).join(" ") + words.slice(last).join("");
1966
+ };
1967
+ var exec = (string, columns2, options = {}) => {
1968
+ if (options.trim !== false && string.trim() === "") {
1969
+ return "";
1970
+ }
1971
+ let returnValue = "";
1972
+ let escapeCode;
1973
+ let escapeUrl;
1974
+ const words = string.split(" ");
1975
+ let rows = [""];
1976
+ let rowLength = 0;
1977
+ for (let index2 = 0;index2 < words.length; index2++) {
1978
+ const word = words[index2];
1979
+ if (options.trim !== false) {
1980
+ const row = rows.at(-1) ?? "";
1981
+ const trimmed = row.trimStart();
1982
+ if (row.length !== trimmed.length) {
1983
+ rows[rows.length - 1] = trimmed;
1984
+ rowLength = dist_default2(trimmed);
1985
+ }
1986
+ }
1987
+ if (index2 !== 0) {
1988
+ if (rowLength >= columns2 && (options.wordWrap === false || options.trim === false)) {
1989
+ rows.push("");
1990
+ rowLength = 0;
1991
+ }
1992
+ if (rowLength || options.trim === false) {
1993
+ rows[rows.length - 1] += " ";
1994
+ rowLength++;
1995
+ }
1996
+ }
1997
+ const wordLength = dist_default2(word);
1998
+ if (options.hard && wordLength > columns2) {
1999
+ const remainingColumns = columns2 - rowLength;
2000
+ const breaksStartingThisLine = 1 + Math.floor((wordLength - remainingColumns - 1) / columns2);
2001
+ const breaksStartingNextLine = Math.floor((wordLength - 1) / columns2);
2002
+ if (breaksStartingNextLine < breaksStartingThisLine) {
2003
+ rows.push("");
2004
+ }
2005
+ wrapWord(rows, word, columns2);
2006
+ rowLength = dist_default2(rows.at(-1) ?? "");
2007
+ continue;
2008
+ }
2009
+ if (rowLength + wordLength > columns2 && rowLength && wordLength) {
2010
+ if (options.wordWrap === false && rowLength < columns2) {
2011
+ wrapWord(rows, word, columns2);
2012
+ rowLength = dist_default2(rows.at(-1) ?? "");
2013
+ continue;
2014
+ }
2015
+ rows.push("");
2016
+ rowLength = 0;
2017
+ }
2018
+ if (rowLength + wordLength > columns2 && options.wordWrap === false) {
2019
+ wrapWord(rows, word, columns2);
2020
+ rowLength = dist_default2(rows.at(-1) ?? "");
2021
+ continue;
2022
+ }
2023
+ rows[rows.length - 1] += word;
2024
+ rowLength += wordLength;
2025
+ }
2026
+ if (options.trim !== false) {
2027
+ rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
2028
+ }
2029
+ const preString = rows.join(`
2030
+ `);
2031
+ let inSurrogate = false;
2032
+ for (let i = 0;i < preString.length; i++) {
2033
+ const character = preString[i];
2034
+ returnValue += character;
2035
+ if (!inSurrogate) {
2036
+ inSurrogate = character >= "\uD800" && character <= "\uDBFF";
2037
+ if (inSurrogate) {
2038
+ continue;
2039
+ }
2040
+ } else {
2041
+ inSurrogate = false;
2042
+ }
2043
+ if (character === ESC || character === CSI) {
2044
+ GROUP_REGEX.lastIndex = i + 1;
2045
+ const groupsResult = GROUP_REGEX.exec(preString);
2046
+ const groups = groupsResult?.groups;
2047
+ if (groups?.code !== undefined) {
2048
+ const code = Number.parseFloat(groups.code);
2049
+ escapeCode = code === END_CODE ? undefined : code;
2050
+ } else if (groups?.uri !== undefined) {
2051
+ escapeUrl = groups.uri.length === 0 ? undefined : groups.uri;
2052
+ }
2053
+ }
2054
+ if (preString[i + 1] === `
2055
+ `) {
2056
+ if (escapeUrl) {
2057
+ returnValue += wrapAnsiHyperlink("");
2058
+ }
2059
+ const closingCode = escapeCode ? getClosingCode(escapeCode) : undefined;
2060
+ if (escapeCode && closingCode) {
2061
+ returnValue += wrapAnsiCode(closingCode);
2062
+ }
2063
+ } else if (character === `
2064
+ `) {
2065
+ if (escapeCode && getClosingCode(escapeCode)) {
2066
+ returnValue += wrapAnsiCode(escapeCode);
2067
+ }
2068
+ if (escapeUrl) {
2069
+ returnValue += wrapAnsiHyperlink(escapeUrl);
2070
+ }
2071
+ }
2072
+ }
2073
+ return returnValue;
2074
+ };
2075
+ var CRLF_OR_LF = /\r?\n/;
2076
+ function wrapAnsi(string, columns2, options) {
2077
+ return String(string).normalize().split(CRLF_OR_LF).map((line) => exec(line, columns2, options)).join(`
2078
+ `);
2079
+ }
2080
+
2081
+ // ../../node_modules/.bun/@clack+core@1.4.3/node_modules/@clack/core/dist/index.mjs
2082
+ var import_sisteransi = __toESM(require_src(), 1);
2083
+ import { ReadStream } from "tty";
2084
+ function findCursor(s, o, l2) {
2085
+ if (!l2.some((r) => !r.disabled))
2086
+ return s;
2087
+ const t = s + o, n = Math.max(l2.length - 1, 0), e = t < 0 ? n : t > n ? 0 : t;
2088
+ return l2[e]?.disabled ? findCursor(e, o < 0 ? -1 : 1, l2) : e;
2089
+ }
2090
+ function findTextCursor(s, o, l2, i) {
2091
+ const t = i.split(`
2092
+ `);
2093
+ let n = 0, e = s;
2094
+ for (const r of t) {
2095
+ if (e <= r.length)
2096
+ break;
2097
+ e -= r.length + 1, n++;
2098
+ }
2099
+ for (n = Math.max(0, Math.min(t.length - 1, n + l2)), e = Math.min(e, t[n].length) + o;e < 0 && n > 0; )
2100
+ n--, e += t[n].length + 1;
2101
+ for (;e > t[n].length && n < t.length - 1; )
2102
+ e -= t[n].length + 1, n++;
2103
+ e = Math.max(0, Math.min(t[n].length, e));
2104
+ let h = 0;
2105
+ for (let r = 0;r < n; r++)
2106
+ h += t[r].length + 1;
2107
+ return h + e;
2108
+ }
2109
+ var a$1 = ["up", "down", "left", "right", "space", "enter", "cancel"];
2110
+ var t = [
2111
+ "January",
2112
+ "February",
2113
+ "March",
2114
+ "April",
2115
+ "May",
2116
+ "June",
2117
+ "July",
2118
+ "August",
2119
+ "September",
2120
+ "October",
2121
+ "November",
2122
+ "December"
2123
+ ];
2124
+ var settings = {
2125
+ actions: new Set(a$1),
2126
+ aliases: /* @__PURE__ */ new Map([
2127
+ ["k", "up"],
2128
+ ["j", "down"],
2129
+ ["h", "left"],
2130
+ ["l", "right"],
2131
+ ["\x03", "cancel"],
2132
+ ["escape", "cancel"]
2133
+ ]),
2134
+ messages: {
2135
+ cancel: "Canceled",
2136
+ error: "Something went wrong"
2137
+ },
2138
+ withGuide: true,
2139
+ date: {
2140
+ monthNames: [...t],
2141
+ messages: {
2142
+ required: "Please enter a valid date",
2143
+ invalidMonth: "There are only 12 months in a year",
2144
+ invalidDay: (n, e) => `There are only ${n} days in ${e}`,
2145
+ afterMin: (n) => `Date must be on or after ${n.toISOString().slice(0, 10)}`,
2146
+ beforeMax: (n) => `Date must be on or before ${n.toISOString().slice(0, 10)}`
2147
+ }
2148
+ }
2149
+ };
2150
+ function isActionKey(n, e) {
2151
+ if (typeof n == "string")
2152
+ return settings.aliases.get(n) === e;
2153
+ for (const s of n)
2154
+ if (s !== undefined && isActionKey(s, e))
2155
+ return true;
2156
+ return false;
2157
+ }
2158
+ function diffLines(i, s) {
2159
+ if (i === s)
2160
+ return;
2161
+ const e = i.split(`
2162
+ `), t2 = s.split(`
2163
+ `), r = Math.max(e.length, t2.length), f = [];
2164
+ for (let n = 0;n < r; n++)
2165
+ e[n] !== t2[n] && f.push(n);
2166
+ return {
2167
+ lines: f,
2168
+ numLinesBefore: e.length,
2169
+ numLinesAfter: t2.length,
2170
+ numLines: r
2171
+ };
2172
+ }
2173
+ var R = globalThis.process.platform.startsWith("win");
2174
+ var CANCEL_SYMBOL = Symbol("clack:cancel");
2175
+ function isCancel(e) {
2176
+ return e === CANCEL_SYMBOL;
2177
+ }
2178
+ function setRawMode(e, r) {
2179
+ const o = e;
2180
+ o.isTTY && o.setRawMode(r);
2181
+ }
2182
+ function block({
2183
+ input: e = stdin,
2184
+ output: r = stdout,
2185
+ overwrite: o = true,
2186
+ hideCursor: t2 = true
2187
+ } = {}) {
2188
+ const s = l.createInterface({
2189
+ input: e,
2190
+ output: r,
2191
+ prompt: "",
2192
+ tabSize: 1
2193
+ });
2194
+ l.emitKeypressEvents(e, s), e instanceof ReadStream && e.isTTY && e.setRawMode(true);
2195
+ const n = (f, { name: a, sequence: p }) => {
2196
+ const c = String(f);
2197
+ if (isActionKey([c, a, p], "cancel")) {
2198
+ t2 && r.write(import_sisteransi.cursor.show), process.exit(0);
2199
+ return;
2200
+ }
2201
+ if (!o)
2202
+ return;
2203
+ const i = a === "return" ? 0 : -1, m = a === "return" ? -1 : 0;
2204
+ l.moveCursor(r, i, m, () => {
2205
+ l.clearLine(r, 1, () => {
2206
+ e.once("keypress", n);
2207
+ });
2208
+ });
2209
+ };
2210
+ return t2 && r.write(import_sisteransi.cursor.hide), e.once("keypress", n), () => {
2211
+ 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();
2212
+ };
2213
+ }
2214
+ var getColumns = (e) => ("columns" in e) && typeof e.columns == "number" ? e.columns : 80;
2215
+ var getRows = (e) => ("rows" in e) && typeof e.rows == "number" ? e.rows : 20;
2216
+ function wrapTextWithPrefix(e, r, o, t2 = o, s = o, n) {
2217
+ const f = getColumns(e ?? stdout);
2218
+ return wrapAnsi(r, f - o.length, {
2219
+ hard: true,
2220
+ trim: false
2221
+ }).split(`
2222
+ `).map((c, i, m) => {
2223
+ const d = n ? n(c, i) : c;
2224
+ return i === 0 ? `${t2}${d}` : i === m.length - 1 ? `${s}${d}` : `${o}${d}`;
2225
+ }).join(`
2226
+ `);
2227
+ }
2228
+ function runValidation(e, n) {
2229
+ if ("~standard" in e) {
2230
+ const a = e["~standard"].validate(n);
2231
+ if (a instanceof Promise)
2232
+ throw new TypeError("Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic.");
2233
+ return a.issues?.at(0)?.message;
2234
+ }
2235
+ return e(n);
2236
+ }
2237
+
2238
+ class V {
2239
+ input;
2240
+ output;
2241
+ _abortSignal;
2242
+ rl;
2243
+ opts;
2244
+ _render;
2245
+ _track = false;
2246
+ _prevFrame = "";
2247
+ _subscribers = /* @__PURE__ */ new Map;
2248
+ _cursor = 0;
2249
+ state = "initial";
2250
+ error = "";
2251
+ value;
2252
+ userInput = "";
2253
+ constructor(t2, e = true) {
2254
+ const { input: i = stdin, output: n = stdout, render: s, signal: r, ...o } = t2;
2255
+ 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;
2256
+ }
2257
+ unsubscribe() {
2258
+ this._subscribers.clear();
2259
+ }
2260
+ setSubscriber(t2, e) {
2261
+ const i = this._subscribers.get(t2) ?? [];
2262
+ i.push(e), this._subscribers.set(t2, i);
2263
+ }
2264
+ on(t2, e) {
2265
+ this.setSubscriber(t2, { cb: e });
2266
+ }
2267
+ once(t2, e) {
2268
+ this.setSubscriber(t2, { cb: e, once: true });
2269
+ }
2270
+ emit(t2, ...e) {
2271
+ const i = this._subscribers.get(t2) ?? [], n = [];
2272
+ for (const s of i)
2273
+ s.cb(...e), s.once && n.push(() => i.splice(i.indexOf(s), 1));
2274
+ for (const s of n)
2275
+ s();
2276
+ }
2277
+ prompt() {
2278
+ return new Promise((t2) => {
2279
+ if (this._abortSignal) {
2280
+ if (this._abortSignal.aborted)
2281
+ return this.state = "cancel", this.close(), t2(CANCEL_SYMBOL);
2282
+ this._abortSignal.addEventListener("abort", () => {
2283
+ this.state = "cancel", this.close();
2284
+ }, { once: true });
2285
+ }
2286
+ this.rl = l__default.createInterface({
2287
+ input: this.input,
2288
+ tabSize: 2,
2289
+ prompt: "",
2290
+ escapeCodeTimeout: 50,
2291
+ terminal: true
2292
+ }), 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", () => {
2293
+ this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t2(this.value);
2294
+ }), this.once("cancel", () => {
2295
+ this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t2(CANCEL_SYMBOL);
2296
+ });
2297
+ });
2298
+ }
2299
+ _isActionKey(t2, e) {
2300
+ return t2 === "\t";
2301
+ }
2302
+ _shouldSubmit(t2, e) {
2303
+ return true;
2304
+ }
2305
+ _setValue(t2) {
2306
+ this.value = t2, this.emit("value", this.value);
2307
+ }
2308
+ _setUserInput(t2, e) {
2309
+ this.userInput = t2 ?? "", this.emit("userInput", this.userInput), e && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
2310
+ }
2311
+ _clearUserInput() {
2312
+ this.rl?.write(null, { ctrl: true, name: "u" }), this._setUserInput("");
2313
+ }
2314
+ onKeypress(t2, e) {
2315
+ 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)) {
2316
+ if (this.opts.validate) {
2317
+ const i = runValidation(this.opts.validate, this.value);
2318
+ i && (this.error = i instanceof Error ? i.message : i, this.state = "error", this.rl?.write(this.userInput));
2319
+ }
2320
+ this.state !== "error" && (this.state = "submit");
2321
+ }
2322
+ 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();
2323
+ }
2324
+ close() {
2325
+ this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
2326
+ `), setRawMode(this.input, false), this.rl?.close(), this.rl = undefined, this.emit(`${this.state}`, this.value), this.unsubscribe();
2327
+ }
2328
+ restoreCursor() {
2329
+ const t2 = wrapAnsi(this._prevFrame, process.stdout.columns, { hard: true, trim: false }).split(`
2330
+ `).length - 1;
2331
+ this.output.write(import_sisteransi.cursor.move(-999, t2 * -1));
2332
+ }
2333
+ render() {
2334
+ const t2 = wrapAnsi(this._render(this) ?? "", process.stdout.columns, {
2335
+ hard: true,
2336
+ trim: false
2337
+ });
2338
+ if (t2 !== this._prevFrame) {
2339
+ if (this.state === "initial")
2340
+ this.output.write(import_sisteransi.cursor.hide);
2341
+ else {
2342
+ const e = diffLines(this._prevFrame, t2), i = getRows(this.output);
2343
+ if (this.restoreCursor(), e) {
2344
+ const n = Math.max(0, e.numLinesAfter - i), s = Math.max(0, e.numLinesBefore - i);
2345
+ let r = e.lines.find((o) => o >= n);
2346
+ if (r === undefined) {
2347
+ this._prevFrame = t2;
2348
+ return;
2349
+ }
2350
+ if (e.lines.length === 1) {
2351
+ this.output.write(import_sisteransi.cursor.move(0, r - s)), this.output.write(import_sisteransi.erase.lines(1));
2352
+ const o = t2.split(`
2353
+ `);
2354
+ this.output.write(o[r]), this._prevFrame = t2, this.output.write(import_sisteransi.cursor.move(0, o.length - r - 1));
2355
+ return;
2356
+ } else if (e.lines.length > 1) {
2357
+ if (n < s)
2358
+ r = n;
2359
+ else {
2360
+ const h = r - s;
2361
+ h > 0 && this.output.write(import_sisteransi.cursor.move(0, h));
2362
+ }
2363
+ this.output.write(import_sisteransi.erase.down());
2364
+ const f = t2.split(`
2365
+ `).slice(r);
2366
+ this.output.write(f.join(`
2367
+ `)), this._prevFrame = t2;
2368
+ return;
2369
+ }
2370
+ }
2371
+ this.output.write(import_sisteransi.erase.down());
2372
+ }
2373
+ this.output.write(t2), this.state === "initial" && (this.state = "active"), this._prevFrame = t2;
2374
+ }
2375
+ }
2376
+ }
2377
+ function p$1(l2, e) {
2378
+ if (l2 === undefined || e.length === 0)
2379
+ return 0;
2380
+ const i = e.findIndex((s) => s.value === l2);
2381
+ return i !== -1 ? i : 0;
2382
+ }
2383
+ function g(l2, e) {
2384
+ return (e.label ?? String(e.value)).toLowerCase().includes(l2.toLowerCase());
2385
+ }
2386
+ function m(l2, e) {
2387
+ if (e)
2388
+ return l2 ? e : e[0];
2389
+ }
2390
+ var T$1 = class T extends V {
2391
+ filteredOptions;
2392
+ multiple;
2393
+ isNavigating = false;
2394
+ selectedValues = [];
2395
+ focusedValue;
2396
+ #e = 0;
2397
+ #s = "";
2398
+ #t;
2399
+ #i;
2400
+ #n;
2401
+ get cursor() {
2402
+ return this.#e;
2403
+ }
2404
+ get userInputWithCursor() {
2405
+ if (!this.userInput)
2406
+ return styleText(["inverse", "hidden"], "_");
2407
+ if (this._cursor >= this.userInput.length)
2408
+ return `${this.userInput}\u2588`;
2409
+ const e = this.userInput.slice(0, this.cursor), t2 = this.userInput.slice(this.cursor, this.cursor + 1), i = this.userInput.slice(this.cursor + 1);
2410
+ return `${e}${styleText("inverse", t2)}${i}`;
2411
+ }
2412
+ get options() {
2413
+ return typeof this.#i == "function" ? this.#i() : this.#i;
2414
+ }
2415
+ constructor(e) {
2416
+ super(e), this.#i = e.options, this.#n = e.placeholder;
2417
+ const t2 = this.options;
2418
+ this.filteredOptions = [...t2], this.multiple = e.multiple === true, this.#t = typeof e.options == "function" ? e.filter : e.filter ?? g;
2419
+ let i;
2420
+ 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)
2421
+ for (const s of i) {
2422
+ const n = t2.findIndex((o) => o.value === s);
2423
+ n !== -1 && (this.toggleSelected(s), this.#e = n);
2424
+ }
2425
+ this.focusedValue = this.options[this.#e]?.value, this.on("key", (s, n) => this.#l(s, n)), this.on("userInput", (s) => this.#u(s));
2426
+ }
2427
+ _isActionKey(e, t2) {
2428
+ return e === "\t" || this.multiple && this.isNavigating && t2.name === "space" && e !== undefined && e !== "";
2429
+ }
2430
+ #l(e, t2) {
2431
+ 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));
2432
+ if (t2.name === "tab" && o && f) {
2433
+ this.userInput === "\t" && this._clearUserInput(), this._setUserInput(u, true), this.isNavigating = false;
2434
+ return;
2435
+ }
2436
+ 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);
2437
+ }
2438
+ deselectAll() {
2439
+ this.selectedValues = [];
2440
+ }
2441
+ toggleSelected(e) {
2442
+ 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]);
2443
+ }
2444
+ #u(e) {
2445
+ if (e !== this.#s) {
2446
+ this.#s = e;
2447
+ const t2 = this.options;
2448
+ e && this.#t ? this.filteredOptions = t2.filter((n) => this.#t?.(e, n)) : this.filteredOptions = [...t2];
2449
+ const i = p$1(this.focusedValue, this.filteredOptions);
2450
+ this.#e = findCursor(i, 0, this.filteredOptions);
2451
+ const s = this.filteredOptions[this.#e];
2452
+ s && !s.disabled ? this.focusedValue = s.value : this.focusedValue = undefined, this.multiple || (this.focusedValue !== undefined ? this.toggleSelected(this.focusedValue) : this.deselectAll());
2453
+ }
2454
+ }
2455
+ };
2456
+
2457
+ class r extends V {
2458
+ get cursor() {
2459
+ return this.value ? 0 : 1;
2460
+ }
2461
+ get _value() {
2462
+ return this.cursor === 0;
2463
+ }
2464
+ constructor(t2) {
2465
+ super(t2, false), this.value = !!t2.initialValue, this.on("userInput", () => {
2466
+ this.value = this._value;
2467
+ }), this.on("confirm", (i) => {
2468
+ this.output.write(import_sisteransi.cursor.move(0, -1)), this.value = i, this.state = "submit", this.close();
2469
+ }), this.on("cursor", () => {
2470
+ this.value = !this.value;
2471
+ });
2472
+ }
2473
+ }
2474
+ var _ = {
2475
+ Y: { type: "year", len: 4 },
2476
+ M: { type: "month", len: 2 },
2477
+ D: { type: "day", len: 2 }
2478
+ };
2479
+ function M(r2) {
2480
+ return [...r2].map((t2) => _[t2]);
2481
+ }
2482
+ function P(r2) {
2483
+ const i = new Intl.DateTimeFormat(r2, {
2484
+ year: "numeric",
2485
+ month: "2-digit",
2486
+ day: "2-digit"
2487
+ }).formatToParts(new Date(2000, 0, 15)), s = [];
2488
+ let n = "/";
2489
+ for (const e of i)
2490
+ 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 });
2491
+ return { segments: s, separator: n };
2492
+ }
2493
+ function p(r2) {
2494
+ return Number.parseInt((r2 || "0").replace(/_/g, "0"), 10) || 0;
2495
+ }
2496
+ function f(r2) {
2497
+ return {
2498
+ year: p(r2.year),
2499
+ month: p(r2.month),
2500
+ day: p(r2.day)
2501
+ };
2502
+ }
2503
+ function c(r2, t2) {
2504
+ return new Date(r2 || 2001, t2 || 1, 0).getDate();
2505
+ }
2506
+ function b(r2) {
2507
+ const { year: t2, month: i, day: s } = f(r2);
2508
+ if (!t2 || t2 < 0 || t2 > 9999 || !i || i < 1 || i > 12 || !s || s < 1)
2509
+ return;
2510
+ const n = new Date(Date.UTC(t2, i - 1, s));
2511
+ if (!(n.getUTCFullYear() !== t2 || n.getUTCMonth() !== i - 1 || n.getUTCDate() !== s))
2512
+ return { year: t2, month: i, day: s };
2513
+ }
2514
+ function C(r2) {
2515
+ const t2 = b(r2);
2516
+ return t2 ? new Date(Date.UTC(t2.year, t2.month - 1, t2.day)) : undefined;
2517
+ }
2518
+ function T2(r2, t2, i, s) {
2519
+ const n = i ? {
2520
+ year: i.getUTCFullYear(),
2521
+ month: i.getUTCMonth() + 1,
2522
+ day: i.getUTCDate()
2523
+ } : null, e = s ? {
2524
+ year: s.getUTCFullYear(),
2525
+ month: s.getUTCMonth() + 1,
2526
+ day: s.getUTCDate()
2527
+ } : null;
2528
+ return r2 === "year" ? { min: n?.year ?? 1, max: e?.year ?? 9999 } : r2 === "month" ? {
2529
+ min: n && t2.year === n.year ? n.month : 1,
2530
+ max: e && t2.year === e.year ? e.month : 12
2531
+ } : {
2532
+ min: n && t2.year === n.year && t2.month === n.month ? n.day : 1,
2533
+ max: e && t2.year === e.year && t2.month === e.month ? e.day : c(t2.year, t2.month)
2534
+ };
2535
+ }
2536
+
2537
+ class U extends V {
2538
+ #i;
2539
+ #o;
2540
+ #t;
2541
+ #h;
2542
+ #u;
2543
+ #e = { segmentIndex: 0, positionInSegment: 0 };
2544
+ #n = true;
2545
+ #s = null;
2546
+ inlineError = "";
2547
+ get segmentCursor() {
2548
+ return { ...this.#e };
2549
+ }
2550
+ get segmentValues() {
2551
+ return { ...this.#t };
2552
+ }
2553
+ get segments() {
2554
+ return this.#i;
2555
+ }
2556
+ get separator() {
2557
+ return this.#o;
2558
+ }
2559
+ get formattedValue() {
2560
+ return this.#l(this.#t);
2561
+ }
2562
+ #l(t2) {
2563
+ return this.#i.map((i) => t2[i.type]).join(this.#o);
2564
+ }
2565
+ #r() {
2566
+ this._setUserInput(this.#l(this.#t)), this._setValue(C(this.#t) ?? undefined);
2567
+ }
2568
+ constructor(t2) {
2569
+ 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 ? {
2570
+ year: String(e.getUTCFullYear()).padStart(4, "0"),
2571
+ month: String(e.getUTCMonth() + 1).padStart(2, "0"),
2572
+ day: String(e.getUTCDate()).padStart(2, "0")
2573
+ } : { year: "____", month: "__", day: "__" }, o = n.map((a) => m2[a.type]).join(s);
2574
+ 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));
2575
+ }
2576
+ #a() {
2577
+ const t2 = Math.max(0, Math.min(this.#e.segmentIndex, this.#i.length - 1)), i = this.#i[t2];
2578
+ if (i)
2579
+ return this.#e.positionInSegment = Math.max(0, Math.min(this.#e.positionInSegment, i.len - 1)), { segment: i, index: t2 };
2580
+ }
2581
+ #m(t2) {
2582
+ this.inlineError = "", this.#s = null;
2583
+ const i = this.#a();
2584
+ i && (this.#e.segmentIndex = Math.max(0, Math.min(this.#i.length - 1, i.index + t2)), this.#e.positionInSegment = 0, this.#n = true);
2585
+ }
2586
+ #d(t2) {
2587
+ const i = this.#a();
2588
+ if (!i)
2589
+ return;
2590
+ 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);
2591
+ let a;
2592
+ e ? a = t2 === 1 ? o.min : o.max : a = Math.max(Math.min(o.max, m2 + t2), o.min), this.#t = {
2593
+ ...this.#t,
2594
+ [s.type]: a.toString().padStart(s.len, "0")
2595
+ }, this.#n = true, this.#s = null, this.#r();
2596
+ }
2597
+ #f(t2) {
2598
+ if (t2)
2599
+ switch (t2) {
2600
+ case "right":
2601
+ return this.#m(1);
2602
+ case "left":
2603
+ return this.#m(-1);
2604
+ case "up":
2605
+ return this.#d(1);
2606
+ case "down":
2607
+ return this.#d(-1);
2608
+ }
2609
+ }
2610
+ #y(t2, i) {
2611
+ if (i?.name === "backspace" || i?.sequence === "\x7F" || i?.sequence === "\b" || t2 === "\x7F" || t2 === "\b") {
2612
+ this.inlineError = "";
2613
+ const n = this.#a();
2614
+ if (!n)
2615
+ return;
2616
+ if (!this.#t[n.segment.type].replace(/_/g, "")) {
2617
+ this.#m(-1);
2618
+ return;
2619
+ }
2620
+ this.#t[n.segment.type] = "_".repeat(n.segment.len), this.#n = true, this.#e.positionInSegment = 0, this.#r();
2621
+ return;
2622
+ }
2623
+ if (i?.name === "tab") {
2624
+ this.inlineError = "";
2625
+ const n = this.#a();
2626
+ if (!n)
2627
+ return;
2628
+ const e = i.shift ? -1 : 1, m2 = n.index + e;
2629
+ m2 >= 0 && m2 < this.#i.length && (this.#e.segmentIndex = m2, this.#e.positionInSegment = 0, this.#n = true);
2630
+ return;
2631
+ }
2632
+ if (t2 && /^[0-9]$/.test(t2)) {
2633
+ const n = this.#a();
2634
+ if (!n)
2635
+ return;
2636
+ const { segment: e } = n, m2 = !this.#t[e.type].replace(/_/g, "");
2637
+ if (this.#n && this.#s !== null && !m2) {
2638
+ const h = this.#s + t2, d = { ...this.#t, [e.type]: h }, g2 = this.#g(d, e);
2639
+ if (g2) {
2640
+ this.inlineError = g2, this.#s = null, this.#n = false;
2641
+ return;
2642
+ }
2643
+ 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);
2644
+ return;
2645
+ }
2646
+ this.#n && !m2 && (this.#t[e.type] = "_".repeat(e.len), this.#e.positionInSegment = 0), this.#n = false, this.#s = null;
2647
+ const o = this.#t[e.type], a = o.indexOf("_"), u = a >= 0 ? a : Math.min(this.#e.positionInSegment, e.len - 1);
2648
+ if (u < 0 || u >= e.len)
2649
+ return;
2650
+ let l2 = o.slice(0, u) + t2 + o.slice(u + 1), D = false;
2651
+ if (u === 0 && o === "__" && (e.type === "month" || e.type === "day")) {
2652
+ const h = Number.parseInt(t2, 10);
2653
+ l2 = `0${t2}`, D = h <= (e.type === "month" ? 1 : 2);
2654
+ }
2655
+ if (e.type === "year" && (l2 = (o.replace(/_/g, "") + t2).padStart(e.len, "_")), !l2.includes("_")) {
2656
+ const h = { ...this.#t, [e.type]: l2 }, d = this.#g(h, e);
2657
+ if (d) {
2658
+ this.inlineError = d;
2659
+ return;
2660
+ }
2661
+ }
2662
+ this.inlineError = "", this.#t[e.type] = l2;
2663
+ const y = l2.includes("_") ? undefined : b(this.#t);
2664
+ if (y) {
2665
+ const { year: h, month: d } = y, g2 = c(h, d);
2666
+ this.#t = {
2667
+ year: String(Math.max(0, Math.min(9999, h))).padStart(4, "0"),
2668
+ month: String(Math.max(1, Math.min(12, d))).padStart(2, "0"),
2669
+ day: String(Math.max(1, Math.min(g2, y.day))).padStart(2, "0")
2670
+ };
2671
+ }
2672
+ this.#r();
2673
+ const S = l2.indexOf("_");
2674
+ 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);
2675
+ }
2676
+ }
2677
+ #g(t2, i) {
2678
+ const { month: s, day: n } = f(t2);
2679
+ if (i.type === "month" && (s < 0 || s > 12))
2680
+ return settings.date.messages.invalidMonth;
2681
+ if (i.type === "day" && (n < 0 || n > 31))
2682
+ return settings.date.messages.invalidDay(31, "any month");
2683
+ }
2684
+ #p(t2) {
2685
+ const { year: i, month: s, day: n } = f(this.#t);
2686
+ if (i && s && n) {
2687
+ const e = c(i, s);
2688
+ this.#t = {
2689
+ ...this.#t,
2690
+ day: String(Math.min(n, e)).padStart(2, "0")
2691
+ };
2692
+ }
2693
+ this.value = C(this.#t) ?? t2.defaultValue ?? undefined;
2694
+ }
2695
+ }
2696
+ var u$2 = class u extends V {
2697
+ options;
2698
+ cursor = 0;
2699
+ #t;
2700
+ getGroupItems(t2) {
2701
+ return this.options.filter((r2) => r2.group === t2);
2702
+ }
2703
+ isGroupSelected(t2) {
2704
+ const r2 = this.getGroupItems(t2), e = this.value;
2705
+ return e === undefined ? false : r2.every((s) => e.includes(s.value));
2706
+ }
2707
+ toggleValue() {
2708
+ const t2 = this.options[this.cursor];
2709
+ if (t2 !== undefined)
2710
+ if (this.value === undefined && (this.value = []), t2.group === true) {
2711
+ const r2 = t2.value, e = this.getGroupItems(r2);
2712
+ 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));
2713
+ } else {
2714
+ const r2 = this.value.includes(t2.value);
2715
+ this.value = r2 ? this.value.filter((e) => e !== t2.value) : [...this.value, t2.value];
2716
+ }
2717
+ }
2718
+ constructor(t2) {
2719
+ super(t2, false);
2720
+ const { options: r2 } = t2;
2721
+ this.#t = t2.selectableGroups !== false, this.options = Object.entries(r2).flatMap(([e, s]) => [
2722
+ { value: e, group: true, label: e },
2723
+ ...s.map((i) => ({ ...i, group: e }))
2724
+ ]), this.value = [...t2.initialValues ?? []], this.cursor = Math.max(this.options.findIndex(({ value: e }) => e === t2.cursorAt), this.#t ? 0 : 1), this.on("cursor", (e) => {
2725
+ switch (e) {
2726
+ case "left":
2727
+ case "up": {
2728
+ this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
2729
+ const s = this.options[this.cursor]?.group === true;
2730
+ !this.#t && s && (this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1);
2731
+ break;
2732
+ }
2733
+ case "down":
2734
+ case "right": {
2735
+ this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
2736
+ const s = this.options[this.cursor]?.group === true;
2737
+ !this.#t && s && (this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1);
2738
+ break;
2739
+ }
2740
+ case "space":
2741
+ this.toggleValue();
2742
+ break;
2743
+ }
2744
+ });
2745
+ }
2746
+ };
2747
+ var o = /* @__PURE__ */ new Set(["up", "down", "left", "right"]);
2748
+
2749
+ class h extends V {
2750
+ #t = false;
2751
+ #s;
2752
+ focused = "editor";
2753
+ get userInputWithCursor() {
2754
+ if (this.state === "submit")
2755
+ return this.userInput;
2756
+ const t2 = this.userInput;
2757
+ if (this.cursor >= t2.length)
2758
+ return `${t2}\u2588`;
2759
+ const s = t2.slice(0, this.cursor), r2 = t2.slice(this.cursor, this.cursor + 1), i = t2.slice(this.cursor + 1);
2760
+ return r2 === `
2761
+ ` ? `${s}\u2588
2762
+ ${i}` : `${s}${styleText("inverse", r2)}${i}`;
2763
+ }
2764
+ get cursor() {
2765
+ return this._cursor;
2766
+ }
2767
+ #r(t2) {
2768
+ if (this.userInput.length === 0) {
2769
+ this._setUserInput(t2);
2770
+ return;
2771
+ }
2772
+ this._setUserInput(this.userInput.slice(0, this.cursor) + t2 + this.userInput.slice(this.cursor));
2773
+ }
2774
+ #i(t2) {
2775
+ const s = this.value ?? "";
2776
+ switch (t2) {
2777
+ case "up":
2778
+ this._cursor = findTextCursor(this._cursor, 0, -1, s);
2779
+ return;
2780
+ case "down":
2781
+ this._cursor = findTextCursor(this._cursor, 0, 1, s);
2782
+ return;
2783
+ case "left":
2784
+ this._cursor = findTextCursor(this._cursor, -1, 0, s);
2785
+ return;
2786
+ case "right":
2787
+ this._cursor = findTextCursor(this._cursor, 1, 0, s);
2788
+ return;
2789
+ }
2790
+ }
2791
+ _shouldSubmit(t2, s) {
2792
+ if (this.#s)
2793
+ return this.focused === "submit" ? true : (this.#r(`
2794
+ `), this._cursor++, false);
2795
+ const r2 = this.#t;
2796
+ return this.#t = true, r2 && this.cursor === this.userInput.length ? (this.userInput[this.cursor - 1] === `
2797
+ ` && (this._setUserInput(this.userInput.slice(0, this.cursor - 1) + this.userInput.slice(this.cursor)), this._cursor--), true) : (this.#r(`
2798
+ `), this._cursor++, false);
2799
+ }
2800
+ constructor(t2) {
2801
+ const s = t2.initialUserInput ?? t2.initialValue;
2802
+ super({
2803
+ ...t2,
2804
+ initialUserInput: s
2805
+ }, false), s !== undefined && (this._cursor = s.length), this.#s = t2.showSubmit ?? false, this.on("key", (r2, i) => {
2806
+ if (i?.name && o.has(i.name)) {
2807
+ this.#t = false, this.#i(i.name);
2808
+ return;
2809
+ }
2810
+ if (r2 === "\t" && this.#s) {
2811
+ this.focused = this.focused === "editor" ? "submit" : "editor";
2812
+ return;
2813
+ }
2814
+ if (i?.name !== "return") {
2815
+ if (this.#t = false, i?.name === "backspace" && this.cursor > 0) {
2816
+ this._setUserInput(this.userInput.slice(0, this.cursor - 1) + this.userInput.slice(this.cursor)), this._cursor--;
2817
+ return;
2818
+ }
2819
+ if (i?.name === "delete" && this.cursor < this.userInput.length) {
2820
+ this._setUserInput(this.userInput.slice(0, this.cursor) + this.userInput.slice(this.cursor + 1));
2821
+ return;
2822
+ }
2823
+ r2 && (this.#s && this.focused === "submit" && (this.focused = "editor"), this.#r(r2 ?? ""), this._cursor++);
2824
+ }
2825
+ }), this.on("userInput", (r2) => {
2826
+ this._setValue(r2);
2827
+ }), this.on("finalize", () => {
2828
+ this.value || (this.value = t2.defaultValue), this.value === undefined && (this.value = "");
2829
+ });
2830
+ }
2831
+ }
2832
+
2833
+ // ../../node_modules/.bun/@clack+prompts@1.7.0/node_modules/@clack/prompts/dist/index.mjs
2834
+ import { styleText as styleText2, stripVTControlCharacters } from "util";
2835
+ import process$1 from "process";
2836
+ var import_sisteransi2 = __toESM(require_src(), 1);
2837
+ function isUnicodeSupported() {
2838
+ if (process$1.platform !== "win32") {
2839
+ return process$1.env.TERM !== "linux";
2840
+ }
2841
+ 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";
2842
+ }
2843
+ var unicode = isUnicodeSupported();
2844
+ var isCI = () => process.env.CI === "true";
2845
+ var unicodeOr = (o2, e) => unicode ? o2 : e;
2846
+ var S_STEP_ACTIVE = unicodeOr("\u25C6", "*");
2847
+ var S_STEP_CANCEL = unicodeOr("\u25A0", "x");
2848
+ var S_STEP_ERROR = unicodeOr("\u25B2", "x");
2849
+ var S_STEP_SUBMIT = unicodeOr("\u25C7", "o");
2850
+ var S_BAR_START = unicodeOr("\u250C", "T");
2851
+ var S_BAR = unicodeOr("\u2502", "|");
2852
+ var S_BAR_END = unicodeOr("\u2514", "\u2014");
2853
+ var S_BAR_START_RIGHT = unicodeOr("\u2510", "T");
2854
+ var S_BAR_END_RIGHT = unicodeOr("\u2518", "\u2014");
2855
+ var S_RADIO_ACTIVE = unicodeOr("\u25CF", ">");
2856
+ var S_RADIO_INACTIVE = unicodeOr("\u25CB", " ");
2857
+ var S_CHECKBOX_ACTIVE = unicodeOr("\u25FB", "[\u2022]");
2858
+ var S_CHECKBOX_SELECTED = unicodeOr("\u25FC", "[+]");
2859
+ var S_CHECKBOX_INACTIVE = unicodeOr("\u25FB", "[ ]");
2860
+ var S_PASSWORD_MASK = unicodeOr("\u25AA", "\u2022");
2861
+ var S_BAR_H = unicodeOr("\u2500", "-");
2862
+ var S_CORNER_TOP_RIGHT = unicodeOr("\u256E", "+");
2863
+ var S_CONNECT_LEFT = unicodeOr("\u251C", "+");
2864
+ var S_CORNER_BOTTOM_RIGHT = unicodeOr("\u256F", "+");
2865
+ var S_CORNER_BOTTOM_LEFT = unicodeOr("\u2570", "+");
2866
+ var S_CORNER_TOP_LEFT = unicodeOr("\u256D", "+");
2867
+ var S_INFO = unicodeOr("\u25CF", "\u2022");
2868
+ var S_SUCCESS = unicodeOr("\u25C6", "*");
2869
+ var S_WARN = unicodeOr("\u25B2", "!");
2870
+ var S_ERROR = unicodeOr("\u25A0", "x");
2871
+ var symbol = (o2) => {
2872
+ switch (o2) {
2873
+ case "initial":
2874
+ case "active":
2875
+ return styleText2("cyan", S_STEP_ACTIVE);
2876
+ case "cancel":
2877
+ return styleText2("red", S_STEP_CANCEL);
2878
+ case "error":
2879
+ return styleText2("yellow", S_STEP_ERROR);
2880
+ case "submit":
2881
+ return styleText2("green", S_STEP_SUBMIT);
2882
+ }
2883
+ };
2884
+ var confirm = (i) => {
2885
+ const a2 = i.active ?? "Yes", s = i.inactive ?? "No";
2886
+ return new r({
2887
+ active: a2,
2888
+ inactive: s,
2889
+ signal: i.signal,
2890
+ input: i.input,
2891
+ output: i.output,
2892
+ initialValue: i.initialValue ?? true,
2893
+ render() {
2894
+ 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)}
2895
+ ` : ""}${f2}
2896
+ `, c2 = this.value ? a2 : s;
2897
+ switch (this.state) {
2898
+ case "submit": {
2899
+ const r2 = e ? `${styleText2("gray", S_BAR)} ` : "";
2900
+ return `${o2}${r2}${styleText2("dim", c2)}`;
2901
+ }
2902
+ case "cancel": {
2903
+ const r2 = e ? `${styleText2("gray", S_BAR)} ` : "";
2904
+ return `${o2}${r2}${styleText2(["strikethrough", "dim"], c2)}${e ? `
2905
+ ${styleText2("gray", S_BAR)}` : ""}`;
2906
+ }
2907
+ default: {
2908
+ const r2 = e ? `${styleText2("cyan", S_BAR)} ` : "", g2 = e ? styleText2("cyan", S_BAR_END) : "";
2909
+ return `${o2}${r2}${this.value ? `${styleText2("green", S_RADIO_ACTIVE)} ${a2}` : `${styleText2("dim", S_RADIO_INACTIVE)} ${styleText2("dim", a2)}`}${i.vertical ? e ? `
2910
+ ${styleText2("cyan", S_BAR)} ` : `
2911
+ ` : ` ${styleText2("dim", "/")} `}${this.value ? `${styleText2("dim", S_RADIO_INACTIVE)} ${styleText2("dim", s)}` : `${styleText2("green", S_RADIO_ACTIVE)} ${s}`}
2912
+ ${g2}
2913
+ `;
2914
+ }
2915
+ }
2916
+ }
2917
+ }).prompt();
2918
+ };
2919
+ var MULTISELECT_INSTRUCTIONS = [
2920
+ `${styleText2("dim", "\u2191/\u2193")} to navigate`,
2921
+ `${styleText2("dim", "Space:")} select`,
2922
+ `${styleText2("dim", "Enter:")} confirm`
2923
+ ];
2924
+ var log = {
2925
+ message: (s = [], {
2926
+ symbol: e = styleText2("gray", S_BAR),
2927
+ secondarySymbol: r2 = styleText2("gray", S_BAR),
2928
+ output: m2 = process.stdout,
2929
+ spacing: l2 = 1,
2930
+ withGuide: c2
2931
+ } = {}) => {
2932
+ const t2 = [], o2 = c2 ?? settings.withGuide, f2 = o2 ? r2 : "", O = o2 ? `${e} ` : "", u3 = o2 ? `${r2} ` : "";
2933
+ for (let i = 0;i < l2; i++)
2934
+ t2.push(f2);
2935
+ const g2 = Array.isArray(s) ? s : s.split(`
2936
+ `);
2937
+ if (g2.length > 0) {
2938
+ const [i, ...y] = g2;
2939
+ i.length > 0 ? t2.push(`${O}${i}`) : t2.push(o2 ? e : "");
2940
+ for (const p2 of y)
2941
+ p2.length > 0 ? t2.push(`${u3}${p2}`) : t2.push(o2 ? r2 : "");
2942
+ }
2943
+ m2.write(`${t2.join(`
2944
+ `)}
2945
+ `);
2946
+ },
2947
+ info: (s, e) => {
2948
+ log.message(s, { ...e, symbol: styleText2("blue", S_INFO) });
2949
+ },
2950
+ success: (s, e) => {
2951
+ log.message(s, { ...e, symbol: styleText2("green", S_SUCCESS) });
2952
+ },
2953
+ step: (s, e) => {
2954
+ log.message(s, { ...e, symbol: styleText2("green", S_STEP_SUBMIT) });
2955
+ },
2956
+ warn: (s, e) => {
2957
+ log.message(s, { ...e, symbol: styleText2("yellow", S_WARN) });
2958
+ },
2959
+ warning: (s, e) => {
2960
+ log.warn(s, e);
2961
+ },
2962
+ error: (s, e) => {
2963
+ log.message(s, { ...e, symbol: styleText2("red", S_ERROR) });
2964
+ }
2965
+ };
2966
+ var intro = (o2 = "", t2) => {
2967
+ const i = t2?.output ?? process.stdout, e = t2?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR_START)} ` : "";
2968
+ i.write(`${e}${o2}
2969
+ `);
2970
+ };
2971
+ var outro = (o2 = "", t2) => {
2972
+ const i = t2?.output ?? process.stdout, e = t2?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR)}
2973
+ ${styleText2("gray", S_BAR_END)} ` : "";
2974
+ i.write(`${e}${o2}
2975
+
2976
+ `);
2977
+ };
2978
+ var W$1 = (o2) => o2;
2979
+ var C2 = (o2, e, s) => {
2980
+ const a2 = {
2981
+ hard: true,
2982
+ trim: false
2983
+ }, i = wrapAnsi(o2, e, a2).split(`
2984
+ `), 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);
2985
+ return wrapAnsi(o2, g2, a2);
2986
+ };
2987
+ var note = (o2 = "", e = "", s) => {
2988
+ 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(`
2989
+ `).map(c2), ""], n2 = dist_default2(e), t2 = Math.max(g2.reduce((m2, F) => {
2990
+ const O = dist_default2(F);
2991
+ return O > m2 ? O : m2;
2992
+ }, 0), n2) + 2, h2 = g2.map((m2) => `${styleText2("gray", S_BAR)} ${m2}${" ".repeat(t2 - dist_default2(m2))}${styleText2("gray", S_BAR)}`).join(`
2993
+ `), T3 = i ? `${styleText2("gray", S_BAR)}
2994
+ ` : "", l$1 = i ? S_CONNECT_LEFT : S_CORNER_BOTTOM_LEFT;
2995
+ 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)}
2996
+ ${h2}
2997
+ ${styleText2("gray", l$1 + S_BAR_H.repeat(t2 + 2) + S_CORNER_BOTTOM_RIGHT)}
2998
+ `);
2999
+ };
3000
+ var W = (l2) => styleText2("magenta", l2);
3001
+ var spinner = ({
3002
+ indicator: l2 = "dots",
3003
+ onCancel: h2,
3004
+ output: n2 = process.stdout,
3005
+ cancelMessage: G,
3006
+ errorMessage: O,
3007
+ frames: E = unicode ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"],
3008
+ delay: F = unicode ? 80 : 120,
3009
+ signal: m2,
3010
+ ...I
3011
+ } = {}) => {
3012
+ const u3 = isCI();
3013
+ let M2, T3, d = false, S = false, s = "", p2, w = performance.now();
3014
+ const x = getColumns(n2), k = I?.styleFrame ?? W, g2 = (e) => {
3015
+ const r2 = e > 1 ? O ?? settings.messages.error : G ?? settings.messages.cancel;
3016
+ S = e === 1, d && (a2(r2, e), S && typeof h2 == "function" && h2());
3017
+ }, f2 = () => g2(2), i = () => g2(1), A = () => {
3018
+ 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);
3019
+ }, H = () => {
3020
+ 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);
3021
+ }, y = () => {
3022
+ if (p2 === undefined)
3023
+ return;
3024
+ u3 && n2.write(`
3025
+ `);
3026
+ const r2 = wrapAnsi(p2, x, {
3027
+ hard: true,
3028
+ trim: false
3029
+ }).split(`
3030
+ `);
3031
+ 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());
3032
+ }, C3 = (e) => e.replace(/\.+$/, ""), _2 = (e) => {
3033
+ const r2 = (performance.now() - e) / 1000, t2 = Math.floor(r2 / 60), o2 = Math.floor(r2 % 60);
3034
+ return t2 > 0 ? `[${t2}m ${o2}s]` : `[${o2}s]`;
3035
+ }, N = I.withGuide ?? settings.withGuide, P2 = (e = "") => {
3036
+ d = true, M2 = block({ output: n2 }), s = C3(e), w = performance.now(), N && n2.write(`${styleText2("gray", S_BAR)}
3037
+ `);
3038
+ let r2 = 0, t2 = 0;
3039
+ A(), T3 = setInterval(() => {
3040
+ if (u3 && s === p2)
3041
+ return;
3042
+ y(), p2 = s;
3043
+ const o2 = k(E[r2]);
3044
+ let v;
3045
+ if (u3)
3046
+ v = `${o2} ${s}...`;
3047
+ else if (l2 === "timer")
3048
+ v = `${o2} ${s} ${_2(w)}`;
3049
+ else {
3050
+ const B = ".".repeat(Math.floor(t2)).slice(0, 3);
3051
+ v = `${o2} ${s}${B}`;
3052
+ }
3053
+ const j = wrapAnsi(v, x, {
3054
+ hard: true,
3055
+ trim: false
3056
+ });
3057
+ n2.write(j), r2 = r2 + 1 < E.length ? r2 + 1 : 0, t2 = t2 < 4 ? t2 + 0.125 : 0;
3058
+ }, F);
3059
+ }, a2 = (e = "", r2 = 0, t2 = false) => {
3060
+ if (!d)
3061
+ return;
3062
+ d = false, clearInterval(T3), y();
3063
+ const o2 = r2 === 0 ? styleText2("green", S_STEP_SUBMIT) : r2 === 1 ? styleText2("red", S_STEP_CANCEL) : styleText2("red", S_STEP_ERROR);
3064
+ s = e ?? s, t2 || (l2 === "timer" ? n2.write(`${o2} ${s} ${_2(w)}
3065
+ `) : n2.write(`${o2} ${s}
3066
+ `)), H(), M2();
3067
+ };
3068
+ return {
3069
+ start: P2,
3070
+ stop: (e = "") => a2(e, 0),
3071
+ message: (e = "") => {
3072
+ s = C3(e ?? s);
3073
+ },
3074
+ cancel: (e = "") => a2(e, 1),
3075
+ error: (e = "") => a2(e, 2),
3076
+ clear: () => a2("", 0, true),
3077
+ get isCancelled() {
3078
+ return S;
3079
+ }
3080
+ };
3081
+ };
3082
+ var u3 = {
3083
+ light: unicodeOr("\u2500", "-"),
3084
+ heavy: unicodeOr("\u2501", "="),
3085
+ block: unicodeOr("\u2588", "#")
3086
+ };
3087
+ var SELECT_INSTRUCTIONS = [
3088
+ `${styleText2("dim", "\u2191/\u2193")} to navigate`,
3089
+ `${styleText2("dim", "Enter:")} confirm`
3090
+ ];
3091
+ var i = `${styleText2("gray", S_BAR)} `;
3092
+
1576
3093
  // src/commands/push.ts
3094
+ var import_picocolors = __toESM(require_picocolors(), 1);
1577
3095
  async function runPush(config, opts = {}) {
1578
- console.log("@bungres/kit push: loading schemas...");
3096
+ intro(import_picocolors.default.bgCyan(import_picocolors.default.black(" @bungres/kit push ")));
3097
+ const s = spinner();
3098
+ s.start("Loading schemas...");
1579
3099
  const schemas = await loadSchemas(config.schema);
1580
3100
  if (schemas.length === 0) {
1581
- console.warn("No table definitions found. Check your schema glob pattern.");
3101
+ s.stop("No schemas found.");
3102
+ log.warn(import_picocolors.default.yellow("No table definitions found. Check your schema glob pattern."));
3103
+ outro("Failed.");
1582
3104
  return;
1583
3105
  }
3106
+ s.stop(`Loaded ${schemas.length} schemas.`);
1584
3107
  const sql2 = new Bun.SQL(config.dbUrl);
3108
+ const ms = spinner();
3109
+ ms.start("Computing diff from database...");
1585
3110
  try {
1586
3111
  await sql2.unsafe(`CREATE SCHEMA IF NOT EXISTS "${config.migrationsSchema}";`);
1587
3112
  const qualifiedPush = `"${config.migrationsSchema}"."__bungres_push"`;
@@ -1596,79 +3121,96 @@ async function runPush(config, opts = {}) {
1596
3121
  if (rows.length > 0) {
1597
3122
  prevSnapshot = typeof rows[0].snapshot === "string" ? JSON.parse(rows[0].snapshot) : rows[0].snapshot;
1598
3123
  }
1599
- const currentSnapshot = Object.fromEntries(schemas.map((s) => [s.config.name, s.config]));
3124
+ const currentSnapshot = Object.fromEntries(schemas.map((schemaEntry) => [schemaEntry.config.name, schemaEntry.config]));
1600
3125
  const diff = diffSchemas(prevSnapshot, currentSnapshot);
1601
3126
  if (diff.statements.length === 0) {
1602
- console.log(`
1603
- No schema changes detected. Database is up to date.`);
3127
+ ms.stop("Up to date.");
3128
+ log.success(import_picocolors.default.green("No schema changes detected. Database is up to date."));
3129
+ outro("Done.");
1604
3130
  return;
1605
3131
  }
1606
- console.log(`
1607
- Changes to apply:`);
1608
- for (const s of diff.summary)
1609
- console.log(` + ${s}`);
3132
+ ms.stop(`Computed ${diff.statements.length} statements.`);
3133
+ log.message(import_picocolors.default.bold("Changes to apply:"));
3134
+ for (const change of diff.summary) {
3135
+ if (change.startsWith("CREATE") || change.startsWith("ALTER TABLE") && change.includes("ADD")) {
3136
+ log.success(import_picocolors.default.green(` + ${change}`));
3137
+ } else if (change.startsWith("DROP") || change.startsWith("ALTER TABLE") && change.includes("DROP")) {
3138
+ log.error(import_picocolors.default.red(` - ${change}`));
3139
+ } else {
3140
+ log.info(import_picocolors.default.blue(` ~ ${change}`));
3141
+ }
3142
+ }
1610
3143
  if (diff.warnings && diff.warnings.length > 0) {
1611
- console.warn(`
1612
- \u26A0\uFE0F WARNING: Data Loss Detected!`);
3144
+ log.warn(import_picocolors.default.bgRed(import_picocolors.default.white(" \u26A0\uFE0F DATA LOSS DETECTED ")));
1613
3145
  for (const w of diff.warnings)
1614
- console.warn(` ! ${w}`);
1615
- console.warn(`
1616
- These changes will be immediately executed against the database!`);
3146
+ log.warn(import_picocolors.default.red(` ! ${w}`));
3147
+ log.warn(import_picocolors.default.yellow("These changes will be immediately executed against the database!"));
1617
3148
  }
1618
3149
  if (!opts.force) {
1619
- process.stdout.write(`
1620
- Are you sure you want to push these changes? Type YES to continue: `);
1621
- const answer = await readLine();
1622
- if (answer.trim().toLowerCase() !== "yes") {
1623
- console.log("Aborted.");
3150
+ const confirm2 = await confirm({
3151
+ message: "Are you sure you want to push these changes?",
3152
+ initialValue: true
3153
+ });
3154
+ if (isCancel(confirm2) || !confirm2) {
3155
+ outro(import_picocolors.default.gray("Push aborted."));
1624
3156
  return;
1625
3157
  }
1626
3158
  }
1627
- console.log(`
1628
- Pushing changes...`);
3159
+ const exSpinner = spinner();
3160
+ exSpinner.start("Pushing changes...");
1629
3161
  for (const stmt of diff.statements) {
1630
3162
  if (config.verbose) {
1631
- console.log(`-- ${stmt}`);
3163
+ log.info(import_picocolors.default.gray(`-- ${stmt}`));
1632
3164
  }
1633
3165
  await sql2.unsafe(stmt);
1634
3166
  }
1635
3167
  await sql2.unsafe(`INSERT INTO ${qualifiedPush} (snapshot) VALUES ($1);`, [JSON.stringify(currentSnapshot)]);
1636
- console.log(`
1637
- Push complete.`);
3168
+ exSpinner.stop(import_picocolors.default.green("Changes applied successfully."));
3169
+ outro(import_picocolors.default.cyan("\u2728 Push complete."));
3170
+ } catch (err) {
3171
+ log.error(import_picocolors.default.red(`Push failed: ${err.message}`));
3172
+ outro("Failed.");
1638
3173
  } finally {
1639
3174
  await sql2.end();
1640
3175
  }
1641
3176
  }
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
3177
  // src/commands/generate.ts
1648
3178
  import { join as join3, resolve as resolve3 } from "path";
1649
-
1650
- // src/utils/colors.ts
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";
3179
+ import { readdirSync } from "fs";
3180
+ var import_picocolors2 = __toESM(require_picocolors(), 1);
1658
3181
  async function runGenerate(config, name) {
1659
- console.log("@bungres/kit generate: loading schemas...");
3182
+ intro(import_picocolors2.default.bgCyan(import_picocolors2.default.black(" @bungres/kit generate ")));
3183
+ const s = spinner();
3184
+ s.start("Loading schemas...");
1660
3185
  const schemas = await loadSchemas(config.schema);
1661
3186
  if (schemas.length === 0) {
1662
- console.warn(colorize("No table definitions found. Check your schema glob pattern.", "yellow"));
3187
+ s.stop("No table definitions found.");
3188
+ log.warn(import_picocolors2.default.yellow("Check your schema glob pattern."));
3189
+ outro("Failed.");
1663
3190
  return;
1664
3191
  }
3192
+ s.stop(`Loaded ${schemas.length} schemas.`);
1665
3193
  const migrationsDir = resolve3(config.out);
3194
+ const metaDir = join3(migrationsDir, "meta");
1666
3195
  await Bun.$`mkdir -p ${migrationsDir}`.quiet();
1667
- const currentSnapshot = Object.fromEntries(schemas.map((s) => [s.config.name, s.config]));
1668
- const snapshotPath = join3(migrationsDir, SNAPSHOT_FILE);
1669
- const snapshotFile = Bun.file(snapshotPath);
1670
- const isFirstMigration = !await snapshotFile.exists();
1671
- const prevSnapshot = isFirstMigration ? {} : JSON.parse(await snapshotFile.text());
3196
+ await Bun.$`mkdir -p ${metaDir}`.quiet();
3197
+ const currentSnapshot = Object.fromEntries(schemas.map((s2) => [s2.config.name, s2.config]));
3198
+ let prevSnapshot = {};
3199
+ let isFirstMigration = true;
3200
+ try {
3201
+ const files = readdirSync(metaDir).filter((f2) => f2.endsWith("_snapshot.json")).sort();
3202
+ if (files.length > 0) {
3203
+ const latest = files[files.length - 1];
3204
+ prevSnapshot = JSON.parse(await Bun.file(join3(metaDir, latest)).text());
3205
+ isFirstMigration = false;
3206
+ } else {
3207
+ const legacyFile2 = Bun.file(join3(migrationsDir, ".snapshot.json"));
3208
+ if (await legacyFile2.exists()) {
3209
+ prevSnapshot = JSON.parse(await legacyFile2.text());
3210
+ isFirstMigration = false;
3211
+ }
3212
+ }
3213
+ } catch (e) {}
1672
3214
  const now = new Date;
1673
3215
  const yyyy = now.getUTCFullYear();
1674
3216
  const mm = String(now.getUTCMonth() + 1).padStart(2, "0");
@@ -1679,60 +3221,86 @@ async function runGenerate(config, name) {
1679
3221
  const prefix = `${yyyy}_${mm}_${dd}_${HH}${MM}${SS}`;
1680
3222
  const filename = name ? `${prefix}_${name}.sql` : `${prefix}.sql`;
1681
3223
  const outPath = join3(migrationsDir, filename);
1682
- let statements;
3224
+ let upStatements;
3225
+ let downStatements;
1683
3226
  let summary;
1684
3227
  let warnings = [];
1685
3228
  if (isFirstMigration) {
1686
3229
  const sorted = topoSort(schemas);
1687
- statements = [
1688
- ...sorted.flatMap((entry) => [
1689
- `-- ${entry.exportName}`,
1690
- generateCreateTable(entry.config, true),
1691
- ``
1692
- ])
1693
- ];
1694
- summary = sorted.map((s) => `CREATE TABLE ${s.config.name}`);
3230
+ upStatements = sorted.flatMap((entry) => [
3231
+ `-- ${entry.exportName}`,
3232
+ generateCreateTable(entry.config, true),
3233
+ ``
3234
+ ]);
3235
+ downStatements = [...sorted].reverse().flatMap((entry) => {
3236
+ const tbl = entry.config.schema ? `"${entry.config.schema}"."${entry.config.name}"` : `"${entry.config.name}"`;
3237
+ return [`DROP TABLE IF EXISTS ${tbl};`];
3238
+ });
3239
+ summary = sorted.map((s2) => `CREATE TABLE ${s2.config.name}`);
1695
3240
  } else {
1696
- const diff = diffSchemas(prevSnapshot, currentSnapshot);
1697
- if (diff.statements.length === 0) {
1698
- console.log(colorize(`
1699
- No schema changes detected. Nothing to generate.`, "yellow"));
3241
+ const upDiff = diffSchemas(prevSnapshot, currentSnapshot);
3242
+ if (upDiff.statements.length === 0) {
3243
+ log.warn(import_picocolors2.default.yellow("No schema changes detected. Nothing to generate."));
3244
+ outro("Done.");
1700
3245
  return;
1701
3246
  }
1702
- statements = diff.statements;
1703
- summary = diff.summary;
1704
- warnings = diff.warnings;
3247
+ upStatements = upDiff.statements;
3248
+ summary = upDiff.summary;
3249
+ warnings = upDiff.warnings;
3250
+ const downDiff = diffSchemas(currentSnapshot, prevSnapshot);
3251
+ downStatements = downDiff.statements;
3252
+ }
3253
+ log.message(import_picocolors2.default.bold("Schema changes detected:"));
3254
+ for (const s2 of summary) {
3255
+ if (s2.startsWith("CREATE") || s2.startsWith("ALTER TABLE") && s2.includes("ADD")) {
3256
+ log.success(import_picocolors2.default.green(` + ${s2}`));
3257
+ } else if (s2.startsWith("DROP") || s2.startsWith("ALTER TABLE") && s2.includes("DROP")) {
3258
+ log.error(import_picocolors2.default.red(` - ${s2}`));
3259
+ } else {
3260
+ log.info(import_picocolors2.default.blue(` ~ ${s2}`));
3261
+ }
1705
3262
  }
3263
+ if (warnings.length > 0) {
3264
+ log.warn(import_picocolors2.default.bgRed(import_picocolors2.default.white(" \u26A0\uFE0F DATA LOSS DETECTED ")));
3265
+ for (const w of warnings)
3266
+ log.warn(import_picocolors2.default.red(` ! ${w}`));
3267
+ }
3268
+ const shouldGenerate = await confirm({
3269
+ message: "Generate this migration?",
3270
+ initialValue: true
3271
+ });
3272
+ if (isCancel(shouldGenerate) || !shouldGenerate) {
3273
+ outro(import_picocolors2.default.gray("Generation cancelled."));
3274
+ return;
3275
+ }
3276
+ s.start("Writing files...");
1706
3277
  const lines = [
1707
3278
  `-- Migration: ${filename}`,
1708
3279
  `-- Generated by @bungres/kit at ${new Date().toISOString()}`,
1709
3280
  `-- Changes: ${summary.join(", ")}`,
1710
3281
  ``,
1711
- ...statements
3282
+ `-- ==== UP ====`,
3283
+ ...upStatements,
3284
+ ``,
3285
+ `-- ==== DOWN ====`,
3286
+ ...downStatements,
3287
+ ``
1712
3288
  ];
1713
3289
  await Bun.write(outPath, lines.join(`
1714
3290
  `));
1715
- await Bun.write(snapshotPath, JSON.stringify(currentSnapshot, null, 2));
1716
- console.log(colorize(`
1717
- Generated: ${outPath}`, "green"));
1718
- console.log(` Changes:`);
1719
- for (const s of summary)
1720
- console.log(colorize(` + ${s}`, "cyan"));
1721
- if (warnings.length > 0) {
1722
- console.warn(colorize(`
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"));
3291
+ const metaPath = join3(metaDir, `${prefix}_snapshot.json`);
3292
+ await Bun.write(metaPath, JSON.stringify(currentSnapshot, null, 2));
3293
+ const legacyFile = Bun.file(join3(migrationsDir, ".snapshot.json"));
3294
+ if (await legacyFile.exists()) {
3295
+ await Bun.$`rm ${legacyFile.name}`.quiet();
3296
+ }
3297
+ s.stop(`Generated ${import_picocolors2.default.cyan(filename)}`);
3298
+ outro(`Run ${import_picocolors2.default.green("bungres migrate")} to apply it.`);
1731
3299
  }
1732
3300
  function topoSort(schemas) {
1733
3301
  const byName = new Map(schemas.map((s) => [s.config.name, s]));
1734
3302
  function deps(config) {
1735
- return Object.values(config.columns).map((col2) => col2.references?.table).filter((t) => t !== undefined && byName.has(t) && t !== config.name);
3303
+ return Object.values(config.columns).map((col2) => col2.references?.table).filter((t2) => t2 !== undefined && byName.has(t2) && t2 !== config.name);
1736
3304
  }
1737
3305
  const visited = new Set;
1738
3306
  const result = [];
@@ -1753,7 +3321,9 @@ function topoSort(schemas) {
1753
3321
  }
1754
3322
  // src/commands/migrate.ts
1755
3323
  import { join as join4, resolve as resolve4 } from "path";
3324
+ var import_picocolors3 = __toESM(require_picocolors(), 1);
1756
3325
  async function runMigrate(config) {
3326
+ intro(import_picocolors3.default.bgCyan(import_picocolors3.default.black(" @bungres/kit migrate ")));
1757
3327
  const migrationsDir = resolve4(config.out);
1758
3328
  const sql2 = new Bun.SQL(config.dbUrl);
1759
3329
  const table2 = config.migrationsTable;
@@ -1766,6 +3336,8 @@ CREATE TABLE IF NOT EXISTS ${qualifiedTable} (
1766
3336
  name TEXT NOT NULL UNIQUE,
1767
3337
  applied_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
1768
3338
  );`.trim();
3339
+ const s = spinner();
3340
+ s.start("Checking pending migrations...");
1769
3341
  try {
1770
3342
  await sql2.unsafe(createSchema);
1771
3343
  await sql2.unsafe(createMigrationsTable);
@@ -1776,38 +3348,49 @@ CREATE TABLE IF NOT EXISTS ${qualifiedTable} (
1776
3348
  }
1777
3349
  files.sort();
1778
3350
  if (files.length === 0) {
1779
- console.log(colorize("No migration files found in " + migrationsDir, "yellow"));
1780
- console.log(colorize("Run `bungres generate` first.", "yellow"));
3351
+ s.stop("No files found.");
3352
+ log.warn(import_picocolors3.default.yellow(`No migration files found in ${migrationsDir}`));
3353
+ log.info(`Run ${import_picocolors3.default.green("bungres generate")} first.`);
3354
+ outro("Done.");
1781
3355
  return;
1782
3356
  }
1783
3357
  const applied = await sql2.unsafe(`SELECT name FROM ${qualifiedTable}`);
1784
- const appliedSet = new Set(applied.map((r) => r.name));
1785
- const pending = files.filter((f) => !appliedSet.has(f));
3358
+ const appliedSet = new Set(applied.map((r2) => r2.name));
3359
+ const pending = files.filter((f2) => !appliedSet.has(f2));
1786
3360
  if (pending.length === 0) {
1787
- console.log(colorize("Everything is up to date.", "green"));
3361
+ s.stop("Up to date.");
3362
+ log.success(import_picocolors3.default.green("Everything is up to date."));
3363
+ outro("Done.");
1788
3364
  return;
1789
3365
  }
1790
- console.log(colorize(`
1791
- Running ${pending.length} pending migration(s)...
1792
- `, "cyan"));
3366
+ s.stop(`Found ${pending.length} pending migration(s).`);
1793
3367
  for (const file of pending) {
3368
+ const ms = spinner();
3369
+ ms.start(`Applying ${file}...`);
1794
3370
  const content = await Bun.file(join4(migrationsDir, file)).text();
3371
+ let upContent = content;
3372
+ const upMatch = content.match(/-- ==== UP ====([\s\S]*?)(?:-- ==== DOWN ====|$)/i);
3373
+ if (upMatch) {
3374
+ upContent = upMatch[1].trim();
3375
+ }
1795
3376
  if (config.verbose) {
1796
- console.log(`-- ${file} --
1797
- ${content}
1798
- `);
3377
+ log.info(import_picocolors3.default.gray(`-- ${file} --
3378
+ ${upContent}
3379
+ `));
1799
3380
  }
1800
3381
  await sql2.transaction(async (txSql) => {
1801
- const statements = config.breakpoints ? content.split(/-->statement-breakpoint/g).flatMap((chunk) => chunk.split(";").map((s) => s.trim()).filter(Boolean)) : content.split(";").map((s) => s.trim()).filter(Boolean);
3382
+ 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
3383
  for (const stmt of statements) {
1803
3384
  await txSql.unsafe(stmt + ";");
1804
3385
  }
1805
3386
  await txSql.unsafe(`INSERT INTO ${qualifiedTable} (name) VALUES ($1)`, [file]);
1806
3387
  });
1807
- console.log(colorize(` \u2713 ${file}`, "green"));
3388
+ ms.stop(import_picocolors3.default.green(`\u2713 Applied ${file}`));
1808
3389
  }
1809
- console.log(colorize(`
1810
- Done.`, "green"));
3390
+ outro(import_picocolors3.default.cyan("\u2728 All migrations applied successfully."));
3391
+ } catch (err) {
3392
+ log.error(import_picocolors3.default.red(`Migration failed: ${err.message}`));
3393
+ outro("Failed.");
1811
3394
  } finally {
1812
3395
  await sql2.end();
1813
3396
  }
@@ -1879,13 +3462,13 @@ function groupByTable(columns2, constraints, indexes) {
1879
3462
  map.set(col2.table_name, {
1880
3463
  tableName: col2.table_name,
1881
3464
  columns: [],
1882
- indexes: indexes.filter((i) => i.tablename === col2.table_name)
3465
+ indexes: indexes.filter((i2) => i2.tablename === col2.table_name)
1883
3466
  });
1884
3467
  }
1885
- const tableConstraints = constraints.filter((c) => c.table_name === col2.table_name && c.column_name === col2.column_name);
1886
- const pkConstraint = tableConstraints.find((c) => c.constraint_type === "PRIMARY KEY");
1887
- const uniqueConstraint = tableConstraints.find((c) => c.constraint_type === "UNIQUE");
1888
- const fkConstraint = tableConstraints.find((c) => c.constraint_type === "FOREIGN KEY");
3468
+ const tableConstraints = constraints.filter((c2) => c2.table_name === col2.table_name && c2.column_name === col2.column_name);
3469
+ const pkConstraint = tableConstraints.find((c2) => c2.constraint_type === "PRIMARY KEY");
3470
+ const uniqueConstraint = tableConstraints.find((c2) => c2.constraint_type === "UNIQUE");
3471
+ const fkConstraint = tableConstraints.find((c2) => c2.constraint_type === "FOREIGN KEY");
1889
3472
  map.get(col2.table_name).columns.push({
1890
3473
  name: col2.column_name,
1891
3474
  dataType: col2.data_type,
@@ -1934,19 +3517,19 @@ function generateSchemaTS(tableMap, dbSchema) {
1934
3517
  if (table2.indexes.length > 0) {
1935
3518
  const idxLines = [];
1936
3519
  for (const idx of table2.indexes) {
1937
- const m = idx.indexdef.match(/CREATE (UNIQUE )?INDEX (.+) ON (.+) USING (\w+) \((.+)\)(?: WHERE (.+))?/i);
1938
- if (m) {
1939
- const isUnique = !!m[1];
1940
- const name = m[2].trim().replace(/^"|"$/g, "");
3520
+ const m2 = idx.indexdef.match(/CREATE (UNIQUE )?INDEX (.+) ON (.+) USING (\w+) \((.+)\)(?: WHERE (.+))?/i);
3521
+ if (m2) {
3522
+ const isUnique = !!m2[1];
3523
+ const name = m2[2].trim().replace(/^"|"$/g, "");
1941
3524
  if (name.endsWith("_pkey") || name.endsWith("_key"))
1942
3525
  continue;
1943
- const using = m[4].toLowerCase();
1944
- const cols = m[5].split(",").map((c) => `"${c.trim().replace(/^"|"$/g, "")}"`);
3526
+ const using = m2[4].toLowerCase();
3527
+ const cols = m2[5].split(",").map((c2) => `"${c2.trim().replace(/^"|"$/g, "")}"`);
1945
3528
  let idxStr = `{ name: "${name}", columns: [${cols.join(", ")}], using: "${using}"`;
1946
3529
  if (isUnique)
1947
3530
  idxStr += `, unique: true`;
1948
- if (m[6])
1949
- idxStr += `, where: \`${m[6].trim()}\``;
3531
+ if (m2[6])
3532
+ idxStr += `, where: \`${m2[6].trim()}\``;
1950
3533
  idxStr += ` }`;
1951
3534
  idxLines.push(idxStr);
1952
3535
  }
@@ -2065,16 +3648,20 @@ function pgTypeToBungresBuilderName(col2) {
2065
3648
  return "text";
2066
3649
  }
2067
3650
  function toCamelCase(str) {
2068
- return str.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
3651
+ return str.replace(/_([a-z])/g, (_2, c2) => c2.toUpperCase());
2069
3652
  }
2070
3653
  // src/commands/status.ts
2071
3654
  import { resolve as resolve6 } from "path";
3655
+ var import_picocolors4 = __toESM(require_picocolors(), 1);
2072
3656
  async function runStatus(config) {
3657
+ intro(import_picocolors4.default.bgCyan(import_picocolors4.default.black(" @bungres/kit status ")));
2073
3658
  const migrationsDir = resolve6(config.out);
2074
3659
  const sql2 = new Bun.SQL(config.dbUrl);
2075
3660
  const table2 = config.migrationsTable;
2076
3661
  const schema = config.migrationsSchema;
2077
3662
  const qualifiedTable = `"${schema}"."${table2}"`;
3663
+ const s = spinner();
3664
+ s.start("Checking migration status...");
2078
3665
  try {
2079
3666
  const tableCheck = await sql2.unsafe(`SELECT EXISTS (
2080
3667
  SELECT 1 FROM information_schema.tables
@@ -2088,44 +3675,59 @@ async function runStatus(config) {
2088
3675
  }
2089
3676
  files.sort();
2090
3677
  if (files.length === 0) {
2091
- console.log(colorize("No migration files found. Run `bungres generate` first.", "yellow"));
3678
+ s.stop("No files found.");
3679
+ log.warn(import_picocolors4.default.yellow("No migration files found."));
3680
+ log.info(`Run ${import_picocolors4.default.green("bungres generate")} first.`);
3681
+ outro("Done.");
2092
3682
  return;
2093
3683
  }
2094
3684
  let appliedSet = new Set;
2095
3685
  if (trackingExists) {
2096
3686
  const applied = await sql2.unsafe(`SELECT name FROM ${qualifiedTable} ORDER BY applied_at`);
2097
- appliedSet = new Set(applied.map((r) => r.name));
3687
+ appliedSet = new Set(applied.map((r2) => r2.name));
2098
3688
  }
2099
- console.log(colorize(`
2100
- Migration status:
2101
- `, "cyan"));
3689
+ s.stop("Status check complete.");
3690
+ log.message(import_picocolors4.default.bold("Migration status:"));
2102
3691
  let pendingCount = 0;
2103
3692
  for (const file of files) {
2104
3693
  const isApplied = appliedSet.has(file);
2105
- const status = isApplied ? colorize("\u2713 applied ", "green") : colorize("\u2717 pending ", "yellow");
2106
- if (!isApplied)
3694
+ if (isApplied) {
3695
+ log.success(`${import_picocolors4.default.green("\u2713 applied ")} ${file}`);
3696
+ } else {
2107
3697
  pendingCount++;
2108
- console.log(` ${status} ${file}`);
3698
+ log.warn(`${import_picocolors4.default.yellow("\u2717 pending ")} ${file}`);
3699
+ }
2109
3700
  }
2110
- console.log(`
2111
- ${colorize(appliedSet.size.toString(), "green")} applied, ${colorize(pendingCount.toString(), "yellow")} pending.
2112
- `);
3701
+ log.info(`${import_picocolors4.default.green(appliedSet.size.toString())} applied, ${import_picocolors4.default.yellow(pendingCount.toString())} pending.`);
3702
+ outro("Done.");
3703
+ } catch (err) {
3704
+ log.error(import_picocolors4.default.red(`Status check failed: ${err.message}`));
3705
+ outro("Failed.");
2113
3706
  } finally {
2114
3707
  await sql2.end();
2115
3708
  }
2116
3709
  }
2117
3710
  // src/commands/drop.ts
3711
+ var import_picocolors5 = __toESM(require_picocolors(), 1);
2118
3712
  async function runDrop(config, opts = {}) {
3713
+ intro(import_picocolors5.default.bgCyan(import_picocolors5.default.black(" @bungres/kit drop ")));
3714
+ const s = spinner();
3715
+ s.start("Loading schemas...");
2119
3716
  const schemas = await loadSchemas(config.schema);
2120
3717
  if (schemas.length === 0) {
2121
- console.warn("No table definitions found in schema files.");
3718
+ s.stop("No schemas found.");
3719
+ log.warn(import_picocolors5.default.yellow("No table definitions found in schema files."));
3720
+ outro("Failed.");
2122
3721
  return;
2123
3722
  }
3723
+ s.stop(`Loaded ${schemas.length} schemas.`);
3724
+ const ms = spinner();
3725
+ ms.start("Checking database tables...");
2124
3726
  const sql2 = new Bun.SQL(config.dbUrl);
2125
3727
  try {
2126
3728
  const userSchema = config.dbSchema;
2127
3729
  const existingUserTablesResult = await sql2.unsafe(`SELECT table_name FROM information_schema.tables WHERE table_schema = $1`, [userSchema]);
2128
- const existingTableNames = new Set(existingUserTablesResult.map((r) => r.table_name));
3730
+ const existingTableNames = new Set(existingUserTablesResult.map((r2) => r2.table_name));
2129
3731
  const migTableCheck = await sql2.unsafe(`SELECT EXISTS (
2130
3732
  SELECT 1 FROM information_schema.tables
2131
3733
  WHERE table_schema = $1 AND table_name = $2
@@ -2136,12 +3738,15 @@ async function runDrop(config, opts = {}) {
2136
3738
  WHERE table_schema = $1 AND table_name = $2
2137
3739
  ) AS exists`, [config.migrationsSchema, "__bungres_push"]);
2138
3740
  const pushTableExists = pushTableCheck[0]?.exists ?? false;
2139
- const tablesToDrop = schemas.filter((s) => existingTableNames.has(s.config.name));
3741
+ const tablesToDrop = schemas.filter((sch) => existingTableNames.has(sch.config.name));
2140
3742
  if (tablesToDrop.length === 0 && !migrationTableExists && !pushTableExists) {
2141
- console.log("No tables to drop (they either don't exist or were already dropped).");
3743
+ ms.stop("Nothing to do.");
3744
+ log.success(import_picocolors5.default.green("No tables to drop (they either don't exist or were already dropped)."));
3745
+ outro("Done.");
2142
3746
  return;
2143
3747
  }
2144
- const tableNamesToPrint = tablesToDrop.map((s) => (s.config.schema ? s.config.schema + "." : "") + s.config.name);
3748
+ ms.stop("Database check complete.");
3749
+ const tableNamesToPrint = tablesToDrop.map((sch) => (sch.config.schema ? sch.config.schema + "." : "") + sch.config.name);
2145
3750
  if (migrationTableExists) {
2146
3751
  tableNamesToPrint.push(`${config.migrationsSchema}.${config.migrationsTable}`);
2147
3752
  }
@@ -2149,37 +3754,41 @@ async function runDrop(config, opts = {}) {
2149
3754
  tableNamesToPrint.push(`${config.migrationsSchema}.__bungres_push`);
2150
3755
  }
2151
3756
  if (!opts.force) {
2152
- console.warn(colorize(`
2153
- \u26A0\uFE0F WARNING: This will drop the following tables and ALL their data:
2154
- `, "red"));
2155
- for (const name of tableNamesToPrint)
2156
- console.log(colorize(` - ${name}`, "yellow"));
2157
- process.stdout.write(colorize(`
2158
- Are you sure? Type YES to continue: `, "cyan"));
2159
- for await (const line of console) {
2160
- if (line.trim().toLowerCase() !== "yes") {
2161
- console.log("Aborted.");
2162
- return;
2163
- }
2164
- break;
3757
+ log.warn(import_picocolors5.default.bgRed(import_picocolors5.default.white(" \u26A0\uFE0F WARNING ")));
3758
+ log.message(import_picocolors5.default.bold(import_picocolors5.default.red("This will drop the following tables and ALL their data:")));
3759
+ for (const name of tableNamesToPrint) {
3760
+ log.info(import_picocolors5.default.yellow(` - ${name}`));
3761
+ }
3762
+ const confirm2 = await confirm({
3763
+ message: "Are you sure you want to proceed?",
3764
+ initialValue: false
3765
+ });
3766
+ if (isCancel(confirm2) || !confirm2) {
3767
+ outro(import_picocolors5.default.gray("Drop aborted."));
3768
+ return;
2165
3769
  }
2166
3770
  }
3771
+ const exSpinner = spinner();
3772
+ exSpinner.start("Dropping tables...");
2167
3773
  for (const entry of tablesToDrop) {
2168
3774
  const ddl = `DROP TABLE IF EXISTS "${entry.config.name}" CASCADE;`;
2169
3775
  await sql2.unsafe(ddl);
2170
- console.log(colorize(` \u2713 dropped ${entry.config.name}`, "green"));
3776
+ log.step(import_picocolors5.default.gray(`Dropped ${entry.config.name}`));
2171
3777
  }
2172
3778
  if (migrationTableExists) {
2173
3779
  const qualifiedMigTable = `"${config.migrationsSchema}"."${config.migrationsTable}"`;
2174
3780
  await sql2.unsafe(`DROP TABLE IF EXISTS ${qualifiedMigTable} CASCADE`);
2175
- console.log(colorize(` \u2713 dropped ${config.migrationsSchema}.${config.migrationsTable}`, "green"));
3781
+ log.step(import_picocolors5.default.gray(`Dropped ${config.migrationsSchema}.${config.migrationsTable}`));
2176
3782
  }
2177
3783
  if (pushTableExists) {
2178
3784
  await sql2.unsafe(`DROP TABLE IF EXISTS "${config.migrationsSchema}"."__bungres_push" CASCADE`);
2179
- console.log(colorize(` \u2713 dropped ${config.migrationsSchema}.__bungres_push`, "green"));
3785
+ log.step(import_picocolors5.default.gray(`Dropped ${config.migrationsSchema}.__bungres_push`));
2180
3786
  }
2181
- console.log(colorize(`
2182
- Drop complete.`, "green"));
3787
+ exSpinner.stop("Tables dropped.");
3788
+ outro(import_picocolors5.default.cyan("\u2728 Drop complete."));
3789
+ } catch (err) {
3790
+ log.error(import_picocolors5.default.red(`Drop failed: ${err.message}`));
3791
+ outro("Failed.");
2183
3792
  } finally {
2184
3793
  await sql2.end();
2185
3794
  }