@volter/twin-standard 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +20 -0
- package/dist/src/check-sources.d.ts +33 -0
- package/dist/src/check-sources.js +128 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +105 -0
- package/dist/src/derive.d.ts +2 -0
- package/dist/src/derive.js +349 -0
- package/dist/src/gate.d.ts +9 -0
- package/dist/src/gate.js +109 -0
- package/dist/src/grade.d.ts +30 -0
- package/dist/src/grade.js +36 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.js +11 -0
- package/dist/src/lanes.d.ts +2 -0
- package/dist/src/lanes.js +33 -0
- package/dist/src/p3-rules.d.ts +8 -0
- package/dist/src/p3-rules.js +43 -0
- package/dist/src/protocol-3.d.ts +5 -0
- package/dist/src/protocol-3.js +721 -0
- package/dist/src/published.d.ts +13 -0
- package/dist/src/published.js +36 -0
- package/dist/src/spec-documents.d.ts +12 -0
- package/dist/src/spec-documents.js +61 -0
- package/dist/src/spec-ir-client.d.ts +20 -0
- package/dist/src/spec-ir-client.js +77 -0
- package/dist/src/spec-ir-commands.d.ts +38 -0
- package/dist/src/spec-ir-commands.js +38 -0
- package/dist/src/spec-ir-discovery.d.ts +11 -0
- package/dist/src/spec-ir-discovery.js +106 -0
- package/dist/src/spec-ir-graphql.d.ts +25 -0
- package/dist/src/spec-ir-graphql.js +46 -0
- package/dist/src/spec-ir-lines.d.ts +19 -0
- package/dist/src/spec-ir-lines.js +76 -0
- package/dist/src/spec-ir-proto.d.ts +80 -0
- package/dist/src/spec-ir-proto.js +339 -0
- package/dist/src/spec-ir.d.ts +104 -0
- package/dist/src/spec-ir.js +691 -0
- package/dist/src/spec-patches.d.ts +8 -0
- package/dist/src/spec-patches.js +24 -0
- package/dist/src/spec.d.ts +5 -0
- package/dist/src/spec.js +7 -0
- package/dist/src/types.d.ts +75 -0
- package/dist/src/types.js +4 -0
- package/dist/src/unit.d.ts +5 -0
- package/dist/src/unit.js +14 -0
- package/package.json +71 -0
- package/src/check-sources.ts +109 -0
- package/src/cli.ts +75 -0
- package/src/derive.ts +316 -0
- package/src/gate.ts +95 -0
- package/src/grade.ts +47 -0
- package/src/index.ts +12 -0
- package/src/lanes.ts +29 -0
- package/src/p3-rules.ts +44 -0
- package/src/protocol-3.ts +617 -0
- package/src/published.ts +37 -0
- package/src/spec-documents.ts +58 -0
- package/src/spec-ir-client.ts +86 -0
- package/src/spec-ir-commands.ts +50 -0
- package/src/spec-ir-discovery.ts +104 -0
- package/src/spec-ir-graphql.ts +64 -0
- package/src/spec-ir-lines.ts +76 -0
- package/src/spec-ir-proto.ts +289 -0
- package/src/spec-ir.ts +689 -0
- package/src/spec-patches.ts +23 -0
- package/src/spec.ts +8 -0
- package/src/types.ts +53 -0
- package/src/unit.ts +15 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// The architecture's mechanical rules for a derived pack's own code (docs/contributing/architecture.md, "What an author
|
|
2
|
+
// writes, and how"), checked by the derive over `src/` (generated files aside). Each was broken by copying: the rules the
|
|
3
|
+
// tools did not check spread from one pack to thirty (the P3 drift pass, 2026-09-30). A line may record why it is the
|
|
4
|
+
// exception, in a `// p3: <reason>` comment on it or on the line before, and the check passes it.
|
|
5
|
+
import { readdirSync, readFileSync, statSync } from 'node:fs';
|
|
6
|
+
import { join, relative } from 'node:path';
|
|
7
|
+
const RULES = [
|
|
8
|
+
// ids come from ctx.mint: never a row count made into an id, a number or a label's nonce
|
|
9
|
+
{ rule: 'an id or number from a row count (use ctx.mint)', test: (l) => /\b(rowsRaw|rows|rowsOf)\([^;]*?\)(\s*\.filter\([^;]*?\))?\.length\s*\+\s*1\b/.test(l) || /\b1\s*\+\s*[\w.]*\b(rowsRaw|rows|rowsOf)\([^;]*?\)(\s*\.filter\([^;]*?\))?\.length\b/.test(l) },
|
|
10
|
+
// the twin's own URL is ctx.publicBase
|
|
11
|
+
{ rule: "the twin's URL from the request (use ctx.publicBase)", test: (l) => /request\.url\)\.origin/.test(l) },
|
|
12
|
+
// signing, digests and randomness are the kernel's (ctx.crypto, world-core's exports)
|
|
13
|
+
{ rule: 'node:crypto in a pack (use ctx.crypto or the kernel\'s digest)', test: (l) => /from ['"](node:)?crypto['"]|require\(['"](node:)?crypto['"]\)/.test(l) },
|
|
14
|
+
// a webhook is the manifest's events; ctx.deliver is for a message that is no declared event (a push notification)
|
|
15
|
+
{ rule: 'ctx.deliver where the manifest\'s events belong (or record why)', test: (l) => /ctx\.deliver\(/.test(l) },
|
|
16
|
+
// an object's bytes are ctx.blobs, never a row's field
|
|
17
|
+
{ rule: "bytes kept in a row (use ctx.blobs)", test: (l) => /ctx\.(write|record)\([^;]*toString\(['"]base64['"]\)/.test(l) || /\b_bytes\s*:/.test(l) },
|
|
18
|
+
// a secret the vendor issues is drawn from ctx.secret, never computed from ids
|
|
19
|
+
{ rule: 'a secret computed from ids (draw it from ctx.secret)', test: (l) => /(\b(const|let)\s+[a-zA-Z]*(secret|Secret|token|Token|password|Password|hmac|Hmac)\b\s*=|[{,]\s*(secret|token|password|hmac|api_key|client_secret|access_token|refresh_token)\s*:(?!\s*(string|number|unknown)\b))[^;,]*\b(digest|uuidFrom|lettersFrom|sha256)\(/.test(l) && !/secret\(|Secret\(|keyValue\(|tokenValue\(|credential\(/.test(l) },
|
|
20
|
+
];
|
|
21
|
+
const files = (dir) => readdirSync(dir).flatMap((n) => {
|
|
22
|
+
const p = join(dir, n);
|
|
23
|
+
if (statSync(p).isDirectory())
|
|
24
|
+
return n === 'generated' || n === 'node_modules' ? [] : files(p);
|
|
25
|
+
return /\.(ts|tsx)$/.test(n) && !n.endsWith('.test.ts') ? [p] : [];
|
|
26
|
+
});
|
|
27
|
+
/** Every line of a unit's `src/` that breaks a rule and does not record why. */
|
|
28
|
+
export function p3RuleHits(unit) {
|
|
29
|
+
const src = join(unit, 'src');
|
|
30
|
+
const out = [];
|
|
31
|
+
for (const f of files(src)) {
|
|
32
|
+
const lines = readFileSync(f, 'utf8').split('\n');
|
|
33
|
+
lines.forEach((text, i) => {
|
|
34
|
+
if (/^\s*(\/\/|\*|\/\*)/.test(text))
|
|
35
|
+
return;
|
|
36
|
+
const excused = /\/\/ p3: \S/.test(text) || /\/\/ p3: \S/.test(lines[i - 1] ?? '');
|
|
37
|
+
for (const r of RULES)
|
|
38
|
+
if (!excused && r.test(text))
|
|
39
|
+
out.push({ file: relative(unit, f), line: i + 1, rule: r.rule, text: text.trim().slice(0, 140) });
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Standard } from './types.js';
|
|
2
|
+
export declare const handlerName: (operationId: string) => string;
|
|
3
|
+
/** Named by "The grade" and decided by no tool yet: counted in no grade until a version of this standard checks them. */
|
|
4
|
+
export declare const PLANNED: string[];
|
|
5
|
+
export declare const protocol3: Standard;
|