@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.
Files changed (93) hide show
  1. package/dist/client/index.js +1 -1
  2. package/dist/externalVersion.js +9 -9
  3. package/dist/node_modules/@ant-design/icons-svg/package.json +1 -1
  4. package/dist/node_modules/acorn/package.json +1 -1
  5. package/dist/node_modules/acorn-jsx/package.json +1 -1
  6. package/dist/node_modules/acorn-walk/package.json +1 -1
  7. package/dist/node_modules/ses/package.json +1 -1
  8. package/dist/node_modules/zod/package.json +1 -1
  9. package/dist/server/flow-surfaces/apply/compiler.js +10 -11
  10. package/dist/server/flow-surfaces/authoring-validation.d.ts +1 -0
  11. package/dist/server/flow-surfaces/authoring-validation.js +773 -26
  12. package/dist/server/flow-surfaces/blueprint/normalize-document.js +5 -1
  13. package/dist/server/flow-surfaces/catalog.js +9 -5
  14. package/dist/server/flow-surfaces/chart-config.js +220 -16
  15. package/dist/server/flow-surfaces/contract-guard.js +40 -6
  16. package/dist/server/flow-surfaces/default-block-actions.js +2 -0
  17. package/dist/server/flow-surfaces/errors.d.ts +15 -0
  18. package/dist/server/flow-surfaces/errors.js +49 -3
  19. package/dist/server/flow-surfaces/event-flow-normalizer.d.ts +19 -0
  20. package/dist/server/flow-surfaces/event-flow-normalizer.js +128 -0
  21. package/dist/server/flow-surfaces/filter-group.d.ts +9 -1
  22. package/dist/server/flow-surfaces/filter-group.js +402 -3
  23. package/dist/server/flow-surfaces/public-data-surface-default-filter.js +2 -1
  24. package/dist/server/flow-surfaces/route-sync.js +19 -2
  25. package/dist/server/flow-surfaces/runjs-authoring/ast/bindings.d.ts +66 -0
  26. package/dist/server/flow-surfaces/runjs-authoring/ast/bindings.js +661 -0
  27. package/dist/server/flow-surfaces/runjs-authoring/ast/execution.d.ts +20 -0
  28. package/dist/server/flow-surfaces/runjs-authoring/ast/execution.js +275 -0
  29. package/dist/server/flow-surfaces/runjs-authoring/ast/parser.d.ts +16 -0
  30. package/dist/server/flow-surfaces/runjs-authoring/ast/parser.js +130 -0
  31. package/dist/server/flow-surfaces/runjs-authoring/ast/react-values.d.ts +20 -0
  32. package/dist/server/flow-surfaces/runjs-authoring/ast/react-values.js +401 -0
  33. package/dist/server/flow-surfaces/runjs-authoring/ast/request-config.d.ts +21 -0
  34. package/dist/server/flow-surfaces/runjs-authoring/ast/request-config.js +199 -0
  35. package/dist/server/flow-surfaces/runjs-authoring/ast/source.d.ts +70 -0
  36. package/dist/server/flow-surfaces/runjs-authoring/ast/source.js +895 -0
  37. package/dist/server/flow-surfaces/runjs-authoring/ast/static-bindings.d.ts +23 -0
  38. package/dist/server/flow-surfaces/runjs-authoring/ast/static-bindings.js +618 -0
  39. package/dist/server/flow-surfaces/runjs-authoring/ast/static-values.d.ts +196 -0
  40. package/dist/server/flow-surfaces/runjs-authoring/ast/static-values.js +1777 -0
  41. package/dist/server/flow-surfaces/runjs-authoring/ast/walk.d.ts +10 -0
  42. package/dist/server/flow-surfaces/runjs-authoring/ast/walk.js +55 -0
  43. package/dist/server/flow-surfaces/runjs-authoring/collectors.d.ts +12 -0
  44. package/dist/server/flow-surfaces/runjs-authoring/collectors.js +589 -0
  45. package/dist/server/flow-surfaces/runjs-authoring/index.d.ts +2 -25
  46. package/dist/server/flow-surfaces/runjs-authoring/index.js +5 -11138
  47. package/dist/server/flow-surfaces/runjs-authoring/inspect.d.ts +13 -0
  48. package/dist/server/flow-surfaces/runjs-authoring/inspect.js +149 -0
  49. package/dist/server/flow-surfaces/runjs-authoring/internal-types.d.ts +333 -0
  50. package/dist/server/flow-surfaces/runjs-authoring/internal-types.js +36 -0
  51. package/dist/server/flow-surfaces/runjs-authoring/rules.js +2 -0
  52. package/dist/server/flow-surfaces/runjs-authoring/runtime/constants.d.ts +67 -0
  53. package/dist/server/flow-surfaces/runjs-authoring/runtime/constants.js +757 -0
  54. package/dist/server/flow-surfaces/runjs-authoring/runtime/errors.d.ts +22 -0
  55. package/dist/server/flow-surfaces/runjs-authoring/runtime/errors.js +91 -0
  56. package/dist/server/flow-surfaces/runjs-authoring/runtime/source-budget.d.ts +16 -0
  57. package/dist/server/flow-surfaces/runjs-authoring/runtime/source-budget.js +115 -0
  58. package/dist/server/flow-surfaces/runjs-authoring/runtime/surface.d.ts +19 -0
  59. package/dist/server/flow-surfaces/runjs-authoring/runtime/surface.js +140 -0
  60. package/dist/server/flow-surfaces/runjs-authoring/runtime/types.d.ts +91 -0
  61. package/dist/server/flow-surfaces/runjs-authoring/runtime/types.js +24 -0
  62. package/dist/server/flow-surfaces/runjs-authoring/scan/ctx-api.d.ts +138 -0
  63. package/dist/server/flow-surfaces/runjs-authoring/scan/ctx-api.js +1779 -0
  64. package/dist/server/flow-surfaces/runjs-authoring/scan/filter.d.ts +10 -0
  65. package/dist/server/flow-surfaces/runjs-authoring/scan/filter.js +1583 -0
  66. package/dist/server/flow-surfaces/runjs-authoring/scan/index.d.ts +195 -0
  67. package/dist/server/flow-surfaces/runjs-authoring/scan/index.js +463 -0
  68. package/dist/server/flow-surfaces/runjs-authoring/scan/react-render.d.ts +48 -0
  69. package/dist/server/flow-surfaces/runjs-authoring/scan/react-render.js +379 -0
  70. package/dist/server/flow-surfaces/runjs-authoring/scan/react.d.ts +26 -0
  71. package/dist/server/flow-surfaces/runjs-authoring/scan/react.js +1441 -0
  72. package/dist/server/flow-surfaces/runjs-authoring/scan/resource.d.ts +23 -0
  73. package/dist/server/flow-surfaces/runjs-authoring/scan/resource.js +1427 -0
  74. package/dist/server/flow-surfaces/runjs-authoring/scan/source-patterns.d.ts +91 -0
  75. package/dist/server/flow-surfaces/runjs-authoring/scan/source-patterns.js +889 -0
  76. package/dist/server/flow-surfaces/runjs-authoring/types.d.ts +1 -1
  77. package/dist/server/flow-surfaces/runjs-authoring/unknown-global-stop/index.d.ts +10 -0
  78. package/dist/server/flow-surfaces/runjs-authoring/unknown-global-stop/index.js +40 -0
  79. package/dist/server/flow-surfaces/runjs-authoring/validators/index.d.ts +12 -0
  80. package/dist/server/flow-surfaces/runjs-authoring/validators/index.js +887 -0
  81. package/dist/server/flow-surfaces/service-helpers.d.ts +29 -0
  82. package/dist/server/flow-surfaces/service-helpers.js +105 -0
  83. package/dist/server/flow-surfaces/service-utils.d.ts +15 -3
  84. package/dist/server/flow-surfaces/service-utils.js +6 -5
  85. package/dist/server/flow-surfaces/service.d.ts +7 -1
  86. package/dist/server/flow-surfaces/service.js +488 -94
  87. package/dist/server/flow-surfaces/types.d.ts +3 -0
  88. package/dist/server/repository.d.ts +12 -1
  89. package/dist/server/repository.js +195 -23
  90. package/dist/swagger/flow-surfaces.d.ts +175 -0
  91. package/dist/swagger/flow-surfaces.js +130 -51
  92. package/dist/swagger/index.d.ts +175 -0
  93. package/package.json +2 -2
