@autofleet/sadot 1.0.9 → 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.
- package/dist/_virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.cjs +1 -0
- package/dist/_virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.js +1 -0
- package/dist/_virtual/_@oxc-project_runtime@0.89.0/helpers/decorateMetadata.cjs +1 -0
- package/dist/_virtual/_@oxc-project_runtime@0.89.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 -0
- 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 -0
- 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 -0
- 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 -0
- 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 -0
- 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 -0
- 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.js +2 -0
- 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 -0
- 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 -0
- 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 -0
- 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 -0
- 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 -0
- package/dist/hooks/hooks.js.map +1 -0
- package/dist/hooks/index.cjs +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/utils/updateInstanceValues.cjs +2 -0
- package/dist/hooks/utils/updateInstanceValues.cjs.map +1 -0
- package/dist/hooks/utils/updateInstanceValues.js +2 -0
- package/dist/hooks/utils/updateInstanceValues.js.map +1 -0
- package/dist/index.cjs +1 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -255
- package/dist/index.d.ts +8 -255
- package/dist/index.js +1 -46
- package/dist/index.js.map +1 -1
- package/dist/models/CustomFieldDefinition.cjs +2 -0
- package/dist/models/CustomFieldDefinition.cjs.map +1 -0
- package/dist/models/CustomFieldDefinition.js +2 -0
- 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.js +2 -0
- 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.js +2 -0
- 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.js +2 -0
- 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.js +2 -0
- 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 -0
- 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 -0
- 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 -0
- 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 -0
- 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 -0
- 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 -0
- 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 -0
- 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 -0
- 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 -0
- 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 +23 -0
- package/dist/scopes/filter.js +2 -0
- 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 +17 -0
- package/dist/scopes/helpers/filter.helpers.js +46 -0
- package/dist/scopes/helpers/filter.helpers.js.map +1 -0
- package/dist/scopes/index.cjs +1 -0
- package/dist/scopes/index.js +1 -0
- package/dist/types/index.d.cts +44 -0
- package/dist/types/index.d.ts +44 -0
- 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 +22 -0
- package/dist/utils/constants/index.js +2 -0
- 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 -0
- 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 +31 -0
- package/dist/utils/helpers/index.js +2 -0
- 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 -0
- 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 -0
- 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 -0
- 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 -0
- 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 +7 -0
- package/dist/utils/validations/schema/custom-fields.js +2 -0
- 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 -0
- 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 -0
- 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 -0
- 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 -0
- package/dist/utils/validations/validators/status.validator.js.map +1 -0
- 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 {
|
|
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 {
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
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 {
|
|
18
|
+
export { CUSTOM_FIELDS_FILTER_SCOPE, CustomFieldDefinitionType, CustomFieldsSchema, customFieldsSortScope, useCustomFields as default, disableCustomFields, generateCustomFieldSearchQueryPayload, generateRandomString, supportedEntities };
|
|
266
19
|
//# sourceMappingURL=index.d.ts.map
|