mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) move home server into core
Summary: This moves enough server material into core to run a home server. The data engine is not yet incorporated (though in manual testing it works when ported). Test Plan: existing tests pass Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D2552
This commit is contained in:
25
app/common/tpromisified.ts
Normal file
25
app/common/tpromisified.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
// tslint:disable:max-line-length
|
||||
// credits: https://stackoverflow.com/questions/49998665/promisified-function-type
|
||||
|
||||
// Generic Function definition
|
||||
type AnyFunction = (...args: any[]) => any;
|
||||
|
||||
// Extracts the type if wrapped by a Promise
|
||||
type Unpacked<T> = T extends Promise<infer U> ? U : T;
|
||||
|
||||
type PromisifiedFunction<T extends AnyFunction> =
|
||||
T extends () => infer U ? () => Promise<Unpacked<U>> :
|
||||
T extends (a1: infer A1) => infer U ? (a1: A1) => Promise<Unpacked<U>> :
|
||||
T extends (a1: infer A1, a2: infer A2) => infer U ? (a1: A1, a2: A2) => Promise<Unpacked<U>> :
|
||||
T extends (a1: infer A1, a2: infer A2, a3: infer A3) => infer U ? (a1: A1, a2: A2, a3: A3) => Promise<Unpacked<U>> :
|
||||
T extends (a1: infer A1, a2: infer A2, a3: infer A3, a4: infer A4) => infer U ? (a1: A1, a2: A2, a3: A3, a4: A4) => Promise<Unpacked<U>> :
|
||||
// ...
|
||||
T extends (...args: any[]) => infer U ? (...args: any[]) => Promise<Unpacked<U>> : T;
|
||||
|
||||
/**
|
||||
* `Promisified<T>` has the same methods as `T` but they all return promises. This is useful when
|
||||
* creating a stub with `grain-rpc` for an api which is synchronous.
|
||||
*/
|
||||
export type Promisified<T> = {
|
||||
[K in keyof T]: T[K] extends AnyFunction ? PromisifiedFunction<T[K]> : never
|
||||
};
|
||||
Reference in New Issue
Block a user