@nocobase/flow-engine 2.1.37 → 2.1.38
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/lib/flowContext.d.ts +4 -1
- package/lib/flowContext.js +8 -2
- package/lib/utils/params-resolvers.d.ts +1 -0
- package/lib/utils/params-resolvers.js +1 -0
- package/package.json +4 -4
- package/src/__tests__/objectVariable.test.ts +6 -1
- package/src/flowContext.ts +17 -3
- package/src/utils/params-resolvers.ts +2 -0
package/lib/flowContext.d.ts
CHANGED
|
@@ -27,6 +27,9 @@ import type { RecordRef } from './utils/serverContextParams';
|
|
|
27
27
|
import { FlowView, FlowViewer } from './views/FlowView';
|
|
28
28
|
import { type RunJSVersion } from './runjs-context/registry';
|
|
29
29
|
type Getter<T = any> = (ctx: FlowContext) => T | Promise<T>;
|
|
30
|
+
export type ResolveJsonTemplateOptions = {
|
|
31
|
+
contractModelUid?: string | number | null;
|
|
32
|
+
};
|
|
30
33
|
export type FlowContextDocRef = string | {
|
|
31
34
|
url: string;
|
|
32
35
|
title?: string;
|
|
@@ -344,7 +347,7 @@ declare class BaseFlowEngineContext extends FlowContext {
|
|
|
344
347
|
* @deprecated use `resolveJsonTemplate` instead
|
|
345
348
|
*/
|
|
346
349
|
renderJson: (template: JSONValue) => Promise<any>;
|
|
347
|
-
resolveJsonTemplate: (template: JSONValue) => Promise<any>;
|
|
350
|
+
resolveJsonTemplate: (template: JSONValue, options?: ResolveJsonTemplateOptions) => Promise<any>;
|
|
348
351
|
getVar: (path: string) => Promise<any>;
|
|
349
352
|
request: (options: RequestOptions) => Promise<any>;
|
|
350
353
|
runjs: (code: string, variables?: Record<string, any>, options?: JSRunnerOptions) => Promise<any>;
|
package/lib/flowContext.js
CHANGED
|
@@ -2383,7 +2383,7 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
|
|
|
2383
2383
|
this.defineMethod("renderJson", function(template) {
|
|
2384
2384
|
return this.resolveJsonTemplate(template);
|
|
2385
2385
|
});
|
|
2386
|
-
|
|
2386
|
+
const resolveJsonTemplate = /* @__PURE__ */ __name(async function(template, options) {
|
|
2387
2387
|
var _a, _b, _c;
|
|
2388
2388
|
const used = (0, import_utils.extractUsedVariablePaths)(template);
|
|
2389
2389
|
const usedVarNames = Object.keys(used || {});
|
|
@@ -2516,7 +2516,12 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
|
|
|
2516
2516
|
}
|
|
2517
2517
|
if (this.api) {
|
|
2518
2518
|
try {
|
|
2519
|
+
const contractRd = (0, import_params_resolvers.buildFlowModelResolveDescriptor)(
|
|
2520
|
+
this,
|
|
2521
|
+
options == null ? void 0 : options.contractModelUid
|
|
2522
|
+
);
|
|
2519
2523
|
serverResolved = await (0, import_params_resolvers.enqueueVariablesResolve)(this, {
|
|
2524
|
+
...contractRd ? { contractRd } : {},
|
|
2520
2525
|
rd: (0, import_params_resolvers.buildFlowModelResolveDescriptor)(this, (_a = this.model) == null ? void 0 : _a.uid),
|
|
2521
2526
|
template,
|
|
2522
2527
|
contextParams: autoContextParams || {}
|
|
@@ -2528,7 +2533,8 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
|
|
|
2528
2533
|
}
|
|
2529
2534
|
}
|
|
2530
2535
|
return (0, import_utils.resolveExpressions)(serverResolved, this);
|
|
2531
|
-
});
|
|
2536
|
+
}, "resolveJsonTemplate");
|
|
2537
|
+
this.defineMethod("resolveJsonTemplate", resolveJsonTemplate);
|
|
2532
2538
|
this.defineMethod(
|
|
2533
2539
|
"getVar",
|
|
2534
2540
|
async function(varPath) {
|
|
@@ -146,6 +146,7 @@ function enqueueVariablesResolve(ctx, payload) {
|
|
|
146
146
|
try {
|
|
147
147
|
const batch = items.map((it) => ({
|
|
148
148
|
id: it.id,
|
|
149
|
+
contractRd: it.payload.contractRd,
|
|
149
150
|
rd: it.payload.rd,
|
|
150
151
|
template: it.payload.template,
|
|
151
152
|
contextParams: it.payload.contextParams || {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/flow-engine",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.38",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A standalone flow engine for NocoBase, managing workflows, models, and actions.",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@formily/antd-v5": "1.x",
|
|
10
10
|
"@formily/reactive": "2.x",
|
|
11
|
-
"@nocobase/sdk": "2.1.
|
|
12
|
-
"@nocobase/shared": "2.1.
|
|
11
|
+
"@nocobase/sdk": "2.1.38",
|
|
12
|
+
"@nocobase/shared": "2.1.38",
|
|
13
13
|
"ahooks": "^3.7.2",
|
|
14
14
|
"axios": "^1.7.0",
|
|
15
15
|
"dayjs": "^1.11.9",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
],
|
|
38
38
|
"author": "NocoBase Team",
|
|
39
39
|
"license": "Apache-2.0",
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "cf73a1ede7f46029428d3ed143af2e5dc4f035e6"
|
|
41
41
|
}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { describe, expect, it, vi } from 'vitest';
|
|
11
|
+
import { generateFlowModelRdFromToken } from '@nocobase/utils/client';
|
|
11
12
|
import { FlowContext } from '../flowContext';
|
|
12
13
|
import { FlowEngine } from '../flowEngine';
|
|
13
14
|
import {
|
|
@@ -122,7 +123,10 @@ describe('objectVariable utilities', () => {
|
|
|
122
123
|
|
|
123
124
|
// Provide API stub to intercept variables:resolve
|
|
124
125
|
const calls: any[] = [];
|
|
126
|
+
const payload = Buffer.from(JSON.stringify({ userId: 1, signInTime: 'contract-owner-test' })).toString('base64url');
|
|
127
|
+
const token = `test.${payload}.sig`;
|
|
125
128
|
(ctx as any).api = {
|
|
129
|
+
auth: { token },
|
|
126
130
|
request: vi.fn(async ({ url, data, method }) => {
|
|
127
131
|
calls.push({ url, data, method });
|
|
128
132
|
const batch = (data?.values?.batch as any[]) || [];
|
|
@@ -146,13 +150,14 @@ describe('objectVariable utilities', () => {
|
|
|
146
150
|
});
|
|
147
151
|
|
|
148
152
|
const template = { x: '{{ ctx.obj.author.name }}' } as any;
|
|
149
|
-
await (ctx as any).resolveJsonTemplate(template);
|
|
153
|
+
await (ctx as any).resolveJsonTemplate(template, { contractModelUid: 'form-grid' });
|
|
150
154
|
|
|
151
155
|
// Assert variables:resolve was called with proper flattened contextParams
|
|
152
156
|
expect((ctx as any).api.request).toHaveBeenCalled();
|
|
153
157
|
const call = calls.find((c) => c.url === 'variables:resolve');
|
|
154
158
|
expect(call).toBeTruthy();
|
|
155
159
|
const batch0 = call.data?.values?.batch?.[0];
|
|
160
|
+
expect(batch0?.contractRd).toBe(generateFlowModelRdFromToken('form-grid', token));
|
|
156
161
|
expect(batch0?.contextParams).toBeTruthy();
|
|
157
162
|
// Flattened key should be 'obj.author'
|
|
158
163
|
const cp = batch0.contextParams as Record<string, any>;
|
package/src/flowContext.ts
CHANGED
|
@@ -165,6 +165,10 @@ function inferSelectsFromUsage(paths: string[] = []): { generatedAppends?: strin
|
|
|
165
165
|
|
|
166
166
|
type Getter<T = any> = (ctx: FlowContext) => T | Promise<T>;
|
|
167
167
|
|
|
168
|
+
export type ResolveJsonTemplateOptions = {
|
|
169
|
+
contractModelUid?: string | number | null;
|
|
170
|
+
};
|
|
171
|
+
|
|
168
172
|
export type FlowContextDocRef = string | { url: string; title?: string };
|
|
169
173
|
|
|
170
174
|
export type FlowDeprecationDoc =
|
|
@@ -3046,7 +3050,7 @@ class BaseFlowEngineContext extends FlowContext {
|
|
|
3046
3050
|
* @deprecated use `resolveJsonTemplate` instead
|
|
3047
3051
|
*/
|
|
3048
3052
|
declare renderJson: (template: JSONValue) => Promise<any>;
|
|
3049
|
-
declare resolveJsonTemplate: (template: JSONValue) => Promise<any>;
|
|
3053
|
+
declare resolveJsonTemplate: (template: JSONValue, options?: ResolveJsonTemplateOptions) => Promise<any>;
|
|
3050
3054
|
declare getVar: (path: string) => Promise<any>;
|
|
3051
3055
|
declare request: (options: RequestOptions) => Promise<any>;
|
|
3052
3056
|
declare runjs: (code: string, variables?: Record<string, any>, options?: JSRunnerOptions) => Promise<any>;
|
|
@@ -3229,7 +3233,11 @@ export class FlowEngineContext extends BaseFlowEngineContext {
|
|
|
3229
3233
|
this.defineMethod('renderJson', function (template: any) {
|
|
3230
3234
|
return this.resolveJsonTemplate(template);
|
|
3231
3235
|
});
|
|
3232
|
-
|
|
3236
|
+
const resolveJsonTemplate = async function (
|
|
3237
|
+
this: BaseFlowEngineContext,
|
|
3238
|
+
template: any,
|
|
3239
|
+
options?: ResolveJsonTemplateOptions,
|
|
3240
|
+
) {
|
|
3233
3241
|
// 提取模板使用到的变量及其子路径
|
|
3234
3242
|
const used = extractUsedVariablePaths(template);
|
|
3235
3243
|
const usedVarNames = Object.keys(used || {});
|
|
@@ -3398,7 +3406,12 @@ export class FlowEngineContext extends BaseFlowEngineContext {
|
|
|
3398
3406
|
|
|
3399
3407
|
if (this.api) {
|
|
3400
3408
|
try {
|
|
3409
|
+
const contractRd = buildFlowModelResolveDescriptor(
|
|
3410
|
+
this as FlowRuntimeContext<FlowModel>,
|
|
3411
|
+
options?.contractModelUid,
|
|
3412
|
+
);
|
|
3401
3413
|
serverResolved = await enqueueVariablesResolve(this as FlowRuntimeContext<FlowModel>, {
|
|
3414
|
+
...(contractRd ? { contractRd } : {}),
|
|
3402
3415
|
rd: buildFlowModelResolveDescriptor(this as FlowRuntimeContext<FlowModel>, this.model?.uid),
|
|
3403
3416
|
template,
|
|
3404
3417
|
contextParams: autoContextParams || {},
|
|
@@ -3411,7 +3424,8 @@ export class FlowEngineContext extends BaseFlowEngineContext {
|
|
|
3411
3424
|
}
|
|
3412
3425
|
|
|
3413
3426
|
return resolveExpressions(serverResolved, this);
|
|
3414
|
-
}
|
|
3427
|
+
};
|
|
3428
|
+
this.defineMethod('resolveJsonTemplate', resolveJsonTemplate);
|
|
3415
3429
|
|
|
3416
3430
|
// Helper: resolve a single ctx expression value via resolveJsonTemplate behavior.
|
|
3417
3431
|
// Example: await ctx.getVar('ctx.record.id')
|
|
@@ -79,6 +79,7 @@ export type JSONValue = string | { [key: string]: JSONValue } | JSONValue[];
|
|
|
79
79
|
// =========================
|
|
80
80
|
|
|
81
81
|
type BatchPayload = {
|
|
82
|
+
contractRd?: string;
|
|
82
83
|
rd?: string;
|
|
83
84
|
template: JSONValue;
|
|
84
85
|
contextParams?: ServerContextParams | undefined;
|
|
@@ -172,6 +173,7 @@ export function enqueueVariablesResolve(ctx: FlowRuntimeContext, payload: BatchP
|
|
|
172
173
|
try {
|
|
173
174
|
const batch = items.map((it) => ({
|
|
174
175
|
id: it.id,
|
|
176
|
+
contractRd: it.payload.contractRd,
|
|
175
177
|
rd: it.payload.rd,
|
|
176
178
|
template: it.payload.template,
|
|
177
179
|
contextParams: it.payload.contextParams || {},
|