@autofleet/sadot 0.4.3 → 0.5.1-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/v1/definition/validations.js +1 -1
- package/dist/hooks/enrich.d.ts +2 -1
- package/dist/hooks/enrich.js +6 -1
- package/dist/tests/mocks/testModel.d.ts +1 -1
- package/dist/utils/init.js +1 -1
- package/package.json +1 -1
- package/src/api/v1/definition/validations.ts +1 -1
- package/src/hooks/enrich.ts +12 -1
- package/src/tests/mocks/testModel.ts +2 -2
- package/src/utils/init.ts +1 -1
|
@@ -26,7 +26,7 @@ const CustomFieldDefinitionUpdateSchema = joi_1.default.object({
|
|
|
26
26
|
displayName: joi_1.default.string(),
|
|
27
27
|
validation: ValidationSchema,
|
|
28
28
|
fieldType: joi_1.default.string().valid(...Object.values(type_1.CustomFieldDefinitionType)),
|
|
29
|
-
description: joi_1.default.string(),
|
|
29
|
+
description: joi_1.default.string().allow(null),
|
|
30
30
|
required: joi_1.default.boolean(),
|
|
31
31
|
disabled: joi_1.default.boolean(),
|
|
32
32
|
});
|
package/dist/hooks/enrich.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
type SupportedHookTypes = 'afterFind' | 'afterCreate' | 'afterUpdate';
|
|
1
2
|
/**
|
|
2
3
|
* A hook to attach the custom fields when fetching a model instances.
|
|
3
4
|
*/
|
|
4
|
-
declare const enrichResults: (modelType: string, scopeAttributes: string[]) => (instancesOrInstance: any | any[], options: any) => Promise<void>;
|
|
5
|
+
declare const enrichResults: (modelType: string, scopeAttributes: string[], hookType?: SupportedHookTypes) => (instancesOrInstance: any | any[], options: any) => Promise<void>;
|
|
5
6
|
export default enrichResults;
|
package/dist/hooks/enrich.js
CHANGED
|
@@ -40,7 +40,7 @@ const serializeCustomFields = (customFieldValues, customFieldDefinitionsHash) =>
|
|
|
40
40
|
/**
|
|
41
41
|
* A hook to attach the custom fields when fetching a model instances.
|
|
42
42
|
*/
|
|
43
|
-
const enrichResults = (modelType, scopeAttributes) => async (instancesOrInstance, options) => {
|
|
43
|
+
const enrichResults = (modelType, scopeAttributes, hookType) => async (instancesOrInstance, options) => {
|
|
44
44
|
if (options.originalAttributes?.length > 0
|
|
45
45
|
&& !options.originalAttributes?.includes?.('customFields')) {
|
|
46
46
|
return;
|
|
@@ -103,6 +103,11 @@ const enrichResults = (modelType, scopeAttributes) => async (instancesOrInstance
|
|
|
103
103
|
// if raw:
|
|
104
104
|
delete instance?.[attribute];
|
|
105
105
|
});
|
|
106
|
+
// sequelize will think customFields changed also in 'find', so we need to mark it as unchanged
|
|
107
|
+
if (hookType === 'afterFind') {
|
|
108
|
+
// changed() could be undefined, i.e in raw: true
|
|
109
|
+
instance?.changed?.('customFields', false);
|
|
110
|
+
}
|
|
106
111
|
});
|
|
107
112
|
};
|
|
108
113
|
exports.default = enrichResults;
|
|
@@ -3,7 +3,7 @@ export declare const createTestModel: (payload?: {}) => Promise<TestModel>;
|
|
|
3
3
|
export declare const createTestModels: (fleetId: any, total: number) => Promise<TestModel[]>;
|
|
4
4
|
export declare const upsertTestModel: (payload: any) => Promise<[TestModel, boolean]>;
|
|
5
5
|
export declare const destroyTestModels: () => Promise<number>;
|
|
6
|
-
export declare const getTestModel: (id: string, options?: {}) => Promise<TestModel>;
|
|
6
|
+
export declare const getTestModel: (id: string, options?: {}) => Promise<TestModel | null>;
|
|
7
7
|
export declare const getSomeTestModels: (options?: {
|
|
8
8
|
limit: number;
|
|
9
9
|
}) => Promise<TestModel[]>;
|
package/dist/utils/init.js
CHANGED
|
@@ -32,7 +32,7 @@ const addHooks = (models, getModel) => {
|
|
|
32
32
|
model.addHook('beforeBulkUpdate', 'sadot-beforeBulkUpdate', hooks_1.beforeBulkUpdate);
|
|
33
33
|
model.addHook('beforeCreate', 'sadot-beforeCreate', (0, hooks_1.beforeCreate)(scopeAttributes));
|
|
34
34
|
model.addHook('beforeUpdate', 'sadot-beforeUpdate', (0, hooks_1.beforeUpdate)(scopeAttributes));
|
|
35
|
-
model.addHook('afterFind', 'sadot-afterFind', (0, hooks_1.enrichResults)(name, scopeAttributes));
|
|
35
|
+
model.addHook('afterFind', 'sadot-afterFind', (0, hooks_1.enrichResults)(name, scopeAttributes, 'afterFind'));
|
|
36
36
|
model.addHook('afterUpdate', 'sadot-afterUpdate', (0, hooks_1.enrichResults)(name, scopeAttributes));
|
|
37
37
|
model.addHook('afterCreate', 'sadot-afterCreate', (0, hooks_1.enrichResults)(name, scopeAttributes));
|
|
38
38
|
}
|
package/package.json
CHANGED
|
@@ -23,7 +23,7 @@ const CustomFieldDefinitionUpdateSchema = Joi.object({
|
|
|
23
23
|
displayName: Joi.string(),
|
|
24
24
|
validation: ValidationSchema,
|
|
25
25
|
fieldType: Joi.string().valid(...Object.values(CustomFieldDefinitionType)),
|
|
26
|
-
description: Joi.string(),
|
|
26
|
+
description: Joi.string().allow(null),
|
|
27
27
|
required: Joi.boolean(),
|
|
28
28
|
disabled: Joi.boolean(),
|
|
29
29
|
});
|
package/src/hooks/enrich.ts
CHANGED
|
@@ -5,6 +5,8 @@ import CustomFieldValue from '../models/CustomFieldValue';
|
|
|
5
5
|
import CustomFieldDefinition from '../models/CustomFieldDefinition';
|
|
6
6
|
import { SerializedCustomFields } from '../types/definition';
|
|
7
7
|
|
|
8
|
+
type SupportedHookTypes = 'afterFind' | 'afterCreate' | 'afterUpdate';
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
* Serialize custom fields value into the format of {[name] -> [fieldData]}
|
|
10
12
|
*/
|
|
@@ -24,7 +26,11 @@ const serializeCustomFields = (
|
|
|
24
26
|
/**
|
|
25
27
|
* A hook to attach the custom fields when fetching a model instances.
|
|
26
28
|
*/
|
|
27
|
-
const enrichResults = (
|
|
29
|
+
const enrichResults = (
|
|
30
|
+
modelType: string,
|
|
31
|
+
scopeAttributes: string[],
|
|
32
|
+
hookType?: SupportedHookTypes,
|
|
33
|
+
) => async (
|
|
28
34
|
instancesOrInstance: any | any[],
|
|
29
35
|
options,
|
|
30
36
|
): Promise<void> => {
|
|
@@ -113,6 +119,11 @@ const enrichResults = (modelType: string, scopeAttributes: string[]) => async (
|
|
|
113
119
|
// if raw:
|
|
114
120
|
delete instance?.[attribute];
|
|
115
121
|
});
|
|
122
|
+
// sequelize will think customFields changed also in 'find', so we need to mark it as unchanged
|
|
123
|
+
if (hookType === 'afterFind') {
|
|
124
|
+
// changed() could be undefined, i.e in raw: true
|
|
125
|
+
instance?.changed?.('customFields', false);
|
|
126
|
+
}
|
|
116
127
|
});
|
|
117
128
|
};
|
|
118
129
|
|
|
@@ -3,7 +3,7 @@ import { TestModel, AssociatedTestModel } from '../../models';
|
|
|
3
3
|
export const createTestModel = (payload = {}) => TestModel.create(payload);
|
|
4
4
|
|
|
5
5
|
export const createTestModels = (fleetId, total: number) => {
|
|
6
|
-
const models = [];
|
|
6
|
+
const models: Promise<TestModel>[] = [];
|
|
7
7
|
for (let i = 0; i < total; i += 1) {
|
|
8
8
|
models.push(createTestModel({ fleetId }));
|
|
9
9
|
}
|
|
@@ -17,7 +17,7 @@ export const destroyTestModels = () => TestModel.destroy({ truncate: true });
|
|
|
17
17
|
export const getTestModel = (
|
|
18
18
|
id: string,
|
|
19
19
|
options = {},
|
|
20
|
-
): Promise<TestModel> => TestModel.findByPk(id, options);
|
|
20
|
+
): Promise<TestModel | null> => TestModel.findByPk(id, options);
|
|
21
21
|
|
|
22
22
|
export const getSomeTestModels = (
|
|
23
23
|
options = { limit: 1 },
|
package/src/utils/init.ts
CHANGED
|
@@ -38,7 +38,7 @@ export const addHooks = (models: ModelOptions[], getModel: ModelFetcher): void =
|
|
|
38
38
|
model.addHook('beforeBulkUpdate', 'sadot-beforeBulkUpdate', beforeBulkUpdate);
|
|
39
39
|
model.addHook('beforeCreate', 'sadot-beforeCreate', beforeCreate(scopeAttributes));
|
|
40
40
|
model.addHook('beforeUpdate', 'sadot-beforeUpdate', beforeUpdate(scopeAttributes));
|
|
41
|
-
model.addHook('afterFind', 'sadot-afterFind', enrichResults(name, scopeAttributes));
|
|
41
|
+
model.addHook('afterFind', 'sadot-afterFind', enrichResults(name, scopeAttributes, 'afterFind'));
|
|
42
42
|
model.addHook('afterUpdate', 'sadot-afterUpdate', enrichResults(name, scopeAttributes));
|
|
43
43
|
model.addHook('afterCreate', 'sadot-afterCreate', enrichResults(name, scopeAttributes));
|
|
44
44
|
} catch (e) {
|