@apex-pub/convector-core-model 1.4.1-4-alpha.8939dce7 → 1.4.1-4-alpha.4ece38f3
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 +87 -74
- package/dist/src/convector-model.js.map +1 -1
- package/dist/src/default.decorator.js +16 -16
- package/dist/src/default.decorator.js.map +1 -1
- package/dist/src/index.d.ts +5 -5
- package/dist/src/index.js +8 -5
- package/dist/src/index.js.map +1 -1
- package/dist/src/read-only.decorator.js +5 -1
- package/dist/src/read-only.decorator.js.map +1 -1
- package/dist/src/required.decorator.js +15 -12
- package/dist/src/required.decorator.js.map +1 -1
- package/dist/src/validate.decorator.js +17 -13
- package/dist/src/validate.decorator.js.map +1 -1
- package/package.json +3 -4
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConvectorModel = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const yup = tslib_1.__importStar(require("yup"));
|
|
6
|
+
const convector_core_errors_1 = require("@apex-pub/convector-core-errors");
|
|
7
|
+
const convector_core_storage_1 = require("@apex-pub/convector-core-storage");
|
|
8
|
+
const validate_decorator_1 = require("../src/validate.decorator");
|
|
9
|
+
const default_decorator_1 = require("../src/default.decorator");
|
|
10
|
+
const required_decorator_1 = require("../src/required.decorator");
|
|
11
|
+
const validate_decorator_2 = require("../src/validate.decorator");
|
|
12
|
+
class ConvectorModel {
|
|
10
13
|
constructor(content) {
|
|
11
14
|
if (!content) {
|
|
12
15
|
return;
|
|
@@ -18,70 +21,80 @@ export class ConvectorModel {
|
|
|
18
21
|
this.assign(content);
|
|
19
22
|
}
|
|
20
23
|
static schema() {
|
|
21
|
-
return yup.object().shape({
|
|
22
|
-
id: yup.string().required(),
|
|
23
|
-
type: yup.string(),
|
|
24
|
-
...getPropertiesValidation(this.prototype)
|
|
25
|
-
});
|
|
24
|
+
return yup.object().shape(Object.assign({ id: yup.string().required(), type: yup.string() }, (0, validate_decorator_2.getPropertiesValidation)(this.prototype)));
|
|
26
25
|
}
|
|
27
|
-
static
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
static getOne(id, type, storageOptions) {
|
|
27
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
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
|
+
}
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
return model;
|
|
40
|
+
});
|
|
40
41
|
}
|
|
41
|
-
static
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
type
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
static query(...args) {
|
|
43
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
let type = this;
|
|
45
|
+
if (args[0] && 'type' in args[0] && args[0].type === ConvectorModel.type) {
|
|
46
|
+
type = args.shift();
|
|
47
|
+
}
|
|
48
|
+
const content = yield convector_core_storage_1.BaseStorage.current.query(...args);
|
|
49
|
+
return Array.isArray(content) ? content.map(c => new type(c)) : new type(content);
|
|
50
|
+
});
|
|
48
51
|
}
|
|
49
|
-
static
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
static getAll(type) {
|
|
53
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
type = type || new this('').type;
|
|
55
|
+
return yield ConvectorModel.query(this, { selector: { type } });
|
|
56
|
+
});
|
|
52
57
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
update(content) {
|
|
59
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
this.assign(content);
|
|
61
|
+
yield this.save();
|
|
62
|
+
});
|
|
56
63
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
fetch(storageOptions) {
|
|
65
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
const content = yield convector_core_storage_1.BaseStorage.current.get(this.id, storageOptions);
|
|
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
|
+
});
|
|
63
72
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
73
|
+
history() {
|
|
74
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const history = yield convector_core_storage_1.BaseStorage.current.history(this.id);
|
|
76
|
+
return history.map(item => ({
|
|
77
|
+
txId: item.tx_id,
|
|
78
|
+
value: new this.constructor(item.value),
|
|
79
|
+
timestamp: item.timestamp
|
|
80
|
+
}));
|
|
81
|
+
});
|
|
71
82
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (!
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
save(storageOptions) {
|
|
84
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
this.assign((0, default_decorator_1.getDefaults)(this), true);
|
|
86
|
+
if (!(0, required_decorator_1.ensureRequired)(this)) {
|
|
87
|
+
if (!this.id) {
|
|
88
|
+
throw new Error(`Model ${this.type} is missing the 'id' property \n${JSON.stringify(this)}`);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
throw new Error(`Model ${this.type} is not complete\n${JSON.stringify(this)}.
|
|
80
92
|
Check your model definition for more details.`);
|
|
93
|
+
}
|
|
81
94
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
95
|
+
convector_core_errors_1.InvalidIdError.test(this.id);
|
|
96
|
+
yield convector_core_storage_1.BaseStorage.current.set(this.id, this, storageOptions);
|
|
97
|
+
});
|
|
85
98
|
}
|
|
86
99
|
clone() {
|
|
87
100
|
return new this.constructor(Object.assign({}, this));
|
|
@@ -101,7 +114,7 @@ export class ConvectorModel {
|
|
|
101
114
|
const base = Object.keys(this).concat('id')
|
|
102
115
|
.filter(k => !k.startsWith('_'))
|
|
103
116
|
.filter(k => !skipEmpty || !(this[k] === undefined || this[k] === null))
|
|
104
|
-
.reduce((result, key) => ({
|
|
117
|
+
.reduce((result, key) => (Object.assign(Object.assign({}, result), { [key]: this[key] })), {});
|
|
105
118
|
return descriptors
|
|
106
119
|
.reduce((result, [key, desc]) => {
|
|
107
120
|
const hasGetter = desc && typeof desc.get === 'function';
|
|
@@ -117,25 +130,25 @@ export class ConvectorModel {
|
|
|
117
130
|
return result;
|
|
118
131
|
}, base);
|
|
119
132
|
}
|
|
120
|
-
|
|
121
|
-
|
|
133
|
+
delete(storageOptions) {
|
|
134
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
yield convector_core_storage_1.BaseStorage.current.delete(this.id, storageOptions);
|
|
136
|
+
});
|
|
122
137
|
}
|
|
123
138
|
assign(content, defaults = false) {
|
|
124
|
-
const validated = ['id', 'type', ...getValidatedProperties(this)];
|
|
139
|
+
const validated = ['id', 'type', ...(0, validate_decorator_2.getValidatedProperties)(this)];
|
|
125
140
|
const filteredContent = Object.keys(content)
|
|
126
141
|
.map(key => key.replace(/^_/, ''))
|
|
127
142
|
.filter(key => validated.indexOf(key) >= 0)
|
|
128
|
-
.reduce((result, key) => ({
|
|
129
|
-
...result,
|
|
130
|
-
[key]: content[key] !== undefined ? content[key] : content['_' + key]
|
|
131
|
-
}), {});
|
|
143
|
+
.reduce((result, key) => (Object.assign(Object.assign({}, result), { [key]: content[key] !== undefined ? content[key] : content['_' + key] })), {});
|
|
132
144
|
const afterDefaults = defaults ? this.toJSON(true) : {};
|
|
133
145
|
Object.assign(this, filteredContent, afterDefaults);
|
|
134
146
|
}
|
|
135
147
|
}
|
|
136
148
|
ConvectorModel.type = 'io.convector.model';
|
|
137
|
-
__decorate([
|
|
138
|
-
Required(),
|
|
139
|
-
Validate(yup.string())
|
|
149
|
+
tslib_1.__decorate([
|
|
150
|
+
(0, required_decorator_1.Required)(),
|
|
151
|
+
(0, validate_decorator_1.Validate)(yup.string())
|
|
140
152
|
], ConvectorModel.prototype, "id", void 0);
|
|
153
|
+
exports.ConvectorModel = ConvectorModel;
|
|
141
154
|
//# 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,iDAA2B;AAC3B,2EAAiE;AACjE,6EAA+D;AAE/D,kEAAqD;AACrD,gEAAuD;AACvD,kEAAqE;AACrE,kEAGmC;AAyBnC,MAAsB,cAAc;IAyGlC,YAAY,OAAgD;QAC1D,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO;SACR;QAED,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YAC/B,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC;YAClB,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S,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC,IACrE,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,IAAA,6BAAQ,GAAE;IACV,IAAA,6BAAQ,EAAC,GAAG,CAAC,MAAM,EAAE,CAAC;0CACL;AAnFpB,wCAmQC"}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDefaults = exports.Default = exports.defaultMetadataKey = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const g = tslib_1.__importStar(require("window-or-global"));
|
|
6
|
+
require("reflect-metadata");
|
|
7
|
+
exports.defaultMetadataKey = g.ConvectorDefaultMetadataKey || Symbol('default');
|
|
8
|
+
g.ConvectorDefaultMetadataKey = exports.defaultMetadataKey;
|
|
9
|
+
function Default(defaultValue) {
|
|
6
10
|
return (target, key) => {
|
|
7
|
-
const defaults = Reflect.getMetadata(defaultMetadataKey, target) || {};
|
|
8
|
-
Reflect.defineMetadata(defaultMetadataKey, {
|
|
9
|
-
...defaults,
|
|
10
|
-
[key]: defaultValue
|
|
11
|
-
}, target);
|
|
11
|
+
const defaults = Reflect.getMetadata(exports.defaultMetadataKey, target) || {};
|
|
12
|
+
Reflect.defineMetadata(exports.defaultMetadataKey, Object.assign(Object.assign({}, defaults), { [key]: defaultValue }), target);
|
|
12
13
|
};
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
exports.Default = Default;
|
|
16
|
+
function getDefaults(obj) {
|
|
17
|
+
const defaults = Reflect.getMetadata(exports.defaultMetadataKey, obj);
|
|
16
18
|
return !defaults ? {} : Object.keys(defaults)
|
|
17
|
-
.reduce((result, k) => ({
|
|
18
|
-
...result,
|
|
19
|
-
[k]: typeof defaults[k] === 'function' ? defaults[k]() : defaults[k]
|
|
20
|
-
}), {});
|
|
19
|
+
.reduce((result, k) => (Object.assign(Object.assign({}, result), { [k]: typeof defaults[k] === 'function' ? defaults[k]() : defaults[k] })), {});
|
|
21
20
|
}
|
|
21
|
+
exports.getDefaults = getDefaults;
|
|
22
22
|
//# sourceMappingURL=default.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default.decorator.js","sourceRoot":"","sources":["../../src/default.decorator.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"default.decorator.js","sourceRoot":"","sources":["../../src/default.decorator.ts"],"names":[],"mappings":";;;;AAEA,4DAAsC;AACtC,4BAA0B;AAEb,QAAA,kBAAkB,GAAG,CAAC,CAAC,2BAA2B,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC;AACrF,CAAC,CAAC,2BAA2B,GAAG,0BAAkB,CAAC;AAEnD,SAAgB,OAAO,CAAI,YAAe;IACxC,OAAO,CAAC,MAAW,EAAE,GAAW,EAAE,EAAE;QAClC,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,0BAAkB,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;QAEvE,OAAO,CAAC,cAAc,CAAC,0BAAkB,kCACpC,QAAQ,KACX,CAAC,GAAG,CAAC,EAAE,YAAY,KAClB,MAAM,CAAC,CAAC;IACb,CAAC,CAAC;AACJ,CAAC;AATD,0BASC;AAED,SAAgB,WAAW,CAAC,GAAQ;IAClC,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,0BAAkB,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,iCAClB,MAAM,KACT,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,IACpE,EAAE,EAAE,CAAC,CAAC;AACZ,CAAC;AARD,kCAQC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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
|
|
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';
|
package/dist/src/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./convector-model"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./default.decorator"), exports);
|
|
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);
|
|
6
9
|
//# 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":"AAQA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAQA,4DAAkC;AAClC,8DAAoC;AACpC,+DAAqC;AACrC,+DAAqC;AACrC,gEAAsC"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReadOnly = void 0;
|
|
4
|
+
function ReadOnly() {
|
|
2
5
|
return function (target, key) {
|
|
3
6
|
const getSet = {
|
|
4
7
|
get() {
|
|
@@ -16,4 +19,5 @@ export function ReadOnly() {
|
|
|
16
19
|
Object.defineProperty(target, key, getSet);
|
|
17
20
|
};
|
|
18
21
|
}
|
|
22
|
+
exports.ReadOnly = ReadOnly;
|
|
19
23
|
//# 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":"AAGA,
|
|
1
|
+
{"version":3,"file":"read-only.decorator.js","sourceRoot":"","sources":["../../src/read-only.decorator.ts"],"names":[],"mappings":";;;AAGA,SAAgB,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;AAtBD,4BAsBC"}
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensureRequired = exports.Required = exports.requiredMetadataKey = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const g = tslib_1.__importStar(require("window-or-global"));
|
|
6
|
+
require("reflect-metadata");
|
|
7
|
+
exports.requiredMetadataKey = g.ConvectorRequiredMetadataKey || Symbol('required');
|
|
8
|
+
g.ConvectorRequiredMetadataKey = exports.requiredMetadataKey;
|
|
9
|
+
function Required() {
|
|
6
10
|
return (target, key) => {
|
|
7
|
-
const required = Reflect.getMetadata(requiredMetadataKey, target);
|
|
8
|
-
Reflect.defineMetadata(requiredMetadataKey, {
|
|
9
|
-
...required,
|
|
10
|
-
[key]: true
|
|
11
|
-
}, target);
|
|
11
|
+
const required = Reflect.getMetadata(exports.requiredMetadataKey, target);
|
|
12
|
+
Reflect.defineMetadata(exports.requiredMetadataKey, Object.assign(Object.assign({}, required), { [key]: true }), target);
|
|
12
13
|
};
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
+
exports.Required = Required;
|
|
16
|
+
function ensureRequired(obj) {
|
|
15
17
|
let required = {};
|
|
16
18
|
try {
|
|
17
|
-
required = Reflect.getMetadata(requiredMetadataKey, obj) || {};
|
|
19
|
+
required = Reflect.getMetadata(exports.requiredMetadataKey, obj) || {};
|
|
18
20
|
}
|
|
19
21
|
catch (e) {
|
|
20
22
|
}
|
|
@@ -27,4 +29,5 @@ export function ensureRequired(obj) {
|
|
|
27
29
|
return res;
|
|
28
30
|
});
|
|
29
31
|
}
|
|
32
|
+
exports.ensureRequired = ensureRequired;
|
|
30
33
|
//# sourceMappingURL=required.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"required.decorator.js","sourceRoot":"","sources":["../../src/required.decorator.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"required.decorator.js","sourceRoot":"","sources":["../../src/required.decorator.ts"],"names":[],"mappings":";;;;AAEA,4DAAsC;AACtC,4BAA0B;AAEb,QAAA,mBAAmB,GAAG,CAAC,CAAC,4BAA4B,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC;AACxF,CAAC,CAAC,4BAA4B,GAAG,2BAAmB,CAAC;AAErD,SAAgB,QAAQ;IACtB,OAAO,CAAC,MAAW,EAAE,GAAW,EAAE,EAAE;QAClC,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,2BAAmB,EAAE,MAAM,CAAC,CAAC;QAElE,OAAO,CAAC,cAAc,CAAC,2BAAmB,kCACrC,QAAQ,KACX,CAAC,GAAG,CAAC,EAAE,IAAI,KACV,MAAM,CAAC,CAAC;IACb,CAAC,CAAC;AACJ,CAAC;AATD,4BASC;AAED,SAAgB,cAAc,CAAC,GAAQ;IACrC,IAAI,QAAQ,GAAG,EAAE,CAAC;IAElB,IAAI;QACF,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,2BAAmB,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;KAChE;IAAC,OAAO,CAAC,EAAE;KAEX;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;SACzB,KAAK,CAAC,CAAC,CAAC,EAAE;QACT,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;QAC/C,IAAI,CAAC,GAAG,EAAE;YACR,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,iCAAiC,CAAC,CAAC;SAC5E;QACD,OAAO,GAAG,CAAC;IACb,CAAC,CAAC,CAAC;AACP,CAAC;AAjBD,wCAiBC"}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getValidatedProperties = exports.getPropertiesValidation = exports.Validate = exports.validateMetadataKey = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const g = tslib_1.__importStar(require("window-or-global"));
|
|
6
|
+
require("reflect-metadata");
|
|
7
|
+
exports.validateMetadataKey = g.ConvectorValidateMetadataKey || Symbol('validate');
|
|
8
|
+
g.ConvectorValidateMetadataKey = exports.validateMetadataKey;
|
|
9
|
+
function Validate(input) {
|
|
6
10
|
let schema = input;
|
|
7
11
|
if ('schema' in input) {
|
|
8
12
|
schema = input.schema();
|
|
@@ -27,23 +31,23 @@ export function Validate(input) {
|
|
|
27
31
|
configurable: true
|
|
28
32
|
};
|
|
29
33
|
Object.defineProperty(target, key, getSet);
|
|
30
|
-
const validated = Reflect.getMetadata(validateMetadataKey, target);
|
|
31
|
-
Reflect.defineMetadata(validateMetadataKey, {
|
|
32
|
-
...validated,
|
|
33
|
-
[key]: schema
|
|
34
|
-
}, target);
|
|
34
|
+
const validated = Reflect.getMetadata(exports.validateMetadataKey, target);
|
|
35
|
+
Reflect.defineMetadata(exports.validateMetadataKey, Object.assign(Object.assign({}, validated), { [key]: schema }), target);
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
+
exports.Validate = Validate;
|
|
39
|
+
function getPropertiesValidation(obj) {
|
|
38
40
|
let validated = {};
|
|
39
41
|
try {
|
|
40
|
-
validated = Reflect.getMetadata(validateMetadataKey, obj) || {};
|
|
42
|
+
validated = Reflect.getMetadata(exports.validateMetadataKey, obj) || {};
|
|
41
43
|
}
|
|
42
44
|
catch (e) {
|
|
43
45
|
}
|
|
44
46
|
return validated;
|
|
45
47
|
}
|
|
46
|
-
|
|
48
|
+
exports.getPropertiesValidation = getPropertiesValidation;
|
|
49
|
+
function getValidatedProperties(obj) {
|
|
47
50
|
return Object.keys(getPropertiesValidation(obj));
|
|
48
51
|
}
|
|
52
|
+
exports.getValidatedProperties = getValidatedProperties;
|
|
49
53
|
//# sourceMappingURL=validate.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.decorator.js","sourceRoot":"","sources":["../../src/validate.decorator.ts"],"names":[],"mappings":"AAIA,
|
|
1
|
+
{"version":3,"file":"validate.decorator.js","sourceRoot":"","sources":["../../src/validate.decorator.ts"],"names":[],"mappings":";;;;AAIA,4DAAsC;AACtC,4BAA0B;AAEb,QAAA,mBAAmB,GAAG,CAAC,CAAC,4BAA4B,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC;AACxF,CAAC,CAAC,4BAA4B,GAAG,2BAAmB,CAAC;AAErD,SAAgB,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,CAA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,CAAC,CAAC;AACnD,CAAC;AAFD,wDAEC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apex-pub/convector-core-model",
|
|
3
|
-
"version": "1.4.1-4-alpha.
|
|
3
|
+
"version": "1.4.1-4-alpha.4ece38f3",
|
|
4
4
|
"description": "Convector Model base class",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
|
-
"type": "module",
|
|
7
6
|
"repository": {
|
|
8
7
|
"type": "git",
|
|
9
8
|
"url": "https://github.com/hyperledger-labs/convector/tree/develop/%40worldsibu/convector-core-model"
|
|
@@ -51,8 +50,8 @@
|
|
|
51
50
|
"reflect-metadata": ">=0.1.12"
|
|
52
51
|
},
|
|
53
52
|
"dependencies": {
|
|
54
|
-
"@apex-pub/convector-core-errors": "1.4.1-4-alpha.
|
|
55
|
-
"@apex-pub/convector-core-storage": "1.4.1-4-alpha.
|
|
53
|
+
"@apex-pub/convector-core-errors": "1.4.1-4-alpha.4ece38f3",
|
|
54
|
+
"@apex-pub/convector-core-storage": "1.4.1-4-alpha.4ece38f3",
|
|
56
55
|
"window-or-global": "^1.0.1",
|
|
57
56
|
"yup": "^0.26.10"
|
|
58
57
|
},
|