remult 0.20.0-exp.12 → 0.20.0-exp.13

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.
@@ -8,5 +8,9 @@ export declare function remultNext(options?: RemultServerOptions<NextApiRequest>
8
8
  } = {
9
9
  [key: string]: any;
10
10
  }, Q extends ParsedUrlQuery = ParsedUrlQuery, D extends PreviewData = PreviewData>(getServerPropsFunction: GetServerSideProps<P, Q, D>): GetServerSideProps<P, Q, D>;
11
+ /** Creates a `next.js` handler with remult defined in the correct context
12
+ * @see
13
+ * https://remult.dev/tutorials/react-next/appendix-1-get-server-side-props.html#using-remult-in-a-next-js-api-handler
14
+ */
11
15
  handle<T>(handler: NextApiHandler<T>): NextApiHandler<T>;
12
16
  };
@@ -61,13 +61,13 @@ export interface ServerHandleResponse {
61
61
  }
62
62
  export interface RemultServer<RequestType> {
63
63
  getRemult(req: RequestType): Promise<Remult>;
64
+ withRemult(req: RequestType, res: GenericResponse, next: VoidFunction): any;
64
65
  openApiDoc(options: {
65
66
  title: string;
66
67
  version?: string;
67
68
  }): any;
68
69
  registerRouter(r: GenericRouter): void;
69
70
  handle(req: RequestType, gRes?: GenericResponse): Promise<ServerHandleResponse | undefined>;
70
- withRemult(req: RequestType, res: GenericResponse, next: VoidFunction): any;
71
71
  }
72
72
  export declare type GenericRouter = {
73
73
  route(path: string): SpecificRoute;
@@ -39,15 +39,17 @@ export class HttpProviderBridgeToRestDataProviderHttpProvider {
39
39
  }
40
40
  }
41
41
  export async function retry(what) {
42
+ let i = 0;
42
43
  while (true) {
43
44
  try {
44
45
  return await what();
45
46
  }
46
47
  catch (err) {
47
- if (err.message?.startsWith("Error occurred while trying to proxy") ||
48
+ if ((err.message?.startsWith("Error occurred while trying to proxy") ||
48
49
  err.message?.startsWith("Error occured while trying to proxy") ||
49
50
  err.message?.includes("http proxy error") ||
50
- err.message?.startsWith("Gateway Timeout")) {
51
+ err.message?.startsWith("Gateway Timeout") ||
52
+ err.status == 500) && i++ < 10) {
51
53
  await new Promise((res, req) => {
52
54
  setTimeout(() => {
53
55
  res({});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "0.20.0-exp.12",
3
+ "version": "0.20.0-exp.13",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/remult-next.d.ts CHANGED
@@ -8,5 +8,9 @@ export declare function remultNext(options?: RemultServerOptions<NextApiRequest>
8
8
  } = {
9
9
  [key: string]: any;
10
10
  }, Q extends ParsedUrlQuery = ParsedUrlQuery, D extends PreviewData = PreviewData>(getServerPropsFunction: GetServerSideProps<P, Q, D>): GetServerSideProps<P, Q, D>;
11
+ /** Creates a `next.js` handler with remult defined in the correct context
12
+ * @see
13
+ * https://remult.dev/tutorials/react-next/appendix-1-get-server-side-props.html#using-remult-in-a-next-js-api-handler
14
+ */
11
15
  handle<T>(handler: NextApiHandler<T>): NextApiHandler<T>;
12
16
  };
@@ -61,13 +61,13 @@ export interface ServerHandleResponse {
61
61
  }
62
62
  export interface RemultServer<RequestType> {
63
63
  getRemult(req: RequestType): Promise<Remult>;
64
+ withRemult(req: RequestType, res: GenericResponse, next: VoidFunction): any;
64
65
  openApiDoc(options: {
65
66
  title: string;
66
67
  version?: string;
67
68
  }): any;
68
69
  registerRouter(r: GenericRouter): void;
69
70
  handle(req: RequestType, gRes?: GenericResponse): Promise<ServerHandleResponse | undefined>;
70
- withRemult(req: RequestType, res: GenericResponse, next: VoidFunction): any;
71
71
  }
72
72
  export declare type GenericRouter = {
73
73
  route(path: string): SpecificRoute;
@@ -65,30 +65,34 @@ exports.HttpProviderBridgeToRestDataProviderHttpProvider = HttpProviderBridgeToR
65
65
  function retry(what) {
66
66
  var _a, _b, _c, _d;
67
67
  return tslib_1.__awaiter(this, void 0, void 0, function () {
68
- var err_1;
68
+ var i, err_1;
69
69
  return tslib_1.__generator(this, function (_e) {
70
70
  switch (_e.label) {
71
71
  case 0:
72
- if (!true) return [3 /*break*/, 7];
72
+ i = 0;
73
73
  _e.label = 1;
74
74
  case 1:
75
- _e.trys.push([1, 3, , 6]);
75
+ if (!true) return [3 /*break*/, 8];
76
+ _e.label = 2;
77
+ case 2:
78
+ _e.trys.push([2, 4, , 7]);
76
79
  return [4 /*yield*/, what()];
77
- case 2: return [2 /*return*/, _e.sent()];
78
- case 3:
80
+ case 3: return [2 /*return*/, _e.sent()];
81
+ case 4:
79
82
  err_1 = _e.sent();
80
- if (!(((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.startsWith("Error occurred while trying to proxy")) || ((_b = err_1.message) === null || _b === void 0 ? void 0 : _b.startsWith("Error occured while trying to proxy")) || ((_c = err_1.message) === null || _c === void 0 ? void 0 : _c.includes("http proxy error")) || ((_d = err_1.message) === null || _d === void 0 ? void 0 : _d.startsWith("Gateway Timeout")))) return [3 /*break*/, 5];
83
+ if (!((((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.startsWith("Error occurred while trying to proxy")) || ((_b = err_1.message) === null || _b === void 0 ? void 0 : _b.startsWith("Error occured while trying to proxy")) || ((_c = err_1.message) === null || _c === void 0 ? void 0 : _c.includes("http proxy error")) || ((_d = err_1.message) === null || _d === void 0 ? void 0 : _d.startsWith("Gateway Timeout")) ||
84
+ err_1.status == 500) && i++ < 10)) return [3 /*break*/, 6];
81
85
  return [4 /*yield*/, new Promise(function (res, req) {
82
86
  setTimeout(function () {
83
87
  res({});
84
88
  }, 250);
85
89
  })];
86
- case 4:
90
+ case 5:
87
91
  _e.sent();
88
- return [3 /*break*/, 0];
89
- case 5: throw err_1;
90
- case 6: return [3 /*break*/, 0];
91
- case 7: return [2 /*return*/];
92
+ return [3 /*break*/, 1];
93
+ case 6: throw err_1;
94
+ case 7: return [3 /*break*/, 1];
95
+ case 8: return [2 /*return*/];
92
96
  }
93
97
  });
94
98
  });