@flowgram.ai/test-run-plugin 0.1.0-alpha.20

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 (51) hide show
  1. package/.eslintrc.cjs +17 -0
  2. package/.rush/temp/chunked-rush-logs/test-run-plugin.build.chunks.jsonl +21 -0
  3. package/.rush/temp/package-deps_build.json +47 -0
  4. package/.rush/temp/shrinkwrap-deps.json +161 -0
  5. package/dist/esm/index.js +731 -0
  6. package/dist/esm/index.js.map +1 -0
  7. package/dist/index.d.mts +314 -0
  8. package/dist/index.d.ts +314 -0
  9. package/dist/index.js +770 -0
  10. package/dist/index.js.map +1 -0
  11. package/package.json +56 -0
  12. package/rush-logs/test-run-plugin.build.log +21 -0
  13. package/src/create-test-run-plugin.ts +39 -0
  14. package/src/form-engine/contexts.ts +16 -0
  15. package/src/form-engine/fields/create-field.tsx +32 -0
  16. package/src/form-engine/fields/general-field.tsx +35 -0
  17. package/src/form-engine/fields/index.ts +9 -0
  18. package/src/form-engine/fields/object-field.tsx +21 -0
  19. package/src/form-engine/fields/reactive-field.tsx +57 -0
  20. package/src/form-engine/fields/recursion-field.tsx +31 -0
  21. package/src/form-engine/fields/schema-field.tsx +32 -0
  22. package/src/form-engine/form/form.tsx +38 -0
  23. package/src/form-engine/form/index.ts +6 -0
  24. package/src/form-engine/hooks/index.ts +8 -0
  25. package/src/form-engine/hooks/use-create-form.ts +69 -0
  26. package/src/form-engine/hooks/use-field.ts +13 -0
  27. package/src/form-engine/hooks/use-form.ts +13 -0
  28. package/src/form-engine/index.ts +19 -0
  29. package/src/form-engine/model/index.ts +89 -0
  30. package/src/form-engine/types.ts +56 -0
  31. package/src/form-engine/utils.ts +64 -0
  32. package/src/index.ts +22 -0
  33. package/src/reactive/hooks/index.ts +7 -0
  34. package/src/reactive/hooks/use-create-form.ts +90 -0
  35. package/src/reactive/hooks/use-test-run-service.ts +10 -0
  36. package/src/reactive/index.ts +6 -0
  37. package/src/services/config.ts +42 -0
  38. package/src/services/form/factory.ts +9 -0
  39. package/src/services/form/form.ts +78 -0
  40. package/src/services/form/index.ts +8 -0
  41. package/src/services/form/manager.ts +43 -0
  42. package/src/services/index.ts +14 -0
  43. package/src/services/pipeline/factory.ts +9 -0
  44. package/src/services/pipeline/index.ts +12 -0
  45. package/src/services/pipeline/pipeline.ts +143 -0
  46. package/src/services/pipeline/plugin.ts +11 -0
  47. package/src/services/pipeline/tap.ts +34 -0
  48. package/src/services/store.ts +27 -0
  49. package/src/services/test-run.ts +100 -0
  50. package/src/types.ts +29 -0
  51. package/tsconfig.json +12 -0
