@based/server 3.3.7 → 3.4.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 (308) hide show
  1. package/.turbo/turbo-build.log +5 -5
  2. package/dist/BasedServerClient.d.ts +0 -0
  3. package/dist/BasedServerClient.js +0 -0
  4. package/dist/BasedServerClient.js.map +0 -0
  5. package/dist/Client.d.ts +0 -0
  6. package/dist/Client.js +0 -0
  7. package/dist/Client.js.map +0 -0
  8. package/dist/Params.d.ts +0 -0
  9. package/dist/Params.js +0 -0
  10. package/dist/Params.js.map +0 -0
  11. package/dist/auth/authorize.d.ts +2 -0
  12. package/dist/auth/authorize.js +8 -0
  13. package/dist/auth/authorize.js.map +1 -0
  14. package/dist/auth/authorizeAdvanced.d.ts +2 -0
  15. package/dist/auth/authorizeAdvanced.js +10 -0
  16. package/dist/auth/authorizeAdvanced.js.map +1 -0
  17. package/dist/auth/defaults/authorize.d.ts +2 -0
  18. package/dist/auth/defaults/authorize.js +8 -0
  19. package/dist/auth/defaults/authorize.js.map +1 -0
  20. package/dist/auth/defaults/authorizeAdvanced.d.ts +2 -0
  21. package/dist/auth/defaults/authorizeAdvanced.js +8 -0
  22. package/dist/auth/defaults/authorizeAdvanced.js.map +1 -0
  23. package/dist/auth/defaults/index.d.ts +2 -0
  24. package/dist/auth/defaults/index.js +19 -0
  25. package/dist/auth/defaults/index.js.map +1 -0
  26. package/dist/auth/index.d.ts +10 -0
  27. package/dist/auth/index.js +23 -0
  28. package/dist/auth/index.js.map +1 -0
  29. package/dist/closeListener.d.ts +0 -0
  30. package/dist/closeListener.js +0 -0
  31. package/dist/closeListener.js.map +0 -0
  32. package/dist/error.d.ts +34 -0
  33. package/dist/error.js +107 -0
  34. package/dist/error.js.map +1 -0
  35. package/dist/findPrefix.d.ts +0 -0
  36. package/dist/findPrefix.js +0 -0
  37. package/dist/findPrefix.js.map +0 -0
  38. package/dist/functions/index.d.ts +31 -0
  39. package/dist/functions/index.js +200 -0
  40. package/dist/functions/index.js.map +1 -0
  41. package/dist/functions/timeout.d.ts +3 -0
  42. package/dist/functions/timeout.js +23 -0
  43. package/dist/functions/timeout.js.map +1 -0
  44. package/dist/getFromConfig.d.ts +0 -0
  45. package/dist/getFromConfig.js +0 -0
  46. package/dist/getFromConfig.js.map +0 -0
  47. package/dist/handlers/authorize.d.ts +0 -0
  48. package/dist/handlers/authorize.js +0 -0
  49. package/dist/handlers/authorize.js.map +0 -0
  50. package/dist/handlers/bulkUpdate/index.d.ts +0 -0
  51. package/dist/handlers/bulkUpdate/index.js +0 -0
  52. package/dist/handlers/bulkUpdate/index.js.map +0 -0
  53. package/dist/handlers/configuration/index.d.ts +0 -0
  54. package/dist/handlers/configuration/index.js +0 -0
  55. package/dist/handlers/configuration/index.js.map +0 -0
  56. package/dist/handlers/configuration/observable/index.d.ts +0 -0
  57. package/dist/handlers/configuration/observable/index.js +0 -0
  58. package/dist/handlers/configuration/observable/index.js.map +0 -0
  59. package/dist/handlers/configure/index.d.ts +0 -0
  60. package/dist/handlers/configure/index.js +0 -0
  61. package/dist/handlers/configure/index.js.map +0 -0
  62. package/dist/handlers/copy/index.d.ts +0 -0
  63. package/dist/handlers/copy/index.js +0 -0
  64. package/dist/handlers/copy/index.js.map +0 -0
  65. package/dist/handlers/delete/index.d.ts +0 -0
  66. package/dist/handlers/delete/index.js +0 -0
  67. package/dist/handlers/delete/index.js.map +0 -0
  68. package/dist/handlers/digest/index.d.ts +0 -0
  69. package/dist/handlers/digest/index.js +0 -0
  70. package/dist/handlers/digest/index.js.map +0 -0
  71. package/dist/handlers/functions/call.d.ts +0 -0
  72. package/dist/handlers/functions/call.js +0 -0
  73. package/dist/handlers/functions/call.js.map +0 -0
  74. package/dist/handlers/functions/observable/Observable.d.ts +0 -0
  75. package/dist/handlers/functions/observable/Observable.js +0 -0
  76. package/dist/handlers/functions/observable/Observable.js.map +0 -0
  77. package/dist/handlers/functions/observable/SharedObservable.d.ts +0 -0
  78. package/dist/handlers/functions/observable/SharedObservable.js +0 -0
  79. package/dist/handlers/functions/observable/SharedObservable.js.map +0 -0
  80. package/dist/handlers/functions/observable/index.d.ts +0 -0
  81. package/dist/handlers/functions/observable/index.js +0 -0
  82. package/dist/handlers/functions/observable/index.js.map +0 -0
  83. package/dist/handlers/get/index.d.ts +0 -0
  84. package/dist/handlers/get/index.js +0 -0
  85. package/dist/handlers/get/index.js.map +0 -0
  86. package/dist/handlers/getConfig/index.d.ts +0 -0
  87. package/dist/handlers/getConfig/index.js +0 -0
  88. package/dist/handlers/getConfig/index.js.map +0 -0
  89. package/dist/handlers/handleRequests.d.ts +0 -0
  90. package/dist/handlers/handleRequests.js +0 -0
  91. package/dist/handlers/handleRequests.js.map +0 -0
  92. package/dist/handlers/index.d.ts +0 -0
  93. package/dist/handlers/index.js +0 -0
  94. package/dist/handlers/index.js.map +0 -0
  95. package/dist/handlers/messageParser.d.ts +0 -0
  96. package/dist/handlers/messageParser.js +0 -0
  97. package/dist/handlers/messageParser.js.map +0 -0
  98. package/dist/handlers/removeField/index.d.ts +0 -0
  99. package/dist/handlers/removeField/index.js +0 -0
  100. package/dist/handlers/removeField/index.js.map +0 -0
  101. package/dist/handlers/removeType/index.d.ts +0 -0
  102. package/dist/handlers/removeType/index.js +0 -0
  103. package/dist/handlers/removeType/index.js.map +0 -0
  104. package/dist/handlers/rest/file/DataStream.d.ts +0 -0
  105. package/dist/handlers/rest/file/DataStream.js +0 -0
  106. package/dist/handlers/rest/file/DataStream.js.map +0 -0
  107. package/dist/handlers/rest/file/formStream.d.ts +0 -0
  108. package/dist/handlers/rest/file/formStream.js +0 -0
  109. package/dist/handlers/rest/file/formStream.js.map +0 -0
  110. package/dist/handlers/rest/file/getExtenstion.d.ts +0 -0
  111. package/dist/handlers/rest/file/getExtenstion.js +0 -0
  112. package/dist/handlers/rest/file/getExtenstion.js.map +0 -0
  113. package/dist/handlers/rest/file/index.d.ts +0 -0
  114. package/dist/handlers/rest/file/index.js +0 -0
  115. package/dist/handlers/rest/file/index.js.map +0 -0
  116. package/dist/handlers/rest/file/storeFile.d.ts +0 -0
  117. package/dist/handlers/rest/file/storeFile.js +0 -0
  118. package/dist/handlers/rest/file/storeFile.js.map +0 -0
  119. package/dist/handlers/rest/file/stream.d.ts +0 -0
  120. package/dist/handlers/rest/file/stream.js +0 -0
  121. package/dist/handlers/rest/file/stream.js.map +0 -0
  122. package/dist/handlers/rest/file/types.d.ts +0 -0
  123. package/dist/handlers/rest/file/types.js +0 -0
  124. package/dist/handlers/rest/file/types.js.map +0 -0
  125. package/dist/handlers/rest/getReqMessage.d.ts +0 -0
  126. package/dist/handlers/rest/getReqMessage.js +0 -0
  127. package/dist/handlers/rest/getReqMessage.js.map +0 -0
  128. package/dist/handlers/rest/index.d.ts +0 -0
  129. package/dist/handlers/rest/index.js +0 -0
  130. package/dist/handlers/rest/index.js.map +0 -0
  131. package/dist/handlers/rest/invalidReq.d.ts +0 -0
  132. package/dist/handlers/rest/invalidReq.js +0 -0
  133. package/dist/handlers/rest/invalidReq.js.map +0 -0
  134. package/dist/handlers/rest/parseResponse.d.ts +0 -0
  135. package/dist/handlers/rest/parseResponse.js +0 -0
  136. package/dist/handlers/rest/parseResponse.js.map +0 -0
  137. package/dist/handlers/rest/playground/index.d.ts +0 -0
  138. package/dist/handlers/rest/playground/index.js +0 -0
  139. package/dist/handlers/rest/playground/index.js.map +0 -0
  140. package/dist/handlers/rest/readBody.d.ts +0 -0
  141. package/dist/handlers/rest/readBody.js +0 -0
  142. package/dist/handlers/rest/readBody.js.map +0 -0
  143. package/dist/handlers/set/index.d.ts +0 -0
  144. package/dist/handlers/set/index.js +0 -0
  145. package/dist/handlers/set/index.js.map +0 -0
  146. package/dist/handlers/subscription/index.d.ts +0 -0
  147. package/dist/handlers/subscription/index.js +0 -0
  148. package/dist/handlers/subscription/index.js.map +0 -0
  149. package/dist/handlers/token.d.ts +0 -0
  150. package/dist/handlers/token.js +0 -0
  151. package/dist/handlers/token.js.map +0 -0
  152. package/dist/handlers/track/index.d.ts +0 -0
  153. package/dist/handlers/track/index.js +0 -0
  154. package/dist/handlers/track/index.js.map +0 -0
  155. package/dist/handlers/userAuth/index.d.ts +0 -0
  156. package/dist/handlers/userAuth/index.js +0 -0
  157. package/dist/handlers/userAuth/index.js.map +0 -0
  158. package/dist/index.d.ts +0 -0
  159. package/dist/index.js +0 -0
  160. package/dist/index.js.map +0 -0
  161. package/dist/network/http/authorize.d.ts +3 -0
  162. package/dist/network/http/authorize.js +30 -0
  163. package/dist/network/http/authorize.js.map +1 -0
  164. package/dist/network/http/compress.d.ts +6 -0
  165. package/dist/network/http/compress.js +47 -0
  166. package/dist/network/http/compress.js.map +1 -0
  167. package/dist/network/http/end.d.ts +4 -0
  168. package/dist/network/http/end.js +19 -0
  169. package/dist/network/http/end.js.map +1 -0
  170. package/dist/network/http/function/index.d.ts +3 -0
  171. package/dist/network/http/function/index.js +82 -0
  172. package/dist/network/http/function/index.js.map +1 -0
  173. package/dist/network/http/function/stream/DataStream.d.ts +7 -0
  174. package/dist/network/http/function/stream/DataStream.js +17 -0
  175. package/dist/network/http/function/stream/DataStream.js.map +1 -0
  176. package/dist/network/http/function/stream/index.d.ts +8 -0
  177. package/dist/network/http/function/stream/index.js +93 -0
  178. package/dist/network/http/function/stream/index.js.map +1 -0
  179. package/dist/network/http/function/stream/multipartFormStream.d.ts +0 -0
  180. package/dist/network/http/function/stream/multipartFormStream.js +194 -0
  181. package/dist/network/http/function/stream/multipartFormStream.js.map +1 -0
  182. package/dist/network/http/function/stream/stream.d.ts +4 -0
  183. package/dist/network/http/function/stream/stream.js +49 -0
  184. package/dist/network/http/function/stream/stream.js.map +1 -0
  185. package/dist/network/http/function.d.ts +3 -0
  186. package/dist/network/http/function.js +46 -0
  187. package/dist/network/http/function.js.map +1 -0
  188. package/dist/network/http/get.d.ts +3 -0
  189. package/dist/network/http/get.js +143 -0
  190. package/dist/network/http/get.js.map +1 -0
  191. package/dist/network/http/index.d.ts +3 -0
  192. package/dist/network/http/index.js +125 -0
  193. package/dist/network/http/index.js.map +1 -0
  194. package/dist/network/http/readBody.d.ts +2 -0
  195. package/dist/network/http/readBody.js +134 -0
  196. package/dist/network/http/readBody.js.map +1 -0
  197. package/dist/network/http/readPostData.d.ts +3 -0
  198. package/dist/network/http/readPostData.js +50 -0
  199. package/dist/network/http/readPostData.js.map +1 -0
  200. package/dist/network/http/send.d.ts +6 -0
  201. package/dist/network/http/send.js +65 -0
  202. package/dist/network/http/send.js.map +1 -0
  203. package/dist/network/http/sendError.d.ts +4 -0
  204. package/dist/network/http/sendError.js +27 -0
  205. package/dist/network/http/sendError.js.map +1 -0
  206. package/dist/network/http/stream/DataStream.d.ts +7 -0
  207. package/dist/network/http/stream/DataStream.js +17 -0
  208. package/dist/network/http/stream/DataStream.js.map +1 -0
  209. package/dist/network/http/stream/formStream.d.ts +4 -0
  210. package/dist/network/http/stream/formStream.js +184 -0
  211. package/dist/network/http/stream/formStream.js.map +1 -0
  212. package/dist/network/http/stream/getExtenstion.d.ts +2 -0
  213. package/dist/network/http/stream/getExtenstion.js +22 -0
  214. package/dist/network/http/stream/getExtenstion.js.map +1 -0
  215. package/dist/network/http/stream/index.d.ts +9 -0
  216. package/dist/network/http/stream/index.js +42 -0
  217. package/dist/network/http/stream/index.js.map +1 -0
  218. package/dist/network/http/stream/multipartFormStream.d.ts +0 -0
  219. package/dist/network/http/stream/multipartFormStream.js +194 -0
  220. package/dist/network/http/stream/multipartFormStream.js.map +1 -0
  221. package/dist/network/http/stream/storeFile.d.ts +5 -0
  222. package/dist/network/http/stream/storeFile.js +30 -0
  223. package/dist/network/http/stream/storeFile.js.map +1 -0
  224. package/dist/network/http/stream/stream.d.ts +4 -0
  225. package/dist/network/http/stream/stream.js +49 -0
  226. package/dist/network/http/stream/stream.js.map +1 -0
  227. package/dist/network/http/stream/types.d.ts +9 -0
  228. package/dist/network/http/stream/types.js +3 -0
  229. package/dist/network/http/stream/types.js.map +1 -0
  230. package/dist/network/http/streamFunction/DataStream.d.ts +7 -0
  231. package/dist/network/http/streamFunction/DataStream.js +17 -0
  232. package/dist/network/http/streamFunction/DataStream.js.map +1 -0
  233. package/dist/network/http/streamFunction/endStreamRequest.d.ts +3 -0
  234. package/dist/network/http/streamFunction/endStreamRequest.js +20 -0
  235. package/dist/network/http/streamFunction/endStreamRequest.js.map +1 -0
  236. package/dist/network/http/streamFunction/getExtension.d.ts +2 -0
  237. package/dist/network/http/streamFunction/getExtension.js +22 -0
  238. package/dist/network/http/streamFunction/getExtension.js.map +1 -0
  239. package/dist/network/http/streamFunction/index.d.ts +3 -0
  240. package/dist/network/http/streamFunction/index.js +71 -0
  241. package/dist/network/http/streamFunction/index.js.map +1 -0
  242. package/dist/network/http/streamFunction/multipartFormStream.d.ts +5 -0
  243. package/dist/network/http/streamFunction/multipartFormStream.js +189 -0
  244. package/dist/network/http/streamFunction/multipartFormStream.js.map +1 -0
  245. package/dist/network/http/streamFunction/multipartStream.d.ts +13 -0
  246. package/dist/network/http/streamFunction/multipartStream.js +166 -0
  247. package/dist/network/http/streamFunction/multipartStream.js.map +1 -0
  248. package/dist/network/http/streamFunction/stream.d.ts +4 -0
  249. package/dist/network/http/streamFunction/stream.js +106 -0
  250. package/dist/network/http/streamFunction/stream.js.map +1 -0
  251. package/dist/network/index.d.ts +4 -0
  252. package/dist/network/index.js +84 -0
  253. package/dist/network/index.js.map +1 -0
  254. package/dist/network/message/auth.d.ts +4 -0
  255. package/dist/network/message/auth.js +35 -0
  256. package/dist/network/message/auth.js.map +1 -0
  257. package/dist/network/message/function.d.ts +3 -0
  258. package/dist/network/message/function.js +70 -0
  259. package/dist/network/message/function.js.map +1 -0
  260. package/dist/network/message/get.d.ts +3 -0
  261. package/dist/network/message/get.js +111 -0
  262. package/dist/network/message/get.js.map +1 -0
  263. package/dist/network/message/index.d.ts +3 -0
  264. package/dist/network/message/index.js +61 -0
  265. package/dist/network/message/index.js.map +1 -0
  266. package/dist/network/message/observable.d.ts +5 -0
  267. package/dist/network/message/observable.js +105 -0
  268. package/dist/network/message/observable.js.map +1 -0
  269. package/dist/network/message/send.d.ts +3 -0
  270. package/dist/network/message/send.js +11 -0
  271. package/dist/network/message/send.js.map +1 -0
  272. package/dist/network/rest/function.d.ts +3 -0
  273. package/dist/network/rest/function.js +85 -0
  274. package/dist/network/rest/function.js.map +1 -0
  275. package/dist/network/rest/index.d.ts +3 -0
  276. package/dist/network/rest/index.js +65 -0
  277. package/dist/network/rest/index.js.map +1 -0
  278. package/dist/network/upgrade.d.ts +4 -0
  279. package/dist/network/upgrade.js +48 -0
  280. package/dist/network/upgrade.js.map +1 -0
  281. package/dist/observable/index.d.ts +8 -0
  282. package/dist/observable/index.js +224 -0
  283. package/dist/observable/index.js.map +1 -0
  284. package/dist/openListener.d.ts +0 -0
  285. package/dist/openListener.js +0 -0
  286. package/dist/openListener.js.map +0 -0
  287. package/dist/protocol.d.ts +18 -0
  288. package/dist/protocol.js +206 -0
  289. package/dist/protocol.js.map +1 -0
  290. package/dist/secrets.d.ts +0 -0
  291. package/dist/secrets.js +0 -0
  292. package/dist/secrets.js.map +0 -0
  293. package/dist/server.d.ts +28 -0
  294. package/dist/server.js +96 -0
  295. package/dist/server.js.map +1 -0
  296. package/dist/types.d.ts +0 -0
  297. package/dist/types.js +0 -0
  298. package/dist/types.js.map +0 -0
  299. package/dist/upgradeListener.d.ts +0 -0
  300. package/dist/upgradeListener.js +0 -0
  301. package/dist/upgradeListener.js.map +0 -0
  302. package/dist/workers/index.d.ts +0 -0
  303. package/dist/workers/index.js +0 -0
  304. package/dist/workers/index.js.map +0 -0
  305. package/dist/workers/workerCode.d.ts +0 -0
  306. package/dist/workers/workerCode.js +0 -0
  307. package/dist/workers/workerCode.js.map +0 -0
  308. package/package.json +2 -2
