@opra/common 0.16.1 → 0.17.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/document/data-type/complex-type.js +69 -56
- package/cjs/document/data-type/simple-type.js +0 -1
- package/cjs/document/resource/collection.js +15 -16
- package/cjs/document/resource/singleton.js +2 -2
- package/cjs/http/http-params.js +10 -11
- package/esm/document/api-document.js +33 -37
- package/esm/document/constants.js +3 -6
- package/esm/document/data-type/api-field.js +12 -15
- package/esm/document/data-type/builtin/any.type.js +5 -8
- package/esm/document/data-type/builtin/base64.type.js +5 -8
- package/esm/document/data-type/builtin/bigint.type.js +5 -8
- package/esm/document/data-type/builtin/boolean.type.js +8 -11
- package/esm/document/data-type/builtin/date.type.js +7 -10
- package/esm/document/data-type/builtin/guid.type.js +9 -12
- package/esm/document/data-type/builtin/index.js +10 -13
- package/esm/document/data-type/builtin/integer.type.js +10 -13
- package/esm/document/data-type/builtin/number.type.js +7 -10
- package/esm/document/data-type/builtin/object.type.js +5 -8
- package/esm/document/data-type/builtin/string.type.js +8 -11
- package/esm/document/data-type/builtin/time.type.js +7 -10
- package/esm/document/data-type/builtin/timestamp.type.js +9 -12
- package/esm/document/data-type/complex-type.js +94 -85
- package/esm/document/data-type/data-type.js +9 -12
- package/esm/document/data-type/enum-type.js +15 -19
- package/esm/document/data-type/mapped-type.js +24 -29
- package/esm/document/data-type/simple-type.js +17 -22
- package/esm/document/data-type/union-type.js +26 -29
- package/esm/document/factory/add-references.js +3 -7
- package/esm/document/factory/create-document.js +10 -16
- package/esm/document/factory/factory.js +33 -37
- package/esm/document/factory/import-resource-class.js +16 -22
- package/esm/document/factory/import-type-class.js +24 -34
- package/esm/document/factory/index.js +1 -4
- package/esm/document/factory/process-resources.js +10 -16
- package/esm/document/factory/process-types.js +31 -37
- package/esm/document/index.js +14 -17
- package/esm/document/resource/collection.js +58 -63
- package/esm/document/resource/resource.js +9 -12
- package/esm/document/resource/singleton.js +27 -31
- package/esm/document/utils/inspect.util.js +4 -7
- package/esm/document/utils/string-compare.util.js +1 -5
- package/esm/exception/enums/issue-severity.enum.js +2 -5
- package/esm/exception/error-issue.js +1 -2
- package/esm/exception/http-errors/bad-request.error.js +4 -8
- package/esm/exception/http-errors/failed-dependency.error.js +4 -8
- package/esm/exception/http-errors/forbidden.error.js +4 -8
- package/esm/exception/http-errors/internal-server.error.js +4 -8
- package/esm/exception/http-errors/method-not-allowed.error.js +4 -8
- package/esm/exception/http-errors/not-acceptable.error.js +4 -8
- package/esm/exception/http-errors/not-found.error.js +4 -8
- package/esm/exception/http-errors/unauthorized.error.js +4 -8
- package/esm/exception/http-errors/unprocessable-entity.error.js +4 -8
- package/esm/exception/index.js +15 -18
- package/esm/exception/opra-exception.js +3 -7
- package/esm/exception/resource-errors/resource-conflict.error.js +4 -8
- package/esm/exception/resource-errors/resource-not-found.error.js +4 -8
- package/esm/exception/wrap-exception.js +20 -24
- package/esm/filter/antlr/OpraFilterLexer.js +6 -9
- package/esm/filter/antlr/OpraFilterListener.js +2 -5
- package/esm/filter/antlr/OpraFilterParser.js +79 -126
- package/esm/filter/antlr/OpraFilterVisitor.js +2 -5
- package/esm/filter/ast/abstract/ast.js +1 -5
- package/esm/filter/ast/abstract/expression.js +2 -6
- package/esm/filter/ast/abstract/literal.js +2 -6
- package/esm/filter/ast/abstract/term.js +2 -6
- package/esm/filter/ast/expressions/arithmetic-expression.js +3 -8
- package/esm/filter/ast/expressions/array-expression.js +2 -6
- package/esm/filter/ast/expressions/comparison-expression.js +2 -6
- package/esm/filter/ast/expressions/logical-expression.js +2 -6
- package/esm/filter/ast/expressions/parentheses-expression.js +2 -6
- package/esm/filter/ast/index.js +16 -19
- package/esm/filter/ast/terms/boolean-literal.js +2 -6
- package/esm/filter/ast/terms/date-literal.js +8 -12
- package/esm/filter/ast/terms/external-constant.js +2 -6
- package/esm/filter/ast/terms/null-literal.js +2 -6
- package/esm/filter/ast/terms/number-literal.js +4 -8
- package/esm/filter/ast/terms/qualified-identifier.js +2 -6
- package/esm/filter/ast/terms/string-literal.js +4 -8
- package/esm/filter/ast/terms/time-literal.js +6 -10
- package/esm/filter/build.js +45 -69
- package/esm/filter/errors.js +3 -9
- package/esm/filter/filter-tree-visitor.js +26 -31
- package/esm/filter/index.js +5 -8
- package/esm/filter/opra-error-listener.js +4 -8
- package/esm/filter/parse.js +14 -19
- package/esm/filter/utils.js +2 -7
- package/esm/helpers/function-utils.js +8 -14
- package/esm/helpers/get-stack-filename.js +1 -5
- package/esm/helpers/index.js +8 -11
- package/esm/helpers/is-url.js +1 -5
- package/esm/helpers/mixin-utils.js +2 -7
- package/esm/helpers/object-utils.js +6 -12
- package/esm/helpers/path-to-object-tree.js +1 -5
- package/esm/helpers/responsive-map.js +1 -5
- package/esm/helpers/type-guards.js +7 -17
- package/esm/http/codecs/boolean-codec.js +1 -5
- package/esm/http/codecs/date-codec.js +1 -5
- package/esm/http/codecs/filter-codec.js +5 -9
- package/esm/http/codecs/integer-codec.js +2 -6
- package/esm/http/codecs/number-codec.js +1 -5
- package/esm/http/codecs/string-codec.js +1 -5
- package/esm/http/enums/http-headers-codes.enum.js +2 -5
- package/esm/http/enums/http-status-codes.enum.js +2 -5
- package/esm/http/enums/http-status-messages.js +1 -4
- package/esm/http/http-headers.js +5 -9
- package/esm/http/http-message.host.js +13 -18
- package/esm/http/http-params.js +30 -36
- package/esm/http/http-request-message.js +18 -22
- package/esm/http/http-response-message.js +23 -28
- package/esm/http/index.js +14 -17
- package/esm/http/interfaces/client-http-headers.interface.js +1 -2
- package/esm/http/interfaces/cookie-options.interface.js +1 -2
- package/esm/http/interfaces/server-http-headers.interface.js +1 -2
- package/esm/i18n/i18n.js +23 -28
- package/esm/i18n/index.js +5 -9
- package/esm/i18n/string-utils.js +2 -7
- package/esm/i18n/translate.js +3 -7
- package/esm/index.js +11 -16
- package/esm/schema/constants.js +1 -4
- package/esm/schema/data-type/complex-type.interface.js +2 -5
- package/esm/schema/data-type/data-type.interface.js +1 -2
- package/esm/schema/data-type/enum-type.interface.js +2 -5
- package/esm/schema/data-type/field.interface.js +1 -2
- package/esm/schema/data-type/mapped-type.interface.js +2 -5
- package/esm/schema/data-type/simple-type.interface.js +2 -5
- package/esm/schema/data-type/union-type.interface.js +2 -5
- package/esm/schema/document.interface.js +1 -2
- package/esm/schema/index.js +31 -34
- package/esm/schema/resource/collection.interface.js +2 -5
- package/esm/schema/resource/container.interface.js +2 -5
- package/esm/schema/resource/endpoint.interface.js +1 -2
- package/esm/schema/resource/resource.interface.js +1 -2
- package/esm/schema/resource/singleton.interface.js +2 -5
- package/esm/schema/type-guards.js +40 -53
- package/esm/types.js +1 -2
- package/esm/url/index.js +5 -8
- package/esm/url/opra-url-path-component.js +3 -7
- package/esm/url/opra-url-path.js +14 -18
- package/esm/url/opra-url.js +15 -19
- package/esm/url/utils/decode-path-component.js +4 -8
- package/esm/url/utils/encode-path-component.js +3 -8
- package/esm/utils/path-utils.js +2 -7
- package/package.json +1 -1
- package/types/document/data-type/complex-type.d.ts +8 -2
- package/types/document/resource/collection.d.ts +5 -3
- package/types/document/resource/singleton.d.ts +3 -1
- package/types/filter/ast/terms/qualified-identifier.d.ts +4 -0
- package/types/http/http-params.d.ts +20 -19
package/esm/http/http-headers.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var _a;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const http_headers_codes_enum_js_1 = require("./enums/http-headers-codes.enum.js");
|
|
7
|
-
const knownKeys = Object.values(http_headers_codes_enum_js_1.HttpHeaderCodes);
|
|
2
|
+
import { ResponsiveMap } from '../helpers/index.js';
|
|
3
|
+
import { HttpHeaderCodes } from './enums/http-headers-codes.enum.js';
|
|
4
|
+
const knownKeys = Object.values(HttpHeaderCodes);
|
|
8
5
|
const knownKeysLower = knownKeys.map(x => x.toLowerCase());
|
|
9
6
|
const nodeInspectCustom = Symbol.for('nodejs.util.inspect.custom');
|
|
10
7
|
const kEntries = Symbol('kEntries');
|
|
@@ -13,9 +10,9 @@ const kOptions = Symbol('kOptions');
|
|
|
13
10
|
*
|
|
14
11
|
* @class HttpHeaders
|
|
15
12
|
*/
|
|
16
|
-
class HttpHeaders {
|
|
13
|
+
export class HttpHeaders {
|
|
17
14
|
constructor(init, options) {
|
|
18
|
-
this[_a] = new
|
|
15
|
+
this[_a] = new ResponsiveMap();
|
|
19
16
|
this[kOptions] = { ...options, onChange: undefined };
|
|
20
17
|
if (init) {
|
|
21
18
|
if (typeof init === 'string')
|
|
@@ -201,7 +198,6 @@ class HttpHeaders {
|
|
|
201
198
|
this[kOptions].onChange();
|
|
202
199
|
}
|
|
203
200
|
}
|
|
204
|
-
exports.HttpHeaders = HttpHeaders;
|
|
205
201
|
HttpHeaders.kEntries = kEntries;
|
|
206
202
|
HttpHeaders.kOptions = kOptions;
|
|
207
203
|
HttpHeaders.NON_DELIMITED_HEADERS = {
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const http_parser_js_1 = require("http-parser-js");
|
|
6
|
-
const stream_1 = tslib_1.__importDefault(require("stream"));
|
|
7
|
-
const http_headers_js_1 = require("./http-headers.js");
|
|
1
|
+
import { HTTPParser } from 'http-parser-js';
|
|
2
|
+
import stream from 'stream';
|
|
3
|
+
import { HttpHeaders } from './http-headers.js';
|
|
8
4
|
const kHeaders = Symbol('kHeaders');
|
|
9
5
|
const kHeadersProxy = Symbol('kHeadersProxy');
|
|
10
6
|
const kTrailers = Symbol('kTrailers');
|
|
@@ -15,14 +11,14 @@ const kOnBodyChunk = Symbol('kOnBodyChunk');
|
|
|
15
11
|
const kOnReadComplete = Symbol('kOnReadComplete');
|
|
16
12
|
const crlfBuffer = Buffer.from('\r\n');
|
|
17
13
|
const HTTP_VERSION_PATTERN = /^(\d)\.(\d)$/;
|
|
18
|
-
class HttpMessageHost {
|
|
14
|
+
export class HttpMessageHost {
|
|
19
15
|
constructor() {
|
|
20
16
|
this.complete = false;
|
|
21
|
-
|
|
22
|
-
this[kHeaders] = new
|
|
17
|
+
stream.Duplex.apply(this);
|
|
18
|
+
this[kHeaders] = new HttpHeaders(undefined, {
|
|
23
19
|
onChange: () => this._headersChanged = true
|
|
24
20
|
});
|
|
25
|
-
this[kTrailers] = new
|
|
21
|
+
this[kTrailers] = new HttpHeaders(undefined, {
|
|
26
22
|
onChange: () => this._trailersChanged = true
|
|
27
23
|
});
|
|
28
24
|
}
|
|
@@ -148,11 +144,11 @@ class HttpMessageHost {
|
|
|
148
144
|
this.body = args.body;
|
|
149
145
|
}
|
|
150
146
|
_parseBuffer(buf, parserType) {
|
|
151
|
-
const parser = new
|
|
152
|
-
parser[
|
|
153
|
-
parser[
|
|
154
|
-
parser[
|
|
155
|
-
parser[
|
|
147
|
+
const parser = new HTTPParser(parserType);
|
|
148
|
+
parser[HTTPParser.kOnHeadersComplete] = this[kOnHeaderReceived].bind(this);
|
|
149
|
+
parser[HTTPParser.kOnBody] = this[kOnBodyChunk].bind(this);
|
|
150
|
+
parser[HTTPParser.kOnHeaders] = this[kOnTrailersReceived].bind(this);
|
|
151
|
+
parser[HTTPParser.kOnMessageComplete] = this[kOnReadComplete].bind(this);
|
|
156
152
|
const buffer = Buffer.from(buf);
|
|
157
153
|
let x = parser.execute(buffer);
|
|
158
154
|
if (typeof x === 'object')
|
|
@@ -238,7 +234,6 @@ class HttpMessageHost {
|
|
|
238
234
|
}
|
|
239
235
|
}
|
|
240
236
|
}
|
|
241
|
-
exports.HttpMessageHost = HttpMessageHost;
|
|
242
237
|
HttpMessageHost.kHeaders = kHeaders;
|
|
243
238
|
HttpMessageHost.kHeadersProxy = kHeadersProxy;
|
|
244
239
|
HttpMessageHost.kTrailers = kTrailers;
|
|
@@ -248,4 +243,4 @@ HttpMessageHost.kOnTrailersReceived = kOnTrailersReceived;
|
|
|
248
243
|
HttpMessageHost.kOnBodyChunk = kOnBodyChunk;
|
|
249
244
|
HttpMessageHost.kOnReadComplete = kOnReadComplete;
|
|
250
245
|
// Mixin with Duplex
|
|
251
|
-
Object.assign(HttpMessageHost.prototype,
|
|
246
|
+
Object.assign(HttpMessageHost.prototype, stream.Duplex.prototype);
|
package/esm/http/http-params.js
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var _a, _b, _c;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const number_codec_js_1 = require("./codecs/number-codec.js");
|
|
12
|
-
const string_codec_js_1 = require("./codecs/string-codec.js");
|
|
2
|
+
import { splitString, tokenize } from 'fast-tokenizer';
|
|
3
|
+
import { ResponsiveMap } from '../helpers/index.js';
|
|
4
|
+
import { BooleanCodec } from './codecs/boolean-codec.js';
|
|
5
|
+
import { DateCodec } from './codecs/date-codec.js';
|
|
6
|
+
import { FilterCodec } from './codecs/filter-codec.js';
|
|
7
|
+
import { IntegerCodec } from './codecs/integer-codec.js';
|
|
8
|
+
import { NumberCodec } from './codecs/number-codec.js';
|
|
9
|
+
import { StringCodec } from './codecs/string-codec.js';
|
|
13
10
|
const kEntries = Symbol('kEntries');
|
|
14
11
|
const kSize = Symbol('kSize');
|
|
15
12
|
const kParamDefs = Symbol('kParamDefs');
|
|
16
13
|
const kOptions = Symbol('kOptions');
|
|
17
|
-
class HttpParams {
|
|
14
|
+
export class HttpParams {
|
|
18
15
|
constructor(init, options) {
|
|
19
|
-
this[_a] = new
|
|
16
|
+
this[_a] = new ResponsiveMap();
|
|
20
17
|
this[_b] = 0;
|
|
21
18
|
this[_c] = new Map();
|
|
22
19
|
this[kOptions] = { ...options, onChange: undefined };
|
|
@@ -45,11 +42,11 @@ class HttpParams {
|
|
|
45
42
|
input = input.substring(1);
|
|
46
43
|
if (!input)
|
|
47
44
|
return this;
|
|
48
|
-
const tokenizer =
|
|
45
|
+
const tokenizer = tokenize(input, { delimiters: '&', quotes: true, brackets: true });
|
|
49
46
|
for (const token of tokenizer) {
|
|
50
47
|
if (!token)
|
|
51
48
|
continue;
|
|
52
|
-
const itemTokenizer =
|
|
49
|
+
const itemTokenizer = tokenize(token, {
|
|
53
50
|
delimiters: '=',
|
|
54
51
|
quotes: true,
|
|
55
52
|
brackets: true
|
|
@@ -191,7 +188,7 @@ class HttpParams {
|
|
|
191
188
|
get(target, p, receiver) {
|
|
192
189
|
if (typeof p === 'string') {
|
|
193
190
|
const v = _this[kEntries].get(p);
|
|
194
|
-
return v ? (v.length > 1 ? v : v[0]) :
|
|
191
|
+
return v ? (v.length > 1 ? v : v[0]) : null;
|
|
195
192
|
}
|
|
196
193
|
return Reflect.get(target, p, receiver);
|
|
197
194
|
},
|
|
@@ -236,14 +233,14 @@ class HttpParams {
|
|
|
236
233
|
? value.map((v) => fn(v)).join(prmDef.arrayDelimiter || ',')
|
|
237
234
|
: fn(value);
|
|
238
235
|
}
|
|
239
|
-
return encodeURIParam(value);
|
|
236
|
+
return encodeURIParam(String(value));
|
|
240
237
|
}
|
|
241
238
|
decodeValue(value, key) {
|
|
242
239
|
const prmDef = this[kParamDefs].get(key);
|
|
243
240
|
let val = value;
|
|
244
241
|
if (prmDef) {
|
|
245
242
|
if (prmDef.array) {
|
|
246
|
-
val =
|
|
243
|
+
val = splitString(value, {
|
|
247
244
|
delimiters: prmDef.arrayDelimiter || ',',
|
|
248
245
|
brackets: true,
|
|
249
246
|
quotes: true,
|
|
@@ -268,6 +265,12 @@ class HttpParams {
|
|
|
268
265
|
}
|
|
269
266
|
return decodeURIComponent(value);
|
|
270
267
|
}
|
|
268
|
+
[(_a = kEntries, _b = kSize, _c = kParamDefs, Symbol.iterator)]() {
|
|
269
|
+
return this.entries();
|
|
270
|
+
}
|
|
271
|
+
get [Symbol.toStringTag]() {
|
|
272
|
+
return 'HttpParams';
|
|
273
|
+
}
|
|
271
274
|
_append(name, value) {
|
|
272
275
|
let values = this[kEntries].get(name);
|
|
273
276
|
if (!values) {
|
|
@@ -283,8 +286,7 @@ class HttpParams {
|
|
|
283
286
|
return false;
|
|
284
287
|
const oldSize = this[kSize];
|
|
285
288
|
if (value) {
|
|
286
|
-
const
|
|
287
|
-
const newValues = oldValues.filter(x => !valueToDelete.includes(x));
|
|
289
|
+
const newValues = oldValues.filter(x => x === value);
|
|
288
290
|
this[kEntries].set(name, newValues);
|
|
289
291
|
this[kSize] += -oldValues.length + newValues.length;
|
|
290
292
|
}
|
|
@@ -295,7 +297,7 @@ class HttpParams {
|
|
|
295
297
|
return oldSize !== this[kSize];
|
|
296
298
|
}
|
|
297
299
|
_set(name, value, index) {
|
|
298
|
-
if (value
|
|
300
|
+
if (value === undefined) {
|
|
299
301
|
this._delete(name);
|
|
300
302
|
return;
|
|
301
303
|
}
|
|
@@ -314,25 +316,18 @@ class HttpParams {
|
|
|
314
316
|
values[Math.min(index, values.length)] = value;
|
|
315
317
|
this[kSize] += -oldLen + values.length;
|
|
316
318
|
}
|
|
317
|
-
[(_a = kEntries, _b = kSize, _c = kParamDefs, Symbol.iterator)]() {
|
|
318
|
-
return this.entries();
|
|
319
|
-
}
|
|
320
|
-
get [Symbol.toStringTag]() {
|
|
321
|
-
return 'HttpParams';
|
|
322
|
-
}
|
|
323
319
|
}
|
|
324
|
-
exports.HttpParams = HttpParams;
|
|
325
320
|
HttpParams.kEntries = kEntries;
|
|
326
321
|
HttpParams.kSize = kSize;
|
|
327
322
|
HttpParams.kParamDefs = kParamDefs;
|
|
328
323
|
HttpParams.kOptions = kOptions;
|
|
329
324
|
HttpParams.codecs = {
|
|
330
|
-
'boolean': new
|
|
331
|
-
'date': new
|
|
332
|
-
'filter': new
|
|
333
|
-
'integer': new
|
|
334
|
-
'number': new
|
|
335
|
-
'string': new
|
|
325
|
+
'boolean': new BooleanCodec(),
|
|
326
|
+
'date': new DateCodec(),
|
|
327
|
+
'filter': new FilterCodec(),
|
|
328
|
+
'integer': new IntegerCodec(),
|
|
329
|
+
'number': new NumberCodec(),
|
|
330
|
+
'string': new StringCodec()
|
|
336
331
|
};
|
|
337
332
|
/**
|
|
338
333
|
* Encode input string with standard encodeURIComponent and then un-encode specific characters.
|
|
@@ -348,7 +343,6 @@ const ENCODING_REPLACEMENTS = {
|
|
|
348
343
|
'3F': '?',
|
|
349
344
|
'40': '@'
|
|
350
345
|
};
|
|
351
|
-
function encodeURIParam(v) {
|
|
346
|
+
export function encodeURIParam(v) {
|
|
352
347
|
return encodeURIComponent(v).replace(ENCODING_REGEX, (s, t) => ENCODING_REPLACEMENTS[t] ?? s);
|
|
353
348
|
}
|
|
354
|
-
exports.encodeURIParam = encodeURIParam;
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const http_parser_js_1 = require("http-parser-js");
|
|
7
|
-
const type_is_1 = tslib_1.__importDefault(require("type-is"));
|
|
8
|
-
const http_message_host_js_1 = require("./http-message.host.js");
|
|
9
|
-
const http_params_js_1 = require("./http-params.js");
|
|
1
|
+
import accepts from 'accepts';
|
|
2
|
+
import { HTTPParser } from 'http-parser-js';
|
|
3
|
+
import typeIs from 'type-is';
|
|
4
|
+
import { HttpMessageHost } from './http-message.host.js';
|
|
5
|
+
import { HttpParams } from './http-params.js';
|
|
10
6
|
const HTTP_VERSION_PATTERN = /^(\d)\.(\d)$/;
|
|
11
|
-
var HttpRequestMessage;
|
|
7
|
+
export var HttpRequestMessage;
|
|
12
8
|
(function (HttpRequestMessage) {
|
|
13
9
|
function create(init) {
|
|
14
10
|
return HttpRequestMessageHost.create(init);
|
|
@@ -22,19 +18,19 @@ var HttpRequestMessage;
|
|
|
22
18
|
return HttpRequestMessageHost.fromStream(readable);
|
|
23
19
|
}
|
|
24
20
|
HttpRequestMessage.fromStream = fromStream;
|
|
25
|
-
})(HttpRequestMessage
|
|
21
|
+
})(HttpRequestMessage || (HttpRequestMessage = {}));
|
|
26
22
|
const kQuery = Symbol('kQuery');
|
|
27
23
|
const kQueryProxy = Symbol('kQueryProxy');
|
|
28
24
|
const kProtocol = Symbol('kProtocol');
|
|
29
25
|
/**
|
|
30
26
|
*
|
|
31
27
|
*/
|
|
32
|
-
class HttpRequestMessageHost extends
|
|
28
|
+
class HttpRequestMessageHost extends HttpMessageHost {
|
|
33
29
|
constructor() {
|
|
34
30
|
super();
|
|
35
31
|
this.httpVersionMajor = 1;
|
|
36
32
|
this.httpVersionMinor = 0;
|
|
37
|
-
this[kQuery] = new
|
|
33
|
+
this[kQuery] = new HttpParams();
|
|
38
34
|
this[kQueryProxy] = this[kQuery].getProxy();
|
|
39
35
|
}
|
|
40
36
|
get httpVersion() {
|
|
@@ -95,22 +91,22 @@ class HttpRequestMessageHost extends http_message_host_js_1.HttpMessageHost {
|
|
|
95
91
|
return this.getHeader(name);
|
|
96
92
|
}
|
|
97
93
|
accepts(...type) {
|
|
98
|
-
const accept = (
|
|
94
|
+
const accept = accepts(this);
|
|
99
95
|
// eslint-disable-next-line prefer-spread
|
|
100
96
|
return accept.types.apply(accept, type);
|
|
101
97
|
}
|
|
102
98
|
acceptsCharsets(...charset) {
|
|
103
|
-
const accept = (
|
|
99
|
+
const accept = accepts(this);
|
|
104
100
|
// eslint-disable-next-line prefer-spread
|
|
105
101
|
return accept.charsets.apply(accept, charset);
|
|
106
102
|
}
|
|
107
103
|
acceptsEncodings(...encoding) {
|
|
108
|
-
const accept = (
|
|
104
|
+
const accept = accepts(this);
|
|
109
105
|
// eslint-disable-next-line prefer-spread
|
|
110
106
|
return accept.encodings.apply(accept, encoding);
|
|
111
107
|
}
|
|
112
108
|
acceptsLanguages(...lang) {
|
|
113
|
-
const accept = (
|
|
109
|
+
const accept = accepts(this);
|
|
114
110
|
// eslint-disable-next-line prefer-spread
|
|
115
111
|
return accept.languages.apply(accept, lang);
|
|
116
112
|
}
|
|
@@ -119,7 +115,7 @@ class HttpRequestMessageHost extends http_message_host_js_1.HttpMessageHost {
|
|
|
119
115
|
if (otherTypes.length)
|
|
120
116
|
types.push(...otherTypes);
|
|
121
117
|
const contentType = this.getHeader('content-type');
|
|
122
|
-
return contentType ?
|
|
118
|
+
return contentType ? typeIs.is(contentType, types) : null;
|
|
123
119
|
}
|
|
124
120
|
_init(init) {
|
|
125
121
|
super._init(init);
|
|
@@ -128,9 +124,9 @@ class HttpRequestMessageHost extends http_message_host_js_1.HttpMessageHost {
|
|
|
128
124
|
this.baseUrl = init.baseUrl || this.url;
|
|
129
125
|
this.protocol = init.protocol;
|
|
130
126
|
}
|
|
131
|
-
[
|
|
132
|
-
super[
|
|
133
|
-
this.method =
|
|
127
|
+
[HttpMessageHost.kOnHeaderReceived](info) {
|
|
128
|
+
super[HttpMessageHost.kOnHeaderReceived](info);
|
|
129
|
+
this.method = HTTPParser.methods[info.method];
|
|
134
130
|
this.url = info.url;
|
|
135
131
|
this.baseUrl = info.url;
|
|
136
132
|
}
|
|
@@ -141,7 +137,7 @@ class HttpRequestMessageHost extends http_message_host_js_1.HttpMessageHost {
|
|
|
141
137
|
}
|
|
142
138
|
static fromBuffer(buffer) {
|
|
143
139
|
const msg = new HttpRequestMessageHost();
|
|
144
|
-
msg._parseBuffer(buffer,
|
|
140
|
+
msg._parseBuffer(buffer, HTTPParser.REQUEST);
|
|
145
141
|
return msg;
|
|
146
142
|
}
|
|
147
143
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const mime_types_1 = tslib_1.__importDefault(require("mime-types"));
|
|
11
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
-
const http_status_messages_js_1 = require("./enums/http-status-messages.js");
|
|
13
|
-
const http_message_host_js_1 = require("./http-message.host.js");
|
|
1
|
+
import contentDisposition from 'content-disposition';
|
|
2
|
+
import cookie from 'cookie';
|
|
3
|
+
import cookieSignature from 'cookie-signature';
|
|
4
|
+
import encodeUrl from 'encodeurl';
|
|
5
|
+
import { HTTPParser } from 'http-parser-js';
|
|
6
|
+
import mime from 'mime-types';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import { HttpStatusMessages } from './enums/http-status-messages.js';
|
|
9
|
+
import { HttpMessageHost } from './http-message.host.js';
|
|
14
10
|
/**
|
|
15
11
|
* @namespace HttpResponseMessage
|
|
16
12
|
*/
|
|
17
|
-
var HttpResponseMessage;
|
|
13
|
+
export var HttpResponseMessage;
|
|
18
14
|
(function (HttpResponseMessage) {
|
|
19
15
|
function create(init) {
|
|
20
16
|
return HttpResponseMessageHost.create(init);
|
|
@@ -28,11 +24,11 @@ var HttpResponseMessage;
|
|
|
28
24
|
return HttpResponseMessageHost.fromStream(readable);
|
|
29
25
|
}
|
|
30
26
|
HttpResponseMessage.fromStream = fromStream;
|
|
31
|
-
})(HttpResponseMessage
|
|
27
|
+
})(HttpResponseMessage || (HttpResponseMessage = {}));
|
|
32
28
|
/**
|
|
33
29
|
* @class HttpResponseMessageHost
|
|
34
30
|
*/
|
|
35
|
-
class HttpResponseMessageHost extends
|
|
31
|
+
export class HttpResponseMessageHost extends HttpMessageHost {
|
|
36
32
|
constructor() {
|
|
37
33
|
super();
|
|
38
34
|
}
|
|
@@ -40,7 +36,7 @@ class HttpResponseMessageHost extends http_message_host_js_1.HttpMessageHost {
|
|
|
40
36
|
return this.set(arg0, arg1);
|
|
41
37
|
}
|
|
42
38
|
append(name, value) {
|
|
43
|
-
this[
|
|
39
|
+
this[HttpMessageHost.kHeaders].append(name, value);
|
|
44
40
|
return this;
|
|
45
41
|
}
|
|
46
42
|
/**
|
|
@@ -48,8 +44,8 @@ class HttpResponseMessageHost extends http_message_host_js_1.HttpMessageHost {
|
|
|
48
44
|
*/
|
|
49
45
|
attachment(filename) {
|
|
50
46
|
if (filename)
|
|
51
|
-
this.type(
|
|
52
|
-
this.set('Content-Disposition', (
|
|
47
|
+
this.type(path.extname(filename));
|
|
48
|
+
this.set('Content-Disposition', contentDisposition(filename));
|
|
53
49
|
return this;
|
|
54
50
|
}
|
|
55
51
|
/**
|
|
@@ -72,7 +68,7 @@ class HttpResponseMessageHost extends http_message_host_js_1.HttpMessageHost {
|
|
|
72
68
|
*/
|
|
73
69
|
type(type) {
|
|
74
70
|
const ct = type.indexOf('/') === -1
|
|
75
|
-
?
|
|
71
|
+
? mime.lookup(type)
|
|
76
72
|
: type;
|
|
77
73
|
if (ct)
|
|
78
74
|
this.set('Content-Type', ct);
|
|
@@ -107,7 +103,7 @@ class HttpResponseMessageHost extends http_message_host_js_1.HttpMessageHost {
|
|
|
107
103
|
? 'j:' + JSON.stringify(value)
|
|
108
104
|
: String(value);
|
|
109
105
|
if (signed)
|
|
110
|
-
val = 's:' +
|
|
106
|
+
val = 's:' + cookieSignature.sign(val, secret);
|
|
111
107
|
if (opts.maxAge != null) {
|
|
112
108
|
const maxAge = opts.maxAge - 0;
|
|
113
109
|
if (!isNaN(maxAge)) {
|
|
@@ -123,7 +119,7 @@ class HttpResponseMessageHost extends http_message_host_js_1.HttpMessageHost {
|
|
|
123
119
|
a = a.filter(x => !x.startsWith(name + '='));
|
|
124
120
|
this.set('Set-Cookie', a);
|
|
125
121
|
}
|
|
126
|
-
this.append('Set-Cookie',
|
|
122
|
+
this.append('Set-Cookie', cookie.serialize(name, String(val), opts));
|
|
127
123
|
return this;
|
|
128
124
|
}
|
|
129
125
|
/**
|
|
@@ -182,7 +178,7 @@ class HttpResponseMessageHost extends http_message_host_js_1.HttpMessageHost {
|
|
|
182
178
|
if (url === 'back')
|
|
183
179
|
loc = this.req?.get('Referrer') || '/';
|
|
184
180
|
// set location
|
|
185
|
-
return this.set('Location', (
|
|
181
|
+
return this.set('Location', encodeUrl(loc));
|
|
186
182
|
}
|
|
187
183
|
/**
|
|
188
184
|
* Set status `code`.
|
|
@@ -203,7 +199,7 @@ class HttpResponseMessageHost extends http_message_host_js_1.HttpMessageHost {
|
|
|
203
199
|
* res.sendStatus(500); // equivalent to res.status(500).send('Internal Server Error')
|
|
204
200
|
*/
|
|
205
201
|
sendStatus(statusCode) {
|
|
206
|
-
const body =
|
|
202
|
+
const body = HttpStatusMessages[statusCode] || String(statusCode);
|
|
207
203
|
this.statusCode = statusCode;
|
|
208
204
|
this.type('txt');
|
|
209
205
|
return this.send(body);
|
|
@@ -215,8 +211,8 @@ class HttpResponseMessageHost extends http_message_host_js_1.HttpMessageHost {
|
|
|
215
211
|
this.req = init?.req;
|
|
216
212
|
this.chunkedEncoding = init?.chunkedEncoding;
|
|
217
213
|
}
|
|
218
|
-
[
|
|
219
|
-
super[
|
|
214
|
+
[HttpMessageHost.kOnHeaderReceived](info) {
|
|
215
|
+
super[HttpMessageHost.kOnHeaderReceived](info);
|
|
220
216
|
this.statusCode = info.statusCode;
|
|
221
217
|
this.statusMessage = info.statusMessage;
|
|
222
218
|
}
|
|
@@ -227,7 +223,7 @@ class HttpResponseMessageHost extends http_message_host_js_1.HttpMessageHost {
|
|
|
227
223
|
}
|
|
228
224
|
static fromBuffer(buffer) {
|
|
229
225
|
const msg = new HttpResponseMessageHost();
|
|
230
|
-
msg._parseBuffer(buffer,
|
|
226
|
+
msg._parseBuffer(buffer, HTTPParser.RESPONSE);
|
|
231
227
|
return msg;
|
|
232
228
|
}
|
|
233
229
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -235,4 +231,3 @@ class HttpResponseMessageHost extends http_message_host_js_1.HttpMessageHost {
|
|
|
235
231
|
throw new Error('fromStream is not implemented yet');
|
|
236
232
|
}
|
|
237
233
|
}
|
|
238
|
-
exports.HttpResponseMessageHost = HttpResponseMessageHost;
|
package/esm/http/index.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
tslib_1.__exportStar(require("./codecs/integer-codec.js"), exports);
|
|
16
|
-
tslib_1.__exportStar(require("./codecs/number-codec.js"), exports);
|
|
17
|
-
tslib_1.__exportStar(require("./codecs/string-codec.js"), exports);
|
|
1
|
+
export * from './http-headers.js';
|
|
2
|
+
export * from './http-params.js';
|
|
3
|
+
export * from './http-response-message.js';
|
|
4
|
+
export * from './http-request-message.js';
|
|
5
|
+
export * from './enums/http-headers-codes.enum.js';
|
|
6
|
+
export * from './enums/http-status-codes.enum.js';
|
|
7
|
+
export * from './interfaces/client-http-headers.interface.js';
|
|
8
|
+
export * from './interfaces/server-http-headers.interface.js';
|
|
9
|
+
export * from './codecs/date-codec.js';
|
|
10
|
+
export * from './codecs/boolean-codec.js';
|
|
11
|
+
export * from './codecs/filter-codec.js';
|
|
12
|
+
export * from './codecs/integer-codec.js';
|
|
13
|
+
export * from './codecs/number-codec.js';
|
|
14
|
+
export * from './codecs/string-codec.js';
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/esm/i18n/i18n.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
9
|
-
const index_js_1 = require("../helpers/index.js");
|
|
10
|
-
const string_utils_js_1 = require("./string-utils.js");
|
|
11
|
-
exports.BaseI18n = Object.getPrototypeOf(i18next_1.default).constructor;
|
|
1
|
+
import { splitString, tokenize } from 'fast-tokenizer';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import i18next from 'i18next';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { isUrl } from '../helpers/index.js';
|
|
6
|
+
import { unescapeString } from './string-utils.js';
|
|
7
|
+
export const BaseI18n = Object.getPrototypeOf(i18next).constructor;
|
|
12
8
|
const globalLocaleDirs = [];
|
|
13
|
-
class I18n extends
|
|
9
|
+
export class I18n extends BaseI18n {
|
|
14
10
|
async init(arg0, arg1) {
|
|
15
11
|
const options = typeof arg0 === 'object' ? arg0 : {};
|
|
16
12
|
const callback = typeof arg0 === 'function' ? arg0 : arg1;
|
|
@@ -58,11 +54,11 @@ class I18n extends exports.BaseI18n {
|
|
|
58
54
|
}
|
|
59
55
|
async loadResourceBundle(lang, ns, filePath, deep, overwrite) {
|
|
60
56
|
let obj;
|
|
61
|
-
if (
|
|
57
|
+
if (isUrl(filePath)) {
|
|
62
58
|
obj = (await fetch(filePath, { headers: { accept: 'application/json' } })).json();
|
|
63
59
|
}
|
|
64
60
|
else {
|
|
65
|
-
const content =
|
|
61
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
66
62
|
obj = JSON.parse(content);
|
|
67
63
|
}
|
|
68
64
|
this.addResourceBundle(lang, ns, obj, deep, overwrite);
|
|
@@ -70,18 +66,18 @@ class I18n extends exports.BaseI18n {
|
|
|
70
66
|
async loadResourceDir(dirnames, deep, overwrite) {
|
|
71
67
|
for (const dirname of Array.isArray(dirnames) ? dirnames : [dirnames]) {
|
|
72
68
|
/* istanbul ignore next */
|
|
73
|
-
if (!(
|
|
69
|
+
if (!(fs.existsSync(dirname)))
|
|
74
70
|
continue;
|
|
75
|
-
const languageDirs =
|
|
71
|
+
const languageDirs = fs.readdirSync(dirname);
|
|
76
72
|
for (const lang of languageDirs) {
|
|
77
|
-
const langDir =
|
|
78
|
-
if ((
|
|
79
|
-
const nsDirs =
|
|
73
|
+
const langDir = path.join(dirname, lang);
|
|
74
|
+
if ((fs.statSync(langDir)).isDirectory()) {
|
|
75
|
+
const nsDirs = fs.readdirSync(langDir);
|
|
80
76
|
for (const nsfile of nsDirs) {
|
|
81
|
-
const nsFilePath =
|
|
82
|
-
const ext =
|
|
83
|
-
if (ext === '.json' && (
|
|
84
|
-
const ns =
|
|
77
|
+
const nsFilePath = path.join(langDir, nsfile);
|
|
78
|
+
const ext = path.extname(nsfile);
|
|
79
|
+
if (ext === '.json' && (fs.statSync(nsFilePath)).isFile()) {
|
|
80
|
+
const ns = path.basename(nsfile, ext);
|
|
85
81
|
await this.loadResourceBundle(lang, ns, nsFilePath, deep, overwrite);
|
|
86
82
|
}
|
|
87
83
|
}
|
|
@@ -104,7 +100,7 @@ class I18n extends exports.BaseI18n {
|
|
|
104
100
|
return objectStack.get(input);
|
|
105
101
|
if (typeof input === 'string') {
|
|
106
102
|
let s = '';
|
|
107
|
-
for (let token of
|
|
103
|
+
for (let token of tokenize(input, {
|
|
108
104
|
brackets: { '$t(': ')' },
|
|
109
105
|
quotes: true,
|
|
110
106
|
keepQuotes: true,
|
|
@@ -113,12 +109,12 @@ class I18n extends exports.BaseI18n {
|
|
|
113
109
|
})) {
|
|
114
110
|
if (token.startsWith('$t(') && token.endsWith(')')) {
|
|
115
111
|
token = token.substring(3, token.length - 1);
|
|
116
|
-
const a =
|
|
117
|
-
const fallback =
|
|
112
|
+
const a = splitString(token, { delimiters: '?', quotes: true, brackets: { '{': '}' } });
|
|
113
|
+
const fallback = unescapeString(token.substring((a[0] || '').length + 1));
|
|
118
114
|
token = a[0] || '';
|
|
119
115
|
const keys = [];
|
|
120
116
|
let opts = null;
|
|
121
|
-
for (const token2 of
|
|
117
|
+
for (const token2 of tokenize(token, { delimiters: ',', quotes: true, brackets: { '{': '}' } })) {
|
|
122
118
|
if (token2.startsWith('{')) {
|
|
123
119
|
opts = JSON.parse(token2);
|
|
124
120
|
continue;
|
|
@@ -167,5 +163,4 @@ class I18n extends exports.BaseI18n {
|
|
|
167
163
|
return defaultInstance;
|
|
168
164
|
}
|
|
169
165
|
}
|
|
170
|
-
exports.I18n = I18n;
|
|
171
166
|
const defaultInstance = I18n.createInstance();
|
package/esm/i18n/index.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const i18n_js_1 = require("./i18n.js");
|
|
6
|
-
tslib_1.__exportStar(require("./i18n.js"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./translate.js"), exports);
|
|
8
|
-
const i18n = i18n_js_1.I18n.createInstance();
|
|
9
|
-
exports.i18n = i18n;
|
|
1
|
+
import { I18n } from './i18n.js';
|
|
2
|
+
export * from './i18n.js';
|
|
3
|
+
export * from './translate.js';
|
|
4
|
+
const i18n = I18n.createInstance();
|
|
10
5
|
i18n.init().catch(() => void 0);
|
|
6
|
+
export { i18n };
|