@apex-pub/convector-core-model 1.5.2-0-alpha.51b9133d → 2.0.0-alpha.3
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.d.ts +4 -4
- package/dist/src/convector-model.js +115 -194
- package/dist/src/convector-model.js.map +1 -1
- package/dist/src/default.decorator.js +14 -11
- package/dist/src/default.decorator.js.map +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/read-only.decorator.js +9 -8
- package/dist/src/read-only.decorator.js.map +1 -1
- package/dist/src/required.decorator.js +13 -10
- package/dist/src/required.decorator.js.map +1 -1
- package/dist/src/validate.decorator.js +19 -16
- package/dist/src/validate.decorator.js.map +1 -1
- package/package.json +9 -9
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as yup from 'yup';
|
|
2
|
-
export
|
|
2
|
+
export type RequiredKeys<T> = {
|
|
3
3
|
[K in keyof T]-?: string extends K ? never : number extends K ? never : {} extends Pick<T, K> ? never : K;
|
|
4
4
|
} extends {
|
|
5
5
|
[_ in keyof T]-?: infer U;
|
|
6
6
|
} ? U extends keyof T ? U : never : never;
|
|
7
|
-
export
|
|
7
|
+
export type OptionalKeys<T> = {
|
|
8
8
|
[K in keyof T]-?: string extends K ? never : number extends K ? never : {} extends Pick<T, K> ? K : never;
|
|
9
9
|
} extends {
|
|
10
10
|
[_ in keyof T]-?: infer U;
|
|
@@ -31,7 +31,7 @@ export declare abstract class ConvectorModel<T extends ConvectorModel<any>> {
|
|
|
31
31
|
static query<T>(type: new (content: any) => T, ...args: any[]): Promise<T | T[]>;
|
|
32
32
|
static getAll<T extends ConvectorModel<any>>(this: new (content: any) => T, type?: string): Promise<T[]>;
|
|
33
33
|
id: string;
|
|
34
|
-
readonly
|
|
34
|
+
abstract readonly type: string;
|
|
35
35
|
constructor();
|
|
36
36
|
constructor(id: string);
|
|
37
37
|
constructor(content: {
|
|
@@ -48,5 +48,5 @@ export declare abstract class ConvectorModel<T extends ConvectorModel<any>> {
|
|
|
48
48
|
[key in keyof T]?: T[key];
|
|
49
49
|
};
|
|
50
50
|
delete(storageOptions?: any): Promise<void>;
|
|
51
|
-
private assign
|
|
51
|
+
private assign;
|
|
52
52
|
}
|
|
@@ -1,15 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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 {
|
|
13
|
+
static schema() {
|
|
14
|
+
return yup.object().shape({
|
|
15
|
+
id: yup.string().required(),
|
|
16
|
+
type: yup.string(),
|
|
17
|
+
...(0, validate_decorator_2.getPropertiesValidation)(this.prototype)
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
static async getOne(id, type, storageOptions) {
|
|
21
|
+
type = type || this;
|
|
22
|
+
const content = await convector_core_storage_1.BaseStorage.current.get(id, storageOptions);
|
|
23
|
+
const model = new type(content);
|
|
24
|
+
if ((content && model) && content.type !== new type('').type) {
|
|
25
|
+
if (storageOptions && storageOptions.enforceType) {
|
|
26
|
+
throw new Error(`Possible ID collision, element ${id} of type ${content.type} is not ${new type('').type}`);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
console.warn(`Possible ID collision, element ${id} of type ${content.type} is not ${new type('').type}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return model;
|
|
33
|
+
}
|
|
34
|
+
static async query(...args) {
|
|
35
|
+
let type = this;
|
|
36
|
+
if (args[0] && 'type' in args[0] && args[0].type === ConvectorModel.type) {
|
|
37
|
+
type = args.shift();
|
|
38
|
+
}
|
|
39
|
+
const content = await convector_core_storage_1.BaseStorage.current.query(...args);
|
|
40
|
+
return Array.isArray(content) ? content.map(c => new type(c)) : new type(content);
|
|
41
|
+
}
|
|
42
|
+
static async getAll(type) {
|
|
43
|
+
type = type || new this('').type;
|
|
44
|
+
return await ConvectorModel.query(this, { selector: { type } });
|
|
45
|
+
}
|
|
46
|
+
constructor(content) {
|
|
13
47
|
if (!content) {
|
|
14
48
|
return;
|
|
15
49
|
}
|
|
@@ -19,166 +53,63 @@ var ConvectorModel = (function () {
|
|
|
19
53
|
}
|
|
20
54
|
this.assign(content);
|
|
21
55
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
case 0:
|
|
31
|
-
type = type || this;
|
|
32
|
-
return [4, convector_core_storage_1.BaseStorage.current.get(id, storageOptions)];
|
|
33
|
-
case 1:
|
|
34
|
-
content = _a.sent();
|
|
35
|
-
model = new type(content);
|
|
36
|
-
if ((content && model) && content.type !== new type('').type) {
|
|
37
|
-
if (storageOptions && storageOptions.enforceType) {
|
|
38
|
-
throw new Error("Possible ID collision, element " + id + " of type " + content.type + " is not " + new type('').type);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
console.warn("Possible ID collision, element " + id + " of type " + content.type + " is not " + new type('').type);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return [2, model];
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
ConvectorModel.query = function () {
|
|
50
|
-
var args = [];
|
|
51
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
52
|
-
args[_i] = arguments[_i];
|
|
56
|
+
async update(content) {
|
|
57
|
+
this.assign(content);
|
|
58
|
+
await this.save();
|
|
59
|
+
}
|
|
60
|
+
async fetch(storageOptions) {
|
|
61
|
+
const content = await convector_core_storage_1.BaseStorage.current.get(this.id, storageOptions);
|
|
62
|
+
if (content.type !== this.type) {
|
|
63
|
+
throw new Error(`Possible ID collision, element ${this.id} of type ${content.type} is not ${this.type}`);
|
|
53
64
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
ConvectorModel.prototype.update = function (content) {
|
|
84
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
85
|
-
return tslib_1.__generator(this, function (_a) {
|
|
86
|
-
switch (_a.label) {
|
|
87
|
-
case 0:
|
|
88
|
-
this.assign(content);
|
|
89
|
-
return [4, this.save()];
|
|
90
|
-
case 1:
|
|
91
|
-
_a.sent();
|
|
92
|
-
return [2];
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
};
|
|
97
|
-
ConvectorModel.prototype.fetch = function (storageOptions) {
|
|
98
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
99
|
-
var content;
|
|
100
|
-
return tslib_1.__generator(this, function (_a) {
|
|
101
|
-
switch (_a.label) {
|
|
102
|
-
case 0: return [4, convector_core_storage_1.BaseStorage.current.get(this.id, storageOptions)];
|
|
103
|
-
case 1:
|
|
104
|
-
content = _a.sent();
|
|
105
|
-
if (content.type !== this.type) {
|
|
106
|
-
throw new Error("Possible ID collision, element " + this.id + " of type " + content.type + " is not " + this.type);
|
|
107
|
-
}
|
|
108
|
-
this.assign(content);
|
|
109
|
-
return [2];
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
};
|
|
114
|
-
ConvectorModel.prototype.history = function () {
|
|
115
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
116
|
-
var _this = this;
|
|
117
|
-
var history;
|
|
118
|
-
return tslib_1.__generator(this, function (_a) {
|
|
119
|
-
switch (_a.label) {
|
|
120
|
-
case 0: return [4, convector_core_storage_1.BaseStorage.current.history(this.id)];
|
|
121
|
-
case 1:
|
|
122
|
-
history = _a.sent();
|
|
123
|
-
return [2, history.map(function (item) { return ({
|
|
124
|
-
txId: item.tx_id,
|
|
125
|
-
value: new _this.constructor(item.value),
|
|
126
|
-
timestamp: item.timestamp
|
|
127
|
-
}); })];
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
};
|
|
132
|
-
ConvectorModel.prototype.save = function (storageOptions) {
|
|
133
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
134
|
-
return tslib_1.__generator(this, function (_a) {
|
|
135
|
-
switch (_a.label) {
|
|
136
|
-
case 0:
|
|
137
|
-
this.assign(default_decorator_1.getDefaults(this), true);
|
|
138
|
-
if (!required_decorator_1.ensureRequired(this)) {
|
|
139
|
-
if (!this.id) {
|
|
140
|
-
throw new Error("Model " + this.type + " is missing the 'id' property \n" + JSON.stringify(this));
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
throw new Error("Model " + this.type + " is not complete\n" + JSON.stringify(this) + ".\n Check your model definition for more details.");
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
convector_core_errors_1.InvalidIdError.test(this.id);
|
|
147
|
-
return [4, convector_core_storage_1.BaseStorage.current.set(this.id, this, storageOptions)];
|
|
148
|
-
case 1:
|
|
149
|
-
_a.sent();
|
|
150
|
-
return [2];
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
};
|
|
155
|
-
ConvectorModel.prototype.clone = function () {
|
|
65
|
+
this.assign(content);
|
|
66
|
+
}
|
|
67
|
+
async history() {
|
|
68
|
+
const history = await convector_core_storage_1.BaseStorage.current.history(this.id);
|
|
69
|
+
return history.map(item => ({
|
|
70
|
+
txId: item.txId,
|
|
71
|
+
value: new this.constructor(item.value),
|
|
72
|
+
timestamp: item.timestamp
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
async save(storageOptions) {
|
|
76
|
+
this.assign((0, default_decorator_1.getDefaults)(this), true);
|
|
77
|
+
if (!(0, required_decorator_1.ensureRequired)(this)) {
|
|
78
|
+
if (!this.id) {
|
|
79
|
+
throw new Error(`Model ${this.type} is missing the 'id' property \n${JSON.stringify(this)}`);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
throw new Error(`Model ${this.type} is not complete\n${JSON.stringify(this)}.
|
|
83
|
+
Check your model definition for more details.`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
convector_core_errors_1.InvalidIdError.test(this.id);
|
|
87
|
+
await convector_core_storage_1.BaseStorage.current.set(this.id, this, storageOptions);
|
|
88
|
+
}
|
|
89
|
+
clone() {
|
|
156
90
|
return new this.constructor(Object.assign({}, this));
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
var protos = [];
|
|
162
|
-
var children = this;
|
|
91
|
+
}
|
|
92
|
+
toJSON(skipEmpty = false) {
|
|
93
|
+
let protos = [];
|
|
94
|
+
let children = this;
|
|
163
95
|
do {
|
|
164
96
|
children = Object.getPrototypeOf(children);
|
|
165
97
|
protos.push(children);
|
|
166
98
|
} while (children['__proto__'].constructor.name !== ConvectorModel.name);
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
99
|
+
const descriptors = protos.reduce((result, proto) => [
|
|
100
|
+
...result,
|
|
101
|
+
...Object.keys(proto)
|
|
102
|
+
.map(key => [key, Object.getOwnPropertyDescriptor(proto, key)])
|
|
103
|
+
], []);
|
|
104
|
+
const base = Object.keys(this).concat('id')
|
|
105
|
+
.filter(k => !k.startsWith('_'))
|
|
106
|
+
.filter(k => !skipEmpty || !(this[k] === undefined || this[k] === null))
|
|
107
|
+
.reduce((result, key) => ({ ...result, [key]: this[key] }), {});
|
|
176
108
|
return descriptors
|
|
177
|
-
.reduce(
|
|
178
|
-
|
|
179
|
-
var hasGetter = desc && typeof desc.get === 'function';
|
|
109
|
+
.reduce((result, [key, desc]) => {
|
|
110
|
+
const hasGetter = desc && typeof desc.get === 'function';
|
|
180
111
|
if (hasGetter) {
|
|
181
|
-
result[key] = desc.get.call(
|
|
112
|
+
result[key] = desc.get.call(this);
|
|
182
113
|
}
|
|
183
114
|
if (skipEmpty && (result[key] === undefined || result[key] === null)) {
|
|
184
115
|
delete result[key];
|
|
@@ -188,38 +119,28 @@ var ConvectorModel = (function () {
|
|
|
188
119
|
}
|
|
189
120
|
return result;
|
|
190
121
|
}, base);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (defaults === void 0) { defaults = false; }
|
|
206
|
-
var validated = ['id', 'type'].concat(validate_decorator_2.getValidatedProperties(this));
|
|
207
|
-
var filteredContent = Object.keys(content)
|
|
208
|
-
.map(function (key) { return key.replace(/^_/, ''); })
|
|
209
|
-
.filter(function (key) { return validated.indexOf(key) >= 0; })
|
|
210
|
-
.reduce(function (result, key) {
|
|
211
|
-
return (tslib_1.__assign({}, result, (_a = {}, _a[key] = content[key] !== undefined ? content[key] : content['_' + key], _a)));
|
|
212
|
-
var _a;
|
|
213
|
-
}, {});
|
|
214
|
-
var afterDefaults = defaults ? this.toJSON(true) : {};
|
|
122
|
+
}
|
|
123
|
+
async delete(storageOptions) {
|
|
124
|
+
await convector_core_storage_1.BaseStorage.current.delete(this.id, storageOptions);
|
|
125
|
+
}
|
|
126
|
+
assign(content, defaults = false) {
|
|
127
|
+
const validated = ['id', 'type', ...(0, validate_decorator_2.getValidatedProperties)(this)];
|
|
128
|
+
const filteredContent = Object.keys(content)
|
|
129
|
+
.map(key => key.replace(/^_/, ''))
|
|
130
|
+
.filter(key => validated.indexOf(key) >= 0)
|
|
131
|
+
.reduce((result, key) => ({
|
|
132
|
+
...result,
|
|
133
|
+
[key]: content[key] !== undefined ? content[key] : content['_' + key]
|
|
134
|
+
}), {});
|
|
135
|
+
const afterDefaults = defaults ? this.toJSON(true) : {};
|
|
215
136
|
Object.assign(this, filteredContent, afterDefaults);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
tslib_1.__decorate([
|
|
219
|
-
required_decorator_1.Required(),
|
|
220
|
-
validate_decorator_1.Validate(yup.string())
|
|
221
|
-
], ConvectorModel.prototype, "id", void 0);
|
|
222
|
-
return ConvectorModel;
|
|
223
|
-
}());
|
|
137
|
+
}
|
|
138
|
+
}
|
|
224
139
|
exports.ConvectorModel = ConvectorModel;
|
|
140
|
+
ConvectorModel.type = 'io.convector.model';
|
|
141
|
+
tslib_1.__decorate([
|
|
142
|
+
(0, required_decorator_1.Required)(),
|
|
143
|
+
(0, validate_decorator_1.Validate)(yup.string()),
|
|
144
|
+
tslib_1.__metadata("design:type", String)
|
|
145
|
+
], ConvectorModel.prototype, "id", void 0);
|
|
225
146
|
//# sourceMappingURL=convector-model.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convector-model.js","sourceRoot":"","sources":["../../src/convector-model.ts"],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exports.defaultMetadataKey = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const g = tslib_1.__importStar(require("window-or-global"));
|
|
5
6
|
require("reflect-metadata");
|
|
6
7
|
exports.defaultMetadataKey = g.ConvectorDefaultMetadataKey || Symbol('default');
|
|
7
8
|
g.ConvectorDefaultMetadataKey = exports.defaultMetadataKey;
|
|
8
9
|
function Default(defaultValue) {
|
|
9
|
-
return
|
|
10
|
-
|
|
11
|
-
Reflect.defineMetadata(exports.defaultMetadataKey,
|
|
12
|
-
|
|
10
|
+
return (target, key) => {
|
|
11
|
+
const defaults = Reflect.getMetadata(exports.defaultMetadataKey, target) || {};
|
|
12
|
+
Reflect.defineMetadata(exports.defaultMetadataKey, {
|
|
13
|
+
...defaults,
|
|
14
|
+
[key]: defaultValue
|
|
15
|
+
}, target);
|
|
13
16
|
};
|
|
14
17
|
}
|
|
15
18
|
exports.Default = Default;
|
|
16
19
|
function getDefaults(obj) {
|
|
17
|
-
|
|
20
|
+
const defaults = Reflect.getMetadata(exports.defaultMetadataKey, obj);
|
|
18
21
|
return !defaults ? {} : Object.keys(defaults)
|
|
19
|
-
.reduce(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}, {});
|
|
22
|
+
.reduce((result, k) => ({
|
|
23
|
+
...result,
|
|
24
|
+
[k]: typeof defaults[k] === 'function' ? defaults[k]() : defaults[k]
|
|
25
|
+
}), {});
|
|
23
26
|
}
|
|
24
27
|
exports.getDefaults = getDefaults;
|
|
25
28
|
//# 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,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,EAAE;YACzC,GAAG,QAAQ;YACX,CAAC,GAAG,CAAC,EAAE,YAAY;SACpB,EAAE,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,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;AARD,kCAQC"}
|
package/dist/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./convector-model"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./default.decorator"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./required.decorator"), exports);
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReadOnly = void 0;
|
|
3
4
|
function ReadOnly() {
|
|
4
5
|
return function (target, key) {
|
|
5
|
-
|
|
6
|
-
get
|
|
7
|
-
return this[
|
|
6
|
+
const getSet = {
|
|
7
|
+
get() {
|
|
8
|
+
return this[`_${key}`];
|
|
8
9
|
},
|
|
9
|
-
set
|
|
10
|
-
|
|
11
|
-
setter = !setter || setter === getSet.set ? (
|
|
12
|
-
this[
|
|
13
|
-
setter.call(this, newVal) : this[
|
|
10
|
+
set(newVal) {
|
|
11
|
+
let setter = target.__lookupSetter__(key);
|
|
12
|
+
setter = !setter || setter === getSet.set ? (v => v) : setter;
|
|
13
|
+
this[`_${key}`] = this[`_${key}`] === undefined ?
|
|
14
|
+
setter.call(this, newVal) : this[`_${key}`];
|
|
14
15
|
},
|
|
15
16
|
enumerable: true,
|
|
16
17
|
configurable: true
|
|
@@ -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,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,30 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
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"));
|
|
5
6
|
require("reflect-metadata");
|
|
6
7
|
exports.requiredMetadataKey = g.ConvectorRequiredMetadataKey || Symbol('required');
|
|
7
8
|
g.ConvectorRequiredMetadataKey = exports.requiredMetadataKey;
|
|
8
9
|
function Required() {
|
|
9
|
-
return
|
|
10
|
-
|
|
11
|
-
Reflect.defineMetadata(exports.requiredMetadataKey,
|
|
12
|
-
|
|
10
|
+
return (target, key) => {
|
|
11
|
+
const required = Reflect.getMetadata(exports.requiredMetadataKey, target);
|
|
12
|
+
Reflect.defineMetadata(exports.requiredMetadataKey, {
|
|
13
|
+
...required,
|
|
14
|
+
[key]: true
|
|
15
|
+
}, target);
|
|
13
16
|
};
|
|
14
17
|
}
|
|
15
18
|
exports.Required = Required;
|
|
16
19
|
function ensureRequired(obj) {
|
|
17
|
-
|
|
20
|
+
let required = {};
|
|
18
21
|
try {
|
|
19
22
|
required = Reflect.getMetadata(exports.requiredMetadataKey, obj) || {};
|
|
20
23
|
}
|
|
21
24
|
catch (e) {
|
|
22
25
|
}
|
|
23
26
|
return Object.keys(required)
|
|
24
|
-
.every(
|
|
25
|
-
|
|
27
|
+
.every(k => {
|
|
28
|
+
let res = !required[k] || obj[k] !== undefined;
|
|
26
29
|
if (!res) {
|
|
27
|
-
console.log(
|
|
30
|
+
console.log(`Validation error. Field ${k} is required but was not found.`);
|
|
28
31
|
}
|
|
29
32
|
return res;
|
|
30
33
|
});
|
|
@@ -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":["../../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,EAAE;YAC1C,GAAG,QAAQ;YACX,CAAC,GAAG,CAAC,EAAE,IAAI;SACZ,EAAE,MAAM,CAAC,CAAC;IACb,CAAC,CAAC;AACJ,CAAC;AATD,4BASC;AAED,SAAgB,cAAc,CAAC,GAAQ;IACrC,IAAI,QAAQ,GAAG,EAAE,CAAC;IAElB,IAAI,CAAC;QACH,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,2BAAmB,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;IACjE,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;IAEb,CAAC;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,CAAC;YACT,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,iCAAiC,CAAC,CAAC;QAC7E,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC,CAAC,CAAC;AACP,CAAC;AAjBD,wCAiBC"}
|
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
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"));
|
|
5
6
|
require("reflect-metadata");
|
|
6
7
|
exports.validateMetadataKey = g.ConvectorValidateMetadataKey || Symbol('validate');
|
|
7
8
|
g.ConvectorValidateMetadataKey = exports.validateMetadataKey;
|
|
8
9
|
function Validate(input) {
|
|
9
|
-
|
|
10
|
+
let schema = input;
|
|
10
11
|
if ('schema' in input) {
|
|
11
12
|
schema = input.schema();
|
|
12
13
|
}
|
|
13
|
-
return
|
|
14
|
-
|
|
15
|
-
get
|
|
16
|
-
return this[
|
|
14
|
+
return (target, key) => {
|
|
15
|
+
const getSet = {
|
|
16
|
+
get() {
|
|
17
|
+
return this[`_${key}`];
|
|
17
18
|
},
|
|
18
|
-
set
|
|
19
|
-
|
|
20
|
-
setter = !setter || setter === getSet.set ? (
|
|
19
|
+
set(newVal) {
|
|
20
|
+
let setter = target.__lookupSetter__(key);
|
|
21
|
+
setter = !setter || setter === getSet.set ? (v => v) : setter;
|
|
21
22
|
try {
|
|
22
|
-
this[
|
|
23
|
+
this[`_${key}`] = schema.validateSync(setter.call(this, newVal));
|
|
23
24
|
}
|
|
24
25
|
catch (ex) {
|
|
25
|
-
ex.message =
|
|
26
|
+
ex.message = `Error for field '${key}' with val '${JSON.stringify(newVal)}' ${ex.message}`;
|
|
26
27
|
throw ex;
|
|
27
28
|
}
|
|
28
29
|
},
|
|
@@ -30,14 +31,16 @@ function Validate(input) {
|
|
|
30
31
|
configurable: true
|
|
31
32
|
};
|
|
32
33
|
Object.defineProperty(target, key, getSet);
|
|
33
|
-
|
|
34
|
-
Reflect.defineMetadata(exports.validateMetadataKey,
|
|
35
|
-
|
|
34
|
+
const validated = Reflect.getMetadata(exports.validateMetadataKey, target);
|
|
35
|
+
Reflect.defineMetadata(exports.validateMetadataKey, {
|
|
36
|
+
...validated,
|
|
37
|
+
[key]: schema
|
|
38
|
+
}, target);
|
|
36
39
|
};
|
|
37
40
|
}
|
|
38
41
|
exports.Validate = Validate;
|
|
39
42
|
function getPropertiesValidation(obj) {
|
|
40
|
-
|
|
43
|
+
let validated = {};
|
|
41
44
|
try {
|
|
42
45
|
validated = Reflect.getMetadata(exports.validateMetadataKey, obj) || {};
|
|
43
46
|
}
|
|
@@ -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,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,CAAC;QACtB,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;IAC1B,CAAC;IAED,OAAO,CAAC,MAAW,EAAE,GAA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AO,CAAC,WAAW,CAAC,2BAAmB,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;IAClE,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;IAEb,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAVD,0DAUC;AAED,SAAgB,sBAAsB,CAAC,GAAQ;IAC7C,OAAO,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,CAAC,CAAC;AACnD,CAAC;AAFD,wDAEC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apex-pub/convector-core-model",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.3",
|
|
4
4
|
"description": "Convector Model base class",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -34,7 +34,6 @@
|
|
|
34
34
|
"clean:docs": "rimraf docs",
|
|
35
35
|
"build": "npm run clean && tsc",
|
|
36
36
|
"watch": "npm-scripts-watcher",
|
|
37
|
-
"prepare": "npm run build",
|
|
38
37
|
"lint": "tslint --fix -c '../../tslint.json' -p './tsconfig.json'",
|
|
39
38
|
"test": "mocha -r ts-node/register tests/**/*.spec.ts --reporter spec",
|
|
40
39
|
"predocs:generate": "npm run clean:docs",
|
|
@@ -50,21 +49,22 @@
|
|
|
50
49
|
"reflect-metadata": ">=0.1.12"
|
|
51
50
|
},
|
|
52
51
|
"dependencies": {
|
|
53
|
-
"@apex-pub/convector-core-errors": "
|
|
54
|
-
"@apex-pub/convector-core-storage": "
|
|
52
|
+
"@apex-pub/convector-core-errors": "^2.0.0-alpha.3",
|
|
53
|
+
"@apex-pub/convector-core-storage": "^2.0.0-alpha.3",
|
|
55
54
|
"tslib": "^1.9.0",
|
|
56
55
|
"window-or-global": "^1.0.1",
|
|
57
56
|
"yup": "^0.26.10"
|
|
58
57
|
},
|
|
59
58
|
"devDependencies": {
|
|
60
59
|
"http-server": "^0.11.1",
|
|
61
|
-
"mocha": "^
|
|
60
|
+
"mocha": "^10.8.2",
|
|
62
61
|
"npm-scripts-watcher": "^1.0.2",
|
|
63
62
|
"reflect-metadata": "^0.1.12",
|
|
64
63
|
"rimraf": "^2.6.2",
|
|
65
|
-
"ts-node": "^
|
|
66
|
-
"tslint": "^
|
|
64
|
+
"ts-node": "^10.9.2",
|
|
65
|
+
"tslint": "^6.1.3",
|
|
67
66
|
"typedoc": "^0.11.1",
|
|
68
|
-
"typescript": "
|
|
69
|
-
}
|
|
67
|
+
"typescript": "5.4.5"
|
|
68
|
+
},
|
|
69
|
+
"gitHead": "d275636ab454ac4f0c519c48695e25b36890633b"
|
|
70
70
|
}
|