@nocobase/flow-engine 2.1.0-alpha.1 → 2.1.0-alpha.11
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/LICENSE +201 -661
- package/README.md +79 -10
- package/lib/BlockScopedFlowEngine.js +0 -1
- package/lib/FlowDefinition.d.ts +6 -0
- package/lib/FlowSchemaRegistry.d.ts +154 -0
- package/lib/FlowSchemaRegistry.js +1427 -0
- package/lib/JSRunner.d.ts +15 -0
- package/lib/JSRunner.js +82 -7
- package/lib/ViewScopedFlowEngine.js +8 -1
- package/lib/acl/Acl.js +13 -3
- package/lib/components/FlowContextSelector.js +155 -10
- package/lib/components/MobilePopup.js +6 -5
- package/lib/components/dnd/gridDragPlanner.d.ts +1 -0
- package/lib/components/dnd/gridDragPlanner.js +59 -3
- package/lib/components/settings/wrappers/component/SwitchWithTitle.js +2 -1
- package/lib/components/settings/wrappers/contextual/DefaultSettingsIcon.js +76 -15
- package/lib/components/settings/wrappers/contextual/FlowsContextMenu.js +24 -4
- package/lib/components/settings/wrappers/contextual/StepSettingsDialog.js +21 -3
- package/lib/components/subModel/AddSubModelButton.js +27 -1
- package/lib/components/subModel/utils.js +2 -2
- package/lib/components/variables/VariableInput.js +9 -4
- package/lib/components/variables/VariableTag.js +46 -39
- package/lib/components/variables/utils.d.ts +7 -0
- package/lib/components/variables/utils.js +42 -2
- package/lib/data-source/index.d.ts +7 -27
- package/lib/data-source/index.js +84 -51
- package/lib/executor/FlowExecutor.d.ts +2 -1
- package/lib/executor/FlowExecutor.js +190 -26
- package/lib/flow-schema-registry/fieldBinding.d.ts +32 -0
- package/lib/flow-schema-registry/fieldBinding.js +165 -0
- package/lib/flow-schema-registry/modelPatches.d.ts +16 -0
- package/lib/flow-schema-registry/modelPatches.js +235 -0
- package/lib/flow-schema-registry/schemaInference.d.ts +17 -0
- package/lib/flow-schema-registry/schemaInference.js +207 -0
- package/lib/flow-schema-registry/utils.d.ts +25 -0
- package/lib/flow-schema-registry/utils.js +293 -0
- package/lib/flowContext.d.ts +230 -7
- package/lib/flowContext.js +2270 -148
- package/lib/flowEngine.d.ts +160 -1
- package/lib/flowEngine.js +387 -27
- package/lib/flowI18n.js +6 -4
- package/lib/flowSettings.d.ts +14 -6
- package/lib/flowSettings.js +51 -17
- package/lib/index.d.ts +8 -1
- package/lib/index.js +24 -1
- package/lib/lazy-helper.d.ts +14 -0
- package/lib/lazy-helper.js +71 -0
- package/lib/locale/en-US.json +9 -2
- package/lib/locale/index.d.ts +14 -0
- package/lib/locale/zh-CN.json +8 -1
- package/lib/models/CollectionFieldModel.d.ts +1 -0
- package/lib/models/CollectionFieldModel.js +3 -2
- package/lib/models/DisplayItemModel.d.ts +1 -1
- package/lib/models/EditableItemModel.d.ts +1 -1
- package/lib/models/FilterableItemModel.d.ts +1 -1
- package/lib/models/flowModel.d.ts +7 -0
- package/lib/models/flowModel.js +83 -8
- package/lib/provider.js +7 -6
- package/lib/resources/baseRecordResource.d.ts +5 -0
- package/lib/resources/baseRecordResource.js +24 -0
- package/lib/resources/multiRecordResource.d.ts +1 -0
- package/lib/resources/multiRecordResource.js +11 -4
- package/lib/resources/singleRecordResource.js +2 -0
- package/lib/resources/sqlResource.d.ts +4 -3
- package/lib/resources/sqlResource.js +8 -3
- package/lib/runjs-context/contexts/FormJSFieldItemRunJSContext.js +12 -2
- package/lib/runjs-context/contexts/JSBlockRunJSContext.js +2 -2
- package/lib/runjs-context/contexts/JSEditableFieldRunJSContext.d.ts +16 -0
- package/lib/runjs-context/contexts/JSEditableFieldRunJSContext.js +125 -0
- package/lib/runjs-context/contexts/JSItemRunJSContext.js +12 -2
- package/lib/runjs-context/contexts/base.js +706 -41
- package/lib/runjs-context/contributions.d.ts +33 -0
- package/lib/runjs-context/contributions.js +88 -0
- package/lib/runjs-context/helpers.js +12 -1
- package/lib/runjs-context/registry.d.ts +1 -1
- package/lib/runjs-context/setup.js +23 -9
- package/lib/runjs-context/snippets/global/api-request.snippet.js +3 -3
- package/lib/runjs-context/snippets/global/import-esm.snippet.js +2 -3
- package/lib/runjs-context/snippets/global/query-selector.snippet.js +8 -3
- package/lib/runjs-context/snippets/global/require-amd.snippet.js +1 -1
- package/lib/runjs-context/snippets/index.d.ts +11 -1
- package/lib/runjs-context/snippets/index.js +61 -40
- package/lib/runjs-context/snippets/scene/block/add-event-listener.snippet.js +10 -7
- package/lib/runjs-context/snippets/scene/block/api-fetch-render-list.snippet.js +3 -3
- package/lib/runjs-context/snippets/scene/block/chartjs-bar.snippet.js +2 -2
- package/lib/runjs-context/snippets/scene/block/echarts-init.snippet.js +2 -2
- package/lib/runjs-context/snippets/scene/block/render-iframe.snippet.js +2 -2
- package/lib/runjs-context/snippets/scene/block/render-react.snippet.js +1 -1
- package/lib/runjs-context/snippets/scene/block/render-statistics.snippet.js +1 -1
- package/lib/runjs-context/snippets/scene/block/render-timeline.snippet.js +1 -1
- package/lib/runjs-context/snippets/scene/block/resource-example.snippet.js +5 -5
- package/lib/runjs-context/snippets/scene/block/three-users-orbit.snippet.js +6 -6
- package/lib/runjs-context/snippets/scene/block/vue-component.snippet.js +3 -4
- package/lib/runjs-context/snippets/scene/detail/color-by-value.snippet.js +1 -1
- package/lib/runjs-context/snippets/scene/detail/copy-to-clipboard.snippet.js +20 -3
- package/lib/runjs-context/snippets/scene/detail/format-number.snippet.js +1 -1
- package/lib/runjs-context/snippets/scene/detail/innerHTML-value.snippet.js +1 -1
- package/lib/runjs-context/snippets/scene/detail/percentage-bar.snippet.js +3 -3
- package/lib/runjs-context/snippets/scene/detail/relative-time.snippet.js +3 -3
- package/lib/runjs-context/snippets/scene/detail/status-tag.snippet.js +2 -2
- package/lib/runjs-context/snippets/scene/form/cascade-select.snippet.js +1 -1
- package/lib/runjs-context/snippets/scene/form/render-basic.snippet.js +2 -2
- package/lib/runjs-context/snippets/scene/table/cell-open-dialog.snippet.js +6 -3
- package/lib/runjs-context/snippets/scene/table/concat-fields.snippet.js +3 -1
- package/lib/runjsLibs.d.ts +28 -0
- package/lib/runjsLibs.js +532 -0
- package/lib/scheduler/ModelOperationScheduler.d.ts +7 -1
- package/lib/scheduler/ModelOperationScheduler.js +28 -23
- package/lib/server.d.ts +10 -0
- package/lib/server.js +32 -0
- package/lib/types.d.ts +296 -1
- package/lib/utils/associationObjectVariable.d.ts +2 -2
- package/lib/utils/createCollectionContextMeta.js +1 -0
- package/lib/utils/createEphemeralContext.js +2 -2
- package/lib/utils/dateVariable.d.ts +16 -0
- package/lib/utils/dateVariable.js +380 -0
- package/lib/utils/exceptions.d.ts +7 -0
- package/lib/utils/exceptions.js +10 -0
- package/lib/utils/index.d.ts +8 -3
- package/lib/utils/index.js +49 -0
- package/lib/utils/params-resolvers.js +16 -9
- package/lib/utils/parsePathnameToViewParams.js +1 -1
- package/lib/utils/resolveModuleUrl.d.ts +58 -0
- package/lib/utils/resolveModuleUrl.js +65 -0
- package/lib/utils/resolveRunJSObjectValues.d.ts +16 -0
- package/lib/utils/resolveRunJSObjectValues.js +61 -0
- package/lib/utils/runjsModuleLoader.d.ts +58 -0
- package/lib/utils/runjsModuleLoader.js +422 -0
- package/lib/utils/runjsTemplateCompat.d.ts +35 -0
- package/lib/utils/runjsTemplateCompat.js +743 -0
- package/lib/utils/runjsValue.d.ts +29 -0
- package/lib/utils/runjsValue.js +275 -0
- package/lib/utils/safeGlobals.d.ts +18 -8
- package/lib/utils/safeGlobals.js +164 -17
- package/lib/utils/schema-utils.d.ts +17 -1
- package/lib/utils/schema-utils.js +80 -0
- package/lib/views/FlowView.d.ts +7 -1
- package/lib/views/createViewMeta.d.ts +0 -7
- package/lib/views/createViewMeta.js +19 -70
- package/lib/views/index.d.ts +1 -2
- package/lib/views/index.js +4 -3
- package/lib/views/runViewBeforeClose.d.ts +10 -0
- package/lib/views/runViewBeforeClose.js +45 -0
- package/lib/views/useDialog.d.ts +2 -1
- package/lib/views/useDialog.js +28 -6
- package/lib/views/useDrawer.d.ts +2 -1
- package/lib/views/useDrawer.js +27 -5
- package/lib/views/usePage.d.ts +6 -1
- package/lib/views/usePage.js +53 -9
- package/lib/views/usePopover.js +4 -1
- package/lib/views/viewEvents.d.ts +17 -0
- package/lib/views/viewEvents.js +90 -0
- package/package.json +5 -5
- package/server.d.ts +1 -0
- package/server.js +1 -0
- package/src/BlockScopedFlowEngine.ts +2 -5
- package/src/FlowSchemaRegistry.ts +1799 -0
- package/src/JSRunner.ts +111 -5
- package/src/ViewScopedFlowEngine.ts +8 -0
- package/src/__tests__/FlowSchemaRegistry.test.ts +1951 -0
- package/src/__tests__/JSRunner.test.ts +91 -1
- package/src/__tests__/createViewMeta.popup.test.ts +62 -1
- package/src/__tests__/flow-engine.test.ts +48 -0
- package/src/__tests__/flowContext.test.ts +693 -1
- package/src/__tests__/flowEngine.dataSourceDirty.test.ts +63 -0
- package/src/__tests__/flowEngine.modelLoaders.test.ts +249 -0
- package/src/__tests__/flowEngine.saveModel.test.ts +4 -0
- package/src/__tests__/flowModel.openView.navigation.test.ts +28 -0
- package/src/__tests__/flowRunJSContextDefine.test.ts +63 -0
- package/src/__tests__/flowRuntimeContext.test.ts +2 -1
- package/src/__tests__/flowSettings.open.test.tsx +123 -19
- package/src/__tests__/flowSettings.test.ts +94 -15
- package/src/__tests__/provider.test.tsx +0 -5
- package/src/__tests__/renderHiddenInConfig.test.tsx +6 -6
- package/src/__tests__/runjsContext.test.ts +26 -7
- package/src/__tests__/runjsContextImplementations.test.ts +34 -3
- package/src/__tests__/runjsContextRuntime.test.ts +5 -3
- package/src/__tests__/runjsContributions.test.ts +89 -0
- package/src/__tests__/runjsExternalLibs.test.ts +242 -0
- package/src/__tests__/runjsLibsLazyLoading.test.ts +44 -0
- package/src/__tests__/runjsLocales.test.ts +4 -1
- package/src/__tests__/runjsPreprocessDefault.test.ts +72 -0
- package/src/__tests__/runjsRuntimeFeatures.test.ts +166 -0
- package/src/__tests__/runjsSnippets.test.ts +40 -3
- package/src/__tests__/viewScopedFlowEngine.test.ts +3 -3
- package/src/acl/Acl.tsx +3 -3
- package/src/components/FlowContextSelector.tsx +208 -12
- package/src/components/MobilePopup.tsx +4 -2
- package/src/components/__tests__/flow-model-render-error-fallback.test.tsx +3 -3
- package/src/components/__tests__/gridDragPlanner.test.ts +229 -1
- package/src/components/dnd/gridDragPlanner.ts +68 -2
- package/src/components/settings/wrappers/component/SwitchWithTitle.tsx +2 -1
- package/src/components/settings/wrappers/component/__tests__/InlineControls.test.tsx +74 -0
- package/src/components/settings/wrappers/contextual/DefaultSettingsIcon.tsx +109 -16
- package/src/components/settings/wrappers/contextual/FlowsContextMenu.tsx +41 -7
- package/src/components/settings/wrappers/contextual/StepSettingsDialog.tsx +31 -4
- package/src/components/settings/wrappers/contextual/__tests__/DefaultSettingsIcon.test.tsx +157 -5
- package/src/components/subModel/AddSubModelButton.tsx +32 -2
- package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +143 -32
- package/src/components/subModel/utils.ts +1 -1
- package/src/components/variables/VariableInput.tsx +12 -4
- package/src/components/variables/VariableTag.tsx +54 -45
- package/src/components/variables/__tests__/FlowContextSelector.test.tsx +260 -3
- package/src/components/variables/__tests__/VariableTag.test.tsx +50 -0
- package/src/components/variables/__tests__/utils.test.ts +81 -3
- package/src/components/variables/utils.ts +67 -6
- package/src/data-source/index.ts +88 -110
- package/src/executor/FlowExecutor.ts +230 -28
- package/src/executor/__tests__/flowExecutor.test.ts +123 -0
- package/src/flow-schema-registry/fieldBinding.ts +171 -0
- package/src/flow-schema-registry/modelPatches.ts +260 -0
- package/src/flow-schema-registry/schemaInference.ts +210 -0
- package/src/flow-schema-registry/utils.ts +268 -0
- package/src/flowContext.ts +2989 -212
- package/src/flowEngine.ts +434 -23
- package/src/flowI18n.ts +7 -5
- package/src/flowSettings.ts +58 -18
- package/src/index.ts +15 -1
- package/src/lazy-helper.tsx +57 -0
- package/src/locale/en-US.json +9 -2
- package/src/locale/zh-CN.json +8 -1
- package/src/models/CollectionFieldModel.tsx +3 -1
- package/src/models/DisplayItemModel.tsx +1 -1
- package/src/models/EditableItemModel.tsx +1 -1
- package/src/models/FilterableItemModel.tsx +1 -1
- package/src/models/__tests__/dispatchEvent.when.test.ts +768 -0
- package/src/models/__tests__/flowModel.clone.test.ts +416 -0
- package/src/models/__tests__/flowModel.test.ts +20 -4
- package/src/models/flowModel.tsx +112 -7
- package/src/provider.tsx +9 -7
- package/src/resources/__tests__/multiRecordResource.test.ts +44 -0
- package/src/resources/__tests__/sqlResource.test.ts +60 -0
- package/src/resources/baseRecordResource.ts +31 -0
- package/src/resources/multiRecordResource.ts +11 -4
- package/src/resources/singleRecordResource.ts +3 -0
- package/src/resources/sqlResource.ts +11 -6
- package/src/runjs-context/contexts/FormJSFieldItemRunJSContext.ts +10 -0
- package/src/runjs-context/contexts/JSBlockRunJSContext.ts +6 -2
- package/src/runjs-context/contexts/JSEditableFieldRunJSContext.ts +106 -0
- package/src/runjs-context/contexts/JSItemRunJSContext.ts +10 -0
- package/src/runjs-context/contexts/base.ts +715 -44
- package/src/runjs-context/contributions.ts +88 -0
- package/src/runjs-context/helpers.ts +11 -1
- package/src/runjs-context/registry.ts +1 -1
- package/src/runjs-context/setup.ts +25 -9
- package/src/runjs-context/snippets/global/api-request.snippet.ts +3 -3
- package/src/runjs-context/snippets/global/import-esm.snippet.ts +2 -3
- package/src/runjs-context/snippets/global/query-selector.snippet.ts +8 -3
- package/src/runjs-context/snippets/global/require-amd.snippet.ts +1 -1
- package/src/runjs-context/snippets/index.ts +75 -41
- package/src/runjs-context/snippets/scene/block/add-event-listener.snippet.ts +11 -13
- package/src/runjs-context/snippets/scene/block/api-fetch-render-list.snippet.ts +3 -3
- package/src/runjs-context/snippets/scene/block/chartjs-bar.snippet.ts +2 -2
- package/src/runjs-context/snippets/scene/block/echarts-init.snippet.ts +2 -2
- package/src/runjs-context/snippets/scene/block/render-iframe.snippet.ts +2 -2
- package/src/runjs-context/snippets/scene/block/render-react.snippet.ts +1 -1
- package/src/runjs-context/snippets/scene/block/render-statistics.snippet.ts +1 -1
- package/src/runjs-context/snippets/scene/block/render-timeline.snippet.ts +1 -1
- package/src/runjs-context/snippets/scene/block/resource-example.snippet.ts +6 -11
- package/src/runjs-context/snippets/scene/block/three-users-orbit.snippet.ts +6 -6
- package/src/runjs-context/snippets/scene/block/vue-component.snippet.ts +3 -4
- package/src/runjs-context/snippets/scene/detail/color-by-value.snippet.ts +1 -1
- package/src/runjs-context/snippets/scene/detail/copy-to-clipboard.snippet.ts +20 -3
- package/src/runjs-context/snippets/scene/detail/format-number.snippet.ts +1 -1
- package/src/runjs-context/snippets/scene/detail/innerHTML-value.snippet.ts +1 -1
- package/src/runjs-context/snippets/scene/detail/percentage-bar.snippet.ts +3 -3
- package/src/runjs-context/snippets/scene/detail/relative-time.snippet.ts +3 -3
- package/src/runjs-context/snippets/scene/detail/status-tag.snippet.ts +2 -2
- package/src/runjs-context/snippets/scene/form/cascade-select.snippet.ts +1 -1
- package/src/runjs-context/snippets/scene/form/render-basic.snippet.ts +3 -8
- package/src/runjs-context/snippets/scene/table/cell-open-dialog.snippet.ts +6 -3
- package/src/runjs-context/snippets/scene/table/concat-fields.snippet.ts +3 -1
- package/src/runjsLibs.ts +622 -0
- package/src/scheduler/ModelOperationScheduler.ts +41 -24
- package/src/server.ts +11 -0
- package/src/types.ts +359 -1
- package/src/utils/__tests__/dateVariable.test.ts +101 -0
- package/src/utils/__tests__/params-resolvers.test.ts +40 -0
- package/src/utils/__tests__/parsePathnameToViewParams.test.ts +7 -0
- package/src/utils/__tests__/runjsRequireAsyncAutoWhitelist.test.ts +38 -0
- package/src/utils/__tests__/runjsTemplateCompat.test.ts +159 -0
- package/src/utils/__tests__/runjsValue.test.ts +44 -0
- package/src/utils/__tests__/safeGlobals.test.ts +57 -2
- package/src/utils/__tests__/utils.test.ts +157 -0
- package/src/utils/associationObjectVariable.ts +2 -2
- package/src/utils/createCollectionContextMeta.ts +1 -0
- package/src/utils/createEphemeralContext.ts +5 -4
- package/src/utils/dateVariable.ts +397 -0
- package/src/utils/exceptions.ts +11 -0
- package/src/utils/index.ts +38 -3
- package/src/utils/params-resolvers.ts +23 -9
- package/src/utils/parsePathnameToViewParams.ts +2 -2
- package/src/utils/resolveModuleUrl.ts +91 -0
- package/src/utils/resolveRunJSObjectValues.ts +46 -0
- package/src/utils/runjsModuleLoader.ts +553 -0
- package/src/utils/runjsTemplateCompat.ts +828 -0
- package/src/utils/runjsValue.ts +287 -0
- package/src/utils/safeGlobals.ts +188 -17
- package/src/utils/schema-utils.ts +109 -1
- package/src/views/FlowView.tsx +11 -1
- package/src/views/__tests__/FlowView.usePage.test.tsx +54 -1
- package/src/views/__tests__/runViewBeforeClose.test.ts +30 -0
- package/src/views/__tests__/useDialog.closeDestroy.test.tsx +44 -16
- package/src/views/__tests__/viewEvents.resolveOpenerEngine.test.ts +28 -0
- package/src/views/createViewMeta.ts +22 -75
- package/src/views/index.tsx +1 -2
- package/src/views/runViewBeforeClose.ts +19 -0
- package/src/views/useDialog.tsx +34 -5
- package/src/views/useDrawer.tsx +33 -4
- package/src/views/usePage.tsx +63 -8
- package/src/views/usePopover.tsx +4 -1
- package/src/views/viewEvents.ts +55 -0
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
11
|
-
import { JSRunner } from '../JSRunner';
|
|
11
|
+
import { JSRunner, shouldPreprocessRunJSTemplates } from '../JSRunner';
|
|
12
|
+
import { createSafeWindow } from '../utils';
|
|
12
13
|
|
|
13
14
|
describe('JSRunner', () => {
|
|
14
15
|
let originalSearch: string;
|
|
@@ -29,6 +30,18 @@ describe('JSRunner', () => {
|
|
|
29
30
|
vi.restoreAllMocks();
|
|
30
31
|
});
|
|
31
32
|
|
|
33
|
+
it('shouldPreprocessRunJSTemplates: explicit option has highest priority', () => {
|
|
34
|
+
expect(shouldPreprocessRunJSTemplates({ version: 'v2', preprocessTemplates: true })).toBe(true);
|
|
35
|
+
expect(shouldPreprocessRunJSTemplates({ version: 'v1', preprocessTemplates: false })).toBe(false);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('shouldPreprocessRunJSTemplates: falls back to version policy', () => {
|
|
39
|
+
expect(shouldPreprocessRunJSTemplates({ version: 'v1' })).toBe(true);
|
|
40
|
+
expect(shouldPreprocessRunJSTemplates({ version: 'v2' })).toBe(false);
|
|
41
|
+
expect(shouldPreprocessRunJSTemplates({})).toBe(true);
|
|
42
|
+
expect(shouldPreprocessRunJSTemplates()).toBe(true);
|
|
43
|
+
});
|
|
44
|
+
|
|
32
45
|
it('executes simple code and returns value', async () => {
|
|
33
46
|
const runner = new JSRunner();
|
|
34
47
|
const result = await runner.run('return 1 + 2 + 3');
|
|
@@ -48,6 +61,69 @@ describe('JSRunner', () => {
|
|
|
48
61
|
expect(res2.value).toBe('baz');
|
|
49
62
|
});
|
|
50
63
|
|
|
64
|
+
it('auto-lifts Blob from injected window to top-level globals', async () => {
|
|
65
|
+
if (typeof Blob === 'undefined') {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const runner = new JSRunner({
|
|
70
|
+
globals: {
|
|
71
|
+
window: createSafeWindow(),
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const result = await runner.run('return new Blob(["x"]).size');
|
|
76
|
+
expect(result.success).toBe(true);
|
|
77
|
+
expect(result.value).toBe(1);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('keeps explicit globals.Blob higher priority than auto-lifted Blob', async () => {
|
|
81
|
+
const explicitBlob = function ExplicitBlob(this: any, chunks: any[]) {
|
|
82
|
+
this.size = Array.isArray(chunks) ? chunks.length : 0;
|
|
83
|
+
} as any;
|
|
84
|
+
|
|
85
|
+
const runner = new JSRunner({
|
|
86
|
+
globals: {
|
|
87
|
+
window: createSafeWindow(),
|
|
88
|
+
Blob: explicitBlob,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const result = await runner.run('const b = new Blob([1,2,3]); return b.size;');
|
|
93
|
+
expect(result.success).toBe(true);
|
|
94
|
+
expect(result.value).toBe(3);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('auto-lifts URL from injected window to top-level globals', async () => {
|
|
98
|
+
const runner = new JSRunner({
|
|
99
|
+
globals: {
|
|
100
|
+
window: createSafeWindow(),
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const result = await runner.run('return typeof URL.createObjectURL === "function"');
|
|
105
|
+
expect(result.success).toBe(true);
|
|
106
|
+
expect(result.value).toBe(true);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('keeps explicit globals.URL higher priority than auto-lifted URL', async () => {
|
|
110
|
+
const explicitURL = {
|
|
111
|
+
createObjectURL: () => 'explicit://url',
|
|
112
|
+
revokeObjectURL: (_url: string) => undefined,
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const runner = new JSRunner({
|
|
116
|
+
globals: {
|
|
117
|
+
window: createSafeWindow(),
|
|
118
|
+
URL: explicitURL,
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const result = await runner.run('return URL.createObjectURL(new Blob(["x"]))');
|
|
123
|
+
expect(result.success).toBe(true);
|
|
124
|
+
expect(result.value).toBe('explicit://url');
|
|
125
|
+
});
|
|
126
|
+
|
|
51
127
|
it('exposes console in sandbox by default', async () => {
|
|
52
128
|
const runner = new JSRunner();
|
|
53
129
|
const result = await runner.run('return typeof console !== "undefined"');
|
|
@@ -88,6 +164,20 @@ describe('JSRunner', () => {
|
|
|
88
164
|
expect((result.error as Error).message).toBe('Execution timed out');
|
|
89
165
|
});
|
|
90
166
|
|
|
167
|
+
it('returns friendly hint when bare {{ctx.xxx}} appears in syntax error', async () => {
|
|
168
|
+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
169
|
+
const runner = new JSRunner();
|
|
170
|
+
const result = await runner.run('const z = {{ctx.user.id}}');
|
|
171
|
+
expect(result.success).toBe(false);
|
|
172
|
+
expect(result.error).toBeInstanceOf(SyntaxError);
|
|
173
|
+
const msg = String((result.error as any)?.message || '');
|
|
174
|
+
expect(msg).toContain('"{{ctx.user.id}}" has been deprecated');
|
|
175
|
+
expect(msg).toContain('await ctx.getVar("ctx.user.id")');
|
|
176
|
+
expect(msg).not.toContain('(at ');
|
|
177
|
+
expect((result.error as any)?.__runjsHideLocation).toBe(true);
|
|
178
|
+
expect(spy).toHaveBeenCalled();
|
|
179
|
+
});
|
|
180
|
+
|
|
91
181
|
it('skips execution when URL contains skipRunJs=true', async () => {
|
|
92
182
|
// 模拟预览模式下通过 URL 参数跳过代码执行
|
|
93
183
|
if (typeof window !== 'undefined' && typeof window.history?.pushState === 'function') {
|
|
@@ -13,7 +13,7 @@ import { FlowEngine } from '../flowEngine';
|
|
|
13
13
|
import type { FlowView } from '../views/FlowView';
|
|
14
14
|
import { createPopupMeta } from '../views/createViewMeta';
|
|
15
15
|
|
|
16
|
-
describe('
|
|
16
|
+
describe('createPopupMeta - popup variables', () => {
|
|
17
17
|
function makeCtx() {
|
|
18
18
|
const engine = new FlowEngine();
|
|
19
19
|
const ctx = new FlowContext();
|
|
@@ -139,4 +139,65 @@ describe('createViewMeta - popup variables', () => {
|
|
|
139
139
|
expect((props.record as any).title).toBe('Current popup record');
|
|
140
140
|
expect((props.record as any).hasChildren).toBe(true);
|
|
141
141
|
});
|
|
142
|
+
|
|
143
|
+
it('treats views with openerUids as popup (meta visible)', async () => {
|
|
144
|
+
const { ctx } = makeCtx();
|
|
145
|
+
|
|
146
|
+
// openerUids 作为路由栈缺失时的兜底标记:即使没有 navigation.viewStack,也应展示 ctx.popup 元信息
|
|
147
|
+
const anchorView: FlowView = {
|
|
148
|
+
type: 'dialog',
|
|
149
|
+
inputArgs: {
|
|
150
|
+
openerUids: ['opener-uid-1'],
|
|
151
|
+
viewUid: 'popup-uid',
|
|
152
|
+
dataSourceKey: 'main',
|
|
153
|
+
collectionName: 'posts',
|
|
154
|
+
filterByTk: 1,
|
|
155
|
+
},
|
|
156
|
+
Header: null,
|
|
157
|
+
Footer: null,
|
|
158
|
+
close: () => void 0,
|
|
159
|
+
update: () => void 0,
|
|
160
|
+
} as any;
|
|
161
|
+
|
|
162
|
+
const meta = (await createPopupMeta(ctx, anchorView)())!;
|
|
163
|
+
expect(typeof meta.hidden).toBe('function');
|
|
164
|
+
expect((meta.hidden as any)()).toBe(false);
|
|
165
|
+
expect(typeof meta.disabled).toBe('function');
|
|
166
|
+
expect((meta.disabled as any)()).toBe(false);
|
|
167
|
+
|
|
168
|
+
const vars = (await meta.buildVariablesParams!(ctx)) as any;
|
|
169
|
+
expect(vars).toBeTruthy();
|
|
170
|
+
expect(vars.record).toEqual({
|
|
171
|
+
collection: 'posts',
|
|
172
|
+
dataSourceKey: 'main',
|
|
173
|
+
filterByTk: 1,
|
|
174
|
+
associationName: undefined,
|
|
175
|
+
sourceId: undefined,
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('does not expose popup.record without filterByTk', async () => {
|
|
180
|
+
const { ctx } = makeCtx();
|
|
181
|
+
|
|
182
|
+
const anchorView: FlowView = {
|
|
183
|
+
type: 'dialog',
|
|
184
|
+
inputArgs: {
|
|
185
|
+
openerUids: ['opener-uid-1'],
|
|
186
|
+
viewUid: 'popup-uid',
|
|
187
|
+
dataSourceKey: 'main',
|
|
188
|
+
collectionName: 'posts',
|
|
189
|
+
// filterByTk 缺失:不应展示“当前弹窗记录”变量
|
|
190
|
+
},
|
|
191
|
+
Header: null,
|
|
192
|
+
Footer: null,
|
|
193
|
+
close: () => void 0,
|
|
194
|
+
update: () => void 0,
|
|
195
|
+
} as any;
|
|
196
|
+
|
|
197
|
+
ctx.defineProperty('view', { value: anchorView });
|
|
198
|
+
|
|
199
|
+
const meta = (await createPopupMeta(ctx, anchorView)())!;
|
|
200
|
+
const props = typeof meta.properties === 'function' ? await (meta.properties as any)() : meta.properties || {};
|
|
201
|
+
expect(props.record).toBeUndefined();
|
|
202
|
+
});
|
|
142
203
|
});
|
|
@@ -89,7 +89,13 @@ describe('FlowEngine', () => {
|
|
|
89
89
|
class MockFlowModelRepository implements IFlowModelRepository {
|
|
90
90
|
// 使用可配置返回值,便于不同用例控制 findOne 行为
|
|
91
91
|
findOneResult: any = null;
|
|
92
|
+
ensureResult: any = null;
|
|
93
|
+
ensureCalls = 0;
|
|
92
94
|
save = vi.fn(async (model: FlowModel) => ({ success: true, uid: model.uid }));
|
|
95
|
+
async ensure() {
|
|
96
|
+
this.ensureCalls += 1;
|
|
97
|
+
return this.ensureResult ? JSON.parse(JSON.stringify(this.ensureResult)) : null;
|
|
98
|
+
}
|
|
93
99
|
async findOne() {
|
|
94
100
|
// 返回深拷贝,避免被测试过程修改
|
|
95
101
|
return this.findOneResult ? JSON.parse(JSON.stringify(this.findOneResult)) : null;
|
|
@@ -188,5 +194,47 @@ describe('FlowEngine', () => {
|
|
|
188
194
|
expect(Array.isArray(mounted)).toBe(false);
|
|
189
195
|
expect(mounted?.uid).toBe('c3');
|
|
190
196
|
});
|
|
197
|
+
|
|
198
|
+
it('should call repository.ensure with repository context preserved', async () => {
|
|
199
|
+
const parent = engine.createModel({ uid: 'p4', use: 'FlowModel' });
|
|
200
|
+
|
|
201
|
+
repo.ensureResult = {
|
|
202
|
+
uid: 'c4',
|
|
203
|
+
use: 'FlowModel',
|
|
204
|
+
parentId: parent.uid,
|
|
205
|
+
subKey: 'page',
|
|
206
|
+
subType: 'object',
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const child = await engine.loadOrCreateModel({
|
|
210
|
+
parentId: parent.uid,
|
|
211
|
+
subKey: 'page',
|
|
212
|
+
subType: 'object',
|
|
213
|
+
use: 'FlowModel',
|
|
214
|
+
async: true,
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
expect(child).toBeTruthy();
|
|
218
|
+
expect(repo.ensureCalls).toBe(1);
|
|
219
|
+
expect((parent.subModels as any).page).toBe(child);
|
|
220
|
+
expect(repo.save).not.toHaveBeenCalled();
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('should not persist through ensure when skipSave is true', async () => {
|
|
224
|
+
repo.findOneResult = null;
|
|
225
|
+
|
|
226
|
+
const model = await engine.loadOrCreateModel(
|
|
227
|
+
{
|
|
228
|
+
uid: 'c5',
|
|
229
|
+
use: 'FlowModel',
|
|
230
|
+
},
|
|
231
|
+
{ skipSave: true },
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
expect(model).toBeTruthy();
|
|
235
|
+
expect(model?.uid).toBe('c5');
|
|
236
|
+
expect(repo.ensureCalls).toBe(0);
|
|
237
|
+
expect(repo.save).not.toHaveBeenCalled();
|
|
238
|
+
});
|
|
191
239
|
});
|
|
192
240
|
});
|