@autofleet/sadot 1.0.10 → 1.0.11

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.
Files changed (192) hide show
  1. package/dist/_virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.cjs +1 -0
  2. package/dist/_virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.js +1 -0
  3. package/dist/_virtual/_@oxc-project_runtime@0.89.0/helpers/decorateMetadata.cjs +1 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.89.0/helpers/decorateMetadata.js +1 -0
  5. package/dist/_virtual/rolldown_runtime.cjs +1 -0
  6. package/dist/api/index.cjs +2 -0
  7. package/dist/api/index.cjs.map +1 -0
  8. package/dist/api/index.js +2 -0
  9. package/dist/api/index.js.map +1 -0
  10. package/dist/api/v1/definition/index.cjs +2 -0
  11. package/dist/api/v1/definition/index.cjs.map +1 -0
  12. package/dist/api/v1/definition/index.js +2 -0
  13. package/dist/api/v1/definition/index.js.map +1 -0
  14. package/dist/api/v1/definition/validations.cjs +2 -0
  15. package/dist/api/v1/definition/validations.cjs.map +1 -0
  16. package/dist/api/v1/definition/validations.js +2 -0
  17. package/dist/api/v1/definition/validations.js.map +1 -0
  18. package/dist/api/v1/errors.cjs +2 -0
  19. package/dist/api/v1/errors.cjs.map +1 -0
  20. package/dist/api/v1/errors.js +2 -0
  21. package/dist/api/v1/errors.js.map +1 -0
  22. package/dist/api/v1/index.cjs +2 -0
  23. package/dist/api/v1/index.cjs.map +1 -0
  24. package/dist/api/v1/index.js +2 -0
  25. package/dist/api/v1/index.js.map +1 -0
  26. package/dist/api/v1/validator/index.cjs +2 -0
  27. package/dist/api/v1/validator/index.cjs.map +1 -0
  28. package/dist/api/v1/validator/index.js +2 -0
  29. package/dist/api/v1/validator/index.js.map +1 -0
  30. package/dist/api/v1/validator/validations.cjs +2 -0
  31. package/dist/api/v1/validator/validations.cjs.map +1 -0
  32. package/dist/api/v1/validator/validations.js +2 -0
  33. package/dist/api/v1/validator/validations.js.map +1 -0
  34. package/dist/errors/index.cjs +3 -0
  35. package/dist/errors/index.cjs.map +1 -0
  36. package/dist/errors/index.js +3 -0
  37. package/dist/errors/index.js.map +1 -0
  38. package/dist/events/index.cjs +2 -0
  39. package/dist/events/index.cjs.map +1 -0
  40. package/dist/events/index.js +2 -0
  41. package/dist/events/index.js.map +1 -0
  42. package/dist/hooks/enrich.cjs +2 -0
  43. package/dist/hooks/enrich.cjs.map +1 -0
  44. package/dist/hooks/enrich.js +2 -0
  45. package/dist/hooks/enrich.js.map +1 -0
  46. package/dist/hooks/find.cjs +2 -0
  47. package/dist/hooks/find.cjs.map +1 -0
  48. package/dist/hooks/find.js +2 -0
  49. package/dist/hooks/find.js.map +1 -0
  50. package/dist/hooks/hooks.cjs +2 -0
  51. package/dist/hooks/hooks.cjs.map +1 -0
  52. package/dist/hooks/hooks.js +2 -0
  53. package/dist/hooks/hooks.js.map +1 -0
  54. package/dist/hooks/index.cjs +1 -0
  55. package/dist/hooks/index.js +1 -0
  56. package/dist/hooks/utils/updateInstanceValues.cjs +2 -0
  57. package/dist/hooks/utils/updateInstanceValues.cjs.map +1 -0
  58. package/dist/hooks/utils/updateInstanceValues.js +2 -0
  59. package/dist/hooks/utils/updateInstanceValues.js.map +1 -0
  60. package/dist/index.cjs +1 -46
  61. package/dist/index.cjs.map +1 -1
  62. package/dist/index.d.cts +8 -255
  63. package/dist/index.d.ts +8 -255
  64. package/dist/index.js +1 -46
  65. package/dist/index.js.map +1 -1
  66. package/dist/models/CustomFieldDefinition.cjs +2 -0
  67. package/dist/models/CustomFieldDefinition.cjs.map +1 -0
  68. package/dist/models/CustomFieldDefinition.js +2 -0
  69. package/dist/models/CustomFieldDefinition.js.map +1 -0
  70. package/dist/models/CustomFieldEntries.cjs +2 -0
  71. package/dist/models/CustomFieldEntries.cjs.map +1 -0
  72. package/dist/models/CustomFieldEntries.js +2 -0
  73. package/dist/models/CustomFieldEntries.js.map +1 -0
  74. package/dist/models/CustomFieldValue.cjs +2 -0
  75. package/dist/models/CustomFieldValue.cjs.map +1 -0
  76. package/dist/models/CustomFieldValue.js +2 -0
  77. package/dist/models/CustomFieldValue.js.map +1 -0
  78. package/dist/models/CustomValidator.cjs +2 -0
  79. package/dist/models/CustomValidator.cjs.map +1 -0
  80. package/dist/models/CustomValidator.js +2 -0
  81. package/dist/models/CustomValidator.js.map +1 -0
  82. package/dist/models/index.cjs +2 -0
  83. package/dist/models/index.cjs.map +1 -0
  84. package/dist/models/index.js +2 -0
  85. package/dist/models/index.js.map +1 -0
  86. package/dist/models/tests/AssociatedTestModel.cjs +2 -0
  87. package/dist/models/tests/AssociatedTestModel.cjs.map +1 -0
  88. package/dist/models/tests/AssociatedTestModel.js +2 -0
  89. package/dist/models/tests/AssociatedTestModel.js.map +1 -0
  90. package/dist/models/tests/TestModel.cjs +2 -0
  91. package/dist/models/tests/TestModel.cjs.map +1 -0
  92. package/dist/models/tests/TestModel.js +2 -0
  93. package/dist/models/tests/TestModel.js.map +1 -0
  94. package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs +2 -0
  95. package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs.map +1 -0
  96. package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js +2 -0
  97. package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js.map +1 -0
  98. package/dist/models/tests/contextAwareModels/ContextTestModel.cjs +2 -0
  99. package/dist/models/tests/contextAwareModels/ContextTestModel.cjs.map +1 -0
  100. package/dist/models/tests/contextAwareModels/ContextTestModel.js +2 -0
  101. package/dist/models/tests/contextAwareModels/ContextTestModel.js.map +1 -0
  102. package/dist/repository/definition.cjs +2 -0
  103. package/dist/repository/definition.cjs.map +1 -0
  104. package/dist/repository/definition.js +2 -0
  105. package/dist/repository/definition.js.map +1 -0
  106. package/dist/repository/entries.cjs +2 -0
  107. package/dist/repository/entries.cjs.map +1 -0
  108. package/dist/repository/entries.js +2 -0
  109. package/dist/repository/entries.js.map +1 -0
  110. package/dist/repository/utils/formatValues.cjs +2 -0
  111. package/dist/repository/utils/formatValues.cjs.map +1 -0
  112. package/dist/repository/utils/formatValues.js +2 -0
  113. package/dist/repository/utils/formatValues.js.map +1 -0
  114. package/dist/repository/validator.cjs +2 -0
  115. package/dist/repository/validator.cjs.map +1 -0
  116. package/dist/repository/validator.js +2 -0
  117. package/dist/repository/validator.js.map +1 -0
  118. package/dist/repository/value.cjs +2 -0
  119. package/dist/repository/value.cjs.map +1 -0
  120. package/dist/repository/value.js +2 -0
  121. package/dist/repository/value.js.map +1 -0
  122. package/dist/scopes/filter.cjs +2 -0
  123. package/dist/scopes/filter.cjs.map +1 -0
  124. package/dist/scopes/filter.d.cts +23 -0
  125. package/dist/scopes/filter.d.ts +23 -0
  126. package/dist/scopes/filter.js +2 -0
  127. package/dist/scopes/filter.js.map +1 -0
  128. package/dist/scopes/helpers/filter.helpers.cjs +46 -0
  129. package/dist/scopes/helpers/filter.helpers.cjs.map +1 -0
  130. package/dist/scopes/helpers/filter.helpers.d.cts +17 -0
  131. package/dist/scopes/helpers/filter.helpers.d.ts +17 -0
  132. package/dist/scopes/helpers/filter.helpers.js +46 -0
  133. package/dist/scopes/helpers/filter.helpers.js.map +1 -0
  134. package/dist/scopes/index.cjs +1 -0
  135. package/dist/scopes/index.js +1 -0
  136. package/dist/types/index.d.cts +44 -0
  137. package/dist/types/index.d.ts +44 -0
  138. package/dist/utils/constants/index.cjs +2 -0
  139. package/dist/utils/constants/index.cjs.map +1 -0
  140. package/dist/utils/constants/index.d.cts +22 -0
  141. package/dist/utils/constants/index.d.ts +22 -0
  142. package/dist/utils/constants/index.js +2 -0
  143. package/dist/utils/constants/index.js.map +1 -0
  144. package/dist/utils/db/index.cjs +2 -0
  145. package/dist/utils/db/index.cjs.map +1 -0
  146. package/dist/utils/db/index.js +2 -0
  147. package/dist/utils/db/index.js.map +1 -0
  148. package/dist/utils/helpers/index.cjs +2 -0
  149. package/dist/utils/helpers/index.cjs.map +1 -0
  150. package/dist/utils/helpers/index.d.cts +31 -0
  151. package/dist/utils/helpers/index.d.ts +31 -0
  152. package/dist/utils/helpers/index.js +2 -0
  153. package/dist/utils/helpers/index.js.map +1 -0
  154. package/dist/utils/init.cjs +2 -0
  155. package/dist/utils/init.cjs.map +1 -0
  156. package/dist/utils/init.js +2 -0
  157. package/dist/utils/init.js.map +1 -0
  158. package/dist/utils/logger/index.cjs +2 -0
  159. package/dist/utils/logger/index.cjs.map +1 -0
  160. package/dist/utils/logger/index.js +2 -0
  161. package/dist/utils/logger/index.js.map +1 -0
  162. package/dist/utils/scopeAttributes.cjs +2 -0
  163. package/dist/utils/scopeAttributes.cjs.map +1 -0
  164. package/dist/utils/scopeAttributes.js +2 -0
  165. package/dist/utils/scopeAttributes.js.map +1 -0
  166. package/dist/utils/validations/index.cjs +2 -0
  167. package/dist/utils/validations/index.cjs.map +1 -0
  168. package/dist/utils/validations/index.js +2 -0
  169. package/dist/utils/validations/index.js.map +1 -0
  170. package/dist/utils/validations/schema/custom-fields.cjs +2 -0
  171. package/dist/utils/validations/schema/custom-fields.cjs.map +1 -0
  172. package/dist/utils/validations/schema/custom-fields.d.cts +7 -0
  173. package/dist/utils/validations/schema/custom-fields.d.ts +7 -0
  174. package/dist/utils/validations/schema/custom-fields.js +2 -0
  175. package/dist/utils/validations/schema/custom-fields.js.map +1 -0
  176. package/dist/utils/validations/schema/validator-schema.cjs +2 -0
  177. package/dist/utils/validations/schema/validator-schema.cjs.map +1 -0
  178. package/dist/utils/validations/schema/validator-schema.js +2 -0
  179. package/dist/utils/validations/schema/validator-schema.js.map +1 -0
  180. package/dist/utils/validations/validators/index.cjs +2 -0
  181. package/dist/utils/validations/validators/index.cjs.map +1 -0
  182. package/dist/utils/validations/validators/index.js +2 -0
  183. package/dist/utils/validations/validators/index.js.map +1 -0
  184. package/dist/utils/validations/validators/select.validator.cjs +2 -0
  185. package/dist/utils/validations/validators/select.validator.cjs.map +1 -0
  186. package/dist/utils/validations/validators/select.validator.js +2 -0
  187. package/dist/utils/validations/validators/select.validator.js.map +1 -0
  188. package/dist/utils/validations/validators/status.validator.cjs +2 -0
  189. package/dist/utils/validations/validators/status.validator.cjs.map +1 -0
  190. package/dist/utils/validations/validators/status.validator.js +2 -0
  191. package/dist/utils/validations/validators/status.validator.js.map +1 -0
  192. package/package.json +1 -1
