remult 0.25.6-exp.0 → 0.25.6-exp.2

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.
@@ -7,6 +7,7 @@ export function remultNext(options) {
7
7
  return Object.assign((req, res) => result.handle(req, res).then(() => { }), result, {
8
8
  getRemult: (req) => result.getRemult(req),
9
9
  openApiDoc: (arg) => result.openApiDoc(arg),
10
+ withRemult: (req, what) => result.withRemultAsync(req, what),
10
11
  }, {
11
12
  getServerSideProps: (getServerPropsFunction) => {
12
13
  return (context) => {
@@ -274,12 +274,16 @@ export class RemultServerImplementation {
274
274
  }
275
275
  process(what) {
276
276
  return async (req, origRes) => {
277
- const genReq = this.coreOptions.buildGenericRequestInfo(req);
278
- if (!genReq.query) {
279
- genReq.query = req['_tempQuery'];
277
+ const genReq = req
278
+ ? this.coreOptions.buildGenericRequestInfo(req)
279
+ : undefined;
280
+ if (req) {
281
+ if (!genReq.query) {
282
+ genReq.query = req['_tempQuery'];
283
+ }
284
+ if (!genReq.params)
285
+ genReq.params = req['_tempParams'];
280
286
  }
281
- if (!genReq.params)
282
- genReq.params = req['_tempParams'];
283
287
  let myReq = new ExpressRequestBridgeToDataApiRequest(genReq);
284
288
  let myRes = new ExpressResponseBridgeToDataApiResponse(origRes, req);
285
289
  await this.runWithRemult(async (remult) => {
@@ -312,6 +316,8 @@ export class RemultServerImplementation {
312
316
  }
313
317
  async getRemult(req) {
314
318
  let remult;
319
+ if (!req)
320
+ return await this.runWithRemult(async (c) => (remult = c));
315
321
  await this.process(async (c) => {
316
322
  remult = c;
317
323
  })(req, undefined);
@@ -653,7 +659,7 @@ export class RemultServerImplementation {
653
659
  class ExpressRequestBridgeToDataApiRequest {
654
660
  r;
655
661
  get(key) {
656
- return this.r.query[key];
662
+ return this.r?.query[key];
657
663
  }
658
664
  constructor(r) {
659
665
  this.r = r;
@@ -690,8 +696,8 @@ class ExpressResponseBridgeToDataApiResponse {
690
696
  console.error({
691
697
  message: data.message,
692
698
  stack: data.stack?.split('\n'),
693
- url: this.req.url,
694
- method: this.req.method,
699
+ url: this.req?.url,
700
+ method: this.req?.method,
695
701
  });
696
702
  this.setStatus(400).json(data);
697
703
  }
@@ -25,7 +25,7 @@ export class ArrayEntityDataProvider {
25
25
  async init() {
26
26
  if (this.__names)
27
27
  return this.__names;
28
- this.__names = await dbNamesOf(this.entity);
28
+ this.__names = await dbNamesOf(this.entity, (x) => x);
29
29
  for (const r of this.rows) {
30
30
  this.verifyThatRowHasAllNotNullColumns(r, this.__names);
31
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "0.25.6-exp.0",
3
+ "version": "0.25.6-exp.2",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "homepage": "https://remult.dev",
6
6
  "repository": {
package/remult-next.d.ts CHANGED
@@ -9,6 +9,7 @@ export type RemultNextServer = RemultServerCore<NextApiRequest> & NextApiHandler
9
9
  } = {
10
10
  [key: string]: any;
11
11
  }, Q extends ParsedUrlQuery = ParsedUrlQuery, D extends PreviewData = PreviewData>(getServerPropsFunction: GetServerSideProps<P, Q, D>): GetServerSideProps<P, Q, D>;
12
+ withRemult<T>(req: NextApiRequest | undefined, what: () => Promise<T>): Promise<T>;
12
13
  /** Creates a `next.js` handler with remult defined in the correct context
13
14
  * @see
14
15
  * https://remult.dev/tutorials/react-next/appendix-1-get-server-side-props.html#using-remult-in-a-next-js-api-handler
package/remult-next.js CHANGED
@@ -14,6 +14,7 @@ function remultNext(options) {
14
14
  return Object.assign(function (req, res) { return result.handle(req, res).then(function () { }); }, result, {
15
15
  getRemult: function (req) { return result.getRemult(req); },
16
16
  openApiDoc: function (arg) { return result.openApiDoc(arg); },
17
+ withRemult: function (req, what) { return result.withRemultAsync(req, what); },
17
18
  }, {
18
19
  getServerSideProps: function (getServerPropsFunction) {
19
20
  return function (context) {
@@ -74,7 +74,7 @@ export interface RemultServer<RequestType> extends RemultServerCore<RequestType>
74
74
  withRemultAsync<T>(request: RequestType | undefined, what: () => Promise<T>): Promise<T>;
75
75
  }
76
76
  export interface RemultServerCore<RequestType> {
77
- getRemult(req: RequestType): Promise<Remult>;
77
+ getRemult(req?: RequestType): Promise<Remult>;
78
78
  openApiDoc(options: {
79
79
  title: string;
80
80
  version?: string;
@@ -532,12 +532,16 @@ var RemultServerImplementation = /** @class */ (function () {
532
532
  return tslib_1.__generator(this, function (_a) {
533
533
  switch (_a.label) {
534
534
  case 0:
535
- genReq = this.coreOptions.buildGenericRequestInfo(req);
536
- if (!genReq.query) {
537
- genReq.query = req['_tempQuery'];
535
+ genReq = req
536
+ ? this.coreOptions.buildGenericRequestInfo(req)
537
+ : undefined;
538
+ if (req) {
539
+ if (!genReq.query) {
540
+ genReq.query = req['_tempQuery'];
541
+ }
542
+ if (!genReq.params)
543
+ genReq.params = req['_tempParams'];
538
544
  }
539
- if (!genReq.params)
540
- genReq.params = req['_tempParams'];
541
545
  myReq = new ExpressRequestBridgeToDataApiRequest(genReq);
542
546
  myRes = new ExpressResponseBridgeToDataApiResponse(origRes, req);
543
547
  return [4 /*yield*/, this.runWithRemult(function (remult) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
@@ -593,13 +597,19 @@ var RemultServerImplementation = /** @class */ (function () {
593
597
  var _this = this;
594
598
  return tslib_1.__generator(this, function (_a) {
595
599
  switch (_a.label) {
596
- case 0: return [4 /*yield*/, this.process(function (c) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
600
+ case 0:
601
+ if (!!req) return [3 /*break*/, 2];
602
+ return [4 /*yield*/, this.runWithRemult(function (c) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
603
+ return [2 /*return*/, (remult = c)];
604
+ }); }); })];
605
+ case 1: return [2 /*return*/, _a.sent()];
606
+ case 2: return [4 /*yield*/, this.process(function (c) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
597
607
  return tslib_1.__generator(this, function (_a) {
598
608
  remult = c;
599
609
  return [2 /*return*/];
600
610
  });
601
611
  }); })(req, undefined)];
602
- case 1:
612
+ case 3:
603
613
  _a.sent();
604
614
  return [2 /*return*/, remult];
605
615
  }
@@ -977,7 +987,8 @@ var ExpressRequestBridgeToDataApiRequest = /** @class */ (function () {
977
987
  this.r = r;
978
988
  }
979
989
  ExpressRequestBridgeToDataApiRequest.prototype.get = function (key) {
980
- return this.r.query[key];
990
+ var _a;
991
+ return (_a = this.r) === null || _a === void 0 ? void 0 : _a.query[key];
981
992
  };
982
993
  return ExpressRequestBridgeToDataApiRequest;
983
994
  }());
@@ -1006,13 +1017,13 @@ var ExpressResponseBridgeToDataApiResponse = /** @class */ (function () {
1006
1017
  this.setStatus(404).end();
1007
1018
  };
1008
1019
  ExpressResponseBridgeToDataApiResponse.prototype.error = function (data) {
1009
- var _a;
1020
+ var _a, _b, _c;
1010
1021
  data = (0, data_api_js_1.serializeError)(data);
1011
1022
  console.error({
1012
1023
  message: data.message,
1013
1024
  stack: (_a = data.stack) === null || _a === void 0 ? void 0 : _a.split('\n'),
1014
- url: this.req.url,
1015
- method: this.req.method,
1025
+ url: (_b = this.req) === null || _b === void 0 ? void 0 : _b.url,
1026
+ method: (_c = this.req) === null || _c === void 0 ? void 0 : _c.method,
1016
1027
  });
1017
1028
  this.setStatus(400).json(data);
1018
1029
  };
@@ -32,7 +32,7 @@ var ArrayEntityDataProvider = /** @class */ (function () {
32
32
  if (this.__names)
33
33
  return [2 /*return*/, this.__names];
34
34
  _a = this;
35
- return [4 /*yield*/, (0, filter_consumer_bridge_to_sql_request_js_1.dbNamesOf)(this.entity)];
35
+ return [4 /*yield*/, (0, filter_consumer_bridge_to_sql_request_js_1.dbNamesOf)(this.entity, function (x) { return x; })];
36
36
  case 1:
37
37
  _a.__names = _e.sent();
38
38
  try {