@fjell/lib-sequelize 4.3.4 → 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.
- package/dist/cjs/AggregationBuilder.cjs +31 -0
- package/dist/cjs/Coordinate.cjs +37 -0
- package/dist/cjs/Definition.cjs +46 -0
- package/dist/cjs/EventCoordinator.cjs +35 -0
- package/dist/cjs/Instance.cjs +40 -0
- package/dist/cjs/KeyMaster.cjs +91 -0
- package/dist/cjs/Operations.cjs +29 -0
- package/dist/cjs/Options.cjs +39 -0
- package/dist/cjs/QueryBuilder.cjs +188 -0
- package/dist/cjs/ReferenceBuilder.cjs +34 -0
- package/dist/cjs/RowProcessor.cjs +41 -0
- package/dist/cjs/contained/Instance.cjs +21 -0
- package/dist/cjs/contained/index.cjs +10 -0
- package/dist/cjs/index.cjs +23 -0
- package/dist/cjs/logger.cjs +10 -0
- package/dist/cjs/ops/all.cjs +62 -0
- package/dist/cjs/ops/create.cjs +23 -0
- package/dist/cjs/ops/find.cjs +45 -0
- package/dist/cjs/ops/get.cjs +49 -0
- package/dist/cjs/ops/one.cjs +26 -0
- package/dist/cjs/ops/remove.cjs +72 -0
- package/dist/cjs/ops/update.cjs +59 -0
- package/dist/cjs/primary/Instance.cjs +31 -0
- package/dist/cjs/primary/index.cjs +10 -0
- package/dist/cjs/util/general.cjs +52 -0
- package/dist/es/AggregationBuilder.js +27 -0
- package/dist/es/Coordinate.js +13 -0
- package/dist/es/Definition.js +23 -0
- package/dist/es/EventCoordinator.js +30 -0
- package/dist/es/Instance.js +17 -0
- package/dist/es/KeyMaster.js +86 -0
- package/dist/es/Operations.js +25 -0
- package/dist/es/Options.js +16 -0
- package/dist/{src → es}/QueryBuilder.js +67 -46
- package/dist/es/ReferenceBuilder.js +30 -0
- package/dist/es/RowProcessor.js +37 -0
- package/dist/es/contained/Instance.js +17 -0
- package/dist/es/contained/index.js +2 -0
- package/dist/es/index.js +10 -0
- package/dist/es/logger.js +6 -0
- package/dist/{src → es}/ops/all.js +25 -14
- package/dist/es/ops/create.js +19 -0
- package/dist/es/ops/find.js +41 -0
- package/dist/es/ops/get.js +45 -0
- package/dist/es/ops/one.js +22 -0
- package/dist/es/ops/remove.js +68 -0
- package/dist/es/ops/update.js +55 -0
- package/dist/es/primary/Instance.js +27 -0
- package/dist/es/primary/index.js +2 -0
- package/dist/es/util/general.js +47 -0
- package/dist/index.cjs +810 -0
- package/dist/index.cjs.map +1 -0
- package/dist/types/AggregationBuilder.d.ts +4 -0
- package/dist/{src → types}/Definition.d.ts +2 -2
- package/dist/{src → types}/Instance.d.ts +2 -2
- package/dist/{src → types}/KeyMaster.d.ts +1 -2
- package/dist/{src → types}/Operations.d.ts +4 -4
- package/dist/{src → types}/Options.d.ts +15 -4
- package/dist/types/ReferenceBuilder.d.ts +3 -0
- package/dist/types/RowProcessor.d.ts +5 -0
- package/dist/{src → types}/contained/Instance.d.ts +2 -1
- package/dist/types/logger.d.ts +2 -0
- package/dist/types/ops/all.d.ts +5 -0
- package/dist/{src → types}/ops/create.d.ts +5 -4
- package/dist/types/ops/find.d.ts +5 -0
- package/dist/{src → types}/ops/get.d.ts +2 -1
- package/dist/types/ops/one.d.ts +5 -0
- package/dist/types/ops/remove.d.ts +5 -0
- package/dist/types/ops/update.d.ts +5 -0
- package/dist/{src → types}/primary/Instance.d.ts +2 -1
- package/dist/types/util/general.d.ts +4 -0
- package/package.json +45 -35
- package/dist/src/Coordinate.js +0 -7
- package/dist/src/Coordinate.js.map +0 -1
- package/dist/src/Definition.js +0 -16
- package/dist/src/Definition.js.map +0 -1
- package/dist/src/EventCoordinator.js +0 -56
- package/dist/src/EventCoordinator.js.map +0 -1
- package/dist/src/Instance.js +0 -14
- package/dist/src/Instance.js.map +0 -1
- package/dist/src/KeyMaster.js +0 -58
- package/dist/src/KeyMaster.js.map +0 -1
- package/dist/src/Operations.js +0 -22
- package/dist/src/Operations.js.map +0 -1
- package/dist/src/Options.js +0 -16
- package/dist/src/Options.js.map +0 -1
- package/dist/src/QueryBuilder.js.map +0 -1
- package/dist/src/RowProcessor.d.ts +0 -3
- package/dist/src/RowProcessor.js +0 -11
- package/dist/src/RowProcessor.js.map +0 -1
- package/dist/src/contained/Instance.js +0 -14
- package/dist/src/contained/Instance.js.map +0 -1
- package/dist/src/contained/index.js +0 -2
- package/dist/src/contained/index.js.map +0 -1
- package/dist/src/index.js +0 -8
- package/dist/src/index.js.map +0 -1
- package/dist/src/logger.d.ts +0 -2
- package/dist/src/logger.js +0 -4
- package/dist/src/logger.js.map +0 -1
- package/dist/src/ops/all.d.ts +0 -4
- package/dist/src/ops/all.js.map +0 -1
- package/dist/src/ops/create.js +0 -14
- package/dist/src/ops/create.js.map +0 -1
- package/dist/src/ops/find.d.ts +0 -4
- package/dist/src/ops/find.js +0 -26
- package/dist/src/ops/find.js.map +0 -1
- package/dist/src/ops/get.js +0 -36
- package/dist/src/ops/get.js.map +0 -1
- package/dist/src/ops/one.d.ts +0 -4
- package/dist/src/ops/one.js +0 -17
- package/dist/src/ops/one.js.map +0 -1
- package/dist/src/ops/remove.d.ts +0 -5
- package/dist/src/ops/remove.js +0 -56
- package/dist/src/ops/remove.js.map +0 -1
- package/dist/src/ops/update.d.ts +0 -4
- package/dist/src/ops/update.js +0 -49
- package/dist/src/ops/update.js.map +0 -1
- package/dist/src/primary/Instance.js +0 -17
- package/dist/src/primary/Instance.js.map +0 -1
- package/dist/src/primary/index.js +0 -2
- package/dist/src/primary/index.js.map +0 -1
- package/eslint.config.mjs +0 -70
- package/src/Coordinate.ts +0 -16
- package/src/Definition.ts +0 -49
- package/src/EventCoordinator.ts +0 -103
- package/src/Instance.ts +0 -45
- package/src/KeyMaster.ts +0 -90
- package/src/Operations.ts +0 -42
- package/src/Options.ts +0 -41
- package/src/QueryBuilder.ts +0 -208
- package/src/RowProcessor.ts +0 -23
- package/src/contained/Instance.ts +0 -45
- package/src/contained/index.ts +0 -1
- package/src/index.ts +0 -7
- package/src/logger.ts +0 -5
- package/src/ops/all.ts +0 -76
- package/src/ops/create.ts +0 -40
- package/src/ops/find.ts +0 -49
- package/src/ops/get.ts +0 -67
- package/src/ops/one.ts +0 -37
- package/src/ops/remove.ts +0 -81
- package/src/ops/update.ts +0 -78
- package/src/primary/Instance.ts +0 -41
- package/src/primary/index.ts +0 -1
- /package/dist/{src → types}/Coordinate.d.ts +0 -0
- /package/dist/{src → types}/EventCoordinator.d.ts +0 -0
- /package/dist/{src → types}/QueryBuilder.d.ts +0 -0
- /package/dist/{src → types}/contained/index.d.ts +0 -0
- /package/dist/{src → types}/index.d.ts +0 -0
- /package/dist/{src → 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
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as Library from '@fjell/lib';
|
|
2
|
+
|
|
3
|
+
const SCOPE_SEQUELIZE = 'sequelize';
|
|
4
|
+
const createCoordinate = (kta, scopes)=>{
|
|
5
|
+
const coordinate = Library.createCoordinate(kta, [
|
|
6
|
+
SCOPE_SEQUELIZE,
|
|
7
|
+
...scopes || []
|
|
8
|
+
]);
|
|
9
|
+
return coordinate;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { SCOPE_SEQUELIZE, createCoordinate };
|
|
13
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ29vcmRpbmF0ZS5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7In0=
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as Library from '@fjell/lib';
|
|
2
|
+
import { createCoordinate } from './Coordinate.js';
|
|
3
|
+
import { createOptions } from './Options.js';
|
|
4
|
+
import LibLogger from './logger.js';
|
|
5
|
+
|
|
6
|
+
const logger = LibLogger.get('lib-sequelize', 'Definition');
|
|
7
|
+
function createDefinition(kta, scopes, libOptions) {
|
|
8
|
+
logger.debug('createDefinition', {
|
|
9
|
+
kta,
|
|
10
|
+
scopes,
|
|
11
|
+
libOptions
|
|
12
|
+
});
|
|
13
|
+
const coordinate = createCoordinate(kta, scopes);
|
|
14
|
+
const options = createOptions(libOptions);
|
|
15
|
+
const definition = Library.createDefinition(coordinate, options);
|
|
16
|
+
return {
|
|
17
|
+
...definition,
|
|
18
|
+
options
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { createDefinition };
|
|
23
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRGVmaW5pdGlvbi5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
|
@@ -0,0 +1,30 @@
|
|
|
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 removeEvents = (item)=>{
|
|
22
|
+
logger.default('Removing Events', {
|
|
23
|
+
item
|
|
24
|
+
});
|
|
25
|
+
delete item.events;
|
|
26
|
+
return item;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { populateEvents, removeEvents };
|
|
30
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRXZlbnRDb29yZGluYXRvci5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as Library from '@fjell/lib';
|
|
2
|
+
import { createDefinition } from './Definition.js';
|
|
3
|
+
import { createOperations } from './Operations.js';
|
|
4
|
+
|
|
5
|
+
function createInstance(keyTypes, models, libOptions = {}, scopes = [], registry) {
|
|
6
|
+
const definition = createDefinition(keyTypes, scopes, libOptions);
|
|
7
|
+
const operations = createOperations(models, definition, registry);
|
|
8
|
+
return {
|
|
9
|
+
definition,
|
|
10
|
+
operations: Library.wrapOperations(operations, definition, registry),
|
|
11
|
+
models,
|
|
12
|
+
registry
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { createInstance };
|
|
17
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2UuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import LibLogger from './logger.js';
|
|
2
|
+
|
|
3
|
+
const logger = LibLogger.get('sequelize', 'KeyMaster');
|
|
4
|
+
const removeKey = (item)=>{
|
|
5
|
+
logger.default('Removing Key', {
|
|
6
|
+
item
|
|
7
|
+
});
|
|
8
|
+
delete item.key;
|
|
9
|
+
return item;
|
|
10
|
+
};
|
|
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
|
+
// }
|
|
38
|
+
const addKey = (item, keyTypes)=>{
|
|
39
|
+
logger.default('Adding Key', {
|
|
40
|
+
item
|
|
41
|
+
});
|
|
42
|
+
const key = {};
|
|
43
|
+
if (Array.isArray(keyTypes) && keyTypes.length > 1) {
|
|
44
|
+
const type = [
|
|
45
|
+
...keyTypes
|
|
46
|
+
];
|
|
47
|
+
const pkType = type.shift();
|
|
48
|
+
Object.assign(key, {
|
|
49
|
+
kt: pkType,
|
|
50
|
+
pk: item.id
|
|
51
|
+
});
|
|
52
|
+
// TODO: This is really just for primary items
|
|
53
|
+
if (type.length === 1) {
|
|
54
|
+
// TODO: This should be looking at the model to get the primary key of the reference item or association
|
|
55
|
+
const locKeyTypeId = type[0] + 'Id';
|
|
56
|
+
Object.assign(key, {
|
|
57
|
+
loc: [
|
|
58
|
+
{
|
|
59
|
+
kt: type[0],
|
|
60
|
+
lk: item[locKeyTypeId]
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
});
|
|
64
|
+
} else if (type.length === 2) {
|
|
65
|
+
throw new Error('Not implemented');
|
|
66
|
+
} else if (type.length === 3) {
|
|
67
|
+
throw new Error('Not implemented');
|
|
68
|
+
} else if (type.length === 4) {
|
|
69
|
+
throw new Error('Not implemented');
|
|
70
|
+
} else if (type.length === 5) {
|
|
71
|
+
throw new Error('Not implemented');
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
Object.assign(key, {
|
|
75
|
+
kt: keyTypes[0],
|
|
76
|
+
pk: item.id
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
Object.assign(item, {
|
|
80
|
+
key
|
|
81
|
+
});
|
|
82
|
+
return item;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export { addKey, removeKey };
|
|
86
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiS2V5TWFzdGVyLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
|