@@ -0,0 +1,1427 @@
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 __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ var resource_exports = {};
38
+ __export(resource_exports, {
39
+ collectAstFlowResourceAliasesFromAst: () => collectAstFlowResourceAliasesFromAst,
40
+ collectAstInvalidFlowResourceMethodCall: () => collectAstInvalidFlowResourceMethodCall,
41
+ collectAstInvalidResourceActionCalls: () => collectAstInvalidResourceActionCalls,
42
+ collectAstInvalidResourceTypeCall: () => collectAstInvalidResourceTypeCall,
43
+ collectAstSharedCtxResourceCallsInFunctions: () => collectAstSharedCtxResourceCallsInFunctions,
44
+ collectPossibleAstFlowResourceSourcesFromAst: () => collectPossibleAstFlowResourceSourcesFromAst,
45
+ getAstFlowResourceFactoryCallFromAst: () => getAstFlowResourceFactoryCallFromAst,
46
+ getDirectAstFlowResourceSourceFromAst: () => getDirectAstFlowResourceSourceFromAst,
47
+ getMaybeAstFlowResourceSourceFromAst: () => getMaybeAstFlowResourceSourceFromAst,
48
+ getRunJsDefaultDataSourceKey: () => getRunJsDefaultDataSourceKey,
49
+ isAstCtxResourceMember: () => isAstCtxResourceMember
50
+ });
51
+ module.exports = __toCommonJS(resource_exports);
52
+ var _ = __toESM(require("lodash"));
53
+ var import_service_helpers = require("../../service-helpers");
54
+ var import_constants = require("../runtime/constants");
55
+ var import_surface = require("../runtime/surface");
56
+ var import_source = require("../ast/source");
57
+ var import_walk = require("../ast/walk");
58
+ var import_bindings = require("../ast/bindings");
59
+ var import_execution = require("../ast/execution");
60
+ var import_static_values = require("../ast/static-values");
61
+ var import_request_config = require("../ast/request-config");
62
+ var import_ctx_api = require("./ctx-api");
63
+ function collectAstInvalidResourceTypeCall(node, method, capability, source, stringBindings, identifierBindings) {
64
+ var _a;
65
+ const firstArg = (_a = node.arguments) == null ? void 0 : _a[0];
66
+ if (!firstArg) {
67
+ return [
68
+ {
69
+ capability,
70
+ expression: "",
71
+ index: node.start || 0,
72
+ ruleId: "runjs-make-resource-type-unresolved"
73
+ }
74
+ ];
75
+ }
76
+ const resolved = (0, import_static_values.resolveAstResourceTypeExpression)(firstArg, source, stringBindings, identifierBindings);
77
+ if (resolved.status === "unresolved") {
78
+ return [
79
+ {
80
+ capability,
81
+ expression: resolved.expression,
82
+ index: node.start || 0,
83
+ ruleId: "runjs-make-resource-type-unresolved"
84
+ }
85
+ ];
86
+ }
87
+ const allowedResourceTypes = method === "initResource" ? import_constants.INIT_RESOURCE_CLASS_NAMES : import_constants.FLOW_RESOURCE_CLASS_NAMES;
88
+ if (!allowedResourceTypes.has(resolved.value)) {
89
+ return [
90
+ {
91
+ capability,
92
+ expression: source.slice(firstArg.start || 0, firstArg.end || firstArg.start || 0).trim(),
93
+ index: node.start || 0,
94
+ resourceType: resolved.value,
95
+ ruleId: "runjs-make-resource-type-invalid"
96
+ }
97
+ ];
98
+ }
99
+ return [];
100
+ }
101
+ function collectAstFlowResourceAliasesFromAst(ast, source, ctxMethodAliases, stringBindings, identifierBindings) {
102
+ const aliases = [];
103
+ const writes = (0, import_execution.collectAstIdentifierWritesFromAst)(ast, source);
104
+ const getActiveAliases = () => (0, import_static_values.trimAstAliasesAfterWrites)(aliases, writes, identifierBindings);
105
+ const addAlias = (name, resource, node, ancestors, isVar = false) => {
106
+ const scope = (0, import_bindings.getAstBindingScopeRange)(ancestors, source.length, isVar);
107
+ aliases.push({
108
+ capability: resource.capability,
109
+ declarationStart: typeof (node == null ? void 0 : node.start) === "number" ? node.start : scope.start,
110
+ executionScope: (0, import_bindings.getAstExecutionScopeRange)(ancestors, source.length),
111
+ name,
112
+ resourceType: resource.resourceType,
113
+ start: typeof (node == null ? void 0 : node.start) === "number" ? node.start : scope.start,
114
+ end: scope.end
115
+ });
116
+ };
117
+ const collectCtxResourcePatternAliases = (pattern, ctxNode, ancestors, isVar = false) => {
118
+ if (!(0, import_static_values.isUnshadowedCtxIdentifier)(ctxNode, identifierBindings)) {
119
+ return;
120
+ }
121
+ (0, import_static_values.collectAstObjectPatternAliases)(pattern, (name, member, aliasNode) => {
122
+ if (member === "resource") {
123
+ addAlias(
124
+ name,
125
+ {
126
+ capability: "ctx.resource",
127
+ index: typeof (ctxNode == null ? void 0 : ctxNode.start) === "number" ? ctxNode.start : 0,
128
+ resourceType: "unknown"
129
+ },
130
+ aliasNode || pattern,
131
+ ancestors,
132
+ isVar
133
+ );
134
+ }
135
+ });
136
+ };
137
+ (0, import_walk.walkAstAncestor)(ast, {
138
+ AssignmentExpression(node, ancestors) {
139
+ var _a, _b;
140
+ if ((0, import_static_values.isAstCtxApiAliasAssignmentOperator)(node.operator) && ((_a = node.left) == null ? void 0 : _a.type) === "Identifier") {
141
+ const resource = getMaybeAstFlowResourceSourceFromAst(
142
+ node.right,
143
+ getActiveAliases(),
144
+ source,
145
+ identifierBindings,
146
+ ctxMethodAliases,
147
+ stringBindings
148
+ );
149
+ if (resource) {
150
+ addAlias(node.left.name, resource, node, ancestors);
151
+ }
152
+ return;
153
+ }
154
+ if (node.operator === "=" && ((_b = node.left) == null ? void 0 : _b.type) === "ObjectPattern") {
155
+ collectCtxResourcePatternAliases(node.left, node.right, ancestors);
156
+ }
157
+ },
158
+ VariableDeclarator(node, ancestors) {
159
+ var _a, _b;
160
+ const declaration = (0, import_bindings.findAstAncestor)(ancestors, "VariableDeclaration");
161
+ const isVar = (declaration == null ? void 0 : declaration.kind) === "var";
162
+ if (((_a = node.id) == null ? void 0 : _a.type) === "Identifier") {
163
+ const resource = getMaybeAstFlowResourceSourceFromAst(
164
+ node.init,
165
+ getActiveAliases(),
166
+ source,
167
+ identifierBindings,
168
+ ctxMethodAliases,
169
+ stringBindings
170
+ );
171
+ if (resource) {
172
+ addAlias(node.id.name, resource, node, ancestors, isVar);
173
+ }
174
+ return;
175
+ }
176
+ if (((_b = node.id) == null ? void 0 : _b.type) === "ObjectPattern") {
177
+ collectCtxResourcePatternAliases(node.id, node.init, ancestors, isVar);
178
+ }
179
+ }
180
+ });
181
+ return (0, import_static_values.trimAstAliasesAfterWrites)(aliases, writes, identifierBindings);
182
+ }
183
+ function collectAstInvalidFlowResourceMethodCall(node, aliases, source, identifierBindings, ctxMethodAliases, stringBindings) {
184
+ var _a;
185
+ const callee = (0, import_bindings.unwrapAstChainExpression)(node.callee);
186
+ if (!callee || callee.type !== "MemberExpression") {
187
+ return { invalidListCalls: [], invalidMethodCalls: [] };
188
+ }
189
+ const method = (0, import_static_values.getAstStaticPropertyName)(callee);
190
+ if (!method) {
191
+ return { invalidListCalls: [], invalidMethodCalls: [] };
192
+ }
193
+ const resource = getMaybeAstFlowResourceSourceFromAst(
194
+ callee.object,
195
+ aliases,
196
+ source,
197
+ identifierBindings,
198
+ ctxMethodAliases,
199
+ stringBindings
200
+ );
201
+ if (!resource) {
202
+ return { invalidListCalls: [], invalidMethodCalls: [] };
203
+ }
204
+ const capability = (0, import_source.getAstSource)(callee, source);
205
+ if (method === "list") {
206
+ return {
207
+ invalidListCalls: [
208
+ {
209
+ capability,
210
+ index: typeof callee.start === "number" ? callee.start : node.start || 0
211
+ }
212
+ ],
213
+ invalidMethodCalls: []
214
+ };
215
+ }
216
+ if (getFlowResourceAllowedMethods(resource.resourceType).has(method)) {
217
+ return { invalidListCalls: [], invalidMethodCalls: [] };
218
+ }
219
+ return {
220
+ invalidListCalls: [],
221
+ invalidMethodCalls: [
222
+ {
223
+ capability,
224
+ index: typeof ((_a = callee.property) == null ? void 0 : _a.start) === "number" ? callee.property.start : typeof callee.start === "number" ? callee.start : node.start || 0,
225
+ method,
226
+ resourceType: resource.resourceType,
227
+ suggestedMethod: getSuggestedFlowResourceMethod(method)
228
+ }
229
+ ]
230
+ };
231
+ }
232
+ function collectAstInvalidResourceActionCalls(ast, source, aliases, identifierBindings, ctxMethodAliases, ctxApiAliases, ctxApiResourceAliases, stringBindings, staticFilterValueBindings, context) {
233
+ const entries = [];
234
+ const ctxResourceStates = /* @__PURE__ */ new Map();
235
+ const aliasStates = /* @__PURE__ */ new Map();
236
+ const events = [];
237
+ const actionAliases = [];
238
+ const writes = (0, import_execution.collectAstIdentifierWritesFromAst)(ast, source);
239
+ const scopeKey = (scope) => `${scope.start}:${scope.end}`;
240
+ const aliasKey = (alias) => `${alias.name}:${alias.declarationStart ?? alias.start}`;
241
+ const defaultDataSourceKey = getRunJsDefaultDataSourceKey(context);
242
+ const defaultCtxState = () => ({
243
+ capability: "ctx.resource",
244
+ collectionName: (0, import_surface.normalizeText)(context.currentCollectionName || context.hostCollectionName) || void 0,
245
+ dataSourceKey: defaultDataSourceKey,
246
+ resourceType: "unknown"
247
+ });
248
+ const mergeResourceState = (state, nextState) => {
249
+ state.capability = nextState.capability;
250
+ state.dataSourceKey = nextState.dataSourceKey;
251
+ state.resourceType = nextState.resourceType;
252
+ state.collectionName = nextState.collectionName;
253
+ return state;
254
+ };
255
+ const getAliasState = (alias) => {
256
+ const key = aliasKey(alias);
257
+ const current = aliasStates.get(key);
258
+ if (current) {
259
+ return current;
260
+ }
261
+ const initial = alias.capability === "ctx.resource" ? {
262
+ ...defaultCtxState(),
263
+ resourceType: alias.resourceType === "unknown" ? defaultCtxState().resourceType : alias.resourceType
264
+ } : {
265
+ capability: alias.capability,
266
+ dataSourceKey: defaultDataSourceKey,
267
+ resourceType: alias.resourceType
268
+ };
269
+ aliasStates.set(key, initial);
270
+ return initial;
271
+ };
272
+ const setAliasState = (alias, state) => {
273
+ if (alias.resourceType !== "unknown") {
274
+ state.resourceType = alias.resourceType;
275
+ }
276
+ aliasStates.set(aliasKey(alias), state);
277
+ return state;
278
+ };
279
+ const setCtxState = (executionScope, state) => {
280
+ const nextState = {
281
+ ...state,
282
+ capability: "ctx.resource"
283
+ };
284
+ ctxResourceStates.set(scopeKey(executionScope), {
285
+ scope: executionScope,
286
+ state: nextState
287
+ });
288
+ return nextState;
289
+ };
290
+ const getCtxState = (executionScope) => {
291
+ var _a, _b;
292
+ const exact = (_a = ctxResourceStates.get(scopeKey(executionScope))) == null ? void 0 : _a.state;
293
+ if (exact) {
294
+ return exact;
295
+ }
296
+ const inherited = (_b = Array.from(ctxResourceStates.values()).filter(({ scope }) => scope.start <= executionScope.start && scope.end >= executionScope.end).sort(
297
+ (left, right) => left.scope.end - left.scope.start - (right.scope.end - right.scope.start) || right.scope.start - left.scope.start
298
+ )[0]) == null ? void 0 : _b.state;
299
+ if (inherited) {
300
+ return inherited;
301
+ }
302
+ return setCtxState(executionScope, defaultCtxState());
303
+ };
304
+ const findDeclaredAlias = (aliasName, index) => aliases.filter((alias) => alias.name === aliasName && (alias.declarationStart ?? alias.start) <= index).sort((left, right) => (right.declarationStart ?? right.start) - (left.declarationStart ?? left.start))[0];
305
+ const resolveStaticStringArg = (node) => {
306
+ const resolved = (0, import_static_values.resolveAstResourceTypeExpression)(node, source, stringBindings, identifierBindings);
307
+ return resolved.status === "resolved" ? resolved.value : void 0;
308
+ };
309
+ const applyStaticResourceStateMethod = (state, method, node) => {
310
+ var _a, _b;
311
+ if (method === "setDataSourceKey") {
312
+ const dataSourceKey = resolveStaticStringArg((_a = node.arguments) == null ? void 0 : _a[0]);
313
+ return {
314
+ ...state,
315
+ dataSourceKey: dataSourceKey || ""
316
+ };
317
+ }
318
+ if (method === "setResourceName") {
319
+ const collectionName = resolveStaticStringArg((_b = node.arguments) == null ? void 0 : _b[0]);
320
+ return {
321
+ ...state,
322
+ collectionName
323
+ };
324
+ }
325
+ return state;
326
+ };
327
+ const getAliasResourceTarget = (alias, executionScope) => ({
328
+ capability: alias.capability,
329
+ state: getAliasState(alias),
330
+ updateState: (nextState) => {
331
+ mergeResourceState(getAliasState(alias), nextState);
332
+ }
333
+ });
334
+ const resolveResourceExpressionTarget = (node, executionScope) => {
335
+ const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
336
+ if (!unwrapped) {
337
+ return void 0;
338
+ }
339
+ if (isAstCtxResourceMember(unwrapped, identifierBindings)) {
340
+ return {
341
+ capability: "ctx.resource",
342
+ state: getCtxState(executionScope),
343
+ updateState: (nextState) => mergeResourceState(getCtxState(executionScope), nextState)
344
+ };
345
+ }
346
+ if (unwrapped.type === "Identifier") {
347
+ const alias = (0, import_static_values.resolveAstAliasBinding)(unwrapped.name, unwrapped.start || 0, aliases, identifierBindings);
348
+ return alias ? getAliasResourceTarget(alias, executionScope) : void 0;
349
+ }
350
+ const factory = getAstFlowResourceFactoryCallFromAst(
351
+ unwrapped,
352
+ ctxMethodAliases,
353
+ source,
354
+ stringBindings,
355
+ identifierBindings
356
+ );
357
+ if (factory) {
358
+ return {
359
+ capability: factory.capability,
360
+ state: {
361
+ capability: factory.capability,
362
+ dataSourceKey: defaultDataSourceKey,
363
+ resourceType: factory.resourceType
364
+ },
365
+ updateState: _.noop
366
+ };
367
+ }
368
+ if (unwrapped.type === "CallExpression") {
369
+ const callTarget = getResourceCallTarget(unwrapped, executionScope);
370
+ if (!callTarget || !import_constants.RUNJS_RESOURCE_CHAINABLE_STATE_METHODS.has(callTarget.method)) {
371
+ return void 0;
372
+ }
373
+ return {
374
+ ...callTarget,
375
+ state: applyStaticResourceStateMethod(callTarget.state, callTarget.method, unwrapped)
376
+ };
377
+ }
378
+ return void 0;
379
+ };
380
+ const resolveExpressionState = (node, executionScope) => {
381
+ var _a;
382
+ return (_a = resolveResourceExpressionTarget(node, executionScope)) == null ? void 0 : _a.state;
383
+ };
384
+ const getResourceCallTarget = (node, executionScope) => {
385
+ const callee = (0, import_bindings.unwrapAstChainExpression)(node.callee);
386
+ if (!callee || callee.type !== "MemberExpression") {
387
+ return void 0;
388
+ }
389
+ const method = (0, import_static_values.getAstStaticPropertyName)(callee);
390
+ if (!method) {
391
+ return void 0;
392
+ }
393
+ const objectTarget = resolveResourceExpressionTarget(callee.object, executionScope);
394
+ if (objectTarget) {
395
+ return {
396
+ ...objectTarget,
397
+ capability: (0, import_source.getAstSource)(callee, source),
398
+ method
399
+ };
400
+ }
401
+ return void 0;
402
+ };
403
+ const addInvalidAction = (input) => {
404
+ const validation = validateRunJsCollectionResourceAction({
405
+ actionName: input.actionName,
406
+ collectionName: input.collectionName,
407
+ dataSourceKey: input.dataSourceKey,
408
+ context,
409
+ resourceType: input.resourceType,
410
+ strictCollectionEndpoint: input.strictCollectionEndpoint
411
+ });
412
+ if (!validation) {
413
+ return;
414
+ }
415
+ entries.push({
416
+ actionName: validation.actionName,
417
+ allowedActions: validation.allowedActions,
418
+ capability: input.capability,
419
+ collectionName: input.collectionName,
420
+ dataSourceKey: input.dataSourceKey,
421
+ endpoint: input.endpoint,
422
+ index: input.index,
423
+ invalidReason: validation.invalidReason,
424
+ resourceType: input.resourceType,
425
+ suggestedMethod: input.actionName === "refresh" ? "refresh" : void 0
426
+ });
427
+ };
428
+ const getActiveActionAliases = () => (0, import_static_values.trimAstAliasesAfterWrites)(actionAliases, writes, identifierBindings);
429
+ const resolveApiResourceCollectionName = (resourceName, dataSourceKey) => resolveRunJsCollectionNameFromDottedResourceName(resourceName, context, dataSourceKey ?? defaultDataSourceKey) || resourceName;
430
+ const getUniqueApiResourceCallSource = (node) => getUniqueApiResourceCallSourceFromCalls(
431
+ (0, import_ctx_api.collectMaybeCtxApiResourceCallsFromAst)(node, ctxApiAliases, source, identifierBindings)
432
+ );
433
+ const getUniqueApiResourceCallSourceFromCalls = (resourceFactoryCalls) => {
434
+ if (resourceFactoryCalls.length <= 1) {
435
+ return resourceFactoryCalls[0];
436
+ }
437
+ const firstIdentity = getApiResourceCallSourceIdentity(resourceFactoryCalls[0]);
438
+ if (!firstIdentity || resourceFactoryCalls.some((entry) => getApiResourceCallSourceIdentity(entry) !== firstIdentity)) {
439
+ return void 0;
440
+ }
441
+ return resourceFactoryCalls[0];
442
+ };
443
+ const getApiResourceCallSourceIdentity = (resourceFactoryCall) => {
444
+ var _a;
445
+ const dataSourceKey = (0, import_request_config.getRunJsApiResourceCallDataSourceKey)(
446
+ resourceFactoryCall.args,
447
+ source,
448
+ stringBindings,
449
+ staticFilterValueBindings,
450
+ identifierBindings
451
+ );
452
+ const resourceName = (0, import_static_values.resolveRunJsStaticString)(
453
+ (_a = resourceFactoryCall.args) == null ? void 0 : _a[0],
454
+ source,
455
+ stringBindings,
456
+ identifierBindings
457
+ );
458
+ const collectionName = resolveApiResourceCollectionName(resourceName, dataSourceKey);
459
+ if (typeof collectionName !== "string" && typeof dataSourceKey !== "string") {
460
+ return "";
461
+ }
462
+ return `${dataSourceKey ?? defaultDataSourceKey}:${collectionName ?? ""}`;
463
+ };
464
+ const addActionAlias = (name, actionSource, node, ancestors, isVar = false) => {
465
+ if (!name) {
466
+ return;
467
+ }
468
+ const scope = (0, import_bindings.getAstBindingScopeRange)(ancestors, source.length, isVar);
469
+ actionAliases.push({
470
+ ...actionSource,
471
+ declarationStart: typeof (node == null ? void 0 : node.start) === "number" ? node.start : scope.start,
472
+ executionScope: (0, import_bindings.getAstExecutionScopeRange)(ancestors, source.length),
473
+ name,
474
+ start: typeof (node == null ? void 0 : node.start) === "number" ? node.start : scope.start,
475
+ end: scope.end
476
+ });
477
+ };
478
+ const getApiResourceHandleSource = (node) => {
479
+ var _a;
480
+ const resourceFactoryCall = getUniqueApiResourceCallSource(node);
481
+ if (resourceFactoryCall) {
482
+ const dataSourceKey = (0, import_request_config.getRunJsApiResourceCallDataSourceKey)(
483
+ resourceFactoryCall.args,
484
+ source,
485
+ stringBindings,
486
+ staticFilterValueBindings,
487
+ identifierBindings
488
+ );
489
+ const resourceName = (0, import_static_values.resolveRunJsStaticString)(
490
+ (_a = resourceFactoryCall.args) == null ? void 0 : _a[0],
491
+ source,
492
+ stringBindings,
493
+ identifierBindings
494
+ );
495
+ return {
496
+ calleeSource: resourceFactoryCall.calleeSource,
497
+ dataSourceKey,
498
+ index: resourceFactoryCall.index,
499
+ resourceName: resolveApiResourceCollectionName(resourceName, dataSourceKey)
500
+ };
501
+ }
502
+ const handleAlias = (0, import_ctx_api.getMaybeCtxApiResourceHandleAliasFromAst)(
503
+ node,
504
+ ctxApiResourceAliases.handles,
505
+ identifierBindings
506
+ );
507
+ return handleAlias ? {
508
+ calleeSource: handleAlias.calleeSource,
509
+ dataSourceKey: handleAlias.dataSourceKey,
510
+ index: handleAlias.start,
511
+ resourceName: resolveApiResourceCollectionName(handleAlias.resourceName, handleAlias.dataSourceKey)
512
+ } : void 0;
513
+ };
514
+ const dedupeApiResourceActionSources = (sources) => {
515
+ const seen = /* @__PURE__ */ new Set();
516
+ return sources.filter((entry) => {
517
+ const key = `${entry.actionName}:${entry.capability}:${entry.collectionName || ""}:${entry.dataSourceKey}`;
518
+ if (seen.has(key)) {
519
+ return false;
520
+ }
521
+ seen.add(key);
522
+ return true;
523
+ });
524
+ };
525
+ const getConsistentApiResourceActionSources = (sources) => {
526
+ const dedupedSources = dedupeApiResourceActionSources(sources);
527
+ if (dedupedSources.length <= 1) {
528
+ return dedupedSources;
529
+ }
530
+ const firstIdentity = getApiResourceActionSourceIdentity(dedupedSources[0]);
531
+ if (!firstIdentity || dedupedSources.some((entry) => getApiResourceActionSourceIdentity(entry) !== firstIdentity)) {
532
+ return [];
533
+ }
534
+ return [dedupedSources[0]];
535
+ };
536
+ const getApiResourceActionSourceIdentity = (actionSource) => {
537
+ if (!actionSource.actionName) {
538
+ return "";
539
+ }
540
+ return `${actionSource.actionName}:${actionSource.collectionName ?? ""}:${actionSource.dataSourceKey ?? ""}`;
541
+ };
542
+ const resolveApiResourceActionAliasSources = (name, index) => {
543
+ var _a;
544
+ const candidates = getActiveActionAliases().filter(
545
+ (entry) => entry.name === name && index >= entry.start && index < entry.end && !(0, import_static_values.hasAstShadowBinding)(name, index, entry, identifierBindings)
546
+ ).sort((left, right) => right.start - left.start);
547
+ const latestStart = (_a = candidates[0]) == null ? void 0 : _a.start;
548
+ return candidates.filter((entry) => entry.start === latestStart).map((alias) => ({
549
+ actionName: alias.actionName,
550
+ capability: alias.capability,
551
+ collectionName: alias.collectionName,
552
+ dataSourceKey: alias.dataSourceKey
553
+ }));
554
+ };
555
+ const getApiResourceActionSourcesFromAst = (node) => {
556
+ const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
557
+ if (!unwrapped) {
558
+ return [];
559
+ }
560
+ if (unwrapped.type === "Identifier") {
561
+ return resolveApiResourceActionAliasSources(unwrapped.name, unwrapped.start || 0);
562
+ }
563
+ if (unwrapped.type === "MemberExpression") {
564
+ const invocationMember = (0, import_static_values.getAstStaticPropertyName)(unwrapped);
565
+ if (invocationMember === "call" || invocationMember === "apply" || invocationMember === "bind") {
566
+ return getApiResourceActionSourcesFromAst(unwrapped.object).map((wrapped) => ({
567
+ ...wrapped,
568
+ capability: (0, import_source.getAstSource)(unwrapped, source) || wrapped.capability
569
+ }));
570
+ }
571
+ const actionName = invocationMember;
572
+ if (!actionName) {
573
+ return [];
574
+ }
575
+ const handleSource = getApiResourceHandleSource(unwrapped.object);
576
+ if (!handleSource) {
577
+ return [];
578
+ }
579
+ return [
580
+ {
581
+ actionName,
582
+ capability: handleSource.resourceName ? `${handleSource.calleeSource}('${handleSource.resourceName}').${actionName}` : `${handleSource.calleeSource}(...).${actionName}`,
583
+ collectionName: handleSource.resourceName,
584
+ dataSourceKey: handleSource.dataSourceKey ?? defaultDataSourceKey
585
+ }
586
+ ];
587
+ }
588
+ if (unwrapped.type === "ConditionalExpression") {
589
+ return getConsistentApiResourceActionSources([
590
+ ...getApiResourceActionSourcesFromAst(unwrapped.consequent),
591
+ ...getApiResourceActionSourcesFromAst(unwrapped.alternate)
592
+ ]);
593
+ }
594
+ if (unwrapped.type === "LogicalExpression") {
595
+ const leftSources = getApiResourceActionSourcesFromAst(unwrapped.left);
596
+ return getConsistentApiResourceActionSources([
597
+ ...leftSources,
598
+ ...getApiResourceActionSourcesFromAst(unwrapped.right)
599
+ ]);
600
+ }
601
+ if (unwrapped.type === "SequenceExpression") {
602
+ const expressions = unwrapped.expressions || [];
603
+ return getApiResourceActionSourcesFromAst(expressions[expressions.length - 1]);
604
+ }
605
+ if (unwrapped.type === "AssignmentExpression" && (0, import_static_values.isAstCtxApiAliasAssignmentOperator)(unwrapped.operator)) {
606
+ return getApiResourceActionSourcesFromAst(unwrapped.right);
607
+ }
608
+ return [];
609
+ };
610
+ const getRunJsStaticRequestResourceActionFromAst = (node, dataSourceKey) => {
611
+ const objectArg = (0, import_request_config.getRunJsStaticRequestConfigObjectFromAst)(node, identifierBindings, staticFilterValueBindings);
612
+ if (!objectArg) {
613
+ return void 0;
614
+ }
615
+ const resourceProperty = (0, import_static_values.getRunJsObjectProperty)(
616
+ objectArg,
617
+ ["collection", "collectionName", "resource"],
618
+ identifierBindings,
619
+ staticFilterValueBindings
620
+ );
621
+ const actionProperty = (0, import_static_values.getRunJsObjectProperty)(objectArg, ["action"], identifierBindings, staticFilterValueBindings);
622
+ const actionName = (0, import_static_values.resolveRunJsStaticString)(actionProperty == null ? void 0 : actionProperty.value, source, stringBindings, identifierBindings);
623
+ if (!actionName) {
624
+ return void 0;
625
+ }
626
+ const resourceName = (0, import_static_values.resolveRunJsStaticString)(resourceProperty == null ? void 0 : resourceProperty.value, source, stringBindings, identifierBindings);
627
+ return {
628
+ actionName,
629
+ collectionName: resolveRunJsCollectionNameFromDottedResourceName(resourceName, context, dataSourceKey) || resourceName
630
+ };
631
+ };
632
+ const collectApiResourceActionPatternAliases = (pattern, handleNode, ancestors, isVar = false) => {
633
+ const handleSource = getApiResourceHandleSource(handleNode);
634
+ if (!handleSource) {
635
+ return;
636
+ }
637
+ (0, import_static_values.collectAstObjectPatternAliases)(pattern, (name, actionName, aliasNode) => {
638
+ addActionAlias(
639
+ name,
640
+ {
641
+ actionName,
642
+ capability: handleSource.resourceName ? `${handleSource.calleeSource}('${handleSource.resourceName}').${actionName}` : `${handleSource.calleeSource}(...).${actionName}`,
643
+ collectionName: handleSource.resourceName,
644
+ dataSourceKey: handleSource.dataSourceKey ?? defaultDataSourceKey
645
+ },
646
+ aliasNode || pattern,
647
+ ancestors,
648
+ isVar
649
+ );
650
+ });
651
+ };
652
+ const collectApiResourceActions = (node) => {
653
+ var _a, _b, _c;
654
+ const resourceFactoryCall = (0, import_ctx_api.getCtxApiResourceCallFromAst)(node, ctxApiAliases, source, identifierBindings);
655
+ if (resourceFactoryCall) {
656
+ const rawResourceName = (0, import_static_values.resolveRunJsStaticString)((_a = node.arguments) == null ? void 0 : _a[0], source, stringBindings, identifierBindings);
657
+ const actionName2 = resolveStaticStringArg((_b = node.arguments) == null ? void 0 : _b[1]);
658
+ const dataSourceKey = (0, import_request_config.getRunJsApiResourceCallDataSourceKey)(
659
+ resourceFactoryCall.args,
660
+ source,
661
+ stringBindings,
662
+ staticFilterValueBindings,
663
+ identifierBindings
664
+ ) ?? defaultDataSourceKey;
665
+ const resourceName = resolveApiResourceCollectionName(rawResourceName, dataSourceKey);
666
+ addInvalidAction({
667
+ actionName: actionName2,
668
+ capability: resourceName ? `${resourceFactoryCall.calleeSource}('${resourceName}', '${actionName2 || ""}')` : `${resourceFactoryCall.calleeSource}(..., '${actionName2 || ""}')`,
669
+ collectionName: resourceName,
670
+ dataSourceKey,
671
+ index: resourceFactoryCall.index
672
+ });
673
+ }
674
+ const callee = (0, import_bindings.unwrapAstChainExpression)(node.callee);
675
+ if (!callee || callee.type !== "MemberExpression") {
676
+ return;
677
+ }
678
+ const actionName = (0, import_static_values.getAstStaticPropertyName)(callee);
679
+ if (!actionName) {
680
+ return;
681
+ }
682
+ const resourceFactory = getUniqueApiResourceCallSource(callee.object);
683
+ if (resourceFactory) {
684
+ const rawResourceName = (0, import_static_values.resolveRunJsStaticString)(
685
+ (_c = resourceFactory.args) == null ? void 0 : _c[0],
686
+ source,
687
+ stringBindings,
688
+ identifierBindings
689
+ );
690
+ const dataSourceKey = (0, import_request_config.getRunJsApiResourceCallDataSourceKey)(
691
+ resourceFactory.args,
692
+ source,
693
+ stringBindings,
694
+ staticFilterValueBindings,
695
+ identifierBindings
696
+ ) ?? defaultDataSourceKey;
697
+ const resourceName = resolveApiResourceCollectionName(rawResourceName, dataSourceKey);
698
+ addInvalidAction({
699
+ actionName,
700
+ capability: resourceName ? `${resourceFactory.calleeSource}('${resourceName}').${actionName}` : `${resourceFactory.calleeSource}(...).${actionName}`,
701
+ collectionName: resourceName,
702
+ dataSourceKey,
703
+ index: resourceFactory.index
704
+ });
705
+ return;
706
+ }
707
+ const resourceHandleAlias = (0, import_ctx_api.getMaybeCtxApiResourceHandleAliasFromAst)(
708
+ callee.object,
709
+ ctxApiResourceAliases.handles,
710
+ identifierBindings
711
+ );
712
+ if (resourceHandleAlias) {
713
+ const dataSourceKey = resourceHandleAlias.dataSourceKey ?? defaultDataSourceKey;
714
+ const collectionName = resolveApiResourceCollectionName(resourceHandleAlias.resourceName, dataSourceKey);
715
+ addInvalidAction({
716
+ actionName,
717
+ capability: (0, import_source.getAstSource)(callee, source),
718
+ collectionName,
719
+ dataSourceKey,
720
+ index: typeof callee.start === "number" ? callee.start : node.start || 0
721
+ });
722
+ }
723
+ };
724
+ const collectRequestEndpointAction = (node) => {
725
+ const requestCapability = getRunJsCtxRequestCallCapabilityFromAst(
726
+ node,
727
+ ctxMethodAliases,
728
+ ctxApiAliases,
729
+ identifierBindings,
730
+ source
731
+ );
732
+ if (!requestCapability) {
733
+ return;
734
+ }
735
+ const dataSourceKey = (0, import_request_config.getRunJsStaticRequestDataSourceKeyFromAst)(
736
+ node,
737
+ source,
738
+ stringBindings,
739
+ staticFilterValueBindings,
740
+ identifierBindings
741
+ ) ?? defaultDataSourceKey;
742
+ const endpoint = getRunJsStaticRequestEndpointFromAst(
743
+ node,
744
+ source,
745
+ stringBindings,
746
+ staticFilterValueBindings,
747
+ identifierBindings
748
+ );
749
+ if (endpoint) {
750
+ const parsed = parseRunJsResourceEndpoint(endpoint, context, dataSourceKey);
751
+ if (parsed) {
752
+ addInvalidAction({
753
+ actionName: parsed.actionName,
754
+ capability: requestCapability,
755
+ collectionName: parsed.collectionName,
756
+ dataSourceKey,
757
+ endpoint: parsed.endpoint,
758
+ index: node.start || 0,
759
+ strictCollectionEndpoint: parsed.explicitCollectionPrefix
760
+ });
761
+ }
762
+ }
763
+ const requestResourceAction = getRunJsStaticRequestResourceActionFromAst(node, dataSourceKey);
764
+ if (!requestResourceAction) {
765
+ return;
766
+ }
767
+ addInvalidAction({
768
+ actionName: requestResourceAction.actionName,
769
+ capability: requestCapability,
770
+ collectionName: requestResourceAction.collectionName,
771
+ dataSourceKey,
772
+ index: node.start || 0
773
+ });
774
+ };
775
+ const collectRunjsEndpointAction = (node, method) => {
776
+ var _a;
777
+ if (method.method !== "runjs") {
778
+ return;
779
+ }
780
+ const endpoint = resolveStaticStringArg((_a = node.arguments) == null ? void 0 : _a[0]);
781
+ if (!endpoint) {
782
+ return;
783
+ }
784
+ const parsed = parseRunJsResourceEndpoint(endpoint, context, defaultDataSourceKey);
785
+ if (!parsed) {
786
+ return;
787
+ }
788
+ addInvalidAction({
789
+ actionName: parsed.actionName,
790
+ capability: method.capability,
791
+ collectionName: parsed.collectionName,
792
+ dataSourceKey: defaultDataSourceKey,
793
+ endpoint: parsed.endpoint,
794
+ index: node.start || 0,
795
+ strictCollectionEndpoint: parsed.explicitCollectionPrefix
796
+ });
797
+ };
798
+ (0, import_walk.walkAstAncestor)(ast, {
799
+ AssignmentExpression(node, ancestors) {
800
+ var _a, _b, _c, _d;
801
+ if (!(0, import_static_values.isAstCtxApiAliasAssignmentOperator)(node.operator)) {
802
+ return;
803
+ }
804
+ if (((_a = node.left) == null ? void 0 : _a.type) === "Identifier") {
805
+ getApiResourceActionSourcesFromAst(node.right).forEach(
806
+ (actionSource) => addActionAlias(node.left.name, actionSource, node, ancestors)
807
+ );
808
+ }
809
+ if (node.operator === "=" && ((_b = node.left) == null ? void 0 : _b.type) === "ObjectPattern") {
810
+ collectApiResourceActionPatternAliases(node.left, node.right, ancestors);
811
+ }
812
+ const alwaysRuns = (0, import_bindings.isAstAlwaysExecutedInCurrentExecutionScope)(ancestors);
813
+ const executionScope = (0, import_bindings.getAstExecutionScopeRange)(ancestors, source.length);
814
+ if (((_c = node.left) == null ? void 0 : _c.type) === "Identifier") {
815
+ events.push({
816
+ type: "aliasBind",
817
+ aliasName: node.left.name,
818
+ alwaysRuns,
819
+ end: typeof node.end === "number" ? node.end : node.start || 0,
820
+ executionScope,
821
+ index: node.start || 0,
822
+ sourceNode: node.right
823
+ });
824
+ return;
825
+ }
826
+ if (((_d = node.left) == null ? void 0 : _d.type) === "ObjectPattern" && (0, import_static_values.isUnshadowedCtxIdentifier)(node.right, identifierBindings)) {
827
+ (0, import_static_values.collectAstObjectPatternAliases)(node.left, (aliasName, member, aliasNode) => {
828
+ if (member !== "resource") {
829
+ return;
830
+ }
831
+ events.push({
832
+ type: "ctxResourceAliasBind",
833
+ aliasName,
834
+ alwaysRuns,
835
+ end: typeof (aliasNode == null ? void 0 : aliasNode.end) === "number" ? aliasNode.end : node.end || node.start || 0,
836
+ executionScope,
837
+ index: typeof (aliasNode == null ? void 0 : aliasNode.start) === "number" ? aliasNode.start : node.start || 0
838
+ });
839
+ });
840
+ }
841
+ },
842
+ CallExpression(node, ancestors) {
843
+ var _a;
844
+ const executionScope = (0, import_bindings.getAstExecutionScopeRange)(ancestors, source.length);
845
+ const alwaysRuns = (0, import_bindings.isAstAlwaysExecutedInCurrentExecutionScope)(ancestors);
846
+ const ctxMethod = (0, import_static_values.resolveCtxMethodCall)(node, ctxMethodAliases, identifierBindings);
847
+ if (ctxMethod) {
848
+ if (ctxMethod.method === "initResource") {
849
+ const resolved = ((_a = node.arguments) == null ? void 0 : _a[0]) ? (0, import_static_values.resolveAstResourceTypeExpression)(node.arguments[0], source, stringBindings, identifierBindings) : void 0;
850
+ events.push({
851
+ type: "initResource",
852
+ alwaysRuns,
853
+ end: typeof node.end === "number" ? node.end : node.start || 0,
854
+ executionScope,
855
+ index: node.start || 0,
856
+ resourceType: (resolved == null ? void 0 : resolved.status) === "resolved" && import_constants.INIT_RESOURCE_CLASS_NAMES.has(resolved.value) ? resolved.value : "unknown"
857
+ });
858
+ }
859
+ collectRunjsEndpointAction(node, ctxMethod);
860
+ }
861
+ getApiResourceActionSourcesFromAst(node.callee).forEach((apiResourceAction) => {
862
+ addInvalidAction({
863
+ actionName: apiResourceAction.actionName,
864
+ capability: apiResourceAction.capability,
865
+ collectionName: apiResourceAction.collectionName,
866
+ dataSourceKey: apiResourceAction.dataSourceKey,
867
+ index: node.start || 0
868
+ });
869
+ });
870
+ collectApiResourceActions(node);
871
+ collectRequestEndpointAction(node);
872
+ if (!getResourceCallTarget(node, executionScope)) {
873
+ return;
874
+ }
875
+ events.push({
876
+ type: "resourceCall",
877
+ alwaysRuns,
878
+ end: typeof node.end === "number" ? node.end : node.start || 0,
879
+ executionScope,
880
+ index: node.start || 0,
881
+ node
882
+ });
883
+ },
884
+ VariableDeclarator(node, ancestors) {
885
+ var _a, _b, _c;
886
+ const alwaysRuns = (0, import_bindings.isAstAlwaysExecutedInCurrentExecutionScope)(ancestors);
887
+ const executionScope = (0, import_bindings.getAstExecutionScopeRange)(ancestors, source.length);
888
+ if (((_a = node.id) == null ? void 0 : _a.type) === "Identifier") {
889
+ const actionSources = getApiResourceActionSourcesFromAst(node.init);
890
+ if (actionSources.length) {
891
+ const declaration = (0, import_bindings.findAstAncestor)(ancestors, "VariableDeclaration");
892
+ actionSources.forEach(
893
+ (actionSource) => addActionAlias(node.id.name, actionSource, node, ancestors, (declaration == null ? void 0 : declaration.kind) === "var")
894
+ );
895
+ }
896
+ events.push({
897
+ type: "aliasBind",
898
+ aliasName: node.id.name,
899
+ alwaysRuns,
900
+ end: typeof node.end === "number" ? node.end : node.start || 0,
901
+ executionScope,
902
+ index: node.start || 0,
903
+ sourceNode: node.init
904
+ });
905
+ return;
906
+ }
907
+ if (((_b = node.id) == null ? void 0 : _b.type) === "ObjectPattern" && (0, import_static_values.isUnshadowedCtxIdentifier)(node.init, identifierBindings)) {
908
+ (0, import_static_values.collectAstObjectPatternAliases)(node.id, (aliasName, member, aliasNode) => {
909
+ if (member !== "resource") {
910
+ return;
911
+ }
912
+ events.push({
913
+ type: "ctxResourceAliasBind",
914
+ aliasName,
915
+ alwaysRuns,
916
+ end: typeof (aliasNode == null ? void 0 : aliasNode.end) === "number" ? aliasNode.end : node.end || node.start || 0,
917
+ executionScope,
918
+ index: typeof (aliasNode == null ? void 0 : aliasNode.start) === "number" ? aliasNode.start : node.start || 0
919
+ });
920
+ });
921
+ }
922
+ if (((_c = node.id) == null ? void 0 : _c.type) === "ObjectPattern") {
923
+ const declaration = (0, import_bindings.findAstAncestor)(ancestors, "VariableDeclaration");
924
+ collectApiResourceActionPatternAliases(node.id, node.init, ancestors, (declaration == null ? void 0 : declaration.kind) === "var");
925
+ }
926
+ }
927
+ });
928
+ ctxResourceStates.clear();
929
+ aliasStates.clear();
930
+ const actionScopes = Array.from(
931
+ new Map(events.map((event) => [scopeKey(event.executionScope), event.executionScope])).values()
932
+ );
933
+ const actionScopeDepth = (scope) => actionScopes.filter(
934
+ (candidate) => candidate.start < scope.start && candidate.end >= scope.end && !(0, import_bindings.isSameAstRange)(candidate, scope)
935
+ ).length;
936
+ events.sort(
937
+ (left, right) => actionScopeDepth(left.executionScope) - actionScopeDepth(right.executionScope) || left.executionScope.start - right.executionScope.start || left.index - right.index || left.end - right.end
938
+ ).forEach((event) => {
939
+ var _a, _b, _c, _d, _e;
940
+ if (event.type === "initResource") {
941
+ if (!event.alwaysRuns) {
942
+ return;
943
+ }
944
+ setCtxState(event.executionScope, {
945
+ capability: "ctx.resource",
946
+ dataSourceKey: defaultDataSourceKey,
947
+ resourceType: event.resourceType
948
+ });
949
+ return;
950
+ }
951
+ if (event.type === "aliasBind") {
952
+ if (!event.alwaysRuns) {
953
+ return;
954
+ }
955
+ const alias = findDeclaredAlias(event.aliasName, event.index);
956
+ const state = resolveExpressionState(event.sourceNode, event.executionScope);
957
+ if (alias && state) {
958
+ setAliasState(alias, state);
959
+ }
960
+ return;
961
+ }
962
+ if (event.type === "ctxResourceAliasBind") {
963
+ if (!event.alwaysRuns) {
964
+ return;
965
+ }
966
+ const alias = findDeclaredAlias(event.aliasName, event.index);
967
+ if (alias) {
968
+ setAliasState(alias, getCtxState(event.executionScope));
969
+ }
970
+ return;
971
+ }
972
+ const target = getResourceCallTarget(event.node, event.executionScope);
973
+ if (!target) {
974
+ return;
975
+ }
976
+ if (target.method === "setDataSourceKey" || target.method === "setResourceName") {
977
+ if (!event.alwaysRuns) {
978
+ return;
979
+ }
980
+ target.updateState(applyStaticResourceStateMethod(target.state, target.method, event.node));
981
+ return;
982
+ }
983
+ if (target.method !== "runAction" && target.method !== "setRefreshAction") {
984
+ return;
985
+ }
986
+ const actionName = resolveStaticStringArg((_a = event.node.arguments) == null ? void 0 : _a[0]);
987
+ addInvalidAction({
988
+ actionName,
989
+ capability: target.capability,
990
+ collectionName: target.state.collectionName,
991
+ dataSourceKey: target.state.dataSourceKey,
992
+ index: typeof ((_c = (_b = event.node.arguments) == null ? void 0 : _b[0]) == null ? void 0 : _c.start) === "number" ? event.node.arguments[0].start : typeof ((_e = (_d = event.node.callee) == null ? void 0 : _d.property) == null ? void 0 : _e.start) === "number" ? event.node.callee.property.start : event.index,
993
+ resourceType: target.state.resourceType,
994
+ strictCollectionEndpoint: true
995
+ });
996
+ });
997
+ return entries;
998
+ }
999
+ function validateRunJsCollectionResourceAction(input) {
1000
+ const actionName = (0, import_surface.normalizeText)(input.actionName);
1001
+ if (!actionName || input.resourceType === "SQLResource") {
1002
+ return void 0;
1003
+ }
1004
+ const hasUnknownDataSource = input.dataSourceKey === "";
1005
+ const actionPolicy = getRunJsCollectionActionPolicy(
1006
+ input.context,
1007
+ hasUnknownDataSource ? void 0 : input.dataSourceKey || getRunJsDefaultDataSourceKey(input.context),
1008
+ input.collectionName
1009
+ );
1010
+ if (!actionPolicy.collectionResolved && !input.strictCollectionEndpoint && !hasUnknownDataSource) {
1011
+ return void 0;
1012
+ }
1013
+ if (!import_constants.RUNJS_COLLECTION_RESOURCE_ACTIONS.has(actionName)) {
1014
+ return {
1015
+ actionName,
1016
+ allowedActions: actionPolicy.allowedActions,
1017
+ invalidReason: actionName === "refresh" ? "refresh-is-flow-resource-method" : "unknown-collection-action"
1018
+ };
1019
+ }
1020
+ if (!hasUnknownDataSource && !actionPolicy.allowedActionSet.has(actionName)) {
1021
+ return {
1022
+ actionName,
1023
+ allowedActions: actionPolicy.allowedActions,
1024
+ invalidReason: "collection-action-unavailable"
1025
+ };
1026
+ }
1027
+ return void 0;
1028
+ }
1029
+ function getRunJsDefaultDataSourceKey(context) {
1030
+ return (0, import_surface.normalizeText)(context.currentDataSourceKey || context.hostDataSourceKey) || "main";
1031
+ }
1032
+ function getRunJsCollectionActionPolicy(context, dataSourceKey, collectionName) {
1033
+ let collection;
1034
+ if (context.getCollection && collectionName && dataSourceKey) {
1035
+ collection = context.getCollection(dataSourceKey || getRunJsDefaultDataSourceKey(context), collectionName);
1036
+ }
1037
+ const availableActions = getRunJsCollectionActionOptionList(collection, "availableActions");
1038
+ const unavailableActions = getRunJsCollectionActionOptionList(collection, "unavailableActions");
1039
+ const allowedActionSet = new Set(import_constants.RUNJS_COLLECTION_RESOURCE_ACTIONS);
1040
+ if (availableActions == null ? void 0 : availableActions.length) {
1041
+ [...allowedActionSet].forEach((actionName) => {
1042
+ if (!availableActions.some(
1043
+ (capabilityName) => isRunJsCollectionActionCoveredByCapability(actionName, capabilityName)
1044
+ )) {
1045
+ allowedActionSet.delete(actionName);
1046
+ }
1047
+ });
1048
+ }
1049
+ if (unavailableActions == null ? void 0 : unavailableActions.length) {
1050
+ [...allowedActionSet].forEach((actionName) => {
1051
+ if (unavailableActions.some(
1052
+ (capabilityName) => isRunJsCollectionActionCoveredByCapability(actionName, capabilityName)
1053
+ )) {
1054
+ allowedActionSet.delete(actionName);
1055
+ }
1056
+ });
1057
+ }
1058
+ const allowedActions = [...allowedActionSet].sort((left, right) => left.localeCompare(right));
1059
+ return {
1060
+ allowedActionSet,
1061
+ allowedActions,
1062
+ collectionResolved: Boolean(collection)
1063
+ };
1064
+ }
1065
+ function getRunJsCollectionActionOptionList(collection, key) {
1066
+ var _a;
1067
+ const directValue = collection == null ? void 0 : collection[key];
1068
+ const optionsValue = (_a = collection == null ? void 0 : collection.options) == null ? void 0 : _a[key];
1069
+ const value = typeof directValue === "function" ? directValue.call(collection) : directValue || optionsValue;
1070
+ return Array.isArray(value) ? value.map((item) => (0, import_surface.normalizeText)(item)).filter(Boolean) : void 0;
1071
+ }
1072
+ function isRunJsCollectionActionCoveredByCapability(actionName, capabilityName) {
1073
+ var _a;
1074
+ if (actionName === capabilityName) {
1075
+ return true;
1076
+ }
1077
+ return ((_a = import_constants.RUNJS_COLLECTION_RESOURCE_ACTION_ALIASES.get(capabilityName)) == null ? void 0 : _a.includes(actionName)) || false;
1078
+ }
1079
+ function getRunJsCtxRequestCallCapabilityFromAst(node, ctxMethodAliases, ctxApiAliases, identifierBindings, source) {
1080
+ const ctxMethod = (0, import_static_values.resolveCtxMethodCall)(node, ctxMethodAliases, identifierBindings);
1081
+ if ((ctxMethod == null ? void 0 : ctxMethod.method) === "request") {
1082
+ return ctxMethod.capability;
1083
+ }
1084
+ const callee = (0, import_bindings.unwrapAstChainExpression)(node.callee);
1085
+ const capability = (0, import_ctx_api.getCtxApiCapabilityFromAst)(callee, ctxApiAliases, identifierBindings) || (0, import_ctx_api.getMaybeCtxApiCapabilityFromAst)(callee, ctxApiAliases, identifierBindings);
1086
+ return capability === "ctx.api.request" ? (0, import_source.getAstSource)(callee, source) || "ctx.api.request" : "";
1087
+ }
1088
+ function getRunJsStaticRequestEndpointFromAst(node, source, stringBindings, staticFilterValueBindings, identifierBindings) {
1089
+ var _a;
1090
+ const firstArg = (_a = node.arguments) == null ? void 0 : _a[0];
1091
+ const firstArgUrl = (0, import_static_values.resolveRunJsStaticString)(firstArg, source, stringBindings, identifierBindings);
1092
+ if (firstArgUrl) {
1093
+ return firstArgUrl;
1094
+ }
1095
+ const objectArg = (0, import_request_config.getRunJsStaticRequestConfigObjectFromAst)(node, identifierBindings, staticFilterValueBindings);
1096
+ if (!objectArg) {
1097
+ return "";
1098
+ }
1099
+ const urlProperty = (0, import_static_values.getRunJsObjectProperty)(objectArg, ["url"], identifierBindings, staticFilterValueBindings);
1100
+ return (0, import_static_values.resolveRunJsStaticString)(urlProperty == null ? void 0 : urlProperty.value, source, stringBindings, identifierBindings) || "";
1101
+ }
1102
+ function parseRunJsResourceEndpoint(value, context, dataSourceKey) {
1103
+ const endpoint = (0, import_surface.normalizeText)(value);
1104
+ if (!endpoint || /^(?:https?:)?\/\//i.test(endpoint)) {
1105
+ return void 0;
1106
+ }
1107
+ const resourceUrl = endpoint.replace(/^\/api\//i, "").replace(/^\//, "");
1108
+ const match = resourceUrl.match(new RegExp(`^(.+?):(${import_constants.RUNJS_RESOURCE_ENDPOINT_ACTION_PATTERN})(?:$|[/?#])`));
1109
+ if (!match) {
1110
+ return void 0;
1111
+ }
1112
+ const resourcePathSegments = (0, import_surface.normalizeText)(match[1]).split("/").filter(Boolean);
1113
+ const resourceName = (0, import_surface.normalizeText)(resourcePathSegments[resourcePathSegments.length - 1]);
1114
+ const actionName = (0, import_surface.normalizeText)(match[2]);
1115
+ const explicitCollectionPrefix = resourceName === "collection" || resourceName === "resource";
1116
+ const collectionName = explicitCollectionPrefix ? void 0 : resolveRunJsCollectionNameFromEndpointResourcePath(resourcePathSegments, context, dataSourceKey) || resourceName;
1117
+ return {
1118
+ actionName,
1119
+ collectionName,
1120
+ endpoint,
1121
+ explicitCollectionPrefix
1122
+ };
1123
+ }
1124
+ function resolveRunJsCollectionNameFromEndpointResourcePath(resourcePathSegments, context, dataSourceKey) {
1125
+ if (!context.getCollection || resourcePathSegments.length < 3) {
1126
+ return "";
1127
+ }
1128
+ const sourceCollectionName = (0, import_surface.normalizeText)(resourcePathSegments[0]);
1129
+ const associationFieldName = (0, import_surface.normalizeText)(resourcePathSegments[resourcePathSegments.length - 1]);
1130
+ if (!sourceCollectionName || !associationFieldName) {
1131
+ return "";
1132
+ }
1133
+ const sourceCollection = context.getCollection(
1134
+ dataSourceKey || getRunJsDefaultDataSourceKey(context),
1135
+ sourceCollectionName
1136
+ );
1137
+ const associationField = (0, import_service_helpers.resolveFieldFromCollection)(sourceCollection, associationFieldName);
1138
+ const targetCollection = associationField ? (0, import_service_helpers.resolveFieldTargetCollection)(
1139
+ associationField,
1140
+ dataSourceKey || getRunJsDefaultDataSourceKey(context),
1141
+ context.getCollection
1142
+ ) : null;
1143
+ return (0, import_surface.normalizeText)((0, import_service_helpers.getCollectionName)(targetCollection));
1144
+ }
1145
+ function resolveRunJsCollectionNameFromDottedResourceName(resourceName, context, dataSourceKey) {
1146
+ const parts = (0, import_surface.normalizeText)(resourceName).split(".").filter(Boolean);
1147
+ if (!context.getCollection || !dataSourceKey || parts.length < 2) {
1148
+ return "";
1149
+ }
1150
+ let currentDataSourceKey = dataSourceKey;
1151
+ let currentCollection = context.getCollection(currentDataSourceKey, parts[0]);
1152
+ for (let index = 1; index < parts.length; index += 1) {
1153
+ const associationFieldName = parts[index];
1154
+ if (!currentCollection || !associationFieldName) {
1155
+ return "";
1156
+ }
1157
+ const associationField = (0, import_service_helpers.resolveFieldFromCollection)(currentCollection, associationFieldName);
1158
+ const targetCollection = associationField ? (0, import_service_helpers.resolveFieldTargetCollection)(
1159
+ associationField,
1160
+ (currentCollection == null ? void 0 : currentCollection.dataSourceKey) || currentDataSourceKey,
1161
+ context.getCollection
1162
+ ) : null;
1163
+ if (!targetCollection) {
1164
+ return "";
1165
+ }
1166
+ currentCollection = targetCollection;
1167
+ currentDataSourceKey = (targetCollection == null ? void 0 : targetCollection.dataSourceKey) || currentDataSourceKey;
1168
+ }
1169
+ return (0, import_surface.normalizeText)((0, import_service_helpers.getCollectionName)(currentCollection));
1170
+ }
1171
+ function getMaybeAstFlowResourceSourceFromAst(node, aliases, source, identifierBindings, ctxMethodAliases, stringBindings) {
1172
+ return selectAstFlowResourceSource(
1173
+ collectPossibleAstFlowResourceSourcesFromAst(
1174
+ node,
1175
+ aliases,
1176
+ source,
1177
+ identifierBindings,
1178
+ ctxMethodAliases,
1179
+ stringBindings
1180
+ )
1181
+ );
1182
+ }
1183
+ function collectPossibleAstFlowResourceSourcesFromAst(node, aliases, source, identifierBindings, ctxMethodAliases, stringBindings) {
1184
+ const direct = getDirectAstFlowResourceSourceFromAst(
1185
+ node,
1186
+ aliases,
1187
+ source,
1188
+ identifierBindings,
1189
+ ctxMethodAliases,
1190
+ stringBindings
1191
+ );
1192
+ if (direct) {
1193
+ return [direct];
1194
+ }
1195
+ const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
1196
+ if (!unwrapped) {
1197
+ return [];
1198
+ }
1199
+ if (unwrapped.type === "ConditionalExpression") {
1200
+ return [
1201
+ ...collectPossibleAstFlowResourceSourcesFromAst(
1202
+ unwrapped.consequent,
1203
+ aliases,
1204
+ source,
1205
+ identifierBindings,
1206
+ ctxMethodAliases,
1207
+ stringBindings
1208
+ ),
1209
+ ...collectPossibleAstFlowResourceSourcesFromAst(
1210
+ unwrapped.alternate,
1211
+ aliases,
1212
+ source,
1213
+ identifierBindings,
1214
+ ctxMethodAliases,
1215
+ stringBindings
1216
+ )
1217
+ ];
1218
+ }
1219
+ if (unwrapped.type === "LogicalExpression") {
1220
+ return [
1221
+ ...collectPossibleAstFlowResourceSourcesFromAst(
1222
+ unwrapped.left,
1223
+ aliases,
1224
+ source,
1225
+ identifierBindings,
1226
+ ctxMethodAliases,
1227
+ stringBindings
1228
+ ),
1229
+ ...collectPossibleAstFlowResourceSourcesFromAst(
1230
+ unwrapped.right,
1231
+ aliases,
1232
+ source,
1233
+ identifierBindings,
1234
+ ctxMethodAliases,
1235
+ stringBindings
1236
+ )
1237
+ ];
1238
+ }
1239
+ if (unwrapped.type === "SequenceExpression") {
1240
+ const expressions = unwrapped.expressions || [];
1241
+ return collectPossibleAstFlowResourceSourcesFromAst(
1242
+ expressions[expressions.length - 1],
1243
+ aliases,
1244
+ source,
1245
+ identifierBindings,
1246
+ ctxMethodAliases,
1247
+ stringBindings
1248
+ );
1249
+ }
1250
+ if (unwrapped.type === "AssignmentExpression" && (0, import_static_values.isAstCtxApiAliasAssignmentOperator)(unwrapped.operator)) {
1251
+ return collectPossibleAstFlowResourceSourcesFromAst(
1252
+ unwrapped.right,
1253
+ aliases,
1254
+ source,
1255
+ identifierBindings,
1256
+ ctxMethodAliases,
1257
+ stringBindings
1258
+ );
1259
+ }
1260
+ return [];
1261
+ }
1262
+ function getDirectAstFlowResourceSourceFromAst(node, aliases, source, identifierBindings, ctxMethodAliases, stringBindings) {
1263
+ const unwrapped = (0, import_bindings.unwrapAstChainExpression)(node);
1264
+ if (!unwrapped) {
1265
+ return void 0;
1266
+ }
1267
+ if (unwrapped.type === "Identifier") {
1268
+ const alias = (0, import_static_values.resolveAstAliasBinding)(unwrapped.name, unwrapped.start || 0, aliases, identifierBindings);
1269
+ return alias ? {
1270
+ capability: alias.capability,
1271
+ index: typeof unwrapped.start === "number" ? unwrapped.start : alias.start,
1272
+ resourceType: alias.resourceType
1273
+ } : void 0;
1274
+ }
1275
+ if (isAstCtxResourceMember(unwrapped, identifierBindings)) {
1276
+ return {
1277
+ capability: "ctx.resource",
1278
+ index: typeof unwrapped.start === "number" ? unwrapped.start : 0,
1279
+ resourceType: "unknown"
1280
+ };
1281
+ }
1282
+ return getAstFlowResourceFactoryCallFromAst(unwrapped, ctxMethodAliases, source, stringBindings, identifierBindings);
1283
+ }
1284
+ function getAstFlowResourceFactoryCallFromAst(node, ctxMethodAliases, source, stringBindings, identifierBindings) {
1285
+ var _a;
1286
+ const call = (0, import_bindings.unwrapAstChainExpression)(node);
1287
+ if (!call || call.type !== "CallExpression") {
1288
+ return void 0;
1289
+ }
1290
+ const method = (0, import_static_values.resolveCtxMethodCall)(call, ctxMethodAliases, identifierBindings);
1291
+ if (!method || method.method !== "makeResource" && method.method !== "initResource") {
1292
+ return void 0;
1293
+ }
1294
+ const firstArg = (_a = call.arguments) == null ? void 0 : _a[0];
1295
+ if (!firstArg) {
1296
+ return void 0;
1297
+ }
1298
+ const resolved = (0, import_static_values.resolveAstResourceTypeExpression)(firstArg, source, stringBindings, identifierBindings);
1299
+ if (resolved.status !== "resolved") {
1300
+ return void 0;
1301
+ }
1302
+ const allowedResourceTypes = method.method === "initResource" ? import_constants.INIT_RESOURCE_CLASS_NAMES : import_constants.FLOW_RESOURCE_CLASS_NAMES;
1303
+ if (!allowedResourceTypes.has(resolved.value) || !isKnownFlowResourceInstanceType(resolved.value)) {
1304
+ return void 0;
1305
+ }
1306
+ return {
1307
+ capability: method.capability,
1308
+ index: typeof call.start === "number" ? call.start : 0,
1309
+ resourceType: resolved.value
1310
+ };
1311
+ }
1312
+ function isAstCtxResourceMember(node, identifierBindings) {
1313
+ const member = (0, import_bindings.unwrapAstChainExpression)(node);
1314
+ return (member == null ? void 0 : member.type) === "MemberExpression" && (0, import_static_values.getAstStaticPropertyName)(member) === "resource" && (0, import_static_values.isUnshadowedCtxIdentifier)(member.object, identifierBindings);
1315
+ }
1316
+ function collectAstSharedCtxResourceCallsInFunctions(ast, source, ctxMethodAliases, identifierBindings) {
1317
+ const entries = [];
1318
+ const seen = /* @__PURE__ */ new Set();
1319
+ const addEntry = (capability, index, ancestors) => {
1320
+ const functionNode = getNearestAstFunctionAncestor(ancestors);
1321
+ if (!functionNode) {
1322
+ return;
1323
+ }
1324
+ const functionName = getAstFunctionDisplayName(functionNode, ancestors);
1325
+ const key = `${capability}:${functionNode.start || 0}:${functionNode.end || source.length}`;
1326
+ if (seen.has(key)) {
1327
+ return;
1328
+ }
1329
+ seen.add(key);
1330
+ entries.push({
1331
+ capability,
1332
+ functionName,
1333
+ index
1334
+ });
1335
+ };
1336
+ (0, import_walk.walkAstAncestor)(ast, {
1337
+ CallExpression(node, ancestors) {
1338
+ const method = (0, import_static_values.resolveCtxMethodCall)(node, ctxMethodAliases, identifierBindings);
1339
+ if ((method == null ? void 0 : method.method) === "initResource") {
1340
+ addEntry(method.capability, node.start || 0, ancestors);
1341
+ }
1342
+ },
1343
+ MemberExpression(node, ancestors) {
1344
+ if (isAstCtxResourceMember(node, identifierBindings)) {
1345
+ addEntry("ctx.resource", node.start || 0, ancestors);
1346
+ }
1347
+ }
1348
+ });
1349
+ return entries.sort((left, right) => left.index - right.index);
1350
+ }
1351
+ function getNearestAstFunctionAncestor(ancestors) {
1352
+ for (let index = ancestors.length - 1; index >= 0; index -= 1) {
1353
+ const ancestor = ancestors[index];
1354
+ if ((0, import_bindings.isAstFunctionLike)(ancestor)) {
1355
+ return ancestor;
1356
+ }
1357
+ }
1358
+ return void 0;
1359
+ }
1360
+ function getAstFunctionDisplayName(functionNode, ancestors) {
1361
+ var _a, _b;
1362
+ if (((_a = functionNode == null ? void 0 : functionNode.id) == null ? void 0 : _a.type) === "Identifier") {
1363
+ return functionNode.id.name;
1364
+ }
1365
+ const functionIndex = ancestors.findIndex((ancestor) => ancestor === functionNode);
1366
+ const parent = functionIndex >= 0 ? ancestors[functionIndex - 1] : void 0;
1367
+ if ((parent == null ? void 0 : parent.type) === "VariableDeclarator" && ((_b = parent.id) == null ? void 0 : _b.type) === "Identifier") {
1368
+ return parent.id.name;
1369
+ }
1370
+ if ((parent == null ? void 0 : parent.type) === "Property") {
1371
+ const key = (0, import_static_values.getAstStaticPropertyName)(parent);
1372
+ if (key) {
1373
+ return key;
1374
+ }
1375
+ }
1376
+ return void 0;
1377
+ }
1378
+ function selectAstFlowResourceSource(sources) {
1379
+ if (!sources.length) {
1380
+ return void 0;
1381
+ }
1382
+ const resourceTypes = [...new Set(sources.map((entry) => entry.resourceType))];
1383
+ if (resourceTypes.length === 1) {
1384
+ return sources[0];
1385
+ }
1386
+ return {
1387
+ capability: sources.map((entry) => entry.capability).join("|"),
1388
+ index: Math.min(...sources.map((entry) => entry.index)),
1389
+ resourceType: "unknown"
1390
+ };
1391
+ }
1392
+ function getFlowResourceAllowedMethods(resourceType) {
1393
+ if (!resourceType || resourceType === "unknown") {
1394
+ return import_constants.UNKNOWN_FLOW_RESOURCE_METHODS;
1395
+ }
1396
+ return import_constants.FLOW_RESOURCE_METHODS_BY_TYPE[resourceType] || import_constants.UNKNOWN_FLOW_RESOURCE_METHODS;
1397
+ }
1398
+ function getSuggestedFlowResourceMethod(method) {
1399
+ const exactSuggestion = import_constants.FLOW_RESOURCE_METHOD_SUGGESTIONS.get(method);
1400
+ if (exactSuggestion) {
1401
+ return exactSuggestion;
1402
+ }
1403
+ if (method.endsWith("s")) {
1404
+ const singular = method.slice(0, -1);
1405
+ if (import_constants.UNKNOWN_FLOW_RESOURCE_METHODS.has(singular)) {
1406
+ return singular;
1407
+ }
1408
+ }
1409
+ return void 0;
1410
+ }
1411
+ function isKnownFlowResourceInstanceType(value) {
1412
+ return value in import_constants.FLOW_RESOURCE_METHODS_BY_TYPE;
1413
+ }
1414
+ // Annotate the CommonJS export names for ESM import in node:
1415
+ 0 && (module.exports = {
1416
+ collectAstFlowResourceAliasesFromAst,
1417
+ collectAstInvalidFlowResourceMethodCall,
1418
+ collectAstInvalidResourceActionCalls,
1419
+ collectAstInvalidResourceTypeCall,
1420
+ collectAstSharedCtxResourceCallsInFunctions,
1421
+ collectPossibleAstFlowResourceSourcesFromAst,
1422
+ getAstFlowResourceFactoryCallFromAst,
1423
+ getDirectAstFlowResourceSourceFromAst,
1424
+ getMaybeAstFlowResourceSourceFromAst,
1425
+ getRunJsDefaultDataSourceKey,
1426
+ isAstCtxResourceMember
1427
+ });