Skip to content
This repository was archived by the owner on Oct 7, 2022. It is now read-only.

Commit b173033

Browse files
committed
Merge branch 'master' into emit
2 parents fe5417a + 3e43cab commit b173033

File tree

5 files changed

+48
-7
lines changed

5 files changed

+48
-7
lines changed

__tests__/$send.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
// purposefully test COMPILED platform.js! (just as lambda_maker would)
2-
const { $sendConfigRuntimeTypeChecker } = require("../dist")
2+
const { $sendConfigRuntimeTypeChecker, HTTP_METHODS } = require("../dist")
33

44
function randString() {
55
return ""+Math.random()
66
}
77

8+
function randHttpMethod() {
9+
const idx = Math.floor(Math.random() * HTTP_METHODS.length)
10+
return HTTP_METHODS[idx]
11+
}
12+
813
const emptyConfig = {}
914

1015
// XXX would be nice to generate a lot of these tests automatically...
@@ -65,7 +70,7 @@ describe("$send.http", () => {
6570
let config
6671
beforeEach(() => {
6772
config = {
68-
method: randString(),
73+
method: randHttpMethod(),
6974
url: randString(),
7075
auth: {
7176
password: randString(),

dist/index.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ export declare const SendConfigEmit: t.IntersectionC<[t.ExactC<t.TypeC<{
2020
event: t.ObjectC;
2121
}>]>;
2222
export declare type SendConfigEmit = t.TypeOf<typeof SendConfigEmit>;
23+
export declare const HTTP_METHODS: string[];
2324
export declare const SendConfigHTTP: t.IntersectionC<[t.ExactC<t.TypeC<{
24-
method: t.StringC;
25+
method: t.KeyofC<{}>;
2526
url: t.StringC;
2627
}>>, t.PartialC<{
2728
auth: t.ExactC<t.TypeC<{
@@ -82,7 +83,7 @@ export declare const sendTypeMap: {
8283
event: t.ObjectC;
8384
}>]>;
8485
http: t.IntersectionC<[t.ExactC<t.TypeC<{
85-
method: t.StringC;
86+
method: t.KeyofC<{}>;
8687
url: t.StringC;
8788
}>>, t.PartialC<{
8889
auth: t.ExactC<t.TypeC<{

dist/index.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,25 @@ const SendConfigHTTPAuth = t.strict({
2727
password: t.string,
2828
username: t.string,
2929
});
30+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
31+
exports.HTTP_METHODS = [
32+
"GET",
33+
"HEAD",
34+
"POST",
35+
"PUT",
36+
"DELETE",
37+
"CONNECT",
38+
"OPTIONS",
39+
"TRACE",
40+
"PATCH",
41+
];
42+
// HTTP method must be uppercase (for kotlin in coordinator -- i voted to make it case insensitive, but w.e for now)
43+
const SendConfigHTTPMethod = t.keyof(exports.HTTP_METHODS.reduce((acc, v) => {
44+
acc[v] = null;
45+
return acc;
46+
}, {}));
3047
const SendConfigHTTP_required = t.strict({
31-
method: t.string,
48+
method: SendConfigHTTPMethod,
3249
url: t.string,
3350
});
3451
const SendConfigHTTP_optional = t.partial({

lib/index.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,26 @@ const SendConfigHTTPAuth = t.strict({
3535
username: t.string,
3636
});
3737
type SendConfigHTTPAuth = t.TypeOf<typeof SendConfigHTTPAuth>;
38+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
39+
export const HTTP_METHODS = [
40+
"GET",
41+
"HEAD",
42+
"POST",
43+
"PUT",
44+
"DELETE",
45+
"CONNECT",
46+
"OPTIONS",
47+
"TRACE",
48+
"PATCH",
49+
]
50+
// HTTP method must be uppercase (for kotlin in coordinator -- i voted to make it case insensitive, but w.e for now)
51+
const SendConfigHTTPMethod = t.keyof(HTTP_METHODS.reduce((acc, v) => {
52+
acc[v] = null
53+
return acc
54+
}, {}))
55+
type SendConfigHTTPMethod = t.TypeOf<typeof SendConfigHTTPMethod>;
3856
const SendConfigHTTP_required = t.strict({
39-
method: t.string, // XXX proper enum for methods here?
57+
method: SendConfigHTTPMethod,
4058
url: t.string,
4159
})
4260
const SendConfigHTTP_optional = t.partial({

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)