@based/server 4.0.0 → 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.
- package/dist/BasedServerClient.d.ts +71 -0
- package/dist/BasedServerClient.js +390 -0
- package/dist/BasedServerClient.js.map +1 -0
- package/dist/Client.d.ts +75 -0
- package/dist/Client.js +277 -0
- package/dist/Client.js.map +1 -0
- package/dist/Params.d.ts +20 -0
- package/dist/Params.js +48 -0
- package/dist/Params.js.map +1 -0
- package/dist/auth/authorize.d.ts +2 -0
- package/dist/auth/authorize.js +8 -0
- package/dist/auth/authorize.js.map +1 -0
- package/dist/clientContext.d.ts +0 -0
- package/dist/clientContext.js +83 -0
- package/dist/clientContext.js.map +1 -0
- package/dist/closeListener.d.ts +4 -0
- package/dist/closeListener.js +13 -0
- package/dist/closeListener.js.map +1 -0
- package/dist/createSimpleServer.d.ts +22 -0
- package/dist/createSimpleServer.js +120 -0
- package/dist/createSimpleServer.js.map +1 -0
- package/dist/error.d.ts +66 -0
- package/dist/error.js +149 -0
- package/dist/error.js.map +1 -0
- package/dist/findPrefix.d.ts +3 -0
- package/dist/findPrefix.js +20 -0
- package/dist/findPrefix.js.map +1 -0
- package/dist/functions/types.d.ts +0 -2
- package/dist/functions/types.js.map +1 -1
- package/dist/functions/workerPool.d.ts +0 -0
- package/dist/functions/workerPool.js +5 -0
- package/dist/functions/workerPool.js.map +1 -0
- package/dist/getFromConfig.d.ts +3 -0
- package/dist/getFromConfig.js +50 -0
- package/dist/getFromConfig.js.map +1 -0
- package/dist/handlers/authorize.d.ts +5 -0
- package/dist/handlers/authorize.js +196 -0
- package/dist/handlers/authorize.js.map +1 -0
- package/dist/handlers/bulkUpdate/index.d.ts +5 -0
- package/dist/handlers/bulkUpdate/index.js +26 -0
- package/dist/handlers/bulkUpdate/index.js.map +1 -0
- package/dist/handlers/configuration/index.d.ts +10 -0
- package/dist/handlers/configuration/index.js +74 -0
- package/dist/handlers/configuration/index.js.map +1 -0
- package/dist/handlers/configuration/observable/index.d.ts +46 -0
- package/dist/handlers/configuration/observable/index.js +277 -0
- package/dist/handlers/configuration/observable/index.js.map +1 -0
- package/dist/handlers/configure/index.d.ts +5 -0
- package/dist/handlers/configure/index.js +44 -0
- package/dist/handlers/configure/index.js.map +1 -0
- package/dist/handlers/copy/index.d.ts +8 -0
- package/dist/handlers/copy/index.js +135 -0
- package/dist/handlers/copy/index.js.map +1 -0
- package/dist/handlers/delete/index.d.ts +5 -0
- package/dist/handlers/delete/index.js +34 -0
- package/dist/handlers/delete/index.js.map +1 -0
- package/dist/handlers/digest/index.d.ts +5 -0
- package/dist/handlers/digest/index.js +23 -0
- package/dist/handlers/digest/index.js.map +1 -0
- package/dist/handlers/functions/call.d.ts +6 -0
- package/dist/handlers/functions/call.js +54 -0
- package/dist/handlers/functions/call.js.map +1 -0
- package/dist/handlers/functions/observable/Observable.d.ts +49 -0
- package/dist/handlers/functions/observable/Observable.js +290 -0
- package/dist/handlers/functions/observable/Observable.js.map +1 -0
- package/dist/handlers/functions/observable/SharedObservable.d.ts +45 -0
- package/dist/handlers/functions/observable/SharedObservable.js +291 -0
- package/dist/handlers/functions/observable/SharedObservable.js.map +1 -0
- package/dist/handlers/functions/observable/index.d.ts +14 -0
- package/dist/handlers/functions/observable/index.js +130 -0
- package/dist/handlers/functions/observable/index.js.map +1 -0
- package/dist/handlers/get/index.d.ts +5 -0
- package/dist/handlers/get/index.js +23 -0
- package/dist/handlers/get/index.js.map +1 -0
- package/dist/handlers/getConfig/index.d.ts +5 -0
- package/dist/handlers/getConfig/index.js +38 -0
- package/dist/handlers/getConfig/index.js.map +1 -0
- package/dist/handlers/handleRequests.d.ts +5 -0
- package/dist/handlers/handleRequests.js +78 -0
- package/dist/handlers/handleRequests.js.map +1 -0
- package/dist/handlers/index.d.ts +4 -0
- package/dist/handlers/index.js +49 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/handlers/messageParser.d.ts +5 -0
- package/dist/handlers/messageParser.js +122 -0
- package/dist/handlers/messageParser.js.map +1 -0
- package/dist/handlers/removeField/index.d.ts +5 -0
- package/dist/handlers/removeField/index.js +42 -0
- package/dist/handlers/removeField/index.js.map +1 -0
- package/dist/handlers/removeType/index.d.ts +5 -0
- package/dist/handlers/removeType/index.js +30 -0
- package/dist/handlers/removeType/index.js.map +1 -0
- package/dist/handlers/rest/file/DataStream.d.ts +7 -0
- package/dist/handlers/rest/file/DataStream.js +17 -0
- package/dist/handlers/rest/file/DataStream.js.map +1 -0
- package/dist/handlers/rest/file/formStream.d.ts +4 -0
- package/dist/handlers/rest/file/formStream.js +188 -0
- package/dist/handlers/rest/file/formStream.js.map +1 -0
- package/dist/handlers/rest/file/getExtenstion.d.ts +2 -0
- package/dist/handlers/rest/file/getExtenstion.js +22 -0
- package/dist/handlers/rest/file/getExtenstion.js.map +1 -0
- package/dist/handlers/rest/file/index.d.ts +4 -0
- package/dist/handlers/rest/file/index.js +53 -0
- package/dist/handlers/rest/file/index.js.map +1 -0
- package/dist/handlers/rest/file/storeFile.d.ts +6 -0
- package/dist/handlers/rest/file/storeFile.js +44 -0
- package/dist/handlers/rest/file/storeFile.js.map +1 -0
- package/dist/handlers/rest/file/stream.d.ts +5 -0
- package/dist/handlers/rest/file/stream.js +104 -0
- package/dist/handlers/rest/file/stream.js.map +1 -0
- package/dist/handlers/rest/file/types.d.ts +9 -0
- package/dist/handlers/rest/file/types.js +3 -0
- package/dist/handlers/rest/file/types.js.map +1 -0
- package/dist/handlers/rest/getReqMessage.d.ts +3 -0
- package/dist/handlers/rest/getReqMessage.js +92 -0
- package/dist/handlers/rest/getReqMessage.js.map +1 -0
- package/dist/handlers/rest/index.d.ts +4 -0
- package/dist/handlers/rest/index.js +121 -0
- package/dist/handlers/rest/index.js.map +1 -0
- package/dist/handlers/rest/invalidReq.d.ts +4 -0
- package/dist/handlers/rest/invalidReq.js +20 -0
- package/dist/handlers/rest/invalidReq.js.map +1 -0
- package/dist/handlers/rest/parseResponse.d.ts +6 -0
- package/dist/handlers/rest/parseResponse.js +230 -0
- package/dist/handlers/rest/parseResponse.js.map +1 -0
- package/dist/handlers/rest/playground/index.d.ts +5 -0
- package/dist/handlers/rest/playground/index.js +308 -0
- package/dist/handlers/rest/playground/index.js.map +1 -0
- package/dist/handlers/rest/readBody.d.ts +3 -0
- package/dist/handlers/rest/readBody.js +45 -0
- package/dist/handlers/rest/readBody.js.map +1 -0
- package/dist/handlers/set/index.d.ts +5 -0
- package/dist/handlers/set/index.js +20 -0
- package/dist/handlers/set/index.js.map +1 -0
- package/dist/handlers/subscription/index.d.ts +32 -0
- package/dist/handlers/subscription/index.js +223 -0
- package/dist/handlers/subscription/index.js.map +1 -0
- package/dist/handlers/token.d.ts +5 -0
- package/dist/handlers/token.js +122 -0
- package/dist/handlers/token.js.map +1 -0
- package/dist/handlers/track/index.d.ts +7 -0
- package/dist/handlers/track/index.js +102 -0
- package/dist/handlers/track/index.js.map +1 -0
- package/dist/handlers/userAuth/index.d.ts +5 -0
- package/dist/handlers/userAuth/index.js +78 -0
- package/dist/handlers/userAuth/index.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/network/http/authorize.d.ts +3 -0
- package/dist/network/http/authorize.js +28 -0
- package/dist/network/http/authorize.js.map +1 -0
- package/dist/network/http/compress.d.ts +6 -0
- package/dist/network/http/compress.js +56 -0
- package/dist/network/http/compress.js.map +1 -0
- package/dist/network/http/end.d.ts +4 -0
- package/dist/network/http/end.js +19 -0
- package/dist/network/http/end.js.map +1 -0
- package/dist/network/http/function.d.ts +3 -0
- package/dist/network/http/function.js +47 -0
- package/dist/network/http/function.js.map +1 -0
- package/dist/network/http/get.d.ts +3 -0
- package/dist/network/http/get.js +129 -0
- package/dist/network/http/get.js.map +1 -0
- package/dist/network/http/index.d.ts +3 -0
- package/dist/network/http/index.js +122 -0
- package/dist/network/http/index.js.map +1 -0
- package/dist/network/http/readBody.d.ts +3 -0
- package/dist/network/http/readBody.js +112 -0
- package/dist/network/http/readBody.js.map +1 -0
- package/dist/network/http/send.d.ts +5 -0
- package/dist/network/http/send.js +60 -0
- package/dist/network/http/send.js.map +1 -0
- package/dist/network/http/streamFunction/DataStream.d.ts +7 -0
- package/dist/network/http/streamFunction/DataStream.js +19 -0
- package/dist/network/http/streamFunction/DataStream.js.map +1 -0
- package/dist/network/http/streamFunction/getExtension.d.ts +2 -0
- package/dist/network/http/streamFunction/getExtension.js +29 -0
- package/dist/network/http/streamFunction/getExtension.js.map +1 -0
- package/dist/network/http/streamFunction/index.d.ts +3 -0
- package/dist/network/http/streamFunction/index.js +81 -0
- package/dist/network/http/streamFunction/index.js.map +1 -0
- package/dist/network/http/streamFunction/multipartStream.d.ts +12 -0
- package/dist/network/http/streamFunction/multipartStream.js +208 -0
- package/dist/network/http/streamFunction/multipartStream.js.map +1 -0
- package/dist/network/http/streamFunction/stream.d.ts +5 -0
- package/dist/network/http/streamFunction/stream.js +103 -0
- package/dist/network/http/streamFunction/stream.js.map +1 -0
- package/dist/network/index.d.ts +4 -0
- package/dist/network/index.js +84 -0
- package/dist/network/index.js.map +1 -0
- package/dist/network/message/auth.d.ts +4 -0
- package/dist/network/message/auth.js +32 -0
- package/dist/network/message/auth.js.map +1 -0
- package/dist/network/message/function.d.ts +3 -0
- package/dist/network/message/function.js +67 -0
- package/dist/network/message/function.js.map +1 -0
- package/dist/network/message/get.d.ts +3 -0
- package/dist/network/message/get.js +109 -0
- package/dist/network/message/get.js.map +1 -0
- package/dist/network/message/index.d.ts +3 -0
- package/dist/network/message/index.js +62 -0
- package/dist/network/message/index.js.map +1 -0
- package/dist/network/message/observable.d.ts +5 -0
- package/dist/network/message/observable.js +103 -0
- package/dist/network/message/observable.js.map +1 -0
- package/dist/network/message/send.d.ts +4 -0
- package/dist/network/message/send.js +11 -0
- package/dist/network/message/send.js.map +1 -0
- package/dist/network/upgrade.d.ts +4 -0
- package/dist/network/upgrade.js +49 -0
- package/dist/network/upgrade.js.map +1 -0
- package/dist/network/worker/get.d.ts +0 -0
- package/dist/network/worker/get.js +122 -0
- package/dist/network/worker/get.js.map +1 -0
- package/dist/network/worker/observable.d.ts +0 -0
- package/dist/network/worker/observable.js +120 -0
- package/dist/network/worker/observable.js.map +1 -0
- package/dist/openListener.d.ts +4 -0
- package/dist/openListener.js +13 -0
- package/dist/openListener.js.map +1 -0
- package/dist/secrets.d.ts +9 -0
- package/dist/secrets.js +150 -0
- package/dist/secrets.js.map +1 -0
- package/dist/security/index.d.ts +3 -0
- package/dist/security/index.js +66 -0
- package/dist/security/index.js.map +1 -0
- package/dist/types.d.ts +129 -0
- package/dist/types.js +17 -0
- package/dist/types.js.map +1 -0
- package/dist/upgradeListener.d.ts +4 -0
- package/dist/upgradeListener.js +47 -0
- package/dist/upgradeListener.js.map +1 -0
- package/dist/worker/authorize.d.ts +5 -0
- package/dist/worker/authorize.js +15 -0
- package/dist/worker/authorize.js.map +1 -0
- package/dist/worker/fnMap.d.ts +2 -0
- package/dist/worker/fnMap.js +5 -0
- package/dist/worker/fnMap.js.map +1 -0
- package/dist/worker/functions.d.ts +3 -0
- package/dist/worker/functions.js +8 -0
- package/dist/worker/functions.js.map +1 -0
- package/dist/worker/http/function.d.ts +4 -0
- package/dist/worker/http/function.js +75 -0
- package/dist/worker/http/function.js.map +1 -0
- package/dist/worker/index.d.ts +1 -0
- package/dist/worker/index.js +101 -0
- package/dist/worker/index.js.map +1 -0
- package/dist/worker/observable.d.ts +15 -0
- package/dist/worker/observable.js +110 -0
- package/dist/worker/observable.js.map +1 -0
- package/dist/worker/ws/function.d.ts +3 -0
- package/dist/worker/ws/function.js +42 -0
- package/dist/worker/ws/function.js.map +1 -0
- package/dist/workers/index.d.ts +0 -0
- package/dist/workers/index.js +20 -0
- package/dist/workers/index.js.map +1 -0
- package/dist/workers/workerCode.d.ts +12 -0
- package/dist/workers/workerCode.js +46 -0
- package/dist/workers/workerCode.js.map +1 -0
- package/package.json +1 -1
package/dist/error.d.ts
ADDED
|
@@ -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 {};
|
package/dist/error.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createError = exports.BasedErrorCode = void 0;
|
|
4
|
+
var BasedErrorCode;
|
|
5
|
+
(function (BasedErrorCode) {
|
|
6
|
+
BasedErrorCode[BasedErrorCode["FunctionError"] = 50001] = "FunctionError";
|
|
7
|
+
BasedErrorCode[BasedErrorCode["AuthorizeFunctionError"] = 50002] = "AuthorizeFunctionError";
|
|
8
|
+
BasedErrorCode[BasedErrorCode["NoOservableCacheAvailable"] = 50003] = "NoOservableCacheAvailable";
|
|
9
|
+
BasedErrorCode[BasedErrorCode["ObservableFunctionError"] = 50004] = "ObservableFunctionError";
|
|
10
|
+
BasedErrorCode[BasedErrorCode["FunctionNotFound"] = 40401] = "FunctionNotFound";
|
|
11
|
+
BasedErrorCode[BasedErrorCode["FunctionIsNotObservable"] = 40402] = "FunctionIsNotObservable";
|
|
12
|
+
BasedErrorCode[BasedErrorCode["FunctionIsObservable"] = 40403] = "FunctionIsObservable";
|
|
13
|
+
BasedErrorCode[BasedErrorCode["FunctionIsStream"] = 40404] = "FunctionIsStream";
|
|
14
|
+
BasedErrorCode[BasedErrorCode["CannotStreamToObservableFunction"] = 40402] = "CannotStreamToObservableFunction";
|
|
15
|
+
BasedErrorCode[BasedErrorCode["AuthorizeRejectedError"] = 40301] = "AuthorizeRejectedError";
|
|
16
|
+
BasedErrorCode[BasedErrorCode["InvalidPayload"] = 40001] = "InvalidPayload";
|
|
17
|
+
BasedErrorCode[BasedErrorCode["PayloadTooLarge"] = 40002] = "PayloadTooLarge";
|
|
18
|
+
BasedErrorCode[BasedErrorCode["ChunkTooLarge"] = 40003] = "ChunkTooLarge";
|
|
19
|
+
BasedErrorCode[BasedErrorCode["UnsupportedContentEncoding"] = 40004] = "UnsupportedContentEncoding";
|
|
20
|
+
BasedErrorCode[BasedErrorCode["NoBinaryProtocol"] = 40005] = "NoBinaryProtocol";
|
|
21
|
+
BasedErrorCode[BasedErrorCode["LengthRequired"] = 41101] = "LengthRequired";
|
|
22
|
+
BasedErrorCode[BasedErrorCode["MethodNotAllowed"] = 40501] = "MethodNotAllowed";
|
|
23
|
+
})(BasedErrorCode = exports.BasedErrorCode || (exports.BasedErrorCode = {}));
|
|
24
|
+
/*
|
|
25
|
+
for functione errors
|
|
26
|
+
|
|
27
|
+
// errorData.basedMessage =
|
|
28
|
+
// typeof errorDefaults[basedCode]?.message === 'function'
|
|
29
|
+
// ? errorDefaults[basedCode]?.message(err)
|
|
30
|
+
// : errorDefaults[basedCode]?.message ||
|
|
31
|
+
// errorDefaults[basedCode]?.status ||
|
|
32
|
+
// 'Oops something went wrong'
|
|
33
|
+
// if (payload && 'err' in payload && payload instanceof Error) {
|
|
34
|
+
// Object.getOwnPropertyNames(payload.err).forEach((key: string) => {
|
|
35
|
+
// errorData[key] = payload.err[key]
|
|
36
|
+
// })
|
|
37
|
+
// } else {
|
|
38
|
+
// errorData.message = errorData.basedMessage
|
|
39
|
+
// const captureTarget = { stack: null }
|
|
40
|
+
// Error.captureStackTrace(captureTarget, createError)
|
|
41
|
+
// errorData.stack = captureTarget.stack
|
|
42
|
+
// }
|
|
43
|
+
// }
|
|
44
|
+
*/
|
|
45
|
+
const errorTypes = {
|
|
46
|
+
[BasedErrorCode.FunctionError]: {
|
|
47
|
+
statusCode: 500,
|
|
48
|
+
statusMessage: 'Internal Server Error',
|
|
49
|
+
message: (payload) => {
|
|
50
|
+
// do it nice
|
|
51
|
+
return `Error in function ${payload.route.name} [${payload.err.name}] ${payload.err.message}`;
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
[BasedErrorCode.FunctionNotFound]: {
|
|
55
|
+
statusCode: 404,
|
|
56
|
+
statusMessage: 'Not Found',
|
|
57
|
+
message: (payload) => `Function not found${payload.name ? ` '${payload.name}'` : ''}${payload.path ? ` path '${payload.path}'` : ''}`,
|
|
58
|
+
},
|
|
59
|
+
[BasedErrorCode.FunctionIsStream]: {
|
|
60
|
+
statusCode: 400,
|
|
61
|
+
statusMessage: 'Incorrect protocol',
|
|
62
|
+
message: () => 'Cannot use stream functions over websockets',
|
|
63
|
+
},
|
|
64
|
+
[BasedErrorCode.CannotStreamToObservableFunction]: {
|
|
65
|
+
statusCode: 404,
|
|
66
|
+
statusMessage: 'Not Found',
|
|
67
|
+
message: 'Cannot stream to observable function.',
|
|
68
|
+
},
|
|
69
|
+
[BasedErrorCode.AuthorizeFunctionError]: {
|
|
70
|
+
statusCode: 403,
|
|
71
|
+
statusMessage: 'Forbidden',
|
|
72
|
+
message: 'Error in authorize function',
|
|
73
|
+
},
|
|
74
|
+
[BasedErrorCode.AuthorizeRejectedError]: {
|
|
75
|
+
statusCode: 403,
|
|
76
|
+
statusMessage: 'Forbidden',
|
|
77
|
+
message: (payload) => `Authorize rejected access to ${payload.name}`,
|
|
78
|
+
},
|
|
79
|
+
[BasedErrorCode.InvalidPayload]: {
|
|
80
|
+
statusCode: 400,
|
|
81
|
+
statusMessage: 'Bad Request',
|
|
82
|
+
message: (payload) => 'Invalid payload ' + payload.name,
|
|
83
|
+
},
|
|
84
|
+
[BasedErrorCode.NoBinaryProtocol]: {
|
|
85
|
+
statusCode: 400,
|
|
86
|
+
statusMessage: 'Protocol mismatch',
|
|
87
|
+
message: () => 'Please upgrade to the latest based client',
|
|
88
|
+
},
|
|
89
|
+
[BasedErrorCode.PayloadTooLarge]: {
|
|
90
|
+
statusCode: 413,
|
|
91
|
+
status: 'Payload Too Large',
|
|
92
|
+
message: (payload) => 'PayloadTooLarge ' + payload.name,
|
|
93
|
+
},
|
|
94
|
+
[BasedErrorCode.ChunkTooLarge]: {
|
|
95
|
+
statusCode: 413,
|
|
96
|
+
status: 'Payload Too Large',
|
|
97
|
+
message: (payload) => 'ChunkTooLarge ' + payload.name,
|
|
98
|
+
},
|
|
99
|
+
[BasedErrorCode.UnsupportedContentEncoding]: {
|
|
100
|
+
statusCode: 400,
|
|
101
|
+
statusMessage: 'Incorrect content encoding',
|
|
102
|
+
},
|
|
103
|
+
[BasedErrorCode.LengthRequired]: { code: 411, status: 'Length Required' },
|
|
104
|
+
[BasedErrorCode.MethodNotAllowed]: {
|
|
105
|
+
statusCode: 405,
|
|
106
|
+
statusMessage: 'Method Not Allowed',
|
|
107
|
+
},
|
|
108
|
+
[BasedErrorCode.NoOservableCacheAvailable]: {
|
|
109
|
+
statusCode: 500,
|
|
110
|
+
statusMessage: 'Internal Server Error',
|
|
111
|
+
message: (payload) => `No observable cache available${payload.route.name} - ${payload.observableId}`,
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
const isBasedFunctionRoute = (route) => {
|
|
115
|
+
if (route && typeof route === 'object' && 'name' in route) {
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
return false;
|
|
119
|
+
};
|
|
120
|
+
const EMPTY = {
|
|
121
|
+
route: {
|
|
122
|
+
name: 'no-route',
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
const createError = (server, client, code, payload) => {
|
|
126
|
+
const type = errorTypes[code];
|
|
127
|
+
const route = !payload
|
|
128
|
+
? EMPTY.route
|
|
129
|
+
: isBasedFunctionRoute(payload)
|
|
130
|
+
? payload
|
|
131
|
+
: payload.route;
|
|
132
|
+
const errorData = {
|
|
133
|
+
code,
|
|
134
|
+
statusCode: type.statusCode,
|
|
135
|
+
statusMessage: type.statusMessage,
|
|
136
|
+
message: typeof type.message === 'function' ? type.message(payload) : type.message,
|
|
137
|
+
route,
|
|
138
|
+
};
|
|
139
|
+
if ('requestId' in payload) {
|
|
140
|
+
errorData.requestId = payload.requestId;
|
|
141
|
+
}
|
|
142
|
+
if ('observableId' in payload) {
|
|
143
|
+
errorData.observableId = payload.observableId;
|
|
144
|
+
}
|
|
145
|
+
server.emit('error', client, errorData);
|
|
146
|
+
return errorData;
|
|
147
|
+
};
|
|
148
|
+
exports.createError = createError;
|
|
149
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";;;AAGA,IAAY,cAkBX;AAlBD,WAAY,cAAc;IACxB,yEAAqB,CAAA;IACrB,2FAA8B,CAAA;IAC9B,iGAAiC,CAAA;IACjC,6FAA+B,CAAA;IAC/B,+EAAwB,CAAA;IACxB,6FAA+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I,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,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;IAEvC,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AAlCY,QAAA,WAAW,eAkCvB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = (selvaClient, type) => {
|
|
4
|
+
let idPrefix;
|
|
5
|
+
if (selvaClient.schemas) {
|
|
6
|
+
for (const db in selvaClient.schemas) {
|
|
7
|
+
const dbSchema = selvaClient.schemas[db];
|
|
8
|
+
if (dbSchema.prefixToTypeMapping) {
|
|
9
|
+
for (const prefix in dbSchema.prefixToTypeMapping) {
|
|
10
|
+
if (dbSchema.prefixToTypeMapping[prefix] === type) {
|
|
11
|
+
idPrefix = prefix;
|
|
12
|
+
break;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return idPrefix;
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=findPrefix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findPrefix.js","sourceRoot":"","sources":["../src/findPrefix.ts"],"names":[],"mappings":";;AAEA,kBAAe,CAAC,WAAwB,EAAE,IAAY,EAAiB,EAAE;IACvE,IAAI,QAAgB,CAAA;IACpB,IAAI,WAAW,CAAC,OAAO,EAAE;QACvB,KAAK,MAAM,EAAE,IAAI,WAAW,CAAC,OAAO,EAAE;YACpC,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;YACxC,IAAI,QAAQ,CAAC,mBAAmB,EAAE;gBAChC,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,mBAAmB,EAAE;oBACjD,IAAI,QAAQ,CAAC,mBAAmB,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE;wBACjD,QAAQ,GAAG,MAAM,CAAA;wBACjB,MAAK;qBACN;iBACF;aACF;SACF;KACF;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA"}
|
|
@@ -18,7 +18,6 @@ export declare type BasedObservableFunctionSpec = BasedFunctionRoute & {
|
|
|
18
18
|
checksum: number;
|
|
19
19
|
observable: true;
|
|
20
20
|
function: BasedObservableFunction;
|
|
21
|
-
stickyWorker?: string;
|
|
22
21
|
customHttpResponse?: CustomHttpResponse;
|
|
23
22
|
memCacheTimeout?: number;
|
|
24
23
|
idleTimeout?: number;
|
|
@@ -30,7 +29,6 @@ export declare type BasedFunctionSpec = BasedFunctionRoute & {
|
|
|
30
29
|
observable?: false;
|
|
31
30
|
customHttpResponse?: CustomHttpResponse;
|
|
32
31
|
checksum: number;
|
|
33
|
-
stickyWorker?: string;
|
|
34
32
|
function: BasedFunction;
|
|
35
33
|
maxExecTime?: number;
|
|
36
34
|
idleTimeout?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/functions/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/functions/types.ts"],"names":[],"mappings":";;;AA2EA,IAAY,YAKX;AALD,WAAY,YAAY;IACtB,yDAAS,CAAA;IACT,qDAAO,CAAA;IACP,uDAAQ,CAAA;IACR,mEAAc,CAAA;AAChB,CAAC,EALW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAKvB;AAED,SAAgB,wBAAwB,CACtC,EAAmD;IAEnD,OAAQ,EAAkC,CAAC,UAAU,CAAA;AACvD,CAAC;AAJD,4DAIC"}
|
|
File without changes
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// add a few worker also handle errors of observables
|
|
2
|
+
// think about making a dedicated worker for based client
|
|
3
|
+
// also make a thing 'sticky worker'
|
|
4
|
+
// cant get the server in a function like this , also not the client just PAYLOAD / OUTGOING PAYLOAD - outgoing
|
|
5
|
+
//# sourceMappingURL=workerPool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workerPool.js","sourceRoot":"","sources":["../../src/functions/workerPool.ts"],"names":[],"mappings":"AAAA,qDAAqD;AAErD,yDAAyD;AACzD,oCAAoC;AAEpC,+GAA+G"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAuthorize = exports.getFunction = void 0;
|
|
4
|
+
// ....
|
|
5
|
+
// TODO: does the same as getDefaultFunction?
|
|
6
|
+
const getFunction = async (server, name) => {
|
|
7
|
+
let fn = server.config?.functions?.[name];
|
|
8
|
+
if (!fn && server.config?.functionConfig) {
|
|
9
|
+
fn = await server.config.functionConfig.getInitial(server, name);
|
|
10
|
+
if (fn) {
|
|
11
|
+
if (!server.config.functions) {
|
|
12
|
+
server.config.functions = {};
|
|
13
|
+
}
|
|
14
|
+
server.config.functions[name] = fn;
|
|
15
|
+
fn.cnt = 0;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (fn && fn.cnt !== undefined) {
|
|
19
|
+
fn.cnt = 0;
|
|
20
|
+
}
|
|
21
|
+
return fn || null;
|
|
22
|
+
};
|
|
23
|
+
exports.getFunction = getFunction;
|
|
24
|
+
const getAuthorize = async (server) => {
|
|
25
|
+
let fn = server.config?.authorize;
|
|
26
|
+
// if from the env 'defaultAuth' call defaultAuth function as well or something?
|
|
27
|
+
// console.info('GET AUTHORIZE CONFIG')
|
|
28
|
+
if (!fn && server.config?.functionConfig) {
|
|
29
|
+
const r = await server.config.functionConfig.getInitial(server, 'authorize');
|
|
30
|
+
// console.info('GET AUTH-->', r)
|
|
31
|
+
if (r) {
|
|
32
|
+
if (!server.config.functions) {
|
|
33
|
+
server.config.functions = {};
|
|
34
|
+
}
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
server.config.functions.authorize = fn;
|
|
37
|
+
if (r.observable === false) {
|
|
38
|
+
server.config.authorize = r.function;
|
|
39
|
+
fn = r.function;
|
|
40
|
+
server.config.noAuth = false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else if (!server.config?.defaultAuthorize) {
|
|
44
|
+
server.config.noAuth = true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return fn || null;
|
|
48
|
+
};
|
|
49
|
+
exports.getAuthorize = getAuthorize;
|
|
50
|
+
//# sourceMappingURL=getFromConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFromConfig.js","sourceRoot":"","sources":["../src/getFromConfig.ts"],"names":[],"mappings":";;;AAEA,OAAO;AAEP,6CAA6C;AACtC,MAAM,WAAW,GAAG,KAAK,EAC9B,MAAmB,EACnB,IAAY,EACuC,EAAE;IACrD,IAAI,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,IAAI,CAAC,CAAA;IAEzC,IAAI,CAAC,EAAE,IAAI,MAAM,CAAC,MAAM,EAAE,cAAc,EAAE;QACxC,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QAEhE,IAAI,EAAE,EAAE;YACN,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE;gBAC5B,MAAM,CAAC,MAAM,CAAC,SAAS,GAAG,EAAE,CAAA;aAC7B;YACD,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,CAAA;YAClC,EAAE,CAAC,GAAG,GAAG,CAAC,CAAA;SACX;KACF;IAED,IAAI,EAAE,IAAI,EAAE,CAAC,GAAG,KAAK,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
|
+
import { Client } from '../Client';
|
|
4
|
+
declare const _default: (server: BasedServer, client: Client, messages: (Message | TrackMessage)[]) => Promise<(Message | TrackMessage)[] | false>;
|
|
5
|
+
export default _default;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const client_1 = require("@based/client");
|
|
4
|
+
const Params_1 = require("../Params");
|
|
5
|
+
const getFromConfig_1 = require("../getFromConfig");
|
|
6
|
+
exports.default = async (server, client, messages) => {
|
|
7
|
+
const q = [];
|
|
8
|
+
const user = client;
|
|
9
|
+
const authorize = await (0, getFromConfig_1.getAuthorize)(server);
|
|
10
|
+
for (const msg of messages) {
|
|
11
|
+
if (msg[0] === client_1.RequestTypes.Auth ||
|
|
12
|
+
msg[0] === client_1.RequestTypes.Unsubscribe ||
|
|
13
|
+
msg[0] === client_1.RequestTypes.SendSubscriptionData) {
|
|
14
|
+
q.push(true);
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
let type;
|
|
18
|
+
let name;
|
|
19
|
+
let payload;
|
|
20
|
+
if (msg[0] === client_1.RequestTypes.Track) {
|
|
21
|
+
type = 'track';
|
|
22
|
+
payload = msg[1];
|
|
23
|
+
}
|
|
24
|
+
else if (msg[0] === client_1.RequestTypes.Copy) {
|
|
25
|
+
type = 'copy';
|
|
26
|
+
payload = msg[2];
|
|
27
|
+
}
|
|
28
|
+
else if (msg[0] === client_1.RequestTypes.BulkUpdate) {
|
|
29
|
+
type = 'bulkUpdate';
|
|
30
|
+
payload = msg[2];
|
|
31
|
+
}
|
|
32
|
+
else if (msg[0] === client_1.RequestTypes.Digest) {
|
|
33
|
+
type = 'digest';
|
|
34
|
+
payload = msg[2];
|
|
35
|
+
}
|
|
36
|
+
else if (msg[0] === client_1.RequestTypes.Call) {
|
|
37
|
+
type = 'function';
|
|
38
|
+
name = msg[1];
|
|
39
|
+
payload = msg[3];
|
|
40
|
+
}
|
|
41
|
+
else if (msg[0] === client_1.RequestTypes.GetConfiguration) {
|
|
42
|
+
type = 'schema';
|
|
43
|
+
payload = msg[2];
|
|
44
|
+
}
|
|
45
|
+
else if (msg[0] === client_1.RequestTypes.Configuration) {
|
|
46
|
+
type = 'updateSchema';
|
|
47
|
+
payload = msg[2];
|
|
48
|
+
}
|
|
49
|
+
else if (msg[0] === client_1.RequestTypes.Get) {
|
|
50
|
+
type = 'get';
|
|
51
|
+
// name
|
|
52
|
+
payload = msg[2];
|
|
53
|
+
}
|
|
54
|
+
else if (msg[0] === client_1.RequestTypes.GetSubscription) {
|
|
55
|
+
type = 'get';
|
|
56
|
+
if (msg[4]) {
|
|
57
|
+
name = msg[4];
|
|
58
|
+
}
|
|
59
|
+
payload = msg[2];
|
|
60
|
+
}
|
|
61
|
+
else if (msg[0] === client_1.RequestTypes.RemoveField) {
|
|
62
|
+
type = 'removeField';
|
|
63
|
+
payload = msg[2];
|
|
64
|
+
}
|
|
65
|
+
else if (msg[0] === client_1.RequestTypes.RemoveType) {
|
|
66
|
+
type = 'removeType';
|
|
67
|
+
payload = msg[2];
|
|
68
|
+
}
|
|
69
|
+
else if (msg[0] === client_1.RequestTypes.Delete) {
|
|
70
|
+
type = 'delete';
|
|
71
|
+
payload = msg[2];
|
|
72
|
+
}
|
|
73
|
+
else if (msg[0] === client_1.RequestTypes.Set) {
|
|
74
|
+
type = 'set';
|
|
75
|
+
payload = msg[2];
|
|
76
|
+
}
|
|
77
|
+
else if (msg[0] === client_1.RequestTypes.Subscription) {
|
|
78
|
+
type = 'observe';
|
|
79
|
+
if (msg[5]) {
|
|
80
|
+
name = msg[5];
|
|
81
|
+
}
|
|
82
|
+
payload = msg[2];
|
|
83
|
+
}
|
|
84
|
+
// SendSubscriptionData not very nessecary - can be done later
|
|
85
|
+
if (!type) {
|
|
86
|
+
client.destroy();
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
if (user?.isBasedUser) {
|
|
90
|
+
q.push(user.token());
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const customAuth = name && (await (0, getFromConfig_1.getFunction)(server, name))?.authorize;
|
|
94
|
+
if (customAuth) {
|
|
95
|
+
q.push(customAuth(new Params_1.Params(server, payload, user, null, null, name, type, true)));
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
q.push(authorize(new Params_1.Params(server, payload, user, null, null, name, type, true)));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const authorized = await Promise.allSettled(q);
|
|
102
|
+
let notAuthCnt = 0;
|
|
103
|
+
for (let i = 0; i < authorized.length; i++) {
|
|
104
|
+
const isAuthorized =
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
authorized[i].status === 'fulfilled' && authorized[i].value;
|
|
107
|
+
if (!isAuthorized) {
|
|
108
|
+
const msg = messages[i - notAuthCnt];
|
|
109
|
+
messages.splice(i - notAuthCnt, 1);
|
|
110
|
+
notAuthCnt++;
|
|
111
|
+
const err =
|
|
112
|
+
// @ts-ignore
|
|
113
|
+
authorized[i].status === 'rejected' && authorized[i].reason.message;
|
|
114
|
+
// @ts-ignore
|
|
115
|
+
const code = err ? authorized[i].reason?.code || 0 : 0;
|
|
116
|
+
if (msg[0] === client_1.RequestTypes.GetSubscription) {
|
|
117
|
+
const [, id, payload, , name] = msg;
|
|
118
|
+
client.send([
|
|
119
|
+
client_1.RequestTypes.Subscription,
|
|
120
|
+
id,
|
|
121
|
+
0,
|
|
122
|
+
0,
|
|
123
|
+
{
|
|
124
|
+
type: 'AuthorizationError',
|
|
125
|
+
name: name ? `get "${name}"` : 'get',
|
|
126
|
+
message: err || 'Unauthorized request',
|
|
127
|
+
payload,
|
|
128
|
+
code,
|
|
129
|
+
auth: true,
|
|
130
|
+
},
|
|
131
|
+
]);
|
|
132
|
+
}
|
|
133
|
+
else if (msg[0] === client_1.RequestTypes.Subscription) {
|
|
134
|
+
const [, id, payload, , , name] = msg;
|
|
135
|
+
client.send([
|
|
136
|
+
client_1.RequestTypes.Subscription,
|
|
137
|
+
id,
|
|
138
|
+
0,
|
|
139
|
+
0,
|
|
140
|
+
{
|
|
141
|
+
type: 'AuthorizationError',
|
|
142
|
+
name: name ? `observe "${name}"` : 'observe',
|
|
143
|
+
message: err || 'Unauthorized request',
|
|
144
|
+
payload,
|
|
145
|
+
code,
|
|
146
|
+
auth: true,
|
|
147
|
+
},
|
|
148
|
+
]);
|
|
149
|
+
}
|
|
150
|
+
else if (msg[0] === client_1.RequestTypes.Call) {
|
|
151
|
+
const [, name, reqId, payload] = msg;
|
|
152
|
+
client.send([
|
|
153
|
+
client_1.RequestTypes.Call,
|
|
154
|
+
reqId,
|
|
155
|
+
0,
|
|
156
|
+
{
|
|
157
|
+
type: 'AuthorizationError',
|
|
158
|
+
name: `call "${name}"`,
|
|
159
|
+
auth: true,
|
|
160
|
+
message: err || 'Unauthorized request',
|
|
161
|
+
payload,
|
|
162
|
+
code,
|
|
163
|
+
},
|
|
164
|
+
]);
|
|
165
|
+
}
|
|
166
|
+
else if (msg[0] === client_1.RequestTypes.Set ||
|
|
167
|
+
msg[0] === client_1.RequestTypes.Get ||
|
|
168
|
+
msg[0] === client_1.RequestTypes.Configuration ||
|
|
169
|
+
msg[0] === client_1.RequestTypes.GetConfiguration ||
|
|
170
|
+
msg[0] === client_1.RequestTypes.Delete ||
|
|
171
|
+
msg[0] === client_1.RequestTypes.Copy ||
|
|
172
|
+
msg[0] === client_1.RequestTypes.Digest ||
|
|
173
|
+
msg[0] === client_1.RequestTypes.Track) {
|
|
174
|
+
client.send([
|
|
175
|
+
msg[0],
|
|
176
|
+
msg[1],
|
|
177
|
+
0,
|
|
178
|
+
{
|
|
179
|
+
type: 'AuthorizationError',
|
|
180
|
+
name: client_1.RequestTypes[msg[0]].toLowerCase(),
|
|
181
|
+
message: err || 'Unauthorized request',
|
|
182
|
+
auth: true,
|
|
183
|
+
code,
|
|
184
|
+
payload: msg[2], // if observe or get without name call it query
|
|
185
|
+
},
|
|
186
|
+
]);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
console.error('Not handling request in not authorized handler! ' +
|
|
190
|
+
client_1.RequestTypes[msg[0]]);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return messages;
|
|
195
|
+
};
|
|
196
|
+
//# sourceMappingURL=authorize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorize.js","sourceRoot":"","sources":["../../src/handlers/authorize.ts"],"names":[],"mappings":";;AACA,0CAAmE;AACnE,sCAAkC;AAClC,oDAA4D;AAG5D,kBAAe,KAAK,EAClB,MAAmB,EACnB,MAAc,EACd,QAAoC,EACS,EAAE;IAC/C,MAAM,CAAC,GAAG,EAAE,CAAA;IACZ,MAAM,IAAI,GAAG,MAAM,CAAA;IACnB,MAAM,SAAS,GAAG,MAAM,IAAA,4BAAY,EAAC,MAAM,CAAC,CAAA;IAE5C,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE;QAC1B,IACE,GAAG,CAAC,CAAC,CAAC,KAAK,qBAAY,CAAC,IAAI;YAC5B,GAAG,CAAC,CAAC,CAAC,KAAK,qBAAY,CAAC,WAAW;YACnC,GAAG,CAAC,CAAC,CAAC,KAAK,qBAAY,CAAC,oBAAoB,EAC5C;YACA,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACZ,SAAQ;SACT;QACD,IAAI,IAAY,CAAA;QAChB,IAAI,IAAY,CAAA;QAChB,IAAI,OAAY,CAAA;QAChB,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,qBAAY,CAAC,KAAK,EAAE;YACjC,IAAI,GAAG,OAAO,CAAA;YACd,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;SACjB;aAAM,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,qBAAY,CAAC,IAAI,EAAE;YACvC,IAAI,GAAG,MAAM,CAAA;YACb,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;SACjB;a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RequestMessage } from '@based/client';
|
|
4
|
+
declare const _default: (server: BasedServer, client: Client, [, reqId, payload]: RequestMessage<import("@based/client").GenericObject>) => Promise<void>;
|
|
5
|
+
export default _default;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const client_1 = require("@based/client");
|
|
4
|
+
exports.default = async (server, client, [, reqId, payload]) => {
|
|
5
|
+
if (typeof payload === 'string')
|
|
6
|
+
throw new Error('payload cannot be a string');
|
|
7
|
+
try {
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
const id = await server.db.update(payload.payload, payload.query);
|
|
10
|
+
client.send([client_1.RequestTypes.BulkUpdate, reqId, { id }]);
|
|
11
|
+
}
|
|
12
|
+
catch (err) {
|
|
13
|
+
client.send([
|
|
14
|
+
client_1.RequestTypes.Set,
|
|
15
|
+
reqId,
|
|
16
|
+
0,
|
|
17
|
+
{
|
|
18
|
+
type: 'ValidationError',
|
|
19
|
+
name: 'BulkUpdate',
|
|
20
|
+
message: err.message,
|
|
21
|
+
payload,
|
|
22
|
+
},
|
|
23
|
+
]);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/handlers/bulkUpdate/index.ts"],"names":[],"mappings":";;AAEA,0CAA4D;AAC5D,kBAAe,KAAK,EAClB,MAAmB,EACnB,MAAc,EACd,CAAC,EAAE,KAAK,EAAE,OAAO,CAAiB,EAClC,EAAE;IACF,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;IAC9E,IAAI;QACF,aAAa;QACb,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;QACjE,MAAM,CAAC,IAAI,CAAC,CAAC,qBAAY,CAAC,UAAU,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAA;KACtD;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,CAAC,IAAI,CAAC;YACV,qBAAY,CAAC,GAAG;YAChB,KAAK;YACL,CAAC;YACD;gBACE,IAAI,EAAE,iBAAiB;gBACvB,IAAI,EAAE,YAAY;gBAClB,OAAO,EAAE,GAAG,CAAC,OAAO;gBACpB,OAAO;aACR;SACF,CAAC,CAAA;KACH;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DataListener } from '../../types';
|
|
2
|
+
import { SharedConfigurationObservable } from './observable';
|
|
3
|
+
import { BasedServer } from '../..';
|
|
4
|
+
import Client from '../../Client';
|
|
5
|
+
import { SendSubscriptionGetDataMessage, SubscribeMessage } from '@based/client';
|
|
6
|
+
import { Params } from '../../Params';
|
|
7
|
+
import { Subscription } from '../subscription';
|
|
8
|
+
export declare const getObservable: (server: BasedServer, client: Client, [, id, payload, checksum, name]: SendSubscriptionGetDataMessage) => Promise<SharedConfigurationObservable | import("../functions/observable").SharedFunctionObservable | import("../functions/observable").FunctionObservable | Subscription>;
|
|
9
|
+
export declare const subscribeObservable: (server: BasedServer, client: Client, [, id, _payload, checksum, allwaysSend, _name]: SubscribeMessage) => Promise<void>;
|
|
10
|
+
export declare const subscribeConfiguration: (params: Params, dataListener: DataListener) => Promise<SharedConfigurationObservable>;
|