@nocobase/plugin-flow-engine 2.3.0-alpha.1 → 2.3.0-beta.3
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/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 +492 -0
- package/dist/server/variables/form-item-record-slot-resolvers.d.ts +10 -0
- package/dist/server/variables/form-item-record-slot-resolvers.js +280 -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 +407 -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
|
@@ -38,17 +38,21 @@ var contexts_exports = {};
|
|
|
38
38
|
__export(contexts_exports, {
|
|
39
39
|
GlobalContext: () => GlobalContext,
|
|
40
40
|
HttpRequestContext: () => HttpRequestContext,
|
|
41
|
+
SERVER_CONTEXT_PROVIDER_TOKEN: () => SERVER_CONTEXT_PROVIDER_TOKEN,
|
|
41
42
|
ServerBaseContext: () => ServerBaseContext
|
|
42
43
|
});
|
|
43
44
|
module.exports = __toCommonJS(contexts_exports);
|
|
44
45
|
var import_lodash = __toESM(require("lodash"));
|
|
45
|
-
|
|
46
|
+
var import_context_keys = require("./context-keys");
|
|
47
|
+
const SERVER_CONTEXT_PROVIDER_TOKEN = Symbol("server-context-provider");
|
|
48
|
+
const PROVIDER_KEYS = /* @__PURE__ */ new Set([...import_context_keys.GLOBAL_CONTEXT_KEYS, ...import_context_keys.HTTP_REQUEST_CONTEXT_KEYS]);
|
|
49
|
+
const INTERNAL_KEYS = new Set(import_context_keys.SERVER_CONTEXT_INTERNAL_KEYS);
|
|
50
|
+
const BLOCKED_SANDBOX_KEYS = /* @__PURE__ */ new Set([...import_context_keys.SERVER_CONTEXT_PROTOTYPE_KEYS, ...import_context_keys.SERVER_CONTEXT_INTERNAL_KEYS]);
|
|
46
51
|
function isBlockedSandboxKey(key) {
|
|
47
52
|
return BLOCKED_SANDBOX_KEYS.has(key);
|
|
48
53
|
}
|
|
49
54
|
class ServerBaseContext {
|
|
50
55
|
_props = {};
|
|
51
|
-
_methods = {};
|
|
52
56
|
_cache = {};
|
|
53
57
|
_delegates = [];
|
|
54
58
|
_proxy;
|
|
@@ -74,10 +78,14 @@ class ServerBaseContext {
|
|
|
74
78
|
* - get:惰性 getter(默认带缓存)
|
|
75
79
|
* - once:已存在时忽略重复定义
|
|
76
80
|
*/
|
|
77
|
-
defineProperty(key, options) {
|
|
81
|
+
defineProperty(key, options, providerToken) {
|
|
78
82
|
var _a;
|
|
79
|
-
if (
|
|
80
|
-
|
|
83
|
+
if (BLOCKED_SANDBOX_KEYS.has(key)) return;
|
|
84
|
+
if (PROVIDER_KEYS.has(key) && (this instanceof HttpRequestContext || this instanceof GlobalContext) && providerToken !== SERVER_CONTEXT_PROVIDER_TOKEN) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (((_a = this._props[key]) == null ? void 0 : _a.once) && providerToken !== SERVER_CONTEXT_PROVIDER_TOKEN) return;
|
|
88
|
+
this._props[key] = providerToken === SERVER_CONTEXT_PROVIDER_TOKEN ? { ...options, once: true } : options;
|
|
81
89
|
delete this._cache[key];
|
|
82
90
|
Object.defineProperty(this, key, {
|
|
83
91
|
configurable: true,
|
|
@@ -85,20 +93,9 @@ class ServerBaseContext {
|
|
|
85
93
|
get: () => this._getOwn(key, this.createProxy())
|
|
86
94
|
});
|
|
87
95
|
}
|
|
88
|
-
/** 定义一个方法(不可枚举、不可写),访问时会自动绑定到对应实例 */
|
|
89
|
-
defineMethod(name, fn) {
|
|
90
|
-
this._methods[name] = fn;
|
|
91
|
-
Object.defineProperty(this, name, {
|
|
92
|
-
configurable: true,
|
|
93
|
-
enumerable: false,
|
|
94
|
-
writable: false,
|
|
95
|
-
value: fn
|
|
96
|
-
// bind at proxy access to keep delegate binding consistent
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
96
|
/**
|
|
100
97
|
* 委托到另一个 ServerBaseContext:
|
|
101
|
-
* -
|
|
98
|
+
* - 访问属性找不到时,会回退到被委托者进行解析
|
|
102
99
|
*/
|
|
103
100
|
delegate(ctx) {
|
|
104
101
|
if (!(ctx instanceof ServerBaseContext)) {
|
|
@@ -115,9 +112,6 @@ class ServerBaseContext {
|
|
|
115
112
|
for (const key of Object.keys(this._props)) {
|
|
116
113
|
if (!isBlockedSandboxKey(key)) keys.add(key);
|
|
117
114
|
}
|
|
118
|
-
for (const key of Object.keys(this._methods)) {
|
|
119
|
-
if (!isBlockedSandboxKey(key)) keys.add(key);
|
|
120
|
-
}
|
|
121
115
|
for (const d of this._delegates) {
|
|
122
116
|
for (const key of d.getSandboxKeys()) {
|
|
123
117
|
if (!isBlockedSandboxKey(key)) keys.add(key);
|
|
@@ -130,10 +124,6 @@ class ServerBaseContext {
|
|
|
130
124
|
if (Object.prototype.hasOwnProperty.call(this._props, key)) {
|
|
131
125
|
return this._getOwn(key, current);
|
|
132
126
|
}
|
|
133
|
-
if (Object.prototype.hasOwnProperty.call(this._methods, key)) {
|
|
134
|
-
const fn = this._methods[key];
|
|
135
|
-
return typeof fn === "function" ? fn.bind(this) : fn;
|
|
136
|
-
}
|
|
137
127
|
for (const d of this._delegates) {
|
|
138
128
|
if (!d.getSandboxKeys().includes(key)) continue;
|
|
139
129
|
return d.getSandboxValue(key, current);
|
|
@@ -145,8 +135,11 @@ class ServerBaseContext {
|
|
|
145
135
|
if (this._proxy) return this._proxy;
|
|
146
136
|
this._proxy = new Proxy(this, {
|
|
147
137
|
get: (target, key, receiver) => {
|
|
148
|
-
var _a;
|
|
149
138
|
if (typeof key !== "string") return Reflect.get(target, key, receiver);
|
|
139
|
+
if (import_context_keys.SERVER_CONTEXT_PROTOTYPE_KEYS.includes(key)) {
|
|
140
|
+
return void 0;
|
|
141
|
+
}
|
|
142
|
+
if (INTERNAL_KEYS.has(key) && key.startsWith("_")) return void 0;
|
|
150
143
|
if (Reflect.has(target, key)) {
|
|
151
144
|
const v = Reflect.get(target, key, receiver);
|
|
152
145
|
return typeof v === "function" ? v.bind(target) : v;
|
|
@@ -154,28 +147,18 @@ class ServerBaseContext {
|
|
|
154
147
|
if (Object.prototype.hasOwnProperty.call(target._props, key)) {
|
|
155
148
|
return target._getOwn(key, this.createProxy());
|
|
156
149
|
}
|
|
157
|
-
if (Object.prototype.hasOwnProperty.call(target._methods, key)) {
|
|
158
|
-
const fn = target._methods[key];
|
|
159
|
-
return typeof fn === "function" ? fn.bind(target) : fn;
|
|
160
|
-
}
|
|
161
150
|
for (const d of target._delegates) {
|
|
162
|
-
const candidate =
|
|
151
|
+
const candidate = d.getSandboxValue(key, this.createProxy());
|
|
163
152
|
if (typeof candidate !== "undefined") return candidate;
|
|
164
|
-
if (Object.prototype.hasOwnProperty.call(d._methods || {}, key)) {
|
|
165
|
-
const fn = d._methods[key];
|
|
166
|
-
return typeof fn === "function" ? fn.bind(d) : fn;
|
|
167
|
-
}
|
|
168
153
|
}
|
|
169
154
|
return void 0;
|
|
170
155
|
},
|
|
171
156
|
has: (target, key) => {
|
|
172
157
|
if (typeof key !== "string") return Reflect.has(target, key);
|
|
158
|
+
if (isBlockedSandboxKey(key)) return false;
|
|
173
159
|
if (Reflect.has(target, key)) return true;
|
|
174
160
|
if (Object.prototype.hasOwnProperty.call(target._props, key)) return true;
|
|
175
|
-
|
|
176
|
-
return target._delegates.some(
|
|
177
|
-
(d) => Object.prototype.hasOwnProperty.call(d._props, key) || Object.prototype.hasOwnProperty.call(d._methods, key)
|
|
178
|
-
);
|
|
161
|
+
return target._delegates.some((d) => d.getSandboxKeys().includes(key));
|
|
179
162
|
}
|
|
180
163
|
});
|
|
181
164
|
return this._proxy;
|
|
@@ -184,9 +167,9 @@ class ServerBaseContext {
|
|
|
184
167
|
class GlobalContext extends ServerBaseContext {
|
|
185
168
|
constructor(env) {
|
|
186
169
|
super();
|
|
187
|
-
this.defineProperty("now", { get: () => (/* @__PURE__ */ new Date()).toISOString(), cache: false });
|
|
188
|
-
this.defineProperty("timestamp", { get: () => Date.now(), cache: false });
|
|
189
|
-
if (env) this.defineProperty("env", { value: filterEnv(env) });
|
|
170
|
+
this.defineProperty("now", { get: () => (/* @__PURE__ */ new Date()).toISOString(), cache: false }, SERVER_CONTEXT_PROVIDER_TOKEN);
|
|
171
|
+
this.defineProperty("timestamp", { get: () => Date.now(), cache: false }, SERVER_CONTEXT_PROVIDER_TOKEN);
|
|
172
|
+
if (env) this.defineProperty("env", { value: filterEnv(env) }, SERVER_CONTEXT_PROVIDER_TOKEN);
|
|
190
173
|
}
|
|
191
174
|
}
|
|
192
175
|
class HttpRequestContext extends ServerBaseContext {
|
|
@@ -194,16 +177,24 @@ class HttpRequestContext extends ServerBaseContext {
|
|
|
194
177
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
195
178
|
super();
|
|
196
179
|
this.koaCtx = koaCtx;
|
|
197
|
-
this.defineProperty(
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
this.defineProperty("
|
|
206
|
-
this.defineProperty("
|
|
180
|
+
this.defineProperty(
|
|
181
|
+
"user",
|
|
182
|
+
{ get: async () => {
|
|
183
|
+
var _a2, _b2;
|
|
184
|
+
return (_b2 = (_a2 = this.koaCtx) == null ? void 0 : _a2.auth) == null ? void 0 : _b2.user;
|
|
185
|
+
}, cache: true },
|
|
186
|
+
SERVER_CONTEXT_PROVIDER_TOKEN
|
|
187
|
+
);
|
|
188
|
+
this.defineProperty("roleName", { value: (_b = (_a = this.koaCtx) == null ? void 0 : _a.auth) == null ? void 0 : _b.role }, SERVER_CONTEXT_PROVIDER_TOKEN);
|
|
189
|
+
this.defineProperty("locale", { value: (_d = (_c = this.koaCtx) == null ? void 0 : _c.getCurrentLocale) == null ? void 0 : _d.call(_c) }, SERVER_CONTEXT_PROVIDER_TOKEN);
|
|
190
|
+
this.defineProperty(
|
|
191
|
+
"ip",
|
|
192
|
+
{ value: ((_f = (_e = this.koaCtx) == null ? void 0 : _e.state) == null ? void 0 : _f.clientIp) || ((_h = (_g = this.koaCtx) == null ? void 0 : _g.request) == null ? void 0 : _h.ip) },
|
|
193
|
+
SERVER_CONTEXT_PROVIDER_TOKEN
|
|
194
|
+
);
|
|
195
|
+
this.defineProperty("headers", { value: (_i = this.koaCtx) == null ? void 0 : _i.headers }, SERVER_CONTEXT_PROVIDER_TOKEN);
|
|
196
|
+
this.defineProperty("query", { value: (_k = (_j = this.koaCtx) == null ? void 0 : _j.request) == null ? void 0 : _k.query }, SERVER_CONTEXT_PROVIDER_TOKEN);
|
|
197
|
+
this.defineProperty("params", { value: import_lodash.default.get(this.koaCtx, "action.params") }, SERVER_CONTEXT_PROVIDER_TOKEN);
|
|
207
198
|
}
|
|
208
199
|
}
|
|
209
200
|
const DEFAULT_ENV_PREFIXES = ["PUBLIC_", "NEXT_PUBLIC_", "NCB_PUBLIC_"];
|
|
@@ -224,5 +215,6 @@ function filterEnv(env, allowedPrefixes = DEFAULT_ENV_PREFIXES) {
|
|
|
224
215
|
0 && (module.exports = {
|
|
225
216
|
GlobalContext,
|
|
226
217
|
HttpRequestContext,
|
|
218
|
+
SERVER_CONTEXT_PROVIDER_TOKEN,
|
|
227
219
|
ServerBaseContext
|
|
228
220
|
});
|
|
@@ -7,24 +7,16 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
import 'ses';
|
|
10
|
-
|
|
10
|
+
import { type AnalyzedTemplate, type ResolvePathPolicy } from './variable-expression';
|
|
11
|
+
export type JSONValue = string | number | boolean | null | {
|
|
11
12
|
[key: string]: JSONValue;
|
|
12
13
|
} | JSONValue[];
|
|
13
14
|
/**
|
|
14
15
|
* 解析 JSON 模板中形如 {{ ... }} 的占位符(服务端解析)。
|
|
15
|
-
* 仅支持以 ctx 开头的路径与表达式(如:{{ ctx.user.id }}、{{ ctx.record.roles[0].name }})。
|
|
16
16
|
* 无法解析或不受支持的表达式将原样保留。
|
|
17
|
-
*
|
|
18
|
-
* @param template 要解析的对象/数组/字符串模板
|
|
19
|
-
* @param ctx 变量上下文(实现了所需属性/方法的代理对象)
|
|
20
|
-
* @returns 解析后的结果,与输入结构相同
|
|
21
17
|
*/
|
|
22
|
-
export declare function resolveJsonTemplate(template: JSONValue, ctx:
|
|
18
|
+
export declare function resolveJsonTemplate(template: JSONValue, ctx: unknown): Promise<any>;
|
|
23
19
|
/**
|
|
24
|
-
*
|
|
25
|
-
* 例如:ctx.user.id + 1 => (await __get('user', '.id')) + 1
|
|
26
|
-
*
|
|
27
|
-
* @param expression 原始表达式字符串
|
|
28
|
-
* @returns 改写后的表达式字符串
|
|
20
|
+
* 执行已分析的模板。授权、挂载和执行链路应复用同一个 analysis 与 policy。
|
|
29
21
|
*/
|
|
30
|
-
export declare function
|
|
22
|
+
export declare function resolveAnalyzedJsonTemplate(analysis: AnalyzedTemplate, ctx: unknown, policy: ResolvePathPolicy): Promise<any>;
|