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

Commit 8ec4989

Browse files
committed
SendConfigHTTPMethod uppercase string union
1 parent 453596f commit 8ec4989

File tree

4 files changed

+47
-6
lines changed

4 files changed

+47
-6
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...
@@ -40,7 +45,7 @@ describe("$send.http", () => {
4045
let config
4146
beforeEach(() => {
4247
config = {
43-
method: randString(),
48+
method: randHttpMethod(),
4449
url: randString(),
4550
auth: {
4651
password: randString(),

dist/index.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ export declare const SendConfigEmail: t.PartialC<{
88
text: t.StringC;
99
}>;
1010
export declare type SendConfigEmail = t.TypeOf<typeof SendConfigEmail>;
11+
export declare const HTTP_METHODS: string[];
1112
export declare const SendConfigHTTP: t.IntersectionC<[t.ExactC<t.TypeC<{
12-
method: t.StringC;
13+
method: t.KeyofC<{}>;
1314
url: t.StringC;
1415
}>>, t.PartialC<{
1516
auth: t.ExactC<t.TypeC<{
@@ -64,7 +65,7 @@ export declare const sendTypeMap: {
6465
text: t.StringC;
6566
}>;
6667
http: t.IntersectionC<[t.ExactC<t.TypeC<{
67-
method: t.StringC;
68+
method: t.KeyofC<{}>;
6869
url: t.StringC;
6970
}>>, t.PartialC<{
7071
auth: t.ExactC<t.TypeC<{

dist/index.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,25 @@ const SendConfigHTTPAuth = t.strict({
2020
password: t.string,
2121
username: t.string,
2222
});
23+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
24+
exports.HTTP_METHODS = [
25+
"GET",
26+
"HEAD",
27+
"POST",
28+
"PUT",
29+
"DELETE",
30+
"CONNECT",
31+
"OPTIONS",
32+
"TRACE",
33+
"PATCH",
34+
];
35+
// HTTP method must be uppercase (for kotlin in coordinator -- i voted to make it case insensitive, but w.e for now)
36+
const SendConfigHTTPMethod = t.keyof(exports.HTTP_METHODS.reduce((acc, v) => {
37+
acc[v] = null;
38+
return acc;
39+
}, {}));
2340
const SendConfigHTTP_required = t.strict({
24-
method: t.string,
41+
method: SendConfigHTTPMethod,
2542
url: t.string,
2643
});
2744
const SendConfigHTTP_optional = t.partial({

lib/index.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,26 @@ const SendConfigHTTPAuth = t.strict({
2525
username: t.string,
2626
});
2727
type SendConfigHTTPAuth = t.TypeOf<typeof SendConfigHTTPAuth>;
28+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
29+
export const HTTP_METHODS = [
30+
"GET",
31+
"HEAD",
32+
"POST",
33+
"PUT",
34+
"DELETE",
35+
"CONNECT",
36+
"OPTIONS",
37+
"TRACE",
38+
"PATCH",
39+
]
40+
// HTTP method must be uppercase (for kotlin in coordinator -- i voted to make it case insensitive, but w.e for now)
41+
const SendConfigHTTPMethod = t.keyof(HTTP_METHODS.reduce((acc, v) => {
42+
acc[v] = null
43+
return acc
44+
}, {}))
45+
type SendConfigHTTPMethod = t.TypeOf<typeof SendConfigHTTPMethod>;
2846
const SendConfigHTTP_required = t.strict({
29-
method: t.string, // XXX proper enum for methods here?
47+
method: SendConfigHTTPMethod,
3048
url: t.string,
3149
})
3250
const SendConfigHTTP_optional = t.partial({

0 commit comments

Comments
 (0)