@fjell/lib-sequelize 4.4.70 → 4.4.71

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.
@@ -1 +1 @@
1
- {"version":3,"file":"RowProcessor.d.ts","sourceRoot":"","sources":["../src/RowProcessor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAIlC,OAAO,EAAE,qBAAqB,EAAE,4BAA4B,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,KAAK,OAAO,MAAM,YAAY,CAAC;AACtC,OAAO,EAEL,cAAc,EACd,sBAAsB,EACtB,gBAAgB,EACjB,MAAM,YAAY,CAAC;AASpB,YAAY,EAAE,gBAAgB,EAAE,CAAC;AACjC,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,CAAC;AAElD,eAAO,MAAM,UAAU,GAAU,CAAC,SAAS,MAAM,EAC/C,EAAE,SAAS,MAAM,GAAG,KAAK,EACzB,EAAE,SAAS,MAAM,GAAG,KAAK,EACzB,EAAE,SAAS,MAAM,GAAG,KAAK,EACzB,EAAE,SAAS,MAAM,GAAG,KAAK,EACzB,EAAE,SAAS,MAAM,GAAG,KAAK,EACvB,KAAK,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,EACpB,UAAU,iBAAiB,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAClD,sBAAsB,4BAA4B,EAAE,EACpD,wBAAwB,qBAAqB,EAAE,EAC/C,UAAU,OAAO,CAAC,QAAQ,EAC1B,UAAU,gBAAgB,KACzB,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CA8DvC,CAAC"}
1
+ {"version":3,"file":"RowProcessor.d.ts","sourceRoot":"","sources":["../src/RowProcessor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAIlC,OAAO,EAAE,qBAAqB,EAAE,4BAA4B,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,KAAK,OAAO,MAAM,YAAY,CAAC;AACtC,OAAO,EAEL,cAAc,EACd,sBAAsB,EACtB,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAUpB,YAAY,EAAE,gBAAgB,EAAE,CAAC;AACjC,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,CAAC;AAElD,eAAO,MAAM,UAAU,GAAU,CAAC,SAAS,MAAM,EAC/C,EAAE,SAAS,MAAM,GAAG,KAAK,EACzB,EAAE,SAAS,MAAM,GAAG,KAAK,EACzB,EAAE,SAAS,MAAM,GAAG,KAAK,EACzB,EAAE,SAAS,MAAM,GAAG,KAAK,EACzB,EAAE,SAAS,MAAM,GAAG,KAAK,EACvB,KAAK,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,EACpB,UAAU,iBAAiB,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAClD,sBAAsB,4BAA4B,EAAE,EACpD,wBAAwB,qBAAqB,EAAE,EAC/C,UAAU,OAAO,CAAC,QAAQ,EAC1B,UAAU,gBAAgB,KACzB,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAqEvC,CAAC"}
package/dist/index.js CHANGED
@@ -580,11 +580,11 @@ var removeEvents = (item) => {
580
580
 
581
581
  // src/processing/ReferenceBuilder.ts
582
582
  var buildSequelizeReference = async (item, referenceDefinition, registry, context) => {
583
- const libLogger2 = logger_default.get("processing", "ReferenceBuilder");
583
+ const libLogger3 = logger_default.get("processing", "ReferenceBuilder");
584
584
  const isCompositeItem = referenceDefinition.kta.length > 1;
585
585
  const primaryKeyType = referenceDefinition.kta[0];
586
586
  if (isCompositeItem) {
587
- libLogger2.debug(
587
+ libLogger3.debug(
588
588
  "Detected composite item reference - will use ComKey with empty loc array",
589
589
  {
590
590
  kta: referenceDefinition.kta,
@@ -624,7 +624,7 @@ var buildSequelizeReference = async (item, referenceDefinition, registry, contex
624
624
  const columnName = referenceDefinition.locationColumns[i];
625
625
  const locValue = item[columnName];
626
626
  if (locValue == null) {
627
- libLogger2.warning(
627
+ libLogger3.warning(
628
628
  `Location column '${columnName}' is null/undefined for reference '${referenceDefinition.property}'. Falling back to empty loc array search.`
629
629
  );
630
630
  hasNullLocation = true;
@@ -647,7 +647,7 @@ var buildSequelizeReference = async (item, referenceDefinition, registry, contex
647
647
  pk: columnValue,
648
648
  loc
649
649
  };
650
- libLogger2.debug("Built full ComKey with location context", {
650
+ libLogger3.debug("Built full ComKey with location context", {
651
651
  itemKey,
652
652
  locationColumns: referenceDefinition.locationColumns,
653
653
  property: referenceDefinition.property
@@ -659,12 +659,12 @@ var buildSequelizeReference = async (item, referenceDefinition, registry, contex
659
659
  pk: columnValue,
660
660
  loc: []
661
661
  };
662
- libLogger2.debug("Using empty loc array for composite item reference", {
662
+ libLogger3.debug("Using empty loc array for composite item reference", {
663
663
  kta: referenceDefinition.kta,
664
664
  property: referenceDefinition.property
665
665
  });
666
666
  }
667
- libLogger2.debug("Created reference key", {
667
+ libLogger3.debug("Created reference key", {
668
668
  itemKey,
669
669
  isCompositeItem,
670
670
  hasLocationColumns: !!referenceDefinition.locationColumns,
@@ -673,10 +673,10 @@ var buildSequelizeReference = async (item, referenceDefinition, registry, contex
673
673
  let referencedItem;
674
674
  if (context) {
675
675
  if (context.isCached(itemKey)) {
676
- libLogger2.debug("Using cached reference", { itemKey, property: referenceDefinition.property });
676
+ libLogger3.debug("Using cached reference", { itemKey, property: referenceDefinition.property });
677
677
  referencedItem = context.getCached(itemKey);
678
678
  } else if (context.isInProgress(itemKey)) {
679
- libLogger2.debug("Circular dependency detected, creating reference placeholder", {
679
+ libLogger3.debug("Circular dependency detected, creating reference placeholder", {
680
680
  itemKey,
681
681
  property: referenceDefinition.property
682
682
  });
@@ -755,10 +755,17 @@ function addRefsToSequelizeItem(item, referenceDefinitions) {
755
755
  if (foreignKeyValue != null) {
756
756
  const key = buildKeyFromForeignKey(refDef, foreignKeyValue, item);
757
757
  const populatedItem = item[refDef.property];
758
- refs[refName] = {
759
- key,
760
- item: populatedItem
761
- };
758
+ if (populatedItem) {
759
+ const { key: _itemKey, ...itemProperties } = populatedItem;
760
+ refs[refName] = {
761
+ key,
762
+ ...itemProperties
763
+ };
764
+ } else {
765
+ refs[refName] = {
766
+ key
767
+ };
768
+ }
762
769
  } else {
763
770
  refs[refName] = {
764
771
  key: {
@@ -782,17 +789,25 @@ function updateForeignKeysFromRefs(item, refs, referenceDefinitions) {
782
789
  if (isPriKey2(ref.key)) {
783
790
  item[refDef.column] = ref.key.pk;
784
791
  } else if (isComKey2(ref.key)) {
785
- item[refDef.column] = ref.key.pk;
786
- if (refDef.locationColumns && ref.key.loc) {
787
- ref.key.loc.forEach((locItem, index) => {
792
+ const comKey = ref.key;
793
+ item[refDef.column] = comKey.pk;
794
+ if (refDef.locationColumns && comKey.loc) {
795
+ comKey.loc.forEach((locItem, index) => {
788
796
  if (refDef.locationColumns && refDef.locationColumns[index]) {
789
797
  item[refDef.locationColumns[index]] = locItem.lk;
790
798
  }
791
799
  });
792
800
  }
793
801
  }
794
- if (ref.item) {
795
- item[refDef.property] = ref.item;
802
+ const { key, ...itemProperties } = ref;
803
+ const hasItemProperties = Object.keys(itemProperties).length > 0;
804
+ if (hasItemProperties) {
805
+ item[refDef.property] = {
806
+ key,
807
+ ...itemProperties
808
+ };
809
+ } else {
810
+ delete item[refDef.property];
796
811
  }
797
812
  } else if (ref == null) {
798
813
  if (refName in refs) {
@@ -811,6 +826,57 @@ function removeRefsFromSequelizeItem(item, referenceDefinitions) {
811
826
  return result;
812
827
  }
813
828
 
829
+ // src/processing/AggsAdapter.ts
830
+ var libLogger2 = logger_default.get("sequelize", "processing", "AggsAdapter");
831
+ function addAggsToItem(item, aggregationDefinitions) {
832
+ if (!aggregationDefinitions || aggregationDefinitions.length === 0) {
833
+ return item;
834
+ }
835
+ const aggs = {};
836
+ const result = { ...item };
837
+ for (const aggDef of aggregationDefinitions) {
838
+ const aggregationValue = item[aggDef.property];
839
+ if (typeof aggregationValue !== "undefined") {
840
+ aggs[aggDef.property] = aggregationValue;
841
+ delete result[aggDef.property];
842
+ libLogger2.debug(`Moved aggregation '${aggDef.property}' to aggs structure`, {
843
+ property: aggDef.property,
844
+ hasValue: typeof aggregationValue !== "undefined",
845
+ valueType: Array.isArray(aggregationValue) ? "array" : typeof aggregationValue
846
+ });
847
+ } else {
848
+ libLogger2.debug(`Aggregation '${aggDef.property}' is undefined, skipping`, {
849
+ property: aggDef.property
850
+ });
851
+ }
852
+ }
853
+ if (Object.keys(aggs).length > 0) {
854
+ return {
855
+ ...result,
856
+ aggs
857
+ };
858
+ }
859
+ return item;
860
+ }
861
+ function removeAggsFromItem(item, aggregationDefinitions) {
862
+ if (!aggregationDefinitions || aggregationDefinitions.length === 0) {
863
+ return item;
864
+ }
865
+ const result = { ...item };
866
+ if (result.aggs && typeof result.aggs === "object") {
867
+ for (const aggDef of aggregationDefinitions) {
868
+ if (typeof result.aggs[aggDef.property] !== "undefined") {
869
+ result[aggDef.property] = result.aggs[aggDef.property];
870
+ libLogger2.debug(`Moved aggregation '${aggDef.property}' from aggs to direct property`, {
871
+ property: aggDef.property
872
+ });
873
+ }
874
+ }
875
+ delete result.aggs;
876
+ }
877
+ return result;
878
+ }
879
+
814
880
  // src/RowProcessor.ts
815
881
  var logger6 = logger_default.get("sequelize", "RowProcessor");
816
882
  var processRow = async (row, keyTypes, referenceDefinitions, aggregationDefinitions, registry, context) => {
@@ -833,7 +899,7 @@ var processRow = async (row, keyTypes, referenceDefinitions, aggregationDefiniti
833
899
  await Promise.all(referencePromises);
834
900
  const referenceDuration = (typeof performance !== "undefined" ? performance.now() : Date.now()) - referenceStartTime;
835
901
  if (referenceDuration > 100) {
836
- logger6.info(`\u23F1\uFE0F REFERENCE_BUILDER_PERF: Loaded ${referenceDefinitions.length} references in parallel for ${item.key.kt} - ${referenceDuration.toFixed(2)}ms`);
902
+ logger6.debug(`\u23F1\uFE0F REFERENCE_BUILDER_PERF: Loaded ${referenceDefinitions.length} references in parallel for ${item.key.kt} - ${referenceDuration.toFixed(2)}ms`);
837
903
  }
838
904
  }
839
905
  if (aggregationDefinitions && aggregationDefinitions.length > 0) {
@@ -850,6 +916,10 @@ var processRow = async (row, keyTypes, referenceDefinitions, aggregationDefiniti
850
916
  item = addRefsToSequelizeItem(item, referenceDefinitions);
851
917
  logger6.debug("Added refs structure to item (transparent wrapper)", { key: item.key });
852
918
  }
919
+ if (aggregationDefinitions && aggregationDefinitions.length > 0) {
920
+ item = addAggsToItem(item, aggregationDefinitions);
921
+ logger6.debug("Added aggs structure to item (transparent wrapper)", { key: item.key });
922
+ }
853
923
  logger6.default("Processed Row: %j", stringifyJSON(item));
854
924
  return item;
855
925
  });
@@ -1151,7 +1221,8 @@ var getAllOperation = (models, definition, registry) => {
1151
1221
  if (options.include) {
1152
1222
  countOptions.include = options.include;
1153
1223
  }
1154
- const total = await model.count(countOptions);
1224
+ const countResult = await model.count(countOptions);
1225
+ const total = Array.isArray(countResult) ? countResult.length : countResult;
1155
1226
  logger7.debug(`[ALL] Total count for ${model.name}: ${total}`);
1156
1227
  delete options.limit;
1157
1228
  delete options.offset;
@@ -1243,6 +1314,9 @@ var getCreateOperation = (models, definition, registry) => {
1243
1314
  if (references && references.length > 0) {
1244
1315
  itemData = removeRefsFromSequelizeItem(itemData, references);
1245
1316
  }
1317
+ if (aggregations && aggregations.length > 0) {
1318
+ itemData = removeAggsFromItem(itemData, aggregations);
1319
+ }
1246
1320
  const invalidAttributes = [];
1247
1321
  for (const key of Object.keys(itemData)) {
1248
1322
  if (!modelAttributes[key]) {
@@ -1706,6 +1780,9 @@ var getUpdateOperation = (models, definition, registry) => {
1706
1780
  if (references && references.length > 0) {
1707
1781
  updateProps = removeRefsFromSequelizeItem(updateProps, references);
1708
1782
  }
1783
+ if (aggregations && aggregations.length > 0) {
1784
+ updateProps = removeAggsFromItem(updateProps, aggregations);
1785
+ }
1709
1786
  logger13.default(`Update found ${model.name} record to modify`);
1710
1787
  logger13.default(`Update properties configured: ${Object.keys(updateProps).join(", ")}`);
1711
1788
  logger13.trace(`[UPDATE] Executing ${model.name}.update() with properties: ${stringifyJSON(updateProps)}`);
@@ -1780,7 +1857,7 @@ var createOperations = (models, coordinate, registry, options) => {
1780
1857
  };
1781
1858
  implOps.findOne = async (finder, params, locations) => {
1782
1859
  const results = await implOps.find(finder, params || {}, locations);
1783
- return results.length > 0 ? results[0] : null;
1860
+ return results.items.length > 0 ? results.items[0] : null;
1784
1861
  };
1785
1862
  return Library2.wrapImplementationOperations(implOps, options);
1786
1863
  };