@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
|
@@ -0,0 +1,207 @@
|
|
|
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 schemaInference_exports = {};
|
|
39
|
+
__export(schemaInference_exports, {
|
|
40
|
+
inferParamsSchemaFromUiSchema: () => inferParamsSchemaFromUiSchema
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(schemaInference_exports);
|
|
43
|
+
var import_lodash = __toESM(require("lodash"));
|
|
44
|
+
var import_utils = require("./utils");
|
|
45
|
+
function inferSchemaFromUiSchemaValue(name, uiSchema, path, hints) {
|
|
46
|
+
if (!uiSchema || typeof uiSchema !== "object" || Array.isArray(uiSchema)) {
|
|
47
|
+
return { type: "object", additionalProperties: true };
|
|
48
|
+
}
|
|
49
|
+
const xComponent = uiSchema["x-component"];
|
|
50
|
+
if (typeof xComponent === "function") {
|
|
51
|
+
hints.push(
|
|
52
|
+
(0, import_utils.createFlowHint)(
|
|
53
|
+
{
|
|
54
|
+
kind: "custom-component",
|
|
55
|
+
path,
|
|
56
|
+
message: `${name} uses a custom component and needs manual schema review.`
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
unresolvedReason: "function-x-component",
|
|
60
|
+
recommendedFallback: { type: "object", additionalProperties: true }
|
|
61
|
+
}
|
|
62
|
+
)
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
const reactions = uiSchema["x-reactions"];
|
|
66
|
+
if (reactions && (Array.isArray(reactions) && reactions.some((item) => typeof item === "function") || typeof reactions === "function")) {
|
|
67
|
+
hints.push(
|
|
68
|
+
(0, import_utils.createFlowHint)(
|
|
69
|
+
{
|
|
70
|
+
kind: "x-reactions",
|
|
71
|
+
path,
|
|
72
|
+
message: `${name} contains function-based x-reactions and only static schema is generated.`
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
unresolvedReason: "function-x-reactions"
|
|
76
|
+
}
|
|
77
|
+
)
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
const schema = {};
|
|
81
|
+
const type = uiSchema.type;
|
|
82
|
+
if (type) {
|
|
83
|
+
schema.type = type;
|
|
84
|
+
}
|
|
85
|
+
if (uiSchema.description) {
|
|
86
|
+
schema.description = uiSchema.description;
|
|
87
|
+
}
|
|
88
|
+
if (uiSchema.default !== void 0) {
|
|
89
|
+
schema.default = import_lodash.default.cloneDeep(uiSchema.default);
|
|
90
|
+
}
|
|
91
|
+
if (uiSchema.enum) {
|
|
92
|
+
if (Array.isArray(uiSchema.enum) && uiSchema.enum.every((item) => import_lodash.default.isPlainObject(item) && "value" in item)) {
|
|
93
|
+
schema.enum = uiSchema.enum.map((item) => item.value);
|
|
94
|
+
} else {
|
|
95
|
+
schema.enum = import_lodash.default.cloneDeep(uiSchema.enum);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (uiSchema.const !== void 0) {
|
|
99
|
+
schema.const = import_lodash.default.cloneDeep(uiSchema.const);
|
|
100
|
+
}
|
|
101
|
+
if (uiSchema.required === true) {
|
|
102
|
+
schema.__required = true;
|
|
103
|
+
}
|
|
104
|
+
const validator = uiSchema["x-validator"];
|
|
105
|
+
if (import_lodash.default.isPlainObject(validator)) {
|
|
106
|
+
if (validator.minimum !== void 0) schema.minimum = validator.minimum;
|
|
107
|
+
if (validator.maximum !== void 0) schema.maximum = validator.maximum;
|
|
108
|
+
if (validator.minLength !== void 0) schema.minLength = validator.minLength;
|
|
109
|
+
if (validator.maxLength !== void 0) schema.maxLength = validator.maxLength;
|
|
110
|
+
if (validator.pattern !== void 0) schema.pattern = validator.pattern;
|
|
111
|
+
} else if (Array.isArray(validator)) {
|
|
112
|
+
for (const item of validator) {
|
|
113
|
+
if (import_lodash.default.isPlainObject(item)) {
|
|
114
|
+
Object.assign(schema, import_lodash.default.pick(item, ["minimum", "maximum", "minLength", "maxLength", "pattern"]));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
} else if (typeof validator === "string") {
|
|
118
|
+
if (validator === "integer") schema.type = "integer";
|
|
119
|
+
if (validator === "email") schema.format = "email";
|
|
120
|
+
if (validator === "url") schema.format = "uri";
|
|
121
|
+
if (validator === "uid") schema.pattern = "^[A-Za-z0-9_-]+$";
|
|
122
|
+
}
|
|
123
|
+
if (uiSchema.properties && import_lodash.default.isPlainObject(uiSchema.properties)) {
|
|
124
|
+
schema.type = schema.type || "object";
|
|
125
|
+
schema.properties = {};
|
|
126
|
+
const required = [];
|
|
127
|
+
for (const [propName, propValue] of Object.entries(uiSchema.properties)) {
|
|
128
|
+
const childSchema = inferSchemaFromUiSchemaValue(propName, propValue, `${path}.${propName}`, hints);
|
|
129
|
+
if (childSchema.__required) {
|
|
130
|
+
required.push(propName);
|
|
131
|
+
delete childSchema.__required;
|
|
132
|
+
}
|
|
133
|
+
schema.properties[propName] = childSchema;
|
|
134
|
+
}
|
|
135
|
+
if (required.length) {
|
|
136
|
+
schema.required = required;
|
|
137
|
+
}
|
|
138
|
+
schema.additionalProperties = false;
|
|
139
|
+
}
|
|
140
|
+
if (uiSchema.items) {
|
|
141
|
+
schema.type = schema.type || "array";
|
|
142
|
+
if (import_lodash.default.isPlainObject(uiSchema.items)) {
|
|
143
|
+
schema.items = inferSchemaFromUiSchemaValue(`${name}.items`, uiSchema.items, `${path}.items`, hints);
|
|
144
|
+
} else if (Array.isArray(uiSchema.items)) {
|
|
145
|
+
schema.items = uiSchema.items.map(
|
|
146
|
+
(item, index) => inferSchemaFromUiSchemaValue(`${name}.items[${index}]`, item, `${path}.items[${index}]`, hints)
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (!schema.type) {
|
|
151
|
+
schema.type = "object";
|
|
152
|
+
schema.additionalProperties = true;
|
|
153
|
+
}
|
|
154
|
+
return schema;
|
|
155
|
+
}
|
|
156
|
+
__name(inferSchemaFromUiSchemaValue, "inferSchemaFromUiSchemaValue");
|
|
157
|
+
function inferParamsSchemaFromUiSchema(name, uiSchema, path) {
|
|
158
|
+
const hints = [];
|
|
159
|
+
if (!uiSchema) {
|
|
160
|
+
return { schema: void 0, hints, coverage: "unresolved" };
|
|
161
|
+
}
|
|
162
|
+
if (typeof uiSchema === "function") {
|
|
163
|
+
hints.push(
|
|
164
|
+
(0, import_utils.createFlowHint)(
|
|
165
|
+
{
|
|
166
|
+
kind: "dynamic-ui-schema",
|
|
167
|
+
path,
|
|
168
|
+
message: `${name} uses function-based uiSchema and requires manual schema patch.`
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
unresolvedReason: "function-ui-schema",
|
|
172
|
+
recommendedFallback: { type: "object", additionalProperties: true }
|
|
173
|
+
}
|
|
174
|
+
)
|
|
175
|
+
);
|
|
176
|
+
return {
|
|
177
|
+
schema: { type: "object", additionalProperties: true },
|
|
178
|
+
hints,
|
|
179
|
+
coverage: "unresolved"
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
const properties = {};
|
|
183
|
+
const required = [];
|
|
184
|
+
for (const [key, value] of Object.entries(uiSchema)) {
|
|
185
|
+
const childSchema = inferSchemaFromUiSchemaValue(key, value, `${path}.${key}`, hints);
|
|
186
|
+
if (childSchema.__required) {
|
|
187
|
+
required.push(key);
|
|
188
|
+
delete childSchema.__required;
|
|
189
|
+
}
|
|
190
|
+
properties[key] = childSchema;
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
schema: {
|
|
194
|
+
type: "object",
|
|
195
|
+
properties,
|
|
196
|
+
...required.length ? { required } : {},
|
|
197
|
+
additionalProperties: false
|
|
198
|
+
},
|
|
199
|
+
hints,
|
|
200
|
+
coverage: hints.length ? "mixed" : "auto"
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
__name(inferParamsSchemaFromUiSchema, "inferParamsSchemaFromUiSchema");
|
|
204
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
205
|
+
0 && (module.exports = {
|
|
206
|
+
inferParamsSchemaFromUiSchema
|
|
207
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
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 { FlowDynamicHint, FlowJsonSchema, FlowSchemaDocs, FlowSubModelSlotSchema } from '../types';
|
|
10
|
+
export declare const JSON_SCHEMA_DRAFT_07 = "http://json-schema.org/draft-07/schema#";
|
|
11
|
+
export declare function stableStringify(input: any): string;
|
|
12
|
+
export declare function deepFreezePlainGraph<T>(input: T, seen?: WeakSet<object>): T;
|
|
13
|
+
export declare function hashString(input: string): string;
|
|
14
|
+
export declare function deepMergeReplaceArrays<T>(base: T, patch: any): T;
|
|
15
|
+
export declare function mergeSchemas(base?: FlowJsonSchema, patch?: FlowJsonSchema): FlowJsonSchema | undefined;
|
|
16
|
+
export declare function normalizeSchemaHints(hints?: FlowDynamicHint[]): FlowDynamicHint[];
|
|
17
|
+
export declare function normalizeSchemaDocs(docs?: FlowSchemaDocs): FlowSchemaDocs;
|
|
18
|
+
export declare function normalizeStringArray(values?: string[]): string[];
|
|
19
|
+
export declare function createFlowHint(hint: FlowDynamicHint, metadata?: FlowDynamicHint['x-flow']): FlowDynamicHint;
|
|
20
|
+
export declare function collectAllowedUses(slot?: FlowSubModelSlotSchema): string[];
|
|
21
|
+
export declare function buildSkeletonFromSchema(schema?: FlowJsonSchema, options?: {
|
|
22
|
+
propertyName?: string;
|
|
23
|
+
depth?: number;
|
|
24
|
+
}): any;
|
|
25
|
+
export declare function toSchemaTitle(input: any, fallback: string): string;
|
|
@@ -0,0 +1,293 @@
|
|
|
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 utils_exports = {};
|
|
39
|
+
__export(utils_exports, {
|
|
40
|
+
JSON_SCHEMA_DRAFT_07: () => JSON_SCHEMA_DRAFT_07,
|
|
41
|
+
buildSkeletonFromSchema: () => buildSkeletonFromSchema,
|
|
42
|
+
collectAllowedUses: () => collectAllowedUses,
|
|
43
|
+
createFlowHint: () => createFlowHint,
|
|
44
|
+
deepFreezePlainGraph: () => deepFreezePlainGraph,
|
|
45
|
+
deepMergeReplaceArrays: () => deepMergeReplaceArrays,
|
|
46
|
+
hashString: () => hashString,
|
|
47
|
+
mergeSchemas: () => mergeSchemas,
|
|
48
|
+
normalizeSchemaDocs: () => normalizeSchemaDocs,
|
|
49
|
+
normalizeSchemaHints: () => normalizeSchemaHints,
|
|
50
|
+
normalizeStringArray: () => normalizeStringArray,
|
|
51
|
+
stableStringify: () => stableStringify,
|
|
52
|
+
toSchemaTitle: () => toSchemaTitle
|
|
53
|
+
});
|
|
54
|
+
module.exports = __toCommonJS(utils_exports);
|
|
55
|
+
var import_lodash = __toESM(require("lodash"));
|
|
56
|
+
const JSON_SCHEMA_DRAFT_07 = "http://json-schema.org/draft-07/schema#";
|
|
57
|
+
function stableStringify(input) {
|
|
58
|
+
if (Array.isArray(input)) {
|
|
59
|
+
return `[${input.map((item) => stableStringify(item)).join(",")}]`;
|
|
60
|
+
}
|
|
61
|
+
if (import_lodash.default.isPlainObject(input)) {
|
|
62
|
+
const entries = Object.entries(input).sort(([a], [b]) => a.localeCompare(b)).map(([key, value]) => `${JSON.stringify(key)}:${stableStringify(value)}`);
|
|
63
|
+
return `{${entries.join(",")}}`;
|
|
64
|
+
}
|
|
65
|
+
return JSON.stringify(input) ?? "null";
|
|
66
|
+
}
|
|
67
|
+
__name(stableStringify, "stableStringify");
|
|
68
|
+
function deepFreezePlainGraph(input, seen = /* @__PURE__ */ new WeakSet()) {
|
|
69
|
+
if (Array.isArray(input)) {
|
|
70
|
+
if (seen.has(input)) {
|
|
71
|
+
return input;
|
|
72
|
+
}
|
|
73
|
+
seen.add(input);
|
|
74
|
+
for (const item of input) {
|
|
75
|
+
deepFreezePlainGraph(item, seen);
|
|
76
|
+
}
|
|
77
|
+
return Object.freeze(input);
|
|
78
|
+
}
|
|
79
|
+
if (!import_lodash.default.isPlainObject(input)) {
|
|
80
|
+
return input;
|
|
81
|
+
}
|
|
82
|
+
const objectValue = input;
|
|
83
|
+
if (seen.has(objectValue)) {
|
|
84
|
+
return input;
|
|
85
|
+
}
|
|
86
|
+
seen.add(objectValue);
|
|
87
|
+
for (const value of Object.values(objectValue)) {
|
|
88
|
+
deepFreezePlainGraph(value, seen);
|
|
89
|
+
}
|
|
90
|
+
return Object.freeze(objectValue);
|
|
91
|
+
}
|
|
92
|
+
__name(deepFreezePlainGraph, "deepFreezePlainGraph");
|
|
93
|
+
function hashString(input) {
|
|
94
|
+
let hash = 0;
|
|
95
|
+
for (let index = 0; index < input.length; index++) {
|
|
96
|
+
hash = hash * 31 + input.charCodeAt(index) >>> 0;
|
|
97
|
+
}
|
|
98
|
+
return hash.toString(16).padStart(8, "0");
|
|
99
|
+
}
|
|
100
|
+
__name(hashString, "hashString");
|
|
101
|
+
function deepMergeReplaceArrays(base, patch) {
|
|
102
|
+
if (typeof patch === "undefined") {
|
|
103
|
+
return import_lodash.default.cloneDeep(base);
|
|
104
|
+
}
|
|
105
|
+
if (typeof base === "undefined") {
|
|
106
|
+
return import_lodash.default.cloneDeep(patch);
|
|
107
|
+
}
|
|
108
|
+
return import_lodash.default.mergeWith({}, import_lodash.default.cloneDeep(base), import_lodash.default.cloneDeep(patch), (_objValue, srcValue) => {
|
|
109
|
+
if (Array.isArray(srcValue)) {
|
|
110
|
+
return import_lodash.default.cloneDeep(srcValue);
|
|
111
|
+
}
|
|
112
|
+
return void 0;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
__name(deepMergeReplaceArrays, "deepMergeReplaceArrays");
|
|
116
|
+
function mergeSchemas(base, patch) {
|
|
117
|
+
if (!base && !patch) return void 0;
|
|
118
|
+
if (!base) return import_lodash.default.cloneDeep(patch);
|
|
119
|
+
if (!patch) return import_lodash.default.cloneDeep(base);
|
|
120
|
+
return deepMergeReplaceArrays(base, patch);
|
|
121
|
+
}
|
|
122
|
+
__name(mergeSchemas, "mergeSchemas");
|
|
123
|
+
function normalizeFlowHintMetadata(metadata) {
|
|
124
|
+
if (!metadata || typeof metadata !== "object" || Array.isArray(metadata)) {
|
|
125
|
+
return void 0;
|
|
126
|
+
}
|
|
127
|
+
const slotRules = metadata.slotRules && typeof metadata.slotRules === "object" && !Array.isArray(metadata.slotRules) ? import_lodash.default.pickBy(
|
|
128
|
+
{
|
|
129
|
+
slotKey: metadata.slotRules.slotKey,
|
|
130
|
+
type: metadata.slotRules.type,
|
|
131
|
+
allowedUses: Array.isArray(metadata.slotRules.allowedUses) ? metadata.slotRules.allowedUses.filter(Boolean) : metadata.slotRules.allowedUses
|
|
132
|
+
},
|
|
133
|
+
(value) => value !== void 0
|
|
134
|
+
) : void 0;
|
|
135
|
+
const normalized = import_lodash.default.pickBy(
|
|
136
|
+
{
|
|
137
|
+
slotRules: slotRules && Object.keys(slotRules).length > 0 ? slotRules : void 0,
|
|
138
|
+
contextRequirements: Array.isArray(metadata.contextRequirements) ? metadata.contextRequirements.filter(Boolean) : metadata.contextRequirements,
|
|
139
|
+
unresolvedReason: metadata.unresolvedReason,
|
|
140
|
+
recommendedFallback: metadata.recommendedFallback
|
|
141
|
+
},
|
|
142
|
+
(value) => value !== void 0
|
|
143
|
+
);
|
|
144
|
+
return Object.keys(normalized).length > 0 ? normalized : void 0;
|
|
145
|
+
}
|
|
146
|
+
__name(normalizeFlowHintMetadata, "normalizeFlowHintMetadata");
|
|
147
|
+
function normalizeFlowHint(hint) {
|
|
148
|
+
const normalizedHint = { ...hint };
|
|
149
|
+
const flowMetadata = normalizeFlowHintMetadata(hint["x-flow"]);
|
|
150
|
+
if (flowMetadata) {
|
|
151
|
+
normalizedHint["x-flow"] = flowMetadata;
|
|
152
|
+
} else {
|
|
153
|
+
delete normalizedHint["x-flow"];
|
|
154
|
+
}
|
|
155
|
+
return normalizedHint;
|
|
156
|
+
}
|
|
157
|
+
__name(normalizeFlowHint, "normalizeFlowHint");
|
|
158
|
+
function normalizeSchemaHints(hints) {
|
|
159
|
+
return Array.isArray(hints) ? import_lodash.default.uniqBy(
|
|
160
|
+
hints.map((item) => normalizeFlowHint(item)),
|
|
161
|
+
(item) => `${item.kind}:${item.path || ""}:${item.message}`
|
|
162
|
+
) : [];
|
|
163
|
+
}
|
|
164
|
+
__name(normalizeSchemaHints, "normalizeSchemaHints");
|
|
165
|
+
function normalizeSchemaDocs(docs) {
|
|
166
|
+
return {
|
|
167
|
+
description: docs == null ? void 0 : docs.description,
|
|
168
|
+
examples: Array.isArray(docs == null ? void 0 : docs.examples) ? import_lodash.default.cloneDeep(docs.examples) : [],
|
|
169
|
+
minimalExample: (docs == null ? void 0 : docs.minimalExample) === void 0 ? void 0 : import_lodash.default.cloneDeep(docs.minimalExample),
|
|
170
|
+
commonPatterns: Array.isArray(docs == null ? void 0 : docs.commonPatterns) ? import_lodash.default.cloneDeep(docs.commonPatterns) : [],
|
|
171
|
+
antiPatterns: Array.isArray(docs == null ? void 0 : docs.antiPatterns) ? import_lodash.default.cloneDeep(docs.antiPatterns) : [],
|
|
172
|
+
dynamicHints: normalizeSchemaHints(docs == null ? void 0 : docs.dynamicHints)
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
__name(normalizeSchemaDocs, "normalizeSchemaDocs");
|
|
176
|
+
function normalizeStringArray(values) {
|
|
177
|
+
if (!Array.isArray(values)) {
|
|
178
|
+
return [];
|
|
179
|
+
}
|
|
180
|
+
return import_lodash.default.uniq(values.map((item) => String(item || "").trim()).filter(Boolean));
|
|
181
|
+
}
|
|
182
|
+
__name(normalizeStringArray, "normalizeStringArray");
|
|
183
|
+
function createFlowHint(hint, metadata) {
|
|
184
|
+
const result = { ...hint };
|
|
185
|
+
const flowMetadata = normalizeFlowHintMetadata({
|
|
186
|
+
...hint["x-flow"] || {},
|
|
187
|
+
...metadata || {}
|
|
188
|
+
});
|
|
189
|
+
if (flowMetadata) {
|
|
190
|
+
result["x-flow"] = flowMetadata;
|
|
191
|
+
} else {
|
|
192
|
+
delete result["x-flow"];
|
|
193
|
+
}
|
|
194
|
+
return result;
|
|
195
|
+
}
|
|
196
|
+
__name(createFlowHint, "createFlowHint");
|
|
197
|
+
function collectAllowedUses(slot) {
|
|
198
|
+
if (!slot) {
|
|
199
|
+
return [];
|
|
200
|
+
}
|
|
201
|
+
if (Array.isArray(slot.uses)) {
|
|
202
|
+
return slot.uses.filter(Boolean);
|
|
203
|
+
}
|
|
204
|
+
return slot.use ? [slot.use] : [];
|
|
205
|
+
}
|
|
206
|
+
__name(collectAllowedUses, "collectAllowedUses");
|
|
207
|
+
function buildSkeletonFromSchema(schema, options = {}) {
|
|
208
|
+
var _a, _b;
|
|
209
|
+
if (!schema) return void 0;
|
|
210
|
+
if (schema.default !== void 0) return import_lodash.default.cloneDeep(schema.default);
|
|
211
|
+
if (schema.const !== void 0) return import_lodash.default.cloneDeep(schema.const);
|
|
212
|
+
if (Array.isArray(schema.enum) && schema.enum.length > 0) return import_lodash.default.cloneDeep(schema.enum[0]);
|
|
213
|
+
const depth = options.depth || 0;
|
|
214
|
+
if (depth > 4) {
|
|
215
|
+
return void 0;
|
|
216
|
+
}
|
|
217
|
+
const type = Array.isArray(schema.type) ? schema.type[0] : schema.type;
|
|
218
|
+
if (type === "object" || !type && import_lodash.default.isPlainObject(schema.properties)) {
|
|
219
|
+
const result = {};
|
|
220
|
+
const properties = schema.properties || {};
|
|
221
|
+
const required = new Set(schema.required || []);
|
|
222
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
223
|
+
const child = buildSkeletonFromSchema(value, {
|
|
224
|
+
propertyName: key,
|
|
225
|
+
depth: depth + 1
|
|
226
|
+
});
|
|
227
|
+
const includeOptionalTopLevelShell = depth === 0 && ["stepParams", "subModels", "flowRegistry"].includes(key) && child !== void 0 && (import_lodash.default.isPlainObject(child) && Object.keys(child).length > 0 || Array.isArray(child));
|
|
228
|
+
if (!includeOptionalTopLevelShell && !required.has(key) && value.default === void 0 && value.const === void 0) {
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
if (child !== void 0) {
|
|
232
|
+
result[key] = child;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
if (type === "array") {
|
|
238
|
+
return [];
|
|
239
|
+
}
|
|
240
|
+
if (type === "boolean") {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
if (type === "integer" || type === "number") {
|
|
244
|
+
return 0;
|
|
245
|
+
}
|
|
246
|
+
if (type === "string") {
|
|
247
|
+
const propertyName = options.propertyName || "value";
|
|
248
|
+
if (propertyName === "uid") {
|
|
249
|
+
return "todo-uid";
|
|
250
|
+
}
|
|
251
|
+
return "";
|
|
252
|
+
}
|
|
253
|
+
if ((_a = schema.oneOf) == null ? void 0 : _a.length) {
|
|
254
|
+
return buildSkeletonFromSchema(schema.oneOf[0], {
|
|
255
|
+
propertyName: options.propertyName,
|
|
256
|
+
depth: depth + 1
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
if ((_b = schema.anyOf) == null ? void 0 : _b.length) {
|
|
260
|
+
return buildSkeletonFromSchema(schema.anyOf[0], {
|
|
261
|
+
propertyName: options.propertyName,
|
|
262
|
+
depth: depth + 1
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
return void 0;
|
|
266
|
+
}
|
|
267
|
+
__name(buildSkeletonFromSchema, "buildSkeletonFromSchema");
|
|
268
|
+
function toSchemaTitle(input, fallback) {
|
|
269
|
+
if (typeof input === "string") {
|
|
270
|
+
return input;
|
|
271
|
+
}
|
|
272
|
+
if (typeof input === "number" || typeof input === "boolean") {
|
|
273
|
+
return String(input);
|
|
274
|
+
}
|
|
275
|
+
return fallback;
|
|
276
|
+
}
|
|
277
|
+
__name(toSchemaTitle, "toSchemaTitle");
|
|
278
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
279
|
+
0 && (module.exports = {
|
|
280
|
+
JSON_SCHEMA_DRAFT_07,
|
|
281
|
+
buildSkeletonFromSchema,
|
|
282
|
+
collectAllowedUses,
|
|
283
|
+
createFlowHint,
|
|
284
|
+
deepFreezePlainGraph,
|
|
285
|
+
deepMergeReplaceArrays,
|
|
286
|
+
hashString,
|
|
287
|
+
mergeSchemas,
|
|
288
|
+
normalizeSchemaDocs,
|
|
289
|
+
normalizeSchemaHints,
|
|
290
|
+
normalizeStringArray,
|
|
291
|
+
stableStringify,
|
|
292
|
+
toSchemaTitle
|
|
293
|
+
});
|
package/lib/flowEngine.js
CHANGED
|
@@ -1140,7 +1140,10 @@ const _FlowEngine = class _FlowEngine {
|
|
|
1140
1140
|
if (hydrated) {
|
|
1141
1141
|
return hydrated;
|
|
1142
1142
|
}
|
|
1143
|
-
const
|
|
1143
|
+
const shouldUseEnsure = !(extra == null ? void 0 : extra.skipSave) && !uid && !!parentId && !!subKey && (options == null ? void 0 : options.subType) === "object";
|
|
1144
|
+
const data = shouldUseEnsure ? await this._modelRepository.ensure(options, {
|
|
1145
|
+
includeAsyncNode: !!((options == null ? void 0 : options.includeAsyncNode) || (options == null ? void 0 : options.async))
|
|
1146
|
+
}) ?? await this._modelRepository.findOne(options) : await this._modelRepository.findOne(options);
|
|
1144
1147
|
let model = null;
|
|
1145
1148
|
if (data == null ? void 0 : data.uid) {
|
|
1146
1149
|
model = await this.createModelAsync(data, extra);
|
package/lib/index.d.ts
CHANGED
|
@@ -34,5 +34,6 @@ export { getSnippetBody, listSnippetsForContext, registerRunJSSnippet } from './
|
|
|
34
34
|
export * from './views';
|
|
35
35
|
export { DATA_SOURCE_DIRTY_EVENT, ENGINE_SCOPE_KEY, getEmitterViewActivatedVersion, VIEW_ACTIVATED_EVENT, VIEW_ACTIVATED_VERSION, VIEW_ENGINE_SCOPE, } from './views/viewEvents';
|
|
36
36
|
export * from './FlowDefinition';
|
|
37
|
+
export * from './FlowSchemaRegistry';
|
|
37
38
|
export { createViewScopedEngine } from './ViewScopedFlowEngine';
|
|
38
39
|
export { createBlockScopedEngine } from './BlockScopedFlowEngine';
|
package/lib/index.js
CHANGED
|
@@ -75,6 +75,7 @@ var import_snippets = require("./runjs-context/snippets");
|
|
|
75
75
|
__reExport(src_exports, require("./views"), module.exports);
|
|
76
76
|
var import_viewEvents = require("./views/viewEvents");
|
|
77
77
|
__reExport(src_exports, require("./FlowDefinition"), module.exports);
|
|
78
|
+
__reExport(src_exports, require("./FlowSchemaRegistry"), module.exports);
|
|
78
79
|
var import_ViewScopedFlowEngine = require("./ViewScopedFlowEngine");
|
|
79
80
|
var import_BlockScopedFlowEngine = require("./BlockScopedFlowEngine");
|
|
80
81
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -116,5 +117,6 @@ var import_BlockScopedFlowEngine = require("./BlockScopedFlowEngine");
|
|
|
116
117
|
...require("./FlowContextProvider"),
|
|
117
118
|
...require("./JSRunner"),
|
|
118
119
|
...require("./views"),
|
|
119
|
-
...require("./FlowDefinition")
|
|
120
|
+
...require("./FlowDefinition"),
|
|
121
|
+
...require("./FlowSchemaRegistry")
|
|
120
122
|
});
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
-
import { DefaultStructure } from '
|
|
9
|
+
import { DefaultStructure } from '../types';
|
|
10
10
|
import { CollectionFieldModel } from './CollectionFieldModel';
|
|
11
11
|
export declare class DisplayItemModel<T extends DefaultStructure = DefaultStructure> extends CollectionFieldModel<T> {
|
|
12
12
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
-
import { DefaultStructure } from '
|
|
9
|
+
import { DefaultStructure } from '../types';
|
|
10
10
|
import { CollectionFieldModel } from './CollectionFieldModel';
|
|
11
11
|
export declare class EditableItemModel<T extends DefaultStructure = DefaultStructure> extends CollectionFieldModel<T> {
|
|
12
12
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
-
import { DefaultStructure } from '
|
|
9
|
+
import { DefaultStructure } from '../types';
|
|
10
10
|
import { CollectionFieldModel } from './CollectionFieldModel';
|
|
11
11
|
export declare class FilterableItemModel<T extends DefaultStructure = DefaultStructure> extends CollectionFieldModel<T> {
|
|
12
12
|
}
|
|
@@ -73,6 +73,7 @@ async function setupRunJSContexts() {
|
|
|
73
73
|
import_registry.RunJSContextRegistry.register(version, "JSFieldModel", JSFieldRunJSContext, { scenes: ["detail"] });
|
|
74
74
|
import_registry.RunJSContextRegistry.register(version, "JSEditableFieldModel", JSEditableFieldRunJSContext, { scenes: ["form"] });
|
|
75
75
|
import_registry.RunJSContextRegistry.register(version, "JSItemModel", JSItemRunJSContext, { scenes: ["form"] });
|
|
76
|
+
import_registry.RunJSContextRegistry.register(version, "JSItemActionModel", JSItemRunJSContext, { scenes: ["table"] });
|
|
76
77
|
import_registry.RunJSContextRegistry.register(version, "JSColumnModel", JSColumnRunJSContext, { scenes: ["table"] });
|
|
77
78
|
import_registry.RunJSContextRegistry.register(version, "FormJSFieldItemModel", FormJSFieldItemRunJSContext, { scenes: ["form"] });
|
|
78
79
|
import_registry.RunJSContextRegistry.register(version, "JSRecordActionModel", JSRecordActionRunJSContext, { scenes: ["table"] });
|
package/lib/server.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
export * from './types';
|
|
10
|
+
export * from './FlowSchemaRegistry';
|
package/lib/server.js
ADDED
|
@@ -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
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var server_exports = {};
|
|
25
|
+
module.exports = __toCommonJS(server_exports);
|
|
26
|
+
__reExport(server_exports, require("./types"), module.exports);
|
|
27
|
+
__reExport(server_exports, require("./FlowSchemaRegistry"), module.exports);
|
|
28
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
+
0 && (module.exports = {
|
|
30
|
+
...require("./types"),
|
|
31
|
+
...require("./FlowSchemaRegistry")
|
|
32
|
+
});
|