@apex-pub/convector-core-model 1.4.1-2.0 → 1.4.1-4-alpha.6064f94c
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/dist/src/convector-model.js +74 -87
- package/dist/src/convector-model.js.map +1 -1
- package/dist/src/default.decorator.js +16 -15
- package/dist/src/default.decorator.js.map +1 -1
- package/dist/src/index.js +5 -8
- package/dist/src/index.js.map +1 -1
- package/dist/src/read-only.decorator.js +1 -5
- package/dist/src/read-only.decorator.js.map +1 -1
- package/dist/src/required.decorator.js +12 -14
- package/dist/src/required.decorator.js.map +1 -1
- package/dist/src/validate.decorator.js +13 -16
- package/dist/src/validate.decorator.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const required_decorator_1 = require("../src/required.decorator");
|
|
11
|
-
const validate_decorator_2 = require("../src/validate.decorator");
|
|
12
|
-
class ConvectorModel {
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import * as yup from 'yup';
|
|
3
|
+
import { InvalidIdError } from '@apex-pub/convector-core-errors';
|
|
4
|
+
import { BaseStorage } from '@apex-pub/convector-core-storage';
|
|
5
|
+
import { Validate } from '../src/validate.decorator';
|
|
6
|
+
import { getDefaults } from '../src/default.decorator';
|
|
7
|
+
import { Required, ensureRequired } from '../src/required.decorator';
|
|
8
|
+
import { getPropertiesValidation, getValidatedProperties } from '../src/validate.decorator';
|
|
9
|
+
export class ConvectorModel {
|
|
13
10
|
constructor(content) {
|
|
14
11
|
if (!content) {
|
|
15
12
|
return;
|
|
@@ -21,80 +18,70 @@ class ConvectorModel {
|
|
|
21
18
|
this.assign(content);
|
|
22
19
|
}
|
|
23
20
|
static schema() {
|
|
24
|
-
return yup.object().shape(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
type = type || this;
|
|
29
|
-
const content = yield convector_core_storage_1.BaseStorage.current.get(id, storageOptions);
|
|
30
|
-
const model = new type(content);
|
|
31
|
-
if ((content && model) && content.type !== new type('').type) {
|
|
32
|
-
if (storageOptions && storageOptions.enforceType) {
|
|
33
|
-
throw new Error(`Possible ID collision, element ${id} of type ${content.type} is not ${new type('').type}`);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
console.warn(`Possible ID collision, element ${id} of type ${content.type} is not ${new type('').type}`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return model;
|
|
21
|
+
return yup.object().shape({
|
|
22
|
+
id: yup.string().required(),
|
|
23
|
+
type: yup.string(),
|
|
24
|
+
...getPropertiesValidation(this.prototype)
|
|
40
25
|
});
|
|
41
26
|
}
|
|
42
|
-
static
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
27
|
+
static async getOne(id, type, storageOptions) {
|
|
28
|
+
type = type || this;
|
|
29
|
+
const content = await BaseStorage.current.get(id, storageOptions);
|
|
30
|
+
const model = new type(content);
|
|
31
|
+
if ((content && model) && content.type !== new type('').type) {
|
|
32
|
+
if (storageOptions && storageOptions.enforceType) {
|
|
33
|
+
throw new Error(`Possible ID collision, element ${id} of type ${content.type} is not ${new type('').type}`);
|
|
47
34
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
else {
|
|
36
|
+
console.warn(`Possible ID collision, element ${id} of type ${content.type} is not ${new type('').type}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return model;
|
|
51
40
|
}
|
|
52
|
-
static
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
41
|
+
static async query(...args) {
|
|
42
|
+
let type = this;
|
|
43
|
+
if (args[0] && 'type' in args[0] && args[0].type === ConvectorModel.type) {
|
|
44
|
+
type = args.shift();
|
|
45
|
+
}
|
|
46
|
+
const content = await BaseStorage.current.query(...args);
|
|
47
|
+
return Array.isArray(content) ? content.map(c => new type(c)) : new type(content);
|
|
57
48
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
yield this.save();
|
|
62
|
-
});
|
|
49
|
+
static async getAll(type) {
|
|
50
|
+
type = type || new this('').type;
|
|
51
|
+
return await ConvectorModel.query(this, { selector: { type } });
|
|
63
52
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (content.type !== this.type) {
|
|
68
|
-
throw new Error(`Possible ID collision, element ${this.id} of type ${content.type} is not ${this.type}`);
|
|
69
|
-
}
|
|
70
|
-
this.assign(content);
|
|
71
|
-
});
|
|
53
|
+
async update(content) {
|
|
54
|
+
this.assign(content);
|
|
55
|
+
await this.save();
|
|
72
56
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
57
|
+
async fetch(storageOptions) {
|
|
58
|
+
const content = await BaseStorage.current.get(this.id, storageOptions);
|
|
59
|
+
if (content.type !== this.type) {
|
|
60
|
+
throw new Error(`Possible ID collision, element ${this.id} of type ${content.type} is not ${this.type}`);
|
|
61
|
+
}
|
|
62
|
+
this.assign(content);
|
|
63
|
+
}
|
|
64
|
+
async history() {
|
|
65
|
+
const history = await BaseStorage.current.history(this.id);
|
|
66
|
+
return history.map(item => ({
|
|
67
|
+
txId: item.tx_id,
|
|
68
|
+
value: new this.constructor(item.value),
|
|
69
|
+
timestamp: item.timestamp
|
|
70
|
+
}));
|
|
82
71
|
}
|
|
83
|
-
save(storageOptions) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (!
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
throw new Error(`Model ${this.type} is not complete\n${JSON.stringify(this)}.
|
|
72
|
+
async save(storageOptions) {
|
|
73
|
+
this.assign(getDefaults(this), true);
|
|
74
|
+
if (!ensureRequired(this)) {
|
|
75
|
+
if (!this.id) {
|
|
76
|
+
throw new Error(`Model ${this.type} is missing the 'id' property \n${JSON.stringify(this)}`);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
throw new Error(`Model ${this.type} is not complete\n${JSON.stringify(this)}.
|
|
92
80
|
Check your model definition for more details.`);
|
|
93
|
-
}
|
|
94
81
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
82
|
+
}
|
|
83
|
+
InvalidIdError.test(this.id);
|
|
84
|
+
await BaseStorage.current.set(this.id, this, storageOptions);
|
|
98
85
|
}
|
|
99
86
|
clone() {
|
|
100
87
|
return new this.constructor(Object.assign({}, this));
|
|
@@ -114,7 +101,7 @@ class ConvectorModel {
|
|
|
114
101
|
const base = Object.keys(this).concat('id')
|
|
115
102
|
.filter(k => !k.startsWith('_'))
|
|
116
103
|
.filter(k => !skipEmpty || !(this[k] === undefined || this[k] === null))
|
|
117
|
-
.reduce((result, key) => (
|
|
104
|
+
.reduce((result, key) => ({ ...result, [key]: this[key] }), {});
|
|
118
105
|
return descriptors
|
|
119
106
|
.reduce((result, [key, desc]) => {
|
|
120
107
|
const hasGetter = desc && typeof desc.get === 'function';
|
|
@@ -130,25 +117,25 @@ class ConvectorModel {
|
|
|
130
117
|
return result;
|
|
131
118
|
}, base);
|
|
132
119
|
}
|
|
133
|
-
delete(storageOptions) {
|
|
134
|
-
|
|
135
|
-
yield convector_core_storage_1.BaseStorage.current.delete(this.id, storageOptions);
|
|
136
|
-
});
|
|
120
|
+
async delete(storageOptions) {
|
|
121
|
+
await BaseStorage.current.delete(this.id, storageOptions);
|
|
137
122
|
}
|
|
138
123
|
assign(content, defaults = false) {
|
|
139
|
-
const validated = ['id', 'type', ...
|
|
124
|
+
const validated = ['id', 'type', ...getValidatedProperties(this)];
|
|
140
125
|
const filteredContent = Object.keys(content)
|
|
141
126
|
.map(key => key.replace(/^_/, ''))
|
|
142
127
|
.filter(key => validated.indexOf(key) >= 0)
|
|
143
|
-
.reduce((result, key) => (
|
|
128
|
+
.reduce((result, key) => ({
|
|
129
|
+
...result,
|
|
130
|
+
[key]: content[key] !== undefined ? content[key] : content['_' + key]
|
|
131
|
+
}), {});
|
|
144
132
|
const afterDefaults = defaults ? this.toJSON(true) : {};
|
|
145
133
|
Object.assign(this, filteredContent, afterDefaults);
|
|
146
134
|
}
|
|
147
135
|
}
|
|
148
136
|
ConvectorModel.type = 'io.convector.model';
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
137
|
+
__decorate([
|
|
138
|
+
Required(),
|
|
139
|
+
Validate(yup.string())
|
|
152
140
|
], ConvectorModel.prototype, "id", void 0);
|
|
153
|
-
exports.ConvectorModel = ConvectorModel;
|
|
154
141
|
//# sourceMappingURL=convector-model.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convector-model.js","sourceRoot":"","sources":["../../src/convector-model.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"convector-model.js","sourceRoot":"","sources":["../../src/convector-model.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAE/D,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,2BAA2B,CAAC;AAyBnC,MAAM,OAAgB,cAAc;IAyGlC,YAAY,OAAgD;QAC1D,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO;SACR;QAED,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YAC/B,IAAI,CAAC,E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,GAAG,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC;SACtE,CAAC,EAAE,EAAE,CAAC,CAAC;QAEV,MAAM,aAAa,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACxD,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,eAAe,EAAE,aAAa,CAAC,CAAC;IACtD,CAAC;;AAjQc,mBAAI,GAAG,oBAAoB,CAAC;AAkF3C;IAFC,QAAQ,EAAE;IACV,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;0CACL"}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.defaultMetadataKey = g.ConvectorDefaultMetadataKey || Symbol('default');
|
|
7
|
-
g.ConvectorDefaultMetadataKey = exports.defaultMetadataKey;
|
|
8
|
-
function Default(defaultValue) {
|
|
1
|
+
import * as g from 'window-or-global';
|
|
2
|
+
import 'reflect-metadata';
|
|
3
|
+
export const defaultMetadataKey = g.ConvectorDefaultMetadataKey || Symbol('default');
|
|
4
|
+
g.ConvectorDefaultMetadataKey = defaultMetadataKey;
|
|
5
|
+
export function Default(defaultValue) {
|
|
9
6
|
return (target, key) => {
|
|
10
|
-
const defaults = Reflect.getMetadata(
|
|
11
|
-
Reflect.defineMetadata(
|
|
7
|
+
const defaults = Reflect.getMetadata(defaultMetadataKey, target) || {};
|
|
8
|
+
Reflect.defineMetadata(defaultMetadataKey, {
|
|
9
|
+
...defaults,
|
|
10
|
+
[key]: defaultValue
|
|
11
|
+
}, target);
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const defaults = Reflect.getMetadata(exports.defaultMetadataKey, obj);
|
|
14
|
+
export function getDefaults(obj) {
|
|
15
|
+
const defaults = Reflect.getMetadata(defaultMetadataKey, obj);
|
|
17
16
|
return !defaults ? {} : Object.keys(defaults)
|
|
18
|
-
.reduce((result, k) => (
|
|
17
|
+
.reduce((result, k) => ({
|
|
18
|
+
...result,
|
|
19
|
+
[k]: typeof defaults[k] === 'function' ? defaults[k]() : defaults[k]
|
|
20
|
+
}), {});
|
|
19
21
|
}
|
|
20
|
-
exports.getDefaults = getDefaults;
|
|
21
22
|
//# sourceMappingURL=default.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default.decorator.js","sourceRoot":"","sources":["../../src/default.decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"default.decorator.js","sourceRoot":"","sources":["../../src/default.decorator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAC;AACtC,OAAO,kBAAkB,CAAC;AAE1B,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,2BAA2B,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC;AACrF,CAAC,CAAC,2BAA2B,GAAG,kBAAkB,CAAC;AAEnD,MAAM,UAAU,OAAO,CAAI,YAAe;IACxC,OAAO,CAAC,MAAW,EAAE,GAAW,EAAE,EAAE;QAClC,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,kBAAkB,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;QAEvE,OAAO,CAAC,cAAc,CAAC,kBAAkB,EAAE;YACzC,GAAG,QAAQ;YACX,CAAC,GAAG,CAAC,EAAE,YAAY;SACpB,EAAE,MAAM,CAAC,CAAC;IACb,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,GAAQ;IAClC,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC;IAE9D,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;SAC1C,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QACtB,GAAG,MAAM;QACT,CAAC,CAAC,CAAC,EAAE,OAAO,QAAQ,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;KACrE,CAAC,EAAE,EAAE,CAAC,CAAC;AACZ,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
tslib_1.__exportStar(require("./required.decorator"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./validate.decorator"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./read-only.decorator"), exports);
|
|
1
|
+
export * from './convector-model';
|
|
2
|
+
export * from './default.decorator';
|
|
3
|
+
export * from './required.decorator';
|
|
4
|
+
export * from './validate.decorator';
|
|
5
|
+
export * from './read-only.decorator';
|
|
9
6
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAQA,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC"}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ReadOnly = void 0;
|
|
4
|
-
function ReadOnly() {
|
|
1
|
+
export function ReadOnly() {
|
|
5
2
|
return function (target, key) {
|
|
6
3
|
const getSet = {
|
|
7
4
|
get() {
|
|
@@ -19,5 +16,4 @@ function ReadOnly() {
|
|
|
19
16
|
Object.defineProperty(target, key, getSet);
|
|
20
17
|
};
|
|
21
18
|
}
|
|
22
|
-
exports.ReadOnly = ReadOnly;
|
|
23
19
|
//# sourceMappingURL=read-only.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-only.decorator.js","sourceRoot":"","sources":["../../src/read-only.decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"read-only.decorator.js","sourceRoot":"","sources":["../../src/read-only.decorator.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,QAAQ;IACtB,OAAO,UACL,MAAW,EACX,GAAW;QAEX,MAAM,MAAM,GAAG;YACb,GAAG;gBACD,OAAO,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;YACzB,CAAC;YACD,GAAG,CAAC,MAAM;gBACR,IAAI,MAAM,GAAG,MAAM,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;gBAC1C,MAAM,GAAG,CAAC,MAAM,IAAI,MAAM,KAAK,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;gBAE9D,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,KAAK,SAAS,CAAC,CAAC;oBAC/C,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;YAChD,CAAC;YACD,UAAU,EAAE,IAAI;YAChB,YAAY,EAAE,IAAI;SACnB,CAAC;QAEF,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IAC7C,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.requiredMetadataKey = g.ConvectorRequiredMetadataKey || Symbol('required');
|
|
7
|
-
g.ConvectorRequiredMetadataKey = exports.requiredMetadataKey;
|
|
8
|
-
function Required() {
|
|
1
|
+
import * as g from 'window-or-global';
|
|
2
|
+
import 'reflect-metadata';
|
|
3
|
+
export const requiredMetadataKey = g.ConvectorRequiredMetadataKey || Symbol('required');
|
|
4
|
+
g.ConvectorRequiredMetadataKey = requiredMetadataKey;
|
|
5
|
+
export function Required() {
|
|
9
6
|
return (target, key) => {
|
|
10
|
-
const required = Reflect.getMetadata(
|
|
11
|
-
Reflect.defineMetadata(
|
|
7
|
+
const required = Reflect.getMetadata(requiredMetadataKey, target);
|
|
8
|
+
Reflect.defineMetadata(requiredMetadataKey, {
|
|
9
|
+
...required,
|
|
10
|
+
[key]: true
|
|
11
|
+
}, target);
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
function ensureRequired(obj) {
|
|
14
|
+
export function ensureRequired(obj) {
|
|
16
15
|
let required = {};
|
|
17
16
|
try {
|
|
18
|
-
required = Reflect.getMetadata(
|
|
17
|
+
required = Reflect.getMetadata(requiredMetadataKey, obj) || {};
|
|
19
18
|
}
|
|
20
19
|
catch (e) {
|
|
21
20
|
}
|
|
@@ -28,5 +27,4 @@ function ensureRequired(obj) {
|
|
|
28
27
|
return res;
|
|
29
28
|
});
|
|
30
29
|
}
|
|
31
|
-
exports.ensureRequired = ensureRequired;
|
|
32
30
|
//# sourceMappingURL=required.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"required.decorator.js","sourceRoot":"","sources":["../../src/required.decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"required.decorator.js","sourceRoot":"","sources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ConvectorValidateMetadataKey || Symbol('validate');
|
|
7
|
-
g.ConvectorValidateMetadataKey = exports.validateMetadataKey;
|
|
8
|
-
function Validate(input) {
|
|
1
|
+
import * as g from 'window-or-global';
|
|
2
|
+
import 'reflect-metadata';
|
|
3
|
+
export const validateMetadataKey = g.ConvectorValidateMetadataKey || Symbol('validate');
|
|
4
|
+
g.ConvectorValidateMetadataKey = validateMetadataKey;
|
|
5
|
+
export function Validate(input) {
|
|
9
6
|
let schema = input;
|
|
10
7
|
if ('schema' in input) {
|
|
11
8
|
schema = input.schema();
|
|
@@ -30,23 +27,23 @@ function Validate(input) {
|
|
|
30
27
|
configurable: true
|
|
31
28
|
};
|
|
32
29
|
Object.defineProperty(target, key, getSet);
|
|
33
|
-
const validated = Reflect.getMetadata(
|
|
34
|
-
Reflect.defineMetadata(
|
|
30
|
+
const validated = Reflect.getMetadata(validateMetadataKey, target);
|
|
31
|
+
Reflect.defineMetadata(validateMetadataKey, {
|
|
32
|
+
...validated,
|
|
33
|
+
[key]: schema
|
|
34
|
+
}, target);
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
function getPropertiesValidation(obj) {
|
|
37
|
+
export function getPropertiesValidation(obj) {
|
|
39
38
|
let validated = {};
|
|
40
39
|
try {
|
|
41
|
-
validated = Reflect.getMetadata(
|
|
40
|
+
validated = Reflect.getMetadata(validateMetadataKey, obj) || {};
|
|
42
41
|
}
|
|
43
42
|
catch (e) {
|
|
44
43
|
}
|
|
45
44
|
return validated;
|
|
46
45
|
}
|
|
47
|
-
|
|
48
|
-
function getValidatedProperties(obj) {
|
|
46
|
+
export function getValidatedProperties(obj) {
|
|
49
47
|
return Object.keys(getPropertiesValidation(obj));
|
|
50
48
|
}
|
|
51
|
-
exports.getValidatedProperties = getValidatedProperties;
|
|
52
49
|
//# sourceMappingURL=validate.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.decorator.js","sourceRoot":"","sources":["../../src/validate.decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate.decorator.js","sourceRoot":"","sources":["../../src/validate.decorator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAC;AACtC,OAAO,kBAAkB,CAAC;AAE1B,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,4BAA4B,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC;AACxF,CAAC,CAAC,4BAA4B,GAAG,mBAAmB,CAAC;AAErD,MAAM,UAAU,QAAQ,CAAI,KAA8C;IACxE,IAAI,MAAM,GAAG,KAAkB,CAAC;IAEhC,IAAI,QAAQ,IAAI,KAAK,EAAE;QACrB,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;KACzB;IAED,OAAO,CAAC,MAAW,EAAE,GAAW,EAAE,EAAE;QAClC,MAAM,MAAM,GAAG;YACb,GAAG;gBACD,OAAO,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;YACzB,CAAC;YACD,GAAG,CAAC,MAAM;gBACR,IAAI,MAAM,GAAG,MAAM,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;gBAC1C,MAAM,GAAG,CAAC,MAAM,IAAI,MAAM,KAAK,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;gBAE9D,IAAI;oBACF,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,GAAG,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;iBAClE;gBAAC,OAAO,EAAE,EAAE;oBACX,EAAE,CAAC,OAAO,GAAG,oBAAoB,GAAG,eAAe,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,CAAC;oBAC3F,MAAM,EAAE,CAAC;iBACV;YAEH,CAAC;YACD,UAAU,EAAE,IAAI;YAChB,YAAY,EAAE,IAAI;SACnB,CAAC;QAEF,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;QAE3C,MAAM,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC;QACnE,OAAO,CAAC,cAAc,CAAC,mBAAmB,EAAE;YAC1C,GAAG,SAAS;YACZ,CAAC,GAAG,CAAC,EAAE,MAAM;SACd,EAAE,MAAM,CAAC,CAAC;IACb,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,GAAQ;IAC9C,IAAI,SAAS,GAAG,EAAE,CAAC;IAEnB,IAAI;QACF,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,mBAAmB,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;KACjE;IAAC,OAAO,CAAC,EAAE;KAEX;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,GAAQ;IAC7C,OAAO,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,CAAC,CAAC;AACnD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apex-pub/convector-core-model",
|
|
3
|
-
"version": "1.4.1-
|
|
3
|
+
"version": "1.4.1-4-alpha.6064f94c",
|
|
4
4
|
"description": "Convector Model base class",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"reflect-metadata": ">=0.1.12"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@apex-pub/convector-core-errors": "
|
|
54
|
-
"@apex-pub/convector-core-storage": "
|
|
53
|
+
"@apex-pub/convector-core-errors": "1.4.1-4-alpha.6064f94c",
|
|
54
|
+
"@apex-pub/convector-core-storage": "1.4.1-4-alpha.6064f94c",
|
|
55
55
|
"window-or-global": "^1.0.1",
|
|
56
56
|
"yup": "^0.26.10"
|
|
57
57
|
},
|