@based/server 3.1.0 → 3.2.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/.turbo/turbo-build.log +2 -2
- package/dist/Params.d.ts +1 -1
- package/dist/functions/index.d.ts +23 -0
- package/dist/functions/index.js +149 -0
- package/dist/functions/index.js.map +1 -0
- package/dist/functions/timeout.d.ts +3 -0
- package/dist/functions/timeout.js +23 -0
- package/dist/functions/timeout.js.map +1 -0
- package/dist/handlers/bulkUpdate/index.d.ts +5 -0
- package/dist/handlers/bulkUpdate/index.js +25 -0
- package/dist/handlers/bulkUpdate/index.js.map +1 -0
- package/dist/handlers/messageParser.js +4 -0
- package/dist/handlers/messageParser.js.map +1 -1
- package/dist/handlers/set copy/index.d.ts +5 -0
- package/dist/handlers/set copy/index.js +20 -0
- package/dist/handlers/set copy/index.js.map +1 -0
- package/dist/network/index.d.ts +4 -0
- package/dist/network/index.js +63 -0
- package/dist/network/index.js.map +1 -0
- package/dist/network/message.d.ts +3 -0
- package/dist/network/message.js +72 -0
- package/dist/network/message.js.map +1 -0
- package/dist/network/protocol.d.ts +6 -0
- package/dist/network/protocol.js +25 -0
- package/dist/network/protocol.js.map +1 -0
- package/dist/network/upgrade.d.ts +4 -0
- package/dist/network/upgrade.js +45 -0
- package/dist/network/upgrade.js.map +1 -0
- package/dist/network/utils.d.ts +6 -0
- package/dist/network/utils.js +25 -0
- package/dist/network/utils.js.map +1 -0
- package/dist/observable/index.d.ts +9 -0
- package/dist/observable/index.js +28 -0
- package/dist/observable/index.js.map +1 -0
- package/dist/server.d.ts +22 -0
- package/dist/server.js +53 -0
- package/dist/server.js.map +1 -0
- package/dist/types.d.ts +2 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +25 -0
- package/dist/utils.js.map +1 -0
- package/package.json +3 -3
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
[36m@based/server:build: [0mcache hit, replaying output [
|
|
1
|
+
[36m@based/server:build: [0mcache hit, replaying output [2mc8a19a5b836d2551[0m
|
|
2
2
|
[36m@based/server:build: [0m
|
|
3
|
-
[36m@based/server:build: [0m> @based/server@3.
|
|
3
|
+
[36m@based/server:build: [0m> @based/server@3.1.1 build
|
|
4
4
|
[36m@based/server:build: [0m> npx tsc
|
|
5
5
|
[36m@based/server:build: [0m
|
package/dist/Params.d.ts
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { BasedServer } from '../server';
|
|
3
|
+
import { BasedFunctionSpec, BasedObservableFunctionSpec, FunctionConfig, isObservableFunctionSpec } from '../types';
|
|
4
|
+
export { isObservableFunctionSpec };
|
|
5
|
+
export declare class BasedFunctions {
|
|
6
|
+
server: BasedServer;
|
|
7
|
+
config: FunctionConfig;
|
|
8
|
+
unregisterTimeout: NodeJS.Timeout;
|
|
9
|
+
observables: {
|
|
10
|
+
[key: string]: BasedObservableFunctionSpec;
|
|
11
|
+
};
|
|
12
|
+
functions: {
|
|
13
|
+
[key: string]: BasedFunctionSpec;
|
|
14
|
+
};
|
|
15
|
+
constructor(server: BasedServer, config?: FunctionConfig);
|
|
16
|
+
unregisterLoop(): void;
|
|
17
|
+
updateConfig(config: FunctionConfig): void;
|
|
18
|
+
get(name: string): Promise<BasedObservableFunctionSpec | BasedFunctionSpec | false>;
|
|
19
|
+
getFromStore(name: string): BasedObservableFunctionSpec | BasedFunctionSpec | false;
|
|
20
|
+
update(spec: BasedObservableFunctionSpec | BasedFunctionSpec): boolean;
|
|
21
|
+
remove(name: string): boolean;
|
|
22
|
+
unregister(name: string, spec?: BasedObservableFunctionSpec | BasedFunctionSpec | false): Promise<boolean>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BasedFunctions = exports.isObservableFunctionSpec = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
Object.defineProperty(exports, "isObservableFunctionSpec", { enumerable: true, get: function () { return types_1.isObservableFunctionSpec; } });
|
|
6
|
+
const utils_1 = require("@saulx/utils");
|
|
7
|
+
const timeout_1 = require("./timeout");
|
|
8
|
+
class BasedFunctions {
|
|
9
|
+
constructor(server, config) {
|
|
10
|
+
this.observables = {};
|
|
11
|
+
this.functions = {};
|
|
12
|
+
this.server = server;
|
|
13
|
+
if (config) {
|
|
14
|
+
this.updateConfig(config);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
unregisterLoop() {
|
|
18
|
+
this.unregisterTimeout = setTimeout(async () => {
|
|
19
|
+
const q = [];
|
|
20
|
+
for (const name in this.functions) {
|
|
21
|
+
const spec = this.functions[name];
|
|
22
|
+
if ((0, timeout_1.fnIsTimedOut)(spec)) {
|
|
23
|
+
q.push(this.unregister(name, spec));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
for (const name in this.observables) {
|
|
27
|
+
const spec = this.observables[name];
|
|
28
|
+
if (this.server.activeObservables[name]) {
|
|
29
|
+
(0, timeout_1.updateTimeoutCounter)(spec, this.config.idleTimeout);
|
|
30
|
+
}
|
|
31
|
+
else if ((0, timeout_1.fnIsTimedOut)(spec)) {
|
|
32
|
+
q.push(this.unregister(name, spec));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
await Promise.all(q);
|
|
36
|
+
this.unregisterLoop();
|
|
37
|
+
}, 3e3);
|
|
38
|
+
}
|
|
39
|
+
updateConfig(config) {
|
|
40
|
+
if (this.config) {
|
|
41
|
+
(0, utils_1.deepMerge)(this.config, config);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.config = config;
|
|
45
|
+
}
|
|
46
|
+
if (this.config.idleTimeout === undefined) {
|
|
47
|
+
this.config.idleTimeout = 20e3; // 1 min
|
|
48
|
+
}
|
|
49
|
+
if (this.config.memCacheTimeout === undefined) {
|
|
50
|
+
this.config.memCacheTimeout = 3e3;
|
|
51
|
+
}
|
|
52
|
+
if (this.config.maxWorkers === undefined) {
|
|
53
|
+
this.config.maxWorkers = 0;
|
|
54
|
+
}
|
|
55
|
+
if (this.config.log === undefined) {
|
|
56
|
+
this.config.log = (opts) => {
|
|
57
|
+
console.info(opts);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (this.unregisterTimeout) {
|
|
61
|
+
clearTimeout(this.unregisterTimeout);
|
|
62
|
+
}
|
|
63
|
+
this.unregisterLoop();
|
|
64
|
+
}
|
|
65
|
+
async get(name) {
|
|
66
|
+
let spec = this.getFromStore(name);
|
|
67
|
+
if (spec) {
|
|
68
|
+
return spec;
|
|
69
|
+
}
|
|
70
|
+
spec = await this.config.register({
|
|
71
|
+
server: this.server,
|
|
72
|
+
name,
|
|
73
|
+
});
|
|
74
|
+
if (spec) {
|
|
75
|
+
this.update(spec);
|
|
76
|
+
return this.getFromStore(name);
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
getFromStore(name) {
|
|
81
|
+
const spec = this.observables[name] || this.functions[name];
|
|
82
|
+
if (spec) {
|
|
83
|
+
(0, timeout_1.updateTimeoutCounter)(spec, this.config.idleTimeout);
|
|
84
|
+
return spec;
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
update(spec) {
|
|
89
|
+
if (spec) {
|
|
90
|
+
if (spec.timeoutCounter === undefined) {
|
|
91
|
+
const idleTimeout = spec.idleTimeout || this.config.idleTimeout;
|
|
92
|
+
spec.timeoutCounter = idleTimeout === 0 ? -1 : idleTimeout;
|
|
93
|
+
}
|
|
94
|
+
if ((0, types_1.isObservableFunctionSpec)(spec)) {
|
|
95
|
+
if (this.functions[spec.name]) {
|
|
96
|
+
this.remove(spec.name);
|
|
97
|
+
}
|
|
98
|
+
this.observables[spec.name] = spec;
|
|
99
|
+
if (this.server.activeObservables[spec.name]) {
|
|
100
|
+
for (const id in this.server.activeObservables[spec.name]) {
|
|
101
|
+
this.server.activeObservables[spec.name][id].updateObservableCode();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
if (this.observables[spec.name]) {
|
|
107
|
+
this.remove(spec.name);
|
|
108
|
+
}
|
|
109
|
+
this.functions[spec.name] = spec;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
remove(name) {
|
|
115
|
+
// Does not call unregister!
|
|
116
|
+
if (this.observables[name]) {
|
|
117
|
+
delete this.observables[name];
|
|
118
|
+
const active = this.server.activeObservables[name];
|
|
119
|
+
if (active) {
|
|
120
|
+
for (const id in active) {
|
|
121
|
+
active[id].destroy();
|
|
122
|
+
}
|
|
123
|
+
delete this.server.activeObservables[name];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else if (this.functions[name]) {
|
|
127
|
+
delete this.functions[name];
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
async unregister(name, spec) {
|
|
133
|
+
if (!spec && spec !== false) {
|
|
134
|
+
spec = this.getFromStore(name);
|
|
135
|
+
}
|
|
136
|
+
if (spec) {
|
|
137
|
+
if (await this.config.unregister({
|
|
138
|
+
server: this.server,
|
|
139
|
+
function: spec,
|
|
140
|
+
name,
|
|
141
|
+
})) {
|
|
142
|
+
return this.remove(name);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.BasedFunctions = BasedFunctions;
|
|
149
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":";;;AACA,oCAKiB;AAIR,yGALP,gCAAwB,OAKO;AAHjC,wCAAwC;AACxC,uCAA8D;AAI9D,MAAa,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IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;aACzB;SACF;QACD,OAAO,KAAK,CAAA;IACd,CAAC;CACF;AAnKD,wCAmKC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { BasedFunctionSpec, BasedObservableFunctionSpec } from '../types';
|
|
2
|
+
export declare const fnIsTimedOut: (spec: BasedObservableFunctionSpec | BasedFunctionSpec) => boolean;
|
|
3
|
+
export declare const updateTimeoutCounter: (spec: BasedObservableFunctionSpec | BasedFunctionSpec, idleTimeoutDefault: number) => void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateTimeoutCounter = exports.fnIsTimedOut = void 0;
|
|
4
|
+
const fnIsTimedOut = (spec) => {
|
|
5
|
+
if (spec.timeoutCounter !== -1) {
|
|
6
|
+
if (spec.idleTimeout > 0) {
|
|
7
|
+
spec.idleTimeout--;
|
|
8
|
+
}
|
|
9
|
+
if (spec.idleTimeout === 0) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
};
|
|
15
|
+
exports.fnIsTimedOut = fnIsTimedOut;
|
|
16
|
+
const updateTimeoutCounter = (spec, idleTimeoutDefault) => {
|
|
17
|
+
if (spec.timeoutCounter !== -1) {
|
|
18
|
+
const idleTimeout = spec.idleTimeout || idleTimeoutDefault;
|
|
19
|
+
spec.timeoutCounter = idleTimeout === 0 ? -1 : idleTimeout;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
exports.updateTimeoutCounter = updateTimeoutCounter;
|
|
23
|
+
//# sourceMappingURL=timeout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout.js","sourceRoot":"","sources":["../../src/functions/timeout.ts"],"names":[],"mappings":";;;AAEO,MAAM,YAAY,GAAG,CAC1B,IAAqD,EAC5C,EAAE;IACX,IAAI,IAAI,CAAC,cAAc,KAAK,CAAC,CAAC,EAAE;QAC9B,IAAI,IAAI,CAAC,WAAW,GAAG,CAAC,EAAE;YACxB,IAAI,CAAC,WAAW,EAAE,CAAA;SACnB;QACD,IAAI,IAAI,CAAC,WAAW,KAAK,CAAC,EAAE;YAC1B,OAAO,IAAI,CAAA;SACZ;KACF;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAZY,QAAA,YAAY,gBAYxB;AAEM,MAAM,oBAAoB,GAAG,CAClC,IAAqD,EACrD,kBAA0B,EAC1B,EAAE;IACF,IAAI,IAAI,CAAC,cAAc,KAAK,CAAC,CAAC,EAAE;QAC9B,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,IAAI,kBAAkB,CAAA;QAC1D,IAAI,CAAC,cAAc,GAAG,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAA;KAC3D;AACH,CAAC,CAAA;AARY,QAAA,oBAAoB,wBAQhC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { BasedServer } from '../..';
|
|
2
|
+
import Client from '../../Client';
|
|
3
|
+
import { RequestMessage } from '@based/client';
|
|
4
|
+
declare const _default: (server: BasedServer, client: Client, [, reqId, payload]: RequestMessage<import("@based/types").GenericObject>) => Promise<void>;
|
|
5
|
+
export default _default;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const client_1 = require("@based/client");
|
|
4
|
+
exports.default = async (server, client, [, reqId, payload]) => {
|
|
5
|
+
if (typeof payload === 'string')
|
|
6
|
+
throw new Error('payload cannot be a string');
|
|
7
|
+
try {
|
|
8
|
+
const id = await server.db.update(payload.payload, payload.query);
|
|
9
|
+
client.send([client_1.RequestTypes.BulkUpdate, reqId, { id }]);
|
|
10
|
+
}
|
|
11
|
+
catch (err) {
|
|
12
|
+
client.send([
|
|
13
|
+
client_1.RequestTypes.Set,
|
|
14
|
+
reqId,
|
|
15
|
+
0,
|
|
16
|
+
{
|
|
17
|
+
type: 'ValidationError',
|
|
18
|
+
name: 'BulkUpdate',
|
|
19
|
+
message: err.message,
|
|
20
|
+
payload,
|
|
21
|
+
},
|
|
22
|
+
]);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/handlers/bulkUpdate/index.ts"],"names":[],"mappings":";;AAEA,0CAA4D;AAC5D,kBAAe,KAAK,EAClB,MAAmB,EACnB,MAAc,EACd,CAAC,EAAE,KAAK,EAAE,OAAO,CAAiB,EAClC,EAAE;IACF,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;IAC9E,IAAI;QACF,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;QACjE,MAAM,CAAC,IAAI,CAAC,CAAC,qBAAY,CAAC,UAAU,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAA;KACtD;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,CAAC,IAAI,CAAC;YACV,qBAAY,CAAC,GAAG;YAChB,KAAK;YACL,CAAC;YACD;gBACE,IAAI,EAAE,iBAAiB;gBACvB,IAAI,EAAE,YAAY;gBAClB,OAAO,EAAE,GAAG,CAAC,OAAO;gBACpB,OAAO;aACR;SACF,CAAC,CAAA;KACH;AACH,CAAC,CAAA"}
|
|
@@ -27,6 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
const set_1 = __importDefault(require("./set"));
|
|
30
|
+
const bulkUpdate_1 = __importDefault(require("./bulkUpdate"));
|
|
30
31
|
const copy_1 = __importDefault(require("./copy"));
|
|
31
32
|
const track_1 = __importDefault(require("./track"));
|
|
32
33
|
const get_1 = __importDefault(require("./get"));
|
|
@@ -77,6 +78,9 @@ exports.default = (server, client, messages) => {
|
|
|
77
78
|
else if (msg[0] === client_1.RequestTypes.Set) {
|
|
78
79
|
(0, set_1.default)(server, client, msg);
|
|
79
80
|
}
|
|
81
|
+
else if (msg[0] === client_1.RequestTypes.BulkUpdate) {
|
|
82
|
+
(0, bulkUpdate_1.default)(server, client, msg);
|
|
83
|
+
}
|
|
80
84
|
else if (msg[0] === client_1.RequestTypes.Track) {
|
|
81
85
|
(0, track_1.default)(server, client, msg);
|
|
82
86
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messageParser.js","sourceRoot":"","sources":["../../src/handlers/messageParser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,gDAAuB;AACvB,kDAAyB;AACzB,oDAA2B;AAC3B,gDAAuB;AACvB,8DAAqC;AACrC,gEAAuC;AACvC,sDAA6B;AAC7B,sDAA0B;AAC1B,4DAAmC;AACnC,4DAAmC;AACnC,4DAAmC;AACnC,4DAA6C;AAC7C,qDAAsC;AACtC,iDAA6E;AAC7E,0CAAmE;AAEnE,0DAAiC;AAEjC,kBAAe,CACb,MAAmB,EACnB,MAAc,EACd,QAAoC,EACpC,EAAE;IACF,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE;QAC1B,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,qBAAY,CAAC,WAAW,EAAE;YACvC,IAAA,qBAAW,EAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAA;SACjC;aAAM,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,qBAAY,CAAC,UAAU,EAAE;YAC7C,IAAA,oBAAU,EAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAA;SAChC;aAA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+
import { BasedServer } from '../..';
|
|
2
|
+
import Client from '../../Client';
|
|
3
|
+
import { RequestMessage } from '@based/client';
|
|
4
|
+
declare const _default: (server: BasedServer, client: Client, [, reqId, payload]: RequestMessage<import("@based/types").GenericObject>) => Promise<void>;
|
|
5
|
+
export default _default;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const client_1 = require("@based/client");
|
|
4
|
+
exports.default = async (server, client, [, reqId, payload]) => {
|
|
5
|
+
if (typeof payload === 'string')
|
|
6
|
+
throw new Error('payload cannot be a string');
|
|
7
|
+
try {
|
|
8
|
+
const id = await server.db.set(payload);
|
|
9
|
+
client.send([client_1.RequestTypes.Set, reqId, { id }]);
|
|
10
|
+
}
|
|
11
|
+
catch (err) {
|
|
12
|
+
client.send([
|
|
13
|
+
client_1.RequestTypes.Set,
|
|
14
|
+
reqId,
|
|
15
|
+
0,
|
|
16
|
+
{ type: 'ValidationError', name: 'set', message: err.message, payload },
|
|
17
|
+
]);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/handlers/set copy/index.ts"],"names":[],"mappings":";;AAEA,0CAA4D;AAC5D,kBAAe,KAAK,EAClB,MAAmB,EACnB,MAAc,EACd,CAAC,EAAE,KAAK,EAAE,OAAO,CAAiB,EAClC,EAAE;IACF,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;IAC9E,IAAI;QACF,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QACvC,MAAM,CAAC,IAAI,CAAC,CAAC,qBAAY,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAA;KAC/C;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,CAAC,IAAI,CAAC;YACV,qBAAY,CAAC,GAAG;YAChB,KAAK;YACL,CAAC;YACD,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE;SACxE,CAAC,CAAA;KACH;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
const uws_1 = __importDefault(require("@based/uws"));
|
|
7
|
+
const upgrade_1 = require("./upgrade");
|
|
8
|
+
const message_1 = require("./message");
|
|
9
|
+
exports.default = (server, { key, cert, port }) => {
|
|
10
|
+
const app = key && cert
|
|
11
|
+
? uws_1.default.SSLApp({
|
|
12
|
+
key_file_name: key,
|
|
13
|
+
cert_file_name: cert,
|
|
14
|
+
ssl_prefer_low_memory_usage: true,
|
|
15
|
+
})
|
|
16
|
+
: uws_1.default.App();
|
|
17
|
+
if (port) {
|
|
18
|
+
server.port = port;
|
|
19
|
+
}
|
|
20
|
+
/*
|
|
21
|
+
open:ws=>ws.subscribe('all')
|
|
22
|
+
app.publish('all',message)
|
|
23
|
+
*/
|
|
24
|
+
app.ws('/*', {
|
|
25
|
+
maxPayloadLength: 1024 * 1024 * 5,
|
|
26
|
+
idleTimeout: 100,
|
|
27
|
+
maxBackpressure: 1024,
|
|
28
|
+
compression: uws_1.default.SHARED_COMPRESSOR,
|
|
29
|
+
upgrade: server.authorizeConnection
|
|
30
|
+
? (res, req, ctx) => {
|
|
31
|
+
(0, upgrade_1.upgradeAuthorize)(server.authorizeConnection, res, req, ctx);
|
|
32
|
+
}
|
|
33
|
+
: upgrade_1.upgrade,
|
|
34
|
+
message: (ws, data, isBinary) => {
|
|
35
|
+
(0, message_1.message)(server, ws, data, isBinary);
|
|
36
|
+
},
|
|
37
|
+
open: (ws) => {
|
|
38
|
+
console.info('open');
|
|
39
|
+
// ws.token = 'x' token - only on upgrade does make it super easy
|
|
40
|
+
console.info(ws);
|
|
41
|
+
// broadcast will only do diffs except when its a new sub
|
|
42
|
+
// send is used to send a current value
|
|
43
|
+
// open(this, ws)
|
|
44
|
+
},
|
|
45
|
+
close: (ws) => {
|
|
46
|
+
console.info('close');
|
|
47
|
+
// close(this, ws)
|
|
48
|
+
},
|
|
49
|
+
drain: (ws) => {
|
|
50
|
+
console.info('drain');
|
|
51
|
+
// call client.drain can be much more efficient
|
|
52
|
+
// if (ws.client && ws.client.backpressureQueue) {
|
|
53
|
+
// ws.client.drain()
|
|
54
|
+
// }
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
// REST
|
|
58
|
+
// .get('/*', (res, req) => restHandler(this, req, res))
|
|
59
|
+
// .post('/*', (res, req) => restHandler(this, req, res))
|
|
60
|
+
// .options('/*', (res, req) => restHandler(this, req, res))
|
|
61
|
+
server.uwsApp = app;
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/network/index.ts"],"names":[],"mappings":";;;;;AAEA,qDAA4B;AAC5B,uCAAqD;AACrD,uCAAmC;AAEnC,kBAAe,CAAC,MAAmB,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAiB,EAAE,EAAE;IACzE,MAAM,GAAG,GACP,GAAG,IAAI,IAAI;QACT,CAAC,CAAC,aAAG,CAAC,MAAM,CAAC;YACT,aAAa,EAAE,GAAG;YAClB,cAAc,EAAE,IAAI;YACpB,2BAA2B,EAAE,IAAI;SAClC,CAAC;QACJ,CAAC,CAAC,aAAG,CAAC,GAAG,EAAE,CAAA;IAEf,IAAI,IAAI,EA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;AACrB,CAAC,CAAA"}
|
|
@@ -0,0 +1,72 @@
|
|
|
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.message = void 0;
|
|
7
|
+
const zlib_1 = __importDefault(require("zlib"));
|
|
8
|
+
const functions_1 = require("../functions");
|
|
9
|
+
const utils_1 = require("../utils");
|
|
10
|
+
const textDecoder = new TextDecoder();
|
|
11
|
+
const reader = (server, ws, arr, start) => {
|
|
12
|
+
const { len, isDeflate, type } = (0, utils_1.decodeHeader)((0, utils_1.readUint8)(arr, start, 4));
|
|
13
|
+
if (type === 0) {
|
|
14
|
+
// make this into a function
|
|
15
|
+
const reqId = (0, utils_1.readUint8)(arr, start + 4, 3);
|
|
16
|
+
const namelen = arr[7];
|
|
17
|
+
const name = new Uint8Array(arr.slice(start + 8, start + 8 + namelen));
|
|
18
|
+
const nameParsed = textDecoder.decode(name);
|
|
19
|
+
const payload = new Uint8Array(arr.slice(start + 8 + namelen, start + len + 4));
|
|
20
|
+
let p;
|
|
21
|
+
if (!isDeflate) {
|
|
22
|
+
p = textDecoder.decode(payload);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const buffer = zlib_1.default.inflateRawSync(payload);
|
|
26
|
+
p = textDecoder.decode(buffer);
|
|
27
|
+
}
|
|
28
|
+
server.functions
|
|
29
|
+
.get(nameParsed)
|
|
30
|
+
.then((spec) => {
|
|
31
|
+
if (spec && !(0, functions_1.isObservableFunctionSpec)(spec)) {
|
|
32
|
+
spec
|
|
33
|
+
.function(p)
|
|
34
|
+
.then((v) => {
|
|
35
|
+
ws.send(JSON.stringify({
|
|
36
|
+
id: reqId,
|
|
37
|
+
msg: v,
|
|
38
|
+
}));
|
|
39
|
+
})
|
|
40
|
+
.catch((err) => {
|
|
41
|
+
console.error('bad fn', err);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
console.error('No function for you');
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
.catch((err) => {
|
|
49
|
+
console.error('fn does not exist', err);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return len + 4 + start;
|
|
53
|
+
};
|
|
54
|
+
const message = (server, ws, msg, isBinary) => {
|
|
55
|
+
if (!isBinary) {
|
|
56
|
+
ws.close();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const uint8View = new Uint8Array(msg);
|
|
60
|
+
const len = uint8View.length;
|
|
61
|
+
let next = 0;
|
|
62
|
+
while (next < len) {
|
|
63
|
+
const n = reader(server, ws, uint8View, next);
|
|
64
|
+
if (n === undefined) {
|
|
65
|
+
console.error('Cannot read header!');
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
next = n;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
exports.message = message;
|
|
72
|
+
//# sourceMappingURL=message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../src/network/message.ts"],"names":[],"mappings":";;;;;;AACA,gDAAuB;AACvB,4CAAuD;AAEvD,oCAAkD;AAElD,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAA;AAErC,MAAM,MAAM,GAAG,CACb,MAAmB,EACnB,EAAiB,EACjB,GAAe,EACf,KAAa,EACL,EAAE;IACV,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,IAAA,oBAAY,EAAC,IAAA,iBAAS,EAAC,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAA;IACvE,IAAI,IAAI,KAAK,CAAC,EAAE;QACd,4BAA4B;QAE5B,MAAM,KAAK,GAAG,IAAA,iBAAS,EAAC,GAAG,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA;QAC1C,MA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AC,CAAA;aACrC;QACH,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACb,OAAO,CAAC,KAAK,CAAC,mBAAmB,EAAE,GAAG,CAAC,CAAA;QACzC,CAAC,CAAC,CAAA;KACL;IACD,OAAO,GAAG,GAAG,CAAC,GAAG,KAAK,CAAA;AACxB,CAAC,CAAA;AAEM,MAAM,OAAO,GAAG,CACrB,MAAmB,EACnB,EAAiB,EACjB,GAAG,EACH,QAAQ,EACR,EAAE;IACF,IAAI,CAAC,QAAQ,EAAE;QACb,EAAE,CAAC,KAAK,EAAE,CAAA;QACV,OAAM;KACP;IAED,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAA;IACrC,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,CAAA;IAE5B,IAAI,IAAI,GAAG,CAAC,CAAA;IACZ,OAAO,IAAI,GAAG,GAAG,EAAE;QACjB,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,CAAA;QAC7C,IAAI,CAAC,KAAK,SAAS,EAAE;YACnB,OAAO,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAA;YACpC,OAAM;SACP;QACD,IAAI,GAAG,CAAC,CAAA;KACT;AACH,CAAC,CAAA;AAvBY,QAAA,OAAO,WAuBnB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readUint8 = exports.decodeHeader = void 0;
|
|
4
|
+
const decodeHeader = (nr) => {
|
|
5
|
+
const len = nr >> 4;
|
|
6
|
+
const meta = nr & 15;
|
|
7
|
+
const type = meta >> 1;
|
|
8
|
+
const isDeflate = meta & 1;
|
|
9
|
+
return {
|
|
10
|
+
type,
|
|
11
|
+
isDeflate: isDeflate === 1,
|
|
12
|
+
len,
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
exports.decodeHeader = decodeHeader;
|
|
16
|
+
const readUint8 = (buff, start, len) => {
|
|
17
|
+
let n = 0;
|
|
18
|
+
const s = len - 1 + start;
|
|
19
|
+
for (let i = s; i >= start; i--) {
|
|
20
|
+
n = n * 256 + buff[i];
|
|
21
|
+
}
|
|
22
|
+
return n;
|
|
23
|
+
};
|
|
24
|
+
exports.readUint8 = readUint8;
|
|
25
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/network/protocol.ts"],"names":[],"mappings":";;;AAAO,MAAM,YAAY,GAAG,CAC1B,EAAU,EACyC,EAAE;IACrD,MAAM,GAAG,GAAG,EAAE,IAAI,CAAC,CAAA;IACnB,MAAM,IAAI,GAAG,EAAE,GAAG,EAAE,CAAA;IACpB,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAA;IACtB,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAA;IAC1B,OAAO;QACL,IAAI;QACJ,SAAS,EAAE,SAAS,KAAK,CAAC;QAC1B,GAAG;KACJ,CAAA;AACH,CAAC,CAAA;AAZY,QAAA,YAAY,gBAYxB;AAEM,MAAM,SAAS,GAAG,CACvB,IAAgB,EAChB,KAAa,EACb,GAAW,EACH,EAAE;IACV,IAAI,CAAC,GAAG,CAAC,CAAA;IACT,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,KAAK,CAAA;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,EAAE,EAAE;QAC/B,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;KACtB;IACD,OAAO,CAAC,CAAA;AACV,CAAC,CAAA;AAXY,QAAA,SAAS,aAWrB"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import uws from '@based/uws';
|
|
2
|
+
import { AuthorizeConnection } from '../types';
|
|
3
|
+
export declare const upgrade: (res: uws.HttpResponse, req: uws.HttpRequest, ctx: uws.us_socket_context_t) => void;
|
|
4
|
+
export declare const upgradeAuthorize: (authorizeConnection: AuthorizeConnection, res: uws.HttpResponse, req: uws.HttpRequest, ctx: uws.us_socket_context_t) => void;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.upgradeAuthorize = exports.upgrade = void 0;
|
|
4
|
+
const upgrade = (res, req,
|
|
5
|
+
// eslint-disable-next-line
|
|
6
|
+
ctx) => {
|
|
7
|
+
const query = req.getQuery();
|
|
8
|
+
const ua = req.getHeader('user-agent');
|
|
9
|
+
const ip = req.getHeader('x-forwarded-for') ||
|
|
10
|
+
Buffer.from(res.getRemoteAddressAsText()).toString();
|
|
11
|
+
const secWebSocketKey = req.getHeader('sec-websocket-key');
|
|
12
|
+
const secWebSocketProtocol = req.getHeader('sec-websocket-protocol');
|
|
13
|
+
const secWebSocketExtensions = req.getHeader('sec-websocket-extensions');
|
|
14
|
+
res.writeStatus('101 Switching Protocols');
|
|
15
|
+
// ip is 39 bytes - may want to make this nicer (adds 312kb for 8k clients to mem)
|
|
16
|
+
// userdata is essentaily the client
|
|
17
|
+
res.upgrade({
|
|
18
|
+
query,
|
|
19
|
+
ua,
|
|
20
|
+
ip,
|
|
21
|
+
}, secWebSocketKey, secWebSocketProtocol, secWebSocketExtensions, ctx);
|
|
22
|
+
};
|
|
23
|
+
exports.upgrade = upgrade;
|
|
24
|
+
const upgradeAuthorize = (authorizeConnection, res, req,
|
|
25
|
+
// eslint-disable-next-line
|
|
26
|
+
ctx) => {
|
|
27
|
+
let aborted = false;
|
|
28
|
+
res.onAborted(() => {
|
|
29
|
+
aborted = true;
|
|
30
|
+
});
|
|
31
|
+
authorizeConnection(req).then((authorized) => {
|
|
32
|
+
if (aborted) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (authorized) {
|
|
36
|
+
(0, exports.upgrade)(res, req, ctx);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
res.writeStatus('401 Unauthorized');
|
|
40
|
+
res.end();
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
exports.upgradeAuthorize = upgradeAuthorize;
|
|
45
|
+
//# sourceMappingURL=upgrade.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upgrade.js","sourceRoot":"","sources":["../../src/network/upgrade.ts"],"names":[],"mappings":";;;AAGO,MAAM,OAAO,GAAG,CACrB,GAAqB,EACrB,GAAoB;AACpB,2BAA2B;AAC3B,GAA4B,EAC5B,EAAE;IACF,MAAM,KAAK,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAA;IAC5B,MAAM,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,YAAY,CAAC,CAAA;IACtC,MAAM,EAAE,GACN,GAAG,CAAC,SAAS,CAAC,iBAAiB,CAAC;QAChC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,sBAAsB,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAA;IACtD,MAAM,eAAe,GAAG,GAAG,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAA;IAC1D,MAAM,oBAAoB,GAAG,GAAG,CAAC,SAAS,CAAC,wBAAwB,CAAC,CAAA;IACpE,MAAM,sBAAsB,GAAG,GAAG,CAAC,SAAS,CAAC,0BAA0B,CAAC,CAAA;IAExE,GAAG,CAAC,WAAW,CAAC,yBAAyB,CAAC,CAAA;IAE1C,kFAAkF;IAElF,oCAAoC;IACpC,GAAG,CAAC,OAAO,CACT;QACE,KAAK;QACL,EAAE;QACF,EAAE;KACH,EACD,eAAe,EACf,oBAAoB,EACpB,sBAAsB,EACtB,GAAG,CACJ,CAAA;AACH,CAAC,CAAA;AA/BY,QAAA,OAAO,WA+BnB;AAEM,MAAM,gBAAgB,GAAG,CAC9B,mBAAwC,EACxC,GAAqB,EACrB,GAAoB;AACpB,2BAA2B;AAC3B,GAA4B,EAC5B,EAAE;IACF,IAAI,OAAO,GAAG,KAAK,CAAA;IACnB,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,OAAO,GAAG,IAAI,CAAA;IAChB,CAAC,CAAC,CAAA;IACF,mBAAmB,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE;QAC3C,IAAI,OAAO,EAAE;YACX,OAAM;SACP;QACD,IAAI,UAAU,EAAE;YACd,IAAA,eAAO,EAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;SACvB;aAAM;YACL,GAAG,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAA;YACnC,GAAG,CAAC,GAAG,EAAE,CAAA;SACV;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAtBY,QAAA,gBAAgB,oBAsB5B"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readUint8 = exports.decodeHeader = void 0;
|
|
4
|
+
const decodeHeader = (nr) => {
|
|
5
|
+
const len = nr >> 4;
|
|
6
|
+
const meta = nr & 15;
|
|
7
|
+
const type = meta >> 1;
|
|
8
|
+
const isDeflate = meta & 1;
|
|
9
|
+
return {
|
|
10
|
+
type,
|
|
11
|
+
isDeflate: isDeflate === 1,
|
|
12
|
+
len,
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
exports.decodeHeader = decodeHeader;
|
|
16
|
+
const readUint8 = (buff, start, len) => {
|
|
17
|
+
let n = 0;
|
|
18
|
+
const s = len - 1 + start;
|
|
19
|
+
for (let i = s; i >= start; i--) {
|
|
20
|
+
n = n * 256 + buff[i];
|
|
21
|
+
}
|
|
22
|
+
return n;
|
|
23
|
+
};
|
|
24
|
+
exports.readUint8 = readUint8;
|
|
25
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/network/utils.ts"],"names":[],"mappings":";;;AAAO,MAAM,YAAY,GAAG,CAC1B,EAAU,EACyC,EAAE;IACrD,MAAM,GAAG,GAAG,EAAE,IAAI,CAAC,CAAA;IACnB,MAAM,IAAI,GAAG,EAAE,GAAG,EAAE,CAAA;IACpB,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAA;IACtB,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAA;IAC1B,OAAO;QACL,IAAI;QACJ,SAAS,EAAE,SAAS,KAAK,CAAC;QAC1B,GAAG;KACJ,CAAA;AACH,CAAC,CAAA;AAZY,QAAA,YAAY,gBAYxB;AAEM,MAAM,SAAS,GAAG,CACvB,IAAgB,EAChB,KAAa,EACb,GAAW,EACH,EAAE;IACV,IAAI,CAAC,GAAG,CAAC,CAAA;IACT,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,KAAK,CAAA;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,EAAE,EAAE;QAC/B,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;KACtB;IACD,OAAO,CAAC,CAAA;AACV,CAAC,CAAA;AAXY,QAAA,SAAS,aAWrB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BasedServer } from '../server';
|
|
2
|
+
export declare class BasedObservableFunction {
|
|
3
|
+
server: BasedServer;
|
|
4
|
+
name: string;
|
|
5
|
+
id: number;
|
|
6
|
+
constructor(server: BasedServer, name: string, id: number);
|
|
7
|
+
destroy(): void;
|
|
8
|
+
updateObservableCode(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BasedObservableFunction = void 0;
|
|
4
|
+
class BasedObservableFunction {
|
|
5
|
+
constructor(server, name, id) {
|
|
6
|
+
this.server = server;
|
|
7
|
+
if (!this.server.activeObservables[name]) {
|
|
8
|
+
this.server.activeObservables[name] = {};
|
|
9
|
+
}
|
|
10
|
+
if (this.server.activeObservables[name][id]) {
|
|
11
|
+
console.error('OBSERVABLE ALLRDY EXISTS', id, name);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
this.server.activeObservables[name][id] = this;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
destroy() {
|
|
18
|
+
console.info('destroy observable!');
|
|
19
|
+
// also need to send info to clients that its gone (e.g. does not exist anymore)
|
|
20
|
+
delete this.server.activeObservables[this.name][this.id];
|
|
21
|
+
delete this.server.activeObservablesById[this.id];
|
|
22
|
+
}
|
|
23
|
+
async updateObservableCode() {
|
|
24
|
+
console.info('update observable code!', this.id, this.name);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.BasedObservableFunction = BasedObservableFunction;
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/observable/index.ts"],"names":[],"mappings":";;;AAEA,MAAa,uBAAuB;IAKlC,YAAY,MAAmB,EAAE,IAAY,EAAE,EAAU;QACvD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE;YACxC,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,GAAG,EAAE,CAAA;SACzC;QAED,IAAI,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE;YAC3C,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,EAAE,EAAE,IAAI,CAAC,CAAA;SACpD;aAAM;YACL,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAA;SAC/C;IACH,CAAC;IAED,OAAO;QACL,OAAO,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAA;QACnC,gFAAgF;QAChF,OAAO,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACxD,OAAO,IAAI,CAAC,MAAM,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACnD,CAAC;IAED,KAAK,CAAC,oBAAoB;QACxB,OAAO,CAAC,IAAI,CAAC,yBAAyB,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAA;IAC7D,CAAC;CACF;AA5BD,0DA4BC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import uws from '@based/uws';
|
|
2
|
+
import type { AuthorizeConnection, ServerOptions } from './types';
|
|
3
|
+
import { BasedFunctions } from './functions';
|
|
4
|
+
import { BasedObservableFunction } from './observable';
|
|
5
|
+
export declare class BasedServer {
|
|
6
|
+
functions: BasedFunctions;
|
|
7
|
+
port: number;
|
|
8
|
+
uwsApp: uws.TemplatedApp;
|
|
9
|
+
listenSocket: any;
|
|
10
|
+
authorizeConnection: AuthorizeConnection;
|
|
11
|
+
activeObservables: {
|
|
12
|
+
[name: string]: {
|
|
13
|
+
[id: string]: BasedObservableFunction;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
activeObservablesById: {
|
|
17
|
+
[id: string]: BasedObservableFunction;
|
|
18
|
+
};
|
|
19
|
+
constructor(opts: ServerOptions);
|
|
20
|
+
start(port?: number): Promise<BasedServer>;
|
|
21
|
+
destroy(): Promise<void>;
|
|
22
|
+
}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
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.BasedServer = void 0;
|
|
7
|
+
const uws_1 = __importDefault(require("@based/uws"));
|
|
8
|
+
const network_1 = __importDefault(require("./network"));
|
|
9
|
+
const functions_1 = require("./functions");
|
|
10
|
+
class BasedServer {
|
|
11
|
+
constructor(opts) {
|
|
12
|
+
this.activeObservables = {};
|
|
13
|
+
this.activeObservablesById = {};
|
|
14
|
+
(0, network_1.default)(this, opts);
|
|
15
|
+
this.functions = new functions_1.BasedFunctions(this, opts.functions);
|
|
16
|
+
if (opts.authorizeConnection) {
|
|
17
|
+
this.authorizeConnection = opts.authorizeConnection;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
start(port) {
|
|
21
|
+
if (!port) {
|
|
22
|
+
port = this.port;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this.port = port;
|
|
26
|
+
}
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
this.uwsApp.listen(this.port, (listenSocket) => {
|
|
29
|
+
if (listenSocket) {
|
|
30
|
+
console.info('💫 Based-server v2 listening on port:', this.port);
|
|
31
|
+
// do this better wrap a nice thing arround it
|
|
32
|
+
this.listenSocket = listenSocket;
|
|
33
|
+
resolve(this);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
console.info('🤮 Based-server v2 error on port:', this.port);
|
|
37
|
+
reject(new Error('Cannot start based-server on port: ' + this.port));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async destroy() {
|
|
43
|
+
console.info('🔥 Based-server v2 Destroy based-server');
|
|
44
|
+
if (this.listenSocket) {
|
|
45
|
+
uws_1.default.us_listen_socket_close(this.listenSocket);
|
|
46
|
+
this.listenSocket = null;
|
|
47
|
+
}
|
|
48
|
+
this.listenSocket = null;
|
|
49
|
+
this.uwsApp = null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.BasedServer = BasedServer;
|
|
53
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;AAAA,qDAA4B;AAC5B,wDAAmC;AAEnC,2CAA4C;AAG5C,MAAa,WAAW;IAqBtB,YAAY,IAAmB;QAVxB,sBAAiB,GAIpB,EAAE,CAAA;QAEC,0BAAqB,GAExB,EAAE,CAAA;QAGJ,IAAA,iBAAW,EAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QACvB,IAAI,CAAC,SAAS,GAAG,IAAI,0BAAc,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;QACzD,IAAI,IAAI,CAAC,mBAAmB,EAAE;YAC5B,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,mBAAmB,CAAA;SACpD;IACH,CAAC;IAED,KAAK,CAAC,IAAa;QACjB,IAAI,CAAC,IAAI,EAAE;YACT,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;SACjB;aAAM;YACL,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;SACjB;QACD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,YAAY,EAAE,EAAE;gBAC7C,IAAI,YAAY,EAAE;oBAChB,OAAO,CAAC,IAAI,CAAC,wCAAwC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAA;oBACjE,8CAA8C;oBAC9C,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;oBAChC,OAAO,CAAC,IAAI,CAAC,CAAA;iBACd;qBAAM;oBACL,OAAO,CAAC,IAAI,CAAC,oCAAoC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAA;oBAC7D,MAAM,CAAC,IAAI,KAAK,CAAC,qCAAqC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;iBACrE;YACH,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,OAAO;QACX,OAAO,CAAC,IAAI,CAAC,yCAAyC,CAAC,CAAA;QACvD,IAAI,IAAI,CAAC,YAAY,EAAE;YACrB,aAAG,CAAC,sBAAsB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;YAC7C,IAAI,CAAC,YAAY,GAAG,IAAI,CAAA;SACzB;QACD,IAAI,CAAC,YAAY,GAAG,IAAI,CAAA;QACxB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;IACpB,CAAC;CACF;AA3DD,kCA2DC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -9,9 +9,10 @@ import { ErrorObject, GenericObject, Based as BasedAdminClient } from '@based/cl
|
|
|
9
9
|
import { Readable } from 'stream';
|
|
10
10
|
export { Client };
|
|
11
11
|
export declare type CallParams = Omit<Params, 'update'>;
|
|
12
|
+
export declare type ObservableParams = Omit<Params, 'user'>;
|
|
12
13
|
export declare type DataListener = (data: GenericObject, checksum: number, error?: ErrorObject) => void;
|
|
13
14
|
export declare type ObservableFunction = {
|
|
14
|
-
function: (params:
|
|
15
|
+
function: (params: ObservableParams) => Promise<() => void>;
|
|
15
16
|
authorize?: (params: CallParams) => Promise<boolean>;
|
|
16
17
|
observable: true;
|
|
17
18
|
shared: boolean;
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA6B;AAapB,iBAbF,gBAAM,CAaE;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA6B;AAapB,iBAbF,gBAAM,CAaE;AAmCR,MAAM,cAAc,GAAG,CAC5B,EAAqC,EACjB,EAAE;IACtB,OAAO,EAAE,CAAC,UAAU,KAAK,KAAK,CAAA;AAChC,CAAC,CAAA;AAJY,QAAA,cAAc,kBAI1B;AAEM,MAAM,oBAAoB,GAAG,CAClC,EAAqC,EACX,EAAE;IAC5B,OAAO,EAAE,CAAC,UAAU,KAAK,IAAI,CAAA;AAC/B,CAAC,CAAA;AAJY,QAAA,oBAAoB,wBAIhC"}
|
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readUint8 = exports.decodeHeader = void 0;
|
|
4
|
+
const decodeHeader = (nr) => {
|
|
5
|
+
const len = nr >> 4;
|
|
6
|
+
const meta = nr & 15;
|
|
7
|
+
const type = meta >> 1;
|
|
8
|
+
const isDeflate = meta & 1;
|
|
9
|
+
return {
|
|
10
|
+
type,
|
|
11
|
+
isDeflate: isDeflate === 1,
|
|
12
|
+
len,
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
exports.decodeHeader = decodeHeader;
|
|
16
|
+
const readUint8 = (buff, start, len) => {
|
|
17
|
+
let n = 0;
|
|
18
|
+
const s = len - 1 + start;
|
|
19
|
+
for (let i = s; i >= start; i--) {
|
|
20
|
+
n = n * 256 + buff[i];
|
|
21
|
+
}
|
|
22
|
+
return n;
|
|
23
|
+
};
|
|
24
|
+
exports.readUint8 = readUint8;
|
|
25
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAO,MAAM,YAAY,GAAG,CAC1B,EAAU,EACyC,EAAE;IACrD,MAAM,GAAG,GAAG,EAAE,IAAI,CAAC,CAAA;IACnB,MAAM,IAAI,GAAG,EAAE,GAAG,EAAE,CAAA;IACpB,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAA;IACtB,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAA;IAC1B,OAAO;QACL,IAAI;QACJ,SAAS,EAAE,SAAS,KAAK,CAAC;QAC1B,GAAG;KACJ,CAAA;AACH,CAAC,CAAA;AAZY,QAAA,YAAY,gBAYxB;AAEM,MAAM,SAAS,GAAG,CACvB,IAAgB,EAChB,KAAa,EACb,GAAW,EACH,EAAE;IACV,IAAI,CAAC,GAAG,CAAC,CAAA;IACT,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,KAAK,CAAA;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,EAAE,EAAE;QAC/B,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;KACtB;IACD,OAAO,CAAC,CAAA;AACV,CAAC,CAAA;AAXY,QAAA,SAAS,aAWrB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@based/server",
|
|
3
|
-
"version": "3.1
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "src/index.ts",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"@saulx/selva": "10||11||12||13||14"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@based/client": "^3.
|
|
17
|
-
"@based/graphql": "2.4.
|
|
16
|
+
"@based/client": "^3.1.1",
|
|
17
|
+
"@based/graphql": "^2.4.3",
|
|
18
18
|
"@based/uws": "2.4.0",
|
|
19
19
|
"@saulx/diff": "^1.1.3",
|
|
20
20
|
"@saulx/hash": "^1.1.0",
|