@autofleet/sadot 0.5.4-beta.25 → 0.5.4-beta.26

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.
@@ -29,7 +29,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  /* eslint-disable no-param-reassign */
30
30
  const ValueRepo = __importStar(require("../repository/value"));
31
31
  const DefinitionRepo = __importStar(require("../repository/definition"));
32
- const logger_1 = __importDefault(require("../utils/logger"));
33
32
  const scopeAttributes_1 = __importDefault(require("../utils/scopeAttributes"));
34
33
  /**
35
34
  * Serialize custom fields value into the format of {[name] -> [fieldData]}
@@ -56,20 +55,28 @@ const enrichResults = (modelType, scopeAttributes, hookType, modelOptions = {})
56
55
  : [instancesOrInstance];
57
56
  instances = instances.filter(Boolean);
58
57
  const identifiers = (0, scopeAttributes_1.default)(instances, scopeAttributes);
59
- logger_1.default.info('enrichResults - sadot - indentifiers: ', identifiers);
60
58
  const uniqueIdentifiers = [...new Set(identifiers)].filter(Boolean);
61
- console.log({ uniqueIdentifiers });
62
59
  const identifierCustomFieldDefinitionsMapping = uniqueIdentifiers.reduce((map, identifier) => ({
63
60
  ...map,
64
61
  [identifier]: [],
65
62
  }), {});
66
63
  const customFieldDefinitions = await DefinitionRepo.findByEntityIds(modelType, uniqueIdentifiers, { transaction: options.transaction, modelOptions });
64
+ if (modelOptions?.include && modelOptions.useEntityIdFromInclude) {
65
+ // if we pass useEntityIdFromInclude,
66
+ // map the entity from the options to the identifierCustomFieldDefinitionsMapping
67
+ modelOptions.include(identifiers).forEach(({ model }) => {
68
+ customFieldDefinitions.forEach((cfd) => {
69
+ const entityId = cfd[`${model.name}.entityId`];
70
+ identifierCustomFieldDefinitionsMapping[entityId] = [];
71
+ });
72
+ });
73
+ }
67
74
  const definitionsMap = customFieldDefinitions.reduce((map, definition) => ({
68
75
  ...map,
69
76
  [definition.id]: definition,
70
77
  }), {});
71
78
  customFieldDefinitions.forEach((cfd) => {
72
- identifierCustomFieldDefinitionsMapping[cfd.entityId]?.push(cfd);
79
+ identifierCustomFieldDefinitionsMapping[cfd.entityId].push(cfd);
73
80
  });
74
81
  // Get the values per instates ids:
75
82
  const instancesIds = instances.map((i) => i[primaryKey]);
@@ -3,8 +3,8 @@ import CustomFieldDefinition from './CustomFieldDefinition';
3
3
  import CustomFieldValue from './CustomFieldValue';
4
4
  import TestModel from './tests/TestModel';
5
5
  import ContextAwareTestModel from './tests/contextAwareModels/ContextAwareTestModel';
6
- import ContextModel from './tests/contextAwareModels/ContextModel';
6
+ import ContextTestModel from './tests/contextAwareModels/ContextTestModel';
7
7
  import AssociatedTestModel from './tests/AssociatedTestModel';
8
8
  declare const initTables: (sequelize: Sequelize, getUser: any) => Promise<void>;
9
9
  declare const initTestModels: (sequelize: Sequelize) => Promise<void>;
10
- export { CustomFieldValue, CustomFieldDefinition, TestModel, AssociatedTestModel, ContextAwareTestModel, ContextModel, initTables, initTestModels, };
10
+ export { CustomFieldValue, CustomFieldDefinition, TestModel, AssociatedTestModel, ContextAwareTestModel, ContextTestModel, initTables, initTestModels, };
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.initTestModels = exports.initTables = exports.ContextModel = exports.ContextAwareTestModel = exports.AssociatedTestModel = exports.TestModel = exports.CustomFieldDefinition = exports.CustomFieldValue = void 0;
6
+ exports.initTestModels = exports.initTables = exports.ContextTestModel = exports.ContextAwareTestModel = exports.AssociatedTestModel = exports.TestModel = exports.CustomFieldDefinition = exports.CustomFieldValue = void 0;
7
7
  /* eslint-disable no-param-reassign */
