remult 0.20.1 → 0.20.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.
package/esm/graphql.js CHANGED
@@ -77,9 +77,10 @@ export function remultGraphql(api) {
77
77
  }
78
78
  filterTypes += "input " + key + "Filter{" + filterFields + "\n\tOR:[" + key + "Filter]\n}\n";
79
79
  query += q;
80
- root[key] = async ({ options, filter }, req, a) => {
80
+ root[key] = async (arg1, req, a) => {
81
+ const { options, filter } = arg1;
81
82
  return new Promise(async (res, error) => {
82
- //TODO - consider this with remult usage
83
+ //TODO - consider this with remult usage when working with other servers
83
84
  api.withRemult(req, undefined, async () => {
84
85
  let remult = await api.getRemult(req);
85
86
  let repo = remult.repo(e);
@@ -140,3 +141,8 @@ input options{
140
141
  `
141
142
  };
142
143
  }
144
+ //TODO - filter doesn't work since we changed id_eq to be id.eq in rest, but graphql doesn't allow it.
145
+ //TODO - the list of entities, is based on allEntities - that's wrong - it should be based on the api entities - or a separate array.
146
+ //TODO - it's currently only planned for express server - it uses it's 'withRemult' that doesn't exist in all other servers.
147
+ //TODO - it doesn't support mutations
148
+ //TODO - it doesn't support backend methods
@@ -49,7 +49,7 @@ export async function retry(what) {
49
49
  err.message?.startsWith("Error occured while trying to proxy") ||
50
50
  err.message?.includes("http proxy error") ||
51
51
  err.message?.startsWith("Gateway Timeout") ||
52
- err.status == 500) && i++ < 10) {
52
+ err.status == 500) && i++ < 50) {
53
53
  await new Promise((res, req) => {
54
54
  setTimeout(() => {
55
55
  res({});
@@ -1484,6 +1484,7 @@ export class Fields {
1484
1484
  }
1485
1485
  static createdAt(...options) {
1486
1486
  return Field(() => Date, {
1487
+ allowApiUpdate: false,
1487
1488
  saving: (_, ref) => {
1488
1489
  if (getEntityRef(_).isNew())
1489
1490
  ref.value = new Date();
@@ -1492,6 +1493,7 @@ export class Fields {
1492
1493
  }
1493
1494
  static updatedAt(...options) {
1494
1495
  return Field(() => Date, {
1496
+ allowApiUpdate: false,
1495
1497
  saving: (_, ref) => {
1496
1498
  ref.value = new Date();
1497
1499
  }
@@ -33,6 +33,11 @@ export declare class myServerAction extends Action<inArgs, result> {
33
33
  export interface BackendMethodOptions<type> {
34
34
  /**Determines when this `BackendMethod` can execute, see: [Allowed](https://remult.dev/docs/allowed.html) */
35
35
  allowed: AllowedForInstance<type>;
36
+ /** Used to determine the route for the BackendMethod.
37
+ * @example
38
+ * {allowed:true, apiPrefix:'someFolder/'}
39
+ */
40
+ apiPrefix?: string;
36
41
  /** EXPERIMENTAL: Determines if this method should be queued for later execution */
37
42
  queue?: boolean;
38
43
  /** EXPERIMENTAL: Determines if the user should be blocked while this `BackendMethod` is running*/
@@ -119,7 +119,7 @@ export function BackendMethod(options) {
119
119
  if (options.paramTypes)
120
120
  types = options.paramTypes;
121
121
  // if types are undefined - you've forgot to set: "emitDecoratorMetadata":true
122
- let serverAction = new myServerAction(key, types, options, args => originalMethod.apply(undefined, args));
122
+ let serverAction = new myServerAction((options?.apiPrefix ? (options.apiPrefix + '/') : '') + key, types, options, args => originalMethod.apply(undefined, args));
123
123
  serverAction.doWork = async (args, self, url, http) => {
124
124
  args = prepareArgsToSend(types, args);
125
125
  if (options.blockUser === false) {
@@ -156,7 +156,7 @@ export function BackendMethod(options) {
156
156
  if (!controllerOptions.key) {
157
157
  controllerOptions.key = c.repo(constructor).metadata.key;
158
158
  }
159
- reg(controllerOptions.key + '/' + key, options ? options.queue : false, options.allowed, async (d, req, res) => {
159
+ reg(controllerOptions.key + '/' + (options?.apiPrefix ? (options.apiPrefix + '/') : '') + key, options ? options.queue : false, options.allowed, async (d, req, res) => {
160
160
  d.args = d.args.map(x => isCustomUndefined(x) ? undefined : x);
161
161
  let allowed = options.allowed;
162
162
  try {
@@ -243,7 +243,7 @@ export function BackendMethod(options) {
243
243
  }
244
244
  try {
245
245
  let r = await (new class extends Action {
246
- }(classOptions.key + "/" + key, options ? options.queue : false, options.allowed).run({
246
+ }(classOptions.key + "/" + (options?.apiPrefix ? (options.apiPrefix + '/') : '') + key, options ? options.queue : false, options.allowed).run({
247
247
  args,
248
248
  rowInfo: {
249
249
  data: await defs.toApiJson(),
@@ -264,7 +264,7 @@ export function BackendMethod(options) {
264
264
  try {
265
265
  await defs.__validateEntity();
266
266
  let r = await (new class extends Action {
267
- }(x.classes.get(self.constructor).key + "/" + key, options ? options.queue : false, options.allowed).run({
267
+ }(x.classes.get(self.constructor).key + "/" + (options?.apiPrefix ? (options.apiPrefix + '/') : '') + key, options ? options.queue : false, options.allowed).run({
268
268
  args,
269
269
  fields: await defs.toApiJson()
270
270
  }, baseUrl, http));
package/graphql.js CHANGED
@@ -142,67 +142,66 @@ function remultGraphql(api) {
142
142
  }
143
143
  filterTypes += "input " + key + "Filter{" + filterFields + "\n\tOR:[" + key + "Filter]\n}\n";
144
144
  query += q;
145
- root[key] = function (_a, req, a) {
146
- var options = _a.options, filter = _a.filter;
147
- return tslib_1.__awaiter(_this, void 0, void 0, function () {
148
- var _this = this;
149
- return tslib_1.__generator(this, function (_b) {
150
- return [2 /*return*/, new Promise(function (res, error) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
151
- var _this = this;
152
- return tslib_1.__generator(this, function (_a) {
153
- //TODO - consider this with remult usage
154
- api.withRemult(req, undefined, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
155
- var remult, repo, dApi, result, err;
156
- return tslib_1.__generator(this, function (_a) {
157
- switch (_a.label) {
158
- case 0: return [4 /*yield*/, api.getRemult(req)];
159
- case 1:
160
- remult = _a.sent();
161
- repo = remult.repo(e);
162
- dApi = new data_api_1.DataApi(repo, remult);
163
- return [4 /*yield*/, dApi.getArray({
164
- success: function (x) { return result = x.map(function (y) {
165
- t.resultProcessors.forEach(function (z) { return z(y); });
166
- return y;
167
- }); },
168
- created: undefined,
169
- deleted: undefined,
170
- error: function (x) { return err = x; },
171
- forbidden: function () { return err = 'forbidden'; },
172
- notFound: function () { return err = 'not found'; },
173
- progress: undefined
174
- }, {
175
- get: function (key) {
176
- if (options)
177
- switch (key) {
178
- case "_limit":
179
- return options.limit;
180
- case "_page":
181
- return options.page;
182
- case "_sort":
183
- return options.sort;
184
- case "_order":
185
- return options.order;
186
- }
187
- }
188
- }, filter)];
189
- case 2:
190
- _a.sent();
191
- if (err) {
192
- error(err);
193
- return [2 /*return*/];
194
- }
195
- res(result);
145
+ root[key] = function (arg1, req, a) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
146
+ var options, filter;
147
+ var _this = this;
148
+ return tslib_1.__generator(this, function (_a) {
149
+ options = arg1.options, filter = arg1.filter;
150
+ return [2 /*return*/, new Promise(function (res, error) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
151
+ var _this = this;
152
+ return tslib_1.__generator(this, function (_a) {
153
+ //TODO - consider this with remult usage when working with other servers
154
+ api.withRemult(req, undefined, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
155
+ var remult, repo, dApi, result, err;
156
+ return tslib_1.__generator(this, function (_a) {
157
+ switch (_a.label) {
158
+ case 0: return [4 /*yield*/, api.getRemult(req)];
159
+ case 1:
160
+ remult = _a.sent();
161
+ repo = remult.repo(e);
162
+ dApi = new data_api_1.DataApi(repo, remult);
163
+ return [4 /*yield*/, dApi.getArray({
164
+ success: function (x) { return result = x.map(function (y) {
165
+ t.resultProcessors.forEach(function (z) { return z(y); });
166
+ return y;
167
+ }); },
168
+ created: undefined,
169
+ deleted: undefined,
170
+ error: function (x) { return err = x; },
171
+ forbidden: function () { return err = 'forbidden'; },
172
+ notFound: function () { return err = 'not found'; },
173
+ progress: undefined
174
+ }, {
175
+ get: function (key) {
176
+ if (options)
177
+ switch (key) {
178
+ case "_limit":
179
+ return options.limit;
180
+ case "_page":
181
+ return options.page;
182
+ case "_sort":
183
+ return options.sort;
184
+ case "_order":
185
+ return options.order;
186
+ }
187
+ }
188
+ }, filter)];
189
+ case 2:
190
+ _a.sent();
191
+ if (err) {
192
+ error(err);
196
193
  return [2 /*return*/];
197
- }
198
- });
199
- }); });
200
- return [2 /*return*/];
201
- });
202
- }); })];
203
- });
194
+ }
195
+ res(result);
196
+ return [2 /*return*/];
197
+ }
198
+ });
199
+ }); });
200
+ return [2 /*return*/];
201
+ });
202
+ }); })];
204
203
  });
205
- };
204
+ }); };
206
205
  }
207
206
  };
208
207
  try {
@@ -230,3 +229,8 @@ function remultGraphql(api) {
230
229
  };
231
230
  }
232
231
  exports.remultGraphql = remultGraphql;
232
+ //TODO - filter doesn't work since we changed id_eq to be id.eq in rest, but graphql doesn't allow it.
233
+ //TODO - the list of entities, is based on allEntities - that's wrong - it should be based on the api entities - or a separate array.
234
+ //TODO - it's currently only planned for express server - it uses it's 'withRemult' that doesn't exist in all other servers.
235
+ //TODO - it doesn't support mutations
236
+ //TODO - it doesn't support backend methods
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "0.20.1",
3
+ "version": "0.20.2",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -81,7 +81,7 @@ function retry(what) {
81
81
  case 4:
82
82
  err_1 = _e.sent();
83
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];
84
+ err_1.status == 500) && i++ < 50)) return [3 /*break*/, 6];
85
85
  return [4 /*yield*/, new Promise(function (res, req) {
86
86
  setTimeout(function () {
87
87
  res({});
@@ -2611,6 +2611,7 @@ var Fields = /** @class */ (function () {
2611
2611
  options[_i] = arguments[_i];
2612
2612
  }
2613
2613
  return Field.apply(void 0, tslib_1.__spread([function () { return Date; }, {
2614
+ allowApiUpdate: false,
2614
2615
  saving: function (_, ref) {
2615
2616
  if (getEntityRef(_).isNew())
2616
2617
  ref.value = new Date();
@@ -2623,6 +2624,7 @@ var Fields = /** @class */ (function () {
2623
2624
  options[_i] = arguments[_i];
2624
2625
  }
2625
2626
  return Field.apply(void 0, tslib_1.__spread([function () { return Date; }, {
2627
+ allowApiUpdate: false,
2626
2628
  saving: function (_, ref) {
2627
2629
  ref.value = new Date();
2628
2630
  }
@@ -33,6 +33,11 @@ export declare class myServerAction extends Action<inArgs, result> {
33
33
  export interface BackendMethodOptions<type> {
34
34
  /**Determines when this `BackendMethod` can execute, see: [Allowed](https://remult.dev/docs/allowed.html) */
35
35
  allowed: AllowedForInstance<type>;
36
+ /** Used to determine the route for the BackendMethod.
37
+ * @example
38
+ * {allowed:true, apiPrefix:'someFolder/'}
39
+ */
40
+ apiPrefix?: string;
36
41
  /** EXPERIMENTAL: Determines if this method should be queued for later execution */
37
42
  queue?: boolean;
38
43
  /** EXPERIMENTAL: Determines if the user should be blocked while this `BackendMethod` is running*/
@@ -196,7 +196,7 @@ function BackendMethod(options) {
196
196
  if (options.paramTypes)
197
197
  types = options.paramTypes;
198
198
  // if types are undefined - you've forgot to set: "emitDecoratorMetadata":true
199
- var serverAction_1 = new myServerAction(key, types, options, function (args) { return originalMethod.apply(undefined, args); });
199
+ var serverAction_1 = new myServerAction(((options === null || options === void 0 ? void 0 : options.apiPrefix) ? (options.apiPrefix + '/') : '') + key, types, options, function (args) { return originalMethod.apply(undefined, args); });
200
200
  serverAction_1.doWork = function (args, self, url, http) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
201
201
  var _this = this;
202
202
  return tslib_1.__generator(this, function (_a) {
@@ -257,7 +257,7 @@ function BackendMethod(options) {
257
257
  if (!controllerOptions.key) {
258
258
  controllerOptions.key = c.repo(constructor).metadata.key;
259
259
  }
260
- reg(controllerOptions.key + '/' + key, options ? options.queue : false, options.allowed, function (d, req, res) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
260
+ reg(controllerOptions.key + '/' + ((options === null || options === void 0 ? void 0 : options.apiPrefix) ? (options.apiPrefix + '/') : '') + key, options ? options.queue : false, options.allowed, function (d, req, res) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
261
261
  var allowed, remult_1, r_1, err_3;
262
262
  var _this = this;
263
263
  return tslib_1.__generator(this, function (_a) {
@@ -415,7 +415,7 @@ function BackendMethod(options) {
415
415
  return _super !== null && _super.apply(this, arguments) || this;
416
416
  }
417
417
  return class_1;
418
- }(Action))(classOptions_1.key + "/" + key, options ? options.queue : false, options.allowed)).run;
418
+ }(Action))(classOptions_1.key + "/" + ((options === null || options === void 0 ? void 0 : options.apiPrefix) ? (options.apiPrefix + '/') : '') + key, options ? options.queue : false, options.allowed)).run;
419
419
  _e = {
420
420
  args: args
421
421
  };
@@ -451,7 +451,7 @@ function BackendMethod(options) {
451
451
  return _super !== null && _super.apply(this, arguments) || this;
452
452
  }
453
453
  return class_2;
454
- }(Action))(x.classes.get(self.constructor).key + "/" + key, options ? options.queue : false, options.allowed)).run;
454
+ }(Action))(x.classes.get(self.constructor).key + "/" + ((options === null || options === void 0 ? void 0 : options.apiPrefix) ? (options.apiPrefix + '/') : '') + key, options ? options.queue : false, options.allowed)).run;
455
455
  _g = {
456
456
  args: args
457
457
  };