@fjell/lib-sequelize 4.4.0 → 4.4.2
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 +54 -0
- package/dist/cjs/Instance.cjs +40 -0
- package/dist/cjs/KeyMaster.cjs +129 -0
- package/dist/cjs/Operations.cjs +29 -0
- package/dist/cjs/Options.cjs +39 -0
- package/dist/cjs/QueryBuilder.cjs +290 -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 +154 -0
- package/dist/cjs/ops/find.cjs +45 -0
- package/dist/cjs/ops/get.cjs +85 -0
- package/dist/cjs/ops/one.cjs +26 -0
- package/dist/cjs/ops/remove.cjs +111 -0
- package/dist/cjs/ops/update.cjs +61 -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/cjs/util/relationshipUtils.cjs +117 -0
- package/dist/es/AggregationBuilder.js +27 -0
- package/dist/es/EventCoordinator.js +48 -0
- package/dist/{Instance.js → es/Instance.js} +6 -5
- package/dist/es/KeyMaster.js +124 -0
- package/dist/{Operations.js → es/Operations.js} +8 -8
- package/dist/{Options.js → es/Options.js} +8 -11
- package/dist/{QueryBuilder.js → es/QueryBuilder.js} +123 -21
- package/dist/es/ReferenceBuilder.js +30 -0
- package/dist/es/RowProcessor.js +37 -0
- package/dist/{contained → es/contained}/Instance.js +6 -5
- package/dist/{index.js → es/index.js} +1 -1
- package/dist/{ops → es/ops}/all.js +7 -4
- package/dist/es/ops/create.js +150 -0
- package/dist/{ops → es/ops}/find.js +16 -6
- package/dist/es/ops/get.js +81 -0
- package/dist/{ops → es/ops}/one.js +2 -2
- package/dist/{ops → es/ops}/remove.js +51 -11
- package/dist/{ops → es/ops}/update.js +15 -15
- package/dist/{primary → es/primary}/Instance.js +6 -5
- package/dist/es/util/general.js +47 -0
- package/dist/es/util/relationshipUtils.js +112 -0
- package/dist/index.cjs +1279 -0
- package/dist/index.cjs.map +1 -0
- package/dist/types/AggregationBuilder.d.ts +4 -0
- package/dist/{Definition.d.ts → types/Definition.d.ts} +1 -1
- package/dist/{EventCoordinator.d.ts → types/EventCoordinator.d.ts} +1 -0
- package/dist/{Instance.d.ts → types/Instance.d.ts} +1 -1
- package/dist/types/KeyMaster.d.ts +4 -0
- package/dist/{Operations.d.ts → types/Operations.d.ts} +2 -2
- package/dist/{Options.d.ts → types/Options.d.ts} +14 -3
- package/dist/{QueryBuilder.d.ts → types/QueryBuilder.d.ts} +1 -0
- package/dist/types/ReferenceBuilder.d.ts +3 -0
- package/dist/{RowProcessor.d.ts → types/RowProcessor.d.ts} +3 -1
- package/dist/{contained → types/contained}/Instance.d.ts +2 -1
- package/dist/{ops → types/ops}/all.d.ts +2 -1
- package/dist/{ops → types/ops}/create.d.ts +3 -2
- package/dist/{ops → types/ops}/find.d.ts +2 -1
- package/dist/{ops → types/ops}/get.d.ts +2 -1
- package/dist/{ops → types/ops}/one.d.ts +2 -1
- package/dist/{ops → types/ops}/remove.d.ts +2 -1
- package/dist/{ops → types/ops}/update.d.ts +2 -1
- package/dist/{primary → types/primary}/Instance.d.ts +2 -1
- package/dist/types/util/general.d.ts +4 -0
- package/dist/types/util/relationshipUtils.d.ts +21 -0
- package/package.json +37 -32
- package/dist/EventCoordinator.js +0 -30
- package/dist/KeyMaster.d.ts +0 -4
- package/dist/KeyMaster.js +0 -84
- package/dist/RowProcessor.js +0 -18
- package/dist/ops/create.js +0 -18
- package/dist/ops/get.js +0 -45
- package/src/Coordinate.ts +0 -16
- package/src/Definition.ts +0 -49
- package/src/EventCoordinator.ts +0 -103
- package/src/Instance.ts +0 -44
- 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 -44
- 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 -40
- package/src/primary/index.ts +0 -1
- /package/dist/{Coordinate.js → es/Coordinate.js} +0 -0
- /package/dist/{Definition.js → es/Definition.js} +0 -0
- /package/dist/{contained → es/contained}/index.js +0 -0
- /package/dist/{logger.js → es/logger.js} +0 -0
- /package/dist/{primary → es/primary}/index.js +0 -0
- /package/dist/{Coordinate.d.ts → types/Coordinate.d.ts} +0 -0
- /package/dist/{contained → types/contained}/index.d.ts +0 -0
- /package/dist/{index.d.ts → types/index.d.ts} +0 -0
- /package/dist/{logger.d.ts → types/logger.d.ts} +0 -0
- /package/dist/{primary → types/primary}/index.d.ts +0 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const core = require('@fjell/core');
|
|
6
|
+
|
|
7
|
+
const buildAggregation = async (item, aggregationDefinition, registry)=>{
|
|
8
|
+
const location = core.ikToLKA(item.key);
|
|
9
|
+
// Get the library instance from the registry using the key type array
|
|
10
|
+
const libraryInstance = registry.get(aggregationDefinition.kta);
|
|
11
|
+
if (!libraryInstance) {
|
|
12
|
+
throw new Error(`Library instance not found for key type array: ${aggregationDefinition.kta.join(', ')}`);
|
|
13
|
+
}
|
|
14
|
+
// Based on cardinality, use either one or all operation
|
|
15
|
+
if (aggregationDefinition.cardinality === 'one') {
|
|
16
|
+
// For one-to-one relationship, use the one operation
|
|
17
|
+
return libraryInstance.operations.one({}, location).then((result)=>{
|
|
18
|
+
item[aggregationDefinition.property] = result;
|
|
19
|
+
return item;
|
|
20
|
+
});
|
|
21
|
+
} else {
|
|
22
|
+
// For one-to-many relationship, use the all operation
|
|
23
|
+
return libraryInstance.operations.all({}, location).then((results)=>{
|
|
24
|
+
item[aggregationDefinition.property] = results;
|
|
25
|
+
return item;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
exports.buildAggregation = buildAggregation;
|
|
31
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQWdncmVnYXRpb25CdWlsZGVyLmNqcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const Library = require('@fjell/lib');
|
|
6
|
+
|
|
7
|
+
function _interopNamespaceDefault(e) {
|
|
8
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
|
|
9
|
+
if (e) {
|
|
10
|
+
for (const k in e) {
|
|
11
|
+
if (k !== 'default') {
|
|
12
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: () => e[k]
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
n.default = e;
|
|
21
|
+
return Object.freeze(n);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const Library__namespace = /*#__PURE__*/_interopNamespaceDefault(Library);
|
|
25
|
+
|
|
26
|
+
const SCOPE_SEQUELIZE = 'sequelize';
|
|
27
|
+
const createCoordinate = (kta, scopes)=>{
|
|
28
|
+
const coordinate = Library__namespace.createCoordinate(kta, [
|
|
29
|
+
SCOPE_SEQUELIZE,
|
|
30
|
+
...scopes || []
|
|
31
|
+
]);
|
|
32
|
+
return coordinate;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
exports.SCOPE_SEQUELIZE = SCOPE_SEQUELIZE;
|
|
36
|
+
exports.createCoordinate = createCoordinate;
|
|
37
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ29vcmRpbmF0ZS5janMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const Library = require('@fjell/lib');
|
|
6
|
+
const Coordinate = require('./Coordinate.cjs');
|
|
7
|
+
const Options = require('./Options.cjs');
|
|
8
|
+
const logger$1 = require('./logger.cjs');
|
|
9
|
+
|
|
10
|
+
function _interopNamespaceDefault(e) {
|
|
11
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
|
|
12
|
+
if (e) {
|
|
13
|
+
for (const k in e) {
|
|
14
|
+
if (k !== 'default') {
|
|
15
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: () => e[k]
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
n.default = e;
|
|
24
|
+
return Object.freeze(n);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const Library__namespace = /*#__PURE__*/_interopNamespaceDefault(Library);
|
|
28
|
+
|
|
29
|
+
const logger = logger$1.default.get('lib-sequelize', 'Definition');
|
|
30
|
+
function createDefinition(kta, scopes, libOptions) {
|
|
31
|
+
logger.debug('createDefinition', {
|
|
32
|
+
kta,
|
|
33
|
+
scopes,
|
|
34
|
+
libOptions
|
|
35
|
+
});
|
|
36
|
+
const coordinate = Coordinate.createCoordinate(kta, scopes);
|
|
37
|
+
const options = Options.createOptions(libOptions);
|
|
38
|
+
const definition = Library__namespace.createDefinition(coordinate, options);
|
|
39
|
+
return {
|
|
40
|
+
...definition,
|
|
41
|
+
options
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
exports.createDefinition = createDefinition;
|
|
46
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRGVmaW5pdGlvbi5janMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
require('deepmerge');
|
|
6
|
+
const logger$1 = require('./logger.cjs');
|
|
7
|
+
|
|
8
|
+
const logger = logger$1.default.get("sequelize", "EventCoordinator");
|
|
9
|
+
//#endregion
|
|
10
|
+
const populateEvents = (item)=>{
|
|
11
|
+
const events = {
|
|
12
|
+
created: {
|
|
13
|
+
at: item.createdAt || null
|
|
14
|
+
},
|
|
15
|
+
updated: {
|
|
16
|
+
at: item.updatedAt || null
|
|
17
|
+
},
|
|
18
|
+
deleted: {
|
|
19
|
+
at: null
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
item.events = events;
|
|
23
|
+
return item;
|
|
24
|
+
};
|
|
25
|
+
const extractEvents = (item)=>{
|
|
26
|
+
logger.default('Extracting Events to database fields', {
|
|
27
|
+
item
|
|
28
|
+
});
|
|
29
|
+
if (item.events) {
|
|
30
|
+
var _item_events_created, _item_events_updated, _item_events_deleted;
|
|
31
|
+
if ((_item_events_created = item.events.created) === null || _item_events_created === void 0 ? void 0 : _item_events_created.at) {
|
|
32
|
+
item.createdAt = item.events.created.at;
|
|
33
|
+
}
|
|
34
|
+
if ((_item_events_updated = item.events.updated) === null || _item_events_updated === void 0 ? void 0 : _item_events_updated.at) {
|
|
35
|
+
item.updatedAt = item.events.updated.at;
|
|
36
|
+
}
|
|
37
|
+
if ((_item_events_deleted = item.events.deleted) === null || _item_events_deleted === void 0 ? void 0 : _item_events_deleted.at) {
|
|
38
|
+
item.deletedAt = item.events.deleted.at;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return item;
|
|
42
|
+
};
|
|
43
|
+
const removeEvents = (item)=>{
|
|
44
|
+
logger.default('Removing Events', {
|
|
45
|
+
item
|
|
46
|
+
});
|
|
47
|
+
delete item.events;
|
|
48
|
+
return item;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
exports.extractEvents = extractEvents;
|
|
52
|
+
exports.populateEvents = populateEvents;
|
|
53
|
+
exports.removeEvents = removeEvents;
|
|
54
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRXZlbnRDb29yZGluYXRvci5janMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
|
|
9
|
+
function _interopNamespaceDefault(e) {
|
|
10
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
|
|
11
|
+
if (e) {
|
|
12
|
+
for (const k in e) {
|
|
13
|
+
if (k !== 'default') {
|
|
14
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: () => e[k]
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
n.default = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const Library__namespace = /*#__PURE__*/_interopNamespaceDefault(Library);
|
|
27
|
+
|
|
28
|
+
function createInstance(keyTypes, models, libOptions = {}, scopes = [], registry) {
|
|
29
|
+
const definition = Definition.createDefinition(keyTypes, scopes, libOptions);
|
|
30
|
+
const operations = Operations.createOperations(models, definition, registry);
|
|
31
|
+
return {
|
|
32
|
+
definition,
|
|
33
|
+
operations: Library__namespace.wrapOperations(operations, definition, registry),
|
|
34
|
+
models,
|
|
35
|
+
registry
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
exports.createInstance = createInstance;
|
|
40
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2UuY2pzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const logger$1 = require('./logger.cjs');
|
|
6
|
+
const relationshipUtils = require('./util/relationshipUtils.cjs');
|
|
7
|
+
|
|
8
|
+
const logger = logger$1.default.get('sequelize', 'KeyMaster');
|
|
9
|
+
// Helper function to extract location key value from item
|
|
10
|
+
const extractLocationKeyValue = (model, item, locatorType, kta)=>{
|
|
11
|
+
logger.default('Extracting location key value', {
|
|
12
|
+
locatorType,
|
|
13
|
+
kta
|
|
14
|
+
});
|
|
15
|
+
const relationshipInfo = relationshipUtils.buildRelationshipPath(model, locatorType, kta, true);
|
|
16
|
+
if (!relationshipInfo.found) {
|
|
17
|
+
throw new Error(`Location key '${locatorType}' cannot be resolved on model '${model.name}' or through its relationships.`);
|
|
18
|
+
}
|
|
19
|
+
if (relationshipInfo.isDirect) {
|
|
20
|
+
// Direct foreign key field
|
|
21
|
+
const foreignKeyField = `${locatorType}Id`;
|
|
22
|
+
const value = item[foreignKeyField];
|
|
23
|
+
if (typeof value === 'undefined' || value === null) {
|
|
24
|
+
throw new Error(`Direct foreign key field '${foreignKeyField}' is missing or null in item`);
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
} else {
|
|
28
|
+
// Need to traverse relationship
|
|
29
|
+
// Try to get the value from the loaded relationship object
|
|
30
|
+
const relationshipObject = item[locatorType];
|
|
31
|
+
if (relationshipObject && typeof relationshipObject.id !== 'undefined') {
|
|
32
|
+
return relationshipObject.id;
|
|
33
|
+
}
|
|
34
|
+
// If the relationship object isn't loaded, we might need to look at the foreign key field
|
|
35
|
+
// This handles cases where we have the foreign key but not the full object
|
|
36
|
+
const foreignKeyField = `${locatorType}Id`;
|
|
37
|
+
if (typeof item[foreignKeyField] !== 'undefined' && item[foreignKeyField] !== null) {
|
|
38
|
+
return item[foreignKeyField];
|
|
39
|
+
}
|
|
40
|
+
throw new Error(`Unable to extract location key for '${locatorType}'. Neither the relationship object nor direct foreign key is available.`);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const removeKey = (item)=>{
|
|
44
|
+
logger.default('Removing Key', {
|
|
45
|
+
item
|
|
46
|
+
});
|
|
47
|
+
delete item.key;
|
|
48
|
+
return item;
|
|
49
|
+
};
|
|
50
|
+
// export const populateKey = <
|
|
51
|
+
// S extends string,
|
|
52
|
+
// L1 extends string = never,
|
|
53
|
+
// L2 extends string = never,
|
|
54
|
+
// L3 extends string = never,
|
|
55
|
+
// L4 extends string = never,
|
|
56
|
+
// L5 extends string = never
|
|
57
|
+
// >(
|
|
58
|
+
// item: ItemProperties<S, L1, L2, L3, L4, L5>,
|
|
59
|
+
// keyTypes: AllItemTypeArrays<S, L1, L2, L3, L4, L5>
|
|
60
|
+
// ): ItemProperties<S, L1, L2, L3, L4, L5> => {
|
|
61
|
+
// if (keyTypes.length === 1) {
|
|
62
|
+
// item.key = { kt: keyTypes[0], pk: item.id };
|
|
63
|
+
// delete item.id;
|
|
64
|
+
// } else if (keyTypes.length === 2) {
|
|
65
|
+
// item.key = {
|
|
66
|
+
// kt: keyTypes[0], pk: item.id,
|
|
67
|
+
// // TODO: Shouldn't this be inspecting the model to get the primary key type?
|
|
68
|
+
// loc: [{ kt: keyTypes[1], lk: item[keyTypes[1] + 'Id'] }],
|
|
69
|
+
// };
|
|
70
|
+
// delete item.id;
|
|
71
|
+
// delete item[keyTypes[1] + 'Id'];
|
|
72
|
+
// } else {
|
|
73
|
+
// throw new Error('Not implemented');
|
|
74
|
+
// }
|
|
75
|
+
// return item;
|
|
76
|
+
// }
|
|
77
|
+
const addKey = (model, item, keyTypes)=>{
|
|
78
|
+
logger.default('Adding Key', {
|
|
79
|
+
item
|
|
80
|
+
});
|
|
81
|
+
const key = {};
|
|
82
|
+
const modelClass = model.constructor;
|
|
83
|
+
const primaryKeyAttr = modelClass.primaryKeyAttribute;
|
|
84
|
+
if (Array.isArray(keyTypes) && keyTypes.length > 1) {
|
|
85
|
+
const type = [
|
|
86
|
+
...keyTypes
|
|
87
|
+
];
|
|
88
|
+
const pkType = type.shift();
|
|
89
|
+
Object.assign(key, {
|
|
90
|
+
kt: pkType,
|
|
91
|
+
pk: item[primaryKeyAttr]
|
|
92
|
+
});
|
|
93
|
+
// Build location keys for composite key
|
|
94
|
+
const locationKeys = [];
|
|
95
|
+
for (const locatorType of type){
|
|
96
|
+
try {
|
|
97
|
+
const lk = extractLocationKeyValue(modelClass, item, locatorType, keyTypes);
|
|
98
|
+
locationKeys.push({
|
|
99
|
+
kt: locatorType,
|
|
100
|
+
lk
|
|
101
|
+
});
|
|
102
|
+
} catch (error) {
|
|
103
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
104
|
+
logger.error(`Failed to extract location key for '${locatorType}'`, {
|
|
105
|
+
error: errorMessage,
|
|
106
|
+
item,
|
|
107
|
+
keyTypes
|
|
108
|
+
});
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
Object.assign(key, {
|
|
113
|
+
loc: locationKeys
|
|
114
|
+
});
|
|
115
|
+
} else {
|
|
116
|
+
Object.assign(key, {
|
|
117
|
+
kt: keyTypes[0],
|
|
118
|
+
pk: item[primaryKeyAttr]
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
Object.assign(item, {
|
|
122
|
+
key
|
|
123
|
+
});
|
|
124
|
+
return item;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
exports.addKey = addKey;
|
|
128
|
+
exports.removeKey = removeKey;
|
|
129
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiS2V5TWFzdGVyLmNqcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const all = require('./ops/all.cjs');
|
|
6
|
+
const create = require('./ops/create.cjs');
|
|
7
|
+
const find = require('./ops/find.cjs');
|
|
8
|
+
const get = require('./ops/get.cjs');
|
|
9
|
+
const one = require('./ops/one.cjs');
|
|
10
|
+
const remove = require('./ops/remove.cjs');
|
|
11
|
+
const update = require('./ops/update.cjs');
|
|
12
|
+
|
|
13
|
+
const createOperations = (models, definition, registry)=>{
|
|
14
|
+
const operations = {};
|
|
15
|
+
operations.all = all.getAllOperation(models, definition, registry);
|
|
16
|
+
operations.one = one.getOneOperation(models, definition, registry);
|
|
17
|
+
operations.create = create.getCreateOperation(models, definition, registry);
|
|
18
|
+
operations.update = update.getUpdateOperation(models, definition, registry);
|
|
19
|
+
operations.get = get.getGetOperation(models, definition, registry);
|
|
20
|
+
operations.remove = remove.getRemoveOperation(models, definition);
|
|
21
|
+
operations.find = find.getFindOperation(models, definition, registry);
|
|
22
|
+
operations.upsert = async ()=>{
|
|
23
|
+
throw new Error('Not implemented');
|
|
24
|
+
};
|
|
25
|
+
return operations;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
exports.createOperations = createOperations;
|
|
29
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiT3BlcmF0aW9ucy5janMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const Library = require('@fjell/lib');
|
|
6
|
+
const deepmerge = require('deepmerge');
|
|
7
|
+
const general = require('./util/general.cjs');
|
|
8
|
+
|
|
9
|
+
function _interopNamespaceDefault(e) {
|
|
10
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
|
|
11
|
+
if (e) {
|
|
12
|
+
for (const k in e) {
|
|
13
|
+
if (k !== 'default') {
|
|
14
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: () => e[k]
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
n.default = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const Library__namespace = /*#__PURE__*/_interopNamespaceDefault(Library);
|
|
27
|
+
|
|
28
|
+
const DEFAULT_OPTIONS = {
|
|
29
|
+
deleteOnRemove: false,
|
|
30
|
+
references: [],
|
|
31
|
+
aggregations: []
|
|
32
|
+
};
|
|
33
|
+
const createOptions = (libOptions)=>{
|
|
34
|
+
const options = Library__namespace.createOptions(libOptions);
|
|
35
|
+
return deepmerge(DEFAULT_OPTIONS, general.clean(options));
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.createOptions = createOptions;
|
|
39
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiT3B0aW9ucy5janMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
|