@based/server 3.4.6 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.js +173 -0
- package/dist/api/index.js.map +1 -0
- 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 +8 -0
- package/dist/auth/dummyAuth.js.map +1 -0
- package/dist/auth/index.d.ts +15 -0
- package/dist/auth/index.js +49 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/parseAuthState.d.ts +2 -0
- package/dist/auth/parseAuthState.js +16 -0
- package/dist/auth/parseAuthState.js.map +1 -0
- package/dist/auth/types.d.ts +10 -0
- package/dist/auth/types.js +3 -0
- package/dist/auth/types.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/compress.d.ts +5 -0
- package/dist/compress.js +52 -0
- package/dist/compress.js.map +1 -0
- package/dist/context.d.ts +54 -0
- package/dist/context.js +18 -0
- package/dist/context.js.map +1 -0
- package/dist/createSimpleServer.d.ts +22 -0
- package/dist/createSimpleServer.js +120 -0
- package/dist/createSimpleServer.js.map +1 -0
- package/dist/error/errorTypeHandlers.d.ts +6 -0
- package/dist/error/errorTypeHandlers.js +130 -0
- package/dist/error/errorTypeHandlers.js.map +1 -0
- package/dist/error/index.d.ts +5 -0
- package/dist/error/index.js +61 -0
- package/dist/error/index.js.map +1 -0
- package/dist/error/types.d.ts +105 -0
- package/dist/error/types.js +30 -0
- package/dist/error/types.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 +34 -0
- package/dist/functions/index.js +210 -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/types.d.ts +67 -0
- package/dist/functions/types.js +15 -0
- package/dist/functions/types.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/configuration/index.d.ts +1 -1
- package/dist/incoming/http/authorize.d.ts +4 -0
- package/dist/incoming/http/authorize.js +37 -0
- package/dist/incoming/http/authorize.js.map +1 -0
- package/dist/incoming/http/function.d.ts +4 -0
- package/dist/incoming/http/function.js +47 -0
- package/dist/incoming/http/function.js.map +1 -0
- package/dist/incoming/http/get.d.ts +4 -0
- package/dist/incoming/http/get.js +155 -0
- package/dist/incoming/http/get.js.map +1 -0
- package/dist/incoming/http/index.d.ts +3 -0
- package/dist/incoming/http/index.js +134 -0
- package/dist/incoming/http/index.js.map +1 -0
- package/dist/incoming/http/parseQuery.d.ts +4 -0
- package/dist/incoming/http/parseQuery.js +25 -0
- package/dist/incoming/http/parseQuery.js.map +1 -0
- package/dist/incoming/http/readBody.d.ts +4 -0
- package/dist/incoming/http/readBody.js +107 -0
- package/dist/incoming/http/readBody.js.map +1 -0
- package/dist/incoming/http/streamFunction/DataStream.d.ts +7 -0
- package/dist/incoming/http/streamFunction/DataStream.js +19 -0
- package/dist/incoming/http/streamFunction/DataStream.js.map +1 -0
- package/dist/incoming/http/streamFunction/getExtension.d.ts +2 -0
- package/dist/incoming/http/streamFunction/getExtension.js +29 -0
- package/dist/incoming/http/streamFunction/getExtension.js.map +1 -0
- package/dist/incoming/http/streamFunction/index.d.ts +4 -0
- package/dist/incoming/http/streamFunction/index.js +106 -0
- package/dist/incoming/http/streamFunction/index.js.map +1 -0
- package/dist/incoming/http/streamFunction/multipartStream.d.ts +13 -0
- package/dist/incoming/http/streamFunction/multipartStream.js +208 -0
- package/dist/incoming/http/streamFunction/multipartStream.js.map +1 -0
- package/dist/incoming/http/streamFunction/stream.d.ts +6 -0
- package/dist/incoming/http/streamFunction/stream.js +108 -0
- package/dist/incoming/http/streamFunction/stream.js.map +1 -0
- package/dist/incoming/index.d.ts +3 -0
- package/dist/incoming/index.js +84 -0
- package/dist/incoming/index.js.map +1 -0
- package/dist/incoming/upgrade.d.ts +4 -0
- package/dist/incoming/upgrade.js +64 -0
- package/dist/incoming/upgrade.js.map +1 -0
- package/dist/incoming/ws/auth.d.ts +5 -0
- package/dist/incoming/ws/auth.js +40 -0
- package/dist/incoming/ws/auth.js.map +1 -0
- package/dist/incoming/ws/function.d.ts +3 -0
- package/dist/incoming/ws/function.js +107 -0
- package/dist/incoming/ws/function.js.map +1 -0
- package/dist/incoming/ws/get.d.ts +3 -0
- package/dist/incoming/ws/get.js +136 -0
- package/dist/incoming/ws/get.js.map +1 -0
- package/dist/incoming/ws/index.d.ts +3 -0
- package/dist/incoming/ws/index.js +61 -0
- package/dist/incoming/ws/index.js.map +1 -0
- package/dist/incoming/ws/observable.d.ts +6 -0
- package/dist/incoming/ws/observable.js +112 -0
- package/dist/incoming/ws/observable.js.map +1 -0
- package/dist/index.d.ts +11 -35
- package/dist/index.js +19 -196
- package/dist/index.js.map +1 -1
- package/dist/ip.d.ts +2 -0
- package/dist/ip.js +8 -0
- package/dist/ip.js.map +1 -0
- 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/create.d.ts +3 -0
- package/dist/observable/create.js +30 -0
- package/dist/observable/create.js.map +1 -0
- package/dist/observable/destroy.d.ts +2 -0
- package/dist/observable/destroy.js +51 -0
- package/dist/observable/destroy.js.map +1 -0
- package/dist/observable/error.d.ts +4 -0
- package/dist/observable/error.js +17 -0
- package/dist/observable/error.js.map +1 -0
- package/dist/observable/extendCache.d.ts +2 -0
- package/dist/observable/extendCache.js +11 -0
- package/dist/observable/extendCache.js.map +1 -0
- package/dist/observable/genObservableId.d.ts +1 -0
- package/dist/observable/genObservableId.js +9 -0
- package/dist/observable/genObservableId.js.map +1 -0
- package/dist/observable/get.d.ts +4 -0
- package/dist/observable/get.js +15 -0
- package/dist/observable/get.js.map +1 -0
- package/dist/observable/index.d.ts +11 -0
- package/dist/observable/index.js +28 -0
- package/dist/observable/index.js.map +1 -0
- package/dist/observable/send.d.ts +6 -0
- package/dist/observable/send.js +32 -0
- package/dist/observable/send.js.map +1 -0
- package/dist/observable/start/error.d.ts +3 -0
- package/dist/observable/start/error.js +36 -0
- package/dist/observable/start/error.js.map +1 -0
- package/dist/observable/start/index.d.ts +2 -0
- package/dist/observable/start/index.js +46 -0
- package/dist/observable/start/index.js.map +1 -0
- package/dist/observable/start/update.d.ts +6 -0
- package/dist/observable/start/update.js +104 -0
- package/dist/observable/start/update.js.map +1 -0
- package/dist/observable/subscribe.d.ts +7 -0
- package/dist/observable/subscribe.js +54 -0
- package/dist/observable/subscribe.js.map +1 -0
- package/dist/observable/types.d.ts +26 -0
- package/dist/observable/types.js +3 -0
- package/dist/observable/types.js.map +1 -0
- package/dist/observable/unsub.d.ts +6 -0
- package/dist/observable/unsub.js +43 -0
- package/dist/observable/unsub.js.map +1 -0
- package/dist/observable/verify.d.ts +4 -0
- package/dist/observable/verify.js +18 -0
- package/dist/observable/verify.js.map +1 -0
- package/dist/protocol.d.ts +21 -0
- package/dist/protocol.js +233 -0
- package/dist/protocol.js.map +1 -0
- package/dist/security/index.d.ts +3 -0
- package/dist/security/index.js +66 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security.d.ts +6 -0
- package/dist/security.js +95 -0
- package/dist/security.js.map +1 -0
- package/dist/sendError.d.ts +5 -0
- package/dist/sendError.js +42 -0
- package/dist/sendError.js.map +1 -0
- package/dist/sendHttpResponse.d.ts +4 -0
- package/dist/sendHttpResponse.js +53 -0
- package/dist/sendHttpResponse.js.map +1 -0
- package/dist/server.d.ts +69 -0
- package/dist/server.js +113 -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 +16 -14
package/dist/index.js
CHANGED
|
@@ -13,203 +13,26 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
const closeListener_1 = __importDefault(require("./closeListener"));
|
|
27
|
-
const Client_1 = __importDefault(require("./Client"));
|
|
28
|
-
exports.User = Client_1.default;
|
|
29
|
-
const selva_1 = require("@saulx/selva");
|
|
30
|
-
const utils_1 = require("@saulx/utils");
|
|
31
|
-
const rest_1 = __importDefault(require("./handlers/rest"));
|
|
32
|
-
const BasedServerClient_1 = __importDefault(require("./BasedServerClient"));
|
|
33
|
-
exports.BasedServerClient = BasedServerClient_1.default;
|
|
34
|
-
const Params_1 = require("./Params");
|
|
35
|
-
Object.defineProperty(exports, "Params", { enumerable: true, get: function () { return Params_1.Params; } });
|
|
36
|
-
const getFromConfig_1 = require("./getFromConfig");
|
|
37
|
-
const pkg = require('../package.json');
|
|
38
|
-
__exportStar(require("./types"), exports);
|
|
39
|
-
class BasedServer extends events_1.EventEmitter {
|
|
40
|
-
constructor({ key, cert, useLessMemory, port, db, config, state, }) {
|
|
41
|
-
super();
|
|
42
|
-
this.subscriptions = {};
|
|
43
|
-
// will be clients
|
|
44
|
-
this.clients = {};
|
|
45
|
-
if (state) {
|
|
46
|
-
this.state = state;
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
this.state = {};
|
|
50
|
-
}
|
|
51
|
-
if (config?.functionConfig) {
|
|
52
|
-
const interval = ~~(config.functionConfig.idleTimeout / 2);
|
|
53
|
-
const clear = async () => {
|
|
54
|
-
if (config.functions) {
|
|
55
|
-
for (const key in config.functions) {
|
|
56
|
-
// & key !== open && key !== close
|
|
57
|
-
// good name ?
|
|
58
|
-
// based init - will ask project env org (all optional ofc)
|
|
59
|
-
if (key !== 'authorize' && !key.startsWith('event-')) {
|
|
60
|
-
if (config.functions[key].cnt === 2) {
|
|
61
|
-
await config.functionConfig.clear(this, key);
|
|
62
|
-
delete config.functions[key];
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
if (config.functions[key].cnt !== undefined) {
|
|
66
|
-
config.functions[key].cnt++;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
setTimeout(clear, interval);
|
|
73
|
-
};
|
|
74
|
-
setTimeout(clear, interval);
|
|
75
|
-
}
|
|
76
|
-
if (config?.secretsConfig) {
|
|
77
|
-
config.secretsConfig.secretTimeouts = {};
|
|
78
|
-
const interval = ~~(config.secretsConfig.idleTimeout / 2);
|
|
79
|
-
const clear = async () => {
|
|
80
|
-
if (config.secrets) {
|
|
81
|
-
for (const key in config.secretsConfig.secretTimeouts) {
|
|
82
|
-
if (config.secretsConfig.secretTimeouts[key] === 2) {
|
|
83
|
-
// await config.secretsConfig.clear(this, key)
|
|
84
|
-
delete config.secretsConfig.secretTimeouts[key];
|
|
85
|
-
// delete config.secrets[key]
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
if (config.secretsConfig.secretTimeouts[key] !== undefined) {
|
|
89
|
-
config.secretsConfig.secretTimeouts[key]++;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
setTimeout(clear, interval);
|
|
95
|
-
};
|
|
96
|
-
setTimeout(clear, interval);
|
|
97
|
-
}
|
|
98
|
-
const app = key && cert
|
|
99
|
-
? uws_1.default.SSLApp({
|
|
100
|
-
key_file_name: key,
|
|
101
|
-
cert_file_name: cert,
|
|
102
|
-
ssl_prefer_low_memory_usage: useLessMemory,
|
|
103
|
-
})
|
|
104
|
-
: uws_1.default.App();
|
|
105
|
-
if (port) {
|
|
106
|
-
this.port = port;
|
|
107
|
-
}
|
|
108
|
-
app
|
|
109
|
-
.ws('/*', {
|
|
110
|
-
maxPayloadLength: 1024 * 1024 * 16 * 1000,
|
|
111
|
-
idleTimeout: 100,
|
|
112
|
-
compression: uws_1.default.SHARED_COMPRESSOR,
|
|
113
|
-
upgrade: (res, req, ctx) => {
|
|
114
|
-
(0, upgradeListener_1.default)(this, res, req, ctx);
|
|
115
|
-
},
|
|
116
|
-
message: (ws, msg) => {
|
|
117
|
-
(0, handlers_1.default)(this, ws, msg);
|
|
118
|
-
},
|
|
119
|
-
open: (ws) => {
|
|
120
|
-
(0, openListener_1.default)(this, ws);
|
|
121
|
-
},
|
|
122
|
-
close: (ws) => {
|
|
123
|
-
(0, closeListener_1.default)(this, ws);
|
|
124
|
-
},
|
|
125
|
-
drain: (ws) => {
|
|
126
|
-
// call client.drain can be much more efficient
|
|
127
|
-
if (ws.client && ws.client.backpressureQueue) {
|
|
128
|
-
ws.client.drain();
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
})
|
|
132
|
-
// /with name
|
|
133
|
-
.get('/*', (res, req) => (0, rest_1.default)(this, req, res))
|
|
134
|
-
.post('/*', (res, req) => (0, rest_1.default)(this, req, res))
|
|
135
|
-
.options('/*', (res, req) => (0, rest_1.default)(this, req, res));
|
|
136
|
-
this.uwsApp = app;
|
|
137
|
-
this.db = (0, selva_1.connect)(db);
|
|
138
|
-
if (config) {
|
|
139
|
-
const based = new BasedServerClient_1.default(new Params_1.Params(this, {
|
|
140
|
-
payload: {},
|
|
141
|
-
callStack: ['server'],
|
|
142
|
-
}), true);
|
|
143
|
-
this.based = based;
|
|
144
|
-
this.on('open', (client) => {
|
|
145
|
-
if (config.onOpen) {
|
|
146
|
-
config.onOpen({ user: client, based });
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
this.on('close', (client) => {
|
|
150
|
-
if (config.onClose) {
|
|
151
|
-
config.onClose({ user: client, based });
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
this.config = config;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
restartSubscription(name) {
|
|
158
|
-
for (const id in this.subscriptions) {
|
|
159
|
-
const sub = this.subscriptions[id];
|
|
160
|
-
// @ts-ignore
|
|
161
|
-
if (sub.name === name) {
|
|
162
|
-
// @ts-ignore
|
|
163
|
-
sub.restart();
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
start(port) {
|
|
168
|
-
if (!port) {
|
|
169
|
-
port = this.port;
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
this.port = port;
|
|
173
|
-
}
|
|
174
|
-
return new Promise((resolve, reject) => {
|
|
175
|
-
this.uwsApp.listen(this.port, (listenSocket) => {
|
|
176
|
-
if (listenSocket) {
|
|
177
|
-
console.info(`💫 Based-server ${pkg.version} listening on port:`, this.port);
|
|
178
|
-
// do this better wrap a nice thing arround it
|
|
179
|
-
this.listenSocket = listenSocket;
|
|
180
|
-
resolve(this);
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
console.info('🤮 Based-server error on port:', this.port);
|
|
184
|
-
reject(new Error('Cannot start based-server on port: ' + this.port));
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
async getFunction(name) {
|
|
190
|
-
return (0, getFromConfig_1.getFunction)(this, name);
|
|
191
|
-
}
|
|
192
|
-
async destroy() {
|
|
193
|
-
console.info('🔥 Destroy based-server');
|
|
194
|
-
for (const c in this.clients) {
|
|
195
|
-
this.clients[c].destroy();
|
|
196
|
-
delete this.clients[c];
|
|
197
|
-
}
|
|
198
|
-
if (this.listenSocket) {
|
|
199
|
-
uws_1.default.us_listen_socket_close(this.listenSocket);
|
|
200
|
-
this.listenSocket = null;
|
|
201
|
-
}
|
|
202
|
-
this.listenSocket = null;
|
|
203
|
-
this.uwsApp = null;
|
|
204
|
-
await this.db.destroy();
|
|
205
|
-
this.db = null;
|
|
206
|
-
await (0, utils_1.wait)(1000);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
exports.BasedServer = BasedServer;
|
|
210
|
-
const createServer = async (props) => {
|
|
211
|
-
const basedServer = new BasedServer(props);
|
|
212
|
-
return props.port ? basedServer.start() : basedServer;
|
|
17
|
+
exports.createSimpleServer = exports.sendError = exports.sendHttpResponse = exports.compress = exports.BasedServer = void 0;
|
|
18
|
+
const server_1 = require("./server");
|
|
19
|
+
Object.defineProperty(exports, "BasedServer", { enumerable: true, get: function () { return server_1.BasedServer; } });
|
|
20
|
+
const createServer = async (props, sharedSocket) => {
|
|
21
|
+
const basedServer = new server_1.BasedServer(props);
|
|
22
|
+
return props.port ? basedServer.start(props.port, sharedSocket) : basedServer;
|
|
213
23
|
};
|
|
214
24
|
exports.default = createServer;
|
|
25
|
+
// maybe send responsed
|
|
26
|
+
var compress_1 = require("./compress");
|
|
27
|
+
Object.defineProperty(exports, "compress", { enumerable: true, get: function () { return compress_1.compress; } });
|
|
28
|
+
var sendHttpResponse_1 = require("./sendHttpResponse");
|
|
29
|
+
Object.defineProperty(exports, "sendHttpResponse", { enumerable: true, get: function () { return sendHttpResponse_1.sendHttpResponse; } });
|
|
30
|
+
var sendError_1 = require("./sendError");
|
|
31
|
+
Object.defineProperty(exports, "sendError", { enumerable: true, get: function () { return sendError_1.sendError; } });
|
|
32
|
+
var createSimpleServer_1 = require("./createSimpleServer");
|
|
33
|
+
Object.defineProperty(exports, "createSimpleServer", { enumerable: true, get: function () { return createSimpleServer_1.createSimpleServer; } });
|
|
34
|
+
__exportStar(require("./auth/types"), exports);
|
|
35
|
+
__exportStar(require("./functions/types"), exports);
|
|
36
|
+
__exportStar(require("./error"), exports);
|
|
37
|
+
__exportStar(require("./api"), exports);
|
|
215
38
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qCAAqD;AAU5C,4FAVA,oBAAW,OAUA;AARpB,MAAM,YAAY,GAAG,KAAK,EACxB,KAAoB,EACpB,YAAsB,EACA,EAAE;IACxB,MAAM,WAAW,GAAG,IAAI,oBAAW,CAAC,KAAK,CAAC,CAAA;IAC1C,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,WAAW,CAAA;AAC/E,CAAC,CAAA;AAID,kBAAe,YAAY,CAAA;AAE3B,uBAAuB;AACvB,uCAAqC;AAA5B,oGAAA,QAAQ,OAAA;AACjB,uDAAqD;AAA5C,oHAAA,gBAAgB,OAAA;AACzB,yCAAuC;AAA9B,sGAAA,SAAS,OAAA;AAClB,2DAAyD;AAAhD,wHAAA,kBAAkB,OAAA;AAE3B,+CAA4B;AAC5B,oDAAiC;AACjC,0CAAuB;AACvB,wCAAqB"}
|
package/dist/ip.d.ts
ADDED
package/dist/ip.js
ADDED
package/dist/ip.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ip.js","sourceRoot":"","sources":["../src/ip.ts"],"names":[],"mappings":";;;AAEO,MAAM,KAAK,GAAG,CAAC,GAAqB,EAAU,EAAE;IACrD,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,sBAAsB,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAA;AAC7D,CAAC,CAAA;AAFY,QAAA,KAAK,SAEjB"}
|
|
@@ -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,CA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C3D;KACF;IACD,OAAO,EAAE,OAAO,EAAE,CAAA;AACpB,CAAC,CAAA;AAvCY,QAAA,QAAQ,YAuCpB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = (client, payload) => {
|
|
4
|
+
if (client.res) {
|
|
5
|
+
client.res.writeHeader('Access-Control-Allow-Origin', '*');
|
|
6
|
+
// only allowed headers
|
|
7
|
+
client.res.writeHeader('Access-Control-Allow-Headers', '*');
|
|
8
|
+
if (payload === undefined) {
|
|
9
|
+
client.res.end();
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
client.res.end(payload);
|
|
13
|
+
}
|
|
14
|
+
client.res = null;
|
|
15
|
+
client.req = null;
|
|
16
|
+
client.context = null;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=end.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"end.js","sourceRoot":"","sources":["../../../src/network/http/end.ts"],"names":[],"mappings":";;AAEA,kBAAe,CAAC,MAAkB,EAAE,OAAsC,EAAE,EAAE;IAC5E,IAAI,MAAM,CAAC,GAAG,EAAE;QACd,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAA;QAC1D,uBAAuB;QACvB,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,8BAA8B,EAAE,GAAG,CAAC,CAAA;QAC3D,IAAI,OAAO,KAAK,SAAS,EAAE;YACzB,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAA;SACjB;aAAM;YACL,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;SACxB;QACD,MAAM,CAAC,GAAG,GAAG,IAAI,CAAA;QACjB,MAAM,CAAC,GAAG,GAAG,IAAI,CAAA;QACjB,MAAM,CAAC,OAAO,GAAG,IAAI,CAAA;KACtB;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.httpFunction = void 0;
|
|
4
|
+
const functions_1 = require("../../functions");
|
|
5
|
+
const send_1 = require("./send");
|
|
6
|
+
const error_1 = require("../../error");
|
|
7
|
+
const httpFunction = (method, route, client, server, payload) => {
|
|
8
|
+
if (!client.res) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const name = route.name;
|
|
12
|
+
server.functions
|
|
13
|
+
.install(name)
|
|
14
|
+
.then((spec) => {
|
|
15
|
+
if (!client.res) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (spec && !(0, functions_1.isObservableFunctionSpec)(spec)) {
|
|
19
|
+
// TODO: way too much copy but this is tmp solution
|
|
20
|
+
server.functions
|
|
21
|
+
.runFunction(method === 'post' ? 3 : 4, spec, client.context, payload)
|
|
22
|
+
.then(async (result) => {
|
|
23
|
+
if (!client.res) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (spec.customHttpResponse) {
|
|
27
|
+
if (await spec.customHttpResponse(result, payload, client)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
(0, send_1.sendHttpResponse)(client, result);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
(0, send_1.sendHttpResponse)(client, result);
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
.catch((err) => {
|
|
37
|
+
(0, send_1.sendHttpError)(server, client, error_1.BasedErrorCode.FunctionError, {
|
|
38
|
+
err,
|
|
39
|
+
route,
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
.catch(() => (0, send_1.sendHttpError)(server, client, error_1.BasedErrorCode.FunctionNotFound, route));
|
|
45
|
+
};
|
|
46
|
+
exports.httpFunction = httpFunction;
|
|
47
|
+
//# sourceMappingURL=function.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function.js","sourceRoot":"","sources":["../../../src/network/http/function.ts"],"names":[],"mappings":";;;AAAA,+CAA0D;AAG1D,iCAAwD;AACxD,uCAA4C;AAErC,MAAM,YAAY,GAAG,CAC1B,MAAc,EACd,KAAyB,EACzB,MAAkB,EAClB,MAAmB,EACnB,OAAoB,EACd,EAAE;IACR,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;QACf,OAAM;KACP;IACD,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAA;IACvB,MAAM,CAAC,SAAS;SACb,OAAO,CAAC,IAAI,CAAC;SACb,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;QACb,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;YACf,OAAM;SACP;QACD,IAAI,IAAI,IAAI,CAAC,IAAA,oCAAwB,EAAC,IAAI,CAAC,EAAE;YAC3C,mDAAmD;YACnD,MAAM,CAAC,SAAS;iBACb,WAAW,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;iBACrE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;gBACrB,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;oBACf,OAAM;iBACP;gBACD,IAAI,IAAI,CAAC,kBAAkB,EAAE;oBAC3B,IAAI,MAAM,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE;wBAC1D,OAAM;qBACP;oBACD,IAAA,uBAAgB,EAAC,MAAM,EAAE,MAAM,CAAC,CAAA;iBACjC;qBAAM;oBACL,IAAA,uBAAgB,EAAC,MAAM,EAAE,MAAM,CAAC,CAAA;iBACjC;YACH,CAAC,CAAC;iBACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBACb,IAAA,oBAAa,EAAC,MAAM,EAAE,MAAM,EAAE,sBAAc,CAAC,aAAa,EAAE;oBAC1D,GAAG;oBACH,KAAK;iBACN,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;SACL;IACH,CAAC,CAAC;SACD,KAAK,CAAC,GAAG,EAAE,CACV,IAAA,oBAAa,EAAC,MAAM,EAAE,MAAM,EAAE,sBAAc,CAAC,gBAAgB,EAAE,KAAK,CAAC,CACtE,CAAA;AACL,CAAC,CAAA;AA7CY,QAAA,YAAY,gBA6CxB"}
|
|
@@ -0,0 +1,129 @@
|
|
|
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.httpGet = void 0;
|
|
7
|
+
const functions_1 = require("../../functions");
|
|
8
|
+
const end_1 = __importDefault(require("./end"));
|
|
9
|
+
const compress_1 = require("./compress");
|
|
10
|
+
const send_1 = require("./send");
|
|
11
|
+
const hash_1 = require("@saulx/hash");
|
|
12
|
+
const observable_1 = require("../../observable");
|
|
13
|
+
const node_zlib_1 = __importDefault(require("node:zlib"));
|
|
14
|
+
const error_1 = require("../../error");
|
|
15
|
+
const sendGetResponse = (route, server, id, obs, checksum, client) => {
|
|
16
|
+
if (!client.res) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const encoding = client.context.headers.encoding;
|
|
20
|
+
try {
|
|
21
|
+
if (checksum === 0 || checksum !== obs.checksum) {
|
|
22
|
+
if (!obs.cache) {
|
|
23
|
+
(0, send_1.sendHttpError)(server, client, error_1.BasedErrorCode.NoOservableCacheAvailable, {
|
|
24
|
+
observableId: id,
|
|
25
|
+
name: obs.name,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
if (obs.isDeflate) {
|
|
30
|
+
if (typeof encoding === 'string' && encoding.includes('deflate')) {
|
|
31
|
+
client.res.cork(() => {
|
|
32
|
+
client.res.writeStatus('200 OK');
|
|
33
|
+
client.res.writeHeader('ETag', String(obs.checksum));
|
|
34
|
+
client.res.writeHeader('Content-Encoding', 'deflate');
|
|
35
|
+
(0, end_1.default)(client, obs.cache.slice(4 + 8 + 8));
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
(0, compress_1.compress)(client, node_zlib_1.default.inflateRawSync(obs.cache.slice(4 + 8 + 8))).then(({ payload, encoding }) => {
|
|
40
|
+
client.res.cork(() => {
|
|
41
|
+
client.res.writeStatus('200 OK');
|
|
42
|
+
if (encoding) {
|
|
43
|
+
client.res.writeHeader('Content-Encoding', encoding);
|
|
44
|
+
}
|
|
45
|
+
client.res.writeHeader('ETag', String(obs.checksum));
|
|
46
|
+
(0, end_1.default)(client, payload);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
client.res.cork(() => {
|
|
53
|
+
client.res.writeStatus('200 OK');
|
|
54
|
+
client.res.writeHeader('ETag', String(obs.checksum));
|
|
55
|
+
(0, end_1.default)(client, obs.cache.slice(4 + 8 + 8));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
client.res.cork(() => {
|
|
62
|
+
client.res.writeStatus('304 Not Modified');
|
|
63
|
+
(0, end_1.default)(client);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
(0, send_1.sendHttpError)(server, client, error_1.BasedErrorCode.FunctionError, {
|
|
69
|
+
err,
|
|
70
|
+
observableId: id,
|
|
71
|
+
route,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (obs.clients.size === 0) {
|
|
75
|
+
(0, observable_1.destroy)(server, id);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const httpGet = (route, payload, client, server, checksum) => {
|
|
79
|
+
if (!client.res) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const name = route.name;
|
|
83
|
+
server.functions
|
|
84
|
+
.install(name)
|
|
85
|
+
.then((spec) => {
|
|
86
|
+
if (!client.res) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (spec && (0, functions_1.isObservableFunctionSpec)(spec)) {
|
|
90
|
+
const id = (0, hash_1.hashObjectIgnoreKeyOrder)([name, payload]);
|
|
91
|
+
if (server.activeObservablesById.has(id)) {
|
|
92
|
+
const obs = server.activeObservablesById.get(id);
|
|
93
|
+
if (obs.beingDestroyed) {
|
|
94
|
+
clearTimeout(obs.beingDestroyed);
|
|
95
|
+
obs.beingDestroyed = null;
|
|
96
|
+
}
|
|
97
|
+
if (obs.cache) {
|
|
98
|
+
sendGetResponse(route, server, id, obs, checksum, client);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
if (!obs.onNextData) {
|
|
102
|
+
obs.onNextData = new Set();
|
|
103
|
+
}
|
|
104
|
+
obs.onNextData.add(() => {
|
|
105
|
+
sendGetResponse(route, server, id, obs, checksum, client);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
const obs = (0, observable_1.create)(server, name, id, payload);
|
|
111
|
+
if (!obs.onNextData) {
|
|
112
|
+
obs.onNextData = new Set();
|
|
113
|
+
}
|
|
114
|
+
obs.onNextData.add(() => {
|
|
115
|
+
sendGetResponse(route, server, id, obs, checksum, client);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else if (spec && (0, functions_1.isObservableFunctionSpec)(spec)) {
|
|
120
|
+
(0, send_1.sendHttpError)(server, client, error_1.BasedErrorCode.FunctionIsNotObservable, route);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
(0, send_1.sendHttpError)(server, client, error_1.BasedErrorCode.FunctionNotFound, route);
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
.catch(() => (0, send_1.sendHttpError)(server, client, error_1.BasedErrorCode.FunctionNotFound, route));
|
|
127
|
+
};
|
|
128
|
+
exports.httpGet = httpGet;
|
|
129
|
+
//# sourceMappingURL=get.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../../src/network/http/get.ts"],"names":[],"mappings":";;;;;;AAAA,+CAA0D;AAG1D,gDAAuB;AACvB,yCAAqC;AACrC,iCAAsC;AACtC,sCAAsD;AACtD,iDAAkD;AAClD,0DAA4B;AAC5B,uCAA4C;AAE5C,MAAM,eAAe,GAAG,CACtB,KAAyB,EACzB,MAAmB,EACnB,EAAU,EACV,GAAqB,EACrB,QAAgB,EAChB,MAAkB,EAClB,EAAE;IACF,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;QACf,OAAM;KACP;IAED,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAA;IAEhD,IAAI;QACF,IAAI,QAAQ,KAAK,CAAC,IAAI,QAAQ,KAAK,GAAG,CAAC,QAAQ,EAAE;YAC/C,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE;gBACd,IAAA,oBAAa,EACX,MAAM,EACN,MAAM,EACN,sBAAc,CAAC,yBAAyB,EACxC;oBACE,YAAY,EAAE,EAAE;oBAChB,IAAI,EAAE,GAAG,CAAC,IAAI;iBACf,CACF,CAAA;aACF;iBAAM;gBACL,IAAI,GAAG,CAAC,SAAS,EAAE;oBACjB,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;wBAChE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE;4BACnB,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;4BAChC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC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