@fjell/lib-sequelize 4.4.50 → 4.4.52

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.js CHANGED
@@ -376,6 +376,52 @@ var buildQuery = (itemQuery, model) => {
376
376
  return options;
377
377
  };
378
378
 
379
+ // src/validation/LocationKeyValidator.ts
380
+ var logger4 = logger_default.get("LocationKeyValidator");
381
+ var validateLocations = (locations, coordinate, operation) => {
382
+ if (!locations || locations.length === 0) {
383
+ return;
384
+ }
385
+ const keyTypeArray = coordinate.kta;
386
+ const expectedLocationTypes = keyTypeArray.slice(1);
387
+ const actualLocationTypes = locations.map((loc) => loc.kt);
388
+ logger4.debug(`Validating locations for ${operation}`, {
389
+ expected: expectedLocationTypes,
390
+ actual: actualLocationTypes,
391
+ coordinate: keyTypeArray
392
+ });
393
+ if (actualLocationTypes.length > expectedLocationTypes.length) {
394
+ logger4.error("Location key array has too many elements", {
395
+ expected: expectedLocationTypes.length,
396
+ actual: actualLocationTypes.length,
397
+ expectedTypes: expectedLocationTypes,
398
+ actualTypes: actualLocationTypes,
399
+ coordinate,
400
+ operation
401
+ });
402
+ throw new Error(
403
+ `Invalid location key array for ${operation}: Expected at most ${expectedLocationTypes.length} location keys (hierarchy: [${expectedLocationTypes.join(", ")}]), but received ${actualLocationTypes.length} (types: [${actualLocationTypes.join(", ")}])`
404
+ );
405
+ }
406
+ for (let i = 0; i < actualLocationTypes.length; i++) {
407
+ if (expectedLocationTypes[i] !== actualLocationTypes[i]) {
408
+ logger4.error("Location key array order mismatch", {
409
+ position: i,
410
+ expected: expectedLocationTypes[i],
411
+ actual: actualLocationTypes[i],
412
+ expectedHierarchy: expectedLocationTypes,
413
+ actualOrder: actualLocationTypes,
414
+ coordinate,
415
+ operation
416
+ });
417
+ throw new Error(
418
+ `Invalid location key array order for ${operation}: At position ${i}, expected key type "${expectedLocationTypes[i]}" but received "${actualLocationTypes[i]}". Location keys must be ordered according to the hierarchy: [${expectedLocationTypes.join(", ")}]. Received order: [${actualLocationTypes.join(", ")}]`
419
+ );
420
+ }
421
+ }
422
+ logger4.debug(`Location key array validation passed for ${operation}`, { locations });
423
+ };
424
+
379
425
  // src/util/relationshipUtils.ts
