@fjell/lib-sequelize 4.4.14 → 4.4.16

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.
Files changed (91) hide show
  1. package/dist/{types/Operations.d.ts → Operations.d.ts} +5 -5
  2. package/dist/{types/SequelizeLibraryFactory.d.ts → SequelizeLibraryFactory.d.ts} +4 -4
  3. package/dist/{types/contained → contained}/SequelizeLibrary.d.ts +4 -4
  4. package/dist/index.js +1488 -0
  5. package/dist/index.js.map +7 -0
  6. package/dist/logger.d.ts +2 -0
  7. package/dist/{types/ops → ops}/all.d.ts +3 -3
  8. package/dist/{types/ops → ops}/create.d.ts +3 -3
  9. package/dist/{types/ops → ops}/find.d.ts +3 -3
  10. package/dist/{types/ops → ops}/get.d.ts +1 -1
  11. package/dist/{types/ops → ops}/one.d.ts +3 -3
  12. package/dist/{types/ops → ops}/remove.d.ts +4 -3
  13. package/dist/{types/ops → ops}/update.d.ts +3 -3
  14. package/dist/{types/primary → primary}/SequelizeLibrary.d.ts +4 -4
  15. package/package.json +17 -20
  16. package/dist/cjs/AggregationBuilder.cjs +0 -65
  17. package/dist/cjs/Coordinate.cjs +0 -24
  18. package/dist/cjs/Definition.cjs +0 -25
  19. package/dist/cjs/EventCoordinator.cjs +0 -54
  20. package/dist/cjs/KeyMaster.cjs +0 -151
  21. package/dist/cjs/OperationContext.cjs +0 -161
  22. package/dist/cjs/Operations.cjs +0 -34
  23. package/dist/cjs/Options.cjs +0 -46
  24. package/dist/cjs/QueryBuilder.cjs +0 -296
  25. package/dist/cjs/ReferenceBuilder.cjs +0 -76
  26. package/dist/cjs/RowProcessor.cjs +0 -56
  27. package/dist/cjs/SequelizeLibrary.cjs +0 -56
  28. package/dist/cjs/SequelizeLibraryFactory.cjs +0 -25
  29. package/dist/cjs/contained/SequelizeLibrary.cjs +0 -31
  30. package/dist/cjs/contained/index.cjs +0 -11
  31. package/dist/cjs/index.cjs +0 -26
  32. package/dist/cjs/logger.cjs +0 -10
  33. package/dist/cjs/ops/all.cjs +0 -145
  34. package/dist/cjs/ops/create.cjs +0 -252
  35. package/dist/cjs/ops/find.cjs +0 -47
  36. package/dist/cjs/ops/get.cjs +0 -92
  37. package/dist/cjs/ops/one.cjs +0 -27
  38. package/dist/cjs/ops/remove.cjs +0 -114
  39. package/dist/cjs/ops/update.cjs +0 -120
  40. package/dist/cjs/primary/SequelizeLibrary.cjs +0 -41
  41. package/dist/cjs/primary/index.cjs +0 -11
  42. package/dist/cjs/util/general.cjs +0 -48
  43. package/dist/cjs/util/relationshipUtils.cjs +0 -117
  44. package/dist/es/AggregationBuilder.js +0 -61
  45. package/dist/es/Coordinate.js +0 -19
  46. package/dist/es/Definition.js +0 -21
  47. package/dist/es/EventCoordinator.js +0 -48
  48. package/dist/es/KeyMaster.js +0 -146
  49. package/dist/es/OperationContext.js +0 -155
  50. package/dist/es/Operations.js +0 -30
  51. package/dist/es/Options.js +0 -23
  52. package/dist/es/QueryBuilder.js +0 -290
  53. package/dist/es/ReferenceBuilder.js +0 -72
  54. package/dist/es/RowProcessor.js +0 -52
  55. package/dist/es/SequelizeLibrary.js +0 -32
  56. package/dist/es/SequelizeLibraryFactory.js +0 -21
  57. package/dist/es/contained/SequelizeLibrary.js +0 -26
  58. package/dist/es/contained/index.js +0 -2
  59. package/dist/es/index.js +0 -11
  60. package/dist/es/logger.js +0 -6
  61. package/dist/es/ops/all.js +0 -141
  62. package/dist/es/ops/create.js +0 -248
  63. package/dist/es/ops/find.js +0 -43
  64. package/dist/es/ops/get.js +0 -88
  65. package/dist/es/ops/one.js +0 -23
  66. package/dist/es/ops/remove.js +0 -110
  67. package/dist/es/ops/update.js +0 -116
  68. package/dist/es/primary/SequelizeLibrary.js +0 -36
  69. package/dist/es/primary/index.js +0 -2
  70. package/dist/es/util/general.js +0 -44
  71. package/dist/es/util/relationshipUtils.js +0 -112
  72. package/dist/index.cjs +0 -1853
  73. package/dist/index.cjs.map +0 -1
  74. package/dist/types/AggregationBuilder.d.ts +0 -5
  75. package/dist/types/EventCoordinator.d.ts +0 -6
  76. package/dist/types/KeyMaster.d.ts +0 -4
  77. package/dist/types/OperationContext.d.ts +0 -72
  78. package/dist/types/QueryBuilder.d.ts +0 -12
  79. package/dist/types/ReferenceBuilder.d.ts +0 -4
  80. package/dist/types/RowProcessor.d.ts +0 -6
  81. package/dist/types/logger.d.ts +0 -2
  82. package/dist/types/util/general.d.ts +0 -4
  83. package/dist/types/util/relationshipUtils.d.ts +0 -21
  84. package/dist/{types/Coordinate.d.ts → Coordinate.d.ts} +0 -0
  85. package/dist/{types/Definition.d.ts → Definition.d.ts} +0 -0
  86. package/dist/{types/Options.d.ts → Options.d.ts} +1 -1
  87. package/dist/{types/Registry.d.ts → Registry.d.ts} +0 -0
  88. package/dist/{types/SequelizeLibrary.d.ts → SequelizeLibrary.d.ts} +1 -1
  89. /package/dist/{types/contained → contained}/index.d.ts +0 -0
  90. /package/dist/{types/index.d.ts → index.d.ts} +0 -0
  91. /package/dist/{types/primary → primary}/index.d.ts +0 -0
