@nocobase/flow-engine 2.1.0-alpha.10 → 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.
Files changed (46) hide show
  1. package/lib/FlowDefinition.d.ts +4 -0
  2. package/lib/FlowSchemaRegistry.d.ts +154 -0
  3. package/lib/FlowSchemaRegistry.js +1427 -0
  4. package/lib/components/subModel/AddSubModelButton.js +11 -0
  5. package/lib/flow-schema-registry/fieldBinding.d.ts +32 -0
  6. package/lib/flow-schema-registry/fieldBinding.js +165 -0
  7. package/lib/flow-schema-registry/modelPatches.d.ts +16 -0
  8. package/lib/flow-schema-registry/modelPatches.js +235 -0
  9. package/lib/flow-schema-registry/schemaInference.d.ts +17 -0
  10. package/lib/flow-schema-registry/schemaInference.js +207 -0
  11. package/lib/flow-schema-registry/utils.d.ts +25 -0
  12. package/lib/flow-schema-registry/utils.js +293 -0
  13. package/lib/flowEngine.js +4 -1
  14. package/lib/index.d.ts +1 -0
  15. package/lib/index.js +3 -1
  16. package/lib/models/DisplayItemModel.d.ts +1 -1
  17. package/lib/models/EditableItemModel.d.ts +1 -1
  18. package/lib/models/FilterableItemModel.d.ts +1 -1
  19. package/lib/runjs-context/setup.js +1 -0
  20. package/lib/server.d.ts +10 -0
  21. package/lib/server.js +32 -0
  22. package/lib/types.d.ts +233 -0
  23. package/package.json +4 -4
  24. package/server.d.ts +1 -0
  25. package/server.js +1 -0
  26. package/src/FlowSchemaRegistry.ts +1799 -0
  27. package/src/__tests__/FlowSchemaRegistry.test.ts +1951 -0
  28. package/src/__tests__/flow-engine.test.ts +48 -0
  29. package/src/__tests__/flowEngine.modelLoaders.test.ts +5 -1
  30. package/src/__tests__/flowEngine.saveModel.test.ts +4 -0
  31. package/src/__tests__/runjsContext.test.ts +3 -0
  32. package/src/__tests__/runjsContextRuntime.test.ts +2 -0
  33. package/src/components/subModel/AddSubModelButton.tsx +15 -1
  34. package/src/components/subModel/__tests__/AddSubModelButton.test.tsx +1 -0
  35. package/src/flow-schema-registry/fieldBinding.ts +171 -0
  36. package/src/flow-schema-registry/modelPatches.ts +260 -0
  37. package/src/flow-schema-registry/schemaInference.ts +210 -0
  38. package/src/flow-schema-registry/utils.ts +268 -0
  39. package/src/flowEngine.ts +7 -1
  40. package/src/index.ts +1 -0
  41. package/src/models/DisplayItemModel.tsx +1 -1
  42. package/src/models/EditableItemModel.tsx +1 -1
  43. package/src/models/FilterableItemModel.tsx +1 -1
  44. package/src/runjs-context/setup.ts +1 -0
  45. package/src/server.ts +11 -0
  46. package/src/types.ts +273 -0
package/lib/types.d.ts CHANGED
@@ -30,6 +30,221 @@ export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
30
30
  export type DeepPartial<T> = {
31
31
  [P in keyof T]?: T[P] extends (infer U)[] ? DeepPartial<U>[] : T[P] extends Record<string, any> ? DeepPartial<T[P]> : T[P] extends object ? DeepPartial<T[P]> : T[P];
32
32
  };
