@fjell/lib-sequelize 4.4.44 → 4.4.46
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/Options.d.ts +43 -16
- package/dist/Options.d.ts.map +1 -1
- package/dist/RowProcessor.d.ts +5 -3
- package/dist/RowProcessor.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +152 -258
- package/dist/index.js.map +4 -4
- package/dist/ops/remove.d.ts +1 -1
- package/dist/ops/remove.d.ts.map +1 -1
- package/dist/processing/ReferenceBuilder.d.ts +37 -0
- package/dist/processing/ReferenceBuilder.d.ts.map +1 -0
- package/dist/processing/index.d.ts +3 -0
- package/dist/processing/index.d.ts.map +1 -0
- package/package.json +3 -3
- package/dist/AggregationBuilder.d.ts +0 -6
- package/dist/AggregationBuilder.d.ts.map +0 -1
- package/dist/OperationContext.d.ts +0 -66
- package/dist/OperationContext.d.ts.map +0 -1
- package/dist/ReferenceBuilder.d.ts +0 -5
- package/dist/ReferenceBuilder.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -6,20 +6,18 @@ var __export = (target, all) => {
|
|
|
6
6
|
|
|
7
7
|
// src/Options.ts
|
|
8
8
|
import * as Library from "@fjell/lib";
|
|
9
|
-
var DEFAULT_SEQUELIZE_OPTIONS = {
|
|
10
|
-
deleteOnRemove: false,
|
|
11
|
-
references: [],
|
|
12
|
-
aggregations: []
|
|
13
|
-
};
|
|
14
9
|
var createOptions2 = (sequelizeOptions) => {
|
|
15
|
-
const
|
|
16
|
-
const
|
|
10
|
+
const { references, deleteOnRemove, ...libCompatibleOptions } = sequelizeOptions || {};
|
|
11
|
+
const baseOptions = Library.createOptions(libCompatibleOptions);
|
|
12
|
+
return {
|
|
17
13
|
...baseOptions,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
aggregations:
|
|
14
|
+
references: references ?? [],
|
|
15
|
+
// Keep Sequelize-specific references
|
|
16
|
+
aggregations: baseOptions.aggregations ?? [],
|
|
17
|
+
// Ensure aggregations is always present
|
|
18
|
+
deleteOnRemove: deleteOnRemove ?? false
|
|
19
|
+
// Sequelize-specific option
|
|
21
20
|
};
|
|
22
|
-
return result;
|
|
23
21
|
};
|
|
24
22
|
|
|
25
23
|
// src/logger.ts
|
|
@@ -508,12 +506,52 @@ var addKey = (model, item, keyTypes) => {
|
|
|
508
506
|
return item;
|
|
509
507
|
};
|
|
510
508
|
|
|
511
|
-
// src/
|
|
512
|
-
|
|
513
|
-
|
|
509
|
+
// src/RowProcessor.ts
|
|
510
|
+
import {
|
|
511
|
+
buildAggregation,
|
|
512
|
+
contextManager,
|
|
513
|
+
createOperationContext
|
|
514
|
+
} from "@fjell/lib";
|
|
515
|
+
|
|
516
|
+
// src/EventCoordinator.ts
|
|
517
|
+
import deepmerge from "deepmerge";
|
|
518
|
+
var logger5 = logger_default.get("sequelize", "EventCoordinator");
|
|
519
|
+
var populateEvents = (item) => {
|
|
520
|
+
const events = {
|
|
521
|
+
created: { at: item.createdAt || null },
|
|
522
|
+
updated: { at: item.updatedAt || null },
|
|
523
|
+
deleted: { at: null }
|
|
524
|
+
};
|
|
525
|
+
item.events = events;
|
|
526
|
+
return item;
|
|
527
|
+
};
|
|
528
|
+
var extractEvents = (item) => {
|
|
529
|
+
logger5.default("Extracting Events to database fields", { item });
|
|
530
|
+
if (item.events) {
|
|
531
|
+
if (item.events.created?.at) {
|
|
532
|
+
item.createdAt = item.events.created.at;
|
|
533
|
+
}
|
|
534
|
+
if (item.events.updated?.at) {
|
|
535
|
+
item.updatedAt = item.events.updated.at;
|
|
536
|
+
}
|
|
537
|
+
if (item.events.deleted?.at) {
|
|
538
|
+
item.deletedAt = item.events.deleted.at;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return item;
|
|
542
|
+
};
|
|
543
|
+
var removeEvents = (item) => {
|
|
544
|
+
logger5.default("Removing Events", { item });
|
|
545
|
+
delete item.events;
|
|
546
|
+
return item;
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
// src/processing/ReferenceBuilder.ts
|
|
550
|
+
var buildSequelizeReference = async (item, referenceDefinition, registry, context) => {
|
|
551
|
+
const libLogger = logger_default.get("processing", "ReferenceBuilder");
|
|
514
552
|
const primaryKeyType = referenceDefinition.kta[0];
|
|
515
553
|
if (referenceDefinition.kta.length > 1) {
|
|
516
|
-
|
|
554
|
+
libLogger.debug(
|
|
517
555
|
"Using multikey reference with PriKey assumption",
|
|
518
556
|
{
|
|
519
557
|
kta: referenceDefinition.kta,
|
|
@@ -522,7 +560,7 @@ var buildReference = async (item, referenceDefinition, registry, context) => {
|
|
|
522
560
|
column: referenceDefinition.column
|
|
523
561
|
}
|
|
524
562
|
);
|
|
525
|
-
|
|
563
|
+
libLogger.debug(
|
|
526
564
|
'ASSUMPTION: The primary key for key type "%s" is unique and can be used to retrieve composite items',
|
|
527
565
|
primaryKeyType
|
|
528
566
|
);
|
|
@@ -550,10 +588,10 @@ var buildReference = async (item, referenceDefinition, registry, context) => {
|
|
|
550
588
|
let referencedItem;
|
|
551
589
|
if (context) {
|
|
552
590
|
if (context.isCached(priKey)) {
|
|
553
|
-
|
|
591
|
+
libLogger.debug("Using cached reference", { priKey, property: referenceDefinition.property });
|
|
554
592
|
referencedItem = context.getCached(priKey);
|
|
555
593
|
} else if (context.isInProgress(priKey)) {
|
|
556
|
-
|
|
594
|
+
libLogger.debug("Circular dependency detected, creating reference placeholder", {
|
|
557
595
|
priKey,
|
|
558
596
|
property: referenceDefinition.property
|
|
559
597
|
});
|
|
@@ -579,182 +617,36 @@ var buildReference = async (item, referenceDefinition, registry, context) => {
|
|
|
579
617
|
item[referenceDefinition.property] = referencedItem;
|
|
580
618
|
return item;
|
|
581
619
|
};
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
// src/OperationContext.ts
|
|
587
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
588
|
-
var logger6 = logger_default.get("sequelize", "OperationContext");
|
|
589
|
-
var serializeKey = (key) => {
|
|
590
|
-
if ("pk" in key && "kt" in key && !("loc" in key)) {
|
|
591
|
-
return `${key.kt}:${key.pk}`;
|
|
592
|
-
} else if ("pk" in key && "kt" in key && "loc" in key) {
|
|
593
|
-
const locStr = key.loc.map((l) => `${l.kt}:${l.lk}`).join(",");
|
|
594
|
-
return `${key.kt}:${key.pk}|${locStr}`;
|
|
595
|
-
}
|
|
596
|
-
throw new Error(`Unsupported key type: ${JSON.stringify(key)}`);
|
|
597
|
-
};
|
|
598
|
-
var createOperationContext = () => {
|
|
599
|
-
const inProgress = /* @__PURE__ */ new Set();
|
|
600
|
-
const cache = /* @__PURE__ */ new Map();
|
|
601
|
-
return {
|
|
602
|
-
inProgress,
|
|
603
|
-
cache,
|
|
604
|
-
markInProgress(key) {
|
|
605
|
-
const serialized = serializeKey(key);
|
|
606
|
-
logger6.default("Marking key as in progress", { key, serialized });
|
|
607
|
-
inProgress.add(serialized);
|
|
608
|
-
},
|
|
609
|
-
markComplete(key) {
|
|
610
|
-
const serialized = serializeKey(key);
|
|
611
|
-
logger6.default("Marking key as complete", { key, serialized });
|
|
612
|
-
inProgress.delete(serialized);
|
|
613
|
-
},
|
|
614
|
-
isInProgress(key) {
|
|
615
|
-
const serialized = serializeKey(key);
|
|
616
|
-
const result = inProgress.has(serialized);
|
|
617
|
-
logger6.default("Checking if key is in progress", { key, serialized, result });
|
|
618
|
-
return result;
|
|
619
|
-
},
|
|
620
|
-
getCached(key) {
|
|
621
|
-
const serialized = serializeKey(key);
|
|
622
|
-
const result = cache.get(serialized);
|
|
623
|
-
logger6.default("Getting cached item", { key, serialized, found: !!result });
|
|
624
|
-
return result;
|
|
625
|
-
},
|
|
626
|
-
setCached(key, item) {
|
|
627
|
-
const serialized = serializeKey(key);
|
|
628
|
-
logger6.default("Caching item", { key, serialized });
|
|
629
|
-
cache.set(serialized, item);
|
|
630
|
-
},
|
|
631
|
-
isCached(key) {
|
|
632
|
-
const serialized = serializeKey(key);
|
|
633
|
-
const result = cache.has(serialized);
|
|
634
|
-
logger6.default("Checking if key is cached", { key, serialized, result });
|
|
635
|
-
return result;
|
|
636
|
-
}
|
|
637
|
-
};
|
|
638
|
-
};
|
|
639
|
-
var ContextManager = class {
|
|
640
|
-
asyncLocalStorage = new AsyncLocalStorage();
|
|
641
|
-
/**
|
|
642
|
-
* Get the current context if one is set
|
|
643
|
-
*/
|
|
644
|
-
getCurrentContext() {
|
|
645
|
-
const context = this.asyncLocalStorage.getStore();
|
|
646
|
-
if (context) {
|
|
647
|
-
logger6.default("Got current context from AsyncLocalStorage");
|
|
648
|
-
}
|
|
649
|
-
return context;
|
|
650
|
-
}
|
|
651
|
-
/**
|
|
652
|
-
* Execute a function with a specific context set as current
|
|
653
|
-
* The context will be available to all async operations within the function
|
|
654
|
-
*/
|
|
655
|
-
async withContext(context, fn) {
|
|
656
|
-
logger6.default("Running with context in AsyncLocalStorage");
|
|
657
|
-
return this.asyncLocalStorage.run(context, fn);
|
|
658
|
-
}
|
|
659
|
-
};
|
|
660
|
-
var contextManager = new ContextManager();
|
|
661
|
-
|
|
662
|
-
// src/AggregationBuilder.ts
|
|
663
|
-
var logger7 = logger_default.get("sequelize", "AggregationBuilder");
|
|
664
|
-
var buildAggregation = async (item, aggregationDefinition, registry, context) => {
|
|
665
|
-
const location = ikToLKA(item.key);
|
|
666
|
-
const libraryInstance = registry.get(aggregationDefinition.kta);
|
|
667
|
-
if (!libraryInstance) {
|
|
668
|
-
throw new Error(`Library instance not found for key type array: ${aggregationDefinition.kta.join(", ")}`);
|
|
669
|
-
}
|
|
670
|
-
const aggregationCacheKey = `${aggregationDefinition.kta.join(".")}_${aggregationDefinition.cardinality}_${serializeKey(item.key)}`;
|
|
671
|
-
if (context) {
|
|
672
|
-
if (context.cache.has(aggregationCacheKey)) {
|
|
673
|
-
const cachedResult = context.cache.get(aggregationCacheKey);
|
|
674
|
-
logger7.default("Using cached aggregation result", {
|
|
675
|
-
aggregationCacheKey,
|
|
676
|
-
property: aggregationDefinition.property
|
|
677
|
-
});
|
|
678
|
-
item[aggregationDefinition.property] = cachedResult;
|
|
679
|
-
return item;
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
return contextManager.withContext(context || contextManager.getCurrentContext() || { inProgress: /* @__PURE__ */ new Set(), cache: /* @__PURE__ */ new Map() }, async () => {
|
|
683
|
-
if (aggregationDefinition.cardinality === "one") {
|
|
684
|
-
return libraryInstance.operations.one({}, location).then((result) => {
|
|
685
|
-
if (context) {
|
|
686
|
-
context.cache.set(aggregationCacheKey, result);
|
|
687
|
-
}
|
|
688
|
-
item[aggregationDefinition.property] = result;
|
|
689
|
-
return item;
|
|
690
|
-
});
|
|
691
|
-
} else {
|
|
692
|
-
return libraryInstance.operations.all({}, location).then((results) => {
|
|
693
|
-
if (context) {
|
|
694
|
-
context.cache.set(aggregationCacheKey, results);
|
|
695
|
-
}
|
|
696
|
-
item[aggregationDefinition.property] = results;
|
|
697
|
-
return item;
|
|
698
|
-
});
|
|
699
|
-
}
|
|
700
|
-
});
|
|
701
|
-
};
|
|
702
|
-
|
|
703
|
-
// src/EventCoordinator.ts
|
|
704
|
-
import deepmerge from "deepmerge";
|
|
705
|
-
var logger8 = logger_default.get("sequelize", "EventCoordinator");
|
|
706
|
-
var populateEvents = (item) => {
|
|
707
|
-
const events = {
|
|
708
|
-
created: { at: item.createdAt || null },
|
|
709
|
-
updated: { at: item.updatedAt || null },
|
|
710
|
-
deleted: { at: null }
|
|
711
|
-
};
|
|
712
|
-
item.events = events;
|
|
713
|
-
return item;
|
|
714
|
-
};
|
|
715
|
-
var extractEvents = (item) => {
|
|
716
|
-
logger8.default("Extracting Events to database fields", { item });
|
|
717
|
-
if (item.events) {
|
|
718
|
-
if (item.events.created?.at) {
|
|
719
|
-
item.createdAt = item.events.created.at;
|
|
720
|
-
}
|
|
721
|
-
if (item.events.updated?.at) {
|
|
722
|
-
item.updatedAt = item.events.updated.at;
|
|
723
|
-
}
|
|
724
|
-
if (item.events.deleted?.at) {
|
|
725
|
-
item.deletedAt = item.events.deleted.at;
|
|
726
|
-
}
|
|
620
|
+
var stripSequelizeReferenceItems = (item, referenceDefinitions) => {
|
|
621
|
+
const result = { ...item };
|
|
622
|
+
for (const refDef of referenceDefinitions) {
|
|
623
|
+
delete result[refDef.property];
|
|
727
624
|
}
|
|
728
|
-
return
|
|
729
|
-
};
|
|
730
|
-
var removeEvents = (item) => {
|
|
731
|
-
logger8.default("Removing Events", { item });
|
|
732
|
-
delete item.events;
|
|
733
|
-
return item;
|
|
625
|
+
return result;
|
|
734
626
|
};
|
|
735
627
|
|
|
736
628
|
// src/RowProcessor.ts
|
|
737
|
-
var
|
|
629
|
+
var logger6 = logger_default.get("sequelize", "RowProcessor");
|
|
738
630
|
var processRow = async (row, keyTypes, referenceDefinitions, aggregationDefinitions, registry, context) => {
|
|
739
|
-
|
|
631
|
+
logger6.default("Processing Row", { row });
|
|
740
632
|
const operationContext = context || createOperationContext();
|
|
741
633
|
return contextManager.withContext(operationContext, async () => {
|
|
742
634
|
let item = row.get({ plain: true });
|
|
743
|
-
|
|
635
|
+
logger6.default("Adding Key to Item with Key Types: %s", stringifyJSON(keyTypes));
|
|
744
636
|
item = addKey(row, item, keyTypes);
|
|
745
637
|
item = populateEvents(item);
|
|
746
|
-
|
|
638
|
+
logger6.default("Key Added to Item: %s", stringifyJSON(item.key));
|
|
747
639
|
operationContext.markInProgress(item.key);
|
|
748
640
|
try {
|
|
749
641
|
if (referenceDefinitions && referenceDefinitions.length > 0) {
|
|
750
642
|
for (const referenceDefinition of referenceDefinitions) {
|
|
751
|
-
|
|
752
|
-
item = await
|
|
643
|
+
logger6.default("Processing Reference for %s to %s", item.key.kt, stringifyJSON(referenceDefinition.kta));
|
|
644
|
+
item = await buildSequelizeReference(item, referenceDefinition, registry, operationContext);
|
|
753
645
|
}
|
|
754
646
|
}
|
|
755
647
|
if (aggregationDefinitions && aggregationDefinitions.length > 0) {
|
|
756
648
|
for (const aggregationDefinition of aggregationDefinitions) {
|
|
757
|
-
|
|
649
|
+
logger6.default("Processing Aggregation for %s from %s", item.key.kt, stringifyJSON(aggregationDefinition.kta));
|
|
758
650
|
item = await buildAggregation(item, aggregationDefinition, registry, operationContext);
|
|
759
651
|
}
|
|
760
652
|
}
|
|
@@ -762,14 +654,14 @@ var processRow = async (row, keyTypes, referenceDefinitions, aggregationDefiniti
|
|
|
762
654
|
} finally {
|
|
763
655
|
operationContext.markComplete(item.key);
|
|
764
656
|
}
|
|
765
|
-
|
|
657
|
+
logger6.default("Processed Row: %j", stringifyJSON(item));
|
|
766
658
|
return item;
|
|
767
659
|
});
|
|
768
660
|
};
|
|
769
661
|
|
|
770
662
|
// src/ops/all.ts
|
|
771
663
|
import { Op as Op2 } from "sequelize";
|
|
772
|
-
var
|
|
664
|
+
var logger7 = logger_default.get("sequelize", "ops", "all");
|
|
773
665
|
var mergeIncludes = (existingIncludes, newIncludes) => {
|
|
774
666
|
const mergedIncludes = [...existingIncludes];
|
|
775
667
|
for (const newInclude of newIncludes) {
|
|
@@ -792,7 +684,7 @@ var mergeIncludes = (existingIncludes, newIncludes) => {
|
|
|
792
684
|
var getAllOperation = (models, definition, registry) => {
|
|
793
685
|
const { coordinate, options: { references, aggregations } } = definition;
|
|
794
686
|
const all = async (itemQuery, locations) => {
|
|
795
|
-
|
|
687
|
+
logger7.debug(`ALL operation called on ${models[0].name} with ${locations?.length || 0} location filters: ${locations?.map((loc2) => `${loc2.kt}=${loc2.lk}`).join(", ") || "none"}`);
|
|
796
688
|
const loc = locations || [];
|
|
797
689
|
const model = models[0];
|
|
798
690
|
const options = buildQuery(itemQuery, model);
|
|
@@ -805,7 +697,7 @@ var getAllOperation = (models, definition, registry) => {
|
|
|
805
697
|
const relationshipInfo = buildRelationshipPath(model, locKey.kt, kta, true);
|
|
806
698
|
if (!relationshipInfo.found) {
|
|
807
699
|
const errorMessage = `Location key '${locKey.kt}' cannot be resolved on model '${model.name}' or through its relationships.`;
|
|
808
|
-
|
|
700
|
+
logger7.error(errorMessage, { locations: loc, kta });
|
|
809
701
|
throw new Error(errorMessage);
|
|
810
702
|
}
|
|
811
703
|
if (relationshipInfo.isDirect) {
|
|
@@ -816,31 +708,31 @@ var getAllOperation = (models, definition, registry) => {
|
|
|
816
708
|
}
|
|
817
709
|
for (const locKey of directLocations) {
|
|
818
710
|
if (locKey.lk === void 0 || locKey.lk == null || locKey.lk === "" || typeof locKey.lk === "object" && Object.keys(locKey.lk).length === 0) {
|
|
819
|
-
|
|
711
|
+
logger7.error(`Location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`, { locKey, locations: loc });
|
|
820
712
|
throw new Error(`Location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`);
|
|
821
713
|
}
|
|
822
714
|
const foreignKeyField = locKey.kt + "Id";
|
|
823
715
|
if (options.where[foreignKeyField]) {
|
|
824
|
-
|
|
716
|
+
logger7.debug(`[ALL] Field ${foreignKeyField} already constrained by itemQuery, skipping location constraint to avoid conflicts`);
|
|
825
717
|
continue;
|
|
826
718
|
}
|
|
827
|
-
|
|
719
|
+
logger7.trace(`[ALL] Setting direct location where clause: ${foreignKeyField} = ${stringifyJSON(locKey.lk)} (type: ${typeof locKey.lk})`);
|
|
828
720
|
options.where[foreignKeyField] = {
|
|
829
721
|
[Op2.eq]: locKey.lk
|
|
830
722
|
};
|
|
831
723
|
}
|
|
832
724
|
for (const locKey of hierarchicalLocations) {
|
|
833
725
|
if (locKey.lk === void 0 || locKey.lk == null || locKey.lk === "" || typeof locKey.lk === "object" && Object.keys(locKey.lk).length === 0) {
|
|
834
|
-
|
|
726
|
+
logger7.error(`Hierarchical location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`, { locKey, locations: loc });
|
|
835
727
|
throw new Error(`Hierarchical location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`);
|
|
836
728
|
}
|
|
837
729
|
const relationshipInfo = buildRelationshipPath(model, locKey.kt, kta);
|
|
838
730
|
if (relationshipInfo.found && relationshipInfo.path) {
|
|
839
731
|
if (options.where[relationshipInfo.path]) {
|
|
840
|
-
|
|
732
|
+
logger7.debug(`[ALL] Field ${relationshipInfo.path} already constrained by itemQuery, skipping hierarchical location constraint to avoid conflicts`);
|
|
841
733
|
continue;
|
|
842
734
|
}
|
|
843
|
-
|
|
735
|
+
logger7.trace(`[ALL] Setting hierarchical location where clause: ${relationshipInfo.path} = ${stringifyJSON(locKey.lk)} (type: ${typeof locKey.lk})`);
|
|
844
736
|
options.where[relationshipInfo.path] = {
|
|
845
737
|
[Op2.eq]: locKey.lk
|
|
846
738
|
};
|
|
@@ -854,11 +746,11 @@ var getAllOperation = (models, definition, registry) => {
|
|
|
854
746
|
options.include = mergeIncludes(existingIncludes, additionalIncludes);
|
|
855
747
|
}
|
|
856
748
|
}
|
|
857
|
-
|
|
749
|
+
logger7.default(`All query configured for ${model.name} with where fields: ${options.where ? Object.keys(options.where).join(", ") : "none"}, includes: ${options.include?.length || 0}`);
|
|
858
750
|
try {
|
|
859
|
-
|
|
751
|
+
logger7.trace(`[ALL] Executing ${model.name}.findAll() with options: ${JSON.stringify(options, null, 2)}`);
|
|
860
752
|
} catch {
|
|
861
|
-
|
|
753
|
+
logger7.trace(`[ALL] Executing ${model.name}.findAll() with options containing non-serializable operators (${Object.keys(options.where || {}).length} where conditions)`);
|
|
862
754
|
}
|
|
863
755
|
const matchingItems = await model.findAll(options);
|
|
864
756
|
const currentContext = contextManager.getCurrentContext();
|
|
@@ -866,7 +758,7 @@ var getAllOperation = (models, definition, registry) => {
|
|
|
866
758
|
const processedRow = await processRow(row, coordinate.kta, references, aggregations, registry, currentContext);
|
|
867
759
|
return validateKeys(processedRow, coordinate.kta);
|
|
868
760
|
}));
|
|
869
|
-
|
|
761
|
+
logger7.debug(`[ALL] Returning ${results.length} ${model.name} records`);
|
|
870
762
|
return results;
|
|
871
763
|
};
|
|
872
764
|
return all;
|
|
@@ -874,13 +766,13 @@ var getAllOperation = (models, definition, registry) => {
|
|
|
874
766
|
|
|
875
767
|
// src/ops/create.ts
|
|
876
768
|
import { isComKey as isComKey2, isPriKey as isPriKey2, validateKeys as validateKeys2 } from "@fjell/core";
|
|
877
|
-
var
|
|
769
|
+
var logger8 = logger_default.get("sequelize", "ops", "create");
|
|
878
770
|
function translateDatabaseError(error, itemData, modelName) {
|
|
879
771
|
const originalMessage = error.message || "";
|
|
880
772
|
const errorCode = error.original?.code;
|
|
881
773
|
const constraint = error.original?.constraint;
|
|
882
774
|
const detail = error.original?.detail;
|
|
883
|
-
|
|
775
|
+
logger8.error("Database error during create operation", {
|
|
884
776
|
errorCode,
|
|
885
777
|
constraint,
|
|
886
778
|
detail,
|
|
@@ -974,8 +866,8 @@ async function validateHierarchicalChain(models, locKey, kta) {
|
|
|
974
866
|
var getCreateOperation = (models, definition, registry) => {
|
|
975
867
|
const create = async (item, options) => {
|
|
976
868
|
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";
|
|
977
|
-
|
|
978
|
-
|
|
869
|
+
logger8.debug(`CREATE operation called on ${models[0].name} with ${constraints}`);
|
|
870
|
+
logger8.default(`Create configured for ${models[0].name} with ${Object.keys(item).length} item fields`);
|
|
979
871
|
const { coordinate, options: { references, aggregations } } = definition;
|
|
980
872
|
const { kta } = coordinate;
|
|
981
873
|
const model = models[0];
|
|
@@ -1009,7 +901,7 @@ var getCreateOperation = (models, definition, registry) => {
|
|
|
1009
901
|
if (!relationshipInfo.found) {
|
|
1010
902
|
const associations = model.associations ? Object.keys(model.associations) : [];
|
|
1011
903
|
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)}`;
|
|
1012
|
-
|
|
904
|
+
logger8.error(errorMessage, { key: comKey, kta, associations });
|
|
1013
905
|
throw new Error(errorMessage);
|
|
1014
906
|
}
|
|
1015
907
|
if (relationshipInfo.isDirect) {
|
|
@@ -1020,7 +912,7 @@ var getCreateOperation = (models, definition, registry) => {
|
|
|
1020
912
|
}
|
|
1021
913
|
for (const locKey of directLocations) {
|
|
1022
914
|
if (locKey.lk == null || locKey.lk === "") {
|
|
1023
|
-
|
|
915
|
+
logger8.error(`Composite key location '${locKey.kt}' has undefined/null lk value`, { locKey, key: comKey });
|
|
1024
916
|
throw new Error(`Composite key location '${locKey.kt}' has undefined/null lk value`);
|
|
1025
917
|
}
|
|
1026
918
|
const foreignKeyField = locKey.kt + "Id";
|
|
@@ -1039,7 +931,7 @@ var getCreateOperation = (models, definition, registry) => {
|
|
|
1039
931
|
if (!relationshipInfo.found) {
|
|
1040
932
|
const associations = model.associations ? Object.keys(model.associations) : [];
|
|
1041
933
|
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)}`;
|
|
1042
|
-
|
|
934
|
+
logger8.error(errorMessage, { locations: options.locations, kta, associations });
|
|
1043
935
|
throw new Error(errorMessage);
|
|
1044
936
|
}
|
|
1045
937
|
if (relationshipInfo.isDirect) {
|
|
@@ -1050,7 +942,7 @@ var getCreateOperation = (models, definition, registry) => {
|
|
|
1050
942
|
}
|
|
1051
943
|
for (const locKey of directLocations) {
|
|
1052
944
|
if (locKey.lk == null || locKey.lk === "") {
|
|
1053
|
-
|
|
945
|
+
logger8.error(`Location option '${locKey.kt}' has undefined/null lk value`, { locKey, locations: options.locations });
|
|
1054
946
|
throw new Error(`Location option '${locKey.kt}' has undefined/null lk value`);
|
|
1055
947
|
}
|
|
1056
948
|
const foreignKeyField = locKey.kt + "Id";
|
|
@@ -1061,11 +953,11 @@ var getCreateOperation = (models, definition, registry) => {
|
|
|
1061
953
|
}
|
|
1062
954
|
}
|
|
1063
955
|
try {
|
|
1064
|
-
|
|
956
|
+
logger8.trace(`[CREATE] Executing ${model.name}.create() with data: ${stringifyJSON(itemData)}`);
|
|
1065
957
|
const createdRecord = await model.create(itemData);
|
|
1066
958
|
const processedRecord = await processRow(createdRecord, kta, references, aggregations, registry);
|
|
1067
959
|
const result = validateKeys2(processedRecord, kta);
|
|
1068
|
-
|
|
960
|
+
logger8.debug(`[CREATE] Created ${model.name} with key: ${result.key ? JSON.stringify(result.key) : `id=${createdRecord.id}`}`);
|
|
1069
961
|
return result;
|
|
1070
962
|
} catch (error) {
|
|
1071
963
|
throw translateDatabaseError(error, itemData, model.name);
|
|
@@ -1076,37 +968,37 @@ var getCreateOperation = (models, definition, registry) => {
|
|
|
1076
968
|
|
|
1077
969
|
// src/ops/find.ts
|
|
1078
970
|
import { validateKeys as validateKeys3 } from "@fjell/core";
|
|
1079
|
-
var
|
|
971
|
+
var logger9 = logger_default.get("sequelize", "ops", "find");
|
|
1080
972
|
var getFindOperation = (models, definition, registry) => {
|
|
1081
973
|
const { options: { finders, references, aggregations } } = definition;
|
|
1082
974
|
const find = async (finder, finderParams, locations) => {
|
|
1083
975
|
const locationFilters = locations?.map((loc) => `${loc.kt}=${loc.lk}`).join(", ") || "none";
|
|
1084
|
-
|
|
976
|
+
logger9.debug(
|
|
1085
977
|
`FIND operation called on ${models[0].name} with finder '${finder}' and ${locations?.length || 0} location filters: ${locationFilters}`
|
|
1086
978
|
);
|
|
1087
|
-
|
|
979
|
+
logger9.default(`Find configured for ${models[0].name} using finder '${finder}' with ${Object.keys(finderParams).length} params`);
|
|
1088
980
|
if (finders && finders[finder]) {
|
|
1089
981
|
const finderMethod = finders[finder];
|
|
1090
982
|
if (finderMethod) {
|
|
1091
|
-
|
|
983
|
+
logger9.trace(`[FIND] Executing finder '${finder}' on ${models[0].name} with params: ${stringifyJSON(finderParams)}, locations: ${stringifyJSON(locations)}`);
|
|
1092
984
|
const results = await finderMethod(finderParams, locations);
|
|
1093
985
|
if (results && results.length > 0) {
|
|
1094
986
|
const processedResults = await Promise.all(results.map(async (row) => {
|
|
1095
987
|
const processedRow = await processRow(row, definition.coordinate.kta, references, aggregations, registry);
|
|
1096
988
|
return validateKeys3(processedRow, definition.coordinate.kta);
|
|
1097
989
|
}));
|
|
1098
|
-
|
|
990
|
+
logger9.debug(`[FIND] Found ${processedResults.length} ${models[0].name} records using finder '${finder}'`);
|
|
1099
991
|
return processedResults;
|
|
1100
992
|
} else {
|
|
1101
|
-
|
|
993
|
+
logger9.debug(`[FIND] Found 0 ${models[0].name} records using finder '${finder}'`);
|
|
1102
994
|
return [];
|
|
1103
995
|
}
|
|
1104
996
|
} else {
|
|
1105
|
-
|
|
997
|
+
logger9.error(`Finder %s not found`, finder);
|
|
1106
998
|
throw new Error(`Finder ${finder} not found`);
|
|
1107
999
|
}
|
|
1108
1000
|
} else {
|
|
1109
|
-
|
|
1001
|
+
logger9.error(`No finders have been defined for this lib`);
|
|
1110
1002
|
throw new Error(`No finders found`);
|
|
1111
1003
|
}
|
|
1112
1004
|
};
|
|
@@ -1121,7 +1013,7 @@ import {
|
|
|
1121
1013
|
validateKeys as validateKeys4
|
|
1122
1014
|
} from "@fjell/core";
|
|
1123
1015
|
import { NotFoundError } from "@fjell/lib";
|
|
1124
|
-
var
|
|
1016
|
+
var logger10 = logger_default.get("sequelize", "ops", "get");
|
|
1125
1017
|
var processCompositeKey = (comKey, model, kta) => {
|
|
1126
1018
|
const where = { id: comKey.pk };
|
|
1127
1019
|
const includes = [];
|
|
@@ -1129,7 +1021,7 @@ var processCompositeKey = (comKey, model, kta) => {
|
|
|
1129
1021
|
const relationshipInfo = buildRelationshipPath(model, locator.kt, kta);
|
|
1130
1022
|
if (!relationshipInfo.found) {
|
|
1131
1023
|
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(", ")}]`;
|
|
1132
|
-
|
|
1024
|
+
logger10.error(errorMessage, { key: comKey, kta });
|
|
1133
1025
|
throw new Error(errorMessage);
|
|
1134
1026
|
}
|
|
1135
1027
|
if (relationshipInfo.path) {
|
|
@@ -1153,23 +1045,23 @@ var getGetOperation = (models, definition, registry) => {
|
|
|
1153
1045
|
const { kta } = coordinate;
|
|
1154
1046
|
const get = async (key) => {
|
|
1155
1047
|
if (!isValidItemKey(key)) {
|
|
1156
|
-
|
|
1048
|
+
logger10.error("Key for Get is not a valid ItemKey: %j", key);
|
|
1157
1049
|
throw new Error("Key for Get is not a valid ItemKey");
|
|
1158
1050
|
}
|
|
1159
1051
|
const keyDescription = isPriKey3(key) ? `primary key: pk=${key.pk}` : `composite key: pk=${key.pk}, loc=[${key.loc.map((l) => `${l.kt}=${l.lk}`).join(", ")}]`;
|
|
1160
|
-
|
|
1161
|
-
|
|
1052
|
+
logger10.debug(`GET operation called on ${models[0].name} with ${keyDescription}`);
|
|
1053
|
+
logger10.default(`Get configured for ${models[0].name} with ${isPriKey3(key) ? "primary" : "composite"} key`);
|
|
1162
1054
|
const itemKey = key;
|
|
1163
1055
|
const model = models[0];
|
|
1164
1056
|
let item;
|
|
1165
1057
|
if (isPriKey3(itemKey)) {
|
|
1166
|
-
|
|
1058
|
+
logger10.trace(`[GET] Executing ${model.name}.findByPk() with pk: ${itemKey.pk}`);
|
|
1167
1059
|
item = await model.findByPk(itemKey.pk);
|
|
1168
1060
|
} else if (isComKey3(itemKey)) {
|
|
1169
1061
|
const comKey = itemKey;
|
|
1170
1062
|
const queryOptions = processCompositeKey(comKey, model, kta);
|
|
1171
|
-
|
|
1172
|
-
|
|
1063
|
+
logger10.default("Composite key query", { queryOptions });
|
|
1064
|
+
logger10.trace(`[GET] Executing ${model.name}.findOne() with options: ${stringifyJSON(queryOptions)}`);
|
|
1173
1065
|
item = await model.findOne(queryOptions);
|
|
1174
1066
|
}
|
|
1175
1067
|
if (!item) {
|
|
@@ -1177,7 +1069,7 @@ var getGetOperation = (models, definition, registry) => {
|
|
|
1177
1069
|
} else {
|
|
1178
1070
|
const currentContext = contextManager.getCurrentContext();
|
|
1179
1071
|
const result = validateKeys4(await processRow(item, kta, references, aggregations, registry, currentContext), kta);
|
|
1180
|
-
|
|
1072
|
+
logger10.debug(`[GET] Retrieved ${model.name} with key: ${result.key ? JSON.stringify(result.key) : `id=${item.id}`}`);
|
|
1181
1073
|
return result;
|
|
1182
1074
|
}
|
|
1183
1075
|
};
|
|
@@ -1185,18 +1077,18 @@ var getGetOperation = (models, definition, registry) => {
|
|
|
1185
1077
|
};
|
|
1186
1078
|
|
|
1187
1079
|
// src/ops/one.ts
|
|
1188
|
-
var
|
|
1080
|
+
var logger11 = logger_default.get("sequelize", "ops", "one");
|
|
1189
1081
|
var getOneOperation = (models, definition, registry) => {
|
|
1190
1082
|
const one = async (itemQuery, locations = []) => {
|
|
1191
|
-
|
|
1192
|
-
|
|
1083
|
+
logger11.debug(`ONE operation called on ${models[0].name} with ${locations.length} location filters: ${locations.map((loc) => `${loc.kt}=${loc.lk}`).join(", ") || "none"}`);
|
|
1084
|
+
logger11.default(`One configured for ${models[0].name} delegating to all operation`);
|
|
1193
1085
|
const items = await getAllOperation(models, definition, registry)(itemQuery, locations);
|
|
1194
1086
|
if (items.length > 0) {
|
|
1195
1087
|
const result = items[0];
|
|
1196
|
-
|
|
1088
|
+
logger11.debug(`[ONE] Found ${models[0].name} record with key: ${result.key ? JSON.stringify(result.key) : "unknown"}`);
|
|
1197
1089
|
return result;
|
|
1198
1090
|
} else {
|
|
1199
|
-
|
|
1091
|
+
logger11.debug(`[ONE] No ${models[0].name} record found`);
|
|
1200
1092
|
return null;
|
|
1201
1093
|
}
|
|
1202
1094
|
};
|
|
@@ -1207,7 +1099,7 @@ var getOneOperation = (models, definition, registry) => {
|
|
|
1207
1099
|
import { isValidItemKey as isValidItemKey2 } from "@fjell/core";
|
|
1208
1100
|
import { abbrevIK, isComKey as isComKey4, isPriKey as isPriKey4 } from "@fjell/core";
|
|
1209
1101
|
import { NotFoundError as NotFoundError2 } from "@fjell/lib";
|
|
1210
|
-
var
|
|
1102
|
+
var logger12 = logger_default.get("sequelize", "ops", "remove");
|
|
1211
1103
|
var processCompositeKey2 = (comKey, model, kta) => {
|
|
1212
1104
|
const where = { id: comKey.pk };
|
|
1213
1105
|
const includes = [];
|
|
@@ -1215,7 +1107,7 @@ var processCompositeKey2 = (comKey, model, kta) => {
|
|
|
1215
1107
|
const relationshipInfo = buildRelationshipPath(model, locator.kt, kta);
|
|
1216
1108
|
if (!relationshipInfo.found) {
|
|
1217
1109
|
const errorMessage = `Composite key locator '${locator.kt}' cannot be resolved on model '${model.name}' or through its relationships.`;
|
|
1218
|
-
|
|
1110
|
+
logger12.error(errorMessage, { key: comKey, kta });
|
|
1219
1111
|
throw new Error(errorMessage);
|
|
1220
1112
|
}
|
|
1221
1113
|
if (relationshipInfo.path) {
|
|
@@ -1234,29 +1126,29 @@ var processCompositeKey2 = (comKey, model, kta) => {
|
|
|
1234
1126
|
}
|
|
1235
1127
|
return result;
|
|
1236
1128
|
};
|
|
1237
|
-
var getRemoveOperation = (models, definition,
|
|
1129
|
+
var getRemoveOperation = (models, definition, _registry) => {
|
|
1238
1130
|
const { coordinate, options } = definition;
|
|
1239
1131
|
const { kta } = coordinate;
|
|
1240
1132
|
const remove = async (key) => {
|
|
1241
1133
|
if (!isValidItemKey2(key)) {
|
|
1242
|
-
|
|
1134
|
+
logger12.error("Key for Remove is not a valid ItemKey: %j", key);
|
|
1243
1135
|
throw new Error("Key for Remove is not a valid ItemKey");
|
|
1244
1136
|
}
|
|
1245
1137
|
const keyDescription = isPriKey4(key) ? `primary key: pk=${key.pk}` : `composite key: pk=${key.pk}, loc=[${key.loc.map((l) => `${l.kt}=${l.lk}`).join(", ")}]`;
|
|
1246
|
-
|
|
1247
|
-
|
|
1138
|
+
logger12.debug(`REMOVE operation called on ${models[0].name} with ${keyDescription}`);
|
|
1139
|
+
logger12.default(`Remove configured for ${models[0].name} with ${isPriKey4(key) ? "primary" : "composite"} key`);
|
|
1248
1140
|
const model = models[0];
|
|
1249
1141
|
let item;
|
|
1250
1142
|
let returnItem;
|
|
1251
|
-
|
|
1143
|
+
logger12.debug("remove: %s", abbrevIK(key));
|
|
1252
1144
|
if (isPriKey4(key)) {
|
|
1253
|
-
|
|
1145
|
+
logger12.debug(`[REMOVE] Executing ${model.name}.findByPk() with pk: ${key.pk}`);
|
|
1254
1146
|
item = await model.findByPk(key.pk);
|
|
1255
1147
|
} else if (isComKey4(key)) {
|
|
1256
1148
|
const comKey = key;
|
|
1257
1149
|
const queryOptions = processCompositeKey2(comKey, model, kta);
|
|
1258
|
-
|
|
1259
|
-
|
|
1150
|
+
logger12.default(`Remove composite key query for ${model.name} with where fields: ${queryOptions.where ? Object.keys(queryOptions.where).join(", ") : "none"}`);
|
|
1151
|
+
logger12.debug(`[REMOVE] Executing ${model.name}.findOne() with options: ${stringifyJSON(queryOptions)}`);
|
|
1260
1152
|
item = await model.findOne(queryOptions);
|
|
1261
1153
|
}
|
|
1262
1154
|
if (!item) {
|
|
@@ -1271,13 +1163,13 @@ var getRemoveOperation = (models, definition, registry) => {
|
|
|
1271
1163
|
if (model.getAttributes().deletedAt) {
|
|
1272
1164
|
item.deletedAt = /* @__PURE__ */ new Date();
|
|
1273
1165
|
}
|
|
1274
|
-
|
|
1166
|
+
logger12.debug(`[REMOVE] Executing ${model.name}.save() for soft delete`);
|
|
1275
1167
|
await item?.save();
|
|
1276
1168
|
returnItem = item?.get({ plain: true });
|
|
1277
1169
|
returnItem = addKey(item, returnItem, kta);
|
|
1278
1170
|
returnItem = populateEvents(returnItem);
|
|
1279
1171
|
} else if (options.deleteOnRemove) {
|
|
1280
|
-
|
|
1172
|
+
logger12.debug(`[REMOVE] Executing ${model.name}.destroy() for hard delete`);
|
|
1281
1173
|
await item?.destroy();
|
|
1282
1174
|
returnItem = item?.get({ plain: true });
|
|
1283
1175
|
returnItem = addKey(item, returnItem, kta);
|
|
@@ -1285,7 +1177,7 @@ var getRemoveOperation = (models, definition, registry) => {
|
|
|
1285
1177
|
} else {
|
|
1286
1178
|
throw new Error("No deletedAt or isDeleted attribute found in model, and deleteOnRemove is not set");
|
|
1287
1179
|
}
|
|
1288
|
-
|
|
1180
|
+
logger12.debug(`[REMOVE] Removed ${model.name} with key: ${returnItem.key ? JSON.stringify(returnItem.key) : `id=${item.id}`}`);
|
|
1289
1181
|
return returnItem;
|
|
1290
1182
|
};
|
|
1291
1183
|
return remove;
|
|
@@ -1296,7 +1188,7 @@ import { abbrevIK as abbrevIK2, isComKey as isComKey5, validateKeys as validateK
|
|
|
1296
1188
|
import { isPriKey as isPriKey5 } from "@fjell/core";
|
|
1297
1189
|
import { NotFoundError as NotFoundError3 } from "@fjell/lib";
|
|
1298
1190
|
import { Op as Op3 } from "sequelize";
|
|
1299
|
-
var
|
|
1191
|
+
var logger13 = logger_default.get("sequelize", "ops", "update");
|
|
1300
1192
|
var mergeIncludes2 = (existingIncludes, newIncludes) => {
|
|
1301
1193
|
const mergedIncludes = [...existingIncludes];
|
|
1302
1194
|
for (const newInclude of newIncludes) {
|
|
@@ -1320,15 +1212,15 @@ var getUpdateOperation = (models, definition, registry) => {
|
|
|
1320
1212
|
const { options: { references, aggregations } } = definition;
|
|
1321
1213
|
const update = async (key, item) => {
|
|
1322
1214
|
const keyDescription = isPriKey5(key) ? `primary key: pk=${key.pk}` : `composite key: pk=${key.pk}, loc=[${key.loc.map((l) => `${l.kt}=${l.lk}`).join(", ")}]`;
|
|
1323
|
-
|
|
1215
|
+
logger13.debug(`UPDATE operation called on ${models[0].name} with ${keyDescription}`);
|
|
1324
1216
|
const { coordinate } = definition;
|
|
1325
1217
|
const { kta } = coordinate;
|
|
1326
|
-
|
|
1218
|
+
logger13.debug("update: %s, %j", abbrevIK2(key), item);
|
|
1327
1219
|
const model = models[0];
|
|
1328
1220
|
let response;
|
|
1329
1221
|
if (isPriKey5(key)) {
|
|
1330
1222
|
const priKey = key;
|
|
1331
|
-
|
|
1223
|
+
logger13.trace(`[UPDATE] Executing ${model.name}.findByPk() with pk: ${priKey.pk}`);
|
|
1332
1224
|
response = await model.findByPk(priKey.pk);
|
|
1333
1225
|
} else if (isComKey5(key)) {
|
|
1334
1226
|
const comKey = key;
|
|
@@ -1338,7 +1230,7 @@ var getUpdateOperation = (models, definition, registry) => {
|
|
|
1338
1230
|
const relationshipInfo = buildRelationshipPath(model, locator.kt, kta, true);
|
|
1339
1231
|
if (!relationshipInfo.found) {
|
|
1340
1232
|
const errorMessage = `Composite key locator '${locator.kt}' cannot be resolved on model '${model.name}' or through its relationships.`;
|
|
1341
|
-
|
|
1233
|
+
logger13.error(errorMessage, { key: comKey, kta });
|
|
1342
1234
|
throw new Error(errorMessage);
|
|
1343
1235
|
}
|
|
1344
1236
|
if (relationshipInfo.isDirect) {
|
|
@@ -1357,21 +1249,21 @@ var getUpdateOperation = (models, definition, registry) => {
|
|
|
1357
1249
|
if (additionalIncludes.length > 0) {
|
|
1358
1250
|
queryOptions.include = mergeIncludes2([], additionalIncludes);
|
|
1359
1251
|
}
|
|
1360
|
-
|
|
1361
|
-
|
|
1252
|
+
logger13.default(`Update composite key query for ${model.name} with where fields: ${queryOptions.where ? Object.keys(queryOptions.where).join(", ") : "none"}`);
|
|
1253
|
+
logger13.trace(`[UPDATE] Executing ${model.name}.findOne() with options: ${stringifyJSON(queryOptions)}`);
|
|
1362
1254
|
response = await model.findOne(queryOptions);
|
|
1363
1255
|
}
|
|
1364
1256
|
if (response) {
|
|
1365
1257
|
let updateProps = removeKey(item);
|
|
1366
1258
|
updateProps = extractEvents(updateProps);
|
|
1367
1259
|
updateProps = removeEvents(updateProps);
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1260
|
+
logger13.default(`Update found ${model.name} record to modify`);
|
|
1261
|
+
logger13.default(`Update properties configured: ${Object.keys(updateProps).join(", ")}`);
|
|
1262
|
+
logger13.trace(`[UPDATE] Executing ${model.name}.update() with properties: ${stringifyJSON(updateProps)}`);
|
|
1371
1263
|
response = await response.update(updateProps);
|
|
1372
1264
|
const processedItem = await processRow(response, kta, references, aggregations, registry);
|
|
1373
1265
|
const returnItem = validateKeys5(processedItem, kta);
|
|
1374
|
-
|
|
1266
|
+
logger13.debug(`[UPDATE] Updated ${model.name} with key: ${returnItem.key ? JSON.stringify(returnItem.key) : `id=${response.id}`}`);
|
|
1375
1267
|
return returnItem;
|
|
1376
1268
|
} else {
|
|
1377
1269
|
throw new NotFoundError3("update", coordinate, key);
|
|
@@ -1382,25 +1274,25 @@ var getUpdateOperation = (models, definition, registry) => {
|
|
|
1382
1274
|
|
|
1383
1275
|
// src/ops/upsert.ts
|
|
1384
1276
|
import { isValidItemKey as isValidItemKey3 } from "@fjell/core";
|
|
1385
|
-
var
|
|
1277
|
+
var logger14 = logger_default.get("sequelize", "ops", "upsert");
|
|
1386
1278
|
var getUpsertOperation = (models, definition, registry) => {
|
|
1387
1279
|
const get = getGetOperation(models, definition, registry);
|
|
1388
1280
|
const update = getUpdateOperation(models, definition, registry);
|
|
1389
1281
|
const create = getCreateOperation(models, definition, registry);
|
|
1390
1282
|
const upsert = async (key, item) => {
|
|
1391
1283
|
if (!isValidItemKey3(key)) {
|
|
1392
|
-
|
|
1284
|
+
logger14.error("Key for Upsert is not a valid ItemKey: %j", key);
|
|
1393
1285
|
throw new Error(`Key for Upsert is not a valid ItemKey: ${stringifyJSON(key)}`);
|
|
1394
1286
|
}
|
|
1395
|
-
|
|
1287
|
+
logger14.debug(`[UPSERT] Attempting upsert with key: ${stringifyJSON(key)}`);
|
|
1396
1288
|
try {
|
|
1397
1289
|
const existingItem = await get(key);
|
|
1398
1290
|
if (existingItem) {
|
|
1399
|
-
|
|
1291
|
+
logger14.debug(`[UPSERT] Item exists, updating with key: ${stringifyJSON(key)}`);
|
|
1400
1292
|
return await update(key, item);
|
|
1401
1293
|
}
|
|
1402
1294
|
} catch {
|
|
1403
|
-
|
|
1295
|
+
logger14.debug(`[UPSERT] Item not found, creating new item with key: ${stringifyJSON(key)}`);
|
|
1404
1296
|
}
|
|
1405
1297
|
return await create(item, { key });
|
|
1406
1298
|
};
|
|
@@ -1436,9 +1328,9 @@ var createOperations = (models, coordinate, registry, options) => {
|
|
|
1436
1328
|
};
|
|
1437
1329
|
|
|
1438
1330
|
// src/SequelizeLibrary.ts
|
|
1439
|
-
var
|
|
1331
|
+
var logger15 = logger_default.get("SequelizeLibrary");
|
|
1440
1332
|
var createSequelizeLibrary = (registry, coordinate, models, options) => {
|
|
1441
|
-
|
|
1333
|
+
logger15.debug("createSequelizeLibrary", { coordinate, models, registry, options });
|
|
1442
1334
|
const operations = createOperations(models, coordinate, registry, options);
|
|
1443
1335
|
const wrappedOperations = Library2.wrapOperations(operations, options, coordinate, registry);
|
|
1444
1336
|
const libLibrary = Library2.createLibrary(registry, coordinate, wrappedOperations, options);
|
|
@@ -1452,10 +1344,10 @@ var isSequelizeLibrary = (library) => {
|
|
|
1452
1344
|
};
|
|
1453
1345
|
|
|
1454
1346
|
// src/SequelizeLibraryFactory.ts
|
|
1455
|
-
var
|
|
1347
|
+
var logger16 = logger_default.get("InstanceFactory");
|
|
1456
1348
|
var createSequelizeLibraryFactory = (models, options) => {
|
|
1457
1349
|
return (coordinate, context) => {
|
|
1458
|
-
|
|
1350
|
+
logger16.debug("Creating Sequelize instance", {
|
|
1459
1351
|
coordinate,
|
|
1460
1352
|
registry: context.registry,
|
|
1461
1353
|
models: models.map((m) => m.name),
|
|
@@ -1500,9 +1392,9 @@ __export(primary_exports, {
|
|
|
1500
1392
|
|
|
1501
1393
|
// src/primary/SequelizeLibrary.ts
|
|
1502
1394
|
import { Primary } from "@fjell/lib";
|
|
1503
|
-
var
|
|
1395
|
+
var logger17 = logger_default.get("lib-sequelize", "primary", "library");
|
|
1504
1396
|
function createSequelizeLibrary3(keyType, models, libOptions = {}, scopes = [], registry) {
|
|
1505
|
-
|
|
1397
|
+
logger17.debug("createSequelizeLibrary", { keyType, models, libOptions, scopes });
|
|
1506
1398
|
const coordinate = createCoordinate([keyType], scopes);
|
|
1507
1399
|
const options = createOptions2(libOptions);
|
|
1508
1400
|
const operations = createOperations(models, coordinate, registry, options);
|
|
@@ -1519,12 +1411,14 @@ export {
|
|
|
1519
1411
|
contained_exports as Contained,
|
|
1520
1412
|
primary_exports as Primary,
|
|
1521
1413
|
SCOPE_SEQUELIZE,
|
|
1414
|
+
buildSequelizeReference,
|
|
1522
1415
|
createCoordinate,
|
|
1523
1416
|
createDefinition,
|
|
1524
1417
|
createOperations,
|
|
1525
1418
|
createOptions2 as createOptions,
|
|
1526
1419
|
createSequelizeLibrary,
|
|
1527
1420
|
createSequelizeLibraryFactory,
|
|
1528
|
-
isSequelizeLibrary
|
|
1421
|
+
isSequelizeLibrary,
|
|
1422
|
+
stripSequelizeReferenceItems
|
|
1529
1423
|
};
|
|
1530
1424
|
//# sourceMappingURL=index.js.map
|