@autofleet/sadot 0.0.1-beta.9 → 0.0.2-beta

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 (145) hide show
  1. package/dist/jest.config.d.ts +12 -0
  2. package/dist/src/api/index.d.ts +2 -0
  3. package/dist/{api → src/api}/index.js +0 -1
  4. package/dist/src/api/v1/definition/index.d.ts +2 -0
  5. package/dist/{api → src/api}/v1/definition/index.js +23 -27
  6. package/dist/src/api/v1/definition/validations.d.ts +2 -0
  7. package/dist/{api → src/api}/v1/definition/validations.js +10 -10
  8. package/dist/src/api/v1/errors.d.ts +2 -0
  9. package/dist/{api → src/api}/v1/errors.js +0 -1
  10. package/dist/src/api/v1/index.d.ts +2 -0
  11. package/dist/{api → src/api}/v1/index.js +1 -2
  12. package/dist/src/errors/index.d.ts +16 -0
  13. package/dist/src/errors/index.js +45 -0
  14. package/dist/src/events/index.d.ts +4 -0
  15. package/dist/{events → src/events}/index.js +21 -2
  16. package/dist/src/hooks/create.d.ts +9 -0
  17. package/dist/{hooks → src/hooks}/create.js +14 -17
  18. package/dist/src/hooks/enrich.d.ts +5 -0
  19. package/dist/src/hooks/enrich.js +118 -0
  20. package/dist/src/hooks/find.d.ts +1 -0
  21. package/dist/src/hooks/find.js +29 -0
  22. package/dist/src/hooks/index.d.ts +6 -0
  23. package/dist/{hooks → src/hooks}/index.js +2 -2
  24. package/dist/src/hooks/update.d.ts +9 -0
  25. package/dist/{hooks → src/hooks}/update.js +7 -22
  26. package/dist/src/hooks/workaround.d.ts +10 -0
  27. package/dist/{hooks → src/hooks}/workaround.js +3 -13
  28. package/dist/src/index.d.ts +11 -0
  29. package/dist/src/index.js +105 -0
  30. package/dist/src/models/CustomFieldDefinition.d.ts +23 -0
  31. package/dist/{models → src/models}/CustomFieldDefinition.js +22 -18
  32. package/dist/src/models/CustomFieldValue.d.ts +15 -0
  33. package/dist/{models → src/models}/CustomFieldValue.js +24 -40
  34. package/dist/src/models/index.d.ts +8 -0
  35. package/dist/src/models/index.js +87 -0
  36. package/dist/src/models/tests/AssociatedTestModel.d.ts +12 -0
  37. package/dist/{models → src/models}/tests/AssociatedTestModel.js +0 -1
  38. package/dist/src/models/tests/TestModel.d.ts +11 -0
  39. package/dist/{models → src/models}/tests/TestModel.js +0 -1
  40. package/dist/src/repository/definition.d.ts +17 -0
  41. package/dist/src/repository/definition.js +80 -0
  42. package/dist/src/repository/value.d.ts +24 -0
  43. package/dist/{repository → src/repository}/value.js +22 -30
  44. package/dist/src/tests/api/test-api.d.ts +2 -0
  45. package/dist/{tests → src/tests}/api/test-api.js +12 -22
  46. package/dist/src/tests/helpers/database-config.d.ts +15 -0
  47. package/dist/{tests → src/tests}/helpers/database-config.js +0 -1
  48. package/dist/src/tests/helpers/index.d.ts +2 -0
  49. package/dist/src/tests/helpers/index.js +18 -0
  50. package/dist/src/tests/mocks/definition.mock.d.ts +37 -0
  51. package/dist/{tests/mocks/index.js → src/tests/mocks/definition.mock.js} +20 -17
  52. package/dist/src/tests/mocks/events.mock.d.ts +3 -0
  53. package/dist/{tests → src/tests}/mocks/events.mock.js +0 -1
  54. package/dist/src/tests/mocks/testModel.d.ts +12 -0
  55. package/dist/{tests → src/tests}/mocks/testModel.js +4 -14
  56. package/dist/src/types/definition/index.d.ts +23 -0
  57. package/dist/{types → src/types}/definition/index.js +0 -1
  58. package/dist/src/types/index.d.ts +13 -0
  59. package/dist/{types → src/types}/index.js +0 -1
  60. package/dist/src/types/value/index.d.ts +15 -0
  61. package/dist/{types → src/types}/value/index.js +0 -1
  62. package/dist/src/utils/constants/index.d.ts +1 -0
  63. package/dist/src/utils/constants/index.js +5 -0
  64. package/dist/src/utils/db/index.d.ts +4 -0
  65. package/dist/{utils → src/utils}/db/index.js +8 -1
  66. package/dist/src/utils/logger/index.d.ts +2 -0
  67. package/dist/{utils → src/utils}/logger/index.js +2 -2
  68. package/dist/src/utils/validations/custom-fields.d.ts +2 -0
  69. package/dist/{utils → src/utils}/validations/custom-fields.js +0 -1
  70. package/dist/src/utils/validations/custom.d.ts +15 -0
  71. package/dist/src/utils/validations/custom.js +42 -0
  72. package/dist/src/utils/validations/index.d.ts +2 -0
  73. package/dist/{utils → src/utils}/validations/index.js +0 -1
  74. package/dist/src/utils/validations/type.d.ts +18 -0
  75. package/dist/src/utils/validations/type.js +50 -0
  76. package/dist/src/utils/validations/validators.d.ts +12 -0
  77. package/dist/src/utils/validations/validators.js +33 -0
  78. package/package.json +3 -1
  79. package/src/api/v1/definition/index.ts +15 -8
  80. package/src/api/v1/definition/validations.ts +11 -25
  81. package/src/api/v1/index.ts +1 -1
  82. package/src/errors/index.ts +42 -0
  83. package/src/events/index.ts +23 -1
  84. package/src/hooks/create.ts +7 -3
  85. package/src/hooks/enrich.ts +125 -0
  86. package/src/hooks/find.ts +2 -101
  87. package/src/hooks/index.ts +2 -1
  88. package/src/hooks/update.ts +2 -15
  89. package/src/index.ts +52 -17
  90. package/src/models/CustomFieldDefinition.ts +23 -16
  91. package/src/models/CustomFieldValue.ts +7 -7
  92. package/src/models/index.ts +72 -16
  93. package/src/repository/definition.ts +26 -33
  94. package/src/repository/value.ts +4 -2
  95. package/src/tests/mocks/{index.ts → definition.mock.ts} +2 -4
  96. package/src/types/index.ts +4 -6
  97. package/src/utils/constants/index.ts +2 -0
  98. package/src/utils/db/index.ts +7 -0
  99. package/src/utils/logger/index.ts +3 -1
  100. package/src/utils/validations/custom.ts +26 -44
  101. package/src/utils/validations/type.ts +23 -6
  102. package/src/utils/validations/validators.ts +34 -0
  103. package/tsconfig.json +9 -25
  104. package/dist/api/index.js.map +0 -1
  105. package/dist/api/v1/definition/index.js.map +0 -1
  106. package/dist/api/v1/definition/validations.js.map +0 -1
  107. package/dist/api/v1/errors.js.map +0 -1
  108. package/dist/api/v1/index.js.map +0 -1
  109. package/dist/events/index.js.map +0 -1
  110. package/dist/hooks/create.js.map +0 -1
  111. package/dist/hooks/find.js +0 -136
  112. package/dist/hooks/find.js.map +0 -1
  113. package/dist/hooks/index.js.map +0 -1
  114. package/dist/hooks/update.js.map +0 -1
  115. package/dist/hooks/workaround.js.map +0 -1
  116. package/dist/index.js +0 -81
  117. package/dist/index.js.map +0 -1
  118. package/dist/models/CustomFieldDefinition.js.map +0 -1
  119. package/dist/models/CustomFieldValue.js.map +0 -1
  120. package/dist/models/index.js +0 -50
  121. package/dist/models/index.js.map +0 -1
  122. package/dist/models/tests/AssociatedTestModel.js.map +0 -1
  123. package/dist/models/tests/TestModel.js.map +0 -1
  124. package/dist/repository/definition.js +0 -101
  125. package/dist/repository/definition.js.map +0 -1
  126. package/dist/repository/value.js.map +0 -1
  127. package/dist/tests/api/test-api.js.map +0 -1
  128. package/dist/tests/helpers/database-config.js.map +0 -1
  129. package/dist/tests/helpers/index.js +0 -28
  130. package/dist/tests/helpers/index.js.map +0 -1
  131. package/dist/tests/mocks/events.mock.js.map +0 -1
  132. package/dist/tests/mocks/index.js.map +0 -1
  133. package/dist/tests/mocks/testModel.js.map +0 -1
  134. package/dist/tsconfig.tsbuildinfo +0 -1
  135. package/dist/types/definition/index.js.map +0 -1
  136. package/dist/types/index.js.map +0 -1
  137. package/dist/types/value/index.js.map +0 -1
  138. package/dist/utils/db/index.js.map +0 -1
  139. package/dist/utils/logger/index.js.map +0 -1
  140. package/dist/utils/validations/custom-fields.js.map +0 -1
  141. package/dist/utils/validations/custom.js +0 -59
  142. package/dist/utils/validations/custom.js.map +0 -1
  143. package/dist/utils/validations/index.js.map +0 -1
  144. package/dist/utils/validations/type.js +0 -32
  145. package/dist/utils/validations/type.js.map +0 -1
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
35
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
27
  };
