@celljs/rpc 3.7.8 → 3.9.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 (199) hide show
  1. package/esm/common/annotation/autorpc.d.ts +5 -0
  2. package/esm/common/annotation/autorpc.js +14 -0
  3. package/esm/common/annotation/autorpc.js.map +1 -0
  4. package/esm/common/annotation/detached/autorpc.d.ts +2 -0
  5. package/esm/common/annotation/detached/autorpc.js +11 -0
  6. package/esm/common/annotation/detached/autorpc.js.map +1 -0
  7. package/esm/common/annotation/detached/index.d.ts +1 -0
  8. package/esm/common/annotation/detached/index.js +2 -0
  9. package/esm/common/annotation/detached/index.js.map +1 -0
  10. package/esm/common/annotation/index.d.ts +2 -0
  11. package/esm/common/annotation/index.js +3 -0
  12. package/esm/common/annotation/index.js.map +1 -0
  13. package/esm/common/annotation/rpc.d.ts +19 -0
  14. package/esm/common/annotation/rpc.js +36 -0
  15. package/esm/common/annotation/rpc.js.map +1 -0
  16. package/esm/common/channal/channel-protocol.d.ts +51 -0
  17. package/esm/common/channal/channel-protocol.js +34 -0
  18. package/esm/common/channal/channel-protocol.js.map +1 -0
  19. package/esm/common/channal/http-channel.d.ts +8 -0
  20. package/esm/common/channal/http-channel.js +22 -0
  21. package/esm/common/channal/http-channel.js.map +1 -0
  22. package/esm/common/channal/index.d.ts +2 -0
  23. package/esm/common/channal/index.js +3 -0
  24. package/esm/common/channal/index.js.map +1 -0
  25. package/esm/common/constants.d.ts +1 -0
  26. package/esm/common/constants.js +2 -0
  27. package/esm/common/constants.js.map +1 -0
  28. package/esm/common/converter/converter-protocol.d.ts +6 -0
  29. package/esm/common/converter/converter-protocol.js +3 -0
  30. package/esm/common/converter/converter-protocol.js.map +1 -0
  31. package/esm/common/converter/index.d.ts +1 -0
  32. package/esm/common/converter/index.js +2 -0
  33. package/esm/common/converter/index.js.map +1 -0
  34. package/esm/common/endpoint/endpoint-protocol.d.ts +4 -0
  35. package/esm/common/endpoint/endpoint-protocol.js +2 -0
  36. package/esm/common/endpoint/endpoint-protocol.js.map +1 -0
  37. package/esm/common/endpoint/endpoint-resolver.d.ts +12 -0
  38. package/esm/common/endpoint/endpoint-resolver.js +58 -0
  39. package/esm/common/endpoint/endpoint-resolver.js.map +1 -0
  40. package/esm/common/endpoint/index.d.ts +2 -0
  41. package/esm/common/endpoint/index.js +3 -0
  42. package/esm/common/endpoint/index.js.map +1 -0
  43. package/esm/common/error/error.d.ts +5 -0
  44. package/esm/common/error/error.js +8 -0
  45. package/esm/common/error/error.js.map +1 -0
  46. package/esm/common/error/index.d.ts +1 -0
  47. package/esm/common/error/index.js +2 -0
  48. package/esm/common/error/index.js.map +1 -0
  49. package/esm/common/factory/connection-factory.d.ts +9 -0
  50. package/esm/common/factory/connection-factory.js +25 -0
  51. package/esm/common/factory/connection-factory.js.map +1 -0
  52. package/esm/common/factory/index.d.ts +4 -0
  53. package/esm/common/factory/index.js +5 -0
  54. package/esm/common/factory/index.js.map +1 -0
  55. package/esm/common/factory/proxy-factory.d.ts +56 -0
  56. package/esm/common/factory/proxy-factory.js +177 -0
  57. package/esm/common/factory/proxy-factory.js.map +1 -0
  58. package/esm/common/factory/reader.d.ts +15 -0
  59. package/esm/common/factory/reader.js +44 -0
  60. package/esm/common/factory/reader.js.map +1 -0
  61. package/esm/common/factory/writer.d.ts +9 -0
  62. package/esm/common/factory/writer.js +21 -0
  63. package/esm/common/factory/writer.js.map +1 -0
  64. package/esm/common/handler/connection-handler.d.ts +6 -0
  65. package/esm/common/handler/connection-handler.js +4 -0
  66. package/esm/common/handler/connection-handler.js.map +1 -0
  67. package/esm/common/handler/handler-protocol.d.ts +6 -0
  68. package/esm/common/handler/handler-protocol.js +2 -0
  69. package/esm/common/handler/handler-protocol.js.map +1 -0
  70. package/esm/common/handler/index.d.ts +2 -0
  71. package/esm/common/handler/index.js +3 -0
  72. package/esm/common/handler/index.js.map +1 -0
  73. package/esm/common/index.d.ts +11 -0
  74. package/esm/common/index.js +12 -0
  75. package/esm/common/index.js.map +1 -0
  76. package/esm/common/module.d.ts +3 -0
  77. package/esm/common/module.js +20 -0
  78. package/esm/common/module.js.map +1 -0
  79. package/esm/common/processor/client-config-processor.d.ts +5 -0
  80. package/esm/common/processor/client-config-processor.js +17 -0
  81. package/esm/common/processor/client-config-processor.js.map +1 -0
  82. package/esm/common/processor/index.d.ts +2 -0
  83. package/esm/common/processor/index.js +3 -0
  84. package/esm/common/processor/index.js.map +1 -0
  85. package/esm/common/processor/processor-protocol.d.ts +5 -0
  86. package/esm/common/processor/processor-protocol.js +2 -0
  87. package/esm/common/processor/processor-protocol.js.map +1 -0
  88. package/esm/common/proxy/delegating-http-proxy-creator.d.ts +23 -0
  89. package/esm/common/proxy/delegating-http-proxy-creator.js +86 -0
  90. package/esm/common/proxy/delegating-http-proxy-creator.js.map +1 -0
  91. package/esm/common/proxy/http-proxy-creator.d.ts +42 -0
  92. package/esm/common/proxy/http-proxy-creator.js +139 -0
  93. package/esm/common/proxy/http-proxy-creator.js.map +1 -0
  94. package/esm/common/proxy/index.d.ts +4 -0
  95. package/esm/common/proxy/index.js +5 -0
  96. package/esm/common/proxy/index.js.map +1 -0
  97. package/esm/common/proxy/proxy-protocol.d.ts +20 -0
  98. package/esm/common/proxy/proxy-protocol.js +3 -0
  99. package/esm/common/proxy/proxy-protocol.js.map +1 -0
  100. package/esm/common/proxy/proxy-provider.d.ts +9 -0
  101. package/esm/common/proxy/proxy-provider.js +40 -0
  102. package/esm/common/proxy/proxy-provider.js.map +1 -0
  103. package/esm/common/utils/converter-util.d.ts +7 -0
  104. package/esm/common/utils/converter-util.js +29 -0
  105. package/esm/common/utils/converter-util.js.map +1 -0
  106. package/esm/common/utils/index.d.ts +3 -0
  107. package/esm/common/utils/index.js +4 -0
  108. package/esm/common/utils/index.js.map +1 -0
  109. package/esm/common/utils/logger.d.ts +8 -0
  110. package/esm/common/utils/logger.js +18 -0
  111. package/esm/common/utils/logger.js.map +1 -0
  112. package/esm/common/utils/rpc-util.d.ts +12 -0
  113. package/esm/common/utils/rpc-util.js +43 -0
  114. package/esm/common/utils/rpc-util.js.map +1 -0
  115. package/esm/node/channel/channel-manager.d.ts +9 -0
  116. package/esm/node/channel/channel-manager.js +56 -0
  117. package/esm/node/channel/channel-manager.js.map +1 -0
  118. package/esm/node/channel/channel-middleware.d.ts +7 -0
  119. package/esm/node/channel/channel-middleware.js +37 -0
  120. package/esm/node/channel/channel-middleware.js.map +1 -0
  121. package/esm/node/channel/channel-protocol.d.ts +12 -0
  122. package/esm/node/channel/channel-protocol.js +6 -0
  123. package/esm/node/channel/channel-protocol.js.map +1 -0
  124. package/esm/node/channel/channel-strategy.d.ts +9 -0
  125. package/esm/node/channel/channel-strategy.js +61 -0
  126. package/esm/node/channel/channel-strategy.js.map +1 -0
  127. package/esm/node/channel/index.d.ts +4 -0
  128. package/esm/node/channel/index.js +5 -0
  129. package/esm/node/channel/index.js.map +1 -0
  130. package/esm/node/handler/handler-adapter.d.ts +13 -0
  131. package/esm/node/handler/handler-adapter.js +52 -0
  132. package/esm/node/handler/handler-adapter.js.map +1 -0
  133. package/esm/node/handler/handler-protocol.d.ts +1 -0
  134. package/esm/node/handler/handler-protocol.js +2 -0
  135. package/esm/node/handler/handler-protocol.js.map +1 -0
  136. package/esm/node/handler/index.d.ts +2 -0
  137. package/esm/node/handler/index.js +3 -0
  138. package/esm/node/handler/index.js.map +1 -0
  139. package/esm/node/index.d.ts +2 -0
  140. package/esm/node/index.js +3 -0
  141. package/esm/node/index.js.map +1 -0
  142. package/esm/node/module.d.ts +3 -0
  143. package/esm/node/module.js +4 -0
  144. package/esm/node/module.js.map +1 -0
  145. package/esm/package.json +3 -0
  146. package/lib/common/annotation/autorpc.d.ts.map +1 -1
  147. package/lib/common/annotation/autorpc.js.map +1 -1
  148. package/lib/common/annotation/detached/autorpc.d.ts.map +1 -1
  149. package/lib/common/annotation/detached/autorpc.js.map +1 -1
  150. package/lib/common/annotation/rpc.js.map +1 -1
  151. package/lib/common/channal/channel-protocol.d.ts.map +1 -1
  152. package/lib/common/channal/channel-protocol.js.map +1 -1
  153. package/lib/common/channal/http-channel.d.ts.map +1 -1
  154. package/lib/common/channal/http-channel.js.map +1 -1
  155. package/lib/common/endpoint/endpoint-resolver.d.ts.map +1 -1
  156. package/lib/common/endpoint/endpoint-resolver.js.map +1 -1
  157. package/lib/common/error/error.d.ts.map +1 -1
  158. package/lib/common/error/error.js.map +1 -1
  159. package/lib/common/factory/connection-factory.d.ts.map +1 -1
  160. package/lib/common/factory/connection-factory.js.map +1 -1
  161. package/lib/common/factory/proxy-factory.d.ts +2 -2
  162. package/lib/common/factory/proxy-factory.d.ts.map +1 -1
  163. package/lib/common/factory/proxy-factory.js.map +1 -1
  164. package/lib/common/factory/reader.d.ts.map +1 -1
  165. package/lib/common/factory/reader.js.map +1 -1
  166. package/lib/common/factory/writer.d.ts.map +1 -1
  167. package/lib/common/factory/writer.js.map +1 -1
  168. package/lib/common/handler/connection-handler.d.ts.map +1 -1
  169. package/lib/common/handler/connection-handler.js.map +1 -1
  170. package/lib/common/module.d.ts.map +1 -1
  171. package/lib/common/module.js.map +1 -1
  172. package/lib/common/processor/client-config-processor.d.ts.map +1 -1
  173. package/lib/common/processor/client-config-processor.js.map +1 -1
  174. package/lib/common/proxy/delegating-http-proxy-creator.d.ts.map +1 -1
  175. package/lib/common/proxy/delegating-http-proxy-creator.js.map +1 -1
  176. package/lib/common/proxy/http-proxy-creator.d.ts.map +1 -1
  177. package/lib/common/proxy/http-proxy-creator.js.map +1 -1
  178. package/lib/common/proxy/proxy-provider.d.ts.map +1 -1
  179. package/lib/common/proxy/proxy-provider.js.map +1 -1
  180. package/lib/common/utils/converter-util.js.map +1 -1
  181. package/lib/common/utils/logger.d.ts.map +1 -1
  182. package/lib/common/utils/logger.js.map +1 -1
  183. package/lib/common/utils/rpc-util.js.map +1 -1
  184. package/lib/node/channel/channel-manager.d.ts.map +1 -1
  185. package/lib/node/channel/channel-manager.js.map +1 -1
  186. package/lib/node/channel/channel-middleware.d.ts.map +1 -1
  187. package/lib/node/channel/channel-middleware.js.map +1 -1
  188. package/lib/node/channel/channel-strategy.d.ts.map +1 -1
  189. package/lib/node/channel/channel-strategy.js.map +1 -1
  190. package/lib/node/handler/handler-adapter.d.ts.map +1 -1
  191. package/lib/node/handler/handler-adapter.js.map +1 -1
  192. package/lib/node/module.d.ts.map +1 -1
  193. package/lib/node/module.js.map +1 -1
  194. package/lib/package.spec.d.ts +1 -0
  195. package/lib/package.spec.js +5 -2
  196. package/lib/package.spec.js.map +1 -1
  197. package/package.json +103 -13
  198. package/src/package.spec.ts +1 -0
  199. package/LICENSE +0 -21
