@based/server 6.0.0 → 6.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/package.json +2 -2
- package/dist/createSimpleServer.d.ts +0 -34
- package/dist/createSimpleServer.js +0 -209
- package/dist/createSimpleServer.js.map +0 -1
- package/dist/incoming/ws/observable.d.ts +0 -7
- package/dist/incoming/ws/observable.js +0 -91
- package/dist/incoming/ws/observable.js.map +0 -1
- package/dist/observable/cleanup.d.ts +0 -2
- package/dist/observable/cleanup.js +0 -66
- package/dist/observable/cleanup.js.map +0 -1
- package/dist/observable/create.d.ts +0 -3
- package/dist/observable/create.js +0 -35
- package/dist/observable/create.js.map +0 -1
- package/dist/observable/destroy.d.ts +0 -4
- package/dist/observable/destroy.js +0 -47
- package/dist/observable/destroy.js.map +0 -1
- package/dist/observable/extendCache.d.ts +0 -2
- package/dist/observable/extendCache.js +0 -10
- package/dist/observable/extendCache.js.map +0 -1
- package/dist/observable/genObservableId.d.ts +0 -1
- package/dist/observable/genObservableId.js +0 -12
- package/dist/observable/genObservableId.js.map +0 -1
- package/dist/observable/get.d.ts +0 -4
- package/dist/observable/get.js +0 -15
- package/dist/observable/get.js.map +0 -1
- package/dist/observable/index.d.ts +0 -10
- package/dist/observable/index.js +0 -27
- package/dist/observable/index.js.map +0 -1
- package/dist/observable/send.d.ts +0 -5
- package/dist/observable/send.js +0 -26
- package/dist/observable/send.js.map +0 -1
- package/dist/observable/start/error.d.ts +0 -3
- package/dist/observable/start/error.js +0 -44
- package/dist/observable/start/error.js.map +0 -1
- package/dist/observable/start/index.d.ts +0 -2
- package/dist/observable/start/index.js +0 -67
- package/dist/observable/start/index.js.map +0 -1
- package/dist/observable/start/relay.d.ts +0 -4
- package/dist/observable/start/relay.js +0 -14
- package/dist/observable/start/relay.js.map +0 -1
- package/dist/observable/start/update.d.ts +0 -3
- package/dist/observable/start/update.js +0 -116
- package/dist/observable/start/update.js.map +0 -1
- package/dist/observable/subscribe.d.ts +0 -7
- package/dist/observable/subscribe.js +0 -47
- package/dist/observable/subscribe.js.map +0 -1
- package/dist/observable/types.d.ts +0 -25
- package/dist/observable/types.js +0 -3
- package/dist/observable/types.js.map +0 -1
- package/dist/observable/unsub.d.ts +0 -6
- package/dist/observable/unsub.js +0 -46
- package/dist/observable/unsub.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@based/server",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"jsonexport": "^3.2.0",
|
|
29
29
|
"jsonwebtoken": "^8.5.1",
|
|
30
30
|
"mime-types": "^2.1.31",
|
|
31
|
-
"@based/functions": "^2.0.
|
|
31
|
+
"@based/functions": "^2.0.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/mime-types": "2.1.1",
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { BasedFunctionSpec, BasedQueryFunctionSpec, BasedStreamFunctionSpec, BasedSpec, BasedChannelFunctionSpec } from './functions';
|
|
2
|
-
import { BasedQueryFunction, BasedFunction, BasedChannelFunction, BasedStreamFunction } from '@based/functions';
|
|
3
|
-
import { BasedServer, ServerOptions } from './server';
|
|
4
|
-
export type SimpleServerOptions = {
|
|
5
|
-
install?: (opts: {
|
|
6
|
-
server: BasedServer;
|
|
7
|
-
name: string;
|
|
8
|
-
function?: BasedSpec;
|
|
9
|
-
}) => Promise<null | BasedSpec>;
|
|
10
|
-
uninstall?: (opts: {
|
|
11
|
-
server: BasedServer;
|
|
12
|
-
name: string;
|
|
13
|
-
function: BasedSpec;
|
|
14
|
-
}) => Promise<boolean>;
|
|
15
|
-
functions?: {
|
|
16
|
-
[key: string]: BasedFunction | Partial<BasedFunctionSpec>;
|
|
17
|
-
};
|
|
18
|
-
streams?: {
|
|
19
|
-
[key: string]: BasedStreamFunction | Partial<BasedStreamFunctionSpec>;
|
|
20
|
-
};
|
|
21
|
-
queryFunctions?: {
|
|
22
|
-
[key: string]: BasedQueryFunction | Partial<BasedQueryFunctionSpec>;
|
|
23
|
-
};
|
|
24
|
-
channels?: {
|
|
25
|
-
[key: string]: BasedChannelFunction | Partial<BasedChannelFunctionSpec>;
|
|
26
|
-
};
|
|
27
|
-
silent?: boolean;
|
|
28
|
-
closeAfterIdleTime?: {
|
|
29
|
-
channel: number;
|
|
30
|
-
query: number;
|
|
31
|
-
};
|
|
32
|
-
uninstallAfterIdleTime?: number;
|
|
33
|
-
} & Omit<ServerOptions, 'functions'>;
|
|
34
|
-
export declare function createSimpleServer(props: SimpleServerOptions, sharedSocket?: boolean): Promise<BasedServer>;
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createSimpleServer = void 0;
|
|
7
|
-
const functions_1 = require("./functions");
|
|
8
|
-
const picocolors_1 = __importDefault(require("picocolors"));
|
|
9
|
-
const server_1 = require("./server");
|
|
10
|
-
const utils_1 = require("@saulx/utils");
|
|
11
|
-
async function createSimpleServer(props, sharedSocket) {
|
|
12
|
-
const { functions, queryFunctions, streams, channels } = props;
|
|
13
|
-
const functionStore = {};
|
|
14
|
-
for (const name in functions) {
|
|
15
|
-
if (functions[name]) {
|
|
16
|
-
const fn = functions[name];
|
|
17
|
-
if ((0, functions_1.isSpec)(fn)) {
|
|
18
|
-
functionStore[name] = {
|
|
19
|
-
function: fn.function,
|
|
20
|
-
name,
|
|
21
|
-
checksum: 1,
|
|
22
|
-
maxPayloadSize: 5e4,
|
|
23
|
-
rateLimitTokens: 1,
|
|
24
|
-
...fn,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
else if (typeof fn === 'function') {
|
|
28
|
-
functionStore[name] = {
|
|
29
|
-
function: fn,
|
|
30
|
-
name,
|
|
31
|
-
checksum: 1,
|
|
32
|
-
maxPayloadSize: 5e4,
|
|
33
|
-
rateLimitTokens: 1,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
console.error(name, fn, 'Is not a function!');
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
for (const name in queryFunctions) {
|
|
42
|
-
if (queryFunctions[name]) {
|
|
43
|
-
const fn = queryFunctions[name];
|
|
44
|
-
if ((0, functions_1.isSpec)(fn)) {
|
|
45
|
-
functionStore[name] = {
|
|
46
|
-
checksum: 1,
|
|
47
|
-
query: true,
|
|
48
|
-
function: fn.function,
|
|
49
|
-
name,
|
|
50
|
-
maxPayloadSize: 5000,
|
|
51
|
-
rateLimitTokens: 1,
|
|
52
|
-
...fn,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
else if (typeof fn === 'function') {
|
|
56
|
-
functionStore[name] = {
|
|
57
|
-
checksum: 1,
|
|
58
|
-
query: true,
|
|
59
|
-
function: fn,
|
|
60
|
-
name,
|
|
61
|
-
maxPayloadSize: 5000,
|
|
62
|
-
rateLimitTokens: 1,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
console.error(name, fn, 'Is not a query function!');
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
for (const name in streams) {
|
|
71
|
-
if (streams[name]) {
|
|
72
|
-
const fn = streams[name];
|
|
73
|
-
if ((0, functions_1.isSpec)(fn)) {
|
|
74
|
-
functionStore[name] = {
|
|
75
|
-
checksum: 1,
|
|
76
|
-
stream: true,
|
|
77
|
-
function: fn.function,
|
|
78
|
-
name,
|
|
79
|
-
maxPayloadSize: 1e9,
|
|
80
|
-
rateLimitTokens: 10,
|
|
81
|
-
...fn,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
else if (typeof fn === 'function') {
|
|
85
|
-
functionStore[name] = {
|
|
86
|
-
checksum: 1,
|
|
87
|
-
stream: true,
|
|
88
|
-
function: fn,
|
|
89
|
-
name,
|
|
90
|
-
maxPayloadSize: 1e9,
|
|
91
|
-
rateLimitTokens: 10,
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
console.error(name, fn, 'Is not a stream function!');
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
for (const name in channels) {
|
|
100
|
-
if (channels[name]) {
|
|
101
|
-
const fn = channels[name];
|
|
102
|
-
if ((0, functions_1.isSpec)(fn)) {
|
|
103
|
-
functionStore[name] = {
|
|
104
|
-
checksum: 1,
|
|
105
|
-
channel: true,
|
|
106
|
-
function: fn.function,
|
|
107
|
-
publish: fn.publish ||
|
|
108
|
-
((based, payload, msg, id) => {
|
|
109
|
-
console.warn(' ↓ Publish to channel (no handler defined)', name, payload, msg, id);
|
|
110
|
-
}),
|
|
111
|
-
name,
|
|
112
|
-
maxPayloadSize: 500,
|
|
113
|
-
rateLimitTokens: 1,
|
|
114
|
-
...fn,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
else if (typeof fn === 'function') {
|
|
118
|
-
functionStore[name] = {
|
|
119
|
-
checksum: 1,
|
|
120
|
-
channel: true,
|
|
121
|
-
publish: (based, payload, msg, id) => {
|
|
122
|
-
console.warn(' ↓ Publish to channel (no handler defined)', name, payload, msg, id);
|
|
123
|
-
},
|
|
124
|
-
function: fn,
|
|
125
|
-
name,
|
|
126
|
-
maxPayloadSize: 500,
|
|
127
|
-
rateLimitTokens: 1,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
console.error(name, fn, 'Is not a channel function!');
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
const properProps = {
|
|
136
|
-
...props,
|
|
137
|
-
functions: {
|
|
138
|
-
closeAfterIdleTime: props.closeAfterIdleTime,
|
|
139
|
-
uninstallAfterIdleTime: props.uninstallAfterIdleTime || -1,
|
|
140
|
-
uninstall: props.uninstall ||
|
|
141
|
-
(async () => {
|
|
142
|
-
return true;
|
|
143
|
-
}),
|
|
144
|
-
install: props.install ||
|
|
145
|
-
(async ({ name }) => {
|
|
146
|
-
if (functionStore[name]) {
|
|
147
|
-
return functionStore[name];
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
return null;
|
|
151
|
-
}
|
|
152
|
-
}),
|
|
153
|
-
route: ({ server, path, name }) => {
|
|
154
|
-
// TODO: too slow will create a dedicated ROUTE thing later
|
|
155
|
-
let rootFn;
|
|
156
|
-
if (path) {
|
|
157
|
-
for (const name in functionStore) {
|
|
158
|
-
const fnPath = functionStore[name].path;
|
|
159
|
-
if (fnPath === path) {
|
|
160
|
-
return functionStore[name];
|
|
161
|
-
}
|
|
162
|
-
if (!rootFn && fnPath === '/') {
|
|
163
|
-
rootFn = functionStore[name];
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
// this will not work for now... will go into ROUTES
|
|
167
|
-
// addRoutes // addSpecs(, true) // makes them info routes as well
|
|
168
|
-
// easier to reaosn about
|
|
169
|
-
// for (const name in server.functions.specs) {
|
|
170
|
-
// const fnPath = server.functions.specs[name].path
|
|
171
|
-
// if (fnPath === path) {
|
|
172
|
-
// return server.functions.specs[name]
|
|
173
|
-
// }
|
|
174
|
-
// if (!rootFn && fnPath === '/') {
|
|
175
|
-
// rootFn = server.functions.specs[name]
|
|
176
|
-
// }
|
|
177
|
-
// }
|
|
178
|
-
}
|
|
179
|
-
return (functionStore[name] || server.functions.specs[name] || rootFn || null);
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
};
|
|
183
|
-
if (!props.silent) {
|
|
184
|
-
console.info(' ', picocolors_1.default.white('Based-server'), `starting with functions`);
|
|
185
|
-
}
|
|
186
|
-
let longestName = 0;
|
|
187
|
-
for (const name in functionStore) {
|
|
188
|
-
if (name.length > longestName) {
|
|
189
|
-
longestName = name.length;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
for (const name in functionStore) {
|
|
193
|
-
const obs = (0, functions_1.isChannelFunctionSpec)(functionStore[name])
|
|
194
|
-
? '[channel]'
|
|
195
|
-
: (0, functions_1.isQueryFunctionSpec)(functionStore[name])
|
|
196
|
-
? '[query]'
|
|
197
|
-
: (0, functions_1.isStreamFunctionSpec)(functionStore[name])
|
|
198
|
-
? '[stream]'
|
|
199
|
-
: '';
|
|
200
|
-
const pub = functionStore[name].public ? 'public' : 'private';
|
|
201
|
-
if (!props.silent) {
|
|
202
|
-
console.info(' ', picocolors_1.default.white(name), (0, utils_1.padLeft)('', longestName + 2 - name.length, ' '), picocolors_1.default.gray(pub), (0, utils_1.padLeft)('', 8 - pub.length, ' '), picocolors_1.default.green(obs), (0, utils_1.padLeft)('', 14 - obs.length, ' '), functionStore[name].path || '');
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
const basedServer = new server_1.BasedServer(properProps);
|
|
206
|
-
return props.port ? basedServer.start(props.port, sharedSocket) : basedServer;
|
|
207
|
-
}
|
|
208
|
-
exports.createSimpleServer = createSimpleServer;
|
|
209
|
-
//# sourceMappingURL=createSimpleServer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createSimpleServer.js","sourceRoot":"","sources":["../src/createSimpleServer.ts"],"names":[],"mappings":";;;;;;AAAA,2CAUoB;AAOpB,4DAAmC;AACnC,qCAAqD;AACrD,wCAAsC;AAoC/B,KAAK,UAAU,kBAAkB,CACtC,KAA0B,EAC1B,YAAsB;IAEtB,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAA;IAC9D,MAAM,aAAa,GAKf,EAAE,CAAA;IAEN,KAAK,MAAM,IAAI,IAA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AE,YAAY,CAAC,CAAC,CAAC,CAAC,WAAW,CAAA;AAC/E,CAAC;AA3OD,gDA2OC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { WebSocketSession } from '@based/functions';
|
|
2
|
-
import { BasedQueryFunctionRoute } from '../../functions';
|
|
3
|
-
import { IsAuthorizedHandler } from '../../authorize';
|
|
4
|
-
import { BinaryMessageHandler } from './types';
|
|
5
|
-
export declare const enableSubscribe: IsAuthorizedHandler<WebSocketSession, BasedQueryFunctionRoute>;
|
|
6
|
-
export declare const subscribeMessage: BinaryMessageHandler;
|
|
7
|
-
export declare const unsubscribeMessage: BinaryMessageHandler;
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unsubscribeMessage = exports.subscribeMessage = exports.enableSubscribe = void 0;
|
|
4
|
-
const protocol_1 = require("../../protocol");
|
|
5
|
-
const observable_1 = require("../../observable");
|
|
6
|
-
const error_1 = require("../../error");
|
|
7
|
-
const sendError_1 = require("../../sendError");
|
|
8
|
-
const security_1 = require("../../security");
|
|
9
|
-
const verifyRoute_1 = require("../../verifyRoute");
|
|
10
|
-
const authorize_1 = require("../../authorize");
|
|
11
|
-
const enableSubscribe = (route, psec, server, ctx, payload, id, checksum) => {
|
|
12
|
-
if ((0, observable_1.hasObs)(server, id)) {
|
|
13
|
-
(0, observable_1.subscribeWs)(server, id, checksum, ctx);
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
const session = ctx.session;
|
|
17
|
-
if (!session.obs.has(id)) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
if (!(0, observable_1.hasObs)(server, id)) {
|
|
21
|
-
(0, observable_1.createObs)(server, route.name, id, payload);
|
|
22
|
-
}
|
|
23
|
-
(0, observable_1.subscribeWs)(server, id, checksum, ctx);
|
|
24
|
-
};
|
|
25
|
-
exports.enableSubscribe = enableSubscribe;
|
|
26
|
-
const isNotAuthorized = (route, server, ctx, payload, id, checksum) => {
|
|
27
|
-
const session = ctx.session;
|
|
28
|
-
if (!session.unauthorizedObs) {
|
|
29
|
-
session.unauthorizedObs = new Set();
|
|
30
|
-
}
|
|
31
|
-
session.unauthorizedObs.add({
|
|
32
|
-
id,
|
|
33
|
-
checksum,
|
|
34
|
-
name: route.name,
|
|
35
|
-
payload,
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
const subscribeMessage = (arr, start, len, isDeflate, ctx, server) => {
|
|
39
|
-
// | 4 header | 8 id | 8 checksum | 1 name length | * name | * payload |
|
|
40
|
-
const nameLen = arr[start + 20];
|
|
41
|
-
const id = (0, protocol_1.readUint8)(arr, start + 4, 8);
|
|
42
|
-
const checksum = (0, protocol_1.readUint8)(arr, start + 12, 8);
|
|
43
|
-
const name = (0, protocol_1.decodeName)(arr, start + 21, start + 21 + nameLen);
|
|
44
|
-
if (!name || !id) {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
const route = (0, verifyRoute_1.verifyRoute)(server, ctx, 'query', server.functions.route(name), name, id);
|
|
48
|
-
// TODO: add strictness setting - if strict return false here
|
|
49
|
-
if (route === null) {
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
if ((0, security_1.rateLimitRequest)(server, ctx, route.rateLimitTokens, server.rateLimit.ws)) {
|
|
53
|
-
ctx.session.ws.close();
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
if (route.maxPayloadSize !== -1 && len > route.maxPayloadSize) {
|
|
57
|
-
(0, sendError_1.sendError)(server, ctx, error_1.BasedErrorCode.PayloadTooLarge, {
|
|
58
|
-
route,
|
|
59
|
-
observableId: id,
|
|
60
|
-
});
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
const session = ctx.session;
|
|
64
|
-
if (session.obs.has(id)) {
|
|
65
|
-
// Allready subscribed to this id
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
const payload = len === nameLen + 21
|
|
69
|
-
? undefined
|
|
70
|
-
: (0, protocol_1.parsePayload)((0, protocol_1.decodePayload)(new Uint8Array(arr.slice(start + 21 + nameLen, start + len)), isDeflate));
|
|
71
|
-
session.obs.add(id);
|
|
72
|
-
(0, authorize_1.authorize)(route, server, ctx, payload, exports.enableSubscribe, id, checksum, false, isNotAuthorized);
|
|
73
|
-
return true;
|
|
74
|
-
};
|
|
75
|
-
exports.subscribeMessage = subscribeMessage;
|
|
76
|
-
const unsubscribeMessage = (arr, start, len, isDeflate, ctx, server) => {
|
|
77
|
-
// | 4 header | 8 id |
|
|
78
|
-
if (!ctx.session) {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
const id = (0, protocol_1.readUint8)(arr, start + 4, 8);
|
|
82
|
-
if (!id) {
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
if ((0, observable_1.unsubscribeWs)(server, id, ctx)) {
|
|
86
|
-
ctx.session.ws.unsubscribe(String(id));
|
|
87
|
-
}
|
|
88
|
-
return true;
|
|
89
|
-
};
|
|
90
|
-
exports.unsubscribeMessage = unsubscribeMessage;
|
|
91
|
-
//# sourceMappingURL=observable.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"observable.js","sourceRoot":"","sources":["../../../src/incoming/ws/observable.ts"],"names":[],"mappings":";;;AAAA,6CAKuB;AACvB,iDAAgF;AAChF,uCAA4C;AAE5C,+CAA2C;AAC3C,6CAAiD;AACjD,mDAA+C;AAC/C,+CAIwB;AAGjB,MAAM,eAAe,GAGxB,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE;IACtD,IAAI,IAAA,mBAAM,EAAC,MAAM,EAAE,EAAE,CAAC,EAAE;QACtB,IAAA,wBAAW,EAAC,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAA;QACtC,OAAM;KACP;IAC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G,OAAO,EAAE,KAAK,GAAG,GAAG,CAAC,CAAC,EAC5D,SAAS,CACV,CACF,CAAA;IAEP,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IAEnB,IAAA,qBAAS,EACP,KAAK,EACL,MAAM,EACN,GAAG,EACH,OAAO,EACP,uBAAe,EACf,EAAE,EACF,QAAQ,EACR,KAAK,EACL,eAAe,CAChB,CAAA;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAhFY,QAAA,gBAAgB,oBAgF5B;AAEM,MAAM,kBAAkB,GAAyB,CACtD,GAAG,EACH,KAAK,EACL,GAAG,EACH,SAAS,EACT,GAAG,EACH,MAAM,EACN,EAAE;IACF,sBAAsB;IACtB,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE;QAChB,OAAO,KAAK,CAAA;KACb;IAED,MAAM,EAAE,GAAG,IAAA,oBAAS,EAAC,GAAG,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA;IAEvC,IAAI,CAAC,EAAE,EAAE;QACP,OAAO,KAAK,CAAA;KACb;IAED,IAAI,IAAA,0BAAa,EAAC,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;AAxBY,QAAA,kBAAkB,sBAwB9B"}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cleanUpObs = void 0;
|
|
4
|
-
// TODO: maybe share between obs and channel
|
|
5
|
-
const destroyObs = (server, obs) => {
|
|
6
|
-
const id = obs.id;
|
|
7
|
-
obs.timeTillDestroy = null;
|
|
8
|
-
if (!server.activeObservables[obs.name]) {
|
|
9
|
-
console.info('Trying to destroy a removed query function');
|
|
10
|
-
server.activeObservablesById.delete(id);
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
server.activeObservables[obs.name].delete(id);
|
|
14
|
-
if (server.activeObservables[obs.name].size === 0) {
|
|
15
|
-
delete server.activeObservables[obs.name];
|
|
16
|
-
}
|
|
17
|
-
server.activeObservablesById.delete(id);
|
|
18
|
-
obs.isDestroyed = true;
|
|
19
|
-
if (obs.closeFunction) {
|
|
20
|
-
obs.closeFunction();
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
const cleanUpObs = (server) => {
|
|
24
|
-
if (!server.obsCleanTimeout) {
|
|
25
|
-
const cycleTime = Math.max(server.obsCleanupCycle, 500);
|
|
26
|
-
server.obsCleanTimeout = setTimeout(() => {
|
|
27
|
-
// const d = Date.now()
|
|
28
|
-
// let cnt = 0
|
|
29
|
-
server.obsCleanTimeout = null;
|
|
30
|
-
let keepRunning = false;
|
|
31
|
-
let shortestCycleTime;
|
|
32
|
-
server.activeObservablesById.forEach((obs) => {
|
|
33
|
-
if (obs.timeTillDestroy !== null) {
|
|
34
|
-
obs.timeTillDestroy -= cycleTime;
|
|
35
|
-
if (obs.timeTillDestroy < 1) {
|
|
36
|
-
// cnt++
|
|
37
|
-
destroyObs(server, obs);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
if (shortestCycleTime === undefined ||
|
|
41
|
-
obs.timeTillDestroy < shortestCycleTime) {
|
|
42
|
-
shortestCycleTime = obs.timeTillDestroy;
|
|
43
|
-
}
|
|
44
|
-
keepRunning = true;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
if (keepRunning) {
|
|
49
|
-
server.obsCleanupCycle = shortestCycleTime;
|
|
50
|
-
(0, exports.cleanUpObs)(server);
|
|
51
|
-
}
|
|
52
|
-
// console.info(
|
|
53
|
-
// 'Cleanup time',
|
|
54
|
-
// cycleTime,
|
|
55
|
-
// 'new',
|
|
56
|
-
// server.obsCleanupCycle,
|
|
57
|
-
// Date.now() - d,
|
|
58
|
-
// 'ms',
|
|
59
|
-
// cnt,
|
|
60
|
-
// 'obs cleaned up'
|
|
61
|
-
// )
|
|
62
|
-
}, cycleTime);
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
exports.cleanUpObs = cleanUpObs;
|
|
66
|
-
//# sourceMappingURL=cleanup.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cleanup.js","sourceRoot":"","sources":["../../src/observable/cleanup.ts"],"names":[],"mappings":";;;AAGA,4CAA4C;AAC5C,MAAM,UAAU,GAAG,CAAC,MAAmB,EAAE,GAAqB,EAAE,EAAE;IAChE,MAAM,EAAE,GAAG,GAAG,CAAC,EAAE,CAAA;IACjB,GAAG,CAAC,eAAe,GAAG,IAAI,CAAA;IAC1B,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;QACvC,OAAO,CAAC,IAAI,CAAC,4CAA4C,CAAC,CAAA;QAC1D,MAAM,CAAC,qBAAqB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QACvC,OAAM;KACP;IACD,MAAM,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IAC7C,IAAI,MAAM,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,EAAE;QACjD,OAAO,MAAM,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;KAC1C;IACD,MAAM,CAAC,qBAAqB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IACvC,GAAG,CAAC,WAAW,GAAG,IAAI,CAAA;IACtB,IAAI,GAAG,CAAC,aAAa,EAAE;QACrB,GAAG,CAAC,aAAa,EAAE,CAAA;KACpB;AACH,CAAC,CAAA;AAEM,MAAM,UAAU,GAAG,CAAC,MAAmB,EAAE,EAAE;IAChD,IAAI,CAAC,MAAM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|
4
|
-
const start_1 = require("./start");
|
|
5
|
-
const get_1 = require("./get");
|
|
6
|
-
const createObs = (server, name, id, payload, noStart) => {
|
|
7
|
-
if ((0, get_1.hasObs)(server, id)) {
|
|
8
|
-
const msg = `Allready has observable ${name} ${id}`;
|
|
9
|
-
console.error(msg);
|
|
10
|
-
throw new Error(msg);
|
|
11
|
-
}
|
|
12
|
-
const obs = {
|
|
13
|
-
payload,
|
|
14
|
-
reusedCache: false,
|
|
15
|
-
clients: new Set(),
|
|
16
|
-
functionObserveClients: new Set(),
|
|
17
|
-
id,
|
|
18
|
-
name,
|
|
19
|
-
isDestroyed: false,
|
|
20
|
-
startId: 0,
|
|
21
|
-
timeTillDestroy: null,
|
|
22
|
-
};
|
|
23
|
-
if (!server.activeObservables[name]) {
|
|
24
|
-
server.activeObservables[name] = new Map();
|
|
25
|
-
}
|
|
26
|
-
server.activeObservables[name].set(id, obs);
|
|
27
|
-
server.activeObservablesById.set(id, obs);
|
|
28
|
-
if (noStart) {
|
|
29
|
-
return obs;
|
|
30
|
-
}
|
|
31
|
-
(0, start_1.start)(server, id);
|
|
32
|
-
return obs;
|
|
33
|
-
};
|
|
34
|
-
exports.createObs = createObs;
|
|
35
|
-
//# sourceMappingURL=create.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/observable/create.ts"],"names":[],"mappings":";;;AAEA,mCAA+B;AAC/B,+BAA8B;AAEvB,MAAM,SAAS,GAAG,CACvB,MAAmB,EACnB,IAAY,EACZ,EAAU,EACV,OAAY,EACZ,OAAiB,EACC,EAAE;IACpB,IAAI,IAAA,YAAM,EAAC,MAAM,EAAE,EAAE,CAAC,EAAE;QACtB,MAAM,GAAG,GAAG,2BAA2B,IAAI,IAAI,EAAE,EAAE,CAAA;QACnD,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAClB,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAA;KACrB;IAED,MAAM,GAAG,GAAqB;QAC5B,OAAO;QACP,WAAW,EAAE,KAAK;QAClB,OAAO,EAAE,IAAI,GAAG,EAAE;QAClB,sBAAsB,EAAE,IAAI,GAAG,EAAE;QACjC,EAAE;QACF,IAAI;QACJ,WAAW,EAAE,KAAK;QAClB,OAAO,EAAE,CAAC;QACV,eAAe,EAAE,IAAI;KACtB,CAAA;IAED,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE;QACnC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,EAAE,CAAA;KAC3C;IAED,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAA;IAC3C,MAAM,CAAC,qBAAqB,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAA;IAEzC,IAAI,OAAO,EAAE;QACX,OAAO,GAAG,CAAA;KACX;IAED,IAAA,aAAK,EAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IACjB,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAtCY,QAAA,SAAS,aAsCrB"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.destroyObs = exports.updateDestroyTimer = void 0;
|
|
4
|
-
const cleanup_1 = require("./cleanup");
|
|
5
|
-
const functions_1 = require("@based/functions");
|
|
6
|
-
const updateDestroyTimer = (server, channel) => {
|
|
7
|
-
const spec = server.functions.specs[channel.name];
|
|
8
|
-
if (!spec || !(0, functions_1.isBasedFunctionConfig)('query', spec)) {
|
|
9
|
-
console.warn('destroyObs - Cannot find obs function spec -', channel.name);
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
const closeAfterIdleTime = spec.closeAfterIdleTime ?? server.functions.config.closeAfterIdleTime.query;
|
|
13
|
-
channel.timeTillDestroy = closeAfterIdleTime;
|
|
14
|
-
channel.closeAfterIdleTime = closeAfterIdleTime;
|
|
15
|
-
const closeTime = Math.round(closeAfterIdleTime / 2);
|
|
16
|
-
if (closeTime < server.obsCleanupCycle) {
|
|
17
|
-
server.obsCleanupCycle = closeTime;
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
exports.updateDestroyTimer = updateDestroyTimer;
|
|
21
|
-
// dont use timer just use counter to remove it over time
|
|
22
|
-
const destroyObs = (server, id) => {
|
|
23
|
-
const obs = server.activeObservablesById.get(id);
|
|
24
|
-
if (!obs) {
|
|
25
|
-
console.error('destroyObs', id, 'does not exist!');
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
if (obs.isDestroyed) {
|
|
29
|
-
console.error('obs allready destroyed', obs.name);
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
if (obs.clients.size ||
|
|
33
|
-
obs.functionObserveClients.size ||
|
|
34
|
-
obs.onNextData?.size) {
|
|
35
|
-
if (obs.timeTillDestroy) {
|
|
36
|
-
obs.timeTillDestroy = null;
|
|
37
|
-
console.warn(`Obs being destroyed while listeners are present ${obs.name} ${obs.id}`, obs.payload);
|
|
38
|
-
}
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
if (obs.timeTillDestroy === null) {
|
|
42
|
-
(0, exports.updateDestroyTimer)(server, obs);
|
|
43
|
-
(0, cleanup_1.cleanUpObs)(server);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
exports.destroyObs = destroyObs;
|
|
47
|
-
//# sourceMappingURL=destroy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"destroy.js","sourceRoot":"","sources":["../../src/observable/destroy.ts"],"names":[],"mappings":";;;AACA,uCAAsC;AAEtC,gDAAwD;AAEjD,MAAM,kBAAkB,GAAG,CAChC,MAAmB,EACnB,OAAyB,EACzB,EAAE;IACF,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,OAA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IAAI,CAAA;YAC1B,OAAO,CAAC,IAAI,CACV,mDAAmD,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,EAAE,EAAE,EACvE,GAAG,CAAC,OAAO,CACZ,CAAA;SACF;QACD,OAAM;KACP;IAED,IAAI,GAAG,CAAC,eAAe,KAAK,IAAI,EAAE;QAChC,IAAA,0BAAkB,EAAC,MAAM,EAAE,GAAG,CAAC,CAAA;QAC/B,IAAA,oBAAU,EAAC,MAAM,CAAC,CAAA;KACnB;AACH,CAAC,CAAA;AAhCY,QAAA,UAAU,cAgCtB"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extendCache = void 0;
|
|
4
|
-
const extendCache = (obs) => {
|
|
5
|
-
if (obs.timeTillDestroy) {
|
|
6
|
-
obs.timeTillDestroy = null;
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
exports.extendCache = extendCache;
|
|
10
|
-
//# sourceMappingURL=extendCache.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extendCache.js","sourceRoot":"","sources":["../../src/observable/extendCache.ts"],"names":[],"mappings":";;;AAEO,MAAM,WAAW,GAAG,CAAC,GAAqB,EAAE,EAAE;IACnD,IAAI,GAAG,CAAC,eAAe,EAAE;QACvB,GAAG,CAAC,eAAe,GAAG,IAAI,CAAA;KAC3B;AACH,CAAC,CAAA;AAJY,QAAA,WAAW,eAIvB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const genObservableId: (name: string, payload: any) => number;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.genObservableId = void 0;
|
|
4
|
-
const hash_1 = require("@saulx/hash");
|
|
5
|
-
const genObservableId = (name, payload) => {
|
|
6
|
-
if (payload === undefined) {
|
|
7
|
-
return (0, hash_1.hash)(name);
|
|
8
|
-
}
|
|
9
|
-
return (0, hash_1.hashObjectIgnoreKeyOrder)([name, payload]);
|
|
10
|
-
};
|
|
11
|
-
exports.genObservableId = genObservableId;
|
|
12
|
-
//# sourceMappingURL=genObservableId.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"genObservableId.js","sourceRoot":"","sources":["../../src/observable/genObservableId.ts"],"names":[],"mappings":";;;AAAA,sCAA4D;AAErD,MAAM,eAAe,GAAG,CAAC,IAAY,EAAE,OAAY,EAAU,EAAE;IACpE,IAAI,OAAO,KAAK,SAAS,EAAE;QACzB,OAAO,IAAA,WAAI,EAAC,IAAI,CAAC,CAAA;KAClB;IACD,OAAO,IAAA,+BAAwB,EAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAA;AAClD,CAAC,CAAA;AALY,QAAA,eAAe,mBAK3B"}
|
package/dist/observable/get.d.ts
DELETED
package/dist/observable/get.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hasObs = exports.getObsAndStopRemove = void 0;
|
|
4
|
-
const extendCache_1 = require("./extendCache");
|
|
5
|
-
const getObsAndStopRemove = (server, id) => {
|
|
6
|
-
const obs = server.activeObservablesById.get(id);
|
|
7
|
-
(0, extendCache_1.extendCache)(obs);
|
|
8
|
-
return obs;
|
|
9
|
-
};
|
|
10
|
-
exports.getObsAndStopRemove = getObsAndStopRemove;
|
|
11
|
-
const hasObs = (server, id) => {
|
|
12
|
-
return server.activeObservablesById.has(id);
|
|
13
|
-
};
|
|
14
|
-
exports.hasObs = hasObs;
|
|
15
|
-
//# sourceMappingURL=get.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../src/observable/get.ts"],"names":[],"mappings":";;;AAEA,+CAA2C;AAEpC,MAAM,mBAAmB,GAAG,CACjC,MAAmB,EACnB,EAAU,EACQ,EAAE;IACpB,MAAM,GAAG,GAAG,MAAM,CAAC,qBAAqB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IAChD,IAAA,yBAAW,EAAC,GAAG,CAAC,CAAA;IAChB,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAPY,QAAA,mBAAmB,uBAO/B;AAEM,MAAM,MAAM,GAAG,CAAC,MAAmB,EAAE,EAAU,EAAW,EAAE;IACjE,OAAO,MAAM,CAAC,qBAAqB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;AAC7C,CAAC,CAAA;AAFY,QAAA,MAAM,UAElB"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from './subscribe';
|
|
2
|
-
export * from './unsub';
|
|
3
|
-
export * from './destroy';
|
|
4
|
-
export * from './create';
|
|
5
|
-
export * from './extendCache';
|
|
6
|
-
export * from './start';
|
|
7
|
-
export * from './send';
|
|
8
|
-
export * from './get';
|
|
9
|
-
export * from './types';
|
|
10
|
-
export * from './genObservableId';
|
package/dist/observable/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./subscribe"), exports);
|
|
18
|
-
__exportStar(require("./unsub"), exports);
|
|
19
|
-
__exportStar(require("./destroy"), exports);
|
|
20
|
-
__exportStar(require("./create"), exports);
|
|
21
|
-
__exportStar(require("./extendCache"), exports);
|
|
22
|
-
__exportStar(require("./start"), exports);
|
|
23
|
-
__exportStar(require("./send"), exports);
|
|
24
|
-
__exportStar(require("./get"), exports);
|
|
25
|
-
__exportStar(require("./types"), exports);
|
|
26
|
-
__exportStar(require("./genObservableId"), exports);
|
|
27
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/observable/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA2B;AAC3B,0CAAuB;AACvB,4CAAyB;AACzB,2CAAwB;AACxB,gDAA6B;AAC7B,0CAAuB;AACvB,yCAAsB;AACtB,wCAAqB;AACrB,0CAAuB;AACvB,oDAAiC"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Context, WebSocketSession, HttpSession } from '@based/functions';
|
|
2
|
-
import { BasedServer } from '../server';
|
|
3
|
-
import { ActiveObservable, ObservableError } from './types';
|
|
4
|
-
export declare const sendObsWs: (ctx: Context<WebSocketSession>, buffer: Uint8Array, obs: ActiveObservable) => void;
|
|
5
|
-
export declare const sendObsGetError: (server: BasedServer, ctx: Context<WebSocketSession | HttpSession>, id: number, err: ObservableError) => void;
|
package/dist/observable/send.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sendObsGetError = exports.sendObsWs = void 0;
|
|
4
|
-
const protocol_1 = require("../protocol");
|
|
5
|
-
const destroy_1 = require("./destroy");
|
|
6
|
-
const sendError_1 = require("../sendError");
|
|
7
|
-
const sendObsWs = (ctx, buffer, obs) => {
|
|
8
|
-
if (!ctx.session) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
if (obs.reusedCache) {
|
|
12
|
-
const prevId = (0, protocol_1.updateId)(buffer, obs.id);
|
|
13
|
-
ctx.session.ws.send(buffer, true, false);
|
|
14
|
-
buffer.set(prevId, 4);
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
ctx.session.ws.send(buffer, true, false);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
exports.sendObsWs = sendObsWs;
|
|
21
|
-
const sendObsGetError = (server, ctx, id, err) => {
|
|
22
|
-
(0, sendError_1.sendErrorData)(ctx, err);
|
|
23
|
-
(0, destroy_1.destroyObs)(server, id);
|
|
24
|
-
};
|
|
25
|
-
exports.sendObsGetError = sendObsGetError;
|
|
26
|
-
//# sourceMappingURL=send.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"send.js","sourceRoot":"","sources":["../../src/observable/send.ts"],"names":[],"mappings":";;;AACA,0CAAsC;AAEtC,uCAAsC;AACtC,4CAA4C;AAGrC,MAAM,SAAS,GAAG,CACvB,GAA8B,EAC9B,MAAkB,EAClB,GAAqB,EACrB,EAAE;IACF,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE;QAChB,OAAM;KACP;IACD,IAAI,GAAG,CAAC,WAAW,EAAE;QACnB,MAAM,MAAM,GAAG,IAAA,mBAAQ,EAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,CAAA;QACvC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;QACxC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;KACtB;SAAM;QACL,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;KACzC;AACH,CAAC,CAAA;AAfY,QAAA,SAAS,aAerB;AAEM,MAAM,eAAe,GAAG,CAC7B,MAAmB,EACnB,GAA4C,EAC5C,EAAU,EACV,GAAoB,EACpB,EAAE;IACF,IAAA,yBAAa,EAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IACvB,IAAA,oBAAU,EAAC,MAAM,EAAE,EAAE,CAAC,CAAA;AACxB,CAAC,CAAA;AARY,QAAA,eAAe,mBAQ3B"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.errorListener = void 0;
|
|
4
|
-
const error_1 = require("../../error");
|
|
5
|
-
const protocol_1 = require("../../protocol");
|
|
6
|
-
const errorListener = (server, obs, err) => {
|
|
7
|
-
delete obs.cache;
|
|
8
|
-
delete obs.diffCache;
|
|
9
|
-
delete obs.checksum;
|
|
10
|
-
delete obs.previousChecksum;
|
|
11
|
-
obs.isDeflate = false;
|
|
12
|
-
obs.reusedCache = false;
|
|
13
|
-
obs.error =
|
|
14
|
-
err instanceof Error
|
|
15
|
-
? (0, error_1.createError)(server, {
|
|
16
|
-
session: { type: 'query', id: obs.id, name: obs.name, headers: {} },
|
|
17
|
-
}, error_1.BasedErrorCode.FunctionError, {
|
|
18
|
-
err,
|
|
19
|
-
observableId: obs.id,
|
|
20
|
-
route: {
|
|
21
|
-
name: obs.name,
|
|
22
|
-
type: 'query',
|
|
23
|
-
},
|
|
24
|
-
})
|
|
25
|
-
: err.observableId !== obs.id
|
|
26
|
-
? { ...err, observableId: obs.id }
|
|
27
|
-
: err;
|
|
28
|
-
if (obs.clients.size) {
|
|
29
|
-
server.uwsApp.publish(String(obs.id), (0, protocol_1.encodeErrorResponse)((0, protocol_1.valueToBuffer)(obs.error)), true, false);
|
|
30
|
-
}
|
|
31
|
-
// TODO: Change this make it one error handler
|
|
32
|
-
if (obs.functionObserveClients.size) {
|
|
33
|
-
obs.functionObserveClients.forEach((fnUpdate) => {
|
|
34
|
-
fnUpdate(obs.rawData, obs.checksum, obs.error, obs.cache, obs.diffCache, obs.previousChecksum, obs.isDeflate);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
if (obs.onNextData) {
|
|
38
|
-
const onNextData = obs.onNextData;
|
|
39
|
-
delete obs.onNextData;
|
|
40
|
-
onNextData.forEach((fn) => fn(obs.error));
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
exports.errorListener = errorListener;
|
|
44
|
-
//# sourceMappingURL=error.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/observable/start/error.ts"],"names":[],"mappings":";;;AAEA,uCAAyD;AACzD,6CAAmE;AAE5D,MAAM,aAAa,GAAG,CAC3B,MAAmB,EACnB,GAAqB,EACrB,GAA4B,EAC5B,EAAE;IACF,OAAO,GAAG,CAAC,KAAK,CAAA;IAChB,OAAO,GAAG,CAAC,SAAS,CAAA;IACpB,OAAO,GAAG,CAAC,QAAQ,CAAA;IACnB,OAAO,GAAG,CAAC,gBAAgB,CAAA;IAE3B,GAAG,CAAC,SAAS,GAAG,KAAK,CAAA;IACrB,GAAG,CAAC,WAAW,GAAG,KAAK,CAAA;IAEvB,GAAG,CAAC,KAAK;QACP,GAAG,YAAY,KAAK;YAClB,CAAC,CAAC,IAAA,mBAAW,EACT,MAAM,EACN;gBACE,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE;aACpE,EACD,sBAAc,CAAC,aAAa,EAC5B;gBACE,GAAG;gBACH,YAAY,EAAE,GAAG,CAAC,EAAE;gBACpB,KAAK,EAAE;oBACL,IAAI,EAAE,GAAG,CAAC,IAAI;oBACd,IAAI,EAAE,OAAO;iBACd;aACF,CACF;YACH,CAAC,CAAC,GAAG,CAAC,YAAY,KAAK,GAAG,CAAC,EAAE;gBAC7B,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,YAAY,EAAE,GAAG,CAAC,EAAE,EAAE;gBAClC,CAAC,CAAC,GAAG,CAAA;IAET,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE;QACpB,MAAM,CAAC,MAAM,CAAC,OAAO,CACnB,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,EACd,IAAA,8BAAmB,EAAC,IAAA,wBAAa,EAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAC7C,IAAI,EACJ,KAAK,CACN,CAAA;KACF;IAED,8CAA8C;IAC9C,IAAI,GAAG,CAAC,sBAAsB,CAAC,IAAI,EAAE;QACnC,GAAG,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC9C,QAAQ,CACN,GAAG,CAAC,OAAO,EACX,GAAG,CAAC,QAAQ,EACZ,GAAG,CAAC,KAAK,EACT,GAAG,CAAC,KAAK,EACT,GAAG,CAAC,SAAS,EACb,GAAG,CAAC,gBAAgB,EACpB,GAAG,CAAC,SAAS,CACd,CAAA;QACH,CAAC,CAAC,CAAA;KACH;IAED,IAAI,GAAG,CAAC,UAAU,EAAE;QAClB,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,CAAA;QACjC,OAAO,GAAG,CAAC,UAAU,CAAA;QACrB,UAAU,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA;KAC1C;AACH,CAAC,CAAA;AA/DY,QAAA,aAAa,iBA+DzB"}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.start = void 0;
|
|
4
|
-
const update_1 = require("./update");
|
|
5
|
-
const error_1 = require("./error");
|
|
6
|
-
const relay_1 = require("./relay");
|
|
7
|
-
const functions_1 = require("@based/functions");
|
|
8
|
-
const start = (server, id) => {
|
|
9
|
-
const obs = server.activeObservablesById.get(id);
|
|
10
|
-
if (obs.closeFunction) {
|
|
11
|
-
obs.closeFunction();
|
|
12
|
-
delete obs.closeFunction;
|
|
13
|
-
}
|
|
14
|
-
const spec = server.functions.specs[obs.name];
|
|
15
|
-
if (!spec || !(0, functions_1.isBasedFunctionConfig)('query', spec)) {
|
|
16
|
-
console.warn('Cannot find observable function spec!', obs.name);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const payload = obs.payload;
|
|
20
|
-
const update = (data, checksum, err, cache, diff, fromChecksum, isDeflate) => {
|
|
21
|
-
if (err) {
|
|
22
|
-
(0, error_1.errorListener)(server, obs, err);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
(0, update_1.updateListener)(server, obs, data, checksum, cache, diff, fromChecksum, isDeflate);
|
|
26
|
-
};
|
|
27
|
-
const startId = ++obs.startId;
|
|
28
|
-
if (spec.relay) {
|
|
29
|
-
const client = server.clients[spec.relay.client];
|
|
30
|
-
if (!client) {
|
|
31
|
-
(0, error_1.errorListener)(server, obs, new Error(`Relay client ${spec.relay} does not exist`));
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
(0, relay_1.relay)(server, obs, client, update);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
try {
|
|
38
|
-
const r = spec.fn(server.client, payload, update, (err) => {
|
|
39
|
-
(0, error_1.errorListener)(server, obs, err);
|
|
40
|
-
});
|
|
41
|
-
if (r instanceof Promise) {
|
|
42
|
-
r.then((close) => {
|
|
43
|
-
if (obs.isDestroyed || startId !== obs.startId) {
|
|
44
|
-
close();
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
obs.closeFunction = close;
|
|
48
|
-
}
|
|
49
|
-
}).catch((err) => {
|
|
50
|
-
if (!(obs.isDestroyed || startId !== obs.startId)) {
|
|
51
|
-
(0, error_1.errorListener)(server, obs, err);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
obs.closeFunction = r;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
catch (err) {
|
|
60
|
-
if (!(obs.isDestroyed || startId !== obs.startId)) {
|
|
61
|
-
(0, error_1.errorListener)(server, obs, err);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
exports.start = start;
|
|
67
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/observable/start/index.ts"],"names":[],"mappings":";;;AACA,qCAAyC;AACzC,mCAAuC;AAEvC,mCAA+B;AAC/B,gDAAwD;AAEjD,MAAM,KAAK,GAAG,CAAC,MAAmB,EAAE,EAAU,EAAE,EAAE;IACvD,MAAM,GAAG,GAAG,MAAM,CAAC,qBAAqB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IAEhD,IAAI,GAAG,CAAC,aAAa,EAAE;QACrB,GAAG,CAAC,aAAa,EAAE,CAAA;QACnB,OAAO,GAAG,CAAC,aAAa,CAAA;KACzB;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAE7C,IAAI,CAAC,IAAI,IAAI,CAAC,IAAA,iCAAqB,EAAC,OAAO,EAAE,IAAI,CAAC,EAAE;QAClD,OAAO,CAAC,IAAI,CAAC,uCAAuC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAA;QAC/D,OAAM;KACP;IAED,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAA;IAE3B,MAAM,MAAM,GAA6B,CACvC,IAAI,EACJ,QAAQ,EACR,GAAG,EACH,KAAK,EACL,IAAI,EACJ,YAAY,EACZ,SAAS,EACT,EAAE;QACF,IAAI,GAAG,EAAE;YACP,IAAA,qBAAa,EAAC,MAAM,EAAE,GAAG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AAE;wBACjD,IAAA,qBAAa,EAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;qBAChC;gBACH,CAAC,CAAC,CAAA;aACH;iBAAM;gBACL,GAAG,CAAC,aAAa,GAAG,CAAC,CAAA;aACtB;SACF;QAAC,OAAO,GAAG,EAAE;YACZ,IAAI,CAAC,CAAC,GAAG,CAAC,WAAW,IAAI,OAAO,KAAK,GAAG,CAAC,OAAO,CAAC,EAAE;gBACjD,IAAA,qBAAa,EAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;aAChC;SACF;KACF;AACH,CAAC,CAAA;AAjFY,QAAA,KAAK,SAiFjB"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { ObservableUpdateFunction } from '@based/functions';
|
|
2
|
-
import { BasedServer } from '../../server';
|
|
3
|
-
import { ActiveObservable } from '../types';
|
|
4
|
-
export declare const relay: (server: BasedServer, obs: ActiveObservable, client: any, update: ObservableUpdateFunction) => void;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.relay = void 0;
|
|
4
|
-
const error_1 = require("./error");
|
|
5
|
-
// this has to be super optmized!
|
|
6
|
-
const relay = (server, obs, client, update) => {
|
|
7
|
-
obs.closeFunction = client
|
|
8
|
-
.query(obs.name, obs.payload)
|
|
9
|
-
.subscribe(update, (err) => {
|
|
10
|
-
(0, error_1.errorListener)(server, obs, err);
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
exports.relay = relay;
|
|
14
|
-
//# sourceMappingURL=relay.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"relay.js","sourceRoot":"","sources":["../../../src/observable/start/relay.ts"],"names":[],"mappings":";;;AAGA,mCAAuC;AAEvC,iCAAiC;AAC1B,MAAM,KAAK,GAAG,CACnB,MAAmB,EACnB,GAAqB,EACrB,MAAW,EACX,MAAgC,EAChC,EAAE;IACF,GAAG,CAAC,aAAa,GAAG,MAAM;SACvB,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC;SAC5B,SAAS,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE;QACzB,IAAA,qBAAa,EAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;IACjC,CAAC,CAAC,CAAA;AACN,CAAC,CAAA;AAXY,QAAA,KAAK,SAWjB"}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { ActiveObservable } from '../types';
|
|
2
|
-
import { BasedServer } from '../../server';
|
|
3
|
-
export declare const updateListener: (server: BasedServer, obs: ActiveObservable, data: any, checksum?: number, reusedData?: Uint8Array, diff?: any, previousChecksum?: number, isDeflate?: boolean) => void;
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateListener = void 0;
|
|
4
|
-
const protocol_1 = require("../../protocol");
|
|
5
|
-
const utils_1 = require("@saulx/utils");
|
|
6
|
-
const hash_1 = require("@saulx/hash");
|
|
7
|
-
const diff_1 = require("@saulx/diff");
|
|
8
|
-
const updateListener = (server, obs, data, checksum, reusedData, diff, previousChecksum, isDeflate) => {
|
|
9
|
-
if (checksum === undefined) {
|
|
10
|
-
if (data === undefined) {
|
|
11
|
-
checksum = 0;
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
if (typeof data === 'object' && data !== null) {
|
|
15
|
-
checksum = (0, hash_1.hashObjectIgnoreKeyOrder)(data);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
checksum = (0, hash_1.hash)(data);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
if (checksum !== obs.checksum) {
|
|
23
|
-
let encodedData;
|
|
24
|
-
if (reusedData) {
|
|
25
|
-
// if reusedData we assume forwarding of all data
|
|
26
|
-
obs.reusedCache = true;
|
|
27
|
-
encodedData = reusedData;
|
|
28
|
-
if (diff) {
|
|
29
|
-
obs.diffCache = diff;
|
|
30
|
-
obs.previousChecksum = previousChecksum;
|
|
31
|
-
}
|
|
32
|
-
if (data) {
|
|
33
|
-
obs.rawData = data;
|
|
34
|
-
}
|
|
35
|
-
if (!isDeflate) {
|
|
36
|
-
isDeflate = false;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
obs.reusedCache = false;
|
|
41
|
-
const buff = (0, protocol_1.valueToBuffer)(data);
|
|
42
|
-
if (diff) {
|
|
43
|
-
if (typeof data === 'object' && data !== null) {
|
|
44
|
-
obs.rawData = data;
|
|
45
|
-
if (!obs.checksum || diff === true) {
|
|
46
|
-
diff = null;
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
obs.previousChecksum = obs.checksum;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
delete obs.rawData;
|
|
54
|
-
diff = null;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
else if (previousChecksum === undefined) {
|
|
58
|
-
if (typeof data === 'object' && data !== null) {
|
|
59
|
-
if (obs.rawData) {
|
|
60
|
-
diff = (0, diff_1.createPatch)(obs.rawData, data);
|
|
61
|
-
obs.previousChecksum = obs.checksum;
|
|
62
|
-
}
|
|
63
|
-
obs.rawData = (0, utils_1.deepCopy)(data);
|
|
64
|
-
}
|
|
65
|
-
else if (obs.rawData) {
|
|
66
|
-
delete obs.rawData;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
// TODO: Keep track globally of total mem usage
|
|
70
|
-
;
|
|
71
|
-
[encodedData, isDeflate] = (0, protocol_1.encodeObservableResponse)(obs.id, checksum, buff);
|
|
72
|
-
if (diff) {
|
|
73
|
-
const diffBuff = (0, protocol_1.valueToBuffer)(diff);
|
|
74
|
-
const encodedDiffData = (0, protocol_1.encodeObservableDiffResponse)(obs.id, checksum, obs.previousChecksum, diffBuff);
|
|
75
|
-
obs.diffCache = encodedDiffData;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
obs.isDeflate = isDeflate;
|
|
79
|
-
obs.cache = encodedData;
|
|
80
|
-
obs.checksum = checksum;
|
|
81
|
-
let prevId;
|
|
82
|
-
let prevDiffId;
|
|
83
|
-
if (obs.clients.size) {
|
|
84
|
-
if (obs.diffCache) {
|
|
85
|
-
if (obs.reusedCache) {
|
|
86
|
-
prevDiffId = (0, protocol_1.updateId)(obs.diffCache, obs.id);
|
|
87
|
-
}
|
|
88
|
-
server.uwsApp.publish(String(obs.id), obs.diffCache, true, false);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
if (obs.reusedCache) {
|
|
92
|
-
prevId = (0, protocol_1.updateId)(encodedData, obs.id);
|
|
93
|
-
}
|
|
94
|
-
server.uwsApp.publish(String(obs.id), encodedData, true, false);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (obs.functionObserveClients.size) {
|
|
98
|
-
obs.functionObserveClients.forEach((fnUpdate) => {
|
|
99
|
-
fnUpdate(obs.rawData, obs.checksum, obs.error, obs.cache, obs.diffCache, obs.previousChecksum, obs.isDeflate);
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
if (obs.onNextData) {
|
|
103
|
-
const onNextData = obs.onNextData;
|
|
104
|
-
delete obs.onNextData;
|
|
105
|
-
onNextData.forEach((fn) => fn());
|
|
106
|
-
}
|
|
107
|
-
if (prevDiffId) {
|
|
108
|
-
obs.diffCache.set(prevDiffId, 4);
|
|
109
|
-
}
|
|
110
|
-
if (prevId) {
|
|
111
|
-
encodedData.set(prevId, 4);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
exports.updateListener = updateListener;
|
|
116
|
-
//# sourceMappingURL=update.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../../src/observable/start/update.ts"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E,CAAC,EAAE,EAAE,CAAC,CAAA;SACjC;QAED,IAAI,UAAU,EAAE;YACd,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC,CAAA;SACjC;QAED,IAAI,MAAM,EAAE;YACV,WAAW,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;SAC3B;KACF;AACH,CAAC,CAAA;AAtIY,QAAA,cAAc,kBAsI1B"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { BasedServer } from '../server';
|
|
2
|
-
import { ActiveObservable, ObservableUpdateFunction } from './types';
|
|
3
|
-
import { BasedErrorCode, BasedErrorData } from '../error';
|
|
4
|
-
import { WebSocketSession, Context } from '@based/functions';
|
|
5
|
-
export declare const subscribeWs: (server: BasedServer, id: number, checksum: number, ctx: Context<WebSocketSession>) => void;
|
|
6
|
-
export declare const subscribeFunction: (server: BasedServer, id: number, update: ObservableUpdateFunction) => void;
|
|
7
|
-
export declare const subscribeNext: (obs: ActiveObservable, onNext: (err?: BasedErrorData<BasedErrorCode.FunctionError>) => void) => void;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.subscribeNext = exports.subscribeFunction = exports.subscribeWs = void 0;
|
|
4
|
-
const extendCache_1 = require("./extendCache");
|
|
5
|
-
const send_1 = require("./send");
|
|
6
|
-
const get_1 = require("./get");
|
|
7
|
-
const sendError_1 = require("../sendError");
|
|
8
|
-
const subscribeWs = (server, id, checksum, ctx) => {
|
|
9
|
-
const session = ctx.session;
|
|
10
|
-
if (!session) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
ctx.session.ws.subscribe(String(id));
|
|
14
|
-
const obs = (0, get_1.getObsAndStopRemove)(server, id);
|
|
15
|
-
session.obs.add(id);
|
|
16
|
-
obs.clients.add(session.id);
|
|
17
|
-
if (obs.error) {
|
|
18
|
-
(0, sendError_1.sendErrorData)(ctx, obs.error);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
if (obs.cache && obs.checksum !== checksum) {
|
|
22
|
-
if (obs.diffCache && obs.previousChecksum === checksum) {
|
|
23
|
-
(0, send_1.sendObsWs)(ctx, obs.diffCache, obs);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
(0, send_1.sendObsWs)(ctx, obs.cache, obs);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
exports.subscribeWs = subscribeWs;
|
|
31
|
-
const subscribeFunction = (server, id, update) => {
|
|
32
|
-
const obs = (0, get_1.getObsAndStopRemove)(server, id);
|
|
33
|
-
if (obs.functionObserveClients.add(update))
|
|
34
|
-
if (obs.cache) {
|
|
35
|
-
update(obs.rawData, obs.checksum, null, obs.cache, obs.diffCache, obs.previousChecksum, obs.isDeflate);
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
exports.subscribeFunction = subscribeFunction;
|
|
39
|
-
const subscribeNext = (obs, onNext) => {
|
|
40
|
-
(0, extendCache_1.extendCache)(obs);
|
|
41
|
-
if (!obs.onNextData) {
|
|
42
|
-
obs.onNextData = new Set();
|
|
43
|
-
}
|
|
44
|
-
obs.onNextData.add(onNext);
|
|
45
|
-
};
|
|
46
|
-
exports.subscribeNext = subscribeNext;
|
|
47
|
-
//# sourceMappingURL=subscribe.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"subscribe.js","sourceRoot":"","sources":["../../src/observable/subscribe.ts"],"names":[],"mappings":";;;AAEA,+CAA2C;AAE3C,iCAAkC;AAClC,+BAA2C;AAC3C,4CAA4C;AAGrC,MAAM,WAAW,GAAG,CACzB,MAAmB,EACnB,EAAU,EACV,QAAgB,EAChB,GAA8B,EAC9B,EAAE;IACF,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAA;IAE3B,IAAI,CAAC,OAAO,EAAE;QACZ,OAAM;KACP;IAED,G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,CAAA;AAlBY,QAAA,iBAAiB,qBAkB7B;AAEM,MAAM,aAAa,GAAG,CAC3B,GAAqB,EACrB,MAAoE,EACpE,EAAE;IACF,IAAA,yBAAW,EAAC,GAAG,CAAC,CAAA;IAChB,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE;QACnB,GAAG,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE,CAAA;KAC3B;IACD,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AAC5B,CAAC,CAAA;AATY,QAAA,aAAa,iBASzB"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { BasedErrorCode, BasedErrorData } from '../error';
|
|
2
|
-
export type ObservableError = BasedErrorData<BasedErrorCode.FunctionError> | BasedErrorData<BasedErrorCode.FunctionIsWrongType> | BasedErrorData<BasedErrorCode.FunctionNotFound>;
|
|
3
|
-
export type ObservableUpdateFunction = (data: any, checksum?: number, err?: null | ObservableError, cache?: Uint8Array, diff?: any, fromChecksum?: number, isDeflate?: boolean) => void;
|
|
4
|
-
export type ObserveErrorListener = (err: ObservableError) => void;
|
|
5
|
-
export type ActiveObservable = {
|
|
6
|
-
startId: number;
|
|
7
|
-
name: string;
|
|
8
|
-
id: number;
|
|
9
|
-
reusedCache: boolean;
|
|
10
|
-
functionObserveClients: Set<ObservableUpdateFunction>;
|
|
11
|
-
clients: Set<number>;
|
|
12
|
-
onNextData?: Set<(err?: ObservableError) => void>;
|
|
13
|
-
payload: any;
|
|
14
|
-
diffCache?: Uint8Array;
|
|
15
|
-
cache?: Uint8Array;
|
|
16
|
-
rawData?: any;
|
|
17
|
-
previousChecksum?: number;
|
|
18
|
-
isDeflate?: boolean;
|
|
19
|
-
checksum?: number;
|
|
20
|
-
closeFunction?: () => void;
|
|
21
|
-
error?: ObservableError | null;
|
|
22
|
-
closeAfterIdleTime?: number;
|
|
23
|
-
timeTillDestroy: number | null;
|
|
24
|
-
isDestroyed: boolean;
|
|
25
|
-
};
|
package/dist/observable/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/observable/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { BasedServer } from '../server';
|
|
2
|
-
import { WebSocketSession, Context } from '@based/functions';
|
|
3
|
-
import { ObservableUpdateFunction } from './types';
|
|
4
|
-
export declare const unsubscribeFunction: (server: BasedServer, id: number, update: ObservableUpdateFunction) => true | void;
|
|
5
|
-
export declare const unsubscribeWs: (server: BasedServer, id: number, ctx: Context<WebSocketSession>) => true | void;
|
|
6
|
-
export declare const unsubscribeWsIgnoreClient: (server: BasedServer, id: number, ctx: Context<WebSocketSession>) => true | void;
|
package/dist/observable/unsub.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unsubscribeWsIgnoreClient = exports.unsubscribeWs = exports.unsubscribeFunction = void 0;
|
|
4
|
-
const destroy_1 = require("./destroy");
|
|
5
|
-
const unsubscribeFunction = (server, id, update) => {
|
|
6
|
-
const obs = server.activeObservablesById.get(id);
|
|
7
|
-
if (!obs) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
if (obs.functionObserveClients.delete(update)) {
|
|
11
|
-
(0, destroy_1.destroyObs)(server, id);
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
exports.unsubscribeFunction = unsubscribeFunction;
|
|
16
|
-
const unsubscribeWs = (server, id, ctx) => {
|
|
17
|
-
const session = ctx.session;
|
|
18
|
-
if (!session || !session.obs.has(id)) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
ctx.session.ws.unsubscribe(String(id));
|
|
22
|
-
const obs = server.activeObservablesById.get(id);
|
|
23
|
-
session.obs.delete(id);
|
|
24
|
-
if (!obs) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
if (obs.clients.delete(session.id)) {
|
|
28
|
-
(0, destroy_1.destroyObs)(server, id);
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
exports.unsubscribeWs = unsubscribeWs;
|
|
33
|
-
const unsubscribeWsIgnoreClient = (server, id, ctx) => {
|
|
34
|
-
const session = ctx.session;
|
|
35
|
-
if (!session) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const obs = server.activeObservablesById.get(id);
|
|
39
|
-
if (!obs) {
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
obs.clients.delete(session.id);
|
|
43
|
-
(0, destroy_1.destroyObs)(server, id);
|
|
44
|
-
};
|
|
45
|
-
exports.unsubscribeWsIgnoreClient = unsubscribeWsIgnoreClient;
|
|
46
|
-
//# sourceMappingURL=unsub.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unsub.js","sourceRoot":"","sources":["../../src/observable/unsub.ts"],"names":[],"mappings":";;;AAEA,uCAAsC;AAG/B,MAAM,mBAAmB,GAAG,CACjC,MAAmB,EACnB,EAAU,EACV,MAAgC,EACnB,EAAE;IACf,MAAM,GAAG,GAAG,MAAM,CAAC,qBAAqB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IAChD,IAAI,CAAC,GAAG,EAAE;QACR,OAAM;KACP;IACD,IAAI,GAAG,CAAC,sBAAsB,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;QAC7C,IAAA,oBAAU,EAAC,MAAM,EAAE,EAAE,CAAC,CAAA;QACtB,OAAO,IAAI,CAAA;KACZ;AACH,CAAC,CAAA;AAbY,QAAA,mBAAmB,uBAa/B;AAEM,MAAM,aAAa,GAAG,CAC3B,MAAmB,EACnB,EAAU,EACV,GAA8B,EACjB,EAAE;IACf,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAA;IAC3B,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG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