@izumi-framework/izumi-runtime-typescript-es 0.0.1-build.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/dispatcher.d.ts +12 -0
  2. package/dispatcher.js +27 -0
  3. package/dispatcher.js.map +1 -0
  4. package/either.d.ts +31 -0
  5. package/either.js +78 -0
  6. package/either.js.map +1 -0
  7. package/formatter.d.ts +14 -0
  8. package/formatter.js +64 -0
  9. package/formatter.js.map +1 -0
  10. package/index.d.ts +9 -0
  11. package/index.js +10 -0
  12. package/index.js.map +1 -0
  13. package/introspector.d.ts +82 -0
  14. package/introspector.js +82 -0
  15. package/introspector.js.map +1 -0
  16. package/logger/index.d.ts +3 -0
  17. package/logger/index.js +4 -0
  18. package/logger/index.js.map +1 -0
  19. package/logger/logger.console.d.ts +7 -0
  20. package/logger/logger.console.js +44 -0
  21. package/logger/logger.console.js.map +1 -0
  22. package/logger/logger.d.ts +10 -0
  23. package/logger/logger.dummy.d.ts +4 -0
  24. package/logger/logger.dummy.js +5 -0
  25. package/logger/logger.dummy.js.map +1 -0
  26. package/logger/logger.js +9 -0
  27. package/logger/logger.js.map +1 -0
  28. package/marshaller.d.ts +12 -0
  29. package/marshaller.js +28 -0
  30. package/marshaller.js.map +1 -0
  31. package/package.json +15 -0
  32. package/transport/auth/auth.apikey.d.ts +7 -0
  33. package/transport/auth/auth.apikey.js +22 -0
  34. package/transport/auth/auth.apikey.js.map +1 -0
  35. package/transport/auth/auth.basic.d.ts +9 -0
  36. package/transport/auth/auth.basic.js +24 -0
  37. package/transport/auth/auth.basic.js.map +1 -0
  38. package/transport/auth/auth.custom.d.ts +7 -0
  39. package/transport/auth/auth.custom.js +15 -0
  40. package/transport/auth/auth.custom.js.map +1 -0
  41. package/transport/auth/auth.d.ts +7 -0
  42. package/transport/auth/auth.js +43 -0
  43. package/transport/auth/auth.js.map +1 -0
  44. package/transport/auth/auth.method.d.ts +4 -0
  45. package/transport/auth/auth.method.js +3 -0
  46. package/transport/auth/auth.method.js.map +1 -0
  47. package/transport/auth/auth.token.d.ts +7 -0
  48. package/transport/auth/auth.token.js +18 -0
  49. package/transport/auth/auth.token.js.map +1 -0
  50. package/transport/auth/index.d.ts +6 -0
  51. package/transport/auth/index.js +7 -0
  52. package/transport/auth/index.js.map +1 -0
  53. package/transport/client/index.d.ts +3 -0
  54. package/transport/client/index.js +4 -0
  55. package/transport/client/index.js.map +1 -0
  56. package/transport/client/transport.http.client.d.ts +26 -0
  57. package/transport/client/transport.http.client.js +125 -0
  58. package/transport/client/transport.http.client.js.map +1 -0
  59. package/transport/client/transport.hybrid.client.d.ts +36 -0
  60. package/transport/client/transport.hybrid.client.js +73 -0
  61. package/transport/client/transport.hybrid.client.js.map +1 -0
  62. package/transport/client/transport.websocket.client.d.ts +45 -0
  63. package/transport/client/transport.websocket.client.js +229 -0
  64. package/transport/client/transport.websocket.client.js.map +1 -0
  65. package/transport/index.d.ts +6 -0
  66. package/transport/index.js +7 -0
  67. package/transport/index.js.map +1 -0
  68. package/transport/server/index.d.ts +5 -0
  69. package/transport/server/index.js +6 -0
  70. package/transport/server/index.js.map +1 -0
  71. package/transport/server/transport.context.d.ts +6 -0
  72. package/transport/server/transport.context.js +8 -0
  73. package/transport/server/transport.context.js.map +1 -0
  74. package/transport/server/transport.context.system.d.ts +5 -0
  75. package/transport/server/transport.context.system.js +7 -0
  76. package/transport/server/transport.context.system.js.map +1 -0
  77. package/transport/server/transport.server.d.ts +8 -0
  78. package/transport/server/transport.server.http.d.ts +21 -0
  79. package/transport/server/transport.server.http.js +131 -0
  80. package/transport/server/transport.server.http.js.map +1 -0
  81. package/transport/server/transport.server.js +2 -0
  82. package/transport/server/transport.server.js.map +1 -0
  83. package/transport/server/transport.server.websocket.d.ts +13 -0
  84. package/transport/server/transport.server.websocket.js +51 -0
  85. package/transport/server/transport.server.websocket.js.map +1 -0
  86. package/transport/transport.d.ts +25 -0
  87. package/transport/transport.js +2 -0
  88. package/transport/transport.js.map +1 -0
  89. package/transport/transport.websocket.d.ts +31 -0
  90. package/transport/transport.websocket.js +13 -0
  91. package/transport/transport.websocket.js.map +1 -0
  92. package/transport/wsclient.d.ts +37 -0
  93. package/transport/wsclient.js +119 -0
  94. package/transport/wsclient.js.map +1 -0
  95. package/void.d.ts +3 -0
  96. package/void.js +4 -0
  97. package/void.js.map +1 -0
