Skip to content

Commit 3ab868e

Browse files
committed
squash: optional attributes interfaces and making options for clone use it
Signed-off-by: Lucas Holmquist <[email protected]>
1 parent e568060 commit 3ab868e

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

src/event/cloudevent.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { v4 as uuidv4 } from "uuid";
22

3-
import { CloudEventV1, validateV1, CloudEventV1Attributes } from "./v1";
4-
import { CloudEventV03, validateV03, CloudEventV03Attributes } from "./v03";
3+
import { CloudEventV1, validateV1, CloudEventV1Attributes, CloudEventV1OptionsAttributes } from "./v1";
4+
import { CloudEventV03, validateV03, CloudEventV03Attributes, CloudEventV03OptionsAttributes } from "./v03";
55
import { ValidationError, isBinary, asBase64 } from "./validation";
66
import CONSTANTS from "../constants";
77
import { isString } from "util";
@@ -170,7 +170,15 @@ export class CloudEvent implements CloudEventV1, CloudEventV03 {
170170
}
171171
}
172172

173-
public cloneWith(options?: any): CloudEvent {
174-
return new CloudEvent(Object.assign({}, this.toJSON(), options));
173+
public cloneWith(
174+
options:
175+
| CloudEventV1
176+
| CloudEventV1Attributes
177+
| CloudEventV1OptionsAttributes
178+
| CloudEventV03
179+
| CloudEventV03Attributes
180+
| CloudEventV03OptionsAttributes,
181+
): CloudEvent {
182+
return new CloudEvent(Object.assign({}, this.toJSON(), options) as CloudEvent);
175183
}
176184
}

src/event/v03/cloudevent.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface CloudEventV03 extends CloudEventV03Attributes {
2525
specversion: string;
2626
}
2727

28-
export interface CloudEventV03Attributes {
28+
export interface CloudEventV03Attributes extends CloudEventV03OptionsAttributes {
2929
/**
3030
* [REQUIRED] Identifies the context in which an event happened. Often this
3131
* will include information such as the type of the event source, the
@@ -57,7 +57,9 @@ export interface CloudEventV03Attributes {
5757
* @example com.example.object.delete.v2
5858
*/
5959
type: string;
60+
}
6061

62+
export interface CloudEventV03OptionsAttributes {
6163
/**
6264
* The following fields are optional.
6365
*/

src/event/v1/cloudevent.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface CloudEventV1 extends CloudEventV1Attributes {
2525
specversion: string;
2626
}
2727

28-
export interface CloudEventV1Attributes {
28+
export interface CloudEventV1Attributes extends CloudEventV1OptionsAttributes {
2929
/**
3030
* [REQUIRED] Identifies the context in which an event happened. Often this
3131
* will include information such as the type of the event source, the
@@ -58,7 +58,9 @@ export interface CloudEventV1Attributes {
5858
* @example com.example.object.delete.v2
5959
*/
6060
type: string;
61+
}
6162

63+
export interface CloudEventV1OptionsAttributes {
6264
/**
6365
* The following fields are optional.
6466
*/

0 commit comments

Comments
 (0)