@@ -40,57 +31,59 @@ exports.deleteValue = exports.updateValues = exports.findValuesByModelIds = expo
40
31
  const models_1 = require("../models");
41
32
  const DefinitionRepo = __importStar(require("./definition"));
42
33
  const logger_1 = __importDefault(require("../utils/logger"));
43
- const findByModelIdAndDefinition = (modelId, customFieldDefinitionId) => __awaiter(void 0, void 0, void 0, function* () { return models_1.CustomFieldValue.findAll({ where: { modelId, customFieldDefinitionId }, include: [models_1.CustomFieldDefinition] }); });
34
+ const errors_1 = require("../errors");
35
+ const findByModelIdAndDefinition = async (modelId, customFieldDefinitionId) => models_1.CustomFieldValue.findAll({ where: { modelId, customFieldDefinitionId }, include: [models_1.CustomFieldDefinition] });
44
36
  exports.findByModelIdAndDefinition = findByModelIdAndDefinition;
45
- const create = (data, withAssociations = false) => __awaiter(void 0, void 0, void 0, function* () {
46
- const created = yield models_1.CustomFieldValue.create(data);
37
+ const create = async (data, withAssociations = false) => {
38
+ const created = await models_1.CustomFieldValue.create(data);
47
39
  if (withAssociations) {
48
- const createdWithAssociations = yield (0, exports.findByModelIdAndDefinition)(created.modelId, created.customFieldDefinitionId);
49
- return createdWithAssociations === null || createdWithAssociations === void 0 ? void 0 : createdWithAssociations[0];
40
+ const createdWithAssociations = await (0, exports.findByModelIdAndDefinition)(created.modelId, created.customFieldDefinitionId);
41
+ return createdWithAssociations?.[0];
50
42
  }
51
43
  return created;
52
- });
44
+ };
53
45
  exports.create = create;
