@nocobase/plugin-flow-engine 2.1.0-beta.42 → 2.1.0-beta.44

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 (86) hide show
  1. package/dist/externalVersion.js +9 -9
  2. package/dist/node_modules/@ant-design/icons-svg/package.json +1 -1
  3. package/dist/node_modules/acorn/package.json +1 -1
  4. package/dist/node_modules/acorn-jsx/package.json +1 -1
  5. package/dist/node_modules/acorn-walk/package.json +1 -1
  6. package/dist/node_modules/ses/package.json +1 -1
  7. package/dist/node_modules/zod/package.json +1 -1
  8. package/dist/server/flow-surfaces/authoring-validation.js +160 -21
  9. package/dist/server/flow-surfaces/catalog.js +9 -5
  10. package/dist/server/flow-surfaces/chart-config.js +29 -6
  11. package/dist/server/flow-surfaces/contract-guard.js +39 -5
  12. package/dist/server/flow-surfaces/default-block-actions.js +2 -0
  13. package/dist/server/flow-surfaces/errors.d.ts +15 -0
  14. package/dist/server/flow-surfaces/errors.js +49 -3
  15. package/dist/server/flow-surfaces/filter-group.d.ts +7 -1
  16. package/dist/server/flow-surfaces/filter-group.js +175 -71
  17. package/dist/server/flow-surfaces/public-data-surface-default-filter.js +2 -1
  18. package/dist/server/flow-surfaces/runjs-authoring/ast/bindings.d.ts +66 -0
  19. package/dist/server/flow-surfaces/runjs-authoring/ast/bindings.js +661 -0
  20. package/dist/server/flow-surfaces/runjs-authoring/ast/execution.d.ts +20 -0
  21. package/dist/server/flow-surfaces/runjs-authoring/ast/execution.js +275 -0
  22. package/dist/server/flow-surfaces/runjs-authoring/ast/parser.d.ts +16 -0
  23. package/dist/server/flow-surfaces/runjs-authoring/ast/parser.js +130 -0
  24. package/dist/server/flow-surfaces/runjs-authoring/ast/react-values.d.ts +20 -0
  25. package/dist/server/flow-surfaces/runjs-authoring/ast/react-values.js +401 -0
  26. package/dist/server/flow-surfaces/runjs-authoring/ast/request-config.d.ts +21 -0
  27. package/dist/server/flow-surfaces/runjs-authoring/ast/request-config.js +199 -0
  28. package/dist/server/flow-surfaces/runjs-authoring/ast/source.d.ts +70 -0
  29. package/dist/server/flow-surfaces/runjs-authoring/ast/source.js +895 -0
  30. package/dist/server/flow-surfaces/runjs-authoring/ast/static-bindings.d.ts +23 -0
  31. package/dist/server/flow-surfaces/runjs-authoring/ast/static-bindings.js +618 -0
  32. package/dist/server/flow-surfaces/runjs-authoring/ast/static-values.d.ts +196 -0
  33. package/dist/server/flow-surfaces/runjs-authoring/ast/static-values.js +1777 -0
  34. package/dist/server/flow-surfaces/runjs-authoring/ast/walk.d.ts +10 -0
  35. package/dist/server/flow-surfaces/runjs-authoring/ast/walk.js +55 -0
  36. package/dist/server/flow-surfaces/runjs-authoring/collectors.d.ts +12 -0
  37. package/dist/server/flow-surfaces/runjs-authoring/collectors.js +589 -0
  38. package/dist/server/flow-surfaces/runjs-authoring/index.d.ts +2 -25
  39. package/dist/server/flow-surfaces/runjs-authoring/index.js +5 -11138
  40. package/dist/server/flow-surfaces/runjs-authoring/inspect.d.ts +13 -0
  41. package/dist/server/flow-surfaces/runjs-authoring/inspect.js +149 -0
  42. package/dist/server/flow-surfaces/runjs-authoring/internal-types.d.ts +333 -0
  43. package/dist/server/flow-surfaces/runjs-authoring/internal-types.js +36 -0
  44. package/dist/server/flow-surfaces/runjs-authoring/rules.js +2 -0
  45. package/dist/server/flow-surfaces/runjs-authoring/runtime/constants.d.ts +67 -0
  46. package/dist/server/flow-surfaces/runjs-authoring/runtime/constants.js +757 -0
  47. package/dist/server/flow-surfaces/runjs-authoring/runtime/errors.d.ts +22 -0
  48. package/dist/server/flow-surfaces/runjs-authoring/runtime/errors.js +91 -0
  49. package/dist/server/flow-surfaces/runjs-authoring/runtime/source-budget.d.ts +16 -0
  50. package/dist/server/flow-surfaces/runjs-authoring/runtime/source-budget.js +115 -0
  51. package/dist/server/flow-surfaces/runjs-authoring/runtime/surface.d.ts +19 -0
  52. package/dist/server/flow-surfaces/runjs-authoring/runtime/surface.js +140 -0
  53. package/dist/server/flow-surfaces/runjs-authoring/runtime/types.d.ts +91 -0
  54. package/dist/server/flow-surfaces/runjs-authoring/runtime/types.js +24 -0
  55. package/dist/server/flow-surfaces/runjs-authoring/scan/ctx-api.d.ts +138 -0
  56. package/dist/server/flow-surfaces/runjs-authoring/scan/ctx-api.js +1779 -0
  57. package/dist/server/flow-surfaces/runjs-authoring/scan/filter.d.ts +10 -0
  58. package/dist/server/flow-surfaces/runjs-authoring/scan/filter.js +1583 -0
  59. package/dist/server/flow-surfaces/runjs-authoring/scan/index.d.ts +195 -0
  60. package/dist/server/flow-surfaces/runjs-authoring/scan/index.js +463 -0
  61. package/dist/server/flow-surfaces/runjs-authoring/scan/react-render.d.ts +48 -0
  62. package/dist/server/flow-surfaces/runjs-authoring/scan/react-render.js +379 -0
  63. package/dist/server/flow-surfaces/runjs-authoring/scan/react.d.ts +26 -0
  64. package/dist/server/flow-surfaces/runjs-authoring/scan/react.js +1441 -0
  65. package/dist/server/flow-surfaces/runjs-authoring/scan/resource.d.ts +23 -0
  66. package/dist/server/flow-surfaces/runjs-authoring/scan/resource.js +1427 -0
  67. package/dist/server/flow-surfaces/runjs-authoring/scan/source-patterns.d.ts +91 -0
  68. package/dist/server/flow-surfaces/runjs-authoring/scan/source-patterns.js +889 -0
  69. package/dist/server/flow-surfaces/runjs-authoring/types.d.ts +1 -1
  70. package/dist/server/flow-surfaces/runjs-authoring/unknown-global-stop/index.d.ts +10 -0
  71. package/dist/server/flow-surfaces/runjs-authoring/unknown-global-stop/index.js +40 -0
  72. package/dist/server/flow-surfaces/runjs-authoring/validators/index.d.ts +12 -0
  73. package/dist/server/flow-surfaces/runjs-authoring/validators/index.js +887 -0
  74. package/dist/server/flow-surfaces/service-helpers.d.ts +29 -0
  75. package/dist/server/flow-surfaces/service-helpers.js +105 -0
  76. package/dist/server/flow-surfaces/service-utils.d.ts +15 -3
  77. package/dist/server/flow-surfaces/service-utils.js +5 -4
  78. package/dist/server/flow-surfaces/service.d.ts +4 -0
  79. package/dist/server/flow-surfaces/service.js +360 -30
  80. package/dist/server/flow-surfaces/types.d.ts +3 -0
  81. package/dist/server/repository.d.ts +12 -1
  82. package/dist/server/repository.js +195 -23
  83. package/dist/swagger/flow-surfaces.d.ts +175 -0
  84. package/dist/swagger/flow-surfaces.js +130 -51
  85. package/dist/swagger/index.d.ts +175 -0
  86. package/package.json +2 -2
