@fjell/lib-sequelize 4.4.0 → 4.4.1

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 (101) hide show
  1. package/dist/cjs/AggregationBuilder.cjs +31 -0
  2. package/dist/cjs/Coordinate.cjs +37 -0
  3. package/dist/cjs/Definition.cjs +46 -0
  4. package/dist/cjs/EventCoordinator.cjs +35 -0
  5. package/dist/cjs/Instance.cjs +40 -0
  6. package/dist/cjs/KeyMaster.cjs +91 -0
  7. package/dist/cjs/Operations.cjs +29 -0
  8. package/dist/cjs/Options.cjs +39 -0
  9. package/dist/cjs/QueryBuilder.cjs +188 -0
  10. package/dist/cjs/ReferenceBuilder.cjs +34 -0
  11. package/dist/cjs/RowProcessor.cjs +41 -0
  12. package/dist/cjs/contained/Instance.cjs +21 -0
  13. package/dist/cjs/contained/index.cjs +10 -0
  14. package/dist/cjs/index.cjs +23 -0
  15. package/dist/cjs/logger.cjs +10 -0
  16. package/dist/cjs/ops/all.cjs +62 -0
  17. package/dist/cjs/ops/create.cjs +23 -0
  18. package/dist/cjs/ops/find.cjs +45 -0
  19. package/dist/cjs/ops/get.cjs +49 -0
  20. package/dist/cjs/ops/one.cjs +26 -0
  21. package/dist/cjs/ops/remove.cjs +72 -0
  22. package/dist/cjs/ops/update.cjs +59 -0
  23. package/dist/cjs/primary/Instance.cjs +31 -0
  24. package/dist/cjs/primary/index.cjs +10 -0
  25. package/dist/cjs/util/general.cjs +52 -0
  26. package/dist/es/AggregationBuilder.js +27 -0
  27. package/dist/{EventCoordinator.js → es/EventCoordinator.js} +2 -2
  28. package/dist/{Instance.js → es/Instance.js} +6 -5
  29. package/dist/{KeyMaster.js → es/KeyMaster.js} +30 -28
  30. package/dist/{Operations.js → es/Operations.js} +6 -6
  31. package/dist/{Options.js → es/Options.js} +8 -11
  32. package/dist/es/ReferenceBuilder.js +30 -0
  33. package/dist/es/RowProcessor.js +37 -0
  34. package/dist/{contained → es/contained}/Instance.js +6 -5
  35. package/dist/{index.js → es/index.js} +1 -1
  36. package/dist/{ops → es/ops}/all.js +7 -4
  37. package/dist/{ops → es/ops}/create.js +3 -2
  38. package/dist/{ops → es/ops}/find.js +16 -6
  39. package/dist/{ops → es/ops}/get.js +3 -3
  40. package/dist/{ops → es/ops}/one.js +2 -2
  41. package/dist/{ops → es/ops}/remove.js +6 -5
  42. package/dist/{ops → es/ops}/update.js +13 -15
  43. package/dist/{primary → es/primary}/Instance.js +6 -5
  44. package/dist/es/util/general.js +47 -0
  45. package/dist/index.cjs +810 -0
  46. package/dist/index.cjs.map +1 -0
  47. package/dist/types/AggregationBuilder.d.ts +4 -0
  48. package/dist/{Definition.d.ts → types/Definition.d.ts} +1 -1
  49. package/dist/{Instance.d.ts → types/Instance.d.ts} +1 -1
  50. package/dist/{KeyMaster.d.ts → types/KeyMaster.d.ts} +1 -2
  51. package/dist/{Operations.d.ts → types/Operations.d.ts} +2 -2
  52. package/dist/{Options.d.ts → types/Options.d.ts} +14 -3
  53. package/dist/types/ReferenceBuilder.d.ts +3 -0
  54. package/dist/{RowProcessor.d.ts → types/RowProcessor.d.ts} +3 -1
  55. package/dist/{contained → types/contained}/Instance.d.ts +2 -1
  56. package/dist/{ops → types/ops}/all.d.ts +2 -1
  57. package/dist/{ops → types/ops}/create.d.ts +2 -1
  58. package/dist/{ops → types/ops}/find.d.ts +2 -1
  59. package/dist/{ops → types/ops}/get.d.ts +2 -1
  60. package/dist/{ops → types/ops}/one.d.ts +2 -1
  61. package/dist/{ops → types/ops}/remove.d.ts +2 -1
  62. package/dist/{ops → types/ops}/update.d.ts +2 -1
  63. package/dist/{primary → types/primary}/Instance.d.ts +2 -1
  64. package/dist/types/util/general.d.ts +4 -0
  65. package/package.json +36 -31
  66. package/dist/RowProcessor.js +0 -18
  67. package/src/Coordinate.ts +0 -16
  68. package/src/Definition.ts +0 -49
  69. package/src/EventCoordinator.ts +0 -103
  70. package/src/Instance.ts +0 -44
  71. package/src/KeyMaster.ts +0 -90
  72. package/src/Operations.ts +0 -42
  73. package/src/Options.ts +0 -41
  74. package/src/QueryBuilder.ts +0 -208
  75. package/src/RowProcessor.ts +0 -23
  76. package/src/contained/Instance.ts +0 -44
  77. package/src/contained/index.ts +0 -1
  78. package/src/index.ts +0 -7
  79. package/src/logger.ts +0 -5
  80. package/src/ops/all.ts +0 -76
  81. package/src/ops/create.ts +0 -40
  82. package/src/ops/find.ts +0 -49
  83. package/src/ops/get.ts +0 -67
  84. package/src/ops/one.ts +0 -37
  85. package/src/ops/remove.ts +0 -81
  86. package/src/ops/update.ts +0 -78
  87. package/src/primary/Instance.ts +0 -40
  88. package/src/primary/index.ts +0 -1
  89. /package/dist/{Coordinate.js → es/Coordinate.js} +0 -0
  90. /package/dist/{Definition.js → es/Definition.js} +0 -0
  91. /package/dist/{QueryBuilder.js → es/QueryBuilder.js} +0 -0
  92. /package/dist/{contained → es/contained}/index.js +0 -0
  93. /package/dist/{logger.js → es/logger.js} +0 -0
  94. /package/dist/{primary → es/primary}/index.js +0 -0
  95. /package/dist/{Coordinate.d.ts → types/Coordinate.d.ts} +0 -0
  96. /package/dist/{EventCoordinator.d.ts → types/EventCoordinator.d.ts} +0 -0
  97. /package/dist/{QueryBuilder.d.ts → types/QueryBuilder.d.ts} +0 -0
  98. /package/dist/{contained → types/contained}/index.d.ts +0 -0
  99. /package/dist/{index.d.ts → types/index.d.ts} +0 -0
  100. /package/dist/{logger.d.ts → types/logger.d.ts} +0 -0
  101. /package/dist/{primary → types/primary}/index.d.ts +0 -0
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
+
5
+ const Logging = require('@fjell/logging');
6
+
7
+ const LibLogger = Logging.getLogger('@fjell/lib-sequelize');
8
+
9
+ exports.default = LibLogger;
10
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9nZ2VyLmNqcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7In0=
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const core = require('@fjell/core');
6
+ const QueryBuilder = require('../QueryBuilder.cjs');
7
+ const logger$1 = require('../logger.cjs');
8
+ const RowProcessor = require('../RowProcessor.cjs');
9
+ const sequelize = require('sequelize');
10
+
11
+ const logger = logger$1.default.get('sequelize', 'ops', 'all');
12
+ const getAllOperation = (models, definition, registry)=>{
13
+ const { coordinate, options: { references, aggregations } } = definition;
14
+ //#region Query
15
+ const all = async (itemQuery, locations)=>{
16
+ logger.default('All', {
17
+ itemQuery,
18
+ locations
19
+ });
20
+ const loc = locations || [];
21
+ // SQ Libs don't support locations
22
+ if (loc.length > 1) {
23
+ throw new Error('Not implemented for more than one location key');
24
+ }
25
+ // We have the model here?
26
+ // @ts-ignore
27
+ const model = models[0];
28
+ // We have the model here?
29
+ const options = QueryBuilder.buildQuery(itemQuery, model);
30
+ // If this has a location array, we need to add a where clause
31
+ if (loc.length === 1) {
32
+ const locKeyType = loc[0].kt;
33
+ if (model.associations[locKeyType]) {
34
+ const association = model.associations[locKeyType];
35
+ options.where = {
36
+ ...options.where,
37
+ [association.foreignKey]: {
38
+ [sequelize.Op.eq]: loc[0].lk
39
+ }
40
+ };
41
+ } else {
42
+ logger.error('Location key type not found in sequelize model association for: %s', locKeyType);
43
+ throw new Error('Location key type not found in model');
44
+ }
45
+ }
46
+ logger.default('Configured this Item Query', {
47
+ itemQuery,
48
+ options
49
+ });
50
+ const matchingItems = await model.findAll(options);
51
+ // this.logger.default('Matching Items', { matchingItems });
52
+ // TODO: Move this Up!
53
+ return await Promise.all(matchingItems.map(async (row)=>{
54
+ const processedRow = await RowProcessor.processRow(row, coordinate.kta, references, aggregations, registry);
55
+ return core.validateKeys(processedRow, coordinate.kta);
56
+ }));
57
+ };
58
+ return all;
59
+ };
60
+
61
+ exports.getAllOperation = getAllOperation;
62
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWxsLmNqcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const logger$1 = require('../logger.cjs');
6
+
7
+ const logger = logger$1.default.get('sequelize', 'ops', 'create');
8
+ const getCreateOperation = (// eslint-disable-next-line @typescript-eslint/no-unused-vars
9
+ models, // eslint-disable-next-line @typescript-eslint/no-unused-vars
10
+ definition, // eslint-disable-next-line @typescript-eslint/no-unused-vars
11
+ registry)=>{
12
+ const create = async (item, options)=>{
13
+ logger.default('Create', {
14
+ item,
15
+ options
16
+ });
17
+ throw new Error('Not implemented');
18
+ };
19
+ return create;
20
+ };
21
+
22
+ exports.getCreateOperation = getCreateOperation;
23
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3JlYXRlLmNqcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
@@ -0,0 +1,45 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const core = require('@fjell/core');
6
+ const logger$1 = require('../logger.cjs');
7
+ const RowProcessor = require('../RowProcessor.cjs');
8
+
9
+ const logger = logger$1.default.get('sequelize', 'ops', 'find');
10
+ const getFindOperation = (models, definition, registry)=>{
11
+ const { options: { finders, references, aggregations } } = definition;
12
+ const find = async (finder, finderParams, locations)=>{
13
+ logger.default('Find', {
14
+ finder,
15
+ finderParams,
16
+ locations
17
+ });
18
+ // Note that we execute the createFinders function here because we want to make sure we're always getting the
19
+ // most up to date methods.
20
+ if (finders && finders[finder]) {
21
+ const finderMethod = finders[finder];
22
+ if (finderMethod) {
23
+ const results = await finderMethod(finderParams, locations);
24
+ if (results && results.length > 0) {
25
+ return await Promise.all(results.map(async (row)=>{
26
+ const processedRow = await RowProcessor.processRow(row, definition.coordinate.kta, references, aggregations, registry);
27
+ return core.validateKeys(processedRow, definition.coordinate.kta);
28
+ }));
29
+ } else {
30
+ return [];
31
+ }
32
+ } else {
33
+ logger.error(`Finder %s not found`, finder);
34
+ throw new Error(`Finder ${finder} not found`);
35
+ }
36
+ } else {
37
+ logger.error(`No finders have been defined for this lib`);
38
+ throw new Error(`No finders found`);
39
+ }
40
+ };
41
+ return find;
42
+ };
43
+
44
+ exports.getFindOperation = getFindOperation;
45
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmluZC5janMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const core = require('@fjell/core');
6
+ const logger$1 = require('../logger.cjs');
7
+ const RowProcessor = require('../RowProcessor.cjs');
8
+ const Library = require('@fjell/lib');
9
+
10
+ const logger = logger$1.default.get('sequelize', 'ops', 'get');
11
+ const getGetOperation = (models, definition, registry)=>{
12
+ const { coordinate, options: { references, aggregations } } = definition;
13
+ const { kta } = coordinate;
14
+ const get = async (key)=>{
15
+ logger.default('Get', {
16
+ key
17
+ });
18
+ if (!core.isValidItemKey(key)) {
19
+ logger.error('Key for Get is not a valid ItemKey: %j', key);
20
+ throw new Error('Key for Get is not a valid ItemKey');
21
+ }
22
+ const itemKey = key;
23
+ // @ts-ignore
24
+ const model = models[0];
25
+ let item;
26
+ if (core.isPriKey(itemKey)) {
27
+ item = await model.findByPk(itemKey.pk);
28
+ } else if (core.isComKey(itemKey)) {
29
+ var _comKey_loc_, _comKey_loc_1;
30
+ const comKey = itemKey;
31
+ // TODO: This should probably interrogate the model?
32
+ item = await model.findOne({
33
+ where: {
34
+ id: comKey.pk,
35
+ [(comKey === null || comKey === void 0 ? void 0 : (_comKey_loc_ = comKey.loc[0]) === null || _comKey_loc_ === void 0 ? void 0 : _comKey_loc_.kt) + 'Id']: comKey === null || comKey === void 0 ? void 0 : (_comKey_loc_1 = comKey.loc[0]) === null || _comKey_loc_1 === void 0 ? void 0 : _comKey_loc_1.lk
36
+ }
37
+ });
38
+ }
39
+ if (!item) {
40
+ throw new Library.NotFoundError('get', coordinate, key);
41
+ } else {
42
+ return core.validateKeys(await RowProcessor.processRow(item, kta, references, aggregations, registry), kta);
43
+ }
44
+ };
45
+ return get;
46
+ };
47
+
48
+ exports.getGetOperation = getGetOperation;
49
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2V0LmNqcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const logger$1 = require('../logger.cjs');
6
+ const all = require('./all.cjs');
7
+
8
+ const logger = logger$1.default.get('sequelize', 'ops', 'one');
9
+ const getOneOperation = (models, definition, registry)=>{
10
+ const one = async (itemQuery, locations = [])=>{
11
+ logger.default('One', {
12
+ itemQuery,
13
+ locations
14
+ });
15
+ const items = await all.getAllOperation(models, definition, registry)(itemQuery, locations);
16
+ if (items.length > 0) {
17
+ return items[0];
18
+ } else {
19
+ return null;
20
+ }
21
+ };
22
+ return one;
23
+ };
24
+
25
+ exports.getOneOperation = getOneOperation;
26
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib25lLmNqcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
@@ -0,0 +1,72 @@
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
+
10
+ const logger = logger$1.default.get('sequelize', 'ops', 'remove');
11
+ const getRemoveOperation = (models, definition, // eslint-disable-next-line @typescript-eslint/no-unused-vars
12
+ registry)=>{
13
+ const { coordinate, options } = definition;
14
+ const { kta } = coordinate;
15
+ const remove = async (key)=>{
16
+ logger.default('Remove', {
17
+ key
18
+ });
19
+ if (!core.isValidItemKey(key)) {
20
+ logger.error('Key for Remove is not a valid ItemKey: %j', key);
21
+ throw new Error('Key for Remove is not a valid ItemKey');
22
+ }
23
+ // @ts-ignore
24
+ const model = models[0];
25
+ let item;
26
+ let returnItem;
27
+ logger.debug('remove: %s', core.abbrevIK(key));
28
+ if (core.isPriKey(key)) {
29
+ item = await model.findByPk(key.pk);
30
+ } else if (core.isComKey(key)) {
31
+ var _comKey_loc_, _comKey_loc_1;
32
+ const comKey = key;
33
+ item = await model.findOne({
34
+ where: {
35
+ id: comKey.pk,
36
+ [(comKey === null || comKey === void 0 ? void 0 : (_comKey_loc_ = comKey.loc[0]) === null || _comKey_loc_ === void 0 ? void 0 : _comKey_loc_.kt) + 'Id']: comKey === null || comKey === void 0 ? void 0 : (_comKey_loc_1 = comKey.loc[0]) === null || _comKey_loc_1 === void 0 ? void 0 : _comKey_loc_1.lk
37
+ }
38
+ });
39
+ }
40
+ const isDeletedAttribute = model.getAttributes().isDeleted;
41
+ const deletedAtAttribute = model.getAttributes().deletedAt;
42
+ if (isDeletedAttribute || deletedAtAttribute) {
43
+ if (model.getAttributes().isDeleted) {
44
+ item.isDeleted = true;
45
+ }
46
+ if (model.getAttributes().deletedAt) {
47
+ item.deletedAt = new Date();
48
+ }
49
+ // Save the object
50
+ await (item === null || item === void 0 ? void 0 : item.save());
51
+ returnItem = item === null || item === void 0 ? void 0 : item.get({
52
+ plain: true
53
+ });
54
+ returnItem = KeyMaster.addKey(returnItem, kta);
55
+ returnItem = EventCoordinator.populateEvents(returnItem);
56
+ } else if (options.deleteOnRemove) {
57
+ await (item === null || item === void 0 ? void 0 : item.destroy());
58
+ returnItem = item === null || item === void 0 ? void 0 : item.get({
59
+ plain: true
60
+ });
61
+ returnItem = KeyMaster.addKey(returnItem, kta);
62
+ returnItem = EventCoordinator.populateEvents(returnItem);
63
+ } else {
64
+ throw new Error('No deletedAt or isDeleted attribute found in model, and deleteOnRemove is not set');
65
+ }
66
+ return returnItem;
67
+ };
68
+ return remove;
69
+ };
70
+
71
+ exports.getRemoveOperation = getRemoveOperation;
72
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVtb3ZlLmNqcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
@@ -0,0 +1,59 @@
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 general = require('../util/general.cjs');
11
+ const Library = require('@fjell/lib');
12
+
13
+ const logger = logger$1.default.get('sequelize', 'ops', 'update');
14
+ const getUpdateOperation = (models, definition, registry)=>{
15
+ const { options: { references, aggregations } } = definition;
16
+ const update = async (key, item)=>{
17
+ const { coordinate } = definition;
18
+ const { kta } = coordinate;
19
+ logger.debug('update: %s, %j', core.abbrevIK(key), item);
20
+ // Find the object we're updating
21
+ // @ts-ignore
22
+ const model = models[0];
23
+ let response;
24
+ if (core.isPriKey(key)) {
25
+ // Find the model by using the PK
26
+ const priKey = key;
27
+ response = await model.findByPk(priKey.pk);
28
+ } else if (core.isComKey(key)) {
29
+ var _comKey_loc_, _comKey_loc_1;
30
+ const comKey = key;
31
+ // Find the model by using both of the identifiers.
32
+ response = await model.findOne({
33
+ where: {
34
+ [(comKey === null || comKey === void 0 ? void 0 : (_comKey_loc_ = comKey.loc[0]) === null || _comKey_loc_ === void 0 ? void 0 : _comKey_loc_.kt) + 'Id']: comKey === null || comKey === void 0 ? void 0 : (_comKey_loc_1 = comKey.loc[0]) === null || _comKey_loc_1 === void 0 ? void 0 : _comKey_loc_1.lk,
35
+ id: comKey === null || comKey === void 0 ? void 0 : comKey.pk
36
+ }
37
+ });
38
+ }
39
+ if (response) {
40
+ // Remove the key and events
41
+ let updateProps = KeyMaster.removeKey(item);
42
+ updateProps = EventCoordinator.removeEvents(item);
43
+ logger.default('Response: %s', general.stringifyJSON(response));
44
+ logger.default('Update Properties: %s', general.stringifyJSON(updateProps));
45
+ // Update the object
46
+ response = await response.update(updateProps);
47
+ // Populate the key and events
48
+ const processedItem = await RowProcessor.processRow(response, kta, references, aggregations, registry);
49
+ const returnItem = core.validateKeys(processedItem, kta);
50
+ return returnItem;
51
+ } else {
52
+ throw new Library.NotFoundError('update', coordinate, key);
53
+ }
54
+ };
55
+ return update;
56
+ };
57
+
58
+ exports.getUpdateOperation = getUpdateOperation;
59
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXBkYXRlLmNqcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const Library = require('@fjell/lib');
6
+ const Definition = require('../Definition.cjs');
7
+ const Operations = require('../Operations.cjs');
8
+ const logger$1 = require('../logger.cjs');
9
+
10
+ const logger = logger$1.default.get('lib-sequelize', 'primary', 'instance');
11
+ function createInstance(keyType, models, libOptions = {}, scopes = [], registry) {
12
+ logger.debug('createInstance', {
13
+ keyType,
14
+ models,
15
+ libOptions,
16
+ scopes
17
+ });
18
+ const definition = Definition.createDefinition([
19
+ keyType
20
+ ], scopes, libOptions);
21
+ const operations = Operations.createOperations(models, definition, registry);
22
+ return {
23
+ definition,
24
+ operations: Library.Primary.wrapOperations(operations, definition, registry),
25
+ models,
26
+ registry
27
+ };
28
+ }
29
+
30
+ exports.createInstance = createInstance;
31
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2UuY2pzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const Instance = require('./Instance.cjs');
6
+
7
+
8
+
9
+ exports.createInstance = Instance.createInstance;
10
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguY2pzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7In0=
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable no-undefined */ const clean = (obj)=>{
6
+ return Object.fromEntries(Object.entries(obj).filter(([_, v])=>v !== undefined));
7
+ };
8
+ //Recursive implementation of jSON.stringify;
9
+ const stringifyJSON = function(obj, visited = new Set()) {
10
+ const arrOfKeyVals = [];
11
+ const arrVals = [];
12
+ let objKeys = [];
13
+ /*********CHECK FOR PRIMITIVE TYPES**********/ if (typeof obj === 'number' || typeof obj === 'boolean' || obj === null) return '' + obj;
14
+ else if (typeof obj === 'string') return '"' + obj + '"';
15
+ /*********DETECT CIRCULAR REFERENCES**********/ if (obj instanceof Object && visited.has(obj)) {
16
+ return '"(circular)"';
17
+ } else if (Array.isArray(obj)) {
18
+ //check for empty array
19
+ if (obj[0] === undefined) return '[]';
20
+ else {
21
+ // Add array to visited before processing its elements
22
+ visited.add(obj);
23
+ obj.forEach(function(el) {
24
+ arrVals.push(stringifyJSON(el, visited));
25
+ });
26
+ return '[' + arrVals + ']';
27
+ }
28
+ } else if (obj instanceof Object) {
29
+ // Add object to visited before processing its properties
30
+ visited.add(obj);
31
+ //get object keys
32
+ objKeys = Object.keys(obj);
33
+ //set key output;
34
+ objKeys.forEach(function(key) {
35
+ const keyOut = '"' + key + '":';
36
+ const keyValOut = obj[key];
37
+ //skip functions and undefined properties
38
+ if (keyValOut instanceof Function || keyValOut === undefined) return; // Skip this entry entirely instead of pushing an empty string
39
+ else if (typeof keyValOut === 'string') arrOfKeyVals.push(keyOut + '"' + keyValOut + '"');
40
+ else if (typeof keyValOut === 'boolean' || typeof keyValOut === 'number' || keyValOut === null) arrOfKeyVals.push(keyOut + keyValOut);
41
+ else if (keyValOut instanceof Object) {
42
+ arrOfKeyVals.push(keyOut + stringifyJSON(keyValOut, visited));
43
+ }
44
+ });
45
+ return '{' + arrOfKeyVals + '}';
46
+ }
47
+ return '';
48
+ };
49
+
50
+ exports.clean = clean;
51
+ exports.stringifyJSON = stringifyJSON;
52
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2VuZXJhbC5janMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
@@ -0,0 +1,27 @@
1
+ import { ikToLKA } from '@fjell/core';
2
+
3
+ const buildAggregation = async (item, aggregationDefinition, registry)=>{
4
+ const location = ikToLKA(item.key);
5
+ // Get the library instance from the registry using the key type array
6
+ const libraryInstance = registry.get(aggregationDefinition.kta);
7
+ if (!libraryInstance) {
8
+ throw new Error(`Library instance not found for key type array: ${aggregationDefinition.kta.join(', ')}`);
9
+ }
10
+ // Based on cardinality, use either one or all operation
11
+ if (aggregationDefinition.cardinality === 'one') {
12
+ // For one-to-one relationship, use the one operation
13
+ return libraryInstance.operations.one({}, location).then((result)=>{
14
+ item[aggregationDefinition.property] = result;
15
+ return item;
16
+ });
17
+ } else {
18
+ // For one-to-many relationship, use the all operation
19
+ return libraryInstance.operations.all({}, location).then((results)=>{
20
+ item[aggregationDefinition.property] = results;
21
+ return item;
22
+ });
23
+ }
24
+ };
25
+
26
+ export { buildAggregation };
27
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQWdncmVnYXRpb25CdWlsZGVyLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
@@ -6,10 +6,10 @@ const logger = LibLogger.get("sequelize", "EventCoordinator");
6
6
  const populateEvents = (item)=>{
7
7
  const events = {
8
8
  created: {
9
- at: item.createdAt
9
+ at: item.createdAt || null
10
10
  },
11
11
  updated: {
12
- at: item.updatedAt
12
+ at: item.updatedAt || null
13
13
  },
14
14
  deleted: {
15
15
  at: null
@@ -2,15 +2,16 @@ import * as Library from '@fjell/lib';
2
2
  import { createDefinition } from './Definition.js';
3
3
  import { createOperations } from './Operations.js';
4
4
 
5
- function createInstance(keyTypes, models, libOptions = {}, scopes = []) {
5
+ function createInstance(keyTypes, models, libOptions = {}, scopes = [], registry) {
6
6
  const definition = createDefinition(keyTypes, scopes, libOptions);
7
- const operations = createOperations(models, definition);
7
+ const operations = createOperations(models, definition, registry);
8
8
  return {
9
9
  definition,
10
- operations: Library.wrapOperations(operations, definition),
11
- models
10
+ operations: Library.wrapOperations(operations, definition, registry),
11
+ models,
12
+ registry
12
13
  };
13
14
  }
14
15
 
15
16
  export { createInstance };
16
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2UuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7OyJ9
17
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2UuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
@@ -8,32 +8,33 @@ const removeKey = (item)=>{
8
8
  delete item.key;
9
9
  return item;
10
10
  };
11
- const populateKey = (item, keyTypes)=>{
12
- if (keyTypes.length === 1) {
13
- item.key = {
14
- kt: keyTypes[0],
15
- pk: item.id
16
- };
17
- delete item.id;
18
- } else if (keyTypes.length === 2) {
19
- item.key = {
20
- kt: keyTypes[0],
21
- pk: item.id,
22
- // TODO: Shouldn't this be inspecting the model to get the primary key type?
23
- loc: [
24
- {
25
- kt: keyTypes[1],
26
- lk: item[keyTypes[1] + 'Id']
27
- }
28
- ]
29
- };
30
- delete item.id;
31
- delete item[keyTypes[1] + 'Id'];
32
- } else {
33
- throw new Error('Not implemented');
34
- }
35
- return item;
36
- };
11
+ // export const populateKey = <
12
+ // S extends string,
13
+ // L1 extends string = never,
14
+ // L2 extends string = never,
15
+ // L3 extends string = never,
16
+ // L4 extends string = never,
17
+ // L5 extends string = never
18
+ // >(
19
+ // item: ItemProperties<S, L1, L2, L3, L4, L5>,
20
+ // keyTypes: AllItemTypeArrays<S, L1, L2, L3, L4, L5>
21
+ // ): ItemProperties<S, L1, L2, L3, L4, L5> => {
22
+ // if (keyTypes.length === 1) {
23
+ // item.key = { kt: keyTypes[0], pk: item.id };
24
+ // delete item.id;
25
+ // } else if (keyTypes.length === 2) {
26
+ // item.key = {
27
+ // kt: keyTypes[0], pk: item.id,
28
+ // // TODO: Shouldn't this be inspecting the model to get the primary key type?
29
+ // loc: [{ kt: keyTypes[1], lk: item[keyTypes[1] + 'Id'] }],
30
+ // };
31
+ // delete item.id;
32
+ // delete item[keyTypes[1] + 'Id'];
33
+ // } else {
34
+ // throw new Error('Not implemented');
35
+ // }
36
+ // return item;
37
+ // }
37
38
  const addKey = (item, keyTypes)=>{
38
39
  logger.default('Adding Key', {
39
40
  item
@@ -78,7 +79,8 @@ const addKey = (item, keyTypes)=>{
78
79
  Object.assign(item, {
79
80
  key
80
81
  });
82
+ return item;
81
83
  };
82
84
 
83
- export { addKey, populateKey, removeKey };
84
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiS2V5TWFzdGVyLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
85
+ export { addKey, removeKey };
86
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiS2V5TWFzdGVyLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
@@ -6,15 +6,15 @@ 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, definition)=>{
9
+ const createOperations = (models, definition, registry)=>{
10
10
  const operations = {};
11
- operations.all = getAllOperation(models, definition);
12
- operations.one = getOneOperation(models, definition);
11
+ operations.all = getAllOperation(models, definition, registry);
12
+ operations.one = getOneOperation(models, definition, registry);
13
13
  operations.create = getCreateOperation();
14
- operations.update = getUpdateOperation(models, definition);
15
- operations.get = getGetOperation(models, definition);
14
+ operations.update = getUpdateOperation(models, definition, registry);
15
+ operations.get = getGetOperation(models, definition, registry);
16
16
  operations.remove = getRemoveOperation(models, definition);
17
- operations.find = getFindOperation(models, definition);
17
+ operations.find = getFindOperation(models, definition, registry);
18
18
  operations.upsert = ()=>{
19
19
  throw new Error('Not implemented');
20
20
  };
@@ -1,19 +1,16 @@
1
1
  import * as Library from '@fjell/lib';
2
2
  import deepmerge from 'deepmerge';
3
+ import { clean } from './util/general.js';
3
4
 
4
- const defaultOptions = {
5
- deleteOnRemove: false
5
+ const DEFAULT_OPTIONS = {
6
+ deleteOnRemove: false,
7
+ references: [],
8
+ aggregations: []
6
9
  };
7
10
  const createOptions = (libOptions)=>{
8
- const defaultOptions = {
9
- deleteOnRemove: false
10
- };
11
11
  const options = Library.createOptions(libOptions);
12
- const mergedOptions = deepmerge(defaultOptions, options);
13
- return {
14
- ...mergedOptions
15
- };
12
+ return deepmerge(DEFAULT_OPTIONS, clean(options));
16
13
  };
17
14
 
18
- export { createOptions, defaultOptions };
19
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiT3B0aW9ucy5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
15
+ export { createOptions };
16
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiT3B0aW9ucy5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7In0=