From 4f3ea84cff3e2114d30d941f8e3360141f8312d5 Mon Sep 17 00:00:00 2001 From: codytseng Date: Mon, 9 Sep 2024 14:14:42 +0800 Subject: [PATCH] feat: add methods to get schemas --- packages/validator/__test__/validator.spec.ts | 9 ++++++ packages/validator/src/validator.ts | 28 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/packages/validator/__test__/validator.spec.ts b/packages/validator/__test__/validator.spec.ts index 916abbab..456b44ef 100644 --- a/packages/validator/__test__/validator.spec.ts +++ b/packages/validator/__test__/validator.spec.ts @@ -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']); + }); }); diff --git a/packages/validator/src/validator.ts b/packages/validator/src/validator.ts index e1d7315a..fc48e8fd 100644 --- a/packages/validator/src/validator.ts +++ b/packages/validator/src/validator.ts @@ -75,6 +75,34 @@ export class Validator { ); } + /** + * Get incoming message schema + */ + getIncomingMessageSchema(): z.ZodType { + return this.incomingMessageSchema; + } + + /** + * Get filter schema + */ + getFilterSchema(): z.ZodType { + return this.filterSchema; + } + + /** + * Get filters schema + */ + getFiltersSchema(): z.ZodType { + return this.filtersSchema; + } + + /** + * Get event schema + */ + getEventSchema(): z.ZodType { + return this.eventSchema; + } + private async errorHandler(asyncFunc: () => Promise): Promise { try { return await asyncFunc();