@autofleet/sadot 0.2.7 → 0.2.9-beta.0
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/coverage/clover.xml +834 -0
- package/coverage/coverage-final.json +35 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +341 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/src/api/index.html +116 -0
- package/coverage/lcov-report/src/api/index.ts.html +112 -0
- package/coverage/lcov-report/src/api/v1/definition/index.html +131 -0
- package/coverage/lcov-report/src/api/v1/definition/index.ts.html +394 -0
- package/coverage/lcov-report/src/api/v1/definition/validations.ts.html +190 -0
- package/coverage/lcov-report/src/api/v1/errors.ts.html +133 -0
- package/coverage/lcov-report/src/api/v1/index.html +131 -0
- package/coverage/lcov-report/src/api/v1/index.ts.html +112 -0
- package/coverage/lcov-report/src/errors/index.html +116 -0
- package/coverage/lcov-report/src/errors/index.ts.html +211 -0
- package/coverage/lcov-report/src/events/index.html +116 -0
- package/coverage/lcov-report/src/events/index.ts.html +235 -0
- package/coverage/lcov-report/src/hooks/create.ts.html +238 -0
- package/coverage/lcov-report/src/hooks/enrich.ts.html +424 -0
- package/coverage/lcov-report/src/hooks/find.ts.html +166 -0
- package/coverage/lcov-report/src/hooks/index.html +191 -0
- package/coverage/lcov-report/src/hooks/index.ts.html +130 -0
- package/coverage/lcov-report/src/hooks/update.ts.html +202 -0
- package/coverage/lcov-report/src/hooks/workaround.ts.html +226 -0
- package/coverage/lcov-report/src/index.html +116 -0
- package/coverage/lcov-report/src/index.ts.html +382 -0
- package/coverage/lcov-report/src/models/CustomFieldDefinition.ts.html +505 -0
- package/coverage/lcov-report/src/models/CustomFieldValue.ts.html +427 -0
- package/coverage/lcov-report/src/models/index.html +146 -0
- package/coverage/lcov-report/src/models/index.ts.html +289 -0
- package/coverage/lcov-report/src/models/tests/AssociatedTestModel.ts.html +256 -0
- package/coverage/lcov-report/src/models/tests/TestModel.ts.html +232 -0
- package/coverage/lcov-report/src/models/tests/index.html +131 -0
- package/coverage/lcov-report/src/repository/definition.ts.html +517 -0
- package/coverage/lcov-report/src/repository/index.html +131 -0
- package/coverage/lcov-report/src/repository/value.ts.html +385 -0
- package/coverage/lcov-report/src/tests/api/index.html +116 -0
- package/coverage/lcov-report/src/tests/api/test-api.ts.html +199 -0
- package/coverage/lcov-report/src/tests/helpers/database-config.ts.html +127 -0
- package/coverage/lcov-report/src/tests/helpers/index.html +131 -0
- package/coverage/lcov-report/src/tests/helpers/index.ts.html +130 -0
- package/coverage/lcov-report/src/tests/mocks/definition.mock.ts.html +292 -0
- package/coverage/lcov-report/src/tests/mocks/events.mock.ts.html +139 -0
- package/coverage/lcov-report/src/tests/mocks/index.html +146 -0
- package/coverage/lcov-report/src/tests/mocks/testModel.ts.html +196 -0
- package/coverage/lcov-report/src/utils/db/index.html +116 -0
- package/coverage/lcov-report/src/utils/db/index.ts.html +127 -0
- package/coverage/lcov-report/src/utils/logger/index.html +116 -0
- package/coverage/lcov-report/src/utils/logger/index.ts.html +115 -0
- package/coverage/lcov-report/src/utils/validations/custom-fields.ts.html +112 -0
- package/coverage/lcov-report/src/utils/validations/custom.ts.html +202 -0
- package/coverage/lcov-report/src/utils/validations/index.html +176 -0
- package/coverage/lcov-report/src/utils/validations/index.ts.html +142 -0
- package/coverage/lcov-report/src/utils/validations/type.ts.html +220 -0
- package/coverage/lcov-report/src/utils/validations/validators.ts.html +187 -0
- package/coverage/lcov.info +1622 -0
- package/dist/events/index.js +16 -20
- package/dist/events/index.js.map +1 -1
- package/dist/hooks/enrich.js +4 -10
- package/dist/hooks/enrich.js.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/repository/definition.js +5 -2
- package/dist/repository/definition.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/logger/index.js +0 -3
- package/dist/utils/logger/index.js.map +1 -1
- package/package.json +1 -1
- package/src/events/index.ts +1 -5
- package/src/hooks/enrich.ts +4 -6
- package/src/index.ts +3 -3
- package/src/repository/definition.ts +5 -1
- package/src/utils/logger/index.ts +0 -4
package/src/hooks/enrich.ts
CHANGED
|
@@ -3,7 +3,6 @@ import * as ValueRepo from '../repository/value';
|
|
|
3
3
|
import * as DefinitionRepo from '../repository/definition';
|
|
4
4
|
import CustomFieldValue from '../models/CustomFieldValue';
|
|
5
5
|
import { SerializedCustomFields } from '../types/definition';
|
|
6
|
-
import logger from '../utils/logger';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Serialize custom fields value into the format of {[name] -> [fieldData]}
|
|
@@ -18,11 +17,10 @@ const serializeCustomFields = (customFieldValues: CustomFieldValue[]): Serialize
|
|
|
18
17
|
/**
|
|
19
18
|
* A hook to attach the custom fields when fetching a model instances.
|
|
20
19
|
*/
|
|
21
|
-
const enrichResults = (scopeAttributes: string[]) => async (
|
|
20
|
+
const enrichResults = (modelType: string, scopeAttributes: string[]) => async (
|
|
22
21
|
instancesOrInstance: any | any[],
|
|
23
22
|
options,
|
|
24
23
|
): Promise<void> => {
|
|
25
|
-
logger.debug('sadot - enrich hook');
|
|
26
24
|
if (
|
|
27
25
|
options.originalAttributes?.length > 0
|
|
28
26
|
&& !options.originalAttributes?.includes?.('customFields')
|
|
@@ -35,22 +33,22 @@ const enrichResults = (scopeAttributes: string[]) => async (
|
|
|
35
33
|
? instancesOrInstance
|
|
36
34
|
: [instancesOrInstance];
|
|
37
35
|
|
|
38
|
-
instances = instances.filter(
|
|
36
|
+
instances = instances.filter(Boolean);
|
|
39
37
|
|
|
40
38
|
const identifiers = instances.map((instance) =>
|
|
41
39
|
scopeAttributes
|
|
42
40
|
.map((attr) => instance[attr])).flat();
|
|
43
41
|
|
|
44
|
-
const uniqueIdentifiers = [...new Set(identifiers)].filter(
|
|
42
|
+
const uniqueIdentifiers = [...new Set(identifiers)].filter(Boolean);
|
|
45
43
|
const identifierCustomFieldDefinitionsMapping = uniqueIdentifiers.reduce((map, identifier) => ({
|
|
46
44
|
...map,
|
|
47
45
|
[identifier]: [],
|
|
48
46
|
}), {});
|
|
49
47
|
const customFieldDefinitions = await DefinitionRepo.findByEntityIds(
|
|
48
|
+
modelType,
|
|
50
49
|
uniqueIdentifiers,
|
|
51
50
|
{ transaction: options.transaction },
|
|
52
51
|
);
|
|
53
|
-
logger.debug('sadot - enrich hook - got customFieldDefinitions');
|
|
54
52
|
|
|
55
53
|
customFieldDefinitions.forEach((cfd) => {
|
|
56
54
|
identifierCustomFieldDefinitionsMapping[cfd.entityId].push(cfd);
|
package/src/index.ts
CHANGED
|
@@ -38,9 +38,9 @@ const addHooks = (models: ModelOptions[], getModel: ModelFetcher) => {
|
|
|
38
38
|
model.addHook('beforeBulkUpdate', 'sadot-beforeBulkUpdate', beforeBulkUpdate);
|
|
39
39
|
model.addHook('beforeCreate', 'sadot-beforeCreate', beforeCreate(scopeAttributes));
|
|
40
40
|
model.addHook('beforeUpdate', 'sadot-beforeUpdate', beforeUpdate(scopeAttributes));
|
|
41
|
-
model.addHook('afterFind', 'sadot-afterFind', enrichResults(scopeAttributes));
|
|
42
|
-
model.addHook('afterUpdate', 'sadot-afterUpdate', enrichResults(scopeAttributes));
|
|
43
|
-
model.addHook('afterCreate', 'sadot-afterCreate', enrichResults(scopeAttributes));
|
|
41
|
+
model.addHook('afterFind', 'sadot-afterFind', enrichResults(name, scopeAttributes));
|
|
42
|
+
model.addHook('afterUpdate', 'sadot-afterUpdate', enrichResults(name, scopeAttributes));
|
|
43
|
+
model.addHook('afterCreate', 'sadot-afterCreate', enrichResults(name, scopeAttributes));
|
|
44
44
|
} catch (e) {
|
|
45
45
|
logger.error(`Could not add custom fields hook to model ${name}. `, e);
|
|
46
46
|
}
|
|
@@ -44,10 +44,14 @@ export const findByEntityId = async (
|
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
export const findByEntityIds = async (
|
|
47
|
+
modelType: string,
|
|
47
48
|
entityIds: string[],
|
|
48
49
|
options: any = {},
|
|
49
50
|
): Promise<CustomFieldDefinition[]> => CustomFieldDefinition.findAll({
|
|
50
|
-
where: {
|
|
51
|
+
where: {
|
|
52
|
+
modelType,
|
|
53
|
+
entityId: entityIds,
|
|
54
|
+
},
|
|
51
55
|
transaction: options.transaction,
|
|
52
56
|
raw: true,
|
|
53
57
|
});
|