@based/server 3.4.4 → 3.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/dist/auth/authorize.d.ts +2 -0
- package/dist/auth/authorize.js +8 -0
- package/dist/auth/authorize.js.map +1 -0
- package/dist/auth/dummyAuth.d.ts +2 -0
- package/dist/auth/dummyAuth.js +7 -0
- package/dist/auth/dummyAuth.js.map +1 -0
- package/dist/auth/index.d.ts +11 -0
- package/dist/auth/index.js +44 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/clientContext.d.ts +0 -0
- package/dist/clientContext.js +83 -0
- package/dist/clientContext.js.map +1 -0
- package/dist/error.d.ts +66 -0
- package/dist/error.js +149 -0
- package/dist/error.js.map +1 -0
- package/dist/functions/index.d.ts +48 -0
- package/dist/functions/index.js +399 -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/functions/workerPool.d.ts +0 -0
- package/dist/functions/workerPool.js +5 -0
- package/dist/functions/workerPool.js.map +1 -0
- package/dist/handlers/rest/file/storeFile.js +33 -23
- package/dist/handlers/rest/file/storeFile.js.map +1 -1
- package/dist/network/http/authorize.d.ts +3 -0
- package/dist/network/http/authorize.js +28 -0
- package/dist/network/http/authorize.js.map +1 -0
- package/dist/network/http/compress.d.ts +6 -0
- package/dist/network/http/compress.js +56 -0
- package/dist/network/http/compress.js.map +1 -0
- package/dist/network/http/end.d.ts +4 -0
- package/dist/network/http/end.js +19 -0
- package/dist/network/http/end.js.map +1 -0
- package/dist/network/http/function.d.ts +3 -0
- package/dist/network/http/function.js +47 -0
- package/dist/network/http/function.js.map +1 -0
- package/dist/network/http/get.d.ts +3 -0
- package/dist/network/http/get.js +129 -0
- package/dist/network/http/get.js.map +1 -0
- package/dist/network/http/index.d.ts +3 -0
- package/dist/network/http/index.js +122 -0
- package/dist/network/http/index.js.map +1 -0
- package/dist/network/http/readBody.d.ts +3 -0
- package/dist/network/http/readBody.js +112 -0
- package/dist/network/http/readBody.js.map +1 -0
- package/dist/network/http/send.d.ts +5 -0
- package/dist/network/http/send.js +60 -0
- package/dist/network/http/send.js.map +1 -0
- package/dist/network/http/streamFunction/DataStream.d.ts +7 -0
- package/dist/network/http/streamFunction/DataStream.js +19 -0
- package/dist/network/http/streamFunction/DataStream.js.map +1 -0
- package/dist/network/http/streamFunction/getExtension.d.ts +2 -0
- package/dist/network/http/streamFunction/getExtension.js +29 -0
- package/dist/network/http/streamFunction/getExtension.js.map +1 -0
- package/dist/network/http/streamFunction/index.d.ts +3 -0
- package/dist/network/http/streamFunction/index.js +81 -0
- package/dist/network/http/streamFunction/index.js.map +1 -0
- package/dist/network/http/streamFunction/multipartStream.d.ts +12 -0
- package/dist/network/http/streamFunction/multipartStream.js +208 -0
- package/dist/network/http/streamFunction/multipartStream.js.map +1 -0
- package/dist/network/http/streamFunction/stream.d.ts +5 -0
- package/dist/network/http/streamFunction/stream.js +103 -0
- package/dist/network/http/streamFunction/stream.js.map +1 -0
- package/dist/network/index.d.ts +4 -0
- package/dist/network/index.js +84 -0
- package/dist/network/index.js.map +1 -0
- package/dist/network/message/auth.d.ts +4 -0
- package/dist/network/message/auth.js +32 -0
- package/dist/network/message/auth.js.map +1 -0
- package/dist/network/message/function.d.ts +3 -0
- package/dist/network/message/function.js +67 -0
- package/dist/network/message/function.js.map +1 -0
- package/dist/network/message/get.d.ts +3 -0
- package/dist/network/message/get.js +109 -0
- package/dist/network/message/get.js.map +1 -0
- package/dist/network/message/index.d.ts +3 -0
- package/dist/network/message/index.js +62 -0
- package/dist/network/message/index.js.map +1 -0
- package/dist/network/message/observable.d.ts +5 -0
- package/dist/network/message/observable.js +103 -0
- package/dist/network/message/observable.js.map +1 -0
- package/dist/network/message/send.d.ts +4 -0
- package/dist/network/message/send.js +11 -0
- package/dist/network/message/send.js.map +1 -0
- package/dist/network/upgrade.d.ts +4 -0
- package/dist/network/upgrade.js +49 -0
- package/dist/network/upgrade.js.map +1 -0
- package/dist/network/worker/get.d.ts +0 -0
- package/dist/network/worker/get.js +122 -0
- package/dist/network/worker/get.js.map +1 -0
- package/dist/network/worker/observable.d.ts +0 -0
- package/dist/network/worker/observable.js +120 -0
- package/dist/network/worker/observable.js.map +1 -0
- package/dist/observable/index.d.ts +8 -0
- package/dist/observable/index.js +154 -0
- package/dist/observable/index.js.map +1 -0
- package/dist/protocol.d.ts +19 -0
- package/dist/protocol.js +212 -0
- package/dist/protocol.js.map +1 -0
- package/dist/security/index.d.ts +2 -0
- package/dist/security/index.js +57 -0
- package/dist/security/index.js.map +1 -0
- package/dist/server.d.ts +35 -0
- package/dist/server.js +99 -0
- package/dist/server.js.map +1 -0
- package/dist/worker/authorize.d.ts +5 -0
- package/dist/worker/authorize.js +15 -0
- package/dist/worker/authorize.js.map +1 -0
- package/dist/worker/fnMap.d.ts +2 -0
- package/dist/worker/fnMap.js +5 -0
- package/dist/worker/fnMap.js.map +1 -0
- package/dist/worker/functions.d.ts +3 -0
- package/dist/worker/functions.js +8 -0
- package/dist/worker/functions.js.map +1 -0
- package/dist/worker/http/function.d.ts +4 -0
- package/dist/worker/http/function.js +75 -0
- package/dist/worker/http/function.js.map +1 -0
- package/dist/worker/index.d.ts +1 -0
- package/dist/worker/index.js +101 -0
- package/dist/worker/index.js.map +1 -0
- package/dist/worker/observable.d.ts +15 -0
- package/dist/worker/observable.js +110 -0
- package/dist/worker/observable.js.map +1 -0
- package/dist/worker/ws/function.d.ts +3 -0
- package/dist/worker/ws/function.js +42 -0
- package/dist/worker/ws/function.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,399 @@
|
|
|
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
|
+
const observable_1 = require("../observable");
|
|
9
|
+
const node_worker_threads_1 = require("node:worker_threads");
|
|
10
|
+
const path_1 = require("path");
|
|
11
|
+
let reqId = 0;
|
|
12
|
+
const WORKER_PATH = (0, path_1.join)(__dirname, '../worker');
|
|
13
|
+
class BasedFunctions {
|
|
14
|
+
constructor(server, config) {
|
|
15
|
+
this.workers = [];
|
|
16
|
+
this.workerResponseListeners = new Map();
|
|
17
|
+
this.paths = {};
|
|
18
|
+
this.observables = {};
|
|
19
|
+
this.functions = {};
|
|
20
|
+
this.beingUninstalled = {};
|
|
21
|
+
this.server = server;
|
|
22
|
+
if (config) {
|
|
23
|
+
this.updateConfig(config);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
workerSortLoop() {
|
|
27
|
+
// or something else?
|
|
28
|
+
// this.workerSortTimeout
|
|
29
|
+
}
|
|
30
|
+
uninstallLoop() {
|
|
31
|
+
this.unregisterTimeout = setTimeout(async () => {
|
|
32
|
+
const q = [];
|
|
33
|
+
for (const name in this.functions) {
|
|
34
|
+
const spec = this.functions[name];
|
|
35
|
+
if ((0, timeout_1.fnIsTimedOut)(spec)) {
|
|
36
|
+
q.push(this.uninstall(name, spec));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
for (const name in this.observables) {
|
|
40
|
+
const spec = this.observables[name];
|
|
41
|
+
if (this.server.activeObservables[name]) {
|
|
42
|
+
(0, timeout_1.updateTimeoutCounter)(spec);
|
|
43
|
+
}
|
|
44
|
+
else if ((0, timeout_1.fnIsTimedOut)(spec)) {
|
|
45
|
+
q.push(this.uninstall(name, spec));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
await Promise.all(q);
|
|
49
|
+
this.uninstallLoop();
|
|
50
|
+
}, 3e3);
|
|
51
|
+
}
|
|
52
|
+
updateConfig(config) {
|
|
53
|
+
if (this.config) {
|
|
54
|
+
(0, utils_1.deepMerge)(this.config, config);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this.config = config;
|
|
58
|
+
}
|
|
59
|
+
if (this.config.idleTimeout === undefined) {
|
|
60
|
+
this.config.idleTimeout = 60e3; // 1 min
|
|
61
|
+
}
|
|
62
|
+
if (this.config.memCacheTimeout === undefined) {
|
|
63
|
+
this.config.memCacheTimeout = 3e3;
|
|
64
|
+
}
|
|
65
|
+
if (this.config.maxWorkers === undefined) {
|
|
66
|
+
this.config.maxWorkers = 1;
|
|
67
|
+
}
|
|
68
|
+
if (this.config.log === undefined) {
|
|
69
|
+
this.config.log = (opts) => {
|
|
70
|
+
console.info(opts);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (this.unregisterTimeout) {
|
|
74
|
+
clearTimeout(this.unregisterTimeout);
|
|
75
|
+
}
|
|
76
|
+
const d = this.config.maxWorkers - this.workers.length;
|
|
77
|
+
// clean all this stuff up.....
|
|
78
|
+
if (d !== 0) {
|
|
79
|
+
if (d < 0) {
|
|
80
|
+
for (let i = 0; i < d; i++) {
|
|
81
|
+
// active into account
|
|
82
|
+
const w = this.workers.pop();
|
|
83
|
+
w.worker.terminate();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
for (let i = 0; i < d; i++) {
|
|
88
|
+
const worker = new node_worker_threads_1.Worker(WORKER_PATH, {});
|
|
89
|
+
this.workers.push({
|
|
90
|
+
worker,
|
|
91
|
+
index: this.workers.length,
|
|
92
|
+
activeObservables: 0,
|
|
93
|
+
activeFunctions: 0,
|
|
94
|
+
});
|
|
95
|
+
if (this.server.auth) {
|
|
96
|
+
// allways install authorize
|
|
97
|
+
worker.postMessage({
|
|
98
|
+
type: 5,
|
|
99
|
+
name: 'authorize',
|
|
100
|
+
path: this.server.auth.config.authorizePath,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
worker.on('message', (data) => {
|
|
104
|
+
// type 0 is just install fn
|
|
105
|
+
// subscribe and close will just go the normal way
|
|
106
|
+
if (data.type === 0) {
|
|
107
|
+
this.install(data.name)
|
|
108
|
+
.then((spec) => {
|
|
109
|
+
if (spec) {
|
|
110
|
+
worker.postMessage({
|
|
111
|
+
type: 5,
|
|
112
|
+
name: spec.name,
|
|
113
|
+
path: spec.functionPath,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
worker.postMessage({
|
|
118
|
+
type: 7,
|
|
119
|
+
name: data.name,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
.catch(() => {
|
|
124
|
+
worker.postMessage({
|
|
125
|
+
type: 7,
|
|
126
|
+
name: data.name,
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
else if (data.id) {
|
|
131
|
+
const listener = this.workerResponseListeners.get(data.id);
|
|
132
|
+
// prob need more here
|
|
133
|
+
if (listener) {
|
|
134
|
+
listener(data.err, data.payload);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (this.workers.length === 0) {
|
|
142
|
+
throw new Error('Needs at least 1 worker');
|
|
143
|
+
}
|
|
144
|
+
this.lowestWorker = this.workers.sort((a, b) => {
|
|
145
|
+
// will be RATE LIMIT TOKEN
|
|
146
|
+
return a.activeFunctions < b.activeFunctions
|
|
147
|
+
? -1
|
|
148
|
+
: a.activeFunctions === b.activeFunctions
|
|
149
|
+
? 0
|
|
150
|
+
: 1;
|
|
151
|
+
})[0];
|
|
152
|
+
this.uninstallLoop();
|
|
153
|
+
}
|
|
154
|
+
async install(name) {
|
|
155
|
+
let spec = this.getFromStore(name);
|
|
156
|
+
if (spec) {
|
|
157
|
+
return spec;
|
|
158
|
+
}
|
|
159
|
+
spec = await this.config.install({
|
|
160
|
+
server: this.server,
|
|
161
|
+
name,
|
|
162
|
+
});
|
|
163
|
+
if (spec) {
|
|
164
|
+
this.update(spec);
|
|
165
|
+
return this.getFromStore(name);
|
|
166
|
+
}
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
getNameFromPath(path) {
|
|
170
|
+
return this.paths[path];
|
|
171
|
+
}
|
|
172
|
+
route(name, path) {
|
|
173
|
+
const result = this.config.route({ server: this.server, name, path });
|
|
174
|
+
if (result && !result.maxPayloadSize) {
|
|
175
|
+
if (result.observable) {
|
|
176
|
+
// 50kb
|
|
177
|
+
result.maxPayloadSize = 50000;
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
if (result.stream) {
|
|
181
|
+
result.maxPayloadSize = -1;
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
result.maxPayloadSize = 250000;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return result;
|
|
189
|
+
}
|
|
190
|
+
getFromStore(name) {
|
|
191
|
+
const spec = this.observables[name] || this.functions[name];
|
|
192
|
+
if (spec) {
|
|
193
|
+
if (this.beingUninstalled[name]) {
|
|
194
|
+
console.info('getFromStore is being uninstalled', name);
|
|
195
|
+
delete this.beingUninstalled[name];
|
|
196
|
+
}
|
|
197
|
+
(0, timeout_1.updateTimeoutCounter)(spec);
|
|
198
|
+
return spec;
|
|
199
|
+
}
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
update(spec) {
|
|
203
|
+
// force uninstall in workers (and clear require cache - so it hopefully re-evaluates authorize etc)
|
|
204
|
+
// will make the 'call' function to be able to call a user defined authorize
|
|
205
|
+
if (spec) {
|
|
206
|
+
if (!spec.idleTimeout) {
|
|
207
|
+
spec.idleTimeout = this.config.idleTimeout;
|
|
208
|
+
}
|
|
209
|
+
if (spec.timeoutCounter === undefined) {
|
|
210
|
+
spec.timeoutCounter =
|
|
211
|
+
spec.idleTimeout === 0 ? -1 : Math.ceil(spec.idleTimeout / 1e3);
|
|
212
|
+
}
|
|
213
|
+
if (spec.path) {
|
|
214
|
+
this.paths[spec.path] = spec.name;
|
|
215
|
+
}
|
|
216
|
+
if ((0, types_1.isObservableFunctionSpec)(spec)) {
|
|
217
|
+
if (this.functions[spec.name]) {
|
|
218
|
+
this.remove(spec.name);
|
|
219
|
+
}
|
|
220
|
+
else if (this.observables[spec.name]) {
|
|
221
|
+
for (const w of this.workers) {
|
|
222
|
+
w.worker.postMessage({
|
|
223
|
+
type: 6,
|
|
224
|
+
name: spec.name,
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
this.observables[spec.name] = spec;
|
|
229
|
+
if (this.server.activeObservables[spec.name]) {
|
|
230
|
+
for (const [id] of this.server.activeObservables[spec.name]) {
|
|
231
|
+
(0, observable_1.initFunction)(this.server, id);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
if (this.observables[spec.name]) {
|
|
237
|
+
this.remove(spec.name);
|
|
238
|
+
}
|
|
239
|
+
else if (this.functions[spec.name]) {
|
|
240
|
+
for (const w of this.workers) {
|
|
241
|
+
w.worker.postMessage({
|
|
242
|
+
type: 6,
|
|
243
|
+
name: spec.name,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
this.functions[spec.name] = spec;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
remove(name) {
|
|
253
|
+
// Does not call unregister!
|
|
254
|
+
if (this.observables[name]) {
|
|
255
|
+
if (this.observables[name].path) {
|
|
256
|
+
delete this.paths[this.observables[name].path];
|
|
257
|
+
}
|
|
258
|
+
delete this.observables[name];
|
|
259
|
+
const activeObs = this.server.activeObservables[name];
|
|
260
|
+
if (activeObs) {
|
|
261
|
+
for (const [id] of activeObs) {
|
|
262
|
+
(0, observable_1.destroy)(this.server, id);
|
|
263
|
+
}
|
|
264
|
+
delete this.server.activeObservables[name];
|
|
265
|
+
}
|
|
266
|
+
// this is a bit harder... not allways relevant
|
|
267
|
+
for (const w of this.workers) {
|
|
268
|
+
w.worker.postMessage({
|
|
269
|
+
type: 6,
|
|
270
|
+
name,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
return true;
|
|
274
|
+
}
|
|
275
|
+
else if (this.functions[name]) {
|
|
276
|
+
if (this.functions[name].path) {
|
|
277
|
+
delete this.paths[this.functions[name].path];
|
|
278
|
+
}
|
|
279
|
+
delete this.functions[name];
|
|
280
|
+
for (const w of this.workers) {
|
|
281
|
+
w.worker.postMessage({
|
|
282
|
+
type: 6,
|
|
283
|
+
name,
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
async uninstall(name, spec) {
|
|
291
|
+
if (this.beingUninstalled[name]) {
|
|
292
|
+
console.error('Allready being unregistered...', name);
|
|
293
|
+
}
|
|
294
|
+
if (!spec && spec !== false) {
|
|
295
|
+
spec = this.getFromStore(name);
|
|
296
|
+
}
|
|
297
|
+
if (spec) {
|
|
298
|
+
this.beingUninstalled[name] = true;
|
|
299
|
+
if (await this.config.uninstall({
|
|
300
|
+
server: this.server,
|
|
301
|
+
function: spec,
|
|
302
|
+
name,
|
|
303
|
+
})) {
|
|
304
|
+
if (this.beingUninstalled[name]) {
|
|
305
|
+
delete this.beingUninstalled[name];
|
|
306
|
+
return this.remove(name);
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
console.info('got requested while being unregistered', name);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
// from other worker fn
|
|
316
|
+
runObservableFunction(spec, id, error, update, payload) {
|
|
317
|
+
// TODO: move selection criteria etc to other file
|
|
318
|
+
const selectedWorker = this.lowestWorker;
|
|
319
|
+
this.workerResponseListeners.set(id, (err, p) => {
|
|
320
|
+
if (err) {
|
|
321
|
+
error(err);
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
update(p.diff, p.data, p.checksum, p.isDeflate);
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
selectedWorker.worker.postMessage({
|
|
328
|
+
type: 1,
|
|
329
|
+
id,
|
|
330
|
+
name: spec.name,
|
|
331
|
+
path: spec.functionPath,
|
|
332
|
+
payload,
|
|
333
|
+
});
|
|
334
|
+
return () => {
|
|
335
|
+
this.workerResponseListeners.delete(id);
|
|
336
|
+
selectedWorker.worker.postMessage({
|
|
337
|
+
id,
|
|
338
|
+
type: 2,
|
|
339
|
+
});
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
async runFunction(type,
|
|
343
|
+
// 0 is normal function WS
|
|
344
|
+
// 3 is POST payload
|
|
345
|
+
// 4 is GET payload
|
|
346
|
+
spec, context, // make this specific
|
|
347
|
+
payload) {
|
|
348
|
+
// TODO: move selection criteria etc to other file
|
|
349
|
+
return new Promise((resolve, reject) => {
|
|
350
|
+
const listenerId = ++reqId;
|
|
351
|
+
// max concurrent execution is 1 mil...
|
|
352
|
+
if (this.workerResponseListeners.size >= 1e6) {
|
|
353
|
+
throw new Error('MAX CONCURRENT SERVER FUNCTION EXECUTION REACHED (1 MIL)');
|
|
354
|
+
}
|
|
355
|
+
if (reqId > 1e6) {
|
|
356
|
+
reqId = 0;
|
|
357
|
+
}
|
|
358
|
+
const selectedWorker = this.lowestWorker;
|
|
359
|
+
this.workerResponseListeners.set(listenerId, (err, p) => {
|
|
360
|
+
this.workerResponseListeners.delete(listenerId);
|
|
361
|
+
// include observables
|
|
362
|
+
selectedWorker.activeFunctions--;
|
|
363
|
+
if (selectedWorker.activeFunctions < this.lowestWorker.activeFunctions) {
|
|
364
|
+
this.lowestWorker = selectedWorker;
|
|
365
|
+
}
|
|
366
|
+
if (err) {
|
|
367
|
+
reject(err);
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
// prob shared array buffer...
|
|
371
|
+
resolve(p);
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
selectedWorker.activeFunctions++;
|
|
375
|
+
let next = selectedWorker.index + 1;
|
|
376
|
+
if (next >= this.workers.length) {
|
|
377
|
+
next = 0;
|
|
378
|
+
}
|
|
379
|
+
if (selectedWorker.activeFunctions > this.workers[next].activeFunctions) {
|
|
380
|
+
this.lowestWorker = this.workers[next];
|
|
381
|
+
}
|
|
382
|
+
selectedWorker.worker.postMessage({
|
|
383
|
+
type,
|
|
384
|
+
path: spec.functionPath,
|
|
385
|
+
name: spec.name,
|
|
386
|
+
payload,
|
|
387
|
+
context,
|
|
388
|
+
id: listenerId,
|
|
389
|
+
});
|
|
390
|
+
// console.info(
|
|
391
|
+
// 'SPEED',
|
|
392
|
+
// selectedWorker.worker.threadId,
|
|
393
|
+
// selectedWorker.worker.performance.eventLoopUtilization()
|
|
394
|
+
// )
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
exports.BasedFunctions = BasedFunctions;
|
|
399
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":";;;AACA,oCAMiB;AAiBR,yGAlBP,gCAAwB,OAkBO;AAhBjC,wCAAwC;AACxC,uCAA8D;AAC9D,8CAAqD;AACrD,6DAA4C;AAC5C,+BAA2B;AAc3B,IAAI,KAAK,GAAG,CAAC,CAAA;AAEb,MAAM,WAAW,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,WAAW,CAAC,CAAA;AAEhD,MAAa,cAAc;IA6BzB,YAAY,MAAmB,EAAE,MAAuB;QAtBxD,YAAO,GAAkB,EAAE,CAAA;QAE3B,4BAAuB,GAA8C,IAAI,GAAG,EAAE,CAAA;QAE9E,UAAK,GAED,EAAE,CAAA;QAEN,gBAAW,GAEP,EAAE,CAAA;QAEN,cAAS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,IAAI,CAAC,CAAA;aACvC;YACD,cAAc,CAAC,MAAM,CAAC,WAAW,CAAC;gBAChC,IAAI;gBACJ,IAAI,EAAE,IAAI,CAAC,YAAY;gBACvB,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,OAAO;gBACP,OAAO;gBACP,EAAE,EAAE,UAAU;aACf,CAAC,CAAA;YACF,gBAAgB;YAChB,aAAa;YACb,oCAAoC;YACpC,6DAA6D;YAC7D,IAAI;QACN,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AApcD,wCAocC"}
|
|
@@ -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) => 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.timeoutCounter === 0) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
if (spec.idleTimeout > 0 && spec.timeoutCounter > 0) {
|
|
10
|
+
spec.timeoutCounter--;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
};
|
|
15
|
+
exports.fnIsTimedOut = fnIsTimedOut;
|
|
16
|
+
const updateTimeoutCounter = (spec) => {
|
|
17
|
+
if (spec.timeoutCounter !== -1) {
|
|
18
|
+
spec.timeoutCounter =
|
|
19
|
+
spec.idleTimeout === -1 ? -1 : Math.ceil(spec.idleTimeout / 1e3 / 3);
|
|
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,cAAc,KAAK,CAAC,EAAE;YAC7B,OAAO,IAAI,CAAA;SACZ;QACD,IAAI,IAAI,CAAC,WAAW,GAAG,CAAC,IAAI,IAAI,CAAC,cAAc,GAAG,CAAC,EAAE;YACnD,IAAI,CAAC,cAAc,EAAE,CAAA;SACtB;KACF;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAZY,QAAA,YAAY,gBAYxB;AAEM,MAAM,oBAAoB,GAAG,CAClC,IAAqD,EACrD,EAAE;IACF,IAAI,IAAI,CAAC,cAAc,KAAK,CAAC,CAAC,EAAE;QAC9B,IAAI,CAAC,cAAc;YACjB,IAAI,CAAC,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,GAAG,GAAG,GAAG,CAAC,CAAC,CAAA;KACvE;AACH,CAAC,CAAA;AAPY,QAAA,oBAAoB,wBAOhC"}
|
|
File without changes
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// add a few worker also handle errors of observables
|
|
2
|
+
// think about making a dedicated worker for based client
|
|
3
|
+
// also make a thing 'sticky worker'
|
|
4
|
+
// cant get the server in a function like this , also not the client just PAYLOAD / OUTGOING PAYLOAD - outgoing
|
|
5
|
+
//# sourceMappingURL=workerPool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workerPool.js","sourceRoot":"","sources":["../../src/functions/workerPool.ts"],"names":[],"mappings":"AAAA,qDAAqD;AAErD,yDAAyD;AACzD,oCAAoC;AAEpC,+GAA+G"}
|
|
@@ -5,30 +5,40 @@ exports.default = async (server, stream, opts, user) => {
|
|
|
5
5
|
if (!storeFile) {
|
|
6
6
|
throw new Error('No file upload handler available!');
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
8
|
+
try {
|
|
9
|
+
const result = await storeFile({
|
|
10
|
+
based: server.based,
|
|
11
|
+
stream,
|
|
12
|
+
id: opts.id,
|
|
13
|
+
mimeType: opts.type,
|
|
14
|
+
extension: opts.extension,
|
|
15
|
+
size: opts.size,
|
|
16
|
+
user,
|
|
17
|
+
});
|
|
18
|
+
const setObj = {
|
|
19
|
+
$id: opts.id,
|
|
20
|
+
src: result.src,
|
|
21
|
+
origin: result.origin,
|
|
22
|
+
status: result.status,
|
|
23
|
+
version: result.version,
|
|
24
|
+
mimeType: result.mimeType || opts.type,
|
|
25
|
+
};
|
|
26
|
+
if (result.thumb) {
|
|
27
|
+
setObj.thumb = result.thumb;
|
|
28
|
+
}
|
|
29
|
+
if (result.statusText) {
|
|
30
|
+
setObj.statusText = result.statusText;
|
|
31
|
+
}
|
|
32
|
+
// add version
|
|
33
|
+
server.based.set(setObj);
|
|
27
34
|
}
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
catch (err) {
|
|
36
|
+
console.error('Could not upload file, error:\n', err);
|
|
37
|
+
server.based.set({
|
|
38
|
+
$id: opts.id,
|
|
39
|
+
status: 4,
|
|
40
|
+
statusText: 'error',
|
|
41
|
+
});
|
|
30
42
|
}
|
|
31
|
-
// add version
|
|
32
|
-
server.based.set(setObj);
|
|
33
43
|
};
|
|
34
44
|
//# sourceMappingURL=storeFile.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storeFile.js","sourceRoot":"","sources":["../../../../src/handlers/rest/file/storeFile.ts"],"names":[],"mappings":";;AAKA,kBAAe,KAAK,EAClB,MAAmB,EACnB,MAAgB,EAChB,IAAiB,EACjB,IAAY,EACG,EAAE;IACjB,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAA;IAEzC,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAA;KACrD;IAED,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"storeFile.js","sourceRoot":"","sources":["../../../../src/handlers/rest/file/storeFile.ts"],"names":[],"mappings":";;AAKA,kBAAe,KAAK,EAClB,MAAmB,EACnB,MAAgB,EAChB,IAAiB,EACjB,IAAY,EACG,EAAE;IACjB,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAA;IAEzC,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAA;KACrD;IAED,IAAI;QACF,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC;YAC7B,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,MAAM;YACN,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,QAAQ,EAAE,IAAI,CAAC,IAAI;YACnB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI;SACL,CAAC,CAAA;QAEF,MAAM,MAAM,GAAQ;YAClB,GAAG,EAAE,IAAI,CAAC,EAAE;YACZ,GAAG,EAAE,MAAM,CAAC,GAAG;YACf,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC,IAAI;SACvC,CAAA;QAED,IAAI,MAAM,CAAC,KAAK,EAAE;YAChB,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAA;SAC5B;QAED,IAAI,MAAM,CAAC,UAAU,EAAE;YACrB,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;SACtC;QAED,cAAc;QACd,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;KACzB;IAAC,OAAO,GAAG,EAAE;QACZ,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,GAAG,CAAC,CAAA;QACrD,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC;YACf,GAAG,EAAE,IAAI,CAAC,EAAE;YACZ,MAAM,EAAE,CAAC;YACT,UAAU,EAAE,OAAO;SACpB,CAAC,CAAA;KACH;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { BasedServer } from '../../server';
|
|
2
|
+
import { BasedFunctionRoute, HttpClient } from '../../types';
|
|
3
|
+
export declare const authorizeRequest: (server: BasedServer, client: HttpClient, payload: any, route: BasedFunctionRoute, authorized: (payload: any) => void) => void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.authorizeRequest = void 0;
|
|
4
|
+
const send_1 = require("./send");
|
|
5
|
+
const error_1 = require("../../error");
|
|
6
|
+
const authorizeRequest = (server, client, payload, route, authorized) => {
|
|
7
|
+
server.auth
|
|
8
|
+
.authorize(client.context, route.name, payload)
|
|
9
|
+
.then((ok) => {
|
|
10
|
+
if (!client.res) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (!ok) {
|
|
14
|
+
(0, send_1.sendHttpError)(server, client, error_1.BasedErrorCode.AuthorizeRejectedError, route);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
authorized(payload);
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
.catch((err) => {
|
|
21
|
+
(0, send_1.sendHttpError)(server, client, error_1.BasedErrorCode.AuthorizeFunctionError, {
|
|
22
|
+
route,
|
|
23
|
+
err,
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
exports.authorizeRequest = authorizeRequest;
|
|
28
|
+
//# sourceMappingURL=authorize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorize.js","sourceRoot":"","sources":["../../../src/network/http/authorize.ts"],"names":[],"mappings":";;;AAEA,iCAAsC;AACtC,uCAA4C;AAErC,MAAM,gBAAgB,GAAG,CAC9B,MAAmB,EACnB,MAAkB,EAClB,OAAY,EACZ,KAAyB,EACzB,UAAkC,EAClC,EAAE;IACF,MAAM,CAAC,IAAI;SACR,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC;SAC9C,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE;QACX,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;YACf,OAAM;SACP;QACD,IAAI,CAAC,EAAE,EAAE;YACP,IAAA,oBAAa,EACX,MAAM,EACN,MAAM,EACN,sBAAc,CAAC,sBAAsB,EACrC,KAAK,CACN,CAAA;SACF;aAAM;YACL,UAAU,CAAC,OAAO,CAAC,CAAA;SACpB;IACH,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACb,IAAA,oBAAa,EAAC,MAAM,EAAE,MAAM,EAAE,sBAAc,CAAC,sBAAsB,EAAE;YACnE,KAAK;YACL,GAAG;SACJ,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACN,CAAC,CAAA;AA9BY,QAAA,gBAAgB,oBA8B5B"}
|
|
@@ -0,0 +1,56 @@
|
|
|
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.compress = void 0;
|
|
7
|
+
const node_zlib_1 = __importDefault(require("node:zlib"));
|
|
8
|
+
const node_util_1 = require("node:util");
|
|
9
|
+
const protocol_1 = require("../../protocol");
|
|
10
|
+
const deflate = (0, node_util_1.promisify)(node_zlib_1.default.deflate);
|
|
11
|
+
const gzip = (0, node_util_1.promisify)(node_zlib_1.default.gzip);
|
|
12
|
+
const br = (0, node_util_1.promisify)(node_zlib_1.default.brotliCompress);
|
|
13
|
+
/*
|
|
14
|
+
Content-Encoding: gzip
|
|
15
|
+
Content-Encoding: compress
|
|
16
|
+
Content-Encoding: deflate
|
|
17
|
+
Content-Encoding: br
|
|
18
|
+
*/
|
|
19
|
+
const COMPRESS_STRING_LEN = Math.ceil(protocol_1.COMPRESS_FROM_BYTES / 1.5);
|
|
20
|
+
const compress = async (client, payload) => {
|
|
21
|
+
if (!client.res) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const encoding = client.context.headers.encoding;
|
|
25
|
+
if (payload instanceof Buffer && payload.byteLength <= protocol_1.COMPRESS_FROM_BYTES) {
|
|
26
|
+
return { payload };
|
|
27
|
+
}
|
|
28
|
+
if (payload.length < COMPRESS_STRING_LEN) {
|
|
29
|
+
return { payload };
|
|
30
|
+
}
|
|
31
|
+
if (encoding && typeof encoding === 'string') {
|
|
32
|
+
let responseEncoding;
|
|
33
|
+
let compressed;
|
|
34
|
+
if (!(payload instanceof Buffer)) {
|
|
35
|
+
payload = Buffer.from(payload);
|
|
36
|
+
}
|
|
37
|
+
if (encoding.includes('deflate')) {
|
|
38
|
+
responseEncoding = 'deflate';
|
|
39
|
+
compressed = await deflate(payload);
|
|
40
|
+
}
|
|
41
|
+
else if (encoding.includes('gzip')) {
|
|
42
|
+
responseEncoding = 'gzip';
|
|
43
|
+
compressed = await gzip(payload);
|
|
44
|
+
}
|
|
45
|
+
else if (encoding.includes('br')) {
|
|
46
|
+
responseEncoding = 'br';
|
|
47
|
+
compressed = await br(payload);
|
|
48
|
+
}
|
|
49
|
+
if (compressed) {
|
|
50
|
+
return { payload: compressed, encoding: responseEncoding };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return { payload };
|
|
54
|
+
};
|
|
55
|
+
exports.compress = compress;
|
|
56
|
+
//# sourceMappingURL=compress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compress.js","sourceRoot":"","sources":["../../../src/network/http/compress.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAC5B,yCAAqC;AAErC,6CAAoD;AAEpD,MAAM,OAAO,GAAG,IAAA,qBAAS,EAAC,mBAAI,CAAC,OAAO,CAAC,CAAA;AACvC,MAAM,IAAI,GAAG,IAAA,qBAAS,EAAC,mBAAI,CAAC,IAAI,CAAC,CAAA;AACjC,MAAM,EAAE,GAAG,IAAA,qBAAS,EAAC,mBAAI,CAAC,cAAc,CAAC,CAAA;AAEzC;;;;;EAKE;AAEF,MAAM,mBAAmB,GAAG,IAAI,CAAC,IAAI,CAAC,8BAAmB,GAAG,GAAG,CAAC,CAAA;AAEzD,MAAM,QAAQ,GAAG,KAAK,EAC3B,MAAkB,EAClB,OAAwB,EACkC,EAAE;IAC5D,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;QACf,OAAM;KACP;IAED,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAA;IAEhD,IAAI,OAAO,YAAY,MAAM,IAAI,OAAO,CAAC,UAAU,IAAI,8BAAmB,EAAE;QAC1E,OAAO,EAAE,OAAO,EAAE,CAAA;KACnB;IAED,IAAI,OAAO,CAAC,MAAM,GAAG,mBAAmB,EAAE;QACxC,OAAO,EAAE,OAAO,EAAE,CAAA;KACnB;IAED,IAAI,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;QAC5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