@niscorp/cli 0.9.0 → 0.9.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/CHANGELOG.md +10 -0
- package/README.md +59 -0
- package/dist/shape.cjs +201 -0
- package/dist/shape.cjs.map +1 -0
- package/dist/shape.d.cts +22 -0
- package/dist/shape.d.ts +22 -0
- package/dist/shape.js +199 -0
- package/dist/shape.js.map +1 -0
- package/package.json +13 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @niscorp/cli
|
|
2
2
|
|
|
3
|
+
## 0.9.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a7b2a05: A shape check, `runShapeCheck` from the new entry `@niscorp/cli/shape`: it reads an app's source and its actions for what its own checks cannot see — rule 16 by the TypeScript compiler, formatting outside Prism, roles read in server code, the kit reading files, the address or the document, code in `src/app` called while the app runs — and fails on every server function an action calls that the app has not named with why it is not a vex read or write. What an app allows, it names per rule and per file, each with its reason. It reads with the app's own TypeScript (6.x) and adds no dependency.
|
|
8
|
+
|
|
9
|
+
`create-nisc` writes it into every app as `src/dev/shape-check.ts`, run by `npm run check`. The rulebook's "Verification" and `REVIEW.md` say what it does.
|
|
10
|
+
|
|
11
|
+
**What to change:** nothing; an app that does not call it is not checked. To check an app made before this, copy `src/dev/shape-check.ts` from a new one, add it to `src/dev/all-checks.ts`, and name what it reports.
|
|
12
|
+
|
|
3
13
|
## 0.9.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -347,6 +347,65 @@ server. An app with its own shell is a vite app and nothing more.
|
|
|
347
347
|
The app's check suite (`src/dev/all-checks.ts`, or `checks` in the config), run
|
|
348
348
|
with the app's own `tsx`. Its exit code is the suite's.
|
|
349
349
|
|
|
350
|
+
## The shape check — `@niscorp/cli/shape`
|
|
351
|
+
|
|
352
|
+
An app's own checks test what it does. The shape check reads how it does it:
|
|
353
|
+
its source and its actions, for what nisc's rulebook (`AGENTS.md` in
|
|
354
|
+
`@niscorp/nisc`) says an app is made of. An app runs it from its suite, as
|
|
355
|
+
`src/dev/shape-check.ts`; `npm create nisc` writes that file. An app that does
|
|
356
|
+
not call it is not checked.
|
|
357
|
+
|
|
358
|
+
```ts
|
|
359
|
+
import { fileURLToPath } from 'node:url';
|
|
360
|
+
import { runShapeCheck } from '@niscorp/cli/shape';
|
|
361
|
+
import { actions } from '../app/action-catalog';
|
|
362
|
+
import { ENTRIES } from '../app/vex';
|
|
363
|
+
|
|
364
|
+
process.exit(
|
|
365
|
+
runShapeCheck({
|
|
366
|
+
root: fileURLToPath(new URL('../..', import.meta.url)),
|
|
367
|
+
actions: Object.values(actions),
|
|
368
|
+
entries: ENTRIES,
|
|
369
|
+
functions: { ask: 'the model composes the answer to a message' },
|
|
370
|
+
allow: { formatting: { 'src/server/today.ts': 'the studio’s day, put in every read’s scope' } },
|
|
371
|
+
}),
|
|
372
|
+
);
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
It prints one `[pass]` or `[fail]` line per rule and answers the exit code, 0
|
|
376
|
+
or 1. It fails when:
|
|
377
|
+
|
|
378
|
+
| Rule | It fails on |
|
|
379
|
+
|---|---|
|
|
380
|
+
| `style` (rule 16) | in `src/`: an `as` or `<T>` assertion other than `as const`, a non-null `!`, a `function` declaration, a class, an enum, `any`, a default export. `.d.ts` files are not read |
|
|
381
|
+
| `formatting` (rule 9) | `Intl.` or a `.toLocale…()` call in `src/`, but `src/dev/` |
|
|
382
|
+
| `roles` (rule 11) | `session.roles` or `principal.roles` in `src/server/` |
|
|
383
|
+
| `files` (rule 9a) | `FileReader` or a `readAs…` call in `src/ui/` |
|
|
384
|
+
| `address` (rule 4) | `location.…`, `history.pushState` or `history.replaceState` in `src/ui/` |
|
|
385
|
+
| `dom` (rule 2) | `document.querySelector` and its kin in `src/ui/` |
|
|
386
|
+
| `data` | a file in `src/` outside `src/app/` and `src/dev/` imports a function from `src/app/` — resolved by the app's `tsconfig.json`, so a path alias counts. A function that answers the manifest (`NiscApp`) is setup, and passes |
|
|
387
|
+
|
|
388
|
+
Each is read off the syntax tree, so a word in a comment or a string is never a
|
|
389
|
+
finding.
|
|
390
|
+
|
|
391
|
+
`allow` names, per rule, the files that may do what the rule refuses, each with
|
|
392
|
+
why: the file that finds the app's day, the identity seam that reads roles, a
|
|
393
|
+
routing adapter, a shim. An allowance fails when it gives no reason, names a
|
|
394
|
+
file that is not there, or allows nothing in that file.
|
|
395
|
+
|
|
396
|
+
`functions` names every server function an action calls (an endpoint with
|
|
397
|
+
`fn`), each with what it does that a vex read or write replayed by the action
|
|
398
|
+
cannot: mail, a model, files, what lives in the person's shell. A function an
|
|
399
|
+
action calls that is not named fails, and so does a name no action calls.
|
|
400
|
+
|
|
401
|
+
It also prints, failing on nothing, how often the actions call functions
|
|
402
|
+
against how often they replay vex, how many reads word their rows with a Prism
|
|
403
|
+
`mapping`, and the `refresh: 'reactive'` reads no action replays by name.
|
|
404
|
+
|
|
405
|
+
It reads the source with the app's own TypeScript, 6.x, found from `root`, and
|
|
406
|
+
the app as its `tsconfig.json` there says. On lyceum it takes under three
|
|
407
|
+
seconds.
|
|
408
|
+
|
|
350
409
|
## `nisc migrate`
|
|
351
410
|
|
|
352
411
|
For an app behind moss whose config hands over `app` and `runtime`. It is the
|
package/dist/shape.cjs
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var module$1 = require('module');
|
|
6
|
+
|
|
7
|
+
// src/shape/index.ts
|
|
8
|
+
var SOURCE = /\.(ts|tsx|mts|cts)$/;
|
|
9
|
+
var pathOf = (root, file) => path.relative(root, file).split(path.sep).join("/");
|
|
10
|
+
var sourceFilesOf = (root, dir = path.join(root, "src")) => {
|
|
11
|
+
let entries;
|
|
12
|
+
try {
|
|
13
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
14
|
+
} catch {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
return entries.flatMap((entry) => {
|
|
18
|
+
if (entry.name === "node_modules") return [];
|
|
19
|
+
const path$1 = path.join(dir, entry.name);
|
|
20
|
+
if (entry.isDirectory()) return sourceFilesOf(root, path$1);
|
|
21
|
+
return SOURCE.test(entry.name) && !entry.name.endsWith(".d.ts") ? [path$1] : [];
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
var READ_FILE = /* @__PURE__ */ new Set(["readAsDataURL", "readAsText", "readAsArrayBuffer", "readAsBinaryString"]);
|
|
25
|
+
var FIND_ELEMENTS = /* @__PURE__ */ new Set(["querySelector", "querySelectorAll", "getElementById", "getElementsByClassName", "getElementsByTagName", "getElementsByName"]);
|
|
26
|
+
var ADDRESS_CHANGE = /* @__PURE__ */ new Set(["pushState", "replaceState"]);
|
|
27
|
+
var lastName = (ts, node) => {
|
|
28
|
+
if (ts.isIdentifier(node)) return node.text;
|
|
29
|
+
if (ts.isPropertyAccessExpression(node)) return node.name.text;
|
|
30
|
+
return void 0;
|
|
31
|
+
};
|
|
32
|
+
var hasModifier = (ts, node, kind) => ts.canHaveModifiers(node) && (ts.getModifiers(node) ?? []).some((modifier) => modifier.kind === kind);
|
|
33
|
+
var findingsIn = (ts, file, source) => {
|
|
34
|
+
const found = [];
|
|
35
|
+
const inSrc = (folder) => file.startsWith(`src/${folder}/`);
|
|
36
|
+
const at = (rule, node, what) => {
|
|
37
|
+
found.push({ rule, file, line: source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1, what });
|
|
38
|
+
};
|
|
39
|
+
const visit = (node) => {
|
|
40
|
+
if (ts.isAsExpression(node) && !(ts.isTypeReferenceNode(node.type) && ts.isIdentifier(node.type.typeName) && node.type.typeName.text === "const")) at("style", node, `"as ${node.type.getText(source)}"`);
|
|
41
|
+
if (ts.isTypeAssertionExpression(node)) at("style", node, 'a "<T>" assertion');
|
|
42
|
+
if (ts.isNonNullExpression(node)) at("style", node, 'a non-null "!"');
|
|
43
|
+
if (ts.isFunctionDeclaration(node) && !hasModifier(ts, node, ts.SyntaxKind.DeclareKeyword)) at("style", node, "a function declaration");
|
|
44
|
+
if (ts.isClassDeclaration(node) || ts.isClassExpression(node)) at("style", node, "a class");
|
|
45
|
+
if (ts.isEnumDeclaration(node)) at("style", node, "an enum");
|
|
46
|
+
if (node.kind === ts.SyntaxKind.AnyKeyword) at("style", node, '"any"');
|
|
47
|
+
if (ts.isExportAssignment(node) && node.isExportEquals !== true || ts.isExportSpecifier(node) && node.name.text === "default" || hasModifier(ts, node, ts.SyntaxKind.DefaultKeyword)) at("style", node, "a default export");
|
|
48
|
+
if (!inSrc("dev")) {
|
|
49
|
+
if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "Intl") at("formatting", node, `Intl.${node.name.text}`);
|
|
50
|
+
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text.startsWith("toLocale")) at("formatting", node, `.${node.expression.name.text}()`);
|
|
51
|
+
}
|
|
52
|
+
if (inSrc("server") && ts.isPropertyAccessExpression(node) && node.name.text === "roles") {
|
|
53
|
+
const whose = lastName(ts, node.expression);
|
|
54
|
+
if (whose === "session" || whose === "principal") at("roles", node, `${whose}.roles`);
|
|
55
|
+
}
|
|
56
|
+
if (inSrc("ui")) {
|
|
57
|
+
if (ts.isIdentifier(node) && node.text === "FileReader" && !ts.isTypeReferenceNode(node.parent)) at("files", node, "FileReader");
|
|
58
|
+
if (ts.isPropertyAccessExpression(node) && READ_FILE.has(node.name.text)) at("files", node, node.name.text);
|
|
59
|
+
if (ts.isPropertyAccessExpression(node) && lastName(ts, node.expression) === "location") at("address", node, `location.${node.name.text}`);
|
|
60
|
+
if (ts.isPropertyAccessExpression(node) && lastName(ts, node.expression) === "history" && ADDRESS_CHANGE.has(node.name.text)) at("address", node, `history.${node.name.text}`);
|
|
61
|
+
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && FIND_ELEMENTS.has(node.expression.name.text) && lastName(ts, node.expression.expression) === "document") {
|
|
62
|
+
at("dom", node, `document.${node.expression.name.text}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
ts.forEachChild(node, visit);
|
|
66
|
+
};
|
|
67
|
+
visit(source);
|
|
68
|
+
return found;
|
|
69
|
+
};
|
|
70
|
+
var sourceFindings = (ts, root) => sourceFilesOf(root).flatMap((path) => {
|
|
71
|
+
const file = pathOf(root, path);
|
|
72
|
+
const source = ts.createSourceFile(file, fs.readFileSync(path, "utf8"), ts.ScriptTarget.Latest, true, path.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
73
|
+
return findingsIn(ts, file, source);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// src/shape/app-data.ts
|
|
77
|
+
var MANIFEST = /^(Promise<)?NiscApp>?$/;
|
|
78
|
+
var programOf = (ts, root) => {
|
|
79
|
+
const config = ts.findConfigFile(root, ts.sys.fileExists, "tsconfig.json");
|
|
80
|
+
if (config === void 0 || !path.resolve(config).startsWith(path.resolve(root))) throw new Error(`the shape check reads the app as its tsconfig.json says, and ${root} has none.`);
|
|
81
|
+
const parsed = ts.getParsedCommandLineOfConfigFile(config, {}, { ...ts.sys, onUnRecoverableConfigFileDiagnostic: () => void 0 });
|
|
82
|
+
if (parsed === void 0) throw new Error(`${config} could not be read.`);
|
|
83
|
+
return ts.createProgram({ rootNames: parsed.fileNames, options: parsed.options });
|
|
84
|
+
};
|
|
85
|
+
var importedNames = (ts, clause) => {
|
|
86
|
+
if (clause === void 0 || clause.isTypeOnly) return [];
|
|
87
|
+
const bindings = clause.namedBindings;
|
|
88
|
+
const named = bindings !== void 0 && ts.isNamedImports(bindings) ? bindings.elements.filter((element) => !element.isTypeOnly).map((element) => element.name) : [];
|
|
89
|
+
return [...clause.name === void 0 ? [] : [clause.name], ...named];
|
|
90
|
+
};
|
|
91
|
+
var appDataFindings = (ts, root) => {
|
|
92
|
+
const program = programOf(ts, root);
|
|
93
|
+
const checker = program.getTypeChecker();
|
|
94
|
+
const options = program.getCompilerOptions();
|
|
95
|
+
return program.getSourceFiles().flatMap((source) => {
|
|
96
|
+
const file = pathOf(root, path.resolve(source.fileName));
|
|
97
|
+
if (!file.startsWith("src/") || file.startsWith("src/app/") || file.startsWith("src/dev/") || source.isDeclarationFile) return [];
|
|
98
|
+
return source.statements.flatMap((statement) => {
|
|
99
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) return [];
|
|
100
|
+
const target = ts.resolveModuleName(statement.moduleSpecifier.text, source.fileName, options, ts.sys).resolvedModule?.resolvedFileName;
|
|
101
|
+
if (target === void 0) return [];
|
|
102
|
+
const from = pathOf(root, path.resolve(target));
|
|
103
|
+
if (!from.startsWith("src/app/")) return [];
|
|
104
|
+
return importedNames(ts, statement.importClause).flatMap((name) => {
|
|
105
|
+
const calls = checker.getTypeAtLocation(name).getCallSignatures();
|
|
106
|
+
if (calls.length === 0 || calls.every((call) => MANIFEST.test(checker.typeToString(call.getReturnType())))) return [];
|
|
107
|
+
const line = source.getLineAndCharacterOfPosition(name.getStart(source)).line + 1;
|
|
108
|
+
return [{ rule: "data", file, line, what: `${name.text}, a function of ${from}` }];
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
var isTypeScript = (value) => value !== null && typeof value === "object" && typeof Reflect.get(value, "createProgram") === "function" && typeof Reflect.get(value, "version") === "string";
|
|
114
|
+
var loadTypeScript = (root) => {
|
|
115
|
+
const require2 = module$1.createRequire(path.join(root, "package.json"));
|
|
116
|
+
let library;
|
|
117
|
+
try {
|
|
118
|
+
library = require2("typescript");
|
|
119
|
+
} catch {
|
|
120
|
+
throw new Error(`the shape check reads the source with TypeScript, and this app has none installed (looked from ${root}). pnpm add -D typescript`);
|
|
121
|
+
}
|
|
122
|
+
if (!isTypeScript(library)) throw new Error('the "typescript" this app has installed is not the TypeScript compiler.');
|
|
123
|
+
if (!library.version.startsWith("6.")) throw new Error(`the shape check is written against TypeScript 6, and this app has ${library.version}.`);
|
|
124
|
+
return library;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// src/shape/index.ts
|
|
128
|
+
var RULES = [
|
|
129
|
+
["style", 'rule 16: no assertion but "as const", no non-null "!", no function declaration, class, enum, "any" or default export in src/'],
|
|
130
|
+
["formatting", "rule 9: no Intl and no toLocale\u2026 outside Prism (src/, but src/dev/)"],
|
|
131
|
+
["roles", "rule 11: no server code reads the caller\u2019s roles (src/server/)"],
|
|
132
|
+
["files", "rule 9a: the kit reads no file into data (src/ui/)"],
|
|
133
|
+
["address", "rule 4: the kit neither reads nor changes the address (src/ui/)"],
|
|
134
|
+
["dom", "rule 2: no component finds elements in the document (src/ui/)"],
|
|
135
|
+
["data", "src/app is data: no code outside it calls a function of it, but the manifest\u2019s factory"]
|
|
136
|
+
];
|
|
137
|
+
var isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
138
|
+
var endpointsOf = (actions) => actions.flatMap((action) => Object.values(action.endpoints ?? {}).flatMap((endpoint) => isRecord(endpoint) ? [{ action: action.id, endpoint }] : []));
|
|
139
|
+
var replayOf = (endpoint) => {
|
|
140
|
+
const request = endpoint["request"];
|
|
141
|
+
if (!isRecord(request) || !("fingerprint" in request)) return void 0;
|
|
142
|
+
const fingerprint = request["fingerprint"];
|
|
143
|
+
return typeof fingerprint === "string" ? { fingerprint } : {};
|
|
144
|
+
};
|
|
145
|
+
var runShapeCheck = (config) => {
|
|
146
|
+
const log = config.log ?? ((line) => console.log(line));
|
|
147
|
+
let failures = 0;
|
|
148
|
+
const check = (what, passed, detail = []) => {
|
|
149
|
+
log(`${passed ? "[pass]" : "[fail]"} ${what}${passed || detail.length === 0 ? "" : ` \u2014 ${detail.join("; ")}`}`);
|
|
150
|
+
if (!passed) failures += 1;
|
|
151
|
+
};
|
|
152
|
+
const done = () => {
|
|
153
|
+
log(failures === 0 ? "[pass] shape: all checks passed" : `[fail] shape: ${failures} check(s) failed`);
|
|
154
|
+
return failures === 0 ? 0 : 1;
|
|
155
|
+
};
|
|
156
|
+
let findings;
|
|
157
|
+
try {
|
|
158
|
+
const ts = loadTypeScript(config.root);
|
|
159
|
+
findings = [...sourceFindings(ts, config.root), ...appDataFindings(ts, config.root)];
|
|
160
|
+
} catch (error) {
|
|
161
|
+
check("the source is read", false, [error instanceof Error ? error.message : String(error)]);
|
|
162
|
+
return done();
|
|
163
|
+
}
|
|
164
|
+
const allow = config.allow ?? {};
|
|
165
|
+
for (const [rule, what] of RULES) {
|
|
166
|
+
const allowed = allow[rule] ?? {};
|
|
167
|
+
const left = findings.filter((finding) => finding.rule === rule && allowed[finding.file] === void 0);
|
|
168
|
+
check(what, left.length === 0, left.map((finding) => `${finding.file}:${finding.line} ${finding.what}`));
|
|
169
|
+
}
|
|
170
|
+
const idle = RULES.flatMap(
|
|
171
|
+
([rule]) => Object.entries(allow[rule] ?? {}).flatMap(([file, reason]) => {
|
|
172
|
+
if (reason.trim() === "") return [`${rule}: ${file} gives no reason`];
|
|
173
|
+
if (!fs.existsSync(path.join(config.root, file))) return [`${rule}: ${file} does not exist`];
|
|
174
|
+
return findings.some((finding) => finding.rule === rule && finding.file === file) ? [] : [`${rule}: ${file} has nothing to allow`];
|
|
175
|
+
})
|
|
176
|
+
);
|
|
177
|
+
check("every allowance names a file there is, why, and something it allows", idle.length === 0, idle);
|
|
178
|
+
const endpoints = endpointsOf(config.actions);
|
|
179
|
+
const ledger = config.functions ?? {};
|
|
180
|
+
const called = new Set(endpoints.flatMap(({ endpoint }) => typeof endpoint["fn"] === "string" ? [endpoint["fn"]] : []));
|
|
181
|
+
const unexplained = [...called].filter((id) => (ledger[id] ?? "").trim() === "").sort();
|
|
182
|
+
check("every server function an action calls is named in `functions`, with what it does that a vex read or write cannot", unexplained.length === 0, unexplained);
|
|
183
|
+
const uncalled = Object.keys(ledger).filter((id) => !called.has(id)).sort();
|
|
184
|
+
check("every function named in `functions` is called by an action", uncalled.length === 0, uncalled);
|
|
185
|
+
const replays = endpoints.flatMap(({ endpoint }) => {
|
|
186
|
+
const replay = replayOf(endpoint);
|
|
187
|
+
return replay === void 0 ? [] : [replay];
|
|
188
|
+
});
|
|
189
|
+
const named = new Set(replays.flatMap((replay) => replay.fingerprint === void 0 ? [] : [replay.fingerprint]));
|
|
190
|
+
const reads = (config.entries ?? []).filter((entry) => entry.dsl !== void 0);
|
|
191
|
+
const calls = endpoints.filter(({ endpoint }) => typeof endpoint["fn"] === "string").length;
|
|
192
|
+
log(`[info] actions call server functions ${calls} times and replay vex ${replays.length} times`);
|
|
193
|
+
log(`[info] ${reads.filter((entry) => entry.mapping !== void 0).length} of ${reads.length} reads word their rows with a Prism mapping`);
|
|
194
|
+
const unnamed = reads.filter((entry) => entry.refresh === "reactive" && !named.has(entry.fingerprint)).map((entry) => entry.fingerprint);
|
|
195
|
+
if (unnamed.length > 0) log(`[info] reactive reads no action replays by name: ${unnamed.join(", ")}`);
|
|
196
|
+
return done();
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
exports.runShapeCheck = runShapeCheck;
|
|
200
|
+
//# sourceMappingURL=shape.cjs.map
|
|
201
|
+
//# sourceMappingURL=shape.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/shape/source.ts","../src/shape/app-data.ts","../src/shape/typescript.ts","../src/shape/index.ts"],"names":["relative","sep","join","readdirSync","path","readFileSync","resolve","require","createRequire","existsSync"],"mappings":";;;;;;;AASA,IAAM,MAAA,GAAS,qBAAA;AAER,IAAM,MAAA,GAAS,CAAC,IAAA,EAAc,IAAA,KAAyBA,aAAA,CAAS,IAAA,EAAM,IAAI,CAAA,CAAE,KAAA,CAAMC,QAAG,CAAA,CAAE,IAAA,CAAK,GAAG,CAAA;AAE/F,IAAM,gBAAgB,CAAC,IAAA,EAAc,MAAMC,SAA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AAA,IAAc,CAAC,MAAM,GAAA,CAAI,KAAA,CAAM,WAAW,CAAC,CAAA,CAAE,IAAI,CAAC,KAAA,KAAU,MAAM,WAAW,CAAA;AACvI,EAAA,IAAI,OAAA,CAAQ,SAAS,CAAA,EAAG,GAAA,CAAI,oDAAoD,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAC,CAAA,CAAE,CAAA;AACpG,EAAA,OAAO,IAAA,EAAK;AACd","file":"shape.cjs","sourcesContent":["import { readdirSync, readFileSync } from 'node:fs';\nimport { join, relative, sep } from 'node:path';\nimport type * as TS from 'typescript';\nimport type { TypeScript } from './typescript';\n\nexport type SourceRule = 'style' | 'formatting' | 'roles' | 'files' | 'address' | 'dom';\n\nexport type Finding = { rule: SourceRule | 'data'; file: string; line: number; what: string };\n\nconst SOURCE = /\\.(ts|tsx|mts|cts)$/;\n\nexport const pathOf = (root: string, file: string): string => relative(root, file).split(sep).join('/');\n\nexport const sourceFilesOf = (root: string, dir = join(root, 'src')): string[] => {\n let entries;\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch {\n return [];\n }\n return entries.flatMap((entry) => {\n if (entry.name === 'node_modules') return [];\n const path = join(dir, entry.name);\n if (entry.isDirectory()) return sourceFilesOf(root, path);\n return SOURCE.test(entry.name) && !entry.name.endsWith('.d.ts') ? [path] : [];\n });\n};\n\nconst READ_FILE = new Set(['readAsDataURL', 'readAsText', 'readAsArrayBuffer', 'readAsBinaryString']);\nconst FIND_ELEMENTS = new Set(['querySelector', 'querySelectorAll', 'getElementById', 'getElementsByClassName', 'getElementsByTagName', 'getElementsByName']);\nconst ADDRESS_CHANGE = new Set(['pushState', 'replaceState']);\n\nconst lastName = (ts: TypeScript, node: TS.Expression): string | undefined => {\n if (ts.isIdentifier(node)) return node.text;\n if (ts.isPropertyAccessExpression(node)) return node.name.text;\n return undefined;\n};\n\nconst hasModifier = (ts: TypeScript, node: TS.Node, kind: TS.SyntaxKind): boolean => ts.canHaveModifiers(node) && (ts.getModifiers(node) ?? []).some((modifier) => modifier.kind === kind);\n\n// Each rule reads the syntax tree, so a word in a comment or a string is never a finding.\nconst findingsIn = (ts: TypeScript, file: string, source: TS.SourceFile): Finding[] => {\n const found: Finding[] = [];\n const inSrc = (folder: string): boolean => file.startsWith(`src/${folder}/`);\n const at = (rule: SourceRule, node: TS.Node, what: string): void => {\n found.push({ rule, file, line: source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1, what });\n };\n const visit = (node: TS.Node): void => {\n if (ts.isAsExpression(node) && !(ts.isTypeReferenceNode(node.type) && ts.isIdentifier(node.type.typeName) && node.type.typeName.text === 'const')) at('style', node, `\"as ${node.type.getText(source)}\"`);\n if (ts.isTypeAssertionExpression(node)) at('style', node, 'a \"<T>\" assertion');\n if (ts.isNonNullExpression(node)) at('style', node, 'a non-null \"!\"');\n if (ts.isFunctionDeclaration(node) && !hasModifier(ts, node, ts.SyntaxKind.DeclareKeyword)) at('style', node, 'a function declaration');\n if (ts.isClassDeclaration(node) || ts.isClassExpression(node)) at('style', node, 'a class');\n if (ts.isEnumDeclaration(node)) at('style', node, 'an enum');\n if (node.kind === ts.SyntaxKind.AnyKeyword) at('style', node, '\"any\"');\n if ((ts.isExportAssignment(node) && node.isExportEquals !== true) || (ts.isExportSpecifier(node) && node.name.text === 'default') || hasModifier(ts, node, ts.SyntaxKind.DefaultKeyword)) at('style', node, 'a default export');\n\n if (!inSrc('dev')) {\n if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'Intl') at('formatting', node, `Intl.${node.name.text}`);\n if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text.startsWith('toLocale')) at('formatting', node, `.${node.expression.name.text}()`);\n }\n if (inSrc('server') && ts.isPropertyAccessExpression(node) && node.name.text === 'roles') {\n const whose = lastName(ts, node.expression);\n if (whose === 'session' || whose === 'principal') at('roles', node, `${whose}.roles`);\n }\n if (inSrc('ui')) {\n if (ts.isIdentifier(node) && node.text === 'FileReader' && !ts.isTypeReferenceNode(node.parent)) at('files', node, 'FileReader');\n if (ts.isPropertyAccessExpression(node) && READ_FILE.has(node.name.text)) at('files', node, node.name.text);\n if (ts.isPropertyAccessExpression(node) && lastName(ts, node.expression) === 'location') at('address', node, `location.${node.name.text}`);\n if (ts.isPropertyAccessExpression(node) && lastName(ts, node.expression) === 'history' && ADDRESS_CHANGE.has(node.name.text)) at('address', node, `history.${node.name.text}`);\n if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && FIND_ELEMENTS.has(node.expression.name.text) && lastName(ts, node.expression.expression) === 'document') {\n at('dom', node, `document.${node.expression.name.text}`);\n }\n }\n ts.forEachChild(node, visit);\n };\n visit(source);\n return found;\n};\n\nexport const sourceFindings = (ts: TypeScript, root: string): Finding[] =>\n sourceFilesOf(root).flatMap((path) => {\n const file = pathOf(root, path);\n const source = ts.createSourceFile(file, readFileSync(path, 'utf8'), ts.ScriptTarget.Latest, true, path.endsWith('.tsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TS);\n return findingsIn(ts, file, source);\n });\n","import { resolve } from 'node:path';\nimport type * as TS from 'typescript';\nimport { pathOf } from './source';\nimport type { Finding } from './source';\nimport type { TypeScript } from './typescript';\n\n// The manifest's factory takes the server's code seams and answers the manifest: setup, not code in the artifact tree.\nconst MANIFEST = /^(Promise<)?NiscApp>?$/;\n\nconst programOf = (ts: TypeScript, root: string): TS.Program => {\n const config = ts.findConfigFile(root, ts.sys.fileExists, 'tsconfig.json');\n if (config === undefined || !resolve(config).startsWith(resolve(root))) throw new Error(`the shape check reads the app as its tsconfig.json says, and ${root} has none.`);\n const parsed = ts.getParsedCommandLineOfConfigFile(config, {}, { ...ts.sys, onUnRecoverableConfigFileDiagnostic: () => undefined });\n if (parsed === undefined) throw new Error(`${config} could not be read.`);\n return ts.createProgram({ rootNames: parsed.fileNames, options: parsed.options });\n};\n\nconst importedNames = (ts: TypeScript, clause: TS.ImportClause | undefined): TS.Identifier[] => {\n if (clause === undefined || clause.isTypeOnly) return [];\n const bindings = clause.namedBindings;\n const named = bindings !== undefined && ts.isNamedImports(bindings) ? bindings.elements.filter((element) => !element.isTypeOnly).map((element) => element.name) : [];\n return [...(clause.name === undefined ? [] : [clause.name]), ...named];\n};\n\n// What code outside src/app calls of it, read by the compiler under the app's own tsconfig, so a path alias counts.\nexport const appDataFindings = (ts: TypeScript, root: string): Finding[] => {\n const program = programOf(ts, root);\n const checker = program.getTypeChecker();\n const options = program.getCompilerOptions();\n return program.getSourceFiles().flatMap((source) => {\n const file = pathOf(root, resolve(source.fileName));\n if (!file.startsWith('src/') || file.startsWith('src/app/') || file.startsWith('src/dev/') || source.isDeclarationFile) return [];\n return source.statements.flatMap((statement) => {\n if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) return [];\n const target = ts.resolveModuleName(statement.moduleSpecifier.text, source.fileName, options, ts.sys).resolvedModule?.resolvedFileName;\n if (target === undefined) return [];\n const from = pathOf(root, resolve(target));\n if (!from.startsWith('src/app/')) return [];\n return importedNames(ts, statement.importClause).flatMap((name) => {\n const calls = checker.getTypeAtLocation(name).getCallSignatures();\n if (calls.length === 0 || calls.every((call) => MANIFEST.test(checker.typeToString(call.getReturnType())))) return [];\n const line = source.getLineAndCharacterOfPosition(name.getStart(source)).line + 1;\n return [{ rule: 'data' as const, file, line, what: `${name.text}, a function of ${from}` }];\n });\n });\n });\n};\n","import { createRequire } from 'node:module';\nimport { join } from 'node:path';\nimport type * as TS from 'typescript';\n\nexport type TypeScript = typeof TS;\n\nconst isTypeScript = (value: unknown): value is TypeScript =>\n value !== null && typeof value === 'object' && typeof Reflect.get(value, 'createProgram') === 'function' && typeof Reflect.get(value, 'version') === 'string';\n\n// The app's own compiler, as `nisc build` uses the app's own jsdom: the gate adds no dependency to the cli.\nexport const loadTypeScript = (root: string): TypeScript => {\n const require = createRequire(join(root, 'package.json'));\n let library: unknown;\n try {\n library = require('typescript');\n } catch {\n throw new Error(`the shape check reads the source with TypeScript, and this app has none installed (looked from ${root}). pnpm add -D typescript`);\n }\n if (!isTypeScript(library)) throw new Error('the \"typescript\" this app has installed is not the TypeScript compiler.');\n if (!library.version.startsWith('6.')) throw new Error(`the shape check is written against TypeScript 6, and this app has ${library.version}.`);\n return library;\n};\n","import { existsSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { appDataFindings } from './app-data';\nimport { sourceFindings } from './source';\nimport type { Finding } from './source';\nimport { loadTypeScript } from './typescript';\n\nexport type ShapeRule = 'style' | 'formatting' | 'roles' | 'files' | 'address' | 'dom' | 'data';\n\nexport type ShapeAction = { id: string; endpoints?: Readonly<Record<string, unknown>> };\n\nexport type ShapeEntry = { fingerprint: string; refresh?: string; dsl?: unknown; mapping?: unknown };\n\nexport type ShapeCheckConfig = {\n root: string;\n actions: readonly ShapeAction[];\n entries?: readonly ShapeEntry[];\n functions?: Readonly<Record<string, string>>;\n allow?: Readonly<Partial<Record<ShapeRule, Readonly<Record<string, string>>>>>;\n log?: (line: string) => void;\n};\n\nconst RULES: readonly (readonly [rule: ShapeRule, what: string])[] = [\n ['style', 'rule 16: no assertion but \"as const\", no non-null \"!\", no function declaration, class, enum, \"any\" or default export in src/'],\n ['formatting', 'rule 9: no Intl and no toLocale… outside Prism (src/, but src/dev/)'],\n ['roles', 'rule 11: no server code reads the caller’s roles (src/server/)'],\n ['files', 'rule 9a: the kit reads no file into data (src/ui/)'],\n ['address', 'rule 4: the kit neither reads nor changes the address (src/ui/)'],\n ['dom', 'rule 2: no component finds elements in the document (src/ui/)'],\n ['data', 'src/app is data: no code outside it calls a function of it, but the manifest’s factory'],\n];\n\nconst isRecord = (value: unknown): value is Record<string, unknown> => value !== null && typeof value === 'object' && !Array.isArray(value);\n\nconst endpointsOf = (actions: readonly ShapeAction[]): { action: string; endpoint: Record<string, unknown> }[] =>\n actions.flatMap((action) => Object.values(action.endpoints ?? {}).flatMap((endpoint) => (isRecord(endpoint) ? [{ action: action.id, endpoint }] : [])));\n\nconst replayOf = (endpoint: Record<string, unknown>): { fingerprint?: string } | undefined => {\n const request = endpoint['request'];\n if (!isRecord(request) || !('fingerprint' in request)) return undefined;\n const fingerprint = request['fingerprint'];\n return typeof fingerprint === 'string' ? { fingerprint } : {};\n};\n\nexport const runShapeCheck = (config: ShapeCheckConfig): number => {\n const log = config.log ?? ((line: string) => console.log(line));\n let failures = 0;\n const check = (what: string, passed: boolean, detail: readonly string[] = []): void => {\n log(`${passed ? '[pass]' : '[fail]'} ${what}${passed || detail.length === 0 ? '' : ` — ${detail.join('; ')}`}`);\n if (!passed) failures += 1;\n };\n const done = (): number => {\n log(failures === 0 ? '[pass] shape: all checks passed' : `[fail] shape: ${failures} check(s) failed`);\n return failures === 0 ? 0 : 1;\n };\n\n let findings: Finding[];\n try {\n const ts = loadTypeScript(config.root);\n findings = [...sourceFindings(ts, config.root), ...appDataFindings(ts, config.root)];\n } catch (error) {\n check('the source is read', false, [error instanceof Error ? error.message : String(error)]);\n return done();\n }\n\n const allow = config.allow ?? {};\n for (const [rule, what] of RULES) {\n const allowed = allow[rule] ?? {};\n const left = findings.filter((finding) => finding.rule === rule && allowed[finding.file] === undefined);\n check(what, left.length === 0, left.map((finding) => `${finding.file}:${finding.line} ${finding.what}`));\n }\n const idle = RULES.flatMap(([rule]) =>\n Object.entries(allow[rule] ?? {}).flatMap(([file, reason]) => {\n if (reason.trim() === '') return [`${rule}: ${file} gives no reason`];\n if (!existsSync(join(config.root, file))) return [`${rule}: ${file} does not exist`];\n return findings.some((finding) => finding.rule === rule && finding.file === file) ? [] : [`${rule}: ${file} has nothing to allow`];\n }),\n );\n check('every allowance names a file there is, why, and something it allows', idle.length === 0, idle);\n\n const endpoints = endpointsOf(config.actions);\n const ledger = config.functions ?? {};\n const called = new Set(endpoints.flatMap(({ endpoint }) => (typeof endpoint['fn'] === 'string' ? [endpoint['fn']] : [])));\n const unexplained = [...called].filter((id) => (ledger[id] ?? '').trim() === '').sort();\n check('every server function an action calls is named in `functions`, with what it does that a vex read or write cannot', unexplained.length === 0, unexplained);\n const uncalled = Object.keys(ledger).filter((id) => !called.has(id)).sort();\n check('every function named in `functions` is called by an action', uncalled.length === 0, uncalled);\n\n const replays = endpoints.flatMap(({ endpoint }) => {\n const replay = replayOf(endpoint);\n return replay === undefined ? [] : [replay];\n });\n const named = new Set(replays.flatMap((replay) => (replay.fingerprint === undefined ? [] : [replay.fingerprint])));\n const reads = (config.entries ?? []).filter((entry) => entry.dsl !== undefined);\n const calls = endpoints.filter(({ endpoint }) => typeof endpoint['fn'] === 'string').length;\n log(`[info] actions call server functions ${calls} times and replay vex ${replays.length} times`);\n log(`[info] ${reads.filter((entry) => entry.mapping !== undefined).length} of ${reads.length} reads word their rows with a Prism mapping`);\n const unnamed = reads.filter((entry) => entry.refresh === 'reactive' && !named.has(entry.fingerprint)).map((entry) => entry.fingerprint);\n if (unnamed.length > 0) log(`[info] reactive reads no action replays by name: ${unnamed.join(', ')}`);\n return done();\n};\n"]}
|
package/dist/shape.d.cts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
type ShapeRule = 'style' | 'formatting' | 'roles' | 'files' | 'address' | 'dom' | 'data';
|
|
2
|
+
type ShapeAction = {
|
|
3
|
+
id: string;
|
|
4
|
+
endpoints?: Readonly<Record<string, unknown>>;
|
|
5
|
+
};
|
|
6
|
+
type ShapeEntry = {
|
|
7
|
+
fingerprint: string;
|
|
8
|
+
refresh?: string;
|
|
9
|
+
dsl?: unknown;
|
|
10
|
+
mapping?: unknown;
|
|
11
|
+
};
|
|
12
|
+
type ShapeCheckConfig = {
|
|
13
|
+
root: string;
|
|
14
|
+
actions: readonly ShapeAction[];
|
|
15
|
+
entries?: readonly ShapeEntry[];
|
|
16
|
+
functions?: Readonly<Record<string, string>>;
|
|
17
|
+
allow?: Readonly<Partial<Record<ShapeRule, Readonly<Record<string, string>>>>>;
|
|
18
|
+
log?: (line: string) => void;
|
|
19
|
+
};
|
|
20
|
+
declare const runShapeCheck: (config: ShapeCheckConfig) => number;
|
|
21
|
+
|
|
22
|
+
export { type ShapeAction, type ShapeCheckConfig, type ShapeEntry, type ShapeRule, runShapeCheck };
|
package/dist/shape.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
type ShapeRule = 'style' | 'formatting' | 'roles' | 'files' | 'address' | 'dom' | 'data';
|
|
2
|
+
type ShapeAction = {
|
|
3
|
+
id: string;
|
|
4
|
+
endpoints?: Readonly<Record<string, unknown>>;
|
|
5
|
+
};
|
|
6
|
+
type ShapeEntry = {
|
|
7
|
+
fingerprint: string;
|
|
8
|
+
refresh?: string;
|
|
9
|
+
dsl?: unknown;
|
|
10
|
+
mapping?: unknown;
|
|
11
|
+
};
|
|
12
|
+
type ShapeCheckConfig = {
|
|
13
|
+
root: string;
|
|
14
|
+
actions: readonly ShapeAction[];
|
|
15
|
+
entries?: readonly ShapeEntry[];
|
|
16
|
+
functions?: Readonly<Record<string, string>>;
|
|
17
|
+
allow?: Readonly<Partial<Record<ShapeRule, Readonly<Record<string, string>>>>>;
|
|
18
|
+
log?: (line: string) => void;
|
|
19
|
+
};
|
|
20
|
+
declare const runShapeCheck: (config: ShapeCheckConfig) => number;
|
|
21
|
+
|
|
22
|
+
export { type ShapeAction, type ShapeCheckConfig, type ShapeEntry, type ShapeRule, runShapeCheck };
|
package/dist/shape.js
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync } from 'fs';
|
|
2
|
+
import { join, resolve, relative, sep } from 'path';
|
|
3
|
+
import { createRequire } from 'module';
|
|
4
|
+
|
|
5
|
+
// src/shape/index.ts
|
|
6
|
+
var SOURCE = /\.(ts|tsx|mts|cts)$/;
|
|
7
|
+
var pathOf = (root, file) => relative(root, file).split(sep).join("/");
|
|
8
|
+
var sourceFilesOf = (root, dir = join(root, "src")) => {
|
|
9
|
+
let entries;
|
|
10
|
+
try {
|
|
11
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
12
|
+
} catch {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
return entries.flatMap((entry) => {
|
|
16
|
+
if (entry.name === "node_modules") return [];
|
|
17
|
+
const path = join(dir, entry.name);
|
|
18
|
+
if (entry.isDirectory()) return sourceFilesOf(root, path);
|
|
19
|
+
return SOURCE.test(entry.name) && !entry.name.endsWith(".d.ts") ? [path] : [];
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var READ_FILE = /* @__PURE__ */ new Set(["readAsDataURL", "readAsText", "readAsArrayBuffer", "readAsBinaryString"]);
|
|
23
|
+
var FIND_ELEMENTS = /* @__PURE__ */ new Set(["querySelector", "querySelectorAll", "getElementById", "getElementsByClassName", "getElementsByTagName", "getElementsByName"]);
|
|
24
|
+
var ADDRESS_CHANGE = /* @__PURE__ */ new Set(["pushState", "replaceState"]);
|
|
25
|
+
var lastName = (ts, node) => {
|
|
26
|
+
if (ts.isIdentifier(node)) return node.text;
|
|
27
|
+
if (ts.isPropertyAccessExpression(node)) return node.name.text;
|
|
28
|
+
return void 0;
|
|
29
|
+
};
|
|
30
|
+
var hasModifier = (ts, node, kind) => ts.canHaveModifiers(node) && (ts.getModifiers(node) ?? []).some((modifier) => modifier.kind === kind);
|
|
31
|
+
var findingsIn = (ts, file, source) => {
|
|
32
|
+
const found = [];
|
|
33
|
+
const inSrc = (folder) => file.startsWith(`src/${folder}/`);
|
|
34
|
+
const at = (rule, node, what) => {
|
|
35
|
+
found.push({ rule, file, line: source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1, what });
|
|
36
|
+
};
|
|
37
|
+
const visit = (node) => {
|
|
38
|
+
if (ts.isAsExpression(node) && !(ts.isTypeReferenceNode(node.type) && ts.isIdentifier(node.type.typeName) && node.type.typeName.text === "const")) at("style", node, `"as ${node.type.getText(source)}"`);
|
|
39
|
+
if (ts.isTypeAssertionExpression(node)) at("style", node, 'a "<T>" assertion');
|
|
40
|
+
if (ts.isNonNullExpression(node)) at("style", node, 'a non-null "!"');
|
|
41
|
+
if (ts.isFunctionDeclaration(node) && !hasModifier(ts, node, ts.SyntaxKind.DeclareKeyword)) at("style", node, "a function declaration");
|
|
42
|
+
if (ts.isClassDeclaration(node) || ts.isClassExpression(node)) at("style", node, "a class");
|
|
43
|
+
if (ts.isEnumDeclaration(node)) at("style", node, "an enum");
|
|
44
|
+
if (node.kind === ts.SyntaxKind.AnyKeyword) at("style", node, '"any"');
|
|
45
|
+
if (ts.isExportAssignment(node) && node.isExportEquals !== true || ts.isExportSpecifier(node) && node.name.text === "default" || hasModifier(ts, node, ts.SyntaxKind.DefaultKeyword)) at("style", node, "a default export");
|
|
46
|
+
if (!inSrc("dev")) {
|
|
47
|
+
if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "Intl") at("formatting", node, `Intl.${node.name.text}`);
|
|
48
|
+
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text.startsWith("toLocale")) at("formatting", node, `.${node.expression.name.text}()`);
|
|
49
|
+
}
|
|
50
|
+
if (inSrc("server") && ts.isPropertyAccessExpression(node) && node.name.text === "roles") {
|
|
51
|
+
const whose = lastName(ts, node.expression);
|
|
52
|
+
if (whose === "session" || whose === "principal") at("roles", node, `${whose}.roles`);
|
|
53
|
+
}
|
|
54
|
+
if (inSrc("ui")) {
|
|
55
|
+
if (ts.isIdentifier(node) && node.text === "FileReader" && !ts.isTypeReferenceNode(node.parent)) at("files", node, "FileReader");
|
|
56
|
+
if (ts.isPropertyAccessExpression(node) && READ_FILE.has(node.name.text)) at("files", node, node.name.text);
|
|
57
|
+
if (ts.isPropertyAccessExpression(node) && lastName(ts, node.expression) === "location") at("address", node, `location.${node.name.text}`);
|
|
58
|
+
if (ts.isPropertyAccessExpression(node) && lastName(ts, node.expression) === "history" && ADDRESS_CHANGE.has(node.name.text)) at("address", node, `history.${node.name.text}`);
|
|
59
|
+
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && FIND_ELEMENTS.has(node.expression.name.text) && lastName(ts, node.expression.expression) === "document") {
|
|
60
|
+
at("dom", node, `document.${node.expression.name.text}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
ts.forEachChild(node, visit);
|
|
64
|
+
};
|
|
65
|
+
visit(source);
|
|
66
|
+
return found;
|
|
67
|
+
};
|
|
68
|
+
var sourceFindings = (ts, root) => sourceFilesOf(root).flatMap((path) => {
|
|
69
|
+
const file = pathOf(root, path);
|
|
70
|
+
const source = ts.createSourceFile(file, readFileSync(path, "utf8"), ts.ScriptTarget.Latest, true, path.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
71
|
+
return findingsIn(ts, file, source);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// src/shape/app-data.ts
|
|
75
|
+
var MANIFEST = /^(Promise<)?NiscApp>?$/;
|
|
76
|
+
var programOf = (ts, root) => {
|
|
77
|
+
const config = ts.findConfigFile(root, ts.sys.fileExists, "tsconfig.json");
|
|
78
|
+
if (config === void 0 || !resolve(config).startsWith(resolve(root))) throw new Error(`the shape check reads the app as its tsconfig.json says, and ${root} has none.`);
|
|
79
|
+
const parsed = ts.getParsedCommandLineOfConfigFile(config, {}, { ...ts.sys, onUnRecoverableConfigFileDiagnostic: () => void 0 });
|
|
80
|
+
if (parsed === void 0) throw new Error(`${config} could not be read.`);
|
|
81
|
+
return ts.createProgram({ rootNames: parsed.fileNames, options: parsed.options });
|
|
82
|
+
};
|
|
83
|
+
var importedNames = (ts, clause) => {
|
|
84
|
+
if (clause === void 0 || clause.isTypeOnly) return [];
|
|
85
|
+
const bindings = clause.namedBindings;
|
|
86
|
+
const named = bindings !== void 0 && ts.isNamedImports(bindings) ? bindings.elements.filter((element) => !element.isTypeOnly).map((element) => element.name) : [];
|
|
87
|
+
return [...clause.name === void 0 ? [] : [clause.name], ...named];
|
|
88
|
+
};
|
|
89
|
+
var appDataFindings = (ts, root) => {
|
|
90
|
+
const program = programOf(ts, root);
|
|
91
|
+
const checker = program.getTypeChecker();
|
|
92
|
+
const options = program.getCompilerOptions();
|
|
93
|
+
return program.getSourceFiles().flatMap((source) => {
|
|
94
|
+
const file = pathOf(root, resolve(source.fileName));
|
|
95
|
+
if (!file.startsWith("src/") || file.startsWith("src/app/") || file.startsWith("src/dev/") || source.isDeclarationFile) return [];
|
|
96
|
+
return source.statements.flatMap((statement) => {
|
|
97
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) return [];
|
|
98
|
+
const target = ts.resolveModuleName(statement.moduleSpecifier.text, source.fileName, options, ts.sys).resolvedModule?.resolvedFileName;
|
|
99
|
+
if (target === void 0) return [];
|
|
100
|
+
const from = pathOf(root, resolve(target));
|
|
101
|
+
if (!from.startsWith("src/app/")) return [];
|
|
102
|
+
return importedNames(ts, statement.importClause).flatMap((name) => {
|
|
103
|
+
const calls = checker.getTypeAtLocation(name).getCallSignatures();
|
|
104
|
+
if (calls.length === 0 || calls.every((call) => MANIFEST.test(checker.typeToString(call.getReturnType())))) return [];
|
|
105
|
+
const line = source.getLineAndCharacterOfPosition(name.getStart(source)).line + 1;
|
|
106
|
+
return [{ rule: "data", file, line, what: `${name.text}, a function of ${from}` }];
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
var isTypeScript = (value) => value !== null && typeof value === "object" && typeof Reflect.get(value, "createProgram") === "function" && typeof Reflect.get(value, "version") === "string";
|
|
112
|
+
var loadTypeScript = (root) => {
|
|
113
|
+
const require2 = createRequire(join(root, "package.json"));
|
|
114
|
+
let library;
|
|
115
|
+
try {
|
|
116
|
+
library = require2("typescript");
|
|
117
|
+
} catch {
|
|
118
|
+
throw new Error(`the shape check reads the source with TypeScript, and this app has none installed (looked from ${root}). pnpm add -D typescript`);
|
|
119
|
+
}
|
|
120
|
+
if (!isTypeScript(library)) throw new Error('the "typescript" this app has installed is not the TypeScript compiler.');
|
|
121
|
+
if (!library.version.startsWith("6.")) throw new Error(`the shape check is written against TypeScript 6, and this app has ${library.version}.`);
|
|
122
|
+
return library;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// src/shape/index.ts
|
|
126
|
+
var RULES = [
|
|
127
|
+
["style", 'rule 16: no assertion but "as const", no non-null "!", no function declaration, class, enum, "any" or default export in src/'],
|
|
128
|
+
["formatting", "rule 9: no Intl and no toLocale\u2026 outside Prism (src/, but src/dev/)"],
|
|
129
|
+
["roles", "rule 11: no server code reads the caller\u2019s roles (src/server/)"],
|
|
130
|
+
["files", "rule 9a: the kit reads no file into data (src/ui/)"],
|
|
131
|
+
["address", "rule 4: the kit neither reads nor changes the address (src/ui/)"],
|
|
132
|
+
["dom", "rule 2: no component finds elements in the document (src/ui/)"],
|
|
133
|
+
["data", "src/app is data: no code outside it calls a function of it, but the manifest\u2019s factory"]
|
|
134
|
+
];
|
|
135
|
+
var isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
136
|
+
var endpointsOf = (actions) => actions.flatMap((action) => Object.values(action.endpoints ?? {}).flatMap((endpoint) => isRecord(endpoint) ? [{ action: action.id, endpoint }] : []));
|
|
137
|
+
var replayOf = (endpoint) => {
|
|
138
|
+
const request = endpoint["request"];
|
|
139
|
+
if (!isRecord(request) || !("fingerprint" in request)) return void 0;
|
|
140
|
+
const fingerprint = request["fingerprint"];
|
|
141
|
+
return typeof fingerprint === "string" ? { fingerprint } : {};
|
|
142
|
+
};
|
|
143
|
+
var runShapeCheck = (config) => {
|
|
144
|
+
const log = config.log ?? ((line) => console.log(line));
|
|
145
|
+
let failures = 0;
|
|
146
|
+
const check = (what, passed, detail = []) => {
|
|
147
|
+
log(`${passed ? "[pass]" : "[fail]"} ${what}${passed || detail.length === 0 ? "" : ` \u2014 ${detail.join("; ")}`}`);
|
|
148
|
+
if (!passed) failures += 1;
|
|
149
|
+
};
|
|
150
|
+
const done = () => {
|
|
151
|
+
log(failures === 0 ? "[pass] shape: all checks passed" : `[fail] shape: ${failures} check(s) failed`);
|
|
152
|
+
return failures === 0 ? 0 : 1;
|
|
153
|
+
};
|
|
154
|
+
let findings;
|
|
155
|
+
try {
|
|
156
|
+
const ts = loadTypeScript(config.root);
|
|
157
|
+
findings = [...sourceFindings(ts, config.root), ...appDataFindings(ts, config.root)];
|
|
158
|
+
} catch (error) {
|
|
159
|
+
check("the source is read", false, [error instanceof Error ? error.message : String(error)]);
|
|
160
|
+
return done();
|
|
161
|
+
}
|
|
162
|
+
const allow = config.allow ?? {};
|
|
163
|
+
for (const [rule, what] of RULES) {
|
|
164
|
+
const allowed = allow[rule] ?? {};
|
|
165
|
+
const left = findings.filter((finding) => finding.rule === rule && allowed[finding.file] === void 0);
|
|
166
|
+
check(what, left.length === 0, left.map((finding) => `${finding.file}:${finding.line} ${finding.what}`));
|
|
167
|
+
}
|
|
168
|
+
const idle = RULES.flatMap(
|
|
169
|
+
([rule]) => Object.entries(allow[rule] ?? {}).flatMap(([file, reason]) => {
|
|
170
|
+
if (reason.trim() === "") return [`${rule}: ${file} gives no reason`];
|
|
171
|
+
if (!existsSync(join(config.root, file))) return [`${rule}: ${file} does not exist`];
|
|
172
|
+
return findings.some((finding) => finding.rule === rule && finding.file === file) ? [] : [`${rule}: ${file} has nothing to allow`];
|
|
173
|
+
})
|
|
174
|
+
);
|
|
175
|
+
check("every allowance names a file there is, why, and something it allows", idle.length === 0, idle);
|
|
176
|
+
const endpoints = endpointsOf(config.actions);
|
|
177
|
+
const ledger = config.functions ?? {};
|
|
178
|
+
const called = new Set(endpoints.flatMap(({ endpoint }) => typeof endpoint["fn"] === "string" ? [endpoint["fn"]] : []));
|
|
179
|
+
const unexplained = [...called].filter((id) => (ledger[id] ?? "").trim() === "").sort();
|
|
180
|
+
check("every server function an action calls is named in `functions`, with what it does that a vex read or write cannot", unexplained.length === 0, unexplained);
|
|
181
|
+
const uncalled = Object.keys(ledger).filter((id) => !called.has(id)).sort();
|
|
182
|
+
check("every function named in `functions` is called by an action", uncalled.length === 0, uncalled);
|
|
183
|
+
const replays = endpoints.flatMap(({ endpoint }) => {
|
|
184
|
+
const replay = replayOf(endpoint);
|
|
185
|
+
return replay === void 0 ? [] : [replay];
|
|
186
|
+
});
|
|
187
|
+
const named = new Set(replays.flatMap((replay) => replay.fingerprint === void 0 ? [] : [replay.fingerprint]));
|
|
188
|
+
const reads = (config.entries ?? []).filter((entry) => entry.dsl !== void 0);
|
|
189
|
+
const calls = endpoints.filter(({ endpoint }) => typeof endpoint["fn"] === "string").length;
|
|
190
|
+
log(`[info] actions call server functions ${calls} times and replay vex ${replays.length} times`);
|
|
191
|
+
log(`[info] ${reads.filter((entry) => entry.mapping !== void 0).length} of ${reads.length} reads word their rows with a Prism mapping`);
|
|
192
|
+
const unnamed = reads.filter((entry) => entry.refresh === "reactive" && !named.has(entry.fingerprint)).map((entry) => entry.fingerprint);
|
|
193
|
+
if (unnamed.length > 0) log(`[info] reactive reads no action replays by name: ${unnamed.join(", ")}`);
|
|
194
|
+
return done();
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
export { runShapeCheck };
|
|
198
|
+
//# sourceMappingURL=shape.js.map
|
|
199
|
+
//# sourceMappingURL=shape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/shape/source.ts","../src/shape/app-data.ts","../src/shape/typescript.ts","../src/shape/index.ts"],"names":["require","join"],"mappings":";;;;;AASA,IAAM,MAAA,GAAS,qBAAA;AAER,IAAM,MAAA,GAAS,CAAC,IAAA,EAAc,IAAA,KAAyB,QAAA,CAAS,IAAA,EAAM,IAAI,CAAA,CAAE,KAAA,CAAM,GAAG,CAAA,CAAE,IAAA,CAAK,GAAG,CAAA;AAE/F,IAAM,gBAAgB,CAAC,IAAA,EAAc,MAAM,IAAA,CAAK,IAAA,EAAM,KAAK,CAAA,KAAgB;AAChF,EAAA,IAAI,OAAA;AACJ,EAAA,IAAI;AACF,IAAA,OAAA,GAAU,WAAA,CAAY,GAAA,EAAK,EAAE,aAAA,EAAe,MA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,GAAA,CAAI,oDAAoD,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAC,CAAA,CAAE,CAAA;AACpG,EAAA,OAAO,IAAA,EAAK;AACd","file":"shape.js","sourcesContent":["import { readdirSync, readFileSync } from 'node:fs';\nimport { join, relative, sep } from 'node:path';\nimport type * as TS from 'typescript';\nimport type { TypeScript } from './typescript';\n\nexport type SourceRule = 'style' | 'formatting' | 'roles' | 'files' | 'address' | 'dom';\n\nexport type Finding = { rule: SourceRule | 'data'; file: string; line: number; what: string };\n\nconst SOURCE = /\\.(ts|tsx|mts|cts)$/;\n\nexport const pathOf = (root: string, file: string): string => relative(root, file).split(sep).join('/');\n\nexport const sourceFilesOf = (root: string, dir = join(root, 'src')): string[] => {\n let entries;\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch {\n return [];\n }\n return entries.flatMap((entry) => {\n if (entry.name === 'node_modules') return [];\n const path = join(dir, entry.name);\n if (entry.isDirectory()) return sourceFilesOf(root, path);\n return SOURCE.test(entry.name) && !entry.name.endsWith('.d.ts') ? [path] : [];\n });\n};\n\nconst READ_FILE = new Set(['readAsDataURL', 'readAsText', 'readAsArrayBuffer', 'readAsBinaryString']);\nconst FIND_ELEMENTS = new Set(['querySelector', 'querySelectorAll', 'getElementById', 'getElementsByClassName', 'getElementsByTagName', 'getElementsByName']);\nconst ADDRESS_CHANGE = new Set(['pushState', 'replaceState']);\n\nconst lastName = (ts: TypeScript, node: TS.Expression): string | undefined => {\n if (ts.isIdentifier(node)) return node.text;\n if (ts.isPropertyAccessExpression(node)) return node.name.text;\n return undefined;\n};\n\nconst hasModifier = (ts: TypeScript, node: TS.Node, kind: TS.SyntaxKind): boolean => ts.canHaveModifiers(node) && (ts.getModifiers(node) ?? []).some((modifier) => modifier.kind === kind);\n\n// Each rule reads the syntax tree, so a word in a comment or a string is never a finding.\nconst findingsIn = (ts: TypeScript, file: string, source: TS.SourceFile): Finding[] => {\n const found: Finding[] = [];\n const inSrc = (folder: string): boolean => file.startsWith(`src/${folder}/`);\n const at = (rule: SourceRule, node: TS.Node, what: string): void => {\n found.push({ rule, file, line: source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1, what });\n };\n const visit = (node: TS.Node): void => {\n if (ts.isAsExpression(node) && !(ts.isTypeReferenceNode(node.type) && ts.isIdentifier(node.type.typeName) && node.type.typeName.text === 'const')) at('style', node, `\"as ${node.type.getText(source)}\"`);\n if (ts.isTypeAssertionExpression(node)) at('style', node, 'a \"<T>\" assertion');\n if (ts.isNonNullExpression(node)) at('style', node, 'a non-null \"!\"');\n if (ts.isFunctionDeclaration(node) && !hasModifier(ts, node, ts.SyntaxKind.DeclareKeyword)) at('style', node, 'a function declaration');\n if (ts.isClassDeclaration(node) || ts.isClassExpression(node)) at('style', node, 'a class');\n if (ts.isEnumDeclaration(node)) at('style', node, 'an enum');\n if (node.kind === ts.SyntaxKind.AnyKeyword) at('style', node, '\"any\"');\n if ((ts.isExportAssignment(node) && node.isExportEquals !== true) || (ts.isExportSpecifier(node) && node.name.text === 'default') || hasModifier(ts, node, ts.SyntaxKind.DefaultKeyword)) at('style', node, 'a default export');\n\n if (!inSrc('dev')) {\n if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'Intl') at('formatting', node, `Intl.${node.name.text}`);\n if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text.startsWith('toLocale')) at('formatting', node, `.${node.expression.name.text}()`);\n }\n if (inSrc('server') && ts.isPropertyAccessExpression(node) && node.name.text === 'roles') {\n const whose = lastName(ts, node.expression);\n if (whose === 'session' || whose === 'principal') at('roles', node, `${whose}.roles`);\n }\n if (inSrc('ui')) {\n if (ts.isIdentifier(node) && node.text === 'FileReader' && !ts.isTypeReferenceNode(node.parent)) at('files', node, 'FileReader');\n if (ts.isPropertyAccessExpression(node) && READ_FILE.has(node.name.text)) at('files', node, node.name.text);\n if (ts.isPropertyAccessExpression(node) && lastName(ts, node.expression) === 'location') at('address', node, `location.${node.name.text}`);\n if (ts.isPropertyAccessExpression(node) && lastName(ts, node.expression) === 'history' && ADDRESS_CHANGE.has(node.name.text)) at('address', node, `history.${node.name.text}`);\n if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && FIND_ELEMENTS.has(node.expression.name.text) && lastName(ts, node.expression.expression) === 'document') {\n at('dom', node, `document.${node.expression.name.text}`);\n }\n }\n ts.forEachChild(node, visit);\n };\n visit(source);\n return found;\n};\n\nexport const sourceFindings = (ts: TypeScript, root: string): Finding[] =>\n sourceFilesOf(root).flatMap((path) => {\n const file = pathOf(root, path);\n const source = ts.createSourceFile(file, readFileSync(path, 'utf8'), ts.ScriptTarget.Latest, true, path.endsWith('.tsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TS);\n return findingsIn(ts, file, source);\n });\n","import { resolve } from 'node:path';\nimport type * as TS from 'typescript';\nimport { pathOf } from './source';\nimport type { Finding } from './source';\nimport type { TypeScript } from './typescript';\n\n// The manifest's factory takes the server's code seams and answers the manifest: setup, not code in the artifact tree.\nconst MANIFEST = /^(Promise<)?NiscApp>?$/;\n\nconst programOf = (ts: TypeScript, root: string): TS.Program => {\n const config = ts.findConfigFile(root, ts.sys.fileExists, 'tsconfig.json');\n if (config === undefined || !resolve(config).startsWith(resolve(root))) throw new Error(`the shape check reads the app as its tsconfig.json says, and ${root} has none.`);\n const parsed = ts.getParsedCommandLineOfConfigFile(config, {}, { ...ts.sys, onUnRecoverableConfigFileDiagnostic: () => undefined });\n if (parsed === undefined) throw new Error(`${config} could not be read.`);\n return ts.createProgram({ rootNames: parsed.fileNames, options: parsed.options });\n};\n\nconst importedNames = (ts: TypeScript, clause: TS.ImportClause | undefined): TS.Identifier[] => {\n if (clause === undefined || clause.isTypeOnly) return [];\n const bindings = clause.namedBindings;\n const named = bindings !== undefined && ts.isNamedImports(bindings) ? bindings.elements.filter((element) => !element.isTypeOnly).map((element) => element.name) : [];\n return [...(clause.name === undefined ? [] : [clause.name]), ...named];\n};\n\n// What code outside src/app calls of it, read by the compiler under the app's own tsconfig, so a path alias counts.\nexport const appDataFindings = (ts: TypeScript, root: string): Finding[] => {\n const program = programOf(ts, root);\n const checker = program.getTypeChecker();\n const options = program.getCompilerOptions();\n return program.getSourceFiles().flatMap((source) => {\n const file = pathOf(root, resolve(source.fileName));\n if (!file.startsWith('src/') || file.startsWith('src/app/') || file.startsWith('src/dev/') || source.isDeclarationFile) return [];\n return source.statements.flatMap((statement) => {\n if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) return [];\n const target = ts.resolveModuleName(statement.moduleSpecifier.text, source.fileName, options, ts.sys).resolvedModule?.resolvedFileName;\n if (target === undefined) return [];\n const from = pathOf(root, resolve(target));\n if (!from.startsWith('src/app/')) return [];\n return importedNames(ts, statement.importClause).flatMap((name) => {\n const calls = checker.getTypeAtLocation(name).getCallSignatures();\n if (calls.length === 0 || calls.every((call) => MANIFEST.test(checker.typeToString(call.getReturnType())))) return [];\n const line = source.getLineAndCharacterOfPosition(name.getStart(source)).line + 1;\n return [{ rule: 'data' as const, file, line, what: `${name.text}, a function of ${from}` }];\n });\n });\n });\n};\n","import { createRequire } from 'node:module';\nimport { join } from 'node:path';\nimport type * as TS from 'typescript';\n\nexport type TypeScript = typeof TS;\n\nconst isTypeScript = (value: unknown): value is TypeScript =>\n value !== null && typeof value === 'object' && typeof Reflect.get(value, 'createProgram') === 'function' && typeof Reflect.get(value, 'version') === 'string';\n\n// The app's own compiler, as `nisc build` uses the app's own jsdom: the gate adds no dependency to the cli.\nexport const loadTypeScript = (root: string): TypeScript => {\n const require = createRequire(join(root, 'package.json'));\n let library: unknown;\n try {\n library = require('typescript');\n } catch {\n throw new Error(`the shape check reads the source with TypeScript, and this app has none installed (looked from ${root}). pnpm add -D typescript`);\n }\n if (!isTypeScript(library)) throw new Error('the \"typescript\" this app has installed is not the TypeScript compiler.');\n if (!library.version.startsWith('6.')) throw new Error(`the shape check is written against TypeScript 6, and this app has ${library.version}.`);\n return library;\n};\n","import { existsSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { appDataFindings } from './app-data';\nimport { sourceFindings } from './source';\nimport type { Finding } from './source';\nimport { loadTypeScript } from './typescript';\n\nexport type ShapeRule = 'style' | 'formatting' | 'roles' | 'files' | 'address' | 'dom' | 'data';\n\nexport type ShapeAction = { id: string; endpoints?: Readonly<Record<string, unknown>> };\n\nexport type ShapeEntry = { fingerprint: string; refresh?: string; dsl?: unknown; mapping?: unknown };\n\nexport type ShapeCheckConfig = {\n root: string;\n actions: readonly ShapeAction[];\n entries?: readonly ShapeEntry[];\n functions?: Readonly<Record<string, string>>;\n allow?: Readonly<Partial<Record<ShapeRule, Readonly<Record<string, string>>>>>;\n log?: (line: string) => void;\n};\n\nconst RULES: readonly (readonly [rule: ShapeRule, what: string])[] = [\n ['style', 'rule 16: no assertion but \"as const\", no non-null \"!\", no function declaration, class, enum, \"any\" or default export in src/'],\n ['formatting', 'rule 9: no Intl and no toLocale… outside Prism (src/, but src/dev/)'],\n ['roles', 'rule 11: no server code reads the caller’s roles (src/server/)'],\n ['files', 'rule 9a: the kit reads no file into data (src/ui/)'],\n ['address', 'rule 4: the kit neither reads nor changes the address (src/ui/)'],\n ['dom', 'rule 2: no component finds elements in the document (src/ui/)'],\n ['data', 'src/app is data: no code outside it calls a function of it, but the manifest’s factory'],\n];\n\nconst isRecord = (value: unknown): value is Record<string, unknown> => value !== null && typeof value === 'object' && !Array.isArray(value);\n\nconst endpointsOf = (actions: readonly ShapeAction[]): { action: string; endpoint: Record<string, unknown> }[] =>\n actions.flatMap((action) => Object.values(action.endpoints ?? {}).flatMap((endpoint) => (isRecord(endpoint) ? [{ action: action.id, endpoint }] : [])));\n\nconst replayOf = (endpoint: Record<string, unknown>): { fingerprint?: string } | undefined => {\n const request = endpoint['request'];\n if (!isRecord(request) || !('fingerprint' in request)) return undefined;\n const fingerprint = request['fingerprint'];\n return typeof fingerprint === 'string' ? { fingerprint } : {};\n};\n\nexport const runShapeCheck = (config: ShapeCheckConfig): number => {\n const log = config.log ?? ((line: string) => console.log(line));\n let failures = 0;\n const check = (what: string, passed: boolean, detail: readonly string[] = []): void => {\n log(`${passed ? '[pass]' : '[fail]'} ${what}${passed || detail.length === 0 ? '' : ` — ${detail.join('; ')}`}`);\n if (!passed) failures += 1;\n };\n const done = (): number => {\n log(failures === 0 ? '[pass] shape: all checks passed' : `[fail] shape: ${failures} check(s) failed`);\n return failures === 0 ? 0 : 1;\n };\n\n let findings: Finding[];\n try {\n const ts = loadTypeScript(config.root);\n findings = [...sourceFindings(ts, config.root), ...appDataFindings(ts, config.root)];\n } catch (error) {\n check('the source is read', false, [error instanceof Error ? error.message : String(error)]);\n return done();\n }\n\n const allow = config.allow ?? {};\n for (const [rule, what] of RULES) {\n const allowed = allow[rule] ?? {};\n const left = findings.filter((finding) => finding.rule === rule && allowed[finding.file] === undefined);\n check(what, left.length === 0, left.map((finding) => `${finding.file}:${finding.line} ${finding.what}`));\n }\n const idle = RULES.flatMap(([rule]) =>\n Object.entries(allow[rule] ?? {}).flatMap(([file, reason]) => {\n if (reason.trim() === '') return [`${rule}: ${file} gives no reason`];\n if (!existsSync(join(config.root, file))) return [`${rule}: ${file} does not exist`];\n return findings.some((finding) => finding.rule === rule && finding.file === file) ? [] : [`${rule}: ${file} has nothing to allow`];\n }),\n );\n check('every allowance names a file there is, why, and something it allows', idle.length === 0, idle);\n\n const endpoints = endpointsOf(config.actions);\n const ledger = config.functions ?? {};\n const called = new Set(endpoints.flatMap(({ endpoint }) => (typeof endpoint['fn'] === 'string' ? [endpoint['fn']] : [])));\n const unexplained = [...called].filter((id) => (ledger[id] ?? '').trim() === '').sort();\n check('every server function an action calls is named in `functions`, with what it does that a vex read or write cannot', unexplained.length === 0, unexplained);\n const uncalled = Object.keys(ledger).filter((id) => !called.has(id)).sort();\n check('every function named in `functions` is called by an action', uncalled.length === 0, uncalled);\n\n const replays = endpoints.flatMap(({ endpoint }) => {\n const replay = replayOf(endpoint);\n return replay === undefined ? [] : [replay];\n });\n const named = new Set(replays.flatMap((replay) => (replay.fingerprint === undefined ? [] : [replay.fingerprint])));\n const reads = (config.entries ?? []).filter((entry) => entry.dsl !== undefined);\n const calls = endpoints.filter(({ endpoint }) => typeof endpoint['fn'] === 'string').length;\n log(`[info] actions call server functions ${calls} times and replay vex ${replays.length} times`);\n log(`[info] ${reads.filter((entry) => entry.mapping !== undefined).length} of ${reads.length} reads word their rows with a Prism mapping`);\n const unnamed = reads.filter((entry) => entry.refresh === 'reactive' && !named.has(entry.fingerprint)).map((entry) => entry.fingerprint);\n if (unnamed.length > 0) log(`[info] reactive reads no action replays by name: ${unnamed.join(', ')}`);\n return done();\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@niscorp/cli",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "nisc — the command for a nisc application: dev, build, export, start. One config file says how the app boots and how its pages are drawn; the command does the rest.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -24,6 +24,16 @@
|
|
|
24
24
|
"default": "./dist/index.cjs"
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
|
+
"./shape": {
|
|
28
|
+
"import": {
|
|
29
|
+
"types": "./dist/shape.d.ts",
|
|
30
|
+
"default": "./dist/shape.js"
|
|
31
|
+
},
|
|
32
|
+
"require": {
|
|
33
|
+
"types": "./dist/shape.d.cts",
|
|
34
|
+
"default": "./dist/shape.cjs"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
27
37
|
"./package.json": "./package.json"
|
|
28
38
|
},
|
|
29
39
|
"files": [
|
|
@@ -60,9 +70,9 @@
|
|
|
60
70
|
"typescript": "^6.0.2",
|
|
61
71
|
"vite": "^7.1.12",
|
|
62
72
|
"vitest": "^4.1.2",
|
|
63
|
-
"@niscorp/
|
|
73
|
+
"@niscorp/moss": "^0.9.0",
|
|
64
74
|
"@niscorp/nova": "^0.5.1",
|
|
65
|
-
"@niscorp/
|
|
75
|
+
"@niscorp/vex": "^0.4.3"
|
|
66
76
|
},
|
|
67
77
|
"scripts": {
|
|
68
78
|
"build": "tsup",
|