@opra/common 0.25.5 → 0.26.1

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 (197) hide show
  1. package/browser.js +1826 -1338
  2. package/cjs/document/api-document.js +16 -220
  3. package/cjs/document/data-type/complex-type-class.js +41 -19
  4. package/cjs/document/data-type/complex-type.js +1 -1
  5. package/cjs/document/data-type/data-type.js +2 -1
  6. package/cjs/document/data-type/enum-type-class.js +15 -12
  7. package/cjs/document/data-type/enum-type.js +28 -14
  8. package/cjs/document/data-type/field-class.js +21 -3
  9. package/cjs/document/data-type/field-decorator.js +0 -19
  10. package/cjs/document/data-type/mapped-type-class.js +8 -10
  11. package/cjs/document/data-type/mapped-type.js +1 -1
  12. package/cjs/document/data-type/simple-type-class.js +17 -8
  13. package/cjs/document/data-type/simple-type.js +1 -1
  14. package/cjs/document/data-type/union-type-class.js +15 -13
  15. package/cjs/document/document-base.js +24 -0
  16. package/cjs/document/factory/api-document-factory.js +231 -0
  17. package/cjs/document/factory/type-document-factory.js +324 -0
  18. package/cjs/document/index.js +7 -1
  19. package/cjs/document/resource/action-decorator.js +27 -0
  20. package/cjs/document/resource/collection-class.js +95 -44
  21. package/cjs/document/resource/collection-decorator.js +182 -0
  22. package/cjs/document/resource/collection.js +4 -4
  23. package/cjs/document/resource/container-class.js +82 -0
  24. package/cjs/document/resource/container-decorator.js +24 -0
  25. package/cjs/document/resource/container.js +29 -0
  26. package/cjs/document/resource/crud-resource.js +31 -0
  27. package/cjs/document/resource/endpoint.js +24 -22
  28. package/cjs/document/resource/operation-decorator.js +27 -0
  29. package/cjs/document/resource/parameter.js +51 -0
  30. package/cjs/document/{decorators/resource.decorator.js → resource/resource-decorator.js} +9 -14
  31. package/cjs/document/resource/resource.js +20 -5
  32. package/cjs/document/resource/singleton-class.js +60 -40
  33. package/cjs/document/resource/singleton-decorator.js +57 -0
  34. package/cjs/document/resource/singleton.js +4 -4
  35. package/cjs/document/resource/storage-class.js +11 -17
  36. package/cjs/document/resource/storage-decorator.js +66 -0
  37. package/cjs/document/resource/storage.js +3 -3
  38. package/cjs/document/type-document.js +195 -0
  39. package/cjs/exception/http-errors/internal-server.error.js +1 -0
  40. package/cjs/exception/wrap-exception.js +2 -1
  41. package/cjs/helpers/responsive-map.js +3 -3
  42. package/cjs/http/opra-url-path.js +2 -1
  43. package/cjs/schema/document/document-base.interface.js +2 -0
  44. package/cjs/schema/document/type-document.interface.js +2 -0
  45. package/cjs/schema/opra-schema.ns.js +3 -1
  46. package/cjs/schema/type-guards.js +3 -3
  47. package/esm/document/api-document.js +16 -220
  48. package/esm/document/data-type/complex-type-class.js +40 -19
  49. package/esm/document/data-type/complex-type.js +1 -1
  50. package/esm/document/data-type/data-type.js +2 -1
  51. package/esm/document/data-type/enum-type-class.js +15 -12
  52. package/esm/document/data-type/enum-type.js +26 -12
  53. package/esm/document/data-type/field-class.js +20 -3
  54. package/esm/document/data-type/field-decorator.js +0 -19
  55. package/esm/document/data-type/mapped-type-class.js +9 -11
  56. package/esm/document/data-type/mapped-type.js +1 -1
  57. package/esm/document/data-type/simple-type-class.js +15 -6
  58. package/esm/document/data-type/simple-type.js +1 -1
  59. package/esm/document/data-type/union-type-class.js +11 -9
  60. package/esm/document/document-base.js +20 -0
  61. package/esm/document/factory/api-document-factory.js +227 -0
  62. package/esm/document/factory/type-document-factory.js +320 -0
  63. package/esm/document/index.js +7 -1
  64. package/esm/document/resource/action-decorator.js +23 -0
  65. package/esm/document/resource/collection-class.js +95 -44
  66. package/esm/document/resource/collection-decorator.js +178 -0
  67. package/esm/document/resource/collection.js +4 -4
  68. package/esm/document/resource/container-class.js +78 -0
  69. package/esm/document/resource/container-decorator.js +20 -0
  70. package/esm/document/resource/container.js +25 -0
  71. package/esm/document/resource/crud-resource.js +27 -0
  72. package/esm/document/resource/endpoint.js +22 -20
  73. package/esm/document/resource/operation-decorator.js +23 -0
  74. package/esm/document/resource/parameter.js +46 -0
  75. package/esm/document/resource/resource-decorator.js +28 -0
  76. package/esm/document/resource/resource.js +20 -5
  77. package/esm/document/resource/singleton-class.js +58 -38
  78. package/esm/document/resource/singleton-decorator.js +53 -0
  79. package/esm/document/resource/singleton.js +4 -4
  80. package/esm/document/resource/storage-class.js +9 -15
  81. package/esm/document/resource/storage-decorator.js +62 -0
  82. package/esm/document/resource/storage.js +3 -3
  83. package/esm/document/type-document.js +191 -0
  84. package/esm/exception/http-errors/internal-server.error.js +1 -0
  85. package/esm/exception/wrap-exception.js +2 -1
  86. package/esm/helpers/responsive-map.js +3 -3
  87. package/esm/http/opra-url-path.js +1 -1
  88. package/esm/schema/document/document-base.interface.js +1 -0
  89. package/esm/schema/document/type-document.interface.js +1 -0
  90. package/esm/schema/opra-schema.ns.js +3 -1
  91. package/esm/schema/type-guards.js +1 -1
  92. package/package.json +4 -4
  93. package/types/document/api-document.d.ts +32 -73
  94. package/types/document/data-type/complex-type-class.d.ts +5 -5
  95. package/types/document/data-type/complex-type.d.ts +8 -3
  96. package/types/document/{decorators → data-type}/complex-type.decorator.d.ts +1 -1
  97. package/types/document/data-type/data-type.d.ts +11 -1
  98. package/types/document/data-type/enum-type-class.d.ts +6 -6
  99. package/types/document/data-type/enum-type.d.ts +12 -6
  100. package/types/document/data-type/field-class.d.ts +9 -1
  101. package/types/document/data-type/field-decorator.d.ts +1 -1
  102. package/types/document/data-type/field.d.ts +4 -3
  103. package/types/document/data-type/mapped-type-class.d.ts +5 -9
  104. package/types/document/data-type/mapped-type.d.ts +6 -7
  105. package/types/document/data-type/simple-type-class.d.ts +6 -3
  106. package/types/document/{decorators → data-type}/simple-type.decorator.d.ts +1 -1
  107. package/types/document/data-type/union-type-class.d.ts +2 -8
  108. package/types/document/data-type/union-type.d.ts +7 -6
  109. package/types/document/document-base.d.ts +10 -0
  110. package/types/document/factory/api-document-factory.d.ts +50 -0
  111. package/types/document/factory/type-document-factory.d.ts +56 -0
  112. package/types/document/index.d.ts +7 -1
  113. package/types/document/resource/action-decorator.d.ts +6 -0
  114. package/types/document/resource/collection-class.d.ts +17 -12
  115. package/types/document/resource/collection-decorator.d.ts +192 -0
  116. package/types/document/resource/collection.d.ts +11 -19
  117. package/types/document/resource/container-class.d.ts +66 -0
  118. package/types/document/resource/container-decorator.d.ts +37 -0
  119. package/types/document/resource/container.d.ts +25 -0
  120. package/types/document/resource/crud-resource.d.ts +16 -0
  121. package/types/document/resource/endpoint.d.ts +21 -21
  122. package/types/document/resource/operation-decorator.d.ts +6 -0
  123. package/types/document/resource/parameter.d.ts +35 -0
  124. package/types/document/resource/resource-decorator.d.ts +32 -0
  125. package/types/document/resource/resource.d.ts +15 -13
  126. package/types/document/resource/singleton-class.d.ts +15 -14
  127. package/types/document/resource/singleton-decorator.d.ts +125 -0
  128. package/types/document/resource/singleton.d.ts +11 -16
  129. package/types/document/resource/storage-class.d.ts +13 -6
  130. package/types/document/resource/storage-decorator.d.ts +98 -0
  131. package/types/document/resource/storage.d.ts +9 -12
  132. package/types/document/type-document.d.ts +68 -0
  133. package/types/http/opra-url-path.d.ts +1 -1
  134. package/types/schema/data-type/complex-type.interface.d.ts +1 -1
  135. package/types/schema/data-type/data-type.interface.d.ts +3 -3
  136. package/types/schema/data-type/enum-type.interface.d.ts +6 -7
  137. package/types/schema/data-type/mapped-type.interface.d.ts +4 -3
  138. package/types/schema/data-type/simple-type.interface.d.ts +3 -3
  139. package/types/schema/data-type/union-type.interface.d.ts +6 -4
  140. package/types/schema/document/api-document.interface.d.ts +11 -0
  141. package/types/schema/document/document-base.interface.d.ts +24 -0
  142. package/types/schema/document/type-document.interface.d.ts +6 -0
  143. package/types/schema/opra-schema.ns.d.ts +3 -1
  144. package/types/schema/resource/collection.interface.d.ts +31 -31
  145. package/types/schema/resource/container.interface.d.ts +4 -3
  146. package/types/schema/resource/resource.interface.d.ts +1 -1
  147. package/types/schema/resource/singleton.interface.d.ts +15 -10
  148. package/types/schema/resource/storage.interface.d.ts +49 -45
  149. package/types/schema/type-guards.d.ts +3 -2
  150. package/cjs/document/decorators/build-operation-decorator.js +0 -27
  151. package/cjs/document/decorators/collection-decorator.js +0 -30
  152. package/cjs/document/decorators/singleton.decorator.js +0 -25
  153. package/cjs/document/decorators/storage.decorator.js +0 -27
  154. package/cjs/document/factory/add-references.js +0 -20
  155. package/cjs/document/factory/create-document.js +0 -83
  156. package/cjs/document/factory/factory.js +0 -66
  157. package/cjs/document/factory/import-resource-class.js +0 -54
  158. package/cjs/document/factory/import-type-class.js +0 -146
  159. package/cjs/document/factory/index.js +0 -4
  160. package/cjs/document/factory/process-resources.js +0 -70
  161. package/cjs/document/factory/process-types.js +0 -191
  162. package/cjs/document/utils/generate-codec.js +0 -39
  163. package/esm/document/decorators/build-operation-decorator.js +0 -23
  164. package/esm/document/decorators/collection-decorator.js +0 -26
  165. package/esm/document/decorators/resource.decorator.js +0 -33
  166. package/esm/document/decorators/singleton.decorator.js +0 -21
  167. package/esm/document/decorators/storage.decorator.js +0 -23
  168. package/esm/document/factory/add-references.js +0 -16
  169. package/esm/document/factory/create-document.js +0 -77
  170. package/esm/document/factory/factory.js +0 -62
  171. package/esm/document/factory/import-resource-class.js +0 -48
  172. package/esm/document/factory/import-type-class.js +0 -136
  173. package/esm/document/factory/index.js +0 -1
  174. package/esm/document/factory/process-resources.js +0 -63
  175. package/esm/document/factory/process-types.js +0 -185
  176. package/esm/document/utils/generate-codec.js +0 -33
  177. package/types/document/decorators/build-operation-decorator.d.ts +0 -13
  178. package/types/document/decorators/collection-decorator.d.ts +0 -33
  179. package/types/document/decorators/resource.decorator.d.ts +0 -9
  180. package/types/document/decorators/singleton.decorator.d.ts +0 -25
  181. package/types/document/decorators/storage.decorator.d.ts +0 -25
  182. package/types/document/factory/add-references.d.ts +0 -4
  183. package/types/document/factory/create-document.d.ts +0 -12
  184. package/types/document/factory/factory.d.ts +0 -63
  185. package/types/document/factory/import-resource-class.d.ts +0 -10
  186. package/types/document/factory/import-type-class.d.ts +0 -17
  187. package/types/document/factory/index.d.ts +0 -1
  188. package/types/document/factory/process-resources.d.ts +0 -9
  189. package/types/document/factory/process-types.d.ts +0 -6
  190. package/types/document/utils/generate-codec.d.ts +0 -10
  191. package/types/schema/document.interface.d.ts +0 -34
  192. /package/cjs/document/{decorators → data-type}/complex-type.decorator.js +0 -0
  193. /package/cjs/document/{decorators → data-type}/simple-type.decorator.js +0 -0
  194. /package/cjs/schema/{document.interface.js → document/api-document.interface.js} +0 -0
  195. /package/esm/document/{decorators → data-type}/complex-type.decorator.js +0 -0
  196. /package/esm/document/{decorators → data-type}/simple-type.decorator.js +0 -0
  197. /package/esm/schema/{document.interface.js → document/api-document.interface.js} +0 -0
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createOperationDecorator = void 0;
4
+ const constants_js_1 = require("../constants.js");
5
+ function createOperationDecorator(operation, options, list) {
6
+ const decorator = ((target, propertyKey) => {
7
+ if (propertyKey !== operation)
8
+ throw new TypeError(`Name of the handler name should be '${operation}'`);
9
+ const resourceMetadata = (Reflect.getOwnMetadata(constants_js_1.RESOURCE_METADATA, target.constructor) || {});
10
+ resourceMetadata.operations = resourceMetadata.operations || {};
11
+ const operationMeta = { ...options };
12
+ resourceMetadata.operations[operation] = operationMeta;
13
+ for (const fn of list)
14
+ fn(operationMeta, target, propertyKey);
15
+ Reflect.defineMetadata(constants_js_1.RESOURCE_METADATA, resourceMetadata, target.constructor);
16
+ });
17
+ decorator.Parameter = (name, arg0) => {
18
+ const parameterOptions = typeof arg0 === 'string' || typeof arg0 === 'function' ? { type: arg0 } : { ...arg0 };
19
+ list.push((operationMeta) => {
20
+ operationMeta.parameters = operationMeta.parameters || {};
21
+ operationMeta.parameters[name] = { ...parameterOptions };
22
+ });
23
+ return decorator;
24
+ };
25
+ return decorator;
26
+ }
27
+ exports.createOperationDecorator = createOperationDecorator;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Parameter = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const vg = tslib_1.__importStar(require("valgen"));
6
+ const index_js_1 = require("../../helpers/index.js");
7
+ /**
8
+ *
9
+ * @class Parameter
10
+ */
11
+ class Parameter {
12
+ constructor(name, init) {
13
+ this.name = name;
14
+ this.type = init.type;
15
+ this.description = init.description;
16
+ this.isArray = init.isArray;
17
+ this.default = init.default;
18
+ this.required = init.required;
19
+ this.deprecated = init.deprecated;
20
+ this.examples = init.examples;
21
+ this.isBuiltin = init.isBuiltin;
22
+ }
23
+ exportSchema(options) {
24
+ return (0, index_js_1.omitUndefined)({
25
+ type: this.type.name ? this.type.name : this.type.exportSchema(options),
26
+ description: this.description,
27
+ isArray: this.isArray,
28
+ default: this.default,
29
+ required: this.required,
30
+ deprecated: this.deprecated,
31
+ examples: this.examples
32
+ });
33
+ }
34
+ getDecoder() {
35
+ if (!this._decoder)
36
+ this._decoder = this.generateCodec('decode');
37
+ return this._decoder;
38
+ }
39
+ getEncoder() {
40
+ if (!this._encoder)
41
+ this._encoder = this.generateCodec('encode');
42
+ return this._encoder;
43
+ }
44
+ generateCodec(codec, options) {
45
+ let fn = this.type.generateCodec(codec, options);
46
+ if (this.isArray)
47
+ fn = vg.stringSplit(',');
48
+ return !options?.partial && this.required ? vg.required(fn) : vg.optional(fn);
49
+ }
50
+ }
51
+ exports.Parameter = Parameter;
@@ -5,10 +5,16 @@ const tslib_1 = require("tslib");
5
5
  const lodash_omit_1 = tslib_1.__importDefault(require("lodash.omit"));
