remult 0.18.1-exp.21 → 0.18.1-exp.22
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/esm/remult-express.js +0 -16
- package/esm/server/expressBridge.js +16 -0
- package/package.json +1 -1
- package/remult-express.js +6 -74
- package/server/expressBridge.js +85 -17
package/esm/remult-express.js
CHANGED
|
@@ -3,7 +3,6 @@ import { createRemultServer } from './server/index';
|
|
|
3
3
|
import { streamUrl } from './src/live-query/SubscriptionChannel';
|
|
4
4
|
import { v4 as uuid } from 'uuid';
|
|
5
5
|
import { remult } from './src/remult-proxy';
|
|
6
|
-
import { getEntityKey } from './src/remult3';
|
|
7
6
|
export function remultExpress(options) {
|
|
8
7
|
let app = express.Router();
|
|
9
8
|
if (!options) {
|
|
@@ -25,21 +24,6 @@ export function remultExpress(options) {
|
|
|
25
24
|
if (canRegisterRoute.registerRoutes) {
|
|
26
25
|
canRegisterRoute.registerRoutes(app, options.rootPath, server);
|
|
27
26
|
}
|
|
28
|
-
server.runWithRequest = async (req, entityKey, what) => {
|
|
29
|
-
for (const e of options.entities) {
|
|
30
|
-
let key = getEntityKey(e);
|
|
31
|
-
if (key === entityKey) {
|
|
32
|
-
await new Promise((result) => {
|
|
33
|
-
server.withRemult(options.requestSerializer.fromJson(req), undefined, async () => {
|
|
34
|
-
await what(remult.repo(e));
|
|
35
|
-
result({});
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
throw new Error("Couldn't find entity " + entityKey);
|
|
42
|
-
};
|
|
43
27
|
return Object.assign(app, {
|
|
44
28
|
getRemult: (req) => server.getRemult(req),
|
|
45
29
|
openApiDoc: (options) => server.openApiDoc(options),
|
|
@@ -116,6 +116,21 @@ export class RemultServerImplementation {
|
|
|
116
116
|
this.options = options;
|
|
117
117
|
this.dataProvider = dataProvider;
|
|
118
118
|
this.liveQueryStorage = new InMemoryLiveQueryStorage();
|
|
119
|
+
this.runWithRequest = async (req, entityKey, what) => {
|
|
120
|
+
for (const e of this.options.entities) {
|
|
121
|
+
let key = getEntityKey(e);
|
|
122
|
+
if (key === entityKey) {
|
|
123
|
+
await new Promise((result) => {
|
|
124
|
+
this.withRemult(this.options.requestSerializer.fromJson(req), undefined, async () => {
|
|
125
|
+
await what(remult.repo(e));
|
|
126
|
+
result({});
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
throw new Error("Couldn't find entity " + entityKey);
|
|
133
|
+
};
|
|
119
134
|
this.registeredRouter = false;
|
|
120
135
|
this.hasQueue = false;
|
|
121
136
|
/* internal */
|
|
@@ -125,6 +140,7 @@ export class RemultServerImplementation {
|
|
|
125
140
|
if (options.subscriptionServer)
|
|
126
141
|
this.subscriptionServer = options.subscriptionServer;
|
|
127
142
|
}
|
|
143
|
+
;
|
|
128
144
|
withRemult(req, res, next) {
|
|
129
145
|
this.process(async () => { next(); })(req, res);
|
|
130
146
|
}
|
package/package.json
CHANGED
package/remult-express.js
CHANGED
|
@@ -7,9 +7,7 @@ var index_1 = require("./server/index");
|
|
|
7
7
|
var SubscriptionChannel_1 = require("./src/live-query/SubscriptionChannel");
|
|
8
8
|
var uuid_1 = require("uuid");
|
|
9
9
|
var remult_proxy_1 = require("./src/remult-proxy");
|
|
10
|
-
var remult3_1 = require("./src/remult3");
|
|
11
10
|
function remultExpress(options) {
|
|
12
|
-
var _this = this;
|
|
13
11
|
var app = express.Router();
|
|
14
12
|
if (!options) {
|
|
15
13
|
options = {};
|
|
@@ -30,72 +28,6 @@ function remultExpress(options) {
|
|
|
30
28
|
if (canRegisterRoute.registerRoutes) {
|
|
31
29
|
canRegisterRoute.registerRoutes(app, options.rootPath, server);
|
|
32
30
|
}
|
|
33
|
-
server.runWithRequest = function (req, entityKey, what) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
34
|
-
var _loop_1, _a, _b, e, state_1, e_1_1;
|
|
35
|
-
var e_1, _c;
|
|
36
|
-
var _this = this;
|
|
37
|
-
return tslib_1.__generator(this, function (_d) {
|
|
38
|
-
switch (_d.label) {
|
|
39
|
-
case 0:
|
|
40
|
-
_loop_1 = function (e) {
|
|
41
|
-
var key;
|
|
42
|
-
return tslib_1.__generator(this, function (_a) {
|
|
43
|
-
switch (_a.label) {
|
|
44
|
-
case 0:
|
|
45
|
-
key = remult3_1.getEntityKey(e);
|
|
46
|
-
if (!(key === entityKey)) return [3 /*break*/, 2];
|
|
47
|
-
return [4 /*yield*/, new Promise(function (result) {
|
|
48
|
-
server.withRemult(options.requestSerializer.fromJson(req), undefined, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
49
|
-
return tslib_1.__generator(this, function (_a) {
|
|
50
|
-
switch (_a.label) {
|
|
51
|
-
case 0: return [4 /*yield*/, what(remult_proxy_1.remult.repo(e))];
|
|
52
|
-
case 1:
|
|
53
|
-
_a.sent();
|
|
54
|
-
result({});
|
|
55
|
-
return [2 /*return*/];
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}); });
|
|
59
|
-
})];
|
|
60
|
-
case 1:
|
|
61
|
-
_a.sent();
|
|
62
|
-
return [2 /*return*/, { value: void 0 }];
|
|
63
|
-
case 2: return [2 /*return*/];
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
_d.label = 1;
|
|
68
|
-
case 1:
|
|
69
|
-
_d.trys.push([1, 6, 7, 8]);
|
|
70
|
-
_a = tslib_1.__values(options.entities), _b = _a.next();
|
|
71
|
-
_d.label = 2;
|
|
72
|
-
case 2:
|
|
73
|
-
if (!!_b.done) return [3 /*break*/, 5];
|
|
74
|
-
e = _b.value;
|
|
75
|
-
return [5 /*yield**/, _loop_1(e)];
|
|
76
|
-
case 3:
|
|
77
|
-
state_1 = _d.sent();
|
|
78
|
-
if (typeof state_1 === "object")
|
|
79
|
-
return [2 /*return*/, state_1.value];
|
|
80
|
-
_d.label = 4;
|
|
81
|
-
case 4:
|
|
82
|
-
_b = _a.next();
|
|
83
|
-
return [3 /*break*/, 2];
|
|
84
|
-
case 5: return [3 /*break*/, 8];
|
|
85
|
-
case 6:
|
|
86
|
-
e_1_1 = _d.sent();
|
|
87
|
-
e_1 = { error: e_1_1 };
|
|
88
|
-
return [3 /*break*/, 8];
|
|
89
|
-
case 7:
|
|
90
|
-
try {
|
|
91
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
92
|
-
}
|
|
93
|
-
finally { if (e_1) throw e_1.error; }
|
|
94
|
-
return [7 /*endfinally*/];
|
|
95
|
-
case 8: throw new Error("Couldn't find entity " + entityKey);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
}); };
|
|
99
31
|
return Object.assign(app, {
|
|
100
32
|
getRemult: function (req) { return server.getRemult(req); },
|
|
101
33
|
openApiDoc: function (options) { return server.openApiDoc(options); },
|
|
@@ -125,7 +57,7 @@ var SseSubscriptionServer = /** @class */ (function () {
|
|
|
125
57
|
}
|
|
126
58
|
//@internal
|
|
127
59
|
SseSubscriptionServer.prototype.subscribeToChannel = function (_a, res, remult, remove) {
|
|
128
|
-
var
|
|
60
|
+
var e_1, _b;
|
|
129
61
|
var channel = _a.channel, clientId = _a.clientId;
|
|
130
62
|
if (remove === void 0) { remove = false; }
|
|
131
63
|
try {
|
|
@@ -149,17 +81,17 @@ var SseSubscriptionServer = /** @class */ (function () {
|
|
|
149
81
|
}
|
|
150
82
|
}
|
|
151
83
|
}
|
|
152
|
-
catch (
|
|
84
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
153
85
|
finally {
|
|
154
86
|
try {
|
|
155
87
|
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
156
88
|
}
|
|
157
|
-
finally { if (
|
|
89
|
+
finally { if (e_1) throw e_1.error; }
|
|
158
90
|
}
|
|
159
91
|
res.sendStatus(404);
|
|
160
92
|
};
|
|
161
93
|
SseSubscriptionServer.prototype.publishMessage = function (channel, message) {
|
|
162
|
-
var
|
|
94
|
+
var e_2, _a;
|
|
163
95
|
var data = JSON.stringify({ channel: channel, data: message });
|
|
164
96
|
try {
|
|
165
97
|
for (var _b = tslib_1.__values(this.connections), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -170,12 +102,12 @@ var SseSubscriptionServer = /** @class */ (function () {
|
|
|
170
102
|
}
|
|
171
103
|
}
|
|
172
104
|
}
|
|
173
|
-
catch (
|
|
105
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
174
106
|
finally {
|
|
175
107
|
try {
|
|
176
108
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
177
109
|
}
|
|
178
|
-
finally { if (
|
|
110
|
+
finally { if (e_2) throw e_2.error; }
|
|
179
111
|
}
|
|
180
112
|
};
|
|
181
113
|
//@internal
|
package/server/expressBridge.js
CHANGED
|
@@ -152,10 +152,77 @@ exports.RemultAsyncLocalStorage = RemultAsyncLocalStorage;
|
|
|
152
152
|
/* @internal*/
|
|
153
153
|
var RemultServerImplementation = /** @class */ (function () {
|
|
154
154
|
function RemultServerImplementation(queue, options, dataProvider) {
|
|
155
|
+
var _this = this;
|
|
155
156
|
this.queue = queue;
|
|
156
157
|
this.options = options;
|
|
157
158
|
this.dataProvider = dataProvider;
|
|
158
159
|
this.liveQueryStorage = new SubscriptionServer_1.InMemoryLiveQueryStorage();
|
|
160
|
+
this.runWithRequest = function (req, entityKey, what) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
161
|
+
var _loop_1, _a, _b, e, state_1, e_2_1;
|
|
162
|
+
var e_2, _c;
|
|
163
|
+
var _this = this;
|
|
164
|
+
return tslib_1.__generator(this, function (_d) {
|
|
165
|
+
switch (_d.label) {
|
|
166
|
+
case 0:
|
|
167
|
+
_loop_1 = function (e) {
|
|
168
|
+
var key;
|
|
169
|
+
return tslib_1.__generator(this, function (_a) {
|
|
170
|
+
switch (_a.label) {
|
|
171
|
+
case 0:
|
|
172
|
+
key = remult3_1.getEntityKey(e);
|
|
173
|
+
if (!(key === entityKey)) return [3 /*break*/, 2];
|
|
174
|
+
return [4 /*yield*/, new Promise(function (result) {
|
|
175
|
+
_this.withRemult(_this.options.requestSerializer.fromJson(req), undefined, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
176
|
+
return tslib_1.__generator(this, function (_a) {
|
|
177
|
+
switch (_a.label) {
|
|
178
|
+
case 0: return [4 /*yield*/, what(remult_proxy_1.remult.repo(e))];
|
|
179
|
+
case 1:
|
|
180
|
+
_a.sent();
|
|
181
|
+
result({});
|
|
182
|
+
return [2 /*return*/];
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}); });
|
|
186
|
+
})];
|
|
187
|
+
case 1:
|
|
188
|
+
_a.sent();
|
|
189
|
+
return [2 /*return*/, { value: void 0 }];
|
|
190
|
+
case 2: return [2 /*return*/];
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
_d.label = 1;
|
|
195
|
+
case 1:
|
|
196
|
+
_d.trys.push([1, 6, 7, 8]);
|
|
197
|
+
_a = tslib_1.__values(this.options.entities), _b = _a.next();
|
|
198
|
+
_d.label = 2;
|
|
199
|
+
case 2:
|
|
200
|
+
if (!!_b.done) return [3 /*break*/, 5];
|
|
201
|
+
e = _b.value;
|
|
202
|
+
return [5 /*yield**/, _loop_1(e)];
|
|
203
|
+
case 3:
|
|
204
|
+
state_1 = _d.sent();
|
|
205
|
+
if (typeof state_1 === "object")
|
|
206
|
+
return [2 /*return*/, state_1.value];
|
|
207
|
+
_d.label = 4;
|
|
208
|
+
case 4:
|
|
209
|
+
_b = _a.next();
|
|
210
|
+
return [3 /*break*/, 2];
|
|
211
|
+
case 5: return [3 /*break*/, 8];
|
|
212
|
+
case 6:
|
|
213
|
+
e_2_1 = _d.sent();
|
|
214
|
+
e_2 = { error: e_2_1 };
|
|
215
|
+
return [3 /*break*/, 8];
|
|
216
|
+
case 7:
|
|
217
|
+
try {
|
|
218
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
219
|
+
}
|
|
220
|
+
finally { if (e_2) throw e_2.error; }
|
|
221
|
+
return [7 /*endfinally*/];
|
|
222
|
+
case 8: throw new Error("Couldn't find entity " + entityKey);
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}); };
|
|
159
226
|
this.registeredRouter = false;
|
|
160
227
|
this.hasQueue = false;
|
|
161
228
|
/* internal */
|
|
@@ -165,6 +232,7 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
165
232
|
if (options.subscriptionServer)
|
|
166
233
|
this.subscriptionServer = options.subscriptionServer;
|
|
167
234
|
}
|
|
235
|
+
;
|
|
168
236
|
RemultServerImplementation.prototype.withRemult = function (req, res, next) {
|
|
169
237
|
var _this = this;
|
|
170
238
|
this.process(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
@@ -180,7 +248,7 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
180
248
|
return this.routeImpl.handle(req, gRes);
|
|
181
249
|
};
|
|
182
250
|
RemultServerImplementation.prototype.registerRouter = function (r) {
|
|
183
|
-
var
|
|
251
|
+
var e_3, _a, e_4, _b;
|
|
184
252
|
var _this = this;
|
|
185
253
|
if (this.registeredRouter)
|
|
186
254
|
throw "Router already registered";
|
|
@@ -192,7 +260,7 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
192
260
|
var z = c[server_action_1.classBackendMethodsArray];
|
|
193
261
|
if (z)
|
|
194
262
|
try {
|
|
195
|
-
for (var z_1 = (
|
|
263
|
+
for (var z_1 = (e_4 = void 0, tslib_1.__values(z)), z_1_1 = z_1.next(); !z_1_1.done; z_1_1 = z_1.next()) {
|
|
196
264
|
var a = z_1_1.value;
|
|
197
265
|
var x = a[server_action_1.serverActionField];
|
|
198
266
|
if (!x) {
|
|
@@ -201,21 +269,21 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
201
269
|
this.addAction(x, r);
|
|
202
270
|
}
|
|
203
271
|
}
|
|
204
|
-
catch (
|
|
272
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
205
273
|
finally {
|
|
206
274
|
try {
|
|
207
275
|
if (z_1_1 && !z_1_1.done && (_b = z_1.return)) _b.call(z_1);
|
|
208
276
|
}
|
|
209
|
-
finally { if (
|
|
277
|
+
finally { if (e_4) throw e_4.error; }
|
|
210
278
|
}
|
|
211
279
|
}
|
|
212
280
|
}
|
|
213
|
-
catch (
|
|
281
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
214
282
|
finally {
|
|
215
283
|
try {
|
|
216
284
|
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
217
285
|
}
|
|
218
|
-
finally { if (
|
|
286
|
+
finally { if (e_3) throw e_3.error; }
|
|
219
287
|
}
|
|
220
288
|
if (this.hasQueue)
|
|
221
289
|
this.addAction({
|
|
@@ -436,7 +504,7 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
436
504
|
});
|
|
437
505
|
};
|
|
438
506
|
RemultServerImplementation.prototype.openApiDoc = function (options) {
|
|
439
|
-
var
|
|
507
|
+
var e_5, _a, e_6, _b;
|
|
440
508
|
var r = new context_1.Remult();
|
|
441
509
|
if (!options.version)
|
|
442
510
|
options.version = "1.0.0";
|
|
@@ -486,15 +554,15 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
486
554
|
return item;
|
|
487
555
|
}
|
|
488
556
|
};
|
|
489
|
-
var
|
|
490
|
-
var
|
|
557
|
+
var _loop_2 = function (e) {
|
|
558
|
+
var e_7, _a;
|
|
491
559
|
var meta = r.repo(e).metadata;
|
|
492
560
|
var key = remult3_1.getEntityKey(e);
|
|
493
561
|
var parameters = [];
|
|
494
562
|
if (key) {
|
|
495
563
|
var properties = {};
|
|
496
564
|
try {
|
|
497
|
-
for (var _b = (
|
|
565
|
+
for (var _b = (e_7 = void 0, tslib_1.__values(meta.fields)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
498
566
|
var f = _c.value;
|
|
499
567
|
var type = f.valueType == String ? "string" :
|
|
500
568
|
f.valueType == Boolean ? "boolean" :
|
|
@@ -522,12 +590,12 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
522
590
|
});
|
|
523
591
|
}
|
|
524
592
|
}
|
|
525
|
-
catch (
|
|
593
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
526
594
|
finally {
|
|
527
595
|
try {
|
|
528
596
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
529
597
|
}
|
|
530
|
-
finally { if (
|
|
598
|
+
finally { if (e_7) throw e_7.error; }
|
|
531
599
|
}
|
|
532
600
|
spec.components.schemas[key] = {
|
|
533
601
|
type: "object",
|
|
@@ -667,15 +735,15 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
667
735
|
try {
|
|
668
736
|
for (var _c = tslib_1.__values(this.options.entities), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
669
737
|
var e = _d.value;
|
|
670
|
-
|
|
738
|
+
_loop_2(e);
|
|
671
739
|
}
|
|
672
740
|
}
|
|
673
|
-
catch (
|
|
741
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
674
742
|
finally {
|
|
675
743
|
try {
|
|
676
744
|
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
677
745
|
}
|
|
678
|
-
finally { if (
|
|
746
|
+
finally { if (e_5) throw e_5.error; }
|
|
679
747
|
}
|
|
680
748
|
try {
|
|
681
749
|
for (var _e = tslib_1.__values(this.backendMethodsOpenApi), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
@@ -718,12 +786,12 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
718
786
|
};
|
|
719
787
|
}
|
|
720
788
|
}
|
|
721
|
-
catch (
|
|
789
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
722
790
|
finally {
|
|
723
791
|
try {
|
|
724
792
|
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
725
793
|
}
|
|
726
|
-
finally { if (
|
|
794
|
+
finally { if (e_6) throw e_6.error; }
|
|
727
795
|
}
|
|
728
796
|
spec.components.schemas["InvalidResponse"] = {
|
|
729
797
|
"type": "object",
|