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";
55import Spec03 from "./bindings/http/v03/spec_0_3.js" ;
66import Formatter from "./formats/json/formatter.js" ;
77import { isBinary } from "./bindings/http/validation/fun.js" ;
8+ import Extensions from "./extensions" ;
89
910const { SPEC_V1 , SPEC_V03 } = require ( "./bindings/http/constants" ) ;
1011
@@ -18,7 +19,7 @@ export type CE = CloudEventV1 | CloudEventV1Attributes | CloudEventV03 | CloudEv
1819export class CloudEvent {
1920 spec : any ;
2021 formatter : any ;
21- extensions : object ;
22+ extensions : Extensions ;
2223
2324 /**
2425 * 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+
13/**
24 * The object interface for CloudEvents 0.3.
35 * @see https://github.com/cloudevents/spec/blob/v0.3/spec.md
@@ -130,6 +132,8 @@ export interface CloudEventV03Attributes {
130132 /**
131133 * [OPTIONAL] CloudEvents extension attributes.
132134 */
135+ extensions ?: Extensions ;
136+
133137 // tslint:disable-next-line:no-any
134138 [ key : string ] : any ;
135- }
139+ }
Original file line number Diff line number Diff line change 1+ import Extensions from "../extensions" ;
12/**
23 * The object interface for CloudEvents 1.0.
34 * @see https://github.com/cloudevents/spec/blob/v1.0/spec.md
@@ -124,6 +125,8 @@ export interface CloudEventV1Attributes {
124125 /**
125126 * [OPTIONAL] CloudEvents extension attributes.
126127 */
128+ extensions ?: Extensions ;
129+
127130 // tslint:disable-next-line:no-any
128131 [ key : string ] : any ;
129- }
132+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { expect } from "chai";
22import { CloudEvent } from "../" ;
33import { CloudEventV03Attributes } from "../lib/v03" ;
44import { CloudEventV1Attributes } from "../lib/v1" ;
5+ import Extensions from "../lib/extensions" ;
56
67const { SPEC_V1 , SPEC_V03 } = require ( "../lib/bindings/http/constants" ) ;
78
@@ -120,13 +121,14 @@ describe("A 1.0 CloudEvent", () => {
120121 } ) ;
121122
122123 it ( "can be constructed with extensions" , ( ) => {
123- const extensions = {
124+ const extensions : Extensions = {
124125 "extension-key" : "extension-value"
125126 } ;
126127 const ce = new CloudEvent ( {
127128 extensions, ...fixture
128129 } ) ;
129130 expect ( Object . keys ( ce . extensions ) . length ) . to . equal ( 1 ) ;
131+ expect ( ce . extensions [ "extension-key" ] ) . to . equal ( extensions [ "extension-key" ] ) ;
130132 } ) ;
131133
132134 it ( "throws ValidationError if the CloudEvent does not conform to the schema" ) ;
You can’t perform that action at this time.
0 commit comments