package/dist/index.d.cts CHANGED
@@ -1,260 +1,13 @@
1
+ import { CUSTOM_FIELDS_FILTER_SCOPE, CustomFieldDefinitionType, supportedEntities } from "./utils/constants/index.cjs";
2
+ import { CustomFieldOptions, ModelFetcher, Models } from "./types/index.cjs";
3
+ import { CustomFieldsSchema } from "./utils/validations/schema/custom-fields.cjs";
4
+ import { generateCustomFieldSearchQueryPayload, generateRandomString } from "./utils/helpers/index.cjs";
5
+ import { customFieldsSortScope } from "./scopes/filter.cjs";
1
6
  import { Application } from "express";
2
- import { Model, ModelCtor, ModelStatic, Sequelize } from "sequelize-typescript";
3
- import { BindOrReplacements, CreateOptions, IncludeOptions, WhereOptions } from "sequelize";
4
- import { getUser } from "@autofleet/zehut";
5
- import { customFields } from "@autofleet/common-types";
6
- import Joi from "joi";
7
- import { Literal } from "sequelize/types/utils";
7
+ import { Sequelize } from "sequelize-typescript";
8
8
 
9
- //#region src/utils/constants/index.d.ts
10
- declare const supportedEntities: readonly ["businessModelId", "fleetId", "demandSourceId"];
11
- /**
12
- * Supported custom field types
13
- */
14
- declare enum CustomFieldDefinitionType {
15
- NUMBER = "number",
16
- BOOLEAN = "boolean",
17
- DATE = "date",
18
- DATETIME = "datetime",
19
- TEXT = "text",
20
- IMAGE = "image",
21
- SELECT = "select",
22
- STATUS = "status",
23
- FILE = "file",
24
- }
25
- declare const CUSTOM_FIELDS_FILTER_SCOPE: typeof customFields.CUSTOM_FIELDS_FILTER_SCOPE;
26
- //#endregion
27
- //#region src/models/CustomFieldValue.d.ts
28
- declare class CustomFieldValue extends Model {
29
- modelId: string;
30
- customFieldDefinitionId: string;
31
- value: any;
32
- createdAt?: Date;
33
- updatedAt?: Date;
34
- deletedAt?: Date;
35
- customFieldDefinition: CustomFieldDefinition;
36
- private static validateValueAgainstDefinition;
37
- static validateCustomFieldValues(instances: CustomFieldValue[]): Promise<void>;
38
- static validateCustomFieldValue(instance: CustomFieldValue): Promise<void>;
39
- static afterSaveHandler(instance: CustomFieldValue, options: CreateOptions): void;
40
- }
41
- //#endregion
42
- //#region src/models/tests/AssociatedTestModel.d.ts
43
- declare class AssociatedTestModel extends Model {
44
- id: string;
45
- testModelId: string;
46
- fleetId: string;
47
- businessModelId: string;
48
- demandSourceId: string;
49
- anotherAttribute?: boolean;
50
- testModel: TestModel;
51
- }
52
- //#endregion
53
- //#region src/models/tests/TestModel.d.ts
54
- declare class TestModel extends Model {
55
- id: string;
56
- fleetId: string;
57
- businessModelId: string;
58
- demandSourceId: string;
59
- coolAttribute?: boolean;
60
- associatedModels: AssociatedTestModel[];
61
- customFields?: any;
62
- }
63
- //#endregion
64
- //#region src/models/tests/contextAwareModels/ContextTestModel.d.ts
65
- declare enum EEntityTypes {
66
- BUSINESS_MODEL = "businessModel",
67
- CONTEXT = "context",
68
- DEMAND_SOURCE = "demandSource",
69
- FLEET = "fleet",
70
- }
71
- declare class ContextTestModel extends Model {
72
- id: string;
73
- entityId: string;
74
- entityType: EEntityTypes;
75
- }
76
- //#endregion
77
- //#region src/models/tests/contextAwareModels/ContextAwareTestModel.d.ts
78
- declare class ContextAwareTestModel extends Model {
79
- id: string;
80
- contextId: string;
81
- coolAttribute?: boolean;
82
- customFields?: any;
83
- context: ContextTestModel;
84
- }
85
- //#endregion
86
- //#region src/models/CustomFieldEntries.d.ts
87
- declare class CustomFieldEntries extends Model {
88
- modelId: string;
89
- entityId: string;
90
- customFields: Record<string, any>;
91
- modelType: string;
92
- createdAt?: Date;
93
- updatedAt?: Date;
94
- static afterSaveHandler(instance: CustomFieldEntries, options: CreateOptions): void;
95
- }
96
- //#endregion
97
- //#region src/api/v1/validator/validations.d.ts
98
- interface SchemaObject {
99
- type: "object";
100
- properties?: {
101
- before?: object;
102
- after?: object;
103
- };
104
- required?: string[];
105
- allOf?: object[];
106
- anyOf?: object[];
107
- oneOf?: object[];
108
- additionalProperties?: boolean | object;
109
- $id?: string;
110
- $schema?: string;
111
- if?: object;
112
- then?: object;
113
- else?: object;
114
- }
115
- //#endregion
116
- //#region src/models/CustomValidator.d.ts
117
- declare class CustomValidator extends Model {
118
- id: string;
119
- entityId: string;
120
- entityType: string;
121
- modelType: string;
122
- schema: SchemaObject;
123
- disabled: boolean;
124
- createdAt?: Date;
125
- updatedAt?: Date;
126
- static afterSaveHandler(instance: CustomValidator, options: CreateOptions): void;
127
- }
128
- //#endregion
129
- //#region src/models/index.d.ts
130
- interface InitTablesOptions {
131
- schemaPrefix?: string;
132
- schemaVersion?: string;
133
- useCustomFieldsEntries?: boolean;
134
- }
135
- declare const initTables: (sequelize: Sequelize, getUser: CustomFieldOptions["getUser"], {
136
- schemaPrefix,
137
- schemaVersion,
138
- useCustomFieldsEntries
139
- }?: InitTablesOptions) => Promise<void>;
140
- declare const initTestModels: (sequelize: Sequelize) => Promise<void>;
141
- //#endregion
142
- //#region src/models/CustomFieldDefinition.d.ts
143
- declare class CustomFieldDefinition extends Model {
144
- id: string;
145
- name: string;
146
- displayName?: string;
147
- fieldType: CustomFieldDefinitionType;
148
- validation?: any;
149
- entityId: string;
150
- entityType: string;
151
- modelType: string;
152
- description?: string;
153
- required?: boolean;
154
- disabled?: boolean;
155
- defaultValue?: any;
156
- createdAt?: Date;
157
- updatedAt?: Date;
158
- deletedAt?: Date;
159
- blockEditingFromUI: boolean;
160
- values: CustomFieldValue[];
161
- static displayNameDefaultValue(instance: CustomFieldDefinition): void;
162
- static afterSaveHandler(instance: CustomFieldDefinition, options: CreateOptions): void;
163
- }
164
- //#endregion
165
- //#region src/types/index.d.ts
166
- type ModelFetcher = (name: string) => any;
167
- type ModelOptions = {
168
- /**
169
- * Include options for the model
170
- */
171
- include?: (entityIds: string | string[]) => IncludeOptions[];
172
- /**
173
- * Custom association for the model
174
- * @param model - The model to associate with
175
- */
176
- customAssociation?: (model: ModelCtor) => void;
177
- /**
178
- * Whether to use the entity id from the instance per scope attribute
179
- */
180
- useEntityIdFromInclude?: boolean;
181
- /**
182
- * Which attributes to include in the model
183
- */
184
- attributes?: string[];
185
- };
186
- type Models = {
187
- name: string;
188
- scopeAttributes: any[];
189
- modelOptions?: ModelOptions;
190
- creationWebhookHandler?: (instance: any) => any;
191
- updateWebhookHandler?: (instance: any) => any;
192
- deletionWebhookHandler?: (instance: any) => any;
193
- };
194
- type CustomFieldOptions = {
195
- models: Models[];
196
- databaseConfig: any;
197
- getUser: typeof getUser;
198
- sequelize?: Sequelize;
199
- useCustomFieldsEntries?: boolean;
200
- useValidators?: boolean;
201
- };
202
- //#endregion
203
- //#region src/utils/validations/schema/custom-fields.d.ts
204
- declare const CustomFieldsSchema: Joi.ObjectSchema<Record<string, any>>;
205
- //#endregion
206
- //#region src/utils/helpers/index.d.ts
207
- /**
208
- * Builds a WHERE clause and replacements for free-text search by custom fields.
209
- *
210
- * This function constructs a WHERE clause and replacement bindings that allow searching
211
- * for a given term within custom fields associated with a specific model type and entity ID.
212
- * The WHERE clause and replacements are designed to be added to the main query.
213
- *
214
- * @param {string} searchTerm - The term to search for within custom fields.
215
- * @param {ModelStatic} model - The Sequelize model representing the entity type to search for.
216
- * @param {string} entityId - The entity ID to filter the custom fields by.
217
- * @param {CustomFieldDefinitionType[]} excludedCustomFieldsTypes - An array of custom field types
218
- * to exclude from the search
219
- *
220
- * @returns {CustomFieldsSearchPayload} - An object containing the WHERE clause and replacements
221
- * for Sequelize.
222
- */
223
- interface CustomFieldsSearchPayload {
224
- where: WhereOptions;
225
- replacements: BindOrReplacements;
226
- }
227
- declare const generateRandomString: (length?: number) => string;
228
- declare const generateCustomFieldSearchQueryPayload: (searchTerm: string, model: ModelStatic, entityId: string, customFieldsTypesToExclude?: CustomFieldDefinitionType[]) => CustomFieldsSearchPayload;
229
- //#endregion
230
- //#region src/scopes/helpers/filter.helpers.d.ts
231
- /**
232
- * Type representing possible condition values.
233
- * Currently supporting strings and arrays of strings.
234
- * More types to be added (TBA).
235
- */
236
- type ConditionWithOperator = {
237
- operator: string;
238
- value: string;
239
- };
240
- type ConditionValue = ConditionWithOperator | ConditionWithOperator[] | string | string[];
241
- //#endregion
242
- //#region src/scopes/filter.d.ts
243
- declare const customFieldsSortScope: (name: string, options?: Pick<CustomFieldOptions, "useCustomFieldsEntries">) => ({
244
- replacementsMap,
245
- scopeValue: sort
246
- }: {
247
- replacementsMap: Record<string, string>;
248
- scopeValue: Record<string, ConditionValue>;
249
- }) => {
250
- attributes: {
251
- include: (string | Literal)[][];
252
- };
253
- order: Literal[];
254
- replacements: Record<string, string>;
255
- } | Record<string, never>;
256
- //#endregion
257
9
  //#region src/index.d.ts
