@nocobase/plugin-flow-engine 2.3.0-alpha.1 → 2.3.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai/ai-employees/nathan/prompt.md +2 -0
- package/dist/ai/ai-employees/nathan/skills/frontend-developer/SKILLS.md +1 -0
- package/dist/ai/ai-employees/nathan/skills/frontend-developer/tools/patchJSCode.js +2 -2
- package/dist/ai/docs/runjs/context/ai.md +194 -4
- package/dist/externalVersion.js +9 -9
- package/dist/locale/en-US.json +2 -0
- package/dist/locale/index.d.ts +4 -0
- package/dist/locale/zh-CN.json +2 -0
- package/dist/node_modules/@ant-design/icons-svg/package.json +1 -1
- package/dist/node_modules/acorn/package.json +1 -1
- package/dist/node_modules/acorn-jsx/package.json +1 -1
- package/dist/node_modules/acorn-walk/package.json +1 -1
- package/dist/node_modules/ses/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/flow-surfaces/builder.js +5 -0
- package/dist/server/flow-surfaces/catalog.js +27 -8
- package/dist/server/flow-surfaces/configure-options.js +17 -1
- package/dist/server/flow-surfaces/field-binding-registry.js +9 -8
- package/dist/server/flow-surfaces/runjs-authoring/ast/parser.d.ts +10 -3
- package/dist/server/flow-surfaces/runjs-authoring/ast/parser.js +90 -8
- package/dist/server/flow-surfaces/runjs-authoring/ast/source.d.ts +2 -2
- package/dist/server/flow-surfaces/runjs-authoring/ast/source.js +7 -69
- package/dist/server/flow-surfaces/runjs-authoring/ast/static-bindings.d.ts +5 -5
- package/dist/server/flow-surfaces/runjs-authoring/ast/static-bindings.js +56 -23
- package/dist/server/flow-surfaces/runjs-authoring/ast/static-values.d.ts +1 -1
- package/dist/server/flow-surfaces/runjs-authoring/ast/static-values.js +4 -2
- package/dist/server/flow-surfaces/service-utils.d.ts +1 -0
- package/dist/server/flow-surfaces/service-utils.js +17 -0
- package/dist/server/flow-surfaces/service.js +9 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +7 -0
- package/dist/server/plugin.d.ts +13 -0
- package/dist/server/plugin.js +90 -3
- package/dist/server/repository.d.ts +12 -0
- package/dist/server/repository.js +39 -2
- package/dist/server/template/context-keys.d.ts +14 -0
- package/dist/server/template/context-keys.js +86 -0
- package/dist/server/template/contexts.d.ts +5 -8
- package/dist/server/template/contexts.js +43 -51
- package/dist/server/template/resolver.d.ts +5 -13
- package/dist/server/template/resolver.js +188 -257
- package/dist/server/template/variable-expression.d.ts +72 -0
- package/dist/server/template/variable-expression.js +597 -0
- package/dist/server/variables/allow-list.d.ts +49 -0
- package/dist/server/variables/allow-list.js +546 -0
- package/dist/server/variables/form-item-record-slot-resolvers.d.ts +10 -0
- package/dist/server/variables/form-item-record-slot-resolvers.js +297 -0
- package/dist/server/variables/record-bindings.d.ts +42 -0
- package/dist/server/variables/record-bindings.js +196 -0
- package/dist/server/variables/record-projection.d.ts +10 -0
- package/dist/server/variables/record-projection.js +140 -0
- package/dist/server/variables/record-slot-policy.d.ts +23 -0
- package/dist/server/variables/record-slot-policy.js +100 -0
- package/dist/server/variables/record-slot-resolvers.d.ts +46 -0
- package/dist/server/variables/record-slot-resolvers.js +115 -0
- package/dist/server/variables/records.d.ts +49 -2
- package/dist/server/variables/records.js +309 -18
- package/dist/server/variables/registry.d.ts +33 -10
- package/dist/server/variables/registry.js +197 -362
- package/dist/server/variables/resolve.d.ts +20 -2
- package/dist/server/variables/resolve.js +85 -13
- package/dist/server/variables/runjs-variable-dependencies.d.ts +23 -0
- package/dist/server/variables/runjs-variable-dependencies.js +542 -0
- package/dist/server/variables/selects.js +6 -3
- package/dist/server/variables/utils.d.ts +3 -6
- package/dist/server/variables/utils.js +50 -111
- package/package.json +2 -2
|
@@ -0,0 +1,542 @@
|
|
|
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 runjs_variable_dependencies_exports = {};
|
|
28
|
+
__export(runjs_variable_dependencies_exports, {
|
|
29
|
+
MAX_FLOW_MODEL_VARIABLE_SOURCE_DEPTH: () => MAX_FLOW_MODEL_VARIABLE_SOURCE_DEPTH,
|
|
30
|
+
MAX_FLOW_MODEL_VARIABLE_SOURCE_NODES: () => MAX_FLOW_MODEL_VARIABLE_SOURCE_NODES,
|
|
31
|
+
MAX_FLOW_MODEL_VARIABLE_STRING_LENGTH: () => MAX_FLOW_MODEL_VARIABLE_STRING_LENGTH,
|
|
32
|
+
MAX_FLOW_MODEL_VARIABLE_TOTAL_STRING_LENGTH: () => MAX_FLOW_MODEL_VARIABLE_TOTAL_STRING_LENGTH,
|
|
33
|
+
collectPersistedRunJsVariableTemplates: () => collectPersistedRunJsVariableTemplates,
|
|
34
|
+
prepareFlowModelVariableSource: () => prepareFlowModelVariableSource
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(runjs_variable_dependencies_exports);
|
|
37
|
+
var import_bindings = require("../flow-surfaces/runjs-authoring/ast/bindings");
|
|
38
|
+
var import_source = require("../flow-surfaces/runjs-authoring/ast/source");
|
|
39
|
+
var import_static_bindings = require("../flow-surfaces/runjs-authoring/ast/static-bindings");
|
|
40
|
+
var import_static_values = require("../flow-surfaces/runjs-authoring/ast/static-values");
|
|
41
|
+
var import_parser = require("../flow-surfaces/runjs-authoring/ast/parser");
|
|
42
|
+
var import_walk = require("../flow-surfaces/runjs-authoring/ast/walk");
|
|
43
|
+
var import_constants = require("../flow-surfaces/runjs-authoring/runtime/constants");
|
|
44
|
+
var import_variable_expression = require("../template/variable-expression");
|
|
45
|
+
const RUNJS_VALUE_KEYS = /* @__PURE__ */ new Set(["code", "version"]);
|
|
46
|
+
const RUNJS_PATH_SUFFIXES = /* @__PURE__ */ new Set(["stepParams.jsSettings.runJs", "stepParams.clickSettings.runJs"]);
|
|
47
|
+
const MUTATING_CTX_METHODS = /* @__PURE__ */ new Set(["__defineGetter__", "__defineSetter__"]);
|
|
48
|
+
const GLOBAL_OBJECT_NAMES = /* @__PURE__ */ new Set(["globalThis"]);
|
|
49
|
+
const DYNAMIC_CODE_EXECUTION_NAMES = /* @__PURE__ */ new Set(["eval", "Function"]);
|
|
50
|
+
const MAX_FLOW_MODEL_VARIABLE_SOURCE_DEPTH = 128;
|
|
51
|
+
const MAX_FLOW_MODEL_VARIABLE_SOURCE_NODES = 1e4;
|
|
52
|
+
const MAX_FLOW_MODEL_VARIABLE_STRING_LENGTH = 256 * 1024;
|
|
53
|
+
const MAX_FLOW_MODEL_VARIABLE_TOTAL_STRING_LENGTH = 1024 * 1024;
|
|
54
|
+
const MAX_RUNJS_STATIC_BINDING_WORK = 1e5;
|
|
55
|
+
const STATIC_BINDING_BUDGET_EXHAUSTED = Symbol("static binding budget exhausted");
|
|
56
|
+
function getEnumerableDataEntries(value) {
|
|
57
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
58
|
+
const entries = [];
|
|
59
|
+
for (const key of Object.keys(descriptors)) {
|
|
60
|
+
const descriptor = descriptors[key];
|
|
61
|
+
if (!descriptor.enumerable) continue;
|
|
62
|
+
if (!Object.prototype.hasOwnProperty.call(descriptor, "value")) {
|
|
63
|
+
throw new TypeError("FlowModel variable source must not contain accessors");
|
|
64
|
+
}
|
|
65
|
+
entries.push([key, descriptor.value]);
|
|
66
|
+
}
|
|
67
|
+
return { descriptors, entries };
|
|
68
|
+
}
|
|
69
|
+
function readPersistedRunJsValue(entries) {
|
|
70
|
+
if (!entries.length || entries.some(([key]) => !RUNJS_VALUE_KEYS.has(key))) return;
|
|
71
|
+
const values = new Map(entries);
|
|
72
|
+
const code = values.get("code");
|
|
73
|
+
const version = values.get("version");
|
|
74
|
+
if (typeof code !== "string" || version != null && typeof version !== "string") return;
|
|
75
|
+
return { code, version };
|
|
76
|
+
}
|
|
77
|
+
function readDataProperty(value, key) {
|
|
78
|
+
var _a;
|
|
79
|
+
return value && typeof value === "object" ? (_a = Object.getOwnPropertyDescriptor(value, key)) == null ? void 0 : _a.value : void 0;
|
|
80
|
+
}
|
|
81
|
+
function isPersistedRunJsPath(pathTail, flowRegistry) {
|
|
82
|
+
const tail = pathTail.slice(-3);
|
|
83
|
+
if (RUNJS_PATH_SUFFIXES.has(tail.join("."))) return true;
|
|
84
|
+
if (tail[0] === "stepParams") {
|
|
85
|
+
const steps = readDataProperty(readDataProperty(flowRegistry, tail[1]), "steps");
|
|
86
|
+
if (readDataProperty(readDataProperty(steps, tail[2]), "use") === "runjs") return true;
|
|
87
|
+
}
|
|
88
|
+
const path = pathTail.join(".");
|
|
89
|
+
return /(?:^|\.)linkageRules\.value\.\d+\.actions\.\d+\.params\.value\.\d+\.value$/.test(path) || /(?:^|\.)formFilterBlockModelSettings\.defaultValues\.value\.\d+\.value$/.test(path);
|
|
90
|
+
}
|
|
91
|
+
function isPersistedRunJsStringPath(pathTail) {
|
|
92
|
+
const path = pathTail.join(".");
|
|
93
|
+
return /(?:^|\.)linkageRules\.value\.\d+\.actions\.\d+\.params\.value\.script$/.test(path) || /(?:^|\.)chartSettings\.configure\.chart\.(?:option|events)\.raw$/.test(path);
|
|
94
|
+
}
|
|
95
|
+
function createTraversalContainer(input, descriptors) {
|
|
96
|
+
var _a;
|
|
97
|
+
if (!Array.isArray(input)) return /* @__PURE__ */ Object.create(null);
|
|
98
|
+
const length = (_a = descriptors.length) == null ? void 0 : _a.value;
|
|
99
|
+
if (!Number.isInteger(length) || length < 0 || length > MAX_FLOW_MODEL_VARIABLE_SOURCE_NODES) {
|
|
100
|
+
throw new RangeError("FlowModel variable source array exceeds its limit");
|
|
101
|
+
}
|
|
102
|
+
return new Array(length);
|
|
103
|
+
}
|
|
104
|
+
function defineTraversalValue(parent, key, value) {
|
|
105
|
+
Object.defineProperty(parent, key, {
|
|
106
|
+
configurable: true,
|
|
107
|
+
enumerable: true,
|
|
108
|
+
value,
|
|
109
|
+
writable: true
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function functionBindsCtxParameter(node, cache) {
|
|
113
|
+
if (!(0, import_bindings.isAstFunctionLike)(node)) return false;
|
|
114
|
+
const objectNode = node;
|
|
115
|
+
const cached = cache.get(objectNode);
|
|
116
|
+
if (typeof cached === "boolean") return cached;
|
|
117
|
+
let bindsCtx = false;
|
|
118
|
+
for (const parameter of node.params || []) {
|
|
119
|
+
(0, import_static_values.collectAstPatternBindingIdentifiers)(parameter, (name) => {
|
|
120
|
+
if (name === "ctx") bindsCtx = true;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
cache.set(objectNode, bindsCtx);
|
|
124
|
+
return bindsCtx;
|
|
125
|
+
}
|
|
126
|
+
function hasCtxParameterInFunctionAncestors(ancestors, cache) {
|
|
127
|
+
return ancestors.some((ancestor) => functionBindsCtxParameter(ancestor, cache));
|
|
128
|
+
}
|
|
129
|
+
function getDirectCtxMethodName(node, identifierBindings) {
|
|
130
|
+
const member = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
131
|
+
if ((member == null ? void 0 : member.type) !== "MemberExpression" || !(0, import_static_values.isUnshadowedCtxIdentifier)(member.object, identifierBindings)) return;
|
|
132
|
+
return (0, import_static_values.getAstStaticPropertyName)(member);
|
|
133
|
+
}
|
|
134
|
+
function isCtxRootedMember(node, identifierBindings) {
|
|
135
|
+
const member = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
136
|
+
if ((member == null ? void 0 : member.type) !== "MemberExpression") return false;
|
|
137
|
+
const root = (0, import_static_values.getAstMemberRootIdentifier)(member);
|
|
138
|
+
return (root == null ? void 0 : root.name) === "ctx" && !(0, import_static_values.hasAstActiveBinding)("ctx", root.index, identifierBindings);
|
|
139
|
+
}
|
|
140
|
+
function isCtxMutationTarget(target, identifierBindings) {
|
|
141
|
+
const node = (0, import_bindings.unwrapAstChainExpression)(target);
|
|
142
|
+
if (!node) return false;
|
|
143
|
+
if (node.type === "Identifier") return (0, import_static_values.isUnshadowedCtxIdentifier)(node, identifierBindings);
|
|
144
|
+
if (node.type === "MemberExpression") return isCtxRootedMember(node, identifierBindings);
|
|
145
|
+
if (node.type === "AssignmentPattern") return isCtxMutationTarget(node.left, identifierBindings);
|
|
146
|
+
if (node.type === "RestElement") return isCtxMutationTarget(node.argument, identifierBindings);
|
|
147
|
+
if (node.type === "ArrayPattern") {
|
|
148
|
+
return (node.elements || []).some((element) => isCtxMutationTarget(element, identifierBindings));
|
|
149
|
+
}
|
|
150
|
+
if (node.type !== "ObjectPattern") return false;
|
|
151
|
+
return (node.properties || []).some((propertyValue) => {
|
|
152
|
+
const property = propertyValue;
|
|
153
|
+
if ((property == null ? void 0 : property.type) === "RestElement") {
|
|
154
|
+
return isCtxMutationTarget(property.argument, identifierBindings);
|
|
155
|
+
}
|
|
156
|
+
return (property == null ? void 0 : property.type) === "Property" && isCtxMutationTarget(property.value, identifierBindings);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function isNonReferenceIdentifier(node, parent) {
|
|
160
|
+
if (!parent) return false;
|
|
161
|
+
if (parent.type === "MemberExpression" && parent.property === node && !parent.computed) return true;
|
|
162
|
+
if (parent.type === "Property" && parent.key === node && !parent.computed && !parent.shorthand) return true;
|
|
163
|
+
if ((parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
return (parent.type === "LabeledStatement" || parent.type === "BreakStatement" || parent.type === "ContinueStatement") && parent.value === node;
|
|
167
|
+
}
|
|
168
|
+
function thisUsesTopLevelBinding(ancestors) {
|
|
169
|
+
for (let index = 0; index < ancestors.length; index += 1) {
|
|
170
|
+
const ancestor = ancestors[index];
|
|
171
|
+
if ((0, import_bindings.isAstFunctionLike)(ancestor) && ancestor.type !== "ArrowFunctionExpression") return false;
|
|
172
|
+
if (ancestor.type === "StaticBlock") return false;
|
|
173
|
+
if (ancestor.type === "PropertyDefinition" && (0, import_bindings.unwrapAstChainExpression)(ancestor.value) === ancestors[index + 1]) {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
function hasUnsafeCtxUsage(ast, identifierBindings) {
|
|
180
|
+
let unsafe = false;
|
|
181
|
+
(0, import_walk.walkAstAncestor)(ast, {
|
|
182
|
+
Identifier(node, ancestors) {
|
|
183
|
+
const parent = ancestors[ancestors.length - 2];
|
|
184
|
+
if (isNonReferenceIdentifier(node, parent)) return;
|
|
185
|
+
if (node.name && (GLOBAL_OBJECT_NAMES.has(node.name) || DYNAMIC_CODE_EXECUTION_NAMES.has(node.name)) && !(0, import_static_values.hasAstActiveBinding)(node.name, node.start || 0, identifierBindings)) {
|
|
186
|
+
unsafe = true;
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (!(0, import_static_values.isUnshadowedCtxIdentifier)(node, identifierBindings)) return;
|
|
190
|
+
if ((parent == null ? void 0 : parent.type) === "MemberExpression" && (0, import_bindings.unwrapAstChainExpression)(parent.object) === node) return;
|
|
191
|
+
unsafe = true;
|
|
192
|
+
},
|
|
193
|
+
ThisExpression(_node, ancestors) {
|
|
194
|
+
if (thisUsesTopLevelBinding(ancestors)) unsafe = true;
|
|
195
|
+
},
|
|
196
|
+
WithStatement() {
|
|
197
|
+
unsafe = true;
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
return unsafe;
|
|
201
|
+
}
|
|
202
|
+
function hasCtxMutation(ast, identifierBindings) {
|
|
203
|
+
let mutated = false;
|
|
204
|
+
(0, import_walk.walkAstSimple)(ast, {
|
|
205
|
+
AssignmentExpression(node) {
|
|
206
|
+
if (isCtxMutationTarget(node.left, identifierBindings)) mutated = true;
|
|
207
|
+
},
|
|
208
|
+
CallExpression(node) {
|
|
209
|
+
const callee = (0, import_bindings.unwrapAstChainExpression)(node.callee);
|
|
210
|
+
if ((callee == null ? void 0 : callee.type) === "MemberExpression" && MUTATING_CTX_METHODS.has((0, import_static_values.getAstStaticPropertyName)(callee)) && isCtxRootedMember(callee, identifierBindings)) {
|
|
211
|
+
mutated = true;
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
ForInStatement(node) {
|
|
215
|
+
if (isCtxMutationTarget(node.left, identifierBindings)) mutated = true;
|
|
216
|
+
},
|
|
217
|
+
ForOfStatement(node) {
|
|
218
|
+
if (isCtxMutationTarget(node.left, identifierBindings)) mutated = true;
|
|
219
|
+
},
|
|
220
|
+
UnaryExpression(node) {
|
|
221
|
+
if (node.operator === "delete" && isCtxMutationTarget(node.argument, identifierBindings)) {
|
|
222
|
+
mutated = true;
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
UpdateExpression(node) {
|
|
226
|
+
if (isCtxMutationTarget(node.argument, identifierBindings)) mutated = true;
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
return mutated;
|
|
230
|
+
}
|
|
231
|
+
function createValidatedGetVarTemplate(value, code) {
|
|
232
|
+
var _a;
|
|
233
|
+
const path = (_a = (0, import_static_values.resolveAstStaticStringValue)(value, code)) == null ? void 0 : _a.trim();
|
|
234
|
+
if (!path) return;
|
|
235
|
+
const template = `{{${path}}}`;
|
|
236
|
+
const analysis = (0, import_variable_expression.analyzeVariableTemplate)(template, { mode: "flow-model" });
|
|
237
|
+
if (analysis.errors.length !== 0 || analysis.paths.length !== 1 || analysis.value.kind !== "string") return;
|
|
238
|
+
if (analysis.value.expressions.length !== 1) return;
|
|
239
|
+
const expression = analysis.value.expressions[0];
|
|
240
|
+
const variablePath = expression.paths[0];
|
|
241
|
+
if (!variablePath || !expression.supported || expression.paths.length !== 1 || expression.expressionSpan.start !== 2 || expression.expressionSpan.end !== 2 + path.length || expression.placeholderSpan.start !== 0 || expression.placeholderSpan.end !== template.length || variablePath.span.start !== 2 || variablePath.span.end !== 2 + path.length) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
return `{{ ${path} }}`;
|
|
245
|
+
}
|
|
246
|
+
function resolveStaticJsonValue(node, code) {
|
|
247
|
+
var _a;
|
|
248
|
+
const valueNode = (0, import_bindings.unwrapAstChainExpression)(node);
|
|
249
|
+
if (!valueNode) return { ok: false };
|
|
250
|
+
if (valueNode.type === "Literal") {
|
|
251
|
+
const literalValue = valueNode.value;
|
|
252
|
+
if (literalValue === null) return { ok: true, value: null };
|
|
253
|
+
if (typeof literalValue === "string") return { ok: true, value: literalValue };
|
|
254
|
+
if (typeof literalValue === "boolean") return { ok: true, value: literalValue };
|
|
255
|
+
if (typeof literalValue === "number" && Number.isFinite(literalValue)) return { ok: true, value: literalValue };
|
|
256
|
+
return { ok: false };
|
|
257
|
+
}
|
|
258
|
+
if (valueNode.type === "TemplateLiteral" && !((_a = valueNode.expressions) == null ? void 0 : _a.length)) {
|
|
259
|
+
const value2 = (0, import_static_values.resolveAstStaticStringValue)(valueNode, code);
|
|
260
|
+
return typeof value2 === "string" ? { ok: true, value: value2 } : { ok: false };
|
|
261
|
+
}
|
|
262
|
+
if (valueNode.type === "UnaryExpression" && valueNode.operator === "-") {
|
|
263
|
+
const argument = (0, import_bindings.unwrapAstChainExpression)(valueNode.argument);
|
|
264
|
+
return (argument == null ? void 0 : argument.type) === "Literal" && typeof argument.value === "number" && Number.isFinite(argument.value) ? { ok: true, value: -argument.value } : { ok: false };
|
|
265
|
+
}
|
|
266
|
+
if (valueNode.type === "ArrayExpression") {
|
|
267
|
+
const value2 = [];
|
|
268
|
+
for (const element of valueNode.elements || []) {
|
|
269
|
+
if (!element || element.type === "SpreadElement") return { ok: false };
|
|
270
|
+
const resolved = resolveStaticJsonValue(element, code);
|
|
271
|
+
if (!resolved.ok) return resolved;
|
|
272
|
+
value2.push(resolved.value);
|
|
273
|
+
}
|
|
274
|
+
return { ok: true, value: value2 };
|
|
275
|
+
}
|
|
276
|
+
if (valueNode.type !== "ObjectExpression") return { ok: false };
|
|
277
|
+
const value = /* @__PURE__ */ Object.create(null);
|
|
278
|
+
for (const propertyValue of valueNode.properties || []) {
|
|
279
|
+
const property = propertyValue;
|
|
280
|
+
if ((property == null ? void 0 : property.type) !== "Property" || property.computed || property.kind !== "init" || property.method || property.shorthand) {
|
|
281
|
+
return { ok: false };
|
|
282
|
+
}
|
|
283
|
+
const keyNode = (0, import_bindings.unwrapAstChainExpression)(property.key);
|
|
284
|
+
const key = (keyNode == null ? void 0 : keyNode.type) === "Identifier" ? keyNode.name : (keyNode == null ? void 0 : keyNode.type) === "Literal" && (typeof keyNode.value === "string" || typeof keyNode.value === "number") ? String(keyNode.value) : void 0;
|
|
285
|
+
if (typeof key !== "string" || key === "__proto__" || Object.prototype.hasOwnProperty.call(value, key)) {
|
|
286
|
+
return { ok: false };
|
|
287
|
+
}
|
|
288
|
+
const resolved = resolveStaticJsonValue(property.value, code);
|
|
289
|
+
if (!resolved.ok) return resolved;
|
|
290
|
+
value[key] = resolved.value;
|
|
291
|
+
}
|
|
292
|
+
return { ok: true, value };
|
|
293
|
+
}
|
|
294
|
+
function collectValidatedResolveJsonTemplates(value) {
|
|
295
|
+
const analysis = (0, import_variable_expression.analyzeVariableTemplate)(value, { mode: "untrusted-request" });
|
|
296
|
+
if (!analysis.supported || analysis.errors.length) return [];
|
|
297
|
+
const templates = /* @__PURE__ */ new Set();
|
|
298
|
+
const visit = (current) => {
|
|
299
|
+
if (typeof current === "string") {
|
|
300
|
+
if ((0, import_variable_expression.analyzeVariableTemplate)(current, { mode: "untrusted-request" }).paths.length) templates.add(current);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
if (Array.isArray(current)) {
|
|
304
|
+
current.forEach(visit);
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
if (current && typeof current === "object") Object.values(current).forEach(visit);
|
|
308
|
+
};
|
|
309
|
+
visit(value);
|
|
310
|
+
return Array.from(templates);
|
|
311
|
+
}
|
|
312
|
+
function collectBindingDependencies(ast, consumeWork) {
|
|
313
|
+
const dependencies = /* @__PURE__ */ new Map();
|
|
314
|
+
(0, import_walk.walkAstSimple)(ast, {
|
|
315
|
+
VariableDeclarator(node) {
|
|
316
|
+
if (!node.init) return;
|
|
317
|
+
const names = [];
|
|
318
|
+
(0, import_static_values.collectAstPatternBindingIdentifiers)(node.id, (name) => names.push(name));
|
|
319
|
+
(0, import_walk.walkAstSimple)(node.init, {
|
|
320
|
+
Identifier(reference) {
|
|
321
|
+
const dependency = reference.name;
|
|
322
|
+
if (!dependency) return;
|
|
323
|
+
for (const name of names) {
|
|
324
|
+
consumeWork(1);
|
|
325
|
+
for (const [from, to] of [
|
|
326
|
+
[name, dependency],
|
|
327
|
+
[dependency, name]
|
|
328
|
+
]) {
|
|
329
|
+
const related = dependencies.get(from) || /* @__PURE__ */ new Set();
|
|
330
|
+
related.add(to);
|
|
331
|
+
dependencies.set(from, related);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
return dependencies;
|
|
339
|
+
}
|
|
340
|
+
function extractStaticVariableTemplates(code, parsed, consumeBindingWork) {
|
|
341
|
+
if (!parsed.ast) return [];
|
|
342
|
+
const identifierBindings = (0, import_static_bindings.collectAstIdentifierBindingsFromAst)(parsed.ast, code);
|
|
343
|
+
if (hasUnsafeCtxUsage(parsed.ast, identifierBindings) || hasCtxMutation(parsed.ast, identifierBindings)) {
|
|
344
|
+
return [];
|
|
345
|
+
}
|
|
346
|
+
let bindingDependencies;
|
|
347
|
+
const bindingResults = /* @__PURE__ */ new Map();
|
|
348
|
+
let bindingBudgetExhausted = false;
|
|
349
|
+
const functionCtxParameterCache = /* @__PURE__ */ new WeakMap();
|
|
350
|
+
const templates = /* @__PURE__ */ new Set();
|
|
351
|
+
(0, import_walk.walkAstAncestor)(parsed.ast, {
|
|
352
|
+
CallExpression(node, ancestors) {
|
|
353
|
+
var _a, _b, _c, _d;
|
|
354
|
+
const methodName = getDirectCtxMethodName(node.callee, identifierBindings);
|
|
355
|
+
if (hasCtxParameterInFunctionAncestors(ancestors, functionCtxParameterCache)) return;
|
|
356
|
+
if (methodName === "getVar") {
|
|
357
|
+
const template = createValidatedGetVarTemplate((_a = node.arguments) == null ? void 0 : _a[0], code);
|
|
358
|
+
if (template) templates.add(template);
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
if (methodName !== "resolveJsonTemplate" || !((_b = node.arguments) == null ? void 0 : _b.length) || node.arguments.length > 2) return;
|
|
362
|
+
if (node.arguments.length === 2) {
|
|
363
|
+
const options = (0, import_bindings.unwrapAstChainExpression)(node.arguments[1]);
|
|
364
|
+
if ((options == null ? void 0 : options.type) !== "ObjectExpression" || ((_c = options.properties) == null ? void 0 : _c.length) !== 0) return;
|
|
365
|
+
}
|
|
366
|
+
const argument = (0, import_bindings.unwrapAstChainExpression)(node.arguments[0]);
|
|
367
|
+
let resolved = resolveStaticJsonValue(argument, code);
|
|
368
|
+
if ((argument == null ? void 0 : argument.type) === "Identifier" && !bindingBudgetExhausted) {
|
|
369
|
+
try {
|
|
370
|
+
const name = argument.name || "";
|
|
371
|
+
let bindings = bindingResults.get(name);
|
|
372
|
+
if (!bindings) {
|
|
373
|
+
bindingDependencies ??= collectBindingDependencies(parsed.ast, consumeBindingWork);
|
|
374
|
+
const names = /* @__PURE__ */ new Set([name]);
|
|
375
|
+
for (const current of names) {
|
|
376
|
+
for (const dependency of bindingDependencies.get(current) || []) {
|
|
377
|
+
consumeBindingWork(1);
|
|
378
|
+
names.add(dependency);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
bindings = {
|
|
382
|
+
names,
|
|
383
|
+
values: (0, import_static_bindings.collectStaticFilterValueBindingsFromAst)(
|
|
384
|
+
parsed.ast,
|
|
385
|
+
code,
|
|
386
|
+
identifierBindings,
|
|
387
|
+
consumeBindingWork,
|
|
388
|
+
names
|
|
389
|
+
)
|
|
390
|
+
};
|
|
391
|
+
bindingResults.set(name, bindings);
|
|
392
|
+
}
|
|
393
|
+
consumeBindingWork(bindings.values.length * (identifierBindings.length + 1));
|
|
394
|
+
resolved = resolveStaticJsonValue(
|
|
395
|
+
(_d = (0, import_static_values.resolveAstAliasBinding)(name, argument.start || 0, bindings.values, identifierBindings)) == null ? void 0 : _d.valueNode,
|
|
396
|
+
code
|
|
397
|
+
);
|
|
398
|
+
if (!resolved.ok) {
|
|
399
|
+
bindings.strings ??= (0, import_static_bindings.collectStaticStringBindingsFromAst)(
|
|
400
|
+
parsed.ast,
|
|
401
|
+
code,
|
|
402
|
+
[],
|
|
403
|
+
identifierBindings,
|
|
404
|
+
consumeBindingWork,
|
|
405
|
+
bindings.names
|
|
406
|
+
);
|
|
407
|
+
consumeBindingWork(bindings.strings.length * (identifierBindings.length + 1));
|
|
408
|
+
const staticString = (0, import_static_values.resolveRunJsStaticString)(argument, code, bindings.strings, identifierBindings);
|
|
409
|
+
if (typeof staticString === "string") resolved = { ok: true, value: staticString };
|
|
410
|
+
}
|
|
411
|
+
} catch (error) {
|
|
412
|
+
if (error !== STATIC_BINDING_BUDGET_EXHAUSTED) throw error;
|
|
413
|
+
bindingBudgetExhausted = true;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
if (!resolved.ok) return;
|
|
417
|
+
collectValidatedResolveJsonTemplates(resolved.value).forEach((template) => templates.add(template));
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
return Array.from(templates);
|
|
421
|
+
}
|
|
422
|
+
function prepareFlowModelVariableSource(value, options = {}) {
|
|
423
|
+
var _a, _b, _c;
|
|
424
|
+
try {
|
|
425
|
+
const templates = /* @__PURE__ */ new Set();
|
|
426
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
427
|
+
const root = /* @__PURE__ */ Object.create(null);
|
|
428
|
+
const stack = [{ depth: 0, input: value, key: "value", parent: root, pathTail: [] }];
|
|
429
|
+
let scheduledNodes = 1;
|
|
430
|
+
let sourceCount = 0;
|
|
431
|
+
let totalStringLength = 0;
|
|
432
|
+
let totalSourceLength = 0;
|
|
433
|
+
let remainingBindingWork = MAX_RUNJS_STATIC_BINDING_WORK;
|
|
434
|
+
const consumeBindingWork = (work) => {
|
|
435
|
+
remainingBindingWork -= work;
|
|
436
|
+
if (remainingBindingWork < 0) throw STATIC_BINDING_BUDGET_EXHAUSTED;
|
|
437
|
+
};
|
|
438
|
+
const supplementalScripts = [];
|
|
439
|
+
const parsedSources = /* @__PURE__ */ new Map();
|
|
440
|
+
const getParsedSource = (code) => {
|
|
441
|
+
let parsed = parsedSources.get(code);
|
|
442
|
+
if (!parsed) {
|
|
443
|
+
parsed = (0, import_parser.parseRunJsAuthoringAst)(code, { allowLegacyTemplates: true });
|
|
444
|
+
parsedSources.set(code, parsed);
|
|
445
|
+
}
|
|
446
|
+
return parsed;
|
|
447
|
+
};
|
|
448
|
+
const extractRunJsDependencies = (code) => {
|
|
449
|
+
if (sourceCount < import_constants.MAX_RUNJS_SOURCES_PER_REQUEST && code.length <= import_constants.MAX_RUNJS_SOURCE_LENGTH && totalSourceLength + code.length <= import_constants.MAX_RUNJS_TOTAL_SOURCE_LENGTH) {
|
|
450
|
+
sourceCount += 1;
|
|
451
|
+
totalSourceLength += code.length;
|
|
452
|
+
extractStaticVariableTemplates(code, getParsedSource(code), consumeBindingWork).forEach(
|
|
453
|
+
(template) => templates.add(template)
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
const prepareRunJsCode = (code, version, preserveLegacyTemplates = false) => {
|
|
458
|
+
if (preserveLegacyTemplates) supplementalScripts.push(code);
|
|
459
|
+
else extractRunJsDependencies(code);
|
|
460
|
+
if (version === "v2" && !preserveLegacyTemplates || !code.includes("{{")) return "";
|
|
461
|
+
return (0, import_source.maskJavaScriptComments)(code, getParsedSource(code));
|
|
462
|
+
};
|
|
463
|
+
while (stack.length) {
|
|
464
|
+
const frame = stack.pop();
|
|
465
|
+
if (!frame) break;
|
|
466
|
+
const { depth, input, key, parent, pathTail } = frame;
|
|
467
|
+
if (!input || typeof input !== "object") {
|
|
468
|
+
if (typeof input === "string") {
|
|
469
|
+
totalStringLength += input.length;
|
|
470
|
+
if (input.length > MAX_FLOW_MODEL_VARIABLE_STRING_LENGTH || totalStringLength > MAX_FLOW_MODEL_VARIABLE_TOTAL_STRING_LENGTH) {
|
|
471
|
+
return { ok: false };
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
const prepared = typeof input === "string" && !options.isRunJsValuePath && isPersistedRunJsStringPath(pathTail) ? prepareRunJsCode(input, void 0, true) : input;
|
|
475
|
+
defineTraversalValue(parent, key, prepared);
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
478
|
+
if (seen.has(input)) return { ok: false };
|
|
479
|
+
seen.add(input);
|
|
480
|
+
const { descriptors, entries } = getEnumerableDataEntries(input);
|
|
481
|
+
for (const [entryKey] of entries) {
|
|
482
|
+
totalStringLength += entryKey.length;
|
|
483
|
+
if (entryKey.length > MAX_FLOW_MODEL_VARIABLE_STRING_LENGTH || totalStringLength > MAX_FLOW_MODEL_VARIABLE_TOTAL_STRING_LENGTH) {
|
|
484
|
+
return { ok: false };
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
const runJsPath = options.isRunJsValuePath ? options.isRunJsValuePath(pathTail) : frame.runJsValue || isPersistedRunJsPath(pathTail, frame.flowRegistry);
|
|
488
|
+
const runJs = !Array.isArray(input) && runJsPath ? readPersistedRunJsValue(entries) : void 0;
|
|
489
|
+
const output = createTraversalContainer(input, descriptors);
|
|
490
|
+
defineTraversalValue(parent, key, output);
|
|
491
|
+
if (runJs) {
|
|
492
|
+
scheduledNodes += entries.length;
|
|
493
|
+
totalStringLength += runJs.code.length + (((_a = runJs.version) == null ? void 0 : _a.length) || 0);
|
|
494
|
+
if (scheduledNodes > MAX_FLOW_MODEL_VARIABLE_SOURCE_NODES || runJs.code.length > MAX_FLOW_MODEL_VARIABLE_STRING_LENGTH || runJs.version != null && runJs.version.length > MAX_FLOW_MODEL_VARIABLE_STRING_LENGTH || totalStringLength > MAX_FLOW_MODEL_VARIABLE_TOTAL_STRING_LENGTH) {
|
|
495
|
+
return { ok: false };
|
|
496
|
+
}
|
|
497
|
+
const code = prepareRunJsCode(
|
|
498
|
+
runJs.code,
|
|
499
|
+
runJs.version,
|
|
500
|
+
!options.isRunJsValuePath && !RUNJS_PATH_SUFFIXES.has(pathTail.slice(-3).join("."))
|
|
501
|
+
);
|
|
502
|
+
for (const [entryKey, entryValue] of entries) {
|
|
503
|
+
defineTraversalValue(output, entryKey, entryKey === "code" ? code : entryValue);
|
|
504
|
+
}
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
507
|
+
if (entries.length && depth >= MAX_FLOW_MODEL_VARIABLE_SOURCE_DEPTH) return { ok: false };
|
|
508
|
+
scheduledNodes += entries.length;
|
|
509
|
+
if (scheduledNodes > MAX_FLOW_MODEL_VARIABLE_SOURCE_NODES) return { ok: false };
|
|
510
|
+
for (let index = entries.length - 1; index >= 0; index -= 1) {
|
|
511
|
+
const [entryKey, entryValue] = entries[index];
|
|
512
|
+
const nextPath = [...pathTail, entryKey];
|
|
513
|
+
stack.push({
|
|
514
|
+
depth: depth + 1,
|
|
515
|
+
input: entryValue,
|
|
516
|
+
key: entryKey,
|
|
517
|
+
parent: output,
|
|
518
|
+
pathTail: options.isRunJsValuePath ? nextPath : nextPath.slice(-12),
|
|
519
|
+
flowRegistry: entryKey === "stepParams" ? (_b = descriptors.flowRegistry) == null ? void 0 : _b.value : frame.flowRegistry,
|
|
520
|
+
runJsValue: entryKey === "defaultParams" && ((_c = descriptors.use) == null ? void 0 : _c.value) === "runjs"
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
supplementalScripts.forEach(extractRunJsDependencies);
|
|
525
|
+
return { ok: true, runJsTemplates: Array.from(templates), templateSource: root.value };
|
|
526
|
+
} catch {
|
|
527
|
+
return { ok: false };
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
function collectPersistedRunJsVariableTemplates(value) {
|
|
531
|
+
const prepared = prepareFlowModelVariableSource(value);
|
|
532
|
+
return prepared.ok ? Array.from(prepared.runJsTemplates) : [];
|
|
533
|
+
}
|
|
534
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
535
|
+
0 && (module.exports = {
|
|
536
|
+
MAX_FLOW_MODEL_VARIABLE_SOURCE_DEPTH,
|
|
537
|
+
MAX_FLOW_MODEL_VARIABLE_SOURCE_NODES,
|
|
538
|
+
MAX_FLOW_MODEL_VARIABLE_STRING_LENGTH,
|
|
539
|
+
MAX_FLOW_MODEL_VARIABLE_TOTAL_STRING_LENGTH,
|
|
540
|
+
collectPersistedRunJsVariableTemplates,
|
|
541
|
+
prepareFlowModelVariableSource
|
|
542
|
+
});
|
|
@@ -30,12 +30,15 @@ __export(selects_exports, {
|
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(selects_exports);
|
|
32
32
|
function adjustSelectsForCollection(koaCtx, dataSourceKey, collection, fields, appends) {
|
|
33
|
-
var _a, _b, _c, _d;
|
|
33
|
+
var _a, _b, _c, _d, _e;
|
|
34
34
|
const ds = koaCtx.app.dataSourceManager.get(dataSourceKey || "main");
|
|
35
35
|
const cm = ds.collectionManager;
|
|
36
36
|
const coll = (_b = (_a = cm == null ? void 0 : cm.db) == null ? void 0 : _a.getCollection) == null ? void 0 : _b.call(_a, collection);
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
if (!((_c = coll == null ? void 0 : coll.model) == null ? void 0 : _c.rawAttributes)) {
|
|
38
|
+
return { fields, appends };
|
|
39
|
+
}
|
|
40
|
+
const assocKeys = Object.keys(((_d = coll == null ? void 0 : coll.model) == null ? void 0 : _d.associations) || {});
|
|
41
|
+
const rawAttrs = ((_e = coll == null ? void 0 : coll.model) == null ? void 0 : _e.rawAttributes) || {};
|
|
39
42
|
const toCamel = (s) => s.replace(/_([a-zA-Z0-9])/g, (_m, c) => String(c).toUpperCase());
|
|
40
43
|
const toSnake = (s) => s.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/^_/, "");
|
|
41
44
|
const assocMap = /* @__PURE__ */ new Map();
|
|
@@ -7,11 +7,8 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
import type { ResourcerContext } from '@nocobase/resourcer';
|
|
10
|
-
import type {
|
|
10
|
+
import type { AuthorizedRecordBinding } from './record-bindings';
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Merge record selects for one resolve request and populate the request cache once per target.
|
|
13
13
|
*/
|
|
14
|
-
export declare function prefetchRecordsForResolve(koaCtx: ResourcerContext,
|
|
15
|
-
template: JSONValue;
|
|
16
|
-
contextParams?: Record<string, unknown>;
|
|
17
|
-
}>): Promise<void>;
|
|
14
|
+
export declare function prefetchRecordsForResolve(koaCtx: ResourcerContext, bindings: readonly AuthorizedRecordBinding[]): Promise<void>;
|