6
6
  const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
7
7
  const constants_js_1 = require("../constants.js");
8
- function ResourceDecorator(kind, options) {
8
+ function ResourceDecorator(kind, meta) {
9
9
  const namePattern = new RegExp(`^(.*)(${kind}|Resource|Controller)$`);
10
10
  return function (target) {
11
- const name = options?.name || namePattern.exec(target.name)?.[1] || target.name;
11
+ let name = meta?.name;
12
+ if (!name) {
13
+ name = namePattern.exec(target.name)?.[1] || target.name;
14
+ // Containers may start with lowercase
15
+ if (kind === 'Container')
16
+ name = name.charAt(0).toLowerCase() + name.substring(1);
17
+ }
12
18
  const metadata = { kind, name };
13
19
  const baseMetadata = Reflect.getOwnMetadata(constants_js_1.RESOURCE_METADATA, Object.getPrototypeOf(target));
14
20
  if (baseMetadata)
@@ -19,20 +25,9 @@ function ResourceDecorator(kind, options) {
19
25
  (0, putil_merge_1.default)(metadata, {
20
26
  kind,
21
27
  name,
22
- ...(0, lodash_omit_1.default)(options, ['kind', 'name', 'controller'])
28
+ ...(0, lodash_omit_1.default)(meta, ['kind', 'name', 'controller'])
23
29
  }, { deep: true });
24
30
  Reflect.defineMetadata(constants_js_1.RESOURCE_METADATA, metadata, target);
25
31
  };
26
32
  }
27
33
  exports.ResourceDecorator = ResourceDecorator;
28
- ResourceDecorator.Action = function (options) {
29
- return (target, propertyKey) => {
30
- if (typeof propertyKey !== 'string')
31
- throw new TypeError(`This decorator can't be used for Symbol keys'`);
32
- const actionMeta = { ...options };
33
- const resourceMetadata = (Reflect.getOwnMetadata(constants_js_1.RESOURCE_METADATA, target.constructor) || {});
34
- resourceMetadata.actions = resourceMetadata.actions || {};
35
- resourceMetadata.actions[propertyKey] = actionMeta;
36
- Reflect.defineMetadata(constants_js_1.RESOURCE_METADATA, resourceMetadata, target.constructor);
37
- };
38
- };
@@ -6,19 +6,34 @@ const object_utils_js_1 = require("../../helpers/object-utils.js");
6
6
  const inspect_util_js_1 = require("../utils/inspect.util.js");
7
7
  const endpoint_js_1 = require("./endpoint.js");
8
8
  class Resource {
9
- constructor(document, init) {
9
+ constructor(parent, init) {
10
10
  this.actions = new index_js_1.ResponsiveMap();
11
- this.document = document;
11
+ if (parent instanceof Resource) {
12
+ this.document = parent.document;
13
+ this.parent = parent;
14
+ }
15
+ else
16
+ this.document = parent;
12
17
  this.name = init.name;
13
18
  this.description = init.description;
14
19
  this.controller = init.controller;
20
+ if (this.controller) {
21
+ this.ctor = Object.getPrototypeOf(this.controller).constructor;
22
+ }
23
+ else
24
+ this.ctor = init.ctor;
15
25
  if (init.actions) {
16
26
  for (const [name, meta] of Object.entries(init.actions)) {
17
- this.actions.set(name, new endpoint_js_1.Endpoint({ ...meta, name }));
27
+ this.actions.set(name, new endpoint_js_1.Endpoint(this, name, meta));
18
28
  }
19
29
  }
20
30
  }
21
- exportSchema() {
31
+ getFullPath() {
32
+ if (this.parent && this.parent.name)
33
+ return this.parent?.getFullPath() + '/' + this.name;
34
+ return this.name;
35
+ }
36
+ exportSchema(options) {
22
37
  const schema = (0, object_utils_js_1.omitUndefined)({
23
38
  kind: this.kind,
24
39
  description: this.description,
@@ -26,7 +41,7 @@ class Resource {
26
41
  if (this.actions.size) {
27
42
  schema.actions = {};
28
43
  for (const action of this.actions.values()) {
29
- schema.actions[action.name] = action.exportSchema();
44
+ schema.actions[action.name] = action.exportSchema(options);
30
45
  }
31
46
  }
32
47
  return schema;
@@ -1,53 +1,73 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SingletonClass = void 0;
4
- const index_js_1 = require("../../helpers/index.js");
5
- const index_js_2 = require("../../schema/index.js");
6
- const generate_codec_js_1 = require("../utils/generate-codec.js");
7
- const resource_js_1 = require("./resource.js");
8
- class SingletonClass extends resource_js_1.Resource {
9
- constructor(document, init) {
10
- super(document, init);
11
- this._decoders = {};
12
- this._encoders = {};
13
- this.kind = index_js_2.OpraSchema.Singleton.Kind;
14
- this.controller = init.controller;
15
- this.operations = { ...init.operations };
4
+ const index_js_1 = require("../../schema/index.js");
5
+ const crud_resource_js_1 = require("./crud-resource.js");
6
+ class SingletonClass extends crud_resource_js_1.CrudResource {
7
+ constructor(parent, init) {
8
+ super(parent, init);
9
+ this.kind = index_js_1.OpraSchema.Singleton.Kind;
16
10
  this.type = init.type;
11
+ // ------------------
12
+ let endpoint = this.operations.get('create');
13
+ if (endpoint) {
14
+ endpoint.returnType = this.type;
15
+ endpoint.decode = this.type.generateCodec('decode', {
16
+ partial: true,
17
+ pick: endpoint.inputPickFields,
18
+ omit: endpoint.inputOmitFields,
19
+ });
20
+ endpoint.encode = this.type.generateCodec('encode', {
21
+ partial: true,
22
+ pick: endpoint.outputPickFields,
23
+ omit: endpoint.outputOmitFields,
24
+ });
25
+ endpoint.defineParameter('pick', { type: 'string', isArray: true, isBuiltin: true });
26
+ endpoint.defineParameter('omit', { type: 'string', isArray: true, isBuiltin: true });
27
+ endpoint.defineParameter('include', { type: 'string', isArray: true, isBuiltin: true });
28
+ }
29
+ // ------------------
30
+ endpoint = this.operations.get('get');
31
+ if (endpoint) {
32
+ endpoint.returnType = this.type;
33
+ endpoint.encode = this.type.generateCodec('encode', {
34
+ partial: true,
35
+ pick: endpoint.outputPickFields,
36
+ omit: endpoint.outputOmitFields,
37
+ });
38
+ endpoint.defineParameter('pick', { type: 'string', isArray: true, isBuiltin: true });
39
+ endpoint.defineParameter('omit', { type: 'string', isArray: true, isBuiltin: true });
40
+ endpoint.defineParameter('include', { type: 'string', isArray: true, isBuiltin: true });
41
+ }
42
+ // ------------------
43
+ endpoint = this.operations.get('update');
44
+ if (endpoint) {
45
+ endpoint.returnType = this.type;
46
+ endpoint.decode = this.type.generateCodec('decode', {
47
+ pick: endpoint.inputPickFields,
48
+ omit: endpoint.inputOmitFields,
49
+ });
50
+ endpoint.encode = this.type.generateCodec('encode', {
51
+ partial: true,
52
+ pick: endpoint.outputPickFields,
53
+ omit: endpoint.outputOmitFields,
54
+ });
55
+ endpoint.defineParameter('pick', { type: 'string', isArray: true, isBuiltin: true });
56
+ endpoint.defineParameter('omit', { type: 'string', isArray: true, isBuiltin: true });
57
+ endpoint.defineParameter('include', { type: 'string', isArray: true, isBuiltin: true });
58
+ }
17
59
  }
18
- exportSchema() {
60
+ getOperation(name) {
61
+ return super.getOperation(name);
62
+ }
63
+ exportSchema(options) {
19
64
  return {
20
- ...super.exportSchema(),
21
- ...(0, index_js_1.omitUndefined)({
22
- type: this.type.name || 'any',
23
- operations: this.operations
24
- })
65
+ ...super.exportSchema(options),
66
+ type: this.type.name || 'any'
25
67
  };
26
68
  }
27
69
  normalizeFieldPath(path) {
28
70
  return this.type.normalizeFieldPath(path);
29
71
  }
30
- getDecoder(endpoint) {
31
- let decoder = this._decoders[endpoint];
32
- if (decoder)
33
- return decoder;
34
- const options = {
35
- partial: endpoint !== 'create'
36
- };
37
- decoder = (0, generate_codec_js_1.generateCodec)(this.type, 'decode', options);
38
- this._decoders[endpoint] = decoder;
39
- return decoder;
40
- }
41
- getEncoder(endpoint) {
42
- let encoder = this._encoders[endpoint];
43
- if (encoder)
44
- return encoder;
45
- const options = {
46
- partial: true
47
- };
48
- encoder = (0, generate_codec_js_1.generateCodec)(this.type, 'encode', options);
49
- this._encoders[endpoint] = encoder;
50
- return encoder;
51
- }
52
72
  }
53
73
  exports.SingletonClass = SingletonClass;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SingletonDecorator = void 0;
4
+ const index_js_1 = require("../../schema/index.js");
5
+ const action_decorator_js_1 = require("./action-decorator.js");
6
+ const collection_decorator_js_1 = require("./collection-decorator.js");
7
+ const resource_decorator_js_1 = require("./resource-decorator.js");
8
+ const operationProperties = ['create', 'delete', 'get', 'update'];
9
+ function SingletonDecorator(type, options) {
10
+ return (0, resource_decorator_js_1.ResourceDecorator)(index_js_1.OpraSchema.Singleton.Kind, { ...options, type });
11
+ }
12
+ exports.SingletonDecorator = SingletonDecorator;
13
+ Object.assign(SingletonDecorator, resource_decorator_js_1.ResourceDecorator);
14
+ /*
15
+ * Action PropertyDecorator
16
+ */
17
+ (function (SingletonDecorator) {
18
+ /**
19
+ * Action PropertyDecorator
20
+ */
21
+ function Action(options) {
22
+ const list = [];
23
+ return (0, action_decorator_js_1.createActionDecorator)(options, operationProperties, list);
24
+ }
25
+ SingletonDecorator.Action = Action;
26
+ function Create(options) {
27
+ return collection_decorator_js_1.CollectionDecorator.Create(options);
28
+ }
29
+ SingletonDecorator.Create = Create;
30
+ })(SingletonDecorator || (exports.SingletonDecorator = SingletonDecorator = {}));
31
+ /*
32
+ * Get PropertyDecorator
33
+ */
34
+ (function (SingletonDecorator) {
35
+ function Get(options) {
36
+ return collection_decorator_js_1.CollectionDecorator.Get(options);
37
+ }
38
+ SingletonDecorator.Get = Get;
39
+ })(SingletonDecorator || (exports.SingletonDecorator = SingletonDecorator = {}));
40
+ /*
41
+ * Delete PropertyDecorator
42
+ */
43
+ (function (SingletonDecorator) {
44
+ function Delete(options) {
45
+ return collection_decorator_js_1.CollectionDecorator.Delete(options);
46
+ }
47
+ SingletonDecorator.Delete = Delete;
48
+ })(SingletonDecorator || (exports.SingletonDecorator = SingletonDecorator = {}));
49
+ /*
50
+ * Update PropertyDecorator
51
+ */
52
+ (function (SingletonDecorator) {
53
+ function Update(options) {
54
+ return collection_decorator_js_1.CollectionDecorator.Update(options);
55
+ }
56
+ SingletonDecorator.Update = Update;
57
+ })(SingletonDecorator || (exports.SingletonDecorator = SingletonDecorator = {}));
@@ -4,21 +4,21 @@ exports.Singleton = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
6
6
  const constants_js_1 = require("../constants.js");
7
- const singleton_decorator_js_1 = require("../decorators/singleton.decorator.js");
8
7
  const singleton_class_js_1 = require("./singleton-class.js");
8
+ const singleton_decorator_js_1 = require("./singleton-decorator.js");
9
9
  /**
10
10
  * @class Singleton
11
11
  * @decorator Singleton
12
12
  */
13
13
  exports.Singleton = function (...args) {
14
- // ClassDecorator
14
+ // Decorator
15
15
  if (!this) {
16
16
  const [type, options] = args;
17
17
  return exports.Singleton[constants_js_1.DECORATOR].call(undefined, type, options);
18
18
  }
19
19
  // Constructor
20
- const [document, init] = args;
21
- (0, putil_merge_1.default)(this, new singleton_class_js_1.SingletonClass(document, init), { descriptor: true });
20
+ const [parent, init] = args;
21
+ (0, putil_merge_1.default)(this, new singleton_class_js_1.SingletonClass(parent, init), { descriptor: true });
22
22
  };
23
23
  exports.Singleton.prototype = singleton_class_js_1.SingletonClass.prototype;
24
24
  Object.assign(exports.Singleton, singleton_decorator_js_1.SingletonDecorator);
@@ -1,24 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StorageClass = void 0;
4
- const index_js_1 = require("../../helpers/index.js");
5
- const index_js_2 = require("../../schema/index.js");
6
- const resource_js_1 = require("./resource.js");
7
- class StorageClass extends resource_js_1.Resource {
8
- constructor(document, init) {
9
- super(document, init);
10
- this.kind = index_js_2.OpraSchema.Storage.Kind;
11
- this.controller = init.controller;
12
- this.operations = { ...init.operations };
4
+ const index_js_1 = require("../../schema/index.js");
5
+ const crud_resource_js_1 = require("./crud-resource.js");
6
+ class StorageClass extends crud_resource_js_1.CrudResource {
7
+ constructor(parent, init) {
8
+ super(parent, init);
9
+ this.kind = index_js_1.OpraSchema.Storage.Kind;
13
10
  }
14
- exportSchema() {
15
- return {
16
- ...super.exportSchema(),
17
- ...(0, index_js_1.omitUndefined)({
18
- kind: index_js_2.OpraSchema.Storage.Kind,
19
- operations: this.operations
20
- })
21
- };
11
+ getOperation(name) {
12
+ return super.getOperation(name);
13
+ }
14
+ exportSchema(options) {
15
+ return super.exportSchema(options);
22
16
  }
23
17
  }
24
18
  exports.StorageClass = StorageClass;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StorageDecorator = void 0;
4
+ const index_js_1 = require("../../schema/index.js");
5
+ const action_decorator_js_1 = require("./action-decorator.js");
6
+ const operation_decorator_js_1 = require("./operation-decorator.js");
7
+ const resource_decorator_js_1 = require("./resource-decorator.js");
8
+ const operationProperties = ['delete', 'get', 'post'];
9
+ function StorageDecorator(options) {
10
+ return (0, resource_decorator_js_1.ResourceDecorator)(index_js_1.OpraSchema.Storage.Kind, options);
11
+ }
12
+ exports.StorageDecorator = StorageDecorator;
13
+ Object.assign(StorageDecorator, resource_decorator_js_1.ResourceDecorator);
14
+ /*
15
+ * Action PropertyDecorator
16
+ */
17
+ (function (StorageDecorator) {
18
+ /**
19
+ * Action PropertyDecorator
20
+ */
21
+ function Action(options) {
22
+ const list = [];
23
+ return (0, action_decorator_js_1.createActionDecorator)(options, operationProperties, list);
24
+ }
25
+ StorageDecorator.Action = Action;
26
+ function Delete(options) {
27
+ const list = [];
28
+ return (0, operation_decorator_js_1.createOperationDecorator)('delete', options, list);
29
+ }
30
+ StorageDecorator.Delete = Delete;
31
+ function Get(options) {
32
+ const list = [];
33
+ return (0, operation_decorator_js_1.createOperationDecorator)('get', options, list);
34
+ }
35
+ StorageDecorator.Get = Get;
36
+ function Post(options) {
37
+ const list = [];
38
+ const decorator = (0, operation_decorator_js_1.createOperationDecorator)('post', options, list);
39
+ decorator.MaxFields = (amount) => {
40
+ list.push(operationMeta => operationMeta.maxFields = amount);
41
+ return decorator;
42
+ };
43
+ decorator.MaxFieldSize = (amount) => {
44
+ list.push(operationMeta => operationMeta.maxFieldsSize = amount);
45
+ return decorator;
46
+ };
47
+ decorator.MaxFiles = (amount) => {
48
+ list.push(operationMeta => operationMeta.maxFiles = amount);
49
+ return decorator;
50
+ };
51
+ decorator.MaxFileSize = (sizeInBytes) => {
52
+ list.push(operationMeta => operationMeta.maxFileSize = sizeInBytes);
53
+ return decorator;
54
+ };
55
+ decorator.MaxTotalFileSize = (sizeInBytes) => {
56
+ list.push(operationMeta => operationMeta.maxTotalFileSize = sizeInBytes);
57
+ return decorator;
58
+ };
59
+ decorator.MinFileSize = (sizeInBytes) => {
60
+ list.push(operationMeta => operationMeta.minFileSize = sizeInBytes);
61
+ return decorator;
62
+ };
63
+ return decorator;
64
+ }
65
+ StorageDecorator.Post = Post;
66
+ })(StorageDecorator || (exports.StorageDecorator = StorageDecorator = {}));
@@ -4,8 +4,8 @@ exports.Storage = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
6
6
  const constants_js_1 = require("../constants.js");
7
- const storage_decorator_js_1 = require("../decorators/storage.decorator.js");
8
7
  const storage_class_js_1 = require("./storage-class.js");
8
+ const storage_decorator_js_1 = require("./storage-decorator.js");
9
9
  /**
10
10
  * @class Storage
11
11
  * @decorator Storage
@@ -17,8 +17,8 @@ exports.Storage = function (...args) {
17
17
  return exports.Storage[constants_js_1.DECORATOR].call(undefined, options);
18
18
  }
19
19
  // Constructor
20
- const [document, init] = args;
21
- (0, putil_merge_1.default)(this, new storage_class_js_1.StorageClass(document, init), { descriptor: true });
20
+ const [parent, init] = args;
21
+ (0, putil_merge_1.default)(this, new storage_class_js_1.StorageClass(parent, init), { descriptor: true });
22
22
  };
23
23
  exports.Storage.prototype = storage_class_js_1.StorageClass.prototype;
24
24
  Object.assign(exports.Storage, storage_decorator_js_1.StorageDecorator);