@decaf-ts/db-decorators 0.6.20 → 0.7.1
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/README.md +1 -1
- package/dist/db-decorators.cjs +1 -1
- package/dist/db-decorators.cjs.map +1 -1
- package/dist/db-decorators.js +1 -1
- package/dist/db-decorators.js.map +1 -1
- package/lib/esm/identity/decorators.d.ts +1 -1
- package/lib/esm/identity/decorators.js +8 -4
- package/lib/esm/identity/decorators.js.map +1 -1
- package/lib/esm/identity/index.d.ts +0 -1
- package/lib/esm/identity/index.js +0 -1
- package/lib/esm/identity/index.js.map +1 -1
- package/lib/esm/index.d.ts +3 -1
- package/lib/esm/index.js +5 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/model/constants.js +1 -1
- package/lib/esm/model/constants.js.map +1 -1
- package/lib/esm/model/decorators.d.ts +3 -3
- package/lib/esm/model/decorators.js +9 -11
- package/lib/esm/model/decorators.js.map +1 -1
- package/lib/esm/model/index.d.ts +0 -2
- package/lib/esm/model/index.js +0 -2
- package/lib/esm/model/index.js.map +1 -1
- package/lib/esm/model/validation.d.ts +7 -7
- package/lib/esm/model/validation.js +52 -56
- package/lib/esm/model/validation.js.map +1 -1
- package/lib/esm/operations/constants.d.ts +11 -0
- package/lib/esm/operations/constants.js +12 -0
- package/lib/esm/operations/constants.js.map +1 -1
- package/lib/esm/operations/decorators.js +4 -6
- package/lib/esm/operations/decorators.js.map +1 -1
- package/lib/esm/overrides/Metadata.d.ts +50 -0
- package/lib/esm/overrides/Metadata.js +2 -0
- package/lib/esm/overrides/Metadata.js.map +1 -0
- package/lib/esm/overrides/Model.d.ts +65 -0
- package/lib/esm/overrides/Model.js +2 -0
- package/lib/esm/overrides/Model.js.map +1 -0
- package/lib/esm/overrides/index.d.ts +3 -0
- package/lib/esm/overrides/index.js +4 -0
- package/lib/esm/overrides/index.js.map +1 -0
- package/lib/esm/overrides/overrides.js +102 -0
- package/lib/esm/overrides/overrides.js.map +1 -0
- package/lib/esm/repository/BaseRepository.d.ts +3 -1
- package/lib/esm/repository/BaseRepository.js +6 -4
- package/lib/esm/repository/BaseRepository.js.map +1 -1
- package/lib/esm/repository/Context.d.ts +2 -1
- package/lib/esm/repository/Context.js.map +1 -1
- package/lib/esm/repository/Repository.d.ts +2 -9
- package/lib/esm/repository/Repository.js +0 -11
- package/lib/esm/repository/Repository.js.map +1 -1
- package/lib/esm/repository/types.d.ts +2 -1
- package/lib/esm/repository/utils.d.ts +2 -16
- package/lib/esm/repository/utils.js +96 -77
- package/lib/esm/repository/utils.js.map +1 -1
- package/lib/esm/validation/decorators.d.ts +1 -1
- package/lib/esm/validation/decorators.js +13 -8
- package/lib/esm/validation/decorators.js.map +1 -1
- package/lib/esm/validation/validators/ReadOnlyValidator.js +1 -1
- package/lib/esm/validation/validators/ReadOnlyValidator.js.map +1 -1
- package/lib/identity/decorators.cjs +7 -3
- package/lib/identity/decorators.d.ts +1 -1
- package/lib/identity/decorators.js.map +1 -1
- package/lib/identity/index.cjs +0 -1
- package/lib/identity/index.d.ts +0 -1
- package/lib/identity/index.js.map +1 -1
- package/lib/index.cjs +6 -2
- package/lib/index.d.ts +3 -1
- package/lib/index.js.map +1 -1
- package/lib/model/constants.cjs +1 -1
- package/lib/model/constants.js.map +1 -1
- package/lib/model/decorators.cjs +10 -12
- package/lib/model/decorators.d.ts +3 -3
- package/lib/model/decorators.js.map +1 -1
- package/lib/model/index.cjs +0 -2
- package/lib/model/index.d.ts +0 -2
- package/lib/model/index.js.map +1 -1
- package/lib/model/validation.cjs +51 -55
- package/lib/model/validation.d.ts +7 -7
- package/lib/model/validation.js.map +1 -1
- package/lib/operations/constants.cjs +13 -1
- package/lib/operations/constants.d.ts +11 -0
- package/lib/operations/constants.js.map +1 -1
- package/lib/operations/decorators.cjs +3 -5
- package/lib/operations/decorators.js.map +1 -1
- package/lib/overrides/Metadata.cjs +3 -0
- package/lib/overrides/Metadata.d.ts +50 -0
- package/lib/overrides/Metadata.js.map +1 -0
- package/lib/overrides/Model.cjs +4 -0
- package/lib/overrides/Model.d.ts +65 -0
- package/lib/overrides/Model.js.map +1 -0
- package/lib/overrides/index.cjs +20 -0
- package/lib/overrides/index.d.ts +3 -0
- package/lib/overrides/index.js.map +1 -0
- package/lib/overrides/overrides.cjs +104 -0
- package/lib/overrides/overrides.js.map +1 -0
- package/lib/repository/BaseRepository.cjs +6 -4
- package/lib/repository/BaseRepository.d.ts +3 -1
- package/lib/repository/BaseRepository.js.map +1 -1
- package/lib/repository/Context.d.ts +2 -1
- package/lib/repository/Context.js.map +1 -1
- package/lib/repository/Repository.cjs +0 -11
- package/lib/repository/Repository.d.ts +2 -9
- package/lib/repository/Repository.js.map +1 -1
- package/lib/repository/types.d.ts +2 -1
- package/lib/repository/utils.cjs +96 -78
- package/lib/repository/utils.d.ts +2 -16
- package/lib/repository/utils.js.map +1 -1
- package/lib/validation/decorators.cjs +16 -11
- package/lib/validation/decorators.d.ts +1 -1
- package/lib/validation/decorators.js.map +1 -1
- package/lib/validation/validators/ReadOnlyValidator.cjs +2 -2
- package/lib/validation/validators/ReadOnlyValidator.js.map +1 -1
- package/package.json +5 -6
- package/lib/esm/identity/utils.d.ts +0 -47
- package/lib/esm/identity/utils.js +0 -75
- package/lib/esm/identity/utils.js.map +0 -1
- package/lib/esm/model/overrides.js +0 -33
- package/lib/esm/model/overrides.js.map +0 -1
- package/lib/esm/model/utils.d.ts +0 -45
- package/lib/esm/model/utils.js +0 -71
- package/lib/esm/model/utils.js.map +0 -1
- package/lib/identity/utils.cjs +0 -79
- package/lib/identity/utils.d.ts +0 -47
- package/lib/identity/utils.js.map +0 -1
- package/lib/model/overrides.cjs +0 -35
- package/lib/model/overrides.js.map +0 -1
- package/lib/model/utils.cjs +0 -75
- package/lib/model/utils.d.ts +0 -45
- package/lib/model/utils.js.map +0 -1
- /package/lib/esm/{model → overrides}/overrides.d.ts +0 -0
- /package/lib/{model → overrides}/overrides.d.ts +0 -0
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { UpdateValidationKeys } from "./../validation/index.js";
|
|
4
|
-
import { findModelId } from "./../identity/index.js";
|
|
1
|
+
import { Model, ModelErrorDefinition, ModelKeys, toConditionalPromise, Validation, ValidationKeys, } from "@decaf-ts/decorator-validation";
|
|
2
|
+
import { Metadata } from "@decaf-ts/decoration";
|
|
5
3
|
/**
|
|
6
4
|
* @description
|
|
7
5
|
* Retrieves validation decorator definitions from a model for update operations, including
|
|
@@ -26,14 +24,17 @@ import { findModelId } from "./../identity/index.js";
|
|
|
26
24
|
export function getValidatableUpdateProps(model, propsToIgnore) {
|
|
27
25
|
const decoratedProperties = [];
|
|
28
26
|
for (const prop in model) {
|
|
29
|
-
if (Object.prototype.hasOwnProperty.call(model, prop)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
if (!Object.prototype.hasOwnProperty.call(model, prop) ||
|
|
28
|
+
propsToIgnore.includes(prop))
|
|
29
|
+
continue;
|
|
30
|
+
const decorators = Metadata.validationFor(model.constructor, prop) || {};
|
|
31
|
+
// Intentionally leaving this part commented out until all tests are complete
|
|
32
|
+
// const listDecorator = getValidationDecorators(model, prop).decorators.find(
|
|
33
|
+
// ({ key }) => key === ValidationKeys.LIST
|
|
34
|
+
// );
|
|
35
|
+
// if (listDecorator)
|
|
36
|
+
// validationPropertyDefinition.decorators.push(listDecorator);
|
|
37
|
+
decoratedProperties.push({ prop, decorators });
|
|
37
38
|
}
|
|
38
39
|
return decoratedProperties;
|
|
39
40
|
}
|
|
@@ -46,9 +47,9 @@ export function validateDecorator(newModel, oldModel, prop, decorator, async) {
|
|
|
46
47
|
if (!validator.updateHasErrors)
|
|
47
48
|
return toConditionalPromise(undefined, async);
|
|
48
49
|
// skip async decorators if validateDecorators is called synchronously (async = false)
|
|
49
|
-
if (!async && decorator.
|
|
50
|
+
if (!async && decorator.async)
|
|
50
51
|
return toConditionalPromise(undefined, async);
|
|
51
|
-
const decoratorProps = Object.values(decorator
|
|
52
|
+
const decoratorProps = Object.values(decorator) || {};
|
|
52
53
|
// const context = PathProxyEngine.create(obj, {
|
|
53
54
|
// ignoreUndefined: true,
|
|
54
55
|
// ignoreNull: true,
|
|
@@ -58,9 +59,10 @@ export function validateDecorator(newModel, oldModel, prop, decorator, async) {
|
|
|
58
59
|
}
|
|
59
60
|
export function validateDecorators(newModel, oldModel, prop, decorators, async) {
|
|
60
61
|
const result = {};
|
|
61
|
-
for (const
|
|
62
|
+
for (const decoratorKey in decorators) {
|
|
63
|
+
const decorator = { ...decorators[decoratorKey], key: decoratorKey };
|
|
62
64
|
// skip async decorators if validateDecorators is called synchronously (async = false)
|
|
63
|
-
if (!async && decorator.
|
|
65
|
+
if (!async && decorator.async)
|
|
64
66
|
continue;
|
|
65
67
|
let validationErrors = validateDecorator(newModel, oldModel, prop, decorator, async);
|
|
66
68
|
/*
|
|
@@ -73,10 +75,8 @@ export function validateDecorators(newModel, oldModel, prop, decorators, async)
|
|
|
73
75
|
const oldPropValue = oldModel[prop];
|
|
74
76
|
const newValues = newPropValue instanceof Set ? [...newPropValue] : newPropValue;
|
|
75
77
|
const oldValues = oldPropValue instanceof Set ? [...oldPropValue] : oldPropValue;
|
|
76
|
-
if (newValues
|
|
77
|
-
const types = decorator.
|
|
78
|
-
decorator.props.clazz ||
|
|
79
|
-
decorator.props.customTypes;
|
|
78
|
+
if (newValues?.length) {
|
|
79
|
+
const types = decorator.class || decorator.clazz || decorator.customTypes;
|
|
80
80
|
const allowedTypes = [types].flat().map((t) => {
|
|
81
81
|
t = typeof t === "function" && !t.name ? t() : t;
|
|
82
82
|
t = t.name ? t.name : t;
|
|
@@ -84,12 +84,12 @@ export function validateDecorators(newModel, oldModel, prop, decorators, async)
|
|
|
84
84
|
});
|
|
85
85
|
const errs = newValues.map((childValue) => {
|
|
86
86
|
// find by id so the list elements order doesn't matter
|
|
87
|
-
const id =
|
|
87
|
+
const id = Model.pk(childValue, true);
|
|
88
88
|
if (!id)
|
|
89
89
|
return "Failed to find model id";
|
|
90
|
-
const
|
|
90
|
+
const oldListModel = oldValues.find((el) => id === Model.pk(el, true));
|
|
91
91
|
if (Model.isModel(childValue)) {
|
|
92
|
-
return childValue.hasErrors(
|
|
92
|
+
return childValue.hasErrors(oldListModel);
|
|
93
93
|
}
|
|
94
94
|
return allowedTypes.includes(typeof childValue)
|
|
95
95
|
? undefined
|
|
@@ -132,7 +132,7 @@ export function validateDecorators(newModel, oldModel, prop, decorators, async)
|
|
|
132
132
|
* @param {M} oldModel - The original model version
|
|
133
133
|
* @param {M} newModel - The updated model version
|
|
134
134
|
* @param {boolean} async - A flag indicating whether validation should be asynchronous.
|
|
135
|
-
* @param {...string[]}
|
|
135
|
+
* @param {...string[]} propsToIgnore - Properties to exclude from validation
|
|
136
136
|
* @return {ModelErrorDefinition|undefined} Error definition if validation fails, undefined otherwise
|
|
137
137
|
* @function validateCompare
|
|
138
138
|
* @memberOf module:db-decorators
|
|
@@ -143,7 +143,7 @@ export function validateDecorators(newModel, oldModel, prop, decorators, async)
|
|
|
143
143
|
* participant Reflection
|
|
144
144
|
* participant Validation
|
|
145
145
|
*
|
|
146
|
-
* Caller->>validateCompare: oldModel, newModel,
|
|
146
|
+
* Caller->>validateCompare: oldModel, newModel, propsToIgnore
|
|
147
147
|
* validateCompare->>Reflection: get decorated properties
|
|
148
148
|
* Reflection-->>validateCompare: property decorators
|
|
149
149
|
* loop For each decorated property
|
|
@@ -156,24 +156,20 @@ export function validateDecorators(newModel, oldModel, prop, decorators, async)
|
|
|
156
156
|
* end
|
|
157
157
|
* validateCompare-->>Caller: validation errors or undefined
|
|
158
158
|
*/
|
|
159
|
-
export function validateCompare(oldModel, newModel, async, ...
|
|
160
|
-
const
|
|
159
|
+
export function validateCompare(oldModel, newModel, async, ...propsToIgnore) {
|
|
160
|
+
const ValidatableUpdateProps = getValidatableUpdateProps(newModel, propsToIgnore);
|
|
161
161
|
const result = {};
|
|
162
162
|
const nestedErrors = {};
|
|
163
|
-
for (const { prop, decorators } of
|
|
163
|
+
for (const { prop, decorators } of ValidatableUpdateProps) {
|
|
164
164
|
const propKey = String(prop);
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
// Get the default type validator
|
|
169
|
-
const designTypeDec = decorators.find((d) => [ModelKeys.TYPE, ValidationKeys.TYPE].includes(d.key));
|
|
170
|
-
if (!designTypeDec)
|
|
165
|
+
const propValue = newModel[prop];
|
|
166
|
+
const { designTypes, designType } = Metadata.getPropDesignTypes(newModel.constructor, prop);
|
|
167
|
+
if (!designTypes)
|
|
171
168
|
continue;
|
|
172
|
-
const designType = designTypeDec.props.name;
|
|
173
169
|
// Handle array or Set types and enforce the presence of @list decorator
|
|
174
|
-
if ([Array.name, Set.name].includes(
|
|
175
|
-
|
|
176
|
-
|
|
170
|
+
if (designTypes.some((t) => [Array.name, Set.name].includes(t))) {
|
|
171
|
+
if (!decorators ||
|
|
172
|
+
!Object.keys(decorators).includes(ValidationKeys.LIST)) {
|
|
177
173
|
result[propKey] = {
|
|
178
174
|
[ValidationKeys.TYPE]: `Array or Set property '${propKey}' requires a @list decorator`,
|
|
179
175
|
};
|
|
@@ -182,32 +178,32 @@ export function validateCompare(oldModel, newModel, async, ...exceptions) {
|
|
|
182
178
|
if (propValue &&
|
|
183
179
|
!(Array.isArray(propValue) || propValue instanceof Set)) {
|
|
184
180
|
result[propKey] = {
|
|
185
|
-
[ValidationKeys.TYPE]: `Property '${String(prop)}' must be either an
|
|
181
|
+
[ValidationKeys.TYPE]: `Property '${String(prop)}' must be either an Array or a Set`,
|
|
186
182
|
};
|
|
187
183
|
continue;
|
|
188
184
|
}
|
|
189
|
-
// Remove design:type decorator, since @list decorator already ensures type
|
|
190
|
-
for (let i = decorators.length - 1; i >= 0; i--) {
|
|
191
|
-
if (decorators[i].key === ModelKeys.TYPE) {
|
|
192
|
-
decorators.splice(i, 1);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
propValue = propValue instanceof Set ? [...propValue] : propValue;
|
|
196
185
|
}
|
|
186
|
+
// TODO: Check validateDecorators method partially working. Complete check pending.
|
|
197
187
|
const propErrors = validateDecorators(newModel, oldModel, propKey, decorators, async) || {};
|
|
198
|
-
// Check for nested
|
|
188
|
+
// Check for nested model.
|
|
199
189
|
// To prevent unnecessary processing, "propValue" must be defined and validatable
|
|
200
190
|
const isConstr = Model.isPropertyModel(newModel, propKey);
|
|
201
|
-
|
|
202
|
-
if (
|
|
191
|
+
const hasPropValue = propValue !== null && propValue !== undefined;
|
|
192
|
+
if (hasPropValue && isConstr) {
|
|
203
193
|
const instance = propValue;
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
typeof
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
194
|
+
const Constr = (Array.isArray(designType) ? designType : [designType])
|
|
195
|
+
.map((d) => {
|
|
196
|
+
if (typeof d === "function" && !d.name)
|
|
197
|
+
d = d();
|
|
198
|
+
return Model.get(d.name || d);
|
|
199
|
+
})
|
|
200
|
+
.find((d) => !!d);
|
|
201
|
+
// Ensure instance is of the expected model class.
|
|
202
|
+
if (!Constr || !(instance instanceof Constr)) {
|
|
203
|
+
propErrors[ValidationKeys.TYPE] = !Constr
|
|
204
|
+
? `Unable to verify type consistency, missing model registry for ${designTypes.toString()} on prop ${propKey}`
|
|
205
|
+
: `Value must be an instance of ${Constr.name}`;
|
|
206
|
+
delete propErrors[ModelKeys.TYPE]; // remove duplicate type error
|
|
211
207
|
}
|
|
212
208
|
else {
|
|
213
209
|
nestedErrors[propKey] = instance.hasErrors(oldModel[prop]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../src/model/validation.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../src/model/validation.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C,CAAC;YACpB,MAAM,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YAEvB,IAAI,GAAG,CAAC,MAAM,KAAK,WAAW,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;gBACzD,MAAc,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC;YACnC,CAAC;iBAAM,IAAI,GAAG,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;gBACpC,MAAc,CAAC,GAAG,CAAC;oBAClB,GAAG,CAAC,MAAM,YAAY,KAAK;wBACzB,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO;wBACpB,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,IAAI,mBAAmB,CAAC,CAAC;YAClD,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC;YACnC,CAAC,CAAC,IAAI,oBAAoB,CAAC,MAAM,CAAC;YAClC,CAAC,CAAC,SAAS,CAAC;IAChB,CAAC,CAAQ,CAAC;AACZ,CAAC"}
|
|
@@ -15,6 +15,17 @@ export declare enum OperationKeys {
|
|
|
15
15
|
AFTER = "after.",
|
|
16
16
|
BLOCK = "block"
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* @description Database operation key naming constants
|
|
20
|
+
* @summary Enum defining operations naming
|
|
21
|
+
* @enum {string}
|
|
22
|
+
* @readonly
|
|
23
|
+
* @memberOf module:db-decorators
|
|
24
|
+
*/
|
|
25
|
+
export declare enum ModelOperations {
|
|
26
|
+
OPERATIONS = "operations",
|
|
27
|
+
RELATIONS = "relations"
|
|
28
|
+
}
|
|
18
29
|
/**
|
|
19
30
|
* @description Type for basic CRUD operations
|
|
20
31
|
* @summary Union type of the four basic database operations: create, read, update, delete
|
|
@@ -16,6 +16,18 @@ export var OperationKeys;
|
|
|
16
16
|
OperationKeys["AFTER"] = "after.";
|
|
17
17
|
OperationKeys["BLOCK"] = "block";
|
|
18
18
|
})(OperationKeys || (OperationKeys = {}));
|
|
19
|
+
/**
|
|
20
|
+
* @description Database operation key naming constants
|
|
21
|
+
* @summary Enum defining operations naming
|
|
22
|
+
* @enum {string}
|
|
23
|
+
* @readonly
|
|
24
|
+
* @memberOf module:db-decorators
|
|
25
|
+
*/
|
|
26
|
+
export var ModelOperations;
|
|
27
|
+
(function (ModelOperations) {
|
|
28
|
+
ModelOperations["OPERATIONS"] = "operations";
|
|
29
|
+
ModelOperations["RELATIONS"] = "relations";
|
|
30
|
+
})(ModelOperations || (ModelOperations = {}));
|
|
19
31
|
/**
|
|
20
32
|
* @description Bulk database operation key constants
|
|
21
33
|
* @summary Enum defining bulk CRUD operations for handling multiple records at once
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/operations/constants.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAN,IAAY,aASX;AATD,WAAY,aAAa;IACvB,uDAAsC,CAAA;IACtC,kCAAiB,CAAA;IACjB,8BAAa,CAAA;IACb,kCAAiB,CAAA;IACjB,kCAAiB,CAAA;IACjB,2BAAU,CAAA;IACV,iCAAgB,CAAA;IAChB,gCAAe,CAAA;AACjB,CAAC,EATW,aAAa,KAAb,aAAa,QASxB;AAcD;;;;;;GAMG;AACH,MAAM,CAAN,IAAY,qBAKX;AALD,WAAY,qBAAqB;IAC/B,iDAAwB,CAAA;IACxB,6CAAoB,CAAA;IACpB,iDAAwB,CAAA;IACxB,iDAAwB,CAAA;AAC1B,CAAC,EALW,qBAAqB,KAArB,qBAAqB,QAKhC;AAcD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAqC;IAC5D,MAAM,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC;IAC9B,IAAI,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC;IAC1B,MAAM,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC;IAC9B,MAAM,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC;IAC9B,aAAa,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC;IAC3D,WAAW,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC;IACvD,GAAG,EAAE;QACH,aAAa,CAAC,MAAM;QACpB,aAAa,CAAC,IAAI;QAClB,aAAa,CAAC,MAAM;QACpB,aAAa,CAAC,MAAM;KACrB;CACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/operations/constants.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAN,IAAY,aASX;AATD,WAAY,aAAa;IACvB,uDAAsC,CAAA;IACtC,kCAAiB,CAAA;IACjB,8BAAa,CAAA;IACb,kCAAiB,CAAA;IACjB,kCAAiB,CAAA;IACjB,2BAAU,CAAA;IACV,iCAAgB,CAAA;IAChB,gCAAe,CAAA;AACjB,CAAC,EATW,aAAa,KAAb,aAAa,QASxB;AAED;;;;;;GAMG;AACH,MAAM,CAAN,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,4CAAyB,CAAA;IACzB,0CAAuB,CAAA;AACzB,CAAC,EAHW,eAAe,KAAf,eAAe,QAG1B;AAcD;;;;;;GAMG;AACH,MAAM,CAAN,IAAY,qBAKX;AALD,WAAY,qBAAqB;IAC/B,iDAAwB,CAAA;IACxB,6CAAoB,CAAA;IACpB,iDAAwB,CAAA;IACxB,iDAAwB,CAAA;AAC1B,CAAC,EALW,qBAAqB,KAArB,qBAAqB,QAKhC;AAcD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAqC;IAC5D,MAAM,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC;IAC9B,IAAI,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC;IAC1B,MAAM,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC;IAC9B,MAAM,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC;IAC9B,aAAa,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC;IAC3D,WAAW,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC;IACvD,GAAG,EAAE;QACH,aAAa,CAAC,MAAM;QACpB,aAAa,CAAC,IAAI;QAClB,aAAa,CAAC,MAAM;QACpB,aAAa,CAAC,MAAM;KACrB;CACF,CAAC"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { DBOperations, OperationKeys } from "./constants.js";
|
|
1
|
+
import { DBOperations, ModelOperations, OperationKeys, } from "./constants.js";
|
|
2
2
|
import { Operations } from "./Operations.js";
|
|
3
|
-
import { apply } from "@decaf-ts/reflection";
|
|
4
|
-
import { propMetadata } from "@decaf-ts/decorator-validation";
|
|
5
3
|
import { InternalError } from "./../repository/errors.js";
|
|
6
4
|
import { getHandlerArgs } from "./../repository/utils.js";
|
|
7
|
-
import { metadata } from "@decaf-ts/decoration";
|
|
5
|
+
import { propMetadata, apply, metadata, Metadata } from "@decaf-ts/decoration";
|
|
8
6
|
const defaultPriority = 50;
|
|
9
7
|
const DefaultGroupSort = { priority: defaultPriority };
|
|
10
8
|
/**
|
|
@@ -352,7 +350,7 @@ export function operation(baseOp, operation = DBOperations.ALL, handler, dataToA
|
|
|
352
350
|
const name = target.constructor.name;
|
|
353
351
|
const decorators = operation.reduce((accum, op) => {
|
|
354
352
|
const compoundKey = baseOp + op;
|
|
355
|
-
let data =
|
|
353
|
+
let data = Metadata.readOperation(target.constructor, propertyKey, compoundKey);
|
|
356
354
|
if (!data)
|
|
357
355
|
data = {
|
|
358
356
|
operation: op,
|
|
@@ -374,7 +372,7 @@ export function operation(baseOp, operation = DBOperations.ALL, handler, dataToA
|
|
|
374
372
|
data.handlers[name][propertyKey][handlerKey] = {
|
|
375
373
|
data: mergeData,
|
|
376
374
|
};
|
|
377
|
-
accum.push(handle(compoundKey, handler), propMetadata(
|
|
375
|
+
accum.push(handle(compoundKey, handler), propMetadata(Metadata.key(ModelOperations.OPERATIONS, propertyKey, compoundKey), data));
|
|
378
376
|
}
|
|
379
377
|
return accum;
|
|
380
378
|
}, []);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../src/operations/decorators.ts"],"names":[],"mappings":"AAQA,OAAO,
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../src/operations/decorators.ts"],"names":[],"mappings":"AAQA,OAAO,EAEL,YAAY,EACZ,eAAe,EACf,aAAa,GACd,uBAAoB;AACrB,OAAO,EAAE,UAAU,EAAE,wBAAqB;AAK1C,OAAO,EAAE,aAAa,EAAE,kCAA6B;AACrD,OAAO,EAAE,cAAc,EAAE,iCAA4B;AACrD,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAiB/E,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,MAAM,gBAAgB,GAAc,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC;AAiBlE;;;;;;;;GAQG;AACH,SAAS,MAAM,CACb,EAAiB,EACjB,OAAkD;IAElD,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,UAAU,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IACxD,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,qBAAqB,CAOnC,KAAY,EACZ,UAA+C,EAC/C,MAAc;IAEd,MAAM,KAAK,GAAsB,EAAE,CAAC;IACpC,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC9B,MAAM,IAAI,GAAwB,UAAU,CAAC,IAAI,CAAC,CAAC;QACnD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,MAAM,EAA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,CAAC,UAAU,CAAC,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Constructor } from "@decaf-ts/decoration";
|
|
2
|
+
import type { Model } from "@decaf-ts/decorator-validation";
|
|
3
|
+
declare module "@decaf-ts/decoration" {
|
|
4
|
+
namespace Metadata {
|
|
5
|
+
/**
|
|
6
|
+
* @description Saves metadata under a key for a specific operation
|
|
7
|
+
* @summary Saves metadata under a key for a specific operation
|
|
8
|
+
*
|
|
9
|
+
* @template M - The model type extending from Model
|
|
10
|
+
* @param {Constructor<M>} model - The constructor of the target model class
|
|
11
|
+
* @param {keyof M} propertyKey - The property key to store metadata for
|
|
12
|
+
* @param {string} operation - The type of operation being done. Eg. on.update
|
|
13
|
+
* @param {any} metadata - The metadata to store to for the operation
|
|
14
|
+
* @return {void}
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* class User extends Model {
|
|
18
|
+
*
|
|
19
|
+
* // Set metatada for 'User' for key updatedOn, for operation on.create
|
|
20
|
+
* Metadata.saveOperation(User.constructor,'updatedOn','on.create',metadata);
|
|
21
|
+
*/
|
|
22
|
+
function saveOperation<M extends Model>(model: Constructor<M>, propertyKey: keyof M, operation: string, metadata: any): void;
|
|
23
|
+
/**
|
|
24
|
+
* @description Reads the metadata under a key for a specific operation
|
|
25
|
+
* @summary Reads the metadata under a key for a specific operation
|
|
26
|
+
*
|
|
27
|
+
* @template M - The model type extending from Model
|
|
28
|
+
* @param {Constructor<M>} model - The constructor of the target model class
|
|
29
|
+
* @param {keyof M} propertyKey - The property key to store metadata for
|
|
30
|
+
* @param {string} operation - The type of operation being done. Eg. on.update
|
|
31
|
+
* @return {any} metadata - The metadata to store to for the operation
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* class User extends Model {
|
|
35
|
+
*
|
|
36
|
+
* // Get metatada for 'User' for key updatedOn, for operation on.create
|
|
37
|
+
* const metadata = Metadata.readOperation(User.constructor,'updatedOn','on.create');
|
|
38
|
+
*/
|
|
39
|
+
function readOperation<M extends Model>(model: Constructor<M>, propertyKey?: keyof M, operation?: string): any;
|
|
40
|
+
/**
|
|
41
|
+
* @description Checks if a model is marked as transient
|
|
42
|
+
* @summary Determines whether a model class has been decorated with the transient decorator
|
|
43
|
+
* @template M - Type extending Model
|
|
44
|
+
* @param {M | Constructor<M>} model - The model instance to check
|
|
45
|
+
* @return {boolean} True if the model is transient, false otherwise
|
|
46
|
+
* @function isTransient
|
|
47
|
+
*/
|
|
48
|
+
function isTransient<M extends Model>(model: M | Constructor<M>): boolean;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Metadata.js","sourceRoot":"","sources":["../../../src/overrides/Metadata.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import "@decaf-ts/decorator-validation";
|
|
2
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
3
|
+
import { Model as MM } from "@decaf-ts/decorator-validation";
|
|
4
|
+
declare module "@decaf-ts/decorator-validation" {
|
|
5
|
+
interface Model {
|
|
6
|
+
isTransient(): boolean;
|
|
7
|
+
toTransient<M extends MM>(this: M): {
|
|
8
|
+
model: M;
|
|
9
|
+
transient?: Record<string, any>;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
namespace Model {
|
|
13
|
+
/**
|
|
14
|
+
* @description Retrieves primary key information for a model
|
|
15
|
+
* @summary Retrieves primary key information or it's value for a model from it's metadata.
|
|
16
|
+
*
|
|
17
|
+
* @template model - The model type extending from Model
|
|
18
|
+
* @param {M | Constructor<M>} model - The model class or it's constructor
|
|
19
|
+
* @param {boolean} keyValue - Optional keyValue flag, to return the value of the id instead of the property. Does not work with constructor.
|
|
20
|
+
* @return {any} The property of the id of the model, or it's value
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* class User extends Model {
|
|
24
|
+
*
|
|
25
|
+
* const idProp = Model.pk(newModel);
|
|
26
|
+
* const id = Model.pk(newModel, true);
|
|
27
|
+
*/
|
|
28
|
+
function pk<M>(model: M | Constructor<M>, keyValue?: boolean): any;
|
|
29
|
+
function isTransient<M extends Model>(model: M | Constructor<M>): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* @description Separates transient properties from a model
|
|
32
|
+
* @summary Extracts properties marked as transient into a separate object
|
|
33
|
+
* @template M - Type extending Model
|
|
34
|
+
* @param {M} model - The model instance to process
|
|
35
|
+
* @return {Object} Object containing the model without transient properties and a separate transient object
|
|
36
|
+
* @property {M} model - The model with transient properties removed
|
|
37
|
+
* @property {Record<string, any>} [transient] - Object containing the transient properties
|
|
38
|
+
* @function modelToTransient
|
|
39
|
+
* @memberOf module:db-decorators
|
|
40
|
+
* @mermaid
|
|
41
|
+
* sequenceDiagram
|
|
42
|
+
* participant Caller
|
|
43
|
+
* participant modelToTransient
|
|
44
|
+
* participant isTransient
|
|
45
|
+
* participant Metadata.validatableProperties
|
|
46
|
+
*
|
|
47
|
+
* Caller->>modelToTransient: model
|
|
48
|
+
* modelToTransient->>isTransient: check if model is transient
|
|
49
|
+
* isTransient-->>modelToTransient: transient status
|
|
50
|
+
* alt model is not transient
|
|
51
|
+
* modelToTransient-->>Caller: {model}
|
|
52
|
+
* else model is transient
|
|
53
|
+
* modelToTransient->>Metadata.validatableProperties: get decorated properties, combine with model props
|
|
54
|
+
* modelToTransient->>get transient properties from Metadata
|
|
55
|
+
* modelToTransient->>modelToTransient: separate properties
|
|
56
|
+
* modelToTransient->>Model.build: rebuild model without transient props
|
|
57
|
+
* modelToTransient-->>Caller: {model, transient}
|
|
58
|
+
* end
|
|
59
|
+
*/
|
|
60
|
+
function toTransient<M extends Model>(model: M): {
|
|
61
|
+
model: M;
|
|
62
|
+
transient?: Record<string, any>;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Model.js","sourceRoot":"","sources":["../../../src/overrides/Model.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/overrides/index.ts"],"names":[],"mappings":"AAAA,2BAAwB;AACxB,+BAA4B;AAC5B,8BAA2B"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Model, validate, } from "@decaf-ts/decorator-validation";
|
|
2
|
+
import { validateCompare } from "./../model/validation.js";
|
|
3
|
+
import { Metadata } from "@decaf-ts/decoration";
|
|
4
|
+
import { DBKeys } from "./../model/constants.js";
|
|
5
|
+
import { ModelOperations } from "./../operations/constants.js";
|
|
6
|
+
import { SerializationError } from "./../repository/errors.js";
|
|
7
|
+
Model.prototype.isTransient = function () {
|
|
8
|
+
return Metadata.isTransient(this);
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* @description Validates the model and checks for errors
|
|
12
|
+
* @summary Validates the current model state and optionally compares with a previous version
|
|
13
|
+
* @template M - Type extending Model
|
|
14
|
+
* @param {M|any} [previousVersion] - Optional previous version of the model for comparison
|
|
15
|
+
* @param {...any[]} exclusions - Properties to exclude from validation
|
|
16
|
+
* @return {ModelErrorDefinition|undefined} Error definition if validation fails, undefined otherwise
|
|
17
|
+
* @function hasErrors
|
|
18
|
+
* @memberOf module:db-decorators
|
|
19
|
+
*/
|
|
20
|
+
Model.prototype.hasErrors = function (previousVersion, ...exclusions) {
|
|
21
|
+
if (previousVersion && !(previousVersion instanceof Model)) {
|
|
22
|
+
exclusions.unshift(previousVersion);
|
|
23
|
+
previousVersion = undefined;
|
|
24
|
+
}
|
|
25
|
+
const async = this.isAsync();
|
|
26
|
+
const errs = validate(this, async, ...exclusions);
|
|
27
|
+
if (async) {
|
|
28
|
+
return Promise.resolve(errs).then((resolvedErrs) => {
|
|
29
|
+
if (resolvedErrs || !previousVersion) {
|
|
30
|
+
return resolvedErrs;
|
|
31
|
+
}
|
|
32
|
+
return validateCompare(previousVersion, this, async, ...exclusions);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (errs || !previousVersion)
|
|
36
|
+
return errs;
|
|
37
|
+
// @ts-expect-error Overriding Model prototype method with dynamic conditional return type.
|
|
38
|
+
return validateCompare(previousVersion, this, async, ...exclusions);
|
|
39
|
+
};
|
|
40
|
+
Model.prototype.toTransient = function toTransient() {
|
|
41
|
+
return Model.toTransient(this);
|
|
42
|
+
};
|
|
43
|
+
Model.toTransient = function toTransient(model) {
|
|
44
|
+
if (!Metadata.isTransient(model))
|
|
45
|
+
return { model: model };
|
|
46
|
+
const decoratedProperties = Metadata.validatableProperties(model.constructor);
|
|
47
|
+
const transientProps = Metadata.get(model.constructor, DBKeys.TRANSIENT);
|
|
48
|
+
const result = {
|
|
49
|
+
model: {},
|
|
50
|
+
transient: {},
|
|
51
|
+
};
|
|
52
|
+
for (const key of decoratedProperties) {
|
|
53
|
+
const isTransient = Object.keys(transientProps).includes(key);
|
|
54
|
+
if (isTransient) {
|
|
55
|
+
result.transient = result.transient || {};
|
|
56
|
+
try {
|
|
57
|
+
result.transient[key] = model[key];
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
throw new SerializationError(`Failed to serialize transient property ${key}: ${e}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
result.model = result.model || {};
|
|
65
|
+
result.model[key] = model[key];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
result.model = Model.build(result.model, model.constructor.name);
|
|
69
|
+
return result;
|
|
70
|
+
};
|
|
71
|
+
Model.pk = function (model, keyValue = false) {
|
|
72
|
+
if (!model)
|
|
73
|
+
throw new Error("No model was provided");
|
|
74
|
+
const constr = model instanceof Model ? model.constructor : model;
|
|
75
|
+
const idProp = Metadata.get(constr, DBKeys.ID);
|
|
76
|
+
if (!idProp) {
|
|
77
|
+
throw new Error(`No Id property defined for model ${constr?.name || "Unknown Model"}`);
|
|
78
|
+
}
|
|
79
|
+
const key = Object.keys(idProp)[0];
|
|
80
|
+
if (!keyValue)
|
|
81
|
+
return key;
|
|
82
|
+
if (model instanceof Model)
|
|
83
|
+
return model[key];
|
|
84
|
+
throw new Error("Cannot get the value of the pk from the constructor");
|
|
85
|
+
}.bind(Model);
|
|
86
|
+
Model.isTransient = function isTransient(model) {
|
|
87
|
+
return Metadata.isTransient(model);
|
|
88
|
+
}.bind(Model);
|
|
89
|
+
Metadata.saveOperation = function (model, propertyKey, operation, metadata) {
|
|
90
|
+
if (!propertyKey)
|
|
91
|
+
return;
|
|
92
|
+
Metadata.set(model, Metadata.key(ModelOperations.OPERATIONS, propertyKey, operation), metadata);
|
|
93
|
+
}.bind(Metadata);
|
|
94
|
+
Metadata.readOperation = function (model, propertyKey, operation) {
|
|
95
|
+
if (!propertyKey || !operation)
|
|
96
|
+
return;
|
|
97
|
+
return Metadata.get(model, Metadata.key(ModelOperations.OPERATIONS, propertyKey, operation));
|
|
98
|
+
}.bind(Metadata);
|
|
99
|
+
Metadata.isTransient = function isTransient(model) {
|
|
100
|
+
return !!Metadata.get(typeof model !== "function" ? model.constructor : model, DBKeys.TRANSIENT);
|
|
101
|
+
}.bind(Metadata);
|
|
102
|
+
//# sourceMappingURL=overrides.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overrides.js","sourceRoot":"","sources":["../../../src/overrides/overrides.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAEL,QAAQ,GACT,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,iCAA4B;AACtD,OAAO,EAAe,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,gCAA2B;AAC5C,OAAO,EAAE,eAAe,EAAE,qCAAgC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,kCAA6B;AAE1D,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG;IAC5B,OAAO,QAAQ,CAAC,WAAW,CAAC,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