@based/server 3.4.5 → 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 +1 -1
- package/dist/auth/dummyAuth.js +3 -2
- package/dist/auth/dummyAuth.js.map +1 -1
- package/dist/auth/index.d.ts +8 -4
- package/dist/auth/index.js +28 -23
- package/dist/auth/index.js.map +1 -1
- 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/{network/http/compress.js → compress.js} +2 -6
- 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 +10 -24
- package/dist/functions/index.js +98 -287
- package/dist/functions/index.js.map +1 -1
- package/dist/functions/timeout.d.ts +1 -1
- 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/{network → incoming}/http/function.js +13 -13
- 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/{network → incoming}/http/index.d.ts +0 -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/{network → incoming}/http/readBody.js +27 -32
- package/dist/incoming/http/readBody.js.map +1 -0
- package/dist/{handlers/rest/file → incoming/http/streamFunction}/DataStream.d.ts +0 -0
- package/dist/{network → incoming}/http/streamFunction/DataStream.js +0 -0
- package/dist/incoming/http/streamFunction/DataStream.js.map +1 -0
- package/dist/{network → incoming}/http/streamFunction/getExtension.d.ts +0 -0
- package/dist/{network → incoming}/http/streamFunction/getExtension.js +0 -0
- 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/{network → incoming}/http/streamFunction/multipartStream.js +12 -12
- package/dist/incoming/http/streamFunction/multipartStream.js.map +1 -0
- package/dist/{network → incoming}/http/streamFunction/stream.d.ts +3 -2
- package/dist/{network → incoming}/http/streamFunction/stream.js +16 -11
- package/dist/incoming/http/streamFunction/stream.js.map +1 -0
- package/dist/incoming/index.d.ts +3 -0
- package/dist/{network → incoming}/index.js +28 -28
- package/dist/incoming/index.js.map +1 -0
- package/dist/incoming/upgrade.d.ts +4 -0
- package/dist/{network → incoming}/upgrade.js +24 -9
- 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/{network/message → incoming/ws}/index.js +17 -18
- 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 -8
- package/dist/observable/index.js +25 -151
- package/dist/observable/index.js.map +1 -1
- 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 +2 -0
- package/dist/protocol.js +32 -11
- package/dist/protocol.js.map +1 -1
- 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 +42 -8
- package/dist/server.js +26 -12
- package/dist/server.js.map +1 -1
- package/package.json +16 -14
- package/.turbo/turbo-build.log +0 -4
- 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/auth/authorize.d.ts +0 -2
- package/dist/auth/authorize.js +0 -8
- package/dist/auth/authorize.js.map +0 -1
- package/dist/clientContext.d.ts +0 -0
- package/dist/clientContext.js +0 -83
- package/dist/clientContext.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/error.d.ts +0 -66
- package/dist/error.js +0 -149
- package/dist/error.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/functions/workerPool.d.ts +0 -0
- package/dist/functions/workerPool.js +0 -5
- package/dist/functions/workerPool.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 +0 -17
- 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.d.ts +0 -2
- package/dist/handlers/rest/file/getExtenstion.js +0 -22
- 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 -105
- 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/network/http/authorize.d.ts +0 -3
- package/dist/network/http/authorize.js +0 -28
- package/dist/network/http/authorize.js.map +0 -1
- package/dist/network/http/compress.d.ts +0 -6
- package/dist/network/http/compress.js.map +0 -1
- package/dist/network/http/end.d.ts +0 -4
- package/dist/network/http/end.js +0 -19
- package/dist/network/http/end.js.map +0 -1
- package/dist/network/http/function.d.ts +0 -3
- package/dist/network/http/function.js.map +0 -1
- package/dist/network/http/get.d.ts +0 -3
- package/dist/network/http/get.js +0 -129
- package/dist/network/http/get.js.map +0 -1
- package/dist/network/http/index.js +0 -122
- package/dist/network/http/index.js.map +0 -1
- package/dist/network/http/readBody.d.ts +0 -3
- package/dist/network/http/readBody.js.map +0 -1
- package/dist/network/http/send.d.ts +0 -5
- package/dist/network/http/send.js +0 -60
- package/dist/network/http/send.js.map +0 -1
- package/dist/network/http/streamFunction/DataStream.d.ts +0 -7
- package/dist/network/http/streamFunction/DataStream.js.map +0 -1
- package/dist/network/http/streamFunction/getExtension.js.map +0 -1
- package/dist/network/http/streamFunction/index.d.ts +0 -3
- package/dist/network/http/streamFunction/index.js +0 -81
- package/dist/network/http/streamFunction/index.js.map +0 -1
- package/dist/network/http/streamFunction/multipartStream.d.ts +0 -12
- package/dist/network/http/streamFunction/multipartStream.js.map +0 -1
- package/dist/network/http/streamFunction/stream.js.map +0 -1
- package/dist/network/index.d.ts +0 -4
- package/dist/network/index.js.map +0 -1
- package/dist/network/message/auth.d.ts +0 -4
- package/dist/network/message/auth.js +0 -32
- package/dist/network/message/auth.js.map +0 -1
- package/dist/network/message/function.d.ts +0 -3
- package/dist/network/message/function.js +0 -67
- package/dist/network/message/function.js.map +0 -1
- package/dist/network/message/get.d.ts +0 -3
- package/dist/network/message/get.js +0 -109
- package/dist/network/message/get.js.map +0 -1
- package/dist/network/message/index.d.ts +0 -3
- package/dist/network/message/index.js.map +0 -1
- package/dist/network/message/observable.d.ts +0 -5
- package/dist/network/message/observable.js +0 -103
- package/dist/network/message/observable.js.map +0 -1
- package/dist/network/message/send.d.ts +0 -4
- package/dist/network/message/send.js +0 -11
- package/dist/network/message/send.js.map +0 -1
- package/dist/network/upgrade.d.ts +0 -4
- package/dist/network/upgrade.js.map +0 -1
- package/dist/network/worker/get.d.ts +0 -0
- package/dist/network/worker/get.js +0 -122
- package/dist/network/worker/get.js.map +0 -1
- package/dist/network/worker/observable.d.ts +0 -0
- package/dist/network/worker/observable.js +0 -120
- package/dist/network/worker/observable.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/security/index.d.ts +0 -2
- package/dist/security/index.js +0 -57
- package/dist/security/index.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/worker/authorize.d.ts +0 -5
- package/dist/worker/authorize.js +0 -15
- package/dist/worker/authorize.js.map +0 -1
- package/dist/worker/fnMap.d.ts +0 -2
- package/dist/worker/fnMap.js +0 -5
- package/dist/worker/fnMap.js.map +0 -1
- package/dist/worker/functions.d.ts +0 -3
- package/dist/worker/functions.js +0 -8
- package/dist/worker/functions.js.map +0 -1
- package/dist/worker/http/function.d.ts +0 -4
- package/dist/worker/http/function.js +0 -75
- package/dist/worker/http/function.js.map +0 -1
- package/dist/worker/index.d.ts +0 -1
- package/dist/worker/index.js +0 -101
- package/dist/worker/index.js.map +0 -1
- package/dist/worker/observable.d.ts +0 -15
- package/dist/worker/observable.js +0 -110
- package/dist/worker/observable.js.map +0 -1
- package/dist/worker/ws/function.d.ts +0 -3
- package/dist/worker/ws/function.js +0 -42
- package/dist/worker/ws/function.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
package/dist/security/index.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.incomingCounter = void 0;
|
|
4
|
-
// import { BasedErrorCode } from '../error'
|
|
5
|
-
// import { HttpClient, isHttpClient, WebsocketClient } from '../types'
|
|
6
|
-
// token
|
|
7
|
-
const drainRequestCounter = (server) => {
|
|
8
|
-
server.requestsCounterInProgress = true;
|
|
9
|
-
server.requestsCounterTimeout = setTimeout(() => {
|
|
10
|
-
server.requestsCounterInProgress = false;
|
|
11
|
-
// every 30 second remove - 30 reqs
|
|
12
|
-
server.requestsCounter.forEach((value, ip) => {
|
|
13
|
-
if (!value.errors?.size) {
|
|
14
|
-
if (value.requests <= 0) {
|
|
15
|
-
server.requestsCounter.delete(ip);
|
|
16
|
-
return;
|
|
17
|
-
// check if client is still active ?
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
console.info('error handle different');
|
|
22
|
-
}
|
|
23
|
-
console.info('DRAIN RATELIMIT TOKENS');
|
|
24
|
-
value.requests -= 60;
|
|
25
|
-
});
|
|
26
|
-
if (server.requestsCounter.size) {
|
|
27
|
-
drainRequestCounter(server);
|
|
28
|
-
}
|
|
29
|
-
}, 30e3);
|
|
30
|
-
};
|
|
31
|
-
// not counter also rate limit adder
|
|
32
|
-
const incomingCounter = (server, ip) => {
|
|
33
|
-
let ipReqCounter = server.requestsCounter.get(ip);
|
|
34
|
-
if (!ipReqCounter) {
|
|
35
|
-
ipReqCounter = {
|
|
36
|
-
requests: 1,
|
|
37
|
-
};
|
|
38
|
-
server.requestsCounter.set(ip, ipReqCounter);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
ipReqCounter.requests++;
|
|
42
|
-
}
|
|
43
|
-
// rate limit per route....
|
|
44
|
-
if (ipReqCounter.requests > 1000) {
|
|
45
|
-
// console.info('RATE LIMIT', ip)
|
|
46
|
-
// good indicator of malicious activity
|
|
47
|
-
// server.emit('ratelimit', client)
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
if (!server.requestsCounterInProgress) {
|
|
51
|
-
drainRequestCounter(server);
|
|
52
|
-
}
|
|
53
|
-
return false;
|
|
54
|
-
};
|
|
55
|
-
exports.incomingCounter = incomingCounter;
|
|
56
|
-
// incoming error counter is also a thing
|
|
57
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/security/index.ts"],"names":[],"mappings":";;;AAEA,4CAA4C;AAC5C,uEAAuE;AAEvE,QAAQ;AAER,MAAM,mBAAmB,GAAG,CAAC,MAAmB,EAAE,EAAE;IAClD,MAAM,CAAC,yBAAyB,GAAG,IAAI,CAAA;IACvC,MAAM,CAAC,sBAAsB,GAAG,UAAU,CAAC,GAAG,EAAE;QAC9C,MAAM,CAAC,yBAAyB,GAAG,KAAK,CAAA;QAExC,oCAAoC;QAEpC,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;YAC3C,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE;gBACvB,IAAI,KAAK,CAAC,QAAQ,IAAI,CAAC,EAAE;oBACvB,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;oBACjC,OAAM;oBACN,oCAAoC;iBACrC;aACF;iBAAM;gBACL,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAA;aACvC;YACD,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAA;YACtC,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAA;QACtB,CAAC,CAAC,CAAA;QAEF,IAAI,MAAM,CAAC,eAAe,CAAC,IAAI,EAAE;YAC/B,mBAAmB,CAAC,MAAM,CAAC,CAAA;SAC5B;IACH,CAAC,EAAE,IAAI,CAAC,CAAA;AACV,CAAC,CAAA;AAED,oCAAoC;AAC7B,MAAM,eAAe,GAAG,CAAC,MAAmB,EAAE,EAAU,EAAW,EAAE;IAC1E,IAAI,YAAY,GAAG,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IACjD,IAAI,CAAC,YAAY,EAAE;QACjB,YAAY,GAAG;YACb,QAAQ,EAAE,CAAC;SACZ,CAAA;QACD,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,EAAE,YAAY,CAAC,CAAA;KAC7C;SAAM;QACL,YAAY,CAAC,QAAQ,EAAE,CAAA;KACxB;IAED,2BAA2B;IAC3B,IAAI,YAAY,CAAC,QAAQ,GAAG,IAAI,EAAE;QAChC,kCAAkC;QAClC,uCAAuC;QACvC,mCAAmC;QACnC,OAAO,IAAI,CAAA;KACZ;IAED,IAAI,CAAC,MAAM,CAAC,yBAAyB,EAAE;QACrC,mBAAmB,CAAC,MAAM,CAAC,CAAA;KAC5B;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAxBY,QAAA,eAAe,mBAwB3B;AAED,yCAAyC"}
|
package/dist/types.d.ts
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import Client from './Client';
|
|
3
|
-
import uws from '@based/uws';
|
|
4
|
-
import { ConnectOptions } from '@saulx/selva';
|
|
5
|
-
import Based from './BasedServerClient';
|
|
6
|
-
import { Params } from './Params';
|
|
7
|
-
import { BasedServer } from '.';
|
|
8
|
-
import { ErrorObject, GenericObject, Based as BasedAdminClient } from '@based/client';
|
|
9
|
-
import { Readable } from 'stream';
|
|
10
|
-
export { Client };
|
|
11
|
-
export declare type CallParams = Omit<Params, 'update'>;
|
|
12
|
-
export declare type ObservableParams = Omit<Params, 'user'>;
|
|
13
|
-
export declare type DataListener = (data: GenericObject, checksum: number, error?: ErrorObject) => void;
|
|
14
|
-
export declare type ObservableFunction = {
|
|
15
|
-
function: (params: ObservableParams) => Promise<() => void>;
|
|
16
|
-
authorize?: (params: CallParams) => Promise<boolean>;
|
|
17
|
-
observable: true;
|
|
18
|
-
shared: boolean;
|
|
19
|
-
cnt?: number;
|
|
20
|
-
worker?: boolean;
|
|
21
|
-
};
|
|
22
|
-
export declare type CallFunction = {
|
|
23
|
-
observable: false;
|
|
24
|
-
authorize?: (params: CallParams) => Promise<boolean>;
|
|
25
|
-
function: (params: CallParams) => Promise<any>;
|
|
26
|
-
cnt?: number;
|
|
27
|
-
worker?: boolean;
|
|
28
|
-
headers?: (params: CallParams, result: any) => Promise<{
|
|
29
|
-
[key: string]: string;
|
|
30
|
-
}>;
|
|
31
|
-
};
|
|
32
|
-
export declare const isCallFunction: (fn: CallFunction | ObservableFunction) => fn is CallFunction;
|
|
33
|
-
export declare const isObservableFunction: (fn: CallFunction | ObservableFunction) => fn is ObservableFunction;
|
|
34
|
-
export declare type AuthorizeFn = (params: Params) => Promise<boolean>;
|
|
35
|
-
export declare type LoginFn = (params: Params) => Promise<GenericObject>;
|
|
36
|
-
export declare type LogoutFn = (params: Params) => Promise<GenericObject>;
|
|
37
|
-
export declare type RenewTokenFn = (params: Params) => Promise<GenericObject>;
|
|
38
|
-
export declare type FileOpts = {
|
|
39
|
-
based: Based;
|
|
40
|
-
stream: Readable;
|
|
41
|
-
mimeType: string;
|
|
42
|
-
id: string;
|
|
43
|
-
extension: string;
|
|
44
|
-
size: number;
|
|
45
|
-
user?: Client;
|
|
46
|
-
};
|
|
47
|
-
export declare type GetInitial = (server: BasedServer, name: string) => Promise<ObservableFunction | CallFunction | null>;
|
|
48
|
-
export declare type Geo = {
|
|
49
|
-
iso: string;
|
|
50
|
-
long: number;
|
|
51
|
-
lat: number;
|
|
52
|
-
regions: string[];
|
|
53
|
-
};
|
|
54
|
-
export declare type Config = {
|
|
55
|
-
noAuth?: boolean;
|
|
56
|
-
getBasedKey?: () => Promise<string>;
|
|
57
|
-
getApiKeysPublicKey?: () => Promise<string>;
|
|
58
|
-
getGeo?: (ip: string) => Geo;
|
|
59
|
-
sendEmail?: (payload: {
|
|
60
|
-
to: string;
|
|
61
|
-
subject: string;
|
|
62
|
-
body: string;
|
|
63
|
-
from?: string;
|
|
64
|
-
}) => Promise<{
|
|
65
|
-
status: 'ok';
|
|
66
|
-
message?: string;
|
|
67
|
-
} | {
|
|
68
|
-
status: 'error';
|
|
69
|
-
message: string;
|
|
70
|
-
}>;
|
|
71
|
-
storeFile?: (opts: FileOpts) => Promise<{
|
|
72
|
-
src: string;
|
|
73
|
-
origin: string;
|
|
74
|
-
status: number;
|
|
75
|
-
statusText?: string;
|
|
76
|
-
thumb?: string;
|
|
77
|
-
version?: string;
|
|
78
|
-
mimeType?: string;
|
|
79
|
-
}>;
|
|
80
|
-
deleteFile?: (opts: {
|
|
81
|
-
based: Based;
|
|
82
|
-
id: string;
|
|
83
|
-
db?: string;
|
|
84
|
-
}) => Promise<boolean>;
|
|
85
|
-
getAdmin?: (key: string) => Promise<BasedAdminClient>;
|
|
86
|
-
functionConfig?: {
|
|
87
|
-
idleTimeout: number;
|
|
88
|
-
getInitial: GetInitial;
|
|
89
|
-
subscribeFunctions: (cb: (err: Error, d?: any) => void) => Promise<() => void>;
|
|
90
|
-
clear: (server: BasedServer, name: string) => Promise<void>;
|
|
91
|
-
};
|
|
92
|
-
secretsConfig?: {
|
|
93
|
-
secretTimeouts?: {
|
|
94
|
-
[name: string]: number;
|
|
95
|
-
};
|
|
96
|
-
idleTimeout: number;
|
|
97
|
-
getInitial: (server: BasedServer, name: string) => Promise<string | null>;
|
|
98
|
-
clear: (server: BasedServer, name: string) => Promise<void>;
|
|
99
|
-
};
|
|
100
|
-
secrets?: {
|
|
101
|
-
[key: string]: any;
|
|
102
|
-
};
|
|
103
|
-
authorizeConnection?: Authorize;
|
|
104
|
-
authorize?: AuthorizeFn;
|
|
105
|
-
defaultAuthorize?: AuthorizeFn;
|
|
106
|
-
login?: LoginFn;
|
|
107
|
-
logout?: LogoutFn;
|
|
108
|
-
renewToken?: RenewTokenFn;
|
|
109
|
-
functions?: {
|
|
110
|
-
[key: string]: ObservableFunction | CallFunction;
|
|
111
|
-
};
|
|
112
|
-
onOpen?: (...args: any[]) => void;
|
|
113
|
-
onClose?: (...args: any[]) => void;
|
|
114
|
-
};
|
|
115
|
-
export declare type Authorize = (req: uws.HttpRequest, ctx: uws.us_socket_context_t) => Promise<boolean>;
|
|
116
|
-
export declare type ServerOptions = {
|
|
117
|
-
port?: number;
|
|
118
|
-
useLessMemory?: boolean;
|
|
119
|
-
key?: string;
|
|
120
|
-
cert?: string;
|
|
121
|
-
debug?: boolean;
|
|
122
|
-
db: ConnectOptions;
|
|
123
|
-
config?: Config;
|
|
124
|
-
state?: GenericObject;
|
|
125
|
-
};
|
|
126
|
-
export declare type SendTokenOptions = {
|
|
127
|
-
isBasedUser?: boolean;
|
|
128
|
-
isApiKey?: boolean;
|
|
129
|
-
};
|
package/dist/types.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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.isObservableFunction = exports.isCallFunction = exports.Client = void 0;
|
|
7
|
-
const Client_1 = __importDefault(require("./Client"));
|
|
8
|
-
exports.Client = Client_1.default;
|
|
9
|
-
const isCallFunction = (fn) => {
|
|
10
|
-
return fn.observable === false;
|
|
11
|
-
};
|
|
12
|
-
exports.isCallFunction = isCallFunction;
|
|
13
|
-
const isObservableFunction = (fn) => {
|
|
14
|
-
return fn.observable === true;
|
|
15
|
-
};
|
|
16
|
-
exports.isObservableFunction = isObservableFunction;
|
|
17
|
-
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA6B;AAapB,iBAbF,gBAAM,CAaE;AAmCR,MAAM,cAAc,GAAG,CAC5B,EAAqC,EACjB,EAAE;IACtB,OAAO,EAAE,CAAC,UAAU,KAAK,KAAK,CAAA;AAChC,CAAC,CAAA;AAJY,QAAA,cAAc,kBAI1B;AAEM,MAAM,oBAAoB,GAAG,CAClC,EAAqC,EACX,EAAE;IAC5B,OAAO,EAAE,CAAC,UAAU,KAAK,IAAI,CAAA;AAC/B,CAAC,CAAA;AAJY,QAAA,oBAAoB,wBAIhC"}
|
package/dist/upgradeListener.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = (server, res, req,
|
|
4
|
-
// eslint-disable-next-line
|
|
5
|
-
ctx) => {
|
|
6
|
-
let aborted;
|
|
7
|
-
const onAborted = () => {
|
|
8
|
-
aborted = true;
|
|
9
|
-
};
|
|
10
|
-
// res.writeStatus('101 Switching Protocols')
|
|
11
|
-
const onAuth = (authorized) => {
|
|
12
|
-
if (aborted) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
if (authorized) {
|
|
16
|
-
const query = req.getQuery();
|
|
17
|
-
const url = req.getUrl();
|
|
18
|
-
const ua = req.getHeader('user-agent');
|
|
19
|
-
const ip = req.getHeader('x-forwarded-for') ||
|
|
20
|
-
Buffer.from(res.getRemoteAddressAsText()).toString();
|
|
21
|
-
const origin = req.getHeader('origin');
|
|
22
|
-
const secWebSocketKey = req.getHeader('sec-websocket-key');
|
|
23
|
-
const secWebSocketProtocol = req.getHeader('sec-websocket-protocol');
|
|
24
|
-
const secWebSocketExtensions = req.getHeader('sec-websocket-extensions');
|
|
25
|
-
res.writeStatus('101 Switching Protocols');
|
|
26
|
-
res.upgrade({
|
|
27
|
-
query,
|
|
28
|
-
origin,
|
|
29
|
-
url,
|
|
30
|
-
ua,
|
|
31
|
-
ip,
|
|
32
|
-
}, secWebSocketKey, secWebSocketProtocol, secWebSocketExtensions, ctx);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
res.writeStatus('401 Unauthorized');
|
|
36
|
-
res.end();
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
res.onAborted(onAborted);
|
|
40
|
-
if (server.config && server.config.authorizeConnection) {
|
|
41
|
-
server.config.authorizeConnection(req, ctx).then(onAuth);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
onAuth(true);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
//# sourceMappingURL=upgradeListener.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"upgradeListener.js","sourceRoot":"","sources":["../src/upgradeListener.ts"],"names":[],"mappings":";;AAGA,kBAAe,CACb,MAAmB,EACnB,GAAqB,EACrB,GAAoB;AACpB,2BAA2B;AAC3B,GAA4B,EAC5B,EAAE;IACF,IAAI,OAAO,CAAA;IACX,MAAM,SAAS,GAAG,GAAG,EAAE;QACrB,OAAO,GAAG,IAAI,CAAA;IAChB,CAAC,CAAA;IACD,6CAA6C;IAE7C,MAAM,MAAM,GAAG,CAAC,UAAU,EAAE,EAAE;QAC5B,IAAI,OAAO,EAAE;YACX,OAAM;SACP;QACD,IAAI,UAAU,EAAE;YACd,MAAM,KAAK,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAA;YAC5B,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,EAAE,CAAA;YACxB,MAAM,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,YAAY,CAAC,CAAA;YACtC,MAAM,EAAE,GACN,GAAG,CAAC,SAAS,CAAC,iBAAiB,CAAC;gBAChC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,sBAAsB,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAA;YACtD,MAAM,MAAM,GAAG,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAA;YACtC,MAAM,eAAe,GAAG,GAAG,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAA;YAC1D,MAAM,oBAAoB,GAAG,GAAG,CAAC,SAAS,CAAC,wBAAwB,CAAC,CAAA;YACpE,MAAM,sBAAsB,GAAG,GAAG,CAAC,SAAS,CAAC,0BAA0B,CAAC,CAAA;YAExE,GAAG,CAAC,WAAW,CAAC,yBAAyB,CAAC,CAAA;YAE1C,GAAG,CAAC,OAAO,CACT;gBACE,KAAK;gBACL,MAAM;gBACN,GAAG;gBACH,EAAE;gBACF,EAAE;aACH,EACD,eAAe,EACf,oBAAoB,EACpB,sBAAsB,EACtB,GAAG,CACJ,CAAA;SACF;aAAM;YACL,GAAG,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAA;YACnC,GAAG,CAAC,GAAG,EAAE,CAAA;SACV;IACH,CAAC,CAAA;IAED,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;IAExB,IAAI,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,mBAAmB,EAAE;QACtD,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;KACzD;SAAM;QACL,MAAM,CAAC,IAAI,CAAC,CAAA;KACb;AACH,CAAC,CAAA"}
|
package/dist/worker/authorize.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.authorize = exports.state = void 0;
|
|
4
|
-
const worker_threads_1 = require("worker_threads");
|
|
5
|
-
exports.state = {};
|
|
6
|
-
const authorize = async (client, name, payload) => {
|
|
7
|
-
if (!exports.state.authorize) {
|
|
8
|
-
console.warn('No authorize installed in worker...', worker_threads_1.threadId);
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
11
|
-
// needs callstack...
|
|
12
|
-
return exports.state.authorize(client, name, payload);
|
|
13
|
-
};
|
|
14
|
-
exports.authorize = authorize;
|
|
15
|
-
//# sourceMappingURL=authorize.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authorize.js","sourceRoot":"","sources":["../../src/worker/authorize.ts"],"names":[],"mappings":";;;AAAA,mDAAyC;AAG5B,QAAA,KAAK,GAEd,EAAE,CAAA;AAEC,MAAM,SAAS,GAAc,KAAK,EACvC,MAAqB,EACrB,IAAY,EACZ,OAAa,EACb,EAAE;IACF,IAAI,CAAC,aAAK,CAAC,SAAS,EAAE;QACpB,OAAO,CAAC,IAAI,CAAC,qCAAqC,EAAE,yBAAQ,CAAC,CAAA;QAC7D,OAAO,IAAI,CAAA;KACZ;IACD,qBAAqB;IACrB,OAAO,aAAK,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;AAC/C,CAAC,CAAA;AAXY,QAAA,SAAS,aAWrB"}
|
package/dist/worker/fnMap.d.ts
DELETED
package/dist/worker/fnMap.js
DELETED
package/dist/worker/fnMap.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fnMap.js","sourceRoot":"","sources":["../../src/worker/fnMap.ts"],"names":[],"mappings":";;AAAA,MAAM,KAAK,GAAwB,IAAI,GAAG,EAAE,CAAA;AAE5C,kBAAe,KAAK,CAAA"}
|
package/dist/worker/functions.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fnInstallListeners = exports.fnPathMap = void 0;
|
|
4
|
-
const fnPathMap = new Map();
|
|
5
|
-
exports.fnPathMap = fnPathMap;
|
|
6
|
-
const fnInstallListeners = new Map();
|
|
7
|
-
exports.fnInstallListeners = fnInstallListeners;
|
|
8
|
-
//# sourceMappingURL=functions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/worker/functions.ts"],"names":[],"mappings":";;;AAAA,MAAM,SAAS,GAAwB,IAAI,GAAG,EAAE,CAAA;AAKvC,8BAAS;AAHlB,MAAM,kBAAkB,GACtB,IAAI,GAAG,EAAE,CAAA;AAES,gDAAkB"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { ClientContext } from '../../types';
|
|
2
|
-
export declare const parsePayload: (id: number, context: ClientContext, data: Uint8Array) => any;
|
|
3
|
-
declare const _default: (name: string, type: number, path: string, id: number, context: ClientContext, payload?: Uint8Array) => void;
|
|
4
|
-
export default _default;
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parsePayload = void 0;
|
|
4
|
-
const worker_threads_1 = require("worker_threads");
|
|
5
|
-
const utils_1 = require("@saulx/utils");
|
|
6
|
-
const authorize_1 = require("../authorize");
|
|
7
|
-
const decoder = new TextDecoder('utf-8');
|
|
8
|
-
const parsePayload = (id, context, data) => {
|
|
9
|
-
const contentType = context.headers['content-type'];
|
|
10
|
-
if (contentType === 'application/json' || !contentType) {
|
|
11
|
-
const str = decoder.decode(data);
|
|
12
|
-
let parsedData;
|
|
13
|
-
try {
|
|
14
|
-
parsedData = data.byteLength ? JSON.parse(str) : undefined;
|
|
15
|
-
return parsedData;
|
|
16
|
-
}
|
|
17
|
-
catch (err) {
|
|
18
|
-
worker_threads_1.parentPort.postMessage({
|
|
19
|
-
id,
|
|
20
|
-
err,
|
|
21
|
-
});
|
|
22
|
-
// sendHttpError(server, client, BasedErrorCode.InvalidPayload, route)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
else if (contentType.startsWith('text') ||
|
|
26
|
-
contentType === 'application/xml') {
|
|
27
|
-
return decoder.decode(data);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
return data;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
exports.parsePayload = parsePayload;
|
|
34
|
-
exports.default = (name, type, path, id, context, payload) => {
|
|
35
|
-
const fn = require(path);
|
|
36
|
-
let parsedPayload;
|
|
37
|
-
if (payload) {
|
|
38
|
-
parsedPayload = (0, exports.parsePayload)(id, context, payload);
|
|
39
|
-
}
|
|
40
|
-
else if (type === 4) {
|
|
41
|
-
parsedPayload = (0, utils_1.parseQuery)(context.query);
|
|
42
|
-
}
|
|
43
|
-
(0, authorize_1.authorize)(context, name, payload)
|
|
44
|
-
.then((ok) => {
|
|
45
|
-
if (!ok) {
|
|
46
|
-
console.error('autn wrong');
|
|
47
|
-
// err will become based error
|
|
48
|
-
worker_threads_1.parentPort.postMessage({
|
|
49
|
-
id,
|
|
50
|
-
err: new Error('AITH WRONG'),
|
|
51
|
-
});
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
fn(parsedPayload, {})
|
|
55
|
-
.then((v) => {
|
|
56
|
-
worker_threads_1.parentPort.postMessage({
|
|
57
|
-
id,
|
|
58
|
-
payload: v,
|
|
59
|
-
});
|
|
60
|
-
})
|
|
61
|
-
.catch((err) => {
|
|
62
|
-
worker_threads_1.parentPort.postMessage({
|
|
63
|
-
id,
|
|
64
|
-
err,
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
})
|
|
68
|
-
.catch((err) => {
|
|
69
|
-
worker_threads_1.parentPort.postMessage({
|
|
70
|
-
id,
|
|
71
|
-
err,
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
//# sourceMappingURL=function.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"function.js","sourceRoot":"","sources":["../../../src/worker/http/function.ts"],"names":[],"mappings":";;;AACA,mDAA2C;AAC3C,wCAAyC;AACzC,4CAAwC;AAExC,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,OAAO,CAAC,CAAA;AAEjC,MAAM,YAAY,GAAG,CAC1B,EAAU,EACV,OAAsB,EACtB,IAAgB,EACX,EAAE;IACP,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA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B,8BAA8B;YAC9B,2BAAU,CAAC,WAAW,CAAC;gBACrB,EAAE;gBACF,GAAG,EAAE,IAAI,KAAK,CAAC,YAAY,CAAC;aAC7B,CAAC,CAAA;YACF,OAAM;SACP;QACD,EAAE,CAAC,aAAa,EAAE,EAAE,CAAC;aAClB,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YACV,2BAAU,CAAC,WAAW,CAAC;gBACrB,EAAE;gBACF,OAAO,EAAE,CAAC;aACX,CAAC,CAAA;QACJ,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACb,2BAAU,CAAC,WAAW,CAAC;gBACrB,EAAE;gBACF,GAAG;aACJ,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACN,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACb,2BAAU,CAAC,WAAW,CAAC;YACrB,EAAE;YACF,GAAG;SACJ,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACN,CAAC,CAAA"}
|
package/dist/worker/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/worker/index.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const node_worker_threads_1 = require("node:worker_threads");
|
|
7
|
-
const observable_1 = require("./observable");
|
|
8
|
-
const function_1 = __importDefault(require("./ws/function"));
|
|
9
|
-
const function_2 = __importDefault(require("./http/function"));
|
|
10
|
-
const functions_1 = require("./functions");
|
|
11
|
-
const authorize_1 = require("./authorize");
|
|
12
|
-
console.info('Start worker', node_worker_threads_1.threadId);
|
|
13
|
-
// outgoing type: 0 => install function
|
|
14
|
-
// outgoing type: 1 => GET
|
|
15
|
-
// outgoing type: 2 => OBSERVE
|
|
16
|
-
node_worker_threads_1.parentPort.on('message', (d) => {
|
|
17
|
-
// d.type === 3 // HTTP POST FN
|
|
18
|
-
// d.type === 4 // HTTP GET FN
|
|
19
|
-
// d.type === 5 // FN INSTALLED (can be observable as well)
|
|
20
|
-
// d.type === 6 // UNINSTALL FN
|
|
21
|
-
// d.type === 7 // CANNOT INSTALL FN
|
|
22
|
-
if (d.type === 5) {
|
|
23
|
-
// maybe if you install like this it gets marked for a bit longer
|
|
24
|
-
// nested functions have to be kept in mem a bit longer...
|
|
25
|
-
const x = functions_1.fnInstallListeners.get(d.name);
|
|
26
|
-
const prevPath = functions_1.fnPathMap.get(d.name);
|
|
27
|
-
if (prevPath) {
|
|
28
|
-
delete require.cache[require.resolve(prevPath)];
|
|
29
|
-
}
|
|
30
|
-
functions_1.fnPathMap.set(d.name, d.path);
|
|
31
|
-
if (x) {
|
|
32
|
-
const installedFn = require(d.path);
|
|
33
|
-
x.forEach((r) => {
|
|
34
|
-
r(installedFn);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
if (d.name === 'authorize') {
|
|
38
|
-
authorize_1.state.authorize = require(d.path);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
else if (d.type === 7) {
|
|
42
|
-
const x = functions_1.fnInstallListeners.get(d.name);
|
|
43
|
-
const prevPath = functions_1.fnPathMap.get(d.name);
|
|
44
|
-
if (prevPath) {
|
|
45
|
-
delete require.cache[require.resolve(prevPath)];
|
|
46
|
-
functions_1.fnPathMap.delete(d.path);
|
|
47
|
-
}
|
|
48
|
-
if (x) {
|
|
49
|
-
const err = new Error(`Cannot install function ${d.name}`);
|
|
50
|
-
x.forEach((r) => {
|
|
51
|
-
r(undefined, err);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
else if (d.type === 6) {
|
|
56
|
-
const path = functions_1.fnPathMap.get(d.name);
|
|
57
|
-
if (!path) {
|
|
58
|
-
// console.info('Cannot find path to uninstall', d.name)
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
console.info('Uninstall', d.name);
|
|
62
|
-
functions_1.fnPathMap.delete(path);
|
|
63
|
-
delete require.cache[require.resolve(path)];
|
|
64
|
-
}
|
|
65
|
-
else if (d.type === 3 || d.type === 4) {
|
|
66
|
-
const prevPath = functions_1.fnPathMap.get(d.name);
|
|
67
|
-
if (!prevPath) {
|
|
68
|
-
functions_1.fnPathMap.set(d.name, d.path);
|
|
69
|
-
}
|
|
70
|
-
else if (prevPath !== d.path) {
|
|
71
|
-
delete require.cache[require.resolve(prevPath)];
|
|
72
|
-
}
|
|
73
|
-
console.info('Http function...');
|
|
74
|
-
(0, function_2.default)(d.name, d.type, d.path, d.id, d.context, d.payload);
|
|
75
|
-
}
|
|
76
|
-
else if (d.type === 0) {
|
|
77
|
-
const prevPath = functions_1.fnPathMap.get(d.name);
|
|
78
|
-
if (!prevPath) {
|
|
79
|
-
functions_1.fnPathMap.set(d.name, d.path);
|
|
80
|
-
}
|
|
81
|
-
else if (prevPath !== d.path) {
|
|
82
|
-
delete require.cache[require.resolve(prevPath)];
|
|
83
|
-
}
|
|
84
|
-
(0, function_1.default)(d.name, d.path, d.id, d.context.reqId, d.context, d.context.isDeflate, d.payload);
|
|
85
|
-
}
|
|
86
|
-
else if (d.type === 1) {
|
|
87
|
-
const prevPath = functions_1.fnPathMap.get(d.name);
|
|
88
|
-
if (!prevPath) {
|
|
89
|
-
functions_1.fnPathMap.set(d.name, d.path);
|
|
90
|
-
}
|
|
91
|
-
else if (prevPath !== d.path) {
|
|
92
|
-
delete require.cache[require.resolve(prevPath)];
|
|
93
|
-
}
|
|
94
|
-
// payload is parsed for this
|
|
95
|
-
(0, observable_1.createObs)(d.id, d.path, d.payload);
|
|
96
|
-
}
|
|
97
|
-
else if (d.type === 2) {
|
|
98
|
-
(0, observable_1.closeObs)(d.id);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
//# sourceMappingURL=index.js.map
|
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AAI,CAAC,QAAQ,EAAE;YACb,qBAAS,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAA;SAC9B;aAAM,IAAI,QAAQ,KAAK,CAAC,CAAC,IAAI,EAAE;YAC9B,OAAO,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA;SAChD;QACD,6BAA6B;QAC7B,IAAA,sBAAS,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAA;KACnC;SAAM,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,EAAE;QACvB,IAAA,qBAAQ,EAAC,CAAC,CAAC,EAAE,CAAC,CAAA;KACf;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export declare type WorkerObs = {
|
|
2
|
-
id: number;
|
|
3
|
-
isDestroyed: boolean;
|
|
4
|
-
rawData?: any;
|
|
5
|
-
rawDataSize?: number;
|
|
6
|
-
diffCache?: Uint8Array;
|
|
7
|
-
previousChecksum?: number;
|
|
8
|
-
cache?: Uint8Array;
|
|
9
|
-
isDeflate?: boolean;
|
|
10
|
-
checksum?: number;
|
|
11
|
-
closeFunction?: () => void;
|
|
12
|
-
};
|
|
13
|
-
export declare const activeObs: Map<number, WorkerObs>;
|
|
14
|
-
export declare const createObs: (id: number, functionPath: string, payload?: any) => void;
|
|
15
|
-
export declare const closeObs: (id: number) => void;
|
|
@@ -1,110 +0,0 @@
|
|
|
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.closeObs = exports.createObs = exports.activeObs = void 0;
|
|
7
|
-
const protocol_1 = require("../protocol");
|
|
8
|
-
const hash_1 = require("@saulx/hash");
|
|
9
|
-
const utils_1 = require("@saulx/utils");
|
|
10
|
-
const diff_1 = __importDefault(require("@saulx/diff"));
|
|
11
|
-
const node_worker_threads_1 = require("node:worker_threads");
|
|
12
|
-
exports.activeObs = new Map();
|
|
13
|
-
const createObs = (id, functionPath, payload) => {
|
|
14
|
-
if (exports.activeObs.has(id)) {
|
|
15
|
-
console.warn('trying to creater an obs that allready exists...');
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
const obs = {
|
|
19
|
-
id,
|
|
20
|
-
isDestroyed: false,
|
|
21
|
-
};
|
|
22
|
-
exports.activeObs.set(id, obs);
|
|
23
|
-
const fn = require(functionPath);
|
|
24
|
-
const update = (data, checksum, diff, previousChecksum) => {
|
|
25
|
-
if (checksum === undefined) {
|
|
26
|
-
if (data === undefined) {
|
|
27
|
-
checksum = 0;
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
// do something
|
|
31
|
-
if (typeof data === 'object' && data !== null) {
|
|
32
|
-
checksum = (0, hash_1.hashObjectIgnoreKeyOrder)(data);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
checksum = (0, hash_1.hash)(data);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (checksum !== obs.checksum) {
|
|
40
|
-
const buff = (0, protocol_1.valueToBuffer)(data);
|
|
41
|
-
if (previousChecksum === undefined) {
|
|
42
|
-
if (typeof data === 'object' && data !== null) {
|
|
43
|
-
if (obs.rawData) {
|
|
44
|
-
diff = (0, diff_1.default)(obs.rawData, data);
|
|
45
|
-
obs.previousChecksum = obs.checksum;
|
|
46
|
-
}
|
|
47
|
-
obs.rawData = (0, utils_1.deepCopy)(data);
|
|
48
|
-
}
|
|
49
|
-
else if (obs.rawData) {
|
|
50
|
-
delete obs.rawData;
|
|
51
|
-
delete obs.rawDataSize;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
// TODO: this will all become SHAREDBUFFERS
|
|
55
|
-
// keep track globally of total mem usage
|
|
56
|
-
const [encodedData, isDeflate] = (0, protocol_1.encodeObservableResponse)(id, checksum, buff);
|
|
57
|
-
// add deflate info
|
|
58
|
-
obs.isDeflate = isDeflate;
|
|
59
|
-
obs.cache = encodedData;
|
|
60
|
-
obs.checksum = checksum;
|
|
61
|
-
if (diff) {
|
|
62
|
-
const diffBuff = (0, protocol_1.valueToBuffer)(diff);
|
|
63
|
-
const encodedDiffData = (0, protocol_1.encodeObservableDiffResponse)(id, checksum, obs.previousChecksum, diffBuff);
|
|
64
|
-
obs.diffCache = encodedDiffData;
|
|
65
|
-
// add to cache size
|
|
66
|
-
}
|
|
67
|
-
node_worker_threads_1.parentPort.postMessage({
|
|
68
|
-
id,
|
|
69
|
-
payload: {
|
|
70
|
-
diff: obs.diffCache,
|
|
71
|
-
data: encodedData,
|
|
72
|
-
checksum: checksum,
|
|
73
|
-
isDeflate: isDeflate,
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
fn(payload, update)
|
|
79
|
-
.then((close) => {
|
|
80
|
-
if (obs.isDestroyed) {
|
|
81
|
-
close();
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
obs.closeFunction = close;
|
|
85
|
-
}
|
|
86
|
-
})
|
|
87
|
-
.catch((err) => {
|
|
88
|
-
node_worker_threads_1.parentPort.postMessage({
|
|
89
|
-
id,
|
|
90
|
-
err,
|
|
91
|
-
});
|
|
92
|
-
// TODO: maybe clear instantly?
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
exports.createObs = createObs;
|
|
96
|
-
const closeObs = (id) => {
|
|
97
|
-
const obs = exports.activeObs.get(id);
|
|
98
|
-
if (!obs) {
|
|
99
|
-
console.warn('trying to close an obs that does not exist');
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
obs.isDestroyed = true;
|
|
103
|
-
if (obs.closeFunction) {
|
|
104
|
-
obs.closeFunction();
|
|
105
|
-
}
|
|
106
|
-
exports.activeObs.delete(id);
|
|
107
|
-
};
|
|
108
|
-
exports.closeObs = closeObs;
|
|
109
|
-
// make a map
|
|
110
|
-
//# sourceMappingURL=observable.js.map
|