@@ -1,114 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const core = require('@fjell/core');
6
- const EventCoordinator = require('../EventCoordinator.cjs');
7
- const KeyMaster = require('../KeyMaster.cjs');
8
- const logger$1 = require('../logger.cjs');
9
- const relationshipUtils = require('../util/relationshipUtils.cjs');
10
- const general = require('../util/general.cjs');
11
-
12
- const logger = logger$1.default.get('sequelize', 'ops', 'remove');
13
- // Helper function to process composite key and build query options
14
- const processCompositeKey = (comKey, model, kta)=>{
15
- const where = {
16
- id: comKey.pk
17
- };
18
- const includes = [];
19
- for (const locator of comKey.loc){
20
- const relationshipInfo = relationshipUtils.buildRelationshipPath(model, locator.kt, kta);
21
- if (!relationshipInfo.found) {
22
- const errorMessage = `Composite key locator '${locator.kt}' cannot be resolved on model '${model.name}' or through its relationships.`;
23
- logger.error(errorMessage, {
24
- key: comKey,
25
- kta
26
- });
27
- throw new Error(errorMessage);
28
- }
29
- if (relationshipInfo.path) {
30
- // This requires a relationship traversal
31
- where[relationshipInfo.path] = locator.lk;
32
- if (relationshipInfo.includes) {
33
- includes.push(...relationshipInfo.includes);
34
- }
35
- } else {
36
- // This is a direct field
37
- const fieldName = `${locator.kt}Id`;
38
- where[fieldName] = locator.lk;
39
- }
40
- }
41
- const result = {
42
- where
43
- };
44
- if (includes.length > 0) {
45
- result.include = includes;
46
- }
47
- return result;
48
- };
49
- const getRemoveOperation = (models, definition, // eslint-disable-next-line @typescript-eslint/no-unused-vars
50
- registry)=>{
51
- const { coordinate, options } = definition;
52
- const { kta } = coordinate;
53
- const remove = async (key)=>{
54
- if (!core.isValidItemKey(key)) {
55
- logger.error('Key for Remove is not a valid ItemKey: %j', key);
56
- throw new Error('Key for Remove is not a valid ItemKey');
57
- }
58
- logger.debug(`REMOVE operation called on ${models[0].name} with ${core.isPriKey(key) ? `primary key: pk=${key.pk}` : `composite key: pk=${key.pk}, loc=[${key.loc.map((l)=>`${l.kt}=${l.lk}`).join(', ')}]`}`);
59
- logger.default(`Remove configured for ${models[0].name} with ${core.isPriKey(key) ? 'primary' : 'composite'} key`);
60
- // @ts-ignore
61
- const model = models[0];
62
- let item;
63
- let returnItem;
64
- logger.debug('remove: %s', core.abbrevIK(key));
65
- if (core.isPriKey(key)) {
66
- logger.debug(`[REMOVE] Executing ${model.name}.findByPk() with pk: ${key.pk}`);
67
- item = await model.findByPk(key.pk);
68
- } else if (core.isComKey(key)) {
69
- // This is a composite key, so we need to build a where clause based on the composite key's locators
70
- const comKey = key;
71
- const queryOptions = processCompositeKey(comKey, model, kta);
72
- logger.default(`Remove composite key query for ${model.name} with where fields: ${queryOptions.where ? Object.keys(queryOptions.where).join(', ') : 'none'}`);
73
- logger.debug(`[REMOVE] Executing ${model.name}.findOne() with options: ${general.stringifyJSON(queryOptions)}`);
74
- item = await model.findOne(queryOptions);
75
- }
76
- if (!item) {
77
- throw new Error(`Item not found for removal with key: ${core.abbrevIK(key)}`);
78
- }
79
- const isDeletedAttribute = model.getAttributes().isDeleted;
80
- const deletedAtAttribute = model.getAttributes().deletedAt;
81
- if (isDeletedAttribute || deletedAtAttribute) {
82
- if (model.getAttributes().isDeleted) {
83
- item.isDeleted = true;
84
- }
85
- if (model.getAttributes().deletedAt) {
86
- item.deletedAt = new Date();
87
- }
88
- // Save the object
89
- logger.debug(`[REMOVE] Executing ${model.name}.save() for soft delete`);
90
- await (item === null || item === void 0 ? void 0 : item.save());
91
- returnItem = item === null || item === void 0 ? void 0 : item.get({
92
- plain: true
93
- });
94
- returnItem = KeyMaster.addKey(item, returnItem, kta);
95
- returnItem = EventCoordinator.populateEvents(returnItem);
96
- } else if (options.deleteOnRemove) {
97
- logger.debug(`[REMOVE] Executing ${model.name}.destroy() for hard delete`);
98
- await (item === null || item === void 0 ? void 0 : item.destroy());
99
- returnItem = item === null || item === void 0 ? void 0 : item.get({
100
- plain: true
101
- });
102
- returnItem = KeyMaster.addKey(item, returnItem, kta);
103
- returnItem = EventCoordinator.populateEvents(returnItem);
104
- } else {
105
- throw new Error('No deletedAt or isDeleted attribute found in model, and deleteOnRemove is not set');
106
- }
107
- logger.debug(`[REMOVE] Removed ${model.name} with key: ${returnItem.key ? JSON.stringify(returnItem.key) : `id=${item.id}`}`);
108
- return returnItem;
109
- };
110
- return remove;
111
- };
112
-
113
- exports.getRemoveOperation = getRemoveOperation;
114
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVtb3ZlLmNqcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
@@ -1,120 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const core = require('@fjell/core');
6
- const EventCoordinator = require('../EventCoordinator.cjs');
7
- const KeyMaster = require('../KeyMaster.cjs');
8
- const logger$1 = require('../logger.cjs');
9
- const RowProcessor = require('../RowProcessor.cjs');
10
- const Library = require('@fjell/lib');
11
- const sequelize = require('sequelize');
12
- const relationshipUtils = require('../util/relationshipUtils.cjs');
13
- const general = require('../util/general.cjs');
14
-
15
- const logger = logger$1.default.get('sequelize', 'ops', 'update');
16
- // Helper function to merge includes avoiding duplicates
17
- const mergeIncludes = (existingIncludes, newIncludes)=>{
18
- const mergedIncludes = [
19
- ...existingIncludes
20
- ];
21
- for (const newInclude of newIncludes){
22
- const existingIndex = mergedIncludes.findIndex((existing)=>existing.as === newInclude.as && existing.model === newInclude.model);
23
- if (existingIndex === -1) {
24
- mergedIncludes.push(newInclude);
25
- } else if (newInclude.include && mergedIncludes[existingIndex].include) {
26
- mergedIncludes[existingIndex].include = [
27
- ...mergedIncludes[existingIndex].include,
28
- ...newInclude.include
29
- ];
30
- } else if (newInclude.include) {
31
- mergedIncludes[existingIndex].include = newInclude.include;
32
- }
33
- }
34
- return mergedIncludes;
35
- };
36
- const getUpdateOperation = (models, definition, registry)=>{
37
- const { options: { references, aggregations } } = definition;
38
- const update = async (key, item)=>{
39
- logger.debug(`UPDATE operation called on ${models[0].name} with ${core.isPriKey(key) ? `primary key: pk=${key.pk}` : `composite key: pk=${key.pk}, loc=[${key.loc.map((l)=>`${l.kt}=${l.lk}`).join(', ')}]`}`);
40
- const { coordinate } = definition;
41
- const { kta } = coordinate;
42
- logger.debug('update: %s, %j', core.abbrevIK(key), item);
43
- // Find the object we're updating
44
- // @ts-ignore
45
- const model = models[0];
46
- let response;
47
- if (core.isPriKey(key)) {
48
- // Find the model by using the PK
49
- const priKey = key;
50
- logger.trace(`[UPDATE] Executing ${model.name}.findByPk() with pk: ${priKey.pk}`);
51
- response = await model.findByPk(priKey.pk);
52
- } else if (core.isComKey(key)) {
53
- const comKey = key;
54
- // Build query options for composite key with multiple location keys
55
- const where = {
56
- id: comKey.pk
57
- };
58
- const additionalIncludes = [];
59
- // Process all location keys in the composite key
60
- for (const locator of comKey.loc){
61
- const relationshipInfo = relationshipUtils.buildRelationshipPath(model, locator.kt, kta, true);
62
- if (!relationshipInfo.found) {
63
- const errorMessage = `Composite key locator '${locator.kt}' cannot be resolved on model '${model.name}' or through its relationships.`;
64
- logger.error(errorMessage, {
65
- key: comKey,
66
- kta
67
- });
68
- throw new Error(errorMessage);
69
- }
70
- if (relationshipInfo.isDirect) {
71
- // Direct foreign key field
72
- const fieldName = `${locator.kt}Id`;
73
- where[fieldName] = locator.lk;
74
- } else if (relationshipInfo.path) {
75
- // Hierarchical relationship requiring traversal
76
- where[relationshipInfo.path] = {
77
- [sequelize.Op.eq]: locator.lk
78
- };
79
- // Add necessary includes for relationship traversal
80
- if (relationshipInfo.includes) {
81
- additionalIncludes.push(...relationshipInfo.includes);
82
- }
83
- }
84
- }
85
- // Build final query options
86
- const queryOptions = {
87
- where
88
- };
89
- if (additionalIncludes.length > 0) {
90
- queryOptions.include = mergeIncludes([], additionalIncludes);
91
- }
92
- logger.default(`Update composite key query for ${model.name} with where fields: ${queryOptions.where ? Object.keys(queryOptions.where).join(', ') : 'none'}`);
93
- logger.trace(`[UPDATE] Executing ${model.name}.findOne() with options: ${general.stringifyJSON(queryOptions)}`);
94
- response = await model.findOne(queryOptions);
95
- }
96
- if (response) {
97
- // Remove the key and events
98
- let updateProps = KeyMaster.removeKey(item);
99
- // TODO: We need the opposite of processRow, something to step down from fjell to database.
100
- updateProps = EventCoordinator.extractEvents(updateProps);
101
- updateProps = EventCoordinator.removeEvents(updateProps);
102
- logger.default(`Update found ${model.name} record to modify`);
103
- logger.default(`Update properties configured: ${Object.keys(updateProps).join(', ')}`);
104
- // Update the object
105
- logger.trace(`[UPDATE] Executing ${model.name}.update() with properties: ${general.stringifyJSON(updateProps)}`);
106
- response = await response.update(updateProps);
107
- // Populate the key and events
108
- const processedItem = await RowProcessor.processRow(response, kta, references, aggregations, registry);
109
- const returnItem = core.validateKeys(processedItem, kta);
110
- logger.debug(`[UPDATE] Updated ${model.name} with key: ${returnItem.key ? JSON.stringify(returnItem.key) : `id=${response.id}`}`);
111
- return returnItem;
112
- } else {
113
- throw new Library.NotFoundError('update', coordinate, key);
114
- }
115
- };
116
- return update;
117
- };
118
-
119
- exports.getUpdateOperation = getUpdateOperation;
120
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXBkYXRlLmNqcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
@@ -1,41 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const Library = require('@fjell/lib');
6
- const Operations = require('../Operations.cjs');
7
- const Options = require('../Options.cjs');
8
- const Coordinate = require('../Coordinate.cjs');
9
- const logger$1 = require('../logger.cjs');
10
-
11
- const logger = logger$1.default.get('lib-sequelize', 'primary', 'instance');
12
- function createSequelizeLibrary(keyType, models, libOptions = {}, scopes = [], registry) {
13
- logger.debug('createSequelizeLibrary', {
14
- keyType,
15
- models,
16
- libOptions,
17
- scopes
18
- });
19
- // Create coordinate and options separately following new pattern
20
- const coordinate = Coordinate.createCoordinate([
21
- keyType
22
- ], scopes);
23
- const options = Options.createOptions(libOptions);
24
- // Create operations with the new signature
25
- const operations = Operations.createOperations(models, coordinate, registry, options);
26
- // Wrap operations for primary pattern
27
- const wrappedOperations = Library.Primary.wrapOperations(operations, options, coordinate, registry);
28
- return {
29
- coordinate,
30
- registry,
31
- operations: wrappedOperations,
32
- options,
33
- models
34
- };
35
- }
36
- // Legacy exports for backwards compatibility
37
- const createInstance = createSequelizeLibrary;
38
-
39
- exports.createInstance = createInstance;
40
- exports.createSequelizeLibrary = createSequelizeLibrary;
41
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiU2VxdWVsaXplTGlicmFyeS5janMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
@@ -1,11 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const SequelizeLibrary = require('./SequelizeLibrary.cjs');
6
-
7
-
8
-
9
- exports.createInstance = SequelizeLibrary.createInstance;
10
- exports.createSequelizeLibrary = SequelizeLibrary.createSequelizeLibrary;
11
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguY2pzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OyJ9
@@ -1,48 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- //Recursive implementation of jSON.stringify;
6
- const stringifyJSON = function(obj, visited = new Set()) {
7
- const arrOfKeyVals = [];
8
- const arrVals = [];
9
- let objKeys = [];
10
- /*********CHECK FOR PRIMITIVE TYPES**********/ if (typeof obj === 'number' || typeof obj === 'boolean' || obj === null) return '' + obj;
11
- else if (typeof obj === 'string') return '"' + obj + '"';
12
- /*********DETECT CIRCULAR REFERENCES**********/ if (obj instanceof Object && visited.has(obj)) {
13
- return '"(circular)"';
14
- } else if (Array.isArray(obj)) {
15
- //check for empty array
16
- if (obj[0] === undefined) return '[]';
17
- else {
18
- // Add array to visited before processing its elements
19
- visited.add(obj);
20
- obj.forEach(function(el) {
21
- arrVals.push(stringifyJSON(el, visited));
22
- });
23
- return '[' + arrVals + ']';
24
- }
25
- } else if (obj instanceof Object) {
26
- // Add object to visited before processing its properties
27
- visited.add(obj);
28
- //get object keys
29
- objKeys = Object.keys(obj);
30
- //set key output;
31
- objKeys.forEach(function(key) {
32
- const keyOut = '"' + key + '":';
33
- const keyValOut = obj[key];
34
- //skip functions and undefined properties
35
- if (keyValOut instanceof Function || keyValOut === undefined) return; // Skip this entry entirely instead of pushing an empty string
36
- else if (typeof keyValOut === 'string') arrOfKeyVals.push(keyOut + '"' + keyValOut + '"');
37
- else if (typeof keyValOut === 'boolean' || typeof keyValOut === 'number' || keyValOut === null) arrOfKeyVals.push(keyOut + keyValOut);
38
- else if (keyValOut instanceof Object) {
39
- arrOfKeyVals.push(keyOut + stringifyJSON(keyValOut, visited));
40
- }
41
- });
42
- return '{' + arrOfKeyVals + '}';
43
- }
44
- return '';
45
- };
46
-
47
- exports.stringifyJSON = stringifyJSON;
48
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2VuZXJhbC5janMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
@@ -1,117 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- /* eslint-disable indent */ /**
6
- * Helper function to build relationship chain includes
7
- */ const buildRelationshipChain = (targetModel, kta, currentIndex, targetIndex)=>{
8
- // Build the association path and validate relationships exist
9
- const associationParts = [];
10
- const modelChain = [
11
- targetModel
12
- ];
13
- let currentModel = targetModel;
14
- // Validate that all associations exist and build model chain
15
- for(let i = currentIndex + 1; i <= targetIndex; i++){
16
- const intermediateType = kta[i];
17
- const associationName = intermediateType;
18
- if (!currentModel.associations || !currentModel.associations[associationName]) {
19
- return {
20
- success: false
21
- };
22
- }
23
- associationParts.push(associationName);
24
- currentModel = currentModel.associations[associationName].target;
25
- modelChain.push(currentModel);
26
- }
27
- // Build the full association path for the target field
28
- const targetPrimaryKey = currentModel.primaryKeyAttribute || 'id';
29
- const associationPath = `$${associationParts.join('.')}.${targetPrimaryKey}$`;
30
- // Build nested includes structure iteratively (clearer than recursion)
31
- let deepestInclude = null;
32
- // Build from the deepest level back to the root
33
- for(let i = targetIndex; i > currentIndex; i--){
34
- const currentType = kta[i];
35
- const modelIndex = i - currentIndex;
36
- const includeObj = {
37
- model: modelChain[modelIndex],
38
- as: currentType,
39
- required: true
40
- };
41
- if (deepestInclude) {
42
- includeObj.include = [
43
- deepestInclude
44
- ];
45
- }
46
- deepestInclude = includeObj;
47
- }
48
- const includes = deepestInclude ? [
49
- deepestInclude
50
- ] : [];
51
- return {
52
- success: true,
53
- path: associationPath,
54
- includes
55
- };
56
- };
57
- /**
58
- * Helper function to build relationship path for a locator
59
- * @param includeIsDirect Whether to include the isDirect flag in the result
60
- */ const buildRelationshipPath = (targetModel, locatorType, kta, includeIsDirect = false)=>{
61
- // First check if the field exists directly
62
- const directFieldName = `${locatorType}Id`;
63
- const attributes = targetModel.getAttributes();
64
- if (attributes && attributes[directFieldName]) {
65
- const result = {
66
- found: true
67
- };
68
- if (includeIsDirect) {
69
- result.isDirect = true;
70
- }
71
- return result;
72
- }
73
- // If not direct, look for relationship path
74
- const targetIndex = kta.indexOf(locatorType);
75
- if (targetIndex === -1) {
76
- const result = {
77
- found: false
78
- };
79
- if (includeIsDirect) {
80
- result.isDirect = false;
81
- }
82
- return result;
83
- }
84
- const currentIndex = 0; // We're always looking from the base model
85
- if (targetIndex <= currentIndex) {
86
- const result = {
87
- found: false
88
- };
89
- if (includeIsDirect) {
90
- result.isDirect = false;
91
- }
92
- return result;
93
- }
94
- const chainResult = buildRelationshipChain(targetModel, kta, currentIndex, targetIndex);
95
- if (chainResult.success) {
96
- const result = {
97
- found: true,
98
- path: chainResult.path,
99
- includes: chainResult.includes
100
- };
101
- if (includeIsDirect) {
102
- result.isDirect = false;
103
- }
104
- return result;
105
- }
106
- const result = {
107
- found: false
108
- };
109
- if (includeIsDirect) {
110
- result.isDirect = false;
111
- }
112
- return result;
113
- };
114
-
115
- exports.buildRelationshipChain = buildRelationshipChain;
116
- exports.buildRelationshipPath = buildRelationshipPath;
117
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVsYXRpb25zaGlwVXRpbHMuY2pzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
@@ -1,61 +0,0 @@
1
- import { ikToLKA } from '@fjell/core';
2
- import { serializeKey, contextManager } from './OperationContext.js';
3
- import LibLogger from './logger.js';
4
-
5
- const logger = LibLogger.get('sequelize', 'AggregationBuilder');
6
- const buildAggregation = async (item, aggregationDefinition, registry, context)=>{
7
- const location = ikToLKA(item.key);
8
- // Get the library instance from the registry using the key type array
9
- const libraryInstance = registry.get(aggregationDefinition.kta);
10
- if (!libraryInstance) {
11
- throw new Error(`Library instance not found for key type array: ${aggregationDefinition.kta.join(', ')}`);
12
- }
13
- // Create a cache key for this aggregation query
14
- // This helps avoid running the same aggregation multiple times
15
- const aggregationCacheKey = `${aggregationDefinition.kta.join('.')}_${aggregationDefinition.cardinality}_${serializeKey(item.key)}`;
16
- if (context) {
17
- // Check if this aggregation is already cached
18
- if (context.cache.has(aggregationCacheKey)) {
19
- const cachedResult = context.cache.get(aggregationCacheKey);
20
- logger.default('Using cached aggregation result', {
21
- aggregationCacheKey,
22
- property: aggregationDefinition.property
23
- });
24
- item[aggregationDefinition.property] = cachedResult;
25
- return item;
26
- }
27
- // Note: We don't check for circular dependencies here because:
28
- // 1. Aggregations are location-based queries, not key-based references
29
- // 2. They should be allowed to run during normal item processing
30
- // 3. The main circular dependency concern is with references, not aggregations
31
- }
32
- // Execute aggregation within the current context to ensure context sharing
33
- return contextManager.withContext(context || contextManager.getCurrentContext() || {
34
- inProgress: new Set(),
35
- cache: new Map()
36
- }, async ()=>{
37
- // Based on cardinality, use either one or all operation
38
- if (aggregationDefinition.cardinality === 'one') {
39
- // For one-to-one relationship, use the one operation
40
- return libraryInstance.operations.one({}, location).then((result)=>{
41
- if (context) {
42
- context.cache.set(aggregationCacheKey, result);
43
- }
44
- item[aggregationDefinition.property] = result;
45
- return item;
46
- });
47
- } else {
48
- // For one-to-many relationship, use the all operation
49
- return libraryInstance.operations.all({}, location).then((results)=>{
50
- if (context) {
51
- context.cache.set(aggregationCacheKey, results);
52
- }
53
- item[aggregationDefinition.property] = results;
54
- return item;
55
- });
56
- }
57
- });
58
- };
59
-
60
- export { buildAggregation };
61
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQWdncmVnYXRpb25CdWlsZGVyLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
@@ -1,19 +0,0 @@
1
- import { createCoordinate as createCoordinate$1 } from '@fjell/registry';
2
- import LibLogger from './logger.js';
3
-
4
- const logger = LibLogger.get('Coordinate');
5
- const SCOPE_SEQUELIZE = 'sequelize';
6
- const createCoordinate = (kta, scopes)=>{
7
- logger.debug('createCoordinate', {
8
- kta,
9
- scopes
10
- });
11
- const coordinate = createCoordinate$1(kta, [
12
- SCOPE_SEQUELIZE,
13
- ...scopes || []
14
- ]);
15
- return coordinate;
16
- };
17
-
18
- export { SCOPE_SEQUELIZE, createCoordinate };
19
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ29vcmRpbmF0ZS5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
@@ -1,21 +0,0 @@
1
- import { createOptions } from './Options.js';
2
- import LibLogger from './logger.js';
3
- import { createCoordinate } from './Coordinate.js';
4
-
5
- const logger = LibLogger.get('lib-sequelize', 'Definition');
6
- const createDefinition = (kta, scopes, libOptions)=>{
7
- logger.debug('createDefinition', {
8
- kta,
9
- scopes,
10
- libOptions
11
- });
12
- const coordinate = createCoordinate(kta, scopes);
13
- const options = createOptions(libOptions);
14
- return {
15
- coordinate,
16
- options
17
- };
18
- };
19
-
20
- export { createDefinition };
21
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRGVmaW5pdGlvbi5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
@@ -1,48 +0,0 @@
1
- import 'deepmerge';
2
- import LibLogger from './logger.js';
3
-
4
- const logger = LibLogger.get("sequelize", "EventCoordinator");
5
- //#endregion
6
- const populateEvents = (item)=>{
7
- const events = {
8
- created: {
9
- at: item.createdAt || null
10
- },
11
- updated: {
12
- at: item.updatedAt || null
13
- },
14
- deleted: {
15
- at: null
16
- }
17
- };
18
- item.events = events;
19
- return item;
20
- };
21
- const extractEvents = (item)=>{
22
- logger.default('Extracting Events to database fields', {
23
- item
24
- });
25
- if (item.events) {
26
- var _item_events_created, _item_events_updated, _item_events_deleted;
27
- if ((_item_events_created = item.events.created) === null || _item_events_created === void 0 ? void 0 : _item_events_created.at) {
28
- item.createdAt = item.events.created.at;
29
- }
30
- if ((_item_events_updated = item.events.updated) === null || _item_events_updated === void 0 ? void 0 : _item_events_updated.at) {
31
- item.updatedAt = item.events.updated.at;
32
- }
33
- if ((_item_events_deleted = item.events.deleted) === null || _item_events_deleted === void 0 ? void 0 : _item_events_deleted.at) {
34
- item.deletedAt = item.events.deleted.at;
35
- }
36
- }
37
- return item;
38
- };
39
- const removeEvents = (item)=>{
40
- logger.default('Removing Events', {
41
- item
42
- });
43
- delete item.events;
44
- return item;
45
- };
46
-
47
- export { extractEvents, populateEvents, removeEvents };
48
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRXZlbnRDb29yZGluYXRvci5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==