Skip to content

Commit b7e7a3f

Browse files
authored
Merge pull request #108 from neuroglia-io/validation
Validation (+Update & format)
2 parents 6cd783a + 8d59c68 commit b7e7a3f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+212
-525
lines changed

README.md

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -73,31 +73,6 @@ const workflow: Specification.Workflow = workflowBuilder()
7373
```
7474

7575

76-
#### Create Workflow using object literals
77-
78-
```typescript
79-
import { Specification } from '@severlessworkflow/sdk-typescript';
80-
81-
const workflow: Specification.Workflow = {
82-
id: 'helloworld',
83-
version: '1.0',
84-
name: 'Hello World Workflow',
85-
description: 'Inject Hello World',
86-
start: 'Hello State',
87-
states: [
88-
{
89-
type: 'inject',
90-
name: 'Hello State',
91-
end: true,
92-
data: {
93-
result: "Hello World!"
94-
}
95-
} as Specification.Injectstate
96-
]
97-
};
98-
```
99-
100-
10176
#### Load a file JSON/YAML to a Workflow instance
10277

10378
```typescript

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"tools:download-schemas": "npx ts-node --project ./tools/tsconfig.json ./tools/download-schemas.ts",
1919
"tools:generate-definitions": "npx ts-node --project ./tools/tsconfig.json ./tools/generate-definitions.ts",
2020
"tools:generate-builders": "npx ts-node --project ./tools/tsconfig.json ./tools/generate-builders.ts",
21-
"update-code-base": "npm run tools:download-schemas && npm run tools:generate-definitions && npm run tools:generate-builders",
21+
"update-code-base": "npm run tools:download-schemas && npm run tools:generate-definitions && npm run tools:generate-builders && npm run format && npm run test",
2222
"format": "npx prettier --write \"**/*.ts\"",
2323
"lint": "npx eslint . --ext .ts && npx prettier --check \"**/*.ts\"",
2424
"pretest": "npx rimraf out-tsc",

src/lib/builders/action-builder.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
*
1616
*/
1717

18-
import { DefinedError } from 'ajv';
1918
import { Builder, builder } from '../builder';
2019
import { Specification } from '../definitions';
21-
import { validators } from '../validators';
20+
import { validate } from '../utils';
2221

2322
/**
2423
* The internal function used by the builder proxy to validate and return its underlying object
@@ -27,14 +26,7 @@ import { validators } from '../validators';
2726
*/
2827
function actionBuildingFn(data: Specification.Action): () => Specification.Action {
2928
return () => {
30-
const validate = validators.get('Action');
31-
// TODO: ignore validation if no validator or throw ?
32-
if (!validate) return data;
33-
if (!validate(data)) {
34-
console.warn(validate.errors);
35-
const firstError: DefinedError = (validate.errors as DefinedError[])[0];
36-
throw new Error(`Action is invalid: ${firstError.message}`);
37-
}
29+
validate('Action', data);
3830
return data;
3931
};
4032
}

src/lib/builders/actiondatafilter-builder.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
*
1616
*/
1717

18-
import { DefinedError } from 'ajv';
1918
import { Builder, builder } from '../builder';
2019
import { Specification } from '../definitions';
21-
import { validators } from '../validators';
20+
import { validate } from '../utils';
2221

2322
/**
2423
* The internal function used by the builder proxy to validate and return its underlying object
@@ -27,14 +26,7 @@ import { validators } from '../validators';
2726
*/
2827
function actiondatafilterBuildingFn(data: Specification.Actiondatafilter): () => Specification.Actiondatafilter {
2928
return () => {
30-
const validate = validators.get('Actiondatafilter');
31-
// TODO: ignore validation if no validator or throw ?
32-
if (!validate) return data;
33-
if (!validate(data)) {
34-
console.warn(validate.errors);
35-
const firstError: DefinedError = (validate.errors as DefinedError[])[0];
36-
throw new Error(`Actiondatafilter is invalid: ${firstError.message}`);
37-
}
29+
validate('Actiondatafilter', data);
3830
return data;
3931
};
4032
}

src/lib/builders/branch-builder.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
*
1616
*/
1717

18-
import { DefinedError } from 'ajv';
1918
import { Builder, builder } from '../builder';
2019
import { Specification } from '../definitions';
21-
import { validators } from '../validators';
20+
import { validate } from '../utils';
2221

2322
/**
2423
* The internal function used by the builder proxy to validate and return its underlying object
@@ -27,14 +26,7 @@ import { validators } from '../validators';
2726
*/
2827
function branchBuildingFn(data: Specification.Branch): () => Specification.Branch {
2928
return () => {
30-
const validate = validators.get('Branch');
31-
// TODO: ignore validation if no validator or throw ?
32-
if (!validate) return data;
33-
if (!validate(data)) {
34-
console.warn(validate.errors);
35-
const firstError: DefinedError = (validate.errors as DefinedError[])[0];
36-
throw new Error(`Branch is invalid: ${firstError.message}`);
37-
}
29+
validate('Branch', data);
3830
return data;
3931
};
4032
}

src/lib/builders/callbackstate-builder.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
*
1616
*/
1717

