Skip to content

Commit

Permalink
Add type for valid fetch methods (#857)
Browse files Browse the repository at this point in the history
* Add type for valid fetch methods

* Address feedback
  • Loading branch information
chris-codaio authored Mar 15, 2021
1 parent 3e9d4dc commit 95b0e71
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 4 deletions.
10 changes: 9 additions & 1 deletion api_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,18 @@ export interface Network {
}

// Fetcher APIs
const ValidFetchMethods = [
'GET',
'PATCH',
'POST',
'PUT',
'DELETE',
] as const;
export type FetchMethodType = typeof ValidFetchMethods[number];

// Copied from https://developer.mozilla.org/en-US/docs/Web/API/Request
export interface FetchRequest {
method: 'GET' | 'PATCH' | 'POST' | 'PUT' | 'DELETE';
method: FetchMethodType;
url: string;
body?: string;
form?: {[key: string]: string};
Expand Down
4 changes: 3 additions & 1 deletion dist/api_types.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions dist/api_types.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion dist/handler_templates.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion handler_templates.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type {FetchMethodType} from './api_types';
import type {FetchRequest} from './api_types';
import type {FetchResponse} from './api_types';
import type {ObjectSchemaProperty} from './schema';
Expand All @@ -17,7 +18,7 @@ type ParamMapper<T> = (val: T) => T;

export interface RequestHandlerTemplate {
url: string;
method: 'GET' | 'PATCH' | 'POST' | 'PUT' | 'DELETE';
method: FetchMethodType;
headers?: {[header: string]: string};
nameMapping?: {[functionParamName: string]: string};
transforms?: {[name: string]: ParamMapper<any>};
Expand Down
1 change: 1 addition & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export type {DynamicSyncTableDef} from './api';
export type {EmptyFormulaDef} from './api';
export type {ExecutionContext} from './api_types';
export type {Fetcher} from './api_types';
export type {FetchMethodType} from './api_types';
export type {FetchRequest} from './api_types';
export type {FetchResponse} from './api_types';
export type {GenericDynamicSyncTable} from './api';
Expand Down

0 comments on commit 95b0e71

Please sign in to comment.