10
+
258
11
  /**
259
12
  * Adding custom fields enrichment to the models inside the MODELS_FILE_NAME json file
260
13
  * @see {@link 'custom-fields/config'} for configurations
@@ -262,5 +15,5 @@ declare const customFieldsSortScope: (name: string, options?: Pick<CustomFieldOp
262
15
  declare const useCustomFields: (app: Pick<Application, "use"> | null, getModel: ModelFetcher, options: CustomFieldOptions) => Promise<Sequelize>;
263
16
  declare const disableCustomFields: (models: Models[], getModel: ModelFetcher) => void;
264
17
  //#endregion
265
- export { AssociatedTestModel, CUSTOM_FIELDS_FILTER_SCOPE, ContextAwareTestModel, ContextTestModel, CustomFieldDefinition, CustomFieldDefinitionType, CustomFieldEntries, CustomFieldValue, CustomFieldsSchema, CustomValidator, TestModel, customFieldsSortScope, useCustomFields as default, disableCustomFields, generateCustomFieldSearchQueryPayload, generateRandomString, initTables, initTestModels, supportedEntities };
18
+ export { CUSTOM_FIELDS_FILTER_SCOPE, CustomFieldDefinitionType, CustomFieldsSchema, customFieldsSortScope, useCustomFields as default, disableCustomFields, generateCustomFieldSearchQueryPayload, generateRandomString, supportedEntities };
266
19
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -1,260 +1,13 @@
1
- import { BindOrReplacements, CreateOptions, IncludeOptions, WhereOptions } from "sequelize";
2
- import { Model, ModelCtor, ModelStatic, Sequelize } from "sequelize-typescript";
3
- import { customFields } from "@autofleet/common-types";
4
- import Joi from "joi";
5
- import { getUser } from "@autofleet/zehut";
1
+ import { CUSTOM_FIELDS_FILTER_SCOPE, CustomFieldDefinitionType, supportedEntities } from "./utils/constants/index.js";
2
+ import { CustomFieldOptions, ModelFetcher, Models } from "./types/index.js";
3
+ import { CustomFieldsSchema } from "./utils/validations/schema/custom-fields.js";
4
+ import { generateCustomFieldSearchQueryPayload, generateRandomString } from "./utils/helpers/index.js";
5
+ import { customFieldsSortScope } from "./scopes/filter.js";
6
+ import { Sequelize } from "sequelize-typescript";
6
7
  import { Application } from "express";
7
- import { Literal } from "sequelize/types/utils";
8
8
 
9
- //#region src/utils/constants/index.d.ts
10
- declare const supportedEntities: readonly ["businessModelId", "fleetId", "demandSourceId"];
11
- /**
12
- * Supported custom field types
13
- */
14
- declare enum CustomFieldDefinitionType {
15
- NUMBER = "number",
16
- BOOLEAN = "boolean",
17
- DATE = "date",
18
- DATETIME = "datetime",
19
- TEXT = "text",
20
- IMAGE = "image",
21
- SELECT = "select",
22
- STATUS = "status",
23
- FILE = "file",
24
- }
25
- declare const CUSTOM_FIELDS_FILTER_SCOPE: typeof customFields.CUSTOM_FIELDS_FILTER_SCOPE;
26
- //#endregion
27
- //#region src/models/CustomFieldValue.d.ts
28
- declare class CustomFieldValue extends Model {
29
- modelId: string;
30
- customFieldDefinitionId: string;
31
- value: any;
32
- createdAt?: Date;
33
- updatedAt?: Date;
34
- deletedAt?: Date;
35
- customFieldDefinition: CustomFieldDefinition;
36
- private static validateValueAgainstDefinition;
37
- static validateCustomFieldValues(instances: CustomFieldValue[]): Promise<void>;
38
- static validateCustomFieldValue(instance: CustomFieldValue): Promise<void>;
39
- static afterSaveHandler(instance: CustomFieldValue, options: CreateOptions): void;
40
- }
41
- //#endregion
42
- //#region src/models/tests/AssociatedTestModel.d.ts
43
- declare class AssociatedTestModel extends Model {
44
- id: string;
45
- testModelId: string;
46
- fleetId: string;
47
- businessModelId: string;
48
- demandSourceId: string;
49
- anotherAttribute?: boolean;
50
- testModel: TestModel;
51
- }
52
- //#endregion
53
- //#region src/models/tests/TestModel.d.ts
54
- declare class TestModel extends Model {
55
- id: string;
56
- fleetId: string;
57
- businessModelId: string;
58
- demandSourceId: string;
59
- coolAttribute?: boolean;
60
- associatedModels: AssociatedTestModel[];
61
- customFields?: any;
62
- }
63
- //#endregion
64
- //#region src/models/tests/contextAwareModels/ContextTestModel.d.ts
65
- declare enum EEntityTypes {
66
- BUSINESS_MODEL = "businessModel",
67
- CONTEXT = "context",
68
- DEMAND_SOURCE = "demandSource",
69
- FLEET = "fleet",
70
- }
71
- declare class ContextTestModel extends Model {
72
- id: string;
73
- entityId: string;
74
- entityType: EEntityTypes;
75
- }
76
- //#endregion
77
- //#region src/models/tests/contextAwareModels/ContextAwareTestModel.d.ts
78
- declare class ContextAwareTestModel extends Model {
79
- id: string;
80
- contextId: string;
81
- coolAttribute?: boolean;
82
- customFields?: any;
83
- context: ContextTestModel;
84
- }
85
- //#endregion
86
- //#region src/models/CustomFieldEntries.d.ts
87
- declare class CustomFieldEntries extends Model {
88
- modelId: string;
89
- entityId: string;
90
- customFields: Record<string, any>;
91
- modelType: string;
92
- createdAt?: Date;
93
- updatedAt?: Date;
94
- static afterSaveHandler(instance: CustomFieldEntries, options: CreateOptions): void;
95
- }
96
- //#endregion
97
- //#region src/api/v1/validator/validations.d.ts
98
- interface SchemaObject {
99
- type: "object";
100
- properties?: {
101
- before?: object;
102
- after?: object;
103
- };
104
- required?: string[];
105
- allOf?: object[];
106
- anyOf?: object[];
107
- oneOf?: object[];
108
- additionalProperties?: boolean | object;
109
- $id?: string;
110
- $schema?: string;
111
- if?: object;
112
- then?: object;
113
- else?: object;
114
- }
115
- //#endregion
116
- //#region src/models/CustomValidator.d.ts
117
- declare class CustomValidator extends Model {
118
- id: string;
119
- entityId: string;
120
- entityType: string;
121
- modelType: string;
122
- schema: SchemaObject;
123
- disabled: boolean;
124
- createdAt?: Date;
125
- updatedAt?: Date;
126
- static afterSaveHandler(instance: CustomValidator, options: CreateOptions): void;
127
- }
128
- //#endregion
129
- //#region src/models/index.d.ts
130
- interface InitTablesOptions {
131
- schemaPrefix?: string;
132
- schemaVersion?: string;
133
- useCustomFieldsEntries?: boolean;
134
- }
135
- declare const initTables: (sequelize: Sequelize, getUser: CustomFieldOptions["getUser"], {
136
- schemaPrefix,
137
- schemaVersion,
138
- useCustomFieldsEntries
139
- }?: InitTablesOptions) => Promise<void>;
140
- declare const initTestModels: (sequelize: Sequelize) => Promise<void>;
141
- //#endregion
142
- //#region src/models/CustomFieldDefinition.d.ts
143
- declare class CustomFieldDefinition extends Model {
144
- id: string;
145
- name: string;
146
- displayName?: string;
147
- fieldType: CustomFieldDefinitionType;
148
- validation?: any;
149
- entityId: string;
150
- entityType: string;
151
- modelType: string;
152
- description?: string;
153
- required?: boolean;
154
- disabled?: boolean;
155
- defaultValue?: any;
156
- createdAt?: Date;
157
- updatedAt?: Date;
158
- deletedAt?: Date;
159
- blockEditingFromUI: boolean;
160
- values: CustomFieldValue[];
161
- static displayNameDefaultValue(instance: CustomFieldDefinition): void;
162
- static afterSaveHandler(instance: CustomFieldDefinition, options: CreateOptions): void;
163
- }
164
- //#endregion
165
- //#region src/types/index.d.ts
166
- type ModelFetcher = (name: string) => any;
167
- type ModelOptions = {
168
- /**
169
- * Include options for the model
170
- */
171
- include?: (entityIds: string | string[]) => IncludeOptions[];
172
- /**
173
- * Custom association for the model
174
- * @param model - The model to associate with
175
- */
176
- customAssociation?: (model: ModelCtor) => void;
177
- /**
178
- * Whether to use the entity id from the instance per scope attribute
179
- */
180
- useEntityIdFromInclude?: boolean;
181
- /**
182
- * Which attributes to include in the model
183
- */
184
- attributes?: string[];
185
- };
186
- type Models = {
187
- name: string;
188
- scopeAttributes: any[];
189
- modelOptions?: ModelOptions;
190
- creationWebhookHandler?: (instance: any) => any;
191
- updateWebhookHandler?: (instance: any) => any;
192
- deletionWebhookHandler?: (instance: any) => any;
193
- };
194
- type CustomFieldOptions = {
195
- models: Models[];
196
- databaseConfig: any;
197
- getUser: typeof getUser;
198
- sequelize?: Sequelize;
199
- useCustomFieldsEntries?: boolean;
200
- useValidators?: boolean;
201
- };
202
- //#endregion
203
- //#region src/utils/validations/schema/custom-fields.d.ts
204
- declare const CustomFieldsSchema: Joi.ObjectSchema<Record<string, any>>;
205
- //#endregion
206
- //#region src/utils/helpers/index.d.ts
207
- /**
208
- * Builds a WHERE clause and replacements for free-text search by custom fields.
209
- *
210
- * This function constructs a WHERE clause and replacement bindings that allow searching
211
- * for a given term within custom fields associated with a specific model type and entity ID.
212
- * The WHERE clause and replacements are designed to be added to the main query.
213
- *
214
- * @param {string} searchTerm - The term to search for within custom fields.
215
- * @param {ModelStatic} model - The Sequelize model representing the entity type to search for.
216
- * @param {string} entityId - The entity ID to filter the custom fields by.
217
- * @param {CustomFieldDefinitionType[]} excludedCustomFieldsTypes - An array of custom field types
218
- * to exclude from the search
219
- *
220
- * @returns {CustomFieldsSearchPayload} - An object containing the WHERE clause and replacements
221
- * for Sequelize.
222
- */
223
- interface CustomFieldsSearchPayload {
224
- where: WhereOptions;
225
- replacements: BindOrReplacements;
226
- }
227
- declare const generateRandomString: (length?: number) => string;
228
- declare const generateCustomFieldSearchQueryPayload: (searchTerm: string, model: ModelStatic, entityId: string, customFieldsTypesToExclude?: CustomFieldDefinitionType[]) => CustomFieldsSearchPayload;
229
- //#endregion
230
- //#region src/scopes/helpers/filter.helpers.d.ts
231
- /**
232
- * Type representing possible condition values.
233
- * Currently supporting strings and arrays of strings.
234
- * More types to be added (TBA).
235
- */
236
- type ConditionWithOperator = {
237
- operator: string;
238
- value: string;
239
- };
240
- type ConditionValue = ConditionWithOperator | ConditionWithOperator[] | string | string[];
241
- //#endregion
242
- //#region src/scopes/filter.d.ts
243
- declare const customFieldsSortScope: (name: string, options?: Pick<CustomFieldOptions, "useCustomFieldsEntries">) => ({
244
- replacementsMap,
245
- scopeValue: sort
246
- }: {
247
- replacementsMap: Record<string, string>;
248
- scopeValue: Record<string, ConditionValue>;
249
- }) => {
250
- attributes: {
251
- include: (string | Literal)[][];
252
- };
253
- order: Literal[];
254
- replacements: Record<string, string>;
255
- } | Record<string, never>;
256
- //#endregion
257
9
  //#region src/index.d.ts