33
+ export type FlowJsonSchema = Record<string, any> & {
34
+ $schema?: string;
35
+ $id?: string;
36
+ };
37
+ export interface FlowDynamicHintMetadata {
38
+ slotRules?: {
39
+ slotKey?: string;
40
+ type?: 'object' | 'array';
41
+ allowedUses?: string[];
42
+ };
43
+ contextRequirements?: string[];
44
+ unresolvedReason?: string;
45
+ recommendedFallback?: any;
46
+ }
47
+ export interface FlowDynamicHint {
48
+ kind: 'dynamic-ui-schema' | 'dynamic-children' | 'custom-component' | 'x-reactions' | 'unresolved-action' | 'manual-schema-required' | 'unresolved-model';
49
+ path?: string;
50
+ message: string;
51
+ 'x-flow'?: FlowDynamicHintMetadata;
52
+ }
53
+ export interface FlowSchemaCoverage {
54
+ status: 'auto' | 'manual' | 'mixed' | 'unresolved';
55
+ source: 'official' | 'plugin' | 'third-party';
56
+ strict?: boolean;
57
+ issues?: string[];
58
+ }
59
+ export type FlowModelSchemaExposure = 'public' | 'internal';
60
+ export interface FlowSchemaPattern {
61
+ title: string;
62
+ description?: string;
63
+ snippet?: any;
64
+ }
65
+ export interface FlowSchemaDocument {
66
+ use: string;
67
+ title?: string;
68
+ jsonSchema: FlowJsonSchema;
69
+ coverage: FlowSchemaCoverage;
70
+ dynamicHints: FlowDynamicHint[];
71
+ examples: any[];
72
+ minimalExample?: any;
73
+ commonPatterns: FlowSchemaPattern[];
74
+ antiPatterns: FlowSchemaPattern[];
75
+ skeleton: any;
76
+ hash: string;
77
+ source: FlowSchemaCoverage['source'];
78
+ }
79
+ export type FlowSchemaDetail = 'compact' | 'full';
80
+ export interface FlowSchemaPublicDocument {
81
+ use: string;
82
+ title?: string;
83
+ jsonSchema: FlowJsonSchema;
84
+ dynamicHints: FlowDynamicHint[];
85
+ minimalExample?: any;
86
+ commonPatterns: FlowSchemaPattern[];
87
+ antiPatterns: FlowSchemaPattern[];
88
+ hash: string;
89
+ source: FlowSchemaCoverage['source'];
90
+ }
91
+ export interface FlowSchemaDocs {
92
+ description?: string;
93
+ examples?: any[];
94
+ minimalExample?: any;
95
+ commonPatterns?: FlowSchemaPattern[];
96
+ antiPatterns?: FlowSchemaPattern[];
97
+ dynamicHints?: FlowDynamicHint[];
98
+ }
99
+ export interface FlowSchemaBundleSlotCatalog {
100
+ type: 'object' | 'array';
101
+ required?: boolean;
102
+ minItems?: number;
103
+ open?: boolean;
104
+ candidates: FlowSchemaBundleNode[];
105
+ }
106
+ export interface FlowSchemaBundleNode {
107
+ use: string;
108
+ title?: string;
109
+ compatibility?: FlowFieldModelCompatibility;
110
+ subModelCatalog?: Record<string, FlowSchemaBundleSlotCatalog>;
111
+ }
112
+ export type FlowSchemaBundleItem = FlowSchemaBundleNode;
113
+ export interface FlowSchemaBundleDocument {
114
+ items: FlowSchemaBundleNode[];
115
+ }
116
+ export interface FlowSchemaContextEdge {
117
+ parentUse: string;
118
+ slotKey: string;
119
+ childUse: string;
120
+ }
121
+ export interface FlowSubModelContextPathStep {
122
+ slotKey: string;
123
+ use?: string | string[];
124
+ }
125
+ export interface FlowModelSchemaPatch {
126
+ stepParamsSchema?: FlowJsonSchema;
127
+ flowRegistrySchema?: FlowJsonSchema;
128
+ subModelSlots?: Record<string, FlowSubModelSlotSchema>;
129
+ flowRegistrySchemaPatch?: FlowJsonSchema;
130
+ docs?: FlowSchemaDocs;
131
+ examples?: any[];
132
+ skeleton?: any;
133
+ dynamicHints?: FlowDynamicHint[];
134
+ }
135
+ export interface FlowDescendantSchemaPatch {
136
+ path: FlowSubModelContextPathStep[];
137
+ patch: FlowModelSchemaPatch;
138
+ }
139
+ export interface FlowSubModelSlotSchema {
140
+ type: 'object' | 'array';
141
+ use?: string;
142
+ uses?: string[];
143
+ required?: boolean;
144
+ minItems?: number;
145
+ dynamic?: boolean;
146
+ schema?: FlowJsonSchema;
147
+ fieldBindingContext?: string;
148
+ childSchemaPatch?: FlowModelSchemaPatch | Record<string, FlowModelSchemaPatch>;
149
+ descendantSchemaPatches?: FlowDescendantSchemaPatch[];
150
+ description?: string;
151
+ }
152
+ export interface FlowModelSchemaMeta {
153
+ stepParamsSchema?: FlowJsonSchema;
154
+ flowRegistrySchema?: FlowJsonSchema;
155
+ subModelSlots?: Record<string, FlowSubModelSlotSchema>;
156
+ flowRegistrySchemaPatch?: FlowJsonSchema;
157
+ docs?: FlowSchemaDocs;
158
+ examples?: any[];
159
+ skeleton?: any;
160
+ dynamicHints?: FlowDynamicHint[];
161
+ source?: FlowSchemaCoverage['source'];
162
+ strict?: boolean;
163
+ exposure?: FlowModelSchemaExposure;
164
+ abstract?: boolean;
165
+ allowDirectUse?: boolean;
166
+ suggestedUses?: string[];
167
+ }
168
+ export interface FlowActionSchemaContribution {
169
+ name: string;
170
+ title?: string;
171
+ paramsSchema?: FlowJsonSchema;
172
+ docs?: FlowSchemaDocs;
173
+ source?: FlowSchemaCoverage['source'];
174
+ strict?: boolean;
175
+ }
176
+ export interface FlowModelSchemaContribution {
177
+ use: string;
178
+ title?: string;
179
+ stepParamsSchema?: FlowJsonSchema;
180
+ flowRegistrySchema?: FlowJsonSchema;
181
+ subModelSlots?: Record<string, FlowSubModelSlotSchema>;
182
+ flowRegistrySchemaPatch?: FlowJsonSchema;
183
+ docs?: FlowSchemaDocs;
184
+ examples?: any[];
185
+ skeleton?: any;
186
+ dynamicHints?: FlowDynamicHint[];
187
+ source?: FlowSchemaCoverage['source'];
188
+ strict?: boolean;
189
+ exposure?: FlowModelSchemaExposure;
190
+ abstract?: boolean;
191
+ allowDirectUse?: boolean;
192
+ suggestedUses?: string[];
193
+ }
194
+ export interface FlowSchemaContributionDefaults {
195
+ source?: FlowSchemaCoverage['source'];
196
+ strict?: boolean;
197
+ }
198
+ export interface FlowSchemaSlotUseExpansion {
199
+ parentUse: string;
200
+ slotKey: string;
201
+ uses: string[];
202
+ }
203
+ export interface FlowSchemaInventoryContribution {
204
+ publicTreeRoots?: string[];
205
+ slotUseExpansions?: FlowSchemaSlotUseExpansion[];
206
+ }
207
+ export interface FlowFieldBindingConditions {
208
+ association?: boolean;
209
+ fieldTypes?: string[];
210
+ targetCollectionTemplateIn?: string[];
211
+ targetCollectionTemplateNotIn?: string[];
212
+ }
213
+ export interface FlowFieldBindingContextContribution {
214
+ name: string;
215
+ inherits?: string[];
216
+ }
217
+ export interface FlowFieldBindingContribution {
218
+ context: string;
219
+ use: string;
220
+ interfaces: string[];
221
+ isDefault?: boolean;
222
+ order?: number;
223
+ conditions?: FlowFieldBindingConditions;
224
+ defaultProps?: any;
225
+ }
226
+ export interface FlowFieldModelCompatibility {
227
+ context: string;
228
+ interfaces: string[];
229
+ isDefault?: boolean;
230
+ order?: number;
231
+ association?: boolean;
232
+ fieldTypes?: string[];
233
+ targetCollectionTemplateIn?: string[];
234
+ targetCollectionTemplateNotIn?: string[];
235
+ inheritParentFieldBinding?: boolean;
236
+ }
237
+ export interface FlowSchemaContribution {
238
+ models?: FlowModelSchemaContribution[] | Record<string, FlowModelSchemaContribution>;
239
+ actions?: FlowActionSchemaContribution[] | Record<string, FlowActionSchemaContribution>;
240
+ fieldBindingContexts?: FlowFieldBindingContextContribution[] | Record<string, FlowFieldBindingContextContribution>;
241
+ fieldBindings?: FlowFieldBindingContribution[] | Record<string, FlowFieldBindingContribution | FlowFieldBindingContribution[]>;
242
+ inventory?: FlowSchemaInventoryContribution;
243
+ defaults?: FlowSchemaContributionDefaults;
244
+ }
245
+ export interface FlowSchemaContributionProvider {
246
+ getFlowSchemaContributions(): FlowSchemaContribution | undefined | Promise<FlowSchemaContribution | undefined>;
247
+ }
33
248
  /**
34
249
  * Defines a flow with generic model type support.
35
250
  */