54
- const findAllValues = () => __awaiter(void 0, void 0, void 0, function* () { return models_1.CustomFieldValue.findAll({ include: [models_1.CustomFieldDefinition] }); });
46
+ const findAllValues = async () => models_1.CustomFieldValue.findAll({ include: [models_1.CustomFieldDefinition] });
55
47
  exports.findAllValues = findAllValues;
56
48
  /**
57
49
  * Get all values for model instance id (with their definitions)
58
50
  * @param modelId
59
51
  * @returns CustomFieldValue[]
60
52
  */
61
- const findValuesByModelId = (modelId) => __awaiter(void 0, void 0, void 0, function* () { return models_1.CustomFieldValue.findAll({ where: { modelId }, include: [models_1.CustomFieldDefinition] }); });
53
+ const findValuesByModelId = async (modelId) => models_1.CustomFieldValue.findAll({ where: { modelId }, include: [models_1.CustomFieldDefinition] });
62
54
  exports.findValuesByModelId = findValuesByModelId;
63
55
  /**
64
56
  * Retrieves custom field values for given model IDs
65
57
  * @param modelIds - An array of model IDs to query custom field values for.
66
58
  * @param options - Optional configuration object.
67
59
  */
68
- const findValuesByModelIds = (modelIds, options) => __awaiter(void 0, void 0, void 0, function* () {
60
+ const findValuesByModelIds = async (modelIds, options) => {
69
61
  const { transaction } = options;
70
62
  return models_1.CustomFieldValue.findAll({
71
63
  where: { modelId: modelIds },
72
- include: [models_1.CustomFieldDefinition],
73
64
  transaction,
65
+ raw: true,
66
+ nest: true,
74
67
  });
75
- });
68
+ };
76
69
  exports.findValuesByModelIds = findValuesByModelIds;
77
70
  /**
78
71
  * Try to update custom field values for a model instance.
79
72
  * Create new value record if not exists, but fails if value's definition not exist.
80
73
  * Return the updated values
81
74
  */
