This repository was archived by the owner on Oct 7, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +47
-6
lines changed Expand file tree Collapse file tree 4 files changed +47
-6
lines changed Original file line number Diff line number Diff line change 11// purposefully test COMPILED platform.js! (just as lambda_maker would)
2- const { $sendConfigRuntimeTypeChecker } = require ( "../dist" )
2+ const { $sendConfigRuntimeTypeChecker, HTTP_METHODS } = require ( "../dist" )
33
44function 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+
813const 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 ( ) ,
Original file line number Diff line number Diff line change @@ -8,8 +8,9 @@ export declare const SendConfigEmail: t.PartialC<{
88 text : t . StringC ;
99} > ;
1010export declare type SendConfigEmail = t . TypeOf < typeof SendConfigEmail > ;
11+ export declare const HTTP_METHODS : string [ ] ;
1112export 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 < {
Original file line number Diff line number Diff 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+ } , { } ) ) ;
2340const SendConfigHTTP_required = t . strict ( {
24- method : t . string ,
41+ method : SendConfigHTTPMethod ,
2542 url : t . string ,
2643} ) ;
2744const SendConfigHTTP_optional = t . partial ( {
Original file line number Diff line number Diff line change @@ -25,8 +25,26 @@ const SendConfigHTTPAuth = t.strict({
2525 username : t . string ,
2626} ) ;
2727type 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 > ;
2846const SendConfigHTTP_required = t . strict ( {
29- method : t . string , // XXX proper enum for methods here?
47+ method : SendConfigHTTPMethod ,
3048 url : t . string ,
3149} )
3250const SendConfigHTTP_optional = t . partial ( {
You can’t perform that action at this time.
0 commit comments