@based/server 3.4.6 → 4.0.1

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 (269) hide show
  1. package/dist/api/index.d.ts +7 -0
  2. package/dist/api/index.js +173 -0
  3. package/dist/api/index.js.map +1 -0
  4. package/dist/auth/authorize.d.ts +2 -0
  5. package/dist/auth/authorize.js +8 -0
  6. package/dist/auth/authorize.js.map +1 -0
  7. package/dist/auth/dummyAuth.d.ts +2 -0
  8. package/dist/auth/dummyAuth.js +8 -0
  9. package/dist/auth/dummyAuth.js.map +1 -0
  10. package/dist/auth/index.d.ts +15 -0
  11. package/dist/auth/index.js +49 -0
  12. package/dist/auth/index.js.map +1 -0
  13. package/dist/auth/parseAuthState.d.ts +2 -0
  14. package/dist/auth/parseAuthState.js +16 -0
  15. package/dist/auth/parseAuthState.js.map +1 -0
  16. package/dist/auth/types.d.ts +10 -0
  17. package/dist/auth/types.js +3 -0
  18. package/dist/auth/types.js.map +1 -0
  19. package/dist/clientContext.d.ts +0 -0
  20. package/dist/clientContext.js +83 -0
  21. package/dist/clientContext.js.map +1 -0
  22. package/dist/compress.d.ts +5 -0
  23. package/dist/compress.js +52 -0
  24. package/dist/compress.js.map +1 -0
  25. package/dist/context.d.ts +54 -0
  26. package/dist/context.js +18 -0
  27. package/dist/context.js.map +1 -0
  28. package/dist/createSimpleServer.d.ts +22 -0
  29. package/dist/createSimpleServer.js +120 -0
  30. package/dist/createSimpleServer.js.map +1 -0
  31. package/dist/error/errorTypeHandlers.d.ts +6 -0
  32. package/dist/error/errorTypeHandlers.js +130 -0
  33. package/dist/error/errorTypeHandlers.js.map +1 -0
  34. package/dist/error/index.d.ts +5 -0
  35. package/dist/error/index.js +61 -0
  36. package/dist/error/index.js.map +1 -0
  37. package/dist/error/types.d.ts +105 -0
  38. package/dist/error/types.js +30 -0
  39. package/dist/error/types.js.map +1 -0
  40. package/dist/error.d.ts +66 -0
  41. package/dist/error.js +149 -0
  42. package/dist/error.js.map +1 -0
  43. package/dist/functions/index.d.ts +34 -0
  44. package/dist/functions/index.js +210 -0
  45. package/dist/functions/index.js.map +1 -0
  46. package/dist/functions/timeout.d.ts +3 -0
  47. package/dist/functions/timeout.js +23 -0
  48. package/dist/functions/timeout.js.map +1 -0
  49. package/dist/functions/types.d.ts +67 -0
  50. package/dist/functions/types.js +15 -0
  51. package/dist/functions/types.js.map +1 -0
  52. package/dist/functions/workerPool.d.ts +0 -0
  53. package/dist/functions/workerPool.js +5 -0
  54. package/dist/functions/workerPool.js.map +1 -0
  55. package/dist/handlers/configuration/index.d.ts +1 -1
  56. package/dist/incoming/http/authorize.d.ts +4 -0
  57. package/dist/incoming/http/authorize.js +37 -0
  58. package/dist/incoming/http/authorize.js.map +1 -0
  59. package/dist/incoming/http/function.d.ts +4 -0
  60. package/dist/incoming/http/function.js +47 -0
  61. package/dist/incoming/http/function.js.map +1 -0
  62. package/dist/incoming/http/get.d.ts +4 -0
  63. package/dist/incoming/http/get.js +155 -0
  64. package/dist/incoming/http/get.js.map +1 -0
  65. package/dist/incoming/http/index.d.ts +3 -0
  66. package/dist/incoming/http/index.js +134 -0
  67. package/dist/incoming/http/index.js.map +1 -0
  68. package/dist/incoming/http/parseQuery.d.ts +4 -0
  69. package/dist/incoming/http/parseQuery.js +25 -0
  70. package/dist/incoming/http/parseQuery.js.map +1 -0
  71. package/dist/incoming/http/readBody.d.ts +4 -0
  72. package/dist/incoming/http/readBody.js +107 -0
  73. package/dist/incoming/http/readBody.js.map +1 -0
  74. package/dist/incoming/http/streamFunction/DataStream.d.ts +7 -0
  75. package/dist/incoming/http/streamFunction/DataStream.js +19 -0
  76. package/dist/incoming/http/streamFunction/DataStream.js.map +1 -0
  77. package/dist/incoming/http/streamFunction/getExtension.d.ts +2 -0
  78. package/dist/incoming/http/streamFunction/getExtension.js +29 -0
  79. package/dist/incoming/http/streamFunction/getExtension.js.map +1 -0
  80. package/dist/incoming/http/streamFunction/index.d.ts +4 -0
  81. package/dist/incoming/http/streamFunction/index.js +106 -0
  82. package/dist/incoming/http/streamFunction/index.js.map +1 -0
  83. package/dist/incoming/http/streamFunction/multipartStream.d.ts +13 -0
  84. package/dist/incoming/http/streamFunction/multipartStream.js +208 -0
  85. package/dist/incoming/http/streamFunction/multipartStream.js.map +1 -0
  86. package/dist/incoming/http/streamFunction/stream.d.ts +6 -0
  87. package/dist/incoming/http/streamFunction/stream.js +108 -0
  88. package/dist/incoming/http/streamFunction/stream.js.map +1 -0
  89. package/dist/incoming/index.d.ts +3 -0
  90. package/dist/incoming/index.js +84 -0
  91. package/dist/incoming/index.js.map +1 -0
  92. package/dist/incoming/upgrade.d.ts +4 -0
  93. package/dist/incoming/upgrade.js +64 -0
  94. package/dist/incoming/upgrade.js.map +1 -0
  95. package/dist/incoming/ws/auth.d.ts +5 -0
  96. package/dist/incoming/ws/auth.js +40 -0
  97. package/dist/incoming/ws/auth.js.map +1 -0
  98. package/dist/incoming/ws/function.d.ts +3 -0
  99. package/dist/incoming/ws/function.js +107 -0
  100. package/dist/incoming/ws/function.js.map +1 -0
  101. package/dist/incoming/ws/get.d.ts +3 -0
  102. package/dist/incoming/ws/get.js +136 -0
  103. package/dist/incoming/ws/get.js.map +1 -0
  104. package/dist/incoming/ws/index.d.ts +3 -0
  105. package/dist/incoming/ws/index.js +61 -0
  106. package/dist/incoming/ws/index.js.map +1 -0
  107. package/dist/incoming/ws/observable.d.ts +6 -0
  108. package/dist/incoming/ws/observable.js +112 -0
  109. package/dist/incoming/ws/observable.js.map +1 -0
  110. package/dist/index.d.ts +11 -35
  111. package/dist/index.js +19 -196
  112. package/dist/index.js.map +1 -1
  113. package/dist/ip.d.ts +2 -0
  114. package/dist/ip.js +8 -0
  115. package/dist/ip.js.map +1 -0
  116. package/dist/network/http/authorize.d.ts +3 -0
  117. package/dist/network/http/authorize.js +28 -0
  118. package/dist/network/http/authorize.js.map +1 -0
  119. package/dist/network/http/compress.d.ts +6 -0
  120. package/dist/network/http/compress.js +56 -0
  121. package/dist/network/http/compress.js.map +1 -0
  122. package/dist/network/http/end.d.ts +4 -0
  123. package/dist/network/http/end.js +19 -0
  124. package/dist/network/http/end.js.map +1 -0
  125. package/dist/network/http/function.d.ts +3 -0
  126. package/dist/network/http/function.js +47 -0
  127. package/dist/network/http/function.js.map +1 -0
  128. package/dist/network/http/get.d.ts +3 -0
  129. package/dist/network/http/get.js +129 -0
  130. package/dist/network/http/get.js.map +1 -0
  131. package/dist/network/http/index.d.ts +3 -0
  132. package/dist/network/http/index.js +122 -0
  133. package/dist/network/http/index.js.map +1 -0
  134. package/dist/network/http/readBody.d.ts +3 -0
  135. package/dist/network/http/readBody.js +112 -0
  136. package/dist/network/http/readBody.js.map +1 -0
  137. package/dist/network/http/send.d.ts +5 -0
  138. package/dist/network/http/send.js +60 -0
  139. package/dist/network/http/send.js.map +1 -0
  140. package/dist/network/http/streamFunction/DataStream.d.ts +7 -0
  141. package/dist/network/http/streamFunction/DataStream.js +19 -0
  142. package/dist/network/http/streamFunction/DataStream.js.map +1 -0
  143. package/dist/network/http/streamFunction/getExtension.d.ts +2 -0
  144. package/dist/network/http/streamFunction/getExtension.js +29 -0
  145. package/dist/network/http/streamFunction/getExtension.js.map +1 -0
  146. package/dist/network/http/streamFunction/index.d.ts +3 -0
  147. package/dist/network/http/streamFunction/index.js +81 -0
  148. package/dist/network/http/streamFunction/index.js.map +1 -0
  149. package/dist/network/http/streamFunction/multipartStream.d.ts +12 -0
  150. package/dist/network/http/streamFunction/multipartStream.js +208 -0
  151. package/dist/network/http/streamFunction/multipartStream.js.map +1 -0
  152. package/dist/network/http/streamFunction/stream.d.ts +5 -0
  153. package/dist/network/http/streamFunction/stream.js +103 -0
  154. package/dist/network/http/streamFunction/stream.js.map +1 -0
  155. package/dist/network/index.d.ts +4 -0
  156. package/dist/network/index.js +84 -0
  157. package/dist/network/index.js.map +1 -0
  158. package/dist/network/message/auth.d.ts +4 -0
  159. package/dist/network/message/auth.js +32 -0
  160. package/dist/network/message/auth.js.map +1 -0
  161. package/dist/network/message/function.d.ts +3 -0
  162. package/dist/network/message/function.js +67 -0
  163. package/dist/network/message/function.js.map +1 -0
  164. package/dist/network/message/get.d.ts +3 -0
  165. package/dist/network/message/get.js +109 -0
  166. package/dist/network/message/get.js.map +1 -0
  167. package/dist/network/message/index.d.ts +3 -0
  168. package/dist/network/message/index.js +62 -0
  169. package/dist/network/message/index.js.map +1 -0
  170. package/dist/network/message/observable.d.ts +5 -0
  171. package/dist/network/message/observable.js +103 -0
  172. package/dist/network/message/observable.js.map +1 -0
  173. package/dist/network/message/send.d.ts +4 -0
  174. package/dist/network/message/send.js +11 -0
  175. package/dist/network/message/send.js.map +1 -0
  176. package/dist/network/upgrade.d.ts +4 -0
  177. package/dist/network/upgrade.js +49 -0
  178. package/dist/network/upgrade.js.map +1 -0
  179. package/dist/network/worker/get.d.ts +0 -0
  180. package/dist/network/worker/get.js +122 -0
  181. package/dist/network/worker/get.js.map +1 -0
  182. package/dist/network/worker/observable.d.ts +0 -0
  183. package/dist/network/worker/observable.js +120 -0
  184. package/dist/network/worker/observable.js.map +1 -0
  185. package/dist/observable/create.d.ts +3 -0
  186. package/dist/observable/create.js +30 -0
  187. package/dist/observable/create.js.map +1 -0
  188. package/dist/observable/destroy.d.ts +2 -0
  189. package/dist/observable/destroy.js +51 -0
  190. package/dist/observable/destroy.js.map +1 -0
  191. package/dist/observable/error.d.ts +4 -0
  192. package/dist/observable/error.js +17 -0
  193. package/dist/observable/error.js.map +1 -0
  194. package/dist/observable/extendCache.d.ts +2 -0
  195. package/dist/observable/extendCache.js +11 -0
  196. package/dist/observable/extendCache.js.map +1 -0
  197. package/dist/observable/genObservableId.d.ts +1 -0
  198. package/dist/observable/genObservableId.js +9 -0
  199. package/dist/observable/genObservableId.js.map +1 -0
  200. package/dist/observable/get.d.ts +4 -0
  201. package/dist/observable/get.js +15 -0
  202. package/dist/observable/get.js.map +1 -0
  203. package/dist/observable/index.d.ts +11 -0
  204. package/dist/observable/index.js +28 -0
  205. package/dist/observable/index.js.map +1 -0
  206. package/dist/observable/send.d.ts +6 -0
  207. package/dist/observable/send.js +32 -0
  208. package/dist/observable/send.js.map +1 -0
  209. package/dist/observable/start/error.d.ts +3 -0
  210. package/dist/observable/start/error.js +36 -0
  211. package/dist/observable/start/error.js.map +1 -0
  212. package/dist/observable/start/index.d.ts +2 -0
  213. package/dist/observable/start/index.js +46 -0
  214. package/dist/observable/start/index.js.map +1 -0
  215. package/dist/observable/start/update.d.ts +6 -0
  216. package/dist/observable/start/update.js +104 -0
  217. package/dist/observable/start/update.js.map +1 -0
  218. package/dist/observable/subscribe.d.ts +7 -0
  219. package/dist/observable/subscribe.js +54 -0
  220. package/dist/observable/subscribe.js.map +1 -0
  221. package/dist/observable/types.d.ts +26 -0
  222. package/dist/observable/types.js +3 -0
  223. package/dist/observable/types.js.map +1 -0
  224. package/dist/observable/unsub.d.ts +6 -0
  225. package/dist/observable/unsub.js +43 -0
  226. package/dist/observable/unsub.js.map +1 -0
  227. package/dist/observable/verify.d.ts +4 -0
  228. package/dist/observable/verify.js +18 -0
  229. package/dist/observable/verify.js.map +1 -0
  230. package/dist/protocol.d.ts +21 -0
  231. package/dist/protocol.js +233 -0
  232. package/dist/protocol.js.map +1 -0
  233. package/dist/security/index.d.ts +3 -0
  234. package/dist/security/index.js +66 -0
  235. package/dist/security/index.js.map +1 -0
  236. package/dist/security.d.ts +6 -0
  237. package/dist/security.js +95 -0
  238. package/dist/security.js.map +1 -0
  239. package/dist/sendError.d.ts +5 -0
  240. package/dist/sendError.js +42 -0
  241. package/dist/sendError.js.map +1 -0
  242. package/dist/sendHttpResponse.d.ts +4 -0
  243. package/dist/sendHttpResponse.js +53 -0
  244. package/dist/sendHttpResponse.js.map +1 -0
  245. package/dist/server.d.ts +69 -0
  246. package/dist/server.js +113 -0
  247. package/dist/server.js.map +1 -0
  248. package/dist/worker/authorize.d.ts +5 -0
  249. package/dist/worker/authorize.js +15 -0
  250. package/dist/worker/authorize.js.map +1 -0
  251. package/dist/worker/fnMap.d.ts +2 -0
  252. package/dist/worker/fnMap.js +5 -0
  253. package/dist/worker/fnMap.js.map +1 -0
  254. package/dist/worker/functions.d.ts +3 -0
  255. package/dist/worker/functions.js +8 -0
  256. package/dist/worker/functions.js.map +1 -0
  257. package/dist/worker/http/function.d.ts +4 -0
  258. package/dist/worker/http/function.js +75 -0
  259. package/dist/worker/http/function.js.map +1 -0
  260. package/dist/worker/index.d.ts +1 -0
  261. package/dist/worker/index.js +101 -0
  262. package/dist/worker/index.js.map +1 -0
  263. package/dist/worker/observable.d.ts +15 -0
  264. package/dist/worker/observable.js +110 -0
  265. package/dist/worker/observable.js.map +1 -0
  266. package/dist/worker/ws/function.d.ts +3 -0
  267. package/dist/worker/ws/function.js +42 -0
  268. package/dist/worker/ws/function.js.map +1 -0
  269. package/package.json +16 -14
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isObsFunctionSpec = exports.isFunctionSpec = exports.createSimpleServer = void 0;
4
+ const server_1 = require("./server");
5
+ async function createSimpleServer(props, sharedSocket) {
6
+ const { functions, observables } = props;
7
+ const functionStore = {};
8
+ for (const name in functions) {
9
+ if (functions[name]) {
10
+ const fn = functions[name];
11
+ if (isFunctionSpec(fn)) {
12
+ functionStore[name] = {
13
+ function: fn.function,
14
+ path: `/${name}`,
15
+ name,
16
+ observable: false,
17
+ checksum: 1,
18
+ maxPayloadSize: 5e3,
19
+ rateLimitTokens: 1,
20
+ ...fn,
21
+ };
22
+ }
23
+ else {
24
+ functionStore[name] = {
25
+ function: fn,
26
+ path: `/${name}`,
27
+ name,
28
+ observable: false,
29
+ checksum: 1,
30
+ maxPayloadSize: 5e3,
31
+ rateLimitTokens: 1,
32
+ };
33
+ }
34
+ }
35
+ }
36
+ for (const name in observables) {
37
+ if (observables[name]) {
38
+ const fn = observables[name];
39
+ if (isObsFunctionSpec(fn)) {
40
+ functionStore[name] = {
41
+ checksum: 1,
42
+ observable: true,
43
+ function: fn.function,
44
+ path: `/${name}`,
45
+ name,
46
+ maxPayloadSize: 500,
47
+ rateLimitTokens: 5,
48
+ ...fn,
49
+ };
50
+ }
51
+ else {
52
+ functionStore[name] = {
53
+ checksum: 1,
54
+ observable: true,
55
+ function: fn,
56
+ name,
57
+ path: `/${name}`,
58
+ maxPayloadSize: 500,
59
+ rateLimitTokens: 5,
60
+ };
61
+ }
62
+ }
63
+ }
64
+ const properProps = {
65
+ port: props.port,
66
+ auth: props.auth,
67
+ cert: props.cert,
68
+ functions: {
69
+ memCacheTimeout: 3e3,
70
+ idleTimeout: 1e3,
71
+ uninstall: async () => {
72
+ return true;
73
+ },
74
+ install: async ({ name }) => {
75
+ if (functionStore[name]) {
76
+ return functionStore[name];
77
+ }
78
+ else {
79
+ return false;
80
+ }
81
+ },
82
+ route: ({ path, name }) => {
83
+ if (path) {
84
+ for (const name in functionStore) {
85
+ if (functionStore[name].path === path) {
86
+ return functionStore[name];
87
+ }
88
+ }
89
+ }
90
+ if (functionStore[name]) {
91
+ return functionStore[name];
92
+ }
93
+ return false;
94
+ },
95
+ },
96
+ };
97
+ console.info('Server starting with the following functions:');
98
+ for (const name in functionStore) {
99
+ console.info({
100
+ name: functionStore[name].name,
101
+ path: functionStore[name].path,
102
+ observable: functionStore[name].observable,
103
+ });
104
+ }
105
+ const basedServer = new server_1.BasedServer(properProps);
106
+ return props.port ? basedServer.start(props.port, sharedSocket) : basedServer;
107
+ }
108
+ exports.createSimpleServer = createSimpleServer;
109
+ // function simpleFuncToNormal(
110
+ // fn: (payload: any, ctx: Context) => any | Partial<BasedFunctionSpec>
111
+ // ): BasedFunctionSpec {}
112
+ function isFunctionSpec(fn) {
113
+ return 'function' in fn || false;
114
+ }
115
+ exports.isFunctionSpec = isFunctionSpec;
116
+ function isObsFunctionSpec(fn) {
117
+ return 'function' in fn || false;
118
+ }
119
+ exports.isObsFunctionSpec = isObsFunctionSpec;
120
+ //# sourceMappingURL=createSim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a,CAAC,IAAI,CAAC,CAAA;iBAC3B;gBACD,OAAO,KAAK,CAAA;YACd,CAAC;SACF;KACF,CAAA;IAED,OAAO,CAAC,IAAI,CAAC,+CAA+C,CAAC,CAAA;IAC7D,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE;QAChC,OAAO,CAAC,IAAI,CAAC;YACX,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI;YAC9B,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI;YAC9B,UAAU,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,UAAU;SAC3C,CAAC,CAAA;KACH;IAED,MAAM,WAAW,GAAG,IAAI,oBAAW,CAAC,WAAW,CAAC,CAAA;IAChD,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,WAAW,CAAA;AAC/E,CAAC;AAvHD,gDAuHC;AAED,+BAA+B;AAC/B,yEAAyE;AACzE,0BAA0B;AAE1B,SAAgB,cAAc,CAC5B,EAA8C;IAE9C,OAAO,UAAU,IAAI,EAAE,IAAI,KAAK,CAAA;AAClC,CAAC;AAJD,wCAIC;AAED,SAAgB,iBAAiB,CAC/B,EAAkE;IAElE,OAAO,UAAU,IAAI,EAAE,IAAI,KAAK,CAAA;AAClC,CAAC;AAJD,8CAIC"}
@@ -0,0 +1,6 @@
1
+ import { BasedErrorCode, ErrorHandler } from './types';
2
+ declare type ErrorType = {
3
+ [K in BasedErrorCode]: ErrorHandler<K>;
4
+ };
5
+ export declare const errorTypeHandlers: ErrorType;
6
+ export {};
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.errorTypeHandlers = void 0;
4
+ const types_1 = require("./types");
5
+ const addName = (payload) => {
6
+ return payload.name ? `[${payload.name}] ` : '';
7
+ };
8
+ exports.errorTypeHandlers = {
9
+ [types_1.BasedErrorCode.RateLimit]: {
10
+ statusCode: 429,
11
+ statusMessage: 'Rate limit',
12
+ message: () => 'rate limt',
13
+ },
14
+ [types_1.BasedErrorCode.FunctionError]: {
15
+ statusCode: 500,
16
+ statusMessage: 'Internal Server Error',
17
+ message: (payload) => {
18
+ if (!payload.err.message) {
19
+ return `[${payload.route.name}] ${JSON.stringify(payload.err)}`;
20
+ }
21
+ return (addName(payload.route) +
22
+ `${payload.err.name && payload.err.name !== 'Error'
23
+ ? `[${payload.err.name}] `
24
+ : ''}${payload.err.message || ''}`);
25
+ },
26
+ },
27
+ [types_1.BasedErrorCode.ObserveCallbackError]: {
28
+ statusCode: 500,
29
+ statusMessage: 'Internal Server Error',
30
+ message: () => {
31
+ return 'Error in server side observer';
32
+ },
33
+ },
34
+ [types_1.BasedErrorCode.ObservableFunctionError]: {
35
+ statusCode: 500,
36
+ statusMessage: 'Internal Server Error',
37
+ message: (payload) => {
38
+ if (payload.err && !payload.err.message && !payload.err.name) {
39
+ return `[${payload.route.name}] ${JSON.stringify(payload.err)}`;
40
+ }
41
+ return `[${payload.route.name}] ${payload.err.name && payload.err.name !== 'Error'
42
+ ? `[${payload.err.name}] `
43
+ : ''}${payload.err.message || ''}`;
44
+ },
45
+ },
46
+ [types_1.BasedErrorCode.FunctionNotFound]: {
47
+ statusCode: 404,
48
+ statusMessage: 'Not Found',
49
+ message: (payload) => {
50
+ return (addName(payload) +
51
+ `Function not found${payload.path ? ` path '${payload.path}'` : ''}`);
52
+ },
53
+ },
54
+ [types_1.BasedErrorCode.FunctionIsStream]: {
55
+ statusCode: 400,
56
+ statusMessage: 'Incorrect Protocol',
57
+ message: (payload) => {
58
+ return addName(payload) + 'Cannot use stream functions over websockets';
59
+ },
60
+ },
61
+ [types_1.BasedErrorCode.FunctionIsNotObservable]: {
62
+ statusCode: 400,
63
+ statusMessage: 'Function Is Not Observable',
64
+ message: (payload) => addName(payload) + 'Cannot observe non observable functions',
65
+ },
66
+ [types_1.BasedErrorCode.FunctionIsObservable]: {
67
+ statusCode: 400,
68
+ statusMessage: 'Function Is Observable',
69
+ message: (payload) => addName(payload) + 'Cannot call observable functions as a standard one',
70
+ },
71
+ [types_1.BasedErrorCode.CannotStreamToObservableFunction]: {
72
+ statusCode: 404,
73
+ statusMessage: 'Not Found',
74
+ message: (payload) => {
75
+ return addName(payload) + 'Cannot stream to observable function';
76
+ },
77
+ },
78
+ [types_1.BasedErrorCode.AuthorizeFunctionError]: {
79
+ statusCode: 403,
80
+ statusMessage: 'Forbidden',
81
+ message: (payload) => addName(payload.route) + 'Error in authorize function',
82
+ },
83
+ [types_1.BasedErrorCode.AuthorizeRejectedError]: {
84
+ statusCode: 403,
85
+ statusMessage: 'Forbidden',
86
+ message: (payload) => addName(payload.route) + `Authorize rejected access`,
87
+ },
88
+ [types_1.BasedErrorCode.InvalidPayload]: {
89
+ statusCode: 400,
90
+ statusMessage: 'Bad Request',
91
+ message: (payload) => addName(payload) + 'Invalid payload',
92
+ },
93
+ [types_1.BasedErrorCode.NoBinaryProtocol]: {
94
+ statusCode: 400,
95
+ statusMessage: 'Protocol mismatch',
96
+ message: () => 'Please upgrade to the latest based client',
97
+ },
98
+ [types_1.BasedErrorCode.PayloadTooLarge]: {
99
+ statusCode: 413,
100
+ statusMessage: 'Payload Too Large',
101
+ message: (payload) => addName(payload) + ' PayloadTooLarge',
102
+ },
103
+ [types_1.BasedErrorCode.ChunkTooLarge]: {
104
+ statusCode: 413,
105
+ statusMessage: 'Payload Too Large',
106
+ message: (payload) => addName(payload) + 'ChunkTooLarge ' + payload.name,
107
+ },
108
+ [types_1.BasedErrorCode.UnsupportedContentEncoding]: {
109
+ statusCode: 400,
110
+ statusMessage: 'Incorrect content encoding',
111
+ message: (payload) => addName(payload) + 'Incorrect content encoding',
112
+ },
113
+ [types_1.BasedErrorCode.LengthRequired]: {
114
+ statusCode: 411,
115
+ statusMessage: 'Length Required',
116
+ message: (payload) => addName(payload) + 'Length Required',
117
+ },
118
+ [types_1.BasedErrorCode.MethodNotAllowed]: {
119
+ statusCode: 405,
120
+ statusMessage: 'Method Not Allowed',
121
+ message: (payload) => addName(payload) + 'Method Not Allowed',
122
+ },
123
+ [types_1.BasedErrorCode.NoOservableCacheAvailable]: {
124
+ statusCode: 500,
125
+ statusMessage: 'Internal Server Error',
126
+ message: (payload) => addName(payload.route) +
127
+ `No observable cache available${payload.route.name} - ${payload.observableId}`,
128
+ },
129
+ };
130
+ //# sourceMappingURL=errorTypeHandlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errorTypeHandlers.js","sourceRoot":"","sources":["../../src/error/errorTypeHandlers.ts"],"names":[],"mappings":";;;AACA,mCAAoE;AAEpE,MAAM,OAAO,GAAG,CAAC,OAA2B,EAAU,EAAE;IACtD,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAA;AACjD,CAAC,CAAA;AAMY,QAAA,iBAAiB,GAAc;IAC1C,CAAC,sBAAc,CAAC,SAAS,CAAC,EAAE;QAC1B,UAAU,EAAE,GAAG;QACf,aAAa,EAAE,YAAY;QAC3B,OAAO,EAAE,GAAG,EAAE,CAAC,WAAW;KAC3B;IACD,CAAC,sBAAc,CAAC,aAAa,CAAC,EAAE;QAC9B,UAAU,EAAE,GAAG;QACf,aAAa,EAAE,uBAAuB;QACtC,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE;YACnB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE;gBACxB,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAA;aAChE;YACD,OAAO,CACL,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;gBACtB,GACE,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,KAAK,OAAO;oBAC9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AE,oBAAoB;QACnC,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,oBAAoB;KAC9D;IACD,CAAC,sBAAc,CAAC,yBAAyB,CAAC,EAAE;QAC1C,UAAU,EAAE,GAAG;QACf,aAAa,EAAE,uBAAuB;QACtC,OAAO,EAAE,CACP,OAA+D,EAC/D,EAAE,CACF,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;YACtB,gCAAgC,OAAO,CAAC,KAAK,CAAC,IAAI,MAAM,OAAO,CAAC,YAAY,EAAE;KACjF;CACF,CAAA"}
@@ -0,0 +1,5 @@
1
+ import { BasedServer } from '../server';
2
+ import { Context } from '../context';
3
+ import { BasedErrorCode, ErrorPayload, BasedErrorData } from './types';
4
+ export * from './types';
5
+ export declare function createError<T extends BasedErrorCode>(server: BasedServer, context: Context, code: T, payload: ErrorPayload[T]): BasedErrorData<T>;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.createError = void 0;
18
+ const types_1 = require("./types");
19
+ const errorTypeHandlers_1 = require("./errorTypeHandlers");
20
+ __exportStar(require("./types"), exports);
21
+ const isBasedFunctionRoute = (route) => {
22
+ if (route && typeof route === 'object' && 'name' in route) {
23
+ return true;
24
+ }
25
+ return false;
26
+ };
27
+ function createError(server, context, code, payload) {
28
+ const type = errorTypeHandlers_1.errorTypeHandlers[code];
29
+ const route = !payload
30
+ ? types_1.EMPTY_ROUTE
31
+ : isBasedFunctionRoute(payload)
32
+ ? payload
33
+ : 'route' in payload
34
+ ? payload.route
35
+ : types_1.EMPTY_ROUTE;
36
+ const errorData = {
37
+ code,
38
+ statusCode: type.statusCode,
39
+ statusMessage: type.statusMessage,
40
+ message: type.message(payload),
41
+ route: {
42
+ name: route.name,
43
+ path: route.path,
44
+ },
45
+ };
46
+ if ('requestId' in payload) {
47
+ errorData.requestId = payload.requestId;
48
+ }
49
+ if ('observableId' in payload) {
50
+ errorData.observableId = payload.observableId;
51
+ }
52
+ if ('err' in payload) {
53
+ server.emit('error', context, errorData, payload.err);
54
+ }
55
+ else {
56
+ server.emit('error', context, errorData);
57
+ }
58
+ return errorData;
59
+ }
60
+ exports.createError = createError;
61
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/error/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAGA,mCAKgB;AAEhB,2DAAuD;AACvD,0CAAuB;AAEvB,MAAM,oBAAoB,GAAG,CAAC,KAAU,EAA+B,EAAE;IACvE,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,IAAI,KAAK,EAAE;QACzD,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED,SAAgB,WAAW,CACzB,MAAmB,EACnB,OAAgB,EAChB,IAAO,EACP,OAAwB;IAExB,MAAM,IAAI,GAAG,qCAAiB,CAAC,IAAI,CAAC,CAAA;IAEpC,MAAM,KAAK,GAAG,CAAC,OAAO;QACpB,CAAC,CAAC,mBAAW;QACb,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC;YAC/B,CAAC,CAAC,OAAO;YACT,CAAC,CAAC,OAAO,IAAI,OAAO;gBACpB,CAAC,CAAC,OAAO,CAAC,KAAK;gBACf,CAAC,CAAC,mBAAW,CAAA;IAEf,MAAM,SAAS,GAAsB;QACnC,IAAI;QACJ,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;QAC9B,KAAK,EAAE;YACL,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,IAAI,EAAE,KAAK,CAAC,IAAI;SACjB;KACF,CAAA;IAED,IAAI,WAAW,IAAI,OAAO,EAAE;QAC1B,SAAS,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;KACxC;IAED,IAAI,cAAc,IAAI,OAAO,EAAE;QAC7B,SAAS,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAA;KAC9C;IAED,IAAI,KAAK,IAAI,OAAO,EAAE;QACpB,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;KACtD;SAAM;QACL,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;KACzC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC;AA1CD,kCA0CC"}
@@ -0,0 +1,105 @@
1
+ import { BasedFunctionRoute } from '../functions';
2
+ export declare const EMPTY_ROUTE: {
3
+ name: string;
4
+ path: string;
5
+ };
6
+ export declare enum BasedErrorCode {
7
+ FunctionError = 50001,
8
+ AuthorizeFunctionError = 50002,
9
+ NoOservableCacheAvailable = 50003,
10
+ ObservableFunctionError = 50004,
11
+ ObserveCallbackError = 50005,
12
+ FunctionNotFound = 40401,
13
+ FunctionIsNotObservable = 40402,
14
+ FunctionIsObservable = 40403,
15
+ FunctionIsStream = 40404,
16
+ CannotStreamToObservableFunction = 40402,
17
+ AuthorizeRejectedError = 40301,
18
+ InvalidPayload = 40001,
19
+ PayloadTooLarge = 40002,
20
+ ChunkTooLarge = 40003,
21
+ UnsupportedContentEncoding = 40004,
22
+ NoBinaryProtocol = 40005,
23
+ LengthRequired = 41101,
24
+ MethodNotAllowed = 40501,
25
+ RateLimit = 40029
26
+ }
27
+ export declare type BasedError<T extends BasedErrorCode = BasedErrorCode> = Error & {
28
+ code: T;
29
+ };
30
+ declare type FunctionErrorProps = {
31
+ err: Error;
32
+ requestId?: number;
33
+ route: BasedFunctionRoute;
34
+ };
35
+ declare type ObservableFunctionErrorProps = {
36
+ observableId: number;
37
+ err: Error;
38
+ route: BasedFunctionRoute;
39
+ };
40
+ export declare type ErrorPayload = {
41
+ [BasedErrorCode.RateLimit]: {};
42
+ [BasedErrorCode.NoBinaryProtocol]: {
43
+ buffer: ArrayBuffer;
44
+ };
45
+ [BasedErrorCode.FunctionError]: FunctionErrorProps;
46
+ [BasedErrorCode.ObservableFunctionError]: ObservableFunctionErrorProps;
47
+ [BasedErrorCode.AuthorizeFunctionError]: FunctionErrorProps | ObservableFunctionErrorProps;
48
+ [BasedErrorCode.AuthorizeRejectedError]: {
49
+ observableId: number;
50
+ route: BasedFunctionRoute;
51
+ } | {
52
+ requestId?: number;
53
+ route: BasedFunctionRoute;
54
+ };
55
+ [BasedErrorCode.ObserveCallbackError]: {
56
+ err: Error;
57
+ observableId: number;
58
+ route?: BasedFunctionRoute;
59
+ };
60
+ [BasedErrorCode.NoOservableCacheAvailable]: {
61
+ observableId: number;
62
+ route: BasedFunctionRoute;
63
+ };
64
+ [BasedErrorCode.FunctionIsStream]: BasedFunctionRoute & {
65
+ requestId?: number;
66
+ };
67
+ [BasedErrorCode.FunctionNotFound]: BasedFunctionRoute & {
68
+ requestId?: number;
69
+ };
70
+ [BasedErrorCode.FunctionIsNotObservable]: BasedFunctionRoute & {
71
+ requestId?: number;
72
+ };
73
+ [BasedErrorCode.FunctionIsObservable]: BasedFunctionRoute & {
74
+ requestId?: number;
75
+ };
76
+ [BasedErrorCode.CannotStreamToObservableFunction]: BasedFunctionRoute & {
77
+ requestId?: number;
78
+ };
79
+ [BasedErrorCode.InvalidPayload]: BasedFunctionRoute & {
80
+ requestId?: number;
81
+ };
82
+ [BasedErrorCode.PayloadTooLarge]: BasedFunctionRoute & {
83
+ requestId?: number;
84
+ };
85
+ [BasedErrorCode.ChunkTooLarge]: BasedFunctionRoute;
86
+ [BasedErrorCode.UnsupportedContentEncoding]: BasedFunctionRoute;
87
+ [BasedErrorCode.LengthRequired]: BasedFunctionRoute;
88
+ [BasedErrorCode.MethodNotAllowed]: BasedFunctionRoute;
89
+ };
90
+ export declare type ErrorHandler<T extends BasedErrorCode> = {
91
+ statusCode: number;
92
+ statusMessage: string;
93
+ message: (payload: ErrorPayload[T]) => string;
94
+ };
95
+ export declare type BasedErrorData<T extends BasedErrorCode = BasedErrorCode> = {
96
+ route: BasedFunctionRoute;
97
+ message: string;
98
+ code: T;
99
+ statusCode: number;
100
+ statusMessage: string;
101
+ requestId?: number;
102
+ observableId?: number;
103
+ err?: BasedError<T>;
104
+ };
105
+ export {};
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BasedErrorCode = exports.EMPTY_ROUTE = void 0;
4
+ exports.EMPTY_ROUTE = {
5
+ name: 'no-route',
6
+ path: '',
7
+ };
8
+ var BasedErrorCode;
9
+ (function (BasedErrorCode) {
10
+ BasedErrorCode[BasedErrorCode["FunctionError"] = 50001] = "FunctionError";
11
+ BasedErrorCode[BasedErrorCode["AuthorizeFunctionError"] = 50002] = "AuthorizeFunctionError";
12
+ BasedErrorCode[BasedErrorCode["NoOservableCacheAvailable"] = 50003] = "NoOservableCacheAvailable";
13
+ BasedErrorCode[BasedErrorCode["ObservableFunctionError"] = 50004] = "ObservableFunctionError";
14
+ BasedErrorCode[BasedErrorCode["ObserveCallbackError"] = 50005] = "ObserveCallbackError";
15
+ BasedErrorCode[BasedErrorCode["FunctionNotFound"] = 40401] = "FunctionNotFound";
16
+ BasedErrorCode[BasedErrorCode["FunctionIsNotObservable"] = 40402] = "FunctionIsNotObservable";
17
+ BasedErrorCode[BasedErrorCode["FunctionIsObservable"] = 40403] = "FunctionIsObservable";
18
+ BasedErrorCode[BasedErrorCode["FunctionIsStream"] = 40404] = "FunctionIsStream";
19
+ BasedErrorCode[BasedErrorCode["CannotStreamToObservableFunction"] = 40402] = "CannotStreamToObservableFunction";
20
+ BasedErrorCode[BasedErrorCode["AuthorizeRejectedError"] = 40301] = "AuthorizeRejectedError";
21
+ BasedErrorCode[BasedErrorCode["InvalidPayload"] = 40001] = "InvalidPayload";
22
+ BasedErrorCode[BasedErrorCode["PayloadTooLarge"] = 40002] = "PayloadTooLarge";
23
+ BasedErrorCode[BasedErrorCode["ChunkTooLarge"] = 40003] = "ChunkTooLarge";
24
+ BasedErrorCode[BasedErrorCode["UnsupportedContentEncoding"] = 40004] = "UnsupportedContentEncoding";
25
+ BasedErrorCode[BasedErrorCode["NoBinaryProtocol"] = 40005] = "NoBinaryProtocol";
26
+ BasedErrorCode[BasedErrorCode["LengthRequired"] = 41101] = "LengthRequired";
27
+ BasedErrorCode[BasedErrorCode["MethodNotAllowed"] = 40501] = "MethodNotAllowed";
28
+ BasedErrorCode[BasedErrorCode["RateLimit"] = 40029] = "RateLimit";
29
+ })(BasedErrorCode = exports.BasedErrorCode || (exports.BasedErrorCode = {}));
30
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/error/types.ts"],"names":[],"mappings":";;;AAEa,QAAA,WAAW,GAAG;IACzB,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,EAAE;CACT,CAAA;AAED,IAAY,cAoBX;AApBD,WAAY,cAAc;IACxB,yEAAqB,CAAA;IACrB,2FAA8B,CAAA;IAC9B,iGAAiC,CAAA;IACjC,6FAA+B,CAAA;IAC/B,uFAA4B,CAAA;IAC5B,+EAAwB,CAAA;IACxB,6FAA+B,CAAA;IAC/B,uFAA4B,CAAA;IAC5B,+EAAwB,CAAA;IACxB,+GAAwC,CAAA;IACxC,2FAA8B,CAAA;IAC9B,2EAAsB,CAAA;IACtB,6EAAuB,CAAA;IACvB,yEAAqB,CAAA;IACrB,mGAAkC,CAAA;IAClC,+EAAwB,CAAA;IACxB,2EAAsB,CAAA;IACtB,+EAAwB,CAAA;IACxB,iEAAiB,CAAA;AACnB,CAAC,EApBW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAoBzB"}
@@ -0,0 +1,66 @@
1
+ import { BasedServer } from './server';
2
+ import { BasedFunctionRoute, HttpClient, WebsocketClient } from './types';
3
+ export declare enum BasedErrorCode {
4
+ FunctionError = 50001,
5
+ AuthorizeFunctionError = 50002,
6
+ NoOservableCacheAvailable = 50003,
7
+ ObservableFunctionError = 50004,
8
+ FunctionNotFound = 40401,
9
+ FunctionIsNotObservable = 40402,
10
+ FunctionIsObservable = 40403,
11
+ FunctionIsStream = 40404,
12
+ CannotStreamToObservableFunction = 40402,
13
+ AuthorizeRejectedError = 40301,
14
+ InvalidPayload = 40001,
15
+ PayloadTooLarge = 40002,
16
+ ChunkTooLarge = 40003,
17
+ UnsupportedContentEncoding = 40004,
18
+ NoBinaryProtocol = 40005,
19
+ LengthRequired = 41101,
20
+ MethodNotAllowed = 40501
21
+ }
22
+ declare type FunctionErrorProps = {
23
+ err: Error;
24
+ requestId?: number;
25
+ route: BasedFunctionRoute;
26
+ } | {
27
+ observableId: number;
28
+ err: Error;
29
+ route: BasedFunctionRoute;
30
+ };
31
+ export declare type ErrorPayload = {
32
+ [BasedErrorCode.NoBinaryProtocol]: any;
33
+ [BasedErrorCode.FunctionError]: FunctionErrorProps;
34
+ [BasedErrorCode.AuthorizeFunctionError]: FunctionErrorProps;
35
+ [BasedErrorCode.NoOservableCacheAvailable]: {
36
+ observableId: number;
37
+ route: BasedFunctionRoute;
38
+ };
39
+ [BasedErrorCode.ObservableFunctionError]: {
40
+ observableId: number;
41
+ route: BasedFunctionRoute;
42
+ };
43
+ [BasedErrorCode.FunctionIsStream]: BasedFunctionRoute;
44
+ [BasedErrorCode.FunctionNotFound]: BasedFunctionRoute;
45
+ [BasedErrorCode.FunctionIsNotObservable]: BasedFunctionRoute;
46
+ [BasedErrorCode.FunctionIsObservable]: BasedFunctionRoute;
47
+ [BasedErrorCode.CannotStreamToObservableFunction]: BasedFunctionRoute;
48
+ [BasedErrorCode.AuthorizeRejectedError]: BasedFunctionRoute;
49
+ [BasedErrorCode.InvalidPayload]: BasedFunctionRoute;
50
+ [BasedErrorCode.PayloadTooLarge]: BasedFunctionRoute;
51
+ [BasedErrorCode.ChunkTooLarge]: BasedFunctionRoute;
52
+ [BasedErrorCode.UnsupportedContentEncoding]: BasedFunctionRoute;
53
+ [BasedErrorCode.LengthRequired]: BasedFunctionRoute;
54
+ [BasedErrorCode.MethodNotAllowed]: BasedFunctionRoute;
55
+ };
56
+ export declare type BasedErrorData = {
57
+ route: BasedFunctionRoute;
58
+ message: string;
59
+ code: BasedErrorCode;
60
+ statusCode: number;
61
+ statusMessage: string;
62
+ requestId?: number;
63
+ observableId?: number;
64
+ };
65
+ export declare const createError: (server: BasedServer, client: HttpClient | WebsocketClient, code: BasedErrorCode, payload: ErrorPayload[BasedErrorCode]) => BasedErrorData;
66
+ export {};