18-
import { DefinedError } from 'ajv';
1918
import { Builder, builder } from '../builder';
2019
import { Specification } from '../definitions';
21-
import { validators } from '../validators';
20+
import { validate } from '../utils';
2221

2322
/**
2423
* The internal function used by the builder proxy to validate and return its underlying object
@@ -28,14 +27,7 @@ import { validators } from '../validators';
2827
function callbackstateBuildingFn(data: Specification.Callbackstate): () => Specification.Callbackstate {
2928
return () => {
3029
data.type = 'callback';
31-
const validate = validators.get('Callbackstate');
32-
// TODO: ignore validation if no validator or throw ?
33-
if (!validate) return data;
34-
if (!validate(data)) {
35-
console.warn(validate.errors);
36-
const firstError: DefinedError = (validate.errors as DefinedError[])[0];
37-
throw new Error(`Callbackstate is invalid: ${firstError.message}`);
38-
}
30+
validate('Callbackstate', data);
3931
return data;
4032
};
4133
}

src/lib/builders/correlation-def-builder.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
*
1616
*/
1717

18-
import { DefinedError } from 'ajv';
1918
import { Builder, builder } from '../builder';
2019
import { Specification } from '../definitions';
21-
import { validators } from '../validators';
20+
import { validate } from '../utils';
2221

2322
/**
2423
* The internal function used by the builder proxy to validate and return its underlying object
@@ -27,14 +26,7 @@ import { validators } from '../validators';
2726
*/
2827
function correlationDefBuildingFn(data: Specification.CorrelationDef): () => Specification.CorrelationDef {
2928
return () => {
30-
const validate = validators.get('CorrelationDef');
31-
// TODO: ignore validation if no validator or throw ?
32-
if (!validate) return data;
33-
if (!validate(data)) {
34-
console.warn(validate.errors);
35-
const firstError: DefinedError = (validate.errors as DefinedError[])[0];
36-
throw new Error(`CorrelationDef is invalid: ${firstError.message}`);
37-
}
29+
validate('CorrelationDef', data);
3830
return data;
3931
};
4032
}

src/lib/builders/crondef-builder.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
*
1616
*/
1717

18-
import { DefinedError } from 'ajv';
1918
import { Builder, builder } from '../builder';
2019
import { Specification } from '../definitions';
21-
import { validators } from '../validators';
20+
import { validate } from '../utils';
2221

2322
/**
2423
* The internal function used by the builder proxy to validate and return its underlying object
@@ -27,14 +26,7 @@ import { validators } from '../validators';
2726
*/
2827
function crondefBuildingFn(data: Specification.Crondef): () => Specification.Crondef {
2928
return () => {
30-
const validate = validators.get('Crondef');
31-
// TODO: ignore validation if no validator or throw ?
32-
if (!validate) return data;
33-
if (!validate(data)) {
34-
console.warn(validate.errors);
35-
const firstError: DefinedError = (validate.errors as DefinedError[])[0];
36-
throw new Error(`Crondef is invalid: ${firstError.message}`);
37-
}
29+
validate('Crondef', data);
3830
return data;
3931
};
4032
}

src/lib/builders/databasedswitch-builder.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
*
1616
*/
1717

18-
import { DefinedError } from 'ajv';
1918
import { Builder, builder } from '../builder';
2019
import { Specification } from '../definitions';
21-
import { validators } from '../validators';
20+
import { validate } from '../utils';
2221

2322
/**
2423
* The internal function used by the builder proxy to validate and return its underlying object
@@ -28,14 +27,7 @@ import { validators } from '../validators';
2827
function databasedswitchBuildingFn(data: Specification.Databasedswitch): () => Specification.Databasedswitch {
2928
return () => {
3029
data.type = 'switch';
31-
const validate = validators.get('Databasedswitch');
32-
// TODO: ignore validation if no validator or throw ?
33-
if (!validate) return data;
34-
if (!validate(data)) {
35-
console.warn(validate.errors);
36-
const firstError: DefinedError = (validate.errors as DefinedError[])[0];
37-
throw new Error(`Databasedswitch is invalid: ${firstError.message}`);
38-
}
30+
validate('Databasedswitch', data);
3931
return data;
4032
};
4133
}

src/lib/builders/datacondition-builder.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
*
1616
*/
1717

18-
import { DefinedError } from 'ajv';
1918
import { Builder, builder } from '../builder';
2019
import { Specification } from '../definitions';
21-
import { validators } from '../validators';
20+
import { validate } from '../utils';
2221

2322
/**
2423
* The internal function used by the builder proxy to validate and return its underlying object
@@ -27,14 +26,7 @@ import { validators } from '../validators';
2726
*/
2827
function dataconditionBuildingFn(data: Specification.Datacondition): () => Specification.Datacondition {
2928
return () => {
30-
const validate = validators.get('Datacondition');
31-
// TODO: ignore validation if no validator or throw ?
32-
if (!validate) return data;
33-
if (!validate(data)) {
34-
console.warn(validate.errors);
35-
const firstError: DefinedError = (validate.errors as DefinedError[])[0];
36-
throw new Error(`Datacondition is invalid: ${firstError.message}`);
37-
}
29+
validate('Datacondition', data);
3830
return data;
3931
};
4032
}

0 commit comments

Comments
 (0)