@nocobase/flow-engine 2.1.0-alpha.12 → 2.1.0-alpha.13
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 +0 -4
- package/lib/index.d.ts +0 -1
- package/lib/index.js +1 -3
- 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/snippets/index.js +13 -2
- package/lib/{server.d.ts → runjs-context/snippets/scene/detail/set-field-style.snippet.d.ts} +3 -2
- package/lib/{server.js → runjs-context/snippets/scene/detail/set-field-style.snippet.js} +27 -9
- package/{src/server.ts → lib/runjs-context/snippets/scene/table/set-cell-style.snippet.d.ts} +3 -3
- package/lib/runjs-context/snippets/scene/table/set-cell-style.snippet.js +54 -0
- package/lib/types.d.ts +0 -221
- package/package.json +4 -4
- package/src/__tests__/runjsSnippets.test.ts +21 -0
- package/src/index.ts +0 -1
- 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/snippets/index.ts +12 -1
- package/src/runjs-context/snippets/scene/detail/set-field-style.snippet.ts +30 -0
- package/src/runjs-context/snippets/scene/table/set-cell-style.snippet.ts +34 -0
- package/src/types.ts +0 -262
- package/lib/FlowSchemaRegistry.d.ts +0 -154
- package/lib/FlowSchemaRegistry.js +0 -1427
- package/lib/flow-schema-registry/fieldBinding.d.ts +0 -32
- package/lib/flow-schema-registry/fieldBinding.js +0 -165
- package/lib/flow-schema-registry/modelPatches.d.ts +0 -16
- package/lib/flow-schema-registry/modelPatches.js +0 -235
- package/lib/flow-schema-registry/schemaInference.d.ts +0 -17
- package/lib/flow-schema-registry/schemaInference.js +0 -207
- package/lib/flow-schema-registry/utils.d.ts +0 -25
- package/lib/flow-schema-registry/utils.js +0 -293
- package/server.d.ts +0 -1
- package/server.js +0 -1
- package/src/FlowSchemaRegistry.ts +0 -1799
- package/src/__tests__/FlowSchemaRegistry.test.ts +0 -1951
- package/src/flow-schema-registry/fieldBinding.ts +0 -171
- package/src/flow-schema-registry/modelPatches.ts +0 -260
- package/src/flow-schema-registry/schemaInference.ts +0 -210
- package/src/flow-schema-registry/utils.ts +0 -268
|
@@ -1,268 +0,0 @@
|
|
|
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
|
-
import _ from 'lodash';
|
|
11
|
-
import type { FlowDynamicHint, FlowJsonSchema, FlowSchemaDocs, FlowSubModelSlotSchema } from '../types';
|
|
12
|
-
|
|
13
|
-
export const JSON_SCHEMA_DRAFT_07 = 'http://json-schema.org/draft-07/schema#';
|
|
14
|
-
|
|
15
|
-
export function stableStringify(input: any): string {
|
|
16
|
-
if (Array.isArray(input)) {
|
|
17
|
-
return `[${input.map((item) => stableStringify(item)).join(',')}]`;
|
|
18
|
-
}
|
|
19
|
-
if (_.isPlainObject(input)) {
|
|
20
|
-
const entries = Object.entries(input)
|
|
21
|
-
.sort(([a], [b]) => a.localeCompare(b))
|
|
22
|
-
.map(([key, value]) => `${JSON.stringify(key)}:${stableStringify(value)}`);
|
|
23
|
-
return `{${entries.join(',')}}`;
|
|
24
|
-
}
|
|
25
|
-
return JSON.stringify(input) ?? 'null';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function deepFreezePlainGraph<T>(input: T, seen = new WeakSet<object>()): T {
|
|
29
|
-
if (Array.isArray(input)) {
|
|
30
|
-
if (seen.has(input)) {
|
|
31
|
-
return input;
|
|
32
|
-
}
|
|
33
|
-
seen.add(input);
|
|
34
|
-
for (const item of input) {
|
|
35
|
-
deepFreezePlainGraph(item, seen);
|
|
36
|
-
}
|
|
37
|
-
return Object.freeze(input);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (!_.isPlainObject(input)) {
|
|
41
|
-
return input;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const objectValue = input as Record<string, any>;
|
|
45
|
-
if (seen.has(objectValue)) {
|
|
46
|
-
return input;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
seen.add(objectValue);
|
|
50
|
-
for (const value of Object.values(objectValue)) {
|
|
51
|
-
deepFreezePlainGraph(value, seen);
|
|
52
|
-
}
|
|
53
|
-
return Object.freeze(objectValue) as T;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function hashString(input: string): string {
|
|
57
|
-
let hash = 0;
|
|
58
|
-
for (let index = 0; index < input.length; index++) {
|
|
59
|
-
hash = (hash * 31 + input.charCodeAt(index)) >>> 0;
|
|
60
|
-
}
|
|
61
|
-
return hash.toString(16).padStart(8, '0');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function deepMergeReplaceArrays<T>(base: T, patch: any): T {
|
|
65
|
-
if (typeof patch === 'undefined') {
|
|
66
|
-
return _.cloneDeep(base);
|
|
67
|
-
}
|
|
68
|
-
if (typeof base === 'undefined') {
|
|
69
|
-
return _.cloneDeep(patch);
|
|
70
|
-
}
|
|
71
|
-
return _.mergeWith({}, _.cloneDeep(base), _.cloneDeep(patch), (_objValue, srcValue) => {
|
|
72
|
-
if (Array.isArray(srcValue)) {
|
|
73
|
-
return _.cloneDeep(srcValue);
|
|
74
|
-
}
|
|
75
|
-
return undefined;
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function mergeSchemas(base?: FlowJsonSchema, patch?: FlowJsonSchema): FlowJsonSchema | undefined {
|
|
80
|
-
if (!base && !patch) return undefined;
|
|
81
|
-
if (!base) return _.cloneDeep(patch);
|
|
82
|
-
if (!patch) return _.cloneDeep(base);
|
|
83
|
-
return deepMergeReplaceArrays(base, patch);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function normalizeFlowHintMetadata(metadata?: FlowDynamicHint['x-flow']): FlowDynamicHint['x-flow'] | undefined {
|
|
87
|
-
if (!metadata || typeof metadata !== 'object' || Array.isArray(metadata)) {
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const slotRules =
|
|
92
|
-
metadata.slotRules && typeof metadata.slotRules === 'object' && !Array.isArray(metadata.slotRules)
|
|
93
|
-
? _.pickBy(
|
|
94
|
-
{
|
|
95
|
-
slotKey: metadata.slotRules.slotKey,
|
|
96
|
-
type: metadata.slotRules.type,
|
|
97
|
-
allowedUses: Array.isArray(metadata.slotRules.allowedUses)
|
|
98
|
-
? metadata.slotRules.allowedUses.filter(Boolean)
|
|
99
|
-
: metadata.slotRules.allowedUses,
|
|
100
|
-
},
|
|
101
|
-
(value) => value !== undefined,
|
|
102
|
-
)
|
|
103
|
-
: undefined;
|
|
104
|
-
|
|
105
|
-
const normalized = _.pickBy(
|
|
106
|
-
{
|
|
107
|
-
slotRules: slotRules && Object.keys(slotRules).length > 0 ? slotRules : undefined,
|
|
108
|
-
contextRequirements: Array.isArray(metadata.contextRequirements)
|
|
109
|
-
? metadata.contextRequirements.filter(Boolean)
|
|
110
|
-
: metadata.contextRequirements,
|
|
111
|
-
unresolvedReason: metadata.unresolvedReason,
|
|
112
|
-
recommendedFallback: metadata.recommendedFallback,
|
|
113
|
-
},
|
|
114
|
-
(value) => value !== undefined,
|
|
115
|
-
) as FlowDynamicHint['x-flow'];
|
|
116
|
-
|
|
117
|
-
return Object.keys(normalized).length > 0 ? normalized : undefined;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function normalizeFlowHint(hint: FlowDynamicHint): FlowDynamicHint {
|
|
121
|
-
const normalizedHint = { ...hint };
|
|
122
|
-
const flowMetadata = normalizeFlowHintMetadata(hint['x-flow']);
|
|
123
|
-
if (flowMetadata) {
|
|
124
|
-
normalizedHint['x-flow'] = flowMetadata;
|
|
125
|
-
} else {
|
|
126
|
-
delete normalizedHint['x-flow'];
|
|
127
|
-
}
|
|
128
|
-
return normalizedHint;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export function normalizeSchemaHints(hints?: FlowDynamicHint[]): FlowDynamicHint[] {
|
|
132
|
-
return Array.isArray(hints)
|
|
133
|
-
? _.uniqBy(
|
|
134
|
-
hints.map((item) => normalizeFlowHint(item)),
|
|
135
|
-
(item) => `${item.kind}:${item.path || ''}:${item.message}`,
|
|
136
|
-
)
|
|
137
|
-
: [];
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export function normalizeSchemaDocs(docs?: FlowSchemaDocs): FlowSchemaDocs {
|
|
141
|
-
return {
|
|
142
|
-
description: docs?.description,
|
|
143
|
-
examples: Array.isArray(docs?.examples) ? _.cloneDeep(docs.examples) : [],
|
|
144
|
-
minimalExample: docs?.minimalExample === undefined ? undefined : _.cloneDeep(docs.minimalExample),
|
|
145
|
-
commonPatterns: Array.isArray(docs?.commonPatterns) ? _.cloneDeep(docs.commonPatterns) : [],
|
|
146
|
-
antiPatterns: Array.isArray(docs?.antiPatterns) ? _.cloneDeep(docs.antiPatterns) : [],
|
|
147
|
-
dynamicHints: normalizeSchemaHints(docs?.dynamicHints),
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export function normalizeStringArray(values?: string[]): string[] {
|
|
152
|
-
if (!Array.isArray(values)) {
|
|
153
|
-
return [];
|
|
154
|
-
}
|
|
155
|
-
return _.uniq(values.map((item) => String(item || '').trim()).filter(Boolean));
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export function createFlowHint(hint: FlowDynamicHint, metadata?: FlowDynamicHint['x-flow']): FlowDynamicHint {
|
|
159
|
-
const result = { ...hint };
|
|
160
|
-
const flowMetadata = normalizeFlowHintMetadata({
|
|
161
|
-
...(hint['x-flow'] || {}),
|
|
162
|
-
...(metadata || {}),
|
|
163
|
-
});
|
|
164
|
-
if (flowMetadata) {
|
|
165
|
-
result['x-flow'] = flowMetadata;
|
|
166
|
-
} else {
|
|
167
|
-
delete result['x-flow'];
|
|
168
|
-
}
|
|
169
|
-
return result;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export function collectAllowedUses(slot?: FlowSubModelSlotSchema): string[] {
|
|
173
|
-
if (!slot) {
|
|
174
|
-
return [];
|
|
175
|
-
}
|
|
176
|
-
if (Array.isArray(slot.uses)) {
|
|
177
|
-
return slot.uses.filter(Boolean);
|
|
178
|
-
}
|
|
179
|
-
return slot.use ? [slot.use] : [];
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export function buildSkeletonFromSchema(
|
|
183
|
-
schema?: FlowJsonSchema,
|
|
184
|
-
options: {
|
|
185
|
-
propertyName?: string;
|
|
186
|
-
depth?: number;
|
|
187
|
-
} = {},
|
|
188
|
-
): any {
|
|
189
|
-
if (!schema) return undefined;
|
|
190
|
-
if (schema.default !== undefined) return _.cloneDeep(schema.default);
|
|
191
|
-
if (schema.const !== undefined) return _.cloneDeep(schema.const);
|
|
192
|
-
if (Array.isArray(schema.enum) && schema.enum.length > 0) return _.cloneDeep(schema.enum[0]);
|
|
193
|
-
|
|
194
|
-
const depth = options.depth || 0;
|
|
195
|
-
if (depth > 4) {
|
|
196
|
-
return undefined;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const type = Array.isArray(schema.type) ? schema.type[0] : schema.type;
|
|
200
|
-
if (type === 'object' || (!type && _.isPlainObject(schema.properties))) {
|
|
201
|
-
const result: Record<string, any> = {};
|
|
202
|
-
const properties = (schema.properties || {}) as Record<string, FlowJsonSchema>;
|
|
203
|
-
const required = new Set<string>(schema.required || []);
|
|
204
|
-
for (const [key, value] of Object.entries(properties)) {
|
|
205
|
-
const child = buildSkeletonFromSchema(value, {
|
|
206
|
-
propertyName: key,
|
|
207
|
-
depth: depth + 1,
|
|
208
|
-
});
|
|
209
|
-
const includeOptionalTopLevelShell =
|
|
210
|
-
depth === 0 &&
|
|
211
|
-
['stepParams', 'subModels', 'flowRegistry'].includes(key) &&
|
|
212
|
-
child !== undefined &&
|
|
213
|
-
((_.isPlainObject(child) && Object.keys(child).length > 0) || Array.isArray(child));
|
|
214
|
-
if (
|
|
215
|
-
!includeOptionalTopLevelShell &&
|
|
216
|
-
!required.has(key) &&
|
|
217
|
-
value.default === undefined &&
|
|
218
|
-
value.const === undefined
|
|
219
|
-
) {
|
|
220
|
-
continue;
|
|
221
|
-
}
|
|
222
|
-
if (child !== undefined) {
|
|
223
|
-
result[key] = child;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
return result;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
if (type === 'array') {
|
|
230
|
-
return [];
|
|
231
|
-
}
|
|
232
|
-
if (type === 'boolean') {
|
|
233
|
-
return false;
|
|
234
|
-
}
|
|
235
|
-
if (type === 'integer' || type === 'number') {
|
|
236
|
-
return 0;
|
|
237
|
-
}
|
|
238
|
-
if (type === 'string') {
|
|
239
|
-
const propertyName = options.propertyName || 'value';
|
|
240
|
-
if (propertyName === 'uid') {
|
|
241
|
-
return 'todo-uid';
|
|
242
|
-
}
|
|
243
|
-
return '';
|
|
244
|
-
}
|
|
245
|
-
if (schema.oneOf?.length) {
|
|
246
|
-
return buildSkeletonFromSchema(schema.oneOf[0], {
|
|
247
|
-
propertyName: options.propertyName,
|
|
248
|
-
depth: depth + 1,
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
if (schema.anyOf?.length) {
|
|
252
|
-
return buildSkeletonFromSchema(schema.anyOf[0], {
|
|
253
|
-
propertyName: options.propertyName,
|
|
254
|
-
depth: depth + 1,
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
return undefined;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
export function toSchemaTitle(input: any, fallback: string): string {
|
|
261
|
-
if (typeof input === 'string') {
|
|
262
|
-
return input;
|
|
263
|
-
}
|
|
264
|
-
if (typeof input === 'number' || typeof input === 'boolean') {
|
|
265
|
-
return String(input);
|
|
266
|
-
}
|
|
267
|
-
return fallback;
|
|
268
|
-
}
|