-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.ts
42 lines (35 loc) · 1.03 KB
/
common.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { JTDSchemaType } from "ajv/dist/jtd";
import { Context } from "@loke/context";
export const requestContexts = new WeakMap<object, Context>();
export type Method<A = any, R = any> = (args: A) => R;
export type ContextMethod<A = any, R = any> = (ctx: Context, args: A) => R;
export interface MethodDetails {
methodName: string;
methodTimeout?: number;
help?: string;
paramNames?: string[];
requestTypeDef?: JTDSchemaType<any, any>;
responseTypeDef?: JTDSchemaType<any, any>;
}
export interface ServiceDetails<
S, // eslint-disable-line @typescript-eslint/no-unused-vars
Def extends Record<string, unknown> = Record<string, never>,
> {
expose: MethodDetails[];
service: string;
help?: string;
path?: string;
definitions?: {
[K in keyof Def]: JTDSchemaType<Def[K], Def>;
};
}
export interface Service {
[methodName: string]: Method;
}
export interface ContextService {
[methodName: string]: ContextMethod;
}
export interface ServiceSet<S extends Service> {
implementation: S;
meta: ServiceDetails<S, any>;
}