82
- const updateValues = (modelType, modelId, identifiers, valuesToUpdate, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
75
+ const updateValues = async (modelType, modelId, identifiers, valuesToUpdate, options = {}) => {
83
76
  logger_1.default.info(`custom-fields: updating values for ${modelType} ${modelId}`, { valuesToUpdate });
84
77
  const names = Object.keys(valuesToUpdate);
85
- const fieldDefinitions = (yield DefinitionRepo.findAll({ modelType, name: names, entityId: identifiers }, { withDisabled: true, transaction: options.transaction })) || [];
78
+ const fieldDefinitions = await DefinitionRepo.findAll({ modelType, name: names, entityId: identifiers }, { withDisabled: true, transaction: options.transaction }) || [];
86
79
  const disabledDefinitions = fieldDefinitions.filter((def) => def.disabled);
87
80
  if (fieldDefinitions.length !== names.length) {
88
81
  const missingDefinitions = names.filter((name) => !fieldDefinitions.some((def) => def.name === name));
89
- throw new Error(`custom-fields: missing definitions for ${missingDefinitions.join(', ')}`);
82
+ throw new errors_1.MissingDefinitionError(missingDefinitions);
90
83
  }
91
- const disabledNames = (disabledDefinitions === null || disabledDefinitions === void 0 ? void 0 : disabledDefinitions.map((def) => def.name)) || [];
84
+ const disabledNames = disabledDefinitions?.map((def) => def.name) || [];
92
85
  const valuesWithDisabledDefinitions = names.filter((name) => disabledNames.includes(name));
93
- if ((valuesWithDisabledDefinitions === null || valuesWithDisabledDefinitions === void 0 ? void 0 : valuesWithDisabledDefinitions.length) > 0) {
86
+ if (valuesWithDisabledDefinitions?.length > 0) {
94
87
  logger_1.default.warn(`custom-fields: trying to update disabled values: ${valuesWithDisabledDefinitions.join(', ')}`);
95
88
  }
96
89
  const values = names.map((name) => ({
@@ -99,17 +92,16 @@ const updateValues = (modelType, modelId, identifiers, valuesToUpdate, options =
99
92
  updatedAt: new Date(),
100
93
  customFieldDefinitionId: fieldDefinitions.find((def) => def.name === name).id,
101
94
  }));
102
- return Promise.all(values.map((value) => __awaiter(void 0, void 0, void 0, function* () {
103
- const [cfv] = yield models_1.CustomFieldValue.upsert(value, {
95
+ return Promise.all(values.map(async (value) => {
96
+ const [cfv] = await models_1.CustomFieldValue.upsert(value, {
104
97
  transaction: options.transaction,
105
98
  });
106
99
  return cfv;
107
- })));
108
- });
100
+ }));
101
+ };
109
102
  exports.updateValues = updateValues;
110
103
  const deleteValue = (id, options = {}) => models_1.CustomFieldValue.update({ deletedAt: new Date() }, {
111
104
  where: { id },
112
105
  transaction: options.transaction,
113
106
  });
114
107
  exports.deleteValue = deleteValue;
115
- //# sourceMappingURL=value.js.map
@@ -0,0 +1,2 @@
1
+ declare const app: import("express-serve-static-core").Express;
2
+ export default app;
@@ -22,45 +22,35 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
25
  Object.defineProperty(exports, "__esModule", { value: true });
35
26
  const express_1 = __importStar(require("express"));
36
27
  const models_1 = require("../../models");
37
28
  const app = (0, express_1.default)();
38
29
  app.use(express_1.default.json());
39
30
  const api = (0, express_1.Router)();
40
- api.get('/v1/test-models', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
41
- const testModels = yield models_1.TestModel.findAll();
31
+ api.get('/v1/test-models', async (req, res) => {
32
+ const testModels = await models_1.TestModel.findAll();
42
33
  return res.json(testModels);
43
- }));
44
- api.get('/v1/test-models/:testModelId', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
34
+ });
35
+ api.get('/v1/test-models/:testModelId', async (req, res) => {
45
36
  const { params: { testModelId } } = req;
46
- const testModel = yield models_1.TestModel.findByPk(testModelId);
37
+ const testModel = await models_1.TestModel.findByPk(testModelId);
47
38
  return res.json(testModel);
48
- }));
49
- api.post('/v1/test-models', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
39
+ });
40
+ api.post('/v1/test-models', async (req, res) => {
50
41
  const { body } = req;
51
- const testModel = yield models_1.TestModel.create(body);
42
+ const testModel = await models_1.TestModel.create(body);
52
43
  return res.json(testModel);
53
- }));
54
- api.patch('/v1/test-models/:testModelId', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
44
+ });
45
+ api.patch('/v1/test-models/:testModelId', async (req, res) => {
55
46
  const { body, params: { testModelId } } = req;
56
- const testModel = yield models_1.TestModel.update(body, {
47
+ const testModel = await models_1.TestModel.update(body, {
57
48
  where: {
58
49
  id: testModelId,
59
50
  },
60
51
  returning: true,
61
52
  });
62
53
  return res.json(testModel[1][0]);
63
- }));
54
+ });
64
55
  app.use('/api', api);