@@ -0,0 +1,139 @@
1
+ import { HttpHeaders, HttpMethod, MediaType, XML_HTTP_REQUEST, DefaultRestOperationsFactory } from '@celljs/http';
2
+ import { ConnnectionFactoryImpl, JsonRpcProxyFactory } from '../factory/index.js';
3
+ import { HttpChannel } from '../channal/index.js';
4
+ import { ConsoleLogger } from '../utils/index.js';
5
+ const DEFAULT_OPTIONS = {
6
+ connnectionFactory: new ConnnectionFactoryImpl(),
7
+ restOperations: new DefaultRestOperationsFactory().create(),
8
+ clientConfig: {},
9
+ merge: {
10
+ maxCount: 100,
11
+ maxLength: 5242880,
12
+ timerDelay: 35,
13
+ enabled: false
14
+ }
15
+ };
16
+ export class HttpProxyCreator {
17
+ constructor(options) {
18
+ this.channelIdSeq = 0;
19
+ this.requestMap = new Map();
20
+ this.channelMap = new Map();
21
+ this.options = { ...DEFAULT_OPTIONS, ...options, merge: { ...DEFAULT_OPTIONS.merge, ...options.merge } };
22
+ }
23
+ create(path, errorConverters, target) {
24
+ const factory = new JsonRpcProxyFactory(target, errorConverters);
25
+ this.options.endpointResolver.resolve(path).then(endpoint => this.listen({
26
+ path: endpoint,
27
+ onConnection: c => factory.listen(c)
28
+ }));
29
+ return factory.createProxy();
30
+ }
31
+ support(path) {
32
+ return 500;
33
+ }
34
+ listen(handler, options) {
35
+ this.openChannel(handler.path, channel => {
36
+ const connection = this.options.connnectionFactory.create(channel, this.createLogger());
37
+ handler.onConnection(connection);
38
+ }, options);
39
+ }
40
+ openChannel(path, handler, options) {
41
+ this.doOpenChannel(path, handler, options);
42
+ }
43
+ doOpenChannel(path, handler, options) {
44
+ const id = this.channelIdSeq++;
45
+ const channel = this.createChannel(id, path);
46
+ handler(channel);
47
+ }
48
+ createChannel(id, path) {
49
+ const parts = path.split('/');
50
+ const serviceName = parts.pop();
51
+ const endpoint = parts.join('/');
52
+ const channel = new HttpChannel(id, async (content) => {
53
+ if (this.options.merge.enabled) {
54
+ if (this.canMerge(endpoint, content)) {
55
+ this.pushContent(endpoint, content);
56
+ }
57
+ else {
58
+ this.executeTask(endpoint);
59
+ this.pushContent(endpoint, content);
60
+ }
61
+ }
62
+ else {
63
+ this.pushContent(endpoint, content);
64
+ this.executeTask(endpoint);
65
+ }
66
+ }, serviceName);
67
+ this.channelMap.set(id, channel);
68
+ return channel;
69
+ }
70
+ executeTask(endpoint) {
71
+ const meta = this.requestMap.get(endpoint);
72
+ if (meta) {
73
+ return meta.task();
74
+ }
75
+ }
76
+ canMerge(endpoint, content) {
77
+ const meta = this.requestMap.get(endpoint);
78
+ if (meta) {
79
+ if (meta.contentLength + content.length > this.options.merge.maxLength ||
80
+ meta.contents.length + 1 > this.options.merge.maxCount) {
81
+ return false;
82
+ }
83
+ }
84
+ return true;
85
+ }
86
+ pushContent(endpoint, content) {
87
+ let meta = this.requestMap.get(endpoint);
88
+ if (!meta) {
89
+ const task = this.createTask(endpoint);
90
+ meta = {
91
+ id: setTimeout(task, this.options.merge.timerDelay),
92
+ contents: [],
93
+ contentLength: 0,
94
+ task
95
+ };
96
+ this.requestMap.set(endpoint, meta);
97
+ }
98
+ meta.contents.push(content);
99
+ meta.contentLength += content.length;
100
+ return meta;
101
+ }
102
+ createTask(endpoint) {
103
+ return async () => {
104
+ var _a;
105
+ const meta = this.requestMap.get(endpoint);
106
+ if (!meta) {
107
+ return;
108
+ }
109
+ clearTimeout(meta.id);
110
+ const contents = meta.contents;
111
+ this.requestMap.delete(endpoint);
112
+ const config = {
113
+ url: endpoint,
114
+ method: HttpMethod.POST,
115
+ data: contents.length > 1 ? JSON.stringify(contents) : contents[0],
116
+ headers: {
117
+ [HttpHeaders.CONTENT_TYPE]: MediaType.APPLICATION_JSON_UTF8,
118
+ [HttpHeaders.X_REQUESTED_WITH]: XML_HTTP_REQUEST
119
+ },
120
+ ...this.options.clientConfig
121
+ };
122
+ await ((_a = this.options.clientConfigProcessor) === null || _a === void 0 ? void 0 : _a.process(config));
123
+ const { data } = await this.options.restOperations.request(config);
124
+ if (Array.isArray(data)) {
125
+ for (const message of data) {
126
+ const parsed = JSON.parse(message);
127
+ this.channelMap.get(parsed.id).handleMessage(parsed);
128
+ }
129
+ }
130
+ else {
131
+ this.channelMap.get(data.id).handleMessage(data);
132
+ }
133
+ };
134
+ }
135
+ createLogger() {
136
+ return new ConsoleLogger();
137
+ }
138
+ }
139
+ //# sourceMappingURL=http-proxy-creator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-proxy-creator.js","sourceRoot":"","sources":["../../../src/common/proxy/http-proxy-creator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,gBAAgB,EAAkB,4BAA4B,EAAE,MAAM,cAAc,CAAC;AAIlI,OAAO,EAAsB,sBAAsB,EAAgB,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAC3G,OAAO,EAAW,WAAW,EAAE,MAAM,YAAY,CAAC;AAKlD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAmBzC,MAAM,eAAe,GAAoE;IACrF,kBAAkB,EAAE,IAAI,sBAAsB,EAAE;IAChD,cAAc,EAAE,IAAI,4BAA4B,EAAE,CAAC,MAAM,EAAE;IAC3D,YAAY,EAAE,EAAE;IAChB,KAAK,EAAE;QACH,QAAQ,EAAE,GAAG;QACb,SAAS,EAAE,OAAO;QAClB,U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IAAI,EAAE,CAAC;oBACzB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;oBACnC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAE,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;gBAC1D,CAAC;YACL,CAAC;iBAAM,CAAC;gBACJ,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAE,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YACtD,CAAC;QACL,CAAC,CAAC;IACN,CAAC;IAES,YAAY;QAClB,OAAO,IAAI,aAAa,EAAE,CAAC;IAC/B,CAAC;CAEJ"}
@@ -0,0 +1,4 @@
1
+ export * from './proxy-provider.js';
2
+ export * from './proxy-protocol.js';
3
+ export * from './http-proxy-creator.js';
4
+ export * from './delegating-http-proxy-creator.js';
@@ -0,0 +1,5 @@
1
+ export * from './proxy-provider.js';
2
+ export * from './proxy-protocol.js';
3
+ export * from './http-proxy-creator.js';
4
+ export * from './delegating-http-proxy-creator.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/proxy/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iCAAiC,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { ErrorConverter } from '../converter/index.js';
2
+ import { JsonRpcProxy } from '../factory/index.js';
3
+ export declare const ProxyProvider: unique symbol;
4
+ export interface ProxyProvider {
5
+ provide<T extends object>(path: string, errorConverters?: ErrorConverter[], target?: object): JsonRpcProxy<T>;
6
+ }
7
+ export declare const ProxyCreator: unique symbol;
8
+ export interface ProxyCreator {
9
+ create<T extends object>(path: string, errorConverters?: ErrorConverter[], target?: object): JsonRpcProxy<T>;
10
+ support(path: string): number;
11
+ }
12
+ export interface ConnectionOptions {
13
+ reconnecting?: boolean;
14
+ }
15
+ export interface RequestTaskMeta {
16
+ id: number | NodeJS.Timeout;
17
+ contentLength: number;
18
+ contents: string[];
19
+ task: () => Promise<void>;
20
+ }
@@ -0,0 +1,3 @@
1
+ export const ProxyProvider = Symbol('ProxyProvider');
2
+ export const ProxyCreator = Symbol('ProxyCreator');
3
+ //# sourceMappingURL=proxy-protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy-protocol.js","sourceRoot":"","sources":["../../../src/common/proxy/proxy-protocol.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAMrD,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { ErrorConverter } from '../converter/index.js';
2
+ import { JsonRpcProxy } from '../factory/index.js';
3
+ import { ProxyProvider, ProxyCreator } from './proxy-protocol.js';
4
+ export declare class ProxyProviderImpl implements ProxyProvider {
5
+ protected readonly proxyCreators: ProxyCreator[];
6
+ constructor(proxyCreators: ProxyCreator[]);
7
+ provide<T extends object>(path: string, errorConverters?: ErrorConverter[], target?: object): JsonRpcProxy<T>;
8
+ protected prioritize(path: string): ProxyCreator[];
9
+ }
@@ -0,0 +1,40 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { Prioritizeable, Component, Autowired } from '@celljs/core';
14
+ import { ProxyProvider, ProxyCreator } from './proxy-protocol.js';
15
+ let ProxyProviderImpl = class ProxyProviderImpl {
16
+ constructor(proxyCreators) {
17
+ this.proxyCreators = proxyCreators;
18
+ }
19
+ provide(path, errorConverters, target) {
20
+ return this.prioritize(path)[0].create(path, errorConverters, target);
21
+ }
22
+ prioritize(path) {
23
+ const prioritized = Prioritizeable.prioritizeAllSync(this.proxyCreators, proxyCreator => {
24
+ try {
25
+ return proxyCreator.support(path);
26
+ }
27
+ catch (_a) {
28
+ return 0;
29
+ }
30
+ });
31
+ return prioritized.map(p => p.value);
32
+ }
33
+ };
34
+ ProxyProviderImpl = __decorate([
35
+ Component(ProxyProvider),
36
+ __param(0, Autowired(ProxyCreator)),
37
+ __metadata("design:paramtypes", [Array])
38
+ ], ProxyProviderImpl);
39
+ export { ProxyProviderImpl };
40
+ //# sourceMappingURL=proxy-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy-provider.js","sourceRoot":"","sources":["../../../src/common/proxy/proxy-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGpE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGxD,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAE1B,YAEuB,aAA6B;6BAA7B,aAAa;IAChC,CAAC;IAEL,OAAO,CAAmB,IAAY,EAAE,eAAkC,EAAE,MAAe;QACvF,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,eAAe,EAAE,MAAM,CAAC,CAAC;IAC1E,CAAC;IAES,UAAU,CAAC,IAAY;QAC7B,MAAM,WAAW,GAAG,cAAc,CAAC,iBAAiB,CAAC,IAAI,CAAC,aAAa,EAAE,YAAY,CAAC,EAAE;YACpF,IAAI,CAAC;gBACD,OAAO,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACtC,CAAC;uBAAO,CAAC;gBACL,OAAO,CAAC,CAAC;YACb,CAAC;QACL,CAAC,CAAC,CAAC;QACH,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;CAEJ,CAAA;AAtBY,iBAAiB;IAD7B,SAAS,CAAC,aAAa,CAAC;IAIhB,WAAA,SAAS,CAAC,YAAY,CAAC,CAAA;;GAHnB,iBAAiB,CAsB7B"}
@@ -0,0 +1,7 @@
1
+ import { Container } from '@celljs/core';
2
+ import { ErrorConverter } from '../converter/index.js';
3
+ export declare namespace ConverterUtil {
4
+ function getErrorConverterIgnoreNoMatching<T>(task: () => T): T | undefined;
5
+ function getGlobalErrorConverters(container?: Container): ErrorConverter[];
6
+ function getErrorConverters(serviceIdentifier: any, container?: Container): ErrorConverter | undefined;
7
+ }
@@ -0,0 +1,29 @@
1
+ import { ContainerUtil } from '@celljs/core';
2
+ import { ErrorConverter, GlobalConverter } from '../converter/index.js';
3
+ import { RpcUtil } from './rpc-util.js';
4
+ export var ConverterUtil;
5
+ (function (ConverterUtil) {
6
+ function getErrorConverterIgnoreNoMatching(task) {
7
+ try {
8
+ return task();
9
+ }
10
+ catch (error) {
11
+ if (!(error === null || error === void 0 ? void 0 : error.message.startsWith('No matching bindings found for serviceIdentifier: Symbol(ErrorConverter)'))) {
12
+ throw error;
13
+ }
14
+ }
15
+ }
16
+ ConverterUtil.getErrorConverterIgnoreNoMatching = getErrorConverterIgnoreNoMatching;
17
+ function getGlobalErrorConverters(container) {
18
+ return getErrorConverterIgnoreNoMatching(() => container ? container.getAllNamed(ErrorConverter, GlobalConverter) :
19
+ ContainerUtil.getAllNamed(ErrorConverter, GlobalConverter)) || [];
20
+ }
21
+ ConverterUtil.getGlobalErrorConverters = getGlobalErrorConverters;
22
+ function getErrorConverters(serviceIdentifier, container) {
23
+ const name = RpcUtil.toName(serviceIdentifier);
24
+ return getErrorConverterIgnoreNoMatching(() => container ? container.getNamed(ErrorConverter, name) :
25
+ ContainerUtil.getNamed(ErrorConverter, name));
26
+ }
27
+ ConverterUtil.getErrorConverters = getErrorConverters;
28
+ })(ConverterUtil || (ConverterUtil = {}));
29
+ //# sourceMappingURL=converter-util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"converter-util.js","sourceRoot":"","sources":["../../../src/common/utils/converter-util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAa,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,KAAW,aAAa,CAwB7B;AAxBD,WAAiB,aAAa;IAE1B,SAAgB,iCAAiC,CAAI,IAAa;QAC9D,IAAI,CAAC;YACD,OAAO,IAAI,EAAE,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,EAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,CAAC,UAAU,CAAC,0EAA0E,CAAC,CAAA,EAAE,CAAC;gBACzG,MAAM,KAAK,CAAC;YAChB,CAAC;QACL,CAAC;IACL,CAAC;IARe,cAAA,iCAAiC,oCAQhD,CAAA;IAED,SAAgB,wBAAwB,CAAC,SAAqB;QAC1D,OAAO,iCAAiC,CAAC,GAAG,EAAE,CAC1C,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW,CAAiB,cAAc,EAAE,eAAe,CAAC,CAAC,CAAC;YAChF,aAAa,CAAC,WAAW,CAAiB,cAAc,EAAE,eAAe,CAAC,CAAC,IAAI,EAAE,CAAC;IAC9F,CAAC;IAJe,cAAA,wBAAwB,2BAIvC,CAAA;IAED,SAAgB,kBAAkB,CAAC,iBAAsB,EAAE,SAAqB;QAC5E,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;QAC/C,OAAO,iCAAiC,CAAC,GAAG,EAAE,CAC1C,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAiB,cAAc,EAAE,IAAI,CAAC,CAAC,CAAC;YAClE,aAAa,CAAC,QAAQ,CAAiB,cAAc,EAAE,IAAI,CAAC,CAAC,CAAC;IAC1E,CAAC;IALe,cAAA,kBAAkB,qBAKjC,CAAA;AACL,CAAC,EAxBgB,aAAa,KAAb,aAAa,QAwB7B"}
@@ -0,0 +1,3 @@
1
+ export * from './rpc-util.js';
2
+ export * from './converter-util.js';
3
+ export * from './logger.js';
@@ -0,0 +1,4 @@
1
+ export * from './rpc-util.js';
2
+ export * from './converter-util.js';
3
+ export * from './logger.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { Logger as ILoger } from 'vscode-jsonrpc';
2
+ export declare class ConsoleLogger implements ILoger {
3
+ error(message: string): void;
4
+ warn(message: string): void;
5
+ info(message: string): void;
6
+ log(message: string): void;
7
+ debug(message: string): void;
8
+ }
@@ -0,0 +1,18 @@
1
+ export class ConsoleLogger {
2
+ error(message) {
3
+ console.error(message);
4
+ }
5
+ warn(message) {
6
+ console.warn(message);
7
+ }
8
+ info(message) {
9
+ console.info(message);
10
+ }
11
+ log(message) {
12
+ console.log(message);
13
+ }
14
+ debug(message) {
15
+ console.debug(message);
16
+ }
17
+ }
18
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/common/utils/logger.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,aAAa;IACf,KAAK,CAAC,OAAe;QACxB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAEM,IAAI,CAAC,OAAe;QACvB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;IAEM,IAAI,CAAC,OAAe;QACvB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;IAEM,GAAG,CAAC,OAAe;QACtB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IAEM,KAAK,CAAC,OAAe;QACxB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;CACJ"}
@@ -0,0 +1,12 @@
1
+ import { ComponentId } from '@celljs/core';
2
+ import { HttpProxyCreator, HttpProxyCreatorOptions, MergeOptions } from '../proxy/http-proxy-creator.js';
3
+ import { ProxyCreator } from '../proxy/proxy-protocol.js';
4
+ export declare namespace RpcUtil {
5
+ function get<T extends object>(rpcServiceIdentifier: ComponentId<T>): T;
6
+ function getDefaultProxyCreator(endpoint: string, options?: Partial<HttpProxyCreatorOptions<Partial<MergeOptions>>>): ProxyCreator | undefined;
7
+ function setDefaultProxyCreator(endpoint: string, options?: Partial<HttpProxyCreatorOptions<Partial<MergeOptions>>>): void;
8
+ function createProxyCreator(endpoint: string, options?: Partial<HttpProxyCreatorOptions<Partial<MergeOptions>>>): HttpProxyCreator;
9
+ function create<T extends object>(endpoint: string, rpcServiceIdentifier: ComponentId<T>, options?: Partial<HttpProxyCreatorOptions<Partial<MergeOptions>>>): T;
10
+ function toPath(serviceIdentifier: any): any;
11
+ function toName(serviceIdentifier: any): any;
12
+ }
@@ -0,0 +1,43 @@
1
+ import { ContainerUtil, UrlUtil } from '@celljs/core';
2
+ import { ID_KEY, RPC } from '../annotation/index.js';
3
+ import { HttpProxyCreator } from '../proxy/http-proxy-creator.js';
4
+ let defaultProxyCreator;
5
+ export var RpcUtil;
6
+ (function (RpcUtil) {
7
+ function get(rpcServiceIdentifier) {
8
+ if (defaultProxyCreator) {
9
+ return defaultProxyCreator.create(toPath(rpcServiceIdentifier));
10
+ }
11
+ return ContainerUtil.getTagged(RPC, ID_KEY, rpcServiceIdentifier);
12
+ }
13
+ RpcUtil.get = get;
14
+ function getDefaultProxyCreator(endpoint, options) {
15
+ return defaultProxyCreator;
16
+ }
17
+ RpcUtil.getDefaultProxyCreator = getDefaultProxyCreator;
18
+ function setDefaultProxyCreator(endpoint, options) {
19
+ defaultProxyCreator = createProxyCreator(endpoint, options);
20
+ }
21
+ RpcUtil.setDefaultProxyCreator = setDefaultProxyCreator;
22
+ function createProxyCreator(endpoint, options) {
23
+ return new HttpProxyCreator({ ...options, endpointResolver: {
24
+ resolve(serviceIdentifier) {
25
+ return Promise.resolve(UrlUtil.join(endpoint, serviceIdentifier));
26
+ }
27
+ } });
28
+ }
29
+ RpcUtil.createProxyCreator = createProxyCreator;
30
+ function create(endpoint, rpcServiceIdentifier, options) {
31
+ return createProxyCreator(endpoint, options).create(toPath(rpcServiceIdentifier));
32
+ }
33
+ RpcUtil.create = create;
34
+ function toPath(serviceIdentifier) {
35
+ return typeof serviceIdentifier !== 'function' ? serviceIdentifier.toString() : serviceIdentifier.name || serviceIdentifier.toString();
36
+ }
37
+ RpcUtil.toPath = toPath;
38
+ function toName(serviceIdentifier) {
39
+ return typeof serviceIdentifier !== 'function' ? serviceIdentifier : serviceIdentifier.name || serviceIdentifier.toString();
40
+ }
41
+ RpcUtil.toName = toName;
42
+ })(RpcUtil || (RpcUtil = {}));
43
+ //# sourceMappingURL=rpc-util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc-util.js","sourceRoot":"","sources":["../../../src/common/utils/rpc-util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAe,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MAAM,CAAI,MAAM,CAAC,oBAAoB,CAAC,CAAC,CAAC;IACzF,CAAC;IAHe,QAAA,MAAM,SAGrB,CAAA;IAED,SAAgB,MAAM,CAAC,iBAAsB;QACzC,OAAO,OAAO,iBAAiB,KAAK,UAAU,CAAC,CAAC,CAAC,iBAAiB,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC,IAAI,IAAI,iBAAiB,CAAC,QAAQ,EAAE,CAAC;IAE3I,CAAC;IAHe,QAAA,MAAM,SAGrB,CAAA;IAED,SAAgB,MAAM,CAAC,iBAAsB;QACzC,OAAO,OAAO,iBAAiB,KAAK,UAAU,CAAC,CAAC,CAAkB,iBAAiB,CAAC,CAAC,CAAC,iBAAiB,CAAC,IAAI,IAAI,iBAAiB,CAAC,QAAQ,EAAE,CAAC;IAEjJ,CAAC;IAHe,QAAA,MAAM,SAGrB,CAAA;AACL,CAAC,EAtCgB,OAAO,KAAP,OAAO,QAsCvB"}
@@ -0,0 +1,9 @@
1
+ import { ConnectionHandler, ConnnectionFactory, Channel } from '../../common/index.js';
2
+ export declare class ChannelManager {
3
+ protected readonly handlers: ConnectionHandler[];
4
+ protected connnectionFactory: ConnnectionFactory<Channel>;
5
+ protected _handlers: Map<string, ConnectionHandler>;
6
+ constructor(handlers: ConnectionHandler[], connnectionFactory: ConnnectionFactory<Channel>);
7
+ handleChannels(): Promise<void>;
8
+ protected getRealPath(path: string): string;
9
+ }
@@ -0,0 +1,56 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { Context, NotFoundError } from '@celljs/web/lib/node';
14
+ import { ConnectionHandler, ConnnectionFactory, ConsoleLogger } from '../../common/index.js';
15
+ import { Component, Autowired, Deferred, Optional } from '@celljs/core';
16
+ import { CURRENT_CHANNEL_STRATEGY_REQUEST_KEY } from './channel-protocol.js';
17
+ // tslint:disable:no-any
18
+ let ChannelManager = class ChannelManager {
19
+ constructor(handlers, connnectionFactory) {
20
+ this.handlers = handlers;
21
+ this.connnectionFactory = connnectionFactory;
22
+ this._handlers = new Map();
23
+ for (const handler of handlers) {
24
+ this._handlers.set(handler.path, handler);
25
+ }
26
+ }
27
+ async handleChannels() {
28
+ const channelStrategy = Context.getAttr(CURRENT_CHANNEL_STRATEGY_REQUEST_KEY);
29
+ Context.getResponse().body = new Deferred();
30
+ for (const message of await channelStrategy.getMessages()) {
31
+ const { id, path } = message;
32
+ if (path) {
33
+ const handler = this._handlers.get(this.getRealPath(path));
34
+ if (handler) {
35
+ const channel = await channelStrategy.createChannel(id);
36
+ handler.onConnection(this.connnectionFactory.create(channel, new ConsoleLogger()));
37
+ channel.handleMessage(message);
38
+ }
39
+ continue;
40
+ }
41
+ throw new NotFoundError(`Cannot find a service for the path: ${path}`);
42
+ }
43
+ }
44
+ getRealPath(path) {
45
+ return path.split(':').pop();
46
+ }
47
+ };
48
+ ChannelManager = __decorate([
49
+ Component(),
50
+ __param(0, Autowired(ConnectionHandler)),
51
+ __param(0, Optional()),
52
+ __param(1, Autowired(ConnnectionFactory)),
53
+ __metadata("design:paramtypes", [Array, Object])
54
+ ], ChannelManager);
55
+ export { ChannelManager };
56
+ //# sourceMappingURL=channel-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3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CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;oBACxD,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,aAAa,EAAE,CAAC,CAAC,CAAC;oBACnF,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;gBACnC,CAAC;gBACD,SAAS;YACb,CAAC;YACD,MAAM,IAAI,aAAa,CAAC,uCAAuC,IAAI,EAAE,CAAC,CAAC;QAC3E,CAAC;IACL,CAAC;IAES,WAAW,CAAC,IAAY;QAC9B,OAAe,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;IACzC,CAAC;CAEJ,CAAA;AApCY,cAAc;IAD1B,SAAS,EAAE;IAMH,WAAA,SAAS,CAAC,iBAAiB,CAAC,CAAA;IAAE,WAAA,QAAQ,EAAE,CAAA;IAExC,WAAA,SAAS,CAAC,kBAAkB,CAAC,CAAA;;GAPzB,cAAc,CAoC1B"}
@@ -0,0 +1,7 @@
1
+ import { Middleware, Context } from '@celljs/web/lib/node';
2
+ import { ChannelStrategy } from './channel-protocol.js';
3
+ export declare class ChannelMiddleware implements Middleware {
4
+ protected readonly channelStrategies: ChannelStrategy[];
5
+ handle(ctx: Context, next: () => Promise<void>): Promise<void>;
6
+ readonly priority = 2100;
7
+ }
@@ -0,0 +1,37 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Middleware, Context } from '@celljs/web/lib/node';
11
+ import { Component, Autowired } from '@celljs/core';
12
+ import { ChannelStrategy, CHANNEL_MIDDLEWARE_PRIORITY, CURRENT_CHANNEL_STRATEGY_REQUEST_KEY } from './channel-protocol.js';
13
+ import { HttpHeaders, MediaType } from '@celljs/http';
14
+ let ChannelMiddleware = class ChannelMiddleware {
15
+ constructor() {
16
+ this.priority = CHANNEL_MIDDLEWARE_PRIORITY;
17
+ }
18
+ async handle(ctx, next) {
19
+ for (const channelStrategy of this.channelStrategies) {
20
+ if (await channelStrategy.support()) {
21
+ Context.setAttr(CURRENT_CHANNEL_STRATEGY_REQUEST_KEY, channelStrategy);
22
+ break;
23
+ }
24
+ }
25
+ ctx.response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8);
26
+ await next();
27
+ }
28
+ };
29
+ __decorate([
30
+ Autowired(ChannelStrategy),
31
+ __metadata("design:type", Array)
32
+ ], ChannelMiddleware.prototype, "channelStrategies", void 0);
33
+ ChannelMiddleware = __decorate([
34
+ Component(Middleware)
35
+ ], ChannelMiddleware);
36
+ export { ChannelMiddleware };
37
+ //# sourceMappingURL=channel-middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channel-middleware.js","sourceRoot":"","sources":["../../../src/node/channel/channel-middleware.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,2BAA2B,EAAE,oCAAoC,EAAE,MAAM,oBAAoB,CAAC;AACxH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAG/C,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAAvB;QAkBM,aAAQ,GAAG,2BAA2B,CAAC;IAEpD,CAAC;IAfG,KAAK,CAAC,MAAM,CAAC,GAAY,EAAE,IAAyB;QAChD,KAAK,MAAM,eAAe,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACnD,IAAI,MAAM,eAAe,CAAC,OAAO,EAAE,EAAE,CAAC;gBAClC,OAAO,CAAC,OAAO,CAAC,oCAAoC,EAAE,eAAe,CAAC,CAAC;gBACvE,MAAM;YACV,CAAC;QACL,CAAC;QAED,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,YAAY,EAAE,SAAS,CAAC,qBAAqB,CAAC,CAAC;QAElF,MAAM,IAAI,EAAE,CAAC;IACjB,CAAC;CAIJ,CAAA;AAjBsB;IADlB,SAAS,CAAC,eAAe,CAAC;;4DAC6B;AAH/C,iBAAiB;IAD7B,SAAS,CAAC,UAAU,CAAC;GACT,iBAAiB,CAoB7B"}
@@ -0,0 +1,12 @@
1
+ import { Channel } from '../../common/index.js';
2
+ export declare const ChannelStrategy: unique symbol;
3
+ export declare const CHANNEL_MIDDLEWARE_PRIORITY = 2100;
4
+ export declare const CURRENT_CHANNEL_STRATEGY_REQUEST_KEY = "CurrentChannelStrategyRequest";
5
+ export declare const CURRENT_MESSAGE_COUNT_REQUEST_KEY = "CurrentMessageCountRequest";
6
+ export declare const CURRENT_RESPONSE_MESSAGE_REQUEST_KEY = "CurrentResponseMessageRequest";
7
+ export interface ChannelStrategy {
8
+ getMessages(): Promise<Channel.Message[]>;
9
+ handleMessage(message: any): Promise<void>;
10
+ createChannel(id: number): Promise<Channel>;
11
+ support(): Promise<boolean>;
12
+ }
@@ -0,0 +1,6 @@
1
+ export const ChannelStrategy = Symbol('ChannelStrategy');
2
+ export const CHANNEL_MIDDLEWARE_PRIORITY = 2100;
3
+ export const CURRENT_CHANNEL_STRATEGY_REQUEST_KEY = 'CurrentChannelStrategyRequest';
4
+ export const CURRENT_MESSAGE_COUNT_REQUEST_KEY = 'CurrentMessageCountRequest';
5
+ export const CURRENT_RESPONSE_MESSAGE_REQUEST_KEY = 'CurrentResponseMessageRequest';
6
+ //# sourceMappingURL=channel-protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channel-protocol.js","sourceRoot":"","sources":["../../../src/node/channel/channel-protocol.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAEzD,MAAM,CAAC,MAAM,2BAA2B,GAAG,IAAI,CAAC;AAEhD,MAAM,CAAC,MAAM,oCAAoC,GAAG,+BAA+B,CAAC;AACpF,MAAM,CAAC,MAAM,iCAAiC,GAAG,4BAA4B,CAAC;AAC9E,MAAM,CAAC,MAAM,oCAAoC,GAAG,+BAA+B,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { Channel } from '../../common/channal/index.js';
2
+ import { ChannelStrategy } from './channel-protocol.js';
3
+ export declare class HttpChannelStrategy implements ChannelStrategy {
4
+ getMessages(): Promise<Channel.Message[]>;
5
+ createChannel(id: number): Promise<Channel>;
6
+ handleMessage(message: string): Promise<void>;
7
+ protected consumeMessage(message: string): boolean;
8
+ support(): Promise<boolean>;
9
+ }
@@ -0,0 +1,61 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { HttpChannel } from '../../common/channal/index.js';
8
+ import { ChannelStrategy, CURRENT_MESSAGE_COUNT_REQUEST_KEY, CURRENT_RESPONSE_MESSAGE_REQUEST_KEY } from './channel-protocol.js';
9
+ import { Component } from '@celljs/core';
10
+ import { Context } from '@celljs/web/lib/node';
11
+ let HttpChannelStrategy = class HttpChannelStrategy {
12
+ async getMessages() {
13
+ let message = await Context.getRequest().body;
14
+ if (!Array.isArray(message)) {
15
+ message = [message];
16
+ }
17
+ else {
18
+ const parsed = [];
19
+ for (const m of message) {
20
+ parsed.push(JSON.parse(m));
21
+ }
22
+ message = parsed;
23
+ }
24
+ Context.setAttr(CURRENT_MESSAGE_COUNT_REQUEST_KEY, message.length);
25
+ return message;
26
+ }
27
+ async createChannel(id) {
28
+ return new HttpChannel(id, async (content) => {
29
+ this.handleMessage(content);
30
+ });
31
+ }
32
+ async handleMessage(message) {
33
+ if (!this.consumeMessage(message)) {
34
+ const deferred = Context.getResponse().body;
35
+ const messages = Context.getAttr(CURRENT_RESPONSE_MESSAGE_REQUEST_KEY);
36
+ deferred.resolve(messages.length > 1 ? JSON.stringify(messages) : message);
37
+ }
38
+ }
39
+ consumeMessage(message) {
40
+ const messageCount = Context.getAttr(CURRENT_MESSAGE_COUNT_REQUEST_KEY);
41
+ Context.setAttr(CURRENT_MESSAGE_COUNT_REQUEST_KEY, messageCount - 1);
42
+ let messages = Context.getAttr(CURRENT_RESPONSE_MESSAGE_REQUEST_KEY);
43
+ if (!messages) {
44
+ messages = [];
45
+ Context.setAttr(CURRENT_RESPONSE_MESSAGE_REQUEST_KEY, messages);
46
+ }
47
+ messages.push(message);
48
+ if (messageCount - 1 <= 0) {
49
+ return false;
50
+ }
51
+ return true;
52
+ }
53
+ async support() {
54
+ return Context.getCurrent() instanceof Context;
55
+ }
56
+ };
57
+ HttpChannelStrategy = __decorate([
58
+ Component(ChannelStrategy)
59
+ ], HttpChannelStrategy);
60
+ export { HttpChannelStrategy };
61
+ //# sourceMappingURL=channel-strategy.js.map