@@ -130,6 +345,9 @@ export interface ActionDefinition<TModel extends FlowModel = FlowModel, TCtx ext
130
345
  title?: string;
131
346
  handler: (ctx: TCtx, params: any) => Promise<any> | any;
132
347
  uiSchema?: Record<string, ISchema> | ((ctx: TCtx) => Record<string, ISchema> | Promise<Record<string, ISchema>>);
348
+ paramsSchema?: FlowJsonSchema;
349
+ paramsSchemaPatch?: FlowJsonSchema;
350
+ schemaDocs?: FlowSchemaDocs;
133
351
  defaultParams?: Record<string, any> | ((ctx: TCtx) => Record<string, any> | Promise<Record<string, any>>);
134
352
  beforeParamsSave?: (ctx: FlowSettingsContext<TModel>, params: any, previousParams: any) => void | Promise<void>;
135
353
  afterParamsSave?: (ctx: FlowSettingsContext<TModel>, params: any, previousParams: any) => void | Promise<void>;
@@ -228,6 +446,8 @@ export interface StepDefinition<TModel extends FlowModel = FlowModel> extends Pa
228
446
  use?: string;
229
447
  sort?: number;
230
448
  preset?: boolean;
449
+ paramsSchemaOverride?: FlowJsonSchema;
450
+ schemaDocs?: FlowSchemaDocs;
231
451
  uiMode?: StepUIMode | ((ctx: FlowRuntimeContext<TModel>) => StepUIMode | Promise<StepUIMode>);
