@opra/common 0.22.0 → 0.23.1
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/browser.js +957 -1566
- package/cjs/document/api-document.js +7 -3
- package/cjs/document/data-type/api-field.js +2 -2
- package/cjs/document/data-type/complex-type.js +17 -63
- package/cjs/document/data-type/data-type.js +0 -9
- package/cjs/document/data-type/enum-type.js +2 -8
- package/cjs/document/data-type/mapped-type.js +0 -36
- package/cjs/document/data-type/simple-type.js +2 -8
- package/cjs/document/data-type/union-type.js +1 -37
- package/cjs/document/index.js +2 -0
- package/cjs/document/resource/collection.js +75 -32
- package/cjs/document/resource/singleton.js +31 -20
- package/cjs/document/resource/storage.js +6 -20
- package/cjs/document/utils/generate-codec.js +39 -0
- package/cjs/exception/http-errors/bad-request.error.js +2 -3
- package/cjs/exception/http-errors/failed-dependency.error.js +2 -3
- package/cjs/exception/http-errors/forbidden.error.js +2 -3
- package/cjs/exception/http-errors/internal-server.error.js +2 -3
- package/cjs/exception/http-errors/method-not-allowed.error.js +2 -3
- package/cjs/exception/http-errors/not-acceptable.error.js +2 -3
- package/cjs/exception/http-errors/not-found.error.js +2 -3
- package/cjs/exception/http-errors/unauthorized.error.js +2 -3
- package/cjs/exception/http-errors/unprocessable-entity.error.js +2 -2
- package/cjs/exception/opra-exception.js +48 -33
- package/cjs/exception/resource-errors/resource-not-found.error.js +2 -3
- package/cjs/exception/wrap-exception.js +16 -16
- package/cjs/helpers/index.js +1 -1
- package/cjs/helpers/is-url-string.js +14 -0
- package/cjs/helpers/object-utils.js +2 -2
- package/cjs/helpers/responsive-map.js +4 -4
- package/cjs/helpers/type-guards.js +15 -3
- package/cjs/http/index.js +2 -9
- package/cjs/http/opra-url-path.js +251 -0
- package/cjs/{url → http}/opra-url.js +53 -109
- package/cjs/i18n/i18n.js +1 -1
- package/cjs/index.js +0 -2
- package/cjs/schema/opra-schema.ns.js +1 -1
- package/cjs/schema/resource/operation.interface.js +2 -0
- package/esm/document/api-document.js +9 -5
- package/esm/document/data-type/api-field.js +2 -2
- package/esm/document/data-type/complex-type.js +13 -59
- package/esm/document/data-type/data-type.js +0 -9
- package/esm/document/data-type/enum-type.js +2 -8
- package/esm/document/data-type/mapped-type.js +0 -36
- package/esm/document/data-type/simple-type.js +2 -8
- package/esm/document/data-type/union-type.js +1 -37
- package/esm/document/index.js +2 -0
- package/esm/document/resource/collection.js +75 -32
- package/esm/document/resource/singleton.js +31 -20
- package/esm/document/resource/storage.js +6 -20
- package/esm/document/utils/generate-codec.js +33 -0
- package/esm/exception/http-errors/bad-request.error.js +2 -3
- package/esm/exception/http-errors/failed-dependency.error.js +2 -3
- package/esm/exception/http-errors/forbidden.error.js +2 -3
- package/esm/exception/http-errors/internal-server.error.js +2 -3
- package/esm/exception/http-errors/method-not-allowed.error.js +2 -3
- package/esm/exception/http-errors/not-acceptable.error.js +2 -3
- package/esm/exception/http-errors/not-found.error.js +2 -3
- package/esm/exception/http-errors/unauthorized.error.js +2 -3
- package/esm/exception/http-errors/unprocessable-entity.error.js +2 -2
- package/esm/exception/opra-exception.js +47 -32
- package/esm/exception/resource-errors/resource-not-found.error.js +2 -3
- package/esm/exception/wrap-exception.js +16 -16
- package/esm/helpers/index.js +1 -1
- package/esm/helpers/is-url-string.js +9 -0
- package/esm/helpers/object-utils.js +2 -2
- package/esm/helpers/responsive-map.js +4 -4
- package/esm/helpers/type-guards.js +11 -2
- package/esm/http/index.js +2 -9
- package/esm/http/opra-url-path.js +246 -0
- package/esm/{url → http}/opra-url.js +53 -109
- package/esm/i18n/i18n.js +2 -2
- package/esm/index.js +0 -2
- package/esm/schema/opra-schema.ns.js +1 -1
- package/esm/schema/resource/operation.interface.js +1 -0
- package/package.json +5 -5
- package/types/document/api-document.d.ts +4 -1
- package/types/document/data-type/complex-type.d.ts +7 -12
- package/types/document/data-type/data-type.d.ts +0 -6
- package/types/document/data-type/enum-type.d.ts +2 -4
- package/types/document/data-type/mapped-type.d.ts +1 -5
- package/types/document/data-type/simple-type.d.ts +2 -4
- package/types/document/data-type/union-type.d.ts +1 -5
- package/types/document/index.d.ts +2 -0
- package/types/document/interfaces/collection-resource.interface.d.ts +10 -0
- package/types/document/interfaces/singleton-resource.interface.d.ts +7 -0
- package/types/document/interfaces/storage-resource.interface.d.ts +8 -0
- package/types/document/resource/collection.d.ts +41 -35
- package/types/document/resource/resource.d.ts +1 -0
- package/types/document/resource/singleton.d.ts +24 -21
- package/types/document/resource/storage.d.ts +14 -17
- package/types/document/utils/generate-codec.d.ts +10 -0
- package/types/exception/error-issue.d.ts +2 -1
- package/types/exception/http-errors/bad-request.error.d.ts +2 -1
- package/types/exception/http-errors/failed-dependency.error.d.ts +2 -1
- package/types/exception/http-errors/forbidden.error.d.ts +2 -1
- package/types/exception/http-errors/internal-server.error.d.ts +2 -1
- package/types/exception/http-errors/method-not-allowed.error.d.ts +2 -1
- package/types/exception/http-errors/not-acceptable.error.d.ts +2 -1
- package/types/exception/http-errors/not-found.error.d.ts +2 -1
- package/types/exception/http-errors/unauthorized.error.d.ts +2 -1
- package/types/exception/http-errors/unprocessable-entity.error.d.ts +2 -1
- package/types/exception/opra-exception.d.ts +13 -8
- package/types/exception/wrap-exception.d.ts +1 -1
- package/types/helpers/index.d.ts +1 -1
- package/types/helpers/is-url-string.d.ts +2 -0
- package/types/helpers/object-utils.d.ts +1 -1
- package/types/helpers/type-guards.d.ts +3 -0
- package/types/http/index.d.ts +2 -9
- package/types/http/opra-url-path.d.ts +54 -0
- package/types/{url → http}/opra-url.d.ts +9 -13
- package/types/index.d.ts +0 -2
- package/types/schema/data-type/complex-type.interface.d.ts +1 -1
- package/types/schema/opra-schema.ns.d.ts +1 -1
- package/types/schema/resource/collection.interface.d.ts +29 -8
- package/types/schema/resource/operation.interface.d.ts +3 -0
- package/types/schema/resource/singleton.interface.d.ts +5 -5
- package/types/schema/resource/storage.interface.d.ts +42 -5
- package/cjs/helpers/is-url.js +0 -8
- package/cjs/http/codecs/boolean-codec.js +0 -24
- package/cjs/http/codecs/date-codec.js +0 -41
- package/cjs/http/codecs/filter-codec.js +0 -17
- package/cjs/http/codecs/integer-codec.js +0 -19
- package/cjs/http/codecs/number-codec.js +0 -24
- package/cjs/http/codecs/string-codec.js +0 -23
- package/cjs/http/http-params.js +0 -353
- package/cjs/http/multipart/batch-multipart.js +0 -170
- package/cjs/http/multipart/http-request-content.js +0 -17
- package/cjs/http/multipart/http-response-content.js +0 -14
- package/cjs/http/multipart/index.js +0 -2
- package/cjs/url/index.js +0 -8
- package/cjs/url/opra-url-path-component.js +0 -30
- package/cjs/url/opra-url-path.js +0 -155
- package/cjs/url/utils/decode-path-component.js +0 -41
- package/cjs/url/utils/encode-path-component.js +0 -27
- package/cjs/utils/path-utils.js +0 -24
- package/esm/helpers/is-url.js +0 -4
- package/esm/http/codecs/boolean-codec.js +0 -20
- package/esm/http/codecs/date-codec.js +0 -37
- package/esm/http/codecs/filter-codec.js +0 -13
- package/esm/http/codecs/integer-codec.js +0 -15
- package/esm/http/codecs/number-codec.js +0 -20
- package/esm/http/codecs/string-codec.js +0 -19
- package/esm/http/http-params.js +0 -348
- package/esm/http/multipart/batch-multipart.js +0 -170
- package/esm/http/multipart/http-request-content.js +0 -17
- package/esm/http/multipart/http-response-content.js +0 -14
- package/esm/http/multipart/index.js +0 -2
- package/esm/url/index.js +0 -5
- package/esm/url/opra-url-path-component.js +0 -26
- package/esm/url/opra-url-path.js +0 -151
- package/esm/url/utils/decode-path-component.js +0 -37
- package/esm/url/utils/encode-path-component.js +0 -22
- package/esm/utils/path-utils.js +0 -19
- package/types/helpers/is-url.d.ts +0 -1
- package/types/http/codecs/boolean-codec.d.ts +0 -5
- package/types/http/codecs/date-codec.d.ts +0 -16
- package/types/http/codecs/filter-codec.d.ts +0 -6
- package/types/http/codecs/integer-codec.d.ts +0 -11
- package/types/http/codecs/number-codec.d.ts +0 -14
- package/types/http/codecs/string-codec.d.ts +0 -16
- package/types/http/http-params.d.ts +0 -114
- package/types/http/interfaces/client-http-headers.interface.d.ts +0 -65
- package/types/http/interfaces/server-http-headers.interface.d.ts +0 -1
- package/types/http/multipart/batch-multipart.d.ts +0 -0
- package/types/http/multipart/http-request-content.d.ts +0 -0
- package/types/http/multipart/http-response-content.d.ts +0 -0
- package/types/http/multipart/index.d.ts +0 -0
- package/types/schema/resource/endpoint.interface.d.ts +0 -29
- package/types/url/index.d.ts +0 -5
- package/types/url/opra-url-path-component.d.ts +0 -15
- package/types/url/opra-url-path.d.ts +0 -36
- package/types/url/utils/decode-path-component.d.ts +0 -5
- package/types/url/utils/encode-path-component.d.ts +0 -1
- package/types/utils/path-utils.d.ts +0 -2
- /package/cjs/{http/interfaces/client-http-headers.interface.js → document/interfaces/collection-resource.interface.js} +0 -0
- /package/cjs/{http/interfaces/server-http-headers.interface.js → document/interfaces/singleton-resource.interface.js} +0 -0
- /package/cjs/{schema/resource/endpoint.interface.js → document/interfaces/storage-resource.interface.js} +0 -0
- /package/esm/{http/interfaces/client-http-headers.interface.js → document/interfaces/collection-resource.interface.js} +0 -0
- /package/esm/{http/interfaces/server-http-headers.interface.js → document/interfaces/singleton-resource.interface.js} +0 -0
- /package/esm/{schema/resource/endpoint.interface.js → document/interfaces/storage-resource.interface.js} +0 -0
|
@@ -1,47 +1,36 @@
|
|
|
1
1
|
var _a;
|
|
2
2
|
import { splitString, tokenize } from 'fast-tokenizer';
|
|
3
|
-
import { HttpParams } from '../http/index.js';
|
|
4
|
-
import { normalizePath } from '../utils/path-utils.js';
|
|
5
3
|
import { OpraURLPath } from './opra-url-path.js';
|
|
6
|
-
import { decodePathComponent } from './utils/decode-path-component.js';
|
|
7
4
|
const nodeInspectCustom = Symbol.for('nodejs.util.inspect.custom');
|
|
8
5
|
const urlRegEx = /^(?:((?:[A-Z][A-Z+-.]+:)+)\/\/([^/?]+))?(.*)?$/i;
|
|
9
6
|
const schemeRegEx = /^([A-Z][A-Z+-.]+:?)+$/i;
|
|
10
7
|
const hostRegEx = /^([^/:]+)(?::(\d+))?$/;
|
|
11
8
|
const hostnameRegEx = /^([^/:]+)$/;
|
|
12
|
-
const kContext = Symbol('kContext');
|
|
13
|
-
const kPath = Symbol('kPath');
|
|
14
|
-
const
|
|
9
|
+
const kContext = Symbol.for('kContext');
|
|
10
|
+
const kPath = Symbol.for('kPath');
|
|
11
|
+
const kSearchParams = Symbol.for('kSearchParams');
|
|
15
12
|
export class OpraURL {
|
|
16
13
|
constructor(input, base) {
|
|
17
14
|
this[_a] = {
|
|
18
15
|
protocol: '',
|
|
19
16
|
username: '',
|
|
20
|
-
prefix: '',
|
|
21
17
|
hostname: '',
|
|
22
18
|
port: '',
|
|
23
19
|
hash: '',
|
|
24
20
|
password: ''
|
|
25
21
|
};
|
|
26
|
-
this[
|
|
27
|
-
|
|
28
|
-
this[kContext].pathname = undefined;
|
|
29
|
-
this[kContext].address = undefined;
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
this[kParams] = new HttpParams('', {
|
|
33
|
-
onChange: () => {
|
|
34
|
-
this[kContext].search = undefined;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
22
|
+
this[kSearchParams] = new URLSearchParams();
|
|
23
|
+
this[kPath] = new OpraURLPath();
|
|
37
24
|
if (input)
|
|
38
|
-
this.
|
|
39
|
-
if (base) {
|
|
25
|
+
this._parse(String(input));
|
|
26
|
+
if (base && !this.host) {
|
|
40
27
|
const baseUrl = base instanceof OpraURL ? base : new OpraURL(base);
|
|
41
28
|
this[kContext].protocol = baseUrl.protocol;
|
|
42
29
|
this[kContext].hostname = baseUrl.hostname;
|
|
30
|
+
this[kContext].username = baseUrl.username;
|
|
31
|
+
this[kContext].password = baseUrl.password;
|
|
43
32
|
this[kContext].port = baseUrl.port;
|
|
44
|
-
this
|
|
33
|
+
this.path = OpraURLPath.join(baseUrl.path, this.path);
|
|
45
34
|
}
|
|
46
35
|
}
|
|
47
36
|
get address() {
|
|
@@ -55,7 +44,6 @@ export class OpraURL {
|
|
|
55
44
|
: '') + this.host;
|
|
56
45
|
}
|
|
57
46
|
this[kContext].address = address +
|
|
58
|
-
(this.prefix !== '/' ? this.prefix : '') +
|
|
59
47
|
(this.pathname !== '/' ? this.pathname : '');
|
|
60
48
|
}
|
|
61
49
|
return this[kContext].address;
|
|
@@ -93,7 +81,7 @@ export class OpraURL {
|
|
|
93
81
|
}
|
|
94
82
|
else
|
|
95
83
|
this[kContext].hostname = '';
|
|
96
|
-
this
|
|
84
|
+
this.invalidate();
|
|
97
85
|
}
|
|
98
86
|
get href() {
|
|
99
87
|
return this.address + this.search + this.hash;
|
|
@@ -103,7 +91,7 @@ export class OpraURL {
|
|
|
103
91
|
}
|
|
104
92
|
set password(v) {
|
|
105
93
|
this[kContext].password = v ?? '';
|
|
106
|
-
this
|
|
94
|
+
this.invalidate();
|
|
107
95
|
}
|
|
108
96
|
get port() {
|
|
109
97
|
return this[kContext].port;
|
|
@@ -112,8 +100,8 @@ export class OpraURL {
|
|
|
112
100
|
if (value) {
|
|
113
101
|
// noinspection SuspiciousTypeOfGuard
|
|
114
102
|
const v = typeof value === 'number' ? value : parseInt(value, 10);
|
|
115
|
-
if (isNaN(v) || v < 1 || v >
|
|
116
|
-
throw Object.assign(new TypeError(
|
|
103
|
+
if (isNaN(v) || v < 1 || v > 65535 || v % 1 > 0)
|
|
104
|
+
throw Object.assign(new TypeError(`Invalid port number (${value})`), {
|
|
117
105
|
hostname: v,
|
|
118
106
|
code: 'ERR_INVALID_URL'
|
|
119
107
|
});
|
|
@@ -121,18 +109,7 @@ export class OpraURL {
|
|
|
121
109
|
}
|
|
122
110
|
else
|
|
123
111
|
this[kContext].port = '';
|
|
124
|
-
|
|
125
|
-
get prefix() {
|
|
126
|
-
return this[kContext].prefix;
|
|
127
|
-
}
|
|
128
|
-
set prefix(value) {
|
|
129
|
-
if (value) {
|
|
130
|
-
const url = new OpraURL(value);
|
|
131
|
-
this[kContext].prefix = url.pathname;
|
|
132
|
-
}
|
|
133
|
-
else
|
|
134
|
-
this[kContext].prefix = '';
|
|
135
|
-
this[kContext].address = undefined;
|
|
112
|
+
this.invalidate();
|
|
136
113
|
}
|
|
137
114
|
get protocol() {
|
|
138
115
|
return this[kContext].protocol;
|
|
@@ -148,14 +125,14 @@ export class OpraURL {
|
|
|
148
125
|
}
|
|
149
126
|
else
|
|
150
127
|
this[kContext].protocol = '';
|
|
151
|
-
this
|
|
128
|
+
this.invalidate();
|
|
152
129
|
}
|
|
153
130
|
get username() {
|
|
154
131
|
return this[kContext].username;
|
|
155
132
|
}
|
|
156
133
|
set username(v) {
|
|
157
134
|
this[kContext].username = v ?? '';
|
|
158
|
-
this
|
|
135
|
+
this.invalidate();
|
|
159
136
|
}
|
|
160
137
|
get origin() {
|
|
161
138
|
return this.hostname ? (this.protocol + '//' + this.hostname) : '';
|
|
@@ -163,13 +140,20 @@ export class OpraURL {
|
|
|
163
140
|
get path() {
|
|
164
141
|
return this[kPath];
|
|
165
142
|
}
|
|
143
|
+
set path(path) {
|
|
144
|
+
// noinspection SuspiciousTypeOfGuard
|
|
145
|
+
this[kPath] = path instanceof OpraURLPath ? path : new OpraURLPath(path);
|
|
146
|
+
this[kContext].pathname = String(this[kPath]);
|
|
147
|
+
this.invalidate();
|
|
148
|
+
}
|
|
166
149
|
get pathname() {
|
|
167
150
|
if (this[kContext].pathname == null)
|
|
168
|
-
this[kContext].pathname =
|
|
151
|
+
this[kContext].pathname = this.path.toString() || '/';
|
|
169
152
|
return this[kContext].pathname;
|
|
170
153
|
}
|
|
171
154
|
set pathname(v) {
|
|
172
|
-
this
|
|
155
|
+
this[kPath] = new OpraURLPath(v);
|
|
156
|
+
this.invalidate();
|
|
173
157
|
}
|
|
174
158
|
get hash() {
|
|
175
159
|
return this[kContext].hash;
|
|
@@ -178,23 +162,36 @@ export class OpraURL {
|
|
|
178
162
|
this[kContext].hash = v ? (v.startsWith('#') ? v : '#' + v) : '';
|
|
179
163
|
}
|
|
180
164
|
get search() {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
this[kContext].search = s ? ('?' + s) : '';
|
|
184
|
-
}
|
|
185
|
-
return this[kContext].search;
|
|
165
|
+
const s = this[kSearchParams].toString();
|
|
166
|
+
return s ? '?' + s : '';
|
|
186
167
|
}
|
|
187
168
|
set search(v) {
|
|
188
|
-
|
|
189
|
-
this[kParams].clear();
|
|
190
|
-
this[kParams].appendAll(v);
|
|
191
|
-
}
|
|
192
|
-
this[kContext].search = undefined;
|
|
169
|
+
this[kSearchParams] = new URLSearchParams(v);
|
|
193
170
|
}
|
|
194
171
|
get searchParams() {
|
|
195
|
-
return this[
|
|
172
|
+
return this[kSearchParams];
|
|
173
|
+
}
|
|
174
|
+
set setSearchParams(v) {
|
|
175
|
+
this[kSearchParams] = v;
|
|
176
|
+
}
|
|
177
|
+
invalidate() {
|
|
178
|
+
this[kContext].address = undefined;
|
|
179
|
+
this[kContext].pathname = undefined;
|
|
180
|
+
}
|
|
181
|
+
join(...items) {
|
|
182
|
+
this.path = this.path.join(...items);
|
|
183
|
+
this.invalidate();
|
|
184
|
+
return this;
|
|
185
|
+
}
|
|
186
|
+
resolve(...items) {
|
|
187
|
+
this.path = this.path.resolve(...items);
|
|
188
|
+
this.invalidate();
|
|
189
|
+
return this;
|
|
196
190
|
}
|
|
197
|
-
|
|
191
|
+
toString() {
|
|
192
|
+
return this.href;
|
|
193
|
+
}
|
|
194
|
+
_parse(input) {
|
|
198
195
|
const m = urlRegEx.exec(input);
|
|
199
196
|
if (!m)
|
|
200
197
|
throw Object.assign(new TypeError('Invalid URL'), {
|
|
@@ -224,16 +221,9 @@ export class OpraURL {
|
|
|
224
221
|
input = tokenizer.next() || '';
|
|
225
222
|
this.hash = tokenizer.join('#');
|
|
226
223
|
tokenizer = tokenize(input, { delimiters: '?', quotes: true, brackets: true });
|
|
227
|
-
this.
|
|
224
|
+
this.path = new OpraURLPath(tokenizer.next());
|
|
228
225
|
this.search = tokenizer.join('&');
|
|
229
226
|
}
|
|
230
|
-
join(...source) {
|
|
231
|
-
this.path.join(...source);
|
|
232
|
-
return this;
|
|
233
|
-
}
|
|
234
|
-
toString() {
|
|
235
|
-
return this.href;
|
|
236
|
-
}
|
|
237
227
|
/* istanbul ignore next */
|
|
238
228
|
[(_a = kContext, nodeInspectCustom)]() {
|
|
239
229
|
// this._update();
|
|
@@ -244,59 +234,13 @@ export class OpraURL {
|
|
|
244
234
|
host: this.host,
|
|
245
235
|
hostname: this.hostname,
|
|
246
236
|
origin: this.origin,
|
|
247
|
-
pathPrefix: this.prefix,
|
|
248
237
|
path: this.path,
|
|
249
238
|
pathname: this.pathname,
|
|
250
239
|
search: this.search,
|
|
251
240
|
hash: this.hash,
|
|
252
241
|
};
|
|
253
242
|
}
|
|
254
|
-
//
|
|
255
|
-
// protected _update() {
|
|
256
|
-
// if (!this[kContext].needUpdate)
|
|
257
|
-
// return;
|
|
258
|
-
// const ctx = this[kContext];
|
|
259
|
-
// ctx.needUpdate = false;
|
|
260
|
-
// let s = this.path.toString();
|
|
261
|
-
// ctx.pathname = s ? '/' + s : '';
|
|
262
|
-
// s = this.searchParams.toString();
|
|
263
|
-
// ctx.search = s ? '?' + s : '';
|
|
264
|
-
//
|
|
265
|
-
// let address = '';
|
|
266
|
-
// if (ctx.hostname) {
|
|
267
|
-
// address += (ctx.protocol || 'http:') + '//' +
|
|
268
|
-
// (ctx.username || ctx.password
|
|
269
|
-
// ? (
|
|
270
|
-
// (ctx.username ? encodeURIComponent(ctx.username) : '') +
|
|
271
|
-
// (ctx.password ? ':' + encodeURIComponent(ctx.password) : '') + '@'
|
|
272
|
-
// )
|
|
273
|
-
// : '') + this.host;
|
|
274
|
-
// }
|
|
275
|
-
// ctx.address = address + ctx.prefix + ctx.pathname;
|
|
276
|
-
// }
|
|
277
|
-
_setPathname(v, trimPrefix) {
|
|
278
|
-
this.path.clear();
|
|
279
|
-
if (!v)
|
|
280
|
-
return;
|
|
281
|
-
const pathTokenizer = tokenize(normalizePath(v, true), {
|
|
282
|
-
delimiters: '/', quotes: true, brackets: true,
|
|
283
|
-
});
|
|
284
|
-
if (trimPrefix && this.prefix) {
|
|
285
|
-
const prefixTokenizer = tokenize(normalizePath(this.prefix, true), {
|
|
286
|
-
delimiters: '/', quotes: true, brackets: true,
|
|
287
|
-
});
|
|
288
|
-
for (const a of prefixTokenizer) {
|
|
289
|
-
const b = pathTokenizer.next();
|
|
290
|
-
if (a !== b)
|
|
291
|
-
throw Object.assign(new Error('Invalid URL path. pathPrefix does not match'), { path: v, code: 'ERR_INVALID_URL_PATH' });
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
for (const x of pathTokenizer) {
|
|
295
|
-
const p = decodePathComponent(x);
|
|
296
|
-
this.path.join(p);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
243
|
}
|
|
300
244
|
OpraURL.kContext = kContext;
|
|
301
245
|
OpraURL.kPath = kPath;
|
|
302
|
-
OpraURL.kParams =
|
|
246
|
+
OpraURL.kParams = kSearchParams;
|
package/esm/i18n/i18n.js
CHANGED
|
@@ -2,7 +2,7 @@ import { splitString, tokenize } from 'fast-tokenizer';
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import i18next from '@browsery/i18next';
|
|
5
|
-
import {
|
|
5
|
+
import { isUrlString } from '../helpers/index.js';
|
|
6
6
|
import { unescapeString } from './string-utils.js';
|
|
7
7
|
export const BaseI18n = Object.getPrototypeOf(i18next).constructor;
|
|
8
8
|
const globalLocaleDirs = [];
|
|
@@ -54,7 +54,7 @@ export class I18n extends BaseI18n {
|
|
|
54
54
|
}
|
|
55
55
|
async loadResourceBundle(lang, ns, filePath, deep, overwrite) {
|
|
56
56
|
let obj;
|
|
57
|
-
if (
|
|
57
|
+
if (isUrlString(filePath)) {
|
|
58
58
|
obj = (await fetch(filePath, { headers: { accept: 'application/json' } })).json();
|
|
59
59
|
}
|
|
60
60
|
else {
|
package/esm/index.js
CHANGED
|
@@ -7,7 +7,7 @@ export * from './data-type/mapped-type.interface.js';
|
|
|
7
7
|
export * from './data-type/union-type.interface.js';
|
|
8
8
|
export * from './resource/collection.interface.js';
|
|
9
9
|
export * from './resource/container.interface.js';
|
|
10
|
-
export * from './resource/
|
|
10
|
+
export * from './resource/operation.interface.js';
|
|
11
11
|
export * from './resource/resource.interface.js';
|
|
12
12
|
export * from './resource/singleton.interface.js';
|
|
13
13
|
export * from './resource/storage.interface.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.1",
|
|
4
4
|
"description": "Opra common package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,20 +49,20 @@
|
|
|
49
49
|
"lodash.omit": "^4.5.0",
|
|
50
50
|
"putil-isplainobject": "^1.1.5",
|
|
51
51
|
"putil-merge": "^3.10.3",
|
|
52
|
-
"putil-promisify": "^1.10.
|
|
52
|
+
"putil-promisify": "^1.10.1",
|
|
53
53
|
"putil-varhelpers": "^1.6.5",
|
|
54
54
|
"reflect-metadata": "^0.1.13",
|
|
55
55
|
"uid": "^2.0.1",
|
|
56
|
-
"valgen": "^4.0.0
|
|
56
|
+
"valgen": "^4.0.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@browsery/fs": "^0.4.0",
|
|
60
60
|
"@browsery/stream": "^0.5.0",
|
|
61
61
|
"@browsery/util": "^0.4.0",
|
|
62
62
|
"@types/encodeurl": "^1.0.0",
|
|
63
|
-
"@types/validator": "^13.
|
|
63
|
+
"@types/validator": "^13.11.1",
|
|
64
64
|
"path-browserify": "^1.0.1",
|
|
65
|
-
"ts-gems": "^2.4.
|
|
65
|
+
"ts-gems": "^2.4.1"
|
|
66
66
|
},
|
|
67
67
|
"engines": {
|
|
68
68
|
"node": ">=16.0",
|
|
@@ -12,6 +12,7 @@ export declare class ApiDocument {
|
|
|
12
12
|
protected _designCtorMap: Map<Function | Type<any>, string>;
|
|
13
13
|
protected _typeCache: ResponsiveMap<DataType>;
|
|
14
14
|
protected _typesCacheByCtor: Map<object | Type<any>, DataType>;
|
|
15
|
+
protected _metadataCache?: OpraSchema.ApiDocument;
|
|
15
16
|
url?: string;
|
|
16
17
|
info: OpraSchema.DocumentInfo;
|
|
17
18
|
references: ResponsiveMap<ApiDocument>;
|
|
@@ -91,6 +92,8 @@ export declare class ApiDocument {
|
|
|
91
92
|
/**
|
|
92
93
|
* Export as Opra schema definition object
|
|
93
94
|
*/
|
|
94
|
-
exportSchema(
|
|
95
|
+
exportSchema(options?: {
|
|
96
|
+
webSafe?: boolean;
|
|
97
|
+
}): OpraSchema.ApiDocument;
|
|
95
98
|
invalidate(): void;
|
|
96
99
|
}
|
|
@@ -6,13 +6,14 @@ import { OpraSchema } from '../../schema/index.js';
|
|
|
6
6
|
import type { ApiDocument } from '../api-document.js';
|
|
7
7
|
import { ApiField } from './api-field.js';
|
|
8
8
|
import { DataType } from './data-type.js';
|
|
9
|
+
import type { MappedType } from './mapped-type.js';
|
|
9
10
|
import type { UnionType } from './union-type.js';
|
|
10
11
|
/**
|
|
11
12
|
* @namespace ComplexType
|
|
12
13
|
*/
|
|
13
14
|
export declare namespace ComplexType {
|
|
14
15
|
interface InitArguments extends DataType.InitArguments, Pick<OpraSchema.ComplexType, 'ctor' | 'abstract' | 'additionalFields'> {
|
|
15
|
-
base?: ComplexType
|
|
16
|
+
base?: ComplexType;
|
|
16
17
|
}
|
|
17
18
|
interface OwnProperties extends Readonly<StrictOmit<OpraSchema.ComplexType, 'fields'>> {
|
|
18
19
|
fields: ResponsiveMap<ApiField>;
|
|
@@ -28,30 +29,24 @@ export declare namespace ComplexType {
|
|
|
28
29
|
* @class ComplexType
|
|
29
30
|
*/
|
|
30
31
|
declare class ComplexTypeClass extends DataType {
|
|
32
|
+
protected _decode: vg.Validator<any, any>;
|
|
33
|
+
protected _encode: vg.Validator<any, any>;
|
|
31
34
|
readonly kind = "ComplexType";
|
|
32
35
|
readonly ctor: Type;
|
|
33
|
-
readonly base?: ComplexType | UnionType;
|
|
36
|
+
readonly base?: ComplexType | UnionType | MappedType;
|
|
34
37
|
readonly own: ComplexType.OwnProperties;
|
|
35
38
|
readonly fields: ResponsiveMap<ApiField>;
|
|
36
39
|
readonly abstract?: boolean;
|
|
37
|
-
readonly additionalFields?: boolean | vg.Validator
|
|
38
|
-
protected _decoder?: vg.Validator<any, any>;
|
|
39
|
-
protected _encoder?: vg.Validator<any, any>;
|
|
40
|
+
readonly additionalFields?: boolean | vg.Validator | 'error';
|
|
40
41
|
constructor(document: ApiDocument, init: ComplexType.InitArguments);
|
|
41
42
|
addField(init: ApiField.InitArguments): ApiField;
|
|
42
43
|
findField(nameOrPath: string): ApiField | undefined;
|
|
43
44
|
getField(nameOrPath: string): ApiField;
|
|
44
45
|
iteratePath(path: string, silent?: boolean): IterableIterator<[string, ApiField | undefined, string]>;
|
|
45
|
-
normalizeFieldPath(
|
|
46
|
-
normalizeFieldPath(fieldPaths: string[]): string[];
|
|
46
|
+
normalizeFieldPath(fieldPaths: string | string[]): string[] | undefined;
|
|
47
47
|
exportSchema(): OpraSchema.ComplexType;
|
|
48
48
|
isTypeOf(t: Type | Function): boolean;
|
|
49
49
|
extendsFrom(t: string | Type | DataType): boolean;
|
|
50
|
-
decode(v: object): any;
|
|
51
|
-
encode(v: any): any;
|
|
52
|
-
validate(v: any): any;
|
|
53
|
-
protected _getDecoder(): vg.Validator<any, any>;
|
|
54
|
-
protected _getEncoder(): vg.Validator<any, any>;
|
|
55
50
|
}
|
|
56
51
|
/**
|
|
57
52
|
* Callable class pattern for ComplexType
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { RequiredSome, Type } from 'ts-gems';
|
|
2
|
-
import * as vg from 'valgen';
|
|
3
2
|
import { OpraSchema } from '../../schema/index.js';
|
|
4
3
|
import type { ApiDocument } from '../api-document.js';
|
|
5
4
|
import { nodeInspectCustom } from '../utils/inspect.util.js';
|
|
@@ -25,11 +24,6 @@ export declare abstract class DataType {
|
|
|
25
24
|
readonly description?: string;
|
|
26
25
|
readonly isAnonymous: boolean;
|
|
27
26
|
protected constructor(document: ApiDocument, init?: DataType.InitArguments);
|
|
28
|
-
decode(v: any): any;
|
|
29
|
-
encode(v: any): any;
|
|
30
|
-
validate(v: any): any;
|
|
31
|
-
protected abstract _getDecoder(): vg.Validator<any, any>;
|
|
32
|
-
protected abstract _getEncoder(): vg.Validator<any, any>;
|
|
33
27
|
exportSchema(): OpraSchema.DataType;
|
|
34
28
|
extendsFrom(type: string | Type | DataType): any;
|
|
35
29
|
toString(): string;
|
|
@@ -23,12 +23,10 @@ declare class EnumTypeClass extends DataType {
|
|
|
23
23
|
readonly meanings: Record<string, string>;
|
|
24
24
|
readonly ownValues: Record<string, string | number>;
|
|
25
25
|
readonly ownMeanings: Record<string, string>;
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
readonly decode: vg.Validator<any, any>;
|
|
27
|
+
readonly encode: vg.Validator<any, any>;
|
|
28
28
|
constructor(document: ApiDocument, init: EnumType.InitArguments);
|
|
29
29
|
exportSchema(): OpraSchema.EnumType;
|
|
30
|
-
protected _getDecoder(): vg.Validator<any, any>;
|
|
31
|
-
protected _getEncoder(): vg.Validator<any, any>;
|
|
32
30
|
}
|
|
33
31
|
export interface EnumTypeConstructor {
|
|
34
32
|
new (document: ApiDocument, init?: EnumType.InitArguments): EnumType;
|
|
@@ -29,16 +29,12 @@ declare class MappedTypeClass extends DataType {
|
|
|
29
29
|
readonly kind = "MappedType";
|
|
30
30
|
readonly own: MappedType.OwnProperties;
|
|
31
31
|
readonly type: ComplexType;
|
|
32
|
-
readonly additionalFields?: boolean | vg.Validator
|
|
32
|
+
readonly additionalFields?: boolean | vg.Validator | 'error';
|
|
33
33
|
readonly fields: ResponsiveMap<ApiField>;
|
|
34
34
|
readonly omit?: Field.Name[];
|
|
35
35
|
readonly pick?: Field.Name[];
|
|
36
|
-
protected _decoder: vg.Validator<any, any>;
|
|
37
|
-
protected _encoder: vg.Validator<any, any>;
|
|
38
36
|
constructor(document: ApiDocument, init: MappedType.InitArguments);
|
|
39
37
|
exportSchema(): OpraSchema.MappedType;
|
|
40
|
-
protected _getDecoder(): vg.Validator<any, any>;
|
|
41
|
-
protected _getEncoder(): vg.Validator<any, any>;
|
|
42
38
|
}
|
|
43
39
|
/**
|
|
44
40
|
* Type definition of MappedType prototype
|
|
@@ -26,12 +26,10 @@ export declare namespace SimpleType {
|
|
|
26
26
|
declare class SimpleTypeClass extends DataType {
|
|
27
27
|
readonly kind = "SimpleType";
|
|
28
28
|
readonly base?: SimpleType;
|
|
29
|
-
protected _decoder: vg.Validator<any, any>;
|
|
30
|
-
protected _encoder: vg.Validator<any, any>;
|
|
31
29
|
readonly own: SimpleType.OwnProperties;
|
|
30
|
+
readonly decode: vg.Validator<any, any>;
|
|
31
|
+
readonly encode: vg.Validator<any, any>;
|
|
32
32
|
constructor(document: ApiDocument, init: SimpleType.InitArguments);
|
|
33
|
-
protected _getDecoder(): vg.Validator<any, any>;
|
|
34
|
-
protected _getEncoder(): vg.Validator<any, any>;
|
|
35
33
|
exportSchema(): OpraSchema.SimpleType;
|
|
36
34
|
}
|
|
37
35
|
export interface SimpleTypeConstructor {
|
|
@@ -26,14 +26,10 @@ declare class UnionTypeClass extends DataType {
|
|
|
26
26
|
readonly kind = "UnionType";
|
|
27
27
|
readonly own: UnionType.OwnProperties;
|
|
28
28
|
readonly types: (ComplexType | UnionType | MappedType)[];
|
|
29
|
-
readonly additionalFields?: boolean;
|
|
29
|
+
readonly additionalFields?: boolean | vg.Validator | 'error';
|
|
30
30
|
readonly fields: ResponsiveMap<ApiField>;
|
|
31
|
-
protected _decoder: vg.Validator<any, any>;
|
|
32
|
-
protected _encoder: vg.Validator<any, any>;
|
|
33
31
|
constructor(document: ApiDocument, init: UnionType.InitArguments);
|
|
34
32
|
exportSchema(): OpraSchema.UnionType;
|
|
35
|
-
protected _getDecoder(): vg.Validator<any, any>;
|
|
36
|
-
protected _getEncoder(): vg.Validator<any, any>;
|
|
37
33
|
}
|
|
38
34
|
/**
|
|
39
35
|
* Type definition of UnionType constructor type
|
|
@@ -13,3 +13,5 @@ export * from './resource/resource.js';
|
|
|
13
13
|
export * from './resource/collection.js';
|
|
14
14
|
export * from './resource/singleton.js';
|
|
15
15
|
export * from './resource/storage.js';
|
|
16
|
+
export * from './interfaces/collection-resource.interface.js';
|
|
17
|
+
export * from './interfaces/singleton-resource.interface.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PartialOutput } from '../../types.js';
|
|
2
|
+
export interface CollectionResource<T> {
|
|
3
|
+
create?(...args: any[]): Promise<PartialOutput<T>>;
|
|
4
|
+
delete?(...args: any[]): Promise<number> | undefined;
|
|
5
|
+
deleteMany?(...args: any[]): Promise<number> | undefined;
|
|
6
|
+
findMany?(...args: any[]): Promise<PartialOutput<T>[] | undefined>;
|
|
7
|
+
get?(...args: any[]): Promise<PartialOutput<T> | undefined>;
|
|
8
|
+
update?(...args: any[]): Promise<PartialOutput<T> | undefined>;
|
|
9
|
+
updateMany?(...args: any[]): Promise<number> | undefined;
|
|
10
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PartialOutput } from '../../types.js';
|
|
2
|
+
export interface SingletonResource<T> {
|
|
3
|
+
create?(...args: any[]): Promise<PartialOutput<T>>;
|
|
4
|
+
delete?(...args: any[]): Promise<number> | undefined;
|
|
5
|
+
get?(...args: any[]): Promise<PartialOutput<T> | undefined>;
|
|
6
|
+
update?(...args: any[]): Promise<PartialOutput<T> | undefined>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Readable } from 'stream';
|
|
4
|
+
export interface StorageResource {
|
|
5
|
+
delete?(...args: any[]): Promise<number | undefined>;
|
|
6
|
+
get?(...args: any[]): Promise<Buffer | Readable | undefined>;
|
|
7
|
+
post?(...args: any[]): Promise<void>;
|
|
8
|
+
}
|
|
@@ -1,66 +1,72 @@
|
|
|
1
|
-
import { StrictOmit } from 'ts-gems';
|
|
1
|
+
import { StrictOmit, Type } from 'ts-gems';
|
|
2
|
+
import * as vg from 'valgen';
|
|
2
3
|
import { OpraFilter } from '../../filter/index.js';
|
|
3
4
|
import { OpraSchema } from '../../schema/index.js';
|
|
4
5
|
import type { TypeThunkAsync } from '../../types.js';
|
|
5
6
|
import type { ApiDocument } from '../api-document.js';
|
|
6
|
-
import
|
|
7
|
+
import { ComplexType } from '../data-type/complex-type.js';
|
|
7
8
|
import { Resource } from './resource.js';
|
|
8
9
|
export declare namespace Collection {
|
|
9
|
-
|
|
10
|
+
interface InitArguments extends Resource.InitArguments, StrictOmit<OpraSchema.Collection, 'kind' | 'type'> {
|
|
10
11
|
type: ComplexType;
|
|
11
|
-
operations: Operations;
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
interface DecoratorOptions<T = any> extends Resource.DecoratorOptions {
|
|
14
|
+
primaryKey?: keyof T | (keyof T)[];
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
+
interface Metadata extends StrictOmit<OpraSchema.Collection, 'type'> {
|
|
16
17
|
name: string;
|
|
17
18
|
type: TypeThunkAsync | string;
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
handlerName?: string;
|
|
20
|
+
namespace Create {
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
create?: OpraSchema.Collection.CreateOperation & Operation;
|
|
24
|
-
delete?: OpraSchema.Collection.DeleteOperation & Operation;
|
|
25
|
-
get?: OpraSchema.Collection.GetOperation & Operation;
|
|
26
|
-
update?: OpraSchema.Collection.UpdateOperation & Operation;
|
|
27
|
-
deleteMany?: OpraSchema.Collection.DeleteManyOperation & Operation;
|
|
28
|
-
findMany?: OpraSchema.Collection.FindManyOperation & Operation;
|
|
29
|
-
updateMany?: OpraSchema.Collection.UpdateManyOperation & Operation;
|
|
22
|
+
namespace Delete {
|
|
30
23
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
24
|
+
namespace DeleteMany {
|
|
25
|
+
}
|
|
26
|
+
namespace FindMany {
|
|
27
|
+
}
|
|
28
|
+
namespace Get {
|
|
29
|
+
}
|
|
30
|
+
namespace Update {
|
|
31
|
+
}
|
|
32
|
+
namespace UpdateMany {
|
|
33
|
+
}
|
|
34
|
+
type CreateOperationOptions = OpraSchema.Collection.CreateOperation;
|
|
35
|
+
type DeleteOperationOptions = OpraSchema.Collection.DeleteOperation;
|
|
36
|
+
type DeleteManyOperationOptions = OpraSchema.Collection.DeleteManyOperation;
|
|
37
|
+
type FindManyOperationOptions = OpraSchema.Collection.FindManyOperation;
|
|
38
|
+
type GetOperationOptions = OpraSchema.Collection.GetOperation;
|
|
39
|
+
type UpdateOperationOptions = OpraSchema.Collection.UpdateOperation;
|
|
40
|
+
type UpdateManyOperationOptions = OpraSchema.Collection.UpdateManyOperation;
|
|
39
41
|
}
|
|
40
42
|
declare class CollectionClass extends Resource {
|
|
43
|
+
private _decoders;
|
|
44
|
+
private _encoders;
|
|
41
45
|
readonly type: ComplexType;
|
|
42
46
|
readonly kind = "Collection";
|
|
43
|
-
readonly operations: Collection.Operations;
|
|
47
|
+
readonly operations: OpraSchema.Collection.Operations;
|
|
44
48
|
readonly controller?: object;
|
|
45
49
|
readonly primaryKey: string[];
|
|
46
50
|
constructor(document: ApiDocument, init: Collection.InitArguments);
|
|
47
51
|
exportSchema(this: Collection): OpraSchema.Collection;
|
|
48
52
|
parseKeyValue(this: Collection, value: any): any;
|
|
49
|
-
normalizeFieldPath(this: Collection, path: string | string[]): string |
|
|
50
|
-
normalizeSortFields(this: Collection, fields: string | string[]): string |
|
|
53
|
+
normalizeFieldPath(this: Collection, path: string | string[]): string[] | undefined;
|
|
54
|
+
normalizeSortFields(this: Collection, fields: string | string[]): string[] | undefined;
|
|
51
55
|
normalizeFilter(filter: string | OpraFilter.Expression): OpraFilter.Expression | undefined;
|
|
56
|
+
getDecoder(operation: keyof OpraSchema.Collection.Operations): vg.Validator<any, any>;
|
|
57
|
+
getEncoder(operation: keyof OpraSchema.Collection.Operations): vg.Validator<any, any>;
|
|
52
58
|
}
|
|
53
59
|
export interface CollectionConstructor {
|
|
54
60
|
prototype: Collection;
|
|
55
61
|
new (document: ApiDocument, init: Collection.InitArguments): Collection;
|
|
56
|
-
(type:
|
|
57
|
-
Create: (options?: Collection.CreateOperationOptions) =>
|
|
58
|
-
Delete: (options?: Collection.DeleteOperationOptions) =>
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
FindMany: (options?: Collection.FindManyOperationOptions) =>
|
|
62
|
-
|
|
63
|
-
UpdateMany: (options?: Collection.UpdateManyOperationOptions) =>
|
|
62
|
+
<T>(type: Type<T> | string, options?: Collection.DecoratorOptions<T>): ClassDecorator;
|
|
63
|
+
Create: (options?: Collection.CreateOperationOptions) => ((target: Object, propertyKey: 'create') => void);
|
|
64
|
+
Delete: (options?: Collection.DeleteOperationOptions) => ((target: Object, propertyKey: 'delete') => void);
|
|
65
|
+
DeleteMany: (options?: Collection.DeleteManyOperationOptions) => ((target: Object, propertyKey: 'deleteMany') => void);
|
|
66
|
+
Get: (options?: Collection.GetOperationOptions) => ((target: Object, propertyKey: 'get') => void);
|
|
67
|
+
FindMany: (options?: Collection.FindManyOperationOptions) => ((target: Object, propertyKey: 'findMany') => void);
|
|
68
|
+
Update: (options?: Collection.UpdateOperationOptions) => ((target: Object, propertyKey: 'update') => void);
|
|
69
|
+
UpdateMany: (options?: Collection.UpdateManyOperationOptions) => ((target: Object, propertyKey: 'updateMany') => void);
|
|
64
70
|
}
|
|
65
71
|
export interface Collection extends CollectionClass {
|
|
66
72
|
}
|