@based/server 3.4.6 → 4.0.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.
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.js +173 -0
- package/dist/api/index.js.map +1 -0
- package/dist/auth/dummyAuth.d.ts +2 -0
- package/dist/auth/dummyAuth.js +8 -0
- package/dist/auth/dummyAuth.js.map +1 -0
- package/dist/auth/index.d.ts +15 -0
- package/dist/auth/index.js +49 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/parseAuthState.d.ts +2 -0
- package/dist/auth/parseAuthState.js +16 -0
- package/dist/auth/parseAuthState.js.map +1 -0
- package/dist/auth/types.d.ts +10 -0
- package/dist/{handlers/rest/file → auth}/types.js +0 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/compress.d.ts +5 -0
- package/dist/compress.js +52 -0
- package/dist/compress.js.map +1 -0
- package/dist/context.d.ts +54 -0
- package/dist/context.js +18 -0
- package/dist/context.js.map +1 -0
- package/dist/error/errorTypeHandlers.d.ts +6 -0
- package/dist/error/errorTypeHandlers.js +130 -0
- package/dist/error/errorTypeHandlers.js.map +1 -0
- package/dist/error/index.d.ts +5 -0
- package/dist/error/index.js +61 -0
- package/dist/error/index.js.map +1 -0
- package/dist/error/types.d.ts +105 -0
- package/dist/error/types.js +30 -0
- package/dist/error/types.js.map +1 -0
- package/dist/functions/index.d.ts +34 -0
- package/dist/functions/index.js +210 -0
- package/dist/functions/index.js.map +1 -0
- package/dist/functions/timeout.d.ts +3 -0
- package/dist/functions/timeout.js +23 -0
- package/dist/functions/timeout.js.map +1 -0
- package/dist/functions/types.d.ts +69 -0
- package/dist/functions/types.js +15 -0
- package/dist/functions/types.js.map +1 -0
- package/dist/incoming/http/authorize.d.ts +4 -0
- package/dist/incoming/http/authorize.js +37 -0
- package/dist/incoming/http/authorize.js.map +1 -0
- package/dist/incoming/http/function.d.ts +4 -0
- package/dist/incoming/http/function.js +47 -0
- package/dist/incoming/http/function.js.map +1 -0
- package/dist/incoming/http/get.d.ts +4 -0
- package/dist/incoming/http/get.js +155 -0
- package/dist/incoming/http/get.js.map +1 -0
- package/dist/incoming/http/index.d.ts +3 -0
- package/dist/incoming/http/index.js +134 -0
- package/dist/incoming/http/index.js.map +1 -0
- package/dist/incoming/http/parseQuery.d.ts +4 -0
- package/dist/incoming/http/parseQuery.js +25 -0
- package/dist/incoming/http/parseQuery.js.map +1 -0
- package/dist/incoming/http/readBody.d.ts +4 -0
- package/dist/incoming/http/readBody.js +107 -0
- package/dist/incoming/http/readBody.js.map +1 -0
- package/dist/{handlers/rest/file → incoming/http/streamFunction}/DataStream.d.ts +0 -0
- package/dist/{handlers/rest/file → incoming/http/streamFunction}/DataStream.js +3 -1
- package/dist/incoming/http/streamFunction/DataStream.js.map +1 -0
- package/dist/{handlers/rest/file/getExtenstion.d.ts → incoming/http/streamFunction/getExtension.d.ts} +0 -0
- package/dist/{handlers/rest/file/getExtenstion.js → incoming/http/streamFunction/getExtension.js} +9 -2
- package/dist/incoming/http/streamFunction/getExtension.js.map +1 -0
- package/dist/incoming/http/streamFunction/index.d.ts +4 -0
- package/dist/incoming/http/streamFunction/index.js +106 -0
- package/dist/incoming/http/streamFunction/index.js.map +1 -0
- package/dist/incoming/http/streamFunction/multipartStream.d.ts +13 -0
- package/dist/incoming/http/streamFunction/multipartStream.js +208 -0
- package/dist/incoming/http/streamFunction/multipartStream.js.map +1 -0
- package/dist/incoming/http/streamFunction/stream.d.ts +6 -0
- package/dist/incoming/http/streamFunction/stream.js +108 -0
- package/dist/incoming/http/streamFunction/stream.js.map +1 -0
- package/dist/incoming/index.d.ts +3 -0
- package/dist/incoming/index.js +84 -0
- package/dist/incoming/index.js.map +1 -0
- package/dist/incoming/upgrade.d.ts +4 -0
- package/dist/incoming/upgrade.js +64 -0
- package/dist/incoming/upgrade.js.map +1 -0
- package/dist/incoming/ws/auth.d.ts +5 -0
- package/dist/incoming/ws/auth.js +40 -0
- package/dist/incoming/ws/auth.js.map +1 -0
- package/dist/incoming/ws/function.d.ts +3 -0
- package/dist/incoming/ws/function.js +107 -0
- package/dist/incoming/ws/function.js.map +1 -0
- package/dist/incoming/ws/get.d.ts +3 -0
- package/dist/incoming/ws/get.js +136 -0
- package/dist/incoming/ws/get.js.map +1 -0
- package/dist/incoming/ws/index.d.ts +3 -0
- package/dist/incoming/ws/index.js +61 -0
- package/dist/incoming/ws/index.js.map +1 -0
- package/dist/incoming/ws/observable.d.ts +6 -0
- package/dist/incoming/ws/observable.js +112 -0
- package/dist/incoming/ws/observable.js.map +1 -0
- package/dist/index.d.ts +10 -35
- package/dist/index.js +17 -196
- package/dist/index.js.map +1 -1
- package/dist/ip.d.ts +2 -0
- package/dist/ip.js +8 -0
- package/dist/ip.js.map +1 -0
- package/dist/observable/create.d.ts +3 -0
- package/dist/observable/create.js +30 -0
- package/dist/observable/create.js.map +1 -0
- package/dist/observable/destroy.d.ts +2 -0
- package/dist/observable/destroy.js +51 -0
- package/dist/observable/destroy.js.map +1 -0
- package/dist/observable/error.d.ts +4 -0
- package/dist/observable/error.js +17 -0
- package/dist/observable/error.js.map +1 -0
- package/dist/observable/extendCache.d.ts +2 -0
- package/dist/observable/extendCache.js +11 -0
- package/dist/observable/extendCache.js.map +1 -0
- package/dist/observable/genObservableId.d.ts +1 -0
- package/dist/observable/genObservableId.js +9 -0
- package/dist/observable/genObservableId.js.map +1 -0
- package/dist/observable/get.d.ts +4 -0
- package/dist/observable/get.js +15 -0
- package/dist/observable/get.js.map +1 -0
- package/dist/observable/index.d.ts +11 -0
- package/dist/observable/index.js +28 -0
- package/dist/observable/index.js.map +1 -0
- package/dist/observable/send.d.ts +6 -0
- package/dist/observable/send.js +32 -0
- package/dist/observable/send.js.map +1 -0
- package/dist/observable/start/error.d.ts +3 -0
- package/dist/observable/start/error.js +36 -0
- package/dist/observable/start/error.js.map +1 -0
- package/dist/observable/start/index.d.ts +2 -0
- package/dist/observable/start/index.js +46 -0
- package/dist/observable/start/index.js.map +1 -0
- package/dist/observable/start/update.d.ts +6 -0
- package/dist/observable/start/update.js +104 -0
- package/dist/observable/start/update.js.map +1 -0
- package/dist/observable/subscribe.d.ts +7 -0
- package/dist/observable/subscribe.js +54 -0
- package/dist/observable/subscribe.js.map +1 -0
- package/dist/observable/types.d.ts +26 -0
- package/dist/observable/types.js +3 -0
- package/dist/observable/types.js.map +1 -0
- package/dist/observable/unsub.d.ts +6 -0
- package/dist/observable/unsub.js +43 -0
- package/dist/observable/unsub.js.map +1 -0
- package/dist/observable/verify.d.ts +4 -0
- package/dist/observable/verify.js +18 -0
- package/dist/observable/verify.js.map +1 -0
- package/dist/protocol.d.ts +21 -0
- package/dist/protocol.js +233 -0
- package/dist/protocol.js.map +1 -0
- package/dist/security.d.ts +6 -0
- package/dist/security.js +95 -0
- package/dist/security.js.map +1 -0
- package/dist/sendError.d.ts +5 -0
- package/dist/sendError.js +42 -0
- package/dist/sendError.js.map +1 -0
- package/dist/sendHttpResponse.d.ts +4 -0
- package/dist/sendHttpResponse.js +53 -0
- package/dist/sendHttpResponse.js.map +1 -0
- package/dist/server.d.ts +69 -0
- package/dist/server.js +113 -0
- package/dist/server.js.map +1 -0
- package/package.json +16 -14
- package/dist/BasedServerClient.d.ts +0 -71
- package/dist/BasedServerClient.js +0 -390
- package/dist/BasedServerClient.js.map +0 -1
- package/dist/Client.d.ts +0 -75
- package/dist/Client.js +0 -277
- package/dist/Client.js.map +0 -1
- package/dist/Params.d.ts +0 -20
- package/dist/Params.js +0 -48
- package/dist/Params.js.map +0 -1
- package/dist/closeListener.d.ts +0 -4
- package/dist/closeListener.js +0 -13
- package/dist/closeListener.js.map +0 -1
- package/dist/findPrefix.d.ts +0 -3
- package/dist/findPrefix.js +0 -20
- package/dist/findPrefix.js.map +0 -1
- package/dist/getFromConfig.d.ts +0 -3
- package/dist/getFromConfig.js +0 -50
- package/dist/getFromConfig.js.map +0 -1
- package/dist/handlers/authorize.d.ts +0 -5
- package/dist/handlers/authorize.js +0 -196
- package/dist/handlers/authorize.js.map +0 -1
- package/dist/handlers/bulkUpdate/index.d.ts +0 -5
- package/dist/handlers/bulkUpdate/index.js +0 -26
- package/dist/handlers/bulkUpdate/index.js.map +0 -1
- package/dist/handlers/configuration/index.d.ts +0 -10
- package/dist/handlers/configuration/index.js +0 -74
- package/dist/handlers/configuration/index.js.map +0 -1
- package/dist/handlers/configuration/observable/index.d.ts +0 -46
- package/dist/handlers/configuration/observable/index.js +0 -277
- package/dist/handlers/configuration/observable/index.js.map +0 -1
- package/dist/handlers/configure/index.d.ts +0 -5
- package/dist/handlers/configure/index.js +0 -44
- package/dist/handlers/configure/index.js.map +0 -1
- package/dist/handlers/copy/index.d.ts +0 -8
- package/dist/handlers/copy/index.js +0 -135
- package/dist/handlers/copy/index.js.map +0 -1
- package/dist/handlers/delete/index.d.ts +0 -5
- package/dist/handlers/delete/index.js +0 -34
- package/dist/handlers/delete/index.js.map +0 -1
- package/dist/handlers/digest/index.d.ts +0 -5
- package/dist/handlers/digest/index.js +0 -23
- package/dist/handlers/digest/index.js.map +0 -1
- package/dist/handlers/functions/call.d.ts +0 -6
- package/dist/handlers/functions/call.js +0 -54
- package/dist/handlers/functions/call.js.map +0 -1
- package/dist/handlers/functions/observable/Observable.d.ts +0 -49
- package/dist/handlers/functions/observable/Observable.js +0 -290
- package/dist/handlers/functions/observable/Observable.js.map +0 -1
- package/dist/handlers/functions/observable/SharedObservable.d.ts +0 -45
- package/dist/handlers/functions/observable/SharedObservable.js +0 -291
- package/dist/handlers/functions/observable/SharedObservable.js.map +0 -1
- package/dist/handlers/functions/observable/index.d.ts +0 -14
- package/dist/handlers/functions/observable/index.js +0 -130
- package/dist/handlers/functions/observable/index.js.map +0 -1
- package/dist/handlers/get/index.d.ts +0 -5
- package/dist/handlers/get/index.js +0 -23
- package/dist/handlers/get/index.js.map +0 -1
- package/dist/handlers/getConfig/index.d.ts +0 -5
- package/dist/handlers/getConfig/index.js +0 -38
- package/dist/handlers/getConfig/index.js.map +0 -1
- package/dist/handlers/handleRequests.d.ts +0 -5
- package/dist/handlers/handleRequests.js +0 -78
- package/dist/handlers/handleRequests.js.map +0 -1
- package/dist/handlers/index.d.ts +0 -4
- package/dist/handlers/index.js +0 -49
- package/dist/handlers/index.js.map +0 -1
- package/dist/handlers/messageParser.d.ts +0 -5
- package/dist/handlers/messageParser.js +0 -122
- package/dist/handlers/messageParser.js.map +0 -1
- package/dist/handlers/removeField/index.d.ts +0 -5
- package/dist/handlers/removeField/index.js +0 -42
- package/dist/handlers/removeField/index.js.map +0 -1
- package/dist/handlers/removeType/index.d.ts +0 -5
- package/dist/handlers/removeType/index.js +0 -30
- package/dist/handlers/removeType/index.js.map +0 -1
- package/dist/handlers/rest/file/DataStream.js.map +0 -1
- package/dist/handlers/rest/file/formStream.d.ts +0 -4
- package/dist/handlers/rest/file/formStream.js +0 -188
- package/dist/handlers/rest/file/formStream.js.map +0 -1
- package/dist/handlers/rest/file/getExtenstion.js.map +0 -1
- package/dist/handlers/rest/file/index.d.ts +0 -4
- package/dist/handlers/rest/file/index.js +0 -53
- package/dist/handlers/rest/file/index.js.map +0 -1
- package/dist/handlers/rest/file/storeFile.d.ts +0 -6
- package/dist/handlers/rest/file/storeFile.js +0 -44
- package/dist/handlers/rest/file/storeFile.js.map +0 -1
- package/dist/handlers/rest/file/stream.d.ts +0 -5
- package/dist/handlers/rest/file/stream.js +0 -104
- package/dist/handlers/rest/file/stream.js.map +0 -1
- package/dist/handlers/rest/file/types.d.ts +0 -9
- package/dist/handlers/rest/file/types.js.map +0 -1
- package/dist/handlers/rest/getReqMessage.d.ts +0 -3
- package/dist/handlers/rest/getReqMessage.js +0 -92
- package/dist/handlers/rest/getReqMessage.js.map +0 -1
- package/dist/handlers/rest/index.d.ts +0 -4
- package/dist/handlers/rest/index.js +0 -121
- package/dist/handlers/rest/index.js.map +0 -1
- package/dist/handlers/rest/invalidReq.d.ts +0 -4
- package/dist/handlers/rest/invalidReq.js +0 -20
- package/dist/handlers/rest/invalidReq.js.map +0 -1
- package/dist/handlers/rest/parseResponse.d.ts +0 -6
- package/dist/handlers/rest/parseResponse.js +0 -230
- package/dist/handlers/rest/parseResponse.js.map +0 -1
- package/dist/handlers/rest/playground/index.d.ts +0 -5
- package/dist/handlers/rest/playground/index.js +0 -308
- package/dist/handlers/rest/playground/index.js.map +0 -1
- package/dist/handlers/rest/readBody.d.ts +0 -3
- package/dist/handlers/rest/readBody.js +0 -45
- package/dist/handlers/rest/readBody.js.map +0 -1
- package/dist/handlers/set/index.d.ts +0 -5
- package/dist/handlers/set/index.js +0 -20
- package/dist/handlers/set/index.js.map +0 -1
- package/dist/handlers/subscription/index.d.ts +0 -32
- package/dist/handlers/subscription/index.js +0 -223
- package/dist/handlers/subscription/index.js.map +0 -1
- package/dist/handlers/token.d.ts +0 -5
- package/dist/handlers/token.js +0 -122
- package/dist/handlers/token.js.map +0 -1
- package/dist/handlers/track/index.d.ts +0 -7
- package/dist/handlers/track/index.js +0 -102
- package/dist/handlers/track/index.js.map +0 -1
- package/dist/handlers/userAuth/index.d.ts +0 -5
- package/dist/handlers/userAuth/index.js +0 -78
- package/dist/handlers/userAuth/index.js.map +0 -1
- package/dist/openListener.d.ts +0 -4
- package/dist/openListener.js +0 -13
- package/dist/openListener.js.map +0 -1
- package/dist/secrets.d.ts +0 -9
- package/dist/secrets.js +0 -150
- package/dist/secrets.js.map +0 -1
- package/dist/types.d.ts +0 -129
- package/dist/types.js +0 -17
- package/dist/types.js.map +0 -1
- package/dist/upgradeListener.d.ts +0 -4
- package/dist/upgradeListener.js +0 -47
- package/dist/upgradeListener.js.map +0 -1
- package/dist/workers/index.d.ts +0 -0
- package/dist/workers/index.js +0 -20
- package/dist/workers/index.js.map +0 -1
- package/dist/workers/workerCode.d.ts +0 -12
- package/dist/workers/workerCode.js +0 -46
- package/dist/workers/workerCode.js.map +0 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BasedServer } from '../server';
|
|
2
|
+
import { Context } from '../context';
|
|
3
|
+
import { ObservableUpdateFunction, ObserveErrorListener } from '../observable';
|
|
4
|
+
export declare const callFunction: (server: BasedServer, name: string, ctx: Context, payload: any) => Promise<any>;
|
|
5
|
+
export declare const get: (server: BasedServer, name: string, ctx: Context, payload: any) => Promise<any>;
|
|
6
|
+
export declare const observe: (server: BasedServer, name: string, ctx: Context, payload: any, update: ObservableUpdateFunction, error: ObserveErrorListener) => (() => void);
|
|
7
|
+
export { decode } from '../protocol';
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decode = exports.observe = exports.get = exports.callFunction = void 0;
|
|
4
|
+
const error_1 = require("../error");
|
|
5
|
+
const functions_1 = require("../functions");
|
|
6
|
+
const observable_1 = require("../observable");
|
|
7
|
+
const callFunction = async (server, name, ctx, payload) => {
|
|
8
|
+
const route = server.functions.route(name);
|
|
9
|
+
if (!route) {
|
|
10
|
+
throw (0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionNotFound, { name });
|
|
11
|
+
}
|
|
12
|
+
if (route.observable === true) {
|
|
13
|
+
throw (0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionIsObservable, {
|
|
14
|
+
name,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
const fn = await server.functions.install(name);
|
|
18
|
+
if (!fn) {
|
|
19
|
+
throw (0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionNotFound, { name });
|
|
20
|
+
}
|
|
21
|
+
if ((0, functions_1.isObservableFunctionSpec)(fn)) {
|
|
22
|
+
throw (0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionIsObservable, {
|
|
23
|
+
name,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
return fn.function(payload, ctx);
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
throw (0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionError, {
|
|
31
|
+
route: { name },
|
|
32
|
+
err,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
exports.callFunction = callFunction;
|
|
37
|
+
const getObsData = (resolve, reject, server, id, ctx, route) => {
|
|
38
|
+
const obs = (0, observable_1.getObs)(server, id);
|
|
39
|
+
if (obs.error) {
|
|
40
|
+
reject((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.ObservableFunctionError, {
|
|
41
|
+
route,
|
|
42
|
+
observableId: id,
|
|
43
|
+
err: obs.error,
|
|
44
|
+
}));
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (obs.cache) {
|
|
48
|
+
resolve(obs.rawData || obs.cache);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
(0, observable_1.subscribeNext)(obs, (err) => {
|
|
52
|
+
if (err) {
|
|
53
|
+
reject((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.ObservableFunctionError, {
|
|
54
|
+
observableId: id,
|
|
55
|
+
route,
|
|
56
|
+
err,
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
resolve(obs.rawData || obs.cache);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
const get = (server, name, ctx, payload) => {
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
const route = server.functions.route(name);
|
|
67
|
+
if (!route) {
|
|
68
|
+
reject((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionNotFound, { name }));
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (route.observable === false) {
|
|
72
|
+
reject((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionIsNotObservable, {
|
|
73
|
+
name,
|
|
74
|
+
}));
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const id = (0, observable_1.genObservableId)(name, payload);
|
|
78
|
+
if (!(0, observable_1.hasObs)(server, id)) {
|
|
79
|
+
server.functions
|
|
80
|
+
.install(name)
|
|
81
|
+
.then((fn) => {
|
|
82
|
+
if (!fn) {
|
|
83
|
+
reject((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionNotFound, {
|
|
84
|
+
name,
|
|
85
|
+
}));
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (!(0, functions_1.isObservableFunctionSpec)(fn)) {
|
|
89
|
+
reject((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionIsNotObservable, {
|
|
90
|
+
name,
|
|
91
|
+
}));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (!(0, observable_1.hasObs)(server, id)) {
|
|
95
|
+
(0, observable_1.createObs)(server, name, id, payload);
|
|
96
|
+
}
|
|
97
|
+
getObsData(resolve, reject, server, id, ctx, route);
|
|
98
|
+
})
|
|
99
|
+
.catch(() => reject((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionNotFound, {
|
|
100
|
+
name,
|
|
101
|
+
})));
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
getObsData(resolve, reject, server, id, ctx, route);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
exports.get = get;
|
|
109
|
+
const observe = (server, name, ctx, payload, update, error) => {
|
|
110
|
+
// TODO: Callstack
|
|
111
|
+
const route = server.functions.route(name);
|
|
112
|
+
if (!route) {
|
|
113
|
+
throw (0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionNotFound, { name });
|
|
114
|
+
}
|
|
115
|
+
if (route.observable !== true) {
|
|
116
|
+
throw (0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionIsNotObservable, {
|
|
117
|
+
name,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
const id = (0, observable_1.genObservableId)(name, payload);
|
|
121
|
+
let obs;
|
|
122
|
+
let isClosed = false;
|
|
123
|
+
const close = () => {
|
|
124
|
+
if (isClosed) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
isClosed = true;
|
|
128
|
+
if (obs) {
|
|
129
|
+
(0, observable_1.unsubscribeFunction)(server, id, update);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
if ((0, observable_1.hasObs)(server, id)) {
|
|
133
|
+
(0, observable_1.subscribeFunction)(server, id, update);
|
|
134
|
+
return close;
|
|
135
|
+
}
|
|
136
|
+
server.functions
|
|
137
|
+
.install(name)
|
|
138
|
+
.then((spec) => {
|
|
139
|
+
if (isClosed) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (spec === false) {
|
|
143
|
+
error((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionNotFound, {
|
|
144
|
+
name,
|
|
145
|
+
}));
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (!(0, functions_1.isObservableFunctionSpec)(spec)) {
|
|
149
|
+
error((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionIsNotObservable, {
|
|
150
|
+
name,
|
|
151
|
+
}));
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (!(0, observable_1.hasObs)(server, id)) {
|
|
155
|
+
(0, observable_1.createObs)(server, name, id, payload);
|
|
156
|
+
}
|
|
157
|
+
(0, observable_1.subscribeFunction)(server, id, update);
|
|
158
|
+
})
|
|
159
|
+
.catch(() => {
|
|
160
|
+
if (isClosed) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
error((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionNotFound, {
|
|
164
|
+
name,
|
|
165
|
+
}));
|
|
166
|
+
});
|
|
167
|
+
return close;
|
|
168
|
+
};
|
|
169
|
+
exports.observe = observe;
|
|
170
|
+
var protocol_1 = require("../protocol");
|
|
171
|
+
Object.defineProperty(exports, "decode", { enumerable: true, get: function () { return protocol_1.decode; } });
|
|
172
|
+
// TODO: nested stream function
|
|
173
|
+
//# sourceMappingURL=index.js.map
|
|
@@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
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// eslint-disable-next-line
|
|
4
|
+
exports.default = async (_ctx, name, payload) => {
|
|
5
|
+
// console.warn(' 🔓 Dummy auth', name, payload)
|
|
6
|
+
return true;
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=dummyAuth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dummyAuth.js","sourceRoot":"","sources":["../../src/auth/dummyAuth.ts"],"names":[],"mappings":";;AAAA,2BAA2B;AAC3B,kBAAe,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;IAC3C,gDAAgD;IAChD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AuthState } from '../incoming/ws/auth';
|
|
2
|
+
import { BasedServer } from '../server';
|
|
3
|
+
import { AuthConfig, Authorize, AuthorizeConnection } from './types';
|
|
4
|
+
import { Context, WebSocketSession } from '../context';
|
|
5
|
+
import parseAuthState from './parseAuthState';
|
|
6
|
+
export { parseAuthState };
|
|
7
|
+
export * from './types';
|
|
8
|
+
export declare class BasedAuth {
|
|
9
|
+
server: BasedServer;
|
|
10
|
+
authorize: Authorize;
|
|
11
|
+
authorizeConnection: AuthorizeConnection;
|
|
12
|
+
constructor(server: BasedServer, config?: AuthConfig);
|
|
13
|
+
updateConfig(config: AuthConfig): void;
|
|
14
|
+
sendAuthUpdate(ctx: Context<WebSocketSession>, authState: AuthState): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.BasedAuth = exports.parseAuthState = void 0;
|
|
21
|
+
const protocol_1 = require("../protocol");
|
|
22
|
+
const dummyAuth_1 = __importDefault(require("./dummyAuth"));
|
|
23
|
+
const parseAuthState_1 = __importDefault(require("./parseAuthState"));
|
|
24
|
+
exports.parseAuthState = parseAuthState_1.default;
|
|
25
|
+
__exportStar(require("./types"), exports);
|
|
26
|
+
class BasedAuth {
|
|
27
|
+
constructor(server, config = {
|
|
28
|
+
authorize: dummyAuth_1.default,
|
|
29
|
+
}) {
|
|
30
|
+
this.server = server;
|
|
31
|
+
this.updateConfig(config);
|
|
32
|
+
}
|
|
33
|
+
updateConfig(config) {
|
|
34
|
+
if (!config) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (config.authorizeConnection) {
|
|
38
|
+
this.authorizeConnection = config.authorizeConnection;
|
|
39
|
+
}
|
|
40
|
+
if (config.authorize) {
|
|
41
|
+
this.authorize = config.authorize;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
sendAuthUpdate(ctx, authState) {
|
|
45
|
+
ctx.session?.send((0, protocol_1.encodeAuthResponse)((0, protocol_1.valueToBuffer)(authState)), true, false);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.BasedAuth = BasedAuth;
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AACA,0CAA+D;AAI/D,4DAAmC;AACnC,sEAA6C;AAEpC,yBAFF,wBAAc,CAEE;AAEvB,0CAAuB;AAEvB,MAAa,SAAS;IAKpB,YACE,MAAmB,EACnB,SAAqB;QACnB,SAAS,EAAE,mBAAS;KACrB;QAED,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAA;IAC3B,CAAC;IAED,YAAY,CAAC,MAAkB;QAC7B,IAAI,CAAC,MAAM,EAAE;YACX,OAAM;SACP;QAED,IAAI,MAAM,CAAC,mBAAmB,EAAE;YAC9B,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC,mBAAmB,CAAA;SACtD;QAED,IAAI,MAAM,CAAC,SAAS,EAAE;YACpB,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAA;SAClC;IACH,CAAC;IAED,cAAc,CAAC,GAA8B,EAAE,SAAoB;QACjE,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,IAAA,6BAAkB,EAAC,IAAA,wBAAa,EAAC,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;IAC9E,CAAC;CACF;AAhCD,8BAgCC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = (authState) => {
|
|
4
|
+
if (!authState) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
if (typeof authState !== 'string') {
|
|
8
|
+
return authState;
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
return JSON.parse(authState);
|
|
12
|
+
}
|
|
13
|
+
catch (err) { }
|
|
14
|
+
return authState;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=parseAuthState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseAuthState.js","sourceRoot":"","sources":["../../src/auth/parseAuthState.ts"],"names":[],"mappings":";;AAAA,kBAAe,CAAC,SAAc,EAAO,EAAE;IACrC,IAAI,CAAC,SAAS,EAAE;QACd,OAAM;KACP;IACD,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;QACjC,OAAO,SAAS,CAAA;KACjB;IACD,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;KAC7B;IAAC,OAAO,GAAG,EAAE,GAAE;IAChB,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BasedServer } from '../server';
|
|
2
|
+
import { Context } from '../context';
|
|
3
|
+
import uws from '@based/uws';
|
|
4
|
+
export declare type AuthConfig = {
|
|
5
|
+
authorize?: Authorize;
|
|
6
|
+
authorizeConnection?: AuthorizeConnection;
|
|
7
|
+
};
|
|
8
|
+
export declare type Authorize = (context: Context, name: string, payload?: any) => Promise<boolean>;
|
|
9
|
+
export declare type AuthorizeHandshake = (server: BasedServer, context: Context, payload?: any) => Promise<boolean>;
|
|
10
|
+
export declare type AuthorizeConnection = (req: uws.HttpRequest) => Promise<boolean>;
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/auth/types.ts"],"names":[],"mappings":""}
|
package/dist/compress.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
exports.compress = void 0;
|
|
7
|
+
const node_zlib_1 = __importDefault(require("node:zlib"));
|
|
8
|
+
const node_util_1 = require("node:util");
|
|
9
|
+
const protocol_1 = require("./protocol");
|
|
10
|
+
const deflate = (0, node_util_1.promisify)(node_zlib_1.default.deflate);
|
|
11
|
+
const gzip = (0, node_util_1.promisify)(node_zlib_1.default.gzip);
|
|
12
|
+
const br = (0, node_util_1.promisify)(node_zlib_1.default.brotliCompress);
|
|
13
|
+
/*
|
|
14
|
+
Content-Encoding: gzip
|
|
15
|
+
Content-Encoding: compress
|
|
16
|
+
Content-Encoding: deflate
|
|
17
|
+
Content-Encoding: br
|
|
18
|
+
*/
|
|
19
|
+
const COMPRESS_STRING_LEN = Math.ceil(protocol_1.COMPRESS_FROM_BYTES / 1.5);
|
|
20
|
+
const compress = async (payload, encoding) => {
|
|
21
|
+
if (payload instanceof Buffer && payload.byteLength <= protocol_1.COMPRESS_FROM_BYTES) {
|
|
22
|
+
return { payload };
|
|
23
|
+
}
|
|
24
|
+
if (payload.length < COMPRESS_STRING_LEN) {
|
|
25
|
+
return { payload };
|
|
26
|
+
}
|
|
27
|
+
if (encoding && typeof encoding === 'string') {
|
|
28
|
+
let responseEncoding;
|
|
29
|
+
let compressed;
|
|
30
|
+
if (!(payload instanceof Buffer)) {
|
|
31
|
+
payload = Buffer.from(payload);
|
|
32
|
+
}
|
|
33
|
+
if (encoding.includes('deflate')) {
|
|
34
|
+
responseEncoding = 'deflate';
|
|
35
|
+
compressed = await deflate(payload);
|
|
36
|
+
}
|
|
37
|
+
else if (encoding.includes('gzip')) {
|
|
38
|
+
responseEncoding = 'gzip';
|
|
39
|
+
compressed = await gzip(payload);
|
|
40
|
+
}
|
|
41
|
+
else if (encoding.includes('br')) {
|
|
42
|
+
responseEncoding = 'br';
|
|
43
|
+
compressed = await br(payload);
|
|
44
|
+
}
|
|
45
|
+
if (compressed) {
|
|
46
|
+
return { payload: compressed, encoding: responseEncoding };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return { payload };
|
|
50
|
+
};
|
|
51
|
+
exports.compress = compress;
|
|
52
|
+
//# sourceMappingURL=compress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compress.js","sourceRoot":"","sources":["../src/compress.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAC5B,yCAAqC;AACrC,yCAAgD;AAEhD,MAAM,OAAO,GAAG,IAAA,qBAAS,EAAC,mBAAI,CAAC,OAAO,CAAC,CAAA;AACvC,MAAM,IAAI,GAAG,IAAA,qBAAS,EAAC,mBAAI,CAAC,IAAI,CAAC,CAAA;AACjC,MAAM,EAAE,GAAG,IAAA,qBAAS,EAAC,mBAAI,CAAC,cAAc,CAAC,CAAA;AAEzC;;;;;EAKE;AAEF,MAAM,mBAAmB,GAAG,IAAI,CAAC,IAAI,CAAC,8BAAmB,GAAG,GAAG,CAAC,CAAA;AAEzD,MAAM,QAAQ,GAAG,KAAK,EAC3B,OAAwB,EACxB,QAAiB,EACyC,EAAE;IAC5D,IAAI,OAAO,YAAY,MAAM,IAAI,OAAO,CAAC,UAAU,IAAI,8BAAmB,EAAE;QAC1E,OAAO,EAAE,OAAO,EAAE,CAAA;KACnB;IAED,IAAI,OAAO,CAAC,MAAM,GAAG,mBAAmB,EAAE;QACxC,OAAO,EAAE,OAAO,EAAE,CAAA;KACnB;IAED,IAAI,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;QAC5C,IAAI,gBAAwB,CAAA;QAC5B,IAAI,UAAkB,CAAA;QACtB,IAAI,CAAC,CAAC,OAAO,YAAY,MAAM,CAAC,EAAE;YAChC,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SAC/B;QACD,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;YAChC,gBAAgB,GAAG,SAAS,CAAA;YAC5B,UAAU,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;SACpC;aAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YACpC,gBAAgB,GAAG,MAAM,CAAA;YACzB,UAAU,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,CAAA;SACjC;aAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;YAClC,gBAAgB,GAAG,IAAI,CAAA;YACvB,UAAU,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,CAAA;SAC/B;QACD,IAAI,UAAU,EAAE;YACd,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,gBAAgB,EAAE,CAAA;SAC3D;KACF;IACD,OAAO,EAAE,OAAO,EAAE,CAAA;AACpB,CAAC,CAAA;AAjCY,QAAA,QAAQ,YAiCpB"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import uws from '@based/uws';
|
|
2
|
+
import { parseQuery } from '@saulx/utils';
|
|
3
|
+
export declare type WebSocketSession = {
|
|
4
|
+
state?: any;
|
|
5
|
+
user?: string;
|
|
6
|
+
query: string;
|
|
7
|
+
ua: string;
|
|
8
|
+
ip: string;
|
|
9
|
+
id: number;
|
|
10
|
+
method: string;
|
|
11
|
+
authState?: any;
|
|
12
|
+
obs: Set<number>;
|
|
13
|
+
unauthorizedObs: Set<{
|
|
14
|
+
id: number;
|
|
15
|
+
checksum: number;
|
|
16
|
+
name: string;
|
|
17
|
+
payload: any;
|
|
18
|
+
}>;
|
|
19
|
+
c?: Context<WebSocketSession>;
|
|
20
|
+
} & uws.WebSocket;
|
|
21
|
+
export declare type HttpSession = {
|
|
22
|
+
state?: any;
|
|
23
|
+
res: uws.HttpResponse;
|
|
24
|
+
req: uws.HttpRequest;
|
|
25
|
+
user?: string;
|
|
26
|
+
query?: string;
|
|
27
|
+
parsedQuery?: ReturnType<typeof parseQuery>;
|
|
28
|
+
ua: string;
|
|
29
|
+
ip: string;
|
|
30
|
+
id: number;
|
|
31
|
+
authState?: any;
|
|
32
|
+
method: string;
|
|
33
|
+
headers: {
|
|
34
|
+
'content-length'?: number;
|
|
35
|
+
'content-type'?: string;
|
|
36
|
+
'content-encoding'?: string;
|
|
37
|
+
encoding?: string;
|
|
38
|
+
} & {
|
|
39
|
+
[key: string]: string;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
export declare type ObservableSession = {
|
|
43
|
+
id: number;
|
|
44
|
+
state?: any;
|
|
45
|
+
};
|
|
46
|
+
export declare type MinimalExternalSession = {
|
|
47
|
+
ua: string;
|
|
48
|
+
ip: string;
|
|
49
|
+
};
|
|
50
|
+
export declare type Context<S extends WebSocketSession | HttpSession | ObservableSession | MinimalExternalSession = WebSocketSession | HttpSession | ObservableSession | MinimalExternalSession> = {
|
|
51
|
+
session?: S;
|
|
52
|
+
};
|
|
53
|
+
export declare const isHttpContext: (ctx: Context<HttpSession | WebSocketSession>) => ctx is Context<HttpSession>;
|
|
54
|
+
export declare const isWsSession: (session: HttpSession | WebSocketSession) => session is WebSocketSession;
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isWsSession = exports.isHttpContext = void 0;
|
|
4
|
+
const isHttpContext = (ctx) => {
|
|
5
|
+
if ('res' in ctx?.session) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
return false;
|
|
9
|
+
};
|
|
10
|
+
exports.isHttpContext = isHttpContext;
|
|
11
|
+
const isWsSession = (session) => {
|
|
12
|
+
if (!('res' in session)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
};
|
|
17
|
+
exports.isWsSession = isWsSession;
|
|
18
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;;AAyEO,MAAM,aAAa,GAAG,CAC3B,GAA4C,EACf,EAAE;IAC/B,IAAI,KAAK,IAAI,GAAG,EAAE,OAAO,EAAE;QACzB,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAPY,QAAA,aAAa,iBAOzB;AAEM,MAAM,WAAW,GAAG,CACzB,OAAuC,EACV,EAAE;IAC/B,IAAI,CAAC,CAAC,KAAK,IAAI,OAAO,CAAC,EAAE;QACvB,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAPY,QAAA,WAAW,eAOvB"}
|
|
@@ -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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OAAO,CAAC,OAAO,CAAC,GAAG,4BAA4B;KACtE;IACD,CAAC,sBAAc,CAAC,cAAc,CAAC,EAAE;QAC/B,UAAU,EAAE,GAAG;QACf,aAAa,EAAE,iBAAiB;QAChC,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,iBAAiB;KAC3D;IACD,CAAC,sBAAc,CAAC,gBAAgB,CAAC,EAAE;QACjC,UAAU,EAAE,GAAG;QACf,aAAa,EAAE,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>;
|