65
56
  exports.default = app;
66
- //# sourceMappingURL=test-api.js.map
@@ -0,0 +1,15 @@
1
+ declare const _default: {
2
+ test: {
3
+ username: string;
4
+ password: string;
5
+ database: string;
6
+ host: string;
7
+ dialect: string;
8
+ define: {
9
+ underscored: boolean;
10
+ underscoredAll: boolean;
11
+ };
12
+ logging: boolean;
13
+ };
14
+ };
15
+ export default _default;
@@ -14,4 +14,3 @@ exports.default = {
14
14
  logging: false,
15
15
  },
16
16
  };
17
- //# sourceMappingURL=database-config.js.map
@@ -0,0 +1,2 @@
1
+ export declare const cleanup: () => Promise<void>;
2
+ export declare const getModel: (name: string) => any;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getModel = exports.cleanup = void 0;
4
+ const models_1 = require("../../models");
5
+ // eslint-disable-next-line import/prefer-default-export
6
+ const cleanup = async () => {
7
+ if (process.env.NODE_ENV === 'test' || process.env.NODE_ENV === 'development') {
8
+ await models_1.CustomFieldDefinition.unscoped().destroy({ where: {} });
9
+ await models_1.TestModel.destroy({ where: {} });
10
+ }
11
+ };
12
+ exports.cleanup = cleanup;
13
+ const getModel = (name) => {
14
+ // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
15
+ const models = require('../../models');
16
+ return models[name];
17
+ };
18
+ exports.getModel = getModel;
@@ -0,0 +1,37 @@
1
+ import { CreateCustomFieldDefinition, CustomFieldDefinitionDTO } from '../../types/definition';
2
+ export declare const coolFieldDefinition: CreateCustomFieldDefinition;
3
+ export declare const coolFieldDefinition2: {
4
+ name: string;
5
+ required?: boolean;
6
+ disabled?: boolean;
7
+ description?: string;
8
+ createdAt?: Date;
9
+ updatedAt?: Date;
10
+ deletedAt?: Date;
11
+ displayName?: string;
12
+ validation?: any;
13
+ fieldType: string;
14
+ entityId: string;
15
+ entityType: string;
16
+ modelType: string;
17
+ };
18
+ export declare const coolFieldDefinition3: {
19
+ name: string;
20
+ required?: boolean;
21
+ disabled?: boolean;
22
+ description?: string;
23
+ createdAt?: Date;
24
+ updatedAt?: Date;
25
+ deletedAt?: Date;
26
+ displayName?: string;
27
+ validation?: any;
28
+ fieldType: string;
29
+ entityId: string;
30
+ entityType: string;
31
+ modelType: string;
32
+ };
33
+ export declare const booleanField: (modelType: string) => CreateCustomFieldDefinition;
34
+ export declare const enumField: (modelType: string, options: any) => CreateCustomFieldDefinition;
35
+ export declare const rangeField: (modelType: string) => CreateCustomFieldDefinition;
36
+ export declare const createDefinition: (defaults: Partial<CustomFieldDefinitionDTO>) => CreateCustomFieldDefinition;
37
+ export declare const createDefinitions: (defaults: Partial<CustomFieldDefinitionDTO>, length?: number) => CreateCustomFieldDefinition[];
@@ -9,8 +9,14 @@ exports.coolFieldDefinition = {
9
9
  entityId: (0, uuid_1.v4)(),
10
10
  entityType: 'fleetId',
11
11
  };
