sequential-workflow-editor-model
Advanced tools
Comparing version 0.2.1 to 0.3.0
@@ -132,3 +132,3 @@ class ModelActivator { | ||
if (configuration.valueTypes && !configuration.valueTypes.includes(variable.type)) { | ||
errors[index] = `Variable ${variable.name} has wrong type`; | ||
errors[index] = `Variable ${variable.name} has invalid type`; | ||
return; | ||
@@ -232,2 +232,31 @@ } | ||
const nullableAnyVariableValueModelId = 'nullableAnyVariable'; | ||
function nullableAnyVariableValueModel(configuration) { | ||
return (path) => ({ | ||
id: nullableAnyVariableValueModelId, | ||
label: 'Variable', | ||
path, | ||
configuration, | ||
getDefaultValue() { | ||
return null; | ||
}, | ||
getVariableDefinitions: () => null, | ||
validate(context) { | ||
const value = context.getValue(); | ||
if (configuration.isRequired && !value) { | ||
return createValidationSingleError(`The variable is required.`); | ||
} | ||
if (value) { | ||
if (!context.hasVariable(value.name, value.type)) { | ||
return createValidationSingleError(`The variable ${value.name} is lost`); | ||
} | ||
if (configuration.valueTypes && !configuration.valueTypes.includes(value.type)) { | ||
return createValidationSingleError(`The variable ${value.name} has invalid type`); | ||
} | ||
} | ||
return null; | ||
} | ||
}); | ||
} | ||
const nullableVariableValueModelId = 'nullableVariable'; | ||
@@ -250,3 +279,3 @@ function nullableVariableValueModel(configuration) { | ||
if (value && value.name) { | ||
if (!context.hasVariable(value.name, configuration.variableType)) { | ||
if (!context.hasVariable(value.name, configuration.valueType)) { | ||
return createValidationSingleError(`The variable ${value.name} is not found.`); | ||
@@ -301,4 +330,4 @@ } | ||
} | ||
if (value.type !== configuration.variableType) { | ||
return createValidationSingleError(`Variable type must be ${configuration.variableType}.`); | ||
if (value.type !== configuration.valueType) { | ||
return createValidationSingleError(`Variable type must be ${configuration.valueType}.`); | ||
} | ||
@@ -423,2 +452,5 @@ if (context.isVariableDuplicated(value.name)) { | ||
} | ||
if (configuration.valueTypes && !configuration.valueTypes.includes(variable.type)) { | ||
errors[index] = 'Value type is not allowed'; | ||
} | ||
}); | ||
@@ -719,11 +751,9 @@ return Object.keys(errors).length > 0 ? errors : null; | ||
hasVariable(name, valueType) { | ||
const variables = this.definitionContext.variablesProvider.getVariables(); | ||
return variables.some(v => v.name === name && v.type === valueType); | ||
return this.getVariables().some(v => v.name === name && v.type === valueType); | ||
} | ||
isVariableDuplicated(name) { | ||
const variables = this.definitionContext.variablesProvider.getVariables(); | ||
return variables.filter(v => v.name === name).length > 1; | ||
return this.getVariables().filter(v => v.name === name).length > 1; | ||
} | ||
getVariables(valueType) { | ||
return this.definitionContext.variablesProvider.getVariables().filter(v => v.type === valueType); | ||
getVariables() { | ||
return this.definitionContext.variablesProvider.getVariables(); | ||
} | ||
@@ -876,2 +906,2 @@ validate() { | ||
export { BranchedStepModelBuilder, CustomValidatorContext, DefinitionContext, DefinitionModelBuilder, ModelActivator, ModelValidator, Path, PropertyModelBuilder, RootModelBuilder, SequentialStepModelBuilder, SimpleEvent, StepModelBuilder, ValueKnownType, ValueModelContext, anyVariablesValueModel, anyVariablesValueModelId, branchesValueModel, branchesValueModelId, choiceValueModel, choiceValueModelId, createBranchedStepModel, createDefinitionModel, createRootModel, createSequentialStepModel, createStepModel, createValidationSingleError, dynamicValueModel, dynamicValueModelId, nullableVariableDefinitionValueModel, nullableVariableDefinitionValueModelId, nullableVariableValueModel, nullableVariableValueModelId, numberValueModel, numberValueModelId, sequenceValueModel, sequenceValueModelId, stringValueModel, stringValueModelId, variableDefinitionsValueModel, variableDefinitionsValueModelId }; | ||
export { BranchedStepModelBuilder, CustomValidatorContext, DefinitionContext, DefinitionModelBuilder, ModelActivator, ModelValidator, Path, PropertyModelBuilder, RootModelBuilder, SequentialStepModelBuilder, SimpleEvent, StepModelBuilder, ValueKnownType, ValueModelContext, anyVariablesValueModel, anyVariablesValueModelId, branchesValueModel, branchesValueModelId, choiceValueModel, choiceValueModelId, createBranchedStepModel, createDefinitionModel, createRootModel, createSequentialStepModel, createStepModel, createValidationSingleError, dynamicValueModel, dynamicValueModelId, nullableAnyVariableValueModel, nullableAnyVariableValueModelId, nullableVariableDefinitionValueModel, nullableVariableDefinitionValueModelId, nullableVariableValueModel, nullableVariableValueModelId, numberValueModel, numberValueModelId, sequenceValueModel, sequenceValueModelId, stringValueModel, stringValueModelId, variableDefinitionsValueModel, variableDefinitionsValueModelId }; |
@@ -19,2 +19,3 @@ import { Step, Definition, DefinitionWalker, PropertyValue, Properties, Sequence, ComponentType, BranchedStep, Branches, SequentialStep } from 'sequential-workflow-model'; | ||
} | ||
type NullableAnyVariable = AnyVariable | null; | ||
interface AnyVariables { | ||
@@ -88,6 +89,6 @@ variables: AnyVariable[]; | ||
setValue(value: ReturnType<TValueModel['getDefaultValue']>): void; | ||
getValueTypes(): string[]; | ||
getValueTypes(): ValueType[]; | ||
hasVariable(name: string, valueType: string): boolean; | ||
isVariableDuplicated(name: string): boolean; | ||
getVariables(valueType: string): ContextVariable[]; | ||
getVariables(): ContextVariable[]; | ||
validate(): ValidationResult; | ||
@@ -283,4 +284,12 @@ createChildContext<TChildModel extends ValueModel<PropertyValue, object>>(childModel: TChildModel): ValueModelContext<TChildModel>; | ||
interface NullableAnyVariableValueModelConfiguration { | ||
isRequired?: boolean; | ||
valueTypes?: ValueType[]; | ||
} | ||
type NullableAnyVariableValueModel = ValueModel<NullableAnyVariable, NullableAnyVariableValueModelConfiguration>; | ||
declare const nullableAnyVariableValueModelId = "nullableAnyVariable"; | ||
declare function nullableAnyVariableValueModel(configuration: NullableAnyVariableValueModelConfiguration): ValueModelFactory<NullableAnyVariableValueModel>; | ||
interface NullableVariableValueModelConfiguration { | ||
variableType: ValueType; | ||
valueType: ValueType; | ||
isRequired?: boolean; | ||
@@ -293,3 +302,3 @@ } | ||
interface NullableVariableDefinitionValueModelConfiguration { | ||
variableType: ValueType; | ||
valueType: ValueType; | ||
isRequired?: boolean; | ||
@@ -329,2 +338,3 @@ defaultValue?: VariableDefinition; | ||
interface VariableDefinitionsValueModelConfiguration { | ||
valueTypes?: ValueType[]; | ||
} | ||
@@ -335,2 +345,2 @@ type VariableDefinitionsValueModel = ValueModel<VariableDefinitions, VariableDefinitionsValueModelConfiguration>; | ||
export { AnyVariable, AnyVariables, AnyVariablesValueModel, AnyVariablesValueModelConfiguration, BranchedStepModelBuilder, BranchesValueModel, BranchesValueModelConfiguration, ChoiceValueModel, ChoiceValueModelConfiguration, ContextVariable, CustomValidator, CustomValidatorContext, DefinitionContext, DefinitionModel, DefinitionModelBuilder, Dynamic, DynamicValueModel, DynamicValueModelConfiguration, ModelActivator, ModelValidator, NullableVariable, NullableVariableDefinition, NullableVariableDefinitionValueModel, NullableVariableDefinitionValueModelConfiguration, NullableVariableValueModel, NullableVariableValueModelConfiguration, NumberValueModel, NumberValueModelConfiguration, Path, PropertyModel, PropertyModelBuilder, PropertyModels, RootModel, RootModelBuilder, SequenceValueModel, SequenceValueModelConfiguration, SequentialStepModelBuilder, SimpleEvent, SimpleEventListener, StepModel, StepModelBuilder, StepModels, StringValueModel, StringValueModelConfiguration, UidGenerator, ValidationResult, ValidationSingleError, ValueKnownType, ValueModel, ValueModelContext, ValueModelFactory, ValueModelFactoryOfValue, ValueModelId, ValueType, Variable, VariableDefinition, VariableDefinitions, VariableDefinitionsValueModel, VariableDefinitionsValueModelConfiguration, anyVariablesValueModel, anyVariablesValueModelId, branchesValueModel, branchesValueModelId, choiceValueModel, choiceValueModelId, createBranchedStepModel, createDefinitionModel, createRootModel, createSequentialStepModel, createStepModel, createValidationSingleError, dynamicValueModel, dynamicValueModelId, nullableVariableDefinitionValueModel, nullableVariableDefinitionValueModelId, nullableVariableValueModel, nullableVariableValueModelId, numberValueModel, numberValueModelId, sequenceValueModel, sequenceValueModelId, stringValueModel, stringValueModelId, variableDefinitionsValueModel, variableDefinitionsValueModelId }; | ||
export { AnyVariable, AnyVariables, AnyVariablesValueModel, AnyVariablesValueModelConfiguration, BranchedStepModelBuilder, BranchesValueModel, BranchesValueModelConfiguration, ChoiceValueModel, ChoiceValueModelConfiguration, ContextVariable, CustomValidator, CustomValidatorContext, DefinitionContext, DefinitionModel, DefinitionModelBuilder, Dynamic, DynamicValueModel, DynamicValueModelConfiguration, ModelActivator, ModelValidator, NullableAnyVariable, NullableAnyVariableValueModel, NullableAnyVariableValueModelConfiguration, NullableVariable, NullableVariableDefinition, NullableVariableDefinitionValueModel, NullableVariableDefinitionValueModelConfiguration, NullableVariableValueModel, NullableVariableValueModelConfiguration, NumberValueModel, NumberValueModelConfiguration, Path, PropertyModel, PropertyModelBuilder, PropertyModels, RootModel, RootModelBuilder, SequenceValueModel, SequenceValueModelConfiguration, SequentialStepModelBuilder, SimpleEvent, SimpleEventListener, StepModel, StepModelBuilder, StepModels, StringValueModel, StringValueModelConfiguration, UidGenerator, ValidationResult, ValidationSingleError, ValueKnownType, ValueModel, ValueModelContext, ValueModelFactory, ValueModelFactoryOfValue, ValueModelId, ValueType, Variable, VariableDefinition, VariableDefinitions, VariableDefinitionsValueModel, VariableDefinitionsValueModelConfiguration, anyVariablesValueModel, anyVariablesValueModelId, branchesValueModel, branchesValueModelId, choiceValueModel, choiceValueModelId, createBranchedStepModel, createDefinitionModel, createRootModel, createSequentialStepModel, createStepModel, createValidationSingleError, dynamicValueModel, dynamicValueModelId, nullableAnyVariableValueModel, nullableAnyVariableValueModelId, nullableVariableDefinitionValueModel, nullableVariableDefinitionValueModelId, nullableVariableValueModel, nullableVariableValueModelId, numberValueModel, numberValueModelId, sequenceValueModel, sequenceValueModelId, stringValueModel, stringValueModelId, variableDefinitionsValueModel, variableDefinitionsValueModelId }; |
{ | ||
"name": "sequential-workflow-editor-model", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"homepage": "https://nocode-js.com/", | ||
@@ -5,0 +5,0 @@ "author": { |
Sorry, the diff of this file is not supported yet
125257
2098