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