232
452
  }
233
453
  /**
@@ -340,6 +560,18 @@ export interface EnsureBatchResult {
340
560
  }
341
561
  export interface IFlowModelRepository<T extends FlowModel = FlowModel> {
342
562
  findOne(query: Record<string, any>): Promise<Record<string, any> | null>;
563
+ /**
564
+ * Ensure a model exists (create if missing) in a single request.
565
+ */
566
+ ensure: (values: Record<string, any>, options?: {
567
+ includeAsyncNode?: boolean;
568
+ }) => Promise<Record<string, any> | null>;
569
+ /**
570
+ * Optional: run multiple ops in a single transaction (server capability).
571
+ */
572
+ mutate?: (values: Record<string, any>, options?: {
573
+ includeAsyncNode?: boolean;
574
+ }) => Promise<Record<string, any>>;
343
575
  save(model: T, options?: {
344
576
  onlyStepParams?: boolean;
345
577
  }): Promise<Record<string, any>>;
@@ -452,6 +684,7 @@ export type FlowModelMeta = Pick<SubModelItem, 'key' | 'label' | 'icon' | 'child
452
684
  label: string;
453
685
  value: string;
454
686
  }[];
687
+ schema?: FlowModelSchemaMeta;
455
688
  };
456
689
  /**
457
690
  * 字段 FlowModel 的专用元数据接口
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/flow-engine",
3
- "version": "2.1.0-alpha.10",
3
+ "version": "2.1.0-alpha.11",
4
4
  "private": false,
5
5
  "description": "A standalone flow engine for NocoBase, managing workflows, models, and actions.",
6
6
  "main": "lib/index.js",
@@ -8,8 +8,8 @@
8
8
  "dependencies": {
9
9
  "@formily/antd-v5": "1.x",
10
10
  "@formily/reactive": "2.x",
11
- "@nocobase/sdk": "2.1.0-alpha.10",
12
- "@nocobase/shared": "2.1.0-alpha.10",
11
+ "@nocobase/sdk": "2.1.0-alpha.11",
12
+ "@nocobase/shared": "2.1.0-alpha.11",
13
13
  "ahooks": "^3.7.2",
14
14
  "dayjs": "^1.11.9",
15
15
  "dompurify": "^3.0.2",
@@ -36,5 +36,5 @@
36
36
  ],
37
37
  "author": "NocoBase Team",
38
38
  "license": "Apache-2.0",
39
- "gitHead": "ce790d46c0a5768ca9618c7d0d77ab8300de75c8"
39
+ "gitHead": "bb96d633a6371afb586072ff516bd0613c757db0"
40
40
  }
package/server.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './src/server';
package/server.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = process.env.IS_DEV_CMD || process.env.VITEST ? require('./src/server.ts') : require('./lib/server');