Skip to content

Commit

Permalink
lib: remove unused event creation functions (#277)
Browse files Browse the repository at this point in the history
This commit removes two functions that are not used.

Signed-off-by: Lance Ball <lball@redhat.com>
  • Loading branch information
lance authored Jul 27, 2020
1 parent 3d82fb6 commit a86cedc
Showing 1 changed file with 1 addition and 23 deletions.
24 changes: 1 addition & 23 deletions src/event/spec.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,21 @@
import Ajv from "ajv";
import { v4 as uuidv4 } from "uuid";
import { ValidationError, isBase64 } from "./validation";

import { CloudEvent } from "./cloudevent";
import { CloudEventV1, CloudEventV1Attributes, CloudEventV03, CloudEventV03Attributes } from "./interfaces";
import { CloudEventV1, CloudEventV03 } from "./interfaces";
import { schemaV03, schemaV1 } from "./schemas";
import CONSTANTS from "../constants";

const ajv = new Ajv({ extendRefs: true });
const isValidAgainstSchemaV1 = ajv.compile(schemaV1);
const isValidAgainstSchemaV03 = ajv.compile(schemaV03);

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 validateV1(event: CloudEventV1): boolean {
if (!isValidAgainstSchemaV1(event)) {
throw new ValidationError("invalid payload", isValidAgainstSchemaV1.errors);
}
return true;
}

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);
}

export function validateV03(event: CloudEventV03): boolean {
if (!isValidAgainstSchemaV03(event)) {
throw new ValidationError("invalid payload", isValidAgainstSchemaV03.errors);
Expand Down

0 comments on commit a86cedc

Please sign in to comment.