@based/server 4.0.2 → 4.0.4
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 +11 -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.d.ts +3 -3
- package/dist/authorize.js +12 -2
- package/dist/authorize.js.map +1 -1
- 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 +46 -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 +63 -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 +13 -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 +14 -15
- package/dist/createSimpleServer.js +63 -25
- package/dist/createSimpleServer.js.map +1 -1
- package/dist/error/errorTypeHandlers.d.ts +1 -1
- package/dist/error/errorTypeHandlers.js +11 -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 +19 -26
- package/dist/error/types.js +1 -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 +6 -3
- package/dist/functionApi/client/index.js +18 -3
- 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 +47 -18
- 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 +96 -56
- package/dist/functions/types.js +16 -5
- package/dist/functions/types.js.map +1 -1
- package/dist/incoming/http/function.js +11 -12
- package/dist/incoming/http/function.js.map +1 -1
- package/dist/incoming/http/index.js +36 -9
- 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/{get.js → query.js} +41 -21
- package/dist/incoming/http/query.js.map +1 -0
- 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 +3 -2
- package/dist/incoming/http/streamFunction/stream/index.js.map +1 -1
- package/dist/incoming/index.d.ts +1 -1
- package/dist/incoming/index.js +32 -22
- package/dist/incoming/index.js.map +1 -1
- package/dist/incoming/upgrade.js +18 -11
- package/dist/incoming/upgrade.js.map +1 -1
- package/dist/incoming/ws/auth.d.ts +1 -1
- package/dist/incoming/ws/auth.js +56 -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 +73 -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 +118 -0
- package/dist/incoming/ws/channelSubscribe.js.map +1 -0
- package/dist/incoming/ws/function.js +11 -3
- package/dist/incoming/ws/function.js.map +1 -1
- package/dist/incoming/ws/get.js +16 -6
- 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 +16 -10
- package/dist/incoming/ws/observable.js.map +1 -1
- package/dist/incoming/ws/types.d.ts +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 +5 -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/sendError.js +2 -4
- package/dist/sendError.js.map +1 -1
- package/dist/sendHttpResponse.d.ts +3 -2
- package/dist/sendHttpResponse.js +63 -23
- package/dist/sendHttpResponse.js.map +1 -1
- package/dist/server.d.ts +22 -13
- package/dist/server.js +13 -10
- package/dist/server.js.map +1 -1
- package/dist/verifyRoute.d.ts +3 -3
- package/dist/verifyRoute.js +31 -20
- package/dist/verifyRoute.js.map +1 -1
- package/package.json +7 -7
- package/dist/incoming/http/authorize.d.ts +0 -4
- package/dist/incoming/http/authorize.js +0 -37
- package/dist/incoming/http/authorize.js.map +0 -1
- 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/incoming/http/streamFunction/multipartStream.d.ts +0 -12
- package/dist/incoming/http/streamFunction/multipartStream.js +0 -210
- package/dist/incoming/http/streamFunction/multipartStream.js.map +0 -1
- package/dist/incoming/http/streamFunction/stream.d.ts +0 -6
- package/dist/incoming/http/streamFunction/stream.js +0 -108
- package/dist/incoming/http/streamFunction/stream.js.map +0 -1
- package/dist/observable/error.d.ts +0 -4
- package/dist/observable/error.js +0 -17
- package/dist/observable/error.js.map +0 -1
- package/dist/observable/verify.d.ts +0 -4
- package/dist/observable/verify.js +0 -18
- package/dist/observable/verify.js.map +0 -1
- /package/dist/incoming/http/{get.d.ts → query.d.ts} +0 -0
|
@@ -1,55 +1,19 @@
|
|
|
1
|
-
import { BasedQueryFunction, BasedFunction,
|
|
1
|
+
import { BasedQueryFunction, BasedFunction, BasedChannelFunction, HttpResponse, UninstallFunction, BasedStreamFunction, BasedChannelPublishFunction } from '@based/functions';
|
|
2
2
|
import { BasedServer } from '../server';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export declare type BasedFunctionRoute = Route;
|
|
13
|
-
export declare type BasedQueryFunctionRoute = Route & {
|
|
14
|
-
query: true;
|
|
15
|
-
};
|
|
16
|
-
export declare type BasedStreamFunctionRoute = Route & {
|
|
17
|
-
stream: true;
|
|
18
|
-
};
|
|
19
|
-
export declare type BasedQueryFunctionSpec = {
|
|
20
|
-
customHttpResponse?: CustomHttpResponse;
|
|
21
|
-
checksum: number;
|
|
22
|
-
function: BasedQueryFunction;
|
|
23
|
-
memCacheTimeout?: number;
|
|
24
|
-
idleTimeout?: number;
|
|
25
|
-
timeoutCounter?: number;
|
|
26
|
-
} & BasedQueryFunctionRoute;
|
|
27
|
-
export declare type BasedStreamFunctionSpec = {
|
|
28
|
-
checksum: number;
|
|
29
|
-
function: BasedStreamFunction;
|
|
30
|
-
maxExecTime?: number;
|
|
31
|
-
idleTimeout?: number;
|
|
32
|
-
timeoutCounter?: number;
|
|
33
|
-
} & BasedStreamFunctionRoute;
|
|
34
|
-
export declare type BasedFunctionSpec = {
|
|
35
|
-
customHttpResponse?: CustomHttpResponse;
|
|
36
|
-
checksum: number;
|
|
37
|
-
function: BasedFunction;
|
|
38
|
-
maxExecTime?: number;
|
|
39
|
-
idleTimeout?: number;
|
|
40
|
-
timeoutCounter?: number;
|
|
41
|
-
} & BasedFunctionRoute;
|
|
42
|
-
export declare type BasedRoute = BasedFunctionRoute | BasedQueryFunctionRoute | BasedStreamFunctionRoute;
|
|
43
|
-
export declare type BasedSpec<R extends BasedRoute = BasedRoute> = R extends BasedQueryFunctionRoute ? BasedQueryFunctionSpec : R extends BasedStreamFunctionRoute ? BasedStreamFunctionSpec : BasedFunctionSpec;
|
|
44
|
-
export declare type FunctionConfig = {
|
|
45
|
-
memCacheTimeout?: number;
|
|
46
|
-
idleTimeout?: number;
|
|
47
|
-
maxWorkers?: number;
|
|
48
|
-
importWrapperPath?: string;
|
|
3
|
+
export type FunctionConfig = {
|
|
4
|
+
/** Default number to close channels & queries when no subscribers are active in ms */
|
|
5
|
+
closeAfterIdleTime?: {
|
|
6
|
+
query: number;
|
|
7
|
+
channel: number;
|
|
8
|
+
};
|
|
9
|
+
/** Default time to uinstall function after it has been idle in ms */
|
|
10
|
+
uninstallAfterIdleTime?: number;
|
|
11
|
+
/** Default max payload sizes in bytes */
|
|
49
12
|
maxPayLoadSizeDefaults?: {
|
|
50
13
|
stream: number;
|
|
51
14
|
query: number;
|
|
52
15
|
function: number;
|
|
16
|
+
channel: number;
|
|
53
17
|
};
|
|
54
18
|
route: (opts: {
|
|
55
19
|
server: BasedServer;
|
|
@@ -62,20 +26,96 @@ export declare type FunctionConfig = {
|
|
|
62
26
|
install: (opts: {
|
|
63
27
|
server: BasedServer;
|
|
64
28
|
name: string;
|
|
65
|
-
function?:
|
|
66
|
-
}) => Promise<null |
|
|
29
|
+
function?: BasedSpec;
|
|
30
|
+
}) => Promise<null | BasedSpec>;
|
|
67
31
|
uninstall: (opts: {
|
|
68
32
|
server: BasedServer;
|
|
69
33
|
name: string;
|
|
70
|
-
function:
|
|
34
|
+
function: BasedSpec;
|
|
71
35
|
}) => Promise<boolean>;
|
|
72
36
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
37
|
+
type Route = {
|
|
38
|
+
/** Function name */
|
|
39
|
+
name: string;
|
|
40
|
+
/** In addition to the name, a function can have a custom path for HTTP requests.
|
|
41
|
+
* For example: `path: 'my/custom/path'` will result in the function being
|
|
42
|
+
* available with a request to `edgeurl.based.io/my/custom/path`
|
|
43
|
+
*/
|
|
44
|
+
path?: string;
|
|
45
|
+
/** In bytes. `-1` indicates no size limit */
|
|
46
|
+
maxPayloadSize?: number;
|
|
47
|
+
/** Cost in tokens for this function call. */
|
|
48
|
+
rateLimitTokens?: number;
|
|
49
|
+
/** A function marked as `public` will skip the call to authorize. */
|
|
50
|
+
public?: boolean;
|
|
51
|
+
/** Array of headers that this function expects to receive. */
|
|
52
|
+
headers?: string[];
|
|
53
|
+
/** A function marked as `internalOnly` will only be accessible from other server side functions,
|
|
54
|
+
* and not through the public internet.
|
|
55
|
+
*/
|
|
56
|
+
internalOnly?: boolean;
|
|
57
|
+
};
|
|
58
|
+
export type BasedFunctionRoute = Route;
|
|
59
|
+
export type BasedQueryFunctionRoute = Route & {
|
|
60
|
+
query: true;
|
|
61
|
+
};
|
|
62
|
+
export type BasedStreamFunctionRoute = Route & {
|
|
63
|
+
stream: true;
|
|
64
|
+
};
|
|
65
|
+
export type BasedChannelFunctionRoute = Route & {
|
|
66
|
+
channel: true;
|
|
67
|
+
publisher?: {
|
|
68
|
+
public?: true;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
export type BasedInstallableFunctionSpec = {
|
|
72
|
+
/** Version hash of the BasedFunction */
|
|
73
|
+
checksum: number;
|
|
74
|
+
/** Uinstall function after it has been idle, in ms */
|
|
75
|
+
uninstallAfterIdleTime?: number;
|
|
76
|
+
/** In ms */
|
|
77
|
+
timeoutCounter?: number;
|
|
78
|
+
/** Hook that fires on uninstall of the function e.g. to clean up database connections */
|
|
79
|
+
uninstall?: UninstallFunction;
|
|
80
|
+
};
|
|
81
|
+
export type BasedQueryFunctionSpec = {
|
|
82
|
+
function: BasedQueryFunction;
|
|
83
|
+
/** How long should the query function remain active after all subscribers are gone, in ms */
|
|
84
|
+
closeAfterIdleTime?: number;
|
|
85
|
+
/** When in an HTTP context, this function is called to wrap the return value of the BasedFunction, and inject headers and a status code */
|
|
86
|
+
httpResponse?: HttpResponse;
|
|
87
|
+
} & BasedQueryFunctionRoute & BasedInstallableFunctionSpec;
|
|
88
|
+
export type BasedStreamFunctionSpec = {
|
|
89
|
+
function: BasedStreamFunction;
|
|
90
|
+
/** Maximum allowed execution time, in ms */
|
|
91
|
+
maxExecTime?: number;
|
|
92
|
+
} & BasedStreamFunctionRoute & BasedInstallableFunctionSpec;
|
|
93
|
+
export type BasedFunctionSpec = {
|
|
94
|
+
function: BasedFunction;
|
|
95
|
+
/** When in an HTTP context, this function is called to wrap the return value of the BasedFunction, and inject headers and a status code */
|
|
96
|
+
httpResponse?: HttpResponse;
|
|
97
|
+
/** Maximum allowed execution time, in ms */
|
|
98
|
+
maxExecTime?: number;
|
|
99
|
+
} & BasedFunctionRoute & BasedInstallableFunctionSpec;
|
|
100
|
+
export type BasedChannelFunctionSpec = {
|
|
101
|
+
function: BasedChannelFunction;
|
|
102
|
+
/** Publish allows publishing to channels */
|
|
103
|
+
publish: BasedChannelPublishFunction;
|
|
104
|
+
/** How long should the channel remain active after all subscribers ae gone, in ms */
|
|
105
|
+
closeAfterIdleTime?: number;
|
|
106
|
+
/** When in an HTTP context, this function is called to wrap the return value of the publish endpoint, and inject headers and a status code */
|
|
107
|
+
httpResponse?: HttpResponse;
|
|
108
|
+
} & BasedChannelFunctionRoute & BasedInstallableFunctionSpec;
|
|
109
|
+
export type BasedRoute = BasedFunctionRoute | BasedQueryFunctionRoute | BasedStreamFunctionRoute | BasedChannelFunctionRoute;
|
|
110
|
+
export type BasedSpec<R extends BasedRoute = BasedRoute> = R extends BasedChannelFunctionRoute ? BasedChannelFunctionSpec : R extends BasedQueryFunctionRoute ? BasedQueryFunctionSpec : R extends BasedStreamFunctionRoute ? BasedStreamFunctionSpec : BasedFunctionSpec;
|
|
111
|
+
export declare function isChannelFunctionSpec(fn: BasedSpec): fn is BasedChannelFunctionSpec;
|
|
112
|
+
export declare function isQueryFunctionSpec(fn: BasedSpec): fn is BasedQueryFunctionSpec;
|
|
113
|
+
export declare function isStreamFunctionSpec(fn: BasedSpec): fn is BasedQueryFunctionSpec;
|
|
114
|
+
export declare function isFunctionSpec(fn: BasedSpec): fn is BasedSpec;
|
|
76
115
|
export declare function isSpec(fn: any): fn is BasedSpec;
|
|
77
|
-
export declare function isQueryFunctionRoute(fn:
|
|
78
|
-
export declare function isStreamFunctionRoute(fn:
|
|
79
|
-
export declare function
|
|
116
|
+
export declare function isQueryFunctionRoute(fn: BasedRoute): fn is BasedQueryFunctionRoute;
|
|
117
|
+
export declare function isStreamFunctionRoute(fn: BasedRoute): fn is BasedStreamFunctionRoute;
|
|
118
|
+
export declare function isChannelFunctionRoute(fn: BasedRoute): fn is BasedChannelFunctionRoute;
|
|
119
|
+
export declare function isFunctionRoute(fn: BasedRoute): fn is BasedFunctionRoute;
|
|
80
120
|
export declare function isRoute(route: any): route is BasedRoute;
|
|
81
121
|
export {};
|
package/dist/functions/types.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isRoute = exports.isFunctionRoute = exports.isStreamFunctionRoute = exports.isQueryFunctionRoute = exports.isSpec = exports.isFunctionSpec = exports.isStreamFunctionSpec = exports.isQueryFunctionSpec = void 0;
|
|
4
|
-
// specs
|
|
3
|
+
exports.isRoute = exports.isFunctionRoute = exports.isChannelFunctionRoute = exports.isStreamFunctionRoute = exports.isQueryFunctionRoute = exports.isSpec = exports.isFunctionSpec = exports.isStreamFunctionSpec = exports.isQueryFunctionSpec = exports.isChannelFunctionSpec = void 0;
|
|
4
|
+
// ---------- specs -------------
|
|
5
|
+
function isChannelFunctionSpec(fn) {
|
|
6
|
+
return fn.channel === true;
|
|
7
|
+
}
|
|
8
|
+
exports.isChannelFunctionSpec = isChannelFunctionSpec;
|
|
5
9
|
function isQueryFunctionSpec(fn) {
|
|
6
10
|
return fn.query === true;
|
|
7
11
|
}
|
|
@@ -17,10 +21,13 @@ exports.isFunctionSpec = isFunctionSpec;
|
|
|
17
21
|
function isSpec(fn) {
|
|
18
22
|
return (fn &&
|
|
19
23
|
typeof fn === 'object' &&
|
|
20
|
-
(isFunctionSpec(fn) ||
|
|
24
|
+
(isFunctionSpec(fn) ||
|
|
25
|
+
isStreamFunctionSpec(fn) ||
|
|
26
|
+
isQueryFunctionSpec(fn) ||
|
|
27
|
+
isChannelFunctionSpec(fn)));
|
|
21
28
|
}
|
|
22
29
|
exports.isSpec = isSpec;
|
|
23
|
-
// routes
|
|
30
|
+
// ---------- routes -------------
|
|
24
31
|
function isQueryFunctionRoute(fn) {
|
|
25
32
|
return fn.query === true;
|
|
26
33
|
}
|
|
@@ -29,8 +36,12 @@ function isStreamFunctionRoute(fn) {
|
|
|
29
36
|
return fn.stream === true;
|
|
30
37
|
}
|
|
31
38
|
exports.isStreamFunctionRoute = isStreamFunctionRoute;
|
|
39
|
+
function isChannelFunctionRoute(fn) {
|
|
40
|
+
return fn.channel === true;
|
|
41
|
+
}
|
|
42
|
+
exports.isChannelFunctionRoute = isChannelFunctionRoute;
|
|
32
43
|
function isFunctionRoute(fn) {
|
|
33
|
-
return !('stream' in fn) && !('query' in fn);
|
|
44
|
+
return !('stream' in fn) && !('query' in fn) && !('channel' in fn);
|
|
34
45
|
}
|
|
35
46
|
exports.isFunctionRoute = isFunctionRoute;
|
|
36
47
|
function isRoute(route) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/functions/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/functions/types.ts"],"names":[],"mappings":";;;AAmJA,iCAAiC;AACjC,SAAgB,qBAAqB,CACnC,EAAa;IAEb,OAAQ,EAA+B,CAAC,OAAO,KAAK,IAAI,CAAA;AAC1D,CAAC;AAJD,sDAIC;AAED,SAAgB,mBAAmB,CACjC,EAAa;IAEb,OAAQ,EAA6B,CAAC,KAAK,KAAK,IAAI,CAAA;AACtD,CAAC;AAJD,kDAIC;AAED,SAAgB,oBAAoB,CAClC,EAAa;IAEb,OAAQ,EAA8B,CAAC,MAAM,KAAK,IAAI,CAAA;AACxD,CAAC;AAJD,oDAIC;AAED,SAAgB,cAAc,CAAC,EAAa;IAC1C,OAAO,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC,CAAA;AAC9C,CAAC;AAFD,wCAEC;AAED,SAAgB,MAAM,CAAC,EAAO;IAC5B,OAAO,CACL,EAAE;QACF,OAAO,EAAE,KAAK,QAAQ;QACtB,CAAC,cAAc,CAAC,EAAE,CAAC;YACjB,oBAAoB,CAAC,EAAE,CAAC;YACxB,mBAAmB,CAAC,EAAE,CAAC;YACvB,qBAAqB,CAAC,EAAE,CAAC,CAAC,CAC7B,CAAA;AACH,CAAC;AATD,wBASC;AAED,kCAAkC;AAClC,SAAgB,oBAAoB,CAClC,EAAc;IAEd,OAAQ,EAA8B,CAAC,KAAK,KAAK,IAAI,CAAA;AACvD,CAAC;AAJD,oDAIC;AAED,SAAgB,qBAAqB,CACnC,EAAc;IAEd,OAAQ,EAA+B,CAAC,MAAM,KAAK,IAAI,CAAA;AACzD,CAAC;AAJD,sDAIC;AAED,SAAgB,sBAAsB,CACpC,EAAc;IAEd,OAAQ,EAAgC,CAAC,OAAO,KAAK,IAAI,CAAA;AAC3D,CAAC;AAJD,wDAIC;AAED,SAAgB,eAAe,CAAC,EAAc;IAC5C,OAAO,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,CAAA;AACpE,CAAC;AAFD,0CAEC;AAED,SAAgB,OAAO,CAAC,KAAU;IAChC,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,IAAI,KAAK,EAAE;QACzD,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AALD,0BAKC"}
|
|
@@ -16,19 +16,18 @@ const httpFunction = async (route, server, ctx, payload) => {
|
|
|
16
16
|
if (!ctx.session) {
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// return
|
|
19
|
+
if (spec.httpResponse) {
|
|
20
|
+
const send = (responseData, headers, status) => {
|
|
21
|
+
(0, sendHttpResponse_1.sendHttpResponse)(ctx, responseData, headers, status !== undefined
|
|
22
|
+
? typeof status === 'string'
|
|
23
|
+
? status
|
|
24
|
+
: String(status)
|
|
25
|
+
: undefined);
|
|
26
|
+
};
|
|
27
|
+
await spec.httpResponse(server.client, payload, result, send, ctx);
|
|
28
|
+
return;
|
|
30
29
|
}
|
|
31
|
-
|
|
30
|
+
(0, sendHttpResponse_1.sendHttpResponse)(ctx, result);
|
|
32
31
|
})
|
|
33
32
|
.catch((err) => {
|
|
34
33
|
(0, sendError_1.sendError)(server, ctx, error_1.BasedErrorCode.FunctionError, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function.js","sourceRoot":"","sources":["../../../src/incoming/http/function.ts"],"names":[],"mappings":";;;AAEA,6DAAyD;AACzD,uCAA4C;AAC5C,+CAA2C;AAC3C,+CAA2C;AAGpC,MAAM,YAAY,GAAqC,KAAK,EACjE,KAAyB,EACzB,MAAM,EACN,GAAG,EACH,OAAO,EACP,EAAE;IACF,IAAA,qBAAS,EAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;QAC1C,IAAI,IAAI,KAAK,IAAI,EAAE;YACjB,OAAM;SACP;QACD,IAAI;aACD,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC;aACrC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;YACrB,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE;gBAChB,OAAM;aACP;
|
|
1
|
+
{"version":3,"file":"function.js","sourceRoot":"","sources":["../../../src/incoming/http/function.ts"],"names":[],"mappings":";;;AAEA,6DAAyD;AACzD,uCAA4C;AAC5C,+CAA2C;AAC3C,+CAA2C;AAGpC,MAAM,YAAY,GAAqC,KAAK,EACjE,KAAyB,EACzB,MAAM,EACN,GAAG,EACH,OAAO,EACP,EAAE;IACF,IAAA,qBAAS,EAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;QAC1C,IAAI,IAAI,KAAK,IAAI,EAAE;YACjB,OAAM;SACP;QACD,IAAI;aACD,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC;aACrC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;YACrB,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE;gBAChB,OAAM;aACP;YAED,IAAI,IAAI,CAAC,YAAY,EAAE;gBACrB,MAAM,IAAI,GAAqB,CAAC,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE;oBAC/D,IAAA,mCAAgB,EACd,GAAG,EACH,YAAY,EACZ,OAAO,EACP,MAAM,KAAK,SAAS;wBAClB,CAAC,CAAC,OAAO,MAAM,KAAK,QAAQ;4BAC1B,CAAC,CAAC,MAAM;4BACR,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;wBAClB,CAAC,CAAC,SAAS,CACd,CAAA;gBACH,CAAC,CAAA;gBACD,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,CAAA;gBAClE,OAAM;aACP;YAED,IAAA,mCAAgB,EAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QAC/B,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACb,IAAA,qBAAS,EAAC,MAAM,EAAE,GAAG,EAAE,sBAAc,CAAC,aAAa,EAAE;gBACnD,GAAG;gBACH,KAAK;aACN,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AA3CY,QAAA,YAAY,gBA2CxB"}
|
|
@@ -7,7 +7,7 @@ exports.httpHandler = void 0;
|
|
|
7
7
|
const function_1 = require("./function");
|
|
8
8
|
const streamFunction_1 = require("./streamFunction");
|
|
9
9
|
const functions_1 = require("../../functions");
|
|
10
|
-
const
|
|
10
|
+
const query_1 = require("./query");
|
|
11
11
|
const readBody_1 = require("./readBody");
|
|
12
12
|
const error_1 = require("../../error");
|
|
13
13
|
const sendError_1 = require("../../sendError");
|
|
@@ -17,6 +17,7 @@ const ip_1 = require("../../ip");
|
|
|
17
17
|
const auth_1 = require("../../auth");
|
|
18
18
|
const authorize_1 = require("../../authorize");
|
|
19
19
|
const sendHttpResponse_1 = require("../../sendHttpResponse");
|
|
20
|
+
const publish_1 = require("./publish");
|
|
20
21
|
let clientId = 0;
|
|
21
22
|
const handleRequest = (server, method, ctx, route, ready) => {
|
|
22
23
|
if (method === 'post') {
|
|
@@ -57,7 +58,20 @@ const httpHandler = (server, req, res) => {
|
|
|
57
58
|
: { route: { name: '', path: url } });
|
|
58
59
|
return;
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
+
let authState = {};
|
|
62
|
+
if (route.public !== true) {
|
|
63
|
+
const authorization = req.getHeader('authorization');
|
|
64
|
+
if (authorization) {
|
|
65
|
+
authState = (0, auth_1.parseAuthState)(authorization);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// TODO: remove this when c++ client can encode
|
|
69
|
+
const authorization = req.getHeader('json-authorization');
|
|
70
|
+
if (authorization) {
|
|
71
|
+
authState = (0, auth_1.parseJSONAuthState)(authorization);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
61
75
|
const ctx = {
|
|
62
76
|
session: {
|
|
63
77
|
res,
|
|
@@ -66,7 +80,7 @@ const httpHandler = (server, req, res) => {
|
|
|
66
80
|
ua: req.getHeader('user-agent'),
|
|
67
81
|
ip,
|
|
68
82
|
id: ++clientId,
|
|
69
|
-
authState
|
|
83
|
+
authState,
|
|
70
84
|
headers: {
|
|
71
85
|
'content-type': req.getHeader('content-type'),
|
|
72
86
|
'content-encoding': req.getHeader('content-encoding'),
|
|
@@ -83,7 +97,6 @@ const httpHandler = (server, req, res) => {
|
|
|
83
97
|
(0, security_1.endRateLimitHttp)(res);
|
|
84
98
|
return;
|
|
85
99
|
}
|
|
86
|
-
// double check impact
|
|
87
100
|
const query = req.getQuery();
|
|
88
101
|
if (query) {
|
|
89
102
|
ctx.session.query = query;
|
|
@@ -95,7 +108,7 @@ const httpHandler = (server, req, res) => {
|
|
|
95
108
|
}
|
|
96
109
|
if (method === 'post' &&
|
|
97
110
|
ctx.session.headers['content-length'] === undefined) {
|
|
98
|
-
//
|
|
111
|
+
// Zero allowed, but not for streams
|
|
99
112
|
(0, sendError_1.sendError)(server, ctx, error_1.BasedErrorCode.LengthRequired, route);
|
|
100
113
|
return;
|
|
101
114
|
}
|
|
@@ -108,7 +121,7 @@ const httpHandler = (server, req, res) => {
|
|
|
108
121
|
}
|
|
109
122
|
}
|
|
110
123
|
if ((0, functions_1.isQueryFunctionRoute)(route)) {
|
|
111
|
-
//
|
|
124
|
+
// Handle HEAD
|
|
112
125
|
if (method !== 'post' && method !== 'get') {
|
|
113
126
|
(0, sendError_1.sendError)(server, ctx, error_1.BasedErrorCode.MethodNotAllowed, route);
|
|
114
127
|
return;
|
|
@@ -117,7 +130,7 @@ const httpHandler = (server, req, res) => {
|
|
|
117
130
|
const checksumNum = Number(checksumRaw);
|
|
118
131
|
const checksum = !isNaN(checksumNum) ? checksumNum : 0;
|
|
119
132
|
handleRequest(server, method, ctx, route, (payload) => {
|
|
120
|
-
(0,
|
|
133
|
+
(0, query_1.httpGet)(route, payload, ctx, server, checksum);
|
|
121
134
|
});
|
|
122
135
|
return;
|
|
123
136
|
}
|
|
@@ -131,15 +144,29 @@ const httpHandler = (server, req, res) => {
|
|
|
131
144
|
return;
|
|
132
145
|
}
|
|
133
146
|
if (ctx.session.headers['content-length'] === 0) {
|
|
134
|
-
//
|
|
147
|
+
// Zero is also not allowed for streams
|
|
135
148
|
(0, sendError_1.sendError)(server, ctx, error_1.BasedErrorCode.LengthRequired, route);
|
|
136
149
|
return;
|
|
137
150
|
}
|
|
138
151
|
(0, streamFunction_1.httpStreamFunction)(server, ctx, route);
|
|
139
152
|
return;
|
|
140
153
|
}
|
|
154
|
+
if ((0, functions_1.isChannelFunctionRoute)(route)) {
|
|
155
|
+
if (method !== 'post' && method !== 'get') {
|
|
156
|
+
(0, sendError_1.sendError)(server, ctx, error_1.BasedErrorCode.MethodNotAllowed, route);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
handleRequest(server, method, ctx, route, (payload) => {
|
|
160
|
+
if (route.public || route.publisher?.public) {
|
|
161
|
+
(0, publish_1.httpPublish)(route, server, ctx, payload);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
(0, authorize_1.authorize)(route, server, ctx, payload, publish_1.httpPublish);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
141
169
|
if ((0, functions_1.isFunctionRoute)(route)) {
|
|
142
|
-
// handle HEAD
|
|
143
170
|
if (method !== 'post' && method !== 'get') {
|
|
144
171
|
(0, sendError_1.sendError)(server, ctx, error_1.BasedErrorCode.MethodNotAllowed, route);
|
|
145
172
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/incoming/http/index.ts"],"names":[],"mappings":";;;;;;AAGA,yCAAyC;AACzC,qDAAqD;AACrD,+
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/incoming/http/index.ts"],"names":[],"mappings":";;;;;;AAGA,yCAAyC;AACzC,qDAAqD;AACrD,+CAMwB;AACxB,mCAAiC;AACjC,yCAAqC;AACrC,uCAA4C;AAC5C,+CAA2C;AAC3C,6CAIuB;AACvB,8DAAqC;AACrC,iCAAgC;AAChC,qCAA+D;AAC/D,+CAA2C;AAC3C,6DAA4C;AAC5C,uCAAuC;AAEvC,IAAI,QAAQ,GAAG,CAAC,CAAA;AAEhB,MAAM,aAAa,GAAG,CACpB,MAAmB,EACnB,MAAc,EACd,GAAyB,EACzB,KAAyB,EACzB,KAA8B,EAC9B,EAAE;IACF,IAAI,MAAM,KAAK,MAAM,EAAE;QACrB,IAAA,mBAAQ,EAAC,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;KACpC;SAAM;QACL,KAAK,CAAC,IAAA,oBAAU,EAAC,GAAG,CAAC,CAAC,CAAA;KACvB;AACH,CAAC,CAAA;AAEM,MAAM,WAAW,GAAG,CACzB,MAAmB,EACnB,GAAoB,EACpB,GAAqB,EACrB,EAAE;IACF,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,GAAG,CAAC,OAAO,CAAC,GAAG,GAAG,IAAI,CAA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AAC,OAAO,EAAE,EAAE;YACpD,IAAI,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE;gBAC3C,IAAA,qBAAW,EAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,CAAA;aACzC;iBAAM;gBACL,IAAA,qBAAS,EAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,qBAAW,CAAC,CAAA;aACpD;QACH,CAAC,CAAC,CAAA;QACF,OAAM;KACP;IAED,IAAI,IAAA,2BAAe,EAAC,KAAK,CAAC,EAAE;QAC1B,IAAI,MAAM,KAAK,MAAM,IAAI,MAAM,KAAK,KAAK,EAAE;YACzC,IAAA,qBAAS,EAAC,MAAM,EAAE,GAAG,EAAE,sBAAc,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAA;YAC9D,OAAM;SACP;QACD,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,OAAO,EAAE,EAAE;YACpD,IAAA,qBAAS,EAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,uBAAY,CAAC,CAAA;QACtD,CAAC,CAAC,CAAA;KACH;AACH,CAAC,CAAA;AAhLY,QAAA,WAAW,eAgLvB"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.httpPublish = void 0;
|
|
4
|
+
const sendHttpResponse_1 = require("../../sendHttpResponse");
|
|
5
|
+
const error_1 = require("../../error");
|
|
6
|
+
const sendError_1 = require("../../sendError");
|
|
7
|
+
const installFn_1 = require("../../installFn");
|
|
8
|
+
const observable_1 = require("../../observable");
|
|
9
|
+
const channel_1 = require("../../channel");
|
|
10
|
+
const httpPublish = async (route, server, ctx, payload) => {
|
|
11
|
+
// parse channel payload / msg
|
|
12
|
+
let msg;
|
|
13
|
+
let channelPayload;
|
|
14
|
+
if (typeof payload !== 'object') {
|
|
15
|
+
msg = payload;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
if (payload.msg !== undefined) {
|
|
19
|
+
msg = payload.msg;
|
|
20
|
+
if (payload.channelid === undefined) {
|
|
21
|
+
channelPayload = {};
|
|
22
|
+
for (const key in payload) {
|
|
23
|
+
if (key === 'msg')
|
|
24
|
+
continue;
|
|
25
|
+
channelPayload[key] = payload[key];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
channelPayload = payload.channelid;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else if (payload.channelid !== undefined) {
|
|
33
|
+
msg = {};
|
|
34
|
+
for (const key in payload) {
|
|
35
|
+
if (key === 'channelid')
|
|
36
|
+
continue;
|
|
37
|
+
msg[key] = payload[key];
|
|
38
|
+
}
|
|
39
|
+
channelPayload = payload.channelid;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
msg = payload;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const name = route.name;
|
|
46
|
+
const id = (0, observable_1.genObservableId)(name, channelPayload);
|
|
47
|
+
(0, installFn_1.installFn)(server, ctx, route).then(async (spec) => {
|
|
48
|
+
if (spec === null) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (!(0, channel_1.hasChannel)(server, id)) {
|
|
52
|
+
(0, channel_1.createChannel)(server, name, id, channelPayload, true);
|
|
53
|
+
(0, channel_1.destroyChannel)(server, id);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
(0, channel_1.extendChannel)(server, server.activeChannelsById.get(id));
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
spec.publish(server.client, channelPayload, msg, id, ctx);
|
|
60
|
+
if (spec.httpResponse) {
|
|
61
|
+
const send = (responseData, headers, status) => {
|
|
62
|
+
(0, sendHttpResponse_1.sendHttpResponse)(ctx, responseData, headers, status !== undefined
|
|
63
|
+
? typeof status === 'string'
|
|
64
|
+
? status
|
|
65
|
+
: String(status)
|
|
66
|
+
: undefined);
|
|
67
|
+
};
|
|
68
|
+
await spec.httpResponse(server.client, payload, undefined, send, ctx);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
(0, sendHttpResponse_1.sendHttpResponse)(ctx, undefined);
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
(0, sendError_1.sendError)(server, ctx, error_1.BasedErrorCode.FunctionError, {
|
|
75
|
+
err,
|
|
76
|
+
route,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
exports.httpPublish = httpPublish;
|
|
82
|
+
//# sourceMappingURL=publish.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../../../src/incoming/http/publish.ts"],"names":[],"mappings":";;;AAEA,6DAAyD;AACzD,uCAA4C;AAC5C,+CAA2C;AAC3C,+CAA2C;AAE3C,iDAAkD;AAClD,2CAKsB;AAEf,MAAM,WAAW,GAAqC,KAAK,EAChE,KAAgC,EAChC,MAAM,EACN,GAAG,EACH,OAAO,EACP,EAAE;IACF,8BAA8B;IAC9B,IAAI,GAAQ,CAAA;IACZ,IAAI,cAAmB,CAAA;IACvB,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC/B,GAAG,GAAG,OAAO,CAAA;KACd;SAAM;QACL,IAAI,OAAO,CAAC,GAAG,KAAK,SAAS,EAAE;YAC7B,GAAG,GAAG,OAAO,CAAC,GAAG,CAAA;YACjB,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,EAAE;gBACnC,cAAc,GAAG,EAAE,CAAA;gBACnB,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE;oBACzB,IAAI,GAAG,KAAK,KAAK;wBAAE,SAAQ;oBAC3B,cAAc,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;iBACnC;aACF;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AE;oBAC/D,IAAA,mCAAgB,EACd,GAAG,EACH,YAAY,EACZ,OAAO,EACP,MAAM,KAAK,SAAS;wBAClB,CAAC,CAAC,OAAO,MAAM,KAAK,QAAQ;4BAC1B,CAAC,CAAC,MAAM;4BACR,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;wBAClB,CAAC,CAAC,SAAS,CACd,CAAA;gBACH,CAAC,CAAA;gBACD,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC,CAAA;gBACrE,OAAM;aACP;YACD,IAAA,mCAAgB,EAAC,GAAG,EAAE,SAAS,CAAC,CAAA;SACjC;QAAC,OAAO,GAAG,EAAE;YACZ,IAAA,qBAAS,EAAC,MAAM,EAAE,GAAG,EAAE,sBAAc,CAAC,aAAa,EAAE;gBACnD,GAAG;gBACH,KAAK;aACN,CAAC,CAAA;SACH;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AA5EY,QAAA,WAAW,eA4EvB"}
|
|
@@ -15,7 +15,7 @@ const node_util_1 = require("node:util");
|
|
|
15
15
|
const authorize_1 = require("../../authorize");
|
|
16
16
|
const installFn_1 = require("../../installFn");
|
|
17
17
|
const inflate = (0, node_util_1.promisify)(node_zlib_1.default.inflate);
|
|
18
|
-
const sendCacheSwapEncoding = async (server, route, ctx, buffer, checksum) => {
|
|
18
|
+
const sendCacheSwapEncoding = async (server, route, ctx, buffer, checksum, headers, status = '200 OK') => {
|
|
19
19
|
try {
|
|
20
20
|
const inflated = await inflate(buffer.slice(20));
|
|
21
21
|
const { payload, encoding } = await (0, compress_1.compress)(inflated, ctx.session.headers.encoding);
|
|
@@ -23,7 +23,10 @@ const sendCacheSwapEncoding = async (server, route, ctx, buffer, checksum) => {
|
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
25
|
ctx.session.res.cork(() => {
|
|
26
|
-
|
|
26
|
+
if (headers) {
|
|
27
|
+
(0, sendHttpResponse_1.sendHeaders)(ctx, headers);
|
|
28
|
+
}
|
|
29
|
+
ctx.session.res.writeStatus(status);
|
|
27
30
|
if (encoding) {
|
|
28
31
|
ctx.session.res.writeHeader('Content-Encoding', encoding);
|
|
29
32
|
}
|
|
@@ -35,9 +38,12 @@ const sendCacheSwapEncoding = async (server, route, ctx, buffer, checksum) => {
|
|
|
35
38
|
(0, sendError_1.sendError)(server, ctx, error_1.BasedErrorCode.UnsupportedContentEncoding, route);
|
|
36
39
|
}
|
|
37
40
|
};
|
|
38
|
-
const sendCache = (ctx, buffer, checksum, isDeflate) => {
|
|
41
|
+
const sendCache = (ctx, buffer, checksum, isDeflate, headers, status = '200 OK') => {
|
|
39
42
|
ctx.session.res.cork(() => {
|
|
40
|
-
|
|
43
|
+
if (headers) {
|
|
44
|
+
(0, sendHttpResponse_1.sendHeaders)(ctx, headers);
|
|
45
|
+
}
|
|
46
|
+
ctx.session.res.writeStatus(status);
|
|
41
47
|
ctx.session.res.writeHeader('ETag', String(checksum));
|
|
42
48
|
if (isDeflate) {
|
|
43
49
|
ctx.session.res.writeHeader('Content-Encoding', 'deflate');
|
|
@@ -45,13 +51,16 @@ const sendCache = (ctx, buffer, checksum, isDeflate) => {
|
|
|
45
51
|
(0, sendHttpResponse_1.end)(ctx, buffer.slice(20));
|
|
46
52
|
});
|
|
47
53
|
};
|
|
48
|
-
const sendNotModified = (ctx) => {
|
|
54
|
+
const sendNotModified = (ctx, headers, status = '304 Not Modified') => {
|
|
49
55
|
ctx.session.res.cork(() => {
|
|
50
|
-
|
|
56
|
+
if (headers) {
|
|
57
|
+
(0, sendHttpResponse_1.sendHeaders)(ctx, headers);
|
|
58
|
+
}
|
|
59
|
+
ctx.session.res.writeStatus(status);
|
|
51
60
|
(0, sendHttpResponse_1.end)(ctx);
|
|
52
61
|
});
|
|
53
62
|
};
|
|
54
|
-
const
|
|
63
|
+
const sendGetResponseInternal = (route, server, id, obs, checksum, ctx, headers, status) => {
|
|
55
64
|
if (!ctx.session) {
|
|
56
65
|
(0, observable_1.destroyObs)(server, id);
|
|
57
66
|
return;
|
|
@@ -66,14 +75,14 @@ const sendGetResponse = (route, server, id, obs, checksum, ctx) => {
|
|
|
66
75
|
}
|
|
67
76
|
else if (obs.isDeflate) {
|
|
68
77
|
if (typeof encoding === 'string' && encoding.includes('deflate')) {
|
|
69
|
-
sendCache(ctx, obs.cache, obs.checksum, true);
|
|
78
|
+
sendCache(ctx, obs.cache, obs.checksum, true, headers, status);
|
|
70
79
|
}
|
|
71
80
|
else {
|
|
72
|
-
sendCacheSwapEncoding(server, route, ctx, obs.cache, obs.checksum);
|
|
81
|
+
sendCacheSwapEncoding(server, route, ctx, obs.cache, obs.checksum, headers, status);
|
|
73
82
|
}
|
|
74
83
|
}
|
|
75
84
|
else {
|
|
76
|
-
sendCache(ctx, obs.cache, obs.checksum, false);
|
|
85
|
+
sendCache(ctx, obs.cache, obs.checksum, false, headers, status);
|
|
77
86
|
}
|
|
78
87
|
}
|
|
79
88
|
else {
|
|
@@ -81,14 +90,25 @@ const sendGetResponse = (route, server, id, obs, checksum, ctx) => {
|
|
|
81
90
|
}
|
|
82
91
|
(0, observable_1.destroyObs)(server, id);
|
|
83
92
|
};
|
|
84
|
-
const
|
|
85
|
-
|
|
93
|
+
const sendGetResponse = (route, spec, server, id, obs, checksum, ctx) => {
|
|
94
|
+
if ('httpResponse' in spec) {
|
|
95
|
+
// response data does not work for query responses
|
|
96
|
+
const send = (responseData, headers, status) => {
|
|
97
|
+
sendGetResponseInternal(route, server, id, obs, checksum, ctx, headers, typeof status === 'string' ? status : String(status));
|
|
98
|
+
};
|
|
99
|
+
spec.httpResponse(server.client, obs.payload, obs.cache, send, ctx);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
sendGetResponseInternal(route, server, id, obs, checksum, ctx);
|
|
103
|
+
};
|
|
104
|
+
const getFromExisting = (server, id, ctx, route, spec, checksum) => {
|
|
105
|
+
const obs = (0, observable_1.getObsAndStopRemove)(server, id);
|
|
86
106
|
if (obs.error) {
|
|
87
107
|
(0, observable_1.sendObsGetError)(server, ctx, obs.id, obs.error);
|
|
88
108
|
return;
|
|
89
109
|
}
|
|
90
110
|
if (obs.cache) {
|
|
91
|
-
sendGetResponse(route, server, id, obs, checksum, ctx);
|
|
111
|
+
sendGetResponse(route, spec, server, id, obs, checksum, ctx);
|
|
92
112
|
return;
|
|
93
113
|
}
|
|
94
114
|
(0, observable_1.subscribeNext)(obs, (err) => {
|
|
@@ -99,22 +119,22 @@ const getFromExisting = (server, id, ctx, route, checksum) => {
|
|
|
99
119
|
(0, observable_1.sendObsGetError)(server, ctx, obs.id, err);
|
|
100
120
|
}
|
|
101
121
|
else {
|
|
102
|
-
sendGetResponse(route, server, id, obs, checksum, ctx);
|
|
122
|
+
sendGetResponse(route, spec, server, id, obs, checksum, ctx);
|
|
103
123
|
}
|
|
104
124
|
});
|
|
105
125
|
};
|
|
106
126
|
const isAuthorized = (route, server, ctx, payload, id, checksum) => {
|
|
107
127
|
const name = route.name;
|
|
108
|
-
if (
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
128
|
+
// if (hasObs(server, id)) {
|
|
129
|
+
// getFromExisting(server, id, ctx, route, checksum)
|
|
130
|
+
// return
|
|
131
|
+
// }
|
|
112
132
|
(0, installFn_1.installFn)(server, ctx, route, id).then((spec) => {
|
|
113
133
|
if (spec === null) {
|
|
114
134
|
return;
|
|
115
135
|
}
|
|
116
136
|
if ((0, observable_1.hasObs)(server, id)) {
|
|
117
|
-
getFromExisting(server, id, ctx, route, checksum);
|
|
137
|
+
getFromExisting(server, id, ctx, route, spec, checksum);
|
|
118
138
|
return;
|
|
119
139
|
}
|
|
120
140
|
const obs = (0, observable_1.createObs)(server, name, id, payload, true);
|
|
@@ -123,7 +143,7 @@ const isAuthorized = (route, server, ctx, payload, id, checksum) => {
|
|
|
123
143
|
(0, observable_1.sendObsGetError)(server, ctx, obs.id, err);
|
|
124
144
|
}
|
|
125
145
|
else {
|
|
126
|
-
sendGetResponse(route, server, id, obs, checksum, ctx);
|
|
146
|
+
sendGetResponse(route, spec, server, id, obs, checksum, ctx);
|
|
127
147
|
}
|
|
128
148
|
});
|
|
129
149
|
(0, observable_1.start)(server, id);
|
|
@@ -142,4 +162,4 @@ const httpGet = (route, payload, ctx, server, checksum) => {
|
|
|
142
162
|
(0, authorize_1.authorize)(route, server, ctx, payload, isAuthorized, (0, observable_1.genObservableId)(route.name, payload), checksum);
|
|
143
163
|
};
|
|
144
164
|
exports.httpGet = httpGet;
|
|
145
|
-
//# sourceMappingURL=
|
|
165
|
+
//# sourceMappingURL=query.js.map
|