Skip to content

Commit

Permalink
0.14.6. (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
b4rtaz authored Feb 5, 2025
1 parent 53c9d33 commit e0b309f
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## O.14.6

Added comments to describe the `BranchedStepModelBuilder`, `SequentialStepModelBuilder` and `RootModelBuilder` classes.

## O.14.5

Added comments to describe the `EditorProvider` class.
Expand Down
4 changes: 2 additions & 2 deletions demos/webpack-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"sequential-workflow-model": "^0.2.0",
"sequential-workflow-designer": "^0.21.2",
"sequential-workflow-machine": "^0.4.0",
"sequential-workflow-editor-model": "^0.14.5",
"sequential-workflow-editor": "^0.14.5"
"sequential-workflow-editor-model": "^0.14.6",
"sequential-workflow-editor": "^0.14.6"
},
"devDependencies": {
"ts-loader": "^9.4.2",
Expand Down
6 changes: 3 additions & 3 deletions editor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sequential-workflow-editor",
"version": "0.14.5",
"version": "0.14.6",
"type": "module",
"main": "./lib/esm/index.js",
"types": "./lib/index.d.ts",
Expand Down Expand Up @@ -46,11 +46,11 @@
"prettier:fix": "prettier --write ./src ./css"
},
"dependencies": {
"sequential-workflow-editor-model": "^0.14.5",
"sequential-workflow-editor-model": "^0.14.6",
"sequential-workflow-model": "^0.2.0"
},
"peerDependencies": {
"sequential-workflow-editor-model": "^0.14.5",
"sequential-workflow-editor-model": "^0.14.6",
"sequential-workflow-model": "^0.2.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion model/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sequential-workflow-editor-model",
"version": "0.14.5",
"version": "0.14.6",
"homepage": "https://nocode-js.com/",
"author": {
"name": "NoCode JS",
Expand Down
4 changes: 4 additions & 0 deletions model/src/builders/branched-step-model-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const branchesPath = Path.create('branches');
export class BranchedStepModelBuilder<TStep extends BranchedStep> extends StepModelBuilder<TStep> {
private readonly branchesBuilder = new PropertyModelBuilder<Branches>(branchesPath, this.circularDependencyDetector);

/**
* @returns the builder for the branches property.
* @example `builder.branches().value(createBranchesValueModel(...));`
*/
public branches(): PropertyModelBuilder<Branches, TStep['properties']> {
return this.branchesBuilder;
}
Expand Down
9 changes: 9 additions & 0 deletions model/src/builders/root-model-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ export class RootModelBuilder<TProperties extends Properties> {
private readonly propertyBuilders: PropertyModelBuilder[] = [];
private readonly sequenceBuilder = new PropertyModelBuilder<Sequence, TProperties>(sequencePath, this.circularDependencyDetector);

/**
* @param propertyName Name of the property.
* @returns The builder for the property.
* @example `builder.property('foo').value(createStringValueModel({ defaultValue: 'Some value' })).label('Foo');`
*/
public property<Key extends keyof TProperties>(propertyName: Key): PropertyModelBuilder<TProperties[Key], TProperties> {
const path = Path.create(['properties', String(propertyName)]);
const builder = new PropertyModelBuilder<TProperties[Key], TProperties>(path, this.circularDependencyDetector);
this.propertyBuilders.push(builder);
return builder;
}

/**
* @returns the builder for the sequence property.
* @example `builder.sequence().value(createSequenceValueModel(...));`
*/
public sequence(): PropertyModelBuilder<Sequence> {
return this.sequenceBuilder;
}
Expand Down
4 changes: 4 additions & 0 deletions model/src/builders/sequential-step-model-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export class SequentialStepModelBuilder<TStep extends SequentialStep> extends St
this.circularDependencyDetector
);

/**
* @returns the builder for the sequence property.
* @example `builder.sequence().value(createSequenceValueModel(...));`
*/
public sequence(): PropertyModelBuilder<Sequence> {
return this.sequenceBuilder;
}
Expand Down
18 changes: 18 additions & 0 deletions model/src/value-models/choice/choice-value-model-configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export interface ChoiceValueModelConfiguration<TValue extends string = string> {
/**
* Label. If not provided, the label is generated from the property name.
*/
label?: string;
/**
* Supported choices.
*/
choices: TValue[];
/**
* Default value.
*/
defaultValue?: TValue;
/**
* Custom editor ID.
*/
editorId?: string;
}
20 changes: 20 additions & 0 deletions model/src/value-models/choice/choice-value-model-validator.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createValueContextStub } from '../../test-tools/value-context-stub';
import { ChoiceValueModel } from './choice-value-model';
import { ChoiceValueModelConfiguration } from './choice-value-model-configuration';
import { choiceValueModelValidator } from './choice-value-model-validator';

describe('choiceValueModelValidator', () => {
it('returns correct response', () => {
const configuration: ChoiceValueModelConfiguration = {
choices: ['x', 'y']
};

const context1 = createValueContextStub<ChoiceValueModel>('z', configuration);
const error1 = choiceValueModelValidator(context1);
expect(error1?.$).toBe('Value is not supported');

const context2 = createValueContextStub<ChoiceValueModel>('x', configuration);
const error2 = choiceValueModelValidator(context2);
expect(error2).toBe(null);
});
});
12 changes: 12 additions & 0 deletions model/src/value-models/choice/choice-value-model-validator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ValueContext } from '../../context';
import { createValidationSingleError, ValidationResult } from '../../model';
import { ChoiceValueModel } from './choice-value-model';

export function choiceValueModelValidator(context: ValueContext<ChoiceValueModel>): ValidationResult {
const value = context.getValue();
const configuration = context.model.configuration;
if (!configuration.choices.includes(value)) {
return createValidationSingleError(context.i18n('choice.notSupportedValue', 'Value is not supported'));
}
return null;
}
20 changes: 4 additions & 16 deletions model/src/value-models/choice/choice-value-model.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { ValueModel, ValidationResult, createValidationSingleError, ValueModelFactory } from '../../model';
import { ValueModel, ValueModelFactory } from '../../model';
import { Path } from '../../core/path';
import { ValueContext } from '../../context';

export interface ChoiceValueModelConfiguration<TValue extends string = string> {
label?: string;
choices: TValue[];
defaultValue?: TValue;
editorId?: string;
}
import { ChoiceValueModelConfiguration } from './choice-value-model-configuration';
import { choiceValueModelValidator } from './choice-value-model-validator';

export type ChoiceValueModel<TValue extends string = string> = ValueModel<TValue, ChoiceValueModelConfiguration<TValue>>;

Expand Down Expand Up @@ -37,13 +31,7 @@ export function createChoiceValueModel<TValue extends string>(
return configuration.choices[0];
},
getVariableDefinitions: () => null,
validate(context: ValueContext<ChoiceValueModel<TValue>>): ValidationResult {
const value = context.getValue();
if (!configuration.choices.includes(value)) {
return createValidationSingleError(context.i18n('choice.notSupportedValue', 'Value is not supported'));
}
return null;
}
validate: choiceValueModelValidator
})
};
}
1 change: 1 addition & 0 deletions model/src/value-models/choice/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './choice-value-model-configuration';
export * from './choice-value-model';

0 comments on commit e0b309f

Please sign in to comment.