@based/server 4.0.3 → 4.0.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/dist/auth/defaultConfig.js +1 -1
- package/dist/auth/defaultConfig.js.map +1 -1
- package/dist/auth/index.d.ts +14 -2
- package/dist/auth/index.js +12 -5
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/parseJSONAuthState.d.ts +3 -0
- package/dist/auth/parseJSONAuthState.js +10 -0
- package/dist/auth/parseJSONAuthState.js.map +1 -0
- package/dist/authorize copy.d.ts +9 -0
- package/dist/authorize copy.js +69 -0
- package/dist/authorize copy.js.map +1 -0
- package/dist/authorize.d.ts +5 -5
- package/dist/authorize.js +33 -17
- package/dist/authorize.js.map +1 -1
- package/dist/authorizeAndInstall.d.ts +9 -0
- package/dist/authorizeAndInstall.js +69 -0
- package/dist/authorizeAndInstall.js.map +1 -0
- package/dist/channel/cleanup.d.ts +2 -0
- package/dist/channel/cleanup.js +53 -0
- package/dist/channel/cleanup.js.map +1 -0
- package/dist/channel/create.d.ts +3 -0
- package/dist/channel/create.js +33 -0
- package/dist/channel/create.js.map +1 -0
- package/dist/channel/destroy.d.ts +4 -0
- package/dist/channel/destroy.js +48 -0
- package/dist/channel/destroy.js.map +1 -0
- package/dist/channel/extend.d.ts +4 -0
- package/dist/channel/extend.js +16 -0
- package/dist/channel/extend.js.map +1 -0
- package/dist/channel/get.d.ts +4 -0
- package/dist/channel/get.js +15 -0
- package/dist/channel/get.js.map +1 -0
- package/dist/channel/index.d.ts +8 -0
- package/dist/channel/index.js +25 -0
- package/dist/channel/index.js.map +1 -0
- package/dist/channel/start.d.ts +2 -0
- package/dist/channel/start.js +76 -0
- package/dist/channel/start.js.map +1 -0
- package/dist/channel/subscribe.d.ts +4 -0
- package/dist/channel/subscribe.js +28 -0
- package/dist/channel/subscribe.js.map +1 -0
- package/dist/channel/types.d.ts +14 -0
- package/dist/channel/types.js +4 -0
- package/dist/channel/types.js.map +1 -0
- package/dist/channel/unsub.d.ts +5 -0
- package/dist/channel/unsub.js +49 -0
- package/dist/channel/unsub.js.map +1 -0
- package/dist/createSimpleServer.d.ts +18 -16
- package/dist/createSimpleServer.js +92 -26
- package/dist/createSimpleServer.js.map +1 -1
- package/dist/error/errorTypeHandlers.d.ts +1 -1
- package/dist/error/errorTypeHandlers.js +16 -46
- package/dist/error/errorTypeHandlers.js.map +1 -1
- package/dist/error/index.js +3 -0
- package/dist/error/index.js.map +1 -1
- package/dist/error/types.d.ts +22 -27
- package/dist/error/types.js +2 -6
- package/dist/error/types.js.map +1 -1
- package/dist/functionApi/channelSubscribe.d.ts +3 -0
- package/dist/functionApi/channelSubscribe.js +43 -0
- package/dist/functionApi/channelSubscribe.js.map +1 -0
- package/dist/functionApi/client/channel.d.ts +10 -0
- package/dist/functionApi/client/channel.js +33 -0
- package/dist/functionApi/client/channel.js.map +1 -0
- package/dist/functionApi/client/index.d.ts +5 -3
- package/dist/functionApi/client/index.js +10 -5
- package/dist/functionApi/client/index.js.map +1 -1
- package/dist/functionApi/get.js +2 -2
- package/dist/functionApi/get.js.map +1 -1
- package/dist/functionApi/index.d.ts +3 -0
- package/dist/functionApi/index.js +3 -1
- package/dist/functionApi/index.js.map +1 -1
- package/dist/functionApi/observe.js +2 -2
- package/dist/functionApi/observe.js.map +1 -1
- package/dist/functionApi/publish.d.ts +3 -0
- package/dist/functionApi/publish.js +29 -0
- package/dist/functionApi/publish.js.map +1 -0
- package/dist/functionApi/stream.d.ts +2 -2
- package/dist/functionApi/stream.js +44 -6
- package/dist/functionApi/stream.js.map +1 -1
- package/dist/functions/index.d.ts +3 -2
- package/dist/functions/index.js +55 -34
- package/dist/functions/index.js.map +1 -1
- package/dist/functions/timeout.js +4 -2
- package/dist/functions/timeout.js.map +1 -1
- package/dist/functions/types.d.ts +100 -56
- package/dist/functions/types.js +16 -5
- package/dist/functions/types.js.map +1 -1
- package/dist/incoming/http/function.js +26 -28
- package/dist/incoming/http/function.js.map +1 -1
- package/dist/incoming/http/index.js +33 -7
- package/dist/incoming/http/index.js.map +1 -1
- package/dist/incoming/http/publish.d.ts +3 -0
- package/dist/incoming/http/publish.js +82 -0
- package/dist/incoming/http/publish.js.map +1 -0
- package/dist/incoming/http/query.js +13 -23
- package/dist/incoming/http/query.js.map +1 -1
- package/dist/incoming/http/streamFunction/multiPart/index.js +9 -9
- package/dist/incoming/http/streamFunction/multiPart/index.js.map +1 -1
- package/dist/incoming/http/streamFunction/multiPart/readFormData.d.ts +1 -1
- package/dist/incoming/http/streamFunction/multiPart/readFormData.js +2 -2
- package/dist/incoming/http/streamFunction/multiPart/readFormData.js.map +1 -1
- package/dist/incoming/http/streamFunction/stream/createStream.d.ts +2 -3
- package/dist/incoming/http/streamFunction/stream/createStream.js +2 -2
- package/dist/incoming/http/streamFunction/stream/createStream.js.map +1 -1
- package/dist/incoming/http/streamFunction/stream/index.js +4 -3
- package/dist/incoming/http/streamFunction/stream/index.js.map +1 -1
- package/dist/incoming/index.d.ts +1 -1
- package/dist/incoming/index.js +66 -54
- package/dist/incoming/index.js.map +1 -1
- package/dist/incoming/upgrade.js +19 -12
- package/dist/incoming/upgrade.js.map +1 -1
- package/dist/incoming/ws/auth.d.ts +1 -1
- package/dist/incoming/ws/auth.js +70 -22
- package/dist/incoming/ws/auth.js.map +1 -1
- package/dist/incoming/ws/channelPublish.d.ts +2 -0
- package/dist/incoming/ws/channelPublish.js +60 -0
- package/dist/incoming/ws/channelPublish.js.map +1 -0
- package/dist/incoming/ws/channelSubscribe.d.ts +7 -0
- package/dist/incoming/ws/channelSubscribe.js +128 -0
- package/dist/incoming/ws/channelSubscribe.js.map +1 -0
- package/dist/incoming/ws/function.js +14 -7
- package/dist/incoming/ws/function.js.map +1 -1
- package/dist/incoming/ws/get.js +33 -29
- package/dist/incoming/ws/get.js.map +1 -1
- package/dist/incoming/ws/index.js +22 -2
- package/dist/incoming/ws/index.js.map +1 -1
- package/dist/incoming/ws/observable.js +24 -21
- package/dist/incoming/ws/observable.js.map +1 -1
- package/dist/incoming/ws/types.d.ts +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/installFn.js +32 -34
- package/dist/installFn.js.map +1 -1
- package/dist/observable/cleanup.d.ts +2 -0
- package/dist/observable/cleanup.js +66 -0
- package/dist/observable/cleanup.js.map +1 -0
- package/dist/observable/create.js +1 -0
- package/dist/observable/create.js.map +1 -1
- package/dist/observable/destroy.d.ts +2 -0
- package/dist/observable/destroy.js +26 -30
- package/dist/observable/destroy.js.map +1 -1
- package/dist/observable/extendCache.js +2 -3
- package/dist/observable/extendCache.js.map +1 -1
- package/dist/observable/genObservableId.js +3 -0
- package/dist/observable/genObservableId.js.map +1 -1
- package/dist/observable/get.d.ts +1 -1
- package/dist/observable/get.js +3 -3
- package/dist/observable/get.js.map +1 -1
- package/dist/observable/send.d.ts +1 -1
- package/dist/observable/send.js +2 -2
- package/dist/observable/send.js.map +1 -1
- package/dist/observable/start/error.d.ts +1 -1
- package/dist/observable/start/error.js +7 -2
- package/dist/observable/start/error.js.map +1 -1
- package/dist/observable/start/index.js +3 -1
- package/dist/observable/start/index.js.map +1 -1
- package/dist/observable/start/update.d.ts +1 -4
- package/dist/observable/start/update.js +0 -1
- package/dist/observable/start/update.js.map +1 -1
- package/dist/observable/subscribe.d.ts +1 -1
- package/dist/observable/subscribe.js +7 -8
- package/dist/observable/subscribe.js.map +1 -1
- package/dist/observable/types.d.ts +9 -9
- package/dist/observable/unsub.d.ts +1 -1
- package/dist/observable/unsub.js +9 -6
- package/dist/observable/unsub.js.map +1 -1
- package/dist/protocol.d.ts +1 -0
- package/dist/protocol.js +60 -48
- package/dist/protocol.js.map +1 -1
- package/dist/security.js +1 -0
- package/dist/security.js.map +1 -1
- package/dist/sendError.js +2 -4
- package/dist/sendError.js.map +1 -1
- package/dist/sendHttpResponse.js +16 -3
- package/dist/sendHttpResponse.js.map +1 -1
- package/dist/server.d.ts +24 -12
- package/dist/server.js +14 -8
- package/dist/server.js.map +1 -1
- package/dist/verifyRoute.d.ts +4 -3
- package/dist/verifyRoute.js +31 -20
- package/dist/verifyRoute.js.map +1 -1
- package/package.json +7 -7
- package/dist/functionApi/callFunction copy.d.ts +0 -3
- package/dist/functionApi/callFunction copy.js +0 -29
- package/dist/functionApi/callFunction copy.js.map +0 -1
- package/dist/incoming/http/get.d.ts +0 -4
- package/dist/incoming/http/get.js +0 -156
- package/dist/incoming/http/get.js.map +0 -1
- package/dist/incoming/http/streamFunction/DataStream.d.ts +0 -15
- package/dist/incoming/http/streamFunction/DataStream.js +0 -58
- package/dist/incoming/http/streamFunction/DataStream.js.map +0 -1
package/dist/error/types.d.ts
CHANGED
|
@@ -7,14 +7,9 @@ export declare enum BasedErrorCode {
|
|
|
7
7
|
FunctionError = 50001,
|
|
8
8
|
AuthorizeFunctionError = 50002,
|
|
9
9
|
NoOservableCacheAvailable = 50003,
|
|
10
|
-
ObservableFunctionError = 50004,
|
|
11
10
|
ObserveCallbackError = 50005,
|
|
12
11
|
FunctionNotFound = 40401,
|
|
13
|
-
|
|
14
|
-
FunctionIsObservable = 40403,
|
|
15
|
-
FunctionIsStream = 40404,
|
|
16
|
-
CannotStreamToObservableFunction = 40405,
|
|
17
|
-
FunctionIsNotStream = 40406,
|
|
12
|
+
FunctionIsWrongType = 40402,
|
|
18
13
|
AuthorizeRejectedError = 40301,
|
|
19
14
|
InvalidPayload = 40001,
|
|
20
15
|
PayloadTooLarge = 40002,
|
|
@@ -24,40 +19,47 @@ export declare enum BasedErrorCode {
|
|
|
24
19
|
LengthRequired = 41101,
|
|
25
20
|
MethodNotAllowed = 40501,
|
|
26
21
|
RateLimit = 40029,
|
|
27
|
-
MissingAuthStateProtocolHeader = 40030
|
|
22
|
+
MissingAuthStateProtocolHeader = 40030,
|
|
23
|
+
IncorrectAccessKey = 40031
|
|
28
24
|
}
|
|
29
|
-
|
|
25
|
+
type FunctionErrorProps = {
|
|
30
26
|
err: Error | string;
|
|
31
27
|
requestId?: number;
|
|
32
28
|
route: BasedRoute;
|
|
33
29
|
};
|
|
34
|
-
|
|
30
|
+
type ObservableFunctionErrorProps = {
|
|
35
31
|
observableId: number;
|
|
36
32
|
err: Error | string;
|
|
37
33
|
route: BasedRoute;
|
|
38
34
|
};
|
|
39
|
-
|
|
35
|
+
type ChannelFunctionErrorProps = {
|
|
36
|
+
channelId: number;
|
|
37
|
+
err: Error | string;
|
|
40
38
|
route: BasedRoute;
|
|
41
|
-
requestId?: number;
|
|
42
39
|
};
|
|
43
|
-
|
|
40
|
+
type BasedErrorPayload = {
|
|
44
41
|
observableId: number;
|
|
45
42
|
route: BasedRoute;
|
|
46
43
|
} | {
|
|
47
44
|
requestId: number;
|
|
48
45
|
route: BasedRoute;
|
|
46
|
+
} | {
|
|
47
|
+
channelId: number;
|
|
48
|
+
route: BasedRoute;
|
|
49
49
|
} | {
|
|
50
50
|
route: BasedRoute;
|
|
51
51
|
};
|
|
52
|
-
|
|
52
|
+
type BasedFunctionError = FunctionErrorProps | ObservableFunctionErrorProps | ChannelFunctionErrorProps;
|
|
53
|
+
export type ErrorPayload = {
|
|
54
|
+
[BasedErrorCode.FunctionNotFound]: BasedErrorPayload;
|
|
53
55
|
[BasedErrorCode.RateLimit]: {};
|
|
56
|
+
[BasedErrorCode.IncorrectAccessKey]: {};
|
|
54
57
|
[BasedErrorCode.MissingAuthStateProtocolHeader]: {};
|
|
55
58
|
[BasedErrorCode.NoBinaryProtocol]: {
|
|
56
59
|
buffer: ArrayBuffer;
|
|
57
60
|
};
|
|
58
|
-
[BasedErrorCode.FunctionError]:
|
|
59
|
-
[BasedErrorCode.
|
|
60
|
-
[BasedErrorCode.AuthorizeFunctionError]: FunctionErrorProps | ObservableFunctionErrorProps;
|
|
61
|
+
[BasedErrorCode.FunctionError]: BasedFunctionError;
|
|
62
|
+
[BasedErrorCode.AuthorizeFunctionError]: BasedFunctionError;
|
|
61
63
|
[BasedErrorCode.AuthorizeRejectedError]: BasedErrorPayload;
|
|
62
64
|
[BasedErrorCode.ObserveCallbackError]: {
|
|
63
65
|
err: Error;
|
|
@@ -68,15 +70,7 @@ export declare type ErrorPayload = {
|
|
|
68
70
|
observableId: number;
|
|
69
71
|
route: BasedRoute;
|
|
70
72
|
};
|
|
71
|
-
[BasedErrorCode.
|
|
72
|
-
[BasedErrorCode.FunctionIsStream]: BasedErrorPayload;
|
|
73
|
-
[BasedErrorCode.FunctionNotFound]: BasedErrorPayload;
|
|
74
|
-
[BasedErrorCode.FunctionIsNotObservable]: {
|
|
75
|
-
route: BasedRoute;
|
|
76
|
-
observableId?: number;
|
|
77
|
-
};
|
|
78
|
-
[BasedErrorCode.FunctionIsObservable]: FunctionBasicPayload;
|
|
79
|
-
[BasedErrorCode.CannotStreamToObservableFunction]: FunctionBasicPayload;
|
|
73
|
+
[BasedErrorCode.FunctionIsWrongType]: BasedErrorPayload;
|
|
80
74
|
[BasedErrorCode.InvalidPayload]: BasedErrorPayload;
|
|
81
75
|
[BasedErrorCode.PayloadTooLarge]: BasedErrorPayload;
|
|
82
76
|
[BasedErrorCode.ChunkTooLarge]: BasedRoute;
|
|
@@ -84,12 +78,12 @@ export declare type ErrorPayload = {
|
|
|
84
78
|
[BasedErrorCode.LengthRequired]: BasedRoute;
|
|
85
79
|
[BasedErrorCode.MethodNotAllowed]: BasedRoute;
|
|
86
80
|
};
|
|
87
|
-
export
|
|
81
|
+
export type ErrorHandler<T extends BasedErrorCode> = {
|
|
88
82
|
statusCode: number;
|
|
89
83
|
statusMessage: string;
|
|
90
84
|
message: (payload: ErrorPayload[T]) => string;
|
|
91
85
|
};
|
|
92
|
-
export
|
|
86
|
+
export type BasedErrorData<T extends BasedErrorCode = BasedErrorCode> = {
|
|
93
87
|
route: BasedRoute;
|
|
94
88
|
message: string;
|
|
95
89
|
code: T;
|
|
@@ -97,5 +91,6 @@ export declare type BasedErrorData<T extends BasedErrorCode = BasedErrorCode> =
|
|
|
97
91
|
statusMessage: string;
|
|
98
92
|
requestId?: number;
|
|
99
93
|
observableId?: number;
|
|
94
|
+
channelId?: number;
|
|
100
95
|
};
|
|
101
96
|
export {};
|
package/dist/error/types.js
CHANGED
|
@@ -10,14 +10,9 @@ var BasedErrorCode;
|
|
|
10
10
|
BasedErrorCode[BasedErrorCode["FunctionError"] = 50001] = "FunctionError";
|
|
11
11
|
BasedErrorCode[BasedErrorCode["AuthorizeFunctionError"] = 50002] = "AuthorizeFunctionError";
|
|
12
12
|
BasedErrorCode[BasedErrorCode["NoOservableCacheAvailable"] = 50003] = "NoOservableCacheAvailable";
|
|
13
|
-
BasedErrorCode[BasedErrorCode["ObservableFunctionError"] = 50004] = "ObservableFunctionError";
|
|
14
13
|
BasedErrorCode[BasedErrorCode["ObserveCallbackError"] = 50005] = "ObserveCallbackError";
|
|
15
14
|
BasedErrorCode[BasedErrorCode["FunctionNotFound"] = 40401] = "FunctionNotFound";
|
|
16
|
-
BasedErrorCode[BasedErrorCode["
|
|
17
|
-
BasedErrorCode[BasedErrorCode["FunctionIsObservable"] = 40403] = "FunctionIsObservable";
|
|
18
|
-
BasedErrorCode[BasedErrorCode["FunctionIsStream"] = 40404] = "FunctionIsStream";
|
|
19
|
-
BasedErrorCode[BasedErrorCode["CannotStreamToObservableFunction"] = 40405] = "CannotStreamToObservableFunction";
|
|
20
|
-
BasedErrorCode[BasedErrorCode["FunctionIsNotStream"] = 40406] = "FunctionIsNotStream";
|
|
15
|
+
BasedErrorCode[BasedErrorCode["FunctionIsWrongType"] = 40402] = "FunctionIsWrongType";
|
|
21
16
|
BasedErrorCode[BasedErrorCode["AuthorizeRejectedError"] = 40301] = "AuthorizeRejectedError";
|
|
22
17
|
BasedErrorCode[BasedErrorCode["InvalidPayload"] = 40001] = "InvalidPayload";
|
|
23
18
|
BasedErrorCode[BasedErrorCode["PayloadTooLarge"] = 40002] = "PayloadTooLarge";
|
|
@@ -28,5 +23,6 @@ var BasedErrorCode;
|
|
|
28
23
|
BasedErrorCode[BasedErrorCode["MethodNotAllowed"] = 40501] = "MethodNotAllowed";
|
|
29
24
|
BasedErrorCode[BasedErrorCode["RateLimit"] = 40029] = "RateLimit";
|
|
30
25
|
BasedErrorCode[BasedErrorCode["MissingAuthStateProtocolHeader"] = 40030] = "MissingAuthStateProtocolHeader";
|
|
26
|
+
BasedErrorCode[BasedErrorCode["IncorrectAccessKey"] = 40031] = "IncorrectAccessKey";
|
|
31
27
|
})(BasedErrorCode = exports.BasedErrorCode || (exports.BasedErrorCode = {}));
|
|
32
28
|
//# 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,cAkBX;AAlBD,WAAY,cAAc;IACxB,yEAAqB,CAAA;IACrB,2FAA8B,CAAA;IAC9B,iGAAiC,CAAA;IACjC,uFAA4B,CAAA;IAC5B,+EAAwB,CAAA;IACxB,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;IACtC,mFAA0B,CAAA;AAC5B,CAAC,EAlBW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAkBzB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.subscribeChannel = void 0;
|
|
4
|
+
const verifyRoute_1 = require("../verifyRoute");
|
|
5
|
+
const channel_1 = require("../channel");
|
|
6
|
+
const installFn_1 = require("../installFn");
|
|
7
|
+
const error_1 = require("../error");
|
|
8
|
+
const subscribeChannel = (server, name, id, payload, update) => {
|
|
9
|
+
const route = (0, verifyRoute_1.verifyRoute)(server, server.client.ctx, 'channel', server.functions.route(name), name, id);
|
|
10
|
+
if (route === null) {
|
|
11
|
+
throw new Error(`[${name}] No session in ctx`);
|
|
12
|
+
}
|
|
13
|
+
let isClosed = false;
|
|
14
|
+
const close = () => {
|
|
15
|
+
if (isClosed) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
isClosed = true;
|
|
19
|
+
(0, channel_1.unsubscribeFunction)(server, id, update);
|
|
20
|
+
};
|
|
21
|
+
if ((0, channel_1.hasChannel)(server, id)) {
|
|
22
|
+
(0, channel_1.subscribeChannelFunction)(server, id, update);
|
|
23
|
+
return close;
|
|
24
|
+
}
|
|
25
|
+
(0, installFn_1.installFn)(server, server.client.ctx, route).then((spec) => {
|
|
26
|
+
if (isClosed) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (spec === null) {
|
|
30
|
+
update(null, (0, error_1.createError)(server, server.client.ctx, error_1.BasedErrorCode.FunctionNotFound, {
|
|
31
|
+
route,
|
|
32
|
+
}));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (!(0, channel_1.hasChannel)(server, id)) {
|
|
36
|
+
(0, channel_1.createChannel)(server, name, id, payload, true);
|
|
37
|
+
}
|
|
38
|
+
(0, channel_1.subscribeChannelFunction)(server, id, update);
|
|
39
|
+
});
|
|
40
|
+
return close;
|
|
41
|
+
};
|
|
42
|
+
exports.subscribeChannel = subscribeChannel;
|
|
43
|
+
//# sourceMappingURL=channelSubscribe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channelS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B;gBACE,KAAK;aACN,CACF,CACF,CAAA;YACD,OAAM;SACP;QACD,IAAI,CAAC,IAAA,oBAAU,EAAC,MAAM,EAAE,EAAE,CAAC,EAAE;YAC3B,IAAA,uBAAa,EAAC,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA;SAC/C;QACD,IAAA,kCAAwB,EAAC,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,CAAA;IAC9C,CAAC,CAAC,CAAA;IAEF,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AA5DY,QAAA,gBAAgB,oBA4D5B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BasedChannel as BasedChannelAbstract, ChannelMessageFunction, Context, InternalSessionClient } from '@based/functions';
|
|
2
|
+
export declare class BasedChannel extends BasedChannelAbstract {
|
|
3
|
+
payload: any;
|
|
4
|
+
name: string;
|
|
5
|
+
id: number;
|
|
6
|
+
ctx: Context<InternalSessionClient>;
|
|
7
|
+
constructor(ctx: Context<InternalSessionClient>, name: string, payload: any);
|
|
8
|
+
subscribe(onMessage: ChannelMessageFunction, onError?: (err: any) => void): () => void;
|
|
9
|
+
publish(message: any, ctx?: Context): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BasedChannel = void 0;
|
|
4
|
+
const functions_1 = require("@based/functions");
|
|
5
|
+
const observable_1 = require("../../observable");
|
|
6
|
+
const publish_1 = require("../publish");
|
|
7
|
+
const channelSubscribe_1 = require("../channelSubscribe");
|
|
8
|
+
// add generics...
|
|
9
|
+
class BasedChannel extends functions_1.BasedChannel {
|
|
10
|
+
constructor(ctx, name, payload) {
|
|
11
|
+
super();
|
|
12
|
+
this.ctx = ctx;
|
|
13
|
+
this.payload = payload;
|
|
14
|
+
this.id = (0, observable_1.genObservableId)(name, payload);
|
|
15
|
+
this.name = name;
|
|
16
|
+
}
|
|
17
|
+
subscribe(onMessage, onError) {
|
|
18
|
+
return (0, channelSubscribe_1.subscribeChannel)(this.ctx.session.client.server, this.name, this.id, this.payload, (msg, err) => {
|
|
19
|
+
if (err) {
|
|
20
|
+
if (onError) {
|
|
21
|
+
onError(err);
|
|
22
|
+
}
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
onMessage(msg);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
publish(message, ctx = this.ctx) {
|
|
29
|
+
(0, publish_1.publish)(this.ctx.session.client.server, this.name, ctx, this.id, this.payload, message);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.BasedChannel = BasedChannel;
|
|
33
|
+
//# sourceMappingURL=channel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel.js","sourceRoot":"","sources":["../../../src/functionApi/client/channel.ts"],"names":[],"mappings":";;;AAAA,gDAKyB;AACzB,iDAAkD;AAClD,wCAAoC;AACpC,0DAAsD;AAEtD,kBAAkB;AAClB,MAAa,YAAa,SAAQ,wBAAoB;IAMpD,YAAY,GAAmC,EAAE,IAAY,EAAE,OAAY;QACzE,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,EAAE,GAAG,IAAA,4BAAe,EAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QACxC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAED,SAAS,CACP,SAAiC,EACjC,OAA4B;QAE5B,OAAO,IAAA,mCAAgB,EACrB,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAC9B,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,EAAE,EACP,IAAI,CAAC,OAAO,EACZ,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACX,IAAI,GAAG,EAAE;gBACP,IAAI,OAAO,EAAE;oBACX,OAAO,CAAC,GAAG,CAAC,CAAA;iBACb;gBACD,OAAM;aACP;YACD,SAAS,CAAC,GAAG,CAAC,CAAA;QAChB,CAAC,CACF,CAAA;IACH,CAAC;IAED,OAAO,CAAC,OAAY,EAAE,MAAe,IAAI,CAAC,GAAG;QAC3C,IAAA,iBAAO,EACL,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAC9B,IAAI,CAAC,IAAI,EACT,GAAG,EACH,IAAI,CAAC,EAAE,EACP,IAAI,CAAC,OAAO,EACZ,OAAO,CACR,CAAA;IACH,CAAC;CACF;AA7CD,oCA6CC"}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { BasedServer } from '../../server';
|
|
3
3
|
import { BasedQuery } from './query';
|
|
4
|
+
import { BasedChannel } from './channel';
|
|
4
5
|
import util from 'node:util';
|
|
5
|
-
import { AuthState, BasedFunctionClient as BasedfunctionClientAbstract, Context, InternalSessionClient, Session } from '@based/functions';
|
|
6
|
+
import { AuthState, BasedFunctionClient as BasedfunctionClientAbstract, Context, InternalSessionClient, StreamFunctionOpts, Session } from '@based/functions';
|
|
6
7
|
export declare class BasedFunctionClient extends BasedfunctionClientAbstract {
|
|
7
8
|
server: BasedServer;
|
|
8
9
|
ctx: Context<InternalSessionClient>;
|
|
9
10
|
constructor(server: BasedServer);
|
|
10
11
|
call(name: string, payload?: any, ctx?: Context): Promise<any>;
|
|
11
12
|
query(name: string, payload?: any): BasedQuery;
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
channel(name: string, payload?: any): BasedChannel;
|
|
14
|
+
stream(name: string, streamOpts: StreamFunctionOpts, ctx?: Context): Promise<any>;
|
|
15
|
+
renewAuthState(ctx: Context<Session>, authState?: AuthState): Promise<AuthState>;
|
|
14
16
|
setAuthState(ctx: Context<Session>, authState: AuthState): void;
|
|
15
17
|
sendAuthState(ctx: Context<Session>, authState: AuthState): void;
|
|
16
18
|
[util.inspect.custom](): string;
|
|
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.BasedFunctionClient = void 0;
|
|
7
7
|
const callFunction_1 = require("../callFunction");
|
|
8
8
|
const query_1 = require("./query");
|
|
9
|
+
const channel_1 = require("./channel");
|
|
10
|
+
const stream_1 = require("../stream");
|
|
9
11
|
const node_util_1 = __importDefault(require("node:util"));
|
|
10
12
|
const functions_1 = require("@based/functions");
|
|
11
13
|
class BasedFunctionClient extends functions_1.BasedFunctionClient {
|
|
@@ -13,7 +15,7 @@ class BasedFunctionClient extends functions_1.BasedFunctionClient {
|
|
|
13
15
|
super();
|
|
14
16
|
this.server = server;
|
|
15
17
|
this.ctx = {
|
|
16
|
-
session: { type: 'client', client: this },
|
|
18
|
+
session: { type: 'client', client: this, headers: {} },
|
|
17
19
|
};
|
|
18
20
|
}
|
|
19
21
|
// TODO: CTX - Transpile the ctx in there by static analysis for "call" & "stream"
|
|
@@ -23,12 +25,15 @@ class BasedFunctionClient extends functions_1.BasedFunctionClient {
|
|
|
23
25
|
query(name, payload) {
|
|
24
26
|
return new query_1.BasedQuery(this.ctx, name, payload);
|
|
25
27
|
}
|
|
26
|
-
|
|
28
|
+
channel(name, payload) {
|
|
29
|
+
return new channel_1.BasedChannel(this.ctx, name, payload);
|
|
30
|
+
}
|
|
31
|
+
async stream(name, streamOpts, ctx = this.ctx) {
|
|
27
32
|
// make later
|
|
28
|
-
return
|
|
33
|
+
return (0, stream_1.streamFunction)(this.server, name, ctx, streamOpts);
|
|
29
34
|
}
|
|
30
|
-
renewAuthState(ctx) {
|
|
31
|
-
this.server.auth.renewAuthState(ctx);
|
|
35
|
+
renewAuthState(ctx, authState) {
|
|
36
|
+
return this.server.auth.renewAuthState(ctx, authState);
|
|
32
37
|
}
|
|
33
38
|
setAuthState(ctx, authState) {
|
|
34
39
|
if (!ctx.session) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/functionApi/client/index.ts"],"names":[],"mappings":";;;;;;AACA,kDAA8C;AAC9C,mCAAoC;AACpC,0DAA4B;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/functionApi/client/index.ts"],"names":[],"mappings":";;;;;;AACA,kDAA8C;AAC9C,mCAAoC;AACpC,uCAAwC;AACxC,sCAA0C;AAC1C,0DAA4B;AAC5B,gDASyB;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,OAAO,EAAE,EAAE,EAAE;SACvD,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,OAAO,CAAC,IAAY,EAAE,OAAa;QACjC,OAAO,IAAI,sBAAY,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IAClD,CAAC;IAED,KAAK,CAAC,MAAM,CACV,IAAY,EACZ,UAA8B,EAC9B,MAAe,IAAI,CAAC,GAAG;QAEvB,aAAa;QACb,OAAO,IAAA,uBAAc,EAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,CAAC,CAAA;IAC3D,CAAC;IAED,cAAc,CACZ,GAAqB,EACrB,SAAqB;QAErB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,SAAS,CAAC,CAAA;IACxD,CAAC;IAED,YAAY,CAAC,GAAqB,EAAE,SAAoB;QACtD,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE;YAChB,OAAM;SACP;QACD,IAAI,CAAC,IAAA,2BAAe,EAAC,GAAG,CAAC,EAAE;YACzB,OAAM;SACP;QACD,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,SAAS,CAAA;QACjC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAA;IACtC,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;AA9DD,kDA8DC"}
|
package/dist/functionApi/get.js
CHANGED
|
@@ -6,9 +6,9 @@ const observable_1 = require("../observable");
|
|
|
6
6
|
const verifyRoute_1 = require("../verifyRoute");
|
|
7
7
|
const installFn_1 = require("../installFn");
|
|
8
8
|
const getObsData = (resolve, reject, server, id, ctx, route) => {
|
|
9
|
-
const obs = (0, observable_1.
|
|
9
|
+
const obs = (0, observable_1.getObsAndStopRemove)(server, id);
|
|
10
10
|
if (obs.error) {
|
|
11
|
-
reject((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.
|
|
11
|
+
reject((0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionError, {
|
|
12
12
|
route,
|
|
13
13
|
observableId: id,
|
|
14
14
|
err: obs.error.message,
|
|
@@ -1 +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,
|
|
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,MAAmE,EACnE,MAAmB,EACnB,EAAU,EACV,GAAY,EACZ,KAA8B,EAC9B,EAAE;IACF,MAAM,GAAG,GAAG,IAAA,gCAAmB,EAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IAC3C,IAAI,GAAG,CAAC,KAAK,EAAE;QACb,MAAM,CACJ,IAAA,mBAAW,EAAC,MAAM,EAAE,GAAG,EAAE,sBAAc,CAAC,aAAa,EAAE;YACrD,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,EAC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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"}
|
|
@@ -21,5 +21,7 @@ __exportStar(require("./client"), exports);
|
|
|
21
21
|
var protocol_1 = require("../protocol");
|
|
22
22
|
Object.defineProperty(exports, "decode", { enumerable: true, get: function () { return protocol_1.decode; } });
|
|
23
23
|
__exportStar(require("./observe"), exports);
|
|
24
|
-
|
|
24
|
+
__exportStar(require("./stream"), exports);
|
|
25
|
+
__exportStar(require("./publish"), exports);
|
|
26
|
+
__exportStar(require("./channelSubscribe"), exports);
|
|
25
27
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +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;
|
|
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;AACzB,2CAAwB;AACxB,4CAAyB;AACzB,qDAAkC"}
|
|
@@ -6,11 +6,11 @@ const verifyRoute_1 = require("../verifyRoute");
|
|
|
6
6
|
const observable_1 = require("../observable");
|
|
7
7
|
const installFn_1 = require("../installFn");
|
|
8
8
|
const observe = (server, name, ctx, payload, update, error) => {
|
|
9
|
-
const
|
|
9
|
+
const id = (0, observable_1.genObservableId)(name, payload);
|
|
10
|
+
const route = (0, verifyRoute_1.verifyRoute)(server, server.client.ctx, 'query', server.functions.route(name), name, id);
|
|
10
11
|
if (route === null) {
|
|
11
12
|
throw new Error(`[${name}] No session in ctx`);
|
|
12
13
|
}
|
|
13
|
-
const id = (0, observable_1.genObservableId)(name, payload);
|
|
14
14
|
let isClosed = false;
|
|
15
15
|
const close = () => {
|
|
16
16
|
if (isClosed) {
|
|
@@ -1 +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,
|
|
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,EAAE,GAAG,IAAA,4BAAe,EAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAEzC,MAAM,KAAK,GAAG,IAAA,yBAAW,EACvB,MAAM,EACN,MAAM,CAAC,MAAM,CAAC,GAAG,EACjB,OAAO,EACP,MAAM,CAAC,SAA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+1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.publish = void 0;
|
|
4
|
+
const verifyRoute_1 = require("../verifyRoute");
|
|
5
|
+
const installFn_1 = require("../installFn");
|
|
6
|
+
const error_1 = require("../error");
|
|
7
|
+
const publish = (server, name, ctx, id, payload, msg) => {
|
|
8
|
+
const route = (0, verifyRoute_1.verifyRoute)(server, server.client.ctx, 'channel', server.functions.route(name), name);
|
|
9
|
+
if (route === null) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
(0, installFn_1.installFn)(server, server.client.ctx, route).then((fn) => {
|
|
13
|
+
if (fn === null) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
return fn.publish(server.client, payload, msg, id, ctx);
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
// Will emit the error
|
|
21
|
+
(0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionError, {
|
|
22
|
+
err,
|
|
23
|
+
route,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
exports.publish = publish;
|
|
29
|
+
//# sourceMappingURL=publish.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../../src/functionApi/publish.ts"],"names":[],"mappings":";;;AAEA,gDAA4C;AAC5C,4CAAwC;AACxC,oCAAsD;AAE/C,MAAM,OAAO,GAAG,CACrB,MAAmB,EACnB,IAAY,EACZ,GAAY,EACZ,EAAU,EACV,OAAY,EACZ,GAAQ,EACR,EAAE;IACF,MAAM,KAAK,GAAG,IAAA,yBAAW,EACvB,MAAM,EACN,MAAM,CAAC,MAAM,CAAC,GAAG,EACjB,SAAS,EACT,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,EAC5B,IAAI,CACL,CAAA;IACD,IAAI,KAAK,KAAK,IAAI,EAAE;QAClB,OAAM;KACP;IACD,IAAA,qBAAS,EAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE;QACtD,IAAI,EAAE,KAAK,IAAI,EAAE;YACf,OAAM;SACP;QACD,IAAI;YACF,OAAO,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,CAAC,CAAA;SACxD;QAAC,OAAO,GAAG,EAAE;YACZ,sBAAsB;YACtB,IAAA,mBAAW,EAAC,MAAM,EAAE,GAAG,EAAE,sBAAc,CAAC,aAAa,EAAE;gBACrD,GAAG;gBACH,KAAK;aACN,CAAC,CAAA;SACH;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAhCY,QAAA,OAAO,WAgCnB"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { BasedServer } from '../server';
|
|
2
|
-
import { Context } from '@based/functions';
|
|
3
|
-
export declare const
|
|
2
|
+
import { Context, StreamFunctionOpts } from '@based/functions';
|
|
3
|
+
export declare const streamFunction: (server: BasedServer, name: string, ctx: Context, streamOpts: StreamFunctionOpts) => Promise<any>;
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.streamFunction = void 0;
|
|
4
4
|
const error_1 = require("../error");
|
|
5
|
+
const functions_1 = require("@based/functions");
|
|
5
6
|
const verifyRoute_1 = require("../verifyRoute");
|
|
6
7
|
const installFn_1 = require("../installFn");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const wrapStream = (stream, size) => {
|
|
9
|
+
if (stream instanceof functions_1.BasedDataStream) {
|
|
10
|
+
return stream;
|
|
11
|
+
}
|
|
12
|
+
const s = new functions_1.BasedDataStream(size);
|
|
13
|
+
stream.pipe(s);
|
|
14
|
+
return s;
|
|
15
|
+
};
|
|
16
|
+
const streamFunction = async (server, name, ctx, streamOpts) => {
|
|
17
|
+
const route = (0, verifyRoute_1.verifyRoute)(server, server.client.ctx, 'stream', server.functions.route(name), name);
|
|
10
18
|
if (route === null) {
|
|
11
19
|
return;
|
|
12
20
|
}
|
|
@@ -16,8 +24,38 @@ const stream = async (server, name, ctx, payload) => {
|
|
|
16
24
|
route,
|
|
17
25
|
});
|
|
18
26
|
}
|
|
27
|
+
let file;
|
|
28
|
+
if ((0, functions_1.isStreamFunctionOpts)(streamOpts)) {
|
|
29
|
+
const stream = wrapStream(streamOpts.contents, streamOpts.size);
|
|
30
|
+
file = {
|
|
31
|
+
stream,
|
|
32
|
+
mimeType: streamOpts.mimeType || 'text/plain',
|
|
33
|
+
fileName: streamOpts.fileName || '',
|
|
34
|
+
size: streamOpts.size || stream.size,
|
|
35
|
+
payload: streamOpts.payload,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const contents = streamOpts.contents;
|
|
40
|
+
const buffer = typeof contents === 'string'
|
|
41
|
+
? Buffer.from(contents)
|
|
42
|
+
: contents instanceof ArrayBuffer
|
|
43
|
+
? Buffer.from(contents)
|
|
44
|
+
: contents;
|
|
45
|
+
const stream = new functions_1.BasedDataStream(buffer.byteLength);
|
|
46
|
+
file = {
|
|
47
|
+
stream,
|
|
48
|
+
mimeType: streamOpts.mimeType || 'text/plain',
|
|
49
|
+
fileName: streamOpts.fileName || '',
|
|
50
|
+
size: stream.size,
|
|
51
|
+
payload: streamOpts.payload,
|
|
52
|
+
};
|
|
53
|
+
process.nextTick(() => {
|
|
54
|
+
stream.end(contents);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
19
57
|
try {
|
|
20
|
-
return fn.function(server.client,
|
|
58
|
+
return fn.function(server.client, file, ctx);
|
|
21
59
|
}
|
|
22
60
|
catch (err) {
|
|
23
61
|
throw (0, error_1.createError)(server, ctx, error_1.BasedErrorCode.FunctionError, {
|
|
@@ -26,5 +64,5 @@ const stream = async (server, name, ctx, payload) => {
|
|
|
26
64
|
});
|
|
27
65
|
}
|
|
28
66
|
};
|
|
29
|
-
exports.
|
|
67
|
+
exports.streamFunction = streamFunction;
|
|
30
68
|
//# sourceMappingURL=stream.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/functionApi/stream.ts"],"names":[],"mappings":";;;AACA,oCAAsD;
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/functionApi/stream.ts"],"names":[],"mappings":";;;AACA,oCAAsD;AACtD,gDAMyB;AACzB,gDAA4C;AAC5C,4CAAwC;AAGxC,MAAM,UAAU,GAAG,CACjB,MAA2C,EAC3C,IAAY,EACK,EAAE;IACnB,IAAI,MAAM,YAAY,2BAAe,EAAE;QACrC,OAAO,MAAM,CAAA;KACd;IACD,MAAM,CAAC,GAAG,IAAI,2BAAe,CAAC,IAAI,CAAC,CAAA;IACnC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACd,OAAO,CAAC,CAAA;AACV,CAAC,CAAA;AAEM,MAAM,cAAc,GAAG,KAAK,EACjC,MAAmB,EACnB,IAAY,EACZ,GAAY,EACZ,UAA8B,EAChB,EAAE;IAChB,MAAM,KAAK,GAAG,IAAA,yBAAW,EACvB,MAAM,EACN,MAAM,CAAC,MAAM,CAAC,GAAG,EACjB,QAAQ,EACR,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,EAA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,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,CAAA;KAC7C;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;AAtEY,QAAA,cAAc,kBAsE1B"}
|
|
@@ -14,6 +14,7 @@ export declare class BasedFunctions {
|
|
|
14
14
|
stream: number;
|
|
15
15
|
query: number;
|
|
16
16
|
function: number;
|
|
17
|
+
channel: number;
|
|
17
18
|
};
|
|
18
19
|
paths: {
|
|
19
20
|
[path: string]: string;
|
|
@@ -30,13 +31,13 @@ export declare class BasedFunctions {
|
|
|
30
31
|
constructor(server: BasedServer, config?: FunctionConfig);
|
|
31
32
|
uninstallLoop(): void;
|
|
32
33
|
updateConfig(config: FunctionConfig): void;
|
|
33
|
-
|
|
34
|
+
update(name: string, checksum: number): Promise<void>;
|
|
34
35
|
private installGaurdedFromConfig;
|
|
35
36
|
install(name: string): Promise<BasedSpec | null>;
|
|
36
37
|
getNameFromPath(path: string): string;
|
|
37
38
|
route(name?: string, path?: string): BasedRoute | null;
|
|
38
39
|
getFromStore(name: string): BasedSpec | null;
|
|
39
|
-
|
|
40
|
+
updateInternal(spec: BasedSpec): boolean;
|
|
40
41
|
remove(name: string): boolean;
|
|
41
42
|
uninstall(name: string, spec?: BasedSpec | false): Promise<boolean>;
|
|
42
43
|
}
|