@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
package/dist/error/index.js
CHANGED
|
@@ -14,26 +14,21 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.createError = void 0;
|
|
17
|
+
exports.createError = exports.createErrorData = void 0;
|
|
18
|
+
const functions_1 = require("../functions");
|
|
18
19
|
const types_1 = require("./types");
|
|
19
20
|
const errorTypeHandlers_1 = require("./errorTypeHandlers");
|
|
20
21
|
__exportStar(require("./types"), exports);
|
|
21
|
-
|
|
22
|
-
if (route && typeof route === 'object' && 'name' in route) {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
return false;
|
|
26
|
-
};
|
|
27
|
-
function createError(server, context, code, payload) {
|
|
22
|
+
function createErrorData(code, payload) {
|
|
28
23
|
const type = errorTypeHandlers_1.errorTypeHandlers[code];
|
|
29
24
|
const route = !payload
|
|
30
25
|
? types_1.EMPTY_ROUTE
|
|
31
|
-
:
|
|
26
|
+
: (0, functions_1.isRoute)(payload)
|
|
32
27
|
? payload
|
|
33
28
|
: 'route' in payload
|
|
34
29
|
? payload.route
|
|
35
30
|
: types_1.EMPTY_ROUTE;
|
|
36
|
-
|
|
31
|
+
return {
|
|
37
32
|
code,
|
|
38
33
|
statusCode: type.statusCode,
|
|
39
34
|
statusMessage: type.statusMessage,
|
|
@@ -43,6 +38,10 @@ function createError(server, context, code, payload) {
|
|
|
43
38
|
path: route.path,
|
|
44
39
|
},
|
|
45
40
|
};
|
|
41
|
+
}
|
|
42
|
+
exports.createErrorData = createErrorData;
|
|
43
|
+
function createError(server, context, code, payload) {
|
|
44
|
+
const errorData = createErrorData(code, payload);
|
|
46
45
|
if ('requestId' in payload) {
|
|
47
46
|
errorData.requestId = payload.requestId;
|
|
48
47
|
}
|
package/dist/error/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/error/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/error/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,4CAAsC;AAEtC,mCAKgB;AAEhB,2DAAuD;AACvD,0CAAuB;AAEvB,SAAgB,eAAe,CAC7B,IAAO,EACP,OAAwB;IAExB,MAAM,IAAI,GAAG,qCAAiB,CAAC,IAAI,CAAC,CAAA;IACpC,MAAM,KAAK,GAAG,CAAC,OAAO;QACpB,CAAC,CAAC,mBAAW;QACb,CAAC,CAAC,IAAA,mBAAO,EAAC,OAAO,CAAC;YAClB,CAAC,CAAC,OAAO;YACT,CAAC,CAAC,OAAO,IAAI,OAAO;gBACpB,CAAC,CAAC,OAAO,CAAC,KAAK;gBACf,CAAC,CAAC,mBAAW,CAAA;IAEf,OAAO;QACL,IAAI;QACJ,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;QAC9B,KAAK,EAAE;YACL,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,IAAI,EAAE,KAAK,CAAC,IAAI;SACjB;KACF,CAAA;AACH,CAAC;AAvBD,0CAuBC;AAED,SAAgB,WAAW,CACzB,MAAmB,EACnB,OAAgB,EAChB,IAAO,EACP,OAAwB;IAExB,MAAM,SAAS,GAAsB,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IACnE,IAAI,WAAW,IAAI,OAAO,EAAE;QAC1B,SAAS,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;KACxC;IACD,IAAI,cAAc,IAAI,OAAO,EAAE;QAC7B,SAAS,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAA;KAC9C;IACD,IAAI,KAAK,IAAI,OAAO,EAAE;QACpB,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;KACtD;SAAM;QACL,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;KACzC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAnBD,kCAmBC"}
|
package/dist/error/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BasedRoute } from '../functions';
|
|
2
2
|
export declare const EMPTY_ROUTE: {
|
|
3
3
|
name: string;
|
|
4
4
|
path: string;
|
|
@@ -13,7 +13,8 @@ export declare enum BasedErrorCode {
|
|
|
13
13
|
FunctionIsNotObservable = 40402,
|
|
14
14
|
FunctionIsObservable = 40403,
|
|
15
15
|
FunctionIsStream = 40404,
|
|
16
|
-
CannotStreamToObservableFunction =
|
|
16
|
+
CannotStreamToObservableFunction = 40405,
|
|
17
|
+
FunctionIsNotStream = 40406,
|
|
17
18
|
AuthorizeRejectedError = 40301,
|
|
18
19
|
InvalidPayload = 40001,
|
|
19
20
|
PayloadTooLarge = 40002,
|
|
@@ -22,70 +23,66 @@ export declare enum BasedErrorCode {
|
|
|
22
23
|
NoBinaryProtocol = 40005,
|
|
23
24
|
LengthRequired = 41101,
|
|
24
25
|
MethodNotAllowed = 40501,
|
|
25
|
-
RateLimit = 40029
|
|
26
|
+
RateLimit = 40029,
|
|
27
|
+
MissingAuthStateProtocolHeader = 40030
|
|
26
28
|
}
|
|
27
|
-
export declare type BasedError<T extends BasedErrorCode = BasedErrorCode> = Error & {
|
|
28
|
-
code: T;
|
|
29
|
-
};
|
|
30
29
|
declare type FunctionErrorProps = {
|
|
31
|
-
err: Error;
|
|
30
|
+
err: Error | string;
|
|
32
31
|
requestId?: number;
|
|
33
|
-
route:
|
|
32
|
+
route: BasedRoute;
|
|
34
33
|
};
|
|
35
34
|
declare type ObservableFunctionErrorProps = {
|
|
36
35
|
observableId: number;
|
|
37
|
-
err: Error;
|
|
38
|
-
route:
|
|
36
|
+
err: Error | string;
|
|
37
|
+
route: BasedRoute;
|
|
38
|
+
};
|
|
39
|
+
declare type FunctionBasicPayload = {
|
|
40
|
+
route: BasedRoute;
|
|
41
|
+
requestId?: number;
|
|
42
|
+
};
|
|
43
|
+
declare type BasedErrorPayload = {
|
|
44
|
+
observableId: number;
|
|
45
|
+
route: BasedRoute;
|
|
46
|
+
} | {
|
|
47
|
+
requestId: number;
|
|
48
|
+
route: BasedRoute;
|
|
49
|
+
} | {
|
|
50
|
+
route: BasedRoute;
|
|
39
51
|
};
|
|
40
52
|
export declare type ErrorPayload = {
|
|
41
53
|
[BasedErrorCode.RateLimit]: {};
|
|
54
|
+
[BasedErrorCode.MissingAuthStateProtocolHeader]: {};
|
|
42
55
|
[BasedErrorCode.NoBinaryProtocol]: {
|
|
43
56
|
buffer: ArrayBuffer;
|
|
44
57
|
};
|
|
45
58
|
[BasedErrorCode.FunctionError]: FunctionErrorProps;
|
|
46
59
|
[BasedErrorCode.ObservableFunctionError]: ObservableFunctionErrorProps;
|
|
47
60
|
[BasedErrorCode.AuthorizeFunctionError]: FunctionErrorProps | ObservableFunctionErrorProps;
|
|
48
|
-
[BasedErrorCode.AuthorizeRejectedError]:
|
|
49
|
-
observableId: number;
|
|
50
|
-
route: BasedFunctionRoute;
|
|
51
|
-
} | {
|
|
52
|
-
requestId?: number;
|
|
53
|
-
route: BasedFunctionRoute;
|
|
54
|
-
};
|
|
61
|
+
[BasedErrorCode.AuthorizeRejectedError]: BasedErrorPayload;
|
|
55
62
|
[BasedErrorCode.ObserveCallbackError]: {
|
|
56
63
|
err: Error;
|
|
57
64
|
observableId: number;
|
|
58
|
-
route
|
|
65
|
+
route: BasedRoute;
|
|
59
66
|
};
|
|
60
67
|
[BasedErrorCode.NoOservableCacheAvailable]: {
|
|
61
68
|
observableId: number;
|
|
62
|
-
route:
|
|
63
|
-
};
|
|
64
|
-
[BasedErrorCode.FunctionIsStream]: BasedFunctionRoute & {
|
|
65
|
-
requestId?: number;
|
|
66
|
-
};
|
|
67
|
-
[BasedErrorCode.FunctionNotFound]: BasedFunctionRoute & {
|
|
68
|
-
requestId?: number;
|
|
69
|
-
};
|
|
70
|
-
[BasedErrorCode.FunctionIsNotObservable]: BasedFunctionRoute & {
|
|
71
|
-
requestId?: number;
|
|
72
|
-
};
|
|
73
|
-
[BasedErrorCode.FunctionIsObservable]: BasedFunctionRoute & {
|
|
74
|
-
requestId?: number;
|
|
75
|
-
};
|
|
76
|
-
[BasedErrorCode.CannotStreamToObservableFunction]: BasedFunctionRoute & {
|
|
77
|
-
requestId?: number;
|
|
78
|
-
};
|
|
79
|
-
[BasedErrorCode.InvalidPayload]: BasedFunctionRoute & {
|
|
80
|
-
requestId?: number;
|
|
69
|
+
route: BasedRoute;
|
|
81
70
|
};
|
|
82
|
-
[BasedErrorCode.
|
|
83
|
-
|
|
71
|
+
[BasedErrorCode.FunctionIsNotStream]: FunctionBasicPayload;
|
|
72
|
+
[BasedErrorCode.FunctionIsStream]: BasedErrorPayload;
|
|
73
|
+
[BasedErrorCode.FunctionNotFound]: BasedErrorPayload;
|
|
74
|
+
[BasedErrorCode.FunctionIsNotObservable]: {
|
|
75
|
+
route: BasedRoute;
|
|
76
|
+
observableId?: number;
|
|
84
77
|
};
|
|
85
|
-
[BasedErrorCode.
|
|
86
|
-
[BasedErrorCode.
|
|
87
|
-
[BasedErrorCode.
|
|
88
|
-
[BasedErrorCode.
|
|
78
|
+
[BasedErrorCode.FunctionIsObservable]: FunctionBasicPayload;
|
|
79
|
+
[BasedErrorCode.CannotStreamToObservableFunction]: FunctionBasicPayload;
|
|
80
|
+
[BasedErrorCode.InvalidPayload]: BasedErrorPayload;
|
|
81
|
+
[BasedErrorCode.PayloadTooLarge]: BasedErrorPayload;
|
|
82
|
+
[BasedErrorCode.ChunkTooLarge]: BasedRoute;
|
|
83
|
+
[BasedErrorCode.UnsupportedContentEncoding]: BasedRoute;
|
|
84
|
+
[BasedErrorCode.LengthRequired]: BasedRoute;
|
|
85
|
+
[BasedErrorCode.MethodNotAllowed]: BasedRoute;
|
|
89
86
|
};
|
|
90
87
|
export declare type ErrorHandler<T extends BasedErrorCode> = {
|
|
91
88
|
statusCode: number;
|
|
@@ -93,13 +90,12 @@ export declare type ErrorHandler<T extends BasedErrorCode> = {
|
|
|
93
90
|
message: (payload: ErrorPayload[T]) => string;
|
|
94
91
|
};
|
|
95
92
|
export declare type BasedErrorData<T extends BasedErrorCode = BasedErrorCode> = {
|
|
96
|
-
route:
|
|
93
|
+
route: BasedRoute;
|
|
97
94
|
message: string;
|
|
98
95
|
code: T;
|
|
99
96
|
statusCode: number;
|
|
100
97
|
statusMessage: string;
|
|
101
98
|
requestId?: number;
|
|
102
99
|
observableId?: number;
|
|
103
|
-
err?: BasedError<T>;
|
|
104
100
|
};
|
|
105
101
|
export {};
|
package/dist/error/types.js
CHANGED
|
@@ -16,7 +16,8 @@ var BasedErrorCode;
|
|
|
16
16
|
BasedErrorCode[BasedErrorCode["FunctionIsNotObservable"] = 40402] = "FunctionIsNotObservable";
|
|
17
17
|
BasedErrorCode[BasedErrorCode["FunctionIsObservable"] = 40403] = "FunctionIsObservable";
|
|
18
18
|
BasedErrorCode[BasedErrorCode["FunctionIsStream"] = 40404] = "FunctionIsStream";
|
|
19
|
-
BasedErrorCode[BasedErrorCode["CannotStreamToObservableFunction"] =
|
|
19
|
+
BasedErrorCode[BasedErrorCode["CannotStreamToObservableFunction"] = 40405] = "CannotStreamToObservableFunction";
|
|
20
|
+
BasedErrorCode[BasedErrorCode["FunctionIsNotStream"] = 40406] = "FunctionIsNotStream";
|
|
20
21
|
BasedErrorCode[BasedErrorCode["AuthorizeRejectedError"] = 40301] = "AuthorizeRejectedError";
|
|
21
22
|
BasedErrorCode[BasedErrorCode["InvalidPayload"] = 40001] = "InvalidPayload";
|
|
22
23
|
BasedErrorCode[BasedErrorCode["PayloadTooLarge"] = 40002] = "PayloadTooLarge";
|
|
@@ -26,5 +27,6 @@ var BasedErrorCode;
|
|
|
26
27
|
BasedErrorCode[BasedErrorCode["LengthRequired"] = 41101] = "LengthRequired";
|
|
27
28
|
BasedErrorCode[BasedErrorCode["MethodNotAllowed"] = 40501] = "MethodNotAllowed";
|
|
28
29
|
BasedErrorCode[BasedErrorCode["RateLimit"] = 40029] = "RateLimit";
|
|
30
|
+
BasedErrorCode[BasedErrorCode["MissingAuthStateProtocolHeader"] = 40030] = "MissingAuthStateProtocolHeader";
|
|
29
31
|
})(BasedErrorCode = exports.BasedErrorCode || (exports.BasedErrorCode = {}));
|
|
30
32
|
//# sourceMappingURL=types.js.map
|
package/dist/error/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/error/types.ts"],"names":[],"mappings":";;;AAEa,QAAA,WAAW,GAAG;IACzB,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,EAAE;CACT,CAAA;AAED,IAAY,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/error/types.ts"],"names":[],"mappings":";;;AAEa,QAAA,WAAW,GAAG;IACzB,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,EAAE;CACT,CAAA;AAED,IAAY,cAsBX;AAtBD,WAAY,cAAc;IACxB,yEAAqB,CAAA;IACrB,2FAA8B,CAAA;IAC9B,iGAAiC,CAAA;IACjC,6FAA+B,CAAA;IAC/B,uFAA4B,CAAA;IAC5B,+EAAwB,CAAA;IACxB,6FAA+B,CAAA;IAC/B,uFAA4B,CAAA;IAC5B,+EAAwB,CAAA;IACxB,+GAAwC,CAAA;IACxC,qFAA2B,CAAA;IAC3B,2FAA8B,CAAA;IAC9B,2EAAsB,CAAA;IACtB,6EAAuB,CAAA;IACvB,yEAAqB,CAAA;IACrB,mGAAkC,CAAA;IAClC,+EAAwB,CAAA;IACxB,2EAAsB,CAAA;IACtB,+EAAwB,CAAA;IACxB,iEAAiB,CAAA;IACjB,2GAAsC,CAAA;AACxC,CAAC,EAtBW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAsBzB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.callFunction = void 0;
|
|
4
|
+
const error_1 = require("../error");
|
|
5
|
+
const verifyRoute_1 = require("../verifyRoute");
|
|
6
|
+
const installFn_1 = require("../installFn");
|
|
7
|
+
const callFunction = async (server, name, ctx, payload) => {
|
|
8
|
+
const route = (0, verifyRoute_1.verifyRoute)(server, server.client.ctx, 'fn', server.functions.route(name), name);
|
|
9
|
+
if (route === null) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const fn = await (0, installFn_1.installFn)(server, server.client.ctx, route);
|
|
13
|
+
if (!fn) {
|
|
14
|
+
throw (0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionNotFound, {
|
|
15
|
+
route,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
return fn.function(server.client, payload, ctx);
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
throw (0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionError, {
|
|
23
|
+
route,
|
|
24
|
+
err,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.callFunction = callFunction;
|
|
29
|
+
//# sourceMappingURL=callFunction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callFunction.js","sourceRoot":"","sources":["../../src/functionApi/callFunction.ts"],"names":[],"mappings":";;;AACA,oCAAsD;AAEtD,gDAA4C;AAC5C,4CAAwC;AAEjC,MAAM,YAAY,GAAG,KAAK,EAC/B,MAAmB,EACnB,IAAY,EACZ,GAAY,EACZ,OAAY,EACE,EAAE;IAChB,MAAM,KAAK,GAAG,IAAA,yBAAW,EACvB,MAAM,EACN,MAAM,CAAC,MAAM,CAAC,GAAG,EACjB,IAAI,EACJ,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,EAC5B,IAAI,CACL,CAAA;IAED,IAAI,KAAK,KAAK,IAAI,EAAE;QAClB,OAAM;KACP;IAED,MAAM,EAAE,GAAG,MAAM,IAAA,qBAAS,EAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IAE5D,IAAI,CAAC,EAAE,EAAE;QACP,MAAM,IAAA,mBAAW,EAAC,MAAM,EAAE,GAAG,EAAE,sBAAc,CAAC,gBAAgB,EAAE;YAC9D,KAAK;SACN,CAAC,CAAA;KACH;IAED,IAAI;QACF,OAAO,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAA;KAChD;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,IAAA,mBAAW,EAAC,MAAM,EAAE,GAAG,EAAE,sBAAc,CAAC,aAAa,EAAE;YAC3D,KAAK;YACL,GAAG;SACJ,CAAC,CAAA;KACH;AACH,CAAC,CAAA;AAlCY,QAAA,YAAY,gBAkCxB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { BasedServer } from '../../server';
|
|
3
|
+
import { BasedQuery } from './query';
|
|
4
|
+
import util from 'node:util';
|
|
5
|
+
import { AuthState, BasedFunctionClient as BasedfunctionClientAbstract, Context, InternalSessionClient, Session } from '@based/functions';
|
|
6
|
+
export declare class BasedFunctionClient extends BasedfunctionClientAbstract {
|
|
7
|
+
server: BasedServer;
|
|
8
|
+
ctx: Context<InternalSessionClient>;
|
|
9
|
+
constructor(server: BasedServer);
|
|
10
|
+
call(name: string, payload?: any, ctx?: Context): Promise<any>;
|
|
11
|
+
query(name: string, payload?: any): BasedQuery;
|
|
12
|
+
stream(name: string, stream?: any): Promise<any>;
|
|
13
|
+
renewAuthState(ctx: Context<Session>, authState?: AuthState): void;
|
|
14
|
+
sendAuthState(ctx: Context<Session>, authState: AuthState): void;
|
|
15
|
+
[util.inspect.custom](): string;
|
|
16
|
+
}
|
|
@@ -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.BasedFunctionClient = void 0;
|
|
7
|
+
const callFunction_1 = require("../callFunction");
|
|
8
|
+
const query_1 = require("./query");
|
|
9
|
+
const node_util_1 = __importDefault(require("node:util"));
|
|
10
|
+
const functions_1 = require("@based/functions");
|
|
11
|
+
class BasedFunctionClient extends functions_1.BasedFunctionClient {
|
|
12
|
+
constructor(server) {
|
|
13
|
+
super();
|
|
14
|
+
this.server = server;
|
|
15
|
+
this.ctx = {
|
|
16
|
+
session: { type: 'client', client: this },
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
// TODO: CTX - Transpile the ctx in there by static analysis for "call" & "stream"
|
|
20
|
+
call(name, payload, ctx = this.ctx) {
|
|
21
|
+
return (0, callFunction_1.callFunction)(this.server, name, ctx, payload);
|
|
22
|
+
}
|
|
23
|
+
query(name, payload) {
|
|
24
|
+
return new query_1.BasedQuery(this.ctx, name, payload);
|
|
25
|
+
}
|
|
26
|
+
async stream(name, stream) {
|
|
27
|
+
// make later
|
|
28
|
+
return { name, stream };
|
|
29
|
+
}
|
|
30
|
+
renewAuthState(ctx, authState) {
|
|
31
|
+
this.server.auth.renewAuthState(ctx, authState);
|
|
32
|
+
}
|
|
33
|
+
sendAuthState(ctx, authState) {
|
|
34
|
+
if (!(0, functions_1.isWsContext)(ctx)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
this.server.auth.sendAuthState(ctx, authState);
|
|
38
|
+
}
|
|
39
|
+
[node_util_1.default.inspect.custom]() {
|
|
40
|
+
return `[BasedFunctionClient]`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.BasedFunctionClient = BasedFunctionClient;
|
|
44
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/functionApi/client/index.ts"],"names":[],"mappings":";;;;;;AACA,kDAA8C;AAC9C,mCAAoC;AACpC,0DAA4B;AAE5B,gDAOyB;AAEzB,MAAa,mBAAoB,SAAQ,+BAA2B;IAIlE,YAAY,MAAmB;QAC7B,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,GAAG,GAAG;YACT,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE;SAC1C,CAAA;IACH,CAAC;IAED,kFAAkF;IAClF,IAAI,CAAC,IAAY,EAAE,OAAa,EAAE,MAAe,IAAI,CAAC,GAAG;QACvD,OAAO,IAAA,2BAAY,EAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,CAAA;IACtD,CAAC;IAED,KAAK,CAAC,IAAY,EAAE,OAAa;QAC/B,OAAO,IAAI,kBAAU,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IAChD,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAAY,EAAE,MAAY;QACrC,aAAa;QACb,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;IACzB,CAAC;IAED,cAAc,CAAC,GAAqB,EAAE,SAAqB;QACzD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,SAAS,CAAC,CAAA;IACjD,CAAC;IAED,aAAa,CAAC,GAAqB,EAAE,SAAoB;QACvD,IAAI,CAAC,IAAA,uBAAW,EAAC,GAAG,CAAC,EAAE;YACrB,OAAM;SACP;QACD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,SAAS,CAAC,CAAA;IAChD,CAAC;IAED,CAAC,mBAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QACnB,OAAO,uBAAuB,CAAA;IAChC,CAAC;CACF;AAxCD,kDAwCC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ObservableUpdateFunction, ObserveErrorListener } from '../../observable';
|
|
2
|
+
import { BasedQuery as BasedQueryAbstract, Context, InternalSessionClient } from '@based/functions';
|
|
3
|
+
export declare class BasedQuery extends BasedQueryAbstract {
|
|
4
|
+
query: any;
|
|
5
|
+
name: string;
|
|
6
|
+
ctx: Context<InternalSessionClient>;
|
|
7
|
+
constructor(ctx: Context<InternalSessionClient>, name: string, payload: any);
|
|
8
|
+
subscribe(onData: ObservableUpdateFunction, onError?: ObserveErrorListener): () => void;
|
|
9
|
+
getWhen(condition: (data: any, checksum: number) => boolean): Promise<any>;
|
|
10
|
+
get(): Promise<any>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BasedQuery = void 0;
|
|
4
|
+
const observe_1 = require("../observe");
|
|
5
|
+
const get_1 = require("../get");
|
|
6
|
+
const functions_1 = require("@based/functions");
|
|
7
|
+
class BasedQuery extends functions_1.BasedQuery {
|
|
8
|
+
constructor(ctx, name, payload) {
|
|
9
|
+
super();
|
|
10
|
+
this.ctx = ctx;
|
|
11
|
+
this.query = payload;
|
|
12
|
+
this.name = name;
|
|
13
|
+
}
|
|
14
|
+
subscribe(onData, onError) {
|
|
15
|
+
return (0, observe_1.observe)(this.ctx.session.client.server, this.name, this.ctx, this.query, onData, onError);
|
|
16
|
+
}
|
|
17
|
+
async getWhen(condition) {
|
|
18
|
+
return new Promise((resolve) => {
|
|
19
|
+
const close = this.subscribe((data, checksum) => {
|
|
20
|
+
if (condition(data, checksum)) {
|
|
21
|
+
resolve(data);
|
|
22
|
+
close();
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async get() {
|
|
28
|
+
return (0, get_1.get)(this.ctx.session.client.server, this.name, this.ctx, this.query);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.BasedQuery = BasedQuery;
|
|
32
|
+
//# sourceMappingURL=query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../../src/functionApi/client/query.ts"],"names":[],"mappings":";;;AAIA,wCAAoC;AACpC,gCAA4B;AAC5B,gDAIyB;AAEzB,MAAa,UAAW,SAAQ,sBAAkB;IAKhD,YAAY,GAAmC,EAAE,IAAY,EAAE,OAAY;QACzE,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,KAAK,GAAG,OAAO,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAED,SAAS,CACP,MAAgC,EAChC,OAA8B;QAE9B,OAAO,IAAA,iBAAO,EACZ,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAC9B,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,GAAG,EACR,IAAI,CAAC,KAAK,EACV,MAAM,EACN,OAAO,CACR,CAAA;IACH,CAAC;IAED,KAAK,CAAC,OAAO,CACX,SAAmD;QAEnD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE;gBAC9C,IAAI,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE;oBAC7B,OAAO,CAAC,IAAI,CAAC,CAAA;oBACb,KAAK,EAAE,CAAA;iBACR;YACH,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,GAAG;QACP,OAAO,IAAA,SAAG,EAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;IAC7E,CAAC;CACF;AA1CD,gCA0CC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.get = void 0;
|
|
4
|
+
const error_1 = require("../error");
|
|
5
|
+
const observable_1 = require("../observable");
|
|
6
|
+
const verifyRoute_1 = require("../verifyRoute");
|
|
7
|
+
const installFn_1 = require("../installFn");
|
|
8
|
+
const getObsData = (resolve, reject, server, id, ctx, route) => {
|
|
9
|
+
const obs = (0, observable_1.getObs)(server, id);
|
|
10
|
+
if (obs.error) {
|
|
11
|
+
reject((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.ObservableFunctionError, {
|
|
12
|
+
route,
|
|
13
|
+
observableId: id,
|
|
14
|
+
err: obs.error.message,
|
|
15
|
+
}));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (obs.cache) {
|
|
19
|
+
resolve(obs.rawData || obs.cache);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
(0, observable_1.subscribeNext)(obs, (err) => {
|
|
23
|
+
(0, observable_1.destroyObs)(server, id);
|
|
24
|
+
if (err) {
|
|
25
|
+
reject(err);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
resolve(obs.rawData || obs.cache);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
const get = (server, name, ctx, payload) => {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
let route;
|
|
35
|
+
try {
|
|
36
|
+
route = (0, verifyRoute_1.verifyRoute)(server, server.client.ctx, 'query', server.functions.route(name), name);
|
|
37
|
+
if (route === null) {
|
|
38
|
+
reject(new Error(`[${name}] No session in ctx`));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
reject(err);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const id = (0, observable_1.genObservableId)(name, payload);
|
|
47
|
+
if (!(0, observable_1.hasObs)(server, id)) {
|
|
48
|
+
(0, installFn_1.installFn)(server, server.client.ctx, route).then((spec) => {
|
|
49
|
+
if (!spec) {
|
|
50
|
+
reject((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionNotFound, {
|
|
51
|
+
route,
|
|
52
|
+
}));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (!(0, observable_1.hasObs)(server, id)) {
|
|
56
|
+
(0, observable_1.createObs)(server, name, id, payload, true);
|
|
57
|
+
getObsData(resolve, reject, server, id, ctx, route);
|
|
58
|
+
(0, observable_1.start)(server, id);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
getObsData(resolve, reject, server, id, ctx, route);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
getObsData(resolve, reject, server, id, ctx, route);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
exports.get = get;
|
|
71
|
+
//# sourceMappingURL=get.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../src/functionApi/get.ts"],"names":[],"mappings":";;;AACA,oCAAsE;AAGtE,8CAQsB;AACtB,gDAA4C;AAC5C,4CAAwC;AAExC,MAAM,UAAU,GAAG,CACjB,OAAwB,EACxB,MAA6E,EAC7E,MAAmB,EACnB,EAAU,EACV,GAAY,EACZ,KAA8B,EAC9B,EAAE;IACF,MAAM,GAAG,GAAG,IAAA,mBAAM,EAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IAC9B,IAAI,GAAG,CAAC,KAAK,EAAE;QACb,MAAM,CACJ,IAAA,mBAAW,EAAC,MAAM,EAAE,GAAG,EAAE,sBAAc,CAAC,uBAAuB,EAAE;YAC/D,KAAK;YACL,YAAY,EAAE,EAAE;YAChB,GAAG,EAAE,GAAG,CAAC,KAAK,CAAC,OAAO;SACvB,CAAC,CACH,CAAA;QACD,OAAM;KACP;IAED,IAAI,GAAG,CAAC,KAAK,EAAE;QACb,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAA;QACjC,OAAM;KACP;IAED,IAAA,0BAAa,EAAC,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE;QACzB,IAAA,uBAAU,EAAC,MAAM,EAAE,EAAE,CAAC,CAAA;QACtB,IAAI,GAAG,EAAE;YACP,MAAM,CAAC,GAAG,CAAC,CAAA;SACZ;aAAM;YACL,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAA;SAClC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAEM,MAAM,GAAG,GAAG,CACjB,MAAmB,EACnB,IAAY,EACZ,GAAY,EACZ,OAAY,EACE,EAAE;IAChB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,KAA8B,CAAA;QAClC,IAAI;YACF,KAAK,GAAG,IAAA,yBAAW,EACjB,MAAM,EACN,MAAM,CAAC,MAAM,CAAC,GAAG,EACjB,OAAO,EACP,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,EAC5B,IAAI,CACL,CAAA;YACD,IAAI,KAAK,KAAK,IAAI,EAAE;gBAClB,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI,IAAI,qBAAqB,CAAC,CAAC,CAAA;gBAChD,OAAM;aACP;SACF;QAAC,OAAO,GAAG,EAAE;YACZ,MAAM,CAAC,GAAG,CAAC,CAAA;YACX,OAAM;SACP;QAED,MAAM,EAAE,GAAG,IAAA,4BAAe,EAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QACzC,IAAI,CAAC,IAAA,mBAAM,EAAC,MAAM,EAAE,EAAE,CAAC,EAAE;YACvB,IAAA,qBAAS,EAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;gBACxD,IAAI,CAAC,IAAI,EAAE;oBACT,MAAM,CACJ,IAAA,mBAAW,EAAC,MAAM,EAAE,GAAG,EAAE,sBAAc,CAAC,gBAAgB,EAAE;wBACxD,KAAK;qBACN,CAAC,CACH,CAAA;oBACD,OAAM;iBACP;gBAED,IAAI,CAAC,IAAA,mBAAM,EAAC,MAAM,EAAE,EAAE,CAAC,EAAE;oBACvB,IAAA,sBAAS,EAAC,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA;oBAC1C,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;oBACnD,IAAA,kBAAK,EAAC,MAAM,EAAE,EAAE,CAAC,CAAA;iBAClB;qBAAM;oBACL,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;iBACpD;YACH,CAAC,CAAC,CAAA;SACH;aAAM;YACL,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;SACpD;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAjDY,QAAA,GAAG,OAiDf"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.decode = void 0;
|
|
18
|
+
__exportStar(require("./callFunction"), exports);
|
|
19
|
+
__exportStar(require("./get"), exports);
|
|
20
|
+
__exportStar(require("./client"), exports);
|
|
21
|
+
var protocol_1 = require("../protocol");
|
|
22
|
+
Object.defineProperty(exports, "decode", { enumerable: true, get: function () { return protocol_1.decode; } });
|
|
23
|
+
__exportStar(require("./observe"), exports);
|
|
24
|
+
// TODO: nested stream function
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/functionApi/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iDAA8B;AAC9B,wCAAqB;AACrB,2CAAwB;AACxB,wCAAoC;AAA3B,kGAAA,MAAM,OAAA;AACf,4CAAyB;AAEzB,+BAA+B"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { BasedServer } from '../server';
|
|
2
|
+
import { Context } from '@based/functions';
|
|
3
|
+
import { ObservableUpdateFunction, ObserveErrorListener } from '../observable';
|
|
4
|
+
export declare const observe: (server: BasedServer, name: string, ctx: Context, payload: any, update: ObservableUpdateFunction, error: ObserveErrorListener) => (() => void);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.observe = void 0;
|
|
4
|
+
const error_1 = require("../error");
|
|
5
|
+
const verifyRoute_1 = require("../verifyRoute");
|
|
6
|
+
const observable_1 = require("../observable");
|
|
7
|
+
const installFn_1 = require("../installFn");
|
|
8
|
+
const observe = (server, name, ctx, payload, update, error) => {
|
|
9
|
+
const route = (0, verifyRoute_1.verifyRoute)(server, server.client.ctx, 'query', server.functions.route(name), name);
|
|
10
|
+
if (route === null) {
|
|
11
|
+
throw new Error(`[${name}] No session in ctx`);
|
|
12
|
+
}
|
|
13
|
+
const id = (0, observable_1.genObservableId)(name, payload);
|
|
14
|
+
let isClosed = false;
|
|
15
|
+
const close = () => {
|
|
16
|
+
if (isClosed) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
isClosed = true;
|
|
20
|
+
(0, observable_1.unsubscribeFunction)(server, id, update);
|
|
21
|
+
};
|
|
22
|
+
if ((0, observable_1.hasObs)(server, id)) {
|
|
23
|
+
(0, observable_1.subscribeFunction)(server, id, update);
|
|
24
|
+
return close;
|
|
25
|
+
}
|
|
26
|
+
(0, installFn_1.installFn)(server, server.client.ctx, route).then((spec) => {
|
|
27
|
+
if (isClosed) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (spec === null) {
|
|
31
|
+
error((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionNotFound, {
|
|
32
|
+
route,
|
|
33
|
+
}));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (!(0, observable_1.hasObs)(server, id)) {
|
|
37
|
+
(0, observable_1.createObs)(server, name, id, payload);
|
|
38
|
+
}
|
|
39
|
+
(0, observable_1.subscribeFunction)(server, id, update);
|
|
40
|
+
});
|
|
41
|
+
return close;
|
|
42
|
+
};
|
|
43
|
+
exports.observe = observe;
|
|
44
|
+
//# sourceMappingURL=observe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observe.js","sourceRoot":"","sources":["../../src/functionApi/observe.ts"],"names":[],"mappings":";;;AACA,oCAAsD;AAEtD,gDAA4C;AAC5C,8CAQsB;AACtB,4CAAwC;AAEjC,MAAM,OAAO,GAAG,CACrB,MAAmB,EACnB,IAAY,EACZ,GAAY,EACZ,OAAY,EACZ,MAAgC,EAChC,KAA2B,EACb,EAAE;IAChB,MAAM,KAAK,GAAG,IAAA,yBAAW,EACvB,MAAM,EACN,MAAM,CAAC,MAAM,CAAC,GAAG,EACjB,OAAO,EACP,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,EAC5B,IAAI,CACL,CAAA;IAED,IAAI,KAAK,KAAK,IAAI,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,IAAI,IAAI,qBAAqB,CAAC,CAAA;KAC/C;IAED,MAAM,EAAE,GAAG,IAAA,4BAAe,EAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IACzC,IAAI,QAAQ,GAAG,KAAK,CAAA;IAEpB,MAAM,KAAK,GAAG,GAAG,EAAE;QACjB,IAAI,QAAQ,EAAE;YACZ,OAAM;SACP;QACD,QAAQ,GAAG,IAAI,CAAA;QACf,IAAA,gCAAmB,EAAC,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,CAAA;IACzC,CAAC,CAAA;IAED,IAAI,IAAA,mBAAM,EAAC,MAAM,EAAE,EAAE,CAAC,EAAE;QACtB,IAAA,8BAAiB,EAAC,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,CAAA;QACrC,OAAO,KAAK,CAAA;KACb;IAED,IAAA,qBAAS,EAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;QACxD,IAAI,QAAQ,EAAE;YACZ,OAAM;SACP;QACD,IAAI,IAAI,KAAK,IAAI,EAAE;YACjB,KAAK,CACH,IAAA,mBAAW,EAAC,MAAM,EAAE,GAAG,EAAE,sBAAc,CAAC,gBAAgB,EAAE;gBACxD,KAAK;aACN,CAAC,CACH,CAAA;YACD,OAAM;SACP;QACD,IAAI,CAAC,IAAA,mBAAM,EAAC,MAAM,EAAE,EAAE,CAAC,EAAE;YACvB,IAAA,sBAAS,EAAC,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,CAAC,CAAA;SACrC;QACD,IAAA,8BAAiB,EAAC,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,CAAA;IACvC,CAAC,CAAC,CAAA;IAEF,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAvDY,QAAA,OAAO,WAuDnB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stream = void 0;
|
|
4
|
+
const error_1 = require("../error");
|
|
5
|
+
const verifyRoute_1 = require("../verifyRoute");
|
|
6
|
+
const installFn_1 = require("../installFn");
|
|
7
|
+
// lots of thins here...
|
|
8
|
+
const stream = async (server, name, ctx, payload) => {
|
|
9
|
+
const route = (0, verifyRoute_1.verifyRoute)(server, server.client.ctx, 'fn', server.functions.route(name), name);
|
|
10
|
+
if (route === null) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const fn = await (0, installFn_1.installFn)(server, server.client.ctx, route);
|
|
14
|
+
if (!fn) {
|
|
15
|
+
throw (0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionNotFound, {
|
|
16
|
+
route,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
return fn.function(server.client, payload, ctx);
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
throw (0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionError, {
|
|
24
|
+
route,
|
|
25
|
+
err,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.stream = stream;
|
|
30
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/functionApi/stream.ts"],"names":[],"mappings":";;;AACA,oCAAsD;AAEtD,gDAA4C;AAC5C,4CAAwC;AAExC,wBAAwB;AACjB,MAAM,MAAM,GAAG,KAAK,EACzB,MAAmB,EACnB,IAAY,EACZ,GAAY,EACZ,OAAY,EACE,EAAE;IAChB,MAAM,KAAK,GAAG,IAAA,yBAAW,EACvB,MAAM,EACN,MAAM,CAAC,MAAM,CAAC,GAAG,EACjB,IAAI,EACJ,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,EAC5B,IAAI,CACL,CAAA;IAED,IAAI,KAAK,KAAK,IAAI,EAAE;QAClB,OAAM;KACP;IAED,MAAM,EAAE,GAAG,MAAM,IAAA,qBAAS,EAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IAE5D,IAAI,CAAC,EAAE,EAAE;QACP,MAAM,IAAA,mBAAW,EAAC,MAAM,EAAE,GAAG,EAAE,sBAAc,CAAC,gBAAgB,EAAE;YAC9D,KAAK;SACN,CAAC,CAAA;KACH;IAED,IAAI;QACF,OAAO,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAA;KAChD;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,IAAA,mBAAW,EAAC,MAAM,EAAE,GAAG,EAAE,sBAAc,CAAC,aAAa,EAAE;YAC3D,KAAK;YACL,GAAG;SACJ,CAAC,CAAA;KACH;AACH,CAAC,CAAA;AAlCY,QAAA,MAAM,UAkClB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { BasedServer } from '../server';
|
|
3
|
-
import {
|
|
3
|
+
import { BasedRoute, BasedSpec, FunctionConfig } from './types';
|
|
4
4
|
export * from './types';
|
|
5
5
|
export declare class BasedFunctions {
|
|
6
6
|
server: BasedServer;
|
|
@@ -10,11 +10,19 @@ export declare class BasedFunctions {
|
|
|
10
10
|
installsInProgress: {
|
|
11
11
|
[name: string]: Promise<any>;
|
|
12
12
|
};
|
|
13
|
+
maxPayLoadSizeDefaults: {
|
|
14
|
+
stream: number;
|
|
15
|
+
query: number;
|
|
16
|
+
function: number;
|
|
17
|
+
};
|
|
13
18
|
paths: {
|
|
14
19
|
[path: string]: string;
|
|
15
20
|
};
|
|
16
21
|
specs: {
|
|
17
|
-
[name: string]:
|
|
22
|
+
[name: string]: BasedSpec & {
|
|
23
|
+
maxPayloadSize: number;
|
|
24
|
+
rateLimitTokens: number;
|
|
25
|
+
};
|
|
18
26
|
};
|
|
19
27
|
beingUninstalled: {
|
|
20
28
|
[name: string]: boolean;
|
|
@@ -22,13 +30,13 @@ export declare class BasedFunctions {
|
|
|
22
30
|
constructor(server: BasedServer, config?: FunctionConfig);
|
|
23
31
|
uninstallLoop(): void;
|
|
24
32
|
updateConfig(config: FunctionConfig): void;
|
|
25
|
-
updateFunction(spec:
|
|
33
|
+
updateFunction(spec: BasedSpec): Promise<void>;
|
|
26
34
|
private installGaurdedFromConfig;
|
|
27
|
-
install(name: string): Promise<
|
|
35
|
+
install(name: string): Promise<BasedSpec | null>;
|
|
28
36
|
getNameFromPath(path: string): string;
|
|
29
|
-
route(name?: string, path?: string):
|
|
30
|
-
getFromStore(name: string):
|
|
31
|
-
update(spec:
|
|
37
|
+
route(name?: string, path?: string): BasedRoute | null;
|
|
38
|
+
getFromStore(name: string): BasedSpec | null;
|
|
39
|
+
update(spec: BasedSpec): boolean;
|
|
32
40
|
remove(name: string): boolean;
|
|
33
|
-
uninstall(name: string, spec?:
|
|
41
|
+
uninstall(name: string, spec?: BasedSpec | false): Promise<boolean>;
|
|
34
42
|
}
|