@opra/common 0.16.2 → 0.17.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 (149) hide show
  1. package/cjs/document/constants.js +1 -1
  2. package/cjs/document/data-type/complex-type.js +69 -56
  3. package/cjs/document/data-type/simple-type.js +0 -1
  4. package/cjs/document/resource/collection.js +15 -16
  5. package/cjs/document/resource/singleton.js +2 -2
  6. package/cjs/http/http-params.js +10 -11
  7. package/esm/document/api-document.js +33 -37
  8. package/esm/document/constants.js +3 -6
  9. package/esm/document/data-type/api-field.js +12 -15
  10. package/esm/document/data-type/builtin/any.type.js +5 -8
  11. package/esm/document/data-type/builtin/base64.type.js +5 -8
  12. package/esm/document/data-type/builtin/bigint.type.js +5 -8
  13. package/esm/document/data-type/builtin/boolean.type.js +8 -11
  14. package/esm/document/data-type/builtin/date.type.js +7 -10
  15. package/esm/document/data-type/builtin/guid.type.js +9 -12
  16. package/esm/document/data-type/builtin/index.js +10 -13
  17. package/esm/document/data-type/builtin/integer.type.js +10 -13
  18. package/esm/document/data-type/builtin/number.type.js +7 -10
  19. package/esm/document/data-type/builtin/object.type.js +5 -8
  20. package/esm/document/data-type/builtin/string.type.js +8 -11
  21. package/esm/document/data-type/builtin/time.type.js +7 -10
  22. package/esm/document/data-type/builtin/timestamp.type.js +9 -12
  23. package/esm/document/data-type/complex-type.js +94 -85
  24. package/esm/document/data-type/data-type.js +9 -12
  25. package/esm/document/data-type/enum-type.js +15 -19
  26. package/esm/document/data-type/mapped-type.js +24 -29
  27. package/esm/document/data-type/simple-type.js +17 -22
  28. package/esm/document/data-type/union-type.js +26 -29
  29. package/esm/document/factory/add-references.js +3 -7
  30. package/esm/document/factory/create-document.js +10 -16
  31. package/esm/document/factory/factory.js +33 -37
  32. package/esm/document/factory/import-resource-class.js +16 -22
  33. package/esm/document/factory/import-type-class.js +24 -34
  34. package/esm/document/factory/index.js +1 -4
  35. package/esm/document/factory/process-resources.js +10 -16
  36. package/esm/document/factory/process-types.js +31 -37
  37. package/esm/document/index.js +14 -17
  38. package/esm/document/resource/collection.js +58 -63
  39. package/esm/document/resource/resource.js +9 -12
  40. package/esm/document/resource/singleton.js +27 -31
  41. package/esm/document/utils/inspect.util.js +4 -7
  42. package/esm/document/utils/string-compare.util.js +1 -5
  43. package/esm/exception/enums/issue-severity.enum.js +2 -5
  44. package/esm/exception/error-issue.js +1 -2
  45. package/esm/exception/http-errors/bad-request.error.js +4 -8
  46. package/esm/exception/http-errors/failed-dependency.error.js +4 -8
  47. package/esm/exception/http-errors/forbidden.error.js +4 -8
  48. package/esm/exception/http-errors/internal-server.error.js +4 -8
  49. package/esm/exception/http-errors/method-not-allowed.error.js +4 -8
  50. package/esm/exception/http-errors/not-acceptable.error.js +4 -8
  51. package/esm/exception/http-errors/not-found.error.js +4 -8
  52. package/esm/exception/http-errors/unauthorized.error.js +4 -8
  53. package/esm/exception/http-errors/unprocessable-entity.error.js +4 -8
  54. package/esm/exception/index.js +15 -18
  55. package/esm/exception/opra-exception.js +3 -7
  56. package/esm/exception/resource-errors/resource-conflict.error.js +4 -8
  57. package/esm/exception/resource-errors/resource-not-found.error.js +4 -8
  58. package/esm/exception/wrap-exception.js +20 -24
  59. package/esm/filter/antlr/OpraFilterLexer.js +6 -9
  60. package/esm/filter/antlr/OpraFilterListener.js +2 -5
  61. package/esm/filter/antlr/OpraFilterParser.js +79 -126
  62. package/esm/filter/antlr/OpraFilterVisitor.js +2 -5
  63. package/esm/filter/ast/abstract/ast.js +1 -5
  64. package/esm/filter/ast/abstract/expression.js +2 -6
  65. package/esm/filter/ast/abstract/literal.js +2 -6
  66. package/esm/filter/ast/abstract/term.js +2 -6
  67. package/esm/filter/ast/expressions/arithmetic-expression.js +3 -8
  68. package/esm/filter/ast/expressions/array-expression.js +2 -6
  69. package/esm/filter/ast/expressions/comparison-expression.js +2 -6
  70. package/esm/filter/ast/expressions/logical-expression.js +2 -6
  71. package/esm/filter/ast/expressions/parentheses-expression.js +2 -6
  72. package/esm/filter/ast/index.js +16 -19
  73. package/esm/filter/ast/terms/boolean-literal.js +2 -6
  74. package/esm/filter/ast/terms/date-literal.js +8 -12
  75. package/esm/filter/ast/terms/external-constant.js +2 -6
  76. package/esm/filter/ast/terms/null-literal.js +2 -6
  77. package/esm/filter/ast/terms/number-literal.js +4 -8
  78. package/esm/filter/ast/terms/qualified-identifier.js +2 -6
  79. package/esm/filter/ast/terms/string-literal.js +4 -8
  80. package/esm/filter/ast/terms/time-literal.js +6 -10
  81. package/esm/filter/build.js +45 -69
  82. package/esm/filter/errors.js +3 -9
  83. package/esm/filter/filter-tree-visitor.js +26 -31
  84. package/esm/filter/index.js +5 -8
  85. package/esm/filter/opra-error-listener.js +4 -8
  86. package/esm/filter/parse.js +14 -19
  87. package/esm/filter/utils.js +2 -7
  88. package/esm/helpers/function-utils.js +8 -14
  89. package/esm/helpers/get-stack-filename.js +1 -5
  90. package/esm/helpers/index.js +8 -11
  91. package/esm/helpers/is-url.js +1 -5
  92. package/esm/helpers/mixin-utils.js +2 -7
  93. package/esm/helpers/object-utils.js +6 -12
  94. package/esm/helpers/path-to-object-tree.js +1 -5
  95. package/esm/helpers/responsive-map.js +1 -5
  96. package/esm/helpers/type-guards.js +7 -17
  97. package/esm/http/codecs/boolean-codec.js +1 -5
  98. package/esm/http/codecs/date-codec.js +1 -5
  99. package/esm/http/codecs/filter-codec.js +5 -9
  100. package/esm/http/codecs/integer-codec.js +2 -6
  101. package/esm/http/codecs/number-codec.js +1 -5
  102. package/esm/http/codecs/string-codec.js +1 -5
  103. package/esm/http/enums/http-headers-codes.enum.js +2 -5
  104. package/esm/http/enums/http-status-codes.enum.js +2 -5
  105. package/esm/http/enums/http-status-messages.js +1 -4
  106. package/esm/http/http-headers.js +5 -9
  107. package/esm/http/http-message.host.js +13 -18
  108. package/esm/http/http-params.js +30 -36
  109. package/esm/http/http-request-message.js +18 -22
  110. package/esm/http/http-response-message.js +23 -28
  111. package/esm/http/index.js +14 -17
  112. package/esm/http/interfaces/client-http-headers.interface.js +1 -2
  113. package/esm/http/interfaces/cookie-options.interface.js +1 -2
  114. package/esm/http/interfaces/server-http-headers.interface.js +1 -2
  115. package/esm/i18n/i18n.js +23 -28
  116. package/esm/i18n/index.js +5 -9
  117. package/esm/i18n/string-utils.js +2 -7
  118. package/esm/i18n/translate.js +3 -7
  119. package/esm/index.js +11 -16
  120. package/esm/schema/constants.js +1 -4
  121. package/esm/schema/data-type/complex-type.interface.js +2 -5
  122. package/esm/schema/data-type/data-type.interface.js +1 -2
  123. package/esm/schema/data-type/enum-type.interface.js +2 -5
  124. package/esm/schema/data-type/field.interface.js +1 -2
  125. package/esm/schema/data-type/mapped-type.interface.js +2 -5
  126. package/esm/schema/data-type/simple-type.interface.js +2 -5
  127. package/esm/schema/data-type/union-type.interface.js +2 -5
  128. package/esm/schema/document.interface.js +1 -2
  129. package/esm/schema/index.js +31 -34
  130. package/esm/schema/resource/collection.interface.js +2 -5
  131. package/esm/schema/resource/container.interface.js +2 -5
  132. package/esm/schema/resource/endpoint.interface.js +1 -2
  133. package/esm/schema/resource/resource.interface.js +1 -2
  134. package/esm/schema/resource/singleton.interface.js +2 -5
  135. package/esm/schema/type-guards.js +40 -53
  136. package/esm/types.js +1 -2
  137. package/esm/url/index.js +5 -8
  138. package/esm/url/opra-url-path-component.js +3 -7
  139. package/esm/url/opra-url-path.js +14 -18
  140. package/esm/url/opra-url.js +15 -19
  141. package/esm/url/utils/decode-path-component.js +4 -8
  142. package/esm/url/utils/encode-path-component.js +3 -8
  143. package/esm/utils/path-utils.js +2 -7
  144. package/package.json +1 -1
  145. package/types/document/data-type/complex-type.d.ts +8 -2
  146. package/types/document/resource/collection.d.ts +5 -3
  147. package/types/document/resource/singleton.d.ts +3 -1
  148. package/types/filter/ast/terms/qualified-identifier.d.ts +4 -0
  149. package/types/http/http-params.d.ts +20 -19
