remult 0.14.13 → 0.14.16

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.
@@ -38,7 +38,25 @@ class middleware {
38
38
  return route;
39
39
  }
40
40
  handleRequest(req, res, next) {
41
- let lowerPath = req.path.toLowerCase();
41
+ const url = new URL(req.url);
42
+ const path = url.pathname;
43
+ if (!req.query) {
44
+ let query = {};
45
+ url.searchParams.forEach((val, key) => {
46
+ let current = query[key];
47
+ if (!current) {
48
+ query[key] = val;
49
+ return;
50
+ }
51
+ if (Array.isArray(current)) {
52
+ current.push(val);
53
+ return;
54
+ }
55
+ query[key] = [current, val];
56
+ });
57
+ req.query = query;
58
+ }
59
+ let lowerPath = path.toLowerCase();
42
60
  let m = this.map.get(lowerPath);
43
61
  if (m) {
44
62
  let h = m.get(req.method.toLowerCase());
@@ -47,14 +65,14 @@ class middleware {
47
65
  return;
48
66
  }
49
67
  }
50
- let idPosition = req.path.lastIndexOf('/');
68
+ let idPosition = path.lastIndexOf('/');
51
69
  if (idPosition >= 0) {
52
- lowerPath = req.path.substring(0, idPosition) + '/:id';
70
+ lowerPath = path.substring(0, idPosition) + '/:id';
53
71
  m = this.map.get(lowerPath);
54
72
  if (m) {
55
73
  let h = m.get(req.method.toLowerCase());
56
74
  if (h) {
57
- req.params.id = req.path.substring(idPosition + 1);
75
+ req.params.id = path.substring(idPosition + 1);
58
76
  h(req, res, next);
59
77
  return;
60
78
  }
@@ -32,15 +32,15 @@ export interface RemultExpressBridge extends GenericRequestHandler {
32
32
  }
33
33
  export interface GenericRequest {
34
34
  method: any;
35
- path: any;
36
- originalUrl: any;
37
- query: any;
35
+ url: any;
36
+ query?: any;
38
37
  body: any;
39
- params: any;
38
+ params?: any;
40
39
  }
41
40
  export interface GenericResponse {
42
- statusCode: number;
43
41
  json(data: any): any;
42
+ statusCode: number;
43
+ end(): any;
44
44
  }
45
45
  export declare type GenericRouter = GenericRequestHandler & {
46
46
  route(path: string): SpecificRoute;
@@ -483,7 +483,7 @@ class ExpressResponseBridgeToDataApiResponse {
483
483
  }
484
484
  sendStatus(status) {
485
485
  this.r.statusCode = status;
486
- this.r.json({});
486
+ this.r.end();
487
487
  }
488
488
  progress(progress) {
489
489
  }
@@ -505,7 +505,7 @@ class ExpressResponseBridgeToDataApiResponse {
505
505
  console.error({
506
506
  message: data.message,
507
507
  stack: data.stack?.split('\n'),
508
- url: this.req.originalUrl ?? this.req.path,
508
+ url: this.req.url,
509
509
  method: this.req.method
510
510
  });
511
511
  this.r.statusCode = 400;
@@ -43,9 +43,7 @@ fit("forbidden", async () => {
43
43
  catch (error) {
44
44
  err = error;
45
45
  }
46
- expect(err).toEqual({
47
- httpStatusCode: 403
48
- });
46
+ expect(err.httpStatusCode).toEqual(403);
49
47
  });
50
48
  fit("test http 404", async () => {
51
49
  const repo = create3Tasks();
@@ -63,7 +61,7 @@ fit("test http 404", async () => {
63
61
  expect(error.response.status).toBe(404);
64
62
  });
65
63
  fit("test http 201", async () => {
66
- let result = await axios.post('http://localhost:3001/api/tasks', { title: "z", id: "" });
64
+ let result = await axios.post(path, { title: "z", id: "" });
67
65
  expect(result.data.title).toBe("z");
68
66
  expect(result.status).toBe(201);
69
67
  result = await axios.delete(path + "/" + result.data.id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "0.14.13",
3
+ "version": "0.14.16",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -42,7 +42,25 @@ var middleware = /** @class */ (function () {
42
42
  return route;
43
43
  };
44
44
  middleware.prototype.handleRequest = function (req, res, next) {
45
- var lowerPath = req.path.toLowerCase();
45
+ var url = new URL(req.url);
46
+ var path = url.pathname;
47
+ if (!req.query) {
48
+ var query_1 = {};
49
+ url.searchParams.forEach(function (val, key) {
50
+ var current = query_1[key];
51
+ if (!current) {
52
+ query_1[key] = val;
53
+ return;
54
+ }
55
+ if (Array.isArray(current)) {
56
+ current.push(val);
57
+ return;
58
+ }
59
+ query_1[key] = [current, val];
60
+ });
61
+ req.query = query_1;
62
+ }
63
+ var lowerPath = path.toLowerCase();
46
64
  var m = this.map.get(lowerPath);
47
65
  if (m) {
48
66
  var h = m.get(req.method.toLowerCase());
@@ -51,14 +69,14 @@ var middleware = /** @class */ (function () {
51
69
  return;
52
70
  }
53
71
  }
54
- var idPosition = req.path.lastIndexOf('/');
72
+ var idPosition = path.lastIndexOf('/');
55
73
  if (idPosition >= 0) {
56
- lowerPath = req.path.substring(0, idPosition) + '/:id';
74
+ lowerPath = path.substring(0, idPosition) + '/:id';
57
75
  m = this.map.get(lowerPath);
58
76
  if (m) {
59
77
  var h = m.get(req.method.toLowerCase());
60
78
  if (h) {
61
- req.params.id = req.path.substring(idPosition + 1);
79
+ req.params.id = path.substring(idPosition + 1);
62
80
  h(req, res, next);
63
81
  return;
64
82
  }
@@ -32,15 +32,15 @@ export interface RemultExpressBridge extends GenericRequestHandler {
32
32
  }
33
33
  export interface GenericRequest {
34
34
  method: any;
35
- path: any;
36
- originalUrl: any;
37
- query: any;
35
+ url: any;
36
+ query?: any;
38
37
  body: any;
39
- params: any;
38
+ params?: any;
40
39
  }
41
40
  export interface GenericResponse {
42
- statusCode: number;
43
41
  json(data: any): any;
42
+ statusCode: number;
43
+ end(): any;
44
44
  }
45
45
  export declare type GenericRouter = GenericRequestHandler & {
46
46
  route(path: string): SpecificRoute;
@@ -581,7 +581,7 @@ var ExpressResponseBridgeToDataApiResponse = /** @class */ (function () {
581
581
  };
582
582
  ExpressResponseBridgeToDataApiResponse.prototype.sendStatus = function (status) {
583
583
  this.r.statusCode = status;
584
- this.r.json({});
584
+ this.r.end();
585
585
  };
586
586
  ExpressResponseBridgeToDataApiResponse.prototype.progress = function (progress) {
587
587
  };
@@ -599,12 +599,12 @@ var ExpressResponseBridgeToDataApiResponse = /** @class */ (function () {
599
599
  this.sendStatus(404);
600
600
  };
601
601
  ExpressResponseBridgeToDataApiResponse.prototype.error = function (data) {
602
- var _a, _b;
602
+ var _a;
603
603
  data = data_api_1.serializeError(data);
604
604
  console.error({
605
605
  message: data.message,
606
606
  stack: (_a = data.stack) === null || _a === void 0 ? void 0 : _a.split('\n'),
607
- url: (_b = this.req.originalUrl) !== null && _b !== void 0 ? _b : this.req.path,
607
+ url: this.req.url,
608
608
  method: this.req.method
609
609
  });
610
610
  this.r.statusCode = 400;
@@ -96,9 +96,7 @@ fit("forbidden", function () { return tslib_1.__awaiter(void 0, void 0, void 0,
96
96
  err = error_2;
97
97
  return [3 /*break*/, 4];
98
98
  case 4:
99
- expect(err).toEqual({
100
- httpStatusCode: 403
101
- });
99
+ expect(err.httpStatusCode).toEqual(403);
102
100
  return [2 /*return*/];
103
101
  }
104
102
  });
@@ -140,7 +138,7 @@ fit("test http 201", function () { return tslib_1.__awaiter(void 0, void 0, void
140
138
  var result;
141
139
  return tslib_1.__generator(this, function (_a) {
142
140
  switch (_a.label) {
143
- case 0: return [4 /*yield*/, axios_1.default.post('http://localhost:3001/api/tasks', { title: "z", id: "" })];
141
+ case 0: return [4 /*yield*/, axios_1.default.post(path, { title: "z", id: "" })];
144
142
  case 1:
145
143
  result = _a.sent();
146
144
  expect(result.data.title).toBe("z");