@opra/common 0.26.4 → 0.26.5

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.
Files changed (54) hide show
  1. package/browser.js +69 -26
  2. package/cjs/document/data-type/mapped-type-class.js +0 -1
  3. package/cjs/document/index.js +2 -1
  4. package/cjs/document/resource/action-decorator.js +6 -0
  5. package/cjs/document/resource/action.js +23 -0
  6. package/cjs/document/resource/collection-class.js +4 -4
  7. package/cjs/document/resource/crud-resource.js +2 -2
  8. package/cjs/document/resource/endpoint.js +6 -2
  9. package/cjs/document/resource/operation.js +20 -0
  10. package/cjs/document/resource/resource.js +2 -2
  11. package/cjs/document/resource/singleton-class.js +3 -3
  12. package/cjs/schema/opra-schema.ns.js +1 -0
  13. package/cjs/schema/resource/action.interface.js +2 -0
  14. package/esm/document/data-type/mapped-type-class.js +0 -1
  15. package/esm/document/index.js +2 -1
  16. package/esm/document/resource/action-decorator.js +6 -0
  17. package/esm/document/resource/action.js +19 -0
  18. package/esm/document/resource/collection-class.js +4 -4
  19. package/esm/document/resource/crud-resource.js +2 -2
  20. package/esm/document/resource/endpoint.js +6 -2
  21. package/esm/document/resource/operation.js +15 -0
  22. package/esm/document/resource/resource.js +2 -2
  23. package/esm/document/resource/singleton-class.js +3 -3
  24. package/esm/schema/opra-schema.ns.js +1 -0
  25. package/esm/schema/resource/action.interface.js +1 -0
  26. package/package.json +1 -1
  27. package/types/document/data-type/complex-type-class.d.ts +1 -1
  28. package/types/document/data-type/mapped-type-class.d.ts +1 -1
  29. package/types/document/data-type/simple-type-class.d.ts +1 -2
  30. package/types/document/data-type/union-type-class.d.ts +1 -1
  31. package/types/document/index.d.ts +2 -1
  32. package/types/document/resource/action-decorator.d.ts +4 -2
  33. package/types/document/resource/action.d.ts +25 -0
  34. package/types/document/resource/collection-class.d.ts +8 -8
  35. package/types/document/resource/collection-decorator.d.ts +18 -18
  36. package/types/document/resource/container-decorator.d.ts +4 -4
  37. package/types/document/resource/crud-resource.d.ts +3 -3
  38. package/types/document/resource/endpoint.d.ts +7 -7
  39. package/types/document/resource/operation-decorator.d.ts +1 -1
  40. package/types/document/resource/operation.d.ts +21 -0
  41. package/types/document/resource/resource-decorator.d.ts +12 -5
  42. package/types/document/resource/resource.d.ts +5 -4
  43. package/types/document/resource/singleton-class.d.ts +5 -5
  44. package/types/document/resource/singleton-decorator.d.ts +12 -12
  45. package/types/document/resource/storage-class.d.ts +4 -4
  46. package/types/document/resource/storage-decorator.d.ts +10 -10
  47. package/types/schema/data-type/complex-type.interface.d.ts +3 -2
  48. package/types/schema/data-type/data-type.interface.d.ts +2 -2
  49. package/types/schema/data-type/enum-type.interface.d.ts +3 -1
  50. package/types/schema/data-type/simple-type.interface.d.ts +3 -1
  51. package/types/schema/opra-schema.ns.d.ts +1 -0
  52. package/types/schema/resource/action.interface.d.ts +5 -0
  53. package/types/schema/resource/container.interface.d.ts +0 -2
  54. package/types/schema/resource/resource.interface.d.ts +2 -2