@@ -0,0 +1,195 @@
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
+ import type { RunJsAuthoringContext } from '../internal-types';
10
+ export declare function scanJavaScriptSource(source: string, ast?: any, context?: RunJsAuthoringContext, modelUse?: string): {
11
+ source: string;
12
+ masked: string;
13
+ functionRanges: import("../internal-types").SourceRange[];
14
+ blockRanges: import("../internal-types").SourceRange[];
15
+ sourceBindings: import("../internal-types").SourceBinding[];
16
+ unknownBareGlobals: {
17
+ index: number;
18
+ name: string;
19
+ suggestedCapability?: string;
20
+ }[];
21
+ ctxRenderCalls: {
22
+ index: number;
23
+ match: string;
24
+ }[];
25
+ topLevelCtxRenderCalls: {
26
+ index: number;
27
+ match: string;
28
+ }[];
29
+ topLevelReachableCtxRenderCalls: {
30
+ capability: string;
31
+ index: number;
32
+ }[];
33
+ topLevelReturns: {
34
+ index: number;
35
+ match: string;
36
+ }[];
37
+ ctxRunjsCalls: {
38
+ index: number;
39
+ match: string;
40
+ }[];
41
+ nestedRunjsCalls: {
42
+ capability: string;
43
+ index: number;
44
+ }[];
45
+ invalidReactRuntimeBindings: import("../internal-types").InvalidReactRuntimeBinding[];
46
+ ctxRequestCalls: {
47
+ index: number;
48
+ match: string;
49
+ }[];
50
+ invalidApiResourceCalls: {
51
+ index: number;
52
+ match: string;
53
+ method: string;
54
+ }[];
55
+ invalidResourceActionCalls: {
56
+ actionName: string;
57
+ allowedActions?: string[];
58
+ capability: string;
59
+ collectionName?: string;
60
+ dataSourceKey?: string;
61
+ endpoint?: string;
62
+ index: number;
63
+ invalidReason: string;
64
+ resourceType?: import("../internal-types").FlowResourceInstanceType;
65
+ suggestedMethod?: string;
66
+ }[];
67
+ invalidResourceTypeCalls: {
68
+ capability: string;
69
+ expression?: string;
70
+ index: number;
71
+ resourceType?: string;
72
+ ruleId: string;
73
+ }[];
74
+ invalidFlowResourceListCalls: {
75
+ capability: string;
76
+ index: number;
77
+ }[];
78
+ invalidFlowResourceMethodCalls: {
79
+ capability: string;
80
+ index: number;
81
+ method: string;
82
+ resourceType?: import("../internal-types").FlowResourceInstanceType;
83
+ suggestedMethod?: string;
84
+ }[];
85
+ invalidResourceFilterCalls: {
86
+ availableFields?: string[];
87
+ capability: string;
88
+ collectionName?: string;
89
+ dataSourceKey?: string;
90
+ fieldInterface?: string;
91
+ fieldPath?: string;
92
+ fieldType?: string;
93
+ invalidShape?: string;
94
+ index: number;
95
+ invalidReason?: string;
96
+ invalidValue?: any;
97
+ message: string;
98
+ operator?: string;
99
+ repairExample?: Record<string, any>;
100
+ repairHint?: string;
101
+ resourceType?: import("../internal-types").FlowResourceInstanceType;
102
+ ruleId: string;
103
+ unsupportedKeys?: string[];
104
+ suggestedOperator?: string;
105
+ suggestedValue?: any;
106
+ examples?: Record<string, any>;
107
+ }[];
108
+ resourceCallsInReactHooks: import("../internal-types").ResourceCallInReactHook[];
109
+ topLevelReactHookCalls: {
110
+ hook: string;
111
+ index: number;
112
+ match: string;
113
+ }[];
114
+ unboundReactCreateElementCalls: {
115
+ index: number;
116
+ }[];
117
+ reactComponentFunctionCalls: {
118
+ index: number;
119
+ component: string;
120
+ capability: string;
121
+ }[];
122
+ reactAsyncComponentReferences: {
123
+ capability: string;
124
+ component: string;
125
+ index: number;
126
+ }[];
127
+ reactComponentCtxRenderCalls: {
128
+ capability: string;
129
+ component: string;
130
+ index: number;
131
+ }[];
132
+ sharedCtxResourceCallsInFunctions: import("../internal-types").SharedCtxResourceCallInFunction[];
133
+ ctxRenderComponentSignatureCalls: {
134
+ index: number;
135
+ component: string;
136
+ capability: string;
137
+ }[];
138
+ reactComponentPropReferences: {
139
+ index: number;
140
+ component: string;
141
+ capability: string;
142
+ prop: string;
143
+ }[];
144
+ directDomWrites: {
145
+ index: number;
146
+ match: string;
147
+ }[];
148
+ directDomAliases: {
149
+ alias: string;
150
+ index: number;
151
+ }[];
152
+ windowDocumentNavigatorUses: {
153
+ root: string;
154
+ member: string;
155
+ index: number;
156
+ }[];
157
+ windowDocumentNavigatorAliases: {
158
+ alias: string;
159
+ root: string;
160
+ index: number;
161
+ }[];
162
+ ctxAliases: {
163
+ alias: string;
164
+ index: number;
165
+ }[];
166
+ ctxLibMemberCaseMismatches: import("../internal-types").CtxLibMemberCaseMismatch[];
167
+ invalidCtxApiMemberAccesses: {
168
+ capability: string;
169
+ index: number;
170
+ match?: string;
171
+ matchIndex?: number;
172
+ member?: string;
173
+ ruleId: string;
174
+ }[];
175
+ invalidCtxNonFunctionCalls: {
176
+ capability: string;
177
+ index: number;
178
+ member: string;
179
+ ruleId: "runjs-ctx-member-not-callable";
180
+ }[];
181
+ invalidCtxLibMemberAccesses: import("../internal-types").InvalidCtxLibMemberAccess[];
182
+ forbiddenBareGlobals: {
183
+ name: string;
184
+ index: number;
185
+ }[];
186
+ ctxMemberAccesses: {
187
+ member: string;
188
+ index: number;
189
+ }[];
190
+ dynamicCtxAccesses: {
191
+ index: number;
192
+ match: string;
193
+ }[];
194
+ isTopLevelFunctionWrapper: boolean;
195
+ };
@@ -0,0 +1,463 @@
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 scan_exports = {};
28
+ __export(scan_exports, {
29
+ scanJavaScriptSource: () => scanJavaScriptSource
30
+ });
31
+ module.exports = __toCommonJS(scan_exports);
32
+ var import_source = require("../ast/source");
33
+ var import_walk = require("../ast/walk");
34
+ var import_bindings = require("../ast/bindings");
35
+ var import_source_patterns = require("./source-patterns");
36
+ var import_static_bindings = require("../ast/static-bindings");
37
+ var import_static_values = require("../ast/static-values");
38
+ var import_react = require("./react");
39
+ var import_react_render = require("./react-render");
40
+ var import_ctx_api = require("./ctx-api");
41
+ var import_resource = require("./resource");
42
+ var import_filter = require("./filter");
43
+ var import_constants = require("../runtime/constants");
44
+ function scanJavaScriptSource(source, ast, context = {}, modelUse = "") {
45
+ const masked = (0, import_source.maskJavaScriptSource)(source);
46
+ const functionRanges = (0, import_source.findFunctionRanges)(masked);
47
+ const blockRanges = (0, import_source.collectBraceRanges)(masked);
48
+ const staticBlockRanges = (0, import_source.collectStaticBlockRanges)(masked);
49
+ const sourceBindings = (0, import_bindings.collectSourceBindings)(masked, functionRanges, blockRanges, staticBlockRanges);
50
+ const stringLiteralBindings = (0, import_bindings.collectStringLiteralBindings)(source, masked, sourceBindings);
51
+ const astInspection = ast ? inspectRunJsAst(ast, source, stringLiteralBindings, context, modelUse) : void 0;
52
+ const ctxRenderCalls = (0, import_static_values.findUnboundCtxMatches)(masked, /\bctx\s*(?:\?\.|\.)\s*render\s*(?:\?\.)?\(/g, sourceBindings);
53
+ const topLevelCtxRenderCalls = ctxRenderCalls.filter((entry) => !(0, import_source.isInsideRanges)(entry.index, functionRanges));
54
+ const topLevelReachableCtxRenderCalls = astInspection ? (0, import_bindings.dedupeIndexedEntries)(astInspection.topLevelReachableCtxRenderCalls).sort(
55
+ (left, right) => left.index - right.index
56
+ ) : topLevelCtxRenderCalls.map((entry) => ({
57
+ capability: "ctx.render",
58
+ index: entry.index
59
+ }));
60
+ const topLevelReturns = (0, import_source.findMatches)(masked, /\breturn\b/g).filter(
61
+ (entry) => !(0, import_source.isInsideRanges)(entry.index, functionRanges)
62
+ );
63
+ const ctxRunjsCalls = (0, import_static_values.findUnboundCtxMatches)(masked, /\bctx\s*(?:\?\.|\.)\s*runjs\s*(?:\?\.)?\(/g, sourceBindings);
64
+ const ctxRequestCalls = (0, import_static_values.findUnboundCtxMatches)(
65
+ masked,
66
+ /\bctx\s*(?:\?\.|\.)\s*(?:api\s*(?:\?\.|\.)\s*)?request\s*(?:\?\.)?\(/g,
67
+ sourceBindings
68
+ );
69
+ const reactHookCalls = (0, import_source_patterns.collectReactHookCalls)(masked, sourceBindings);
70
+ const reactComponentAliases = (0, import_source_patterns.collectReactComponentAliases)(masked, sourceBindings);
71
+ const flowResourceAliases = (0, import_source_patterns.collectFlowResourceAliases)(masked, sourceBindings);
72
+ const directDomWrites = (0, import_source_patterns.collectDirectDomWrites)(source, masked, sourceBindings);
73
+ const directDomAliases = (0, import_source_patterns.collectDirectDomAliases)(masked, sourceBindings);
74
+ const windowDocumentNavigatorUses = (0, import_source_patterns.collectWindowDocumentNavigatorUses)(source, masked, sourceBindings);
75
+ const windowDocumentNavigatorAliases = (0, import_source_patterns.collectWindowDocumentNavigatorAliases)(masked, sourceBindings);
76
+ const ctxAliases = (0, import_source_patterns.collectCtxAliases)(masked, sourceBindings);
77
+ const forbiddenBareGlobals = (0, import_source_patterns.collectForbiddenBareGlobals)(masked, sourceBindings);
78
+ return {
79
+ source,
80
+ masked,
81
+ functionRanges,
82
+ blockRanges,
83
+ sourceBindings,
84
+ unknownBareGlobals: (astInspection == null ? void 0 : astInspection.unknownBareGlobals) || [],
85
+ ctxRenderCalls,
86
+ topLevelCtxRenderCalls,
87
+ topLevelReachableCtxRenderCalls,
88
+ topLevelReturns,
89
+ ctxRunjsCalls,
90
+ nestedRunjsCalls: (astInspection == null ? void 0 : astInspection.nestedRunjsCalls) || ctxRunjsCalls.map((entry) => ({
91
+ capability: "ctx.runjs",
92
+ index: entry.index
93
+ })),
94
+ invalidReactRuntimeBindings: (astInspection == null ? void 0 : astInspection.invalidReactRuntimeBindings) || [],
95
+ ctxRequestCalls,
96
+ invalidApiResourceCalls: (0, import_bindings.dedupeIndexedEntries)([
97
+ ...(0, import_source_patterns.collectInvalidApiResourceCalls)(source, masked, sourceBindings),
98
+ ...(astInspection == null ? void 0 : astInspection.invalidApiResourceCalls) || []
99
+ ]).sort((left, right) => left.index - right.index),
100
+ invalidResourceActionCalls: (astInspection == null ? void 0 : astInspection.invalidResourceActionCalls) || [],
101
+ invalidResourceTypeCalls: (astInspection == null ? void 0 : astInspection.invalidResourceTypeCalls) || (0, import_source_patterns.collectInvalidResourceTypeCalls)(source, masked, stringLiteralBindings, sourceBindings),
102
+ invalidFlowResourceListCalls: (0, import_bindings.dedupeIndexedEntries)([
103
+ ...(0, import_source_patterns.collectInvalidFlowResourceListCalls)(masked, flowResourceAliases, sourceBindings),
104
+ ...(astInspection == null ? void 0 : astInspection.invalidFlowResourceListCalls) || []
105
+ ]).sort((left, right) => left.index - right.index),
106
+ invalidFlowResourceMethodCalls: (astInspection == null ? void 0 : astInspection.invalidFlowResourceMethodCalls) || [],
107
+ invalidResourceFilterCalls: (astInspection == null ? void 0 : astInspection.invalidResourceFilterCalls) || [],
108
+ resourceCallsInReactHooks: (0, import_source_patterns.collectResourceCallsInReactHooks)(source, masked, reactHookCalls, sourceBindings),
109
+ topLevelReactHookCalls: reactHookCalls.filter((entry) => !(0, import_source.isInsideRanges)(entry.index, functionRanges)),
110
+ unboundReactCreateElementCalls: (0, import_source_patterns.collectUnboundReactCreateElementCalls)(masked, sourceBindings),
111
+ reactComponentFunctionCalls: (0, import_source_patterns.collectReactComponentFunctionCalls)(masked, reactComponentAliases, sourceBindings),
112
+ reactAsyncComponentReferences: (astInspection == null ? void 0 : astInspection.reactAsyncComponentReferences) || [],
113
+ reactComponentCtxRenderCalls: (astInspection == null ? void 0 : astInspection.reactComponentCtxRenderCalls) || [],
114
+ sharedCtxResourceCallsInFunctions: (astInspection == null ? void 0 : astInspection.sharedCtxResourceCallsInFunctions) || [],
115
+ ctxRenderComponentSignatureCalls: (0, import_source_patterns.collectCtxRenderComponentSignatureCalls)(
116
+ source,
117
+ masked,
118
+ reactComponentAliases,
119
+ sourceBindings
120
+ ),
121
+ reactComponentPropReferences: (0, import_source_patterns.collectReactComponentPropReferences)(
122
+ source,
123
+ masked,
124
+ reactComponentAliases,
125
+ sourceBindings
126
+ ),
127
+ directDomWrites,
128
+ directDomAliases,
129
+ windowDocumentNavigatorUses,
130
+ windowDocumentNavigatorAliases,
131
+ ctxAliases,
132
+ ctxLibMemberCaseMismatches: (0, import_source_patterns.collectCtxLibMemberCaseMismatches)(source, masked, sourceBindings),
133
+ invalidCtxApiMemberAccesses: (astInspection == null ? void 0 : astInspection.invalidCtxApiMemberAccesses) || [],
134
+ invalidCtxNonFunctionCalls: (astInspection == null ? void 0 : astInspection.invalidCtxNonFunctionCalls) || [],
135
+ invalidCtxLibMemberAccesses: (astInspection == null ? void 0 : astInspection.invalidCtxLibMemberAccesses) || [],
136
+ forbiddenBareGlobals,
137
+ ctxMemberAccesses: (0, import_source_patterns.collectCtxMemberAccesses)(masked, sourceBindings),
138
+ dynamicCtxAccesses: (0, import_static_values.findUnboundCtxMatches)(masked, /\bctx\s*(?:\?\.\s*)?\[/g, sourceBindings),
139
+ isTopLevelFunctionWrapper: (0, import_source_patterns.isTopLevelFunctionWrapper)(masked, functionRanges, topLevelReachableCtxRenderCalls)
140
+ };
141
+ }
142
+ function collectAstUnknownBareGlobalsFromAst(ast, identifierBindings, modelUse) {
143
+ var _a;
144
+ const allowedGlobals = new Set(import_constants.RUNJS_ALLOWED_BARE_GLOBALS);
145
+ (_a = import_constants.RUNJS_ALLOWED_BARE_GLOBALS_BY_MODEL_USE[modelUse]) == null ? void 0 : _a.forEach((name) => allowedGlobals.add(name));
146
+ const entries = [];
147
+ const reported = /* @__PURE__ */ new Set();
148
+ (0, import_walk.walkAstAncestor)(ast, {
149
+ Identifier(node, ancestors) {
150
+ const name = typeof (node == null ? void 0 : node.name) === "string" ? node.name : "";
151
+ if (!name) {
152
+ return;
153
+ }
154
+ if (allowedGlobals.has(name) || import_constants.FORBIDDEN_BARE_GLOBALS.has(name)) {
155
+ return;
156
+ }
157
+ const index = typeof node.start === "number" ? node.start : 0;
158
+ if (hasAstDeclaredBindingAtIndex(name, index, identifierBindings)) {
159
+ return;
160
+ }
161
+ if (!isIdentifierReadReference(node, ancestors)) {
162
+ return;
163
+ }
164
+ const key = `${name}@${index}`;
165
+ if (reported.has(key)) {
166
+ return;
167
+ }
168
+ reported.add(key);
169
+ entries.push({
170
+ index,
171
+ name,
172
+ suggestedCapability: import_constants.ALLOWED_CTX_ROOTS.has(name) ? `ctx.${name}` : void 0
173
+ });
174
+ }
175
+ });
176
+ return entries.sort((left, right) => left.index - right.index);
177
+ }
178
+ function hasAstDeclaredBindingAtIndex(name, index, identifierBindings) {
179
+ var _a;
180
+ const binding = (0, import_static_values.resolveAstActiveIdentifierBinding)(name, index, identifierBindings);
181
+ if (!binding) {
182
+ return false;
183
+ }
184
+ if ((_a = binding.unavailableRanges) == null ? void 0 : _a.some((range) => index >= range.start && index < range.end)) {
185
+ return false;
186
+ }
187
+ return index >= (binding.declarationStart ?? binding.start);
188
+ }
189
+ function isIdentifierReadReference(node, ancestors) {
190
+ const parent = ancestors[ancestors.length - 2];
191
+ const grandparent = ancestors[ancestors.length - 3];
192
+ if (!parent) {
193
+ return true;
194
+ }
195
+ if (parent.type === "VariableDeclarator" && parent.id === node || parent.type === "FunctionDeclaration" && parent.id === node || parent.type === "FunctionExpression" && parent.id === node || parent.type === "ClassDeclaration" && parent.id === node || parent.type === "ClassExpression" && parent.id === node || parent.type === "MethodDefinition" && parent.key === node && parent.computed !== true || parent.type === "PropertyDefinition" && parent.key === node && parent.computed !== true || parent.type === "MemberExpression" && parent.property === node && parent.computed !== true || parent.type === "LabeledStatement" && parent.label === node || parent.type === "BreakStatement" && parent.label === node || parent.type === "ContinueStatement" && parent.label === node || parent.type === "MetaProperty") {
196
+ return false;
197
+ }
198
+ if (parent.type === "Property") {
199
+ if ((grandparent == null ? void 0 : grandparent.type) === "ObjectPattern") {
200
+ return false;
201
+ }
202
+ if (parent.key === node && parent.value !== node && parent.computed !== true) {
203
+ return false;
204
+ }
205
+ }
206
+ return true;
207
+ }
208
+ function inspectRunJsAst(ast, source, stringBindings, context = {}, modelUse = "") {
209
+ const identifierBindings = (0, import_static_bindings.collectAstIdentifierBindingsFromAst)(ast, source);
210
+ const functionBindings = (0, import_static_bindings.collectAstFunctionBindingsFromAst)(ast, source);
211
+ const aliases = (0, import_ctx_api.collectCtxMethodAliasesFromAst)(ast, source, identifierBindings);
212
+ const ctxRootAliases = (0, import_ctx_api.collectCtxRootAliasesFromAst)(ast, source, identifierBindings);
213
+ const ctxDefiniteRootAliases = (0, import_ctx_api.collectCtxDefiniteRootAliasesFromAst)(ast, source, identifierBindings);
214
+ const ctxNonFunctionRootAliases = (0, import_ctx_api.collectCtxNonFunctionRootAliasesFromAst)(
215
+ ast,
216
+ source,
217
+ ctxDefiniteRootAliases,
218
+ identifierBindings,
219
+ modelUse
220
+ );
221
+ const ctxApiAliases = (0, import_ctx_api.collectCtxApiAliasesFromAst)(ast, source, identifierBindings);
222
+ const ctxLibsRootAliases = (0, import_ctx_api.collectCtxLibsRootAliasesFromAst)(ast, source, identifierBindings);
223
+ const ctxLibAliases = (0, import_ctx_api.collectCtxLibAliasesFromAst)(ast, source, ctxLibsRootAliases, identifierBindings);
224
+ const staticStringBindings = [
225
+ ...stringBindings,
226
+ ...(0, import_static_bindings.collectStaticStringBindingsFromAst)(ast, source, stringBindings, identifierBindings)
227
+ ];
228
+ const staticFilterValueBindings = (0, import_static_bindings.collectStaticFilterValueBindingsFromAst)(ast, source, identifierBindings);
229
+ const ctxApiResourceAliases = (0, import_ctx_api.collectCtxApiResourceAliasesFromAst)(
230
+ ast,
231
+ source,
232
+ ctxApiAliases,
233
+ staticStringBindings,
234
+ staticFilterValueBindings,
235
+ identifierBindings
236
+ );
237
+ const reactNamespaceAliases = (0, import_react.collectReactNamespaceAliasesFromAst)(ast, source, identifierBindings, ctxRootAliases);
238
+ const reactDefaultAliases = (0, import_react.collectReactDefaultAliasesFromAst)(
239
+ ast,
240
+ source,
241
+ identifierBindings,
242
+ reactNamespaceAliases,
243
+ ctxRootAliases
244
+ );
245
+ const invalidReactRuntimeBindings = (0, import_react.collectAstInvalidReactRuntimeBindingsFromAst)(
246
+ ast,
247
+ source,
248
+ identifierBindings,
249
+ reactNamespaceAliases,
250
+ ctxRootAliases,
251
+ reactDefaultAliases
252
+ );
253
+ const reactCreateElementAliases = (0, import_react.collectReactCreateElementAliasesFromAst)(
254
+ ast,
255
+ source,
256
+ identifierBindings,
257
+ reactNamespaceAliases,
258
+ ctxRootAliases
259
+ );
260
+ const asyncComponentBindings = (0, import_react.collectReactAsyncComponentBindingsFromAst)(ast, source, identifierBindings);
261
+ const flowResourceAliases = (0, import_resource.collectAstFlowResourceAliasesFromAst)(
262
+ ast,
263
+ source,
264
+ aliases,
265
+ staticStringBindings,
266
+ identifierBindings
267
+ );
268
+ const nestedRunjsCalls = [];
269
+ const invalidCtxApiMemberAccesses = [
270
+ ...(0, import_ctx_api.collectAstInvalidCtxApiPatternAccesses)(ast, ctxApiAliases, identifierBindings)
271
+ ];
272
+ const invalidCtxNonFunctionCalls = [];
273
+ const invalidCtxLibMemberAccesses = [
274
+ ...(0, import_ctx_api.collectAstInvalidCtxLibPatternAccesses)(ast, ctxLibAliases, ctxLibsRootAliases, identifierBindings, source)
275
+ ];
276
+ const invalidApiResourceCalls = [];
277
+ const invalidResourceActionCalls = (0, import_resource.collectAstInvalidResourceActionCalls)(
278
+ ast,
279
+ source,
280
+ flowResourceAliases,
281
+ identifierBindings,
282
+ aliases,
283
+ ctxApiAliases,
284
+ ctxApiResourceAliases,
285
+ staticStringBindings,
286
+ staticFilterValueBindings,
287
+ context
288
+ );
289
+ const invalidResourceTypeCalls = [];
290
+ const invalidFlowResourceListCalls = [];
291
+ const invalidFlowResourceMethodCalls = [];
292
+ const invalidResourceFilterCalls = (0, import_filter.collectAstInvalidResourceFilterCalls)(
293
+ ast,
294
+ source,
295
+ flowResourceAliases,
296
+ identifierBindings,
297
+ aliases,
298
+ staticStringBindings,
299
+ staticFilterValueBindings,
300
+ context
301
+ );
302
+ const reactAsyncComponentReferences = [];
303
+ const topLevelReachableCtxRenderCalls = (0, import_react_render.collectAstTopLevelReachableCtxRenderCallsFromAst)(
304
+ ast,
305
+ aliases,
306
+ identifierBindings,
307
+ functionBindings
308
+ );
309
+ const reactComponentCtxRenderCalls = (0, import_react_render.collectAstReactComponentCtxRenderCallsFromAst)(
310
+ topLevelReachableCtxRenderCalls,
311
+ aliases,
312
+ reactCreateElementAliases,
313
+ identifierBindings,
314
+ functionBindings
315
+ );
316
+ const sharedCtxResourceCallsInFunctions = (0, import_resource.collectAstSharedCtxResourceCallsInFunctions)(
317
+ ast,
318
+ source,
319
+ aliases,
320
+ identifierBindings
321
+ );
322
+ const unknownBareGlobals = collectAstUnknownBareGlobalsFromAst(ast, identifierBindings, modelUse);
323
+ (0, import_walk.walkAstSimple)(ast, {
324
+ CallExpression(node) {
325
+ const method = (0, import_static_values.resolveCtxMethodCall)(node, aliases, identifierBindings);
326
+ if (method) {
327
+ if (method.method === "runjs") {
328
+ nestedRunjsCalls.push({
329
+ capability: method.capability,
330
+ index: node.start || 0
331
+ });
332
+ return;
333
+ }
334
+ if (method.method === "makeResource" || method.method === "initResource") {
335
+ invalidResourceTypeCalls.push(
336
+ ...(0, import_resource.collectAstInvalidResourceTypeCall)(
337
+ node,
338
+ method.method,
339
+ method.capability,
340
+ source,
341
+ staticStringBindings,
342
+ identifierBindings
343
+ )
344
+ );
345
+ }
346
+ }
347
+ const flowResourceMethodCall = (0, import_resource.collectAstInvalidFlowResourceMethodCall)(
348
+ node,
349
+ flowResourceAliases,
350
+ source,
351
+ identifierBindings,
352
+ aliases,
353
+ staticStringBindings
354
+ );
355
+ flowResourceMethodCall.invalidListCalls.forEach((entry) => invalidFlowResourceListCalls.push(entry));
356
+ flowResourceMethodCall.invalidMethodCalls.forEach((entry) => invalidFlowResourceMethodCalls.push(entry));
357
+ (0, import_ctx_api.collectAstInvalidApiResourceCall)(node, ctxApiAliases, ctxApiResourceAliases, source, identifierBindings).forEach(
358
+ (entry) => invalidApiResourceCalls.push(entry)
359
+ );
360
+ (0, import_ctx_api.collectAstInvalidCtxNonFunctionCall)(
361
+ node,
362
+ ctxDefiniteRootAliases,
363
+ ctxNonFunctionRootAliases,
364
+ identifierBindings,
365
+ modelUse
366
+ ).forEach((entry) => invalidCtxNonFunctionCalls.push(entry));
367
+ (0, import_react.collectAstReactAsyncComponentReferences)(
368
+ node,
369
+ asyncComponentBindings,
370
+ reactCreateElementAliases,
371
+ identifierBindings
372
+ ).forEach((entry) => reactAsyncComponentReferences.push(entry));
373
+ },
374
+ MemberExpression(node) {
375
+ const invalidCtxLibAccess = (0, import_ctx_api.collectAstInvalidCtxLibMemberAccess)(
376
+ node,
377
+ ctxLibAliases,
378
+ ctxLibsRootAliases,
379
+ identifierBindings,
380
+ source
381
+ );
382
+ if (invalidCtxLibAccess) {
383
+ invalidCtxLibMemberAccesses.push(invalidCtxLibAccess);
384
+ }
385
+ const invalidCtxApiAccess = (0, import_ctx_api.collectAstInvalidCtxApiMemberAccess)(node, ctxApiAliases, identifierBindings, source);
386
+ if (invalidCtxApiAccess) {
387
+ invalidCtxApiMemberAccesses.push(invalidCtxApiAccess);
388
+ }
389
+ },
390
+ AssignmentExpression(node) {
391
+ (0, import_ctx_api.collectAstInvalidCtxApiReadonlyWrites)(node.left, ctxApiAliases, identifierBindings).forEach(
392
+ (entry) => invalidCtxApiMemberAccesses.push(entry)
393
+ );
394
+ },
395
+ UpdateExpression(node) {
396
+ (0, import_ctx_api.collectAstInvalidCtxApiReadonlyWrites)(node.argument, ctxApiAliases, identifierBindings).forEach(
397
+ (entry) => invalidCtxApiMemberAccesses.push(entry)
398
+ );
399
+ },
400
+ UnaryExpression(node) {
401
+ if (node.operator !== "delete") {
402
+ return;
403
+ }
404
+ (0, import_ctx_api.collectAstInvalidCtxApiReadonlyWrites)(node.argument, ctxApiAliases, identifierBindings).forEach(
405
+ (entry) => invalidCtxApiMemberAccesses.push(entry)
406
+ );
407
+ },
408
+ ForInStatement(node) {
409
+ (0, import_ctx_api.collectAstInvalidCtxApiReadonlyWrites)(node.left, ctxApiAliases, identifierBindings).forEach(
410
+ (entry) => invalidCtxApiMemberAccesses.push(entry)
411
+ );
412
+ },
413
+ ForOfStatement(node) {
414
+ (0, import_ctx_api.collectAstInvalidCtxApiReadonlyWrites)(node.left, ctxApiAliases, identifierBindings).forEach(
415
+ (entry) => invalidCtxApiMemberAccesses.push(entry)
416
+ );
417
+ }
418
+ });
419
+ const dedupedInvalidApiResourceCalls = (0, import_bindings.dedupeIndexedEntries)(invalidApiResourceCalls).sort(
420
+ (left, right) => left.index - right.index
421
+ );
422
+ return {
423
+ unknownBareGlobals,
424
+ invalidApiResourceCalls: dedupedInvalidApiResourceCalls,
425
+ invalidResourceActionCalls: (0, import_bindings.dedupeIndexedEntries)(invalidResourceActionCalls).sort(
426
+ (left, right) => left.index - right.index
427
+ ),
428
+ invalidCtxApiMemberAccesses: (0, import_ctx_api.filterInvalidCtxApiMemberAccessesForResourceCalls)(
429
+ (0, import_bindings.dedupeIndexedEntries)(invalidCtxApiMemberAccesses),
430
+ dedupedInvalidApiResourceCalls
431
+ ).sort((left, right) => left.index - right.index),
432
+ invalidCtxNonFunctionCalls: (0, import_bindings.dedupeIndexedEntries)(invalidCtxNonFunctionCalls).sort(
433
+ (left, right) => left.index - right.index
434
+ ),
435
+ invalidCtxLibMemberAccesses: (0, import_bindings.dedupeIndexedEntries)(invalidCtxLibMemberAccesses).sort(
436
+ (left, right) => left.index - right.index
437
+ ),
438
+ invalidResourceTypeCalls: (0, import_static_values.dedupeAstResourceEntries)(invalidResourceTypeCalls),
439
+ invalidFlowResourceListCalls: (0, import_bindings.dedupeIndexedEntries)(invalidFlowResourceListCalls).sort(
440
+ (left, right) => left.index - right.index
441
+ ),
442
+ invalidFlowResourceMethodCalls: (0, import_bindings.dedupeIndexedEntries)(invalidFlowResourceMethodCalls).sort(
443
+ (left, right) => left.index - right.index
444
+ ),
445
+ invalidResourceFilterCalls: (0, import_bindings.dedupeIndexedEntries)(invalidResourceFilterCalls).sort(
446
+ (left, right) => left.index - right.index
447
+ ),
448
+ invalidReactRuntimeBindings: (0, import_bindings.dedupeIndexedEntries)(invalidReactRuntimeBindings).sort(
449
+ (left, right) => left.start - right.start
450
+ ),
451
+ nestedRunjsCalls: (0, import_bindings.dedupeIndexedEntries)(nestedRunjsCalls).sort((left, right) => left.index - right.index),
452
+ reactAsyncComponentReferences: (0, import_bindings.dedupeIndexedEntries)(reactAsyncComponentReferences).sort(
453
+ (left, right) => left.index - right.index
454
+ ),
455
+ reactComponentCtxRenderCalls,
456
+ sharedCtxResourceCallsInFunctions,
457
+ topLevelReachableCtxRenderCalls
458
+ };
459
+ }
460
+ // Annotate the CommonJS export names for ESM import in node:
461
+ 0 && (module.exports = {
462
+ scanJavaScriptSource
463
+ });