diff --git a/__tests__/$send.js b/__tests__/$send.js index 4c0df72..85c903b 100644 --- a/__tests__/$send.js +++ b/__tests__/$send.js @@ -40,6 +40,31 @@ describe("$send.email", () => { }) }) +describe("$send.emit", () => { + const checker = $sendConfigRuntimeTypeChecker.emit + let config + beforeEach(() => { + config = { + raw_event: { + key: randString(), + }, + } + }) + + it("should fail with empty config", () => { + expect(() => checker({})).toThrow() + }) + + it("should pass with full config", () => { + expect(() => checker(config)).not.toThrow() + }) + + xit("should fail with .__extra", () => { + config.__extra = randString() + expect(() => checker(config)).toThrow() + }) +}) + describe("$send.http", () => { const checker = $sendConfigRuntimeTypeChecker.http let config diff --git a/dist/index.d.ts b/dist/index.d.ts index 1a2b2d2..3542a07 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -8,6 +8,18 @@ export declare const SendConfigEmail: t.PartialC<{ text: t.StringC; }>; export declare type SendConfigEmail = t.TypeOf; +export declare const SendConfigEmit_required: t.ExactC>; +export declare const SendConfigEmit_optional: t.PartialC<{ + event: t.ObjectC; +}>; +export declare const SendConfigEmit: t.IntersectionC<[t.ExactC>, t.PartialC<{ + event: t.ObjectC; +}>]>; +export declare type SendConfigEmit = t.TypeOf; export declare const HTTP_METHODS: string[]; export declare const SendConfigHTTP: t.IntersectionC<[t.ExactC; @@ -52,6 +64,7 @@ export declare const SendConfigSSE: t.ExactC; interface SendFunctionsWrapper { email: (config: SendConfigEmail) => void; + emit: (config: SendConfigEmit) => void; http: (config: SendConfigHTTP) => void; s3: (config: SendConfigS3) => void; sql: (config: SendConfigSQL) => void; @@ -64,6 +77,11 @@ export declare const sendTypeMap: { subject: t.StringC; text: t.StringC; }>; + emit: t.IntersectionC<[t.ExactC>, t.PartialC<{ + event: t.ObjectC; + }>]>; http: t.IntersectionC<[t.ExactC; url: t.StringC; diff --git a/dist/index.js b/dist/index.js index ae5e5f9..92b4044 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12,6 +12,13 @@ exports.SendConfigEmail = t.partial({ subject: t.string, text: t.string, }); +exports.SendConfigEmit_required = t.strict({ + raw_event: t.object, +}); +exports.SendConfigEmit_optional = t.partial({ + event: t.object, +}); +exports.SendConfigEmit = t.intersection([exports.SendConfigEmit_required, exports.SendConfigEmit_optional]); // interface SendConfigHTTPKv { // [key: string]: string; // } @@ -75,6 +82,7 @@ exports.SendConfigSSE = t.strict({ // XXX would be cool to have this and SendFunctionsWrapper be more shared exports.sendTypeMap = { email: exports.SendConfigEmail, + emit: exports.SendConfigEmit, http: exports.SendConfigHTTP, s3: exports.SendConfigS3, sql: exports.SendConfigSQL, diff --git a/lib/index.ts b/lib/index.ts index b60bb32..9ac613a 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -15,6 +15,16 @@ export const SendConfigEmail = t.partial({ }); export type SendConfigEmail = t.TypeOf; +export const SendConfigEmit_required = t.strict({ + raw_event: t.object, +}); + +export const SendConfigEmit_optional = t.partial({ + event: t.object, +}); +export const SendConfigEmit = t.intersection([SendConfigEmit_required, SendConfigEmit_optional]); +export type SendConfigEmit = t.TypeOf; + // interface SendConfigHTTPKv { // [key: string]: string; // } @@ -92,6 +102,7 @@ export type SendConfigSSE = t.TypeOf; // optionals so we can use self-invoking function below interface SendFunctionsWrapper { email: (config: SendConfigEmail) => void; + emit: (config: SendConfigEmit) => void; http: (config: SendConfigHTTP) => void; s3: (config: SendConfigS3) => void; sql: (config: SendConfigSQL) => void; @@ -101,6 +112,7 @@ interface SendFunctionsWrapper { // XXX would be cool to have this and SendFunctionsWrapper be more shared export const sendTypeMap = { email: SendConfigEmail, + emit: SendConfigEmit, http: SendConfigHTTP, s3: SendConfigS3, sql: SendConfigSQL,