8
8
  const sequelize_1 = require("sequelize");
9
9
  const logger_1 = __importDefault(require("../utils/logger"));
@@ -15,12 +15,12 @@ const TestModel_1 = __importDefault(require("./tests/TestModel"));
15
15
  exports.TestModel = TestModel_1.default;
16
16
  const ContextAwareTestModel_1 = __importDefault(require("./tests/contextAwareModels/ContextAwareTestModel"));
17
17
  exports.ContextAwareTestModel = ContextAwareTestModel_1.default;
18
- const ContextModel_1 = __importDefault(require("./tests/contextAwareModels/ContextModel"));
19
- exports.ContextModel = ContextModel_1.default;
18
+ const ContextTestModel_1 = __importDefault(require("./tests/contextAwareModels/ContextTestModel"));
19
+ exports.ContextTestModel = ContextTestModel_1.default;
20
20
  const AssociatedTestModel_1 = __importDefault(require("./tests/AssociatedTestModel"));
21
21
  exports.AssociatedTestModel = AssociatedTestModel_1.default;
22
22
  const productionModels = [CustomFieldDefinition_1.default, CustomFieldValue_1.default];
23
- const testModels = [TestModel_1.default, AssociatedTestModel_1.default, ContextAwareTestModel_1.default, ContextModel_1.default];
23
+ const testModels = [TestModel_1.default, AssociatedTestModel_1.default, ContextAwareTestModel_1.default, ContextTestModel_1.default];
24
24
  const SADOT_MIGRATION_PREFIX = 'sadot-migration';
25
25
  const SCHEMA_VERSION = 1;
26
26
  const CUSTOM_FIELDS_SCHEMA_VERSION = `${SADOT_MIGRATION_PREFIX}_${SCHEMA_VERSION}`;
@@ -86,7 +86,7 @@ const initTestModels = async (sequelize) => {
86
86
  logger_1.default.info('custom-fields: test models added');
87
87
  await TestModel_1.default.sync({ alter: true });
88
88
  await AssociatedTestModel_1.default.sync({ alter: true });
89
- await ContextModel_1.default.sync({ alter: true });
89
+ await ContextTestModel_1.default.sync({ alter: true });
90
90
  await ContextAwareTestModel_1.default.sync({ alter: true });
91
91
  logger_1.default.info('custom-fields: test models synced');
92
92
  };
@@ -1,10 +1,10 @@
1
1
  import { Model } from 'sequelize-typescript';
2
- import ContextModel from './ContextModel';
2
+ import ContextTestModel from './ContextTestModel';
3
3
  declare class ContextAwareTestModel extends Model {
4
4
  id: string;
5
5
  contextId: string;
6
6
  coolAttribute?: boolean;
7
7
  customFields?: any;
8
- context: ContextModel;
8
+ context: ContextTestModel;
9
9
  }
10
10
  export default ContextAwareTestModel;
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  /* eslint-disable @typescript-eslint/no-unused-vars */
16
16
  const sequelize_typescript_1 = require("sequelize-typescript");
17
- const ContextModel_1 = __importDefault(require("./ContextModel"));
17
+ const ContextTestModel_1 = __importDefault(require("./ContextTestModel"));
18
18
  let ContextAwareTestModel = class ContextAwareTestModel extends sequelize_typescript_1.Model {
19
19
  };
