@based/server 6.8.0 → 7.0.1
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 +4 -9
- package/dist/auth/defaultConfig.js.map +1 -1
- package/dist/auth/index.d.ts +3 -3
- package/dist/auth/index.js +21 -24
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/parseAuthState.js +3 -5
- package/dist/auth/parseAuthState.js.map +1 -1
- package/dist/auth/parseJSONAuthState.js +1 -3
- package/dist/auth/parseJSONAuthState.js.map +1 -1
- package/dist/authorize.d.ts +2 -2
- package/dist/authorize.js +17 -22
- package/dist/authorize.js.map +1 -1
- package/dist/channel/cleanup.d.ts +1 -1
- package/dist/channel/cleanup.js +2 -6
- package/dist/channel/cleanup.js.map +1 -1
- package/dist/channel/create.d.ts +2 -2
- package/dist/channel/create.js +5 -9
- package/dist/channel/create.js.map +1 -1
- package/dist/channel/destroy.d.ts +2 -2
- package/dist/channel/destroy.js +7 -12
- package/dist/channel/destroy.js.map +1 -1
- package/dist/channel/extend.d.ts +3 -3
- package/dist/channel/extend.js +2 -7
- package/dist/channel/extend.js.map +1 -1
- package/dist/channel/get.d.ts +2 -2
- package/dist/channel/get.js +4 -9
- package/dist/channel/get.js.map +1 -1
- package/dist/channel/index.d.ts +8 -8
- package/dist/channel/index.js +8 -24
- package/dist/channel/index.js.map +1 -1
- package/dist/channel/start.d.ts +1 -1
- package/dist/channel/start.js +10 -15
- package/dist/channel/start.js.map +1 -1
- package/dist/channel/subscribe.d.ts +1 -1
- package/dist/channel/subscribe.js +8 -13
- package/dist/channel/subscribe.js.map +1 -1
- package/dist/channel/types.js +1 -2
- package/dist/channel/types.js.map +1 -1
- package/dist/channel/unsub.d.ts +1 -1
- package/dist/channel/unsub.js +7 -13
- package/dist/channel/unsub.js.map +1 -1
- package/dist/compress.d.ts +1 -1
- package/dist/compress.js +9 -16
- package/dist/compress.js.map +1 -1
- package/dist/error/errorTypeHandlers.d.ts +1 -1
- package/dist/error/errorTypeHandlers.js +20 -23
- package/dist/error/errorTypeHandlers.js.map +1 -1
- package/dist/error/index.d.ts +4 -4
- package/dist/error/index.js +10 -29
- package/dist/error/index.js.map +1 -1
- package/dist/error/types.js +3 -6
- package/dist/error/types.js.map +1 -1
- package/dist/functionApi/callFunction.d.ts +1 -1
- package/dist/functionApi/callFunction.js +10 -14
- package/dist/functionApi/callFunction.js.map +1 -1
- package/dist/functionApi/channelSubscribe.d.ts +1 -1
- package/dist/functionApi/channelSubscribe.js +14 -18
- package/dist/functionApi/channelSubscribe.js.map +1 -1
- package/dist/functionApi/client/channel.js +12 -12
- package/dist/functionApi/client/channel.js.map +1 -1
- package/dist/functionApi/client/index.d.ts +4 -4
- package/dist/functionApi/client/index.js +15 -21
- package/dist/functionApi/client/index.js.map +1 -1
- package/dist/functionApi/client/query.d.ts +1 -1
- package/dist/functionApi/client/query.js +9 -10
- package/dist/functionApi/client/query.js.map +1 -1
- package/dist/functionApi/get.d.ts +1 -1
- package/dist/functionApi/get.js +17 -21
- package/dist/functionApi/get.js.map +1 -1
- package/dist/functionApi/index.d.ts +7 -8
- package/dist/functionApi/index.js +7 -26
- package/dist/functionApi/index.js.map +1 -1
- package/dist/functionApi/observe.d.ts +2 -2
- package/dist/functionApi/observe.js +15 -19
- package/dist/functionApi/observe.js.map +1 -1
- package/dist/functionApi/publish.d.ts +1 -1
- package/dist/functionApi/publish.js +7 -11
- package/dist/functionApi/publish.js.map +1 -1
- package/dist/functionApi/stream.d.ts +1 -1
- package/dist/functionApi/stream.js +13 -17
- package/dist/functionApi/stream.js.map +1 -1
- package/dist/functions/genVersion.js +8 -12
- package/dist/functions/genVersion.js.map +1 -1
- package/dist/functions/index.d.ts +5 -4
- package/dist/functions/index.js +54 -59
- package/dist/functions/index.js.map +1 -1
- package/dist/functions/timeout.js +2 -7
- package/dist/functions/timeout.js.map +1 -1
- package/dist/functions/types.d.ts +1 -1
- package/dist/functions/types.js +1 -2
- package/dist/incoming/http/function.d.ts +1 -1
- package/dist/incoming/http/function.js +13 -17
- package/dist/incoming/http/function.js.map +1 -1
- package/dist/incoming/http/handleRequest.d.ts +3 -0
- package/dist/incoming/http/handleRequest.js +11 -0
- package/dist/incoming/http/handleRequest.js.map +1 -0
- package/dist/incoming/http/index.d.ts +1 -1
- package/dist/incoming/http/index.js +54 -90
- package/dist/incoming/http/index.js.map +1 -1
- package/dist/incoming/http/parseQuery.d.ts +2 -2
- package/dist/incoming/http/parseQuery.js +9 -8
- package/dist/incoming/http/parseQuery.js.map +1 -1
- package/dist/incoming/http/publish.d.ts +1 -1
- package/dist/incoming/http/publish.js +16 -20
- package/dist/incoming/http/publish.js.map +1 -1
- package/dist/incoming/http/query.d.ts +1 -1
- package/dist/incoming/http/query.js +32 -46
- package/dist/incoming/http/query.js.map +1 -1
- package/dist/incoming/http/readBody.d.ts +1 -1
- package/dist/incoming/http/readBody.js +17 -25
- package/dist/incoming/http/readBody.js.map +1 -1
- package/dist/incoming/http/streamFunction/getExtension.js +3 -8
- package/dist/incoming/http/streamFunction/getExtension.js.map +1 -1
- package/dist/incoming/http/streamFunction/index.d.ts +1 -1
- package/dist/incoming/http/streamFunction/index.js +8 -12
- package/dist/incoming/http/streamFunction/index.js.map +1 -1
- package/dist/incoming/http/streamFunction/multiPart/index.d.ts +1 -1
- package/dist/incoming/http/streamFunction/multiPart/index.js +12 -19
- 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 +11 -16
- package/dist/incoming/http/streamFunction/multiPart/readFormData.js.map +1 -1
- package/dist/incoming/http/streamFunction/stream/createStream.d.ts +1 -1
- package/dist/incoming/http/streamFunction/stream/createStream.js +13 -18
- package/dist/incoming/http/streamFunction/stream/createStream.js.map +1 -1
- package/dist/incoming/http/streamFunction/stream/index.d.ts +1 -1
- package/dist/incoming/http/streamFunction/stream/index.js +19 -26
- package/dist/incoming/http/streamFunction/stream/index.js.map +1 -1
- package/dist/incoming/index.d.ts +1 -1
- package/dist/incoming/index.js +19 -24
- package/dist/incoming/index.js.map +1 -1
- package/dist/incoming/upgrade.d.ts +1 -1
- package/dist/incoming/upgrade.js +8 -13
- package/dist/incoming/upgrade.js.map +1 -1
- package/dist/incoming/ws/auth.d.ts +2 -2
- package/dist/incoming/ws/auth.js +19 -25
- package/dist/incoming/ws/auth.js.map +1 -1
- package/dist/incoming/ws/channelPublish.d.ts +1 -1
- package/dist/incoming/ws/channelPublish.js +17 -21
- package/dist/incoming/ws/channelPublish.js.map +1 -1
- package/dist/incoming/ws/channelSubscribe.d.ts +2 -2
- package/dist/incoming/ws/channelSubscribe.js +32 -38
- package/dist/incoming/ws/channelSubscribe.js.map +1 -1
- package/dist/incoming/ws/function.d.ts +1 -1
- package/dist/incoming/ws/function.js +23 -27
- package/dist/incoming/ws/function.js.map +1 -1
- package/dist/incoming/ws/get.d.ts +1 -1
- package/dist/incoming/ws/get.js +34 -38
- package/dist/incoming/ws/get.js.map +1 -1
- package/dist/incoming/ws/index.d.ts +1 -1
- package/dist/incoming/ws/index.js +19 -23
- package/dist/incoming/ws/index.js.map +1 -1
- package/dist/incoming/ws/query.d.ts +2 -2
- package/dist/incoming/ws/query.js +26 -32
- package/dist/incoming/ws/query.js.map +1 -1
- package/dist/incoming/ws/types.d.ts +1 -1
- package/dist/incoming/ws/types.js +1 -2
- package/dist/index.d.ts +9 -9
- package/dist/index.js +9 -29
- package/dist/index.js.map +1 -1
- package/dist/installFn.d.ts +3 -3
- package/dist/installFn.js +10 -14
- package/dist/installFn.js.map +1 -1
- package/dist/protocol.d.ts +1 -1
- package/dist/protocol.js +55 -78
- package/dist/protocol.js.map +1 -1
- package/dist/query/cleanup.d.ts +1 -1
- package/dist/query/cleanup.js +2 -6
- package/dist/query/cleanup.js.map +1 -1
- package/dist/query/create.d.ts +2 -2
- package/dist/query/create.js +5 -9
- package/dist/query/create.js.map +1 -1
- package/dist/query/destroy.d.ts +2 -2
- package/dist/query/destroy.js +7 -12
- package/dist/query/destroy.js.map +1 -1
- package/dist/query/extendCache.d.ts +1 -1
- package/dist/query/extendCache.js +1 -5
- package/dist/query/extendCache.js.map +1 -1
- package/dist/query/genObservableId.js +4 -8
- package/dist/query/genObservableId.js.map +1 -1
- package/dist/query/get.d.ts +2 -2
- package/dist/query/get.js +4 -9
- package/dist/query/get.js.map +1 -1
- package/dist/query/index.d.ts +10 -10
- package/dist/query/index.js +10 -26
- package/dist/query/index.js.map +1 -1
- package/dist/query/send.d.ts +2 -2
- package/dist/query/send.js +8 -13
- package/dist/query/send.js.map +1 -1
- package/dist/query/start/error.d.ts +2 -2
- package/dist/query/start/error.js +6 -10
- package/dist/query/start/error.js.map +1 -1
- package/dist/query/start/index.d.ts +1 -1
- package/dist/query/start/index.js +14 -19
- package/dist/query/start/index.js.map +1 -1
- package/dist/query/start/relay.d.ts +2 -2
- package/dist/query/start/relay.js +3 -7
- package/dist/query/start/relay.js.map +1 -1
- package/dist/query/start/update.d.ts +2 -2
- package/dist/query/start/update.js +18 -19
- package/dist/query/start/update.js.map +1 -1
- package/dist/query/subscribe.d.ts +3 -3
- package/dist/query/subscribe.js +13 -19
- package/dist/query/subscribe.js.map +1 -1
- package/dist/query/types.d.ts +1 -1
- package/dist/query/types.js +1 -2
- package/dist/query/unsub.d.ts +2 -2
- package/dist/query/unsub.js +7 -13
- package/dist/query/unsub.js.map +1 -1
- package/dist/security.d.ts +1 -1
- package/dist/security.js +8 -14
- package/dist/security.js.map +1 -1
- package/dist/sendError.d.ts +2 -2
- package/dist/sendError.js +21 -28
- package/dist/sendError.js.map +1 -1
- package/dist/sendHttpResponse.d.ts +1 -1
- package/dist/sendHttpResponse.js +11 -17
- package/dist/sendHttpResponse.js.map +1 -1
- package/dist/server.d.ts +8 -8
- package/dist/server.js +73 -64
- package/dist/server.js.map +1 -1
- package/dist/verifyRoute.d.ts +2 -2
- package/dist/verifyRoute.js +13 -17
- package/dist/verifyRoute.js.map +1 -1
- package/package.json +10 -14
|
@@ -1,29 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const enableSubscribe = (route, psec, server, ctx, payload, id, checksum) => {
|
|
12
|
-
if ((0, query_1.hasObs)(server, id)) {
|
|
13
|
-
(0, query_1.subscribeWs)(server, id, checksum, ctx);
|
|
1
|
+
import { decodePayload, decodeName, readUint8, parsePayload, } from '../../protocol.js';
|
|
2
|
+
import { createObs, unsubscribeWs, subscribeWs, hasObs, } from '../../query/index.js';
|
|
3
|
+
import { BasedErrorCode } from '../../error/index.js';
|
|
4
|
+
import { sendError } from '../../sendError.js';
|
|
5
|
+
import { rateLimitRequest } from '../../security.js';
|
|
6
|
+
import { verifyRoute } from '../../verifyRoute.js';
|
|
7
|
+
import { authorize, } from '../../authorize.js';
|
|
8
|
+
export const enableSubscribe = (route, _spec, server, ctx, payload, id, checksum) => {
|
|
9
|
+
if (hasObs(server, id)) {
|
|
10
|
+
subscribeWs(server, id, checksum, ctx);
|
|
14
11
|
return;
|
|
15
12
|
}
|
|
16
13
|
const session = ctx.session;
|
|
17
14
|
if (!session.obs.has(id)) {
|
|
18
15
|
return;
|
|
19
16
|
}
|
|
20
|
-
if (!
|
|
21
|
-
|
|
17
|
+
if (!hasObs(server, id)) {
|
|
18
|
+
createObs(server, route.name, id, payload);
|
|
22
19
|
}
|
|
23
|
-
|
|
20
|
+
subscribeWs(server, id, checksum, ctx);
|
|
24
21
|
};
|
|
25
|
-
|
|
26
|
-
const isNotAuthorized = (route, server, ctx, payload, id, checksum) => {
|
|
22
|
+
const isNotAuthorized = (route, _server, ctx, payload, id, checksum) => {
|
|
27
23
|
const session = ctx.session;
|
|
28
24
|
if (!session.unauthorizedObs) {
|
|
29
25
|
session.unauthorizedObs = new Set();
|
|
@@ -35,26 +31,26 @@ const isNotAuthorized = (route, server, ctx, payload, id, checksum) => {
|
|
|
35
31
|
payload,
|
|
36
32
|
});
|
|
37
33
|
};
|
|
38
|
-
const subscribeMessage = (arr, start, len, isDeflate, ctx, server) => {
|
|
34
|
+
export const subscribeMessage = (arr, start, len, isDeflate, ctx, server) => {
|
|
39
35
|
// | 4 header | 8 id | 8 checksum | 1 name length | * name | * payload |
|
|
40
36
|
const nameLen = arr[start + 20];
|
|
41
|
-
const id =
|
|
42
|
-
const checksum =
|
|
43
|
-
const name =
|
|
37
|
+
const id = readUint8(arr, start + 4, 8);
|
|
38
|
+
const checksum = readUint8(arr, start + 12, 8);
|
|
39
|
+
const name = decodeName(arr, start + 21, start + 21 + nameLen);
|
|
44
40
|
if (!name || !id) {
|
|
45
41
|
return false;
|
|
46
42
|
}
|
|
47
|
-
const route =
|
|
43
|
+
const route = verifyRoute(server, ctx, 'query', server.functions.route(name), name, id);
|
|
48
44
|
// TODO: add strictness setting - if strict return false here
|
|
49
45
|
if (route === null) {
|
|
50
46
|
return true;
|
|
51
47
|
}
|
|
52
|
-
if (
|
|
48
|
+
if (rateLimitRequest(server, ctx, route.rateLimitTokens, server.rateLimit.ws)) {
|
|
53
49
|
ctx.session.ws.close();
|
|
54
50
|
return false;
|
|
55
51
|
}
|
|
56
52
|
if (route.maxPayloadSize !== -1 && len > route.maxPayloadSize) {
|
|
57
|
-
|
|
53
|
+
sendError(server, ctx, BasedErrorCode.PayloadTooLarge, {
|
|
58
54
|
route,
|
|
59
55
|
observableId: id,
|
|
60
56
|
});
|
|
@@ -67,25 +63,23 @@ const subscribeMessage = (arr, start, len, isDeflate, ctx, server) => {
|
|
|
67
63
|
}
|
|
68
64
|
const payload = len === nameLen + 21
|
|
69
65
|
? undefined
|
|
70
|
-
:
|
|
66
|
+
: parsePayload(decodePayload(new Uint8Array(arr.slice(start + 21 + nameLen, start + len)), isDeflate));
|
|
71
67
|
session.obs.add(id);
|
|
72
|
-
|
|
68
|
+
authorize(route, server, ctx, payload, enableSubscribe, id, checksum, false, isNotAuthorized);
|
|
73
69
|
return true;
|
|
74
70
|
};
|
|
75
|
-
|
|
76
|
-
const unsubscribeMessage = (arr, start, len, isDeflate, ctx, server) => {
|
|
71
|
+
export const unsubscribeMessage = (arr, start, _len, _isDeflate, ctx, server) => {
|
|
77
72
|
// | 4 header | 8 id |
|
|
78
73
|
if (!ctx.session) {
|
|
79
74
|
return false;
|
|
80
75
|
}
|
|
81
|
-
const id =
|
|
76
|
+
const id = readUint8(arr, start + 4, 8);
|
|
82
77
|
if (!id) {
|
|
83
78
|
return false;
|
|
84
79
|
}
|
|
85
|
-
if (
|
|
80
|
+
if (unsubscribeWs(server, id, ctx)) {
|
|
86
81
|
ctx.session.ws.unsubscribe(String(id));
|
|
87
82
|
}
|
|
88
83
|
return true;
|
|
89
84
|
};
|
|
90
|
-
exports.unsubscribeMessage = unsubscribeMessage;
|
|
91
85
|
//# sourceMappingURL=query.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../../src/incoming/ws/query.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../../src/incoming/ws/query.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,UAAU,EACV,SAAS,EACT,YAAY,GACb,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,SAAS,EACT,aAAa,EACb,WAAW,EACX,MAAM,GACP,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAErD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EACL,SAAS,GAGV,MAAM,oBAAoB,CAAA;AAG3B,MAAM,CAAC,MAAM,eAA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GAAG,KAAK,OAAO,GAAG,EAAE;QAClB,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,YAAY,CACV,aAAa,CACX,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,GAAG,OAAO,EAAE,KAAK,GAAG,GAAG,CAAC,CAAC,EAC5D,SAAS,CACV,CACF,CAAA;IAEP,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IAEnB,SAAS,CACP,KAAK,EACL,MAAM,EACN,GAAG,EACH,OAAO,EACP,eAAe,EACf,EAAE,EACF,QAAQ,EACR,KAAK,EACL,eAAe,CAChB,CAAA;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAyB,CACtD,GAAG,EACH,KAAK,EACL,IAAI,EACJ,UAAU,EACV,GAAG,EACH,MAAM,EACN,EAAE;IACF,sBAAsB;IACtB,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE;QAChB,OAAO,KAAK,CAAA;KACb;IAED,MAAM,EAAE,GAAG,SAAS,CAAC,GAAG,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA;IAEvC,IAAI,CAAC,EAAE,EAAE;QACP,OAAO,KAAK,CAAA;KACb;IAED,IAAI,aAAa,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE;QAClC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAA;KACvC;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { BasedServer } from '../../server';
|
|
1
|
+
import { BasedServer } from '../../server.js';
|
|
2
2
|
import { WebSocketSession, Context } from '@based/functions';
|
|
3
3
|
export type BinaryMessageHandler = (arr: Uint8Array, start: number, len: number, isDeflate: boolean, ctx: Context<WebSocketSession>, server: BasedServer) => boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { compress } from './compress';
|
|
2
|
-
export { sendHttpResponse } from './sendHttpResponse';
|
|
3
|
-
export { sendError } from './sendError';
|
|
4
|
-
export * from './server';
|
|
5
|
-
export * from './functions/types';
|
|
6
|
-
export * from './error';
|
|
7
|
-
export * from './functionApi';
|
|
8
|
-
export * from './query/types';
|
|
9
|
-
export * from './protocol';
|
|
1
|
+
export { compress } from './compress.js';
|
|
2
|
+
export { sendHttpResponse } from './sendHttpResponse.js';
|
|
3
|
+
export { sendError } from './sendError.js';
|
|
4
|
+
export * from './server.js';
|
|
5
|
+
export * from './functions/types.js';
|
|
6
|
+
export * from './error/index.js';
|
|
7
|
+
export * from './functionApi/index.js';
|
|
8
|
+
export * from './query/types.js';
|
|
9
|
+
export * from './protocol.js';
|
package/dist/index.js
CHANGED
|
@@ -1,30 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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.sendError = exports.sendHttpResponse = exports.compress = void 0;
|
|
18
|
-
var compress_1 = require("./compress");
|
|
19
|
-
Object.defineProperty(exports, "compress", { enumerable: true, get: function () { return compress_1.compress; } });
|
|
20
|
-
var sendHttpResponse_1 = require("./sendHttpResponse");
|
|
21
|
-
Object.defineProperty(exports, "sendHttpResponse", { enumerable: true, get: function () { return sendHttpResponse_1.sendHttpResponse; } });
|
|
22
|
-
var sendError_1 = require("./sendError");
|
|
23
|
-
Object.defineProperty(exports, "sendError", { enumerable: true, get: function () { return sendError_1.sendError; } });
|
|
24
|
-
__exportStar(require("./server"), exports);
|
|
25
|
-
__exportStar(require("./functions/types"), exports);
|
|
26
|
-
__exportStar(require("./error"), exports);
|
|
27
|
-
__exportStar(require("./functionApi"), exports);
|
|
28
|
-
__exportStar(require("./query/types"), exports);
|
|
29
|
-
__exportStar(require("./protocol"), exports);
|
|
1
|
+
export { compress } from './compress.js';
|
|
2
|
+
export { sendHttpResponse } from './sendHttpResponse.js';
|
|
3
|
+
export { sendError } from './sendError.js';
|
|
4
|
+
export * from './server.js';
|
|
5
|
+
export * from './functions/types.js';
|
|
6
|
+
export * from './error/index.js';
|
|
7
|
+
export * from './functionApi/index.js';
|
|
8
|
+
export * from './query/types.js';
|
|
9
|
+
export * from './protocol.js';
|
|
30
10
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,cAAc,aAAa,CAAA;AAC3B,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,cAAc,wBAAwB,CAAA;AACtC,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA"}
|
package/dist/installFn.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { BasedServer } from './server';
|
|
2
|
-
import { Context, BasedRoute, BasedFunctionConfig
|
|
3
|
-
export declare const installFn: <R extends BasedRoute
|
|
1
|
+
import { BasedServer } from './server.js';
|
|
2
|
+
import { Context, BasedRoute, BasedFunctionConfig } from '@based/functions';
|
|
3
|
+
export declare const installFn: <R extends BasedRoute>(server: BasedServer, ctx: Context, route: R, id?: number) => Promise<BasedFunctionConfig<R["type"]>>;
|
package/dist/installFn.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const error_1 = require("./error");
|
|
7
|
-
const functionNotFound = (server, ctx, route, type, id) => {
|
|
8
|
-
if (!(0, functions_1.isClientContext)(ctx)) {
|
|
1
|
+
import { isClientContext, isBasedFunctionConfig, } from '@based/functions';
|
|
2
|
+
import { sendSimpleError } from './sendError.js';
|
|
3
|
+
import { BasedErrorCode } from './error/index.js';
|
|
4
|
+
const functionNotFound = (server, ctx, route, _type, id) => {
|
|
5
|
+
if (!isClientContext(ctx)) {
|
|
9
6
|
return;
|
|
10
7
|
}
|
|
11
|
-
|
|
8
|
+
sendSimpleError(server, ctx, BasedErrorCode.FunctionNotFound, { type: route.type, name: route.name }, id);
|
|
12
9
|
};
|
|
13
|
-
const installFn = async (server, ctx, route, id) => {
|
|
10
|
+
export const installFn = async (server, ctx, route, id) => {
|
|
14
11
|
if (!route) {
|
|
15
12
|
return null;
|
|
16
13
|
}
|
|
@@ -24,11 +21,11 @@ const installFn = async (server, ctx, route, id) => {
|
|
|
24
21
|
functionNotFound(server, ctx, route, type, id);
|
|
25
22
|
return null;
|
|
26
23
|
}
|
|
27
|
-
if (!
|
|
28
|
-
if (!
|
|
24
|
+
if (!isBasedFunctionConfig(type, route)) {
|
|
25
|
+
if (!isClientContext(ctx)) {
|
|
29
26
|
return null;
|
|
30
27
|
}
|
|
31
|
-
|
|
28
|
+
sendSimpleError(server, ctx, BasedErrorCode.FunctionIsWrongType, { name, type }, id);
|
|
32
29
|
return null;
|
|
33
30
|
}
|
|
34
31
|
// @ts-ignore Fixed by chekcing the specs
|
|
@@ -39,5 +36,4 @@ const installFn = async (server, ctx, route, id) => {
|
|
|
39
36
|
}
|
|
40
37
|
return null;
|
|
41
38
|
};
|
|
42
|
-
exports.installFn = installFn;
|
|
43
39
|
//# sourceMappingURL=installFn.js.map
|
package/dist/installFn.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installFn.js","sourceRoot":"","sources":["../src/installFn.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"installFn.js","sourceRoot":"","sources":["../src/installFn.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,eAAe,EAGf,qBAAqB,GAEtB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD,MAAM,gBAAgB,GAAG,CACvB,MAAmB,EACnB,GAAY,EACZ,KAAiB,EACjB,KAA0B,EAC1B,EAAW,EACX,EAAE;IACF,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE;QACzB,OAAM;KACP;IACD,eAAe,CACb,MAAM,EACN,GAAG,EACH,cAAc,CAAC,gBAAgB,EAC/B,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,EACtC,EAAE,CACH,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAC5B,MAAmB,EACnB,GAAY,EACZ,KAAQ,EACR,EAAW,EACqC,EAAE;IAClD,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,IAAI,CAAA;KACZ;IAED,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,KAAK,CAAA;IAC5B,IAAI;QACF,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QACjD,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE;YAChB,OAAO,IAAI,CAAA;SACZ;QAED,IAAI,IAAI,KAAK,IAAI,EAAE;YACjB,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;YAC9C,OAAO,IAAI,CAAA;SACZ;QAED,IAAI,CAAC,qBAAqB,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE;YACvC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE;gBACzB,OAAO,IAAI,CAAA;aACZ;YACD,eAAe,CACb,MAAM,EACN,GAAG,EACH,cAAc,CAAC,mBAAmB,EAClC,EAAE,IAAI,EAAE,IAAI,EAAE,EACd,EAAE,CACH,CAAA;YACD,OAAO,IAAI,CAAA;SACZ;QAED,yCAAyC;QACzC,OAAO,IAAI,CAAA;KACZ;IAAC,OAAO,GAAG,EAAE;QACZ,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;KAC/C;IACD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"}
|
package/dist/protocol.d.ts
CHANGED
package/dist/protocol.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
|
|
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.decode = exports.encodeChannelMessage = exports.encodeErrorResponse = exports.encodeAuthResponse = exports.encodeObservableDiffResponse = exports.encodeObservableResponse = exports.updateId = exports.encodeGetResponse = exports.encodeFunctionResponse = exports.decodeName = exports.parsePayload = exports.decodePayload = exports.valueToBuffer = exports.encodeHeader = exports.readUint8 = exports.storeUint8 = exports.decodeHeader = exports.COMPRESS_FROM_BYTES = void 0;
|
|
7
|
-
const node_zlib_1 = __importDefault(require("node:zlib"));
|
|
1
|
+
import zlib from 'node:zlib';
|
|
8
2
|
const textDecoder = new TextDecoder();
|
|
9
|
-
|
|
10
|
-
const decodeHeader = (nr) => {
|
|
3
|
+
export const COMPRESS_FROM_BYTES = 150;
|
|
4
|
+
export const decodeHeader = (nr) => {
|
|
11
5
|
// 4 bytes
|
|
12
6
|
// type (3 bits)
|
|
13
7
|
// 0 = function
|
|
@@ -30,16 +24,14 @@ const decodeHeader = (nr) => {
|
|
|
30
24
|
len,
|
|
31
25
|
};
|
|
32
26
|
};
|
|
33
|
-
|
|
34
|
-
const storeUint8 = (buff, n, start, len) => {
|
|
27
|
+
export const storeUint8 = (buff, n, start, len) => {
|
|
35
28
|
for (let index = start; index < start + len; index++) {
|
|
36
29
|
const byte = n & 0xff;
|
|
37
30
|
buff[index] = byte;
|
|
38
31
|
n = (n - byte) / 256;
|
|
39
32
|
}
|
|
40
33
|
};
|
|
41
|
-
|
|
42
|
-
const readUint8 = (buff, start, len) => {
|
|
34
|
+
export const readUint8 = (buff, start, len) => {
|
|
43
35
|
let n = 0;
|
|
44
36
|
const s = len - 1 + start;
|
|
45
37
|
for (let i = s; i >= start; i--) {
|
|
@@ -47,8 +39,7 @@ const readUint8 = (buff, start, len) => {
|
|
|
47
39
|
}
|
|
48
40
|
return n;
|
|
49
41
|
};
|
|
50
|
-
|
|
51
|
-
const encodeHeader = (type, isDeflate, len) => {
|
|
42
|
+
export const encodeHeader = (type, isDeflate, len) => {
|
|
52
43
|
// 4 bytes
|
|
53
44
|
// type (3 bits)
|
|
54
45
|
// 0 = functionData
|
|
@@ -65,8 +56,7 @@ const encodeHeader = (type, isDeflate, len) => {
|
|
|
65
56
|
const nr = (len << 4) + encodedMeta;
|
|
66
57
|
return nr;
|
|
67
58
|
};
|
|
68
|
-
|
|
69
|
-
const valueToBuffer = (payload) => {
|
|
59
|
+
export const valueToBuffer = (payload) => {
|
|
70
60
|
// can use a more elloborate typed response e.g. number etc in there
|
|
71
61
|
if (payload === undefined) {
|
|
72
62
|
return Buffer.from([]);
|
|
@@ -74,21 +64,19 @@ const valueToBuffer = (payload) => {
|
|
|
74
64
|
// TODO: only stringify if not string...
|
|
75
65
|
return Buffer.from(JSON.stringify(payload));
|
|
76
66
|
};
|
|
77
|
-
|
|
78
|
-
const decodePayload = (payload, isDeflate) => {
|
|
67
|
+
export const decodePayload = (payload, isDeflate) => {
|
|
79
68
|
if (!isDeflate) {
|
|
80
69
|
return textDecoder.decode(payload);
|
|
81
70
|
}
|
|
82
71
|
try {
|
|
83
|
-
const buffer =
|
|
72
|
+
const buffer = zlib.inflateRawSync(payload);
|
|
84
73
|
return textDecoder.decode(buffer);
|
|
85
74
|
}
|
|
86
75
|
catch (err) {
|
|
87
76
|
console.error('Error deflating payload', err);
|
|
88
77
|
}
|
|
89
78
|
};
|
|
90
|
-
|
|
91
|
-
const parsePayload = (payload) => {
|
|
79
|
+
export const parsePayload = (payload) => {
|
|
92
80
|
if (typeof payload === 'string') {
|
|
93
81
|
try {
|
|
94
82
|
return JSON.parse(payload);
|
|
@@ -97,32 +85,30 @@ const parsePayload = (payload) => {
|
|
|
97
85
|
}
|
|
98
86
|
return payload;
|
|
99
87
|
};
|
|
100
|
-
|
|
101
|
-
const decodeName = (arr, start, end) => {
|
|
88
|
+
export const decodeName = (arr, start, end) => {
|
|
102
89
|
const name = new Uint8Array(arr.slice(start, end));
|
|
103
90
|
return textDecoder.decode(name);
|
|
104
91
|
};
|
|
105
|
-
|
|
106
|
-
const encodeFunctionResponse = (id, buffer) => {
|
|
92
|
+
export const encodeFunctionResponse = (id, buffer) => {
|
|
107
93
|
// Type 0
|
|
108
94
|
// | 4 header | 3 id | * payload |
|
|
109
95
|
let isDeflate = false;
|
|
110
96
|
// TODO: implement for streams!
|
|
111
97
|
// chunk isChunk | isNotCunk | isLastchunk 0|1 (use 1 bye for now?)
|
|
112
98
|
const chunks = 1;
|
|
113
|
-
if (buffer.length >
|
|
99
|
+
if (buffer.length > COMPRESS_FROM_BYTES) {
|
|
114
100
|
isDeflate = true;
|
|
115
|
-
buffer =
|
|
101
|
+
buffer = zlib.deflateRawSync(buffer, {});
|
|
116
102
|
}
|
|
117
103
|
if (chunks === 1) {
|
|
118
104
|
const headerSize = 4;
|
|
119
105
|
const idSize = 3;
|
|
120
106
|
const msgSize = idSize + buffer.length;
|
|
121
|
-
const header =
|
|
107
|
+
const header = encodeHeader(0, isDeflate, msgSize);
|
|
122
108
|
// not very nessecary but ok
|
|
123
109
|
const array = new Uint8Array(headerSize + msgSize);
|
|
124
|
-
|
|
125
|
-
|
|
110
|
+
storeUint8(array, header, 0, 4);
|
|
111
|
+
storeUint8(array, id, 4, 3);
|
|
126
112
|
if (buffer.length) {
|
|
127
113
|
array.set(buffer, 7);
|
|
128
114
|
}
|
|
@@ -133,114 +119,106 @@ const encodeFunctionResponse = (id, buffer) => {
|
|
|
133
119
|
return new Uint8Array(0);
|
|
134
120
|
}
|
|
135
121
|
};
|
|
136
|
-
|
|
137
|
-
const encodeGetResponse = (id) => {
|
|
122
|
+
export const encodeGetResponse = (id) => {
|
|
138
123
|
// Type 4
|
|
139
124
|
// | 4 header | 8 id |
|
|
140
|
-
const header =
|
|
125
|
+
const header = encodeHeader(3, false, 8);
|
|
141
126
|
const array = new Uint8Array(12);
|
|
142
|
-
|
|
143
|
-
|
|
127
|
+
storeUint8(array, header, 0, 4);
|
|
128
|
+
storeUint8(array, id, 4, 8);
|
|
144
129
|
return array;
|
|
145
130
|
};
|
|
146
|
-
|
|
147
|
-
const updateId = (payload, id) => {
|
|
131
|
+
export const updateId = (payload, id) => {
|
|
148
132
|
const prevId = payload.slice(4, 12);
|
|
149
|
-
|
|
133
|
+
storeUint8(payload, id, 4, 8);
|
|
150
134
|
return prevId;
|
|
151
135
|
};
|
|
152
|
-
|
|
153
|
-
const encodeObservableResponse = (id, checksum, buffer) => {
|
|
136
|
+
export const encodeObservableResponse = (id, checksum, buffer) => {
|
|
154
137
|
// Type 1 (full data)
|
|
155
138
|
// | 4 header | 8 id | 8 checksum | * payload |
|
|
156
139
|
let isDeflate = false;
|
|
157
|
-
if (buffer.length >
|
|
140
|
+
if (buffer.length > COMPRESS_FROM_BYTES) {
|
|
158
141
|
isDeflate = true;
|
|
159
|
-
buffer =
|
|
142
|
+
buffer = zlib.deflateRawSync(buffer, {});
|
|
160
143
|
}
|
|
161
144
|
const msgSize = 16 + buffer.length;
|
|
162
|
-
const header =
|
|
145
|
+
const header = encodeHeader(1, isDeflate, msgSize);
|
|
163
146
|
const array = new Uint8Array(4 + msgSize);
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
147
|
+
storeUint8(array, header, 0, 4);
|
|
148
|
+
storeUint8(array, id, 4, 8);
|
|
149
|
+
storeUint8(array, checksum, 12, 8);
|
|
167
150
|
if (buffer.length) {
|
|
168
151
|
array.set(buffer, 20);
|
|
169
152
|
}
|
|
170
153
|
return [array, isDeflate];
|
|
171
154
|
};
|
|
172
|
-
|
|
173
|
-
const encodeObservableDiffResponse = (id, checksum, previousChecksum, buffer) => {
|
|
155
|
+
export const encodeObservableDiffResponse = (id, checksum, previousChecksum, buffer) => {
|
|
174
156
|
// Type 2 (diff data)
|
|
175
157
|
// | 4 header | 8 id | 8 checksum | 8 previousChecksum | * diff |
|
|
176
158
|
let isDeflate = false;
|
|
177
|
-
if (buffer.length >
|
|
159
|
+
if (buffer.length > COMPRESS_FROM_BYTES) {
|
|
178
160
|
isDeflate = true;
|
|
179
|
-
buffer =
|
|
161
|
+
buffer = zlib.deflateRawSync(buffer, {});
|
|
180
162
|
}
|
|
181
163
|
const msgSize = 24 + buffer.length;
|
|
182
|
-
const header =
|
|
164
|
+
const header = encodeHeader(2, isDeflate, msgSize);
|
|
183
165
|
const array = new Uint8Array(4 + msgSize);
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
166
|
+
storeUint8(array, header, 0, 4);
|
|
167
|
+
storeUint8(array, id, 4, 8);
|
|
168
|
+
storeUint8(array, checksum, 12, 8);
|
|
169
|
+
storeUint8(array, previousChecksum, 20, 8);
|
|
188
170
|
if (buffer.length) {
|
|
189
171
|
array.set(buffer, 28);
|
|
190
172
|
}
|
|
191
173
|
return array;
|
|
192
174
|
};
|
|
193
|
-
exports.encodeObservableDiffResponse = encodeObservableDiffResponse;
|
|
194
175
|
const encodeSimpleResponse = (type, buffer) => {
|
|
195
176
|
// | 4 header | * payload |
|
|
196
177
|
let isDeflate = false;
|
|
197
|
-
if (buffer.length >
|
|
178
|
+
if (buffer.length > COMPRESS_FROM_BYTES) {
|
|
198
179
|
isDeflate = true;
|
|
199
|
-
buffer =
|
|
180
|
+
buffer = zlib.deflateRawSync(buffer, {});
|
|
200
181
|
}
|
|
201
182
|
const headerSize = 4;
|
|
202
183
|
const msgSize = buffer.length;
|
|
203
|
-
const header =
|
|
184
|
+
const header = encodeHeader(type, isDeflate, msgSize);
|
|
204
185
|
const array = new Uint8Array(headerSize + msgSize);
|
|
205
|
-
|
|
186
|
+
storeUint8(array, header, 0, 4);
|
|
206
187
|
if (buffer.length) {
|
|
207
188
|
array.set(buffer, 4);
|
|
208
189
|
}
|
|
209
190
|
return array;
|
|
210
191
|
};
|
|
211
|
-
const encodeAuthResponse = (buffer) => {
|
|
192
|
+
export const encodeAuthResponse = (buffer) => {
|
|
212
193
|
// Type 4
|
|
213
194
|
return encodeSimpleResponse(4, buffer);
|
|
214
195
|
};
|
|
215
|
-
|
|
216
|
-
const encodeErrorResponse = (buffer) => {
|
|
196
|
+
export const encodeErrorResponse = (buffer) => {
|
|
217
197
|
// Type 5
|
|
218
198
|
return encodeSimpleResponse(5, buffer);
|
|
219
199
|
};
|
|
220
|
-
|
|
221
|
-
const encodeChannelMessage = (id, buffer) => {
|
|
200
|
+
export const encodeChannelMessage = (id, buffer) => {
|
|
222
201
|
// Type 7.0 (fill data)
|
|
223
202
|
// | 4 header | 1 subType | 8 id | * payload |
|
|
224
203
|
let isDeflate = false;
|
|
225
|
-
if (buffer.length >
|
|
204
|
+
if (buffer.length > COMPRESS_FROM_BYTES) {
|
|
226
205
|
isDeflate = true;
|
|
227
|
-
buffer =
|
|
206
|
+
buffer = zlib.deflateRawSync(buffer, {});
|
|
228
207
|
}
|
|
229
208
|
const msgSize = 8 + buffer.length + 1;
|
|
230
|
-
const header =
|
|
209
|
+
const header = encodeHeader(7, isDeflate, msgSize);
|
|
231
210
|
const array = new Uint8Array(4 + msgSize);
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
211
|
+
storeUint8(array, 0, 4, 1);
|
|
212
|
+
storeUint8(array, header, 0, 4);
|
|
213
|
+
storeUint8(array, id, 5, 8);
|
|
235
214
|
if (buffer.length) {
|
|
236
215
|
array.set(buffer, 13);
|
|
237
216
|
}
|
|
238
217
|
return array;
|
|
239
218
|
};
|
|
240
|
-
|
|
241
|
-
const
|
|
242
|
-
const
|
|
243
|
-
const { isDeflate, len, type } = (0, exports.decodeHeader)(header);
|
|
219
|
+
export const decode = (buffer) => {
|
|
220
|
+
const header = readUint8(buffer, 0, 4);
|
|
221
|
+
const { isDeflate, len, type } = decodeHeader(header);
|
|
244
222
|
if (type === 1) {
|
|
245
223
|
// | 4 header | 8 id | 8 checksum | * payload |
|
|
246
224
|
if (len === 16) {
|
|
@@ -248,8 +226,7 @@ const decode = (buffer) => {
|
|
|
248
226
|
}
|
|
249
227
|
const start = 20;
|
|
250
228
|
const end = len + 4;
|
|
251
|
-
return
|
|
229
|
+
return decodePayload(buffer.slice(start, end), isDeflate);
|
|
252
230
|
}
|
|
253
231
|
};
|
|
254
|
-
exports.decode = decode;
|
|
255
232
|
//# sourceMappingURL=protocol.js.map
|
package/dist/protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAA;AAErC,MAAM,CAAC,MAAM,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AC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;IACtC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,YAAY,CAAC,MAAM,CAAC,CAAA;IACrD,IAAI,IAAI,KAAK,CAAC,EAAE;QACd,+CAA+C;QAC/C,IAAI,GAAG,KAAK,EAAE,EAAE;YACd,OAAM;SACP;QACD,MAAM,KAAK,GAAG,EAAE,CAAA;QAChB,MAAM,GAAG,GAAG,GAAG,GAAG,CAAC,CAAA;QACnB,OAAO,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,SAAS,CAAC,CAAA;KAC1D;AACH,CAAC,CAAA"}
|
package/dist/query/cleanup.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { BasedServer } from '../server';
|
|
1
|
+
import { BasedServer } from '../server.js';
|
|
2
2
|
export declare const cleanUpObs: (server: BasedServer) => void;
|