380
426
  var buildRelationshipChain = (targetModel, kta, currentIndex, targetIndex) => {
381
427
  const associationParts = [];
@@ -456,9 +502,9 @@ var buildRelationshipPath = (targetModel, locatorType, kta, includeIsDirect = fa
456
502
  };
457
503
 
458
504
  // src/KeyMaster.ts
459
- var logger4 = logger_default.get("sequelize", "KeyMaster");
505
+ var logger5 = logger_default.get("sequelize", "KeyMaster");
460
506
  var extractLocationKeyValue = (model, item, locatorType, kta) => {
461
- logger4.default("Extracting location key value", { locatorType, kta });
507
+ logger5.default("Extracting location key value", { locatorType, kta });
462
508
  const relationshipInfo = buildRelationshipPath(model, locatorType, kta, true);
463
509
  if (!relationshipInfo.found) {
464
510
  throw new Error(`Location key '${locatorType}' cannot be resolved on model '${model.name}' or through its relationships. Key type array: [${kta.join(", ")}]. Available associations: [${Object.keys(model.associations || {}).join(", ")}]`);
@@ -502,12 +548,12 @@ var extractLocationKeyValue = (model, item, locatorType, kta) => {
502
548
  }
503
549
  };
504
550
  var removeKey = (item) => {
505
- logger4.default("Removing Key", { item });
551
+ logger5.default("Removing Key", { item });
506
552
  delete item.key;
507
553
  return item;
508
554
  };
509
555
  var addKey = (model, item, keyTypes) => {
510
- logger4.default("Adding Key", { item });
556
+ logger5.default("Adding Key", { item });
511
557
  const key = {};
512
558
  const modelClass = model.constructor;
513
559
  const primaryKeyAttr = modelClass.primaryKeyAttribute;
@@ -522,7 +568,7 @@ var addKey = (model, item, keyTypes) => {
522
568
  locationKeys.push({ kt: locatorType, lk });
523
569
  } catch (error) {
524
570
  const errorMessage = error instanceof Error ? error.message : String(error);
525
- logger4.error(`Failed to extract location key for '${locatorType}'`, { error: errorMessage, item, keyTypes });
571
+ logger5.error(`Failed to extract location key for '${locatorType}'`, { error: errorMessage, item, keyTypes });
526
572
  throw error;
527
573
  }
528
574
  }
@@ -543,7 +589,7 @@ import {
543
589
 
544
590
  // src/EventCoordinator.ts
545
591
  import deepmerge from "deepmerge";
546
- var logger5 = logger_default.get("sequelize", "EventCoordinator");
592
+ var logger6 = logger_default.get("sequelize", "EventCoordinator");
547
593
  var populateEvents = (item) => {
548
594
  const events = {
549
595
  created: { at: item.createdAt || null },
@@ -554,7 +600,7 @@ var populateEvents = (item) => {
554
600
  return item;
555
601
  };
556
602
  var extractEvents = (item) => {
557
- logger5.default("Extracting Events to database fields", { item });
603
+ logger6.default("Extracting Events to database fields", { item });
558
604
  if (item.events) {
559
605
  if (item.events.created?.at) {
560
606
  item.createdAt = item.events.created.at;
@@ -569,7 +615,7 @@ var extractEvents = (item) => {
569
615
  return item;
570
616
  };
571
617
  var removeEvents = (item) => {
572
- logger5.default("Removing Events", { item });
618
+ logger6.default("Removing Events", { item });
573
619
  delete item.events;
574
620
  return item;
575
621
  };
@@ -654,27 +700,27 @@ var stripSequelizeReferenceItems = (item, referenceDefinitions) => {
654
700
  };
655
701
 
656
702
  // src/RowProcessor.ts
657
- var logger6 = logger_default.get("sequelize", "RowProcessor");
703
+ var logger7 = logger_default.get("sequelize", "RowProcessor");
658
704
  var processRow = async (row, keyTypes, referenceDefinitions, aggregationDefinitions, registry, context) => {
659
- logger6.default("Processing Row", { row });
705
+ logger7.default("Processing Row", { row });
660
706
  const operationContext = context || createOperationContext();
661
707
  return contextManager.withContext(operationContext, async () => {
662
708
  let item = row.get({ plain: true });
663
- logger6.default("Adding Key to Item with Key Types: %s", stringifyJSON(keyTypes));
709
+ logger7.default("Adding Key to Item with Key Types: %s", stringifyJSON(keyTypes));
664
710
  item = addKey(row, item, keyTypes);
665
711
  item = populateEvents(item);
666
- logger6.default("Key Added to Item: %s", stringifyJSON(item.key));
712
+ logger7.default("Key Added to Item: %s", stringifyJSON(item.key));
667
713
  operationContext.markInProgress(item.key);
668
714
  try {
669
715
  if (referenceDefinitions && referenceDefinitions.length > 0) {
670
716
  for (const referenceDefinition of referenceDefinitions) {
671
- logger6.default("Processing Reference for %s to %s", item.key.kt, stringifyJSON(referenceDefinition.kta));
717
+ logger7.default("Processing Reference for %s to %s", item.key.kt, stringifyJSON(referenceDefinition.kta));
672
718
  item = await buildSequelizeReference(item, referenceDefinition, registry, operationContext);
673
719
  }
674
720
  }
675
721
  if (aggregationDefinitions && aggregationDefinitions.length > 0) {
676
722
  for (const aggregationDefinition of aggregationDefinitions) {
677
- logger6.default("Processing Aggregation for %s from %s", item.key.kt, stringifyJSON(aggregationDefinition.kta));
723
+ logger7.default("Processing Aggregation for %s from %s", item.key.kt, stringifyJSON(aggregationDefinition.kta));
678
724
  item = await buildAggregation(item, aggregationDefinition, registry, operationContext);
679
725
  }
680
726
  }
@@ -682,14 +728,14 @@ var processRow = async (row, keyTypes, referenceDefinitions, aggregationDefiniti
682
728
  } finally {
683
729
  operationContext.markComplete(item.key);
684
730
  }
685
- logger6.default("Processed Row: %j", stringifyJSON(item));
731
+ logger7.default("Processed Row: %j", stringifyJSON(item));
686
732
  return item;
687
733
  });
688
734
  };
689
735
 
690
736
  // src/ops/all.ts
691
737
  import { Op as Op2 } from "sequelize";
692
- var logger7 = logger_default.get("sequelize", "ops", "all");
738
+ var logger8 = logger_default.get("sequelize", "ops", "all");
693
739
  var mergeIncludes = (existingIncludes, newIncludes) => {
694
740
  const mergedIncludes = [...existingIncludes];
695
741
  for (const newInclude of newIncludes) {
@@ -712,7 +758,8 @@ var mergeIncludes = (existingIncludes, newIncludes) => {
712
758
  var getAllOperation = (models, definition, registry) => {
713
759
  const { coordinate, options: { references, aggregations } } = definition;
714
760
  const all = async (itemQuery, locations) => {
715
- logger7.debug(`ALL operation called on ${models[0].name} with ${locations?.length || 0} location filters: ${locations?.map((loc2) => `${loc2.kt}=${loc2.lk}`).join(", ") || "none"}`);
761
+ logger8.debug(`ALL operation called on ${models[0].name} with ${locations?.length || 0} location filters: ${locations?.map((loc2) => `${loc2.kt}=${loc2.lk}`).join(", ") || "none"}`);
762
+ validateLocations(locations, coordinate, "all");
716
763
  const loc = locations || [];
717
764
  const model = models[0];
718
765
  const options = buildQuery(itemQuery, model);
@@ -725,7 +772,7 @@ var getAllOperation = (models, definition, registry) => {
725
772
  const relationshipInfo = buildRelationshipPath(model, locKey.kt, kta, true);
726
773
  if (!relationshipInfo.found) {
727
774
  const errorMessage = `Location key '${locKey.kt}' cannot be resolved on model '${model.name}' or through its relationships.`;
728
- logger7.error(errorMessage, { locations: loc, kta });
775
+ logger8.error(errorMessage, { locations: loc, kta });
729
776
  throw new Error(errorMessage);
730
777
  }
731
778
  if (relationshipInfo.isDirect) {
@@ -736,31 +783,31 @@ var getAllOperation = (models, definition, registry) => {
736
783
  }
737
784
  for (const locKey of directLocations) {
738
785
  if (locKey.lk === void 0 || locKey.lk == null || locKey.lk === "" || typeof locKey.lk === "object" && Object.keys(locKey.lk).length === 0) {
739
- logger7.error(`Location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`, { locKey, locations: loc });
786
+ logger8.error(`Location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`, { locKey, locations: loc });
740
787
  throw new Error(`Location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`);
741
788
  }
742
789
  const foreignKeyField = locKey.kt + "Id";
743
790
  if (options.where[foreignKeyField]) {
744
- logger7.debug(`[ALL] Field ${foreignKeyField} already constrained by itemQuery, skipping location constraint to avoid conflicts`);
791
+ logger8.debug(`[ALL] Field ${foreignKeyField} already constrained by itemQuery, skipping location constraint to avoid conflicts`);
745
792
  continue;
746
793
  }
747
- logger7.trace(`[ALL] Setting direct location where clause: ${foreignKeyField} = ${stringifyJSON(locKey.lk)} (type: ${typeof locKey.lk})`);
794
+ logger8.trace(`[ALL] Setting direct location where clause: ${foreignKeyField} = ${stringifyJSON(locKey.lk)} (type: ${typeof locKey.lk})`);
748
795
  options.where[foreignKeyField] = {
749
796
  [Op2.eq]: locKey.lk
750
797
  };
751
798
  }
752
799
  for (const locKey of hierarchicalLocations) {
753
800
  if (locKey.lk === void 0 || locKey.lk == null || locKey.lk === "" || typeof locKey.lk === "object" && Object.keys(locKey.lk).length === 0) {
754
- logger7.error(`Hierarchical location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`, { locKey, locations: loc });
801
+ logger8.error(`Hierarchical location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`, { locKey, locations: loc });
755
802
  throw new Error(`Hierarchical location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`);
756
803
  }
757
804
  const relationshipInfo = buildRelationshipPath(model, locKey.kt, kta);
758
805
  if (relationshipInfo.found && relationshipInfo.path) {
759
806
  if (options.where[relationshipInfo.path]) {
760
- logger7.debug(`[ALL] Field ${relationshipInfo.path} already constrained by itemQuery, skipping hierarchical location constraint to avoid conflicts`);
807
+ logger8.debug(`[ALL] Field ${relationshipInfo.path} already constrained by itemQuery, skipping hierarchical location constraint to avoid conflicts`);
761
808
  continue;
762
809
  }
763
- logger7.trace(`[ALL] Setting hierarchical location where clause: ${relationshipInfo.path} = ${stringifyJSON(locKey.lk)} (type: ${typeof locKey.lk})`);
810
+ logger8.trace(`[ALL] Setting hierarchical location where clause: ${relationshipInfo.path} = ${stringifyJSON(locKey.lk)} (type: ${typeof locKey.lk})`);
764
811
  options.where[relationshipInfo.path] = {
765
812
  [Op2.eq]: locKey.lk
766
813
  };
@@ -774,11 +821,11 @@ var getAllOperation = (models, definition, registry) => {
774
821
  options.include = mergeIncludes(existingIncludes, additionalIncludes);
775
822
  }
776
823
  }
777
- logger7.default(`All query configured for ${model.name} with where fields: ${options.where ? Object.keys(options.where).join(", ") : "none"}, includes: ${options.include?.length || 0}`);
824
+ logger8.default(`All query configured for ${model.name} with where fields: ${options.where ? Object.keys(options.where).join(", ") : "none"}, includes: ${options.include?.length || 0}`);
778
825
  try {
779
- logger7.trace(`[ALL] Executing ${model.name}.findAll() with options: ${JSON.stringify(options, null, 2)}`);
826
+ logger8.trace(`[ALL] Executing ${model.name}.findAll() with options: ${JSON.stringify(options, null, 2)}`);
780
827
  } catch {
781
- logger7.trace(`[ALL] Executing ${model.name}.findAll() with options containing non-serializable operators (${Object.keys(options.where || {}).length} where conditions)`);
828
+ logger8.trace(`[ALL] Executing ${model.name}.findAll() with options containing non-serializable operators (${Object.keys(options.where || {}).length} where conditions)`);
782
829
  }
783
830
  const matchingItems = await model.findAll(options);
784
831
  const currentContext = contextManager.getCurrentContext();
@@ -786,7 +833,7 @@ var getAllOperation = (models, definition, registry) => {
786
833
  const processedRow = await processRow(row, coordinate.kta, references || [], aggregations || [], registry, currentContext);
787
834
  return validateKeys(processedRow, coordinate.kta);
788
835
  }));
789
- logger7.debug(`[ALL] Returning ${results.length} ${model.name} records`);
836
+ logger8.debug(`[ALL] Returning ${results.length} ${model.name} records`);
790
837
  return results;
791
838
  };
792
839
  return all;
@@ -794,13 +841,13 @@ var getAllOperation = (models, definition, registry) => {
794
841
 
795
842
  // src/ops/create.ts
796
843
  import { isComKey as isComKey2, isPriKey as isPriKey2, validateKeys as validateKeys2 } from "@fjell/core";
797
- var logger8 = logger_default.get("sequelize", "ops", "create");
844
+ var logger9 = logger_default.get("sequelize", "ops", "create");
798
845
  function translateDatabaseError(error, itemData, modelName) {
799
846
  const originalMessage = error.message || "";
800
847
  const errorCode = error.original?.code;
801
848
  const constraint = error.original?.constraint;
802
849
  const detail = error.original?.detail;
803
- logger8.error("Database error during create operation", {
850
+ logger9.error("Database error during create operation", {
804
851
  errorCode,
805
852
  constraint,
806
853
  detail,
@@ -894,10 +941,16 @@ async function validateHierarchicalChain(models, locKey, kta) {
894
941
  var getCreateOperation = (models, definition, registry) => {
895
942
  const create = async (item, options) => {
896
943
  const constraints = options?.key ? `key: pk=${options.key.pk}, loc=[${isComKey2(options.key) ? options.key.loc.map((l) => `${l.kt}=${l.lk}`).join(", ") : ""}]` : options?.locations ? `locations: ${options.locations.map((loc) => `${loc.kt}=${loc.lk}`).join(", ")}` : "no constraints";
897
- logger8.debug(`CREATE operation called on ${models[0].name} with ${constraints}`);
898
- logger8.default(`Create configured for ${models[0].name} with ${Object.keys(item).length} item fields`);
944
+ logger9.debug(`CREATE operation called on ${models[0].name} with ${constraints}`);
945
+ logger9.default(`Create configured for ${models[0].name} with ${Object.keys(item).length} item fields`);
899
946
  const { coordinate, options: { references, aggregations } } = definition;
900
947
  const { kta } = coordinate;
948
+ if (options?.locations) {
949
+ validateLocations(options.locations, coordinate, "create");
950
+ }
951
+ if (options?.key && isComKey2(options.key)) {
952
+ validateLocations(options.key.loc, coordinate, "create");
953
+ }
901
954
  const model = models[0];
902
955
  const modelAttributes = model.getAttributes();
903
956
  let itemData = { ...item };
@@ -929,7 +982,7 @@ var getCreateOperation = (models, definition, registry) => {
929
982
  if (!relationshipInfo.found) {
930
983
  const associations = model.associations ? Object.keys(model.associations) : [];
931
984
  const errorMessage = `Composite key locator '${locKey.kt}' cannot be resolved on model '${model.name}' or through its relationships. Available associations: [${associations.join(", ")}]. KTA: [${kta.join(", ")}]. Composite key: ${JSON.stringify(comKey, null, 2)}`;
932
- logger8.error(errorMessage, { key: comKey, kta, associations });
985
+ logger9.error(errorMessage, { key: comKey, kta, associations });
933
986
  throw new Error(errorMessage);
934
987
  }
935
988
  if (relationshipInfo.isDirect) {
@@ -940,7 +993,7 @@ var getCreateOperation = (models, definition, registry) => {
940
993
  }
941
994
  for (const locKey of directLocations) {
942
995
  if (locKey.lk == null || locKey.lk === "") {
943
- logger8.error(`Composite key location '${locKey.kt}' has undefined/null lk value`, { locKey, key: comKey });
996
+ logger9.error(`Composite key location '${locKey.kt}' has undefined/null lk value`, { locKey, key: comKey });
944
997
  throw new Error(`Composite key location '${locKey.kt}' has undefined/null lk value`);
945
998
  }
946
999
  const foreignKeyField = locKey.kt + "Id";
@@ -959,7 +1012,7 @@ var getCreateOperation = (models, definition, registry) => {
959
1012
  if (!relationshipInfo.found) {
960
1013
  const associations = model.associations ? Object.keys(model.associations) : [];
961
1014
  const errorMessage = `Location key '${locKey.kt}' cannot be resolved on model '${model.name}' or through its relationships. Available associations: [${associations.join(", ")}]. KTA: [${kta.join(", ")}]. Locations: ${JSON.stringify(options.locations, null, 2)}`;
962
- logger8.error(errorMessage, { locations: options.locations, kta, associations });
1015
+ logger9.error(errorMessage, { locations: options.locations, kta, associations });
963
1016
  throw new Error(errorMessage);
964
1017
  }
965
1018
  if (relationshipInfo.isDirect) {
@@ -970,7 +1023,7 @@ var getCreateOperation = (models, definition, registry) => {
970
1023
  }
971
1024
  for (const locKey of directLocations) {
972
1025
  if (locKey.lk == null || locKey.lk === "") {
973
- logger8.error(`Location option '${locKey.kt}' has undefined/null lk value`, { locKey, locations: options.locations });
1026
+ logger9.error(`Location option '${locKey.kt}' has undefined/null lk value`, { locKey, locations: options.locations });
974
1027
  throw new Error(`Location option '${locKey.kt}' has undefined/null lk value`);
975
1028
  }
976
1029
  const foreignKeyField = locKey.kt + "Id";
@@ -981,11 +1034,11 @@ var getCreateOperation = (models, definition, registry) => {
981
1034
  }
982
1035
  }
983
1036
  try {
984
- logger8.trace(`[CREATE] Executing ${model.name}.create() with data: ${stringifyJSON(itemData)}`);
1037
+ logger9.trace(`[CREATE] Executing ${model.name}.create() with data: ${stringifyJSON(itemData)}`);
985
1038
  const createdRecord = await model.create(itemData);
986
1039
  const processedRecord = await processRow(createdRecord, kta, references || [], aggregations || [], registry);
987
1040
  const result = validateKeys2(processedRecord, kta);
988
- logger8.debug(`[CREATE] Created ${model.name} with key: ${result.key ? JSON.stringify(result.key) : `id=${createdRecord.id}`}`);
1041
+ logger9.debug(`[CREATE] Created ${model.name} with key: ${result.key ? JSON.stringify(result.key) : `id=${createdRecord.id}`}`);
989
1042
  return result;
990
1043
  } catch (error) {
991
1044
  throw translateDatabaseError(error, itemData, model.name);
@@ -996,37 +1049,38 @@ var getCreateOperation = (models, definition, registry) => {
996
1049
 
997
1050
  // src/ops/find.ts
998
1051
  import { validateKeys as validateKeys3 } from "@fjell/core";
999
- var logger9 = logger_default.get("sequelize", "ops", "find");
1052
+ var logger10 = logger_default.get("sequelize", "ops", "find");
1000
1053
  var getFindOperation = (models, definition, registry) => {
1001
1054
  const { options: { finders, references, aggregations } } = definition;
1002
1055
  const find = async (finder, finderParams, locations) => {
1003
1056
  const locationFilters = locations?.map((loc) => `${loc.kt}=${loc.lk}`).join(", ") || "none";
1004
- logger9.debug(
1057
+ logger10.debug(
1005
1058
  `FIND operation called on ${models[0].name} with finder '${finder}' and ${locations?.length || 0} location filters: ${locationFilters}`
1006
1059
  );
1007
- logger9.default(`Find configured for ${models[0].name} using finder '${finder}' with ${Object.keys(finderParams).length} params`);
1060
+ logger10.default(`Find configured for ${models[0].name} using finder '${finder}' with ${Object.keys(finderParams).length} params`);
1061
+ validateLocations(locations, definition.coordinate, "find");
1008
1062
  if (finders && finders[finder]) {
1009
1063
  const finderMethod = finders[finder];
1010
1064
  if (finderMethod) {
1011
- logger9.trace(`[FIND] Executing finder '${finder}' on ${models[0].name} with params: ${stringifyJSON(finderParams)}, locations: ${stringifyJSON(locations)}`);
1065
+ logger10.trace(`[FIND] Executing finder '${finder}' on ${models[0].name} with params: ${stringifyJSON(finderParams)}, locations: ${stringifyJSON(locations)}`);
1012
1066
  const results = await finderMethod(finderParams, locations);
1013
1067
  if (results && results.length > 0) {
1014
1068
  const processedResults = await Promise.all(results.map(async (row) => {
1015
1069
  const processedRow = await processRow(row, definition.coordinate.kta, references || [], aggregations || [], registry);
1016
1070
  return validateKeys3(processedRow, definition.coordinate.kta);
1017
1071
  }));
1018
- logger9.debug(`[FIND] Found ${processedResults.length} ${models[0].name} records using finder '${finder}'`);
1072
+ logger10.debug(`[FIND] Found ${processedResults.length} ${models[0].name} records using finder '${finder}'`);
1019
1073
  return processedResults;
1020
1074
  } else {
1021
- logger9.debug(`[FIND] Found 0 ${models[0].name} records using finder '${finder}'`);
1075
+ logger10.debug(`[FIND] Found 0 ${models[0].name} records using finder '${finder}'`);
1022
1076
  return [];
1023
1077
  }
1024
1078
  } else {
1025
- logger9.error(`Finder %s not found`, finder);
1079
+ logger10.error(`Finder %s not found`, finder);
1026
1080
  throw new Error(`Finder ${finder} not found`);
1027
1081
  }
1028
1082
  } else {
1029
- logger9.error(`No finders have been defined for this lib`);
1083
+ logger10.error(`No finders have been defined for this lib`);
1030
1084
  throw new Error(`No finders found`);
1031
1085
  }
1032
1086
  };
@@ -1041,7 +1095,7 @@ import {
1041
1095
  validateKeys as validateKeys4
1042
1096
  } from "@fjell/core";
1043
1097
  import { NotFoundError } from "@fjell/lib";
1044
- var logger10 = logger_default.get("sequelize", "ops", "get");
1098
+ var logger11 = logger_default.get("sequelize", "ops", "get");
1045
1099
  var processCompositeKey = (comKey, model, kta) => {
1046
1100
  const where = { id: comKey.pk };
1047
1101
  const includes = [];
@@ -1049,7 +1103,7 @@ var processCompositeKey = (comKey, model, kta) => {
1049
1103
  const relationshipInfo = buildRelationshipPath(model, locator.kt, kta);
1050
1104
  if (!relationshipInfo.found) {
1051
1105
  const errorMessage = `Composite key locator '${locator.kt}' cannot be resolved on model '${model.name}' or through its relationships. Key type array: [${kta.join(", ")}], Composite key: ${stringifyJSON(comKey)}, Available associations: [${Object.keys(model.associations || {}).join(", ")}]`;
1052
- logger10.error(errorMessage, { key: comKey, kta });
1106
+ logger11.error(errorMessage, { key: comKey, kta });
1053
1107
  throw new Error(errorMessage);
1054
1108
  }
1055
1109
  if (relationshipInfo.path) {
@@ -1073,23 +1127,23 @@ var getGetOperation = (models, definition, registry) => {
1073
1127
  const { kta } = coordinate;
1074
1128
  const get = async (key) => {
1075
1129
  if (!isValidItemKey(key)) {
1076
- logger10.error("Key for Get is not a valid ItemKey: %j", key);
1130
+ logger11.error("Key for Get is not a valid ItemKey: %j", key);
1077
1131
  throw new Error("Key for Get is not a valid ItemKey");
1078
1132
  }
1079
1133
  const keyDescription = isPriKey3(key) ? `primary key: pk=${key.pk}` : `composite key: pk=${key.pk}, loc=[${key.loc.map((l) => `${l.kt}=${l.lk}`).join(", ")}]`;
1080
- logger10.debug(`GET operation called on ${models[0].name} with ${keyDescription}`);
1081
- logger10.default(`Get configured for ${models[0].name} with ${isPriKey3(key) ? "primary" : "composite"} key`);
1134
+ logger11.debug(`GET operation called on ${models[0].name} with ${keyDescription}`);
1135
+ logger11.default(`Get configured for ${models[0].name} with ${isPriKey3(key) ? "primary" : "composite"} key`);
1082
1136
  const itemKey = key;
1083
1137
  const model = models[0];
1084
1138
  let item;
1085
1139
  if (isPriKey3(itemKey)) {
1086
- logger10.trace(`[GET] Executing ${model.name}.findByPk() with pk: ${itemKey.pk}`);
1140
+ logger11.trace(`[GET] Executing ${model.name}.findByPk() with pk: ${itemKey.pk}`);
1087
1141
  item = await model.findByPk(itemKey.pk);
1088
1142
  } else if (isComKey3(itemKey)) {
1089
1143
  const comKey = itemKey;
1090
1144
  const queryOptions = processCompositeKey(comKey, model, kta);
1091
- logger10.default("Composite key query", { queryOptions });
1092
- logger10.trace(`[GET] Executing ${model.name}.findOne() with options: ${stringifyJSON(queryOptions)}`);
1145
+ logger11.default("Composite key query", { queryOptions });
1146
+ logger11.trace(`[GET] Executing ${model.name}.findOne() with options: ${stringifyJSON(queryOptions)}`);
1093
1147
  item = await model.findOne(queryOptions);
1094
1148
  }
1095
1149
  if (!item) {
@@ -1097,7 +1151,7 @@ var getGetOperation = (models, definition, registry) => {
1097
1151
  } else {
1098
1152
  const currentContext = contextManager.getCurrentContext();
1099
1153
  const result = validateKeys4(await processRow(item, kta, references || [], aggregations || [], registry, currentContext), kta);
1100
- logger10.debug(`[GET] Retrieved ${model.name} with key: ${result.key ? JSON.stringify(result.key) : `id=${item.id}`}`);
1154
+ logger11.debug(`[GET] Retrieved ${model.name} with key: ${result.key ? JSON.stringify(result.key) : `id=${item.id}`}`);
1101
1155
  return result;
1102
1156
  }
1103
1157
  };
@@ -1105,18 +1159,19 @@ var getGetOperation = (models, definition, registry) => {
1105
1159
  };
1106
1160
 
1107
1161
  // src/ops/one.ts
1108
- var logger11 = logger_default.get("sequelize", "ops", "one");
1162
+ var logger12 = logger_default.get("sequelize", "ops", "one");
1109
1163
  var getOneOperation = (models, definition, registry) => {
1110
1164
  const one = async (itemQuery, locations = []) => {
1111
- logger11.debug(`ONE operation called on ${models[0].name} with ${locations.length} location filters: ${locations.map((loc) => `${loc.kt}=${loc.lk}`).join(", ") || "none"}`);
1112
- logger11.default(`One configured for ${models[0].name} delegating to all operation`);
1165
+ logger12.debug(`ONE operation called on ${models[0].name} with ${locations.length} location filters: ${locations.map((loc) => `${loc.kt}=${loc.lk}`).join(", ") || "none"}`);
1166
+ logger12.default(`One configured for ${models[0].name} delegating to all operation`);
1167
+ validateLocations(locations, definition.coordinate, "one");
1113
1168
  const items = await getAllOperation(models, definition, registry)(itemQuery, locations);
1114
1169
  if (items.length > 0) {
1115
1170
  const result = items[0];
1116
- logger11.debug(`[ONE] Found ${models[0].name} record with key: ${result.key ? JSON.stringify(result.key) : "unknown"}`);
1171
+ logger12.debug(`[ONE] Found ${models[0].name} record with key: ${result.key ? JSON.stringify(result.key) : "unknown"}`);
1117
1172
  return result;
1118
1173
  } else {
1119
- logger11.debug(`[ONE] No ${models[0].name} record found`);
1174
+ logger12.debug(`[ONE] No ${models[0].name} record found`);
1120
1175
  return null;
1121
1176
  }
1122
1177
  };
@@ -1127,7 +1182,7 @@ var getOneOperation = (models, definition, registry) => {
1127
1182
  import { isValidItemKey as isValidItemKey2 } from "@fjell/core";
1128
1183
  import { abbrevIK, isComKey as isComKey4, isPriKey as isPriKey4 } from "@fjell/core";
1129
1184
  import { NotFoundError as NotFoundError2 } from "@fjell/lib";
1130
- var logger12 = logger_default.get("sequelize", "ops", "remove");
1185
+ var logger13 = logger_default.get("sequelize", "ops", "remove");
1131
1186
  var processCompositeKey2 = (comKey, model, kta) => {
1132
1187
  const where = { id: comKey.pk };
1133
1188
  const includes = [];
@@ -1135,7 +1190,7 @@ var processCompositeKey2 = (comKey, model, kta) => {
1135
1190
  const relationshipInfo = buildRelationshipPath(model, locator.kt, kta);
1136
1191
  if (!relationshipInfo.found) {
1137
1192
  const errorMessage = `Composite key locator '${locator.kt}' cannot be resolved on model '${model.name}' or through its relationships.`;
1138
- logger12.error(errorMessage, { key: comKey, kta });
1193
+ logger13.error(errorMessage, { key: comKey, kta });
1139
1194
  throw new Error(errorMessage);
1140
1195
  }
1141
1196
  if (relationshipInfo.path) {
@@ -1159,24 +1214,24 @@ var getRemoveOperation = (models, definition, _registry) => {
1159
1214
  const { kta } = coordinate;
1160
1215
  const remove = async (key) => {
1161
1216
  if (!isValidItemKey2(key)) {
1162
- logger12.error("Key for Remove is not a valid ItemKey: %j", key);
1217
+ logger13.error("Key for Remove is not a valid ItemKey: %j", key);
1163
1218
  throw new Error("Key for Remove is not a valid ItemKey");
1164
1219
  }
1165
1220
  const keyDescription = isPriKey4(key) ? `primary key: pk=${key.pk}` : `composite key: pk=${key.pk}, loc=[${key.loc.map((l) => `${l.kt}=${l.lk}`).join(", ")}]`;
1166
- logger12.debug(`REMOVE operation called on ${models[0].name} with ${keyDescription}`);
1167
- logger12.default(`Remove configured for ${models[0].name} with ${isPriKey4(key) ? "primary" : "composite"} key`);
1221
+ logger13.debug(`REMOVE operation called on ${models[0].name} with ${keyDescription}`);
1222
+ logger13.default(`Remove configured for ${models[0].name} with ${isPriKey4(key) ? "primary" : "composite"} key`);
1168
1223
  const model = models[0];
1169
1224
  let item;
1170
1225
  let returnItem;
1171
- logger12.debug("remove: %s", abbrevIK(key));
1226
+ logger13.debug("remove: %s", abbrevIK(key));
1172
1227
  if (isPriKey4(key)) {
1173
- logger12.debug(`[REMOVE] Executing ${model.name}.findByPk() with pk: ${key.pk}`);
1228
+ logger13.debug(`[REMOVE] Executing ${model.name}.findByPk() with pk: ${key.pk}`);
1174
1229
  item = await model.findByPk(key.pk);
1175
1230
  } else if (isComKey4(key)) {
1176
1231
  const comKey = key;
1177
1232
  const queryOptions = processCompositeKey2(comKey, model, kta);
1178
- logger12.default(`Remove composite key query for ${model.name} with where fields: ${queryOptions.where ? Object.keys(queryOptions.where).join(", ") : "none"}`);
1179
- logger12.debug(`[REMOVE] Executing ${model.name}.findOne() with options: ${stringifyJSON(queryOptions)}`);
1233
+ logger13.default(`Remove composite key query for ${model.name} with where fields: ${queryOptions.where ? Object.keys(queryOptions.where).join(", ") : "none"}`);
1234
+ logger13.debug(`[REMOVE] Executing ${model.name}.findOne() with options: ${stringifyJSON(queryOptions)}`);
1180
1235
  item = await model.findOne(queryOptions);
1181
1236
  }
1182
1237
  if (!item) {
@@ -1191,13 +1246,13 @@ var getRemoveOperation = (models, definition, _registry) => {
1191
1246
  if (model.getAttributes().deletedAt) {
1192
1247
  item.deletedAt = /* @__PURE__ */ new Date();
1193
1248
  }
1194
- logger12.debug(`[REMOVE] Executing ${model.name}.save() for soft delete`);
1249
+ logger13.debug(`[REMOVE] Executing ${model.name}.save() for soft delete`);
1195
1250
  await item?.save();
1196
1251
  returnItem = item?.get({ plain: true });
1197
1252
  returnItem = addKey(item, returnItem, kta);
1198
1253
  returnItem = populateEvents(returnItem);
1199
1254
  } else if (options.deleteOnRemove) {
1200
- logger12.debug(`[REMOVE] Executing ${model.name}.destroy() for hard delete`);
1255
+ logger13.debug(`[REMOVE] Executing ${model.name}.destroy() for hard delete`);
1201
1256
  await item?.destroy();
1202
1257
  returnItem = item?.get({ plain: true });
1203
1258
  returnItem = addKey(item, returnItem, kta);
@@ -1205,7 +1260,7 @@ var getRemoveOperation = (models, definition, _registry) => {
1205
1260
  } else {
1206
1261
  throw new Error("No deletedAt or isDeleted attribute found in model, and deleteOnRemove is not set");
1207
1262
  }
1208
- logger12.debug(`[REMOVE] Removed ${model.name} with key: ${returnItem.key ? JSON.stringify(returnItem.key) : `id=${item.id}`}`);
1263
+ logger13.debug(`[REMOVE] Removed ${model.name} with key: ${returnItem.key ? JSON.stringify(returnItem.key) : `id=${item.id}`}`);
1209
1264
  return returnItem;
1210
1265
  };
1211
1266
  return remove;
@@ -1216,7 +1271,7 @@ import { abbrevIK as abbrevIK2, isComKey as isComKey5, validateKeys as validateK
1216
1271
  import { isPriKey as isPriKey5 } from "@fjell/core";
1217
1272
  import { NotFoundError as NotFoundError3 } from "@fjell/lib";
1218
1273
  import { Op as Op3 } from "sequelize";
1219
- var logger13 = logger_default.get("sequelize", "ops", "update");
1274
+ var logger14 = logger_default.get("sequelize", "ops", "update");
1220
1275
  var mergeIncludes2 = (existingIncludes, newIncludes) => {
1221
1276
  const mergedIncludes = [...existingIncludes];
1222
1277
  for (const newInclude of newIncludes) {
@@ -1240,15 +1295,15 @@ var getUpdateOperation = (models, definition, registry) => {
1240
1295
  const { options: { references, aggregations } } = definition;
1241
1296
  const update = async (key, item) => {
1242
1297
  const keyDescription = isPriKey5(key) ? `primary key: pk=${key.pk}` : `composite key: pk=${key.pk}, loc=[${key.loc.map((l) => `${l.kt}=${l.lk}`).join(", ")}]`;
1243
- logger13.debug(`UPDATE operation called on ${models[0].name} with ${keyDescription}`);
1298
+ logger14.debug(`UPDATE operation called on ${models[0].name} with ${keyDescription}`);
1244
1299
  const { coordinate } = definition;
1245
1300
  const { kta } = coordinate;
1246
- logger13.debug("update: %s, %j", abbrevIK2(key), item);
1301
+ logger14.debug("update: %s, %j", abbrevIK2(key), item);
1247
1302
  const model = models[0];
1248
1303
  let response;
1249
1304
  if (isPriKey5(key)) {
1250
1305
  const priKey = key;
1251
- logger13.trace(`[UPDATE] Executing ${model.name}.findByPk() with pk: ${priKey.pk}`);
1306
+ logger14.trace(`[UPDATE] Executing ${model.name}.findByPk() with pk: ${priKey.pk}`);
1252
1307
  response = await model.findByPk(priKey.pk);
1253
1308
  } else if (isComKey5(key)) {
1254
1309
  const comKey = key;
@@ -1258,7 +1313,7 @@ var getUpdateOperation = (models, definition, registry) => {
1258
1313
  const relationshipInfo = buildRelationshipPath(model, locator.kt, kta, true);
1259
1314
  if (!relationshipInfo.found) {
1260
1315
  const errorMessage = `Composite key locator '${locator.kt}' cannot be resolved on model '${model.name}' or through its relationships.`;
1261
- logger13.error(errorMessage, { key: comKey, kta });
1316
+ logger14.error(errorMessage, { key: comKey, kta });
1262
1317
  throw new Error(errorMessage);
1263
1318
  }
1264
1319
  if (relationshipInfo.isDirect) {
@@ -1277,21 +1332,21 @@ var getUpdateOperation = (models, definition, registry) => {
1277
1332
  if (additionalIncludes.length > 0) {
1278
1333
  queryOptions.include = mergeIncludes2([], additionalIncludes);
1279
1334
  }
1280
- logger13.default(`Update composite key query for ${model.name} with where fields: ${queryOptions.where ? Object.keys(queryOptions.where).join(", ") : "none"}`);
1281
- logger13.trace(`[UPDATE] Executing ${model.name}.findOne() with options: ${stringifyJSON(queryOptions)}`);
1335
+ logger14.default(`Update composite key query for ${model.name} with where fields: ${queryOptions.where ? Object.keys(queryOptions.where).join(", ") : "none"}`);
1336
+ logger14.trace(`[UPDATE] Executing ${model.name}.findOne() with options: ${stringifyJSON(queryOptions)}`);
1282
1337
  response = await model.findOne(queryOptions);
1283
1338
  }
1284
1339
  if (response) {
1285
1340
  let updateProps = removeKey(item);
1286
1341
  updateProps = extractEvents(updateProps);
1287
1342
  updateProps = removeEvents(updateProps);
1288
- logger13.default(`Update found ${model.name} record to modify`);
1289
- logger13.default(`Update properties configured: ${Object.keys(updateProps).join(", ")}`);
1290
- logger13.trace(`[UPDATE] Executing ${model.name}.update() with properties: ${stringifyJSON(updateProps)}`);
1343
+ logger14.default(`Update found ${model.name} record to modify`);
1344
+ logger14.default(`Update properties configured: ${Object.keys(updateProps).join(", ")}`);
1345
+ logger14.trace(`[UPDATE] Executing ${model.name}.update() with properties: ${stringifyJSON(updateProps)}`);
1291
1346
  response = await response.update(updateProps);
1292
1347
  const processedItem = await processRow(response, kta, references || [], aggregations || [], registry);
1293
1348
  const returnItem = validateKeys5(processedItem, kta);
1294
- logger13.debug(`[UPDATE] Updated ${model.name} with key: ${returnItem.key ? JSON.stringify(returnItem.key) : `id=${response.id}`}`);
1349
+ logger14.debug(`[UPDATE] Updated ${model.name} with key: ${returnItem.key ? JSON.stringify(returnItem.key) : `id=${response.id}`}`);
1295
1350
  return returnItem;
1296
1351
  } else {
1297
1352
  throw new NotFoundError3("update", coordinate, key);
@@ -1302,25 +1357,25 @@ var getUpdateOperation = (models, definition, registry) => {
1302
1357
 
1303
1358
  // src/ops/upsert.ts
1304
1359
  import { isValidItemKey as isValidItemKey3 } from "@fjell/core";
1305
- var logger14 = logger_default.get("sequelize", "ops", "upsert");
1360
+ var logger15 = logger_default.get("sequelize", "ops", "upsert");
1306
1361
  var getUpsertOperation = (models, definition, registry) => {
1307
1362
  const get = getGetOperation(models, definition, registry);
1308
1363
  const update = getUpdateOperation(models, definition, registry);
1309
1364
  const create = getCreateOperation(models, definition, registry);
1310
1365
  const upsert = async (key, item) => {
1311
1366
  if (!isValidItemKey3(key)) {
1312
- logger14.error("Key for Upsert is not a valid ItemKey: %j", key);
1367
+ logger15.error("Key for Upsert is not a valid ItemKey: %j", key);
1313
1368
  throw new Error(`Key for Upsert is not a valid ItemKey: ${stringifyJSON(key)}`);
1314
1369
  }
1315
- logger14.debug(`[UPSERT] Attempting upsert with key: ${stringifyJSON(key)}`);
1370
+ logger15.debug(`[UPSERT] Attempting upsert with key: ${stringifyJSON(key)}`);
1316
1371
  try {
1317
1372
  const existingItem = await get(key);
1318
1373
  if (existingItem) {
1319
- logger14.debug(`[UPSERT] Item exists, updating with key: ${stringifyJSON(key)}`);
1374
+ logger15.debug(`[UPSERT] Item exists, updating with key: ${stringifyJSON(key)}`);
1320
1375
  return await update(key, item);
1321
1376
  }
1322
1377
  } catch {
1323
- logger14.debug(`[UPSERT] Item not found, creating new item with key: ${stringifyJSON(key)}`);
1378
+ logger15.debug(`[UPSERT] Item not found, creating new item with key: ${stringifyJSON(key)}`);
1324
1379
  }
1325
1380
  return await create(item, { key });
1326
1381
  };
@@ -1356,9 +1411,9 @@ var createOperations = (models, coordinate, registry, options) => {
1356
1411
  };
1357
1412
 
1358
1413
  // src/SequelizeLibrary.ts
1359
- var logger15 = logger_default.get("SequelizeLibrary");
1414
+ var logger16 = logger_default.get("SequelizeLibrary");
1360
1415
  var createSequelizeLibrary = (registry, coordinate, models, options) => {
1361
- logger15.debug("createSequelizeLibrary", { coordinate, models, registry, options });
1416
+ logger16.debug("createSequelizeLibrary", { coordinate, models, registry, options });
1362
1417
  const operations = createOperations(models, coordinate, registry, options);
1363
1418
  const wrappedOperations = Library2.wrapOperations(operations, options, coordinate, registry);
1364
1419
  const libLibrary = Library2.createLibrary(registry, coordinate, wrappedOperations, options);
@@ -1372,10 +1427,10 @@ var isSequelizeLibrary = (library) => {
1372
1427
  };
1373
1428
 
1374
1429
  // src/SequelizeLibraryFactory.ts
1375
- var logger16 = logger_default.get("InstanceFactory");
1430
+ var logger17 = logger_default.get("InstanceFactory");
1376
1431
  var createSequelizeLibraryFactory = (models, options) => {
1377
1432
  return (coordinate, context) => {
1378
- logger16.debug("Creating Sequelize instance", {
1433
+ logger17.debug("Creating Sequelize instance", {
1379
1434
  coordinate,
1380
1435
  registry: context.registry,
1381
1436
  models: models.map((m) => m.name),
@@ -1420,9 +1475,9 @@ __export(primary_exports, {
1420
1475
 
1421
1476
  // src/primary/SequelizeLibrary.ts
1422
1477
  import { Primary } from "@fjell/lib";
1423
- var logger17 = logger_default.get("lib-sequelize", "primary", "library");
1478
+ var logger18 = logger_default.get("lib-sequelize", "primary", "library");
1424
1479
  function createSequelizeLibrary3(keyType, models, libOptions = {}, scopes = [], registry) {
1425
- logger17.debug("createSequelizeLibrary", { keyType, models, libOptions, scopes });
1480
+ logger18.debug("createSequelizeLibrary", { keyType, models, libOptions, scopes });
1426
1481
  const coordinate = createCoordinate([keyType], scopes);
1427
1482
  const options = createOptions2(libOptions);
1428
1483
  const operations = createOperations(models, coordinate, registry, options);