@autofleet/sadot 0.12.0 → 0.13.0-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/package.json +3 -1
- package/src/api/v1/index.ts +2 -0
- package/src/api/v1/validator/index.ts +127 -0
- package/src/api/v1/validator/validations.ts +39 -0
- package/src/events/index.ts +1 -1
- package/src/hooks/hooks.ts +304 -0
- package/src/hooks/index.ts +10 -5
- package/src/index.ts +6 -0
- package/src/models/CustomValidator.ts +76 -0
- package/src/models/index.ts +7 -2
- package/src/repository/validator.ts +91 -0
- package/src/tests/helpers/commonHooks.ts +9 -2
- package/src/tests/helpers/index.ts +7 -2
- package/src/types/index.ts +1 -0
- package/src/utils/validations/schema/README.md +93 -0
- package/src/utils/validations/schema/validator-schema.ts +103 -0
- package/dist/api/index.d.ts +0 -3
- package/dist/api/index.js +0 -12
- package/dist/api/v1/definition/index.d.ts +0 -3
- package/dist/api/v1/definition/index.js +0 -116
- package/dist/api/v1/definition/validations.d.ts +0 -2
- package/dist/api/v1/definition/validations.js +0 -77
- package/dist/api/v1/errors.d.ts +0 -4
- package/dist/api/v1/errors.js +0 -12
- package/dist/api/v1/index.d.ts +0 -3
- package/dist/api/v1/index.js +0 -11
- package/dist/errors/index.d.ts +0 -24
- package/dist/errors/index.js +0 -66
- package/dist/events/index.d.ts +0 -4
- package/dist/events/index.js +0 -50
- package/dist/hooks/create.d.ts +0 -10
- package/dist/hooks/create.js +0 -95
- package/dist/hooks/enrich.d.ts +0 -30
- package/dist/hooks/enrich.js +0 -159
- package/dist/hooks/find.d.ts +0 -1
- package/dist/hooks/find.js +0 -29
- package/dist/hooks/index.d.ts +0 -6
- package/dist/hooks/index.js +0 -18
- package/dist/hooks/update.d.ts +0 -10
- package/dist/hooks/update.js +0 -49
- package/dist/hooks/utils/updateInstanceValues.d.ts +0 -15
- package/dist/hooks/utils/updateInstanceValues.js +0 -50
- package/dist/hooks/workaround.d.ts +0 -10
- package/dist/hooks/workaround.js +0 -37
- package/dist/index.d.ts +0 -13
- package/dist/index.js +0 -67
- package/dist/models/CustomFieldDefinition.d.ts +0 -25
- package/dist/models/CustomFieldDefinition.js +0 -192
- package/dist/models/CustomFieldEntries.d.ts +0 -15
- package/dist/models/CustomFieldEntries.js +0 -123
- package/dist/models/CustomFieldValue.d.ts +0 -16
- package/dist/models/CustomFieldValue.js +0 -151
- package/dist/models/index.d.ts +0 -17
- package/dist/models/index.js +0 -113
- package/dist/models/tests/AssociatedTestModel.d.ts +0 -12
- package/dist/models/tests/AssociatedTestModel.js +0 -71
- package/dist/models/tests/TestModel.d.ts +0 -12
- package/dist/models/tests/TestModel.js +0 -69
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.d.ts +0 -10
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js +0 -53
- package/dist/models/tests/contextAwareModels/ContextTestModel.d.ts +0 -13
- package/dist/models/tests/contextAwareModels/ContextTestModel.js +0 -47
- package/dist/repository/definition.d.ts +0 -36
- package/dist/repository/definition.js +0 -121
- package/dist/repository/entries.d.ts +0 -13
- package/dist/repository/entries.js +0 -92
- package/dist/repository/utils/formatValues.d.ts +0 -3
- package/dist/repository/utils/formatValues.js +0 -16
- package/dist/repository/value.d.ts +0 -28
- package/dist/repository/value.js +0 -124
- package/dist/scopes/filter.d.ts +0 -30
- package/dist/scopes/filter.js +0 -75
- package/dist/scopes/helpers/filter.helpers.d.ts +0 -42
- package/dist/scopes/helpers/filter.helpers.js +0 -204
- package/dist/scopes/index.d.ts +0 -2
- package/dist/scopes/index.js +0 -6
- package/dist/tests/api/test-api.d.ts +0 -2
- package/dist/tests/api/test-api.js +0 -38
- package/dist/tests/functional/searching/index.d.ts +0 -8
- package/dist/tests/functional/searching/index.js +0 -44
- package/dist/tests/helpers/commonHooks.d.ts +0 -5
- package/dist/tests/helpers/commonHooks.js +0 -55
- package/dist/tests/helpers/database-config.d.ts +0 -16
- package/dist/tests/helpers/database-config.js +0 -17
- package/dist/tests/helpers/index.d.ts +0 -7
- package/dist/tests/helpers/index.js +0 -29
- package/dist/tests/mocks/definition.mock.d.ts +0 -48
- package/dist/tests/mocks/definition.mock.js +0 -78
- package/dist/tests/mocks/events.mock.d.ts +0 -4
- package/dist/tests/mocks/events.mock.js +0 -21
- package/dist/tests/mocks/testModel.d.ts +0 -12
- package/dist/tests/mocks/testModel.js +0 -35
- package/dist/types/definition/index.d.ts +0 -25
- package/dist/types/definition/index.js +0 -2
- package/dist/types/entries/index.d.ts +0 -25
- package/dist/types/entries/index.js +0 -2
- package/dist/types/index.d.ts +0 -34
- package/dist/types/index.js +0 -2
- package/dist/types/value/index.d.ts +0 -15
- package/dist/types/value/index.js +0 -2
- package/dist/utils/constants/index.d.ts +0 -19
- package/dist/utils/constants/index.js +0 -22
- package/dist/utils/db/index.d.ts +0 -4
- package/dist/utils/db/index.js +0 -24
- package/dist/utils/helpers/index.d.ts +0 -26
- package/dist/utils/helpers/index.js +0 -40
- package/dist/utils/init.d.ts +0 -7
- package/dist/utils/init.js +0 -109
- package/dist/utils/logger/index.d.ts +0 -3
- package/dist/utils/logger/index.js +0 -42
- package/dist/utils/scopeAttributes.d.ts +0 -2
- package/dist/utils/scopeAttributes.js +0 -11
- package/dist/utils/validations/index.d.ts +0 -8
- package/dist/utils/validations/index.js +0 -41
- package/dist/utils/validations/schema/custom-fields.d.ts +0 -3
- package/dist/utils/validations/schema/custom-fields.js +0 -9
- package/dist/utils/validations/type.d.ts +0 -15
- package/dist/utils/validations/type.js +0 -2
- package/dist/utils/validations/validators/index.d.ts +0 -14
- package/dist/utils/validations/validators/index.js +0 -40
- package/dist/utils/validations/validators/select.validator.d.ts +0 -5
- package/dist/utils/validations/validators/select.validator.js +0 -12
- package/dist/utils/validations/validators/status.validator.d.ts +0 -12
- package/dist/utils/validations/validators/status.validator.js +0 -15
|
@@ -1,38 +0,0 @@
|
|
|
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
|
-
const express_1 = __importDefault(require("express"));
|
|
7
|
-
const node_common_1 = require("@autofleet/node-common");
|
|
8
|
-
const logger_1 = __importDefault(require("../../utils/logger"));
|
|
9
|
-
const models_1 = require("../../models");
|
|
10
|
-
const app = (0, express_1.default)();
|
|
11
|
-
app.use(express_1.default.json());
|
|
12
|
-
const api = (0, node_common_1.Router)({ logger: logger_1.default });
|
|
13
|
-
api.get('/v1/test-models', async (req, res) => {
|
|
14
|
-
const testModels = await models_1.TestModel.findAll();
|
|
15
|
-
return res.json(testModels);
|
|
16
|
-
});
|
|
17
|
-
api.get('/v1/test-models/:testModelId', async (req, res) => {
|
|
18
|
-
const { params: { testModelId } } = req;
|
|
19
|
-
const testModel = await models_1.TestModel.findByPk(testModelId);
|
|
20
|
-
return res.json(testModel);
|
|
21
|
-
});
|
|
22
|
-
api.post('/v1/test-models', async (req, res) => {
|
|
23
|
-
const { body } = req;
|
|
24
|
-
const testModel = await models_1.TestModel.create(body);
|
|
25
|
-
return res.json(testModel);
|
|
26
|
-
});
|
|
27
|
-
api.patch('/v1/test-models/:testModelId', async (req, res) => {
|
|
28
|
-
const { body, params: { testModelId } } = req;
|
|
29
|
-
const testModel = await models_1.TestModel.update(body, {
|
|
30
|
-
where: {
|
|
31
|
-
id: testModelId,
|
|
32
|
-
},
|
|
33
|
-
returning: true,
|
|
34
|
-
});
|
|
35
|
-
return res.json(testModel[1][0]);
|
|
36
|
-
});
|
|
37
|
-
app.use('/api', api);
|
|
38
|
-
exports.default = app;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
interface CustomFieldsSearchTestFlowInput {
|
|
2
|
-
fieldType: string;
|
|
3
|
-
fieldValue: string | number;
|
|
4
|
-
searchTerm: string;
|
|
5
|
-
expectedNumberOfQueryResults: number;
|
|
6
|
-
}
|
|
7
|
-
declare const customFieldsSearchTestFlow: ({ fieldType, fieldValue, searchTerm, expectedNumberOfQueryResults, }: CustomFieldsSearchTestFlowInput) => Promise<void>;
|
|
8
|
-
export default customFieldsSearchTestFlow;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const index_1 = require("../../../index");
|
|
27
|
-
const DefinitionRepo = __importStar(require("../../../repository/definition"));
|
|
28
|
-
const definition_mock_1 = require("../../mocks/definition.mock");
|
|
29
|
-
const testModel_1 = require("../../mocks/testModel");
|
|
30
|
-
const models_1 = require("../../../models");
|
|
31
|
-
const customFieldsSearchTestFlow = async ({ fieldType, fieldValue, searchTerm, expectedNumberOfQueryResults, }) => {
|
|
32
|
-
const definition = (0, definition_mock_1.createDefinition)({ fieldType, name: 'coolDefinition' });
|
|
33
|
-
await DefinitionRepo.create({ ...definition });
|
|
34
|
-
const [testModel1] = await (0, testModel_1.createTestModels)(definition.entityId, 2);
|
|
35
|
-
await testModel1.update({ customFields: { [definition.name]: fieldValue } });
|
|
36
|
-
const models = await models_1.TestModel.findAndCountAll({
|
|
37
|
-
...(0, index_1.generateCustomFieldSearchQueryPayload)(searchTerm, models_1.TestModel, definition.entityId),
|
|
38
|
-
});
|
|
39
|
-
expect(models.count).toBe(expectedNumberOfQueryResults);
|
|
40
|
-
if (expectedNumberOfQueryResults > 0) {
|
|
41
|
-
expect(models.rows[0].dataValues.id).toBe(testModel1.id);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
exports.default = customFieldsSearchTestFlow;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.commonTestHooks = void 0;
|
|
30
|
-
const __1 = __importDefault(require("../.."));
|
|
31
|
-
const _1 = require(".");
|
|
32
|
-
const database_config_1 = __importDefault(require("./database-config"));
|
|
33
|
-
const db_1 = __importStar(require("../../utils/db"));
|
|
34
|
-
function commonTestHooks(app = null, models = [{ name: 'TestModel', scopeAttributes: ['fleetId'] }], options = { useCustomFieldsEntries: false }) {
|
|
35
|
-
let sequelize;
|
|
36
|
-
beforeAll(async () => {
|
|
37
|
-
sequelize = (0, db_1.default)(database_config_1.default);
|
|
38
|
-
await (0, db_1.createSequelizeMeta)(sequelize);
|
|
39
|
-
await (0, __1.default)(app, _1.getModel, {
|
|
40
|
-
models,
|
|
41
|
-
databaseConfig: database_config_1.default,
|
|
42
|
-
getUser: () => undefined,
|
|
43
|
-
sequelize,
|
|
44
|
-
useCustomFieldsEntries: options.useCustomFieldsEntries,
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
afterEach(async () => {
|
|
48
|
-
jest.clearAllMocks();
|
|
49
|
-
await (0, _1.cleanup)({ useCustomFieldsEntries: options.useCustomFieldsEntries });
|
|
50
|
-
});
|
|
51
|
-
afterAll(async () => {
|
|
52
|
-
await sequelize.close();
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
exports.commonTestHooks = commonTestHooks;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
declare const _default: {
|
|
2
|
-
test: {
|
|
3
|
-
username: string;
|
|
4
|
-
password: string;
|
|
5
|
-
database: string;
|
|
6
|
-
host: string;
|
|
7
|
-
port: string | number;
|
|
8
|
-
dialect: string;
|
|
9
|
-
define: {
|
|
10
|
-
underscored: boolean;
|
|
11
|
-
underscoredAll: boolean;
|
|
12
|
-
};
|
|
13
|
-
logging: boolean;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
export default _default;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = {
|
|
4
|
-
test: {
|
|
5
|
-
username: process.env.DB_USERNAME || '',
|
|
6
|
-
password: process.env.DB_PASSWORD || null,
|
|
7
|
-
database: process.env.DB_NAME || 'sadot_package_test',
|
|
8
|
-
host: process.env.DB_HOST || '127.0.0.1',
|
|
9
|
-
port: process.env.DB_PORT || 5432,
|
|
10
|
-
dialect: process.env.DB_TYPE || 'postgres',
|
|
11
|
-
define: {
|
|
12
|
-
underscored: true,
|
|
13
|
-
underscoredAll: true,
|
|
14
|
-
},
|
|
15
|
-
logging: false,
|
|
16
|
-
},
|
|
17
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { CustomFieldOptions } from '../../types';
|
|
2
|
-
export declare const cleanup: (options?: Pick<CustomFieldOptions, 'useCustomFieldsEntries'>) => Promise<void>;
|
|
3
|
-
export declare const getModel: (name: string) => any;
|
|
4
|
-
export declare const getReplacementMapWithScopeValue: (conditions: Record<string, any>) => {
|
|
5
|
-
replacementsMap: Record<string, string>;
|
|
6
|
-
scopeValue: Record<string, any>;
|
|
7
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getReplacementMapWithScopeValue = exports.getModel = exports.cleanup = void 0;
|
|
4
|
-
const sheilta_1 = require("@autofleet/sheilta");
|
|
5
|
-
const models_1 = require("../../models");
|
|
6
|
-
// eslint-disable-next-line import/prefer-default-export
|
|
7
|
-
const cleanup = async (options) => {
|
|
8
|
-
if (process.env.NODE_ENV === 'test' || process.env.NODE_ENV === 'development') {
|
|
9
|
-
await models_1.CustomFieldDefinition.unscoped().destroy({ where: {} });
|
|
10
|
-
await models_1.TestModel.destroy({ where: {} });
|
|
11
|
-
await models_1.ContextAwareTestModel.destroy({ where: {} });
|
|
12
|
-
await models_1.ContextTestModel.destroy({ where: {} });
|
|
13
|
-
if (options?.useCustomFieldsEntries) {
|
|
14
|
-
await models_1.CustomFieldEntries.unscoped().destroy({ where: {} });
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
exports.cleanup = cleanup;
|
|
19
|
-
const getModel = (name) => {
|
|
20
|
-
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
21
|
-
const models = require('../../models');
|
|
22
|
-
return models[name];
|
|
23
|
-
};
|
|
24
|
-
exports.getModel = getModel;
|
|
25
|
-
const getReplacementMapWithScopeValue = (conditions) => ({
|
|
26
|
-
replacementsMap: (0, sheilta_1.generateFilterReplacements)(Object.fromEntries(Object.entries(conditions).map(([key, value]) => [`customFields.${key}`, value]))),
|
|
27
|
-
scopeValue: conditions,
|
|
28
|
-
});
|
|
29
|
-
exports.getReplacementMapWithScopeValue = getReplacementMapWithScopeValue;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { CreateCustomFieldDefinition, CustomFieldDefinitionDTO } from '../../types/definition';
|
|
2
|
-
export declare const contextAwareFieldDefinition: {
|
|
3
|
-
name: string;
|
|
4
|
-
modelType: string;
|
|
5
|
-
fieldType: string;
|
|
6
|
-
entityType: string;
|
|
7
|
-
};
|
|
8
|
-
export declare const coolFieldDefinition: CreateCustomFieldDefinition;
|
|
9
|
-
export declare const coolFieldDefinition2: {
|
|
10
|
-
name: string;
|
|
11
|
-
required?: boolean;
|
|
12
|
-
disabled?: boolean;
|
|
13
|
-
description?: string;
|
|
14
|
-
createdAt?: Date;
|
|
15
|
-
updatedAt?: Date;
|
|
16
|
-
deletedAt?: Date;
|
|
17
|
-
defaultValue?: any;
|
|
18
|
-
blockEditingFromUI?: boolean;
|
|
19
|
-
validation?: any;
|
|
20
|
-
fieldType: string;
|
|
21
|
-
displayName?: string;
|
|
22
|
-
entityId: string;
|
|
23
|
-
entityType: string;
|
|
24
|
-
modelType: string;
|
|
25
|
-
};
|
|
26
|
-
export declare const coolFieldDefinition3: {
|
|
27
|
-
name: string;
|
|
28
|
-
required?: boolean;
|
|
29
|
-
disabled?: boolean;
|
|
30
|
-
description?: string;
|
|
31
|
-
createdAt?: Date;
|
|
32
|
-
updatedAt?: Date;
|
|
33
|
-
deletedAt?: Date;
|
|
34
|
-
defaultValue?: any;
|
|
35
|
-
blockEditingFromUI?: boolean;
|
|
36
|
-
validation?: any;
|
|
37
|
-
fieldType: string;
|
|
38
|
-
displayName?: string;
|
|
39
|
-
entityId: string;
|
|
40
|
-
entityType: string;
|
|
41
|
-
modelType: string;
|
|
42
|
-
};
|
|
43
|
-
export declare const booleanField: (modelType: string) => CreateCustomFieldDefinition;
|
|
44
|
-
export declare const selectField: (modelType: string, options: any) => CreateCustomFieldDefinition;
|
|
45
|
-
export declare const statusField: (modelType: string, options: any) => CreateCustomFieldDefinition;
|
|
46
|
-
export declare const fileField: (modelType: string) => CreateCustomFieldDefinition;
|
|
47
|
-
export declare const createDefinition: (defaults: Partial<CustomFieldDefinitionDTO>) => CreateCustomFieldDefinition;
|
|
48
|
-
export declare const createDefinitions: (defaults: Partial<CustomFieldDefinitionDTO>, length?: number) => CreateCustomFieldDefinition[];
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createDefinitions = exports.createDefinition = exports.fileField = exports.statusField = exports.selectField = exports.booleanField = exports.coolFieldDefinition3 = exports.coolFieldDefinition2 = exports.coolFieldDefinition = exports.contextAwareFieldDefinition = void 0;
|
|
4
|
-
const node_crypto_1 = require("node:crypto");
|
|
5
|
-
exports.contextAwareFieldDefinition = {
|
|
6
|
-
name: 'cool field',
|
|
7
|
-
modelType: 'ContextAwareTestModel',
|
|
8
|
-
fieldType: 'number',
|
|
9
|
-
entityType: 'fleetId',
|
|
10
|
-
};
|
|
11
|
-
exports.coolFieldDefinition = {
|
|
12
|
-
name: 'cool field',
|
|
13
|
-
modelType: 'TestModel',
|
|
14
|
-
fieldType: 'number',
|
|
15
|
-
entityId: (0, node_crypto_1.randomUUID)(),
|
|
16
|
-
entityType: 'fleetId',
|
|
17
|
-
};
|
|
18
|
-
exports.coolFieldDefinition2 = {
|
|
19
|
-
...exports.coolFieldDefinition,
|
|
20
|
-
name: 'cool field2',
|
|
21
|
-
};
|
|
22
|
-
exports.coolFieldDefinition3 = {
|
|
23
|
-
...exports.coolFieldDefinition,
|
|
24
|
-
name: 'cool field3',
|
|
25
|
-
};
|
|
26
|
-
const booleanField = (modelType) => ({
|
|
27
|
-
name: 'shapeless',
|
|
28
|
-
modelType,
|
|
29
|
-
fieldType: 'boolean',
|
|
30
|
-
entityId: (0, node_crypto_1.randomUUID)(),
|
|
31
|
-
entityType: 'fleetId',
|
|
32
|
-
});
|
|
33
|
-
exports.booleanField = booleanField;
|
|
34
|
-
const selectField = (modelType, options) => ({
|
|
35
|
-
name: 'choices',
|
|
36
|
-
modelType,
|
|
37
|
-
fieldType: 'select',
|
|
38
|
-
validation: options,
|
|
39
|
-
entityId: (0, node_crypto_1.randomUUID)(),
|
|
40
|
-
entityType: 'fleetId',
|
|
41
|
-
});
|
|
42
|
-
exports.selectField = selectField;
|
|
43
|
-
const statusField = (modelType, options) => ({
|
|
44
|
-
name: 'lifecycle',
|
|
45
|
-
modelType,
|
|
46
|
-
fieldType: 'status',
|
|
47
|
-
validation: options,
|
|
48
|
-
entityId: (0, node_crypto_1.randomUUID)(),
|
|
49
|
-
entityType: 'fleetId',
|
|
50
|
-
});
|
|
51
|
-
exports.statusField = statusField;
|
|
52
|
-
const fileField = (modelType) => ({
|
|
53
|
-
name: 'file',
|
|
54
|
-
modelType,
|
|
55
|
-
fieldType: 'file',
|
|
56
|
-
entityId: (0, node_crypto_1.randomUUID)(),
|
|
57
|
-
entityType: 'fleetId',
|
|
58
|
-
});
|
|
59
|
-
exports.fileField = fileField;
|
|
60
|
-
// eslint-disable-next-line max-len
|
|
61
|
-
const createDefinition = (defaults) => ({
|
|
62
|
-
name: defaults?.name || `def_${(0, node_crypto_1.randomUUID)()}`,
|
|
63
|
-
modelType: defaults?.modelType || 'TestModel',
|
|
64
|
-
fieldType: defaults?.fieldType || 'boolean',
|
|
65
|
-
entityId: defaults?.entityId || (0, node_crypto_1.randomUUID)(),
|
|
66
|
-
entityType: defaults?.entityType || 'fleetId',
|
|
67
|
-
...(defaults?.validation && { validation: defaults.validation }),
|
|
68
|
-
...(defaults?.defaultValue && { defaultValue: defaults.defaultValue }),
|
|
69
|
-
});
|
|
70
|
-
exports.createDefinition = createDefinition;
|
|
71
|
-
const createDefinitions = (defaults, length = 1) => (Array(length).fill({}).map((_) => ({
|
|
72
|
-
name: defaults?.name || `def_${(0, node_crypto_1.randomUUID)()}`,
|
|
73
|
-
modelType: defaults?.modelType || 'TestModel',
|
|
74
|
-
fieldType: defaults?.fieldType || 'boolean',
|
|
75
|
-
entityId: defaults?.entityId || (0, node_crypto_1.randomUUID)(),
|
|
76
|
-
entityType: defaults?.entityType || 'fleetId',
|
|
77
|
-
})));
|
|
78
|
-
exports.createDefinitions = createDefinitions;
|
|
@@ -1,4 +0,0 @@
|
|
|
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[];
|
|
4
|
-
export declare const mockDimCustomFieldEntriesEvent: (events: any, numberOfEvents: any) => any[];
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable no-param-reassign */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.mockDimCustomFieldEntriesEvent = exports.mockDimCustomFieldValueEvent = exports.mockDimCustomFieldDefinitionEvent = exports.mockEvent = void 0;
|
|
5
|
-
const mockEvent = (events, eventName, numberOfEvents) => {
|
|
6
|
-
events.sendObject = jest.fn().mockResolvedValue(true);
|
|
7
|
-
return [
|
|
8
|
-
events.sendObject,
|
|
9
|
-
() => {
|
|
10
|
-
const matchingEvents = events.sendObject.mock.calls.filter((call) => call[0] === eventName);
|
|
11
|
-
expect(matchingEvents.length).toEqual(numberOfEvents);
|
|
12
|
-
},
|
|
13
|
-
];
|
|
14
|
-
};
|
|
15
|
-
exports.mockEvent = mockEvent;
|
|
16
|
-
const mockDimCustomFieldDefinitionEvent = (events, numberOfEvents) => (0, exports.mockEvent)(events, 'dim_custom_field_definition', numberOfEvents);
|
|
17
|
-
exports.mockDimCustomFieldDefinitionEvent = mockDimCustomFieldDefinitionEvent;
|
|
18
|
-
const mockDimCustomFieldValueEvent = (events, numberOfEvents) => (0, exports.mockEvent)(events, 'dim_custom_field_value', numberOfEvents);
|
|
19
|
-
exports.mockDimCustomFieldValueEvent = mockDimCustomFieldValueEvent;
|
|
20
|
-
const mockDimCustomFieldEntriesEvent = (events, numberOfEvents) => (0, exports.mockEvent)(events, 'dim_custom_field_entries', numberOfEvents);
|
|
21
|
-
exports.mockDimCustomFieldEntriesEvent = mockDimCustomFieldEntriesEvent;
|
|
@@ -1,12 +0,0 @@
|
|
|
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 | null>;
|
|
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,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTestModelWithAssociation = exports.createTestModelWithAssociation = exports.updateTestModel = exports.getSomeTestModels = exports.getTestModel = exports.destroyTestModels = exports.upsertTestModel = exports.createTestModels = exports.createTestModel = void 0;
|
|
4
|
-
const models_1 = require("../../models");
|
|
5
|
-
const createTestModel = (payload = {}) => models_1.TestModel.create(payload);
|
|
6
|
-
exports.createTestModel = createTestModel;
|
|
7
|
-
const createTestModels = (fleetId, total) => {
|
|
8
|
-
const models = [];
|
|
9
|
-
for (let i = 0; i < total; i += 1) {
|
|
10
|
-
models.push((0, exports.createTestModel)({ fleetId }));
|
|
11
|
-
}
|
|
12
|
-
return Promise.all(models);
|
|
13
|
-
};
|
|
14
|
-
exports.createTestModels = createTestModels;
|
|
15
|
-
const upsertTestModel = (payload) => models_1.TestModel.upsert(payload);
|
|
16
|
-
exports.upsertTestModel = upsertTestModel;
|
|
17
|
-
const destroyTestModels = () => models_1.TestModel.destroy({ truncate: true });
|
|
18
|
-
exports.destroyTestModels = destroyTestModels;
|
|
19
|
-
const getTestModel = (id, options = {}) => models_1.TestModel.findByPk(id, options);
|
|
20
|
-
exports.getTestModel = getTestModel;
|
|
21
|
-
const getSomeTestModels = (options = { limit: 1 }) => models_1.TestModel.findAll(options);
|
|
22
|
-
exports.getSomeTestModels = getSomeTestModels;
|
|
23
|
-
const updateTestModel = (payload, query) => models_1.TestModel.update(payload, query);
|
|
24
|
-
exports.updateTestModel = updateTestModel;
|
|
25
|
-
// Associations
|
|
26
|
-
const createTestModelWithAssociation = async () => {
|
|
27
|
-
const model = await models_1.TestModel.create({});
|
|
28
|
-
await models_1.AssociatedTestModel.create({ testModelId: model.id });
|
|
29
|
-
return model;
|
|
30
|
-
};
|
|
31
|
-
exports.createTestModelWithAssociation = createTestModelWithAssociation;
|
|
32
|
-
const getTestModelWithAssociation = (limit = 1) => models_1.TestModel.findAll({
|
|
33
|
-
limit, include: [models_1.AssociatedTestModel],
|
|
34
|
-
});
|
|
35
|
-
exports.getTestModelWithAssociation = getTestModelWithAssociation;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export interface CustomFieldDefinitionDTO {
|
|
2
|
-
id: string;
|
|
3
|
-
name: string;
|
|
4
|
-
displayName?: string;
|
|
5
|
-
validation?: any;
|
|
6
|
-
defaultValue?: any;
|
|
7
|
-
fieldType: string;
|
|
8
|
-
entityId: string;
|
|
9
|
-
entityType: string;
|
|
10
|
-
modelType: string;
|
|
11
|
-
required?: boolean;
|
|
12
|
-
description?: string;
|
|
13
|
-
disabled?: boolean;
|
|
14
|
-
createdAt?: Date;
|
|
15
|
-
updatedAt?: Date;
|
|
16
|
-
deletedAt?: Date;
|
|
17
|
-
blockEditingFromUI?: boolean;
|
|
18
|
-
}
|
|
19
|
-
export type CreateCustomFieldDefinition = Omit<CustomFieldDefinitionDTO, 'id'>;
|
|
20
|
-
export type UpdateCustomFieldDefinition = Partial<CreateCustomFieldDefinition>;
|
|
21
|
-
export type SerializedCustomFields = {
|
|
22
|
-
[name: string]: CustomFieldDefinitionDTO & {
|
|
23
|
-
value: any;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { ValidationError } from 'joi';
|
|
2
|
-
export interface CustomFieldEntriesDTO {
|
|
3
|
-
modelId: string;
|
|
4
|
-
entityId: string;
|
|
5
|
-
modelType: string;
|
|
6
|
-
/**
|
|
7
|
-
* A collection of custom fields where each key is the name of a CustomFieldDefinition and
|
|
8
|
-
* each value is the value of that custom field for this specific `modelId`.
|
|
9
|
-
*
|
|
10
|
-
* Example:
|
|
11
|
-
* {
|
|
12
|
-
* "vehicleColor": "Red",
|
|
13
|
-
* "vehicleType": "premium",
|
|
14
|
-
* "isActive": true
|
|
15
|
-
* }
|
|
16
|
-
*/
|
|
17
|
-
customFields: Record<string, any>;
|
|
18
|
-
createdAt?: Date;
|
|
19
|
-
updatedAt?: Date;
|
|
20
|
-
}
|
|
21
|
-
export interface EntriesValidationError {
|
|
22
|
-
value: any;
|
|
23
|
-
fieldDefinitionName: string;
|
|
24
|
-
joiValidationError: ValidationError;
|
|
25
|
-
}
|
package/dist/types/index.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { IncludeOptions } from 'sequelize';
|
|
2
|
-
import type { ModelCtor, Sequelize } from 'sequelize-typescript';
|
|
3
|
-
import type { getUser as GetUserType } from '@autofleet/zehut';
|
|
4
|
-
export type ModelFetcher = (name: string) => any;
|
|
5
|
-
export type ModelOptions = {
|
|
6
|
-
/**
|
|
7
|
-
* Include options for the model
|
|
8
|
-
*/
|
|
9
|
-
include?: (entityIds: string[]) => IncludeOptions[];
|
|
10
|
-
/**
|
|
11
|
-
* Custom association for the model
|
|
12
|
-
* @param model - The model to associate with
|
|
13
|
-
*/
|
|
14
|
-
customAssociation?: (model: ModelCtor) => void;
|
|
15
|
-
/**
|
|
16
|
-
* Whether to use the entity id from the instance per scope attribute
|
|
17
|
-
*/
|
|
18
|
-
useEntityIdFromInclude?: boolean;
|
|
19
|
-
};
|
|
20
|
-
export type Models = {
|
|
21
|
-
name: string;
|
|
22
|
-
scopeAttributes: any[];
|
|
23
|
-
modelOptions?: ModelOptions;
|
|
24
|
-
creationWebhookHandler?: (instance: any) => any;
|
|
25
|
-
updateWebhookHandler?: (instance: any) => any;
|
|
26
|
-
deletionWebhookHandler?: (instance: any) => any;
|
|
27
|
-
};
|
|
28
|
-
export type CustomFieldOptions = {
|
|
29
|
-
models: Models[];
|
|
30
|
-
databaseConfig: any;
|
|
31
|
-
getUser: typeof GetUserType;
|
|
32
|
-
sequelize?: Sequelize;
|
|
33
|
-
useCustomFieldsEntries?: boolean;
|
|
34
|
-
};
|
package/dist/types/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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,19 +0,0 @@
|
|
|
1
|
-
declare const CUSTOM_FIELDS_FILTER_SCOPE: "filterByCustomFields";
|
|
2
|
-
export declare const supportedEntities: string[];
|
|
3
|
-
/**
|
|
4
|
-
* Supported custom field types
|
|
5
|
-
*/
|
|
6
|
-
export declare enum CustomFieldDefinitionType {
|
|
7
|
-
NUMBER = "number",
|
|
8
|
-
BOOLEAN = "boolean",
|
|
9
|
-
DATE = "date",
|
|
10
|
-
DATETIME = "datetime",
|
|
11
|
-
TEXT = "text",
|
|
12
|
-
IMAGE = "image",
|
|
13
|
-
SELECT = "select",
|
|
14
|
-
STATUS = "status",
|
|
15
|
-
FILE = "file"
|
|
16
|
-
}
|
|
17
|
-
export {
|
|
18
|
-
/** @deprecated Use the value from `@autofleet/common-types` instead */
|
|
19
|
-
CUSTOM_FIELDS_FILTER_SCOPE, };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CUSTOM_FIELDS_FILTER_SCOPE = exports.CustomFieldDefinitionType = exports.supportedEntities = void 0;
|
|
4
|
-
const common_types_1 = require("@autofleet/common-types");
|
|
5
|
-
const { CUSTOM_FIELDS_FILTER_SCOPE } = common_types_1.customFields;
|
|
6
|
-
exports.CUSTOM_FIELDS_FILTER_SCOPE = CUSTOM_FIELDS_FILTER_SCOPE;
|
|
7
|
-
exports.supportedEntities = ['businessModelId', 'fleetId', 'demandSourceId'];
|
|
8
|
-
/**
|
|
9
|
-
* Supported custom field types
|
|
10
|
-
*/
|
|
11
|
-
var CustomFieldDefinitionType;
|
|
12
|
-
(function (CustomFieldDefinitionType) {
|
|
13
|
-
CustomFieldDefinitionType["NUMBER"] = "number";
|
|
14
|
-
CustomFieldDefinitionType["BOOLEAN"] = "boolean";
|
|
15
|
-
CustomFieldDefinitionType["DATE"] = "date";
|
|
16
|
-
CustomFieldDefinitionType["DATETIME"] = "datetime";
|
|
17
|
-
CustomFieldDefinitionType["TEXT"] = "text";
|
|
18
|
-
CustomFieldDefinitionType["IMAGE"] = "image";
|
|
19
|
-
CustomFieldDefinitionType["SELECT"] = "select";
|
|
20
|
-
CustomFieldDefinitionType["STATUS"] = "status";
|
|
21
|
-
CustomFieldDefinitionType["FILE"] = "file";
|
|
22
|
-
})(CustomFieldDefinitionType || (exports.CustomFieldDefinitionType = CustomFieldDefinitionType = {}));
|
package/dist/utils/db/index.d.ts
DELETED
package/dist/utils/db/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createSequelizeMeta = void 0;
|
|
4
|
-
const sequelize_typescript_1 = require("sequelize-typescript");
|
|
5
|
-
const sequelize_1 = require("sequelize");
|
|
6
|
-
exports.default = (databaseConfig) => {
|
|
7
|
-
const ENV_DEV = 'test';
|
|
8
|
-
const env = process.env.NODE_ENV || ENV_DEV;
|
|
9
|
-
const config = databaseConfig[env];
|
|
10
|
-
let sequelize;
|
|
11
|
-
if (config.use_env_variable) {
|
|
12
|
-
sequelize = new sequelize_typescript_1.Sequelize(process.env[config.use_env_variable], config);
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
sequelize = new sequelize_typescript_1.Sequelize(config.database, config.username, config.password, config);
|
|
16
|
-
}
|
|
17
|
-
return sequelize;
|
|
18
|
-
};
|
|
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;
|