@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.
- package/cjs/filter/antlr/OpraFilterLexer.js +1 -1
- package/cjs/filter/antlr/OpraFilterListener.js +1 -1
- package/cjs/filter/antlr/OpraFilterParser.js +5 -5
- package/cjs/filter/antlr/OpraFilterVisitor.js +1 -1
- package/cjs/filter/filter-tree-visitor.js +8 -2
- package/cjs/filter/opra-error-listener.js +2 -2
- package/cjs/filter/parse.js +1 -1
- package/cjs/helpers/responsive-map.js +45 -28
- package/{esm/http/enums/http-headers.enum.js → cjs/http/enums/http-headers-codes.enum.js} +95 -92
- package/{esm/http/enums/http-status.enum.js → cjs/http/enums/http-status-codes.enum.js} +62 -59
- package/cjs/http/http-headers.js +213 -0
- package/cjs/http/http-param-codec.js +6 -0
- package/cjs/http/http-params.js +321 -0
- package/cjs/http/http-request-node.js +105 -0
- package/cjs/http/http-request.js +73 -88
- package/cjs/http/http-response.js +23 -0
- package/cjs/http/index.js +13 -2
- package/cjs/http/multipart/batch-multipart.js +12 -12
- package/cjs/http/param-codec/boolean-codec.js +25 -0
- package/cjs/http/param-codec/date-codec.js +44 -0
- package/cjs/http/param-codec/filter-codec.js +18 -0
- package/cjs/http/param-codec/integer-codec.js +19 -0
- package/cjs/http/param-codec/number-codec.js +26 -0
- package/cjs/http/param-codec/string-codec.js +25 -0
- package/cjs/http/utils/encodeURIParam.js +21 -0
- package/cjs/http/utils/normalize-headers.js +2 -2
- package/cjs/i18n/i18n.js +1 -4
- package/cjs/schema/implementation/data-type/data-type.js +4 -0
- package/cjs/schema/implementation/opra-document.js +12 -11
- package/cjs/schema/implementation/resource/collection-resource-info.js +15 -0
- package/cjs/schema/implementation/resource/singleton-resource-info.js +8 -0
- package/cjs/url/opra-url-path.js +96 -72
- package/cjs/url/opra-url-search-params.js +16 -234
- package/cjs/url/opra-url.js +201 -160
- package/esm/filter/antlr/OpraFilterLexer.d.ts +1 -1
- package/esm/filter/antlr/OpraFilterLexer.js +1 -1
- package/esm/filter/antlr/OpraFilterListener.d.ts +1 -1
- package/esm/filter/antlr/OpraFilterListener.js +1 -1
- package/esm/filter/antlr/OpraFilterParser.d.ts +1 -1
- package/esm/filter/antlr/OpraFilterParser.js +5 -5
- package/esm/filter/antlr/OpraFilterVisitor.d.ts +1 -1
- package/esm/filter/antlr/OpraFilterVisitor.js +1 -1
- package/esm/filter/ast/expressions/arithmetic-expression.d.ts +1 -1
- package/esm/filter/ast/expressions/comparison-expression.d.ts +1 -1
- package/esm/filter/ast/expressions/logical-expression.d.ts +1 -1
- package/esm/filter/build.d.ts +3 -3
- package/esm/filter/errors.d.ts +4 -2
- package/esm/filter/filter-tree-visitor.d.ts +2 -1
- package/esm/filter/filter-tree-visitor.js +8 -2
- package/esm/filter/opra-error-listener.d.ts +2 -2
- package/esm/filter/opra-error-listener.js +2 -2
- package/esm/filter/parse.d.ts +1 -1
- package/esm/filter/parse.js +1 -1
- package/esm/helpers/responsive-map.d.ts +19 -5
- package/esm/helpers/responsive-map.js +45 -28
- package/esm/http/enums/{http-headers.enum.d.ts → http-headers-codes.enum.d.ts} +1 -1
- package/{cjs/http/enums/http-headers.enum.js → esm/http/enums/http-headers-codes.enum.js} +92 -95
- package/esm/http/enums/{http-status.enum.d.ts → http-status-codes.enum.d.ts} +1 -1
- package/{cjs/http/enums/http-status.enum.js → esm/http/enums/http-status-codes.enum.js} +59 -62
- package/esm/http/http-headers.d.ts +70 -0
- package/esm/http/http-headers.js +209 -0
- package/esm/http/http-param-codec.d.ts +4 -0
- package/esm/http/http-param-codec.js +2 -0
- package/esm/http/http-params.d.ts +99 -0
- package/esm/http/http-params.js +317 -0
- package/esm/http/http-request-node.d.ts +34 -0
- package/esm/http/http-request-node.js +101 -0
- package/esm/http/http-request.d.ts +73 -31
- package/esm/http/http-request.js +72 -87
- package/esm/http/http-response.d.ts +41 -0
- package/esm/http/http-response.js +19 -0
- package/esm/http/index.d.ts +13 -2
- package/esm/http/index.js +13 -2
- package/esm/http/interfaces/client-http-headers.interface.d.ts +1 -1
- package/esm/http/interfaces/server-http-headers.interface.d.ts +1 -1
- package/esm/http/multipart/batch-multipart.d.ts +1 -1
- package/esm/http/multipart/batch-multipart.js +12 -12
- package/esm/http/multipart/http-request-content.d.ts +1 -1
- package/esm/http/multipart/http-response-content.d.ts +1 -1
- package/esm/http/param-codec/boolean-codec.d.ts +5 -0
- package/esm/http/param-codec/boolean-codec.js +21 -0
- package/esm/http/param-codec/date-codec.d.ts +16 -0
- package/esm/http/param-codec/date-codec.js +40 -0
- package/esm/http/param-codec/filter-codec.d.ts +6 -0
- package/esm/http/param-codec/filter-codec.js +14 -0
- package/esm/http/param-codec/integer-codec.d.ts +9 -0
- package/esm/http/param-codec/integer-codec.js +15 -0
- package/esm/http/param-codec/number-codec.d.ts +12 -0
- package/esm/http/param-codec/number-codec.js +22 -0
- package/esm/http/param-codec/string-codec.d.ts +14 -0
- package/esm/http/param-codec/string-codec.js +21 -0
- package/esm/http/utils/encodeURIParam.d.ts +1 -0
- package/esm/http/utils/encodeURIParam.js +17 -0
- package/esm/http/utils/normalize-headers.js +2 -2
- package/esm/i18n/i18n.d.ts +6 -6
- package/esm/i18n/i18n.js +1 -4
- package/esm/schema/decorators/opr-collection-resource.decorator.d.ts +1 -1
- package/esm/schema/decorators/opr-complex-type.decorator.d.ts +1 -1
- package/esm/schema/decorators/opr-simple-type.decorator.d.ts +1 -1
- package/esm/schema/decorators/opr-singleton-resource.decorator.d.ts +1 -1
- package/esm/schema/implementation/data-type/complex-type.d.ts +1 -1
- package/esm/schema/implementation/data-type/data-type.d.ts +1 -0
- package/esm/schema/implementation/data-type/data-type.js +4 -0
- package/esm/schema/implementation/data-type/union-type.d.ts +1 -1
- package/esm/schema/implementation/document-builder.d.ts +1 -1
- package/esm/schema/implementation/opra-document.d.ts +2 -2
- package/esm/schema/implementation/opra-document.js +12 -11
- package/esm/schema/implementation/query/collection-count-query.d.ts +1 -1
- package/esm/schema/implementation/query/collection-create-query.d.ts +1 -1
- package/esm/schema/implementation/query/collection-delete-many-query.d.ts +1 -1
- package/esm/schema/implementation/query/collection-get-query.d.ts +1 -1
- package/esm/schema/implementation/query/collection-search-query.d.ts +1 -1
- package/esm/schema/implementation/query/collection-update-many-query.d.ts +1 -1
- package/esm/schema/implementation/query/collection-update-query.d.ts +1 -1
- package/esm/schema/implementation/query/field-get-query.d.ts +1 -1
- package/esm/schema/implementation/query/index.d.ts +4 -4
- package/esm/schema/implementation/query/singleton-get-query.d.ts +1 -1
- package/esm/schema/implementation/resource/collection-resource-info.d.ts +3 -0
- package/esm/schema/implementation/resource/collection-resource-info.js +15 -0
- package/esm/schema/implementation/resource/singleton-resource-info.d.ts +1 -0
- package/esm/schema/implementation/resource/singleton-resource-info.js +8 -0
- package/esm/schema/interfaces/data-type.metadata.d.ts +4 -4
- package/esm/schema/interfaces/resource.metadata.d.ts +9 -9
- package/esm/schema/types.d.ts +8 -8
- package/esm/url/opra-url-path-component.d.ts +1 -1
- package/esm/url/opra-url-path.d.ts +24 -18
- package/esm/url/opra-url-path.js +96 -72
- package/esm/url/opra-url-search-params.d.ts +3 -42
- package/esm/url/opra-url-search-params.js +16 -234
- package/esm/url/opra-url.d.ts +38 -28
- package/esm/url/opra-url.js +201 -160
- package/package.json +11 -11
package/esm/url/opra-url.js
CHANGED
|
@@ -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
|
|
11
|
-
const
|
|
12
|
-
const
|
|
11
|
+
const kContext = Symbol('kContext');
|
|
12
|
+
const kPath = Symbol('kPath');
|
|
13
|
+
const kSearchParams = Symbol('kSearchParams');
|
|
13
14
|
export class OpraURL {
|
|
14
|
-
constructor(input,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
configurable: true,
|
|
30
|
-
enumerable: false,
|
|
31
|
-
value: new OpraURLSearchParams()
|
|
32
|
+
this[kSearchParams] = new OpraURLSearchParams('', {
|
|
33
|
+
onChange: () => this._changed()
|
|
32
34
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
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
|
|
53
|
-
return this.
|
|
55
|
+
get host() {
|
|
56
|
+
return this.hostname ? (this.hostname + (this.port ? ':' + this.port : '')) : '';
|
|
54
57
|
}
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
59
|
-
|
|
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
|
-
|
|
67
|
-
|
|
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
|
-
|
|
70
|
-
this
|
|
91
|
+
get href() {
|
|
92
|
+
return this.address + this.search + this.hash;
|
|
71
93
|
}
|
|
72
94
|
get password() {
|
|
73
|
-
return this[
|
|
95
|
+
return this[kContext].password;
|
|
74
96
|
}
|
|
75
97
|
set password(v) {
|
|
76
|
-
this[
|
|
98
|
+
this[kContext].password = v || '';
|
|
99
|
+
this._changed();
|
|
77
100
|
}
|
|
78
|
-
get
|
|
79
|
-
return this.
|
|
80
|
-
}
|
|
81
|
-
set
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
|
92
|
-
return this[
|
|
119
|
+
get prefix() {
|
|
120
|
+
return this[kContext].prefix;
|
|
93
121
|
}
|
|
94
|
-
set
|
|
95
|
-
if (
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
|
103
|
-
|
|
104
|
-
return v == null ? null : v;
|
|
131
|
+
get protocol() {
|
|
132
|
+
return this[kContext].protocol || 'http:';
|
|
105
133
|
}
|
|
106
|
-
set
|
|
107
|
-
if (v
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
|
120
|
-
return this.
|
|
147
|
+
get username() {
|
|
148
|
+
return this[kContext].username;
|
|
121
149
|
}
|
|
122
|
-
|
|
123
|
-
|
|
150
|
+
set username(v) {
|
|
151
|
+
this[kContext].username = v || '';
|
|
152
|
+
this._changed();
|
|
124
153
|
}
|
|
125
|
-
|
|
126
|
-
|
|
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[
|
|
158
|
+
return this[kPath];
|
|
138
159
|
}
|
|
139
160
|
get pathname() {
|
|
140
161
|
this._update();
|
|
141
|
-
return this[
|
|
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[
|
|
168
|
+
return this[kSearchParams];
|
|
148
169
|
}
|
|
149
170
|
get hash() {
|
|
150
|
-
return this[
|
|
171
|
+
return this[kContext].hash || '';
|
|
151
172
|
}
|
|
152
173
|
set hash(v) {
|
|
153
|
-
this[
|
|
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[
|
|
179
|
+
return this[kContext].search || '';
|
|
158
180
|
}
|
|
159
181
|
set search(v) {
|
|
160
|
-
this.searchParams.
|
|
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
|
-
|
|
163
|
-
this.path.
|
|
220
|
+
join(...source) {
|
|
221
|
+
this.path.join(...source);
|
|
164
222
|
return this;
|
|
165
223
|
}
|
|
166
|
-
|
|
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.
|
|
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.
|
|
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[
|
|
286
|
+
if (!this[kContext].needUpdate)
|
|
263
287
|
return;
|
|
264
|
-
this[
|
|
288
|
+
const ctx = this[kContext];
|
|
289
|
+
ctx.needUpdate = false;
|
|
265
290
|
let s = this.path.toString();
|
|
266
|
-
|
|
291
|
+
ctx.pathname = s ? '/' + s : '';
|
|
267
292
|
s = this.searchParams.toString();
|
|
268
|
-
|
|
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,
|
|
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 (
|
|
278
|
-
const prefixTokenizer = tokenize(normalizePath(this.
|
|
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.
|
|
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.
|
|
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": "
|
|
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": "^
|
|
31
|
-
"fast-tokenizer": "^1.2.
|
|
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.
|
|
34
|
+
"i18next": "^22.4.9",
|
|
35
35
|
"lodash.omit": "^4.5.0",
|
|
36
|
-
"putil-isplainobject": "^1.1.
|
|
37
|
-
"putil-merge": "^3.
|
|
36
|
+
"putil-isplainobject": "^1.1.5",
|
|
37
|
+
"putil-merge": "^3.10.1",
|
|
38
38
|
"putil-promisify": "^1.10.0",
|
|
39
|
-
"putil-varhelpers": "^1.6.
|
|
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
|
+
}
|