@opra/common 0.10.3 → 0.13.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 (132) 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/data-type/data-type.js +4 -0
  29. package/cjs/schema/implementation/opra-document.js +12 -11
  30. package/cjs/schema/implementation/resource/collection-resource-info.js +15 -0
  31. package/cjs/schema/implementation/resource/singleton-resource-info.js +8 -0
  32. package/cjs/url/opra-url-path.js +96 -72
  33. package/cjs/url/opra-url-search-params.js +16 -234
  34. package/cjs/url/opra-url.js +201 -160
  35. package/esm/filter/antlr/OpraFilterLexer.d.ts +1 -1
  36. package/esm/filter/antlr/OpraFilterLexer.js +1 -1
  37. package/esm/filter/antlr/OpraFilterListener.d.ts +1 -1
  38. package/esm/filter/antlr/OpraFilterListener.js +1 -1
  39. package/esm/filter/antlr/OpraFilterParser.d.ts +1 -1
  40. package/esm/filter/antlr/OpraFilterParser.js +5 -5
  41. package/esm/filter/antlr/OpraFilterVisitor.d.ts +1 -1
  42. package/esm/filter/antlr/OpraFilterVisitor.js +1 -1
  43. package/esm/filter/ast/expressions/arithmetic-expression.d.ts +1 -1
  44. package/esm/filter/ast/expressions/comparison-expression.d.ts +1 -1
  45. package/esm/filter/ast/expressions/logical-expression.d.ts +1 -1
  46. package/esm/filter/build.d.ts +3 -3
  47. package/esm/filter/errors.d.ts +4 -2
  48. package/esm/filter/filter-tree-visitor.d.ts +2 -1
  49. package/esm/filter/filter-tree-visitor.js +8 -2
  50. package/esm/filter/opra-error-listener.d.ts +2 -2
  51. package/esm/filter/opra-error-listener.js +2 -2
  52. package/esm/filter/parse.d.ts +1 -1
  53. package/esm/filter/parse.js +1 -1
  54. package/esm/helpers/responsive-map.d.ts +19 -5
  55. package/esm/helpers/responsive-map.js +45 -28
  56. package/esm/http/enums/{http-headers.enum.d.ts → http-headers-codes.enum.d.ts} +1 -1
  57. package/{cjs/http/enums/http-headers.enum.js → esm/http/enums/http-headers-codes.enum.js} +92 -95
  58. package/esm/http/enums/{http-status.enum.d.ts → http-status-codes.enum.d.ts} +1 -1
  59. package/{cjs/http/enums/http-status.enum.js → esm/http/enums/http-status-codes.enum.js} +59 -62
  60. package/esm/http/http-headers.d.ts +70 -0
  61. package/esm/http/http-headers.js +209 -0
  62. package/esm/http/http-param-codec.d.ts +4 -0
  63. package/esm/http/http-param-codec.js +2 -0
  64. package/esm/http/http-params.d.ts +99 -0
  65. package/esm/http/http-params.js +317 -0
  66. package/esm/http/http-request-node.d.ts +34 -0
  67. package/esm/http/http-request-node.js +101 -0
  68. package/esm/http/http-request.d.ts +73 -31
  69. package/esm/http/http-request.js +72 -87
  70. package/esm/http/http-response.d.ts +41 -0
  71. package/esm/http/http-response.js +19 -0
  72. package/esm/http/index.d.ts +13 -2
  73. package/esm/http/index.js +13 -2
  74. package/esm/http/interfaces/client-http-headers.interface.d.ts +1 -1
  75. package/esm/http/interfaces/server-http-headers.interface.d.ts +1 -1
  76. package/esm/http/multipart/batch-multipart.d.ts +1 -1
  77. package/esm/http/multipart/batch-multipart.js +12 -12
  78. package/esm/http/multipart/http-request-content.d.ts +1 -1
  79. package/esm/http/multipart/http-response-content.d.ts +1 -1
  80. package/esm/http/param-codec/boolean-codec.d.ts +5 -0
  81. package/esm/http/param-codec/boolean-codec.js +21 -0
  82. package/esm/http/param-codec/date-codec.d.ts +16 -0
  83. package/esm/http/param-codec/date-codec.js +40 -0
  84. package/esm/http/param-codec/filter-codec.d.ts +6 -0
  85. package/esm/http/param-codec/filter-codec.js +14 -0
  86. package/esm/http/param-codec/integer-codec.d.ts +9 -0
  87. package/esm/http/param-codec/integer-codec.js +15 -0
  88. package/esm/http/param-codec/number-codec.d.ts +12 -0
  89. package/esm/http/param-codec/number-codec.js +22 -0
  90. package/esm/http/param-codec/string-codec.d.ts +14 -0
  91. package/esm/http/param-codec/string-codec.js +21 -0
  92. package/esm/http/utils/encodeURIParam.d.ts +1 -0
  93. package/esm/http/utils/encodeURIParam.js +17 -0
  94. package/esm/http/utils/normalize-headers.js +2 -2
  95. package/esm/i18n/i18n.d.ts +6 -6
  96. package/esm/i18n/i18n.js +1 -4
  97. package/esm/schema/decorators/opr-collection-resource.decorator.d.ts +1 -1
  98. package/esm/schema/decorators/opr-complex-type.decorator.d.ts +1 -1
  99. package/esm/schema/decorators/opr-simple-type.decorator.d.ts +1 -1
  100. package/esm/schema/decorators/opr-singleton-resource.decorator.d.ts +1 -1
  101. package/esm/schema/implementation/data-type/complex-type.d.ts +1 -1
  102. package/esm/schema/implementation/data-type/data-type.d.ts +1 -0
  103. package/esm/schema/implementation/data-type/data-type.js +4 -0
  104. package/esm/schema/implementation/data-type/union-type.d.ts +1 -1
  105. package/esm/schema/implementation/document-builder.d.ts +1 -1
  106. package/esm/schema/implementation/opra-document.d.ts +2 -2
  107. package/esm/schema/implementation/opra-document.js +12 -11
  108. package/esm/schema/implementation/query/collection-count-query.d.ts +1 -1
  109. package/esm/schema/implementation/query/collection-create-query.d.ts +1 -1
  110. package/esm/schema/implementation/query/collection-delete-many-query.d.ts +1 -1
  111. package/esm/schema/implementation/query/collection-get-query.d.ts +1 -1
  112. package/esm/schema/implementation/query/collection-search-query.d.ts +1 -1
  113. package/esm/schema/implementation/query/collection-update-many-query.d.ts +1 -1
  114. package/esm/schema/implementation/query/collection-update-query.d.ts +1 -1
  115. package/esm/schema/implementation/query/field-get-query.d.ts +1 -1
  116. package/esm/schema/implementation/query/index.d.ts +4 -4
  117. package/esm/schema/implementation/query/singleton-get-query.d.ts +1 -1
  118. package/esm/schema/implementation/resource/collection-resource-info.d.ts +3 -0
  119. package/esm/schema/implementation/resource/collection-resource-info.js +15 -0
  120. package/esm/schema/implementation/resource/singleton-resource-info.d.ts +1 -0
  121. package/esm/schema/implementation/resource/singleton-resource-info.js +8 -0
  122. package/esm/schema/interfaces/data-type.metadata.d.ts +4 -4
  123. package/esm/schema/interfaces/resource.metadata.d.ts +9 -9
  124. package/esm/schema/types.d.ts +8 -8
  125. package/esm/url/opra-url-path-component.d.ts +1 -1
  126. package/esm/url/opra-url-path.d.ts +24 -18
  127. package/esm/url/opra-url-path.js +96 -72
  128. package/esm/url/opra-url-search-params.d.ts +3 -42
  129. package/esm/url/opra-url-search-params.js +16 -234
  130. package/esm/url/opra-url.d.ts +38 -28
  131. package/esm/url/opra-url.js +201 -160
  132. package/package.json +11 -11