@@ -1,32 +1,28 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Singleton = void 0;
4
- const tslib_1 = require("tslib");
5
- const lodash_omit_1 = tslib_1.__importDefault(require("lodash.omit"));
6
- const index_js_1 = require("../../helpers/index.js");
7
- const index_js_2 = require("../../schema/index.js");
8
- const constants_js_1 = require("../constants.js");
9
- const resource_js_1 = require("./resource.js");
1
+ import omit from 'lodash.omit';
2
+ import { omitUndefined } from '../../helpers/index.js';
3
+ import { OpraSchema } from '../../schema/index.js';
4
+ import { METADATA_KEY } from '../constants.js';
5
+ import { Resource } from './resource.js';
10
6
  const NESTJS_INJECTABLE_WATERMARK = '__injectable__';
11
7
  const NAME_PATTERN = /^(.*)(Resource|Singleton)$/;
12
- exports.Singleton = function (...args) {
8
+ export const Singleton = function (...args) {
13
9
  // ClassDecorator
14
10
  if (!this) {
15
11
  const [type, options] = args;
16
12
  return function (target) {
17
13
  const name = options?.name || target.name.match(NAME_PATTERN)?.[1] || target.name;
18
- const metadata = Reflect.getOwnMetadata(constants_js_1.METADATA_KEY, target) || {};
19
- metadata.kind = index_js_2.OpraSchema.Singleton.Kind;
14
+ const metadata = Reflect.getOwnMetadata(METADATA_KEY, target) || {};
15
+ metadata.kind = OpraSchema.Singleton.Kind;
20
16
  metadata.name = name;
21
17
  metadata.type = type;
22
18
  // Merge with previous metadata object
23
- const m = Reflect.getMetadata(constants_js_1.METADATA_KEY, target);
19
+ const m = Reflect.getMetadata(METADATA_KEY, target);
24
20
  if (m && metadata !== m)
25
- Object.assign(metadata, (0, lodash_omit_1.default)(m), Object.keys(metadata));
21
+ Object.assign(metadata, omit(m), Object.keys(metadata));
26
22
  // Merge options
27
23
  if (options)
28
- Object.assign(metadata, (0, lodash_omit_1.default)(options, ['kind', 'name', 'type', 'controller']));
29
- Reflect.defineMetadata(constants_js_1.METADATA_KEY, metadata, target);
24
+ Object.assign(metadata, omit(options, ['kind', 'name', 'type', 'controller']));
25
+ Reflect.defineMetadata(METADATA_KEY, metadata, target);
30
26
  /* Define Injectable metadata for NestJS support*/
31
27
  Reflect.defineMetadata(NESTJS_INJECTABLE_WATERMARK, true, target);
32
28
  };
@@ -34,14 +30,14 @@ exports.Singleton = function (...args) {
34
30
  // Constructor
35
31
  const [document, init] = args;
36
32
  // call super()
37
- resource_js_1.Resource.apply(this, [document, init]);
33
+ Resource.apply(this, [document, init]);
38
34
  };
39
35
  const proto = {
40
36
  _construct(init) {
41
37
  // call super()
42
- resource_js_1.Resource.prototype._construct.call(this, init);
38
+ Resource.prototype._construct.call(this, init);
43
39
  const _this = this;
44
- _this.kind = index_js_2.OpraSchema.Singleton.Kind;
40
+ _this.kind = OpraSchema.Singleton.Kind;
45
41
  _this.controller = init.controller;
46
42
  const operations = _this.operations = init.operations || {};
47
43
  _this.type = init.type;
@@ -60,32 +56,32 @@ const proto = {
60
56
  }
61
57
  },
62
58
  exportSchema() {
63
- const out = resource_js_1.Resource.prototype.exportSchema.call(this);
64
- Object.assign(out, (0, index_js_1.omitUndefined)({
59
+ const out = Resource.prototype.exportSchema.call(this);
60
+ Object.assign(out, omitUndefined({
65
61
  type: this.type.name,
66
62
  operations: this.operations
67
63
  }));
68
64
  return out;
69
65
  },
70
- normalizeFieldNames(fields) {
71
- return this.type.normalizeFieldNames(fields);
66
+ normalizeFieldPath(path) {
67
+ return this.type.normalizeFieldPath(path);
72
68
  },
73
69
  };
74
- Object.assign(exports.Singleton.prototype, proto);
75
- Object.setPrototypeOf(exports.Singleton.prototype, resource_js_1.Resource.prototype);
70
+ Object.assign(Singleton.prototype, proto);
71
+ Object.setPrototypeOf(Singleton.prototype, Resource.prototype);
76
72
  function createOperationDecorator(operation) {
77
73
  return (options) => ((target, propertyKey) => {
78
74
  const metadata = {
79
75
  ...options,
80
76
  handlerName: propertyKey
81
77
  };
82
- const resourceMetadata = (Reflect.getOwnMetadata(constants_js_1.METADATA_KEY, target.constructor) || {});
78
+ const resourceMetadata = (Reflect.getOwnMetadata(METADATA_KEY, target.constructor) || {});
83
79
  resourceMetadata.operations = resourceMetadata.operations || {};
84
80
  resourceMetadata.operations[operation] = metadata;
85
- Reflect.defineMetadata(constants_js_1.METADATA_KEY, resourceMetadata, target.constructor);
81
+ Reflect.defineMetadata(METADATA_KEY, resourceMetadata, target.constructor);
86
82
  });
87
83
  }
88
- exports.Singleton.Create = createOperationDecorator('create');
89
- exports.Singleton.Get = createOperationDecorator('get');
90
- exports.Singleton.Delete = createOperationDecorator('delete');
91
- exports.Singleton.Update = createOperationDecorator('update');
84
+ Singleton.Create = createOperationDecorator('create');
85
+ Singleton.Get = createOperationDecorator('get');
86
+ Singleton.Delete = createOperationDecorator('delete');
87
+ Singleton.Update = createOperationDecorator('update');
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.colorFgMagenta = exports.colorFgYellow = exports.colorReset = exports.nodeInspectCustom = void 0;
4
- exports.nodeInspectCustom = Symbol.for('nodejs.util.inspect.custom');
5
- exports.colorReset = "\x1b[0m";
6
- exports.colorFgYellow = "\x1b[33m";
7
- exports.colorFgMagenta = "\x1b[35m";
1
+ export const nodeInspectCustom = Symbol.for('nodejs.util.inspect.custom');
2
+ export const colorReset = "\x1b[0m";
3
+ export const colorFgYellow = "\x1b[33m";
4
+ export const colorFgMagenta = "\x1b[35m";
@@ -1,11 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stringCompare = void 0;
4
- function stringCompare(a, b) {
1
+ export function stringCompare(a, b) {
5
2
  if (a < b)
6
3
  return -1;
7
4
  if (a > b)
8
5
  return 1;
9
6
  return 0;
10
7
  }
11
- exports.stringCompare = stringCompare;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IssueSeverity = void 0;
4
- var IssueSeverity;
1
+ export var IssueSeverity;
5
2
  (function (IssueSeverity) {
6
3
  let Enum;
7
4
  (function (Enum) {
@@ -20,4 +17,4 @@ var IssueSeverity;
20
17
  'may cause it to be performed suboptimally or in a way that is not as desired',
21
18
  info: 'The issue has no relation to the degree of success of the action'
22
19
  };
23
- })(IssueSeverity = exports.IssueSeverity || (exports.IssueSeverity = {}));
20
+ })(IssueSeverity || (IssueSeverity = {}));
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,25 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BadRequestError = void 0;
4
- const index_js_1 = require("../../i18n/index.js");
5
- const opra_exception_js_1 = require("../opra-exception.js");
1
+ import { translate } from '../../i18n/index.js';
2
+ import { OpraException } from '../opra-exception.js';
6
3
  /**
7
4
  * 400 Bad Request
8
5
  * The server cannot or will not process the request due to something that is perceived to be a client error
9
6
  * (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
10
7
  */
11
- class BadRequestError extends opra_exception_js_1.OpraException {
8
+ export class BadRequestError extends OpraException {
12
9
  constructor() {
13
10
  super(...arguments);
14
11
  this.status = 400;
15
12
  }
16
13
  setIssue(issue) {
17
14
  super.setIssue({
18
- message: (0, index_js_1.translate)('error:BAD_REQUEST', 'Bad request'),
15
+ message: translate('error:BAD_REQUEST', 'Bad request'),
19
16
  severity: 'error',
20
17
  code: 'BAD_REQUEST',
21
18
  ...issue
22
19
  });
23
20
  }
24
21
  }
25
- exports.BadRequestError = BadRequestError;
@@ -1,24 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FailedDependencyError = void 0;
4
- const index_js_1 = require("../../i18n/index.js");
5
- const opra_exception_js_1 = require("../opra-exception.js");
1
+ import { translate } from '../../i18n/index.js';
2
+ import { OpraException } from '../opra-exception.js';
6
3
  /**
7
4
  * 424 Failed Dependency
8
5
  * The request failed due to failure of a previous request.
9
6
  */
10
- class FailedDependencyError extends opra_exception_js_1.OpraException {
7
+ export class FailedDependencyError extends OpraException {
11
8
  constructor() {
12
9
  super(...arguments);
13
10
  this.status = 424;
14
11
  }
15
12
  setIssue(issue) {
16
13
  super.setIssue({
17
- message: (0, index_js_1.translate)('error:FAILED_DEPENDENCY', 'The request failed due to failure of a previous request'),
14
+ message: translate('error:FAILED_DEPENDENCY', 'The request failed due to failure of a previous request'),
18
15
  severity: 'error',
19
16
  code: 'FAILED_DEPENDENCY',
20
17
  ...issue
21
18
  });
22
19
  }
23
20
  }
24
- exports.FailedDependencyError = FailedDependencyError;
@@ -1,26 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ForbiddenError = void 0;
4
- const index_js_1 = require("../../i18n/index.js");
5
- const opra_exception_js_1 = require("../opra-exception.js");
1
+ import { translate } from '../../i18n/index.js';
2
+ import { OpraException } from '../opra-exception.js';
6
3
  /**
7
4
  * 403 Forbidden
8
5
  * The client does not have access rights to the content; that is, it is unauthorized,
9
6
  * so the server is refusing to give the requested resource. Unlike 401 Unauthorized,
10
7
  * the client's identity is known to the server.
11
8
  */
12
- class ForbiddenError extends opra_exception_js_1.OpraException {
9
+ export class ForbiddenError extends OpraException {
13
10
  constructor() {
14
11
  super(...arguments);
15
12
  this.status = 403;
16
13
  }
17
14
  setIssue(issue) {
18
15
  super.setIssue({
19
- message: (0, index_js_1.translate)('error:FORBIDDEN', 'You are not authorized to perform this action'),
16
+ message: translate('error:FORBIDDEN', 'You are not authorized to perform this action'),
20
17
  severity: 'error',
21
18
  code: 'FORBIDDEN',
22
19
  ...issue
23
20
  });
24
21
  }
25
22
  }
26
- exports.ForbiddenError = ForbiddenError;
@@ -1,24 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InternalServerError = void 0;
4
- const index_js_1 = require("../../i18n/index.js");
5
- const opra_exception_js_1 = require("../opra-exception.js");
1
+ import { translate } from '../../i18n/index.js';
2
+ import { OpraException } from '../opra-exception.js';
6
3
  /**
7
4
  * 500 Internal Server Error
8
5
  * The server has encountered a situation it does not know how to handle.
9
6
  */
10
- class InternalServerError extends opra_exception_js_1.OpraException {
7
+ export class InternalServerError extends OpraException {
11
8
  constructor() {
12
9
  super(...arguments);
13
10
  this.status = 500;
14
11
  }
15
12
  setIssue(issue) {
16
13
  super.setIssue({
17
- message: (0, index_js_1.translate)('error:INTERNAL_SERVER_ERROR', 'Internal server error'),
14
+ message: translate('error:INTERNAL_SERVER_ERROR', 'Internal server error'),
18
15
  severity: 'error',
19
16
  code: 'INTERNAL_SERVER_ERROR',
20
17
  ...issue
21
18
  });
22
19
  }
23
20
  }
24
- exports.InternalServerError = InternalServerError;
@@ -1,25 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MethodNotAllowedError = void 0;
4
- const index_js_1 = require("../../i18n/index.js");
5
- const opra_exception_js_1 = require("../opra-exception.js");
1
+ import { translate } from '../../i18n/index.js';
2
+ import { OpraException } from '../opra-exception.js';
6
3
  /**
7
4
  * 405 Method Not Allowed
8
5
  * The request method is known by the server but is not supported by the target resource.
9
6
  * For example, an API may not allow calling DELETE to remove a resource.
10
7
  */
11
- class MethodNotAllowedError extends opra_exception_js_1.OpraException {
8
+ export class MethodNotAllowedError extends OpraException {
12
9
  constructor() {
13
10
  super(...arguments);
14
11
  this.status = 405;
15
12
  }
16
13
  setIssue(issue) {
17
14
  super.setIssue({
18
- message: (0, index_js_1.translate)('error:METHOD_NOT_ALLOWED', 'Method not allowed'),
15
+ message: translate('error:METHOD_NOT_ALLOWED', 'Method not allowed'),
19
16
  severity: 'error',
20
17
  code: 'METHOD_NOT_ALLOWED',
21
18
  ...issue
22
19
  });
23
20
  }
24
21
  }
25
- exports.MethodNotAllowedError = MethodNotAllowedError;
@@ -1,25 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NotAcceptableError = void 0;
4
- const index_js_1 = require("../../i18n/index.js");
5
- const opra_exception_js_1 = require("../opra-exception.js");
1
+ import { translate } from '../../i18n/index.js';
2
+ import { OpraException } from '../opra-exception.js';
6
3
  /**
7
4
  * 406 Not Acceptable
8
5
  * This response is sent when the web server, after performing server-driven content negotiation,
9
6
  * doesn't find any content that conforms to the criteria given by the user agent.
10
7
  */
11
- class NotAcceptableError extends opra_exception_js_1.OpraException {
8
+ export class NotAcceptableError extends OpraException {
12
9
  constructor() {
13
10
  super(...arguments);
14
11
  this.status = 406;
15
12
  }
16
13
  setIssue(issue) {
17
14
  super.setIssue({
18
- message: (0, index_js_1.translate)('error:NOT_ACCEPTABLE', 'Not Acceptable'),
15
+ message: translate('error:NOT_ACCEPTABLE', 'Not Acceptable'),
19
16
  severity: 'error',
20
17
  code: 'NOT_ACCEPTABLE',
21
18
  ...issue
22
19
  });
23
20
  }
24
21
  }
25
- exports.NotAcceptableError = NotAcceptableError;
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NotFoundError = void 0;
4
- const index_js_1 = require("../../i18n/index.js");
5
- const opra_exception_js_1 = require("../opra-exception.js");
1
+ import { translate } from '../../i18n/index.js';
2
+ import { OpraException } from '../opra-exception.js';
6
3
  /**
7
4
  * 404 Not Found
8
5
  * The server can not find the requested resource. In the browser, this means the URL is not recognized.
@@ -11,18 +8,17 @@ const opra_exception_js_1 = require("../opra-exception.js");
11
8
  * from an unauthorized client. This response code is probably the most well known due to its
12
9
  * frequent occurrence on the web.
13
10
  */
14
- class NotFoundError extends opra_exception_js_1.OpraException {
11
+ export class NotFoundError extends OpraException {
15
12
  constructor() {
16
13
  super(...arguments);
17
14
  this.status = 404;
18
15
  }
19
16
  setIssue(issue) {
20
17
  super.setIssue({
21
- message: (0, index_js_1.translate)('error:NOT_FOUND', 'Not found'),
18
+ message: translate('error:NOT_FOUND', 'Not found'),
22
19
  severity: 'error',
23
20
  code: 'NOT_FOUND',
24
21
  ...issue
25
22
  });
26
23
  }
27
24
  }
28
- exports.NotFoundError = NotFoundError;
@@ -1,25 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UnauthorizedError = void 0;
4
- const index_js_1 = require("../../i18n/index.js");
5
- const opra_exception_js_1 = require("../opra-exception.js");
1
+ import { translate } from '../../i18n/index.js';
2
+ import { OpraException } from '../opra-exception.js';
6
3
  /**
7
4
  * 401 Unauthorized
8
5
  * Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated".
9
6
  * That is, the client must authenticate itself to get the requested response.
10
7
  */
11
- class UnauthorizedError extends opra_exception_js_1.OpraException {
8
+ export class UnauthorizedError extends OpraException {
12
9
  constructor() {
13
10
  super(...arguments);
14
11
  this.status = 401;
15
12
  }
16
13
  setIssue(issue) {
17
14
  super.setIssue({
18
- message: (0, index_js_1.translate)('error:UNAUTHORIZED', 'You have not been authenticated to perform this action'),
15
+ message: translate('error:UNAUTHORIZED', 'You have not been authenticated to perform this action'),
19
16
  severity: 'error',
20
17
  code: 'UNAUTHORIZED',
21
18
  ...issue
22
19
  });
23
20
  }
24
21
  }
25
- exports.UnauthorizedError = UnauthorizedError;
@@ -1,24 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UnprocessableEntityError = void 0;
4
- const index_js_1 = require("../../i18n/index.js");
5
- const opra_exception_js_1 = require("../opra-exception.js");
1
+ import { translate } from '../../i18n/index.js';
2
+ import { OpraException } from '../opra-exception.js';
6
3
  /**
7
4
  * 422 Unprocessable Entity
8
5
  * The request was well-formed but was unable to be followed due to semantic errors.
9
6
  */
10
- class UnprocessableEntityError extends opra_exception_js_1.OpraException {
7
+ export class UnprocessableEntityError extends OpraException {
11
8
  constructor() {
12
9
  super(...arguments);
13
10
  this.status = 422;
14
11
  }
15
12
  setIssue(issue) {
16
13
  super.setIssue({
17
- message: (0, index_js_1.translate)('error:UNPROCESSABLE_ENTITY', 'Unprocessable entity'),
14
+ message: translate('error:UNPROCESSABLE_ENTITY', 'Unprocessable entity'),
18
15
  severity: 'error',
19
16
  code: 'UNPROCESSABLE_ENTITY',
20
17
  ...issue
21
18
  });
22
19
  }
23
20
  }
24
- exports.UnprocessableEntityError = UnprocessableEntityError;
@@ -1,18 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./opra-exception.js"), exports);
5
- tslib_1.__exportStar(require("./error-issue.js"), exports);
6
- tslib_1.__exportStar(require("./wrap-exception.js"), exports);
7
- tslib_1.__exportStar(require("./enums/issue-severity.enum.js"), exports);
8
- tslib_1.__exportStar(require("./http-errors/bad-request.error.js"), exports);
9
- tslib_1.__exportStar(require("./http-errors/failed-dependency.error.js"), exports);
10
- tslib_1.__exportStar(require("./http-errors/forbidden.error.js"), exports);
11
- tslib_1.__exportStar(require("./http-errors/internal-server.error.js"), exports);
12
- tslib_1.__exportStar(require("./http-errors/method-not-allowed.error.js"), exports);
13
- tslib_1.__exportStar(require("./http-errors/not-acceptable.error.js"), exports);
14
- tslib_1.__exportStar(require("./http-errors/not-found.error.js"), exports);
15
- tslib_1.__exportStar(require("./http-errors/unauthorized.error.js"), exports);
16
- tslib_1.__exportStar(require("./http-errors/unprocessable-entity.error.js"), exports);
17
- tslib_1.__exportStar(require("./resource-errors/resource-conflict.error.js"), exports);
18
- tslib_1.__exportStar(require("./resource-errors/resource-not-found.error.js"), exports);
1
+ export * from './opra-exception.js';
2
+ export * from './error-issue.js';
3
+ export * from './wrap-exception.js';
4
+ export * from './enums/issue-severity.enum.js';
5
+ export * from './http-errors/bad-request.error.js';
6
+ export * from './http-errors/failed-dependency.error.js';
7
+ export * from './http-errors/forbidden.error.js';
8
+ export * from './http-errors/internal-server.error.js';
9
+ export * from './http-errors/method-not-allowed.error.js';
10
+ export * from './http-errors/not-acceptable.error.js';
11
+ export * from './http-errors/not-found.error.js';
12
+ export * from './http-errors/unauthorized.error.js';
13
+ export * from './http-errors/unprocessable-entity.error.js';
14
+ export * from './resource-errors/resource-conflict.error.js';
15
+ export * from './resource-errors/resource-not-found.error.js';
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpraException = void 0;
4
- const index_js_1 = require("../i18n/index.js");
1
+ import { i18n } from '../i18n/index.js';
5
2
  /**
6
3
  * Defines the base Opra exception, which is handled by the default Exceptions Handler.
7
4
  */
8
- class OpraException extends Error {
5
+ export class OpraException extends Error {
9
6
  constructor(issue, cause) {
10
7
  super('');
11
8
  this.status = 500;
@@ -18,7 +15,7 @@ class OpraException extends Error {
18
15
  this._init(issue || cause || 'Unknown error');
19
16
  if (issue instanceof Error)
20
17
  this.stack = issue.stack;
21
- this.message = index_js_1.i18n.deep(this.issue.message);
18
+ this.message = i18n.deep(this.issue.message);
22
19
  }
23
20
  get issue() {
24
21
  return this._issue;
@@ -53,4 +50,3 @@ class OpraException extends Error {
53
50
  }
54
51
  }
55
52
  }
56
- exports.OpraException = OpraException;
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ResourceConflictError = void 0;
4
- const index_js_1 = require("../../i18n/index.js");
5
- const opra_exception_js_1 = require("../opra-exception.js");
6
- class ResourceConflictError extends opra_exception_js_1.OpraException {
1
+ import { translate } from '../../i18n/index.js';
2
+ import { OpraException } from '../opra-exception.js';
3
+ export class ResourceConflictError extends OpraException {
7
4
  constructor(resource, fields, cause) {
8
5
  super({
9
- message: (0, index_js_1.translate)(`error:RESOURCE_CONFLICT`, { resource, fields }, `There is already an other {{resource}} resource with same field values ({{fields}})`),
6
+ message: translate(`error:RESOURCE_CONFLICT`, { resource, fields }, `There is already an other {{resource}} resource with same field values ({{fields}})`),
10
7
  severity: 'error',
11
8
  code: 'RESOURCE_CONFLICT',
12
9
  details: {
@@ -17,4 +14,3 @@ class ResourceConflictError extends opra_exception_js_1.OpraException {
17
14
  this.status = 409;
18
15
  }
19
16
  }
20
- exports.ResourceConflictError = ResourceConflictError;
@@ -1,16 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ResourceNotFoundError = void 0;
4
- const index_js_1 = require("../../i18n/index.js");
5
- const opra_exception_js_1 = require("../opra-exception.js");
1
+ import { translate } from '../../i18n/index.js';
2
+ import { OpraException } from '../opra-exception.js';
6
3
  /**
7
4
  * The server cannot find the requested resource.
8
5
  * This can also mean that the endpoint is valid but the resource itself does not exist.
9
6
  */
10
- class ResourceNotFoundError extends opra_exception_js_1.OpraException {
7
+ export class ResourceNotFoundError extends OpraException {
11
8
  constructor(resource, keyValue, cause) {
12
9
  super({
13
- message: (0, index_js_1.translate)(`error:RESOURCE_NOT_FOUND`, { resource: resource + (keyValue ? '@' + keyValue : '') }, `The resource '{{resource}}' could not be found`),
10
+ message: translate(`error:RESOURCE_NOT_FOUND`, { resource: resource + (keyValue ? '@' + keyValue : '') }, `The resource '{{resource}}' could not be found`),
14
11
  severity: 'error',
15
12
  code: 'RESOURCE_NOT_FOUND',
16
13
  details: {
@@ -21,4 +18,3 @@ class ResourceNotFoundError extends opra_exception_js_1.OpraException {
21
18
  this.status = 404;
22
19
  }
23
20
  }
24
- exports.ResourceNotFoundError = ResourceNotFoundError;
@@ -1,17 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wrapException = void 0;
4
- const bad_request_error_js_1 = require("./http-errors/bad-request.error.js");
5
- const failed_dependency_error_js_1 = require("./http-errors/failed-dependency.error.js");
6
- const forbidden_error_js_1 = require("./http-errors/forbidden.error.js");
7
- const method_not_allowed_error_js_1 = require("./http-errors/method-not-allowed.error.js");
8
- const not_acceptable_error_js_1 = require("./http-errors/not-acceptable.error.js");
9
- const not_found_error_js_1 = require("./http-errors/not-found.error.js");
10
- const unauthorized_error_js_1 = require("./http-errors/unauthorized.error.js");
11
- const unprocessable_entity_error_js_1 = require("./http-errors/unprocessable-entity.error.js");
12
- const opra_exception_js_1 = require("./opra-exception.js");
13
- function wrapException(e) {
14
- if (e instanceof opra_exception_js_1.OpraException)
1
+ import { BadRequestError } from './http-errors/bad-request.error.js';
2
+ import { FailedDependencyError } from './http-errors/failed-dependency.error.js';
3
+ import { ForbiddenError } from './http-errors/forbidden.error.js';
4
+ import { MethodNotAllowedError } from './http-errors/method-not-allowed.error.js';
5
+ import { NotAcceptableError } from './http-errors/not-acceptable.error.js';
6
+ import { NotFoundError } from './http-errors/not-found.error.js';
7
+ import { UnauthorizedError } from './http-errors/unauthorized.error.js';
8
+ import { UnprocessableEntityError } from './http-errors/unprocessable-entity.error.js';
9
+ import { OpraException } from './opra-exception.js';
10
+ export function wrapException(e) {
11
+ if (e instanceof OpraException)
15
12
  return e;
16
13
  let status = 500;
17
14
  if (typeof e.status === 'number')
@@ -20,23 +17,22 @@ function wrapException(e) {
20
17
  status = e.getStatus();
21
18
  switch (status) {
22
19
  case 400:
23
- return new bad_request_error_js_1.BadRequestError(e);
20
+ return new BadRequestError(e);
24
21
  case 401:
25
- return new unauthorized_error_js_1.UnauthorizedError(e);
22
+ return new UnauthorizedError(e);
26
23
  case 403:
27
- return new forbidden_error_js_1.ForbiddenError(e);
24
+ return new ForbiddenError(e);
28
25
  case 404:
29
- return new not_found_error_js_1.NotFoundError(e);
26
+ return new NotFoundError(e);
30
27
  case 405:
31
- return new method_not_allowed_error_js_1.MethodNotAllowedError(e);
28
+ return new MethodNotAllowedError(e);
32
29
  case 406:
33
- return new not_acceptable_error_js_1.NotAcceptableError(e);
30
+ return new NotAcceptableError(e);
34
31
  case 422:
35
- return new unprocessable_entity_error_js_1.UnprocessableEntityError(e);
32
+ return new UnprocessableEntityError(e);
36
33
  case 424:
37
- return new failed_dependency_error_js_1.FailedDependencyError(e);
34
+ return new FailedDependencyError(e);
38
35
  default:
39
- return new failed_dependency_error_js_1.FailedDependencyError(e);
36
+ return new FailedDependencyError(e);
40
37
  }
41
38
  }
42
- exports.wrapException = wrapException;