@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.
Files changed (78) hide show
  1. package/coverage/clover.xml +834 -0
  2. package/coverage/coverage-final.json +35 -0
  3. package/coverage/lcov-report/base.css +224 -0
  4. package/coverage/lcov-report/block-navigation.js +87 -0
  5. package/coverage/lcov-report/favicon.png +0 -0
  6. package/coverage/lcov-report/index.html +341 -0
  7. package/coverage/lcov-report/prettify.css +1 -0
  8. package/coverage/lcov-report/prettify.js +2 -0
  9. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  10. package/coverage/lcov-report/sorter.js +196 -0
  11. package/coverage/lcov-report/src/api/index.html +116 -0
  12. package/coverage/lcov-report/src/api/index.ts.html +112 -0
  13. package/coverage/lcov-report/src/api/v1/definition/index.html +131 -0
  14. package/coverage/lcov-report/src/api/v1/definition/index.ts.html +394 -0
  15. package/coverage/lcov-report/src/api/v1/definition/validations.ts.html +190 -0
  16. package/coverage/lcov-report/src/api/v1/errors.ts.html +133 -0
  17. package/coverage/lcov-report/src/api/v1/index.html +131 -0
  18. package/coverage/lcov-report/src/api/v1/index.ts.html +112 -0
  19. package/coverage/lcov-report/src/errors/index.html +116 -0
  20. package/coverage/lcov-report/src/errors/index.ts.html +211 -0
  21. package/coverage/lcov-report/src/events/index.html +116 -0
  22. package/coverage/lcov-report/src/events/index.ts.html +235 -0
  23. package/coverage/lcov-report/src/hooks/create.ts.html +238 -0
  24. package/coverage/lcov-report/src/hooks/enrich.ts.html +424 -0
  25. package/coverage/lcov-report/src/hooks/find.ts.html +166 -0
  26. package/coverage/lcov-report/src/hooks/index.html +191 -0
  27. package/coverage/lcov-report/src/hooks/index.ts.html +130 -0
  28. package/coverage/lcov-report/src/hooks/update.ts.html +202 -0
  29. package/coverage/lcov-report/src/hooks/workaround.ts.html +226 -0
  30. package/coverage/lcov-report/src/index.html +116 -0
  31. package/coverage/lcov-report/src/index.ts.html +382 -0
  32. package/coverage/lcov-report/src/models/CustomFieldDefinition.ts.html +505 -0
  33. package/coverage/lcov-report/src/models/CustomFieldValue.ts.html +427 -0
  34. package/coverage/lcov-report/src/models/index.html +146 -0
  35. package/coverage/lcov-report/src/models/index.ts.html +289 -0
  36. package/coverage/lcov-report/src/models/tests/AssociatedTestModel.ts.html +256 -0
  37. package/coverage/lcov-report/src/models/tests/TestModel.ts.html +232 -0
  38. package/coverage/lcov-report/src/models/tests/index.html +131 -0
  39. package/coverage/lcov-report/src/repository/definition.ts.html +517 -0
  40. package/coverage/lcov-report/src/repository/index.html +131 -0
  41. package/coverage/lcov-report/src/repository/value.ts.html +385 -0
  42. package/coverage/lcov-report/src/tests/api/index.html +116 -0
  43. package/coverage/lcov-report/src/tests/api/test-api.ts.html +199 -0
  44. package/coverage/lcov-report/src/tests/helpers/database-config.ts.html +127 -0
  45. package/coverage/lcov-report/src/tests/helpers/index.html +131 -0
  46. package/coverage/lcov-report/src/tests/helpers/index.ts.html +130 -0
  47. package/coverage/lcov-report/src/tests/mocks/definition.mock.ts.html +292 -0
  48. package/coverage/lcov-report/src/tests/mocks/events.mock.ts.html +139 -0
  49. package/coverage/lcov-report/src/tests/mocks/index.html +146 -0
  50. package/coverage/lcov-report/src/tests/mocks/testModel.ts.html +196 -0
  51. package/coverage/lcov-report/src/utils/db/index.html +116 -0
  52. package/coverage/lcov-report/src/utils/db/index.ts.html +127 -0
  53. package/coverage/lcov-report/src/utils/logger/index.html +116 -0
  54. package/coverage/lcov-report/src/utils/logger/index.ts.html +115 -0
  55. package/coverage/lcov-report/src/utils/validations/custom-fields.ts.html +112 -0
  56. package/coverage/lcov-report/src/utils/validations/custom.ts.html +202 -0
  57. package/coverage/lcov-report/src/utils/validations/index.html +176 -0
  58. package/coverage/lcov-report/src/utils/validations/index.ts.html +142 -0
  59. package/coverage/lcov-report/src/utils/validations/type.ts.html +220 -0
  60. package/coverage/lcov-report/src/utils/validations/validators.ts.html +187 -0
  61. package/coverage/lcov.info +1622 -0
  62. package/dist/events/index.js +16 -20
  63. package/dist/events/index.js.map +1 -1
  64. package/dist/hooks/enrich.js +4 -10
  65. package/dist/hooks/enrich.js.map +1 -1
  66. package/dist/index.js +3 -3
  67. package/dist/index.js.map +1 -1
  68. package/dist/repository/definition.js +5 -2
  69. package/dist/repository/definition.js.map +1 -1
  70. package/dist/tsconfig.tsbuildinfo +1 -1
  71. package/dist/utils/logger/index.js +0 -3
  72. package/dist/utils/logger/index.js.map +1 -1
  73. package/package.json +1 -1
  74. package/src/events/index.ts +1 -5
  75. package/src/hooks/enrich.ts +4 -6
  76. package/src/index.ts +3 -3
  77. package/src/repository/definition.ts +5 -1
  78. package/src/utils/logger/index.ts +0 -4
@@ -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((instance) => !!instance);
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((identifier) => !!identifier);
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: { entityId: entityIds },
51
+ where: {
52
+ modelType,
53
+ entityId: entityIds,
54
+ },
51
55
  transaction: options.transaction,
52
56
  raw: true,
53
57
  });
@@ -3,8 +3,4 @@ const Logger = require('@autofleet/logger');
3
3
 
4
4
  const logger = Logger();
5
5
 
6
- if (process.env.SADOT_DEBUG === 'true') {
7
- logger.debug = logger.info;
8
- }
9
-
10
6
  export default logger;