import type { ServicesRecord } from "../services/ServicesRecord.js"; import type { ServiceInterface } from "../services/ServiceInterface.js"; import type { ApiResponse } from "./ApiResponse.js"; import type { GravityStream } from "../types/GravityStream.js"; /** * ⛔️ Because Typescript does not support type injection (ie passing a generic as a generic paremeter), * we can't be DRY and this code has to be repeated for every Api.ts + ApiStoreProxy.ts file. * If you have to modify Api.ts or any ApiStoreProxy.ts of the compatible front-end frameworks, * please make sure to modify all other Api.ts and ApiStoreProxy.ts files. */ /** * Transforms a type into a callable type: * - the return of functions are promisified * - values are transformed into functions with no argument that return a promise of the value * with nested capabilities */ type Callable = Type extends (...args: infer Parameters) => infer ReturnType ? ReturnType extends GravityStream | Promise> ? (...args: Parameters) => Promise>> : (...args: Parameters) => Promise> : Type extends any[] ? Array<() => Promise>> & (() => Promise>) : Type extends Set | Map | RegExp | String | Number | BigInt | Boolean | Date | ArrayBuffer ? () => Promise> : Type extends object ? { [Key in keyof Type]: Callable; } : () => Promise>; type ExposedProperties> = { [Key in Exclude]: Callable; }; export type Api> = { [Key in keyof Services]: ExposedProperties>; }; /** * BEACON API */ type SendableBeacon = Type extends (...args: infer Parameters) => any ? (...args: Parameters) => boolean : Type extends any[] ? Array<() => boolean> & (() => boolean) : Type extends Set | Map | RegExp | String | Number | BigInt | Boolean | Date | ArrayBuffer ? () => boolean : Type extends object ? { [Key in keyof Type]: SendableBeacon; } : () => boolean; type ExposedBeaconProperties> = { [Key in Exclude]: SendableBeacon; }; export type BeaconApi> = { [Key in keyof Services]: ExposedBeaconProperties>; }; export {};