@opra/common 0.18.4 → 0.19.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/browser.js +1225 -910
- package/cjs/document/api-document.js +55 -38
- package/cjs/document/data-type/api-field.js +5 -5
- package/cjs/document/data-type/builtin/any.type.js +3 -5
- package/cjs/document/data-type/builtin/base64.type.js +5 -28
- package/cjs/document/data-type/builtin/bigint.type.js +7 -25
- package/cjs/document/data-type/builtin/boolean.type.js +5 -18
- package/cjs/document/data-type/builtin/date.type.js +13 -9
- package/cjs/document/data-type/builtin/index.js +3 -1
- package/cjs/document/data-type/builtin/integer.type.js +5 -18
- package/cjs/document/data-type/builtin/number.type.js +5 -23
- package/cjs/document/data-type/builtin/object.type.js +4 -9
- package/cjs/document/data-type/builtin/string.type.js +5 -14
- package/cjs/document/data-type/builtin/time.type.js +11 -23
- package/cjs/document/data-type/builtin/timestamp.type.js +8 -20
- package/cjs/document/data-type/builtin/uuid.type.js +15 -0
- package/cjs/document/data-type/complex-type.js +151 -92
- package/cjs/document/data-type/data-type.js +32 -31
- package/cjs/document/data-type/enum-type.js +49 -43
- package/cjs/document/data-type/mapped-type.js +115 -70
- package/cjs/document/data-type/simple-type.js +46 -45
- package/cjs/document/data-type/union-type.js +69 -36
- package/cjs/document/factory/create-document.js +5 -3
- package/cjs/document/factory/factory.js +23 -20
- package/cjs/document/factory/import-type-class.js +13 -4
- package/cjs/document/resource/collection.js +55 -59
- package/cjs/document/resource/resource.js +10 -21
- package/cjs/document/resource/singleton.js +36 -39
- package/cjs/exception/common-errors/validation.error.js +11 -0
- package/cjs/exception/index.js +2 -1
- package/cjs/exception/{enums/issue-severity.enum.js → issue-severity.enum.js} +1 -1
- package/cjs/exception/opra-exception.js +2 -2
- package/cjs/filter/antlr/OpraFilterLexer.js +1 -1
- package/cjs/filter/antlr/OpraFilterParser.js +1 -1
- package/cjs/filter/errors.js +5 -0
- package/cjs/http/enums/http-headers-codes.enum.js +1 -1
- package/cjs/http/enums/http-status-codes.enum.js +1 -1
- package/cjs/http/http-request-message.js +1 -1
- package/cjs/http/http-response-message.js +1 -1
- package/cjs/schema/data-type/complex-type.interface.js +1 -1
- package/cjs/schema/data-type/enum-type.interface.js +1 -1
- package/cjs/schema/data-type/mapped-type.interface.js +1 -1
- package/cjs/schema/data-type/simple-type.interface.js +1 -1
- package/cjs/schema/data-type/union-type.interface.js +1 -1
- package/cjs/schema/index.js +3 -41
- package/cjs/schema/opra-schema.ns.js +18 -0
- package/cjs/schema/resource/collection.interface.js +1 -1
- package/cjs/schema/resource/container.interface.js +1 -1
- package/cjs/schema/resource/singleton.interface.js +1 -1
- package/esm/document/api-document.js +55 -38
- package/esm/document/data-type/api-field.js +5 -5
- package/esm/document/data-type/builtin/any.type.js +2 -4
- package/esm/document/data-type/builtin/base64.type.js +4 -27
- package/esm/document/data-type/builtin/bigint.type.js +6 -24
- package/esm/document/data-type/builtin/boolean.type.js +4 -17
- package/esm/document/data-type/builtin/date.type.js +12 -8
- package/esm/document/data-type/builtin/index.js +3 -1
- package/esm/document/data-type/builtin/integer.type.js +4 -17
- package/esm/document/data-type/builtin/number.type.js +4 -22
- package/esm/document/data-type/builtin/object.type.js +3 -8
- package/esm/document/data-type/builtin/string.type.js +4 -13
- package/esm/document/data-type/builtin/time.type.js +10 -22
- package/esm/document/data-type/builtin/timestamp.type.js +7 -19
- package/esm/document/data-type/builtin/uuid.type.js +12 -0
- package/esm/document/data-type/complex-type.js +151 -92
- package/esm/document/data-type/data-type.js +31 -31
- package/esm/document/data-type/enum-type.js +49 -43
- package/esm/document/data-type/mapped-type.js +114 -70
- package/esm/document/data-type/simple-type.js +45 -44
- package/esm/document/data-type/union-type.js +68 -36
- package/esm/document/factory/create-document.js +6 -4
- package/esm/document/factory/factory.js +23 -20
- package/esm/document/factory/import-type-class.js +13 -4
- package/esm/document/resource/collection.js +55 -59
- package/esm/document/resource/resource.js +9 -21
- package/esm/document/resource/singleton.js +36 -39
- package/esm/exception/common-errors/validation.error.js +7 -0
- package/esm/exception/index.js +2 -1
- package/esm/exception/opra-exception.js +2 -2
- package/esm/filter/antlr/OpraFilterLexer.js +2 -1
- package/esm/filter/antlr/OpraFilterParser.js +2 -1
- package/esm/filter/errors.js +5 -0
- package/esm/schema/index.js +2 -41
- package/esm/schema/opra-schema.ns.js +15 -0
- package/package.json +5 -3
- package/types/document/api-document.d.ts +3 -2
- package/types/document/data-type/builtin/base64.type.d.ts +0 -4
- package/types/document/data-type/builtin/bigint.type.d.ts +1 -5
- package/types/document/data-type/builtin/boolean.type.d.ts +0 -3
- package/types/document/data-type/builtin/date.type.d.ts +1 -3
- package/types/document/data-type/builtin/index.d.ts +3 -1
- package/types/document/data-type/builtin/integer.type.d.ts +1 -5
- package/types/document/data-type/builtin/number.type.d.ts +0 -4
- package/types/document/data-type/builtin/object.type.d.ts +0 -1
- package/types/document/data-type/builtin/string.type.d.ts +0 -3
- package/types/document/data-type/builtin/time.type.d.ts +1 -6
- package/types/document/data-type/builtin/timestamp.type.d.ts +0 -3
- package/types/document/data-type/builtin/uuid.type.d.ts +2 -0
- package/types/document/data-type/complex-type.d.ts +29 -16
- package/types/document/data-type/data-type.d.ts +19 -15
- package/types/document/data-type/enum-type.d.ts +15 -5
- package/types/document/data-type/mapped-type.d.ts +27 -5
- package/types/document/data-type/simple-type.d.ts +26 -12
- package/types/document/data-type/union-type.d.ts +20 -5
- package/types/document/factory/factory.d.ts +3 -2
- package/types/document/resource/collection.d.ts +11 -9
- package/types/document/resource/resource.d.ts +3 -9
- package/types/document/resource/singleton.d.ts +7 -5
- package/types/exception/common-errors/validation.error.d.ts +4 -0
- package/types/exception/error-issue.d.ts +1 -1
- package/types/exception/index.d.ts +2 -1
- package/types/exception/opra-exception.d.ts +4 -2
- package/types/filter/errors.d.ts +3 -0
- package/types/schema/data-type/enum-type.interface.d.ts +5 -5
- package/types/schema/data-type/simple-type.interface.d.ts +5 -11
- package/types/schema/index.d.ts +2 -51
- package/types/schema/opra-schema.ns.d.ts +15 -0
- package/cjs/document/data-type/builtin/guid.type.js +0 -35
- package/esm/document/data-type/builtin/guid.type.js +0 -32
- package/types/document/data-type/builtin/guid.type.d.ts +0 -7
- /package/esm/exception/{enums/issue-severity.enum.js → issue-severity.enum.js} +0 -0
- /package/types/exception/{enums/issue-severity.enum.d.ts → issue-severity.enum.d.ts} +0 -0
|
@@ -3,58 +3,59 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SimpleType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const lodash_omit_1 = tslib_1.__importDefault(require("lodash.omit"));
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
7
|
+
const vg = tslib_1.__importStar(require("valgen"));
|
|
8
|
+
const index_js_1 = require("../../schema/index.js");
|
|
8
9
|
const constants_js_1 = require("../constants.js");
|
|
9
10
|
const data_type_js_1 = require("./data-type.js");
|
|
10
11
|
/**
|
|
11
12
|
* @class SimpleType
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
14
|
+
class SimpleTypeClass extends data_type_js_1.DataType {
|
|
15
|
+
constructor(document, init) {
|
|
16
|
+
super(document, init);
|
|
17
|
+
this.kind = index_js_1.OpraSchema.SimpleType.Kind;
|
|
18
|
+
this.base = init.base;
|
|
19
|
+
this._decoder = init.decoder || init.base?._decoder || vg.isAny();
|
|
20
|
+
this._encoder = init.encoder || init.base?._encoder || vg.isAny();
|
|
21
|
+
}
|
|
22
|
+
_getDecoder() {
|
|
23
|
+
return this._decoder;
|
|
24
|
+
}
|
|
25
|
+
_getEncoder() {
|
|
26
|
+
return this._encoder;
|
|
27
27
|
}
|
|
28
|
-
// Constructor
|
|
29
|
-
const [, options] = args;
|
|
30
|
-
// call super()
|
|
31
|
-
data_type_js_1.DataType.apply(this, args);
|
|
32
|
-
const _this = this;
|
|
33
|
-
_this.kind = index_js_2.OpraSchema.SimpleType.Kind;
|
|
34
|
-
_this.base = options?.base;
|
|
35
|
-
const own = _this.own;
|
|
36
|
-
own.codec = options?.codec;
|
|
37
|
-
own.ctor = options?.ctor;
|
|
38
|
-
if (options?.pattern)
|
|
39
|
-
own.pattern = (options?.pattern instanceof RegExp ? options.pattern : new RegExp(options.pattern));
|
|
40
|
-
const ctor = own.ctor || _this.base?.ctor;
|
|
41
|
-
_this.ctor = ctor || Object;
|
|
42
|
-
_this.decode = own.codec?.decode || _this.base?.decode || ((v) => v);
|
|
43
|
-
_this.encode = own.codec?.encode || _this.base?.encode || ((v) => v);
|
|
44
|
-
_this.coerce = own.codec?.coerce || _this.base?.coerce || ((v) => v);
|
|
45
|
-
_this.validate = own.codec?.validate || _this.base?.validate || (() => true);
|
|
46
|
-
_this.pattern = own.pattern || _this.base?.pattern;
|
|
47
|
-
};
|
|
48
|
-
const proto = {
|
|
49
28
|
exportSchema() {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}));
|
|
29
|
+
// noinspection UnnecessaryLocalVariableJS
|
|
30
|
+
const out = super.exportSchema();
|
|
31
|
+
// Object.assign(out, omitUndefined({
|
|
32
|
+
// base: this.base ?
|
|
33
|
+
// (this.base.name ? this.base.name : this.base.exportSchema()) : undefined,
|
|
34
|
+
// }));
|
|
56
35
|
return out;
|
|
57
36
|
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @class SimpleType
|
|
40
|
+
*/
|
|
41
|
+
exports.SimpleType = function (...args) {
|
|
42
|
+
// Constructor
|
|
43
|
+
if (this) {
|
|
44
|
+
const [document, init] = args;
|
|
45
|
+
(0, putil_merge_1.default)(this, new SimpleTypeClass(document, init), { descriptor: true });
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
// ClassDecorator
|
|
49
|
+
const [options] = args;
|
|
50
|
+
return function (target) {
|
|
51
|
+
let name = options?.name || target.name.match(constants_js_1.TYPENAME_PATTERN)?.[1] || target.name;
|
|
52
|
+
name = name.charAt(0).toLowerCase() + name.substring(1);
|
|
53
|
+
const metadata = Reflect.getOwnMetadata(constants_js_1.METADATA_KEY, target) || {};
|
|
54
|
+
metadata.kind = index_js_1.OpraSchema.SimpleType.Kind;
|
|
55
|
+
metadata.name = name;
|
|
56
|
+
if (options)
|
|
57
|
+
Object.assign(metadata, (0, lodash_omit_1.default)(options, ['kind', 'name']));
|
|
58
|
+
Reflect.defineMetadata(constants_js_1.METADATA_KEY, metadata, target);
|
|
59
|
+
};
|
|
58
60
|
};
|
|
59
|
-
|
|
60
|
-
Object.setPrototypeOf(exports.SimpleType.prototype, data_type_js_1.DataType.prototype);
|
|
61
|
+
exports.SimpleType.prototype = SimpleTypeClass.prototype;
|
|
@@ -1,56 +1,87 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UnionType = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
6
|
+
const vg = tslib_1.__importStar(require("valgen"));
|
|
4
7
|
const index_js_1 = require("../../helpers/index.js");
|
|
5
8
|
const index_js_2 = require("../../schema/index.js");
|
|
6
9
|
const constants_js_1 = require("../constants.js");
|
|
7
10
|
const complex_type_js_1 = require("./complex-type.js");
|
|
8
11
|
const data_type_js_1 = require("./data-type.js");
|
|
9
12
|
const mapped_type_js_1 = require("./mapped-type.js");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (!(base instanceof complex_type_js_1.ComplexType || base instanceof exports.UnionType || base instanceof mapped_type_js_1.MappedType))
|
|
28
|
-
throw new TypeError(`${index_js_2.OpraSchema.UnionType.Kind} shall contain ${index_js_2.OpraSchema.ComplexType.Kind}, ` +
|
|
29
|
-
`${index_js_2.OpraSchema.UnionType.Kind} of ${index_js_2.OpraSchema.MappedType.Kind} types.`);
|
|
30
|
-
own.types.push(base);
|
|
31
|
-
if (base.additionalFields)
|
|
32
|
-
_this.additionalFields = true;
|
|
33
|
-
_this.fields.setAll(base.fields);
|
|
13
|
+
class UnionTypeClass extends data_type_js_1.DataType {
|
|
14
|
+
constructor(document, init) {
|
|
15
|
+
super(document, init);
|
|
16
|
+
this.kind = index_js_2.OpraSchema.UnionType.Kind;
|
|
17
|
+
this.fields = new index_js_1.ResponsiveMap();
|
|
18
|
+
const own = this.own;
|
|
19
|
+
own.types = [];
|
|
20
|
+
for (const base of init.types) {
|
|
21
|
+
if (!(base instanceof complex_type_js_1.ComplexType || base instanceof exports.UnionType || base instanceof mapped_type_js_1.MappedType))
|
|
22
|
+
throw new TypeError(`${index_js_2.OpraSchema.UnionType.Kind} shall contain ${index_js_2.OpraSchema.ComplexType.Kind}, ` +
|
|
23
|
+
`${index_js_2.OpraSchema.UnionType.Kind} of ${index_js_2.OpraSchema.MappedType.Kind} types.`);
|
|
24
|
+
own.types.push(base);
|
|
25
|
+
if (base.additionalFields)
|
|
26
|
+
this.additionalFields = true;
|
|
27
|
+
this.fields.setAll(base.fields);
|
|
28
|
+
}
|
|
29
|
+
this.types = [...own.types];
|
|
34
30
|
}
|
|
35
|
-
_this.kind = 'UnionType';
|
|
36
|
-
_this.types = [...own.types];
|
|
37
|
-
};
|
|
38
|
-
exports.UnionType._applyMixin = () => void 0;
|
|
39
|
-
const proto = {
|
|
40
31
|
exportSchema() {
|
|
41
|
-
const out =
|
|
32
|
+
const out = super.exportSchema();
|
|
42
33
|
Object.assign(out, (0, index_js_1.omitUndefined)({
|
|
43
34
|
types: this.own.types.map(t => t.name ? t.name : t.exportSchema())
|
|
44
35
|
}));
|
|
45
36
|
return out;
|
|
46
37
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
38
|
+
_getDecoder() {
|
|
39
|
+
if (this._decoder)
|
|
40
|
+
return this._decoder;
|
|
41
|
+
const schema = {};
|
|
42
|
+
for (const f of this.fields.values()) {
|
|
43
|
+
let t = f.type.getDecoder();
|
|
44
|
+
if (f.isArray)
|
|
45
|
+
t = vg.isArray(t);
|
|
46
|
+
schema[f.name] = t;
|
|
47
|
+
}
|
|
48
|
+
this._decoder = vg.isObject(schema, {
|
|
49
|
+
additionalFields: this.additionalFields,
|
|
50
|
+
name: this.name,
|
|
51
|
+
caseInSensitive: true
|
|
52
|
+
});
|
|
53
|
+
return this._decoder;
|
|
54
|
+
}
|
|
55
|
+
_getEncoder() {
|
|
56
|
+
if (this._encoder)
|
|
57
|
+
return this._encoder;
|
|
58
|
+
const schema = {};
|
|
59
|
+
for (const f of this.fields.values()) {
|
|
60
|
+
let t = f.type.getEncoder();
|
|
61
|
+
if (f.isArray)
|
|
62
|
+
t = vg.isArray(t);
|
|
63
|
+
schema[f.name] = t;
|
|
64
|
+
}
|
|
65
|
+
this._encoder = vg.isObject(schema, {
|
|
66
|
+
additionalFields: this.additionalFields,
|
|
67
|
+
name: this.name,
|
|
68
|
+
caseInSensitive: true,
|
|
69
|
+
detectCircular: true
|
|
70
|
+
});
|
|
71
|
+
return this._encoder;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
50
74
|
/**
|
|
51
|
-
*
|
|
75
|
+
* @class UnionType
|
|
52
76
|
*/
|
|
53
|
-
function
|
|
77
|
+
exports.UnionType = function (...args) {
|
|
78
|
+
// Constructor
|
|
79
|
+
if (this) {
|
|
80
|
+
const [document, init] = args;
|
|
81
|
+
(0, putil_merge_1.default)(this, new UnionTypeClass(document, init), { descriptor: true });
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// UnionType helper
|
|
54
85
|
// Filter undefined items
|
|
55
86
|
const clasRefs = [...args].filter(x => !!x);
|
|
56
87
|
if (!clasRefs.length)
|
|
@@ -78,4 +109,6 @@ function mapToUnionType(...args) {
|
|
|
78
109
|
}
|
|
79
110
|
exports.UnionType._applyMixin(UnionClass, ...clasRefs);
|
|
80
111
|
return UnionClass;
|
|
81
|
-
}
|
|
112
|
+
};
|
|
113
|
+
exports.UnionType.prototype = UnionTypeClass.prototype;
|
|
114
|
+
exports.UnionType._applyMixin = () => void 0;
|
|
@@ -11,6 +11,8 @@ async function createDocument(init, options) {
|
|
|
11
11
|
if (!options?.noBuiltinTypes) {
|
|
12
12
|
const builtinDocument = await this.createBuiltinTypeDocument();
|
|
13
13
|
this.document.references.set('Opra', builtinDocument);
|
|
14
|
+
for (const [c, s] of Object.getPrototypeOf(this).constructor.designTypeMap.entries())
|
|
15
|
+
this.document._designTypeMap.set(c, s);
|
|
14
16
|
}
|
|
15
17
|
if (init.references)
|
|
16
18
|
await this.addReferences(init.references);
|
|
@@ -69,9 +71,9 @@ async function createBuiltinTypeDocument() {
|
|
|
69
71
|
name: 'MIT'
|
|
70
72
|
}
|
|
71
73
|
},
|
|
72
|
-
types: [index_js_2.AnyType, index_js_2.Base64Type, index_js_2.
|
|
73
|
-
index_js_2.DateType, index_js_2.
|
|
74
|
-
index_js_2.ObjectType, index_js_2.StringType
|
|
74
|
+
types: [index_js_2.AnyType, index_js_2.Base64Type, index_js_2.BigintType, index_js_2.BooleanType,
|
|
75
|
+
index_js_2.DateType, index_js_2.UuidType, index_js_2.IntegerType, index_js_2.NumberType,
|
|
76
|
+
index_js_2.ObjectType, index_js_2.StringType, index_js_2.TimeType, index_js_2.TimestampType
|
|
75
77
|
]
|
|
76
78
|
};
|
|
77
79
|
const factoryClass = Object.getPrototypeOf(this).constructor;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _a;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.DocumentFactory = void 0;
|
|
4
5
|
const index_js_1 = require("../../helpers/index.js");
|
|
@@ -38,25 +39,27 @@ class DocumentFactory {
|
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
exports.DocumentFactory = DocumentFactory;
|
|
42
|
+
_a = DocumentFactory;
|
|
43
|
+
DocumentFactory.designTypeMap = new Map();
|
|
41
44
|
(() => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
45
|
+
_a.prototype.createDocument = create_document_js_1.createDocument;
|
|
46
|
+
_a.prototype.createDocumentFromUrl = create_document_js_1.createDocumentFromUrl;
|
|
47
|
+
_a.prototype.createBuiltinTypeDocument = create_document_js_1.createBuiltinTypeDocument;
|
|
48
|
+
_a.prototype.addReferences = add_references_js_1.addReferences;
|
|
49
|
+
_a.prototype.importTypeClass = import_type_class_js_1.importTypeClass;
|
|
50
|
+
_a.prototype.extractSimpleTypeSchema = import_type_class_js_1.extractSimpleTypeSchema;
|
|
51
|
+
_a.prototype.extractComplexTypeSchema = import_type_class_js_1.extractComplexTypeSchema;
|
|
52
|
+
_a.prototype.extractMappedTypeSchema = import_type_class_js_1.extractMappedTypeSchema;
|
|
53
|
+
_a.prototype.extractUnionTypeSchema = import_type_class_js_1.extractUnionTypeSchema;
|
|
54
|
+
_a.prototype.extractEnumTypeSchema = import_type_class_js_1.extractEnumTypeSchema;
|
|
55
|
+
_a.prototype.extractFieldSchema = import_type_class_js_1.extractFieldSchema;
|
|
56
|
+
_a.prototype.processTypes = process_types_js_1.processTypes;
|
|
57
|
+
_a.prototype.createDataTypeInstance = process_types_js_1.createDataTypeInstance;
|
|
58
|
+
_a.prototype.addDataType = process_types_js_1.addDataType;
|
|
59
|
+
_a.prototype.importResourceClass = import_resource_class_js_1.importResourceClass;
|
|
60
|
+
_a.prototype.extractSingletonSchema = import_resource_class_js_1.extractSingletonSchema;
|
|
61
|
+
_a.prototype.extractCollectionSchema = import_resource_class_js_1.extractCollectionSchema;
|
|
62
|
+
_a.prototype.processResourceQueue = process_resources_js_1.processResourceQueue;
|
|
63
|
+
_a.prototype.createCollection = process_resources_js_1.createCollection;
|
|
64
|
+
_a.prototype.createSingleton = process_resources_js_1.createSingleton;
|
|
62
65
|
})();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extractFieldSchema = exports.extractEnumTypeSchema = exports.extractUnionTypeSchema = exports.extractMappedTypeSchema = exports.extractComplexTypeSchema = exports.extractSimpleTypeSchema = exports.importTypeClass = void 0;
|
|
4
|
+
const valgen_1 = require("valgen");
|
|
4
5
|
const index_js_1 = require("../../helpers/index.js");
|
|
5
6
|
const index_js_2 = require("../../schema/index.js");
|
|
6
7
|
const constants_js_1 = require("../constants.js");
|
|
@@ -67,14 +68,17 @@ metadata) {
|
|
|
67
68
|
const baseClass = Object.getPrototypeOf(ctor.prototype).constructor;
|
|
68
69
|
if (Reflect.hasMetadata(constants_js_1.METADATA_KEY, baseClass))
|
|
69
70
|
target.base = await this.importTypeClass(baseClass);
|
|
70
|
-
|
|
71
|
+
if (typeof ctor.prototype.decode === 'function')
|
|
72
|
+
target.decoder = (0, valgen_1.validator)(metadata.name, ctor.prototype.decode);
|
|
73
|
+
if (typeof ctor.prototype.encode === 'function')
|
|
74
|
+
target.encoder = (0, valgen_1.validator)(metadata.name, ctor.prototype.encode);
|
|
71
75
|
}
|
|
72
76
|
exports.extractSimpleTypeSchema = extractSimpleTypeSchema;
|
|
73
77
|
async function extractComplexTypeSchema(target, ctor, metadata) {
|
|
74
78
|
const baseClass = Object.getPrototypeOf(ctor.prototype).constructor;
|
|
75
79
|
if (Reflect.hasMetadata(constants_js_1.METADATA_KEY, baseClass))
|
|
76
80
|
target.base = await this.importTypeClass(baseClass);
|
|
77
|
-
target.ctor = ctor;
|
|
81
|
+
target.ctor = target.ctor || ctor;
|
|
78
82
|
// Fields
|
|
79
83
|
if (metadata.fields) {
|
|
80
84
|
const fields = target.fields = {};
|
|
@@ -90,8 +94,13 @@ async function extractComplexTypeSchema(target, ctor, metadata) {
|
|
|
90
94
|
};
|
|
91
95
|
if (elemMeta.enum)
|
|
92
96
|
elemSchema.type = await this.importTypeClass(elemMeta.enum);
|
|
93
|
-
if (!elemSchema.type && elemMeta.designType)
|
|
94
|
-
|
|
97
|
+
if (!elemSchema.type && elemMeta.designType) {
|
|
98
|
+
const mappingType = this.document.getDataType(elemMeta.designType, true);
|
|
99
|
+
if (mappingType)
|
|
100
|
+
elemSchema.type = mappingType.name;
|
|
101
|
+
else
|
|
102
|
+
elemSchema.type = await this.importTypeClass(elemMeta.designType);
|
|
103
|
+
}
|
|
95
104
|
await this.extractFieldSchema(elemSchema, ctor, elemMeta, elemName);
|
|
96
105
|
// Check enum again. External packages may modify enum value
|
|
97
106
|
if (elemMeta.enum)
|
|
@@ -14,64 +14,28 @@ const simple_type_js_1 = require("../data-type/simple-type.js");
|
|
|
14
14
|
const resource_js_1 = require("./resource.js");
|
|
15
15
|
const NESTJS_INJECTABLE_WATERMARK = '__injectable__';
|
|
16
16
|
const NAME_PATTERN = /^(.*)(Resource|Collection)$/;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
return function (target) {
|
|
25
|
-
const name = options?.name || target.name.match(NAME_PATTERN)?.[1] || target.name;
|
|
26
|
-
const metadata = Reflect.getOwnMetadata(constants_js_1.METADATA_KEY, target) || {};
|
|
27
|
-
const baseMetadata = Reflect.getOwnMetadata(constants_js_1.METADATA_KEY, Object.getPrototypeOf(target));
|
|
28
|
-
if (baseMetadata) {
|
|
29
|
-
(0, putil_merge_1.default)(metadata, baseMetadata, { deep: true });
|
|
30
|
-
}
|
|
31
|
-
metadata.kind = index_js_5.OpraSchema.Collection.Kind;
|
|
32
|
-
metadata.name = name;
|
|
33
|
-
metadata.type = type;
|
|
34
|
-
// Merge with previous metadata object
|
|
35
|
-
const m = Reflect.getMetadata(constants_js_1.METADATA_KEY, target);
|
|
36
|
-
if (m && metadata !== m)
|
|
37
|
-
Object.assign(metadata, (0, lodash_omit_1.default)(m), Object.keys(metadata));
|
|
38
|
-
// Merge options
|
|
39
|
-
if (options)
|
|
40
|
-
Object.assign(metadata, (0, lodash_omit_1.default)(options, ['kind', 'name', 'type', 'controller']));
|
|
41
|
-
Reflect.defineMetadata(constants_js_1.METADATA_KEY, metadata, target);
|
|
42
|
-
/* Define Injectable metadata for NestJS support*/
|
|
43
|
-
Reflect.defineMetadata(NESTJS_INJECTABLE_WATERMARK, true, target);
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
// Constructor
|
|
47
|
-
const [document, init] = args;
|
|
48
|
-
// call super()
|
|
49
|
-
resource_js_1.Resource.apply(this, [document, init]);
|
|
50
|
-
};
|
|
51
|
-
const proto = {
|
|
52
|
-
_construct(init) {
|
|
53
|
-
// call super()
|
|
54
|
-
resource_js_1.Resource.prototype._construct.call(this, init);
|
|
55
|
-
const _this = this;
|
|
56
|
-
_this.kind = index_js_5.OpraSchema.Collection.Kind;
|
|
57
|
-
_this.controller = init.controller;
|
|
58
|
-
const operations = _this.operations = init.operations || {};
|
|
59
|
-
const dataType = _this.type = init.type;
|
|
17
|
+
class CollectionClass extends resource_js_1.Resource {
|
|
18
|
+
constructor(document, init) {
|
|
19
|
+
super(document, init);
|
|
20
|
+
this.kind = index_js_5.OpraSchema.Collection.Kind;
|
|
21
|
+
this.controller = init.controller;
|
|
22
|
+
const operations = this.operations = init.operations || {};
|
|
23
|
+
const dataType = this.type = init.type;
|
|
60
24
|
// Validate key fields
|
|
61
|
-
|
|
25
|
+
this.primaryKey = init.primaryKey
|
|
62
26
|
? (Array.isArray(init.primaryKey) ? init.primaryKey : [init.primaryKey])
|
|
63
27
|
: [];
|
|
64
|
-
if (!
|
|
65
|
-
throw new TypeError(`You must provide primaryKey for Collection resource ("${
|
|
66
|
-
|
|
28
|
+
if (!this.primaryKey.length)
|
|
29
|
+
throw new TypeError(`You must provide primaryKey for Collection resource ("${this.name}")`);
|
|
30
|
+
this.primaryKey.forEach(f => {
|
|
67
31
|
const field = dataType.getField(f);
|
|
68
32
|
if (!(field?.type instanceof simple_type_js_1.SimpleType))
|
|
69
33
|
throw new TypeError(`Only Simple type allowed for primary keys but "${f}" is a ${field.type.kind}`);
|
|
70
34
|
});
|
|
71
|
-
if (
|
|
72
|
-
const instance = typeof
|
|
73
|
-
? new
|
|
74
|
-
:
|
|
35
|
+
if (this.controller) {
|
|
36
|
+
const instance = typeof this.controller == 'function'
|
|
37
|
+
? new this.controller()
|
|
38
|
+
: this.controller;
|
|
75
39
|
for (const operation of Object.values(operations)) {
|
|
76
40
|
if (!operation.handler && operation.handlerName) {
|
|
77
41
|
const fn = instance[operation.handlerName];
|
|
@@ -81,7 +45,7 @@ const proto = {
|
|
|
81
45
|
}
|
|
82
46
|
}
|
|
83
47
|
}
|
|
84
|
-
}
|
|
48
|
+
}
|
|
85
49
|
exportSchema() {
|
|
86
50
|
const out = resource_js_1.Resource.prototype.exportSchema.call(this);
|
|
87
51
|
Object.assign(out, (0, index_js_3.omitUndefined)({
|
|
@@ -90,7 +54,7 @@ const proto = {
|
|
|
90
54
|
primaryKey: this.primaryKey
|
|
91
55
|
}));
|
|
92
56
|
return out;
|
|
93
|
-
}
|
|
57
|
+
}
|
|
94
58
|
parseKeyValue(value) {
|
|
95
59
|
if (!this.primaryKey?.length)
|
|
96
60
|
return;
|
|
@@ -121,22 +85,22 @@ const proto = {
|
|
|
121
85
|
throw new TypeError(`You must provide value of primary field(s) (${primaryKey})`);
|
|
122
86
|
return result;
|
|
123
87
|
}
|
|
124
|
-
}
|
|
88
|
+
}
|
|
125
89
|
normalizeFieldPath(path) {
|
|
126
90
|
return this.type.normalizeFieldPath(path);
|
|
127
|
-
}
|
|
91
|
+
}
|
|
128
92
|
normalizeSortFields(fields) {
|
|
129
93
|
const normalized = this.type.normalizeFieldPath(fields);
|
|
130
94
|
const findManyEndpoint = this.operations.findMany;
|
|
131
95
|
const sortFields = findManyEndpoint && findManyEndpoint.sortFields;
|
|
132
|
-
normalized.forEach(field => {
|
|
96
|
+
(Array.isArray(normalized) ? normalized : [normalized]).forEach(field => {
|
|
133
97
|
if (!sortFields?.find(x => x === field))
|
|
134
98
|
throw new index_js_1.BadRequestError({
|
|
135
99
|
message: (0, index_js_4.translate)('error:UNACCEPTED_SORT_FIELD', { field }, `Field '${field}' is not available for sort operation`),
|
|
136
100
|
});
|
|
137
101
|
});
|
|
138
102
|
return normalized;
|
|
139
|
-
}
|
|
103
|
+
}
|
|
140
104
|
normalizeFilter(filter) {
|
|
141
105
|
if (!filter)
|
|
142
106
|
return;
|
|
@@ -166,9 +130,41 @@ const proto = {
|
|
|
166
130
|
}
|
|
167
131
|
return ast;
|
|
168
132
|
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
*
|
|
136
|
+
*/
|
|
137
|
+
exports.Collection = function (...args) {
|
|
138
|
+
// ClassDecorator
|
|
139
|
+
if (!this) {
|
|
140
|
+
const [type, options] = args;
|
|
141
|
+
return function (target) {
|
|
142
|
+
const name = options?.name || target.name.match(NAME_PATTERN)?.[1] || target.name;
|
|
143
|
+
const metadata = Reflect.getOwnMetadata(constants_js_1.METADATA_KEY, target) || {};
|
|
144
|
+
const baseMetadata = Reflect.getOwnMetadata(constants_js_1.METADATA_KEY, Object.getPrototypeOf(target));
|
|
145
|
+
if (baseMetadata) {
|
|
146
|
+
(0, putil_merge_1.default)(metadata, baseMetadata, { deep: true });
|
|
147
|
+
}
|
|
148
|
+
metadata.kind = index_js_5.OpraSchema.Collection.Kind;
|
|
149
|
+
metadata.name = name;
|
|
150
|
+
metadata.type = type;
|
|
151
|
+
// Merge with previous metadata object
|
|
152
|
+
const m = Reflect.getMetadata(constants_js_1.METADATA_KEY, target);
|
|
153
|
+
if (m && metadata !== m)
|
|
154
|
+
Object.assign(metadata, (0, lodash_omit_1.default)(m), Object.keys(metadata));
|
|
155
|
+
// Merge options
|
|
156
|
+
if (options)
|
|
157
|
+
Object.assign(metadata, (0, lodash_omit_1.default)(options, ['kind', 'name', 'type', 'controller']));
|
|
158
|
+
Reflect.defineMetadata(constants_js_1.METADATA_KEY, metadata, target);
|
|
159
|
+
/* Define Injectable metadata for NestJS support*/
|
|
160
|
+
Reflect.defineMetadata(NESTJS_INJECTABLE_WATERMARK, true, target);
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
// Constructor
|
|
164
|
+
const [document, init] = args;
|
|
165
|
+
(0, putil_merge_1.default)(this, new CollectionClass(document, init), { descriptor: true });
|
|
169
166
|
};
|
|
170
|
-
|
|
171
|
-
Object.setPrototypeOf(exports.Collection.prototype, resource_js_1.Resource.prototype);
|
|
167
|
+
exports.Collection.prototype = CollectionClass.prototype;
|
|
172
168
|
function createOperationDecorator(operation) {
|
|
173
169
|
return (options) => ((target, propertyKey) => {
|
|
174
170
|
const metadata = {
|
|
@@ -3,36 +3,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Resource = void 0;
|
|
4
4
|
const object_utils_js_1 = require("../../helpers/object-utils.js");
|
|
5
5
|
const inspect_util_js_1 = require("../utils/inspect.util.js");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
class Resource {
|
|
7
|
+
constructor(document, init) {
|
|
8
|
+
this.document = document;
|
|
9
|
+
this.name = init.name;
|
|
10
|
+
this.description = init.description;
|
|
11
|
+
this.controller = init.controller;
|
|
11
12
|
}
|
|
12
|
-
const _this = this;
|
|
13
|
-
_this.document = document;
|
|
14
|
-
_this.name = init.name;
|
|
15
|
-
_this.description = init.description;
|
|
16
|
-
_this.controller = init.controller;
|
|
17
|
-
_this._construct(init);
|
|
18
|
-
};
|
|
19
|
-
const proto = {
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
21
|
-
_construct(init) {
|
|
22
|
-
// Do nothing
|
|
23
|
-
},
|
|
24
13
|
exportSchema() {
|
|
25
14
|
return (0, object_utils_js_1.omitUndefined)({
|
|
26
15
|
kind: this.kind,
|
|
27
16
|
description: this.description
|
|
28
17
|
});
|
|
29
|
-
}
|
|
18
|
+
}
|
|
30
19
|
toString() {
|
|
31
20
|
return `[${Object.getPrototypeOf(this).constructor.name} ${this.name || '#anonymous'}]`;
|
|
32
|
-
}
|
|
21
|
+
}
|
|
33
22
|
[inspect_util_js_1.nodeInspectCustom]() {
|
|
34
23
|
return `[${inspect_util_js_1.colorFgYellow + Object.getPrototypeOf(this).constructor.name + inspect_util_js_1.colorReset}` +
|
|
35
24
|
` ${inspect_util_js_1.colorFgMagenta + this.name + inspect_util_js_1.colorReset}]`;
|
|
36
25
|
}
|
|
37
|
-
}
|
|
38
|
-
|
|
26
|
+
}
|
|
27
|
+
exports.Resource = Resource;
|