@koalarx/nest 3.1.36 → 3.1.37

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.
@@ -17,6 +17,38 @@ class EntityBase {
17
17
  _action = EntityActionType.create;
18
18
  _hasUpdate = false;
19
19
  constructor(props) {
20
+ Object.defineProperties(this, {
21
+ _trackHasUpdateOnSet: {
22
+ enumerable: false,
23
+ configurable: true,
24
+ writable: true,
25
+ value: false,
26
+ },
27
+ _setTrackingProxy: {
28
+ enumerable: false,
29
+ configurable: true,
30
+ writable: true,
31
+ value: undefined,
32
+ },
33
+ _id: {
34
+ enumerable: false,
35
+ configurable: true,
36
+ writable: true,
37
+ value: this._id,
38
+ },
39
+ _action: {
40
+ enumerable: false,
41
+ configurable: true,
42
+ writable: true,
43
+ value: this._action,
44
+ },
45
+ _hasUpdate: {
46
+ enumerable: false,
47
+ configurable: true,
48
+ writable: true,
49
+ value: this._hasUpdate,
50
+ },
51
+ });
20
52
  if (props) {
21
53
  this.automap(props);
22
54
  }
@@ -37,6 +69,8 @@ class EntityBase {
37
69
  if (success &&
38
70
  target._trackHasUpdateOnSet &&
39
71
  property !== '_hasUpdate' &&
72
+ property !== '_action' &&
73
+ property !== '_id' &&
40
74
  property !== '_trackHasUpdateOnSet' &&
41
75
  property !== '_setTrackingProxy') {
42
76
  target._hasUpdate = true;
@@ -8,5 +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) => T;
11
+ export declare function Entity(id?: keyof EntityProps<any> | IdConfig<EntityProps<any>>): <T extends new (...args: any[]) => EntityBase<any>>(target: T) => T;
12
12
  export {};
@@ -30,6 +30,8 @@ function Entity(id) {
30
30
  });
31
31
  const idConfig = normalizeIdConfig(id);
32
32
  Reflect.defineMetadata('entity:id', idConfig, NewConstructor.prototype);
33
+ Reflect.defineMetadata('entity:decorated-constructor', NewConstructor, target.prototype);
34
+ Reflect.defineMetadata('entity:decorated-constructor', NewConstructor, NewConstructor.prototype);
33
35
  return NewConstructor;
34
36
  };
35
37
  }
@@ -285,8 +285,15 @@ class RepositoryBase {
285
285
  }
286
286
  createEntity(data, entityClass) {
287
287
  const entity = new (entityClass || this._modelName)();
288
+ const trackedEntity = entity;
289
+ if (typeof trackedEntity.stopHasUpdateTracking === 'function') {
290
+ trackedEntity.stopHasUpdateTracking();
291
+ }
288
292
  entity._action = entity_base_1.EntityActionType.update;
289
293
  entity.automap(data);
294
+ if (typeof trackedEntity.startHasUpdateTracking === 'function') {
295
+ trackedEntity.startHasUpdateTracking();
296
+ }
290
297
  return entity;
291
298
  }
292
299
  orphanRemoval(client, entity) {
@@ -15,12 +15,19 @@ function mapEntityReference(value, EntityOnPropKey, context, action) {
15
15
  if (cachedEntity) {
16
16
  return cachedEntity;
17
17
  }
18
- const entity = new EntityOnPropKey();
18
+ const DecoratedEntityConstructor = Reflect.getMetadata('entity:decorated-constructor', EntityOnPropKey.prototype) ?? EntityOnPropKey;
19
+ const entity = new DecoratedEntityConstructor();
20
+ const trackedEntity = entity;
19
21
  if (entity && typeof entity.automap === 'function') {
20
- ;
21
- entity._action = action;
22
+ if (typeof trackedEntity.stopHasUpdateTracking === 'function') {
23
+ trackedEntity.stopHasUpdateTracking();
24
+ }
25
+ trackedEntity._action = action;
22
26
  context.references.set(value, entity);
23
- entity.automap(value, context);
27
+ trackedEntity.automap(value, context);
28
+ if (typeof trackedEntity.startHasUpdateTracking === 'function') {
29
+ trackedEntity.startHasUpdateTracking();
30
+ }
24
31
  }
25
32
  return entity;
26
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koalarx/nest",
3
- "version": "3.1.36",
3
+ "version": "3.1.37",
4
4
  "description": "",
5
5
  "author": "Igor D. Rangel",
6
6
  "license": "MIT",