@@ -1,3 +1,4 @@
1
+ var _a;
1
2
  import { splitString, tokenize } from 'fast-tokenizer';
2
3
  import { OpraURLPath } from './opra-url-path.js';
3
4
  import { OpraURLSearchParams } from './opra-url-search-params.js';
@@ -7,166 +8,227 @@ const urlRegEx = /^(?:((?:[A-Z][A-Z+-.]+:)+)\/\/([^/?]+))?(.*)?$/i;
7
8
  const schemeRegEx = /^([A-Z][A-Z+-.]+:?)+$/i;
8
9
  const hostRegEx = /^([^/:]+)(?::(\d+))?$/;
9
10
  const hostnameRegEx = /^([^/:]+)$/;
10
- const CONTEXT_KEY = Symbol.for('opra.url.context');
11
- const PATH_KEY = Symbol.for('opra.url.path');
12
- const SEARCHPARAMS_KEY = Symbol.for('opra.url.searchparams');
11
+ const kContext = Symbol('kContext');
12
+ const kPath = Symbol('kPath');
13
+ const kSearchParams = Symbol('kSearchParams');
13
14
  export class OpraURL {
14
- constructor(input, pathPrefix) {
15
- Object.defineProperty(this, CONTEXT_KEY, {
16
- writable: true,
17
- configurable: true,
18
- enumerable: false,
19
- value: {}
20
- });
21
- Object.defineProperty(this, PATH_KEY, {
22
- writable: true,
23
- configurable: true,
24
- enumerable: false,
25
- value: new OpraURLPath()
15
+ constructor(input, arg1) {
16
+ this[_a] = {
17
+ protocol: '',
18
+ username: '',
19
+ pathname: '',
20
+ prefix: '',
21
+ hostname: '',
22
+ port: '',
23
+ hash: '',
24
+ password: '',
25
+ search: '',
26
+ address: '',
27
+ needUpdate: true
28
+ };
29
+ this[kPath] = new OpraURLPath('', {
30
+ onChange: () => this._changed()
26
31
  });
27
- Object.defineProperty(this, SEARCHPARAMS_KEY, {
28
- writable: true,
29
- configurable: true,
30
- enumerable: false,
31
- value: new OpraURLSearchParams()
32
+ this[kSearchParams] = new OpraURLSearchParams('', {
33
+ onChange: () => this._changed()
32
34
  });
33
- this.searchParams.on('change', () => this._invalidate());
34
- this.path.on('change', () => this._invalidate());
35
- if (pathPrefix)
36
- this.setPrefix(pathPrefix);
35
+ const base = typeof arg1 === 'object' ? arg1.base : arg1;
36
+ if (typeof arg1 === 'object') {
37
+ const defineParams = arg1?.params;
38
+ if (defineParams)
39
+ Object.keys(defineParams).forEach(key => this.searchParams.define(key, defineParams[key]));
40
+ }
37
41
  if (input)
38
- this.parse(input);
42
+ this.parse(typeof input === 'object' ? input.toString() : input);
43
+ if (base) {
44
+ const baseUrl = base instanceof OpraURL ? base : new OpraURL(base);
45
+ this[kContext].protocol = baseUrl.protocol;
46
+ this[kContext].hostname = baseUrl.hostname;
47
+ this[kContext].port = baseUrl.port;
48
+ this[kContext].prefix = baseUrl.pathname;
49
+ }
39
50
  }
40
51
  get address() {
41
52
  this._update();
42
- let out = '';
43
- if (this.hostname) {
44
- out += this.protocol + '//' +
45
- (this.username || this.password
46
- ? ((this.username ? encodeURIComponent(this.username) : '') +
47
- (this.password ? ':' + encodeURIComponent(this.password) : '') + '@')
48
- : '') + this.host;
49
- }
50
- return out + this.pathPrefix + this.pathname;
53
+ return this[kContext].address;
51
54
  }
52
- get href() {
53
- return this.address + this.search + this.hash;
55
+ get host() {
56
+ return this.hostname ? (this.hostname + (this.port ? ':' + this.port : '')) : '';
54
57
  }
55
- get protocol() {
56
- return this[CONTEXT_KEY].protocol || 'http:';
58
+ set host(v) {
59
+ if (v) {
60
+ const m = hostRegEx.exec(v);
61
+ if (!m)
62
+ throw Object.assign(new TypeError('Invalid host'), {
63
+ host: v,
64
+ code: 'ERR_INVALID_URL'
65
+ });
66
+ this[kContext].hostname = m[1];
67
+ this[kContext].port = m[2] || '';
68
+ }
69
+ else {
70
+ this[kContext].hostname = '';
71
+ this[kContext].port = '';
72
+ }
73
+ this._changed();
57
74
  }
58
- set protocol(v) {
59
- if (!schemeRegEx.test(v))
60
- throw Object.assign(new TypeError('Invalid protocol'), {
61
- protocol: v,
62
- code: 'ERR_INVALID_URL'
63
- });
64
- this[CONTEXT_KEY].protocol = v + (v.endsWith(':') ? '' : ':');
75
+ get hostname() {
76
+ return this[kContext].hostname || '';
65
77
  }
66
- get username() {
67
- return this[CONTEXT_KEY].username || '';
78
+ set hostname(v) {
79
+ if (v) {
80
+ if (!hostnameRegEx.test(v))
81
+ throw Object.assign(new TypeError('Invalid hostname'), {
82
+ hostname: v,
83
+ code: 'ERR_INVALID_URL'
84
+ });
85
+ this[kContext].hostname = v;
86
+ }
87
+ else
88
+ this[kContext].hostname = '';
89
+ this._changed();
68
90
  }
69
- set username(v) {
70
- this[CONTEXT_KEY].username = v;
91
+ get href() {
92
+ return this.address + this.search + this.hash;
71
93
  }
72
94
  get password() {
73
- return this[CONTEXT_KEY].password || '';
95
+ return this[kContext].password;
74
96
  }
75
97
  set password(v) {
76
- this[CONTEXT_KEY].password = v;
98
+ this[kContext].password = v || '';
99
+ this._changed();
77
100
  }
78
- get host() {
79
- return this.hostname ? (this.hostname + (this.port ? ':' + this.port : '')) : '';
80
- }
81
- set host(v) {
82
- const m = hostRegEx.exec(v);
83
- if (!m)
84
- throw Object.assign(new TypeError('Invalid host'), {
85
- host: v,
86
- code: 'ERR_INVALID_URL'
87
- });
88
- this[CONTEXT_KEY].hostname = m[1];
89
- this[CONTEXT_KEY].port = m[2] ? parseInt(m[2], 10) : null;
101
+ get port() {
102
+ return this[kContext].port;
103
+ }
104
+ set port(value) {
105
+ if (value) {
106
+ // noinspection SuspiciousTypeOfGuard
107
+ const v = parseInt(value, 10);
108
+ if (isNaN(v) || v < 1 || v > 35535 || v % 1 > 0)
109
+ throw Object.assign(new TypeError('Invalid port'), {
110
+ hostname: v,
111
+ code: 'ERR_INVALID_URL'
112
+ });
113
+ this[kContext].port = value;
114
+ }
115
+ else
116
+ this[kContext].port = '';
117
+ this._changed();
90
118
  }
91
- get hostname() {
92
- return this[CONTEXT_KEY].hostname || '';
119
+ get prefix() {
120
+ return this[kContext].prefix;
93
121
  }
94
- set hostname(v) {
95
- if (!hostnameRegEx.test(v))
96
- throw Object.assign(new TypeError('Invalid hostname'), {
97
- hostname: v,
98
- code: 'ERR_INVALID_URL'
99
- });
100
- this[CONTEXT_KEY].hostname = v;
122
+ set prefix(value) {
123
+ if (value) {
124
+ const url = new OpraURL(value);
125
+ this[kContext].prefix = url.pathname;
126
+ }
127
+ else
128
+ this[kContext].prefix = '';
129
+ this._changed();
101
130
  }
102
- get port() {
103
- const v = this[CONTEXT_KEY].port;
104
- return v == null ? null : v;
131
+ get protocol() {
132
+ return this[kContext].protocol || 'http:';
105
133
  }
106
- set port(v) {
107
- if (v == null) {
108
- this[CONTEXT_KEY].port = null;
109
- return;
134
+ set protocol(v) {
135
+ if (v) {
136
+ if (!schemeRegEx.test(v))
137
+ throw Object.assign(new TypeError('Invalid protocol'), {
138
+ protocol: v,
139
+ code: 'ERR_INVALID_URL'
140
+ });
141
+ this[kContext].protocol = v + (v.endsWith(':') ? '' : ':');
110
142
  }
111
- // noinspection SuspiciousTypeOfGuard
112
- if (typeof v !== 'number' || isNaN(v) || v < 1 || v > 35535 || v % 1 > 0)
113
- throw Object.assign(new TypeError('Invalid port'), {
114
- hostname: v,
115
- code: 'ERR_INVALID_URL'
116
- });
117
- this[CONTEXT_KEY].port = v;
143
+ else
144
+ this[kContext].protocol = '';
145
+ this._changed();
118
146
  }
119
- get origin() {
120
- return this.hostname ? (this.protocol + '//' + this.hostname) : '';
147
+ get username() {
148
+ return this[kContext].username;
121
149
  }
122
- get pathPrefix() {
123
- return this[CONTEXT_KEY].pathPrefix || '';
150
+ set username(v) {
151
+ this[kContext].username = v || '';
152
+ this._changed();
124
153
  }
125
- set pathPrefix(v) {
126
- if (!v) {
127
- this[CONTEXT_KEY].pathPrefix = '';
128
- return;
129
- }
130
- v = normalizePath(tokenize(v, { delimiters: '#?', quotes: true, brackets: true }).next() || '', true);
131
- if (v.includes('://'))
132
- this[CONTEXT_KEY].pathPrefix = v;
133
- else
134
- this[CONTEXT_KEY].pathPrefix = v ? '/' + v : '';
154
+ get origin() {
155
+ return this.hostname ? (this.protocol + '//' + this.hostname) : '';
135
156
  }
136
157
  get path() {
137
- return this[PATH_KEY];
158
+ return this[kPath];
138
159
  }
139
160
  get pathname() {
140
161
  this._update();
141
- return this[CONTEXT_KEY].pathname || '';
162
+ return this[kContext].pathname || '';
142
163
  }
143
164
  set pathname(v) {
144
165
  this._setPathname(v, false);
145
166
  }
146
167
  get searchParams() {
147
- return this[SEARCHPARAMS_KEY];
168
+ return this[kSearchParams];
148
169
  }
149
170
  get hash() {
150
- return this[CONTEXT_KEY].hash || '';
171
+ return this[kContext].hash || '';
151
172
  }
152
173
  set hash(v) {
153
- this[CONTEXT_KEY].hash = v ? (v.startsWith('#') ? v : '#' + v) : '';
174
+ this[kContext].hash = v ? (v.startsWith('#') ? v : '#' + v) : '';
175
+ this._changed();
154
176
  }
155
177
  get search() {
156
178
  this._update();
157
- return this[CONTEXT_KEY].search || '';
179
+ return this[kContext].search || '';
158
180
  }
159
181
  set search(v) {
160
- this.searchParams.parse(v);
182
+ this.searchParams.clear();
183
+ this.searchParams.appendAll(v);
184
+ }
185
+ parse(input) {
186
+ const m = urlRegEx.exec(input);
187
+ if (!m)
188
+ throw Object.assign(new TypeError('Invalid URL'), {
189
+ input,
190
+ code: 'ERR_INVALID_URL'
191
+ });
192
+ this.protocol = m[1];
193
+ const isAbsolute = !!m[2];
194
+ if (isAbsolute) {
195
+ let tokens = splitString(m[2], { delimiters: '@' });
196
+ if (tokens.length > 1) {
197
+ this.host = tokens[1];
198
+ tokens = splitString(tokens[0], { delimiters: ':' });
199
+ this.username = tokens[0] ? decodeURIComponent(tokens[0]) : '';
200
+ this.password = tokens[1] ? decodeURIComponent(tokens[1]) : '';
201
+ }
202
+ else
203
+ this.host = tokens[0];
204
+ }
205
+ else {
206
+ this.host = '';
207
+ this.username = '';
208
+ this.password = '';
209
+ }
210
+ input = m[3] || '';
211
+ let tokenizer = tokenize(input, { delimiters: '#', quotes: true, brackets: true });
212
+ input = tokenizer.next() || '';
213
+ this.hash = tokenizer.join('#');
214
+ tokenizer = tokenize(input, { delimiters: '?', quotes: true, brackets: true });
215
+ this._setPathname(tokenizer.next() || '', isAbsolute);
216
+ this.searchParams.clear();
217
+ this.searchParams.appendAll(tokenizer.join('&'));
218
+ this._changed();
161
219
  }
162
- addPath(name, key) {
163
- this.path.add(name, key);
220
+ join(...source) {
221
+ this.path.join(...source);
164
222
  return this;
165
223
  }
166
- addSearchParam(name, value) {
224
+ addParam(name, value) {
167
225
  this.searchParams.append(name, value);
168
226
  return this;
169
227
  }
228
+ setParam(name, value) {
229
+ this.searchParams.set(name, value);
230
+ return this;
231
+ }
170
232
  setHost(v) {
171
233
  this.host = v;
172
234
  return this;
@@ -180,11 +242,11 @@ export class OpraURL {
180
242
  return this;
181
243
  }
182
244
  setPort(v) {
183
- this.port = v;
245
+ this.port = v ? String(v) : '';
184
246
  return this;
185
247
  }
186
248
  setPrefix(v) {
187
- this.pathPrefix = v;
249
+ this.prefix = v;
188
250
  return this;
189
251
  }
190
252
  setPathname(v) {
@@ -199,46 +261,11 @@ export class OpraURL {
199
261
  this.search = v;
200
262
  return this;
201
263
  }
202
- setSearchParam(name, value) {
203
- this.searchParams.set(name, value);
204
- return this;
205
- }
206
- parse(input) {
207
- const m = urlRegEx.exec(input);
208
- if (!m)
209
- throw Object.assign(new TypeError('Invalid URL'), {
210
- input,
211
- code: 'ERR_INVALID_URL'
212
- });
213
- if (m[1])
214
- this.protocol = m[1];
215
- if (m[2]) {
216
- let tokens = splitString(m[2], { delimiters: '@' });
217
- if (tokens.length > 1) {
218
- this.host = tokens[1];
219
- tokens = splitString(tokens[0], { delimiters: ':' });
220
- this.username = tokens[0] ? decodeURIComponent(tokens[0]) : '';
221
- this.password = tokens[1] ? decodeURIComponent(tokens[1]) : '';
222
- }
223
- else
224
- this.host = tokens[0];
225
- }
226
- input = m[3] || '';
227
- let tokenizer = tokenize(input, { delimiters: '#', quotes: true, brackets: true });
228
- input = tokenizer.next() || '';
229
- this.hash = tokenizer.join('#');
230
- tokenizer = tokenize(input, { delimiters: '?', quotes: true, brackets: true });
231
- this._setPathname(tokenizer.next() || '', true);
232
- // this.path.join()
233
- this.searchParams.clear();
234
- this.searchParams.parse(tokenizer.join('&'));
235
- return this;
236
- }
237
264
  toString() {
238
265
  return this.href;
239
266
  }
240
267
  /* istanbul ignore next */
241
- [nodeInspectCustom]() {
268
+ [(_a = kContext, nodeInspectCustom)]() {
242
269
  this._update();
243
270
  return {
244
271
  protocol: this.protocol,
@@ -247,7 +274,7 @@ export class OpraURL {
247
274
  host: this.host,
248
275
  hostname: this.hostname,
249
276
  origin: this.origin,
250
- pathPrefix: this.pathPrefix,
277
+ pathPrefix: this.prefix,
251
278
  path: this.path,
252
279
  pathname: this.pathname,
253
280
  search: this.search,
@@ -255,27 +282,34 @@ export class OpraURL {
255
282
  hash: this.hash,
256
283
  };
257
284
  }
258
- _invalidate() {
259
- this[CONTEXT_KEY].needUpdate = true;
260
- }
261
285
  _update() {
262
- if (!this[CONTEXT_KEY].needUpdate)
286
+ if (!this[kContext].needUpdate)
263
287
  return;
264
- this[CONTEXT_KEY].needUpdate = false;
288
+ const ctx = this[kContext];
289
+ ctx.needUpdate = false;
265
290
  let s = this.path.toString();
266
- this[CONTEXT_KEY].pathname = s ? '/' + s : '';
291
+ ctx.pathname = s ? '/' + s : '';
267
292
  s = this.searchParams.toString();
268
- this[CONTEXT_KEY].search = s ? '?' + s : '';
293
+ ctx.search = s ? '?' + s : '';
294
+ let address = '';
295
+ if (ctx.hostname) {
296
+ address += (ctx.protocol || 'http:') + '//' +
297
+ (ctx.username || ctx.password
298
+ ? ((ctx.username ? encodeURIComponent(ctx.username) : '') +
299
+ (ctx.password ? ':' + encodeURIComponent(ctx.password) : '') + '@')
300
+ : '') + this.host;
301
+ }
302
+ ctx.address = address + ctx.prefix + ctx.pathname;
269
303
  }
270
- _setPathname(v, inclSvcRoot) {
304
+ _setPathname(v, trimPrefix) {
271
305
  this.path.clear();
272
306
  if (!v)
273
307
  return;
274
308
  const pathTokenizer = tokenize(normalizePath(v, true), {
275
309
  delimiters: '/', quotes: true, brackets: true,
276
310
  });
277
- if (inclSvcRoot && this.pathPrefix) {
278
- const prefixTokenizer = tokenize(normalizePath(this.pathPrefix, true), {
311
+ if (trimPrefix && this.prefix) {
312
+ const prefixTokenizer = tokenize(normalizePath(this.prefix, true), {
279
313
  delimiters: '/', quotes: true, brackets: true,
280
314
  });
281
315
  for (const a of prefixTokenizer) {
@@ -286,7 +320,14 @@ export class OpraURL {
286
320
  }
287
321
  for (const x of pathTokenizer) {
288
322
  const p = decodePathComponent(x);
289
- this.path.add(p);
323
+ this.path.join(p);
290
324
  }
325
+ this._changed();
326
+ }
327
+ _changed() {
328
+ this[kContext].needUpdate = true;
291
329
  }
292
330
  }
331
+ OpraURL.kContext = kContext;
332
+ OpraURL.kPath = kPath;
333
+ OpraURL.kSearchParams = kSearchParams;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/common",
3
- "version": "0.10.3",
3
+ "version": "0.13.0",
4
4
  "description": "Opra internationalization package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -18,25 +18,25 @@
18
18
  "postbuild": "cp package.json ../../LICENSE ../../build/common && cp ../../package.cjs.json ../../build/common/cjs/package.json",
19
19
  "lint": "eslint . --max-warnings=0",
20
20
  "check": "madge --circular src/**",
21
- "test": "jest --runInBand --detectOpenHandles",
22
- "cover": "jest --collect-coverage",
21
+ "test": "NODE_OPTIONS=--experimental-vm-modules npx jest",
22
+ "cover": "NODE_OPTIONS=--experimental-vm-modules npx jest --collect-coverage",
23
23
  "clean": "npm run clean:src && npm run clean:dist && npm run clean:cover",
24
- "clean:src": "ts-cleanup -s src --all",
24
+ "clean:src": "ts-cleanup -s src --all && ts-cleanup -s test --all",
25
25
  "clean:dist": "rimraf ../../build/common",
26
26
  "clean:cover": "rimraf ../../coverage/common",
27
27
  "antlr4": "java -jar ./tools/antlr4-4.11.2-SNAPSHOT-complete.jar -Dlanguage=TypeScript ./src/filter/antlr/OpraFilter.g4 -visitor"
28
28
  },
29
29
  "dependencies": {
30
- "antlr4": "^4.12.0-beta.3",
31
- "fast-tokenizer": "^1.2.0",
30
+ "@browsery/antlr4": "^0.2.0",
31
+ "fast-tokenizer": "^1.2.1",
32
32
  "highland": "^2.13.5",
33
33
  "http-parser-js": "^0.5.8",
34
- "i18next": "^22.4.6",
34
+ "i18next": "^22.4.9",
35
35
  "lodash.omit": "^4.5.0",
36
- "putil-isplainobject": "^1.1.4",
37
- "putil-merge": "^3.9.0",
36
+ "putil-isplainobject": "^1.1.5",
37
+ "putil-merge": "^3.10.1",
38
38
  "putil-promisify": "^1.10.0",
39
- "putil-varhelpers": "^1.6.4",
39
+ "putil-varhelpers": "^1.6.5",
40
40
  "reflect-metadata": "^0.1.13",
41
41
  "uid": "^2.0.1"
42
42
  },
@@ -67,4 +67,4 @@
67
67
  "opra",
68
68
  "common"
69
69
  ]
70
- }
70
+ }