@fjell/lib-sequelize 4.4.5 → 4.4.10
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/cjs/Coordinate.cjs +9 -22
- package/dist/cjs/Definition.cjs +5 -26
- package/dist/cjs/Instance.cjs +26 -10
- package/dist/cjs/InstanceFactory.cjs +25 -0
- package/dist/cjs/Operations.cjs +7 -2
- package/dist/cjs/Options.cjs +14 -7
- package/dist/cjs/QueryBuilder.cjs +31 -25
- package/dist/cjs/contained/Instance.cjs +15 -8
- package/dist/cjs/index.cjs +7 -4
- package/dist/cjs/ops/all.cjs +44 -20
- package/dist/cjs/ops/create.cjs +138 -40
- package/dist/cjs/ops/find.cjs +9 -7
- package/dist/cjs/ops/get.cjs +9 -5
- package/dist/cjs/ops/one.cjs +7 -6
- package/dist/cjs/ops/remove.cjs +10 -7
- package/dist/cjs/ops/update.cjs +10 -7
- package/dist/cjs/primary/Instance.cjs +16 -9
- package/dist/cjs/util/general.cjs +1 -5
- package/dist/es/Coordinate.js +9 -3
- package/dist/es/Definition.js +5 -7
- package/dist/es/Instance.js +26 -11
- package/dist/es/InstanceFactory.js +21 -0
- package/dist/es/Operations.js +7 -2
- package/dist/es/Options.js +14 -7
- package/dist/es/QueryBuilder.js +31 -25
- package/dist/es/contained/Instance.js +15 -8
- package/dist/es/index.js +4 -3
- package/dist/es/ops/all.js +44 -20
- package/dist/es/ops/create.js +139 -41
- package/dist/es/ops/find.js +9 -7
- package/dist/es/ops/get.js +9 -5
- package/dist/es/ops/one.js +7 -6
- package/dist/es/ops/remove.js +11 -8
- package/dist/es/ops/update.js +11 -8
- package/dist/es/primary/Instance.js +16 -9
- package/dist/es/util/general.js +2 -5
- package/dist/index.cjs +412 -216
- package/dist/index.cjs.map +1 -1
- package/dist/types/AggregationBuilder.d.ts +1 -1
- package/dist/types/Coordinate.d.ts +3 -2
- package/dist/types/Definition.d.ts +3 -3
- package/dist/types/Instance.d.ts +22 -2
- package/dist/types/InstanceFactory.d.ts +14 -0
- package/dist/types/Operations.d.ts +3 -2
- package/dist/types/Options.d.ts +1 -1
- package/dist/types/Registry.d.ts +6 -0
- package/dist/types/contained/Instance.d.ts +3 -3
- package/dist/types/index.d.ts +4 -1
- package/dist/types/primary/Instance.d.ts +2 -2
- package/package.json +23 -23
package/dist/es/Instance.js
CHANGED
|
@@ -1,17 +1,32 @@
|
|
|
1
1
|
import * as Library from '@fjell/lib';
|
|
2
|
-
import { createDefinition } from './Definition.js';
|
|
3
2
|
import { createOperations } from './Operations.js';
|
|
3
|
+
import LibLogger from './logger.js';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
const logger = LibLogger.get("Instance");
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new Sequelize instance that extends the fjell-lib instance
|
|
8
|
+
* with Sequelize-specific functionality
|
|
9
|
+
*/ const createInstance = (registry, coordinate, models, options)=>{
|
|
10
|
+
logger.debug("createInstance", {
|
|
11
|
+
coordinate,
|
|
11
12
|
models,
|
|
12
|
-
registry
|
|
13
|
+
registry,
|
|
14
|
+
options
|
|
15
|
+
});
|
|
16
|
+
// Create Sequelize-specific operations
|
|
17
|
+
const operations = createOperations(models, coordinate, registry, options);
|
|
18
|
+
// Create the base fjell-lib instance
|
|
19
|
+
const libInstance = Library.createInstance(registry, coordinate, operations, options);
|
|
20
|
+
return {
|
|
21
|
+
...libInstance,
|
|
22
|
+
models
|
|
13
23
|
};
|
|
14
|
-
}
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Type guard to check if an object is a Sequelize Instance
|
|
27
|
+
*/ const isInstance = (instance)=>{
|
|
28
|
+
return instance != null && instance.coordinate != null && instance.operations != null && instance.options != null && instance.registry != null && instance.models != null && Array.isArray(instance.models);
|
|
29
|
+
};
|
|
15
30
|
|
|
16
|
-
export { createInstance };
|
|
17
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
31
|
+
export { createInstance, isInstance };
|
|
32
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2UuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createInstance } from './Instance.js';
|
|
2
|
+
import LibLogger from './logger.js';
|
|
3
|
+
|
|
4
|
+
const logger = LibLogger.get("InstanceFactory");
|
|
5
|
+
/**
|
|
6
|
+
* Factory function for creating Sequelize instances
|
|
7
|
+
* This extends the fjell-lib pattern by adding Sequelize-specific models
|
|
8
|
+
*/ const createInstanceFactory = (models, options)=>{
|
|
9
|
+
return (coordinate, context)=>{
|
|
10
|
+
logger.debug("Creating Sequelize instance", {
|
|
11
|
+
coordinate,
|
|
12
|
+
registry: context.registry,
|
|
13
|
+
models: models.map((m)=>m.name),
|
|
14
|
+
options
|
|
15
|
+
});
|
|
16
|
+
return createInstance(context.registry, coordinate, models, options);
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { createInstanceFactory };
|
|
21
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2VGYWN0b3J5LmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
package/dist/es/Operations.js
CHANGED
|
@@ -6,8 +6,13 @@ import { getOneOperation } from './ops/one.js';
|
|
|
6
6
|
import { getRemoveOperation } from './ops/remove.js';
|
|
7
7
|
import { getUpdateOperation } from './ops/update.js';
|
|
8
8
|
|
|
9
|
-
const createOperations = (models,
|
|
9
|
+
const createOperations = (models, coordinate, registry, options)=>{
|
|
10
10
|
const operations = {};
|
|
11
|
+
// Create a definition-like object for backward compatibility with existing operation functions
|
|
12
|
+
const definition = {
|
|
13
|
+
coordinate,
|
|
14
|
+
options
|
|
15
|
+
};
|
|
11
16
|
operations.all = getAllOperation(models, definition, registry);
|
|
12
17
|
operations.one = getOneOperation(models, definition, registry);
|
|
13
18
|
operations.create = getCreateOperation(models, definition, registry);
|
|
@@ -22,4 +27,4 @@ const createOperations = (models, definition, registry)=>{
|
|
|
22
27
|
};
|
|
23
28
|
|
|
24
29
|
export { createOperations };
|
|
25
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
30
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiT3BlcmF0aW9ucy5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
package/dist/es/Options.js
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
import * as Library from '@fjell/lib';
|
|
2
|
-
import deepmerge from 'deepmerge';
|
|
3
|
-
import { clean } from './util/general.js';
|
|
4
2
|
|
|
5
|
-
const
|
|
3
|
+
const DEFAULT_SEQUELIZE_OPTIONS = {
|
|
6
4
|
deleteOnRemove: false,
|
|
7
5
|
references: [],
|
|
8
6
|
aggregations: []
|
|
9
7
|
};
|
|
10
|
-
const createOptions = (
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
const createOptions = (sequelizeOptions)=>{
|
|
9
|
+
// Create the base lib options
|
|
10
|
+
const baseOptions = Library.createOptions(sequelizeOptions);
|
|
11
|
+
var _sequelizeOptions_deleteOnRemove, _sequelizeOptions_references, _sequelizeOptions_aggregations;
|
|
12
|
+
// Add Sequelize-specific defaults
|
|
13
|
+
const result = {
|
|
14
|
+
...baseOptions,
|
|
15
|
+
deleteOnRemove: (_sequelizeOptions_deleteOnRemove = sequelizeOptions === null || sequelizeOptions === void 0 ? void 0 : sequelizeOptions.deleteOnRemove) !== null && _sequelizeOptions_deleteOnRemove !== void 0 ? _sequelizeOptions_deleteOnRemove : DEFAULT_SEQUELIZE_OPTIONS.deleteOnRemove,
|
|
16
|
+
references: (_sequelizeOptions_references = sequelizeOptions === null || sequelizeOptions === void 0 ? void 0 : sequelizeOptions.references) !== null && _sequelizeOptions_references !== void 0 ? _sequelizeOptions_references : DEFAULT_SEQUELIZE_OPTIONS.references,
|
|
17
|
+
aggregations: (_sequelizeOptions_aggregations = sequelizeOptions === null || sequelizeOptions === void 0 ? void 0 : sequelizeOptions.aggregations) !== null && _sequelizeOptions_aggregations !== void 0 ? _sequelizeOptions_aggregations : DEFAULT_SEQUELIZE_OPTIONS.aggregations
|
|
18
|
+
};
|
|
19
|
+
return result;
|
|
13
20
|
};
|
|
14
21
|
|
|
15
22
|
export { createOptions };
|
|
16
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
23
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiT3B0aW9ucy5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
package/dist/es/QueryBuilder.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { isCondition, isPriKey, isComKey } from '@fjell/core';
|
|
2
2
|
import { Op } from 'sequelize';
|
|
3
3
|
import LibLogger from './logger.js';
|
|
4
|
+
import { stringifyJSON } from './util/general.js';
|
|
4
5
|
|
|
5
6
|
const logger = LibLogger.get('sequelize', 'QueryBuilder');
|
|
6
7
|
const addDeleteQuery = (options, model)=>{
|
|
7
|
-
logger.default(
|
|
8
|
-
options
|
|
9
|
-
});
|
|
8
|
+
logger.default(`QueryBuilder adding delete query with options: ${stringifyJSON(options)}`);
|
|
10
9
|
if (model.getAttributes().deletedAt) {
|
|
11
10
|
options.where['deletedAt'] = {
|
|
12
11
|
[Op.eq]: null
|
|
@@ -19,10 +18,7 @@ const addDeleteQuery = (options, model)=>{
|
|
|
19
18
|
return options;
|
|
20
19
|
};
|
|
21
20
|
const addEventQueries = (options, events, model)=>{
|
|
22
|
-
logger.default(
|
|
23
|
-
options,
|
|
24
|
-
events
|
|
25
|
-
});
|
|
21
|
+
logger.default(`QueryBuilder adding event queries with options: ${stringifyJSON(options)}, events: ${stringifyJSON(events)}`);
|
|
26
22
|
Object.keys(events).forEach((key)=>{
|
|
27
23
|
if (!model.getAttributes()[`${key}At`]) {
|
|
28
24
|
throw new Error(`Event ${key} is not supported on this model, column ${key}At not found`);
|
|
@@ -56,20 +52,22 @@ const addEventQueries = (options, events, model)=>{
|
|
|
56
52
|
};
|
|
57
53
|
// Add the references to the query
|
|
58
54
|
const addReferenceQueries = (options, references, model)=>{
|
|
59
|
-
logger.default(
|
|
60
|
-
options,
|
|
61
|
-
references
|
|
62
|
-
});
|
|
55
|
+
logger.default(`QueryBuilder adding reference queries with options: ${stringifyJSON(options)}, references: ${stringifyJSON(references)}`);
|
|
63
56
|
Object.keys(references).forEach((key)=>{
|
|
64
|
-
logger.default(
|
|
65
|
-
key,
|
|
66
|
-
references
|
|
67
|
-
});
|
|
57
|
+
logger.default(`QueryBuilder adding reference query for key: ${key}, references: ${stringifyJSON(references)}`);
|
|
68
58
|
if (!model.getAttributes()[`${key}Id`]) {
|
|
69
59
|
throw new Error(`Reference ${key} is not supported on this model, column ${key}Id not found`);
|
|
70
60
|
}
|
|
71
61
|
if (isPriKey(references[key])) {
|
|
72
62
|
const priKey = references[key];
|
|
63
|
+
if (priKey.pk == null || priKey.pk === '' || typeof priKey.pk === 'object' && Object.keys(priKey.pk).length === 0) {
|
|
64
|
+
logger.error(`Reference key '${key}' has invalid pk value: ${stringifyJSON(priKey.pk)}`, {
|
|
65
|
+
priKey,
|
|
66
|
+
references
|
|
67
|
+
});
|
|
68
|
+
throw new Error(`Reference key '${key}' has invalid pk value: ${stringifyJSON(priKey.pk)}`);
|
|
69
|
+
}
|
|
70
|
+
logger.trace(`[QueryBuilder] Setting reference where clause: ${key}Id = ${stringifyJSON(priKey.pk)} (type: ${typeof priKey.pk})`);
|
|
73
71
|
options.where[`${key}Id`] = {
|
|
74
72
|
[Op.eq]: priKey.pk
|
|
75
73
|
};
|
|
@@ -146,6 +144,13 @@ const addAssociationCondition = (conditions, condition, model)=>{
|
|
|
146
144
|
// Use Sequelize's $association.attribute$ syntax for querying associated models
|
|
147
145
|
const sequelizeAssociationColumn = `$${associationName}.${attributeName}$`;
|
|
148
146
|
const conditionOp = getSequelizeOperator(condition.operator);
|
|
147
|
+
if (condition.value == null && condition.operator !== '==' && condition.operator !== 'in') {
|
|
148
|
+
logger.error(`Association condition for '${associationName}.${attributeName}' has undefined/null value`, {
|
|
149
|
+
condition
|
|
150
|
+
});
|
|
151
|
+
throw new Error(`Association condition for '${associationName}.${attributeName}' has undefined/null value`);
|
|
152
|
+
}
|
|
153
|
+
logger.trace(`[QueryBuilder] Setting association condition: ${sequelizeAssociationColumn} = ${stringifyJSON(condition.value)} (type: ${typeof condition.value})`);
|
|
149
154
|
conditions[sequelizeAssociationColumn] = {
|
|
150
155
|
[conditionOp]: condition.value
|
|
151
156
|
};
|
|
@@ -157,6 +162,13 @@ const addAttributeCondition = (conditions, condition, model)=>{
|
|
|
157
162
|
throw new Error(`Condition column ${conditionColumn} not found on model ${model.name}`);
|
|
158
163
|
}
|
|
159
164
|
const conditionOp = getSequelizeOperator(condition.operator);
|
|
165
|
+
if (condition.value == null && condition.operator !== '==' && condition.operator !== 'in') {
|
|
166
|
+
logger.error(`Attribute condition for '${conditionColumn}' has undefined/null value`, {
|
|
167
|
+
condition
|
|
168
|
+
});
|
|
169
|
+
throw new Error(`Attribute condition for '${conditionColumn}' has undefined/null value`);
|
|
170
|
+
}
|
|
171
|
+
logger.trace(`[QueryBuilder] Setting attribute condition: ${conditionColumn} = ${stringifyJSON(condition.value)} (type: ${typeof condition.value})`);
|
|
160
172
|
conditions[conditionColumn] = {
|
|
161
173
|
[conditionOp]: condition.value
|
|
162
174
|
};
|
|
@@ -227,16 +239,12 @@ const addAssociationIncludes = (options, model)=>{
|
|
|
227
239
|
return options;
|
|
228
240
|
};
|
|
229
241
|
const buildQuery = (itemQuery, model)=>{
|
|
230
|
-
logger.default(
|
|
231
|
-
itemQuery
|
|
232
|
-
});
|
|
242
|
+
logger.default(`QueryBuilder build called with itemQuery: ${stringifyJSON(itemQuery)}`);
|
|
233
243
|
let options = {
|
|
234
244
|
where: {}
|
|
235
245
|
};
|
|
236
246
|
if (itemQuery.compoundCondition) {
|
|
237
|
-
logger.default(
|
|
238
|
-
compoundCondition: itemQuery.compoundCondition
|
|
239
|
-
});
|
|
247
|
+
logger.default(`QueryBuilder adding conditions: ${stringifyJSON(itemQuery.compoundCondition)}`);
|
|
240
248
|
options = addCompoundCondition(options, itemQuery.compoundCondition, model);
|
|
241
249
|
}
|
|
242
250
|
// If the model has a deletedAt column, we need to add a delete query
|
|
@@ -252,9 +260,7 @@ const buildQuery = (itemQuery, model)=>{
|
|
|
252
260
|
// TODO: Once we start to support Aggs on the server-side, we'll need to parse agg queries
|
|
253
261
|
// Apply a limit to the result set
|
|
254
262
|
if (itemQuery.limit) {
|
|
255
|
-
logger.default(
|
|
256
|
-
limit: itemQuery.limit
|
|
257
|
-
});
|
|
263
|
+
logger.default(`QueryBuilder applying limit: ${itemQuery.limit}`);
|
|
258
264
|
options.limit = itemQuery.limit;
|
|
259
265
|
}
|
|
260
266
|
// Apply an offset to the result set
|
|
@@ -281,4 +287,4 @@ const buildQuery = (itemQuery, model)=>{
|
|
|
281
287
|
};
|
|
282
288
|
|
|
283
289
|
export { addCompoundCondition, addCondition, buildQuery };
|
|
284
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
290
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUXVlcnlCdWlsZGVyLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
|
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import { Contained } from '@fjell/lib';
|
|
2
|
-
import { createDefinition } from '../Definition.js';
|
|
3
2
|
import { createOperations } from '../Operations.js';
|
|
3
|
+
import { createOptions } from '../Options.js';
|
|
4
|
+
import { createCoordinate } from '../Coordinate.js';
|
|
4
5
|
|
|
5
6
|
function createInstance(keyTypes, models, libOptions = {}, scopes = [], registry) {
|
|
6
|
-
|
|
7
|
-
const
|
|
7
|
+
// Create coordinate and options separately following new pattern
|
|
8
|
+
const coordinate = createCoordinate(keyTypes, scopes);
|
|
9
|
+
const options = createOptions(libOptions);
|
|
10
|
+
// Create operations with the new signature
|
|
11
|
+
const operations = createOperations(models, coordinate, registry, options);
|
|
12
|
+
// Wrap operations for contained pattern
|
|
13
|
+
const wrappedOperations = Contained.wrapOperations(operations, options, coordinate, registry);
|
|
8
14
|
return {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
coordinate,
|
|
16
|
+
registry,
|
|
17
|
+
operations: wrappedOperations,
|
|
18
|
+
options,
|
|
19
|
+
models
|
|
13
20
|
};
|
|
14
21
|
}
|
|
15
22
|
|
|
16
23
|
export { createInstance };
|
|
17
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
24
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2UuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
|
package/dist/es/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
export { SCOPE_SEQUELIZE, createCoordinate } from './Coordinate.js';
|
|
2
1
|
export { createDefinition } from './Definition.js';
|
|
3
|
-
export { createInstance } from './Instance.js';
|
|
2
|
+
export { createInstance, isInstance } from './Instance.js';
|
|
3
|
+
export { createInstanceFactory } from './InstanceFactory.js';
|
|
4
4
|
export { createOptions } from './Options.js';
|
|
5
5
|
export { createOperations } from './Operations.js';
|
|
6
6
|
import * as index from './contained/index.js';
|
|
7
7
|
export { index as Contained };
|
|
8
8
|
import * as index$1 from './primary/index.js';
|
|
9
9
|
export { index$1 as Primary };
|
|
10
|
-
|
|
10
|
+
export { SCOPE_SEQUELIZE, createCoordinate } from './Coordinate.js';
|
|
11
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7In0=
|
package/dist/es/ops/all.js
CHANGED
|
@@ -5,6 +5,7 @@ import { processRow } from '../RowProcessor.js';
|
|
|
5
5
|
import { Op } from 'sequelize';
|
|
6
6
|
import { buildRelationshipPath } from '../util/relationshipUtils.js';
|
|
7
7
|
import { contextManager } from '../OperationContext.js';
|
|
8
|
+
import { stringifyJSON } from '../util/general.js';
|
|
8
9
|
|
|
9
10
|
const logger = LibLogger.get('sequelize', 'ops', 'all');
|
|
10
11
|
// Helper function to merge includes avoiding duplicates
|
|
@@ -31,10 +32,8 @@ const getAllOperation = (models, definition, registry)=>{
|
|
|
31
32
|
const { coordinate, options: { references, aggregations } } = definition;
|
|
32
33
|
//#region Query
|
|
33
34
|
const all = async (itemQuery, locations)=>{
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
locations
|
|
37
|
-
});
|
|
35
|
+
var _options_include;
|
|
36
|
+
logger.debug(`ALL operation called on ${models[0].name} with ${(locations === null || locations === void 0 ? void 0 : locations.length) || 0} location filters: ${(locations === null || locations === void 0 ? void 0 : locations.map((loc)=>`${loc.kt}=${loc.lk}`).join(', ')) || 'none'}`);
|
|
38
37
|
const loc = locations || [];
|
|
39
38
|
// @ts-ignore
|
|
40
39
|
const model = models[0];
|
|
@@ -65,24 +64,44 @@ const getAllOperation = (models, definition, registry)=>{
|
|
|
65
64
|
}
|
|
66
65
|
// Handle direct location keys (simple foreign key constraints)
|
|
67
66
|
for (const locKey of directLocations){
|
|
67
|
+
if (locKey.lk === undefined || locKey.lk == null || locKey.lk === '' || typeof locKey.lk === 'object' && Object.keys(locKey.lk).length === 0) {
|
|
68
|
+
logger.error(`Location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`, {
|
|
69
|
+
locKey,
|
|
70
|
+
locations: loc
|
|
71
|
+
});
|
|
72
|
+
throw new Error(`Location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`);
|
|
73
|
+
}
|
|
68
74
|
const foreignKeyField = locKey.kt + 'Id';
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
[
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
// Check if this field already has a condition from the itemQuery
|
|
76
|
+
if (options.where[foreignKeyField]) {
|
|
77
|
+
logger.debug(`[ALL] Field ${foreignKeyField} already constrained by itemQuery, skipping location constraint to avoid conflicts`);
|
|
78
|
+
continue; // Skip this location constraint to avoid conflicts
|
|
79
|
+
}
|
|
80
|
+
logger.trace(`[ALL] Setting direct location where clause: ${foreignKeyField} = ${stringifyJSON(locKey.lk)} (type: ${typeof locKey.lk})`);
|
|
81
|
+
options.where[foreignKeyField] = {
|
|
82
|
+
[Op.eq]: locKey.lk
|
|
74
83
|
};
|
|
75
84
|
}
|
|
76
85
|
// Handle hierarchical location keys (requires relationship traversal)
|
|
77
86
|
for (const locKey of hierarchicalLocations){
|
|
87
|
+
if (locKey.lk === undefined || locKey.lk == null || locKey.lk === '' || typeof locKey.lk === 'object' && Object.keys(locKey.lk).length === 0) {
|
|
88
|
+
logger.error(`Hierarchical location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`, {
|
|
89
|
+
locKey,
|
|
90
|
+
locations: loc
|
|
91
|
+
});
|
|
92
|
+
throw new Error(`Hierarchical location key '${locKey.kt}' has invalid lk value: ${stringifyJSON(locKey.lk)}`);
|
|
93
|
+
}
|
|
78
94
|
const relationshipInfo = buildRelationshipPath(model, locKey.kt, kta);
|
|
79
95
|
if (relationshipInfo.found && relationshipInfo.path) {
|
|
96
|
+
// Check if this field already has a condition from the itemQuery
|
|
97
|
+
if (options.where[relationshipInfo.path]) {
|
|
98
|
+
logger.debug(`[ALL] Field ${relationshipInfo.path} already constrained by itemQuery, skipping hierarchical location constraint to avoid conflicts`);
|
|
99
|
+
continue; // Skip this location constraint to avoid conflicts
|
|
100
|
+
}
|
|
80
101
|
// Add the relationship constraint using the path
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
[
|
|
84
|
-
[Op.eq]: locKey.lk
|
|
85
|
-
}
|
|
102
|
+
logger.trace(`[ALL] Setting hierarchical location where clause: ${relationshipInfo.path} = ${stringifyJSON(locKey.lk)} (type: ${typeof locKey.lk})`);
|
|
103
|
+
options.where[relationshipInfo.path] = {
|
|
104
|
+
[Op.eq]: locKey.lk
|
|
86
105
|
};
|
|
87
106
|
// Add necessary includes for the relationship traversal
|
|
88
107
|
if (relationshipInfo.includes) {
|
|
@@ -96,22 +115,27 @@ const getAllOperation = (models, definition, registry)=>{
|
|
|
96
115
|
options.include = mergeIncludes(existingIncludes, additionalIncludes);
|
|
97
116
|
}
|
|
98
117
|
}
|
|
99
|
-
logger.default('
|
|
100
|
-
|
|
101
|
-
options
|
|
102
|
-
}
|
|
118
|
+
logger.default(`All query configured for ${model.name} with where fields: ${options.where ? Object.keys(options.where).join(', ') : 'none'}, includes: ${((_options_include = options.include) === null || _options_include === void 0 ? void 0 : _options_include.length) || 0}`);
|
|
119
|
+
try {
|
|
120
|
+
logger.trace(`[ALL] Executing ${model.name}.findAll() with options: ${JSON.stringify(options, null, 2)}`);
|
|
121
|
+
} catch {
|
|
122
|
+
// Fallback for cases where JSON.stringify fails on Sequelize operators
|
|
123
|
+
logger.trace(`[ALL] Executing ${model.name}.findAll() with options containing non-serializable operators (${Object.keys(options.where || {}).length} where conditions)`);
|
|
124
|
+
}
|
|
103
125
|
const matchingItems = await model.findAll(options);
|
|
104
126
|
// this.logger.default('Matching Items', { matchingItems });
|
|
105
127
|
// Get the current context from context manager
|
|
106
128
|
const context = contextManager.getCurrentContext();
|
|
107
129
|
// TODO: Move this Up!
|
|
108
|
-
|
|
130
|
+
const results = await Promise.all(matchingItems.map(async (row)=>{
|
|
109
131
|
const processedRow = await processRow(row, coordinate.kta, references, aggregations, registry, context);
|
|
110
132
|
return validateKeys(processedRow, coordinate.kta);
|
|
111
133
|
}));
|
|
134
|
+
logger.debug(`[ALL] Returning ${results.length} ${model.name} records`);
|
|
135
|
+
return results;
|
|
112
136
|
};
|
|
113
137
|
return all;
|
|
114
138
|
};
|
|
115
139
|
|
|
116
140
|
export { getAllOperation };
|
|
117
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
141
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWxsLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|