@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.
- 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/{EventCoordinator.js → es/EventCoordinator.js} +2 -2
- package/dist/{Instance.js → es/Instance.js} +6 -5
- package/dist/{KeyMaster.js → es/KeyMaster.js} +30 -28
- package/dist/{Operations.js → es/Operations.js} +6 -6
- package/dist/{Options.js → es/Options.js} +8 -11
- 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/{ops → es/ops}/create.js +3 -2
- package/dist/{ops → es/ops}/find.js +16 -6
- package/dist/{ops → es/ops}/get.js +3 -3
- package/dist/{ops → es/ops}/one.js +2 -2
- package/dist/{ops → es/ops}/remove.js +6 -5
- package/dist/{ops → es/ops}/update.js +13 -15
- package/dist/{primary → es/primary}/Instance.js +6 -5
- 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/{Definition.d.ts → types/Definition.d.ts} +1 -1
- package/dist/{Instance.d.ts → types/Instance.d.ts} +1 -1
- package/dist/{KeyMaster.d.ts → types/KeyMaster.d.ts} +1 -2
- package/dist/{Operations.d.ts → types/Operations.d.ts} +2 -2
- package/dist/{Options.d.ts → types/Options.d.ts} +14 -3
- 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 +2 -1
- 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/package.json +36 -31
- package/dist/RowProcessor.js +0 -18
- 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/{QueryBuilder.js → es/QueryBuilder.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/{EventCoordinator.d.ts → types/EventCoordinator.d.ts} +0 -0
- /package/dist/{QueryBuilder.d.ts → types/QueryBuilder.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,30 @@
|
|
|
1
|
+
const buildReference = async (item, referenceDefinition, registry)=>{
|
|
2
|
+
// Check if there is more than one key type
|
|
3
|
+
if (referenceDefinition.kta.length > 1) {
|
|
4
|
+
throw new Error("The ReferenceBuilder doesn't work with more than one key type yet");
|
|
5
|
+
}
|
|
6
|
+
// Check if dependencies exist
|
|
7
|
+
if (!registry) {
|
|
8
|
+
throw new Error("This model definition has a reference definition, but the registry is not present");
|
|
9
|
+
}
|
|
10
|
+
// Find the Library.Instance for the key type
|
|
11
|
+
const library = registry.get(referenceDefinition.kta);
|
|
12
|
+
if (!library) {
|
|
13
|
+
throw new Error("This model definition has a reference definition, but the dependency is not present");
|
|
14
|
+
}
|
|
15
|
+
// Create a PriKey using the column value from item
|
|
16
|
+
const priKey = {
|
|
17
|
+
kt: referenceDefinition.kta[0],
|
|
18
|
+
pk: item[referenceDefinition.column]
|
|
19
|
+
};
|
|
20
|
+
// Get the referenced item using the Library.Operations get method
|
|
21
|
+
const referencedItem = await library.operations.get(priKey);
|
|
22
|
+
// TODO: In a Fjell-compliant implementation, this value should be stored in the ref property
|
|
23
|
+
// For now, we'll just populate the property directly
|
|
24
|
+
// Store the result in the property on item
|
|
25
|
+
item[referenceDefinition.property] = referencedItem;
|
|
26
|
+
return item;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { buildReference };
|
|
30
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUmVmZXJlbmNlQnVpbGRlci5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import LibLogger from './logger.js';
|
|
2
|
+
import { addKey } from './KeyMaster.js';
|
|
3
|
+
import { buildReference } from './ReferenceBuilder.js';
|
|
4
|
+
import { buildAggregation } from './AggregationBuilder.js';
|
|
5
|
+
import { stringifyJSON } from './util/general.js';
|
|
6
|
+
import { populateEvents } from './EventCoordinator.js';
|
|
7
|
+
|
|
8
|
+
const logger = LibLogger.get('sequelize', 'RowProcessor');
|
|
9
|
+
const processRow = async (row, keyTypes, referenceDefinitions, aggregationDefinitions, registry)=>{
|
|
10
|
+
logger.default('Processing Row', {
|
|
11
|
+
row
|
|
12
|
+
});
|
|
13
|
+
let item = row.get({
|
|
14
|
+
plain: true
|
|
15
|
+
});
|
|
16
|
+
logger.default('Adding Key to Item with Key Types: %s', stringifyJSON(keyTypes));
|
|
17
|
+
item = addKey(item, keyTypes);
|
|
18
|
+
item = populateEvents(item);
|
|
19
|
+
logger.default('Key Added to Item: %s', stringifyJSON(item.key));
|
|
20
|
+
if (referenceDefinitions && referenceDefinitions.length > 0) {
|
|
21
|
+
for (const referenceDefinition of referenceDefinitions){
|
|
22
|
+
logger.default('Processing Reference for %s to %s', item.key.kt, stringifyJSON(referenceDefinition.kta));
|
|
23
|
+
item = await buildReference(item, referenceDefinition, registry);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (aggregationDefinitions && aggregationDefinitions.length > 0) {
|
|
27
|
+
for (const aggregationDefinition of aggregationDefinitions){
|
|
28
|
+
logger.default('Processing Aggregation for %s from %s', item.key.kt, stringifyJSON(aggregationDefinition.kta));
|
|
29
|
+
item = await buildAggregation(item, aggregationDefinition, registry);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
logger.default('Processed Row: %j', stringifyJSON(item));
|
|
33
|
+
return item;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { processRow };
|
|
37
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUm93UHJvY2Vzc29yLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
|
@@ -2,15 +2,16 @@ import { Contained } 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: Contained.wrapOperations(operations, definition),
|
|
11
|
-
models
|
|
10
|
+
operations: Contained.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,
|
|
17
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2UuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { SCOPE_SEQUELIZE, createCoordinate } from './Coordinate.js';
|
|
2
2
|
export { createDefinition } from './Definition.js';
|
|
3
3
|
export { createInstance } from './Instance.js';
|
|
4
|
-
export { createOptions
|
|
4
|
+
export { createOptions } from './Options.js';
|
|
5
5
|
export { createOperations } from './Operations.js';
|
|
6
6
|
import * as index from './contained/index.js';
|
|
7
7
|
export { index as Contained };
|
|
@@ -5,8 +5,8 @@ import { processRow } from '../RowProcessor.js';
|
|
|
5
5
|
import { Op } from 'sequelize';
|
|
6
6
|
|
|
7
7
|
const logger = LibLogger.get('sequelize', 'ops', 'all');
|
|
8
|
-
const getAllOperation = (models, definition)=>{
|
|
9
|
-
const { coordinate } = definition;
|
|
8
|
+
const getAllOperation = (models, definition, registry)=>{
|
|
9
|
+
const { coordinate, options: { references, aggregations } } = definition;
|
|
10
10
|
//#region Query
|
|
11
11
|
const all = async (itemQuery, locations)=>{
|
|
12
12
|
logger.default('All', {
|
|
@@ -46,10 +46,13 @@ const getAllOperation = (models, definition)=>{
|
|
|
46
46
|
const matchingItems = await model.findAll(options);
|
|
47
47
|
// this.logger.default('Matching Items', { matchingItems });
|
|
48
48
|
// TODO: Move this Up!
|
|
49
|
-
return matchingItems.map((row)=>
|
|
49
|
+
return await Promise.all(matchingItems.map(async (row)=>{
|
|
50
|
+
const processedRow = await processRow(row, coordinate.kta, references, aggregations, registry);
|
|
51
|
+
return validateKeys(processedRow, coordinate.kta);
|
|
52
|
+
}));
|
|
50
53
|
};
|
|
51
54
|
return all;
|
|
52
55
|
};
|
|
53
56
|
|
|
54
57
|
export { getAllOperation };
|
|
55
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
58
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWxsLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
|
@@ -3,7 +3,8 @@ import LibLogger from '../logger.js';
|
|
|
3
3
|
const logger = LibLogger.get('sequelize', 'ops', 'create');
|
|
4
4
|
const getCreateOperation = (// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5
5
|
models, // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
|
-
definition
|
|
6
|
+
definition, // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
7
|
+
registry)=>{
|
|
7
8
|
const create = async (item, options)=>{
|
|
8
9
|
logger.default('Create', {
|
|
9
10
|
item,
|
|
@@ -15,4 +16,4 @@ definition)=>{
|
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
export { getCreateOperation };
|
|
18
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
19
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3JlYXRlLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { validateKeys } from '@fjell/core';
|
|
1
2
|
import LibLogger from '../logger.js';
|
|
3
|
+
import { processRow } from '../RowProcessor.js';
|
|
2
4
|
|
|
3
5
|
const logger = LibLogger.get('sequelize', 'ops', 'find');
|
|
4
|
-
const getFindOperation = (models, definition)=>{
|
|
5
|
-
const { options } = definition;
|
|
6
|
+
const getFindOperation = (models, definition, registry)=>{
|
|
7
|
+
const { options: { finders, references, aggregations } } = definition;
|
|
6
8
|
const find = async (finder, finderParams, locations)=>{
|
|
7
9
|
logger.default('Find', {
|
|
8
10
|
finder,
|
|
@@ -11,10 +13,18 @@ const getFindOperation = (models, definition)=>{
|
|
|
11
13
|
});
|
|
12
14
|
// Note that we execute the createFinders function here because we want to make sure we're always getting the
|
|
13
15
|
// most up to date methods.
|
|
14
|
-
if (
|
|
15
|
-
const finderMethod =
|
|
16
|
+
if (finders && finders[finder]) {
|
|
17
|
+
const finderMethod = finders[finder];
|
|
16
18
|
if (finderMethod) {
|
|
17
|
-
|
|
19
|
+
const results = await finderMethod(finderParams, locations);
|
|
20
|
+
if (results && results.length > 0) {
|
|
21
|
+
return await Promise.all(results.map(async (row)=>{
|
|
22
|
+
const processedRow = await processRow(row, definition.coordinate.kta, references, aggregations, registry);
|
|
23
|
+
return validateKeys(processedRow, definition.coordinate.kta);
|
|
24
|
+
}));
|
|
25
|
+
} else {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
18
28
|
} else {
|
|
19
29
|
logger.error(`Finder %s not found`, finder);
|
|
20
30
|
throw new Error(`Finder ${finder} not found`);
|
|
@@ -28,4 +38,4 @@ const getFindOperation = (models, definition)=>{
|
|
|
28
38
|
};
|
|
29
39
|
|
|
30
40
|
export { getFindOperation };
|
|
31
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
41
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmluZC5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
|
@@ -4,8 +4,8 @@ import { processRow } from '../RowProcessor.js';
|
|
|
4
4
|
import { NotFoundError } from '@fjell/lib';
|
|
5
5
|
|
|
6
6
|
const logger = LibLogger.get('sequelize', 'ops', 'get');
|
|
7
|
-
const getGetOperation = (models, definition)=>{
|
|
8
|
-
const { coordinate } = definition;
|
|
7
|
+
const getGetOperation = (models, definition, registry)=>{
|
|
8
|
+
const { coordinate, options: { references, aggregations } } = definition;
|
|
9
9
|
const { kta } = coordinate;
|
|
10
10
|
const get = async (key)=>{
|
|
11
11
|
logger.default('Get', {
|
|
@@ -35,7 +35,7 @@ const getGetOperation = (models, definition)=>{
|
|
|
35
35
|
if (!item) {
|
|
36
36
|
throw new NotFoundError('get', coordinate, key);
|
|
37
37
|
} else {
|
|
38
|
-
return validateKeys(processRow(item, kta), kta);
|
|
38
|
+
return validateKeys(await processRow(item, kta, references, aggregations, registry), kta);
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
return get;
|
|
@@ -2,13 +2,13 @@ import LibLogger from '../logger.js';
|
|
|
2
2
|
import { getAllOperation } from './all.js';
|
|
3
3
|
|
|
4
4
|
const logger = LibLogger.get('sequelize', 'ops', 'one');
|
|
5
|
-
const getOneOperation = (models, definition)=>{
|
|
5
|
+
const getOneOperation = (models, definition, registry)=>{
|
|
6
6
|
const one = async (itemQuery, locations = [])=>{
|
|
7
7
|
logger.default('One', {
|
|
8
8
|
itemQuery,
|
|
9
9
|
locations
|
|
10
10
|
});
|
|
11
|
-
const items = await getAllOperation(models, definition)(itemQuery, locations);
|
|
11
|
+
const items = await getAllOperation(models, definition, registry)(itemQuery, locations);
|
|
12
12
|
if (items.length > 0) {
|
|
13
13
|
return items[0];
|
|
14
14
|
} else {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { isValidItemKey, abbrevIK, isPriKey, isComKey } from '@fjell/core';
|
|
2
2
|
import { populateEvents } from '../EventCoordinator.js';
|
|
3
|
-
import {
|
|
3
|
+
import { addKey } from '../KeyMaster.js';
|
|
4
4
|
import LibLogger from '../logger.js';
|
|
5
5
|
|
|
6
6
|
const logger = LibLogger.get('sequelize', 'ops', 'remove');
|
|
7
|
-
const getRemoveOperation = (models, definition
|
|
7
|
+
const getRemoveOperation = (models, definition, // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8
|
+
registry)=>{
|
|
8
9
|
const { coordinate, options } = definition;
|
|
9
10
|
const { kta } = coordinate;
|
|
10
11
|
const remove = async (key)=>{
|
|
@@ -46,14 +47,14 @@ const getRemoveOperation = (models, definition)=>{
|
|
|
46
47
|
returnItem = item === null || item === void 0 ? void 0 : item.get({
|
|
47
48
|
plain: true
|
|
48
49
|
});
|
|
49
|
-
returnItem =
|
|
50
|
+
returnItem = addKey(returnItem, kta);
|
|
50
51
|
returnItem = populateEvents(returnItem);
|
|
51
52
|
} else if (options.deleteOnRemove) {
|
|
52
53
|
await (item === null || item === void 0 ? void 0 : item.destroy());
|
|
53
54
|
returnItem = item === null || item === void 0 ? void 0 : item.get({
|
|
54
55
|
plain: true
|
|
55
56
|
});
|
|
56
|
-
returnItem =
|
|
57
|
+
returnItem = addKey(returnItem, kta);
|
|
57
58
|
returnItem = populateEvents(returnItem);
|
|
58
59
|
} else {
|
|
59
60
|
throw new Error('No deletedAt or isDeleted attribute found in model, and deleteOnRemove is not set');
|
|
@@ -64,4 +65,4 @@ const getRemoveOperation = (models, definition)=>{
|
|
|
64
65
|
};
|
|
65
66
|
|
|
66
67
|
export { getRemoveOperation };
|
|
67
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
68
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVtb3ZlLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { abbrevIK, isPriKey, isComKey } from '@fjell/core';
|
|
2
|
-
import { removeEvents
|
|
3
|
-
import { removeKey
|
|
1
|
+
import { abbrevIK, isPriKey, isComKey, validateKeys } from '@fjell/core';
|
|
2
|
+
import { removeEvents } from '../EventCoordinator.js';
|
|
3
|
+
import { removeKey } from '../KeyMaster.js';
|
|
4
4
|
import LibLogger from '../logger.js';
|
|
5
|
+
import { processRow } from '../RowProcessor.js';
|
|
6
|
+
import { stringifyJSON } from '../util/general.js';
|
|
5
7
|
import { NotFoundError } from '@fjell/lib';
|
|
6
8
|
|
|
7
9
|
const logger = LibLogger.get('sequelize', 'ops', 'update');
|
|
8
|
-
const getUpdateOperation = (models, definition)=>{
|
|
10
|
+
const getUpdateOperation = (models, definition, registry)=>{
|
|
11
|
+
const { options: { references, aggregations } } = definition;
|
|
9
12
|
const update = async (key, item)=>{
|
|
10
13
|
const { coordinate } = definition;
|
|
11
14
|
const { kta } = coordinate;
|
|
@@ -33,18 +36,13 @@ const getUpdateOperation = (models, definition)=>{
|
|
|
33
36
|
// Remove the key and events
|
|
34
37
|
let updateProps = removeKey(item);
|
|
35
38
|
updateProps = removeEvents(item);
|
|
39
|
+
logger.default('Response: %s', stringifyJSON(response));
|
|
40
|
+
logger.default('Update Properties: %s', stringifyJSON(updateProps));
|
|
36
41
|
// Update the object
|
|
37
|
-
response =
|
|
38
|
-
...response,
|
|
39
|
-
...updateProps
|
|
40
|
-
};
|
|
41
|
-
await (response === null || response === void 0 ? void 0 : response.save());
|
|
42
|
+
response = await response.update(updateProps);
|
|
42
43
|
// Populate the key and events
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
});
|
|
46
|
-
returnItem = populateKey(returnItem, kta);
|
|
47
|
-
returnItem = populateEvents(returnItem);
|
|
44
|
+
const processedItem = await processRow(response, kta, references, aggregations, registry);
|
|
45
|
+
const returnItem = validateKeys(processedItem, kta);
|
|
48
46
|
return returnItem;
|
|
49
47
|
} else {
|
|
50
48
|
throw new NotFoundError('update', coordinate, key);
|
|
@@ -54,4 +52,4 @@ const getUpdateOperation = (models, definition)=>{
|
|
|
54
52
|
};
|
|
55
53
|
|
|
56
54
|
export { getUpdateOperation };
|
|
57
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
55
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXBkYXRlLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
|
@@ -4,7 +4,7 @@ import { createOperations } from '../Operations.js';
|
|
|
4
4
|
import LibLogger from '../logger.js';
|
|
5
5
|
|
|
6
6
|
const logger = LibLogger.get('lib-sequelize', 'primary', 'instance');
|
|
7
|
-
function createInstance(keyType, models, libOptions = {}, scopes = []) {
|
|
7
|
+
function createInstance(keyType, models, libOptions = {}, scopes = [], registry) {
|
|
8
8
|
logger.debug('createInstance', {
|
|
9
9
|
keyType,
|
|
10
10
|
models,
|
|
@@ -14,13 +14,14 @@ function createInstance(keyType, models, libOptions = {}, scopes = []) {
|
|
|
14
14
|
const definition = createDefinition([
|
|
15
15
|
keyType
|
|
16
16
|
], scopes, libOptions);
|
|
17
|
-
const operations = createOperations(models, definition);
|
|
17
|
+
const operations = createOperations(models, definition, registry);
|
|
18
18
|
return {
|
|
19
19
|
definition,
|
|
20
|
-
operations: Primary.wrapOperations(operations, definition),
|
|
21
|
-
models
|
|
20
|
+
operations: Primary.wrapOperations(operations, definition, registry),
|
|
21
|
+
models,
|
|
22
|
+
registry
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export { createInstance };
|
|
26
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
27
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2UuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable no-undefined */ const clean = (obj)=>{
|
|
2
|
+
return Object.fromEntries(Object.entries(obj).filter(([_, v])=>v !== undefined));
|
|
3
|
+
};
|
|
4
|
+
//Recursive implementation of jSON.stringify;
|
|
5
|
+
const stringifyJSON = function(obj, visited = new Set()) {
|
|
6
|
+
const arrOfKeyVals = [];
|
|
7
|
+
const arrVals = [];
|
|
8
|
+
let objKeys = [];
|
|
9
|
+
/*********CHECK FOR PRIMITIVE TYPES**********/ if (typeof obj === 'number' || typeof obj === 'boolean' || obj === null) return '' + obj;
|
|
10
|
+
else if (typeof obj === 'string') return '"' + obj + '"';
|
|
11
|
+
/*********DETECT CIRCULAR REFERENCES**********/ if (obj instanceof Object && visited.has(obj)) {
|
|
12
|
+
return '"(circular)"';
|
|
13
|
+
} else if (Array.isArray(obj)) {
|
|
14
|
+
//check for empty array
|
|
15
|
+
if (obj[0] === undefined) return '[]';
|
|
16
|
+
else {
|
|
17
|
+
// Add array to visited before processing its elements
|
|
18
|
+
visited.add(obj);
|
|
19
|
+
obj.forEach(function(el) {
|
|
20
|
+
arrVals.push(stringifyJSON(el, visited));
|
|
21
|
+
});
|
|
22
|
+
return '[' + arrVals + ']';
|
|
23
|
+
}
|
|
24
|
+
} else if (obj instanceof Object) {
|
|
25
|
+
// Add object to visited before processing its properties
|
|
26
|
+
visited.add(obj);
|
|
27
|
+
//get object keys
|
|
28
|
+
objKeys = Object.keys(obj);
|
|
29
|
+
//set key output;
|
|
30
|
+
objKeys.forEach(function(key) {
|
|
31
|
+
const keyOut = '"' + key + '":';
|
|
32
|
+
const keyValOut = obj[key];
|
|
33
|
+
//skip functions and undefined properties
|
|
34
|
+
if (keyValOut instanceof Function || keyValOut === undefined) return; // Skip this entry entirely instead of pushing an empty string
|
|
35
|
+
else if (typeof keyValOut === 'string') arrOfKeyVals.push(keyOut + '"' + keyValOut + '"');
|
|
36
|
+
else if (typeof keyValOut === 'boolean' || typeof keyValOut === 'number' || keyValOut === null) arrOfKeyVals.push(keyOut + keyValOut);
|
|
37
|
+
else if (keyValOut instanceof Object) {
|
|
38
|
+
arrOfKeyVals.push(keyOut + stringifyJSON(keyValOut, visited));
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return '{' + arrOfKeyVals + '}';
|
|
42
|
+
}
|
|
43
|
+
return '';
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export { clean, stringifyJSON };
|
|
47
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2VuZXJhbC5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|