remult 0.20.2 → 0.20.3

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.
@@ -391,37 +391,54 @@ export class RemultServerImplementation {
391
391
  let key = getEntityKey(e);
392
392
  let parameters = [];
393
393
  if (key) {
394
+ let mutationKey = key;
394
395
  let properties = {};
396
+ let mutationProperties = {};
395
397
  for (const f of meta.fields) {
396
398
  let type = f.valueType == String ? "string" :
397
399
  f.valueType == Boolean ? "boolean" :
398
400
  f.valueType == Date ? "string" :
399
401
  f.valueType == Number ? "number" :
400
402
  "object";
401
- properties[f.key] = {
402
- type
403
- };
404
- parameters.push({
405
- "name": f.key,
406
- "in": "query",
407
- "description": "filter equal to " + f.key,
408
- "required": false,
409
- "style": "simple",
410
- type
411
- });
412
- parameters.push({
413
- "name": f.key + "_ne",
414
- "in": "query",
415
- "description": "filter not equal to " + f.key,
416
- "required": false,
417
- "style": "simple",
418
- type
419
- });
403
+ if (f.options.includeInApi !== false) {
404
+ properties[f.key] = {
405
+ type
406
+ };
407
+ if (f.options.allowApiUpdate !== false) {
408
+ mutationProperties[f.key] = {
409
+ type
410
+ };
411
+ }
412
+ parameters.push({
413
+ "name": f.key,
414
+ "in": "query",
415
+ "description": "filter equal to " + f.key,
416
+ "required": false,
417
+ "style": "simple",
418
+ type
419
+ });
420
+ parameters.push({
421
+ "name": f.key + "_ne",
422
+ "in": "query",
423
+ "description": "filter not equal to " + f.key,
424
+ "required": false,
425
+ "style": "simple",
426
+ type
427
+ });
428
+ }
420
429
  }
421
430
  spec.components.schemas[key] = {
422
431
  type: "object",
423
432
  properties
424
433
  };
434
+ //TODO - handle allow api read also on the get level
435
+ if (JSON.stringify(properties) !== JSON.stringify(mutationProperties)) {
436
+ mutationKey += 'Mutation';
437
+ spec.components.schemas[mutationKey] = {
438
+ type: "object",
439
+ properties: mutationProperties
440
+ };
441
+ }
425
442
  let definition = {
426
443
  "$ref": "#/components/schemas/" + key
427
444
  };
@@ -431,8 +448,8 @@ export class RemultServerImplementation {
431
448
  condition = meta.options.allowApiCrud;
432
449
  return secureBase(condition, def, item);
433
450
  };
434
- let apiPath = spec.paths['/api/' + key] = {};
435
- let apiPathWithId = spec.paths['/api/' + key + "/{id}"] = {};
451
+ let apiPath = spec.paths[this.options.rootPath + '/' + key] = {};
452
+ let apiPathWithId = spec.paths[this.options.rootPath + '/' + key + "/{id}"] = {};
436
453
  //https://github.com/2fd/open-api.d.ts
437
454
  apiPath.get = secure(meta.options.allowApiRead, true, {
438
455
  description: "return an array of " + key + ". supports filter operators. For more info on filtering [see this article](https://remult.dev/docs/rest-api.html#filter)",
@@ -491,7 +508,7 @@ export class RemultServerImplementation {
491
508
  "content": {
492
509
  "application/json": {
493
510
  "schema": {
494
- "$ref": "#/components/schemas/" + key
511
+ "$ref": "#/components/schemas/" + mutationKey
495
512
  }
496
513
  }
497
514
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "0.20.2",
3
+ "version": "0.20.3",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -696,7 +696,9 @@ var RemultServerImplementation = /** @class */ (function () {
696
696
  var key = remult3_1.getEntityKey(e);
697
697
  var parameters = [];
698
698
  if (key) {
699
+ var mutationKey = key;
699
700
  var properties = {};
701
+ var mutationProperties = {};
700
702
  try {
701
703
  for (var _b = (e_7 = void 0, tslib_1.__values(meta.fields)), _c = _b.next(); !_c.done; _c = _b.next()) {
702
704
  var f = _c.value;
@@ -705,25 +707,32 @@ var RemultServerImplementation = /** @class */ (function () {
705
707
  f.valueType == Date ? "string" :
706
708
  f.valueType == Number ? "number" :
707
709
  "object";
708
- properties[f.key] = {
709
- type: type
710
- };
711
- parameters.push({
712
- "name": f.key,
713
- "in": "query",
714
- "description": "filter equal to " + f.key,
715
- "required": false,
716
- "style": "simple",
717
- type: type
718
- });
719
- parameters.push({
720
- "name": f.key + "_ne",
721
- "in": "query",
722
- "description": "filter not equal to " + f.key,
723
- "required": false,
724
- "style": "simple",
725
- type: type
726
- });
710
+ if (f.options.includeInApi !== false) {
711
+ properties[f.key] = {
712
+ type: type
713
+ };
714
+ if (f.options.allowApiUpdate !== false) {
715
+ mutationProperties[f.key] = {
716
+ type: type
717
+ };
718
+ }
719
+ parameters.push({
720
+ "name": f.key,
721
+ "in": "query",
722
+ "description": "filter equal to " + f.key,
723
+ "required": false,
724
+ "style": "simple",
725
+ type: type
726
+ });
727
+ parameters.push({
728
+ "name": f.key + "_ne",
729
+ "in": "query",
730
+ "description": "filter not equal to " + f.key,
731
+ "required": false,
732
+ "style": "simple",
733
+ type: type
734
+ });
735
+ }
727
736
  }
728
737
  }
729
738
  catch (e_7_1) { e_7 = { error: e_7_1 }; }
@@ -737,6 +746,14 @@ var RemultServerImplementation = /** @class */ (function () {
737
746
  type: "object",
738
747
  properties: properties
739
748
  };
749
+ //TODO - handle allow api read also on the get level
750
+ if (JSON.stringify(properties) !== JSON.stringify(mutationProperties)) {
751
+ mutationKey += 'Mutation';
752
+ spec.components.schemas[mutationKey] = {
753
+ type: "object",
754
+ properties: mutationProperties
755
+ };
756
+ }
740
757
  var definition = {
741
758
  "$ref": "#/components/schemas/" + key
742
759
  };
@@ -746,8 +763,8 @@ var RemultServerImplementation = /** @class */ (function () {
746
763
  condition = meta.options.allowApiCrud;
747
764
  return secureBase(condition, def, item);
748
765
  };
749
- var apiPath = spec.paths['/api/' + key] = {};
750
- var apiPathWithId = spec.paths['/api/' + key + "/{id}"] = {};
766
+ var apiPath = spec.paths[this_2.options.rootPath + '/' + key] = {};
767
+ var apiPathWithId = spec.paths[this_2.options.rootPath + '/' + key + "/{id}"] = {};
751
768
  //https://github.com/2fd/open-api.d.ts
752
769
  apiPath.get = secure(meta.options.allowApiRead, true, {
753
770
  description: "return an array of " + key + ". supports filter operators. For more info on filtering [see this article](https://remult.dev/docs/rest-api.html#filter)",
@@ -806,7 +823,7 @@ var RemultServerImplementation = /** @class */ (function () {
806
823
  "content": {
807
824
  "application/json": {
808
825
  "schema": {
809
- "$ref": "#/components/schemas/" + key
826
+ "$ref": "#/components/schemas/" + mutationKey
810
827
  }
811
828
  }
812
829
  }
@@ -868,6 +885,7 @@ var RemultServerImplementation = /** @class */ (function () {
868
885
  });
869
886
  }
870
887
  };
888
+ var this_2 = this;
871
889
  try {
872
890
  for (var _c = tslib_1.__values(this.options.entities), _d = _c.next(); !_d.done; _d = _c.next()) {
873
891
  var e = _d.value;