File tree Expand file tree Collapse file tree 5 files changed +17
-4
lines changed Expand file tree Collapse file tree 5 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import Spec1 from "./bindings/http/v1/spec_1.js";
5
5
import Spec03 from "./bindings/http/v03/spec_0_3.js" ;
6
6
import Formatter from "./formats/json/formatter.js" ;
7
7
import { isBinary } from "./bindings/http/validation/fun.js" ;
8
+ import Extensions from "./extensions" ;
8
9
9
10
const { SPEC_V1 , SPEC_V03 } = require ( "./bindings/http/constants" ) ;
10
11
@@ -18,7 +19,7 @@ export type CE = CloudEventV1 | CloudEventV1Attributes | CloudEventV03 | CloudEv
18
19
export class CloudEvent {
19
20
spec : any ;
20
21
formatter : any ;
21
- extensions : object ;
22
+ extensions : Extensions ;
22
23
23
24
/**
24
25
* Creates a new CloudEvent instance
Original file line number Diff line number Diff line change
1
+ export default interface Extensions {
2
+ [ key : string ] : any
3
+ }
Original file line number Diff line number Diff line change
1
+ import Extensions from "../extensions" ;
2
+
1
3
/**
2
4
* The object interface for CloudEvents 0.3.
3
5
* @see https://github.com/cloudevents/spec/blob/v0.3/spec.md
@@ -130,6 +132,8 @@ export interface CloudEventV03Attributes {
130
132
/**
131
133
* [OPTIONAL] CloudEvents extension attributes.
132
134
*/
135
+ extensions ?: Extensions ;
136
+
133
137
// tslint:disable-next-line:no-any
134
138
[ key : string ] : any ;
135
- }
139
+ }
Original file line number Diff line number Diff line change
1
+ import Extensions from "../extensions" ;
1
2
/**
2
3
* The object interface for CloudEvents 1.0.
3
4
* @see https://github.com/cloudevents/spec/blob/v1.0/spec.md
@@ -124,6 +125,8 @@ export interface CloudEventV1Attributes {
124
125
/**
125
126
* [OPTIONAL] CloudEvents extension attributes.
126
127
*/
128
+ extensions ?: Extensions ;
129
+
127
130
// tslint:disable-next-line:no-any
128
131
[ key : string ] : any ;
129
- }
132
+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { expect } from "chai";
2
2
import { CloudEvent } from "../" ;
3
3
import { CloudEventV03Attributes } from "../lib/v03" ;
4
4
import { CloudEventV1Attributes } from "../lib/v1" ;
5
+ import Extensions from "../lib/extensions" ;
5
6
6
7
const { SPEC_V1 , SPEC_V03 } = require ( "../lib/bindings/http/constants" ) ;
7
8
@@ -120,13 +121,14 @@ describe("A 1.0 CloudEvent", () => {
120
121
} ) ;
121
122
122
123
it ( "can be constructed with extensions" , ( ) => {
123
- const extensions = {
124
+ const extensions : Extensions = {
124
125
"extension-key" : "extension-value"
125
126
} ;
126
127
const ce = new CloudEvent ( {
127
128
extensions, ...fixture
128
129
} ) ;
129
130
expect ( Object . keys ( ce . extensions ) . length ) . to . equal ( 1 ) ;
131
+ expect ( ce . extensions [ "extension-key" ] ) . to . equal ( extensions [ "extension-key" ] ) ;
130
132
} ) ;
131
133
132
134
it ( "throws ValidationError if the CloudEvent does not conform to the schema" ) ;
You can’t perform that action at this time.
0 commit comments