forked from metarhia/metacom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetacom.d.ts
126 lines (116 loc) Β· 2.99 KB
/
metacom.d.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import { EventEmitter } from 'events';
import { ClientRequest, ServerResponse } from 'http';
import WebSocket from 'ws';
import { Semaphore } from 'metautil';
export interface MetacomError extends Error {
code: string;
}
export class Metacom extends EventEmitter {
url: string;
socket: WebSocket;
api: object;
callId: number;
calls: Map<number, [Function, Function]>;
constructor(url: string);
static create(url: string, options?: unknown): Metacom;
ready(): Promise<void>;
load(...interfaces: Array<string>): Promise<void>;
httpCall(
iname: string,
ver: string
): (methodName: string) => (args: object) => Promise<void>;
socketCall(
iname: string,
ver: string
): (methodName: string) => (args: object) => Promise<void>;
}
export interface ServerConfig {
concurrency: number;
host: string;
balancer: boolean;
protocol: string;
ports: Array<number>;
queue: object;
}
export class Session {
constructor(token: string, channel: Channel, data: any);
}
export interface ErrorOptions {
callId?: number;
error?: Error;
pass?: boolean;
}
export class Client extends EventEmitter {
events: { close: Array<Function> };
callId: number;
ip: string | undefined;
redirect(location: string): void;
startSession(token: string, data: object): boolean;
restoreSession(token: string): boolean;
}
export class Channel {
application: object;
req: ClientRequest;
res: ServerResponse;
ip: string;
client: Client;
session?: Session;
constructor(application: object, req: ClientRequest, res: ServerResponse);
message(data: string): void;
prc(
callId: number,
interfaceName: string,
methodName: string,
args: []
): Promise<void>;
restoreSession(): Promise<Session | null>;
destroy(): void;
error(code: number, errorOptions?: ErrorOptions): void;
}
export class HttpChannel extends Channel {
write(data: any, httpCode?: number, ext?: string): void;
send(obj: object, httpCode?: number): void;
redirect(location: string): void;
options(): void;
hook(
proc: object,
interfaceName: string,
methodName: string,
args: Array<any>
): Promise<void>;
startSession(): Session;
deleteSession(): void;
}
export class WsChannel extends Channel {
connection: WebSocket;
constructor(application: object, req: ClientRequest, connection: WebSocket);
write(data: any): void;
send(obj: object): void;
redirect(location: string): void;
options(): void;
hook(
proc: object,
interfaceName: string,
methodName: string,
args: Array<any>
): Promise<void>;
startSession(): Session;
deleteSession(): void;
}
export class Server {
config: ServerConfig;
application: object;
semaphore: Semaphore;
balancer: boolean;
port: number;
server?: any;
ws?: any;
protocol: string;
host: string;
constructor(config: ServerConfig, application: object);
bind(): void;
listener(req: ClientRequest, res: ServerResponse): void;
request(channel: Channel): void;
closeChannels(): void;
close(): Promise<void>;
}