UNPKG

@binochoi/drizzle-kit

Version:
1,430 lines (1,419 loc) 3.18 MB
#!/usr/bin/env node "use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __esm = (fn, res) => function __init() { return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res; }; var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // ../node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/vendor/ansi-styles/index.js function assembleStyles() { const codes = /* @__PURE__ */ new Map(); for (const [groupName, group] of Object.entries(styles)) { for (const [styleName, style] of Object.entries(group)) { styles[styleName] = { open: `\x1B[${style[0]}m`, close: `\x1B[${style[1]}m` }; group[styleName] = styles[styleName]; codes.set(style[0], style[1]); } Object.defineProperty(styles, groupName, { value: group, enumerable: false }); } Object.defineProperty(styles, "codes", { value: codes, enumerable: false }); styles.color.close = "\x1B[39m"; styles.bgColor.close = "\x1B[49m"; styles.color.ansi = wrapAnsi16(); styles.color.ansi256 = wrapAnsi256(); styles.color.ansi16m = wrapAnsi16m(); styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET); styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET); styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET); Object.defineProperties(styles, { rgbToAnsi256: { value(red, green, blue) { if (red === green && green === blue) { if (red < 8) { return 16; } if (red > 248) { return 231; } return Math.round((red - 8) / 247 * 24) + 232; } return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5); }, enumerable: false }, hexToRgb: { value(hex) { const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16)); if (!matches) { return [0, 0, 0]; } let [colorString] = matches; if (colorString.length === 3) { colorString = [...colorString].map((character) => character + character).join(""); } const integer = Number.parseInt(colorString, 16); return [ /* eslint-disable no-bitwise */ integer >> 16 & 255, integer >> 8 & 255, integer & 255 /* eslint-enable no-bitwise */ ]; }, enumerable: false }, hexToAnsi256: { value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)), enumerable: false }, ansi256ToAnsi: { value(code) { if (code < 8) { return 30 + code; } if (code < 16) { return 90 + (code - 8); } let red; let green; let blue; if (code >= 232) { red = ((code - 232) * 10 + 8) / 255; green = red; blue = red; } else { code -= 16; const remainder = code % 36; red = Math.floor(code / 36) / 5; green = Math.floor(remainder / 6) / 5; blue = remainder % 6 / 5; } const value = Math.max(red, green, blue) * 2; if (value === 0) { return 30; } let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red)); if (value === 2) { result += 60; } return result; }, enumerable: false }, rgbToAnsi: { value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)), enumerable: false }, hexToAnsi: { value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)), enumerable: false } }); return styles; } var ANSI_BACKGROUND_OFFSET, wrapAnsi16, wrapAnsi256, wrapAnsi16m, styles, modifierNames, foregroundColorNames, backgroundColorNames, colorNames, ansiStyles, ansi_styles_default; var init_ansi_styles = __esm({ "../node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/vendor/ansi-styles/index.js"() { ANSI_BACKGROUND_OFFSET = 10; wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`; wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`; wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`; styles = { modifier: { reset: [0, 0], // 21 isn't widely supported and 22 does the same thing bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], overline: [53, 55], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29] }, color: { black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], // Bright color blackBright: [90, 39], gray: [90, 39], // Alias of `blackBright` grey: [90, 39], // Alias of `blackBright` redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39] }, bgColor: { bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], // Bright color bgBlackBright: [100, 49], bgGray: [100, 49], // Alias of `bgBlackBright` bgGrey: [100, 49], // Alias of `bgBlackBright` bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49] } }; modifierNames = Object.keys(styles.modifier); foregroundColorNames = Object.keys(styles.color); backgroundColorNames = Object.keys(styles.bgColor); colorNames = [...foregroundColorNames, ...backgroundColorNames]; ansiStyles = assembleStyles(); ansi_styles_default = ansiStyles; } }); // ../node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/vendor/supports-color/index.js function hasFlag(flag, argv2 = globalThis.Deno ? globalThis.Deno.args : import_node_process.default.argv) { const prefix2 = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--"; const position = argv2.indexOf(prefix2 + flag); const terminatorPosition = argv2.indexOf("--"); return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition); } function envForceColor() { if ("FORCE_COLOR" in env) { if (env.FORCE_COLOR === "true") { return 1; } if (env.FORCE_COLOR === "false") { return 0; } return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3); } } function translateLevel(level) { if (level === 0) { return false; } return { level, hasBasic: true, has256: level >= 2, has16m: level >= 3 }; } function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) { const noFlagForceColor = envForceColor(); if (noFlagForceColor !== void 0) { flagForceColor = noFlagForceColor; } const forceColor = sniffFlags ? flagForceColor : noFlagForceColor; if (forceColor === 0) { return 0; } if (sniffFlags) { if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) { return 3; } if (hasFlag("color=256")) { return 2; } } if ("TF_BUILD" in env && "AGENT_NAME" in env) { return 1; } if (haveStream && !streamIsTTY && forceColor === void 0) { return 0; } const min = forceColor || 0; if (env.TERM === "dumb") { return min; } if (import_node_process.default.platform === "win32") { const osRelease = import_node_os.default.release().split("."); if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) { return Number(osRelease[2]) >= 14931 ? 3 : 2; } return 1; } if ("CI" in env) { if ("GITHUB_ACTIONS" in env || "GITEA_ACTIONS" in env) { return 3; } if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") { return 1; } return min; } if ("TEAMCITY_VERSION" in env) { return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0; } if (env.COLORTERM === "truecolor") { return 3; } if (env.TERM === "xterm-kitty") { return 3; } if ("TERM_PROGRAM" in env) { const version3 = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10); switch (env.TERM_PROGRAM) { case "iTerm.app": { return version3 >= 3 ? 3 : 2; } case "Apple_Terminal": { return 2; } } } if (/-256(color)?$/i.test(env.TERM)) { return 2; } if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) { return 1; } if ("COLORTERM" in env) { return 1; } return min; } function createSupportsColor(stream, options = {}) { const level = _supportsColor(stream, { streamIsTTY: stream && stream.isTTY, ...options }); return translateLevel(level); } var import_node_process, import_node_os, import_node_tty, env, flagForceColor, supportsColor, supports_color_default; var init_supports_color = __esm({ "../node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/vendor/supports-color/index.js"() { import_node_process = __toESM(require("node:process"), 1); import_node_os = __toESM(require("node:os"), 1); import_node_tty = __toESM(require("node:tty"), 1); ({ env } = import_node_process.default); if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) { flagForceColor = 0; } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) { flagForceColor = 1; } supportsColor = { stdout: createSupportsColor({ isTTY: import_node_tty.default.isatty(1) }), stderr: createSupportsColor({ isTTY: import_node_tty.default.isatty(2) }) }; supports_color_default = supportsColor; } }); // ../node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/utilities.js function stringReplaceAll(string2, substring, replacer) { let index4 = string2.indexOf(substring); if (index4 === -1) { return string2; } const substringLength = substring.length; let endIndex = 0; let returnValue = ""; do { returnValue += string2.slice(endIndex, index4) + substring + replacer; endIndex = index4 + substringLength; index4 = string2.indexOf(substring, endIndex); } while (index4 !== -1); returnValue += string2.slice(endIndex); return returnValue; } function stringEncaseCRLFWithFirstIndex(string2, prefix2, postfix, index4) { let endIndex = 0; let returnValue = ""; do { const gotCR = string2[index4 - 1] === "\r"; returnValue += string2.slice(endIndex, gotCR ? index4 - 1 : index4) + prefix2 + (gotCR ? "\r\n" : "\n") + postfix; endIndex = index4 + 1; index4 = string2.indexOf("\n", endIndex); } while (index4 !== -1); returnValue += string2.slice(endIndex); return returnValue; } var init_utilities = __esm({ "../node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/utilities.js"() { } }); // ../node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/index.js function createChalk(options) { return chalkFactory(options); } var stdoutColor, stderrColor, GENERATOR, STYLER, IS_EMPTY, levelMapping, styles2, applyOptions, chalkFactory, getModelAnsi, usedModels, proto, createStyler, createBuilder, applyStyle, chalk, chalkStderr, source_default; var init_source = __esm({ "../node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/index.js"() { init_ansi_styles(); init_supports_color(); init_utilities(); ({ stdout: stdoutColor, stderr: stderrColor } = supports_color_default); GENERATOR = Symbol("GENERATOR"); STYLER = Symbol("STYLER"); IS_EMPTY = Symbol("IS_EMPTY"); levelMapping = [ "ansi", "ansi", "ansi256", "ansi16m" ]; styles2 = /* @__PURE__ */ Object.create(null); applyOptions = (object, options = {}) => { if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) { throw new Error("The `level` option should be an integer from 0 to 3"); } const colorLevel = stdoutColor ? stdoutColor.level : 0; object.level = options.level === void 0 ? colorLevel : options.level; }; chalkFactory = (options) => { const chalk2 = (...strings) => strings.join(" "); applyOptions(chalk2, options); Object.setPrototypeOf(chalk2, createChalk.prototype); return chalk2; }; Object.setPrototypeOf(createChalk.prototype, Function.prototype); for (const [styleName, style] of Object.entries(ansi_styles_default)) { styles2[styleName] = { get() { const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]); Object.defineProperty(this, styleName, { value: builder }); return builder; } }; } styles2.visible = { get() { const builder = createBuilder(this, this[STYLER], true); Object.defineProperty(this, "visible", { value: builder }); return builder; } }; getModelAnsi = (model, level, type, ...arguments_) => { if (model === "rgb") { if (level === "ansi16m") { return ansi_styles_default[type].ansi16m(...arguments_); } if (level === "ansi256") { return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_)); } return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_)); } if (model === "hex") { return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_)); } return ansi_styles_default[type][model](...arguments_); }; usedModels = ["rgb", "hex", "ansi256"]; for (const model of usedModels) { styles2[model] = { get() { const { level } = this; return function(...arguments_) { const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]); return createBuilder(this, styler, this[IS_EMPTY]); }; } }; const bgModel = "bg" + model[0].toUpperCase() + model.slice(1); styles2[bgModel] = { get() { const { level } = this; return function(...arguments_) { const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]); return createBuilder(this, styler, this[IS_EMPTY]); }; } }; } proto = Object.defineProperties(() => { }, { ...styles2, level: { enumerable: true, get() { return this[GENERATOR].level; }, set(level) { this[GENERATOR].level = level; } } }); createStyler = (open, close, parent) => { let openAll; let closeAll; if (parent === void 0) { openAll = open; closeAll = close; } else { openAll = parent.openAll + open; closeAll = close + parent.closeAll; } return { open, close, openAll, closeAll, parent }; }; createBuilder = (self2, _styler, _isEmpty) => { const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" ")); Object.setPrototypeOf(builder, proto); builder[GENERATOR] = self2; builder[STYLER] = _styler; builder[IS_EMPTY] = _isEmpty; return builder; }; applyStyle = (self2, string2) => { if (self2.level <= 0 || !string2) { return self2[IS_EMPTY] ? "" : string2; } let styler = self2[STYLER]; if (styler === void 0) { return string2; } const { openAll, closeAll } = styler; if (string2.includes("\x1B")) { while (styler !== void 0) { string2 = stringReplaceAll(string2, styler.close, styler.open); styler = styler.parent; } } const lfIndex = string2.indexOf("\n"); if (lfIndex !== -1) { string2 = stringEncaseCRLFWithFirstIndex(string2, closeAll, openAll, lfIndex); } return openAll + string2 + closeAll; }; Object.defineProperties(createChalk.prototype, styles2); chalk = createChalk(); chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 }); source_default = chalk; } }); // ../node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/readline.js var require_readline = __commonJS({ "../node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/readline.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.prepareReadLine = void 0; var prepareReadLine = () => { const stdin = process.stdin; const stdout = process.stdout; const readline = require("readline"); const rl = readline.createInterface({ input: stdin, escapeCodeTimeout: 50 }); readline.emitKeypressEvents(stdin, rl); return { stdin, stdout, closable: rl }; }; exports2.prepareReadLine = prepareReadLine; } }); // ../node_modules/.pnpm/sisteransi@1.0.5/node_modules/sisteransi/src/index.js var require_src = __commonJS({ "../node_modules/.pnpm/sisteransi@1.0.5/node_modules/sisteransi/src/index.js"(exports2, module2) { "use strict"; var ESC = "\x1B"; var CSI = `${ESC}[`; var beep = "\x07"; var cursor = { to(x2, y) { if (!y) return `${CSI}${x2 + 1}G`; return `${CSI}${y + 1};${x2 + 1}H`; }, move(x2, y) { let ret = ""; if (x2 < 0) ret += `${CSI}${-x2}D`; else if (x2 > 0) ret += `${CSI}${x2}C`; if (y < 0) ret += `${CSI}${-y}A`; else if (y > 0) ret += `${CSI}${y}B`; return ret; }, up: (count = 1) => `${CSI}${count}A`, down: (count = 1) => `${CSI}${count}B`, forward: (count = 1) => `${CSI}${count}C`, backward: (count = 1) => `${CSI}${count}D`, nextLine: (count = 1) => `${CSI}E`.repeat(count), prevLine: (count = 1) => `${CSI}F`.repeat(count), left: `${CSI}G`, hide: `${CSI}?25l`, show: `${CSI}?25h`, save: `${ESC}7`, restore: `${ESC}8` }; var scroll = { up: (count = 1) => `${CSI}S`.repeat(count), down: (count = 1) => `${CSI}T`.repeat(count) }; var erase = { screen: `${CSI}2J`, up: (count = 1) => `${CSI}1J`.repeat(count), down: (count = 1) => `${CSI}J`.repeat(count), line: `${CSI}2K`, lineEnd: `${CSI}K`, lineStart: `${CSI}1K`, lines(count) { let clear = ""; for (let i2 = 0; i2 < count; i2++) clear += this.line + (i2 < count - 1 ? cursor.up() : ""); if (count) clear += cursor.left; return clear; } }; module2.exports = { cursor, scroll, erase, beep }; } }); // ../node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/utils.js var require_utils = __commonJS({ "../node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/utils.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.clear = void 0; var sisteransi_1 = require_src(); var strip = (str) => { const pattern = [ "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))" ].join("|"); const RGX = new RegExp(pattern, "g"); return typeof str === "string" ? str.replace(RGX, "") : str; }; var stringWidth = (str) => [...strip(str)].length; var clear = function(prompt, perLine) { if (!perLine) return sisteransi_1.erase.line + sisteransi_1.cursor.to(0); let rows = 0; const lines = prompt.split(/\r?\n/); for (let line of lines) { rows += 1 + Math.floor(Math.max(stringWidth(line) - 1, 0) / perLine); } return sisteransi_1.erase.lines(rows); }; exports2.clear = clear; } }); // ../node_modules/.pnpm/lodash.throttle@4.1.1/node_modules/lodash.throttle/index.js var require_lodash = __commonJS({ "../node_modules/.pnpm/lodash.throttle@4.1.1/node_modules/lodash.throttle/index.js"(exports2, module2) { var FUNC_ERROR_TEXT = "Expected a function"; var NAN = 0 / 0; var symbolTag = "[object Symbol]"; var reTrim = /^\s+|\s+$/g; var reIsBadHex = /^[-+]0x[0-9a-f]+$/i; var reIsBinary = /^0b[01]+$/i; var reIsOctal = /^0o[0-7]+$/i; var freeParseInt = parseInt; var freeGlobal = typeof global == "object" && global && global.Object === Object && global; var freeSelf = typeof self == "object" && self && self.Object === Object && self; var root = freeGlobal || freeSelf || Function("return this")(); var objectProto = Object.prototype; var objectToString = objectProto.toString; var nativeMax = Math.max; var nativeMin = Math.min; var now = function() { return root.Date.now(); }; function debounce(func, wait, options) { var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true; if (typeof func != "function") { throw new TypeError(FUNC_ERROR_TEXT); } wait = toNumber(wait) || 0; if (isObject(options)) { leading = !!options.leading; maxing = "maxWait" in options; maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait; trailing = "trailing" in options ? !!options.trailing : trailing; } function invokeFunc(time) { var args = lastArgs, thisArg = lastThis; lastArgs = lastThis = void 0; lastInvokeTime = time; result = func.apply(thisArg, args); return result; } function leadingEdge(time) { lastInvokeTime = time; timerId = setTimeout(timerExpired, wait); return leading ? invokeFunc(time) : result; } function remainingWait(time) { var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime, result2 = wait - timeSinceLastCall; return maxing ? nativeMin(result2, maxWait - timeSinceLastInvoke) : result2; } function shouldInvoke(time) { var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime; return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait; } function timerExpired() { var time = now(); if (shouldInvoke(time)) { return trailingEdge(time); } timerId = setTimeout(timerExpired, remainingWait(time)); } function trailingEdge(time) { timerId = void 0; if (trailing && lastArgs) { return invokeFunc(time); } lastArgs = lastThis = void 0; return result; } function cancel() { if (timerId !== void 0) { clearTimeout(timerId); } lastInvokeTime = 0; lastArgs = lastCallTime = lastThis = timerId = void 0; } function flush() { return timerId === void 0 ? result : trailingEdge(now()); } function debounced() { var time = now(), isInvoking = shouldInvoke(time); lastArgs = arguments; lastThis = this; lastCallTime = time; if (isInvoking) { if (timerId === void 0) { return leadingEdge(lastCallTime); } if (maxing) { timerId = setTimeout(timerExpired, wait); return invokeFunc(lastCallTime); } } if (timerId === void 0) { timerId = setTimeout(timerExpired, wait); } return result; } debounced.cancel = cancel; debounced.flush = flush; return debounced; } function throttle(func, wait, options) { var leading = true, trailing = true; if (typeof func != "function") { throw new TypeError(FUNC_ERROR_TEXT); } if (isObject(options)) { leading = "leading" in options ? !!options.leading : leading; trailing = "trailing" in options ? !!options.trailing : trailing; } return debounce(func, wait, { "leading": leading, "maxWait": wait, "trailing": trailing }); } function isObject(value) { var type = typeof value; return !!value && (type == "object" || type == "function"); } function isObjectLike(value) { return !!value && typeof value == "object"; } function isSymbol2(value) { return typeof value == "symbol" || isObjectLike(value) && objectToString.call(value) == symbolTag; } function toNumber(value) { if (typeof value == "number") { return value; } if (isSymbol2(value)) { return NAN; } if (isObject(value)) { var other = typeof value.valueOf == "function" ? value.valueOf() : value; value = isObject(other) ? other + "" : other; } if (typeof value != "string") { return value === 0 ? value : +value; } value = value.replace(reTrim, ""); var isBinary = reIsBinary.test(value); return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value; } module2.exports = throttle; } }); // ../node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/index.js var require_hanji = __commonJS({ "../node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/index.js"(exports2) { "use strict"; var __awaiter2 = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function(resolve2) { resolve2(value); }); } return new (P || (P = Promise))(function(resolve2, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e2) { reject(e2); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e2) { reject(e2); } } function step(result) { result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault2 = exports2 && exports2.__importDefault || function(mod) { return mod && mod.__esModule ? mod : { "default": mod }; }; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.onTerminate = exports2.renderWithTask = exports2.render = exports2.TaskTerminal = exports2.TaskView = exports2.Terminal = exports2.deferred = exports2.SelectState = exports2.Prompt = void 0; var readline_1 = require_readline(); var sisteransi_1 = require_src(); var utils_1 = require_utils(); var lodash_throttle_1 = __importDefault2(require_lodash()); var Prompt3 = class { constructor() { this.attachCallbacks = []; this.detachCallbacks = []; this.inputCallbacks = []; } requestLayout() { this.terminal.requestLayout(); } on(type, callback) { if (type === "attach") { this.attachCallbacks.push(callback); } else if (type === "detach") { this.detachCallbacks.push(callback); } else if (type === "input") { this.inputCallbacks.push(callback); } } attach(terminal) { this.terminal = terminal; this.attachCallbacks.forEach((it) => it(terminal)); } detach(terminal) { this.detachCallbacks.forEach((it) => it(terminal)); this.terminal = void 0; } input(str, key) { this.inputCallbacks.forEach((it) => it(str, key)); } }; exports2.Prompt = Prompt3; var SelectState3 = class { constructor(items) { this.items = items; this.selectedIdx = 0; } bind(prompt) { prompt.on("input", (str, key) => { const invalidate = this.consume(str, key); if (invalidate) prompt.requestLayout(); }); } consume(str, key) { if (!key) return false; if (key.name === "down") { this.selectedIdx = (this.selectedIdx + 1) % this.items.length; return true; } if (key.name === "up") { this.selectedIdx -= 1; this.selectedIdx = this.selectedIdx < 0 ? this.items.length - 1 : this.selectedIdx; return true; } return false; } }; exports2.SelectState = SelectState3; var deferred = () => { let resolve2; let reject; const promise = new Promise((res, rej) => { resolve2 = res; reject = rej; }); return { resolve: resolve2, reject, promise }; }; exports2.deferred = deferred; var Terminal = class { constructor(view, stdin, stdout, closable) { this.view = view; this.stdin = stdin; this.stdout = stdout; this.closable = closable; this.text = ""; this.status = "idle"; if (this.stdin.isTTY) this.stdin.setRawMode(true); const keypress = (str, key) => { if (key.name === "c" && key.ctrl === true) { this.requestLayout(); this.view.detach(this); this.tearDown(keypress); if (terminateHandler) { terminateHandler(this.stdin, this.stdout); return; } this.stdout.write(` ^C `); process.exit(1); } if (key.name === "escape") { this.status = "aborted"; this.requestLayout(); this.view.detach(this); this.tearDown(keypress); this.resolve({ status: "aborted", data: void 0 }); return; } if (key.name === "return") { this.status = "submitted"; this.requestLayout(); this.view.detach(this); this.tearDown(keypress); this.resolve({ status: "submitted", data: this.view.result() }); return; } view.input(str, key); }; this.stdin.on("keypress", keypress); this.view.attach(this); const { resolve: resolve2, promise } = (0, exports2.deferred)(); this.resolve = resolve2; this.promise = promise; this.renderFunc = (0, lodash_throttle_1.default)((str) => { this.stdout.write(str); }); } tearDown(keypress) { this.stdout.write(sisteransi_1.cursor.show); this.stdin.removeListener("keypress", keypress); if (this.stdin.isTTY) this.stdin.setRawMode(false); this.closable.close(); } result() { return this.promise; } toggleCursor(state) { if (state === "hide") { this.stdout.write(sisteransi_1.cursor.hide); } else { this.stdout.write(sisteransi_1.cursor.show); } } requestLayout() { const string2 = this.view.render(this.status); const clearPrefix = this.text ? (0, utils_1.clear)(this.text, this.stdout.columns) : ""; this.text = string2; this.renderFunc(`${clearPrefix}${string2}`); } }; exports2.Terminal = Terminal; var TaskView2 = class { constructor() { this.attachCallbacks = []; this.detachCallbacks = []; } requestLayout() { this.terminal.requestLayout(); } attach(terminal) { this.terminal = terminal; this.attachCallbacks.forEach((it) => it(terminal)); } detach(terminal) { this.detachCallbacks.forEach((it) => it(terminal)); this.terminal = void 0; } on(type, callback) { if (type === "attach") { this.attachCallbacks.push(callback); } else if (type === "detach") { this.detachCallbacks.push(callback); } } }; exports2.TaskView = TaskView2; var TaskTerminal = class { constructor(view, stdout) { this.view = view; this.stdout = stdout; this.text = ""; this.view.attach(this); } requestLayout() { const string2 = this.view.render("pending"); const clearPrefix = this.text ? (0, utils_1.clear)(this.text, this.stdout.columns) : ""; this.text = string2; this.stdout.write(`${clearPrefix}${string2}`); } clear() { const string2 = this.view.render("done"); this.view.detach(this); const clearPrefix = this.text ? (0, utils_1.clear)(this.text, this.stdout.columns) : ""; this.stdout.write(`${clearPrefix}${string2}`); } }; exports2.TaskTerminal = TaskTerminal; function render9(view) { const { stdin, stdout, closable } = (0, readline_1.prepareReadLine)(); if (view instanceof Prompt3) { const terminal = new Terminal(view, stdin, stdout, closable); terminal.requestLayout(); return terminal.result(); } stdout.write(`${view} `); closable.close(); return; } exports2.render = render9; function renderWithTask6(view, task) { return __awaiter2(this, void 0, void 0, function* () { const terminal = new TaskTerminal(view, process.stdout); terminal.requestLayout(); const result = yield task; terminal.clear(); return result; }); } exports2.renderWithTask = renderWithTask6; var terminateHandler; function onTerminate(callback) { terminateHandler = callback; } exports2.onTerminate = onTerminate; } }); // src/cli/views.ts var import_hanji, warning, err, info, grey, error, schema, isRenamePromptItem, ResolveColumnSelect, tableKey, ResolveSelect, ResolveSchemasSelect, Spinner, IntrospectProgress, MigrateProgress, ProgressView, DropMigrationView, trimmedRange; var init_views = __esm({ "src/cli/views.ts"() { "use strict"; init_source(); import_hanji = __toESM(require_hanji()); init_utils(); warning = (msg) => { (0, import_hanji.render)(`[${source_default.yellow("Warning")}] ${msg}`); }; err = (msg) => { (0, import_hanji.render)(`${source_default.bold.red("Error")} ${msg}`); }; info = (msg, greyMsg = "") => { return `${source_default.blue.bold("Info:")} ${msg} ${greyMsg ? source_default.grey(greyMsg) : ""}`.trim(); }; grey = (msg) => { return source_default.grey(msg); }; error = (error2, greyMsg = "") => { return `${source_default.bgRed.bold(" Error ")} ${error2} ${greyMsg ? source_default.grey(greyMsg) : ""}`.trim(); }; schema = (schema5) => { const tables = Object.values(schema5.tables); let msg = source_default.bold(`${tables.length} tables `); msg += tables.map((t2) => { const columnsCount = Object.values(t2.columns).length; const indexesCount = Object.values(t2.indexes).length; const foreignKeys = Object.values(t2.foreignKeys).length; return `${source_default.bold.blue(t2.name)} ${source_default.gray( `${columnsCount} columns ${indexesCount} indexes ${foreignKeys} fks` )}`; }).join("\n"); msg += "\n"; const enums = objectValues( "enums" in schema5 ? "values" in schema5["enums"] ? schema5["enums"] : {} : {} ); if (enums.length > 0) { msg += "\n"; msg += source_default.bold(`${enums.length} enums `); msg += enums.map((it) => { return `${source_default.bold.blue(it.name)} ${source_default.gray( `[${Object.values(it.values).join(", ")}]` )}`; }).join("\n"); msg += "\n"; } return msg; }; isRenamePromptItem = (item) => { return "from" in item && "to" in item; }; ResolveColumnSelect = class extends import_hanji.Prompt { constructor(tableName, base, data) { super(); this.tableName = tableName; this.base = base; this.on("attach", (terminal) => terminal.toggleCursor("hide")); this.data = new import_hanji.SelectState(data); this.data.bind(this); } render(status) { if (status === "submitted" || status === "aborted") { return "\n"; } let text = ` Is ${source_default.bold.blue( this.base.name )} column in ${source_default.bold.blue( this.tableName )} table created or renamed from another column? `; const isSelectedRenamed = isRenamePromptItem( this.data.items[this.data.selectedIdx] ); const selectedPrefix = isSelectedRenamed ? source_default.yellow("\u276F ") : source_default.green("\u276F "); const labelLength = this.data.items.filter((it) => isRenamePromptItem(it)).map((it) => { return this.base.name.length + 3 + it["from"].name.length; }).reduce((a, b) => { if (a > b) { return a; } return b; }, 0); this.data.items.forEach((it, idx) => { const isSelected = idx === this.data.selectedIdx; const isRenamed = isRenamePromptItem(it); const title = isRenamed ? `${it.from.name} \u203A ${it.to.name}`.padEnd(labelLength, " ") : it.name.padEnd(labelLength, " "); const label = isRenamed ? `${source_default.yellow("~")} ${title} ${source_default.gray("rename column")}` : `${source_default.green("+")} ${title} ${source_default.gray("create column")}`; text += isSelected ? `${selectedPrefix}${label}` : ` ${label}`; text += idx != this.data.items.length - 1 ? "\n" : ""; }); return text; } result() { return this.data.items[this.data.selectedIdx]; } }; tableKey = (it) => { return it.schema === "public" || !it.schema ? it.name : `${it.schema}.${it.name}`; }; ResolveSelect = class extends import_hanji.Prompt { constructor(base, data, entityType) { super(); this.base = base; this.entityType = entityType; this.on("attach", (terminal) => terminal.toggleCursor("hide")); this.state = new import_hanji.SelectState(data); this.state.bind(this); this.base = base; } render(status) { if (status === "submitted" || status === "aborted") { return ""; } const key = tableKey(this.base); let text = ` Is ${source_default.bold.blue(key)} ${this.entityType} created or renamed from another ${this.entityType}? `; const isSelectedRenamed = isRenamePromptItem( this.state.items[this.state.selectedIdx] ); const selectedPrefix = isSelectedRenamed ? source_default.yellow("\u276F ") : source_default.green("\u276F "); const labelLength = this.state.items.filter((it) => isRenamePromptItem(it)).map((_2) => { const it = _2; const keyFrom = tableKey(it.from); return key.length + 3 + keyFrom.length; }).reduce((a, b) => { if (a > b) { return a; } return b; }, 0); const entityType = this.entityType; this.state.items.forEach((it, idx) => { const isSelected = idx === this.state.selectedIdx; const isRenamed = isRenamePromptItem(it); const title = isRenamed ? `${tableKey(it.from)} \u203A ${tableKey(it.to)}`.padEnd(labelLength, " ") : tableKey(it).padEnd(labelLength, " "); const label = isRenamed ? `${source_default.yellow("~")} ${title} ${source_default.gray(`rename ${entityType}`)}` : `${source_default.green("+")} ${title} ${source_default.gray(`create ${entityType}`)}`; text += isSelected ? `${selectedPrefix}${label}` : ` ${label}`; text += idx != this.state.items.length - 1 ? "\n" : ""; }); return text; } result() { return this.state.items[this.state.selectedIdx]; } }; ResolveSchemasSelect = class extends import_hanji.Prompt { constructor(base, data) { super(); this.base = base; this.on("attach", (terminal) => terminal.toggleCursor("hide")); this.state = new import_hanji.SelectState(data); this.state.bind(this); this.base = base; } render(status) { if (status === "submitted" || status === "aborted") { return ""; } let text = ` Is ${source_default.bold.blue( this.base.name )} schema created or renamed from another schema? `; const isSelectedRenamed = isRenamePromptItem( this.state.items[this.state.selectedIdx] ); const selectedPrefix = isSelectedRenamed ? source_default.yellow("\u276F ") : source_default.green("\u276F "); const labelLength = this.state.items.filter((it) => isRenamePromptItem(it)).map((it) => { return this.base.name.length + 3 + it["from"].name.length; }).reduce((a, b) => { if (a > b) { return a; } return b; }, 0); this.state.items.forEach((it, idx) => { const isSelected = idx === this.state.selectedIdx; const isRenamed = isRenamePromptItem(it); const title = isRenamed ? `${it.from.name} \u203A ${it.to.name}`.padEnd(labelLength, " ") : it.name.padEnd(labelLength, " "); const label = isRenamed ? `${source_default.yellow("~")} ${title} ${source_default.gray("rename schema")}` : `${source_default.green("+")} ${title} ${source_default.gray("create schema")}`; text += isSelected ? `${selectedPrefix}${label}` : ` ${label}`; text += idx != this.state.items.length - 1 ? "\n" : ""; }); return text; } result() { return this.state.items[this.state.selectedIdx]; } }; Spinner = class { constructor(frames) { this.frames = frames; this.offset = 0; this.tick = () => { this.iterator(); }; this.value = () => { return this.frames[this.offset]; }; this.iterator = () => { this.offset += 1; this.offset %= frames.length - 1; }; } }; IntrospectProgress = class extends import_hanji.TaskView { constructor(hasEnums = false) { super(); this.hasEnums = hasEnums; this.spinner = new Spinner("\u28F7\u28EF\u28DF\u287F\u28BF\u28FB\u28FD\u28FE".split("")); this.state = { tables: { count: 0, name: "tables", status: "fetching" }, columns: { count: 0, name: "columns", status: "fetching" }, enums: { count: 0, name: "enums", status: "fetching" }, indexes: { count: 0, name: "indexes", status: "fetching" }, fks: { count: 0, name: "foreign keys", status: "fetching" } }; this.formatCount = (count) => { const width = Math.max.apply( null, Object.values(this.state).map((it) => it.count.toFixed(0).length) ); return count.toFixed(0).padEnd(width, " "); }; this.statusText = (spinner, stage) => { const { name, count } = stage; const isDone = stage.status === "done"; const prefix2 = isDone ? `[${source_default.green("\u2713")}]` : `[${spinner}]`; const formattedCount = this.formatCount(count); const suffix = isDone ? `${formattedCount} ${name} fetched` : `${formattedCount} ${name} fetching`; return `${prefix2} ${suffix} `; }; this.timeout = setInterval(() => { this.spinner.tick(); this.requestLayout(); }, 128); this.on("detach", () => clearInterval(this.timeout)); } update(stage, count, status) { this.state[stage].count = count; this.state[stage].status = status; this.requestLayout(); } render() { let info2 = ""; const spin = this.spinner.value(); info2 += this.statusText(spin, this.state.tables); info2 += this.statusText(spin, this.state.columns); info2 += this.hasEnums ? this.statusText(spin, this.state.enums) : ""; info2 += this.statusText(spin, this.state.indexes); info2 += this.statusText(spin, this.state.fks); return info2; } }; MigrateProgress = class extends import_hanji.TaskView { constructor() { super(); this.spinner = new Spinner("\u28F7\u28EF\u28DF\u287F\u28BF\u28FB\u28FD\u28FE".split("")); this.timeout = setInterval(() => { this.spinner.tick(); this.requestLayout(); }, 128); this.on("detach", () => clearInterval(this.timeout)); } render(status) { if (status === "pending") { const spin = this.spinner.value(); return `[${spin}] applying migrations...`; } return `[${source_default.green("\u2713")}] migrations applied successfully!`; } }; ProgressView = class extends import_hanji.TaskView { constructor(progressText, successText) { super(); this.progressText = progressText; this.successText = successText; this.spinner = new Spinner("\u28F7\u28EF\u28DF\u287F\u28BF\u28FB\u28FD\u28FE".split("")); this.timeout = setInterval(() => { this.spinner.tick(); this.requestLayout(); }, 128); this.on("detach", () => clearInterval(this.timeout)); } render(status) { if (status === "pending") { const spin = this.spinner.value(); return `[${spin}] ${this.progressText} `; } return `[${source_default.green("\u2713")}] ${this.successText} `; } }; DropMigrationView = class extends import_hanji.Prompt { constructor(data) { super(); this.on("attach", (terminal) => terminal.toggleCursor("hide")); this.data = new import_hanji.SelectState(data); this.data.selectedIdx = data.length - 1; this.data.bind(this); } render(status) { if (status === "submitted" || status === "aborted") { return "\n"; } let text = source_default.bold("Please select migration to drop:\n"); const selectedPrefix = source_default.yellow("\u276F "); const data = trimmedRange(this.data.items, this.data.selectedIdx, 9); const labelLength = data.trimmed.map((it) => it.tag.length).reduce((a, b) => { if (a > b) { return a; } return b; }, 0); text += data.startTrimmed ? " ...\n" : ""; data.trimmed.forEach((it, idx) => { const isSelected = idx === this.data.selectedIdx - data.offset; let title = it.tag.padEnd(labelLength, " "); title = isSelected ? source_default.yellow(title) : title; text += isSelected ? `${selectedPrefix}${title}` : ` ${title}`; text += idx != this.data.items.length - 1 ? "\n" : ""; }); text += data.endTrimmed ? " ...\n" : ""; return text; }