@opra/common 0.16.1 → 0.17.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 (148) hide show
  1. package/cjs/document/data-type/complex-type.js +69 -56
  2. package/cjs/document/data-type/simple-type.js +0 -1
  3. package/cjs/document/resource/collection.js +15 -16
  4. package/cjs/document/resource/singleton.js +2 -2
  5. package/cjs/http/http-params.js +10 -11
  6. package/esm/document/api-document.js +33 -37
  7. package/esm/document/constants.js +3 -6
  8. package/esm/document/data-type/api-field.js +12 -15
  9. package/esm/document/data-type/builtin/any.type.js +5 -8
  10. package/esm/document/data-type/builtin/base64.type.js +5 -8
  11. package/esm/document/data-type/builtin/bigint.type.js +5 -8
  12. package/esm/document/data-type/builtin/boolean.type.js +8 -11
  13. package/esm/document/data-type/builtin/date.type.js +7 -10
  14. package/esm/document/data-type/builtin/guid.type.js +9 -12
  15. package/esm/document/data-type/builtin/index.js +10 -13
  16. package/esm/document/data-type/builtin/integer.type.js +10 -13
  17. package/esm/document/data-type/builtin/number.type.js +7 -10
  18. package/esm/document/data-type/builtin/object.type.js +5 -8
  19. package/esm/document/data-type/builtin/string.type.js +8 -11
  20. package/esm/document/data-type/builtin/time.type.js +7 -10
  21. package/esm/document/data-type/builtin/timestamp.type.js +9 -12
  22. package/esm/document/data-type/complex-type.js +94 -85
  23. package/esm/document/data-type/data-type.js +9 -12
  24. package/esm/document/data-type/enum-type.js +15 -19
  25. package/esm/document/data-type/mapped-type.js +24 -29
  26. package/esm/document/data-type/simple-type.js +17 -22
  27. package/esm/document/data-type/union-type.js +26 -29
  28. package/esm/document/factory/add-references.js +3 -7
  29. package/esm/document/factory/create-document.js +10 -16
  30. package/esm/document/factory/factory.js +33 -37
  31. package/esm/document/factory/import-resource-class.js +16 -22
  32. package/esm/document/factory/import-type-class.js +24 -34
  33. package/esm/document/factory/index.js +1 -4
  34. package/esm/document/factory/process-resources.js +10 -16
  35. package/esm/document/factory/process-types.js +31 -37
  36. package/esm/document/index.js +14 -17
  37. package/esm/document/resource/collection.js +58 -63
  38. package/esm/document/resource/resource.js +9 -12
  39. package/esm/document/resource/singleton.js +27 -31
  40. package/esm/document/utils/inspect.util.js +4 -7
  41. package/esm/document/utils/string-compare.util.js +1 -5
  42. package/esm/exception/enums/issue-severity.enum.js +2 -5
  43. package/esm/exception/error-issue.js +1 -2
  44. package/esm/exception/http-errors/bad-request.error.js +4 -8
  45. package/esm/exception/http-errors/failed-dependency.error.js +4 -8
  46. package/esm/exception/http-errors/forbidden.error.js +4 -8
  47. package/esm/exception/http-errors/internal-server.error.js +4 -8
  48. package/esm/exception/http-errors/method-not-allowed.error.js +4 -8
  49. package/esm/exception/http-errors/not-acceptable.error.js +4 -8
  50. package/esm/exception/http-errors/not-found.error.js +4 -8
  51. package/esm/exception/http-errors/unauthorized.error.js +4 -8
  52. package/esm/exception/http-errors/unprocessable-entity.error.js +4 -8
  53. package/esm/exception/index.js +15 -18
  54. package/esm/exception/opra-exception.js +3 -7
  55. package/esm/exception/resource-errors/resource-conflict.error.js +4 -8
  56. package/esm/exception/resource-errors/resource-not-found.error.js +4 -8
  57. package/esm/exception/wrap-exception.js +20 -24
  58. package/esm/filter/antlr/OpraFilterLexer.js +6 -9
  59. package/esm/filter/antlr/OpraFilterListener.js +2 -5
  60. package/esm/filter/antlr/OpraFilterParser.js +79 -126
  61. package/esm/filter/antlr/OpraFilterVisitor.js +2 -5
  62. package/esm/filter/ast/abstract/ast.js +1 -5
  63. package/esm/filter/ast/abstract/expression.js +2 -6
  64. package/esm/filter/ast/abstract/literal.js +2 -6
  65. package/esm/filter/ast/abstract/term.js +2 -6
  66. package/esm/filter/ast/expressions/arithmetic-expression.js +3 -8
  67. package/esm/filter/ast/expressions/array-expression.js +2 -6
  68. package/esm/filter/ast/expressions/comparison-expression.js +2 -6
  69. package/esm/filter/ast/expressions/logical-expression.js +2 -6
  70. package/esm/filter/ast/expressions/parentheses-expression.js +2 -6
  71. package/esm/filter/ast/index.js +16 -19
  72. package/esm/filter/ast/terms/boolean-literal.js +2 -6
  73. package/esm/filter/ast/terms/date-literal.js +8 -12
  74. package/esm/filter/ast/terms/external-constant.js +2 -6
  75. package/esm/filter/ast/terms/null-literal.js +2 -6
  76. package/esm/filter/ast/terms/number-literal.js +4 -8
  77. package/esm/filter/ast/terms/qualified-identifier.js +2 -6
  78. package/esm/filter/ast/terms/string-literal.js +4 -8
  79. package/esm/filter/ast/terms/time-literal.js +6 -10
  80. package/esm/filter/build.js +45 -69
  81. package/esm/filter/errors.js +3 -9
  82. package/esm/filter/filter-tree-visitor.js +26 -31
  83. package/esm/filter/index.js +5 -8
  84. package/esm/filter/opra-error-listener.js +4 -8
  85. package/esm/filter/parse.js +14 -19
  86. package/esm/filter/utils.js +2 -7
  87. package/esm/helpers/function-utils.js +8 -14
  88. package/esm/helpers/get-stack-filename.js +1 -5
  89. package/esm/helpers/index.js +8 -11
  90. package/esm/helpers/is-url.js +1 -5
  91. package/esm/helpers/mixin-utils.js +2 -7
  92. package/esm/helpers/object-utils.js +6 -12
  93. package/esm/helpers/path-to-object-tree.js +1 -5
  94. package/esm/helpers/responsive-map.js +1 -5
  95. package/esm/helpers/type-guards.js +7 -17
  96. package/esm/http/codecs/boolean-codec.js +1 -5
  97. package/esm/http/codecs/date-codec.js +1 -5
  98. package/esm/http/codecs/filter-codec.js +5 -9
  99. package/esm/http/codecs/integer-codec.js +2 -6
  100. package/esm/http/codecs/number-codec.js +1 -5
  101. package/esm/http/codecs/string-codec.js +1 -5
  102. package/esm/http/enums/http-headers-codes.enum.js +2 -5
  103. package/esm/http/enums/http-status-codes.enum.js +2 -5
  104. package/esm/http/enums/http-status-messages.js +1 -4
  105. package/esm/http/http-headers.js +5 -9
  106. package/esm/http/http-message.host.js +13 -18
  107. package/esm/http/http-params.js +30 -36
  108. package/esm/http/http-request-message.js +18 -22
  109. package/esm/http/http-response-message.js +23 -28
  110. package/esm/http/index.js +14 -17
  111. package/esm/http/interfaces/client-http-headers.interface.js +1 -2
  112. package/esm/http/interfaces/cookie-options.interface.js +1 -2
  113. package/esm/http/interfaces/server-http-headers.interface.js +1 -2
  114. package/esm/i18n/i18n.js +23 -28
  115. package/esm/i18n/index.js +5 -9
  116. package/esm/i18n/string-utils.js +2 -7
  117. package/esm/i18n/translate.js +3 -7
  118. package/esm/index.js +11 -16
  119. package/esm/schema/constants.js +1 -4
  120. package/esm/schema/data-type/complex-type.interface.js +2 -5
  121. package/esm/schema/data-type/data-type.interface.js +1 -2
  122. package/esm/schema/data-type/enum-type.interface.js +2 -5
  123. package/esm/schema/data-type/field.interface.js +1 -2
  124. package/esm/schema/data-type/mapped-type.interface.js +2 -5
  125. package/esm/schema/data-type/simple-type.interface.js +2 -5
  126. package/esm/schema/data-type/union-type.interface.js +2 -5
  127. package/esm/schema/document.interface.js +1 -2
  128. package/esm/schema/index.js +31 -34
  129. package/esm/schema/resource/collection.interface.js +2 -5
  130. package/esm/schema/resource/container.interface.js +2 -5
  131. package/esm/schema/resource/endpoint.interface.js +1 -2
  132. package/esm/schema/resource/resource.interface.js +1 -2
  133. package/esm/schema/resource/singleton.interface.js +2 -5
  134. package/esm/schema/type-guards.js +40 -53
  135. package/esm/types.js +1 -2
  136. package/esm/url/index.js +5 -8
  137. package/esm/url/opra-url-path-component.js +3 -7
  138. package/esm/url/opra-url-path.js +14 -18
  139. package/esm/url/opra-url.js +15 -19
  140. package/esm/url/utils/decode-path-component.js +4 -8
  141. package/esm/url/utils/encode-path-component.js +3 -8
  142. package/esm/utils/path-utils.js +2 -7
  143. package/package.json +1 -1
  144. package/types/document/data-type/complex-type.d.ts +8 -2
  145. package/types/document/resource/collection.d.ts +5 -3
  146. package/types/document/resource/singleton.d.ts +3 -1
  147. package/types/filter/ast/terms/qualified-identifier.d.ts +4 -0
  148. package/types/http/http-params.d.ts +20 -19
