@rotorsoft/act-diagram 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/cli/colors.d.ts +1 -1
- package/dist/@types/cli/colors.d.ts.map +1 -1
- package/dist/@types/cli/contract-index.d.ts +6 -6
- package/dist/@types/cli/contract-index.d.ts.map +1 -1
- package/dist/@types/cli/format.d.ts +9 -9
- package/dist/@types/cli/format.d.ts.map +1 -1
- package/dist/@types/cli/index.d.ts +9 -9
- package/dist/@types/cli/index.d.ts.map +1 -1
- package/dist/@types/cli/json-schema.d.ts +1 -1
- package/dist/@types/cli/json-schema.d.ts.map +1 -1
- package/dist/@types/cli/load-project.d.ts +3 -3
- package/dist/@types/cli/load-project.d.ts.map +1 -1
- package/dist/@types/cli/markdown.d.ts +1 -1
- package/dist/@types/cli/markdown.d.ts.map +1 -1
- package/dist/@types/cli/open-editor.d.ts +4 -4
- package/dist/@types/cli/open-editor.d.ts.map +1 -1
- package/dist/@types/cli/repl.d.ts +1 -1
- package/dist/@types/cli/repl.d.ts.map +1 -1
- package/dist/@types/cli/vim-keys.d.ts +1 -1
- package/dist/@types/cli/vim-keys.d.ts.map +1 -1
- package/dist/@types/client/components/ActDiagram.d.ts +1 -1
- package/dist/@types/client/components/ActDiagram.d.ts.map +1 -1
- package/dist/@types/client/components/AiBar.d.ts +1 -1
- package/dist/@types/client/components/AiBar.d.ts.map +1 -1
- package/dist/@types/client/components/CodePreview.d.ts +2 -2
- package/dist/@types/client/components/CodePreview.d.ts.map +1 -1
- package/dist/@types/client/components/Diagram.d.ts +1 -1
- package/dist/@types/client/components/Diagram.d.ts.map +1 -1
- package/dist/@types/client/components/Logo.d.ts +1 -1
- package/dist/@types/client/components/Logo.d.ts.map +1 -1
- package/dist/@types/client/components/Tooltip.d.ts +1 -1
- package/dist/@types/client/components/Tooltip.d.ts.map +1 -1
- package/dist/@types/client/lib/build-model.d.ts +2 -2
- package/dist/@types/client/lib/build-model.d.ts.map +1 -1
- package/dist/@types/client/lib/evaluate.d.ts +2 -2
- package/dist/@types/client/lib/evaluate.d.ts.map +1 -1
- package/dist/@types/client/lib/layout.d.ts +1 -1
- package/dist/@types/client/lib/layout.d.ts.map +1 -1
- package/dist/@types/client/lib/mock-builders.d.ts +6 -6
- package/dist/@types/client/lib/mock-builders.d.ts.map +1 -1
- package/dist/@types/client/lib/navigate.d.ts +1 -1
- package/dist/@types/client/lib/navigate.d.ts.map +1 -1
- package/dist/@types/client/lib/schema-extract.d.ts +4 -4
- package/dist/@types/client/lib/schema-extract.d.ts.map +1 -1
- package/dist/@types/client/lib/sort.d.ts +1 -1
- package/dist/@types/client/lib/sort.d.ts.map +1 -1
- package/dist/@types/client/lib/strip-fences.d.ts +3 -3
- package/dist/@types/client/lib/strip-fences.d.ts.map +1 -1
- package/dist/@types/index.d.ts +0 -6
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/cli/act.js +1515 -1310
- package/dist/cli/act.js.map +1 -1
- package/dist/index.cjs +640 -704
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +640 -696
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
package/dist/cli/act.js
CHANGED
|
@@ -30,68 +30,68 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
var require_picocolors = __commonJS({
|
|
31
31
|
"../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js"(exports, module) {
|
|
32
32
|
"use strict";
|
|
33
|
-
var
|
|
34
|
-
var argv =
|
|
35
|
-
var env =
|
|
36
|
-
var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") ||
|
|
33
|
+
var p = process || {};
|
|
34
|
+
var argv = p.argv || [];
|
|
35
|
+
var env = p.env || {};
|
|
36
|
+
var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
37
37
|
var formatter = (open, close, replace = open) => (input) => {
|
|
38
38
|
let string = "" + input, index = string.indexOf(close, open.length);
|
|
39
39
|
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
40
40
|
};
|
|
41
41
|
var replaceClose = (string, close, replace, index) => {
|
|
42
|
-
let result = "",
|
|
42
|
+
let result = "", cursor3 = 0;
|
|
43
43
|
do {
|
|
44
|
-
result += string.substring(
|
|
45
|
-
|
|
46
|
-
index = string.indexOf(close,
|
|
44
|
+
result += string.substring(cursor3, index) + replace;
|
|
45
|
+
cursor3 = index + close.length;
|
|
46
|
+
index = string.indexOf(close, cursor3);
|
|
47
47
|
} while (~index);
|
|
48
|
-
return result + string.substring(
|
|
48
|
+
return result + string.substring(cursor3);
|
|
49
49
|
};
|
|
50
50
|
var createColors = (enabled = isColorSupported) => {
|
|
51
|
-
let
|
|
51
|
+
let f = enabled ? formatter : () => String;
|
|
52
52
|
return {
|
|
53
53
|
isColorSupported: enabled,
|
|
54
|
-
reset:
|
|
55
|
-
bold:
|
|
56
|
-
dim:
|
|
57
|
-
italic:
|
|
58
|
-
underline:
|
|
59
|
-
inverse:
|
|
60
|
-
hidden:
|
|
61
|
-
strikethrough:
|
|
62
|
-
black:
|
|
63
|
-
red:
|
|
64
|
-
green:
|
|
65
|
-
yellow:
|
|
66
|
-
blue:
|
|
67
|
-
magenta:
|
|
68
|
-
cyan:
|
|
69
|
-
white:
|
|
70
|
-
gray:
|
|
71
|
-
bgBlack:
|
|
72
|
-
bgRed:
|
|
73
|
-
bgGreen:
|
|
74
|
-
bgYellow:
|
|
75
|
-
bgBlue:
|
|
76
|
-
bgMagenta:
|
|
77
|
-
bgCyan:
|
|
78
|
-
bgWhite:
|
|
79
|
-
blackBright:
|
|
80
|
-
redBright:
|
|
81
|
-
greenBright:
|
|
82
|
-
yellowBright:
|
|
83
|
-
blueBright:
|
|
84
|
-
magentaBright:
|
|
85
|
-
cyanBright:
|
|
86
|
-
whiteBright:
|
|
87
|
-
bgBlackBright:
|
|
88
|
-
bgRedBright:
|
|
89
|
-
bgGreenBright:
|
|
90
|
-
bgYellowBright:
|
|
91
|
-
bgBlueBright:
|
|
92
|
-
bgMagentaBright:
|
|
93
|
-
bgCyanBright:
|
|
94
|
-
bgWhiteBright:
|
|
54
|
+
reset: f("\x1B[0m", "\x1B[0m"),
|
|
55
|
+
bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
56
|
+
dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
57
|
+
italic: f("\x1B[3m", "\x1B[23m"),
|
|
58
|
+
underline: f("\x1B[4m", "\x1B[24m"),
|
|
59
|
+
inverse: f("\x1B[7m", "\x1B[27m"),
|
|
60
|
+
hidden: f("\x1B[8m", "\x1B[28m"),
|
|
61
|
+
strikethrough: f("\x1B[9m", "\x1B[29m"),
|
|
62
|
+
black: f("\x1B[30m", "\x1B[39m"),
|
|
63
|
+
red: f("\x1B[31m", "\x1B[39m"),
|
|
64
|
+
green: f("\x1B[32m", "\x1B[39m"),
|
|
65
|
+
yellow: f("\x1B[33m", "\x1B[39m"),
|
|
66
|
+
blue: f("\x1B[34m", "\x1B[39m"),
|
|
67
|
+
magenta: f("\x1B[35m", "\x1B[39m"),
|
|
68
|
+
cyan: f("\x1B[36m", "\x1B[39m"),
|
|
69
|
+
white: f("\x1B[37m", "\x1B[39m"),
|
|
70
|
+
gray: f("\x1B[90m", "\x1B[39m"),
|
|
71
|
+
bgBlack: f("\x1B[40m", "\x1B[49m"),
|
|
72
|
+
bgRed: f("\x1B[41m", "\x1B[49m"),
|
|
73
|
+
bgGreen: f("\x1B[42m", "\x1B[49m"),
|
|
74
|
+
bgYellow: f("\x1B[43m", "\x1B[49m"),
|
|
75
|
+
bgBlue: f("\x1B[44m", "\x1B[49m"),
|
|
76
|
+
bgMagenta: f("\x1B[45m", "\x1B[49m"),
|
|
77
|
+
bgCyan: f("\x1B[46m", "\x1B[49m"),
|
|
78
|
+
bgWhite: f("\x1B[47m", "\x1B[49m"),
|
|
79
|
+
blackBright: f("\x1B[90m", "\x1B[39m"),
|
|
80
|
+
redBright: f("\x1B[91m", "\x1B[39m"),
|
|
81
|
+
greenBright: f("\x1B[92m", "\x1B[39m"),
|
|
82
|
+
yellowBright: f("\x1B[93m", "\x1B[39m"),
|
|
83
|
+
blueBright: f("\x1B[94m", "\x1B[39m"),
|
|
84
|
+
magentaBright: f("\x1B[95m", "\x1B[39m"),
|
|
85
|
+
cyanBright: f("\x1B[96m", "\x1B[39m"),
|
|
86
|
+
whiteBright: f("\x1B[97m", "\x1B[39m"),
|
|
87
|
+
bgBlackBright: f("\x1B[100m", "\x1B[49m"),
|
|
88
|
+
bgRedBright: f("\x1B[101m", "\x1B[49m"),
|
|
89
|
+
bgGreenBright: f("\x1B[102m", "\x1B[49m"),
|
|
90
|
+
bgYellowBright: f("\x1B[103m", "\x1B[49m"),
|
|
91
|
+
bgBlueBright: f("\x1B[104m", "\x1B[49m"),
|
|
92
|
+
bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
|
|
93
|
+
bgCyanBright: f("\x1B[106m", "\x1B[49m"),
|
|
94
|
+
bgWhiteBright: f("\x1B[107m", "\x1B[49m")
|
|
95
95
|
};
|
|
96
96
|
};
|
|
97
97
|
module.exports = createColors();
|
|
@@ -106,15 +106,15 @@ var require_src = __commonJS({
|
|
|
106
106
|
var ESC3 = "\x1B";
|
|
107
107
|
var CSI2 = `${ESC3}[`;
|
|
108
108
|
var beep = "\x07";
|
|
109
|
-
var
|
|
110
|
-
to(
|
|
111
|
-
if (!y) return `${CSI2}${
|
|
112
|
-
return `${CSI2}${y + 1};${
|
|
109
|
+
var cursor3 = {
|
|
110
|
+
to(x, y) {
|
|
111
|
+
if (!y) return `${CSI2}${x + 1}G`;
|
|
112
|
+
return `${CSI2}${y + 1};${x + 1}H`;
|
|
113
113
|
},
|
|
114
|
-
move(
|
|
114
|
+
move(x, y) {
|
|
115
115
|
let ret = "";
|
|
116
|
-
if (
|
|
117
|
-
else if (
|
|
116
|
+
if (x < 0) ret += `${CSI2}${-x}D`;
|
|
117
|
+
else if (x > 0) ret += `${CSI2}${x}C`;
|
|
118
118
|
if (y < 0) ret += `${CSI2}${-y}A`;
|
|
119
119
|
else if (y > 0) ret += `${CSI2}${y}B`;
|
|
120
120
|
return ret;
|
|
@@ -135,7 +135,7 @@ var require_src = __commonJS({
|
|
|
135
135
|
up: (count = 1) => `${CSI2}S`.repeat(count),
|
|
136
136
|
down: (count = 1) => `${CSI2}T`.repeat(count)
|
|
137
137
|
};
|
|
138
|
-
var
|
|
138
|
+
var erase3 = {
|
|
139
139
|
screen: `${CSI2}2J`,
|
|
140
140
|
up: (count = 1) => `${CSI2}1J`.repeat(count),
|
|
141
141
|
down: (count = 1) => `${CSI2}J`.repeat(count),
|
|
@@ -144,14 +144,14 @@ var require_src = __commonJS({
|
|
|
144
144
|
lineStart: `${CSI2}1K`,
|
|
145
145
|
lines(count) {
|
|
146
146
|
let clear = "";
|
|
147
|
-
for (let
|
|
148
|
-
clear += this.line + (
|
|
147
|
+
for (let i2 = 0; i2 < count; i2++)
|
|
148
|
+
clear += this.line + (i2 < count - 1 ? cursor3.up() : "");
|
|
149
149
|
if (count)
|
|
150
|
-
clear +=
|
|
150
|
+
clear += cursor3.left;
|
|
151
151
|
return clear;
|
|
152
152
|
}
|
|
153
153
|
};
|
|
154
|
-
module.exports = { cursor, scroll, erase, beep };
|
|
154
|
+
module.exports = { cursor: cursor3, scroll, erase: erase3, beep };
|
|
155
155
|
}
|
|
156
156
|
});
|
|
157
157
|
|
|
@@ -162,350 +162,350 @@ import { resolve as resolve4 } from "path";
|
|
|
162
162
|
import { transform } from "sucrase";
|
|
163
163
|
|
|
164
164
|
// src/client/lib/schema-extract.ts
|
|
165
|
-
var
|
|
166
|
-
var
|
|
167
|
-
function
|
|
168
|
-
let
|
|
169
|
-
while (
|
|
170
|
-
const
|
|
171
|
-
if (
|
|
172
|
-
|
|
165
|
+
var is_w_s = (c2) => c2 === " " || c2 === " " || c2 === "\n" || c2 === "\r";
|
|
166
|
+
var is_ident = (c2) => !!c2 && /[\w$]/.test(c2);
|
|
167
|
+
function skip_trivia(src, from) {
|
|
168
|
+
let i2 = from;
|
|
169
|
+
while (i2 < src.length) {
|
|
170
|
+
const c2 = src[i2];
|
|
171
|
+
if (is_w_s(c2)) {
|
|
172
|
+
i2++;
|
|
173
173
|
continue;
|
|
174
174
|
}
|
|
175
|
-
if (
|
|
176
|
-
while (
|
|
175
|
+
if (c2 === "/" && src[i2 + 1] === "/") {
|
|
176
|
+
while (i2 < src.length && src[i2] !== "\n") i2++;
|
|
177
177
|
continue;
|
|
178
178
|
}
|
|
179
|
-
if (
|
|
180
|
-
|
|
181
|
-
while (
|
|
182
|
-
|
|
179
|
+
if (c2 === "/" && src[i2 + 1] === "*") {
|
|
180
|
+
i2 += 2;
|
|
181
|
+
while (i2 < src.length && !(src[i2 - 1] === "*" && src[i2] === "/")) i2++;
|
|
182
|
+
i2++;
|
|
183
183
|
continue;
|
|
184
184
|
}
|
|
185
185
|
break;
|
|
186
186
|
}
|
|
187
|
-
return
|
|
187
|
+
return i2;
|
|
188
188
|
}
|
|
189
|
-
function
|
|
190
|
-
let
|
|
189
|
+
function read_value(src, start) {
|
|
190
|
+
let i2 = start;
|
|
191
191
|
let depth = 0;
|
|
192
|
-
while (
|
|
193
|
-
const
|
|
194
|
-
if (
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
while (
|
|
198
|
-
if (src[
|
|
199
|
-
|
|
192
|
+
while (i2 < src.length) {
|
|
193
|
+
const c2 = src[i2];
|
|
194
|
+
if (c2 === '"' || c2 === "'") {
|
|
195
|
+
const q = c2;
|
|
196
|
+
i2++;
|
|
197
|
+
while (i2 < src.length && src[i2] !== q) {
|
|
198
|
+
if (src[i2] === "\\") {
|
|
199
|
+
i2 += 2;
|
|
200
200
|
continue;
|
|
201
201
|
}
|
|
202
|
-
|
|
202
|
+
i2++;
|
|
203
203
|
}
|
|
204
|
-
|
|
204
|
+
i2++;
|
|
205
205
|
continue;
|
|
206
206
|
}
|
|
207
|
-
if (
|
|
208
|
-
|
|
209
|
-
while (
|
|
210
|
-
if (src[
|
|
211
|
-
|
|
207
|
+
if (c2 === "`") {
|
|
208
|
+
i2++;
|
|
209
|
+
while (i2 < src.length && src[i2] !== "`") {
|
|
210
|
+
if (src[i2] === "\\") {
|
|
211
|
+
i2 += 2;
|
|
212
212
|
continue;
|
|
213
213
|
}
|
|
214
|
-
if (src[
|
|
214
|
+
if (src[i2] === "$" && src[i2 + 1] === "{") {
|
|
215
215
|
let td = 1;
|
|
216
|
-
|
|
217
|
-
while (
|
|
218
|
-
if (src[
|
|
219
|
-
else if (src[
|
|
220
|
-
if (td > 0)
|
|
216
|
+
i2 += 2;
|
|
217
|
+
while (i2 < src.length && td > 0) {
|
|
218
|
+
if (src[i2] === "{") td++;
|
|
219
|
+
else if (src[i2] === "}") td--;
|
|
220
|
+
if (td > 0) i2++;
|
|
221
221
|
}
|
|
222
|
-
|
|
222
|
+
i2++;
|
|
223
223
|
continue;
|
|
224
224
|
}
|
|
225
|
-
|
|
225
|
+
i2++;
|
|
226
226
|
}
|
|
227
|
-
|
|
227
|
+
i2++;
|
|
228
228
|
continue;
|
|
229
229
|
}
|
|
230
|
-
if (
|
|
231
|
-
while (
|
|
230
|
+
if (c2 === "/" && src[i2 + 1] === "/") {
|
|
231
|
+
while (i2 < src.length && src[i2] !== "\n") i2++;
|
|
232
232
|
continue;
|
|
233
233
|
}
|
|
234
|
-
if (
|
|
235
|
-
|
|
236
|
-
while (
|
|
237
|
-
|
|
234
|
+
if (c2 === "/" && src[i2 + 1] === "*") {
|
|
235
|
+
i2 += 2;
|
|
236
|
+
while (i2 < src.length && !(src[i2 - 1] === "*" && src[i2] === "/")) i2++;
|
|
237
|
+
i2++;
|
|
238
238
|
continue;
|
|
239
239
|
}
|
|
240
|
-
if (
|
|
240
|
+
if (c2 === "(" || c2 === "{" || c2 === "[") {
|
|
241
241
|
depth++;
|
|
242
|
-
|
|
242
|
+
i2++;
|
|
243
243
|
continue;
|
|
244
244
|
}
|
|
245
|
-
if (
|
|
245
|
+
if (c2 === ")" || c2 === "]") {
|
|
246
246
|
depth--;
|
|
247
|
-
|
|
247
|
+
i2++;
|
|
248
248
|
continue;
|
|
249
249
|
}
|
|
250
|
-
if (
|
|
251
|
-
if (depth === 0) return
|
|
250
|
+
if (c2 === "}") {
|
|
251
|
+
if (depth === 0) return i2;
|
|
252
252
|
depth--;
|
|
253
|
-
|
|
253
|
+
i2++;
|
|
254
254
|
continue;
|
|
255
255
|
}
|
|
256
|
-
if (
|
|
257
|
-
|
|
256
|
+
if (c2 === "," && depth === 0) return i2;
|
|
257
|
+
i2++;
|
|
258
258
|
}
|
|
259
|
-
return
|
|
259
|
+
return i2;
|
|
260
260
|
}
|
|
261
|
-
function
|
|
261
|
+
function parse_object_literal(src, start_brace) {
|
|
262
262
|
const entries = [];
|
|
263
|
-
let
|
|
264
|
-
while (
|
|
265
|
-
|
|
266
|
-
if (src[
|
|
263
|
+
let i2 = start_brace + 1;
|
|
264
|
+
while (i2 < src.length) {
|
|
265
|
+
i2 = skip_trivia(src, i2);
|
|
266
|
+
if (src[i2] === "}") return { entries, end_brace: i2 };
|
|
267
267
|
let key = "";
|
|
268
|
-
let
|
|
269
|
-
let
|
|
270
|
-
let
|
|
271
|
-
if (src[
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
while (
|
|
275
|
-
if (src[
|
|
276
|
-
|
|
268
|
+
let key_start = i2;
|
|
269
|
+
let key_end = i2;
|
|
270
|
+
let key_was_identifier = false;
|
|
271
|
+
if (src[i2] === '"' || src[i2] === "'") {
|
|
272
|
+
const q = src[i2];
|
|
273
|
+
key_start = ++i2;
|
|
274
|
+
while (i2 < src.length && src[i2] !== q) {
|
|
275
|
+
if (src[i2] === "\\") {
|
|
276
|
+
i2 += 2;
|
|
277
277
|
continue;
|
|
278
278
|
}
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
-
key = src.slice(
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
} else if (
|
|
285
|
-
|
|
286
|
-
while (
|
|
287
|
-
key = src.slice(
|
|
288
|
-
|
|
289
|
-
|
|
279
|
+
i2++;
|
|
280
|
+
}
|
|
281
|
+
key = src.slice(key_start, i2);
|
|
282
|
+
key_end = i2;
|
|
283
|
+
i2++;
|
|
284
|
+
} else if (is_ident(src[i2])) {
|
|
285
|
+
key_start = i2;
|
|
286
|
+
while (is_ident(src[i2])) i2++;
|
|
287
|
+
key = src.slice(key_start, i2);
|
|
288
|
+
key_end = i2;
|
|
289
|
+
key_was_identifier = true;
|
|
290
290
|
} else {
|
|
291
291
|
return null;
|
|
292
292
|
}
|
|
293
|
-
|
|
294
|
-
if (src[
|
|
295
|
-
if (
|
|
296
|
-
entries.push({ key,
|
|
293
|
+
i2 = skip_trivia(src, i2);
|
|
294
|
+
if (src[i2] !== ":") {
|
|
295
|
+
if (key_was_identifier) {
|
|
296
|
+
entries.push({ key, value_start: key_start, value_end: key_end });
|
|
297
297
|
}
|
|
298
|
-
while (
|
|
299
|
-
if (src[
|
|
298
|
+
while (i2 < src.length && src[i2] !== "," && src[i2] !== "}") i2++;
|
|
299
|
+
if (src[i2] === ",") i2++;
|
|
300
300
|
continue;
|
|
301
301
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
const
|
|
305
|
-
const
|
|
306
|
-
entries.push({ key,
|
|
307
|
-
|
|
308
|
-
if (src[
|
|
302
|
+
i2++;
|
|
303
|
+
i2 = skip_trivia(src, i2);
|
|
304
|
+
const value_start = i2;
|
|
305
|
+
const value_end = read_value(src, i2);
|
|
306
|
+
entries.push({ key, value_start, value_end });
|
|
307
|
+
i2 = value_end;
|
|
308
|
+
if (src[i2] === ",") i2++;
|
|
309
309
|
}
|
|
310
310
|
return null;
|
|
311
311
|
}
|
|
312
|
-
function
|
|
313
|
-
let
|
|
312
|
+
function read_top_level_expression(src, start) {
|
|
313
|
+
let i2 = start;
|
|
314
314
|
let depth = 0;
|
|
315
|
-
while (
|
|
316
|
-
const
|
|
317
|
-
if (
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
while (
|
|
321
|
-
if (src[
|
|
322
|
-
|
|
315
|
+
while (i2 < src.length) {
|
|
316
|
+
const c2 = src[i2];
|
|
317
|
+
if (c2 === '"' || c2 === "'") {
|
|
318
|
+
const q = c2;
|
|
319
|
+
i2++;
|
|
320
|
+
while (i2 < src.length && src[i2] !== q) {
|
|
321
|
+
if (src[i2] === "\\") {
|
|
322
|
+
i2 += 2;
|
|
323
323
|
continue;
|
|
324
324
|
}
|
|
325
|
-
|
|
325
|
+
i2++;
|
|
326
326
|
}
|
|
327
|
-
|
|
327
|
+
i2++;
|
|
328
328
|
continue;
|
|
329
329
|
}
|
|
330
|
-
if (
|
|
331
|
-
|
|
332
|
-
while (
|
|
333
|
-
if (src[
|
|
334
|
-
|
|
330
|
+
if (c2 === "`") {
|
|
331
|
+
i2++;
|
|
332
|
+
while (i2 < src.length && src[i2] !== "`") {
|
|
333
|
+
if (src[i2] === "\\") {
|
|
334
|
+
i2 += 2;
|
|
335
335
|
continue;
|
|
336
336
|
}
|
|
337
|
-
if (src[
|
|
337
|
+
if (src[i2] === "$" && src[i2 + 1] === "{") {
|
|
338
338
|
let td = 1;
|
|
339
|
-
|
|
340
|
-
while (
|
|
341
|
-
if (src[
|
|
342
|
-
else if (src[
|
|
343
|
-
if (td > 0)
|
|
339
|
+
i2 += 2;
|
|
340
|
+
while (i2 < src.length && td > 0) {
|
|
341
|
+
if (src[i2] === "{") td++;
|
|
342
|
+
else if (src[i2] === "}") td--;
|
|
343
|
+
if (td > 0) i2++;
|
|
344
344
|
}
|
|
345
|
-
|
|
345
|
+
i2++;
|
|
346
346
|
continue;
|
|
347
347
|
}
|
|
348
|
-
|
|
348
|
+
i2++;
|
|
349
349
|
}
|
|
350
|
-
|
|
350
|
+
i2++;
|
|
351
351
|
continue;
|
|
352
352
|
}
|
|
353
|
-
if (
|
|
354
|
-
while (
|
|
353
|
+
if (c2 === "/" && src[i2 + 1] === "/") {
|
|
354
|
+
while (i2 < src.length && src[i2] !== "\n") i2++;
|
|
355
355
|
continue;
|
|
356
356
|
}
|
|
357
|
-
if (
|
|
358
|
-
|
|
359
|
-
while (
|
|
360
|
-
|
|
357
|
+
if (c2 === "/" && src[i2 + 1] === "*") {
|
|
358
|
+
i2 += 2;
|
|
359
|
+
while (i2 < src.length && !(src[i2 - 1] === "*" && src[i2] === "/")) i2++;
|
|
360
|
+
i2++;
|
|
361
361
|
continue;
|
|
362
362
|
}
|
|
363
|
-
if (
|
|
363
|
+
if (c2 === "(" || c2 === "{" || c2 === "[") {
|
|
364
364
|
depth++;
|
|
365
|
-
|
|
365
|
+
i2++;
|
|
366
366
|
continue;
|
|
367
367
|
}
|
|
368
|
-
if (
|
|
368
|
+
if (c2 === ")" || c2 === "}" || c2 === "]") {
|
|
369
369
|
depth--;
|
|
370
|
-
|
|
370
|
+
i2++;
|
|
371
371
|
continue;
|
|
372
372
|
}
|
|
373
|
-
if (
|
|
374
|
-
|
|
373
|
+
if (c2 === ";" && depth === 0) return i2;
|
|
374
|
+
i2++;
|
|
375
375
|
}
|
|
376
|
-
return
|
|
376
|
+
return i2;
|
|
377
377
|
}
|
|
378
|
-
function
|
|
378
|
+
function extract_identifier_assignments(src) {
|
|
379
379
|
const out = /* @__PURE__ */ new Map();
|
|
380
380
|
const re = /(?:^|[^\w$])(?:export\s+)?(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*(?::[^=\n;]{1,256})?=\s*/gm;
|
|
381
|
-
let
|
|
382
|
-
while ((
|
|
383
|
-
const ident =
|
|
381
|
+
let m;
|
|
382
|
+
while ((m = re.exec(src)) !== null) {
|
|
383
|
+
const ident = m[1];
|
|
384
384
|
if (out.has(ident)) {
|
|
385
385
|
continue;
|
|
386
386
|
}
|
|
387
|
-
const start =
|
|
388
|
-
const end =
|
|
389
|
-
const
|
|
390
|
-
if (
|
|
387
|
+
const start = m.index + m[0].length;
|
|
388
|
+
const end = read_top_level_expression(src, start);
|
|
389
|
+
const text2 = src.slice(start, end).trim();
|
|
390
|
+
if (text2) out.set(ident, text2);
|
|
391
391
|
re.lastIndex = end;
|
|
392
392
|
}
|
|
393
393
|
return out;
|
|
394
394
|
}
|
|
395
|
-
function
|
|
395
|
+
function find_identifier_object_literal(src, ident) {
|
|
396
396
|
const re = new RegExp(
|
|
397
397
|
`(?:^|[^\\w$])(?:const|let|var)\\s+${ident}\\b\\s*(?::[^=\\n;]+)?=\\s*`,
|
|
398
398
|
"m"
|
|
399
399
|
);
|
|
400
|
-
const
|
|
401
|
-
if (!
|
|
402
|
-
const after =
|
|
403
|
-
const skipped =
|
|
400
|
+
const m = re.exec(src);
|
|
401
|
+
if (!m) return -1;
|
|
402
|
+
const after = m.index + m[0].length;
|
|
403
|
+
const skipped = skip_trivia(src, after);
|
|
404
404
|
return src[skipped] === "{" ? skipped : -1;
|
|
405
405
|
}
|
|
406
406
|
var BARE_IDENT_RE = /^[A-Za-z_$][\w$]*$/;
|
|
407
|
-
function
|
|
407
|
+
function extract_schemas_from_source(src, event_names, external) {
|
|
408
408
|
const out = /* @__PURE__ */ new Map();
|
|
409
|
-
if (!src ||
|
|
410
|
-
const
|
|
411
|
-
const deref = (
|
|
412
|
-
const
|
|
413
|
-
let
|
|
414
|
-
while ((
|
|
415
|
-
let
|
|
416
|
-
if (
|
|
417
|
-
const start =
|
|
418
|
-
while (
|
|
419
|
-
const ident = src.slice(start,
|
|
420
|
-
const
|
|
421
|
-
if (
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
if (src[
|
|
425
|
-
const parsed =
|
|
409
|
+
if (!src || event_names.size === 0) return out;
|
|
410
|
+
const local_idents = extract_identifier_assignments(src);
|
|
411
|
+
const deref = (text2) => BARE_IDENT_RE.test(text2) ? local_idents.get(text2) ?? external?.get(text2) ?? text2 : text2;
|
|
412
|
+
const emits_re = /\.emits\s*\(/g;
|
|
413
|
+
let m;
|
|
414
|
+
while ((m = emits_re.exec(src)) !== null) {
|
|
415
|
+
let i2 = skip_trivia(src, emits_re.lastIndex);
|
|
416
|
+
if (is_ident(src[i2])) {
|
|
417
|
+
const start = i2;
|
|
418
|
+
while (is_ident(src[i2])) i2++;
|
|
419
|
+
const ident = src.slice(start, i2);
|
|
420
|
+
const obj_start = find_identifier_object_literal(src, ident);
|
|
421
|
+
if (obj_start < 0) continue;
|
|
422
|
+
i2 = obj_start;
|
|
423
|
+
}
|
|
424
|
+
if (src[i2] !== "{") continue;
|
|
425
|
+
const parsed = parse_object_literal(src, i2);
|
|
426
426
|
if (!parsed) continue;
|
|
427
|
-
for (const
|
|
428
|
-
if (!
|
|
429
|
-
const raw = src.slice(
|
|
430
|
-
const
|
|
431
|
-
if (
|
|
427
|
+
for (const e of parsed.entries) {
|
|
428
|
+
if (!event_names.has(e.key)) continue;
|
|
429
|
+
const raw = src.slice(e.value_start, e.value_end).trim();
|
|
430
|
+
const text2 = deref(raw);
|
|
431
|
+
if (text2) out.set(e.key, text2);
|
|
432
432
|
}
|
|
433
|
-
|
|
433
|
+
emits_re.lastIndex = Math.max(emits_re.lastIndex, parsed.end_brace + 1);
|
|
434
434
|
}
|
|
435
435
|
return out;
|
|
436
436
|
}
|
|
437
437
|
|
|
438
438
|
// src/client/lib/build-model.ts
|
|
439
439
|
var _stateIdx = 0;
|
|
440
|
-
function
|
|
441
|
-
const events =
|
|
440
|
+
function build_state(model, st) {
|
|
441
|
+
const events = st.events ?? {};
|
|
442
442
|
for (const [name, schema] of Object.entries(events)) {
|
|
443
443
|
if (schema === void 0)
|
|
444
444
|
return { error: `Event "${name}" has undefined schema` };
|
|
445
445
|
}
|
|
446
|
-
const
|
|
447
|
-
for (const [name, schema] of Object.entries(
|
|
446
|
+
const raw_actions = st.actions ?? {};
|
|
447
|
+
for (const [name, schema] of Object.entries(raw_actions)) {
|
|
448
448
|
if (name.startsWith("__emits_")) continue;
|
|
449
449
|
if (schema === void 0)
|
|
450
450
|
return { error: `Action "${name}" has undefined schema` };
|
|
451
451
|
}
|
|
452
|
-
const
|
|
453
|
-
const
|
|
454
|
-
const
|
|
455
|
-
for (const
|
|
456
|
-
|
|
457
|
-
name:
|
|
458
|
-
hasCustomPatch:
|
|
452
|
+
const domain_name = st.name;
|
|
453
|
+
const unique_key = `${domain_name}:${_stateIdx++}`;
|
|
454
|
+
const event_nodes = [];
|
|
455
|
+
for (const event_name of Object.keys(events)) {
|
|
456
|
+
event_nodes.push({
|
|
457
|
+
name: event_name,
|
|
458
|
+
hasCustomPatch: st.patches?.has(event_name) ?? false,
|
|
459
459
|
// Stash the runtime Zod schema so the JSON Schema exporter can
|
|
460
460
|
// call `z.toJSONSchema(zod)` later without re-running the parser.
|
|
461
|
-
zod: events[
|
|
461
|
+
zod: events[event_name]
|
|
462
462
|
});
|
|
463
463
|
}
|
|
464
|
-
const
|
|
465
|
-
for (const
|
|
466
|
-
if (
|
|
467
|
-
const emits =
|
|
468
|
-
const invariants = (
|
|
464
|
+
const action_nodes = [];
|
|
465
|
+
for (const action_name of Object.keys(raw_actions)) {
|
|
466
|
+
if (action_name.startsWith("__emits_")) continue;
|
|
467
|
+
const emits = raw_actions[`__emits_${action_name}`] ?? [];
|
|
468
|
+
const invariants = (st.given?.[action_name] ?? []).map(
|
|
469
469
|
(inv) => inv.description ?? ""
|
|
470
470
|
);
|
|
471
|
-
|
|
471
|
+
action_nodes.push({ name: action_name, emits, invariants });
|
|
472
472
|
}
|
|
473
473
|
const node = {
|
|
474
|
-
name:
|
|
475
|
-
varName:
|
|
476
|
-
events:
|
|
477
|
-
actions:
|
|
478
|
-
file:
|
|
474
|
+
name: domain_name,
|
|
475
|
+
varName: unique_key,
|
|
476
|
+
events: event_nodes,
|
|
477
|
+
actions: action_nodes,
|
|
478
|
+
file: st._sourceFile
|
|
479
479
|
};
|
|
480
480
|
model.states.push(node);
|
|
481
|
-
|
|
482
|
-
return { key:
|
|
481
|
+
st._modelKey = unique_key;
|
|
482
|
+
return { key: unique_key, node };
|
|
483
483
|
}
|
|
484
|
-
function
|
|
485
|
-
const fallbacks = reactions.filter((
|
|
484
|
+
function fixup_reactions(reactions, files, source_file) {
|
|
485
|
+
const fallbacks = reactions.filter((r2) => r2.handlerName.startsWith("on "));
|
|
486
486
|
if (fallbacks.length === 0) return;
|
|
487
|
-
const src =
|
|
487
|
+
const src = source_file ? files.find((f) => f.path === source_file)?.content : files.map((f) => f.content).join("\n");
|
|
488
488
|
if (!src) return;
|
|
489
|
-
const
|
|
489
|
+
const do_re = /\.on\(\s*["'`](\w+)["'`]\s*\)\s*\.do\(\s*(?:async\s+)?(?:function\s+(\w+)|(?:\w+\.)?(\w+))?/g;
|
|
490
490
|
let dm;
|
|
491
|
-
while ((dm =
|
|
492
|
-
const
|
|
491
|
+
while ((dm = do_re.exec(src)) !== null) {
|
|
492
|
+
const event_name = dm[1];
|
|
493
493
|
const handlerName = dm[2] || dm[3];
|
|
494
494
|
if (!handlerName) continue;
|
|
495
|
-
const
|
|
496
|
-
(
|
|
495
|
+
const r2 = fallbacks.find(
|
|
496
|
+
(r3) => r3.event === event_name && r3.handlerName === `on ${event_name}`
|
|
497
497
|
);
|
|
498
|
-
if (
|
|
498
|
+
if (r2) r2.handlerName = handlerName;
|
|
499
499
|
}
|
|
500
500
|
}
|
|
501
|
-
function
|
|
502
|
-
const
|
|
503
|
-
const
|
|
504
|
-
const
|
|
505
|
-
(
|
|
501
|
+
function build_model(result, files, expected_slices) {
|
|
502
|
+
const raw_states = result.states.filter((s) => s && s._tag === "State");
|
|
503
|
+
const raw_slices = result.slices.filter((s) => s && s._tag === "Slice");
|
|
504
|
+
const raw_projections = result.projections.filter(
|
|
505
|
+
(p) => p && p._tag === "Projection"
|
|
506
506
|
);
|
|
507
|
-
const
|
|
508
|
-
const
|
|
507
|
+
const raw_acts = result.acts.filter((a2) => a2 && a2._tag === "Act");
|
|
508
|
+
const state_by_ref = /* @__PURE__ */ new Map();
|
|
509
509
|
const model = {
|
|
510
510
|
entries: [],
|
|
511
511
|
states: [],
|
|
@@ -513,89 +513,89 @@ function buildModel(result, files, expectedSlices) {
|
|
|
513
513
|
projections: [],
|
|
514
514
|
reactions: []
|
|
515
515
|
};
|
|
516
|
-
for (const
|
|
517
|
-
if (
|
|
516
|
+
for (const st of raw_states) {
|
|
517
|
+
if (state_by_ref.has(st)) continue;
|
|
518
518
|
try {
|
|
519
|
-
|
|
520
|
-
} catch (
|
|
521
|
-
|
|
522
|
-
error:
|
|
519
|
+
state_by_ref.set(st, build_state(model, st));
|
|
520
|
+
} catch (e) {
|
|
521
|
+
state_by_ref.set(st, {
|
|
522
|
+
error: e instanceof Error ? e.message : String(e)
|
|
523
523
|
});
|
|
524
524
|
}
|
|
525
525
|
}
|
|
526
|
-
for (const
|
|
527
|
-
for (const
|
|
528
|
-
if (!
|
|
526
|
+
for (const a2 of raw_acts) {
|
|
527
|
+
for (const st of a2.states ?? []) {
|
|
528
|
+
if (!st || st._tag !== "State" || state_by_ref.has(st)) continue;
|
|
529
529
|
try {
|
|
530
|
-
|
|
531
|
-
} catch (
|
|
532
|
-
|
|
533
|
-
error:
|
|
530
|
+
state_by_ref.set(st, build_state(model, st));
|
|
531
|
+
} catch (e) {
|
|
532
|
+
state_by_ref.set(st, {
|
|
533
|
+
error: e instanceof Error ? e.message : String(e)
|
|
534
534
|
});
|
|
535
535
|
}
|
|
536
536
|
}
|
|
537
537
|
}
|
|
538
|
-
const
|
|
539
|
-
for (const s of
|
|
540
|
-
const
|
|
541
|
-
|
|
538
|
+
const built_slice_names = /* @__PURE__ */ new Set();
|
|
539
|
+
for (const s of raw_slices) {
|
|
540
|
+
const slice_name = s._varName ?? "slice";
|
|
541
|
+
built_slice_names.add(slice_name);
|
|
542
542
|
try {
|
|
543
543
|
try {
|
|
544
|
-
|
|
544
|
+
fixup_reactions(s.reactions, files);
|
|
545
545
|
} catch {
|
|
546
546
|
}
|
|
547
|
-
const
|
|
547
|
+
const slice_state_keys = [];
|
|
548
548
|
const errors = [];
|
|
549
|
-
for (const
|
|
550
|
-
if (!
|
|
551
|
-
const fileErr = [...result.
|
|
549
|
+
for (const st of s.states ?? []) {
|
|
550
|
+
if (!st || typeof st !== "object") {
|
|
551
|
+
const fileErr = [...result.file_errors.values()][0];
|
|
552
552
|
errors.push(fileErr ?? "Missing state (broken import)");
|
|
553
553
|
continue;
|
|
554
554
|
}
|
|
555
|
-
const built =
|
|
555
|
+
const built = state_by_ref.get(st);
|
|
556
556
|
if (built) {
|
|
557
557
|
if ("error" in built) {
|
|
558
558
|
errors.push(built.error);
|
|
559
559
|
} else {
|
|
560
|
-
|
|
560
|
+
slice_state_keys.push(built.key);
|
|
561
561
|
}
|
|
562
562
|
} else {
|
|
563
563
|
try {
|
|
564
|
-
const result2 =
|
|
565
|
-
|
|
564
|
+
const result2 = build_state(model, st);
|
|
565
|
+
state_by_ref.set(st, result2);
|
|
566
566
|
if ("error" in result2) {
|
|
567
567
|
errors.push(result2.error);
|
|
568
568
|
} else {
|
|
569
|
-
|
|
569
|
+
slice_state_keys.push(result2.key);
|
|
570
570
|
}
|
|
571
|
-
} catch (
|
|
572
|
-
const msg =
|
|
573
|
-
|
|
571
|
+
} catch (e) {
|
|
572
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
573
|
+
state_by_ref.set(st, { error: msg });
|
|
574
574
|
errors.push(msg);
|
|
575
575
|
}
|
|
576
576
|
}
|
|
577
577
|
}
|
|
578
|
-
const
|
|
579
|
-
for (const
|
|
580
|
-
if (
|
|
578
|
+
const proj_names = [];
|
|
579
|
+
for (const p of s.projections ?? []) {
|
|
580
|
+
if (p && p._tag === "Projection") proj_names.push(p.target);
|
|
581
581
|
}
|
|
582
|
-
const
|
|
582
|
+
const slice_file = s._sourceFile;
|
|
583
583
|
model.slices.push({
|
|
584
|
-
name:
|
|
585
|
-
states:
|
|
586
|
-
stateVars:
|
|
587
|
-
projections:
|
|
588
|
-
reactions: (s.reactions ?? []).map((
|
|
589
|
-
...
|
|
590
|
-
file:
|
|
584
|
+
name: slice_name,
|
|
585
|
+
states: slice_state_keys,
|
|
586
|
+
stateVars: slice_state_keys,
|
|
587
|
+
projections: proj_names,
|
|
588
|
+
reactions: (s.reactions ?? []).map((r2) => ({
|
|
589
|
+
...r2,
|
|
590
|
+
file: r2.file ?? slice_file
|
|
591
591
|
})),
|
|
592
|
-
file:
|
|
592
|
+
file: slice_file,
|
|
593
593
|
error: errors.length > 0 ? errors.join("; ") : void 0
|
|
594
594
|
});
|
|
595
|
-
} catch (
|
|
596
|
-
const msg =
|
|
595
|
+
} catch (e) {
|
|
596
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
597
597
|
model.slices.push({
|
|
598
|
-
name:
|
|
598
|
+
name: slice_name,
|
|
599
599
|
states: [],
|
|
600
600
|
stateVars: [],
|
|
601
601
|
projections: [],
|
|
@@ -605,109 +605,111 @@ function buildModel(result, files, expectedSlices) {
|
|
|
605
605
|
});
|
|
606
606
|
}
|
|
607
607
|
}
|
|
608
|
-
for (const [name,
|
|
609
|
-
if (!
|
|
608
|
+
for (const [name, file_path] of expected_slices) {
|
|
609
|
+
if (!built_slice_names.has(name)) {
|
|
610
610
|
model.slices.push({
|
|
611
611
|
name,
|
|
612
612
|
states: [],
|
|
613
613
|
stateVars: [],
|
|
614
614
|
projections: [],
|
|
615
615
|
reactions: [],
|
|
616
|
-
error: result.
|
|
617
|
-
file:
|
|
616
|
+
error: result.file_errors.get(file_path) ?? result.error ?? "Failed to build slice",
|
|
617
|
+
file: file_path
|
|
618
618
|
});
|
|
619
619
|
}
|
|
620
620
|
}
|
|
621
|
-
const
|
|
622
|
-
const
|
|
623
|
-
for (const
|
|
624
|
-
|
|
625
|
-
for (const [ident, expr] of
|
|
626
|
-
if (!
|
|
621
|
+
const source_by_path = /* @__PURE__ */ new Map();
|
|
622
|
+
const external_idents = /* @__PURE__ */ new Map();
|
|
623
|
+
for (const f of files) {
|
|
624
|
+
source_by_path.set(f.path, f.content);
|
|
625
|
+
for (const [ident, expr] of extract_identifier_assignments(f.content)) {
|
|
626
|
+
if (!external_idents.has(ident)) external_idents.set(ident, expr);
|
|
627
627
|
}
|
|
628
628
|
}
|
|
629
|
-
for (const
|
|
630
|
-
if (!
|
|
631
|
-
const src =
|
|
632
|
-
const names = new Set(
|
|
629
|
+
for (const st_node of model.states) {
|
|
630
|
+
if (!st_node.file) continue;
|
|
631
|
+
const src = source_by_path.get(st_node.file);
|
|
632
|
+
const names = new Set(st_node.events.map((e) => e.name));
|
|
633
633
|
if (names.size === 0) continue;
|
|
634
|
-
const schemas =
|
|
635
|
-
for (const ev of
|
|
634
|
+
const schemas = extract_schemas_from_source(src, names, external_idents);
|
|
635
|
+
for (const ev of st_node.events) {
|
|
636
636
|
ev.schema = schemas.get(ev.name);
|
|
637
637
|
}
|
|
638
638
|
}
|
|
639
|
-
for (const
|
|
639
|
+
for (const p of raw_projections) {
|
|
640
640
|
model.projections.push({
|
|
641
|
-
name:
|
|
642
|
-
varName:
|
|
643
|
-
handles:
|
|
644
|
-
file:
|
|
641
|
+
name: p.target,
|
|
642
|
+
varName: p.target,
|
|
643
|
+
handles: p.handles,
|
|
644
|
+
file: p._sourceFile
|
|
645
645
|
});
|
|
646
646
|
}
|
|
647
|
-
const
|
|
648
|
-
const
|
|
649
|
-
for (const
|
|
647
|
+
const states_in_slices = new Set(model.slices.flatMap((s) => s.states));
|
|
648
|
+
const global_state_keys = model.states.filter((s) => !states_in_slices.has(s.varName)).map((s) => s.varName);
|
|
649
|
+
for (const a2 of raw_acts) {
|
|
650
650
|
try {
|
|
651
|
-
|
|
652
|
-
|
|
651
|
+
fixup_reactions(
|
|
652
|
+
a2.reactions ?? [],
|
|
653
653
|
files,
|
|
654
|
-
|
|
654
|
+
a2._sourceFile
|
|
655
655
|
);
|
|
656
656
|
} catch {
|
|
657
657
|
}
|
|
658
658
|
model.orchestrator = {
|
|
659
659
|
slices: model.slices.map((s) => s.name),
|
|
660
|
-
projections: model.projections.map((
|
|
660
|
+
projections: model.projections.map((p) => p.name),
|
|
661
661
|
states: model.states.map((s) => s.name)
|
|
662
662
|
};
|
|
663
|
-
const
|
|
664
|
-
for (const
|
|
665
|
-
model.reactions.push({ ...
|
|
663
|
+
const act_file = a2._sourceFile;
|
|
664
|
+
for (const r2 of a2.reactions ?? []) {
|
|
665
|
+
model.reactions.push({ ...r2, file: r2.file ?? act_file });
|
|
666
666
|
}
|
|
667
|
-
const
|
|
668
|
-
const
|
|
669
|
-
(
|
|
667
|
+
const entry_path = a2._sourceFile ?? "app.ts";
|
|
668
|
+
const act_slice_names = new Set(
|
|
669
|
+
(a2.slices ?? []).filter((s) => s != null).map((s) => s._varName ?? "").filter(Boolean)
|
|
670
670
|
);
|
|
671
671
|
for (const sl of model.slices) {
|
|
672
|
-
if (sl.error && !
|
|
673
|
-
const
|
|
674
|
-
if (
|
|
675
|
-
|
|
672
|
+
if (sl.error && !act_slice_names.has(sl.name)) {
|
|
673
|
+
const act_src = files.find((f) => f.path === entry_path)?.content ?? "";
|
|
674
|
+
if (act_src.includes(sl.name)) {
|
|
675
|
+
act_slice_names.add(sl.name);
|
|
676
676
|
}
|
|
677
677
|
}
|
|
678
678
|
}
|
|
679
|
-
const
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
679
|
+
const entry_slices = model.slices.filter(
|
|
680
|
+
(s) => act_slice_names.has(s.name)
|
|
681
|
+
);
|
|
682
|
+
const slice_state_keys = new Set(entry_slices.flatMap((s) => s.states));
|
|
683
|
+
const act_state_keys = /* @__PURE__ */ new Set();
|
|
684
|
+
for (const s of a2.states ?? []) {
|
|
683
685
|
try {
|
|
684
686
|
if (s && s._tag === "State") {
|
|
685
|
-
|
|
687
|
+
act_state_keys.add(s._modelKey ?? s.name);
|
|
686
688
|
}
|
|
687
689
|
} catch {
|
|
688
690
|
}
|
|
689
691
|
}
|
|
690
|
-
const
|
|
691
|
-
const
|
|
692
|
-
(
|
|
692
|
+
const all_state_keys = /* @__PURE__ */ new Set([...act_state_keys, ...slice_state_keys]);
|
|
693
|
+
const act_proj_names = new Set(
|
|
694
|
+
(a2.projections ?? []).filter((p) => p && p._tag === "Projection").map((p) => p.target)
|
|
693
695
|
);
|
|
694
|
-
for (const sl of
|
|
695
|
-
for (const pn of sl.projections)
|
|
696
|
+
for (const sl of entry_slices) {
|
|
697
|
+
for (const pn of sl.projections) act_proj_names.add(pn);
|
|
696
698
|
}
|
|
697
699
|
model.entries.push({
|
|
698
|
-
path:
|
|
699
|
-
states: model.states.filter((s) =>
|
|
700
|
-
slices:
|
|
701
|
-
projections: model.projections.filter((
|
|
702
|
-
reactions:
|
|
700
|
+
path: entry_path,
|
|
701
|
+
states: model.states.filter((s) => all_state_keys.has(s.varName)),
|
|
702
|
+
slices: entry_slices,
|
|
703
|
+
projections: model.projections.filter((p) => act_proj_names.has(p.name)),
|
|
704
|
+
reactions: a2.reactions ?? []
|
|
703
705
|
});
|
|
704
706
|
}
|
|
705
|
-
if (
|
|
707
|
+
if (global_state_keys.length > 0 || model.reactions.length > 0) {
|
|
706
708
|
model.slices.push({
|
|
707
709
|
name: "global",
|
|
708
|
-
states:
|
|
709
|
-
stateVars:
|
|
710
|
-
projections: model.projections.map((
|
|
710
|
+
states: global_state_keys,
|
|
711
|
+
stateVars: global_state_keys,
|
|
712
|
+
projections: model.projections.map((p) => p.name),
|
|
711
713
|
reactions: model.reactions
|
|
712
714
|
});
|
|
713
715
|
}
|
|
@@ -728,42 +730,42 @@ function buildModel(result, files, expectedSlices) {
|
|
|
728
730
|
|
|
729
731
|
// src/client/lib/mock-builders.ts
|
|
730
732
|
import { z } from "zod";
|
|
731
|
-
function
|
|
733
|
+
function proxy_target() {
|
|
732
734
|
}
|
|
733
|
-
function
|
|
735
|
+
function attach_emit(info, action_name, handler) {
|
|
734
736
|
const emits = [];
|
|
735
737
|
if (typeof handler === "string") {
|
|
736
738
|
emits.push(handler);
|
|
737
739
|
} else if (typeof handler === "function") {
|
|
738
740
|
const src = String(handler);
|
|
739
|
-
for (const
|
|
740
|
-
if (src.includes(`"${
|
|
741
|
-
emits.push(
|
|
741
|
+
for (const event_name of Object.keys(info.events)) {
|
|
742
|
+
if (src.includes(`"${event_name}"`) || src.includes(`'${event_name}'`) || src.includes(`\`${event_name}\``)) {
|
|
743
|
+
emits.push(event_name);
|
|
742
744
|
}
|
|
743
745
|
}
|
|
744
746
|
if (emits.length === 0) {
|
|
745
747
|
try {
|
|
746
|
-
const
|
|
748
|
+
const deep_proxy = new Proxy(
|
|
747
749
|
{},
|
|
748
750
|
{
|
|
749
|
-
get: () =>
|
|
751
|
+
get: () => deep_proxy,
|
|
750
752
|
has: () => true
|
|
751
753
|
}
|
|
752
754
|
);
|
|
753
|
-
const
|
|
754
|
-
get: () =>
|
|
755
|
-
apply: () =>
|
|
755
|
+
const proxy_fn = new Proxy(proxy_target, {
|
|
756
|
+
get: () => deep_proxy,
|
|
757
|
+
apply: () => deep_proxy
|
|
756
758
|
});
|
|
757
|
-
const
|
|
759
|
+
const dummy_arg = new Proxy(
|
|
758
760
|
{},
|
|
759
761
|
{
|
|
760
|
-
get: (
|
|
761
|
-
if (typeof prop === "string") return
|
|
762
|
+
get: (_t, prop) => {
|
|
763
|
+
if (typeof prop === "string") return proxy_fn;
|
|
762
764
|
return void 0;
|
|
763
765
|
}
|
|
764
766
|
}
|
|
765
767
|
);
|
|
766
|
-
const result = handler(
|
|
768
|
+
const result = handler(dummy_arg, dummy_arg, dummy_arg);
|
|
767
769
|
if (Array.isArray(result) && typeof result[0] === "string") {
|
|
768
770
|
emits.push(result[0]);
|
|
769
771
|
}
|
|
@@ -771,9 +773,9 @@ function attachEmit(info, actionName, handler) {
|
|
|
771
773
|
}
|
|
772
774
|
}
|
|
773
775
|
}
|
|
774
|
-
info.actions[`__emits_${
|
|
776
|
+
info.actions[`__emits_${action_name}`] = emits;
|
|
775
777
|
}
|
|
776
|
-
function
|
|
778
|
+
function mock_state(entry, on_build) {
|
|
777
779
|
const name = Object.keys(entry)[0];
|
|
778
780
|
const info = {
|
|
779
781
|
name,
|
|
@@ -783,29 +785,29 @@ function mockState(entry, onBuild) {
|
|
|
783
785
|
patches: /* @__PURE__ */ new Set(),
|
|
784
786
|
_tag: "State"
|
|
785
787
|
};
|
|
786
|
-
const
|
|
787
|
-
on(
|
|
788
|
-
const
|
|
789
|
-
info.actions[
|
|
788
|
+
const action_builder = (_currentAction) => ({
|
|
789
|
+
on(action_entry) {
|
|
790
|
+
const action_name = Object.keys(action_entry)[0];
|
|
791
|
+
info.actions[action_name] = action_entry[action_name];
|
|
790
792
|
return {
|
|
791
793
|
given(rules) {
|
|
792
|
-
if (rules) info.given[
|
|
794
|
+
if (rules) info.given[action_name] = rules;
|
|
793
795
|
return {
|
|
794
796
|
emit(handler) {
|
|
795
|
-
|
|
796
|
-
return
|
|
797
|
+
attach_emit(info, action_name, handler);
|
|
798
|
+
return action_builder(action_name);
|
|
797
799
|
}
|
|
798
800
|
};
|
|
799
801
|
},
|
|
800
802
|
emit(handler) {
|
|
801
|
-
|
|
802
|
-
return
|
|
803
|
+
attach_emit(info, action_name, handler);
|
|
804
|
+
return action_builder(action_name);
|
|
803
805
|
}
|
|
804
806
|
};
|
|
805
807
|
},
|
|
806
|
-
snap: () =>
|
|
808
|
+
snap: () => action_builder(_currentAction),
|
|
807
809
|
build: () => {
|
|
808
|
-
|
|
810
|
+
on_build?.(info);
|
|
809
811
|
return info;
|
|
810
812
|
}
|
|
811
813
|
});
|
|
@@ -815,36 +817,36 @@ function mockState(entry, onBuild) {
|
|
|
815
817
|
emits(events) {
|
|
816
818
|
info.events = events ?? {};
|
|
817
819
|
return {
|
|
818
|
-
...
|
|
820
|
+
...action_builder(),
|
|
819
821
|
patch(patches) {
|
|
820
822
|
if (patches)
|
|
821
|
-
for (const
|
|
822
|
-
return
|
|
823
|
+
for (const k of Object.keys(patches)) info.patches.add(k);
|
|
824
|
+
return action_builder();
|
|
823
825
|
}
|
|
824
826
|
};
|
|
825
827
|
}
|
|
826
828
|
})
|
|
827
829
|
};
|
|
828
830
|
}
|
|
829
|
-
function
|
|
831
|
+
function capture_dispatches(handler) {
|
|
830
832
|
const dispatches = [];
|
|
831
833
|
if (typeof handler !== "function") return dispatches;
|
|
832
834
|
try {
|
|
833
|
-
const
|
|
834
|
-
const
|
|
835
|
-
do: (
|
|
836
|
-
if (typeof
|
|
837
|
-
dispatches.push(
|
|
835
|
+
const safe_proxy = () => new Proxy({}, { get: () => "" });
|
|
836
|
+
const mock_app = {
|
|
837
|
+
do: (action_name) => {
|
|
838
|
+
if (typeof action_name === "string" && !dispatches.includes(action_name))
|
|
839
|
+
dispatches.push(action_name);
|
|
838
840
|
return Promise.resolve([]);
|
|
839
841
|
},
|
|
840
|
-
load: () => Promise.resolve({ state:
|
|
842
|
+
load: () => Promise.resolve({ state: safe_proxy(), version: 0 }),
|
|
841
843
|
query: () => Promise.resolve({ count: 0 }),
|
|
842
844
|
query_array: () => Promise.resolve([])
|
|
843
845
|
};
|
|
844
|
-
const
|
|
846
|
+
const mock_event = new Proxy({}, {
|
|
845
847
|
get: (_, prop) => prop === "stream" ? "mock" : prop === "data" ? new Proxy({}, { get: () => "" }) : ""
|
|
846
848
|
});
|
|
847
|
-
const result = handler(
|
|
849
|
+
const result = handler(mock_event, "mock", mock_app);
|
|
848
850
|
if (result && typeof result.catch === "function") {
|
|
849
851
|
result.catch(() => {
|
|
850
852
|
});
|
|
@@ -854,14 +856,14 @@ function captureDispatches(handler) {
|
|
|
854
856
|
if (dispatches.length === 0) {
|
|
855
857
|
const src = String(handler);
|
|
856
858
|
const re = /\.do\(\s*["'](\w+)["']/g;
|
|
857
|
-
let
|
|
858
|
-
while ((
|
|
859
|
-
if (!dispatches.includes(
|
|
859
|
+
let m;
|
|
860
|
+
while ((m = re.exec(src)) !== null) {
|
|
861
|
+
if (!dispatches.includes(m[1])) dispatches.push(m[1]);
|
|
860
862
|
}
|
|
861
863
|
}
|
|
862
864
|
return dispatches;
|
|
863
865
|
}
|
|
864
|
-
function
|
|
866
|
+
function mock_slice(on_build) {
|
|
865
867
|
const info = {
|
|
866
868
|
_tag: "Slice",
|
|
867
869
|
states: [],
|
|
@@ -873,17 +875,17 @@ function mockSlice(onBuild) {
|
|
|
873
875
|
info.states.push(s ?? null);
|
|
874
876
|
return builder;
|
|
875
877
|
},
|
|
876
|
-
withProjection(
|
|
877
|
-
if (
|
|
878
|
+
withProjection(p) {
|
|
879
|
+
if (p) info.projections.push(p);
|
|
878
880
|
return builder;
|
|
879
881
|
},
|
|
880
|
-
on(
|
|
882
|
+
on(event_name) {
|
|
881
883
|
return {
|
|
882
884
|
do(handler) {
|
|
883
|
-
const dispatches =
|
|
885
|
+
const dispatches = capture_dispatches(handler);
|
|
884
886
|
const reaction = {
|
|
885
|
-
event:
|
|
886
|
-
handlerName: typeof handler?.name === "string" && handler.name || `on ${
|
|
887
|
+
event: event_name,
|
|
888
|
+
handlerName: typeof handler?.name === "string" && handler.name || `on ${event_name}`,
|
|
887
889
|
dispatches
|
|
888
890
|
};
|
|
889
891
|
info.reactions.push(reaction);
|
|
@@ -897,22 +899,22 @@ function mockSlice(onBuild) {
|
|
|
897
899
|
};
|
|
898
900
|
},
|
|
899
901
|
build: () => {
|
|
900
|
-
|
|
902
|
+
on_build?.(info);
|
|
901
903
|
return info;
|
|
902
904
|
}
|
|
903
905
|
};
|
|
904
906
|
return builder;
|
|
905
907
|
}
|
|
906
|
-
function
|
|
908
|
+
function mock_projection(target, on_build) {
|
|
907
909
|
const info = {
|
|
908
910
|
_tag: "Projection",
|
|
909
911
|
target: target || "projection",
|
|
910
912
|
handles: []
|
|
911
913
|
};
|
|
912
914
|
const builder = {
|
|
913
|
-
on(
|
|
914
|
-
const
|
|
915
|
-
info.handles.push(
|
|
915
|
+
on(event_entry) {
|
|
916
|
+
const event_name = Object.keys(event_entry)[0];
|
|
917
|
+
info.handles.push(event_name);
|
|
916
918
|
return {
|
|
917
919
|
do() {
|
|
918
920
|
return {
|
|
@@ -926,13 +928,13 @@ function mockProjection(target, onBuild) {
|
|
|
926
928
|
};
|
|
927
929
|
},
|
|
928
930
|
build: () => {
|
|
929
|
-
|
|
931
|
+
on_build?.(info);
|
|
930
932
|
return info;
|
|
931
933
|
}
|
|
932
934
|
};
|
|
933
935
|
return builder;
|
|
934
936
|
}
|
|
935
|
-
function
|
|
937
|
+
function mock_act(on_build) {
|
|
936
938
|
const info = {
|
|
937
939
|
_tag: "Act",
|
|
938
940
|
states: [],
|
|
@@ -949,18 +951,18 @@ function mockAct(onBuild) {
|
|
|
949
951
|
info.slices.push(s ?? null);
|
|
950
952
|
return builder;
|
|
951
953
|
},
|
|
952
|
-
withProjection(
|
|
953
|
-
if (
|
|
954
|
+
withProjection(p) {
|
|
955
|
+
if (p) info.projections.push(p);
|
|
954
956
|
return builder;
|
|
955
957
|
},
|
|
956
958
|
withActor: () => builder,
|
|
957
|
-
on(
|
|
959
|
+
on(event_name) {
|
|
958
960
|
return {
|
|
959
961
|
do(handler) {
|
|
960
|
-
const dispatches =
|
|
962
|
+
const dispatches = capture_dispatches(handler);
|
|
961
963
|
const reaction = {
|
|
962
|
-
event:
|
|
963
|
-
handlerName: typeof handler?.name === "string" && handler.name || `on ${
|
|
964
|
+
event: event_name,
|
|
965
|
+
handlerName: typeof handler?.name === "string" && handler.name || `on ${event_name}`,
|
|
964
966
|
dispatches
|
|
965
967
|
};
|
|
966
968
|
info.reactions.push(reaction);
|
|
@@ -974,10 +976,10 @@ function mockAct(onBuild) {
|
|
|
974
976
|
};
|
|
975
977
|
},
|
|
976
978
|
build: () => {
|
|
977
|
-
const noop = () =>
|
|
978
|
-
const
|
|
979
|
+
const noop = () => act_stub;
|
|
980
|
+
const act_stub = {
|
|
979
981
|
...info,
|
|
980
|
-
on: () =>
|
|
982
|
+
on: () => act_stub,
|
|
981
983
|
do: () => Promise.resolve([]),
|
|
982
984
|
load: () => Promise.resolve({}),
|
|
983
985
|
drain: () => Promise.resolve(),
|
|
@@ -986,8 +988,8 @@ function mockAct(onBuild) {
|
|
|
986
988
|
start_correlations: noop,
|
|
987
989
|
query_array: () => Promise.resolve([])
|
|
988
990
|
};
|
|
989
|
-
|
|
990
|
-
return
|
|
991
|
+
on_build?.(act_stub);
|
|
992
|
+
return act_stub;
|
|
991
993
|
}
|
|
992
994
|
};
|
|
993
995
|
return builder;
|
|
@@ -998,13 +1000,13 @@ var InvariantError = class extends Error {
|
|
|
998
1000
|
this.name = "InvariantError";
|
|
999
1001
|
}
|
|
1000
1002
|
};
|
|
1001
|
-
var
|
|
1003
|
+
var crypto_mock = { randomUUID: () => "mock-uuid" };
|
|
1002
1004
|
var MODULES = {
|
|
1003
1005
|
"@rotorsoft/act": {
|
|
1004
|
-
state:
|
|
1005
|
-
slice:
|
|
1006
|
-
projection:
|
|
1007
|
-
act:
|
|
1006
|
+
state: mock_state,
|
|
1007
|
+
slice: mock_slice,
|
|
1008
|
+
projection: mock_projection,
|
|
1009
|
+
act: mock_act,
|
|
1008
1010
|
store: () => ({
|
|
1009
1011
|
seed: () => Promise.resolve(),
|
|
1010
1012
|
drop: () => Promise.resolve(),
|
|
@@ -1017,10 +1019,10 @@ var MODULES = {
|
|
|
1017
1019
|
InvariantError
|
|
1018
1020
|
},
|
|
1019
1021
|
zod: { z, ...z },
|
|
1020
|
-
crypto:
|
|
1021
|
-
"node:crypto":
|
|
1022
|
+
crypto: crypto_mock,
|
|
1023
|
+
"node:crypto": crypto_mock
|
|
1022
1024
|
};
|
|
1023
|
-
function
|
|
1025
|
+
function unknown_module_proxy() {
|
|
1024
1026
|
const handler = {
|
|
1025
1027
|
get(_target, prop) {
|
|
1026
1028
|
if (prop === Symbol.toPrimitive) return () => "";
|
|
@@ -1037,97 +1039,97 @@ function unknownModuleProxy() {
|
|
|
1037
1039
|
return true;
|
|
1038
1040
|
}
|
|
1039
1041
|
};
|
|
1040
|
-
const proxy = new Proxy(
|
|
1042
|
+
const proxy = new Proxy(proxy_target, handler);
|
|
1041
1043
|
return proxy;
|
|
1042
1044
|
}
|
|
1043
1045
|
|
|
1044
1046
|
// src/client/lib/sort.ts
|
|
1045
|
-
function
|
|
1046
|
-
if (
|
|
1047
|
-
const strip = (
|
|
1048
|
-
const
|
|
1049
|
-
for (const
|
|
1050
|
-
|
|
1047
|
+
function topo_sort(ts_files) {
|
|
1048
|
+
if (ts_files.length <= 1) return ts_files;
|
|
1049
|
+
const strip = (p) => p.replace(/\.tsx?$/, "");
|
|
1050
|
+
const by_key = /* @__PURE__ */ new Map();
|
|
1051
|
+
for (const f of ts_files) {
|
|
1052
|
+
by_key.set(strip(f.path), f);
|
|
1051
1053
|
}
|
|
1052
1054
|
const deps = /* @__PURE__ */ new Map();
|
|
1053
|
-
for (const
|
|
1054
|
-
const key = strip(
|
|
1055
|
-
const
|
|
1056
|
-
deps.set(key,
|
|
1057
|
-
const
|
|
1058
|
-
let
|
|
1059
|
-
while ((
|
|
1060
|
-
const imp =
|
|
1061
|
-
const resolved = resolve(imp, key,
|
|
1062
|
-
if (resolved &&
|
|
1055
|
+
for (const f of ts_files) {
|
|
1056
|
+
const key = strip(f.path);
|
|
1057
|
+
const file_deps = /* @__PURE__ */ new Set();
|
|
1058
|
+
deps.set(key, file_deps);
|
|
1059
|
+
const from_re = /from\s+["']([^"']+)["']/g;
|
|
1060
|
+
let m;
|
|
1061
|
+
while ((m = from_re.exec(f.content)) !== null) {
|
|
1062
|
+
const imp = m[1];
|
|
1063
|
+
const resolved = resolve(imp, key, by_key);
|
|
1064
|
+
if (resolved && by_key.has(resolved)) file_deps.add(resolved);
|
|
1063
1065
|
}
|
|
1064
1066
|
}
|
|
1065
|
-
const
|
|
1066
|
-
for (const
|
|
1067
|
-
for (const [,
|
|
1068
|
-
for (const dep of
|
|
1069
|
-
|
|
1067
|
+
const in_degree = /* @__PURE__ */ new Map();
|
|
1068
|
+
for (const f of ts_files) in_degree.set(strip(f.path), 0);
|
|
1069
|
+
for (const [, file_deps] of deps) {
|
|
1070
|
+
for (const dep of file_deps) {
|
|
1071
|
+
in_degree.set(dep, in_degree.get(dep) + 1);
|
|
1070
1072
|
}
|
|
1071
1073
|
}
|
|
1072
1074
|
const queue = [];
|
|
1073
|
-
for (const [key, _deg] of
|
|
1075
|
+
for (const [key, _deg] of in_degree) {
|
|
1074
1076
|
if (deps.get(key)?.size === 0) queue.push(key);
|
|
1075
1077
|
}
|
|
1076
1078
|
const order = [];
|
|
1077
1079
|
while (queue.length > 0) {
|
|
1078
1080
|
const key = queue.shift();
|
|
1079
1081
|
order.push(key);
|
|
1080
|
-
for (const [other,
|
|
1081
|
-
if (
|
|
1082
|
-
|
|
1083
|
-
if (
|
|
1082
|
+
for (const [other, file_deps] of deps) {
|
|
1083
|
+
if (file_deps.has(key)) {
|
|
1084
|
+
file_deps.delete(key);
|
|
1085
|
+
if (file_deps.size === 0) queue.push(other);
|
|
1084
1086
|
}
|
|
1085
1087
|
}
|
|
1086
1088
|
}
|
|
1087
|
-
for (const
|
|
1088
|
-
const key = strip(
|
|
1089
|
+
for (const f of ts_files) {
|
|
1090
|
+
const key = strip(f.path);
|
|
1089
1091
|
if (!order.includes(key)) order.push(key);
|
|
1090
1092
|
}
|
|
1091
|
-
return order.map((
|
|
1093
|
+
return order.map((k) => by_key.get(k)).filter(Boolean);
|
|
1092
1094
|
}
|
|
1093
|
-
function resolve(imp,
|
|
1095
|
+
function resolve(imp, from_path, by_key) {
|
|
1094
1096
|
if (imp.startsWith(".")) {
|
|
1095
|
-
const dir =
|
|
1097
|
+
const dir = from_path.includes("/") ? from_path.slice(0, from_path.lastIndexOf("/")) : "";
|
|
1096
1098
|
const parts = (dir ? dir + "/" + imp : imp).split("/");
|
|
1097
1099
|
const resolved = [];
|
|
1098
|
-
for (const
|
|
1099
|
-
if (
|
|
1100
|
-
if (
|
|
1101
|
-
else resolved.push(
|
|
1100
|
+
for (const p of parts) {
|
|
1101
|
+
if (p === "." || p === "") continue;
|
|
1102
|
+
if (p === "..") resolved.pop();
|
|
1103
|
+
else resolved.push(p);
|
|
1102
1104
|
}
|
|
1103
1105
|
return resolved.join("/").replace(/\.js$/, "").replace(/\.ts$/, "");
|
|
1104
1106
|
}
|
|
1105
1107
|
if (imp.startsWith("@") && !imp.startsWith("@rotorsoft/")) {
|
|
1106
|
-
const
|
|
1107
|
-
if (
|
|
1108
|
+
const pkg_name = imp.split("/")[1];
|
|
1109
|
+
if (pkg_name) {
|
|
1108
1110
|
for (const candidate of [
|
|
1109
|
-
`packages/${
|
|
1110
|
-
`${
|
|
1111
|
-
`${
|
|
1111
|
+
`packages/${pkg_name}/src/index`,
|
|
1112
|
+
`${pkg_name}/src/index`,
|
|
1113
|
+
`${pkg_name}/index`
|
|
1112
1114
|
]) {
|
|
1113
|
-
if (
|
|
1115
|
+
if (by_key?.has(candidate)) return candidate;
|
|
1114
1116
|
}
|
|
1115
|
-
return `packages/${
|
|
1117
|
+
return `packages/${pkg_name}/src/index`;
|
|
1116
1118
|
}
|
|
1117
1119
|
}
|
|
1118
1120
|
return void 0;
|
|
1119
1121
|
}
|
|
1120
1122
|
|
|
1121
1123
|
// src/client/lib/evaluate.ts
|
|
1122
|
-
var
|
|
1123
|
-
const blank = (
|
|
1124
|
+
var strip_non_code = (src, level = "full") => {
|
|
1125
|
+
const blank = (m) => m.replace(/[^\n]/g, " ");
|
|
1124
1126
|
let result = src.replace(/\/\/[^\n]*/g, blank).replace(/\/\*[\s\S]*?\*\//g, blank).replace(/`(?:\\[\s\S]|[^`\\])*`/g, blank);
|
|
1125
1127
|
if (level === "full") {
|
|
1126
1128
|
result = result.replace(/"(?:\\[\s\S]|[^"\\])*"/g, blank).replace(/'(?:\\[\s\S]|[^'\\])*'/g, blank);
|
|
1127
1129
|
}
|
|
1128
1130
|
return result;
|
|
1129
1131
|
};
|
|
1130
|
-
var
|
|
1132
|
+
var is_source_file = (f) => f.path.endsWith(".ts") && !f.path.endsWith(".d.ts") && !f.path.endsWith(".tsx") && !f.path.endsWith(".spec.ts") && !f.path.endsWith(".test.ts") && !f.path.includes("node_modules/") && !f.path.includes("__tests__/") && !f.path.includes("/test/") && !f.path.startsWith("test/");
|
|
1131
1133
|
function transpile(code) {
|
|
1132
1134
|
try {
|
|
1133
1135
|
const safe = code.replace(/\bimport\.meta\.\w+/g, "'__import_meta__'");
|
|
@@ -1149,8 +1151,8 @@ function execute(files) {
|
|
|
1149
1151
|
projections: [],
|
|
1150
1152
|
acts: [],
|
|
1151
1153
|
error: void 0,
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
+
file_errors: /* @__PURE__ */ new Map(),
|
|
1155
|
+
expected_slices: /* @__PURE__ */ new Map()
|
|
1154
1156
|
};
|
|
1155
1157
|
try {
|
|
1156
1158
|
const __built__ = {
|
|
@@ -1164,69 +1166,70 @@ function execute(files) {
|
|
|
1164
1166
|
info._sourceFile = _currentFile;
|
|
1165
1167
|
__built__[type + "s"].push(info);
|
|
1166
1168
|
};
|
|
1167
|
-
const
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1169
|
+
const act_module = { ...MODULES["@rotorsoft/act"] };
|
|
1170
|
+
act_module.state = (entry) => MODULES["@rotorsoft/act"].state(entry, capture("state"));
|
|
1171
|
+
act_module.slice = () => MODULES["@rotorsoft/act"].slice(capture("slice"));
|
|
1172
|
+
act_module.projection = (target) => MODULES["@rotorsoft/act"].projection(
|
|
1171
1173
|
target,
|
|
1172
1174
|
capture("projection")
|
|
1173
1175
|
);
|
|
1174
|
-
|
|
1175
|
-
const
|
|
1176
|
+
act_module.act = () => MODULES["@rotorsoft/act"].act(capture("act"));
|
|
1177
|
+
const pkg_modules = {
|
|
1176
1178
|
...MODULES,
|
|
1177
|
-
"@rotorsoft/act":
|
|
1179
|
+
"@rotorsoft/act": act_module
|
|
1178
1180
|
};
|
|
1179
|
-
const
|
|
1180
|
-
const strip = (
|
|
1181
|
-
const
|
|
1182
|
-
if (
|
|
1181
|
+
const file_exports = /* @__PURE__ */ new Map();
|
|
1182
|
+
const strip = (p) => p.replace(/\.tsx?$/, "");
|
|
1183
|
+
const resolve_module = (mod, from_path) => {
|
|
1184
|
+
if (pkg_modules[mod]) return pkg_modules[mod];
|
|
1183
1185
|
if (mod.startsWith(".")) {
|
|
1184
|
-
const dir =
|
|
1186
|
+
const dir = from_path.includes("/") ? from_path.slice(0, from_path.lastIndexOf("/")) : "";
|
|
1185
1187
|
const parts = (dir ? dir + "/" + mod : mod).split("/");
|
|
1186
1188
|
const resolved = [];
|
|
1187
|
-
for (const
|
|
1188
|
-
if (
|
|
1189
|
-
if (
|
|
1190
|
-
else resolved.push(
|
|
1189
|
+
for (const p of parts) {
|
|
1190
|
+
if (p === "." || p === "") continue;
|
|
1191
|
+
if (p === "..") resolved.pop();
|
|
1192
|
+
else resolved.push(p);
|
|
1191
1193
|
}
|
|
1192
1194
|
const rp = resolved.join("/").replace(/\.js$/, "").replace(/\.ts$/, "");
|
|
1193
|
-
return
|
|
1195
|
+
return file_exports.get(rp) ?? file_exports.get(rp + "/index") ?? {};
|
|
1194
1196
|
}
|
|
1195
1197
|
if (mod.startsWith("@") && !mod.startsWith("@rotorsoft/")) {
|
|
1196
|
-
const
|
|
1197
|
-
const
|
|
1198
|
-
if (
|
|
1199
|
-
const suffix =
|
|
1200
|
-
return
|
|
1198
|
+
const pkg_name = mod.split("/")[1];
|
|
1199
|
+
const sub_path = mod.split("/").slice(2).join("/");
|
|
1200
|
+
if (pkg_name) {
|
|
1201
|
+
const suffix = sub_path ? `/${sub_path.replace(/\.js$/, "")}` : "/src/index";
|
|
1202
|
+
return file_exports.get(`packages/${pkg_name}${suffix}`) ?? file_exports.get(`${pkg_name}${suffix}`) ?? file_exports.get(`packages/${pkg_name}/src/index`) ?? file_exports.get(`${pkg_name}/src/index`) ?? file_exports.get(`${pkg_name}/index`) ?? file_exports.get(pkg_name) ?? unknown_module_proxy();
|
|
1201
1203
|
}
|
|
1202
1204
|
}
|
|
1203
|
-
return
|
|
1205
|
+
return unknown_module_proxy();
|
|
1204
1206
|
};
|
|
1205
|
-
const sorted =
|
|
1207
|
+
const sorted = topo_sort(files.filter(is_source_file));
|
|
1206
1208
|
for (const file of sorted) {
|
|
1207
1209
|
_currentFile = file.path;
|
|
1208
1210
|
const js = transpile(file.content);
|
|
1209
1211
|
const key = strip(file.path);
|
|
1210
1212
|
const fileExp = {};
|
|
1211
|
-
|
|
1212
|
-
const
|
|
1213
|
-
const
|
|
1213
|
+
file_exports.set(key, fileExp);
|
|
1214
|
+
const slice_names_in_act = [];
|
|
1215
|
+
const ws_re = /\.withSlice\(\s*(?:\w+\.)*(\w+)\s*\)/g;
|
|
1214
1216
|
let wsm;
|
|
1215
|
-
const
|
|
1216
|
-
while ((wsm =
|
|
1217
|
-
if (!
|
|
1217
|
+
const code_only = strip_non_code(js);
|
|
1218
|
+
while ((wsm = ws_re.exec(code_only)) !== null) {
|
|
1219
|
+
if (!slice_names_in_act.includes(wsm[1]))
|
|
1220
|
+
slice_names_in_act.push(wsm[1]);
|
|
1218
1221
|
}
|
|
1219
|
-
for (const
|
|
1222
|
+
for (const m of code_only.matchAll(
|
|
1220
1223
|
/(?:exports\.)?(\w+)\s*=\s*(?:\w+\.)?slice(?:\s*\(\s*\)|\.call\(void 0,\s*\))/g
|
|
1221
1224
|
)) {
|
|
1222
|
-
result.
|
|
1225
|
+
result.expected_slices.set(m[1], file.path);
|
|
1223
1226
|
}
|
|
1224
|
-
const
|
|
1225
|
-
(mod) =>
|
|
1227
|
+
const file_require = Object.assign(
|
|
1228
|
+
(mod) => resolve_module(mod, key),
|
|
1226
1229
|
{ resolve: (mod) => mod, cache: {}, main: void 0 }
|
|
1227
1230
|
);
|
|
1228
1231
|
try {
|
|
1229
|
-
const
|
|
1232
|
+
const clean_js = js.replace(/\bconst\s+__dirname\b/g, "var __dirname").replace(/\bconst\s+__filename\b/g, "var __filename");
|
|
1230
1233
|
const fn = new Function(
|
|
1231
1234
|
// lgtm[js/code-injection]
|
|
1232
1235
|
"require",
|
|
@@ -1239,21 +1242,21 @@ function execute(files) {
|
|
|
1239
1242
|
var process = { env: {}, cwd: function() { return "/"; }, exit: function() {}, on: function() {}, off: function() {} };
|
|
1240
1243
|
var Buffer = { from: function() { return ""; } };
|
|
1241
1244
|
var console = { log: function() {}, error: function() {}, warn: function() {}, info: function() {}, debug: function() {} };
|
|
1242
|
-
${
|
|
1245
|
+
${clean_js}
|
|
1243
1246
|
`
|
|
1244
1247
|
);
|
|
1245
|
-
fn(
|
|
1248
|
+
fn(file_require, fileExp, { exports: fileExp });
|
|
1246
1249
|
} catch (evalErr) {
|
|
1247
1250
|
const errMsg = evalErr instanceof Error ? evalErr.message : String(evalErr);
|
|
1248
|
-
result.
|
|
1249
|
-
}
|
|
1250
|
-
if (
|
|
1251
|
-
for (const
|
|
1252
|
-
if (
|
|
1253
|
-
const
|
|
1254
|
-
for (let ai = 0; ai < Math.min(
|
|
1255
|
-
if (
|
|
1256
|
-
|
|
1251
|
+
result.file_errors.set(file.path, errMsg);
|
|
1252
|
+
}
|
|
1253
|
+
if (slice_names_in_act.length > 0) {
|
|
1254
|
+
for (const act_obj of __built__.acts) {
|
|
1255
|
+
if (act_obj._sourceFile !== file.path) continue;
|
|
1256
|
+
const act_slices = act_obj.slices;
|
|
1257
|
+
for (let ai = 0; ai < Math.min(slice_names_in_act.length, act_slices.length); ai++) {
|
|
1258
|
+
if (act_slices[ai]) {
|
|
1259
|
+
act_slices[ai]._varName = slice_names_in_act[ai];
|
|
1257
1260
|
}
|
|
1258
1261
|
}
|
|
1259
1262
|
}
|
|
@@ -1263,62 +1266,62 @@ function execute(files) {
|
|
|
1263
1266
|
result.slices = __built__.slices;
|
|
1264
1267
|
result.projections = __built__.projections;
|
|
1265
1268
|
result.acts = __built__.acts;
|
|
1266
|
-
} catch (
|
|
1267
|
-
result.error =
|
|
1269
|
+
} catch (e) {
|
|
1270
|
+
result.error = e instanceof Error ? e.message : String(e);
|
|
1268
1271
|
}
|
|
1269
1272
|
return result;
|
|
1270
1273
|
}
|
|
1271
|
-
function
|
|
1274
|
+
function extract_model(files) {
|
|
1272
1275
|
const result = execute(files);
|
|
1273
|
-
return
|
|
1276
|
+
return build_model(result, files, result.expected_slices);
|
|
1274
1277
|
}
|
|
1275
1278
|
|
|
1276
1279
|
// src/cli/contract-index.ts
|
|
1277
|
-
function
|
|
1278
|
-
const
|
|
1279
|
-
if (
|
|
1280
|
+
function decompose_event_name(name) {
|
|
1281
|
+
const m = name.match(/^(.+)_v(\d+)$/);
|
|
1282
|
+
if (m) return { base: m[1], version: Number.parseInt(m[2], 10) };
|
|
1280
1283
|
return { base: name, version: 1 };
|
|
1281
1284
|
}
|
|
1282
|
-
function
|
|
1283
|
-
const me =
|
|
1284
|
-
let
|
|
1285
|
-
let
|
|
1286
|
-
for (const other of
|
|
1285
|
+
function event_status(name, all_names) {
|
|
1286
|
+
const me = decompose_event_name(name);
|
|
1287
|
+
let best_version = me.version;
|
|
1288
|
+
let best_name;
|
|
1289
|
+
for (const other of all_names) {
|
|
1287
1290
|
if (other === name) continue;
|
|
1288
|
-
const dec =
|
|
1289
|
-
if (dec.base === me.base && dec.version >
|
|
1290
|
-
|
|
1291
|
-
|
|
1291
|
+
const dec = decompose_event_name(other);
|
|
1292
|
+
if (dec.base === me.base && dec.version > best_version) {
|
|
1293
|
+
best_version = dec.version;
|
|
1294
|
+
best_name = other;
|
|
1292
1295
|
}
|
|
1293
1296
|
}
|
|
1294
|
-
return
|
|
1297
|
+
return best_name ? { status: "deprecated", superseded_by: best_name } : { status: "active" };
|
|
1295
1298
|
}
|
|
1296
|
-
function
|
|
1299
|
+
function build_contract_index(model) {
|
|
1297
1300
|
const entries = [];
|
|
1298
|
-
const
|
|
1299
|
-
for (const
|
|
1301
|
+
const all_event_names = /* @__PURE__ */ new Set();
|
|
1302
|
+
for (const st of model.states) {
|
|
1300
1303
|
entries.push({
|
|
1301
1304
|
kind: "state",
|
|
1302
|
-
name:
|
|
1303
|
-
file:
|
|
1304
|
-
line:
|
|
1305
|
+
name: st.name,
|
|
1306
|
+
file: st.file,
|
|
1307
|
+
line: st.line
|
|
1305
1308
|
});
|
|
1306
|
-
for (const ev of
|
|
1307
|
-
|
|
1309
|
+
for (const ev of st.events) {
|
|
1310
|
+
all_event_names.add(ev.name);
|
|
1308
1311
|
entries.push({
|
|
1309
1312
|
kind: "event",
|
|
1310
1313
|
name: ev.name,
|
|
1311
|
-
qualifier:
|
|
1312
|
-
file:
|
|
1314
|
+
qualifier: st.name,
|
|
1315
|
+
file: st.file,
|
|
1313
1316
|
line: ev.line
|
|
1314
1317
|
});
|
|
1315
1318
|
}
|
|
1316
|
-
for (const act of
|
|
1319
|
+
for (const act of st.actions) {
|
|
1317
1320
|
entries.push({
|
|
1318
1321
|
kind: "action",
|
|
1319
1322
|
name: act.name,
|
|
1320
|
-
qualifier:
|
|
1321
|
-
file:
|
|
1323
|
+
qualifier: st.name,
|
|
1324
|
+
file: st.file,
|
|
1322
1325
|
line: act.line
|
|
1323
1326
|
});
|
|
1324
1327
|
}
|
|
@@ -1330,14 +1333,14 @@ function buildContractIndex(model) {
|
|
|
1330
1333
|
file: sl.file,
|
|
1331
1334
|
line: sl.line
|
|
1332
1335
|
});
|
|
1333
|
-
for (const
|
|
1334
|
-
|
|
1336
|
+
for (const r2 of sl.reactions) {
|
|
1337
|
+
all_event_names.add(r2.event);
|
|
1335
1338
|
entries.push({
|
|
1336
1339
|
kind: "reaction",
|
|
1337
|
-
name:
|
|
1338
|
-
qualifier: `${sl.name}::${
|
|
1339
|
-
file:
|
|
1340
|
-
line:
|
|
1340
|
+
name: r2.handlerName,
|
|
1341
|
+
qualifier: `${sl.name}::${r2.event}`,
|
|
1342
|
+
file: r2.file ?? sl.file,
|
|
1343
|
+
line: r2.line
|
|
1341
1344
|
});
|
|
1342
1345
|
}
|
|
1343
1346
|
}
|
|
@@ -1348,19 +1351,19 @@ function buildContractIndex(model) {
|
|
|
1348
1351
|
file: pr.file,
|
|
1349
1352
|
line: pr.line
|
|
1350
1353
|
});
|
|
1351
|
-
for (const ev of pr.handles)
|
|
1354
|
+
for (const ev of pr.handles) all_event_names.add(ev);
|
|
1352
1355
|
}
|
|
1353
|
-
for (const
|
|
1354
|
-
|
|
1356
|
+
for (const r2 of model.reactions) {
|
|
1357
|
+
all_event_names.add(r2.event);
|
|
1355
1358
|
entries.push({
|
|
1356
1359
|
kind: "reaction",
|
|
1357
|
-
name:
|
|
1358
|
-
qualifier: `*::${
|
|
1359
|
-
file:
|
|
1360
|
-
line:
|
|
1360
|
+
name: r2.handlerName,
|
|
1361
|
+
qualifier: `*::${r2.event}`,
|
|
1362
|
+
file: r2.file,
|
|
1363
|
+
line: r2.line
|
|
1361
1364
|
});
|
|
1362
1365
|
}
|
|
1363
|
-
return { entries, model,
|
|
1366
|
+
return { entries, model, all_event_names };
|
|
1364
1367
|
}
|
|
1365
1368
|
var CATEGORY_KEYWORDS = {
|
|
1366
1369
|
event: "event",
|
|
@@ -1376,27 +1379,27 @@ var CATEGORY_KEYWORDS = {
|
|
|
1376
1379
|
reaction: "reaction",
|
|
1377
1380
|
reactions: "reaction"
|
|
1378
1381
|
};
|
|
1379
|
-
function
|
|
1380
|
-
return idx.entries.filter((
|
|
1382
|
+
function list_by_kind(idx, kind) {
|
|
1383
|
+
return idx.entries.filter((e) => e.kind === kind).sort((a2, b) => a2.name.localeCompare(b.name));
|
|
1381
1384
|
}
|
|
1382
1385
|
function search(idx, query, limit = 20) {
|
|
1383
|
-
const
|
|
1384
|
-
if (!
|
|
1386
|
+
const q = query.trim().toLowerCase();
|
|
1387
|
+
if (!q) return [];
|
|
1385
1388
|
const scored = [];
|
|
1386
1389
|
for (const entry of idx.entries) {
|
|
1387
1390
|
const name = entry.name.toLowerCase();
|
|
1388
1391
|
let score;
|
|
1389
|
-
if (name ===
|
|
1390
|
-
else if (name.startsWith(
|
|
1391
|
-
else if (name.includes(
|
|
1392
|
+
if (name === q) score = 0;
|
|
1393
|
+
else if (name.startsWith(q)) score = 1;
|
|
1394
|
+
else if (name.includes(q)) score = 2;
|
|
1392
1395
|
else continue;
|
|
1393
1396
|
scored.push({ entry, score });
|
|
1394
1397
|
}
|
|
1395
|
-
scored.sort((
|
|
1396
|
-
if (
|
|
1397
|
-
if (
|
|
1398
|
-
return
|
|
1399
|
-
return
|
|
1398
|
+
scored.sort((a2, b) => {
|
|
1399
|
+
if (a2.score !== b.score) return a2.score - b.score;
|
|
1400
|
+
if (a2.entry.kind !== b.entry.kind)
|
|
1401
|
+
return a2.entry.kind.localeCompare(b.entry.kind);
|
|
1402
|
+
return a2.entry.name.localeCompare(b.entry.name);
|
|
1400
1403
|
});
|
|
1401
1404
|
return scored.slice(0, limit).map((s) => s.entry);
|
|
1402
1405
|
}
|
|
@@ -1419,7 +1422,7 @@ var violet = (s) => ext(141, s);
|
|
|
1419
1422
|
var emerald = (s) => ext(41, s);
|
|
1420
1423
|
var fuchsia = (s) => ext(207, s);
|
|
1421
1424
|
var pink = cornflower;
|
|
1422
|
-
var
|
|
1425
|
+
var kind_color = {
|
|
1423
1426
|
event: orange,
|
|
1424
1427
|
action: cornflower,
|
|
1425
1428
|
state: amber,
|
|
@@ -1433,36 +1436,36 @@ var loc = (file, line) => {
|
|
|
1433
1436
|
if (!file) return "";
|
|
1434
1437
|
return line ? `${file}:${line}` : file;
|
|
1435
1438
|
};
|
|
1436
|
-
var
|
|
1437
|
-
const
|
|
1438
|
-
return
|
|
1439
|
+
var file_note = (file, line) => {
|
|
1440
|
+
const l2 = loc(file, line);
|
|
1441
|
+
return l2 ? ` ${dim(l2)}` : "";
|
|
1439
1442
|
};
|
|
1440
|
-
var
|
|
1441
|
-
const
|
|
1442
|
-
return (
|
|
1443
|
+
var kind_label = (kind) => {
|
|
1444
|
+
const k = kind_color[kind];
|
|
1445
|
+
return (k ?? dim)(kind.padEnd(10));
|
|
1443
1446
|
};
|
|
1444
|
-
function
|
|
1447
|
+
function format_matches(query, matches2) {
|
|
1445
1448
|
if (matches2.length === 0) return dim(`no matches for "${query}"`);
|
|
1446
1449
|
const head = dim(`matches (${matches2.length}) \u2014 type a number to pick:`);
|
|
1447
1450
|
const width = String(matches2.length).length;
|
|
1448
|
-
const lines = matches2.map((
|
|
1449
|
-
const idx = dim(`[${String(
|
|
1450
|
-
const where = loc(
|
|
1451
|
-
const
|
|
1452
|
-
const
|
|
1453
|
-
return ` ${idx} ${
|
|
1451
|
+
const lines = matches2.map((m, i2) => {
|
|
1452
|
+
const idx = dim(`[${String(i2 + 1).padStart(width)}]`);
|
|
1453
|
+
const where = loc(m.file, m.line);
|
|
1454
|
+
const q = m.qualifier ? dim(` (${m.qualifier})`) : "";
|
|
1455
|
+
const w = where ? ` ${dim(where)}` : "";
|
|
1456
|
+
return ` ${idx} ${kind_label(m.kind)} ${m.name}${q}${w}`;
|
|
1454
1457
|
});
|
|
1455
1458
|
return [head, ...lines].join("\n");
|
|
1456
1459
|
}
|
|
1457
|
-
var
|
|
1460
|
+
var find_actions_emitting = (model, event_name) => {
|
|
1458
1461
|
const out = [];
|
|
1459
|
-
for (const
|
|
1460
|
-
for (const act of
|
|
1461
|
-
if (act.emits.includes(
|
|
1462
|
+
for (const st of model.states) {
|
|
1463
|
+
for (const act of st.actions) {
|
|
1464
|
+
if (act.emits.includes(event_name)) {
|
|
1462
1465
|
out.push({
|
|
1463
|
-
state:
|
|
1466
|
+
state: st.name,
|
|
1464
1467
|
action: act.name,
|
|
1465
|
-
file:
|
|
1468
|
+
file: st.file,
|
|
1466
1469
|
line: act.line
|
|
1467
1470
|
});
|
|
1468
1471
|
}
|
|
@@ -1470,108 +1473,110 @@ var findActionsEmitting = (model, eventName) => {
|
|
|
1470
1473
|
}
|
|
1471
1474
|
return out;
|
|
1472
1475
|
};
|
|
1473
|
-
var
|
|
1476
|
+
var find_reactions_for = (model, event_name) => {
|
|
1474
1477
|
const out = [];
|
|
1475
1478
|
for (const sl of model.slices) {
|
|
1476
|
-
for (const
|
|
1477
|
-
if (
|
|
1479
|
+
for (const r2 of sl.reactions) {
|
|
1480
|
+
if (r2.event === event_name) {
|
|
1478
1481
|
out.push({
|
|
1479
1482
|
slice: sl.name,
|
|
1480
|
-
handler:
|
|
1481
|
-
dispatches:
|
|
1482
|
-
file:
|
|
1483
|
-
line:
|
|
1483
|
+
handler: r2.handlerName,
|
|
1484
|
+
dispatches: r2.dispatches,
|
|
1485
|
+
file: r2.file ?? sl.file,
|
|
1486
|
+
line: r2.line
|
|
1484
1487
|
});
|
|
1485
1488
|
}
|
|
1486
1489
|
}
|
|
1487
1490
|
}
|
|
1488
|
-
for (const
|
|
1489
|
-
if (
|
|
1491
|
+
for (const r2 of model.reactions) {
|
|
1492
|
+
if (r2.event === event_name) {
|
|
1490
1493
|
out.push({
|
|
1491
|
-
handler:
|
|
1492
|
-
dispatches:
|
|
1493
|
-
file:
|
|
1494
|
-
line:
|
|
1494
|
+
handler: r2.handlerName,
|
|
1495
|
+
dispatches: r2.dispatches,
|
|
1496
|
+
file: r2.file,
|
|
1497
|
+
line: r2.line
|
|
1495
1498
|
});
|
|
1496
1499
|
}
|
|
1497
1500
|
}
|
|
1498
1501
|
return out;
|
|
1499
1502
|
};
|
|
1500
|
-
var
|
|
1501
|
-
function
|
|
1503
|
+
var find_projections_for = (model, event_name) => model.projections.filter((p) => p.handles.includes(event_name)).map((p) => ({ name: p.name, file: p.file }));
|
|
1504
|
+
function format_event(idx, entry) {
|
|
1502
1505
|
const model = idx.model;
|
|
1503
1506
|
let schema;
|
|
1504
|
-
let
|
|
1505
|
-
for (const
|
|
1506
|
-
const ev =
|
|
1507
|
+
let owning_state;
|
|
1508
|
+
for (const st of model.states) {
|
|
1509
|
+
const ev = st.events.find((e) => e.name === entry.name);
|
|
1507
1510
|
if (ev) {
|
|
1508
1511
|
schema = ev.schema;
|
|
1509
|
-
|
|
1512
|
+
owning_state = { name: st.name, file: st.file };
|
|
1510
1513
|
break;
|
|
1511
1514
|
}
|
|
1512
1515
|
}
|
|
1513
|
-
const file = entry.file ??
|
|
1514
|
-
const status =
|
|
1515
|
-
const
|
|
1516
|
-
// `
|
|
1517
|
-
`${red("deprecated")} (superseded by ${orange(status.
|
|
1516
|
+
const file = entry.file ?? owning_state?.file;
|
|
1517
|
+
const status = event_status(entry.name, idx.all_event_names);
|
|
1518
|
+
const status_line = status.status === "active" ? green("active") : (
|
|
1519
|
+
// `superseded_by` is always set on deprecated entries — see event_status.
|
|
1520
|
+
`${red("deprecated")} (superseded by ${orange(status.superseded_by)})`
|
|
1518
1521
|
);
|
|
1519
1522
|
const lines = [];
|
|
1520
1523
|
lines.push(bold(orange(entry.name)));
|
|
1521
1524
|
if (file) lines.push(` in: ${dim(loc(file, entry.line))}`);
|
|
1522
|
-
if (
|
|
1523
|
-
lines.push(` on: ${amber(
|
|
1525
|
+
if (owning_state && owning_state.name !== entry.name)
|
|
1526
|
+
lines.push(` on: ${amber(owning_state.name)}`);
|
|
1524
1527
|
lines.push(` schema: ${schema ?? dim("(not captured)")}`);
|
|
1525
|
-
lines.push(` status: ${
|
|
1526
|
-
const producers =
|
|
1528
|
+
lines.push(` status: ${status_line}`);
|
|
1529
|
+
const producers = find_actions_emitting(model, entry.name);
|
|
1527
1530
|
if (producers.length > 0) {
|
|
1528
1531
|
lines.push(" producers:");
|
|
1529
|
-
for (const
|
|
1532
|
+
for (const p of producers) {
|
|
1530
1533
|
lines.push(
|
|
1531
|
-
` - ${pink(
|
|
1534
|
+
` - ${pink(p.action)} ${dim(`(on ${p.state})`)}${file_note(p.file, p.line)}`
|
|
1532
1535
|
);
|
|
1533
1536
|
}
|
|
1534
1537
|
} else {
|
|
1535
1538
|
lines.push(` producers: ${dim("(none)")}`);
|
|
1536
1539
|
}
|
|
1537
|
-
const reactions =
|
|
1538
|
-
const projections =
|
|
1540
|
+
const reactions = find_reactions_for(model, entry.name);
|
|
1541
|
+
const projections = find_projections_for(model, entry.name);
|
|
1539
1542
|
if (reactions.length === 0 && projections.length === 0) {
|
|
1540
1543
|
lines.push(` consumers: ${dim("(none)")}`);
|
|
1541
1544
|
} else {
|
|
1542
1545
|
lines.push(" consumers:");
|
|
1543
|
-
for (const
|
|
1544
|
-
const slice =
|
|
1545
|
-
const triggers =
|
|
1546
|
+
for (const r2 of reactions) {
|
|
1547
|
+
const slice = r2.slice ? `${violet(r2.slice)}${dim("::")}` : "";
|
|
1548
|
+
const triggers = r2.dispatches.length > 0 ? ` \u2192 ${r2.dispatches.map((d) => pink(d)).join(", ")}` : "";
|
|
1546
1549
|
lines.push(
|
|
1547
|
-
` - ${slice}${fuchsia(
|
|
1550
|
+
` - ${slice}${fuchsia(r2.handler)}${triggers}${file_note(r2.file, r2.line)}`
|
|
1548
1551
|
);
|
|
1549
1552
|
}
|
|
1550
|
-
for (const
|
|
1551
|
-
lines.push(` - ${emerald(
|
|
1553
|
+
for (const p of projections) {
|
|
1554
|
+
lines.push(` - ${emerald(p.name)}${file_note(p.file)}`);
|
|
1552
1555
|
}
|
|
1553
1556
|
}
|
|
1554
1557
|
return lines.join("\n");
|
|
1555
1558
|
}
|
|
1556
|
-
function
|
|
1559
|
+
function format_action(idx, entry) {
|
|
1557
1560
|
const model = idx.model;
|
|
1558
|
-
const
|
|
1561
|
+
const owner_name = entry.qualifier;
|
|
1559
1562
|
let action;
|
|
1560
|
-
let
|
|
1561
|
-
for (const
|
|
1562
|
-
if (
|
|
1563
|
-
const
|
|
1564
|
-
if (
|
|
1565
|
-
action =
|
|
1566
|
-
|
|
1563
|
+
let state_file;
|
|
1564
|
+
for (const st of model.states) {
|
|
1565
|
+
if (owner_name && st.name !== owner_name) continue;
|
|
1566
|
+
const a2 = st.actions.find((x) => x.name === entry.name);
|
|
1567
|
+
if (a2) {
|
|
1568
|
+
action = a2;
|
|
1569
|
+
state_file = st.file;
|
|
1567
1570
|
break;
|
|
1568
1571
|
}
|
|
1569
1572
|
}
|
|
1570
1573
|
const lines = [];
|
|
1571
1574
|
lines.push(bold(pink(entry.name)));
|
|
1572
|
-
if (
|
|
1573
|
-
if (
|
|
1574
|
-
lines.push(
|
|
1575
|
+
if (owner_name) lines.push(` on: ${amber(owner_name)}`);
|
|
1576
|
+
if (state_file)
|
|
1577
|
+
lines.push(
|
|
1578
|
+
` in: ${dim(loc(state_file, action?.line ?? entry.line))}`
|
|
1579
|
+
);
|
|
1575
1580
|
if (action) {
|
|
1576
1581
|
if (action.invariants.length > 0) {
|
|
1577
1582
|
lines.push(" invariants:");
|
|
@@ -1579,36 +1584,36 @@ function formatAction(idx, entry) {
|
|
|
1579
1584
|
}
|
|
1580
1585
|
if (action.emits.length > 0) {
|
|
1581
1586
|
lines.push(" emits:");
|
|
1582
|
-
for (const
|
|
1587
|
+
for (const e of action.emits) lines.push(` - ${orange(e)}`);
|
|
1583
1588
|
} else {
|
|
1584
1589
|
lines.push(` emits: ${dim("(none)")}`);
|
|
1585
1590
|
}
|
|
1586
1591
|
}
|
|
1587
1592
|
return lines.join("\n");
|
|
1588
1593
|
}
|
|
1589
|
-
function
|
|
1590
|
-
const
|
|
1594
|
+
function format_state(idx, entry) {
|
|
1595
|
+
const st = idx.model.states.find((s) => s.name === entry.name);
|
|
1591
1596
|
const lines = [];
|
|
1592
1597
|
lines.push(bold(amber(entry.name)));
|
|
1593
1598
|
if (entry.file) lines.push(` in: ${dim(loc(entry.file, entry.line))}`);
|
|
1594
|
-
if (!
|
|
1595
|
-
if (
|
|
1599
|
+
if (!st) return lines.join("\n");
|
|
1600
|
+
if (st.actions.length > 0) {
|
|
1596
1601
|
lines.push(" actions:");
|
|
1597
|
-
for (const
|
|
1598
|
-
const emits =
|
|
1599
|
-
lines.push(` - ${pink(
|
|
1602
|
+
for (const a2 of st.actions) {
|
|
1603
|
+
const emits = a2.emits.length > 0 ? ` \u2192 ${a2.emits.join(", ")}` : "";
|
|
1604
|
+
lines.push(` - ${pink(a2.name)}${emits}`);
|
|
1600
1605
|
}
|
|
1601
1606
|
}
|
|
1602
|
-
if (
|
|
1607
|
+
if (st.events.length > 0) {
|
|
1603
1608
|
lines.push(" events:");
|
|
1604
|
-
for (const
|
|
1605
|
-
const schema =
|
|
1606
|
-
lines.push(` - ${orange(
|
|
1609
|
+
for (const e of st.events) {
|
|
1610
|
+
const schema = e.schema ? ` ${dim(e.schema)}` : "";
|
|
1611
|
+
lines.push(` - ${orange(e.name)}${schema}`);
|
|
1607
1612
|
}
|
|
1608
1613
|
}
|
|
1609
1614
|
return lines.join("\n");
|
|
1610
1615
|
}
|
|
1611
|
-
function
|
|
1616
|
+
function format_slice(idx, entry) {
|
|
1612
1617
|
const sl = idx.model.slices.find((s) => s.name === entry.name);
|
|
1613
1618
|
const lines = [];
|
|
1614
1619
|
lines.push(bold(violet(entry.name)));
|
|
@@ -1621,21 +1626,21 @@ function formatSlice(idx, entry) {
|
|
|
1621
1626
|
}
|
|
1622
1627
|
if (sl.projections.length > 0) {
|
|
1623
1628
|
lines.push(" projections:");
|
|
1624
|
-
for (const
|
|
1629
|
+
for (const p of sl.projections) lines.push(` - ${emerald(p)}`);
|
|
1625
1630
|
}
|
|
1626
1631
|
if (sl.reactions.length > 0) {
|
|
1627
1632
|
lines.push(" reactions:");
|
|
1628
|
-
for (const
|
|
1629
|
-
const triggers =
|
|
1633
|
+
for (const r2 of sl.reactions) {
|
|
1634
|
+
const triggers = r2.dispatches.length > 0 ? ` \u2192 ${r2.dispatches.map((d) => pink(d)).join(", ")}` : "";
|
|
1630
1635
|
lines.push(
|
|
1631
|
-
` - ${orange(
|
|
1636
|
+
` - ${orange(r2.event)} \u2192 ${fuchsia(r2.handlerName)}${triggers}${file_note(r2.file, r2.line)}`
|
|
1632
1637
|
);
|
|
1633
1638
|
}
|
|
1634
1639
|
}
|
|
1635
1640
|
return lines.join("\n");
|
|
1636
1641
|
}
|
|
1637
|
-
function
|
|
1638
|
-
const pr = idx.model.projections.find((
|
|
1642
|
+
function format_projection(idx, entry) {
|
|
1643
|
+
const pr = idx.model.projections.find((p) => p.name === entry.name);
|
|
1639
1644
|
const lines = [];
|
|
1640
1645
|
lines.push(bold(emerald(entry.name)));
|
|
1641
1646
|
if (pr?.file) lines.push(` in: ${dim(loc(pr.file, pr.line))}`);
|
|
@@ -1646,72 +1651,72 @@ function formatProjection(idx, entry) {
|
|
|
1646
1651
|
}
|
|
1647
1652
|
return lines.join("\n");
|
|
1648
1653
|
}
|
|
1649
|
-
function
|
|
1650
|
-
const [
|
|
1654
|
+
function format_reaction(idx, entry) {
|
|
1655
|
+
const [slice_name, event_name] = (entry.qualifier ?? "::").split("::");
|
|
1651
1656
|
const lines = [];
|
|
1652
|
-
const slice =
|
|
1657
|
+
const slice = slice_name && slice_name !== "*" ? violet(slice_name) : "";
|
|
1653
1658
|
const header = slice ? `${bold(fuchsia(entry.name))} ${dim(`(in ${slice})`)}` : bold(fuchsia(entry.name));
|
|
1654
1659
|
lines.push(header);
|
|
1655
|
-
if (
|
|
1660
|
+
if (event_name) lines.push(` on: ${orange(event_name)}`);
|
|
1656
1661
|
if (entry.file) lines.push(` in: ${dim(loc(entry.file, entry.line))}`);
|
|
1657
|
-
const
|
|
1658
|
-
(
|
|
1662
|
+
const slice_reaction = idx.model.slices.find((s) => s.name === slice_name)?.reactions.find(
|
|
1663
|
+
(r3) => r3.handlerName === entry.name && r3.event === event_name
|
|
1659
1664
|
);
|
|
1660
|
-
const
|
|
1661
|
-
(
|
|
1665
|
+
const orch_reaction = idx.model.reactions.find(
|
|
1666
|
+
(r3) => r3.handlerName === entry.name && r3.event === event_name
|
|
1662
1667
|
);
|
|
1663
|
-
const
|
|
1664
|
-
if (
|
|
1665
|
-
const producers =
|
|
1668
|
+
const r2 = slice_reaction ?? orch_reaction;
|
|
1669
|
+
if (event_name) {
|
|
1670
|
+
const producers = find_actions_emitting(idx.model, event_name);
|
|
1666
1671
|
if (producers.length > 0) {
|
|
1667
1672
|
lines.push(" producers (of triggering event):");
|
|
1668
|
-
for (const
|
|
1673
|
+
for (const p of producers) {
|
|
1669
1674
|
lines.push(
|
|
1670
|
-
` - action ${pink(
|
|
1675
|
+
` - action ${pink(p.action)} (state ${p.state})${file_note(p.file, p.line)}`
|
|
1671
1676
|
);
|
|
1672
1677
|
}
|
|
1673
1678
|
}
|
|
1674
1679
|
}
|
|
1675
|
-
if (
|
|
1680
|
+
if (r2 && r2.dispatches.length > 0) {
|
|
1676
1681
|
lines.push(" triggers:");
|
|
1677
|
-
for (const d of
|
|
1682
|
+
for (const d of r2.dispatches) lines.push(` - action ${pink(d)}`);
|
|
1678
1683
|
}
|
|
1679
1684
|
return lines.join("\n");
|
|
1680
1685
|
}
|
|
1681
1686
|
var formatters = {
|
|
1682
|
-
event:
|
|
1683
|
-
action:
|
|
1684
|
-
state:
|
|
1685
|
-
slice:
|
|
1686
|
-
projection:
|
|
1687
|
-
reaction:
|
|
1687
|
+
event: format_event,
|
|
1688
|
+
action: format_action,
|
|
1689
|
+
state: format_state,
|
|
1690
|
+
slice: format_slice,
|
|
1691
|
+
projection: format_projection,
|
|
1692
|
+
reaction: format_reaction
|
|
1688
1693
|
};
|
|
1689
|
-
function
|
|
1694
|
+
function format_detail(idx, entry) {
|
|
1690
1695
|
const fmt = formatters[entry.kind];
|
|
1691
1696
|
return fmt ? fmt(idx, entry) : "";
|
|
1692
1697
|
}
|
|
1693
|
-
function
|
|
1694
|
-
const
|
|
1698
|
+
function format_summary(idx) {
|
|
1699
|
+
const m = idx.model;
|
|
1695
1700
|
const parts = [
|
|
1696
|
-
`${
|
|
1697
|
-
`${
|
|
1698
|
-
`${
|
|
1699
|
-
`${idx.
|
|
1701
|
+
`${m.states.length} ${m.states.length === 1 ? "state" : "states"}`,
|
|
1702
|
+
`${m.slices.length} ${m.slices.length === 1 ? "slice" : "slices"}`,
|
|
1703
|
+
`${m.projections.length} ${m.projections.length === 1 ? "projection" : "projections"}`,
|
|
1704
|
+
`${idx.all_event_names.size} ${idx.all_event_names.size === 1 ? "event" : "events"}`
|
|
1700
1705
|
];
|
|
1701
1706
|
return dim(`loaded ${parts.join(", ")}`);
|
|
1702
1707
|
}
|
|
1703
1708
|
|
|
1704
1709
|
// src/cli/json-schema.ts
|
|
1705
1710
|
import { z as z2 } from "zod";
|
|
1706
|
-
var
|
|
1711
|
+
var find_producers = (model, event_name) => {
|
|
1707
1712
|
const out = [];
|
|
1708
|
-
for (const
|
|
1709
|
-
for (const act of
|
|
1710
|
-
if (act.emits.includes(
|
|
1713
|
+
for (const st of model.states) {
|
|
1714
|
+
for (const act of st.actions) {
|
|
1715
|
+
if (act.emits.includes(event_name)) {
|
|
1711
1716
|
out.push({
|
|
1712
1717
|
action: act.name,
|
|
1713
|
-
state:
|
|
1714
|
-
file:
|
|
1718
|
+
state: st.name,
|
|
1719
|
+
file: st.file,
|
|
1715
1720
|
line: act.line
|
|
1716
1721
|
});
|
|
1717
1722
|
}
|
|
@@ -1719,36 +1724,36 @@ var findProducers = (model, eventName) => {
|
|
|
1719
1724
|
}
|
|
1720
1725
|
return out;
|
|
1721
1726
|
};
|
|
1722
|
-
var
|
|
1727
|
+
var find_consumers = (model, event_name) => {
|
|
1723
1728
|
const out = [];
|
|
1724
1729
|
for (const sl of model.slices) {
|
|
1725
|
-
for (const
|
|
1726
|
-
if (
|
|
1730
|
+
for (const r2 of sl.reactions) {
|
|
1731
|
+
if (r2.event === event_name) {
|
|
1727
1732
|
out.push({
|
|
1728
1733
|
type: "reaction",
|
|
1729
1734
|
slice: sl.name,
|
|
1730
|
-
handler:
|
|
1731
|
-
dispatches:
|
|
1732
|
-
file:
|
|
1733
|
-
line:
|
|
1735
|
+
handler: r2.handlerName,
|
|
1736
|
+
dispatches: r2.dispatches,
|
|
1737
|
+
file: r2.file ?? sl.file,
|
|
1738
|
+
line: r2.line
|
|
1734
1739
|
});
|
|
1735
1740
|
}
|
|
1736
1741
|
}
|
|
1737
1742
|
}
|
|
1738
|
-
for (const
|
|
1739
|
-
if (
|
|
1743
|
+
for (const r2 of model.reactions) {
|
|
1744
|
+
if (r2.event === event_name) {
|
|
1740
1745
|
out.push({
|
|
1741
1746
|
type: "reaction",
|
|
1742
|
-
handler:
|
|
1743
|
-
dispatches:
|
|
1744
|
-
file:
|
|
1745
|
-
line:
|
|
1747
|
+
handler: r2.handlerName,
|
|
1748
|
+
dispatches: r2.dispatches,
|
|
1749
|
+
file: r2.file,
|
|
1750
|
+
line: r2.line
|
|
1746
1751
|
});
|
|
1747
1752
|
}
|
|
1748
1753
|
}
|
|
1749
|
-
for (const
|
|
1750
|
-
if (
|
|
1751
|
-
out.push({ type: "projection", name:
|
|
1754
|
+
for (const p of model.projections) {
|
|
1755
|
+
if (p.handles.includes(event_name)) {
|
|
1756
|
+
out.push({ type: "projection", name: p.name, file: p.file });
|
|
1752
1757
|
}
|
|
1753
1758
|
}
|
|
1754
1759
|
return out;
|
|
@@ -1764,37 +1769,37 @@ function toJsonSchemaSafe(zod) {
|
|
|
1764
1769
|
return { error: err instanceof Error ? err.message : String(err) };
|
|
1765
1770
|
}
|
|
1766
1771
|
}
|
|
1767
|
-
function
|
|
1768
|
-
const
|
|
1772
|
+
function format_json_schema(idx) {
|
|
1773
|
+
const m = idx.model;
|
|
1769
1774
|
const events = {};
|
|
1770
|
-
for (const
|
|
1771
|
-
for (const ev of
|
|
1772
|
-
const status =
|
|
1775
|
+
for (const st of m.states) {
|
|
1776
|
+
for (const ev of st.events) {
|
|
1777
|
+
const status = event_status(ev.name, idx.all_event_names);
|
|
1773
1778
|
const conv = toJsonSchemaSafe(ev.zod);
|
|
1774
1779
|
const report = {
|
|
1775
1780
|
name: ev.name,
|
|
1776
|
-
file:
|
|
1781
|
+
file: st.file,
|
|
1777
1782
|
line: ev.line,
|
|
1778
1783
|
status: status.status,
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
producers:
|
|
1782
|
-
consumers:
|
|
1784
|
+
superseded_by: status.superseded_by,
|
|
1785
|
+
schema_text: ev.schema,
|
|
1786
|
+
producers: find_producers(m, ev.name),
|
|
1787
|
+
consumers: find_consumers(m, ev.name)
|
|
1783
1788
|
};
|
|
1784
1789
|
if ("schema" in conv) report.schema = conv.schema;
|
|
1785
|
-
else report.
|
|
1790
|
+
else report.schema_error = conv.error;
|
|
1786
1791
|
events[ev.name] = report;
|
|
1787
1792
|
}
|
|
1788
1793
|
}
|
|
1789
1794
|
const out = {
|
|
1790
1795
|
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
1791
1796
|
generator: "act-diagram/act-contracts",
|
|
1792
|
-
|
|
1797
|
+
generated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1793
1798
|
counts: {
|
|
1794
|
-
states:
|
|
1795
|
-
slices:
|
|
1796
|
-
projections:
|
|
1797
|
-
events: idx.
|
|
1799
|
+
states: m.states.length,
|
|
1800
|
+
slices: m.slices.length,
|
|
1801
|
+
projections: m.projections.length,
|
|
1802
|
+
events: idx.all_event_names.size
|
|
1798
1803
|
},
|
|
1799
1804
|
events
|
|
1800
1805
|
};
|
|
@@ -1828,14 +1833,14 @@ var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
|
1828
1833
|
"scripts"
|
|
1829
1834
|
]);
|
|
1830
1835
|
var SKIP_FILE_RE = /\.(?:d\.ts|tsx|test\.ts|spec\.ts|bench\.ts|perf\.ts)$/;
|
|
1831
|
-
async function
|
|
1832
|
-
const max = opts.
|
|
1836
|
+
async function load_project(root_dir, opts = {}) {
|
|
1837
|
+
const max = opts.max_files ?? 5e3;
|
|
1833
1838
|
const files = [];
|
|
1834
1839
|
let truncated = false;
|
|
1835
|
-
const visit = async (
|
|
1840
|
+
const visit = async (abs_dir, rel_dir) => {
|
|
1836
1841
|
let entries;
|
|
1837
1842
|
try {
|
|
1838
|
-
entries = await readdir(
|
|
1843
|
+
entries = await readdir(abs_dir, { withFileTypes: true });
|
|
1839
1844
|
} catch {
|
|
1840
1845
|
return;
|
|
1841
1846
|
}
|
|
@@ -1846,28 +1851,28 @@ async function loadProject(rootDir, opts = {}) {
|
|
|
1846
1851
|
}
|
|
1847
1852
|
const name = entry.name;
|
|
1848
1853
|
if (name.startsWith(".") && name !== ".") continue;
|
|
1849
|
-
const
|
|
1850
|
-
const
|
|
1854
|
+
const abs_path = posix.join(abs_dir.replace(/\\/g, "/"), name);
|
|
1855
|
+
const rel_path = rel_dir ? posix.join(rel_dir, name) : name;
|
|
1851
1856
|
if (entry.isDirectory()) {
|
|
1852
1857
|
if (SKIP_DIRS.has(name)) continue;
|
|
1853
|
-
await visit(
|
|
1858
|
+
await visit(abs_path, rel_path);
|
|
1854
1859
|
continue;
|
|
1855
1860
|
}
|
|
1856
1861
|
if (!entry.isFile()) continue;
|
|
1857
1862
|
if (!name.endsWith(".ts")) continue;
|
|
1858
1863
|
if (SKIP_FILE_RE.test(name)) continue;
|
|
1859
1864
|
try {
|
|
1860
|
-
const content = await readFile(
|
|
1861
|
-
files.push({ path:
|
|
1865
|
+
const content = await readFile(abs_path, "utf8");
|
|
1866
|
+
files.push({ path: rel_path, content });
|
|
1862
1867
|
} catch {
|
|
1863
1868
|
}
|
|
1864
1869
|
}
|
|
1865
1870
|
};
|
|
1866
|
-
const
|
|
1867
|
-
if (!
|
|
1871
|
+
const root_stat = await stat(root_dir).catch(() => null);
|
|
1872
|
+
if (!root_stat || !root_stat.isDirectory()) {
|
|
1868
1873
|
return { files, truncated };
|
|
1869
1874
|
}
|
|
1870
|
-
await visit(
|
|
1875
|
+
await visit(root_dir.replace(/\\/g, "/"), "");
|
|
1871
1876
|
return { files, truncated };
|
|
1872
1877
|
}
|
|
1873
1878
|
|
|
@@ -1876,15 +1881,15 @@ var loc2 = (file, line) => {
|
|
|
1876
1881
|
if (!file) return "";
|
|
1877
1882
|
return line ? `${file}:${line}` : file;
|
|
1878
1883
|
};
|
|
1879
|
-
var
|
|
1884
|
+
var find_actions_emitting2 = (model, event_name) => {
|
|
1880
1885
|
const out = [];
|
|
1881
|
-
for (const
|
|
1882
|
-
for (const act of
|
|
1883
|
-
if (act.emits.includes(
|
|
1886
|
+
for (const st of model.states) {
|
|
1887
|
+
for (const act of st.actions) {
|
|
1888
|
+
if (act.emits.includes(event_name)) {
|
|
1884
1889
|
out.push({
|
|
1885
|
-
state:
|
|
1890
|
+
state: st.name,
|
|
1886
1891
|
action: act.name,
|
|
1887
|
-
file:
|
|
1892
|
+
file: st.file,
|
|
1888
1893
|
line: act.line
|
|
1889
1894
|
});
|
|
1890
1895
|
}
|
|
@@ -1892,129 +1897,129 @@ var findActionsEmitting2 = (model, eventName) => {
|
|
|
1892
1897
|
}
|
|
1893
1898
|
return out;
|
|
1894
1899
|
};
|
|
1895
|
-
var
|
|
1900
|
+
var find_reactions_for2 = (model, event_name) => {
|
|
1896
1901
|
const out = [];
|
|
1897
1902
|
for (const sl of model.slices) {
|
|
1898
|
-
for (const
|
|
1899
|
-
if (
|
|
1903
|
+
for (const r2 of sl.reactions) {
|
|
1904
|
+
if (r2.event === event_name) {
|
|
1900
1905
|
out.push({
|
|
1901
1906
|
slice: sl.name,
|
|
1902
|
-
handler:
|
|
1903
|
-
dispatches:
|
|
1904
|
-
file:
|
|
1905
|
-
line:
|
|
1907
|
+
handler: r2.handlerName,
|
|
1908
|
+
dispatches: r2.dispatches,
|
|
1909
|
+
file: r2.file ?? sl.file,
|
|
1910
|
+
line: r2.line
|
|
1906
1911
|
});
|
|
1907
1912
|
}
|
|
1908
1913
|
}
|
|
1909
1914
|
}
|
|
1910
|
-
for (const
|
|
1911
|
-
if (
|
|
1915
|
+
for (const r2 of model.reactions) {
|
|
1916
|
+
if (r2.event === event_name) {
|
|
1912
1917
|
out.push({
|
|
1913
|
-
handler:
|
|
1914
|
-
dispatches:
|
|
1915
|
-
file:
|
|
1916
|
-
line:
|
|
1918
|
+
handler: r2.handlerName,
|
|
1919
|
+
dispatches: r2.dispatches,
|
|
1920
|
+
file: r2.file,
|
|
1921
|
+
line: r2.line
|
|
1917
1922
|
});
|
|
1918
1923
|
}
|
|
1919
1924
|
}
|
|
1920
1925
|
return out;
|
|
1921
1926
|
};
|
|
1922
|
-
var
|
|
1923
|
-
var
|
|
1924
|
-
const
|
|
1925
|
-
return
|
|
1927
|
+
var find_projections_for2 = (model, event_name) => model.projections.filter((p) => p.handles.includes(event_name)).map((p) => ({ name: p.name, file: p.file }));
|
|
1928
|
+
var file_suffix = (file, line) => {
|
|
1929
|
+
const l2 = loc2(file, line);
|
|
1930
|
+
return l2 ? ` *(${l2})*` : "";
|
|
1926
1931
|
};
|
|
1927
|
-
var
|
|
1932
|
+
var render_schema = (s) => {
|
|
1928
1933
|
if (!s) return "_(not captured)_";
|
|
1929
1934
|
if (!s.includes("\n")) return `\`${s}\``;
|
|
1930
|
-
const indented = s.split("\n").map((
|
|
1935
|
+
const indented = s.split("\n").map((l2) => ` ${l2}`).join("\n");
|
|
1931
1936
|
return `
|
|
1932
1937
|
|
|
1933
1938
|
\`\`\`ts
|
|
1934
1939
|
${indented}
|
|
1935
1940
|
\`\`\``;
|
|
1936
1941
|
};
|
|
1937
|
-
function
|
|
1938
|
-
const
|
|
1942
|
+
function format_markdown(idx) {
|
|
1943
|
+
const m = idx.model;
|
|
1939
1944
|
const lines = [];
|
|
1940
1945
|
lines.push("# Act Contracts Registry");
|
|
1941
1946
|
lines.push("");
|
|
1942
1947
|
lines.push(
|
|
1943
|
-
`_Generated by \`act --markdown\`. ${
|
|
1948
|
+
`_Generated by \`act --markdown\`. ${m.states.length} states, ${m.slices.length} slices, ${m.projections.length} projections, ${idx.all_event_names.size} events._`
|
|
1944
1949
|
);
|
|
1945
1950
|
lines.push("");
|
|
1946
1951
|
lines.push("## Events");
|
|
1947
1952
|
lines.push("");
|
|
1948
|
-
const events =
|
|
1953
|
+
const events = list_by_kind(idx, "event");
|
|
1949
1954
|
if (events.length === 0) lines.push("_(none)_\n");
|
|
1950
|
-
for (const
|
|
1955
|
+
for (const e of events) {
|
|
1951
1956
|
let schema;
|
|
1952
|
-
let
|
|
1953
|
-
for (const
|
|
1954
|
-
const ev =
|
|
1957
|
+
let owning_state;
|
|
1958
|
+
for (const st of m.states) {
|
|
1959
|
+
const ev = st.events.find((x) => x.name === e.name);
|
|
1955
1960
|
if (ev) {
|
|
1956
1961
|
schema = ev.schema;
|
|
1957
|
-
|
|
1962
|
+
owning_state = st.name;
|
|
1958
1963
|
break;
|
|
1959
1964
|
}
|
|
1960
1965
|
}
|
|
1961
|
-
const status =
|
|
1962
|
-
const
|
|
1963
|
-
lines.push(`### \`${
|
|
1964
|
-
if (
|
|
1965
|
-
if (
|
|
1966
|
-
lines.push(`- **on state:** \`${
|
|
1967
|
-
lines.push(`- **schema:** ${
|
|
1968
|
-
lines.push(`- **status:** ${
|
|
1969
|
-
const producers =
|
|
1966
|
+
const status = event_status(e.name, idx.all_event_names);
|
|
1967
|
+
const status_label = status.status === "active" ? "active" : `deprecated \u2014 superseded by **${status.superseded_by}**`;
|
|
1968
|
+
lines.push(`### \`${e.name}\``);
|
|
1969
|
+
if (e.file) lines.push(`- **defined in:** \`${loc2(e.file, e.line)}\``);
|
|
1970
|
+
if (owning_state && owning_state !== e.name)
|
|
1971
|
+
lines.push(`- **on state:** \`${owning_state}\``);
|
|
1972
|
+
lines.push(`- **schema:** ${render_schema(schema)}`);
|
|
1973
|
+
lines.push(`- **status:** ${status_label}`);
|
|
1974
|
+
const producers = find_actions_emitting2(m, e.name);
|
|
1970
1975
|
if (producers.length > 0) {
|
|
1971
1976
|
lines.push("- **producers:**");
|
|
1972
|
-
for (const
|
|
1977
|
+
for (const p of producers)
|
|
1973
1978
|
lines.push(
|
|
1974
|
-
` - \`${
|
|
1979
|
+
` - \`${p.action}\` (state \`${p.state}\`)${file_suffix(p.file, p.line)}`
|
|
1975
1980
|
);
|
|
1976
1981
|
} else {
|
|
1977
1982
|
lines.push("- **producers:** _(none)_");
|
|
1978
1983
|
}
|
|
1979
|
-
const reactions2 =
|
|
1980
|
-
const projections2 =
|
|
1984
|
+
const reactions2 = find_reactions_for2(m, e.name);
|
|
1985
|
+
const projections2 = find_projections_for2(m, e.name);
|
|
1981
1986
|
if (reactions2.length === 0 && projections2.length === 0) {
|
|
1982
1987
|
lines.push("- **consumers:** _(none)_");
|
|
1983
1988
|
} else {
|
|
1984
1989
|
lines.push("- **consumers:**");
|
|
1985
|
-
for (const
|
|
1986
|
-
const slice =
|
|
1987
|
-
const triggers =
|
|
1990
|
+
for (const r2 of reactions2) {
|
|
1991
|
+
const slice = r2.slice ? `\`${r2.slice}\`::` : "";
|
|
1992
|
+
const triggers = r2.dispatches.length > 0 ? ` \u2192 triggers ${r2.dispatches.map((d) => `\`${d}\``).join(", ")}` : "";
|
|
1988
1993
|
lines.push(
|
|
1989
|
-
` - reaction ${slice}\`${
|
|
1994
|
+
` - reaction ${slice}\`${r2.handler}\`${triggers}${file_suffix(r2.file, r2.line)}`
|
|
1990
1995
|
);
|
|
1991
1996
|
}
|
|
1992
|
-
for (const
|
|
1993
|
-
lines.push(` - projection \`${
|
|
1997
|
+
for (const p of projections2)
|
|
1998
|
+
lines.push(` - projection \`${p.name}\`${file_suffix(p.file)}`);
|
|
1994
1999
|
}
|
|
1995
2000
|
lines.push("");
|
|
1996
2001
|
}
|
|
1997
2002
|
lines.push("## Actions");
|
|
1998
2003
|
lines.push("");
|
|
1999
|
-
const actions =
|
|
2004
|
+
const actions = list_by_kind(idx, "action");
|
|
2000
2005
|
if (actions.length === 0) lines.push("_(none)_\n");
|
|
2001
|
-
for (const
|
|
2006
|
+
for (const a2 of actions) {
|
|
2002
2007
|
let action;
|
|
2003
|
-
let
|
|
2004
|
-
for (const
|
|
2005
|
-
if (
|
|
2006
|
-
const found =
|
|
2008
|
+
let state_file;
|
|
2009
|
+
for (const st of m.states) {
|
|
2010
|
+
if (a2.qualifier && st.name !== a2.qualifier) continue;
|
|
2011
|
+
const found = st.actions.find((x) => x.name === a2.name);
|
|
2007
2012
|
if (found) {
|
|
2008
2013
|
action = found;
|
|
2009
|
-
|
|
2014
|
+
state_file = st.file;
|
|
2010
2015
|
break;
|
|
2011
2016
|
}
|
|
2012
2017
|
}
|
|
2013
|
-
lines.push(`### \`${
|
|
2014
|
-
if (
|
|
2015
|
-
if (
|
|
2018
|
+
lines.push(`### \`${a2.name}\``);
|
|
2019
|
+
if (a2.qualifier) lines.push(`- **on state:** \`${a2.qualifier}\``);
|
|
2020
|
+
if (state_file)
|
|
2016
2021
|
lines.push(
|
|
2017
|
-
`- **defined in:** \`${loc2(
|
|
2022
|
+
`- **defined in:** \`${loc2(state_file, action?.line ?? a2.line)}\``
|
|
2018
2023
|
);
|
|
2019
2024
|
if (action) {
|
|
2020
2025
|
if (action.invariants.length > 0) {
|
|
@@ -2032,48 +2037,48 @@ function formatMarkdown(idx) {
|
|
|
2032
2037
|
}
|
|
2033
2038
|
lines.push("## States");
|
|
2034
2039
|
lines.push("");
|
|
2035
|
-
const states =
|
|
2040
|
+
const states = list_by_kind(idx, "state");
|
|
2036
2041
|
if (states.length === 0) lines.push("_(none)_\n");
|
|
2037
2042
|
for (const s of states) {
|
|
2038
|
-
const
|
|
2043
|
+
const st = m.states.find((x) => x.name === s.name);
|
|
2039
2044
|
lines.push(`### \`${s.name}\``);
|
|
2040
2045
|
if (s.file) lines.push(`- **defined in:** \`${loc2(s.file, s.line)}\``);
|
|
2041
|
-
if (
|
|
2042
|
-
if (
|
|
2046
|
+
if (st) {
|
|
2047
|
+
if (st.actions.length > 0)
|
|
2043
2048
|
lines.push(
|
|
2044
|
-
`- **actions:** ${
|
|
2049
|
+
`- **actions:** ${st.actions.map((x) => `\`${x.name}\``).join(", ")}`
|
|
2045
2050
|
);
|
|
2046
|
-
if (
|
|
2051
|
+
if (st.events.length > 0)
|
|
2047
2052
|
lines.push(
|
|
2048
|
-
`- **events:** ${
|
|
2053
|
+
`- **events:** ${st.events.map((x) => `\`${x.name}\``).join(", ")}`
|
|
2049
2054
|
);
|
|
2050
2055
|
}
|
|
2051
2056
|
lines.push("");
|
|
2052
2057
|
}
|
|
2053
2058
|
lines.push("## Slices");
|
|
2054
2059
|
lines.push("");
|
|
2055
|
-
const slices =
|
|
2060
|
+
const slices = list_by_kind(idx, "slice");
|
|
2056
2061
|
if (slices.length === 0) lines.push("_(none)_\n");
|
|
2057
2062
|
for (const s of slices) {
|
|
2058
|
-
const sl =
|
|
2063
|
+
const sl = m.slices.find((x) => x.name === s.name);
|
|
2059
2064
|
lines.push(`### \`${s.name}\``);
|
|
2060
2065
|
if (s.file) lines.push(`- **defined in:** \`${loc2(s.file, s.line)}\``);
|
|
2061
2066
|
if (sl) {
|
|
2062
2067
|
if (sl.error) lines.push(`- **error:** ${sl.error}`);
|
|
2063
2068
|
if (sl.states.length > 0)
|
|
2064
2069
|
lines.push(
|
|
2065
|
-
`- **states:** ${sl.states.map((
|
|
2070
|
+
`- **states:** ${sl.states.map((x) => `\`${x}\``).join(", ")}`
|
|
2066
2071
|
);
|
|
2067
2072
|
if (sl.projections.length > 0)
|
|
2068
2073
|
lines.push(
|
|
2069
|
-
`- **projections:** ${sl.projections.map((
|
|
2074
|
+
`- **projections:** ${sl.projections.map((x) => `\`${x}\``).join(", ")}`
|
|
2070
2075
|
);
|
|
2071
2076
|
if (sl.reactions.length > 0) {
|
|
2072
2077
|
lines.push("- **reactions:**");
|
|
2073
|
-
for (const
|
|
2074
|
-
const triggers =
|
|
2078
|
+
for (const r2 of sl.reactions) {
|
|
2079
|
+
const triggers = r2.dispatches.length > 0 ? ` \u2192 ${r2.dispatches.map((d) => `\`${d}\``).join(", ")}` : "";
|
|
2075
2080
|
lines.push(
|
|
2076
|
-
` - \`${
|
|
2081
|
+
` - \`${r2.event}\` \u2192 \`${r2.handlerName}\`${triggers}${file_suffix(r2.file, r2.line)}`
|
|
2077
2082
|
);
|
|
2078
2083
|
}
|
|
2079
2084
|
}
|
|
@@ -2082,36 +2087,36 @@ function formatMarkdown(idx) {
|
|
|
2082
2087
|
}
|
|
2083
2088
|
lines.push("## Projections");
|
|
2084
2089
|
lines.push("");
|
|
2085
|
-
const projections =
|
|
2090
|
+
const projections = list_by_kind(idx, "projection");
|
|
2086
2091
|
if (projections.length === 0) lines.push("_(none)_\n");
|
|
2087
|
-
for (const
|
|
2088
|
-
const pr =
|
|
2089
|
-
lines.push(`### \`${
|
|
2092
|
+
for (const p of projections) {
|
|
2093
|
+
const pr = m.projections.find((x) => x.name === p.name);
|
|
2094
|
+
lines.push(`### \`${p.name}\``);
|
|
2090
2095
|
if (pr?.file) lines.push(`- **defined in:** \`${loc2(pr.file, pr.line)}\``);
|
|
2091
2096
|
if (pr && pr.handles.length > 0)
|
|
2092
2097
|
lines.push(
|
|
2093
|
-
`- **handles:** ${pr.handles.map((
|
|
2098
|
+
`- **handles:** ${pr.handles.map((x) => `\`${x}\``).join(", ")}`
|
|
2094
2099
|
);
|
|
2095
2100
|
lines.push("");
|
|
2096
2101
|
}
|
|
2097
2102
|
lines.push("## Reactions");
|
|
2098
2103
|
lines.push("");
|
|
2099
|
-
const reactions =
|
|
2104
|
+
const reactions = list_by_kind(idx, "reaction");
|
|
2100
2105
|
if (reactions.length === 0) lines.push("_(none)_\n");
|
|
2101
|
-
for (const
|
|
2102
|
-
const [
|
|
2103
|
-
lines.push(`### \`${
|
|
2104
|
-
if (
|
|
2105
|
-
lines.push(`- **in slice:** \`${
|
|
2106
|
-
if (
|
|
2107
|
-
if (
|
|
2108
|
-
const
|
|
2109
|
-
(rr) => rr.handlerName ===
|
|
2106
|
+
for (const r2 of reactions) {
|
|
2107
|
+
const [slice_name, event_name] = (r2.qualifier ?? "::").split("::");
|
|
2108
|
+
lines.push(`### \`${r2.name}\``);
|
|
2109
|
+
if (slice_name && slice_name !== "*")
|
|
2110
|
+
lines.push(`- **in slice:** \`${slice_name}\``);
|
|
2111
|
+
if (event_name) lines.push(`- **on event:** \`${event_name}\``);
|
|
2112
|
+
if (r2.file) lines.push(`- **defined in:** \`${loc2(r2.file, r2.line)}\``);
|
|
2113
|
+
const slice_reaction = m.slices.find((x) => x.name === slice_name)?.reactions.find(
|
|
2114
|
+
(rr) => rr.handlerName === r2.name && rr.event === event_name
|
|
2110
2115
|
);
|
|
2111
|
-
const
|
|
2112
|
-
(rr) => rr.handlerName ===
|
|
2116
|
+
const orch_reaction = m.reactions.find(
|
|
2117
|
+
(rr) => rr.handlerName === r2.name && rr.event === event_name
|
|
2113
2118
|
);
|
|
2114
|
-
const inner =
|
|
2119
|
+
const inner = slice_reaction ?? orch_reaction;
|
|
2115
2120
|
if (inner && inner.dispatches.length > 0) {
|
|
2116
2121
|
lines.push(
|
|
2117
2122
|
`- **triggers:** ${inner.dispatches.map((d) => `\`${d}\``).join(", ")}`
|
|
@@ -2126,11 +2131,11 @@ function formatMarkdown(idx) {
|
|
|
2126
2131
|
import { writeFile } from "fs/promises";
|
|
2127
2132
|
import { resolve as resolve3 } from "path";
|
|
2128
2133
|
|
|
2129
|
-
// ../../node_modules/.pnpm/@clack+core@1.
|
|
2130
|
-
import { styleText
|
|
2131
|
-
import { stdout
|
|
2132
|
-
import * as
|
|
2133
|
-
import
|
|
2134
|
+
// ../../node_modules/.pnpm/@clack+core@1.4.1/node_modules/@clack/core/dist/index.mjs
|
|
2135
|
+
import { styleText } from "util";
|
|
2136
|
+
import { stdout, stdin } from "process";
|
|
2137
|
+
import * as l from "readline";
|
|
2138
|
+
import l__default from "readline";
|
|
2134
2139
|
|
|
2135
2140
|
// ../../node_modules/.pnpm/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/utils.js
|
|
2136
2141
|
var getCodePointsLength = /* @__PURE__ */ (() => {
|
|
@@ -2144,11 +2149,11 @@ var getCodePointsLength = /* @__PURE__ */ (() => {
|
|
|
2144
2149
|
return input.length - surrogatePairsNr;
|
|
2145
2150
|
};
|
|
2146
2151
|
})();
|
|
2147
|
-
var isFullWidth = (
|
|
2148
|
-
return
|
|
2152
|
+
var isFullWidth = (x) => {
|
|
2153
|
+
return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
|
|
2149
2154
|
};
|
|
2150
|
-
var isWideNotCJKTNotEmoji = (
|
|
2151
|
-
return
|
|
2155
|
+
var isWideNotCJKTNotEmoji = (x) => {
|
|
2156
|
+
return x === 8987 || x === 9001 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12441 && x <= 12543 || x >= 12549 && x <= 12591 || x >= 12593 && x <= 12686 || x >= 12688 && x <= 12771 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && x <= 19903 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
|
|
2152
2157
|
};
|
|
2153
2158
|
|
|
2154
2159
|
// ../../node_modules/.pnpm/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/index.js
|
|
@@ -2218,8 +2223,8 @@ var getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {})
|
|
|
2218
2223
|
if (index >= length) {
|
|
2219
2224
|
break outer;
|
|
2220
2225
|
}
|
|
2221
|
-
for (let
|
|
2222
|
-
const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[
|
|
2226
|
+
for (let i2 = 0, l2 = PARSE_BLOCKS.length; i2 < l2; i2++) {
|
|
2227
|
+
const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[i2];
|
|
2223
2228
|
BLOCK_RE.lastIndex = index;
|
|
2224
2229
|
if (BLOCK_RE.test(input)) {
|
|
2225
2230
|
lengthExtra = BLOCK_RE === CJKT_WIDE_RE ? getCodePointsLength(input.slice(index, BLOCK_RE.lastIndex)) : BLOCK_RE === EMOJI_RE ? 1 : BLOCK_RE.lastIndex - index;
|
|
@@ -2422,8 +2427,8 @@ var exec = (string, columns, options = {}) => {
|
|
|
2422
2427
|
}
|
|
2423
2428
|
const preString = rows.join("\n");
|
|
2424
2429
|
let inSurrogate = false;
|
|
2425
|
-
for (let
|
|
2426
|
-
const character = preString[
|
|
2430
|
+
for (let i2 = 0; i2 < preString.length; i2++) {
|
|
2431
|
+
const character = preString[i2];
|
|
2427
2432
|
returnValue += character;
|
|
2428
2433
|
if (!inSurrogate) {
|
|
2429
2434
|
inSurrogate = character >= "\uD800" && character <= "\uDBFF";
|
|
@@ -2434,7 +2439,7 @@ var exec = (string, columns, options = {}) => {
|
|
|
2434
2439
|
inSurrogate = false;
|
|
2435
2440
|
}
|
|
2436
2441
|
if (character === ESC || character === CSI) {
|
|
2437
|
-
GROUP_REGEX.lastIndex =
|
|
2442
|
+
GROUP_REGEX.lastIndex = i2 + 1;
|
|
2438
2443
|
const groupsResult = GROUP_REGEX.exec(preString);
|
|
2439
2444
|
const groups = groupsResult?.groups;
|
|
2440
2445
|
if (groups?.code !== void 0) {
|
|
@@ -2444,7 +2449,7 @@ var exec = (string, columns, options = {}) => {
|
|
|
2444
2449
|
escapeUrl = groups.uri.length === 0 ? void 0 : groups.uri;
|
|
2445
2450
|
}
|
|
2446
2451
|
}
|
|
2447
|
-
if (preString[
|
|
2452
|
+
if (preString[i2 + 1] === "\n") {
|
|
2448
2453
|
if (escapeUrl) {
|
|
2449
2454
|
returnValue += wrapAnsiHyperlink("");
|
|
2450
2455
|
}
|
|
@@ -2468,51 +2473,115 @@ function wrapAnsi(string, columns, options) {
|
|
|
2468
2473
|
return String(string).normalize().split(CRLF_OR_LF).map((line) => exec(line, columns, options)).join("\n");
|
|
2469
2474
|
}
|
|
2470
2475
|
|
|
2471
|
-
// ../../node_modules/.pnpm/@clack+core@1.
|
|
2476
|
+
// ../../node_modules/.pnpm/@clack+core@1.4.1/node_modules/@clack/core/dist/index.mjs
|
|
2472
2477
|
var import_sisteransi = __toESM(require_src(), 1);
|
|
2473
|
-
import { ReadStream
|
|
2474
|
-
function
|
|
2475
|
-
if (!
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
var
|
|
2481
|
-
var
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2478
|
+
import { ReadStream } from "tty";
|
|
2479
|
+
function findCursor(s, o2, l2) {
|
|
2480
|
+
if (!l2.some((r2) => !r2.disabled))
|
|
2481
|
+
return s;
|
|
2482
|
+
const t2 = s + o2, n2 = Math.max(l2.length - 1, 0), e = t2 < 0 ? n2 : t2 > n2 ? 0 : t2;
|
|
2483
|
+
return l2[e].disabled ? findCursor(e, o2 < 0 ? -1 : 1, l2) : e;
|
|
2484
|
+
}
|
|
2485
|
+
var a$2 = ["up", "down", "left", "right", "space", "enter", "cancel"];
|
|
2486
|
+
var t = [
|
|
2487
|
+
"January",
|
|
2488
|
+
"February",
|
|
2489
|
+
"March",
|
|
2490
|
+
"April",
|
|
2491
|
+
"May",
|
|
2492
|
+
"June",
|
|
2493
|
+
"July",
|
|
2494
|
+
"August",
|
|
2495
|
+
"September",
|
|
2496
|
+
"October",
|
|
2497
|
+
"November",
|
|
2498
|
+
"December"
|
|
2499
|
+
];
|
|
2500
|
+
var settings = {
|
|
2501
|
+
actions: new Set(a$2),
|
|
2502
|
+
aliases: /* @__PURE__ */ new Map([
|
|
2503
|
+
// vim support
|
|
2504
|
+
["k", "up"],
|
|
2505
|
+
["j", "down"],
|
|
2506
|
+
["h", "left"],
|
|
2507
|
+
["l", "right"],
|
|
2508
|
+
["", "cancel"],
|
|
2509
|
+
// opinionated defaults!
|
|
2510
|
+
["escape", "cancel"]
|
|
2511
|
+
]),
|
|
2512
|
+
messages: {
|
|
2513
|
+
cancel: "Canceled",
|
|
2514
|
+
error: "Something went wrong"
|
|
2515
|
+
},
|
|
2516
|
+
withGuide: true,
|
|
2517
|
+
date: {
|
|
2518
|
+
monthNames: [...t],
|
|
2519
|
+
messages: {
|
|
2520
|
+
required: "Please enter a valid date",
|
|
2521
|
+
invalidMonth: "There are only 12 months in a year",
|
|
2522
|
+
invalidDay: (n2, e) => `There are only ${n2} days in ${e}`,
|
|
2523
|
+
afterMin: (n2) => `Date must be on or after ${n2.toISOString().slice(0, 10)}`,
|
|
2524
|
+
beforeMax: (n2) => `Date must be on or before ${n2.toISOString().slice(0, 10)}`
|
|
2525
|
+
}
|
|
2526
|
+
}
|
|
2527
|
+
};
|
|
2528
|
+
function isActionKey(n2, e) {
|
|
2529
|
+
if (typeof n2 == "string")
|
|
2530
|
+
return settings.aliases.get(n2) === e;
|
|
2531
|
+
for (const s of n2)
|
|
2532
|
+
if (s !== void 0 && isActionKey(s, e))
|
|
2533
|
+
return true;
|
|
2485
2534
|
return false;
|
|
2486
2535
|
}
|
|
2487
|
-
function
|
|
2488
|
-
if (
|
|
2489
|
-
const
|
|
2490
|
-
`),
|
|
2491
|
-
`),
|
|
2492
|
-
for (let
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
}
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
function
|
|
2507
|
-
const
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2536
|
+
function diffLines(i2, s) {
|
|
2537
|
+
if (i2 === s) return;
|
|
2538
|
+
const e = i2.split(`
|
|
2539
|
+
`), t2 = s.split(`
|
|
2540
|
+
`), r2 = Math.max(e.length, t2.length), f = [];
|
|
2541
|
+
for (let n2 = 0; n2 < r2; n2++)
|
|
2542
|
+
e[n2] !== t2[n2] && f.push(n2);
|
|
2543
|
+
return {
|
|
2544
|
+
lines: f,
|
|
2545
|
+
numLinesBefore: e.length,
|
|
2546
|
+
numLinesAfter: t2.length,
|
|
2547
|
+
numLines: r2
|
|
2548
|
+
};
|
|
2549
|
+
}
|
|
2550
|
+
var R = globalThis.process.platform.startsWith("win");
|
|
2551
|
+
var CANCEL_SYMBOL = /* @__PURE__ */ Symbol("clack:cancel");
|
|
2552
|
+
function isCancel(e) {
|
|
2553
|
+
return e === CANCEL_SYMBOL;
|
|
2554
|
+
}
|
|
2555
|
+
function setRawMode(e, r2) {
|
|
2556
|
+
const o2 = e;
|
|
2557
|
+
o2.isTTY && o2.setRawMode(r2);
|
|
2558
|
+
}
|
|
2559
|
+
var getColumns = (e) => "columns" in e && typeof e.columns == "number" ? e.columns : 80;
|
|
2560
|
+
var getRows = (e) => "rows" in e && typeof e.rows == "number" ? e.rows : 20;
|
|
2561
|
+
function wrapTextWithPrefix(e, r2, o2, t2 = o2, s = o2, n2) {
|
|
2562
|
+
const f = getColumns(e ?? stdout);
|
|
2563
|
+
return wrapAnsi(r2, f - o2.length, {
|
|
2564
|
+
hard: true,
|
|
2565
|
+
trim: false
|
|
2566
|
+
}).split(`
|
|
2567
|
+
`).map((c2, i2, m) => {
|
|
2568
|
+
const d = n2 ? n2(c2, i2) : c2;
|
|
2569
|
+
return i2 === 0 ? `${t2}${d}` : i2 === m.length - 1 ? `${s}${d}` : `${o2}${d}`;
|
|
2512
2570
|
}).join(`
|
|
2513
2571
|
`);
|
|
2514
2572
|
}
|
|
2515
|
-
|
|
2573
|
+
function runValidation(e, n2) {
|
|
2574
|
+
if ("~standard" in e) {
|
|
2575
|
+
const a2 = e["~standard"].validate(n2);
|
|
2576
|
+
if (a2 instanceof Promise)
|
|
2577
|
+
throw new TypeError(
|
|
2578
|
+
"Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic."
|
|
2579
|
+
);
|
|
2580
|
+
return a2.issues?.at(0)?.message;
|
|
2581
|
+
}
|
|
2582
|
+
return e(n2);
|
|
2583
|
+
}
|
|
2584
|
+
var V = class {
|
|
2516
2585
|
input;
|
|
2517
2586
|
output;
|
|
2518
2587
|
_abortSignal;
|
|
@@ -2527,117 +2596,157 @@ var m = class {
|
|
|
2527
2596
|
error = "";
|
|
2528
2597
|
value;
|
|
2529
2598
|
userInput = "";
|
|
2530
|
-
constructor(
|
|
2531
|
-
const { input:
|
|
2532
|
-
this.opts =
|
|
2599
|
+
constructor(t2, e = true) {
|
|
2600
|
+
const { input: i2 = stdin, output: n2 = stdout, render: s, signal: r2, ...o2 } = t2;
|
|
2601
|
+
this.opts = o2, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = s.bind(this), this._track = e, this._abortSignal = r2, this.input = i2, this.output = n2;
|
|
2533
2602
|
}
|
|
2603
|
+
/**
|
|
2604
|
+
* Unsubscribe all listeners
|
|
2605
|
+
*/
|
|
2534
2606
|
unsubscribe() {
|
|
2535
2607
|
this._subscribers.clear();
|
|
2536
2608
|
}
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
this.
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2609
|
+
/**
|
|
2610
|
+
* Set a subscriber with opts
|
|
2611
|
+
* @param event - The event name
|
|
2612
|
+
*/
|
|
2613
|
+
setSubscriber(t2, e) {
|
|
2614
|
+
const i2 = this._subscribers.get(t2) ?? [];
|
|
2615
|
+
i2.push(e), this._subscribers.set(t2, i2);
|
|
2616
|
+
}
|
|
2617
|
+
/**
|
|
2618
|
+
* Subscribe to an event
|
|
2619
|
+
* @param event - The event name
|
|
2620
|
+
* @param cb - The callback
|
|
2621
|
+
*/
|
|
2622
|
+
on(t2, e) {
|
|
2623
|
+
this.setSubscriber(t2, { cb: e });
|
|
2624
|
+
}
|
|
2625
|
+
/**
|
|
2626
|
+
* Subscribe to an event once
|
|
2627
|
+
* @param event - The event name
|
|
2628
|
+
* @param cb - The callback
|
|
2629
|
+
*/
|
|
2630
|
+
once(t2, e) {
|
|
2631
|
+
this.setSubscriber(t2, { cb: e, once: true });
|
|
2632
|
+
}
|
|
2633
|
+
/**
|
|
2634
|
+
* Emit an event with data
|
|
2635
|
+
* @param event - The event name
|
|
2636
|
+
* @param data - The data to pass to the callback
|
|
2637
|
+
*/
|
|
2638
|
+
emit(t2, ...e) {
|
|
2639
|
+
const i2 = this._subscribers.get(t2) ?? [], n2 = [];
|
|
2640
|
+
for (const s of i2)
|
|
2641
|
+
s.cb(...e), s.once && n2.push(() => i2.splice(i2.indexOf(s), 1));
|
|
2642
|
+
for (const s of n2)
|
|
2643
|
+
s();
|
|
2551
2644
|
}
|
|
2552
2645
|
prompt() {
|
|
2553
|
-
return new Promise((
|
|
2646
|
+
return new Promise((t2) => {
|
|
2554
2647
|
if (this._abortSignal) {
|
|
2555
|
-
if (this._abortSignal.aborted)
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2648
|
+
if (this._abortSignal.aborted)
|
|
2649
|
+
return this.state = "cancel", this.close(), t2(CANCEL_SYMBOL);
|
|
2650
|
+
this._abortSignal.addEventListener(
|
|
2651
|
+
"abort",
|
|
2652
|
+
() => {
|
|
2653
|
+
this.state = "cancel", this.close();
|
|
2654
|
+
},
|
|
2655
|
+
{ once: true }
|
|
2656
|
+
);
|
|
2559
2657
|
}
|
|
2560
|
-
this.rl =
|
|
2561
|
-
|
|
2658
|
+
this.rl = l__default.createInterface({
|
|
2659
|
+
input: this.input,
|
|
2660
|
+
tabSize: 2,
|
|
2661
|
+
prompt: "",
|
|
2662
|
+
escapeCodeTimeout: 50,
|
|
2663
|
+
terminal: true
|
|
2664
|
+
}), this.rl.prompt(), this.opts.initialUserInput !== void 0 && this._setUserInput(this.opts.initialUserInput, true), this.input.on("keypress", this.onKeypress), setRawMode(this.input, true), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
|
|
2665
|
+
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t2(this.value);
|
|
2562
2666
|
}), this.once("cancel", () => {
|
|
2563
|
-
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render),
|
|
2667
|
+
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t2(CANCEL_SYMBOL);
|
|
2564
2668
|
});
|
|
2565
2669
|
});
|
|
2566
2670
|
}
|
|
2567
|
-
_isActionKey(
|
|
2568
|
-
return
|
|
2671
|
+
_isActionKey(t2, e) {
|
|
2672
|
+
return t2 === " ";
|
|
2569
2673
|
}
|
|
2570
|
-
_shouldSubmit(
|
|
2674
|
+
_shouldSubmit(t2, e) {
|
|
2571
2675
|
return true;
|
|
2572
2676
|
}
|
|
2573
|
-
_setValue(
|
|
2574
|
-
this.value =
|
|
2677
|
+
_setValue(t2) {
|
|
2678
|
+
this.value = t2, this.emit("value", this.value);
|
|
2575
2679
|
}
|
|
2576
|
-
_setUserInput(
|
|
2577
|
-
this.userInput =
|
|
2680
|
+
_setUserInput(t2, e) {
|
|
2681
|
+
this.userInput = t2 ?? "", this.emit("userInput", this.userInput), e && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
|
|
2578
2682
|
}
|
|
2579
2683
|
_clearUserInput() {
|
|
2580
2684
|
this.rl?.write(null, { ctrl: true, name: "u" }), this._setUserInput("");
|
|
2581
2685
|
}
|
|
2582
|
-
onKeypress(
|
|
2583
|
-
if (this._track &&
|
|
2686
|
+
onKeypress(t2, e) {
|
|
2687
|
+
if (this._track && e.name !== "return" && (e.name && this._isActionKey(t2, e) && this.rl?.write(null, { ctrl: true, name: "h" }), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), e?.name && (!this._track && settings.aliases.has(e.name) && this.emit("cursor", settings.aliases.get(e.name)), settings.actions.has(e.name) && this.emit("cursor", e.name)), t2 && (t2.toLowerCase() === "y" || t2.toLowerCase() === "n") && this.emit("confirm", t2.toLowerCase() === "y"), this.emit("key", t2, e), e?.name === "return" && this._shouldSubmit(t2, e)) {
|
|
2584
2688
|
if (this.opts.validate) {
|
|
2585
|
-
const
|
|
2586
|
-
|
|
2689
|
+
const i2 = runValidation(this.opts.validate, this.value);
|
|
2690
|
+
i2 && (this.error = i2 instanceof Error ? i2.message : i2, this.state = "error", this.rl?.write(this.userInput));
|
|
2587
2691
|
}
|
|
2588
2692
|
this.state !== "error" && (this.state = "submit");
|
|
2589
2693
|
}
|
|
2590
|
-
|
|
2694
|
+
isActionKey([t2, e?.name, e?.sequence], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
|
|
2591
2695
|
}
|
|
2592
2696
|
close() {
|
|
2593
2697
|
this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
|
|
2594
|
-
`),
|
|
2698
|
+
`), setRawMode(this.input, false), this.rl?.close(), this.rl = void 0, this.emit(`${this.state}`, this.value), this.unsubscribe();
|
|
2595
2699
|
}
|
|
2596
2700
|
restoreCursor() {
|
|
2597
|
-
const
|
|
2701
|
+
const t2 = wrapAnsi(this._prevFrame, process.stdout.columns, { hard: true, trim: false }).split(`
|
|
2598
2702
|
`).length - 1;
|
|
2599
|
-
this.output.write(import_sisteransi.cursor.move(-999,
|
|
2703
|
+
this.output.write(import_sisteransi.cursor.move(-999, t2 * -1));
|
|
2600
2704
|
}
|
|
2601
2705
|
render() {
|
|
2602
|
-
const
|
|
2603
|
-
|
|
2604
|
-
|
|
2706
|
+
const t2 = wrapAnsi(this._render(this) ?? "", process.stdout.columns, {
|
|
2707
|
+
hard: true,
|
|
2708
|
+
trim: false
|
|
2709
|
+
});
|
|
2710
|
+
if (t2 !== this._prevFrame) {
|
|
2711
|
+
if (this.state === "initial")
|
|
2712
|
+
this.output.write(import_sisteransi.cursor.hide);
|
|
2605
2713
|
else {
|
|
2606
|
-
const
|
|
2607
|
-
if (this.restoreCursor(),
|
|
2608
|
-
const
|
|
2609
|
-
let
|
|
2610
|
-
if (
|
|
2611
|
-
this._prevFrame =
|
|
2714
|
+
const e = diffLines(this._prevFrame, t2), i2 = getRows(this.output);
|
|
2715
|
+
if (this.restoreCursor(), e) {
|
|
2716
|
+
const n2 = Math.max(0, e.numLinesAfter - i2), s = Math.max(0, e.numLinesBefore - i2);
|
|
2717
|
+
let r2 = e.lines.find((o2) => o2 >= n2);
|
|
2718
|
+
if (r2 === void 0) {
|
|
2719
|
+
this._prevFrame = t2;
|
|
2612
2720
|
return;
|
|
2613
2721
|
}
|
|
2614
|
-
if (
|
|
2615
|
-
this.output.write(import_sisteransi.cursor.move(0,
|
|
2616
|
-
const
|
|
2722
|
+
if (e.lines.length === 1) {
|
|
2723
|
+
this.output.write(import_sisteransi.cursor.move(0, r2 - s)), this.output.write(import_sisteransi.erase.lines(1));
|
|
2724
|
+
const o2 = t2.split(`
|
|
2617
2725
|
`);
|
|
2618
|
-
this.output.write(
|
|
2726
|
+
this.output.write(o2[r2]), this._prevFrame = t2, this.output.write(import_sisteransi.cursor.move(0, o2.length - r2 - 1));
|
|
2619
2727
|
return;
|
|
2620
|
-
} else if (
|
|
2621
|
-
if (
|
|
2728
|
+
} else if (e.lines.length > 1) {
|
|
2729
|
+
if (n2 < s)
|
|
2730
|
+
r2 = n2;
|
|
2622
2731
|
else {
|
|
2623
|
-
const
|
|
2624
|
-
|
|
2732
|
+
const h2 = r2 - s;
|
|
2733
|
+
h2 > 0 && this.output.write(import_sisteransi.cursor.move(0, h2));
|
|
2625
2734
|
}
|
|
2626
2735
|
this.output.write(import_sisteransi.erase.down());
|
|
2627
|
-
const
|
|
2628
|
-
`).slice(
|
|
2629
|
-
this.output.write(
|
|
2630
|
-
`)), this._prevFrame =
|
|
2736
|
+
const f = t2.split(`
|
|
2737
|
+
`).slice(r2);
|
|
2738
|
+
this.output.write(f.join(`
|
|
2739
|
+
`)), this._prevFrame = t2;
|
|
2631
2740
|
return;
|
|
2632
2741
|
}
|
|
2633
2742
|
}
|
|
2634
2743
|
this.output.write(import_sisteransi.erase.down());
|
|
2635
2744
|
}
|
|
2636
|
-
this.output.write(
|
|
2745
|
+
this.output.write(t2), this.state === "initial" && (this.state = "active"), this._prevFrame = t2;
|
|
2637
2746
|
}
|
|
2638
2747
|
}
|
|
2639
2748
|
};
|
|
2640
|
-
var
|
|
2749
|
+
var a = class extends V {
|
|
2641
2750
|
options;
|
|
2642
2751
|
cursor = 0;
|
|
2643
2752
|
get _selectedValue() {
|
|
@@ -2646,270 +2755,366 @@ var ut = class extends m {
|
|
|
2646
2755
|
changeValue() {
|
|
2647
2756
|
this.value = this._selectedValue.value;
|
|
2648
2757
|
}
|
|
2649
|
-
constructor(
|
|
2650
|
-
super(
|
|
2651
|
-
const
|
|
2652
|
-
this.cursor = this.options[
|
|
2653
|
-
switch (
|
|
2758
|
+
constructor(t2) {
|
|
2759
|
+
super(t2, false), this.options = t2.options;
|
|
2760
|
+
const i2 = this.options.findIndex(({ value: s }) => s === t2.initialValue), e = i2 === -1 ? 0 : i2;
|
|
2761
|
+
this.cursor = this.options[e].disabled ? findCursor(e, 1, this.options) : e, this.changeValue(), this.on("cursor", (s) => {
|
|
2762
|
+
switch (s) {
|
|
2654
2763
|
case "left":
|
|
2655
2764
|
case "up":
|
|
2656
|
-
this.cursor =
|
|
2765
|
+
this.cursor = findCursor(this.cursor, -1, this.options);
|
|
2657
2766
|
break;
|
|
2658
2767
|
case "down":
|
|
2659
2768
|
case "right":
|
|
2660
|
-
this.cursor =
|
|
2769
|
+
this.cursor = findCursor(this.cursor, 1, this.options);
|
|
2661
2770
|
break;
|
|
2662
2771
|
}
|
|
2663
2772
|
this.changeValue();
|
|
2664
2773
|
});
|
|
2665
2774
|
}
|
|
2666
2775
|
};
|
|
2667
|
-
var
|
|
2776
|
+
var n = class extends V {
|
|
2668
2777
|
get userInputWithCursor() {
|
|
2669
|
-
if (this.state === "submit")
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2778
|
+
if (this.state === "submit")
|
|
2779
|
+
return this.userInput;
|
|
2780
|
+
const t2 = this.userInput;
|
|
2781
|
+
if (this.cursor >= t2.length)
|
|
2782
|
+
return `${this.userInput}\u2588`;
|
|
2783
|
+
const e = t2.slice(0, this.cursor), [s, ...r2] = t2.slice(this.cursor);
|
|
2784
|
+
return `${e}${styleText("inverse", s)}${r2.join("")}`;
|
|
2674
2785
|
}
|
|
2675
2786
|
get cursor() {
|
|
2676
2787
|
return this._cursor;
|
|
2677
2788
|
}
|
|
2678
|
-
constructor(
|
|
2679
|
-
super({
|
|
2680
|
-
|
|
2789
|
+
constructor(t2) {
|
|
2790
|
+
super({
|
|
2791
|
+
...t2,
|
|
2792
|
+
initialUserInput: t2.initialUserInput ?? t2.initialValue
|
|
2793
|
+
}), this.on("userInput", (e) => {
|
|
2794
|
+
this._setValue(e);
|
|
2681
2795
|
}), this.on("finalize", () => {
|
|
2682
|
-
this.value || (this.value =
|
|
2796
|
+
this.value || (this.value = t2.defaultValue), this.value === void 0 && (this.value = "");
|
|
2683
2797
|
});
|
|
2684
2798
|
}
|
|
2685
2799
|
};
|
|
2686
2800
|
|
|
2687
|
-
// ../../node_modules/.pnpm/@clack+prompts@1.
|
|
2688
|
-
import { styleText as
|
|
2689
|
-
import
|
|
2801
|
+
// ../../node_modules/.pnpm/@clack+prompts@1.5.1/node_modules/@clack/prompts/dist/index.mjs
|
|
2802
|
+
import { styleText as styleText2, stripVTControlCharacters } from "util";
|
|
2803
|
+
import process$1 from "process";
|
|
2690
2804
|
var import_sisteransi2 = __toESM(require_src(), 1);
|
|
2691
|
-
import { existsSync
|
|
2692
|
-
import { dirname
|
|
2693
|
-
function
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
var
|
|
2700
|
-
var
|
|
2701
|
-
var
|
|
2702
|
-
var
|
|
2703
|
-
var
|
|
2704
|
-
var
|
|
2705
|
-
var
|
|
2706
|
-
var
|
|
2707
|
-
var
|
|
2708
|
-
var
|
|
2709
|
-
var
|
|
2710
|
-
var
|
|
2711
|
-
var
|
|
2712
|
-
var
|
|
2713
|
-
var
|
|
2714
|
-
var
|
|
2715
|
-
var
|
|
2716
|
-
var
|
|
2717
|
-
var
|
|
2718
|
-
var
|
|
2719
|
-
var
|
|
2720
|
-
var
|
|
2721
|
-
var
|
|
2722
|
-
var
|
|
2723
|
-
var
|
|
2724
|
-
|
|
2805
|
+
import { existsSync, lstatSync, readdirSync } from "fs";
|
|
2806
|
+
import { dirname, join } from "path";
|
|
2807
|
+
function isUnicodeSupported() {
|
|
2808
|
+
if (process$1.platform !== "win32") {
|
|
2809
|
+
return process$1.env.TERM !== "linux";
|
|
2810
|
+
}
|
|
2811
|
+
return Boolean(process$1.env.CI) || Boolean(process$1.env.WT_SESSION) || Boolean(process$1.env.TERMINUS_SUBLIME) || process$1.env.ConEmuTask === "{cmd::Cmder}" || process$1.env.TERM_PROGRAM === "Terminus-Sublime" || process$1.env.TERM_PROGRAM === "vscode" || process$1.env.TERM === "xterm-256color" || process$1.env.TERM === "alacritty" || process$1.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
2812
|
+
}
|
|
2813
|
+
var unicode = isUnicodeSupported();
|
|
2814
|
+
var unicodeOr = (e, o2) => unicode ? e : o2;
|
|
2815
|
+
var S_STEP_ACTIVE = unicodeOr("\u25C6", "*");
|
|
2816
|
+
var S_STEP_CANCEL = unicodeOr("\u25A0", "x");
|
|
2817
|
+
var S_STEP_ERROR = unicodeOr("\u25B2", "x");
|
|
2818
|
+
var S_STEP_SUBMIT = unicodeOr("\u25C7", "o");
|
|
2819
|
+
var S_BAR_START = unicodeOr("\u250C", "T");
|
|
2820
|
+
var S_BAR = unicodeOr("\u2502", "|");
|
|
2821
|
+
var S_BAR_END = unicodeOr("\u2514", "\u2014");
|
|
2822
|
+
var S_BAR_START_RIGHT = unicodeOr("\u2510", "T");
|
|
2823
|
+
var S_BAR_END_RIGHT = unicodeOr("\u2518", "\u2014");
|
|
2824
|
+
var S_RADIO_ACTIVE = unicodeOr("\u25CF", ">");
|
|
2825
|
+
var S_RADIO_INACTIVE = unicodeOr("\u25CB", " ");
|
|
2826
|
+
var S_CHECKBOX_ACTIVE = unicodeOr("\u25FB", "[\u2022]");
|
|
2827
|
+
var S_CHECKBOX_SELECTED = unicodeOr("\u25FC", "[+]");
|
|
2828
|
+
var S_CHECKBOX_INACTIVE = unicodeOr("\u25FB", "[ ]");
|
|
2829
|
+
var S_PASSWORD_MASK = unicodeOr("\u25AA", "\u2022");
|
|
2830
|
+
var S_BAR_H = unicodeOr("\u2500", "-");
|
|
2831
|
+
var S_CORNER_TOP_RIGHT = unicodeOr("\u256E", "+");
|
|
2832
|
+
var S_CONNECT_LEFT = unicodeOr("\u251C", "+");
|
|
2833
|
+
var S_CORNER_BOTTOM_RIGHT = unicodeOr("\u256F", "+");
|
|
2834
|
+
var S_CORNER_BOTTOM_LEFT = unicodeOr("\u2570", "+");
|
|
2835
|
+
var S_CORNER_TOP_LEFT = unicodeOr("\u256D", "+");
|
|
2836
|
+
var S_INFO = unicodeOr("\u25CF", "\u2022");
|
|
2837
|
+
var S_SUCCESS = unicodeOr("\u25C6", "*");
|
|
2838
|
+
var S_WARN = unicodeOr("\u25B2", "!");
|
|
2839
|
+
var S_ERROR = unicodeOr("\u25A0", "x");
|
|
2840
|
+
var symbol = (e) => {
|
|
2841
|
+
switch (e) {
|
|
2725
2842
|
case "initial":
|
|
2726
2843
|
case "active":
|
|
2727
|
-
return
|
|
2844
|
+
return styleText2("cyan", S_STEP_ACTIVE);
|
|
2728
2845
|
case "cancel":
|
|
2729
|
-
return
|
|
2846
|
+
return styleText2("red", S_STEP_CANCEL);
|
|
2730
2847
|
case "error":
|
|
2731
|
-
return
|
|
2848
|
+
return styleText2("yellow", S_STEP_ERROR);
|
|
2732
2849
|
case "submit":
|
|
2733
|
-
return
|
|
2850
|
+
return styleText2("green", S_STEP_SUBMIT);
|
|
2734
2851
|
}
|
|
2735
2852
|
};
|
|
2736
|
-
var
|
|
2737
|
-
switch (
|
|
2853
|
+
var symbolBar = (e) => {
|
|
2854
|
+
switch (e) {
|
|
2738
2855
|
case "initial":
|
|
2739
2856
|
case "active":
|
|
2740
|
-
return
|
|
2857
|
+
return styleText2("cyan", S_BAR);
|
|
2741
2858
|
case "cancel":
|
|
2742
|
-
return
|
|
2859
|
+
return styleText2("red", S_BAR);
|
|
2743
2860
|
case "error":
|
|
2744
|
-
return
|
|
2861
|
+
return styleText2("yellow", S_BAR);
|
|
2745
2862
|
case "submit":
|
|
2746
|
-
return
|
|
2863
|
+
return styleText2("green", S_BAR);
|
|
2747
2864
|
}
|
|
2748
2865
|
};
|
|
2749
|
-
var
|
|
2750
|
-
let
|
|
2751
|
-
if (
|
|
2752
|
-
|
|
2753
|
-
|
|
2866
|
+
var E$1 = (l2, o2, g, c2, h2, O = false) => {
|
|
2867
|
+
let r2 = o2, w = 0;
|
|
2868
|
+
if (O)
|
|
2869
|
+
for (let i2 = c2 - 1; i2 >= g && (r2 -= l2[i2].length, w++, !(r2 <= h2)); i2--)
|
|
2870
|
+
;
|
|
2871
|
+
else
|
|
2872
|
+
for (let i2 = g; i2 < c2 && (r2 -= l2[i2].length, w++, !(r2 <= h2)); i2++)
|
|
2873
|
+
;
|
|
2874
|
+
return { lineCount: r2, removals: w };
|
|
2754
2875
|
};
|
|
2755
|
-
var
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2876
|
+
var limitOptions = ({
|
|
2877
|
+
cursor: l2,
|
|
2878
|
+
options: o2,
|
|
2879
|
+
style: g,
|
|
2880
|
+
output: c2 = process.stdout,
|
|
2881
|
+
maxItems: h2 = Number.POSITIVE_INFINITY,
|
|
2882
|
+
columnPadding: O = 0,
|
|
2883
|
+
rowPadding: r2 = 4
|
|
2884
|
+
}) => {
|
|
2885
|
+
const i2 = getColumns(c2) - O, I = getRows(c2), C = styleText2("dim", "..."), x = Math.max(I - r2, 0), m = Math.max(Math.min(h2, x), 5);
|
|
2886
|
+
let p = 0;
|
|
2887
|
+
l2 >= m - 3 && (p = Math.max(
|
|
2888
|
+
Math.min(l2 - m + 3, o2.length - m),
|
|
2889
|
+
0
|
|
2890
|
+
));
|
|
2891
|
+
let f = m < o2.length && p > 0, u3 = m < o2.length && p + m < o2.length;
|
|
2892
|
+
const W = Math.min(
|
|
2893
|
+
p + m,
|
|
2894
|
+
o2.length
|
|
2895
|
+
), e = [];
|
|
2896
|
+
let d = 0;
|
|
2897
|
+
f && d++, u3 && d++;
|
|
2898
|
+
const v = p + (f ? 1 : 0), P = W - (u3 ? 1 : 0);
|
|
2899
|
+
for (let t2 = v; t2 < P; t2++) {
|
|
2900
|
+
const n2 = wrapAnsi(g(o2[t2], t2 === l2), i2, {
|
|
2901
|
+
hard: true,
|
|
2902
|
+
trim: false
|
|
2903
|
+
}).split(`
|
|
2766
2904
|
`);
|
|
2767
|
-
|
|
2768
|
-
}
|
|
2769
|
-
if (
|
|
2770
|
-
let
|
|
2771
|
-
const
|
|
2772
|
-
let
|
|
2773
|
-
const
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2905
|
+
e.push(n2), d += n2.length;
|
|
2906
|
+
}
|
|
2907
|
+
if (d > x) {
|
|
2908
|
+
let t2 = 0, n2 = 0, s = d;
|
|
2909
|
+
const M = l2 - v;
|
|
2910
|
+
let a2 = x;
|
|
2911
|
+
const T = () => E$1(e, s, 0, M, a2), L = () => E$1(
|
|
2912
|
+
e,
|
|
2913
|
+
s,
|
|
2914
|
+
M + 1,
|
|
2915
|
+
e.length,
|
|
2916
|
+
a2,
|
|
2917
|
+
true
|
|
2918
|
+
);
|
|
2919
|
+
f ? ({ lineCount: s, removals: t2 } = T(), s > a2 && (u3 || (a2 -= 1), { lineCount: s, removals: n2 } = L())) : (u3 || (a2 -= 1), { lineCount: s, removals: n2 } = L(), s > a2 && (a2 -= 1, { lineCount: s, removals: t2 } = T())), t2 > 0 && (f = true, e.splice(0, t2)), n2 > 0 && (u3 = true, e.splice(e.length - n2, n2));
|
|
2920
|
+
}
|
|
2921
|
+
const b = [];
|
|
2922
|
+
f && b.push(C);
|
|
2923
|
+
for (const t2 of e)
|
|
2924
|
+
for (const n2 of t2)
|
|
2925
|
+
b.push(n2);
|
|
2926
|
+
return u3 && b.push(C), b;
|
|
2780
2927
|
};
|
|
2781
|
-
var
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2928
|
+
var log = {
|
|
2929
|
+
message: (s = [], {
|
|
2930
|
+
symbol: e = styleText2("gray", S_BAR),
|
|
2931
|
+
secondarySymbol: r2 = styleText2("gray", S_BAR),
|
|
2932
|
+
output: m = process.stdout,
|
|
2933
|
+
spacing: l2 = 1,
|
|
2934
|
+
withGuide: c2
|
|
2935
|
+
} = {}) => {
|
|
2936
|
+
const t2 = [], o2 = c2 ?? settings.withGuide, f = o2 ? r2 : "", O = o2 ? `${e} ` : "", u3 = o2 ? `${r2} ` : "";
|
|
2937
|
+
for (let i2 = 0; i2 < l2; i2++)
|
|
2938
|
+
t2.push(f);
|
|
2939
|
+
const g = Array.isArray(s) ? s : s.split(`
|
|
2785
2940
|
`);
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2941
|
+
if (g.length > 0) {
|
|
2942
|
+
const [i2, ...y] = g;
|
|
2943
|
+
i2.length > 0 ? t2.push(`${O}${i2}`) : t2.push(o2 ? e : "");
|
|
2944
|
+
for (const p of y)
|
|
2945
|
+
p.length > 0 ? t2.push(`${u3}${p}`) : t2.push(o2 ? r2 : "");
|
|
2946
|
+
}
|
|
2947
|
+
m.write(`${t2.join(`
|
|
2792
2948
|
`)}
|
|
2793
2949
|
`);
|
|
2794
|
-
},
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
},
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
}
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2950
|
+
},
|
|
2951
|
+
info: (s, e) => {
|
|
2952
|
+
log.message(s, { ...e, symbol: styleText2("blue", S_INFO) });
|
|
2953
|
+
},
|
|
2954
|
+
success: (s, e) => {
|
|
2955
|
+
log.message(s, { ...e, symbol: styleText2("green", S_SUCCESS) });
|
|
2956
|
+
},
|
|
2957
|
+
step: (s, e) => {
|
|
2958
|
+
log.message(s, { ...e, symbol: styleText2("green", S_STEP_SUBMIT) });
|
|
2959
|
+
},
|
|
2960
|
+
warn: (s, e) => {
|
|
2961
|
+
log.message(s, { ...e, symbol: styleText2("yellow", S_WARN) });
|
|
2962
|
+
},
|
|
2963
|
+
/** alias for `log.warn()`. */
|
|
2964
|
+
warning: (s, e) => {
|
|
2965
|
+
log.warn(s, e);
|
|
2966
|
+
},
|
|
2967
|
+
error: (s, e) => {
|
|
2968
|
+
log.message(s, { ...e, symbol: styleText2("red", S_ERROR) });
|
|
2969
|
+
}
|
|
2970
|
+
};
|
|
2971
|
+
var intro = (o2 = "", t2) => {
|
|
2972
|
+
const i2 = t2?.output ?? process.stdout, e = t2?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR_START)} ` : "";
|
|
2973
|
+
i2.write(`${e}${o2}
|
|
2810
2974
|
`);
|
|
2811
2975
|
};
|
|
2812
|
-
var
|
|
2813
|
-
const
|
|
2814
|
-
${
|
|
2815
|
-
|
|
2976
|
+
var outro = (o2 = "", t2) => {
|
|
2977
|
+
const i2 = t2?.output ?? process.stdout, e = t2?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR)}
|
|
2978
|
+
${styleText2("gray", S_BAR_END)} ` : "";
|
|
2979
|
+
i2.write(`${e}${o2}
|
|
2816
2980
|
|
|
2817
2981
|
`);
|
|
2818
2982
|
};
|
|
2819
|
-
var
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
var
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2983
|
+
var u2 = {
|
|
2984
|
+
light: unicodeOr("\u2500", "-"),
|
|
2985
|
+
heavy: unicodeOr("\u2501", "="),
|
|
2986
|
+
block: unicodeOr("\u2588", "#")
|
|
2987
|
+
};
|
|
2988
|
+
var c = (e, a2) => e.includes(`
|
|
2989
|
+
`) ? e.split(`
|
|
2990
|
+
`).map((t2) => a2(t2)).join(`
|
|
2991
|
+
`) : a2(e);
|
|
2992
|
+
var select = (e) => {
|
|
2993
|
+
const a2 = (t2, d) => {
|
|
2994
|
+
const s = t2.label ?? String(t2.value);
|
|
2995
|
+
switch (d) {
|
|
2828
2996
|
case "disabled":
|
|
2829
|
-
return `${
|
|
2997
|
+
return `${styleText2("gray", S_RADIO_INACTIVE)} ${c(s, (n2) => styleText2("gray", n2))}${t2.hint ? ` ${styleText2("dim", `(${t2.hint ?? "disabled"})`)}` : ""}`;
|
|
2830
2998
|
case "selected":
|
|
2831
|
-
return `${
|
|
2999
|
+
return `${c(s, (n2) => styleText2("dim", n2))}`;
|
|
2832
3000
|
case "active":
|
|
2833
|
-
return `${
|
|
3001
|
+
return `${styleText2("green", S_RADIO_ACTIVE)} ${s}${t2.hint ? ` ${styleText2("dim", `(${t2.hint})`)}` : ""}`;
|
|
2834
3002
|
case "cancelled":
|
|
2835
|
-
return `${
|
|
3003
|
+
return `${c(s, (n2) => styleText2(["strikethrough", "dim"], n2))}`;
|
|
2836
3004
|
default:
|
|
2837
|
-
return `${
|
|
3005
|
+
return `${styleText2("dim", S_RADIO_INACTIVE)} ${c(s, (n2) => styleText2("dim", n2))}`;
|
|
2838
3006
|
}
|
|
2839
3007
|
};
|
|
2840
|
-
return new
|
|
2841
|
-
|
|
2842
|
-
|
|
3008
|
+
return new a({
|
|
3009
|
+
options: e.options,
|
|
3010
|
+
signal: e.signal,
|
|
3011
|
+
input: e.input,
|
|
3012
|
+
output: e.output,
|
|
3013
|
+
initialValue: e.initialValue,
|
|
3014
|
+
render() {
|
|
3015
|
+
const t2 = e.withGuide ?? settings.withGuide, d = `${symbol(this.state)} `, s = `${symbolBar(this.state)} `, n2 = wrapTextWithPrefix(
|
|
3016
|
+
e.output,
|
|
3017
|
+
e.message,
|
|
3018
|
+
s,
|
|
3019
|
+
d
|
|
3020
|
+
), u3 = `${t2 ? `${styleText2("gray", S_BAR)}
|
|
3021
|
+
` : ""}${n2}
|
|
2843
3022
|
`;
|
|
3023
|
+
switch (this.state) {
|
|
3024
|
+
case "submit": {
|
|
3025
|
+
const r2 = t2 ? `${styleText2("gray", S_BAR)} ` : "", l2 = wrapTextWithPrefix(
|
|
3026
|
+
e.output,
|
|
3027
|
+
a2(this.options[this.cursor], "selected"),
|
|
3028
|
+
r2
|
|
3029
|
+
);
|
|
3030
|
+
return `${u3}${l2}`;
|
|
3031
|
+
}
|
|
3032
|
+
case "cancel": {
|
|
3033
|
+
const r2 = t2 ? `${styleText2("gray", S_BAR)} ` : "", l2 = wrapTextWithPrefix(
|
|
3034
|
+
e.output,
|
|
3035
|
+
a2(this.options[this.cursor], "cancelled"),
|
|
3036
|
+
r2
|
|
3037
|
+
);
|
|
3038
|
+
return `${u3}${l2}${t2 ? `
|
|
3039
|
+
${styleText2("gray", S_BAR)}` : ""}`;
|
|
3040
|
+
}
|
|
3041
|
+
default: {
|
|
3042
|
+
const r2 = t2 ? `${styleText2("cyan", S_BAR)} ` : "", l2 = t2 ? styleText2("cyan", S_BAR_END) : "", g = u3.split(`
|
|
3043
|
+
`).length, h2 = t2 ? 2 : 1;
|
|
3044
|
+
return `${u3}${r2}${limitOptions({
|
|
3045
|
+
output: e.output,
|
|
3046
|
+
cursor: this.cursor,
|
|
3047
|
+
options: this.options,
|
|
3048
|
+
maxItems: e.maxItems,
|
|
3049
|
+
columnPadding: r2.length,
|
|
3050
|
+
rowPadding: g + h2,
|
|
3051
|
+
style: (p, b) => a2(p, p.disabled ? "disabled" : b ? "active" : "inactive")
|
|
3052
|
+
}).join(`
|
|
3053
|
+
${r2}`)}
|
|
3054
|
+
${l2}
|
|
3055
|
+
`;
|
|
3056
|
+
}
|
|
3057
|
+
}
|
|
3058
|
+
}
|
|
3059
|
+
}).prompt();
|
|
3060
|
+
};
|
|
3061
|
+
var i = `${styleText2("gray", S_BAR)} `;
|
|
3062
|
+
var text = (t2) => new n({
|
|
3063
|
+
validate: t2.validate,
|
|
3064
|
+
placeholder: t2.placeholder,
|
|
3065
|
+
defaultValue: t2.defaultValue,
|
|
3066
|
+
initialValue: t2.initialValue,
|
|
3067
|
+
output: t2.output,
|
|
3068
|
+
signal: t2.signal,
|
|
3069
|
+
input: t2.input,
|
|
3070
|
+
render() {
|
|
3071
|
+
const i2 = t2?.withGuide ?? settings.withGuide, s = `${`${i2 ? `${styleText2("gray", S_BAR)}
|
|
3072
|
+
` : ""}${symbol(this.state)} `}${t2.message}
|
|
3073
|
+
`, c2 = t2.placeholder ? styleText2("inverse", t2.placeholder[0]) + styleText2("dim", t2.placeholder.slice(1)) : styleText2(["inverse", "hidden"], "_"), o2 = this.userInput ? this.userInputWithCursor : c2, a2 = this.value ?? "";
|
|
2844
3074
|
switch (this.state) {
|
|
3075
|
+
case "error": {
|
|
3076
|
+
const n2 = this.error ? ` ${styleText2("yellow", this.error)}` : "", r2 = i2 ? `${styleText2("yellow", S_BAR)} ` : "", d = i2 ? styleText2("yellow", S_BAR_END) : "";
|
|
3077
|
+
return `${s.trim()}
|
|
3078
|
+
${r2}${o2}
|
|
3079
|
+
${d}${n2}
|
|
3080
|
+
`;
|
|
3081
|
+
}
|
|
2845
3082
|
case "submit": {
|
|
2846
|
-
const
|
|
2847
|
-
return `${
|
|
3083
|
+
const n2 = a2 ? ` ${styleText2("dim", a2)}` : "", r2 = i2 ? styleText2("gray", S_BAR) : "";
|
|
3084
|
+
return `${s}${r2}${n2}`;
|
|
2848
3085
|
}
|
|
2849
3086
|
case "cancel": {
|
|
2850
|
-
const
|
|
2851
|
-
return `${
|
|
2852
|
-
${
|
|
3087
|
+
const n2 = a2 ? ` ${styleText2(["strikethrough", "dim"], a2)}` : "", r2 = i2 ? styleText2("gray", S_BAR) : "";
|
|
3088
|
+
return `${s}${r2}${n2}${a2.trim() ? `
|
|
3089
|
+
${r2}` : ""}`;
|
|
2853
3090
|
}
|
|
2854
3091
|
default: {
|
|
2855
|
-
const
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
${c}`)}
|
|
2859
|
-
${o}
|
|
3092
|
+
const n2 = i2 ? `${styleText2("cyan", S_BAR)} ` : "", r2 = i2 ? styleText2("cyan", S_BAR_END) : "";
|
|
3093
|
+
return `${s}${n2}${o2}
|
|
3094
|
+
${r2}
|
|
2860
3095
|
`;
|
|
2861
3096
|
}
|
|
2862
3097
|
}
|
|
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
3098
|
}
|
|
2894
|
-
}
|
|
3099
|
+
}).prompt();
|
|
2895
3100
|
|
|
2896
3101
|
// src/cli/open-editor.ts
|
|
2897
3102
|
import { spawn } from "child_process";
|
|
2898
3103
|
import { resolve as resolve2 } from "path";
|
|
2899
|
-
var
|
|
2900
|
-
function
|
|
3104
|
+
var is_code_family = (cmd) => /(^|\/)code(-insiders)?(\.exe)?$/i.test(cmd) || /(^|\/)cursor(\.exe)?$/i.test(cmd);
|
|
3105
|
+
function pick_editor(env, override) {
|
|
2901
3106
|
if (override) return override;
|
|
2902
3107
|
return env.VISUAL || env.EDITOR || "vi";
|
|
2903
3108
|
}
|
|
2904
|
-
function
|
|
2905
|
-
if (line &&
|
|
3109
|
+
function editor_args(editor, file, line) {
|
|
3110
|
+
if (line && is_code_family(editor)) return ["--goto", `${file}:${line}`];
|
|
2906
3111
|
if (line) return [`+${line}`, file];
|
|
2907
3112
|
return [file];
|
|
2908
3113
|
}
|
|
2909
|
-
async function
|
|
2910
|
-
const editor =
|
|
2911
|
-
const
|
|
2912
|
-
const args =
|
|
3114
|
+
async function open_in_editor(file, line, deps) {
|
|
3115
|
+
const editor = pick_editor(process.env, deps.editor);
|
|
3116
|
+
const abs_path = resolve2(deps.root_dir, file);
|
|
3117
|
+
const args = editor_args(editor, abs_path, line);
|
|
2913
3118
|
return await new Promise((resolveP) => {
|
|
2914
3119
|
const child = spawn(editor, args, {
|
|
2915
3120
|
/* c8 ignore next — "inherit" path runs only inside a real TTY. */
|
|
@@ -2939,30 +3144,30 @@ function classify(chunk) {
|
|
|
2939
3144
|
if (matches(chunk, "/")) return "slash";
|
|
2940
3145
|
return null;
|
|
2941
3146
|
}
|
|
2942
|
-
function enableVimKeys(
|
|
2943
|
-
const
|
|
3147
|
+
function enableVimKeys(stdin2) {
|
|
3148
|
+
const orig_emit = stdin2.emit.bind(stdin2);
|
|
2944
3149
|
let active = true;
|
|
2945
|
-
const
|
|
3150
|
+
const slash_listeners = [];
|
|
2946
3151
|
const patched = (event, ...args) => {
|
|
2947
3152
|
if (active && event === "data" && args[0] instanceof Buffer) {
|
|
2948
3153
|
const direction = classify(args[0]);
|
|
2949
|
-
if (direction === "down") return
|
|
2950
|
-
if (direction === "up") return
|
|
2951
|
-
if (direction === "cancel") return
|
|
3154
|
+
if (direction === "down") return orig_emit("data", DOWN);
|
|
3155
|
+
if (direction === "up") return orig_emit("data", UP);
|
|
3156
|
+
if (direction === "cancel") return orig_emit("data", ESC2);
|
|
2952
3157
|
if (direction === "slash") {
|
|
2953
|
-
for (const cb of
|
|
2954
|
-
return
|
|
3158
|
+
for (const cb of slash_listeners) cb();
|
|
3159
|
+
return orig_emit("data", ESC2);
|
|
2955
3160
|
}
|
|
2956
3161
|
}
|
|
2957
|
-
return
|
|
3162
|
+
return orig_emit(event, ...args);
|
|
2958
3163
|
};
|
|
2959
|
-
|
|
3164
|
+
stdin2.emit = patched;
|
|
2960
3165
|
let restored = false;
|
|
2961
3166
|
return {
|
|
2962
3167
|
restore: () => {
|
|
2963
3168
|
if (restored) return;
|
|
2964
3169
|
restored = true;
|
|
2965
|
-
if (
|
|
3170
|
+
if (stdin2.emit === patched) stdin2.emit = orig_emit;
|
|
2966
3171
|
},
|
|
2967
3172
|
pause: () => {
|
|
2968
3173
|
active = false;
|
|
@@ -2970,19 +3175,19 @@ function enableVimKeys(stdin) {
|
|
|
2970
3175
|
resume: () => {
|
|
2971
3176
|
active = true;
|
|
2972
3177
|
},
|
|
2973
|
-
|
|
2974
|
-
|
|
3178
|
+
on_slash: (cb) => {
|
|
3179
|
+
slash_listeners.push(cb);
|
|
2975
3180
|
return () => {
|
|
2976
|
-
const
|
|
2977
|
-
if (
|
|
3181
|
+
const i2 = slash_listeners.indexOf(cb);
|
|
3182
|
+
if (i2 >= 0) slash_listeners.splice(i2, 1);
|
|
2978
3183
|
};
|
|
2979
3184
|
}
|
|
2980
3185
|
};
|
|
2981
3186
|
}
|
|
2982
3187
|
|
|
2983
3188
|
// src/cli/repl.ts
|
|
2984
|
-
var
|
|
2985
|
-
var
|
|
3189
|
+
var vim_keys = null;
|
|
3190
|
+
var search_requested = false;
|
|
2986
3191
|
var NAV_LEGEND = dim("j/k or \u2191/\u2193 move \xB7 enter pick \xB7 / search \xB7 esc/q back");
|
|
2987
3192
|
var KIND_LABELS = {
|
|
2988
3193
|
event: "events",
|
|
@@ -3000,39 +3205,39 @@ var KIND_ORDER = [
|
|
|
3000
3205
|
"projection",
|
|
3001
3206
|
"reaction"
|
|
3002
3207
|
];
|
|
3003
|
-
var
|
|
3004
|
-
if (kind === "event") return idx.
|
|
3005
|
-
return idx.entries.filter((
|
|
3208
|
+
var count_by_kind = (idx, kind) => {
|
|
3209
|
+
if (kind === "event") return idx.all_event_names.size;
|
|
3210
|
+
return idx.entries.filter((e) => e.kind === kind).length;
|
|
3006
3211
|
};
|
|
3007
|
-
var
|
|
3008
|
-
const loc3 =
|
|
3212
|
+
var label_entry = (e) => {
|
|
3213
|
+
const loc3 = e.file ? `${e.file}${e.line ? `:${e.line}` : ""}` : "";
|
|
3009
3214
|
const where = loc3 ? ` ${dim(loc3)}` : "";
|
|
3010
|
-
const qual =
|
|
3011
|
-
const colored =
|
|
3215
|
+
const qual = e.qualifier ? dim(` (${e.qualifier})`) : "";
|
|
3216
|
+
const colored = kind_color[e.kind](e.name);
|
|
3012
3217
|
return `${colored}${qual}${where}`;
|
|
3013
3218
|
};
|
|
3014
|
-
async function
|
|
3219
|
+
async function pick_from_list(idx, root_dir, message, entries) {
|
|
3015
3220
|
if (entries.length === 0) {
|
|
3016
|
-
|
|
3221
|
+
log.warn("nothing to show.");
|
|
3017
3222
|
return;
|
|
3018
3223
|
}
|
|
3019
|
-
const pick = await
|
|
3224
|
+
const pick = await select({
|
|
3020
3225
|
message: `${message} ${NAV_LEGEND}`,
|
|
3021
|
-
options: entries.map((
|
|
3022
|
-
value:
|
|
3023
|
-
label:
|
|
3024
|
-
hint:
|
|
3226
|
+
options: entries.map((e) => ({
|
|
3227
|
+
value: e,
|
|
3228
|
+
label: label_entry(e),
|
|
3229
|
+
hint: e.kind
|
|
3025
3230
|
})),
|
|
3026
3231
|
maxItems: 12
|
|
3027
3232
|
});
|
|
3028
|
-
if (
|
|
3029
|
-
await
|
|
3233
|
+
if (isCancel(pick)) return;
|
|
3234
|
+
await show_detail(idx, root_dir, pick);
|
|
3030
3235
|
}
|
|
3031
|
-
async function
|
|
3032
|
-
|
|
3236
|
+
async function show_detail(idx, root_dir, entry) {
|
|
3237
|
+
log.message(format_detail(idx, entry));
|
|
3033
3238
|
if (!entry.file) return;
|
|
3034
|
-
const editor =
|
|
3035
|
-
const action = await
|
|
3239
|
+
const editor = pick_editor(process.env);
|
|
3240
|
+
const action = await select({
|
|
3036
3241
|
message: `now what? ${NAV_LEGEND}`,
|
|
3037
3242
|
options: [
|
|
3038
3243
|
{
|
|
@@ -3042,16 +3247,16 @@ async function showDetail(idx, rootDir, entry) {
|
|
|
3042
3247
|
}
|
|
3043
3248
|
]
|
|
3044
3249
|
});
|
|
3045
|
-
if (
|
|
3046
|
-
const result = await
|
|
3047
|
-
if (!result.ok)
|
|
3250
|
+
if (isCancel(action)) return;
|
|
3251
|
+
const result = await open_in_editor(entry.file, entry.line, { root_dir });
|
|
3252
|
+
if (!result.ok) log.warn(`editor exited: ${result.reason ?? "unknown"}`);
|
|
3048
3253
|
}
|
|
3049
3254
|
var DEFAULT_PATHS = {
|
|
3050
3255
|
markdown: "act-contracts.md",
|
|
3051
3256
|
"json-schema": "act-contracts.schema.json"
|
|
3052
3257
|
};
|
|
3053
|
-
async function
|
|
3054
|
-
const format = await
|
|
3258
|
+
async function export_registry(idx, root_dir) {
|
|
3259
|
+
const format = await select({
|
|
3055
3260
|
message: `Export as ${NAV_LEGEND}`,
|
|
3056
3261
|
options: [
|
|
3057
3262
|
{
|
|
@@ -3066,85 +3271,85 @@ async function exportRegistry(idx, rootDir) {
|
|
|
3066
3271
|
}
|
|
3067
3272
|
]
|
|
3068
3273
|
});
|
|
3069
|
-
if (
|
|
3070
|
-
|
|
3071
|
-
const path = await
|
|
3072
|
-
message: `Save to (relative to ${dim(
|
|
3274
|
+
if (isCancel(format)) return;
|
|
3275
|
+
vim_keys?.pause();
|
|
3276
|
+
const path = await text({
|
|
3277
|
+
message: `Save to (relative to ${dim(root_dir)}) ${dim("(esc to cancel)")}`,
|
|
3073
3278
|
placeholder: DEFAULT_PATHS[format],
|
|
3074
3279
|
initialValue: DEFAULT_PATHS[format]
|
|
3075
3280
|
});
|
|
3076
|
-
|
|
3077
|
-
if (
|
|
3078
|
-
const content = format === "markdown" ?
|
|
3079
|
-
const abs = resolve3(
|
|
3281
|
+
vim_keys?.resume();
|
|
3282
|
+
if (isCancel(path) || !path || !path.trim()) return;
|
|
3283
|
+
const content = format === "markdown" ? format_markdown(idx) : format_json_schema(idx);
|
|
3284
|
+
const abs = resolve3(root_dir, path.trim());
|
|
3080
3285
|
try {
|
|
3081
3286
|
await writeFile(abs, `${content}
|
|
3082
3287
|
`, "utf8");
|
|
3083
|
-
|
|
3288
|
+
log.success(`wrote ${abs}`);
|
|
3084
3289
|
} catch (err) {
|
|
3085
|
-
|
|
3290
|
+
log.error(
|
|
3086
3291
|
/* c8 ignore next — the `String(err)` arm fires only on non-Error
|
|
3087
3292
|
throws, which Node fs.writeFile doesn't produce. */
|
|
3088
3293
|
`could not write ${abs}: ${err instanceof Error ? err.message : String(err)}`
|
|
3089
3294
|
);
|
|
3090
3295
|
}
|
|
3091
3296
|
}
|
|
3092
|
-
async function
|
|
3093
|
-
|
|
3094
|
-
const
|
|
3297
|
+
async function search_by_name(idx, root_dir) {
|
|
3298
|
+
vim_keys?.pause();
|
|
3299
|
+
const q = await text({
|
|
3095
3300
|
message: `Partial name to search ${dim("(esc to cancel)")}`,
|
|
3096
3301
|
placeholder: "e.g. order, ticket, place"
|
|
3097
3302
|
});
|
|
3098
|
-
|
|
3099
|
-
if (q
|
|
3100
|
-
const lower =
|
|
3303
|
+
vim_keys?.resume();
|
|
3304
|
+
if (isCancel(q) || !q || !q.trim()) return;
|
|
3305
|
+
const lower = q.trim().toLowerCase();
|
|
3101
3306
|
const kind = CATEGORY_KEYWORDS[lower];
|
|
3102
3307
|
if (kind) {
|
|
3103
|
-
await
|
|
3308
|
+
await pick_from_list(
|
|
3104
3309
|
idx,
|
|
3105
|
-
|
|
3310
|
+
root_dir,
|
|
3106
3311
|
`${KIND_LABELS[kind]}`,
|
|
3107
|
-
|
|
3312
|
+
list_by_kind(idx, kind)
|
|
3108
3313
|
);
|
|
3109
3314
|
return;
|
|
3110
3315
|
}
|
|
3111
|
-
const matches2 = search(idx,
|
|
3316
|
+
const matches2 = search(idx, q.trim(), 200);
|
|
3112
3317
|
if (matches2.length === 0) {
|
|
3113
|
-
|
|
3318
|
+
log.warn(`no matches for "${q}"`);
|
|
3114
3319
|
return;
|
|
3115
3320
|
}
|
|
3116
|
-
await
|
|
3321
|
+
await pick_from_list(idx, root_dir, `matches for "${q}"`, matches2);
|
|
3117
3322
|
}
|
|
3118
|
-
async function
|
|
3119
|
-
|
|
3120
|
-
const unsub =
|
|
3121
|
-
|
|
3323
|
+
async function run_interactive(idx, root_dir) {
|
|
3324
|
+
vim_keys = enableVimKeys(process.stdin);
|
|
3325
|
+
const unsub = vim_keys.on_slash(() => {
|
|
3326
|
+
search_requested = true;
|
|
3122
3327
|
});
|
|
3123
3328
|
try {
|
|
3124
|
-
await
|
|
3329
|
+
await drive_interactive(idx, root_dir);
|
|
3125
3330
|
} finally {
|
|
3126
3331
|
unsub();
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3332
|
+
vim_keys.restore();
|
|
3333
|
+
vim_keys = null;
|
|
3334
|
+
search_requested = false;
|
|
3130
3335
|
}
|
|
3131
3336
|
}
|
|
3132
|
-
async function
|
|
3133
|
-
|
|
3134
|
-
|
|
3337
|
+
async function drive_interactive(idx, root_dir) {
|
|
3338
|
+
intro("act \u2014 contracts explorer");
|
|
3339
|
+
log.message(format_summary(idx));
|
|
3135
3340
|
while (true) {
|
|
3136
|
-
if (
|
|
3137
|
-
|
|
3138
|
-
await
|
|
3341
|
+
if (search_requested) {
|
|
3342
|
+
search_requested = false;
|
|
3343
|
+
await search_by_name(idx, root_dir);
|
|
3139
3344
|
continue;
|
|
3140
3345
|
}
|
|
3141
|
-
const choice = await
|
|
3346
|
+
const choice = await select({
|
|
3142
3347
|
message: `What do you want to inspect? ${NAV_LEGEND}`,
|
|
3143
3348
|
options: [
|
|
3144
|
-
...KIND_ORDER.map((
|
|
3145
|
-
value:
|
|
3146
|
-
label:
|
|
3147
|
-
hint: `${
|
|
3349
|
+
...KIND_ORDER.map((k) => ({
|
|
3350
|
+
value: k,
|
|
3351
|
+
label: kind_color[k](KIND_LABELS[k]),
|
|
3352
|
+
hint: `${count_by_kind(idx, k)}`
|
|
3148
3353
|
})),
|
|
3149
3354
|
{
|
|
3150
3355
|
value: "export",
|
|
@@ -3154,48 +3359,48 @@ async function driveInteractive(idx, rootDir) {
|
|
|
3154
3359
|
],
|
|
3155
3360
|
maxItems: 10
|
|
3156
3361
|
});
|
|
3157
|
-
if (
|
|
3158
|
-
if (
|
|
3159
|
-
|
|
3362
|
+
if (isCancel(choice)) {
|
|
3363
|
+
if (search_requested) continue;
|
|
3364
|
+
outro("bye.");
|
|
3160
3365
|
return;
|
|
3161
3366
|
}
|
|
3162
3367
|
if (choice === "export") {
|
|
3163
|
-
await
|
|
3368
|
+
await export_registry(idx, root_dir);
|
|
3164
3369
|
continue;
|
|
3165
3370
|
}
|
|
3166
|
-
await
|
|
3371
|
+
await pick_from_list(
|
|
3167
3372
|
idx,
|
|
3168
|
-
|
|
3373
|
+
root_dir,
|
|
3169
3374
|
`${KIND_LABELS[choice]}`,
|
|
3170
|
-
|
|
3375
|
+
list_by_kind(idx, choice)
|
|
3171
3376
|
);
|
|
3172
3377
|
}
|
|
3173
3378
|
}
|
|
3174
3379
|
|
|
3175
3380
|
// src/cli/index.ts
|
|
3176
|
-
function
|
|
3381
|
+
function parse_args(argv) {
|
|
3177
3382
|
let cwd;
|
|
3178
3383
|
let help = false;
|
|
3179
3384
|
let version = false;
|
|
3180
|
-
let
|
|
3385
|
+
let max_files;
|
|
3181
3386
|
let query;
|
|
3182
3387
|
let markdown = false;
|
|
3183
|
-
let
|
|
3184
|
-
for (let
|
|
3185
|
-
const
|
|
3186
|
-
if (
|
|
3187
|
-
else if (
|
|
3188
|
-
else if (
|
|
3189
|
-
else if (
|
|
3190
|
-
else if (
|
|
3191
|
-
else if (
|
|
3192
|
-
|
|
3193
|
-
else if (
|
|
3194
|
-
const
|
|
3195
|
-
if (Number.isFinite(
|
|
3196
|
-
} else if (!
|
|
3197
|
-
}
|
|
3198
|
-
return { cwd, help, version,
|
|
3388
|
+
let json_schema = false;
|
|
3389
|
+
for (let i2 = 0; i2 < argv.length; i2++) {
|
|
3390
|
+
const a2 = argv[i2];
|
|
3391
|
+
if (a2 === "-h" || a2 === "--help") help = true;
|
|
3392
|
+
else if (a2 === "-v" || a2 === "--version") version = true;
|
|
3393
|
+
else if (a2 === "--cwd") cwd = argv[++i2] ?? cwd;
|
|
3394
|
+
else if (a2 === "-q" || a2 === "--query") query = argv[++i2] ?? query;
|
|
3395
|
+
else if (a2 === "-m" || a2 === "--markdown" || a2 === "--md") markdown = true;
|
|
3396
|
+
else if (a2 === "-j" || a2 === "--json-schema" || a2 === "--json")
|
|
3397
|
+
json_schema = true;
|
|
3398
|
+
else if (a2 === "--max-files") {
|
|
3399
|
+
const n2 = Number.parseInt(argv[++i2] ?? "", 10);
|
|
3400
|
+
if (Number.isFinite(n2) && n2 > 0) max_files = n2;
|
|
3401
|
+
} else if (!a2.startsWith("-")) cwd = a2;
|
|
3402
|
+
}
|
|
3403
|
+
return { cwd, help, version, max_files, query, markdown, json_schema };
|
|
3199
3404
|
}
|
|
3200
3405
|
var USAGE = [
|
|
3201
3406
|
"Usage: act [dir] [-q <name>] [-m | -j] [--cwd <dir>] [--max-files <n>] [--help] [--version]",
|
|
@@ -3216,76 +3421,76 @@ var USAGE = [
|
|
|
3216
3421
|
"file path you choose."
|
|
3217
3422
|
].join("\n");
|
|
3218
3423
|
async function main(deps) {
|
|
3219
|
-
const args =
|
|
3424
|
+
const args = parse_args(deps.argv);
|
|
3220
3425
|
if (args.help) {
|
|
3221
3426
|
deps.output.write(USAGE + "\n");
|
|
3222
3427
|
return 0;
|
|
3223
3428
|
}
|
|
3224
3429
|
if (args.version) {
|
|
3225
|
-
deps.output.write(deps.
|
|
3430
|
+
deps.output.write(deps.version_string + "\n");
|
|
3226
3431
|
return 0;
|
|
3227
3432
|
}
|
|
3228
|
-
const
|
|
3229
|
-
const { files, truncated } = await
|
|
3230
|
-
|
|
3433
|
+
const root_dir = resolve4(args.cwd ?? deps.default_dir ?? ".");
|
|
3434
|
+
const { files, truncated } = await load_project(root_dir, {
|
|
3435
|
+
max_files: args.max_files
|
|
3231
3436
|
});
|
|
3232
3437
|
if (files.length === 0) {
|
|
3233
|
-
deps.
|
|
3234
|
-
`act: no TypeScript source files found under ${
|
|
3438
|
+
deps.error_output.write(
|
|
3439
|
+
`act: no TypeScript source files found under ${root_dir}
|
|
3235
3440
|
`
|
|
3236
3441
|
);
|
|
3237
3442
|
return 1;
|
|
3238
3443
|
}
|
|
3239
3444
|
if (truncated) {
|
|
3240
|
-
deps.
|
|
3445
|
+
deps.error_output.write(
|
|
3241
3446
|
"act: scan was truncated (file cap reached); some sources may be missing.\n"
|
|
3242
3447
|
);
|
|
3243
3448
|
}
|
|
3244
|
-
const { model, error } =
|
|
3449
|
+
const { model, error } = extract_model(files);
|
|
3245
3450
|
if (error) {
|
|
3246
|
-
deps.
|
|
3451
|
+
deps.error_output.write(`act: parse error \u2014 ${error}
|
|
3247
3452
|
`);
|
|
3248
3453
|
}
|
|
3249
|
-
const idx =
|
|
3454
|
+
const idx = build_contract_index(model);
|
|
3250
3455
|
if (args.markdown) {
|
|
3251
|
-
deps.output.write(`${
|
|
3456
|
+
deps.output.write(`${format_markdown(idx)}
|
|
3252
3457
|
`);
|
|
3253
3458
|
return 0;
|
|
3254
3459
|
}
|
|
3255
|
-
if (args.
|
|
3256
|
-
deps.output.write(`${
|
|
3460
|
+
if (args.json_schema) {
|
|
3461
|
+
deps.output.write(`${format_json_schema(idx)}
|
|
3257
3462
|
`);
|
|
3258
3463
|
return 0;
|
|
3259
3464
|
}
|
|
3260
3465
|
if (args.query) {
|
|
3261
3466
|
const matches2 = search(idx, args.query);
|
|
3262
3467
|
if (matches2.length === 0) {
|
|
3263
|
-
deps.
|
|
3468
|
+
deps.error_output.write(`act: no matches for "${args.query}"
|
|
3264
3469
|
`);
|
|
3265
3470
|
return 1;
|
|
3266
3471
|
}
|
|
3267
3472
|
const exact = matches2.filter(
|
|
3268
|
-
(
|
|
3473
|
+
(m) => m.name.toLowerCase() === args.query.toLowerCase()
|
|
3269
3474
|
);
|
|
3270
|
-
const
|
|
3271
|
-
const
|
|
3272
|
-
new Map(exact.map((
|
|
3475
|
+
const equiv_key = (m) => `${m.kind}\0${m.name}\0${m.qualifier ?? ""}`;
|
|
3476
|
+
const uniq_exact = Array.from(
|
|
3477
|
+
new Map(exact.map((m) => [equiv_key(m), m])).values()
|
|
3273
3478
|
);
|
|
3274
|
-
if (
|
|
3275
|
-
deps.output.write(
|
|
3479
|
+
if (uniq_exact.length === 1) {
|
|
3480
|
+
deps.output.write(format_detail(idx, uniq_exact[0]) + "\n");
|
|
3276
3481
|
return 0;
|
|
3277
3482
|
}
|
|
3278
|
-
const
|
|
3279
|
-
new Map(matches2.map((
|
|
3483
|
+
const uniq_matches = Array.from(
|
|
3484
|
+
new Map(matches2.map((m) => [equiv_key(m), m])).values()
|
|
3280
3485
|
);
|
|
3281
|
-
if (
|
|
3282
|
-
deps.output.write(
|
|
3486
|
+
if (uniq_matches.length === 1) {
|
|
3487
|
+
deps.output.write(format_detail(idx, uniq_matches[0]) + "\n");
|
|
3283
3488
|
return 0;
|
|
3284
3489
|
}
|
|
3285
|
-
deps.output.write(
|
|
3490
|
+
deps.output.write(format_matches(args.query, uniq_matches) + "\n");
|
|
3286
3491
|
return 0;
|
|
3287
3492
|
}
|
|
3288
|
-
await (deps.
|
|
3493
|
+
await (deps.run_interactive ?? run_interactive)(idx, root_dir);
|
|
3289
3494
|
return 0;
|
|
3290
3495
|
}
|
|
3291
3496
|
var isMain = (() => {
|
|
@@ -3301,11 +3506,11 @@ if (isMain) {
|
|
|
3301
3506
|
main({
|
|
3302
3507
|
input: process.stdin,
|
|
3303
3508
|
output: process.stdout,
|
|
3304
|
-
|
|
3509
|
+
error_output: process.stderr,
|
|
3305
3510
|
isTTY: !!process.stdout.isTTY,
|
|
3306
3511
|
argv: process.argv.slice(2),
|
|
3307
|
-
|
|
3308
|
-
|
|
3512
|
+
version_string: "act (act-diagram)",
|
|
3513
|
+
default_dir: process.env.INIT_CWD ?? process.cwd()
|
|
3309
3514
|
}).then(
|
|
3310
3515
|
(code) => process.exit(code),
|
|
3311
3516
|
(err) => {
|
|
@@ -3319,6 +3524,6 @@ if (isMain) {
|
|
|
3319
3524
|
}
|
|
3320
3525
|
export {
|
|
3321
3526
|
main,
|
|
3322
|
-
|
|
3527
|
+
parse_args
|
|
3323
3528
|
};
|
|
3324
3529
|
//# sourceMappingURL=act.js.map
|