20
20
  __decorate([
@@ -27,7 +27,7 @@ __decorate([
27
27
  __metadata("design:type", String)
28
28
  ], ContextAwareTestModel.prototype, "id", void 0);
29
29
  __decorate([
30
- (0, sequelize_typescript_1.ForeignKey)(() => ContextModel_1.default),
30
+ (0, sequelize_typescript_1.ForeignKey)(() => ContextTestModel_1.default),
31
31
  (0, sequelize_typescript_1.Column)({
32
32
  type: sequelize_typescript_1.DataType.UUID,
33
33
  }),
@@ -46,8 +46,8 @@ __decorate([
46
46
  __metadata("design:type", Object)
47
47
  ], ContextAwareTestModel.prototype, "customFields", void 0);
48
48
  __decorate([
49
- (0, sequelize_typescript_1.BelongsTo)(() => ContextModel_1.default),
50
- __metadata("design:type", ContextModel_1.default)
49
+ (0, sequelize_typescript_1.BelongsTo)(() => ContextTestModel_1.default),
50
+ __metadata("design:type", ContextTestModel_1.default)
51
51
  ], ContextAwareTestModel.prototype, "context", void 0);
52
52
  ContextAwareTestModel = __decorate([
53
53
  (0, sequelize_typescript_1.Table)({ createdAt: false, updatedAt: false })
@@ -5,9 +5,9 @@ declare enum EEntityTypes {
5
5
  DEMAND_SOURCE = "demandSource",
6
6
  FLEET = "fleet"
7
7
  }
8
- declare class ContextModel extends Model {
8
+ declare class ContextTestModel extends Model {
9
9
  id: string;
10
10
  entityId: string;
11
11
  entityType: EEntityTypes;
12
12
  }
13
- export default ContextModel;
13
+ export default ContextTestModel;
@@ -19,7 +19,7 @@ var EEntityTypes;
19
19
  EEntityTypes["DEMAND_SOURCE"] = "demandSource";
20
20
  EEntityTypes["FLEET"] = "fleet";
21
21
  })(EEntityTypes || (EEntityTypes = {}));
22
- let ContextModel = class ContextModel extends sequelize_typescript_1.Model {
22
+ let ContextTestModel = class ContextTestModel extends sequelize_typescript_1.Model {
23
23
  };
24
24
  __decorate([
25
25
  sequelize_typescript_1.PrimaryKey,
@@ -28,20 +28,20 @@ __decorate([
28
28
  type: sequelize_typescript_1.DataType.UUID,
29
29
  }),
30
30
  __metadata("design:type", String)
31
- ], ContextModel.prototype, "id", void 0);
31
+ ], ContextTestModel.prototype, "id", void 0);
32
32
  __decorate([
33
33
  (0, sequelize_typescript_1.Column)({
34
34
  type: sequelize_typescript_1.DataType.UUID,
35
35
  }),
36
36
  __metadata("design:type", String)
37
- ], ContextModel.prototype, "entityId", void 0);
37
+ ], ContextTestModel.prototype, "entityId", void 0);
38
38
  __decorate([
39
39
  (0, sequelize_typescript_1.Column)({
40
40
  type: sequelize_typescript_1.DataType.ENUM(...Object.values(EEntityTypes)),
41
41
  }),
42
42
  __metadata("design:type", String)
43
- ], ContextModel.prototype, "entityType", void 0);
44
- ContextModel = __decorate([
43
+ ], ContextTestModel.prototype, "entityType", void 0);
44
+ ContextTestModel = __decorate([
45
45
  (0, sequelize_typescript_1.Table)({ createdAt: false, updatedAt: false })
46
- ], ContextModel);
47
- exports.default = ContextModel;
46
+ ], ContextTestModel);
47
+ exports.default = ContextTestModel;
@@ -14,7 +14,6 @@ const findAll = (where, options = { withDisabled: false }) => {
14
14
  transaction: options.transaction,
15
15
  raw: true,
16
16
  include: options.include,
17
- logging: console.log,
18
17
  });
19
18
  };
20
19
  exports.findAll = findAll;
@@ -1,4 +1,4 @@
1
- import { FindOptions } from 'sequelize';
1
+ import type { FindOptions } from 'sequelize';
2
2
  import { CustomFieldValue } from '../models';
3
3
  import { CreateCustomFieldValue, ValuesToUpdate } from '../types/value';
4
4
  import { ModelOptions } from '../types';
