behavguard 0.0.0-stage → 0.8.3
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/.github/workflows/behavguard.yml +91 -0
- package/README.md +131 -2
- package/config/static-gates.example.json +9 -0
- package/dist/analysis-cache.d.ts +3 -0
- package/dist/analysis-cache.js +115 -0
- package/dist/analysis-cache.js.map +1 -0
- package/dist/artifacts.d.ts +32 -0
- package/dist/artifacts.js +170 -0
- package/dist/artifacts.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +200 -0
- package/dist/cli.js.map +1 -0
- package/dist/comparator.d.ts +21 -0
- package/dist/comparator.js +238 -0
- package/dist/comparator.js.map +1 -0
- package/dist/controller.d.ts +93 -0
- package/dist/controller.js +384 -0
- package/dist/controller.js.map +1 -0
- package/dist/coverage.d.ts +14 -0
- package/dist/coverage.js +134 -0
- package/dist/coverage.js.map +1 -0
- package/dist/database-syntax.d.ts +3 -0
- package/dist/database-syntax.js +117 -0
- package/dist/database-syntax.js.map +1 -0
- package/dist/dependencies.d.ts +10 -0
- package/dist/dependencies.js +249 -0
- package/dist/dependencies.js.map +1 -0
- package/dist/dependency-inputs.d.ts +8 -0
- package/dist/dependency-inputs.js +10 -0
- package/dist/dependency-inputs.js.map +1 -0
- package/dist/effects.d.ts +12 -0
- package/dist/effects.js +263 -0
- package/dist/effects.js.map +1 -0
- package/dist/evidence.d.ts +3 -0
- package/dist/evidence.js +68 -0
- package/dist/evidence.js.map +1 -0
- package/dist/gate.d.ts +46 -0
- package/dist/gate.js +89 -0
- package/dist/gate.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/model.d.ts +78 -0
- package/dist/model.js +2 -0
- package/dist/model.js.map +1 -0
- package/dist/package-resolution.d.ts +15 -0
- package/dist/package-resolution.js +156 -0
- package/dist/package-resolution.js.map +1 -0
- package/dist/planning.d.ts +35 -0
- package/dist/planning.js +56 -0
- package/dist/planning.js.map +1 -0
- package/dist/runtime-coverage.d.ts +8 -0
- package/dist/runtime-coverage.js +70 -0
- package/dist/runtime-coverage.js.map +1 -0
- package/dist/runtime-protocol.d.ts +33 -0
- package/dist/runtime-protocol.js +2 -0
- package/dist/runtime-protocol.js.map +1 -0
- package/dist/runtime.d.ts +17 -0
- package/dist/runtime.js +215 -0
- package/dist/runtime.js.map +1 -0
- package/dist/scenarios.d.ts +75 -0
- package/dist/scenarios.js +435 -0
- package/dist/scenarios.js.map +1 -0
- package/dist/snapshot.d.ts +5 -0
- package/dist/snapshot.js +93 -0
- package/dist/snapshot.js.map +1 -0
- package/dist/static-analysis.d.ts +61 -0
- package/dist/static-analysis.js +408 -0
- package/dist/static-analysis.js.map +1 -0
- package/dist/static-approvals.d.ts +25 -0
- package/dist/static-approvals.js +54 -0
- package/dist/static-approvals.js.map +1 -0
- package/dist/static-index.d.ts +113 -0
- package/dist/static-index.js +654 -0
- package/dist/static-index.js.map +1 -0
- package/dist/static-project.d.ts +40 -0
- package/dist/static-project.js +236 -0
- package/dist/static-project.js.map +1 -0
- package/dist/values.d.ts +10 -0
- package/dist/values.js +274 -0
- package/dist/values.js.map +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/dist/worker.d.ts +1 -0
- package/dist/worker.js +338 -0
- package/dist/worker.js.map +1 -0
- package/docs/pilot-evaluation.md +113 -0
- package/docs/pilot-fixtures/ky840.catalog.json +21 -0
- package/docs/pilot-fixtures/ky840.scenarios.json +82 -0
- package/docs/pilot-fixtures/ofetch482.catalog.json +45 -0
- package/docs/pilot-fixtures/ofetch482.scenarios.json +294 -0
- package/package.json +39 -4
- package/scripts/check-pull-request.sh +46 -0
- package/scripts/github-static-approvals.mjs +196 -0
- package/skills/behavguard/SKILL.md +15 -0
|
@@ -0,0 +1,654 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import ts from 'typescript';
|
|
3
|
+
import { isCompilerLib, isDeclaration, repositoryPath } from './static-project.js';
|
|
4
|
+
function digest(text) {
|
|
5
|
+
return createHash('sha256').update(text).digest('hex');
|
|
6
|
+
}
|
|
7
|
+
function scan(text, offset = 0) {
|
|
8
|
+
const scanner = ts.createScanner(ts.ScriptTarget.Latest, true, ts.LanguageVariant.Standard, text);
|
|
9
|
+
const tokens = [];
|
|
10
|
+
for (let type = scanner.scan(); type !== ts.SyntaxKind.EndOfFileToken; type = scanner.scan()) {
|
|
11
|
+
tokens.push({ key: `${type}:${scanner.getTokenText()}`, start: offset + scanner.getTokenStart(), end: offset + scanner.getTextPos() });
|
|
12
|
+
}
|
|
13
|
+
return tokens;
|
|
14
|
+
}
|
|
15
|
+
function semanticTokens(node, normalizeStringValues = false) {
|
|
16
|
+
const source = node.getSourceFile();
|
|
17
|
+
const tokens = [];
|
|
18
|
+
function append(child) {
|
|
19
|
+
if (ts.isJSDoc(child) || child.kind === ts.SyntaxKind.EndOfFileToken)
|
|
20
|
+
return;
|
|
21
|
+
const children = child.getChildren(source);
|
|
22
|
+
if (children.length) {
|
|
23
|
+
children.forEach(append);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const start = ts.isJsxText(child) ? child.getFullStart() : child.getStart(source);
|
|
27
|
+
const end = child.getEnd();
|
|
28
|
+
if (end > start) {
|
|
29
|
+
const value = normalizeStringValues && ts.isStringLiteral(child) && !ts.isExpressionStatement(child.parent)
|
|
30
|
+
? JSON.stringify(child.text) : source.text.slice(start, end);
|
|
31
|
+
tokens.push({ key: `${child.kind}:${value}`, start, end });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
append(node);
|
|
35
|
+
return tokens;
|
|
36
|
+
}
|
|
37
|
+
export function normalized(node) {
|
|
38
|
+
return normalizedExcept(node);
|
|
39
|
+
}
|
|
40
|
+
function normalizedExcept(node, declarationName) {
|
|
41
|
+
const source = node.getSourceFile();
|
|
42
|
+
function signature(child) {
|
|
43
|
+
if (ts.isJSDoc(child) || child.kind === ts.SyntaxKind.EndOfFileToken)
|
|
44
|
+
return undefined;
|
|
45
|
+
if (child === declarationName)
|
|
46
|
+
return '*';
|
|
47
|
+
const children = child.getChildren(source);
|
|
48
|
+
if (children.length)
|
|
49
|
+
return [child.kind, ...children.map(signature).filter((part) => part !== undefined)];
|
|
50
|
+
const start = ts.isJsxText(child) ? child.getFullStart() : child.getStart(source);
|
|
51
|
+
return [child.kind, source.text.slice(start, child.getEnd())];
|
|
52
|
+
}
|
|
53
|
+
return JSON.stringify(signature(node));
|
|
54
|
+
}
|
|
55
|
+
export function sourceSpan(node) {
|
|
56
|
+
return { path: repositoryPath(node.getSourceFile().fileName) ?? node.getSourceFile().fileName, start: node.getStart(), end: node.getEnd() };
|
|
57
|
+
}
|
|
58
|
+
function moduleId(path) {
|
|
59
|
+
return `${path}#<module>`;
|
|
60
|
+
}
|
|
61
|
+
function declarationKey(node) {
|
|
62
|
+
return `${node.getSourceFile().fileName}:${node.pos}:${node.end}`;
|
|
63
|
+
}
|
|
64
|
+
function declarationName(node) {
|
|
65
|
+
if (!node.name)
|
|
66
|
+
return undefined;
|
|
67
|
+
if (ts.isIdentifier(node.name) || ts.isStringLiteral(node.name) || ts.isNumericLiteral(node.name) || ts.isPrivateIdentifier(node.name))
|
|
68
|
+
return node.name.text;
|
|
69
|
+
if (ts.isComputedPropertyName(node.name) && ts.isStringLiteralLike(node.name.expression))
|
|
70
|
+
return node.name.expression.text;
|
|
71
|
+
if (ts.isComputedPropertyName(node.name))
|
|
72
|
+
return node.name.getText();
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
function isDefault(node) {
|
|
76
|
+
return ts.canHaveModifiers(node) && (ts.getModifiers(node)?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword) ?? false);
|
|
77
|
+
}
|
|
78
|
+
function isStatic(node) {
|
|
79
|
+
return ts.canHaveModifiers(node) && (ts.getModifiers(node)?.some((modifier) => modifier.kind === ts.SyntaxKind.StaticKeyword) ?? false);
|
|
80
|
+
}
|
|
81
|
+
function isSharedBinding(node) {
|
|
82
|
+
if (ts.isPropertyDeclaration(node))
|
|
83
|
+
return isStatic(node) && !node.modifiers?.some((entry) => entry.kind === ts.SyntaxKind.ReadonlyKeyword);
|
|
84
|
+
if (!ts.isVariableDeclaration(node) || !ts.isVariableDeclarationList(node.parent) || (node.parent.flags & ts.NodeFlags.Const))
|
|
85
|
+
return false;
|
|
86
|
+
if (!ts.isVariableStatement(node.parent.parent))
|
|
87
|
+
return false;
|
|
88
|
+
const container = node.parent.parent.parent;
|
|
89
|
+
return ts.isSourceFile(container) || ts.isModuleBlock(container);
|
|
90
|
+
}
|
|
91
|
+
function stateAccess(node) {
|
|
92
|
+
let receiver = node;
|
|
93
|
+
while ((ts.isPropertyAccessExpression(receiver.parent) || ts.isElementAccessExpression(receiver.parent)) && receiver.parent.expression === receiver)
|
|
94
|
+
receiver = receiver.parent;
|
|
95
|
+
const parent = receiver.parent;
|
|
96
|
+
if (ts.isBinaryExpression(parent) && parent.left === receiver && parent.operatorToken.kind >= ts.SyntaxKind.FirstAssignment && parent.operatorToken.kind <= ts.SyntaxKind.LastAssignment) {
|
|
97
|
+
return { access: parent.operatorToken.kind === ts.SyntaxKind.EqualsToken ? 'write' : 'read_write', detail: parent };
|
|
98
|
+
}
|
|
99
|
+
if ((ts.isPrefixUnaryExpression(parent) || ts.isPostfixUnaryExpression(parent)) && (parent.operator === ts.SyntaxKind.PlusPlusToken || parent.operator === ts.SyntaxKind.MinusMinusToken)) {
|
|
100
|
+
return { access: 'read_write', detail: parent };
|
|
101
|
+
}
|
|
102
|
+
if (ts.isDeleteExpression(parent))
|
|
103
|
+
return { access: 'write', detail: parent };
|
|
104
|
+
return { access: 'read' };
|
|
105
|
+
}
|
|
106
|
+
function patternNames(pattern) {
|
|
107
|
+
if (ts.isIdentifier(pattern))
|
|
108
|
+
return [pattern.text];
|
|
109
|
+
return pattern.elements.flatMap((element) => ts.isBindingElement(element) ? patternNames(element.name) : []);
|
|
110
|
+
}
|
|
111
|
+
function functionParts(node) {
|
|
112
|
+
if (!node.body)
|
|
113
|
+
return { signature: normalized(node), implementation: '' };
|
|
114
|
+
const header = node.getText().slice(0, node.body.getStart() - node.getStart());
|
|
115
|
+
return { signature: scan(header).map((part) => part.key).join('\u0000'), implementation: normalized(node.body) };
|
|
116
|
+
}
|
|
117
|
+
function relevantPragmas(text) {
|
|
118
|
+
return [...text.matchAll(/(?:^#![^\r\n]*|\/\/[^\r\n]*|\/\*[\s\S]*?\*\/)/gmu)]
|
|
119
|
+
.map((match) => match[0])
|
|
120
|
+
.filter((comment) => /@(?:ts-(?:check|nocheck|ignore|expect-error)|jsx(?:ImportSource|Runtime|Frag)?|vite-ignore|webpack\w*)\b|@__PURE__|#__PURE__|<reference\b|^#!/u.test(comment))
|
|
121
|
+
.map((comment) => comment.trim());
|
|
122
|
+
}
|
|
123
|
+
function isModuleStatement(statement) {
|
|
124
|
+
return !ts.isFunctionDeclaration(statement) && !ts.isInterfaceDeclaration(statement) && !ts.isTypeAliasDeclaration(statement);
|
|
125
|
+
}
|
|
126
|
+
export function moduleFingerprint(file) {
|
|
127
|
+
const statements = file.statements.filter(isModuleStatement).map((statement) => {
|
|
128
|
+
if (!ts.isVariableStatement(statement))
|
|
129
|
+
return normalized(statement);
|
|
130
|
+
// Each initializer has its own symbol. The module also observes which bindings initialize first.
|
|
131
|
+
const { declarationList } = statement;
|
|
132
|
+
return [declarationList.flags & ts.NodeFlags.BlockScoped, declarationList.declarations.map(({ name }) => normalized(name))];
|
|
133
|
+
});
|
|
134
|
+
return JSON.stringify([statements, relevantPragmas(file.text)]);
|
|
135
|
+
}
|
|
136
|
+
export function isFormattingOnly(base, head) {
|
|
137
|
+
return !!base && !!head && base.file.statements.length === head.file.statements.length &&
|
|
138
|
+
base.file.statements.every((node, index) => normalized(node) === normalized(head.file.statements[index])) &&
|
|
139
|
+
JSON.stringify(relevantPragmas(base.file.text)) === JSON.stringify(relevantPragmas(head.file.text));
|
|
140
|
+
}
|
|
141
|
+
function getStructure(node, implementation) {
|
|
142
|
+
const name = node.name;
|
|
143
|
+
return digest(JSON.stringify([normalizedExcept(node, name), implementation]));
|
|
144
|
+
}
|
|
145
|
+
function typeOf(symbol, node, checker) {
|
|
146
|
+
return checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration ?? node);
|
|
147
|
+
}
|
|
148
|
+
function resolveAlias(symbol, checker) {
|
|
149
|
+
if (!symbol || !(symbol.flags & ts.SymbolFlags.Alias))
|
|
150
|
+
return symbol;
|
|
151
|
+
return checker.getAliasedSymbol(symbol);
|
|
152
|
+
}
|
|
153
|
+
function entryParameters(symbol, source) {
|
|
154
|
+
const signatures = typeOf(symbol, source.file, source.checker).getCallSignatures();
|
|
155
|
+
const parameters = signatures[0]?.getParameters();
|
|
156
|
+
return parameters?.map((parameter) => {
|
|
157
|
+
const declaration = parameter.valueDeclaration ?? parameter.declarations?.[0];
|
|
158
|
+
return declaration ? declaration.getText() : parameter.getName();
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
export class IndexBuilder {
|
|
162
|
+
snapshot;
|
|
163
|
+
project;
|
|
164
|
+
symbols = new Map();
|
|
165
|
+
publicEntries = new Map();
|
|
166
|
+
edges = [];
|
|
167
|
+
effects = new Map();
|
|
168
|
+
unknown = [];
|
|
169
|
+
owners = new Map();
|
|
170
|
+
edgeKeys = new Set();
|
|
171
|
+
constructor(snapshot, project) {
|
|
172
|
+
this.snapshot = snapshot;
|
|
173
|
+
this.project = project;
|
|
174
|
+
}
|
|
175
|
+
build() {
|
|
176
|
+
for (const [path, source] of this.project.sources) {
|
|
177
|
+
const implementation = moduleFingerprint(source.file);
|
|
178
|
+
this.register(path, '<module>', 'module', source.file, source, '', implementation);
|
|
179
|
+
for (const statement of source.file.statements)
|
|
180
|
+
this.collectDeclaration(statement, path, source);
|
|
181
|
+
}
|
|
182
|
+
for (const [path, source] of this.project.sources) {
|
|
183
|
+
this.collectExports(path, source);
|
|
184
|
+
this.collectDependencies(source.file, moduleId(path), source);
|
|
185
|
+
}
|
|
186
|
+
return this;
|
|
187
|
+
}
|
|
188
|
+
recordEffect(owner, node, effect) {
|
|
189
|
+
const symbol = this.symbols.get(owner);
|
|
190
|
+
const entries = this.effects.get(owner) ?? [];
|
|
191
|
+
const location = sourceSpan(node);
|
|
192
|
+
const { line } = node.getSourceFile().getLineAndCharacterOfPosition(location.start);
|
|
193
|
+
entries.push({ ...effect, source: symbol.ref, location: { ...location, line: line + 1 }, callSiteId: `${owner}@${entries.length + 1}` });
|
|
194
|
+
this.effects.set(owner, entries);
|
|
195
|
+
}
|
|
196
|
+
addUnknown(owner, node, code, detail) {
|
|
197
|
+
this.unknown.push({ from: owner, code, detail, location: sourceSpan(node) });
|
|
198
|
+
}
|
|
199
|
+
register(path, name, kind, node, source, signature, implementation, nodeOwns = true) {
|
|
200
|
+
const id = kind === 'export' ? `export:${path}#${name}` : `${path}#${name}`;
|
|
201
|
+
const existing = this.symbols.get(id);
|
|
202
|
+
const span = sourceSpan(node);
|
|
203
|
+
const ref = { id, snapshotId: this.snapshot.sha, projectPath: source.projectPath, filePath: path, qualifiedName: kind === 'export' ? `export ${name}` : name, kind, span: { start: span.start, end: span.end } };
|
|
204
|
+
const positionKey = declarationKey(node);
|
|
205
|
+
if (nodeOwns)
|
|
206
|
+
this.owners.set(positionKey, id);
|
|
207
|
+
const tokens = kind === 'module'
|
|
208
|
+
? source.file.statements.filter(isModuleStatement).flatMap((statement) => semanticTokens(statement))
|
|
209
|
+
: semanticTokens(node);
|
|
210
|
+
this.symbols.set(id, {
|
|
211
|
+
ref, node, source, tokens,
|
|
212
|
+
signature: existing ? `${existing.signature}\n${signature}` : signature,
|
|
213
|
+
implementation: implementation || existing?.implementation || '',
|
|
214
|
+
structure: getStructure(node, implementation), positionKey,
|
|
215
|
+
});
|
|
216
|
+
return id;
|
|
217
|
+
}
|
|
218
|
+
collectDeclaration(node, path, source, scope = '') {
|
|
219
|
+
const name = declarationName(node) ?? (isDefault(node) ? 'default' : undefined);
|
|
220
|
+
const qualified = name ? `${scope}${name}` : undefined;
|
|
221
|
+
if (qualified && (ts.isFunctionDeclaration(node) || ts.isMethodDeclaration(node) || ts.isAccessor(node))) {
|
|
222
|
+
const kind = ts.isFunctionDeclaration(node) ? 'function' : 'method';
|
|
223
|
+
const parts = functionParts(node);
|
|
224
|
+
const prefix = kind === 'method' && isStatic(node) ? `${scope}static.` : scope;
|
|
225
|
+
const ownName = `${prefix}${name}`;
|
|
226
|
+
this.register(path, ownName, kind, node, source, parts.signature, parts.implementation);
|
|
227
|
+
if (node.body)
|
|
228
|
+
node.body.forEachChild((child) => this.collectDeclaration(child, path, source, `${ownName}.`));
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
if (ts.isConstructorDeclaration(node)) {
|
|
232
|
+
const parts = functionParts(node);
|
|
233
|
+
this.register(path, `${scope}constructor`, 'method', node, source, parts.signature, parts.implementation);
|
|
234
|
+
if (node.body)
|
|
235
|
+
node.body.forEachChild((child) => this.collectDeclaration(child, path, source, `${scope}constructor.`));
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (ts.isVariableDeclaration(node) || ts.isPropertyDeclaration(node)) {
|
|
239
|
+
const names = ts.isVariableDeclaration(node) ? patternNames(node.name) : (name ? [name] : []);
|
|
240
|
+
const init = node.initializer;
|
|
241
|
+
const functional = init && (ts.isArrowFunction(init) || ts.isFunctionExpression(init));
|
|
242
|
+
const initializerStart = init ? init.getStart() - node.getStart() : node.getWidth();
|
|
243
|
+
const prefix = ts.isPropertyDeclaration(node) && isStatic(node) ? `${scope}static.` : scope;
|
|
244
|
+
const header = scan(node.getText().slice(0, initializerStart)).map((token) => token.key).join('\u0000');
|
|
245
|
+
for (const item of names) {
|
|
246
|
+
const ownName = `${prefix}${item}`;
|
|
247
|
+
const func = functional ? functionParts(init) : undefined;
|
|
248
|
+
this.register(path, ownName, func ? 'function' : 'variable', node, source, header + (func?.signature ?? ''), func?.implementation ?? (init ? normalized(init) : ''));
|
|
249
|
+
if (functional && init.body)
|
|
250
|
+
init.body.forEachChild((child) => this.collectDeclaration(child, path, source, `${ownName}.`));
|
|
251
|
+
}
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
if (qualified && (ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node) || ts.isEnumDeclaration(node))) {
|
|
255
|
+
this.register(path, qualified, 'type', node, source, normalized(node), '');
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (qualified && (ts.isClassDeclaration(node) || ts.isModuleDeclaration(node))) {
|
|
259
|
+
const first = ts.isClassDeclaration(node) ? node.members.pos : node.body?.getStart();
|
|
260
|
+
const header = first === undefined ? node.getText() : node.getSourceFile().text.slice(node.getStart(), first);
|
|
261
|
+
this.register(path, qualified, ts.isClassDeclaration(node) ? 'class' : 'namespace', node, source, scan(header).map((token) => token.key).join('\u0000'), '');
|
|
262
|
+
const members = ts.isClassDeclaration(node) ? node.members : node.body && ts.isModuleBlock(node.body) ? node.body.statements : [];
|
|
263
|
+
for (const child of members)
|
|
264
|
+
this.collectDeclaration(child, path, source, `${qualified}.`);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (ts.isExportAssignment(node) && (ts.isArrowFunction(node.expression) || ts.isFunctionExpression(node.expression))) {
|
|
268
|
+
const parts = functionParts(node.expression);
|
|
269
|
+
this.register(path, 'default', 'function', node.expression, source, parts.signature, parts.implementation);
|
|
270
|
+
node.expression.body.forEachChild((child) => this.collectDeclaration(child, path, source, 'default.'));
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
node.forEachChild((child) => this.collectDeclaration(child, path, source, scope));
|
|
274
|
+
}
|
|
275
|
+
collectExports(path, source) {
|
|
276
|
+
const symbol = source.checker.getSymbolAtLocation(source.file);
|
|
277
|
+
if (!symbol)
|
|
278
|
+
return;
|
|
279
|
+
for (const exported of source.checker.getExportsOfModule(symbol)) {
|
|
280
|
+
const name = exported.getName();
|
|
281
|
+
const original = resolveAlias(exported, source.checker);
|
|
282
|
+
if (!original)
|
|
283
|
+
continue;
|
|
284
|
+
const local = exported.declarations?.find((entry) => entry.getSourceFile() === source.file);
|
|
285
|
+
const typeOnly = local && (ts.isExportSpecifier(local) && (local.isTypeOnly || local.parent.parent.isTypeOnly));
|
|
286
|
+
const origin = original.valueDeclaration ?? original.declarations?.[0];
|
|
287
|
+
const declaration = local ?? origin ?? source.file;
|
|
288
|
+
const owner = this.ownerForSymbol(original);
|
|
289
|
+
const filePath = origin ? repositoryPath(origin.getSourceFile().fileName) : undefined;
|
|
290
|
+
const location = declaration.getSourceFile() === source.file ? declaration : source.file;
|
|
291
|
+
const id = this.register(path, name, 'export', location, source, `${name}:${owner ?? filePath ?? 'unresolved'}`, '', false);
|
|
292
|
+
this.addEdge(id, moduleId(path), 'imports', sourceSpan(location));
|
|
293
|
+
if (owner)
|
|
294
|
+
this.addEdge(id, owner, filePath === path && exported === original ? 'references' : 'reexports', sourceSpan(location));
|
|
295
|
+
if (!owner && !typeOnly && !origin)
|
|
296
|
+
this.addUnknown(id, location, 'unresolved_export', name);
|
|
297
|
+
if (typeOnly)
|
|
298
|
+
continue;
|
|
299
|
+
const parameters = entryParameters(original, source);
|
|
300
|
+
if (!parameters || !origin || isDeclaration(path) || isDeclaration(filePath ?? ''))
|
|
301
|
+
continue;
|
|
302
|
+
const targetRef = `${path}#${name}`;
|
|
303
|
+
this.publicEntries.set(targetRef, { id, targetRef, entry: { path, exportName: name, parameters } });
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
ownerForSymbol(symbol) {
|
|
307
|
+
if (!symbol)
|
|
308
|
+
return undefined;
|
|
309
|
+
const decls = symbol.declarations ?? [];
|
|
310
|
+
return (symbol.valueDeclaration && this.owners.get(declarationKey(symbol.valueDeclaration))) ??
|
|
311
|
+
decls.map((declaration) => this.owners.get(declarationKey(declaration))).find(Boolean);
|
|
312
|
+
}
|
|
313
|
+
addEdge(from, to, kind, location) {
|
|
314
|
+
if (from === to)
|
|
315
|
+
return;
|
|
316
|
+
const key = `${from}\0${to}\0${kind}\0${location.path}\0${location.start}`;
|
|
317
|
+
if (this.edgeKeys.has(key))
|
|
318
|
+
return;
|
|
319
|
+
this.edgeKeys.add(key);
|
|
320
|
+
this.edges.push({ from, to, kind, location });
|
|
321
|
+
}
|
|
322
|
+
collectDependencies(node, parent, source) {
|
|
323
|
+
const owner = this.owners.get(declarationKey(node)) ?? parent;
|
|
324
|
+
if (owner !== parent) {
|
|
325
|
+
const enclosing = this.symbols.get(parent)?.ref.kind;
|
|
326
|
+
const declared = this.symbols.get(owner)?.ref.kind;
|
|
327
|
+
if (declared === 'variable' || (enclosing === 'class' && declared === 'method'))
|
|
328
|
+
this.addEdge(parent, owner, 'references', sourceSpan(node));
|
|
329
|
+
}
|
|
330
|
+
if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {
|
|
331
|
+
if (node.moduleSpecifier && ts.isStringLiteralLike(node.moduleSpecifier)) {
|
|
332
|
+
this.addModuleDependency(node.moduleSpecifier, node, owner, source, ts.isExportDeclaration(node) ? 'reexports' : 'imports');
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
if (ts.isImportEqualsDeclaration(node) && ts.isExternalModuleReference(node.moduleReference) &&
|
|
336
|
+
node.moduleReference.expression && ts.isStringLiteralLike(node.moduleReference.expression)) {
|
|
337
|
+
this.addModuleDependency(node.moduleReference.expression, node, owner, source, 'imports');
|
|
338
|
+
}
|
|
339
|
+
if (ts.isCallExpression(node) || ts.isNewExpression(node)) {
|
|
340
|
+
this.collectCall(node, owner, source);
|
|
341
|
+
}
|
|
342
|
+
else if (ts.isTaggedTemplateExpression(node)) {
|
|
343
|
+
this.collectTaggedCall(node, owner, source);
|
|
344
|
+
}
|
|
345
|
+
if (ts.isIdentifier(node) && this.isReferenceIdentifier(node)) {
|
|
346
|
+
const raw = source.checker.getSymbolAtLocation(node);
|
|
347
|
+
const symbol = resolveAlias(raw, source.checker);
|
|
348
|
+
const target = this.ownerForSymbol(symbol);
|
|
349
|
+
if (target) {
|
|
350
|
+
const declaration = this.symbols.get(target)?.node;
|
|
351
|
+
if (declaration && isSharedBinding(declaration)) {
|
|
352
|
+
const operation = stateAccess(node);
|
|
353
|
+
const kind = operation.access === 'read' ? 'reads' : 'writes';
|
|
354
|
+
this.addEdge(owner, target, kind, sourceSpan(node));
|
|
355
|
+
this.recordEffect(owner, node, {
|
|
356
|
+
kind: 'shared_state', operation: operation.access, resource: target,
|
|
357
|
+
access: operation.access, confidence: 'approximate',
|
|
358
|
+
arguments: operation.detail ? [argumentExpression(operation.detail)] : undefined,
|
|
359
|
+
guard: enclosingGuard(node),
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
this.addEdge(owner, target, this.referenceKind(node), sourceSpan(node));
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
node.forEachChild((child) => this.collectDependencies(child, owner, source));
|
|
368
|
+
}
|
|
369
|
+
addModuleDependency(specifier, node, owner, source, kind) {
|
|
370
|
+
const path = this.project.resolveModule(specifier, source);
|
|
371
|
+
if (path && this.symbols.has(moduleId(path)))
|
|
372
|
+
this.addEdge(owner, moduleId(path), kind, sourceSpan(node));
|
|
373
|
+
else if (!path && !specifier.text.startsWith('node:'))
|
|
374
|
+
this.addUnknown(owner, node, 'unresolved_module', specifier.text);
|
|
375
|
+
}
|
|
376
|
+
referenceKind(node) {
|
|
377
|
+
if (ts.isTypeReferenceNode(node.parent))
|
|
378
|
+
return 'type_depends_on';
|
|
379
|
+
if (ts.isExpressionWithTypeArguments(node.parent) && ts.isHeritageClause(node.parent.parent)) {
|
|
380
|
+
return node.parent.parent.token === ts.SyntaxKind.ImplementsKeyword ? 'implements' : 'inherits';
|
|
381
|
+
}
|
|
382
|
+
if (ts.isBinaryExpression(node.parent) && node.parent.left === node && node.parent.operatorToken.kind >= ts.SyntaxKind.FirstAssignment && node.parent.operatorToken.kind <= ts.SyntaxKind.LastAssignment)
|
|
383
|
+
return 'writes';
|
|
384
|
+
return 'references';
|
|
385
|
+
}
|
|
386
|
+
isReferenceIdentifier(node) {
|
|
387
|
+
const parent = node.parent;
|
|
388
|
+
if (!parent)
|
|
389
|
+
return false;
|
|
390
|
+
if (ts.isShorthandPropertyAssignment(parent))
|
|
391
|
+
return true;
|
|
392
|
+
if (parent.name === node) {
|
|
393
|
+
return ts.isPropertyAccessExpression(parent);
|
|
394
|
+
}
|
|
395
|
+
return !ts.isImportSpecifier(parent) && !ts.isExportSpecifier(parent) && !ts.isImportClause(parent) && !ts.isNamespaceImport(parent) &&
|
|
396
|
+
!(ts.isLabeledStatement(parent) && parent.label === node) &&
|
|
397
|
+
!(ts.isBreakOrContinueStatement(parent) && parent.label === node);
|
|
398
|
+
}
|
|
399
|
+
collectCall(node, owner, source) {
|
|
400
|
+
const expr = node.expression;
|
|
401
|
+
if (expr.kind === ts.SyntaxKind.ImportKeyword) {
|
|
402
|
+
const arg = node.arguments?.[0];
|
|
403
|
+
if (arg && ts.isStringLiteralLike(arg))
|
|
404
|
+
this.addModuleDependency(arg, node, owner, source, 'imports');
|
|
405
|
+
else
|
|
406
|
+
this.unresolvedCall(owner, node, 'dynamic_import');
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
const raw = resolveAlias(source.checker.getSymbolAtLocation(expr), source.checker);
|
|
410
|
+
const declaration = source.checker.getResolvedSignature(node)?.declaration;
|
|
411
|
+
const target = this.ownerForSymbol(raw) ?? (declaration && this.owners.get(declarationKey(declaration)));
|
|
412
|
+
if (target)
|
|
413
|
+
this.addEdge(owner, target, 'calls', sourceSpan(node));
|
|
414
|
+
const handled = this.modelCall(node, owner, source, raw);
|
|
415
|
+
if (!handled && !target && !isStandardLibrarySymbol(raw))
|
|
416
|
+
this.unresolvedCall(owner, node);
|
|
417
|
+
}
|
|
418
|
+
collectTaggedCall(node, owner, source) {
|
|
419
|
+
const symbol = resolveAlias(source.checker.getSymbolAtLocation(node.tag), source.checker);
|
|
420
|
+
const target = this.ownerForSymbol(symbol);
|
|
421
|
+
if (target)
|
|
422
|
+
this.addEdge(owner, target, 'calls', sourceSpan(node));
|
|
423
|
+
else
|
|
424
|
+
this.unresolvedCall(owner, node, 'tagged_template_effect_unverified');
|
|
425
|
+
}
|
|
426
|
+
unresolvedCall(owner, node, code = 'unresolved_call') {
|
|
427
|
+
this.addUnknown(owner, node, code);
|
|
428
|
+
this.recordEffect(owner, node, { kind: 'unknown', operation: 'call', resource: null, access: 'unknown', confidence: 'unknown' });
|
|
429
|
+
}
|
|
430
|
+
modelCall(node, owner, source, symbol) {
|
|
431
|
+
const details = resolveEffect(node, source, symbol);
|
|
432
|
+
if (!details)
|
|
433
|
+
return false;
|
|
434
|
+
for (const detail of details) {
|
|
435
|
+
this.recordEffect(owner, node, detail);
|
|
436
|
+
if (detail.kind === 'unknown')
|
|
437
|
+
this.addUnknown(owner, node, 'effect_unverified', detail.operation);
|
|
438
|
+
}
|
|
439
|
+
return true;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
function isStandardLibrarySymbol(symbol) {
|
|
443
|
+
return !!symbol?.declarations?.length && symbol.declarations.every((declaration) => isCompilerLib(declaration.getSourceFile().fileName));
|
|
444
|
+
}
|
|
445
|
+
function importedModules(symbol) {
|
|
446
|
+
const modules = new Set();
|
|
447
|
+
for (const decl of symbol?.declarations ?? []) {
|
|
448
|
+
for (let node = decl; node; node = node.parent) {
|
|
449
|
+
if (ts.isImportDeclaration(node) && ts.isStringLiteralLike(node.moduleSpecifier))
|
|
450
|
+
modules.add(node.moduleSpecifier.text);
|
|
451
|
+
if (ts.isSourceFile(node) || ts.isImportDeclaration(node))
|
|
452
|
+
break;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
return modules;
|
|
456
|
+
}
|
|
457
|
+
function isPrismaModule(name) {
|
|
458
|
+
return name === '@prisma/client' || name.startsWith('@prisma/client/');
|
|
459
|
+
}
|
|
460
|
+
function isPrismaDeclaration(decl) {
|
|
461
|
+
const file = decl.getSourceFile();
|
|
462
|
+
const path = repositoryPath(file.fileName) ?? file.fileName;
|
|
463
|
+
if (/(?:^|\/)(?:@prisma\/client|\.prisma\/client)(?:\/|$)/.test(path))
|
|
464
|
+
return true;
|
|
465
|
+
// Prisma 7 can generate into any application-selected relative path.
|
|
466
|
+
return /(?:Prisma Client|Prisma generated|generated by Prisma)/i.test(file.text.slice(0, 500)) &&
|
|
467
|
+
/["']@prisma\/client(?:\/runtime(?:\/[^"']*)?)?["']/.test(file.text);
|
|
468
|
+
}
|
|
469
|
+
function isPrismaSymbol(symbol) {
|
|
470
|
+
return [...importedModules(symbol)].some(isPrismaModule) || !!symbol?.declarations?.some(isPrismaDeclaration);
|
|
471
|
+
}
|
|
472
|
+
function isPrismaConstructor(node, checker) {
|
|
473
|
+
const symbol = checker.getSymbolAtLocation(node);
|
|
474
|
+
const resolved = resolveAlias(symbol, checker);
|
|
475
|
+
const name = resolved?.getName() === 'unknown' ? symbol?.getName() : resolved?.getName();
|
|
476
|
+
if (name !== 'PrismaClient' && !(ts.isPropertyAccessExpression(node) && node.name.text === 'PrismaClient')) {
|
|
477
|
+
// Aliases still retain their Prisma declaration or an original imported name.
|
|
478
|
+
if (!symbol?.declarations?.some((declaration) => ts.isImportSpecifier(declaration) && (declaration.propertyName ?? declaration.name).text === 'PrismaClient'))
|
|
479
|
+
return false;
|
|
480
|
+
}
|
|
481
|
+
const receiver = ts.isPropertyAccessExpression(node) ? checker.getSymbolAtLocation(node.expression) : undefined;
|
|
482
|
+
return isPrismaSymbol(symbol) || isPrismaSymbol(resolved) || isPrismaSymbol(receiver);
|
|
483
|
+
}
|
|
484
|
+
function unwrap(expr) {
|
|
485
|
+
if (ts.isParenthesizedExpression(expr) || ts.isNonNullExpression(expr) || ts.isAsExpression(expr) || ts.isTypeAssertionExpression(expr) || ts.isSatisfiesExpression(expr))
|
|
486
|
+
return unwrap(expr.expression);
|
|
487
|
+
return expr;
|
|
488
|
+
}
|
|
489
|
+
function isPrismaReceiver(node, checker, visited = new Set()) {
|
|
490
|
+
node = unwrap(node);
|
|
491
|
+
if (ts.isNewExpression(node))
|
|
492
|
+
return isPrismaConstructor(node.expression, checker);
|
|
493
|
+
const type = checker.getTypeAtLocation(node);
|
|
494
|
+
if (isPrismaSymbol(type.aliasSymbol) || isPrismaSymbol(type.getSymbol()))
|
|
495
|
+
return true;
|
|
496
|
+
const symbol = resolveAlias(checker.getSymbolAtLocation(node), checker);
|
|
497
|
+
if (!symbol || visited.has(symbol))
|
|
498
|
+
return false;
|
|
499
|
+
visited.add(symbol);
|
|
500
|
+
const declaration = symbol.valueDeclaration;
|
|
501
|
+
if ((declaration && ts.isVariableDeclaration(declaration)) || (declaration && ts.isPropertyDeclaration(declaration))) {
|
|
502
|
+
if (declaration.initializer)
|
|
503
|
+
return isPrismaReceiver(declaration.initializer, checker, visited);
|
|
504
|
+
}
|
|
505
|
+
if (declaration && ts.isParameter(declaration)) {
|
|
506
|
+
const callback = declaration.parent;
|
|
507
|
+
const call = callback.parent;
|
|
508
|
+
return (ts.isArrowFunction(callback) || ts.isFunctionExpression(callback)) && ts.isCallExpression(call) &&
|
|
509
|
+
ts.isPropertyAccessExpression(call.expression) && call.expression.name.text === '$transaction' && isPrismaReceiver(call.expression.expression, checker, visited);
|
|
510
|
+
}
|
|
511
|
+
return false;
|
|
512
|
+
}
|
|
513
|
+
function textValue(node) {
|
|
514
|
+
if (!node)
|
|
515
|
+
return undefined;
|
|
516
|
+
const expr = unwrap(node);
|
|
517
|
+
return ts.isStringLiteralLike(expr) ? expr.text : undefined;
|
|
518
|
+
}
|
|
519
|
+
function argumentExpression(node) {
|
|
520
|
+
return semanticTokens(node, true).map((token) => token.key.slice(token.key.indexOf(':') + 1)).join(' ');
|
|
521
|
+
}
|
|
522
|
+
function propertyValue(node, name) {
|
|
523
|
+
if (!node || !ts.isObjectLiteralExpression(node))
|
|
524
|
+
return undefined;
|
|
525
|
+
return node.properties.find((property) => ts.isPropertyAssignment(property) && declarationName(property) === name)?.initializer;
|
|
526
|
+
}
|
|
527
|
+
function enclosingGuard(node) {
|
|
528
|
+
const conditions = [];
|
|
529
|
+
for (let child = node; child.parent; child = child.parent) {
|
|
530
|
+
const parent = child.parent;
|
|
531
|
+
if (ts.isIfStatement(parent) && child !== parent.expression) {
|
|
532
|
+
const guard = argumentExpression(parent.expression);
|
|
533
|
+
conditions.unshift(child === parent.thenStatement ? guard : `!(${guard})`);
|
|
534
|
+
}
|
|
535
|
+
if (ts.isConditionalExpression(parent) && child !== parent.condition) {
|
|
536
|
+
const guard = argumentExpression(parent.condition);
|
|
537
|
+
conditions.unshift(child === parent.whenTrue ? guard : `!(${guard})`);
|
|
538
|
+
}
|
|
539
|
+
if (ts.isBinaryExpression(parent) && child === parent.right &&
|
|
540
|
+
(parent.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken || parent.operatorToken.kind === ts.SyntaxKind.BarBarToken)) {
|
|
541
|
+
const guard = argumentExpression(parent.left);
|
|
542
|
+
conditions.unshift(parent.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken ? guard : `!(${guard})`);
|
|
543
|
+
}
|
|
544
|
+
if (ts.isFunctionLike(parent))
|
|
545
|
+
break;
|
|
546
|
+
}
|
|
547
|
+
return conditions.length ? conditions.join(' && ') : undefined;
|
|
548
|
+
}
|
|
549
|
+
function transactionScope(node, checker) {
|
|
550
|
+
for (let child = node; child.parent; child = child.parent) {
|
|
551
|
+
const parent = child.parent;
|
|
552
|
+
if (!ts.isCallExpression(parent) || !ts.isPropertyAccessExpression(parent.expression) || parent.expression.name.text !== '$transaction')
|
|
553
|
+
continue;
|
|
554
|
+
if (!parent.arguments.some((arg) => child === arg) || !isPrismaReceiver(parent.expression.expression, checker))
|
|
555
|
+
continue;
|
|
556
|
+
return 'prisma.$transaction';
|
|
557
|
+
}
|
|
558
|
+
return undefined;
|
|
559
|
+
}
|
|
560
|
+
const prismaReads = new Set(['findUnique', 'findUniqueOrThrow', 'findFirst', 'findFirstOrThrow', 'findMany', 'count', 'aggregate', 'groupBy']);
|
|
561
|
+
const prismaWrites = new Set(['create', 'createMany', 'createManyAndReturn', 'update', 'updateMany', 'updateManyAndReturn', 'delete', 'deleteMany']);
|
|
562
|
+
const nestedWriteKeys = new Set([...prismaWrites, 'upsert', 'connect', 'disconnect', 'connectOrCreate', 'set']);
|
|
563
|
+
function hasNestedWrite(node) {
|
|
564
|
+
if (ts.isPropertyAssignment(node) && nestedWriteKeys.has(declarationName(node) ?? '') && (ts.isObjectLiteralExpression(node.initializer) || ts.isArrayLiteralExpression(node.initializer)))
|
|
565
|
+
return true;
|
|
566
|
+
return node.forEachChild(hasNestedWrite) ?? false;
|
|
567
|
+
}
|
|
568
|
+
function resolveEffect(node, source, symbol) {
|
|
569
|
+
const { checker } = source;
|
|
570
|
+
const expr = unwrap(node.expression);
|
|
571
|
+
const access = ts.isPropertyAccessExpression(expr) ? expr : undefined;
|
|
572
|
+
const member = access?.name.text;
|
|
573
|
+
const symbolName = symbol?.getName();
|
|
574
|
+
const args = [...(node.arguments ?? [])];
|
|
575
|
+
const detail = (effect) => ({ ...effect, arguments: args.map(argumentExpression), guard: enclosingGuard(node), transactionScope: transactionScope(node, checker) });
|
|
576
|
+
const unknown = (operation, adapter) => ({ kind: 'unknown', operation, adapter, resource: null, access: 'unknown', confidence: 'unknown' });
|
|
577
|
+
if (symbolName === 'fetch' && isStandardLibrarySymbol(symbol)) {
|
|
578
|
+
const resource = textValue(args[0]) ?? null;
|
|
579
|
+
const declaredMethod = propertyValue(args[1], 'method');
|
|
580
|
+
const method = textValue(declaredMethod)?.toUpperCase() ?? (!args[1] || (ts.isObjectLiteralExpression(args[1]) && !declaredMethod && !args[1].properties.some(ts.isSpreadAssignment)) ? 'GET' : 'request');
|
|
581
|
+
return [detail({ kind: 'http', adapter: 'fetch', operation: method, resource, access: 'unknown', confidence: resource && method !== 'request' ? 'resolved' : 'approximate' })];
|
|
582
|
+
}
|
|
583
|
+
if (isStandardLibrarySymbol(symbol) && ((symbolName === 'Date' && (ts.isCallExpression(node) || !args.length)) ||
|
|
584
|
+
(member === 'now' && access?.expression.getText() === 'Date'))) {
|
|
585
|
+
return [detail({ kind: 'clock', operation: 'now', resource: 'clock', access: 'read', confidence: 'resolved' })];
|
|
586
|
+
}
|
|
587
|
+
if (isStandardLibrarySymbol(symbol) && member === 'random' && access?.expression.getText() === 'Math') {
|
|
588
|
+
return [detail({ kind: 'random', operation: 'random', resource: 'random', access: 'read', confidence: 'resolved' })];
|
|
589
|
+
}
|
|
590
|
+
if (ts.isNewExpression(node) && isPrismaConstructor(expr, checker)) {
|
|
591
|
+
return [detail({ kind: 'db', adapter: 'prisma', operation: 'initialize', resource: null, access: 'unknown', confidence: 'resolved' })];
|
|
592
|
+
}
|
|
593
|
+
if (access && member) {
|
|
594
|
+
const receiver = unwrap(access.expression);
|
|
595
|
+
if (isPrismaReceiver(receiver, checker) && member.startsWith('$')) {
|
|
596
|
+
return member === '$transaction'
|
|
597
|
+
? [detail({ kind: 'db', adapter: 'prisma', operation: member, resource: null, access: 'read_write', confidence: 'resolved' })]
|
|
598
|
+
: [detail(unknown(member, 'prisma'))];
|
|
599
|
+
}
|
|
600
|
+
const delegate = ts.isPropertyAccessExpression(receiver) ? receiver : undefined;
|
|
601
|
+
if (delegate && (isPrismaReceiver(delegate.expression, checker) || (!!symbol?.declarations?.some(isPrismaDeclaration) && isPrismaSymbol(checker.getTypeAtLocation(delegate).getSymbol())))) {
|
|
602
|
+
const model = delegate.name.text;
|
|
603
|
+
const resource = model.charAt(0).toUpperCase() + model.slice(1);
|
|
604
|
+
if (!prismaReads.has(member) && !prismaWrites.has(member) && member !== 'upsert')
|
|
605
|
+
return [detail(unknown(member, 'prisma'))];
|
|
606
|
+
const effect = detail({ kind: 'db', adapter: 'prisma', operation: member, resource, access: prismaReads.has(member) ? 'read' : member === 'upsert' ? 'read_write' : 'write', confidence: 'resolved' });
|
|
607
|
+
const data = propertyValue(args[0], 'data') ?? propertyValue(args[0], 'create') ?? propertyValue(args[0], 'update');
|
|
608
|
+
return data && hasNestedWrite(data) ? [effect, detail(unknown('nested_write', 'prisma'))] : [effect];
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
const provenance = importedModules(checker.getSymbolAtLocation(expr));
|
|
612
|
+
if (access)
|
|
613
|
+
for (const module of importedModules(checker.getSymbolAtLocation(access.expression)))
|
|
614
|
+
provenance.add(module);
|
|
615
|
+
if ([...provenance].some((name) => /^(?:node:)?fs(?:\/promises)?$/.test(name))) {
|
|
616
|
+
const operation = member ?? symbolName ?? 'file';
|
|
617
|
+
const resource = textValue(args[0]) ?? null;
|
|
618
|
+
const mode = /^(?:write|append|mkdir|rm|rmdir|rename|copy|unlink|chmod|chown|symlink|link|truncate)/.test(operation) ? 'write' : /^(?:read|stat|access|exists|realpath)/.test(operation) ? 'read' : 'unknown';
|
|
619
|
+
return [detail({ kind: 'file', operation, resource, access: mode, confidence: 'approximate' })];
|
|
620
|
+
}
|
|
621
|
+
if ([...provenance].some((name) => /^(?:node:)?(?:child_process|worker_threads)$/.test(name))) {
|
|
622
|
+
return [detail({ kind: 'process', operation: member ?? symbolName ?? 'subprocess', resource: null, access: 'write', confidence: 'approximate' })];
|
|
623
|
+
}
|
|
624
|
+
return undefined;
|
|
625
|
+
}
|
|
626
|
+
export function indexedSnapshot(snapshot, project) {
|
|
627
|
+
return new IndexBuilder(snapshot, project).build();
|
|
628
|
+
}
|
|
629
|
+
export function changedSpans(base, head) {
|
|
630
|
+
const left = base?.tokens ?? [];
|
|
631
|
+
const right = head?.tokens ?? [];
|
|
632
|
+
let prefix = 0;
|
|
633
|
+
let suffix = 0;
|
|
634
|
+
while (prefix < left.length && prefix < right.length && left[prefix].key === right[prefix].key)
|
|
635
|
+
prefix++;
|
|
636
|
+
while (suffix < left.length - prefix && suffix < right.length - prefix && left[left.length - suffix - 1].key === right[right.length - suffix - 1].key)
|
|
637
|
+
suffix++;
|
|
638
|
+
function span(symbol, tokens) {
|
|
639
|
+
if (!symbol)
|
|
640
|
+
return [];
|
|
641
|
+
const changed = tokens.slice(prefix, tokens.length - suffix);
|
|
642
|
+
if (!changed.length) {
|
|
643
|
+
if (left.length !== right.length) {
|
|
644
|
+
const nearest = tokens[Math.min(prefix, tokens.length - 1)];
|
|
645
|
+
if (nearest)
|
|
646
|
+
return [{ path: symbol.ref.filePath, start: nearest.start, end: nearest.end }];
|
|
647
|
+
}
|
|
648
|
+
return [{ path: symbol.ref.filePath, ...symbol.ref.span }];
|
|
649
|
+
}
|
|
650
|
+
return [{ path: symbol.ref.filePath, start: changed[0].start, end: changed.at(-1).end }];
|
|
651
|
+
}
|
|
652
|
+
return { baseChangedSpans: span(base, left), headChangedSpans: span(head, right) };
|
|
653
|
+
}
|
|
654
|
+
//# sourceMappingURL=static-index.js.map
|