sequential-workflow-editor-model
Advanced tools
Comparing version 0.3.2 to 0.4.0
@@ -1,40 +0,1 @@ | ||
class ModelActivator { | ||
static create(definitionModel, uidGenerator) { | ||
return new ModelActivator(definitionModel, uidGenerator); | ||
} | ||
constructor(definitionModel, uidGenerator) { | ||
this.definitionModel = definitionModel; | ||
this.uidGenerator = uidGenerator; | ||
} | ||
activateDefinition() { | ||
const definition = { | ||
properties: {}, | ||
sequence: this.definitionModel.root.sequence.value.getDefaultValue(this) | ||
}; | ||
this.activateProperties(definition, this.definitionModel.root.properties); | ||
return definition; | ||
} | ||
activateStep(stepType) { | ||
const model = this.definitionModel.steps[stepType]; | ||
if (!model) { | ||
throw new Error(`Unknown step type: ${stepType}`); | ||
} | ||
const step = { | ||
id: this.uidGenerator(), | ||
name: model.name.value.getDefaultValue(this), | ||
type: stepType, | ||
componentType: model.componentType, | ||
properties: {} | ||
}; | ||
this.activateProperties(step, model.properties); | ||
return step; | ||
} | ||
activateProperties(object, models) { | ||
for (const model of models) { | ||
const defaultValue = model.value.getDefaultValue(this); | ||
model.value.path.write(object, defaultValue); | ||
} | ||
} | ||
} | ||
const SEPARATOR = '/'; | ||
@@ -110,5 +71,100 @@ class Path { | ||
class SimpleEvent { | ||
constructor() { | ||
this.listeners = []; | ||
this.forward = (value) => { | ||
if (this.listeners.length > 0) { | ||
this.listeners.forEach(listener => listener(value)); | ||
} | ||
}; | ||
} | ||
subscribe(listener) { | ||
this.listeners.push(listener); | ||
} | ||
unsubscribe(listener) { | ||
const index = this.listeners.indexOf(listener); | ||
if (index >= 0) { | ||
this.listeners.splice(index, 1); | ||
} | ||
else { | ||
throw new Error('Unknown listener'); | ||
} | ||
} | ||
count() { | ||
return this.listeners.length; | ||
} | ||
} | ||
function readPropertyValue(name, model, object) { | ||
const nameStr = String(name); | ||
const path = Path.create(['properties', nameStr]); | ||
if (!model.dependencies.some(dep => dep.equals(path))) { | ||
throw new Error(`Property ${nameStr} is not registered as dependency`); | ||
} | ||
return path.read(object); | ||
} | ||
class DefaultValueContext { | ||
static create(activator, object, model) { | ||
return new DefaultValueContext(activator, name => readPropertyValue(name, model, object)); | ||
} | ||
static createFromValueContext(activator, valueContext) { | ||
return new DefaultValueContext(activator, valueContext.getPropertyValue); | ||
} | ||
constructor(activator, getPropertyValue) { | ||
this.activator = activator; | ||
this.getPropertyValue = getPropertyValue; | ||
this.activateStep = this.activator.activateStep; | ||
} | ||
} | ||
class ModelActivator { | ||
static create(definitionModel, uidGenerator) { | ||
return new ModelActivator(definitionModel, uidGenerator); | ||
} | ||
constructor(definitionModel, uidGenerator) { | ||
this.definitionModel = definitionModel; | ||
this.uidGenerator = uidGenerator; | ||
} | ||
activateDefinition() { | ||
const definition = { | ||
properties: {} | ||
}; | ||
this.activatePropertiesInOrder(definition, this.definitionModel.root.properties); | ||
const sequenceValueContext = DefaultValueContext.create(this, definition, this.definitionModel.root.sequence); | ||
const sequence = this.definitionModel.root.sequence.value.getDefaultValue(sequenceValueContext); | ||
return Object.assign(Object.assign({}, definition), { sequence }); | ||
} | ||
activateStep(stepType) { | ||
const model = this.definitionModel.steps[stepType]; | ||
if (!model) { | ||
throw new Error(`Unknown step type: ${stepType}`); | ||
} | ||
const step = { | ||
id: this.uidGenerator(), | ||
type: stepType, | ||
componentType: model.componentType, | ||
properties: {} | ||
}; | ||
this.activatePropertiesInOrder(step, model.properties); | ||
const nameValueContext = DefaultValueContext.create(this, step, model.name); | ||
const name = model.name.value.getDefaultValue(nameValueContext); | ||
return Object.assign(Object.assign({}, step), { name }); | ||
} | ||
activatePropertiesInOrder(object, models) { | ||
this.activateProperties(object, models.filter(m => m.dependencies.length === 0)); | ||
this.activateProperties(object, models.filter(m => m.dependencies.length > 0)); | ||
} | ||
activateProperties(object, models) { | ||
for (const model of models) { | ||
const defaultValueContext = DefaultValueContext.create(this, object, model); | ||
const defaultValue = model.value.getDefaultValue(defaultValueContext); | ||
model.value.path.write(object, defaultValue); | ||
} | ||
} | ||
} | ||
const anyVariablesValueModelId = 'anyVariables'; | ||
function anyVariablesValueModel(configuration) { | ||
return (path) => ({ | ||
const anyVariablesValueModel = (configuration) => ({ | ||
create: (path) => ({ | ||
id: anyVariablesValueModelId, | ||
@@ -139,8 +195,8 @@ label: 'Variables', | ||
} | ||
}); | ||
} | ||
}) | ||
}); | ||
const booleanValueModelId = 'boolean'; | ||
function booleanValueModel(configuration) { | ||
return (path) => ({ | ||
const booleanValueModel = (configuration) => ({ | ||
create: (path) => ({ | ||
id: booleanValueModelId, | ||
@@ -158,8 +214,8 @@ label: 'Boolean', | ||
validate: () => null | ||
}); | ||
} | ||
}) | ||
}); | ||
const branchesValueModelId = 'branches'; | ||
function branchesValueModel(configuration) { | ||
return (path) => ({ | ||
const branchesValueModel = (configuration) => ({ | ||
create: (path) => ({ | ||
id: branchesValueModelId, | ||
@@ -169,5 +225,5 @@ label: 'Branches', | ||
configuration, | ||
getDefaultValue(activator) { | ||
getDefaultValue(context) { | ||
const branches = Object.keys(configuration.branches).reduce((result, branchName) => { | ||
result[branchName] = configuration.branches[branchName].map(type => activator.activateStep(type)); | ||
result[branchName] = configuration.branches[branchName].map(type => context.activateStep(type)); | ||
return result; | ||
@@ -179,4 +235,4 @@ }, {}); | ||
validate: () => null | ||
}); | ||
} | ||
}) | ||
}); | ||
@@ -194,25 +250,27 @@ function createValidationSingleError(error) { | ||
} | ||
return (path) => ({ | ||
id: choiceValueModelId, | ||
label: 'Choice', | ||
path, | ||
configuration, | ||
getDefaultValue() { | ||
if (configuration.defaultValue) { | ||
if (!configuration.choices.includes(configuration.defaultValue)) { | ||
throw new Error('Default value does not match any of the choices.'); | ||
return { | ||
create: (path) => ({ | ||
id: choiceValueModelId, | ||
label: 'Choice', | ||
path, | ||
configuration, | ||
getDefaultValue() { | ||
if (configuration.defaultValue) { | ||
if (!configuration.choices.includes(configuration.defaultValue)) { | ||
throw new Error('Default value does not match any of the choices.'); | ||
} | ||
return configuration.defaultValue; | ||
} | ||
return configuration.defaultValue; | ||
return configuration.choices[0]; | ||
}, | ||
getVariableDefinitions: () => null, | ||
validate(context) { | ||
const value = context.getValue(); | ||
if (!configuration.choices.includes(value)) { | ||
return createValidationSingleError('Choice is not supported.'); | ||
} | ||
return null; | ||
} | ||
return configuration.choices[0]; | ||
}, | ||
getVariableDefinitions: () => null, | ||
validate(context) { | ||
const value = context.getValue(); | ||
if (!configuration.choices.includes(value)) { | ||
return createValidationSingleError('Choice is not supported.'); | ||
} | ||
return null; | ||
} | ||
}); | ||
}) | ||
}; | ||
} | ||
@@ -225,30 +283,74 @@ | ||
} | ||
return (path) => { | ||
const valuePath = path.add('value'); | ||
const subModels = configuration.models.map(modelFactory => modelFactory(valuePath)); | ||
return { | ||
id: dynamicValueModelId, | ||
label: 'Dynamic value', | ||
return { | ||
create(path) { | ||
const valuePath = path.add('value'); | ||
const subModels = configuration.models.map(modelFactory => modelFactory.create(valuePath)); | ||
return { | ||
id: dynamicValueModelId, | ||
label: 'Dynamic value', | ||
path, | ||
configuration, | ||
subModels, | ||
getDefaultValue(context) { | ||
const model = subModels[0]; | ||
return { | ||
modelId: model.id, | ||
value: model.getDefaultValue(context) | ||
}; | ||
}, | ||
getVariableDefinitions: () => null, | ||
validate(context) { | ||
const value = context.getValue(); | ||
const model = subModels.find(m => m.id === value.modelId); | ||
if (!model) { | ||
const availableModels = subModels.map(m => m.id).join(', '); | ||
throw new Error(`Cannot find sub model id: ${value.modelId} (available: ${availableModels})`); | ||
} | ||
const childContext = context.createChildContext(model); | ||
return model.validate(childContext); | ||
} | ||
}; | ||
} | ||
}; | ||
} | ||
class GeneratedStringContext { | ||
static create(context) { | ||
return new GeneratedStringContext(context); | ||
} | ||
constructor(context) { | ||
this.context = context; | ||
this.getPropertyValue = this.context.getPropertyValue; | ||
} | ||
formatPropertyValue(name, formatter) { | ||
const value = this.getPropertyValue(name); | ||
if (value === undefined || value === null) { | ||
return '?'; | ||
} | ||
return formatter(value); | ||
} | ||
} | ||
const generatedStringValueModelId = 'generatedString'; | ||
function generatedStringValueModel(configuration) { | ||
return { | ||
create: (path) => ({ | ||
id: generatedStringValueModelId, | ||
label: 'Generated string', | ||
path, | ||
configuration, | ||
subModels, | ||
getDefaultValue(activator) { | ||
const model = subModels[0]; | ||
return { | ||
modelId: model.id, | ||
value: model.getDefaultValue(activator) | ||
}; | ||
getDefaultValue(context) { | ||
const subContext = GeneratedStringContext.create(context); | ||
return configuration.generator(subContext); | ||
}, | ||
getVariableDefinitions: () => null, | ||
validate(context) { | ||
const value = context.getValue(); | ||
const model = subModels.find(m => m.id === value.modelId); | ||
if (!model) { | ||
const availableModels = subModels.map(m => m.id).join(', '); | ||
throw new Error(`Cannot find sub model id: ${value.modelId} (available: ${availableModels})`); | ||
const subContext = GeneratedStringContext.create(context); | ||
const value = configuration.generator(subContext); | ||
if (context.getValue() !== value) { | ||
return createValidationSingleError('Generator returns different value than the current value'); | ||
} | ||
const childContext = context.createChildContext(model); | ||
return model.validate(childContext); | ||
return null; | ||
} | ||
}; | ||
}) | ||
}; | ||
@@ -258,4 +360,4 @@ } | ||
const nullableAnyVariableValueModelId = 'nullableAnyVariable'; | ||
function nullableAnyVariableValueModel(configuration) { | ||
return (path) => ({ | ||
const nullableAnyVariableValueModel = (configuration) => ({ | ||
create: (path) => ({ | ||
id: nullableAnyVariableValueModelId, | ||
@@ -284,8 +386,8 @@ label: 'Variable', | ||
} | ||
}); | ||
} | ||
}) | ||
}); | ||
const nullableVariableValueModelId = 'nullableVariable'; | ||
function nullableVariableValueModel(configuration) { | ||
return (path) => ({ | ||
const nullableVariableValueModel = (configuration) => ({ | ||
create: (path) => ({ | ||
id: nullableVariableValueModelId, | ||
@@ -311,4 +413,4 @@ label: 'Variable', | ||
} | ||
}); | ||
} | ||
}) | ||
}); | ||
@@ -330,4 +432,4 @@ const MAX_LENGTH = 32; | ||
const nullableVariableDefinitionValueModelId = 'nullableVariableDefinition'; | ||
function nullableVariableDefinitionValueModel(configuration) { | ||
return (path) => ({ | ||
const nullableVariableDefinitionValueModel = (configuration) => ({ | ||
create: (path) => ({ | ||
id: nullableVariableDefinitionValueModelId, | ||
@@ -366,8 +468,8 @@ label: 'Variable definition', | ||
} | ||
}); | ||
} | ||
}) | ||
}); | ||
const numberValueModelId = 'number'; | ||
function numberValueModel(configuration) { | ||
return (path) => ({ | ||
const numberValueModel = (configuration) => ({ | ||
create: (path) => ({ | ||
id: numberValueModelId, | ||
@@ -400,8 +502,8 @@ label: 'Number', | ||
} | ||
}); | ||
} | ||
}) | ||
}); | ||
const sequenceValueModelId = 'sequence'; | ||
function sequenceValueModel(configuration) { | ||
return (path) => ({ | ||
const sequenceValueModel = (configuration) => ({ | ||
create: (path) => ({ | ||
id: sequenceValueModelId, | ||
@@ -412,9 +514,9 @@ label: 'Sequence', | ||
editorId: null, | ||
getDefaultValue(activator) { | ||
return configuration.sequence.map(type => activator.activateStep(type)); | ||
getDefaultValue(context) { | ||
return configuration.sequence.map(type => context.activateStep(type)); | ||
}, | ||
getVariableDefinitions: () => null, | ||
validate: () => null | ||
}); | ||
} | ||
}) | ||
}); | ||
@@ -434,4 +536,4 @@ function stringValueModelValidator(context) { | ||
const stringValueModelId = 'string'; | ||
function stringValueModel(configuration) { | ||
return (path) => ({ | ||
const stringValueModel = (configuration) => ({ | ||
create: (path) => ({ | ||
id: stringValueModelId, | ||
@@ -446,8 +548,8 @@ label: 'String', | ||
validate: stringValueModelValidator | ||
}); | ||
} | ||
}) | ||
}); | ||
const variableDefinitionsValueModelId = 'variableDefinitions'; | ||
function variableDefinitionsValueModel(configuration) { | ||
return (path) => ({ | ||
const variableDefinitionsValueModel = (configuration) => ({ | ||
create: (path) => ({ | ||
id: variableDefinitionsValueModelId, | ||
@@ -489,4 +591,4 @@ label: 'Variable definitions', | ||
} | ||
}); | ||
} | ||
}) | ||
}); | ||
@@ -570,3 +672,3 @@ function buildLabel(value) { | ||
return { | ||
name: this.path.last(), | ||
path: this.path, | ||
label: this._label || this.getDefaultLabel(), | ||
@@ -576,3 +678,3 @@ hint: this._hint, | ||
customValidator: this._customValidator, | ||
value: this._value(this.path) | ||
value: this._value.create(this.path) | ||
}; | ||
@@ -590,4 +692,4 @@ } | ||
check(source, target) { | ||
if (this.dependencies.some(dep => dep.source.equals(target) && dep.target.equals(source))) { | ||
throw new Error(`Circular dependency detected: ${source.toString()} <-> ${target.toString()}`); | ||
if (this.dependencies.some(dep => dep.source.equals(target))) { | ||
throw new Error(`It is not allowed to depend on dependency with dependency: ${source.toString()} <-> ${target.toString()}`); | ||
} | ||
@@ -614,2 +716,9 @@ this.dependencies.push({ source, target }); | ||
/** | ||
* Sets the label of the step. This field is used in the toolbox and the editor to display the step. | ||
*/ | ||
label(label) { | ||
this._label = label; | ||
return this; | ||
} | ||
/** | ||
* Sets the category of the step. This field is used in the toolbox to group steps. | ||
@@ -651,2 +760,3 @@ * @param category The category of the step. | ||
build() { | ||
var _a; | ||
if (!this.nameBuilder.hasValue()) { | ||
@@ -661,2 +771,3 @@ this.nameBuilder.value(stringValueModel({ | ||
componentType: this.componentType, | ||
label: (_a = this._label) !== null && _a !== void 0 ? _a : buildLabel(this.type), | ||
category: this._category, | ||
@@ -803,36 +914,14 @@ description: this._description, | ||
class SimpleEvent { | ||
constructor() { | ||
this.listeners = []; | ||
class ValueContext { | ||
static create(valueModel, propertyModel, definitionContext) { | ||
return new ValueContext(valueModel, propertyModel, definitionContext); | ||
} | ||
subscribe(listener) { | ||
this.listeners.push(listener); | ||
} | ||
unsubscribe(listener) { | ||
const index = this.listeners.indexOf(listener); | ||
if (index >= 0) { | ||
this.listeners.splice(index, 1); | ||
} | ||
else { | ||
throw new Error('Unknown listener'); | ||
} | ||
} | ||
forward(value) { | ||
if (this.listeners.length > 0) { | ||
this.listeners.forEach(listener => listener(value)); | ||
} | ||
} | ||
count() { | ||
return this.listeners.length; | ||
} | ||
} | ||
class ValueModelContext { | ||
static create(model, definitionContext) { | ||
return new ValueModelContext(model, definitionContext); | ||
} | ||
constructor(model, definitionContext) { | ||
constructor(model, propertyModel, definitionContext) { | ||
this.model = model; | ||
this.propertyModel = propertyModel; | ||
this.definitionContext = definitionContext; | ||
this.onValueChanged = new SimpleEvent(); | ||
this.getPropertyValue = (name) => { | ||
return readPropertyValue(name, this.propertyModel, this.definitionContext.object); | ||
}; | ||
} | ||
@@ -846,2 +935,5 @@ getValue() { | ||
} | ||
validate() { | ||
return this.model.validate(this); | ||
} | ||
getValueTypes() { | ||
@@ -859,8 +951,5 @@ return this.definitionContext.definitionModel.valueTypes; | ||
} | ||
validate() { | ||
return this.model.validate(this); | ||
} | ||
createChildContext(childModel) { | ||
const context = ValueModelContext.create(childModel, this.definitionContext); | ||
context.onValueChanged.subscribe(path => this.onValueChanged.forward(path)); | ||
const context = ValueContext.create(childModel, this.propertyModel, this.definitionContext); | ||
context.onValueChanged.subscribe(this.onValueChanged.forward); | ||
return context; | ||
@@ -889,3 +978,4 @@ } | ||
const parents = this.definitionWalker.getParents(this.definition, this.step); | ||
for (let index = 0; index < parents.length; index++) { | ||
const count = parents.length - 1; // skips variable definitions from itself | ||
for (let index = 0; index < count; index++) { | ||
const parent = parents[index]; | ||
@@ -905,6 +995,6 @@ if (typeof parent === 'string') { | ||
} | ||
appendVariables(result, stepId, propertyModels, editorContext) { | ||
appendVariables(result, stepId, propertyModels, definitionContext) { | ||
for (const propertyModel of propertyModels) { | ||
const context = ValueModelContext.create(propertyModel.value, editorContext); | ||
const definitions = propertyModel.value.getVariableDefinitions(context); | ||
const valueContext = ValueContext.create(propertyModel.value, propertyModel, definitionContext); | ||
const definitions = propertyModel.value.getVariableDefinitions(valueContext); | ||
if (!definitions) { | ||
@@ -943,4 +1033,4 @@ continue; | ||
class CustomValidatorContext { | ||
static create(model, definitionContext) { | ||
return new CustomValidatorContext(model, definitionContext); | ||
static create(propertyModel, definitionContext) { | ||
return new CustomValidatorContext(propertyModel, definitionContext); | ||
} | ||
@@ -952,11 +1042,6 @@ constructor(model, definitionContext) { | ||
getValue() { | ||
return this.model.value.path.read(this.definitionContext.object); | ||
return this.model.path.read(this.definitionContext.object); | ||
} | ||
getPropertyValue(name) { | ||
const nameStr = String(name); | ||
const path = Path.create(['properties', nameStr]); | ||
if (!this.model.dependencies.some(dep => dep.equals(path))) { | ||
throw new Error(`Property ${nameStr} is not registered as dependency`); | ||
} | ||
return path.read(this.definitionContext.object); | ||
return readPropertyValue(name, this.model, this.definitionContext.object); | ||
} | ||
@@ -987,3 +1072,3 @@ } | ||
for (const propertyModel of properties) { | ||
const valueContext = ValueModelContext.create(propertyModel.value, definitionContext); | ||
const valueContext = ValueContext.create(propertyModel.value, propertyModel, definitionContext); | ||
if (propertyModel.value.validate(valueContext)) { | ||
@@ -1011,2 +1096,2 @@ return false; | ||
export { BranchedStepModelBuilder, CustomValidatorContext, DefinitionContext, DefinitionModelBuilder, ModelActivator, ModelValidator, Path, PropertyModelBuilder, RootModelBuilder, SequentialStepModelBuilder, SimpleEvent, StepModelBuilder, ValueKnownType, ValueModelContext, anyVariablesValueModel, anyVariablesValueModelId, booleanValueModel, booleanValueModelId, 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 }; | ||
export { BranchedStepModelBuilder, CustomValidatorContext, DefaultValueContext, DefinitionContext, DefinitionModelBuilder, GeneratedStringContext, ModelActivator, ModelValidator, Path, PropertyModelBuilder, RootModelBuilder, SequentialStepModelBuilder, SimpleEvent, StepModelBuilder, ValueContext, ValueKnownType, anyVariablesValueModel, anyVariablesValueModelId, booleanValueModel, booleanValueModelId, branchesValueModel, branchesValueModelId, choiceValueModel, choiceValueModelId, createBranchedStepModel, createDefinitionModel, createRootModel, createSequentialStepModel, createStepModel, createValidationSingleError, dynamicValueModel, dynamicValueModelId, generatedStringValueModel, generatedStringValueModelId, nullableAnyVariableValueModel, nullableAnyVariableValueModelId, nullableVariableDefinitionValueModel, nullableVariableDefinitionValueModelId, nullableVariableValueModel, nullableVariableValueModelId, numberValueModel, numberValueModelId, sequenceValueModel, sequenceValueModelId, stringValueModel, stringValueModelId, variableDefinitionsValueModel, variableDefinitionsValueModelId }; |
@@ -1,2 +0,3 @@ | ||
import { Step, Definition, DefinitionWalker, PropertyValue, Properties, Sequence, ComponentType, BranchedStep, Branches, SequentialStep } from 'sequential-workflow-model'; | ||
import * as sequential_workflow_model from 'sequential-workflow-model'; | ||
import { Step, Definition, DefinitionWalker, Properties, PropertyValue, Sequence, ComponentType, BranchedStep, Branches, SequentialStep } from 'sequential-workflow-model'; | ||
@@ -49,2 +50,11 @@ interface VariableDefinitions { | ||
declare class SimpleEvent<T> { | ||
private readonly listeners; | ||
subscribe(listener: SimpleEventListener<T>): void; | ||
unsubscribe(listener: SimpleEventListener<T>): void; | ||
readonly forward: (value: T) => void; | ||
count(): number; | ||
} | ||
type SimpleEventListener<T> = (value: T) => void; | ||
declare class VariablesProvider { | ||
@@ -72,15 +82,7 @@ private readonly step; | ||
declare class SimpleEvent<T> { | ||
private readonly listeners; | ||
subscribe(listener: SimpleEventListener<T>): void; | ||
unsubscribe(listener: SimpleEventListener<T>): void; | ||
forward(value: T): void; | ||
count(): number; | ||
} | ||
type SimpleEventListener<T> = (value: T) => void; | ||
declare class ValueModelContext<TValueModel extends ValueModel = ValueModel> { | ||
declare class ValueContext<TValueModel extends ValueModel = ValueModel, TProperties extends Properties = Properties> { | ||
readonly model: TValueModel; | ||
readonly definitionContext: DefinitionContext; | ||
static create<TValueModel extends ValueModel>(model: TValueModel, definitionContext: DefinitionContext): ValueModelContext<TValueModel>; | ||
private readonly propertyModel; | ||
private readonly definitionContext; | ||
static create<TValueModel extends ValueModel>(valueModel: TValueModel, propertyModel: PropertyModel, definitionContext: DefinitionContext): ValueContext<TValueModel>; | ||
readonly onValueChanged: SimpleEvent<Path>; | ||
@@ -90,2 +92,4 @@ private constructor(); | ||
setValue(value: ReturnType<TValueModel['getDefaultValue']>): void; | ||
validate(): ValidationResult; | ||
readonly getPropertyValue: <Key extends keyof TProperties>(name: Key) => TProperties[Key]; | ||
getValueTypes(): ValueType[]; | ||
@@ -95,10 +99,18 @@ hasVariable(name: string, valueType: string): boolean; | ||
getVariables(): ContextVariable[]; | ||
validate(): ValidationResult; | ||
createChildContext<TChildModel extends ValueModel<PropertyValue, object>>(childModel: TChildModel): ValueModelContext<TChildModel>; | ||
createChildContext<TChildModel extends ValueModel<PropertyValue, object, TProperties>>(childModel: TChildModel): ValueContext<TChildModel>; | ||
} | ||
declare class DefaultValueContext<TProperties extends Properties = Properties> { | ||
private readonly activator; | ||
readonly getPropertyValue: <Key extends keyof TProperties>(name: Key) => TProperties[Key]; | ||
static create<TProps extends Properties = Properties>(activator: ModelActivator, object: object, model: PropertyModel): DefaultValueContext<TProps>; | ||
static createFromValueContext<TProps extends Properties = Properties>(activator: ModelActivator, valueContext: ValueContext<ValueModel, TProps>): DefaultValueContext<TProps>; | ||
private constructor(); | ||
readonly activateStep: <TStep extends sequential_workflow_model.Step>(stepType: string) => TStep; | ||
} | ||
declare class CustomValidatorContext<TValue extends PropertyValue = PropertyValue, TProperties extends Properties = Properties> { | ||
private readonly model; | ||
private readonly definitionContext; | ||
static create<TVal extends PropertyValue, TProps extends Properties>(model: PropertyModel<TVal>, definitionContext: DefinitionContext): CustomValidatorContext<TVal, TProps>; | ||
static create<TVal extends PropertyValue, TProps extends Properties>(propertyModel: PropertyModel<TVal>, definitionContext: DefinitionContext): CustomValidatorContext<TVal, TProps>; | ||
private constructor(); | ||
@@ -133,2 +145,3 @@ getValue(): TValue; | ||
category?: string; | ||
label: string; | ||
description?: string; | ||
@@ -140,3 +153,3 @@ name: PropertyModel<string>; | ||
interface PropertyModel<TValue extends PropertyValue = PropertyValue, TConfiguration extends object = object> { | ||
name: string; | ||
path: Path; | ||
label: string; | ||
@@ -146,15 +159,17 @@ hint?: string; | ||
customValidator?: CustomValidator<TValue>; | ||
value: ValueModel<TValue, TConfiguration>; | ||
value: ValueModel<TValue, TConfiguration, Properties>; | ||
} | ||
type ValueModelFactory<TValueModel extends ValueModel = ValueModel> = (path: Path) => TValueModel; | ||
type ValueModelFactoryOfValue<TValue extends PropertyValue = PropertyValue> = (path: Path) => ValueModel<TValue, object>; | ||
interface ValueModel<TValue extends PropertyValue = PropertyValue, TConfiguration extends object = object> { | ||
interface ValueModelFactory<TValue extends PropertyValue = PropertyValue, TConfiguration extends object = object, TProperties extends Properties = Properties> { | ||
create(path: Path): ValueModel<TValue, TConfiguration, TProperties>; | ||
} | ||
type ValueModelFactoryFromModel<TValueModel extends ValueModel = ValueModel> = ValueModelFactory<ReturnType<TValueModel['getDefaultValue']>, TValueModel['configuration']>; | ||
interface ValueModel<TValue extends PropertyValue = PropertyValue, TConfiguration extends object = object, TProperties extends Properties = Properties> { | ||
id: ValueModelId; | ||
path: Path; | ||
label: string; | ||
path: Path; | ||
configuration: TConfiguration; | ||
subModels?: ValueModel[]; | ||
getDefaultValue(activator: ModelActivator): TValue; | ||
getVariableDefinitions(context: ValueModelContext<ValueModel<TValue, TConfiguration>>): VariableDefinition[] | null; | ||
validate(context: ValueModelContext<ValueModel<TValue, TConfiguration>>): ValidationResult; | ||
getDefaultValue(context: DefaultValueContext): TValue; | ||
getVariableDefinitions(context: ValueContext<ValueModel<TValue, TConfiguration, TProperties>>): VariableDefinition[] | null; | ||
validate(context: ValueContext<ValueModel<TValue, TConfiguration, TProperties>>): ValidationResult; | ||
} | ||
@@ -183,2 +198,3 @@ interface CustomValidator<TValue extends PropertyValue = PropertyValue, TProperties extends Properties = Properties> { | ||
activateStep<TStep extends Step>(stepType: string): TStep; | ||
private activatePropertiesInOrder; | ||
private activateProperties; | ||
@@ -210,3 +226,3 @@ } | ||
*/ | ||
value(valueModelFactory: ValueModelFactoryOfValue<TValue>): this; | ||
value(valueModelFactory: ValueModelFactory<TValue, object, TProperties>): this; | ||
/** | ||
@@ -243,2 +259,3 @@ * Sets the label of the property. | ||
protected readonly circularDependencyDetector: CircularDependencyDetector; | ||
private _label?; | ||
private _description?; | ||
@@ -250,2 +267,6 @@ private _category?; | ||
/** | ||
* Sets the label of the step. This field is used in the toolbox and the editor to display the step. | ||
*/ | ||
label(label: string): this; | ||
/** | ||
* Sets the category of the step. This field is used in the toolbox to group steps. | ||
@@ -318,3 +339,3 @@ * @param category The category of the step. | ||
declare const anyVariablesValueModelId = "anyVariables"; | ||
declare function anyVariablesValueModel(configuration: AnyVariablesValueModelConfiguration): ValueModelFactory<AnyVariablesValueModel>; | ||
declare const anyVariablesValueModel: (configuration: AnyVariablesValueModelConfiguration) => ValueModelFactoryFromModel<AnyVariablesValueModel>; | ||
@@ -327,3 +348,3 @@ interface BooleanValueModelConfiguration { | ||
declare const booleanValueModelId = "boolean"; | ||
declare function booleanValueModel(configuration: BooleanValueModelConfiguration): ValueModelFactory<BooleanValueModel>; | ||
declare const booleanValueModel: (configuration: BooleanValueModelConfiguration) => ValueModelFactoryFromModel<BooleanValueModel>; | ||
@@ -339,3 +360,3 @@ interface BranchesValueModelConfiguration { | ||
declare const branchesValueModelId = "branches"; | ||
declare function branchesValueModel<TConfiguration extends BranchesValueModelConfiguration>(configuration: TConfiguration): ValueModelFactory<BranchesValueModel<BranchesOf<TConfiguration>>>; | ||
declare const branchesValueModel: <TConfiguration extends BranchesValueModelConfiguration>(configuration: TConfiguration) => ValueModelFactoryFromModel<BranchesValueModel<BranchesOf<TConfiguration>>>; | ||
@@ -348,13 +369,28 @@ interface ChoiceValueModelConfiguration { | ||
declare const choiceValueModelId = "choice"; | ||
declare function choiceValueModel(configuration: ChoiceValueModelConfiguration): ValueModelFactory<ChoiceValueModel>; | ||
declare function choiceValueModel(configuration: ChoiceValueModelConfiguration): ValueModelFactoryFromModel<ChoiceValueModel>; | ||
interface DynamicValueModelConfiguration<TSubModels extends ValueModelFactory[]> { | ||
interface DynamicValueModelConfiguration<TSubModels extends ValueModelFactoryFromModel[]> { | ||
models: TSubModels; | ||
} | ||
type DynamicValueModel<TSubModels extends ValueModelFactory[] = ValueModelFactory[]> = ValueModel<Dynamic<TValueOf<TSubModels>>, DynamicValueModelConfiguration<ValueModelFactory[]>>; | ||
type ReturnTypeOfModelFactory<TValueModelFactory> = TValueModelFactory extends ValueModelFactory<infer U>[] ? ReturnType<U['getDefaultValue']> : never; | ||
type TValueOf<TValueModelFactory extends ValueModelFactory[]> = ReturnTypeOfModelFactory<TValueModelFactory>; | ||
type DynamicValueModel<TSubModels extends ValueModelFactoryFromModel[] = ValueModelFactoryFromModel[]> = ValueModel<Dynamic<TValueOf<TSubModels>>, DynamicValueModelConfiguration<ValueModelFactoryFromModel[]>>; | ||
type ReturnTypeOfModelFactory<TValueModelFactory> = TValueModelFactory extends ValueModelFactoryFromModel<infer U>[] ? ReturnType<U['getDefaultValue']> : never; | ||
type TValueOf<TValueModelFactory extends ValueModelFactoryFromModel[]> = ReturnTypeOfModelFactory<TValueModelFactory>; | ||
declare const dynamicValueModelId = "dynamic"; | ||
declare function dynamicValueModel<TValueModelFactory extends ValueModelFactory[]>(configuration: DynamicValueModelConfiguration<TValueModelFactory>): ValueModelFactory<DynamicValueModel<TValueModelFactory>>; | ||
declare function dynamicValueModel<TValueModelFactory extends ValueModelFactoryFromModel[]>(configuration: DynamicValueModelConfiguration<TValueModelFactory>): ValueModelFactoryFromModel<DynamicValueModel<TValueModelFactory>>; | ||
interface GeneratedStringValueModelConfiguration<TProperties extends Properties = Properties> { | ||
generator(context: GeneratedStringContext<TProperties>): string; | ||
} | ||
type GeneratedStringVariableValueModel<TProperties extends Properties = Properties> = ValueModel<string, GeneratedStringValueModelConfiguration<TProperties>>; | ||
declare const generatedStringValueModelId = "generatedString"; | ||
declare function generatedStringValueModel<TProperties extends Properties = Properties>(configuration: GeneratedStringValueModelConfiguration<TProperties>): ValueModelFactory<string, GeneratedStringValueModelConfiguration<TProperties>, TProperties>; | ||
declare class GeneratedStringContext<TProperties extends Properties = Properties> { | ||
private readonly context; | ||
static create<TProps extends Properties = Properties>(context: ValueContext<GeneratedStringVariableValueModel<TProps>, TProps> | DefaultValueContext<TProps>): GeneratedStringContext<TProps>; | ||
private constructor(); | ||
readonly getPropertyValue: (<Key extends keyof TProperties>(name: Key) => TProperties[Key]) | (<Key_1 extends keyof TProperties>(name: Key_1) => TProperties[Key_1]); | ||
formatPropertyValue<Key extends keyof TProperties>(name: Key, formatter: (value: NonNullable<TProperties[Key]>) => string): string; | ||
} | ||
interface NullableAnyVariableValueModelConfiguration { | ||
@@ -366,3 +402,3 @@ isRequired?: boolean; | ||
declare const nullableAnyVariableValueModelId = "nullableAnyVariable"; | ||
declare function nullableAnyVariableValueModel(configuration: NullableAnyVariableValueModelConfiguration): ValueModelFactory<NullableAnyVariableValueModel>; | ||
declare const nullableAnyVariableValueModel: (configuration: NullableAnyVariableValueModelConfiguration) => ValueModelFactoryFromModel<NullableAnyVariableValueModel>; | ||
@@ -375,3 +411,3 @@ interface NullableVariableValueModelConfiguration { | ||
declare const nullableVariableValueModelId = "nullableVariable"; | ||
declare function nullableVariableValueModel(configuration: NullableVariableValueModelConfiguration): ValueModelFactory<NullableVariableValueModel>; | ||
declare const nullableVariableValueModel: (configuration: NullableVariableValueModelConfiguration) => ValueModelFactoryFromModel<NullableVariableValueModel>; | ||
@@ -385,3 +421,3 @@ interface NullableVariableDefinitionValueModelConfiguration { | ||
declare const nullableVariableDefinitionValueModelId = "nullableVariableDefinition"; | ||
declare function nullableVariableDefinitionValueModel(configuration: NullableVariableDefinitionValueModelConfiguration): ValueModelFactory<NullableVariableDefinitionValueModel>; | ||
declare const nullableVariableDefinitionValueModel: (configuration: NullableVariableDefinitionValueModelConfiguration) => ValueModelFactoryFromModel<NullableVariableDefinitionValueModel>; | ||
@@ -395,3 +431,3 @@ interface NumberValueModelConfiguration { | ||
declare const numberValueModelId = "number"; | ||
declare function numberValueModel(configuration: NumberValueModelConfiguration): ValueModelFactory<NumberValueModel>; | ||
declare const numberValueModel: (configuration: NumberValueModelConfiguration) => ValueModelFactoryFromModel<NumberValueModel>; | ||
@@ -403,3 +439,3 @@ interface SequenceValueModelConfiguration { | ||
declare const sequenceValueModelId = "sequence"; | ||
declare function sequenceValueModel(configuration: SequenceValueModelConfiguration): ValueModelFactory<SequenceValueModel>; | ||
declare const sequenceValueModel: (configuration: SequenceValueModelConfiguration) => ValueModelFactoryFromModel<SequenceValueModel>; | ||
@@ -414,3 +450,3 @@ interface StringValueModelConfiguration { | ||
declare const stringValueModelId = "string"; | ||
declare function stringValueModel(configuration: StringValueModelConfiguration): ValueModelFactory<StringValueModel>; | ||
declare const stringValueModel: (configuration: StringValueModelConfiguration) => ValueModelFactoryFromModel<StringValueModel>; | ||
@@ -422,4 +458,4 @@ interface VariableDefinitionsValueModelConfiguration { | ||
declare const variableDefinitionsValueModelId = "variableDefinitions"; | ||
declare function variableDefinitionsValueModel(configuration: VariableDefinitionsValueModelConfiguration): ValueModelFactory<VariableDefinitionsValueModel>; | ||
declare const variableDefinitionsValueModel: (configuration: VariableDefinitionsValueModelConfiguration) => ValueModelFactoryFromModel<VariableDefinitionsValueModel>; | ||
export { AnyVariable, AnyVariables, AnyVariablesValueModel, AnyVariablesValueModelConfiguration, BooleanValueModel, BooleanValueModelConfiguration, 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, booleanValueModel, booleanValueModelId, 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 }; | ||
export { AnyVariable, AnyVariables, AnyVariablesValueModel, AnyVariablesValueModelConfiguration, BooleanValueModel, BooleanValueModelConfiguration, BranchedStepModelBuilder, BranchesValueModel, BranchesValueModelConfiguration, ChoiceValueModel, ChoiceValueModelConfiguration, ContextVariable, CustomValidator, CustomValidatorContext, DefaultValueContext, DefinitionContext, DefinitionModel, DefinitionModelBuilder, Dynamic, DynamicValueModel, DynamicValueModelConfiguration, GeneratedStringContext, GeneratedStringValueModelConfiguration, GeneratedStringVariableValueModel, 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, ValueContext, ValueKnownType, ValueModel, ValueModelFactory, ValueModelFactoryFromModel, ValueModelId, ValueType, Variable, VariableDefinition, VariableDefinitions, VariableDefinitionsValueModel, VariableDefinitionsValueModelConfiguration, anyVariablesValueModel, anyVariablesValueModelId, booleanValueModel, booleanValueModelId, branchesValueModel, branchesValueModelId, choiceValueModel, choiceValueModelId, createBranchedStepModel, createDefinitionModel, createRootModel, createSequentialStepModel, createStepModel, createValidationSingleError, dynamicValueModel, dynamicValueModelId, generatedStringValueModel, generatedStringValueModelId, nullableAnyVariableValueModel, nullableAnyVariableValueModelId, nullableVariableDefinitionValueModel, nullableVariableDefinitionValueModelId, nullableVariableValueModel, nullableVariableValueModelId, numberValueModel, numberValueModelId, sequenceValueModel, sequenceValueModelId, stringValueModel, stringValueModelId, variableDefinitionsValueModel, variableDefinitionsValueModelId }; |
{ | ||
"name": "sequential-workflow-editor-model", | ||
"version": "0.3.2", | ||
"version": "0.4.0", | ||
"homepage": "https://nocode-js.com/", | ||
@@ -5,0 +5,0 @@ "author": { |
Sorry, the diff of this file is not supported yet
144805
2520