@@ -0,0 +1,314 @@
1
+ import * as _flowgram_ai_core from '@flowgram.ai/core';
2
+ import { FlowNodeType, FlowNodeEntity } from '@flowgram.ai/document';
3
+ import * as React$1 from 'react';
4
+ import React__default, { ReactNode } from 'react';
5
+ import { Validate, FieldState, ValidateTrigger, IForm } from '@flowgram.ai/form';
6
+ import * as _flowgram_ai_utils from '@flowgram.ai/utils';
7
+ import { Emitter, Disposable } from '@flowgram.ai/utils';
8
+ import { StoreApi, StateCreator } from 'zustand';
9
+ import { interfaces } from 'inversify';
10
+ import { OnFormValuesChangePayload } from '@flowgram.ai/form-core';
11
+ import { ReactiveState } from '@flowgram.ai/reactive';
12
+
13
+ /**
14
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
15
+ * SPDX-License-Identifier: MIT
16
+ */
17
+
18
+ /** field type */
19
+ type FormSchemaType = 'string' | 'number' | 'boolean' | 'object' | string;
20
+ type FormSchemaValidate = Validate;
21
+ interface FormSchema {
22
+ /** core */
23
+ name?: string;
24
+ type?: FormSchemaType;
25
+ defaultValue?: any;
26
+ /** children */
27
+ properties?: Record<string, FormSchema>;
28
+ /** ui */
29
+ title?: string | React__default.ReactNode;
30
+ description?: string | React__default.ReactNode;
31
+ ['x-index']?: number;
32
+ ['x-visible']?: boolean;
33
+ ['x-hidden']?: boolean;
34
+ ['x-component']?: string;
35
+ ['x-component-props']?: Record<string, unknown>;
36
+ ['x-decorator']?: string;
37
+ ['x-decorator-props']?: Record<string, unknown>;
38
+ /** rule */
39
+ required?: boolean;
40
+ ['x-validator']?: FormSchemaValidate;
41
+ /** custom */
42
+ [key: string]: any;
43
+ }
44
+ type FormComponentProps = {
45
+ type?: FormSchemaType;
46
+ disabled?: boolean;
47
+ [key: string]: any;
48
+ } & FormSchema['x-component-props'] & FormSchema['x-decorator-props'] & Partial<FieldState>;
49
+ type FormComponent = React__default.FunctionComponent<any>;
50
+ type FormComponents = Record<string, FormComponent>;
51
+ /** ui state */
52
+ interface FormSchemaModelState {
53
+ disabled: boolean;
54
+ }
55
+
56
+ /**
57
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
58
+ * SPDX-License-Identifier: MIT
59
+ */
60
+
61
+ declare class FormSchemaModel implements FormSchema {
62
+ name?: string;
63
+ type?: FormSchemaType;
64
+ defaultValue?: any;
65
+ properties?: Record<string, FormSchema>;
66
+ ['x-index']?: number;
67
+ ['x-component']?: string;
68
+ ['x-component-props']?: Record<string, unknown>;
69
+ ['x-decorator']?: string;
70
+ ['x-decorator-props']?: Record<string, unknown>;
71
+ [key: string]: any;
72
+ path: string[];
73
+ state: ReactiveState<FormSchemaModelState>;
74
+ get componentType(): string | undefined;
75
+ get componentProps(): Record<string, unknown> | undefined;
76
+ get decoratorType(): string | undefined;
77
+ get decoratorProps(): Record<string, unknown> | undefined;
78
+ get uniqueName(): string;
79
+ constructor(json: FormSchema, path?: string[]);
80
+ private fromJSON;
81
+ getPropertyList(): FormSchemaModel[];
82
+ }
83
+
84
+ interface FormInstance {
85
+ model: FormSchemaModel;
86
+ form: IForm;
87
+ }
88
+ interface UseCreateFormOptions {
89
+ defaultValues?: any;
90
+ validate?: Record<string, FormSchemaValidate>;
91
+ validateTrigger?: ValidateTrigger;
92
+ onMounted?: (form: FormInstance) => void;
93
+ onFormValuesChange?: (payload: OnFormValuesChangePayload) => void;
94
+ onUnmounted?: () => void;
95
+ }
96
+
97
+ /**
98
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
99
+ * SPDX-License-Identifier: MIT
100
+ */
101
+
102
+ type FormEngineProps = React.PropsWithChildren<{
103
+ /** Form schema */
104
+ schema: FormSchema;
105
+ /** form material map */
106
+ components?: FormComponents;
107
+ } & UseCreateFormOptions>;
108
+ declare const FormEngine: React.FC<FormEngineProps>;
109
+
110
+ declare const connect: <T = any>(Component: React.FunctionComponent<any>, mapProps: (p: FormComponentProps) => T) => (props: FormComponentProps) => React$1.FunctionComponentElement<any>;
111
+
112
+ type FormRenderProps = Omit<FormEngineProps, 'schema' | 'components' | 'onMounted' | 'onUnmounted'>;
113
+ declare class TestRunFormEntity {
114
+ private readonly config;
115
+ private _schema;
116
+ private initialized;
117
+ id: string;
118
+ form: FormInstance | null;
119
+ onFormMountedEmitter: Emitter<FormInstance>;
120
+ onFormMounted: _flowgram_ai_utils.Event<FormInstance>;
121
+ onFormUnmountedEmitter: Emitter<void>;
122
+ onFormUnmounted: _flowgram_ai_utils.Event<void>;
123
+ get schema(): FormSchema;
124
+ init(options: {
125
+ schema: FormSchema;
126
+ }): void;
127
+ render(props?: FormRenderProps): ReactNode;
128
+ dispose(): void;
129
+ }
130
+
131
+ /**
132
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
133
+ * SPDX-License-Identifier: MIT
134
+ */
135
+
136
+ declare class TestRunFormManager {
137
+ private readonly factory;
138
+ private entities;
139
+ createForm(): TestRunFormEntity;
140
+ getForm(id: string): TestRunFormEntity | undefined;
141
+ getAllForm(): [string, TestRunFormEntity][];
142
+ disposeForm(id: string): void;
143
+ disposeAllForm(): void;
144
+ }
145
+
146
+ /**
147
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
148
+ * SPDX-License-Identifier: MIT
149
+ */
150
+
151
+ type MaybePromise<T> = T | Promise<T>;
152
+
153
+ /**
154
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
155
+ * SPDX-License-Identifier: MIT
156
+ */
157
+
158
+ interface TapValue<T> {
159
+ name: string;
160
+ fn: (arg: T) => MaybePromise<void>;
161
+ }
162
+ declare class Tap<T> {
163
+ private taps;
164
+ private frozen;
165
+ tap(name: string, fn: TapValue<T>['fn']): void;
166
+ call(ctx: T): Promise<void>;
167
+ freeze(): void;
168
+ }
169
+
170
+ /**
171
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
172
+ * SPDX-License-Identifier: MIT
173
+ */
174
+
175
+ interface TestRunPipelinePlugin {
176
+ name: string;
177
+ apply(pipeline: TestRunPipelineEntity): void;
178
+ }
179
+
180
+ /**
181
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
182
+ * SPDX-License-Identifier: MIT
183
+ */
184
+
185
+ /**
186
+ * 包含 Store 的 Service
187
+ */
188
+ declare class StoreService<State> {
189
+ store: StoreApi<State>;
190
+ get getState(): () => State;
191
+ get setState(): {
192
+ (partial: State | Partial<State> | ((state: State) => State | Partial<State>), replace?: false): void;
193
+ (state: State | ((state: State) => State), replace: true): void;
194
+ };
195
+ constructor(stateCreator: StateCreator<State>);
196
+ }
197
+
198
+ interface TestRunPipelineEntityOptions {
199
+ plugins: (new () => TestRunPipelinePlugin)[];
200
+ }
201
+ interface TestRunPipelineEntityState<T = any> {
202
+ status: 'idle' | 'preparing' | 'executing' | 'canceled' | 'finished';
203
+ data?: T;
204
+ result?: any;
205
+ getData: () => T;
206
+ setData: (next: any) => void;
207
+ }
208
+ interface TestRunPipelineEntityCtx<T = any> {
209
+ id: string;
210
+ store: StoreApi<TestRunPipelineEntityState<T>>;
211
+ operate: {
212
+ update: (data: any) => void;
213
+ cancel: () => void;
214
+ };
215
+ }
216
+ declare class TestRunPipelineEntity extends StoreService<TestRunPipelineEntityState> {
217
+ container: interfaces.Container | undefined;
218
+ id: string;
219
+ prepare: Tap<TestRunPipelineEntityCtx<any>>;
220
+ private execute?;
221
+ private progress?;
222
+ get status(): TestRunPipelineEntityState["status"];
223
+ set status(next: TestRunPipelineEntityState['status']);
224
+ onProgressEmitter: Emitter<any>;
225
+ onProgress: _flowgram_ai_utils.Event<any>;
226
+ onFinishedEmitter: Emitter<any>;
227
+ onFinished: _flowgram_ai_utils.Event<any>;
228
+ constructor();
229
+ init(options: TestRunPipelineEntityOptions): void;
230
+ registerExecute(fn: (ctx: TestRunPipelineEntityCtx) => Promise<void> | void): void;
231
+ registerProgress(fn: (ctx: TestRunPipelineEntityCtx) => Promise<void> | void): void;
232
+ start<T>(options?: {
233
+ data: T;
234
+ }): Promise<void>;
235
+ update(result: any): void;
236
+ cancel(): void;
237
+ dispose(): void;
238
+ }
239
+
240
+ declare class TestRunService {
241
+ private readonly config;
242
+ private readonly pipelineFactory;
243
+ readonly formManager: TestRunFormManager;
244
+ pipelineEntities: Map<string, TestRunPipelineEntity>;
245
+ pipelineBindings: Map<string, Disposable>;
246
+ onPipelineProgressEmitter: Emitter<any>;
247
+ onPipelineProgress: _flowgram_ai_utils.Event<any>;
248
+ onPipelineFinishedEmitter: Emitter<any>;
249
+ onPipelineFinished: _flowgram_ai_utils.Event<any>;
250
+ isEnabled(nodeType: FlowNodeType): boolean;
251
+ toSchema(node: FlowNodeEntity): Promise<{
252
+ type?: undefined;
253
+ properties?: undefined;
254
+ } | {
255
+ type: string;
256
+ properties: Record<string, FormSchema> | undefined;
257
+ }>;
258
+ createFormWithSchema(schema: FormSchema): TestRunFormEntity;
259
+ createForm(node: FlowNodeEntity): Promise<TestRunFormEntity>;
260
+ createPipeline(options: TestRunPipelineEntityOptions): TestRunPipelineEntity;
261
+ connectPipeline(pipeline: TestRunPipelineEntity): void;
262
+ disconnectPipeline(id: string): void;
263
+ disconnectAllPipeline(): void;
264
+ }
265
+
266
+ /**
267
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
268
+ * SPDX-License-Identifier: MIT
269
+ */
270
+
271
+ type PropertiesFunctionParams = {
272
+ node: FlowNodeEntity;
273
+ };
274
+ type NodeMap = Record<FlowNodeType, NodeTestConfig>;
275
+ interface NodeTestConfig {
276
+ /** Enable node TestRun */
277
+ enabled?: boolean;
278
+ /** Input schema properties */
279
+ properties?: Record<string, FormSchema> | ((params: PropertiesFunctionParams) => MaybePromise<Record<string, FormSchema>>);
280
+ }
281
+ interface TestRunConfig {
282
+ components: FormComponents;
283
+ nodes: NodeMap;
284
+ plugins: (new () => TestRunPipelinePlugin)[];
285
+ }
286
+ declare const TestRunConfig: unique symbol;
287
+
288
+ declare const createTestRunPlugin: _flowgram_ai_core.PluginCreator<Partial<TestRunConfig>>;
289
+
290
+ interface UseFormOptions {
291
+ node?: FlowNodeEntity;
292
+ /** form loading */
293
+ loadingRenderer?: React.ReactNode;
294
+ /** form empty */
295
+ emptyRenderer?: React.ReactNode;
296
+ defaultValues?: FormEngineProps['defaultValues'];
297
+ onMounted?: FormEngineProps['onMounted'];
298
+ onUnmounted?: FormEngineProps['onUnmounted'];
299
+ onFormValuesChange?: FormEngineProps['onFormValuesChange'];
300
+ }
301
+ declare const useCreateForm: ({ node, loadingRenderer, emptyRenderer, defaultValues, onMounted, onUnmounted, onFormValuesChange, }: UseFormOptions) => {
302
+ renderer: React$1.ReactNode;
303
+ loading: boolean;
304
+ form: TestRunFormEntity | null;
305
+ };
306
+
307
+ /**
308
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
309
+ * SPDX-License-Identifier: MIT
310
+ */
311
+
312
+ declare const useTestRunService: () => TestRunService;
313
+
314
+ export { type FormComponentProps, FormEngine, type FormEngineProps, type FormInstance, type FormSchema, TestRunPipelineEntity, type TestRunPipelineEntityCtx, type TestRunPipelinePlugin, connect, createTestRunPlugin, useCreateForm, useTestRunService };