@koalarx/nest 3.1.35 → 3.1.36
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/core/database/entity.base.d.ts +6 -0
- package/core/database/entity.base.js +28 -0
- package/core/database/entity.decorator.d.ts +1 -8
- package/core/database/entity.decorator.js +3 -0
- package/core/database/repository.base.js +12 -2
- package/package.json +1 -1
- package/tsconfig.lib.tsbuildinfo +1 -1
|
@@ -13,9 +13,15 @@ export type EntityProps<T extends IComparable<T>> = Overwrite<Omit<{
|
|
|
13
13
|
} ? U : never;
|
|
14
14
|
}>;
|
|
15
15
|
export declare abstract class EntityBase<T extends IComparable<T>> implements IComparable<T> {
|
|
16
|
+
private _trackHasUpdateOnSet;
|
|
17
|
+
private _setTrackingProxy?;
|
|
16
18
|
_id: IComparableId;
|
|
17
19
|
_action: EntityActionType;
|
|
20
|
+
_hasUpdate: boolean;
|
|
18
21
|
constructor(props?: EntityProps<T>);
|
|
22
|
+
protected startHasUpdateTracking(): void;
|
|
23
|
+
protected stopHasUpdateTracking(): void;
|
|
24
|
+
protected createSetTrackingProxy(): this;
|
|
19
25
|
automap(props?: EntityProps<T>, context?: AutomapContext): void;
|
|
20
26
|
equals(obj: EntityBase<T>): boolean;
|
|
21
27
|
}
|
|
@@ -11,13 +11,41 @@ var EntityActionType;
|
|
|
11
11
|
EntityActionType[EntityActionType["update"] = 2] = "update";
|
|
12
12
|
})(EntityActionType || (exports.EntityActionType = EntityActionType = {}));
|
|
13
13
|
class EntityBase {
|
|
14
|
+
_trackHasUpdateOnSet = false;
|
|
15
|
+
_setTrackingProxy;
|
|
14
16
|
_id;
|
|
15
17
|
_action = EntityActionType.create;
|
|
18
|
+
_hasUpdate = false;
|
|
16
19
|
constructor(props) {
|
|
17
20
|
if (props) {
|
|
18
21
|
this.automap(props);
|
|
19
22
|
}
|
|
20
23
|
}
|
|
24
|
+
startHasUpdateTracking() {
|
|
25
|
+
this._trackHasUpdateOnSet = true;
|
|
26
|
+
}
|
|
27
|
+
stopHasUpdateTracking() {
|
|
28
|
+
this._trackHasUpdateOnSet = false;
|
|
29
|
+
}
|
|
30
|
+
createSetTrackingProxy() {
|
|
31
|
+
if (this._setTrackingProxy) {
|
|
32
|
+
return this._setTrackingProxy;
|
|
33
|
+
}
|
|
34
|
+
this._setTrackingProxy = new Proxy(this, {
|
|
35
|
+
set: (target, property, value, receiver) => {
|
|
36
|
+
const success = Reflect.set(target, property, value, receiver);
|
|
37
|
+
if (success &&
|
|
38
|
+
target._trackHasUpdateOnSet &&
|
|
39
|
+
property !== '_hasUpdate' &&
|
|
40
|
+
property !== '_trackHasUpdateOnSet' &&
|
|
41
|
+
property !== '_setTrackingProxy') {
|
|
42
|
+
target._hasUpdate = true;
|
|
43
|
+
}
|
|
44
|
+
return success;
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
return this._setTrackingProxy;
|
|
48
|
+
}
|
|
21
49
|
automap(props, context = (0, automap_cycle_context_1.createAutomapContext)()) {
|
|
22
50
|
if (props) {
|
|
23
51
|
if (typeof props === 'object' && props !== null) {
|
|
@@ -8,12 +8,5 @@ export interface IdConfig<T extends EntityProps<any>> {
|
|
|
8
8
|
composite?: readonly (keyof T)[];
|
|
9
9
|
custom?: (props: T) => string | number | CompositeId;
|
|
10
10
|
}
|
|
11
|
-
export declare function Entity<T extends new (...args: any[]) => EntityBase<any>>(id?: keyof EntityProps<InstanceType<T>> | IdConfig<EntityProps<InstanceType<T>>>): (target: T) =>
|
|
12
|
-
new (...args: any[]): {
|
|
13
|
-
_id: import("../utils/interfaces/icomparable").IComparableId;
|
|
14
|
-
_action: import("./entity.base").EntityActionType;
|
|
15
|
-
automap(props?: import("./entity.base").EntityProps<any> | undefined, context?: import("../utils/automap-cycle-context").AutomapContext): void;
|
|
16
|
-
equals(obj: EntityBase<any>): boolean;
|
|
17
|
-
};
|
|
18
|
-
} & T;
|
|
11
|
+
export declare function Entity<T extends new (...args: any[]) => EntityBase<any>>(id?: keyof EntityProps<InstanceType<T>> | IdConfig<EntityProps<InstanceType<T>>>): (target: T) => T;
|
|
19
12
|
export {};
|
|
@@ -14,9 +14,12 @@ function Entity(id) {
|
|
|
14
14
|
class NewConstructor extends target {
|
|
15
15
|
constructor(...args) {
|
|
16
16
|
super(...args);
|
|
17
|
+
this.stopHasUpdateTracking();
|
|
17
18
|
if (typeof this.automap === 'function') {
|
|
18
19
|
this.automap(args[0]);
|
|
19
20
|
}
|
|
21
|
+
this.startHasUpdateTracking();
|
|
22
|
+
return this.createSetTrackingProxy();
|
|
20
23
|
}
|
|
21
24
|
}
|
|
22
25
|
Object.setPrototypeOf(NewConstructor.prototype, target.prototype);
|
|
@@ -210,7 +210,8 @@ class RepositoryBase {
|
|
|
210
210
|
else if (entity[key] instanceof entity_base_1.EntityBase) {
|
|
211
211
|
const entityInstance = entity[key];
|
|
212
212
|
const modelName = entity[key].constructor.name;
|
|
213
|
-
if (entity[key]._action === entity_base_1.EntityActionType.update
|
|
213
|
+
if (entity[key]._action === entity_base_1.EntityActionType.update &&
|
|
214
|
+
entity[key]._hasUpdate) {
|
|
214
215
|
relationUpdates.push({
|
|
215
216
|
modelName: (0, KlString_1.toCamelCase)(modelName),
|
|
216
217
|
entityInstance,
|
|
@@ -377,7 +378,16 @@ class RepositoryBase {
|
|
|
377
378
|
}
|
|
378
379
|
if (relationUpdates.length > 0) {
|
|
379
380
|
await Promise.all([
|
|
380
|
-
...relationUpdates.map((
|
|
381
|
+
...relationUpdates.map((relationUpdate) => transaction[relationUpdate.modelName]
|
|
382
|
+
.update(relationUpdate.schema)
|
|
383
|
+
.then(() => {
|
|
384
|
+
if (relationUpdate.relations.length === 0) {
|
|
385
|
+
return Promise.all([]);
|
|
386
|
+
}
|
|
387
|
+
return Promise.all(relationUpdate.relations.map((relation) => {
|
|
388
|
+
return this.persistRelations(transaction, relation);
|
|
389
|
+
}));
|
|
390
|
+
})),
|
|
381
391
|
]);
|
|
382
392
|
}
|
|
383
393
|
if (relationCreates.length > 0) {
|