@flowgram-vue/test-run-plugin 0.2.0
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/LICENSE +22 -0
- package/dist/index.cjs +765 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +408 -0
- package/dist/index.js +759 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
- package/src/create-test-run-plugin.ts +39 -0
- package/src/env.d.ts +10 -0
- package/src/form-engine/contexts.ts +16 -0
- package/src/form-engine/fields/create-field.ts +41 -0
- package/src/form-engine/fields/general-field.ts +42 -0
- package/src/form-engine/fields/index.ts +9 -0
- package/src/form-engine/fields/object-field.ts +25 -0
- package/src/form-engine/fields/reactive-field.ts +55 -0
- package/src/form-engine/fields/recursion-field.ts +28 -0
- package/src/form-engine/fields/schema-field.ts +29 -0
- package/src/form-engine/form/form.ts +57 -0
- package/src/form-engine/form/index.ts +6 -0
- package/src/form-engine/hooks/index.ts +8 -0
- package/src/form-engine/hooks/use-create-form.ts +63 -0
- package/src/form-engine/hooks/use-field.ts +19 -0
- package/src/form-engine/hooks/use-form.ts +19 -0
- package/src/form-engine/index.ts +19 -0
- package/src/form-engine/model/index.ts +89 -0
- package/src/form-engine/types.ts +56 -0
- package/src/form-engine/utils.ts +69 -0
- package/src/index.ts +23 -0
- package/src/reactive/hooks/index.ts +7 -0
- package/src/reactive/hooks/use-create-form.ts +101 -0
- package/src/reactive/hooks/use-test-run-service.ts +10 -0
- package/src/reactive/index.ts +6 -0
- package/src/services/config.ts +42 -0
- package/src/services/form/factory.ts +9 -0
- package/src/services/form/form.ts +77 -0
- package/src/services/form/index.ts +8 -0
- package/src/services/form/manager.ts +43 -0
- package/src/services/index.ts +14 -0
- package/src/services/pipeline/factory.ts +9 -0
- package/src/services/pipeline/index.ts +12 -0
- package/src/services/pipeline/pipeline.ts +155 -0
- package/src/services/pipeline/plugin.ts +13 -0
- package/src/services/pipeline/tap.ts +34 -0
- package/src/services/store.ts +27 -0
- package/src/services/test-run.ts +108 -0
- package/src/types.ts +29 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,759 @@
|
|
|
1
|
+
import { definePluginCreator, useService } from '@flowgram-vue/core';
|
|
2
|
+
import { defineComponent, inject, h, provide, onBeforeUnmount, ref, shallowRef, computed, watch } from 'vue';
|
|
3
|
+
import { nanoid } from 'nanoid';
|
|
4
|
+
import { inject as inject$1, injectable, unmanaged } from 'inversify';
|
|
5
|
+
import { Emitter, DisposableCollection } from '@flowgram-vue/utils';
|
|
6
|
+
import { Field, Form, createForm, ValidateTrigger } from '@flowgram-vue/form';
|
|
7
|
+
import { useObserve, ReactiveState } from '@flowgram-vue/reactive';
|
|
8
|
+
import { createStore } from 'zustand/vanilla';
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
13
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
14
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
15
|
+
if (decorator = decorators[i])
|
|
16
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
17
|
+
if (kind && result) __defProp(target, key, result);
|
|
18
|
+
return result;
|
|
19
|
+
};
|
|
20
|
+
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
21
|
+
|
|
22
|
+
// src/services/config.ts
|
|
23
|
+
var TestRunConfig = /* @__PURE__ */ Symbol("TestRunConfig");
|
|
24
|
+
var defineConfig = (config) => {
|
|
25
|
+
const defaultConfig = {
|
|
26
|
+
components: {},
|
|
27
|
+
nodes: {},
|
|
28
|
+
plugins: []
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
...defaultConfig,
|
|
32
|
+
...config
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
var getUniqueFieldName = (...args) => args.filter((path) => path).join(".");
|
|
36
|
+
var mergeFieldPath = (path, name) => [...path || [], name].filter((i) => Boolean(i));
|
|
37
|
+
var createValidate = (schema) => {
|
|
38
|
+
const rules = {};
|
|
39
|
+
visit(schema);
|
|
40
|
+
return rules;
|
|
41
|
+
function visit(current, name) {
|
|
42
|
+
if (name && current["x-validator"]) {
|
|
43
|
+
rules[name] = current["x-validator"];
|
|
44
|
+
}
|
|
45
|
+
if (current.type === "object" && current.properties) {
|
|
46
|
+
Object.entries(current.properties).forEach(([key, value]) => {
|
|
47
|
+
visit(value, getUniqueFieldName(name, key));
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var connect = (Comp, mapProps) => {
|
|
53
|
+
const Connected = defineComponent({
|
|
54
|
+
name: "ConnectedFormComponent",
|
|
55
|
+
setup(props, { slots }) {
|
|
56
|
+
return () => {
|
|
57
|
+
const mappedProps = mapProps(props);
|
|
58
|
+
return h(Comp, mappedProps, () => slots.default?.() ?? mappedProps.children);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return Connected;
|
|
63
|
+
};
|
|
64
|
+
var isFormEmpty = (schema) => {
|
|
65
|
+
const isEmpty = (s) => {
|
|
66
|
+
if (!s.type || s.type === "object" || !s.name) {
|
|
67
|
+
return Object.entries(schema.properties || {}).map(([key, value]) => ({
|
|
68
|
+
name: key,
|
|
69
|
+
...value
|
|
70
|
+
})).every(isFormEmpty);
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
};
|
|
74
|
+
return isEmpty(schema);
|
|
75
|
+
};
|
|
76
|
+
var FormSchemaModel = class _FormSchemaModel {
|
|
77
|
+
constructor(json, path = []) {
|
|
78
|
+
this.path = [];
|
|
79
|
+
this.state = new ReactiveState({ disabled: false });
|
|
80
|
+
this.fromJSON(json);
|
|
81
|
+
this.path = path;
|
|
82
|
+
}
|
|
83
|
+
get componentType() {
|
|
84
|
+
return this["x-component"];
|
|
85
|
+
}
|
|
86
|
+
get componentProps() {
|
|
87
|
+
return this["x-component-props"];
|
|
88
|
+
}
|
|
89
|
+
get decoratorType() {
|
|
90
|
+
return this["x-decorator"];
|
|
91
|
+
}
|
|
92
|
+
get decoratorProps() {
|
|
93
|
+
return this["x-decorator-props"];
|
|
94
|
+
}
|
|
95
|
+
get uniqueName() {
|
|
96
|
+
return getUniqueFieldName(...this.path);
|
|
97
|
+
}
|
|
98
|
+
fromJSON(json) {
|
|
99
|
+
Object.entries(json).forEach(([key, value]) => {
|
|
100
|
+
this[key] = value;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
getPropertyList() {
|
|
104
|
+
const orderProperties = [];
|
|
105
|
+
const unOrderProperties = [];
|
|
106
|
+
Object.entries(this.properties || {}).forEach(([key, item]) => {
|
|
107
|
+
const index = item["x-index"];
|
|
108
|
+
const defaultValues = this.defaultValue;
|
|
109
|
+
if (typeof defaultValues === "object" && defaultValues !== null && key in defaultValues) {
|
|
110
|
+
item.defaultValue = defaultValues[key];
|
|
111
|
+
}
|
|
112
|
+
const current = new _FormSchemaModel(item, mergeFieldPath(this.path, key));
|
|
113
|
+
if (index !== void 0 && !isNaN(index)) {
|
|
114
|
+
orderProperties[index] = current;
|
|
115
|
+
} else {
|
|
116
|
+
unOrderProperties.push(current);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
return orderProperties.concat(unOrderProperties).filter((item) => !!item);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// src/form-engine/hooks/use-create-form.ts
|
|
124
|
+
var useCreateForm = (schema, options = {}) => {
|
|
125
|
+
const { form, control } = createForm({
|
|
126
|
+
validate: {
|
|
127
|
+
...createValidate(schema),
|
|
128
|
+
...options.validate
|
|
129
|
+
},
|
|
130
|
+
validateTrigger: options.validateTrigger ?? ValidateTrigger.onBlur
|
|
131
|
+
});
|
|
132
|
+
const model = new FormSchemaModel({
|
|
133
|
+
type: "object",
|
|
134
|
+
...schema,
|
|
135
|
+
defaultValue: options.defaultValues
|
|
136
|
+
});
|
|
137
|
+
if (options.onMounted) {
|
|
138
|
+
options.onMounted({ model, form });
|
|
139
|
+
}
|
|
140
|
+
const disposable = control._formModel.onFormValuesChange((payload) => {
|
|
141
|
+
if (options.onFormValuesChange) {
|
|
142
|
+
options.onFormValuesChange(payload);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
onBeforeUnmount(() => {
|
|
146
|
+
disposable.dispose();
|
|
147
|
+
if (options.onUnmounted) {
|
|
148
|
+
options.onUnmounted();
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
return {
|
|
152
|
+
form,
|
|
153
|
+
control,
|
|
154
|
+
model
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// src/form-engine/contexts.ts
|
|
159
|
+
var FieldModelKey = /* @__PURE__ */ Symbol("FieldModelContext");
|
|
160
|
+
var FormModelKey = /* @__PURE__ */ Symbol("FormModelContext");
|
|
161
|
+
var ComponentsKey = /* @__PURE__ */ Symbol("ComponentsContext");
|
|
162
|
+
|
|
163
|
+
// src/form-engine/hooks/use-field.ts
|
|
164
|
+
var useFieldModel = () => {
|
|
165
|
+
const model = inject(FieldModelKey);
|
|
166
|
+
if (!model) {
|
|
167
|
+
throw new Error("useFieldModel must be used within FieldModelKey provider");
|
|
168
|
+
}
|
|
169
|
+
return model;
|
|
170
|
+
};
|
|
171
|
+
var useFieldState = () => useObserve(useFieldModel().state.value);
|
|
172
|
+
var useFormModel = () => {
|
|
173
|
+
const model = inject(FormModelKey);
|
|
174
|
+
if (!model) {
|
|
175
|
+
throw new Error("useFormModel must be used within FormModelKey provider");
|
|
176
|
+
}
|
|
177
|
+
return model;
|
|
178
|
+
};
|
|
179
|
+
var useFormState = () => useObserve(useFormModel().state.value);
|
|
180
|
+
var ReactiveField = defineComponent({
|
|
181
|
+
name: "ReactiveField",
|
|
182
|
+
props: {
|
|
183
|
+
componentProps: { type: Object, default: void 0 },
|
|
184
|
+
decoratorProps: { type: Object, default: void 0 }
|
|
185
|
+
},
|
|
186
|
+
setup(props, { slots }) {
|
|
187
|
+
const formState = useFormState();
|
|
188
|
+
const model = useFieldModel();
|
|
189
|
+
const modelState = useFieldState();
|
|
190
|
+
const components = inject(ComponentsKey, {});
|
|
191
|
+
return () => {
|
|
192
|
+
const disabled = modelState.disabled || formState.disabled;
|
|
193
|
+
let children = slots.default?.();
|
|
194
|
+
if (model.componentType && components[model.componentType]) {
|
|
195
|
+
children = [
|
|
196
|
+
h(
|
|
197
|
+
components[model.componentType],
|
|
198
|
+
{
|
|
199
|
+
disabled,
|
|
200
|
+
...model.componentProps,
|
|
201
|
+
...props.componentProps
|
|
202
|
+
},
|
|
203
|
+
() => slots.default?.()
|
|
204
|
+
)
|
|
205
|
+
];
|
|
206
|
+
}
|
|
207
|
+
if (!model.decoratorType || !components[model.decoratorType]) {
|
|
208
|
+
return children;
|
|
209
|
+
}
|
|
210
|
+
return h(
|
|
211
|
+
components[model.decoratorType],
|
|
212
|
+
{
|
|
213
|
+
type: model.type,
|
|
214
|
+
required: model.required,
|
|
215
|
+
...model.decoratorProps,
|
|
216
|
+
...props.decoratorProps
|
|
217
|
+
},
|
|
218
|
+
() => children
|
|
219
|
+
);
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
// src/form-engine/fields/object-field.ts
|
|
225
|
+
var ObjectField = defineComponent({
|
|
226
|
+
name: "ObjectField",
|
|
227
|
+
props: {
|
|
228
|
+
model: { type: Object, required: true }
|
|
229
|
+
},
|
|
230
|
+
setup(props, { slots }) {
|
|
231
|
+
provide(FieldModelKey, props.model);
|
|
232
|
+
return () => h(ReactiveField, null, () => slots.default?.());
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
var GeneralField = defineComponent({
|
|
236
|
+
name: "GeneralField",
|
|
237
|
+
props: {
|
|
238
|
+
model: { type: Object, required: true }
|
|
239
|
+
},
|
|
240
|
+
setup(props) {
|
|
241
|
+
provide(FieldModelKey, props.model);
|
|
242
|
+
return () => h(Field, {
|
|
243
|
+
name: props.model.uniqueName,
|
|
244
|
+
defaultValue: props.model.defaultValue,
|
|
245
|
+
render: ({ field, fieldState }) => h(ReactiveField, {
|
|
246
|
+
componentProps: {
|
|
247
|
+
value: field.value,
|
|
248
|
+
onChange: field.onChange,
|
|
249
|
+
onFocus: field.onFocus,
|
|
250
|
+
onBlur: field.onBlur,
|
|
251
|
+
...fieldState
|
|
252
|
+
},
|
|
253
|
+
decoratorProps: fieldState
|
|
254
|
+
})
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
// src/form-engine/fields/recursion-field.ts
|
|
260
|
+
var RecursionField = defineComponent({
|
|
261
|
+
name: "RecursionField",
|
|
262
|
+
props: {
|
|
263
|
+
model: { type: Object, required: true }
|
|
264
|
+
},
|
|
265
|
+
setup(props) {
|
|
266
|
+
return () => {
|
|
267
|
+
const properties = props.model.getPropertyList();
|
|
268
|
+
if (props.model.type !== "object") {
|
|
269
|
+
return h(GeneralField, { model: props.model });
|
|
270
|
+
}
|
|
271
|
+
return h(
|
|
272
|
+
ObjectField,
|
|
273
|
+
{ model: props.model },
|
|
274
|
+
() => properties.map((item) => h(RecursionField, { key: item.uniqueName, model: item }))
|
|
275
|
+
);
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
// src/form-engine/fields/schema-field.ts
|
|
281
|
+
var SchemaField = defineComponent({
|
|
282
|
+
name: "SchemaField",
|
|
283
|
+
props: {
|
|
284
|
+
model: { type: Object, required: true },
|
|
285
|
+
components: { type: Object, default: () => ({}) }
|
|
286
|
+
},
|
|
287
|
+
setup(props, { slots }) {
|
|
288
|
+
provide(ComponentsKey, props.components || {});
|
|
289
|
+
provide(FormModelKey, props.model);
|
|
290
|
+
return () => [h(RecursionField, { model: props.model }), slots.default?.()];
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
var createSchemaField = (options) => {
|
|
294
|
+
const InnerSchemaField = defineComponent({
|
|
295
|
+
name: "InnerSchemaField",
|
|
296
|
+
props: {
|
|
297
|
+
model: { type: Object, required: true },
|
|
298
|
+
components: { type: Object, default: void 0 }
|
|
299
|
+
},
|
|
300
|
+
setup(props, { slots }) {
|
|
301
|
+
return () => h(
|
|
302
|
+
SchemaField,
|
|
303
|
+
{
|
|
304
|
+
model: props.model,
|
|
305
|
+
components: {
|
|
306
|
+
...options.components,
|
|
307
|
+
...props.components
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
() => slots.default?.()
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
return InnerSchemaField;
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
// src/form-engine/form/form.ts
|
|
318
|
+
var SchemaField2 = createSchemaField({});
|
|
319
|
+
var FormEngine = defineComponent({
|
|
320
|
+
name: "FormEngine",
|
|
321
|
+
props: {
|
|
322
|
+
schema: { type: Object, required: true },
|
|
323
|
+
components: { type: Object, default: void 0 },
|
|
324
|
+
defaultValues: { default: void 0 },
|
|
325
|
+
validate: { type: Object, default: void 0 },
|
|
326
|
+
validateTrigger: { default: void 0 },
|
|
327
|
+
onMounted: { type: Function, default: void 0 },
|
|
328
|
+
onFormValuesChange: {
|
|
329
|
+
type: Function,
|
|
330
|
+
default: void 0
|
|
331
|
+
},
|
|
332
|
+
onUnmounted: {
|
|
333
|
+
type: Function,
|
|
334
|
+
default: void 0
|
|
335
|
+
}
|
|
336
|
+
},
|
|
337
|
+
setup(props, { slots }) {
|
|
338
|
+
const { model, control } = useCreateForm(props.schema, {
|
|
339
|
+
defaultValues: props.defaultValues,
|
|
340
|
+
validate: props.validate,
|
|
341
|
+
validateTrigger: props.validateTrigger,
|
|
342
|
+
onMounted: props.onMounted,
|
|
343
|
+
onFormValuesChange: props.onFormValuesChange,
|
|
344
|
+
onUnmounted: props.onUnmounted
|
|
345
|
+
});
|
|
346
|
+
return () => h(
|
|
347
|
+
Form,
|
|
348
|
+
{ control },
|
|
349
|
+
() => h(SchemaField2, { model, components: props.components }, () => slots.default?.())
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
// src/services/form/form.ts
|
|
355
|
+
var TestRunFormEntity = class {
|
|
356
|
+
constructor() {
|
|
357
|
+
this.initialized = false;
|
|
358
|
+
this.id = nanoid();
|
|
359
|
+
this.form = null;
|
|
360
|
+
this.onFormMountedEmitter = new Emitter();
|
|
361
|
+
this.onFormMounted = this.onFormMountedEmitter.event;
|
|
362
|
+
this.onFormUnmountedEmitter = new Emitter();
|
|
363
|
+
this.onFormUnmounted = this.onFormUnmountedEmitter.event;
|
|
364
|
+
}
|
|
365
|
+
get schema() {
|
|
366
|
+
return this._schema;
|
|
367
|
+
}
|
|
368
|
+
init(options) {
|
|
369
|
+
if (this.initialized) return;
|
|
370
|
+
this._schema = options.schema;
|
|
371
|
+
this.initialized = true;
|
|
372
|
+
}
|
|
373
|
+
render(props) {
|
|
374
|
+
if (!this.initialized) {
|
|
375
|
+
return null;
|
|
376
|
+
}
|
|
377
|
+
const { children, ...restProps } = props || {};
|
|
378
|
+
return h(
|
|
379
|
+
FormEngine,
|
|
380
|
+
{
|
|
381
|
+
schema: this.schema,
|
|
382
|
+
components: this.config.components,
|
|
383
|
+
onMounted: (instance) => {
|
|
384
|
+
this.form = instance;
|
|
385
|
+
this.onFormMountedEmitter.fire(instance);
|
|
386
|
+
},
|
|
387
|
+
onUnmounted: this.onFormUnmountedEmitter.fire.bind(this.onFormUnmountedEmitter),
|
|
388
|
+
...restProps
|
|
389
|
+
},
|
|
390
|
+
() => children
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
dispose() {
|
|
394
|
+
this._schema = {};
|
|
395
|
+
this.form = null;
|
|
396
|
+
this.onFormMountedEmitter.dispose();
|
|
397
|
+
this.onFormUnmountedEmitter.dispose();
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
__decorateClass([
|
|
401
|
+
inject$1(TestRunConfig)
|
|
402
|
+
], TestRunFormEntity.prototype, "config", 2);
|
|
403
|
+
TestRunFormEntity = __decorateClass([
|
|
404
|
+
injectable()
|
|
405
|
+
], TestRunFormEntity);
|
|
406
|
+
|
|
407
|
+
// src/services/form/factory.ts
|
|
408
|
+
var TestRunFormFactory = /* @__PURE__ */ Symbol("TestRunFormFactory");
|
|
409
|
+
var TestRunFormManager = class {
|
|
410
|
+
constructor() {
|
|
411
|
+
this.entities = /* @__PURE__ */ new Map();
|
|
412
|
+
}
|
|
413
|
+
createForm() {
|
|
414
|
+
return this.factory();
|
|
415
|
+
}
|
|
416
|
+
getForm(id) {
|
|
417
|
+
return this.entities.get(id);
|
|
418
|
+
}
|
|
419
|
+
getAllForm() {
|
|
420
|
+
return Array.from(this.entities);
|
|
421
|
+
}
|
|
422
|
+
disposeForm(id) {
|
|
423
|
+
const form = this.entities.get(id);
|
|
424
|
+
if (!form) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
form.dispose();
|
|
428
|
+
this.entities.delete(id);
|
|
429
|
+
}
|
|
430
|
+
disposeAllForm() {
|
|
431
|
+
for (const id of this.entities.keys()) {
|
|
432
|
+
this.disposeForm(id);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
__decorateClass([
|
|
437
|
+
inject$1(TestRunFormFactory)
|
|
438
|
+
], TestRunFormManager.prototype, "factory", 2);
|
|
439
|
+
TestRunFormManager = __decorateClass([
|
|
440
|
+
injectable()
|
|
441
|
+
], TestRunFormManager);
|
|
442
|
+
|
|
443
|
+
// src/services/pipeline/factory.ts
|
|
444
|
+
var TestRunPipelineFactory = /* @__PURE__ */ Symbol("TestRunPipelineFactory");
|
|
445
|
+
|
|
446
|
+
// src/services/test-run.ts
|
|
447
|
+
var TestRunService = class {
|
|
448
|
+
constructor() {
|
|
449
|
+
this.pipelineEntities = /* @__PURE__ */ new Map();
|
|
450
|
+
this.pipelineBindings = /* @__PURE__ */ new Map();
|
|
451
|
+
this.onPipelineProgressEmitter = new Emitter();
|
|
452
|
+
this.onPipelineProgress = this.onPipelineProgressEmitter.event;
|
|
453
|
+
this.onPipelineFinishedEmitter = new Emitter();
|
|
454
|
+
this.onPipelineFinished = this.onPipelineFinishedEmitter.event;
|
|
455
|
+
}
|
|
456
|
+
isEnabled(nodeType) {
|
|
457
|
+
const config = this.config.nodes[nodeType];
|
|
458
|
+
return config && config?.enabled !== false;
|
|
459
|
+
}
|
|
460
|
+
async toSchema(node) {
|
|
461
|
+
const nodeType = node.flowNodeType;
|
|
462
|
+
const config = this.config.nodes[nodeType];
|
|
463
|
+
if (!this.isEnabled(nodeType)) {
|
|
464
|
+
return {};
|
|
465
|
+
}
|
|
466
|
+
const properties = typeof config.properties === "function" ? await config.properties({ node }) : config.properties;
|
|
467
|
+
return {
|
|
468
|
+
type: "object",
|
|
469
|
+
properties
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
createFormWithSchema(schema) {
|
|
473
|
+
const form = this.formManager.createForm();
|
|
474
|
+
form.init({ schema });
|
|
475
|
+
return form;
|
|
476
|
+
}
|
|
477
|
+
async createForm(node) {
|
|
478
|
+
const schema = await this.toSchema(node);
|
|
479
|
+
return this.createFormWithSchema(schema);
|
|
480
|
+
}
|
|
481
|
+
createPipeline(options) {
|
|
482
|
+
const pipeline = this.pipelineFactory();
|
|
483
|
+
this.pipelineEntities.set(pipeline.id, pipeline);
|
|
484
|
+
pipeline.init(options);
|
|
485
|
+
return pipeline;
|
|
486
|
+
}
|
|
487
|
+
disposePipeline(id) {
|
|
488
|
+
const pipeline = this.pipelineEntities.get(id);
|
|
489
|
+
if (pipeline) {
|
|
490
|
+
this.pipelineEntities.delete(id);
|
|
491
|
+
pipeline.dispose();
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
connectPipeline(pipeline) {
|
|
495
|
+
if (this.pipelineBindings.get(pipeline.id)) {
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
const disposable = new DisposableCollection(
|
|
499
|
+
pipeline.onProgress(this.onPipelineProgressEmitter.fire.bind(this.onPipelineProgressEmitter)),
|
|
500
|
+
pipeline.onFinished(this.onPipelineFinishedEmitter.fire.bind(this.onPipelineFinishedEmitter))
|
|
501
|
+
);
|
|
502
|
+
this.pipelineBindings.set(pipeline.id, disposable);
|
|
503
|
+
}
|
|
504
|
+
disconnectPipeline(id) {
|
|
505
|
+
if (this.pipelineBindings.has(id)) {
|
|
506
|
+
const disposable = this.pipelineBindings.get(id);
|
|
507
|
+
disposable?.dispose();
|
|
508
|
+
this.pipelineBindings.delete(id);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
disconnectAllPipeline() {
|
|
512
|
+
for (const id of this.pipelineBindings.keys()) {
|
|
513
|
+
this.disconnectPipeline(id);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
__decorateClass([
|
|
518
|
+
inject$1(TestRunConfig)
|
|
519
|
+
], TestRunService.prototype, "config", 2);
|
|
520
|
+
__decorateClass([
|
|
521
|
+
inject$1(TestRunPipelineFactory)
|
|
522
|
+
], TestRunService.prototype, "pipelineFactory", 2);
|
|
523
|
+
__decorateClass([
|
|
524
|
+
inject$1(TestRunFormManager)
|
|
525
|
+
], TestRunService.prototype, "formManager", 2);
|
|
526
|
+
TestRunService = __decorateClass([
|
|
527
|
+
injectable()
|
|
528
|
+
], TestRunService);
|
|
529
|
+
|
|
530
|
+
// src/services/pipeline/tap.ts
|
|
531
|
+
var Tap = class {
|
|
532
|
+
constructor() {
|
|
533
|
+
this.taps = [];
|
|
534
|
+
this.frozen = false;
|
|
535
|
+
}
|
|
536
|
+
tap(name, fn) {
|
|
537
|
+
this.taps.push({ name, fn });
|
|
538
|
+
}
|
|
539
|
+
async call(ctx) {
|
|
540
|
+
for (const tap of this.taps) {
|
|
541
|
+
if (this.frozen) {
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
await tap.fn(ctx);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
freeze() {
|
|
548
|
+
this.frozen = true;
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
var StoreService = class {
|
|
552
|
+
get getState() {
|
|
553
|
+
return this.store.getState.bind(this.store);
|
|
554
|
+
}
|
|
555
|
+
get setState() {
|
|
556
|
+
return this.store.setState.bind(this.store);
|
|
557
|
+
}
|
|
558
|
+
constructor(stateCreator) {
|
|
559
|
+
this.store = createStore(stateCreator);
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
StoreService = __decorateClass([
|
|
563
|
+
injectable(),
|
|
564
|
+
__decorateParam(0, unmanaged())
|
|
565
|
+
], StoreService);
|
|
566
|
+
|
|
567
|
+
// src/services/pipeline/pipeline.ts
|
|
568
|
+
var initialState = {
|
|
569
|
+
status: "idle",
|
|
570
|
+
data: {}
|
|
571
|
+
};
|
|
572
|
+
var TestRunPipelineEntity = class extends StoreService {
|
|
573
|
+
constructor() {
|
|
574
|
+
super((set, get) => ({
|
|
575
|
+
...initialState,
|
|
576
|
+
getData: () => get().data || {},
|
|
577
|
+
setData: (next) => set((state) => ({ ...state, data: { ...state.data, ...next } }))
|
|
578
|
+
}));
|
|
579
|
+
this.id = nanoid();
|
|
580
|
+
this.plugins = [];
|
|
581
|
+
this.prepare = new Tap();
|
|
582
|
+
this.onProgressEmitter = new Emitter();
|
|
583
|
+
this.onProgress = this.onProgressEmitter.event;
|
|
584
|
+
this.onFinishedEmitter = new Emitter();
|
|
585
|
+
this.onFinished = this.onFinishedEmitter.event;
|
|
586
|
+
}
|
|
587
|
+
get status() {
|
|
588
|
+
return this.getState().status;
|
|
589
|
+
}
|
|
590
|
+
set status(next) {
|
|
591
|
+
this.setState({ status: next });
|
|
592
|
+
}
|
|
593
|
+
init(options) {
|
|
594
|
+
if (!this.container) {
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
const { plugins } = options;
|
|
598
|
+
for (const PluginClass of plugins) {
|
|
599
|
+
const plugin = this.container.resolve(PluginClass);
|
|
600
|
+
plugin.apply(this);
|
|
601
|
+
this.plugins.push(plugin);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
registerExecute(fn) {
|
|
605
|
+
this.execute = fn;
|
|
606
|
+
}
|
|
607
|
+
registerProgress(fn) {
|
|
608
|
+
this.progress = fn;
|
|
609
|
+
}
|
|
610
|
+
async start(options) {
|
|
611
|
+
const { data } = options || {};
|
|
612
|
+
if (this.status !== "idle") {
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
this.setState({ data });
|
|
616
|
+
const ctx = {
|
|
617
|
+
id: this.id,
|
|
618
|
+
store: this.store,
|
|
619
|
+
operate: {
|
|
620
|
+
update: this.update.bind(this),
|
|
621
|
+
cancel: this.cancel.bind(this)
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
this.status = "preparing";
|
|
625
|
+
await this.prepare.call(ctx);
|
|
626
|
+
if (this.status !== "preparing") {
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
this.status = "executing";
|
|
630
|
+
if (this.execute) {
|
|
631
|
+
await this.execute(ctx);
|
|
632
|
+
}
|
|
633
|
+
if (this.progress) {
|
|
634
|
+
await this.progress(ctx);
|
|
635
|
+
}
|
|
636
|
+
if (this.status === "executing") {
|
|
637
|
+
this.status = "finished";
|
|
638
|
+
this.onFinishedEmitter.fire(this.getState().result);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
update(result) {
|
|
642
|
+
this.setState({ result });
|
|
643
|
+
this.onProgressEmitter.fire(result);
|
|
644
|
+
}
|
|
645
|
+
cancel() {
|
|
646
|
+
if (this.status = "preparing") {
|
|
647
|
+
this.prepare.freeze();
|
|
648
|
+
}
|
|
649
|
+
this.status = "canceled";
|
|
650
|
+
}
|
|
651
|
+
dispose() {
|
|
652
|
+
this.status = "disposed";
|
|
653
|
+
this.plugins.forEach((p) => {
|
|
654
|
+
if (p.dispose) {
|
|
655
|
+
p.dispose();
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
this.onProgressEmitter.dispose();
|
|
659
|
+
this.onFinishedEmitter.dispose();
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
TestRunPipelineEntity = __decorateClass([
|
|
663
|
+
injectable()
|
|
664
|
+
], TestRunPipelineEntity);
|
|
665
|
+
|
|
666
|
+
// src/create-test-run-plugin.ts
|
|
667
|
+
var createTestRunPlugin = definePluginCreator({
|
|
668
|
+
onBind: ({ bind }, opt) => {
|
|
669
|
+
bind(TestRunService).toSelf().inSingletonScope();
|
|
670
|
+
bind(TestRunConfig).toConstantValue(defineConfig(opt));
|
|
671
|
+
bind(TestRunFormManager).toSelf().inSingletonScope();
|
|
672
|
+
bind(TestRunFormFactory).toFactory((context) => () => {
|
|
673
|
+
const e = context.container.resolve(TestRunFormEntity);
|
|
674
|
+
return e;
|
|
675
|
+
});
|
|
676
|
+
bind(TestRunPipelineFactory).toFactory(
|
|
677
|
+
(context) => () => {
|
|
678
|
+
const e = context.container.resolve(TestRunPipelineEntity);
|
|
679
|
+
e.container = context.container.createChild();
|
|
680
|
+
return e;
|
|
681
|
+
}
|
|
682
|
+
);
|
|
683
|
+
}
|
|
684
|
+
});
|
|
685
|
+
var useTestRunService = () => useService(TestRunService);
|
|
686
|
+
|
|
687
|
+
// src/reactive/hooks/use-create-form.ts
|
|
688
|
+
var useCreateForm2 = ({
|
|
689
|
+
node,
|
|
690
|
+
loadingRenderer,
|
|
691
|
+
emptyRenderer,
|
|
692
|
+
defaultValues,
|
|
693
|
+
onMounted,
|
|
694
|
+
onUnmounted,
|
|
695
|
+
onFormValuesChange
|
|
696
|
+
}) => {
|
|
697
|
+
const testRun = useTestRunService();
|
|
698
|
+
const loading = ref(false);
|
|
699
|
+
const form = shallowRef(null);
|
|
700
|
+
const renderer = computed(() => {
|
|
701
|
+
if (loading.value || !form.value) {
|
|
702
|
+
return loadingRenderer;
|
|
703
|
+
}
|
|
704
|
+
const isEmpty = isFormEmpty(form.value.schema);
|
|
705
|
+
return form.value.render({
|
|
706
|
+
defaultValues,
|
|
707
|
+
onFormValuesChange,
|
|
708
|
+
children: isEmpty ? emptyRenderer : null
|
|
709
|
+
});
|
|
710
|
+
});
|
|
711
|
+
const compute = async () => {
|
|
712
|
+
if (!node) {
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
try {
|
|
716
|
+
loading.value = true;
|
|
717
|
+
const formEntity = await testRun.createForm(node);
|
|
718
|
+
form.value = formEntity;
|
|
719
|
+
} finally {
|
|
720
|
+
loading.value = false;
|
|
721
|
+
}
|
|
722
|
+
};
|
|
723
|
+
watch(
|
|
724
|
+
() => node,
|
|
725
|
+
() => {
|
|
726
|
+
void compute();
|
|
727
|
+
},
|
|
728
|
+
{ immediate: true }
|
|
729
|
+
);
|
|
730
|
+
watch(
|
|
731
|
+
form,
|
|
732
|
+
(next, _prev, onCleanup) => {
|
|
733
|
+
if (!next) {
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
const disposable = new DisposableCollection(
|
|
737
|
+
next.onFormMounted((data) => {
|
|
738
|
+
onMounted?.(data);
|
|
739
|
+
}),
|
|
740
|
+
next.onFormUnmounted(() => {
|
|
741
|
+
onUnmounted?.();
|
|
742
|
+
})
|
|
743
|
+
);
|
|
744
|
+
onCleanup(() => disposable.dispose());
|
|
745
|
+
}
|
|
746
|
+
);
|
|
747
|
+
onBeforeUnmount(() => {
|
|
748
|
+
form.value = null;
|
|
749
|
+
});
|
|
750
|
+
return {
|
|
751
|
+
renderer,
|
|
752
|
+
loading,
|
|
753
|
+
form
|
|
754
|
+
};
|
|
755
|
+
};
|
|
756
|
+
|
|
757
|
+
export { FormEngine, TestRunPipelineEntity, connect, createTestRunPlugin, useCreateForm2 as useCreateForm, useTestRunService };
|
|
758
|
+
//# sourceMappingURL=index.js.map
|
|
759
|
+
//# sourceMappingURL=index.js.map
|