@webpieces/code-rules 0.4.979 → 0.4.980

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.
Files changed (55) hide show
  1. package/package.json +8 -7
  2. package/src/code-policy-registry.js +5 -0
  3. package/src/code-policy-registry.js.map +1 -1
  4. package/src/configs/ipc-configs.d.ts +158 -0
  5. package/src/configs/ipc-configs.js +206 -0
  6. package/src/configs/ipc-configs.js.map +1 -0
  7. package/src/index.d.ts +7 -0
  8. package/src/index.js +20 -1
  9. package/src/index.js.map +1 -1
  10. package/src/ipc/ipc-boundary-analyzer.d.ts +92 -0
  11. package/src/ipc/ipc-boundary-analyzer.js +371 -0
  12. package/src/ipc/ipc-boundary-analyzer.js.map +1 -0
  13. package/src/ipc/ipc-contract-inventory.d.ts +83 -0
  14. package/src/ipc/ipc-contract-inventory.js +215 -0
  15. package/src/ipc/ipc-contract-inventory.js.map +1 -0
  16. package/src/ipc/ipc-contract-shape-analyzer.d.ts +54 -0
  17. package/src/ipc/ipc-contract-shape-analyzer.js +186 -0
  18. package/src/ipc/ipc-contract-shape-analyzer.js.map +1 -0
  19. package/src/ipc/ipc-controller-resolver.d.ts +43 -0
  20. package/src/ipc/ipc-controller-resolver.js +187 -0
  21. package/src/ipc/ipc-controller-resolver.js.map +1 -0
  22. package/src/ipc/ipc-pairing-analyzer.d.ts +43 -0
  23. package/src/ipc/ipc-pairing-analyzer.js +247 -0
  24. package/src/ipc/ipc-pairing-analyzer.js.map +1 -0
  25. package/src/ipc/ipc-protocol-fingerprint.d.ts +50 -0
  26. package/src/ipc/ipc-protocol-fingerprint.js +215 -0
  27. package/src/ipc/ipc-protocol-fingerprint.js.map +1 -0
  28. package/src/ipc/ipc-protocol-recorder.d.ts +25 -0
  29. package/src/ipc/ipc-protocol-recorder.js +98 -0
  30. package/src/ipc/ipc-protocol-recorder.js.map +1 -0
  31. package/src/ipc/ipc-rule-support.d.ts +27 -0
  32. package/src/ipc/ipc-rule-support.js +76 -0
  33. package/src/ipc/ipc-rule-support.js.map +1 -0
  34. package/src/ipc/ipc-source.d.ts +96 -0
  35. package/src/ipc/ipc-source.js +239 -0
  36. package/src/ipc/ipc-source.js.map +1 -0
  37. package/src/ipc-record-protocol.d.ts +2 -0
  38. package/src/ipc-record-protocol.js +34 -0
  39. package/src/ipc-record-protocol.js.map +1 -0
  40. package/src/rule-help.js +4 -0
  41. package/src/rule-help.js.map +1 -1
  42. package/src/rule-settings.js +119 -1
  43. package/src/rule-settings.js.map +1 -1
  44. package/src/validate-ipc-boundary.d.ts +20 -0
  45. package/src/validate-ipc-boundary.js +96 -0
  46. package/src/validate-ipc-boundary.js.map +1 -0
  47. package/src/validate-ipc-contract-shape.d.ts +20 -0
  48. package/src/validate-ipc-contract-shape.js +105 -0
  49. package/src/validate-ipc-contract-shape.js.map +1 -0
  50. package/src/validate-ipc-pairing.d.ts +16 -0
  51. package/src/validate-ipc-pairing.js +71 -0
  52. package/src/validate-ipc-pairing.js.map +1 -0
  53. package/src/validate-ipc-protocol-fingerprint.d.ts +23 -0
  54. package/src/validate-ipc-protocol-fingerprint.js +79 -0
  55. package/src/validate-ipc-protocol-fingerprint.js.map +1 -0
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Follows a receiver registration's controller argument to its class, and that class's `extends` chain to
3
+ * the shared contract — syntactically, across exactly the files the chain passes through (#1389).
4
+ *
5
+ * The replaced script asked the checker for the controller's base types, which required every endpoint
6
+ * file in one program. A registration is written in a few recognisable shapes, and those are what this
7
+ * follows: `new Controller(…)`, a `const` initialised with one (in the same file or imported), and for
8
+ * `createScoped` an object whose `create` returns one. Anything else is reported as unresolvable rather
9
+ * than passed — the rule fails closed.
10
+ */
11
+ import * as ts from 'typescript';
12
+ import { IpcFileReader, IpcModuleResolver, IpcSourceFile } from './ipc-source';
13
+ /** A class declaration and the file it is declared in. Data-only. */
14
+ export declare class IpcClassRef {
15
+ readonly file: IpcSourceFile;
16
+ readonly declaration: ts.ClassDeclaration;
17
+ constructor(file: IpcSourceFile, declaration: ts.ClassDeclaration);
18
+ }
19
+ export declare class IpcControllerResolver {
20
+ private readonly reader;
21
+ private readonly resolver;
22
+ private readonly contractPaths;
23
+ constructor(reader: IpcFileReader, resolver: IpcModuleResolver, contractPaths: readonly string[]);
24
+ /** The class a `create(api, <expr>)` controller argument instantiates. */
25
+ controllerOf(file: IpcSourceFile, expr: ts.Expression): IpcClassRef | undefined;
26
+ /** The class a `createScoped(api, { create })` scope's `create` returns. */
27
+ scopedControllerOf(file: IpcSourceFile, expr: ts.Expression): IpcClassRef | undefined;
28
+ /** True when `ref` (or a class it extends, transitively) extends the contract class `contractName`. */
29
+ extendsContract(ref: IpcClassRef, contractName: string, hops?: number): boolean;
30
+ private instanceOf;
31
+ /** The class named `name` as seen from `file`: declared there, imported, or re-exported to it. */
32
+ private classNamed;
33
+ /** The class `module` (as written in `from`) exports under `name`, following `export … from`. */
34
+ private exportedClass;
35
+ /** The source name `export … from` re-exports as `name`, or undefined when it does not. */
36
+ private reexportedName;
37
+ /** The initializer of the nearest `const <name> = …` anywhere in the file. */
38
+ private localInitializer;
39
+ private returnedExpression;
40
+ private bodyResult;
41
+ private baseExpression;
42
+ private unwrap;
43
+ }
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+ /**
3
+ * Follows a receiver registration's controller argument to its class, and that class's `extends` chain to
4
+ * the shared contract — syntactically, across exactly the files the chain passes through (#1389).
5
+ *
6
+ * The replaced script asked the checker for the controller's base types, which required every endpoint
7
+ * file in one program. A registration is written in a few recognisable shapes, and those are what this
8
+ * follows: `new Controller(…)`, a `const` initialised with one (in the same file or imported), and for
9
+ * `createScoped` an object whose `create` returns one. Anything else is reported as unresolvable rather
10
+ * than passed — the rule fails closed.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.IpcControllerResolver = exports.IpcClassRef = void 0;
14
+ const tslib_1 = require("tslib");
15
+ const ts = tslib_1.__importStar(require("typescript"));
16
+ const rules_config_1 = require("@webpieces/rules-config");
17
+ /** A class declaration and the file it is declared in. Data-only. */
18
+ class IpcClassRef {
19
+ file;
20
+ declaration;
21
+ constructor(file, declaration) {
22
+ this.file = file;
23
+ this.declaration = declaration;
24
+ }
25
+ }
26
+ exports.IpcClassRef = IpcClassRef;
27
+ /** How many files/aliases one resolution may pass through before it is treated as unresolvable. */
28
+ const MAX_HOPS = 12;
29
+ class IpcControllerResolver {
30
+ reader;
31
+ resolver;
32
+ contractPaths;
33
+ constructor(reader, resolver, contractPaths) {
34
+ this.reader = reader;
35
+ this.resolver = resolver;
36
+ this.contractPaths = contractPaths;
37
+ }
38
+ /** The class a `create(api, <expr>)` controller argument instantiates. */
39
+ controllerOf(file, expr) {
40
+ return this.instanceOf(file, expr, 0);
41
+ }
42
+ /** The class a `createScoped(api, { create })` scope's `create` returns. */
43
+ scopedControllerOf(file, expr) {
44
+ const scope = this.unwrap(expr);
45
+ if (!ts.isObjectLiteralExpression(scope))
46
+ return undefined;
47
+ for (const property of scope.properties) {
48
+ if (property.name === undefined || property.name.getText(file.source) !== 'create')
49
+ continue;
50
+ const returned = this.returnedExpression(property);
51
+ return returned === undefined ? undefined : this.instanceOf(file, returned, 0);
52
+ }
53
+ return undefined;
54
+ }
55
+ /** True when `ref` (or a class it extends, transitively) extends the contract class `contractName`. */
56
+ extendsContract(ref, contractName, hops = 0) {
57
+ if (hops > MAX_HOPS)
58
+ return false;
59
+ const base = this.baseExpression(ref.declaration);
60
+ if (base === undefined || !ts.isIdentifier(base))
61
+ return false;
62
+ const binding = ref.file.importOf(base.text);
63
+ if (binding !== undefined && binding.imported === contractName) {
64
+ const target = this.resolver.resolve(ref.file.relFile, binding.moduleSpecifier);
65
+ if (target !== undefined && (0, rules_config_1.matchesAnyGlob)(target, this.contractPaths))
66
+ return true;
67
+ }
68
+ const parent = this.classNamed(ref.file, base.text, hops + 1);
69
+ return parent !== undefined && this.extendsContract(parent, contractName, hops + 1);
70
+ }
71
+ instanceOf(file, expr, hops) {
72
+ if (hops > MAX_HOPS)
73
+ return undefined;
74
+ const node = this.unwrap(expr);
75
+ if (ts.isNewExpression(node)) {
76
+ return ts.isIdentifier(node.expression) ? this.classNamed(file, node.expression.text, hops + 1) : undefined;
77
+ }
78
+ if (!ts.isIdentifier(node))
79
+ return undefined;
80
+ const local = this.localInitializer(file, node.text);
81
+ if (local !== undefined)
82
+ return this.instanceOf(file, local, hops + 1);
83
+ const binding = file.importOf(node.text);
84
+ const target = binding === undefined ? undefined : this.resolver.resolve(file.relFile, binding.moduleSpecifier);
85
+ const targetFile = target === undefined ? undefined : this.reader.read(target);
86
+ if (binding === undefined || targetFile === undefined)
87
+ return undefined;
88
+ const exported = targetFile.variableInitializer(binding.imported);
89
+ return exported === undefined ? undefined : this.instanceOf(targetFile, exported, hops + 1);
90
+ }
91
+ /** The class named `name` as seen from `file`: declared there, imported, or re-exported to it. */
92
+ classNamed(file, name, hops) {
93
+ if (hops > MAX_HOPS)
94
+ return undefined;
95
+ const declared = file.classNamed(name);
96
+ if (declared !== undefined)
97
+ return new IpcClassRef(file, declared);
98
+ const binding = file.importOf(name);
99
+ if (binding !== undefined)
100
+ return this.exportedClass(file, binding.moduleSpecifier, binding.imported, hops + 1);
101
+ return undefined;
102
+ }
103
+ /** The class `module` (as written in `from`) exports under `name`, following `export … from`. */
104
+ exportedClass(from, module, name, hops) {
105
+ const target = this.resolver.resolve(from.relFile, module);
106
+ const file = target === undefined ? undefined : this.reader.read(target);
107
+ if (file === undefined || hops > MAX_HOPS)
108
+ return undefined;
109
+ const declared = file.classNamed(name);
110
+ if (declared !== undefined)
111
+ return new IpcClassRef(file, declared);
112
+ for (const statement of file.source.statements) {
113
+ if (!ts.isExportDeclaration(statement) || statement.moduleSpecifier === undefined)
114
+ continue;
115
+ if (!ts.isStringLiteral(statement.moduleSpecifier))
116
+ continue;
117
+ const reexported = this.reexportedName(statement, name);
118
+ if (reexported === undefined)
119
+ continue;
120
+ const found = this.exportedClass(file, statement.moduleSpecifier.text, reexported, hops + 1);
121
+ if (found !== undefined)
122
+ return found;
123
+ }
124
+ return undefined;
125
+ }
126
+ /** The source name `export … from` re-exports as `name`, or undefined when it does not. */
127
+ reexportedName(statement, name) {
128
+ const clause = statement.exportClause;
129
+ if (clause === undefined)
130
+ return name;
131
+ if (!ts.isNamedExports(clause))
132
+ return undefined;
133
+ const element = clause.elements.find((each) => each.name.text === name);
134
+ return element === undefined ? undefined : (element.propertyName?.text ?? element.name.text);
135
+ }
136
+ /** The initializer of the nearest `const <name> = …` anywhere in the file. */
137
+ localInitializer(file, name) {
138
+ let found;
139
+ const visit = (node) => {
140
+ if (found !== undefined)
141
+ return;
142
+ if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.name.text === name && node.initializer) {
143
+ found = node.initializer;
144
+ return;
145
+ }
146
+ ts.forEachChild(node, visit);
147
+ };
148
+ visit(file.source);
149
+ return found;
150
+ }
151
+ returnedExpression(property) {
152
+ if (ts.isPropertyAssignment(property)) {
153
+ const value = this.unwrap(property.initializer);
154
+ if (ts.isArrowFunction(value) || ts.isFunctionExpression(value))
155
+ return this.bodyResult(value.body);
156
+ return undefined;
157
+ }
158
+ if (ts.isMethodDeclaration(property) && property.body !== undefined)
159
+ return this.bodyResult(property.body);
160
+ return undefined;
161
+ }
162
+ bodyResult(body) {
163
+ if (!ts.isBlock(body))
164
+ return body;
165
+ for (const statement of body.statements) {
166
+ if (ts.isReturnStatement(statement))
167
+ return statement.expression;
168
+ }
169
+ return undefined;
170
+ }
171
+ baseExpression(declaration) {
172
+ for (const clause of declaration.heritageClauses ?? []) {
173
+ if (clause.token === ts.SyntaxKind.ExtendsKeyword)
174
+ return clause.types[0]?.expression;
175
+ }
176
+ return undefined;
177
+ }
178
+ unwrap(expr) {
179
+ let node = expr;
180
+ while (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isNonNullExpression(node) || ts.isSatisfiesExpression(node)) {
181
+ node = node.expression;
182
+ }
183
+ return node;
184
+ }
185
+ }
186
+ exports.IpcControllerResolver = IpcControllerResolver;
187
+ //# sourceMappingURL=ipc-controller-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ipc-controller-resolver.js","sourceRoot":"","sources":["../../../../../../packages/tooling/code-rules/src/ipc/ipc-controller-resolver.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;AAEH,uDAAiC;AACjC,0DAAyD;AAGzD,qEAAqE;AACrE,MAAa,WAAW;IAEP;IACA;IAFb,YACa,IAAmB,EACnB,WAAgC;QADhC,SAAI,GAAJ,IAAI,CAAe;QACnB,gBAAW,GAAX,WAAW,CAAqB;IAC1C,CAAC;CACP;AALD,kCAKC;AAED,mGAAmG;AACnG,MAAM,QAAQ,GAAG,EAAE,CAAC;AAEpB,MAAa,qBAAqB;IAET;IACA;IACA;IAHrB,YACqB,MAAqB,EACrB,QAA2B,EAC3B,aAAgC;QAFhC,WAAM,GAAN,MAAM,CAAe;QACrB,aAAQ,GAAR,QAAQ,CAAmB;QAC3B,kBAAa,GAAb,aAAa,CAAmB;IAClD,CAAC;IAEJ,0EAA0E;IAC1E,YAAY,CAAC,IAAmB,EAAE,IAAmB;QACjD,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,4EAA4E;IAC5E,kBAAkB,CAAC,IAAmB,EAAE,IAAmB;QACvD,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,CAAC,EAAE,CAAC,yBAAyB,CAAC,KAAK,CAAC;YAAE,OAAO,SAAS,CAAC;QAC3D,KAAK,MAAM,QAAQ,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;YACtC,IAAI,QAAQ,CAAC,IAAI,KAAK,SAAS,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,QAAQ;gBAAE,SAAS;YAC7F,MAAM,QAAQ,GAA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EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC;QACnC,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACtC,IAAI,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC;gBAAE,OAAO,SAAS,CAAC,UAAU,CAAC;QACrE,CAAC;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;IAEO,cAAc,CAAC,WAAgC;QACnD,KAAK,MAAM,MAAM,IAAI,WAAW,CAAC,eAAe,IAAI,EAAE,EAAE,CAAC;YACrD,IAAI,MAAM,CAAC,KAAK,KAAK,EAAE,CAAC,UAAU,CAAC,cAAc;gBAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC;QAC1F,CAAC;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;IAEO,MAAM,CAAC,IAAmB;QAC9B,IAAI,IAAI,GAAG,IAAI,CAAC;QAChB,OAAO,EAAE,CAAC,yBAAyB,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAAE,CAAC;YACrI,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC;QAC3B,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AA3ID,sDA2IC","sourcesContent":["/**\n * Follows a receiver registration's controller argument to its class, and that class's `extends` chain to\n * the shared contract — syntactically, across exactly the files the chain passes through (#1389).\n *\n * The replaced script asked the checker for the controller's base types, which required every endpoint\n * file in one program. A registration is written in a few recognisable shapes, and those are what this\n * follows: `new Controller(…)`, a `const` initialised with one (in the same file or imported), and for\n * `createScoped` an object whose `create` returns one. Anything else is reported as unresolvable rather\n * than passed — the rule fails closed.\n */\n\nimport * as ts from 'typescript';\nimport { matchesAnyGlob } from '@webpieces/rules-config';\nimport { IpcFileReader, IpcModuleResolver, IpcSourceFile } from './ipc-source';\n\n/** A class declaration and the file it is declared in. Data-only. */\nexport class IpcClassRef {\n constructor(\n readonly file: IpcSourceFile,\n readonly declaration: ts.ClassDeclaration,\n ) {}\n}\n\n/** How many files/aliases one resolution may pass through before it is treated as unresolvable. */\nconst MAX_HOPS = 12;\n\nexport class IpcControllerResolver {\n constructor(\n private readonly reader: IpcFileReader,\n private readonly resolver: IpcModuleResolver,\n private readonly contractPaths: readonly string[],\n ) {}\n\n /** The class a `create(api, <expr>)` controller argument instantiates. */\n controllerOf(file: IpcSourceFile, expr: ts.Expression): IpcClassRef | undefined {\n return this.instanceOf(file, expr, 0);\n }\n\n /** The class a `createScoped(api, { create })` scope's `create` returns. */\n scopedControllerOf(file: IpcSourceFile, expr: ts.Expression): IpcClassRef | undefined {\n const scope = this.unwrap(expr);\n if (!ts.isObjectLiteralExpression(scope)) return undefined;\n for (const property of scope.properties) {\n if (property.name === undefined || property.name.getText(file.source) !== 'create') continue;\n const returned = this.returnedExpression(property);\n return returned === undefined ? undefined : this.instanceOf(file, returned, 0);\n }\n return undefined;\n }\n\n /** True when `ref` (or a class it extends, transitively) extends the contract class `contractName`. */\n extendsContract(ref: IpcClassRef, contractName: string, hops = 0): boolean {\n if (hops > MAX_HOPS) return false;\n const base = this.baseExpression(ref.declaration);\n if (base === undefined || !ts.isIdentifier(base)) return false;\n const binding = ref.file.importOf(base.text);\n if (binding !== undefined && binding.imported === contractName) {\n const target = this.resolver.resolve(ref.file.relFile, binding.moduleSpecifier);\n if (target !== undefined && matchesAnyGlob(target, this.contractPaths)) return true;\n }\n const parent = this.classNamed(ref.file, base.text, hops + 1);\n return parent !== undefined && this.extendsContract(parent, contractName, hops + 1);\n }\n\n private instanceOf(file: IpcSourceFile, expr: ts.Expression, hops: number): IpcClassRef | undefined {\n if (hops > MAX_HOPS) return undefined;\n const node = this.unwrap(expr);\n if (ts.isNewExpression(node)) {\n return ts.isIdentifier(node.expression) ? this.classNamed(file, node.expression.text, hops + 1) : undefined;\n }\n if (!ts.isIdentifier(node)) return undefined;\n const local = this.localInitializer(file, node.text);\n if (local !== undefined) return this.instanceOf(file, local, hops + 1);\n const binding = file.importOf(node.text);\n const target = binding === undefined ? undefined : this.resolver.resolve(file.relFile, binding.moduleSpecifier);\n const targetFile = target === undefined ? undefined : this.reader.read(target);\n if (binding === undefined || targetFile === undefined) return undefined;\n const exported = targetFile.variableInitializer(binding.imported);\n return exported === undefined ? undefined : this.instanceOf(targetFile, exported, hops + 1);\n }\n\n /** The class named `name` as seen from `file`: declared there, imported, or re-exported to it. */\n private classNamed(file: IpcSourceFile, name: string, hops: number): IpcClassRef | undefined {\n if (hops > MAX_HOPS) return undefined;\n const declared = file.classNamed(name);\n if (declared !== undefined) return new IpcClassRef(file, declared);\n const binding = file.importOf(name);\n if (binding !== undefined) return this.exportedClass(file, binding.moduleSpecifier, binding.imported, hops + 1);\n return undefined;\n }\n\n /** The class `module` (as written in `from`) exports under `name`, following `export … from`. */\n private exportedClass(from: IpcSourceFile, module: string, name: string, hops: number): IpcClassRef | undefined {\n const target = this.resolver.resolve(from.relFile, module);\n const file = target === undefined ? undefined : this.reader.read(target);\n if (file === undefined || hops > MAX_HOPS) return undefined;\n const declared = file.classNamed(name);\n if (declared !== undefined) return new IpcClassRef(file, declared);\n for (const statement of file.source.statements) {\n if (!ts.isExportDeclaration(statement) || statement.moduleSpecifier === undefined) continue;\n if (!ts.isStringLiteral(statement.moduleSpecifier)) continue;\n const reexported = this.reexportedName(statement, name);\n if (reexported === undefined) continue;\n const found = this.exportedClass(file, statement.moduleSpecifier.text, reexported, hops + 1);\n if (found !== undefined) return found;\n }\n return undefined;\n }\n\n /** The source name `export … from` re-exports as `name`, or undefined when it does not. */\n private reexportedName(statement: ts.ExportDeclaration, name: string): string | undefined {\n const clause = statement.exportClause;\n if (clause === undefined) return name;\n if (!ts.isNamedExports(clause)) return undefined;\n const element = clause.elements.find((each: ts.ExportSpecifier) => each.name.text === name);\n return element === undefined ? undefined : (element.propertyName?.text ?? element.name.text);\n }\n\n /** The initializer of the nearest `const <name> = …` anywhere in the file. */\n private localInitializer(file: IpcSourceFile, name: string): ts.Expression | undefined {\n let found: ts.Expression | undefined;\n const visit = (node: ts.Node): void => {\n if (found !== undefined) return;\n if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.name.text === name && node.initializer) {\n found = node.initializer;\n return;\n }\n ts.forEachChild(node, visit);\n };\n visit(file.source);\n return found;\n }\n\n private returnedExpression(property: ts.ObjectLiteralElementLike): ts.Expression | undefined {\n if (ts.isPropertyAssignment(property)) {\n const value = this.unwrap(property.initializer);\n if (ts.isArrowFunction(value) || ts.isFunctionExpression(value)) return this.bodyResult(value.body);\n return undefined;\n }\n if (ts.isMethodDeclaration(property) && property.body !== undefined) return this.bodyResult(property.body);\n return undefined;\n }\n\n private bodyResult(body: ts.ConciseBody): ts.Expression | undefined {\n if (!ts.isBlock(body)) return body;\n for (const statement of body.statements) {\n if (ts.isReturnStatement(statement)) return statement.expression;\n }\n return undefined;\n }\n\n private baseExpression(declaration: ts.ClassDeclaration): ts.Expression | undefined {\n for (const clause of declaration.heritageClauses ?? []) {\n if (clause.token === ts.SyntaxKind.ExtendsKeyword) return clause.types[0]?.expression;\n }\n return undefined;\n }\n\n private unwrap(expr: ts.Expression): ts.Expression {\n let node = expr;\n while (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isNonNullExpression(node) || ts.isSatisfiesExpression(node)) {\n node = node.expression;\n }\n return node;\n }\n}\n"]}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * `ipc-pairing` judgement (#1389): the cross-file half of the replaced script — `metadata.mjs`'s
3
+ * inventory checks and `registrations.mjs`. Given the contract inventory (type-checked, contract-rooted)
4
+ * and the endpoint files (parsed one by one), it verifies:
5
+ *
6
+ * - every directional contract matches exactly one configured direction;
7
+ * - API ids are unique across the library; with a wire table, every row names a real contract method,
8
+ * wires are unique, kind/since/direction are sane, each method has exactly one row, and the
9
+ * decorator kind agrees with the row (an `event` row is a `notification` endpoint);
10
+ * - every contract has a generated `createClient(<Contract>)` in its direction's sender files;
11
+ * - every contract has EXACTLY ONE `create` / `createScoped(<Contract>, …)` registration across all
12
+ * receiver files, it sits in its own direction's receiver files, and its controller is a subclass of
13
+ * that same shared contract;
14
+ * - no receiver file registers an unknown contract or keeps a handwritten dispatch map beside the factory.
15
+ */
16
+ import { IpcPairingConfig } from '../configs/ipc-configs';
17
+ import { IpcContractInventory } from './ipc-contract-inventory';
18
+ import { IpcControllerResolver } from './ipc-controller-resolver';
19
+ import { IpcFileReader, IpcFinding } from './ipc-source';
20
+ export declare class IpcPairingAnalyzer {
21
+ private readonly config;
22
+ private readonly reader;
23
+ private readonly controllers;
24
+ private readonly suffixes;
25
+ constructor(config: IpcPairingConfig, reader: IpcFileReader, controllers: IpcControllerResolver);
26
+ /** `sourceFiles` is every workspace TypeScript source file; the configured globs pick from it. */
27
+ analyze(inventory: IpcContractInventory, sourceFiles: readonly string[]): IpcFinding[];
28
+ private filesOf;
29
+ private directionOf;
30
+ private judgeIds;
31
+ private judgeWireTable;
32
+ private judgeRowsOf;
33
+ private judgeContract;
34
+ private clientSites;
35
+ private readRegistrations;
36
+ private readRegistration;
37
+ private judgeDispatchMap;
38
+ /** `x.<member>(…)` → member, else undefined. */
39
+ private calledMember;
40
+ /** The contract class named by a call's first argument, through an import rename, or undefined. */
41
+ private contractArgument;
42
+ private at;
43
+ }
@@ -0,0 +1,247 @@
1
+ "use strict";
2
+ /**
3
+ * `ipc-pairing` judgement (#1389): the cross-file half of the replaced script — `metadata.mjs`'s
4
+ * inventory checks and `registrations.mjs`. Given the contract inventory (type-checked, contract-rooted)
5
+ * and the endpoint files (parsed one by one), it verifies:
6
+ *
7
+ * - every directional contract matches exactly one configured direction;
8
+ * - API ids are unique across the library; with a wire table, every row names a real contract method,
9
+ * wires are unique, kind/since/direction are sane, each method has exactly one row, and the
10
+ * decorator kind agrees with the row (an `event` row is a `notification` endpoint);
11
+ * - every contract has a generated `createClient(<Contract>)` in its direction's sender files;
12
+ * - every contract has EXACTLY ONE `create` / `createScoped(<Contract>, …)` registration across all
13
+ * receiver files, it sits in its own direction's receiver files, and its controller is a subclass of
14
+ * that same shared contract;
15
+ * - no receiver file registers an unknown contract or keeps a handwritten dispatch map beside the factory.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.IpcPairingAnalyzer = void 0;
19
+ const tslib_1 = require("tslib");
20
+ const ts = tslib_1.__importStar(require("typescript"));
21
+ const rules_config_1 = require("@webpieces/rules-config");
22
+ const ipc_source_1 = require("./ipc-source");
23
+ /** One `create` / `createScoped` call found in a receiver file. Data-only. */
24
+ class IpcRegistration {
25
+ contract;
26
+ file;
27
+ call;
28
+ controller;
29
+ constructor(contract, file, call, controller) {
30
+ this.contract = contract;
31
+ this.file = file;
32
+ this.call = call;
33
+ this.controller = controller;
34
+ }
35
+ }
36
+ /** One `createClient(<Contract>)` call found in a sender file. Data-only. */
37
+ class IpcClientSite {
38
+ contract;
39
+ relFile;
40
+ constructor(contract, relFile) {
41
+ this.contract = contract;
42
+ this.relFile = relFile;
43
+ }
44
+ }
45
+ const REGISTRATION_METHODS = ['create', 'createScoped'];
46
+ class IpcPairingAnalyzer {
47
+ config;
48
+ reader;
49
+ controllers;
50
+ suffixes;
51
+ constructor(config, reader, controllers) {
52
+ this.config = config;
53
+ this.reader = reader;
54
+ this.controllers = controllers;
55
+ this.suffixes = config.directions.map((direction) => direction.apiSuffix);
56
+ }
57
+ /** `sourceFiles` is every workspace TypeScript source file; the configured globs pick from it. */
58
+ analyze(inventory, sourceFiles) {
59
+ const out = [];
60
+ for (const error of inventory.errors)
61
+ out.push(new ipc_source_1.IpcFinding(this.config.wireTableFile ?? '', 1, '', error));
62
+ out.push(...this.judgeIds(inventory));
63
+ if (inventory.rows !== undefined)
64
+ out.push(...this.judgeWireTable(inventory, inventory.rows));
65
+ const senders = this.filesOf(sourceFiles, (direction) => direction.senderFiles);
66
+ const receivers = this.filesOf(sourceFiles, (direction) => direction.receiverFiles);
67
+ const clients = senders.flatMap((rel) => this.clientSites(rel));
68
+ const registrations = [];
69
+ for (const rel of receivers)
70
+ out.push(...this.readRegistrations(rel, registrations));
71
+ for (const contract of inventory.contracts.values())
72
+ out.push(...this.judgeContract(contract, clients, registrations));
73
+ for (const registration of registrations) {
74
+ if (inventory.contracts.has(registration.contract))
75
+ continue;
76
+ out.push(registration.file.finding(registration.call, `IPC receiver registers unknown contract ${registration.contract}.`));
77
+ }
78
+ return out;
79
+ }
80
+ filesOf(all, globs) {
81
+ const patterns = this.config.directions.flatMap(globs);
82
+ return all.filter((rel) => (0, rules_config_1.matchesAnyGlob)(rel, patterns));
83
+ }
84
+ directionOf(contract) {
85
+ return this.config.directions.find((direction) => contract.endsWith(direction.apiSuffix));
86
+ }
87
+ judgeIds(inventory) {
88
+ const out = [];
89
+ const seen = new Map();
90
+ for (const contract of inventory.contracts.values()) {
91
+ const clash = contract.id === undefined ? undefined : seen.get(contract.id);
92
+ if (contract.id === undefined || clash !== undefined) {
93
+ out.push(this.at(contract, `IPC ${contract.name} needs one uniquely identified @WpInternal id${clash ? ` (also used by ${clash})` : ''}.`));
94
+ }
95
+ else {
96
+ seen.set(contract.id, contract.name);
97
+ }
98
+ }
99
+ return out;
100
+ }
101
+ judgeWireTable(inventory, rows) {
102
+ const table = this.config.wireTableFile ?? '';
103
+ const out = [];
104
+ const wires = new Set();
105
+ for (const row of rows) {
106
+ const label = `${String(row.api)}.${String(row.method)}`;
107
+ const contract = typeof row.api === 'string' ? inventory.contracts.get(row.api) : undefined;
108
+ if (contract?.methods.some((method) => method.name === row.method) !== true) {
109
+ out.push(new ipc_source_1.IpcFinding(table, 1, label, `IPC metadata ${label} has no shared abstract API method.`));
110
+ }
111
+ if (row.wire === undefined || wires.has(row.wire)) {
112
+ out.push(new ipc_source_1.IpcFinding(table, 1, label, `IPC wire registration is missing or duplicated: ${String(row.wire)}.`));
113
+ }
114
+ if (row.wire !== undefined)
115
+ wires.add(row.wire);
116
+ const since = row.since;
117
+ if ((row.kind !== 'request' && row.kind !== 'event') || typeof since !== 'number' || !Number.isInteger(since) || since < 0) {
118
+ out.push(new ipc_source_1.IpcFinding(table, 1, label, `IPC ${String(row.wire)} needs kind and since-protocol metadata.`));
119
+ }
120
+ const direction = typeof row.api === 'string' ? this.directionOf(row.api) : undefined;
121
+ if (direction === undefined || row.direction !== direction.wireDirection) {
122
+ out.push(new ipc_source_1.IpcFinding(table, 1, label, `IPC ${String(row.wire)} direction does not match ${String(row.api)}.`));
123
+ }
124
+ }
125
+ for (const contract of inventory.contracts.values())
126
+ out.push(...this.judgeRowsOf(contract, rows));
127
+ return out;
128
+ }
129
+ judgeRowsOf(contract, rows) {
130
+ const out = [];
131
+ for (const method of contract.methods) {
132
+ const own = rows.filter((row) => row.api === contract.name && row.method === method.name);
133
+ if (own.length !== 1)
134
+ out.push(this.at(contract, `IPC ${contract.name}.${method.name} requires exactly one wire metadata entry.`));
135
+ const expected = own[0]?.kind === 'event' ? 'notification' : 'request';
136
+ if (method.hasEndpoint && method.kind !== expected) {
137
+ out.push(this.at(contract, `IPC ${contract.name}.${method.name} decorator kind must be ${expected}.`));
138
+ }
139
+ }
140
+ return out;
141
+ }
142
+ judgeContract(contract, clients, registrations) {
143
+ const direction = this.directionOf(contract.name);
144
+ if (direction === undefined) {
145
+ return [this.at(contract, `IPC ${contract.name} matches no configured direction's apiSuffix.`)];
146
+ }
147
+ const out = [];
148
+ const sent = clients.some((site) => site.contract === contract.name && (0, rules_config_1.matchesAnyGlob)(site.relFile, direction.senderFiles));
149
+ if (!sent)
150
+ out.push(this.at(contract, `IPC ${contract.name} has no generated client at its sending endpoint.`));
151
+ const matches = registrations.filter((registration) => registration.contract === contract.name);
152
+ if (matches.length !== 1) {
153
+ out.push(this.at(contract, `IPC ${contract.name} requires exactly one framework receiver registration (found ${matches.length}).`));
154
+ return out;
155
+ }
156
+ const registration = matches[0];
157
+ const controller = registration.controller;
158
+ if (controller === undefined || !this.controllers.extendsContract(controller, contract.name)) {
159
+ out.push(registration.file.finding(registration.call, `IPC ${contract.name} registration must receive a concrete subclass of the same shared API ` +
160
+ '(pass `new <Controller>(…)`, a const initialised with one, or a scope whose `create` returns one).'));
161
+ }
162
+ if (!(0, rules_config_1.matchesAnyGlob)(registration.file.relFile, direction.receiverFiles)) {
163
+ out.push(registration.file.finding(registration.call, `IPC ${contract.name} receiver is on the wrong endpoint.`));
164
+ }
165
+ return out;
166
+ }
167
+ clientSites(rel) {
168
+ const file = this.reader.read(rel);
169
+ if (file === undefined)
170
+ return [];
171
+ const out = [];
172
+ const visit = (node) => {
173
+ const name = this.calledMember(node);
174
+ const contract = name === 'createClient' ? this.contractArgument(file, node) : undefined;
175
+ if (contract !== undefined)
176
+ out.push(new IpcClientSite(contract, rel));
177
+ ts.forEachChild(node, visit);
178
+ };
179
+ visit(file.source);
180
+ return out;
181
+ }
182
+ readRegistrations(rel, into) {
183
+ const file = this.reader.read(rel);
184
+ if (file === undefined)
185
+ return [];
186
+ const out = [];
187
+ const visit = (node) => {
188
+ out.push(...this.judgeDispatchMap(file, node));
189
+ const name = this.calledMember(node);
190
+ if (name !== undefined && REGISTRATION_METHODS.includes(name)) {
191
+ out.push(...this.readRegistration(file, node, name, into));
192
+ }
193
+ ts.forEachChild(node, visit);
194
+ };
195
+ visit(file.source);
196
+ return out;
197
+ }
198
+ readRegistration(file, call, method, into) {
199
+ const contract = this.contractArgument(file, call);
200
+ if (contract === undefined)
201
+ return [];
202
+ const controllerArg = call.arguments[1];
203
+ if (controllerArg === undefined) {
204
+ return [file.finding(call, `IPC registration of ${contract} in ${file.relFile} lacks contract/controller.`)];
205
+ }
206
+ const controller = method === 'createScoped'
207
+ ? this.controllers.scopedControllerOf(file, controllerArg)
208
+ : this.controllers.controllerOf(file, controllerArg);
209
+ into.push(new IpcRegistration(contract, file, call, controller));
210
+ return [];
211
+ }
212
+ judgeDispatchMap(file, node) {
213
+ if (!ts.isVariableDeclaration(node) || !ts.isIdentifier(node.name))
214
+ return [];
215
+ if (!this.config.forbiddenDispatchVariables.includes(node.name.text))
216
+ return [];
217
+ if (node.initializer === undefined || !ts.isNewExpression(node.initializer))
218
+ return [];
219
+ return [file.finding(node, `Remove the legacy receiver map in ${file.relFile}; IpcServerFactory is the dispatcher.`)];
220
+ }
221
+ /** `x.<member>(…)` → member, else undefined. */
222
+ calledMember(node) {
223
+ if (!ts.isCallExpression(node) || !ts.isPropertyAccessExpression(node.expression))
224
+ return undefined;
225
+ return node.expression.name.text;
226
+ }
227
+ /** The contract class named by a call's first argument, through an import rename, or undefined. */
228
+ contractArgument(file, call) {
229
+ const first = call.arguments[0];
230
+ if (first === undefined)
231
+ return undefined;
232
+ const name = ts.isIdentifier(first)
233
+ ? (file.importOf(first.text)?.imported ?? first.text)
234
+ : ts.isPropertyAccessExpression(first) ? first.name.text : undefined;
235
+ if (name === undefined)
236
+ return undefined;
237
+ return this.suffixes.some((suffix) => name.endsWith(suffix)) ? name : undefined;
238
+ }
239
+ at(contract, message) {
240
+ const source = contract.declaration.getSourceFile();
241
+ const node = contract.declaration.name ?? contract.declaration;
242
+ const line = source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1;
243
+ return new ipc_source_1.IpcFinding(contract.relFile, line, contract.name, message);
244
+ }
245
+ }
246
+ exports.IpcPairingAnalyzer = IpcPairingAnalyzer;
247
+ //# sourceMappingURL=ipc-pairing-analyzer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ipc-pairing-analyzer.js","sourceRoot":"","sources":["../../../../../../packages/tooling/code-rules/src/ipc/ipc-pairing-analyzer.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;AAEH,uDAAiC;AACjC,0DAAyD;AAIzD,6CAAwE;AAExE,8EAA8E;AAC9E,MAAM,eAAe;IAEJ;IACA;IACA;IACA;IAJb,YACa,QAAgB,EAChB,IAAmB,EACnB,IAAuB,EACvB,UAAmC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AAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IAC5F,CAAC;IAEO,EAAE,CAAC,QAAgC,EAAE,OAAe;QACxD,MAAM,MAAM,GAAG,QAAQ,CAAC,WAAW,CAAC,aAAa,EAAE,CAAC;QACpD,MAAM,IAAI,GAAG,QAAQ,CAAC,WAAW,CAAC,IAAI,IAAI,QAAQ,CAAC,WAAW,CAAC;QAC/D,MAAM,IAAI,GAAG,MAAM,CAAC,6BAA6B,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC;QAClF,OAAO,IAAI,uBAAU,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC1E,CAAC;CACJ;AAzMD,gDAyMC","sourcesContent":["/**\n * `ipc-pairing` judgement (#1389): the cross-file half of the replaced script — `metadata.mjs`'s\n * inventory checks and `registrations.mjs`. Given the contract inventory (type-checked, contract-rooted)\n * and the endpoint files (parsed one by one), it verifies:\n *\n * - every directional contract matches exactly one configured direction;\n * - API ids are unique across the library; with a wire table, every row names a real contract method,\n * wires are unique, kind/since/direction are sane, each method has exactly one row, and the\n * decorator kind agrees with the row (an `event` row is a `notification` endpoint);\n * - every contract has a generated `createClient(<Contract>)` in its direction's sender files;\n * - every contract has EXACTLY ONE `create` / `createScoped(<Contract>, …)` registration across all\n * receiver files, it sits in its own direction's receiver files, and its controller is a subclass of\n * that same shared contract;\n * - no receiver file registers an unknown contract or keeps a handwritten dispatch map beside the factory.\n */\n\nimport * as ts from 'typescript';\nimport { matchesAnyGlob } from '@webpieces/rules-config';\nimport { IpcDirectionEntry, IpcPairingConfig } from '../configs/ipc-configs';\nimport { IpcContractInventory, IpcContractMethod, IpcDirectionalContract, IpcWireRow } from './ipc-contract-inventory';\nimport { IpcClassRef, IpcControllerResolver } from './ipc-controller-resolver';\nimport { IpcFileReader, IpcFinding, IpcSourceFile } from './ipc-source';\n\n/** One `create` / `createScoped` call found in a receiver file. Data-only. */\nclass IpcRegistration {\n constructor(\n readonly contract: string,\n readonly file: IpcSourceFile,\n readonly call: ts.CallExpression,\n readonly controller: IpcClassRef | undefined,\n ) {}\n}\n\n/** One `createClient(<Contract>)` call found in a sender file. Data-only. */\nclass IpcClientSite {\n constructor(\n readonly contract: string,\n readonly relFile: string,\n ) {}\n}\n\nconst REGISTRATION_METHODS: readonly string[] = ['create', 'createScoped'];\n\nexport class IpcPairingAnalyzer {\n private readonly suffixes: readonly string[];\n\n constructor(\n private readonly config: IpcPairingConfig,\n private readonly reader: IpcFileReader,\n private readonly controllers: IpcControllerResolver,\n ) {\n this.suffixes = config.directions.map((direction: IpcDirectionEntry) => direction.apiSuffix);\n }\n\n /** `sourceFiles` is every workspace TypeScript source file; the configured globs pick from it. */\n analyze(inventory: IpcContractInventory, sourceFiles: readonly string[]): IpcFinding[] {\n const out: IpcFinding[] = [];\n for (const error of inventory.errors) out.push(new IpcFinding(this.config.wireTableFile ?? '', 1, '', error));\n out.push(...this.judgeIds(inventory));\n if (inventory.rows !== undefined) out.push(...this.judgeWireTable(inventory, inventory.rows));\n const senders = this.filesOf(sourceFiles, (direction: IpcDirectionEntry) => direction.senderFiles);\n const receivers = this.filesOf(sourceFiles, (direction: IpcDirectionEntry) => direction.receiverFiles);\n const clients = senders.flatMap((rel: string) => this.clientSites(rel));\n const registrations: IpcRegistration[] = [];\n for (const rel of receivers) out.push(...this.readRegistrations(rel, registrations));\n for (const contract of inventory.contracts.values()) out.push(...this.judgeContract(contract, clients, registrations));\n for (const registration of registrations) {\n if (inventory.contracts.has(registration.contract)) continue;\n out.push(registration.file.finding(registration.call, `IPC receiver registers unknown contract ${registration.contract}.`));\n }\n return out;\n }\n\n private filesOf(all: readonly string[], globs: (direction: IpcDirectionEntry) => readonly string[]): string[] {\n const patterns = this.config.directions.flatMap(globs);\n return all.filter((rel: string) => matchesAnyGlob(rel, patterns));\n }\n\n private directionOf(contract: string): IpcDirectionEntry | undefined {\n return this.config.directions.find((direction: IpcDirectionEntry) => contract.endsWith(direction.apiSuffix));\n }\n\n private judgeIds(inventory: IpcContractInventory): IpcFinding[] {\n const out: IpcFinding[] = [];\n const seen = new Map<string | number, string>();\n for (const contract of inventory.contracts.values()) {\n const clash = contract.id === undefined ? undefined : seen.get(contract.id);\n if (contract.id === undefined || clash !== undefined) {\n out.push(this.at(contract, `IPC ${contract.name} needs one uniquely identified @WpInternal id${clash ? ` (also used by ${clash})` : ''}.`));\n } else {\n seen.set(contract.id, contract.name);\n }\n }\n return out;\n }\n\n private judgeWireTable(inventory: IpcContractInventory, rows: readonly IpcWireRow[]): IpcFinding[] {\n const table = this.config.wireTableFile ?? '';\n const out: IpcFinding[] = [];\n const wires = new Set<string | number>();\n for (const row of rows) {\n const label = `${String(row.api)}.${String(row.method)}`;\n const contract = typeof row.api === 'string' ? inventory.contracts.get(row.api) : undefined;\n if (contract?.methods.some((method: IpcContractMethod) => method.name === row.method) !== true) {\n out.push(new IpcFinding(table, 1, label, `IPC metadata ${label} has no shared abstract API method.`));\n }\n if (row.wire === undefined || wires.has(row.wire)) {\n out.push(new IpcFinding(table, 1, label, `IPC wire registration is missing or duplicated: ${String(row.wire)}.`));\n }\n if (row.wire !== undefined) wires.add(row.wire);\n const since = row.since;\n if ((row.kind !== 'request' && row.kind !== 'event') || typeof since !== 'number' || !Number.isInteger(since) || since < 0) {\n out.push(new IpcFinding(table, 1, label, `IPC ${String(row.wire)} needs kind and since-protocol metadata.`));\n }\n const direction = typeof row.api === 'string' ? this.directionOf(row.api) : undefined;\n if (direction === undefined || row.direction !== direction.wireDirection) {\n out.push(new IpcFinding(table, 1, label, `IPC ${String(row.wire)} direction does not match ${String(row.api)}.`));\n }\n }\n for (const contract of inventory.contracts.values()) out.push(...this.judgeRowsOf(contract, rows));\n return out;\n }\n\n private judgeRowsOf(contract: IpcDirectionalContract, rows: readonly IpcWireRow[]): IpcFinding[] {\n const out: IpcFinding[] = [];\n for (const method of contract.methods) {\n const own = rows.filter((row: IpcWireRow) => row.api === contract.name && row.method === method.name);\n if (own.length !== 1) out.push(this.at(contract, `IPC ${contract.name}.${method.name} requires exactly one wire metadata entry.`));\n const expected = own[0]?.kind === 'event' ? 'notification' : 'request';\n if (method.hasEndpoint && method.kind !== expected) {\n out.push(this.at(contract, `IPC ${contract.name}.${method.name} decorator kind must be ${expected}.`));\n }\n }\n return out;\n }\n\n private judgeContract(\n contract: IpcDirectionalContract,\n clients: readonly IpcClientSite[],\n registrations: readonly IpcRegistration[],\n ): IpcFinding[] {\n const direction = this.directionOf(contract.name);\n if (direction === undefined) {\n return [this.at(contract, `IPC ${contract.name} matches no configured direction's apiSuffix.`)];\n }\n const out: IpcFinding[] = [];\n const sent = clients.some(\n (site: IpcClientSite) => site.contract === contract.name && matchesAnyGlob(site.relFile, direction.senderFiles),\n );\n if (!sent) out.push(this.at(contract, `IPC ${contract.name} has no generated client at its sending endpoint.`));\n const matches = registrations.filter((registration: IpcRegistration) => registration.contract === contract.name);\n if (matches.length !== 1) {\n out.push(this.at(contract, `IPC ${contract.name} requires exactly one framework receiver registration (found ${matches.length}).`));\n return out;\n }\n const registration = matches[0];\n const controller = registration.controller;\n if (controller === undefined || !this.controllers.extendsContract(controller, contract.name)) {\n out.push(registration.file.finding(\n registration.call,\n `IPC ${contract.name} registration must receive a concrete subclass of the same shared API ` +\n '(pass `new <Controller>(…)`, a const initialised with one, or a scope whose `create` returns one).',\n ));\n }\n if (!matchesAnyGlob(registration.file.relFile, direction.receiverFiles)) {\n out.push(registration.file.finding(registration.call, `IPC ${contract.name} receiver is on the wrong endpoint.`));\n }\n return out;\n }\n\n private clientSites(rel: string): IpcClientSite[] {\n const file = this.reader.read(rel);\n if (file === undefined) return [];\n const out: IpcClientSite[] = [];\n const visit = (node: ts.Node): void => {\n const name = this.calledMember(node);\n const contract = name === 'createClient' ? this.contractArgument(file, node as ts.CallExpression) : undefined;\n if (contract !== undefined) out.push(new IpcClientSite(contract, rel));\n ts.forEachChild(node, visit);\n };\n visit(file.source);\n return out;\n }\n\n private readRegistrations(rel: string, into: IpcRegistration[]): IpcFinding[] {\n const file = this.reader.read(rel);\n if (file === undefined) return [];\n const out: IpcFinding[] = [];\n const visit = (node: ts.Node): void => {\n out.push(...this.judgeDispatchMap(file, node));\n const name = this.calledMember(node);\n if (name !== undefined && REGISTRATION_METHODS.includes(name)) {\n out.push(...this.readRegistration(file, node as ts.CallExpression, name, into));\n }\n ts.forEachChild(node, visit);\n };\n visit(file.source);\n return out;\n }\n\n private readRegistration(file: IpcSourceFile, call: ts.CallExpression, method: string, into: IpcRegistration[]): IpcFinding[] {\n const contract = this.contractArgument(file, call);\n if (contract === undefined) return [];\n const controllerArg = call.arguments[1];\n if (controllerArg === undefined) {\n return [file.finding(call, `IPC registration of ${contract} in ${file.relFile} lacks contract/controller.`)];\n }\n const controller = method === 'createScoped'\n ? this.controllers.scopedControllerOf(file, controllerArg)\n : this.controllers.controllerOf(file, controllerArg);\n into.push(new IpcRegistration(contract, file, call, controller));\n return [];\n }\n\n private judgeDispatchMap(file: IpcSourceFile, node: ts.Node): IpcFinding[] {\n if (!ts.isVariableDeclaration(node) || !ts.isIdentifier(node.name)) return [];\n if (!this.config.forbiddenDispatchVariables.includes(node.name.text)) return [];\n if (node.initializer === undefined || !ts.isNewExpression(node.initializer)) return [];\n return [file.finding(node, `Remove the legacy receiver map in ${file.relFile}; IpcServerFactory is the dispatcher.`)];\n }\n\n /** `x.<member>(…)` → member, else undefined. */\n private calledMember(node: ts.Node): string | undefined {\n if (!ts.isCallExpression(node) || !ts.isPropertyAccessExpression(node.expression)) return undefined;\n return node.expression.name.text;\n }\n\n /** The contract class named by a call's first argument, through an import rename, or undefined. */\n private contractArgument(file: IpcSourceFile, call: ts.CallExpression): string | undefined {\n const first = call.arguments[0];\n if (first === undefined) return undefined;\n const name = ts.isIdentifier(first)\n ? (file.importOf(first.text)?.imported ?? first.text)\n : ts.isPropertyAccessExpression(first) ? first.name.text : undefined;\n if (name === undefined) return undefined;\n return this.suffixes.some((suffix: string) => name.endsWith(suffix)) ? name : undefined;\n }\n\n private at(contract: IpcDirectionalContract, message: string): IpcFinding {\n const source = contract.declaration.getSourceFile();\n const node = contract.declaration.name ?? contract.declaration;\n const line = source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1;\n return new IpcFinding(contract.relFile, line, contract.name, message);\n }\n}\n"]}