@@ -0,0 +1,4 @@
1
+ import type { ServerOptions } from '../types';
2
+ import type { BasedServer } from '../server';
3
+ declare const _default: (server: BasedServer, { key, cert, port }: ServerOptions) => void;
4
+ export default _default;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const uws_1 = __importDefault(require("@based/uws"));
7
+ const upgrade_1 = require("./upgrade");
8
+ const message_1 = require("./message");
9
+ const observable_1 = require("../observable");
10
+ const http_1 = require("./http");
11
+ // ----------------- mem test code -------------------
12
+ // let cl = 0
13
+ // const genLargeMemBlock = (): string => {
14
+ // ++cl
15
+ // let str = ''
16
+ // for (let i = 0; i < 100000; i++) {
17
+ // str += Math.random() * 99999 + ' xxxx'
18
+ // }
19
+ // return str
20
+ // }
21
+ // let cnt = 0
22
+ // setInterval(() => {
23
+ // ++cnt
24
+ // console.info('Amount of clients', cl, 'after', cnt, 'seconds')
25
+ // }, 1e3)
26
+ // -----------------------------------------------------
27
+ exports.default = (server, { key, cert, port }) => {
28
+ const app = key && cert
29
+ ? uws_1.default.SSLApp({
30
+ key_file_name: key,
31
+ cert_file_name: cert,
32
+ ssl_prefer_low_memory_usage: true,
33
+ })
34
+ : uws_1.default.App();
35
+ if (port) {
36
+ server.port = port;
37
+ }
38
+ app
39
+ .ws('/*', {
40
+ maxPayloadLength: 1024 * 1024 * 5,
41
+ idleTimeout: 100,
42
+ maxBackpressure: 1024,
43
+ // compression: uws.SHARED_COMPRESSOR,
44
+ upgrade: server.auth?.config?.authorizeConnection
45
+ ? (res, req, ctx) => {
46
+ (0, upgrade_1.upgradeAuthorize)(server.auth.config.authorizeConnection, res, req, ctx);
47
+ }
48
+ : upgrade_1.upgrade,
49
+ message: (ws, data, isBinary) => {
50
+ (0, message_1.message)(server, ws.c, data, isBinary);
51
+ },
52
+ open: (ws) => {
53
+ if (ws) {
54
+ // ws.bla = genLargeMemBlock()
55
+ const client = { ws };
56
+ ws.c = client;
57
+ }
58
+ },
59
+ close: (ws) => {
60
+ // cl--
61
+ ws.obs.forEach((id) => {
62
+ (0, observable_1.unsubscribeIgnoreClient)(server, id, ws.c);
63
+ });
64
+ // Looks really ugly but same impact on memory and GC as using the ws directly
65
+ // and better for dc's when functions etc are in progress
66
+ ws.c.ws = null;
67
+ ws.c = null;
68
+ },
69
+ drain: () => {
70
+ // console.info('drain')
71
+ // lets handle drain efficiently (or more efficiently at least)
72
+ // call client.drain can be much more efficient
73
+ // if (ws.client && ws.client.backpressureQueue) {
74
+ // ws.client.drain()
75
+ // }
76
+ },
77
+ })
78
+ // REST
79
+ .get('/*', (res, req) => (0, http_1.httpHandler)(server, req, res))
80
+ .post('/*', (res, req) => (0, http_1.httpHandler)(server, req, res))
81
+ .options('/*', (res, req) => (0, http_1.httpHandler)(server, req, res));
82
+ server.uwsApp = app;
83
+ };
84
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/network/index.ts"],"names":[],"mappings":";;;;;AAEA,qDAA4B;AAC5B,uCAAqD;AACrD,uCAAmC;AACnC,8CAAuD;AACvD,iCAAoC;AAEpC,sDAAsD;AACtD,aAAa;AACb,2CAA2C;AAC3C,SAAS;AACT,iBAAiB;AACjB,uCAAuC;AACvC,6CAA6C;AAC7C,MAAM;AACN,eAAe;AACf,IAAI;AACJ,cAAc;AACd,sBAAsB;AACtB,UAAU;AACV,mEAAmE;AACnE,UAAU;AACV,wDAAwD;AAExD,kBAAe,CAAC,MAAmB,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAiB,EAAE,EAAE;IACzE,MAAM,GAAG,GACP,GAAG,IAAI,IAAI;QACT,CAAC,CAAC,aAAG,CAAC,MAAM,CAAC;YACT,aAAa,EAAE,GAAG;YAClB,cAAc,EAAE,IAAI;YACpB,2BAA2B,EAAE,IAAI;SAClC,CAAC;QACJ,CAAC,CAAC,aAAG,CAAC,GAAG,EAAE,CAAA;IAEf,IAAI,IAAI,EAAE;QACR,MAAM,CAAC,IAAI,GAAG,IAAI,CAAA;KACnB;IAED,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kD;YAClD,sBAAsB;YACtB,IAAI;QACN,CAAC;KACF,CAAC;QACF,OAAO;SACN,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,IAAA,kBAAW,EAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;SACtD,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,IAAA,kBAAW,EAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;SACvD,OAAO,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,IAAA,kBAAW,EAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;IAE7D,MAAM,CAAC,MAAM,GAAG,GAAG,CAAA;AACrB,CAAC,CAAA"}
@@ -0,0 +1,4 @@
1
+ import { BasedServer } from '../../server';
2
+ import { WebsocketClient } from '../../types';
3
+ export declare type AuthState = any;
4
+ export declare const authMessage: (arr: Uint8Array, start: number, len: number, isDeflate: boolean, client: WebsocketClient, server: BasedServer) => boolean;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.authMessage = void 0;
4
+ const protocol_1 = require("../../protocol");
5
+ const observable_1 = require("./observable");
6
+ const authMessage = (arr, start, len, isDeflate, client,
7
+ // eslint-disable-next-line
8
+ server) => {
9
+ // | 4 header | * payload |
10
+ const authPayload = (0, protocol_1.decodePayload)(new Uint8Array(arr.slice(start + 4, start + len)), isDeflate);
11
+ // authorizeHandshake here
12
+ let authState;
13
+ try {
14
+ // this has to be part of the handshake
15
+ authState = JSON.parse(authPayload);
16
+ }
17
+ catch (err) {
18
+ console.error("can't decode auth payload", err);
19
+ }
20
+ if (client.ws) {
21
+ client.ws.authState = authState;
22
+ if (client.ws.unauthorizedObs.size) {
23
+ client.ws.unauthorizedObs.forEach((obs) => {
24
+ const { id, name, checksum, payload } = obs;
25
+ (0, observable_1.enableSubscribe)(server, client, id, checksum, name, payload);
26
+ });
27
+ //
28
+ client.ws.unauthorizedObs.clear();
29
+ }
30
+ client.ws.send((0, protocol_1.encodeAuthResponse)((0, protocol_1.valueToBuffer)(true)), true, false);
31
+ }
32
+ return true;
33
+ };
34
+ exports.authMessage = authMessage;
35
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/network/message/auth.ts"],"names":[],"mappings":";;;AAAA,6CAIuB;AAGvB,6CAA8C;AAIvC,MAAM,WAAW,GAAG,CACzB,GAAe,EACf,KAAa,EACb,GAAW,EACX,SAAkB,EAClB,MAAuB;AACvB,2BAA2B;AAC3B,MAAmB,EACV,EAAE;IACX,2BAA2B;IAE3B,MAAM,WAAW,GAAG,IAAA,wBAAa,EAC/B,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,GAAG,CAAC,CAAC,EACjD,SAAS,CACV,CAAA;IAED,0BAA0B;IAE1B,IAAI,SAAoB,CAAA;IACxB,IAAI;QACF,uCAAuC;QACvC,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;KACpC;IAAC,OAAO,GAAG,EAAE;QACZ,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,GAAG,CAAC,CAAA;KAChD;IACD,IAAI,MAAM,CAAC,EAAE,EAAE;QACb,MAAM,CAAC,EAAE,CAAC,SAAS,GAAG,SAAS,CAAA;QAE/B,IAAI,MAAM,CAAC,EAAE,CAAC,eAAe,CAAC,IAAI,EAAE;YAClC,MAAM,CAAC,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;gBACxC,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,GAAG,CAAA;gBAC3C,IAAA,4BAAe,EAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;YAC9D,CAAC,CAAC,CAAA;YACF,EAAE;YACF,MAAM,CAAC,EAAE,CAAC,eAAe,CAAC,KAAK,EAAE,CAAA;SAClC;QAED,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,IAAA,6BAAkB,EAAC,IAAA,wBAAa,EAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;KACrE;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAzCY,QAAA,WAAW,eAyCvB"}
@@ -0,0 +1,3 @@
1
+ import { BasedServer } from '../../server';
2
+ import { WebsocketClient } from '../../types';
3
+ export declare const functionMessage: (arr: Uint8Array, start: number, len: number, isDeflate: boolean, client: WebsocketClient, server: BasedServer) => boolean;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.functionMessage = void 0;
4
+ const functions_1 = require("../../functions");
5
+ const protocol_1 = require("../../protocol");
6
+ const error_1 = require("../../error");
7
+ const send_1 = require("./send");
8
+ const functionMessage = (arr, start, len, isDeflate, client, server) => {
9
+ // | 4 header | 3 id | 1 name length | * name | * payload |
10
+ const reqId = (0, protocol_1.readUint8)(arr, start + 4, 3);
11
+ const nameLen = arr[start + 7];
12
+ const name = (0, protocol_1.decodeName)(arr, start + 8, start + 8 + nameLen);
13
+ const payload = (0, protocol_1.decodePayload)(new Uint8Array(arr.slice(start + 8 + nameLen, start + len)), isDeflate);
14
+ if (!name || !reqId) {
15
+ return false;
16
+ }
17
+ const route = server.functions.route(name);
18
+ if (!route || route.observable === true || route.stream === true) {
19
+ // stream not with ws for now...
20
+ return false;
21
+ }
22
+ server.auth.config
23
+ .authorize(server, client, name, payload)
24
+ .then((ok) => {
25
+ if (!ok) {
26
+ (0, send_1.sendError)(client, error_1.BasedErrorCode.AuthorizeRejectedError, {
27
+ requestId: reqId,
28
+ });
29
+ return false;
30
+ }
31
+ server.functions
32
+ .install(name)
33
+ .then((spec) => {
34
+ if (spec && !(0, functions_1.isObservableFunctionSpec)(spec)) {
35
+ spec
36
+ .function(payload, client)
37
+ .then((v) => {
38
+ client.ws?.send((0, protocol_1.encodeFunctionResponse)(reqId, (0, protocol_1.valueToBuffer)(v)), true, false);
39
+ })
40
+ .catch((err) => {
41
+ (0, send_1.sendError)(client, error_1.BasedErrorCode.FunctionError, {
42
+ requestId: reqId,
43
+ err,
44
+ });
45
+ });
46
+ }
47
+ else {
48
+ (0, send_1.sendError)(client, error_1.BasedErrorCode.FunctionNotFound, {
49
+ requestId: reqId,
50
+ });
51
+ }
52
+ })
53
+ .catch((err) => {
54
+ (0, send_1.sendError)(client, error_1.BasedErrorCode.FunctionNotFound, {
55
+ requestId: reqId,
56
+ err,
57
+ });
58
+ });
59
+ })
60
+ .catch((err) => {
61
+ (0, send_1.sendError)(client, error_1.BasedErrorCode.AuthorizeFunctionError, {
62
+ requestId: reqId,
63
+ err,
64
+ });
65
+ return false;
66
+ });
67
+ return true;
68
+ };
69
+ exports.functionMessage = functionMessage;
70
+ //# sourceMappingURL=function.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function.js","sourceRoot":"","sources":["../../../src/network/message/function.ts"],"names":[],"mappings":";;;AAAA,+CAA0D;AAC1D,6CAMuB;AAEvB,uCAA4C;AAC5C,iCAAkC;AAG3B,MAAM,eAAe,GAAG,CAC7B,GAAe,EACf,KAAa,EACb,GAAW,EACX,SAAkB,EAClB,MAAuB,EACvB,MAAmB,EACV,EAAE;IACX,2DAA2D;IAE3D,MAAM,KAAK,GAAG,IAAA,oBAAS,EAAC,GAAG,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA;IAC1C,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAA;IAC9B,MAAM,IAAI,GAAG,IAAA,qBAAU,EAAC,GAAG,EAAE,KAAK,GAAG,CA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CACN,CAAA;gBACH,CAAC,CAAC;qBACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;oBACb,IAAA,gBAAS,EAAC,MAAM,EAAE,sBAAc,CAAC,aAAa,EAAE;wBAC9C,SAAS,EAAE,KAAK;wBAChB,GAAG;qBACJ,CAAC,CAAA;gBACJ,CAAC,CAAC,CAAA;aACL;iBAAM;gBACL,IAAA,gBAAS,EAAC,MAAM,EAAE,sBAAc,CAAC,gBAAgB,EAAE;oBACjD,SAAS,EAAE,KAAK;iBACjB,CAAC,CAAA;aACH;QACH,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACb,IAAA,gBAAS,EAAC,MAAM,EAAE,sBAAc,CAAC,gBAAgB,EAAE;gBACjD,SAAS,EAAE,KAAK;gBAChB,GAAG;aACJ,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACN,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACb,IAAA,gBAAS,EAAC,MAAM,EAAE,sBAAc,CAAC,sBAAsB,EAAE;YACvD,SAAS,EAAE,KAAK;YAChB,GAAG;SACJ,CAAC,CAAA;QACF,OAAO,KAAK,CAAA;IACd,CAAC,CAAC,CAAA;IAEJ,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAhFY,QAAA,eAAe,mBAgF3B"}
@@ -0,0 +1,3 @@
1
+ import { BasedServer } from '../../server';
2
+ import { WebsocketClient } from '../../types';
3
+ export declare const getMessage: (arr: Uint8Array, start: number, len: number, isDeflate: boolean, client: WebsocketClient, server: BasedServer) => boolean;
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMessage = void 0;
4
+ const functions_1 = require("../../functions");
5
+ const protocol_1 = require("../../protocol");
6
+ const observable_1 = require("../../observable");
7
+ const error_1 = require("../../error");
8
+ const send_1 = require("./send");
9
+ const sendGetData = (server, id, obs, checksum, client) => {
10
+ if (!client.ws) {
11
+ return;
12
+ }
13
+ if (checksum === 0) {
14
+ client.ws.send(obs.cache, true, false);
15
+ }
16
+ else if (checksum === obs.checksum) {
17
+ client.ws.send((0, protocol_1.encodeGetResponse)(id), true, false);
18
+ }
19
+ else if (obs.diffCache && obs.previousChecksum === checksum) {
20
+ client.ws.send(obs.diffCache, true, false);
21
+ }
22
+ else {
23
+ client.ws.send(obs.cache, true, false);
24
+ }
25
+ if (obs.clients.size === 0) {
26
+ (0, observable_1.destroy)(server, id);
27
+ }
28
+ };
29
+ const getMessage = (arr, start, len, isDeflate, client, server) => {
30
+ // | 4 header | 8 id | 8 checksum | 1 name length | * name | * payload |
31
+ const nameLen = arr[start + 20];
32
+ const id = (0, protocol_1.readUint8)(arr, start + 4, 8);
33
+ const checksum = (0, protocol_1.readUint8)(arr, start + 12, 8);
34
+ const name = (0, protocol_1.decodeName)(arr, start + 21, start + 21 + nameLen);
35
+ if (!name || !id) {
36
+ return false;
37
+ }
38
+ const route = server.functions.route(name);
39
+ if (!route || !route.observable) {
40
+ return false;
41
+ }
42
+ const payload = (0, protocol_1.decodePayload)(new Uint8Array(arr.slice(start + 21 + nameLen, start + len)), isDeflate);
43
+ server.auth.config
44
+ .authorize(server, client, name, payload)
45
+ .then((ok) => {
46
+ if (!client.ws) {
47
+ return false;
48
+ }
49
+ if (!ok) {
50
+ (0, send_1.sendError)(client, error_1.BasedErrorCode.AuthorizeRejectedError, {
51
+ observableId: id,
52
+ });
53
+ return false;
54
+ }
55
+ if (server.activeObservablesById.has(id)) {
56
+ const obs = server.activeObservablesById.get(id);
57
+ if (obs.beingDestroyed) {
58
+ clearTimeout(obs.beingDestroyed);
59
+ obs.beingDestroyed = null;
60
+ }
61
+ if (obs.cache) {
62
+ sendGetData(server, id, obs, checksum, client);
63
+ }
64
+ else {
65
+ if (!obs.onNextData) {
66
+ obs.onNextData = new Set();
67
+ }
68
+ obs.onNextData.add(() => {
69
+ sendGetData(server, id, obs, checksum, client);
70
+ });
71
+ }
72
+ }
73
+ else {
74
+ server.functions
75
+ .install(name)
76
+ .then((spec) => {
77
+ if (spec && (0, functions_1.isObservableFunctionSpec)(spec)) {
78
+ const obs = (0, observable_1.create)(server, name, id, payload);
79
+ if (!client.ws?.obs.has(id)) {
80
+ if (!obs.onNextData) {
81
+ obs.onNextData = new Set();
82
+ }
83
+ obs.onNextData.add(() => {
84
+ sendGetData(server, id, obs, checksum, client);
85
+ });
86
+ }
87
+ }
88
+ else {
89
+ (0, send_1.sendError)(client, error_1.BasedErrorCode.FunctionNotFound, {
90
+ observableId: id,
91
+ });
92
+ }
93
+ })
94
+ .catch((err) => {
95
+ (0, send_1.sendError)(client, error_1.BasedErrorCode.FunctionNotFound, {
96
+ observableId: id,
97
+ err,
98
+ });
99
+ });
100
+ }
101
+ })
102
+ .catch((err) => {
103
+ (0, send_1.sendError)(client, error_1.BasedErrorCode.AuthorizeFunctionError, {
104
+ observableId: id,
105
+ err,
106
+ });
107
+ });
108
+ return true;
109
+ };
110
+ exports.getMessage = getMessage;
111
+ //# sourceMappingURL=get.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get.js","sourceRoot":"","sources":["../../../src/network/message/get.ts"],"names":[],"mappings":";;;AAAA,+CAA0D;AAC1D,6CAKuB;AAEvB,iDAAkD;AAElD,uCAA4C;AAC5C,iCAAkC;AAElC,MAAM,WAAW,GAAG,CAClB,MAAmB,EACnB,EAAU,EACV,GAAqB,EACrB,QAAgB,EAChB,MAAuB,EACvB,EAAE;IACF,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE;QACd,OAAM;KACP;IAED,IAAI,QAAQ,KAAK,CAAC,EAAE;QAClB,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;KACvC;SAAM,IAAI,QAAQ,KAAK,GAAG,CAAC,QAAQ,EAAE;QACpC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,IAAA,4BAAiB,EAAC,EAA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GY,QAAA,UAAU,cAiGtB"}
@@ -0,0 +1,3 @@
1
+ import { BasedServer } from '../../server';
2
+ import { WebsocketClient } from '../../types';
3
+ export declare const message: (server: BasedServer, client: WebsocketClient, msg: ArrayBuffer, isBinary: boolean) => void;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.message = void 0;
4
+ const protocol_1 = require("../../protocol");
5
+ const function_1 = require("./function");
6
+ const observable_1 = require("./observable");
7
+ const auth_1 = require("./auth");
8
+ const get_1 = require("./get");
9
+ const reader = (server, client, arr, start) => {
10
+ const { len, isDeflate, type } = (0, protocol_1.decodeHeader)((0, protocol_1.readUint8)(arr, start, 4));
11
+ const next = len + start;
12
+ // type 0 = function
13
+ if (type === 0 &&
14
+ (0, function_1.functionMessage)(arr, start, len, isDeflate, client, server)) {
15
+ return next;
16
+ }
17
+ // type 1 = subscribe
18
+ if (type === 1 &&
19
+ (0, observable_1.subscribeMessage)(arr, start, len, isDeflate, client, server)) {
20
+ return next;
21
+ }
22
+ // type 2 = unsubscribe
23
+ if (type === 2 && (0, observable_1.unsubscribeMessage)(arr, start, client, server)) {
24
+ return next;
25
+ }
26
+ // type 3 = get
27
+ if (type === 3 && (0, get_1.getMessage)(arr, start, len, isDeflate, client, server)) {
28
+ return next;
29
+ }
30
+ // type 4 = auth
31
+ if (type === 4 && (0, auth_1.authMessage)(arr, start, len, isDeflate, client, server)) {
32
+ return next;
33
+ }
34
+ // emit whats wrong
35
+ console.warn('Unsupported incoming message with type', type);
36
+ };
37
+ const message = (server, client, msg, isBinary) => {
38
+ if (!client.ws) {
39
+ return;
40
+ }
41
+ if (!isBinary) {
42
+ // TODO: add an event here for illegal requests
43
+ client.ws.close();
44
+ return;
45
+ }
46
+ // check if msg if empty (0) then it idle timeout
47
+ const uint8View = new Uint8Array(msg);
48
+ const len = uint8View.length;
49
+ let next = 0;
50
+ while (next < len) {
51
+ const n = reader(server, client, uint8View, next);
52
+ if (n === undefined) {
53
+ // Malformed message close client
54
+ client.ws.close();
55
+ return;
56
+ }
57
+ next = n;
58
+ }
59
+ };
60
+ exports.message = message;
61
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/network/message/index.ts"],"names":[],"mappings":";;;AACA,6CAAwD;AACxD,yCAA4C;AAC5C,6CAAmE;AACnE,iCAAoC;AACpC,+BAAkC;AAGlC,MAAM,MAAM,GAAG,CACb,MAAmB,EACnB,MAAuB,EACvB,GAAe,EACf,KAAa,EACL,EAAE;IACV,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,IAAA,uBAAY,EAAC,IAAA,oBAAS,EAAC,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAA;IACvE,MAAM,IAAI,GAAG,GAAG,GAAG,KAAK,CAAA;IAExB,oBAAoB;IACpB,IACE,IAAI,KAAK,CAAC;QACV,IAAA,0BAAe,EAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAC3D;QACA,OAAO,IAAI,CAAA;KACZ;IAED,qBAAqB;IACrB,IACE,IAAI,KAAK,CAAC;QACV,IAAA,6BAAgB,EAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAC5D;QACA,OAAO,IAAI,CAAA;KACZ;IAED,uBAAuB;IACvB,IAAI,IAAI,KAAK,CAAC,IAAI,IAAA,+BAAkB,EAAC,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;QAChE,OAAO,IAAI,CAAA;KACZ;IAED,eAAe;IACf,IAAI,IAAI,KAAK,CAAC,IAAI,IAAA,gBAAU,EAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;QACxE,OAAO,IAAI,CAAA;KACZ;IAED,gBAAgB;IAChB,IAAI,IAAI,KAAK,CAAC,IAAI,IAAA,kBAAW,EAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;QACzE,OAAO,IAAI,CAAA;KACZ;IAED,mBAAmB;IACnB,OAAO,CAAC,IAAI,CAAC,wCAAwC,EAAE,IAAI,CAAC,CAAA;AAC9D,CAAC,CAAA;AAEM,MAAM,OAAO,GAAG,CACrB,MAAmB,EACnB,MAAuB,EACvB,GAAgB,EAChB,QAAiB,EACjB,EAAE;IACF,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE;QACd,OAAM;KACP;IAED,IAAI,CAAC,QAAQ,EAAE;QACb,+CAA+C;QAC/C,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,CAAA;QACjB,OAAM;KACP;IAED,iDAAiD;IAEjD,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAA;IACrC,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,CAAA;IAC5B,IAAI,IAAI,GAAG,CAAC,CAAA;IACZ,OAAO,IAAI,GAAG,GAAG,EAAE;QACjB,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,CAAA;QACjD,IAAI,CAAC,KAAK,SAAS,EAAE;YACnB,iCAAiC;YACjC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,CAAA;YACjB,OAAM;SACP;QACD,IAAI,GAAG,CAAC,CAAA;KACT;AACH,CAAC,CAAA;AA9BY,QAAA,OAAO,WA8BnB"}
@@ -0,0 +1,5 @@
1
+ import { BasedServer } from '../../server';
2
+ import { WebsocketClient } from '../../types';
3
+ export declare const enableSubscribe: (server: BasedServer, client: WebsocketClient, id: number, checksum: number, name: string, payload: any) => void;
4
+ export declare const subscribeMessage: (arr: Uint8Array, start: number, len: number, isDeflate: boolean, client: WebsocketClient, server: BasedServer) => boolean;
5
+ export declare const unsubscribeMessage: (arr: Uint8Array, start: number, client: WebsocketClient, server: BasedServer) => boolean;
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unsubscribeMessage = exports.subscribeMessage = exports.enableSubscribe = void 0;
4
+ const functions_1 = require("../../functions");
5
+ const protocol_1 = require("../../protocol");
6
+ const observable_1 = require("../../observable");
7
+ const error_1 = require("../../error");
8
+ const send_1 = require("./send");
9
+ const enableSubscribe = (server, client, id, checksum, name, payload) => {
10
+ client.ws.subscribe(String(id));
11
+ client.ws.obs.add(id);
12
+ if (server.activeObservablesById.has(id)) {
13
+ (0, observable_1.subscribe)(server, id, checksum, client);
14
+ }
15
+ else {
16
+ server.functions
17
+ .install(name)
18
+ .then((spec) => {
19
+ if (spec && (0, functions_1.isObservableFunctionSpec)(spec)) {
20
+ const obs = (0, observable_1.create)(server, name, id, payload);
21
+ if (!client.ws?.obs.has(id)) {
22
+ if (obs.clients.size === 0) {
23
+ (0, observable_1.destroy)(server, id);
24
+ }
25
+ }
26
+ else {
27
+ (0, observable_1.subscribe)(server, id, checksum, client);
28
+ }
29
+ }
30
+ else {
31
+ (0, send_1.sendError)(client, error_1.BasedErrorCode.FunctionNotFound, {
32
+ observableId: id,
33
+ });
34
+ }
35
+ })
36
+ .catch((err) => {
37
+ (0, send_1.sendError)(client, error_1.BasedErrorCode.FunctionNotFound, {
38
+ observableId: id,
39
+ err,
40
+ });
41
+ });
42
+ }
43
+ };
44
+ exports.enableSubscribe = enableSubscribe;
45
+ const subscribeMessage = (arr, start, len, isDeflate, client, server) => {
46
+ // | 4 header | 8 id | 8 checksum | 1 name length | * name | * payload |
47
+ const nameLen = arr[start + 20];
48
+ const id = (0, protocol_1.readUint8)(arr, start + 4, 8);
49
+ const checksum = (0, protocol_1.readUint8)(arr, start + 12, 8);
50
+ const name = (0, protocol_1.decodeName)(arr, start + 21, start + 21 + nameLen);
51
+ if (!name || !id) {
52
+ return false;
53
+ }
54
+ const route = server.functions.route(name);
55
+ if (!route || !route.observable) {
56
+ return false;
57
+ }
58
+ if (client.ws?.obs.has(id)) {
59
+ // allready subscribed to this id
60
+ return true;
61
+ }
62
+ const payload = (0, protocol_1.decodePayload)(new Uint8Array(arr.slice(start + 21 + nameLen, start + len)), isDeflate);
63
+ server.auth.config
64
+ .authorize(server, client, name, payload)
65
+ .then((ok) => {
66
+ if (!client.ws) {
67
+ return;
68
+ }
69
+ if (!ok) {
70
+ client.ws.unauthorizedObs.add({ id, checksum, name, payload });
71
+ (0, send_1.sendError)(client, error_1.BasedErrorCode.AuthorizeRejectedError, {
72
+ observableId: id,
73
+ });
74
+ return false;
75
+ }
76
+ (0, exports.enableSubscribe)(server, client, id, checksum, name, payload);
77
+ })
78
+ .catch((err) => {
79
+ (0, send_1.sendError)(client, error_1.BasedErrorCode.AuthorizeFunctionError, {
80
+ observableId: id,
81
+ err,
82
+ });
83
+ (0, observable_1.destroy)(server, id);
84
+ });
85
+ return true;
86
+ };
87
+ exports.subscribeMessage = subscribeMessage;
88
+ const unsubscribeMessage = (arr, start, client, server) => {
89
+ // | 4 header | 8 id |
90
+ const id = (0, protocol_1.readUint8)(arr, start + 4, 8);
91
+ if (!id) {
92
+ return false;
93
+ }
94
+ if (!client.ws) {
95
+ return;
96
+ }
97
+ if (!client.ws.obs.has(id)) {
98
+ return true;
99
+ }
100
+ client.ws.unsubscribe(String(id));
101
+ (0, observable_1.unsubscribe)(server, id, client);
102
+ return true;
103
+ };
104
+ exports.unsubscribeMessage = unsubscribeMessage;
105
+ //# sourceMappingURL=observable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observable.js","sourceRoot":"","sources":["../../../src/network/message/observable.ts"],"names":[],"mappings":";;;AAAA,+CAA0D;AAC1D,6CAAqE;AAErE,iDAA0E;AAC1E,uCAA4C;AAC5C,iCAAkC;AAG3B,MAAM,eAAe,GAAG,CAC7B,MAAmB,EACnB,MAAuB,EACvB,EAAU,EACV,QAA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KACZ;IAED,MAAM,CAAC,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAA;IAEjC,IAAA,wBAAW,EAAC,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,CAAA;IAE/B,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AA3BY,QAAA,kBAAkB,sBA2B9B"}
@@ -0,0 +1,3 @@
1
+ import { BasedErrorCode, CreateErrorProps } from '../../error';
2
+ import { WebsocketClient } from '../../types';
3
+ export declare const sendError: (client: WebsocketClient, basedCode: BasedErrorCode, err?: CreateErrorProps, overrides?: any) => void;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendError = void 0;
4
+ const protocol_1 = require("../../protocol");
5
+ const error_1 = require("../../error");
6
+ const sendError = (client, basedCode, err, overrides) => {
7
+ const errorData = (0, error_1.createError)(basedCode, err);
8
+ client.ws?.send((0, protocol_1.encodeErrorResponse)((0, protocol_1.valueToBuffer)({ ...errorData, ...overrides })), true, false);
9
+ };
10
+ exports.sendError = sendError;
11
+ //# sourceMappingURL=send.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send.js","sourceRoot":"","sources":["../../../src/network/message/send.ts"],"names":[],"mappings":";;;AAAA,6CAAmE;AACnE,uCAA2E;AAGpE,MAAM,SAAS,GAAG,CACvB,MAAuB,EACvB,SAAyB,EACzB,GAAsB,EACtB,SAAe,EACT,EAAE;IACR,MAAM,SAAS,GAAG,IAAA,mBAAW,EAAC,SAAS,EAAE,GAAG,CAAC,CAAA;IAC7C,MAAM,CAAC,EAAE,EAAE,IAAI,CACb,IAAA,8BAAmB,EAAC,IAAA,wBAAa,EAAC,EAAE,GAAG,SAAS,EAAE,GAAG,SAAS,EAAE,CAAC,CAAC,EAClE,IAAI,EACJ,KAAK,CACN,CAAA;AACH,CAAC,CAAA;AAZY,QAAA,SAAS,aAYrB"}
@@ -0,0 +1,3 @@
1
+ import { BasedServer } from '../../server';
2
+ import { RestClient } from '../../types';
3
+ export declare const functionRest: (name: string, payload: any, isDeflate: boolean, client: RestClient, server: BasedServer) => void;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.functionRest = void 0;
4
+ const functions_1 = require("../../functions");
5
+ const functionRest = (name, payload, isDeflate, // lets add this ad well...
6
+ client, server) => {
7
+ console.info('go fn', isDeflate);
8
+ server.functions
9
+ .get(name)
10
+ .then((spec) => {
11
+ if (client.isAborted) {
12
+ return;
13
+ }
14
+ if (spec && !(0, functions_1.isObservableFunctionSpec)(spec)) {
15
+ server.auth.config
16
+ .authorize(server, client, 'function', name, payload)
17
+ .then((ok) => {
18
+ if (client.isAborted) {
19
+ return;
20
+ }
21
+ if (!ok) {
22
+ client.res.writeStatus('401 Unauthorized');
23
+ client.res.end('WRONG AUTH');
24
+ }
25
+ else {
26
+ spec
27
+ .function(payload, client)
28
+ .then(async (result) => {
29
+ if (client.isAborted) {
30
+ return;
31
+ }
32
+ if (spec.customHttpResponse) {
33
+ console.log(client);
34
+ if (await spec.customHttpResponse(result, payload, client)) {
35
+ // if true all is handled
36
+ return;
37
+ }
38
+ if (client.isAborted) {
39
+ return;
40
+ }
41
+ }
42
+ // handle response
43
+ if (typeof result === 'string') {
44
+ client.res.end(result);
45
+ }
46
+ else {
47
+ client.res.end(JSON.stringify(result));
48
+ }
49
+ })
50
+ .catch((err) => {
51
+ if (client.isAborted) {
52
+ return;
53
+ }
54
+ // error handling nice
55
+ console.error('bad fn', client.id, client.isAborted, err);
56
+ client.res.end('wrong!');
57
+ });
58
+ }
59
+ })
60
+ .catch((err) => {
61
+ if (client.isAborted) {
62
+ return;
63
+ }
64
+ console.error('no auth', err);
65
+ client.res.end('wrong!');
66
+ });
67
+ }
68
+ else {
69
+ console.error('No function for you');
70
+ if (client.isAborted) {
71
+ return;
72
+ }
73
+ client.res.end('wrong!');
74
+ }
75
+ })
76
+ .catch((err) => {
77
+ if (client.isAborted) {
78
+ return;
79
+ }
80
+ console.error('fn does not exist', err);
81
+ client.res.end('wrong!');
82
+ });
83
+ };
84
+ exports.functionRest = functionRest;
85
+ //# sourceMappingURL=function.js.map