@opra/common 0.10.2 → 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 +12 -12
@@ -1,16 +1,22 @@
1
- import antlr4 from 'antlr4';
1
+ import antlr4 from '@browsery/antlr4';
2
2
  import { ArithmeticExpressionContext, LogicalExpressionContext, } from './antlr/OpraFilterParser.js';
3
3
  import { ArithmeticExpression, ArrayExpression, BooleanLiteral, ComparisonExpression, DateLiteral, LogicalExpression, NullLiteral, NumberLiteral, ParenthesesExpression, QualifiedIdentifier, StringLiteral, TimeLiteral } from './ast/index.js';
4
4
  import { ExternalConstant } from './ast/terms/external-constant.js';
5
5
  import { SyntaxError } from './errors.js';
6
6
  import { unquoteFilterString } from './utils.js';
7
- // Fix: antlr4 d.ts files is invalid
7
+ // Fix: antlr4 d.ts files are invalid
8
8
  const ParseTreeVisitor = antlr4.tree.ParseTreeVisitor;
9
9
  export class FilterTreeVisitor extends ParseTreeVisitor {
10
10
  constructor(options) {
11
11
  super();
12
12
  this._timeZone = options?.timeZone;
13
13
  }
14
+ visitChildren(node) {
15
+ const result = super.visitChildren(node);
16
+ if (Array.isArray(result) && result.length < 2)
17
+ return result[0];
18
+ return result;
19
+ }
14
20
  defaultResult() {
15
21
  return undefined;
16
22
  }
@@ -1,5 +1,5 @@
1
- import { ErrorListener, RecognitionException } from 'antlr4';
2
- import { Recognizer } from 'antlr4/src/antlr4/Recognizer';
1
+ import { ErrorListener, RecognitionException } from '@browsery/antlr4';
2
+ import { Recognizer } from '@browsery/antlr4/typings/Recognizer';
3
3
  import { FilterParseError } from './errors.js';
4
4
  export declare class OpraErrorListener extends ErrorListener<any> {
5
5
  errors: FilterParseError[];
@@ -1,4 +1,4 @@
1
- import { ErrorListener } from 'antlr4';
1
+ import { ErrorListener } from '@browsery/antlr4';
2
2
  import { FilterParseError } from './errors.js';
3
3
  export class OpraErrorListener extends ErrorListener {
4
4
  constructor(errors) {
@@ -6,6 +6,6 @@ export class OpraErrorListener extends ErrorListener {
6
6
  this.errors = errors;
7
7
  }
8
8
  syntaxError(recognizer, offendingSymbol, line, column, msg, e) {
9
- this.errors.push(new FilterParseError(msg, { recognizer, offendingSymbol, line, e }));
9
+ this.errors.push(new FilterParseError(msg, { recognizer, offendingSymbol, line, column, e }));
10
10
  }
11
11
  }
@@ -1,2 +1,2 @@
1
- import type { ParseTreeVisitor } from 'antlr4';
1
+ import type { ParseTreeVisitor } from '@browsery/antlr4';
2
2
  export declare function parseFilter(text: string, visitor?: ParseTreeVisitor<any>): any;
@@ -1,4 +1,4 @@
1
- import { CharStream, CommonTokenStream } from 'antlr4';
1
+ import { CharStream, CommonTokenStream } from '@browsery/antlr4';
2
2
  import OpraFilterLexer from './antlr/OpraFilterLexer.js';
3
3
  import OpraFilterParser from './antlr/OpraFilterParser.js';
4
4
  import { SyntaxError } from './errors.js';
@@ -1,8 +1,21 @@
1
+ export interface ResponsiveMapOptions {
2
+ wellKnownKeys?: string[];
3
+ caseSensitive?: boolean;
4
+ }
5
+ export type ResponsiveMapInit<K, V> = ResponsiveMap<K, V> | Map<K, V> | Record<any, V>;
6
+ declare const kKeyMap: unique symbol;
7
+ declare const kKeyOrder: unique symbol;
8
+ declare const kWellKnownKeys: unique symbol;
9
+ declare const kOptions: unique symbol;
10
+ /**
11
+ * A Map implementation that supports case-insensitivity and ordered keys
12
+ */
1
13
  export declare class ResponsiveMap<K, V> extends Map<K, V> {
2
- private _keyMap;
3
- private _keyOrder;
4
- private _wellKnownKeyMap;
5
- constructor(data?: any, wellKnownKeys?: string[]);
14
+ private [kKeyMap];
15
+ private [kKeyOrder];
16
+ private [kWellKnownKeys];
17
+ private [kOptions];
18
+ constructor(init?: ResponsiveMapInit<K, V>, options?: ResponsiveMapOptions);
6
19
  clear(): void;
7
20
  get(key: K): V | undefined;
8
21
  has(key: K): boolean;
@@ -14,5 +27,6 @@ export declare class ResponsiveMap<K, V> extends Map<K, V> {
14
27
  sort(compareFn?: (a: K, b: K) => number): this;
15
28
  [Symbol.iterator](): IterableIterator<[K, V]>;
16
29
  protected _getOriginalKey(key: K): K;
17
- protected _getLowerKey(key: K): K;
30
+ protected _getStoringKey(key: K): K;
18
31
  }
32
+ export {};
@@ -1,42 +1,55 @@
1
+ var _a, _b, _c, _d;
2
+ function isMap(v) {
3
+ return v && typeof v.forEach === 'function';
4
+ }
5
+ const kKeyMap = Symbol('kKeyMap');
6
+ const kKeyOrder = Symbol('kKeyOrder');
7
+ const kWellKnownKeys = Symbol('kWellKnownKeys');
8
+ const kOptions = Symbol('kOptions');
9
+ /**
10
+ * A Map implementation that supports case-insensitivity and ordered keys
11
+ */
1
12
  export class ResponsiveMap extends Map {
2
- constructor(data, wellKnownKeys) {
13
+ constructor(init, options) {
3
14
  super();
4
- this._keyMap = new Map();
5
- this._keyOrder = [];
6
- this._wellKnownKeyMap = new Map();
7
- if (wellKnownKeys)
8
- wellKnownKeys.forEach(k => this._wellKnownKeyMap.set(k.toLowerCase(), k));
9
- if (typeof data?.forEach === 'function') {
10
- data.forEach((v, k) => this.set(k, v));
15
+ this[_a] = new Map();
16
+ this[_b] = [];
17
+ this[_c] = new Map();
18
+ this[_d] = { caseSensitive: false };
19
+ this[kOptions].caseSensitive = !!options?.caseSensitive;
20
+ if (options?.wellKnownKeys)
21
+ options.wellKnownKeys.forEach(k => this[kWellKnownKeys].set(k.toLowerCase(), k));
22
+ if (isMap(init)) {
23
+ init.forEach((v, k) => this.set(k, v));
11
24
  }
12
- else if (data && typeof data === 'object')
13
- Object.keys(data).forEach(k => this.set(k, data[k]));
25
+ else if (init && typeof init === 'object')
26
+ Object.keys(init).forEach(k => this.set(k, init[k]));
14
27
  }
15
28
  clear() {
16
29
  super.clear();
17
- this._keyMap.clear();
18
- this._keyOrder = [];
30
+ this[kKeyMap].clear();
31
+ this[kKeyOrder] = [];
19
32
  }
20
33
  get(key) {
21
34
  const orgKey = this._getOriginalKey(key);
22
35
  return super.get(orgKey);
23
36
  }
24
37
  has(key) {
25
- return this._keyMap.has(this._getLowerKey(key));
38
+ return this[kKeyMap].has(this._getStoringKey(key));
26
39
  }
27
40
  set(key, value) {
28
41
  key = this._getOriginalKey(key);
29
- this._keyMap.set(this._getLowerKey(key), key);
30
- if (!this._keyOrder.includes(key))
31
- this._keyOrder.push(key);
42
+ this[kKeyMap].set(this._getStoringKey(key), key);
43
+ if (!this[kKeyOrder].includes(key))
44
+ this[kKeyOrder].push(key);
32
45
  return super.set(key, value);
33
46
  }
34
47
  keys() {
35
- return this._keyOrder.values();
48
+ return this[kKeyOrder].values();
36
49
  }
37
50
  values() {
38
51
  let i = -1;
39
- const arr = this._keyOrder;
52
+ const arr = this[kKeyOrder];
40
53
  const map = this;
41
54
  return {
42
55
  [Symbol.iterator]() {
@@ -53,7 +66,7 @@ export class ResponsiveMap extends Map {
53
66
  }
54
67
  entries() {
55
68
  let i = -1;
56
- const arr = this._keyOrder;
69
+ const arr = this[kKeyOrder];
57
70
  const map = this;
58
71
  return {
59
72
  [Symbol.iterator]() {
@@ -70,27 +83,31 @@ export class ResponsiveMap extends Map {
70
83
  }
71
84
  delete(key) {
72
85
  const orgKey = this._getOriginalKey(key);
73
- const k = this._getLowerKey(key);
74
- this._keyMap.delete(k);
75
- const i = this._keyOrder.indexOf(orgKey);
86
+ const k = this._getStoringKey(key);
87
+ this[kKeyMap].delete(k);
88
+ const i = this[kKeyOrder].indexOf(orgKey);
76
89
  if (i >= 0)
77
- this._keyOrder.splice(i, 1);
90
+ this[kKeyOrder].splice(i, 1);
78
91
  return super.delete(orgKey);
79
92
  }
80
93
  sort(compareFn) {
81
- this._keyOrder.sort(compareFn);
94
+ this[kKeyOrder].sort(compareFn);
82
95
  return this;
83
96
  }
84
- [Symbol.iterator]() {
97
+ [(_a = kKeyMap, _b = kKeyOrder, _c = kWellKnownKeys, _d = kOptions, Symbol.iterator)]() {
85
98
  return this.entries();
86
99
  }
87
100
  _getOriginalKey(key) {
101
+ if (this[kOptions].caseSensitive)
102
+ return key;
88
103
  if (typeof key === 'string')
89
- return this._keyMap.get(key.toLowerCase()) ??
90
- (this._wellKnownKeyMap.get(key.toLowerCase()) ?? key);
104
+ return this[kKeyMap].get(key.toLowerCase()) ??
105
+ (this[kWellKnownKeys].get(key.toLowerCase()) ?? key);
91
106
  return key;
92
107
  }
93
- _getLowerKey(key) {
108
+ _getStoringKey(key) {
109
+ if (this[kOptions].caseSensitive)
110
+ return key;
94
111
  if (typeof key === 'string')
95
112
  return key.toLowerCase();
96
113
  return key;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers#controls
3
3
  */
4
- export declare enum HttpHeaders {
4
+ export declare enum HttpHeaderCodes {
5
5
  X_Opra_Version = "X-Opra-Version",
6
6
  X_Opra_DataType = "X-Opra-DataType",
7
7
  X_Opra_Count = "X-Opra-Count",