@@ -73,7 +73,7 @@ exports.findValuesByModelIds = findValuesByModelIds;
73
73
  */
74
74
  const updateValues = async (modelType, modelId, identifiers, valuesToUpdate, options = {}) => {
75
75
  const names = Object.keys(valuesToUpdate);
76
- logger_1.default.info(`custom-fiel ds: updating values for ${modelType} ${modelId}`, {
76
+ logger_1.default.info(`custom-fields: updating values for ${modelType} ${modelId}`, {
77
77
  names, options, valuesToUpdate, identifiers,
78
78
  });
79
79
  const { modelOptions, transaction } = options;
@@ -8,7 +8,7 @@ const cleanup = async () => {
8
8
  await models_1.CustomFieldDefinition.unscoped().destroy({ where: {} });
9
9
  await models_1.TestModel.destroy({ where: {} });
10
10
  await models_1.ContextAwareTestModel.destroy({ where: {} });
11
- await models_1.ContextModel.destroy({ where: {} });
11
+ await models_1.ContextTestModel.destroy({ where: {} });
12
12
  }
13
13
  };
14
14
  exports.cleanup = cleanup;
@@ -1,18 +1,18 @@
1
- import { Includeable } from 'sequelize';
1
+ import { IncludeOptions } from 'sequelize';
2
2
  import { ModelCtor } from 'sequelize-typescript';
3
3
  export type ModelFetcher = (name: string) => any;
4
4
  export type ModelOptions = {
5
- include?: (entityIds: string[]) => Includeable[];
6
5
  /**
7
- * A function that will be called to resolve the entity id.
8
- * @param {string | string[]} - The entity id.
9
- * @returns {void}
6
+ * Include options for the model
7
+ */
8
+ include?: (entityIds: string[]) => IncludeOptions[];
9
+ /**
10
+ * Custom association for the model
11
+ * @param model - The model to associate with
10
12
  */
11
13
  customAssociation?: (model: ModelCtor) => void;
12
14
  /**
13
15
  * Whether to use the entity id from the instance per scope attribute
14
- * @param {string} -
15
- * @returns {void}
16
16
  */
17
17
  useEntityIdFromInclude?: boolean;
18
18
  };
@@ -1,2 +1,2 @@
1
- declare const buildAttributesByInstance: (instance: any, scopeAttributes: string[]) => any[];
2
- export default buildAttributesByInstance;
1
+ declare const applyScopeToInstance: (instance: any, scopeAttributes: string[]) => any[];
2
+ export default applyScopeToInstance;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const mapAttributeToInstance = (scopeAttributes, instance) => scopeAttributes.map((attr) => instance[attr]);
4
- const buildAttributesByInstance = (instance, scopeAttributes) => {
4
+ const applyScopeToInstance = (instance, scopeAttributes) => {
5
5
  const uniqueAttributes = Array.from(new Set(scopeAttributes));
6
6
  if (Array.isArray(instance)) {
7
7
  return instance.flatMap((ins) => mapAttributeToInstance(uniqueAttributes, ins));
8
8
  }
9
9
  return mapAttributeToInstance(uniqueAttributes, instance);
10
10
  };
11
- exports.default = buildAttributesByInstance;
11
+ exports.default = applyScopeToInstance;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/sadot",
3
- "version": "0.5.4-beta.25",
3
+ "version": "0.5.4-beta.26",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -3,7 +3,7 @@ import * as ValueRepo from '../repository/value';
3
3
  import * as DefinitionRepo from '../repository/definition';
4
4
  import { MissingRequiredCustomFieldError } from '../errors';
5
5
  import { ModelOptions } from '../types';
6
- import buildAttributesByInstance from '../utils/scopeAttributes';
6
+ import applyScopeToInstance from '../utils/scopeAttributes';
7
7
 
8
8
  /**
9
9
  * A hook to create the custom fields when updating a model (more then one instance).
@@ -25,7 +25,7 @@ export const beforeCreate = (scopeAttributes: string[], modelOptions: ModelOptio
25
25
  const { fields } = options;
26
26
  const modelType = instance.constructor.name;
27
27
 
28
- const identifiers = buildAttributesByInstance(instance, scopeAttributes);
28
+ const identifiers = applyScopeToInstance(instance, scopeAttributes);
29
29
 
30
30
  // get all model's required definitions
31
31
  const requiredFieldsNames = await DefinitionRepo.getRequiredFields(modelType,
@@ -4,9 +4,8 @@ import * as DefinitionRepo from '../repository/definition';
4
4
  import CustomFieldValue from '../models/CustomFieldValue';
5
5
  import CustomFieldDefinition from '../models/CustomFieldDefinition';
6
6
  import { SerializedCustomFields } from '../types/definition';
7
- import logger from '../utils/logger';
8
7
  import { ModelOptions } from '../types';
9
- import buildAttributesByInstance from '../utils/scopeAttributes';
8
+ import applyScopeToInstance from '../utils/scopeAttributes';
10
9
 
11
10
  type SupportedHookTypes = 'afterFind' | 'afterCreate' | 'afterUpdate';
12
11
 
@@ -52,14 +51,10 @@ const enrichResults = (
52
51
 
53
52
  instances = instances.filter(Boolean);
54
53
 
55
- const identifiers = buildAttributesByInstance(instances, scopeAttributes);
56
-
57
- logger.info('enrichResults - sadot - indentifiers: ', identifiers);
54
+ const identifiers = applyScopeToInstance(instances, scopeAttributes);
58
55
 
59
56
  const uniqueIdentifiers = [...new Set(identifiers)].filter(Boolean);
60
57
 
61
- console.log({ uniqueIdentifiers });
62
-
63
58
  const identifierCustomFieldDefinitionsMapping = uniqueIdentifiers.reduce((map, identifier) => ({
64
59
  ...map,
65
60
  [identifier]: [],
@@ -72,13 +67,24 @@ const enrichResults = (
72
67
  { transaction: options.transaction, modelOptions },
73
68
  );
74
69
 
70
+ if (modelOptions?.include && modelOptions.useEntityIdFromInclude) {
71
+ // if we pass useEntityIdFromInclude,
72
+ // map the entity from the options to the identifierCustomFieldDefinitionsMapping
73
+ modelOptions.include(identifiers).forEach(({ model }) => {
74
+ customFieldDefinitions.forEach((cfd) => {
75
+ const entityId = cfd[`${model.name}.entityId`];
76
+ identifierCustomFieldDefinitionsMapping[entityId] = [];
77
+ });
78
+ });
79
+ }
80
+
75
81
  const definitionsMap = customFieldDefinitions.reduce((map, definition) => ({
76
82
  ...map,
77
83
  [definition.id]: definition,
78
84
  }), {});
79
85
 
80
86
  customFieldDefinitions.forEach((cfd) => {
81
- identifierCustomFieldDefinitionsMapping[cfd.entityId]?.push(cfd);
87
+ identifierCustomFieldDefinitionsMapping[cfd.entityId].push(cfd);
82
88
  });
83
89
 
84
90
  // Get the values per instates ids:
@@ -1,7 +1,7 @@
1
1
  import logger from '../utils/logger';
2
2
  import * as ValueRepo from '../repository/value';
3
3
  import { ModelOptions } from '../types';
4
- import buildAttributesByInstance from '../utils/scopeAttributes';
4
+ import applyScopeToInstance from '../utils/scopeAttributes';
5
5
 
6
6
  /**
7
7
  * A hook to update the custom fields when updating a model (more then one instance).
@@ -23,7 +23,7 @@ export const beforeUpdate = (scopeAttributes: string[], modelOptions: ModelOptio
23
23
  logger.debug('sadot - before update hook');
24
24
  const { fields } = options;
25
25
  const modelType = instance.constructor.name;
26
- const identifiers = buildAttributesByInstance(instance, scopeAttributes);
26
+ const identifiers = applyScopeToInstance(instance, scopeAttributes);
27
27
 
28
28
  const customFieldsIdx = fields.indexOf('customFields');
29
29
  if (customFieldsIdx > -1) {
@@ -6,11 +6,11 @@ import CustomFieldDefinition from './CustomFieldDefinition';
6
6
  import CustomFieldValue from './CustomFieldValue';
7
7
  import TestModel from './tests/TestModel';
8
8
  import ContextAwareTestModel from './tests/contextAwareModels/ContextAwareTestModel';
9
- import ContextModel from './tests/contextAwareModels/ContextModel';
9
+ import ContextTestModel from './tests/contextAwareModels/ContextTestModel';
10
10
  import AssociatedTestModel from './tests/AssociatedTestModel';
11
11
 
12
12
  const productionModels = [CustomFieldDefinition, CustomFieldValue];
13
- const testModels = [TestModel, AssociatedTestModel, ContextAwareTestModel, ContextModel];
13
+ const testModels = [TestModel, AssociatedTestModel, ContextAwareTestModel, ContextTestModel];
14
14
 
15
15
  const SADOT_MIGRATION_PREFIX = 'sadot-migration';
16
16
  const SCHEMA_VERSION = 1;
@@ -90,7 +90,7 @@ const initTestModels = async (sequelize: Sequelize): Promise<void> => {
90
90
  logger.info('custom-fields: test models added');
91
91
  await TestModel.sync({ alter: true });
92
92
  await AssociatedTestModel.sync({ alter: true });
93
- await ContextModel.sync({ alter: true });
93
+ await ContextTestModel.sync({ alter: true });
94
94
  await ContextAwareTestModel.sync({ alter: true });
95
95
  logger.info('custom-fields: test models synced');
96
96
  };
@@ -101,7 +101,7 @@ export {
101
101
  TestModel,
102
102
  AssociatedTestModel,
103
103
  ContextAwareTestModel,
104
- ContextModel,
104
+ ContextTestModel,
105
105
  initTables,
106
106
  initTestModels,
107
107
  };
@@ -10,7 +10,7 @@ import {
10
10
  ForeignKey,
11
11
  } from 'sequelize-typescript';
12
12
  import AssociatedTestModel from '../AssociatedTestModel';
13
- import ContextModel from './ContextModel';
13
+ import ContextTestModel from './ContextTestModel';
14
14
 
15
15
  @Table({ createdAt: false, updatedAt: false })
16
16
  class ContextAwareTestModel extends Model {
@@ -22,7 +22,7 @@ class ContextAwareTestModel extends Model {
22
22
  })
23
23
  id!: string;
24
24
 
25
- @ForeignKey(() => ContextModel)
25
+ @ForeignKey(() => ContextTestModel)
26
26
  @Column({
27
27
  type: DataType.UUID,
28
28
  })
@@ -38,8 +38,8 @@ class ContextAwareTestModel extends Model {
38
38
  })
39
39
  customFields?: any;
40
40
 
41
- @BelongsTo(() => ContextModel)
42
- context: ContextModel;
41
+ @BelongsTo(() => ContextTestModel)
42
+ context: ContextTestModel;
43
43
  }
44
44
 
45
45
  export default ContextAwareTestModel;
@@ -16,7 +16,7 @@ import {
16
16
  }
17
17
 
18
18
  @Table({ createdAt: false, updatedAt: false })
19
- class ContextModel extends Model {
19
+ class ContextTestModel extends Model {
20
20
  @PrimaryKey
21
21
  @Column({
22
22
  defaultValue: DataType.UUIDV4,
@@ -35,4 +35,4 @@ class ContextModel extends Model {
35
35
  entityType: EEntityTypes;
36
36
  }
37
37
 
38
- export default ContextModel;
38
+ export default ContextTestModel;
@@ -22,7 +22,6 @@ export const findAll = (
22
22
  transaction: options.transaction,
23
23
  raw: true,
24
24
  include: options.include,
25
- logging: console.log,
26
25
  });
27
26
  };
28
27
 
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable max-len */
2
- import { FindOptions, WhereOptions } from 'sequelize';
2
+ import type { FindOptions, WhereOptions } from 'sequelize';
3
3
  import { CustomFieldValue, CustomFieldDefinition } from '../models';
4
4
  import * as DefinitionRepo from './definition';
5
5
  import { CreateCustomFieldValue, ValuesToUpdate } from '../types/value';
@@ -55,7 +55,7 @@ export const updateValues = async (
55
55
  options: FindOptions & { modelOptions?: ModelOptions } = {},
56
56
  ): Promise<CustomFieldValue[]> => {
57
57
  const names = Object.keys(valuesToUpdate);
58
- logger.info(`custom-fiel ds: updating values for ${modelType} ${modelId}`, {
58
+ logger.info(`custom-fields: updating values for ${modelType} ${modelId}`, {
59
59
  names, options, valuesToUpdate, identifiers,
60
60
  });
61
61
  const { modelOptions, transaction } = options;
@@ -1,5 +1,5 @@
1
1
  import {
2
- ContextAwareTestModel, ContextModel, CustomFieldDefinition, TestModel,
2
+ ContextAwareTestModel, ContextTestModel, CustomFieldDefinition, TestModel,
3
3
  } from '../../models';
4
4
 
5
5
  // eslint-disable-next-line import/prefer-default-export
@@ -8,7 +8,7 @@ export const cleanup = async (): Promise<void> => {
8
8
  await CustomFieldDefinition.unscoped().destroy({ where: {} });
9
9
  await TestModel.destroy({ where: {} });
10
10
  await ContextAwareTestModel.destroy({ where: {} });
11
- await ContextModel.destroy({ where: {} });
11
+ await ContextTestModel.destroy({ where: {} });
12
12
  }
13
13
  };
14
14
 
@@ -1,23 +1,22 @@
1
- import { Includeable } from 'sequelize';
1
+ import { IncludeOptions } from 'sequelize';
2
2
  import { ModelCtor } from 'sequelize-typescript';
3
3
 
4
4
  export type ModelFetcher = (name: string) => any;
5
5
 
6
6
  export type ModelOptions = {
7
- include?: (entityIds: string[]) => Includeable[];
8
7
  /**
9
- * A function that will be called to resolve the entity id.
10
- * @param {string | string[]} - The entity id.
11
- * @returns {void}
8
+ * Include options for the model
9
+ */
10
+ include?: (entityIds: string[]) => IncludeOptions[];
11
+ /**
12
+ * Custom association for the model
13
+ * @param model - The model to associate with
12
14
  */
13
15
 
14
16
  customAssociation?: (model: ModelCtor) => void;
15
17
  /**
16
18
  * Whether to use the entity id from the instance per scope attribute
17
- * @param {string} -
18
- * @returns {void}
19
19
  */
20
-
21
20
  useEntityIdFromInclude?: boolean
22
21
  }
23
22
  export type Models = {
@@ -33,5 +32,4 @@ export type CustomFieldOptions = {
33
32
  models: Models[];
34
33
  databaseConfig: any;
35
34
  getUser: () => any;
36
-
37
35
  };
@@ -1,7 +1,7 @@
1
1
  const mapAttributeToInstance = (scopeAttributes: string[], instance: any) =>
2
2
  scopeAttributes.map((attr) => instance[attr]);
3
3
 
4
- const buildAttributesByInstance = (instance: any, scopeAttributes: string[]) => {
4
+ const applyScopeToInstance = (instance: any, scopeAttributes: string[]) => {
5
5
  const uniqueAttributes = Array.from(new Set(scopeAttributes));
6
6
  if (Array.isArray(instance)) {
7
7
  return instance.flatMap((ins) => mapAttributeToInstance(uniqueAttributes, ins));
@@ -9,4 +9,4 @@ const buildAttributesByInstance = (instance: any, scopeAttributes: string[]) =>
9
9
  return mapAttributeToInstance(uniqueAttributes, instance);
10
10
  };
11
11
 
12
- export default buildAttributesByInstance;
12
+ export default applyScopeToInstance;