@based/server 4.0.0 → 4.0.2
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/auth/defaultConfig.d.ts +3 -0
- package/dist/auth/defaultConfig.js +12 -0
- package/dist/auth/defaultConfig.js.map +1 -0
- package/dist/auth/index.d.ts +12 -6
- package/dist/auth/index.js +32 -20
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/parseAuthState.d.ts +2 -1
- package/dist/auth/parseAuthState.js +28 -6
- package/dist/auth/parseAuthState.js.map +1 -1
- package/dist/authorize.d.ts +9 -0
- package/dist/authorize.js +59 -0
- package/dist/authorize.js.map +1 -0
- package/dist/compress.js +3 -0
- package/dist/compress.js.map +1 -1
- package/dist/createSimpleServer.d.ts +32 -0
- package/dist/createSimpleServer.js +131 -0
- package/dist/createSimpleServer.js.map +1 -0
- package/dist/error/errorTypeHandlers.js +31 -12
- package/dist/error/errorTypeHandlers.js.map +1 -1
- package/dist/error/index.d.ts +11 -1
- package/dist/error/index.js +9 -10
- package/dist/error/index.js.map +1 -1
- package/dist/error/types.d.ts +41 -45
- package/dist/error/types.js +3 -1
- package/dist/error/types.js.map +1 -1
- package/dist/functionApi/callFunction.d.ts +3 -0
- package/dist/functionApi/callFunction.js +29 -0
- package/dist/functionApi/callFunction.js.map +1 -0
- package/dist/functionApi/client/index.d.ts +16 -0
- package/dist/functionApi/client/index.js +44 -0
- package/dist/functionApi/client/index.js.map +1 -0
- package/dist/functionApi/client/query.d.ts +11 -0
- package/dist/functionApi/client/query.js +32 -0
- package/dist/functionApi/client/query.js.map +1 -0
- package/dist/functionApi/get.d.ts +3 -0
- package/dist/functionApi/get.js +71 -0
- package/dist/functionApi/get.js.map +1 -0
- package/dist/functionApi/index.d.ts +5 -0
- package/dist/functionApi/index.js +25 -0
- package/dist/functionApi/index.js.map +1 -0
- package/dist/functionApi/observe.d.ts +4 -0
- package/dist/functionApi/observe.js +44 -0
- package/dist/functionApi/observe.js.map +1 -0
- package/dist/functionApi/stream.d.ts +3 -0
- package/dist/functionApi/stream.js +30 -0
- package/dist/functionApi/stream.js.map +1 -0
- package/dist/functions/index.d.ts +16 -8
- package/dist/functions/index.js +39 -10
- package/dist/functions/index.js.map +1 -1
- package/dist/functions/timeout.d.ts +3 -3
- package/dist/functions/timeout.js.map +1 -1
- package/dist/functions/types.d.ts +44 -32
- package/dist/functions/types.js +40 -12
- package/dist/functions/types.js.map +1 -1
- package/dist/incoming/http/authorize.d.ts +2 -2
- package/dist/incoming/http/authorize.js +4 -4
- package/dist/incoming/http/authorize.js.map +1 -1
- package/dist/incoming/http/function.d.ts +3 -4
- package/dist/incoming/http/function.js +30 -35
- package/dist/incoming/http/function.js.map +1 -1
- package/dist/incoming/http/get.d.ts +3 -3
- package/dist/incoming/http/get.js +23 -33
- package/dist/incoming/http/get.js.map +1 -1
- package/dist/incoming/http/index.js +49 -30
- package/dist/incoming/http/index.js.map +1 -1
- package/dist/incoming/http/parseQuery.d.ts +1 -1
- package/dist/incoming/http/parseQuery.js +3 -1
- package/dist/incoming/http/parseQuery.js.map +1 -1
- package/dist/incoming/http/readBody.d.ts +4 -3
- package/dist/incoming/http/readBody.js +32 -8
- package/dist/incoming/http/readBody.js.map +1 -1
- package/dist/incoming/http/streamFunction/DataStream.d.ts +8 -0
- package/dist/incoming/http/streamFunction/DataStream.js +42 -3
- package/dist/incoming/http/streamFunction/DataStream.js.map +1 -1
- package/dist/incoming/http/streamFunction/getExtension.d.ts +1 -1
- package/dist/incoming/http/streamFunction/index.d.ts +3 -3
- package/dist/incoming/http/streamFunction/index.js +6 -87
- package/dist/incoming/http/streamFunction/index.js.map +1 -1
- package/dist/incoming/http/streamFunction/multiPart/index.d.ts +4 -0
- package/dist/incoming/http/streamFunction/multiPart/index.js +66 -0
- package/dist/incoming/http/streamFunction/multiPart/index.js.map +1 -0
- package/dist/incoming/http/streamFunction/multiPart/readFormData.d.ts +12 -0
- package/dist/incoming/http/streamFunction/multiPart/readFormData.js +202 -0
- package/dist/incoming/http/streamFunction/multiPart/readFormData.js.map +1 -0
- package/dist/incoming/http/streamFunction/multipartStream.d.ts +3 -4
- package/dist/incoming/http/streamFunction/multipartStream.js +68 -66
- package/dist/incoming/http/streamFunction/multipartStream.js.map +1 -1
- package/dist/incoming/http/streamFunction/stream/createStream.d.ts +6 -0
- package/dist/incoming/http/streamFunction/stream/createStream.js +75 -0
- package/dist/incoming/http/streamFunction/stream/createStream.js.map +1 -0
- package/dist/incoming/http/streamFunction/stream/index.d.ts +4 -0
- package/dist/incoming/http/streamFunction/stream/index.js +70 -0
- package/dist/incoming/http/streamFunction/stream/index.js.map +1 -0
- package/dist/incoming/http/streamFunction/stream.d.ts +1 -1
- package/dist/incoming/index.d.ts +1 -1
- package/dist/incoming/index.js +13 -11
- package/dist/incoming/index.js.map +1 -1
- package/dist/incoming/upgrade.js +18 -9
- package/dist/incoming/upgrade.js.map +1 -1
- package/dist/incoming/ws/auth.d.ts +4 -4
- package/dist/incoming/ws/auth.js +37 -19
- package/dist/incoming/ws/auth.js.map +1 -1
- package/dist/incoming/ws/function.d.ts +2 -3
- package/dist/incoming/ws/function.js +21 -73
- package/dist/incoming/ws/function.js.map +1 -1
- package/dist/incoming/ws/get.d.ts +2 -3
- package/dist/incoming/ws/get.js +33 -54
- package/dist/incoming/ws/get.js.map +1 -1
- package/dist/incoming/ws/index.d.ts +1 -1
- package/dist/incoming/ws/index.js +2 -1
- package/dist/incoming/ws/index.js.map +1 -1
- package/dist/incoming/ws/observable.d.ts +7 -6
- package/dist/incoming/ws/observable.js +25 -49
- package/dist/incoming/ws/observable.js.map +1 -1
- package/dist/incoming/ws/types.d.ts +3 -0
- package/dist/{auth → incoming/ws}/types.js +0 -0
- package/dist/{auth → incoming/ws}/types.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/installFn.d.ts +4 -0
- package/dist/installFn.js +94 -0
- package/dist/installFn.js.map +1 -0
- package/dist/observable/create.d.ts +1 -1
- package/dist/observable/create.js +5 -1
- package/dist/observable/create.js.map +1 -1
- package/dist/observable/destroy.js +1 -1
- package/dist/observable/destroy.js.map +1 -1
- package/dist/observable/error.d.ts +1 -1
- package/dist/observable/index.d.ts +0 -1
- package/dist/observable/index.js +0 -1
- package/dist/observable/index.js.map +1 -1
- package/dist/observable/send.d.ts +3 -3
- package/dist/observable/send.js +2 -8
- package/dist/observable/send.js.map +1 -1
- package/dist/observable/start/error.d.ts +2 -1
- package/dist/observable/start/error.js +13 -11
- package/dist/observable/start/error.js.map +1 -1
- package/dist/observable/start/index.js +17 -8
- package/dist/observable/start/index.js.map +1 -1
- package/dist/observable/subscribe.d.ts +3 -3
- package/dist/observable/subscribe.js +6 -12
- package/dist/observable/subscribe.js.map +1 -1
- package/dist/observable/types.d.ts +6 -5
- package/dist/observable/unsub.d.ts +1 -1
- package/dist/observable/unsub.js.map +1 -1
- package/dist/observable/verify.d.ts +1 -1
- package/dist/observable/verify.js +1 -1
- package/dist/observable/verify.js.map +1 -1
- package/dist/protocol.d.ts +1 -0
- package/dist/protocol.js +11 -1
- package/dist/protocol.js.map +1 -1
- package/dist/security.d.ts +1 -1
- package/dist/security.js +1 -1
- package/dist/security.js.map +1 -1
- package/dist/sendError.d.ts +3 -2
- package/dist/sendError.js +30 -16
- package/dist/sendError.js.map +1 -1
- package/dist/sendHttpResponse.d.ts +1 -1
- package/dist/sendHttpResponse.js +29 -4
- package/dist/sendHttpResponse.js.map +1 -1
- package/dist/server.d.ts +10 -3
- package/dist/server.js +16 -4
- package/dist/server.js.map +1 -1
- package/dist/verifyRoute.d.ts +14 -0
- package/dist/verifyRoute.js +99 -0
- package/dist/verifyRoute.js.map +1 -0
- package/package.json +4 -2
- package/dist/api/index.d.ts +0 -7
- package/dist/api/index.js +0 -173
- package/dist/api/index.js.map +0 -1
- package/dist/auth/dummyAuth.d.ts +0 -2
- package/dist/auth/dummyAuth.js +0 -8
- package/dist/auth/dummyAuth.js.map +0 -1
- package/dist/auth/types.d.ts +0 -10
- package/dist/context.d.ts +0 -54
- package/dist/context.js +0 -18
- package/dist/context.js.map +0 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifyRoute = void 0;
|
|
4
|
+
const functions_1 = require("@based/functions");
|
|
5
|
+
const functions_2 = require("./functions");
|
|
6
|
+
const sendError_1 = require("./sendError");
|
|
7
|
+
const error_1 = require("./error");
|
|
8
|
+
const verifyRoute = (server, ctx = server.client.ctx, type, route, name, id) => {
|
|
9
|
+
if (!ctx.session) {
|
|
10
|
+
console.warn('VERIFY ROUTE NO SESSION', name);
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
if (!route) {
|
|
14
|
+
if (!(0, functions_1.isClientContext)(ctx)) {
|
|
15
|
+
throw (0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionNotFound, {
|
|
16
|
+
route: {
|
|
17
|
+
name,
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
(0, sendError_1.sendError)(server, ctx, error_1.BasedErrorCode.FunctionNotFound, type === 'query'
|
|
22
|
+
? {
|
|
23
|
+
route: { name },
|
|
24
|
+
observableId: id,
|
|
25
|
+
}
|
|
26
|
+
: {
|
|
27
|
+
route: { name },
|
|
28
|
+
requestId: id,
|
|
29
|
+
});
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
if (route.internalOnly === true && (0, functions_1.isClientContext)(ctx)) {
|
|
33
|
+
(0, sendError_1.sendError)(server, ctx, error_1.BasedErrorCode.FunctionNotFound, type === 'query'
|
|
34
|
+
? {
|
|
35
|
+
route: { name },
|
|
36
|
+
observableId: id,
|
|
37
|
+
}
|
|
38
|
+
: {
|
|
39
|
+
route: { name },
|
|
40
|
+
requestId: id,
|
|
41
|
+
});
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
if (type === 'query') {
|
|
45
|
+
if (!(0, functions_2.isQueryFunctionRoute)(route)) {
|
|
46
|
+
if (!(0, functions_1.isClientContext)(ctx)) {
|
|
47
|
+
throw (0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionIsNotObservable, {
|
|
48
|
+
route,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
(0, sendError_1.sendError)(server, ctx, error_1.BasedErrorCode.FunctionIsNotObservable, {
|
|
52
|
+
route: { name },
|
|
53
|
+
observableId: id,
|
|
54
|
+
});
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (type === 'stream') {
|
|
59
|
+
if (!(0, functions_2.isStreamFunctionRoute)(route)) {
|
|
60
|
+
if (!(0, functions_1.isClientContext)(ctx)) {
|
|
61
|
+
throw (0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionIsNotStream, {
|
|
62
|
+
route,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
(0, sendError_1.sendError)(server, ctx, error_1.BasedErrorCode.FunctionIsNotStream, {
|
|
66
|
+
route: { name },
|
|
67
|
+
requestId: id,
|
|
68
|
+
});
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (type === 'fn' && !(0, functions_2.isFunctionRoute)(route)) {
|
|
73
|
+
if (!(0, functions_1.isClientContext)(ctx)) {
|
|
74
|
+
if ((0, functions_2.isStreamFunctionRoute)(route)) {
|
|
75
|
+
throw (0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionIsNotObservable, {
|
|
76
|
+
route,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
throw (0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionIsObservable, {
|
|
80
|
+
route,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if ((0, functions_2.isStreamFunctionRoute)(route)) {
|
|
84
|
+
(0, sendError_1.sendError)(server, ctx, error_1.BasedErrorCode.FunctionIsStream, {
|
|
85
|
+
route,
|
|
86
|
+
requestId: id,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
(0, sendError_1.sendError)(server, ctx, error_1.BasedErrorCode.FunctionIsObservable, {
|
|
90
|
+
route,
|
|
91
|
+
requestId: id,
|
|
92
|
+
});
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
// @ts-ignore fixed by checking the routes
|
|
96
|
+
return route;
|
|
97
|
+
};
|
|
98
|
+
exports.verifyRoute = verifyRoute;
|
|
99
|
+
//# sourceMappingURL=verifyRoute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verifyRoute.js","sourceRoot":"","sources":["../src/verifyRoute.ts"],"names":[],"mappings":";;;AAAA,gDAA2D;AAC3D,2CAQoB;AACpB,2CAAuC;AACvC,mCAAqD;AAK9C,MAAM,WAAW,GAAG,CACzB,MAAmB,EACnB,MAAe,MAAM,CAAC,MAAM,CAAC,GAAG,EAChC,IAAO,EACP,KAAwB,EACxB,IAAY,EACZ,EAAW,EAOJ,EAAE;IACT,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE;QAChB,OAAO,CAAC,IAAI,CAAC,yBAAyB,EAAE,IAAI,CAAC,CAAA;QAC7C,OAAO,IAAI,CAAA;KACZ;IAED,IAAI,CAAC,KAAK,EAAE;QACV,IAAI,CAAC,IAAA,2BAAe,EAAC,GAAG,CAAC,EAAE;YACzB,MAAM,IAAA,mBAAW,EAAC,MAAM,EAAE,GAAG,EAAE,sBAAc,CAAC,gBAAgB,EAAE;gBAC9D,KAAK,EAAE;oBACL,IAAI;iBACL;aACF,CAAC,CAAA;SACH;QACD,IAAA,qBAAS,EACP,MAAM,EACN,GAAG,EACH,sBAAc,CAAC,gBAAgB,EAC/B,IAAI,KAAK,OAAO;YACd,CAAC,CAAC;gBACE,KAAK,EAAE,EAAE,IAAI,EAAE;gBACf,YAAY,EAAE,EAAE;aACjB;YACH,CAAC,CAAC;gBAC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MAAM,EAAE,GAAG,EAAE,sBAAc,CAAC,mBAAmB,EAAE;gBACzD,KAAK,EAAE,EAAE,IAAI,EAAE;gBACf,SAAS,EAAE,EAAE;aACd,CAAC,CAAA;YACF,OAAO,IAAI,CAAA;SACZ;KACF;IAED,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,IAAA,2BAAe,EAAC,KAAK,CAAC,EAAE;QAC5C,IAAI,CAAC,IAAA,2BAAe,EAAC,GAAG,CAAC,EAAE;YACzB,IAAI,IAAA,iCAAqB,EAAC,KAAK,CAAC,EAAE;gBAChC,MAAM,IAAA,mBAAW,EAAC,MAAM,EAAE,GAAG,EAAE,sBAAc,CAAC,uBAAuB,EAAE;oBACrE,KAAK;iBACN,CAAC,CAAA;aACH;YACD,MAAM,IAAA,mBAAW,EAAC,MAAM,EAAE,GAAG,EAAE,sBAAc,CAAC,oBAAoB,EAAE;gBAClE,KAAK;aACN,CAAC,CAAA;SACH;QACD,IAAI,IAAA,iCAAqB,EAAC,KAAK,CAAC,EAAE;YAChC,IAAA,qBAAS,EAAC,MAAM,EAAE,GAAG,EAAE,sBAAc,CAAC,gBAAgB,EAAE;gBACtD,KAAK;gBACL,SAAS,EAAE,EAAE;aACd,CAAC,CAAA;SACH;QACD,IAAA,qBAAS,EAAC,MAAM,EAAE,GAAG,EAAE,sBAAc,CAAC,oBAAoB,EAAE;YAC1D,KAAK;YACL,SAAS,EAAE,EAAE;SACd,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;KACZ;IAED,0CAA0C;IAC1C,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAtHY,QAAA,WAAW,eAsHvB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@based/server",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -22,13 +22,15 @@
|
|
|
22
22
|
"@based/uws": "2.4.0",
|
|
23
23
|
"@saulx/diff": "^1.1.3",
|
|
24
24
|
"@saulx/hash": "^1.1.0",
|
|
25
|
-
"@saulx/utils": "^2.
|
|
25
|
+
"@saulx/utils": "^3.2.0",
|
|
26
26
|
"picocolors": "^1.0.0",
|
|
27
27
|
"jsonexport": "^3.2.0",
|
|
28
28
|
"jsonwebtoken": "^8.5.1",
|
|
29
29
|
"mime-types": "^2.1.31"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
+
"@types/mime-types": "2.1.1",
|
|
33
|
+
"@based/functions": "^1.0.0",
|
|
32
34
|
"@types/node": "^17.0.23",
|
|
33
35
|
"ts-node": "^10.1.0",
|
|
34
36
|
"typescript": "^4.3.5",
|
package/dist/api/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { BasedServer } from '../server';
|
|
2
|
-
import { Context } from '../context';
|
|
3
|
-
import { ObservableUpdateFunction, ObserveErrorListener } from '../observable';
|
|
4
|
-
export declare const callFunction: (server: BasedServer, name: string, ctx: Context, payload: any) => Promise<any>;
|
|
5
|
-
export declare const get: (server: BasedServer, name: string, ctx: Context, payload: any) => Promise<any>;
|
|
6
|
-
export declare const observe: (server: BasedServer, name: string, ctx: Context, payload: any, update: ObservableUpdateFunction, error: ObserveErrorListener) => (() => void);
|
|
7
|
-
export { decode } from '../protocol';
|
package/dist/api/index.js
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.decode = exports.observe = exports.get = exports.callFunction = void 0;
|
|
4
|
-
const error_1 = require("../error");
|
|
5
|
-
const functions_1 = require("../functions");
|
|
6
|
-
const observable_1 = require("../observable");
|
|
7
|
-
const callFunction = async (server, name, ctx, payload) => {
|
|
8
|
-
const route = server.functions.route(name);
|
|
9
|
-
if (!route) {
|
|
10
|
-
throw (0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionNotFound, { name });
|
|
11
|
-
}
|
|
12
|
-
if (route.observable === true) {
|
|
13
|
-
throw (0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionIsObservable, {
|
|
14
|
-
name,
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
const fn = await server.functions.install(name);
|
|
18
|
-
if (!fn) {
|
|
19
|
-
throw (0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionNotFound, { name });
|
|
20
|
-
}
|
|
21
|
-
if ((0, functions_1.isObservableFunctionSpec)(fn)) {
|
|
22
|
-
throw (0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionIsObservable, {
|
|
23
|
-
name,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
try {
|
|
27
|
-
return fn.function(payload, ctx);
|
|
28
|
-
}
|
|
29
|
-
catch (err) {
|
|
30
|
-
throw (0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionError, {
|
|
31
|
-
route: { name },
|
|
32
|
-
err,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
exports.callFunction = callFunction;
|
|
37
|
-
const getObsData = (resolve, reject, server, id, ctx, route) => {
|
|
38
|
-
const obs = (0, observable_1.getObs)(server, id);
|
|
39
|
-
if (obs.error) {
|
|
40
|
-
reject((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.ObservableFunctionError, {
|
|
41
|
-
route,
|
|
42
|
-
observableId: id,
|
|
43
|
-
err: obs.error,
|
|
44
|
-
}));
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
if (obs.cache) {
|
|
48
|
-
resolve(obs.rawData || obs.cache);
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
(0, observable_1.subscribeNext)(obs, (err) => {
|
|
52
|
-
if (err) {
|
|
53
|
-
reject((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.ObservableFunctionError, {
|
|
54
|
-
observableId: id,
|
|
55
|
-
route,
|
|
56
|
-
err,
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
resolve(obs.rawData || obs.cache);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
const get = (server, name, ctx, payload) => {
|
|
65
|
-
return new Promise((resolve, reject) => {
|
|
66
|
-
const route = server.functions.route(name);
|
|
67
|
-
if (!route) {
|
|
68
|
-
reject((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionNotFound, { name }));
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
if (route.observable === false) {
|
|
72
|
-
reject((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionIsNotObservable, {
|
|
73
|
-
name,
|
|
74
|
-
}));
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const id = (0, observable_1.genObservableId)(name, payload);
|
|
78
|
-
if (!(0, observable_1.hasObs)(server, id)) {
|
|
79
|
-
server.functions
|
|
80
|
-
.install(name)
|
|
81
|
-
.then((fn) => {
|
|
82
|
-
if (!fn) {
|
|
83
|
-
reject((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionNotFound, {
|
|
84
|
-
name,
|
|
85
|
-
}));
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
if (!(0, functions_1.isObservableFunctionSpec)(fn)) {
|
|
89
|
-
reject((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionIsNotObservable, {
|
|
90
|
-
name,
|
|
91
|
-
}));
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
if (!(0, observable_1.hasObs)(server, id)) {
|
|
95
|
-
(0, observable_1.createObs)(server, name, id, payload);
|
|
96
|
-
}
|
|
97
|
-
getObsData(resolve, reject, server, id, ctx, route);
|
|
98
|
-
})
|
|
99
|
-
.catch(() => reject((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionNotFound, {
|
|
100
|
-
name,
|
|
101
|
-
})));
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
getObsData(resolve, reject, server, id, ctx, route);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
exports.get = get;
|
|
109
|
-
const observe = (server, name, ctx, payload, update, error) => {
|
|
110
|
-
// TODO: Callstack
|
|
111
|
-
const route = server.functions.route(name);
|
|
112
|
-
if (!route) {
|
|
113
|
-
throw (0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionNotFound, { name });
|
|
114
|
-
}
|
|
115
|
-
if (route.observable !== true) {
|
|
116
|
-
throw (0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionIsNotObservable, {
|
|
117
|
-
name,
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
const id = (0, observable_1.genObservableId)(name, payload);
|
|
121
|
-
let obs;
|
|
122
|
-
let isClosed = false;
|
|
123
|
-
const close = () => {
|
|
124
|
-
if (isClosed) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
isClosed = true;
|
|
128
|
-
if (obs) {
|
|
129
|
-
(0, observable_1.unsubscribeFunction)(server, id, update);
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
if ((0, observable_1.hasObs)(server, id)) {
|
|
133
|
-
(0, observable_1.subscribeFunction)(server, id, update);
|
|
134
|
-
return close;
|
|
135
|
-
}
|
|
136
|
-
server.functions
|
|
137
|
-
.install(name)
|
|
138
|
-
.then((spec) => {
|
|
139
|
-
if (isClosed) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
if (spec === false) {
|
|
143
|
-
error((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionNotFound, {
|
|
144
|
-
name,
|
|
145
|
-
}));
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
if (!(0, functions_1.isObservableFunctionSpec)(spec)) {
|
|
149
|
-
error((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionIsNotObservable, {
|
|
150
|
-
name,
|
|
151
|
-
}));
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
if (!(0, observable_1.hasObs)(server, id)) {
|
|
155
|
-
(0, observable_1.createObs)(server, name, id, payload);
|
|
156
|
-
}
|
|
157
|
-
(0, observable_1.subscribeFunction)(server, id, update);
|
|
158
|
-
})
|
|
159
|
-
.catch(() => {
|
|
160
|
-
if (isClosed) {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
error((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionNotFound, {
|
|
164
|
-
name,
|
|
165
|
-
}));
|
|
166
|
-
});
|
|
167
|
-
return close;
|
|
168
|
-
};
|
|
169
|
-
exports.observe = observe;
|
|
170
|
-
var protocol_1 = require("../protocol");
|
|
171
|
-
Object.defineProperty(exports, "decode", { enumerable: true, get: function () { return protocol_1.decode; } });
|
|
172
|
-
// TODO: nested stream function
|
|
173
|
-
//# sourceMappingURL=index.js.map
|
package/dist/api/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";;;AACA,oCAAsD;AAEtD,4CAA2E;AAC3E,8CAWsB;AAEf,MAAM,YAAY,GAAG,KAAK,EAC/B,MAAmB,EACnB,IAAY,EACZ,GAAY,EACZ,OAAY,EACE,EAAE;IAChB,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAE1C,IAAI,CAAC,KAAK,EAAE;QACV,MAAM,IAAA,mBAAW,EAAC,MAAM,EAAE,GAAG,EAAE,sBAAc,CAAC,gBAAgB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;KAC1E;IAED,IAAI,KAAK,CAAC,UAAU,KAAK,IAAI,EAAE;QAC7B,MAAM,IAAA,mBAAW,EAAC,MAAM,EAAE,GAAG,EAAE,sBAAc,CAAC,oBAAoB,EAAE;YAClE,IAAI;SACL,CAAC,CA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AAI;aACL,CAAC,CACH,CAAA;YACD,OAAM;SACP;QAED,IAAI,CAAC,IAAA,mBAAM,EAAC,MAAM,EAAE,EAAE,CAAC,EAAE;YACvB,IAAA,sBAAS,EAAC,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,CAAC,CAAA;SACrC;QAED,IAAA,8BAAiB,EAAC,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,CAAA;IACvC,CAAC,CAAC;SACD,KAAK,CAAC,GAAG,EAAE;QACV,IAAI,QAAQ,EAAE;YACZ,OAAM;SACP;QACD,KAAK,CACH,IAAA,mBAAW,EAAC,MAAM,EAAE,GAAG,EAAE,sBAAc,CAAC,gBAAgB,EAAE;YACxD,IAAI;SACL,CAAC,CACH,CAAA;IACH,CAAC,CAAC,CAAA;IAEJ,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAlFY,QAAA,OAAO,WAkFnB;AAED,wCAAoC;AAA3B,kGAAA,MAAM,OAAA;AAEf,+BAA+B"}
|
package/dist/auth/dummyAuth.d.ts
DELETED
package/dist/auth/dummyAuth.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// eslint-disable-next-line
|
|
4
|
-
exports.default = async (_ctx, name, payload) => {
|
|
5
|
-
// console.warn(' 🔓 Dummy auth', name, payload)
|
|
6
|
-
return true;
|
|
7
|
-
};
|
|
8
|
-
//# sourceMappingURL=dummyAuth.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dummyAuth.js","sourceRoot":"","sources":["../../src/auth/dummyAuth.ts"],"names":[],"mappings":";;AAAA,2BAA2B;AAC3B,kBAAe,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;IAC3C,gDAAgD;IAChD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"}
|
package/dist/auth/types.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { BasedServer } from '../server';
|
|
2
|
-
import { Context } from '../context';
|
|
3
|
-
import uws from '@based/uws';
|
|
4
|
-
export declare type AuthConfig = {
|
|
5
|
-
authorize?: Authorize;
|
|
6
|
-
authorizeConnection?: AuthorizeConnection;
|
|
7
|
-
};
|
|
8
|
-
export declare type Authorize = (context: Context, name: string, payload?: any) => Promise<boolean>;
|
|
9
|
-
export declare type AuthorizeHandshake = (server: BasedServer, context: Context, payload?: any) => Promise<boolean>;
|
|
10
|
-
export declare type AuthorizeConnection = (req: uws.HttpRequest) => Promise<boolean>;
|
package/dist/context.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import uws from '@based/uws';
|
|
2
|
-
import { parseQuery } from '@saulx/utils';
|
|
3
|
-
export declare type WebSocketSession = {
|
|
4
|
-
state?: any;
|
|
5
|
-
user?: string;
|
|
6
|
-
query: string;
|
|
7
|
-
ua: string;
|
|
8
|
-
ip: string;
|
|
9
|
-
id: number;
|
|
10
|
-
method: string;
|
|
11
|
-
authState?: any;
|
|
12
|
-
obs: Set<number>;
|
|
13
|
-
unauthorizedObs: Set<{
|
|
14
|
-
id: number;
|
|
15
|
-
checksum: number;
|
|
16
|
-
name: string;
|
|
17
|
-
payload: any;
|
|
18
|
-
}>;
|
|
19
|
-
c?: Context<WebSocketSession>;
|
|
20
|
-
} & uws.WebSocket;
|
|
21
|
-
export declare type HttpSession = {
|
|
22
|
-
state?: any;
|
|
23
|
-
res: uws.HttpResponse;
|
|
24
|
-
req: uws.HttpRequest;
|
|
25
|
-
user?: string;
|
|
26
|
-
query?: string;
|
|
27
|
-
parsedQuery?: ReturnType<typeof parseQuery>;
|
|
28
|
-
ua: string;
|
|
29
|
-
ip: string;
|
|
30
|
-
id: number;
|
|
31
|
-
authState?: any;
|
|
32
|
-
method: string;
|
|
33
|
-
headers: {
|
|
34
|
-
'content-length'?: number;
|
|
35
|
-
'content-type'?: string;
|
|
36
|
-
'content-encoding'?: string;
|
|
37
|
-
encoding?: string;
|
|
38
|
-
} & {
|
|
39
|
-
[key: string]: string;
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
export declare type ObservableSession = {
|
|
43
|
-
id: number;
|
|
44
|
-
state?: any;
|
|
45
|
-
};
|
|
46
|
-
export declare type MinimalExternalSession = {
|
|
47
|
-
ua: string;
|
|
48
|
-
ip: string;
|
|
49
|
-
};
|
|
50
|
-
export declare type Context<S extends WebSocketSession | HttpSession | ObservableSession | MinimalExternalSession = WebSocketSession | HttpSession | ObservableSession | MinimalExternalSession> = {
|
|
51
|
-
session?: S;
|
|
52
|
-
};
|
|
53
|
-
export declare const isHttpContext: (ctx: Context<HttpSession | WebSocketSession>) => ctx is Context<HttpSession>;
|
|
54
|
-
export declare const isWsSession: (session: HttpSession | WebSocketSession) => session is WebSocketSession;
|
package/dist/context.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isWsSession = exports.isHttpContext = void 0;
|
|
4
|
-
const isHttpContext = (ctx) => {
|
|
5
|
-
if ('res' in ctx?.session) {
|
|
6
|
-
return true;
|
|
7
|
-
}
|
|
8
|
-
return false;
|
|
9
|
-
};
|
|
10
|
-
exports.isHttpContext = isHttpContext;
|
|
11
|
-
const isWsSession = (session) => {
|
|
12
|
-
if (!('res' in session)) {
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
return false;
|
|
16
|
-
};
|
|
17
|
-
exports.isWsSession = isWsSession;
|
|
18
|
-
//# sourceMappingURL=context.js.map
|
package/dist/context.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;;AAyEO,MAAM,aAAa,GAAG,CAC3B,GAA4C,EACf,EAAE;IAC/B,IAAI,KAAK,IAAI,GAAG,EAAE,OAAO,EAAE;QACzB,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAPY,QAAA,aAAa,iBAOzB;AAEM,MAAM,WAAW,GAAG,CACzB,OAAuC,EACV,EAAE;IAC/B,IAAI,CAAC,CAAC,KAAK,IAAI,OAAO,CAAC,EAAE;QACvB,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAPY,QAAA,WAAW,eAOvB"}
|