remult 0.26.12-next.0 → 0.26.12-next.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/esm/remult-next.js +1 -1
- package/esm/remult-solid-start.js +2 -2
- package/esm/server/remult-api-server.js +31 -23
- package/package.json +1 -1
- package/remult-next.d.ts +1 -1
- package/remult-next.js +3 -1
- package/remult-solid-start.d.ts +1 -1
- package/remult-solid-start.js +12 -6
- package/server/remult-api-server.js +127 -93
package/esm/remult-next.js
CHANGED
|
@@ -118,6 +118,6 @@ export function remultNextApp(options) {
|
|
|
118
118
|
POST: handler,
|
|
119
119
|
PUT: handler,
|
|
120
120
|
DELETE: handler,
|
|
121
|
-
withRemult: (what) => result.withRemultAsync({}, what),
|
|
121
|
+
withRemult: (what, disableInitUserAndRequest) => result.withRemultAsync(disableInitUserAndRequest ? undefined : {}, what),
|
|
122
122
|
};
|
|
123
123
|
}
|
|
@@ -86,8 +86,8 @@ export function remultSolidStart(options) {
|
|
|
86
86
|
return Object.assign(handler, {
|
|
87
87
|
getRemult: (req) => result.getRemult(req),
|
|
88
88
|
openApiDoc: (options) => result.openApiDoc(options),
|
|
89
|
-
async withRemult(what) {
|
|
90
|
-
return result.withRemultAsync(await getRequestEvent(), what);
|
|
89
|
+
async withRemult(what, disableInitUserAndRequest) {
|
|
90
|
+
return result.withRemultAsync(disableInitUserAndRequest ? undefined : await getRequestEvent(), what);
|
|
91
91
|
},
|
|
92
92
|
GET: serverHandler,
|
|
93
93
|
PUT: serverHandler,
|
|
@@ -105,15 +105,20 @@ export class RemultServerImplementation {
|
|
|
105
105
|
withRemultAsync(request, what) {
|
|
106
106
|
if (!request)
|
|
107
107
|
return this.runWithRemult(what);
|
|
108
|
-
return new Promise((resolve, error) => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
108
|
+
return new Promise(async (resolve, error) => {
|
|
109
|
+
try {
|
|
110
|
+
return await this.withRemult(request, undefined, async () => {
|
|
111
|
+
try {
|
|
112
|
+
what().then(resolve).catch(error);
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
error(err);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
error(err);
|
|
121
|
+
}
|
|
117
122
|
});
|
|
118
123
|
}
|
|
119
124
|
getEntities() {
|
|
@@ -146,9 +151,9 @@ export class RemultServerImplementation {
|
|
|
146
151
|
throw new Error("Couldn't find entity " + entityKey);
|
|
147
152
|
};
|
|
148
153
|
subscriptionServer;
|
|
149
|
-
withRemult = (req, res, next) => {
|
|
150
|
-
this.process(async () => {
|
|
151
|
-
next();
|
|
154
|
+
withRemult = async (req, res, next) => {
|
|
155
|
+
await this.process(async () => {
|
|
156
|
+
await next();
|
|
152
157
|
})(req, res);
|
|
153
158
|
};
|
|
154
159
|
routeImpl;
|
|
@@ -294,12 +299,12 @@ export class RemultServerImplementation {
|
|
|
294
299
|
if (!genReq.params)
|
|
295
300
|
genReq.params = req['_tempParams'];
|
|
296
301
|
}
|
|
297
|
-
let myReq = new
|
|
298
|
-
let myRes = new
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
302
|
+
let myReq = new RequestBridgeToDataApiRequest(genReq);
|
|
303
|
+
let myRes = new ResponseBridgeToDataApiResponse(origRes, req, this.options.error);
|
|
304
|
+
try {
|
|
305
|
+
if (remultStatic.asyncContext.isInInitRequest())
|
|
306
|
+
return await what(remultStatic.asyncContext.getStore().remult, myReq, myRes, genReq, origRes, req);
|
|
307
|
+
else
|
|
303
308
|
await this.runWithRemult(async (remult) => {
|
|
304
309
|
if (req) {
|
|
305
310
|
remultStatic.asyncContext.setInInitRequest(true);
|
|
@@ -332,10 +337,13 @@ export class RemultServerImplementation {
|
|
|
332
337
|
}
|
|
333
338
|
await what(remult, myReq, myRes, genReq, origRes, req);
|
|
334
339
|
});
|
|
335
|
-
|
|
336
|
-
|
|
340
|
+
}
|
|
341
|
+
catch (err) {
|
|
342
|
+
if (origRes)
|
|
337
343
|
myRes.error(err, undefined);
|
|
338
|
-
|
|
344
|
+
else
|
|
345
|
+
throw err;
|
|
346
|
+
}
|
|
339
347
|
};
|
|
340
348
|
}
|
|
341
349
|
async getRemult(req) {
|
|
@@ -747,7 +755,7 @@ export class RemultServerImplementation {
|
|
|
747
755
|
/* internal */
|
|
748
756
|
backendMethodsOpenApi = [];
|
|
749
757
|
}
|
|
750
|
-
class
|
|
758
|
+
class RequestBridgeToDataApiRequest {
|
|
751
759
|
r;
|
|
752
760
|
get(key) {
|
|
753
761
|
return this.r?.query[key];
|
|
@@ -756,7 +764,7 @@ class ExpressRequestBridgeToDataApiRequest {
|
|
|
756
764
|
this.r = r;
|
|
757
765
|
}
|
|
758
766
|
}
|
|
759
|
-
class
|
|
767
|
+
class ResponseBridgeToDataApiResponse {
|
|
760
768
|
r;
|
|
761
769
|
req;
|
|
762
770
|
handleError;
|
package/package.json
CHANGED
package/remult-next.d.ts
CHANGED
|
@@ -22,5 +22,5 @@ export type RemultNextAppServer = RemultServerCore<Request> & {
|
|
|
22
22
|
PUT: (req: Request) => Promise<Response>;
|
|
23
23
|
POST: (req: Request) => Promise<Response>;
|
|
24
24
|
DELETE: (req: Request) => Promise<Response>;
|
|
25
|
-
withRemult<T>(what: () => Promise<T
|
|
25
|
+
withRemult<T>(what: () => Promise<T>, disableInitUserAndRequest?: boolean): Promise<T>;
|
|
26
26
|
};
|
package/remult-next.js
CHANGED
|
@@ -174,7 +174,9 @@ function remultNextApp(options) {
|
|
|
174
174
|
POST: handler,
|
|
175
175
|
PUT: handler,
|
|
176
176
|
DELETE: handler,
|
|
177
|
-
withRemult: function (what
|
|
177
|
+
withRemult: function (what, disableInitUserAndRequest) {
|
|
178
|
+
return result.withRemultAsync(disableInitUserAndRequest ? undefined : {}, what);
|
|
179
|
+
},
|
|
178
180
|
};
|
|
179
181
|
}
|
|
180
182
|
exports.remultNextApp = remultNextApp;
|
package/remult-solid-start.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { RemultServerCore, RemultServerOptions } from './server/index.js';
|
|
|
3
3
|
export declare function remultSolidStart(options: RemultServerOptions<RequestEvent>): RemultSolidStartServer;
|
|
4
4
|
type RequestHandler = (event: RequestEvent) => Promise<Response>;
|
|
5
5
|
export type RemultSolidStartServer = RemultServerCore<RequestEvent> & {
|
|
6
|
-
withRemult<T>(what: () => Promise<T
|
|
6
|
+
withRemult<T>(what: () => Promise<T>, disableInitUserAndRequest?: boolean): Promise<T>;
|
|
7
7
|
GET: RequestHandler;
|
|
8
8
|
PUT: RequestHandler;
|
|
9
9
|
POST: RequestHandler;
|
package/remult-solid-start.js
CHANGED
|
@@ -112,15 +112,21 @@ function remultSolidStart(options) {
|
|
|
112
112
|
return Object.assign(handler, {
|
|
113
113
|
getRemult: function (req) { return result.getRemult(req); },
|
|
114
114
|
openApiDoc: function (options) { return result.openApiDoc(options); },
|
|
115
|
-
withRemult: function (what) {
|
|
115
|
+
withRemult: function (what, disableInitUserAndRequest) {
|
|
116
116
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
117
|
-
var _a, _b;
|
|
118
|
-
return tslib_1.__generator(this, function (
|
|
119
|
-
switch (
|
|
117
|
+
var _a, _b, _c;
|
|
118
|
+
return tslib_1.__generator(this, function (_d) {
|
|
119
|
+
switch (_d.label) {
|
|
120
120
|
case 0:
|
|
121
121
|
_b = (_a = result).withRemultAsync;
|
|
122
|
-
return [
|
|
123
|
-
|
|
122
|
+
if (!disableInitUserAndRequest) return [3 /*break*/, 1];
|
|
123
|
+
_c = undefined;
|
|
124
|
+
return [3 /*break*/, 3];
|
|
125
|
+
case 1: return [4 /*yield*/, (0, web_1.getRequestEvent)()];
|
|
126
|
+
case 2:
|
|
127
|
+
_c = _d.sent();
|
|
128
|
+
_d.label = 3;
|
|
129
|
+
case 3: return [2 /*return*/, _b.apply(_a, [_c, what])];
|
|
124
130
|
}
|
|
125
131
|
});
|
|
126
132
|
});
|
|
@@ -143,14 +143,26 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
143
143
|
}
|
|
144
144
|
});
|
|
145
145
|
}); };
|
|
146
|
-
this.withRemult = function (req, res, next) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
return [
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
146
|
+
this.withRemult = function (req, res, next) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
147
|
+
var _this = this;
|
|
148
|
+
return tslib_1.__generator(this, function (_a) {
|
|
149
|
+
switch (_a.label) {
|
|
150
|
+
case 0: return [4 /*yield*/, this.process(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
151
|
+
return tslib_1.__generator(this, function (_a) {
|
|
152
|
+
switch (_a.label) {
|
|
153
|
+
case 0: return [4 /*yield*/, next()];
|
|
154
|
+
case 1:
|
|
155
|
+
_a.sent();
|
|
156
|
+
return [2 /*return*/];
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}); })(req, res)];
|
|
160
|
+
case 1:
|
|
161
|
+
_a.sent();
|
|
162
|
+
return [2 /*return*/];
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}); };
|
|
154
166
|
this.registeredRouter = false;
|
|
155
167
|
this.hasQueue = false;
|
|
156
168
|
/* internal */
|
|
@@ -241,16 +253,33 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
241
253
|
var _this = this;
|
|
242
254
|
if (!request)
|
|
243
255
|
return this.runWithRemult(what);
|
|
244
|
-
return new Promise(function (resolve, error) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
256
|
+
return new Promise(function (resolve, error) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
257
|
+
var err_1;
|
|
258
|
+
var _this = this;
|
|
259
|
+
return tslib_1.__generator(this, function (_a) {
|
|
260
|
+
switch (_a.label) {
|
|
261
|
+
case 0:
|
|
262
|
+
_a.trys.push([0, 2, , 3]);
|
|
263
|
+
return [4 /*yield*/, this.withRemult(request, undefined, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
264
|
+
return tslib_1.__generator(this, function (_a) {
|
|
265
|
+
try {
|
|
266
|
+
what().then(resolve).catch(error);
|
|
267
|
+
}
|
|
268
|
+
catch (err) {
|
|
269
|
+
error(err);
|
|
270
|
+
}
|
|
271
|
+
return [2 /*return*/];
|
|
272
|
+
});
|
|
273
|
+
}); })];
|
|
274
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
275
|
+
case 2:
|
|
276
|
+
err_1 = _a.sent();
|
|
277
|
+
error(err_1);
|
|
278
|
+
return [3 /*break*/, 3];
|
|
279
|
+
case 3: return [2 /*return*/];
|
|
251
280
|
}
|
|
252
281
|
});
|
|
253
|
-
});
|
|
282
|
+
}); });
|
|
254
283
|
};
|
|
255
284
|
RemultServerImplementation.prototype.getEntities = function () {
|
|
256
285
|
//TODO V2 - consider using entitiesMetaData - but it may require making it all awaitable
|
|
@@ -536,7 +565,7 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
536
565
|
RemultServerImplementation.prototype.process = function (what) {
|
|
537
566
|
var _this = this;
|
|
538
567
|
return function (req, origRes) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
539
|
-
var genReq, myReq, myRes,
|
|
568
|
+
var genReq, myReq, myRes, err_2;
|
|
540
569
|
var _this = this;
|
|
541
570
|
return tslib_1.__generator(this, function (_a) {
|
|
542
571
|
switch (_a.label) {
|
|
@@ -551,69 +580,74 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
551
580
|
if (!genReq.params)
|
|
552
581
|
genReq.params = req['_tempParams'];
|
|
553
582
|
}
|
|
554
|
-
myReq = new
|
|
555
|
-
myRes = new
|
|
556
|
-
|
|
583
|
+
myReq = new RequestBridgeToDataApiRequest(genReq);
|
|
584
|
+
myRes = new ResponseBridgeToDataApiResponse(origRes, req, this.options.error);
|
|
585
|
+
_a.label = 1;
|
|
586
|
+
case 1:
|
|
587
|
+
_a.trys.push([1, 6, , 7]);
|
|
588
|
+
if (!remult_static_js_1.remultStatic.asyncContext.isInInitRequest()) return [3 /*break*/, 3];
|
|
557
589
|
return [4 /*yield*/, what(remult_static_js_1.remultStatic.asyncContext.getStore().remult, myReq, myRes, genReq, origRes, req)];
|
|
558
|
-
case
|
|
559
|
-
case
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
user = req['
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
});
|
|
608
|
-
}); })];
|
|
609
|
-
case 3:
|
|
610
|
-
_a.sent();
|
|
611
|
-
return [3 /*break*/, 5];
|
|
590
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
591
|
+
case 3: return [4 /*yield*/, this.runWithRemult(function (remult) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
592
|
+
var user;
|
|
593
|
+
return tslib_1.__generator(this, function (_a) {
|
|
594
|
+
switch (_a.label) {
|
|
595
|
+
case 0:
|
|
596
|
+
if (!req) return [3 /*break*/, 8];
|
|
597
|
+
remult_static_js_1.remultStatic.asyncContext.setInInitRequest(true);
|
|
598
|
+
_a.label = 1;
|
|
599
|
+
case 1:
|
|
600
|
+
_a.trys.push([1, , 7, 8]);
|
|
601
|
+
user = void 0;
|
|
602
|
+
if (!this.options.getUser) return [3 /*break*/, 3];
|
|
603
|
+
return [4 /*yield*/, this.options.getUser(req)];
|
|
604
|
+
case 2:
|
|
605
|
+
user = _a.sent();
|
|
606
|
+
return [3 /*break*/, 4];
|
|
607
|
+
case 3:
|
|
608
|
+
user = req['user'];
|
|
609
|
+
if (!user)
|
|
610
|
+
user = req['auth'];
|
|
611
|
+
_a.label = 4;
|
|
612
|
+
case 4:
|
|
613
|
+
if (user)
|
|
614
|
+
remult.user = user;
|
|
615
|
+
if (!this.options.initRequest) return [3 /*break*/, 6];
|
|
616
|
+
return [4 /*yield*/, this.options.initRequest(req, {
|
|
617
|
+
remult: remult,
|
|
618
|
+
get liveQueryStorage() {
|
|
619
|
+
return remult.liveQueryStorage;
|
|
620
|
+
},
|
|
621
|
+
set liveQueryStorage(value) {
|
|
622
|
+
remult.liveQueryStorage = value;
|
|
623
|
+
},
|
|
624
|
+
})];
|
|
625
|
+
case 5:
|
|
626
|
+
_a.sent();
|
|
627
|
+
_a.label = 6;
|
|
628
|
+
case 6: return [3 /*break*/, 8];
|
|
629
|
+
case 7:
|
|
630
|
+
remult_static_js_1.remultStatic.asyncContext.setInInitRequest(false);
|
|
631
|
+
return [7 /*endfinally*/];
|
|
632
|
+
case 8: return [4 /*yield*/, what(remult, myReq, myRes, genReq, origRes, req)];
|
|
633
|
+
case 9:
|
|
634
|
+
_a.sent();
|
|
635
|
+
return [2 /*return*/];
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
}); })];
|
|
612
639
|
case 4:
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
case
|
|
640
|
+
_a.sent();
|
|
641
|
+
_a.label = 5;
|
|
642
|
+
case 5: return [3 /*break*/, 7];
|
|
643
|
+
case 6:
|
|
644
|
+
err_2 = _a.sent();
|
|
645
|
+
if (origRes)
|
|
646
|
+
myRes.error(err_2, undefined);
|
|
647
|
+
else
|
|
648
|
+
throw err_2;
|
|
649
|
+
return [3 /*break*/, 7];
|
|
650
|
+
case 7: return [2 /*return*/];
|
|
617
651
|
}
|
|
618
652
|
});
|
|
619
653
|
}); };
|
|
@@ -1071,42 +1105,42 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
1071
1105
|
return RemultServerImplementation;
|
|
1072
1106
|
}());
|
|
1073
1107
|
exports.RemultServerImplementation = RemultServerImplementation;
|
|
1074
|
-
var
|
|
1075
|
-
function
|
|
1108
|
+
var RequestBridgeToDataApiRequest = /** @class */ (function () {
|
|
1109
|
+
function RequestBridgeToDataApiRequest(r) {
|
|
1076
1110
|
this.r = r;
|
|
1077
1111
|
}
|
|
1078
|
-
|
|
1112
|
+
RequestBridgeToDataApiRequest.prototype.get = function (key) {
|
|
1079
1113
|
var _a;
|
|
1080
1114
|
return (_a = this.r) === null || _a === void 0 ? void 0 : _a.query[key];
|
|
1081
1115
|
};
|
|
1082
|
-
return
|
|
1116
|
+
return RequestBridgeToDataApiRequest;
|
|
1083
1117
|
}());
|
|
1084
|
-
var
|
|
1085
|
-
function
|
|
1118
|
+
var ResponseBridgeToDataApiResponse = /** @class */ (function () {
|
|
1119
|
+
function ResponseBridgeToDataApiResponse(r, req, handleError) {
|
|
1086
1120
|
this.r = r;
|
|
1087
1121
|
this.req = req;
|
|
1088
1122
|
this.handleError = handleError;
|
|
1089
1123
|
}
|
|
1090
|
-
|
|
1124
|
+
ResponseBridgeToDataApiResponse.prototype.forbidden = function () {
|
|
1091
1125
|
this.error({ message: 'Forbidden' }, undefined, 403);
|
|
1092
1126
|
};
|
|
1093
|
-
|
|
1127
|
+
ResponseBridgeToDataApiResponse.prototype.setStatus = function (status) {
|
|
1094
1128
|
return this.r.status(status);
|
|
1095
1129
|
};
|
|
1096
|
-
|
|
1097
|
-
|
|
1130
|
+
ResponseBridgeToDataApiResponse.prototype.progress = function (progress) { };
|
|
1131
|
+
ResponseBridgeToDataApiResponse.prototype.success = function (data) {
|
|
1098
1132
|
this.r.json(data);
|
|
1099
1133
|
};
|
|
1100
|
-
|
|
1134
|
+
ResponseBridgeToDataApiResponse.prototype.created = function (data) {
|
|
1101
1135
|
this.setStatus(201).json(data);
|
|
1102
1136
|
};
|
|
1103
|
-
|
|
1137
|
+
ResponseBridgeToDataApiResponse.prototype.deleted = function () {
|
|
1104
1138
|
this.setStatus(204).end();
|
|
1105
1139
|
};
|
|
1106
|
-
|
|
1140
|
+
ResponseBridgeToDataApiResponse.prototype.notFound = function () {
|
|
1107
1141
|
this.error({ message: 'NotFound' }, undefined, 404);
|
|
1108
1142
|
};
|
|
1109
|
-
|
|
1143
|
+
ResponseBridgeToDataApiResponse.prototype.error = function (exception, entity, httpStatusCode) {
|
|
1110
1144
|
var _a;
|
|
1111
1145
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1112
1146
|
var data, responseSent, sendError;
|
|
@@ -1164,7 +1198,7 @@ var ExpressResponseBridgeToDataApiResponse = /** @class */ (function () {
|
|
|
1164
1198
|
});
|
|
1165
1199
|
});
|
|
1166
1200
|
};
|
|
1167
|
-
return
|
|
1201
|
+
return ResponseBridgeToDataApiResponse;
|
|
1168
1202
|
}());
|
|
1169
1203
|
var inProcessQueueHandler = /** @class */ (function () {
|
|
1170
1204
|
function inProcessQueueHandler(storage) {
|