From c853bd9ada5154b07ba1c1202a94fe43fb12e898 Mon Sep 17 00:00:00 2001 From: Dan Hsiung Date: Wed, 22 Jan 2020 12:03:39 -0800 Subject: [PATCH 1/3] add emit type info --- lib/index.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/index.ts b/lib/index.ts index 50c553e..f7f413c 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; // } @@ -74,6 +84,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; @@ -83,6 +94,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, From 11e4f898f22a57c505a996d249be0f33ad0bb502 Mon Sep 17 00:00:00 2001 From: Dan Hsiung Date: Fri, 24 Jan 2020 02:03:28 -0800 Subject: [PATCH 2/3] adding dist files for emit type --- __tests__/$send.js | 25 +++++++++++++++++++++++++ dist/index.d.ts | 18 ++++++++++++++++++ dist/index.js | 8 ++++++++ 3 files changed, 51 insertions(+) diff --git a/__tests__/$send.js b/__tests__/$send.js index b1b29e3..c3ff749 100644 --- a/__tests__/$send.js +++ b/__tests__/$send.js @@ -35,6 +35,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 929dbea..49600e8 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 SendConfigHTTP: t.IntersectionC<[t.ExactC; interface SendFunctionsWrapper { email: (config: SendConfigEmail) => void; + emit: (config: SendConfigEmit) => void; http: (config: SendConfigHTTP) => void; s3: (config: SendConfigS3) => void; sql: (config: SendConfigSQL) => void; @@ -63,6 +76,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 Date: Tue, 28 Jan 2020 10:11:59 -0800 Subject: [PATCH 3/3] bump up release version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2a58fc6..0338fcb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@pipedreamhq/platform", - "version": "0.7.0", + "version": "0.7.1", "description": "Pipedream platform globals (typing and runtime type checking)", "homepage": "https://pipedream.com", "main": "dist/index.js",