@autofleet/sadot 1.1.7-beta → 1.1.7
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/_virtual/_@oxc-project_runtime@0.103.0/helpers/decorate.cjs +1 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/decorate.js +1 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.cjs +1 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.js +1 -0
- package/dist/_virtual/rolldown_runtime.cjs +1 -0
- package/dist/api/index.cjs +2 -0
- package/dist/api/index.cjs.map +1 -0
- package/dist/api/index.js +2 -12
- package/dist/api/index.js.map +1 -0
- package/dist/api/v1/definition/index.cjs +2 -0
- package/dist/api/v1/definition/index.cjs.map +1 -0
- package/dist/api/v1/definition/index.js +2 -116
- package/dist/api/v1/definition/index.js.map +1 -0
- package/dist/api/v1/definition/validations.cjs +2 -0
- package/dist/api/v1/definition/validations.cjs.map +1 -0
- package/dist/api/v1/definition/validations.js +2 -77
- package/dist/api/v1/definition/validations.js.map +1 -0
- package/dist/api/v1/errors.cjs +2 -0
- package/dist/api/v1/errors.cjs.map +1 -0
- package/dist/api/v1/errors.js +2 -12
- package/dist/api/v1/errors.js.map +1 -0
- package/dist/api/v1/index.cjs +2 -0
- package/dist/api/v1/index.cjs.map +1 -0
- package/dist/api/v1/index.js +2 -13
- package/dist/api/v1/index.js.map +1 -0
- package/dist/api/v1/validator/index.cjs +2 -0
- package/dist/api/v1/validator/index.cjs.map +1 -0
- package/dist/api/v1/validator/index.js +2 -143
- package/dist/api/v1/validator/index.js.map +1 -0
- package/dist/api/v1/validator/validations.cjs +2 -0
- package/dist/api/v1/validator/validations.cjs.map +1 -0
- package/dist/api/v1/validator/validations.d.cts +23 -0
- package/dist/api/v1/validator/validations.d.ts +23 -6
- package/dist/api/v1/validator/validations.js +2 -38
- package/dist/api/v1/validator/validations.js.map +1 -0
- package/dist/errors/index.cjs +3 -0
- package/dist/errors/index.cjs.map +1 -0
- package/dist/errors/index.js +3 -66
- package/dist/errors/index.js.map +1 -0
- package/dist/events/index.cjs +2 -0
- package/dist/events/index.cjs.map +1 -0
- package/dist/events/index.js +2 -54
- package/dist/events/index.js.map +1 -0
- package/dist/hooks/enrich.cjs +2 -0
- package/dist/hooks/enrich.cjs.map +1 -0
- package/dist/hooks/enrich.js +2 -198
- package/dist/hooks/enrich.js.map +1 -0
- package/dist/hooks/find.cjs +2 -0
- package/dist/hooks/find.cjs.map +1 -0
- package/dist/hooks/find.js +2 -29
- package/dist/hooks/find.js.map +1 -0
- package/dist/hooks/hooks.cjs +2 -0
- package/dist/hooks/hooks.cjs.map +1 -0
- package/dist/hooks/hooks.js +2 -388
- package/dist/hooks/hooks.js.map +1 -0
- package/dist/hooks/index.cjs +1 -0
- package/dist/hooks/index.js +1 -17
- package/dist/hooks/utils/updateInstanceValues.cjs +2 -0
- package/dist/hooks/utils/updateInstanceValues.cjs.map +1 -0
- package/dist/hooks/utils/updateInstanceValues.js +2 -50
- package/dist/hooks/utils/updateInstanceValues.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +23 -0
- package/dist/index.d.ts +22 -12
- package/dist/index.js +2 -67
- package/dist/index.js.map +1 -0
- package/dist/models/CustomFieldDefinition.cjs +2 -0
- package/dist/models/CustomFieldDefinition.cjs.map +1 -0
- package/dist/models/CustomFieldDefinition.d.cts +31 -0
- package/dist/models/CustomFieldDefinition.d.ts +29 -23
- package/dist/models/CustomFieldDefinition.js +2 -192
- package/dist/models/CustomFieldDefinition.js.map +1 -0
- package/dist/models/CustomFieldEntries.cjs +2 -0
- package/dist/models/CustomFieldEntries.cjs.map +1 -0
- package/dist/models/CustomFieldEntries.d.cts +16 -0
- package/dist/models/CustomFieldEntries.d.ts +14 -13
- package/dist/models/CustomFieldEntries.js +2 -123
- package/dist/models/CustomFieldEntries.js.map +1 -0
- package/dist/models/CustomFieldValue.cjs +2 -0
- package/dist/models/CustomFieldValue.cjs.map +1 -0
- package/dist/models/CustomFieldValue.d.cts +22 -0
- package/dist/models/CustomFieldValue.d.ts +20 -14
- package/dist/models/CustomFieldValue.js +2 -151
- package/dist/models/CustomFieldValue.js.map +1 -0
- package/dist/models/CustomValidator.cjs +2 -0
- package/dist/models/CustomValidator.cjs.map +1 -0
- package/dist/models/CustomValidator.d.cts +19 -0
- package/dist/models/CustomValidator.d.ts +17 -15
- package/dist/models/CustomValidator.js +2 -98
- package/dist/models/CustomValidator.js.map +1 -0
- package/dist/models/index.cjs +2 -0
- package/dist/models/index.cjs.map +1 -0
- package/dist/models/index.d.cts +6 -0
- package/dist/models/index.d.ts +6 -18
- package/dist/models/index.js +2 -131
- package/dist/models/index.js.map +1 -0
- package/dist/models/tests/AssociatedTestModel.cjs +2 -0
- package/dist/models/tests/AssociatedTestModel.cjs.map +1 -0
- package/dist/models/tests/AssociatedTestModel.js +2 -71
- package/dist/models/tests/AssociatedTestModel.js.map +1 -0
- package/dist/models/tests/TestModel.cjs +2 -0
- package/dist/models/tests/TestModel.cjs.map +1 -0
- package/dist/models/tests/TestModel.js +2 -69
- package/dist/models/tests/TestModel.js.map +1 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs +2 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs.map +1 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js +2 -53
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js.map +1 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.cjs +2 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.cjs.map +1 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.js +2 -47
- package/dist/models/tests/contextAwareModels/ContextTestModel.js.map +1 -0
- package/dist/repository/definition.cjs +2 -0
- package/dist/repository/definition.cjs.map +1 -0
- package/dist/repository/definition.js +2 -121
- package/dist/repository/definition.js.map +1 -0
- package/dist/repository/entries.cjs +2 -0
- package/dist/repository/entries.cjs.map +1 -0
- package/dist/repository/entries.js +2 -92
- package/dist/repository/entries.js.map +1 -0
- package/dist/repository/utils/formatValues.cjs +2 -0
- package/dist/repository/utils/formatValues.cjs.map +1 -0
- package/dist/repository/utils/formatValues.js +2 -16
- package/dist/repository/utils/formatValues.js.map +1 -0
- package/dist/repository/validator.cjs +2 -0
- package/dist/repository/validator.cjs.map +1 -0
- package/dist/repository/validator.js +2 -69
- package/dist/repository/validator.js.map +1 -0
- package/dist/repository/value.cjs +2 -0
- package/dist/repository/value.cjs.map +1 -0
- package/dist/repository/value.js +2 -124
- package/dist/repository/value.js.map +1 -0
- package/dist/scopes/filter.cjs +2 -0
- package/dist/scopes/filter.cjs.map +1 -0
- package/dist/scopes/filter.d.cts +23 -0
- package/dist/scopes/filter.d.ts +22 -29
- package/dist/scopes/filter.js +2 -75
- package/dist/scopes/filter.js.map +1 -0
- package/dist/scopes/helpers/filter.helpers.cjs +46 -0
- package/dist/scopes/helpers/filter.helpers.cjs.map +1 -0
- package/dist/scopes/helpers/filter.helpers.d.cts +17 -0
- package/dist/scopes/helpers/filter.helpers.d.ts +15 -40
- package/dist/scopes/helpers/filter.helpers.js +25 -183
- package/dist/scopes/helpers/filter.helpers.js.map +1 -0
- package/dist/scopes/index.cjs +1 -0
- package/dist/scopes/index.js +1 -6
- package/dist/types/index.d.cts +45 -0
- package/dist/types/index.d.ts +45 -46
- package/dist/utils/constants/index.cjs +2 -0
- package/dist/utils/constants/index.cjs.map +1 -0
- package/dist/utils/constants/index.d.cts +22 -0
- package/dist/utils/constants/index.d.ts +20 -17
- package/dist/utils/constants/index.js +2 -22
- package/dist/utils/constants/index.js.map +1 -0
- package/dist/utils/db/index.cjs +2 -0
- package/dist/utils/db/index.cjs.map +1 -0
- package/dist/utils/db/index.js +2 -24
- package/dist/utils/db/index.js.map +1 -0
- package/dist/utils/helpers/index.cjs +2 -0
- package/dist/utils/helpers/index.cjs.map +1 -0
- package/dist/utils/helpers/index.d.cts +31 -0
- package/dist/utils/helpers/index.d.ts +28 -23
- package/dist/utils/helpers/index.js +2 -40
- package/dist/utils/helpers/index.js.map +1 -0
- package/dist/utils/init.cjs +2 -0
- package/dist/utils/init.cjs.map +1 -0
- package/dist/utils/init.js +2 -112
- package/dist/utils/init.js.map +1 -0
- package/dist/utils/logger/index.cjs +2 -0
- package/dist/utils/logger/index.cjs.map +1 -0
- package/dist/utils/logger/index.js +2 -42
- package/dist/utils/logger/index.js.map +1 -0
- package/dist/utils/scopeAttributes.cjs +2 -0
- package/dist/utils/scopeAttributes.cjs.map +1 -0
- package/dist/utils/scopeAttributes.js +2 -11
- package/dist/utils/scopeAttributes.js.map +1 -0
- package/dist/utils/validations/index.cjs +2 -0
- package/dist/utils/validations/index.cjs.map +1 -0
- package/dist/utils/validations/index.js +2 -41
- package/dist/utils/validations/index.js.map +1 -0
- package/dist/utils/validations/schema/custom-fields.cjs +2 -0
- package/dist/utils/validations/schema/custom-fields.cjs.map +1 -0
- package/dist/utils/validations/schema/custom-fields.d.cts +7 -0
- package/dist/utils/validations/schema/custom-fields.d.ts +6 -2
- package/dist/utils/validations/schema/custom-fields.js +2 -9
- package/dist/utils/validations/schema/custom-fields.js.map +1 -0
- package/dist/utils/validations/schema/validator-schema.cjs +2 -0
- package/dist/utils/validations/schema/validator-schema.cjs.map +1 -0
- package/dist/utils/validations/schema/validator-schema.js +2 -95
- package/dist/utils/validations/schema/validator-schema.js.map +1 -0
- package/dist/utils/validations/validators/index.cjs +2 -0
- package/dist/utils/validations/validators/index.cjs.map +1 -0
- package/dist/utils/validations/validators/index.js +2 -40
- package/dist/utils/validations/validators/index.js.map +1 -0
- package/dist/utils/validations/validators/select.validator.cjs +2 -0
- package/dist/utils/validations/validators/select.validator.cjs.map +1 -0
- package/dist/utils/validations/validators/select.validator.js +2 -12
- package/dist/utils/validations/validators/select.validator.js.map +1 -0
- package/dist/utils/validations/validators/status.validator.cjs +2 -0
- package/dist/utils/validations/validators/status.validator.cjs.map +1 -0
- package/dist/utils/validations/validators/status.validator.js +2 -15
- package/dist/utils/validations/validators/status.validator.js.map +1 -0
- package/package.json +40 -39
- package/.nvmrc +0 -1
- package/dist/api/index.d.ts +0 -3
- package/dist/api/v1/definition/index.d.ts +0 -3
- package/dist/api/v1/definition/validations.d.ts +0 -2
- package/dist/api/v1/errors.d.ts +0 -4
- package/dist/api/v1/index.d.ts +0 -3
- package/dist/api/v1/validator/index.d.ts +0 -3
- package/dist/errors/index.d.ts +0 -24
- package/dist/events/index.d.ts +0 -5
- package/dist/hooks/create.d.ts +0 -10
- package/dist/hooks/create.js +0 -95
- package/dist/hooks/enrich.d.ts +0 -25
- package/dist/hooks/find.d.ts +0 -1
- package/dist/hooks/hooks.d.ts +0 -17
- package/dist/hooks/index.d.ts +0 -5
- 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/workaround.d.ts +0 -10
- package/dist/hooks/workaround.js +0 -37
- package/dist/models/tests/AssociatedTestModel.d.ts +0 -12
- package/dist/models/tests/TestModel.d.ts +0 -12
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.d.ts +0 -10
- package/dist/models/tests/contextAwareModels/ContextTestModel.d.ts +0 -13
- package/dist/repository/definition.d.ts +0 -36
- package/dist/repository/entries.d.ts +0 -13
- package/dist/repository/utils/formatValues.d.ts +0 -3
- package/dist/repository/validator.d.ts +0 -28
- package/dist/repository/value.d.ts +0 -28
- package/dist/scopes/index.d.ts +0 -2
- 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 -6
- package/dist/tests/helpers/commonHooks.js +0 -62
- 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 -33
- 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.js +0 -2
- package/dist/types/value/index.d.ts +0 -15
- package/dist/types/value/index.js +0 -2
- package/dist/utils/db/index.d.ts +0 -4
- package/dist/utils/init.d.ts +0 -7
- package/dist/utils/logger/index.d.ts +0 -3
- package/dist/utils/scopeAttributes.d.ts +0 -2
- package/dist/utils/validations/index.d.ts +0 -8
- package/dist/utils/validations/schema/validator-schema.d.ts +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/select.validator.d.ts +0 -5
- package/dist/utils/validations/validators/status.validator.d.ts +0 -12
- package/src/api/index.ts +0 -10
- package/src/api/v1/definition/index.ts +0 -104
- package/src/api/v1/definition/validations.ts +0 -75
- package/src/api/v1/errors.ts +0 -13
- package/src/api/v1/index.ts +0 -11
- package/src/api/v1/validator/index.ts +0 -141
- package/src/api/v1/validator/validations.ts +0 -38
- package/src/errors/index.ts +0 -70
- package/src/events/index.ts +0 -63
- package/src/hooks/create.ts +0 -81
- package/src/hooks/enrich.ts +0 -255
- package/src/hooks/find.ts +0 -27
- package/src/hooks/hooks.ts +0 -479
- package/src/hooks/index.ts +0 -20
- package/src/hooks/update.ts +0 -55
- package/src/hooks/utils/updateInstanceValues.ts +0 -63
- package/src/hooks/workaround.ts +0 -47
- package/src/index.ts +0 -52
- package/src/models/CustomFieldDefinition.ts +0 -162
- package/src/models/CustomFieldEntries.ts +0 -81
- package/src/models/CustomFieldValue.ts +0 -118
- package/src/models/CustomValidator.ts +0 -78
- package/src/models/index.ts +0 -165
- package/src/models/tests/AssociatedTestModel.ts +0 -57
- package/src/models/tests/TestModel.ts +0 -54
- package/src/models/tests/contextAwareModels/ContextAwareTestModel.ts +0 -43
- package/src/models/tests/contextAwareModels/ContextTestModel.ts +0 -38
- package/src/repository/definition.ts +0 -175
- package/src/repository/entries.ts +0 -88
- package/src/repository/utils/formatValues.ts +0 -14
- package/src/repository/validator.ts +0 -119
- package/src/repository/value.ts +0 -116
- package/src/scopes/filter.ts +0 -100
- package/src/scopes/helpers/filter.helpers.ts +0 -227
- package/src/scopes/index.ts +0 -6
- package/src/tests/api/test-api.ts +0 -40
- package/src/tests/functional/searching/index.ts +0 -39
- package/src/tests/helpers/commonHooks.ts +0 -43
- package/src/tests/helpers/database-config.ts +0 -15
- package/src/tests/helpers/index.ts +0 -35
- package/src/tests/mocks/definition.mock.ts +0 -84
- package/src/tests/mocks/events.mock.ts +0 -21
- package/src/tests/mocks/testModel.ts +0 -37
- package/src/types/definition/index.ts +0 -24
- package/src/types/entries/index.ts +0 -27
- package/src/types/index.ts +0 -52
- package/src/types/value/index.ts +0 -14
- package/src/utils/constants/index.ts +0 -25
- package/src/utils/db/index.ts +0 -21
- package/src/utils/helpers/index.ts +0 -66
- package/src/utils/init.ts +0 -122
- package/src/utils/logger/index.ts +0 -14
- package/src/utils/scopeAttributes.ts +0 -12
- package/src/utils/validations/index.ts +0 -46
- package/src/utils/validations/schema/README.md +0 -93
- package/src/utils/validations/schema/custom-fields.ts +0 -8
- package/src/utils/validations/schema/validator-schema.ts +0 -106
- package/src/utils/validations/type.ts +0 -20
- package/src/utils/validations/validators/index.ts +0 -38
- package/src/utils/validations/validators/select.validator.ts +0 -12
- package/src/utils/validations/validators/status.validator.ts +0 -22
- package/tsconfig.build.json +0 -7
- package/tsconfig.json +0 -16
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import type { CreateCustomFieldDefinition, CustomFieldDefinitionDTO } from '../../types/definition';
|
|
3
|
-
|
|
4
|
-
export const contextAwareFieldDefinition = {
|
|
5
|
-
name: 'cool field',
|
|
6
|
-
modelType: 'ContextAwareTestModel',
|
|
7
|
-
fieldType: 'number',
|
|
8
|
-
entityType: 'fleetId',
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const coolFieldDefinition: CreateCustomFieldDefinition = {
|
|
12
|
-
name: 'cool field',
|
|
13
|
-
modelType: 'TestModel',
|
|
14
|
-
fieldType: 'number',
|
|
15
|
-
entityId: randomUUID(),
|
|
16
|
-
entityType: 'fleetId',
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const coolFieldDefinition2 = {
|
|
20
|
-
...coolFieldDefinition,
|
|
21
|
-
name: 'cool field2',
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const coolFieldDefinition3 = {
|
|
25
|
-
...coolFieldDefinition,
|
|
26
|
-
name: 'cool field3',
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const booleanField = (modelType: string): CreateCustomFieldDefinition => ({
|
|
30
|
-
name: 'shapeless',
|
|
31
|
-
modelType,
|
|
32
|
-
fieldType: 'boolean',
|
|
33
|
-
entityId: randomUUID(),
|
|
34
|
-
entityType: 'fleetId',
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
export const selectField = (modelType: string, options): CreateCustomFieldDefinition => ({
|
|
38
|
-
name: 'choices',
|
|
39
|
-
modelType,
|
|
40
|
-
fieldType: 'select',
|
|
41
|
-
validation: options,
|
|
42
|
-
entityId: randomUUID(),
|
|
43
|
-
entityType: 'fleetId',
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
export const statusField = (modelType: string, options): CreateCustomFieldDefinition => ({
|
|
47
|
-
name: 'lifecycle',
|
|
48
|
-
modelType,
|
|
49
|
-
fieldType: 'status',
|
|
50
|
-
validation: options,
|
|
51
|
-
entityId: randomUUID(),
|
|
52
|
-
entityType: 'fleetId',
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
export const fileField = (modelType: string): CreateCustomFieldDefinition => ({
|
|
56
|
-
name: 'file',
|
|
57
|
-
modelType,
|
|
58
|
-
fieldType: 'file',
|
|
59
|
-
entityId: randomUUID(),
|
|
60
|
-
entityType: 'fleetId',
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// eslint-disable-next-line max-len
|
|
64
|
-
export const createDefinition = (defaults: Partial<CustomFieldDefinitionDTO>): CreateCustomFieldDefinition => ({
|
|
65
|
-
name: defaults?.name || `def_${randomUUID()}`,
|
|
66
|
-
modelType: defaults?.modelType || 'TestModel',
|
|
67
|
-
fieldType: defaults?.fieldType || 'boolean',
|
|
68
|
-
entityId: defaults?.entityId || randomUUID(),
|
|
69
|
-
entityType: defaults?.entityType || 'fleetId',
|
|
70
|
-
...(defaults?.validation && { validation: defaults.validation }),
|
|
71
|
-
...(defaults?.defaultValue && { defaultValue: defaults.defaultValue }),
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
export const createDefinitions = (
|
|
75
|
-
defaults: Partial<CustomFieldDefinitionDTO>,
|
|
76
|
-
length = 1,
|
|
77
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
78
|
-
): CreateCustomFieldDefinition[] => (Array(length).fill({}).map((_) => ({
|
|
79
|
-
name: defaults?.name || `def_${randomUUID()}`,
|
|
80
|
-
modelType: defaults?.modelType || 'TestModel',
|
|
81
|
-
fieldType: defaults?.fieldType || 'boolean',
|
|
82
|
-
entityId: defaults?.entityId || randomUUID(),
|
|
83
|
-
entityType: defaults?.entityType || 'fleetId',
|
|
84
|
-
})));
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-param-reassign */
|
|
2
|
-
|
|
3
|
-
export const mockEvent = (events: any, eventName, numberOfEvents) => {
|
|
4
|
-
events.sendObject = jest.fn().mockResolvedValue(true);
|
|
5
|
-
return [
|
|
6
|
-
events.sendObject,
|
|
7
|
-
(): void => {
|
|
8
|
-
const matchingEvents = events.sendObject.mock.calls.filter((call) => call[0] === eventName);
|
|
9
|
-
expect(matchingEvents.length).toEqual(numberOfEvents);
|
|
10
|
-
},
|
|
11
|
-
];
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const mockDimCustomFieldDefinitionEvent = (events, numberOfEvents) =>
|
|
15
|
-
mockEvent(events, 'dim_custom_field_definition', numberOfEvents);
|
|
16
|
-
|
|
17
|
-
export const mockDimCustomFieldValueEvent = (events, numberOfEvents) =>
|
|
18
|
-
mockEvent(events, 'dim_custom_field_value', numberOfEvents);
|
|
19
|
-
|
|
20
|
-
export const mockDimCustomFieldEntriesEvent = (events, numberOfEvents) =>
|
|
21
|
-
mockEvent(events, 'dim_custom_field_entries', numberOfEvents);
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { TestModel, AssociatedTestModel } from '../../models';
|
|
2
|
-
|
|
3
|
-
export const createTestModel = (payload = {}) => TestModel.create(payload);
|
|
4
|
-
|
|
5
|
-
export const createTestModels = (fleetId, total: number) => {
|
|
6
|
-
const models: Promise<TestModel>[] = [];
|
|
7
|
-
for (let i = 0; i < total; i += 1) {
|
|
8
|
-
models.push(createTestModel({ fleetId }));
|
|
9
|
-
}
|
|
10
|
-
return Promise.all<TestModel>(models);
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const upsertTestModel = (payload) => TestModel.upsert(payload);
|
|
14
|
-
|
|
15
|
-
export const destroyTestModels = () => TestModel.destroy({ truncate: true });
|
|
16
|
-
|
|
17
|
-
export const getTestModel = (
|
|
18
|
-
id: string,
|
|
19
|
-
options = {},
|
|
20
|
-
): Promise<TestModel | null> => TestModel.findByPk(id, options);
|
|
21
|
-
|
|
22
|
-
export const getSomeTestModels = (
|
|
23
|
-
options = { limit: 1 },
|
|
24
|
-
): Promise<TestModel[]> => TestModel.findAll(options);
|
|
25
|
-
|
|
26
|
-
export const updateTestModel = (payload, query) => TestModel.update(payload, query);
|
|
27
|
-
|
|
28
|
-
// Associations
|
|
29
|
-
export const createTestModelWithAssociation = async () => {
|
|
30
|
-
const model = await TestModel.create({});
|
|
31
|
-
await AssociatedTestModel.create({ testModelId: model.id });
|
|
32
|
-
return model;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export const getTestModelWithAssociation = (limit = 1) => TestModel.findAll({
|
|
36
|
-
limit, include: [AssociatedTestModel],
|
|
37
|
-
});
|
|
@@ -1,24 +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
|
-
|
|
22
|
-
export type SerializedCustomFields = {
|
|
23
|
-
[name: string]: CustomFieldDefinitionDTO & { value: any };
|
|
24
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { ValidationError } from 'joi';
|
|
2
|
-
|
|
3
|
-
export interface CustomFieldEntriesDTO {
|
|
4
|
-
modelId: string;
|
|
5
|
-
entityId: string;
|
|
6
|
-
modelType: string;
|
|
7
|
-
/**
|
|
8
|
-
* A collection of custom fields where each key is the name of a CustomFieldDefinition and
|
|
9
|
-
* each value is the value of that custom field for this specific `modelId`.
|
|
10
|
-
*
|
|
11
|
-
* Example:
|
|
12
|
-
* {
|
|
13
|
-
* "vehicleColor": "Red",
|
|
14
|
-
* "vehicleType": "premium",
|
|
15
|
-
* "isActive": true
|
|
16
|
-
* }
|
|
17
|
-
*/
|
|
18
|
-
customFields: Record<string, any>;
|
|
19
|
-
createdAt?: Date;
|
|
20
|
-
updatedAt?: Date;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface EntriesValidationError {
|
|
24
|
-
value: any,
|
|
25
|
-
fieldDefinitionName: string,
|
|
26
|
-
joiValidationError: ValidationError
|
|
27
|
-
}
|
package/src/types/index.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type { IncludeOptions, Transaction } from 'sequelize';
|
|
2
|
-
import type { ModelCtor, Sequelize } from 'sequelize-typescript';
|
|
3
|
-
import type { getUser as GetUserType } from '@autofleet/zehut';
|
|
4
|
-
import type CustomFieldDefinition from '../models/CustomFieldDefinition';
|
|
5
|
-
import type CustomValidator from '../models/CustomValidator';
|
|
6
|
-
|
|
7
|
-
export type ModelFetcher = (name: string) => any;
|
|
8
|
-
|
|
9
|
-
export interface TransactionOptions extends Record<string, any> {
|
|
10
|
-
transaction?: Transaction & {
|
|
11
|
-
definitionCache?: Map<string, CustomFieldDefinition[]>;
|
|
12
|
-
validationsCache?: Map<string, CustomValidator[]>;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type ModelOptions = {
|
|
17
|
-
/**
|
|
18
|
-
* Include options for the model
|
|
19
|
-
*/
|
|
20
|
-
include?: (entityIds: string | string[]) => IncludeOptions[];
|
|
21
|
-
/**
|
|
22
|
-
* Custom association for the model
|
|
23
|
-
* @param model - The model to associate with
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
customAssociation?: (model: ModelCtor) => void;
|
|
27
|
-
/**
|
|
28
|
-
* Whether to use the entity id from the instance per scope attribute
|
|
29
|
-
*/
|
|
30
|
-
useEntityIdFromInclude?: boolean
|
|
31
|
-
/**
|
|
32
|
-
* Which attributes to include in the model
|
|
33
|
-
*/
|
|
34
|
-
attributes?: string[];
|
|
35
|
-
}
|
|
36
|
-
export type Models = {
|
|
37
|
-
name: string;
|
|
38
|
-
scopeAttributes: any[];
|
|
39
|
-
modelOptions?: ModelOptions;
|
|
40
|
-
creationWebhookHandler?: (instance: any) => any;
|
|
41
|
-
updateWebhookHandler?: (instance: any) => any;
|
|
42
|
-
deletionWebhookHandler?: (instance: any) => any;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export type CustomFieldOptions = {
|
|
46
|
-
models: Models[];
|
|
47
|
-
databaseConfig: any;
|
|
48
|
-
getUser: typeof GetUserType;
|
|
49
|
-
sequelize?: Sequelize;
|
|
50
|
-
useCustomFieldsEntries?: boolean;
|
|
51
|
-
useValidators?: boolean;
|
|
52
|
-
};
|
package/src/types/value/index.ts
DELETED
|
@@ -1,14 +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
|
-
|
|
11
|
-
export type ValuesToUpdate = {[name: string]: any };
|
|
12
|
-
export type CreateCustomFieldValue = Omit<CustomFieldValueDTO, 'id'>;
|
|
13
|
-
export type UpdateCustomFieldValue = ValuesToUpdate;
|
|
14
|
-
export type BulkUpdateCustomFieldValue = Partial<CustomFieldValueDTO>[];
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { customFields } from '@autofleet/common-types';
|
|
2
|
-
|
|
3
|
-
const { CUSTOM_FIELDS_FILTER_SCOPE } = customFields;
|
|
4
|
-
|
|
5
|
-
export const supportedEntities = ['businessModelId', 'fleetId', 'demandSourceId'];
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Supported custom field types
|
|
9
|
-
*/
|
|
10
|
-
export enum CustomFieldDefinitionType {
|
|
11
|
-
NUMBER = 'number',
|
|
12
|
-
BOOLEAN = 'boolean',
|
|
13
|
-
DATE = 'date',
|
|
14
|
-
DATETIME = 'datetime',
|
|
15
|
-
TEXT = 'text',
|
|
16
|
-
IMAGE = 'image',
|
|
17
|
-
SELECT = 'select',
|
|
18
|
-
STATUS = 'status',
|
|
19
|
-
FILE = 'file',
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export {
|
|
23
|
-
/** @deprecated Use the value from `@autofleet/common-types` instead */
|
|
24
|
-
CUSTOM_FIELDS_FILTER_SCOPE,
|
|
25
|
-
};
|
package/src/utils/db/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Sequelize } from 'sequelize-typescript';
|
|
2
|
-
import { QueryTypes } from 'sequelize';
|
|
3
|
-
|
|
4
|
-
export default (databaseConfig: any): Sequelize => {
|
|
5
|
-
const ENV_DEV = 'test';
|
|
6
|
-
const env: string = process.env.NODE_ENV || ENV_DEV;
|
|
7
|
-
const config = databaseConfig[env];
|
|
8
|
-
let sequelize: Sequelize;
|
|
9
|
-
if (config.use_env_variable) {
|
|
10
|
-
sequelize = new Sequelize(process.env[config.use_env_variable], config);
|
|
11
|
-
} else {
|
|
12
|
-
sequelize = new Sequelize(config.database, config.username, config.password, config);
|
|
13
|
-
}
|
|
14
|
-
return sequelize;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const createSequelizeMeta = (sequelize: Sequelize) => sequelize.query(`
|
|
18
|
-
CREATE TABLE IF NOT EXISTS "SequelizeMeta" (
|
|
19
|
-
name character varying(255) PRIMARY KEY
|
|
20
|
-
);
|
|
21
|
-
`, { type: QueryTypes.SELECT });
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/prefer-default-export */
|
|
2
|
-
import { type WhereOptions, Op, type BindOrReplacements } from 'sequelize';
|
|
3
|
-
import { type ModelStatic, Sequelize } from 'sequelize-typescript';
|
|
4
|
-
import { randomInt } from 'node:crypto';
|
|
5
|
-
import { CustomFieldDefinitionType } from '../constants';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Builds a WHERE clause and replacements for free-text search by custom fields.
|
|
9
|
-
*
|
|
10
|
-
* This function constructs a WHERE clause and replacement bindings that allow searching
|
|
11
|
-
* for a given term within custom fields associated with a specific model type and entity ID.
|
|
12
|
-
* The WHERE clause and replacements are designed to be added to the main query.
|
|
13
|
-
*
|
|
14
|
-
* @param {string} searchTerm - The term to search for within custom fields.
|
|
15
|
-
* @param {ModelStatic} model - The Sequelize model representing the entity type to search for.
|
|
16
|
-
* @param {string} entityId - The entity ID to filter the custom fields by.
|
|
17
|
-
* @param {CustomFieldDefinitionType[]} excludedCustomFieldsTypes - An array of custom field types
|
|
18
|
-
* to exclude from the search
|
|
19
|
-
*
|
|
20
|
-
* @returns {CustomFieldsSearchPayload} - An object containing the WHERE clause and replacements
|
|
21
|
-
* for Sequelize.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
interface CustomFieldsSearchPayload {
|
|
25
|
-
where: WhereOptions;
|
|
26
|
-
replacements: BindOrReplacements;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const generateRandomString = (length = 5): string => {
|
|
30
|
-
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
31
|
-
return Array.from({ length }, () => characters.charAt(randomInt(characters.length))).join('');
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const generateCustomFieldSearchQueryPayload = (
|
|
35
|
-
searchTerm: string,
|
|
36
|
-
model: ModelStatic,
|
|
37
|
-
entityId: string,
|
|
38
|
-
customFieldsTypesToExclude: CustomFieldDefinitionType[] = [
|
|
39
|
-
CustomFieldDefinitionType.DATETIME,
|
|
40
|
-
CustomFieldDefinitionType.DATE,
|
|
41
|
-
],
|
|
42
|
-
): CustomFieldsSearchPayload => {
|
|
43
|
-
const excludedTypesString = customFieldsTypesToExclude.map((type) => `'${type}'`).join(',');
|
|
44
|
-
|
|
45
|
-
const subQuery = 'EXISTS ('
|
|
46
|
-
+ ' SELECT 1'
|
|
47
|
-
+ ' FROM "custom_field_values" AS "cv"'
|
|
48
|
-
+ ' INNER JOIN custom_field_definitions AS cd '
|
|
49
|
-
+ ` ON cd.entity_id = '${entityId}'`
|
|
50
|
-
+ ' AND cv.custom_field_definition_id = cd.id'
|
|
51
|
-
+ ` AND cd.model_type = '${model.name}'`
|
|
52
|
-
+ ` ${excludedTypesString ? `AND cd.field_type NOT IN (${excludedTypesString})` : ''}`
|
|
53
|
-
+ ' WHERE'
|
|
54
|
-
+ ' "cv"."deleted_at" IS NULL'
|
|
55
|
-
+ ` AND "cv"."model_id" = "${model.name}"."id"`
|
|
56
|
-
+ ' AND CAST("cv"."value" AS TEXT) ILIKE :searchTerm)';
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
where: {
|
|
60
|
-
[Op.or]: [
|
|
61
|
-
Sequelize.where(Sequelize.literal(subQuery), true),
|
|
62
|
-
],
|
|
63
|
-
},
|
|
64
|
-
replacements: { searchTerm: `%${searchTerm}%` },
|
|
65
|
-
};
|
|
66
|
-
};
|
package/src/utils/init.ts
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { DataTypes } from 'sequelize';
|
|
2
|
-
import type { ModelCtor } from 'sequelize-typescript';
|
|
3
|
-
import { customFields } from '@autofleet/common-types';
|
|
4
|
-
import { CUSTOM_FIELDS_SORT_SCOPE } from '@autofleet/common-types/lib/custom-fields';
|
|
5
|
-
import {
|
|
6
|
-
CustomFieldDefinition,
|
|
7
|
-
CustomFieldValue,
|
|
8
|
-
CustomValidator,
|
|
9
|
-
} from '../models';
|
|
10
|
-
import {
|
|
11
|
-
beforeFind,
|
|
12
|
-
enrichResults,
|
|
13
|
-
beforeBulkUpdate,
|
|
14
|
-
beforeUpdate,
|
|
15
|
-
beforeCreate,
|
|
16
|
-
beforeBulkCreate,
|
|
17
|
-
} from '../hooks';
|
|
18
|
-
import { customFieldsFilterScope } from '../scopes';
|
|
19
|
-
import logger from './logger';
|
|
20
|
-
import type { CustomFieldOptions, ModelFetcher, Models } from '../types';
|
|
21
|
-
import { customFieldsSortScope } from '../scopes/filter';
|
|
22
|
-
|
|
23
|
-
const { CUSTOM_FIELDS_FILTER_SCOPE } = customFields;
|
|
24
|
-
|
|
25
|
-
export const addHooks = (
|
|
26
|
-
models: Models[],
|
|
27
|
-
getModel: ModelFetcher,
|
|
28
|
-
sadotOptions: { useCustomFieldsEntries: boolean } = { useCustomFieldsEntries: false },
|
|
29
|
-
): void => {
|
|
30
|
-
models.forEach(async ({
|
|
31
|
-
name, scopeAttributes, modelOptions,
|
|
32
|
-
}) => {
|
|
33
|
-
try {
|
|
34
|
-
const model = getModel(name);
|
|
35
|
-
if (!model) {
|
|
36
|
-
logger.warn('sadot - tried to addHooks to a model that does not exist yet', {
|
|
37
|
-
name,
|
|
38
|
-
scopeAttributes,
|
|
39
|
-
});
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
model.rawAttributes.customFields = {
|
|
43
|
-
type: DataTypes.VIRTUAL,
|
|
44
|
-
};
|
|
45
|
-
model.refreshAttributes();
|
|
46
|
-
// TODO: Uncomment after tests are passed
|
|
47
|
-
// model.addHook('afterFind', workaround);
|
|
48
|
-
model.addHook('beforeFind', 'sadot-beforeFind', beforeFind(scopeAttributes));
|
|
49
|
-
model.addHook('beforeBulkCreate', 'sadot-beforeBulkCreate', beforeBulkCreate);
|
|
50
|
-
model.addHook('beforeBulkUpdate', 'sadot-beforeBulkUpdate', beforeBulkUpdate);
|
|
51
|
-
model.addHook('beforeCreate', 'sadot-beforeCreate', beforeCreate(scopeAttributes, modelOptions, sadotOptions));
|
|
52
|
-
model.addHook('beforeUpdate', 'sadot-beforeUpdate', beforeUpdate(scopeAttributes, modelOptions, sadotOptions));
|
|
53
|
-
model.addHook('afterFind', 'sadot-afterFind', enrichResults(name, scopeAttributes, 'afterFind', modelOptions, sadotOptions));
|
|
54
|
-
model.addHook('afterUpdate', 'sadot-afterUpdate', enrichResults(name, scopeAttributes, null, modelOptions, sadotOptions));
|
|
55
|
-
model.addHook('afterCreate', 'sadot-afterCreate', enrichResults(name, scopeAttributes, null, modelOptions, sadotOptions));
|
|
56
|
-
} catch (e) {
|
|
57
|
-
logger.error(`Could not add custom fields hook to model ${name}. `, e);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export const removeHooks = (models: Models[], getModel: ModelFetcher): void => {
|
|
63
|
-
models.forEach(async ({ name }) => {
|
|
64
|
-
try {
|
|
65
|
-
const model = getModel(name);
|
|
66
|
-
if (!model) return;
|
|
67
|
-
if (model.rawAttributes.customFields) {
|
|
68
|
-
delete model.rawAttributes.customFields;
|
|
69
|
-
model.refreshAttributes();
|
|
70
|
-
}
|
|
71
|
-
// model.removeHook('afterFind', 'sadot-workaround');
|
|
72
|
-
model.removeHook('beforeFind', 'sadot-beforeFind');
|
|
73
|
-
model.removeHook('beforeBulkCreate', 'sadot-beforeBulkCreate');
|
|
74
|
-
model.removeHook('beforeBulkUpdate', 'sadot-beforeBulkUpdate');
|
|
75
|
-
model.removeHook('beforeCreate', 'sadot-beforeCreate');
|
|
76
|
-
model.removeHook('beforeUpdate', 'sadot-beforeUpdate');
|
|
77
|
-
model.removeHook('afterFind', 'sadot-afterFind');
|
|
78
|
-
model.removeHook('afterUpdate', 'sadot-afterUpdate');
|
|
79
|
-
} catch (e) {
|
|
80
|
-
logger.error(`Could not add custom fields hook to model ${name}. `, e);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Necessary associations for the {@link customFieldsFilterScope} scope
|
|
87
|
-
*/
|
|
88
|
-
const addAssociations = (model: ModelCtor, modelName: string, options: Pick<CustomFieldOptions, 'useCustomFieldsEntries'>): void => {
|
|
89
|
-
if (options?.useCustomFieldsEntries) return;
|
|
90
|
-
model.hasMany(CustomFieldValue, { foreignKey: 'modelId', as: 'customFieldValue' });
|
|
91
|
-
// TBC: maybe can be removed
|
|
92
|
-
CustomFieldValue.belongsTo(model, { foreignKey: 'modelId', as: modelName });
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
export const addScopes = (models: Models[], getModel: ModelFetcher, options: Pick<CustomFieldOptions, 'useCustomFieldsEntries'> = { useCustomFieldsEntries: false }): void => {
|
|
96
|
-
models.forEach(async ({ name, scopeAttributes }) => {
|
|
97
|
-
try {
|
|
98
|
-
const model = getModel(name);
|
|
99
|
-
if (!model) {
|
|
100
|
-
logger.warn('sadot - tried to addScopes to a model that does not exist yet', {
|
|
101
|
-
name,
|
|
102
|
-
scopeAttributes,
|
|
103
|
-
});
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
// Necessary associations for the filtering scope
|
|
107
|
-
addAssociations(model, name, options);
|
|
108
|
-
// Add filter scope
|
|
109
|
-
model.addScope(CUSTOM_FIELDS_FILTER_SCOPE, customFieldsFilterScope(name, options));
|
|
110
|
-
model.addScope(CUSTOM_FIELDS_SORT_SCOPE, customFieldsSortScope(name, options));
|
|
111
|
-
} catch (e) {
|
|
112
|
-
logger.error(`Could not add custom fields scopes to model ${name}. `, e);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
export const applyCustomAssociation = (models: Models[]): void => {
|
|
118
|
-
models.forEach(({ modelOptions }) => {
|
|
119
|
-
modelOptions?.customAssociation?.(CustomFieldDefinition);
|
|
120
|
-
modelOptions?.customAssociation?.(CustomValidator);
|
|
121
|
-
});
|
|
122
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import Logger from '@autofleet/logger';
|
|
2
|
-
|
|
3
|
-
const logger = Logger();
|
|
4
|
-
|
|
5
|
-
export async function tryAddingTraceIdMiddleware() {
|
|
6
|
-
try {
|
|
7
|
-
const { outbreak } = await import('@autofleet/zehut');
|
|
8
|
-
logger.addContextMiddleware(() => ({ traceId: outbreak.getCurrentContextTraceId() }));
|
|
9
|
-
} catch (err) {
|
|
10
|
-
logger.error('Failed to add traceId middleware', { err });
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export default logger;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const mapAttributeToInstance = (scopeAttributes: string[], instance: any) =>
|
|
2
|
-
scopeAttributes.map((attr) => instance[attr]);
|
|
3
|
-
|
|
4
|
-
const applyScopeToInstance = (instance: any, scopeAttributes: string[]) => {
|
|
5
|
-
const uniqueAttributes = Array.from(new Set(scopeAttributes));
|
|
6
|
-
if (Array.isArray(instance)) {
|
|
7
|
-
return instance.flatMap((ins) => mapAttributeToInstance(uniqueAttributes, ins));
|
|
8
|
-
}
|
|
9
|
-
return mapAttributeToInstance(uniqueAttributes, instance);
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export default applyScopeToInstance;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { InvalidEntriesError } from '../../errors';
|
|
2
|
-
import type { CustomFieldDefinition } from '../../models';
|
|
3
|
-
import type { CustomFieldEntriesDTO } from '../../types/entries';
|
|
4
|
-
import type { CustomFieldDefinitionType } from '../constants';
|
|
5
|
-
import { validators } from './validators';
|
|
6
|
-
|
|
7
|
-
export const validateFieldType = (type: CustomFieldDefinitionType): boolean => Object.keys(validators).includes(type);
|
|
8
|
-
|
|
9
|
-
export const validateValue = (
|
|
10
|
-
value: unknown,
|
|
11
|
-
valueType: CustomFieldDefinitionType,
|
|
12
|
-
validation?: unknown,
|
|
13
|
-
) => {
|
|
14
|
-
const validator = validators[valueType];
|
|
15
|
-
return validator(value, validation);
|
|
16
|
-
/** TODO: Add validation for required fields
|
|
17
|
-
* @example
|
|
18
|
-
* if (validations.required && !value) {
|
|
19
|
-
* return false;
|
|
20
|
-
* }
|
|
21
|
-
*/
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const validateInstanceCustomFieldEntries = (instance: CustomFieldEntriesDTO, definitionsByName: { [defName: string]: CustomFieldDefinition; }) => {
|
|
25
|
-
const validationErrors = Object.entries(instance.customFields)
|
|
26
|
-
.map(([customFieldName, value]) => {
|
|
27
|
-
// Allow NULL values, just like we do in custom_field_values.
|
|
28
|
-
if (value === null) return null;
|
|
29
|
-
|
|
30
|
-
const { validation, fieldType } = definitionsByName[customFieldName];
|
|
31
|
-
const result = validateValue(value, fieldType, validation);
|
|
32
|
-
if (result?.error) {
|
|
33
|
-
return {
|
|
34
|
-
joiValidationError: result.error,
|
|
35
|
-
fieldDefinitionName: customFieldName,
|
|
36
|
-
value,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
return null;
|
|
40
|
-
})
|
|
41
|
-
.filter((result) => !!result);
|
|
42
|
-
|
|
43
|
-
if (validationErrors?.length) {
|
|
44
|
-
throw new InvalidEntriesError(instance.modelId, validationErrors);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
# Schema Validation
|
|
2
|
-
|
|
3
|
-
This directory contains schema validation utilities for the Sadot library, including:
|
|
4
|
-
|
|
5
|
-
1. **Custom Fields Schemas** - Schema definitions for custom field validation
|
|
6
|
-
2. **Validator Schemas** - Meta-validation for custom validator JSON schemas
|
|
7
|
-
|
|
8
|
-
## Custom Fields Schema
|
|
9
|
-
|
|
10
|
-
`custom-fields.ts` defines JSON Schema validation for custom field definitions, ensuring fields are created with valid configurations.
|
|
11
|
-
|
|
12
|
-
## Validator Schema Validation
|
|
13
|
-
|
|
14
|
-
`validator-schema.ts` provides meta-validation for custom validator schemas. It ensures that:
|
|
15
|
-
|
|
16
|
-
1. The validator schema follows the expected structure
|
|
17
|
-
2. The schema is a valid JSON Schema that can be compiled by AJV
|
|
18
|
-
3. The validation rules defined in the schema are syntactically correct
|
|
19
|
-
|
|
20
|
-
### Usage
|
|
21
|
-
|
|
22
|
-
The `validateValidatorSchema` function is used by the custom validator API to validate schemas at creation and update time:
|
|
23
|
-
|
|
24
|
-
```typescript
|
|
25
|
-
import { validateValidatorSchema } from '../utils/validations/schema/validator-schema';
|
|
26
|
-
|
|
27
|
-
// Validates a schema, throws BadRequest if invalid
|
|
28
|
-
validateValidatorSchema(schema);
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
### Schema Structure
|
|
32
|
-
|
|
33
|
-
Validator schemas must follow this general structure:
|
|
34
|
-
|
|
35
|
-
```json
|
|
36
|
-
{
|
|
37
|
-
"type": "object",
|
|
38
|
-
"properties": {
|
|
39
|
-
"before": {
|
|
40
|
-
"type": "object",
|
|
41
|
-
"properties": {
|
|
42
|
-
// Model properties to validate before update
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
"after": {
|
|
46
|
-
"type": "object",
|
|
47
|
-
"properties": {
|
|
48
|
-
// Model properties to validate after update/create
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
For create operations, only the `after` section is used. For update operations, both `before` and `after` can be used.
|
|
56
|
-
|
|
57
|
-
### Conditional Validation
|
|
58
|
-
|
|
59
|
-
The schema can include conditional validation using JSON Schema's `if/then/else` constructs:
|
|
60
|
-
|
|
61
|
-
```json
|
|
62
|
-
{
|
|
63
|
-
"type": "object",
|
|
64
|
-
"if": {
|
|
65
|
-
"properties": {
|
|
66
|
-
"before": {
|
|
67
|
-
"properties": {
|
|
68
|
-
"status": { "const": "PENDING" }
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
"then": {
|
|
74
|
-
"properties": {
|
|
75
|
-
"after": {
|
|
76
|
-
"properties": {
|
|
77
|
-
"status": { "enum": ["APPROVED", "REJECTED"] }
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
This example validates that if a model's status was "PENDING", it can only be updated to "APPROVED" or "REJECTED".
|
|
86
|
-
|
|
87
|
-
### Error Handling
|
|
88
|
-
|
|
89
|
-
Schema validation errors are thrown as BadRequest errors with descriptive messages indicating:
|
|
90
|
-
|
|
91
|
-
1. The specific validation error in the schema
|
|
92
|
-
2. The path within the schema where the error occurred
|
|
93
|
-
3. A readable message for API consumers
|