12
- exports.coolFieldDefinition2 = Object.assign(Object.assign({}, exports.coolFieldDefinition), { name: 'cool field2' });
13
- exports.coolFieldDefinition3 = Object.assign(Object.assign({}, exports.coolFieldDefinition), { name: 'cool field3' });
12
+ exports.coolFieldDefinition2 = {
13
+ ...exports.coolFieldDefinition,
14
+ name: 'cool field2',
15
+ };
16
+ exports.coolFieldDefinition3 = {
17
+ ...exports.coolFieldDefinition,
18
+ name: 'cool field3',
19
+ };
14
20
  const booleanField = (modelType) => ({
15
21
  name: 'shapeless',
16
22
  modelType,
@@ -22,10 +28,8 @@ exports.booleanField = booleanField;
22
28
  const enumField = (modelType, options) => ({
23
29
  name: 'choices',
24
30
  modelType,
25
- fieldType: 'enum',
26
- validation: {
27
- enum: options,
28
- },
31
+ fieldType: 'select',
32
+ validation: options,
29
33
  entityId: (0, uuid_1.v4)(),
30
34
  entityType: 'fleetId',
31
35
  });
@@ -43,19 +47,18 @@ const rangeField = (modelType) => ({
43
47
  exports.rangeField = rangeField;
44
48
  // eslint-disable-next-line max-len
45
49
  const createDefinition = (defaults) => ({
46
- name: (defaults === null || defaults === void 0 ? void 0 : defaults.name) || `def_${(0, uuid_1.v4)()}`,
47
- modelType: (defaults === null || defaults === void 0 ? void 0 : defaults.modelType) || 'TestModel',
48
- fieldType: (defaults === null || defaults === void 0 ? void 0 : defaults.fieldType) || 'boolean',
49
- entityId: (defaults === null || defaults === void 0 ? void 0 : defaults.entityId) || (0, uuid_1.v4)(),
50
- entityType: (defaults === null || defaults === void 0 ? void 0 : defaults.entityType) || 'fleetId',
50
+ name: defaults?.name || `def_${(0, uuid_1.v4)()}`,
51
+ modelType: defaults?.modelType || 'TestModel',
52
+ fieldType: defaults?.fieldType || 'boolean',
53
+ entityId: defaults?.entityId || (0, uuid_1.v4)(),
54
+ entityType: defaults?.entityType || 'fleetId',
51
55
  });
52
56
  exports.createDefinition = createDefinition;
53
57
  const createDefinitions = (defaults, length = 1) => (Array(length).fill({}).map((_) => ({
54
- name: (defaults === null || defaults === void 0 ? void 0 : defaults.name) || `def_${(0, uuid_1.v4)()}`,
55
- modelType: (defaults === null || defaults === void 0 ? void 0 : defaults.modelType) || 'TestModel',
56
- fieldType: (defaults === null || defaults === void 0 ? void 0 : defaults.fieldType) || 'boolean',
57
- entityId: (defaults === null || defaults === void 0 ? void 0 : defaults.entityId) || (0, uuid_1.v4)(),
58
- entityType: (defaults === null || defaults === void 0 ? void 0 : defaults.entityType) || 'fleetId',
58
+ name: defaults?.name || `def_${(0, uuid_1.v4)()}`,
59
+ modelType: defaults?.modelType || 'TestModel',
60
+ fieldType: defaults?.fieldType || 'boolean',
61
+ entityId: defaults?.entityId || (0, uuid_1.v4)(),
62
+ entityType: defaults?.entityType || 'fleetId',
59
63
  })));
60
64
  exports.createDefinitions = createDefinitions;
61
- //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ export declare const mockEvent: (events: any, eventName: any, numberOfEvents: any) => any[];
2
+ export declare const mockDimCustomFieldDefinitionEvent: (events: any, numberOfEvents: any) => any[];
3
+ export declare const mockDimCustomFieldValueEvent: (events: any, numberOfEvents: any) => any[];
@@ -17,4 +17,3 @@ const mockDimCustomFieldDefinitionEvent = (events, numberOfEvents) => (0, export
17
17
  exports.mockDimCustomFieldDefinitionEvent = mockDimCustomFieldDefinitionEvent;
18
18
  const mockDimCustomFieldValueEvent = (events, numberOfEvents) => (0, exports.mockEvent)(events, 'dim_custom_field_value', numberOfEvents);
19
19
  exports.mockDimCustomFieldValueEvent = mockDimCustomFieldValueEvent;
20
- //# sourceMappingURL=events.mock.js.map
@@ -0,0 +1,12 @@
1
+ import { TestModel } from '../../models';
2
+ export declare const createTestModel: (payload?: {}) => Promise<TestModel>;
3
+ export declare const createTestModels: (fleetId: any, total: number) => Promise<TestModel[]>;
4
+ export declare const upsertTestModel: (payload: any) => Promise<[TestModel, boolean]>;
5
+ export declare const destroyTestModels: () => Promise<number>;
6
+ export declare const getTestModel: (id: string, options?: {}) => Promise<TestModel>;
7
+ export declare const getSomeTestModels: (options?: {
8
+ limit: number;
9
+ }) => Promise<TestModel[]>;
10
+ export declare const updateTestModel: (payload: any, query: any) => Promise<[affectedCount: number, affectedRows: TestModel[]]>;
11
+ export declare const createTestModelWithAssociation: () => Promise<TestModel>;
12
+ export declare const getTestModelWithAssociation: (limit?: number) => Promise<TestModel[]>;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.getTestModelWithAssociation = exports.createTestModelWithAssociation = exports.updateTestModel = exports.getSomeTestModels = exports.getTestModel = exports.destroyTestModels = exports.upsertTestModel = exports.createTestModels = exports.createTestModel = void 0;
13
4
  const models_1 = require("../../models");
@@ -32,14 +23,13 @@ exports.getSomeTestModels = getSomeTestModels;
32
23
  const updateTestModel = (payload, query) => models_1.TestModel.update(payload, query);
33
24
  exports.updateTestModel = updateTestModel;
34
25
  // Associations
35
- const createTestModelWithAssociation = () => __awaiter(void 0, void 0, void 0, function* () {
36
- const model = yield models_1.TestModel.create({});
37
- yield models_1.AssociatedTestModel.create({ testModelId: model.id });
26
+ const createTestModelWithAssociation = async () => {
27
+ const model = await models_1.TestModel.create({});
28
+ await models_1.AssociatedTestModel.create({ testModelId: model.id });
38
29
  return model;
39
- });
30
+ };
40
31
  exports.createTestModelWithAssociation = createTestModelWithAssociation;
41
32
  const getTestModelWithAssociation = (limit = 1) => models_1.TestModel.findAll({
42
33
  limit, include: [models_1.AssociatedTestModel],
43
34
  });
44
35
  exports.getTestModelWithAssociation = getTestModelWithAssociation;
45
- //# sourceMappingURL=testModel.js.map
@@ -0,0 +1,23 @@
1
+ export interface CustomFieldDefinitionDTO {
2
+ id: string;
3
+ name: string;
4
+ displayName?: string;
5
+ validation?: any;
6
+ fieldType: string;
7
+ entityId: string;
8
+ entityType: string;
9
+ modelType: string;
10
+ required?: boolean;
11
+ description?: string;
12
+ disabled?: boolean;
13
+ createdAt?: Date;
14
+ updatedAt?: Date;
15
+ deletedAt?: Date;
16
+ }
17
+ export type CreateCustomFieldDefinition = Omit<CustomFieldDefinitionDTO, 'id'>;
18
+ export type UpdateCustomFieldDefinition = Partial<CreateCustomFieldDefinition>;
19
+ export type SerializedCustomFields = {
20
+ [name: string]: CustomFieldDefinitionDTO & {
21
+ value: any;
22
+ };
23
+ };
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=index.js.map
@@ -0,0 +1,13 @@
1
+ export type ModelFetcher = (name: string) => any;
2
+ export type ModelOptions = {
3
+ name: string;
4
+ scopeAttributes: string[];
5
+ creationWebhookHandler?: (instance: any) => any;
6
+ updateWebhookHandler?: (instance: any) => any;
7
+ deletionWebhookHandler?: (instance: any) => any;
8
+ };
9
+ export type CustomFieldOptions = {
10
+ models: ModelOptions[];
11
+ databaseConfig: any;
12
+ getUser: () => any;
13
+ };
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=index.js.map
@@ -0,0 +1,15 @@
1
+ export interface CustomFieldValueDTO {
2
+ id?: string;
3
+ modelId: string;
4
+ customFieldDefinitionId: string;
5
+ value: any;
6
+ createdAt?: Date;
7
+ updatedAt?: Date;
8
+ deletedAt?: Date;
9
+ }
10
+ export type ValuesToUpdate = {
11
+ [name: string]: any;
12
+ };
13
+ export type CreateCustomFieldValue = Omit<CustomFieldValueDTO, 'id'>;
14
+ export type UpdateCustomFieldValue = ValuesToUpdate;
15
+ export type BulkUpdateCustomFieldValue = Partial<CustomFieldValueDTO>[];
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ export declare const supportedEntities: string[];
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.supportedEntities = void 0;
4
+ // eslint-disable-next-line import/prefer-default-export
5
+ exports.supportedEntities = ['businessModelId', 'fleetId', 'demandSourceId'];
@@ -0,0 +1,4 @@
1
+ import { Sequelize } from 'sequelize-typescript';
2
+ declare const _default: (databaseConfig: any) => Sequelize;
3
+ export default _default;
4
+ export declare const createSequelizeMeta: (sequelize: Sequelize) => Promise<object[]>;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSequelizeMeta = void 0;
3
4
  const sequelize_typescript_1 = require("sequelize-typescript");
5
+ const sequelize_1 = require("sequelize");
4
6
  exports.default = (databaseConfig) => {
5
7
  const ENV_DEV = 'test';
6
8
  const env = process.env.NODE_ENV || ENV_DEV;
@@ -14,4 +16,9 @@ exports.default = (databaseConfig) => {
14
16
  }
15
17
  return sequelize;
16
18
  };
17
- //# sourceMappingURL=index.js.map
19
+ const createSequelizeMeta = (sequelize) => sequelize.query(`
20
+ CREATE TABLE IF NOT EXISTS "SequelizeMeta" (
21
+ name character varying(255) PRIMARY KEY
22
+ );
23
+ `, { type: sequelize_1.QueryTypes.SELECT });
24
+ exports.createSequelizeMeta = createSequelizeMeta;
@@ -0,0 +1,2 @@
1
+ declare const logger: any;
2
+ export default logger;
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  // eslint-disable-next-line @typescript-eslint/no-var-requires
4
4
  const Logger = require('@autofleet/logger');
5
- exports.default = Logger();
6
- //# sourceMappingURL=index.js.map
5
+ const logger = Logger();
6
+ exports.default = logger;
@@ -0,0 +1,2 @@
1
+ declare const CustomFieldsSchema: any;
2
+ export { CustomFieldsSchema };
@@ -8,4 +8,3 @@ exports.CustomFieldsSchema = void 0;
8
8
  const joi_1 = __importDefault(require("@hapi/joi"));
9
9
  const CustomFieldsSchema = joi_1.default.object().pattern(joi_1.default.string(), joi_1.default.any());
10
10
  exports.CustomFieldsSchema = CustomFieldsSchema;
11
- //# sourceMappingURL=custom-fields.js.map
@@ -0,0 +1,15 @@
1
+ export declare const mustHaveCustomValidation: {
2
+ select: boolean;
3
+ };
4
+ /**
5
+ * Validates the given validations object against the supported field types and their validators.
6
+ * @return true if the validation is valid, false otherwise.
7
+ */
8
+ export declare const validateValidation: (valueType: any, validation: any) => boolean;
9
+ /**
10
+ * Validates the given value against the custom validation rules for the specified field type.
11
+ * If no custom validation rules are provided, it falls back to the default validation.
12
+ * @returns true if the value is valid according to the validation rules, false otherwise.
13
+ */
14
+ declare const customValidation: (value: any, valueType: any, validation: any) => boolean;
15
+ export default customValidation;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.validateValidation = exports.mustHaveCustomValidation = void 0;
7
+ /* eslint-disable no-shadow */
8
+ const logger_1 = __importDefault(require("../logger"));
9
+ const type_1 = require("./type");
10
+ const validators_1 = __importDefault(require("./validators"));
11
+ exports.mustHaveCustomValidation = {
12
+ [type_1.CustomFieldDefinitionType.SELECT]: true,
13
+ };
14
+ /**
15
+ * Validates the given validations object against the supported field types and their validators.
16
+ * @return true if the validation is valid, false otherwise.
17
+ */
18
+ const validateValidation = (valueType, validation) => {
19
+ if (!validation) {
20
+ if (exports.mustHaveCustomValidation[valueType]) {
21
+ logger_1.default.error(`No custom validation for custom field type ${valueType} found`);
22
+ return false;
23
+ }
24
+ return true;
25
+ }
26
+ return true;
27
+ };
28
+ exports.validateValidation = validateValidation;
29
+ /**
30
+ * Validates the given value against the custom validation rules for the specified field type.
31
+ * If no custom validation rules are provided, it falls back to the default validation.
32
+ * @returns true if the value is valid according to the validation rules, false otherwise.
33
+ */
34
+ const customValidation = (value, valueType, validation) => {
35
+ const validator = validators_1.default?.[valueType];
36
+ if (!validation || !validator) {
37
+ return (0, exports.validateValidation)(valueType, validation);
38
+ }
39
+ // Always allow null values
40
+ return value === null || validator(value, validation);
41
+ };
42
+ exports.default = customValidation;
@@ -0,0 +1,2 @@
1
+ declare const validateValue: (value: any, valueType: any, customValidations: any) => boolean;
2
+ export default validateValue;
@@ -18,4 +18,3 @@ const validateValue = (value, valueType, customValidations) => {
18
18
  return true;
19
19
  };
20
20
  exports.default = validateValue;
21
- //# sourceMappingURL=index.js.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Supported custom field types
3
+ */
4
+ export declare enum CustomFieldDefinitionType {
5
+ NUMBER = "number",
6
+ BOOLEAN = "boolean",
7
+ DATE = "date",
8
+ DATETIME = "datetime",
9
+ TEXT = "text",
10
+ IMAGE = "image",
11
+ SELECT = "select"
12
+ }
13
+ /**
14
+ * Validate that the given value is really of type "valueType"
15
+ * TODO: verify that required field not set to null
16
+ */
17
+ declare const validateValueType: (value: unknown, valueType: CustomFieldDefinitionType) => boolean;
18
+ export default validateValueType;