@elsikora/nestjs-crud-automator 4.3.3 → 4.3.4
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/cjs/decorator/api/function/update.decorator.js +19 -3
- package/dist/cjs/decorator/api/function/update.decorator.js.map +1 -1
- package/dist/esm/decorator/api/function/update.decorator.js +19 -3
- package/dist/esm/decorator/api/function/update.decorator.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -637,7 +637,7 @@ Steps do not dispatch function subscribers, create route metadata, or define Swa
|
|
|
637
637
|
|
|
638
638
|
`REQUIRED` opens one Automator-owned `QueryRunner` transaction when none exists. Nested `REQUIRED`, `MANDATORY`, and transactional `SUPPORTS` calls join the same manager and register ordered transaction events; only the outer route, function, or named scope owner commits, rolls back, and flushes post-transaction subscribers. `NONE` and nontransactional `SUPPORTS` do not produce post-transaction lifecycle work.
|
|
639
639
|
|
|
640
|
-
Before `onBeforeUpdate` runs, `ApiFunctionUpdate` performs one ordinary decorated GET through the active transaction manager when present. Update subscribers receive the incoming patch in `context.result`, the active manager repository when a transaction exists (otherwise the service base repository) in `context.DATA.repository`, and a top-level detached and frozen snapshot in `context.DATA.currentEntity: Readonly<TEntity>`. The snapshot is shallow: nested relations, arrays, JSON, dates, buffers, and lazy values retain aliases to the internal loaded entity, so mutating them can affect persistence. Automator merges the subscriber-returned patch into its internal loaded entity and does not issue a second explicit GET. A missing row keeps the GET error lifecycle, skips `onBeforeUpdate`, and then enters the UPDATE error lifecycle.
|
|
640
|
+
Before `onBeforeUpdate` runs, `ApiFunctionUpdate` performs one ordinary decorated GET through the active transaction manager when present. Update subscribers receive the incoming patch in `context.result`, the active manager repository when a transaction exists (otherwise the service base repository) in `context.DATA.repository`, and a top-level detached and frozen snapshot in `context.DATA.currentEntity: Readonly<TEntity>`. Enumerable own patch fields whose value is `undefined` are treated as omitted before subscribers and persistence, while `null` remains an explicit value; patches without such fields retain their original object identity. The same normalization is applied to a subscriber-replaced patch before it is saved. The snapshot is shallow: nested relations, arrays, JSON, dates, buffers, and lazy values retain aliases to the internal loaded entity, so mutating them can affect persistence. Automator merges the subscriber-returned patch into its internal loaded entity and does not issue a second explicit GET. A missing row keeps the GET error lifecycle, skips `onBeforeUpdate`, and then enters the UPDATE error lifecycle.
|
|
641
641
|
|
|
642
642
|
Use a named scope when application code, rather than a decorated function, must own the transaction:
|
|
643
643
|
|
|
@@ -66,6 +66,7 @@ function ApiFunctionUpdate(properties) {
|
|
|
66
66
|
return function (_target, propertyKey, descriptor) {
|
|
67
67
|
descriptor.value = async function (criteria, updateProperties) {
|
|
68
68
|
const mandatoryWhere = readScopeStorage_class.ApiControllerGeneratedReadScopeStorage.claim(type_enum.EApiFunctionType.UPDATE, criteria);
|
|
69
|
+
const normalizedUpdateProperties = normalizeUpdateProperties(updateProperties);
|
|
69
70
|
return await functionTransaction_utility.ApiFunctionExecuteWithTransaction({
|
|
70
71
|
callback: async (eventManager) => {
|
|
71
72
|
const entityInstance = new entity();
|
|
@@ -95,7 +96,7 @@ function ApiFunctionUpdate(properties) {
|
|
|
95
96
|
}
|
|
96
97
|
catch (caughtError) {
|
|
97
98
|
const errorExecutionContext = {
|
|
98
|
-
DATA: { criteria, eventManager, properties:
|
|
99
|
+
DATA: { criteria, eventManager, properties: normalizedUpdateProperties, repository },
|
|
99
100
|
ENTITY: entityInstance,
|
|
100
101
|
FUNCTION_TYPE: type_enum.EApiFunctionType.UPDATE,
|
|
101
102
|
};
|
|
@@ -107,13 +108,14 @@ function ApiFunctionUpdate(properties) {
|
|
|
107
108
|
DATA: { criteria, currentEntity, eventManager, repository },
|
|
108
109
|
ENTITY: entityInstance,
|
|
109
110
|
FUNCTION_TYPE: type_enum.EApiFunctionType.UPDATE,
|
|
110
|
-
result:
|
|
111
|
+
result: normalizedUpdateProperties,
|
|
111
112
|
};
|
|
112
113
|
const result = await executor_class.ApiSubscriberExecutor.executeFunctionBeforeSubscribers(this.constructor, entityInstance, type_enum.EApiFunctionType.UPDATE, executionContext);
|
|
113
114
|
if (result) {
|
|
114
115
|
executionContext.result = result;
|
|
115
116
|
}
|
|
116
|
-
|
|
117
|
+
const executorProperties = normalizeUpdateProperties(executionContext.result ?? {});
|
|
118
|
+
return await executor({ constructor: this.constructor, criteria, entity, existingEntity, properties: executorProperties, repository });
|
|
117
119
|
},
|
|
118
120
|
entity,
|
|
119
121
|
functionType: type_enum.EApiFunctionType.UPDATE,
|
|
@@ -221,6 +223,20 @@ async function executor(options) {
|
|
|
221
223
|
}), { cause: caughtError });
|
|
222
224
|
}
|
|
223
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* Treats enumerable own properties with an undefined value as omitted update fields.
|
|
228
|
+
* Returns the original patch when no normalization is needed so subscriber identity remains stable.
|
|
229
|
+
* @template E The entity type
|
|
230
|
+
* @param {TApiFunctionUpdateProperties<E>} properties - Update patch to normalize
|
|
231
|
+
* @returns {TApiFunctionUpdateProperties<E>} The original patch or a shallow normalized copy
|
|
232
|
+
*/
|
|
233
|
+
function normalizeUpdateProperties(properties) {
|
|
234
|
+
const entries = Object.entries(properties);
|
|
235
|
+
if (!entries.some(([, value]) => value === undefined)) {
|
|
236
|
+
return properties;
|
|
237
|
+
}
|
|
238
|
+
return Object.fromEntries(entries.filter(([, value]) => value !== undefined));
|
|
239
|
+
}
|
|
224
240
|
|
|
225
241
|
exports.ApiFunctionUpdate = ApiFunctionUpdate;
|
|
226
242
|
//# sourceMappingURL=update.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.decorator.js","sources":["../../../../../../src/decorator/api/function/update.decorator.ts"],"sourcesContent":[null],"names":["EApiFunctionTransactionMode","ApiFunctionGet","ApiControllerGeneratedReadScopeStorage","EApiFunctionType","ApiFunctionExecuteWithTransaction","ApiSubscriberExecutor","EApiSubscriberOnType","ErrorException","ApiControllerGeneratedFunctionCapability","ApiFunctionContextStorage","DatabaseTypeOrmIsEntityNotFound","NotFoundException","ErrorString","EErrorStringAction","DatabaseTypeOrmIsEntityMetadataNotFound","InternalServerErrorException","DatabaseTypeOrmIsForeignKeyViolation","DatabaseTypeOrmGetForeignKeyViolationDetails","EApiExceptionDetailsType","BadRequestException","HttpStatus","DatabaseTypeOrmIsUniqueViolation","DatabaseTypeOrmGetUniqueViolationDetails","ConflictException","HttpException","LoggerUtility","FormatErrorEvidenceForLog"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA;;;;;;AAMG;AACG,SAAU,iBAAiB,CAA2B,UAAqC,EAAA;AAChG,IAAA,MAAM,EAAE,MAAM,EAAE,GAA8B,UAAU;IACxD,MAAM,eAAe,GAAgC,UAAU,CAAC,WAAW,EAAE,IAAI,IAAIA,qCAA2B,CAAC,QAAQ;AACzH,IAAA,MAAM,YAAY,GAAiGC,wBAAc,CAAI,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,WAAW,EAAE,CAAC;AACrL,IAAA,IAAI,WAAwH;AAE5H,IAAA,OAAO,UAAU,OAAgB,EAAE,WAAmB,EAAE,UAA8B,EAAA;AACrF,QAAA,UAAU,CAAC,KAAK,GAAG,gBAAqD,QAAuC,EAAE,gBAAiD,EAAA;AACjK,YAAA,MAAM,cAAc,GAA+CC,6DAAsC,CAAC,KAAK,CAACC,0BAAgB,CAAC,MAAM,EAAE,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"update.decorator.js","sources":["../../../../../../src/decorator/api/function/update.decorator.ts"],"sourcesContent":[null],"names":["EApiFunctionTransactionMode","ApiFunctionGet","ApiControllerGeneratedReadScopeStorage","EApiFunctionType","ApiFunctionExecuteWithTransaction","ApiSubscriberExecutor","EApiSubscriberOnType","ErrorException","ApiControllerGeneratedFunctionCapability","ApiFunctionContextStorage","DatabaseTypeOrmIsEntityNotFound","NotFoundException","ErrorString","EErrorStringAction","DatabaseTypeOrmIsEntityMetadataNotFound","InternalServerErrorException","DatabaseTypeOrmIsForeignKeyViolation","DatabaseTypeOrmGetForeignKeyViolationDetails","EApiExceptionDetailsType","BadRequestException","HttpStatus","DatabaseTypeOrmIsUniqueViolation","DatabaseTypeOrmGetUniqueViolationDetails","ConflictException","HttpException","LoggerUtility","FormatErrorEvidenceForLog"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA;;;;;;AAMG;AACG,SAAU,iBAAiB,CAA2B,UAAqC,EAAA;AAChG,IAAA,MAAM,EAAE,MAAM,EAAE,GAA8B,UAAU;IACxD,MAAM,eAAe,GAAgC,UAAU,CAAC,WAAW,EAAE,IAAI,IAAIA,qCAA2B,CAAC,QAAQ;AACzH,IAAA,MAAM,YAAY,GAAiGC,wBAAc,CAAI,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,WAAW,EAAE,CAAC;AACrL,IAAA,IAAI,WAAwH;AAE5H,IAAA,OAAO,UAAU,OAAgB,EAAE,WAAmB,EAAE,UAA8B,EAAA;AACrF,QAAA,UAAU,CAAC,KAAK,GAAG,gBAAqD,QAAuC,EAAE,gBAAiD,EAAA;AACjK,YAAA,MAAM,cAAc,GAA+CC,6DAAsC,CAAC,KAAK,CAACC,0BAAgB,CAAC,MAAM,EAAE,QAAQ,CAAC;AAClJ,YAAA,MAAM,0BAA0B,GAAoC,yBAAyB,CAAC,gBAAgB,CAAC;YAE/G,OAAO,MAAMC,6DAAiC,CAAC;AAC9C,gBAAA,QAAQ,EAAE,OAAO,YAAuC,KAAgB;AACvE,oBAAA,MAAM,cAAc,GAAM,IAAI,MAAM,EAAE;AACtC,oBAAA,MAAM,UAAU,GAAkB,YAAY,GAAG,YAAY,CAAC,aAAa,CAAI,MAAM,CAAC,GAAG,IAAI,CAAC,UAAU;oBAExG,IAAI,CAAC,UAAU,EAAE;AAChB,wBAAA,MAAM,qBAAqB,GAAkG;AAC5H,4BAAA,IAAI,EAAE,EAAE,QAAQ,EAAE,YAA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SAAS,CAAC,CAAoC;AAC7I;;"}
|
|
@@ -64,6 +64,7 @@ function ApiFunctionUpdate(properties) {
|
|
|
64
64
|
return function (_target, propertyKey, descriptor) {
|
|
65
65
|
descriptor.value = async function (criteria, updateProperties) {
|
|
66
66
|
const mandatoryWhere = ApiControllerGeneratedReadScopeStorage.claim(EApiFunctionType.UPDATE, criteria);
|
|
67
|
+
const normalizedUpdateProperties = normalizeUpdateProperties(updateProperties);
|
|
67
68
|
return await ApiFunctionExecuteWithTransaction({
|
|
68
69
|
callback: async (eventManager) => {
|
|
69
70
|
const entityInstance = new entity();
|
|
@@ -93,7 +94,7 @@ function ApiFunctionUpdate(properties) {
|
|
|
93
94
|
}
|
|
94
95
|
catch (caughtError) {
|
|
95
96
|
const errorExecutionContext = {
|
|
96
|
-
DATA: { criteria, eventManager, properties:
|
|
97
|
+
DATA: { criteria, eventManager, properties: normalizedUpdateProperties, repository },
|
|
97
98
|
ENTITY: entityInstance,
|
|
98
99
|
FUNCTION_TYPE: EApiFunctionType.UPDATE,
|
|
99
100
|
};
|
|
@@ -105,13 +106,14 @@ function ApiFunctionUpdate(properties) {
|
|
|
105
106
|
DATA: { criteria, currentEntity, eventManager, repository },
|
|
106
107
|
ENTITY: entityInstance,
|
|
107
108
|
FUNCTION_TYPE: EApiFunctionType.UPDATE,
|
|
108
|
-
result:
|
|
109
|
+
result: normalizedUpdateProperties,
|
|
109
110
|
};
|
|
110
111
|
const result = await ApiSubscriberExecutor.executeFunctionBeforeSubscribers(this.constructor, entityInstance, EApiFunctionType.UPDATE, executionContext);
|
|
111
112
|
if (result) {
|
|
112
113
|
executionContext.result = result;
|
|
113
114
|
}
|
|
114
|
-
|
|
115
|
+
const executorProperties = normalizeUpdateProperties(executionContext.result ?? {});
|
|
116
|
+
return await executor({ constructor: this.constructor, criteria, entity, existingEntity, properties: executorProperties, repository });
|
|
115
117
|
},
|
|
116
118
|
entity,
|
|
117
119
|
functionType: EApiFunctionType.UPDATE,
|
|
@@ -219,6 +221,20 @@ async function executor(options) {
|
|
|
219
221
|
}), { cause: caughtError });
|
|
220
222
|
}
|
|
221
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* Treats enumerable own properties with an undefined value as omitted update fields.
|
|
226
|
+
* Returns the original patch when no normalization is needed so subscriber identity remains stable.
|
|
227
|
+
* @template E The entity type
|
|
228
|
+
* @param {TApiFunctionUpdateProperties<E>} properties - Update patch to normalize
|
|
229
|
+
* @returns {TApiFunctionUpdateProperties<E>} The original patch or a shallow normalized copy
|
|
230
|
+
*/
|
|
231
|
+
function normalizeUpdateProperties(properties) {
|
|
232
|
+
const entries = Object.entries(properties);
|
|
233
|
+
if (!entries.some(([, value]) => value === undefined)) {
|
|
234
|
+
return properties;
|
|
235
|
+
}
|
|
236
|
+
return Object.fromEntries(entries.filter(([, value]) => value !== undefined));
|
|
237
|
+
}
|
|
222
238
|
|
|
223
239
|
export { ApiFunctionUpdate };
|
|
224
240
|
//# sourceMappingURL=update.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.decorator.js","sources":["../../../../../../src/decorator/api/function/update.decorator.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA;;;;;;AAMG;AACG,SAAU,iBAAiB,CAA2B,UAAqC,EAAA;AAChG,IAAA,MAAM,EAAE,MAAM,EAAE,GAA8B,UAAU;IACxD,MAAM,eAAe,GAAgC,UAAU,CAAC,WAAW,EAAE,IAAI,IAAI,2BAA2B,CAAC,QAAQ;AACzH,IAAA,MAAM,YAAY,GAAiG,cAAc,CAAI,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,WAAW,EAAE,CAAC;AACrL,IAAA,IAAI,WAAwH;AAE5H,IAAA,OAAO,UAAU,OAAgB,EAAE,WAAmB,EAAE,UAA8B,EAAA;AACrF,QAAA,UAAU,CAAC,KAAK,GAAG,gBAAqD,QAAuC,EAAE,gBAAiD,EAAA;AACjK,YAAA,MAAM,cAAc,GAA+C,sCAAsC,CAAC,KAAK,CAAC,gBAAgB,CAAC,MAAM,EAAE,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"update.decorator.js","sources":["../../../../../../src/decorator/api/function/update.decorator.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA;;;;;;AAMG;AACG,SAAU,iBAAiB,CAA2B,UAAqC,EAAA;AAChG,IAAA,MAAM,EAAE,MAAM,EAAE,GAA8B,UAAU;IACxD,MAAM,eAAe,GAAgC,UAAU,CAAC,WAAW,EAAE,IAAI,IAAI,2BAA2B,CAAC,QAAQ;AACzH,IAAA,MAAM,YAAY,GAAiG,cAAc,CAAI,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,WAAW,EAAE,CAAC;AACrL,IAAA,IAAI,WAAwH;AAE5H,IAAA,OAAO,UAAU,OAAgB,EAAE,WAAmB,EAAE,UAA8B,EAAA;AACrF,QAAA,UAAU,CAAC,KAAK,GAAG,gBAAqD,QAAuC,EAAE,gBAAiD,EAAA;AACjK,YAAA,MAAM,cAAc,GAA+C,sCAAsC,CAAC,KAAK,CAAC,gBAAgB,CAAC,MAAM,EAAE,QAAQ,CAAC;AAClJ,YAAA,MAAM,0BAA0B,GAAoC,yBAAyB,CAAC,gBAAgB,CAAC;YAE/G,OAAO,MAAM,iCAAiC,CAAC;AAC9C,gBAAA,QAAQ,EAAE,OAAO,YAAuC,KAAgB;AACvE,oBAAA,MAAM,cAAc,GAAM,IAAI,MAAM,EAAE;AACtC,oBAAA,MAAM,UAAU,GAAkB,YAAY,GAAG,YAAY,CAAC,aAAa,CAAI,MAAM,CAAC,GAAG,IAAI,CAAC,UAAU;oBAExG,IAAI,CAAC,UAAU,EAAE;AAChB,wBAAA,MAAM,qBAAqB,GAAkG;AAC5H,4BAAA,IAAI,EAAE,EAAE,QAAQ,E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