@autofleet/sadot 0.0.2-beta → 0.1.1
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/dist/{src/api → api}/index.js +1 -0
- package/dist/api/index.js.map +1 -0
- package/dist/{src/api → api}/v1/definition/index.js +27 -23
- package/dist/api/v1/definition/index.js.map +1 -0
- package/dist/{src/api → api}/v1/definition/validations.js +1 -0
- package/dist/api/v1/definition/validations.js.map +1 -0
- package/dist/{src/api → api}/v1/errors.js +1 -0
- package/dist/api/v1/errors.js.map +1 -0
- package/dist/{src/api → api}/v1/index.js +1 -0
- package/dist/api/v1/index.js.map +1 -0
- package/dist/{src/errors → errors}/index.js +1 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/{src/events → events}/index.js +2 -21
- package/dist/events/index.js.map +1 -0
- package/dist/{src/hooks → hooks}/create.js +15 -10
- package/dist/hooks/create.js.map +1 -0
- package/dist/{src/hooks → hooks}/enrich.js +34 -42
- package/dist/hooks/enrich.js.map +1 -0
- package/dist/{src/hooks → hooks}/find.js +6 -9
- package/dist/hooks/find.js.map +1 -0
- package/dist/{src/hooks → hooks}/index.js +1 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/{src/hooks → hooks}/update.js +12 -7
- package/dist/hooks/update.js.map +1 -0
- package/dist/{src/hooks → hooks}/workaround.js +13 -3
- package/dist/hooks/workaround.js.map +1 -0
- package/dist/{src/index.js → index.js} +20 -21
- package/dist/index.js.map +1 -0
- package/dist/{src/models → models}/CustomFieldDefinition.js +3 -2
- package/dist/models/CustomFieldDefinition.js.map +1 -0
- package/dist/{src/models → models}/CustomFieldValue.js +34 -20
- package/dist/models/CustomFieldValue.js.map +1 -0
- package/dist/models/index.js +63 -0
- package/dist/models/index.js.map +1 -0
- package/dist/{src/models → models}/tests/AssociatedTestModel.js +1 -0
- package/dist/models/tests/AssociatedTestModel.js.map +1 -0
- package/dist/{src/models → models}/tests/TestModel.js +1 -0
- package/dist/models/tests/TestModel.js.map +1 -0
- package/dist/repository/definition.js +97 -0
- package/dist/repository/definition.js.map +1 -0
- package/dist/{src/repository → repository}/value.js +29 -20
- package/dist/repository/value.js.map +1 -0
- package/dist/{src/tests → tests}/api/test-api.js +22 -12
- package/dist/tests/api/test-api.js.map +1 -0
- package/dist/{src/tests → tests}/helpers/database-config.js +1 -0
- package/dist/tests/helpers/database-config.js.map +1 -0
- package/dist/tests/helpers/index.js +28 -0
- package/dist/tests/helpers/index.js.map +1 -0
- package/dist/{src/tests → tests}/mocks/definition.mock.js +13 -18
- package/dist/tests/mocks/definition.mock.js.map +1 -0
- package/dist/{src/tests → tests}/mocks/events.mock.js +1 -0
- package/dist/tests/mocks/events.mock.js.map +1 -0
- package/dist/{src/tests → tests}/mocks/testModel.js +14 -4
- package/dist/tests/mocks/testModel.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/{src/types → types}/definition/index.js +1 -0
- package/dist/types/definition/index.js.map +1 -0
- package/dist/{src/types → types}/index.js +1 -0
- package/dist/types/index.js.map +1 -0
- package/dist/{src/types → types}/value/index.js +1 -0
- package/dist/types/value/index.js.map +1 -0
- package/dist/{src/utils → utils}/db/index.js +1 -8
- package/dist/utils/db/index.js.map +1 -0
- package/dist/{src/utils → utils}/logger/index.js +2 -2
- package/dist/utils/logger/index.js.map +1 -0
- package/dist/{src/utils → utils}/validations/custom-fields.js +1 -0
- package/dist/utils/validations/custom-fields.js.map +1 -0
- package/dist/{src/utils → utils}/validations/custom.js +2 -1
- package/dist/utils/validations/custom.js.map +1 -0
- package/dist/{src/utils → utils}/validations/index.js +1 -0
- package/dist/utils/validations/index.js.map +1 -0
- package/dist/{src/utils → utils}/validations/type.js +2 -2
- package/dist/utils/validations/type.js.map +1 -0
- package/dist/{src/utils → utils}/validations/validators.js +1 -0
- package/dist/utils/validations/validators.js.map +1 -0
- package/package.json +1 -3
- package/src/api/v1/definition/index.ts +3 -10
- package/src/events/index.ts +1 -23
- package/src/hooks/create.ts +0 -2
- package/src/hooks/enrich.ts +18 -41
- package/src/hooks/find.ts +0 -2
- package/src/hooks/update.ts +0 -2
- package/src/index.ts +6 -19
- package/src/models/CustomFieldDefinition.ts +1 -1
- package/src/models/index.ts +17 -59
- package/src/repository/definition.ts +25 -22
- package/src/repository/value.ts +1 -2
- package/src/types/index.ts +4 -4
- package/src/utils/db/index.ts +0 -7
- package/src/utils/logger/index.ts +1 -3
- package/src/utils/validations/type.ts +1 -2
- package/tsconfig.json +25 -9
- package/dist/jest.config.d.ts +0 -12
- package/dist/src/api/index.d.ts +0 -2
- package/dist/src/api/v1/definition/index.d.ts +0 -2
- package/dist/src/api/v1/definition/validations.d.ts +0 -2
- package/dist/src/api/v1/errors.d.ts +0 -2
- package/dist/src/api/v1/index.d.ts +0 -2
- package/dist/src/errors/index.d.ts +0 -16
- package/dist/src/events/index.d.ts +0 -4
- package/dist/src/hooks/create.d.ts +0 -9
- package/dist/src/hooks/enrich.d.ts +0 -5
- package/dist/src/hooks/find.d.ts +0 -1
- package/dist/src/hooks/index.d.ts +0 -6
- package/dist/src/hooks/update.d.ts +0 -9
- package/dist/src/hooks/workaround.d.ts +0 -10
- package/dist/src/index.d.ts +0 -11
- package/dist/src/models/CustomFieldDefinition.d.ts +0 -23
- package/dist/src/models/CustomFieldValue.d.ts +0 -15
- package/dist/src/models/index.d.ts +0 -8
- package/dist/src/models/index.js +0 -87
- package/dist/src/models/tests/AssociatedTestModel.d.ts +0 -12
- package/dist/src/models/tests/TestModel.d.ts +0 -11
- package/dist/src/repository/definition.d.ts +0 -17
- package/dist/src/repository/definition.js +0 -80
- package/dist/src/repository/value.d.ts +0 -24
- package/dist/src/tests/api/test-api.d.ts +0 -2
- package/dist/src/tests/helpers/database-config.d.ts +0 -15
- package/dist/src/tests/helpers/index.d.ts +0 -2
- package/dist/src/tests/helpers/index.js +0 -18
- package/dist/src/tests/mocks/definition.mock.d.ts +0 -37
- package/dist/src/tests/mocks/events.mock.d.ts +0 -3
- package/dist/src/tests/mocks/testModel.d.ts +0 -12
- package/dist/src/types/definition/index.d.ts +0 -23
- package/dist/src/types/index.d.ts +0 -13
- package/dist/src/types/value/index.d.ts +0 -15
- package/dist/src/utils/constants/index.d.ts +0 -1
- package/dist/src/utils/constants/index.js +0 -5
- package/dist/src/utils/db/index.d.ts +0 -4
- package/dist/src/utils/logger/index.d.ts +0 -2
- package/dist/src/utils/validations/custom-fields.d.ts +0 -2
- package/dist/src/utils/validations/custom.d.ts +0 -15
- package/dist/src/utils/validations/index.d.ts +0 -2
- package/dist/src/utils/validations/type.d.ts +0 -18
- package/dist/src/utils/validations/validators.d.ts +0 -12
- package/src/utils/constants/index.ts +0 -2
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Sequelize } from 'sequelize-typescript';
|
|
2
|
-
import CustomFieldDefinition from './CustomFieldDefinition';
|
|
3
|
-
import CustomFieldValue from './CustomFieldValue';
|
|
4
|
-
import TestModel from './tests/TestModel';
|
|
5
|
-
import AssociatedTestModel from './tests/AssociatedTestModel';
|
|
6
|
-
declare const initTables: (sequelize: Sequelize, getUser: any) => Promise<void>;
|
|
7
|
-
declare const initTestModels: (sequelize: Sequelize) => Promise<void>;
|
|
8
|
-
export { CustomFieldValue, CustomFieldDefinition, TestModel, AssociatedTestModel, initTables, initTestModels, };
|
package/dist/src/models/index.js
DELETED
|
@@ -1,87 +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
|
-
exports.initTestModels = exports.initTables = exports.AssociatedTestModel = exports.TestModel = exports.CustomFieldDefinition = exports.CustomFieldValue = void 0;
|
|
7
|
-
/* eslint-disable no-param-reassign */
|
|
8
|
-
const sequelize_1 = require("sequelize");
|
|
9
|
-
const logger_1 = __importDefault(require("../utils/logger"));
|
|
10
|
-
const CustomFieldDefinition_1 = __importDefault(require("./CustomFieldDefinition"));
|
|
11
|
-
exports.CustomFieldDefinition = CustomFieldDefinition_1.default;
|
|
12
|
-
const CustomFieldValue_1 = __importDefault(require("./CustomFieldValue"));
|
|
13
|
-
exports.CustomFieldValue = CustomFieldValue_1.default;
|
|
14
|
-
const TestModel_1 = __importDefault(require("./tests/TestModel"));
|
|
15
|
-
exports.TestModel = TestModel_1.default;
|
|
16
|
-
const AssociatedTestModel_1 = __importDefault(require("./tests/AssociatedTestModel"));
|
|
17
|
-
exports.AssociatedTestModel = AssociatedTestModel_1.default;
|
|
18
|
-
const productionModels = [CustomFieldDefinition_1.default, CustomFieldValue_1.default];
|
|
19
|
-
const testModels = [TestModel_1.default, AssociatedTestModel_1.default];
|
|
20
|
-
const SADOT_MIGRATION_PREFIX = 'sadot-migration';
|
|
21
|
-
const SCHEMA_VERSION = 1;
|
|
22
|
-
const CUSTOM_FIELDS_SCHEMA_VERSION = `${SADOT_MIGRATION_PREFIX}_${SCHEMA_VERSION}`;
|
|
23
|
-
const initTables = async (sequelize, getUser) => {
|
|
24
|
-
logger_1.default.info('custom-fields: initialize custom-fields tables');
|
|
25
|
-
// Detect models and import them to the orm
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
27
|
-
if (!sequelize.addModels) {
|
|
28
|
-
throw new Error('sequelize instance must have addModels function');
|
|
29
|
-
}
|
|
30
|
-
sequelize.addModels(productionModels);
|
|
31
|
-
CustomFieldDefinition_1.default.addScope('userScope', () => {
|
|
32
|
-
const user = getUser();
|
|
33
|
-
if (user?.permissions) {
|
|
34
|
-
return {
|
|
35
|
-
where: {
|
|
36
|
-
entityId: [
|
|
37
|
-
...Object.keys(user.permissions.fleets),
|
|
38
|
-
...Object.keys(user.permissions.businessModels),
|
|
39
|
-
...Object.keys(user.permissions.demandSources),
|
|
40
|
-
],
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
return {};
|
|
45
|
-
});
|
|
46
|
-
logger_1.default.info('custom-fields: models added');
|
|
47
|
-
const SequelizeMeta = sequelize.define('SequelizeMeta', {
|
|
48
|
-
name: {
|
|
49
|
-
type: sequelize_1.DataTypes.STRING,
|
|
50
|
-
allowNull: false,
|
|
51
|
-
unique: true,
|
|
52
|
-
primaryKey: true,
|
|
53
|
-
autoIncrement: false,
|
|
54
|
-
},
|
|
55
|
-
}, {
|
|
56
|
-
tableName: 'SequelizeMeta',
|
|
57
|
-
timestamps: false,
|
|
58
|
-
schema: 'public',
|
|
59
|
-
});
|
|
60
|
-
const migrations = await SequelizeMeta.findAll({ raw: true });
|
|
61
|
-
const currentSadotSchemaVersion = migrations
|
|
62
|
-
.reverse().find((m) => m.name.includes(SADOT_MIGRATION_PREFIX));
|
|
63
|
-
if (!currentSadotSchemaVersion
|
|
64
|
-
|| currentSadotSchemaVersion.name !== CUSTOM_FIELDS_SCHEMA_VERSION) {
|
|
65
|
-
await CustomFieldDefinition_1.default.sync({ alter: true });
|
|
66
|
-
await CustomFieldValue_1.default.sync({ alter: true });
|
|
67
|
-
await SequelizeMeta.create({ name: CUSTOM_FIELDS_SCHEMA_VERSION });
|
|
68
|
-
logger_1.default.info('custom-fields: models synced');
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
exports.initTables = initTables;
|
|
72
|
-
const initTestModels = async (sequelize) => {
|
|
73
|
-
logger_1.default.info('custom-fields: initialize custom-fields test models');
|
|
74
|
-
// Detect models and import them to the orm
|
|
75
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
76
|
-
if (!sequelize.addModels) {
|
|
77
|
-
throw new Error('sequelize instance must have addModels function');
|
|
78
|
-
}
|
|
79
|
-
sequelize.addModels(testModels);
|
|
80
|
-
await sequelize.dropSchema('custom-fields', { logging: false });
|
|
81
|
-
await sequelize.createSchema('custom-fields', { logging: false });
|
|
82
|
-
logger_1.default.info('custom-fields: test models added');
|
|
83
|
-
await TestModel_1.default.sync({ alter: true });
|
|
84
|
-
await AssociatedTestModel_1.default.sync({ alter: true });
|
|
85
|
-
logger_1.default.info('custom-fields: test models synced');
|
|
86
|
-
};
|
|
87
|
-
exports.initTestModels = initTestModels;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Model } from 'sequelize-typescript';
|
|
2
|
-
import TestModel from './TestModel';
|
|
3
|
-
declare class AssociatedTestModel extends Model {
|
|
4
|
-
id: string;
|
|
5
|
-
testModelId: string;
|
|
6
|
-
fleetId: string;
|
|
7
|
-
businessModelId: string;
|
|
8
|
-
demandSourceId: string;
|
|
9
|
-
anotherAttribute?: boolean;
|
|
10
|
-
testModel: TestModel;
|
|
11
|
-
}
|
|
12
|
-
export default AssociatedTestModel;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Model } from 'sequelize-typescript';
|
|
2
|
-
import AssociatedTestModel from './AssociatedTestModel';
|
|
3
|
-
declare class TestModel extends Model {
|
|
4
|
-
id: string;
|
|
5
|
-
fleetId: string;
|
|
6
|
-
businessModelId: string;
|
|
7
|
-
demandSourceId: string;
|
|
8
|
-
coolAttribute?: boolean;
|
|
9
|
-
associatedModels: AssociatedTestModel[];
|
|
10
|
-
}
|
|
11
|
-
export default TestModel;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { CustomFieldDefinition } from '../models';
|
|
2
|
-
import type { CreateCustomFieldDefinition, UpdateCustomFieldDefinition } from '../types/definition';
|
|
3
|
-
export declare const create: (data: CreateCustomFieldDefinition) => Promise<CustomFieldDefinition>;
|
|
4
|
-
export declare const findAll: (where: any, options?: any) => Promise<CustomFieldDefinition[]>;
|
|
5
|
-
export declare const findByIds: (ids: string[], options?: any) => Promise<CustomFieldDefinition[]>;
|
|
6
|
-
export declare const findById: (id: string, options?: any) => Promise<CustomFieldDefinition | null>;
|
|
7
|
-
export declare const findByEntityId: (entityId: string, options?: any) => Promise<CustomFieldDefinition[]>;
|
|
8
|
-
export declare const findByEntityIds: (modelType: string, entityIds: string[], options?: any) => Promise<CustomFieldDefinition[]>;
|
|
9
|
-
export declare const findByWhere: (where: any) => Promise<CustomFieldDefinition | null>;
|
|
10
|
-
export declare const findDefinitionsByModels: (modelTypes: string[], options?: any) => Promise<CustomFieldDefinition[]>;
|
|
11
|
-
export declare const update: (id: string, data: UpdateCustomFieldDefinition) => Promise<CustomFieldDefinition>;
|
|
12
|
-
export declare const disable: (id: string) => Promise<any>;
|
|
13
|
-
export declare const destroy: (id: string) => Promise<any>;
|
|
14
|
-
/**
|
|
15
|
-
* Return the names of the required fields for a given model
|
|
16
|
-
*/
|
|
17
|
-
export declare const getRequiredFields: (modelType: string, modelId: string | string[], entityId: string | string[]) => Promise<string[]>;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRequiredFields = exports.destroy = exports.disable = exports.update = exports.findDefinitionsByModels = exports.findByWhere = exports.findByEntityIds = exports.findByEntityId = exports.findById = exports.findByIds = exports.findAll = exports.create = void 0;
|
|
4
|
-
const sequelize_1 = require("sequelize");
|
|
5
|
-
const models_1 = require("../models");
|
|
6
|
-
const create = (data) => models_1.CustomFieldDefinition.create(data);
|
|
7
|
-
exports.create = create;
|
|
8
|
-
const findAll = (where, options = { withDisabled: false }) => {
|
|
9
|
-
const queryModel = options.withDisabled
|
|
10
|
-
? models_1.CustomFieldDefinition.unscoped()
|
|
11
|
-
: models_1.CustomFieldDefinition;
|
|
12
|
-
return queryModel.scope('userScope').findAll({
|
|
13
|
-
where,
|
|
14
|
-
transaction: options.transaction,
|
|
15
|
-
raw: true,
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
exports.findAll = findAll;
|
|
19
|
-
const findByIds = (ids, options = { withDisabled: false }) => (0, exports.findAll)({ id: { [sequelize_1.Op.in]: ids } }, options);
|
|
20
|
-
exports.findByIds = findByIds;
|
|
21
|
-
const findById = (id, options = { withDisabled: false }) => {
|
|
22
|
-
const { withDisabled } = options;
|
|
23
|
-
if (withDisabled) {
|
|
24
|
-
return models_1.CustomFieldDefinition.unscoped().scope('userScope').findByPk(id);
|
|
25
|
-
}
|
|
26
|
-
return models_1.CustomFieldDefinition.scope('userScope').findByPk(id);
|
|
27
|
-
};
|
|
28
|
-
exports.findById = findById;
|
|
29
|
-
const findByEntityId = async (entityId, options = {}) => models_1.CustomFieldDefinition.findAll({
|
|
30
|
-
where: { entityId },
|
|
31
|
-
transaction: options.transaction,
|
|
32
|
-
});
|
|
33
|
-
exports.findByEntityId = findByEntityId;
|
|
34
|
-
const findByEntityIds = async (modelType, entityIds, options = {}) => models_1.CustomFieldDefinition.findAll({
|
|
35
|
-
where: {
|
|
36
|
-
modelType,
|
|
37
|
-
entityId: entityIds,
|
|
38
|
-
},
|
|
39
|
-
transaction: options.transaction,
|
|
40
|
-
raw: true,
|
|
41
|
-
});
|
|
42
|
-
exports.findByEntityIds = findByEntityIds;
|
|
43
|
-
const findByWhere = (where) => models_1.CustomFieldDefinition.scope('userScope').findOne({
|
|
44
|
-
where,
|
|
45
|
-
});
|
|
46
|
-
exports.findByWhere = findByWhere;
|
|
47
|
-
const findDefinitionsByModels = async (modelTypes, options) => {
|
|
48
|
-
const query = { modelType: { [sequelize_1.Op.in]: modelTypes } };
|
|
49
|
-
return models_1.CustomFieldDefinition.findAll({
|
|
50
|
-
where: query,
|
|
51
|
-
transaction: options?.transaction,
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
exports.findDefinitionsByModels = findDefinitionsByModels;
|
|
55
|
-
const update = async (id, data) => {
|
|
56
|
-
const updatedDefinition = (await models_1.CustomFieldDefinition.scope('userScope').update(data, {
|
|
57
|
-
where: { id },
|
|
58
|
-
returning: true,
|
|
59
|
-
individualHooks: true,
|
|
60
|
-
}))[1][0];
|
|
61
|
-
return updatedDefinition;
|
|
62
|
-
};
|
|
63
|
-
exports.update = update;
|
|
64
|
-
const disable = (id) => models_1.CustomFieldDefinition.update({ disabled: true }, { where: { id } });
|
|
65
|
-
exports.disable = disable;
|
|
66
|
-
const destroy = (id) => models_1.CustomFieldDefinition.destroy({ where: { id } });
|
|
67
|
-
exports.destroy = destroy;
|
|
68
|
-
/**
|
|
69
|
-
* Return the names of the required fields for a given model
|
|
70
|
-
*/
|
|
71
|
-
const getRequiredFields = async (modelType, modelId, entityId) => {
|
|
72
|
-
const entityIds = Array.isArray(entityId) ? entityId : [entityId];
|
|
73
|
-
const requiredFields = await models_1.CustomFieldDefinition.findAll({
|
|
74
|
-
where: { required: true, modelType, entityId: { [sequelize_1.Op.in]: entityIds } },
|
|
75
|
-
logging: true,
|
|
76
|
-
});
|
|
77
|
-
const requiredFieldsNames = requiredFields.map((definition) => definition.name);
|
|
78
|
-
return [...new Set(requiredFieldsNames)];
|
|
79
|
-
};
|
|
80
|
-
exports.getRequiredFields = getRequiredFields;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { CustomFieldValue } from '../models';
|
|
2
|
-
import { CreateCustomFieldValue, ValuesToUpdate } from '../types/value';
|
|
3
|
-
export declare const findByModelIdAndDefinition: (modelId: string, customFieldDefinitionId: string) => Promise<CustomFieldValue[]>;
|
|
4
|
-
export declare const create: (data: CreateCustomFieldValue, withAssociations?: boolean) => Promise<CustomFieldValue>;
|
|
5
|
-
export declare const findAllValues: () => Promise<CustomFieldValue[]>;
|
|
6
|
-
/**
|
|
7
|
-
* Get all values for model instance id (with their definitions)
|
|
8
|
-
* @param modelId
|
|
9
|
-
* @returns CustomFieldValue[]
|
|
10
|
-
*/
|
|
11
|
-
export declare const findValuesByModelId: (modelId: string) => Promise<CustomFieldValue[]>;
|
|
12
|
-
/**
|
|
13
|
-
* Retrieves custom field values for given model IDs
|
|
14
|
-
* @param modelIds - An array of model IDs to query custom field values for.
|
|
15
|
-
* @param options - Optional configuration object.
|
|
16
|
-
*/
|
|
17
|
-
export declare const findValuesByModelIds: (modelIds: string[], options?: any) => Promise<CustomFieldValue[]>;
|
|
18
|
-
/**
|
|
19
|
-
* Try to update custom field values for a model instance.
|
|
20
|
-
* Create new value record if not exists, but fails if value's definition not exist.
|
|
21
|
-
* Return the updated values
|
|
22
|
-
*/
|
|
23
|
-
export declare const updateValues: (modelType: string, modelId: string, identifiers: string[], valuesToUpdate: ValuesToUpdate, options?: any) => Promise<CustomFieldValue[]>;
|
|
24
|
-
export declare const deleteValue: (id: string, options?: any) => Promise<any>;
|
|
@@ -1,15 +0,0 @@
|
|
|
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;
|
|
@@ -1,18 +0,0 @@
|
|
|
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;
|
|
@@ -1,37 +0,0 @@
|
|
|
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[];
|
|
@@ -1,3 +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[];
|
|
@@ -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>;
|
|
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,23 +0,0 @@
|
|
|
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,13 +0,0 @@
|
|
|
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,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 +0,0 @@
|
|
|
1
|
-
export declare const supportedEntities: string[];
|
|
@@ -1,15 +0,0 @@
|
|
|
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;
|
|
@@ -1,18 +0,0 @@
|
|
|
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;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export declare enum CustomValidations {
|
|
2
|
-
SELECT = "select",
|
|
3
|
-
RANGE = "between"
|
|
4
|
-
}
|
|
5
|
-
type Validator = (value: any, validation: any) => boolean;
|
|
6
|
-
/**
|
|
7
|
-
* Validators for custom fields
|
|
8
|
-
*/
|
|
9
|
-
declare const validators: {
|
|
10
|
-
[key: string]: Validator;
|
|
11
|
-
};
|
|
12
|
-
export default validators;
|