@betterportal/framework 10.6.34 → 10.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/adapters/h3.d.ts +2 -0
- package/lib/adapters/h3.d.ts.map +1 -1
- package/lib/adapters/h3.js +237 -134
- package/lib/adapters/h3.js.map +1 -1
- package/lib/cli/bp.js +14 -0
- package/lib/cli/bp.js.map +1 -1
- package/lib/codegen/cli.js +7 -0
- package/lib/codegen/cli.js.map +1 -1
- package/lib/codegen/init.js +5 -0
- package/lib/codegen/init.js.map +1 -1
- package/lib/codegen/routeUrlPolicy.d.ts +15 -0
- package/lib/codegen/routeUrlPolicy.d.ts.map +1 -0
- package/lib/codegen/routeUrlPolicy.js +1012 -0
- package/lib/codegen/routeUrlPolicy.js.map +1 -0
- package/lib/contracts/registry.d.ts +9 -12
- package/lib/contracts/registry.d.ts.map +1 -1
- package/lib/contracts/route.d.ts +6 -27
- package/lib/contracts/route.d.ts.map +1 -1
- package/lib/contracts/route.js.map +1 -1
- package/lib/contracts/routeUrl.d.ts +66 -0
- package/lib/contracts/routeUrl.d.ts.map +1 -0
- package/lib/contracts/routeUrl.js +2 -0
- package/lib/contracts/routeUrl.js.map +1 -0
- package/lib/contracts/streaming.d.ts +6 -4
- package/lib/contracts/streaming.d.ts.map +1 -1
- package/lib/contracts/streaming.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/runtime/auth/redirect.d.ts +13 -2
- package/lib/runtime/auth/redirect.d.ts.map +1 -1
- package/lib/runtime/auth/redirect.js +1 -1
- package/lib/runtime/auth/redirect.js.map +1 -1
- package/lib/runtime/configProvider.d.ts +8 -0
- package/lib/runtime/configProvider.d.ts.map +1 -1
- package/lib/runtime/configProvider.js +16 -0
- package/lib/runtime/configProvider.js.map +1 -1
- package/lib/runtime/llms.js +6 -6
- package/lib/runtime/llms.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,1012 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
const legacyFields = new Set(["accountUrl", "loginUrl", "logoutUrl", "socialUrl", "firstAdminUrl", "nextUrl", "mailNextUrl", "sessionNextUrl", "previewPath", "tenantsPath"]);
|
|
5
|
+
const internalPaths = new Set(["apiPath", "viewPath", "uiPath", "absoluteApiPath", "absoluteViewPath"]);
|
|
6
|
+
/** Reject the old routing API and renderer-only URL payloads even in loosely typed source. */
|
|
7
|
+
export function inspectRouteUrlSource(file, source) {
|
|
8
|
+
const tree = ts.createSourceFile(file, source, ts.ScriptTarget.Latest, true, file.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
9
|
+
const errors = [];
|
|
10
|
+
const rendererFunctions = new Set();
|
|
11
|
+
const declarations = new Map();
|
|
12
|
+
const selections = new Map();
|
|
13
|
+
const initializers = new Map();
|
|
14
|
+
const lengthTypes = new Map();
|
|
15
|
+
const stringTypes = new Map();
|
|
16
|
+
const pendingMutations = [];
|
|
17
|
+
const functions = new Map();
|
|
18
|
+
const propertyKey = (name) => {
|
|
19
|
+
if (ts.isIdentifier(name) || ts.isStringLiteralLike(name) || ts.isNumericLiteral(name))
|
|
20
|
+
return name.text;
|
|
21
|
+
if (ts.isComputedPropertyName(name) && (ts.isStringLiteralLike(name.expression) || ts.isNumericLiteral(name.expression)))
|
|
22
|
+
return name.expression.text;
|
|
23
|
+
return undefined;
|
|
24
|
+
};
|
|
25
|
+
const collect = (node) => {
|
|
26
|
+
if (file.includes("_renderer.") && ts.isFunctionLike(node)) {
|
|
27
|
+
const declaration = ts.isVariableDeclaration(node.parent) ? node.parent : undefined;
|
|
28
|
+
const name = ts.isFunctionDeclaration(node) ? node.name?.text : declaration && ts.isIdentifier(declaration.name) ? declaration.name.text : undefined;
|
|
29
|
+
const owner = declaration?.parent.parent;
|
|
30
|
+
const exported = ts.isFunctionDeclaration(node) ? ts.getModifiers(node)?.some(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword)
|
|
31
|
+
: owner && ts.isVariableStatement(owner) && ts.getModifiers(owner)?.some(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword);
|
|
32
|
+
if (name?.startsWith("render") && exported)
|
|
33
|
+
rendererFunctions.add(node);
|
|
34
|
+
}
|
|
35
|
+
if ((ts.isVariableDeclaration(node) || ts.isParameter(node)) && ts.isIdentifier(node.name)
|
|
36
|
+
&& node.type && [ts.SyntaxKind.StringKeyword, ts.SyntaxKind.ArrayType, ts.SyntaxKind.TupleType].includes(node.type.kind)) {
|
|
37
|
+
let scope = node.parent;
|
|
38
|
+
while (!ts.isBlock(scope) && !ts.isSourceFile(scope) && !(ts.isParameter(node) && ts.isFunctionLike(scope)))
|
|
39
|
+
scope = scope.parent;
|
|
40
|
+
const bindings = lengthTypes.get(scope) ?? new Set();
|
|
41
|
+
bindings.add(node.name.text);
|
|
42
|
+
lengthTypes.set(scope, bindings);
|
|
43
|
+
if (node.type.kind === ts.SyntaxKind.StringKeyword) {
|
|
44
|
+
const strings = stringTypes.get(scope) ?? new Set();
|
|
45
|
+
strings.add(node.name.text);
|
|
46
|
+
stringTypes.set(scope, strings);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer) {
|
|
50
|
+
let scope = node.parent;
|
|
51
|
+
while (!ts.isBlock(scope) && !ts.isSourceFile(scope))
|
|
52
|
+
scope = scope.parent;
|
|
53
|
+
const bindings = initializers.get(scope) ?? new Map();
|
|
54
|
+
bindings.set(node.name.text, node.initializer);
|
|
55
|
+
initializers.set(scope, bindings);
|
|
56
|
+
}
|
|
57
|
+
if ((ts.isVariableDeclaration(node) && node.initializer || ts.isParameter(node)) && ts.isObjectBindingPattern(node.name)) {
|
|
58
|
+
let scope = node.parent;
|
|
59
|
+
while (!ts.isBlock(scope) && !ts.isSourceFile(scope) && !(ts.isParameter(node) && ts.isFunctionLike(scope)))
|
|
60
|
+
scope = scope.parent;
|
|
61
|
+
const bindings = selections.get(scope) ?? new Map();
|
|
62
|
+
for (const item of node.name.elements) {
|
|
63
|
+
if (!ts.isIdentifier(item.name))
|
|
64
|
+
continue;
|
|
65
|
+
const key = item.propertyName ?? item.name;
|
|
66
|
+
if (!ts.isIdentifier(key) && !ts.isStringLiteralLike(key))
|
|
67
|
+
continue;
|
|
68
|
+
bindings.set(item.name.text, { expression: node.initializer ?? node.name, field: key.text, rest: !!item.dotDotDotToken });
|
|
69
|
+
}
|
|
70
|
+
selections.set(scope, bindings);
|
|
71
|
+
}
|
|
72
|
+
if (ts.isVariableDeclaration(node) && ts.isArrayBindingPattern(node.name) && node.initializer) {
|
|
73
|
+
let scope = node.parent;
|
|
74
|
+
while (!ts.isBlock(scope) && !ts.isSourceFile(scope))
|
|
75
|
+
scope = scope.parent;
|
|
76
|
+
const bindings = selections.get(scope) ?? new Map();
|
|
77
|
+
for (const [index, item] of node.name.elements.entries()) {
|
|
78
|
+
if (!ts.isBindingElement(item) || !ts.isIdentifier(item.name))
|
|
79
|
+
continue;
|
|
80
|
+
bindings.set(item.name.text, { expression: node.initializer, field: String(index), rest: !!item.dotDotDotToken, element: index });
|
|
81
|
+
}
|
|
82
|
+
selections.set(scope, bindings);
|
|
83
|
+
}
|
|
84
|
+
const declare = (name) => {
|
|
85
|
+
let scope = node.parent;
|
|
86
|
+
while (!ts.isBlock(scope) && !ts.isSourceFile(scope))
|
|
87
|
+
scope = scope.parent;
|
|
88
|
+
const names = declarations.get(scope) ?? new Set();
|
|
89
|
+
names.add(name);
|
|
90
|
+
declarations.set(scope, names);
|
|
91
|
+
};
|
|
92
|
+
if ((ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node)) && node.name)
|
|
93
|
+
declare(node.name.text);
|
|
94
|
+
if (ts.isFunctionDeclaration(node) && node.name) {
|
|
95
|
+
let scope = node.parent;
|
|
96
|
+
while (!ts.isBlock(scope) && !ts.isSourceFile(scope))
|
|
97
|
+
scope = scope.parent;
|
|
98
|
+
const bindings = functions.get(scope) ?? new Map();
|
|
99
|
+
bindings.set(node.name.text, node);
|
|
100
|
+
functions.set(scope, bindings);
|
|
101
|
+
}
|
|
102
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name))
|
|
103
|
+
declare(node.name.text);
|
|
104
|
+
if (ts.isImportDeclaration(node) && !node.importClause?.isTypeOnly) {
|
|
105
|
+
if (node.importClause?.name)
|
|
106
|
+
declare(node.importClause.name.text);
|
|
107
|
+
const bindings = node.importClause?.namedBindings;
|
|
108
|
+
if (bindings && ts.isNamespaceImport(bindings))
|
|
109
|
+
declare(bindings.name.text);
|
|
110
|
+
if (bindings && ts.isNamedImports(bindings))
|
|
111
|
+
for (const binding of bindings.elements)
|
|
112
|
+
if (!binding.isTypeOnly)
|
|
113
|
+
declare(binding.name.text);
|
|
114
|
+
}
|
|
115
|
+
if (ts.isBinaryExpression(node) && [ts.SyntaxKind.EqualsToken, ts.SyntaxKind.PlusEqualsToken,
|
|
116
|
+
ts.SyntaxKind.BarBarEqualsToken, ts.SyntaxKind.AmpersandAmpersandEqualsToken,
|
|
117
|
+
ts.SyntaxKind.QuestionQuestionEqualsToken].includes(node.operatorToken.kind)) {
|
|
118
|
+
const assigned = (target, value) => {
|
|
119
|
+
if (ts.isParenthesizedExpression(target)) {
|
|
120
|
+
assigned(target.expression, value);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (ts.isArrayLiteralExpression(target)) {
|
|
124
|
+
for (const [index, item] of target.elements.entries()) {
|
|
125
|
+
if (ts.isOmittedExpression(item))
|
|
126
|
+
continue;
|
|
127
|
+
if (ts.isSpreadElement(item)) {
|
|
128
|
+
const values = ts.isArrayLiteralExpression(value) ? value.elements.slice(index) : [value];
|
|
129
|
+
pendingMutations.push({ target: item.expression, values });
|
|
130
|
+
}
|
|
131
|
+
else
|
|
132
|
+
assigned(item, ts.isArrayLiteralExpression(value) && !value.elements.some(ts.isSpreadElement)
|
|
133
|
+
? value.elements[index] ?? ts.factory.createIdentifier("undefined") : value);
|
|
134
|
+
}
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (ts.isObjectLiteralExpression(target)) {
|
|
138
|
+
for (const item of target.properties) {
|
|
139
|
+
if (ts.isSpreadAssignment(item)) {
|
|
140
|
+
pendingMutations.push({ target: item.expression, values: [value] });
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (!ts.isPropertyAssignment(item) && !ts.isShorthandPropertyAssignment(item))
|
|
144
|
+
continue;
|
|
145
|
+
const name = propertyKey(item.name);
|
|
146
|
+
if (name === undefined)
|
|
147
|
+
continue;
|
|
148
|
+
const source = ts.isObjectLiteralExpression(value) ? value.properties.find(property => property.name && propertyKey(property.name) === name) : undefined;
|
|
149
|
+
const selected = source && ts.isPropertyAssignment(source) ? source.initializer : source && ts.isShorthandPropertyAssignment(source) ? source.name : ts.factory.createPropertyAccessExpression(value, name);
|
|
150
|
+
assigned(ts.isPropertyAssignment(item) ? item.initializer : item.name, selected);
|
|
151
|
+
}
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
pendingMutations.push({ target, values: [value] });
|
|
155
|
+
};
|
|
156
|
+
assigned(node.left, node.right);
|
|
157
|
+
}
|
|
158
|
+
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression)) {
|
|
159
|
+
const method = node.expression.name.text;
|
|
160
|
+
if (["push", "unshift", "splice", "fill"].includes(method))
|
|
161
|
+
pendingMutations.push({
|
|
162
|
+
target: node.expression.expression,
|
|
163
|
+
values: method === "splice" ? node.arguments.slice(2) : method === "fill" ? node.arguments.slice(0, 1) : node.arguments
|
|
164
|
+
});
|
|
165
|
+
if (["set", "append", "add"].includes(method))
|
|
166
|
+
pendingMutations.push({
|
|
167
|
+
target: node.expression.expression, values: node.arguments, collection: true
|
|
168
|
+
});
|
|
169
|
+
if (["defineProperty", "defineProperties"].includes(method) && node.arguments[0])
|
|
170
|
+
pendingMutations.push({
|
|
171
|
+
target: node.arguments[0], values: node.arguments.slice(method === "defineProperty" ? 2 : 1), global: node.expression.expression
|
|
172
|
+
});
|
|
173
|
+
if (method === "assign" && node.arguments[0])
|
|
174
|
+
pendingMutations.push({
|
|
175
|
+
target: node.arguments[0], values: node.arguments.slice(1), global: node.expression.expression
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
ts.forEachChild(node, collect);
|
|
179
|
+
};
|
|
180
|
+
collect(tree);
|
|
181
|
+
const references = new Map();
|
|
182
|
+
const reference = (expression, seen = new Set()) => {
|
|
183
|
+
if (seen.has(expression))
|
|
184
|
+
return undefined;
|
|
185
|
+
if (references.has(expression))
|
|
186
|
+
return references.get(expression);
|
|
187
|
+
const next = new Set([...seen, expression]);
|
|
188
|
+
if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isTypeAssertionExpression(expression)
|
|
189
|
+
|| ts.isNonNullExpression(expression) || ts.isSatisfiesExpression(expression)
|
|
190
|
+
|| ts.isPropertyAccessExpression(expression) || ts.isElementAccessExpression(expression))
|
|
191
|
+
return reference(expression.expression, next);
|
|
192
|
+
if (!ts.isIdentifier(expression))
|
|
193
|
+
return undefined;
|
|
194
|
+
let scope = expression.parent;
|
|
195
|
+
while (scope) {
|
|
196
|
+
if (declarations.get(scope)?.has(expression.text) || selections.get(scope)?.has(expression.text)) {
|
|
197
|
+
const initializer = initializers.get(scope)?.get(expression.text);
|
|
198
|
+
const selected = selections.get(scope)?.get(expression.text);
|
|
199
|
+
const alias = initializer ? reference(initializer, next) : selected ? reference(selected.expression, next) : undefined;
|
|
200
|
+
const binding = alias ?? { scope, name: expression.text };
|
|
201
|
+
references.set(expression, binding);
|
|
202
|
+
return binding;
|
|
203
|
+
}
|
|
204
|
+
if (ts.isFunctionLike(scope) && scope.parameters.some(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === expression.text))
|
|
205
|
+
return undefined;
|
|
206
|
+
scope = scope.parent;
|
|
207
|
+
}
|
|
208
|
+
return undefined;
|
|
209
|
+
};
|
|
210
|
+
const mutations = new Map();
|
|
211
|
+
for (const mutation of pendingMutations) {
|
|
212
|
+
const binding = reference(mutation.target);
|
|
213
|
+
if (!binding)
|
|
214
|
+
continue;
|
|
215
|
+
const bindings = mutations.get(binding.scope) ?? new Map();
|
|
216
|
+
bindings.set(binding.name, [...bindings.get(binding.name) ?? [], mutation]);
|
|
217
|
+
mutations.set(binding.scope, bindings);
|
|
218
|
+
}
|
|
219
|
+
const rendererPayload = (expression, seen = new Set()) => {
|
|
220
|
+
if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isTypeAssertionExpression(expression)
|
|
221
|
+
|| ts.isNonNullExpression(expression) || ts.isSatisfiesExpression(expression))
|
|
222
|
+
return rendererPayload(expression.expression, seen);
|
|
223
|
+
if (!ts.isIdentifier(expression) || seen.has(expression.text))
|
|
224
|
+
return false;
|
|
225
|
+
let scope = expression.parent;
|
|
226
|
+
while (scope) {
|
|
227
|
+
const initializer = initializers.get(scope)?.get(expression.text);
|
|
228
|
+
if (initializer)
|
|
229
|
+
return rendererPayload(initializer, new Set([...seen, expression.text]));
|
|
230
|
+
if (ts.isFunctionLike(scope) && scope.parameters.some(param => ts.isIdentifier(param.name) && param.name.text === expression.text)) {
|
|
231
|
+
const input = scope.parameters[0]?.name;
|
|
232
|
+
return rendererFunctions.has(scope) && input !== undefined && ts.isIdentifier(input) && input.text === expression.text;
|
|
233
|
+
}
|
|
234
|
+
scope = scope.parent;
|
|
235
|
+
}
|
|
236
|
+
return false;
|
|
237
|
+
};
|
|
238
|
+
const collection = (expression, seen = new Set()) => {
|
|
239
|
+
if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isNonNullExpression(expression))
|
|
240
|
+
return collection(expression.expression, seen);
|
|
241
|
+
if (ts.isNewExpression(expression))
|
|
242
|
+
return ["Map", "Set", "Headers", "URLSearchParams", "FormData"].some(name => isGlobal(expression.expression, name));
|
|
243
|
+
if (!ts.isIdentifier(expression) || seen.has(expression.text))
|
|
244
|
+
return false;
|
|
245
|
+
let scope = expression.parent;
|
|
246
|
+
while (scope) {
|
|
247
|
+
const initializer = initializers.get(scope)?.get(expression.text);
|
|
248
|
+
if (initializer)
|
|
249
|
+
return collection(initializer, new Set([...seen, expression.text]));
|
|
250
|
+
if (ts.isFunctionLike(scope) && scope.parameters.some(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === expression.text))
|
|
251
|
+
return false;
|
|
252
|
+
scope = scope.parent;
|
|
253
|
+
}
|
|
254
|
+
return false;
|
|
255
|
+
};
|
|
256
|
+
const report = (node, message) => {
|
|
257
|
+
const position = tree.getLineAndCharacterOfPosition(node.getStart(tree));
|
|
258
|
+
errors.push({ file: `${file}:${position.line + 1}:${position.character + 1}`, message, severity: "error" });
|
|
259
|
+
};
|
|
260
|
+
const resolveCallback = (expression, seen = new Set()) => {
|
|
261
|
+
if (!expression)
|
|
262
|
+
return undefined;
|
|
263
|
+
if (ts.isArrowFunction(expression) || ts.isFunctionExpression(expression) || ts.isFunctionDeclaration(expression) || ts.isMethodDeclaration(expression))
|
|
264
|
+
return expression;
|
|
265
|
+
if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isNonNullExpression(expression))
|
|
266
|
+
return resolveCallback(expression.expression, seen);
|
|
267
|
+
if (ts.isPropertyAccessExpression(expression) || ts.isElementAccessExpression(expression) && ts.isStringLiteralLike(expression.argumentExpression)) {
|
|
268
|
+
const field = ts.isPropertyAccessExpression(expression) ? expression.name.text : expression.argumentExpression.text;
|
|
269
|
+
return resolveCallback(selectedProperty(expression.expression, field), seen);
|
|
270
|
+
}
|
|
271
|
+
if (!ts.isIdentifier(expression) || seen.has(expression.text))
|
|
272
|
+
return undefined;
|
|
273
|
+
let scope = expression.parent;
|
|
274
|
+
while (scope) {
|
|
275
|
+
const initializer = initializers.get(scope)?.get(expression.text);
|
|
276
|
+
if (initializer)
|
|
277
|
+
return resolveCallback(initializer, new Set([...seen, expression.text]));
|
|
278
|
+
const declaration = functions.get(scope)?.get(expression.text);
|
|
279
|
+
if (declaration)
|
|
280
|
+
return declaration;
|
|
281
|
+
if (declarations.get(scope)?.has(expression.text) || selections.get(scope)?.has(expression.text))
|
|
282
|
+
return undefined;
|
|
283
|
+
if (ts.isFunctionLike(scope) && scope.parameters.some(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === expression.text))
|
|
284
|
+
return undefined;
|
|
285
|
+
scope = scope.parent;
|
|
286
|
+
}
|
|
287
|
+
return undefined;
|
|
288
|
+
};
|
|
289
|
+
const arrayValues = (expression, seen = new Set()) => {
|
|
290
|
+
if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isNonNullExpression(expression))
|
|
291
|
+
return arrayValues(expression.expression, seen);
|
|
292
|
+
if (ts.isArrayLiteralExpression(expression) && !expression.elements.some(ts.isSpreadElement))
|
|
293
|
+
return expression.elements;
|
|
294
|
+
if (ts.isCallExpression(expression) && ts.isPropertyAccessExpression(expression.expression) && isGlobal(expression.expression.expression, "Array") && expression.expression.name.text === "of")
|
|
295
|
+
return expression.arguments;
|
|
296
|
+
if (ts.isNewExpression(expression) && isGlobal(expression.expression, "Array"))
|
|
297
|
+
return expression.arguments;
|
|
298
|
+
if (!ts.isIdentifier(expression) || seen.has(expression.text))
|
|
299
|
+
return undefined;
|
|
300
|
+
let scope = expression.parent;
|
|
301
|
+
while (scope) {
|
|
302
|
+
const initializer = initializers.get(scope)?.get(expression.text);
|
|
303
|
+
if (initializer)
|
|
304
|
+
return arrayValues(initializer, new Set([...seen, expression.text]));
|
|
305
|
+
if (declarations.get(scope)?.has(expression.text) || selections.get(scope)?.has(expression.text))
|
|
306
|
+
return undefined;
|
|
307
|
+
if (ts.isFunctionLike(scope) && scope.parameters.some(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === expression.text))
|
|
308
|
+
return undefined;
|
|
309
|
+
scope = scope.parent;
|
|
310
|
+
}
|
|
311
|
+
return undefined;
|
|
312
|
+
};
|
|
313
|
+
const selectedElements = (selected) => {
|
|
314
|
+
const values = arrayValues(selected.expression);
|
|
315
|
+
return values && selected.element !== undefined ? selected.rest ? values.slice(selected.element) : values.slice(selected.element, selected.element + 1) : [selected.expression];
|
|
316
|
+
};
|
|
317
|
+
const isStringValue = (expression, seen = new Set()) => {
|
|
318
|
+
if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isNonNullExpression(expression))
|
|
319
|
+
return isStringValue(expression.expression, seen);
|
|
320
|
+
if (ts.isStringLiteralLike(expression) || ts.isTemplateExpression(expression))
|
|
321
|
+
return true;
|
|
322
|
+
if (ts.isPropertyAccessExpression(expression))
|
|
323
|
+
return (internalPaths.has(expression.name.text) || expression.name.text === "absoluteUiPath") && internalValue(expression.expression);
|
|
324
|
+
if (ts.isCallExpression(expression) && isGlobal(expression.expression, "String") || ts.isNewExpression(expression) && isGlobal(expression.expression, "String"))
|
|
325
|
+
return true;
|
|
326
|
+
if (!ts.isIdentifier(expression) || seen.has(expression.text))
|
|
327
|
+
return false;
|
|
328
|
+
let scope = expression.parent;
|
|
329
|
+
while (scope) {
|
|
330
|
+
if (stringTypes.get(scope)?.has(expression.text))
|
|
331
|
+
return true;
|
|
332
|
+
const selected = selections.get(scope)?.get(expression.text);
|
|
333
|
+
if (selected?.element !== undefined)
|
|
334
|
+
return !selected.rest && selectedElements(selected).length === 1 && isStringValue(selectedElements(selected)[0], new Set([...seen, expression.text]));
|
|
335
|
+
const initializer = initializers.get(scope)?.get(expression.text);
|
|
336
|
+
if (initializer)
|
|
337
|
+
return isStringValue(initializer, new Set([...seen, expression.text]));
|
|
338
|
+
if (declarations.get(scope)?.has(expression.text) || selected)
|
|
339
|
+
return false;
|
|
340
|
+
if (ts.isFunctionLike(scope) && scope.parameters.some(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === expression.text))
|
|
341
|
+
return false;
|
|
342
|
+
scope = scope.parent;
|
|
343
|
+
}
|
|
344
|
+
return false;
|
|
345
|
+
};
|
|
346
|
+
const hasScalarLength = (expression, seen = new Set()) => {
|
|
347
|
+
if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isNonNullExpression(expression))
|
|
348
|
+
return hasScalarLength(expression.expression, seen);
|
|
349
|
+
if (ts.isArrayLiteralExpression(expression) || ts.isStringLiteralLike(expression) || ts.isTemplateExpression(expression))
|
|
350
|
+
return true;
|
|
351
|
+
if (ts.isPropertyAccessExpression(expression))
|
|
352
|
+
return internalPaths.has(expression.name.text) && internalValue(expression.expression);
|
|
353
|
+
if (ts.isElementAccessExpression(expression) && ts.isStringLiteralLike(expression.argumentExpression))
|
|
354
|
+
return internalPaths.has(expression.argumentExpression.text) && internalValue(expression.expression);
|
|
355
|
+
if (ts.isNewExpression(expression))
|
|
356
|
+
return isGlobal(expression.expression, "Array") || isGlobal(expression.expression, "String");
|
|
357
|
+
if (ts.isCallExpression(expression) && isGlobal(expression.expression, "String"))
|
|
358
|
+
return true;
|
|
359
|
+
if (ts.isCallExpression(expression) && ts.isPropertyAccessExpression(expression.expression) && ["trim", "trimStart", "trimEnd", "replace", "replaceAll", "toLowerCase", "toUpperCase", "normalize", "substring", "substr", "padStart", "padEnd", "repeat", "split", "slice", "filter", "map", "flatMap"].includes(expression.expression.name.text))
|
|
360
|
+
return hasScalarLength(expression.expression.expression, seen);
|
|
361
|
+
if (ts.isCallExpression(expression) && ts.isPropertyAccessExpression(expression.expression) && isGlobal(expression.expression.expression, "Promise") && expression.expression.name.text === "resolve")
|
|
362
|
+
return !!expression.arguments[0] && hasScalarLength(expression.arguments[0], seen);
|
|
363
|
+
if (!ts.isIdentifier(expression) || seen.has(expression.text))
|
|
364
|
+
return false;
|
|
365
|
+
let scope = expression.parent;
|
|
366
|
+
while (scope) {
|
|
367
|
+
if (lengthTypes.get(scope)?.has(expression.text))
|
|
368
|
+
return true;
|
|
369
|
+
const initializer = initializers.get(scope)?.get(expression.text);
|
|
370
|
+
if (initializer)
|
|
371
|
+
return hasScalarLength(initializer, new Set([...seen, expression.text]));
|
|
372
|
+
if (declarations.get(scope)?.has(expression.text) || selections.get(scope)?.has(expression.text))
|
|
373
|
+
return false;
|
|
374
|
+
if (ts.isFunctionLike(scope)) {
|
|
375
|
+
const parameter = scope.parameters.find(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === expression.text);
|
|
376
|
+
if (parameter) {
|
|
377
|
+
const input = parameterInputs.get(parameter);
|
|
378
|
+
if (!input)
|
|
379
|
+
return false;
|
|
380
|
+
return elementParameters.has(parameter) ? ts.isArrayLiteralExpression(input) && input.elements.every(item => hasScalarLength(item, seen)) : hasScalarLength(input, seen);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
scope = scope.parent;
|
|
384
|
+
}
|
|
385
|
+
return false;
|
|
386
|
+
};
|
|
387
|
+
const parameterInputs = new Map();
|
|
388
|
+
const elementParameters = new Set();
|
|
389
|
+
const promiseResolvers = new Set();
|
|
390
|
+
const isPromiseResolver = (expression, seen = new Set()) => {
|
|
391
|
+
if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isNonNullExpression(expression))
|
|
392
|
+
return isPromiseResolver(expression.expression, seen);
|
|
393
|
+
if (!ts.isIdentifier(expression) || seen.has(expression.text))
|
|
394
|
+
return false;
|
|
395
|
+
let scope = expression.parent;
|
|
396
|
+
while (scope) {
|
|
397
|
+
const initializer = initializers.get(scope)?.get(expression.text);
|
|
398
|
+
if (initializer)
|
|
399
|
+
return isPromiseResolver(initializer, new Set([...seen, expression.text]));
|
|
400
|
+
if (declarations.get(scope)?.has(expression.text) || selections.get(scope)?.has(expression.text))
|
|
401
|
+
return false;
|
|
402
|
+
if (ts.isFunctionLike(scope)) {
|
|
403
|
+
const parameter = scope.parameters.find(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === expression.text);
|
|
404
|
+
if (parameter)
|
|
405
|
+
return promiseResolvers.has(parameter) || parameterInputs.has(parameter) && isPromiseResolver(parameterInputs.get(parameter));
|
|
406
|
+
}
|
|
407
|
+
scope = scope.parent;
|
|
408
|
+
}
|
|
409
|
+
return false;
|
|
410
|
+
};
|
|
411
|
+
const evaluatingFunctions = new Set();
|
|
412
|
+
const callbackInternal = (callback, seen, inputs = [], elements = [], fulfillOnly = false) => {
|
|
413
|
+
if (!callback?.body || evaluatingFunctions.has(callback))
|
|
414
|
+
return false;
|
|
415
|
+
evaluatingFunctions.add(callback);
|
|
416
|
+
const previous = callback.parameters.map(parameter => ({ parameter, input: parameterInputs.get(parameter), element: elementParameters.has(parameter) }));
|
|
417
|
+
for (const [index, parameter] of callback.parameters.entries()) {
|
|
418
|
+
const input = inputs[index];
|
|
419
|
+
if (input)
|
|
420
|
+
parameterInputs.set(parameter, input);
|
|
421
|
+
else
|
|
422
|
+
parameterInputs.delete(parameter);
|
|
423
|
+
if (elements.includes(index))
|
|
424
|
+
elementParameters.add(parameter);
|
|
425
|
+
else
|
|
426
|
+
elementParameters.delete(parameter);
|
|
427
|
+
}
|
|
428
|
+
try {
|
|
429
|
+
if (!fulfillOnly && !ts.isBlock(callback.body))
|
|
430
|
+
return internalValue(callback.body, seen);
|
|
431
|
+
let internal = false;
|
|
432
|
+
const returned = (node) => {
|
|
433
|
+
if (node !== callback.body && ts.isFunctionLike(node))
|
|
434
|
+
return;
|
|
435
|
+
if (!fulfillOnly && (ts.isReturnStatement(node) || ts.isYieldExpression(node)) && node.expression && internalValue(node.expression, seen))
|
|
436
|
+
internal = true;
|
|
437
|
+
if (fulfillOnly && ts.isCallExpression(node)) {
|
|
438
|
+
if (isPromiseResolver(node.expression)) {
|
|
439
|
+
if (node.arguments[0] && internalValue(node.arguments[0], seen))
|
|
440
|
+
internal = true;
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
if (callbackInternal(resolveCallback(node.expression), seen, node.arguments, [], true))
|
|
444
|
+
internal = true;
|
|
445
|
+
for (const argument of node.arguments)
|
|
446
|
+
if (callbackInternal(resolveCallback(argument), seen, [], [], true))
|
|
447
|
+
internal = true;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
ts.forEachChild(node, returned);
|
|
451
|
+
};
|
|
452
|
+
returned(callback.body);
|
|
453
|
+
return internal;
|
|
454
|
+
}
|
|
455
|
+
finally {
|
|
456
|
+
for (const { parameter, input, element } of previous) {
|
|
457
|
+
if (input)
|
|
458
|
+
parameterInputs.set(parameter, input);
|
|
459
|
+
else
|
|
460
|
+
parameterInputs.delete(parameter);
|
|
461
|
+
if (element)
|
|
462
|
+
elementParameters.add(parameter);
|
|
463
|
+
else
|
|
464
|
+
elementParameters.delete(parameter);
|
|
465
|
+
}
|
|
466
|
+
evaluatingFunctions.delete(callback);
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
const selectedProperty = (expression, field, seen = new Set()) => {
|
|
470
|
+
if (seen.has(expression))
|
|
471
|
+
return undefined;
|
|
472
|
+
const next = new Set([...seen, expression]);
|
|
473
|
+
if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isNonNullExpression(expression)
|
|
474
|
+
|| ts.isSatisfiesExpression(expression) || ts.isTypeAssertionExpression(expression))
|
|
475
|
+
return selectedProperty(expression.expression, field, next);
|
|
476
|
+
if (ts.isObjectLiteralExpression(expression)) {
|
|
477
|
+
const property = expression.properties.find(item => item.name && propertyKey(item.name) === field);
|
|
478
|
+
return property && ts.isPropertyAssignment(property) ? property.initializer : property && ts.isShorthandPropertyAssignment(property) ? property.name : property && ts.isMethodDeclaration(property) ? property : undefined;
|
|
479
|
+
}
|
|
480
|
+
if (ts.isIdentifier(expression)) {
|
|
481
|
+
let scope = expression.parent;
|
|
482
|
+
while (scope) {
|
|
483
|
+
const initializer = initializers.get(scope)?.get(expression.text);
|
|
484
|
+
if (initializer)
|
|
485
|
+
return selectedProperty(initializer, field, next);
|
|
486
|
+
if (declarations.get(scope)?.has(expression.text) || selections.get(scope)?.has(expression.text))
|
|
487
|
+
break;
|
|
488
|
+
scope = scope.parent;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
return undefined;
|
|
492
|
+
};
|
|
493
|
+
const internalValue = (expression, seen = new Set()) => {
|
|
494
|
+
if (ts.isElementAccessExpression(expression) && isStringValue(expression.expression)) {
|
|
495
|
+
const index = expression.argumentExpression;
|
|
496
|
+
if (ts.isNumericLiteral(index) || ts.isStringLiteralLike(index) && /^\d+$/.test(index.text)
|
|
497
|
+
|| ts.isPrefixUnaryExpression(index) && ts.isNumericLiteral(index.operand))
|
|
498
|
+
return false;
|
|
499
|
+
}
|
|
500
|
+
if (ts.isObjectBindingPattern(expression) && ts.isParameter(expression.parent)) {
|
|
501
|
+
const input = parameterInputs.get(expression.parent);
|
|
502
|
+
return !!input && internalValue(input, seen);
|
|
503
|
+
}
|
|
504
|
+
if (ts.isPrefixUnaryExpression(expression) || ts.isPostfixUnaryExpression(expression)
|
|
505
|
+
|| ts.isTypeOfExpression(expression) || ts.isVoidExpression(expression) || ts.isDeleteExpression(expression))
|
|
506
|
+
return false;
|
|
507
|
+
if (ts.isBinaryExpression(expression) && [ts.SyntaxKind.EqualsEqualsToken, ts.SyntaxKind.EqualsEqualsEqualsToken,
|
|
508
|
+
ts.SyntaxKind.ExclamationEqualsToken, ts.SyntaxKind.ExclamationEqualsEqualsToken, ts.SyntaxKind.LessThanToken,
|
|
509
|
+
ts.SyntaxKind.LessThanEqualsToken, ts.SyntaxKind.GreaterThanToken, ts.SyntaxKind.GreaterThanEqualsToken,
|
|
510
|
+
ts.SyntaxKind.InKeyword, ts.SyntaxKind.InstanceOfKeyword, ts.SyntaxKind.MinusToken, ts.SyntaxKind.AsteriskToken,
|
|
511
|
+
ts.SyntaxKind.SlashToken, ts.SyntaxKind.PercentToken, ts.SyntaxKind.AsteriskAsteriskToken, ts.SyntaxKind.AmpersandToken,
|
|
512
|
+
ts.SyntaxKind.BarToken, ts.SyntaxKind.CaretToken, ts.SyntaxKind.LessThanLessThanToken,
|
|
513
|
+
ts.SyntaxKind.GreaterThanGreaterThanToken, ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken].includes(expression.operatorToken.kind))
|
|
514
|
+
return false;
|
|
515
|
+
if (ts.isConditionalExpression(expression))
|
|
516
|
+
return internalValue(expression.whenTrue, seen) || internalValue(expression.whenFalse, seen);
|
|
517
|
+
if (ts.isIdentifier(expression) && !seen.has(expression.text)) {
|
|
518
|
+
const binding = reference(expression);
|
|
519
|
+
if (binding && mutations.get(binding.scope)?.get(binding.name)?.some(mutation => (!mutation.global || isGlobal(mutation.global, "Object")) && (!mutation.collection || collection(mutation.target))
|
|
520
|
+
&& mutation.values.some(value => internalValue(value, new Set([...seen, expression.text])))))
|
|
521
|
+
return true;
|
|
522
|
+
let scope = expression.parent;
|
|
523
|
+
while (scope) {
|
|
524
|
+
const selected = selections.get(scope)?.get(expression.text);
|
|
525
|
+
if (selected)
|
|
526
|
+
return selected.element !== undefined ? selectedElements(selected).some(value => internalValue(value, new Set([...seen, expression.text]))) : (selected.rest || internalPaths.has(selected.field)) && internalValue(selected.expression, new Set([...seen, expression.text]));
|
|
527
|
+
const initializer = initializers.get(scope)?.get(expression.text);
|
|
528
|
+
if (initializer)
|
|
529
|
+
return internalValue(initializer, new Set([...seen, expression.text]));
|
|
530
|
+
if (ts.isFunctionLike(scope) && scope.parameters.some(param => ts.isIdentifier(param.name) && param.name.text === expression.text)) {
|
|
531
|
+
const parameter = scope.parameters.find(param => ts.isIdentifier(param.name) && param.name.text === expression.text);
|
|
532
|
+
const input = parameterInputs.get(parameter);
|
|
533
|
+
if (input)
|
|
534
|
+
return internalValue(input, seen);
|
|
535
|
+
const call = scope.parent;
|
|
536
|
+
const first = scope.parameters[0]?.name;
|
|
537
|
+
if (first && ts.isIdentifier(first) && first.text === expression.text && ts.isCallExpression(call)
|
|
538
|
+
&& call.arguments[1] === scope && ts.isPropertyAccessExpression(call.expression)
|
|
539
|
+
&& isGlobal(call.expression.expression, "Array") && call.expression.name.text === "from") {
|
|
540
|
+
return !!call.arguments[0] && internalValue(call.arguments[0], new Set([...seen, expression.text]));
|
|
541
|
+
}
|
|
542
|
+
break;
|
|
543
|
+
}
|
|
544
|
+
scope = scope.parent;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
if (ts.isPropertyAccessExpression(expression) || ts.isElementAccessExpression(expression) && ts.isStringLiteralLike(expression.argumentExpression)) {
|
|
548
|
+
const field = ts.isPropertyAccessExpression(expression) ? expression.name.text : expression.argumentExpression.text;
|
|
549
|
+
const selected = selectedProperty(expression.expression, field);
|
|
550
|
+
if (selected)
|
|
551
|
+
return internalValue(selected, seen);
|
|
552
|
+
}
|
|
553
|
+
if ((ts.isPropertyAccessExpression(expression) && expression.name.text === "length"
|
|
554
|
+
|| ts.isElementAccessExpression(expression) && ts.isStringLiteralLike(expression.argumentExpression) && expression.argumentExpression.text === "length") && hasScalarLength(expression.expression))
|
|
555
|
+
return false;
|
|
556
|
+
if (ts.isPropertyAccessExpression(expression) && expression.name.text === "size" && collection(expression.expression))
|
|
557
|
+
return false;
|
|
558
|
+
if (ts.isPropertyAccessExpression(expression) && expression.name.text === "absoluteUiPath"
|
|
559
|
+
|| ts.isElementAccessExpression(expression) && ts.isStringLiteralLike(expression.argumentExpression) && expression.argumentExpression.text === "absoluteUiPath")
|
|
560
|
+
return false;
|
|
561
|
+
if (ts.isPropertyAccessExpression(expression) && internalPaths.has(expression.name.text))
|
|
562
|
+
return internalValue(expression.expression, seen);
|
|
563
|
+
if (ts.isCallExpression(expression) && (authRedirectFunction(expression.expression)
|
|
564
|
+
|| isResolverFunction(expression.expression)))
|
|
565
|
+
return true;
|
|
566
|
+
if (ts.isPropertyAccessExpression(expression))
|
|
567
|
+
return internalValue(expression.expression, seen);
|
|
568
|
+
if (ts.isPropertyAssignment(expression))
|
|
569
|
+
return internalValue(expression.initializer, seen);
|
|
570
|
+
// An arbitrary function may consume a URL while returning unrelated domain data.
|
|
571
|
+
if (ts.isCallExpression(expression)) {
|
|
572
|
+
const localCallback = resolveCallback(expression.expression);
|
|
573
|
+
if (localCallback)
|
|
574
|
+
return callbackInternal(localCallback, seen, expression.arguments);
|
|
575
|
+
if (isPromiseResolver(expression.expression))
|
|
576
|
+
return !!expression.arguments[0] && internalValue(expression.arguments[0], seen);
|
|
577
|
+
if (["encodeURI", "encodeURIComponent", "decodeURI", "decodeURIComponent", "escape", "unescape", "btoa", "atob"].some(name => isGlobal(expression.expression, name)))
|
|
578
|
+
return !!expression.arguments[0] && internalValue(expression.arguments[0], seen);
|
|
579
|
+
if (isGlobal(expression.expression, "String") || isGlobal(expression.expression, "Object"))
|
|
580
|
+
return !!expression.arguments[0] && internalValue(expression.arguments[0], seen);
|
|
581
|
+
if (isGlobal(expression.expression, "structuredClone"))
|
|
582
|
+
return !!expression.arguments[0] && internalValue(expression.arguments[0], seen);
|
|
583
|
+
if (ts.isPropertyAccessExpression(expression.expression) && isGlobal(expression.expression.expression, "Array")) {
|
|
584
|
+
if (expression.expression.name.text === "of")
|
|
585
|
+
return expression.arguments.some(argument => internalValue(argument, seen));
|
|
586
|
+
if (expression.expression.name.text === "from") {
|
|
587
|
+
const callback = resolveCallback(expression.arguments[1]);
|
|
588
|
+
if (!expression.arguments[1])
|
|
589
|
+
return !!expression.arguments[0] && internalValue(expression.arguments[0], seen);
|
|
590
|
+
return callbackInternal(callback, seen, [expression.arguments[0]], [0]);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
if (ts.isPropertyAccessExpression(expression.expression) && isGlobal(expression.expression.expression, "Object")) {
|
|
594
|
+
if (expression.expression.name.text === "create")
|
|
595
|
+
return !!expression.arguments[1] && internalValue(expression.arguments[1], seen);
|
|
596
|
+
if (expression.expression.name.text === "defineProperty")
|
|
597
|
+
return !!expression.arguments[0] && internalValue(expression.arguments[0], seen)
|
|
598
|
+
|| !!expression.arguments[2] && internalValue(expression.arguments[2], seen);
|
|
599
|
+
if (expression.expression.name.text === "defineProperties")
|
|
600
|
+
return expression.arguments.some(argument => internalValue(argument, seen));
|
|
601
|
+
if (expression.expression.name.text === "assign")
|
|
602
|
+
return expression.arguments.some(argument => internalValue(argument, seen));
|
|
603
|
+
if (["values", "entries", "freeze", "seal", "preventExtensions"].includes(expression.expression.name.text))
|
|
604
|
+
return !!expression.arguments[0] && internalValue(expression.arguments[0], seen);
|
|
605
|
+
if (expression.expression.name.text === "fromEntries")
|
|
606
|
+
return !!expression.arguments[0] && internalValue(expression.arguments[0], seen);
|
|
607
|
+
}
|
|
608
|
+
if (ts.isPropertyAccessExpression(expression.expression)) {
|
|
609
|
+
const operation = expression.expression.name.text;
|
|
610
|
+
if ((operation === "charAt" || operation === "at") && isStringValue(expression.expression.expression))
|
|
611
|
+
return false;
|
|
612
|
+
if (["replace", "replaceAll"].includes(operation) && hasScalarLength(expression.expression.expression)) {
|
|
613
|
+
const replacement = expression.arguments[1];
|
|
614
|
+
const callback = resolveCallback(replacement);
|
|
615
|
+
return internalValue(expression.expression.expression, seen) || (callback
|
|
616
|
+
? callbackInternal(callback, seen, [expression.expression.expression]) : !!replacement && internalValue(replacement, seen));
|
|
617
|
+
}
|
|
618
|
+
if (["toString", "valueOf", "join", "trim", "trimStart", "trimEnd", "trimLeft", "trimRight", "replace", "replaceAll", "toLowerCase", "toUpperCase", "toLocaleLowerCase", "toLocaleUpperCase", "normalize", "substring", "substr", "charAt", "at", "padStart", "padEnd", "repeat", "split"].includes(operation))
|
|
619
|
+
return internalValue(expression.expression.expression, seen);
|
|
620
|
+
if (operation === "fill")
|
|
621
|
+
return internalValue(expression.expression.expression, seen) || !!expression.arguments[0] && internalValue(expression.arguments[0], seen);
|
|
622
|
+
if (operation === "splice") {
|
|
623
|
+
const values = arrayValues(expression.expression.expression);
|
|
624
|
+
const number = (value) => value && ts.isNumericLiteral(value) ? Number(value.text)
|
|
625
|
+
: value && ts.isPrefixUnaryExpression(value) && value.operator === ts.SyntaxKind.MinusToken && ts.isNumericLiteral(value.operand) ? -Number(value.operand.text) : undefined;
|
|
626
|
+
const start = number(expression.arguments[0]);
|
|
627
|
+
const count = number(expression.arguments[1]);
|
|
628
|
+
const binding = reference(expression.expression.expression);
|
|
629
|
+
const earlierMutation = binding && mutations.get(binding.scope)?.get(binding.name)?.some(mutation => mutation.target.getStart(tree) < expression.getStart(tree)
|
|
630
|
+
&& mutation.values.some(value => internalValue(value, seen)));
|
|
631
|
+
if (earlierMutation)
|
|
632
|
+
return internalValue(expression.expression.expression, seen);
|
|
633
|
+
if (values && (start !== undefined || !expression.arguments.length) && (count !== undefined || expression.arguments.length < 2)) {
|
|
634
|
+
const index = Math.max(0, Math.min(values.length, start === undefined ? 0 : start < 0 ? values.length + start : start));
|
|
635
|
+
const removed = !expression.arguments.length ? [] : values.slice(index, expression.arguments.length === 1 ? values.length : index + Math.max(0, count));
|
|
636
|
+
return removed.some(value => internalValue(value, seen));
|
|
637
|
+
}
|
|
638
|
+
return internalValue(expression.expression.expression, seen);
|
|
639
|
+
}
|
|
640
|
+
if (["filter", "slice", "sort", "reverse", "copyWithin", "toSorted", "toReversed", "flat", "find", "findLast", "pop", "shift"].includes(operation))
|
|
641
|
+
return internalValue(expression.expression.expression, seen);
|
|
642
|
+
if (operation === "concat")
|
|
643
|
+
return internalValue(expression.expression.expression, seen) || expression.arguments.some(argument => internalValue(argument, seen));
|
|
644
|
+
if (["with", "toSpliced"].includes(operation))
|
|
645
|
+
return internalValue(expression.expression.expression, seen)
|
|
646
|
+
|| expression.arguments.slice(operation === "with" ? 1 : 2).some(argument => internalValue(argument, seen));
|
|
647
|
+
}
|
|
648
|
+
if (ts.isPropertyAccessExpression(expression.expression) && ["then", "catch", "finally"].includes(expression.expression.name.text)) {
|
|
649
|
+
const operation = expression.expression.name.text;
|
|
650
|
+
if ((operation === "charAt" || operation === "at") && isStringValue(expression.expression.expression))
|
|
651
|
+
return false;
|
|
652
|
+
if (["replace", "replaceAll"].includes(operation) && hasScalarLength(expression.expression.expression)) {
|
|
653
|
+
const replacement = expression.arguments[1];
|
|
654
|
+
const callback = resolveCallback(replacement);
|
|
655
|
+
return internalValue(expression.expression.expression, seen) || (callback
|
|
656
|
+
? callbackInternal(callback, seen, [expression.expression.expression]) : !!replacement && internalValue(replacement, seen));
|
|
657
|
+
}
|
|
658
|
+
if (operation === "finally")
|
|
659
|
+
return internalValue(expression.expression.expression, seen);
|
|
660
|
+
for (const argument of expression.arguments) {
|
|
661
|
+
const callback = resolveCallback(argument);
|
|
662
|
+
if (callbackInternal(callback, seen, operation === "then" && argument === expression.arguments[0] ? [expression.expression.expression] : []))
|
|
663
|
+
return true;
|
|
664
|
+
}
|
|
665
|
+
return (operation === "catch" || !expression.arguments[0]) && internalValue(expression.expression.expression, seen);
|
|
666
|
+
}
|
|
667
|
+
if (isResponseConstructor(expression.expression) || ts.isPropertyAccessExpression(expression.expression)
|
|
668
|
+
&& expression.expression.name.text === "response" && contextValue(expression.expression.expression))
|
|
669
|
+
return !!expression.arguments[0] && internalValue(expression.arguments[0], seen);
|
|
670
|
+
if (ts.isPropertyAccessExpression(expression.expression) && ["map", "flatMap", "reduce", "reduceRight"].includes(expression.expression.name.text)) {
|
|
671
|
+
if (["reduce", "reduceRight"].includes(expression.expression.name.text) && expression.arguments[1] && internalValue(expression.arguments[1], seen))
|
|
672
|
+
return true;
|
|
673
|
+
const callback = resolveCallback(expression.arguments[0]);
|
|
674
|
+
return ["reduce", "reduceRight"].includes(expression.expression.name.text)
|
|
675
|
+
? callbackInternal(callback, seen, [expression.arguments[1], expression.expression.expression], [1])
|
|
676
|
+
: callbackInternal(callback, seen, [expression.expression.expression], [0]);
|
|
677
|
+
}
|
|
678
|
+
return callbackInternal(resolveCallback(expression.expression), seen, expression.arguments);
|
|
679
|
+
}
|
|
680
|
+
if (ts.isNewExpression(expression) && isGlobal(expression.expression, "Promise")) {
|
|
681
|
+
const executor = resolveCallback(expression.arguments?.[0]);
|
|
682
|
+
const parameter = executor?.parameters[0];
|
|
683
|
+
if (!executor || !parameter)
|
|
684
|
+
return false;
|
|
685
|
+
promiseResolvers.add(parameter);
|
|
686
|
+
try {
|
|
687
|
+
return callbackInternal(executor, seen, [], [], true);
|
|
688
|
+
}
|
|
689
|
+
finally {
|
|
690
|
+
promiseResolvers.delete(parameter);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
if (ts.isNewExpression(expression) && ["Array", "Map", "Set", "URLSearchParams", "Headers", "FormData", "URL", "String", "Object"].some(name => isGlobal(expression.expression, name)))
|
|
694
|
+
return !!expression.arguments?.some(argument => internalValue(argument, seen));
|
|
695
|
+
if (ts.isNewExpression(expression))
|
|
696
|
+
return isGlobal(expression.expression, "Response") && !!expression.arguments?.[0] && internalValue(expression.arguments[0], seen);
|
|
697
|
+
return expression.getChildren(tree).some(child => internalValue(child, seen));
|
|
698
|
+
};
|
|
699
|
+
const defaultExports = new Set(tree.statements.flatMap(statement => ts.isExportAssignment(statement) && ts.isIdentifier(statement.expression) ? [statement.expression.text] : []));
|
|
700
|
+
const factoryNames = new Set(["createHandler", "createRawHandler", "createStreamHandler", "createSse"]);
|
|
701
|
+
const handlerFactories = new Set();
|
|
702
|
+
const handlerNamespaces = new Set();
|
|
703
|
+
for (const statement of tree.statements) {
|
|
704
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteralLike(statement.moduleSpecifier) || statement.importClause?.isTypeOnly)
|
|
705
|
+
continue;
|
|
706
|
+
const module = statement.moduleSpecifier.text;
|
|
707
|
+
if (module !== "@betterportal/framework" && !module.startsWith("@betterportal/framework/")
|
|
708
|
+
&& !/(?:^|[/])\.bp-generated[/]route-runtime(?:\.[cm]?[jt]s)?$/.test(module))
|
|
709
|
+
continue;
|
|
710
|
+
const bindings = statement.importClause?.namedBindings;
|
|
711
|
+
if (bindings && ts.isNamespaceImport(bindings))
|
|
712
|
+
handlerNamespaces.add(bindings.name.text);
|
|
713
|
+
if (bindings && ts.isNamedImports(bindings))
|
|
714
|
+
for (const binding of bindings.elements) {
|
|
715
|
+
if (!binding.isTypeOnly && factoryNames.has(binding.propertyName?.text ?? binding.name.text))
|
|
716
|
+
handlerFactories.add(binding.name.text);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
const factoryImport = (expression, namespace = false, seen = new Set()) => {
|
|
720
|
+
if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isNonNullExpression(expression))
|
|
721
|
+
return factoryImport(expression.expression, namespace, seen);
|
|
722
|
+
if (!ts.isIdentifier(expression) || seen.has(expression.text))
|
|
723
|
+
return false;
|
|
724
|
+
let scope = expression.parent;
|
|
725
|
+
while (scope) {
|
|
726
|
+
const initializer = initializers.get(scope)?.get(expression.text);
|
|
727
|
+
if (initializer)
|
|
728
|
+
return namespace ? factoryImport(initializer, true, new Set([...seen, expression.text])) : factory(initializer, new Set([...seen, expression.text]));
|
|
729
|
+
if (ts.isFunctionLike(scope) && scope.parameters.some(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === expression.text))
|
|
730
|
+
return false;
|
|
731
|
+
scope = scope.parent;
|
|
732
|
+
}
|
|
733
|
+
return (namespace ? handlerNamespaces : handlerFactories).has(expression.text) && isGlobal(expression, expression.text, true);
|
|
734
|
+
};
|
|
735
|
+
const factory = (expression, seen = new Set()) => ts.isIdentifier(expression) ? factoryImport(expression, false, seen)
|
|
736
|
+
: ts.isPropertyAccessExpression(expression) ? factoryNames.has(expression.name.text) && factoryImport(expression.expression, true, seen)
|
|
737
|
+
|| expression.name.text === "forContext" && factory(expression.expression, seen)
|
|
738
|
+
: ts.isCallExpression(expression) ? factory(expression.expression, seen) : false;
|
|
739
|
+
const routeHandlerFile = /(?:^|[/])bp-routes[/](?:.*[/])?(?:GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|SSE|STREAM)\.(?:[cm]?ts|tsx)$/.test(file.replace(/\\/g, "/"));
|
|
740
|
+
const isReturnedValue = (node) => {
|
|
741
|
+
let current = node.parent;
|
|
742
|
+
while (current && !ts.isFunctionLike(current)) {
|
|
743
|
+
if ((ts.isReturnStatement(current) || ts.isYieldExpression(current)))
|
|
744
|
+
return true;
|
|
745
|
+
if (ts.isCallExpression(current) || ts.isNewExpression(current) || ts.isVariableDeclaration(current))
|
|
746
|
+
return false;
|
|
747
|
+
current = current.parent;
|
|
748
|
+
}
|
|
749
|
+
return Boolean(current && ts.isArrowFunction(current) && !ts.isBlock(current.body));
|
|
750
|
+
};
|
|
751
|
+
const ownsHandlerContext = (node) => {
|
|
752
|
+
if (file.includes("_renderer."))
|
|
753
|
+
return false;
|
|
754
|
+
if (routeHandlerFile && (ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node))) {
|
|
755
|
+
if (node.name && (["handler", "handle"].includes(node.name.text) || defaultExports.has(node.name.text)))
|
|
756
|
+
return true;
|
|
757
|
+
if (ts.getModifiers(node)?.some(modifier => modifier.kind === ts.SyntaxKind.DefaultKeyword))
|
|
758
|
+
return true;
|
|
759
|
+
}
|
|
760
|
+
const parent = node.parent;
|
|
761
|
+
if (routeHandlerFile && ts.isVariableDeclaration(parent) && ts.isIdentifier(parent.name)
|
|
762
|
+
&& (["handler", "handle"].includes(parent.name.text) || defaultExports.has(parent.name.text)))
|
|
763
|
+
return true;
|
|
764
|
+
if (routeHandlerFile && ts.isExportAssignment(parent))
|
|
765
|
+
return true;
|
|
766
|
+
if (!ts.isCallExpression(parent))
|
|
767
|
+
return false;
|
|
768
|
+
return factory(parent.expression);
|
|
769
|
+
};
|
|
770
|
+
const belongsToHandler = (node) => {
|
|
771
|
+
if (file.includes("_renderer."))
|
|
772
|
+
return false;
|
|
773
|
+
while (node && !ts.isFunctionLike(node) && !ts.isSourceFile(node))
|
|
774
|
+
node = node.parent;
|
|
775
|
+
if (!node || !ts.isFunctionLike(node))
|
|
776
|
+
return false;
|
|
777
|
+
if (ownsHandlerContext(node))
|
|
778
|
+
return true;
|
|
779
|
+
const parent = node.parent;
|
|
780
|
+
if (!ts.isCallExpression(parent))
|
|
781
|
+
return false;
|
|
782
|
+
const callee = parent.expression;
|
|
783
|
+
// A callback contributes to the response only when its call result is returned.
|
|
784
|
+
return ts.isPropertyAccessExpression(callee) && ["map", "flatMap", "reduce", "reduceRight", "transaction", "then", "catch"].includes(callee.name.text)
|
|
785
|
+
&& isReturnedValue(parent) && belongsToHandler(parent.parent);
|
|
786
|
+
};
|
|
787
|
+
const inReturnedObject = (node) => {
|
|
788
|
+
let current = node.parent;
|
|
789
|
+
while (current && !ts.isFunctionLike(current)) {
|
|
790
|
+
if (ts.isCallExpression(current) || ts.isNewExpression(current) || ts.isJsxAttribute(current) || ts.isJsxSpreadAttribute(current))
|
|
791
|
+
return false;
|
|
792
|
+
if ((ts.isReturnStatement(current) || ts.isYieldExpression(current)))
|
|
793
|
+
return belongsToHandler(current.parent);
|
|
794
|
+
current = current.parent;
|
|
795
|
+
}
|
|
796
|
+
return Boolean(current && ts.isArrowFunction(current) && !ts.isBlock(current.body) && belongsToHandler(current));
|
|
797
|
+
};
|
|
798
|
+
const contextValue = (expression, seen = new Set()) => {
|
|
799
|
+
if (ts.isObjectBindingPattern(expression) && ts.isParameter(expression.parent)) {
|
|
800
|
+
const parameter = expression.parent;
|
|
801
|
+
const input = parameterInputs.get(parameter);
|
|
802
|
+
if (input)
|
|
803
|
+
return contextValue(input, seen);
|
|
804
|
+
const owner = parameter.parent;
|
|
805
|
+
return ts.isFunctionLike(owner) && (owner.parameters[0] === parameter && ownsHandlerContext(owner)
|
|
806
|
+
|| owner.parameters[1] === parameter && rendererFunctions.has(owner)
|
|
807
|
+
|| /(?:RouteHandlerContext|ViewRenderContext|HandlerContext)/.test(parameter.type?.getText(tree) ?? ""));
|
|
808
|
+
}
|
|
809
|
+
if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isTypeAssertionExpression(expression)
|
|
810
|
+
|| ts.isNonNullExpression(expression) || ts.isSatisfiesExpression(expression))
|
|
811
|
+
return contextValue(expression.expression, seen);
|
|
812
|
+
if (!ts.isIdentifier(expression) || seen.has(expression.text))
|
|
813
|
+
return false;
|
|
814
|
+
let scope = expression.parent;
|
|
815
|
+
while (scope) {
|
|
816
|
+
const selected = selections.get(scope)?.get(expression.text);
|
|
817
|
+
if (selected)
|
|
818
|
+
return selected.element !== undefined ? !selected.rest && selectedElements(selected).some(value => contextValue(value, new Set([...seen, expression.text]))) : selected.rest && contextValue(selected.expression, new Set([...seen, expression.text]));
|
|
819
|
+
const initializer = initializers.get(scope)?.get(expression.text);
|
|
820
|
+
if (initializer)
|
|
821
|
+
return contextValue(initializer, new Set([...seen, expression.text]));
|
|
822
|
+
if (ts.isFunctionLike(scope)) {
|
|
823
|
+
const index = scope.parameters.findIndex(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === expression.text);
|
|
824
|
+
if (index >= 0 && parameterInputs.has(scope.parameters[index]))
|
|
825
|
+
return contextValue(parameterInputs.get(scope.parameters[index]), seen);
|
|
826
|
+
if (index >= 0)
|
|
827
|
+
return index === 0 && ownsHandlerContext(scope)
|
|
828
|
+
|| index === 1 && rendererFunctions.has(scope)
|
|
829
|
+
|| /(?:RouteHandlerContext|ViewRenderContext|HandlerContext)/.test(scope.parameters[index].type?.getText(tree) ?? "");
|
|
830
|
+
}
|
|
831
|
+
scope = scope.parent;
|
|
832
|
+
}
|
|
833
|
+
return false;
|
|
834
|
+
};
|
|
835
|
+
const isResolverFunction = (expression, seen = new Set()) => {
|
|
836
|
+
if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isNonNullExpression(expression))
|
|
837
|
+
return isResolverFunction(expression.expression, seen);
|
|
838
|
+
if (ts.isPropertyAccessExpression(expression))
|
|
839
|
+
return expression.name.text === "routeUrl" && contextValue(expression.expression);
|
|
840
|
+
if (ts.isElementAccessExpression(expression))
|
|
841
|
+
return ts.isStringLiteralLike(expression.argumentExpression) && expression.argumentExpression.text === "routeUrl" && contextValue(expression.expression);
|
|
842
|
+
if (!ts.isIdentifier(expression) || seen.has(expression.text))
|
|
843
|
+
return false;
|
|
844
|
+
let scope = expression.parent;
|
|
845
|
+
while (scope) {
|
|
846
|
+
const selected = selections.get(scope)?.get(expression.text);
|
|
847
|
+
if (selected)
|
|
848
|
+
return selected.element !== undefined ? !selected.rest && selectedElements(selected).some(value => isResolverFunction(value, new Set([...seen, expression.text]))) : selected.field === "routeUrl" && contextValue(selected.expression);
|
|
849
|
+
const initializer = initializers.get(scope)?.get(expression.text);
|
|
850
|
+
if (initializer)
|
|
851
|
+
return isResolverFunction(initializer, new Set([...seen, expression.text]));
|
|
852
|
+
if (ts.isFunctionLike(scope)) {
|
|
853
|
+
const parameter = scope.parameters.find(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === expression.text);
|
|
854
|
+
if (parameter)
|
|
855
|
+
return parameterInputs.has(parameter) && isResolverFunction(parameterInputs.get(parameter));
|
|
856
|
+
}
|
|
857
|
+
scope = scope.parent;
|
|
858
|
+
}
|
|
859
|
+
return false;
|
|
860
|
+
};
|
|
861
|
+
const authRedirectHelpers = new Set();
|
|
862
|
+
const authRedirectNamespaces = new Set();
|
|
863
|
+
for (const statement of tree.statements) {
|
|
864
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)
|
|
865
|
+
|| !/^@betterportal\/framework(?:\/|$)/.test(statement.moduleSpecifier.text) || statement.importClause?.isTypeOnly)
|
|
866
|
+
continue;
|
|
867
|
+
const bindings = statement.importClause?.namedBindings;
|
|
868
|
+
if (bindings && ts.isNamespaceImport(bindings))
|
|
869
|
+
authRedirectNamespaces.add(bindings.name.text);
|
|
870
|
+
if (bindings && ts.isNamedImports(bindings))
|
|
871
|
+
for (const binding of bindings.elements)
|
|
872
|
+
if (!binding.isTypeOnly && (binding.propertyName?.text ?? binding.name.text) === "resolveAppAuthRedirect")
|
|
873
|
+
authRedirectHelpers.add(binding.name.text);
|
|
874
|
+
}
|
|
875
|
+
const authRedirectFunction = (expression, namespace = false, seen = new Set()) => {
|
|
876
|
+
if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isNonNullExpression(expression))
|
|
877
|
+
return authRedirectFunction(expression.expression, namespace, seen);
|
|
878
|
+
if (ts.isPropertyAccessExpression(expression))
|
|
879
|
+
return expression.name.text === "resolveAppAuthRedirect" && authRedirectFunction(expression.expression, true, seen);
|
|
880
|
+
if (!ts.isIdentifier(expression) || seen.has(expression.text))
|
|
881
|
+
return false;
|
|
882
|
+
let scope = expression.parent;
|
|
883
|
+
while (scope) {
|
|
884
|
+
const initializer = initializers.get(scope)?.get(expression.text);
|
|
885
|
+
if (initializer)
|
|
886
|
+
return authRedirectFunction(initializer, namespace, new Set([...seen, expression.text]));
|
|
887
|
+
const selected = selections.get(scope)?.get(expression.text);
|
|
888
|
+
if (selected)
|
|
889
|
+
return selected.field === "resolveAppAuthRedirect" && authRedirectFunction(selected.expression, true, new Set([...seen, expression.text]));
|
|
890
|
+
if (ts.isFunctionLike(scope) && scope.parameters.some(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === expression.text))
|
|
891
|
+
return false;
|
|
892
|
+
scope = scope.parent;
|
|
893
|
+
}
|
|
894
|
+
return (namespace ? authRedirectNamespaces : authRedirectHelpers).has(expression.text) && isGlobal(expression, expression.text, true);
|
|
895
|
+
};
|
|
896
|
+
const jsonHelpers = new Set();
|
|
897
|
+
for (const statement of tree.statements) {
|
|
898
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)
|
|
899
|
+
|| statement.moduleSpecifier.text !== "@betterportal/framework" || statement.importClause?.isTypeOnly)
|
|
900
|
+
continue;
|
|
901
|
+
const bindings = statement.importClause?.namedBindings;
|
|
902
|
+
if (bindings && ts.isNamedImports(bindings))
|
|
903
|
+
for (const binding of bindings.elements) {
|
|
904
|
+
if (!binding.isTypeOnly && (binding.propertyName?.text ?? binding.name.text) === "jsonResponse")
|
|
905
|
+
jsonHelpers.add(binding.name.text);
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
const isGlobal = (expression, name, allowImport = false) => {
|
|
909
|
+
if (!ts.isIdentifier(expression) || expression.text !== name)
|
|
910
|
+
return false;
|
|
911
|
+
let scope = expression.parent;
|
|
912
|
+
while (scope) {
|
|
913
|
+
if (declarations.get(scope)?.has(name) && !(allowImport && ts.isSourceFile(scope)) || initializers.get(scope)?.has(name) || selections.get(scope)?.has(name))
|
|
914
|
+
return false;
|
|
915
|
+
if (ts.isFunctionLike(scope) && scope.parameters.some(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === name))
|
|
916
|
+
return false;
|
|
917
|
+
scope = scope.parent;
|
|
918
|
+
}
|
|
919
|
+
return true;
|
|
920
|
+
};
|
|
921
|
+
const isResponseConstructor = (expression) => {
|
|
922
|
+
if (ts.isIdentifier(expression))
|
|
923
|
+
return jsonHelpers.has(expression.text) && isGlobal(expression, expression.text, true);
|
|
924
|
+
return ts.isPropertyAccessExpression(expression) && (isGlobal(expression.expression, "Response") && expression.name.text === "json"
|
|
925
|
+
|| isGlobal(expression.expression, "JSON") && ["stringify", "parse"].includes(expression.name.text)
|
|
926
|
+
|| isGlobal(expression.expression, "Promise") && ["resolve", "all", "allSettled", "race", "any"].includes(expression.name.text));
|
|
927
|
+
};
|
|
928
|
+
const visit = (node) => {
|
|
929
|
+
if (ts.isPropertyAccessExpression(node) && node.name.text === "uiRouteUrl" && contextValue(node.expression)
|
|
930
|
+
|| ts.isElementAccessExpression(node) && ts.isStringLiteralLike(node.argumentExpression) && node.argumentExpression.text === "uiRouteUrl" && contextValue(node.expression)
|
|
931
|
+
|| ts.isBindingElement(node) && (node.propertyName ?? node.name).getText(tree).replace(/^["']|["']$/g, "") === "uiRouteUrl"
|
|
932
|
+
&& ts.isObjectBindingPattern(node.parent) && ts.isVariableDeclaration(node.parent.parent)
|
|
933
|
+
&& !!node.parent.parent.initializer && contextValue(node.parent.parent.initializer)
|
|
934
|
+
|| ts.isBindingElement(node) && (node.propertyName ?? node.name).getText(tree).replace(/^["']|["']$/g, "") === "uiRouteUrl"
|
|
935
|
+
&& ts.isObjectBindingPattern(node.parent) && ts.isParameter(node.parent.parent) && contextValue(node.parent)) {
|
|
936
|
+
report(node, "uiRouteUrl was removed. Use ctx.routeUrl({ ... }) and select uiPath or absoluteUiPath.");
|
|
937
|
+
}
|
|
938
|
+
if (ts.isPropertyAccessExpression(node) && ["route", "uiRoute", "current", "path"].includes(node.name.text)
|
|
939
|
+
&& ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === "url" && contextValue(node.expression.expression)) {
|
|
940
|
+
report(node, "ctx.url helpers were removed. Use ctx.routeUrl({ ... }); omit the target for self.");
|
|
941
|
+
}
|
|
942
|
+
if (ts.isCallExpression(node) && isResolverFunction(node.expression)) {
|
|
943
|
+
if (node.arguments[0] && ts.isObjectLiteralExpression(node.arguments[0])
|
|
944
|
+
&& node.arguments[0].properties.some(item => item.name && ["absolute", "origin"].includes(ts.isIdentifier(item.name) || ts.isStringLiteralLike(item.name) ? item.name.text : item.name.getText(tree)))) {
|
|
945
|
+
report(node, "absolute/origin options were removed. Select the corresponding absolute destination field.");
|
|
946
|
+
}
|
|
947
|
+
if ((node.arguments.length > 1 || node.arguments[0] && ts.isStringLiteralLike(node.arguments[0]))) {
|
|
948
|
+
report(node, "routeUrl no longer accepts a positional view id or returns a string. Pass one options object and select a destination field.");
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
let field;
|
|
952
|
+
if (ts.isPropertyAccessExpression(node))
|
|
953
|
+
field = node.name.text;
|
|
954
|
+
if ((ts.isPropertyAssignment(node) || ts.isShorthandPropertyAssignment(node) || ts.isBindingElement(node)) && node.name && (ts.isIdentifier(node.name) || ts.isStringLiteralLike(node.name)))
|
|
955
|
+
field = node.name.text;
|
|
956
|
+
if (ts.isBindingElement(node) && node.propertyName && (ts.isIdentifier(node.propertyName) || ts.isStringLiteralLike(node.propertyName)))
|
|
957
|
+
field = node.propertyName.text;
|
|
958
|
+
if (ts.isElementAccessExpression(node) && node.argumentExpression && ts.isStringLiteralLike(node.argumentExpression))
|
|
959
|
+
field = node.argumentExpression.text;
|
|
960
|
+
const payloadAccess = (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node))
|
|
961
|
+
&& rendererPayload(node.expression);
|
|
962
|
+
const payloadBinding = ts.isBindingElement(node) && ts.isObjectBindingPattern(node.parent)
|
|
963
|
+
&& ts.isVariableDeclaration(node.parent.parent) && node.parent.parent.initializer
|
|
964
|
+
&& rendererPayload(node.parent.parent.initializer);
|
|
965
|
+
const payloadParameter = ts.isBindingElement(node) && ts.isObjectBindingPattern(node.parent)
|
|
966
|
+
&& ts.isParameter(node.parent.parent) && rendererFunctions.has(node.parent.parent.parent)
|
|
967
|
+
&& ts.isFunctionLike(node.parent.parent.parent) && node.parent.parent.parent.parameters[0] === node.parent.parent;
|
|
968
|
+
if (field && legacyFields.has(field) && (payloadAccess || payloadBinding || payloadParameter))
|
|
969
|
+
report(node, `Legacy internal URL field '${field}' was removed. Return domain data/cursors and resolve destinations in the renderer.`);
|
|
970
|
+
const returned = (ts.isReturnStatement(node) || ts.isYieldExpression(node)) && node.expression && belongsToHandler(node.parent) ? node.expression
|
|
971
|
+
: ts.isArrowFunction(node) && !ts.isBlock(node.body) && belongsToHandler(node) ? node.body : undefined;
|
|
972
|
+
if (returned && internalValue(returned))
|
|
973
|
+
report(node, "Do not return internal route destinations from API handlers. Return domain data and resolve destinations at the point of use.");
|
|
974
|
+
if ((ts.isPropertyAssignment(node) || ts.isShorthandPropertyAssignment(node) || ts.isSpreadAssignment(node)) && inReturnedObject(node) && internalValue(ts.isSpreadAssignment(node) ? node.expression : ts.isPropertyAssignment(node) ? node.initializer : node.name)) {
|
|
975
|
+
report(node, "Do not return internal route paths as API response fields. Resolve them at the point of use; only public absoluteUiPath links belong in domain responses.");
|
|
976
|
+
}
|
|
977
|
+
if ((ts.isStringLiteralLike(node) || ts.isNoSubstitutionTemplateLiteral(node)) && /(?:href|action|hx-(?:get|post|put|patch|delete|download))=["']\{[A-Za-z0-9_$.-]+\}["']/.test(node.text)) {
|
|
978
|
+
report(node, "Legacy route tokens were removed. Resolve the destination with ctx.routeUrl in the renderer.");
|
|
979
|
+
}
|
|
980
|
+
if (ts.isJsxAttribute(node) && node.initializer && ts.isStringLiteralLike(node.initializer)
|
|
981
|
+
&& ["href", "action", "hx-get", "hx-post", "hx-put", "hx-patch", "hx-delete", "hx-download", "sse-connect"].includes(node.name.getText(tree))
|
|
982
|
+
&& /^\{[A-Za-z0-9_$.-]+\}$/.test(node.initializer.text)) {
|
|
983
|
+
report(node, "Legacy route tokens were removed. Resolve the destination with ctx.routeUrl in the renderer.");
|
|
984
|
+
}
|
|
985
|
+
ts.forEachChild(node, visit);
|
|
986
|
+
};
|
|
987
|
+
visit(tree);
|
|
988
|
+
return errors;
|
|
989
|
+
}
|
|
990
|
+
/** Inspect project source, including domain helpers outside bp-routes, before generation/build. */
|
|
991
|
+
export function checkProjectRouteUrls(directory) {
|
|
992
|
+
if (!fs.existsSync(directory))
|
|
993
|
+
return [];
|
|
994
|
+
return fs.readdirSync(directory, { withFileTypes: true }).flatMap(entry => {
|
|
995
|
+
if ((entry.name.startsWith(".") && entry.name !== ".well-known") || entry.name === "node_modules")
|
|
996
|
+
return [];
|
|
997
|
+
const file = path.join(directory, entry.name);
|
|
998
|
+
return entry.isDirectory() ? checkProjectRouteUrls(file) : /\.(?:[cm]?ts|tsx)$/.test(file) ? inspectRouteUrlSource(file, fs.readFileSync(file, "utf8")) : [];
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
/** Inspect default source helpers and every configured route/shell input root. */
|
|
1002
|
+
export function checkConfiguredRouteUrls(packageDir, config = {}) {
|
|
1003
|
+
const roots = [...new Set(["src", ...config.routes ?? [], ...config.shells ?? []].map(directory => path.resolve(packageDir, directory)))];
|
|
1004
|
+
const minimal = roots.filter(root => !roots.some(parent => {
|
|
1005
|
+
if (parent === root)
|
|
1006
|
+
return false;
|
|
1007
|
+
const relative = path.relative(parent, root);
|
|
1008
|
+
return relative !== ".." && !relative.startsWith(".." + path.sep) && !path.isAbsolute(relative);
|
|
1009
|
+
}));
|
|
1010
|
+
return minimal.flatMap(checkProjectRouteUrls);
|
|
1011
|
+
}
|
|
1012
|
+
//# sourceMappingURL=routeUrlPolicy.js.map
|