@@ -0,0 +1,229 @@
1
+ import { WSClient, WSClientState } from '../wsclient';
2
+ import { LogLevel } from '../../logger';
3
+ import { Authorization } from '../auth';
4
+ import { WebSocketMessageKind } from '../transport.websocket';
5
+ import { Dispatcher } from '../../dispatcher';
6
+ export function RandomMessageID(prefix = '') {
7
+ return prefix + 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
8
+ const r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
9
+ return v.toString(16);
10
+ });
11
+ }
12
+ const headersUpdatedPrefix = 'headersupdate-';
13
+ export class WebSocketClientTransport {
14
+ constructor(endpoint, marshaller, logger, protocols = []) {
15
+ this._supported = !!window['WebSocket'];
16
+ if (!this._supported) {
17
+ return;
18
+ }
19
+ this._logger = logger;
20
+ this._marshaller = marshaller;
21
+ this._wsc = new WSClient();
22
+ this._wsc.open(endpoint, protocols);
23
+ this.onOpen = this.onOpen.bind(this);
24
+ this.onMessage = this.onMessage.bind(this);
25
+ this.onClose = this.onClose.bind(this);
26
+ this.onConnecting = this.onConnecting.bind(this);
27
+ this._requests = {};
28
+ this._wsc.onDisconnect = this.onClose;
29
+ this._wsc.onMessage = this.onMessage;
30
+ this._wsc.onConnect = this.onOpen;
31
+ this._wsc.onConnecting = this.onConnecting;
32
+ this._headersUpdated = true;
33
+ this._dispatcher = new Dispatcher();
34
+ }
35
+ isReady(checkHeaders = true) {
36
+ if (!this._supported) {
37
+ return false;
38
+ }
39
+ if (checkHeaders && !this._headersUpdated) {
40
+ return false;
41
+ }
42
+ return this._wsc.state === WSClientState.Connected;
43
+ }
44
+ send(service, method, data) {
45
+ const request = {
46
+ service,
47
+ method,
48
+ kind: WebSocketMessageKind.RpcRequest,
49
+ id: RandomMessageID(),
50
+ data: data.serialize()
51
+ };
52
+ this._logger.logf(LogLevel.Trace, '====================================================\nOutgoing message:\n', request);
53
+ const serialized = this._marshaller.Marshal(request);
54
+ const onFailure = this.onFailure;
55
+ const record = {
56
+ service,
57
+ method,
58
+ timeout: window.setTimeout(() => {
59
+ const error = 'timed out request to ' + service + '/' + method;
60
+ if (onFailure) {
61
+ onFailure(service, method, error);
62
+ }
63
+ record.reject(new Error(error));
64
+ delete this._requests[request.id];
65
+ }, 60000)
66
+ };
67
+ record.promise = new Promise((resolve, reject) => {
68
+ record.reject = reject;
69
+ record.resolve = resolve;
70
+ });
71
+ this._requests[request.id] = record;
72
+ this._wsc.send(serialized);
73
+ if (this.onSend) {
74
+ this.onSend(service, method, serialized);
75
+ }
76
+ return record.promise;
77
+ }
78
+ checkHeaders() {
79
+ if (!this.isReady(false)) {
80
+ return;
81
+ }
82
+ if (this._auth) {
83
+ this.sendHeaders();
84
+ return;
85
+ }
86
+ this._headersUpdated = true;
87
+ }
88
+ sendHeaders() {
89
+ this._headersUpdateID = RandomMessageID(headersUpdatedPrefix);
90
+ const headers = {
91
+ ...this._headers
92
+ };
93
+ if (this._auth) {
94
+ headers['Authorization'] = this._auth.toValue();
95
+ }
96
+ const msg = {
97
+ headers,
98
+ kind: WebSocketMessageKind.RpcRequest,
99
+ id: this._headersUpdateID,
100
+ };
101
+ const serialized = this._marshaller.Marshal(msg);
102
+ this._logger.logf(LogLevel.Trace, '====================================================\Updating headers...\n', JSON.stringify(msg, null, ' '));
103
+ this._wsc.send(serialized);
104
+ }
105
+ getHeaders() {
106
+ return this._headers;
107
+ }
108
+ setHeaders(headers) {
109
+ this._headers = headers || {};
110
+ }
111
+ getAuthorization() {
112
+ return this._auth ? this._auth.method : undefined;
113
+ }
114
+ setAuthorization(method) {
115
+ if (!method) {
116
+ this._auth = undefined;
117
+ }
118
+ this._auth = new Authorization();
119
+ this._auth.method = method;
120
+ this.checkHeaders();
121
+ }
122
+ onConnecting() {
123
+ this._headersUpdated = false;
124
+ }
125
+ onClose() {
126
+ this._headersUpdated = false;
127
+ }
128
+ onHeadersUpdated(res) {
129
+ if (res.ref === this._headersUpdateID) {
130
+ if (res.kind === WebSocketMessageKind.RpcFailure) {
131
+ this._logger.logf(LogLevel.Error, `Headers update failed. Ref: ${res.ref}`, res.data);
132
+ }
133
+ this._headersUpdated = true;
134
+ return true;
135
+ }
136
+ return false;
137
+ }
138
+ onRpcResponseMessage(res) {
139
+ if (!(res.ref in this._requests)) {
140
+ if (!this.onHeadersUpdated(res)) {
141
+ if (res.ref.indexOf(headersUpdatedPrefix) === 0) {
142
+ this._logger.logf(LogLevel.Debug, 'Outdated headers update ID came back: ' + res.ref, res);
143
+ }
144
+ else {
145
+ this._logger.logf(LogLevel.Warning, 'Unknown reference ID came back: ' + res.ref, res);
146
+ }
147
+ }
148
+ return;
149
+ }
150
+ const record = this._requests[res.ref];
151
+ delete this._requests[res.ref];
152
+ clearTimeout(record.timeout);
153
+ if (res.kind === WebSocketMessageKind.RpcFailure) {
154
+ if (this.onFailure) {
155
+ this.onFailure(record.service, record.method, res.data);
156
+ }
157
+ record.reject(res.data);
158
+ }
159
+ else {
160
+ if (this.onSuccess) {
161
+ this.onSuccess(record.service, record.method, res.data);
162
+ }
163
+ record.resolve(res.data);
164
+ }
165
+ }
166
+ onFailureMessage(res) {
167
+ this._logger.logf(LogLevel.Error, `Server was unable to process a request. Error: ${res.cause}`, res.data);
168
+ }
169
+ onBuzzerRequestMessage(req) {
170
+ this._logger.logf(LogLevel.Debug, 'Incoming buzzer call:', req);
171
+ const res = {
172
+ kind: WebSocketMessageKind.BuzzerResponse,
173
+ ref: req.id,
174
+ data: undefined,
175
+ };
176
+ this._dispatcher.dispatch(this._context, req.service, req.method, req.data)
177
+ .then((data) => {
178
+ res.data = data;
179
+ this._wsc.send(JSON.stringify(res));
180
+ })
181
+ .catch((err) => {
182
+ res.kind = WebSocketMessageKind.BuzzerFailure;
183
+ res.data = err;
184
+ this._wsc.send(JSON.stringify(res));
185
+ });
186
+ }
187
+ onStreamS2CMessage(res) {
188
+ this._logger.logf(LogLevel.Warning, 'Incoming S2C stream, not supported!', res);
189
+ }
190
+ onMessage(data) {
191
+ const deserialized = this._marshaller.Unmarshal(data);
192
+ this._logger.logf(LogLevel.Trace, '====================================================\nIncoming message:\n', data);
193
+ switch (deserialized.kind) {
194
+ case WebSocketMessageKind.RpcResponse:
195
+ this.onRpcResponseMessage(deserialized);
196
+ break;
197
+ case WebSocketMessageKind.RpcFailure:
198
+ this.onRpcResponseMessage(deserialized);
199
+ break;
200
+ case WebSocketMessageKind.BuzzerRequest:
201
+ this.onBuzzerRequestMessage(deserialized);
202
+ break;
203
+ case WebSocketMessageKind.Failure:
204
+ this.onFailureMessage(deserialized);
205
+ break;
206
+ case WebSocketMessageKind.StreamS2C:
207
+ this.onStreamS2CMessage(deserialized);
208
+ break;
209
+ default:
210
+ this._logger.logf(LogLevel.Error, 'Invalid message received, kind is unknown or not supported.', data);
211
+ }
212
+ }
213
+ onOpen() {
214
+ this.checkHeaders();
215
+ }
216
+ registerBuzzer(buzzer) {
217
+ return this._dispatcher.register(buzzer);
218
+ }
219
+ unregisterBuzzer(id) {
220
+ return this._dispatcher.unregister(id);
221
+ }
222
+ setContext(context) {
223
+ this._context = context;
224
+ }
225
+ getContext() {
226
+ return this._context;
227
+ }
228
+ }
229
+ //# sourceMappingURL=transport.websocket.client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.websocket.client.js","sourceRoot":"","sources":["../../../irt/transport/client/transport.websocket.client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EAAU,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,EAA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AM;YACV;gBACI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,6DAA6D,EAAE,IAAI,CAAC,CAAC;SAC9G;IACL,CAAC;IAEO,MAAM;QACV,IAAI,CAAC,YAAY,EAAE,CAAC;IACxB,CAAC;IAEM,cAAc,CAAC,MAAoC;QACtD,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC7C,CAAC;IAEM,gBAAgB,CAAC,EAAU;QAC9B,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAC3C,CAAC;IAEM,UAAU,CAAC,OAAU;QACxB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC5B,CAAC;IAEM,UAAU;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;CACJ"}
@@ -0,0 +1,6 @@
1
+ export * from './client';
2
+ export * from './server';
3
+ export * from './transport.websocket';
4
+ export * from './wsclient';
5
+ export * from './transport';
6
+ export * from './auth';
@@ -0,0 +1,7 @@
1
+ export * from './client';
2
+ export * from './server';
3
+ export * from './transport.websocket';
4
+ export * from './wsclient';
5
+ export * from './transport';
6
+ export * from './auth';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../irt/transport/index.ts"],"names":[],"mappings":"AACA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './transport.context';
2
+ export * from './transport.context.system';
3
+ export * from './transport.server.http';
4
+ export * from './transport.server.websocket';
5
+ export * from './transport.server';
@@ -0,0 +1,6 @@
1
+ export * from './transport.context';
2
+ export * from './transport.context.system';
3
+ export * from './transport.server.http';
4
+ export * from './transport.server.websocket';
5
+ export * from './transport.server';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../irt/transport/server/index.ts"],"names":[],"mappings":"AACA,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { SystemContext } from './transport.context.system';
2
+ export declare class ConnectionContext<C> {
3
+ system: SystemContext;
4
+ user: C;
5
+ constructor(user?: C);
6
+ }
@@ -0,0 +1,8 @@
1
+ import { SystemContext } from './transport.context.system';
2
+ export class ConnectionContext {
3
+ constructor(user = undefined) {
4
+ this.system = new SystemContext();
5
+ this.user = user;
6
+ }
7
+ }
8
+ //# sourceMappingURL=transport.context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.context.js","sourceRoot":"","sources":["../../../irt/transport/server/transport.context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,MAAM,OAAO,iBAAiB;IAI1B,YAAY,OAAU,SAAS;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,aAAa,EAAE,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ"}
@@ -0,0 +1,5 @@
1
+ import { Authorization } from '../auth';
2
+ export declare class SystemContext {
3
+ auth: Authorization;
4
+ constructor();
5
+ }
@@ -0,0 +1,7 @@
1
+ import { Authorization } from '../auth';
2
+ export class SystemContext {
3
+ constructor() {
4
+ this.auth = new Authorization();
5
+ }
6
+ }
7
+ //# sourceMappingURL=transport.context.system.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.context.system.js","sourceRoot":"","sources":["../../../irt/transport/server/transport.context.system.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,MAAM,OAAO,aAAa;IAGtB;QACI,IAAI,CAAC,IAAI,GAAG,IAAI,aAAa,EAAE,CAAC;IACpC,CAAC;CACJ"}
@@ -0,0 +1,8 @@
1
+ /// <reference types="node" />
2
+ import * as http from 'http';
3
+ import { ConnectionContext } from './transport.context';
4
+ export interface TransportHandlers<C> {
5
+ onConnect(context: ConnectionContext<C>, request: http.IncomingMessage): boolean;
6
+ onAuth(context: ConnectionContext<C>): boolean;
7
+ onDisconnect(context: ConnectionContext<C>): void;
8
+ }
@@ -0,0 +1,21 @@
1
+ /// <reference types="node" />
2
+ import * as http from 'http';
3
+ import { Dispatcher, ServiceDispatcher } from '../../dispatcher';
4
+ import { Logger } from '../../logger';
5
+ import { TransportHandlers } from './transport.server';
6
+ import { ConnectionContext } from './transport.context';
7
+ export declare class HttpServerGeneric<C> {
8
+ private _port;
9
+ private _endpoint;
10
+ private _server;
11
+ private _open;
12
+ private _logger;
13
+ private _handlers;
14
+ private _dispatcher;
15
+ get server(): http.Server;
16
+ constructor(endpoint: string, port: number, services: ServiceDispatcher<ConnectionContext<C>, string>[], logger: Logger, open?: boolean, dispatcher?: Dispatcher<ConnectionContext<C>, string> | undefined, handlers?: TransportHandlers<C> | undefined);
17
+ open(): void;
18
+ protected requestHandler(request: http.IncomingMessage, response: http.ServerResponse): void;
19
+ }
20
+ export declare class HttpServer extends HttpServerGeneric<object> {
21
+ }
@@ -0,0 +1,131 @@
1
+ import * as http from 'http';
2
+ import { Dispatcher } from '../../dispatcher';
3
+ import { LogLevel } from '../../logger';
4
+ import { ConnectionContext } from './transport.context';
5
+ import { SystemContext } from './transport.context.system';
6
+ export class HttpServerGeneric {
7
+ constructor(endpoint, port, services, logger, open = true, dispatcher = undefined, handlers = undefined) {
8
+ this._port = port;
9
+ this._endpoint = endpoint;
10
+ if (!dispatcher) {
11
+ this._dispatcher = new Dispatcher();
12
+ }
13
+ else {
14
+ this._dispatcher = dispatcher;
15
+ }
16
+ services.forEach(s => {
17
+ this._dispatcher.register(s);
18
+ });
19
+ this.requestHandler = this.requestHandler.bind(this);
20
+ this._logger = logger;
21
+ this._handlers = handlers;
22
+ this._server = http.createServer(this.requestHandler);
23
+ }
24
+ get server() {
25
+ return this._server;
26
+ }
27
+ open() {
28
+ if (this._open) {
29
+ return;
30
+ }
31
+ this._server
32
+ .listen(this._port, () => {
33
+ this._logger.logf(LogLevel.Info, 'Server is listening on port ' + this._port);
34
+ })
35
+ .on('error', (err) => {
36
+ this._logger.logf(LogLevel.Error, 'Failed to start server ' + err);
37
+ });
38
+ }
39
+ requestHandler(request, response) {
40
+ const { method, url, headers } = request;
41
+ let respHeaders = {};
42
+ respHeaders['Access-Control-Allow-Origin'] = '*';
43
+ if (method === 'OPTIONS') {
44
+ respHeaders['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS';
45
+ respHeaders['Access-Control-Max-Age'] = '86400';
46
+ respHeaders['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept, Authorization, X-Forwarded-For';
47
+ response.writeHead(200, respHeaders);
48
+ response.end();
49
+ return;
50
+ }
51
+ respHeaders['Content-Type'] = 'application/json';
52
+ const context = new ConnectionContext();
53
+ context.system = new SystemContext();
54
+ if (this._handlers && this._handlers.onConnect) {
55
+ if (!this._handlers.onConnect(context, request)) {
56
+ response.writeHead(403);
57
+ response.end();
58
+ }
59
+ }
60
+ if (headers.authorization) {
61
+ context.system.auth.updateFromValue(headers.authorization);
62
+ if (this._handlers && this._handlers.onAuth) {
63
+ if (!this._handlers.onAuth(context)) {
64
+ response.writeHead(403);
65
+ response.end();
66
+ }
67
+ }
68
+ }
69
+ const endpointPos = url.indexOf(this._endpoint);
70
+ if (endpointPos < 0) {
71
+ const msg = 'Invalid endpoint hit: ' + url + '. Expected to use ' + this._endpoint;
72
+ this._logger.logf(LogLevel.Error, msg);
73
+ response.statusCode = 500;
74
+ response.write(msg);
75
+ response.end();
76
+ return;
77
+ }
78
+ const urlEnd = url.substr(endpointPos + this._endpoint.length);
79
+ const pieces = urlEnd.split('/');
80
+ if (pieces.length != 3) {
81
+ const msg = 'Invalid endpoint format. Expected to be /serviceName/serviceMethod, got ' + urlEnd;
82
+ this._logger.logf(LogLevel.Error, msg);
83
+ response.statusCode = 500;
84
+ response.write(msg);
85
+ response.end();
86
+ return;
87
+ }
88
+ const rpcService = pieces[1];
89
+ const rpcMethod = pieces[2];
90
+ this._logger.logf(LogLevel.Trace, 'Incoming request:\n', url, method);
91
+ let body = [];
92
+ request
93
+ .on('error', (err) => {
94
+ this._logger.logf(LogLevel.Error, 'Error while serving request: ', err);
95
+ })
96
+ .on('data', (chunk) => {
97
+ body.push(chunk);
98
+ })
99
+ .on('end', () => {
100
+ const data = method === 'POST' ? Buffer.concat(body).toString() : null;
101
+ this._logger.logf(LogLevel.Trace, data);
102
+ response.on('error', (err) => {
103
+ this._logger.logf(LogLevel.Error, 'Error while serving response: ', err);
104
+ });
105
+ try {
106
+ this._dispatcher.dispatch(null, rpcService, rpcMethod, data)
107
+ .then((res) => {
108
+ this._logger.logf(LogLevel.Trace, 'Outgoing response:\n', res);
109
+ response.writeHead(200, respHeaders);
110
+ response.write(res);
111
+ response.end();
112
+ })
113
+ .catch((err) => {
114
+ this._logger.logf(LogLevel.Trace, 'Outgoing response:\n', 500, err);
115
+ response.statusCode = 500;
116
+ response.write(err);
117
+ response.end();
118
+ });
119
+ }
120
+ catch (err) {
121
+ this._logger.logf(LogLevel.Warning, 'Dispatching failed:\n', err);
122
+ response.statusCode = 500;
123
+ response.write(err);
124
+ response.end();
125
+ }
126
+ });
127
+ }
128
+ }
129
+ export class HttpServer extends HttpServerGeneric {
130
+ }
131
+ //# sourceMappingURL=transport.server.http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.server.http.js","sourceRoot":"","sources":["../../../irt/transport/server/transport.server.http.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AA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OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,sBAAsB,EAAE,GAAG,CAAC,CAAC;oBAC/D,QAAQ,CAAC,SAAS,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;oBACrC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;oBACpB,QAAQ,CAAC,GAAG,EAAE,CAAC;gBACnB,CAAC,CAAC;qBACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;oBACX,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,sBAAsB,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;oBACpE,QAAQ,CAAC,UAAU,GAAG,GAAG,CAAC;oBAC1B,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;oBACpB,QAAQ,CAAC,GAAG,EAAE,CAAC;gBACnB,CAAC,CAAC,CAAC;aACV;YAAC,OAAO,GAAG,EAAE;gBACV,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,uBAAuB,EAAE,GAAG,CAAC,CAAC;gBAClE,QAAQ,CAAC,UAAU,GAAG,GAAG,CAAC;gBAC1B,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACpB,QAAQ,CAAC,GAAG,EAAE,CAAC;aAClB;QACL,CAAC,CAAC,CAAC;IACX,CAAC;CACJ;AAED,MAAM,OAAO,UAAW,SAAQ,iBAAyB;CACxD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=transport.server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.server.js","sourceRoot":"","sources":["../../../irt/transport/server/transport.server.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ /// <reference types="node" />
2
+ import * as http from 'http';
3
+ import { Dispatcher, ServiceDispatcher } from '../../dispatcher';
4
+ import { Logger } from '../../logger';
5
+ import { TransportHandlers } from "./transport.server";
6
+ export declare class WebSocketServerGeneric<C, D> {
7
+ private _server;
8
+ private _dispatcher;
9
+ private _logger;
10
+ private _handlers;
11
+ private _connections;
12
+ constructor(server: http.Server, services: ServiceDispatcher<C, D>[], logger: Logger, open?: boolean, dispatcher?: Dispatcher<C, D>, handlers?: TransportHandlers<C>);
13
+ }
@@ -0,0 +1,51 @@
1
+ import { server as wsServer } from 'websocket';
2
+ import { Dispatcher } from '../../dispatcher';
3
+ import { LogLevel } from '../../logger';
4
+ export class WebSocketServerGeneric {
5
+ constructor(server, services, logger, open = true, dispatcher = undefined, handlers = undefined) {
6
+ this._logger = logger;
7
+ if (!dispatcher) {
8
+ this._dispatcher = new Dispatcher();
9
+ }
10
+ else {
11
+ this._dispatcher = dispatcher;
12
+ }
13
+ services.forEach(s => {
14
+ this._dispatcher.register(s);
15
+ });
16
+ this._handlers = handlers;
17
+ this._connections = [];
18
+ this._server = new wsServer({
19
+ httpServer: server
20
+ });
21
+ this._server.on('request', (request) => {
22
+ this._logger.logf(LogLevel.Trace, 'Incoming connection from ' + request.origin);
23
+ var connection = request.accept(null, request.origin);
24
+ if (this._handlers) {
25
+ if (!this._handlers.onConnect(null, null)) {
26
+ connection.close();
27
+ return;
28
+ }
29
+ }
30
+ this._connections.push(connection);
31
+ connection.on('message', (message) => {
32
+ if (message.type !== 'utf8' || !message.utf8Data) {
33
+ this._logger.logf(LogLevel.Warning, 'Non textual format is not supported. ', message);
34
+ return;
35
+ }
36
+ const data = message.utf8Data;
37
+ throw new Error('Not implemented!');
38
+ });
39
+ connection.on('error', (err) => {
40
+ this._logger.logf(LogLevel.Error, 'Error received: ', err);
41
+ });
42
+ connection.on('close', (code, desc) => {
43
+ if (this._handlers) {
44
+ this._handlers.onDisconnect(null);
45
+ }
46
+ this._connections = this._connections.filter(c => c !== connection);
47
+ });
48
+ });
49
+ }
50
+ }
51
+ //# sourceMappingURL=transport.server.websocket.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.server.websocket.js","sourceRoot":"","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IAAI,CAAC,EAAE;oBACvC,UAAU,CAAC,KAAK,EAAE,CAAC;oBACnB,OAAO;iBACV;aACJ;YAED,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAEnC,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,OAAgB,EAAE,EAAE;gBAC1C,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;oBAC9C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,uCAAuC,EAAE,OAAO,CAAC,CAAC;oBACtF,OAAO;iBACV;gBAED,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC;gBAC9B,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;YACxC,CAAC,CAAC,CAAC;YAEH,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAU,EAAE,EAAE;gBAClC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,kBAAkB,EAAE,GAAG,CAAC,CAAC;YAC/D,CAAC,CAAC,CAAC;YAEH,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAY,EAAE,IAAY,EAAE,EAAE;gBAClD,IAAI,IAAI,CAAC,SAAS,EAAE;oBAChB,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;iBACrC;gBAED,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC;YACxE,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ"}
@@ -0,0 +1,25 @@
1
+ import { AuthMethod } from './auth';
2
+ import { ServiceDispatcher } from '../dispatcher';
3
+ export interface IncomingData {
4
+ serialize(): any;
5
+ }
6
+ export declare type OutgoingData = any;
7
+ export declare type TransportHeaders = {
8
+ [key: string]: string;
9
+ };
10
+ export interface ClientTransport {
11
+ send(service: string, method: string, data: IncomingData): Promise<OutgoingData>;
12
+ setAuthorization(method: AuthMethod | undefined): void;
13
+ getAuthorization(): AuthMethod | undefined;
14
+ setHeaders(headers: TransportHeaders | undefined): void;
15
+ getHeaders(): TransportHeaders;
16
+ }
17
+ export interface ClientSocketTransport<C, D> extends ClientTransport {
18
+ setContext(context: C): void;
19
+ getContext(): C;
20
+ registerBuzzer(buzzer: ServiceDispatcher<C, D>): boolean;
21
+ unregisterBuzzer(id: string): boolean;
22
+ }
23
+ export interface ServerSocketTransport {
24
+ send(service: string, method: string, data: IncomingData): Promise<OutgoingData>;
25
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.js","sourceRoot":"","sources":["../../irt/transport/transport.ts"],"names":[],"mappings":""}
@@ -0,0 +1,31 @@
1
+ export declare enum WebSocketMessageKind {
2
+ Failure = "?:failure",
3
+ RpcRequest = "rpc:request",
4
+ RpcResponse = "rpc:response",
5
+ RpcFailure = "rpc:failure",
6
+ BuzzerRequest = "buzzer:request",
7
+ BuzzerResponse = "buzzer:response",
8
+ BuzzerFailure = "buzzer:failure",
9
+ StreamS2C = "stream:s2c",
10
+ StreamC2S = "stream:c2s"
11
+ }
12
+ export interface WebSocketMessageBase {
13
+ kind: WebSocketMessageKind;
14
+ }
15
+ export interface WebSocketRequestMessage extends WebSocketMessageBase {
16
+ service?: string;
17
+ method?: string;
18
+ id: string;
19
+ data?: any;
20
+ headers?: {
21
+ [key: string]: string;
22
+ };
23
+ }
24
+ export interface WebSocketResponseMessage extends WebSocketMessageBase {
25
+ ref: string;
26
+ data: any;
27
+ }
28
+ export interface WebSocketFailureMessage extends WebSocketMessageBase {
29
+ data: string;
30
+ cause: string;
31
+ }