@autofleet/sadot 1.0.8 → 1.0.10
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/index.cjs +46 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +255 -8
- package/dist/index.d.ts +255 -8
- package/dist/index.js +46 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/_virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.cjs +0 -1
- package/dist/_virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.js +0 -1
- package/dist/_virtual/_@oxc-project_runtime@0.89.0/helpers/decorateMetadata.cjs +0 -1
- package/dist/_virtual/_@oxc-project_runtime@0.89.0/helpers/decorateMetadata.js +0 -1
- package/dist/_virtual/rolldown_runtime.cjs +0 -1
- package/dist/api/index.cjs +0 -2
- package/dist/api/index.cjs.map +0 -1
- package/dist/api/index.js +0 -2
- package/dist/api/index.js.map +0 -1
- package/dist/api/v1/definition/index.cjs +0 -2
- package/dist/api/v1/definition/index.cjs.map +0 -1
- package/dist/api/v1/definition/index.js +0 -2
- package/dist/api/v1/definition/index.js.map +0 -1
- package/dist/api/v1/definition/validations.cjs +0 -2
- package/dist/api/v1/definition/validations.cjs.map +0 -1
- package/dist/api/v1/definition/validations.js +0 -2
- package/dist/api/v1/definition/validations.js.map +0 -1
- package/dist/api/v1/errors.cjs +0 -2
- package/dist/api/v1/errors.cjs.map +0 -1
- package/dist/api/v1/errors.js +0 -2
- package/dist/api/v1/errors.js.map +0 -1
- package/dist/api/v1/index.cjs +0 -2
- package/dist/api/v1/index.cjs.map +0 -1
- package/dist/api/v1/index.js +0 -2
- package/dist/api/v1/index.js.map +0 -1
- package/dist/api/v1/validator/index.cjs +0 -2
- package/dist/api/v1/validator/index.cjs.map +0 -1
- package/dist/api/v1/validator/index.js +0 -2
- package/dist/api/v1/validator/index.js.map +0 -1
- package/dist/api/v1/validator/validations.cjs +0 -2
- package/dist/api/v1/validator/validations.cjs.map +0 -1
- package/dist/api/v1/validator/validations.js +0 -2
- package/dist/api/v1/validator/validations.js.map +0 -1
- package/dist/errors/index.cjs +0 -3
- package/dist/errors/index.cjs.map +0 -1
- package/dist/errors/index.js +0 -3
- package/dist/errors/index.js.map +0 -1
- package/dist/events/index.cjs +0 -2
- package/dist/events/index.cjs.map +0 -1
- package/dist/events/index.js +0 -2
- package/dist/events/index.js.map +0 -1
- package/dist/hooks/enrich.cjs +0 -2
- package/dist/hooks/enrich.cjs.map +0 -1
- package/dist/hooks/enrich.js +0 -2
- package/dist/hooks/enrich.js.map +0 -1
- package/dist/hooks/find.cjs +0 -2
- package/dist/hooks/find.cjs.map +0 -1
- package/dist/hooks/find.js +0 -2
- package/dist/hooks/find.js.map +0 -1
- package/dist/hooks/hooks.cjs +0 -2
- package/dist/hooks/hooks.cjs.map +0 -1
- package/dist/hooks/hooks.js +0 -2
- package/dist/hooks/hooks.js.map +0 -1
- package/dist/hooks/index.cjs +0 -1
- package/dist/hooks/index.js +0 -1
- package/dist/hooks/utils/updateInstanceValues.cjs +0 -2
- package/dist/hooks/utils/updateInstanceValues.cjs.map +0 -1
- package/dist/hooks/utils/updateInstanceValues.js +0 -2
- package/dist/hooks/utils/updateInstanceValues.js.map +0 -1
- package/dist/models/CustomFieldDefinition.cjs +0 -2
- package/dist/models/CustomFieldDefinition.cjs.map +0 -1
- package/dist/models/CustomFieldDefinition.js +0 -2
- package/dist/models/CustomFieldDefinition.js.map +0 -1
- package/dist/models/CustomFieldEntries.cjs +0 -2
- package/dist/models/CustomFieldEntries.cjs.map +0 -1
- package/dist/models/CustomFieldEntries.js +0 -2
- package/dist/models/CustomFieldEntries.js.map +0 -1
- package/dist/models/CustomFieldValue.cjs +0 -2
- package/dist/models/CustomFieldValue.cjs.map +0 -1
- package/dist/models/CustomFieldValue.js +0 -2
- package/dist/models/CustomFieldValue.js.map +0 -1
- package/dist/models/CustomValidator.cjs +0 -2
- package/dist/models/CustomValidator.cjs.map +0 -1
- package/dist/models/CustomValidator.js +0 -2
- package/dist/models/CustomValidator.js.map +0 -1
- package/dist/models/index.cjs +0 -2
- package/dist/models/index.cjs.map +0 -1
- package/dist/models/index.js +0 -2
- package/dist/models/index.js.map +0 -1
- package/dist/models/tests/AssociatedTestModel.cjs +0 -2
- package/dist/models/tests/AssociatedTestModel.cjs.map +0 -1
- package/dist/models/tests/AssociatedTestModel.js +0 -2
- package/dist/models/tests/AssociatedTestModel.js.map +0 -1
- package/dist/models/tests/TestModel.cjs +0 -2
- package/dist/models/tests/TestModel.cjs.map +0 -1
- package/dist/models/tests/TestModel.js +0 -2
- package/dist/models/tests/TestModel.js.map +0 -1
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs +0 -2
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs.map +0 -1
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js +0 -2
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js.map +0 -1
- package/dist/models/tests/contextAwareModels/ContextTestModel.cjs +0 -2
- package/dist/models/tests/contextAwareModels/ContextTestModel.cjs.map +0 -1
- package/dist/models/tests/contextAwareModels/ContextTestModel.js +0 -2
- package/dist/models/tests/contextAwareModels/ContextTestModel.js.map +0 -1
- package/dist/repository/definition.cjs +0 -2
- package/dist/repository/definition.cjs.map +0 -1
- package/dist/repository/definition.js +0 -2
- package/dist/repository/definition.js.map +0 -1
- package/dist/repository/entries.cjs +0 -2
- package/dist/repository/entries.cjs.map +0 -1
- package/dist/repository/entries.js +0 -2
- package/dist/repository/entries.js.map +0 -1
- package/dist/repository/utils/formatValues.cjs +0 -2
- package/dist/repository/utils/formatValues.cjs.map +0 -1
- package/dist/repository/utils/formatValues.js +0 -2
- package/dist/repository/utils/formatValues.js.map +0 -1
- package/dist/repository/validator.cjs +0 -2
- package/dist/repository/validator.cjs.map +0 -1
- package/dist/repository/validator.js +0 -2
- package/dist/repository/validator.js.map +0 -1
- package/dist/repository/value.cjs +0 -2
- package/dist/repository/value.cjs.map +0 -1
- package/dist/repository/value.js +0 -2
- package/dist/repository/value.js.map +0 -1
- package/dist/scopes/filter.cjs +0 -2
- package/dist/scopes/filter.cjs.map +0 -1
- package/dist/scopes/filter.d.cts +0 -23
- package/dist/scopes/filter.d.ts +0 -23
- package/dist/scopes/filter.js +0 -2
- package/dist/scopes/filter.js.map +0 -1
- package/dist/scopes/helpers/filter.helpers.cjs +0 -46
- package/dist/scopes/helpers/filter.helpers.cjs.map +0 -1
- package/dist/scopes/helpers/filter.helpers.d.cts +0 -17
- package/dist/scopes/helpers/filter.helpers.d.ts +0 -17
- package/dist/scopes/helpers/filter.helpers.js +0 -46
- package/dist/scopes/helpers/filter.helpers.js.map +0 -1
- package/dist/scopes/index.cjs +0 -1
- package/dist/scopes/index.js +0 -1
- package/dist/types/index.d.cts +0 -44
- package/dist/types/index.d.ts +0 -44
- package/dist/utils/constants/index.cjs +0 -2
- package/dist/utils/constants/index.cjs.map +0 -1
- package/dist/utils/constants/index.d.cts +0 -22
- package/dist/utils/constants/index.d.ts +0 -22
- package/dist/utils/constants/index.js +0 -2
- package/dist/utils/constants/index.js.map +0 -1
- package/dist/utils/db/index.cjs +0 -2
- package/dist/utils/db/index.cjs.map +0 -1
- package/dist/utils/db/index.js +0 -2
- package/dist/utils/db/index.js.map +0 -1
- package/dist/utils/helpers/index.cjs +0 -2
- package/dist/utils/helpers/index.cjs.map +0 -1
- package/dist/utils/helpers/index.d.cts +0 -31
- package/dist/utils/helpers/index.d.ts +0 -31
- package/dist/utils/helpers/index.js +0 -2
- package/dist/utils/helpers/index.js.map +0 -1
- package/dist/utils/init.cjs +0 -2
- package/dist/utils/init.cjs.map +0 -1
- package/dist/utils/init.js +0 -2
- package/dist/utils/init.js.map +0 -1
- package/dist/utils/logger/index.cjs +0 -2
- package/dist/utils/logger/index.cjs.map +0 -1
- package/dist/utils/logger/index.js +0 -2
- package/dist/utils/logger/index.js.map +0 -1
- package/dist/utils/scopeAttributes.cjs +0 -2
- package/dist/utils/scopeAttributes.cjs.map +0 -1
- package/dist/utils/scopeAttributes.js +0 -2
- package/dist/utils/scopeAttributes.js.map +0 -1
- package/dist/utils/validations/index.cjs +0 -2
- package/dist/utils/validations/index.cjs.map +0 -1
- package/dist/utils/validations/index.js +0 -2
- package/dist/utils/validations/index.js.map +0 -1
- package/dist/utils/validations/schema/custom-fields.cjs +0 -2
- package/dist/utils/validations/schema/custom-fields.cjs.map +0 -1
- package/dist/utils/validations/schema/custom-fields.d.cts +0 -7
- package/dist/utils/validations/schema/custom-fields.d.ts +0 -7
- package/dist/utils/validations/schema/custom-fields.js +0 -2
- package/dist/utils/validations/schema/custom-fields.js.map +0 -1
- package/dist/utils/validations/schema/validator-schema.cjs +0 -2
- package/dist/utils/validations/schema/validator-schema.cjs.map +0 -1
- package/dist/utils/validations/schema/validator-schema.js +0 -2
- package/dist/utils/validations/schema/validator-schema.js.map +0 -1
- package/dist/utils/validations/validators/index.cjs +0 -2
- package/dist/utils/validations/validators/index.cjs.map +0 -1
- package/dist/utils/validations/validators/index.js +0 -2
- package/dist/utils/validations/validators/index.js.map +0 -1
- package/dist/utils/validations/validators/select.validator.cjs +0 -2
- package/dist/utils/validations/validators/select.validator.cjs.map +0 -1
- package/dist/utils/validations/validators/select.validator.js +0 -2
- package/dist/utils/validations/validators/select.validator.js.map +0 -1
- package/dist/utils/validations/validators/status.validator.cjs +0 -2
- package/dist/utils/validations/validators/status.validator.cjs.map +0 -1
- package/dist/utils/validations/validators/status.validator.js +0 -2
- package/dist/utils/validations/validators/status.validator.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["env: string","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,CAEjD,IAAMA,EAAc,QAAQ,IAAI,UADhB,OAEV,EAAS,EAAe,GAC1BC,EAMJ,MALA,CAGE,EAHE,EAAO,iBACG,IAAI,EAAU,QAAQ,IAAI,EAAO,kBAAmB,EAAO,CAE3D,IAAI,EAAU,EAAO,SAAU,EAAO,SAAU,EAAO,SAAU,EAAO,CAE/E"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=require(`../../_virtual/rolldown_runtime.cjs`),t=require(`../constants/index.cjs`);let n=require(`sequelize`);n=e.__toESM(n);let r=require(`sequelize-typescript`);r=e.__toESM(r);let i=require(`node:crypto`);i=e.__toESM(i);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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["CustomFieldDefinitionType","Op","Sequelize"],"sources":["../../../src/utils/helpers/index.ts"],"sourcesContent":["/* eslint-disable import/prefer-default-export */\nimport { 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":"sOA4BA,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,IAAK,GAAS,IAAI,EAAK,GAAG,CAAC,KAAK,IAAI,CAErF,EAAW,sHAIc,EAAS,mEAEP,EAAM,KAAK,IAChC,EAAsB,6BAA6B,EAAoB,GAAK,GAAA,0DAGrD,EAAM,KAAK,0DAG9C,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"}
|
|
@@ -1,31 +0,0 @@
|
|
|
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,31 +0,0 @@
|
|
|
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
|
-
|
|
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.ts.map
|
|
@@ -1,2 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/utils/helpers/index.ts"],"sourcesContent":["/* eslint-disable import/prefer-default-export */\nimport { 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":"0LA4BA,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,IAAK,GAAS,IAAI,EAAK,GAAG,CAAC,KAAK,IAAI,CAErF,EAAW,sHAIc,EAAS,mEAEP,EAAM,KAAK,IAChC,EAAsB,6BAA6B,EAAoB,GAAK,GAAA,0DAGrD,EAAM,KAAK,0DAG9C,MAAO,CACL,MAAO,EACJ,EAAG,IAAK,CACP,EAAU,MAAM,EAAU,QAAQ,EAAS,CAAE,GAAK,CACnD,CACF,CACD,aAAc,CAAE,WAAY,IAAI,EAAW,GAAI,CAChD"}
|
package/dist/utils/init.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
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`);l=e.__toESM(l);let u=require(`@autofleet/common-types`);u=e.__toESM(u);let d=require(`@autofleet/common-types/lib/custom-fields`);d=e.__toESM(d);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,null,c,r)),u.addHook(`afterCreate`,`sadot-afterCreate`,a.default(e,i,null,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
|
package/dist/utils/init.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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, null, modelOptions, sadotOptions));\n model.addHook('afterCreate', 'sadot-afterCreate', enrichResults(name, scopeAttributes, null, 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":"knBAsBA,KAAM,CAAE,8BAA+BA,EAAAA,aAE1B,GACX,EACA,EACA,EAAoD,CAAE,uBAAwB,GAAO,GAC5E,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,KAAM,EAAc,EAAa,CAAC,CACzH,EAAM,QAAQ,cAAe,oBAAqBA,EAAAA,QAAc,EAAM,EAAiB,KAAM,EAAc,EAAa,CAAC,OAClH,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
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
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,null,d,r)),p.addHook(`afterCreate`,`sadot-afterCreate`,i(t,u,null,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
|
package/dist/utils/init.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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, null, modelOptions, sadotOptions));\n model.addHook('afterCreate', 'sadot-afterCreate', enrichResults(name, scopeAttributes, null, 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,EAAoD,CAAE,uBAAwB,GAAO,GAC5E,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,KAAM,EAAc,EAAa,CAAC,CACzH,EAAM,QAAQ,cAAe,oBAAqBA,EAAc,EAAM,EAAiB,KAAM,EAAc,EAAa,CAAC,OAClH,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"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=require(`../../_virtual/rolldown_runtime.cjs`);let t=require(`@autofleet/logger`);t=e.__toESM(t);const n=(0,t.default)();async function r(){try{let{outbreak:e}=await import(`@autofleet/zehut`);n.addContextMiddleware(()=>({traceId:e.getCurrentContextTraceId()}))}catch(e){n.error(`Failed to add traceId middleware`,{err:e})}}var i=n;exports.default=i,exports.tryAddingTraceIdMiddleware=r;
|
|
2
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["logger: LoggerInstanceManager"],"sources":["../../../src/utils/logger/index.ts"],"sourcesContent":["import Logger, { type LoggerInstanceManager } from '@autofleet/logger';\n\nconst logger: LoggerInstanceManager = Logger();\n\nexport async function tryAddingTraceIdMiddleware(): Promise<void> {\n try {\n const { outbreak } = await import('@autofleet/zehut');\n logger.addContextMiddleware(() => ({ traceId: outbreak.getCurrentContextTraceId() }));\n } catch (err) {\n logger.error('Failed to add traceId middleware', { err });\n }\n}\n\nexport default logger;\n"],"mappings":"yGAEA,MAAMA,GAAAA,EAAAA,EAAAA,UAAwC,CAE9C,eAAsB,GAA4C,CAChE,GAAI,CACF,GAAM,CAAE,YAAa,MAAM,OAAO,oBAClC,EAAO,0BAA4B,CAAE,QAAS,EAAS,0BAA0B,CAAE,EAAE,OAC9E,EAAK,CACZ,EAAO,MAAM,mCAAoC,CAAE,MAAK,CAAC,EAI7D,IAAA,EAAe"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import e from"@autofleet/logger";const t=e();async function n(){try{let{outbreak:e}=await import(`@autofleet/zehut`);t.addContextMiddleware(()=>({traceId:e.getCurrentContextTraceId()}))}catch(e){t.error(`Failed to add traceId middleware`,{err:e})}}var r=t;export{r as default,n as tryAddingTraceIdMiddleware};
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["logger: LoggerInstanceManager"],"sources":["../../../src/utils/logger/index.ts"],"sourcesContent":["import Logger, { type LoggerInstanceManager } from '@autofleet/logger';\n\nconst logger: LoggerInstanceManager = Logger();\n\nexport async function tryAddingTraceIdMiddleware(): Promise<void> {\n try {\n const { outbreak } = await import('@autofleet/zehut');\n logger.addContextMiddleware(() => ({ traceId: outbreak.getCurrentContextTraceId() }));\n } catch (err) {\n logger.error('Failed to add traceId middleware', { err });\n }\n}\n\nexport default logger;\n"],"mappings":"iCAEA,MAAMA,EAAgC,GAAQ,CAE9C,eAAsB,GAA4C,CAChE,GAAI,CACF,GAAM,CAAE,YAAa,MAAM,OAAO,oBAClC,EAAO,0BAA4B,CAAE,QAAS,EAAS,0BAA0B,CAAE,EAAE,OAC9E,EAAK,CACZ,EAAO,MAAM,mCAAoC,CAAE,MAAK,CAAC,EAI7D,IAAA,EAAe"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scopeAttributes.cjs","names":[],"sources":["../../src/utils/scopeAttributes.ts"],"sourcesContent":["const mapAttributeToInstance = (scopeAttributes: string[], instance: any) =>\n scopeAttributes.map((attr) => instance[attr]);\n\nconst applyScopeToInstance = (instance: any, scopeAttributes: string[]): any[] => {\n const uniqueAttributes = Array.from(new Set(scopeAttributes));\n if (Array.isArray(instance)) {\n return instance.flatMap((ins) => mapAttributeToInstance(uniqueAttributes, ins));\n }\n return mapAttributeToInstance(uniqueAttributes, instance);\n};\n\nexport default applyScopeToInstance;\n"],"mappings":"AAAA,MAAM,GAA0B,EAA2B,IACzD,EAAgB,IAAK,GAAS,EAAS,GAAM,CAEzC,GAAwB,EAAe,IAAqC,CAChF,IAAM,EAAmB,MAAM,KAAK,IAAI,IAAI,EAAgB,CAAC,CAI7D,OAHI,MAAM,QAAQ,EAAS,CAClB,EAAS,QAAS,GAAQ,EAAuB,EAAkB,EAAI,CAAC,CAE1E,EAAuB,EAAkB,EAAS,EAG3D,IAAA,EAAe"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scopeAttributes.js","names":[],"sources":["../../src/utils/scopeAttributes.ts"],"sourcesContent":["const mapAttributeToInstance = (scopeAttributes: string[], instance: any) =>\n scopeAttributes.map((attr) => instance[attr]);\n\nconst applyScopeToInstance = (instance: any, scopeAttributes: string[]): any[] => {\n const uniqueAttributes = Array.from(new Set(scopeAttributes));\n if (Array.isArray(instance)) {\n return instance.flatMap((ins) => mapAttributeToInstance(uniqueAttributes, ins));\n }\n return mapAttributeToInstance(uniqueAttributes, instance);\n};\n\nexport default applyScopeToInstance;\n"],"mappings":"AAAA,MAAM,GAA0B,EAA2B,IACzD,EAAgB,IAAK,GAAS,EAAS,GAAM,CAU/C,IAAA,GAR8B,EAAe,IAAqC,CAChF,IAAM,EAAmB,MAAM,KAAK,IAAI,IAAI,EAAgB,CAAC,CAI7D,OAHI,MAAM,QAAQ,EAAS,CAClB,EAAS,QAAS,GAAQ,EAAuB,EAAkB,EAAI,CAAC,CAE1E,EAAuB,EAAkB,EAAS"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=require(`./validators/index.cjs`),t=require(`../../errors/index.cjs`),n=t=>Object.keys(e.validators).includes(t),r=(t,n,r)=>{let i=e.validators[n];return i(t,r)},i=(e,n,i=r)=>{let a=Object.entries(e.customFields).map(([e,t])=>{if(t===null)return null;let{validation:r,fieldType:a}=n[e],o=i(t,a,r);return o?.error?{joiValidationError:o.error,fieldDefinitionName:e,value:t}:null}).filter(e=>!!e);if(a?.length)throw new t.InvalidEntriesError(e.modelId,a)};exports.validateFieldType=n,exports.validateInstanceCustomFieldEntries=i,exports.validateValue=r;
|
|
2
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["validators","InvalidEntriesError"],"sources":["../../../src/utils/validations/index.ts"],"sourcesContent":["import type Joi from 'joi';\nimport { InvalidEntriesError } from '../../errors';\nimport type { CustomFieldDefinition } from '../../models';\nimport type { CustomFieldEntriesDTO } from '../../types/entries';\nimport type { CustomFieldDefinitionType } from '../constants';\nimport { validators } from './validators';\n\nexport const validateFieldType = (type: CustomFieldDefinitionType): boolean => Object.keys(validators).includes(type);\n\nexport const validateValue = (\n value: unknown,\n valueType: CustomFieldDefinitionType,\n validation?: unknown,\n): Joi.ValidationResult => {\n const validator = validators[valueType];\n return validator(value, validation);\n /** TODO: Add validation for required fields\n * @example\n * if (validations.required && !value) {\n * return false;\n * }\n */\n};\n\nexport const validateInstanceCustomFieldEntries = (\n instance: CustomFieldEntriesDTO,\n definitionsByName: { [defName: string]: CustomFieldDefinition; },\n _validateValue: typeof validateValue = validateValue,\n): void => {\n const validationErrors = Object.entries(instance.customFields)\n .map(([customFieldName, value]) => {\n // Allow NULL values, just like we do in custom_field_values.\n if (value === null) return null;\n\n const { validation, fieldType } = definitionsByName[customFieldName];\n const result = _validateValue(value, fieldType, validation);\n if (result?.error) {\n return {\n joiValidationError: result.error,\n fieldDefinitionName: customFieldName,\n value,\n };\n }\n return null;\n })\n .filter((result) => !!result);\n\n if (validationErrors?.length) {\n throw new InvalidEntriesError(instance.modelId, validationErrors);\n }\n};\n"],"mappings":"8EAOa,EAAqB,GAA6C,OAAO,KAAKA,EAAAA,WAAW,CAAC,SAAS,EAAK,CAExG,GACX,EACA,EACA,IACyB,CACzB,IAAM,EAAYA,EAAAA,WAAW,GAC7B,OAAO,EAAU,EAAO,EAAW,EASxB,GACX,EACA,EACA,EAAuC,IAC9B,CACT,IAAM,EAAmB,OAAO,QAAQ,EAAS,aAAa,CAC3D,KAAK,CAAC,EAAiB,KAAW,CAEjC,GAAI,IAAU,KAAM,OAAO,KAE3B,GAAM,CAAE,aAAY,aAAc,EAAkB,GAC9C,EAAS,EAAe,EAAO,EAAW,EAAW,CAQ3D,OAPI,GAAQ,MACH,CACL,mBAAoB,EAAO,MAC3B,oBAAqB,EACrB,QACD,CAEI,MACP,CACD,OAAQ,GAAW,CAAC,CAAC,EAAO,CAE/B,GAAI,GAAkB,OACpB,MAAM,IAAIC,EAAAA,oBAAoB,EAAS,QAAS,EAAiB"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{validators as e}from"./validators/index.js";import{InvalidEntriesError as t}from"../../errors/index.js";const n=t=>Object.keys(e).includes(t),r=(t,n,r)=>{let i=e[n];return i(t,r)},i=(e,n,i=r)=>{let a=Object.entries(e.customFields).map(([e,t])=>{if(t===null)return null;let{validation:r,fieldType:a}=n[e],o=i(t,a,r);return o?.error?{joiValidationError:o.error,fieldDefinitionName:e,value:t}:null}).filter(e=>!!e);if(a?.length)throw new t(e.modelId,a)};export{n as validateFieldType,i as validateInstanceCustomFieldEntries,r as validateValue};
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/utils/validations/index.ts"],"sourcesContent":["import type Joi from 'joi';\nimport { InvalidEntriesError } from '../../errors';\nimport type { CustomFieldDefinition } from '../../models';\nimport type { CustomFieldEntriesDTO } from '../../types/entries';\nimport type { CustomFieldDefinitionType } from '../constants';\nimport { validators } from './validators';\n\nexport const validateFieldType = (type: CustomFieldDefinitionType): boolean => Object.keys(validators).includes(type);\n\nexport const validateValue = (\n value: unknown,\n valueType: CustomFieldDefinitionType,\n validation?: unknown,\n): Joi.ValidationResult => {\n const validator = validators[valueType];\n return validator(value, validation);\n /** TODO: Add validation for required fields\n * @example\n * if (validations.required && !value) {\n * return false;\n * }\n */\n};\n\nexport const validateInstanceCustomFieldEntries = (\n instance: CustomFieldEntriesDTO,\n definitionsByName: { [defName: string]: CustomFieldDefinition; },\n _validateValue: typeof validateValue = validateValue,\n): void => {\n const validationErrors = Object.entries(instance.customFields)\n .map(([customFieldName, value]) => {\n // Allow NULL values, just like we do in custom_field_values.\n if (value === null) return null;\n\n const { validation, fieldType } = definitionsByName[customFieldName];\n const result = _validateValue(value, fieldType, validation);\n if (result?.error) {\n return {\n joiValidationError: result.error,\n fieldDefinitionName: customFieldName,\n value,\n };\n }\n return null;\n })\n .filter((result) => !!result);\n\n if (validationErrors?.length) {\n throw new InvalidEntriesError(instance.modelId, validationErrors);\n }\n};\n"],"mappings":"+GAOA,MAAa,EAAqB,GAA6C,OAAO,KAAK,EAAW,CAAC,SAAS,EAAK,CAExG,GACX,EACA,EACA,IACyB,CACzB,IAAM,EAAY,EAAW,GAC7B,OAAO,EAAU,EAAO,EAAW,EASxB,GACX,EACA,EACA,EAAuC,IAC9B,CACT,IAAM,EAAmB,OAAO,QAAQ,EAAS,aAAa,CAC3D,KAAK,CAAC,EAAiB,KAAW,CAEjC,GAAI,IAAU,KAAM,OAAO,KAE3B,GAAM,CAAE,aAAY,aAAc,EAAkB,GAC9C,EAAS,EAAe,EAAO,EAAW,EAAW,CAQ3D,OAPI,GAAQ,MACH,CACL,mBAAoB,EAAO,MAC3B,oBAAqB,EACrB,QACD,CAEI,MACP,CACD,OAAQ,GAAW,CAAC,CAAC,EAAO,CAE/B,GAAI,GAAkB,OACpB,MAAM,IAAI,EAAoB,EAAS,QAAS,EAAiB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"custom-fields.cjs","names":["CustomFieldsSchema: Joi.ObjectSchema<Record<string, any>>","Joi"],"sources":["../../../../src/utils/validations/schema/custom-fields.ts"],"sourcesContent":["import Joi from 'joi';\n\nconst CustomFieldsSchema: Joi.ObjectSchema<Record<string, any>> = Joi.object().pattern(\n Joi.string(),\n Joi.any(),\n);\n\nexport { CustomFieldsSchema };\n"],"mappings":"8FAEA,MAAMA,EAA4DC,EAAAA,QAAI,QAAQ,CAAC,QAC7EA,EAAAA,QAAI,QAAQ,CACZA,EAAAA,QAAI,KAAK,CACV"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"custom-fields.js","names":["CustomFieldsSchema: Joi.ObjectSchema<Record<string, any>>"],"sources":["../../../../src/utils/validations/schema/custom-fields.ts"],"sourcesContent":["import Joi from 'joi';\n\nconst CustomFieldsSchema: Joi.ObjectSchema<Record<string, any>> = Joi.object().pattern(\n Joi.string(),\n Joi.any(),\n);\n\nexport { CustomFieldsSchema };\n"],"mappings":"mBAEA,MAAMA,EAA4D,EAAI,QAAQ,CAAC,QAC7E,EAAI,QAAQ,CACZ,EAAI,KAAK,CACV"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=require(`../../../_virtual/rolldown_runtime.cjs`),t=require(`../../logger/index.cjs`);let n=require(`@autofleet/errors`);n=e.__toESM(n);let r=require(`ajv`);r=e.__toESM(r);let i=require(`ajv-formats`);i=e.__toESM(i);const a=new r.default({allErrors:!0,strict:!1,strictTypes:!1,$data:!0});(0,i.default)(a);const o={type:`object`,properties:{type:{type:`string`,enum:[`object`]},properties:{type:`object`,properties:{before:{type:`object`,properties:{type:{type:`string`,enum:[`object`]},properties:{type:`object`}}},after:{type:`object`,properties:{type:{type:`string`,enum:[`object`]},properties:{type:`object`}}}}},required:{type:`array`,items:{type:`string`}},if:{type:`object`},then:{type:`object`},else:{type:`object`}},required:[`type`,`properties`]},s=e=>{try{let r=a.compile(o);if(!r(e)){let i=r.errors?.map(e=>`${e.instancePath||``} ${e.message||`Invalid schema structure`}`).join(`, `);throw t.default.error(`Invalid validator schema structure`,{errors:r.errors,schema:e}),new n.BadRequest([Error(`Invalid validator schema structure: ${i}`)],[`Invalid validator schema structure`])}try{return a.compile(e),!0}catch(r){throw t.default.error(`Failed to compile validator schema`,{error:r,schema:e}),new n.BadRequest([Error(`Failed to compile validator schema: ${r.message}`)],[`Invalid validator schema`])}}catch(r){throw r instanceof n.BadRequest?r:(t.default.error(`Error validating validator schema`,{error:r,schema:e}),new n.BadRequest([Error(`Error validating validator schema: ${r.message}`)],[`Invalid validator schema`]))}};exports.validateValidatorSchema=s;
|
|
2
|
-
//# sourceMappingURL=validator-schema.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validator-schema.cjs","names":["Ajv","BadRequest"],"sources":["../../../../src/utils/validations/schema/validator-schema.ts"],"sourcesContent":["import Ajv from 'ajv';\nimport addFormats from 'ajv-formats';\nimport { BadRequest } from '@autofleet/errors';\nimport logger from '../../logger';\nimport type { SchemaObject } from '../../../api/v1/validator/validations';\n\n// Instantiate Ajv for meta-validation\nconst metaValidator = new Ajv({\n allErrors: true,\n strict: false,\n strictTypes: false,\n $data: true, // Enable $data references\n});\naddFormats(metaValidator);\n\n/**\n * Schema for validating JSON Schema objects in custom validators\n * This is a meta-schema to ensure that custom validator schemas are valid Ajv schemas\n */\nconst validatorMetaSchema = {\n type: 'object',\n properties: {\n type: { type: 'string', enum: ['object'] },\n properties: {\n type: 'object',\n properties: {\n before: {\n type: 'object',\n properties: {\n type: { type: 'string', enum: ['object'] },\n properties: { type: 'object' },\n },\n },\n after: {\n type: 'object',\n properties: {\n type: { type: 'string', enum: ['object'] },\n properties: { type: 'object' },\n },\n },\n },\n },\n required: {\n type: 'array',\n items: { type: 'string' },\n },\n if: { type: 'object' },\n then: { type: 'object' },\n else: { type: 'object' },\n },\n required: ['type', 'properties'],\n};\n\n/**\n * Validates that a given schema is a valid Ajv schema\n * This function is used to validate schemas passed to custom validators\n *\n * @param schema The schema to validate\n * @returns true if valid, throws an error if invalid\n */\nexport const validateValidatorSchema = (schema: SchemaObject): boolean => {\n try {\n // First validate the schema structure\n const validateMetaSchema = metaValidator.compile(validatorMetaSchema);\n const isValidStructure = validateMetaSchema(schema);\n\n if (!isValidStructure) {\n const errorDetails = validateMetaSchema.errors?.map((err) =>\n `${(err as unknown as { instancePath: string }).instancePath || ''} ${(err as unknown as { message: string }).message || 'Invalid schema structure'}`).join(', ');\n\n logger.error('Invalid validator schema structure', {\n errors: validateMetaSchema.errors,\n schema,\n });\n\n throw new BadRequest(\n [new Error(`Invalid validator schema structure: ${errorDetails}`)],\n ['Invalid validator schema structure'],\n );\n }\n\n // Then try to compile the schema with Ajv to verify it's a valid JSON Schema\n try {\n metaValidator.compile(schema);\n return true;\n } catch (compileError) {\n logger.error('Failed to compile validator schema', { error: compileError, schema });\n\n throw new BadRequest(\n [new Error(`Failed to compile validator schema: ${(compileError as Error).message}`)],\n ['Invalid validator schema'],\n );\n }\n } catch (error) {\n if (error instanceof BadRequest) {\n throw error;\n }\n\n logger.error('Error validating validator schema', { error, schema });\n throw new BadRequest(\n [new Error(`Error validating validator schema: ${(error as Error).message}`)],\n ['Invalid validator schema'],\n );\n }\n};\n\nexport default validateValidatorSchema;\n"],"mappings":"gOAOA,MAAM,EAAgB,IAAIA,EAAAA,QAAI,CAC5B,UAAW,GACX,OAAQ,GACR,YAAa,GACb,MAAO,GACR,CAAC,eACS,EAAc,CAMzB,MAAM,EAAsB,CAC1B,KAAM,SACN,WAAY,CACV,KAAM,CAAE,KAAM,SAAU,KAAM,CAAC,SAAS,CAAE,CAC1C,WAAY,CACV,KAAM,SACN,WAAY,CACV,OAAQ,CACN,KAAM,SACN,WAAY,CACV,KAAM,CAAE,KAAM,SAAU,KAAM,CAAC,SAAS,CAAE,CAC1C,WAAY,CAAE,KAAM,SAAU,CAC/B,CACF,CACD,MAAO,CACL,KAAM,SACN,WAAY,CACV,KAAM,CAAE,KAAM,SAAU,KAAM,CAAC,SAAS,CAAE,CAC1C,WAAY,CAAE,KAAM,SAAU,CAC/B,CACF,CACF,CACF,CACD,SAAU,CACR,KAAM,QACN,MAAO,CAAE,KAAM,SAAU,CAC1B,CACD,GAAI,CAAE,KAAM,SAAU,CACtB,KAAM,CAAE,KAAM,SAAU,CACxB,KAAM,CAAE,KAAM,SAAU,CACzB,CACD,SAAU,CAAC,OAAQ,aAAa,CACjC,CASY,EAA2B,GAAkC,CACxE,GAAI,CAEF,IAAM,EAAqB,EAAc,QAAQ,EAAoB,CAGrE,GAAI,CAFqB,EAAmB,EAAO,CAE5B,CACrB,IAAM,EAAe,EAAmB,QAAQ,IAAK,GACnD,GAAI,EAA4C,cAAgB,GAAG,GAAI,EAAuC,SAAW,6BAA6B,CAAC,KAAK,KAAK,CAOnK,MALA,EAAA,QAAO,MAAM,qCAAsC,CACjD,OAAQ,EAAmB,OAC3B,SACD,CAAC,CAEI,IAAIC,EAAAA,WACR,CAAK,MAAM,uCAAuC,IAAe,CAAC,CAClE,CAAC,qCAAqC,CACvC,CAIH,GAAI,CAEF,OADA,EAAc,QAAQ,EAAO,CACtB,SACA,EAAc,CAGrB,MAFA,EAAA,QAAO,MAAM,qCAAsC,CAAE,MAAO,EAAc,SAAQ,CAAC,CAE7E,IAAIA,EAAAA,WACR,CAAK,MAAM,uCAAwC,EAAuB,UAAU,CAAC,CACrF,CAAC,2BAA2B,CAC7B,QAEI,EAAO,CAMd,MALI,aAAiBA,EAAAA,WACb,GAGR,EAAA,QAAO,MAAM,oCAAqC,CAAE,QAAO,SAAQ,CAAC,CAC9D,IAAIA,EAAAA,WACR,CAAK,MAAM,sCAAuC,EAAgB,UAAU,CAAC,CAC7E,CAAC,2BAA2B,CAC7B"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import e from"../../logger/index.js";import{BadRequest as t}from"@autofleet/errors";import n from"ajv";import r from"ajv-formats";const i=new n({allErrors:!0,strict:!1,strictTypes:!1,$data:!0});r(i);const a={type:`object`,properties:{type:{type:`string`,enum:[`object`]},properties:{type:`object`,properties:{before:{type:`object`,properties:{type:{type:`string`,enum:[`object`]},properties:{type:`object`}}},after:{type:`object`,properties:{type:{type:`string`,enum:[`object`]},properties:{type:`object`}}}}},required:{type:`array`,items:{type:`string`}},if:{type:`object`},then:{type:`object`},else:{type:`object`}},required:[`type`,`properties`]},o=n=>{try{let r=i.compile(a);if(!r(n)){let i=r.errors?.map(e=>`${e.instancePath||``} ${e.message||`Invalid schema structure`}`).join(`, `);throw e.error(`Invalid validator schema structure`,{errors:r.errors,schema:n}),new t([Error(`Invalid validator schema structure: ${i}`)],[`Invalid validator schema structure`])}try{return i.compile(n),!0}catch(r){throw e.error(`Failed to compile validator schema`,{error:r,schema:n}),new t([Error(`Failed to compile validator schema: ${r.message}`)],[`Invalid validator schema`])}}catch(r){throw r instanceof t?r:(e.error(`Error validating validator schema`,{error:r,schema:n}),new t([Error(`Error validating validator schema: ${r.message}`)],[`Invalid validator schema`]))}};export{o as validateValidatorSchema};
|
|
2
|
-
//# sourceMappingURL=validator-schema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validator-schema.js","names":[],"sources":["../../../../src/utils/validations/schema/validator-schema.ts"],"sourcesContent":["import Ajv from 'ajv';\nimport addFormats from 'ajv-formats';\nimport { BadRequest } from '@autofleet/errors';\nimport logger from '../../logger';\nimport type { SchemaObject } from '../../../api/v1/validator/validations';\n\n// Instantiate Ajv for meta-validation\nconst metaValidator = new Ajv({\n allErrors: true,\n strict: false,\n strictTypes: false,\n $data: true, // Enable $data references\n});\naddFormats(metaValidator);\n\n/**\n * Schema for validating JSON Schema objects in custom validators\n * This is a meta-schema to ensure that custom validator schemas are valid Ajv schemas\n */\nconst validatorMetaSchema = {\n type: 'object',\n properties: {\n type: { type: 'string', enum: ['object'] },\n properties: {\n type: 'object',\n properties: {\n before: {\n type: 'object',\n properties: {\n type: { type: 'string', enum: ['object'] },\n properties: { type: 'object' },\n },\n },\n after: {\n type: 'object',\n properties: {\n type: { type: 'string', enum: ['object'] },\n properties: { type: 'object' },\n },\n },\n },\n },\n required: {\n type: 'array',\n items: { type: 'string' },\n },\n if: { type: 'object' },\n then: { type: 'object' },\n else: { type: 'object' },\n },\n required: ['type', 'properties'],\n};\n\n/**\n * Validates that a given schema is a valid Ajv schema\n * This function is used to validate schemas passed to custom validators\n *\n * @param schema The schema to validate\n * @returns true if valid, throws an error if invalid\n */\nexport const validateValidatorSchema = (schema: SchemaObject): boolean => {\n try {\n // First validate the schema structure\n const validateMetaSchema = metaValidator.compile(validatorMetaSchema);\n const isValidStructure = validateMetaSchema(schema);\n\n if (!isValidStructure) {\n const errorDetails = validateMetaSchema.errors?.map((err) =>\n `${(err as unknown as { instancePath: string }).instancePath || ''} ${(err as unknown as { message: string }).message || 'Invalid schema structure'}`).join(', ');\n\n logger.error('Invalid validator schema structure', {\n errors: validateMetaSchema.errors,\n schema,\n });\n\n throw new BadRequest(\n [new Error(`Invalid validator schema structure: ${errorDetails}`)],\n ['Invalid validator schema structure'],\n );\n }\n\n // Then try to compile the schema with Ajv to verify it's a valid JSON Schema\n try {\n metaValidator.compile(schema);\n return true;\n } catch (compileError) {\n logger.error('Failed to compile validator schema', { error: compileError, schema });\n\n throw new BadRequest(\n [new Error(`Failed to compile validator schema: ${(compileError as Error).message}`)],\n ['Invalid validator schema'],\n );\n }\n } catch (error) {\n if (error instanceof BadRequest) {\n throw error;\n }\n\n logger.error('Error validating validator schema', { error, schema });\n throw new BadRequest(\n [new Error(`Error validating validator schema: ${(error as Error).message}`)],\n ['Invalid validator schema'],\n );\n }\n};\n\nexport default validateValidatorSchema;\n"],"mappings":"kIAOA,MAAM,EAAgB,IAAI,EAAI,CAC5B,UAAW,GACX,OAAQ,GACR,YAAa,GACb,MAAO,GACR,CAAC,CACF,EAAW,EAAc,CAMzB,MAAM,EAAsB,CAC1B,KAAM,SACN,WAAY,CACV,KAAM,CAAE,KAAM,SAAU,KAAM,CAAC,SAAS,CAAE,CAC1C,WAAY,CACV,KAAM,SACN,WAAY,CACV,OAAQ,CACN,KAAM,SACN,WAAY,CACV,KAAM,CAAE,KAAM,SAAU,KAAM,CAAC,SAAS,CAAE,CAC1C,WAAY,CAAE,KAAM,SAAU,CAC/B,CACF,CACD,MAAO,CACL,KAAM,SACN,WAAY,CACV,KAAM,CAAE,KAAM,SAAU,KAAM,CAAC,SAAS,CAAE,CAC1C,WAAY,CAAE,KAAM,SAAU,CAC/B,CACF,CACF,CACF,CACD,SAAU,CACR,KAAM,QACN,MAAO,CAAE,KAAM,SAAU,CAC1B,CACD,GAAI,CAAE,KAAM,SAAU,CACtB,KAAM,CAAE,KAAM,SAAU,CACxB,KAAM,CAAE,KAAM,SAAU,CACzB,CACD,SAAU,CAAC,OAAQ,aAAa,CACjC,CASY,EAA2B,GAAkC,CACxE,GAAI,CAEF,IAAM,EAAqB,EAAc,QAAQ,EAAoB,CAGrE,GAAI,CAFqB,EAAmB,EAAO,CAE5B,CACrB,IAAM,EAAe,EAAmB,QAAQ,IAAK,GACnD,GAAI,EAA4C,cAAgB,GAAG,GAAI,EAAuC,SAAW,6BAA6B,CAAC,KAAK,KAAK,CAOnK,MALA,EAAO,MAAM,qCAAsC,CACjD,OAAQ,EAAmB,OAC3B,SACD,CAAC,CAEI,IAAI,EACR,CAAK,MAAM,uCAAuC,IAAe,CAAC,CAClE,CAAC,qCAAqC,CACvC,CAIH,GAAI,CAEF,OADA,EAAc,QAAQ,EAAO,CACtB,SACA,EAAc,CAGrB,MAFA,EAAO,MAAM,qCAAsC,CAAE,MAAO,EAAc,SAAQ,CAAC,CAE7E,IAAI,EACR,CAAK,MAAM,uCAAwC,EAAuB,UAAU,CAAC,CACrF,CAAC,2BAA2B,CAC7B,QAEI,EAAO,CAMd,MALI,aAAiB,EACb,GAGR,EAAO,MAAM,oCAAqC,CAAE,QAAO,SAAQ,CAAC,CAC9D,IAAI,EACR,CAAK,MAAM,sCAAuC,EAAgB,UAAU,CAAC,CAC7E,CAAC,2BAA2B,CAC7B"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=require(`../../../_virtual/rolldown_runtime.cjs`),t=require(`../../constants/index.cjs`),n=require(`./select.validator.cjs`),r=require(`./status.validator.cjs`);let i=require(`joi`);i=e.__toESM(i);const a={[t.CustomFieldDefinitionType.SELECT]:t.CustomFieldDefinitionType.SELECT,[t.CustomFieldDefinitionType.STATUS]:t.CustomFieldDefinitionType.STATUS},o={[t.CustomFieldDefinitionType.SELECT]:n.validateSelect,[t.CustomFieldDefinitionType.STATUS]:r.validateStatus,[t.CustomFieldDefinitionType.TEXT]:e=>i.default.string().min(0).validate(e),[t.CustomFieldDefinitionType.NUMBER]:e=>i.default.number().strict(!0).validate(e),[t.CustomFieldDefinitionType.BOOLEAN]:e=>i.default.boolean().strict().validate(e),[t.CustomFieldDefinitionType.DATE]:e=>i.default.date().validate(e),[t.CustomFieldDefinitionType.DATETIME]:e=>i.default.date().validate(e),[t.CustomFieldDefinitionType.IMAGE]:e=>i.default.array().min(1).unique().items(i.default.string().uri()).validate(e),[t.CustomFieldDefinitionType.FILE]:e=>i.default.array().min(1).unique().items(i.default.object({name:i.default.string().required(),type:i.default.string(),size:i.default.string(),addedBy:i.default.string().uuid()})).validate(e)};exports.CustomValidationTypes=a,exports.validators=o;
|
|
2
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["CustomValidationTypes: Record<Extract<CustomFieldDefinitionType, 'select' | 'status'>, CustomFieldDefinitionType>","CustomFieldDefinitionType","validators: Validators","validateSelect","validateStatus","Joi"],"sources":["../../../../src/utils/validations/validators/index.ts"],"sourcesContent":["import Joi from 'joi';\nimport { CustomFieldDefinitionType } from '../../constants';\nimport type { Validators } from '../type';\nimport { validateSelect } from './select.validator';\nimport { validateStatus } from './status.validator';\n\ntype CustomValidationTypes = Extract<CustomFieldDefinitionType, 'select' | 'status'>;\n/**\n * Custom field types that must have custom validation.\n * TODO: remove this after moving to schema-based validation\n */\nexport const CustomValidationTypes: Record<Extract<CustomFieldDefinitionType, 'select' | 'status'>, CustomFieldDefinitionType> = {\n [CustomFieldDefinitionType.SELECT]: CustomFieldDefinitionType.SELECT,\n [CustomFieldDefinitionType.STATUS]: CustomFieldDefinitionType.STATUS,\n} as const;\n\n/**\n * Validators for custom fields\n */\nexport const validators: Validators = {\n [CustomFieldDefinitionType.SELECT]: validateSelect,\n [CustomFieldDefinitionType.STATUS]: validateStatus,\n [CustomFieldDefinitionType.TEXT]: (value) => Joi.string().min(0).validate(value),\n [CustomFieldDefinitionType.NUMBER]: (value) => Joi.number().strict(true).validate(value),\n [CustomFieldDefinitionType.BOOLEAN]: (value) => Joi.boolean().strict().validate(value),\n [CustomFieldDefinitionType.DATE]: (value) => Joi.date().validate(value),\n [CustomFieldDefinitionType.DATETIME]: (value) => Joi.date().validate(value),\n [CustomFieldDefinitionType.IMAGE]: (value) => Joi.array().min(1).unique()\n .items(Joi.string().uri())\n .validate(value),\n [CustomFieldDefinitionType.FILE]: (value) => Joi.array().min(1).unique().items(Joi.object({\n name: Joi.string().required(),\n type: Joi.string(),\n size: Joi.string(),\n addedBy: Joi.string().uuid(),\n }))\n .validate(value),\n};\n"],"mappings":"6MAWA,MAAaA,EAAoH,EAC9HC,EAAAA,0BAA0B,QAASA,EAAAA,0BAA0B,QAC7DA,EAAAA,0BAA0B,QAASA,EAAAA,0BAA0B,OAC/D,CAKYC,EAAyB,EACnCD,EAAAA,0BAA0B,QAASE,EAAAA,gBACnCF,EAAAA,0BAA0B,QAASG,EAAAA,gBACnCH,EAAAA,0BAA0B,MAAQ,GAAUI,EAAAA,QAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,SAAS,EAAM,EAC/EJ,EAAAA,0BAA0B,QAAU,GAAUI,EAAAA,QAAI,QAAQ,CAAC,OAAO,GAAK,CAAC,SAAS,EAAM,EACvFJ,EAAAA,0BAA0B,SAAW,GAAUI,EAAAA,QAAI,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAM,EACrFJ,EAAAA,0BAA0B,MAAQ,GAAUI,EAAAA,QAAI,MAAM,CAAC,SAAS,EAAM,EACtEJ,EAAAA,0BAA0B,UAAY,GAAUI,EAAAA,QAAI,MAAM,CAAC,SAAS,EAAM,EAC1EJ,EAAAA,0BAA0B,OAAS,GAAUI,EAAAA,QAAI,OAAO,CAAC,IAAI,EAAE,CAAC,QAAQ,CACtE,MAAMA,EAAAA,QAAI,QAAQ,CAAC,KAAK,CAAC,CACzB,SAAS,EAAM,EACjBJ,EAAAA,0BAA0B,MAAQ,GAAUI,EAAAA,QAAI,OAAO,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,MAAMA,EAAAA,QAAI,OAAO,CACxF,KAAMA,EAAAA,QAAI,QAAQ,CAAC,UAAU,CAC7B,KAAMA,EAAAA,QAAI,QAAQ,CAClB,KAAMA,EAAAA,QAAI,QAAQ,CAClB,QAASA,EAAAA,QAAI,QAAQ,CAAC,MAAM,CAC7B,CAAC,CAAC,CACA,SAAS,EAAM,CACnB"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{CustomFieldDefinitionType as e}from"../../constants/index.js";import{validateSelect as t}from"./select.validator.js";import{validateStatus as n}from"./status.validator.js";import r from"joi";const i={[e.SELECT]:e.SELECT,[e.STATUS]:e.STATUS},a={[e.SELECT]:t,[e.STATUS]:n,[e.TEXT]:e=>r.string().min(0).validate(e),[e.NUMBER]:e=>r.number().strict(!0).validate(e),[e.BOOLEAN]:e=>r.boolean().strict().validate(e),[e.DATE]:e=>r.date().validate(e),[e.DATETIME]:e=>r.date().validate(e),[e.IMAGE]:e=>r.array().min(1).unique().items(r.string().uri()).validate(e),[e.FILE]:e=>r.array().min(1).unique().items(r.object({name:r.string().required(),type:r.string(),size:r.string(),addedBy:r.string().uuid()})).validate(e)};export{i as CustomValidationTypes,a as validators};
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["CustomValidationTypes: Record<Extract<CustomFieldDefinitionType, 'select' | 'status'>, CustomFieldDefinitionType>","validators: Validators"],"sources":["../../../../src/utils/validations/validators/index.ts"],"sourcesContent":["import Joi from 'joi';\nimport { CustomFieldDefinitionType } from '../../constants';\nimport type { Validators } from '../type';\nimport { validateSelect } from './select.validator';\nimport { validateStatus } from './status.validator';\n\ntype CustomValidationTypes = Extract<CustomFieldDefinitionType, 'select' | 'status'>;\n/**\n * Custom field types that must have custom validation.\n * TODO: remove this after moving to schema-based validation\n */\nexport const CustomValidationTypes: Record<Extract<CustomFieldDefinitionType, 'select' | 'status'>, CustomFieldDefinitionType> = {\n [CustomFieldDefinitionType.SELECT]: CustomFieldDefinitionType.SELECT,\n [CustomFieldDefinitionType.STATUS]: CustomFieldDefinitionType.STATUS,\n} as const;\n\n/**\n * Validators for custom fields\n */\nexport const validators: Validators = {\n [CustomFieldDefinitionType.SELECT]: validateSelect,\n [CustomFieldDefinitionType.STATUS]: validateStatus,\n [CustomFieldDefinitionType.TEXT]: (value) => Joi.string().min(0).validate(value),\n [CustomFieldDefinitionType.NUMBER]: (value) => Joi.number().strict(true).validate(value),\n [CustomFieldDefinitionType.BOOLEAN]: (value) => Joi.boolean().strict().validate(value),\n [CustomFieldDefinitionType.DATE]: (value) => Joi.date().validate(value),\n [CustomFieldDefinitionType.DATETIME]: (value) => Joi.date().validate(value),\n [CustomFieldDefinitionType.IMAGE]: (value) => Joi.array().min(1).unique()\n .items(Joi.string().uri())\n .validate(value),\n [CustomFieldDefinitionType.FILE]: (value) => Joi.array().min(1).unique().items(Joi.object({\n name: Joi.string().required(),\n type: Joi.string(),\n size: Joi.string(),\n addedBy: Joi.string().uuid(),\n }))\n .validate(value),\n};\n"],"mappings":"sMAWA,MAAaA,EAAoH,EAC9H,EAA0B,QAAS,EAA0B,QAC7D,EAA0B,QAAS,EAA0B,OAC/D,CAKYC,EAAyB,EACnC,EAA0B,QAAS,GACnC,EAA0B,QAAS,GACnC,EAA0B,MAAQ,GAAU,EAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,SAAS,EAAM,EAC/E,EAA0B,QAAU,GAAU,EAAI,QAAQ,CAAC,OAAO,GAAK,CAAC,SAAS,EAAM,EACvF,EAA0B,SAAW,GAAU,EAAI,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAM,EACrF,EAA0B,MAAQ,GAAU,EAAI,MAAM,CAAC,SAAS,EAAM,EACtE,EAA0B,UAAY,GAAU,EAAI,MAAM,CAAC,SAAS,EAAM,EAC1E,EAA0B,OAAS,GAAU,EAAI,OAAO,CAAC,IAAI,EAAE,CAAC,QAAQ,CACtE,MAAM,EAAI,QAAQ,CAAC,KAAK,CAAC,CACzB,SAAS,EAAM,EACjB,EAA0B,MAAQ,GAAU,EAAI,OAAO,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAI,OAAO,CACxF,KAAM,EAAI,QAAQ,CAAC,UAAU,CAC7B,KAAM,EAAI,QAAQ,CAClB,KAAM,EAAI,QAAQ,CAClB,QAAS,EAAI,QAAQ,CAAC,MAAM,CAC7B,CAAC,CAAC,CACA,SAAS,EAAM,CACnB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"select.validator.cjs","names":["validateSelect: Validator<string, string[]>","Joi"],"sources":["../../../../src/utils/validations/validators/select.validator.ts"],"sourcesContent":["import Joi from 'joi';\nimport type { Validator } from '../type';\n\n/**\n * Validate that the value is one of the select values\n */\nexport const validateSelect: Validator<string, string[]> = (\n value,\n selectValues,\n) => (\n Joi.string().allow(null).valid(...selectValues).validate(value)\n);\n"],"mappings":"8FAMA,MAAaA,GACX,EACA,IAEAC,EAAAA,QAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,MAAM,GAAG,EAAa,CAAC,SAAS,EAAM"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"select.validator.js","names":["validateSelect: Validator<string, string[]>"],"sources":["../../../../src/utils/validations/validators/select.validator.ts"],"sourcesContent":["import Joi from 'joi';\nimport type { Validator } from '../type';\n\n/**\n * Validate that the value is one of the select values\n */\nexport const validateSelect: Validator<string, string[]> = (\n value,\n selectValues,\n) => (\n Joi.string().allow(null).valid(...selectValues).validate(value)\n);\n"],"mappings":"mBAMA,MAAaA,GACX,EACA,IAEA,EAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,MAAM,GAAG,EAAa,CAAC,SAAS,EAAM"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"status.validator.cjs","names":["validateStatus: Validator<StatusValue, StatusOption[]>","Joi"],"sources":["../../../../src/utils/validations/validators/status.validator.ts"],"sourcesContent":["import Joi from 'joi';\nimport type { Validator } from '../type';\n\ntype StatusColor = string | null; // TODO: Takes from @autofleet/colors ?\ntype StatusValue = string;\ntype StatusOption = {\n value: StatusValue;\n color: StatusColor;\n}\n\n/**\n* Validate that the value is one of the status values\n*/\nexport const validateStatus: Validator<StatusValue, StatusOption[]> = (\n value,\n statusValues,\n) => (\n Joi.string()\n .allow(null)\n .valid(...statusValues.map((statusValue) => statusValue.value))\n .validate(value)\n);\n"],"mappings":"8FAaA,MAAaA,GACX,EACA,IAEAC,EAAAA,QAAI,QAAQ,CACT,MAAM,KAAK,CACX,MAAM,GAAG,EAAa,IAAK,GAAgB,EAAY,MAAM,CAAC,CAC9D,SAAS,EAAM"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"status.validator.js","names":["validateStatus: Validator<StatusValue, StatusOption[]>"],"sources":["../../../../src/utils/validations/validators/status.validator.ts"],"sourcesContent":["import Joi from 'joi';\nimport type { Validator } from '../type';\n\ntype StatusColor = string | null; // TODO: Takes from @autofleet/colors ?\ntype StatusValue = string;\ntype StatusOption = {\n value: StatusValue;\n color: StatusColor;\n}\n\n/**\n* Validate that the value is one of the status values\n*/\nexport const validateStatus: Validator<StatusValue, StatusOption[]> = (\n value,\n statusValues,\n) => (\n Joi.string()\n .allow(null)\n .valid(...statusValues.map((statusValue) => statusValue.value))\n .validate(value)\n);\n"],"mappings":"mBAaA,MAAaA,GACX,EACA,IAEA,EAAI,QAAQ,CACT,MAAM,KAAK,CACX,MAAM,GAAG,EAAa,IAAK,GAAgB,EAAY,MAAM,CAAC,CAC9D,SAAS,EAAM"}
|