File tree Expand file tree Collapse file tree 5 files changed +34
-23
lines changed Expand file tree Collapse file tree 5 files changed +34
-23
lines changed Original file line number Diff line number Diff line change 1- import { CloudEventV1 } from "./v1" ;
2- import { CloudEventV03 } from "./v03" ;
1+ import { CloudEventV1 , CloudEventV1Attributes } from "./v1" ;
2+ import { CloudEventV03 , CloudEventV03Attributes } from "./v03" ;
33
44import Spec1 from "./bindings/http/v1/spec_1.js" ;
55import Spec03 from "./bindings/http/v03/spec_0_3.js" ;
@@ -8,6 +8,8 @@ import { isBinary } from "./bindings/http/validation/fun.js";
88
99const { SPEC_V1 , SPEC_V03 } = require ( "./bindings/http/constants.js" ) ;
1010
11+ export type Event = CloudEventV1 | CloudEventV1Attributes | CloudEventV03 | CloudEventV03Attributes
12+
1113/**
1214 * A CloudEvent describes event data in common formats to provide
1315 * interoperability across services, platforms and systems.
@@ -33,7 +35,7 @@ export class CloudEvent {
3335 * @param {string } [event.specversion] The CloudEvent specification version for this event - default: 1.0
3436 * @param {* } [event.data] The event payload
3537 */
36- constructor ( event : CloudEventV1 | CloudEventV03 | any ) {
38+ constructor ( event : Event ) {
3739 if ( ! event || ! event . type || ! event . source ) {
3840 throw new TypeError ( "event type and source are required" ) ;
3941 }
Original file line number Diff line number Diff line change 22 * The object interface for CloudEvents 0.3.
33 * @see https://github.com/cloudevents/spec/blob/v0.3/spec.md
44 */
5- export interface CloudEventV03 {
5+
6+ export interface CloudEventV03 extends CloudEventV03Attributes {
67 // REQUIRED Attributes
78 /**
89 * [REQUIRED] Identifies the event. Producers MUST ensure that `source` + `id`
@@ -14,6 +15,17 @@ export interface CloudEventV03 {
1415 * @example A UUID
1516 */
1617 id : string ;
18+ /**
19+ * [REQUIRED] The version of the CloudEvents specification which the event
20+ * uses. This enables the interpretation of the context. Compliant event
21+ * producers MUST use a value of `1.0` when referring to this version of the
22+ * specification.
23+ * @required MUST be a non-empty string.
24+ */
25+ specversion : string ;
26+ }
27+
28+ export interface CloudEventV03Attributes {
1729 /**
1830 * [REQUIRED] Identifies the context in which an event happened. Often this
1931 * will include information such as the type of the event source, the
@@ -30,14 +42,6 @@ export interface CloudEventV03 {
3042 * @required Non-empty URI-reference
3143 */
3244 source : string ;
33- /**
34- * [REQUIRED] The version of the CloudEvents specification which the event
35- * uses. This enables the interpretation of the context. Compliant event
36- * producers MUST use a value of `1.0` when referring to this version of the
37- * specification.
38- * @required MUST be a non-empty string.
39- */
40- specversion : string ;
4145 /**
4246 * [REQUIRED] This attribute contains a value describing the type of event
4347 * related to the originating occurrence. Often this attribute is used for
Original file line number Diff line number Diff line change 22 * The object interface for CloudEvents 1.0.
33 * @see https://github.com/cloudevents/spec/blob/v1.0/spec.md
44 */
5- export interface CloudEventV1 {
5+ export interface CloudEventV1 extends CloudEventV1Attributes {
66 // REQUIRED Attributes
77 /**
88 * [REQUIRED] Identifies the event. Producers MUST ensure that `source` + `id`
@@ -14,6 +14,18 @@ export interface CloudEventV1 {
1414 * @example A UUID
1515 */
1616 id : string ;
17+
18+ /**
19+ * [REQUIRED] The version of the CloudEvents specification which the event
20+ * uses. This enables the interpretation of the context. Compliant event
21+ * producers MUST use a value of `1.0` when referring to this version of the
22+ * specification.
23+ * @required MUST be a non-empty string.
24+ */
25+ specversion : string ;
26+ }
27+
28+ export interface CloudEventV1Attributes {
1729 /**
1830 * [REQUIRED] Identifies the context in which an event happened. Often this
1931 * will include information such as the type of the event source, the
@@ -30,14 +42,7 @@ export interface CloudEventV1 {
3042 * @required Non-empty URI-reference
3143 */
3244 source : string ;
33- /**
34- * [REQUIRED] The version of the CloudEvents specification which the event
35- * uses. This enables the interpretation of the context. Compliant event
36- * producers MUST use a value of `1.0` when referring to this version of the
37- * specification.
38- * @required MUST be a non-empty string.
39- */
40- specversion : string ;
45+
4146 /**
4247 * [REQUIRED] This attribute contains a value describing the type of event
4348 * related to the originating occurrence. Often this attribute is used for
Original file line number Diff line number Diff line change 11const { expect } = require ( "chai" ) ;
2- const { CloudEvent, HTTPReceiver } = require ( "../../..// index.js" ) ;
2+ const { CloudEvent, HTTPReceiver } = require ( "../../../index.js" ) ;
33const {
44 HEADER_CONTENT_TYPE ,
55 DEFAULT_CONTENT_TYPE ,
Original file line number Diff line number Diff line change 11const expect = require ( "chai" ) . expect ;
22const { Spec } = require ( "../../../lib/bindings/http/v1/index.js" ) ;
3- const { CloudEvent } = require ( "../../..// index.js" ) ;
3+ const { CloudEvent } = require ( "../../../index.js" ) ;
44const { asBase64 } = require ( "../../../lib/bindings/http/validation/fun.js" ) ;
55const { SPEC_V1 } = require ( "../../../lib/bindings/http/constants.js" ) ;
66const ValidationError = require ( "../../../lib/bindings/http/validation/validation_error.js" ) ;
You can’t perform that action at this time.
0 commit comments