10
+
258
11
  /**
259
12
  * Adding custom fields enrichment to the models inside the MODELS_FILE_NAME json file
260
13
  * @see {@link 'custom-fields/config'} for configurations
@@ -262,5 +15,5 @@ declare const customFieldsSortScope: (name: string, options?: Pick<CustomFieldOp
262
15
  declare const useCustomFields: (app: Pick<Application, "use"> | null, getModel: ModelFetcher, options: CustomFieldOptions) => Promise<Sequelize>;
263
16
  declare const disableCustomFields: (models: Models[], getModel: ModelFetcher) => void;
264
17
  //#endregion
265
- export { AssociatedTestModel, CUSTOM_FIELDS_FILTER_SCOPE, ContextAwareTestModel, ContextTestModel, CustomFieldDefinition, CustomFieldDefinitionType, CustomFieldEntries, CustomFieldValue, CustomFieldsSchema, CustomValidator, TestModel, customFieldsSortScope, useCustomFields as default, disableCustomFields, generateCustomFieldSearchQueryPayload, generateRandomString, initTables, initTestModels, supportedEntities };
18
+ export { CUSTOM_FIELDS_FILTER_SCOPE, CustomFieldDefinitionType, CustomFieldsSchema, customFieldsSortScope, useCustomFields as default, disableCustomFields, generateCustomFieldSearchQueryPayload, generateRandomString, supportedEntities };
266
19
  //# sourceMappingURL=index.d.ts.map