Skip to content

Commit

Permalink
feat: add methods to get schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyTseng committed Sep 9, 2024
1 parent 3778e90 commit 4f3ea84
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/validator/__test__/validator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,13 @@ describe('Validator', () => {
await expect(specValidator.validateEvent(event2)).rejects.toThrow();
});
});

it('get schema', () => {
expect(validator.getIncomingMessageSchema()).toBe(
validator['incomingMessageSchema'],
);
expect(validator.getFilterSchema()).toBe(validator['filterSchema']);
expect(validator.getFiltersSchema()).toBe(validator['filtersSchema']);
expect(validator.getEventSchema()).toBe(validator['eventSchema']);
});
});
28 changes: 28 additions & 0 deletions packages/validator/src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,34 @@ export class Validator {
);
}

/**
* Get incoming message schema
*/
getIncomingMessageSchema(): z.ZodType<IncomingMessage> {
return this.incomingMessageSchema;
}

/**
* Get filter schema
*/
getFilterSchema(): z.ZodType<Filter> {
return this.filterSchema;
}

/**
* Get filters schema
*/
getFiltersSchema(): z.ZodType<Filter[]> {
return this.filtersSchema;
}

/**
* Get event schema
*/
getEventSchema(): z.ZodType<Event> {
return this.eventSchema;
}

private async errorHandler<T>(asyncFunc: () => Promise<T>): Promise<T> {
try {
return await asyncFunc();
Expand Down

0 comments on commit 4f3ea84

Please sign in to comment.