@rotorsoft/act-diagram 0.3.10 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/cli/colors.d.ts +19 -0
- package/dist/@types/cli/colors.d.ts.map +1 -0
- package/dist/@types/cli/contract-index.d.ts +57 -0
- package/dist/@types/cli/contract-index.d.ts.map +1 -0
- package/dist/@types/cli/format.d.ts +22 -0
- package/dist/@types/cli/format.d.ts.map +1 -0
- package/dist/@types/cli/index.d.ts +32 -0
- package/dist/@types/cli/index.d.ts.map +1 -0
- package/dist/@types/cli/json-schema.d.ts +13 -0
- package/dist/@types/cli/json-schema.d.ts.map +1 -0
- package/dist/@types/cli/load-project.d.ts +15 -0
- package/dist/@types/cli/load-project.d.ts.map +1 -0
- package/dist/@types/cli/markdown.d.ts +3 -0
- package/dist/@types/cli/markdown.d.ts.map +1 -0
- package/dist/@types/cli/open-editor.d.ts +23 -0
- package/dist/@types/cli/open-editor.d.ts.map +1 -0
- package/dist/@types/cli/repl.d.ts +3 -0
- package/dist/@types/cli/repl.d.ts.map +1 -0
- package/dist/@types/cli/vim-keys.d.ts +34 -0
- package/dist/@types/cli/vim-keys.d.ts.map +1 -0
- package/dist/@types/client/components/Diagram.d.ts.map +1 -1
- package/dist/@types/client/lib/build-model.d.ts.map +1 -1
- package/dist/@types/client/lib/layout.d.ts +6 -0
- package/dist/@types/client/lib/layout.d.ts.map +1 -1
- package/dist/@types/client/lib/schema-extract.d.ts +37 -0
- package/dist/@types/client/lib/schema-extract.d.ts.map +1 -0
- package/dist/@types/client/types/domain-model.d.ts +15 -0
- package/dist/@types/client/types/domain-model.d.ts.map +1 -1
- package/dist/cli/act.js +3324 -0
- package/dist/cli/act.js.map +1 -0
- package/dist/index.cjs +413 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +413 -39
- package/dist/index.js.map +1 -1
- package/dist/styles.css +2 -2
- package/package.json +13 -7
package/dist/cli/act.js
ADDED
|
@@ -0,0 +1,3324 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
#!/usr/bin/env node
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
10
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
|
|
29
|
+
// ../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js
|
|
30
|
+
var require_picocolors = __commonJS({
|
|
31
|
+
"../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js"(exports, module) {
|
|
32
|
+
"use strict";
|
|
33
|
+
var p2 = process || {};
|
|
34
|
+
var argv = p2.argv || [];
|
|
35
|
+
var env = p2.env || {};
|
|
36
|
+
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);
|
|
37
|
+
var formatter = (open, close, replace = open) => (input) => {
|
|
38
|
+
let string = "" + input, index = string.indexOf(close, open.length);
|
|
39
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
40
|
+
};
|
|
41
|
+
var replaceClose = (string, close, replace, index) => {
|
|
42
|
+
let result = "", cursor = 0;
|
|
43
|
+
do {
|
|
44
|
+
result += string.substring(cursor, index) + replace;
|
|
45
|
+
cursor = index + close.length;
|
|
46
|
+
index = string.indexOf(close, cursor);
|
|
47
|
+
} while (~index);
|
|
48
|
+
return result + string.substring(cursor);
|
|
49
|
+
};
|
|
50
|
+
var createColors = (enabled = isColorSupported) => {
|
|
51
|
+
let f2 = enabled ? formatter : () => String;
|
|
52
|
+
return {
|
|
53
|
+
isColorSupported: enabled,
|
|
54
|
+
reset: f2("\x1B[0m", "\x1B[0m"),
|
|
55
|
+
bold: f2("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
56
|
+
dim: f2("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
57
|
+
italic: f2("\x1B[3m", "\x1B[23m"),
|
|
58
|
+
underline: f2("\x1B[4m", "\x1B[24m"),
|
|
59
|
+
inverse: f2("\x1B[7m", "\x1B[27m"),
|
|
60
|
+
hidden: f2("\x1B[8m", "\x1B[28m"),
|
|
61
|
+
strikethrough: f2("\x1B[9m", "\x1B[29m"),
|
|
62
|
+
black: f2("\x1B[30m", "\x1B[39m"),
|
|
63
|
+
red: f2("\x1B[31m", "\x1B[39m"),
|
|
64
|
+
green: f2("\x1B[32m", "\x1B[39m"),
|
|
65
|
+
yellow: f2("\x1B[33m", "\x1B[39m"),
|
|
66
|
+
blue: f2("\x1B[34m", "\x1B[39m"),
|
|
67
|
+
magenta: f2("\x1B[35m", "\x1B[39m"),
|
|
68
|
+
cyan: f2("\x1B[36m", "\x1B[39m"),
|
|
69
|
+
white: f2("\x1B[37m", "\x1B[39m"),
|
|
70
|
+
gray: f2("\x1B[90m", "\x1B[39m"),
|
|
71
|
+
bgBlack: f2("\x1B[40m", "\x1B[49m"),
|
|
72
|
+
bgRed: f2("\x1B[41m", "\x1B[49m"),
|
|
73
|
+
bgGreen: f2("\x1B[42m", "\x1B[49m"),
|
|
74
|
+
bgYellow: f2("\x1B[43m", "\x1B[49m"),
|
|
75
|
+
bgBlue: f2("\x1B[44m", "\x1B[49m"),
|
|
76
|
+
bgMagenta: f2("\x1B[45m", "\x1B[49m"),
|
|
77
|
+
bgCyan: f2("\x1B[46m", "\x1B[49m"),
|
|
78
|
+
bgWhite: f2("\x1B[47m", "\x1B[49m"),
|
|
79
|
+
blackBright: f2("\x1B[90m", "\x1B[39m"),
|
|
80
|
+
redBright: f2("\x1B[91m", "\x1B[39m"),
|
|
81
|
+
greenBright: f2("\x1B[92m", "\x1B[39m"),
|
|
82
|
+
yellowBright: f2("\x1B[93m", "\x1B[39m"),
|
|
83
|
+
blueBright: f2("\x1B[94m", "\x1B[39m"),
|
|
84
|
+
magentaBright: f2("\x1B[95m", "\x1B[39m"),
|
|
85
|
+
cyanBright: f2("\x1B[96m", "\x1B[39m"),
|
|
86
|
+
whiteBright: f2("\x1B[97m", "\x1B[39m"),
|
|
87
|
+
bgBlackBright: f2("\x1B[100m", "\x1B[49m"),
|
|
88
|
+
bgRedBright: f2("\x1B[101m", "\x1B[49m"),
|
|
89
|
+
bgGreenBright: f2("\x1B[102m", "\x1B[49m"),
|
|
90
|
+
bgYellowBright: f2("\x1B[103m", "\x1B[49m"),
|
|
91
|
+
bgBlueBright: f2("\x1B[104m", "\x1B[49m"),
|
|
92
|
+
bgMagentaBright: f2("\x1B[105m", "\x1B[49m"),
|
|
93
|
+
bgCyanBright: f2("\x1B[106m", "\x1B[49m"),
|
|
94
|
+
bgWhiteBright: f2("\x1B[107m", "\x1B[49m")
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
module.exports = createColors();
|
|
98
|
+
module.exports.createColors = createColors;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// ../../node_modules/.pnpm/sisteransi@1.0.5/node_modules/sisteransi/src/index.js
|
|
103
|
+
var require_src = __commonJS({
|
|
104
|
+
"../../node_modules/.pnpm/sisteransi@1.0.5/node_modules/sisteransi/src/index.js"(exports, module) {
|
|
105
|
+
"use strict";
|
|
106
|
+
var ESC3 = "\x1B";
|
|
107
|
+
var CSI2 = `${ESC3}[`;
|
|
108
|
+
var beep = "\x07";
|
|
109
|
+
var cursor = {
|
|
110
|
+
to(x3, y) {
|
|
111
|
+
if (!y) return `${CSI2}${x3 + 1}G`;
|
|
112
|
+
return `${CSI2}${y + 1};${x3 + 1}H`;
|
|
113
|
+
},
|
|
114
|
+
move(x3, y) {
|
|
115
|
+
let ret = "";
|
|
116
|
+
if (x3 < 0) ret += `${CSI2}${-x3}D`;
|
|
117
|
+
else if (x3 > 0) ret += `${CSI2}${x3}C`;
|
|
118
|
+
if (y < 0) ret += `${CSI2}${-y}A`;
|
|
119
|
+
else if (y > 0) ret += `${CSI2}${y}B`;
|
|
120
|
+
return ret;
|
|
121
|
+
},
|
|
122
|
+
up: (count = 1) => `${CSI2}${count}A`,
|
|
123
|
+
down: (count = 1) => `${CSI2}${count}B`,
|
|
124
|
+
forward: (count = 1) => `${CSI2}${count}C`,
|
|
125
|
+
backward: (count = 1) => `${CSI2}${count}D`,
|
|
126
|
+
nextLine: (count = 1) => `${CSI2}E`.repeat(count),
|
|
127
|
+
prevLine: (count = 1) => `${CSI2}F`.repeat(count),
|
|
128
|
+
left: `${CSI2}G`,
|
|
129
|
+
hide: `${CSI2}?25l`,
|
|
130
|
+
show: `${CSI2}?25h`,
|
|
131
|
+
save: `${ESC3}7`,
|
|
132
|
+
restore: `${ESC3}8`
|
|
133
|
+
};
|
|
134
|
+
var scroll = {
|
|
135
|
+
up: (count = 1) => `${CSI2}S`.repeat(count),
|
|
136
|
+
down: (count = 1) => `${CSI2}T`.repeat(count)
|
|
137
|
+
};
|
|
138
|
+
var erase = {
|
|
139
|
+
screen: `${CSI2}2J`,
|
|
140
|
+
up: (count = 1) => `${CSI2}1J`.repeat(count),
|
|
141
|
+
down: (count = 1) => `${CSI2}J`.repeat(count),
|
|
142
|
+
line: `${CSI2}2K`,
|
|
143
|
+
lineEnd: `${CSI2}K`,
|
|
144
|
+
lineStart: `${CSI2}1K`,
|
|
145
|
+
lines(count) {
|
|
146
|
+
let clear = "";
|
|
147
|
+
for (let i = 0; i < count; i++)
|
|
148
|
+
clear += this.line + (i < count - 1 ? cursor.up() : "");
|
|
149
|
+
if (count)
|
|
150
|
+
clear += cursor.left;
|
|
151
|
+
return clear;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
module.exports = { cursor, scroll, erase, beep };
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// src/cli/index.ts
|
|
159
|
+
import { resolve as resolve4 } from "path";
|
|
160
|
+
|
|
161
|
+
// src/client/lib/evaluate.ts
|
|
162
|
+
import { transform } from "sucrase";
|
|
163
|
+
|
|
164
|
+
// src/client/lib/schema-extract.ts
|
|
165
|
+
var isWS = (c) => c === " " || c === " " || c === "\n" || c === "\r";
|
|
166
|
+
var isIdent = (c) => !!c && /[\w$]/.test(c);
|
|
167
|
+
function skipTrivia(src, from) {
|
|
168
|
+
let i = from;
|
|
169
|
+
while (i < src.length) {
|
|
170
|
+
const c = src[i];
|
|
171
|
+
if (isWS(c)) {
|
|
172
|
+
i++;
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (c === "/" && src[i + 1] === "/") {
|
|
176
|
+
while (i < src.length && src[i] !== "\n") i++;
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
if (c === "/" && src[i + 1] === "*") {
|
|
180
|
+
i += 2;
|
|
181
|
+
while (i < src.length && !(src[i - 1] === "*" && src[i] === "/")) i++;
|
|
182
|
+
i++;
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
return i;
|
|
188
|
+
}
|
|
189
|
+
function readValue(src, start) {
|
|
190
|
+
let i = start;
|
|
191
|
+
let depth = 0;
|
|
192
|
+
while (i < src.length) {
|
|
193
|
+
const c = src[i];
|
|
194
|
+
if (c === '"' || c === "'") {
|
|
195
|
+
const q2 = c;
|
|
196
|
+
i++;
|
|
197
|
+
while (i < src.length && src[i] !== q2) {
|
|
198
|
+
if (src[i] === "\\") {
|
|
199
|
+
i += 2;
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
i++;
|
|
203
|
+
}
|
|
204
|
+
i++;
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if (c === "`") {
|
|
208
|
+
i++;
|
|
209
|
+
while (i < src.length && src[i] !== "`") {
|
|
210
|
+
if (src[i] === "\\") {
|
|
211
|
+
i += 2;
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (src[i] === "$" && src[i + 1] === "{") {
|
|
215
|
+
let td = 1;
|
|
216
|
+
i += 2;
|
|
217
|
+
while (i < src.length && td > 0) {
|
|
218
|
+
if (src[i] === "{") td++;
|
|
219
|
+
else if (src[i] === "}") td--;
|
|
220
|
+
if (td > 0) i++;
|
|
221
|
+
}
|
|
222
|
+
i++;
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
i++;
|
|
226
|
+
}
|
|
227
|
+
i++;
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
if (c === "/" && src[i + 1] === "/") {
|
|
231
|
+
while (i < src.length && src[i] !== "\n") i++;
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (c === "/" && src[i + 1] === "*") {
|
|
235
|
+
i += 2;
|
|
236
|
+
while (i < src.length && !(src[i - 1] === "*" && src[i] === "/")) i++;
|
|
237
|
+
i++;
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
if (c === "(" || c === "{" || c === "[") {
|
|
241
|
+
depth++;
|
|
242
|
+
i++;
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
if (c === ")" || c === "]") {
|
|
246
|
+
depth--;
|
|
247
|
+
i++;
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
if (c === "}") {
|
|
251
|
+
if (depth === 0) return i;
|
|
252
|
+
depth--;
|
|
253
|
+
i++;
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
if (c === "," && depth === 0) return i;
|
|
257
|
+
i++;
|
|
258
|
+
}
|
|
259
|
+
return i;
|
|
260
|
+
}
|
|
261
|
+
function parseObjectLiteral(src, startBrace) {
|
|
262
|
+
const entries = [];
|
|
263
|
+
let i = startBrace + 1;
|
|
264
|
+
while (i < src.length) {
|
|
265
|
+
i = skipTrivia(src, i);
|
|
266
|
+
if (src[i] === "}") return { entries, endBrace: i };
|
|
267
|
+
let key = "";
|
|
268
|
+
let keyStart = i;
|
|
269
|
+
let keyEnd = i;
|
|
270
|
+
let keyWasIdentifier = false;
|
|
271
|
+
if (src[i] === '"' || src[i] === "'") {
|
|
272
|
+
const q2 = src[i];
|
|
273
|
+
keyStart = ++i;
|
|
274
|
+
while (i < src.length && src[i] !== q2) {
|
|
275
|
+
if (src[i] === "\\") {
|
|
276
|
+
i += 2;
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
i++;
|
|
280
|
+
}
|
|
281
|
+
key = src.slice(keyStart, i);
|
|
282
|
+
keyEnd = i;
|
|
283
|
+
i++;
|
|
284
|
+
} else if (isIdent(src[i])) {
|
|
285
|
+
keyStart = i;
|
|
286
|
+
while (isIdent(src[i])) i++;
|
|
287
|
+
key = src.slice(keyStart, i);
|
|
288
|
+
keyEnd = i;
|
|
289
|
+
keyWasIdentifier = true;
|
|
290
|
+
} else {
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
i = skipTrivia(src, i);
|
|
294
|
+
if (src[i] !== ":") {
|
|
295
|
+
if (keyWasIdentifier) {
|
|
296
|
+
entries.push({ key, valueStart: keyStart, valueEnd: keyEnd });
|
|
297
|
+
}
|
|
298
|
+
while (i < src.length && src[i] !== "," && src[i] !== "}") i++;
|
|
299
|
+
if (src[i] === ",") i++;
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
i++;
|
|
303
|
+
i = skipTrivia(src, i);
|
|
304
|
+
const valueStart = i;
|
|
305
|
+
const valueEnd = readValue(src, i);
|
|
306
|
+
entries.push({ key, valueStart, valueEnd });
|
|
307
|
+
i = valueEnd;
|
|
308
|
+
if (src[i] === ",") i++;
|
|
309
|
+
}
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
312
|
+
function readTopLevelExpression(src, start) {
|
|
313
|
+
let i = start;
|
|
314
|
+
let depth = 0;
|
|
315
|
+
while (i < src.length) {
|
|
316
|
+
const c = src[i];
|
|
317
|
+
if (c === '"' || c === "'") {
|
|
318
|
+
const q2 = c;
|
|
319
|
+
i++;
|
|
320
|
+
while (i < src.length && src[i] !== q2) {
|
|
321
|
+
if (src[i] === "\\") {
|
|
322
|
+
i += 2;
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
i++;
|
|
326
|
+
}
|
|
327
|
+
i++;
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
if (c === "`") {
|
|
331
|
+
i++;
|
|
332
|
+
while (i < src.length && src[i] !== "`") {
|
|
333
|
+
if (src[i] === "\\") {
|
|
334
|
+
i += 2;
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
if (src[i] === "$" && src[i + 1] === "{") {
|
|
338
|
+
let td = 1;
|
|
339
|
+
i += 2;
|
|
340
|
+
while (i < src.length && td > 0) {
|
|
341
|
+
if (src[i] === "{") td++;
|
|
342
|
+
else if (src[i] === "}") td--;
|
|
343
|
+
if (td > 0) i++;
|
|
344
|
+
}
|
|
345
|
+
i++;
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
i++;
|
|
349
|
+
}
|
|
350
|
+
i++;
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
if (c === "/" && src[i + 1] === "/") {
|
|
354
|
+
while (i < src.length && src[i] !== "\n") i++;
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
if (c === "/" && src[i + 1] === "*") {
|
|
358
|
+
i += 2;
|
|
359
|
+
while (i < src.length && !(src[i - 1] === "*" && src[i] === "/")) i++;
|
|
360
|
+
i++;
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
if (c === "(" || c === "{" || c === "[") {
|
|
364
|
+
depth++;
|
|
365
|
+
i++;
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
if (c === ")" || c === "}" || c === "]") {
|
|
369
|
+
depth--;
|
|
370
|
+
i++;
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
if (c === ";" && depth === 0) return i;
|
|
374
|
+
i++;
|
|
375
|
+
}
|
|
376
|
+
return i;
|
|
377
|
+
}
|
|
378
|
+
function extractIdentifierAssignments(src) {
|
|
379
|
+
const out = /* @__PURE__ */ new Map();
|
|
380
|
+
const re = /(?:^|[^\w$])(?:export\s+)?(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*(?::[^=\n;]{1,256})?=\s*/gm;
|
|
381
|
+
let m2;
|
|
382
|
+
while ((m2 = re.exec(src)) !== null) {
|
|
383
|
+
const ident = m2[1];
|
|
384
|
+
if (out.has(ident)) {
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
const start = m2.index + m2[0].length;
|
|
388
|
+
const end = readTopLevelExpression(src, start);
|
|
389
|
+
const text = src.slice(start, end).trim();
|
|
390
|
+
if (text) out.set(ident, text);
|
|
391
|
+
re.lastIndex = end;
|
|
392
|
+
}
|
|
393
|
+
return out;
|
|
394
|
+
}
|
|
395
|
+
function findIdentifierObjectLiteral(src, ident) {
|
|
396
|
+
const re = new RegExp(
|
|
397
|
+
`(?:^|[^\\w$])(?:const|let|var)\\s+${ident}\\b\\s*(?::[^=\\n;]+)?=\\s*`,
|
|
398
|
+
"m"
|
|
399
|
+
);
|
|
400
|
+
const m2 = re.exec(src);
|
|
401
|
+
if (!m2) return -1;
|
|
402
|
+
const after = m2.index + m2[0].length;
|
|
403
|
+
const skipped = skipTrivia(src, after);
|
|
404
|
+
return src[skipped] === "{" ? skipped : -1;
|
|
405
|
+
}
|
|
406
|
+
var BARE_IDENT_RE = /^[A-Za-z_$][\w$]*$/;
|
|
407
|
+
function extractSchemasFromSource(src, eventNames, external) {
|
|
408
|
+
const out = /* @__PURE__ */ new Map();
|
|
409
|
+
if (!src || eventNames.size === 0) return out;
|
|
410
|
+
const localIdents = extractIdentifierAssignments(src);
|
|
411
|
+
const deref = (text) => BARE_IDENT_RE.test(text) ? localIdents.get(text) ?? external?.get(text) ?? text : text;
|
|
412
|
+
const emitsRe = /\.emits\s*\(/g;
|
|
413
|
+
let m2;
|
|
414
|
+
while ((m2 = emitsRe.exec(src)) !== null) {
|
|
415
|
+
let i = skipTrivia(src, emitsRe.lastIndex);
|
|
416
|
+
if (isIdent(src[i])) {
|
|
417
|
+
const start = i;
|
|
418
|
+
while (isIdent(src[i])) i++;
|
|
419
|
+
const ident = src.slice(start, i);
|
|
420
|
+
const objStart = findIdentifierObjectLiteral(src, ident);
|
|
421
|
+
if (objStart < 0) continue;
|
|
422
|
+
i = objStart;
|
|
423
|
+
}
|
|
424
|
+
if (src[i] !== "{") continue;
|
|
425
|
+
const parsed = parseObjectLiteral(src, i);
|
|
426
|
+
if (!parsed) continue;
|
|
427
|
+
for (const e2 of parsed.entries) {
|
|
428
|
+
if (!eventNames.has(e2.key)) continue;
|
|
429
|
+
const raw = src.slice(e2.valueStart, e2.valueEnd).trim();
|
|
430
|
+
const text = deref(raw);
|
|
431
|
+
if (text) out.set(e2.key, text);
|
|
432
|
+
}
|
|
433
|
+
emitsRe.lastIndex = Math.max(emitsRe.lastIndex, parsed.endBrace + 1);
|
|
434
|
+
}
|
|
435
|
+
return out;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// src/client/lib/build-model.ts
|
|
439
|
+
var _stateIdx = 0;
|
|
440
|
+
function buildState(model, st2) {
|
|
441
|
+
const events = st2.events ?? {};
|
|
442
|
+
for (const [name, schema] of Object.entries(events)) {
|
|
443
|
+
if (schema === void 0)
|
|
444
|
+
return { error: `Event "${name}" has undefined schema` };
|
|
445
|
+
}
|
|
446
|
+
const rawActions = st2.actions ?? {};
|
|
447
|
+
for (const [name, schema] of Object.entries(rawActions)) {
|
|
448
|
+
if (name.startsWith("__emits_")) continue;
|
|
449
|
+
if (schema === void 0)
|
|
450
|
+
return { error: `Action "${name}" has undefined schema` };
|
|
451
|
+
}
|
|
452
|
+
const domainName = st2.name;
|
|
453
|
+
const uniqueKey = `${domainName}:${_stateIdx++}`;
|
|
454
|
+
const eventNodes = [];
|
|
455
|
+
for (const eventName of Object.keys(events)) {
|
|
456
|
+
eventNodes.push({
|
|
457
|
+
name: eventName,
|
|
458
|
+
hasCustomPatch: st2.patches?.has(eventName) ?? false,
|
|
459
|
+
// Stash the runtime Zod schema so the JSON Schema exporter can
|
|
460
|
+
// call `z.toJSONSchema(zod)` later without re-running the parser.
|
|
461
|
+
zod: events[eventName]
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
const actionNodes = [];
|
|
465
|
+
for (const actionName of Object.keys(rawActions)) {
|
|
466
|
+
if (actionName.startsWith("__emits_")) continue;
|
|
467
|
+
const emits = rawActions[`__emits_${actionName}`] ?? [];
|
|
468
|
+
const invariants = (st2.given?.[actionName] ?? []).map(
|
|
469
|
+
(inv) => inv.description ?? ""
|
|
470
|
+
);
|
|
471
|
+
actionNodes.push({ name: actionName, emits, invariants });
|
|
472
|
+
}
|
|
473
|
+
const node = {
|
|
474
|
+
name: domainName,
|
|
475
|
+
varName: uniqueKey,
|
|
476
|
+
events: eventNodes,
|
|
477
|
+
actions: actionNodes,
|
|
478
|
+
file: st2._sourceFile
|
|
479
|
+
};
|
|
480
|
+
model.states.push(node);
|
|
481
|
+
st2._modelKey = uniqueKey;
|
|
482
|
+
return { key: uniqueKey, node };
|
|
483
|
+
}
|
|
484
|
+
function fixupReactions(reactions, files, sourceFile) {
|
|
485
|
+
const fallbacks = reactions.filter((r) => r.handlerName.startsWith("on "));
|
|
486
|
+
if (fallbacks.length === 0) return;
|
|
487
|
+
const src = sourceFile ? files.find((f2) => f2.path === sourceFile)?.content : files.map((f2) => f2.content).join("\n");
|
|
488
|
+
if (!src) return;
|
|
489
|
+
const doRe = /\.on\(\s*["'`](\w+)["'`]\s*\)\s*\.do\(\s*(?:async\s+)?(?:function\s+(\w+)|(?:\w+\.)?(\w+))?/g;
|
|
490
|
+
let dm;
|
|
491
|
+
while ((dm = doRe.exec(src)) !== null) {
|
|
492
|
+
const eventName = dm[1];
|
|
493
|
+
const handlerName = dm[2] || dm[3];
|
|
494
|
+
if (!handlerName) continue;
|
|
495
|
+
const r = fallbacks.find(
|
|
496
|
+
(r2) => r2.event === eventName && r2.handlerName === `on ${eventName}`
|
|
497
|
+
);
|
|
498
|
+
if (r) r.handlerName = handlerName;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
function buildModel(result, files, expectedSlices) {
|
|
502
|
+
const rawStates = result.states.filter((s) => s && s._tag === "State");
|
|
503
|
+
const rawSlices = result.slices.filter((s) => s && s._tag === "Slice");
|
|
504
|
+
const rawProjections = result.projections.filter(
|
|
505
|
+
(p2) => p2 && p2._tag === "Projection"
|
|
506
|
+
);
|
|
507
|
+
const rawActs = result.acts.filter((a) => a && a._tag === "Act");
|
|
508
|
+
const stateByRef = /* @__PURE__ */ new Map();
|
|
509
|
+
const model = {
|
|
510
|
+
entries: [],
|
|
511
|
+
states: [],
|
|
512
|
+
slices: [],
|
|
513
|
+
projections: [],
|
|
514
|
+
reactions: []
|
|
515
|
+
};
|
|
516
|
+
for (const st2 of rawStates) {
|
|
517
|
+
if (stateByRef.has(st2)) continue;
|
|
518
|
+
try {
|
|
519
|
+
stateByRef.set(st2, buildState(model, st2));
|
|
520
|
+
} catch (e2) {
|
|
521
|
+
stateByRef.set(st2, {
|
|
522
|
+
error: e2 instanceof Error ? e2.message : String(e2)
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
for (const a of rawActs) {
|
|
527
|
+
for (const st2 of a.states ?? []) {
|
|
528
|
+
if (!st2 || st2._tag !== "State" || stateByRef.has(st2)) continue;
|
|
529
|
+
try {
|
|
530
|
+
stateByRef.set(st2, buildState(model, st2));
|
|
531
|
+
} catch (e2) {
|
|
532
|
+
stateByRef.set(st2, {
|
|
533
|
+
error: e2 instanceof Error ? e2.message : String(e2)
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
const builtSliceNames = /* @__PURE__ */ new Set();
|
|
539
|
+
for (const s of rawSlices) {
|
|
540
|
+
const sliceName = s._varName ?? "slice";
|
|
541
|
+
builtSliceNames.add(sliceName);
|
|
542
|
+
try {
|
|
543
|
+
try {
|
|
544
|
+
fixupReactions(s.reactions, files);
|
|
545
|
+
} catch {
|
|
546
|
+
}
|
|
547
|
+
const sliceStateKeys = [];
|
|
548
|
+
const errors = [];
|
|
549
|
+
for (const st2 of s.states ?? []) {
|
|
550
|
+
if (!st2 || typeof st2 !== "object") {
|
|
551
|
+
const fileErr = [...result.fileErrors.values()][0];
|
|
552
|
+
errors.push(fileErr ?? "Missing state (broken import)");
|
|
553
|
+
continue;
|
|
554
|
+
}
|
|
555
|
+
const built = stateByRef.get(st2);
|
|
556
|
+
if (built) {
|
|
557
|
+
if ("error" in built) {
|
|
558
|
+
errors.push(built.error);
|
|
559
|
+
} else {
|
|
560
|
+
sliceStateKeys.push(built.key);
|
|
561
|
+
}
|
|
562
|
+
} else {
|
|
563
|
+
try {
|
|
564
|
+
const result2 = buildState(model, st2);
|
|
565
|
+
stateByRef.set(st2, result2);
|
|
566
|
+
if ("error" in result2) {
|
|
567
|
+
errors.push(result2.error);
|
|
568
|
+
} else {
|
|
569
|
+
sliceStateKeys.push(result2.key);
|
|
570
|
+
}
|
|
571
|
+
} catch (e2) {
|
|
572
|
+
const msg = e2 instanceof Error ? e2.message : String(e2);
|
|
573
|
+
stateByRef.set(st2, { error: msg });
|
|
574
|
+
errors.push(msg);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
const projNames = [];
|
|
579
|
+
for (const p2 of s.projections ?? []) {
|
|
580
|
+
if (p2 && p2._tag === "Projection") projNames.push(p2.target);
|
|
581
|
+
}
|
|
582
|
+
const sliceFile = s._sourceFile;
|
|
583
|
+
model.slices.push({
|
|
584
|
+
name: sliceName,
|
|
585
|
+
states: sliceStateKeys,
|
|
586
|
+
stateVars: sliceStateKeys,
|
|
587
|
+
projections: projNames,
|
|
588
|
+
reactions: (s.reactions ?? []).map((r) => ({
|
|
589
|
+
...r,
|
|
590
|
+
file: r.file ?? sliceFile
|
|
591
|
+
})),
|
|
592
|
+
file: sliceFile,
|
|
593
|
+
error: errors.length > 0 ? errors.join("; ") : void 0
|
|
594
|
+
});
|
|
595
|
+
} catch (e2) {
|
|
596
|
+
const msg = e2 instanceof Error ? e2.message : String(e2);
|
|
597
|
+
model.slices.push({
|
|
598
|
+
name: sliceName,
|
|
599
|
+
states: [],
|
|
600
|
+
stateVars: [],
|
|
601
|
+
projections: [],
|
|
602
|
+
reactions: [],
|
|
603
|
+
error: msg,
|
|
604
|
+
file: s._sourceFile
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
for (const [name, filePath] of expectedSlices) {
|
|
609
|
+
if (!builtSliceNames.has(name)) {
|
|
610
|
+
model.slices.push({
|
|
611
|
+
name,
|
|
612
|
+
states: [],
|
|
613
|
+
stateVars: [],
|
|
614
|
+
projections: [],
|
|
615
|
+
reactions: [],
|
|
616
|
+
error: result.fileErrors.get(filePath) ?? result.error ?? "Failed to build slice",
|
|
617
|
+
file: filePath
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
const sourceByPath = /* @__PURE__ */ new Map();
|
|
622
|
+
const externalIdents = /* @__PURE__ */ new Map();
|
|
623
|
+
for (const f2 of files) {
|
|
624
|
+
sourceByPath.set(f2.path, f2.content);
|
|
625
|
+
for (const [ident, expr] of extractIdentifierAssignments(f2.content)) {
|
|
626
|
+
if (!externalIdents.has(ident)) externalIdents.set(ident, expr);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
for (const stNode of model.states) {
|
|
630
|
+
if (!stNode.file) continue;
|
|
631
|
+
const src = sourceByPath.get(stNode.file);
|
|
632
|
+
const names = new Set(stNode.events.map((e2) => e2.name));
|
|
633
|
+
if (names.size === 0) continue;
|
|
634
|
+
const schemas = extractSchemasFromSource(src, names, externalIdents);
|
|
635
|
+
for (const ev of stNode.events) {
|
|
636
|
+
ev.schema = schemas.get(ev.name);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
for (const p2 of rawProjections) {
|
|
640
|
+
model.projections.push({
|
|
641
|
+
name: p2.target,
|
|
642
|
+
varName: p2.target,
|
|
643
|
+
handles: p2.handles,
|
|
644
|
+
file: p2._sourceFile
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
const statesInSlices = new Set(model.slices.flatMap((s) => s.states));
|
|
648
|
+
const globalStateKeys = model.states.filter((s) => !statesInSlices.has(s.varName)).map((s) => s.varName);
|
|
649
|
+
for (const a of rawActs) {
|
|
650
|
+
try {
|
|
651
|
+
fixupReactions(
|
|
652
|
+
a.reactions ?? [],
|
|
653
|
+
files,
|
|
654
|
+
a._sourceFile
|
|
655
|
+
);
|
|
656
|
+
} catch {
|
|
657
|
+
}
|
|
658
|
+
model.orchestrator = {
|
|
659
|
+
slices: model.slices.map((s) => s.name),
|
|
660
|
+
projections: model.projections.map((p2) => p2.name),
|
|
661
|
+
states: model.states.map((s) => s.name)
|
|
662
|
+
};
|
|
663
|
+
const actFile = a._sourceFile;
|
|
664
|
+
for (const r of a.reactions ?? []) {
|
|
665
|
+
model.reactions.push({ ...r, file: r.file ?? actFile });
|
|
666
|
+
}
|
|
667
|
+
const entryPath = a._sourceFile ?? "app.ts";
|
|
668
|
+
const actSliceNames = new Set(
|
|
669
|
+
(a.slices ?? []).filter((s) => s != null).map((s) => s._varName ?? "").filter(Boolean)
|
|
670
|
+
);
|
|
671
|
+
for (const sl of model.slices) {
|
|
672
|
+
if (sl.error && !actSliceNames.has(sl.name)) {
|
|
673
|
+
const actSrc = files.find((f2) => f2.path === entryPath)?.content ?? "";
|
|
674
|
+
if (actSrc.includes(sl.name)) {
|
|
675
|
+
actSliceNames.add(sl.name);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
const entrySlices = model.slices.filter((s) => actSliceNames.has(s.name));
|
|
680
|
+
const sliceStateKeys = new Set(entrySlices.flatMap((s) => s.states));
|
|
681
|
+
const actStateKeys = /* @__PURE__ */ new Set();
|
|
682
|
+
for (const s of a.states ?? []) {
|
|
683
|
+
try {
|
|
684
|
+
if (s && s._tag === "State") {
|
|
685
|
+
actStateKeys.add(s._modelKey ?? s.name);
|
|
686
|
+
}
|
|
687
|
+
} catch {
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
const allStateKeys = /* @__PURE__ */ new Set([...actStateKeys, ...sliceStateKeys]);
|
|
691
|
+
const actProjNames = new Set(
|
|
692
|
+
(a.projections ?? []).filter((p2) => p2 && p2._tag === "Projection").map((p2) => p2.target)
|
|
693
|
+
);
|
|
694
|
+
for (const sl of entrySlices) {
|
|
695
|
+
for (const pn of sl.projections) actProjNames.add(pn);
|
|
696
|
+
}
|
|
697
|
+
model.entries.push({
|
|
698
|
+
path: entryPath,
|
|
699
|
+
states: model.states.filter((s) => allStateKeys.has(s.varName)),
|
|
700
|
+
slices: entrySlices,
|
|
701
|
+
projections: model.projections.filter((p2) => actProjNames.has(p2.name)),
|
|
702
|
+
reactions: a.reactions ?? []
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
if (globalStateKeys.length > 0 || model.reactions.length > 0) {
|
|
706
|
+
model.slices.push({
|
|
707
|
+
name: "global",
|
|
708
|
+
states: globalStateKeys,
|
|
709
|
+
stateVars: globalStateKeys,
|
|
710
|
+
projections: model.projections.map((p2) => p2.name),
|
|
711
|
+
reactions: model.reactions
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
if (model.entries.length === 0 && (model.states.length > 0 || model.slices.length > 0)) {
|
|
715
|
+
model.entries.push({
|
|
716
|
+
path: "app",
|
|
717
|
+
states: model.states,
|
|
718
|
+
slices: model.slices,
|
|
719
|
+
projections: model.projections,
|
|
720
|
+
reactions: model.reactions
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
if (result.error && model.states.length === 0 && model.slices.length === 0) {
|
|
724
|
+
return { model, error: result.error };
|
|
725
|
+
}
|
|
726
|
+
return { model };
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// src/client/lib/mock-builders.ts
|
|
730
|
+
import { z } from "zod";
|
|
731
|
+
function proxyTarget() {
|
|
732
|
+
}
|
|
733
|
+
function attachEmit(info, actionName, handler) {
|
|
734
|
+
const emits = [];
|
|
735
|
+
if (typeof handler === "string") {
|
|
736
|
+
emits.push(handler);
|
|
737
|
+
} else if (typeof handler === "function") {
|
|
738
|
+
const src = String(handler);
|
|
739
|
+
for (const eventName of Object.keys(info.events)) {
|
|
740
|
+
if (src.includes(`"${eventName}"`) || src.includes(`'${eventName}'`) || src.includes(`\`${eventName}\``)) {
|
|
741
|
+
emits.push(eventName);
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
if (emits.length === 0) {
|
|
745
|
+
try {
|
|
746
|
+
const deepProxy = new Proxy(
|
|
747
|
+
{},
|
|
748
|
+
{
|
|
749
|
+
get: () => deepProxy,
|
|
750
|
+
has: () => true
|
|
751
|
+
}
|
|
752
|
+
);
|
|
753
|
+
const proxyFn = new Proxy(proxyTarget, {
|
|
754
|
+
get: () => deepProxy,
|
|
755
|
+
apply: () => deepProxy
|
|
756
|
+
});
|
|
757
|
+
const dummyArg = new Proxy(
|
|
758
|
+
{},
|
|
759
|
+
{
|
|
760
|
+
get: (_t2, prop) => {
|
|
761
|
+
if (typeof prop === "string") return proxyFn;
|
|
762
|
+
return void 0;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
);
|
|
766
|
+
const result = handler(dummyArg, dummyArg, dummyArg);
|
|
767
|
+
if (Array.isArray(result) && typeof result[0] === "string") {
|
|
768
|
+
emits.push(result[0]);
|
|
769
|
+
}
|
|
770
|
+
} catch {
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
info.actions[`__emits_${actionName}`] = emits;
|
|
775
|
+
}
|
|
776
|
+
function mockState(entry, onBuild) {
|
|
777
|
+
const name = Object.keys(entry)[0];
|
|
778
|
+
const info = {
|
|
779
|
+
name,
|
|
780
|
+
events: {},
|
|
781
|
+
actions: {},
|
|
782
|
+
given: {},
|
|
783
|
+
patches: /* @__PURE__ */ new Set(),
|
|
784
|
+
_tag: "State"
|
|
785
|
+
};
|
|
786
|
+
const actionBuilder = (_currentAction) => ({
|
|
787
|
+
on(actionEntry) {
|
|
788
|
+
const actionName = Object.keys(actionEntry)[0];
|
|
789
|
+
info.actions[actionName] = actionEntry[actionName];
|
|
790
|
+
return {
|
|
791
|
+
given(rules) {
|
|
792
|
+
if (rules) info.given[actionName] = rules;
|
|
793
|
+
return {
|
|
794
|
+
emit(handler) {
|
|
795
|
+
attachEmit(info, actionName, handler);
|
|
796
|
+
return actionBuilder(actionName);
|
|
797
|
+
}
|
|
798
|
+
};
|
|
799
|
+
},
|
|
800
|
+
emit(handler) {
|
|
801
|
+
attachEmit(info, actionName, handler);
|
|
802
|
+
return actionBuilder(actionName);
|
|
803
|
+
}
|
|
804
|
+
};
|
|
805
|
+
},
|
|
806
|
+
snap: () => actionBuilder(_currentAction),
|
|
807
|
+
build: () => {
|
|
808
|
+
onBuild?.(info);
|
|
809
|
+
return info;
|
|
810
|
+
}
|
|
811
|
+
});
|
|
812
|
+
return {
|
|
813
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
814
|
+
init: (_initFn) => ({
|
|
815
|
+
emits(events) {
|
|
816
|
+
info.events = events ?? {};
|
|
817
|
+
return {
|
|
818
|
+
...actionBuilder(),
|
|
819
|
+
patch(patches) {
|
|
820
|
+
if (patches)
|
|
821
|
+
for (const k2 of Object.keys(patches)) info.patches.add(k2);
|
|
822
|
+
return actionBuilder();
|
|
823
|
+
}
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
})
|
|
827
|
+
};
|
|
828
|
+
}
|
|
829
|
+
function captureDispatches(handler) {
|
|
830
|
+
const dispatches = [];
|
|
831
|
+
if (typeof handler !== "function") return dispatches;
|
|
832
|
+
try {
|
|
833
|
+
const safeProxy = () => new Proxy({}, { get: () => "" });
|
|
834
|
+
const mockApp = {
|
|
835
|
+
do: (actionName) => {
|
|
836
|
+
if (typeof actionName === "string" && !dispatches.includes(actionName))
|
|
837
|
+
dispatches.push(actionName);
|
|
838
|
+
return Promise.resolve([]);
|
|
839
|
+
},
|
|
840
|
+
load: () => Promise.resolve({ state: safeProxy(), version: 0 }),
|
|
841
|
+
query: () => Promise.resolve({ count: 0 }),
|
|
842
|
+
query_array: () => Promise.resolve([])
|
|
843
|
+
};
|
|
844
|
+
const mockEvent = new Proxy({}, {
|
|
845
|
+
get: (_, prop) => prop === "stream" ? "mock" : prop === "data" ? new Proxy({}, { get: () => "" }) : ""
|
|
846
|
+
});
|
|
847
|
+
const result = handler(mockEvent, "mock", mockApp);
|
|
848
|
+
if (result && typeof result.catch === "function") {
|
|
849
|
+
result.catch(() => {
|
|
850
|
+
});
|
|
851
|
+
}
|
|
852
|
+
} catch {
|
|
853
|
+
}
|
|
854
|
+
if (dispatches.length === 0) {
|
|
855
|
+
const src = String(handler);
|
|
856
|
+
const re = /\.do\(\s*["'](\w+)["']/g;
|
|
857
|
+
let m2;
|
|
858
|
+
while ((m2 = re.exec(src)) !== null) {
|
|
859
|
+
if (!dispatches.includes(m2[1])) dispatches.push(m2[1]);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
return dispatches;
|
|
863
|
+
}
|
|
864
|
+
function mockSlice(onBuild) {
|
|
865
|
+
const info = {
|
|
866
|
+
_tag: "Slice",
|
|
867
|
+
states: [],
|
|
868
|
+
projections: [],
|
|
869
|
+
reactions: []
|
|
870
|
+
};
|
|
871
|
+
const builder = {
|
|
872
|
+
withState(s) {
|
|
873
|
+
info.states.push(s ?? null);
|
|
874
|
+
return builder;
|
|
875
|
+
},
|
|
876
|
+
withProjection(p2) {
|
|
877
|
+
if (p2) info.projections.push(p2);
|
|
878
|
+
return builder;
|
|
879
|
+
},
|
|
880
|
+
on(eventName) {
|
|
881
|
+
return {
|
|
882
|
+
do(handler) {
|
|
883
|
+
const dispatches = captureDispatches(handler);
|
|
884
|
+
const reaction = {
|
|
885
|
+
event: eventName,
|
|
886
|
+
handlerName: typeof handler?.name === "string" && handler.name || `on ${eventName}`,
|
|
887
|
+
dispatches
|
|
888
|
+
};
|
|
889
|
+
info.reactions.push(reaction);
|
|
890
|
+
return {
|
|
891
|
+
...builder,
|
|
892
|
+
to() {
|
|
893
|
+
return builder;
|
|
894
|
+
}
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
},
|
|
899
|
+
build: () => {
|
|
900
|
+
onBuild?.(info);
|
|
901
|
+
return info;
|
|
902
|
+
}
|
|
903
|
+
};
|
|
904
|
+
return builder;
|
|
905
|
+
}
|
|
906
|
+
function mockProjection(target, onBuild) {
|
|
907
|
+
const info = {
|
|
908
|
+
_tag: "Projection",
|
|
909
|
+
target: target || "projection",
|
|
910
|
+
handles: []
|
|
911
|
+
};
|
|
912
|
+
const builder = {
|
|
913
|
+
on(eventEntry) {
|
|
914
|
+
const eventName = Object.keys(eventEntry)[0];
|
|
915
|
+
info.handles.push(eventName);
|
|
916
|
+
return {
|
|
917
|
+
do() {
|
|
918
|
+
return {
|
|
919
|
+
...builder,
|
|
920
|
+
to(resolver) {
|
|
921
|
+
if (typeof resolver === "string") info.target = resolver;
|
|
922
|
+
return builder;
|
|
923
|
+
}
|
|
924
|
+
};
|
|
925
|
+
}
|
|
926
|
+
};
|
|
927
|
+
},
|
|
928
|
+
build: () => {
|
|
929
|
+
onBuild?.(info);
|
|
930
|
+
return info;
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
return builder;
|
|
934
|
+
}
|
|
935
|
+
function mockAct(onBuild) {
|
|
936
|
+
const info = {
|
|
937
|
+
_tag: "Act",
|
|
938
|
+
states: [],
|
|
939
|
+
slices: [],
|
|
940
|
+
projections: [],
|
|
941
|
+
reactions: []
|
|
942
|
+
};
|
|
943
|
+
const builder = {
|
|
944
|
+
withState(s) {
|
|
945
|
+
info.states.push(s ?? null);
|
|
946
|
+
return builder;
|
|
947
|
+
},
|
|
948
|
+
withSlice(s) {
|
|
949
|
+
info.slices.push(s ?? null);
|
|
950
|
+
return builder;
|
|
951
|
+
},
|
|
952
|
+
withProjection(p2) {
|
|
953
|
+
if (p2) info.projections.push(p2);
|
|
954
|
+
return builder;
|
|
955
|
+
},
|
|
956
|
+
withActor: () => builder,
|
|
957
|
+
on(eventName) {
|
|
958
|
+
return {
|
|
959
|
+
do(handler) {
|
|
960
|
+
const dispatches = captureDispatches(handler);
|
|
961
|
+
const reaction = {
|
|
962
|
+
event: eventName,
|
|
963
|
+
handlerName: typeof handler?.name === "string" && handler.name || `on ${eventName}`,
|
|
964
|
+
dispatches
|
|
965
|
+
};
|
|
966
|
+
info.reactions.push(reaction);
|
|
967
|
+
return {
|
|
968
|
+
...builder,
|
|
969
|
+
to() {
|
|
970
|
+
return builder;
|
|
971
|
+
}
|
|
972
|
+
};
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
},
|
|
976
|
+
build: () => {
|
|
977
|
+
const noop = () => actStub;
|
|
978
|
+
const actStub = {
|
|
979
|
+
...info,
|
|
980
|
+
on: () => actStub,
|
|
981
|
+
do: () => Promise.resolve([]),
|
|
982
|
+
load: () => Promise.resolve({}),
|
|
983
|
+
drain: () => Promise.resolve(),
|
|
984
|
+
correlate: () => Promise.resolve({ subscribed: 0, last_id: 0 }),
|
|
985
|
+
settle: noop,
|
|
986
|
+
start_correlations: noop,
|
|
987
|
+
query_array: () => Promise.resolve([])
|
|
988
|
+
};
|
|
989
|
+
onBuild?.(actStub);
|
|
990
|
+
return actStub;
|
|
991
|
+
}
|
|
992
|
+
};
|
|
993
|
+
return builder;
|
|
994
|
+
}
|
|
995
|
+
var InvariantError = class extends Error {
|
|
996
|
+
constructor(message) {
|
|
997
|
+
super(message);
|
|
998
|
+
this.name = "InvariantError";
|
|
999
|
+
}
|
|
1000
|
+
};
|
|
1001
|
+
var cryptoMock = { randomUUID: () => "mock-uuid" };
|
|
1002
|
+
var MODULES = {
|
|
1003
|
+
"@rotorsoft/act": {
|
|
1004
|
+
state: mockState,
|
|
1005
|
+
slice: mockSlice,
|
|
1006
|
+
projection: mockProjection,
|
|
1007
|
+
act: mockAct,
|
|
1008
|
+
store: () => ({
|
|
1009
|
+
seed: () => Promise.resolve(),
|
|
1010
|
+
drop: () => Promise.resolve(),
|
|
1011
|
+
commit: () => Promise.resolve([]),
|
|
1012
|
+
query: () => Promise.resolve(0),
|
|
1013
|
+
dispose: () => Promise.resolve()
|
|
1014
|
+
}),
|
|
1015
|
+
dispose: () => () => Promise.resolve(),
|
|
1016
|
+
ZodEmpty: z.record(z.string(), z.never()),
|
|
1017
|
+
InvariantError
|
|
1018
|
+
},
|
|
1019
|
+
zod: { z, ...z },
|
|
1020
|
+
crypto: cryptoMock,
|
|
1021
|
+
"node:crypto": cryptoMock
|
|
1022
|
+
};
|
|
1023
|
+
function unknownModuleProxy() {
|
|
1024
|
+
const handler = {
|
|
1025
|
+
get(_target, prop) {
|
|
1026
|
+
if (prop === Symbol.toPrimitive) return () => "";
|
|
1027
|
+
if (prop === "default") return proxy;
|
|
1028
|
+
return proxy;
|
|
1029
|
+
},
|
|
1030
|
+
apply() {
|
|
1031
|
+
return proxy;
|
|
1032
|
+
},
|
|
1033
|
+
construct() {
|
|
1034
|
+
return proxy;
|
|
1035
|
+
},
|
|
1036
|
+
has() {
|
|
1037
|
+
return true;
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
const proxy = new Proxy(proxyTarget, handler);
|
|
1041
|
+
return proxy;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
// src/client/lib/sort.ts
|
|
1045
|
+
function topoSort(tsFiles) {
|
|
1046
|
+
if (tsFiles.length <= 1) return tsFiles;
|
|
1047
|
+
const strip = (p2) => p2.replace(/\.tsx?$/, "");
|
|
1048
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
1049
|
+
for (const f2 of tsFiles) {
|
|
1050
|
+
byKey.set(strip(f2.path), f2);
|
|
1051
|
+
}
|
|
1052
|
+
const deps = /* @__PURE__ */ new Map();
|
|
1053
|
+
for (const f2 of tsFiles) {
|
|
1054
|
+
const key = strip(f2.path);
|
|
1055
|
+
const fileDeps = /* @__PURE__ */ new Set();
|
|
1056
|
+
deps.set(key, fileDeps);
|
|
1057
|
+
const fromRe = /from\s+["']([^"']+)["']/g;
|
|
1058
|
+
let m2;
|
|
1059
|
+
while ((m2 = fromRe.exec(f2.content)) !== null) {
|
|
1060
|
+
const imp = m2[1];
|
|
1061
|
+
const resolved = resolve(imp, key, byKey);
|
|
1062
|
+
if (resolved && byKey.has(resolved)) fileDeps.add(resolved);
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
const inDegree = /* @__PURE__ */ new Map();
|
|
1066
|
+
for (const f2 of tsFiles) inDegree.set(strip(f2.path), 0);
|
|
1067
|
+
for (const [, fileDeps] of deps) {
|
|
1068
|
+
for (const dep of fileDeps) {
|
|
1069
|
+
inDegree.set(dep, inDegree.get(dep) + 1);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
const queue = [];
|
|
1073
|
+
for (const [key, _deg] of inDegree) {
|
|
1074
|
+
if (deps.get(key)?.size === 0) queue.push(key);
|
|
1075
|
+
}
|
|
1076
|
+
const order = [];
|
|
1077
|
+
while (queue.length > 0) {
|
|
1078
|
+
const key = queue.shift();
|
|
1079
|
+
order.push(key);
|
|
1080
|
+
for (const [other, fileDeps] of deps) {
|
|
1081
|
+
if (fileDeps.has(key)) {
|
|
1082
|
+
fileDeps.delete(key);
|
|
1083
|
+
if (fileDeps.size === 0) queue.push(other);
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
for (const f2 of tsFiles) {
|
|
1088
|
+
const key = strip(f2.path);
|
|
1089
|
+
if (!order.includes(key)) order.push(key);
|
|
1090
|
+
}
|
|
1091
|
+
return order.map((k2) => byKey.get(k2)).filter(Boolean);
|
|
1092
|
+
}
|
|
1093
|
+
function resolve(imp, fromPath, byKey) {
|
|
1094
|
+
if (imp.startsWith(".")) {
|
|
1095
|
+
const dir = fromPath.includes("/") ? fromPath.slice(0, fromPath.lastIndexOf("/")) : "";
|
|
1096
|
+
const parts = (dir ? dir + "/" + imp : imp).split("/");
|
|
1097
|
+
const resolved = [];
|
|
1098
|
+
for (const p2 of parts) {
|
|
1099
|
+
if (p2 === "." || p2 === "") continue;
|
|
1100
|
+
if (p2 === "..") resolved.pop();
|
|
1101
|
+
else resolved.push(p2);
|
|
1102
|
+
}
|
|
1103
|
+
return resolved.join("/").replace(/\.js$/, "").replace(/\.ts$/, "");
|
|
1104
|
+
}
|
|
1105
|
+
if (imp.startsWith("@") && !imp.startsWith("@rotorsoft/")) {
|
|
1106
|
+
const pkgName = imp.split("/")[1];
|
|
1107
|
+
if (pkgName) {
|
|
1108
|
+
for (const candidate of [
|
|
1109
|
+
`packages/${pkgName}/src/index`,
|
|
1110
|
+
`${pkgName}/src/index`,
|
|
1111
|
+
`${pkgName}/index`
|
|
1112
|
+
]) {
|
|
1113
|
+
if (byKey?.has(candidate)) return candidate;
|
|
1114
|
+
}
|
|
1115
|
+
return `packages/${pkgName}/src/index`;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
return void 0;
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
// src/client/lib/evaluate.ts
|
|
1122
|
+
var stripNonCode = (src, level = "full") => {
|
|
1123
|
+
const blank = (m2) => m2.replace(/[^\n]/g, " ");
|
|
1124
|
+
let result = src.replace(/\/\/[^\n]*/g, blank).replace(/\/\*[\s\S]*?\*\//g, blank).replace(/`(?:\\[\s\S]|[^`\\])*`/g, blank);
|
|
1125
|
+
if (level === "full") {
|
|
1126
|
+
result = result.replace(/"(?:\\[\s\S]|[^"\\])*"/g, blank).replace(/'(?:\\[\s\S]|[^'\\])*'/g, blank);
|
|
1127
|
+
}
|
|
1128
|
+
return result;
|
|
1129
|
+
};
|
|
1130
|
+
var isSourceFile = (f2) => f2.path.endsWith(".ts") && !f2.path.endsWith(".d.ts") && !f2.path.endsWith(".tsx") && !f2.path.endsWith(".spec.ts") && !f2.path.endsWith(".test.ts") && !f2.path.includes("node_modules/") && !f2.path.includes("__tests__/") && !f2.path.includes("/test/") && !f2.path.startsWith("test/");
|
|
1131
|
+
function transpile(code) {
|
|
1132
|
+
try {
|
|
1133
|
+
const safe = code.replace(/\bimport\.meta\.\w+/g, "'__import_meta__'");
|
|
1134
|
+
const { code: js } = transform(safe, {
|
|
1135
|
+
transforms: ["typescript", "imports"]
|
|
1136
|
+
});
|
|
1137
|
+
return js.replace(
|
|
1138
|
+
/^(?:void\s+|await\s+)?(?:main|run|start|bootstrap|seed)\s*\([^)]*\)(?:\s*\.catch\([^)]*\))?;?\s*$/gm,
|
|
1139
|
+
"/* stripped runtime call */"
|
|
1140
|
+
);
|
|
1141
|
+
} catch {
|
|
1142
|
+
return code;
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
function execute(files) {
|
|
1146
|
+
const result = {
|
|
1147
|
+
states: [],
|
|
1148
|
+
slices: [],
|
|
1149
|
+
projections: [],
|
|
1150
|
+
acts: [],
|
|
1151
|
+
error: void 0,
|
|
1152
|
+
fileErrors: /* @__PURE__ */ new Map(),
|
|
1153
|
+
expectedSlices: /* @__PURE__ */ new Map()
|
|
1154
|
+
};
|
|
1155
|
+
try {
|
|
1156
|
+
const __built__ = {
|
|
1157
|
+
states: [],
|
|
1158
|
+
slices: [],
|
|
1159
|
+
projections: [],
|
|
1160
|
+
acts: []
|
|
1161
|
+
};
|
|
1162
|
+
let _currentFile = "";
|
|
1163
|
+
const capture = (type) => (info) => {
|
|
1164
|
+
info._sourceFile = _currentFile;
|
|
1165
|
+
__built__[type + "s"].push(info);
|
|
1166
|
+
};
|
|
1167
|
+
const actModule = { ...MODULES["@rotorsoft/act"] };
|
|
1168
|
+
actModule.state = (entry) => MODULES["@rotorsoft/act"].state(entry, capture("state"));
|
|
1169
|
+
actModule.slice = () => MODULES["@rotorsoft/act"].slice(capture("slice"));
|
|
1170
|
+
actModule.projection = (target) => MODULES["@rotorsoft/act"].projection(
|
|
1171
|
+
target,
|
|
1172
|
+
capture("projection")
|
|
1173
|
+
);
|
|
1174
|
+
actModule.act = () => MODULES["@rotorsoft/act"].act(capture("act"));
|
|
1175
|
+
const pkgModules = {
|
|
1176
|
+
...MODULES,
|
|
1177
|
+
"@rotorsoft/act": actModule
|
|
1178
|
+
};
|
|
1179
|
+
const fileExports = /* @__PURE__ */ new Map();
|
|
1180
|
+
const strip = (p2) => p2.replace(/\.tsx?$/, "");
|
|
1181
|
+
const resolveModule = (mod, fromPath) => {
|
|
1182
|
+
if (pkgModules[mod]) return pkgModules[mod];
|
|
1183
|
+
if (mod.startsWith(".")) {
|
|
1184
|
+
const dir = fromPath.includes("/") ? fromPath.slice(0, fromPath.lastIndexOf("/")) : "";
|
|
1185
|
+
const parts = (dir ? dir + "/" + mod : mod).split("/");
|
|
1186
|
+
const resolved = [];
|
|
1187
|
+
for (const p2 of parts) {
|
|
1188
|
+
if (p2 === "." || p2 === "") continue;
|
|
1189
|
+
if (p2 === "..") resolved.pop();
|
|
1190
|
+
else resolved.push(p2);
|
|
1191
|
+
}
|
|
1192
|
+
const rp = resolved.join("/").replace(/\.js$/, "").replace(/\.ts$/, "");
|
|
1193
|
+
return fileExports.get(rp) ?? fileExports.get(rp + "/index") ?? {};
|
|
1194
|
+
}
|
|
1195
|
+
if (mod.startsWith("@") && !mod.startsWith("@rotorsoft/")) {
|
|
1196
|
+
const pkgName = mod.split("/")[1];
|
|
1197
|
+
const subPath = mod.split("/").slice(2).join("/");
|
|
1198
|
+
if (pkgName) {
|
|
1199
|
+
const suffix = subPath ? `/${subPath.replace(/\.js$/, "")}` : "/src/index";
|
|
1200
|
+
return fileExports.get(`packages/${pkgName}${suffix}`) ?? fileExports.get(`${pkgName}${suffix}`) ?? fileExports.get(`packages/${pkgName}/src/index`) ?? fileExports.get(`${pkgName}/src/index`) ?? fileExports.get(`${pkgName}/index`) ?? fileExports.get(pkgName) ?? unknownModuleProxy();
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
return unknownModuleProxy();
|
|
1204
|
+
};
|
|
1205
|
+
const sorted = topoSort(files.filter(isSourceFile));
|
|
1206
|
+
for (const file of sorted) {
|
|
1207
|
+
_currentFile = file.path;
|
|
1208
|
+
const js = transpile(file.content);
|
|
1209
|
+
const key = strip(file.path);
|
|
1210
|
+
const fileExp = {};
|
|
1211
|
+
fileExports.set(key, fileExp);
|
|
1212
|
+
const sliceNamesInAct = [];
|
|
1213
|
+
const wsRe = /\.withSlice\(\s*(?:\w+\.)*(\w+)\s*\)/g;
|
|
1214
|
+
let wsm;
|
|
1215
|
+
const codeOnly = stripNonCode(js);
|
|
1216
|
+
while ((wsm = wsRe.exec(codeOnly)) !== null) {
|
|
1217
|
+
if (!sliceNamesInAct.includes(wsm[1])) sliceNamesInAct.push(wsm[1]);
|
|
1218
|
+
}
|
|
1219
|
+
for (const m2 of codeOnly.matchAll(
|
|
1220
|
+
/(?:exports\.)?(\w+)\s*=\s*(?:\w+\.)?slice(?:\s*\(\s*\)|\.call\(void 0,\s*\))/g
|
|
1221
|
+
)) {
|
|
1222
|
+
result.expectedSlices.set(m2[1], file.path);
|
|
1223
|
+
}
|
|
1224
|
+
const fileRequire = Object.assign(
|
|
1225
|
+
(mod) => resolveModule(mod, key),
|
|
1226
|
+
{ resolve: (mod) => mod, cache: {}, main: void 0 }
|
|
1227
|
+
);
|
|
1228
|
+
try {
|
|
1229
|
+
const cleanJs = js.replace(/\bconst\s+__dirname\b/g, "var __dirname").replace(/\bconst\s+__filename\b/g, "var __filename");
|
|
1230
|
+
const fn = new Function(
|
|
1231
|
+
// lgtm[js/code-injection]
|
|
1232
|
+
"require",
|
|
1233
|
+
"exports",
|
|
1234
|
+
"module",
|
|
1235
|
+
`
|
|
1236
|
+
"use strict";
|
|
1237
|
+
var __filename = ${JSON.stringify(file.path)};
|
|
1238
|
+
var __dirname = ".";
|
|
1239
|
+
var process = { env: {}, cwd: function() { return "/"; }, exit: function() {}, on: function() {}, off: function() {} };
|
|
1240
|
+
var Buffer = { from: function() { return ""; } };
|
|
1241
|
+
var console = { log: function() {}, error: function() {}, warn: function() {}, info: function() {}, debug: function() {} };
|
|
1242
|
+
${cleanJs}
|
|
1243
|
+
`
|
|
1244
|
+
);
|
|
1245
|
+
fn(fileRequire, fileExp, { exports: fileExp });
|
|
1246
|
+
} catch (evalErr) {
|
|
1247
|
+
const errMsg = evalErr instanceof Error ? evalErr.message : String(evalErr);
|
|
1248
|
+
result.fileErrors.set(file.path, errMsg);
|
|
1249
|
+
}
|
|
1250
|
+
if (sliceNamesInAct.length > 0) {
|
|
1251
|
+
for (const actObj of __built__.acts) {
|
|
1252
|
+
if (actObj._sourceFile !== file.path) continue;
|
|
1253
|
+
const actSlices = actObj.slices;
|
|
1254
|
+
for (let ai = 0; ai < Math.min(sliceNamesInAct.length, actSlices.length); ai++) {
|
|
1255
|
+
if (actSlices[ai]) {
|
|
1256
|
+
actSlices[ai]._varName = sliceNamesInAct[ai];
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
result.states = __built__.states;
|
|
1263
|
+
result.slices = __built__.slices;
|
|
1264
|
+
result.projections = __built__.projections;
|
|
1265
|
+
result.acts = __built__.acts;
|
|
1266
|
+
} catch (e2) {
|
|
1267
|
+
result.error = e2 instanceof Error ? e2.message : String(e2);
|
|
1268
|
+
}
|
|
1269
|
+
return result;
|
|
1270
|
+
}
|
|
1271
|
+
function extractModel(files) {
|
|
1272
|
+
const result = execute(files);
|
|
1273
|
+
return buildModel(result, files, result.expectedSlices);
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
// src/cli/contract-index.ts
|
|
1277
|
+
function decomposeEventName(name) {
|
|
1278
|
+
const m2 = name.match(/^(.+)_v(\d+)$/);
|
|
1279
|
+
if (m2) return { base: m2[1], version: Number.parseInt(m2[2], 10) };
|
|
1280
|
+
return { base: name, version: 1 };
|
|
1281
|
+
}
|
|
1282
|
+
function eventStatus(name, allNames) {
|
|
1283
|
+
const me = decomposeEventName(name);
|
|
1284
|
+
let bestVersion = me.version;
|
|
1285
|
+
let bestName;
|
|
1286
|
+
for (const other of allNames) {
|
|
1287
|
+
if (other === name) continue;
|
|
1288
|
+
const dec = decomposeEventName(other);
|
|
1289
|
+
if (dec.base === me.base && dec.version > bestVersion) {
|
|
1290
|
+
bestVersion = dec.version;
|
|
1291
|
+
bestName = other;
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
return bestName ? { status: "deprecated", supersededBy: bestName } : { status: "active" };
|
|
1295
|
+
}
|
|
1296
|
+
function buildContractIndex(model) {
|
|
1297
|
+
const entries = [];
|
|
1298
|
+
const allEventNames = /* @__PURE__ */ new Set();
|
|
1299
|
+
for (const st2 of model.states) {
|
|
1300
|
+
entries.push({
|
|
1301
|
+
kind: "state",
|
|
1302
|
+
name: st2.name,
|
|
1303
|
+
file: st2.file,
|
|
1304
|
+
line: st2.line
|
|
1305
|
+
});
|
|
1306
|
+
for (const ev of st2.events) {
|
|
1307
|
+
allEventNames.add(ev.name);
|
|
1308
|
+
entries.push({
|
|
1309
|
+
kind: "event",
|
|
1310
|
+
name: ev.name,
|
|
1311
|
+
qualifier: st2.name,
|
|
1312
|
+
file: st2.file,
|
|
1313
|
+
line: ev.line
|
|
1314
|
+
});
|
|
1315
|
+
}
|
|
1316
|
+
for (const act of st2.actions) {
|
|
1317
|
+
entries.push({
|
|
1318
|
+
kind: "action",
|
|
1319
|
+
name: act.name,
|
|
1320
|
+
qualifier: st2.name,
|
|
1321
|
+
file: st2.file,
|
|
1322
|
+
line: act.line
|
|
1323
|
+
});
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
for (const sl of model.slices) {
|
|
1327
|
+
entries.push({
|
|
1328
|
+
kind: "slice",
|
|
1329
|
+
name: sl.name,
|
|
1330
|
+
file: sl.file,
|
|
1331
|
+
line: sl.line
|
|
1332
|
+
});
|
|
1333
|
+
for (const r of sl.reactions) {
|
|
1334
|
+
allEventNames.add(r.event);
|
|
1335
|
+
entries.push({
|
|
1336
|
+
kind: "reaction",
|
|
1337
|
+
name: r.handlerName,
|
|
1338
|
+
qualifier: `${sl.name}::${r.event}`,
|
|
1339
|
+
file: r.file ?? sl.file,
|
|
1340
|
+
line: r.line
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
for (const pr of model.projections) {
|
|
1345
|
+
entries.push({
|
|
1346
|
+
kind: "projection",
|
|
1347
|
+
name: pr.name,
|
|
1348
|
+
file: pr.file,
|
|
1349
|
+
line: pr.line
|
|
1350
|
+
});
|
|
1351
|
+
for (const ev of pr.handles) allEventNames.add(ev);
|
|
1352
|
+
}
|
|
1353
|
+
for (const r of model.reactions) {
|
|
1354
|
+
allEventNames.add(r.event);
|
|
1355
|
+
entries.push({
|
|
1356
|
+
kind: "reaction",
|
|
1357
|
+
name: r.handlerName,
|
|
1358
|
+
qualifier: `*::${r.event}`,
|
|
1359
|
+
file: r.file,
|
|
1360
|
+
line: r.line
|
|
1361
|
+
});
|
|
1362
|
+
}
|
|
1363
|
+
return { entries, model, allEventNames };
|
|
1364
|
+
}
|
|
1365
|
+
var CATEGORY_KEYWORDS = {
|
|
1366
|
+
event: "event",
|
|
1367
|
+
events: "event",
|
|
1368
|
+
action: "action",
|
|
1369
|
+
actions: "action",
|
|
1370
|
+
state: "state",
|
|
1371
|
+
states: "state",
|
|
1372
|
+
slice: "slice",
|
|
1373
|
+
slices: "slice",
|
|
1374
|
+
projection: "projection",
|
|
1375
|
+
projections: "projection",
|
|
1376
|
+
reaction: "reaction",
|
|
1377
|
+
reactions: "reaction"
|
|
1378
|
+
};
|
|
1379
|
+
function listByKind(idx, kind) {
|
|
1380
|
+
return idx.entries.filter((e2) => e2.kind === kind).sort((a, b2) => a.name.localeCompare(b2.name));
|
|
1381
|
+
}
|
|
1382
|
+
function search(idx, query, limit = 20) {
|
|
1383
|
+
const q2 = query.trim().toLowerCase();
|
|
1384
|
+
if (!q2) return [];
|
|
1385
|
+
const scored = [];
|
|
1386
|
+
for (const entry of idx.entries) {
|
|
1387
|
+
const name = entry.name.toLowerCase();
|
|
1388
|
+
let score;
|
|
1389
|
+
if (name === q2) score = 0;
|
|
1390
|
+
else if (name.startsWith(q2)) score = 1;
|
|
1391
|
+
else if (name.includes(q2)) score = 2;
|
|
1392
|
+
else continue;
|
|
1393
|
+
scored.push({ entry, score });
|
|
1394
|
+
}
|
|
1395
|
+
scored.sort((a, b2) => {
|
|
1396
|
+
if (a.score !== b2.score) return a.score - b2.score;
|
|
1397
|
+
if (a.entry.kind !== b2.entry.kind)
|
|
1398
|
+
return a.entry.kind.localeCompare(b2.entry.kind);
|
|
1399
|
+
return a.entry.name.localeCompare(b2.entry.name);
|
|
1400
|
+
});
|
|
1401
|
+
return scored.slice(0, limit).map((s) => s.entry);
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
// src/cli/colors.ts
|
|
1405
|
+
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
1406
|
+
var supported = import_picocolors.default.isColorSupported;
|
|
1407
|
+
var CANCEL_DIM = "\x1B[22m";
|
|
1408
|
+
var ext = (code, s) => supported ? `${CANCEL_DIM}\x1B[38;5;${code}m${s}\x1B[39m` : s;
|
|
1409
|
+
var bold = import_picocolors.default.bold;
|
|
1410
|
+
var red = import_picocolors.default.red;
|
|
1411
|
+
var green = import_picocolors.default.green;
|
|
1412
|
+
var cyan = import_picocolors.default.cyan;
|
|
1413
|
+
var muted = (s) => supported ? `\x1B[38;5;248m${s}\x1B[39m` : s;
|
|
1414
|
+
var dim = muted;
|
|
1415
|
+
var orange = (s) => ext(208, s);
|
|
1416
|
+
var cornflower = (s) => ext(33, s);
|
|
1417
|
+
var amber = (s) => ext(220, s);
|
|
1418
|
+
var violet = (s) => ext(141, s);
|
|
1419
|
+
var emerald = (s) => ext(41, s);
|
|
1420
|
+
var fuchsia = (s) => ext(207, s);
|
|
1421
|
+
var pink = cornflower;
|
|
1422
|
+
var kindColor = {
|
|
1423
|
+
event: orange,
|
|
1424
|
+
action: cornflower,
|
|
1425
|
+
state: amber,
|
|
1426
|
+
slice: violet,
|
|
1427
|
+
projection: emerald,
|
|
1428
|
+
reaction: fuchsia
|
|
1429
|
+
};
|
|
1430
|
+
|
|
1431
|
+
// src/cli/format.ts
|
|
1432
|
+
var loc = (file, line) => {
|
|
1433
|
+
if (!file) return "";
|
|
1434
|
+
return line ? `${file}:${line}` : file;
|
|
1435
|
+
};
|
|
1436
|
+
var fileNote = (file, line) => {
|
|
1437
|
+
const l = loc(file, line);
|
|
1438
|
+
return l ? ` ${dim(l)}` : "";
|
|
1439
|
+
};
|
|
1440
|
+
var kindLabel = (kind) => {
|
|
1441
|
+
const k2 = kindColor[kind];
|
|
1442
|
+
return (k2 ?? dim)(kind.padEnd(10));
|
|
1443
|
+
};
|
|
1444
|
+
function formatMatches(query, matches2) {
|
|
1445
|
+
if (matches2.length === 0) return dim(`no matches for "${query}"`);
|
|
1446
|
+
const head = dim(`matches (${matches2.length}) \u2014 type a number to pick:`);
|
|
1447
|
+
const width = String(matches2.length).length;
|
|
1448
|
+
const lines = matches2.map((m2, i) => {
|
|
1449
|
+
const idx = dim(`[${String(i + 1).padStart(width)}]`);
|
|
1450
|
+
const where = loc(m2.file, m2.line);
|
|
1451
|
+
const q2 = m2.qualifier ? dim(` (${m2.qualifier})`) : "";
|
|
1452
|
+
const w3 = where ? ` ${dim(where)}` : "";
|
|
1453
|
+
return ` ${idx} ${kindLabel(m2.kind)} ${m2.name}${q2}${w3}`;
|
|
1454
|
+
});
|
|
1455
|
+
return [head, ...lines].join("\n");
|
|
1456
|
+
}
|
|
1457
|
+
var findActionsEmitting = (model, eventName) => {
|
|
1458
|
+
const out = [];
|
|
1459
|
+
for (const st2 of model.states) {
|
|
1460
|
+
for (const act of st2.actions) {
|
|
1461
|
+
if (act.emits.includes(eventName)) {
|
|
1462
|
+
out.push({
|
|
1463
|
+
state: st2.name,
|
|
1464
|
+
action: act.name,
|
|
1465
|
+
file: st2.file,
|
|
1466
|
+
line: act.line
|
|
1467
|
+
});
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
return out;
|
|
1472
|
+
};
|
|
1473
|
+
var findReactionsFor = (model, eventName) => {
|
|
1474
|
+
const out = [];
|
|
1475
|
+
for (const sl of model.slices) {
|
|
1476
|
+
for (const r of sl.reactions) {
|
|
1477
|
+
if (r.event === eventName) {
|
|
1478
|
+
out.push({
|
|
1479
|
+
slice: sl.name,
|
|
1480
|
+
handler: r.handlerName,
|
|
1481
|
+
dispatches: r.dispatches,
|
|
1482
|
+
file: r.file ?? sl.file,
|
|
1483
|
+
line: r.line
|
|
1484
|
+
});
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
for (const r of model.reactions) {
|
|
1489
|
+
if (r.event === eventName) {
|
|
1490
|
+
out.push({
|
|
1491
|
+
handler: r.handlerName,
|
|
1492
|
+
dispatches: r.dispatches,
|
|
1493
|
+
file: r.file,
|
|
1494
|
+
line: r.line
|
|
1495
|
+
});
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
return out;
|
|
1499
|
+
};
|
|
1500
|
+
var findProjectionsFor = (model, eventName) => model.projections.filter((p2) => p2.handles.includes(eventName)).map((p2) => ({ name: p2.name, file: p2.file }));
|
|
1501
|
+
function formatEvent(idx, entry) {
|
|
1502
|
+
const model = idx.model;
|
|
1503
|
+
let schema;
|
|
1504
|
+
let owningState;
|
|
1505
|
+
for (const st2 of model.states) {
|
|
1506
|
+
const ev = st2.events.find((e2) => e2.name === entry.name);
|
|
1507
|
+
if (ev) {
|
|
1508
|
+
schema = ev.schema;
|
|
1509
|
+
owningState = { name: st2.name, file: st2.file };
|
|
1510
|
+
break;
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
const file = entry.file ?? owningState?.file;
|
|
1514
|
+
const status = eventStatus(entry.name, idx.allEventNames);
|
|
1515
|
+
const statusLine = status.status === "active" ? green("active") : (
|
|
1516
|
+
// `supersededBy` is always set on deprecated entries — see eventStatus.
|
|
1517
|
+
`${red("deprecated")} (superseded by ${orange(status.supersededBy)})`
|
|
1518
|
+
);
|
|
1519
|
+
const lines = [];
|
|
1520
|
+
lines.push(bold(orange(entry.name)));
|
|
1521
|
+
if (file) lines.push(` in: ${dim(loc(file, entry.line))}`);
|
|
1522
|
+
if (owningState && owningState.name !== entry.name)
|
|
1523
|
+
lines.push(` on: ${amber(owningState.name)}`);
|
|
1524
|
+
lines.push(` schema: ${schema ?? dim("(not captured)")}`);
|
|
1525
|
+
lines.push(` status: ${statusLine}`);
|
|
1526
|
+
const producers = findActionsEmitting(model, entry.name);
|
|
1527
|
+
if (producers.length > 0) {
|
|
1528
|
+
lines.push(" producers:");
|
|
1529
|
+
for (const p2 of producers) {
|
|
1530
|
+
lines.push(
|
|
1531
|
+
` - ${pink(p2.action)} ${dim(`(on ${p2.state})`)}${fileNote(p2.file, p2.line)}`
|
|
1532
|
+
);
|
|
1533
|
+
}
|
|
1534
|
+
} else {
|
|
1535
|
+
lines.push(` producers: ${dim("(none)")}`);
|
|
1536
|
+
}
|
|
1537
|
+
const reactions = findReactionsFor(model, entry.name);
|
|
1538
|
+
const projections = findProjectionsFor(model, entry.name);
|
|
1539
|
+
if (reactions.length === 0 && projections.length === 0) {
|
|
1540
|
+
lines.push(` consumers: ${dim("(none)")}`);
|
|
1541
|
+
} else {
|
|
1542
|
+
lines.push(" consumers:");
|
|
1543
|
+
for (const r of reactions) {
|
|
1544
|
+
const slice = r.slice ? `${violet(r.slice)}${dim("::")}` : "";
|
|
1545
|
+
const triggers = r.dispatches.length > 0 ? ` \u2192 ${r.dispatches.map((d) => pink(d)).join(", ")}` : "";
|
|
1546
|
+
lines.push(
|
|
1547
|
+
` - ${slice}${fuchsia(r.handler)}${triggers}${fileNote(r.file, r.line)}`
|
|
1548
|
+
);
|
|
1549
|
+
}
|
|
1550
|
+
for (const p2 of projections) {
|
|
1551
|
+
lines.push(` - ${emerald(p2.name)}${fileNote(p2.file)}`);
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
return lines.join("\n");
|
|
1555
|
+
}
|
|
1556
|
+
function formatAction(idx, entry) {
|
|
1557
|
+
const model = idx.model;
|
|
1558
|
+
const ownerName = entry.qualifier;
|
|
1559
|
+
let action;
|
|
1560
|
+
let stateFile;
|
|
1561
|
+
for (const st2 of model.states) {
|
|
1562
|
+
if (ownerName && st2.name !== ownerName) continue;
|
|
1563
|
+
const a = st2.actions.find((x3) => x3.name === entry.name);
|
|
1564
|
+
if (a) {
|
|
1565
|
+
action = a;
|
|
1566
|
+
stateFile = st2.file;
|
|
1567
|
+
break;
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
const lines = [];
|
|
1571
|
+
lines.push(bold(pink(entry.name)));
|
|
1572
|
+
if (ownerName) lines.push(` on: ${amber(ownerName)}`);
|
|
1573
|
+
if (stateFile)
|
|
1574
|
+
lines.push(` in: ${dim(loc(stateFile, action?.line ?? entry.line))}`);
|
|
1575
|
+
if (action) {
|
|
1576
|
+
if (action.invariants.length > 0) {
|
|
1577
|
+
lines.push(" invariants:");
|
|
1578
|
+
for (const inv of action.invariants) lines.push(` - ${inv}`);
|
|
1579
|
+
}
|
|
1580
|
+
if (action.emits.length > 0) {
|
|
1581
|
+
lines.push(" emits:");
|
|
1582
|
+
for (const e2 of action.emits) lines.push(` - ${orange(e2)}`);
|
|
1583
|
+
} else {
|
|
1584
|
+
lines.push(` emits: ${dim("(none)")}`);
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
return lines.join("\n");
|
|
1588
|
+
}
|
|
1589
|
+
function formatState(idx, entry) {
|
|
1590
|
+
const st2 = idx.model.states.find((s) => s.name === entry.name);
|
|
1591
|
+
const lines = [];
|
|
1592
|
+
lines.push(bold(amber(entry.name)));
|
|
1593
|
+
if (entry.file) lines.push(` in: ${dim(loc(entry.file, entry.line))}`);
|
|
1594
|
+
if (!st2) return lines.join("\n");
|
|
1595
|
+
if (st2.actions.length > 0) {
|
|
1596
|
+
lines.push(" actions:");
|
|
1597
|
+
for (const a of st2.actions) {
|
|
1598
|
+
const emits = a.emits.length > 0 ? ` \u2192 ${a.emits.join(", ")}` : "";
|
|
1599
|
+
lines.push(` - ${pink(a.name)}${emits}`);
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
if (st2.events.length > 0) {
|
|
1603
|
+
lines.push(" events:");
|
|
1604
|
+
for (const e2 of st2.events) {
|
|
1605
|
+
const schema = e2.schema ? ` ${dim(e2.schema)}` : "";
|
|
1606
|
+
lines.push(` - ${orange(e2.name)}${schema}`);
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
return lines.join("\n");
|
|
1610
|
+
}
|
|
1611
|
+
function formatSlice(idx, entry) {
|
|
1612
|
+
const sl = idx.model.slices.find((s) => s.name === entry.name);
|
|
1613
|
+
const lines = [];
|
|
1614
|
+
lines.push(bold(violet(entry.name)));
|
|
1615
|
+
if (entry.file) lines.push(` in: ${dim(loc(entry.file, entry.line))}`);
|
|
1616
|
+
if (!sl) return lines.join("\n");
|
|
1617
|
+
if (sl.error) lines.push(` ${red("error: " + sl.error)}`);
|
|
1618
|
+
if (sl.states.length > 0) {
|
|
1619
|
+
lines.push(" states:");
|
|
1620
|
+
for (const s of sl.states) lines.push(` - ${amber(s)}`);
|
|
1621
|
+
}
|
|
1622
|
+
if (sl.projections.length > 0) {
|
|
1623
|
+
lines.push(" projections:");
|
|
1624
|
+
for (const p2 of sl.projections) lines.push(` - ${emerald(p2)}`);
|
|
1625
|
+
}
|
|
1626
|
+
if (sl.reactions.length > 0) {
|
|
1627
|
+
lines.push(" reactions:");
|
|
1628
|
+
for (const r of sl.reactions) {
|
|
1629
|
+
const triggers = r.dispatches.length > 0 ? ` \u2192 ${r.dispatches.map((d) => pink(d)).join(", ")}` : "";
|
|
1630
|
+
lines.push(
|
|
1631
|
+
` - ${orange(r.event)} \u2192 ${fuchsia(r.handlerName)}${triggers}${fileNote(r.file, r.line)}`
|
|
1632
|
+
);
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
return lines.join("\n");
|
|
1636
|
+
}
|
|
1637
|
+
function formatProjection(idx, entry) {
|
|
1638
|
+
const pr = idx.model.projections.find((p2) => p2.name === entry.name);
|
|
1639
|
+
const lines = [];
|
|
1640
|
+
lines.push(bold(emerald(entry.name)));
|
|
1641
|
+
if (pr?.file) lines.push(` in: ${dim(loc(pr.file, pr.line))}`);
|
|
1642
|
+
if (!pr) return lines.join("\n");
|
|
1643
|
+
if (pr.handles.length > 0) {
|
|
1644
|
+
lines.push(" handles:");
|
|
1645
|
+
for (const h2 of pr.handles) lines.push(` - ${orange(h2)}`);
|
|
1646
|
+
}
|
|
1647
|
+
return lines.join("\n");
|
|
1648
|
+
}
|
|
1649
|
+
function formatReaction(idx, entry) {
|
|
1650
|
+
const [sliceName, eventName] = (entry.qualifier ?? "::").split("::");
|
|
1651
|
+
const lines = [];
|
|
1652
|
+
const slice = sliceName && sliceName !== "*" ? violet(sliceName) : "";
|
|
1653
|
+
const header = slice ? `${bold(fuchsia(entry.name))} ${dim(`(in ${slice})`)}` : bold(fuchsia(entry.name));
|
|
1654
|
+
lines.push(header);
|
|
1655
|
+
if (eventName) lines.push(` on: ${orange(eventName)}`);
|
|
1656
|
+
if (entry.file) lines.push(` in: ${dim(loc(entry.file, entry.line))}`);
|
|
1657
|
+
const sliceReaction = idx.model.slices.find((s) => s.name === sliceName)?.reactions.find(
|
|
1658
|
+
(r2) => r2.handlerName === entry.name && r2.event === eventName
|
|
1659
|
+
);
|
|
1660
|
+
const orchReaction = idx.model.reactions.find(
|
|
1661
|
+
(r2) => r2.handlerName === entry.name && r2.event === eventName
|
|
1662
|
+
);
|
|
1663
|
+
const r = sliceReaction ?? orchReaction;
|
|
1664
|
+
if (eventName) {
|
|
1665
|
+
const producers = findActionsEmitting(idx.model, eventName);
|
|
1666
|
+
if (producers.length > 0) {
|
|
1667
|
+
lines.push(" producers (of triggering event):");
|
|
1668
|
+
for (const p2 of producers) {
|
|
1669
|
+
lines.push(
|
|
1670
|
+
` - action ${pink(p2.action)} (state ${p2.state})${fileNote(p2.file, p2.line)}`
|
|
1671
|
+
);
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
if (r && r.dispatches.length > 0) {
|
|
1676
|
+
lines.push(" triggers:");
|
|
1677
|
+
for (const d of r.dispatches) lines.push(` - action ${pink(d)}`);
|
|
1678
|
+
}
|
|
1679
|
+
return lines.join("\n");
|
|
1680
|
+
}
|
|
1681
|
+
var formatters = {
|
|
1682
|
+
event: formatEvent,
|
|
1683
|
+
action: formatAction,
|
|
1684
|
+
state: formatState,
|
|
1685
|
+
slice: formatSlice,
|
|
1686
|
+
projection: formatProjection,
|
|
1687
|
+
reaction: formatReaction
|
|
1688
|
+
};
|
|
1689
|
+
function formatDetail(idx, entry) {
|
|
1690
|
+
const fmt = formatters[entry.kind];
|
|
1691
|
+
return fmt ? fmt(idx, entry) : "";
|
|
1692
|
+
}
|
|
1693
|
+
function formatSummary(idx) {
|
|
1694
|
+
const m2 = idx.model;
|
|
1695
|
+
const parts = [
|
|
1696
|
+
`${m2.states.length} ${m2.states.length === 1 ? "state" : "states"}`,
|
|
1697
|
+
`${m2.slices.length} ${m2.slices.length === 1 ? "slice" : "slices"}`,
|
|
1698
|
+
`${m2.projections.length} ${m2.projections.length === 1 ? "projection" : "projections"}`,
|
|
1699
|
+
`${idx.allEventNames.size} ${idx.allEventNames.size === 1 ? "event" : "events"}`
|
|
1700
|
+
];
|
|
1701
|
+
return dim(`loaded ${parts.join(", ")}`);
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
// src/cli/json-schema.ts
|
|
1705
|
+
import { z as z2 } from "zod";
|
|
1706
|
+
var findProducers = (model, eventName) => {
|
|
1707
|
+
const out = [];
|
|
1708
|
+
for (const st2 of model.states) {
|
|
1709
|
+
for (const act of st2.actions) {
|
|
1710
|
+
if (act.emits.includes(eventName)) {
|
|
1711
|
+
out.push({
|
|
1712
|
+
action: act.name,
|
|
1713
|
+
state: st2.name,
|
|
1714
|
+
file: st2.file,
|
|
1715
|
+
line: act.line
|
|
1716
|
+
});
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
return out;
|
|
1721
|
+
};
|
|
1722
|
+
var findConsumers = (model, eventName) => {
|
|
1723
|
+
const out = [];
|
|
1724
|
+
for (const sl of model.slices) {
|
|
1725
|
+
for (const r of sl.reactions) {
|
|
1726
|
+
if (r.event === eventName) {
|
|
1727
|
+
out.push({
|
|
1728
|
+
type: "reaction",
|
|
1729
|
+
slice: sl.name,
|
|
1730
|
+
handler: r.handlerName,
|
|
1731
|
+
dispatches: r.dispatches,
|
|
1732
|
+
file: r.file ?? sl.file,
|
|
1733
|
+
line: r.line
|
|
1734
|
+
});
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
for (const r of model.reactions) {
|
|
1739
|
+
if (r.event === eventName) {
|
|
1740
|
+
out.push({
|
|
1741
|
+
type: "reaction",
|
|
1742
|
+
handler: r.handlerName,
|
|
1743
|
+
dispatches: r.dispatches,
|
|
1744
|
+
file: r.file,
|
|
1745
|
+
line: r.line
|
|
1746
|
+
});
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
for (const p2 of model.projections) {
|
|
1750
|
+
if (p2.handles.includes(eventName)) {
|
|
1751
|
+
out.push({ type: "projection", name: p2.name, file: p2.file });
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
return out;
|
|
1755
|
+
};
|
|
1756
|
+
function toJsonSchemaSafe(zod) {
|
|
1757
|
+
if (!zod || typeof zod !== "object") {
|
|
1758
|
+
return { error: "no zod schema captured" };
|
|
1759
|
+
}
|
|
1760
|
+
try {
|
|
1761
|
+
const schema = z2.toJSONSchema(zod);
|
|
1762
|
+
return { schema };
|
|
1763
|
+
} catch (err) {
|
|
1764
|
+
return { error: err instanceof Error ? err.message : String(err) };
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
function formatJsonSchema(idx) {
|
|
1768
|
+
const m2 = idx.model;
|
|
1769
|
+
const events = {};
|
|
1770
|
+
for (const st2 of m2.states) {
|
|
1771
|
+
for (const ev of st2.events) {
|
|
1772
|
+
const status = eventStatus(ev.name, idx.allEventNames);
|
|
1773
|
+
const conv = toJsonSchemaSafe(ev.zod);
|
|
1774
|
+
const report = {
|
|
1775
|
+
name: ev.name,
|
|
1776
|
+
file: st2.file,
|
|
1777
|
+
line: ev.line,
|
|
1778
|
+
status: status.status,
|
|
1779
|
+
supersededBy: status.supersededBy,
|
|
1780
|
+
schemaText: ev.schema,
|
|
1781
|
+
producers: findProducers(m2, ev.name),
|
|
1782
|
+
consumers: findConsumers(m2, ev.name)
|
|
1783
|
+
};
|
|
1784
|
+
if ("schema" in conv) report.schema = conv.schema;
|
|
1785
|
+
else report.schemaError = conv.error;
|
|
1786
|
+
events[ev.name] = report;
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1789
|
+
const out = {
|
|
1790
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
1791
|
+
generator: "act-diagram/act-contracts",
|
|
1792
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1793
|
+
counts: {
|
|
1794
|
+
states: m2.states.length,
|
|
1795
|
+
slices: m2.slices.length,
|
|
1796
|
+
projections: m2.projections.length,
|
|
1797
|
+
events: idx.allEventNames.size
|
|
1798
|
+
},
|
|
1799
|
+
events
|
|
1800
|
+
};
|
|
1801
|
+
return JSON.stringify(out, null, 2);
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
// src/cli/load-project.ts
|
|
1805
|
+
import { readdir, readFile, stat } from "fs/promises";
|
|
1806
|
+
import { posix } from "path";
|
|
1807
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
1808
|
+
"node_modules",
|
|
1809
|
+
"dist",
|
|
1810
|
+
"coverage",
|
|
1811
|
+
"build",
|
|
1812
|
+
".git",
|
|
1813
|
+
".turbo",
|
|
1814
|
+
".next",
|
|
1815
|
+
".vercel",
|
|
1816
|
+
// tests
|
|
1817
|
+
"__tests__",
|
|
1818
|
+
"test",
|
|
1819
|
+
"tests",
|
|
1820
|
+
"e2e",
|
|
1821
|
+
// benchmarks
|
|
1822
|
+
"bench",
|
|
1823
|
+
"benches",
|
|
1824
|
+
"benchmark",
|
|
1825
|
+
"benchmarks",
|
|
1826
|
+
"perf",
|
|
1827
|
+
// build-time scripts and generated artifacts
|
|
1828
|
+
"scripts"
|
|
1829
|
+
]);
|
|
1830
|
+
var SKIP_FILE_RE = /\.(?:d\.ts|tsx|test\.ts|spec\.ts|bench\.ts|perf\.ts)$/;
|
|
1831
|
+
async function loadProject(rootDir, opts = {}) {
|
|
1832
|
+
const max = opts.maxFiles ?? 5e3;
|
|
1833
|
+
const files = [];
|
|
1834
|
+
let truncated = false;
|
|
1835
|
+
const visit = async (absDir, relDir) => {
|
|
1836
|
+
let entries;
|
|
1837
|
+
try {
|
|
1838
|
+
entries = await readdir(absDir, { withFileTypes: true });
|
|
1839
|
+
} catch {
|
|
1840
|
+
return;
|
|
1841
|
+
}
|
|
1842
|
+
for (const entry of entries) {
|
|
1843
|
+
if (files.length >= max) {
|
|
1844
|
+
truncated = true;
|
|
1845
|
+
return;
|
|
1846
|
+
}
|
|
1847
|
+
const name = entry.name;
|
|
1848
|
+
if (name.startsWith(".") && name !== ".") continue;
|
|
1849
|
+
const absPath = posix.join(absDir.replace(/\\/g, "/"), name);
|
|
1850
|
+
const relPath = relDir ? posix.join(relDir, name) : name;
|
|
1851
|
+
if (entry.isDirectory()) {
|
|
1852
|
+
if (SKIP_DIRS.has(name)) continue;
|
|
1853
|
+
await visit(absPath, relPath);
|
|
1854
|
+
continue;
|
|
1855
|
+
}
|
|
1856
|
+
if (!entry.isFile()) continue;
|
|
1857
|
+
if (!name.endsWith(".ts")) continue;
|
|
1858
|
+
if (SKIP_FILE_RE.test(name)) continue;
|
|
1859
|
+
try {
|
|
1860
|
+
const content = await readFile(absPath, "utf8");
|
|
1861
|
+
files.push({ path: relPath, content });
|
|
1862
|
+
} catch {
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
};
|
|
1866
|
+
const rootStat = await stat(rootDir).catch(() => null);
|
|
1867
|
+
if (!rootStat || !rootStat.isDirectory()) {
|
|
1868
|
+
return { files, truncated };
|
|
1869
|
+
}
|
|
1870
|
+
await visit(rootDir.replace(/\\/g, "/"), "");
|
|
1871
|
+
return { files, truncated };
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
// src/cli/markdown.ts
|
|
1875
|
+
var loc2 = (file, line) => {
|
|
1876
|
+
if (!file) return "";
|
|
1877
|
+
return line ? `${file}:${line}` : file;
|
|
1878
|
+
};
|
|
1879
|
+
var findActionsEmitting2 = (model, eventName) => {
|
|
1880
|
+
const out = [];
|
|
1881
|
+
for (const st2 of model.states) {
|
|
1882
|
+
for (const act of st2.actions) {
|
|
1883
|
+
if (act.emits.includes(eventName)) {
|
|
1884
|
+
out.push({
|
|
1885
|
+
state: st2.name,
|
|
1886
|
+
action: act.name,
|
|
1887
|
+
file: st2.file,
|
|
1888
|
+
line: act.line
|
|
1889
|
+
});
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
return out;
|
|
1894
|
+
};
|
|
1895
|
+
var findReactionsFor2 = (model, eventName) => {
|
|
1896
|
+
const out = [];
|
|
1897
|
+
for (const sl of model.slices) {
|
|
1898
|
+
for (const r of sl.reactions) {
|
|
1899
|
+
if (r.event === eventName) {
|
|
1900
|
+
out.push({
|
|
1901
|
+
slice: sl.name,
|
|
1902
|
+
handler: r.handlerName,
|
|
1903
|
+
dispatches: r.dispatches,
|
|
1904
|
+
file: r.file ?? sl.file,
|
|
1905
|
+
line: r.line
|
|
1906
|
+
});
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
for (const r of model.reactions) {
|
|
1911
|
+
if (r.event === eventName) {
|
|
1912
|
+
out.push({
|
|
1913
|
+
handler: r.handlerName,
|
|
1914
|
+
dispatches: r.dispatches,
|
|
1915
|
+
file: r.file,
|
|
1916
|
+
line: r.line
|
|
1917
|
+
});
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
return out;
|
|
1921
|
+
};
|
|
1922
|
+
var findProjectionsFor2 = (model, eventName) => model.projections.filter((p2) => p2.handles.includes(eventName)).map((p2) => ({ name: p2.name, file: p2.file }));
|
|
1923
|
+
var fileSuffix = (file, line) => {
|
|
1924
|
+
const l = loc2(file, line);
|
|
1925
|
+
return l ? ` *(${l})*` : "";
|
|
1926
|
+
};
|
|
1927
|
+
var renderSchema = (s) => {
|
|
1928
|
+
if (!s) return "_(not captured)_";
|
|
1929
|
+
if (!s.includes("\n")) return `\`${s}\``;
|
|
1930
|
+
const indented = s.split("\n").map((l) => ` ${l}`).join("\n");
|
|
1931
|
+
return `
|
|
1932
|
+
|
|
1933
|
+
\`\`\`ts
|
|
1934
|
+
${indented}
|
|
1935
|
+
\`\`\``;
|
|
1936
|
+
};
|
|
1937
|
+
function formatMarkdown(idx) {
|
|
1938
|
+
const m2 = idx.model;
|
|
1939
|
+
const lines = [];
|
|
1940
|
+
lines.push("# Act Contracts Registry");
|
|
1941
|
+
lines.push("");
|
|
1942
|
+
lines.push(
|
|
1943
|
+
`_Generated by \`act --markdown\`. ${m2.states.length} states, ${m2.slices.length} slices, ${m2.projections.length} projections, ${idx.allEventNames.size} events._`
|
|
1944
|
+
);
|
|
1945
|
+
lines.push("");
|
|
1946
|
+
lines.push("## Events");
|
|
1947
|
+
lines.push("");
|
|
1948
|
+
const events = listByKind(idx, "event");
|
|
1949
|
+
if (events.length === 0) lines.push("_(none)_\n");
|
|
1950
|
+
for (const e2 of events) {
|
|
1951
|
+
let schema;
|
|
1952
|
+
let owningState;
|
|
1953
|
+
for (const st2 of m2.states) {
|
|
1954
|
+
const ev = st2.events.find((x3) => x3.name === e2.name);
|
|
1955
|
+
if (ev) {
|
|
1956
|
+
schema = ev.schema;
|
|
1957
|
+
owningState = st2.name;
|
|
1958
|
+
break;
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
const status = eventStatus(e2.name, idx.allEventNames);
|
|
1962
|
+
const statusLabel = status.status === "active" ? "active" : `deprecated \u2014 superseded by **${status.supersededBy}**`;
|
|
1963
|
+
lines.push(`### \`${e2.name}\``);
|
|
1964
|
+
if (e2.file) lines.push(`- **defined in:** \`${loc2(e2.file, e2.line)}\``);
|
|
1965
|
+
if (owningState && owningState !== e2.name)
|
|
1966
|
+
lines.push(`- **on state:** \`${owningState}\``);
|
|
1967
|
+
lines.push(`- **schema:** ${renderSchema(schema)}`);
|
|
1968
|
+
lines.push(`- **status:** ${statusLabel}`);
|
|
1969
|
+
const producers = findActionsEmitting2(m2, e2.name);
|
|
1970
|
+
if (producers.length > 0) {
|
|
1971
|
+
lines.push("- **producers:**");
|
|
1972
|
+
for (const p2 of producers)
|
|
1973
|
+
lines.push(
|
|
1974
|
+
` - \`${p2.action}\` (state \`${p2.state}\`)${fileSuffix(p2.file, p2.line)}`
|
|
1975
|
+
);
|
|
1976
|
+
} else {
|
|
1977
|
+
lines.push("- **producers:** _(none)_");
|
|
1978
|
+
}
|
|
1979
|
+
const reactions2 = findReactionsFor2(m2, e2.name);
|
|
1980
|
+
const projections2 = findProjectionsFor2(m2, e2.name);
|
|
1981
|
+
if (reactions2.length === 0 && projections2.length === 0) {
|
|
1982
|
+
lines.push("- **consumers:** _(none)_");
|
|
1983
|
+
} else {
|
|
1984
|
+
lines.push("- **consumers:**");
|
|
1985
|
+
for (const r of reactions2) {
|
|
1986
|
+
const slice = r.slice ? `\`${r.slice}\`::` : "";
|
|
1987
|
+
const triggers = r.dispatches.length > 0 ? ` \u2192 triggers ${r.dispatches.map((d) => `\`${d}\``).join(", ")}` : "";
|
|
1988
|
+
lines.push(
|
|
1989
|
+
` - reaction ${slice}\`${r.handler}\`${triggers}${fileSuffix(r.file, r.line)}`
|
|
1990
|
+
);
|
|
1991
|
+
}
|
|
1992
|
+
for (const p2 of projections2)
|
|
1993
|
+
lines.push(` - projection \`${p2.name}\`${fileSuffix(p2.file)}`);
|
|
1994
|
+
}
|
|
1995
|
+
lines.push("");
|
|
1996
|
+
}
|
|
1997
|
+
lines.push("## Actions");
|
|
1998
|
+
lines.push("");
|
|
1999
|
+
const actions = listByKind(idx, "action");
|
|
2000
|
+
if (actions.length === 0) lines.push("_(none)_\n");
|
|
2001
|
+
for (const a of actions) {
|
|
2002
|
+
let action;
|
|
2003
|
+
let stateFile;
|
|
2004
|
+
for (const st2 of m2.states) {
|
|
2005
|
+
if (a.qualifier && st2.name !== a.qualifier) continue;
|
|
2006
|
+
const found = st2.actions.find((x3) => x3.name === a.name);
|
|
2007
|
+
if (found) {
|
|
2008
|
+
action = found;
|
|
2009
|
+
stateFile = st2.file;
|
|
2010
|
+
break;
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
lines.push(`### \`${a.name}\``);
|
|
2014
|
+
if (a.qualifier) lines.push(`- **on state:** \`${a.qualifier}\``);
|
|
2015
|
+
if (stateFile)
|
|
2016
|
+
lines.push(
|
|
2017
|
+
`- **defined in:** \`${loc2(stateFile, action?.line ?? a.line)}\``
|
|
2018
|
+
);
|
|
2019
|
+
if (action) {
|
|
2020
|
+
if (action.invariants.length > 0) {
|
|
2021
|
+
lines.push("- **invariants:**");
|
|
2022
|
+
for (const inv of action.invariants) lines.push(` - ${inv}`);
|
|
2023
|
+
}
|
|
2024
|
+
if (action.emits.length > 0) {
|
|
2025
|
+
lines.push("- **emits:**");
|
|
2026
|
+
for (const ev of action.emits) lines.push(` - \`${ev}\``);
|
|
2027
|
+
} else {
|
|
2028
|
+
lines.push("- **emits:** _(none)_");
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
lines.push("");
|
|
2032
|
+
}
|
|
2033
|
+
lines.push("## States");
|
|
2034
|
+
lines.push("");
|
|
2035
|
+
const states = listByKind(idx, "state");
|
|
2036
|
+
if (states.length === 0) lines.push("_(none)_\n");
|
|
2037
|
+
for (const s of states) {
|
|
2038
|
+
const st2 = m2.states.find((x3) => x3.name === s.name);
|
|
2039
|
+
lines.push(`### \`${s.name}\``);
|
|
2040
|
+
if (s.file) lines.push(`- **defined in:** \`${loc2(s.file, s.line)}\``);
|
|
2041
|
+
if (st2) {
|
|
2042
|
+
if (st2.actions.length > 0)
|
|
2043
|
+
lines.push(
|
|
2044
|
+
`- **actions:** ${st2.actions.map((x3) => `\`${x3.name}\``).join(", ")}`
|
|
2045
|
+
);
|
|
2046
|
+
if (st2.events.length > 0)
|
|
2047
|
+
lines.push(
|
|
2048
|
+
`- **events:** ${st2.events.map((x3) => `\`${x3.name}\``).join(", ")}`
|
|
2049
|
+
);
|
|
2050
|
+
}
|
|
2051
|
+
lines.push("");
|
|
2052
|
+
}
|
|
2053
|
+
lines.push("## Slices");
|
|
2054
|
+
lines.push("");
|
|
2055
|
+
const slices = listByKind(idx, "slice");
|
|
2056
|
+
if (slices.length === 0) lines.push("_(none)_\n");
|
|
2057
|
+
for (const s of slices) {
|
|
2058
|
+
const sl = m2.slices.find((x3) => x3.name === s.name);
|
|
2059
|
+
lines.push(`### \`${s.name}\``);
|
|
2060
|
+
if (s.file) lines.push(`- **defined in:** \`${loc2(s.file, s.line)}\``);
|
|
2061
|
+
if (sl) {
|
|
2062
|
+
if (sl.error) lines.push(`- **error:** ${sl.error}`);
|
|
2063
|
+
if (sl.states.length > 0)
|
|
2064
|
+
lines.push(
|
|
2065
|
+
`- **states:** ${sl.states.map((x3) => `\`${x3}\``).join(", ")}`
|
|
2066
|
+
);
|
|
2067
|
+
if (sl.projections.length > 0)
|
|
2068
|
+
lines.push(
|
|
2069
|
+
`- **projections:** ${sl.projections.map((x3) => `\`${x3}\``).join(", ")}`
|
|
2070
|
+
);
|
|
2071
|
+
if (sl.reactions.length > 0) {
|
|
2072
|
+
lines.push("- **reactions:**");
|
|
2073
|
+
for (const r of sl.reactions) {
|
|
2074
|
+
const triggers = r.dispatches.length > 0 ? ` \u2192 ${r.dispatches.map((d) => `\`${d}\``).join(", ")}` : "";
|
|
2075
|
+
lines.push(
|
|
2076
|
+
` - \`${r.event}\` \u2192 \`${r.handlerName}\`${triggers}${fileSuffix(r.file, r.line)}`
|
|
2077
|
+
);
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
lines.push("");
|
|
2082
|
+
}
|
|
2083
|
+
lines.push("## Projections");
|
|
2084
|
+
lines.push("");
|
|
2085
|
+
const projections = listByKind(idx, "projection");
|
|
2086
|
+
if (projections.length === 0) lines.push("_(none)_\n");
|
|
2087
|
+
for (const p2 of projections) {
|
|
2088
|
+
const pr = m2.projections.find((x3) => x3.name === p2.name);
|
|
2089
|
+
lines.push(`### \`${p2.name}\``);
|
|
2090
|
+
if (pr?.file) lines.push(`- **defined in:** \`${loc2(pr.file, pr.line)}\``);
|
|
2091
|
+
if (pr && pr.handles.length > 0)
|
|
2092
|
+
lines.push(
|
|
2093
|
+
`- **handles:** ${pr.handles.map((x3) => `\`${x3}\``).join(", ")}`
|
|
2094
|
+
);
|
|
2095
|
+
lines.push("");
|
|
2096
|
+
}
|
|
2097
|
+
lines.push("## Reactions");
|
|
2098
|
+
lines.push("");
|
|
2099
|
+
const reactions = listByKind(idx, "reaction");
|
|
2100
|
+
if (reactions.length === 0) lines.push("_(none)_\n");
|
|
2101
|
+
for (const r of reactions) {
|
|
2102
|
+
const [sliceName, eventName] = (r.qualifier ?? "::").split("::");
|
|
2103
|
+
lines.push(`### \`${r.name}\``);
|
|
2104
|
+
if (sliceName && sliceName !== "*")
|
|
2105
|
+
lines.push(`- **in slice:** \`${sliceName}\``);
|
|
2106
|
+
if (eventName) lines.push(`- **on event:** \`${eventName}\``);
|
|
2107
|
+
if (r.file) lines.push(`- **defined in:** \`${loc2(r.file, r.line)}\``);
|
|
2108
|
+
const sliceReaction = m2.slices.find((x3) => x3.name === sliceName)?.reactions.find(
|
|
2109
|
+
(rr) => rr.handlerName === r.name && rr.event === eventName
|
|
2110
|
+
);
|
|
2111
|
+
const orchReaction = m2.reactions.find(
|
|
2112
|
+
(rr) => rr.handlerName === r.name && rr.event === eventName
|
|
2113
|
+
);
|
|
2114
|
+
const inner = sliceReaction ?? orchReaction;
|
|
2115
|
+
if (inner && inner.dispatches.length > 0) {
|
|
2116
|
+
lines.push(
|
|
2117
|
+
`- **triggers:** ${inner.dispatches.map((d) => `\`${d}\``).join(", ")}`
|
|
2118
|
+
);
|
|
2119
|
+
}
|
|
2120
|
+
lines.push("");
|
|
2121
|
+
}
|
|
2122
|
+
return lines.join("\n");
|
|
2123
|
+
}
|
|
2124
|
+
|
|
2125
|
+
// src/cli/repl.ts
|
|
2126
|
+
import { writeFile } from "fs/promises";
|
|
2127
|
+
import { resolve as resolve3 } from "path";
|
|
2128
|
+
|
|
2129
|
+
// ../../node_modules/.pnpm/@clack+core@1.3.1/node_modules/@clack/core/dist/index.mjs
|
|
2130
|
+
import { styleText as v } from "util";
|
|
2131
|
+
import { stdout as x, stdin as D } from "process";
|
|
2132
|
+
import * as b from "readline";
|
|
2133
|
+
import E from "readline";
|
|
2134
|
+
|
|
2135
|
+
// ../../node_modules/.pnpm/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/utils.js
|
|
2136
|
+
var getCodePointsLength = /* @__PURE__ */ (() => {
|
|
2137
|
+
const SURROGATE_PAIR_RE = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
|
2138
|
+
return (input) => {
|
|
2139
|
+
let surrogatePairsNr = 0;
|
|
2140
|
+
SURROGATE_PAIR_RE.lastIndex = 0;
|
|
2141
|
+
while (SURROGATE_PAIR_RE.test(input)) {
|
|
2142
|
+
surrogatePairsNr += 1;
|
|
2143
|
+
}
|
|
2144
|
+
return input.length - surrogatePairsNr;
|
|
2145
|
+
};
|
|
2146
|
+
})();
|
|
2147
|
+
var isFullWidth = (x3) => {
|
|
2148
|
+
return x3 === 12288 || x3 >= 65281 && x3 <= 65376 || x3 >= 65504 && x3 <= 65510;
|
|
2149
|
+
};
|
|
2150
|
+
var isWideNotCJKTNotEmoji = (x3) => {
|
|
2151
|
+
return x3 === 8987 || x3 === 9001 || x3 >= 12272 && x3 <= 12287 || x3 >= 12289 && x3 <= 12350 || x3 >= 12441 && x3 <= 12543 || x3 >= 12549 && x3 <= 12591 || x3 >= 12593 && x3 <= 12686 || x3 >= 12688 && x3 <= 12771 || x3 >= 12783 && x3 <= 12830 || x3 >= 12832 && x3 <= 12871 || x3 >= 12880 && x3 <= 19903 || x3 >= 65040 && x3 <= 65049 || x3 >= 65072 && x3 <= 65106 || x3 >= 65108 && x3 <= 65126 || x3 >= 65128 && x3 <= 65131 || x3 >= 127488 && x3 <= 127490 || x3 >= 127504 && x3 <= 127547 || x3 >= 127552 && x3 <= 127560 || x3 >= 131072 && x3 <= 196605 || x3 >= 196608 && x3 <= 262141;
|
|
2152
|
+
};
|
|
2153
|
+
|
|
2154
|
+
// ../../node_modules/.pnpm/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/index.js
|
|
2155
|
+
var ANSI_RE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y;
|
|
2156
|
+
var CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
|
|
2157
|
+
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;
|
|
2158
|
+
var TAB_RE = /\t{1,1000}/y;
|
|
2159
|
+
var EMOJI_RE = new RegExp("[\\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");
|
|
2160
|
+
var LATIN_RE = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
|
|
2161
|
+
var MODIFIER_RE = new RegExp("\\p{M}+", "gu");
|
|
2162
|
+
var NO_TRUNCATION = { limit: Infinity, ellipsis: "" };
|
|
2163
|
+
var getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {}) => {
|
|
2164
|
+
const LIMIT = truncationOptions.limit ?? Infinity;
|
|
2165
|
+
const ELLIPSIS = truncationOptions.ellipsis ?? "";
|
|
2166
|
+
const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth(ELLIPSIS, NO_TRUNCATION, widthOptions).width : 0);
|
|
2167
|
+
const ANSI_WIDTH = 0;
|
|
2168
|
+
const CONTROL_WIDTH = widthOptions.controlWidth ?? 0;
|
|
2169
|
+
const TAB_WIDTH = widthOptions.tabWidth ?? 8;
|
|
2170
|
+
const EMOJI_WIDTH = widthOptions.emojiWidth ?? 2;
|
|
2171
|
+
const FULL_WIDTH_WIDTH = 2;
|
|
2172
|
+
const REGULAR_WIDTH = widthOptions.regularWidth ?? 1;
|
|
2173
|
+
const WIDE_WIDTH = widthOptions.wideWidth ?? FULL_WIDTH_WIDTH;
|
|
2174
|
+
const PARSE_BLOCKS = [
|
|
2175
|
+
[LATIN_RE, REGULAR_WIDTH],
|
|
2176
|
+
[ANSI_RE, ANSI_WIDTH],
|
|
2177
|
+
[CONTROL_RE, CONTROL_WIDTH],
|
|
2178
|
+
[TAB_RE, TAB_WIDTH],
|
|
2179
|
+
[EMOJI_RE, EMOJI_WIDTH],
|
|
2180
|
+
[CJKT_WIDE_RE, WIDE_WIDTH]
|
|
2181
|
+
];
|
|
2182
|
+
let indexPrev = 0;
|
|
2183
|
+
let index = 0;
|
|
2184
|
+
let length = input.length;
|
|
2185
|
+
let lengthExtra = 0;
|
|
2186
|
+
let truncationEnabled = false;
|
|
2187
|
+
let truncationIndex = length;
|
|
2188
|
+
let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH);
|
|
2189
|
+
let unmatchedStart = 0;
|
|
2190
|
+
let unmatchedEnd = 0;
|
|
2191
|
+
let width = 0;
|
|
2192
|
+
let widthExtra = 0;
|
|
2193
|
+
outer: while (true) {
|
|
2194
|
+
if (unmatchedEnd > unmatchedStart || index >= length && index > indexPrev) {
|
|
2195
|
+
const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
|
|
2196
|
+
lengthExtra = 0;
|
|
2197
|
+
for (const char of unmatched.replaceAll(MODIFIER_RE, "")) {
|
|
2198
|
+
const codePoint = char.codePointAt(0) || 0;
|
|
2199
|
+
if (isFullWidth(codePoint)) {
|
|
2200
|
+
widthExtra = FULL_WIDTH_WIDTH;
|
|
2201
|
+
} else if (isWideNotCJKTNotEmoji(codePoint)) {
|
|
2202
|
+
widthExtra = WIDE_WIDTH;
|
|
2203
|
+
} else {
|
|
2204
|
+
widthExtra = REGULAR_WIDTH;
|
|
2205
|
+
}
|
|
2206
|
+
if (width + widthExtra > truncationLimit) {
|
|
2207
|
+
truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
|
|
2208
|
+
}
|
|
2209
|
+
if (width + widthExtra > LIMIT) {
|
|
2210
|
+
truncationEnabled = true;
|
|
2211
|
+
break outer;
|
|
2212
|
+
}
|
|
2213
|
+
lengthExtra += char.length;
|
|
2214
|
+
width += widthExtra;
|
|
2215
|
+
}
|
|
2216
|
+
unmatchedStart = unmatchedEnd = 0;
|
|
2217
|
+
}
|
|
2218
|
+
if (index >= length) {
|
|
2219
|
+
break outer;
|
|
2220
|
+
}
|
|
2221
|
+
for (let i = 0, l = PARSE_BLOCKS.length; i < l; i++) {
|
|
2222
|
+
const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[i];
|
|
2223
|
+
BLOCK_RE.lastIndex = index;
|
|
2224
|
+
if (BLOCK_RE.test(input)) {
|
|
2225
|
+
lengthExtra = BLOCK_RE === CJKT_WIDE_RE ? getCodePointsLength(input.slice(index, BLOCK_RE.lastIndex)) : BLOCK_RE === EMOJI_RE ? 1 : BLOCK_RE.lastIndex - index;
|
|
2226
|
+
widthExtra = lengthExtra * BLOCK_WIDTH;
|
|
2227
|
+
if (width + widthExtra > truncationLimit) {
|
|
2228
|
+
truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / BLOCK_WIDTH));
|
|
2229
|
+
}
|
|
2230
|
+
if (width + widthExtra > LIMIT) {
|
|
2231
|
+
truncationEnabled = true;
|
|
2232
|
+
break outer;
|
|
2233
|
+
}
|
|
2234
|
+
width += widthExtra;
|
|
2235
|
+
unmatchedStart = indexPrev;
|
|
2236
|
+
unmatchedEnd = index;
|
|
2237
|
+
index = indexPrev = BLOCK_RE.lastIndex;
|
|
2238
|
+
continue outer;
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
index += 1;
|
|
2242
|
+
}
|
|
2243
|
+
return {
|
|
2244
|
+
width: truncationEnabled ? truncationLimit : width,
|
|
2245
|
+
index: truncationEnabled ? truncationIndex : length,
|
|
2246
|
+
truncated: truncationEnabled,
|
|
2247
|
+
ellipsed: truncationEnabled && LIMIT >= ELLIPSIS_WIDTH
|
|
2248
|
+
};
|
|
2249
|
+
};
|
|
2250
|
+
var dist_default = getStringTruncatedWidth;
|
|
2251
|
+
|
|
2252
|
+
// ../../node_modules/.pnpm/fast-string-width@3.0.2/node_modules/fast-string-width/dist/index.js
|
|
2253
|
+
var NO_TRUNCATION2 = {
|
|
2254
|
+
limit: Infinity,
|
|
2255
|
+
ellipsis: "",
|
|
2256
|
+
ellipsisWidth: 0
|
|
2257
|
+
};
|
|
2258
|
+
var fastStringWidth = (input, options = {}) => {
|
|
2259
|
+
return dist_default(input, NO_TRUNCATION2, options).width;
|
|
2260
|
+
};
|
|
2261
|
+
var dist_default2 = fastStringWidth;
|
|
2262
|
+
|
|
2263
|
+
// ../../node_modules/.pnpm/fast-wrap-ansi@0.2.0/node_modules/fast-wrap-ansi/lib/main.js
|
|
2264
|
+
var ESC = "\x1B";
|
|
2265
|
+
var CSI = "\x9B";
|
|
2266
|
+
var END_CODE = 39;
|
|
2267
|
+
var ANSI_ESCAPE_BELL = "\x07";
|
|
2268
|
+
var ANSI_CSI = "[";
|
|
2269
|
+
var ANSI_OSC = "]";
|
|
2270
|
+
var ANSI_SGR_TERMINATOR = "m";
|
|
2271
|
+
var ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
|
|
2272
|
+
var GROUP_REGEX = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`, "y");
|
|
2273
|
+
var getClosingCode = (openingCode) => {
|
|
2274
|
+
if (openingCode >= 30 && openingCode <= 37)
|
|
2275
|
+
return 39;
|
|
2276
|
+
if (openingCode >= 90 && openingCode <= 97)
|
|
2277
|
+
return 39;
|
|
2278
|
+
if (openingCode >= 40 && openingCode <= 47)
|
|
2279
|
+
return 49;
|
|
2280
|
+
if (openingCode >= 100 && openingCode <= 107)
|
|
2281
|
+
return 49;
|
|
2282
|
+
if (openingCode === 1 || openingCode === 2)
|
|
2283
|
+
return 22;
|
|
2284
|
+
if (openingCode === 3)
|
|
2285
|
+
return 23;
|
|
2286
|
+
if (openingCode === 4)
|
|
2287
|
+
return 24;
|
|
2288
|
+
if (openingCode === 7)
|
|
2289
|
+
return 27;
|
|
2290
|
+
if (openingCode === 8)
|
|
2291
|
+
return 28;
|
|
2292
|
+
if (openingCode === 9)
|
|
2293
|
+
return 29;
|
|
2294
|
+
if (openingCode === 0)
|
|
2295
|
+
return 0;
|
|
2296
|
+
return void 0;
|
|
2297
|
+
};
|
|
2298
|
+
var wrapAnsiCode = (code) => `${ESC}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
|
|
2299
|
+
var wrapAnsiHyperlink = (url) => `${ESC}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
|
|
2300
|
+
var wrapWord = (rows, word, columns) => {
|
|
2301
|
+
const characters = word[Symbol.iterator]();
|
|
2302
|
+
let isInsideEscape = false;
|
|
2303
|
+
let isInsideLinkEscape = false;
|
|
2304
|
+
let lastRow = rows.at(-1);
|
|
2305
|
+
let visible = lastRow === void 0 ? 0 : dist_default2(lastRow);
|
|
2306
|
+
let currentCharacter = characters.next();
|
|
2307
|
+
let nextCharacter = characters.next();
|
|
2308
|
+
let rawCharacterIndex = 0;
|
|
2309
|
+
while (!currentCharacter.done) {
|
|
2310
|
+
const character = currentCharacter.value;
|
|
2311
|
+
const characterLength = dist_default2(character);
|
|
2312
|
+
if (visible + characterLength <= columns) {
|
|
2313
|
+
rows[rows.length - 1] += character;
|
|
2314
|
+
} else {
|
|
2315
|
+
rows.push(character);
|
|
2316
|
+
visible = 0;
|
|
2317
|
+
}
|
|
2318
|
+
if (character === ESC || character === CSI) {
|
|
2319
|
+
isInsideEscape = true;
|
|
2320
|
+
isInsideLinkEscape = word.startsWith(ANSI_ESCAPE_LINK, rawCharacterIndex + 1);
|
|
2321
|
+
}
|
|
2322
|
+
if (isInsideEscape) {
|
|
2323
|
+
if (isInsideLinkEscape) {
|
|
2324
|
+
if (character === ANSI_ESCAPE_BELL) {
|
|
2325
|
+
isInsideEscape = false;
|
|
2326
|
+
isInsideLinkEscape = false;
|
|
2327
|
+
}
|
|
2328
|
+
} else if (character === ANSI_SGR_TERMINATOR) {
|
|
2329
|
+
isInsideEscape = false;
|
|
2330
|
+
}
|
|
2331
|
+
} else {
|
|
2332
|
+
visible += characterLength;
|
|
2333
|
+
if (visible === columns && !nextCharacter.done) {
|
|
2334
|
+
rows.push("");
|
|
2335
|
+
visible = 0;
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
currentCharacter = nextCharacter;
|
|
2339
|
+
nextCharacter = characters.next();
|
|
2340
|
+
rawCharacterIndex += character.length;
|
|
2341
|
+
}
|
|
2342
|
+
lastRow = rows.at(-1);
|
|
2343
|
+
if (!visible && lastRow !== void 0 && lastRow.length && rows.length > 1) {
|
|
2344
|
+
rows[rows.length - 2] += rows.pop();
|
|
2345
|
+
}
|
|
2346
|
+
};
|
|
2347
|
+
var stringVisibleTrimSpacesRight = (string) => {
|
|
2348
|
+
const words = string.split(" ");
|
|
2349
|
+
let last = words.length;
|
|
2350
|
+
while (last) {
|
|
2351
|
+
if (dist_default2(words[last - 1])) {
|
|
2352
|
+
break;
|
|
2353
|
+
}
|
|
2354
|
+
last--;
|
|
2355
|
+
}
|
|
2356
|
+
if (last === words.length) {
|
|
2357
|
+
return string;
|
|
2358
|
+
}
|
|
2359
|
+
return words.slice(0, last).join(" ") + words.slice(last).join("");
|
|
2360
|
+
};
|
|
2361
|
+
var exec = (string, columns, options = {}) => {
|
|
2362
|
+
if (options.trim !== false && string.trim() === "") {
|
|
2363
|
+
return "";
|
|
2364
|
+
}
|
|
2365
|
+
let returnValue = "";
|
|
2366
|
+
let escapeCode;
|
|
2367
|
+
let escapeUrl;
|
|
2368
|
+
const words = string.split(" ");
|
|
2369
|
+
let rows = [""];
|
|
2370
|
+
let rowLength = 0;
|
|
2371
|
+
for (let index = 0; index < words.length; index++) {
|
|
2372
|
+
const word = words[index];
|
|
2373
|
+
if (options.trim !== false) {
|
|
2374
|
+
const row = rows.at(-1) ?? "";
|
|
2375
|
+
const trimmed = row.trimStart();
|
|
2376
|
+
if (row.length !== trimmed.length) {
|
|
2377
|
+
rows[rows.length - 1] = trimmed;
|
|
2378
|
+
rowLength = dist_default2(trimmed);
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
if (index !== 0) {
|
|
2382
|
+
if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
|
|
2383
|
+
rows.push("");
|
|
2384
|
+
rowLength = 0;
|
|
2385
|
+
}
|
|
2386
|
+
if (rowLength || options.trim === false) {
|
|
2387
|
+
rows[rows.length - 1] += " ";
|
|
2388
|
+
rowLength++;
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
const wordLength = dist_default2(word);
|
|
2392
|
+
if (options.hard && wordLength > columns) {
|
|
2393
|
+
const remainingColumns = columns - rowLength;
|
|
2394
|
+
const breaksStartingThisLine = 1 + Math.floor((wordLength - remainingColumns - 1) / columns);
|
|
2395
|
+
const breaksStartingNextLine = Math.floor((wordLength - 1) / columns);
|
|
2396
|
+
if (breaksStartingNextLine < breaksStartingThisLine) {
|
|
2397
|
+
rows.push("");
|
|
2398
|
+
}
|
|
2399
|
+
wrapWord(rows, word, columns);
|
|
2400
|
+
rowLength = dist_default2(rows.at(-1) ?? "");
|
|
2401
|
+
continue;
|
|
2402
|
+
}
|
|
2403
|
+
if (rowLength + wordLength > columns && rowLength && wordLength) {
|
|
2404
|
+
if (options.wordWrap === false && rowLength < columns) {
|
|
2405
|
+
wrapWord(rows, word, columns);
|
|
2406
|
+
rowLength = dist_default2(rows.at(-1) ?? "");
|
|
2407
|
+
continue;
|
|
2408
|
+
}
|
|
2409
|
+
rows.push("");
|
|
2410
|
+
rowLength = 0;
|
|
2411
|
+
}
|
|
2412
|
+
if (rowLength + wordLength > columns && options.wordWrap === false) {
|
|
2413
|
+
wrapWord(rows, word, columns);
|
|
2414
|
+
rowLength = dist_default2(rows.at(-1) ?? "");
|
|
2415
|
+
continue;
|
|
2416
|
+
}
|
|
2417
|
+
rows[rows.length - 1] += word;
|
|
2418
|
+
rowLength += wordLength;
|
|
2419
|
+
}
|
|
2420
|
+
if (options.trim !== false) {
|
|
2421
|
+
rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
|
|
2422
|
+
}
|
|
2423
|
+
const preString = rows.join("\n");
|
|
2424
|
+
let inSurrogate = false;
|
|
2425
|
+
for (let i = 0; i < preString.length; i++) {
|
|
2426
|
+
const character = preString[i];
|
|
2427
|
+
returnValue += character;
|
|
2428
|
+
if (!inSurrogate) {
|
|
2429
|
+
inSurrogate = character >= "\uD800" && character <= "\uDBFF";
|
|
2430
|
+
if (inSurrogate) {
|
|
2431
|
+
continue;
|
|
2432
|
+
}
|
|
2433
|
+
} else {
|
|
2434
|
+
inSurrogate = false;
|
|
2435
|
+
}
|
|
2436
|
+
if (character === ESC || character === CSI) {
|
|
2437
|
+
GROUP_REGEX.lastIndex = i + 1;
|
|
2438
|
+
const groupsResult = GROUP_REGEX.exec(preString);
|
|
2439
|
+
const groups = groupsResult?.groups;
|
|
2440
|
+
if (groups?.code !== void 0) {
|
|
2441
|
+
const code = Number.parseFloat(groups.code);
|
|
2442
|
+
escapeCode = code === END_CODE ? void 0 : code;
|
|
2443
|
+
} else if (groups?.uri !== void 0) {
|
|
2444
|
+
escapeUrl = groups.uri.length === 0 ? void 0 : groups.uri;
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
if (preString[i + 1] === "\n") {
|
|
2448
|
+
if (escapeUrl) {
|
|
2449
|
+
returnValue += wrapAnsiHyperlink("");
|
|
2450
|
+
}
|
|
2451
|
+
const closingCode = escapeCode ? getClosingCode(escapeCode) : void 0;
|
|
2452
|
+
if (escapeCode && closingCode) {
|
|
2453
|
+
returnValue += wrapAnsiCode(closingCode);
|
|
2454
|
+
}
|
|
2455
|
+
} else if (character === "\n") {
|
|
2456
|
+
if (escapeCode && getClosingCode(escapeCode)) {
|
|
2457
|
+
returnValue += wrapAnsiCode(escapeCode);
|
|
2458
|
+
}
|
|
2459
|
+
if (escapeUrl) {
|
|
2460
|
+
returnValue += wrapAnsiHyperlink(escapeUrl);
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
return returnValue;
|
|
2465
|
+
};
|
|
2466
|
+
var CRLF_OR_LF = /\r?\n/;
|
|
2467
|
+
function wrapAnsi(string, columns, options) {
|
|
2468
|
+
return String(string).normalize().split(CRLF_OR_LF).map((line) => exec(line, columns, options)).join("\n");
|
|
2469
|
+
}
|
|
2470
|
+
|
|
2471
|
+
// ../../node_modules/.pnpm/@clack+core@1.3.1/node_modules/@clack/core/dist/index.mjs
|
|
2472
|
+
var import_sisteransi = __toESM(require_src(), 1);
|
|
2473
|
+
import { ReadStream as O } from "tty";
|
|
2474
|
+
function f(r, t, s) {
|
|
2475
|
+
if (!s.some((o) => !o.disabled)) return r;
|
|
2476
|
+
const e2 = r + t, i = Math.max(s.length - 1, 0), n = e2 < 0 ? i : e2 > i ? 0 : e2;
|
|
2477
|
+
return s[n].disabled ? f(n, t < 0 ? -1 : 1, s) : n;
|
|
2478
|
+
}
|
|
2479
|
+
var G = ["up", "down", "left", "right", "space", "enter", "cancel"];
|
|
2480
|
+
var K = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
2481
|
+
var h = { actions: new Set(G), aliases: /* @__PURE__ */ new Map([["k", "up"], ["j", "down"], ["h", "left"], ["l", "right"], ["", "cancel"], ["escape", "cancel"]]), messages: { cancel: "Canceled", error: "Something went wrong" }, withGuide: true, date: { monthNames: [...K], messages: { required: "Please enter a valid date", invalidMonth: "There are only 12 months in a year", invalidDay: (r, t) => `There are only ${r} days in ${t}`, afterMin: (r) => `Date must be on or after ${r.toISOString().slice(0, 10)}`, beforeMax: (r) => `Date must be on or before ${r.toISOString().slice(0, 10)}` } } };
|
|
2482
|
+
function C(r, t) {
|
|
2483
|
+
if (typeof r == "string") return h.aliases.get(r) === t;
|
|
2484
|
+
for (const s of r) if (s !== void 0 && C(s, t)) return true;
|
|
2485
|
+
return false;
|
|
2486
|
+
}
|
|
2487
|
+
function z3(r, t) {
|
|
2488
|
+
if (r === t) return;
|
|
2489
|
+
const s = r.split(`
|
|
2490
|
+
`), e2 = t.split(`
|
|
2491
|
+
`), i = Math.max(s.length, e2.length), n = [];
|
|
2492
|
+
for (let o = 0; o < i; o++) s[o] !== e2[o] && n.push(o);
|
|
2493
|
+
return { lines: n, numLinesBefore: s.length, numLinesAfter: e2.length, numLines: i };
|
|
2494
|
+
}
|
|
2495
|
+
var Y = globalThis.process.platform.startsWith("win");
|
|
2496
|
+
var k = /* @__PURE__ */ Symbol("clack:cancel");
|
|
2497
|
+
function q(r) {
|
|
2498
|
+
return r === k;
|
|
2499
|
+
}
|
|
2500
|
+
function w(r, t) {
|
|
2501
|
+
const s = r;
|
|
2502
|
+
s.isTTY && s.setRawMode(t);
|
|
2503
|
+
}
|
|
2504
|
+
var A = (r) => "columns" in r && typeof r.columns == "number" ? r.columns : 80;
|
|
2505
|
+
var L = (r) => "rows" in r && typeof r.rows == "number" ? r.rows : 20;
|
|
2506
|
+
function W(r, t, s, e2 = s, i = s, n) {
|
|
2507
|
+
const o = A(r ?? x);
|
|
2508
|
+
return wrapAnsi(t, o - s.length, { hard: true, trim: false }).split(`
|
|
2509
|
+
`).map((u, a, l) => {
|
|
2510
|
+
const c = n ? n(u, a) : u;
|
|
2511
|
+
return a === 0 ? `${e2}${c}` : a === l.length - 1 ? `${i}${c}` : `${s}${c}`;
|
|
2512
|
+
}).join(`
|
|
2513
|
+
`);
|
|
2514
|
+
}
|
|
2515
|
+
var m = class {
|
|
2516
|
+
input;
|
|
2517
|
+
output;
|
|
2518
|
+
_abortSignal;
|
|
2519
|
+
rl;
|
|
2520
|
+
opts;
|
|
2521
|
+
_render;
|
|
2522
|
+
_track = false;
|
|
2523
|
+
_prevFrame = "";
|
|
2524
|
+
_subscribers = /* @__PURE__ */ new Map();
|
|
2525
|
+
_cursor = 0;
|
|
2526
|
+
state = "initial";
|
|
2527
|
+
error = "";
|
|
2528
|
+
value;
|
|
2529
|
+
userInput = "";
|
|
2530
|
+
constructor(t, s = true) {
|
|
2531
|
+
const { input: e2 = D, output: i = x, render: n, signal: o, ...u } = t;
|
|
2532
|
+
this.opts = u, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = n.bind(this), this._track = s, this._abortSignal = o, this.input = e2, this.output = i;
|
|
2533
|
+
}
|
|
2534
|
+
unsubscribe() {
|
|
2535
|
+
this._subscribers.clear();
|
|
2536
|
+
}
|
|
2537
|
+
setSubscriber(t, s) {
|
|
2538
|
+
const e2 = this._subscribers.get(t) ?? [];
|
|
2539
|
+
e2.push(s), this._subscribers.set(t, e2);
|
|
2540
|
+
}
|
|
2541
|
+
on(t, s) {
|
|
2542
|
+
this.setSubscriber(t, { cb: s });
|
|
2543
|
+
}
|
|
2544
|
+
once(t, s) {
|
|
2545
|
+
this.setSubscriber(t, { cb: s, once: true });
|
|
2546
|
+
}
|
|
2547
|
+
emit(t, ...s) {
|
|
2548
|
+
const e2 = this._subscribers.get(t) ?? [], i = [];
|
|
2549
|
+
for (const n of e2) n.cb(...s), n.once && i.push(() => e2.splice(e2.indexOf(n), 1));
|
|
2550
|
+
for (const n of i) n();
|
|
2551
|
+
}
|
|
2552
|
+
prompt() {
|
|
2553
|
+
return new Promise((t) => {
|
|
2554
|
+
if (this._abortSignal) {
|
|
2555
|
+
if (this._abortSignal.aborted) return this.state = "cancel", this.close(), t(k);
|
|
2556
|
+
this._abortSignal.addEventListener("abort", () => {
|
|
2557
|
+
this.state = "cancel", this.close();
|
|
2558
|
+
}, { once: true });
|
|
2559
|
+
}
|
|
2560
|
+
this.rl = E.createInterface({ input: this.input, tabSize: 2, prompt: "", escapeCodeTimeout: 50, terminal: true }), this.rl.prompt(), this.opts.initialUserInput !== void 0 && this._setUserInput(this.opts.initialUserInput, true), this.input.on("keypress", this.onKeypress), w(this.input, true), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
|
|
2561
|
+
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), w(this.input, false), t(this.value);
|
|
2562
|
+
}), this.once("cancel", () => {
|
|
2563
|
+
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), w(this.input, false), t(k);
|
|
2564
|
+
});
|
|
2565
|
+
});
|
|
2566
|
+
}
|
|
2567
|
+
_isActionKey(t, s) {
|
|
2568
|
+
return t === " ";
|
|
2569
|
+
}
|
|
2570
|
+
_shouldSubmit(t, s) {
|
|
2571
|
+
return true;
|
|
2572
|
+
}
|
|
2573
|
+
_setValue(t) {
|
|
2574
|
+
this.value = t, this.emit("value", this.value);
|
|
2575
|
+
}
|
|
2576
|
+
_setUserInput(t, s) {
|
|
2577
|
+
this.userInput = t ?? "", this.emit("userInput", this.userInput), s && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
|
|
2578
|
+
}
|
|
2579
|
+
_clearUserInput() {
|
|
2580
|
+
this.rl?.write(null, { ctrl: true, name: "u" }), this._setUserInput("");
|
|
2581
|
+
}
|
|
2582
|
+
onKeypress(t, s) {
|
|
2583
|
+
if (this._track && s.name !== "return" && (s.name && this._isActionKey(t, s) && 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"), s?.name && (!this._track && h.aliases.has(s.name) && this.emit("cursor", h.aliases.get(s.name)), h.actions.has(s.name) && this.emit("cursor", s.name)), t && (t.toLowerCase() === "y" || t.toLowerCase() === "n") && this.emit("confirm", t.toLowerCase() === "y"), this.emit("key", t?.toLowerCase(), s), s?.name === "return" && this._shouldSubmit(t, s)) {
|
|
2584
|
+
if (this.opts.validate) {
|
|
2585
|
+
const e2 = this.opts.validate(this.value);
|
|
2586
|
+
e2 && (this.error = e2 instanceof Error ? e2.message : e2, this.state = "error", this.rl?.write(this.userInput));
|
|
2587
|
+
}
|
|
2588
|
+
this.state !== "error" && (this.state = "submit");
|
|
2589
|
+
}
|
|
2590
|
+
C([t, s?.name, s?.sequence], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
|
|
2591
|
+
}
|
|
2592
|
+
close() {
|
|
2593
|
+
this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
|
|
2594
|
+
`), w(this.input, false), this.rl?.close(), this.rl = void 0, this.emit(`${this.state}`, this.value), this.unsubscribe();
|
|
2595
|
+
}
|
|
2596
|
+
restoreCursor() {
|
|
2597
|
+
const t = wrapAnsi(this._prevFrame, process.stdout.columns, { hard: true, trim: false }).split(`
|
|
2598
|
+
`).length - 1;
|
|
2599
|
+
this.output.write(import_sisteransi.cursor.move(-999, t * -1));
|
|
2600
|
+
}
|
|
2601
|
+
render() {
|
|
2602
|
+
const t = wrapAnsi(this._render(this) ?? "", process.stdout.columns, { hard: true, trim: false });
|
|
2603
|
+
if (t !== this._prevFrame) {
|
|
2604
|
+
if (this.state === "initial") this.output.write(import_sisteransi.cursor.hide);
|
|
2605
|
+
else {
|
|
2606
|
+
const s = z3(this._prevFrame, t), e2 = L(this.output);
|
|
2607
|
+
if (this.restoreCursor(), s) {
|
|
2608
|
+
const i = Math.max(0, s.numLinesAfter - e2), n = Math.max(0, s.numLinesBefore - e2);
|
|
2609
|
+
let o = s.lines.find((u) => u >= i);
|
|
2610
|
+
if (o === void 0) {
|
|
2611
|
+
this._prevFrame = t;
|
|
2612
|
+
return;
|
|
2613
|
+
}
|
|
2614
|
+
if (s.lines.length === 1) {
|
|
2615
|
+
this.output.write(import_sisteransi.cursor.move(0, o - n)), this.output.write(import_sisteransi.erase.lines(1));
|
|
2616
|
+
const u = t.split(`
|
|
2617
|
+
`);
|
|
2618
|
+
this.output.write(u[o]), this._prevFrame = t, this.output.write(import_sisteransi.cursor.move(0, u.length - o - 1));
|
|
2619
|
+
return;
|
|
2620
|
+
} else if (s.lines.length > 1) {
|
|
2621
|
+
if (i < n) o = i;
|
|
2622
|
+
else {
|
|
2623
|
+
const a = o - n;
|
|
2624
|
+
a > 0 && this.output.write(import_sisteransi.cursor.move(0, a));
|
|
2625
|
+
}
|
|
2626
|
+
this.output.write(import_sisteransi.erase.down());
|
|
2627
|
+
const u = t.split(`
|
|
2628
|
+
`).slice(o);
|
|
2629
|
+
this.output.write(u.join(`
|
|
2630
|
+
`)), this._prevFrame = t;
|
|
2631
|
+
return;
|
|
2632
|
+
}
|
|
2633
|
+
}
|
|
2634
|
+
this.output.write(import_sisteransi.erase.down());
|
|
2635
|
+
}
|
|
2636
|
+
this.output.write(t), this.state === "initial" && (this.state = "active"), this._prevFrame = t;
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
};
|
|
2640
|
+
var ut = class extends m {
|
|
2641
|
+
options;
|
|
2642
|
+
cursor = 0;
|
|
2643
|
+
get _selectedValue() {
|
|
2644
|
+
return this.options[this.cursor];
|
|
2645
|
+
}
|
|
2646
|
+
changeValue() {
|
|
2647
|
+
this.value = this._selectedValue.value;
|
|
2648
|
+
}
|
|
2649
|
+
constructor(t) {
|
|
2650
|
+
super(t, false), this.options = t.options;
|
|
2651
|
+
const s = this.options.findIndex(({ value: i }) => i === t.initialValue), e2 = s === -1 ? 0 : s;
|
|
2652
|
+
this.cursor = this.options[e2].disabled ? f(e2, 1, this.options) : e2, this.changeValue(), this.on("cursor", (i) => {
|
|
2653
|
+
switch (i) {
|
|
2654
|
+
case "left":
|
|
2655
|
+
case "up":
|
|
2656
|
+
this.cursor = f(this.cursor, -1, this.options);
|
|
2657
|
+
break;
|
|
2658
|
+
case "down":
|
|
2659
|
+
case "right":
|
|
2660
|
+
this.cursor = f(this.cursor, 1, this.options);
|
|
2661
|
+
break;
|
|
2662
|
+
}
|
|
2663
|
+
this.changeValue();
|
|
2664
|
+
});
|
|
2665
|
+
}
|
|
2666
|
+
};
|
|
2667
|
+
var ht = class extends m {
|
|
2668
|
+
get userInputWithCursor() {
|
|
2669
|
+
if (this.state === "submit") return this.userInput;
|
|
2670
|
+
const t = this.userInput;
|
|
2671
|
+
if (this.cursor >= t.length) return `${this.userInput}\u2588`;
|
|
2672
|
+
const s = t.slice(0, this.cursor), [e2, ...i] = t.slice(this.cursor);
|
|
2673
|
+
return `${s}${v("inverse", e2)}${i.join("")}`;
|
|
2674
|
+
}
|
|
2675
|
+
get cursor() {
|
|
2676
|
+
return this._cursor;
|
|
2677
|
+
}
|
|
2678
|
+
constructor(t) {
|
|
2679
|
+
super({ ...t, initialUserInput: t.initialUserInput ?? t.initialValue }), this.on("userInput", (s) => {
|
|
2680
|
+
this._setValue(s);
|
|
2681
|
+
}), this.on("finalize", () => {
|
|
2682
|
+
this.value || (this.value = t.defaultValue), this.value === void 0 && (this.value = "");
|
|
2683
|
+
});
|
|
2684
|
+
}
|
|
2685
|
+
};
|
|
2686
|
+
|
|
2687
|
+
// ../../node_modules/.pnpm/@clack+prompts@1.4.0/node_modules/@clack/prompts/dist/index.mjs
|
|
2688
|
+
import { styleText as e, stripVTControlCharacters as nt2 } from "util";
|
|
2689
|
+
import V2 from "process";
|
|
2690
|
+
var import_sisteransi2 = __toESM(require_src(), 1);
|
|
2691
|
+
import { existsSync as Qt, lstatSync as wt, readdirSync as Zt } from "fs";
|
|
2692
|
+
import { dirname as bt, join as te } from "path";
|
|
2693
|
+
function ee() {
|
|
2694
|
+
return V2.platform !== "win32" ? V2.env.TERM !== "linux" : !!V2.env.CI || !!V2.env.WT_SESSION || !!V2.env.TERMINUS_SUBLIME || V2.env.ConEmuTask === "{cmd::Cmder}" || V2.env.TERM_PROGRAM === "Terminus-Sublime" || V2.env.TERM_PROGRAM === "vscode" || V2.env.TERM === "xterm-256color" || V2.env.TERM === "alacritty" || V2.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
2695
|
+
}
|
|
2696
|
+
var tt = ee();
|
|
2697
|
+
var w2 = (t, i) => tt ? t : i;
|
|
2698
|
+
var Tt = w2("\u25C6", "*");
|
|
2699
|
+
var at2 = w2("\u25A0", "x");
|
|
2700
|
+
var ut2 = w2("\u25B2", "x");
|
|
2701
|
+
var H = w2("\u25C7", "o");
|
|
2702
|
+
var lt = w2("\u250C", "T");
|
|
2703
|
+
var $ = w2("\u2502", "|");
|
|
2704
|
+
var x2 = w2("\u2514", "\u2014");
|
|
2705
|
+
var _t = w2("\u2510", "T");
|
|
2706
|
+
var xt = w2("\u2518", "\u2014");
|
|
2707
|
+
var z4 = w2("\u25CF", ">");
|
|
2708
|
+
var U = w2("\u25CB", " ");
|
|
2709
|
+
var et2 = w2("\u25FB", "[\u2022]");
|
|
2710
|
+
var K2 = w2("\u25FC", "[+]");
|
|
2711
|
+
var Y2 = w2("\u25FB", "[ ]");
|
|
2712
|
+
var Et = w2("\u25AA", "\u2022");
|
|
2713
|
+
var st = w2("\u2500", "-");
|
|
2714
|
+
var ct = w2("\u256E", "+");
|
|
2715
|
+
var Gt = w2("\u251C", "+");
|
|
2716
|
+
var $t = w2("\u256F", "+");
|
|
2717
|
+
var dt = w2("\u2570", "+");
|
|
2718
|
+
var Mt = w2("\u256D", "+");
|
|
2719
|
+
var ht2 = w2("\u25CF", "\u2022");
|
|
2720
|
+
var pt = w2("\u25C6", "*");
|
|
2721
|
+
var mt = w2("\u25B2", "!");
|
|
2722
|
+
var gt = w2("\u25A0", "x");
|
|
2723
|
+
var P = (t) => {
|
|
2724
|
+
switch (t) {
|
|
2725
|
+
case "initial":
|
|
2726
|
+
case "active":
|
|
2727
|
+
return e("cyan", Tt);
|
|
2728
|
+
case "cancel":
|
|
2729
|
+
return e("red", at2);
|
|
2730
|
+
case "error":
|
|
2731
|
+
return e("yellow", ut2);
|
|
2732
|
+
case "submit":
|
|
2733
|
+
return e("green", H);
|
|
2734
|
+
}
|
|
2735
|
+
};
|
|
2736
|
+
var yt = (t) => {
|
|
2737
|
+
switch (t) {
|
|
2738
|
+
case "initial":
|
|
2739
|
+
case "active":
|
|
2740
|
+
return e("cyan", $);
|
|
2741
|
+
case "cancel":
|
|
2742
|
+
return e("red", $);
|
|
2743
|
+
case "error":
|
|
2744
|
+
return e("yellow", $);
|
|
2745
|
+
case "submit":
|
|
2746
|
+
return e("green", $);
|
|
2747
|
+
}
|
|
2748
|
+
};
|
|
2749
|
+
var Ot = (t, i, s, r, u, n = false) => {
|
|
2750
|
+
let a = i, c = 0;
|
|
2751
|
+
if (n) for (let o = r - 1; o >= s && (a -= t[o].length, c++, !(a <= u)); o--) ;
|
|
2752
|
+
else for (let o = s; o < r && (a -= t[o].length, c++, !(a <= u)); o++) ;
|
|
2753
|
+
return { lineCount: a, removals: c };
|
|
2754
|
+
};
|
|
2755
|
+
var F = ({ cursor: t, options: i, style: s, output: r = process.stdout, maxItems: u = Number.POSITIVE_INFINITY, columnPadding: n = 0, rowPadding: a = 4 }) => {
|
|
2756
|
+
const c = A(r) - n, o = L(r), l = e("dim", "..."), d = Math.max(o - a, 0), g = Math.max(Math.min(u, d), 5);
|
|
2757
|
+
let p2 = 0;
|
|
2758
|
+
t >= g - 3 && (p2 = Math.max(Math.min(t - g + 3, i.length - g), 0));
|
|
2759
|
+
let f2 = g < i.length && p2 > 0, h2 = g < i.length && p2 + g < i.length;
|
|
2760
|
+
const I = Math.min(p2 + g, i.length), m2 = [];
|
|
2761
|
+
let y = 0;
|
|
2762
|
+
f2 && y++, h2 && y++;
|
|
2763
|
+
const v2 = p2 + (f2 ? 1 : 0), C2 = I - (h2 ? 1 : 0);
|
|
2764
|
+
for (let b2 = v2; b2 < C2; b2++) {
|
|
2765
|
+
const G2 = wrapAnsi(s(i[b2], b2 === t), c, { hard: true, trim: false }).split(`
|
|
2766
|
+
`);
|
|
2767
|
+
m2.push(G2), y += G2.length;
|
|
2768
|
+
}
|
|
2769
|
+
if (y > d) {
|
|
2770
|
+
let b2 = 0, G2 = 0, M = y;
|
|
2771
|
+
const N = t - v2;
|
|
2772
|
+
let O2 = d;
|
|
2773
|
+
const j2 = () => Ot(m2, M, 0, N, O2), k2 = () => Ot(m2, M, N + 1, m2.length, O2, true);
|
|
2774
|
+
f2 ? ({ lineCount: M, removals: b2 } = j2(), M > O2 && (h2 || (O2 -= 1), { lineCount: M, removals: G2 } = k2())) : (h2 || (O2 -= 1), { lineCount: M, removals: G2 } = k2(), M > O2 && (O2 -= 1, { lineCount: M, removals: b2 } = j2())), b2 > 0 && (f2 = true, m2.splice(0, b2)), G2 > 0 && (h2 = true, m2.splice(m2.length - G2, G2));
|
|
2775
|
+
}
|
|
2776
|
+
const S = [];
|
|
2777
|
+
f2 && S.push(l);
|
|
2778
|
+
for (const b2 of m2) for (const G2 of b2) S.push(G2);
|
|
2779
|
+
return h2 && S.push(l), S;
|
|
2780
|
+
};
|
|
2781
|
+
var R2 = { message: (t = [], { symbol: i = e("gray", $), secondarySymbol: s = e("gray", $), output: r = process.stdout, spacing: u = 1, withGuide: n } = {}) => {
|
|
2782
|
+
const a = [], c = n ?? h.withGuide, o = c ? s : "", l = c ? `${i} ` : "", d = c ? `${s} ` : "";
|
|
2783
|
+
for (let p2 = 0; p2 < u; p2++) a.push(o);
|
|
2784
|
+
const g = Array.isArray(t) ? t : t.split(`
|
|
2785
|
+
`);
|
|
2786
|
+
if (g.length > 0) {
|
|
2787
|
+
const [p2, ...f2] = g;
|
|
2788
|
+
p2.length > 0 ? a.push(`${l}${p2}`) : a.push(c ? i : "");
|
|
2789
|
+
for (const h2 of f2) h2.length > 0 ? a.push(`${d}${h2}`) : a.push(c ? s : "");
|
|
2790
|
+
}
|
|
2791
|
+
r.write(`${a.join(`
|
|
2792
|
+
`)}
|
|
2793
|
+
`);
|
|
2794
|
+
}, info: (t, i) => {
|
|
2795
|
+
R2.message(t, { ...i, symbol: e("blue", ht2) });
|
|
2796
|
+
}, success: (t, i) => {
|
|
2797
|
+
R2.message(t, { ...i, symbol: e("green", pt) });
|
|
2798
|
+
}, step: (t, i) => {
|
|
2799
|
+
R2.message(t, { ...i, symbol: e("green", H) });
|
|
2800
|
+
}, warn: (t, i) => {
|
|
2801
|
+
R2.message(t, { ...i, symbol: e("yellow", mt) });
|
|
2802
|
+
}, warning: (t, i) => {
|
|
2803
|
+
R2.warn(t, i);
|
|
2804
|
+
}, error: (t, i) => {
|
|
2805
|
+
R2.message(t, { ...i, symbol: e("red", gt) });
|
|
2806
|
+
} };
|
|
2807
|
+
var ge = (t = "", i) => {
|
|
2808
|
+
const s = i?.output ?? process.stdout, r = i?.withGuide ?? h.withGuide ? `${e("gray", lt)} ` : "";
|
|
2809
|
+
s.write(`${r}${t}
|
|
2810
|
+
`);
|
|
2811
|
+
};
|
|
2812
|
+
var ye = (t = "", i) => {
|
|
2813
|
+
const s = i?.output ?? process.stdout, r = i?.withGuide ?? h.withGuide ? `${e("gray", $)}
|
|
2814
|
+
${e("gray", x2)} ` : "";
|
|
2815
|
+
s.write(`${r}${t}
|
|
2816
|
+
|
|
2817
|
+
`);
|
|
2818
|
+
};
|
|
2819
|
+
var jt = { light: w2("\u2500", "-"), heavy: w2("\u2501", "="), block: w2("\u2588", "#") };
|
|
2820
|
+
var it2 = (t, i) => t.includes(`
|
|
2821
|
+
`) ? t.split(`
|
|
2822
|
+
`).map((s) => i(s)).join(`
|
|
2823
|
+
`) : i(t);
|
|
2824
|
+
var xe = (t) => {
|
|
2825
|
+
const i = (s, r) => {
|
|
2826
|
+
const u = s.label ?? String(s.value);
|
|
2827
|
+
switch (r) {
|
|
2828
|
+
case "disabled":
|
|
2829
|
+
return `${e("gray", U)} ${it2(u, (n) => e("gray", n))}${s.hint ? ` ${e("dim", `(${s.hint ?? "disabled"})`)}` : ""}`;
|
|
2830
|
+
case "selected":
|
|
2831
|
+
return `${it2(u, (n) => e("dim", n))}`;
|
|
2832
|
+
case "active":
|
|
2833
|
+
return `${e("green", z4)} ${u}${s.hint ? ` ${e("dim", `(${s.hint})`)}` : ""}`;
|
|
2834
|
+
case "cancelled":
|
|
2835
|
+
return `${it2(u, (n) => e(["strikethrough", "dim"], n))}`;
|
|
2836
|
+
default:
|
|
2837
|
+
return `${e("dim", U)} ${it2(u, (n) => e("dim", n))}`;
|
|
2838
|
+
}
|
|
2839
|
+
};
|
|
2840
|
+
return new ut({ options: t.options, signal: t.signal, input: t.input, output: t.output, initialValue: t.initialValue, render() {
|
|
2841
|
+
const s = t.withGuide ?? h.withGuide, r = `${P(this.state)} `, u = `${yt(this.state)} `, n = W(t.output, t.message, u, r), a = `${s ? `${e("gray", $)}
|
|
2842
|
+
` : ""}${n}
|
|
2843
|
+
`;
|
|
2844
|
+
switch (this.state) {
|
|
2845
|
+
case "submit": {
|
|
2846
|
+
const c = s ? `${e("gray", $)} ` : "", o = W(t.output, i(this.options[this.cursor], "selected"), c);
|
|
2847
|
+
return `${a}${o}`;
|
|
2848
|
+
}
|
|
2849
|
+
case "cancel": {
|
|
2850
|
+
const c = s ? `${e("gray", $)} ` : "", o = W(t.output, i(this.options[this.cursor], "cancelled"), c);
|
|
2851
|
+
return `${a}${o}${s ? `
|
|
2852
|
+
${e("gray", $)}` : ""}`;
|
|
2853
|
+
}
|
|
2854
|
+
default: {
|
|
2855
|
+
const c = s ? `${e("cyan", $)} ` : "", o = s ? e("cyan", x2) : "", l = a.split(`
|
|
2856
|
+
`).length, d = s ? 2 : 1;
|
|
2857
|
+
return `${a}${c}${F({ output: t.output, cursor: this.cursor, options: this.options, maxItems: t.maxItems, columnPadding: c.length, rowPadding: l + d, style: (g, p2) => i(g, g.disabled ? "disabled" : p2 ? "active" : "inactive") }).join(`
|
|
2858
|
+
${c}`)}
|
|
2859
|
+
${o}
|
|
2860
|
+
`;
|
|
2861
|
+
}
|
|
2862
|
+
}
|
|
2863
|
+
} }).prompt();
|
|
2864
|
+
};
|
|
2865
|
+
var Nt = `${e("gray", $)} `;
|
|
2866
|
+
var Pe = (t) => new ht({ validate: t.validate, placeholder: t.placeholder, defaultValue: t.defaultValue, initialValue: t.initialValue, output: t.output, signal: t.signal, input: t.input, render() {
|
|
2867
|
+
const i = t?.withGuide ?? h.withGuide, s = `${`${i ? `${e("gray", $)}
|
|
2868
|
+
` : ""}${P(this.state)} `}${t.message}
|
|
2869
|
+
`, r = t.placeholder ? e("inverse", t.placeholder[0]) + e("dim", t.placeholder.slice(1)) : e(["inverse", "hidden"], "_"), u = this.userInput ? this.userInputWithCursor : r, n = this.value ?? "";
|
|
2870
|
+
switch (this.state) {
|
|
2871
|
+
case "error": {
|
|
2872
|
+
const a = this.error ? ` ${e("yellow", this.error)}` : "", c = i ? `${e("yellow", $)} ` : "", o = i ? e("yellow", x2) : "";
|
|
2873
|
+
return `${s.trim()}
|
|
2874
|
+
${c}${u}
|
|
2875
|
+
${o}${a}
|
|
2876
|
+
`;
|
|
2877
|
+
}
|
|
2878
|
+
case "submit": {
|
|
2879
|
+
const a = n ? ` ${e("dim", n)}` : "", c = i ? e("gray", $) : "";
|
|
2880
|
+
return `${s}${c}${a}`;
|
|
2881
|
+
}
|
|
2882
|
+
case "cancel": {
|
|
2883
|
+
const a = n ? ` ${e(["strikethrough", "dim"], n)}` : "", c = i ? e("gray", $) : "";
|
|
2884
|
+
return `${s}${c}${a}${n.trim() ? `
|
|
2885
|
+
${c}` : ""}`;
|
|
2886
|
+
}
|
|
2887
|
+
default: {
|
|
2888
|
+
const a = i ? `${e("cyan", $)} ` : "", c = i ? e("cyan", x2) : "";
|
|
2889
|
+
return `${s}${a}${u}
|
|
2890
|
+
${c}
|
|
2891
|
+
`;
|
|
2892
|
+
}
|
|
2893
|
+
}
|
|
2894
|
+
} }).prompt();
|
|
2895
|
+
|
|
2896
|
+
// src/cli/open-editor.ts
|
|
2897
|
+
import { spawn } from "child_process";
|
|
2898
|
+
import { resolve as resolve2 } from "path";
|
|
2899
|
+
var isCodeFamily = (cmd) => /(^|\/)code(-insiders)?(\.exe)?$/i.test(cmd) || /(^|\/)cursor(\.exe)?$/i.test(cmd);
|
|
2900
|
+
function pickEditor(env, override) {
|
|
2901
|
+
if (override) return override;
|
|
2902
|
+
return env.VISUAL || env.EDITOR || "vi";
|
|
2903
|
+
}
|
|
2904
|
+
function editorArgs(editor, file, line) {
|
|
2905
|
+
if (line && isCodeFamily(editor)) return ["--goto", `${file}:${line}`];
|
|
2906
|
+
if (line) return [`+${line}`, file];
|
|
2907
|
+
return [file];
|
|
2908
|
+
}
|
|
2909
|
+
async function openInEditor(file, line, deps) {
|
|
2910
|
+
const editor = pickEditor(process.env, deps.editor);
|
|
2911
|
+
const absPath = resolve2(deps.rootDir, file);
|
|
2912
|
+
const args = editorArgs(editor, absPath, line);
|
|
2913
|
+
return await new Promise((resolveP) => {
|
|
2914
|
+
const child = spawn(editor, args, {
|
|
2915
|
+
/* c8 ignore next — "inherit" path runs only inside a real TTY. */
|
|
2916
|
+
stdio: deps.stdio ?? "inherit"
|
|
2917
|
+
});
|
|
2918
|
+
child.on("error", (err) => {
|
|
2919
|
+
resolveP({ ok: false, reason: err.message });
|
|
2920
|
+
});
|
|
2921
|
+
child.on("exit", (code) => {
|
|
2922
|
+
resolveP({
|
|
2923
|
+
ok: code === 0,
|
|
2924
|
+
reason: code === 0 ? void 0 : `exit ${code}`
|
|
2925
|
+
});
|
|
2926
|
+
});
|
|
2927
|
+
});
|
|
2928
|
+
}
|
|
2929
|
+
|
|
2930
|
+
// src/cli/vim-keys.ts
|
|
2931
|
+
var UP = Buffer.from("\x1B[A");
|
|
2932
|
+
var DOWN = Buffer.from("\x1B[B");
|
|
2933
|
+
var ESC2 = Buffer.from("\x1B");
|
|
2934
|
+
var matches = (chunk, key) => chunk.length === key.length && chunk.toString("utf8") === key;
|
|
2935
|
+
function classify(chunk) {
|
|
2936
|
+
if (matches(chunk, "j")) return "down";
|
|
2937
|
+
if (matches(chunk, "k")) return "up";
|
|
2938
|
+
if (matches(chunk, "q")) return "cancel";
|
|
2939
|
+
if (matches(chunk, "/")) return "slash";
|
|
2940
|
+
return null;
|
|
2941
|
+
}
|
|
2942
|
+
function enableVimKeys(stdin) {
|
|
2943
|
+
const origEmit = stdin.emit.bind(stdin);
|
|
2944
|
+
let active = true;
|
|
2945
|
+
const slashListeners = [];
|
|
2946
|
+
const patched = (event, ...args) => {
|
|
2947
|
+
if (active && event === "data" && args[0] instanceof Buffer) {
|
|
2948
|
+
const direction = classify(args[0]);
|
|
2949
|
+
if (direction === "down") return origEmit("data", DOWN);
|
|
2950
|
+
if (direction === "up") return origEmit("data", UP);
|
|
2951
|
+
if (direction === "cancel") return origEmit("data", ESC2);
|
|
2952
|
+
if (direction === "slash") {
|
|
2953
|
+
for (const cb of slashListeners) cb();
|
|
2954
|
+
return origEmit("data", ESC2);
|
|
2955
|
+
}
|
|
2956
|
+
}
|
|
2957
|
+
return origEmit(event, ...args);
|
|
2958
|
+
};
|
|
2959
|
+
stdin.emit = patched;
|
|
2960
|
+
let restored = false;
|
|
2961
|
+
return {
|
|
2962
|
+
restore: () => {
|
|
2963
|
+
if (restored) return;
|
|
2964
|
+
restored = true;
|
|
2965
|
+
if (stdin.emit === patched) stdin.emit = origEmit;
|
|
2966
|
+
},
|
|
2967
|
+
pause: () => {
|
|
2968
|
+
active = false;
|
|
2969
|
+
},
|
|
2970
|
+
resume: () => {
|
|
2971
|
+
active = true;
|
|
2972
|
+
},
|
|
2973
|
+
onSlash: (cb) => {
|
|
2974
|
+
slashListeners.push(cb);
|
|
2975
|
+
return () => {
|
|
2976
|
+
const i = slashListeners.indexOf(cb);
|
|
2977
|
+
if (i >= 0) slashListeners.splice(i, 1);
|
|
2978
|
+
};
|
|
2979
|
+
}
|
|
2980
|
+
};
|
|
2981
|
+
}
|
|
2982
|
+
|
|
2983
|
+
// src/cli/repl.ts
|
|
2984
|
+
var vimKeys = null;
|
|
2985
|
+
var searchRequested = false;
|
|
2986
|
+
var NAV_LEGEND = dim("j/k or \u2191/\u2193 move \xB7 enter pick \xB7 / search \xB7 esc/q back");
|
|
2987
|
+
var KIND_LABELS = {
|
|
2988
|
+
event: "events",
|
|
2989
|
+
action: "actions",
|
|
2990
|
+
state: "states",
|
|
2991
|
+
slice: "slices",
|
|
2992
|
+
projection: "projections",
|
|
2993
|
+
reaction: "reactions"
|
|
2994
|
+
};
|
|
2995
|
+
var KIND_ORDER = [
|
|
2996
|
+
"event",
|
|
2997
|
+
"action",
|
|
2998
|
+
"state",
|
|
2999
|
+
"slice",
|
|
3000
|
+
"projection",
|
|
3001
|
+
"reaction"
|
|
3002
|
+
];
|
|
3003
|
+
var countByKind = (idx, kind) => {
|
|
3004
|
+
if (kind === "event") return idx.allEventNames.size;
|
|
3005
|
+
return idx.entries.filter((e2) => e2.kind === kind).length;
|
|
3006
|
+
};
|
|
3007
|
+
var labelEntry = (e2) => {
|
|
3008
|
+
const loc3 = e2.file ? `${e2.file}${e2.line ? `:${e2.line}` : ""}` : "";
|
|
3009
|
+
const where = loc3 ? ` ${dim(loc3)}` : "";
|
|
3010
|
+
const qual = e2.qualifier ? dim(` (${e2.qualifier})`) : "";
|
|
3011
|
+
const colored = kindColor[e2.kind](e2.name);
|
|
3012
|
+
return `${colored}${qual}${where}`;
|
|
3013
|
+
};
|
|
3014
|
+
async function pickFromList(idx, rootDir, message, entries) {
|
|
3015
|
+
if (entries.length === 0) {
|
|
3016
|
+
R2.warn("nothing to show.");
|
|
3017
|
+
return;
|
|
3018
|
+
}
|
|
3019
|
+
const pick = await xe({
|
|
3020
|
+
message: `${message} ${NAV_LEGEND}`,
|
|
3021
|
+
options: entries.map((e2) => ({
|
|
3022
|
+
value: e2,
|
|
3023
|
+
label: labelEntry(e2),
|
|
3024
|
+
hint: e2.kind
|
|
3025
|
+
})),
|
|
3026
|
+
maxItems: 12
|
|
3027
|
+
});
|
|
3028
|
+
if (q(pick)) return;
|
|
3029
|
+
await showDetail(idx, rootDir, pick);
|
|
3030
|
+
}
|
|
3031
|
+
async function showDetail(idx, rootDir, entry) {
|
|
3032
|
+
R2.message(formatDetail(idx, entry));
|
|
3033
|
+
if (!entry.file) return;
|
|
3034
|
+
const editor = pickEditor(process.env);
|
|
3035
|
+
const action = await xe({
|
|
3036
|
+
message: `now what? ${NAV_LEGEND}`,
|
|
3037
|
+
options: [
|
|
3038
|
+
{
|
|
3039
|
+
value: "open",
|
|
3040
|
+
label: `open in ${editor}`,
|
|
3041
|
+
hint: `${entry.file}${entry.line ? `:${entry.line}` : ""}`
|
|
3042
|
+
}
|
|
3043
|
+
]
|
|
3044
|
+
});
|
|
3045
|
+
if (q(action)) return;
|
|
3046
|
+
const result = await openInEditor(entry.file, entry.line, { rootDir });
|
|
3047
|
+
if (!result.ok) R2.warn(`editor exited: ${result.reason ?? "unknown"}`);
|
|
3048
|
+
}
|
|
3049
|
+
var DEFAULT_PATHS = {
|
|
3050
|
+
markdown: "act-contracts.md",
|
|
3051
|
+
"json-schema": "act-contracts.schema.json"
|
|
3052
|
+
};
|
|
3053
|
+
async function exportRegistry(idx, rootDir) {
|
|
3054
|
+
const format = await xe({
|
|
3055
|
+
message: `Export as ${NAV_LEGEND}`,
|
|
3056
|
+
options: [
|
|
3057
|
+
{
|
|
3058
|
+
value: "markdown",
|
|
3059
|
+
label: "Markdown",
|
|
3060
|
+
hint: "human-readable registry, pipe to docs/EVENTS.md"
|
|
3061
|
+
},
|
|
3062
|
+
{
|
|
3063
|
+
value: "json-schema",
|
|
3064
|
+
label: "JSON Schema",
|
|
3065
|
+
hint: "machine-readable; consumers can Ajv.compile() each event"
|
|
3066
|
+
}
|
|
3067
|
+
]
|
|
3068
|
+
});
|
|
3069
|
+
if (q(format)) return;
|
|
3070
|
+
vimKeys?.pause();
|
|
3071
|
+
const path = await Pe({
|
|
3072
|
+
message: `Save to (relative to ${dim(rootDir)}) ${dim("(esc to cancel)")}`,
|
|
3073
|
+
placeholder: DEFAULT_PATHS[format],
|
|
3074
|
+
initialValue: DEFAULT_PATHS[format]
|
|
3075
|
+
});
|
|
3076
|
+
vimKeys?.resume();
|
|
3077
|
+
if (q(path) || !path || !path.trim()) return;
|
|
3078
|
+
const content = format === "markdown" ? formatMarkdown(idx) : formatJsonSchema(idx);
|
|
3079
|
+
const abs = resolve3(rootDir, path.trim());
|
|
3080
|
+
try {
|
|
3081
|
+
await writeFile(abs, `${content}
|
|
3082
|
+
`, "utf8");
|
|
3083
|
+
R2.success(`wrote ${abs}`);
|
|
3084
|
+
} catch (err) {
|
|
3085
|
+
R2.error(
|
|
3086
|
+
/* c8 ignore next — the `String(err)` arm fires only on non-Error
|
|
3087
|
+
throws, which Node fs.writeFile doesn't produce. */
|
|
3088
|
+
`could not write ${abs}: ${err instanceof Error ? err.message : String(err)}`
|
|
3089
|
+
);
|
|
3090
|
+
}
|
|
3091
|
+
}
|
|
3092
|
+
async function searchByName(idx, rootDir) {
|
|
3093
|
+
vimKeys?.pause();
|
|
3094
|
+
const q2 = await Pe({
|
|
3095
|
+
message: `Partial name to search ${dim("(esc to cancel)")}`,
|
|
3096
|
+
placeholder: "e.g. order, ticket, place"
|
|
3097
|
+
});
|
|
3098
|
+
vimKeys?.resume();
|
|
3099
|
+
if (q(q2) || !q2 || !q2.trim()) return;
|
|
3100
|
+
const lower = q2.trim().toLowerCase();
|
|
3101
|
+
const kind = CATEGORY_KEYWORDS[lower];
|
|
3102
|
+
if (kind) {
|
|
3103
|
+
await pickFromList(
|
|
3104
|
+
idx,
|
|
3105
|
+
rootDir,
|
|
3106
|
+
`${KIND_LABELS[kind]}`,
|
|
3107
|
+
listByKind(idx, kind)
|
|
3108
|
+
);
|
|
3109
|
+
return;
|
|
3110
|
+
}
|
|
3111
|
+
const matches2 = search(idx, q2.trim(), 200);
|
|
3112
|
+
if (matches2.length === 0) {
|
|
3113
|
+
R2.warn(`no matches for "${q2}"`);
|
|
3114
|
+
return;
|
|
3115
|
+
}
|
|
3116
|
+
await pickFromList(idx, rootDir, `matches for "${q2}"`, matches2);
|
|
3117
|
+
}
|
|
3118
|
+
async function runInteractive(idx, rootDir) {
|
|
3119
|
+
vimKeys = enableVimKeys(process.stdin);
|
|
3120
|
+
const unsub = vimKeys.onSlash(() => {
|
|
3121
|
+
searchRequested = true;
|
|
3122
|
+
});
|
|
3123
|
+
try {
|
|
3124
|
+
await driveInteractive(idx, rootDir);
|
|
3125
|
+
} finally {
|
|
3126
|
+
unsub();
|
|
3127
|
+
vimKeys.restore();
|
|
3128
|
+
vimKeys = null;
|
|
3129
|
+
searchRequested = false;
|
|
3130
|
+
}
|
|
3131
|
+
}
|
|
3132
|
+
async function driveInteractive(idx, rootDir) {
|
|
3133
|
+
ge("act \u2014 contracts explorer");
|
|
3134
|
+
R2.message(formatSummary(idx));
|
|
3135
|
+
while (true) {
|
|
3136
|
+
if (searchRequested) {
|
|
3137
|
+
searchRequested = false;
|
|
3138
|
+
await searchByName(idx, rootDir);
|
|
3139
|
+
continue;
|
|
3140
|
+
}
|
|
3141
|
+
const choice = await xe({
|
|
3142
|
+
message: `What do you want to inspect? ${NAV_LEGEND}`,
|
|
3143
|
+
options: [
|
|
3144
|
+
...KIND_ORDER.map((k2) => ({
|
|
3145
|
+
value: k2,
|
|
3146
|
+
label: kindColor[k2](KIND_LABELS[k2]),
|
|
3147
|
+
hint: `${countByKind(idx, k2)}`
|
|
3148
|
+
})),
|
|
3149
|
+
{
|
|
3150
|
+
value: "export",
|
|
3151
|
+
label: "export",
|
|
3152
|
+
hint: "Markdown / JSON Schema"
|
|
3153
|
+
}
|
|
3154
|
+
],
|
|
3155
|
+
maxItems: 10
|
|
3156
|
+
});
|
|
3157
|
+
if (q(choice)) {
|
|
3158
|
+
if (searchRequested) continue;
|
|
3159
|
+
ye("bye.");
|
|
3160
|
+
return;
|
|
3161
|
+
}
|
|
3162
|
+
if (choice === "export") {
|
|
3163
|
+
await exportRegistry(idx, rootDir);
|
|
3164
|
+
continue;
|
|
3165
|
+
}
|
|
3166
|
+
await pickFromList(
|
|
3167
|
+
idx,
|
|
3168
|
+
rootDir,
|
|
3169
|
+
`${KIND_LABELS[choice]}`,
|
|
3170
|
+
listByKind(idx, choice)
|
|
3171
|
+
);
|
|
3172
|
+
}
|
|
3173
|
+
}
|
|
3174
|
+
|
|
3175
|
+
// src/cli/index.ts
|
|
3176
|
+
function parseArgs(argv) {
|
|
3177
|
+
let cwd;
|
|
3178
|
+
let help = false;
|
|
3179
|
+
let version = false;
|
|
3180
|
+
let maxFiles;
|
|
3181
|
+
let query;
|
|
3182
|
+
let markdown = false;
|
|
3183
|
+
let jsonSchema = false;
|
|
3184
|
+
for (let i = 0; i < argv.length; i++) {
|
|
3185
|
+
const a = argv[i];
|
|
3186
|
+
if (a === "-h" || a === "--help") help = true;
|
|
3187
|
+
else if (a === "-v" || a === "--version") version = true;
|
|
3188
|
+
else if (a === "--cwd") cwd = argv[++i] ?? cwd;
|
|
3189
|
+
else if (a === "-q" || a === "--query") query = argv[++i] ?? query;
|
|
3190
|
+
else if (a === "-m" || a === "--markdown" || a === "--md") markdown = true;
|
|
3191
|
+
else if (a === "-j" || a === "--json-schema" || a === "--json")
|
|
3192
|
+
jsonSchema = true;
|
|
3193
|
+
else if (a === "--max-files") {
|
|
3194
|
+
const n = Number.parseInt(argv[++i] ?? "", 10);
|
|
3195
|
+
if (Number.isFinite(n) && n > 0) maxFiles = n;
|
|
3196
|
+
} else if (!a.startsWith("-")) cwd = a;
|
|
3197
|
+
}
|
|
3198
|
+
return { cwd, help, version, maxFiles, query, markdown, jsonSchema };
|
|
3199
|
+
}
|
|
3200
|
+
var USAGE = [
|
|
3201
|
+
"Usage: act [dir] [-q <name>] [-m | -j] [--cwd <dir>] [--max-files <n>] [--help] [--version]",
|
|
3202
|
+
"",
|
|
3203
|
+
"Interactive mode (default):",
|
|
3204
|
+
" pnpm act # explore the current project",
|
|
3205
|
+
" pnpm act packages/foo # explore a specific package",
|
|
3206
|
+
"",
|
|
3207
|
+
"Non-interactive (scripts, CI):",
|
|
3208
|
+
" pnpm act -q OrderPlaced # print the detail for OrderPlaced and exit",
|
|
3209
|
+
" pnpm act -m > EVENTS.md # emit the full registry as Markdown",
|
|
3210
|
+
" pnpm act -j > contracts.json # emit per-event JSON Schema (machine-readable)",
|
|
3211
|
+
"",
|
|
3212
|
+
"In interactive mode you pick a category (events, actions, slices, \u2026),",
|
|
3213
|
+
"then an entry, then view its neighborhood. From the detail view you",
|
|
3214
|
+
"can jump straight to the source file in $EDITOR. The top menu also",
|
|
3215
|
+
"offers an `Export` action that writes Markdown or JSON Schema to a",
|
|
3216
|
+
"file path you choose."
|
|
3217
|
+
].join("\n");
|
|
3218
|
+
async function main(deps) {
|
|
3219
|
+
const args = parseArgs(deps.argv);
|
|
3220
|
+
if (args.help) {
|
|
3221
|
+
deps.output.write(USAGE + "\n");
|
|
3222
|
+
return 0;
|
|
3223
|
+
}
|
|
3224
|
+
if (args.version) {
|
|
3225
|
+
deps.output.write(deps.versionString + "\n");
|
|
3226
|
+
return 0;
|
|
3227
|
+
}
|
|
3228
|
+
const rootDir = resolve4(args.cwd ?? deps.defaultDir ?? ".");
|
|
3229
|
+
const { files, truncated } = await loadProject(rootDir, {
|
|
3230
|
+
maxFiles: args.maxFiles
|
|
3231
|
+
});
|
|
3232
|
+
if (files.length === 0) {
|
|
3233
|
+
deps.errorOutput.write(
|
|
3234
|
+
`act: no TypeScript source files found under ${rootDir}
|
|
3235
|
+
`
|
|
3236
|
+
);
|
|
3237
|
+
return 1;
|
|
3238
|
+
}
|
|
3239
|
+
if (truncated) {
|
|
3240
|
+
deps.errorOutput.write(
|
|
3241
|
+
"act: scan was truncated (file cap reached); some sources may be missing.\n"
|
|
3242
|
+
);
|
|
3243
|
+
}
|
|
3244
|
+
const { model, error } = extractModel(files);
|
|
3245
|
+
if (error) {
|
|
3246
|
+
deps.errorOutput.write(`act: parse error \u2014 ${error}
|
|
3247
|
+
`);
|
|
3248
|
+
}
|
|
3249
|
+
const idx = buildContractIndex(model);
|
|
3250
|
+
if (args.markdown) {
|
|
3251
|
+
deps.output.write(`${formatMarkdown(idx)}
|
|
3252
|
+
`);
|
|
3253
|
+
return 0;
|
|
3254
|
+
}
|
|
3255
|
+
if (args.jsonSchema) {
|
|
3256
|
+
deps.output.write(`${formatJsonSchema(idx)}
|
|
3257
|
+
`);
|
|
3258
|
+
return 0;
|
|
3259
|
+
}
|
|
3260
|
+
if (args.query) {
|
|
3261
|
+
const matches2 = search(idx, args.query);
|
|
3262
|
+
if (matches2.length === 0) {
|
|
3263
|
+
deps.errorOutput.write(`act: no matches for "${args.query}"
|
|
3264
|
+
`);
|
|
3265
|
+
return 1;
|
|
3266
|
+
}
|
|
3267
|
+
const exact = matches2.filter(
|
|
3268
|
+
(m2) => m2.name.toLowerCase() === args.query.toLowerCase()
|
|
3269
|
+
);
|
|
3270
|
+
const equivKey = (m2) => `${m2.kind}\0${m2.name}\0${m2.qualifier ?? ""}`;
|
|
3271
|
+
const uniqExact = Array.from(
|
|
3272
|
+
new Map(exact.map((m2) => [equivKey(m2), m2])).values()
|
|
3273
|
+
);
|
|
3274
|
+
if (uniqExact.length === 1) {
|
|
3275
|
+
deps.output.write(formatDetail(idx, uniqExact[0]) + "\n");
|
|
3276
|
+
return 0;
|
|
3277
|
+
}
|
|
3278
|
+
const uniqMatches = Array.from(
|
|
3279
|
+
new Map(matches2.map((m2) => [equivKey(m2), m2])).values()
|
|
3280
|
+
);
|
|
3281
|
+
if (uniqMatches.length === 1) {
|
|
3282
|
+
deps.output.write(formatDetail(idx, uniqMatches[0]) + "\n");
|
|
3283
|
+
return 0;
|
|
3284
|
+
}
|
|
3285
|
+
deps.output.write(formatMatches(args.query, uniqMatches) + "\n");
|
|
3286
|
+
return 0;
|
|
3287
|
+
}
|
|
3288
|
+
await (deps.runInteractive ?? runInteractive)(idx, rootDir);
|
|
3289
|
+
return 0;
|
|
3290
|
+
}
|
|
3291
|
+
var isMain = (() => {
|
|
3292
|
+
try {
|
|
3293
|
+
if (typeof process === "undefined" || !process.argv?.[1]) return false;
|
|
3294
|
+
const entry = process.argv[1];
|
|
3295
|
+
return import.meta.url === `file://${entry}` || import.meta.url.endsWith(entry) || entry.endsWith("/act") || entry.endsWith("/act.js");
|
|
3296
|
+
} catch {
|
|
3297
|
+
return false;
|
|
3298
|
+
}
|
|
3299
|
+
})();
|
|
3300
|
+
if (isMain) {
|
|
3301
|
+
main({
|
|
3302
|
+
input: process.stdin,
|
|
3303
|
+
output: process.stdout,
|
|
3304
|
+
errorOutput: process.stderr,
|
|
3305
|
+
isTTY: !!process.stdout.isTTY,
|
|
3306
|
+
argv: process.argv.slice(2),
|
|
3307
|
+
versionString: "act (act-diagram)",
|
|
3308
|
+
defaultDir: process.env.INIT_CWD ?? process.cwd()
|
|
3309
|
+
}).then(
|
|
3310
|
+
(code) => process.exit(code),
|
|
3311
|
+
(err) => {
|
|
3312
|
+
process.stderr.write(
|
|
3313
|
+
`act: fatal \u2014 ${err instanceof Error ? err.message : String(err)}
|
|
3314
|
+
`
|
|
3315
|
+
);
|
|
3316
|
+
process.exit(2);
|
|
3317
|
+
}
|
|
3318
|
+
);
|
|
3319
|
+
}
|
|
3320
|
+
export {
|
|
3321
|
+
main,
|
|
3322
|
+
parseArgs
|
|
3323
|
+
};
|
|
3324
|
+
//# sourceMappingURL=act.js.map
|