@opra/common 0.10.3 → 0.12.0

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 (126) hide show
  1. package/cjs/filter/antlr/OpraFilterLexer.js +1 -1
  2. package/cjs/filter/antlr/OpraFilterListener.js +1 -1
  3. package/cjs/filter/antlr/OpraFilterParser.js +5 -5
  4. package/cjs/filter/antlr/OpraFilterVisitor.js +1 -1
  5. package/cjs/filter/filter-tree-visitor.js +8 -2
  6. package/cjs/filter/opra-error-listener.js +2 -2
  7. package/cjs/filter/parse.js +1 -1
  8. package/cjs/helpers/responsive-map.js +45 -28
  9. package/{esm/http/enums/http-headers.enum.js → cjs/http/enums/http-headers-codes.enum.js} +95 -92
  10. package/{esm/http/enums/http-status.enum.js → cjs/http/enums/http-status-codes.enum.js} +62 -59
  11. package/cjs/http/http-headers.js +213 -0
  12. package/cjs/http/http-param-codec.js +6 -0
  13. package/cjs/http/http-params.js +321 -0
  14. package/cjs/http/http-request-node.js +105 -0
  15. package/cjs/http/http-request.js +73 -88
  16. package/cjs/http/http-response.js +23 -0
  17. package/cjs/http/index.js +13 -2
  18. package/cjs/http/multipart/batch-multipart.js +12 -12
  19. package/cjs/http/param-codec/boolean-codec.js +25 -0
  20. package/cjs/http/param-codec/date-codec.js +44 -0
  21. package/cjs/http/param-codec/filter-codec.js +18 -0
  22. package/cjs/http/param-codec/integer-codec.js +19 -0
  23. package/cjs/http/param-codec/number-codec.js +26 -0
  24. package/cjs/http/param-codec/string-codec.js +25 -0
  25. package/cjs/http/utils/encodeURIParam.js +21 -0
  26. package/cjs/http/utils/normalize-headers.js +2 -2
  27. package/cjs/i18n/i18n.js +1 -4
  28. package/cjs/schema/implementation/opra-document.js +12 -11
  29. package/cjs/schema/implementation/resource/collection-resource-info.js +7 -0
  30. package/cjs/url/opra-url-path.js +96 -72
  31. package/cjs/url/opra-url-search-params.js +16 -234
  32. package/cjs/url/opra-url.js +201 -160
  33. package/esm/filter/antlr/OpraFilterLexer.d.ts +1 -1
  34. package/esm/filter/antlr/OpraFilterLexer.js +1 -1
  35. package/esm/filter/antlr/OpraFilterListener.d.ts +1 -1
  36. package/esm/filter/antlr/OpraFilterListener.js +1 -1
  37. package/esm/filter/antlr/OpraFilterParser.d.ts +1 -1
  38. package/esm/filter/antlr/OpraFilterParser.js +5 -5
  39. package/esm/filter/antlr/OpraFilterVisitor.d.ts +1 -1
  40. package/esm/filter/antlr/OpraFilterVisitor.js +1 -1
  41. package/esm/filter/ast/expressions/arithmetic-expression.d.ts +1 -1
  42. package/esm/filter/ast/expressions/comparison-expression.d.ts +1 -1
  43. package/esm/filter/ast/expressions/logical-expression.d.ts +1 -1
  44. package/esm/filter/build.d.ts +3 -3
  45. package/esm/filter/errors.d.ts +4 -2
  46. package/esm/filter/filter-tree-visitor.d.ts +2 -1
  47. package/esm/filter/filter-tree-visitor.js +8 -2
  48. package/esm/filter/opra-error-listener.d.ts +2 -2
  49. package/esm/filter/opra-error-listener.js +2 -2
  50. package/esm/filter/parse.d.ts +1 -1
  51. package/esm/filter/parse.js +1 -1
  52. package/esm/helpers/responsive-map.d.ts +19 -5
  53. package/esm/helpers/responsive-map.js +45 -28
  54. package/esm/http/enums/{http-headers.enum.d.ts → http-headers-codes.enum.d.ts} +1 -1
  55. package/{cjs/http/enums/http-headers.enum.js → esm/http/enums/http-headers-codes.enum.js} +92 -95
  56. package/esm/http/enums/{http-status.enum.d.ts → http-status-codes.enum.d.ts} +1 -1
  57. package/{cjs/http/enums/http-status.enum.js → esm/http/enums/http-status-codes.enum.js} +59 -62
  58. package/esm/http/http-headers.d.ts +70 -0
  59. package/esm/http/http-headers.js +209 -0
  60. package/esm/http/http-param-codec.d.ts +4 -0
  61. package/esm/http/http-param-codec.js +2 -0
  62. package/esm/http/http-params.d.ts +99 -0
  63. package/esm/http/http-params.js +317 -0
  64. package/esm/http/http-request-node.d.ts +34 -0
  65. package/esm/http/http-request-node.js +101 -0
  66. package/esm/http/http-request.d.ts +73 -31
  67. package/esm/http/http-request.js +72 -87
  68. package/esm/http/http-response.d.ts +41 -0
  69. package/esm/http/http-response.js +19 -0
  70. package/esm/http/index.d.ts +13 -2
  71. package/esm/http/index.js +13 -2
  72. package/esm/http/interfaces/client-http-headers.interface.d.ts +1 -1
  73. package/esm/http/interfaces/server-http-headers.interface.d.ts +1 -1
  74. package/esm/http/multipart/batch-multipart.d.ts +1 -1
  75. package/esm/http/multipart/batch-multipart.js +12 -12
  76. package/esm/http/multipart/http-request-content.d.ts +1 -1
  77. package/esm/http/multipart/http-response-content.d.ts +1 -1
  78. package/esm/http/param-codec/boolean-codec.d.ts +5 -0
  79. package/esm/http/param-codec/boolean-codec.js +21 -0
  80. package/esm/http/param-codec/date-codec.d.ts +16 -0
  81. package/esm/http/param-codec/date-codec.js +40 -0
  82. package/esm/http/param-codec/filter-codec.d.ts +6 -0
  83. package/esm/http/param-codec/filter-codec.js +14 -0
  84. package/esm/http/param-codec/integer-codec.d.ts +9 -0
  85. package/esm/http/param-codec/integer-codec.js +15 -0
  86. package/esm/http/param-codec/number-codec.d.ts +12 -0
  87. package/esm/http/param-codec/number-codec.js +22 -0
  88. package/esm/http/param-codec/string-codec.d.ts +14 -0
  89. package/esm/http/param-codec/string-codec.js +21 -0
  90. package/esm/http/utils/encodeURIParam.d.ts +1 -0
  91. package/esm/http/utils/encodeURIParam.js +17 -0
  92. package/esm/http/utils/normalize-headers.js +2 -2
  93. package/esm/i18n/i18n.d.ts +6 -6
  94. package/esm/i18n/i18n.js +1 -4
  95. package/esm/schema/decorators/opr-collection-resource.decorator.d.ts +1 -1
  96. package/esm/schema/decorators/opr-complex-type.decorator.d.ts +1 -1
  97. package/esm/schema/decorators/opr-simple-type.decorator.d.ts +1 -1
  98. package/esm/schema/decorators/opr-singleton-resource.decorator.d.ts +1 -1
  99. package/esm/schema/implementation/data-type/complex-type.d.ts +1 -1
  100. package/esm/schema/implementation/data-type/union-type.d.ts +1 -1
  101. package/esm/schema/implementation/document-builder.d.ts +1 -1
  102. package/esm/schema/implementation/opra-document.d.ts +2 -2
  103. package/esm/schema/implementation/opra-document.js +12 -11
  104. package/esm/schema/implementation/query/collection-count-query.d.ts +1 -1
  105. package/esm/schema/implementation/query/collection-create-query.d.ts +1 -1
  106. package/esm/schema/implementation/query/collection-delete-many-query.d.ts +1 -1
  107. package/esm/schema/implementation/query/collection-get-query.d.ts +1 -1
  108. package/esm/schema/implementation/query/collection-search-query.d.ts +1 -1
  109. package/esm/schema/implementation/query/collection-update-many-query.d.ts +1 -1
  110. package/esm/schema/implementation/query/collection-update-query.d.ts +1 -1
  111. package/esm/schema/implementation/query/field-get-query.d.ts +1 -1
  112. package/esm/schema/implementation/query/index.d.ts +4 -4
  113. package/esm/schema/implementation/query/singleton-get-query.d.ts +1 -1
  114. package/esm/schema/implementation/resource/collection-resource-info.d.ts +2 -0
  115. package/esm/schema/implementation/resource/collection-resource-info.js +7 -0
  116. package/esm/schema/interfaces/data-type.metadata.d.ts +4 -4
  117. package/esm/schema/interfaces/resource.metadata.d.ts +9 -9
  118. package/esm/schema/types.d.ts +8 -8
  119. package/esm/url/opra-url-path-component.d.ts +1 -1
  120. package/esm/url/opra-url-path.d.ts +24 -18
  121. package/esm/url/opra-url-path.js +96 -72
  122. package/esm/url/opra-url-search-params.d.ts +3 -42
  123. package/esm/url/opra-url-search-params.js +16 -234
  124. package/esm/url/opra-url.d.ts +38 -28
  125. package/esm/url/opra-url.js +201 -160
  126. package/package.json +10 -10