package/browser.js CHANGED
@@ -1117,8 +1117,7 @@ var Endpoint = class {
1117
1117
  constructor(resource, name, init) {
1118
1118
  this.resource = resource;
1119
1119
  this.name = name;
1120
- this.decode = vg2.isAny();
1121
- this.encode = vg2.isAny();
1120
+ this.encodeReturning = vg2.isAny();
1122
1121
  Object.assign(this, init);
1123
1122
  this.parameters = new ResponsiveMap();
1124
1123
  if (init.parameters) {
@@ -1126,6 +1125,10 @@ var Endpoint = class {
1126
1125
  this.defineParameter(n, p);
1127
1126
  }
1128
1127
  }
1128
+ if (init.returnType) {
1129
+ this.returnType = init.returnType instanceof DataType ? init.returnType : this.resource.document.getDataType(init.returnType);
1130
+ this.encodeReturning = this.returnType.generateCodec("encode");
1131
+ }
1129
1132
  }
1130
1133
  defineParameter(name, init) {
1131
1134
  const type = init.type && init.type instanceof DataType ? init.type : this.resource.document.getDataType(init.type || "any");
@@ -1151,6 +1154,25 @@ var Endpoint = class {
1151
1154
  }
1152
1155
  };
1153
1156
 
1157
+ // ../../build/common/esm/document/resource/action.js
1158
+ var Action = class extends Endpoint {
1159
+ static {
1160
+ __name(this, "Action");
1161
+ }
1162
+ constructor(resource, name, init) {
1163
+ super(resource, name, init);
1164
+ this.resource = resource;
1165
+ this.name = name;
1166
+ this.kind = "action";
1167
+ }
1168
+ exportSchema(options) {
1169
+ const schema = super.exportSchema(options);
1170
+ if (this.returnType)
1171
+ schema.returnType = this.returnType.name ? this.returnType.name : this.returnType.exportSchema(options);
1172
+ return schema;
1173
+ }
1174
+ };
1175
+
1154
1176
  // ../../build/common/esm/document/resource/resource.js
1155
1177
  var Resource = class _Resource {
1156
1178
  static {
@@ -1172,7 +1194,7 @@ var Resource = class _Resource {
1172
1194
  this.ctor = init.ctor;
1173
1195
  if (init.actions) {
1174
1196
  for (const [name, meta] of Object.entries(init.actions)) {
1175
- this.actions.set(name, new Endpoint(this, name, meta));
1197
+ this.actions.set(name, new Action(this, name, meta));
1176
1198
  }
1177
1199
  }
1178
1200
  }
@@ -1300,6 +1322,12 @@ function createActionDecorator(options, bannedProperties, list) {
1300
1322
  });
1301
1323
  return decorator;
1302
1324
  };
1325
+ decorator.Returns = (t) => {
1326
+ list.push((actionMetadata) => {
1327
+ actionMetadata.returnType = t;
1328
+ });
1329
+ return decorator;
1330
+ };
1303
1331
  return decorator;
1304
1332
  }
1305
1333
  __name(createActionDecorator, "createActionDecorator");
@@ -1340,12 +1368,12 @@ function ContainerDecorator(options) {
1340
1368
  __name(ContainerDecorator, "ContainerDecorator");
1341
1369
  Object.assign(ContainerDecorator, ResourceDecorator);
1342
1370
  (function(ContainerDecorator2) {
1343
- function Action(options) {
1371
+ function Action2(options) {
1344
1372
  const list = [];
1345
1373
  return createActionDecorator(options, [], list);
1346
1374
  }
1347
- __name(Action, "Action");
1348
- ContainerDecorator2.Action = Action;
1375
+ __name(Action2, "Action");
1376
+ ContainerDecorator2.Action = Action2;
1349
1377
  })(ContainerDecorator || (ContainerDecorator = {}));
1350
1378
 
1351
1379
  // ../../build/common/esm/document/resource/container.js
@@ -2287,7 +2315,6 @@ var MappedTypeClass = class extends ComplexTypeClass {
2287
2315
  }
2288
2316
  }
2289
2317
  }
