Skip to content
This repository was archived by the owner on Oct 7, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions __tests__/$send.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ export declare const SendConfigEmail: t.PartialC<{
text: t.StringC;
}>;
export declare type SendConfigEmail = t.TypeOf<typeof SendConfigEmail>;
export declare const SendConfigEmit_required: t.ExactC<t.TypeC<{
raw_event: t.ObjectC;
}>>;
export declare const SendConfigEmit_optional: t.PartialC<{
event: t.ObjectC;
}>;
export declare const SendConfigEmit: t.IntersectionC<[t.ExactC<t.TypeC<{
raw_event: t.ObjectC;
}>>, t.PartialC<{
event: t.ObjectC;
}>]>;
export declare type SendConfigEmit = t.TypeOf<typeof SendConfigEmit>;
export declare const HTTP_METHODS: string[];
export declare const SendConfigHTTP: t.IntersectionC<[t.ExactC<t.TypeC<{
method: t.KeyofC<{}>;
Expand Down Expand Up @@ -52,6 +64,7 @@ export declare const SendConfigSSE: t.ExactC<t.TypeC<{
export declare type SendConfigSSE = t.TypeOf<typeof SendConfigSSE>;
interface SendFunctionsWrapper {
email: (config: SendConfigEmail) => void;
emit: (config: SendConfigEmit) => void;
http: (config: SendConfigHTTP) => void;
s3: (config: SendConfigS3) => void;
sql: (config: SendConfigSQL) => void;
Expand All @@ -64,6 +77,11 @@ export declare const sendTypeMap: {
subject: t.StringC;
text: t.StringC;
}>;
emit: t.IntersectionC<[t.ExactC<t.TypeC<{
raw_event: t.ObjectC;
}>>, t.PartialC<{
event: t.ObjectC;
}>]>;
http: t.IntersectionC<[t.ExactC<t.TypeC<{
method: t.KeyofC<{}>;
url: t.StringC;
Expand Down
8 changes: 8 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
// }
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ export const SendConfigEmail = t.partial({
});
export type SendConfigEmail = t.TypeOf<typeof SendConfigEmail>;

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<typeof SendConfigEmit>;

// interface SendConfigHTTPKv {
// [key: string]: string;
// }
Expand Down Expand Up @@ -92,6 +102,7 @@ export type SendConfigSSE = t.TypeOf<typeof SendConfigSSE>;
// 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;
Expand All @@ -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,
Expand Down