Skip to content

Commit 4c19f76

Browse files
committed
added metadata.builder
Signed-off-by: Antonio Mendoza Pérez <[email protected]>
1 parent ae494d6 commit 4c19f76

File tree

6 files changed

+122
-19
lines changed

6 files changed

+122
-19
lines changed

spec/metadata-builder.spec.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2021-Present The Serverless Workflow Specification Authors
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
import {MetadataBuilder} from '../src/model/metadata.builder';
18+
19+
20+
describe("MetadataBuilder", () => {
21+
22+
it("should create an empty object ", () => {
23+
24+
expect(new MetadataBuilder().build()).toEqual({});
25+
26+
});
27+
28+
it("should create an object with key/value strings ", () => {
29+
30+
expect(new MetadataBuilder()
31+
.withKeyValue("k1", "v1")
32+
.build()).toEqual(
33+
{
34+
"k1": "v1",
35+
});
36+
37+
38+
expect(new MetadataBuilder()
39+
.withKeyValue("k2", "v2")
40+
.withKeyValue("k3", "v3")
41+
.build()).toEqual(
42+
{
43+
"k2": "v2",
44+
"k3": "v3",
45+
});
46+
47+
48+
});
49+
50+
51+
it("should allow to overwrite pairs of key/value ", () => {
52+
53+
expect(new MetadataBuilder()
54+
.withKeyValue("k1", "v1")
55+
.withKeyValue("k1", "v2")
56+
.build()).toEqual(
57+
{
58+
"k1": "v2",
59+
});
60+
61+
62+
});
63+
64+
65+
});
66+
67+
68+

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export {EventRefBuilder} from "./model/event-ref.builder";
2626
export {FunctionBuilder} from "./model/function.builder";
2727
export {FunctionRefImplBuilder} from "./model/function-ref-impl.builder";
2828
export {InjectStateBuilder} from "./model/inject-state.builder";
29+
export {MetadataBuilder} from "./model/metadata.builder";
2930
export {OperationStateBuilder} from "./model/operation-state.builder";
3031
export {ProduceEventDefBuilder} from "./model/produce-event-def.builder";
3132
export {RepeatBuilder} from "./model/repeat.builder";

src/model/metadata.builder.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2021-Present The Serverless Workflow Specification Authors
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
import {Metadata} from '../index';
18+
19+
export class MetadataBuilder {
20+
21+
private model: Metadata = {};
22+
23+
withKeyValue(key: string, value: string): MetadataBuilder {
24+
25+
Object.assign(this.model, {[key]: value});
26+
return this;
27+
28+
}
29+
30+
build(): Metadata {
31+
return this.model;
32+
}
33+
34+
}

src/model/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export type StartScheduledType = {
199199
schedule: Schedule;
200200
};
201201

202-
export type MetadataType = {
202+
export type Metadata = {
203203
[k: string]: string;
204204
};
205205

@@ -248,7 +248,7 @@ type EventType = {
248248
/**
249249
* Metadata information
250250
*/
251-
metadata?: MetadataType;
251+
metadata?: Metadata;
252252
};
253253
export type EventsDef = | string
254254
| [

src/model/workflow.builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*/
1717
import {Exectimeout, StartDef, Workflow} from "./workflow";
18-
import {EventsDef, FunctionsDef, MetadataType, RetriesDef, StatesType} from "./types";
18+
import {EventsDef, FunctionsDef, Metadata, RetriesDef, StatesType} from "./types";
1919
import {ValidatorFactory} from "./workflow.validator";
2020

2121

@@ -87,7 +87,7 @@ export class WorkflowBuilder {
8787
return this;
8888
}
8989

90-
withMetadata(value: MetadataType): WorkflowBuilder {
90+
withMetadata(value: Metadata): WorkflowBuilder {
9191
this.model.metadata = value;
9292
return this;
9393
}

src/model/workflow.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
DataConditionsType,
2121
DefaultTransitionType,
2222
EndType, EventsDef,
23-
FunctionsDef, Interval, MetadataType, ProduceEventsDef, RepeatType, RetriesDef, StartScheduledType,
23+
FunctionsDef, Interval, Metadata, ProduceEventsDef, RepeatType, RetriesDef, StartScheduledType,
2424
StateDataFilterType,
2525
StatesType,
2626
} from "./types";
@@ -63,7 +63,7 @@ export type Workflow = {
6363
/**
6464
* Metadata information
6565
*/
66-
metadata?: MetadataType;
66+
metadata?: Metadata;
6767
events?: EventsDef;
6868
functions?:FunctionsDef;
6969
retries?:RetriesDef;
@@ -235,7 +235,7 @@ export interface DelayState {
235235
/**
236236
* Metadata information
237237
*/
238-
metadata?: MetadataType;
238+
metadata?: Metadata;
239239
}
240240

241241

@@ -313,7 +313,7 @@ export interface OperationState {
313313
/**
314314
* Metadata information
315315
*/
316-
metadata?: MetadataType;
316+
metadata?: Metadata;
317317
}
318318

319319
/**
@@ -401,7 +401,7 @@ export interface ParallelState {
401401
/**
402402
* Metadata information
403403
*/
404-
metadata?: MetadataType;
404+
metadata?: Metadata;
405405
}
406406

407407

@@ -455,7 +455,7 @@ export interface Databasedswitch {
455455
/**
456456
* Metadata information
457457
*/
458-
metadata?: MetadataType;
458+
metadata?: Metadata;
459459
}
460460

461461
/**
@@ -492,7 +492,7 @@ export interface Transitiondatacondition {
492492
/**
493493
* Metadata information
494494
*/
495-
metadata?: MetadataType;
495+
metadata?: Metadata;
496496
}
497497

498498
/**
@@ -514,7 +514,7 @@ export interface Enddatacondition {
514514
/**
515515
* Metadata information
516516
*/
517-
metadata?: MetadataType;
517+
metadata?: Metadata;
518518
}
519519

520520
/**
@@ -571,7 +571,7 @@ export interface Eventbasedswitch {
571571
/**
572572
* Metadata information
573573
*/
574-
metadata?: MetadataType;
574+
metadata?: Metadata;
575575
}
576576

577577
/**
@@ -621,7 +621,7 @@ export interface Transitioneventcondition {
621621
/**
622622
* Metadata information
623623
*/
624-
metadata?: MetadataType;
624+
metadata?: Metadata;
625625
}
626626

627627
/**
@@ -657,7 +657,7 @@ export interface Enddeventcondition {
657657
/**
658658
* Metadata information
659659
*/
660-
metadata?: MetadataType;
660+
metadata?: Metadata;
661661
}
662662

663663

@@ -739,7 +739,7 @@ export interface SubFlowState {
739739
/**
740740
* Metadata information
741741
*/
742-
metadata?: MetadataType;
742+
metadata?: Metadata;
743743
}
744744

745745
/**
@@ -803,7 +803,7 @@ export interface InjectState {
803803
/**
804804
* Metadata information
805805
*/
806-
metadata?: MetadataType;
806+
metadata?: Metadata;
807807
}
808808

809809
/**
@@ -903,7 +903,7 @@ export interface ForEachState {
903903
/**
904904
* Metadata information
905905
*/
906-
metadata?: MetadataType;
906+
metadata?: Metadata;
907907
}
908908

909909
/**
@@ -1003,7 +1003,7 @@ export interface CallbackState {
10031003
/**
10041004
* Metadata information
10051005
*/
1006-
metadata?: MetadataType;
1006+
metadata?: Metadata;
10071007
}
10081008

10091009

0 commit comments

Comments
 (0)