@@ -1,10 +1,7 @@
1
- "use strict";
2
1
  var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.HttpHeaders = void 0;
5
- const index_js_1 = require("../helpers/index.js");
6
- const http_headers_codes_enum_js_1 = require("./enums/http-headers-codes.enum.js");
7
- const knownKeys = Object.values(http_headers_codes_enum_js_1.HttpHeaderCodes);
2
+ import { ResponsiveMap } from '../helpers/index.js';
3
+ import { HttpHeaderCodes } from './enums/http-headers-codes.enum.js';
4
+ const knownKeys = Object.values(HttpHeaderCodes);
8
5
  const knownKeysLower = knownKeys.map(x => x.toLowerCase());
9
6
  const nodeInspectCustom = Symbol.for('nodejs.util.inspect.custom');
10
7
  const kEntries = Symbol('kEntries');
@@ -13,9 +10,9 @@ const kOptions = Symbol('kOptions');
13
10
  *
14
11
  * @class HttpHeaders
15
12
  */
16
- class HttpHeaders {
13
+ export class HttpHeaders {
17
14
  constructor(init, options) {
18
- this[_a] = new index_js_1.ResponsiveMap();
15
+ this[_a] = new ResponsiveMap();
19
16
  this[kOptions] = { ...options, onChange: undefined };
20
17
  if (init) {
21
18
  if (typeof init === 'string')
@@ -201,7 +198,6 @@ class HttpHeaders {
201
198
  this[kOptions].onChange();
202
199
  }
203
200
  }
204
- exports.HttpHeaders = HttpHeaders;
205
201
  HttpHeaders.kEntries = kEntries;
206
202
  HttpHeaders.kOptions = kOptions;
207
203
  HttpHeaders.NON_DELIMITED_HEADERS = {
@@ -1,10 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpMessageHost = void 0;
4
- const tslib_1 = require("tslib");
5
- const http_parser_js_1 = require("http-parser-js");
6
- const stream_1 = tslib_1.__importDefault(require("stream"));
7
- const http_headers_js_1 = require("./http-headers.js");
1
+ import { HTTPParser } from 'http-parser-js';
2
+ import stream from 'stream';
3
+ import { HttpHeaders } from './http-headers.js';
8
4
  const kHeaders = Symbol('kHeaders');
9
5
  const kHeadersProxy = Symbol('kHeadersProxy');
10
6
  const kTrailers = Symbol('kTrailers');
@@ -15,14 +11,14 @@ const kOnBodyChunk = Symbol('kOnBodyChunk');
15
11
  const kOnReadComplete = Symbol('kOnReadComplete');
16
12
  const crlfBuffer = Buffer.from('\r\n');
17
13
  const HTTP_VERSION_PATTERN = /^(\d)\.(\d)$/;
18
- class HttpMessageHost {
14
+ export class HttpMessageHost {
19
15
  constructor() {
20
16
  this.complete = false;
21
- stream_1.default.Duplex.apply(this);
22
- this[kHeaders] = new http_headers_js_1.HttpHeaders(undefined, {
17
+ stream.Duplex.apply(this);
18
+ this[kHeaders] = new HttpHeaders(undefined, {
23
19
  onChange: () => this._headersChanged = true
24
20
  });
25
- this[kTrailers] = new http_headers_js_1.HttpHeaders(undefined, {
21
+ this[kTrailers] = new HttpHeaders(undefined, {
26
22
  onChange: () => this._trailersChanged = true
27
23
  });
28
24
  }
@@ -148,11 +144,11 @@ class HttpMessageHost {
148
144
  this.body = args.body;
149
145
  }
150
146
  _parseBuffer(buf, parserType) {
151
- const parser = new http_parser_js_1.HTTPParser(parserType);
152
- parser[http_parser_js_1.HTTPParser.kOnHeadersComplete] = this[kOnHeaderReceived].bind(this);
153
- parser[http_parser_js_1.HTTPParser.kOnBody] = this[kOnBodyChunk].bind(this);
154
- parser[http_parser_js_1.HTTPParser.kOnHeaders] = this[kOnTrailersReceived].bind(this);
155
- parser[http_parser_js_1.HTTPParser.kOnMessageComplete] = this[kOnReadComplete].bind(this);
147
+ const parser = new HTTPParser(parserType);
148
+ parser[HTTPParser.kOnHeadersComplete] = this[kOnHeaderReceived].bind(this);
149
+ parser[HTTPParser.kOnBody] = this[kOnBodyChunk].bind(this);
150
+ parser[HTTPParser.kOnHeaders] = this[kOnTrailersReceived].bind(this);
151
+ parser[HTTPParser.kOnMessageComplete] = this[kOnReadComplete].bind(this);
156
152
  const buffer = Buffer.from(buf);
157
153
  let x = parser.execute(buffer);
158
154
  if (typeof x === 'object')
@@ -238,7 +234,6 @@ class HttpMessageHost {
238
234
  }
239
235
  }
240
236
  }
241
- exports.HttpMessageHost = HttpMessageHost;
242
237
  HttpMessageHost.kHeaders = kHeaders;
243
238
  HttpMessageHost.kHeadersProxy = kHeadersProxy;
244
239
  HttpMessageHost.kTrailers = kTrailers;
@@ -248,4 +243,4 @@ HttpMessageHost.kOnTrailersReceived = kOnTrailersReceived;
248
243
  HttpMessageHost.kOnBodyChunk = kOnBodyChunk;
249
244
  HttpMessageHost.kOnReadComplete = kOnReadComplete;
250
245
  // Mixin with Duplex
251
- Object.assign(HttpMessageHost.prototype, stream_1.default.Duplex.prototype);
246
+ Object.assign(HttpMessageHost.prototype, stream.Duplex.prototype);
@@ -1,22 +1,19 @@
1
- "use strict";
2
1
  var _a, _b, _c;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.encodeURIParam = exports.HttpParams = void 0;
5
- const fast_tokenizer_1 = require("fast-tokenizer");
6
- const index_js_1 = require("../helpers/index.js");
7
- const boolean_codec_js_1 = require("./codecs/boolean-codec.js");
8
- const date_codec_js_1 = require("./codecs/date-codec.js");
9
- const filter_codec_js_1 = require("./codecs/filter-codec.js");
10
- const integer_codec_js_1 = require("./codecs/integer-codec.js");
11
- const number_codec_js_1 = require("./codecs/number-codec.js");
12
- const string_codec_js_1 = require("./codecs/string-codec.js");
2
+ import { splitString, tokenize } from 'fast-tokenizer';
3
+ import { ResponsiveMap } from '../helpers/index.js';
4
+ import { BooleanCodec } from './codecs/boolean-codec.js';
5
+ import { DateCodec } from './codecs/date-codec.js';
6
+ import { FilterCodec } from './codecs/filter-codec.js';
7
+ import { IntegerCodec } from './codecs/integer-codec.js';
8
+ import { NumberCodec } from './codecs/number-codec.js';
9
+ import { StringCodec } from './codecs/string-codec.js';
13
10
  const kEntries = Symbol('kEntries');
14
11
  const kSize = Symbol('kSize');
15
12
  const kParamDefs = Symbol('kParamDefs');
16
13
  const kOptions = Symbol('kOptions');
17
- class HttpParams {
14
+ export class HttpParams {
18
15
  constructor(init, options) {
19
- this[_a] = new index_js_1.ResponsiveMap();
16
+ this[_a] = new ResponsiveMap();
20
17
  this[_b] = 0;
21
18
  this[_c] = new Map();
22
19
  this[kOptions] = { ...options, onChange: undefined };
@@ -45,11 +42,11 @@ class HttpParams {
45
42
  input = input.substring(1);
46
43
  if (!input)
47
44
  return this;
48
- const tokenizer = (0, fast_tokenizer_1.tokenize)(input, { delimiters: '&', quotes: true, brackets: true });
45
+ const tokenizer = tokenize(input, { delimiters: '&', quotes: true, brackets: true });
49
46
  for (const token of tokenizer) {
50
47
  if (!token)
51
48
  continue;
52
- const itemTokenizer = (0, fast_tokenizer_1.tokenize)(token, {
49
+ const itemTokenizer = tokenize(token, {
53
50
  delimiters: '=',
54
51
  quotes: true,
55
52
  brackets: true
@@ -191,7 +188,7 @@ class HttpParams {
191
188
  get(target, p, receiver) {
192
189
  if (typeof p === 'string') {
193
190
  const v = _this[kEntries].get(p);
194
- return v ? (v.length > 1 ? v : v[0]) : undefined;
191
+ return v ? (v.length > 1 ? v : v[0]) : null;
195
192
  }
196
193
  return Reflect.get(target, p, receiver);
197
194
  },
@@ -236,14 +233,14 @@ class HttpParams {
236
233
  ? value.map((v) => fn(v)).join(prmDef.arrayDelimiter || ',')
237
234
  : fn(value);
238
235
  }
239
- return encodeURIParam(value);
236
+ return encodeURIParam(String(value));
240
237
  }
241
238
  decodeValue(value, key) {
242
239
  const prmDef = this[kParamDefs].get(key);
243
240
  let val = value;
244
241
  if (prmDef) {
245
242
  if (prmDef.array) {
246
- val = (0, fast_tokenizer_1.splitString)(value, {
243
+ val = splitString(value, {
247
244
  delimiters: prmDef.arrayDelimiter || ',',
248
245
  brackets: true,
249
246
  quotes: true,
@@ -268,6 +265,12 @@ class HttpParams {
268
265
  }
269
266
  return decodeURIComponent(value);
270
267
  }
268
+ [(_a = kEntries, _b = kSize, _c = kParamDefs, Symbol.iterator)]() {
269
+ return this.entries();
270
+ }
271
+ get [Symbol.toStringTag]() {
272
+ return 'HttpParams';
273
+ }
271
274
  _append(name, value) {
272
275
  let values = this[kEntries].get(name);
273
276
  if (!values) {
@@ -283,8 +286,7 @@ class HttpParams {
283
286
  return false;
284
287
  const oldSize = this[kSize];
285
288
  if (value) {
286
- const valueToDelete = Array.isArray(value) ? value : [value];
287
- const newValues = oldValues.filter(x => !valueToDelete.includes(x));
289
+ const newValues = oldValues.filter(x => x === value);
288
290
  this[kEntries].set(name, newValues);
289
291
  this[kSize] += -oldValues.length + newValues.length;
290
292
  }
@@ -295,7 +297,7 @@ class HttpParams {
295
297
  return oldSize !== this[kSize];
296
298
  }
297
299
  _set(name, value, index) {
298
- if (value == null) {
300
+ if (value === undefined) {
299
301
  this._delete(name);
300
302
  return;
301
303
  }
@@ -314,25 +316,18 @@ class HttpParams {
314
316
  values[Math.min(index, values.length)] = value;
315
317
  this[kSize] += -oldLen + values.length;
316
318
  }
317
- [(_a = kEntries, _b = kSize, _c = kParamDefs, Symbol.iterator)]() {
318
- return this.entries();
319
- }
320
- get [Symbol.toStringTag]() {
321
- return 'HttpParams';
322
- }
323
319
  }
324
- exports.HttpParams = HttpParams;
325
320
  HttpParams.kEntries = kEntries;
326
321
  HttpParams.kSize = kSize;
327
322
  HttpParams.kParamDefs = kParamDefs;
328
323
  HttpParams.kOptions = kOptions;
329
324
  HttpParams.codecs = {
330
- 'boolean': new boolean_codec_js_1.BooleanCodec(),
331
- 'date': new date_codec_js_1.DateCodec(),
332
- 'filter': new filter_codec_js_1.FilterCodec(),
333
- 'integer': new integer_codec_js_1.IntegerCodec(),
334
- 'number': new number_codec_js_1.NumberCodec(),
335
- 'string': new string_codec_js_1.StringCodec()
325
+ 'boolean': new BooleanCodec(),
326
+ 'date': new DateCodec(),
327
+ 'filter': new FilterCodec(),
328
+ 'integer': new IntegerCodec(),
329
+ 'number': new NumberCodec(),
330
+ 'string': new StringCodec()
336
331
  };
337
332
  /**
338
333
  * Encode input string with standard encodeURIComponent and then un-encode specific characters.
@@ -348,7 +343,6 @@ const ENCODING_REPLACEMENTS = {
348
343
  '3F': '?',
349
344
  '40': '@'
350
345
  };
351
- function encodeURIParam(v) {
346
+ export function encodeURIParam(v) {
352
347
  return encodeURIComponent(v).replace(ENCODING_REGEX, (s, t) => ENCODING_REPLACEMENTS[t] ?? s);
353
348
  }
354
- exports.encodeURIParam = encodeURIParam;
@@ -1,14 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpRequestMessage = void 0;
4
- const tslib_1 = require("tslib");
5
- const accepts_1 = tslib_1.__importDefault(require("accepts"));
6
- const http_parser_js_1 = require("http-parser-js");
7
- const type_is_1 = tslib_1.__importDefault(require("type-is"));
8
- const http_message_host_js_1 = require("./http-message.host.js");
9
- const http_params_js_1 = require("./http-params.js");
1
+ import accepts from 'accepts';
2
+ import { HTTPParser } from 'http-parser-js';
3
+ import typeIs from 'type-is';
4
+ import { HttpMessageHost } from './http-message.host.js';
5
+ import { HttpParams } from './http-params.js';
10
6
  const HTTP_VERSION_PATTERN = /^(\d)\.(\d)$/;
11
- var HttpRequestMessage;
7
+ export var HttpRequestMessage;
12
8
  (function (HttpRequestMessage) {
13
9
  function create(init) {
14
10
  return HttpRequestMessageHost.create(init);
@@ -22,19 +18,19 @@ var HttpRequestMessage;
22
18
  return HttpRequestMessageHost.fromStream(readable);
23
19
  }
24
20
  HttpRequestMessage.fromStream = fromStream;
25
- })(HttpRequestMessage = exports.HttpRequestMessage || (exports.HttpRequestMessage = {}));
21
+ })(HttpRequestMessage || (HttpRequestMessage = {}));
26
22
  const kQuery = Symbol('kQuery');
27
23
  const kQueryProxy = Symbol('kQueryProxy');
28
24
  const kProtocol = Symbol('kProtocol');
29
25
  /**
30
26
  *
31
27
  */
32
- class HttpRequestMessageHost extends http_message_host_js_1.HttpMessageHost {
28
+ class HttpRequestMessageHost extends HttpMessageHost {
33
29
  constructor() {
34
30
  super();
35
31
  this.httpVersionMajor = 1;
36
32
  this.httpVersionMinor = 0;
37
- this[kQuery] = new http_params_js_1.HttpParams();
33
+ this[kQuery] = new HttpParams();
38
34
  this[kQueryProxy] = this[kQuery].getProxy();
39
35
  }
40
36
  get httpVersion() {
@@ -95,22 +91,22 @@ class HttpRequestMessageHost extends http_message_host_js_1.HttpMessageHost {
95
91
  return this.getHeader(name);
96
92
  }
97
93
  accepts(...type) {
98
- const accept = (0, accepts_1.default)(this);
94
+ const accept = accepts(this);
99
95
  // eslint-disable-next-line prefer-spread
100
96
  return accept.types.apply(accept, type);
101
97
  }
102
98
  acceptsCharsets(...charset) {
103
- const accept = (0, accepts_1.default)(this);
99
+ const accept = accepts(this);
104
100
  // eslint-disable-next-line prefer-spread
105
101
  return accept.charsets.apply(accept, charset);
106
102
  }
107
103
  acceptsEncodings(...encoding) {
108
- const accept = (0, accepts_1.default)(this);
104
+ const accept = accepts(this);
109
105
  // eslint-disable-next-line prefer-spread
110
106
  return accept.encodings.apply(accept, encoding);
111
107
  }
112
108
  acceptsLanguages(...lang) {
113
- const accept = (0, accepts_1.default)(this);
109
+ const accept = accepts(this);
114
110
  // eslint-disable-next-line prefer-spread
115
111
  return accept.languages.apply(accept, lang);
116
112
  }
@@ -119,7 +115,7 @@ class HttpRequestMessageHost extends http_message_host_js_1.HttpMessageHost {
119
115
  if (otherTypes.length)
120
116
  types.push(...otherTypes);
121
117
  const contentType = this.getHeader('content-type');
122
- return contentType ? type_is_1.default.is(contentType, types) : null;
118
+ return contentType ? typeIs.is(contentType, types) : null;
123
119
  }
124
120
  _init(init) {
125
121
  super._init(init);
@@ -128,9 +124,9 @@ class HttpRequestMessageHost extends http_message_host_js_1.HttpMessageHost {
128
124
  this.baseUrl = init.baseUrl || this.url;
129
125
  this.protocol = init.protocol;
130
126
  }
131
- [http_message_host_js_1.HttpMessageHost.kOnHeaderReceived](info) {
132
- super[http_message_host_js_1.HttpMessageHost.kOnHeaderReceived](info);
133
- this.method = http_parser_js_1.HTTPParser.methods[info.method];
127
+ [HttpMessageHost.kOnHeaderReceived](info) {
128
+ super[HttpMessageHost.kOnHeaderReceived](info);
129
+ this.method = HTTPParser.methods[info.method];
134
130
  this.url = info.url;
135
131
  this.baseUrl = info.url;
136
132
  }
@@ -141,7 +137,7 @@ class HttpRequestMessageHost extends http_message_host_js_1.HttpMessageHost {
141
137
  }
142
138
  static fromBuffer(buffer) {
143
139
  const msg = new HttpRequestMessageHost();
144
- msg._parseBuffer(buffer, http_parser_js_1.HTTPParser.REQUEST);
140
+ msg._parseBuffer(buffer, HTTPParser.REQUEST);
145
141
  return msg;
146
142
  }
147
143
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -1,20 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpResponseMessageHost = exports.HttpResponseMessage = void 0;
4
- const tslib_1 = require("tslib");
5
- const content_disposition_1 = tslib_1.__importDefault(require("content-disposition"));
6
- const cookie_1 = tslib_1.__importDefault(require("cookie"));
7
- const cookie_signature_1 = tslib_1.__importDefault(require("cookie-signature"));
8
- const encodeurl_1 = tslib_1.__importDefault(require("encodeurl"));
9
- const http_parser_js_1 = require("http-parser-js");
10
- const mime_types_1 = tslib_1.__importDefault(require("mime-types"));
11
- const path_1 = tslib_1.__importDefault(require("path"));
12
- const http_status_messages_js_1 = require("./enums/http-status-messages.js");
13
- const http_message_host_js_1 = require("./http-message.host.js");
1
+ import contentDisposition from 'content-disposition';
2
+ import cookie from 'cookie';
3
+ import cookieSignature from 'cookie-signature';
4
+ import encodeUrl from 'encodeurl';
5
+ import { HTTPParser } from 'http-parser-js';
6
+ import mime from 'mime-types';
7
+ import path from 'path';
8
+ import { HttpStatusMessages } from './enums/http-status-messages.js';
9
+ import { HttpMessageHost } from './http-message.host.js';
14
10
  /**
15
11
  * @namespace HttpResponseMessage
16
12
  */
17
- var HttpResponseMessage;
13
+ export var HttpResponseMessage;
18
14
  (function (HttpResponseMessage) {
19
15
  function create(init) {
20
16
  return HttpResponseMessageHost.create(init);
@@ -28,11 +24,11 @@ var HttpResponseMessage;
28
24
  return HttpResponseMessageHost.fromStream(readable);
29
25
  }
30
26
  HttpResponseMessage.fromStream = fromStream;
31
- })(HttpResponseMessage = exports.HttpResponseMessage || (exports.HttpResponseMessage = {}));
27
+ })(HttpResponseMessage || (HttpResponseMessage = {}));
32
28
  /**
33
29
  * @class HttpResponseMessageHost
34
30
  */
35
- class HttpResponseMessageHost extends http_message_host_js_1.HttpMessageHost {
31
+ export class HttpResponseMessageHost extends HttpMessageHost {
36
32
  constructor() {
37
33
  super();
38
34
  }
@@ -40,7 +36,7 @@ class HttpResponseMessageHost extends http_message_host_js_1.HttpMessageHost {
40
36
  return this.set(arg0, arg1);
41
37
  }
42
38
  append(name, value) {
43
- this[http_message_host_js_1.HttpMessageHost.kHeaders].append(name, value);
39
+ this[HttpMessageHost.kHeaders].append(name, value);
44
40
  return this;
45
41
  }
46
42
  /**
@@ -48,8 +44,8 @@ class HttpResponseMessageHost extends http_message_host_js_1.HttpMessageHost {
48
44
  */
49
45
  attachment(filename) {
50
46
  if (filename)
51
- this.type(path_1.default.extname(filename));
52
- this.set('Content-Disposition', (0, content_disposition_1.default)(filename));
47
+ this.type(path.extname(filename));
48
+ this.set('Content-Disposition', contentDisposition(filename));
53
49
  return this;
54
50
  }
55
51
  /**
@@ -72,7 +68,7 @@ class HttpResponseMessageHost extends http_message_host_js_1.HttpMessageHost {
72
68
  */
73
69
  type(type) {
74
70
  const ct = type.indexOf('/') === -1
75
- ? mime_types_1.default.lookup(type)
71
+ ? mime.lookup(type)
76
72
  : type;
77
73
  if (ct)
78
74
  this.set('Content-Type', ct);
@@ -107,7 +103,7 @@ class HttpResponseMessageHost extends http_message_host_js_1.HttpMessageHost {
107
103
  ? 'j:' + JSON.stringify(value)
108
104
  : String(value);
109
105
  if (signed)
110
- val = 's:' + cookie_signature_1.default.sign(val, secret);
106
+ val = 's:' + cookieSignature.sign(val, secret);
111
107
  if (opts.maxAge != null) {
112
108
  const maxAge = opts.maxAge - 0;
113
109
  if (!isNaN(maxAge)) {
@@ -123,7 +119,7 @@ class HttpResponseMessageHost extends http_message_host_js_1.HttpMessageHost {
123
119
  a = a.filter(x => !x.startsWith(name + '='));
124
120
  this.set('Set-Cookie', a);
125
121
  }
126
- this.append('Set-Cookie', cookie_1.default.serialize(name, String(val), opts));
122
+ this.append('Set-Cookie', cookie.serialize(name, String(val), opts));
127
123
  return this;
128
124
  }
129
125
  /**
@@ -182,7 +178,7 @@ class HttpResponseMessageHost extends http_message_host_js_1.HttpMessageHost {
182
178
  if (url === 'back')
183
179
  loc = this.req?.get('Referrer') || '/';
184
180
  // set location
185
- return this.set('Location', (0, encodeurl_1.default)(loc));
181
+ return this.set('Location', encodeUrl(loc));
186
182
  }
187
183
  /**
188
184
  * Set status `code`.
@@ -203,7 +199,7 @@ class HttpResponseMessageHost extends http_message_host_js_1.HttpMessageHost {
203
199
  * res.sendStatus(500); // equivalent to res.status(500).send('Internal Server Error')
204
200
  */
205
201
  sendStatus(statusCode) {
206
- const body = http_status_messages_js_1.HttpStatusMessages[statusCode] || String(statusCode);
202
+ const body = HttpStatusMessages[statusCode] || String(statusCode);
207
203
  this.statusCode = statusCode;
208
204
  this.type('txt');
209
205
  return this.send(body);
@@ -215,8 +211,8 @@ class HttpResponseMessageHost extends http_message_host_js_1.HttpMessageHost {
215
211
  this.req = init?.req;
216
212
  this.chunkedEncoding = init?.chunkedEncoding;
217
213
  }
218
- [http_message_host_js_1.HttpMessageHost.kOnHeaderReceived](info) {
219
- super[http_message_host_js_1.HttpMessageHost.kOnHeaderReceived](info);
214
+ [HttpMessageHost.kOnHeaderReceived](info) {
215
+ super[HttpMessageHost.kOnHeaderReceived](info);
220
216
  this.statusCode = info.statusCode;
221
217
  this.statusMessage = info.statusMessage;
222
218
  }
@@ -227,7 +223,7 @@ class HttpResponseMessageHost extends http_message_host_js_1.HttpMessageHost {
227
223
  }
228
224
  static fromBuffer(buffer) {
229
225
  const msg = new HttpResponseMessageHost();
230
- msg._parseBuffer(buffer, http_parser_js_1.HTTPParser.RESPONSE);
226
+ msg._parseBuffer(buffer, HTTPParser.RESPONSE);
231
227
  return msg;
232
228
  }
233
229
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -235,4 +231,3 @@ class HttpResponseMessageHost extends http_message_host_js_1.HttpMessageHost {
235
231
  throw new Error('fromStream is not implemented yet');
236
232
  }
237
233
  }
238
- exports.HttpResponseMessageHost = HttpResponseMessageHost;
package/esm/http/index.js CHANGED
@@ -1,17 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./http-headers.js"), exports);
5
- tslib_1.__exportStar(require("./http-params.js"), exports);
6
- tslib_1.__exportStar(require("./http-response-message.js"), exports);
7
- tslib_1.__exportStar(require("./http-request-message.js"), exports);
8
- tslib_1.__exportStar(require("./enums/http-headers-codes.enum.js"), exports);
9
- tslib_1.__exportStar(require("./enums/http-status-codes.enum.js"), exports);
10
- tslib_1.__exportStar(require("./interfaces/client-http-headers.interface.js"), exports);
11
- tslib_1.__exportStar(require("./interfaces/server-http-headers.interface.js"), exports);
12
- tslib_1.__exportStar(require("./codecs/date-codec.js"), exports);
13
- tslib_1.__exportStar(require("./codecs/boolean-codec.js"), exports);
14
- tslib_1.__exportStar(require("./codecs/filter-codec.js"), exports);
15
- tslib_1.__exportStar(require("./codecs/integer-codec.js"), exports);
16
- tslib_1.__exportStar(require("./codecs/number-codec.js"), exports);
17
- tslib_1.__exportStar(require("./codecs/string-codec.js"), exports);
1
+ export * from './http-headers.js';
2
+ export * from './http-params.js';
3
+ export * from './http-response-message.js';
4
+ export * from './http-request-message.js';
5
+ export * from './enums/http-headers-codes.enum.js';
6
+ export * from './enums/http-status-codes.enum.js';
7
+ export * from './interfaces/client-http-headers.interface.js';
8
+ export * from './interfaces/server-http-headers.interface.js';
9
+ export * from './codecs/date-codec.js';
10
+ export * from './codecs/boolean-codec.js';
11
+ export * from './codecs/filter-codec.js';
12
+ export * from './codecs/integer-codec.js';
13
+ export * from './codecs/number-codec.js';
14
+ export * from './codecs/string-codec.js';
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/esm/i18n/i18n.js CHANGED
@@ -1,16 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.I18n = exports.BaseI18n = void 0;
4
- const tslib_1 = require("tslib");
5
- const fast_tokenizer_1 = require("fast-tokenizer");
6
- const fs_1 = tslib_1.__importDefault(require("fs"));
7
- const i18next_1 = tslib_1.__importDefault(require("i18next"));
8
- const path_1 = tslib_1.__importDefault(require("path"));
9
- const index_js_1 = require("../helpers/index.js");
10
- const string_utils_js_1 = require("./string-utils.js");
11
- exports.BaseI18n = Object.getPrototypeOf(i18next_1.default).constructor;
1
+ import { splitString, tokenize } from 'fast-tokenizer';
2
+ import fs from 'fs';
3
+ import i18next from 'i18next';
4
+ import path from 'path';
5
+ import { isUrl } from '../helpers/index.js';
6
+ import { unescapeString } from './string-utils.js';
7
+ export const BaseI18n = Object.getPrototypeOf(i18next).constructor;
12
8
  const globalLocaleDirs = [];
13
- class I18n extends exports.BaseI18n {
9
+ export class I18n extends BaseI18n {
14
10
  async init(arg0, arg1) {
15
11
  const options = typeof arg0 === 'object' ? arg0 : {};
16
12
  const callback = typeof arg0 === 'function' ? arg0 : arg1;
@@ -58,11 +54,11 @@ class I18n extends exports.BaseI18n {
58
54
  }
59
55
  async loadResourceBundle(lang, ns, filePath, deep, overwrite) {
60
56
  let obj;
61
- if ((0, index_js_1.isUrl)(filePath)) {
57
+ if (isUrl(filePath)) {
62
58
  obj = (await fetch(filePath, { headers: { accept: 'application/json' } })).json();
63
59
  }
64
60
  else {
65
- const content = fs_1.default.readFileSync(filePath, 'utf8');
61
+ const content = fs.readFileSync(filePath, 'utf8');
66
62
  obj = JSON.parse(content);
67
63
  }
68
64
  this.addResourceBundle(lang, ns, obj, deep, overwrite);
@@ -70,18 +66,18 @@ class I18n extends exports.BaseI18n {
70
66
  async loadResourceDir(dirnames, deep, overwrite) {
71
67
  for (const dirname of Array.isArray(dirnames) ? dirnames : [dirnames]) {
72
68
  /* istanbul ignore next */
73
- if (!(fs_1.default.existsSync(dirname)))
69
+ if (!(fs.existsSync(dirname)))
74
70
  continue;
75
- const languageDirs = fs_1.default.readdirSync(dirname);
71
+ const languageDirs = fs.readdirSync(dirname);
76
72
  for (const lang of languageDirs) {
77
- const langDir = path_1.default.join(dirname, lang);
78
- if ((fs_1.default.statSync(langDir)).isDirectory()) {
79
- const nsDirs = fs_1.default.readdirSync(langDir);
73
+ const langDir = path.join(dirname, lang);
74
+ if ((fs.statSync(langDir)).isDirectory()) {
75
+ const nsDirs = fs.readdirSync(langDir);
80
76
  for (const nsfile of nsDirs) {
81
- const nsFilePath = path_1.default.join(langDir, nsfile);
82
- const ext = path_1.default.extname(nsfile);
83
- if (ext === '.json' && (fs_1.default.statSync(nsFilePath)).isFile()) {
84
- const ns = path_1.default.basename(nsfile, ext);
77
+ const nsFilePath = path.join(langDir, nsfile);
78
+ const ext = path.extname(nsfile);
79
+ if (ext === '.json' && (fs.statSync(nsFilePath)).isFile()) {
80
+ const ns = path.basename(nsfile, ext);
85
81
  await this.loadResourceBundle(lang, ns, nsFilePath, deep, overwrite);
86
82
  }
87
83
  }
@@ -104,7 +100,7 @@ class I18n extends exports.BaseI18n {
104
100
  return objectStack.get(input);
105
101
  if (typeof input === 'string') {
106
102
  let s = '';
107
- for (let token of (0, fast_tokenizer_1.tokenize)(input, {
103
+ for (let token of tokenize(input, {
108
104
  brackets: { '$t(': ')' },
109
105
  quotes: true,
110
106
  keepQuotes: true,
@@ -113,12 +109,12 @@ class I18n extends exports.BaseI18n {
113
109
  })) {
114
110
  if (token.startsWith('$t(') && token.endsWith(')')) {
115
111
  token = token.substring(3, token.length - 1);
116
- const a = (0, fast_tokenizer_1.splitString)(token, { delimiters: '?', quotes: true, brackets: { '{': '}' } });
117
- const fallback = (0, string_utils_js_1.unescapeString)(token.substring((a[0] || '').length + 1));
112
+ const a = splitString(token, { delimiters: '?', quotes: true, brackets: { '{': '}' } });
113
+ const fallback = unescapeString(token.substring((a[0] || '').length + 1));
118
114
  token = a[0] || '';
119
115
  const keys = [];
120
116
  let opts = null;
121
- for (const token2 of (0, fast_tokenizer_1.tokenize)(token, { delimiters: ',', quotes: true, brackets: { '{': '}' } })) {
117
+ for (const token2 of tokenize(token, { delimiters: ',', quotes: true, brackets: { '{': '}' } })) {
122
118
  if (token2.startsWith('{')) {
123
119
  opts = JSON.parse(token2);
124
120
  continue;
@@ -167,5 +163,4 @@ class I18n extends exports.BaseI18n {
167
163
  return defaultInstance;
168
164
  }
169
165
  }
170
- exports.I18n = I18n;
171
166
  const defaultInstance = I18n.createInstance();
package/esm/i18n/index.js CHANGED
@@ -1,10 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.i18n = void 0;
4
- const tslib_1 = require("tslib");
5
- const i18n_js_1 = require("./i18n.js");
6
- tslib_1.__exportStar(require("./i18n.js"), exports);
7
- tslib_1.__exportStar(require("./translate.js"), exports);
8
- const i18n = i18n_js_1.I18n.createInstance();
9
- exports.i18n = i18n;
1
+ import { I18n } from './i18n.js';
2
+ export * from './i18n.js';
3
+ export * from './translate.js';
4
+ const i18n = I18n.createInstance();
10
5
  i18n.init().catch(() => void 0);
6
+ export { i18n };