@fjell/lib-sequelize 4.4.13 → 4.4.15
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.cjs +31 -31
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -79,7 +79,7 @@ const createDefinition = (kta, scopes, libOptions)=>{
|
|
|
79
79
|
};
|
|
80
80
|
|
|
81
81
|
//Recursive implementation of jSON.stringify;
|
|
82
|
-
const
|
|
82
|
+
const stringifyJSON = function(obj, visited = new Set()) {
|
|
83
83
|
const arrOfKeyVals = [];
|
|
84
84
|
const arrVals = [];
|
|
85
85
|
let objKeys = [];
|
|
@@ -94,7 +94,7 @@ const general.stringifyJSON = function(obj, visited = new Set()) {
|
|
|
94
94
|
// Add array to visited before processing its elements
|
|
95
95
|
visited.add(obj);
|
|
96
96
|
obj.forEach(function(el) {
|
|
97
|
-
arrVals.push(
|
|
97
|
+
arrVals.push(stringifyJSON(el, visited));
|
|
98
98
|
});
|
|
99
99
|
return '[' + arrVals + ']';
|
|
100
100
|
}
|
|
@@ -112,7 +112,7 @@ const general.stringifyJSON = function(obj, visited = new Set()) {
|
|
|
112
112
|
else if (typeof keyValOut === 'string') arrOfKeyVals.push(keyOut + '"' + keyValOut + '"');
|
|
113
113
|
else if (typeof keyValOut === 'boolean' || typeof keyValOut === 'number' || keyValOut === null) arrOfKeyVals.push(keyOut + keyValOut);
|
|
114
114
|
else if (keyValOut instanceof Object) {
|
|
115
|
-
arrOfKeyVals.push(keyOut +
|
|
115
|
+
arrOfKeyVals.push(keyOut + stringifyJSON(keyValOut, visited));
|
|
116
116
|
}
|
|
117
117
|
});
|
|
118
118
|
return '{' + arrOfKeyVals + '}';
|
|
@@ -122,7 +122,7 @@ const general.stringifyJSON = function(obj, visited = new Set()) {
|
|
|
122
122
|
|
|
123
123
|
const logger$g = logger$1.default.get('sequelize', 'QueryBuilder');
|
|
124
124
|
const addDeleteQuery = (options, model)=>{
|
|
125
|
-
logger$g.default(`QueryBuilder adding delete query with options: ${
|
|
125
|
+
logger$g.default(`QueryBuilder adding delete query with options: ${stringifyJSON(options)}`);
|
|
126
126
|
if (model.getAttributes().deletedAt) {
|
|
127
127
|
options.where['deletedAt'] = {
|
|
128
128
|
[sequelize.Op.eq]: null
|
|
@@ -135,7 +135,7 @@ const addDeleteQuery = (options, model)=>{
|
|
|
135
135
|
return options;
|
|
136
136
|
};
|
|
137
137
|
const addEventQueries = (options, events, model)=>{
|
|
138
|
-
logger$g.default(`QueryBuilder adding event queries with options: ${
|
|
138
|
+
logger$g.default(`QueryBuilder adding event queries with options: ${stringifyJSON(options)}, events: ${stringifyJSON(events)}`);
|
|
139
139
|
Object.keys(events).forEach((key)=>{
|
|
140
140
|
if (!model.getAttributes()[`${key}At`]) {
|
|
141
141
|
throw new Error(`Event ${key} is not supported on this model, column ${key}At not found`);
|
|
@@ -169,22 +169,22 @@ const addEventQueries = (options, events, model)=>{
|
|
|
169
169
|
};
|
|
170
170
|
// Add the references to the query
|
|
171
171
|
const addReferenceQueries = (options, references, model)=>{
|
|
172
|
-
logger$g.default(`QueryBuilder adding reference queries with options: ${
|
|
172
|
+
logger$g.default(`QueryBuilder adding reference queries with options: ${stringifyJSON(options)}, references: ${stringifyJSON(references)}`);
|
|
173
173
|
Object.keys(references).forEach((key)=>{
|
|
174
|
-
logger$g.default(`QueryBuilder adding reference query for key: ${key}, references: ${
|
|
174
|
+
logger$g.default(`QueryBuilder adding reference query for key: ${key}, references: ${stringifyJSON(references)}`);
|
|
175
175
|
if (!model.getAttributes()[`${key}Id`]) {
|
|
176
176
|
throw new Error(`Reference ${key} is not supported on this model, column ${key}Id not found`);
|
|
177
177
|
}
|
|
178
178
|
if (core.isPriKey(references[key])) {
|
|
179
179
|
const priKey = references[key];
|
|
180
180
|
if (priKey.pk == null || priKey.pk === '' || typeof priKey.pk === 'object' && Object.keys(priKey.pk).length === 0) {
|
|
181
|
-
logger$g.error(`Reference key '${key}' has invalid pk value: ${
|
|
181
|
+
logger$g.error(`Reference key '${key}' has invalid pk value: ${stringifyJSON(priKey.pk)}`, {
|
|
182
182
|
priKey,
|
|
183
183
|
references
|
|
184
184
|
});
|
|
185
|
-
throw new Error(`Reference key '${key}' has invalid pk value: ${
|
|
185
|
+
throw new Error(`Reference key '${key}' has invalid pk value: ${stringifyJSON(priKey.pk)}`);
|
|
186
186
|
}
|
|
187
|
-
logger$g.trace(`[QueryBuilder] Setting reference where clause: ${key}Id = ${
|
|
187
|
+
logger$g.trace(`[QueryBuilder] Setting reference where clause: ${key}Id = ${stringifyJSON(priKey.pk)} (type: ${typeof priKey.pk})`);
|
|
188
188
|
options.where[`${key}Id`] = {
|
|
189
189
|
[sequelize.Op.eq]: priKey.pk
|
|
190
190
|
};
|
|
@@ -267,7 +267,7 @@ const addAssociationCondition = (conditions, condition, model)=>{
|
|
|
267
267
|
});
|
|
268
268
|
throw new Error(`Association condition for '${associationName}.${attributeName}' has undefined/null value`);
|
|
269
269
|
}
|
|
270
|
-
logger$g.trace(`[QueryBuilder] Setting association condition: ${sequelizeAssociationColumn} = ${
|
|
270
|
+
logger$g.trace(`[QueryBuilder] Setting association condition: ${sequelizeAssociationColumn} = ${stringifyJSON(condition.value)} (type: ${typeof condition.value})`);
|
|
271
271
|
conditions[sequelizeAssociationColumn] = {
|
|
272
272
|
[conditionOp]: condition.value
|
|
273
273
|
};
|
|
@@ -285,7 +285,7 @@ const addAttributeCondition = (conditions, condition, model)=>{
|
|
|
285
285
|
});
|
|
286
286
|
throw new Error(`Attribute condition for '${conditionColumn}' has undefined/null value`);
|
|
287
287
|
}
|
|
288
|
-
logger$g.trace(`[QueryBuilder] Setting attribute condition: ${conditionColumn} = ${
|
|
288
|
+
logger$g.trace(`[QueryBuilder] Setting attribute condition: ${conditionColumn} = ${stringifyJSON(condition.value)} (type: ${typeof condition.value})`);
|
|
289
289
|
conditions[conditionColumn] = {
|
|
290
290
|
[conditionOp]: condition.value
|
|
291
291
|
};
|
|
@@ -356,12 +356,12 @@ const addAssociationIncludes = (options, model)=>{
|
|
|
356
356
|
return options;
|
|
357
357
|
};
|
|
358
358
|
const buildQuery = (itemQuery, model)=>{
|
|
359
|
-
logger$g.default(`QueryBuilder build called with itemQuery: ${
|
|
359
|
+
logger$g.default(`QueryBuilder build called with itemQuery: ${stringifyJSON(itemQuery)}`);
|
|
360
360
|
let options = {
|
|
361
361
|
where: {}
|
|
362
362
|
};
|
|
363
363
|
if (itemQuery.compoundCondition) {
|
|
364
|
-
logger$g.default(`QueryBuilder adding conditions: ${
|
|
364
|
+
logger$g.default(`QueryBuilder adding conditions: ${stringifyJSON(itemQuery.compoundCondition)}`);
|
|
365
365
|
options = addCompoundCondition(options, itemQuery.compoundCondition, model);
|
|
366
366
|
}
|
|
367
367
|
// If the model has a deletedAt column, we need to add a delete query
|
|
@@ -983,22 +983,22 @@ const processRow = async (row, keyTypes, referenceDefinitions, aggregationDefini
|
|
|
983
983
|
let item = row.get({
|
|
984
984
|
plain: true
|
|
985
985
|
});
|
|
986
|
-
logger$a.default('Adding Key to Item with Key Types: %s',
|
|
986
|
+
logger$a.default('Adding Key to Item with Key Types: %s', stringifyJSON(keyTypes));
|
|
987
987
|
item = addKey(row, item, keyTypes);
|
|
988
988
|
item = populateEvents(item);
|
|
989
|
-
logger$a.default('Key Added to Item: %s',
|
|
989
|
+
logger$a.default('Key Added to Item: %s', stringifyJSON(item.key));
|
|
990
990
|
// Mark this item as in progress to detect circular references
|
|
991
991
|
operationContext.markInProgress(item.key);
|
|
992
992
|
try {
|
|
993
993
|
if (referenceDefinitions && referenceDefinitions.length > 0) {
|
|
994
994
|
for (const referenceDefinition of referenceDefinitions){
|
|
995
|
-
logger$a.default('Processing Reference for %s to %s', item.key.kt,
|
|
995
|
+
logger$a.default('Processing Reference for %s to %s', item.key.kt, stringifyJSON(referenceDefinition.kta));
|
|
996
996
|
item = await buildReference(item, referenceDefinition, registry, operationContext);
|
|
997
997
|
}
|
|
998
998
|
}
|
|
999
999
|
if (aggregationDefinitions && aggregationDefinitions.length > 0) {
|
|
1000
1000
|
for (const aggregationDefinition of aggregationDefinitions){
|
|
1001
|
-
logger$a.default('Processing Aggregation for %s from %s', item.key.kt,
|
|
1001
|
+
logger$a.default('Processing Aggregation for %s from %s', item.key.kt, stringifyJSON(aggregationDefinition.kta));
|
|
1002
1002
|
item = await buildAggregation(item, aggregationDefinition, registry, operationContext);
|
|
1003
1003
|
}
|
|
1004
1004
|
}
|
|
@@ -1008,7 +1008,7 @@ const processRow = async (row, keyTypes, referenceDefinitions, aggregationDefini
|
|
|
1008
1008
|
// Mark this item as complete
|
|
1009
1009
|
operationContext.markComplete(item.key);
|
|
1010
1010
|
}
|
|
1011
|
-
logger$a.default('Processed Row: %j',
|
|
1011
|
+
logger$a.default('Processed Row: %j', stringifyJSON(item));
|
|
1012
1012
|
return item;
|
|
1013
1013
|
});
|
|
1014
1014
|
};
|
|
@@ -1071,11 +1071,11 @@ const all.getAllOperation = (models, definition, registry)=>{
|
|
|
1071
1071
|
// Handle direct location keys (simple foreign key constraints)
|
|
1072
1072
|
for (const locKey of directLocations){
|
|
1073
1073
|
if (locKey.lk === undefined || locKey.lk == null || locKey.lk === '' || typeof locKey.lk === 'object' && Object.keys(locKey.lk).length === 0) {
|
|
1074
|
-
logger$9.error(`Location key '${locKey.kt}' has invalid lk value: ${
|
|
1074
|
+
logger$9.error(`Location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`, {
|
|
1075
1075
|
locKey,
|
|
1076
1076
|
locations: loc
|
|
1077
1077
|
});
|
|
1078
|
-
throw new Error(`Location key '${locKey.kt}' has invalid lk value: ${
|
|
1078
|
+
throw new Error(`Location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`);
|
|
1079
1079
|
}
|
|
1080
1080
|
const foreignKeyField = locKey.kt + 'Id';
|
|
1081
1081
|
// Check if this field already has a condition from the itemQuery
|
|
@@ -1083,7 +1083,7 @@ const all.getAllOperation = (models, definition, registry)=>{
|
|
|
1083
1083
|
logger$9.debug(`[ALL] Field ${foreignKeyField} already constrained by itemQuery, skipping location constraint to avoid conflicts`);
|
|
1084
1084
|
continue; // Skip this location constraint to avoid conflicts
|
|
1085
1085
|
}
|
|
1086
|
-
logger$9.trace(`[ALL] Setting direct location where clause: ${foreignKeyField} = ${
|
|
1086
|
+
logger$9.trace(`[ALL] Setting direct location where clause: ${foreignKeyField} = ${stringifyJSON(locKey.lk)} (type: ${typeof locKey.lk})`);
|
|
1087
1087
|
options.where[foreignKeyField] = {
|
|
1088
1088
|
[sequelize.Op.eq]: locKey.lk
|
|
1089
1089
|
};
|
|
@@ -1091,11 +1091,11 @@ const all.getAllOperation = (models, definition, registry)=>{
|
|
|
1091
1091
|
// Handle hierarchical location keys (requires relationship traversal)
|
|
1092
1092
|
for (const locKey of hierarchicalLocations){
|
|
1093
1093
|
if (locKey.lk === undefined || locKey.lk == null || locKey.lk === '' || typeof locKey.lk === 'object' && Object.keys(locKey.lk).length === 0) {
|
|
1094
|
-
logger$9.error(`Hierarchical location key '${locKey.kt}' has invalid lk value: ${
|
|
1094
|
+
logger$9.error(`Hierarchical location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`, {
|
|
1095
1095
|
locKey,
|
|
1096
1096
|
locations: loc
|
|
1097
1097
|
});
|
|
1098
|
-
throw new Error(`Hierarchical location key '${locKey.kt}' has invalid lk value: ${
|
|
1098
|
+
throw new Error(`Hierarchical location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`);
|
|
1099
1099
|
}
|
|
1100
1100
|
const relationshipInfo = relationshipUtils.buildRelationshipPath(model, locKey.kt, kta);
|
|
1101
1101
|
if (relationshipInfo.found && relationshipInfo.path) {
|
|
@@ -1105,7 +1105,7 @@ const all.getAllOperation = (models, definition, registry)=>{
|
|
|
1105
1105
|
continue; // Skip this location constraint to avoid conflicts
|
|
1106
1106
|
}
|
|
1107
1107
|
// Add the relationship constraint using the path
|
|
1108
|
-
logger$9.trace(`[ALL] Setting hierarchical location where clause: ${relationshipInfo.path} = ${
|
|
1108
|
+
logger$9.trace(`[ALL] Setting hierarchical location where clause: ${relationshipInfo.path} = ${stringifyJSON(locKey.lk)} (type: ${typeof locKey.lk})`);
|
|
1109
1109
|
options.where[relationshipInfo.path] = {
|
|
1110
1110
|
[sequelize.Op.eq]: locKey.lk
|
|
1111
1111
|
};
|
|
@@ -1368,7 +1368,7 @@ const getCreateOperation = (models, definition, registry)=>{
|
|
|
1368
1368
|
}
|
|
1369
1369
|
// Create the record
|
|
1370
1370
|
try {
|
|
1371
|
-
logger$8.trace(`[CREATE] Executing ${model.name}.create() with data: ${
|
|
1371
|
+
logger$8.trace(`[CREATE] Executing ${model.name}.create() with data: ${stringifyJSON(itemData)}`);
|
|
1372
1372
|
const createdRecord = await model.create(itemData);
|
|
1373
1373
|
// Add key and events
|
|
1374
1374
|
const processedRecord = await processRow(createdRecord, kta, references, aggregations, registry);
|
|
@@ -1393,7 +1393,7 @@ const getFindOperation = (models, definition, registry)=>{
|
|
|
1393
1393
|
if (finders && finders[finder]) {
|
|
1394
1394
|
const finderMethod = finders[finder];
|
|
1395
1395
|
if (finderMethod) {
|
|
1396
|
-
logger$7.trace(`[FIND] Executing finder '${finder}' on ${models[0].name} with params: ${
|
|
1396
|
+
logger$7.trace(`[FIND] Executing finder '${finder}' on ${models[0].name} with params: ${stringifyJSON(finderParams)}, locations: ${stringifyJSON(locations)}`);
|
|
1397
1397
|
const results = await finderMethod(finderParams, locations);
|
|
1398
1398
|
if (results && results.length > 0) {
|
|
1399
1399
|
const processedResults = await Promise.all(results.map(async (row)=>{
|
|
@@ -1480,7 +1480,7 @@ const getGetOperation = (models, definition, registry)=>{
|
|
|
1480
1480
|
logger$6.default('Composite key query', {
|
|
1481
1481
|
queryOptions
|
|
1482
1482
|
});
|
|
1483
|
-
logger$6.trace(`[GET] Executing ${model.name}.findOne() with options: ${
|
|
1483
|
+
logger$6.trace(`[GET] Executing ${model.name}.findOne() with options: ${stringifyJSON(queryOptions)}`);
|
|
1484
1484
|
item = await model.findOne(queryOptions);
|
|
1485
1485
|
}
|
|
1486
1486
|
if (!item) {
|
|
@@ -1575,7 +1575,7 @@ registry)=>{
|
|
|
1575
1575
|
const comKey = key;
|
|
1576
1576
|
const queryOptions = processCompositeKey(comKey, model, kta);
|
|
1577
1577
|
logger$4.default(`Remove composite key query for ${model.name} with where fields: ${queryOptions.where ? Object.keys(queryOptions.where).join(', ') : 'none'}`);
|
|
1578
|
-
logger$4.debug(`[REMOVE] Executing ${model.name}.findOne() with options: ${
|
|
1578
|
+
logger$4.debug(`[REMOVE] Executing ${model.name}.findOne() with options: ${stringifyJSON(queryOptions)}`);
|
|
1579
1579
|
item = await model.findOne(queryOptions);
|
|
1580
1580
|
}
|
|
1581
1581
|
if (!item) {
|
|
@@ -1693,7 +1693,7 @@ const getUpdateOperation = (models, definition, registry)=>{
|
|
|
1693
1693
|
queryOptions.include = mergeIncludes([], additionalIncludes);
|
|
1694
1694
|
}
|
|
1695
1695
|
logger$3.default(`Update composite key query for ${model.name} with where fields: ${queryOptions.where ? Object.keys(queryOptions.where).join(', ') : 'none'}`);
|
|
1696
|
-
logger$3.trace(`[UPDATE] Executing ${model.name}.findOne() with options: ${
|
|
1696
|
+
logger$3.trace(`[UPDATE] Executing ${model.name}.findOne() with options: ${stringifyJSON(queryOptions)}`);
|
|
1697
1697
|
response = await model.findOne(queryOptions);
|
|
1698
1698
|
}
|
|
1699
1699
|
if (response) {
|
|
@@ -1705,7 +1705,7 @@ const getUpdateOperation = (models, definition, registry)=>{
|
|
|
1705
1705
|
logger$3.default(`Update found ${model.name} record to modify`);
|
|
1706
1706
|
logger$3.default(`Update properties configured: ${Object.keys(updateProps).join(', ')}`);
|
|
1707
1707
|
// Update the object
|
|
1708
|
-
logger$3.trace(`[UPDATE] Executing ${model.name}.update() with properties: ${
|
|
1708
|
+
logger$3.trace(`[UPDATE] Executing ${model.name}.update() with properties: ${stringifyJSON(updateProps)}`);
|
|
1709
1709
|
response = await response.update(updateProps);
|
|
1710
1710
|
// Populate the key and events
|
|
1711
1711
|
const processedItem = await processRow(response, kta, references, aggregations, registry);
|