@@ -5,8 +5,8 @@ const tslib_1 = require("tslib");
5
5
  const highland_1 = tslib_1.__importDefault(require("highland"));
6
6
  const uid_1 = require("uid");
7
7
  const type_guards_js_1 = require("../../utils/type-guards.js");
8
- const http_headers_enum_js_1 = require("../enums/http-headers.enum.js");
9
- const http_status_enum_js_1 = require("../enums/http-status.enum.js");
8
+ const http_headers_codes_enum_js_1 = require("../enums/http-headers-codes.enum.js");
9
+ const http_status_codes_enum_js_1 = require("../enums/http-status-codes.enum.js");
10
10
  const normalize_headers_js_1 = require("../utils/normalize-headers.js");
11
11
  const http_request_content_js_1 = require("./http-request-content.js");
12
12
  const http_response_content_js_1 = require("./http-response-content.js");
@@ -20,11 +20,11 @@ class BatchMultipart {
20
20
  addRequestPart(content, part) {
21
21
  const headers = {
22
22
  ...(0, normalize_headers_js_1.normalizeHeaders)(part?.headers || {}, true),
23
- [http_headers_enum_js_1.HttpHeaders.Content_Type]: 'application/http',
24
- [http_headers_enum_js_1.HttpHeaders.Content_Transfer_Encoding]: 'binary'
23
+ [http_headers_codes_enum_js_1.HttpHeaderCodes.Content_Type]: 'application/http',
24
+ [http_headers_codes_enum_js_1.HttpHeaderCodes.Content_Transfer_Encoding]: 'binary'
25
25
  };
26
26
  if (part?.contentId)
27
- headers[http_headers_enum_js_1.HttpHeaders.Content_ID] = part.contentId;
27
+ headers[http_headers_codes_enum_js_1.HttpHeaderCodes.Content_ID] = part.contentId;
28
28
  this._parts.push({
29
29
  headers,
30
30
  contentId: part?.contentId,
@@ -35,11 +35,11 @@ class BatchMultipart {
35
35
  addHttpResponse(content, part) {
36
36
  const headers = {
37
37
  ...(0, normalize_headers_js_1.normalizeHeaders)(part?.headers || {}, true),
38
- [http_headers_enum_js_1.HttpHeaders.Content_Type]: 'application/http',
39
- [http_headers_enum_js_1.HttpHeaders.Content_Transfer_Encoding]: 'binary'
38
+ [http_headers_codes_enum_js_1.HttpHeaderCodes.Content_Type]: 'application/http',
39
+ [http_headers_codes_enum_js_1.HttpHeaderCodes.Content_Transfer_Encoding]: 'binary'
40
40
  };
41
41
  if (part?.contentId)
42
- headers[http_headers_enum_js_1.HttpHeaders.Content_ID] = part.contentId;
42
+ headers[http_headers_codes_enum_js_1.HttpHeaderCodes.Content_ID] = part.contentId;
43
43
  this._parts.push({
44
44
  headers,
45
45
  contentId: part?.contentId,
@@ -50,11 +50,11 @@ class BatchMultipart {
50
50
  addBatch(batch, part) {
51
51
  const headers = {
52
52
  ...(0, normalize_headers_js_1.normalizeHeaders)(part?.headers || {}, true),
53
- [http_headers_enum_js_1.HttpHeaders.Content_Type]: 'application/http',
54
- [http_headers_enum_js_1.HttpHeaders.Content_Transfer_Encoding]: 'binary'
53
+ [http_headers_codes_enum_js_1.HttpHeaderCodes.Content_Type]: 'application/http',
54
+ [http_headers_codes_enum_js_1.HttpHeaderCodes.Content_Transfer_Encoding]: 'binary'
55
55
  };
56
56
  if (part?.contentId)
57
- headers[http_headers_enum_js_1.HttpHeaders.Content_ID] = part.contentId;
57
+ headers[http_headers_codes_enum_js_1.HttpHeaderCodes.Content_ID] = part.contentId;
58
58
  this._parts.push({
59
59
  headers,
60
60
  contentId: part?.contentId,
@@ -126,7 +126,7 @@ class BatchMultipart {
126
126
  if (part.content instanceof http_request_content_js_1.HttpRequestContent)
127
127
  s += (part.content.method || 'GET').toUpperCase() + ' ' + part.content.url + ' HTTP/1.1' + CRLF;
128
128
  else
129
- s += 'HTTP/1.1 ' + part.content.status + (http_status_enum_js_1.HttpStatus[part.content.status] || 'Unknown') + CRLF;
129
+ s += 'HTTP/1.1 ' + part.content.status + (http_status_codes_enum_js_1.HttpStatusCodes[part.content.status] || 'Unknown') + CRLF;
130
130
  if (part.content.headers) {
131
131
  for (const [k, v] of Object.entries(part.content.headers)) {
132
132
  if (v === '' || v == null)
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BooleanCodec = void 0;
4
+ const http_param_codec_js_1 = require("../http-param-codec.js");
5
+ const trueValues = ['true', 't', 'yes', 'y', '1'];
6
+ const falseValues = ['false', 'f', 'no', 'n', '0'];
7
+ class BooleanCodec extends http_param_codec_js_1.HttpParamCodec {
8
+ decode(value) {
9
+ if (value === '')
10
+ return true;
11
+ // noinspection SuspiciousTypeOfGuard
12
+ if (typeof value === 'boolean')
13
+ return value;
14
+ if (trueValues.includes(value.toLowerCase()))
15
+ return true;
16
+ if (falseValues.includes(value.toLowerCase()))
17
+ return false;
18
+ throw new TypeError(`"${value}" is not a valid boolean`);
19
+ }
20
+ encode(value) {
21
+ return typeof value === 'boolean' ?
22
+ (value ? 'true' : 'false') : '';
23
+ }
24
+ }
25
+ exports.BooleanCodec = BooleanCodec;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DateCodec = void 0;
4
+ /* eslint-disable max-len */
5
+ const http_param_codec_js_1 = require("../http-param-codec.js");
6
+ // noinspection RegExpUnnecessaryNonCapturingGroup
7
+ const DATE_FORMAT_PATTERN = /^(\d{4})(?:-?(0[1-9]|1[012])(?:-?([123]0|[012][1-9]|31))?)?(?:[T ]?([01][0-9]|2[0-3]):?([0-5][0-9]):?([0-5][0-9])?(?:\.(\d+))?(?:(Z)|(?:([+-])([01]?[0-9]|2[0-3]):?([0-5][0-9])?))?)?$/;
8
+ class DateCodec extends http_param_codec_js_1.HttpParamCodec {
9
+ constructor(options) {
10
+ super();
11
+ this.max = options?.max ? coerceToDateString(options.max) : undefined;
12
+ this.min = options?.min ? coerceToDateString(options.min) : undefined;
13
+ this.time = options?.time ?? true;
14
+ this.timeZone = options?.timeZone ?? true;
15
+ }
16
+ decode(value) {
17
+ const v = coerceToDateString(value, this.time, this.timeZone);
18
+ if (this.min != null && v < this.min)
19
+ throw new TypeError(`Value must be ${this.min} or greater.`);
20
+ if (this.max != null && v > this.max)
21
+ throw new TypeError(`Value must be ${this.max} or less.`);
22
+ return v;
23
+ }
24
+ encode(value) {
25
+ return coerceToDateString(value, this.time, this.timeZone);
26
+ }
27
+ }
28
+ exports.DateCodec = DateCodec;
29
+ function coerceToDateString(value, time, timeZone) {
30
+ if (value === '' || value == null)
31
+ return '';
32
+ const m = value.match(DATE_FORMAT_PATTERN);
33
+ if (!m)
34
+ throw new TypeError(`"${value}" is not a valid date.`);
35
+ let v = m[1] + '-' + (m[2] || '01') + '-' + (m[3] || '01');
36
+ if (time) {
37
+ v += 'T' + (m[4] || '00') + ':' + (m[5] || '00') + ':' + (m[6] || '00') +
38
+ (m[7] ? '.' + m[7] : '');
39
+ if (timeZone)
40
+ v += m[8] ? 'Z' :
41
+ (m[9] ? (m[9] + (m[10] || '00') + ':' + (m[11] || '00')) : '');
42
+ }
43
+ return v;
44
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FilterCodec = void 0;
4
+ const index_js_1 = require("../../filter/ast/index.js");
5
+ const parse_js_1 = require("../../filter/parse.js");
6
+ const http_param_codec_js_1 = require("../http-param-codec.js");
7
+ class FilterCodec extends http_param_codec_js_1.HttpParamCodec {
8
+ decode(value) {
9
+ if (value instanceof index_js_1.Expression)
10
+ return value;
11
+ return (0, parse_js_1.parseFilter)(value);
12
+ }
13
+ encode(value) {
14
+ // @ts-ignore
15
+ return value ? '' + value : '';
16
+ }
17
+ }
18
+ exports.FilterCodec = FilterCodec;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IntegerCodec = void 0;
4
+ const number_codec_js_1 = require("./number-codec.js");
5
+ class IntegerCodec extends number_codec_js_1.NumberCodec {
6
+ constructor(options) {
7
+ super(options);
8
+ this.enum = options?.enum;
9
+ }
10
+ decode(value) {
11
+ const v = super.decode(value);
12
+ if (!Number.isInteger(v))
13
+ throw new TypeError(`"${value}" is not a valid integer`);
14
+ if (this.enum && !this.enum.includes(v))
15
+ throw new TypeError(`"${value}" is not one of allowed enum values (${this.enum}).`);
16
+ return v;
17
+ }
18
+ }
19
+ exports.IntegerCodec = IntegerCodec;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NumberCodec = void 0;
4
+ const http_param_codec_js_1 = require("../http-param-codec.js");
5
+ class NumberCodec extends http_param_codec_js_1.HttpParamCodec {
6
+ constructor(options) {
7
+ super();
8
+ this.max = options?.max;
9
+ this.min = options?.min;
10
+ }
11
+ decode(value) {
12
+ // noinspection SuspiciousTypeOfGuard
13
+ const v = typeof value === 'number' ? value : parseFloat(value);
14
+ if (isNaN(v))
15
+ throw new TypeError(`"${value}" is not a valid number`);
16
+ if (this.min != null && v < this.min)
17
+ throw new TypeError(`Value must be ${this.min} or greater.`);
18
+ if (this.max != null && v > this.max)
19
+ throw new TypeError(`Value must be ${this.max} or less.`);
20
+ return v;
21
+ }
22
+ encode(value) {
23
+ return typeof value === 'number' ? '' + value : '';
24
+ }
25
+ }
26
+ exports.NumberCodec = NumberCodec;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StringCodec = void 0;
4
+ const http_param_codec_js_1 = require("../http-param-codec.js");
5
+ class StringCodec extends http_param_codec_js_1.HttpParamCodec {
6
+ constructor(options) {
7
+ super();
8
+ this.maxLength = options?.maxLength;
9
+ this.minLength = options?.minLength;
10
+ this.enum = options?.enum;
11
+ }
12
+ decode(value) {
13
+ if (this.minLength != null && value.length < this.minLength)
14
+ throw new TypeError(`Value must be at least ${this.minLength} character${this.minLength > 1 ? 's' : ''} long.`);
15
+ if (this.maxLength != null && value.length > this.maxLength)
16
+ throw new TypeError(`Value can be up to ${this.maxLength} character${this.maxLength > 1 ? 's' : ''} long.`);
17
+ if (this.enum && !this.enum.includes(value))
18
+ throw new TypeError(`"${value}" is not one of allowed enum values (${this.enum}).`);
19
+ return value;
20
+ }
21
+ encode(value) {
22
+ return value == null ? '' : '' + value;
23
+ }
24
+ }
25
+ exports.StringCodec = StringCodec;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encodeURIParam = void 0;
4
+ /**
5
+ * Encode input string with standard encodeURIComponent and then un-encode specific characters.
6
+ */
7
+ const ENCODING_REGEX = /%(\d[a-f0-9])/gi;
8
+ const ENCODING_REPLACEMENTS = {
9
+ '2C': ',',
10
+ '2F': '/',
11
+ '24': '$',
12
+ '3A': ':',
13
+ '3B': ';',
14
+ '3D': '=',
15
+ '3F': '?',
16
+ '40': '@'
17
+ };
18
+ function encodeURIParam(v) {
19
+ return encodeURIComponent(v).replace(ENCODING_REGEX, (s, t) => ENCODING_REPLACEMENTS[t] ?? s);
20
+ }
21
+ exports.encodeURIParam = encodeURIParam;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeHeaders = void 0;
4
- const http_headers_enum_js_1 = require("../enums/http-headers.enum.js");
5
- const knownKeys = Object.keys(http_headers_enum_js_1.HttpHeaders);
4
+ const http_headers_codes_enum_js_1 = require("../enums/http-headers-codes.enum.js");
5
+ const knownKeys = Object.keys(http_headers_codes_enum_js_1.HttpHeaderCodes);
6
6
  const knownKeysLower = knownKeys.map(x => x.toLowerCase());
7
7
  function normalizeHeaders(headers, normalCase) {
8
8
  if (!headers)
package/cjs/i18n/i18n.js CHANGED
@@ -70,11 +70,8 @@ class I18n extends exports.BaseI18n {
70
70
  async loadResourceDir(dirnames, deep, overwrite) {
71
71
  for (const dirname of Array.isArray(dirnames) ? dirnames : [dirnames]) {
72
72
  /* istanbul ignore next */
73
- if (!(fs_1.default.statSync(dirname)).isDirectory()) {
74
- // eslint-disable-next-line no-console
75
- console.warn(`Locale directory does not exists. (${dirname})`);
73
+ if (!(fs_1.default.existsSync(dirname)))
76
74
  continue;
77
- }
78
75
  const languageDirs = fs_1.default.readdirSync(dirname);
79
76
  for (const lang of languageDirs) {
80
77
  const langDir = path_1.default.join(dirname, lang);
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OpraDocument = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const lodash_omit_1 = tslib_1.__importDefault(require("lodash.omit"));
6
+ const index_js_1 = require("../../exception/index.js");
6
7
  const responsive_map_js_1 = require("../../helpers/responsive-map.js");
7
8
  const opra_schema_definition_js_1 = require("../opra-schema.definition.js");
8
9
  const clone_object_util_js_1 = require("../utils/clone-object.util.js");
@@ -43,25 +44,25 @@ class OpraDocument {
43
44
  const t = this.types.get(name);
44
45
  if (t)
45
46
  return t;
46
- throw new Error(`Data type "${name}" does not exists`);
47
+ throw new index_js_1.NotFoundError(`Data type "${name}" does not exists`);
47
48
  }
48
49
  getComplexDataType(name) {
49
50
  const t = this.getDataType(name);
50
51
  if (t && t instanceof complex_type_js_1.ComplexType)
51
52
  return t;
52
- throw new Error(`Data type "${name}" is not a ComplexType`);
53
+ throw new index_js_1.NotAcceptableError(`Data type "${name}" is not a ComplexType`);
53
54
  }
54
55
  getSimpleDataType(name) {
55
56
  const t = this.getDataType(name);
56
57
  if (t && t instanceof simple_type_js_1.SimpleType)
57
58
  return t;
58
- throw new Error(`Data type "${name}" is not a SimpleType`);
59
+ throw new index_js_1.NotAcceptableError(`Data type "${name}" is not a SimpleType`);
59
60
  }
60
61
  getUnionDataType(name) {
61
62
  const t = this.getDataType(name);
62
63
  if (t && t instanceof union_type_js_1.UnionType)
63
64
  return t;
64
- throw new Error(`Data type "${name}" is not a UnionType`);
65
+ throw new index_js_1.NotAcceptableError(`Data type "${name}" is not a UnionType`);
65
66
  }
66
67
  get resources() {
67
68
  return this._resources;
@@ -72,19 +73,19 @@ class OpraDocument {
72
73
  getResource(name) {
73
74
  const t = this.resources.get(name);
74
75
  if (!t)
75
- throw new Error(`Resource "${name}" does not exists`);
76
+ throw new index_js_1.NotFoundError(`Resource "${name}" does not exists`);
76
77
  return t;
77
78
  }
78
79
  getCollectionResource(name) {
79
80
  const t = this.getResource(name);
80
81
  if (!(t instanceof collection_resource_info_js_1.CollectionResourceInfo))
81
- throw new Error(`"${name}" is not a CollectionResource`);
82
+ throw new index_js_1.NotAcceptableError(`"${name}" is not a CollectionResource`);
82
83
  return t;
83
84
  }
84
85
  getSingletonResource(name) {
85
86
  const t = this.getResource(name);
86
87
  if (!(t instanceof singleton_resource_info_js_1.SingletonResourceInfo))
87
- throw new Error(`"${name}" is not a SingletonResource`);
88
+ throw new index_js_1.NotAcceptableError(`"${name}" is not a SingletonResource`);
88
89
  return t;
89
90
  }
90
91
  getMetadata(jsonOnly) {
@@ -125,7 +126,7 @@ class OpraDocument {
125
126
  dataType = new union_type_js_1.UnionType(this, name, { ...schema, types: [] });
126
127
  }
127
128
  else
128
- throw new TypeError(`Invalid data type schema`);
129
+ throw new index_js_1.InternalServerError(`Invalid data type schema`);
129
130
  this._types.set(name, dataType);
130
131
  if (isOwn)
131
132
  this._ownTypes.set(name, dataType);
@@ -135,16 +136,16 @@ class OpraDocument {
135
136
  if (opra_schema_definition_js_1.OpraSchema.isCollectionResource(schema) || opra_schema_definition_js_1.OpraSchema.isSingletonResource(schema)) {
136
137
  const dataType = this.getDataType(schema.type);
137
138
  if (!dataType)
138
- throw new TypeError(`Datatype "${schema.type}" declared in CollectionResource (${name}) does not exists`);
139
+ throw new index_js_1.InternalServerError(`Datatype "${schema.type}" declared in CollectionResource (${name}) does not exists`);
139
140
  if (!(dataType instanceof complex_type_js_1.ComplexType))
140
- throw new TypeError(`${schema.type} is not an ComplexType`);
141
+ throw new index_js_1.InternalServerError(`${schema.type} is not an ComplexType`);
141
142
  if (opra_schema_definition_js_1.OpraSchema.isCollectionResource(schema))
142
143
  this.resources.set(name, new collection_resource_info_js_1.CollectionResourceInfo(this, name, dataType, schema));
143
144
  else
144
145
  this.resources.set(name, new singleton_resource_info_js_1.SingletonResourceInfo(this, name, dataType, schema));
145
146
  }
146
147
  else
147
- throw new TypeError(`Unknown resource kind (${schema.kind})`);
148
+ throw new index_js_1.InternalServerError(`Unknown resource kind (${schema.kind})`);
148
149
  }
149
150
  _initTypes() {
150
151
  for (const dataType of this._types.values()) {
@@ -16,6 +16,9 @@ class CollectionResourceInfo extends resource_info_js_1.ResourceInfo {
16
16
  metadata.search.sortFields = (0, normalize_field_array_util_js_1.normalizeFieldArray)(document, dataType, metadata.search.sortFields);
17
17
  }
18
18
  }
19
+ get instance() {
20
+ return this.metadata.instance;
21
+ }
19
22
  get keyFields() {
20
23
  return this.metadata.keyFields;
21
24
  }
@@ -43,6 +46,10 @@ class CollectionResourceInfo extends resource_info_js_1.ResourceInfo {
43
46
  get search() {
44
47
  return this.metadata.search;
45
48
  }
49
+ getHandler(method) {
50
+ const r = this.metadata[method];
51
+ return r && r.handler;
52
+ }
46
53
  getSchema(jsonOnly) {
47
54
  const out = super.getSchema(jsonOnly);
48
55
  if (out.keyFields.length < 2)
@@ -1,56 +1,46 @@
1
1
  "use strict";
2
+ var _a;
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.OpraURLPath = void 0;
4
- const events_1 = require("events");
5
5
  const fast_tokenizer_1 = require("fast-tokenizer");
6
6
  const index_js_1 = require("../utils/index.js");
7
7
  const opra_url_path_component_js_1 = require("./opra-url-path-component.js");
8
8
  const path_utils_js_1 = require("./utils/path-utils.js");
9
9
  const nodeInspectCustom = Symbol.for('nodejs.util.inspect.custom');
10
- class OpraURLPath extends events_1.EventEmitter {
11
- constructor(...args) {
12
- super();
13
- this._entries = [];
14
- for (const x of args) {
15
- if ((0, index_js_1.isURL)(x)) {
16
- this._parse(x.pathname);
17
- continue;
18
- }
19
- // noinspection SuspiciousTypeOfGuard
20
- if (x instanceof OpraURLPath)
21
- this._entries.push(...x._entries);
22
- else
23
- this.add(x);
24
- }
10
+ const kEntries = Symbol('kEntries');
11
+ const kOptions = Symbol('kOptions');
12
+ class OpraURLPath {
13
+ constructor(init, options) {
14
+ this[_a] = [];
15
+ this[kOptions] = { ...options, onChange: undefined };
16
+ if (Array.isArray(init))
17
+ this.join(...init);
18
+ else if (init)
19
+ this.join(init);
20
+ this[kOptions].onChange = options?.onChange;
25
21
  }
26
22
  get size() {
27
- return this._entries.length;
23
+ return this[kEntries].length;
28
24
  }
29
- add(component, key, typeCast) {
30
- this._add(component, key, typeCast);
31
- this.emit('change');
25
+ changed() {
26
+ if (this[kOptions].onChange)
27
+ this[kOptions].onChange();
32
28
  }
33
29
  clear() {
34
- this._entries = [];
35
- this.emit('change');
30
+ this[kEntries] = [];
31
+ this.changed();
36
32
  }
37
33
  get(index) {
38
- return this._entries[index];
39
- }
40
- join(pathString) {
41
- const pathTokenizer = (0, fast_tokenizer_1.tokenize)((0, path_utils_js_1.normalizePath)(pathString, true), {
42
- delimiters: '/', quotes: true, brackets: true,
43
- });
44
- for (const x of pathTokenizer) {
45
- const p = (0, path_utils_js_1.decodePathComponent)(x);
46
- this._add(p);
47
- }
48
- this.emit('change');
34
+ return this[kEntries][index];
35
+ }
36
+ join(...source) {
37
+ source.forEach(x => this._join(this[kEntries], x));
38
+ this.changed();
49
39
  return this;
50
40
  }
51
41
  entries() {
52
42
  let i = -1;
53
- const arr = [...this._entries];
43
+ const arr = [...this[kEntries]];
54
44
  return {
55
45
  [Symbol.iterator]() {
56
46
  return this;
@@ -64,9 +54,46 @@ class OpraURLPath extends events_1.EventEmitter {
64
54
  }
65
55
  };
66
56
  }
57
+ forEach(callback) {
58
+ for (const item of this[kEntries]) {
59
+ callback.call(this, item, this);
60
+ }
61
+ }
62
+ getResource(index) {
63
+ const v = this[kEntries][index];
64
+ return v == null ? undefined : v.resource;
65
+ }
66
+ getKey(index) {
67
+ const v = this[kEntries][index];
68
+ return v == null ? undefined : v.key;
69
+ }
70
+ pop() {
71
+ const out = this[kEntries].pop();
72
+ this.changed();
73
+ return out;
74
+ }
75
+ shift() {
76
+ const out = this[kEntries].shift();
77
+ this.changed();
78
+ return out;
79
+ }
80
+ slice(start, end) {
81
+ return new OpraURLPath(this[kEntries].slice(start, end));
82
+ }
83
+ splice(start, deleteCount, join) {
84
+ const items = (join ? this._join([], join) : []);
85
+ this[kEntries].splice(start, deleteCount, ...items);
86
+ this.changed();
87
+ }
88
+ unshift(join) {
89
+ return this.splice(0, 0, join);
90
+ }
91
+ toString() {
92
+ return this[kEntries].map(x => (0, path_utils_js_1.encodePathComponent)(x.resource, x.key, x.typeCast)).join('/');
93
+ }
67
94
  values() {
68
95
  let i = -1;
69
- const arr = [...this._entries];
96
+ const arr = [...this[kEntries]];
70
97
  return {
71
98
  [Symbol.iterator]() {
72
99
  return this;
@@ -80,49 +107,46 @@ class OpraURLPath extends events_1.EventEmitter {
80
107
  }
81
108
  };
82
109
  }
83
- forEach(callback) {
84
- for (const item of this._entries) {
85
- callback.call(this, item.resource, item.key, this);
110
+ _join(target, source) {
111
+ if (typeof source === 'string') {
112
+ const pathTokenizer = (0, fast_tokenizer_1.tokenize)((0, path_utils_js_1.normalizePath)(source, true), {
113
+ delimiters: '/', quotes: true, brackets: true,
114
+ });
115
+ for (const x of pathTokenizer) {
116
+ const p = (0, path_utils_js_1.decodePathComponent)(x);
117
+ target.push(new opra_url_path_component_js_1.OpraURLPathComponent(p));
118
+ }
119
+ return;
86
120
  }
121
+ if (source instanceof OpraURLPath) {
122
+ target.push(...source[kEntries].map(x => new opra_url_path_component_js_1.OpraURLPathComponent(x)));
123
+ return;
124
+ }
125
+ if (typeof source === 'object' && source.path instanceof OpraURLPath) {
126
+ this._join(target, source.path);
127
+ return;
128
+ }
129
+ if ((0, index_js_1.isURL)(source)) {
130
+ this._join(target, source.pathname);
131
+ return;
132
+ }
133
+ if (Array.isArray(source)) {
134
+ source.forEach(x => this._join(target, x));
135
+ return;
136
+ }
137
+ target.push(new opra_url_path_component_js_1.OpraURLPathComponent(source));
87
138
  }
88
- getResource(index) {
89
- const v = this._entries[index];
90
- return v == null ? undefined : v.resource;
91
- }
92
- getKey(index) {
93
- const v = this._entries[index];
94
- return v == null ? undefined : v.key;
95
- }
96
- toString() {
97
- return this._entries.map(x => (0, path_utils_js_1.encodePathComponent)(x.resource, x.key, x.typeCast)).join('/');
139
+ /* istanbul ignore next */
140
+ [(_a = kEntries, nodeInspectCustom)]() {
141
+ return this[kEntries];
98
142
  }
99
143
  [Symbol.iterator]() {
100
144
  return this.entries();
101
145
  }
102
- /* istanbul ignore next */
103
- [nodeInspectCustom]() {
104
- return this._entries;
105
- }
106
- _add(component, key, typeCast) {
107
- if (component instanceof opra_url_path_component_js_1.OpraURLPathComponent) {
108
- this._entries.push(component);
109
- }
110
- else if (typeof component === 'object')
111
- this._entries.push(new opra_url_path_component_js_1.OpraURLPathComponent(component));
112
- else
113
- this._entries.push(new opra_url_path_component_js_1.OpraURLPathComponent({ resource: component, key, typeCast }));
114
- }
115
- _parse(v) {
116
- if (!v)
117
- return;
118
- const pathTokenizer = (0, fast_tokenizer_1.tokenize)(v, { delimiters: '/', quotes: true, brackets: true });
119
- for (const x of pathTokenizer) {
120
- if (!x)
121
- continue;
122
- const p = (0, path_utils_js_1.decodePathComponent)(x);
123
- this._add(p);
124
- }
125
- this.emit('change');
146
+ get [Symbol.toStringTag]() {
147
+ return 'OpraURLPath';
126
148
  }
127
149
  }
128
150
  exports.OpraURLPath = OpraURLPath;
151
+ OpraURLPath.kEntries = kEntries;
152
+ OpraURLPath.kOptions = kOptions;