@fjell/lib-sequelize 4.4.43 → 4.4.45
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 +2 -13
- package/dist/Options.d.ts.map +1 -1
- package/dist/RowProcessor.d.ts +3 -1
- package/dist/RowProcessor.d.ts.map +1 -1
- package/dist/index.js +100 -289
- 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/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,18 +6,13 @@ 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
10
|
const baseOptions = Library.createOptions(sequelizeOptions);
|
|
16
11
|
const result = {
|
|
17
12
|
...baseOptions,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
references: baseOptions.references ?? [],
|
|
14
|
+
aggregations: baseOptions.aggregations ?? [],
|
|
15
|
+
deleteOnRemove: sequelizeOptions?.deleteOnRemove ?? false
|
|
21
16
|
};
|
|
22
17
|
return result;
|
|
23
18
|
};
|
|
@@ -508,201 +503,17 @@ var addKey = (model, item, keyTypes) => {
|
|
|
508
503
|
return item;
|
|
509
504
|
};
|
|
510
505
|
|
|
511
|
-
// src/
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
{
|
|
519
|
-
kta: referenceDefinition.kta,
|
|
520
|
-
primaryKeyType,
|
|
521
|
-
property: referenceDefinition.property,
|
|
522
|
-
column: referenceDefinition.column
|
|
523
|
-
}
|
|
524
|
-
);
|
|
525
|
-
logger5.default(
|
|
526
|
-
'ASSUMPTION: The primary key for key type "%s" is unique and can be used to retrieve composite items',
|
|
527
|
-
primaryKeyType
|
|
528
|
-
);
|
|
529
|
-
}
|
|
530
|
-
if (!registry) {
|
|
531
|
-
throw new Error(
|
|
532
|
-
`This model definition has a reference definition, but the registry is not present. Reference property: '${referenceDefinition.property}', key types: [${referenceDefinition.kta.join(", ")}], column: '${referenceDefinition.column}'`
|
|
533
|
-
);
|
|
534
|
-
}
|
|
535
|
-
const library = registry.get(referenceDefinition.kta);
|
|
536
|
-
if (!library) {
|
|
537
|
-
throw new Error(
|
|
538
|
-
`This model definition has a reference definition, but the dependency is not present in registry. Reference property: '${referenceDefinition.property}', missing key type: '${primaryKeyType}', column: '${referenceDefinition.column}'`
|
|
539
|
-
);
|
|
540
|
-
}
|
|
541
|
-
const columnValue = item[referenceDefinition.column];
|
|
542
|
-
if (columnValue == null) {
|
|
543
|
-
item[referenceDefinition.property] = null;
|
|
544
|
-
return item;
|
|
545
|
-
}
|
|
546
|
-
const priKey = {
|
|
547
|
-
kt: primaryKeyType,
|
|
548
|
-
pk: columnValue
|
|
549
|
-
};
|
|
550
|
-
let referencedItem;
|
|
551
|
-
if (context) {
|
|
552
|
-
if (context.isCached(priKey)) {
|
|
553
|
-
logger5.default("Using cached reference", { priKey, property: referenceDefinition.property });
|
|
554
|
-
referencedItem = context.getCached(priKey);
|
|
555
|
-
} else if (context.isInProgress(priKey)) {
|
|
556
|
-
logger5.default("Circular dependency detected, creating reference placeholder", {
|
|
557
|
-
priKey,
|
|
558
|
-
property: referenceDefinition.property
|
|
559
|
-
});
|
|
560
|
-
referencedItem = {
|
|
561
|
-
key: priKey
|
|
562
|
-
// Add any other minimal properties that might be needed
|
|
563
|
-
// This prevents infinite loops while still providing the key for identification
|
|
564
|
-
};
|
|
565
|
-
} else {
|
|
566
|
-
context.markInProgress(priKey);
|
|
567
|
-
try {
|
|
568
|
-
referencedItem = await library.operations.get(priKey);
|
|
569
|
-
context.setCached(priKey, referencedItem);
|
|
570
|
-
} catch (error) {
|
|
571
|
-
throw error;
|
|
572
|
-
} finally {
|
|
573
|
-
context.markComplete(priKey);
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
} else {
|
|
577
|
-
referencedItem = await library.operations.get(priKey);
|
|
578
|
-
}
|
|
579
|
-
item[referenceDefinition.property] = referencedItem;
|
|
580
|
-
return item;
|
|
581
|
-
};
|
|
582
|
-
|
|
583
|
-
// src/AggregationBuilder.ts
|
|
584
|
-
import { ikToLKA } from "@fjell/core";
|
|
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
|
-
};
|
|
506
|
+
// src/RowProcessor.ts
|
|
507
|
+
import {
|
|
508
|
+
buildAggregation,
|
|
509
|
+
buildReference,
|
|
510
|
+
contextManager,
|
|
511
|
+
createOperationContext
|
|
512
|
+
} from "@fjell/lib";
|
|
702
513
|
|
|
703
514
|
// src/EventCoordinator.ts
|
|
704
515
|
import deepmerge from "deepmerge";
|
|
705
|
-
var
|
|
516
|
+
var logger5 = logger_default.get("sequelize", "EventCoordinator");
|
|
706
517
|
var populateEvents = (item) => {
|
|
707
518
|
const events = {
|
|
708
519
|
created: { at: item.createdAt || null },
|
|
@@ -713,7 +524,7 @@ var populateEvents = (item) => {
|
|
|
713
524
|
return item;
|
|
714
525
|
};
|
|
715
526
|
var extractEvents = (item) => {
|
|
716
|
-
|
|
527
|
+
logger5.default("Extracting Events to database fields", { item });
|
|
717
528
|
if (item.events) {
|
|
718
529
|
if (item.events.created?.at) {
|
|
719
530
|
item.createdAt = item.events.created.at;
|
|
@@ -728,33 +539,33 @@ var extractEvents = (item) => {
|
|
|
728
539
|
return item;
|
|
729
540
|
};
|
|
730
541
|
var removeEvents = (item) => {
|
|
731
|
-
|
|
542
|
+
logger5.default("Removing Events", { item });
|
|
732
543
|
delete item.events;
|
|
733
544
|
return item;
|
|
734
545
|
};
|
|
735
546
|
|
|
736
547
|
// src/RowProcessor.ts
|
|
737
|
-
var
|
|
548
|
+
var logger6 = logger_default.get("sequelize", "RowProcessor");
|
|
738
549
|
var processRow = async (row, keyTypes, referenceDefinitions, aggregationDefinitions, registry, context) => {
|
|
739
|
-
|
|
550
|
+
logger6.default("Processing Row", { row });
|
|
740
551
|
const operationContext = context || createOperationContext();
|
|
741
552
|
return contextManager.withContext(operationContext, async () => {
|
|
742
553
|
let item = row.get({ plain: true });
|
|
743
|
-
|
|
554
|
+
logger6.default("Adding Key to Item with Key Types: %s", stringifyJSON(keyTypes));
|
|
744
555
|
item = addKey(row, item, keyTypes);
|
|
745
556
|
item = populateEvents(item);
|
|
746
|
-
|
|
557
|
+
logger6.default("Key Added to Item: %s", stringifyJSON(item.key));
|
|
747
558
|
operationContext.markInProgress(item.key);
|
|
748
559
|
try {
|
|
749
560
|
if (referenceDefinitions && referenceDefinitions.length > 0) {
|
|
750
561
|
for (const referenceDefinition of referenceDefinitions) {
|
|
751
|
-
|
|
562
|
+
logger6.default("Processing Reference for %s to %s", item.key.kt, stringifyJSON(referenceDefinition.kta));
|
|
752
563
|
item = await buildReference(item, referenceDefinition, registry, operationContext);
|
|
753
564
|
}
|
|
754
565
|
}
|
|
755
566
|
if (aggregationDefinitions && aggregationDefinitions.length > 0) {
|
|
756
567
|
for (const aggregationDefinition of aggregationDefinitions) {
|
|
757
|
-
|
|
568
|
+
logger6.default("Processing Aggregation for %s from %s", item.key.kt, stringifyJSON(aggregationDefinition.kta));
|
|
758
569
|
item = await buildAggregation(item, aggregationDefinition, registry, operationContext);
|
|
759
570
|
}
|
|
760
571
|
}
|
|
@@ -762,14 +573,14 @@ var processRow = async (row, keyTypes, referenceDefinitions, aggregationDefiniti
|
|
|
762
573
|
} finally {
|
|
763
574
|
operationContext.markComplete(item.key);
|
|
764
575
|
}
|
|
765
|
-
|
|
576
|
+
logger6.default("Processed Row: %j", stringifyJSON(item));
|
|
766
577
|
return item;
|
|
767
578
|
});
|
|
768
579
|
};
|
|
769
580
|
|
|
770
581
|
// src/ops/all.ts
|
|
771
582
|
import { Op as Op2 } from "sequelize";
|
|
772
|
-
var
|
|
583
|
+
var logger7 = logger_default.get("sequelize", "ops", "all");
|
|
773
584
|
var mergeIncludes = (existingIncludes, newIncludes) => {
|
|
774
585
|
const mergedIncludes = [...existingIncludes];
|
|
775
586
|
for (const newInclude of newIncludes) {
|
|
@@ -792,7 +603,7 @@ var mergeIncludes = (existingIncludes, newIncludes) => {
|
|
|
792
603
|
var getAllOperation = (models, definition, registry) => {
|
|
793
604
|
const { coordinate, options: { references, aggregations } } = definition;
|
|
794
605
|
const all = async (itemQuery, locations) => {
|
|
795
|
-
|
|
606
|
+
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
607
|
const loc = locations || [];
|
|
797
608
|
const model = models[0];
|
|
798
609
|
const options = buildQuery(itemQuery, model);
|
|
@@ -805,7 +616,7 @@ var getAllOperation = (models, definition, registry) => {
|
|
|
805
616
|
const relationshipInfo = buildRelationshipPath(model, locKey.kt, kta, true);
|
|
806
617
|
if (!relationshipInfo.found) {
|
|
807
618
|
const errorMessage = `Location key '${locKey.kt}' cannot be resolved on model '${model.name}' or through its relationships.`;
|
|
808
|
-
|
|
619
|
+
logger7.error(errorMessage, { locations: loc, kta });
|
|
809
620
|
throw new Error(errorMessage);
|
|
810
621
|
}
|
|
811
622
|
if (relationshipInfo.isDirect) {
|
|
@@ -816,31 +627,31 @@ var getAllOperation = (models, definition, registry) => {
|
|
|
816
627
|
}
|
|
817
628
|
for (const locKey of directLocations) {
|
|
818
629
|
if (locKey.lk === void 0 || locKey.lk == null || locKey.lk === "" || typeof locKey.lk === "object" && Object.keys(locKey.lk).length === 0) {
|
|
819
|
-
|
|
630
|
+
logger7.error(`Location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`, { locKey, locations: loc });
|
|
820
631
|
throw new Error(`Location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`);
|
|
821
632
|
}
|
|
822
633
|
const foreignKeyField = locKey.kt + "Id";
|
|
823
634
|
if (options.where[foreignKeyField]) {
|
|
824
|
-
|
|
635
|
+
logger7.debug(`[ALL] Field ${foreignKeyField} already constrained by itemQuery, skipping location constraint to avoid conflicts`);
|
|
825
636
|
continue;
|
|
826
637
|
}
|
|
827
|
-
|
|
638
|
+
logger7.trace(`[ALL] Setting direct location where clause: ${foreignKeyField} = ${stringifyJSON(locKey.lk)} (type: ${typeof locKey.lk})`);
|
|
828
639
|
options.where[foreignKeyField] = {
|
|
829
640
|
[Op2.eq]: locKey.lk
|
|
830
641
|
};
|
|
831
642
|
}
|
|
832
643
|
for (const locKey of hierarchicalLocations) {
|
|
833
644
|
if (locKey.lk === void 0 || locKey.lk == null || locKey.lk === "" || typeof locKey.lk === "object" && Object.keys(locKey.lk).length === 0) {
|
|
834
|
-
|
|
645
|
+
logger7.error(`Hierarchical location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`, { locKey, locations: loc });
|
|
835
646
|
throw new Error(`Hierarchical location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`);
|
|
836
647
|
}
|
|
837
648
|
const relationshipInfo = buildRelationshipPath(model, locKey.kt, kta);
|
|
838
649
|
if (relationshipInfo.found && relationshipInfo.path) {
|
|
839
650
|
if (options.where[relationshipInfo.path]) {
|
|
840
|
-
|
|
651
|
+
logger7.debug(`[ALL] Field ${relationshipInfo.path} already constrained by itemQuery, skipping hierarchical location constraint to avoid conflicts`);
|
|
841
652
|
continue;
|
|
842
653
|
}
|
|
843
|
-
|
|
654
|
+
logger7.trace(`[ALL] Setting hierarchical location where clause: ${relationshipInfo.path} = ${stringifyJSON(locKey.lk)} (type: ${typeof locKey.lk})`);
|
|
844
655
|
options.where[relationshipInfo.path] = {
|
|
845
656
|
[Op2.eq]: locKey.lk
|
|
846
657
|
};
|
|
@@ -854,11 +665,11 @@ var getAllOperation = (models, definition, registry) => {
|
|
|
854
665
|
options.include = mergeIncludes(existingIncludes, additionalIncludes);
|
|
855
666
|
}
|
|
856
667
|
}
|
|
857
|
-
|
|
668
|
+
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
669
|
try {
|
|
859
|
-
|
|
670
|
+
logger7.trace(`[ALL] Executing ${model.name}.findAll() with options: ${JSON.stringify(options, null, 2)}`);
|
|
860
671
|
} catch {
|
|
861
|
-
|
|
672
|
+
logger7.trace(`[ALL] Executing ${model.name}.findAll() with options containing non-serializable operators (${Object.keys(options.where || {}).length} where conditions)`);
|
|
862
673
|
}
|
|
863
674
|
const matchingItems = await model.findAll(options);
|
|
864
675
|
const currentContext = contextManager.getCurrentContext();
|
|
@@ -866,7 +677,7 @@ var getAllOperation = (models, definition, registry) => {
|
|
|
866
677
|
const processedRow = await processRow(row, coordinate.kta, references, aggregations, registry, currentContext);
|
|
867
678
|
return validateKeys(processedRow, coordinate.kta);
|
|
868
679
|
}));
|
|
869
|
-
|
|
680
|
+
logger7.debug(`[ALL] Returning ${results.length} ${model.name} records`);
|
|
870
681
|
return results;
|
|
871
682
|
};
|
|
872
683
|
return all;
|
|
@@ -874,13 +685,13 @@ var getAllOperation = (models, definition, registry) => {
|
|
|
874
685
|
|
|
875
686
|
// src/ops/create.ts
|
|
876
687
|
import { isComKey as isComKey2, isPriKey as isPriKey2, validateKeys as validateKeys2 } from "@fjell/core";
|
|
877
|
-
var
|
|
688
|
+
var logger8 = logger_default.get("sequelize", "ops", "create");
|
|
878
689
|
function translateDatabaseError(error, itemData, modelName) {
|
|
879
690
|
const originalMessage = error.message || "";
|
|
880
691
|
const errorCode = error.original?.code;
|
|
881
692
|
const constraint = error.original?.constraint;
|
|
882
693
|
const detail = error.original?.detail;
|
|
883
|
-
|
|
694
|
+
logger8.error("Database error during create operation", {
|
|
884
695
|
errorCode,
|
|
885
696
|
constraint,
|
|
886
697
|
detail,
|
|
@@ -974,8 +785,8 @@ async function validateHierarchicalChain(models, locKey, kta) {
|
|
|
974
785
|
var getCreateOperation = (models, definition, registry) => {
|
|
975
786
|
const create = async (item, options) => {
|
|
976
787
|
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
|
-
|
|
788
|
+
logger8.debug(`CREATE operation called on ${models[0].name} with ${constraints}`);
|
|
789
|
+
logger8.default(`Create configured for ${models[0].name} with ${Object.keys(item).length} item fields`);
|
|
979
790
|
const { coordinate, options: { references, aggregations } } = definition;
|
|
980
791
|
const { kta } = coordinate;
|
|
981
792
|
const model = models[0];
|
|
@@ -1009,7 +820,7 @@ var getCreateOperation = (models, definition, registry) => {
|
|
|
1009
820
|
if (!relationshipInfo.found) {
|
|
1010
821
|
const associations = model.associations ? Object.keys(model.associations) : [];
|
|
1011
822
|
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
|
-
|
|
823
|
+
logger8.error(errorMessage, { key: comKey, kta, associations });
|
|
1013
824
|
throw new Error(errorMessage);
|
|
1014
825
|
}
|
|
1015
826
|
if (relationshipInfo.isDirect) {
|
|
@@ -1020,7 +831,7 @@ var getCreateOperation = (models, definition, registry) => {
|
|
|
1020
831
|
}
|
|
1021
832
|
for (const locKey of directLocations) {
|
|
1022
833
|
if (locKey.lk == null || locKey.lk === "") {
|
|
1023
|
-
|
|
834
|
+
logger8.error(`Composite key location '${locKey.kt}' has undefined/null lk value`, { locKey, key: comKey });
|
|
1024
835
|
throw new Error(`Composite key location '${locKey.kt}' has undefined/null lk value`);
|
|
1025
836
|
}
|
|
1026
837
|
const foreignKeyField = locKey.kt + "Id";
|
|
@@ -1039,7 +850,7 @@ var getCreateOperation = (models, definition, registry) => {
|
|
|
1039
850
|
if (!relationshipInfo.found) {
|
|
1040
851
|
const associations = model.associations ? Object.keys(model.associations) : [];
|
|
1041
852
|
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
|
-
|
|
853
|
+
logger8.error(errorMessage, { locations: options.locations, kta, associations });
|
|
1043
854
|
throw new Error(errorMessage);
|
|
1044
855
|
}
|
|
1045
856
|
if (relationshipInfo.isDirect) {
|
|
@@ -1050,7 +861,7 @@ var getCreateOperation = (models, definition, registry) => {
|
|
|
1050
861
|
}
|
|
1051
862
|
for (const locKey of directLocations) {
|
|
1052
863
|
if (locKey.lk == null || locKey.lk === "") {
|
|
1053
|
-
|
|
864
|
+
logger8.error(`Location option '${locKey.kt}' has undefined/null lk value`, { locKey, locations: options.locations });
|
|
1054
865
|
throw new Error(`Location option '${locKey.kt}' has undefined/null lk value`);
|
|
1055
866
|
}
|
|
1056
867
|
const foreignKeyField = locKey.kt + "Id";
|
|
@@ -1061,11 +872,11 @@ var getCreateOperation = (models, definition, registry) => {
|
|
|
1061
872
|
}
|
|
1062
873
|
}
|
|
1063
874
|
try {
|
|
1064
|
-
|
|
875
|
+
logger8.trace(`[CREATE] Executing ${model.name}.create() with data: ${stringifyJSON(itemData)}`);
|
|
1065
876
|
const createdRecord = await model.create(itemData);
|
|
1066
877
|
const processedRecord = await processRow(createdRecord, kta, references, aggregations, registry);
|
|
1067
878
|
const result = validateKeys2(processedRecord, kta);
|
|
1068
|
-
|
|
879
|
+
logger8.debug(`[CREATE] Created ${model.name} with key: ${result.key ? JSON.stringify(result.key) : `id=${createdRecord.id}`}`);
|
|
1069
880
|
return result;
|
|
1070
881
|
} catch (error) {
|
|
1071
882
|
throw translateDatabaseError(error, itemData, model.name);
|
|
@@ -1076,37 +887,37 @@ var getCreateOperation = (models, definition, registry) => {
|
|
|
1076
887
|
|
|
1077
888
|
// src/ops/find.ts
|
|
1078
889
|
import { validateKeys as validateKeys3 } from "@fjell/core";
|
|
1079
|
-
var
|
|
890
|
+
var logger9 = logger_default.get("sequelize", "ops", "find");
|
|
1080
891
|
var getFindOperation = (models, definition, registry) => {
|
|
1081
892
|
const { options: { finders, references, aggregations } } = definition;
|
|
1082
893
|
const find = async (finder, finderParams, locations) => {
|
|
1083
894
|
const locationFilters = locations?.map((loc) => `${loc.kt}=${loc.lk}`).join(", ") || "none";
|
|
1084
|
-
|
|
895
|
+
logger9.debug(
|
|
1085
896
|
`FIND operation called on ${models[0].name} with finder '${finder}' and ${locations?.length || 0} location filters: ${locationFilters}`
|
|
1086
897
|
);
|
|
1087
|
-
|
|
898
|
+
logger9.default(`Find configured for ${models[0].name} using finder '${finder}' with ${Object.keys(finderParams).length} params`);
|
|
1088
899
|
if (finders && finders[finder]) {
|
|
1089
900
|
const finderMethod = finders[finder];
|
|
1090
901
|
if (finderMethod) {
|
|
1091
|
-
|
|
902
|
+
logger9.trace(`[FIND] Executing finder '${finder}' on ${models[0].name} with params: ${stringifyJSON(finderParams)}, locations: ${stringifyJSON(locations)}`);
|
|
1092
903
|
const results = await finderMethod(finderParams, locations);
|
|
1093
904
|
if (results && results.length > 0) {
|
|
1094
905
|
const processedResults = await Promise.all(results.map(async (row) => {
|
|
1095
906
|
const processedRow = await processRow(row, definition.coordinate.kta, references, aggregations, registry);
|
|
1096
907
|
return validateKeys3(processedRow, definition.coordinate.kta);
|
|
1097
908
|
}));
|
|
1098
|
-
|
|
909
|
+
logger9.debug(`[FIND] Found ${processedResults.length} ${models[0].name} records using finder '${finder}'`);
|
|
1099
910
|
return processedResults;
|
|
1100
911
|
} else {
|
|
1101
|
-
|
|
912
|
+
logger9.debug(`[FIND] Found 0 ${models[0].name} records using finder '${finder}'`);
|
|
1102
913
|
return [];
|
|
1103
914
|
}
|
|
1104
915
|
} else {
|
|
1105
|
-
|
|
916
|
+
logger9.error(`Finder %s not found`, finder);
|
|
1106
917
|
throw new Error(`Finder ${finder} not found`);
|
|
1107
918
|
}
|
|
1108
919
|
} else {
|
|
1109
|
-
|
|
920
|
+
logger9.error(`No finders have been defined for this lib`);
|
|
1110
921
|
throw new Error(`No finders found`);
|
|
1111
922
|
}
|
|
1112
923
|
};
|
|
@@ -1121,7 +932,7 @@ import {
|
|
|
1121
932
|
validateKeys as validateKeys4
|
|
1122
933
|
} from "@fjell/core";
|
|
1123
934
|
import { NotFoundError } from "@fjell/lib";
|
|
1124
|
-
var
|
|
935
|
+
var logger10 = logger_default.get("sequelize", "ops", "get");
|
|
1125
936
|
var processCompositeKey = (comKey, model, kta) => {
|
|
1126
937
|
const where = { id: comKey.pk };
|
|
1127
938
|
const includes = [];
|
|
@@ -1129,7 +940,7 @@ var processCompositeKey = (comKey, model, kta) => {
|
|
|
1129
940
|
const relationshipInfo = buildRelationshipPath(model, locator.kt, kta);
|
|
1130
941
|
if (!relationshipInfo.found) {
|
|
1131
942
|
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
|
-
|
|
943
|
+
logger10.error(errorMessage, { key: comKey, kta });
|
|
1133
944
|
throw new Error(errorMessage);
|
|
1134
945
|
}
|
|
1135
946
|
if (relationshipInfo.path) {
|
|
@@ -1153,23 +964,23 @@ var getGetOperation = (models, definition, registry) => {
|
|
|
1153
964
|
const { kta } = coordinate;
|
|
1154
965
|
const get = async (key) => {
|
|
1155
966
|
if (!isValidItemKey(key)) {
|
|
1156
|
-
|
|
967
|
+
logger10.error("Key for Get is not a valid ItemKey: %j", key);
|
|
1157
968
|
throw new Error("Key for Get is not a valid ItemKey");
|
|
1158
969
|
}
|
|
1159
970
|
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
|
-
|
|
971
|
+
logger10.debug(`GET operation called on ${models[0].name} with ${keyDescription}`);
|
|
972
|
+
logger10.default(`Get configured for ${models[0].name} with ${isPriKey3(key) ? "primary" : "composite"} key`);
|
|
1162
973
|
const itemKey = key;
|
|
1163
974
|
const model = models[0];
|
|
1164
975
|
let item;
|
|
1165
976
|
if (isPriKey3(itemKey)) {
|
|
1166
|
-
|
|
977
|
+
logger10.trace(`[GET] Executing ${model.name}.findByPk() with pk: ${itemKey.pk}`);
|
|
1167
978
|
item = await model.findByPk(itemKey.pk);
|
|
1168
979
|
} else if (isComKey3(itemKey)) {
|
|
1169
980
|
const comKey = itemKey;
|
|
1170
981
|
const queryOptions = processCompositeKey(comKey, model, kta);
|
|
1171
|
-
|
|
1172
|
-
|
|
982
|
+
logger10.default("Composite key query", { queryOptions });
|
|
983
|
+
logger10.trace(`[GET] Executing ${model.name}.findOne() with options: ${stringifyJSON(queryOptions)}`);
|
|
1173
984
|
item = await model.findOne(queryOptions);
|
|
1174
985
|
}
|
|
1175
986
|
if (!item) {
|
|
@@ -1177,7 +988,7 @@ var getGetOperation = (models, definition, registry) => {
|
|
|
1177
988
|
} else {
|
|
1178
989
|
const currentContext = contextManager.getCurrentContext();
|
|
1179
990
|
const result = validateKeys4(await processRow(item, kta, references, aggregations, registry, currentContext), kta);
|
|
1180
|
-
|
|
991
|
+
logger10.debug(`[GET] Retrieved ${model.name} with key: ${result.key ? JSON.stringify(result.key) : `id=${item.id}`}`);
|
|
1181
992
|
return result;
|
|
1182
993
|
}
|
|
1183
994
|
};
|
|
@@ -1185,18 +996,18 @@ var getGetOperation = (models, definition, registry) => {
|
|
|
1185
996
|
};
|
|
1186
997
|
|
|
1187
998
|
// src/ops/one.ts
|
|
1188
|
-
var
|
|
999
|
+
var logger11 = logger_default.get("sequelize", "ops", "one");
|
|
1189
1000
|
var getOneOperation = (models, definition, registry) => {
|
|
1190
1001
|
const one = async (itemQuery, locations = []) => {
|
|
1191
|
-
|
|
1192
|
-
|
|
1002
|
+
logger11.debug(`ONE operation called on ${models[0].name} with ${locations.length} location filters: ${locations.map((loc) => `${loc.kt}=${loc.lk}`).join(", ") || "none"}`);
|
|
1003
|
+
logger11.default(`One configured for ${models[0].name} delegating to all operation`);
|
|
1193
1004
|
const items = await getAllOperation(models, definition, registry)(itemQuery, locations);
|
|
1194
1005
|
if (items.length > 0) {
|
|
1195
1006
|
const result = items[0];
|
|
1196
|
-
|
|
1007
|
+
logger11.debug(`[ONE] Found ${models[0].name} record with key: ${result.key ? JSON.stringify(result.key) : "unknown"}`);
|
|
1197
1008
|
return result;
|
|
1198
1009
|
} else {
|
|
1199
|
-
|
|
1010
|
+
logger11.debug(`[ONE] No ${models[0].name} record found`);
|
|
1200
1011
|
return null;
|
|
1201
1012
|
}
|
|
1202
1013
|
};
|
|
@@ -1207,7 +1018,7 @@ var getOneOperation = (models, definition, registry) => {
|
|
|
1207
1018
|
import { isValidItemKey as isValidItemKey2 } from "@fjell/core";
|
|
1208
1019
|
import { abbrevIK, isComKey as isComKey4, isPriKey as isPriKey4 } from "@fjell/core";
|
|
1209
1020
|
import { NotFoundError as NotFoundError2 } from "@fjell/lib";
|
|
1210
|
-
var
|
|
1021
|
+
var logger12 = logger_default.get("sequelize", "ops", "remove");
|
|
1211
1022
|
var processCompositeKey2 = (comKey, model, kta) => {
|
|
1212
1023
|
const where = { id: comKey.pk };
|
|
1213
1024
|
const includes = [];
|
|
@@ -1215,7 +1026,7 @@ var processCompositeKey2 = (comKey, model, kta) => {
|
|
|
1215
1026
|
const relationshipInfo = buildRelationshipPath(model, locator.kt, kta);
|
|
1216
1027
|
if (!relationshipInfo.found) {
|
|
1217
1028
|
const errorMessage = `Composite key locator '${locator.kt}' cannot be resolved on model '${model.name}' or through its relationships.`;
|
|
1218
|
-
|
|
1029
|
+
logger12.error(errorMessage, { key: comKey, kta });
|
|
1219
1030
|
throw new Error(errorMessage);
|
|
1220
1031
|
}
|
|
1221
1032
|
if (relationshipInfo.path) {
|
|
@@ -1234,29 +1045,29 @@ var processCompositeKey2 = (comKey, model, kta) => {
|
|
|
1234
1045
|
}
|
|
1235
1046
|
return result;
|
|
1236
1047
|
};
|
|
1237
|
-
var getRemoveOperation = (models, definition,
|
|
1048
|
+
var getRemoveOperation = (models, definition, _registry) => {
|
|
1238
1049
|
const { coordinate, options } = definition;
|
|
1239
1050
|
const { kta } = coordinate;
|
|
1240
1051
|
const remove = async (key) => {
|
|
1241
1052
|
if (!isValidItemKey2(key)) {
|
|
1242
|
-
|
|
1053
|
+
logger12.error("Key for Remove is not a valid ItemKey: %j", key);
|
|
1243
1054
|
throw new Error("Key for Remove is not a valid ItemKey");
|
|
1244
1055
|
}
|
|
1245
1056
|
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
|
-
|
|
1057
|
+
logger12.debug(`REMOVE operation called on ${models[0].name} with ${keyDescription}`);
|
|
1058
|
+
logger12.default(`Remove configured for ${models[0].name} with ${isPriKey4(key) ? "primary" : "composite"} key`);
|
|
1248
1059
|
const model = models[0];
|
|
1249
1060
|
let item;
|
|
1250
1061
|
let returnItem;
|
|
1251
|
-
|
|
1062
|
+
logger12.debug("remove: %s", abbrevIK(key));
|
|
1252
1063
|
if (isPriKey4(key)) {
|
|
1253
|
-
|
|
1064
|
+
logger12.debug(`[REMOVE] Executing ${model.name}.findByPk() with pk: ${key.pk}`);
|
|
1254
1065
|
item = await model.findByPk(key.pk);
|
|
1255
1066
|
} else if (isComKey4(key)) {
|
|
1256
1067
|
const comKey = key;
|
|
1257
1068
|
const queryOptions = processCompositeKey2(comKey, model, kta);
|
|
1258
|
-
|
|
1259
|
-
|
|
1069
|
+
logger12.default(`Remove composite key query for ${model.name} with where fields: ${queryOptions.where ? Object.keys(queryOptions.where).join(", ") : "none"}`);
|
|
1070
|
+
logger12.debug(`[REMOVE] Executing ${model.name}.findOne() with options: ${stringifyJSON(queryOptions)}`);
|
|
1260
1071
|
item = await model.findOne(queryOptions);
|
|
1261
1072
|
}
|
|
1262
1073
|
if (!item) {
|
|
@@ -1271,13 +1082,13 @@ var getRemoveOperation = (models, definition, registry) => {
|
|
|
1271
1082
|
if (model.getAttributes().deletedAt) {
|
|
1272
1083
|
item.deletedAt = /* @__PURE__ */ new Date();
|
|
1273
1084
|
}
|
|
1274
|
-
|
|
1085
|
+
logger12.debug(`[REMOVE] Executing ${model.name}.save() for soft delete`);
|
|
1275
1086
|
await item?.save();
|
|
1276
1087
|
returnItem = item?.get({ plain: true });
|
|
1277
1088
|
returnItem = addKey(item, returnItem, kta);
|
|
1278
1089
|
returnItem = populateEvents(returnItem);
|
|
1279
1090
|
} else if (options.deleteOnRemove) {
|
|
1280
|
-
|
|
1091
|
+
logger12.debug(`[REMOVE] Executing ${model.name}.destroy() for hard delete`);
|
|
1281
1092
|
await item?.destroy();
|
|
1282
1093
|
returnItem = item?.get({ plain: true });
|
|
1283
1094
|
returnItem = addKey(item, returnItem, kta);
|
|
@@ -1285,7 +1096,7 @@ var getRemoveOperation = (models, definition, registry) => {
|
|
|
1285
1096
|
} else {
|
|
1286
1097
|
throw new Error("No deletedAt or isDeleted attribute found in model, and deleteOnRemove is not set");
|
|
1287
1098
|
}
|
|
1288
|
-
|
|
1099
|
+
logger12.debug(`[REMOVE] Removed ${model.name} with key: ${returnItem.key ? JSON.stringify(returnItem.key) : `id=${item.id}`}`);
|
|
1289
1100
|
return returnItem;
|
|
1290
1101
|
};
|
|
1291
1102
|
return remove;
|
|
@@ -1296,7 +1107,7 @@ import { abbrevIK as abbrevIK2, isComKey as isComKey5, validateKeys as validateK
|
|
|
1296
1107
|
import { isPriKey as isPriKey5 } from "@fjell/core";
|
|
1297
1108
|
import { NotFoundError as NotFoundError3 } from "@fjell/lib";
|
|
1298
1109
|
import { Op as Op3 } from "sequelize";
|
|
1299
|
-
var
|
|
1110
|
+
var logger13 = logger_default.get("sequelize", "ops", "update");
|
|
1300
1111
|
var mergeIncludes2 = (existingIncludes, newIncludes) => {
|
|
1301
1112
|
const mergedIncludes = [...existingIncludes];
|
|
1302
1113
|
for (const newInclude of newIncludes) {
|
|
@@ -1320,15 +1131,15 @@ var getUpdateOperation = (models, definition, registry) => {
|
|
|
1320
1131
|
const { options: { references, aggregations } } = definition;
|
|
1321
1132
|
const update = async (key, item) => {
|
|
1322
1133
|
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
|
-
|
|
1134
|
+
logger13.debug(`UPDATE operation called on ${models[0].name} with ${keyDescription}`);
|
|
1324
1135
|
const { coordinate } = definition;
|
|
1325
1136
|
const { kta } = coordinate;
|
|
1326
|
-
|
|
1137
|
+
logger13.debug("update: %s, %j", abbrevIK2(key), item);
|
|
1327
1138
|
const model = models[0];
|
|
1328
1139
|
let response;
|
|
1329
1140
|
if (isPriKey5(key)) {
|
|
1330
1141
|
const priKey = key;
|
|
1331
|
-
|
|
1142
|
+
logger13.trace(`[UPDATE] Executing ${model.name}.findByPk() with pk: ${priKey.pk}`);
|
|
1332
1143
|
response = await model.findByPk(priKey.pk);
|
|
1333
1144
|
} else if (isComKey5(key)) {
|
|
1334
1145
|
const comKey = key;
|
|
@@ -1338,7 +1149,7 @@ var getUpdateOperation = (models, definition, registry) => {
|
|
|
1338
1149
|
const relationshipInfo = buildRelationshipPath(model, locator.kt, kta, true);
|
|
1339
1150
|
if (!relationshipInfo.found) {
|
|
1340
1151
|
const errorMessage = `Composite key locator '${locator.kt}' cannot be resolved on model '${model.name}' or through its relationships.`;
|
|
1341
|
-
|
|
1152
|
+
logger13.error(errorMessage, { key: comKey, kta });
|
|
1342
1153
|
throw new Error(errorMessage);
|
|
1343
1154
|
}
|
|
1344
1155
|
if (relationshipInfo.isDirect) {
|
|
@@ -1357,21 +1168,21 @@ var getUpdateOperation = (models, definition, registry) => {
|
|
|
1357
1168
|
if (additionalIncludes.length > 0) {
|
|
1358
1169
|
queryOptions.include = mergeIncludes2([], additionalIncludes);
|
|
1359
1170
|
}
|
|
1360
|
-
|
|
1361
|
-
|
|
1171
|
+
logger13.default(`Update composite key query for ${model.name} with where fields: ${queryOptions.where ? Object.keys(queryOptions.where).join(", ") : "none"}`);
|
|
1172
|
+
logger13.trace(`[UPDATE] Executing ${model.name}.findOne() with options: ${stringifyJSON(queryOptions)}`);
|
|
1362
1173
|
response = await model.findOne(queryOptions);
|
|
1363
1174
|
}
|
|
1364
1175
|
if (response) {
|
|
1365
1176
|
let updateProps = removeKey(item);
|
|
1366
1177
|
updateProps = extractEvents(updateProps);
|
|
1367
1178
|
updateProps = removeEvents(updateProps);
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1179
|
+
logger13.default(`Update found ${model.name} record to modify`);
|
|
1180
|
+
logger13.default(`Update properties configured: ${Object.keys(updateProps).join(", ")}`);
|
|
1181
|
+
logger13.trace(`[UPDATE] Executing ${model.name}.update() with properties: ${stringifyJSON(updateProps)}`);
|
|
1371
1182
|
response = await response.update(updateProps);
|
|
1372
1183
|
const processedItem = await processRow(response, kta, references, aggregations, registry);
|
|
1373
1184
|
const returnItem = validateKeys5(processedItem, kta);
|
|
1374
|
-
|
|
1185
|
+
logger13.debug(`[UPDATE] Updated ${model.name} with key: ${returnItem.key ? JSON.stringify(returnItem.key) : `id=${response.id}`}`);
|
|
1375
1186
|
return returnItem;
|
|
1376
1187
|
} else {
|
|
1377
1188
|
throw new NotFoundError3("update", coordinate, key);
|
|
@@ -1382,25 +1193,25 @@ var getUpdateOperation = (models, definition, registry) => {
|
|
|
1382
1193
|
|
|
1383
1194
|
// src/ops/upsert.ts
|
|
1384
1195
|
import { isValidItemKey as isValidItemKey3 } from "@fjell/core";
|
|
1385
|
-
var
|
|
1196
|
+
var logger14 = logger_default.get("sequelize", "ops", "upsert");
|
|
1386
1197
|
var getUpsertOperation = (models, definition, registry) => {
|
|
1387
1198
|
const get = getGetOperation(models, definition, registry);
|
|
1388
1199
|
const update = getUpdateOperation(models, definition, registry);
|
|
1389
1200
|
const create = getCreateOperation(models, definition, registry);
|
|
1390
1201
|
const upsert = async (key, item) => {
|
|
1391
1202
|
if (!isValidItemKey3(key)) {
|
|
1392
|
-
|
|
1203
|
+
logger14.error("Key for Upsert is not a valid ItemKey: %j", key);
|
|
1393
1204
|
throw new Error(`Key for Upsert is not a valid ItemKey: ${stringifyJSON(key)}`);
|
|
1394
1205
|
}
|
|
1395
|
-
|
|
1206
|
+
logger14.debug(`[UPSERT] Attempting upsert with key: ${stringifyJSON(key)}`);
|
|
1396
1207
|
try {
|
|
1397
1208
|
const existingItem = await get(key);
|
|
1398
1209
|
if (existingItem) {
|
|
1399
|
-
|
|
1210
|
+
logger14.debug(`[UPSERT] Item exists, updating with key: ${stringifyJSON(key)}`);
|
|
1400
1211
|
return await update(key, item);
|
|
1401
1212
|
}
|
|
1402
1213
|
} catch {
|
|
1403
|
-
|
|
1214
|
+
logger14.debug(`[UPSERT] Item not found, creating new item with key: ${stringifyJSON(key)}`);
|
|
1404
1215
|
}
|
|
1405
1216
|
return await create(item, { key });
|
|
1406
1217
|
};
|
|
@@ -1436,9 +1247,9 @@ var createOperations = (models, coordinate, registry, options) => {
|
|
|
1436
1247
|
};
|
|
1437
1248
|
|
|
1438
1249
|
// src/SequelizeLibrary.ts
|
|
1439
|
-
var
|
|
1250
|
+
var logger15 = logger_default.get("SequelizeLibrary");
|
|
1440
1251
|
var createSequelizeLibrary = (registry, coordinate, models, options) => {
|
|
1441
|
-
|
|
1252
|
+
logger15.debug("createSequelizeLibrary", { coordinate, models, registry, options });
|
|
1442
1253
|
const operations = createOperations(models, coordinate, registry, options);
|
|
1443
1254
|
const wrappedOperations = Library2.wrapOperations(operations, options, coordinate, registry);
|
|
1444
1255
|
const libLibrary = Library2.createLibrary(registry, coordinate, wrappedOperations, options);
|
|
@@ -1452,10 +1263,10 @@ var isSequelizeLibrary = (library) => {
|
|
|
1452
1263
|
};
|
|
1453
1264
|
|
|
1454
1265
|
// src/SequelizeLibraryFactory.ts
|
|
1455
|
-
var
|
|
1266
|
+
var logger16 = logger_default.get("InstanceFactory");
|
|
1456
1267
|
var createSequelizeLibraryFactory = (models, options) => {
|
|
1457
1268
|
return (coordinate, context) => {
|
|
1458
|
-
|
|
1269
|
+
logger16.debug("Creating Sequelize instance", {
|
|
1459
1270
|
coordinate,
|
|
1460
1271
|
registry: context.registry,
|
|
1461
1272
|
models: models.map((m) => m.name),
|
|
@@ -1500,9 +1311,9 @@ __export(primary_exports, {
|
|
|
1500
1311
|
|
|
1501
1312
|
// src/primary/SequelizeLibrary.ts
|
|
1502
1313
|
import { Primary } from "@fjell/lib";
|
|
1503
|
-
var
|
|
1314
|
+
var logger17 = logger_default.get("lib-sequelize", "primary", "library");
|
|
1504
1315
|
function createSequelizeLibrary3(keyType, models, libOptions = {}, scopes = [], registry) {
|
|
1505
|
-
|
|
1316
|
+
logger17.debug("createSequelizeLibrary", { keyType, models, libOptions, scopes });
|
|
1506
1317
|
const coordinate = createCoordinate([keyType], scopes);
|
|
1507
1318
|
const options = createOptions2(libOptions);
|
|
1508
1319
|
const operations = createOperations(models, coordinate, registry, options);
|