@based/server 3.4.4 → 3.4.5
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/.turbo/turbo-build.log +1 -1
- 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/auth/dummyAuth.d.ts +2 -0
- package/dist/auth/dummyAuth.js +7 -0
- package/dist/auth/dummyAuth.js.map +1 -0
- package/dist/auth/index.d.ts +11 -0
- package/dist/auth/index.js +44 -0
- package/dist/auth/index.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/error.d.ts +66 -0
- package/dist/error.js +149 -0
- package/dist/error.js.map +1 -0
- package/dist/functions/index.d.ts +48 -0
- package/dist/functions/index.js +399 -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/workerPool.d.ts +0 -0
- package/dist/functions/workerPool.js +5 -0
- package/dist/functions/workerPool.js.map +1 -0
- package/dist/handlers/rest/file/storeFile.js +33 -23
- package/dist/handlers/rest/file/storeFile.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/observable/index.d.ts +8 -0
- package/dist/observable/index.js +154 -0
- package/dist/observable/index.js.map +1 -0
- package/dist/protocol.d.ts +19 -0
- package/dist/protocol.js +212 -0
- package/dist/protocol.js.map +1 -0
- package/dist/security/index.d.ts +2 -0
- package/dist/security/index.js +57 -0
- package/dist/security/index.js.map +1 -0
- package/dist/server.d.ts +35 -0
- package/dist/server.js +99 -0
- package/dist/server.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/package.json +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorize.js","sourceRoot":"","sources":["../../src/auth/authorize.ts"],"names":[],"mappings":";;;AAEO,MAAM,SAAS,GAAc,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;IAC1E,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAFY,QAAA,SAAS,aAErB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dummyAuth.js","sourceRoot":"","sources":["../../src/auth/dummyAuth.ts"],"names":[],"mappings":";;AAAA,kBAAe,KAAK,IAAI,EAAE;IACxB,OAAO,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAA;IACpD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AuthState } from '../network/message/auth';
|
|
2
|
+
import { BasedServer } from '../server';
|
|
3
|
+
import { AuthConfig, Authorize, WebsocketClient } from '../types';
|
|
4
|
+
export declare class BasedAuth {
|
|
5
|
+
server: BasedServer;
|
|
6
|
+
config: AuthConfig;
|
|
7
|
+
authorize: Authorize;
|
|
8
|
+
constructor(server: BasedServer, config?: AuthConfig);
|
|
9
|
+
updateConfig(config: AuthConfig): void;
|
|
10
|
+
sendAuthUpdate(client: WebsocketClient, authState: AuthState): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
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.BasedAuth = void 0;
|
|
7
|
+
const utils_1 = require("@saulx/utils");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const protocol_1 = require("../protocol");
|
|
10
|
+
const dummyAuth_1 = __importDefault(require("./dummyAuth"));
|
|
11
|
+
class BasedAuth {
|
|
12
|
+
constructor(server, config) {
|
|
13
|
+
this.authorize = dummyAuth_1.default;
|
|
14
|
+
this.server = server;
|
|
15
|
+
this.config = {
|
|
16
|
+
authorizePath: (0, path_1.join)(__dirname, './dummyAuth'),
|
|
17
|
+
};
|
|
18
|
+
this.updateConfig(config);
|
|
19
|
+
}
|
|
20
|
+
updateConfig(config) {
|
|
21
|
+
if (!config) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (config.authorizePath !== this.config.authorizePath) {
|
|
25
|
+
if (this.config.authorizePath) {
|
|
26
|
+
delete require.cache[require.resolve(this.config.authorizePath)];
|
|
27
|
+
}
|
|
28
|
+
this.authorize = require(config.authorizePath);
|
|
29
|
+
for (const worker of this.server.functions.workers) {
|
|
30
|
+
worker.worker.postMessage({
|
|
31
|
+
type: 5,
|
|
32
|
+
name: 'authorize',
|
|
33
|
+
path: this.config.authorizePath,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
(0, utils_1.deepMerge)(this.config, config);
|
|
38
|
+
}
|
|
39
|
+
sendAuthUpdate(client, authState) {
|
|
40
|
+
client.ws?.send((0, protocol_1.encodeAuthResponse)((0, protocol_1.valueToBuffer)(authState)), true, false);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.BasedAuth = BasedAuth;
|
|
44
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":";;;;;;AAAA,wCAAwC;AACxC,+BAA2B;AAE3B,0CAA+D;AAG/D,4DAAmC;AAEnC,MAAa,SAAS;IAKpB,YAAY,MAAmB,EAAE,MAAmB;QAFpD,cAAS,GAAc,mBAAS,CAAA;QAG9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG;YACZ,aAAa,EAAE,IAAA,WAAI,EAAC,SAAS,EAAE,aAAa,CAAC;SAC9C,CAAA;QACD,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,aAAa,KAAK,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE;YACtD,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE;gBAC7B,OAAO,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAA;aACjE;YAED,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAA;YAE9C,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE;gBAClD,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC;oBACxB,IAAI,EAAE,CAAC;oBACP,IAAI,EAAE,WAAW;oBACjB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa;iBAChC,CAAC,CAAA;aACH;SACF;QAED,IAAA,iBAAS,EAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,CAAC;IAED,cAAc,CAAC,MAAuB,EAAE,SAAoB;QAC1D,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,IAAA,6BAAkB,EAAC,IAAA,wBAAa,EAAC,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;IAC5E,CAAC;CACF;AAxCD,8BAwCC"}
|
|
File without changes
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// import { hash } from '@saulx/hash'
|
|
2
|
+
/*
|
|
3
|
+
sharedArrayBuffer UA
|
|
4
|
+
// make a ua table and hash UA
|
|
5
|
+
// ip just in buffer format
|
|
6
|
+
// 250 bytes
|
|
7
|
+
*/
|
|
8
|
+
// export const readIpFromContext = () => {
|
|
9
|
+
// // what to read
|
|
10
|
+
// // ip
|
|
11
|
+
// // ua
|
|
12
|
+
// // id
|
|
13
|
+
// // authState
|
|
14
|
+
// /*
|
|
15
|
+
// function bytesToNumber(byteArray) {
|
|
16
|
+
// let result = 0;
|
|
17
|
+
// for (let i = byteArray.length - 1; i >= 0; i--) {
|
|
18
|
+
// result = (result * 256) + byteArray[i];
|
|
19
|
+
// }
|
|
20
|
+
// return result;
|
|
21
|
+
// }
|
|
22
|
+
// */
|
|
23
|
+
// }
|
|
24
|
+
// export const readUaFromContext = () => {}
|
|
25
|
+
// export const readQueryFromContext = () => {}
|
|
26
|
+
// export const readEncodingFromContext = () => {}
|
|
27
|
+
// export const readAuthStateFromContext = () => {}
|
|
28
|
+
// /*
|
|
29
|
+
// export type ClientContext = {
|
|
30
|
+
// query: string
|
|
31
|
+
// ua: string
|
|
32
|
+
// ip: string
|
|
33
|
+
// id: number
|
|
34
|
+
// authState?: any
|
|
35
|
+
// method: string // this will be removed
|
|
36
|
+
// headers: {
|
|
37
|
+
// 'content-length'?: number
|
|
38
|
+
// authorization?: string
|
|
39
|
+
// 'content-type'?: string
|
|
40
|
+
// 'content-encoding'?: string
|
|
41
|
+
// encoding?: string
|
|
42
|
+
// }
|
|
43
|
+
// }
|
|
44
|
+
// */
|
|
45
|
+
// const encoder = new TextEncoder()
|
|
46
|
+
// export const createContext = (
|
|
47
|
+
// ip: ArrayBuffer,
|
|
48
|
+
// ua: string,
|
|
49
|
+
// query: string,
|
|
50
|
+
// authState: any, // maybe add refresh and token (token can then have )
|
|
51
|
+
// forwardedFor: string,
|
|
52
|
+
// outgoingEncoding: string
|
|
53
|
+
// ): Uint8Array => {
|
|
54
|
+
// // IP 16 bytes
|
|
55
|
+
// // UA 8 bytes
|
|
56
|
+
// // ENCODING 1 byte (in & out)
|
|
57
|
+
// // forwarded for needs to be parsed to 16 bytes ipv6
|
|
58
|
+
// let len = 16 + 8 + 1
|
|
59
|
+
// const encodedQuery = encoder.encode(query)
|
|
60
|
+
// len += encodedQuery.byteLength
|
|
61
|
+
// const sharedBuffer = new SharedArrayBuffer(len)
|
|
62
|
+
// const view = new Uint8Array(sharedBuffer)
|
|
63
|
+
// view.set(new Uint8Array(ip), 0)
|
|
64
|
+
// const uaHash = hash(ua)
|
|
65
|
+
// let n = uaHash
|
|
66
|
+
// for (let index = 16; index < 32; index++) {
|
|
67
|
+
// const byte = n & 0xff
|
|
68
|
+
// view[index] = byte
|
|
69
|
+
// n = (n - byte) / 256
|
|
70
|
+
// }
|
|
71
|
+
// // typeof auth state is {} with refresh token and token
|
|
72
|
+
// // then
|
|
73
|
+
// // parse encoding
|
|
74
|
+
// view[32] = outgoingEncoding.includes('deflate')
|
|
75
|
+
// ? 1
|
|
76
|
+
// : outgoingEncoding.includes('gzip')
|
|
77
|
+
// ? 2
|
|
78
|
+
// : outgoingEncoding.includes('br')
|
|
79
|
+
// ? 3
|
|
80
|
+
// : 0
|
|
81
|
+
// return view
|
|
82
|
+
// }
|
|
83
|
+
//# sourceMappingURL=clientContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientContext.js","sourceRoot":"","sources":["../src/clientContext.ts"],"names":[],"mappings":"AAAA,qCAAqC;AAErC;;;;;IAKI;AAEJ,2CAA2C;AAC3C,oBAAoB;AACpB,UAAU;AACV,UAAU;AACV,UAAU;AACV,iBAAiB;AACjB,OAAO;AACP,wCAAwC;AACxC,sBAAsB;AACtB,wDAAwD;AACxD,kDAAkD;AAClD,QAAQ;AACR,qBAAqB;AACrB,IAAI;AACJ,OAAO;AACP,IAAI;AAEJ,4CAA4C;AAE5C,+CAA+C;AAE/C,kDAAkD;AAElD,mDAAmD;AAEnD,KAAK;AACL,gCAAgC;AAChC,kBAAkB;AAClB,eAAe;AACf,eAAe;AACf,eAAe;AACf,oBAAoB;AACpB,4CAA4C;AAC5C,eAAe;AACf,gCAAgC;AAChC,6BAA6B;AAC7B,8BAA8B;AAC9B,kCAAkC;AAClC,wBAAwB;AACxB,MAAM;AACN,IAAI;AACJ,KAAK;AAEL,oCAAoC;AAEpC,iCAAiC;AACjC,qBAAqB;AACrB,gBAAgB;AAChB,mBAAmB;AACnB,0EAA0E;AAC1E,0BAA0B;AAC1B,6BAA6B;AAC7B,qBAAqB;AACrB,mBAAmB;AACnB,kBAAkB;AAClB,kCAAkC;AAElC,yDAAyD;AACzD,yBAAyB;AAEzB,+CAA+C;AAE/C,mCAAmC;AAEnC,oDAAoD;AAEpD,8CAA8C;AAE9C,oCAAoC;AAEpC,4BAA4B;AAE5B,mBAAmB;AACnB,gDAAgD;AAChD,4BAA4B;AAC5B,yBAAyB;AACzB,2BAA2B;AAC3B,MAAM;AAEN,4DAA4D;AAC5D,YAAY;AAEZ,sBAAsB;AACtB,oDAAoD;AACpD,UAAU;AACV,0CAA0C;AAC1C,UAAU;AACV,wCAAwC;AACxC,UAAU;AACV,UAAU;AAEV,gBAAgB;AAChB,IAAI"}
|
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+B,CAAA;IAC/B,uFAA4B,CAAA;IAC5B,+EAAwB,CAAA;IACxB,+GAAwC,CAAA;IACxC,2FAA8B,CAAA;IAC9B,2EAAsB,CAAA;IACtB,6EAAuB,CAAA;IACvB,yEAAqB,CAAA;IACrB,mGAAkC,CAAA;IAClC,+EAAwB,CAAA;IACxB,2EAAsB,CAAA;IACtB,+EAAwB,CAAA;AAC1B,CAAC,EAlBW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAkBzB;AA0CD;;;;;;;;;;;;;;;;;;;;EAoBE;AAEF,MAAM,UAAU,GAAG;IACjB,CAAC,cAAc,CAAC,aAAa,CAAC,EAAE;QAC9B,UAAU,EAAE,GAAG;QACf,aAAa,EAAE,uBAAuB;QACtC,OAAO,EAAE,CAAC,OAAmD,EAAE,EAAE;YAC/D,aAAa;YACb,OAAO,qBAAqB,OAAO,CAAC,KAAK,CAAC,IAAI,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,KAAK,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAA;QAChG,CAAC;KACF;IACD,CAAC,cAAc,CAAC,gBAAgB,CAAC,EAAE;QACjC,UAAU,EAAE,GAAG;QACf,aAAa,EAAE,WAAW;QAC1B,OAAO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,KAAK,GAAG,CAAC,OAAO;QACpB,CAAC,CAAC,KAAK,CAAC,KAAK;QACb,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC;YAC/B,CAAC,CAAC,OAAO;YACT,CAAC,CAAC,OAAO,CAAC,KAAK,CAAA;IAEjB,MAAM,SAAS,GAAmB;QAChC,IAAI;QACJ,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,OAAO,EACL,OAAO,IAAI,CAAC,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO;QAC3E,KAAK;KACN,CAAA;IAED,IAAI,WAAW,IAAI,OAAO,EAAE;QAC1B,SAAS,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;KACxC;IAED,IAAI,cAAc,IAAI,OAAO,EAAE;QAC7B,SAAS,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAA;KAC9C;IAED,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,48 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { BasedServer } from '../server';
|
|
3
|
+
import { BasedFunctionRoute, BasedFunctionSpec, BasedObservableFunctionSpec, FunctionConfig, isObservableFunctionSpec } from '../types';
|
|
4
|
+
import { Worker } from 'node:worker_threads';
|
|
5
|
+
declare type BasedWorker = {
|
|
6
|
+
worker: Worker;
|
|
7
|
+
name?: string;
|
|
8
|
+
index: number;
|
|
9
|
+
activeObservables: number;
|
|
10
|
+
activeFunctions: number;
|
|
11
|
+
};
|
|
12
|
+
export { isObservableFunctionSpec };
|
|
13
|
+
export declare class BasedFunctions {
|
|
14
|
+
server: BasedServer;
|
|
15
|
+
config: FunctionConfig;
|
|
16
|
+
unregisterTimeout: NodeJS.Timeout;
|
|
17
|
+
workers: BasedWorker[];
|
|
18
|
+
workerResponseListeners: Map<number, (err: Error, p: any) => void>;
|
|
19
|
+
paths: {
|
|
20
|
+
[path: string]: string;
|
|
21
|
+
};
|
|
22
|
+
observables: {
|
|
23
|
+
[name: string]: BasedObservableFunctionSpec;
|
|
24
|
+
};
|
|
25
|
+
functions: {
|
|
26
|
+
[name: string]: BasedFunctionSpec;
|
|
27
|
+
};
|
|
28
|
+
beingUninstalled: {
|
|
29
|
+
[name: string]: boolean;
|
|
30
|
+
};
|
|
31
|
+
lowestWorker: BasedWorker;
|
|
32
|
+
constructor(server: BasedServer, config?: FunctionConfig);
|
|
33
|
+
workerSortLoop(): void;
|
|
34
|
+
uninstallLoop(): void;
|
|
35
|
+
updateConfig(config: FunctionConfig): void;
|
|
36
|
+
install(name: string): Promise<BasedObservableFunctionSpec | BasedFunctionSpec | false>;
|
|
37
|
+
getNameFromPath(path: string): string;
|
|
38
|
+
route(name?: string, path?: string): BasedFunctionRoute | false;
|
|
39
|
+
getFromStore(name: string): BasedObservableFunctionSpec | BasedFunctionSpec | false;
|
|
40
|
+
update(spec: BasedObservableFunctionSpec | BasedFunctionSpec): boolean;
|
|
41
|
+
remove(name: string): boolean;
|
|
42
|
+
uninstall(name: string, spec?: BasedObservableFunctionSpec | BasedFunctionSpec | false): Promise<boolean>;
|
|
43
|
+
runObservableFunction(spec: BasedFunctionSpec, id: number, error: (err: Error) => void, update: (encodedDiffData: Uint8Array, encodedData: Uint8Array, checksum: number, isDeflate: boolean) => void, payload?: any): () => void;
|
|
44
|
+
runFunction(type: 0 | 3 | 4, spec: BasedFunctionSpec, context: {
|
|
45
|
+
[key: string]: any;
|
|
46
|
+
}, // make this specific
|
|
47
|
+
payload?: Uint8Array): Promise<Uint8Array>;
|
|
48
|
+
}
|