@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.
- package/.eslintrc.cjs +17 -0
- package/.rush/temp/chunked-rush-logs/test-run-plugin.build.chunks.jsonl +21 -0
- package/.rush/temp/package-deps_build.json +47 -0
- package/.rush/temp/shrinkwrap-deps.json +161 -0
- package/dist/esm/index.js +731 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +314 -0
- package/dist/index.d.ts +314 -0
- package/dist/index.js +770 -0
- package/dist/index.js.map +1 -0
- package/package.json +56 -0
- package/rush-logs/test-run-plugin.build.log +21 -0
- package/src/create-test-run-plugin.ts +39 -0
- package/src/form-engine/contexts.ts +16 -0
- package/src/form-engine/fields/create-field.tsx +32 -0
- package/src/form-engine/fields/general-field.tsx +35 -0
- package/src/form-engine/fields/index.ts +9 -0
- package/src/form-engine/fields/object-field.tsx +21 -0
- package/src/form-engine/fields/reactive-field.tsx +57 -0
- package/src/form-engine/fields/recursion-field.tsx +31 -0
- package/src/form-engine/fields/schema-field.tsx +32 -0
- package/src/form-engine/form/form.tsx +38 -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 +69 -0
- package/src/form-engine/hooks/use-field.ts +13 -0
- package/src/form-engine/hooks/use-form.ts +13 -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 +64 -0
- package/src/index.ts +22 -0
- package/src/reactive/hooks/index.ts +7 -0
- package/src/reactive/hooks/use-create-form.ts +90 -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 +78 -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 +143 -0
- package/src/services/pipeline/plugin.ts +11 -0
- package/src/services/pipeline/tap.ts +34 -0
- package/src/services/store.ts +27 -0
- package/src/services/test-run.ts +100 -0
- package/src/types.ts +29 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/create-test-run-plugin.ts","../../src/services/form/form.ts","../../src/services/config.ts","../../src/form-engine/form/form.tsx","../../src/form-engine/hooks/use-create-form.ts","../../src/form-engine/utils.ts","../../src/form-engine/model/index.ts","../../src/form-engine/hooks/use-field.ts","../../src/form-engine/contexts.ts","../../src/form-engine/hooks/use-form.ts","../../src/form-engine/fields/schema-field.tsx","../../src/form-engine/fields/recursion-field.tsx","../../src/form-engine/fields/reactive-field.tsx","../../src/form-engine/fields/object-field.tsx","../../src/form-engine/fields/general-field.tsx","../../src/form-engine/fields/create-field.tsx","../../src/services/form/factory.ts","../../src/services/form/manager.ts","../../src/services/test-run.ts","../../src/services/pipeline/factory.ts","../../src/services/pipeline/pipeline.ts","../../src/services/pipeline/tap.ts","../../src/services/store.ts","../../src/reactive/hooks/use-create-form.ts","../../src/reactive/hooks/use-test-run-service.ts"],"sourcesContent":["/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { definePluginCreator } from '@flowgram.ai/core';\n\nimport { TestRunFormEntity, TestRunFormFactory, TestRunFormManager } from './services/form';\nimport {\n TestRunService,\n TestRunPipelineEntity,\n TestRunPipelineFactory,\n TestRunConfig,\n defineConfig,\n} from './services';\n\nexport const createTestRunPlugin = definePluginCreator<Partial<TestRunConfig>>({\n onBind: ({ bind }, opt) => {\n /** service */\n bind(TestRunService).toSelf().inSingletonScope();\n /** config */\n bind(TestRunConfig).toConstantValue(defineConfig(opt));\n /** form manager */\n bind(TestRunFormManager).toSelf().inSingletonScope();\n /** form entity */\n bind<TestRunFormFactory>(TestRunFormFactory).toFactory<TestRunFormEntity>((context) => () => {\n const e = context.container.resolve(TestRunFormEntity);\n return e;\n });\n /** pipeline entity */\n bind<TestRunPipelineFactory>(TestRunPipelineFactory).toFactory<TestRunPipelineEntity>(\n (context) => () => {\n const e = context.container.resolve(TestRunPipelineEntity);\n e.container = context.container.createChild();\n return e;\n }\n );\n },\n});\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { createElement, type ReactNode } from 'react';\n\nimport { nanoid } from 'nanoid';\nimport { injectable, inject } from 'inversify';\nimport { Emitter } from '@flowgram.ai/utils';\n\nimport { TestRunConfig } from '../config';\nimport { FormSchema, FormEngine, type FormInstance, type FormEngineProps } from '../../form-engine';\n\nexport type FormRenderProps = Omit<\n FormEngineProps,\n 'schema' | 'components' | 'onMounted' | 'onUnmounted'\n>;\n\n@injectable()\nexport class TestRunFormEntity {\n @inject(TestRunConfig) private readonly config: TestRunConfig;\n\n private _schema: FormSchema;\n\n private initialized = false;\n\n id = nanoid();\n\n form: FormInstance | null = null;\n\n onFormMountedEmitter = new Emitter<FormInstance>();\n\n onFormMounted = this.onFormMountedEmitter.event;\n\n onFormUnmountedEmitter = new Emitter<void>();\n\n onFormUnmounted = this.onFormUnmountedEmitter.event;\n\n get schema() {\n return this._schema;\n }\n\n init(options: { schema: FormSchema }) {\n if (this.initialized) return;\n\n this._schema = options.schema;\n this.initialized = true;\n }\n\n render(props?: FormRenderProps): ReactNode {\n if (!this.initialized) {\n return null;\n }\n const { children, ...restProps } = props || {};\n return createElement(\n FormEngine,\n {\n schema: this.schema,\n components: this.config.components,\n onMounted: (instance) => {\n this.form = instance;\n this.onFormMountedEmitter.fire(instance);\n },\n onUnmounted: this.onFormUnmountedEmitter.fire.bind(this.onFormUnmountedEmitter),\n ...restProps,\n },\n children\n );\n }\n\n dispose() {\n this._schema = {};\n this.form = null;\n this.onFormMountedEmitter.dispose();\n this.onFormUnmountedEmitter.dispose();\n }\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport type { FlowNodeType, FlowNodeEntity } from '@flowgram.ai/document';\n\nimport type { MaybePromise } from '../types';\nimport type { FormSchema, FormComponents } from '../form-engine';\nimport type { TestRunPipelinePlugin } from './pipeline';\n\ntype PropertiesFunctionParams = {\n node: FlowNodeEntity;\n};\nexport type NodeMap = Record<FlowNodeType, NodeTestConfig>;\nexport interface NodeTestConfig {\n /** Enable node TestRun */\n enabled?: boolean;\n /** Input schema properties */\n properties?:\n | Record<string, FormSchema>\n | ((params: PropertiesFunctionParams) => MaybePromise<Record<string, FormSchema>>);\n}\n\nexport interface TestRunConfig {\n components: FormComponents;\n nodes: NodeMap;\n plugins: (new () => TestRunPipelinePlugin)[];\n}\n\nexport const TestRunConfig = Symbol('TestRunConfig');\nexport const defineConfig = (config: Partial<TestRunConfig>) => {\n const defaultConfig: TestRunConfig = {\n components: {},\n nodes: {},\n plugins: [],\n };\n return {\n ...defaultConfig,\n ...config,\n };\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { Form } from '@flowgram.ai/form';\n\nimport { FormSchema, FormComponents } from '../types';\nimport { useCreateForm, type UseCreateFormOptions } from '../hooks';\nimport { createSchemaField } from '../fields';\n\nconst SchemaField = createSchemaField({});\n\nexport type FormEngineProps = React.PropsWithChildren<\n {\n /** Form schema */\n schema: FormSchema;\n /** form material map */\n components?: FormComponents;\n } & UseCreateFormOptions\n>;\n\nexport const FormEngine: React.FC<FormEngineProps> = ({\n schema,\n components,\n children,\n ...props\n}) => {\n const { model, control } = useCreateForm(schema, props);\n\n return (\n <Form control={control}>\n <SchemaField model={model} components={components}>\n {children}\n </SchemaField>\n </Form>\n );\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { useEffect, useMemo } from 'react';\n\nimport type { OnFormValuesChangePayload } from '@flowgram.ai/form-core';\nimport { createForm, ValidateTrigger, type IForm } from '@flowgram.ai/form';\n\nimport { createValidate } from '../utils';\nimport { FormSchema, FormSchemaValidate } from '../types';\nimport { FormSchemaModel } from '../model';\n\nexport interface FormInstance {\n model: FormSchemaModel;\n form: IForm;\n}\nexport interface UseCreateFormOptions {\n defaultValues?: any;\n validate?: Record<string, FormSchemaValidate>;\n validateTrigger?: ValidateTrigger;\n onMounted?: (form: FormInstance) => void;\n onFormValuesChange?: (payload: OnFormValuesChangePayload) => void;\n onUnmounted?: () => void;\n}\n\nexport const useCreateForm = (schema: FormSchema, options: UseCreateFormOptions = {}) => {\n const { form, control } = useMemo(\n () =>\n createForm({\n validate: {\n ...createValidate(schema),\n ...options.validate,\n },\n validateTrigger: options.validateTrigger ?? ValidateTrigger.onBlur,\n }),\n [schema]\n );\n\n const model = useMemo(\n () => new FormSchemaModel({ type: 'object', ...schema, defaultValue: options.defaultValues }),\n [schema]\n );\n\n /** Lifecycle and event binding */\n useEffect(() => {\n if (options.onMounted) {\n options.onMounted({ model, form });\n }\n const disposable = control._formModel.onFormValuesChange((payload) => {\n if (options.onFormValuesChange) {\n options.onFormValuesChange(payload);\n }\n });\n return () => {\n disposable.dispose();\n if (options.onUnmounted) {\n options.onUnmounted();\n }\n };\n }, [control]);\n\n return {\n form,\n control,\n model,\n };\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { createElement } from 'react';\n\nimport type { FormSchema, FormSchemaValidate, FormComponentProps } from './types';\n\n/** Splice form item unique name */\nexport const getUniqueFieldName = (...args: (string | undefined)[]) =>\n args.filter((path) => path).join('.');\n\nexport const mergeFieldPath = (path?: string[], name?: string) =>\n [...(path || []), name].filter((i): i is string => Boolean(i));\n\n/** Create validation rules */\nexport const createValidate = (schema: FormSchema) => {\n const rules: Record<string, FormSchemaValidate> = {};\n\n visit(schema);\n\n return rules;\n\n function visit(current: FormSchema, name?: string) {\n if (name && current['x-validator']) {\n rules[name] = current['x-validator'];\n }\n if (current.type === 'object' && current.properties) {\n Object.entries(current.properties).forEach(([key, value]) => {\n visit(value, getUniqueFieldName(name, key));\n });\n }\n }\n};\n\nexport const connect = <T = any>(\n Component: React.FunctionComponent<any>,\n mapProps: (p: FormComponentProps) => T\n) => {\n const Connected = (props: FormComponentProps) => {\n const mappedProps = mapProps(props);\n return createElement(Component, mappedProps, (mappedProps as any).children);\n };\n\n return Connected;\n};\n\nexport const isFormEmpty = (schema: FormSchema) => {\n /** is not general field and not has children */\n const isEmpty = (s: FormSchema): boolean => {\n if (!s.type || s.type === 'object' || !s.name) {\n return Object.entries(schema.properties || {})\n .map(([key, value]) => ({\n name: key,\n ...value,\n }))\n .every(isFormEmpty);\n }\n return false;\n };\n\n return isEmpty(schema);\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { ReactiveState } from '@flowgram.ai/reactive';\n\nimport { getUniqueFieldName, mergeFieldPath } from '../utils';\nimport { FormSchema, FormSchemaType, FormSchemaModelState } from '../types';\n\nexport class FormSchemaModel implements FormSchema {\n name?: string;\n\n type?: FormSchemaType;\n\n defaultValue?: any;\n\n properties?: Record<string, FormSchema>;\n\n ['x-index']?: number;\n\n ['x-component']?: string;\n\n ['x-component-props']?: Record<string, unknown>;\n\n ['x-decorator']?: string;\n\n ['x-decorator-props']?: Record<string, unknown>;\n\n [key: string]: any;\n\n path: string[] = [];\n\n state = new ReactiveState<FormSchemaModelState>({ disabled: false });\n\n get componentType() {\n return this['x-component'];\n }\n\n get componentProps() {\n return this['x-component-props'];\n }\n\n get decoratorType() {\n return this['x-decorator'];\n }\n\n get decoratorProps() {\n return this['x-decorator-props'];\n }\n\n get uniqueName() {\n return getUniqueFieldName(...this.path);\n }\n\n constructor(json: FormSchema, path: string[] = []) {\n this.fromJSON(json);\n this.path = path;\n }\n\n private fromJSON(json: FormSchema) {\n Object.entries(json).forEach(([key, value]) => {\n this[key] = value;\n });\n }\n\n getPropertyList() {\n const orderProperties: FormSchemaModel[] = [];\n const unOrderProperties: FormSchemaModel[] = [];\n Object.entries(this.properties || {}).forEach(([key, item]) => {\n const index = item['x-index'];\n const defaultValues = this.defaultValue;\n /**\n * The upper layer's default value has a higher priority than its own default value,\n * because the upper layer's default value ultimately comes from the outside world.\n */\n if (typeof defaultValues === 'object' && defaultValues !== null && key in defaultValues) {\n item.defaultValue = defaultValues[key];\n }\n const current = new FormSchemaModel(item, mergeFieldPath(this.path, key));\n if (index !== undefined && !isNaN(index)) {\n orderProperties[index] = current;\n } else {\n unOrderProperties.push(current);\n }\n });\n return orderProperties.concat(unOrderProperties).filter((item) => !!item);\n }\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { useContext } from 'react';\n\nimport { useObserve } from '@flowgram.ai/reactive';\n\nimport { FieldModelContext } from '../contexts';\n\nexport const useFieldModel = () => useContext(FieldModelContext);\nexport const useFieldState = () => useObserve(useFieldModel().state.value);\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { createContext } from 'react';\n\nimport type { FormComponents } from './types';\nimport type { FormSchemaModel } from './model';\n\n/** Model context for each form item */\nexport const FieldModelContext = createContext<FormSchemaModel>({} as any);\n/** The form's model context */\nexport const FormModelContext = createContext<FormSchemaModel>({} as any);\n/** Context of material component map */\nexport const ComponentsContext = createContext<FormComponents>({});\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { useContext } from 'react';\n\nimport { useObserve } from '@flowgram.ai/reactive';\n\nimport { FormModelContext } from '../contexts';\n\nexport const useFormModel = () => useContext(FormModelContext);\nexport const useFormState = () => useObserve(useFormModel().state.value);\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { useState } from 'react';\n\nimport type { FormComponents } from '../types';\nimport { FormSchemaModel } from '../model';\nimport { ComponentsContext, FormModelContext } from '../contexts';\nimport { RecursionField } from './recursion-field';\n\nexport interface SchemaFieldProps {\n model: FormSchemaModel;\n components: FormComponents;\n}\nexport const SchemaField: React.FC<React.PropsWithChildren<SchemaFieldProps>> = ({\n components,\n model,\n children,\n}) => {\n /** Only initialized once, dynamic is not supported */\n const [innerComponents] = useState(() => components);\n return (\n <ComponentsContext.Provider value={innerComponents}>\n <FormModelContext.Provider value={model}>\n <RecursionField model={model} />\n {children}\n </FormModelContext.Provider>\n </ComponentsContext.Provider>\n );\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { useMemo } from 'react';\n\nimport { FormSchemaModel } from '../model';\nimport { ObjectField } from './object-field';\nimport { GeneralField } from './general-field';\n\ninterface RecursionFieldProps {\n model: FormSchemaModel;\n}\n\nexport const RecursionField: React.FC<RecursionFieldProps> = ({ model }) => {\n const properties = useMemo(() => model.getPropertyList(), [model]);\n\n /** general field has no children */\n if (model.type !== 'object') {\n return <GeneralField model={model} />;\n }\n\n return (\n <ObjectField model={model}>\n {properties.map((item) => (\n <RecursionField key={item.uniqueName} model={item} />\n ))}\n </ObjectField>\n );\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { useContext } from 'react';\nimport React from 'react';\n\nimport { useFormState } from '../hooks/use-form';\nimport { useFieldModel, useFieldState } from '../hooks/use-field';\nimport { ComponentsContext } from '../contexts';\n\ninterface ReactiveFieldProps {\n componentProps?: Record<string, unknown>;\n decoratorProps?: Record<string, unknown>;\n}\n\nexport const ReactiveField: React.FC<React.PropsWithChildren<ReactiveFieldProps>> = (props) => {\n const formState = useFormState();\n const model = useFieldModel();\n const modelState = useFieldState();\n const components = useContext(ComponentsContext);\n\n const disabled = modelState.disabled || formState.disabled;\n const componentRender = () => {\n if (!model.componentType || !components[model.componentType]) {\n return props.children;\n }\n return React.createElement(\n components[model.componentType],\n {\n disabled,\n ...model.componentProps,\n ...props.componentProps,\n },\n props.children\n );\n };\n\n const decoratorRender = (children: React.ReactNode) => {\n if (!model.decoratorType || !components[model.decoratorType]) {\n return <>{children}</>;\n }\n return React.createElement(\n components[model.decoratorType],\n {\n type: model.type,\n required: model.required,\n ...model.decoratorProps,\n ...props.decoratorProps,\n },\n children\n );\n };\n\n return decoratorRender(componentRender());\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport type { FormSchemaModel } from '../model';\nimport { FieldModelContext } from '../contexts';\nimport { ReactiveField } from './reactive-field';\n\nexport interface ObjectFieldProps {\n model: FormSchemaModel;\n}\n\nexport const ObjectField: React.FC<React.PropsWithChildren<ObjectFieldProps>> = ({\n model,\n children,\n}) => (\n <FieldModelContext.Provider value={model}>\n <ReactiveField>{children}</ReactiveField>\n </FieldModelContext.Provider>\n);\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { Field } from '@flowgram.ai/form';\n\nimport { ReactiveField } from './reactive-field';\nimport type { FormSchemaModel } from '../model';\nimport { FieldModelContext } from '../contexts';\n\nexport interface GeneralFieldProps {\n model: FormSchemaModel;\n}\n\nexport const GeneralField: React.FC<GeneralFieldProps> = ({ model }) => (\n <FieldModelContext.Provider value={model}>\n <Field\n name={model.uniqueName}\n defaultValue={model.defaultValue}\n render={({ field, fieldState }) => (\n <ReactiveField\n componentProps={{\n value: field.value,\n onChange: field.onChange,\n onFocus: field.onFocus,\n onBlur: field.onBlur,\n ...fieldState,\n }}\n decoratorProps={fieldState}\n />\n )}\n />\n </FieldModelContext.Provider>\n);\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { PropsWithChildren } from 'react';\n\nimport { SchemaField, type SchemaFieldProps } from './schema-field';\nimport { FormComponents } from '../types';\n\ntype InnerSchemaFieldProps = Omit<SchemaFieldProps, 'components'> &\n Pick<Partial<SchemaFieldProps>, 'components'>;\n\nexport interface CreateSchemaFieldOptions {\n components?: FormComponents;\n}\nexport const createSchemaField = (options: CreateSchemaFieldOptions) => {\n const InnerSchemaField: React.FC<PropsWithChildren<InnerSchemaFieldProps>> = ({\n components,\n ...props\n }) => (\n <SchemaField\n components={{\n ...options.components,\n ...components,\n }}\n {...props}\n />\n );\n\n return InnerSchemaField;\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport type { TestRunFormEntity } from './form';\n\nexport const TestRunFormFactory = Symbol('TestRunFormFactory');\nexport type TestRunFormFactory = () => TestRunFormEntity;\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { inject, injectable } from 'inversify';\n\nimport type { TestRunFormEntity } from './form';\nimport { TestRunFormFactory } from './factory';\n\n@injectable()\nexport class TestRunFormManager {\n @inject(TestRunFormFactory) private readonly factory: TestRunFormFactory;\n\n private entities = new Map<string, TestRunFormEntity>();\n\n createForm() {\n return this.factory();\n }\n\n getForm(id: string) {\n return this.entities.get(id);\n }\n\n getAllForm() {\n return Array.from(this.entities);\n }\n\n disposeForm(id: string) {\n const form = this.entities.get(id);\n if (!form) {\n return;\n }\n form.dispose();\n this.entities.delete(id);\n }\n\n disposeAllForm() {\n for (const id of this.entities.keys()) {\n this.disposeForm(id);\n }\n }\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { inject, injectable } from 'inversify';\nimport { Disposable, DisposableCollection, Emitter } from '@flowgram.ai/utils';\nimport type { FlowNodeEntity, FlowNodeType } from '@flowgram.ai/document';\n\nimport { TestRunPipelineFactory } from './pipeline/factory';\nimport { TestRunFormManager } from './form';\nimport { FormSchema } from '../form-engine';\nimport { TestRunPipelineEntity, type TestRunPipelineEntityOptions } from './pipeline';\nimport { TestRunConfig } from './config';\n\n@injectable()\nexport class TestRunService {\n @inject(TestRunConfig) private readonly config: TestRunConfig;\n\n @inject(TestRunPipelineFactory) private readonly pipelineFactory: TestRunPipelineFactory;\n\n @inject(TestRunFormManager) readonly formManager: TestRunFormManager;\n\n pipelineEntities = new Map<string, TestRunPipelineEntity>();\n\n pipelineBindings = new Map<string, Disposable>();\n\n onPipelineProgressEmitter = new Emitter();\n\n onPipelineProgress = this.onPipelineProgressEmitter.event;\n\n onPipelineFinishedEmitter = new Emitter();\n\n onPipelineFinished = this.onPipelineFinishedEmitter.event;\n\n public isEnabled(nodeType: FlowNodeType) {\n const config = this.config.nodes[nodeType];\n return config && config?.enabled !== false;\n }\n\n async toSchema(node: FlowNodeEntity) {\n const nodeType = node.flowNodeType;\n const config = this.config.nodes[nodeType];\n if (!this.isEnabled(nodeType)) {\n return {};\n }\n const properties =\n typeof config.properties === 'function'\n ? await config.properties({ node })\n : config.properties;\n\n return {\n type: 'object',\n properties,\n };\n }\n\n createFormWithSchema(schema: FormSchema) {\n const form = this.formManager.createForm();\n form.init({ schema });\n return form;\n }\n\n async createForm(node: FlowNodeEntity) {\n const schema = await this.toSchema(node);\n return this.createFormWithSchema(schema);\n }\n\n createPipeline(options: TestRunPipelineEntityOptions) {\n const pipeline = this.pipelineFactory();\n this.pipelineEntities.set(pipeline.id, pipeline);\n pipeline.init(options);\n return pipeline;\n }\n\n connectPipeline(pipeline: TestRunPipelineEntity) {\n if (this.pipelineBindings.get(pipeline.id)) {\n return;\n }\n const disposable = new DisposableCollection(\n pipeline.onProgress(this.onPipelineProgressEmitter.fire.bind(this.onPipelineProgressEmitter)),\n pipeline.onFinished(this.onPipelineFinishedEmitter.fire.bind(this.onPipelineFinishedEmitter))\n );\n this.pipelineBindings.set(pipeline.id, disposable);\n }\n\n disconnectPipeline(id: string) {\n if (this.pipelineBindings.has(id)) {\n const disposable = this.pipelineBindings.get(id);\n disposable?.dispose();\n this.pipelineBindings.delete(id);\n }\n }\n\n disconnectAllPipeline() {\n for (const id of this.pipelineBindings.keys()) {\n this.disconnectPipeline(id);\n }\n }\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport type { TestRunPipelineEntity } from './pipeline';\n\nexport const TestRunPipelineFactory = Symbol('TestRunPipelineFactory');\nexport type TestRunPipelineFactory = () => TestRunPipelineEntity;\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport type { StoreApi } from 'zustand';\nimport { nanoid } from 'nanoid';\nimport { injectable, interfaces } from 'inversify';\nimport { Emitter } from '@flowgram.ai/utils';\n\nimport { Tap } from './tap';\nimport type { TestRunPipelinePlugin } from './plugin';\nimport { StoreService } from '../store';\nexport interface TestRunPipelineEntityOptions {\n plugins: (new () => TestRunPipelinePlugin)[];\n}\n\ninterface TestRunPipelineEntityState<T = any> {\n status: 'idle' | 'preparing' | 'executing' | 'canceled' | 'finished';\n data?: T;\n result?: any;\n getData: () => T;\n setData: (next: any) => void;\n}\n\nexport interface TestRunPipelineEntityCtx<T = any> {\n id: string;\n store: StoreApi<TestRunPipelineEntityState<T>>;\n operate: {\n update: (data: any) => void;\n cancel: () => void;\n };\n}\n\nconst initialState: Omit<TestRunPipelineEntityState, 'getData' | 'setData'> = {\n status: 'idle',\n data: {},\n};\n\n@injectable()\nexport class TestRunPipelineEntity extends StoreService<TestRunPipelineEntityState> {\n container: interfaces.Container | undefined;\n\n id = nanoid();\n\n prepare = new Tap<TestRunPipelineEntityCtx>();\n\n private execute?: (ctx: TestRunPipelineEntityCtx) => Promise<void> | void;\n\n private progress?: (ctx: TestRunPipelineEntityCtx) => Promise<void> | void;\n\n get status() {\n return this.getState().status;\n }\n\n set status(next: TestRunPipelineEntityState['status']) {\n this.setState({ status: next });\n }\n\n onProgressEmitter = new Emitter<any>();\n\n onProgress = this.onProgressEmitter.event;\n\n onFinishedEmitter = new Emitter();\n\n onFinished = this.onFinishedEmitter.event;\n\n constructor() {\n super((set, get) => ({\n ...initialState,\n getData: () => get().data || {},\n setData: (next: any) => set((state) => ({ ...state, data: { ...state.data, ...next } })),\n }));\n }\n\n public init(options: TestRunPipelineEntityOptions) {\n if (!this.container) {\n return;\n }\n const { plugins } = options;\n for (const PluginClass of plugins) {\n const plugin = this.container.resolve<TestRunPipelinePlugin>(PluginClass);\n plugin.apply(this);\n }\n }\n\n public registerExecute(fn: (ctx: TestRunPipelineEntityCtx) => Promise<void> | void) {\n this.execute = fn;\n }\n\n public registerProgress(fn: (ctx: TestRunPipelineEntityCtx) => Promise<void> | void) {\n this.progress = fn;\n }\n\n async start<T>(options?: { data: T }) {\n const { data } = options || {};\n if (this.status !== 'idle') {\n return;\n }\n /** initialization data */\n this.setState({ data });\n const ctx: TestRunPipelineEntityCtx = {\n id: this.id,\n store: this.store,\n operate: {\n update: this.update.bind(this),\n cancel: this.cancel.bind(this),\n },\n };\n\n this.status = 'preparing';\n await this.prepare.call(ctx);\n if (this.status !== 'preparing') {\n return;\n }\n\n this.status = 'executing';\n if (this.execute) {\n await this.execute(ctx);\n }\n if (this.progress) {\n await this.progress(ctx);\n }\n if (this.status === 'executing') {\n this.status = 'finished';\n this.onFinishedEmitter.fire(this.getState().result);\n }\n }\n\n update(result: any) {\n this.setState({ result });\n this.onProgressEmitter.fire(result);\n }\n\n cancel() {\n if ((this.status = 'preparing')) {\n this.prepare.freeze();\n }\n this.status = 'canceled';\n }\n\n dispose() {}\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { MaybePromise } from '../../types';\n\ninterface TapValue<T> {\n name: string;\n fn: (arg: T) => MaybePromise<void>;\n}\n\nexport class Tap<T> {\n private taps: TapValue<T>[] = [];\n\n private frozen = false;\n\n tap(name: string, fn: TapValue<T>['fn']) {\n this.taps.push({ name, fn });\n }\n\n async call(ctx: T) {\n for (const tap of this.taps) {\n if (this.frozen) {\n return;\n }\n await tap.fn(ctx);\n }\n }\n\n freeze() {\n this.frozen = true;\n }\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { createStore } from 'zustand/vanilla';\nimport type { StoreApi, StateCreator } from 'zustand';\nimport { injectable, unmanaged } from 'inversify';\n/**\n * 包含 Store 的 Service\n */\n@injectable()\nexport class StoreService<State> {\n store: StoreApi<State>;\n\n get getState() {\n return this.store.getState.bind(this.store);\n }\n\n get setState() {\n return this.store.setState.bind(this.store);\n }\n\n constructor(@unmanaged() stateCreator: StateCreator<State>) {\n this.store = createStore(stateCreator);\n }\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { useEffect, useMemo, useState } from 'react';\n\nimport { DisposableCollection } from '@flowgram.ai/utils';\nimport type { FlowNodeEntity } from '@flowgram.ai/document';\n\nimport { TestRunFormEntity } from '../../services/form/form';\nimport { FormEngineProps, isFormEmpty } from '../../form-engine';\nimport { useTestRunService } from './use-test-run-service';\n\ninterface UseFormOptions {\n node?: FlowNodeEntity;\n /** form loading */\n loadingRenderer?: React.ReactNode;\n /** form empty */\n emptyRenderer?: React.ReactNode;\n defaultValues?: FormEngineProps['defaultValues'];\n onMounted?: FormEngineProps['onMounted'];\n onUnmounted?: FormEngineProps['onUnmounted'];\n onFormValuesChange?: FormEngineProps['onFormValuesChange'];\n}\n\nexport const useCreateForm = ({\n node,\n loadingRenderer,\n emptyRenderer,\n defaultValues,\n onMounted,\n onUnmounted,\n onFormValuesChange,\n}: UseFormOptions) => {\n const testRun = useTestRunService();\n const [loading, setLoading] = useState(false);\n const [form, setForm] = useState<TestRunFormEntity | null>(null);\n const renderer = useMemo(() => {\n if (loading || !form) {\n return loadingRenderer;\n }\n\n const isEmpty = isFormEmpty(form.schema);\n\n return form.render({\n defaultValues,\n onFormValuesChange,\n children: isEmpty ? emptyRenderer : null,\n });\n }, [form, loading]);\n\n const compute = async () => {\n if (!node) {\n return;\n }\n try {\n setLoading(true);\n const formEntity = await testRun.createForm(node);\n setForm(formEntity);\n } finally {\n setLoading(false);\n }\n };\n\n useEffect(() => {\n compute();\n }, [node]);\n\n useEffect(() => {\n if (!form) {\n return;\n }\n const disposable = new DisposableCollection(\n form.onFormMounted((data) => {\n onMounted?.(data);\n }),\n form.onFormUnmounted(() => {\n onUnmounted?.();\n })\n );\n return () => disposable.dispose();\n }, [form]);\n\n return {\n renderer,\n loading,\n form,\n };\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { useService } from '@flowgram.ai/core';\n\nimport { TestRunService } from '../../services/test-run';\n\nexport const useTestRunService = () => useService<TestRunService>(TestRunService);\n"],"mappings":";;;;;;;;;;;;;AAKA,SAAS,2BAA2B;;;ACApC,SAAS,iBAAAA,sBAAqC;AAE9C,SAAS,cAAc;AACvB,SAAS,YAAY,cAAc;AACnC,SAAS,eAAe;;;ACqBjB,IAAM,gBAAgB,OAAO,eAAe;AAC5C,IAAM,eAAe,CAAC,WAAmC;AAC9D,QAAM,gBAA+B;AAAA,IACnC,YAAY,CAAC;AAAA,IACb,OAAO,CAAC;AAAA,IACR,SAAS,CAAC;AAAA,EACZ;AACA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AACF;;;ACpCA,SAAS,YAAY;;;ACArB,SAAS,WAAW,eAAe;AAGnC,SAAS,YAAY,uBAAmC;;;ACHxD,SAAS,qBAAqB;AAKvB,IAAM,qBAAqB,IAAI,SACpC,KAAK,OAAO,CAAC,SAAS,IAAI,EAAE,KAAK,GAAG;AAE/B,IAAM,iBAAiB,CAAC,M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AAC;AAET,EAAAA,WAAU,MAAM;AACd,QAAI,CAAC,MAAM;AACT;AAAA,IACF;AACA,UAAM,aAAa,IAAIC;AAAA,MACrB,KAAK,cAAc,CAAC,SAAS;AAC3B,oBAAY,IAAI;AAAA,MAClB,CAAC;AAAA,MACD,KAAK,gBAAgB,MAAM;AACzB,sBAAc;AAAA,MAChB,CAAC;AAAA,IACH;AACA,WAAO,MAAM,WAAW,QAAQ;AAAA,EAClC,GAAG,CAAC,IAAI,CAAC;AAET,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["createElement","useContext","useObserve","useContext","useObserve","useMemo","useContext","useContext","jsx","jsx","jsx","useMemo","jsx","jsx","jsx","SchemaField","createElement","inject","injectable","inject","injectable","inject","injectable","Emitter","Emitter","inject","injectable","nanoid","injectable","Emitter","injectable","injectable","nanoid","Emitter","injectable","useEffect","useMemo","useState","DisposableCollection","useCreateForm","useState","useMemo","useEffect","DisposableCollection"]}
|
package/dist/index.d.mts
ADDED
|
@@ -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 };
|