@nocobase/plugin-flow-engine 2.1.0-alpha.45 → 2.1.0-alpha.46
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/dist/client/index.js +1 -1
- package/dist/externalVersion.js +9 -9
- package/dist/node_modules/@ant-design/icons-svg/package.json +1 -1
- package/dist/node_modules/acorn/package.json +1 -1
- package/dist/node_modules/acorn-jsx/package.json +1 -1
- package/dist/node_modules/acorn-walk/package.json +1 -1
- package/dist/node_modules/ses/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/flow-surfaces/apply/compiler.js +10 -11
- package/dist/server/flow-surfaces/authoring-validation.d.ts +1 -0
- package/dist/server/flow-surfaces/authoring-validation.js +773 -26
- package/dist/server/flow-surfaces/blueprint/normalize-document.js +5 -1
- package/dist/server/flow-surfaces/catalog.js +9 -5
- package/dist/server/flow-surfaces/chart-config.js +220 -16
- package/dist/server/flow-surfaces/contract-guard.js +40 -6
- package/dist/server/flow-surfaces/default-block-actions.js +2 -0
- package/dist/server/flow-surfaces/errors.d.ts +15 -0
- package/dist/server/flow-surfaces/errors.js +49 -3
- package/dist/server/flow-surfaces/event-flow-normalizer.d.ts +19 -0
- package/dist/server/flow-surfaces/event-flow-normalizer.js +128 -0
- package/dist/server/flow-surfaces/filter-group.d.ts +9 -1
- package/dist/server/flow-surfaces/filter-group.js +402 -3
- package/dist/server/flow-surfaces/public-data-surface-default-filter.js +2 -1
- package/dist/server/flow-surfaces/route-sync.js +19 -2
- package/dist/server/flow-surfaces/runjs-authoring/ast/bindings.d.ts +66 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/bindings.js +661 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/execution.d.ts +20 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/execution.js +275 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/parser.d.ts +16 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/parser.js +130 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/react-values.d.ts +20 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/react-values.js +401 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/request-config.d.ts +21 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/request-config.js +199 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/source.d.ts +70 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/source.js +895 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/static-bindings.d.ts +23 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/static-bindings.js +618 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/static-values.d.ts +196 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/static-values.js +1777 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/walk.d.ts +10 -0
- package/dist/server/flow-surfaces/runjs-authoring/ast/walk.js +55 -0
- package/dist/server/flow-surfaces/runjs-authoring/collectors.d.ts +12 -0
- package/dist/server/flow-surfaces/runjs-authoring/collectors.js +589 -0
- package/dist/server/flow-surfaces/runjs-authoring/index.d.ts +2 -25
- package/dist/server/flow-surfaces/runjs-authoring/index.js +5 -11138
- package/dist/server/flow-surfaces/runjs-authoring/inspect.d.ts +13 -0
- package/dist/server/flow-surfaces/runjs-authoring/inspect.js +149 -0
- package/dist/server/flow-surfaces/runjs-authoring/internal-types.d.ts +333 -0
- package/dist/server/flow-surfaces/runjs-authoring/internal-types.js +36 -0
- package/dist/server/flow-surfaces/runjs-authoring/rules.js +2 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/constants.d.ts +67 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/constants.js +757 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/errors.d.ts +22 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/errors.js +91 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/source-budget.d.ts +16 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/source-budget.js +115 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/surface.d.ts +19 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/surface.js +140 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/types.d.ts +91 -0
- package/dist/server/flow-surfaces/runjs-authoring/runtime/types.js +24 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/ctx-api.d.ts +138 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/ctx-api.js +1779 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/filter.d.ts +10 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/filter.js +1583 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/index.d.ts +195 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/index.js +463 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/react-render.d.ts +48 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/react-render.js +379 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/react.d.ts +26 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/react.js +1441 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/resource.d.ts +23 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/resource.js +1427 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/source-patterns.d.ts +91 -0
- package/dist/server/flow-surfaces/runjs-authoring/scan/source-patterns.js +889 -0
- package/dist/server/flow-surfaces/runjs-authoring/types.d.ts +1 -1
- package/dist/server/flow-surfaces/runjs-authoring/unknown-global-stop/index.d.ts +10 -0
- package/dist/server/flow-surfaces/runjs-authoring/unknown-global-stop/index.js +40 -0
- package/dist/server/flow-surfaces/runjs-authoring/validators/index.d.ts +12 -0
- package/dist/server/flow-surfaces/runjs-authoring/validators/index.js +887 -0
- package/dist/server/flow-surfaces/service-helpers.d.ts +29 -0
- package/dist/server/flow-surfaces/service-helpers.js +105 -0
- package/dist/server/flow-surfaces/service-utils.d.ts +15 -3
- package/dist/server/flow-surfaces/service-utils.js +6 -5
- package/dist/server/flow-surfaces/service.d.ts +7 -1
- package/dist/server/flow-surfaces/service.js +488 -94
- package/dist/server/flow-surfaces/types.d.ts +3 -0
- package/dist/server/repository.d.ts +12 -1
- package/dist/server/repository.js +195 -23
- package/dist/swagger/flow-surfaces.d.ts +175 -0
- package/dist/swagger/flow-surfaces.js +130 -51
- package/dist/swagger/index.d.ts +175 -0
- package/package.json +2 -2
|
@@ -0,0 +1,1779 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var ctx_api_exports = {};
|
|
28
|
+
__export(ctx_api_exports, {
|
|
29
|
+
buildInvalidCtxApiMemberAccess: () => buildInvalidCtxApiMemberAccess,
|
|
30
|
+
buildInvalidCtxLibMemberAccess: () => buildInvalidCtxLibMemberAccess,
|
|
31
|
+
collectAstInvalidApiResourceCall: () => collectAstInvalidApiResourceCall,
|
|
32
|
+
collectAstInvalidCtxApiMemberAccess: () => collectAstInvalidCtxApiMemberAccess,
|
|
33
|
+
collectAstInvalidCtxApiPatternAccesses: () => collectAstInvalidCtxApiPatternAccesses,
|
|
34
|
+
collectAstInvalidCtxApiReadonlyWrites: () => collectAstInvalidCtxApiReadonlyWrites,
|
|
35
|
+
collectAstInvalidCtxLibMemberAccess: () => collectAstInvalidCtxLibMemberAccess,
|
|
36
|
+
collectAstInvalidCtxLibPatternAccesses: () => collectAstInvalidCtxLibPatternAccesses,
|
|
37
|
+
collectAstInvalidCtxNonFunctionCall: () => collectAstInvalidCtxNonFunctionCall,
|
|
38
|
+
collectAstWriteTargetNodes: () => collectAstWriteTargetNodes,
|
|
39
|
+
collectCtxApiAliasesFromAst: () => collectCtxApiAliasesFromAst,
|
|
40
|
+
collectCtxApiObjectPatternAliases: () => collectCtxApiObjectPatternAliases,
|
|
41
|
+
collectCtxApiResourceAliasesFromAst: () => collectCtxApiResourceAliasesFromAst,
|
|
42
|
+
collectCtxDefiniteRootAliasesFromAst: () => collectCtxDefiniteRootAliasesFromAst,
|
|
43
|
+
collectCtxLibAliasesFromAst: () => collectCtxLibAliasesFromAst,
|
|
44
|
+
collectCtxLibObjectPatternAliases: () => collectCtxLibObjectPatternAliases,
|
|
45
|
+
collectCtxLibsRootAliasesFromAst: () => collectCtxLibsRootAliasesFromAst,
|
|
46
|
+
collectCtxMethodAliasesFromAst: () => collectCtxMethodAliasesFromAst,
|
|
47
|
+
collectCtxNonFunctionRootAliasesFromAst: () => collectCtxNonFunctionRootAliasesFromAst,
|
|
48
|
+
collectCtxRootAliasesFromAst: () => collectCtxRootAliasesFromAst,
|
|
49
|
+
collectInvalidCtxApiObjectPatternAccesses: () => collectInvalidCtxApiObjectPatternAccesses,
|
|
50
|
+
collectInvalidCtxLibObjectPatternAccesses: () => collectInvalidCtxLibObjectPatternAccesses,
|
|
51
|
+
collectMaybeCtxApiResourceCallsFromAst: () => collectMaybeCtxApiResourceCallsFromAst,
|
|
52
|
+
collectMaybeCtxApiResourceHandleAliasesFromAst: () => collectMaybeCtxApiResourceHandleAliasesFromAst,
|
|
53
|
+
collectPossibleCtxApiCapabilitiesFromAst: () => collectPossibleCtxApiCapabilitiesFromAst,
|
|
54
|
+
filterInvalidCtxApiMemberAccessesForResourceCalls: () => filterInvalidCtxApiMemberAccessesForResourceCalls,
|
|
55
|
+
getCtxApiAliasMemberPath: () => getCtxApiAliasMemberPath,
|
|
56
|
+
getCtxApiCapabilityFromAst: () => getCtxApiCapabilityFromAst,
|
|
57
|
+
getCtxApiCapabilityMemberPath: () => getCtxApiCapabilityMemberPath,
|
|
58
|
+
getCtxApiCapabilityMemberPrefix: () => getCtxApiCapabilityMemberPrefix,
|
|
59
|
+
getCtxApiMemberAccessFromAst: () => getCtxApiMemberAccessFromAst,
|
|
60
|
+
getCtxApiMemberPathFromAst: () => getCtxApiMemberPathFromAst,
|
|
61
|
+
getCtxApiResourceCallFromAst: () => getCtxApiResourceCallFromAst,
|
|
62
|
+
getCtxApiResourceCallIdentity: () => getCtxApiResourceCallIdentity,
|
|
63
|
+
getCtxApiResourceCalleeFromAst: () => getCtxApiResourceCalleeFromAst,
|
|
64
|
+
getCtxApiResourceChainedMethodFromAst: () => getCtxApiResourceChainedMethodFromAst,
|
|
65
|
+
getCtxApiResourceHandleAliasFromAst: () => getCtxApiResourceHandleAliasFromAst,
|
|
66
|
+
getCtxApiResourceHandleAliasIdentity: () => getCtxApiResourceHandleAliasIdentity,
|
|
67
|
+
getCtxApiResourceMethodAliasFromAst: () => getCtxApiResourceMethodAliasFromAst,
|
|
68
|
+
getCtxLibMemberCapability: () => getCtxLibMemberCapability,
|
|
69
|
+
getCtxLibMemberPathFromAst: () => getCtxLibMemberPathFromAst,
|
|
70
|
+
getDirectCtxLibPathFromAst: () => getDirectCtxLibPathFromAst,
|
|
71
|
+
getMaybeCtxApiCapabilityFromAst: () => getMaybeCtxApiCapabilityFromAst,
|
|
72
|
+
getMaybeCtxApiResourceCallFromAst: () => getMaybeCtxApiResourceCallFromAst,
|
|
73
|
+
getMaybeCtxApiResourceHandleAliasFromAst: () => getMaybeCtxApiResourceHandleAliasFromAst,
|
|
74
|
+
getMaybeCtxApiResourceMethodAliasFromAst: () => getMaybeCtxApiResourceMethodAliasFromAst,
|
|
75
|
+
getSuggestedCtxLibMemberImport: () => getSuggestedCtxLibMemberImport,
|
|
76
|
+
getUniqueCtxApiResourceCall: () => getUniqueCtxApiResourceCall,
|
|
77
|
+
getUniqueCtxApiResourceHandleAlias: () => getUniqueCtxApiResourceHandleAlias,
|
|
78
|
+
getWrappedCtxApiResourceChainedMethodFromAst: () => getWrappedCtxApiResourceChainedMethodFromAst,
|
|
79
|
+
isCtxApiCapabilityDefinitelyTruthy: () => isCtxApiCapabilityDefinitelyTruthy,
|
|
80
|
+
isCtxApiResourcePath: () => isCtxApiResourcePath,
|
|
81
|
+
isCtxLibsRootFromAst: () => isCtxLibsRootFromAst,
|
|
82
|
+
selectCtxApiCapability: () => selectCtxApiCapability,
|
|
83
|
+
trimCtxApiAliasesAfterWrites: () => trimCtxApiAliasesAfterWrites,
|
|
84
|
+
uniqueCtxApiCapabilities: () => uniqueCtxApiCapabilities
|
|
85
|
+
});
|
|
86
|
+
module.exports = __toCommonJS(ctx_api_exports);
|
|
87
|
+
var import_walk = require("../ast/walk");
|
|
88
|
+
var import_bindings = require("../ast/bindings");
|
|
89
|
+
var import_source = require("../ast/source");
|
|
90
|
+
var import_execution = require("../ast/execution");
|
|
91
|
+
var import_static_values = require("../ast/static-values");
|
|
92
|
+
var import_request_config = require("../ast/request-config");
|
|
93
|
+
var import_constants = require("../runtime/constants");
|
|
94
|
+
function collectCtxRootAliasesFromAst(ast, source, identifierBindings) {
|
|
95
|
+
return collectCtxRootAliasesFromAstInternal(ast, source, identifierBindings, false);
|
|
96
|
+
}
|
|
97
|
+
function collectCtxDefiniteRootAliasesFromAst(ast, source, identifierBindings) {
|
|
98
|
+
return collectCtxRootAliasesFromAstInternal(ast, source, identifierBindings, true);
|
|
99
|
+
}
|
|
100
|
+
function collectCtxRootAliasesFromAstInternal(ast, source, identifierBindings, definiteOnly) {
|
|
101
|
+
const aliases = [];
|
|
102
|
+
const writes = (0, import_execution.collectAstIdentifierWritesFromAst)(ast, source);
|
|
103
|
+
const addAlias = (name, node, ancestors, isVar = false, scopeOverride) => {
|
|
104
|
+
const scope = scopeOverride || (0, import_bindings.getAstBindingScopeRange)(ancestors, source.length, isVar);
|
|
105
|
+
aliases.push({
|
|
106
|
+
capability: "ctx",
|
|
107
|
+
declarationStart: typeof (node == null ? void 0 : node.start) === "number" ? node.start : scope.start,
|
|
108
|
+
executionScope: (0, import_bindings.getAstExecutionScopeRange)(ancestors, source.length),
|
|
109
|
+
name,
|
|
110
|
+
start: typeof (node == null ? void 0 : node.start) === "number" ? node.start : scope.start,
|
|
111
|
+
end: scope.end
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
const getActiveAliases = () => (0, import_static_values.trimAstAliasesAfterWrites)(aliases, writes, identifierBindings);
|
|
115
|
+
(0, import_walk.walkAstAncestor)(ast, {
|
|
116
|
+
AssignmentExpression(node, ancestors) {
|
|
117
|
+
var _a;
|
|
118
|
+
const isAliasAssignmentOperator = definiteOnly ? (0, import_static_values.isAstDefiniteAssignmentOperator)(node.operator) : (0, import_static_values.isAstCtxApiAliasAssignmentOperator)(node.operator);
|
|
119
|
+
if (!isAliasAssignmentOperator || ((_a = node.left) == null ? void 0 : _a.type) !== "Identifier") {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const isCtxRoot = definiteOnly ? isDefiniteCtxRootFromAst(node.right, getActiveAliases(), identifierBindings) : (0, import_static_values.isCtxRootFromAst)(node.right, getActiveAliases(), identifierBindings);
|
|
123
|
+
if (isCtxRoot) {
|
|
124
|
+
addAlias(
|
|
125
|
+
node.left.name,
|
|
126
|
+
node,
|
|
127
|
+
ancestors,
|
|
128
|
+
false,
|
|
129
|
+
(0, import_static_values.getAstAssignmentTargetScope)(node.left, ancestors, source.length, identifierBindings)
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
VariableDeclarator(node, ancestors) {
|
|
134
|
+
var _a;
|
|
135
|
+
const isCtxRoot = definiteOnly ? isDefiniteCtxRootFromAst(node.init, getActiveAliases(), identifierBindings) : (0, import_static_values.isCtxRootFromAst)(node.init, getActiveAliases(), identifierBindings);
|
|
136
|
+
if (((_a = node.id) == null ? void 0 : _a.type) !== "Identifier" || !isCtxRoot) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const declaration = (0, import_bindings.findAstAncestor)(ancestors, "VariableDeclaration");
|
|
140
|
+
addAlias(node.id.name, node, ancestors, (declaration == null ? void 0 : declaration.kind) === "var");
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return (0, import_static_values.trimAstAliasesAfterWrites)(aliases, writes, identifierBindings);
|
|
144
|
+
}
|
|
145
|
+
function isDefiniteCtxRootFromAst(node, aliases, identifierBindings) {
|
|
146
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
147
|
+
if (!unwrapped) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
if (unwrapped.type === "ConditionalExpression") {
|
|
151
|
+
return isDefiniteCtxRootFromAst(unwrapped.consequent, aliases, identifierBindings) && isDefiniteCtxRootFromAst(unwrapped.alternate, aliases, identifierBindings);
|
|
152
|
+
}
|
|
153
|
+
if (unwrapped.type === "SequenceExpression") {
|
|
154
|
+
const expressions = unwrapped.expressions || [];
|
|
155
|
+
return isDefiniteCtxRootFromAst(expressions[expressions.length - 1], aliases, identifierBindings);
|
|
156
|
+
}
|
|
157
|
+
if (unwrapped.type === "AssignmentExpression" && (0, import_static_values.isAstDefiniteAssignmentOperator)(unwrapped.operator)) {
|
|
158
|
+
return isDefiniteCtxRootFromAst(unwrapped.right, aliases, identifierBindings);
|
|
159
|
+
}
|
|
160
|
+
if ((0, import_static_values.isUnshadowedCtxIdentifier)(unwrapped, identifierBindings)) {
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
if (unwrapped.type !== "Identifier") {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
const index = typeof unwrapped.start === "number" ? unwrapped.start : 0;
|
|
167
|
+
return !!(0, import_static_values.resolveAstAliasBinding)(unwrapped.name, index, aliases, identifierBindings);
|
|
168
|
+
}
|
|
169
|
+
function collectCtxNonFunctionRootAliasesFromAst(ast, source, ctxRootAliases, identifierBindings, modelUse = "") {
|
|
170
|
+
const aliases = [];
|
|
171
|
+
const writes = (0, import_execution.collectAstIdentifierWritesFromAst)(ast, source);
|
|
172
|
+
const addAlias = (name, member, node, ancestors, isVar = false, scopeOverride) => {
|
|
173
|
+
const scope = scopeOverride || (0, import_bindings.getAstBindingScopeRange)(ancestors, source.length, isVar);
|
|
174
|
+
aliases.push({
|
|
175
|
+
capability: `ctx.${member}`,
|
|
176
|
+
declarationStart: typeof (node == null ? void 0 : node.start) === "number" ? node.start : scope.start,
|
|
177
|
+
executionScope: (0, import_bindings.getAstExecutionScopeRange)(ancestors, source.length),
|
|
178
|
+
member,
|
|
179
|
+
name,
|
|
180
|
+
start: typeof (node == null ? void 0 : node.start) === "number" ? node.start : scope.start,
|
|
181
|
+
end: scope.end
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
const collectPatternAliases = (pattern, node, ancestors, isVar = false) => {
|
|
185
|
+
(0, import_static_values.collectAstObjectPatternAliases)(pattern, (name, member, aliasNode) => {
|
|
186
|
+
if (isRunJsCtxNonFunctionRoot(member, modelUse)) {
|
|
187
|
+
addAlias(name, member, aliasNode || node, ancestors, isVar);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
(0, import_walk.walkAstAncestor)(ast, {
|
|
192
|
+
AssignmentExpression(node, ancestors) {
|
|
193
|
+
var _a, _b;
|
|
194
|
+
if (!(0, import_static_values.isAstDefiniteAssignmentOperator)(node.operator)) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const member = getCtxNonFunctionRootMemberFromAst(node.right, ctxRootAliases, identifierBindings, modelUse);
|
|
198
|
+
if (((_a = node.left) == null ? void 0 : _a.type) === "Identifier" && member) {
|
|
199
|
+
addAlias(
|
|
200
|
+
node.left.name,
|
|
201
|
+
member,
|
|
202
|
+
node,
|
|
203
|
+
ancestors,
|
|
204
|
+
false,
|
|
205
|
+
(0, import_static_values.getAstAssignmentTargetScope)(node.left, ancestors, source.length, identifierBindings)
|
|
206
|
+
);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (node.operator === "=" && ((_b = node.left) == null ? void 0 : _b.type) === "ObjectPattern") {
|
|
210
|
+
if (isDefiniteCtxRootFromAst(node.right, ctxRootAliases, identifierBindings)) {
|
|
211
|
+
collectPatternAliases(node.left, node, ancestors);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
VariableDeclarator(node, ancestors) {
|
|
216
|
+
var _a, _b;
|
|
217
|
+
const declaration = (0, import_bindings.findAstAncestor)(ancestors, "VariableDeclaration");
|
|
218
|
+
const isVar = (declaration == null ? void 0 : declaration.kind) === "var";
|
|
219
|
+
const member = getCtxNonFunctionRootMemberFromAst(node.init, ctxRootAliases, identifierBindings, modelUse);
|
|
220
|
+
if (((_a = node.id) == null ? void 0 : _a.type) === "Identifier" && member) {
|
|
221
|
+
addAlias(node.id.name, member, node, ancestors, isVar);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (((_b = node.id) == null ? void 0 : _b.type) === "ObjectPattern" && isDefiniteCtxRootFromAst(node.init, ctxRootAliases, identifierBindings)) {
|
|
225
|
+
collectPatternAliases(node.id, node, ancestors, isVar);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
return (0, import_static_values.trimAstAliasesAfterWrites)(aliases, writes, identifierBindings);
|
|
230
|
+
}
|
|
231
|
+
function collectAstInvalidCtxNonFunctionCall(node, ctxRootAliases, ctxNonFunctionRootAliases, identifierBindings, modelUse = "") {
|
|
232
|
+
const callee = (0, import_bindings.unwrapAstChainExpression)(node == null ? void 0 : node.callee);
|
|
233
|
+
const directMember = getCtxNonFunctionRootMemberFromAst(callee, ctxRootAliases, identifierBindings, modelUse);
|
|
234
|
+
if (directMember) {
|
|
235
|
+
return [
|
|
236
|
+
{
|
|
237
|
+
capability: `ctx.${directMember}`,
|
|
238
|
+
index: typeof (node == null ? void 0 : node.start) === "number" ? node.start : 0,
|
|
239
|
+
member: directMember,
|
|
240
|
+
ruleId: "runjs-ctx-member-not-callable"
|
|
241
|
+
}
|
|
242
|
+
];
|
|
243
|
+
}
|
|
244
|
+
if ((callee == null ? void 0 : callee.type) !== "Identifier") {
|
|
245
|
+
return [];
|
|
246
|
+
}
|
|
247
|
+
const alias = (0, import_static_values.resolveAstAliasBinding)(
|
|
248
|
+
callee.name,
|
|
249
|
+
typeof callee.start === "number" ? callee.start : typeof (node == null ? void 0 : node.start) === "number" ? node.start : 0,
|
|
250
|
+
ctxNonFunctionRootAliases,
|
|
251
|
+
identifierBindings
|
|
252
|
+
);
|
|
253
|
+
if (!alias) {
|
|
254
|
+
return [];
|
|
255
|
+
}
|
|
256
|
+
return [
|
|
257
|
+
{
|
|
258
|
+
capability: alias.capability,
|
|
259
|
+
index: typeof (node == null ? void 0 : node.start) === "number" ? node.start : alias.start,
|
|
260
|
+
member: alias.member,
|
|
261
|
+
ruleId: "runjs-ctx-member-not-callable"
|
|
262
|
+
}
|
|
263
|
+
];
|
|
264
|
+
}
|
|
265
|
+
function getCtxNonFunctionRootMemberFromAst(node, ctxRootAliases, identifierBindings, modelUse) {
|
|
266
|
+
const member = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
267
|
+
if (!member || member.type !== "MemberExpression") {
|
|
268
|
+
return "";
|
|
269
|
+
}
|
|
270
|
+
const propertyName = (0, import_static_values.getAstStaticPropertyName)(member);
|
|
271
|
+
if (!isRunJsCtxNonFunctionRoot(propertyName, modelUse)) {
|
|
272
|
+
return "";
|
|
273
|
+
}
|
|
274
|
+
return isDefiniteCtxRootFromAst(member.object, ctxRootAliases, identifierBindings) ? propertyName : "";
|
|
275
|
+
}
|
|
276
|
+
function isRunJsCtxNonFunctionRoot(member, modelUse) {
|
|
277
|
+
var _a;
|
|
278
|
+
return import_constants.RUNJS_CTX_NON_FUNCTION_ROOTS.has(member) || Boolean(modelUse && ((_a = import_constants.RUNJS_CTX_NON_FUNCTION_ROOTS_BY_MODEL_USE[modelUse]) == null ? void 0 : _a.has(member)));
|
|
279
|
+
}
|
|
280
|
+
function collectCtxMethodAliasesFromAst(ast, source, identifierBindings) {
|
|
281
|
+
const aliases = [];
|
|
282
|
+
const addAlias = (name, method, node, ancestors, isVar = false) => {
|
|
283
|
+
const scope = (0, import_bindings.getAstBindingScopeRange)(ancestors, source.length, isVar);
|
|
284
|
+
aliases.push({
|
|
285
|
+
capability: `ctx.${method}`,
|
|
286
|
+
method,
|
|
287
|
+
name,
|
|
288
|
+
start: typeof node.start === "number" ? node.start : scope.start,
|
|
289
|
+
end: scope.end
|
|
290
|
+
});
|
|
291
|
+
};
|
|
292
|
+
(0, import_walk.walkAstAncestor)(ast, {
|
|
293
|
+
AssignmentExpression(node, ancestors) {
|
|
294
|
+
var _a;
|
|
295
|
+
if (node.operator !== "=" || ((_a = node.left) == null ? void 0 : _a.type) !== "Identifier") {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
const method = (0, import_static_values.getCtxMethodName)(node.right, identifierBindings);
|
|
299
|
+
if (method) {
|
|
300
|
+
addAlias(node.left.name, method, node, ancestors);
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
VariableDeclarator(node, ancestors) {
|
|
304
|
+
var _a, _b;
|
|
305
|
+
const method = (0, import_static_values.getCtxMethodName)(node.init, identifierBindings);
|
|
306
|
+
const declaration = (0, import_bindings.findAstAncestor)(ancestors, "VariableDeclaration");
|
|
307
|
+
const isVar = (declaration == null ? void 0 : declaration.kind) === "var";
|
|
308
|
+
if (((_a = node.id) == null ? void 0 : _a.type) === "Identifier" && method) {
|
|
309
|
+
addAlias(node.id.name, method, node, ancestors, isVar);
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
if (((_b = node.id) == null ? void 0 : _b.type) === "ObjectPattern" && (0, import_static_values.isUnshadowedCtxIdentifier)(node.init, identifierBindings)) {
|
|
313
|
+
(0, import_static_values.collectAstObjectPatternAliases)(node.id, (name, member, aliasNode) => {
|
|
314
|
+
if (import_constants.AST_CTX_METHOD_NAMES.has(member)) {
|
|
315
|
+
addAlias(name, member, aliasNode || node, ancestors, isVar);
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
return aliases;
|
|
322
|
+
}
|
|
323
|
+
function collectCtxApiAliasesFromAst(ast, source, identifierBindings) {
|
|
324
|
+
const aliases = [];
|
|
325
|
+
const writes = (0, import_execution.collectAstIdentifierWritesFromAst)(ast, source);
|
|
326
|
+
const addAlias = (name, capability, node, ancestors, isVar = false) => {
|
|
327
|
+
const scope = (0, import_bindings.getAstBindingScopeRange)(ancestors, source.length, isVar);
|
|
328
|
+
aliases.push({
|
|
329
|
+
capability,
|
|
330
|
+
declarationStart: typeof (node == null ? void 0 : node.start) === "number" ? node.start : scope.start,
|
|
331
|
+
executionScope: (0, import_bindings.getAstExecutionScopeRange)(ancestors, source.length),
|
|
332
|
+
name,
|
|
333
|
+
start: typeof (node == null ? void 0 : node.start) === "number" ? node.start : scope.start,
|
|
334
|
+
end: scope.end
|
|
335
|
+
});
|
|
336
|
+
};
|
|
337
|
+
const getActiveAliases = () => trimCtxApiAliasesAfterWrites(aliases, writes, identifierBindings);
|
|
338
|
+
(0, import_walk.walkAstAncestor)(ast, {
|
|
339
|
+
AssignmentExpression(node, ancestors) {
|
|
340
|
+
var _a, _b;
|
|
341
|
+
if (!(0, import_static_values.isAstCtxApiAliasAssignmentOperator)(node.operator)) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
const activeAliases = getActiveAliases();
|
|
345
|
+
const capability = getCtxApiCapabilityFromAst(node.right, activeAliases, identifierBindings) || getMaybeCtxApiCapabilityFromAst(node.right, activeAliases, identifierBindings);
|
|
346
|
+
if (((_a = node.left) == null ? void 0 : _a.type) === "Identifier" && capability) {
|
|
347
|
+
addAlias(node.left.name, capability, node, ancestors);
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
if (node.operator === "=" && ((_b = node.left) == null ? void 0 : _b.type) === "ObjectPattern") {
|
|
351
|
+
collectCtxApiObjectPatternAliases(node.left, capability, (name, aliasCapability, aliasNode) => {
|
|
352
|
+
addAlias(name, aliasCapability, aliasNode || node, ancestors);
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
VariableDeclarator(node, ancestors) {
|
|
357
|
+
var _a, _b;
|
|
358
|
+
const declaration = (0, import_bindings.findAstAncestor)(ancestors, "VariableDeclaration");
|
|
359
|
+
const isVar = (declaration == null ? void 0 : declaration.kind) === "var";
|
|
360
|
+
const activeAliases = getActiveAliases();
|
|
361
|
+
const capability = getCtxApiCapabilityFromAst(node.init, activeAliases, identifierBindings) || getMaybeCtxApiCapabilityFromAst(node.init, activeAliases, identifierBindings);
|
|
362
|
+
if (((_a = node.id) == null ? void 0 : _a.type) === "Identifier" && capability) {
|
|
363
|
+
addAlias(node.id.name, capability, node, ancestors, isVar);
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
if (((_b = node.id) == null ? void 0 : _b.type) === "ObjectPattern") {
|
|
367
|
+
collectCtxApiObjectPatternAliases(node.id, capability, (name, aliasCapability, aliasNode) => {
|
|
368
|
+
addAlias(name, aliasCapability, aliasNode || node, ancestors, isVar);
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
return trimCtxApiAliasesAfterWrites(aliases, writes, identifierBindings);
|
|
374
|
+
}
|
|
375
|
+
function collectCtxApiObjectPatternAliases(pattern, capability, addAlias) {
|
|
376
|
+
if (capability === "ctx.api") {
|
|
377
|
+
for (const property of (pattern == null ? void 0 : pattern.properties) || []) {
|
|
378
|
+
if (!property || property.type !== "Property") {
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
const member = (0, import_static_values.getAstStaticPropertyName)(property);
|
|
382
|
+
const alias = (0, import_static_values.getAstBindingIdentifierName)(property.value);
|
|
383
|
+
const aliasNode = (0, import_static_values.getAstBindingIdentifierNode)(property.value);
|
|
384
|
+
if (member && alias && import_constants.RUNJS_CTX_API_ALLOWED_MEMBERS.has(member)) {
|
|
385
|
+
addAlias(alias, `ctx.api.${member}`, aliasNode);
|
|
386
|
+
}
|
|
387
|
+
if (member === "auth") {
|
|
388
|
+
const nestedPattern = (0, import_static_values.getAstObjectPatternFromValue)(property.value);
|
|
389
|
+
if (nestedPattern) {
|
|
390
|
+
collectCtxApiObjectPatternAliases(nestedPattern, "ctx.api.auth", addAlias);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
if (capability === "ctx.api.auth") {
|
|
397
|
+
(0, import_static_values.collectAstObjectPatternAliases)(pattern, (name, member, aliasNode) => {
|
|
398
|
+
if (import_constants.RUNJS_CTX_API_AUTH_ALLOWED_MEMBERS.has(member)) {
|
|
399
|
+
addAlias(name, `ctx.api.auth.${member}`, aliasNode);
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
function trimCtxApiAliasesAfterWrites(aliases, writes, identifierBindings) {
|
|
405
|
+
return (0, import_static_values.trimAstAliasesAfterWrites)(aliases, writes, identifierBindings);
|
|
406
|
+
}
|
|
407
|
+
function collectCtxLibsRootAliasesFromAst(ast, source, identifierBindings) {
|
|
408
|
+
const aliases = [];
|
|
409
|
+
const writes = (0, import_execution.collectAstIdentifierWritesFromAst)(ast, source);
|
|
410
|
+
const addAlias = (name, node, ancestors, isVar = false) => {
|
|
411
|
+
const scope = (0, import_bindings.getAstBindingScopeRange)(ancestors, source.length, isVar);
|
|
412
|
+
aliases.push({
|
|
413
|
+
capability: "ctx.libs",
|
|
414
|
+
declarationStart: typeof (node == null ? void 0 : node.start) === "number" ? node.start : scope.start,
|
|
415
|
+
executionScope: (0, import_bindings.getAstExecutionScopeRange)(ancestors, source.length),
|
|
416
|
+
name,
|
|
417
|
+
start: typeof (node == null ? void 0 : node.start) === "number" ? node.start : scope.start,
|
|
418
|
+
end: scope.end
|
|
419
|
+
});
|
|
420
|
+
};
|
|
421
|
+
const getActiveAliases = () => (0, import_static_values.trimAstAliasesAfterWrites)(aliases, writes, identifierBindings);
|
|
422
|
+
(0, import_walk.walkAstAncestor)(ast, {
|
|
423
|
+
AssignmentExpression(node, ancestors) {
|
|
424
|
+
var _a;
|
|
425
|
+
if (!(0, import_static_values.isAstCtxApiAliasAssignmentOperator)(node.operator)) {
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
if (((_a = node.left) == null ? void 0 : _a.type) === "Identifier" && isCtxLibsRootFromAst(node.right, getActiveAliases(), identifierBindings)) {
|
|
429
|
+
addAlias(node.left.name, node, ancestors);
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
VariableDeclarator(node, ancestors) {
|
|
433
|
+
var _a;
|
|
434
|
+
if (((_a = node.id) == null ? void 0 : _a.type) !== "Identifier" || !isCtxLibsRootFromAst(node.init, getActiveAliases(), identifierBindings)) {
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
const declaration = (0, import_bindings.findAstAncestor)(ancestors, "VariableDeclaration");
|
|
438
|
+
addAlias(node.id.name, node, ancestors, (declaration == null ? void 0 : declaration.kind) === "var");
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
return (0, import_static_values.trimAstAliasesAfterWrites)(aliases, writes, identifierBindings);
|
|
442
|
+
}
|
|
443
|
+
function collectCtxLibAliasesFromAst(ast, source, rootAliases, identifierBindings) {
|
|
444
|
+
const aliases = [];
|
|
445
|
+
const writes = (0, import_execution.collectAstIdentifierWritesFromAst)(ast, source);
|
|
446
|
+
const addAlias = (name, library, capability, node, ancestors, isVar = false) => {
|
|
447
|
+
const scope = (0, import_bindings.getAstBindingScopeRange)(ancestors, source.length, isVar);
|
|
448
|
+
aliases.push({
|
|
449
|
+
capability,
|
|
450
|
+
declarationStart: typeof (node == null ? void 0 : node.start) === "number" ? node.start : scope.start,
|
|
451
|
+
executionScope: (0, import_bindings.getAstExecutionScopeRange)(ancestors, source.length),
|
|
452
|
+
library,
|
|
453
|
+
name,
|
|
454
|
+
start: typeof (node == null ? void 0 : node.start) === "number" ? node.start : scope.start,
|
|
455
|
+
end: scope.end
|
|
456
|
+
});
|
|
457
|
+
};
|
|
458
|
+
const getActiveAliases = () => (0, import_static_values.trimAstAliasesAfterWrites)(aliases, writes, identifierBindings);
|
|
459
|
+
(0, import_walk.walkAstAncestor)(ast, {
|
|
460
|
+
AssignmentExpression(node, ancestors) {
|
|
461
|
+
var _a, _b;
|
|
462
|
+
if (!(0, import_static_values.isAstCtxApiAliasAssignmentOperator)(node.operator)) {
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
const activeAliases = getActiveAliases();
|
|
466
|
+
const sourcePath = getCtxLibMemberPathFromAst(node.right, activeAliases, rootAliases, identifierBindings, source);
|
|
467
|
+
if (((_a = node.left) == null ? void 0 : _a.type) === "Identifier" && sourcePath && !sourcePath.hasDynamicMember && !sourcePath.members.length) {
|
|
468
|
+
addAlias(node.left.name, sourcePath.library, sourcePath.rootCapability, node, ancestors);
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
if (node.operator === "=" && ((_b = node.left) == null ? void 0 : _b.type) === "ObjectPattern") {
|
|
472
|
+
collectCtxLibObjectPatternAliases(
|
|
473
|
+
node.left,
|
|
474
|
+
node.right,
|
|
475
|
+
rootAliases,
|
|
476
|
+
identifierBindings,
|
|
477
|
+
(name, alias, aliasNode) => {
|
|
478
|
+
addAlias(name, alias.library, alias.capability, aliasNode || node, ancestors);
|
|
479
|
+
}
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
},
|
|
483
|
+
VariableDeclarator(node, ancestors) {
|
|
484
|
+
var _a, _b;
|
|
485
|
+
const declaration = (0, import_bindings.findAstAncestor)(ancestors, "VariableDeclaration");
|
|
486
|
+
const isVar = (declaration == null ? void 0 : declaration.kind) === "var";
|
|
487
|
+
const activeAliases = getActiveAliases();
|
|
488
|
+
const sourcePath = getCtxLibMemberPathFromAst(node.init, activeAliases, rootAliases, identifierBindings, source);
|
|
489
|
+
if (((_a = node.id) == null ? void 0 : _a.type) === "Identifier" && sourcePath && !sourcePath.hasDynamicMember && !sourcePath.members.length) {
|
|
490
|
+
addAlias(node.id.name, sourcePath.library, sourcePath.rootCapability, node, ancestors, isVar);
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
if (((_b = node.id) == null ? void 0 : _b.type) === "ObjectPattern") {
|
|
494
|
+
collectCtxLibObjectPatternAliases(
|
|
495
|
+
node.id,
|
|
496
|
+
node.init,
|
|
497
|
+
rootAliases,
|
|
498
|
+
identifierBindings,
|
|
499
|
+
(name, alias, aliasNode) => {
|
|
500
|
+
addAlias(name, alias.library, alias.capability, aliasNode || node, ancestors, isVar);
|
|
501
|
+
}
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
return (0, import_static_values.trimAstAliasesAfterWrites)(aliases, writes, identifierBindings);
|
|
507
|
+
}
|
|
508
|
+
function collectCtxLibObjectPatternAliases(pattern, sourceNode, rootAliases, identifierBindings, addAlias) {
|
|
509
|
+
if (!isCtxLibsRootFromAst(sourceNode, rootAliases, identifierBindings)) {
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
(0, import_static_values.collectAstObjectPatternAliases)(pattern, (name, member, aliasNode) => {
|
|
513
|
+
if (member) {
|
|
514
|
+
addAlias(name, { capability: `ctx.libs.${member}`, library: member }, aliasNode);
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
function collectCtxApiResourceAliasesFromAst(ast, source, ctxApiAliases, stringBindings, staticFilterValueBindings, identifierBindings) {
|
|
519
|
+
const handles = [];
|
|
520
|
+
const methods = [];
|
|
521
|
+
const writes = (0, import_execution.collectAstIdentifierWritesFromAst)(ast, source);
|
|
522
|
+
const addHandleAlias = (name, resourceFactoryCall, node, ancestors, isVar = false) => {
|
|
523
|
+
var _a;
|
|
524
|
+
const scope = (0, import_bindings.getAstBindingScopeRange)(ancestors, source.length, isVar);
|
|
525
|
+
handles.push({
|
|
526
|
+
calleeSource: resourceFactoryCall.calleeSource,
|
|
527
|
+
declarationStart: typeof (node == null ? void 0 : node.start) === "number" ? node.start : scope.start,
|
|
528
|
+
executionScope: (0, import_bindings.getAstExecutionScopeRange)(ancestors, source.length),
|
|
529
|
+
name,
|
|
530
|
+
dataSourceKey: "args" in resourceFactoryCall ? (0, import_request_config.getRunJsApiResourceCallDataSourceKey)(
|
|
531
|
+
resourceFactoryCall.args,
|
|
532
|
+
source,
|
|
533
|
+
stringBindings,
|
|
534
|
+
staticFilterValueBindings,
|
|
535
|
+
identifierBindings
|
|
536
|
+
) : resourceFactoryCall.dataSourceKey,
|
|
537
|
+
resourceName: "args" in resourceFactoryCall ? (0, import_static_values.resolveRunJsStaticString)((_a = resourceFactoryCall.args) == null ? void 0 : _a[0], source, stringBindings, identifierBindings) : resourceFactoryCall.resourceName,
|
|
538
|
+
start: typeof (node == null ? void 0 : node.start) === "number" ? node.start : scope.start,
|
|
539
|
+
end: scope.end
|
|
540
|
+
});
|
|
541
|
+
};
|
|
542
|
+
const addMethodAlias = (name, method, node, ancestors, isVar = false) => {
|
|
543
|
+
const scope = (0, import_bindings.getAstBindingScopeRange)(ancestors, source.length, isVar);
|
|
544
|
+
methods.push({
|
|
545
|
+
declarationStart: typeof node.start === "number" ? node.start : scope.start,
|
|
546
|
+
executionScope: (0, import_bindings.getAstExecutionScopeRange)(ancestors, source.length),
|
|
547
|
+
method,
|
|
548
|
+
name,
|
|
549
|
+
start: typeof (node == null ? void 0 : node.start) === "number" ? node.start : scope.start,
|
|
550
|
+
end: scope.end
|
|
551
|
+
});
|
|
552
|
+
};
|
|
553
|
+
const getActiveHandles = () => (0, import_static_values.trimAstAliasesAfterWrites)(handles, writes, identifierBindings);
|
|
554
|
+
const getActiveMethods = () => (0, import_static_values.trimAstAliasesAfterWrites)(methods, writes, identifierBindings);
|
|
555
|
+
const collectMethodAliases = (pattern, sourceNode, ancestors, isVar = false) => {
|
|
556
|
+
if (!sourceNode) {
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
(0, import_static_values.collectAstObjectPatternAliases)(pattern, (name, method, aliasNode) => {
|
|
560
|
+
if (import_constants.RUNJS_RESOURCE_METHODS.has(method)) {
|
|
561
|
+
addMethodAlias(name, method, aliasNode || pattern, ancestors, isVar);
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
};
|
|
565
|
+
const getDirectResourceHandleSource = (node) => getCtxApiResourceCallFromAst(node, ctxApiAliases, source, identifierBindings) || getCtxApiResourceHandleAliasFromAst(node, getActiveHandles(), identifierBindings);
|
|
566
|
+
const getMaybeResourceHandleSource = (node) => getUniqueCtxApiResourceHandleSource(collectPossibleResourceHandleSources(node));
|
|
567
|
+
const collectPossibleResourceHandleSources = (node) => {
|
|
568
|
+
const directSource = getDirectResourceHandleSource(node);
|
|
569
|
+
if (directSource) {
|
|
570
|
+
return [directSource];
|
|
571
|
+
}
|
|
572
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
573
|
+
if (!unwrapped) {
|
|
574
|
+
return [];
|
|
575
|
+
}
|
|
576
|
+
if (unwrapped.type === "ConditionalExpression") {
|
|
577
|
+
return [
|
|
578
|
+
...collectPossibleResourceHandleSources(unwrapped.consequent),
|
|
579
|
+
...collectPossibleResourceHandleSources(unwrapped.alternate)
|
|
580
|
+
];
|
|
581
|
+
}
|
|
582
|
+
if (unwrapped.type === "LogicalExpression") {
|
|
583
|
+
const leftSources = collectPossibleResourceHandleSources(unwrapped.left);
|
|
584
|
+
const rightSources = collectPossibleResourceHandleSources(unwrapped.right);
|
|
585
|
+
return [...leftSources, ...rightSources];
|
|
586
|
+
}
|
|
587
|
+
if (unwrapped.type === "SequenceExpression") {
|
|
588
|
+
const expressions = unwrapped.expressions || [];
|
|
589
|
+
return collectPossibleResourceHandleSources(expressions[expressions.length - 1]);
|
|
590
|
+
}
|
|
591
|
+
if (unwrapped.type === "AssignmentExpression" && (0, import_static_values.isAstCtxApiAliasAssignmentOperator)(unwrapped.operator)) {
|
|
592
|
+
return collectPossibleResourceHandleSources(unwrapped.right);
|
|
593
|
+
}
|
|
594
|
+
return [];
|
|
595
|
+
};
|
|
596
|
+
const getResourceHandleSourceIdentity = (resourceHandleSource) => {
|
|
597
|
+
var _a;
|
|
598
|
+
const dataSourceKey = "args" in resourceHandleSource ? (0, import_request_config.getRunJsApiResourceCallDataSourceKey)(
|
|
599
|
+
resourceHandleSource.args,
|
|
600
|
+
source,
|
|
601
|
+
stringBindings,
|
|
602
|
+
staticFilterValueBindings,
|
|
603
|
+
identifierBindings
|
|
604
|
+
) : resourceHandleSource.dataSourceKey;
|
|
605
|
+
const resourceName = "args" in resourceHandleSource ? (0, import_static_values.resolveRunJsStaticString)((_a = resourceHandleSource.args) == null ? void 0 : _a[0], source, stringBindings, identifierBindings) : resourceHandleSource.resourceName;
|
|
606
|
+
if (typeof resourceName !== "string" && typeof dataSourceKey !== "string") {
|
|
607
|
+
return void 0;
|
|
608
|
+
}
|
|
609
|
+
return `${dataSourceKey ?? ""}:${resourceName ?? ""}`;
|
|
610
|
+
};
|
|
611
|
+
const getUniqueCtxApiResourceHandleSource = (sources) => {
|
|
612
|
+
if (sources.length <= 1) {
|
|
613
|
+
return sources[0];
|
|
614
|
+
}
|
|
615
|
+
const firstIdentity = getResourceHandleSourceIdentity(sources[0]);
|
|
616
|
+
if (!firstIdentity || sources.some((entry) => getResourceHandleSourceIdentity(entry) !== firstIdentity)) {
|
|
617
|
+
return void 0;
|
|
618
|
+
}
|
|
619
|
+
return sources[0];
|
|
620
|
+
};
|
|
621
|
+
const getDirectResourceMethodSource = (node) => {
|
|
622
|
+
const methodAlias = getCtxApiResourceMethodAliasFromAst(node, getActiveMethods(), identifierBindings);
|
|
623
|
+
if (methodAlias) {
|
|
624
|
+
return { method: methodAlias.method };
|
|
625
|
+
}
|
|
626
|
+
const member = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
627
|
+
if (!member || member.type !== "MemberExpression") {
|
|
628
|
+
return void 0;
|
|
629
|
+
}
|
|
630
|
+
const method = (0, import_static_values.getAstStaticPropertyName)(member);
|
|
631
|
+
if (!import_constants.RUNJS_RESOURCE_METHODS.has(method) || !getMaybeResourceHandleSource(member.object)) {
|
|
632
|
+
return void 0;
|
|
633
|
+
}
|
|
634
|
+
return { method };
|
|
635
|
+
};
|
|
636
|
+
const getMaybeResourceMethodSource = (node) => {
|
|
637
|
+
const sources = collectPossibleResourceMethodSources(node);
|
|
638
|
+
return sources[0];
|
|
639
|
+
};
|
|
640
|
+
const collectPossibleResourceMethodSources = (node) => {
|
|
641
|
+
const directSource = getDirectResourceMethodSource(node);
|
|
642
|
+
if (directSource) {
|
|
643
|
+
return [directSource];
|
|
644
|
+
}
|
|
645
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
646
|
+
if (!unwrapped) {
|
|
647
|
+
return [];
|
|
648
|
+
}
|
|
649
|
+
if (unwrapped.type === "ConditionalExpression") {
|
|
650
|
+
return [
|
|
651
|
+
...collectPossibleResourceMethodSources(unwrapped.consequent),
|
|
652
|
+
...collectPossibleResourceMethodSources(unwrapped.alternate)
|
|
653
|
+
];
|
|
654
|
+
}
|
|
655
|
+
if (unwrapped.type === "LogicalExpression") {
|
|
656
|
+
const leftSources = collectPossibleResourceMethodSources(unwrapped.left);
|
|
657
|
+
const rightSources = collectPossibleResourceMethodSources(unwrapped.right);
|
|
658
|
+
return [...leftSources, ...rightSources];
|
|
659
|
+
}
|
|
660
|
+
if (unwrapped.type === "SequenceExpression") {
|
|
661
|
+
const expressions = unwrapped.expressions || [];
|
|
662
|
+
return collectPossibleResourceMethodSources(expressions[expressions.length - 1]);
|
|
663
|
+
}
|
|
664
|
+
if (unwrapped.type === "AssignmentExpression" && (0, import_static_values.isAstCtxApiAliasAssignmentOperator)(unwrapped.operator)) {
|
|
665
|
+
return collectPossibleResourceMethodSources(unwrapped.right);
|
|
666
|
+
}
|
|
667
|
+
return [];
|
|
668
|
+
};
|
|
669
|
+
(0, import_walk.walkAstAncestor)(ast, {
|
|
670
|
+
AssignmentExpression(node, ancestors) {
|
|
671
|
+
var _a, _b;
|
|
672
|
+
if ((0, import_static_values.isAstCtxApiAliasAssignmentOperator)(node.operator) && ((_a = node.left) == null ? void 0 : _a.type) === "Identifier") {
|
|
673
|
+
const resourceMethodSource = getMaybeResourceMethodSource(node.right);
|
|
674
|
+
if (resourceMethodSource) {
|
|
675
|
+
addMethodAlias(node.left.name, resourceMethodSource.method, node, ancestors);
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
const resourceHandleSource = getMaybeResourceHandleSource(node.right);
|
|
679
|
+
if (resourceHandleSource) {
|
|
680
|
+
addHandleAlias(node.left.name, resourceHandleSource, node, ancestors);
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
if (node.operator === "=" && ((_b = node.left) == null ? void 0 : _b.type) === "ObjectPattern") {
|
|
685
|
+
collectMethodAliases(node.left, getMaybeResourceHandleSource(node.right), ancestors);
|
|
686
|
+
}
|
|
687
|
+
},
|
|
688
|
+
VariableDeclarator(node, ancestors) {
|
|
689
|
+
var _a, _b;
|
|
690
|
+
const declaration = (0, import_bindings.findAstAncestor)(ancestors, "VariableDeclaration");
|
|
691
|
+
const isVar = (declaration == null ? void 0 : declaration.kind) === "var";
|
|
692
|
+
if (((_a = node.id) == null ? void 0 : _a.type) === "Identifier") {
|
|
693
|
+
const resourceMethodSource = getMaybeResourceMethodSource(node.init);
|
|
694
|
+
if (resourceMethodSource) {
|
|
695
|
+
addMethodAlias(node.id.name, resourceMethodSource.method, node, ancestors, isVar);
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
const resourceHandleSource2 = getMaybeResourceHandleSource(node.init);
|
|
699
|
+
if (resourceHandleSource2) {
|
|
700
|
+
addHandleAlias(node.id.name, resourceHandleSource2, node, ancestors, isVar);
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
const resourceHandleSource = getMaybeResourceHandleSource(node.init);
|
|
705
|
+
if (((_b = node.id) == null ? void 0 : _b.type) === "ObjectPattern") {
|
|
706
|
+
collectMethodAliases(node.id, resourceHandleSource, ancestors, isVar);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
return {
|
|
711
|
+
handles: (0, import_static_values.trimAstAliasesAfterWrites)(handles, writes, identifierBindings),
|
|
712
|
+
methods: (0, import_static_values.trimAstAliasesAfterWrites)(methods, writes, identifierBindings)
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
function collectAstInvalidApiResourceCall(node, aliases, resourceAliases, source, identifierBindings) {
|
|
716
|
+
var _a, _b, _c;
|
|
717
|
+
const entries = [];
|
|
718
|
+
const callee = (0, import_bindings.unwrapAstChainExpression)(node.callee);
|
|
719
|
+
const chainedResourceMethod = getCtxApiResourceChainedMethodFromAst(
|
|
720
|
+
callee,
|
|
721
|
+
aliases,
|
|
722
|
+
resourceAliases,
|
|
723
|
+
source,
|
|
724
|
+
identifierBindings
|
|
725
|
+
);
|
|
726
|
+
if (chainedResourceMethod) {
|
|
727
|
+
entries.push(chainedResourceMethod);
|
|
728
|
+
}
|
|
729
|
+
const resourceFactoryCall = getCtxApiResourceCallFromAst(node, aliases, source, identifierBindings);
|
|
730
|
+
if (!resourceFactoryCall) {
|
|
731
|
+
return entries;
|
|
732
|
+
}
|
|
733
|
+
const method = (0, import_static_values.resolveAstStaticStringValue)((_a = node.arguments) == null ? void 0 : _a[0], source);
|
|
734
|
+
if (method && import_constants.RUNJS_RESOURCE_METHODS.has(method)) {
|
|
735
|
+
entries.push({
|
|
736
|
+
index: resourceFactoryCall.index,
|
|
737
|
+
match: `${resourceFactoryCall.calleeSource}('${method}')`,
|
|
738
|
+
matchIndex: resourceFactoryCall.index,
|
|
739
|
+
method
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
const resourceName = (0, import_static_values.resolveAstStaticStringValue)((_b = node.arguments) == null ? void 0 : _b[0], source);
|
|
743
|
+
const action = (0, import_static_values.resolveAstStaticStringValue)((_c = node.arguments) == null ? void 0 : _c[1], source);
|
|
744
|
+
if (action && import_constants.RUNJS_RESOURCE_METHODS.has(action)) {
|
|
745
|
+
entries.push({
|
|
746
|
+
index: resourceFactoryCall.index,
|
|
747
|
+
match: resourceName ? `${resourceFactoryCall.calleeSource}('${resourceName}', '${action}')` : `${resourceFactoryCall.calleeSource}(..., '${action}')`,
|
|
748
|
+
matchIndex: resourceFactoryCall.index,
|
|
749
|
+
method: action
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
return entries;
|
|
753
|
+
}
|
|
754
|
+
function getCtxApiResourceChainedMethodFromAst(node, aliases, resourceAliases, source, identifierBindings) {
|
|
755
|
+
var _a;
|
|
756
|
+
const callee = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
757
|
+
const wrappedMethod = getWrappedCtxApiResourceChainedMethodFromAst(
|
|
758
|
+
callee,
|
|
759
|
+
aliases,
|
|
760
|
+
resourceAliases,
|
|
761
|
+
source,
|
|
762
|
+
identifierBindings
|
|
763
|
+
);
|
|
764
|
+
if (wrappedMethod) {
|
|
765
|
+
return wrappedMethod;
|
|
766
|
+
}
|
|
767
|
+
const methodAlias = getMaybeCtxApiResourceMethodAliasFromAst(callee, resourceAliases.methods, identifierBindings);
|
|
768
|
+
if (methodAlias) {
|
|
769
|
+
return {
|
|
770
|
+
index: typeof callee.start === "number" ? callee.start : 0,
|
|
771
|
+
match: (0, import_source.getAstSource)(callee, source),
|
|
772
|
+
matchIndex: typeof callee.start === "number" ? callee.start : 0,
|
|
773
|
+
method: methodAlias.method
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
if (!callee || callee.type !== "MemberExpression") {
|
|
777
|
+
return void 0;
|
|
778
|
+
}
|
|
779
|
+
const invocationMember = (0, import_static_values.getAstStaticPropertyName)(callee);
|
|
780
|
+
if (invocationMember === "call" || invocationMember === "apply" || invocationMember === "bind") {
|
|
781
|
+
const targetMethod = getCtxApiResourceChainedMethodFromAst(
|
|
782
|
+
callee.object,
|
|
783
|
+
aliases,
|
|
784
|
+
resourceAliases,
|
|
785
|
+
source,
|
|
786
|
+
identifierBindings
|
|
787
|
+
);
|
|
788
|
+
if (targetMethod) {
|
|
789
|
+
return {
|
|
790
|
+
...targetMethod,
|
|
791
|
+
index: typeof callee.start === "number" ? callee.start : targetMethod.index,
|
|
792
|
+
match: (0, import_source.getAstSource)(callee, source),
|
|
793
|
+
matchIndex: typeof callee.start === "number" ? callee.start : targetMethod.matchIndex
|
|
794
|
+
};
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
const method = (0, import_static_values.getAstStaticPropertyName)(callee);
|
|
798
|
+
if (!import_constants.RUNJS_RESOURCE_METHODS.has(method)) {
|
|
799
|
+
return void 0;
|
|
800
|
+
}
|
|
801
|
+
const resourceHandleAlias = getMaybeCtxApiResourceHandleAliasFromAst(
|
|
802
|
+
callee.object,
|
|
803
|
+
resourceAliases.handles,
|
|
804
|
+
identifierBindings
|
|
805
|
+
);
|
|
806
|
+
if (resourceHandleAlias) {
|
|
807
|
+
return {
|
|
808
|
+
index: typeof callee.start === "number" ? callee.start : 0,
|
|
809
|
+
match: (0, import_source.getAstSource)(callee, source),
|
|
810
|
+
matchIndex: typeof callee.start === "number" ? callee.start : 0,
|
|
811
|
+
method
|
|
812
|
+
};
|
|
813
|
+
}
|
|
814
|
+
const objectPath = getCtxApiMemberPathFromAst(callee.object, aliases, identifierBindings);
|
|
815
|
+
if (isCtxApiResourcePath(objectPath)) {
|
|
816
|
+
return {
|
|
817
|
+
index: typeof callee.start === "number" ? callee.start : 0,
|
|
818
|
+
match: (0, import_source.getAstSource)(callee, source),
|
|
819
|
+
matchIndex: typeof callee.start === "number" ? callee.start : 0,
|
|
820
|
+
method
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
const resourceFactoryCall = getMaybeCtxApiResourceCallFromAst(callee.object, aliases, source, identifierBindings);
|
|
824
|
+
if (!resourceFactoryCall) {
|
|
825
|
+
return void 0;
|
|
826
|
+
}
|
|
827
|
+
const resourceName = (0, import_static_values.resolveAstStaticStringValue)((_a = resourceFactoryCall.args) == null ? void 0 : _a[0], source);
|
|
828
|
+
return {
|
|
829
|
+
index: resourceFactoryCall.index,
|
|
830
|
+
match: resourceName ? `${resourceFactoryCall.calleeSource}('${resourceName}').${method}` : `${resourceFactoryCall.calleeSource}(...).${method}`,
|
|
831
|
+
matchIndex: resourceFactoryCall.index,
|
|
832
|
+
method
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
function getWrappedCtxApiResourceChainedMethodFromAst(node, aliases, resourceAliases, source, identifierBindings) {
|
|
836
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
837
|
+
if (!unwrapped) {
|
|
838
|
+
return void 0;
|
|
839
|
+
}
|
|
840
|
+
const wrapEntry = (entry) => {
|
|
841
|
+
if (!entry) {
|
|
842
|
+
return void 0;
|
|
843
|
+
}
|
|
844
|
+
return {
|
|
845
|
+
...entry,
|
|
846
|
+
index: typeof unwrapped.start === "number" ? unwrapped.start : entry.index,
|
|
847
|
+
match: (0, import_source.getAstSource)(unwrapped, source),
|
|
848
|
+
matchIndex: typeof unwrapped.start === "number" ? unwrapped.start : entry.matchIndex
|
|
849
|
+
};
|
|
850
|
+
};
|
|
851
|
+
if (unwrapped.type === "ConditionalExpression") {
|
|
852
|
+
return wrapEntry(
|
|
853
|
+
getCtxApiResourceChainedMethodFromAst(
|
|
854
|
+
unwrapped.consequent,
|
|
855
|
+
aliases,
|
|
856
|
+
resourceAliases,
|
|
857
|
+
source,
|
|
858
|
+
identifierBindings
|
|
859
|
+
)
|
|
860
|
+
) || wrapEntry(
|
|
861
|
+
getCtxApiResourceChainedMethodFromAst(
|
|
862
|
+
unwrapped.alternate,
|
|
863
|
+
aliases,
|
|
864
|
+
resourceAliases,
|
|
865
|
+
source,
|
|
866
|
+
identifierBindings
|
|
867
|
+
)
|
|
868
|
+
);
|
|
869
|
+
}
|
|
870
|
+
if (unwrapped.type === "LogicalExpression") {
|
|
871
|
+
const leftEntry = getCtxApiResourceChainedMethodFromAst(
|
|
872
|
+
unwrapped.left,
|
|
873
|
+
aliases,
|
|
874
|
+
resourceAliases,
|
|
875
|
+
source,
|
|
876
|
+
identifierBindings
|
|
877
|
+
);
|
|
878
|
+
if (unwrapped.operator === "&&") {
|
|
879
|
+
return wrapEntry(
|
|
880
|
+
getCtxApiResourceChainedMethodFromAst(unwrapped.right, aliases, resourceAliases, source, identifierBindings)
|
|
881
|
+
);
|
|
882
|
+
}
|
|
883
|
+
if ((unwrapped.operator === "||" || unwrapped.operator === "??") && leftEntry) {
|
|
884
|
+
return wrapEntry(leftEntry);
|
|
885
|
+
}
|
|
886
|
+
return wrapEntry(leftEntry) || wrapEntry(
|
|
887
|
+
getCtxApiResourceChainedMethodFromAst(unwrapped.right, aliases, resourceAliases, source, identifierBindings)
|
|
888
|
+
);
|
|
889
|
+
}
|
|
890
|
+
if (unwrapped.type === "SequenceExpression") {
|
|
891
|
+
const expressions = unwrapped.expressions || [];
|
|
892
|
+
return wrapEntry(
|
|
893
|
+
getCtxApiResourceChainedMethodFromAst(
|
|
894
|
+
expressions[expressions.length - 1],
|
|
895
|
+
aliases,
|
|
896
|
+
resourceAliases,
|
|
897
|
+
source,
|
|
898
|
+
identifierBindings
|
|
899
|
+
)
|
|
900
|
+
);
|
|
901
|
+
}
|
|
902
|
+
if (unwrapped.type === "AssignmentExpression" && (0, import_static_values.isAstCtxApiAliasAssignmentOperator)(unwrapped.operator)) {
|
|
903
|
+
return wrapEntry(
|
|
904
|
+
getCtxApiResourceChainedMethodFromAst(unwrapped.right, aliases, resourceAliases, source, identifierBindings)
|
|
905
|
+
);
|
|
906
|
+
}
|
|
907
|
+
return void 0;
|
|
908
|
+
}
|
|
909
|
+
function getCtxApiResourceHandleAliasFromAst(node, aliases, identifierBindings) {
|
|
910
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
911
|
+
if ((unwrapped == null ? void 0 : unwrapped.type) !== "Identifier") {
|
|
912
|
+
return void 0;
|
|
913
|
+
}
|
|
914
|
+
return (0, import_static_values.resolveAstAliasBinding)(unwrapped.name, unwrapped.start || 0, aliases, identifierBindings);
|
|
915
|
+
}
|
|
916
|
+
function getCtxApiResourceMethodAliasFromAst(node, aliases, identifierBindings) {
|
|
917
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
918
|
+
if ((unwrapped == null ? void 0 : unwrapped.type) !== "Identifier") {
|
|
919
|
+
return void 0;
|
|
920
|
+
}
|
|
921
|
+
return (0, import_static_values.resolveAstAliasBinding)(unwrapped.name, unwrapped.start || 0, aliases, identifierBindings);
|
|
922
|
+
}
|
|
923
|
+
function getMaybeCtxApiResourceHandleAliasFromAst(node, aliases, identifierBindings) {
|
|
924
|
+
return getUniqueCtxApiResourceHandleAlias(
|
|
925
|
+
collectMaybeCtxApiResourceHandleAliasesFromAst(node, aliases, identifierBindings)
|
|
926
|
+
);
|
|
927
|
+
}
|
|
928
|
+
function collectMaybeCtxApiResourceHandleAliasesFromAst(node, aliases, identifierBindings) {
|
|
929
|
+
const directAlias = getCtxApiResourceHandleAliasFromAst(node, aliases, identifierBindings);
|
|
930
|
+
if (directAlias) {
|
|
931
|
+
return [directAlias];
|
|
932
|
+
}
|
|
933
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
934
|
+
if (!unwrapped) {
|
|
935
|
+
return [];
|
|
936
|
+
}
|
|
937
|
+
if (unwrapped.type === "ConditionalExpression") {
|
|
938
|
+
return [
|
|
939
|
+
...collectMaybeCtxApiResourceHandleAliasesFromAst(unwrapped.consequent, aliases, identifierBindings),
|
|
940
|
+
...collectMaybeCtxApiResourceHandleAliasesFromAst(unwrapped.alternate, aliases, identifierBindings)
|
|
941
|
+
];
|
|
942
|
+
}
|
|
943
|
+
if (unwrapped.type === "LogicalExpression") {
|
|
944
|
+
const leftAliases = collectMaybeCtxApiResourceHandleAliasesFromAst(unwrapped.left, aliases, identifierBindings);
|
|
945
|
+
return [
|
|
946
|
+
...leftAliases,
|
|
947
|
+
...collectMaybeCtxApiResourceHandleAliasesFromAst(unwrapped.right, aliases, identifierBindings)
|
|
948
|
+
];
|
|
949
|
+
}
|
|
950
|
+
if (unwrapped.type === "SequenceExpression") {
|
|
951
|
+
const expressions = unwrapped.expressions || [];
|
|
952
|
+
return collectMaybeCtxApiResourceHandleAliasesFromAst(
|
|
953
|
+
expressions[expressions.length - 1],
|
|
954
|
+
aliases,
|
|
955
|
+
identifierBindings
|
|
956
|
+
);
|
|
957
|
+
}
|
|
958
|
+
if (unwrapped.type === "AssignmentExpression" && (0, import_static_values.isAstCtxApiAliasAssignmentOperator)(unwrapped.operator)) {
|
|
959
|
+
return collectMaybeCtxApiResourceHandleAliasesFromAst(unwrapped.right, aliases, identifierBindings);
|
|
960
|
+
}
|
|
961
|
+
return [];
|
|
962
|
+
}
|
|
963
|
+
function getUniqueCtxApiResourceHandleAlias(aliases) {
|
|
964
|
+
if (aliases.length <= 1) {
|
|
965
|
+
return aliases[0];
|
|
966
|
+
}
|
|
967
|
+
const firstIdentity = getCtxApiResourceHandleAliasIdentity(aliases[0]);
|
|
968
|
+
if (!firstIdentity || aliases.some((alias) => getCtxApiResourceHandleAliasIdentity(alias) !== firstIdentity)) {
|
|
969
|
+
return void 0;
|
|
970
|
+
}
|
|
971
|
+
return aliases[0];
|
|
972
|
+
}
|
|
973
|
+
function getCtxApiResourceHandleAliasIdentity(alias) {
|
|
974
|
+
if (typeof alias.resourceName !== "string" && typeof alias.dataSourceKey !== "string") {
|
|
975
|
+
return "";
|
|
976
|
+
}
|
|
977
|
+
return `${alias.dataSourceKey ?? ""}:${alias.resourceName ?? ""}`;
|
|
978
|
+
}
|
|
979
|
+
function getMaybeCtxApiResourceMethodAliasFromAst(node, aliases, identifierBindings) {
|
|
980
|
+
const directAlias = getCtxApiResourceMethodAliasFromAst(node, aliases, identifierBindings);
|
|
981
|
+
if (directAlias) {
|
|
982
|
+
return directAlias;
|
|
983
|
+
}
|
|
984
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
985
|
+
if (!unwrapped) {
|
|
986
|
+
return void 0;
|
|
987
|
+
}
|
|
988
|
+
if (unwrapped.type === "ConditionalExpression") {
|
|
989
|
+
return getMaybeCtxApiResourceMethodAliasFromAst(unwrapped.consequent, aliases, identifierBindings) || getMaybeCtxApiResourceMethodAliasFromAst(unwrapped.alternate, aliases, identifierBindings);
|
|
990
|
+
}
|
|
991
|
+
if (unwrapped.type === "LogicalExpression") {
|
|
992
|
+
const leftAlias = getMaybeCtxApiResourceMethodAliasFromAst(unwrapped.left, aliases, identifierBindings);
|
|
993
|
+
if (unwrapped.operator === "&&") {
|
|
994
|
+
return getMaybeCtxApiResourceMethodAliasFromAst(unwrapped.right, aliases, identifierBindings);
|
|
995
|
+
}
|
|
996
|
+
if ((unwrapped.operator === "||" || unwrapped.operator === "??") && leftAlias) {
|
|
997
|
+
return leftAlias;
|
|
998
|
+
}
|
|
999
|
+
return leftAlias || getMaybeCtxApiResourceMethodAliasFromAst(unwrapped.right, aliases, identifierBindings);
|
|
1000
|
+
}
|
|
1001
|
+
if (unwrapped.type === "SequenceExpression") {
|
|
1002
|
+
const expressions = unwrapped.expressions || [];
|
|
1003
|
+
return getMaybeCtxApiResourceMethodAliasFromAst(expressions[expressions.length - 1], aliases, identifierBindings);
|
|
1004
|
+
}
|
|
1005
|
+
if (unwrapped.type === "AssignmentExpression" && (0, import_static_values.isAstCtxApiAliasAssignmentOperator)(unwrapped.operator)) {
|
|
1006
|
+
return getMaybeCtxApiResourceMethodAliasFromAst(unwrapped.right, aliases, identifierBindings);
|
|
1007
|
+
}
|
|
1008
|
+
return void 0;
|
|
1009
|
+
}
|
|
1010
|
+
function getCtxApiResourceCallFromAst(node, aliases, source, identifierBindings) {
|
|
1011
|
+
const call = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
1012
|
+
if (!call || call.type !== "CallExpression") {
|
|
1013
|
+
return void 0;
|
|
1014
|
+
}
|
|
1015
|
+
const callee = getCtxApiResourceCalleeFromAst(call.callee, aliases, source, identifierBindings);
|
|
1016
|
+
if (!callee) {
|
|
1017
|
+
return void 0;
|
|
1018
|
+
}
|
|
1019
|
+
return {
|
|
1020
|
+
args: call.arguments || [],
|
|
1021
|
+
calleeSource: callee.source,
|
|
1022
|
+
index: typeof call.start === "number" ? call.start : callee.index
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
1025
|
+
function getCtxApiResourceCalleeFromAst(node, aliases, source, identifierBindings) {
|
|
1026
|
+
const callee = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
1027
|
+
if (!callee) {
|
|
1028
|
+
return void 0;
|
|
1029
|
+
}
|
|
1030
|
+
const path = getCtxApiMemberPathFromAst(callee, aliases, identifierBindings);
|
|
1031
|
+
if (isCtxApiResourcePath(path)) {
|
|
1032
|
+
return {
|
|
1033
|
+
index: typeof callee.start === "number" ? callee.start : 0,
|
|
1034
|
+
source: (0, import_source.getAstSource)(callee, source)
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
const wrapEntry = (entry) => {
|
|
1038
|
+
if (!entry) {
|
|
1039
|
+
return void 0;
|
|
1040
|
+
}
|
|
1041
|
+
return {
|
|
1042
|
+
index: typeof callee.start === "number" ? callee.start : entry.index,
|
|
1043
|
+
source: (0, import_source.getAstSource)(callee, source)
|
|
1044
|
+
};
|
|
1045
|
+
};
|
|
1046
|
+
if (callee.type === "ConditionalExpression") {
|
|
1047
|
+
return wrapEntry(getCtxApiResourceCalleeFromAst(callee.consequent, aliases, source, identifierBindings)) || wrapEntry(getCtxApiResourceCalleeFromAst(callee.alternate, aliases, source, identifierBindings));
|
|
1048
|
+
}
|
|
1049
|
+
if (callee.type === "LogicalExpression") {
|
|
1050
|
+
const leftEntry = getCtxApiResourceCalleeFromAst(callee.left, aliases, source, identifierBindings);
|
|
1051
|
+
if (callee.operator === "&&") {
|
|
1052
|
+
return wrapEntry(getCtxApiResourceCalleeFromAst(callee.right, aliases, source, identifierBindings));
|
|
1053
|
+
}
|
|
1054
|
+
if ((callee.operator === "||" || callee.operator === "??") && leftEntry) {
|
|
1055
|
+
return wrapEntry(leftEntry);
|
|
1056
|
+
}
|
|
1057
|
+
return wrapEntry(leftEntry) || wrapEntry(getCtxApiResourceCalleeFromAst(callee.right, aliases, source, identifierBindings));
|
|
1058
|
+
}
|
|
1059
|
+
if (callee.type === "SequenceExpression") {
|
|
1060
|
+
const expressions = callee.expressions || [];
|
|
1061
|
+
return wrapEntry(
|
|
1062
|
+
getCtxApiResourceCalleeFromAst(expressions[expressions.length - 1], aliases, source, identifierBindings)
|
|
1063
|
+
);
|
|
1064
|
+
}
|
|
1065
|
+
if (callee.type === "AssignmentExpression" && (0, import_static_values.isAstCtxApiAliasAssignmentOperator)(callee.operator)) {
|
|
1066
|
+
return wrapEntry(getCtxApiResourceCalleeFromAst(callee.right, aliases, source, identifierBindings));
|
|
1067
|
+
}
|
|
1068
|
+
return void 0;
|
|
1069
|
+
}
|
|
1070
|
+
function getMaybeCtxApiResourceCallFromAst(node, aliases, source, identifierBindings) {
|
|
1071
|
+
return getUniqueCtxApiResourceCall(
|
|
1072
|
+
collectMaybeCtxApiResourceCallsFromAst(node, aliases, source, identifierBindings),
|
|
1073
|
+
source
|
|
1074
|
+
);
|
|
1075
|
+
}
|
|
1076
|
+
function collectMaybeCtxApiResourceCallsFromAst(node, aliases, source, identifierBindings) {
|
|
1077
|
+
const directCall = getCtxApiResourceCallFromAst(node, aliases, source, identifierBindings);
|
|
1078
|
+
if (directCall) {
|
|
1079
|
+
return [directCall];
|
|
1080
|
+
}
|
|
1081
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
1082
|
+
if (!unwrapped) {
|
|
1083
|
+
return [];
|
|
1084
|
+
}
|
|
1085
|
+
if (unwrapped.type === "ConditionalExpression") {
|
|
1086
|
+
return [
|
|
1087
|
+
...collectMaybeCtxApiResourceCallsFromAst(unwrapped.consequent, aliases, source, identifierBindings),
|
|
1088
|
+
...collectMaybeCtxApiResourceCallsFromAst(unwrapped.alternate, aliases, source, identifierBindings)
|
|
1089
|
+
];
|
|
1090
|
+
}
|
|
1091
|
+
if (unwrapped.type === "LogicalExpression") {
|
|
1092
|
+
const leftCalls = collectMaybeCtxApiResourceCallsFromAst(unwrapped.left, aliases, source, identifierBindings);
|
|
1093
|
+
return [
|
|
1094
|
+
...leftCalls,
|
|
1095
|
+
...collectMaybeCtxApiResourceCallsFromAst(unwrapped.right, aliases, source, identifierBindings)
|
|
1096
|
+
];
|
|
1097
|
+
}
|
|
1098
|
+
if (unwrapped.type === "SequenceExpression") {
|
|
1099
|
+
const expressions = unwrapped.expressions || [];
|
|
1100
|
+
return collectMaybeCtxApiResourceCallsFromAst(
|
|
1101
|
+
expressions[expressions.length - 1],
|
|
1102
|
+
aliases,
|
|
1103
|
+
source,
|
|
1104
|
+
identifierBindings
|
|
1105
|
+
);
|
|
1106
|
+
}
|
|
1107
|
+
if (unwrapped.type === "AssignmentExpression" && (0, import_static_values.isAstCtxApiAliasAssignmentOperator)(unwrapped.operator)) {
|
|
1108
|
+
return collectMaybeCtxApiResourceCallsFromAst(unwrapped.right, aliases, source, identifierBindings);
|
|
1109
|
+
}
|
|
1110
|
+
return [];
|
|
1111
|
+
}
|
|
1112
|
+
function getUniqueCtxApiResourceCall(calls, source) {
|
|
1113
|
+
if (calls.length <= 1) {
|
|
1114
|
+
return calls[0];
|
|
1115
|
+
}
|
|
1116
|
+
const firstIdentity = getCtxApiResourceCallIdentity(calls[0], source);
|
|
1117
|
+
if (!firstIdentity || calls.some((call) => getCtxApiResourceCallIdentity(call, source) !== firstIdentity)) {
|
|
1118
|
+
return void 0;
|
|
1119
|
+
}
|
|
1120
|
+
return calls[0];
|
|
1121
|
+
}
|
|
1122
|
+
function getCtxApiResourceCallIdentity(call, source) {
|
|
1123
|
+
var _a, _b, _c;
|
|
1124
|
+
const resourceSource = (0, import_source.getAstSource)((_a = call.args) == null ? void 0 : _a[0], source);
|
|
1125
|
+
if (!resourceSource) {
|
|
1126
|
+
return "";
|
|
1127
|
+
}
|
|
1128
|
+
return [resourceSource, (0, import_source.getAstSource)((_b = call.args) == null ? void 0 : _b[1], source), (0, import_source.getAstSource)((_c = call.args) == null ? void 0 : _c[2], source)].join(":");
|
|
1129
|
+
}
|
|
1130
|
+
function filterInvalidCtxApiMemberAccessesForResourceCalls(memberAccesses, resourceCalls) {
|
|
1131
|
+
const resourceCallMatches = new Set(resourceCalls.map((entry) => entry.match));
|
|
1132
|
+
const resourceCallMatchRanges = new Set(
|
|
1133
|
+
resourceCalls.filter((entry) => typeof entry.matchIndex === "number").map((entry) => `${entry.matchIndex}:${entry.match}`)
|
|
1134
|
+
);
|
|
1135
|
+
return memberAccesses.filter((entry) => {
|
|
1136
|
+
if (entry.ruleId !== "runjs-ctx-api-member-unknown") {
|
|
1137
|
+
return true;
|
|
1138
|
+
}
|
|
1139
|
+
if (!entry.match || !entry.capability.startsWith("ctx.api.resource.")) {
|
|
1140
|
+
return true;
|
|
1141
|
+
}
|
|
1142
|
+
if (typeof entry.matchIndex === "number") {
|
|
1143
|
+
return !resourceCallMatchRanges.has(`${entry.matchIndex}:${entry.match}`);
|
|
1144
|
+
}
|
|
1145
|
+
return !resourceCallMatches.has(entry.match);
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
1148
|
+
function isCtxApiResourcePath(path) {
|
|
1149
|
+
return !!path && !path.hasDynamicMember && path.members.length === 1 && path.members[0].name === "resource";
|
|
1150
|
+
}
|
|
1151
|
+
function collectAstInvalidCtxLibPatternAccesses(ast, aliases, rootAliases, identifierBindings, source) {
|
|
1152
|
+
const entries = [];
|
|
1153
|
+
const collectPattern = (pattern, sourceNode) => {
|
|
1154
|
+
const sourcePath = getCtxLibMemberPathFromAst(sourceNode, aliases, rootAliases, identifierBindings, source);
|
|
1155
|
+
if (!sourcePath || sourcePath.hasDynamicMember || sourcePath.members.length) {
|
|
1156
|
+
return;
|
|
1157
|
+
}
|
|
1158
|
+
collectInvalidCtxLibObjectPatternAccesses(pattern, sourcePath).forEach((entry) => entries.push(entry));
|
|
1159
|
+
};
|
|
1160
|
+
(0, import_walk.walkAstAncestor)(ast, {
|
|
1161
|
+
AssignmentExpression(node) {
|
|
1162
|
+
var _a;
|
|
1163
|
+
if (node.operator !== "=" || ((_a = node.left) == null ? void 0 : _a.type) !== "ObjectPattern") {
|
|
1164
|
+
return;
|
|
1165
|
+
}
|
|
1166
|
+
collectPattern(node.left, node.right);
|
|
1167
|
+
},
|
|
1168
|
+
VariableDeclarator(node) {
|
|
1169
|
+
var _a;
|
|
1170
|
+
if (((_a = node.id) == null ? void 0 : _a.type) !== "ObjectPattern") {
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1173
|
+
collectPattern(node.id, node.init);
|
|
1174
|
+
}
|
|
1175
|
+
});
|
|
1176
|
+
return (0, import_bindings.dedupeIndexedEntries)(entries);
|
|
1177
|
+
}
|
|
1178
|
+
function collectInvalidCtxLibObjectPatternAccesses(pattern, sourcePath) {
|
|
1179
|
+
var _a;
|
|
1180
|
+
const entries = [];
|
|
1181
|
+
for (const property of (pattern == null ? void 0 : pattern.properties) || []) {
|
|
1182
|
+
if (!property || property.type !== "Property") {
|
|
1183
|
+
continue;
|
|
1184
|
+
}
|
|
1185
|
+
const member = (0, import_static_values.getAstStaticPropertyName)(property);
|
|
1186
|
+
if (!member) {
|
|
1187
|
+
continue;
|
|
1188
|
+
}
|
|
1189
|
+
const invalidAccess = buildInvalidCtxLibMemberAccess({
|
|
1190
|
+
...sourcePath,
|
|
1191
|
+
members: [
|
|
1192
|
+
{
|
|
1193
|
+
accessKind: "destructure",
|
|
1194
|
+
index: typeof ((_a = property.key) == null ? void 0 : _a.start) === "number" ? property.key.start : property.start || 0,
|
|
1195
|
+
name: member
|
|
1196
|
+
}
|
|
1197
|
+
]
|
|
1198
|
+
});
|
|
1199
|
+
if (invalidAccess) {
|
|
1200
|
+
entries.push(invalidAccess);
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
return entries;
|
|
1204
|
+
}
|
|
1205
|
+
function collectAstInvalidCtxLibMemberAccess(node, aliases, rootAliases, identifierBindings, source) {
|
|
1206
|
+
const path = getCtxLibMemberPathFromAst(node, aliases, rootAliases, identifierBindings, source);
|
|
1207
|
+
if (!path || path.hasDynamicMember || !path.members.length) {
|
|
1208
|
+
return void 0;
|
|
1209
|
+
}
|
|
1210
|
+
return buildInvalidCtxLibMemberAccess(path);
|
|
1211
|
+
}
|
|
1212
|
+
function buildInvalidCtxLibMemberAccess(path) {
|
|
1213
|
+
const allowedMembers = import_constants.RUNJS_CTX_LIB_ALLOWED_MEMBERS_BY_LIBRARY.get(path.library);
|
|
1214
|
+
const member = path.members[0];
|
|
1215
|
+
if (!allowedMembers || !member || allowedMembers.has(member.name)) {
|
|
1216
|
+
return void 0;
|
|
1217
|
+
}
|
|
1218
|
+
return {
|
|
1219
|
+
accessKind: member.accessKind,
|
|
1220
|
+
capability: getCtxLibMemberCapability(path.rootCapability, member),
|
|
1221
|
+
index: member.index,
|
|
1222
|
+
library: path.library,
|
|
1223
|
+
member: member.name,
|
|
1224
|
+
ruleId: "runjs-ctx-libs-member-unknown",
|
|
1225
|
+
suggestedImport: getSuggestedCtxLibMemberImport(path.library, member.name)
|
|
1226
|
+
};
|
|
1227
|
+
}
|
|
1228
|
+
function getCtxLibMemberCapability(rootCapability, member) {
|
|
1229
|
+
return member.accessKind === "bracket" ? `${rootCapability}[${JSON.stringify(member.name)}]` : `${rootCapability}.${member.name}`;
|
|
1230
|
+
}
|
|
1231
|
+
function getSuggestedCtxLibMemberImport(library, member) {
|
|
1232
|
+
if (library === "antd" && member === "colors") {
|
|
1233
|
+
return "@ant-design/colors";
|
|
1234
|
+
}
|
|
1235
|
+
return void 0;
|
|
1236
|
+
}
|
|
1237
|
+
function getCtxLibMemberPathFromAst(node, aliases, rootAliases, identifierBindings, source) {
|
|
1238
|
+
var _a;
|
|
1239
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
1240
|
+
if (!unwrapped) {
|
|
1241
|
+
return void 0;
|
|
1242
|
+
}
|
|
1243
|
+
if (unwrapped.type === "Identifier") {
|
|
1244
|
+
const alias = (0, import_static_values.resolveAstAliasBinding)(unwrapped.name, unwrapped.start || 0, aliases, identifierBindings);
|
|
1245
|
+
if (!alias) {
|
|
1246
|
+
return void 0;
|
|
1247
|
+
}
|
|
1248
|
+
const index = typeof unwrapped.start === "number" ? unwrapped.start : alias.start;
|
|
1249
|
+
return {
|
|
1250
|
+
dynamicIndex: index,
|
|
1251
|
+
hasDynamicMember: false,
|
|
1252
|
+
library: alias.library,
|
|
1253
|
+
libraryIndex: index,
|
|
1254
|
+
memberIndex: index,
|
|
1255
|
+
members: [],
|
|
1256
|
+
rootCapability: alias.capability
|
|
1257
|
+
};
|
|
1258
|
+
}
|
|
1259
|
+
if (unwrapped.type !== "MemberExpression") {
|
|
1260
|
+
return void 0;
|
|
1261
|
+
}
|
|
1262
|
+
const objectPath = getCtxLibMemberPathFromAst(unwrapped.object, aliases, rootAliases, identifierBindings, source);
|
|
1263
|
+
if (objectPath) {
|
|
1264
|
+
const propertyName = (0, import_static_values.getAstStaticPropertyName)(unwrapped);
|
|
1265
|
+
const propertyIndex = typeof ((_a = unwrapped.property) == null ? void 0 : _a.start) === "number" ? unwrapped.property.start : unwrapped.start || 0;
|
|
1266
|
+
return {
|
|
1267
|
+
...objectPath,
|
|
1268
|
+
dynamicIndex: propertyName ? objectPath.dynamicIndex : propertyIndex,
|
|
1269
|
+
hasDynamicMember: objectPath.hasDynamicMember || !propertyName,
|
|
1270
|
+
memberIndex: objectPath.members.length ? objectPath.memberIndex : propertyIndex,
|
|
1271
|
+
members: propertyName ? [
|
|
1272
|
+
...objectPath.members,
|
|
1273
|
+
{
|
|
1274
|
+
accessKind: unwrapped.computed ? "bracket" : "member",
|
|
1275
|
+
index: propertyIndex,
|
|
1276
|
+
name: propertyName
|
|
1277
|
+
}
|
|
1278
|
+
] : objectPath.members
|
|
1279
|
+
};
|
|
1280
|
+
}
|
|
1281
|
+
return getDirectCtxLibPathFromAst(unwrapped, rootAliases, identifierBindings, source);
|
|
1282
|
+
}
|
|
1283
|
+
function getDirectCtxLibPathFromAst(node, rootAliases, identifierBindings, source) {
|
|
1284
|
+
var _a;
|
|
1285
|
+
const member = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
1286
|
+
if (!member || member.type !== "MemberExpression") {
|
|
1287
|
+
return void 0;
|
|
1288
|
+
}
|
|
1289
|
+
const propertyName = (0, import_static_values.getAstStaticPropertyName)(member);
|
|
1290
|
+
if (!propertyName) {
|
|
1291
|
+
return void 0;
|
|
1292
|
+
}
|
|
1293
|
+
const propertyIndex = typeof ((_a = member.property) == null ? void 0 : _a.start) === "number" ? member.property.start : member.start || 0;
|
|
1294
|
+
if (isCtxLibsRootFromAst(member.object, rootAliases, identifierBindings)) {
|
|
1295
|
+
return {
|
|
1296
|
+
dynamicIndex: propertyIndex,
|
|
1297
|
+
hasDynamicMember: false,
|
|
1298
|
+
library: propertyName,
|
|
1299
|
+
libraryIndex: propertyIndex,
|
|
1300
|
+
memberIndex: propertyIndex,
|
|
1301
|
+
members: [],
|
|
1302
|
+
rootCapability: (0, import_source.getAstSource)(member, source) || `ctx.libs.${propertyName}`
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1305
|
+
if (import_constants.CANONICAL_CTX_LIB_MEMBERS.includes(propertyName) && (0, import_static_values.isUnshadowedCtxIdentifier)(member.object, identifierBindings)) {
|
|
1306
|
+
return {
|
|
1307
|
+
dynamicIndex: propertyIndex,
|
|
1308
|
+
hasDynamicMember: false,
|
|
1309
|
+
library: propertyName,
|
|
1310
|
+
libraryIndex: propertyIndex,
|
|
1311
|
+
memberIndex: propertyIndex,
|
|
1312
|
+
members: [],
|
|
1313
|
+
rootCapability: (0, import_source.getAstSource)(member, source) || `ctx.${propertyName}`
|
|
1314
|
+
};
|
|
1315
|
+
}
|
|
1316
|
+
return void 0;
|
|
1317
|
+
}
|
|
1318
|
+
function isCtxLibsRootFromAst(node, rootAliases, identifierBindings) {
|
|
1319
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
1320
|
+
if (!unwrapped) {
|
|
1321
|
+
return false;
|
|
1322
|
+
}
|
|
1323
|
+
if (unwrapped.type === "Identifier") {
|
|
1324
|
+
return !!(0, import_static_values.resolveAstAliasBinding)(unwrapped.name, unwrapped.start || 0, rootAliases, identifierBindings);
|
|
1325
|
+
}
|
|
1326
|
+
return unwrapped.type === "MemberExpression" && (0, import_static_values.getAstStaticPropertyName)(unwrapped) === "libs" && (0, import_static_values.isUnshadowedCtxIdentifier)(unwrapped.object, identifierBindings);
|
|
1327
|
+
}
|
|
1328
|
+
function collectAstInvalidCtxApiPatternAccesses(ast, aliases, identifierBindings) {
|
|
1329
|
+
const entries = [];
|
|
1330
|
+
const collectPattern = (pattern, capability) => {
|
|
1331
|
+
collectInvalidCtxApiObjectPatternAccesses(pattern, getCtxApiCapabilityMemberPrefix(capability)).forEach(
|
|
1332
|
+
(entry) => entries.push(entry)
|
|
1333
|
+
);
|
|
1334
|
+
};
|
|
1335
|
+
(0, import_walk.walkAstAncestor)(ast, {
|
|
1336
|
+
AssignmentExpression(node) {
|
|
1337
|
+
var _a;
|
|
1338
|
+
if (node.operator !== "=" || ((_a = node.left) == null ? void 0 : _a.type) !== "ObjectPattern") {
|
|
1339
|
+
return;
|
|
1340
|
+
}
|
|
1341
|
+
const capability = getCtxApiCapabilityFromAst(node.right, aliases, identifierBindings) || getMaybeCtxApiCapabilityFromAst(node.right, aliases, identifierBindings);
|
|
1342
|
+
if (capability) {
|
|
1343
|
+
collectPattern(node.left, capability);
|
|
1344
|
+
}
|
|
1345
|
+
},
|
|
1346
|
+
VariableDeclarator(node) {
|
|
1347
|
+
var _a;
|
|
1348
|
+
if (((_a = node.id) == null ? void 0 : _a.type) !== "ObjectPattern") {
|
|
1349
|
+
return;
|
|
1350
|
+
}
|
|
1351
|
+
const capability = getCtxApiCapabilityFromAst(node.init, aliases, identifierBindings) || getMaybeCtxApiCapabilityFromAst(node.init, aliases, identifierBindings);
|
|
1352
|
+
if (capability) {
|
|
1353
|
+
collectPattern(node.id, capability);
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
});
|
|
1357
|
+
return (0, import_bindings.dedupeIndexedEntries)(entries);
|
|
1358
|
+
}
|
|
1359
|
+
function getCtxApiCapabilityMemberPrefix(capability) {
|
|
1360
|
+
if (capability === "ctx.api.auth") {
|
|
1361
|
+
return ["auth"];
|
|
1362
|
+
}
|
|
1363
|
+
if (capability.startsWith("ctx.api.auth.")) {
|
|
1364
|
+
return ["auth", capability.slice("ctx.api.auth.".length)];
|
|
1365
|
+
}
|
|
1366
|
+
if (capability === "ctx.api.request") {
|
|
1367
|
+
return ["request"];
|
|
1368
|
+
}
|
|
1369
|
+
if (capability === "ctx.api.resource") {
|
|
1370
|
+
return ["resource"];
|
|
1371
|
+
}
|
|
1372
|
+
return [];
|
|
1373
|
+
}
|
|
1374
|
+
function collectInvalidCtxApiObjectPatternAccesses(pattern, prefix) {
|
|
1375
|
+
var _a;
|
|
1376
|
+
const entries = [];
|
|
1377
|
+
for (const property of (pattern == null ? void 0 : pattern.properties) || []) {
|
|
1378
|
+
if (!property) {
|
|
1379
|
+
continue;
|
|
1380
|
+
}
|
|
1381
|
+
if (property.type === "RestElement") {
|
|
1382
|
+
const dynamicAccess = buildInvalidCtxApiMemberAccess([...prefix, "[...]"], property.start || 0, true);
|
|
1383
|
+
if (dynamicAccess) {
|
|
1384
|
+
entries.push(dynamicAccess);
|
|
1385
|
+
}
|
|
1386
|
+
continue;
|
|
1387
|
+
}
|
|
1388
|
+
if (property.type !== "Property") {
|
|
1389
|
+
continue;
|
|
1390
|
+
}
|
|
1391
|
+
const member = (0, import_static_values.getAstStaticPropertyName)(property);
|
|
1392
|
+
if (!member) {
|
|
1393
|
+
const dynamicAccess = buildInvalidCtxApiMemberAccess([...prefix, "[...]"], property.start || 0, true);
|
|
1394
|
+
if (dynamicAccess) {
|
|
1395
|
+
entries.push(dynamicAccess);
|
|
1396
|
+
}
|
|
1397
|
+
continue;
|
|
1398
|
+
}
|
|
1399
|
+
const memberPath = [...prefix, member];
|
|
1400
|
+
const invalidAccess = buildInvalidCtxApiMemberAccess(
|
|
1401
|
+
memberPath,
|
|
1402
|
+
typeof ((_a = property.key) == null ? void 0 : _a.start) === "number" ? property.key.start : property.start || 0
|
|
1403
|
+
);
|
|
1404
|
+
if (invalidAccess) {
|
|
1405
|
+
entries.push(invalidAccess);
|
|
1406
|
+
continue;
|
|
1407
|
+
}
|
|
1408
|
+
const nestedPattern = (0, import_static_values.getAstObjectPatternFromValue)(property.value);
|
|
1409
|
+
if (nestedPattern) {
|
|
1410
|
+
collectInvalidCtxApiObjectPatternAccesses(nestedPattern, memberPath).forEach((entry) => entries.push(entry));
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
return entries;
|
|
1414
|
+
}
|
|
1415
|
+
function collectAstInvalidCtxApiMemberAccess(node, aliases, identifierBindings, source) {
|
|
1416
|
+
const access = getCtxApiMemberAccessFromAst(node, aliases, identifierBindings);
|
|
1417
|
+
if (!access || !access.memberPath.length) {
|
|
1418
|
+
return void 0;
|
|
1419
|
+
}
|
|
1420
|
+
const invalidAccess = buildInvalidCtxApiMemberAccess(
|
|
1421
|
+
access.memberPath,
|
|
1422
|
+
access.hasDynamicMember ? access.dynamicIndex : access.memberIndex,
|
|
1423
|
+
access.hasDynamicMember
|
|
1424
|
+
);
|
|
1425
|
+
return invalidAccess ? { ...invalidAccess, match: (0, import_source.getAstSource)(node, source), matchIndex: node.start || 0 } : void 0;
|
|
1426
|
+
}
|
|
1427
|
+
function buildInvalidCtxApiMemberAccess(memberPath, index, hasDynamicMember = false) {
|
|
1428
|
+
const capability = `ctx.api.${memberPath.join(".")}`;
|
|
1429
|
+
const topLevelMember = memberPath[0];
|
|
1430
|
+
if (hasDynamicMember) {
|
|
1431
|
+
return {
|
|
1432
|
+
capability,
|
|
1433
|
+
index,
|
|
1434
|
+
ruleId: "runjs-ctx-api-member-dynamic-unresolved"
|
|
1435
|
+
};
|
|
1436
|
+
}
|
|
1437
|
+
if (!import_constants.RUNJS_CTX_API_ALLOWED_MEMBERS.has(topLevelMember)) {
|
|
1438
|
+
return {
|
|
1439
|
+
capability,
|
|
1440
|
+
index,
|
|
1441
|
+
member: topLevelMember,
|
|
1442
|
+
ruleId: "runjs-ctx-api-member-unknown"
|
|
1443
|
+
};
|
|
1444
|
+
}
|
|
1445
|
+
if (topLevelMember === "request" && memberPath.length > 1) {
|
|
1446
|
+
return {
|
|
1447
|
+
capability,
|
|
1448
|
+
index,
|
|
1449
|
+
member: memberPath[1],
|
|
1450
|
+
ruleId: "runjs-ctx-api-member-unknown"
|
|
1451
|
+
};
|
|
1452
|
+
}
|
|
1453
|
+
if (topLevelMember === "resource" && memberPath.length > 1) {
|
|
1454
|
+
return {
|
|
1455
|
+
capability,
|
|
1456
|
+
index,
|
|
1457
|
+
member: memberPath[1],
|
|
1458
|
+
ruleId: "runjs-ctx-api-member-unknown"
|
|
1459
|
+
};
|
|
1460
|
+
}
|
|
1461
|
+
if (topLevelMember === "auth" && memberPath.length > 1) {
|
|
1462
|
+
const authMember = memberPath[1];
|
|
1463
|
+
if (!import_constants.RUNJS_CTX_API_AUTH_ALLOWED_MEMBERS.has(authMember)) {
|
|
1464
|
+
return {
|
|
1465
|
+
capability,
|
|
1466
|
+
index,
|
|
1467
|
+
member: authMember,
|
|
1468
|
+
ruleId: "runjs-ctx-api-auth-member-unsupported"
|
|
1469
|
+
};
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
return void 0;
|
|
1473
|
+
}
|
|
1474
|
+
function collectAstInvalidCtxApiReadonlyWrites(node, aliases, identifierBindings) {
|
|
1475
|
+
const entries = [];
|
|
1476
|
+
collectAstWriteTargetNodes(node, (target) => {
|
|
1477
|
+
const path = getCtxApiMemberPathFromAst(target, aliases, identifierBindings);
|
|
1478
|
+
if (!(path == null ? void 0 : path.isCtxApi) || path.hasDynamicMember) {
|
|
1479
|
+
return;
|
|
1480
|
+
}
|
|
1481
|
+
const memberPath = path.members.map((member) => member.name);
|
|
1482
|
+
if (memberPath[0] !== "auth") {
|
|
1483
|
+
return;
|
|
1484
|
+
}
|
|
1485
|
+
if (memberPath.length === 1 || import_constants.RUNJS_CTX_API_AUTH_ALLOWED_MEMBERS.has(memberPath[1])) {
|
|
1486
|
+
entries.push({
|
|
1487
|
+
capability: `ctx.api.${memberPath.join(".")}`,
|
|
1488
|
+
index: path.memberIndex,
|
|
1489
|
+
member: memberPath[1] || "auth",
|
|
1490
|
+
ruleId: "runjs-ctx-api-auth-member-readonly"
|
|
1491
|
+
});
|
|
1492
|
+
}
|
|
1493
|
+
});
|
|
1494
|
+
return entries;
|
|
1495
|
+
}
|
|
1496
|
+
function collectAstWriteTargetNodes(node, visit) {
|
|
1497
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
1498
|
+
if (!unwrapped) {
|
|
1499
|
+
return;
|
|
1500
|
+
}
|
|
1501
|
+
if (unwrapped.type === "MemberExpression") {
|
|
1502
|
+
visit(unwrapped);
|
|
1503
|
+
return;
|
|
1504
|
+
}
|
|
1505
|
+
if (unwrapped.type === "AssignmentPattern") {
|
|
1506
|
+
collectAstWriteTargetNodes(unwrapped.left, visit);
|
|
1507
|
+
return;
|
|
1508
|
+
}
|
|
1509
|
+
if (unwrapped.type === "RestElement") {
|
|
1510
|
+
collectAstWriteTargetNodes(unwrapped.argument, visit);
|
|
1511
|
+
return;
|
|
1512
|
+
}
|
|
1513
|
+
if (unwrapped.type === "ArrayPattern") {
|
|
1514
|
+
for (const element of unwrapped.elements || []) {
|
|
1515
|
+
collectAstWriteTargetNodes(element, visit);
|
|
1516
|
+
}
|
|
1517
|
+
return;
|
|
1518
|
+
}
|
|
1519
|
+
if (unwrapped.type === "ObjectPattern") {
|
|
1520
|
+
for (const property of unwrapped.properties || []) {
|
|
1521
|
+
if (!property) {
|
|
1522
|
+
continue;
|
|
1523
|
+
}
|
|
1524
|
+
if (property.type === "RestElement") {
|
|
1525
|
+
collectAstWriteTargetNodes(property.argument, visit);
|
|
1526
|
+
continue;
|
|
1527
|
+
}
|
|
1528
|
+
if (property.type === "Property") {
|
|
1529
|
+
collectAstWriteTargetNodes(property.value, visit);
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
function getCtxApiMemberAccessFromAst(node, aliases, identifierBindings) {
|
|
1535
|
+
const path = getCtxApiMemberPathFromAst(node, aliases, identifierBindings);
|
|
1536
|
+
if (!(path == null ? void 0 : path.isCtxApi)) {
|
|
1537
|
+
return void 0;
|
|
1538
|
+
}
|
|
1539
|
+
const memberPath = path.members.map((member) => member.name);
|
|
1540
|
+
if (path.hasDynamicMember) {
|
|
1541
|
+
memberPath.push("[...]");
|
|
1542
|
+
}
|
|
1543
|
+
if (!memberPath.length) {
|
|
1544
|
+
return void 0;
|
|
1545
|
+
}
|
|
1546
|
+
return {
|
|
1547
|
+
dynamicIndex: path.dynamicIndex,
|
|
1548
|
+
hasDynamicMember: path.hasDynamicMember,
|
|
1549
|
+
memberIndex: path.memberIndex,
|
|
1550
|
+
memberPath
|
|
1551
|
+
};
|
|
1552
|
+
}
|
|
1553
|
+
function getCtxApiMemberPathFromAst(node, aliases, identifierBindings) {
|
|
1554
|
+
var _a, _b, _c, _d;
|
|
1555
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
1556
|
+
if (!unwrapped) {
|
|
1557
|
+
return void 0;
|
|
1558
|
+
}
|
|
1559
|
+
if (unwrapped.type === "Identifier") {
|
|
1560
|
+
const alias = (0, import_static_values.resolveAstAliasBinding)(unwrapped.name, unwrapped.start || 0, aliases, identifierBindings);
|
|
1561
|
+
if (!alias) {
|
|
1562
|
+
return void 0;
|
|
1563
|
+
}
|
|
1564
|
+
return {
|
|
1565
|
+
dynamicIndex: unwrapped.start || 0,
|
|
1566
|
+
hasDynamicMember: false,
|
|
1567
|
+
isCtxApi: true,
|
|
1568
|
+
memberIndex: unwrapped.start || 0,
|
|
1569
|
+
members: getCtxApiAliasMemberPath(alias, unwrapped.start || 0)
|
|
1570
|
+
};
|
|
1571
|
+
}
|
|
1572
|
+
if (unwrapped.type !== "MemberExpression") {
|
|
1573
|
+
return void 0;
|
|
1574
|
+
}
|
|
1575
|
+
const objectPath = getCtxApiMemberPathFromAst(unwrapped.object, aliases, identifierBindings);
|
|
1576
|
+
if (objectPath == null ? void 0 : objectPath.isCtxApi) {
|
|
1577
|
+
const propertyName2 = (0, import_static_values.getAstStaticPropertyName)(unwrapped);
|
|
1578
|
+
const propertyIndex2 = typeof ((_a = unwrapped.property) == null ? void 0 : _a.start) === "number" ? unwrapped.property.start : unwrapped.start || 0;
|
|
1579
|
+
return {
|
|
1580
|
+
...objectPath,
|
|
1581
|
+
dynamicIndex: propertyName2 ? objectPath.dynamicIndex : propertyIndex2,
|
|
1582
|
+
hasDynamicMember: objectPath.hasDynamicMember || !propertyName2,
|
|
1583
|
+
memberIndex: objectPath.members.length ? objectPath.memberIndex : propertyIndex2,
|
|
1584
|
+
members: propertyName2 ? [...objectPath.members, { index: propertyIndex2, name: propertyName2 }] : objectPath.members
|
|
1585
|
+
};
|
|
1586
|
+
}
|
|
1587
|
+
const objectCapability = getMaybeCtxApiCapabilityFromAst(unwrapped.object, aliases, identifierBindings);
|
|
1588
|
+
if (objectCapability) {
|
|
1589
|
+
const propertyName2 = (0, import_static_values.getAstStaticPropertyName)(unwrapped);
|
|
1590
|
+
const propertyIndex2 = typeof ((_b = unwrapped.property) == null ? void 0 : _b.start) === "number" ? unwrapped.property.start : unwrapped.start || 0;
|
|
1591
|
+
const members = getCtxApiCapabilityMemberPath(objectCapability, ((_c = unwrapped.object) == null ? void 0 : _c.start) || propertyIndex2);
|
|
1592
|
+
return {
|
|
1593
|
+
dynamicIndex: propertyName2 ? propertyIndex2 : propertyIndex2,
|
|
1594
|
+
hasDynamicMember: !propertyName2,
|
|
1595
|
+
isCtxApi: true,
|
|
1596
|
+
memberIndex: members.length ? members[0].index : propertyIndex2,
|
|
1597
|
+
members: propertyName2 ? [...members, { index: propertyIndex2, name: propertyName2 }] : members
|
|
1598
|
+
};
|
|
1599
|
+
}
|
|
1600
|
+
if (!(0, import_static_values.isUnshadowedCtxIdentifier)(unwrapped.object, identifierBindings)) {
|
|
1601
|
+
return void 0;
|
|
1602
|
+
}
|
|
1603
|
+
const propertyName = (0, import_static_values.getAstStaticPropertyName)(unwrapped);
|
|
1604
|
+
if (propertyName !== "api") {
|
|
1605
|
+
return void 0;
|
|
1606
|
+
}
|
|
1607
|
+
const propertyIndex = typeof ((_d = unwrapped.property) == null ? void 0 : _d.start) === "number" ? unwrapped.property.start : unwrapped.start || 0;
|
|
1608
|
+
return {
|
|
1609
|
+
dynamicIndex: propertyIndex,
|
|
1610
|
+
hasDynamicMember: false,
|
|
1611
|
+
isCtxApi: true,
|
|
1612
|
+
memberIndex: propertyIndex,
|
|
1613
|
+
members: []
|
|
1614
|
+
};
|
|
1615
|
+
}
|
|
1616
|
+
function getCtxApiAliasMemberPath(alias, index) {
|
|
1617
|
+
return getCtxApiCapabilityMemberPath(alias.capability, index);
|
|
1618
|
+
}
|
|
1619
|
+
function getCtxApiCapabilityMemberPath(capability, index) {
|
|
1620
|
+
if (capability === "ctx.api.auth") {
|
|
1621
|
+
return [{ index, name: "auth" }];
|
|
1622
|
+
}
|
|
1623
|
+
if (capability.startsWith("ctx.api.auth.")) {
|
|
1624
|
+
return [
|
|
1625
|
+
{ index, name: "auth" },
|
|
1626
|
+
{ index, name: capability.slice("ctx.api.auth.".length) }
|
|
1627
|
+
];
|
|
1628
|
+
}
|
|
1629
|
+
if (capability === "ctx.api.request") {
|
|
1630
|
+
return [{ index, name: "request" }];
|
|
1631
|
+
}
|
|
1632
|
+
if (capability === "ctx.api.resource") {
|
|
1633
|
+
return [{ index, name: "resource" }];
|
|
1634
|
+
}
|
|
1635
|
+
return [];
|
|
1636
|
+
}
|
|
1637
|
+
function getCtxApiCapabilityFromAst(node, aliases, identifierBindings) {
|
|
1638
|
+
const path = getCtxApiMemberPathFromAst(node, aliases, identifierBindings);
|
|
1639
|
+
if (!(path == null ? void 0 : path.isCtxApi) || path.hasDynamicMember) {
|
|
1640
|
+
return "";
|
|
1641
|
+
}
|
|
1642
|
+
if (!path.members.length) {
|
|
1643
|
+
return "ctx.api";
|
|
1644
|
+
}
|
|
1645
|
+
if (path.members.length === 1 && import_constants.RUNJS_CTX_API_ALLOWED_MEMBERS.has(path.members[0].name)) {
|
|
1646
|
+
return `ctx.api.${path.members[0].name}`;
|
|
1647
|
+
}
|
|
1648
|
+
if (path.members.length === 2 && path.members[0].name === "auth" && import_constants.RUNJS_CTX_API_AUTH_ALLOWED_MEMBERS.has(path.members[1].name)) {
|
|
1649
|
+
return `ctx.api.auth.${path.members[1].name}`;
|
|
1650
|
+
}
|
|
1651
|
+
return "";
|
|
1652
|
+
}
|
|
1653
|
+
function getMaybeCtxApiCapabilityFromAst(node, aliases, identifierBindings) {
|
|
1654
|
+
return selectCtxApiCapability(collectPossibleCtxApiCapabilitiesFromAst(node, aliases, identifierBindings));
|
|
1655
|
+
}
|
|
1656
|
+
function collectPossibleCtxApiCapabilitiesFromAst(node, aliases, identifierBindings) {
|
|
1657
|
+
const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
1658
|
+
if (!unwrapped) {
|
|
1659
|
+
return [];
|
|
1660
|
+
}
|
|
1661
|
+
const directCapability = getCtxApiCapabilityFromAst(unwrapped, aliases, identifierBindings);
|
|
1662
|
+
if (directCapability) {
|
|
1663
|
+
return [directCapability];
|
|
1664
|
+
}
|
|
1665
|
+
if (unwrapped.type === "ConditionalExpression") {
|
|
1666
|
+
return uniqueCtxApiCapabilities([
|
|
1667
|
+
...collectPossibleCtxApiCapabilitiesFromAst(unwrapped.consequent, aliases, identifierBindings),
|
|
1668
|
+
...collectPossibleCtxApiCapabilitiesFromAst(unwrapped.alternate, aliases, identifierBindings)
|
|
1669
|
+
]);
|
|
1670
|
+
}
|
|
1671
|
+
if (unwrapped.type === "LogicalExpression") {
|
|
1672
|
+
const leftCapabilities = collectPossibleCtxApiCapabilitiesFromAst(unwrapped.left, aliases, identifierBindings);
|
|
1673
|
+
const rightCapabilities = collectPossibleCtxApiCapabilitiesFromAst(unwrapped.right, aliases, identifierBindings);
|
|
1674
|
+
if (unwrapped.operator === "&&" && leftCapabilities.length) {
|
|
1675
|
+
return leftCapabilities.every(isCtxApiCapabilityDefinitelyTruthy) ? uniqueCtxApiCapabilities(rightCapabilities) : uniqueCtxApiCapabilities([...leftCapabilities, ...rightCapabilities]);
|
|
1676
|
+
}
|
|
1677
|
+
if ((unwrapped.operator === "||" || unwrapped.operator === "??") && leftCapabilities.length) {
|
|
1678
|
+
return leftCapabilities.every(isCtxApiCapabilityDefinitelyTruthy) ? uniqueCtxApiCapabilities(leftCapabilities) : uniqueCtxApiCapabilities([...leftCapabilities, ...rightCapabilities]);
|
|
1679
|
+
}
|
|
1680
|
+
return uniqueCtxApiCapabilities([...leftCapabilities, ...rightCapabilities]);
|
|
1681
|
+
}
|
|
1682
|
+
if (unwrapped.type === "SequenceExpression") {
|
|
1683
|
+
const expressions = unwrapped.expressions || [];
|
|
1684
|
+
return collectPossibleCtxApiCapabilitiesFromAst(expressions[expressions.length - 1], aliases, identifierBindings);
|
|
1685
|
+
}
|
|
1686
|
+
if (unwrapped.type === "AssignmentExpression" && (0, import_static_values.isAstCtxApiAliasAssignmentOperator)(unwrapped.operator)) {
|
|
1687
|
+
return collectPossibleCtxApiCapabilitiesFromAst(unwrapped.right, aliases, identifierBindings);
|
|
1688
|
+
}
|
|
1689
|
+
return [];
|
|
1690
|
+
}
|
|
1691
|
+
function selectCtxApiCapability(capabilities) {
|
|
1692
|
+
const uniqueCapabilities = uniqueCtxApiCapabilities(capabilities);
|
|
1693
|
+
if (!uniqueCapabilities.length) {
|
|
1694
|
+
return "";
|
|
1695
|
+
}
|
|
1696
|
+
if (uniqueCapabilities.length === 1) {
|
|
1697
|
+
return uniqueCapabilities[0];
|
|
1698
|
+
}
|
|
1699
|
+
if (uniqueCapabilities.some((capability) => capability === "ctx.api")) {
|
|
1700
|
+
return "ctx.api";
|
|
1701
|
+
}
|
|
1702
|
+
const topLevelMembers = new Set(uniqueCapabilities.map((capability) => capability.split(".")[2]));
|
|
1703
|
+
if (topLevelMembers.size > 1) {
|
|
1704
|
+
return "ctx.api";
|
|
1705
|
+
}
|
|
1706
|
+
const topLevelMember = [...topLevelMembers][0];
|
|
1707
|
+
if (topLevelMember === "auth") {
|
|
1708
|
+
return "ctx.api.auth";
|
|
1709
|
+
}
|
|
1710
|
+
if (topLevelMember === "request" || topLevelMember === "resource") {
|
|
1711
|
+
return `ctx.api.${topLevelMember}`;
|
|
1712
|
+
}
|
|
1713
|
+
return "ctx.api";
|
|
1714
|
+
}
|
|
1715
|
+
function uniqueCtxApiCapabilities(capabilities) {
|
|
1716
|
+
return [...new Set(capabilities.filter(Boolean))];
|
|
1717
|
+
}
|
|
1718
|
+
function isCtxApiCapabilityDefinitelyTruthy(capability) {
|
|
1719
|
+
return capability === "ctx.api" || capability === "ctx.api.auth" || capability === "ctx.api.request" || capability === "ctx.api.resource" || capability === "ctx.api.auth.authenticator";
|
|
1720
|
+
}
|
|
1721
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1722
|
+
0 && (module.exports = {
|
|
1723
|
+
buildInvalidCtxApiMemberAccess,
|
|
1724
|
+
buildInvalidCtxLibMemberAccess,
|
|
1725
|
+
collectAstInvalidApiResourceCall,
|
|
1726
|
+
collectAstInvalidCtxApiMemberAccess,
|
|
1727
|
+
collectAstInvalidCtxApiPatternAccesses,
|
|
1728
|
+
collectAstInvalidCtxApiReadonlyWrites,
|
|
1729
|
+
collectAstInvalidCtxLibMemberAccess,
|
|
1730
|
+
collectAstInvalidCtxLibPatternAccesses,
|
|
1731
|
+
collectAstInvalidCtxNonFunctionCall,
|
|
1732
|
+
collectAstWriteTargetNodes,
|
|
1733
|
+
collectCtxApiAliasesFromAst,
|
|
1734
|
+
collectCtxApiObjectPatternAliases,
|
|
1735
|
+
collectCtxApiResourceAliasesFromAst,
|
|
1736
|
+
collectCtxDefiniteRootAliasesFromAst,
|
|
1737
|
+
collectCtxLibAliasesFromAst,
|
|
1738
|
+
collectCtxLibObjectPatternAliases,
|
|
1739
|
+
collectCtxLibsRootAliasesFromAst,
|
|
1740
|
+
collectCtxMethodAliasesFromAst,
|
|
1741
|
+
collectCtxNonFunctionRootAliasesFromAst,
|
|
1742
|
+
collectCtxRootAliasesFromAst,
|
|
1743
|
+
collectInvalidCtxApiObjectPatternAccesses,
|
|
1744
|
+
collectInvalidCtxLibObjectPatternAccesses,
|
|
1745
|
+
collectMaybeCtxApiResourceCallsFromAst,
|
|
1746
|
+
collectMaybeCtxApiResourceHandleAliasesFromAst,
|
|
1747
|
+
collectPossibleCtxApiCapabilitiesFromAst,
|
|
1748
|
+
filterInvalidCtxApiMemberAccessesForResourceCalls,
|
|
1749
|
+
getCtxApiAliasMemberPath,
|
|
1750
|
+
getCtxApiCapabilityFromAst,
|
|
1751
|
+
getCtxApiCapabilityMemberPath,
|
|
1752
|
+
getCtxApiCapabilityMemberPrefix,
|
|
1753
|
+
getCtxApiMemberAccessFromAst,
|
|
1754
|
+
getCtxApiMemberPathFromAst,
|
|
1755
|
+
getCtxApiResourceCallFromAst,
|
|
1756
|
+
getCtxApiResourceCallIdentity,
|
|
1757
|
+
getCtxApiResourceCalleeFromAst,
|
|
1758
|
+
getCtxApiResourceChainedMethodFromAst,
|
|
1759
|
+
getCtxApiResourceHandleAliasFromAst,
|
|
1760
|
+
getCtxApiResourceHandleAliasIdentity,
|
|
1761
|
+
getCtxApiResourceMethodAliasFromAst,
|
|
1762
|
+
getCtxLibMemberCapability,
|
|
1763
|
+
getCtxLibMemberPathFromAst,
|
|
1764
|
+
getDirectCtxLibPathFromAst,
|
|
1765
|
+
getMaybeCtxApiCapabilityFromAst,
|
|
1766
|
+
getMaybeCtxApiResourceCallFromAst,
|
|
1767
|
+
getMaybeCtxApiResourceHandleAliasFromAst,
|
|
1768
|
+
getMaybeCtxApiResourceMethodAliasFromAst,
|
|
1769
|
+
getSuggestedCtxLibMemberImport,
|
|
1770
|
+
getUniqueCtxApiResourceCall,
|
|
1771
|
+
getUniqueCtxApiResourceHandleAlias,
|
|
1772
|
+
getWrappedCtxApiResourceChainedMethodFromAst,
|
|
1773
|
+
isCtxApiCapabilityDefinitelyTruthy,
|
|
1774
|
+
isCtxApiResourcePath,
|
|
1775
|
+
isCtxLibsRootFromAst,
|
|
1776
|
+
selectCtxApiCapability,
|
|
1777
|
+
trimCtxApiAliasesAfterWrites,
|
|
1778
|
+
uniqueCtxApiCapabilities
|
|
1779
|
+
});
|