@antelopejs/dms 0.20.7 → 0.20.8-next.919.g0c68f67
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/bin/control/commands-verify.mjs +8 -49
- package/bin/control/options.mjs +0 -1
- package/bin/control/run-state.mjs +1 -1
- package/bin/control/timing.mjs +1 -16
- package/bin/control/timing.test.mjs +0 -11
- package/bin/control/verify/decode.mjs +4 -144
- package/bin/control/verify/decode.test.mjs +1 -149
- package/bin/control/verify/formal.mjs +22 -218
- package/bin/control/verify/formal.test.mjs +60 -117
- package/bin/control/verify/map.test.mjs +0 -73
- package/bin/control/verify/types.mjs +4 -18
- package/bin/dms-control.mjs +0 -2
- package/dist/implementations/dms/page/controller.d.ts +2 -1
- package/dist/implementations/dms/page/controller.js.map +1 -1
- package/dist/implementations/dms-builder/engine/connection-access-config.js +2 -2
- package/dist/implementations/dms-builder/engine/connection-targets.js.map +1 -1
- package/dist/implementations/dms-builder/engine/database-access.d.ts +1 -1
- package/dist/implementations/dms-builder/engine/database-access.js +2 -2
- package/dist/implementations/dms-builder/engine/database-check-input.d.ts +3 -2
- package/dist/implementations/dms-builder/engine/database-check-input.js.map +1 -1
- package/dist/implementations/dms-builder/engine/database-check.js +2 -2
- package/dist/implementations/dms-builder/engine/database-check.js.map +1 -1
- package/dist/implementations/dms-builder/engine/probe-answer.d.ts +44 -1
- package/dist/implementations/dms-builder/engine/probe-answer.js +2 -5
- package/dist/implementations/dms-builder/engine/probe-answer.js.map +1 -1
- package/dist/mockup/files.d.ts +1 -1
- package/dist/mockup/files.js +2 -2
- package/dist/pages/settings/users/roles.js.map +1 -1
- package/dist/store/internal/frontend/frontend-ready.d.ts +2 -1
- package/dist/store/internal/frontend/frontend-ready.js.map +1 -1
- package/dist/store/operations.js +4 -4
- package/dist/store/operations.js.map +1 -1
- package/dist/utils/upload-constraints.d.ts +1 -1
- package/dist/utils/upload-constraints.js +2 -2
- package/dist/utils/upload-constraints.js.map +1 -1
- package/dist/validation/issue-message.d.ts +1 -1
- package/dist/validation/issue-message.js +3 -3
- package/dist/validation/issue-message.js.map +1 -1
- package/frontend-vue/layers/dms-core/app/utils/formatter.ts +1 -0
- package/frontend-vue/layers/dms-layout/app/build/composables/navigation/useVisitNavBadges.ts +11 -14
- package/frontend-vue/layers/dms-layout/app/build/composables/settings/security/useSecurityFormat.ts +5 -5
- package/frontend-vue/layers/dms-layout/app/build/utils/modules-catalog.ts +7 -2
- package/frontend-vue/layers/dms-layout/app/build/utils/notificationPayload.ts +9 -5
- package/frontend-vue/layers/dms-layout/app/composables/page/useModuleHistory.ts +4 -1
- package/frontend-vue/layers/dms-layout/app/composables/page/useModulesListing.ts +7 -17
- package/frontend-vue/layers/dms-layout/app/custom-pages/modules.vue +5 -1
- package/frontend-vue/layers/dms-ui/app/build/composables/block-preview/useMockupCatalog.ts +4 -1
- package/frontend-vue/layers/dms-ui/app/build/composables/block-preview/useMockupSpec.ts +18 -16
- package/frontend-vue/layers/dms-ui/app/build/composables/block-preview/usePreviewFrame.ts +2 -1
- package/frontend-vue/layers/dms-ui/app/build/composables/containers/drawerSize.ts +4 -4
- package/frontend-vue/layers/dms-ui/app/build/composables/data-types/relationBadges.ts +2 -5
- package/frontend-vue/layers/dms-ui/app/build/composables/form/fieldComponentProps.ts +2 -2
- package/frontend-vue/layers/dms-ui/app/build/composables/layout/sidePanelState.ts +5 -2
- package/frontend-vue/layers/dms-ui/app/build/composables/period/periodQuery.ts +6 -3
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/tableRowActionValues.ts +13 -13
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/utils/writeError.ts +2 -2
- package/frontend-vue/layers/dms-ui/app/build/utils/blockPreview.ts +1 -1
- package/frontend-vue/layers/dms-ui/app/build/utils/blockPreviewMessages.ts +26 -18
- package/frontend-vue/layers/dms-ui/app/build/utils/mockupCatalog.ts +7 -2
- package/frontend-vue/layers/dms-ui/app/build/utils/mockupSpec.ts +2 -1
- package/frontend-vue/layers/dms-ui/app/components/chart/ApexChartHost.vue +2 -0
- package/frontend-vue/layers/dms-ui/app/composables/useExportJob.ts +2 -2
- package/package.json +9 -8
- package/bin/control/verify/behaviour.mjs +0 -183
- package/bin/control/verify/behaviour.test.mjs +0 -472
- package/bin/control/verify/emit.mjs +0 -539
- package/bin/control/verify/judgement.mjs +0 -101
- package/bin/control/verify/verdict.mjs +0 -327
- package/frontend-vue/scripts/probes/capture-frontend-probe.cjs +0 -23
- package/frontend-vue/scripts/probes/frontend-behavior.cjs +0 -606
- package/frontend-vue/scripts/probes/frontend-legacy.cjs +0 -620
- package/frontend-vue/scripts/probes/frontend-probe-controls.cjs +0 -322
- package/frontend-vue/scripts/prove-comment-emit.mjs +0 -171
- package/frontend-vue/scripts/prove-component-registration.mjs +0 -259
|
@@ -1,539 +0,0 @@
|
|
|
1
|
-
import { spawnSync } from "node:child_process";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
import { dirname, extname, join, posix } from "node:path";
|
|
4
|
-
import { PACKAGE_ROOT } from "../launch.mjs";
|
|
5
|
-
|
|
6
|
-
/** @typedef {typeof import("typescript")} TypeScript */
|
|
7
|
-
/** @typedef {import("typescript").Node} Node */
|
|
8
|
-
/** @typedef {{ modules: Set<string>, functions: Set<string> }} Covered The covered modules and function names */
|
|
9
|
-
/** @typedef {{ structure: string, text: string, hoisted: boolean }} Item */
|
|
10
|
-
/** @typedef {{ path: string, file: import("typescript").SourceFile }} Script */
|
|
11
|
-
|
|
12
|
-
const CODE_EXTENSIONS = new Set([
|
|
13
|
-
".ts",
|
|
14
|
-
".mts",
|
|
15
|
-
".cts",
|
|
16
|
-
".tsx",
|
|
17
|
-
".js",
|
|
18
|
-
".mjs",
|
|
19
|
-
".cjs",
|
|
20
|
-
".jsx",
|
|
21
|
-
]);
|
|
22
|
-
const OUTPUT_LIMIT = 64 * 1024 * 1024;
|
|
23
|
-
const TEXT_LENGTH = 160;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @param {string} repo
|
|
27
|
-
* @returns {TypeScript}
|
|
28
|
-
*/
|
|
29
|
-
function loadTypeScript(repo) {
|
|
30
|
-
for (const folder of [repo, join(repo, "packages", "dms"), PACKAGE_ROOT]) {
|
|
31
|
-
try {
|
|
32
|
-
// oxlint-disable-next-line typescript/no-unsafe-return -- createRequire loads TypeScript by a path known only at run time, from the checkout under test first and the dms package last, and Node types what require answers as any.
|
|
33
|
-
return createRequire(join(folder, "package.json"))("typescript");
|
|
34
|
-
} catch {
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
throw new Error(
|
|
39
|
-
"dms-control needs the typescript package in the repository to compare covered code",
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @param {string} repo
|
|
45
|
-
* @param {string} sha
|
|
46
|
-
* @param {string} path
|
|
47
|
-
* @returns {string | null}
|
|
48
|
-
*/
|
|
49
|
-
function fileAt(repo, sha, path) {
|
|
50
|
-
const shown = spawnSync("git", ["show", `${sha}:${path}`], {
|
|
51
|
-
cwd: repo,
|
|
52
|
-
encoding: "utf8",
|
|
53
|
-
maxBuffer: OUTPUT_LIMIT,
|
|
54
|
-
});
|
|
55
|
-
return shown.status === 0 ? shown.stdout : null;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @param {TypeScript} ts
|
|
60
|
-
* @param {Node} node
|
|
61
|
-
* @param {Map<string, string>} bindings
|
|
62
|
-
* @returns {string}
|
|
63
|
-
*/
|
|
64
|
-
function leafOf(ts, node, bindings) {
|
|
65
|
-
if (ts.isIdentifier(node))
|
|
66
|
-
return propertyName(ts, node)
|
|
67
|
-
? node.text
|
|
68
|
-
: (bindings.get(node.text) ?? node.text);
|
|
69
|
-
if (ts.isPrivateIdentifier(node)) return node.text;
|
|
70
|
-
if (ts.isNumericLiteral(node)) return String(Number(node.text));
|
|
71
|
-
if (ts.isStringLiteralLike(node) || ts.isTemplateLiteralToken(node))
|
|
72
|
-
return JSON.stringify(node.text);
|
|
73
|
-
if (ts.isBigIntLiteral(node) || ts.isRegularExpressionLiteral(node))
|
|
74
|
-
return node.text;
|
|
75
|
-
if (ts.isPrefixUnaryExpression(node) || ts.isPostfixUnaryExpression(node))
|
|
76
|
-
return ts.SyntaxKind[node.operator];
|
|
77
|
-
if (ts.isVariableDeclarationList(node))
|
|
78
|
-
return String(node.flags & (ts.NodeFlags.Let | ts.NodeFlags.Const));
|
|
79
|
-
if (ts.isMetaProperty(node)) return ts.SyntaxKind[node.keywordToken];
|
|
80
|
-
return "";
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const MODULE_EXTENSION = /\.(?:[cm]?[jt]s|[jt]sx)$/;
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* The module a specifier names. Only a string literal names a module; any
|
|
87
|
-
* other expression, which only a file that does not parse as a module can
|
|
88
|
-
* hold, is keyed by its structure, so it never reads as the module its text
|
|
89
|
-
* spells.
|
|
90
|
-
*
|
|
91
|
-
* @param {TypeScript} ts
|
|
92
|
-
* @param {string} path The file that holds the specifier
|
|
93
|
-
* @param {import("typescript").Expression} specifier
|
|
94
|
-
* @returns {string}
|
|
95
|
-
*/
|
|
96
|
-
function moduleOf(ts, path, specifier) {
|
|
97
|
-
return ts.isStringLiteral(specifier)
|
|
98
|
-
? moduleKey(path, specifier.text)
|
|
99
|
-
: `expression ${structureOf(ts, specifier, new Map())}`;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* @param {string} path
|
|
104
|
-
* @param {string} specifier The text of the module specifier
|
|
105
|
-
* @returns {string}
|
|
106
|
-
*/
|
|
107
|
-
function moduleKey(path, specifier) {
|
|
108
|
-
if (!specifier.startsWith(".")) return specifier;
|
|
109
|
-
return posix.join(dirname(path), specifier).replace(MODULE_EXTENSION, "");
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* @param {string} path
|
|
114
|
-
* @returns {string}
|
|
115
|
-
*/
|
|
116
|
-
function stripExtension(path) {
|
|
117
|
-
return path.replace(MODULE_EXTENSION, "");
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* @param {TypeScript} ts
|
|
122
|
-
* @param {Node} node
|
|
123
|
-
* @returns {boolean}
|
|
124
|
-
*/
|
|
125
|
-
function propertyName(ts, node) {
|
|
126
|
-
const parent = node.parent;
|
|
127
|
-
return (
|
|
128
|
-
parent !== undefined &&
|
|
129
|
-
parent.name === node &&
|
|
130
|
-
(ts.isPropertyAccessExpression(parent) ||
|
|
131
|
-
ts.isPropertyAssignment(parent) ||
|
|
132
|
-
ts.isMethodDeclaration(parent) ||
|
|
133
|
-
ts.isPropertyDeclaration(parent) ||
|
|
134
|
-
ts.isGetAccessor(parent) ||
|
|
135
|
-
ts.isSetAccessor(parent) ||
|
|
136
|
-
ts.isEnumMember(parent))
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* A binding from a covered module is its name alone when it is a function
|
|
142
|
-
* declaration, which may move between covered files, and `module#name`
|
|
143
|
-
* otherwise, so a variable or class of one file never reads as one of the same
|
|
144
|
-
* name in another.
|
|
145
|
-
*
|
|
146
|
-
* @param {Covered} covered The covered modules and function names
|
|
147
|
-
* @param {string} module The resolved module
|
|
148
|
-
* @param {string} name The imported name
|
|
149
|
-
* @returns {string} The origin
|
|
150
|
-
*/
|
|
151
|
-
function bindingOrigin(covered, module, name) {
|
|
152
|
-
return covered.modules.has(module) && covered.functions.has(name)
|
|
153
|
-
? name
|
|
154
|
-
: `${module}#${name}`;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* @param {TypeScript} ts
|
|
159
|
-
* @param {import("typescript").ImportClause} clause
|
|
160
|
-
* @param {string} module
|
|
161
|
-
* @param {Covered} covered
|
|
162
|
-
* @returns {[string, string][]}
|
|
163
|
-
*/
|
|
164
|
-
function importedBindings(ts, clause, module, covered) {
|
|
165
|
-
const named = clause.namedBindings;
|
|
166
|
-
/** @type {[string, string][]} */
|
|
167
|
-
const bindings = [];
|
|
168
|
-
if (clause.name)
|
|
169
|
-
bindings.push([
|
|
170
|
-
clause.name.text,
|
|
171
|
-
bindingOrigin(covered, module, "default"),
|
|
172
|
-
]);
|
|
173
|
-
if (named && ts.isNamespaceImport(named))
|
|
174
|
-
bindings.push([named.name.text, bindingOrigin(covered, module, "*")]);
|
|
175
|
-
if (named && ts.isNamedImports(named))
|
|
176
|
-
for (const element of named.elements)
|
|
177
|
-
bindings.push([
|
|
178
|
-
element.name.text,
|
|
179
|
-
bindingOrigin(
|
|
180
|
-
covered,
|
|
181
|
-
module,
|
|
182
|
-
(element.propertyName ?? element.name).text,
|
|
183
|
-
),
|
|
184
|
-
]);
|
|
185
|
-
return bindings;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* @param {TypeScript} ts
|
|
190
|
-
* @param {import("typescript").ExportDeclaration} statement
|
|
191
|
-
* @param {string} module
|
|
192
|
-
* @param {Covered} covered
|
|
193
|
-
* @returns {string[]}
|
|
194
|
-
*/
|
|
195
|
-
function reexportTexts(ts, statement, module, covered) {
|
|
196
|
-
const exported = statement.exportClause;
|
|
197
|
-
const inside = covered.modules.has(module);
|
|
198
|
-
if (exported === undefined) return inside ? [] : [`export * from ${module}`];
|
|
199
|
-
if (ts.isNamespaceExport(exported))
|
|
200
|
-
return inside ? [] : [`export * as ${exported.name.text} from ${module}`];
|
|
201
|
-
return exported.elements.flatMap((element) => {
|
|
202
|
-
const origin = bindingOrigin(
|
|
203
|
-
covered,
|
|
204
|
-
module,
|
|
205
|
-
(element.propertyName ?? element.name).text,
|
|
206
|
-
);
|
|
207
|
-
return origin === element.name.text
|
|
208
|
-
? []
|
|
209
|
-
: [`export ${origin} as ${element.name.text}`];
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* The exports of a file that name a local or imported binding, keyed by the
|
|
215
|
-
* origin of what they export. An export under its own name of a local needs no
|
|
216
|
-
* entry, the same as an `export` keyword, so only a renamed local and any
|
|
217
|
-
* imported binding does.
|
|
218
|
-
* @param {TypeScript} ts
|
|
219
|
-
* @param {import("typescript").ExportDeclaration} statement
|
|
220
|
-
* @param {Map<string, string>} bindings
|
|
221
|
-
* @param {Map<string, string>} locals
|
|
222
|
-
* @returns {string[]}
|
|
223
|
-
*/
|
|
224
|
-
function localExportTexts(ts, statement, bindings, locals) {
|
|
225
|
-
const exported = statement.exportClause;
|
|
226
|
-
if (exported === undefined || !ts.isNamedExports(exported)) return [];
|
|
227
|
-
return exported.elements.flatMap((element) => {
|
|
228
|
-
const name = (element.propertyName ?? element.name).text;
|
|
229
|
-
const imported = bindings.get(name);
|
|
230
|
-
const origin = imported ?? locals.get(name) ?? name;
|
|
231
|
-
const own = imported === undefined && name === element.name.text;
|
|
232
|
-
return own || origin === element.name.text
|
|
233
|
-
? []
|
|
234
|
-
: [`export ${origin} as ${element.name.text}`];
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Where each value-imported binding of a file comes from: the resolved
|
|
240
|
-
* module and the imported name, so an alias or a swapped specifier changes
|
|
241
|
-
* what a use refers to. A binding from a covered module is its name alone
|
|
242
|
-
* when it is a function declaration, so moving the declaration between
|
|
243
|
-
* covered files keeps every use the same; any other binding is keyed by its
|
|
244
|
-
* module. Side-effect imports keep their order in the file. Re-exports and
|
|
245
|
-
* renamed or imported exports become entries keyed by the origin they export.
|
|
246
|
-
*
|
|
247
|
-
* @param {TypeScript} ts The TypeScript module
|
|
248
|
-
* @param {string} path The file
|
|
249
|
-
* @param {Covered} covered The covered modules and function names
|
|
250
|
-
* @param {import("typescript").SourceFile} file The emitted source file
|
|
251
|
-
* @param {Map<string, string>} locals The top-level variables and classes of the file, keyed by file and name
|
|
252
|
-
* @returns {{ bindings: Map<string, string>, entries: { structure: string, text: string, hoisted: boolean }[], ordered: { structure: string, text: string, hoisted: boolean }[] }} The origins; `entries` may move freely, `ordered` keep their order in the file
|
|
253
|
-
*/
|
|
254
|
-
function originsOf(ts, path, covered, file, locals) {
|
|
255
|
-
/** @type {Map<string, string>} */
|
|
256
|
-
const bindings = new Map();
|
|
257
|
-
/** @type {string[]} */
|
|
258
|
-
const texts = [];
|
|
259
|
-
/** @type {string[]} */
|
|
260
|
-
const ordered = [];
|
|
261
|
-
/** @type {import("typescript").ExportDeclaration[]} */
|
|
262
|
-
const exports = [];
|
|
263
|
-
for (const statement of file.statements) {
|
|
264
|
-
if (
|
|
265
|
-
!(ts.isImportDeclaration(statement) || ts.isExportDeclaration(statement))
|
|
266
|
-
)
|
|
267
|
-
continue;
|
|
268
|
-
const specifier = statement.moduleSpecifier;
|
|
269
|
-
if (specifier === undefined && ts.isExportDeclaration(statement))
|
|
270
|
-
exports.push(statement);
|
|
271
|
-
if (specifier === undefined) continue;
|
|
272
|
-
const module = moduleOf(ts, path, specifier);
|
|
273
|
-
if (ts.isImportDeclaration(statement)) {
|
|
274
|
-
if (statement.importClause === undefined) {
|
|
275
|
-
ordered.push(`import ${module}`);
|
|
276
|
-
continue;
|
|
277
|
-
}
|
|
278
|
-
for (const [name, origin] of importedBindings(
|
|
279
|
-
ts,
|
|
280
|
-
statement.importClause,
|
|
281
|
-
module,
|
|
282
|
-
covered,
|
|
283
|
-
))
|
|
284
|
-
bindings.set(name, origin);
|
|
285
|
-
} else texts.push(...reexportTexts(ts, statement, module, covered));
|
|
286
|
-
}
|
|
287
|
-
for (const statement of exports)
|
|
288
|
-
texts.push(...localExportTexts(ts, statement, bindings, locals));
|
|
289
|
-
/**
|
|
290
|
-
* @param {string} text
|
|
291
|
-
* @param {boolean} hoisted
|
|
292
|
-
* @returns {Item}
|
|
293
|
-
*/
|
|
294
|
-
const item = (text, hoisted) => ({ structure: text, text, hoisted });
|
|
295
|
-
return {
|
|
296
|
-
bindings,
|
|
297
|
-
entries: texts.map((text) => item(text, true)),
|
|
298
|
-
ordered: ordered.map((text) => item(text, false)),
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* @param {TypeScript} ts
|
|
304
|
-
* @param {Node} node
|
|
305
|
-
* @returns {boolean}
|
|
306
|
-
*/
|
|
307
|
-
function dropped(ts, node) {
|
|
308
|
-
return (
|
|
309
|
-
node.kind === ts.SyntaxKind.ExportKeyword ||
|
|
310
|
-
node.kind === ts.SyntaxKind.DefaultKeyword
|
|
311
|
-
);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* The structure of a node: its kind, its identifier name or literal value,
|
|
316
|
-
* and its children's structure, with parentheses, positions, trivia, quote
|
|
317
|
-
* style and line breaks left out, so formatting never changes it.
|
|
318
|
-
*
|
|
319
|
-
* @param {TypeScript} ts The TypeScript module
|
|
320
|
-
* @param {Node} node A node of the emitted JavaScript
|
|
321
|
-
* @param {Map<string, string>} bindings The origin of each imported binding
|
|
322
|
-
* @returns {string} The structure
|
|
323
|
-
*/
|
|
324
|
-
function structureOf(ts, node, bindings) {
|
|
325
|
-
if (ts.isParenthesizedExpression(node))
|
|
326
|
-
return structureOf(ts, node.expression, bindings);
|
|
327
|
-
/** @type {string[]} */
|
|
328
|
-
const children = [];
|
|
329
|
-
ts.forEachChild(node, (child) => {
|
|
330
|
-
if (!dropped(ts, child)) children.push(structureOf(ts, child, bindings));
|
|
331
|
-
});
|
|
332
|
-
return `${ts.SyntaxKind[node.kind]}(${leafOf(ts, node, bindings)}|${children.join(",")})`;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* @param {TypeScript} ts
|
|
337
|
-
* @param {string} path
|
|
338
|
-
* @param {string} source
|
|
339
|
-
* @returns {Script}
|
|
340
|
-
*/
|
|
341
|
-
function parseScript(ts, path, source) {
|
|
342
|
-
const { outputText } = ts.transpileModule(source, {
|
|
343
|
-
fileName: path,
|
|
344
|
-
compilerOptions: {
|
|
345
|
-
target: ts.ScriptTarget.ES2022,
|
|
346
|
-
module: ts.ModuleKind.ESNext,
|
|
347
|
-
removeComments: true,
|
|
348
|
-
experimentalDecorators: true,
|
|
349
|
-
},
|
|
350
|
-
});
|
|
351
|
-
return {
|
|
352
|
-
path,
|
|
353
|
-
file: ts.createSourceFile(
|
|
354
|
-
"emit.js",
|
|
355
|
-
outputText,
|
|
356
|
-
ts.ScriptTarget.ES2022,
|
|
357
|
-
true,
|
|
358
|
-
ts.ScriptKind.JS,
|
|
359
|
-
),
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* @param {string} text
|
|
365
|
-
* @returns {string}
|
|
366
|
-
*/
|
|
367
|
-
function readable(text) {
|
|
368
|
-
const flat = text.replace(/\s+/g, " ").trim();
|
|
369
|
-
return flat.length > TEXT_LENGTH ? `${flat.slice(0, TEXT_LENGTH)}…` : flat;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* @param {TypeScript} ts
|
|
374
|
-
* @param {import("typescript").BindingName} name
|
|
375
|
-
* @returns {string[]}
|
|
376
|
-
*/
|
|
377
|
-
function declaredNames(ts, name) {
|
|
378
|
-
return ts.isIdentifier(name)
|
|
379
|
-
? [name.text]
|
|
380
|
-
: name.elements.flatMap((element) =>
|
|
381
|
-
ts.isOmittedExpression(element) ? [] : declaredNames(ts, element.name),
|
|
382
|
-
);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
/**
|
|
386
|
-
* @param {TypeScript} ts
|
|
387
|
-
* @param {import("typescript").Statement} statement
|
|
388
|
-
* @returns {statement is import("typescript").FunctionDeclaration & { name: import("typescript").Identifier }}
|
|
389
|
-
*/
|
|
390
|
-
function isFunctionDeclaration(ts, statement) {
|
|
391
|
-
return (
|
|
392
|
-
ts.isFunctionDeclaration(statement) &&
|
|
393
|
-
Boolean(statement.body) &&
|
|
394
|
-
statement.name !== undefined
|
|
395
|
-
);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* The top-level variables, classes and enums of a script, each keyed by its file and name: what a function moved into another file must not pick up by name.
|
|
400
|
-
* @param {TypeScript} ts
|
|
401
|
-
* @param {Script} script
|
|
402
|
-
* @returns {Map<string, string>}
|
|
403
|
-
*/
|
|
404
|
-
function localsOf(ts, script) {
|
|
405
|
-
const file = stripExtension(script.path);
|
|
406
|
-
const names = script.file.statements.flatMap((statement) => {
|
|
407
|
-
if (ts.isVariableStatement(statement))
|
|
408
|
-
return statement.declarationList.declarations.flatMap((declaration) =>
|
|
409
|
-
declaredNames(ts, declaration.name),
|
|
410
|
-
);
|
|
411
|
-
return (ts.isClassDeclaration(statement) ||
|
|
412
|
-
ts.isEnumDeclaration(statement)) &&
|
|
413
|
-
statement.name
|
|
414
|
-
? [statement.name.text]
|
|
415
|
-
: [];
|
|
416
|
-
});
|
|
417
|
-
return new Map(names.map((name) => [name, `${file}#${name}`]));
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
/**
|
|
421
|
-
* @param {TypeScript} ts
|
|
422
|
-
* @param {Script} script
|
|
423
|
-
* @param {Covered} covered
|
|
424
|
-
* @returns {Item[]}
|
|
425
|
-
*/
|
|
426
|
-
function scriptItems(ts, script, covered) {
|
|
427
|
-
const locals = localsOf(ts, script);
|
|
428
|
-
const origins = originsOf(ts, script.path, covered, script.file, locals);
|
|
429
|
-
const inFunctions = new Map([...locals, ...origins.bindings]);
|
|
430
|
-
const statements = script.file.statements
|
|
431
|
-
.filter(
|
|
432
|
-
(statement) =>
|
|
433
|
-
!ts.isImportDeclaration(statement) &&
|
|
434
|
-
!ts.isExportDeclaration(statement),
|
|
435
|
-
)
|
|
436
|
-
.map((statement) => {
|
|
437
|
-
const hoisted =
|
|
438
|
-
ts.isFunctionDeclaration(statement) && Boolean(statement.body);
|
|
439
|
-
return {
|
|
440
|
-
structure: structureOf(
|
|
441
|
-
ts,
|
|
442
|
-
statement,
|
|
443
|
-
hoisted ? inFunctions : origins.bindings,
|
|
444
|
-
),
|
|
445
|
-
text: readable(statement.getText(script.file)),
|
|
446
|
-
hoisted,
|
|
447
|
-
};
|
|
448
|
-
});
|
|
449
|
-
return [...origins.entries, ...origins.ordered, ...statements];
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
/**
|
|
453
|
-
* A covered file as its scripts and the items that are not scripts: a Vue template, or the whole text of any other file.
|
|
454
|
-
* @param {TypeScript} ts
|
|
455
|
-
* @param {string} path
|
|
456
|
-
* @param {string} source
|
|
457
|
-
*/
|
|
458
|
-
function parsedFile(ts, path, source) {
|
|
459
|
-
if (path.endsWith(".vue")) {
|
|
460
|
-
const template = /<template\b[^>]*>([\s\S]*)<\/template>/.exec(source);
|
|
461
|
-
const markup = template ? template[1].replace(/\s+/g, " ").trim() : null;
|
|
462
|
-
return {
|
|
463
|
-
path,
|
|
464
|
-
scripts: [...source.matchAll(/<script\b[^>]*>([\s\S]*?)<\/script>/g)].map(
|
|
465
|
-
([, body]) => parseScript(ts, `${path}.ts`, body),
|
|
466
|
-
),
|
|
467
|
-
others:
|
|
468
|
-
markup === null
|
|
469
|
-
? []
|
|
470
|
-
: [
|
|
471
|
-
{
|
|
472
|
-
structure: `template(${markup})`,
|
|
473
|
-
text: readable(`<template> ${markup}`),
|
|
474
|
-
hoisted: false,
|
|
475
|
-
},
|
|
476
|
-
],
|
|
477
|
-
};
|
|
478
|
-
}
|
|
479
|
-
if (CODE_EXTENSIONS.has(extname(path)))
|
|
480
|
-
return { path, scripts: [parseScript(ts, path, source)], others: [] };
|
|
481
|
-
const flat = source.replace(/\s+/g, " ").trim();
|
|
482
|
-
return {
|
|
483
|
-
path,
|
|
484
|
-
scripts: [],
|
|
485
|
-
others: [
|
|
486
|
-
{ structure: `file(${flat})`, text: readable(flat), hoisted: false },
|
|
487
|
-
],
|
|
488
|
-
};
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
/**
|
|
492
|
-
* What the covered code does at a commit, as structure rather than text:
|
|
493
|
-
* each covered file's top-level statements and side-effect imports in order,
|
|
494
|
-
* and, apart, the function declarations and exports keyed by origin of every
|
|
495
|
-
* covered file, which hoisting lets move freely. Each use of an imported
|
|
496
|
-
* binding stands for its origin (resolved module and imported name), and a
|
|
497
|
-
* function declaration refers to the top-level variables and classes of its
|
|
498
|
-
* own file by file and name, so retargeting an import, an alias or an export,
|
|
499
|
-
* or moving a function next to a different variable of the same name, changes
|
|
500
|
-
* the fingerprint. Types, comments, formatting and export keywords are left
|
|
501
|
-
* out, so a type-only edit, a reformat, or moving a function declaration to
|
|
502
|
-
* another covered file keeps the same fingerprint, while reordering or moving
|
|
503
|
-
* any other statement changes it.
|
|
504
|
-
*
|
|
505
|
-
* @param {string} repo The checkout
|
|
506
|
-
* @param {string} sha The commit
|
|
507
|
-
* @param {string[]} files The covered files
|
|
508
|
-
* @returns {{ functions: { structure: string, text: string, hoisted: boolean }[], files: Record<string, { structure: string, text: string, hoisted: boolean }[]> }} The fingerprint
|
|
509
|
-
*/
|
|
510
|
-
export function emitFingerprint(repo, sha, files) {
|
|
511
|
-
const ts = loadTypeScript(repo);
|
|
512
|
-
/** @type {{ functions: Item[], files: Record<string, Item[]> }} */
|
|
513
|
-
const fingerprint = { functions: [], files: {} };
|
|
514
|
-
const parsed = files.flatMap((path) => {
|
|
515
|
-
const source = fileAt(repo, sha, path);
|
|
516
|
-
return source === null ? [] : [parsedFile(ts, path, source)];
|
|
517
|
-
});
|
|
518
|
-
const covered = {
|
|
519
|
-
modules: new Set(files.map(stripExtension)),
|
|
520
|
-
functions: new Set(
|
|
521
|
-
parsed.flatMap(({ scripts }) =>
|
|
522
|
-
scripts.flatMap(({ file }) =>
|
|
523
|
-
file.statements
|
|
524
|
-
.filter((statement) => isFunctionDeclaration(ts, statement))
|
|
525
|
-
.map(({ name }) => name.text),
|
|
526
|
-
),
|
|
527
|
-
),
|
|
528
|
-
),
|
|
529
|
-
};
|
|
530
|
-
for (const { path, scripts, others } of parsed) {
|
|
531
|
-
const items = [
|
|
532
|
-
...scripts.flatMap((script) => scriptItems(ts, script, covered)),
|
|
533
|
-
...others,
|
|
534
|
-
];
|
|
535
|
-
fingerprint.functions.push(...items.filter((item) => item.hoisted));
|
|
536
|
-
fingerprint.files[path] = items.filter((item) => !item.hoisted);
|
|
537
|
-
}
|
|
538
|
-
return fingerprint;
|
|
539
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
-
import { decodeRawJudgement } from "./decode.mjs";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @param {import("./skill.mjs").Skill} skill The skill
|
|
6
|
-
* @param {string | undefined} value The kind a judgement names
|
|
7
|
-
* @param {string} label Where the kind was read
|
|
8
|
-
* @returns {string} The kind
|
|
9
|
-
*/
|
|
10
|
-
function doorKind(skill, value, label) {
|
|
11
|
-
if (!Object.hasOwn(skill.config.doors, value)) {
|
|
12
|
-
throw new Error(
|
|
13
|
-
`judgement.json: ${label} is "${value}", not one of ${Object.keys(skill.config.doors).join(", ")}`,
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
return value;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @param {import("./skill.mjs").Skill} skill The skill
|
|
21
|
-
* @param {import("./types.mjs").RawJudgement} raw The judgement file
|
|
22
|
-
* @returns {import("./types.mjs").DoorRow[]} The door rows
|
|
23
|
-
*/
|
|
24
|
-
function parseRows(skill, raw) {
|
|
25
|
-
return (raw.doors?.rows ?? []).map((row, index) => {
|
|
26
|
-
if (!row.kind || !row.location || !row.irreversible || !row.containment) {
|
|
27
|
-
throw new Error(
|
|
28
|
-
`judgement.json: doors.rows[${index}] needs kind, location, irreversible and containment`,
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
...row,
|
|
33
|
-
kind: doorKind(skill, row.kind, `doors.rows[${index}].kind`),
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @param {import("./skill.mjs").Skill} skill The skill
|
|
40
|
-
* @param {import("./types.mjs").RawJudgement} raw The judgement file
|
|
41
|
-
* @returns {import("./types.mjs").FalsePositive[]} The dismissed doors
|
|
42
|
-
*/
|
|
43
|
-
function parseFalsePositives(skill, raw) {
|
|
44
|
-
return (raw.doors?.falsePositives ?? []).map((entry, index) => {
|
|
45
|
-
if (!entry.location || !entry.reason?.trim()) {
|
|
46
|
-
throw new Error(
|
|
47
|
-
`judgement.json: doors.falsePositives[${index}] needs location and reason`,
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
...entry,
|
|
52
|
-
kind: doorKind(skill, entry.kind, `doors.falsePositives[${index}].kind`),
|
|
53
|
-
};
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Parses `evidence/judgement.json`, what only the verifier can judge. A
|
|
59
|
-
* verdict without a One-way doors section is void, and one that does not
|
|
60
|
-
* name its verifier is refused, so both throw.
|
|
61
|
-
*
|
|
62
|
-
* @param {import("./skill.mjs").Skill} skill The skill
|
|
63
|
-
* @param {string} file The judgement file
|
|
64
|
-
* @returns {import("./types.mjs").Judgement} The judgement
|
|
65
|
-
*/
|
|
66
|
-
export function readJudgement(skill, file) {
|
|
67
|
-
if (!existsSync(file)) {
|
|
68
|
-
throw new Error(
|
|
69
|
-
`${file} is missing: write the verifier's judgement before rendering the verdict`,
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
/** @type {unknown} */
|
|
73
|
-
const stored = JSON.parse(readFileSync(file, "utf8"));
|
|
74
|
-
const raw = decodeRawJudgement(stored, file);
|
|
75
|
-
const rows = parseRows(skill, raw);
|
|
76
|
-
const none = raw.doors?.none?.trim() || null;
|
|
77
|
-
if (!none && rows.length === 0) {
|
|
78
|
-
throw new Error(
|
|
79
|
-
"judgement.json: doors needs `none` with a reason or at least one row; a verdict without it is void",
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
const verifier = raw.verifier?.trim();
|
|
83
|
-
if (!verifier) {
|
|
84
|
-
throw new Error(
|
|
85
|
-
"judgement.json: verifier must say who judged this run, for example the verifier thread's URL",
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
return {
|
|
89
|
-
notVerified: raw.notVerified ?? [],
|
|
90
|
-
attention: raw.attention ?? [],
|
|
91
|
-
docs: (raw.docs ?? []).map((entry) => ({
|
|
92
|
-
page: entry.page,
|
|
93
|
-
matches: entry.matches === true,
|
|
94
|
-
note: entry.note ?? "",
|
|
95
|
-
})),
|
|
96
|
-
doorsNone: none,
|
|
97
|
-
doors: rows,
|
|
98
|
-
falsePositives: parseFalsePositives(skill, raw),
|
|
99
|
-
verifier,
|
|
100
|
-
};
|
|
101
|
-
}
|