@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
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import "../models/CustomFieldDefinition.cjs";
|
|
2
|
+
import { ModelCtor, Sequelize } from "sequelize-typescript";
|
|
3
|
+
import { IncludeOptions } from "sequelize";
|
|
4
|
+
import { getUser } from "@autofleet/zehut";
|
|
5
|
+
|
|
6
|
+
//#region src/types/index.d.ts
|
|
7
|
+
type ModelFetcher = (name: string) => any;
|
|
8
|
+
interface ModelOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Include options for the model
|
|
11
|
+
*/
|
|
12
|
+
include?: (entityIds: string | string[]) => IncludeOptions[];
|
|
13
|
+
/**
|
|
14
|
+
* Custom association for the model
|
|
15
|
+
* @param model - The model to associate with
|
|
16
|
+
*/
|
|
17
|
+
customAssociation?: (model: ModelCtor) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Whether to use the entity id from the instance per scope attribute
|
|
20
|
+
*/
|
|
21
|
+
useEntityIdFromInclude?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Which attributes to include in the model
|
|
24
|
+
*/
|
|
25
|
+
attributes?: string[];
|
|
26
|
+
}
|
|
27
|
+
interface Models {
|
|
28
|
+
name: string;
|
|
29
|
+
scopeAttributes: any[];
|
|
30
|
+
modelOptions?: ModelOptions;
|
|
31
|
+
creationWebhookHandler?: (instance: any) => any;
|
|
32
|
+
updateWebhookHandler?: (instance: any) => any;
|
|
33
|
+
deletionWebhookHandler?: (instance: any) => any;
|
|
34
|
+
}
|
|
35
|
+
interface CustomFieldOptions {
|
|
36
|
+
models: Models[];
|
|
37
|
+
databaseConfig: any;
|
|
38
|
+
getUser: typeof getUser;
|
|
39
|
+
sequelize?: Sequelize;
|
|
40
|
+
useCustomFieldsEntries?: boolean;
|
|
41
|
+
useValidators?: boolean;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { CustomFieldOptions, ModelFetcher, Models };
|
|
45
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,47 +1,46 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import "../models/CustomValidator.js";
|
|
2
|
+
import "../models/CustomFieldDefinition.js";
|
|
3
|
+
import { IncludeOptions } from "sequelize";
|
|
4
|
+
import { getUser } from "@autofleet/zehut";
|
|
5
|
+
import { ModelCtor, Sequelize } from "sequelize-typescript";
|
|
6
|
+
|
|
7
|
+
//#region src/types/index.d.ts
|
|
8
|
+
type ModelFetcher = (name: string) => any;
|
|
9
|
+
interface ModelOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Include options for the model
|
|
12
|
+
*/
|
|
13
|
+
include?: (entityIds: string | string[]) => IncludeOptions[];
|
|
14
|
+
/**
|
|
15
|
+
* Custom association for the model
|
|
16
|
+
* @param model - The model to associate with
|
|
17
|
+
*/
|
|
18
|
+
customAssociation?: (model: ModelCtor) => void;
|
|
19
|
+
/**
|
|
20
|
+
* Whether to use the entity id from the instance per scope attribute
|
|
21
|
+
*/
|
|
22
|
+
useEntityIdFromInclude?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Which attributes to include in the model
|
|
25
|
+
*/
|
|
26
|
+
attributes?: string[];
|
|
12
27
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
export type Models = {
|
|
33
|
-
name: string;
|
|
34
|
-
scopeAttributes: any[];
|
|
35
|
-
modelOptions?: ModelOptions;
|
|
36
|
-
creationWebhookHandler?: (instance: any) => any;
|
|
37
|
-
updateWebhookHandler?: (instance: any) => any;
|
|
38
|
-
deletionWebhookHandler?: (instance: any) => any;
|
|
39
|
-
};
|
|
40
|
-
export type CustomFieldOptions = {
|
|
41
|
-
models: Models[];
|
|
42
|
-
databaseConfig: any;
|
|
43
|
-
getUser: typeof GetUserType;
|
|
44
|
-
sequelize?: Sequelize;
|
|
45
|
-
useCustomFieldsEntries?: boolean;
|
|
46
|
-
useValidators?: boolean;
|
|
47
|
-
};
|
|
28
|
+
interface Models {
|
|
29
|
+
name: string;
|
|
30
|
+
scopeAttributes: any[];
|
|
31
|
+
modelOptions?: ModelOptions;
|
|
32
|
+
creationWebhookHandler?: (instance: any) => any;
|
|
33
|
+
updateWebhookHandler?: (instance: any) => any;
|
|
34
|
+
deletionWebhookHandler?: (instance: any) => any;
|
|
35
|
+
}
|
|
36
|
+
interface CustomFieldOptions {
|
|
37
|
+
models: Models[];
|
|
38
|
+
databaseConfig: any;
|
|
39
|
+
getUser: typeof getUser;
|
|
40
|
+
sequelize?: Sequelize;
|
|
41
|
+
useCustomFieldsEntries?: boolean;
|
|
42
|
+
useValidators?: boolean;
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { CustomFieldOptions, ModelFetcher, Models };
|
|
46
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`../../_virtual/rolldown_runtime.cjs`);let t=require(`@autofleet/common-types`);const n=[`businessModelId`,`fleetId`,`demandSourceId`];let r=function(e){return e.NUMBER=`number`,e.BOOLEAN=`boolean`,e.DATE=`date`,e.DATETIME=`datetime`,e.TEXT=`text`,e.IMAGE=`image`,e.SELECT=`select`,e.STATUS=`status`,e.FILE=`file`,e}({});const i=t.customFields.CUSTOM_FIELDS_FILTER_SCOPE;exports.CUSTOM_FIELDS_FILTER_SCOPE=i,exports.CustomFieldDefinitionType=r,exports.supportedEntities=n;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["CUSTOM_FIELDS_FILTER_SCOPE: typeof customFields.CUSTOM_FIELDS_FILTER_SCOPE","customFields"],"sources":["../../../src/utils/constants/index.ts"],"sourcesContent":["import { customFields } from '@autofleet/common-types';\n\nexport const supportedEntities = ['businessModelId', 'fleetId', 'demandSourceId'] as const;\n\n/**\n * Supported custom field types\n */\nexport enum CustomFieldDefinitionType {\n NUMBER = 'number',\n BOOLEAN = 'boolean',\n DATE = 'date',\n DATETIME = 'datetime',\n TEXT = 'text',\n IMAGE = 'image',\n SELECT = 'select',\n STATUS = 'status',\n FILE = 'file',\n}\n\nconst CUSTOM_FIELDS_FILTER_SCOPE: typeof customFields.CUSTOM_FIELDS_FILTER_SCOPE = customFields.CUSTOM_FIELDS_FILTER_SCOPE;\n\nexport {\n /** @deprecated Use the value from `@autofleet/common-types` instead */\n CUSTOM_FIELDS_FILTER_SCOPE,\n};\n"],"mappings":"gGAEA,MAAa,EAAoB,CAAC,kBAAmB,UAAW,iBAAiB,CAKjF,IAAY,EAAA,SAAA,EAAL,OACL,GAAA,OAAA,SACA,EAAA,QAAA,UACA,EAAA,KAAA,OACA,EAAA,SAAA,WACA,EAAA,KAAA,OACA,EAAA,MAAA,QACA,EAAA,OAAA,SACA,EAAA,OAAA,SACA,EAAA,KAAA,cAGF,MAAMA,EAA6EC,EAAAA,aAAa"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { customFields } from "@autofleet/common-types";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/constants/index.d.ts
|
|
4
|
+
declare const supportedEntities: readonly ["businessModelId", "fleetId", "demandSourceId"];
|
|
5
|
+
/**
|
|
6
|
+
* Supported custom field types
|
|
7
|
+
*/
|
|
8
|
+
declare enum CustomFieldDefinitionType {
|
|
9
|
+
NUMBER = "number",
|
|
10
|
+
BOOLEAN = "boolean",
|
|
11
|
+
DATE = "date",
|
|
12
|
+
DATETIME = "datetime",
|
|
13
|
+
TEXT = "text",
|
|
14
|
+
IMAGE = "image",
|
|
15
|
+
SELECT = "select",
|
|
16
|
+
STATUS = "status",
|
|
17
|
+
FILE = "file",
|
|
18
|
+
}
|
|
19
|
+
declare const CUSTOM_FIELDS_FILTER_SCOPE: typeof customFields.CUSTOM_FIELDS_FILTER_SCOPE;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { CUSTOM_FIELDS_FILTER_SCOPE, CustomFieldDefinitionType, supportedEntities };
|
|
22
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { customFields } from "@autofleet/common-types";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/constants/index.d.ts
|
|
4
|
+
declare const supportedEntities: readonly ["businessModelId", "fleetId", "demandSourceId"];
|
|
3
5
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
* Supported custom field types
|
|
7
|
+
*/
|
|
8
|
+
declare enum CustomFieldDefinitionType {
|
|
9
|
+
NUMBER = "number",
|
|
10
|
+
BOOLEAN = "boolean",
|
|
11
|
+
DATE = "date",
|
|
12
|
+
DATETIME = "datetime",
|
|
13
|
+
TEXT = "text",
|
|
14
|
+
IMAGE = "image",
|
|
15
|
+
SELECT = "select",
|
|
16
|
+
STATUS = "status",
|
|
17
|
+
FILE = "file",
|
|
16
18
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
CUSTOM_FIELDS_FILTER_SCOPE, };
|
|
19
|
+
declare const CUSTOM_FIELDS_FILTER_SCOPE: typeof customFields.CUSTOM_FIELDS_FILTER_SCOPE;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { CUSTOM_FIELDS_FILTER_SCOPE, CustomFieldDefinitionType, supportedEntities };
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,22 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 = {}));
|
|
1
|
+
import{customFields as e}from"@autofleet/common-types";const t=[`businessModelId`,`fleetId`,`demandSourceId`];let n=function(e){return e.NUMBER=`number`,e.BOOLEAN=`boolean`,e.DATE=`date`,e.DATETIME=`datetime`,e.TEXT=`text`,e.IMAGE=`image`,e.SELECT=`select`,e.STATUS=`status`,e.FILE=`file`,e}({});const r=e.CUSTOM_FIELDS_FILTER_SCOPE;export{r as CUSTOM_FIELDS_FILTER_SCOPE,n as CustomFieldDefinitionType,t as supportedEntities};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["CUSTOM_FIELDS_FILTER_SCOPE: typeof customFields.CUSTOM_FIELDS_FILTER_SCOPE"],"sources":["../../../src/utils/constants/index.ts"],"sourcesContent":["import { customFields } from '@autofleet/common-types';\n\nexport const supportedEntities = ['businessModelId', 'fleetId', 'demandSourceId'] as const;\n\n/**\n * Supported custom field types\n */\nexport enum CustomFieldDefinitionType {\n NUMBER = 'number',\n BOOLEAN = 'boolean',\n DATE = 'date',\n DATETIME = 'datetime',\n TEXT = 'text',\n IMAGE = 'image',\n SELECT = 'select',\n STATUS = 'status',\n FILE = 'file',\n}\n\nconst CUSTOM_FIELDS_FILTER_SCOPE: typeof customFields.CUSTOM_FIELDS_FILTER_SCOPE = customFields.CUSTOM_FIELDS_FILTER_SCOPE;\n\nexport {\n /** @deprecated Use the value from `@autofleet/common-types` instead */\n CUSTOM_FIELDS_FILTER_SCOPE,\n};\n"],"mappings":"uDAEA,MAAa,EAAoB,CAAC,kBAAmB,UAAW,iBAAiB,CAKjF,IAAY,EAAA,SAAA,EAAL,OACL,GAAA,OAAA,SACA,EAAA,QAAA,UACA,EAAA,KAAA,OACA,EAAA,SAAA,WACA,EAAA,KAAA,OACA,EAAA,MAAA,QACA,EAAA,OAAA,SACA,EAAA,OAAA,SACA,EAAA,KAAA,cAGF,MAAMA,EAA6E,EAAa"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`../../_virtual/rolldown_runtime.cjs`);let t=require(`sequelize`),n=require(`sequelize-typescript`);var r=e=>{let t=e[process.env.NODE_ENV||`test`],r;return r=t.use_env_variable?new n.Sequelize(process.env[t.use_env_variable],t):new n.Sequelize(t.database,t.username,t.password,t),r};exports.default=r;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["sequelize: Sequelize","Sequelize","sequelize"],"sources":["../../../src/utils/db/index.ts"],"sourcesContent":["import { Sequelize } from 'sequelize-typescript';\nimport { QueryTypes } from 'sequelize';\n\nexport default (databaseConfig: any): Sequelize => {\n const ENV_DEV = 'test';\n const env: string = process.env.NODE_ENV || ENV_DEV;\n const config = databaseConfig[env];\n let sequelize: Sequelize;\n if (config.use_env_variable) {\n sequelize = new Sequelize(process.env[config.use_env_variable]!, config);\n } else {\n sequelize = new Sequelize(config.database, config.username, config.password, config);\n }\n return sequelize;\n};\n\nexport const createSequelizeMeta = (sequelize: Sequelize): Promise<{ name: string; }[]> => sequelize.query(`\nCREATE TABLE IF NOT EXISTS \"SequelizeMeta\" (\n name character varying(255) PRIMARY KEY\n);\n`, { type: QueryTypes.SELECT });\n"],"mappings":"oHAGA,IAAA,EAAgB,GAAmC,CAGjD,IAAM,EAAS,EADK,QAAQ,IAAI,UADhB,QAGZA,EAMJ,MALA,CAGE,EAHE,EAAO,iBACG,IAAIC,EAAAA,UAAU,QAAQ,IAAI,EAAO,kBAAoB,EAAO,CAE5D,IAAIA,EAAAA,UAAU,EAAO,SAAU,EAAO,SAAU,EAAO,SAAU,EAAO,CAE/EC"}
|
package/dist/utils/db/index.js
CHANGED
|
@@ -1,24 +1,2 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
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;
|
|
1
|
+
import"sequelize";import{Sequelize as e}from"sequelize-typescript";var t=t=>{let n=t[process.env.NODE_ENV||`test`],r;return r=n.use_env_variable?new e(process.env[n.use_env_variable],n):new e(n.database,n.username,n.password,n),r};export{t as default};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["sequelize: Sequelize"],"sources":["../../../src/utils/db/index.ts"],"sourcesContent":["import { Sequelize } from 'sequelize-typescript';\nimport { QueryTypes } from 'sequelize';\n\nexport default (databaseConfig: any): Sequelize => {\n const ENV_DEV = 'test';\n const env: string = process.env.NODE_ENV || ENV_DEV;\n const config = databaseConfig[env];\n let sequelize: Sequelize;\n if (config.use_env_variable) {\n sequelize = new Sequelize(process.env[config.use_env_variable]!, config);\n } else {\n sequelize = new Sequelize(config.database, config.username, config.password, config);\n }\n return sequelize;\n};\n\nexport const createSequelizeMeta = (sequelize: Sequelize): Promise<{ name: string; }[]> => sequelize.query(`\nCREATE TABLE IF NOT EXISTS \"SequelizeMeta\" (\n name character varying(255) PRIMARY KEY\n);\n`, { type: QueryTypes.SELECT });\n"],"mappings":"mEAGA,IAAA,EAAgB,GAAmC,CAGjD,IAAM,EAAS,EADK,QAAQ,IAAI,UADhB,QAGZA,EAMJ,MALA,CAGE,EAHE,EAAO,iBACG,IAAI,EAAU,QAAQ,IAAI,EAAO,kBAAoB,EAAO,CAE5D,IAAI,EAAU,EAAO,SAAU,EAAO,SAAU,EAAO,SAAU,EAAO,CAE/E"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`../../_virtual/rolldown_runtime.cjs`),t=require(`../constants/index.cjs`);let n=require(`sequelize`),r=require(`sequelize-typescript`),i=require(`node:crypto`);const a=(e=5)=>Array.from({length:e},()=>`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`.charAt((0,i.randomInt)(52))).join(``),o=(e,i,a,o=[t.CustomFieldDefinitionType.DATETIME,t.CustomFieldDefinitionType.DATE])=>{let s=o.map(e=>`'${e}'`).join(`,`),c=`EXISTS ( SELECT 1 FROM "custom_field_values" AS "cv" INNER JOIN custom_field_definitions AS cd ON cd.entity_id = '${a}' AND cv.custom_field_definition_id = cd.id AND cd.model_type = '${i.name}' ${s?`AND cd.field_type NOT IN (${s})`:``} WHERE "cv"."deleted_at" IS NULL AND "cv"."model_id" = "${i.name}"."id" AND CAST("cv"."value" AS TEXT) ILIKE :searchTerm)`;return{where:{[n.Op.or]:[r.Sequelize.where(r.Sequelize.literal(c),!0)]},replacements:{searchTerm:`%${e}%`}}};exports.generateCustomFieldSearchQueryPayload=o,exports.generateRandomString=a;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["CustomFieldDefinitionType","Op","Sequelize"],"sources":["../../../src/utils/helpers/index.ts"],"sourcesContent":["import { type WhereOptions, Op, type BindOrReplacements } from 'sequelize';\nimport { type ModelStatic, Sequelize } from 'sequelize-typescript';\nimport { randomInt } from 'node:crypto';\nimport { CustomFieldDefinitionType } from '../constants';\n\n/**\n * Builds a WHERE clause and replacements for free-text search by custom fields.\n *\n * This function constructs a WHERE clause and replacement bindings that allow searching\n * for a given term within custom fields associated with a specific model type and entity ID.\n * The WHERE clause and replacements are designed to be added to the main query.\n *\n * @param {string} searchTerm - The term to search for within custom fields.\n * @param {ModelStatic} model - The Sequelize model representing the entity type to search for.\n * @param {string} entityId - The entity ID to filter the custom fields by.\n * @param {CustomFieldDefinitionType[]} excludedCustomFieldsTypes - An array of custom field types\n * to exclude from the search\n *\n * @returns {CustomFieldsSearchPayload} - An object containing the WHERE clause and replacements\n * for Sequelize.\n */\n\ninterface CustomFieldsSearchPayload {\n where: WhereOptions;\n replacements: BindOrReplacements;\n}\n\nexport const generateRandomString = (length = 5): string => {\n const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';\n return Array.from({ length }, () => characters.charAt(randomInt(characters.length))).join('');\n};\n\nexport const generateCustomFieldSearchQueryPayload = (\n searchTerm: string,\n model: ModelStatic,\n entityId: string,\n customFieldsTypesToExclude: CustomFieldDefinitionType[] = [\n CustomFieldDefinitionType.DATETIME,\n CustomFieldDefinitionType.DATE,\n ],\n): CustomFieldsSearchPayload => {\n const excludedTypesString = customFieldsTypesToExclude.map(type => `'${type}'`).join(',');\n\n const subQuery = 'EXISTS ('\n + ' SELECT 1'\n + ' FROM \"custom_field_values\" AS \"cv\"'\n + ' INNER JOIN custom_field_definitions AS cd '\n + ` ON cd.entity_id = '${entityId}'`\n + ' AND cv.custom_field_definition_id = cd.id'\n + ` AND cd.model_type = '${model.name}'`\n + ` ${excludedTypesString ? `AND cd.field_type NOT IN (${excludedTypesString})` : ''}`\n + ' WHERE'\n + ' \"cv\".\"deleted_at\" IS NULL'\n + ` AND \"cv\".\"model_id\" = \"${model.name}\".\"id\"`\n + ' AND CAST(\"cv\".\"value\" AS TEXT) ILIKE :searchTerm)';\n\n return {\n where: {\n [Op.or]: [\n Sequelize.where(Sequelize.literal(subQuery), true),\n ],\n },\n replacements: { searchTerm: `%${searchTerm}%` },\n };\n};\n"],"mappings":"iLA2BA,MAAa,GAAwB,EAAS,IAErC,MAAM,KAAK,CAAE,SAAQ,KAAQ,uDAAW,QAAA,EAAA,EAAA,WAAiB,GAAkB,CAAC,CAAC,CAAC,KAAK,GAAG,CAGlF,GACX,EACA,EACA,EACA,EAA0D,CACxDA,EAAAA,0BAA0B,SAC1BA,EAAAA,0BAA0B,KAC3B,GAC6B,CAC9B,IAAM,EAAsB,EAA2B,IAAI,GAAQ,IAAI,EAAK,GAAG,CAAC,KAAK,IAAI,CAEnF,EAAW,sHAIU,EAAS,mEAEP,EAAM,KAAK,IAChC,EAAsB,6BAA6B,EAAoB,GAAK,GAAA,0DAGrD,EAAM,KAAK,0DAG1C,MAAO,CACL,MAAO,EACJC,EAAAA,GAAG,IAAK,CACPC,EAAAA,UAAU,MAAMA,EAAAA,UAAU,QAAQ,EAAS,CAAE,GAAK,CACnD,CACF,CACD,aAAc,CAAE,WAAY,IAAI,EAAW,GAAI,CAChD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { CustomFieldDefinitionType } from "../constants/index.cjs";
|
|
2
|
+
import { ModelStatic } from "sequelize-typescript";
|
|
3
|
+
import { BindOrReplacements, WhereOptions } from "sequelize";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/helpers/index.d.ts
|
|
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
|
+
interface CustomFieldsSearchPayload {
|
|
24
|
+
where: WhereOptions;
|
|
25
|
+
replacements: BindOrReplacements;
|
|
26
|
+
}
|
|
27
|
+
declare const generateRandomString: (length?: number) => string;
|
|
28
|
+
declare const generateCustomFieldSearchQueryPayload: (searchTerm: string, model: ModelStatic, entityId: string, customFieldsTypesToExclude?: CustomFieldDefinitionType[]) => CustomFieldsSearchPayload;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { generateCustomFieldSearchQueryPayload, generateRandomString };
|
|
31
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1,26 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { CustomFieldDefinitionType } from "../constants/index.js";
|
|
2
|
+
import { BindOrReplacements, WhereOptions } from "sequelize";
|
|
3
|
+
import { ModelStatic } from "sequelize-typescript";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/helpers/index.d.ts
|
|
6
|
+
|
|
4
7
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
+
*/
|
|
20
23
|
interface CustomFieldsSearchPayload {
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
where: WhereOptions;
|
|
25
|
+
replacements: BindOrReplacements;
|
|
23
26
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
declare const generateRandomString: (length?: number) => string;
|
|
28
|
+
declare const generateCustomFieldSearchQueryPayload: (searchTerm: string, model: ModelStatic, entityId: string, customFieldsTypesToExclude?: CustomFieldDefinitionType[]) => CustomFieldsSearchPayload;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { generateCustomFieldSearchQueryPayload, generateRandomString };
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,40 +1,2 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
exports.generateCustomFieldSearchQueryPayload = exports.generateRandomString = void 0;
|
|
4
|
-
/* eslint-disable import/prefer-default-export */
|
|
5
|
-
const sequelize_1 = require("sequelize");
|
|
6
|
-
const sequelize_typescript_1 = require("sequelize-typescript");
|
|
7
|
-
const node_crypto_1 = require("node:crypto");
|
|
8
|
-
const constants_1 = require("../constants");
|
|
9
|
-
const generateRandomString = (length = 5) => {
|
|
10
|
-
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
11
|
-
return Array.from({ length }, () => characters.charAt((0, node_crypto_1.randomInt)(characters.length))).join('');
|
|
12
|
-
};
|
|
13
|
-
exports.generateRandomString = generateRandomString;
|
|
14
|
-
const generateCustomFieldSearchQueryPayload = (searchTerm, model, entityId, customFieldsTypesToExclude = [
|
|
15
|
-
constants_1.CustomFieldDefinitionType.DATETIME,
|
|
16
|
-
constants_1.CustomFieldDefinitionType.DATE,
|
|
17
|
-
]) => {
|
|
18
|
-
const excludedTypesString = customFieldsTypesToExclude.map((type) => `'${type}'`).join(',');
|
|
19
|
-
const subQuery = 'EXISTS ('
|
|
20
|
-
+ ' SELECT 1'
|
|
21
|
-
+ ' FROM "custom_field_values" AS "cv"'
|
|
22
|
-
+ ' INNER JOIN custom_field_definitions AS cd '
|
|
23
|
-
+ ` ON cd.entity_id = '${entityId}'`
|
|
24
|
-
+ ' AND cv.custom_field_definition_id = cd.id'
|
|
25
|
-
+ ` AND cd.model_type = '${model.name}'`
|
|
26
|
-
+ ` ${excludedTypesString ? `AND cd.field_type NOT IN (${excludedTypesString})` : ''}`
|
|
27
|
-
+ ' WHERE'
|
|
28
|
-
+ ' "cv"."deleted_at" IS NULL'
|
|
29
|
-
+ ` AND "cv"."model_id" = "${model.name}"."id"`
|
|
30
|
-
+ ' AND CAST("cv"."value" AS TEXT) ILIKE :searchTerm)';
|
|
31
|
-
return {
|
|
32
|
-
where: {
|
|
33
|
-
[sequelize_1.Op.or]: [
|
|
34
|
-
sequelize_typescript_1.Sequelize.where(sequelize_typescript_1.Sequelize.literal(subQuery), true),
|
|
35
|
-
],
|
|
36
|
-
},
|
|
37
|
-
replacements: { searchTerm: `%${searchTerm}%` },
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
exports.generateCustomFieldSearchQueryPayload = generateCustomFieldSearchQueryPayload;
|
|
1
|
+
import{CustomFieldDefinitionType as e}from"../constants/index.js";import{Op as t}from"sequelize";import{Sequelize as n}from"sequelize-typescript";import{randomInt as r}from"node:crypto";const i=(e=5)=>Array.from({length:e},()=>`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`.charAt(r(52))).join(``),a=(r,i,a,o=[e.DATETIME,e.DATE])=>{let s=o.map(e=>`'${e}'`).join(`,`),c=`EXISTS ( SELECT 1 FROM "custom_field_values" AS "cv" INNER JOIN custom_field_definitions AS cd ON cd.entity_id = '${a}' AND cv.custom_field_definition_id = cd.id AND cd.model_type = '${i.name}' ${s?`AND cd.field_type NOT IN (${s})`:``} WHERE "cv"."deleted_at" IS NULL AND "cv"."model_id" = "${i.name}"."id" AND CAST("cv"."value" AS TEXT) ILIKE :searchTerm)`;return{where:{[t.or]:[n.where(n.literal(c),!0)]},replacements:{searchTerm:`%${r}%`}}};export{a as generateCustomFieldSearchQueryPayload,i as generateRandomString};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/utils/helpers/index.ts"],"sourcesContent":["import { type WhereOptions, Op, type BindOrReplacements } from 'sequelize';\nimport { type ModelStatic, Sequelize } from 'sequelize-typescript';\nimport { randomInt } from 'node:crypto';\nimport { CustomFieldDefinitionType } from '../constants';\n\n/**\n * Builds a WHERE clause and replacements for free-text search by custom fields.\n *\n * This function constructs a WHERE clause and replacement bindings that allow searching\n * for a given term within custom fields associated with a specific model type and entity ID.\n * The WHERE clause and replacements are designed to be added to the main query.\n *\n * @param {string} searchTerm - The term to search for within custom fields.\n * @param {ModelStatic} model - The Sequelize model representing the entity type to search for.\n * @param {string} entityId - The entity ID to filter the custom fields by.\n * @param {CustomFieldDefinitionType[]} excludedCustomFieldsTypes - An array of custom field types\n * to exclude from the search\n *\n * @returns {CustomFieldsSearchPayload} - An object containing the WHERE clause and replacements\n * for Sequelize.\n */\n\ninterface CustomFieldsSearchPayload {\n where: WhereOptions;\n replacements: BindOrReplacements;\n}\n\nexport const generateRandomString = (length = 5): string => {\n const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';\n return Array.from({ length }, () => characters.charAt(randomInt(characters.length))).join('');\n};\n\nexport const generateCustomFieldSearchQueryPayload = (\n searchTerm: string,\n model: ModelStatic,\n entityId: string,\n customFieldsTypesToExclude: CustomFieldDefinitionType[] = [\n CustomFieldDefinitionType.DATETIME,\n CustomFieldDefinitionType.DATE,\n ],\n): CustomFieldsSearchPayload => {\n const excludedTypesString = customFieldsTypesToExclude.map(type => `'${type}'`).join(',');\n\n const subQuery = 'EXISTS ('\n + ' SELECT 1'\n + ' FROM \"custom_field_values\" AS \"cv\"'\n + ' INNER JOIN custom_field_definitions AS cd '\n + ` ON cd.entity_id = '${entityId}'`\n + ' AND cv.custom_field_definition_id = cd.id'\n + ` AND cd.model_type = '${model.name}'`\n + ` ${excludedTypesString ? `AND cd.field_type NOT IN (${excludedTypesString})` : ''}`\n + ' WHERE'\n + ' \"cv\".\"deleted_at\" IS NULL'\n + ` AND \"cv\".\"model_id\" = \"${model.name}\".\"id\"`\n + ' AND CAST(\"cv\".\"value\" AS TEXT) ILIKE :searchTerm)';\n\n return {\n where: {\n [Op.or]: [\n Sequelize.where(Sequelize.literal(subQuery), true),\n ],\n },\n replacements: { searchTerm: `%${searchTerm}%` },\n };\n};\n"],"mappings":"0LA2BA,MAAa,GAAwB,EAAS,IAErC,MAAM,KAAK,CAAE,SAAQ,KAAQ,uDAAW,OAAO,EAAU,GAAkB,CAAC,CAAC,CAAC,KAAK,GAAG,CAGlF,GACX,EACA,EACA,EACA,EAA0D,CACxD,EAA0B,SAC1B,EAA0B,KAC3B,GAC6B,CAC9B,IAAM,EAAsB,EAA2B,IAAI,GAAQ,IAAI,EAAK,GAAG,CAAC,KAAK,IAAI,CAEnF,EAAW,sHAIU,EAAS,mEAEP,EAAM,KAAK,IAChC,EAAsB,6BAA6B,EAAoB,GAAK,GAAA,0DAGrD,EAAM,KAAK,0DAG1C,MAAO,CACL,MAAO,EACJ,EAAG,IAAK,CACP,EAAU,MAAM,EAAU,QAAQ,EAAS,CAAE,GAAK,CACnD,CACF,CACD,aAAc,CAAE,WAAY,IAAI,EAAW,GAAI,CAChD"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`./logger/index.cjs`),n=require(`../models/CustomFieldDefinition.cjs`),r=require(`../models/CustomFieldValue.cjs`),i=require(`../models/CustomValidator.cjs`);require(`../models/index.cjs`);const a=require(`../hooks/enrich.cjs`),o=require(`../hooks/find.cjs`),s=require(`../hooks/hooks.cjs`);require(`../hooks/index.cjs`);const c=require(`../scopes/filter.cjs`);require(`../scopes/index.cjs`);let l=require(`sequelize`),u=require(`@autofleet/common-types`),d=require(`@autofleet/common-types/lib/custom-fields`);const{CUSTOM_FIELDS_FILTER_SCOPE:f}=u.customFields,p=(e,n,r={useCustomFieldsEntries:!1})=>{e.forEach(async({name:e,scopeAttributes:i,modelOptions:c})=>{try{let u=n(e);if(!u){t.default.warn(`sadot - tried to addHooks to a model that does not exist yet`,{name:e,scopeAttributes:i});return}u.rawAttributes.customFields={type:l.DataTypes.VIRTUAL},u.refreshAttributes(),u.addHook(`beforeFind`,`sadot-beforeFind`,o.beforeFind(i)),u.addHook(`beforeBulkCreate`,`sadot-beforeBulkCreate`,s.beforeBulkCreate),u.addHook(`beforeBulkUpdate`,`sadot-beforeBulkUpdate`,s.beforeBulkUpdate),u.addHook(`beforeCreate`,`sadot-beforeCreate`,s.beforeCreate(i,c,r)),u.addHook(`beforeUpdate`,`sadot-beforeUpdate`,s.beforeUpdate(i,c,r)),u.addHook(`afterFind`,`sadot-afterFind`,a.default(e,i,`afterFind`,c,r)),u.addHook(`afterUpdate`,`sadot-afterUpdate`,a.default(e,i,void 0,c,r)),u.addHook(`afterCreate`,`sadot-afterCreate`,a.default(e,i,void 0,c,r))}catch(n){t.default.error(`Could not add custom fields hook to model ${e}. `,n)}})},m=(e,n)=>{e.forEach(async({name:e})=>{try{let t=n(e);if(!t)return;t.rawAttributes.customFields&&(delete t.rawAttributes.customFields,t.refreshAttributes()),t.removeHook(`beforeFind`,`sadot-beforeFind`),t.removeHook(`beforeBulkCreate`,`sadot-beforeBulkCreate`),t.removeHook(`beforeBulkUpdate`,`sadot-beforeBulkUpdate`),t.removeHook(`beforeCreate`,`sadot-beforeCreate`),t.removeHook(`beforeUpdate`,`sadot-beforeUpdate`),t.removeHook(`afterFind`,`sadot-afterFind`),t.removeHook(`afterUpdate`,`sadot-afterUpdate`)}catch(n){t.default.error(`Could not add custom fields hook to model ${e}. `,n)}})},h=(e,t,n)=>{n?.useCustomFieldsEntries||(e.hasMany(r.default,{foreignKey:`modelId`,as:`customFieldValue`}),r.default.belongsTo(e,{foreignKey:`modelId`,as:t}))},g=(e,n,r={useCustomFieldsEntries:!1})=>{e.forEach(async({name:e,scopeAttributes:i})=>{try{let a=n(e);if(!a){t.default.warn(`sadot - tried to addScopes to a model that does not exist yet`,{name:e,scopeAttributes:i});return}h(a,e,r),a.addScope(f,c.customFieldsFilterScope(e,r)),a.addScope(d.CUSTOM_FIELDS_SORT_SCOPE,c.customFieldsSortScope(e,r))}catch(n){t.default.error(`Could not add custom fields scopes to model ${e}. `,n)}})},_=e=>{e.forEach(({modelOptions:e})=>{e?.customAssociation?.(n.default),e?.customAssociation?.(i.default)})};exports.addHooks=p,exports.addScopes=g,exports.applyCustomAssociation=_,exports.removeHooks=m;
|
|
2
|
+
//# sourceMappingURL=init.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.cjs","names":["customFields","DataTypes","beforeFind","beforeBulkCreate","beforeBulkUpdate","beforeCreate","beforeUpdate","enrichResults","CustomFieldValue","customFieldsFilterScope","CUSTOM_FIELDS_SORT_SCOPE","customFieldsSortScope","CustomFieldDefinition","CustomValidator"],"sources":["../../src/utils/init.ts"],"sourcesContent":["import { DataTypes } from 'sequelize';\nimport type { ModelCtor } from 'sequelize-typescript';\nimport { customFields } from '@autofleet/common-types';\nimport { CUSTOM_FIELDS_SORT_SCOPE } from '@autofleet/common-types/lib/custom-fields';\nimport {\n CustomFieldDefinition,\n CustomFieldValue,\n CustomValidator,\n} from '../models';\nimport {\n beforeFind,\n enrichResults,\n beforeBulkUpdate,\n beforeUpdate,\n beforeCreate,\n beforeBulkCreate,\n} from '../hooks';\nimport { customFieldsFilterScope } from '../scopes';\nimport logger from './logger';\nimport type { CustomFieldOptions, ModelFetcher, Models } from '../types';\nimport { customFieldsSortScope } from '../scopes/filter';\n\nconst { CUSTOM_FIELDS_FILTER_SCOPE } = customFields;\n\nexport const addHooks = (\n models: Models[],\n getModel: ModelFetcher,\n sadotOptions: { useCustomFieldsEntries?: boolean; } = { useCustomFieldsEntries: false },\n): void => {\n models.forEach(async ({\n name, scopeAttributes, modelOptions,\n }) => {\n try {\n const model = getModel(name);\n if (!model) {\n logger.warn('sadot - tried to addHooks to a model that does not exist yet', {\n name,\n scopeAttributes,\n });\n return;\n }\n model.rawAttributes.customFields = {\n type: DataTypes.VIRTUAL,\n };\n model.refreshAttributes();\n // TODO: Uncomment after tests are passed\n // model.addHook('afterFind', workaround);\n model.addHook('beforeFind', 'sadot-beforeFind', beforeFind(scopeAttributes));\n model.addHook('beforeBulkCreate', 'sadot-beforeBulkCreate', beforeBulkCreate);\n model.addHook('beforeBulkUpdate', 'sadot-beforeBulkUpdate', beforeBulkUpdate);\n model.addHook('beforeCreate', 'sadot-beforeCreate', beforeCreate(scopeAttributes, modelOptions, sadotOptions));\n model.addHook('beforeUpdate', 'sadot-beforeUpdate', beforeUpdate(scopeAttributes, modelOptions, sadotOptions));\n model.addHook('afterFind', 'sadot-afterFind', enrichResults(name, scopeAttributes, 'afterFind', modelOptions, sadotOptions));\n model.addHook('afterUpdate', 'sadot-afterUpdate', enrichResults(name, scopeAttributes, undefined, modelOptions, sadotOptions));\n model.addHook('afterCreate', 'sadot-afterCreate', enrichResults(name, scopeAttributes, undefined, modelOptions, sadotOptions));\n } catch (e) {\n logger.error(`Could not add custom fields hook to model ${name}. `, e);\n }\n });\n};\n\nexport const removeHooks = (models: Models[], getModel: ModelFetcher): void => {\n models.forEach(async ({ name }) => {\n try {\n const model = getModel(name);\n if (!model) return;\n if (model.rawAttributes.customFields) {\n delete model.rawAttributes.customFields;\n model.refreshAttributes();\n }\n // model.removeHook('afterFind', 'sadot-workaround');\n model.removeHook('beforeFind', 'sadot-beforeFind');\n model.removeHook('beforeBulkCreate', 'sadot-beforeBulkCreate');\n model.removeHook('beforeBulkUpdate', 'sadot-beforeBulkUpdate');\n model.removeHook('beforeCreate', 'sadot-beforeCreate');\n model.removeHook('beforeUpdate', 'sadot-beforeUpdate');\n model.removeHook('afterFind', 'sadot-afterFind');\n model.removeHook('afterUpdate', 'sadot-afterUpdate');\n } catch (e) {\n logger.error(`Could not add custom fields hook to model ${name}. `, e);\n }\n });\n};\n\n/**\n * Necessary associations for the {@link customFieldsFilterScope} scope\n */\nconst addAssociations = (model: ModelCtor, modelName: string, options: Pick<CustomFieldOptions, 'useCustomFieldsEntries'>): void => {\n if (options?.useCustomFieldsEntries) return;\n model.hasMany(CustomFieldValue, { foreignKey: 'modelId', as: 'customFieldValue' });\n // TBC: maybe can be removed\n CustomFieldValue.belongsTo(model, { foreignKey: 'modelId', as: modelName });\n};\n\nexport const addScopes = (models: Models[], getModel: ModelFetcher, options: Pick<CustomFieldOptions, 'useCustomFieldsEntries'> = { useCustomFieldsEntries: false }): void => {\n models.forEach(async ({ name, scopeAttributes }) => {\n try {\n const model = getModel(name);\n if (!model) {\n logger.warn('sadot - tried to addScopes to a model that does not exist yet', {\n name,\n scopeAttributes,\n });\n return;\n }\n // Necessary associations for the filtering scope\n addAssociations(model, name, options);\n // Add filter scope\n model.addScope(CUSTOM_FIELDS_FILTER_SCOPE, customFieldsFilterScope(name, options));\n model.addScope(CUSTOM_FIELDS_SORT_SCOPE, customFieldsSortScope(name, options));\n } catch (e) {\n logger.error(`Could not add custom fields scopes to model ${name}. `, e);\n }\n });\n};\n\nexport const applyCustomAssociation = (models: Models[]): void => {\n models.forEach(({ modelOptions }) => {\n modelOptions?.customAssociation?.(CustomFieldDefinition);\n modelOptions?.customAssociation?.(CustomValidator);\n });\n};\n"],"mappings":"6jBAsBA,KAAM,CAAE,8BAA+BA,EAAAA,aAE1B,GACX,EACA,EACA,EAAsD,CAAE,uBAAwB,GAAO,GAC9E,CACT,EAAO,QAAQ,MAAO,CACpB,OAAM,kBAAiB,kBACnB,CACJ,GAAI,CACF,IAAM,EAAQ,EAAS,EAAK,CAC5B,GAAI,CAAC,EAAO,CACV,EAAA,QAAO,KAAK,+DAAgE,CAC1E,OACA,kBACD,CAAC,CACF,OAEF,EAAM,cAAc,aAAe,CACjC,KAAMC,EAAAA,UAAU,QACjB,CACD,EAAM,mBAAmB,CAGzB,EAAM,QAAQ,aAAc,mBAAoBC,EAAAA,WAAW,EAAgB,CAAC,CAC5E,EAAM,QAAQ,mBAAoB,yBAA0BC,EAAAA,iBAAiB,CAC7E,EAAM,QAAQ,mBAAoB,yBAA0BC,EAAAA,iBAAiB,CAC7E,EAAM,QAAQ,eAAgB,qBAAsBC,EAAAA,aAAa,EAAiB,EAAc,EAAa,CAAC,CAC9G,EAAM,QAAQ,eAAgB,qBAAsBC,EAAAA,aAAa,EAAiB,EAAc,EAAa,CAAC,CAC9G,EAAM,QAAQ,YAAa,kBAAmBC,EAAAA,QAAc,EAAM,EAAiB,YAAa,EAAc,EAAa,CAAC,CAC5H,EAAM,QAAQ,cAAe,oBAAqBA,EAAAA,QAAc,EAAM,EAAiB,IAAA,GAAW,EAAc,EAAa,CAAC,CAC9H,EAAM,QAAQ,cAAe,oBAAqBA,EAAAA,QAAc,EAAM,EAAiB,IAAA,GAAW,EAAc,EAAa,CAAC,OACvH,EAAG,CACV,EAAA,QAAO,MAAM,6CAA6C,EAAK,IAAK,EAAE,GAExE,EAGS,GAAe,EAAkB,IAAiC,CAC7E,EAAO,QAAQ,MAAO,CAAE,UAAW,CACjC,GAAI,CACF,IAAM,EAAQ,EAAS,EAAK,CAC5B,GAAI,CAAC,EAAO,OACR,EAAM,cAAc,eACtB,OAAO,EAAM,cAAc,aAC3B,EAAM,mBAAmB,EAG3B,EAAM,WAAW,aAAc,mBAAmB,CAClD,EAAM,WAAW,mBAAoB,yBAAyB,CAC9D,EAAM,WAAW,mBAAoB,yBAAyB,CAC9D,EAAM,WAAW,eAAgB,qBAAqB,CACtD,EAAM,WAAW,eAAgB,qBAAqB,CACtD,EAAM,WAAW,YAAa,kBAAkB,CAChD,EAAM,WAAW,cAAe,oBAAoB,OAC7C,EAAG,CACV,EAAA,QAAO,MAAM,6CAA6C,EAAK,IAAK,EAAE,GAExE,EAME,GAAmB,EAAkB,EAAmB,IAAsE,CAC9H,GAAS,yBACb,EAAM,QAAQC,EAAAA,QAAkB,CAAE,WAAY,UAAW,GAAI,mBAAoB,CAAC,CAElF,EAAA,QAAiB,UAAU,EAAO,CAAE,WAAY,UAAW,GAAI,EAAW,CAAC,GAGhE,GAAa,EAAkB,EAAwB,EAA8D,CAAE,uBAAwB,GAAO,GAAW,CAC5K,EAAO,QAAQ,MAAO,CAAE,OAAM,qBAAsB,CAClD,GAAI,CACF,IAAM,EAAQ,EAAS,EAAK,CAC5B,GAAI,CAAC,EAAO,CACV,EAAA,QAAO,KAAK,gEAAiE,CAC3E,OACA,kBACD,CAAC,CACF,OAGF,EAAgB,EAAO,EAAM,EAAQ,CAErC,EAAM,SAAS,EAA4BC,EAAAA,wBAAwB,EAAM,EAAQ,CAAC,CAClF,EAAM,SAASC,EAAAA,yBAA0BC,EAAAA,sBAAsB,EAAM,EAAQ,CAAC,OACvE,EAAG,CACV,EAAA,QAAO,MAAM,+CAA+C,EAAK,IAAK,EAAE,GAE1E,EAGS,EAA0B,GAA2B,CAChE,EAAO,SAAS,CAAE,kBAAmB,CACnC,GAAc,oBAAoBC,EAAAA,QAAsB,CACxD,GAAc,oBAAoBC,EAAAA,QAAgB,EAClD"}
|
package/dist/utils/init.js
CHANGED
|
@@ -1,112 +1,2 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.applyCustomAssociation = exports.addScopes = exports.removeHooks = exports.addHooks = void 0;
|
|
7
|
-
const sequelize_1 = require("sequelize");
|
|
8
|
-
const common_types_1 = require("@autofleet/common-types");
|
|
9
|
-
const custom_fields_1 = require("@autofleet/common-types/lib/custom-fields");
|
|
10
|
-
const models_1 = require("../models");
|
|
11
|
-
const hooks_1 = require("../hooks");
|
|
12
|
-
const scopes_1 = require("../scopes");
|
|
13
|
-
const logger_1 = __importDefault(require("./logger"));
|
|
14
|
-
const filter_1 = require("../scopes/filter");
|
|
15
|
-
const { CUSTOM_FIELDS_FILTER_SCOPE } = common_types_1.customFields;
|
|
16
|
-
const addHooks = (models, getModel, sadotOptions = { useCustomFieldsEntries: false }) => {
|
|
17
|
-
models.forEach(async ({ name, scopeAttributes, modelOptions, }) => {
|
|
18
|
-
try {
|
|
19
|
-
const model = getModel(name);
|
|
20
|
-
if (!model) {
|
|
21
|
-
logger_1.default.warn('sadot - tried to addHooks to a model that does not exist yet', {
|
|
22
|
-
name,
|
|
23
|
-
scopeAttributes,
|
|
24
|
-
});
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
model.rawAttributes.customFields = {
|
|
28
|
-
type: sequelize_1.DataTypes.VIRTUAL,
|
|
29
|
-
};
|
|
30
|
-
model.refreshAttributes();
|
|
31
|
-
// TODO: Uncomment after tests are passed
|
|
32
|
-
// model.addHook('afterFind', workaround);
|
|
33
|
-
model.addHook('beforeFind', 'sadot-beforeFind', (0, hooks_1.beforeFind)(scopeAttributes));
|
|
34
|
-
model.addHook('beforeBulkCreate', 'sadot-beforeBulkCreate', hooks_1.beforeBulkCreate);
|
|
35
|
-
model.addHook('beforeBulkUpdate', 'sadot-beforeBulkUpdate', hooks_1.beforeBulkUpdate);
|
|
36
|
-
model.addHook('beforeCreate', 'sadot-beforeCreate', (0, hooks_1.beforeCreate)(scopeAttributes, modelOptions, sadotOptions));
|
|
37
|
-
model.addHook('beforeUpdate', 'sadot-beforeUpdate', (0, hooks_1.beforeUpdate)(scopeAttributes, modelOptions, sadotOptions));
|
|
38
|
-
model.addHook('afterFind', 'sadot-afterFind', (0, hooks_1.enrichResults)(name, scopeAttributes, 'afterFind', modelOptions, sadotOptions));
|
|
39
|
-
model.addHook('afterUpdate', 'sadot-afterUpdate', (0, hooks_1.enrichResults)(name, scopeAttributes, null, modelOptions, sadotOptions));
|
|
40
|
-
model.addHook('afterCreate', 'sadot-afterCreate', (0, hooks_1.enrichResults)(name, scopeAttributes, null, modelOptions, sadotOptions));
|
|
41
|
-
}
|
|
42
|
-
catch (e) {
|
|
43
|
-
logger_1.default.error(`Could not add custom fields hook to model ${name}. `, e);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
exports.addHooks = addHooks;
|
|
48
|
-
const removeHooks = (models, getModel) => {
|
|
49
|
-
models.forEach(async ({ name }) => {
|
|
50
|
-
try {
|
|
51
|
-
const model = getModel(name);
|
|
52
|
-
if (!model)
|
|
53
|
-
return;
|
|
54
|
-
if (model.rawAttributes.customFields) {
|
|
55
|
-
delete model.rawAttributes.customFields;
|
|
56
|
-
model.refreshAttributes();
|
|
57
|
-
}
|
|
58
|
-
// model.removeHook('afterFind', 'sadot-workaround');
|
|
59
|
-
model.removeHook('beforeFind', 'sadot-beforeFind');
|
|
60
|
-
model.removeHook('beforeBulkCreate', 'sadot-beforeBulkCreate');
|
|
61
|
-
model.removeHook('beforeBulkUpdate', 'sadot-beforeBulkUpdate');
|
|
62
|
-
model.removeHook('beforeCreate', 'sadot-beforeCreate');
|
|
63
|
-
model.removeHook('beforeUpdate', 'sadot-beforeUpdate');
|
|
64
|
-
model.removeHook('afterFind', 'sadot-afterFind');
|
|
65
|
-
model.removeHook('afterUpdate', 'sadot-afterUpdate');
|
|
66
|
-
}
|
|
67
|
-
catch (e) {
|
|
68
|
-
logger_1.default.error(`Could not add custom fields hook to model ${name}. `, e);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
exports.removeHooks = removeHooks;
|
|
73
|
-
/**
|
|
74
|
-
* Necessary associations for the {@link customFieldsFilterScope} scope
|
|
75
|
-
*/
|
|
76
|
-
const addAssociations = (model, modelName, options) => {
|
|
77
|
-
if (options?.useCustomFieldsEntries)
|
|
78
|
-
return;
|
|
79
|
-
model.hasMany(models_1.CustomFieldValue, { foreignKey: 'modelId', as: 'customFieldValue' });
|
|
80
|
-
// TBC: maybe can be removed
|
|
81
|
-
models_1.CustomFieldValue.belongsTo(model, { foreignKey: 'modelId', as: modelName });
|
|
82
|
-
};
|
|
83
|
-
const addScopes = (models, getModel, options = { useCustomFieldsEntries: false }) => {
|
|
84
|
-
models.forEach(async ({ name, scopeAttributes }) => {
|
|
85
|
-
try {
|
|
86
|
-
const model = getModel(name);
|
|
87
|
-
if (!model) {
|
|
88
|
-
logger_1.default.warn('sadot - tried to addScopes to a model that does not exist yet', {
|
|
89
|
-
name,
|
|
90
|
-
scopeAttributes,
|
|
91
|
-
});
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
// Necessary associations for the filtering scope
|
|
95
|
-
addAssociations(model, name, options);
|
|
96
|
-
// Add filter scope
|
|
97
|
-
model.addScope(CUSTOM_FIELDS_FILTER_SCOPE, (0, scopes_1.customFieldsFilterScope)(name, options));
|
|
98
|
-
model.addScope(custom_fields_1.CUSTOM_FIELDS_SORT_SCOPE, (0, filter_1.customFieldsSortScope)(name, options));
|
|
99
|
-
}
|
|
100
|
-
catch (e) {
|
|
101
|
-
logger_1.default.error(`Could not add custom fields scopes to model ${name}. `, e);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
};
|
|
105
|
-
exports.addScopes = addScopes;
|
|
106
|
-
const applyCustomAssociation = (models) => {
|
|
107
|
-
models.forEach(({ modelOptions }) => {
|
|
108
|
-
modelOptions?.customAssociation?.(models_1.CustomFieldDefinition);
|
|
109
|
-
modelOptions?.customAssociation?.(models_1.CustomValidator);
|
|
110
|
-
});
|
|
111
|
-
};
|
|
112
|
-
exports.applyCustomAssociation = applyCustomAssociation;
|
|
1
|
+
import e from"./logger/index.js";import t from"../models/CustomFieldDefinition.js";import n from"../models/CustomFieldValue.js";import r from"../models/CustomValidator.js";import"../models/index.js";import i from"../hooks/enrich.js";import{beforeFind as a}from"../hooks/find.js";import{beforeBulkCreate as o,beforeBulkUpdate as s,beforeCreate as c,beforeUpdate as l}from"../hooks/hooks.js";import"../hooks/index.js";import{customFieldsFilterScope as u,customFieldsSortScope as d}from"../scopes/filter.js";import"../scopes/index.js";import{DataTypes as f}from"sequelize";import{customFields as p}from"@autofleet/common-types";import{CUSTOM_FIELDS_SORT_SCOPE as m}from"@autofleet/common-types/lib/custom-fields";const{CUSTOM_FIELDS_FILTER_SCOPE:h}=p,g=(t,n,r={useCustomFieldsEntries:!1})=>{t.forEach(async({name:t,scopeAttributes:u,modelOptions:d})=>{try{let p=n(t);if(!p){e.warn(`sadot - tried to addHooks to a model that does not exist yet`,{name:t,scopeAttributes:u});return}p.rawAttributes.customFields={type:f.VIRTUAL},p.refreshAttributes(),p.addHook(`beforeFind`,`sadot-beforeFind`,a(u)),p.addHook(`beforeBulkCreate`,`sadot-beforeBulkCreate`,o),p.addHook(`beforeBulkUpdate`,`sadot-beforeBulkUpdate`,s),p.addHook(`beforeCreate`,`sadot-beforeCreate`,c(u,d,r)),p.addHook(`beforeUpdate`,`sadot-beforeUpdate`,l(u,d,r)),p.addHook(`afterFind`,`sadot-afterFind`,i(t,u,`afterFind`,d,r)),p.addHook(`afterUpdate`,`sadot-afterUpdate`,i(t,u,void 0,d,r)),p.addHook(`afterCreate`,`sadot-afterCreate`,i(t,u,void 0,d,r))}catch(n){e.error(`Could not add custom fields hook to model ${t}. `,n)}})},_=(t,n)=>{t.forEach(async({name:t})=>{try{let e=n(t);if(!e)return;e.rawAttributes.customFields&&(delete e.rawAttributes.customFields,e.refreshAttributes()),e.removeHook(`beforeFind`,`sadot-beforeFind`),e.removeHook(`beforeBulkCreate`,`sadot-beforeBulkCreate`),e.removeHook(`beforeBulkUpdate`,`sadot-beforeBulkUpdate`),e.removeHook(`beforeCreate`,`sadot-beforeCreate`),e.removeHook(`beforeUpdate`,`sadot-beforeUpdate`),e.removeHook(`afterFind`,`sadot-afterFind`),e.removeHook(`afterUpdate`,`sadot-afterUpdate`)}catch(n){e.error(`Could not add custom fields hook to model ${t}. `,n)}})},v=(e,t,r)=>{r?.useCustomFieldsEntries||(e.hasMany(n,{foreignKey:`modelId`,as:`customFieldValue`}),n.belongsTo(e,{foreignKey:`modelId`,as:t}))},y=(t,n,r={useCustomFieldsEntries:!1})=>{t.forEach(async({name:t,scopeAttributes:i})=>{try{let a=n(t);if(!a){e.warn(`sadot - tried to addScopes to a model that does not exist yet`,{name:t,scopeAttributes:i});return}v(a,t,r),a.addScope(h,u(t,r)),a.addScope(m,d(t,r))}catch(n){e.error(`Could not add custom fields scopes to model ${t}. `,n)}})},b=e=>{e.forEach(({modelOptions:e})=>{e?.customAssociation?.(t),e?.customAssociation?.(r)})};export{g as addHooks,y as addScopes,b as applyCustomAssociation,_ as removeHooks};
|
|
2
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","names":["enrichResults","CustomFieldValue","CustomFieldDefinition","CustomValidator"],"sources":["../../src/utils/init.ts"],"sourcesContent":["import { DataTypes } from 'sequelize';\nimport type { ModelCtor } from 'sequelize-typescript';\nimport { customFields } from '@autofleet/common-types';\nimport { CUSTOM_FIELDS_SORT_SCOPE } from '@autofleet/common-types/lib/custom-fields';\nimport {\n CustomFieldDefinition,\n CustomFieldValue,\n CustomValidator,\n} from '../models';\nimport {\n beforeFind,\n enrichResults,\n beforeBulkUpdate,\n beforeUpdate,\n beforeCreate,\n beforeBulkCreate,\n} from '../hooks';\nimport { customFieldsFilterScope } from '../scopes';\nimport logger from './logger';\nimport type { CustomFieldOptions, ModelFetcher, Models } from '../types';\nimport { customFieldsSortScope } from '../scopes/filter';\n\nconst { CUSTOM_FIELDS_FILTER_SCOPE } = customFields;\n\nexport const addHooks = (\n models: Models[],\n getModel: ModelFetcher,\n sadotOptions: { useCustomFieldsEntries?: boolean; } = { useCustomFieldsEntries: false },\n): void => {\n models.forEach(async ({\n name, scopeAttributes, modelOptions,\n }) => {\n try {\n const model = getModel(name);\n if (!model) {\n logger.warn('sadot - tried to addHooks to a model that does not exist yet', {\n name,\n scopeAttributes,\n });\n return;\n }\n model.rawAttributes.customFields = {\n type: DataTypes.VIRTUAL,\n };\n model.refreshAttributes();\n // TODO: Uncomment after tests are passed\n // model.addHook('afterFind', workaround);\n model.addHook('beforeFind', 'sadot-beforeFind', beforeFind(scopeAttributes));\n model.addHook('beforeBulkCreate', 'sadot-beforeBulkCreate', beforeBulkCreate);\n model.addHook('beforeBulkUpdate', 'sadot-beforeBulkUpdate', beforeBulkUpdate);\n model.addHook('beforeCreate', 'sadot-beforeCreate', beforeCreate(scopeAttributes, modelOptions, sadotOptions));\n model.addHook('beforeUpdate', 'sadot-beforeUpdate', beforeUpdate(scopeAttributes, modelOptions, sadotOptions));\n model.addHook('afterFind', 'sadot-afterFind', enrichResults(name, scopeAttributes, 'afterFind', modelOptions, sadotOptions));\n model.addHook('afterUpdate', 'sadot-afterUpdate', enrichResults(name, scopeAttributes, undefined, modelOptions, sadotOptions));\n model.addHook('afterCreate', 'sadot-afterCreate', enrichResults(name, scopeAttributes, undefined, modelOptions, sadotOptions));\n } catch (e) {\n logger.error(`Could not add custom fields hook to model ${name}. `, e);\n }\n });\n};\n\nexport const removeHooks = (models: Models[], getModel: ModelFetcher): void => {\n models.forEach(async ({ name }) => {\n try {\n const model = getModel(name);\n if (!model) return;\n if (model.rawAttributes.customFields) {\n delete model.rawAttributes.customFields;\n model.refreshAttributes();\n }\n // model.removeHook('afterFind', 'sadot-workaround');\n model.removeHook('beforeFind', 'sadot-beforeFind');\n model.removeHook('beforeBulkCreate', 'sadot-beforeBulkCreate');\n model.removeHook('beforeBulkUpdate', 'sadot-beforeBulkUpdate');\n model.removeHook('beforeCreate', 'sadot-beforeCreate');\n model.removeHook('beforeUpdate', 'sadot-beforeUpdate');\n model.removeHook('afterFind', 'sadot-afterFind');\n model.removeHook('afterUpdate', 'sadot-afterUpdate');\n } catch (e) {\n logger.error(`Could not add custom fields hook to model ${name}. `, e);\n }\n });\n};\n\n/**\n * Necessary associations for the {@link customFieldsFilterScope} scope\n */\nconst addAssociations = (model: ModelCtor, modelName: string, options: Pick<CustomFieldOptions, 'useCustomFieldsEntries'>): void => {\n if (options?.useCustomFieldsEntries) return;\n model.hasMany(CustomFieldValue, { foreignKey: 'modelId', as: 'customFieldValue' });\n // TBC: maybe can be removed\n CustomFieldValue.belongsTo(model, { foreignKey: 'modelId', as: modelName });\n};\n\nexport const addScopes = (models: Models[], getModel: ModelFetcher, options: Pick<CustomFieldOptions, 'useCustomFieldsEntries'> = { useCustomFieldsEntries: false }): void => {\n models.forEach(async ({ name, scopeAttributes }) => {\n try {\n const model = getModel(name);\n if (!model) {\n logger.warn('sadot - tried to addScopes to a model that does not exist yet', {\n name,\n scopeAttributes,\n });\n return;\n }\n // Necessary associations for the filtering scope\n addAssociations(model, name, options);\n // Add filter scope\n model.addScope(CUSTOM_FIELDS_FILTER_SCOPE, customFieldsFilterScope(name, options));\n model.addScope(CUSTOM_FIELDS_SORT_SCOPE, customFieldsSortScope(name, options));\n } catch (e) {\n logger.error(`Could not add custom fields scopes to model ${name}. `, e);\n }\n });\n};\n\nexport const applyCustomAssociation = (models: Models[]): void => {\n models.forEach(({ modelOptions }) => {\n modelOptions?.customAssociation?.(CustomFieldDefinition);\n modelOptions?.customAssociation?.(CustomValidator);\n });\n};\n"],"mappings":"ssBAsBA,KAAM,CAAE,8BAA+B,EAE1B,GACX,EACA,EACA,EAAsD,CAAE,uBAAwB,GAAO,GAC9E,CACT,EAAO,QAAQ,MAAO,CACpB,OAAM,kBAAiB,kBACnB,CACJ,GAAI,CACF,IAAM,EAAQ,EAAS,EAAK,CAC5B,GAAI,CAAC,EAAO,CACV,EAAO,KAAK,+DAAgE,CAC1E,OACA,kBACD,CAAC,CACF,OAEF,EAAM,cAAc,aAAe,CACjC,KAAM,EAAU,QACjB,CACD,EAAM,mBAAmB,CAGzB,EAAM,QAAQ,aAAc,mBAAoB,EAAW,EAAgB,CAAC,CAC5E,EAAM,QAAQ,mBAAoB,yBAA0B,EAAiB,CAC7E,EAAM,QAAQ,mBAAoB,yBAA0B,EAAiB,CAC7E,EAAM,QAAQ,eAAgB,qBAAsB,EAAa,EAAiB,EAAc,EAAa,CAAC,CAC9G,EAAM,QAAQ,eAAgB,qBAAsB,EAAa,EAAiB,EAAc,EAAa,CAAC,CAC9G,EAAM,QAAQ,YAAa,kBAAmBA,EAAc,EAAM,EAAiB,YAAa,EAAc,EAAa,CAAC,CAC5H,EAAM,QAAQ,cAAe,oBAAqBA,EAAc,EAAM,EAAiB,IAAA,GAAW,EAAc,EAAa,CAAC,CAC9H,EAAM,QAAQ,cAAe,oBAAqBA,EAAc,EAAM,EAAiB,IAAA,GAAW,EAAc,EAAa,CAAC,OACvH,EAAG,CACV,EAAO,MAAM,6CAA6C,EAAK,IAAK,EAAE,GAExE,EAGS,GAAe,EAAkB,IAAiC,CAC7E,EAAO,QAAQ,MAAO,CAAE,UAAW,CACjC,GAAI,CACF,IAAM,EAAQ,EAAS,EAAK,CAC5B,GAAI,CAAC,EAAO,OACR,EAAM,cAAc,eACtB,OAAO,EAAM,cAAc,aAC3B,EAAM,mBAAmB,EAG3B,EAAM,WAAW,aAAc,mBAAmB,CAClD,EAAM,WAAW,mBAAoB,yBAAyB,CAC9D,EAAM,WAAW,mBAAoB,yBAAyB,CAC9D,EAAM,WAAW,eAAgB,qBAAqB,CACtD,EAAM,WAAW,eAAgB,qBAAqB,CACtD,EAAM,WAAW,YAAa,kBAAkB,CAChD,EAAM,WAAW,cAAe,oBAAoB,OAC7C,EAAG,CACV,EAAO,MAAM,6CAA6C,EAAK,IAAK,EAAE,GAExE,EAME,GAAmB,EAAkB,EAAmB,IAAsE,CAC9H,GAAS,yBACb,EAAM,QAAQC,EAAkB,CAAE,WAAY,UAAW,GAAI,mBAAoB,CAAC,CAElF,EAAiB,UAAU,EAAO,CAAE,WAAY,UAAW,GAAI,EAAW,CAAC,GAGhE,GAAa,EAAkB,EAAwB,EAA8D,CAAE,uBAAwB,GAAO,GAAW,CAC5K,EAAO,QAAQ,MAAO,CAAE,OAAM,qBAAsB,CAClD,GAAI,CACF,IAAM,EAAQ,EAAS,EAAK,CAC5B,GAAI,CAAC,EAAO,CACV,EAAO,KAAK,gEAAiE,CAC3E,OACA,kBACD,CAAC,CACF,OAGF,EAAgB,EAAO,EAAM,EAAQ,CAErC,EAAM,SAAS,EAA4B,EAAwB,EAAM,EAAQ,CAAC,CAClF,EAAM,SAAS,EAA0B,EAAsB,EAAM,EAAQ,CAAC,OACvE,EAAG,CACV,EAAO,MAAM,+CAA+C,EAAK,IAAK,EAAE,GAE1E,EAGS,EAA0B,GAA2B,CAChE,EAAO,SAAS,CAAE,kBAAmB,CACnC,GAAc,oBAAoBC,EAAsB,CACxD,GAAc,oBAAoBC,EAAgB,EAClD"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`../../_virtual/rolldown_runtime.cjs`);let t=require(`@autofleet/zehut`),n=require(`@autofleet/logger`);n=e.__toESM(n);const r=(0,n.default)();function i(){r.addContextMiddleware(()=>({traceId:t.outbreak.getCurrentContextTraceId()}))}var a=r;exports.default=a,exports.tryAddingTraceIdMiddleware=i;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|