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