Skip to content

Remove All Version-Specific Methods #275

Closed
@grant

Description

@grant

Describe the Bug

This module includes a lot of public methods that assume there are are only 2 versions of the spec. We shouldn't copy-and-paste functions across versions. Rather, we should just pass a parameter to specify the CloudEvent version.

Here's an example:

Actual

export function createV1(attributes: CloudEventV1Attributes): CloudEventV1 {
  const event: CloudEventV1 = {
    specversion: schemaV1.definitions.specversion.const,
    id: uuidv4(),
    time: new Date().toISOString(),
    ...attributes,
  };
  return new CloudEvent(event);
}

export function createV03(attributes: CloudEventV03Attributes): CloudEventV03 {
  const event: CloudEventV03 = {
    specversion: schemaV03.definitions.specversion.const,
    id: uuidv4(),
    time: new Date().toISOString(),
    ...attributes,
  };
  return new CloudEvent(event);
}

Expected

export function create(attributes: CloudEventV03Attributes | CloudEventV1Attributes): CloudEvent {
  ...
  return new CloudEvent(event);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions