@nocobase/flow-engine 2.1.0-alpha.10 → 2.1.0-alpha.12
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/FlowDefinition.d.ts +4 -0
- package/lib/FlowSchemaRegistry.d.ts +154 -0
- package/lib/FlowSchemaRegistry.js +1427 -0
- package/lib/components/subModel/AddSubModelButton.js +11 -0
- 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/flowEngine.js +4 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- 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/runjs-context/setup.js +1 -0
- package/lib/server.d.ts +10 -0
- package/lib/server.js +32 -0
- package/lib/types.d.ts +233 -0
- package/package.json +4 -4
- package/server.d.ts +1 -0
- package/server.js +1 -0
- package/src/FlowSchemaRegistry.ts +1799 -0
- package/src/__tests__/FlowSchemaRegistry.test.ts +1951 -0
- package/src/__tests__/flow-engine.test.ts +48 -0
- package/src/__tests__/flowEngine.modelLoaders.test.ts +5 -1
- package/src/__tests__/flowEngine.saveModel.test.ts +4 -0
- package/src/__tests__/runjsContext.test.ts +3 -0
- package/src/__tests__/runjsContextRuntime.test.ts +2 -0
- package/src/components/subModel/AddSubModelButton.tsx +15 -1
- package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +1 -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/flowEngine.ts +7 -1
- package/src/index.ts +1 -0
- package/src/models/DisplayItemModel.tsx +1 -1
- package/src/models/EditableItemModel.tsx +1 -1
- package/src/models/FilterableItemModel.tsx +1 -1
- package/src/runjs-context/setup.ts +1 -0
- package/src/server.ts +11 -0
- package/src/types.ts +273 -0
|
@@ -476,6 +476,17 @@ const AddSubModelButtonCore = /* @__PURE__ */ __name(function AddSubModelButton(
|
|
|
476
476
|
() => transformItems(finalItems, model, subModelKey, subModelType),
|
|
477
477
|
[finalItems, model, subModelKey, subModelType]
|
|
478
478
|
);
|
|
479
|
+
(0, import_react.useEffect)(() => {
|
|
480
|
+
const handleSubModelChange = /* @__PURE__ */ __name(() => {
|
|
481
|
+
setRefreshTick((x) => x + 1);
|
|
482
|
+
}, "handleSubModelChange");
|
|
483
|
+
model.emitter.on("onSubModelAdded", handleSubModelChange);
|
|
484
|
+
model.emitter.on("onSubModelRemoved", handleSubModelChange);
|
|
485
|
+
return () => {
|
|
486
|
+
model.emitter.off("onSubModelAdded", handleSubModelChange);
|
|
487
|
+
model.emitter.off("onSubModelRemoved", handleSubModelChange);
|
|
488
|
+
};
|
|
489
|
+
}, [model]);
|
|
479
490
|
return /* @__PURE__ */ import_react.default.createElement(
|
|
480
491
|
import_LazyDropdown.default,
|
|
481
492
|
{
|
|
@@ -0,0 +1,32 @@
|
|
|
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 { FlowFieldBindingConditions, FlowFieldBindingContextContribution, FlowFieldBindingContribution, FlowFieldModelCompatibility, FlowSchemaCoverage } from '../types';
|
|
10
|
+
export type RegisteredFieldBindingContext = {
|
|
11
|
+
name: string;
|
|
12
|
+
inherits: string[];
|
|
13
|
+
};
|
|
14
|
+
export type RegisteredFieldBinding = {
|
|
15
|
+
context: string;
|
|
16
|
+
use: string;
|
|
17
|
+
interfaces: string[];
|
|
18
|
+
isDefault: boolean;
|
|
19
|
+
order?: number;
|
|
20
|
+
conditions?: FlowFieldBindingConditions;
|
|
21
|
+
defaultProps?: any;
|
|
22
|
+
source: FlowSchemaCoverage['source'];
|
|
23
|
+
};
|
|
24
|
+
export declare function normalizeFieldBindingContextContribution(contribution?: FlowFieldBindingContextContribution, fallbackName?: string): RegisteredFieldBindingContext | undefined;
|
|
25
|
+
export declare function normalizeFieldBindingContribution(contribution?: FlowFieldBindingContribution, source?: FlowSchemaCoverage['source']): RegisteredFieldBinding | undefined;
|
|
26
|
+
export declare function matchesFieldBinding(binding: RegisteredFieldBinding, options: {
|
|
27
|
+
interface?: string;
|
|
28
|
+
fieldType?: string;
|
|
29
|
+
association?: boolean;
|
|
30
|
+
targetCollectionTemplate?: string;
|
|
31
|
+
}): boolean;
|
|
32
|
+
export declare function buildFieldModelCompatibility(binding: RegisteredFieldBinding): FlowFieldModelCompatibility;
|
|
@@ -0,0 +1,165 @@
|
|
|
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 __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
17
|
+
var __export = (target, all) => {
|
|
18
|
+
for (var name in all)
|
|
19
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
20
|
+
};
|
|
21
|
+
var __copyProps = (to, from, except, desc) => {
|
|
22
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
+
for (let key of __getOwnPropNames(from))
|
|
24
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
25
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
26
|
+
}
|
|
27
|
+
return to;
|
|
28
|
+
};
|
|
29
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
30
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
+
mod
|
|
36
|
+
));
|
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
+
var fieldBinding_exports = {};
|
|
39
|
+
__export(fieldBinding_exports, {
|
|
40
|
+
buildFieldModelCompatibility: () => buildFieldModelCompatibility,
|
|
41
|
+
matchesFieldBinding: () => matchesFieldBinding,
|
|
42
|
+
normalizeFieldBindingContextContribution: () => normalizeFieldBindingContextContribution,
|
|
43
|
+
normalizeFieldBindingContribution: () => normalizeFieldBindingContribution
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(fieldBinding_exports);
|
|
46
|
+
var import_lodash = __toESM(require("lodash"));
|
|
47
|
+
var import_utils = require("./utils");
|
|
48
|
+
function normalizeFieldBindingConditions(conditions) {
|
|
49
|
+
if (!conditions || typeof conditions !== "object" || Array.isArray(conditions)) {
|
|
50
|
+
return void 0;
|
|
51
|
+
}
|
|
52
|
+
const normalized = import_lodash.default.pickBy(
|
|
53
|
+
{
|
|
54
|
+
association: typeof conditions.association === "boolean" ? conditions.association : void 0,
|
|
55
|
+
fieldTypes: (0, import_utils.normalizeStringArray)(conditions.fieldTypes),
|
|
56
|
+
targetCollectionTemplateIn: (0, import_utils.normalizeStringArray)(conditions.targetCollectionTemplateIn),
|
|
57
|
+
targetCollectionTemplateNotIn: (0, import_utils.normalizeStringArray)(conditions.targetCollectionTemplateNotIn)
|
|
58
|
+
},
|
|
59
|
+
(value) => {
|
|
60
|
+
if (Array.isArray(value)) {
|
|
61
|
+
return value.length > 0;
|
|
62
|
+
}
|
|
63
|
+
return value !== void 0;
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
return Object.keys(normalized).length > 0 ? normalized : void 0;
|
|
67
|
+
}
|
|
68
|
+
__name(normalizeFieldBindingConditions, "normalizeFieldBindingConditions");
|
|
69
|
+
function normalizeFieldBindingContextContribution(contribution, fallbackName) {
|
|
70
|
+
const name = String((contribution == null ? void 0 : contribution.name) || fallbackName || "").trim();
|
|
71
|
+
if (!name) {
|
|
72
|
+
return void 0;
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
name,
|
|
76
|
+
inherits: (0, import_utils.normalizeStringArray)(contribution == null ? void 0 : contribution.inherits)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
__name(normalizeFieldBindingContextContribution, "normalizeFieldBindingContextContribution");
|
|
80
|
+
function normalizeFieldBindingContribution(contribution, source = "official") {
|
|
81
|
+
const context = String((contribution == null ? void 0 : contribution.context) || "").trim();
|
|
82
|
+
const use = String((contribution == null ? void 0 : contribution.use) || "").trim();
|
|
83
|
+
const interfaces = (0, import_utils.normalizeStringArray)(contribution == null ? void 0 : contribution.interfaces);
|
|
84
|
+
if (!context || !use || interfaces.length === 0) {
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
context,
|
|
89
|
+
use,
|
|
90
|
+
interfaces,
|
|
91
|
+
isDefault: (contribution == null ? void 0 : contribution.isDefault) === true,
|
|
92
|
+
order: typeof (contribution == null ? void 0 : contribution.order) === "number" ? contribution.order : void 0,
|
|
93
|
+
conditions: normalizeFieldBindingConditions(contribution == null ? void 0 : contribution.conditions),
|
|
94
|
+
defaultProps: (contribution == null ? void 0 : contribution.defaultProps) === void 0 ? void 0 : import_lodash.default.cloneDeep(contribution.defaultProps),
|
|
95
|
+
source
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
__name(normalizeFieldBindingContribution, "normalizeFieldBindingContribution");
|
|
99
|
+
function matchesFieldBinding(binding, options) {
|
|
100
|
+
var _a, _b, _c;
|
|
101
|
+
if (options.interface && !binding.interfaces.includes("*") && !binding.interfaces.includes(options.interface)) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
const conditions = binding.conditions;
|
|
105
|
+
if (!conditions) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
if (typeof conditions.association === "boolean" && options.association !== void 0) {
|
|
109
|
+
if (conditions.association !== options.association) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (((_a = conditions.fieldTypes) == null ? void 0 : _a.length) && options.fieldType) {
|
|
114
|
+
if (!conditions.fieldTypes.includes(options.fieldType)) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (((_b = conditions.targetCollectionTemplateIn) == null ? void 0 : _b.length) && options.targetCollectionTemplate) {
|
|
119
|
+
if (!conditions.targetCollectionTemplateIn.includes(options.targetCollectionTemplate)) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (((_c = conditions.targetCollectionTemplateNotIn) == null ? void 0 : _c.length) && options.targetCollectionTemplate) {
|
|
124
|
+
if (conditions.targetCollectionTemplateNotIn.includes(options.targetCollectionTemplate)) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
__name(matchesFieldBinding, "matchesFieldBinding");
|
|
131
|
+
function buildFieldModelCompatibility(binding) {
|
|
132
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
133
|
+
const compatibility = {
|
|
134
|
+
context: binding.context,
|
|
135
|
+
interfaces: import_lodash.default.cloneDeep(binding.interfaces),
|
|
136
|
+
inheritParentFieldBinding: true
|
|
137
|
+
};
|
|
138
|
+
if (binding.isDefault) {
|
|
139
|
+
compatibility.isDefault = true;
|
|
140
|
+
}
|
|
141
|
+
if (typeof binding.order === "number") {
|
|
142
|
+
compatibility.order = binding.order;
|
|
143
|
+
}
|
|
144
|
+
if (typeof ((_a = binding.conditions) == null ? void 0 : _a.association) === "boolean") {
|
|
145
|
+
compatibility.association = binding.conditions.association;
|
|
146
|
+
}
|
|
147
|
+
if ((_c = (_b = binding.conditions) == null ? void 0 : _b.fieldTypes) == null ? void 0 : _c.length) {
|
|
148
|
+
compatibility.fieldTypes = import_lodash.default.cloneDeep(binding.conditions.fieldTypes);
|
|
149
|
+
}
|
|
150
|
+
if ((_e = (_d = binding.conditions) == null ? void 0 : _d.targetCollectionTemplateIn) == null ? void 0 : _e.length) {
|
|
151
|
+
compatibility.targetCollectionTemplateIn = import_lodash.default.cloneDeep(binding.conditions.targetCollectionTemplateIn);
|
|
152
|
+
}
|
|
153
|
+
if ((_g = (_f = binding.conditions) == null ? void 0 : _f.targetCollectionTemplateNotIn) == null ? void 0 : _g.length) {
|
|
154
|
+
compatibility.targetCollectionTemplateNotIn = import_lodash.default.cloneDeep(binding.conditions.targetCollectionTemplateNotIn);
|
|
155
|
+
}
|
|
156
|
+
return compatibility;
|
|
157
|
+
}
|
|
158
|
+
__name(buildFieldModelCompatibility, "buildFieldModelCompatibility");
|
|
159
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
160
|
+
0 && (module.exports = {
|
|
161
|
+
buildFieldModelCompatibility,
|
|
162
|
+
matchesFieldBinding,
|
|
163
|
+
normalizeFieldBindingContextContribution,
|
|
164
|
+
normalizeFieldBindingContribution
|
|
165
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
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 { FlowDescendantSchemaPatch, FlowModelSchemaPatch, FlowSchemaContextEdge, FlowSchemaCoverage, FlowSubModelContextPathStep, FlowSubModelSlotSchema } from '../types';
|
|
10
|
+
import type { RegisteredModelSchema } from '../FlowSchemaRegistry';
|
|
11
|
+
export declare function normalizeSubModelContextPath(path?: FlowSubModelContextPathStep[]): FlowSubModelContextPathStep[];
|
|
12
|
+
export declare function normalizeModelSchemaPatch(patch?: FlowModelSchemaPatch): FlowModelSchemaPatch | undefined;
|
|
13
|
+
export declare function normalizeSubModelSlots(slots?: Record<string, FlowSubModelSlotSchema>): Record<string, FlowSubModelSlotSchema> | undefined;
|
|
14
|
+
export declare function matchesDescendantSchemaPatch(patch: FlowDescendantSchemaPatch, remainingEdges: FlowSchemaContextEdge[]): boolean;
|
|
15
|
+
export declare function resolveChildSchemaPatch(slot: FlowSubModelSlotSchema, childUse: string): FlowModelSchemaPatch | undefined;
|
|
16
|
+
export declare function applyModelSchemaPatch(target: RegisteredModelSchema, patch: FlowModelSchemaPatch, source: FlowSchemaCoverage['source'], strict?: boolean): void;
|
|
@@ -0,0 +1,235 @@
|
|
|
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 __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
17
|
+
var __export = (target, all) => {
|
|
18
|
+
for (var name in all)
|
|
19
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
20
|
+
};
|
|
21
|
+
var __copyProps = (to, from, except, desc) => {
|
|
22
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
+
for (let key of __getOwnPropNames(from))
|
|
24
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
25
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
26
|
+
}
|
|
27
|
+
return to;
|
|
28
|
+
};
|
|
29
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
30
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
+
mod
|
|
36
|
+
));
|
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
+
var modelPatches_exports = {};
|
|
39
|
+
__export(modelPatches_exports, {
|
|
40
|
+
applyModelSchemaPatch: () => applyModelSchemaPatch,
|
|
41
|
+
matchesDescendantSchemaPatch: () => matchesDescendantSchemaPatch,
|
|
42
|
+
normalizeModelSchemaPatch: () => normalizeModelSchemaPatch,
|
|
43
|
+
normalizeSubModelContextPath: () => normalizeSubModelContextPath,
|
|
44
|
+
normalizeSubModelSlots: () => normalizeSubModelSlots,
|
|
45
|
+
resolveChildSchemaPatch: () => resolveChildSchemaPatch
|
|
46
|
+
});
|
|
47
|
+
module.exports = __toCommonJS(modelPatches_exports);
|
|
48
|
+
var import_lodash = __toESM(require("lodash"));
|
|
49
|
+
var import_utils = require("./utils");
|
|
50
|
+
function normalizeSubModelContextPath(path) {
|
|
51
|
+
if (!Array.isArray(path)) {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
return path.map((step) => ({
|
|
55
|
+
slotKey: String((step == null ? void 0 : step.slotKey) || "").trim(),
|
|
56
|
+
...typeof (step == null ? void 0 : step.use) === "string" ? { use: step.use.trim() } : Array.isArray(step == null ? void 0 : step.use) ? { use: step.use.map((item) => String(item || "").trim()).filter(Boolean) } : {}
|
|
57
|
+
})).filter((step) => !!step.slotKey);
|
|
58
|
+
}
|
|
59
|
+
__name(normalizeSubModelContextPath, "normalizeSubModelContextPath");
|
|
60
|
+
function normalizeModelSchemaPatch(patch) {
|
|
61
|
+
if (!patch || typeof patch !== "object" || Array.isArray(patch)) {
|
|
62
|
+
return void 0;
|
|
63
|
+
}
|
|
64
|
+
const normalized = import_lodash.default.pickBy(
|
|
65
|
+
{
|
|
66
|
+
stepParamsSchema: patch.stepParamsSchema ? import_lodash.default.cloneDeep(patch.stepParamsSchema) : void 0,
|
|
67
|
+
flowRegistrySchema: patch.flowRegistrySchema ? import_lodash.default.cloneDeep(patch.flowRegistrySchema) : void 0,
|
|
68
|
+
flowRegistrySchemaPatch: patch.flowRegistrySchemaPatch ? import_lodash.default.cloneDeep(patch.flowRegistrySchemaPatch) : void 0,
|
|
69
|
+
subModelSlots: normalizeSubModelSlots(patch.subModelSlots),
|
|
70
|
+
docs: patch.docs ? (0, import_utils.normalizeSchemaDocs)(patch.docs) : void 0,
|
|
71
|
+
examples: Array.isArray(patch.examples) ? import_lodash.default.cloneDeep(patch.examples) : void 0,
|
|
72
|
+
skeleton: patch.skeleton === void 0 ? void 0 : import_lodash.default.cloneDeep(patch.skeleton),
|
|
73
|
+
dynamicHints: Array.isArray(patch.dynamicHints) ? (0, import_utils.normalizeSchemaHints)(patch.dynamicHints) : void 0
|
|
74
|
+
},
|
|
75
|
+
(value) => value !== void 0 && (!Array.isArray(value) || value.length > 0)
|
|
76
|
+
);
|
|
77
|
+
return Object.keys(normalized).length > 0 ? normalized : void 0;
|
|
78
|
+
}
|
|
79
|
+
__name(normalizeModelSchemaPatch, "normalizeModelSchemaPatch");
|
|
80
|
+
function normalizeDescendantSchemaPatches(patches) {
|
|
81
|
+
if (!Array.isArray(patches)) {
|
|
82
|
+
return void 0;
|
|
83
|
+
}
|
|
84
|
+
const normalized = patches.map((item) => {
|
|
85
|
+
const path = normalizeSubModelContextPath(item == null ? void 0 : item.path);
|
|
86
|
+
const patch = normalizeModelSchemaPatch(item == null ? void 0 : item.patch);
|
|
87
|
+
if (!patch) {
|
|
88
|
+
return void 0;
|
|
89
|
+
}
|
|
90
|
+
return { path, patch };
|
|
91
|
+
}).filter(Boolean);
|
|
92
|
+
return normalized.length > 0 ? normalized : void 0;
|
|
93
|
+
}
|
|
94
|
+
__name(normalizeDescendantSchemaPatches, "normalizeDescendantSchemaPatches");
|
|
95
|
+
function normalizeChildSchemaPatch(patch) {
|
|
96
|
+
if (!patch || typeof patch !== "object" || Array.isArray(patch)) {
|
|
97
|
+
return void 0;
|
|
98
|
+
}
|
|
99
|
+
const directPatch = normalizeModelSchemaPatch(patch);
|
|
100
|
+
if (directPatch) {
|
|
101
|
+
return directPatch;
|
|
102
|
+
}
|
|
103
|
+
const entries = Object.entries(patch).map(([childUse, childPatch]) => [String(childUse || "").trim(), normalizeModelSchemaPatch(childPatch)]).filter(([childUse, childPatch]) => !!childUse && !!childPatch);
|
|
104
|
+
if (!entries.length) {
|
|
105
|
+
return void 0;
|
|
106
|
+
}
|
|
107
|
+
return Object.fromEntries(entries);
|
|
108
|
+
}
|
|
109
|
+
__name(normalizeChildSchemaPatch, "normalizeChildSchemaPatch");
|
|
110
|
+
function normalizeSubModelSlots(slots) {
|
|
111
|
+
if (!slots || typeof slots !== "object" || Array.isArray(slots)) {
|
|
112
|
+
return void 0;
|
|
113
|
+
}
|
|
114
|
+
const normalizedEntries = Object.entries(slots).map(([slotKey, slot]) => {
|
|
115
|
+
if (!(slot == null ? void 0 : slot.type)) {
|
|
116
|
+
return void 0;
|
|
117
|
+
}
|
|
118
|
+
const normalizedSlot = {
|
|
119
|
+
type: slot.type
|
|
120
|
+
};
|
|
121
|
+
const normalizedUse = typeof slot.use === "string" ? slot.use.trim() : void 0;
|
|
122
|
+
if (normalizedUse) {
|
|
123
|
+
normalizedSlot.use = normalizedUse;
|
|
124
|
+
}
|
|
125
|
+
const normalizedUses = Array.isArray(slot.uses) ? slot.uses.map((item) => String(item || "").trim()).filter(Boolean) : void 0;
|
|
126
|
+
if (normalizedUses == null ? void 0 : normalizedUses.length) {
|
|
127
|
+
normalizedSlot.uses = normalizedUses;
|
|
128
|
+
}
|
|
129
|
+
if (slot.required !== void 0) {
|
|
130
|
+
normalizedSlot.required = slot.required;
|
|
131
|
+
}
|
|
132
|
+
if (slot.type === "array" && typeof slot.minItems === "number" && Number.isFinite(slot.minItems)) {
|
|
133
|
+
normalizedSlot.minItems = Math.max(0, Math.trunc(slot.minItems));
|
|
134
|
+
}
|
|
135
|
+
if (slot.dynamic !== void 0) {
|
|
136
|
+
normalizedSlot.dynamic = slot.dynamic;
|
|
137
|
+
}
|
|
138
|
+
if (slot.schema) {
|
|
139
|
+
normalizedSlot.schema = import_lodash.default.cloneDeep(slot.schema);
|
|
140
|
+
}
|
|
141
|
+
if (typeof slot.fieldBindingContext === "string" && slot.fieldBindingContext.trim()) {
|
|
142
|
+
normalizedSlot.fieldBindingContext = slot.fieldBindingContext.trim();
|
|
143
|
+
}
|
|
144
|
+
const childSchemaPatch = normalizeChildSchemaPatch(slot.childSchemaPatch);
|
|
145
|
+
if (childSchemaPatch) {
|
|
146
|
+
normalizedSlot.childSchemaPatch = childSchemaPatch;
|
|
147
|
+
}
|
|
148
|
+
const descendantSchemaPatches = normalizeDescendantSchemaPatches(slot.descendantSchemaPatches);
|
|
149
|
+
if (descendantSchemaPatches == null ? void 0 : descendantSchemaPatches.length) {
|
|
150
|
+
normalizedSlot.descendantSchemaPatches = descendantSchemaPatches;
|
|
151
|
+
}
|
|
152
|
+
if (slot.description !== void 0) {
|
|
153
|
+
normalizedSlot.description = slot.description;
|
|
154
|
+
}
|
|
155
|
+
return [slotKey, normalizedSlot];
|
|
156
|
+
}).filter(Boolean);
|
|
157
|
+
return normalizedEntries.length > 0 ? Object.fromEntries(normalizedEntries) : void 0;
|
|
158
|
+
}
|
|
159
|
+
__name(normalizeSubModelSlots, "normalizeSubModelSlots");
|
|
160
|
+
function matchesDescendantSchemaPatch(patch, remainingEdges) {
|
|
161
|
+
const path = normalizeSubModelContextPath(patch.path);
|
|
162
|
+
if (path.length !== remainingEdges.length) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
return path.every((step, index) => {
|
|
166
|
+
const edge = remainingEdges[index];
|
|
167
|
+
if (step.slotKey !== edge.slotKey) {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
if (typeof step.use === "undefined") {
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
if (typeof step.use === "string") {
|
|
174
|
+
return step.use === edge.childUse;
|
|
175
|
+
}
|
|
176
|
+
return step.use.includes(edge.childUse);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
__name(matchesDescendantSchemaPatch, "matchesDescendantSchemaPatch");
|
|
180
|
+
function resolveChildSchemaPatch(slot, childUse) {
|
|
181
|
+
const childSchemaPatch = slot.childSchemaPatch;
|
|
182
|
+
if (!childSchemaPatch || typeof childSchemaPatch !== "object" || Array.isArray(childSchemaPatch)) {
|
|
183
|
+
return void 0;
|
|
184
|
+
}
|
|
185
|
+
const directPatch = normalizeModelSchemaPatch(childSchemaPatch);
|
|
186
|
+
if (directPatch) {
|
|
187
|
+
return directPatch;
|
|
188
|
+
}
|
|
189
|
+
return normalizeModelSchemaPatch(childSchemaPatch[childUse]);
|
|
190
|
+
}
|
|
191
|
+
__name(resolveChildSchemaPatch, "resolveChildSchemaPatch");
|
|
192
|
+
function applyModelSchemaPatch(target, patch, source, strict) {
|
|
193
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
194
|
+
target.stepParamsSchema = (0, import_utils.mergeSchemas)(target.stepParamsSchema, patch.stepParamsSchema);
|
|
195
|
+
target.flowRegistrySchema = (0, import_utils.mergeSchemas)(target.flowRegistrySchema, patch.flowRegistrySchema);
|
|
196
|
+
target.flowRegistrySchemaPatch = (0, import_utils.mergeSchemas)(target.flowRegistrySchemaPatch, patch.flowRegistrySchemaPatch);
|
|
197
|
+
target.subModelSlots = normalizeSubModelSlots(
|
|
198
|
+
patch.subModelSlots ? (0, import_utils.deepMergeReplaceArrays)(target.subModelSlots || {}, patch.subModelSlots) : target.subModelSlots
|
|
199
|
+
);
|
|
200
|
+
target.docs = (0, import_utils.normalizeSchemaDocs)({
|
|
201
|
+
...target.docs,
|
|
202
|
+
...patch.docs,
|
|
203
|
+
examples: ((_a = patch.docs) == null ? void 0 : _a.examples) || ((_b = target.docs) == null ? void 0 : _b.examples),
|
|
204
|
+
dynamicHints: [...((_c = target.docs) == null ? void 0 : _c.dynamicHints) || [], ...((_d = patch.docs) == null ? void 0 : _d.dynamicHints) || []],
|
|
205
|
+
commonPatterns: ((_e = patch.docs) == null ? void 0 : _e.commonPatterns) || ((_f = target.docs) == null ? void 0 : _f.commonPatterns),
|
|
206
|
+
antiPatterns: ((_g = patch.docs) == null ? void 0 : _g.antiPatterns) || ((_h = target.docs) == null ? void 0 : _h.antiPatterns),
|
|
207
|
+
minimalExample: ((_i = patch.docs) == null ? void 0 : _i.minimalExample) !== void 0 ? patch.docs.minimalExample : (_j = target.docs) == null ? void 0 : _j.minimalExample
|
|
208
|
+
});
|
|
209
|
+
target.examples = Array.isArray(patch.examples) ? import_lodash.default.cloneDeep(patch.examples) : target.examples;
|
|
210
|
+
target.skeleton = patch.skeleton !== void 0 ? (0, import_utils.deepMergeReplaceArrays)(target.skeleton, patch.skeleton) : target.skeleton;
|
|
211
|
+
target.dynamicHints = (0, import_utils.normalizeSchemaHints)([
|
|
212
|
+
...target.dynamicHints || [],
|
|
213
|
+
...patch.dynamicHints || [],
|
|
214
|
+
...((_k = patch.docs) == null ? void 0 : _k.dynamicHints) || []
|
|
215
|
+
]);
|
|
216
|
+
const hasSchemaPatch = !!patch.stepParamsSchema || !!patch.flowRegistrySchema || !!patch.flowRegistrySchemaPatch || !!patch.subModelSlots;
|
|
217
|
+
if (hasSchemaPatch) {
|
|
218
|
+
target.coverage = {
|
|
219
|
+
...target.coverage,
|
|
220
|
+
status: target.coverage.status === "unresolved" ? "manual" : target.coverage.status === "auto" ? "mixed" : target.coverage.status,
|
|
221
|
+
source: target.coverage.source === "third-party" ? source : target.coverage.source,
|
|
222
|
+
strict: target.coverage.strict ?? strict
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
__name(applyModelSchemaPatch, "applyModelSchemaPatch");
|
|
227
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
228
|
+
0 && (module.exports = {
|
|
229
|
+
applyModelSchemaPatch,
|
|
230
|
+
matchesDescendantSchemaPatch,
|
|
231
|
+
normalizeModelSchemaPatch,
|
|
232
|
+
normalizeSubModelContextPath,
|
|
233
|
+
normalizeSubModelSlots,
|
|
234
|
+
resolveChildSchemaPatch
|
|
235
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
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 { ISchema } from '@formily/json-schema';
|
|
10
|
+
import type { FlowDynamicHint, FlowJsonSchema, FlowSchemaCoverage } from '../types';
|
|
11
|
+
export type StepSchemaResolution = {
|
|
12
|
+
schema?: FlowJsonSchema;
|
|
13
|
+
hints: FlowDynamicHint[];
|
|
14
|
+
coverage: FlowSchemaCoverage['status'];
|
|
15
|
+
};
|
|
16
|
+
export type UiSchemaLike = Record<string, ISchema> | ((...args: any[]) => Record<string, ISchema> | Promise<Record<string, ISchema>>) | undefined;
|
|
17
|
+
export declare function inferParamsSchemaFromUiSchema(name: string, uiSchema: UiSchemaLike, path: string): StepSchemaResolution;
|