From d668eac4a63a9aa98c3efff395faa23cfcea1c1b Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 21 Mar 2024 17:08:37 +0100 Subject: [node] begin the great typescript rewrite --- nodejs/model/api.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 nodejs/model/api.ts (limited to 'nodejs/model/api.ts') diff --git a/nodejs/model/api.ts b/nodejs/model/api.ts new file mode 100644 index 0000000..5092157 --- /dev/null +++ b/nodejs/model/api.ts @@ -0,0 +1,32 @@ +export type APIError = { + apiError: 'APIError'; + error: string; + code: number; + data: any; // TODO +}; + +export type Meta = { + limit: number; + page: number; + total: number; +} + +export type Request = { + endpoint: string; // the path part of the url to call + method?: string; // HTTP method for `fetch` call, defaults to 'GET' + page?: number; // run a paginated request starting from this page until all the following pages are fetched + payload?: { [key:string]: any}; // optional json object that will be sent along the request + priority?: number; // optional priority value, defaults to 10. lower than 10 means the message will be sent faster +}; + +export type RequestPromise = { + reject: (reason?: any) => void; + request: Request; + resolve: (value: Response | PromiseLike>) => void; +}; + +export type Response = { + data: T; + error?: APIError; + meta?: Meta; +} -- cgit v1.2.3