av6-core 1.4.2 → 1.4.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/dist/index.d.mts CHANGED
@@ -431,6 +431,7 @@ interface CacheAdapter {
431
431
  interface SingleValidationMapping {
432
432
  create?: DtoMappingFunction;
433
433
  update?: DtoMappingFunction;
434
+ bulkCreateUpdate?: DtoMappingFunction;
434
435
  }
435
436
  interface Mapper {
436
437
  dtoMapping: Record<string, DtoMappingFunction>;
package/dist/index.d.ts CHANGED
@@ -431,6 +431,7 @@ interface CacheAdapter {
431
431
  interface SingleValidationMapping {
432
432
  create?: DtoMappingFunction;
433
433
  update?: DtoMappingFunction;
434
+ bulkCreateUpdate?: DtoMappingFunction;
434
435
  }
435
436
  interface Mapper {
436
437
  dtoMapping: Record<string, DtoMappingFunction>;
package/dist/index.js CHANGED
@@ -927,7 +927,7 @@ var buildRelationWrite = (rel, op, env) => {
927
927
  if (writeCfg.strategy === "replace") return { deleteMany: {}, create: itemsCreate };
928
928
  if (writeCfg.strategy === "upsert") {
929
929
  const incomingIds = [];
930
- const upsertItems = [];
930
+ const updateItems = [];
931
931
  const createOnly = [];
932
932
  for (const item of arr) {
933
933
  const itemRec = isRecord(item) ? item : {};
@@ -940,14 +940,13 @@ var buildRelationWrite = (rel, op, env) => {
940
940
  }
941
941
  const pkNum = typeof pk === "string" ? Number(pk) : pk;
942
942
  if (Number.isFinite(pkNum)) incomingIds.push(pkNum);
943
- upsertItems.push({
943
+ updateItems.push({
944
944
  where: { [itemPrimaryKey]: pkNum },
945
- create: dataCreate,
946
945
  update: omitUndefined(dataUpdate)
947
946
  });
948
947
  }
949
948
  const payload = {};
950
- if (upsertItems.length) payload.upsert = upsertItems;
949
+ if (updateItems.length) payload.update = updateItems;
951
950
  if (createOnly.length) payload.create = createOnly;
952
951
  const cfgAny = writeCfg;
953
952
  const now = /* @__PURE__ */ new Date();
@@ -958,18 +957,16 @@ var buildRelationWrite = (rel, op, env) => {
958
957
  };
959
958
  if (data.deletedAt === "now") data.deletedAt = now;
960
959
  if (data.deletedBy === "ctx.userId") data.deletedBy = env.ctx.userId ?? void 0;
961
- if (incomingIds.length > 0) {
962
- payload.updateMany = [
963
- {
964
- where: {
965
- ...whereExtra,
966
- createdAt: { lt: now },
967
- [itemPrimaryKey]: { notIn: incomingIds }
968
- },
969
- data
970
- }
971
- ];
972
- }
960
+ payload.updateMany = [
961
+ {
962
+ where: {
963
+ ...whereExtra,
964
+ createdAt: { lt: now },
965
+ ...incomingIds.length > 0 ? { [itemPrimaryKey]: { notIn: incomingIds } } : {}
966
+ },
967
+ data
968
+ }
969
+ ];
973
970
  }
974
971
  return payload;
975
972
  }
@@ -1808,6 +1805,9 @@ var commonService = (serviceDeps) => {
1808
1805
  const messages = error.details.map((d) => d.message.replace(/['"]/g, "")).join(", ");
1809
1806
  throw new ErrorHandler(400, messages, error.details);
1810
1807
  }
1808
+ if (validationMapping && validationMapping[shortCodeData.shortCode] && validationMapping[shortCodeData.shortCode].bulkCreateUpdate) {
1809
+ await validationMapping[shortCodeData.shortCode].bulkCreateUpdate?.(validatedBulk[bulk.arrayKey]);
1810
+ }
1811
1811
  const commonData = await commonCreateUpdateRepositoryFactory.commonBulkUpsertAtomic({
1812
1812
  body: validatedBulk,
1813
1813
  shortCodeData,
package/dist/index.mjs CHANGED
@@ -877,7 +877,7 @@ var buildRelationWrite = (rel, op, env) => {
877
877
  if (writeCfg.strategy === "replace") return { deleteMany: {}, create: itemsCreate };
878
878
  if (writeCfg.strategy === "upsert") {
879
879
  const incomingIds = [];
880
- const upsertItems = [];
880
+ const updateItems = [];
881
881
  const createOnly = [];
882
882
  for (const item of arr) {
883
883
  const itemRec = isRecord(item) ? item : {};
@@ -890,14 +890,13 @@ var buildRelationWrite = (rel, op, env) => {
890
890
  }
891
891
  const pkNum = typeof pk === "string" ? Number(pk) : pk;
892
892
  if (Number.isFinite(pkNum)) incomingIds.push(pkNum);
893
- upsertItems.push({
893
+ updateItems.push({
894
894
  where: { [itemPrimaryKey]: pkNum },
895
- create: dataCreate,
896
895
  update: omitUndefined(dataUpdate)
897
896
  });
898
897
  }
899
898
  const payload = {};
900
- if (upsertItems.length) payload.upsert = upsertItems;
899
+ if (updateItems.length) payload.update = updateItems;
901
900
  if (createOnly.length) payload.create = createOnly;
902
901
  const cfgAny = writeCfg;
903
902
  const now = /* @__PURE__ */ new Date();
@@ -908,18 +907,16 @@ var buildRelationWrite = (rel, op, env) => {
908
907
  };
909
908
  if (data.deletedAt === "now") data.deletedAt = now;
910
909
  if (data.deletedBy === "ctx.userId") data.deletedBy = env.ctx.userId ?? void 0;
911
- if (incomingIds.length > 0) {
912
- payload.updateMany = [
913
- {
914
- where: {
915
- ...whereExtra,
916
- createdAt: { lt: now },
917
- [itemPrimaryKey]: { notIn: incomingIds }
918
- },
919
- data
920
- }
921
- ];
922
- }
910
+ payload.updateMany = [
911
+ {
912
+ where: {
913
+ ...whereExtra,
914
+ createdAt: { lt: now },
915
+ ...incomingIds.length > 0 ? { [itemPrimaryKey]: { notIn: incomingIds } } : {}
916
+ },
917
+ data
918
+ }
919
+ ];
923
920
  }
924
921
  return payload;
925
922
  }
@@ -1758,6 +1755,9 @@ var commonService = (serviceDeps) => {
1758
1755
  const messages = error.details.map((d) => d.message.replace(/['"]/g, "")).join(", ");
1759
1756
  throw new ErrorHandler(400, messages, error.details);
1760
1757
  }
1758
+ if (validationMapping && validationMapping[shortCodeData.shortCode] && validationMapping[shortCodeData.shortCode].bulkCreateUpdate) {
1759
+ await validationMapping[shortCodeData.shortCode].bulkCreateUpdate?.(validatedBulk[bulk.arrayKey]);
1760
+ }
1761
1761
  const commonData = await commonCreateUpdateRepositoryFactory.commonBulkUpsertAtomic({
1762
1762
  body: validatedBulk,
1763
1763
  shortCodeData,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "av6-core",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",