2290
- // @ts-ignore
2291
2318
  exportSchema() {
2292
2319
  const out = super.exportSchema();
2293
2320
  Object.assign(out, omitUndefined({
@@ -2739,7 +2766,7 @@ TypeDocumentFactory.designTypeMap = /* @__PURE__ */ new Map();
2739
2766
  import merge10 from "putil-merge";
2740
2767
 
2741
2768
  // ../../build/common/esm/document/resource/collection-class.js
2742
- import * as vg7 from "valgen";
2769
+ import * as vg8 from "valgen";
2743
2770
 
2744
2771
  // ../../build/common/esm/filter/opra-filter.ns.js
2745
2772
  var opra_filter_ns_exports = {};
@@ -10252,6 +10279,21 @@ var _wrapEntryValue = /* @__PURE__ */ __name((v) => {
10252
10279
  return new StringLiteral("" + v);
10253
10280
  }, "_wrapEntryValue");
10254
10281
 
10282
+ // ../../build/common/esm/document/resource/operation.js
10283
+ import * as vg7 from "valgen";
10284
+ var Operation = class extends Endpoint {
10285
+ static {
10286
+ __name(this, "Operation");
10287
+ }
10288
+ constructor(resource, name, init) {
10289
+ super(resource, name, init);
10290
+ this.resource = resource;
10291
+ this.name = name;
10292
+ this.kind = "operation";
10293
+ this.decodeInput = vg7.isAny();
10294
+ }
10295
+ };
10296
+
10255
10297
  // ../../build/common/esm/document/resource/crud-resource.js
10256
10298
  var CrudResource = class extends Resource {
10257
10299
  static {
@@ -10262,7 +10304,7 @@ var CrudResource = class extends Resource {
10262
10304
  this.operations = new ResponsiveMap();
10263
10305
  if (init.operations) {
10264
10306
  for (const [name, meta] of Object.entries(init.operations)) {
10265
- this.operations.set(name, new Endpoint(this, name, meta));
10307
+ this.operations.set(name, new Operation(this, name, meta));
10266
10308
  }
10267
10309
  }
10268
10310
  }
@@ -10306,7 +10348,7 @@ var CollectionClass = class extends CrudResource {
10306
10348
  pick: endpoint.inputPickFields,
10307
10349
  omit: endpoint.inputOmitFields
10308
10350
  });
10309
- endpoint.encode = this.type.generateCodec("encode", {
10351
+ endpoint.encodeReturning = this.type.generateCodec("encode", {
10310
10352
  partial: true,
10311
10353
  pick: endpoint.outputPickFields,
10312
10354
  omit: endpoint.outputOmitFields
@@ -10322,7 +10364,7 @@ var CollectionClass = class extends CrudResource {
10322
10364
  endpoint = this.operations.get("get");
10323
10365
  if (endpoint) {
10324
10366
  endpoint.returnType = this.type;
10325
- endpoint.encode = this.type.generateCodec("encode", {
10367
+ endpoint.encodeReturning = this.type.generateCodec("encode", {
10326
10368
  partial: true,
10327
10369
  pick: endpoint.outputPickFields,
10328
10370
  omit: endpoint.outputOmitFields
@@ -10334,7 +10376,7 @@ var CollectionClass = class extends CrudResource {
10334
10376
  endpoint = this.operations.get("findMany");
10335
10377
  if (endpoint) {
10336
10378
  endpoint.returnType = this.type;
10337
- endpoint.encode = vg7.isArray(this.type.generateCodec("encode", {
10379
+ endpoint.encodeReturning = vg8.isArray(this.type.generateCodec("encode", {
10338
10380
  partial: true,
10339
10381
  pick: endpoint.outputPickFields,
10340
10382
  omit: endpoint.outputOmitFields
@@ -10356,7 +10398,7 @@ var CollectionClass = class extends CrudResource {
10356
10398
  pick: endpoint.inputPickFields,
10357
10399
  omit: endpoint.inputOmitFields
10358
10400
  });
10359
- endpoint.encode = this.type.generateCodec("encode", {
10401
+ endpoint.encodeReturning = this.type.generateCodec("encode", {
10360
10402
  partial: true,
10361
10403
  pick: endpoint.outputPickFields,
10362
10404
  omit: endpoint.outputOmitFields
@@ -10515,12 +10557,12 @@ function CollectionDecorator(type, options) {
10515
10557
  __name(CollectionDecorator, "CollectionDecorator");
10516
10558
  Object.assign(CollectionDecorator, ResourceDecorator);
10517
10559
  (function(CollectionDecorator2) {
10518
- function Action(options) {
10560
+ function Action2(options) {
10519
10561
  const list = [];
10520
10562
  return createActionDecorator(options, operationProperties, list);
10521
10563
  }
10522
- __name(Action, "Action");
10523
- CollectionDecorator2.Action = Action;
10564
+ __name(Action2, "Action");
10565
+ CollectionDecorator2.Action = Action2;
10524
10566
  function Create(options) {
10525
10567
  const list = [];
10526
10568
  const decorator = createOperationDecorator("create", options, list);
@@ -10712,7 +10754,7 @@ var SingletonClass = class extends CrudResource {
10712
10754
  pick: endpoint.inputPickFields,
10713
10755
  omit: endpoint.inputOmitFields
10714
10756
  });
10715
- endpoint.encode = this.type.generateCodec("encode", {
10757
+ endpoint.encodeReturning = this.type.generateCodec("encode", {
10716
10758
  partial: true,
10717
10759
  pick: endpoint.outputPickFields,
10718
10760
  omit: endpoint.outputOmitFields
@@ -10724,7 +10766,7 @@ var SingletonClass = class extends CrudResource {
10724
10766
  endpoint = this.operations.get("get");
10725
10767
  if (endpoint) {
10726
10768
  endpoint.returnType = this.type;
10727
- endpoint.encode = this.type.generateCodec("encode", {
10769
+ endpoint.encodeReturning = this.type.generateCodec("encode", {
10728
10770
  partial: true,
10729
10771
  pick: endpoint.outputPickFields,
10730
10772
  omit: endpoint.outputOmitFields
@@ -10740,7 +10782,7 @@ var SingletonClass = class extends CrudResource {
10740
10782
  pick: endpoint.inputPickFields,
10741
10783
  omit: endpoint.inputOmitFields
10742
10784
  });
10743
- endpoint.encode = this.type.generateCodec("encode", {
10785
+ endpoint.encodeReturning = this.type.generateCodec("encode", {
10744
10786
  partial: true,
10745
10787
  pick: endpoint.outputPickFields,
10746
10788
  omit: endpoint.outputOmitFields
@@ -10772,12 +10814,12 @@ function SingletonDecorator(type, options) {
10772
10814
  __name(SingletonDecorator, "SingletonDecorator");
10773
10815
  Object.assign(SingletonDecorator, ResourceDecorator);
10774
10816
  (function(SingletonDecorator2) {
10775
- function Action(options) {
10817
+ function Action2(options) {
10776
10818
  const list = [];
10777
10819
  return createActionDecorator(options, operationProperties2, list);
10778
10820
  }
10779
- __name(Action, "Action");
10780
- SingletonDecorator2.Action = Action;
10821
+ __name(Action2, "Action");
10822
+ SingletonDecorator2.Action = Action2;
10781
10823
  function Create(options) {
10782
10824
  return CollectionDecorator.Create(options);
10783
10825
  }
@@ -10847,12 +10889,12 @@ function StorageDecorator(options) {
10847
10889
  __name(StorageDecorator, "StorageDecorator");
10848
10890
  Object.assign(StorageDecorator, ResourceDecorator);
10849
10891
  (function(StorageDecorator2) {
10850
- function Action(options) {
10892
+ function Action2(options) {
10851
10893
  const list = [];
10852
10894
  return createActionDecorator(options, operationProperties3, list);
10853
10895
  }
10854
- __name(Action, "Action");
10855
- StorageDecorator2.Action = Action;
10896
+ __name(Action2, "Action");
10897
+ StorageDecorator2.Action = Action2;
10856
10898
  function Delete(options) {
10857
10899
  const list = [];
10858
10900
  return createOperationDecorator("delete", options, list);
@@ -11828,6 +11870,7 @@ var HttpStatusMessages = {
11828
11870
  // ../../build/common/esm/index.js
11829
11871
  import { uid } from "uid";
11830
11872
  export {
11873
+ Action,
11831
11874
  ApiDocument,
11832
11875
  ApiDocumentFactory,
11833
11876
  ApiField,
@@ -11840,7 +11883,6 @@ export {
11840
11883
  DATATYPE_METADATA,
11841
11884
  DECORATOR,
11842
11885
  DataType,
11843
- Endpoint,
11844
11886
  EnumType2 as EnumType,
11845
11887
  FailedDependencyError,
11846
11888
  ForbiddenError,
@@ -11856,6 +11898,7 @@ export {
11856
11898
  NotAcceptableError,
11857
11899
  NotFoundError,
11858
11900
  OmitType,
11901
+ Operation,
11859
11902
  OpraException,
11860
11903
  opra_filter_ns_exports as OpraFilter,
11861
11904
  opra_schema_ns_exports as OpraSchema,
@@ -21,7 +21,6 @@ class MappedTypeClass extends complex_type_class_js_1.ComplexTypeClass {
21
21
  }
22
22
  }
23
23
  }
24
- // @ts-ignore
25
24
  exportSchema() {
26
25
  const out = super.exportSchema();
27
26
  Object.assign(out, (0, index_js_1.omitUndefined)({
@@ -14,13 +14,14 @@ tslib_1.__exportStar(require("./data-type/enum-type.js"), exports);
14
14
  tslib_1.__exportStar(require("./data-type/mapped-type.js"), exports);
15
15
  tslib_1.__exportStar(require("./data-type/simple-type.js"), exports);
16
16
  tslib_1.__exportStar(require("./data-type/union-type.js"), exports);
17
+ tslib_1.__exportStar(require("./resource/action.js"), exports);
17
18
  tslib_1.__exportStar(require("./resource/resource.js"), exports);
18
19
  tslib_1.__exportStar(require("./resource/crud-resource.js"), exports);
19
20
  tslib_1.__exportStar(require("./resource/collection.js"), exports);
20
21
  tslib_1.__exportStar(require("./resource/container.js"), exports);
21
22
  tslib_1.__exportStar(require("./resource/singleton.js"), exports);
22
23
  tslib_1.__exportStar(require("./resource/storage.js"), exports);
23
- tslib_1.__exportStar(require("./resource/endpoint.js"), exports);
24
+ tslib_1.__exportStar(require("./resource/operation.js"), exports);
24
25
  tslib_1.__exportStar(require("./resource/parameter.js"), exports);
25
26
  tslib_1.__exportStar(require("./interfaces/collection.interface.js"), exports);
26
27
  tslib_1.__exportStar(require("./interfaces/singleton.interface.js"), exports);
@@ -22,6 +22,12 @@ function createActionDecorator(options, bannedProperties, list) {
22
22
  });
23
23
  return decorator;
24
24
  };
25
+ decorator.Returns = (t) => {
26
+ list.push((actionMetadata) => {
27
+ actionMetadata.returnType = t;
28
+ });
29
+ return decorator;
30
+ };
25
31
  return decorator;
26
32
  }
27
33
  exports.createActionDecorator = createActionDecorator;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Action = void 0;
4
+ const endpoint_js_1 = require("./endpoint.js");
5
+ /**
6
+ *
7
+ * @class Action
8
+ */
9
+ class Action extends endpoint_js_1.Endpoint {
10
+ constructor(resource, name, init) {
11
+ super(resource, name, init);
12
+ this.resource = resource;
13
+ this.name = name;
14
+ this.kind = 'action';
15
+ }
16
+ exportSchema(options) {
17
+ const schema = super.exportSchema(options);
18
+ if (this.returnType)
19
+ schema.returnType = this.returnType.name ? this.returnType.name : this.returnType.exportSchema(options);
20
+ return schema;
21
+ }
22
+ }
23
+ exports.Action = Action;
@@ -34,7 +34,7 @@ class CollectionClass extends crud_resource_js_1.CrudResource {
34
34
  pick: endpoint.inputPickFields,
35
35
  omit: endpoint.inputOmitFields,
36
36
  });
37
- endpoint.encode = this.type.generateCodec('encode', {
37
+ endpoint.encodeReturning = this.type.generateCodec('encode', {
38
38
  partial: true,
39
39
  pick: endpoint.outputPickFields,
40
40
  omit: endpoint.outputOmitFields,
@@ -52,7 +52,7 @@ class CollectionClass extends crud_resource_js_1.CrudResource {
52
52
  endpoint = this.operations.get('get');
53
53
  if (endpoint) {
54
54
  endpoint.returnType = this.type;
55
- endpoint.encode = this.type.generateCodec('encode', {
55
+ endpoint.encodeReturning = this.type.generateCodec('encode', {
56
56
  partial: true,
57
57
  pick: endpoint.outputPickFields,
58
58
  omit: endpoint.outputOmitFields,
@@ -65,7 +65,7 @@ class CollectionClass extends crud_resource_js_1.CrudResource {
65
65
  endpoint = this.operations.get('findMany');
66
66
  if (endpoint) {
67
67
  endpoint.returnType = this.type;
68
- endpoint.encode = vg.isArray(this.type.generateCodec('encode', {
68
+ endpoint.encodeReturning = vg.isArray(this.type.generateCodec('encode', {
69
69
  partial: true,
70
70
  pick: endpoint.outputPickFields,
71
71
  omit: endpoint.outputOmitFields,
@@ -88,7 +88,7 @@ class CollectionClass extends crud_resource_js_1.CrudResource {
88
88
  pick: endpoint.inputPickFields,
89
89
  omit: endpoint.inputOmitFields,
90
90
  });
91
- endpoint.encode = this.type.generateCodec('encode', {
91
+ endpoint.encodeReturning = this.type.generateCodec('encode', {
92
92
  partial: true,
93
93
  pick: endpoint.outputPickFields,
94
94
  omit: endpoint.outputOmitFields,
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CrudResource = void 0;
4
4
  const index_js_1 = require("../../helpers/index.js");
5
- const endpoint_js_1 = require("./endpoint.js");
5
+ const operation_js_1 = require("./operation.js");
6
6
  const resource_js_1 = require("./resource.js");
7
7
  class CrudResource extends resource_js_1.Resource {
8
8
  constructor(parent, init) {
@@ -10,7 +10,7 @@ class CrudResource extends resource_js_1.Resource {
10
10
  this.operations = new index_js_1.ResponsiveMap();
11
11
  if (init.operations) {
12
12
  for (const [name, meta] of Object.entries(init.operations)) {
13
- this.operations.set(name, new endpoint_js_1.Endpoint(this, name, meta));
13
+ this.operations.set(name, new operation_js_1.Operation(this, name, meta));
14
14
  }
15
15
  }
16
16
  }
@@ -14,8 +14,7 @@ class Endpoint {
14
14
  constructor(resource, name, init) {
15
15
  this.resource = resource;
16
16
  this.name = name;
17
- this.decode = vg.isAny();
18
- this.encode = vg.isAny();
17
+ this.encodeReturning = vg.isAny();
19
18
  Object.assign(this, init);
20
19
  this.parameters = new index_js_1.ResponsiveMap();
21
20
  if (init.parameters) {
@@ -23,6 +22,11 @@ class Endpoint {
23
22
  this.defineParameter(n, p);
24
23
  }
25
24
  }
25
+ if (init.returnType) {
26
+ this.returnType = init.returnType instanceof data_type_js_1.DataType
27
+ ? init.returnType : this.resource.document.getDataType(init.returnType);
28
+ this.encodeReturning = this.returnType.generateCodec('encode');
29
+ }
26
30
  }
27
31
  defineParameter(name, init) {
28
32
  const type = init.type && init.type instanceof data_type_js_1.DataType
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Operation = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const vg = tslib_1.__importStar(require("valgen"));
6
+ const endpoint_js_1 = require("./endpoint.js");
7
+ /**
8
+ *
9
+ * @class Operation
10
+ */
11
+ class Operation extends endpoint_js_1.Endpoint {
12
+ constructor(resource, name, init) {
13
+ super(resource, name, init);
14
+ this.resource = resource;
15
+ this.name = name;
16
+ this.kind = 'operation';
17
+ this.decodeInput = vg.isAny();
18
+ }
19
+ }
20
+ exports.Operation = Operation;
@@ -4,7 +4,7 @@ exports.Resource = void 0;
4
4
  const index_js_1 = require("../../helpers/index.js");
5
5
  const object_utils_js_1 = require("../../helpers/object-utils.js");
6
6
  const inspect_util_js_1 = require("../utils/inspect.util.js");
7
- const endpoint_js_1 = require("./endpoint.js");
7
+ const action_js_1 = require("./action.js");
8
8
  class Resource {
9
9
  constructor(parent, init) {
10
10
  this.actions = new index_js_1.ResponsiveMap();
@@ -24,7 +24,7 @@ class Resource {
24
24
  this.ctor = init.ctor;
25
25
  if (init.actions) {
26
26
  for (const [name, meta] of Object.entries(init.actions)) {
27
- this.actions.set(name, new endpoint_js_1.Endpoint(this, name, meta));
27
+ this.actions.set(name, new action_js_1.Action(this, name, meta));
28
28
  }
29
29
  }
30
30
  }
@@ -17,7 +17,7 @@ class SingletonClass extends crud_resource_js_1.CrudResource {
17
17
  pick: endpoint.inputPickFields,
18
18
  omit: endpoint.inputOmitFields,
19
19
  });
20
- endpoint.encode = this.type.generateCodec('encode', {
20
+ endpoint.encodeReturning = this.type.generateCodec('encode', {
21
21
  partial: true,
22
22
  pick: endpoint.outputPickFields,
23
23
  omit: endpoint.outputOmitFields,
@@ -30,7 +30,7 @@ class SingletonClass extends crud_resource_js_1.CrudResource {
30
30
  endpoint = this.operations.get('get');
31
31
  if (endpoint) {
32
32
  endpoint.returnType = this.type;
33
- endpoint.encode = this.type.generateCodec('encode', {
33
+ endpoint.encodeReturning = this.type.generateCodec('encode', {
34
34
  partial: true,
35
35
  pick: endpoint.outputPickFields,
36
36
  omit: endpoint.outputOmitFields,
@@ -47,7 +47,7 @@ class SingletonClass extends crud_resource_js_1.CrudResource {
47
47
  pick: endpoint.inputPickFields,
48
48
  omit: endpoint.inputOmitFields,
49
49
  });
50
- endpoint.encode = this.type.generateCodec('encode', {
50
+ endpoint.encodeReturning = this.type.generateCodec('encode', {
51
51
  partial: true,
52
52
  pick: endpoint.outputPickFields,
53
53
  omit: endpoint.outputOmitFields,
@@ -8,6 +8,7 @@ tslib_1.__exportStar(require("./data-type/field.interface.js"), exports);
8
8
  tslib_1.__exportStar(require("./data-type/simple-type.interface.js"), exports);
9
9
  tslib_1.__exportStar(require("./data-type/mapped-type.interface.js"), exports);
10
10
  tslib_1.__exportStar(require("./data-type/union-type.interface.js"), exports);
11
+ tslib_1.__exportStar(require("./resource/action.interface.js"), exports);
11
12
  tslib_1.__exportStar(require("./resource/endpoint.interface.js"), exports);
12
13
  tslib_1.__exportStar(require("./resource/collection.interface.js"), exports);
13
14
  tslib_1.__exportStar(require("./resource/container.interface.js"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -18,7 +18,6 @@ export class MappedTypeClass extends ComplexTypeClass {
18
18
  }
19
19
  }
20
20
  }
21
- // @ts-ignore
22
21
  exportSchema() {
23
22
  const out = super.exportSchema();
24
23
  Object.assign(out, omitUndefined({
@@ -11,13 +11,14 @@ export * from './data-type/enum-type.js';
11
11
  export * from './data-type/mapped-type.js';
12
12
  export * from './data-type/simple-type.js';
13
13
  export * from './data-type/union-type.js';
14
+ export * from './resource/action.js';
14
15
  export * from './resource/resource.js';
15
16
  export * from './resource/crud-resource.js';
16
17
  export * from './resource/collection.js';
17
18
  export * from './resource/container.js';
18
19
  export * from './resource/singleton.js';
19
20
  export * from './resource/storage.js';
20
- export * from './resource/endpoint.js';
21
+ export * from './resource/operation.js';
21
22
  export * from './resource/parameter.js';
22
23
  export * from './interfaces/collection.interface.js';
23
24
  export * from './interfaces/singleton.interface.js';
@@ -19,5 +19,11 @@ export function createActionDecorator(options, bannedProperties, list) {
19
19
  });
20
20
  return decorator;
21
21
  };
22
+ decorator.Returns = (t) => {
23
+ list.push((actionMetadata) => {
24
+ actionMetadata.returnType = t;
25
+ });
26
+ return decorator;
27
+ };
22
28
  return decorator;
23
29
  }
@@ -0,0 +1,19 @@
1
+ import { Endpoint } from './endpoint.js';
2
+ /**
3
+ *
4
+ * @class Action
5
+ */
6
+ export class Action extends Endpoint {
7
+ constructor(resource, name, init) {
8
+ super(resource, name, init);
9
+ this.resource = resource;
10
+ this.name = name;
11
+ this.kind = 'action';
12
+ }
13
+ exportSchema(options) {
14
+ const schema = super.exportSchema(options);
15
+ if (this.returnType)
16
+ schema.returnType = this.returnType.name ? this.returnType.name : this.returnType.exportSchema(options);
17
+ return schema;
18
+ }
19
+ }
@@ -30,7 +30,7 @@ export class CollectionClass extends CrudResource {
30
30
  pick: endpoint.inputPickFields,
31
31
  omit: endpoint.inputOmitFields,
32
32
  });
33
- endpoint.encode = this.type.generateCodec('encode', {
33
+ endpoint.encodeReturning = this.type.generateCodec('encode', {
34
34
  partial: true,
35
35
  pick: endpoint.outputPickFields,
36
36
  omit: endpoint.outputOmitFields,
@@ -48,7 +48,7 @@ export class CollectionClass extends CrudResource {
48
48
  endpoint = this.operations.get('get');
49
49
  if (endpoint) {
50
50
  endpoint.returnType = this.type;
51
- endpoint.encode = this.type.generateCodec('encode', {
51
+ endpoint.encodeReturning = this.type.generateCodec('encode', {
52
52
  partial: true,
53
53
  pick: endpoint.outputPickFields,
54
54
  omit: endpoint.outputOmitFields,
@@ -61,7 +61,7 @@ export class CollectionClass extends CrudResource {
61
61
  endpoint = this.operations.get('findMany');
62
62
  if (endpoint) {
63
63
  endpoint.returnType = this.type;
64
- endpoint.encode = vg.isArray(this.type.generateCodec('encode', {
64
+ endpoint.encodeReturning = vg.isArray(this.type.generateCodec('encode', {
65
65
  partial: true,
66
66
  pick: endpoint.outputPickFields,
67
67
  omit: endpoint.outputOmitFields,
@@ -84,7 +84,7 @@ export class CollectionClass extends CrudResource {
84
84
  pick: endpoint.inputPickFields,
85
85
  omit: endpoint.inputOmitFields,
86
86
  });
87
- endpoint.encode = this.type.generateCodec('encode', {
87
+ endpoint.encodeReturning = this.type.generateCodec('encode', {
88
88
  partial: true,
89
89
  pick: endpoint.outputPickFields,
90
90
  omit: endpoint.outputOmitFields,
@@ -1,5 +1,5 @@
1
1
  import { ResponsiveMap } from '../../helpers/index.js';
2
- import { Endpoint } from './endpoint.js';
2
+ import { Operation } from './operation.js';
3
3
  import { Resource } from './resource.js';
4
4
  export class CrudResource extends Resource {
5
5
  constructor(parent, init) {
@@ -7,7 +7,7 @@ export class CrudResource extends Resource {
7
7
  this.operations = new ResponsiveMap();
8
8
  if (init.operations) {
9
9
  for (const [name, meta] of Object.entries(init.operations)) {
10
- this.operations.set(name, new Endpoint(this, name, meta));
10
+ this.operations.set(name, new Operation(this, name, meta));
11
11
  }
12
12
  }
13
13
  }
@@ -10,8 +10,7 @@ export class Endpoint {
10
10
  constructor(resource, name, init) {
11
11
  this.resource = resource;
12
12
  this.name = name;
13
- this.decode = vg.isAny();
14
- this.encode = vg.isAny();
13
+ this.encodeReturning = vg.isAny();
15
14
  Object.assign(this, init);
16
15
  this.parameters = new ResponsiveMap();
17
16
  if (init.parameters) {
@@ -19,6 +18,11 @@ export class Endpoint {
19
18
  this.defineParameter(n, p);
20
19
  }
21
20
  }
21
+ if (init.returnType) {
22
+ this.returnType = init.returnType instanceof DataType
23
+ ? init.returnType : this.resource.document.getDataType(init.returnType);
24
+ this.encodeReturning = this.returnType.generateCodec('encode');
25
+ }
22
26
  }
23
27
  defineParameter(name, init) {
24
28
  const type = init.type && init.type instanceof DataType
@@ -0,0 +1,15 @@
1
+ import * as vg from 'valgen';
2
+ import { Endpoint } from './endpoint.js';
3
+ /**
4
+ *
5
+ * @class Operation
6
+ */
7
+ export class Operation extends Endpoint {
8
+ constructor(resource, name, init) {
9
+ super(resource, name, init);
10
+ this.resource = resource;
11
+ this.name = name;
12
+ this.kind = 'operation';
13
+ this.decodeInput = vg.isAny();
14
+ }
15
+ }
@@ -1,7 +1,7 @@
1
1
  import { ResponsiveMap } from '../../helpers/index.js';
2
2
  import { omitUndefined } from '../../helpers/object-utils.js';
3
3
  import { colorFgMagenta, colorFgYellow, colorReset, nodeInspectCustom } from '../utils/inspect.util.js';
4
- import { Endpoint } from './endpoint.js';
4
+ import { Action } from './action.js';
5
5
  export class Resource {
6
6
  constructor(parent, init) {
7
7
  this.actions = new ResponsiveMap();
@@ -21,7 +21,7 @@ export class Resource {
21
21
  this.ctor = init.ctor;
22
22
  if (init.actions) {
23
23
  for (const [name, meta] of Object.entries(init.actions)) {
24
- this.actions.set(name, new Endpoint(this, name, meta));
24
+ this.actions.set(name, new Action(this, name, meta));
25
25
  }
26
26
  }
27
27
  }