@decaf-ts/db-decorators 0.6.20 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +2 -3
- 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
package/lib/esm/model/utils.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { getAllPropertyDecoratorsRecursive, Repository, SerializationError, } from "./../repository/index.js";
|
|
2
|
-
import { Model } from "@decaf-ts/decorator-validation";
|
|
3
|
-
import { DBKeys } from "./constants.js";
|
|
4
|
-
/**
|
|
5
|
-
* @description Checks if a model is marked as transient
|
|
6
|
-
* @summary Determines whether a model class has been decorated with the transient decorator
|
|
7
|
-
* @template M - Type extending Model
|
|
8
|
-
* @param {M} model - The model instance to check
|
|
9
|
-
* @return {boolean} True if the model is transient, false otherwise
|
|
10
|
-
* @function isTransient
|
|
11
|
-
* @memberOf module:db-decorators
|
|
12
|
-
*/
|
|
13
|
-
export function isTransient(model) {
|
|
14
|
-
return !!(Reflect.getMetadata(Repository.key(DBKeys.TRANSIENT), model.constructor) ||
|
|
15
|
-
Reflect.getMetadata(Repository.key(DBKeys.TRANSIENT), Model.get(model.constructor.name)));
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* @description Separates transient properties from a model
|
|
19
|
-
* @summary Extracts properties marked as transient into a separate object
|
|
20
|
-
* @template M - Type extending Model
|
|
21
|
-
* @param {M} model - The model instance to process
|
|
22
|
-
* @return {Object} Object containing the model without transient properties and a separate transient object
|
|
23
|
-
* @property {M} model - The model with transient properties removed
|
|
24
|
-
* @property {Record<string, any>} [transient] - Object containing the transient properties
|
|
25
|
-
* @function modelToTransient
|
|
26
|
-
* @memberOf module:db-decorators
|
|
27
|
-
* @mermaid
|
|
28
|
-
* sequenceDiagram
|
|
29
|
-
* participant Caller
|
|
30
|
-
* participant modelToTransient
|
|
31
|
-
* participant isTransient
|
|
32
|
-
* participant getAllPropertyDecoratorsRecursive
|
|
33
|
-
*
|
|
34
|
-
* Caller->>modelToTransient: model
|
|
35
|
-
* modelToTransient->>isTransient: check if model is transient
|
|
36
|
-
* isTransient-->>modelToTransient: transient status
|
|
37
|
-
* alt model is not transient
|
|
38
|
-
* modelToTransient-->>Caller: {model}
|
|
39
|
-
* else model is transient
|
|
40
|
-
* modelToTransient->>getAllPropertyDecoratorsRecursive: get transient properties
|
|
41
|
-
* getAllPropertyDecoratorsRecursive-->>modelToTransient: property decorators
|
|
42
|
-
* modelToTransient->>modelToTransient: separate properties
|
|
43
|
-
* modelToTransient->>Model.build: rebuild model without transient props
|
|
44
|
-
* modelToTransient-->>Caller: {model, transient}
|
|
45
|
-
* end
|
|
46
|
-
*/
|
|
47
|
-
export function modelToTransient(model) {
|
|
48
|
-
if (!isTransient(model))
|
|
49
|
-
return { model: model };
|
|
50
|
-
const decs = getAllPropertyDecoratorsRecursive(model, undefined, Repository.key(DBKeys.TRANSIENT));
|
|
51
|
-
const result = Object.entries(decs).reduce((accum, [k, val]) => {
|
|
52
|
-
const transient = val.find((el) => el.key === "");
|
|
53
|
-
if (transient) {
|
|
54
|
-
accum.transient = accum.transient || {};
|
|
55
|
-
try {
|
|
56
|
-
accum.transient[k] = model[k];
|
|
57
|
-
}
|
|
58
|
-
catch (e) {
|
|
59
|
-
throw new SerializationError(`Failed to serialize transient property ${k}: ${e}`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
accum.model = accum.model || {};
|
|
64
|
-
accum.model[k] = model[k];
|
|
65
|
-
}
|
|
66
|
-
return accum;
|
|
67
|
-
}, {});
|
|
68
|
-
result.model = Model.build(result.model, model.constructor.name);
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/model/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iCAAiC,EACjC,UAAU,EACV,kBAAkB,GACnB,iCAAsB;AACvB,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,uBAAoB;AAErC;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAA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C,KAAK,GAAG,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC;YAChC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,GAAI,KAA6B,CAAC,CAAC,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,EACD,EAAqE,CACtE,CAAC;IACF,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACjE,OAAO,MAAuD,CAAC;AACjE,CAAC"}
|
package/lib/identity/utils.cjs
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findPrimaryKey = findPrimaryKey;
|
|
4
|
-
exports.findModelId = findModelId;
|
|
5
|
-
const constants_1 = require("./../model/constants.cjs");
|
|
6
|
-
const utils_1 = require("./../repository/utils.cjs");
|
|
7
|
-
const decorator_validation_1 = require("@decaf-ts/decorator-validation");
|
|
8
|
-
const errors_1 = require("./../repository/errors.cjs");
|
|
9
|
-
/**
|
|
10
|
-
* @description Finds the primary key attribute for a model
|
|
11
|
-
* @summary Searches in all the properties in the object for an {@link id} decorated property and returns the property key and metadata
|
|
12
|
-
* @param {Model} model - The model object to search for primary key
|
|
13
|
-
* @return {Object} An object containing the id property name and its metadata
|
|
14
|
-
* @function findPrimaryKey
|
|
15
|
-
* @mermaid
|
|
16
|
-
* sequenceDiagram
|
|
17
|
-
* participant Caller
|
|
18
|
-
* participant findPrimaryKey
|
|
19
|
-
* participant getAllPropertyDecoratorsRecursive
|
|
20
|
-
*
|
|
21
|
-
* Caller->>findPrimaryKey: model
|
|
22
|
-
* findPrimaryKey->>getAllPropertyDecoratorsRecursive: get decorators
|
|
23
|
-
* getAllPropertyDecoratorsRecursive-->>findPrimaryKey: decorators
|
|
24
|
-
* findPrimaryKey->>findPrimaryKey: filter ID decorators
|
|
25
|
-
* findPrimaryKey->>findPrimaryKey: validate single ID property
|
|
26
|
-
* findPrimaryKey-->>Caller: {id, props}
|
|
27
|
-
* @memberOf module:db-decorators
|
|
28
|
-
*/
|
|
29
|
-
function findPrimaryKey(model) {
|
|
30
|
-
const decorators = (0, utils_1.getAllPropertyDecoratorsRecursive)(model, undefined, constants_1.DBKeys.REFLECT + constants_1.DBKeys.ID);
|
|
31
|
-
const idDecorators = Object.entries(decorators).reduce((accum, [prop, decs]) => {
|
|
32
|
-
const filtered = decs.filter((d) => d.key !== decorator_validation_1.ModelKeys.TYPE);
|
|
33
|
-
if (filtered && filtered.length) {
|
|
34
|
-
accum[prop] = accum[prop] || [];
|
|
35
|
-
accum[prop].push(...filtered);
|
|
36
|
-
}
|
|
37
|
-
return accum;
|
|
38
|
-
}, {});
|
|
39
|
-
if (!idDecorators || !Object.keys(idDecorators).length)
|
|
40
|
-
throw new errors_1.InternalError("Could not find ID decorated Property");
|
|
41
|
-
if (Object.keys(idDecorators).length > 1)
|
|
42
|
-
throw new errors_1.InternalError((0, decorator_validation_1.sf)(Object.keys(idDecorators).join(", ")));
|
|
43
|
-
const idProp = Object.keys(idDecorators)[0];
|
|
44
|
-
if (!idProp)
|
|
45
|
-
throw new errors_1.InternalError("Could not find ID decorated Property");
|
|
46
|
-
return {
|
|
47
|
-
id: idProp,
|
|
48
|
-
props: idDecorators[idProp][0].props,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* @description Retrieves the primary key value from a model
|
|
53
|
-
* @summary Searches for the ID-decorated property in the model and returns its value
|
|
54
|
-
* @param {Model} model - The model object to extract the ID from
|
|
55
|
-
* @param {boolean} [returnEmpty=false] - Whether to return undefined if no ID value is found
|
|
56
|
-
* @return {string | number | bigint} The primary key value
|
|
57
|
-
* @function findModelId
|
|
58
|
-
* @mermaid
|
|
59
|
-
* sequenceDiagram
|
|
60
|
-
* participant Caller
|
|
61
|
-
* participant findModelId
|
|
62
|
-
* participant findPrimaryKey
|
|
63
|
-
*
|
|
64
|
-
* Caller->>findModelId: model, returnEmpty
|
|
65
|
-
* findModelId->>findPrimaryKey: model
|
|
66
|
-
* findPrimaryKey-->>findModelId: {id, props}
|
|
67
|
-
* findModelId->>findModelId: extract model[id]
|
|
68
|
-
* findModelId->>findModelId: validate ID exists if required
|
|
69
|
-
* findModelId-->>Caller: ID value
|
|
70
|
-
* @memberOf module:db-decorators
|
|
71
|
-
*/
|
|
72
|
-
function findModelId(model, returnEmpty = false) {
|
|
73
|
-
const idProp = findPrimaryKey(model).id;
|
|
74
|
-
const modelId = model[idProp];
|
|
75
|
-
if (typeof modelId === "undefined" && !returnEmpty)
|
|
76
|
-
throw new errors_1.InternalError(`No value for the Id is defined under the property ${idProp}`);
|
|
77
|
-
return modelId;
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=utils.js.map
|
package/lib/identity/utils.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
|
-
/**
|
|
3
|
-
* @description Finds the primary key attribute for a model
|
|
4
|
-
* @summary Searches in all the properties in the object for an {@link id} decorated property and returns the property key and metadata
|
|
5
|
-
* @param {Model} model - The model object to search for primary key
|
|
6
|
-
* @return {Object} An object containing the id property name and its metadata
|
|
7
|
-
* @function findPrimaryKey
|
|
8
|
-
* @mermaid
|
|
9
|
-
* sequenceDiagram
|
|
10
|
-
* participant Caller
|
|
11
|
-
* participant findPrimaryKey
|
|
12
|
-
* participant getAllPropertyDecoratorsRecursive
|
|
13
|
-
*
|
|
14
|
-
* Caller->>findPrimaryKey: model
|
|
15
|
-
* findPrimaryKey->>getAllPropertyDecoratorsRecursive: get decorators
|
|
16
|
-
* getAllPropertyDecoratorsRecursive-->>findPrimaryKey: decorators
|
|
17
|
-
* findPrimaryKey->>findPrimaryKey: filter ID decorators
|
|
18
|
-
* findPrimaryKey->>findPrimaryKey: validate single ID property
|
|
19
|
-
* findPrimaryKey-->>Caller: {id, props}
|
|
20
|
-
* @memberOf module:db-decorators
|
|
21
|
-
*/
|
|
22
|
-
export declare function findPrimaryKey<M extends Model>(model: M): {
|
|
23
|
-
id: keyof M;
|
|
24
|
-
props: any;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* @description Retrieves the primary key value from a model
|
|
28
|
-
* @summary Searches for the ID-decorated property in the model and returns its value
|
|
29
|
-
* @param {Model} model - The model object to extract the ID from
|
|
30
|
-
* @param {boolean} [returnEmpty=false] - Whether to return undefined if no ID value is found
|
|
31
|
-
* @return {string | number | bigint} The primary key value
|
|
32
|
-
* @function findModelId
|
|
33
|
-
* @mermaid
|
|
34
|
-
* sequenceDiagram
|
|
35
|
-
* participant Caller
|
|
36
|
-
* participant findModelId
|
|
37
|
-
* participant findPrimaryKey
|
|
38
|
-
*
|
|
39
|
-
* Caller->>findModelId: model, returnEmpty
|
|
40
|
-
* findModelId->>findPrimaryKey: model
|
|
41
|
-
* findPrimaryKey-->>findModelId: {id, props}
|
|
42
|
-
* findModelId->>findModelId: extract model[id]
|
|
43
|
-
* findModelId->>findModelId: validate ID exists if required
|
|
44
|
-
* findModelId-->>Caller: ID value
|
|
45
|
-
* @memberOf module:db-decorators
|
|
46
|
-
*/
|
|
47
|
-
export declare function findModelId<M extends Model>(model: M, returnEmpty?: boolean): string | number | bigint;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/identity/utils.ts"],"names":[],"mappings":";;AAyBA,wCA8BC;AAuBD,kCAWC;AAzFD,wDAA4C;AAC5C,qDAAwE;AACxE,yEAAsE;AACtE,uDAAqD;AAErD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,cAAc,CAAkB,KAAQ;IACtD,MAAM,UAAU,GAAG,IAAA,yCAAiC,EAClD,KAAK,EACL,SAAS,EACT,kBAAM,CAAC,OAAO,GAAG,kBAAM,CAAC,EAAE,CAC3B,CAAC;IACF,MAAM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CACzB,KAAQ,EACR,WAAW,GAAG,KAAK;IAEnB,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;IACxC,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IAC9B,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,CAAC,WAAW;QAChD,MAAM,IAAI,sBAAa,CACrB,qDAAqD,MAAgB,EAAE,CACxE,CAAC;IACJ,OAAO,OAAmC,CAAC;AAC7C,CAAC"}
|
package/lib/model/overrides.cjs
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const decorator_validation_1 = require("@decaf-ts/decorator-validation");
|
|
4
|
-
const validation_1 = require("./validation.cjs");
|
|
5
|
-
/**
|
|
6
|
-
* @description Validates the model and checks for errors
|
|
7
|
-
* @summary Validates the current model state and optionally compares with a previous version
|
|
8
|
-
* @template M - Type extending Model
|
|
9
|
-
* @param {M|any} [previousVersion] - Optional previous version of the model for comparison
|
|
10
|
-
* @param {...any[]} exclusions - Properties to exclude from validation
|
|
11
|
-
* @return {ModelErrorDefinition|undefined} Error definition if validation fails, undefined otherwise
|
|
12
|
-
* @function hasErrors
|
|
13
|
-
* @memberOf module:db-decorators
|
|
14
|
-
*/
|
|
15
|
-
decorator_validation_1.Model.prototype.hasErrors = function (previousVersion, ...exclusions) {
|
|
16
|
-
if (previousVersion && !(previousVersion instanceof decorator_validation_1.Model)) {
|
|
17
|
-
exclusions.unshift(previousVersion);
|
|
18
|
-
previousVersion = undefined;
|
|
19
|
-
}
|
|
20
|
-
const async = this.isAsync();
|
|
21
|
-
const errs = (0, decorator_validation_1.validate)(this, async, ...exclusions);
|
|
22
|
-
if (async) {
|
|
23
|
-
return Promise.resolve(errs).then((resolvedErrs) => {
|
|
24
|
-
if (resolvedErrs || !previousVersion) {
|
|
25
|
-
return resolvedErrs;
|
|
26
|
-
}
|
|
27
|
-
return (0, validation_1.validateCompare)(previousVersion, this, async, ...exclusions);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
if (errs || !previousVersion)
|
|
31
|
-
return errs;
|
|
32
|
-
// @ts-expect-error Overriding Model prototype method with dynamic conditional return type.
|
|
33
|
-
return (0, validation_1.validateCompare)(previousVersion, this, async, ...exclusions);
|
|
34
|
-
};
|
|
35
|
-
//# sourceMappingURL=overrides.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"overrides.js","sourceRoot":"","sources":["../../src/model/overrides.ts"],"names":[],"mappings":";;AAAA,yEAIwC;AACxC,iDAA+C;AAE/C;;;;;;;;;GASG;AACH,4BAAK,CAAC,SAAS,CAAC,SAAS,GAAG,UAE1B,eAAyB,EACzB,GAAG,UAAiB;IAEpB,IAAI,eAAe,IAAI,CAAC,CAAC,eAAe,YAAY,4BAAK,CAAC,EAAE,CAAC;QAC3D,UAAU,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;QACpC,eAAe,GAAG,SAAS,CAAC;IAC9B,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IAC7B,MAAM,IAAI,GAAG,IAAA,+BAAQ,EAAC,IAAI,EAAE,KAAK,EAAE,GAAG,UAAU,CAAC,CAAC;IAElD,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE;YACjD,IAAI,YAAY,IAAI,CAAC,eAAe,EAAE,CAAC;gBACrC,OAAO,YAAY,CAAC;YACtB,CAAC;YACD,OAAO,IAAA,4BAAe,EAAC,eAAe,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,UAAU,CAAC,CAAC;QACtE,CAAC,CAAQ,CAAC;IACZ,CAAC;IAED,IAAI,IAAI,IAAI,CAAC,eAAe;QAAE,OAAO,IAAW,CAAC;IAEjD,2FAA2F;IAC3F,OAAO,IAAA,4BAAe,EAAC,eAAe,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,UAAU,CAAC,CAAC;AACtE,CAAC,CAAC"}
|
package/lib/model/utils.cjs
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isTransient = isTransient;
|
|
4
|
-
exports.modelToTransient = modelToTransient;
|
|
5
|
-
const repository_1 = require("./../repository/index.cjs");
|
|
6
|
-
const decorator_validation_1 = require("@decaf-ts/decorator-validation");
|
|
7
|
-
const constants_1 = require("./constants.cjs");
|
|
8
|
-
/**
|
|
9
|
-
* @description Checks if a model is marked as transient
|
|
10
|
-
* @summary Determines whether a model class has been decorated with the transient decorator
|
|
11
|
-
* @template M - Type extending Model
|
|
12
|
-
* @param {M} model - The model instance to check
|
|
13
|
-
* @return {boolean} True if the model is transient, false otherwise
|
|
14
|
-
* @function isTransient
|
|
15
|
-
* @memberOf module:db-decorators
|
|
16
|
-
*/
|
|
17
|
-
function isTransient(model) {
|
|
18
|
-
return !!(Reflect.getMetadata(repository_1.Repository.key(constants_1.DBKeys.TRANSIENT), model.constructor) ||
|
|
19
|
-
Reflect.getMetadata(repository_1.Repository.key(constants_1.DBKeys.TRANSIENT), decorator_validation_1.Model.get(model.constructor.name)));
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* @description Separates transient properties from a model
|
|
23
|
-
* @summary Extracts properties marked as transient into a separate object
|
|
24
|
-
* @template M - Type extending Model
|
|
25
|
-
* @param {M} model - The model instance to process
|
|
26
|
-
* @return {Object} Object containing the model without transient properties and a separate transient object
|
|
27
|
-
* @property {M} model - The model with transient properties removed
|
|
28
|
-
* @property {Record<string, any>} [transient] - Object containing the transient properties
|
|
29
|
-
* @function modelToTransient
|
|
30
|
-
* @memberOf module:db-decorators
|
|
31
|
-
* @mermaid
|
|
32
|
-
* sequenceDiagram
|
|
33
|
-
* participant Caller
|
|
34
|
-
* participant modelToTransient
|
|
35
|
-
* participant isTransient
|
|
36
|
-
* participant getAllPropertyDecoratorsRecursive
|
|
37
|
-
*
|
|
38
|
-
* Caller->>modelToTransient: model
|
|
39
|
-
* modelToTransient->>isTransient: check if model is transient
|
|
40
|
-
* isTransient-->>modelToTransient: transient status
|
|
41
|
-
* alt model is not transient
|
|
42
|
-
* modelToTransient-->>Caller: {model}
|
|
43
|
-
* else model is transient
|
|
44
|
-
* modelToTransient->>getAllPropertyDecoratorsRecursive: get transient properties
|
|
45
|
-
* getAllPropertyDecoratorsRecursive-->>modelToTransient: property decorators
|
|
46
|
-
* modelToTransient->>modelToTransient: separate properties
|
|
47
|
-
* modelToTransient->>Model.build: rebuild model without transient props
|
|
48
|
-
* modelToTransient-->>Caller: {model, transient}
|
|
49
|
-
* end
|
|
50
|
-
*/
|
|
51
|
-
function modelToTransient(model) {
|
|
52
|
-
if (!isTransient(model))
|
|
53
|
-
return { model: model };
|
|
54
|
-
const decs = (0, repository_1.getAllPropertyDecoratorsRecursive)(model, undefined, repository_1.Repository.key(constants_1.DBKeys.TRANSIENT));
|
|
55
|
-
const result = Object.entries(decs).reduce((accum, [k, val]) => {
|
|
56
|
-
const transient = val.find((el) => el.key === "");
|
|
57
|
-
if (transient) {
|
|
58
|
-
accum.transient = accum.transient || {};
|
|
59
|
-
try {
|
|
60
|
-
accum.transient[k] = model[k];
|
|
61
|
-
}
|
|
62
|
-
catch (e) {
|
|
63
|
-
throw new repository_1.SerializationError(`Failed to serialize transient property ${k}: ${e}`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
accum.model = accum.model || {};
|
|
68
|
-
accum.model[k] = model[k];
|
|
69
|
-
}
|
|
70
|
-
return accum;
|
|
71
|
-
}, {});
|
|
72
|
-
result.model = decorator_validation_1.Model.build(result.model, model.constructor.name);
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
//# sourceMappingURL=utils.js.map
|
package/lib/model/utils.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
|
-
/**
|
|
3
|
-
* @description Checks if a model is marked as transient
|
|
4
|
-
* @summary Determines whether a model class has been decorated with the transient decorator
|
|
5
|
-
* @template M - Type extending Model
|
|
6
|
-
* @param {M} model - The model instance to check
|
|
7
|
-
* @return {boolean} True if the model is transient, false otherwise
|
|
8
|
-
* @function isTransient
|
|
9
|
-
* @memberOf module:db-decorators
|
|
10
|
-
*/
|
|
11
|
-
export declare function isTransient<M extends Model>(model: M): boolean;
|
|
12
|
-
/**
|
|
13
|
-
* @description Separates transient properties from a model
|
|
14
|
-
* @summary Extracts properties marked as transient into a separate object
|
|
15
|
-
* @template M - Type extending Model
|
|
16
|
-
* @param {M} model - The model instance to process
|
|
17
|
-
* @return {Object} Object containing the model without transient properties and a separate transient object
|
|
18
|
-
* @property {M} model - The model with transient properties removed
|
|
19
|
-
* @property {Record<string, any>} [transient] - Object containing the transient properties
|
|
20
|
-
* @function modelToTransient
|
|
21
|
-
* @memberOf module:db-decorators
|
|
22
|
-
* @mermaid
|
|
23
|
-
* sequenceDiagram
|
|
24
|
-
* participant Caller
|
|
25
|
-
* participant modelToTransient
|
|
26
|
-
* participant isTransient
|
|
27
|
-
* participant getAllPropertyDecoratorsRecursive
|
|
28
|
-
*
|
|
29
|
-
* Caller->>modelToTransient: model
|
|
30
|
-
* modelToTransient->>isTransient: check if model is transient
|
|
31
|
-
* isTransient-->>modelToTransient: transient status
|
|
32
|
-
* alt model is not transient
|
|
33
|
-
* modelToTransient-->>Caller: {model}
|
|
34
|
-
* else model is transient
|
|
35
|
-
* modelToTransient->>getAllPropertyDecoratorsRecursive: get transient properties
|
|
36
|
-
* getAllPropertyDecoratorsRecursive-->>modelToTransient: property decorators
|
|
37
|
-
* modelToTransient->>modelToTransient: separate properties
|
|
38
|
-
* modelToTransient->>Model.build: rebuild model without transient props
|
|
39
|
-
* modelToTransient-->>Caller: {model, transient}
|
|
40
|
-
* end
|
|
41
|
-
*/
|
|
42
|
-
export declare function modelToTransient<M extends Model>(model: M): {
|
|
43
|
-
model: M;
|
|
44
|
-
transient?: Record<string, any>;
|
|
45
|
-
};
|
package/lib/model/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/model/utils.ts"],"names":[],"mappings":";;AAiBA,kCAQC;AAgCD,4CAmCC;AA5FD,0DAIuB;AACvB,yEAAuD;AACvD,+CAAqC;AAErC;;;;;;;;GAQG;AACH,SAAgB,WAAW,CAAkB,KAAQ;IACnD,OAAO,CAAC,CAAC,CACP,OAAO,CAAC,WAAW,CAAC,uBAAU,CAAC,GAAG,CAAC,kBAAM,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC;QACxE,OAAO,CAAC,WAAW,CACjB,uBAAU,CAAC,GAAG,CAAC,kBAAM,CAAC,SAAS,CAAC,EAChC,4BAAK,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAQ,CACzC,CACF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,SAAgB,gBAAgB,CAC9B,KAAQ;IAER,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IACjD,MAAM,IAAI,GAA0B,IAAA,8CAAiC,EACnE,KAAK,EACL,SAAS,EACT,uBAAU,CAAC,GAAG,CAAC,kBAAM,CAAC,SAAS,CAAC,CACR,CAAC;IAE3B,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CACxC,CACE,KAAsE,EACtE,CAAC,CAAC,EAAE,GAAG,CAAC,EACR,EAAE;QACF,MAAM,SAAS,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAA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