@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/cjs/url/opra-url.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _a;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.OpraURL = void 0;
|
|
4
5
|
const fast_tokenizer_1 = require("fast-tokenizer");
|
|
@@ -10,166 +11,227 @@ const urlRegEx = /^(?:((?:[A-Z][A-Z+-.]+:)+)\/\/([^/?]+))?(.*)?$/i;
|
|
|
10
11
|
const schemeRegEx = /^([A-Z][A-Z+-.]+:?)+$/i;
|
|
11
12
|
const hostRegEx = /^([^/:]+)(?::(\d+))?$/;
|
|
12
13
|
const hostnameRegEx = /^([^/:]+)$/;
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
14
|
+
const kContext = Symbol('kContext');
|
|
15
|
+
const kPath = Symbol('kPath');
|
|
16
|
+
const kSearchParams = Symbol('kSearchParams');
|
|
16
17
|
class OpraURL {
|
|
17
|
-
constructor(input,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
18
|
+
constructor(input, arg1) {
|
|
19
|
+
this[_a] = {
|
|
20
|
+
protocol: '',
|
|
21
|
+
username: '',
|
|
22
|
+
pathname: '',
|
|
23
|
+
prefix: '',
|
|
24
|
+
hostname: '',
|
|
25
|
+
port: '',
|
|
26
|
+
hash: '',
|
|
27
|
+
password: '',
|
|
28
|
+
search: '',
|
|
29
|
+
address: '',
|
|
30
|
+
needUpdate: true
|
|
31
|
+
};
|
|
32
|
+
this[kPath] = new opra_url_path_js_1.OpraURLPath('', {
|
|
33
|
+
onChange: () => this._changed()
|
|
29
34
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
configurable: true,
|
|
33
|
-
enumerable: false,
|
|
34
|
-
value: new opra_url_search_params_js_1.OpraURLSearchParams()
|
|
35
|
+
this[kSearchParams] = new opra_url_search_params_js_1.OpraURLSearchParams('', {
|
|
36
|
+
onChange: () => this._changed()
|
|
35
37
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
const base = typeof arg1 === 'object' ? arg1.base : arg1;
|
|
39
|
+
if (typeof arg1 === 'object') {
|
|
40
|
+
const defineParams = arg1?.params;
|
|
41
|
+
if (defineParams)
|
|
42
|
+
Object.keys(defineParams).forEach(key => this.searchParams.define(key, defineParams[key]));
|
|
43
|
+
}
|
|
40
44
|
if (input)
|
|
41
|
-
this.parse(input);
|
|
45
|
+
this.parse(typeof input === 'object' ? input.toString() : input);
|
|
46
|
+
if (base) {
|
|
47
|
+
const baseUrl = base instanceof OpraURL ? base : new OpraURL(base);
|
|
48
|
+
this[kContext].protocol = baseUrl.protocol;
|
|
49
|
+
this[kContext].hostname = baseUrl.hostname;
|
|
50
|
+
this[kContext].port = baseUrl.port;
|
|
51
|
+
this[kContext].prefix = baseUrl.pathname;
|
|
52
|
+
}
|
|
42
53
|
}
|
|
43
54
|
get address() {
|
|
44
55
|
this._update();
|
|
45
|
-
|
|
46
|
-
if (this.hostname) {
|
|
47
|
-
out += this.protocol + '//' +
|
|
48
|
-
(this.username || this.password
|
|
49
|
-
? ((this.username ? encodeURIComponent(this.username) : '') +
|
|
50
|
-
(this.password ? ':' + encodeURIComponent(this.password) : '') + '@')
|
|
51
|
-
: '') + this.host;
|
|
52
|
-
}
|
|
53
|
-
return out + this.pathPrefix + this.pathname;
|
|
56
|
+
return this[kContext].address;
|
|
54
57
|
}
|
|
55
|
-
get
|
|
56
|
-
return this.
|
|
58
|
+
get host() {
|
|
59
|
+
return this.hostname ? (this.hostname + (this.port ? ':' + this.port : '')) : '';
|
|
57
60
|
}
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
set host(v) {
|
|
62
|
+
if (v) {
|
|
63
|
+
const m = hostRegEx.exec(v);
|
|
64
|
+
if (!m)
|
|
65
|
+
throw Object.assign(new TypeError('Invalid host'), {
|
|
66
|
+
host: v,
|
|
67
|
+
code: 'ERR_INVALID_URL'
|
|
68
|
+
});
|
|
69
|
+
this[kContext].hostname = m[1];
|
|
70
|
+
this[kContext].port = m[2] || '';
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
this[kContext].hostname = '';
|
|
74
|
+
this[kContext].port = '';
|
|
75
|
+
}
|
|
76
|
+
this._changed();
|
|
60
77
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
throw Object.assign(new TypeError('Invalid protocol'), {
|
|
64
|
-
protocol: v,
|
|
65
|
-
code: 'ERR_INVALID_URL'
|
|
66
|
-
});
|
|
67
|
-
this[CONTEXT_KEY].protocol = v + (v.endsWith(':') ? '' : ':');
|
|
78
|
+
get hostname() {
|
|
79
|
+
return this[kContext].hostname || '';
|
|
68
80
|
}
|
|
69
|
-
|
|
70
|
-
|
|
81
|
+
set hostname(v) {
|
|
82
|
+
if (v) {
|
|
83
|
+
if (!hostnameRegEx.test(v))
|
|
84
|
+
throw Object.assign(new TypeError('Invalid hostname'), {
|
|
85
|
+
hostname: v,
|
|
86
|
+
code: 'ERR_INVALID_URL'
|
|
87
|
+
});
|
|
88
|
+
this[kContext].hostname = v;
|
|
89
|
+
}
|
|
90
|
+
else
|
|
91
|
+
this[kContext].hostname = '';
|
|
92
|
+
this._changed();
|
|
71
93
|
}
|
|
72
|
-
|
|
73
|
-
this
|
|
94
|
+
get href() {
|
|
95
|
+
return this.address + this.search + this.hash;
|
|
74
96
|
}
|
|
75
97
|
get password() {
|
|
76
|
-
return this[
|
|
98
|
+
return this[kContext].password;
|
|
77
99
|
}
|
|
78
100
|
set password(v) {
|
|
79
|
-
this[
|
|
101
|
+
this[kContext].password = v || '';
|
|
102
|
+
this._changed();
|
|
80
103
|
}
|
|
81
|
-
get
|
|
82
|
-
return this.
|
|
83
|
-
}
|
|
84
|
-
set
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
104
|
+
get port() {
|
|
105
|
+
return this[kContext].port;
|
|
106
|
+
}
|
|
107
|
+
set port(value) {
|
|
108
|
+
if (value) {
|
|
109
|
+
// noinspection SuspiciousTypeOfGuard
|
|
110
|
+
const v = parseInt(value, 10);
|
|
111
|
+
if (isNaN(v) || v < 1 || v > 35535 || v % 1 > 0)
|
|
112
|
+
throw Object.assign(new TypeError('Invalid port'), {
|
|
113
|
+
hostname: v,
|
|
114
|
+
code: 'ERR_INVALID_URL'
|
|
115
|
+
});
|
|
116
|
+
this[kContext].port = value;
|
|
117
|
+
}
|
|
118
|
+
else
|
|
119
|
+
this[kContext].port = '';
|
|
120
|
+
this._changed();
|
|
93
121
|
}
|
|
94
|
-
get
|
|
95
|
-
return this[
|
|
122
|
+
get prefix() {
|
|
123
|
+
return this[kContext].prefix;
|
|
96
124
|
}
|
|
97
|
-
set
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
125
|
+
set prefix(value) {
|
|
126
|
+
if (value) {
|
|
127
|
+
const url = new OpraURL(value);
|
|
128
|
+
this[kContext].prefix = url.pathname;
|
|
129
|
+
}
|
|
130
|
+
else
|
|
131
|
+
this[kContext].prefix = '';
|
|
132
|
+
this._changed();
|
|
104
133
|
}
|
|
105
|
-
get
|
|
106
|
-
|
|
107
|
-
return v == null ? null : v;
|
|
134
|
+
get protocol() {
|
|
135
|
+
return this[kContext].protocol || 'http:';
|
|
108
136
|
}
|
|
109
|
-
set
|
|
110
|
-
if (v
|
|
111
|
-
|
|
112
|
-
|
|
137
|
+
set protocol(v) {
|
|
138
|
+
if (v) {
|
|
139
|
+
if (!schemeRegEx.test(v))
|
|
140
|
+
throw Object.assign(new TypeError('Invalid protocol'), {
|
|
141
|
+
protocol: v,
|
|
142
|
+
code: 'ERR_INVALID_URL'
|
|
143
|
+
});
|
|
144
|
+
this[kContext].protocol = v + (v.endsWith(':') ? '' : ':');
|
|
113
145
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
hostname: v,
|
|
118
|
-
code: 'ERR_INVALID_URL'
|
|
119
|
-
});
|
|
120
|
-
this[CONTEXT_KEY].port = v;
|
|
146
|
+
else
|
|
147
|
+
this[kContext].protocol = '';
|
|
148
|
+
this._changed();
|
|
121
149
|
}
|
|
122
|
-
get
|
|
123
|
-
return this.
|
|
150
|
+
get username() {
|
|
151
|
+
return this[kContext].username;
|
|
124
152
|
}
|
|
125
|
-
|
|
126
|
-
|
|
153
|
+
set username(v) {
|
|
154
|
+
this[kContext].username = v || '';
|
|
155
|
+
this._changed();
|
|
127
156
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
this[CONTEXT_KEY].pathPrefix = '';
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
v = (0, path_utils_js_1.normalizePath)((0, fast_tokenizer_1.tokenize)(v, { delimiters: '#?', quotes: true, brackets: true }).next() || '', true);
|
|
134
|
-
if (v.includes('://'))
|
|
135
|
-
this[CONTEXT_KEY].pathPrefix = v;
|
|
136
|
-
else
|
|
137
|
-
this[CONTEXT_KEY].pathPrefix = v ? '/' + v : '';
|
|
157
|
+
get origin() {
|
|
158
|
+
return this.hostname ? (this.protocol + '//' + this.hostname) : '';
|
|
138
159
|
}
|
|
139
160
|
get path() {
|
|
140
|
-
return this[
|
|
161
|
+
return this[kPath];
|
|
141
162
|
}
|
|
142
163
|
get pathname() {
|
|
143
164
|
this._update();
|
|
144
|
-
return this[
|
|
165
|
+
return this[kContext].pathname || '';
|
|
145
166
|
}
|
|
146
167
|
set pathname(v) {
|
|
147
168
|
this._setPathname(v, false);
|
|
148
169
|
}
|
|
149
170
|
get searchParams() {
|
|
150
|
-
return this[
|
|
171
|
+
return this[kSearchParams];
|
|
151
172
|
}
|
|
152
173
|
get hash() {
|
|
153
|
-
return this[
|
|
174
|
+
return this[kContext].hash || '';
|
|
154
175
|
}
|
|
155
176
|
set hash(v) {
|
|
156
|
-
this[
|
|
177
|
+
this[kContext].hash = v ? (v.startsWith('#') ? v : '#' + v) : '';
|
|
178
|
+
this._changed();
|
|
157
179
|
}
|
|
158
180
|
get search() {
|
|
159
181
|
this._update();
|
|
160
|
-
return this[
|
|
182
|
+
return this[kContext].search || '';
|
|
161
183
|
}
|
|
162
184
|
set search(v) {
|
|
163
|
-
this.searchParams.
|
|
185
|
+
this.searchParams.clear();
|
|
186
|
+
this.searchParams.appendAll(v);
|
|
187
|
+
}
|
|
188
|
+
parse(input) {
|
|
189
|
+
const m = urlRegEx.exec(input);
|
|
190
|
+
if (!m)
|
|
191
|
+
throw Object.assign(new TypeError('Invalid URL'), {
|
|
192
|
+
input,
|
|
193
|
+
code: 'ERR_INVALID_URL'
|
|
194
|
+
});
|
|
195
|
+
this.protocol = m[1];
|
|
196
|
+
const isAbsolute = !!m[2];
|
|
197
|
+
if (isAbsolute) {
|
|
198
|
+
let tokens = (0, fast_tokenizer_1.splitString)(m[2], { delimiters: '@' });
|
|
199
|
+
if (tokens.length > 1) {
|
|
200
|
+
this.host = tokens[1];
|
|
201
|
+
tokens = (0, fast_tokenizer_1.splitString)(tokens[0], { delimiters: ':' });
|
|
202
|
+
this.username = tokens[0] ? decodeURIComponent(tokens[0]) : '';
|
|
203
|
+
this.password = tokens[1] ? decodeURIComponent(tokens[1]) : '';
|
|
204
|
+
}
|
|
205
|
+
else
|
|
206
|
+
this.host = tokens[0];
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
this.host = '';
|
|
210
|
+
this.username = '';
|
|
211
|
+
this.password = '';
|
|
212
|
+
}
|
|
213
|
+
input = m[3] || '';
|
|
214
|
+
let tokenizer = (0, fast_tokenizer_1.tokenize)(input, { delimiters: '#', quotes: true, brackets: true });
|
|
215
|
+
input = tokenizer.next() || '';
|
|
216
|
+
this.hash = tokenizer.join('#');
|
|
217
|
+
tokenizer = (0, fast_tokenizer_1.tokenize)(input, { delimiters: '?', quotes: true, brackets: true });
|
|
218
|
+
this._setPathname(tokenizer.next() || '', isAbsolute);
|
|
219
|
+
this.searchParams.clear();
|
|
220
|
+
this.searchParams.appendAll(tokenizer.join('&'));
|
|
221
|
+
this._changed();
|
|
164
222
|
}
|
|
165
|
-
|
|
166
|
-
this.path.
|
|
223
|
+
join(...source) {
|
|
224
|
+
this.path.join(...source);
|
|
167
225
|
return this;
|
|
168
226
|
}
|
|
169
|
-
|
|
227
|
+
addParam(name, value) {
|
|
170
228
|
this.searchParams.append(name, value);
|
|
171
229
|
return this;
|
|
172
230
|
}
|
|
231
|
+
setParam(name, value) {
|
|
232
|
+
this.searchParams.set(name, value);
|
|
233
|
+
return this;
|
|
234
|
+
}
|
|
173
235
|
setHost(v) {
|
|
174
236
|
this.host = v;
|
|
175
237
|
return this;
|
|
@@ -183,11 +245,11 @@ class OpraURL {
|
|
|
183
245
|
return this;
|
|
184
246
|
}
|
|
185
247
|
setPort(v) {
|
|
186
|
-
this.port = v;
|
|
248
|
+
this.port = v ? String(v) : '';
|
|
187
249
|
return this;
|
|
188
250
|
}
|
|
189
251
|
setPrefix(v) {
|
|
190
|
-
this.
|
|
252
|
+
this.prefix = v;
|
|
191
253
|
return this;
|
|
192
254
|
}
|
|
193
255
|
setPathname(v) {
|
|
@@ -202,46 +264,11 @@ class OpraURL {
|
|
|
202
264
|
this.search = v;
|
|
203
265
|
return this;
|
|
204
266
|
}
|
|
205
|
-
setSearchParam(name, value) {
|
|
206
|
-
this.searchParams.set(name, value);
|
|
207
|
-
return this;
|
|
208
|
-
}
|
|
209
|
-
parse(input) {
|
|
210
|
-
const m = urlRegEx.exec(input);
|
|
211
|
-
if (!m)
|
|
212
|
-
throw Object.assign(new TypeError('Invalid URL'), {
|
|
213
|
-
input,
|
|
214
|
-
code: 'ERR_INVALID_URL'
|
|
215
|
-
});
|
|
216
|
-
if (m[1])
|
|
217
|
-
this.protocol = m[1];
|
|
218
|
-
if (m[2]) {
|
|
219
|
-
let tokens = (0, fast_tokenizer_1.splitString)(m[2], { delimiters: '@' });
|
|
220
|
-
if (tokens.length > 1) {
|
|
221
|
-
this.host = tokens[1];
|
|
222
|
-
tokens = (0, fast_tokenizer_1.splitString)(tokens[0], { delimiters: ':' });
|
|
223
|
-
this.username = tokens[0] ? decodeURIComponent(tokens[0]) : '';
|
|
224
|
-
this.password = tokens[1] ? decodeURIComponent(tokens[1]) : '';
|
|
225
|
-
}
|
|
226
|
-
else
|
|
227
|
-
this.host = tokens[0];
|
|
228
|
-
}
|
|
229
|
-
input = m[3] || '';
|
|
230
|
-
let tokenizer = (0, fast_tokenizer_1.tokenize)(input, { delimiters: '#', quotes: true, brackets: true });
|
|
231
|
-
input = tokenizer.next() || '';
|
|
232
|
-
this.hash = tokenizer.join('#');
|
|
233
|
-
tokenizer = (0, fast_tokenizer_1.tokenize)(input, { delimiters: '?', quotes: true, brackets: true });
|
|
234
|
-
this._setPathname(tokenizer.next() || '', true);
|
|
235
|
-
// this.path.join()
|
|
236
|
-
this.searchParams.clear();
|
|
237
|
-
this.searchParams.parse(tokenizer.join('&'));
|
|
238
|
-
return this;
|
|
239
|
-
}
|
|
240
267
|
toString() {
|
|
241
268
|
return this.href;
|
|
242
269
|
}
|
|
243
270
|
/* istanbul ignore next */
|
|
244
|
-
[nodeInspectCustom]() {
|
|
271
|
+
[(_a = kContext, nodeInspectCustom)]() {
|
|
245
272
|
this._update();
|
|
246
273
|
return {
|
|
247
274
|
protocol: this.protocol,
|
|
@@ -250,7 +277,7 @@ class OpraURL {
|
|
|
250
277
|
host: this.host,
|
|
251
278
|
hostname: this.hostname,
|
|
252
279
|
origin: this.origin,
|
|
253
|
-
pathPrefix: this.
|
|
280
|
+
pathPrefix: this.prefix,
|
|
254
281
|
path: this.path,
|
|
255
282
|
pathname: this.pathname,
|
|
256
283
|
search: this.search,
|
|
@@ -258,27 +285,34 @@ class OpraURL {
|
|
|
258
285
|
hash: this.hash,
|
|
259
286
|
};
|
|
260
287
|
}
|
|
261
|
-
_invalidate() {
|
|
262
|
-
this[CONTEXT_KEY].needUpdate = true;
|
|
263
|
-
}
|
|
264
288
|
_update() {
|
|
265
|
-
if (!this[
|
|
289
|
+
if (!this[kContext].needUpdate)
|
|
266
290
|
return;
|
|
267
|
-
this[
|
|
291
|
+
const ctx = this[kContext];
|
|
292
|
+
ctx.needUpdate = false;
|
|
268
293
|
let s = this.path.toString();
|
|
269
|
-
|
|
294
|
+
ctx.pathname = s ? '/' + s : '';
|
|
270
295
|
s = this.searchParams.toString();
|
|
271
|
-
|
|
296
|
+
ctx.search = s ? '?' + s : '';
|
|
297
|
+
let address = '';
|
|
298
|
+
if (ctx.hostname) {
|
|
299
|
+
address += (ctx.protocol || 'http:') + '//' +
|
|
300
|
+
(ctx.username || ctx.password
|
|
301
|
+
? ((ctx.username ? encodeURIComponent(ctx.username) : '') +
|
|
302
|
+
(ctx.password ? ':' + encodeURIComponent(ctx.password) : '') + '@')
|
|
303
|
+
: '') + this.host;
|
|
304
|
+
}
|
|
305
|
+
ctx.address = address + ctx.prefix + ctx.pathname;
|
|
272
306
|
}
|
|
273
|
-
_setPathname(v,
|
|
307
|
+
_setPathname(v, trimPrefix) {
|
|
274
308
|
this.path.clear();
|
|
275
309
|
if (!v)
|
|
276
310
|
return;
|
|
277
311
|
const pathTokenizer = (0, fast_tokenizer_1.tokenize)((0, path_utils_js_1.normalizePath)(v, true), {
|
|
278
312
|
delimiters: '/', quotes: true, brackets: true,
|
|
279
313
|
});
|
|
280
|
-
if (
|
|
281
|
-
const prefixTokenizer = (0, fast_tokenizer_1.tokenize)((0, path_utils_js_1.normalizePath)(this.
|
|
314
|
+
if (trimPrefix && this.prefix) {
|
|
315
|
+
const prefixTokenizer = (0, fast_tokenizer_1.tokenize)((0, path_utils_js_1.normalizePath)(this.prefix, true), {
|
|
282
316
|
delimiters: '/', quotes: true, brackets: true,
|
|
283
317
|
});
|
|
284
318
|
for (const a of prefixTokenizer) {
|
|
@@ -289,8 +323,15 @@ class OpraURL {
|
|
|
289
323
|
}
|
|
290
324
|
for (const x of pathTokenizer) {
|
|
291
325
|
const p = (0, path_utils_js_1.decodePathComponent)(x);
|
|
292
|
-
this.path.
|
|
326
|
+
this.path.join(p);
|
|
293
327
|
}
|
|
328
|
+
this._changed();
|
|
329
|
+
}
|
|
330
|
+
_changed() {
|
|
331
|
+
this[kContext].needUpdate = true;
|
|
294
332
|
}
|
|
295
333
|
}
|
|
296
334
|
exports.OpraURL = OpraURL;
|
|
335
|
+
OpraURL.kContext = kContext;
|
|
336
|
+
OpraURL.kPath = kPath;
|
|
337
|
+
OpraURL.kSearchParams = kSearchParams;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Generated from ./src/filter/antlr/OpraFilter.g4 by ANTLR 4.11.2-SNAPSHOT
|
|
2
2
|
// noinspection ES6UnusedImports,JSUnusedGlobalSymbols,JSUnusedLocalSymbols
|
|
3
|
-
import { ATNDeserializer, DFA, Lexer, LexerATNSimulator, PredictionContextCache, Token } from "antlr4";
|
|
3
|
+
import { ATNDeserializer, DFA, Lexer, LexerATNSimulator, PredictionContextCache, Token } from "@browsery/antlr4";
|
|
4
4
|
export default class OpraFilterLexer extends Lexer {
|
|
5
5
|
constructor(input) {
|
|
6
6
|
super(input);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParseTreeListener } from "antlr4";
|
|
1
|
+
import { ParseTreeListener } from "@browsery/antlr4";
|
|
2
2
|
import { ArithmeticExpressionContext, ArrayExpressionContext, ArthOpContext, BooleanContext, BooleanLiteralContext, ComparisonExpressionContext, CompOpContext, DateLiteralContext, DateTimeLiteralContext, DateTimePrecisionContext, ExternalConstantContext, ExternalConstantTermContext, FunctionContext, IdentifierContext, InfinityContext, InfinityLiteralContext, InvocableContext, LiteralTermContext, LogicalExpressionContext, LogOpContext, MemberIndexContext, MemberInvocationContext, NullContext, NullLiteralContext, NumberIndexContext, NumberLiteralContext, ParamListContext, ParenthesizedExpressionContext, PluralDateTimePrecisionContext, PolarityExpressionContext, PolarOpContext, QualifiedIdentifierContext, QualifiedIdentifierTermContext, RootContext, StringLiteralContext, TermExpressionContext, TimeLiteralContext, UnitContext } from "./OpraFilterParser.js";
|
|
3
3
|
/**
|
|
4
4
|
* This interface defines a complete listener for a parse tree produced by
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Generated from ./src/filter/antlr/OpraFilter.g4 by ANTLR 4.11.2-SNAPSHOT
|
|
2
|
-
import { ParseTreeListener } from "antlr4";
|
|
2
|
+
import { ParseTreeListener } from "@browsery/antlr4";
|
|
3
3
|
/**
|
|
4
4
|
* This interface defines a complete listener for a parse tree produced by
|
|
5
5
|
* `OpraFilterParser`.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ATN, DFA, FailedPredicateException, Parser, ParserRuleContext, RuleContext, TerminalNode, TokenStream } from 'antlr4';
|
|
1
|
+
import { ATN, DFA, FailedPredicateException, Parser, ParserRuleContext, RuleContext, TerminalNode, TokenStream } from '@browsery/antlr4';
|
|
2
2
|
import type OpraFilterListener from "./OpraFilterListener.js";
|
|
3
3
|
import type OpraFilterVisitor from "./OpraFilterVisitor.js";
|
|
4
4
|
export default class OpraFilterParser extends Parser {
|
|
@@ -2,12 +2,8 @@
|
|
|
2
2
|
// Generated from ./src/filter/antlr/OpraFilter.g4 by ANTLR 4.11.2-SNAPSHOT
|
|
3
3
|
// noinspection ES6UnusedImports,JSUnusedGlobalSymbols,JSUnusedLocalSymbols,SpellCheckingInspection
|
|
4
4
|
// @ts-nocheck
|
|
5
|
-
import { ATN, ATNDeserializer, DFA, FailedPredicateException, NoViableAltException, Parser, ParserATNSimulator, ParserRuleContext, PredictionContextCache, RecognitionException, Token } from 'antlr4';
|
|
5
|
+
import { ATN, ATNDeserializer, DFA, FailedPredicateException, NoViableAltException, Parser, ParserATNSimulator, ParserRuleContext, PredictionContextCache, RecognitionException, Token } from '@browsery/antlr4';
|
|
6
6
|
export default class OpraFilterParser extends Parser {
|
|
7
|
-
constructor(input) {
|
|
8
|
-
super(input);
|
|
9
|
-
this._interp = new ParserATNSimulator(this, OpraFilterParser._ATN, OpraFilterParser.DecisionsToDFA, new PredictionContextCache());
|
|
10
|
-
}
|
|
11
7
|
get grammarFileName() {
|
|
12
8
|
return "OpraFilter.g4";
|
|
13
9
|
}
|
|
@@ -26,6 +22,10 @@ export default class OpraFilterParser extends Parser {
|
|
|
26
22
|
createFailedPredicateException(predicate, message) {
|
|
27
23
|
return new FailedPredicateException(this, predicate, message);
|
|
28
24
|
}
|
|
25
|
+
constructor(input) {
|
|
26
|
+
super(input);
|
|
27
|
+
this._interp = new ParserATNSimulator(this, OpraFilterParser._ATN, OpraFilterParser.DecisionsToDFA, new PredictionContextCache());
|
|
28
|
+
}
|
|
29
29
|
// @RuleVersion(0)
|
|
30
30
|
root() {
|
|
31
31
|
let localctx = new RootContext(this, this._ctx, this.state);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParseTreeVisitor } from 'antlr4';
|
|
1
|
+
import { ParseTreeVisitor } from '@browsery/antlr4';
|
|
2
2
|
import { ArithmeticExpressionContext, ArrayExpressionContext, ArthOpContext, BooleanContext, BooleanLiteralContext, ComparisonExpressionContext, CompOpContext, DateLiteralContext, DateTimeLiteralContext, DateTimePrecisionContext, ExternalConstantContext, ExternalConstantTermContext, FunctionContext, IdentifierContext, InfinityContext, InfinityLiteralContext, InvocableContext, LiteralTermContext, LogicalExpressionContext, LogOpContext, MemberIndexContext, MemberInvocationContext, NullContext, NullLiteralContext, NumberIndexContext, NumberLiteralContext, ParamListContext, ParenthesizedExpressionContext, PluralDateTimePrecisionContext, PolarityExpressionContext, PolarOpContext, QualifiedIdentifierContext, QualifiedIdentifierTermContext, RootContext, StringLiteralContext, TermExpressionContext, TimeLiteralContext, UnitContext } from "./OpraFilterParser.js";
|
|
3
3
|
/**
|
|
4
4
|
* This interface defines a complete generic visitor for a parse tree produced
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Generated from ./src/filter/antlr/OpraFilter.g4 by ANTLR 4.11.2-SNAPSHOT
|
|
2
|
-
import { ParseTreeVisitor } from 'antlr4';
|
|
2
|
+
import { ParseTreeVisitor } from '@browsery/antlr4';
|
|
3
3
|
/**
|
|
4
4
|
* This interface defines a complete generic visitor for a parse tree produced
|
|
5
5
|
* by `OpraFilterParser`.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Expression } from '../abstract/expression.js';
|
|
2
|
-
export
|
|
2
|
+
export type ArithmeticOperator = '+' | '-' | '*' | '/';
|
|
3
3
|
export declare class ArithmeticExpression extends Expression {
|
|
4
4
|
items: ArithmeticExpressionItem[];
|
|
5
5
|
constructor();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StrictOmit } from 'ts-gems';
|
|
2
2
|
import { Expression } from '../abstract/expression.js';
|
|
3
|
-
export
|
|
3
|
+
export type ComparisonOperator = '<=' | '<' | '>' | '>=' | '=' | '!=' | 'in' | '!in' | 'like' | '!like' | 'ilike' | '!ilike';
|
|
4
4
|
export declare class ComparisonExpression extends Expression {
|
|
5
5
|
op: ComparisonOperator;
|
|
6
6
|
left: Expression;
|
package/esm/filter/build.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ArithmeticExpression, ArrayExpression, ComparisonExpression, DateLiteral, Expression, LogicalExpression, NumberLiteral, ParenthesesExpression, QualifiedIdentifier, TimeLiteral } from './ast/index.js';
|
|
2
|
-
|
|
3
|
-
export
|
|
2
|
+
type _EntryValue = Expression | string | number | bigint | boolean | null | Date;
|
|
3
|
+
export type EntryValue = _EntryValue | _EntryValue[];
|
|
4
4
|
export declare function $or(...items: Expression[]): LogicalExpression;
|
|
5
5
|
export declare function $and(...items: Expression[]): LogicalExpression;
|
|
6
6
|
export declare function $date(v: string): DateLiteral;
|
|
@@ -21,7 +21,7 @@ export declare function $notLike(left: _EntryValue, right: _EntryValue): Compari
|
|
|
21
21
|
export declare function $ilike(left: _EntryValue, right: _EntryValue): ComparisonExpression;
|
|
22
22
|
export declare function $notILike(left: _EntryValue, right: _EntryValue): ComparisonExpression;
|
|
23
23
|
export declare function $paren(expression: Expression): ParenthesesExpression;
|
|
24
|
-
|
|
24
|
+
type MathExpression = ArithmeticExpression & {
|
|
25
25
|
add(expression: EntryValue): MathExpression;
|
|
26
26
|
sub(expression: EntryValue): MathExpression;
|
|
27
27
|
mul(expression: EntryValue): MathExpression;
|
package/esm/filter/errors.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RecognitionException } from 'antlr4';
|
|
2
|
-
import { Recognizer } from 'antlr4/
|
|
1
|
+
import { RecognitionException } from '@browsery/antlr4';
|
|
2
|
+
import { Recognizer } from '@browsery/antlr4/typings/Recognizer';
|
|
3
3
|
export declare class SyntaxError extends TypeError {
|
|
4
4
|
}
|
|
5
5
|
export declare class ValidationError extends TypeError {
|
|
@@ -8,11 +8,13 @@ export declare class FilterParseError extends Error {
|
|
|
8
8
|
recognizer: Recognizer<any>;
|
|
9
9
|
offendingSymbol: any | undefined;
|
|
10
10
|
line: number;
|
|
11
|
+
column: number;
|
|
11
12
|
e: RecognitionException | undefined;
|
|
12
13
|
constructor(message: string, args: {
|
|
13
14
|
recognizer: Recognizer<any>;
|
|
14
15
|
offendingSymbol: any | undefined;
|
|
15
16
|
line: number;
|
|
17
|
+
column: number;
|
|
16
18
|
e: RecognitionException | undefined;
|
|
17
19
|
});
|
|
18
20
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ParseTreeVisitor as TParseTreeVisitor } from 'antlr4';
|
|
1
|
+
import type { ParseTreeVisitor as TParseTreeVisitor, RuleNode } from '@browsery/antlr4';
|
|
2
2
|
import { ArithmeticExpressionContext, ArrayExpressionContext, BooleanLiteralContext, ComparisonExpressionContext, DateLiteralContext, DateTimeLiteralContext, ExternalConstantTermContext, IdentifierContext, LogicalExpressionContext, NumberLiteralContext, ParenthesizedExpressionContext, PolarityExpressionContext, QualifiedIdentifierTermContext, RootContext, StringLiteralContext, TimeLiteralContext } from './antlr/OpraFilterParser.js';
|
|
3
3
|
import OpraFilterVisitor from './antlr/OpraFilterVisitor.js';
|
|
4
4
|
import { ArithmeticExpression, ArrayExpression, BooleanLiteral, DateLiteral, LogicalExpression, NullLiteral, NumberLiteral, ParenthesesExpression, QualifiedIdentifier, StringLiteral, TimeLiteral } from './ast/index.js';
|
|
@@ -9,6 +9,7 @@ export declare class FilterTreeVisitor extends ParseTreeVisitor<any> implements
|
|
|
9
9
|
constructor(options?: {
|
|
10
10
|
timeZone?: string;
|
|
11
11
|
});
|
|
12
|
+
visitChildren(node: RuleNode): any;
|
|
12
13
|
protected defaultResult(): any;
|
|
13
14
|
visitRoot(ctx: RootContext): any;
|
|
14
15
|
visitIdentifier(ctx: IdentifierContext): string;
|