@opra/common 1.0.0-alpha.3 → 1.0.0-alpha.30
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 +6036 -5788
- package/cjs/document/api-document.js +12 -0
- package/cjs/document/common/api-base.js +1 -0
- package/cjs/document/common/document-element.js +5 -1
- package/cjs/document/data-type/api-field.js +12 -6
- package/cjs/document/data-type/complex-type-base.js +10 -3
- package/cjs/document/data-type/complex-type.js +6 -2
- package/cjs/document/data-type/data-type.js +2 -1
- package/cjs/document/data-type/enum-type.js +5 -2
- package/cjs/document/data-type/extended-types/base64.type.js +4 -0
- package/cjs/document/data-type/extended-types/date-string.type.js +6 -2
- package/cjs/document/data-type/extended-types/date-time-string.type.js +6 -2
- package/cjs/document/data-type/extended-types/date-time.type.js +6 -2
- package/cjs/document/data-type/extended-types/date.type.js +6 -2
- package/cjs/document/data-type/extended-types/email.type.js +6 -2
- package/cjs/document/data-type/extended-types/field-path.type.js +5 -3
- package/cjs/document/data-type/extended-types/filter.type.js +19 -17
- package/cjs/document/data-type/extended-types/object-id.type.js +4 -0
- package/cjs/document/data-type/extended-types/time.type.js +6 -2
- package/cjs/document/data-type/extended-types/url.type.js +6 -2
- package/cjs/document/data-type/extended-types/uuid.type.js +4 -0
- package/cjs/document/data-type/mapped-type.js +12 -5
- package/cjs/document/data-type/mixin-type.js +5 -1
- package/cjs/document/data-type/omit-type.js +7 -2
- package/cjs/document/data-type/partial-type.js +7 -2
- package/cjs/document/data-type/pick-type.js +1 -2
- package/cjs/document/data-type/primitive-types/bigint.type.js +4 -0
- package/cjs/document/data-type/primitive-types/boolean.type.js +4 -0
- package/cjs/document/data-type/primitive-types/integer.type.js +4 -0
- package/cjs/document/data-type/primitive-types/null.type.js +4 -0
- package/cjs/document/data-type/primitive-types/number.type.js +4 -0
- package/cjs/document/data-type/primitive-types/object.type.js +0 -3
- package/cjs/document/data-type/primitive-types/string.type.js +4 -0
- package/cjs/document/data-type/required-type.js +1 -2
- package/cjs/document/data-type/simple-type.js +17 -16
- package/cjs/document/data-type/utils/create-mapped-class.js +3 -3
- package/cjs/document/data-type/utils/get-is-inherited-predicate-fn.js +1 -2
- package/cjs/document/decorators/api-field-decorator.js +4 -6
- package/cjs/document/decorators/complex-type.decorator.js +1 -2
- package/cjs/document/decorators/http-controller.decorator.js +26 -2
- package/cjs/document/decorators/http-operation-entity.decorator.js +123 -93
- package/cjs/document/decorators/http-operation.decorator.js +12 -6
- package/cjs/document/decorators/simple-type.decorator.js +2 -3
- package/cjs/document/factory/api-document.factory.js +14 -11
- package/cjs/document/factory/data-type.factory.js +97 -56
- package/cjs/document/factory/http-api.factory.js +3 -1
- package/cjs/document/http/http-api.js +2 -2
- package/cjs/document/http/http-controller.js +26 -14
- package/cjs/document/http/http-media-type.js +21 -4
- package/cjs/document/http/http-operation-response.js +2 -1
- package/cjs/document/http/http-operation.js +28 -4
- package/cjs/document/http/http-parameter.js +4 -0
- package/cjs/document/http/http-status-range.js +6 -4
- package/cjs/document/index.js +5 -5
- package/cjs/document/utils/parse-regexp.util.js +1 -2
- package/cjs/document/utils/string-compare.util.js +1 -2
- package/cjs/exception/index.js +5 -5
- package/cjs/exception/opra-exception.js +1 -0
- package/cjs/filter/antlr/OpraFilterParser.js +28 -82
- package/cjs/filter/ast/index.js +1 -1
- package/cjs/filter/build.js +22 -25
- package/cjs/filter/filter-rules.js +4 -2
- package/cjs/filter/opra-filter.ns.js +2 -2
- package/cjs/filter/parse.js +2 -5
- package/cjs/filter/utils.js +2 -3
- package/cjs/helpers/function-utils.js +1 -2
- package/cjs/helpers/get-stack-filename.js +2 -3
- package/cjs/helpers/mixin-utils.js +4 -4
- package/cjs/helpers/monkey-patches.js +4 -2
- package/cjs/helpers/object-utils.js +5 -6
- package/cjs/helpers/parse-fields-projection.js +4 -6
- package/cjs/helpers/responsive-map.js +5 -4
- package/cjs/helpers/type-guards.js +10 -11
- package/cjs/i18n/i18n.js +4 -3
- package/cjs/i18n/index.js +1 -1
- package/cjs/i18n/string-utils.js +2 -3
- package/cjs/i18n/translate.js +1 -2
- package/cjs/index.js +1 -1
- package/cjs/schema/type-guards.js +7 -8
- package/esm/document/api-document.js +11 -0
- package/esm/document/common/api-base.js +1 -0
- package/esm/document/common/document-element.js +4 -1
- package/esm/document/data-type/api-field.js +12 -6
- package/esm/document/data-type/complex-type-base.js +10 -3
- package/esm/document/data-type/complex-type.js +6 -2
- package/esm/document/data-type/data-type.js +2 -1
- package/esm/document/data-type/enum-type.js +5 -2
- package/esm/document/data-type/extended-types/base64.type.js +4 -0
- package/esm/document/data-type/extended-types/date-string.type.js +6 -2
- package/esm/document/data-type/extended-types/date-time-string.type.js +6 -2
- package/esm/document/data-type/extended-types/date-time.type.js +6 -2
- package/esm/document/data-type/extended-types/date.type.js +6 -2
- package/esm/document/data-type/extended-types/email.type.js +6 -2
- package/esm/document/data-type/extended-types/field-path.type.js +5 -3
- package/esm/document/data-type/extended-types/filter.type.js +19 -17
- package/esm/document/data-type/extended-types/object-id.type.js +4 -0
- package/esm/document/data-type/extended-types/time.type.js +6 -2
- package/esm/document/data-type/extended-types/url.type.js +6 -2
- package/esm/document/data-type/extended-types/uuid.type.js +4 -0
- package/esm/document/data-type/mapped-type.js +12 -5
- package/esm/document/data-type/mixin-type.js +5 -1
- package/esm/document/data-type/omit-type.js +6 -0
- package/esm/document/data-type/partial-type.js +6 -0
- package/esm/document/data-type/primitive-types/bigint.type.js +4 -0
- package/esm/document/data-type/primitive-types/boolean.type.js +4 -0
- package/esm/document/data-type/primitive-types/integer.type.js +4 -0
- package/esm/document/data-type/primitive-types/null.type.js +4 -0
- package/esm/document/data-type/primitive-types/number.type.js +4 -0
- package/esm/document/data-type/primitive-types/object.type.js +0 -3
- package/esm/document/data-type/primitive-types/string.type.js +4 -0
- package/esm/document/data-type/simple-type.js +17 -16
- package/esm/document/data-type/utils/create-mapped-class.js +2 -1
- package/esm/document/decorators/api-field-decorator.js +1 -2
- package/esm/document/decorators/http-controller.decorator.js +25 -0
- package/esm/document/decorators/http-operation-entity.decorator.js +80 -50
- package/esm/document/decorators/http-operation.decorator.js +11 -4
- package/esm/document/factory/api-document.factory.js +14 -10
- package/esm/document/factory/data-type.factory.js +97 -56
- package/esm/document/factory/http-api.factory.js +3 -1
- package/esm/document/http/http-api.js +2 -2
- package/esm/document/http/http-controller.js +25 -14
- package/esm/document/http/http-media-type.js +20 -4
- package/esm/document/http/http-operation-response.js +2 -1
- package/esm/document/http/http-operation.js +27 -4
- package/esm/document/http/http-parameter.js +4 -0
- package/esm/document/http/http-status-range.js +6 -4
- package/esm/document/index.js +5 -5
- package/esm/exception/index.js +5 -5
- package/esm/exception/opra-exception.js +1 -0
- package/esm/filter/antlr/OpraFilterParser.js +28 -82
- package/esm/filter/ast/index.js +1 -1
- package/esm/filter/build.js +1 -3
- package/esm/filter/filter-rules.js +4 -2
- package/esm/filter/opra-filter.ns.js +2 -2
- package/esm/filter/parse.js +1 -3
- package/esm/helpers/mixin-utils.js +2 -1
- package/esm/helpers/monkey-patches.js +4 -2
- package/esm/helpers/object-utils.js +2 -2
- package/esm/helpers/parse-fields-projection.js +1 -3
- package/esm/helpers/responsive-map.js +5 -4
- package/esm/i18n/i18n.js +4 -3
- package/esm/i18n/index.js +1 -1
- package/esm/index.js +1 -1
- package/package.json +11 -8
- package/types/document/api-document.d.ts +1 -0
- package/types/document/common/document-element.d.ts +1 -0
- package/types/document/data-type/api-field.d.ts +12 -0
- package/types/document/data-type/complex-type-base.d.ts +1 -1
- package/types/document/data-type/complex-type.d.ts +1 -1
- package/types/document/data-type/data-type.d.ts +5 -2
- package/types/document/data-type/enum-type.d.ts +2 -2
- package/types/document/data-type/mapped-type.d.ts +3 -3
- package/types/document/data-type/mixin-type.d.ts +2 -2
- package/types/document/data-type/omit-type.d.ts +0 -6
- package/types/document/data-type/partial-type.d.ts +0 -6
- package/types/document/data-type/pick-type.d.ts +2 -2
- package/types/document/data-type/required-type.d.ts +7 -7
- package/types/document/data-type/simple-type.d.ts +4 -2
- package/types/document/decorators/http-controller.decorator.d.ts +1 -0
- package/types/document/decorators/http-operation-entity.decorator.d.ts +1 -0
- package/types/document/factory/data-type.factory.d.ts +5 -0
- package/types/document/http/http-controller.d.ts +1 -0
- package/types/document/http/http-media-type.d.ts +2 -1
- package/types/document/http/http-operation.d.ts +5 -3
- package/types/document/http/http-parameter.d.ts +3 -2
- package/types/document/http/http-status-range.d.ts +2 -1
- package/types/document/index.d.ts +5 -5
- package/types/exception/index.d.ts +5 -5
- package/types/filter/ast/index.d.ts +1 -1
- package/types/filter/opra-filter.ns.d.ts +2 -2
- package/types/helpers/type-guards.d.ts +0 -2
- package/types/i18n/i18n.d.ts +21 -19
- package/types/index.d.ts +1 -1
- package/types/schema/data-type/data-type.interface.d.ts +1 -1
- package/types/schema/data-type/mapped-type.interface.d.ts +2 -2
- package/types/schema/data-type/simple-type.interface.d.ts +4 -0
- package/types/schema/data-type-container.interface.d.ts +1 -1
- package/types/schema/document.interface.d.ts +1 -1
- package/types/schema/http/http-controller.interface.d.ts +2 -2
- package/types/schema/http/http-media-type.interface.d.ts +1 -1
- package/types/schema/http/http-operation-response.interface.d.ts +2 -2
- package/types/schema/http/http-operation.interface.d.ts +8 -4
- package/types/schema/http/http-parameter.interface.d.ts +5 -1
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.mergePrototype = mergePrototype;
|
|
4
|
+
exports.inheritPropertyInitializers = inheritPropertyInitializers;
|
|
4
5
|
function mergePrototype(targetProto, baseProto, filter) {
|
|
5
6
|
for (const k of Object.getOwnPropertyNames(baseProto)) {
|
|
6
|
-
if (k === 'constructor' || k === '__proto__' || k === 'toJSON' || k === 'toString' || (filter && !filter(k)))
|
|
7
|
+
if (k === 'constructor' || k === '__proto__' || k === 'toJSON' || k === 'toString' || (filter && !filter(k))) {
|
|
7
8
|
continue;
|
|
9
|
+
}
|
|
8
10
|
Object.defineProperty(targetProto, k, Object.getOwnPropertyDescriptor(baseProto, k) || Object.create(null));
|
|
9
11
|
}
|
|
10
12
|
}
|
|
11
|
-
exports.mergePrototype = mergePrototype;
|
|
12
13
|
// noinspection JSUnusedLocalSymbols
|
|
13
14
|
function inheritPropertyInitializers(target, clazz,
|
|
14
15
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -27,4 +28,3 @@ isPropertyInherited = (key) => true) {
|
|
|
27
28
|
//
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
|
-
exports.inheritPropertyInitializers = inheritPropertyInitializers;
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
/** monkey patch (hijack)
|
|
3
3
|
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#use_within_json
|
|
4
4
|
*/
|
|
5
|
-
if (!BigInt.prototype.toJSON)
|
|
5
|
+
if (!BigInt.prototype.toJSON) {
|
|
6
6
|
BigInt.prototype.toJSON = function () {
|
|
7
7
|
return this.toString();
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
}
|
|
10
|
+
if (!RegExp.prototype.toJSON) {
|
|
10
11
|
RegExp.prototype.toJSON = function () {
|
|
11
12
|
return this.toString();
|
|
12
13
|
};
|
|
14
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.cloneObject = cloneObject;
|
|
4
|
+
exports.omitUndefined = omitUndefined;
|
|
5
|
+
exports.omitNullish = omitNullish;
|
|
4
6
|
const tslib_1 = require("tslib");
|
|
5
7
|
const putil_isplainobject_1 = tslib_1.__importDefault(require("putil-isplainobject"));
|
|
6
8
|
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
@@ -8,14 +10,13 @@ const constants_js_1 = require("../document/constants.js");
|
|
|
8
10
|
function cloneObject(obj, jsonOnly) {
|
|
9
11
|
return (0, putil_merge_1.default)({}, obj, {
|
|
10
12
|
deep: v => (0, putil_isplainobject_1.default)(v) && !v[constants_js_1.DATATYPE_METADATA],
|
|
13
|
+
descriptor: true,
|
|
11
14
|
filter: (source, key) => {
|
|
12
15
|
const v = source[key];
|
|
13
|
-
return (
|
|
14
|
-
(typeof v !== 'function' && (typeof v !== 'object' || (0, putil_isplainobject_1.default)(v) || Array.isArray(v))));
|
|
16
|
+
return !jsonOnly || (typeof v !== 'function' && (typeof v !== 'object' || (0, putil_isplainobject_1.default)(v) || Array.isArray(v)));
|
|
15
17
|
},
|
|
16
18
|
});
|
|
17
19
|
}
|
|
18
|
-
exports.cloneObject = cloneObject;
|
|
19
20
|
function omitUndefined(obj, recursive) {
|
|
20
21
|
if (!(obj && typeof obj === 'object'))
|
|
21
22
|
return obj;
|
|
@@ -27,7 +28,6 @@ function omitUndefined(obj, recursive) {
|
|
|
27
28
|
}
|
|
28
29
|
return obj;
|
|
29
30
|
}
|
|
30
|
-
exports.omitUndefined = omitUndefined;
|
|
31
31
|
function omitNullish(obj, recursive) {
|
|
32
32
|
if (!(obj && typeof obj === 'object'))
|
|
33
33
|
return obj;
|
|
@@ -39,4 +39,3 @@ function omitNullish(obj, recursive) {
|
|
|
39
39
|
}
|
|
40
40
|
return obj;
|
|
41
41
|
}
|
|
42
|
-
exports.omitNullish = omitNullish;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.FieldsProjection = void 0;
|
|
4
|
+
exports.parseFieldsProjection = parseFieldsProjection;
|
|
5
|
+
exports.parse = parse;
|
|
4
6
|
const fast_tokenizer_1 = require("fast-tokenizer");
|
|
5
7
|
const FIELD_PATTERN = /^([+-])?([a-z_$]\w*)$/i;
|
|
6
8
|
const NO_DOT_BRACKET_PATTERN = /[^.]\(/g;
|
|
@@ -24,12 +26,9 @@ function parseFieldsProjection(projection, keepCase) {
|
|
|
24
26
|
}
|
|
25
27
|
return out;
|
|
26
28
|
}
|
|
27
|
-
exports.parseFieldsProjection = parseFieldsProjection;
|
|
28
29
|
function parse(input, target) {
|
|
29
30
|
/** Add dot before brackets which is required to split fields */
|
|
30
|
-
input = input.replace(NO_DOT_BRACKET_PATTERN, s =>
|
|
31
|
-
return s.charAt(0) + '.' + s.substring(1);
|
|
32
|
-
});
|
|
31
|
+
input = input.replace(NO_DOT_BRACKET_PATTERN, s => s.charAt(0) + '.' + s.substring(1));
|
|
33
32
|
const fields = (0, fast_tokenizer_1.splitString)(input, {
|
|
34
33
|
delimiters: '.',
|
|
35
34
|
brackets: true,
|
|
@@ -64,4 +63,3 @@ function parse(input, target) {
|
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
65
|
}
|
|
67
|
-
exports.parse = parse;
|
|
@@ -41,13 +41,14 @@ class ResponsiveMap {
|
|
|
41
41
|
},
|
|
42
42
|
enumerable: false,
|
|
43
43
|
});
|
|
44
|
-
if (options?.wellKnownKeys)
|
|
44
|
+
if (options?.wellKnownKeys) {
|
|
45
45
|
options.wellKnownKeys.forEach(k => {
|
|
46
46
|
if (caseSensitive)
|
|
47
47
|
this[kWellKnownKeys][k] = k;
|
|
48
48
|
else
|
|
49
49
|
this[kWellKnownKeys][k.toLowerCase()] = k;
|
|
50
50
|
});
|
|
51
|
+
}
|
|
51
52
|
this.clear();
|
|
52
53
|
if (init)
|
|
53
54
|
this.setAll(init);
|
|
@@ -73,12 +74,12 @@ class ResponsiveMap {
|
|
|
73
74
|
has(key) {
|
|
74
75
|
if (!key)
|
|
75
76
|
return false;
|
|
76
|
-
return this[kEntries]
|
|
77
|
+
return Object.prototype.hasOwnProperty.call(this[kEntries], this._getStoringKey(key));
|
|
77
78
|
}
|
|
78
79
|
set(key, value) {
|
|
79
80
|
const storeKey = this._getStoringKey(key);
|
|
80
81
|
key = this._getOriginalKey(key);
|
|
81
|
-
const exists = this[kEntries]
|
|
82
|
+
const exists = Object.prototype.hasOwnProperty.call(this[kEntries], storeKey);
|
|
82
83
|
this[kEntries][storeKey] = value;
|
|
83
84
|
if (!exists)
|
|
84
85
|
this[kSize]++;
|
|
@@ -103,7 +104,7 @@ class ResponsiveMap {
|
|
|
103
104
|
}
|
|
104
105
|
delete(key) {
|
|
105
106
|
const storeKey = this._getStoringKey(key);
|
|
106
|
-
const exists = this[kEntries]
|
|
107
|
+
const exists = Object.prototype.hasOwnProperty.call(this[kEntries], storeKey);
|
|
107
108
|
delete this[kEntries][storeKey];
|
|
108
109
|
delete this[kKeyMap][storeKey];
|
|
109
110
|
if (!exists)
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isConstructor = isConstructor;
|
|
4
|
+
exports.isStream = isStream;
|
|
5
|
+
exports.isReadable = isReadable;
|
|
6
|
+
exports.isWritable = isWritable;
|
|
7
|
+
exports.isReadableStream = isReadableStream;
|
|
8
|
+
exports.isBlob = isBlob;
|
|
9
|
+
exports.isFormData = isFormData;
|
|
10
|
+
exports.isURL = isURL;
|
|
11
|
+
exports.isIterable = isIterable;
|
|
12
|
+
exports.isAsyncIterable = isAsyncIterable;
|
|
4
13
|
function isConstructor(fn) {
|
|
5
14
|
return (typeof fn === 'function' &&
|
|
6
15
|
fn.prototype &&
|
|
@@ -8,26 +17,21 @@ function isConstructor(fn) {
|
|
|
8
17
|
fn.prototype.constructor.name !== 'Function' &&
|
|
9
18
|
fn.prototype.constructor.name !== 'embedded');
|
|
10
19
|
}
|
|
11
|
-
exports.isConstructor = isConstructor;
|
|
12
20
|
function isStream(x) {
|
|
13
21
|
return x !== null && typeof x === 'object' && typeof x.pipe === 'function';
|
|
14
22
|
}
|
|
15
|
-
exports.isStream = isStream;
|
|
16
23
|
function isReadable(x) {
|
|
17
24
|
return isStream(x) && typeof x._read === 'function' && typeof x._readableState === 'object';
|
|
18
25
|
}
|
|
19
|
-
exports.isReadable = isReadable;
|
|
20
26
|
function isWritable(x) {
|
|
21
27
|
return isStream(x) && typeof x._write === 'function';
|
|
22
28
|
}
|
|
23
|
-
exports.isWritable = isWritable;
|
|
24
29
|
function isReadableStream(x) {
|
|
25
30
|
return (isStream(x) &&
|
|
26
31
|
typeof x.getReader === 'function' &&
|
|
27
32
|
typeof x.pipeThrough === 'function' &&
|
|
28
33
|
typeof x.pipeTo === 'function');
|
|
29
34
|
}
|
|
30
|
-
exports.isReadableStream = isReadableStream;
|
|
31
35
|
function isBlob(x) {
|
|
32
36
|
return (x !== null &&
|
|
33
37
|
typeof x === 'object' &&
|
|
@@ -35,7 +39,6 @@ function isBlob(x) {
|
|
|
35
39
|
typeof x.arrayBuffer === 'function' &&
|
|
36
40
|
typeof x.stream === 'function');
|
|
37
41
|
}
|
|
38
|
-
exports.isBlob = isBlob;
|
|
39
42
|
function isFormData(x) {
|
|
40
43
|
return (x !== null &&
|
|
41
44
|
typeof x.constructor === 'function' &&
|
|
@@ -43,16 +46,12 @@ function isFormData(x) {
|
|
|
43
46
|
typeof x.append === 'function' &&
|
|
44
47
|
typeof x.getAll === 'function');
|
|
45
48
|
}
|
|
46
|
-
exports.isFormData = isFormData;
|
|
47
49
|
function isURL(x) {
|
|
48
50
|
return x !== null && typeof x == 'object' && typeof x.host === 'string' && typeof x.href === 'string';
|
|
49
51
|
}
|
|
50
|
-
exports.isURL = isURL;
|
|
51
52
|
function isIterable(x) {
|
|
52
53
|
return Symbol.iterator in x;
|
|
53
54
|
}
|
|
54
|
-
exports.isIterable = isIterable;
|
|
55
55
|
function isAsyncIterable(x) {
|
|
56
56
|
return Symbol.asyncIterator in x;
|
|
57
57
|
}
|
|
58
|
-
exports.isAsyncIterable = isAsyncIterable;
|
package/cjs/i18n/i18n.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.I18n = exports.BaseI18n = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const fast_tokenizer_1 = require("fast-tokenizer");
|
|
6
5
|
const i18next_1 = tslib_1.__importDefault(require("@browsery/i18next"));
|
|
6
|
+
const fast_tokenizer_1 = require("fast-tokenizer");
|
|
7
7
|
const string_utils_js_1 = require("./string-utils.js");
|
|
8
8
|
exports.BaseI18n = Object.getPrototypeOf(i18next_1.default.createInstance()).constructor;
|
|
9
9
|
class I18n extends exports.BaseI18n {
|
|
@@ -42,7 +42,7 @@ class I18n extends exports.BaseI18n {
|
|
|
42
42
|
const objectStack = new WeakMap();
|
|
43
43
|
return this._deepTranslate(input, objectStack, options);
|
|
44
44
|
}
|
|
45
|
-
createInstance(options
|
|
45
|
+
createInstance(options, callback) {
|
|
46
46
|
return new I18n(options, callback);
|
|
47
47
|
}
|
|
48
48
|
static createInstance(options, callback) {
|
|
@@ -106,8 +106,9 @@ class I18n extends exports.BaseI18n {
|
|
|
106
106
|
input instanceof Map ||
|
|
107
107
|
input instanceof Set ||
|
|
108
108
|
input instanceof WeakMap ||
|
|
109
|
-
input instanceof WeakSet)
|
|
109
|
+
input instanceof WeakSet) {
|
|
110
110
|
return input;
|
|
111
|
+
}
|
|
111
112
|
const out = {};
|
|
112
113
|
objectStack.set(input, out);
|
|
113
114
|
const keys = Object.keys(input);
|
package/cjs/i18n/index.js
CHANGED
package/cjs/i18n/string-utils.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.escapeString = escapeString;
|
|
4
|
+
exports.unescapeString = unescapeString;
|
|
4
5
|
const unescapeRegEx = /\\(.)/g;
|
|
5
6
|
const escapeRegEx = /(\\)/g;
|
|
6
7
|
function escapeString(s) {
|
|
7
8
|
return s.replace(escapeRegEx, '\\\\');
|
|
8
9
|
}
|
|
9
|
-
exports.escapeString = escapeString;
|
|
10
10
|
function unescapeString(s) {
|
|
11
11
|
return s.replace(unescapeRegEx, '$1');
|
|
12
12
|
}
|
|
13
|
-
exports.unescapeString = unescapeString;
|
package/cjs/i18n/translate.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.translate =
|
|
3
|
+
exports.translate = translate;
|
|
4
4
|
const string_utils_js_1 = require("./string-utils.js");
|
|
5
5
|
const bracketRegEx = /(\))/g;
|
|
6
6
|
function translate(key, arg0, arg1) {
|
|
@@ -12,4 +12,3 @@ function translate(key, arg0, arg1) {
|
|
|
12
12
|
(fallback ? '?' + (0, string_utils_js_1.escapeString)(fallback).replace(bracketRegEx, '\\$1') : '') +
|
|
13
13
|
')');
|
|
14
14
|
}
|
|
15
|
-
exports.translate = translate;
|
package/cjs/index.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.uid = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
tslib_1.__exportStar(require("./types.js"), exports);
|
|
6
5
|
tslib_1.__exportStar(require("./document/index.js"), exports);
|
|
7
6
|
tslib_1.__exportStar(require("./exception/index.js"), exports);
|
|
8
7
|
tslib_1.__exportStar(require("./filter/index.js"), exports);
|
|
@@ -10,5 +9,6 @@ tslib_1.__exportStar(require("./helpers/index.js"), exports);
|
|
|
10
9
|
tslib_1.__exportStar(require("./http/index.js"), exports);
|
|
11
10
|
tslib_1.__exportStar(require("./i18n/index.js"), exports);
|
|
12
11
|
tslib_1.__exportStar(require("./schema/index.js"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./types.js"), exports);
|
|
13
13
|
var uid_1 = require("uid");
|
|
14
14
|
Object.defineProperty(exports, "uid", { enumerable: true, get: function () { return uid_1.uid; } });
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isDataType = isDataType;
|
|
4
|
+
exports.isComplexType = isComplexType;
|
|
5
|
+
exports.isSimpleType = isSimpleType;
|
|
6
|
+
exports.isMixinType = isMixinType;
|
|
7
|
+
exports.isMappedType = isMappedType;
|
|
8
|
+
exports.isEnumType = isEnumType;
|
|
9
|
+
exports.isHttpController = isHttpController;
|
|
4
10
|
const complex_type_interface_js_1 = require("./data-type/complex-type.interface.js");
|
|
5
11
|
const enum_type_interface_js_1 = require("./data-type/enum-type.interface.js");
|
|
6
12
|
const mapped_type_interface_js_1 = require("./data-type/mapped-type.interface.js");
|
|
@@ -16,28 +22,21 @@ function isDataType(obj) {
|
|
|
16
22
|
obj.kind === simple_type_interface_js_1.SimpleType.Kind ||
|
|
17
23
|
obj.kind === mixin_type_interface_js_1.MixinType.Kind));
|
|
18
24
|
}
|
|
19
|
-
exports.isDataType = isDataType;
|
|
20
25
|
function isComplexType(obj) {
|
|
21
26
|
return obj && typeof obj === 'object' && obj.kind === complex_type_interface_js_1.ComplexType.Kind;
|
|
22
27
|
}
|
|
23
|
-
exports.isComplexType = isComplexType;
|
|
24
28
|
function isSimpleType(obj) {
|
|
25
29
|
return obj && typeof obj === 'object' && obj.kind === simple_type_interface_js_1.SimpleType.Kind;
|
|
26
30
|
}
|
|
27
|
-
exports.isSimpleType = isSimpleType;
|
|
28
31
|
function isMixinType(obj) {
|
|
29
32
|
return obj && typeof obj === 'object' && obj.kind === mixin_type_interface_js_1.MixinType.Kind;
|
|
30
33
|
}
|
|
31
|
-
exports.isMixinType = isMixinType;
|
|
32
34
|
function isMappedType(obj) {
|
|
33
35
|
return obj && typeof obj === 'object' && obj.kind === mapped_type_interface_js_1.MappedType.Kind;
|
|
34
36
|
}
|
|
35
|
-
exports.isMappedType = isMappedType;
|
|
36
37
|
function isEnumType(obj) {
|
|
37
38
|
return obj && typeof obj === 'object' && obj.kind === enum_type_interface_js_1.EnumType.Kind;
|
|
38
39
|
}
|
|
39
|
-
exports.isEnumType = isEnumType;
|
|
40
40
|
function isHttpController(obj) {
|
|
41
41
|
return obj && typeof obj === 'object' && obj.kind === http_controller_interface_js_1.HttpController.Kind;
|
|
42
42
|
}
|
|
43
|
-
exports.isHttpController = isHttpController;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
var _a;
|
|
2
|
+
import crypto from 'node:crypto';
|
|
2
3
|
import { cloneObject, omitUndefined, ResponsiveMap } from '../helpers/index.js';
|
|
3
4
|
import { OpraSchema } from '../schema/index.js';
|
|
4
5
|
import { DataTypeMap } from './common/data-type-map.js';
|
|
@@ -13,6 +14,8 @@ export class ApiDocument extends DocumentElement {
|
|
|
13
14
|
constructor() {
|
|
14
15
|
super(null);
|
|
15
16
|
this[_a] = new WeakMap();
|
|
17
|
+
this.id = '';
|
|
18
|
+
this.info = {};
|
|
16
19
|
this.references = new ResponsiveMap();
|
|
17
20
|
this.types = new DataTypeMap();
|
|
18
21
|
this.node[kDataTypeMap] = this.types;
|
|
@@ -77,6 +80,14 @@ export class ApiDocument extends DocumentElement {
|
|
|
77
80
|
out.api = this.api.toJSON();
|
|
78
81
|
return out;
|
|
79
82
|
}
|
|
83
|
+
invalidate() {
|
|
84
|
+
/** Generate id */
|
|
85
|
+
const x = this.export();
|
|
86
|
+
delete x.id;
|
|
87
|
+
this.id = crypto.createHash('md5').update(JSON.stringify(x)).digest('base64url');
|
|
88
|
+
/** Clear [kTypeNSMap] */
|
|
89
|
+
this[kTypeNSMap] = new WeakMap();
|
|
90
|
+
}
|
|
80
91
|
_findDataType(nameOrCtor, visitedRefs) {
|
|
81
92
|
let result = this.types.get(nameOrCtor);
|
|
82
93
|
if (result || !this.references.size)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
1
2
|
import { asMutable } from 'ts-gems';
|
|
2
3
|
import { DocumentNode } from './document-node.js';
|
|
3
4
|
/**
|
|
@@ -8,17 +9,19 @@ export const DocumentElement = function (owner) {
|
|
|
8
9
|
if (!this)
|
|
9
10
|
throw new TypeError('"this" should be passed to call class constructor');
|
|
10
11
|
const _this = asMutable(this);
|
|
12
|
+
_this.id = crypto.randomBytes(16).toString('base64url');
|
|
11
13
|
Object.defineProperty(_this, 'node', {
|
|
12
14
|
value: new DocumentNode(this, owner?.node),
|
|
13
15
|
enumerable: false,
|
|
14
16
|
writable: true,
|
|
15
17
|
});
|
|
16
|
-
if (owner)
|
|
18
|
+
if (owner) {
|
|
17
19
|
Object.defineProperty(_this, 'owner', {
|
|
18
20
|
value: owner,
|
|
19
21
|
enumerable: false,
|
|
20
22
|
writable: true,
|
|
21
23
|
});
|
|
24
|
+
}
|
|
22
25
|
};
|
|
23
26
|
/**
|
|
24
27
|
* @class DocumentElement
|
|
@@ -21,8 +21,9 @@ export const ApiField = function (...args) {
|
|
|
21
21
|
_this.name = initArgs.name;
|
|
22
22
|
const origin = initArgs.origin || owner;
|
|
23
23
|
/* istanbul ignore next */
|
|
24
|
-
if (!(origin instanceof ComplexTypeBase))
|
|
24
|
+
if (!(origin instanceof ComplexTypeBase)) {
|
|
25
25
|
throw new Error('Field origin should be one of ComplexType, MappedType or MixinType');
|
|
26
|
+
}
|
|
26
27
|
_this.origin = origin;
|
|
27
28
|
_this.type = initArgs.type || owner.node.getDataType('any');
|
|
28
29
|
_this.description = initArgs.description;
|
|
@@ -33,7 +34,10 @@ export const ApiField = function (...args) {
|
|
|
33
34
|
_this.exclusive = initArgs.exclusive;
|
|
34
35
|
_this.translatable = initArgs.translatable;
|
|
35
36
|
_this.deprecated = initArgs.deprecated;
|
|
37
|
+
_this.readonly = initArgs.readonly;
|
|
38
|
+
_this.writeonly = initArgs.writeonly;
|
|
36
39
|
_this.examples = initArgs.examples;
|
|
40
|
+
_this.hidden = initArgs.hidden;
|
|
37
41
|
};
|
|
38
42
|
/**
|
|
39
43
|
*
|
|
@@ -45,13 +49,15 @@ class ApiFieldClass extends DocumentElement {
|
|
|
45
49
|
return omitUndefined({
|
|
46
50
|
type: typeName ? typeName : this.type?.toJSON(),
|
|
47
51
|
description: this.description,
|
|
48
|
-
isArray: this.isArray,
|
|
52
|
+
isArray: this.isArray || undefined,
|
|
49
53
|
default: this.default,
|
|
50
54
|
fixed: this.fixed,
|
|
51
|
-
required: this.required,
|
|
52
|
-
exclusive: this.exclusive,
|
|
53
|
-
translatable: this.translatable,
|
|
54
|
-
deprecated: this.deprecated,
|
|
55
|
+
required: this.required || undefined,
|
|
56
|
+
exclusive: this.exclusive || undefined,
|
|
57
|
+
translatable: this.translatable || undefined,
|
|
58
|
+
deprecated: this.deprecated || undefined,
|
|
59
|
+
readonly: this.readonly || undefined,
|
|
60
|
+
writeonly: this.writeonly || undefined,
|
|
55
61
|
examples: this.examples,
|
|
56
62
|
});
|
|
57
63
|
}
|
|
@@ -115,8 +115,9 @@ class ComplexTypeBaseClass extends DataType {
|
|
|
115
115
|
: options?.projection;
|
|
116
116
|
const schema = this._generateSchema(codec, { ...options, projection, currentPath: '' });
|
|
117
117
|
let additionalFields;
|
|
118
|
-
if (this.additionalFields instanceof DataType)
|
|
118
|
+
if (this.additionalFields instanceof DataType) {
|
|
119
119
|
additionalFields = this.additionalFields.generateCodec(codec, options);
|
|
120
|
+
}
|
|
120
121
|
else if (typeof this.additionalFields === 'boolean')
|
|
121
122
|
additionalFields = this.additionalFields;
|
|
122
123
|
else if (Array.isArray(this.additionalFields)) {
|
|
@@ -128,7 +129,7 @@ class ComplexTypeBaseClass extends DataType {
|
|
|
128
129
|
}
|
|
129
130
|
}
|
|
130
131
|
return vg.isObject(schema, {
|
|
131
|
-
ctor: this.ctor,
|
|
132
|
+
ctor: this.name === 'object' ? Object : this.ctor,
|
|
132
133
|
additionalFields,
|
|
133
134
|
name: this.name,
|
|
134
135
|
coerce: true,
|
|
@@ -143,6 +144,12 @@ class ComplexTypeBaseClass extends DataType {
|
|
|
143
144
|
// Process fields
|
|
144
145
|
let fieldName;
|
|
145
146
|
for (const field of this.fields.values()) {
|
|
147
|
+
if ((context.ignoreReadonlyFields && field.readonly) ||
|
|
148
|
+
(context.ignoreWriteonlyFields && field.writeonly) ||
|
|
149
|
+
(context.ignoreHiddenFields && field.hidden)) {
|
|
150
|
+
schema[field.name] = vg.isUndefined({ coerce: true });
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
146
153
|
fieldName = field.name;
|
|
147
154
|
let p;
|
|
148
155
|
if (projection !== '*') {
|
|
@@ -161,7 +168,7 @@ class ComplexTypeBaseClass extends DataType {
|
|
|
161
168
|
const fn = this._generateFieldCodec(codec, field, {
|
|
162
169
|
...context,
|
|
163
170
|
partial: context.partial === 'deep' ? context.partial : undefined,
|
|
164
|
-
projection
|
|
171
|
+
projection,
|
|
165
172
|
currentPath: currentPath + (currentPath ? '.' : '') + fieldName,
|
|
166
173
|
});
|
|
167
174
|
schema[fieldName] = context.partial || !field.required ? vg.optional(fn) : vg.required(fn);
|
|
@@ -26,11 +26,13 @@ export const ComplexType = function (...args) {
|
|
|
26
26
|
if (initArgs.base) {
|
|
27
27
|
context.enter('.base', () => {
|
|
28
28
|
// noinspection SuspiciousTypeOfGuard
|
|
29
|
-
if (!(initArgs.base instanceof ComplexTypeBase))
|
|
29
|
+
if (!(initArgs.base instanceof ComplexTypeBase)) {
|
|
30
30
|
throw new TypeError(`"${initArgs.base.kind}" can't be set as base for a "${this.kind}"`);
|
|
31
|
+
}
|
|
31
32
|
_this.base = initArgs.base;
|
|
32
|
-
if (_this.additionalFields == null && _this.base.additionalFields)
|
|
33
|
+
if (_this.additionalFields == null && _this.base.additionalFields) {
|
|
33
34
|
_this.additionalFields = _this.base.additionalFields;
|
|
35
|
+
}
|
|
34
36
|
/** Copy fields from base */
|
|
35
37
|
for (const v of _this.base.fields.values()) {
|
|
36
38
|
this.fields.set(v.name, new ApiField(this, v));
|
|
@@ -57,6 +59,8 @@ export const ComplexType = function (...args) {
|
|
|
57
59
|
*/
|
|
58
60
|
class ComplexTypeClass extends ComplexTypeBase {
|
|
59
61
|
extendsFrom(baseType) {
|
|
62
|
+
if (!(baseType instanceof DataType))
|
|
63
|
+
baseType = this.node.getDataType(baseType);
|
|
60
64
|
if (!(baseType instanceof ComplexTypeBase))
|
|
61
65
|
return false;
|
|
62
66
|
if (baseType === this)
|
|
@@ -11,8 +11,9 @@ export const DataType = function (owner, initArgs,
|
|
|
11
11
|
context) {
|
|
12
12
|
if (!this)
|
|
13
13
|
throw new TypeError('"this" should be passed to call class constructor');
|
|
14
|
-
if (initArgs?.name && !CLASS_NAME_PATTERN.test(initArgs.name))
|
|
14
|
+
if (initArgs?.name && !CLASS_NAME_PATTERN.test(initArgs.name)) {
|
|
15
15
|
throw new TypeError(`"${initArgs.name}" is not a valid DataType name`);
|
|
16
|
+
}
|
|
16
17
|
DocumentElement.call(this, owner);
|
|
17
18
|
const _this = asMutable(this);
|
|
18
19
|
_this.kind = initArgs.kind;
|
|
@@ -19,8 +19,9 @@ export const EnumType = function (...args) {
|
|
|
19
19
|
_this.kind = OpraSchema.EnumType.Kind;
|
|
20
20
|
if (initArgs.base) {
|
|
21
21
|
// noinspection SuspiciousTypeOfGuard
|
|
22
|
-
if (!(initArgs.base instanceof EnumType))
|
|
23
|
-
throw new TypeError(`"${initArgs.base.kind}" can't be set as base for a "${
|
|
22
|
+
if (!(initArgs.base instanceof EnumType)) {
|
|
23
|
+
throw new TypeError(`"${initArgs.base.kind}" can't be set as base for a "${_this.kind}"`);
|
|
24
|
+
}
|
|
24
25
|
_this.base = initArgs.base;
|
|
25
26
|
}
|
|
26
27
|
_this.instance = initArgs.instance;
|
|
@@ -35,6 +36,8 @@ export const EnumType = function (...args) {
|
|
|
35
36
|
*/
|
|
36
37
|
class EnumTypeClass extends DataType {
|
|
37
38
|
extendsFrom(baseType) {
|
|
39
|
+
if (!(baseType instanceof DataType))
|
|
40
|
+
baseType = this.node.getDataType(baseType);
|
|
38
41
|
if (!(baseType instanceof EnumType))
|
|
39
42
|
return false;
|
|
40
43
|
if (baseType === this)
|
|
@@ -17,6 +17,10 @@ let Base64Type = class Base64Type {
|
|
|
17
17
|
Base64Type = __decorate([
|
|
18
18
|
SimpleType({
|
|
19
19
|
description: 'A stream of bytes, base64 encoded',
|
|
20
|
+
nameMappings: {
|
|
21
|
+
js: 'string',
|
|
22
|
+
json: 'string',
|
|
23
|
+
},
|
|
20
24
|
}),
|
|
21
25
|
__metadata("design:paramtypes", [Object])
|
|
22
26
|
], Base64Type);
|
|
@@ -33,12 +33,16 @@ __decorate([
|
|
|
33
33
|
__metadata("design:type", String)
|
|
34
34
|
], DateStringType.prototype, "maxValue", void 0);
|
|
35
35
|
DateStringType = __decorate([
|
|
36
|
-
SimpleType({
|
|
36
|
+
(SimpleType({
|
|
37
37
|
description: 'Date string value',
|
|
38
|
+
nameMappings: {
|
|
39
|
+
js: 'string',
|
|
40
|
+
json: 'string',
|
|
41
|
+
},
|
|
38
42
|
})
|
|
39
43
|
.Example('2021-04-18', 'Full date value')
|
|
40
44
|
.Example('2021-04', 'Date value without day')
|
|
41
|
-
.Example('2021', 'Year only value'),
|
|
45
|
+
.Example('2021', 'Year only value')),
|
|
42
46
|
__metadata("design:paramtypes", [Object])
|
|
43
47
|
], DateStringType);
|
|
44
48
|
export { DateStringType };
|
|
@@ -33,15 +33,19 @@ __decorate([
|
|
|
33
33
|
__metadata("design:type", String)
|
|
34
34
|
], DateTimeStringType.prototype, "maxValue", void 0);
|
|
35
35
|
DateTimeStringType = __decorate([
|
|
36
|
-
SimpleType({
|
|
36
|
+
(SimpleType({
|
|
37
37
|
description: 'DateTime string value',
|
|
38
|
+
nameMappings: {
|
|
39
|
+
js: 'string',
|
|
40
|
+
json: 'string',
|
|
41
|
+
},
|
|
38
42
|
})
|
|
39
43
|
.Example('2021-04-18T22:30:15+01:00', 'Full date-time value with timezone')
|
|
40
44
|
.Example('2021-04-18T22:30:15', 'Full date-time value without timezone')
|
|
41
45
|
.Example('2021-04-18 22:30', 'Date-time value')
|
|
42
46
|
.Example('2021-04-18', 'Date value')
|
|
43
47
|
.Example('2021-04', 'Date value without day')
|
|
44
|
-
.Example('2021', 'Year only value'),
|
|
48
|
+
.Example('2021', 'Year only value')),
|
|
45
49
|
__metadata("design:paramtypes", [Object])
|
|
46
50
|
], DateTimeStringType);
|
|
47
51
|
export { DateTimeStringType };
|
|
@@ -47,12 +47,16 @@ __decorate([
|
|
|
47
47
|
__metadata("design:type", String)
|
|
48
48
|
], DateTimeType.prototype, "maxValue", void 0);
|
|
49
49
|
DateTimeType = __decorate([
|
|
50
|
-
SimpleType({
|
|
50
|
+
(SimpleType({
|
|
51
51
|
description: 'A full datetime value',
|
|
52
|
+
nameMappings: {
|
|
53
|
+
js: 'string',
|
|
54
|
+
json: 'string',
|
|
55
|
+
},
|
|
52
56
|
})
|
|
53
57
|
.Example('2021-04-18T22:30:15')
|
|
54
58
|
.Example('2021-04-18 22:30:15')
|
|
55
|
-
.Example('2021-04-18 22:30'),
|
|
59
|
+
.Example('2021-04-18 22:30')),
|
|
56
60
|
__metadata("design:paramtypes", [Object])
|
|
57
61
|
], DateTimeType);
|
|
58
62
|
export { DateTimeType };
|
|
@@ -47,9 +47,13 @@ __decorate([
|
|
|
47
47
|
__metadata("design:type", String)
|
|
48
48
|
], DateType.prototype, "maxValue", void 0);
|
|
49
49
|
DateType = __decorate([
|
|
50
|
-
SimpleType({
|
|
50
|
+
(SimpleType({
|
|
51
51
|
description: 'A date without time',
|
|
52
|
-
|
|
52
|
+
nameMappings: {
|
|
53
|
+
js: 'Date',
|
|
54
|
+
json: 'string',
|
|
55
|
+
},
|
|
56
|
+
}).Example('2021-04-18', 'Full date value')),
|
|
53
57
|
__metadata("design:paramtypes", [Object])
|
|
54
58
|
], DateType);
|
|
55
59
|
export { DateType };
|