@autofleet/sadot 1.0.13-beta-3 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/README.md +0 -2
  2. package/dist/api/v1/definition/index.cjs +1 -1
  3. package/dist/api/v1/definition/index.cjs.map +1 -1
  4. package/dist/api/v1/definition/index.js +1 -1
  5. package/dist/api/v1/definition/index.js.map +1 -1
  6. package/dist/api/v1/definition/validations.cjs.map +1 -1
  7. package/dist/api/v1/definition/validations.js.map +1 -1
  8. package/dist/api/v1/errors.cjs +1 -1
  9. package/dist/api/v1/errors.cjs.map +1 -1
  10. package/dist/api/v1/errors.js +1 -1
  11. package/dist/api/v1/errors.js.map +1 -1
  12. package/dist/api/v1/validator/index.cjs.map +1 -1
  13. package/dist/api/v1/validator/index.js +1 -1
  14. package/dist/api/v1/validator/index.js.map +1 -1
  15. package/dist/errors/index.cjs +2 -2
  16. package/dist/errors/index.cjs.map +1 -1
  17. package/dist/errors/index.js +2 -2
  18. package/dist/errors/index.js.map +1 -1
  19. package/dist/events/index.cjs +1 -1
  20. package/dist/events/index.cjs.map +1 -1
  21. package/dist/events/index.js +1 -1
  22. package/dist/events/index.js.map +1 -1
  23. package/dist/hooks/enrich.cjs +1 -1
  24. package/dist/hooks/enrich.cjs.map +1 -1
  25. package/dist/hooks/enrich.js +1 -1
  26. package/dist/hooks/enrich.js.map +1 -1
  27. package/dist/hooks/find.cjs.map +1 -1
  28. package/dist/hooks/find.js.map +1 -1
  29. package/dist/hooks/hooks.cjs +1 -1
  30. package/dist/hooks/hooks.cjs.map +1 -1
  31. package/dist/hooks/hooks.js +1 -1
  32. package/dist/hooks/hooks.js.map +1 -1
  33. package/dist/hooks/utils/updateInstanceValues.cjs.map +1 -1
  34. package/dist/hooks/utils/updateInstanceValues.js +1 -1
  35. package/dist/hooks/utils/updateInstanceValues.js.map +1 -1
  36. package/dist/index.cjs +1 -1
  37. package/dist/index.cjs.map +1 -1
  38. package/dist/index.js +1 -1
  39. package/dist/index.js.map +1 -1
  40. package/dist/models/CustomFieldDefinition.cjs +1 -1
  41. package/dist/models/CustomFieldDefinition.cjs.map +1 -1
  42. package/dist/models/CustomFieldDefinition.js +1 -1
  43. package/dist/models/CustomFieldDefinition.js.map +1 -1
  44. package/dist/models/CustomFieldEntries.cjs +1 -1
  45. package/dist/models/CustomFieldEntries.cjs.map +1 -1
  46. package/dist/models/CustomFieldEntries.js +1 -1
  47. package/dist/models/CustomFieldEntries.js.map +1 -1
  48. package/dist/models/CustomFieldValue.cjs +1 -1
  49. package/dist/models/CustomFieldValue.cjs.map +1 -1
  50. package/dist/models/CustomFieldValue.js +1 -1
  51. package/dist/models/CustomFieldValue.js.map +1 -1
  52. package/dist/models/CustomValidator.cjs +1 -1
  53. package/dist/models/CustomValidator.cjs.map +1 -1
  54. package/dist/models/CustomValidator.js +1 -1
  55. package/dist/models/CustomValidator.js.map +1 -1
  56. package/dist/models/index.cjs.map +1 -1
  57. package/dist/models/index.js.map +1 -1
  58. package/dist/models/tests/AssociatedTestModel.cjs +1 -1
  59. package/dist/models/tests/AssociatedTestModel.cjs.map +1 -1
  60. package/dist/models/tests/AssociatedTestModel.js +1 -1
  61. package/dist/models/tests/AssociatedTestModel.js.map +1 -1
  62. package/dist/models/tests/TestModel.cjs +1 -1
  63. package/dist/models/tests/TestModel.cjs.map +1 -1
  64. package/dist/models/tests/TestModel.js +1 -1
  65. package/dist/models/tests/TestModel.js.map +1 -1
  66. package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs +1 -1
  67. package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs.map +1 -1
  68. package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js +1 -1
  69. package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js.map +1 -1
  70. package/dist/models/tests/contextAwareModels/ContextTestModel.cjs +1 -1
  71. package/dist/models/tests/contextAwareModels/ContextTestModel.cjs.map +1 -1
  72. package/dist/models/tests/contextAwareModels/ContextTestModel.js +1 -1
  73. package/dist/models/tests/contextAwareModels/ContextTestModel.js.map +1 -1
  74. package/dist/repository/definition.cjs +1 -1
  75. package/dist/repository/definition.cjs.map +1 -1
  76. package/dist/repository/definition.js +1 -1
  77. package/dist/repository/definition.js.map +1 -1
  78. package/dist/repository/entries.cjs +1 -1
  79. package/dist/repository/entries.cjs.map +1 -1
  80. package/dist/repository/entries.js +1 -1
  81. package/dist/repository/entries.js.map +1 -1
  82. package/dist/repository/validator.cjs.map +1 -1
  83. package/dist/repository/validator.js.map +1 -1
  84. package/dist/repository/value.cjs +1 -1
  85. package/dist/repository/value.cjs.map +1 -1
  86. package/dist/repository/value.js +1 -1
  87. package/dist/repository/value.js.map +1 -1
  88. package/dist/scopes/filter.cjs.map +1 -1
  89. package/dist/scopes/filter.js.map +1 -1
  90. package/dist/scopes/helpers/filter.helpers.cjs +1 -1
  91. package/dist/scopes/helpers/filter.helpers.cjs.map +1 -1
  92. package/dist/scopes/helpers/filter.helpers.d.cts +2 -2
  93. package/dist/scopes/helpers/filter.helpers.d.ts +2 -2
  94. package/dist/scopes/helpers/filter.helpers.js +1 -1
  95. package/dist/scopes/helpers/filter.helpers.js.map +1 -1
  96. package/dist/types/index.d.cts +6 -6
  97. package/dist/types/index.d.ts +7 -7
  98. package/dist/utils/constants/index.cjs.map +1 -1
  99. package/dist/utils/constants/index.js.map +1 -1
  100. package/dist/utils/db/index.cjs +1 -1
  101. package/dist/utils/db/index.cjs.map +1 -1
  102. package/dist/utils/db/index.js +1 -1
  103. package/dist/utils/db/index.js.map +1 -1
  104. package/dist/utils/helpers/index.cjs.map +1 -1
  105. package/dist/utils/helpers/index.js.map +1 -1
  106. package/dist/utils/init.cjs +1 -1
  107. package/dist/utils/init.cjs.map +1 -1
  108. package/dist/utils/init.js +1 -1
  109. package/dist/utils/init.js.map +1 -1
  110. package/dist/utils/logger/index.cjs +1 -1
  111. package/dist/utils/logger/index.cjs.map +1 -1
  112. package/dist/utils/logger/index.js +1 -1
  113. package/dist/utils/logger/index.js.map +1 -1
  114. package/dist/utils/scopeAttributes.cjs.map +1 -1
  115. package/dist/utils/scopeAttributes.js.map +1 -1
  116. package/dist/utils/validations/index.cjs.map +1 -1
  117. package/dist/utils/validations/index.js.map +1 -1
  118. package/dist/utils/validations/schema/validator-schema.cjs.map +1 -1
  119. package/dist/utils/validations/schema/validator-schema.js.map +1 -1
  120. package/dist/utils/validations/validators/index.cjs.map +1 -1
  121. package/dist/utils/validations/validators/index.js.map +1 -1
  122. package/dist/utils/validations/validators/select.validator.cjs.map +1 -1
  123. package/dist/utils/validations/validators/select.validator.js.map +1 -1
  124. package/dist/utils/validations/validators/status.validator.cjs.map +1 -1
  125. package/dist/utils/validations/validators/status.validator.js.map +1 -1
  126. package/package.json +2 -16
  127. /package/dist/_virtual/{_@oxc-project_runtime@0.89.0 → _@oxc-project_runtime@0.94.0}/helpers/decorate.cjs +0 -0
  128. /package/dist/_virtual/{_@oxc-project_runtime@0.89.0 → _@oxc-project_runtime@0.94.0}/helpers/decorate.js +0 -0
  129. /package/dist/_virtual/{_@oxc-project_runtime@0.89.0 → _@oxc-project_runtime@0.94.0}/helpers/decorateMetadata.cjs +0 -0
  130. /package/dist/_virtual/{_@oxc-project_runtime@0.89.0 → _@oxc-project_runtime@0.94.0}/helpers/decorateMetadata.js +0 -0
@@ -1,10 +1,10 @@
1
1
  import { IncludeOptions } from "sequelize";
2
- import { ModelCtor, Sequelize } from "sequelize-typescript";
3
2
  import { getUser } from "@autofleet/zehut";
3
+ import { ModelCtor, Sequelize } from "sequelize-typescript";
4
4
 
5
5
  //#region src/types/index.d.ts
6
6
  type ModelFetcher = (name: string) => any;
7
- type ModelOptions = {
7
+ interface ModelOptions {
8
8
  /**
9
9
  * Include options for the model
10
10
  */
@@ -22,23 +22,23 @@ type ModelOptions = {
22
22
  * Which attributes to include in the model
23
23
  */
24
24
  attributes?: string[];
25
- };
26
- type Models = {
25
+ }
26
+ interface Models {
27
27
  name: string;
28
28
  scopeAttributes: any[];
29
29
  modelOptions?: ModelOptions;
30
30
  creationWebhookHandler?: (instance: any) => any;
31
31
  updateWebhookHandler?: (instance: any) => any;
32
32
  deletionWebhookHandler?: (instance: any) => any;
33
- };
34
- type CustomFieldOptions = {
33
+ }
34
+ interface CustomFieldOptions {
35
35
  models: Models[];
36
36
  databaseConfig: any;
37
37
  getUser: typeof getUser;
38
38
  sequelize?: Sequelize;
39
39
  useCustomFieldsEntries?: boolean;
40
40
  useValidators?: boolean;
41
- };
41
+ }
42
42
  //#endregion
43
43
  export { CustomFieldOptions, ModelFetcher, Models };
44
44
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["CUSTOM_FIELDS_FILTER_SCOPE: typeof customFields.CUSTOM_FIELDS_FILTER_SCOPE","customFields"],"sources":["../../../src/utils/constants/index.ts"],"sourcesContent":["import { customFields } from '@autofleet/common-types';\n\nexport const supportedEntities = ['businessModelId', 'fleetId', 'demandSourceId'] as const;\n\n/**\n * Supported custom field types\n */\nexport enum CustomFieldDefinitionType {\n NUMBER = 'number',\n BOOLEAN = 'boolean',\n DATE = 'date',\n DATETIME = 'datetime',\n TEXT = 'text',\n IMAGE = 'image',\n SELECT = 'select',\n STATUS = 'status',\n FILE = 'file',\n}\n\n// eslint-disable-next-line prefer-destructuring\nconst CUSTOM_FIELDS_FILTER_SCOPE: typeof customFields.CUSTOM_FIELDS_FILTER_SCOPE = customFields.CUSTOM_FIELDS_FILTER_SCOPE;\n\nexport {\n /** @deprecated Use the value from `@autofleet/common-types` instead */\n CUSTOM_FIELDS_FILTER_SCOPE,\n};\n"],"mappings":"+GAEA,MAAa,EAAoB,CAAC,kBAAmB,UAAW,iBAAiB,CAKjF,IAAY,EAAA,SAAA,EAAL,OACL,GAAA,OAAA,SACA,EAAA,QAAA,UACA,EAAA,KAAA,OACA,EAAA,SAAA,WACA,EAAA,KAAA,OACA,EAAA,MAAA,QACA,EAAA,OAAA,SACA,EAAA,OAAA,SACA,EAAA,KAAA,cAIF,MAAMA,EAA6EC,EAAAA,aAAa"}
1
+ {"version":3,"file":"index.cjs","names":["CUSTOM_FIELDS_FILTER_SCOPE: typeof customFields.CUSTOM_FIELDS_FILTER_SCOPE","customFields"],"sources":["../../../src/utils/constants/index.ts"],"sourcesContent":["import { customFields } from '@autofleet/common-types';\n\nexport const supportedEntities = ['businessModelId', 'fleetId', 'demandSourceId'] as const;\n\n/**\n * Supported custom field types\n */\nexport enum CustomFieldDefinitionType {\n NUMBER = 'number',\n BOOLEAN = 'boolean',\n DATE = 'date',\n DATETIME = 'datetime',\n TEXT = 'text',\n IMAGE = 'image',\n SELECT = 'select',\n STATUS = 'status',\n FILE = 'file',\n}\n\nconst CUSTOM_FIELDS_FILTER_SCOPE: typeof customFields.CUSTOM_FIELDS_FILTER_SCOPE = customFields.CUSTOM_FIELDS_FILTER_SCOPE;\n\nexport {\n /** @deprecated Use the value from `@autofleet/common-types` instead */\n CUSTOM_FIELDS_FILTER_SCOPE,\n};\n"],"mappings":"+GAEA,MAAa,EAAoB,CAAC,kBAAmB,UAAW,iBAAiB,CAKjF,IAAY,EAAA,SAAA,EAAL,OACL,GAAA,OAAA,SACA,EAAA,QAAA,UACA,EAAA,KAAA,OACA,EAAA,SAAA,WACA,EAAA,KAAA,OACA,EAAA,MAAA,QACA,EAAA,OAAA,SACA,EAAA,OAAA,SACA,EAAA,KAAA,cAGF,MAAMA,EAA6EC,EAAAA,aAAa"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["CUSTOM_FIELDS_FILTER_SCOPE: typeof customFields.CUSTOM_FIELDS_FILTER_SCOPE"],"sources":["../../../src/utils/constants/index.ts"],"sourcesContent":["import { customFields } from '@autofleet/common-types';\n\nexport const supportedEntities = ['businessModelId', 'fleetId', 'demandSourceId'] as const;\n\n/**\n * Supported custom field types\n */\nexport enum CustomFieldDefinitionType {\n NUMBER = 'number',\n BOOLEAN = 'boolean',\n DATE = 'date',\n DATETIME = 'datetime',\n TEXT = 'text',\n IMAGE = 'image',\n SELECT = 'select',\n STATUS = 'status',\n FILE = 'file',\n}\n\n// eslint-disable-next-line prefer-destructuring\nconst CUSTOM_FIELDS_FILTER_SCOPE: typeof customFields.CUSTOM_FIELDS_FILTER_SCOPE = customFields.CUSTOM_FIELDS_FILTER_SCOPE;\n\nexport {\n /** @deprecated Use the value from `@autofleet/common-types` instead */\n CUSTOM_FIELDS_FILTER_SCOPE,\n};\n"],"mappings":"uDAEA,MAAa,EAAoB,CAAC,kBAAmB,UAAW,iBAAiB,CAKjF,IAAY,EAAA,SAAA,EAAL,OACL,GAAA,OAAA,SACA,EAAA,QAAA,UACA,EAAA,KAAA,OACA,EAAA,SAAA,WACA,EAAA,KAAA,OACA,EAAA,MAAA,QACA,EAAA,OAAA,SACA,EAAA,OAAA,SACA,EAAA,KAAA,cAIF,MAAMA,EAA6E,EAAa"}
1
+ {"version":3,"file":"index.js","names":["CUSTOM_FIELDS_FILTER_SCOPE: typeof customFields.CUSTOM_FIELDS_FILTER_SCOPE"],"sources":["../../../src/utils/constants/index.ts"],"sourcesContent":["import { customFields } from '@autofleet/common-types';\n\nexport const supportedEntities = ['businessModelId', 'fleetId', 'demandSourceId'] as const;\n\n/**\n * Supported custom field types\n */\nexport enum CustomFieldDefinitionType {\n NUMBER = 'number',\n BOOLEAN = 'boolean',\n DATE = 'date',\n DATETIME = 'datetime',\n TEXT = 'text',\n IMAGE = 'image',\n SELECT = 'select',\n STATUS = 'status',\n FILE = 'file',\n}\n\nconst CUSTOM_FIELDS_FILTER_SCOPE: typeof customFields.CUSTOM_FIELDS_FILTER_SCOPE = customFields.CUSTOM_FIELDS_FILTER_SCOPE;\n\nexport {\n /** @deprecated Use the value from `@autofleet/common-types` instead */\n CUSTOM_FIELDS_FILTER_SCOPE,\n};\n"],"mappings":"uDAEA,MAAa,EAAoB,CAAC,kBAAmB,UAAW,iBAAiB,CAKjF,IAAY,EAAA,SAAA,EAAL,OACL,GAAA,OAAA,SACA,EAAA,QAAA,UACA,EAAA,KAAA,OACA,EAAA,SAAA,WACA,EAAA,KAAA,OACA,EAAA,MAAA,QACA,EAAA,OAAA,SACA,EAAA,OAAA,SACA,EAAA,KAAA,cAGF,MAAMA,EAA6E,EAAa"}
@@ -1,2 +1,2 @@
1
- const e=require(`../../_virtual/rolldown_runtime.cjs`);let t=require(`sequelize`);t=e.__toESM(t);let n=require(`sequelize-typescript`);n=e.__toESM(n);var r=e=>{let t=process.env.NODE_ENV||`test`,r=e[t],i;return i=r.use_env_variable?new n.Sequelize(process.env[r.use_env_variable],r):new n.Sequelize(r.database,r.username,r.password,r),i};exports.default=r;
1
+ const e=require(`../../_virtual/rolldown_runtime.cjs`);let t=require(`sequelize`);t=e.__toESM(t);let n=require(`sequelize-typescript`);n=e.__toESM(n);var r=e=>{let t=e[process.env.NODE_ENV||`test`],r;return r=t.use_env_variable?new n.Sequelize(process.env[t.use_env_variable],t):new n.Sequelize(t.database,t.username,t.password,t),r};exports.default=r;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["env: string","sequelize: Sequelize","Sequelize","sequelize"],"sources":["../../../src/utils/db/index.ts"],"sourcesContent":["import { Sequelize } from 'sequelize-typescript';\nimport { QueryTypes } from 'sequelize';\n\nexport default (databaseConfig: any): Sequelize => {\n const ENV_DEV = 'test';\n const env: string = process.env.NODE_ENV || ENV_DEV;\n const config = databaseConfig[env];\n let sequelize: Sequelize;\n if (config.use_env_variable) {\n sequelize = new Sequelize(process.env[config.use_env_variable], config);\n } else {\n sequelize = new Sequelize(config.database, config.username, config.password, config);\n }\n return sequelize;\n};\n\nexport const createSequelizeMeta = (sequelize: Sequelize): Promise<{ name: string; }[]> => sequelize.query(`\nCREATE TABLE IF NOT EXISTS \"SequelizeMeta\" (\n name character varying(255) PRIMARY KEY\n);\n`, { type: QueryTypes.SELECT });\n"],"mappings":"sJAGA,IAAA,EAAgB,GAAmC,CAEjD,IAAMA,EAAc,QAAQ,IAAI,UADhB,OAEV,EAAS,EAAe,GAC1BC,EAMJ,MALA,CAGE,EAHE,EAAO,iBACG,IAAIC,EAAAA,UAAU,QAAQ,IAAI,EAAO,kBAAmB,EAAO,CAE3D,IAAIA,EAAAA,UAAU,EAAO,SAAU,EAAO,SAAU,EAAO,SAAU,EAAO,CAE/EC"}
1
+ {"version":3,"file":"index.cjs","names":["sequelize: Sequelize","Sequelize","sequelize"],"sources":["../../../src/utils/db/index.ts"],"sourcesContent":["import { Sequelize } from 'sequelize-typescript';\nimport { QueryTypes } from 'sequelize';\n\nexport default (databaseConfig: any): Sequelize => {\n const ENV_DEV = 'test';\n const env: string = process.env.NODE_ENV || ENV_DEV;\n const config = databaseConfig[env];\n let sequelize: Sequelize;\n if (config.use_env_variable) {\n sequelize = new Sequelize(process.env[config.use_env_variable]!, config);\n } else {\n sequelize = new Sequelize(config.database, config.username, config.password, config);\n }\n return sequelize;\n};\n\nexport const createSequelizeMeta = (sequelize: Sequelize): Promise<{ name: string; }[]> => sequelize.query(`\nCREATE TABLE IF NOT EXISTS \"SequelizeMeta\" (\n name character varying(255) PRIMARY KEY\n);\n`, { type: QueryTypes.SELECT });\n"],"mappings":"sJAGA,IAAA,EAAgB,GAAmC,CAGjD,IAAM,EAAS,EADK,QAAQ,IAAI,UADhB,QAGZA,EAMJ,MALA,CAGE,EAHE,EAAO,iBACG,IAAIC,EAAAA,UAAU,QAAQ,IAAI,EAAO,kBAAoB,EAAO,CAE5D,IAAIA,EAAAA,UAAU,EAAO,SAAU,EAAO,SAAU,EAAO,SAAU,EAAO,CAE/EC"}
@@ -1,2 +1,2 @@
1
- import"sequelize";import{Sequelize as e}from"sequelize-typescript";var t=t=>{let n=process.env.NODE_ENV||`test`,r=t[n],i;return i=r.use_env_variable?new e(process.env[r.use_env_variable],r):new e(r.database,r.username,r.password,r),i};export{t as default};
1
+ import"sequelize";import{Sequelize as e}from"sequelize-typescript";var t=t=>{let n=t[process.env.NODE_ENV||`test`],r;return r=n.use_env_variable?new e(process.env[n.use_env_variable],n):new e(n.database,n.username,n.password,n),r};export{t as default};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
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
+ {"version":3,"file":"index.js","names":["sequelize: Sequelize"],"sources":["../../../src/utils/db/index.ts"],"sourcesContent":["import { Sequelize } from 'sequelize-typescript';\nimport { QueryTypes } from 'sequelize';\n\nexport default (databaseConfig: any): Sequelize => {\n const ENV_DEV = 'test';\n const env: string = process.env.NODE_ENV || ENV_DEV;\n const config = databaseConfig[env];\n let sequelize: Sequelize;\n if (config.use_env_variable) {\n sequelize = new Sequelize(process.env[config.use_env_variable]!, config);\n } else {\n sequelize = new Sequelize(config.database, config.username, config.password, config);\n }\n return sequelize;\n};\n\nexport const createSequelizeMeta = (sequelize: Sequelize): Promise<{ name: string; }[]> => sequelize.query(`\nCREATE TABLE IF NOT EXISTS \"SequelizeMeta\" (\n name character varying(255) PRIMARY KEY\n);\n`, { type: QueryTypes.SELECT });\n"],"mappings":"mEAGA,IAAA,EAAgB,GAAmC,CAGjD,IAAM,EAAS,EADK,QAAQ,IAAI,UADhB,QAGZA,EAMJ,MALA,CAGE,EAHE,EAAO,iBACG,IAAI,EAAU,QAAQ,IAAI,EAAO,kBAAoB,EAAO,CAE5D,IAAI,EAAU,EAAO,SAAU,EAAO,SAAU,EAAO,SAAU,EAAO,CAE/E"}
@@ -1 +1 @@
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
+ {"version":3,"file":"index.cjs","names":["CustomFieldDefinitionType","Op","Sequelize"],"sources":["../../../src/utils/helpers/index.ts"],"sourcesContent":["import { type WhereOptions, Op, type BindOrReplacements } from 'sequelize';\nimport { type ModelStatic, Sequelize } from 'sequelize-typescript';\nimport { randomInt } from 'node:crypto';\nimport { CustomFieldDefinitionType } from '../constants';\n\n/**\n * Builds a WHERE clause and replacements for free-text search by custom fields.\n *\n * This function constructs a WHERE clause and replacement bindings that allow searching\n * for a given term within custom fields associated with a specific model type and entity ID.\n * The WHERE clause and replacements are designed to be added to the main query.\n *\n * @param {string} searchTerm - The term to search for within custom fields.\n * @param {ModelStatic} model - The Sequelize model representing the entity type to search for.\n * @param {string} entityId - The entity ID to filter the custom fields by.\n * @param {CustomFieldDefinitionType[]} excludedCustomFieldsTypes - An array of custom field types\n * to exclude from the search\n *\n * @returns {CustomFieldsSearchPayload} - An object containing the WHERE clause and replacements\n * for Sequelize.\n */\n\ninterface CustomFieldsSearchPayload {\n where: WhereOptions;\n replacements: BindOrReplacements;\n}\n\nexport const generateRandomString = (length = 5): string => {\n const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';\n return Array.from({ length }, () => characters.charAt(randomInt(characters.length))).join('');\n};\n\nexport const generateCustomFieldSearchQueryPayload = (\n searchTerm: string,\n model: ModelStatic,\n entityId: string,\n customFieldsTypesToExclude: CustomFieldDefinitionType[] = [\n CustomFieldDefinitionType.DATETIME,\n CustomFieldDefinitionType.DATE,\n ],\n): CustomFieldsSearchPayload => {\n const excludedTypesString = customFieldsTypesToExclude.map(type => `'${type}'`).join(',');\n\n const subQuery = 'EXISTS ('\n + ' SELECT 1'\n + ' FROM \"custom_field_values\" AS \"cv\"'\n + ' INNER JOIN custom_field_definitions AS cd '\n + ` ON cd.entity_id = '${entityId}'`\n + ' AND cv.custom_field_definition_id = cd.id'\n + ` AND cd.model_type = '${model.name}'`\n + ` ${excludedTypesString ? `AND cd.field_type NOT IN (${excludedTypesString})` : ''}`\n + ' WHERE'\n + ' \"cv\".\"deleted_at\" IS NULL'\n + ` AND \"cv\".\"model_id\" = \"${model.name}\".\"id\"`\n + ' AND CAST(\"cv\".\"value\" AS TEXT) ILIKE :searchTerm)';\n\n return {\n where: {\n [Op.or]: [\n Sequelize.where(Sequelize.literal(subQuery), true),\n ],\n },\n replacements: { searchTerm: `%${searchTerm}%` },\n };\n};\n"],"mappings":"sOA2BA,MAAa,GAAwB,EAAS,IAErC,MAAM,KAAK,CAAE,SAAQ,KAAQ,uDAAW,QAAA,EAAA,EAAA,WAAiB,GAAkB,CAAC,CAAC,CAAC,KAAK,GAAG,CAGlF,GACX,EACA,EACA,EACA,EAA0D,CACxDA,EAAAA,0BAA0B,SAC1BA,EAAAA,0BAA0B,KAC3B,GAC6B,CAC9B,IAAM,EAAsB,EAA2B,IAAI,GAAQ,IAAI,EAAK,GAAG,CAAC,KAAK,IAAI,CAEnF,EAAW,sHAIU,EAAS,mEAEP,EAAM,KAAK,IAChC,EAAsB,6BAA6B,EAAoB,GAAK,GAAA,0DAGrD,EAAM,KAAK,0DAG1C,MAAO,CACL,MAAO,EACJC,EAAAA,GAAG,IAAK,CACPC,EAAAA,UAAU,MAAMA,EAAAA,UAAU,QAAQ,EAAS,CAAE,GAAK,CACnD,CACF,CACD,aAAc,CAAE,WAAY,IAAI,EAAW,GAAI,CAChD"}
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/utils/helpers/index.ts"],"sourcesContent":["import { type WhereOptions, Op, type BindOrReplacements } from 'sequelize';\nimport { type ModelStatic, Sequelize } from 'sequelize-typescript';\nimport { randomInt } from 'node:crypto';\nimport { CustomFieldDefinitionType } from '../constants';\n\n/**\n * Builds a WHERE clause and replacements for free-text search by custom fields.\n *\n * This function constructs a WHERE clause and replacement bindings that allow searching\n * for a given term within custom fields associated with a specific model type and entity ID.\n * The WHERE clause and replacements are designed to be added to the main query.\n *\n * @param {string} searchTerm - The term to search for within custom fields.\n * @param {ModelStatic} model - The Sequelize model representing the entity type to search for.\n * @param {string} entityId - The entity ID to filter the custom fields by.\n * @param {CustomFieldDefinitionType[]} excludedCustomFieldsTypes - An array of custom field types\n * to exclude from the search\n *\n * @returns {CustomFieldsSearchPayload} - An object containing the WHERE clause and replacements\n * for Sequelize.\n */\n\ninterface CustomFieldsSearchPayload {\n where: WhereOptions;\n replacements: BindOrReplacements;\n}\n\nexport const generateRandomString = (length = 5): string => {\n const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';\n return Array.from({ length }, () => characters.charAt(randomInt(characters.length))).join('');\n};\n\nexport const generateCustomFieldSearchQueryPayload = (\n searchTerm: string,\n model: ModelStatic,\n entityId: string,\n customFieldsTypesToExclude: CustomFieldDefinitionType[] = [\n CustomFieldDefinitionType.DATETIME,\n CustomFieldDefinitionType.DATE,\n ],\n): CustomFieldsSearchPayload => {\n const excludedTypesString = customFieldsTypesToExclude.map(type => `'${type}'`).join(',');\n\n const subQuery = 'EXISTS ('\n + ' SELECT 1'\n + ' FROM \"custom_field_values\" AS \"cv\"'\n + ' INNER JOIN custom_field_definitions AS cd '\n + ` ON cd.entity_id = '${entityId}'`\n + ' AND cv.custom_field_definition_id = cd.id'\n + ` AND cd.model_type = '${model.name}'`\n + ` ${excludedTypesString ? `AND cd.field_type NOT IN (${excludedTypesString})` : ''}`\n + ' WHERE'\n + ' \"cv\".\"deleted_at\" IS NULL'\n + ` AND \"cv\".\"model_id\" = \"${model.name}\".\"id\"`\n + ' AND CAST(\"cv\".\"value\" AS TEXT) ILIKE :searchTerm)';\n\n return {\n where: {\n [Op.or]: [\n Sequelize.where(Sequelize.literal(subQuery), true),\n ],\n },\n replacements: { searchTerm: `%${searchTerm}%` },\n };\n};\n"],"mappings":"0LA2BA,MAAa,GAAwB,EAAS,IAErC,MAAM,KAAK,CAAE,SAAQ,KAAQ,uDAAW,OAAO,EAAU,GAAkB,CAAC,CAAC,CAAC,KAAK,GAAG,CAGlF,GACX,EACA,EACA,EACA,EAA0D,CACxD,EAA0B,SAC1B,EAA0B,KAC3B,GAC6B,CAC9B,IAAM,EAAsB,EAA2B,IAAI,GAAQ,IAAI,EAAK,GAAG,CAAC,KAAK,IAAI,CAEnF,EAAW,sHAIU,EAAS,mEAEP,EAAM,KAAK,IAChC,EAAsB,6BAA6B,EAAoB,GAAK,GAAA,0DAGrD,EAAM,KAAK,0DAG1C,MAAO,CACL,MAAO,EACJ,EAAG,IAAK,CACP,EAAU,MAAM,EAAU,QAAQ,EAAS,CAAE,GAAK,CACnD,CACF,CACD,aAAc,CAAE,WAAY,IAAI,EAAW,GAAI,CAChD"}
@@ -1,2 +1,2 @@
1
- const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`./logger/index.cjs`),n=require(`../models/CustomFieldDefinition.cjs`),r=require(`../models/CustomFieldValue.cjs`),i=require(`../models/CustomValidator.cjs`);require(`../models/index.cjs`);const a=require(`../hooks/enrich.cjs`),o=require(`../hooks/find.cjs`),s=require(`../hooks/hooks.cjs`);require(`../hooks/index.cjs`);const c=require(`../scopes/filter.cjs`);require(`../scopes/index.cjs`);let l=require(`sequelize`);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;
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,void 0,c,r)),u.addHook(`afterCreate`,`sadot-afterCreate`,a.default(e,i,void 0,c,r))}catch(n){t.default.error(`Could not add custom fields hook to model ${e}. `,n)}})},m=(e,n)=>{e.forEach(async({name:e})=>{try{let t=n(e);if(!t)return;t.rawAttributes.customFields&&(delete t.rawAttributes.customFields,t.refreshAttributes()),t.removeHook(`beforeFind`,`sadot-beforeFind`),t.removeHook(`beforeBulkCreate`,`sadot-beforeBulkCreate`),t.removeHook(`beforeBulkUpdate`,`sadot-beforeBulkUpdate`),t.removeHook(`beforeCreate`,`sadot-beforeCreate`),t.removeHook(`beforeUpdate`,`sadot-beforeUpdate`),t.removeHook(`afterFind`,`sadot-afterFind`),t.removeHook(`afterUpdate`,`sadot-afterUpdate`)}catch(n){t.default.error(`Could not add custom fields hook to model ${e}. `,n)}})},h=(e,t,n)=>{n?.useCustomFieldsEntries||(e.hasMany(r.default,{foreignKey:`modelId`,as:`customFieldValue`}),r.default.belongsTo(e,{foreignKey:`modelId`,as:t}))},g=(e,n,r={useCustomFieldsEntries:!1})=>{e.forEach(async({name:e,scopeAttributes:i})=>{try{let a=n(e);if(!a){t.default.warn(`sadot - tried to addScopes to a model that does not exist yet`,{name:e,scopeAttributes:i});return}h(a,e,r),a.addScope(f,c.customFieldsFilterScope(e,r)),a.addScope(d.CUSTOM_FIELDS_SORT_SCOPE,c.customFieldsSortScope(e,r))}catch(n){t.default.error(`Could not add custom fields scopes to model ${e}. `,n)}})},_=e=>{e.forEach(({modelOptions:e})=>{e?.customAssociation?.(n.default),e?.customAssociation?.(i.default)})};exports.addHooks=p,exports.addScopes=g,exports.applyCustomAssociation=_,exports.removeHooks=m;
2
2
  //# sourceMappingURL=init.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"init.cjs","names":["customFields","DataTypes","beforeFind","beforeBulkCreate","beforeBulkUpdate","beforeCreate","beforeUpdate","enrichResults","CustomFieldValue","customFieldsFilterScope","CUSTOM_FIELDS_SORT_SCOPE","customFieldsSortScope","CustomFieldDefinition","CustomValidator"],"sources":["../../src/utils/init.ts"],"sourcesContent":["import { DataTypes } from 'sequelize';\nimport type { ModelCtor } from 'sequelize-typescript';\nimport { customFields } from '@autofleet/common-types';\nimport { CUSTOM_FIELDS_SORT_SCOPE } from '@autofleet/common-types/lib/custom-fields';\nimport {\n CustomFieldDefinition,\n CustomFieldValue,\n CustomValidator,\n} from '../models';\nimport {\n beforeFind,\n enrichResults,\n beforeBulkUpdate,\n beforeUpdate,\n beforeCreate,\n beforeBulkCreate,\n} from '../hooks';\nimport { customFieldsFilterScope } from '../scopes';\nimport logger from './logger';\nimport type { CustomFieldOptions, ModelFetcher, Models } from '../types';\nimport { customFieldsSortScope } from '../scopes/filter';\n\nconst { CUSTOM_FIELDS_FILTER_SCOPE } = customFields;\n\nexport const addHooks = (\n models: Models[],\n getModel: ModelFetcher,\n sadotOptions: { useCustomFieldsEntries: boolean } = { useCustomFieldsEntries: false },\n): void => {\n models.forEach(async ({\n name, scopeAttributes, modelOptions,\n }) => {\n try {\n const model = getModel(name);\n if (!model) {\n logger.warn('sadot - tried to addHooks to a model that does not exist yet', {\n name,\n scopeAttributes,\n });\n return;\n }\n model.rawAttributes.customFields = {\n type: DataTypes.VIRTUAL,\n };\n model.refreshAttributes();\n // TODO: Uncomment after tests are passed\n // model.addHook('afterFind', workaround);\n model.addHook('beforeFind', 'sadot-beforeFind', beforeFind(scopeAttributes));\n model.addHook('beforeBulkCreate', 'sadot-beforeBulkCreate', beforeBulkCreate);\n model.addHook('beforeBulkUpdate', 'sadot-beforeBulkUpdate', beforeBulkUpdate);\n model.addHook('beforeCreate', 'sadot-beforeCreate', beforeCreate(scopeAttributes, modelOptions, sadotOptions));\n model.addHook('beforeUpdate', 'sadot-beforeUpdate', beforeUpdate(scopeAttributes, modelOptions, sadotOptions));\n model.addHook('afterFind', 'sadot-afterFind', enrichResults(name, scopeAttributes, 'afterFind', modelOptions, sadotOptions));\n model.addHook('afterUpdate', 'sadot-afterUpdate', enrichResults(name, scopeAttributes, 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\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,EAIS,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"}
1
+ {"version":3,"file":"init.cjs","names":["customFields","DataTypes","beforeFind","beforeBulkCreate","beforeBulkUpdate","beforeCreate","beforeUpdate","enrichResults","CustomFieldValue","customFieldsFilterScope","CUSTOM_FIELDS_SORT_SCOPE","customFieldsSortScope","CustomFieldDefinition","CustomValidator"],"sources":["../../src/utils/init.ts"],"sourcesContent":["import { DataTypes } from 'sequelize';\nimport type { ModelCtor } from 'sequelize-typescript';\nimport { customFields } from '@autofleet/common-types';\nimport { CUSTOM_FIELDS_SORT_SCOPE } from '@autofleet/common-types/lib/custom-fields';\nimport {\n CustomFieldDefinition,\n CustomFieldValue,\n CustomValidator,\n} from '../models';\nimport {\n beforeFind,\n enrichResults,\n beforeBulkUpdate,\n beforeUpdate,\n beforeCreate,\n beforeBulkCreate,\n} from '../hooks';\nimport { customFieldsFilterScope } from '../scopes';\nimport logger from './logger';\nimport type { CustomFieldOptions, ModelFetcher, Models } from '../types';\nimport { customFieldsSortScope } from '../scopes/filter';\n\nconst { CUSTOM_FIELDS_FILTER_SCOPE } = customFields;\n\nexport const addHooks = (\n models: Models[],\n getModel: ModelFetcher,\n sadotOptions: { useCustomFieldsEntries?: boolean; } = { useCustomFieldsEntries: false },\n): void => {\n models.forEach(async ({\n name, scopeAttributes, modelOptions,\n }) => {\n try {\n const model = getModel(name);\n if (!model) {\n logger.warn('sadot - tried to addHooks to a model that does not exist yet', {\n name,\n scopeAttributes,\n });\n return;\n }\n model.rawAttributes.customFields = {\n type: DataTypes.VIRTUAL,\n };\n model.refreshAttributes();\n // TODO: Uncomment after tests are passed\n // model.addHook('afterFind', workaround);\n model.addHook('beforeFind', 'sadot-beforeFind', beforeFind(scopeAttributes));\n model.addHook('beforeBulkCreate', 'sadot-beforeBulkCreate', beforeBulkCreate);\n model.addHook('beforeBulkUpdate', 'sadot-beforeBulkUpdate', beforeBulkUpdate);\n model.addHook('beforeCreate', 'sadot-beforeCreate', beforeCreate(scopeAttributes, modelOptions, sadotOptions));\n model.addHook('beforeUpdate', 'sadot-beforeUpdate', beforeUpdate(scopeAttributes, modelOptions, sadotOptions));\n model.addHook('afterFind', 'sadot-afterFind', enrichResults(name, scopeAttributes, 'afterFind', modelOptions, sadotOptions));\n model.addHook('afterUpdate', 'sadot-afterUpdate', enrichResults(name, scopeAttributes, undefined, modelOptions, sadotOptions));\n model.addHook('afterCreate', 'sadot-afterCreate', enrichResults(name, scopeAttributes, undefined, modelOptions, sadotOptions));\n } catch (e) {\n logger.error(`Could not add custom fields hook to model ${name}. `, e);\n }\n });\n};\n\nexport const removeHooks = (models: Models[], getModel: ModelFetcher): void => {\n models.forEach(async ({ name }) => {\n try {\n const model = getModel(name);\n if (!model) return;\n if (model.rawAttributes.customFields) {\n delete model.rawAttributes.customFields;\n model.refreshAttributes();\n }\n // model.removeHook('afterFind', 'sadot-workaround');\n model.removeHook('beforeFind', 'sadot-beforeFind');\n model.removeHook('beforeBulkCreate', 'sadot-beforeBulkCreate');\n model.removeHook('beforeBulkUpdate', 'sadot-beforeBulkUpdate');\n model.removeHook('beforeCreate', 'sadot-beforeCreate');\n model.removeHook('beforeUpdate', 'sadot-beforeUpdate');\n model.removeHook('afterFind', 'sadot-afterFind');\n model.removeHook('afterUpdate', 'sadot-afterUpdate');\n } catch (e) {\n logger.error(`Could not add custom fields hook to model ${name}. `, e);\n }\n });\n};\n\n/**\n * Necessary associations for the {@link customFieldsFilterScope} scope\n */\nconst addAssociations = (model: ModelCtor, modelName: string, options: Pick<CustomFieldOptions, 'useCustomFieldsEntries'>): void => {\n if (options?.useCustomFieldsEntries) return;\n model.hasMany(CustomFieldValue, { foreignKey: 'modelId', as: 'customFieldValue' });\n // TBC: maybe can be removed\n CustomFieldValue.belongsTo(model, { foreignKey: 'modelId', as: modelName });\n};\n\nexport const addScopes = (models: Models[], getModel: ModelFetcher, options: Pick<CustomFieldOptions, 'useCustomFieldsEntries'> = { useCustomFieldsEntries: false }): void => {\n models.forEach(async ({ name, scopeAttributes }) => {\n try {\n const model = getModel(name);\n if (!model) {\n logger.warn('sadot - tried to addScopes to a model that does not exist yet', {\n name,\n scopeAttributes,\n });\n return;\n }\n // Necessary associations for the filtering scope\n addAssociations(model, name, options);\n // Add filter scope\n model.addScope(CUSTOM_FIELDS_FILTER_SCOPE, customFieldsFilterScope(name, options));\n model.addScope(CUSTOM_FIELDS_SORT_SCOPE, customFieldsSortScope(name, options));\n } catch (e) {\n logger.error(`Could not add custom fields scopes to model ${name}. `, e);\n }\n });\n};\n\nexport const applyCustomAssociation = (models: Models[]): void => {\n models.forEach(({ modelOptions }) => {\n modelOptions?.customAssociation?.(CustomFieldDefinition);\n modelOptions?.customAssociation?.(CustomValidator);\n });\n};\n"],"mappings":"knBAsBA,KAAM,CAAE,8BAA+BA,EAAAA,aAE1B,GACX,EACA,EACA,EAAsD,CAAE,uBAAwB,GAAO,GAC9E,CACT,EAAO,QAAQ,MAAO,CACpB,OAAM,kBAAiB,kBACnB,CACJ,GAAI,CACF,IAAM,EAAQ,EAAS,EAAK,CAC5B,GAAI,CAAC,EAAO,CACV,EAAA,QAAO,KAAK,+DAAgE,CAC1E,OACA,kBACD,CAAC,CACF,OAEF,EAAM,cAAc,aAAe,CACjC,KAAMC,EAAAA,UAAU,QACjB,CACD,EAAM,mBAAmB,CAGzB,EAAM,QAAQ,aAAc,mBAAoBC,EAAAA,WAAW,EAAgB,CAAC,CAC5E,EAAM,QAAQ,mBAAoB,yBAA0BC,EAAAA,iBAAiB,CAC7E,EAAM,QAAQ,mBAAoB,yBAA0BC,EAAAA,iBAAiB,CAC7E,EAAM,QAAQ,eAAgB,qBAAsBC,EAAAA,aAAa,EAAiB,EAAc,EAAa,CAAC,CAC9G,EAAM,QAAQ,eAAgB,qBAAsBC,EAAAA,aAAa,EAAiB,EAAc,EAAa,CAAC,CAC9G,EAAM,QAAQ,YAAa,kBAAmBC,EAAAA,QAAc,EAAM,EAAiB,YAAa,EAAc,EAAa,CAAC,CAC5H,EAAM,QAAQ,cAAe,oBAAqBA,EAAAA,QAAc,EAAM,EAAiB,IAAA,GAAW,EAAc,EAAa,CAAC,CAC9H,EAAM,QAAQ,cAAe,oBAAqBA,EAAAA,QAAc,EAAM,EAAiB,IAAA,GAAW,EAAc,EAAa,CAAC,OACvH,EAAG,CACV,EAAA,QAAO,MAAM,6CAA6C,EAAK,IAAK,EAAE,GAExE,EAGS,GAAe,EAAkB,IAAiC,CAC7E,EAAO,QAAQ,MAAO,CAAE,UAAW,CACjC,GAAI,CACF,IAAM,EAAQ,EAAS,EAAK,CAC5B,GAAI,CAAC,EAAO,OACR,EAAM,cAAc,eACtB,OAAO,EAAM,cAAc,aAC3B,EAAM,mBAAmB,EAG3B,EAAM,WAAW,aAAc,mBAAmB,CAClD,EAAM,WAAW,mBAAoB,yBAAyB,CAC9D,EAAM,WAAW,mBAAoB,yBAAyB,CAC9D,EAAM,WAAW,eAAgB,qBAAqB,CACtD,EAAM,WAAW,eAAgB,qBAAqB,CACtD,EAAM,WAAW,YAAa,kBAAkB,CAChD,EAAM,WAAW,cAAe,oBAAoB,OAC7C,EAAG,CACV,EAAA,QAAO,MAAM,6CAA6C,EAAK,IAAK,EAAE,GAExE,EAME,GAAmB,EAAkB,EAAmB,IAAsE,CAC9H,GAAS,yBACb,EAAM,QAAQC,EAAAA,QAAkB,CAAE,WAAY,UAAW,GAAI,mBAAoB,CAAC,CAElF,EAAA,QAAiB,UAAU,EAAO,CAAE,WAAY,UAAW,GAAI,EAAW,CAAC,GAGhE,GAAa,EAAkB,EAAwB,EAA8D,CAAE,uBAAwB,GAAO,GAAW,CAC5K,EAAO,QAAQ,MAAO,CAAE,OAAM,qBAAsB,CAClD,GAAI,CACF,IAAM,EAAQ,EAAS,EAAK,CAC5B,GAAI,CAAC,EAAO,CACV,EAAA,QAAO,KAAK,gEAAiE,CAC3E,OACA,kBACD,CAAC,CACF,OAGF,EAAgB,EAAO,EAAM,EAAQ,CAErC,EAAM,SAAS,EAA4BC,EAAAA,wBAAwB,EAAM,EAAQ,CAAC,CAClF,EAAM,SAASC,EAAAA,yBAA0BC,EAAAA,sBAAsB,EAAM,EAAQ,CAAC,OACvE,EAAG,CACV,EAAA,QAAO,MAAM,+CAA+C,EAAK,IAAK,EAAE,GAE1E,EAGS,EAA0B,GAA2B,CAChE,EAAO,SAAS,CAAE,kBAAmB,CACnC,GAAc,oBAAoBC,EAAAA,QAAsB,CACxD,GAAc,oBAAoBC,EAAAA,QAAgB,EAClD"}
@@ -1,2 +1,2 @@
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};
1
+ import e from"./logger/index.js";import t from"../models/CustomFieldDefinition.js";import n from"../models/CustomFieldValue.js";import r from"../models/CustomValidator.js";import"../models/index.js";import i from"../hooks/enrich.js";import{beforeFind as a}from"../hooks/find.js";import{beforeBulkCreate as o,beforeBulkUpdate as s,beforeCreate as c,beforeUpdate as l}from"../hooks/hooks.js";import"../hooks/index.js";import{customFieldsFilterScope as u,customFieldsSortScope as d}from"../scopes/filter.js";import"../scopes/index.js";import{DataTypes as f}from"sequelize";import{customFields as p}from"@autofleet/common-types";import{CUSTOM_FIELDS_SORT_SCOPE as m}from"@autofleet/common-types/lib/custom-fields";const{CUSTOM_FIELDS_FILTER_SCOPE:h}=p,g=(t,n,r={useCustomFieldsEntries:!1})=>{t.forEach(async({name:t,scopeAttributes:u,modelOptions:d})=>{try{let p=n(t);if(!p){e.warn(`sadot - tried to addHooks to a model that does not exist yet`,{name:t,scopeAttributes:u});return}p.rawAttributes.customFields={type:f.VIRTUAL},p.refreshAttributes(),p.addHook(`beforeFind`,`sadot-beforeFind`,a(u)),p.addHook(`beforeBulkCreate`,`sadot-beforeBulkCreate`,o),p.addHook(`beforeBulkUpdate`,`sadot-beforeBulkUpdate`,s),p.addHook(`beforeCreate`,`sadot-beforeCreate`,c(u,d,r)),p.addHook(`beforeUpdate`,`sadot-beforeUpdate`,l(u,d,r)),p.addHook(`afterFind`,`sadot-afterFind`,i(t,u,`afterFind`,d,r)),p.addHook(`afterUpdate`,`sadot-afterUpdate`,i(t,u,void 0,d,r)),p.addHook(`afterCreate`,`sadot-afterCreate`,i(t,u,void 0,d,r))}catch(n){e.error(`Could not add custom fields hook to model ${t}. `,n)}})},_=(t,n)=>{t.forEach(async({name:t})=>{try{let e=n(t);if(!e)return;e.rawAttributes.customFields&&(delete e.rawAttributes.customFields,e.refreshAttributes()),e.removeHook(`beforeFind`,`sadot-beforeFind`),e.removeHook(`beforeBulkCreate`,`sadot-beforeBulkCreate`),e.removeHook(`beforeBulkUpdate`,`sadot-beforeBulkUpdate`),e.removeHook(`beforeCreate`,`sadot-beforeCreate`),e.removeHook(`beforeUpdate`,`sadot-beforeUpdate`),e.removeHook(`afterFind`,`sadot-afterFind`),e.removeHook(`afterUpdate`,`sadot-afterUpdate`)}catch(n){e.error(`Could not add custom fields hook to model ${t}. `,n)}})},v=(e,t,r)=>{r?.useCustomFieldsEntries||(e.hasMany(n,{foreignKey:`modelId`,as:`customFieldValue`}),n.belongsTo(e,{foreignKey:`modelId`,as:t}))},y=(t,n,r={useCustomFieldsEntries:!1})=>{t.forEach(async({name:t,scopeAttributes:i})=>{try{let a=n(t);if(!a){e.warn(`sadot - tried to addScopes to a model that does not exist yet`,{name:t,scopeAttributes:i});return}v(a,t,r),a.addScope(h,u(t,r)),a.addScope(m,d(t,r))}catch(n){e.error(`Could not add custom fields scopes to model ${t}. `,n)}})},b=e=>{e.forEach(({modelOptions:e})=>{e?.customAssociation?.(t),e?.customAssociation?.(r)})};export{g as addHooks,y as addScopes,b as applyCustomAssociation,_ as removeHooks};
2
2
  //# sourceMappingURL=init.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"init.js","names":["enrichResults","CustomFieldValue","CustomFieldDefinition","CustomValidator"],"sources":["../../src/utils/init.ts"],"sourcesContent":["import { DataTypes } from 'sequelize';\nimport type { ModelCtor } from 'sequelize-typescript';\nimport { customFields } from '@autofleet/common-types';\nimport { CUSTOM_FIELDS_SORT_SCOPE } from '@autofleet/common-types/lib/custom-fields';\nimport {\n CustomFieldDefinition,\n CustomFieldValue,\n CustomValidator,\n} from '../models';\nimport {\n beforeFind,\n enrichResults,\n beforeBulkUpdate,\n beforeUpdate,\n beforeCreate,\n beforeBulkCreate,\n} from '../hooks';\nimport { customFieldsFilterScope } from '../scopes';\nimport logger from './logger';\nimport type { CustomFieldOptions, ModelFetcher, Models } from '../types';\nimport { customFieldsSortScope } from '../scopes/filter';\n\nconst { CUSTOM_FIELDS_FILTER_SCOPE } = customFields;\n\nexport const addHooks = (\n models: Models[],\n getModel: ModelFetcher,\n sadotOptions: { useCustomFieldsEntries: boolean } = { useCustomFieldsEntries: false },\n): void => {\n models.forEach(async ({\n name, scopeAttributes, modelOptions,\n }) => {\n try {\n const model = getModel(name);\n if (!model) {\n logger.warn('sadot - tried to addHooks to a model that does not exist yet', {\n name,\n scopeAttributes,\n });\n return;\n }\n model.rawAttributes.customFields = {\n type: DataTypes.VIRTUAL,\n };\n model.refreshAttributes();\n // TODO: Uncomment after tests are passed\n // model.addHook('afterFind', workaround);\n model.addHook('beforeFind', 'sadot-beforeFind', beforeFind(scopeAttributes));\n model.addHook('beforeBulkCreate', 'sadot-beforeBulkCreate', beforeBulkCreate);\n model.addHook('beforeBulkUpdate', 'sadot-beforeBulkUpdate', beforeBulkUpdate);\n model.addHook('beforeCreate', 'sadot-beforeCreate', beforeCreate(scopeAttributes, modelOptions, sadotOptions));\n model.addHook('beforeUpdate', 'sadot-beforeUpdate', beforeUpdate(scopeAttributes, modelOptions, sadotOptions));\n model.addHook('afterFind', 'sadot-afterFind', enrichResults(name, scopeAttributes, 'afterFind', modelOptions, sadotOptions));\n model.addHook('afterUpdate', 'sadot-afterUpdate', enrichResults(name, scopeAttributes, 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\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,EAIS,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
+ {"version":3,"file":"init.js","names":["enrichResults","CustomFieldValue","CustomFieldDefinition","CustomValidator"],"sources":["../../src/utils/init.ts"],"sourcesContent":["import { DataTypes } from 'sequelize';\nimport type { ModelCtor } from 'sequelize-typescript';\nimport { customFields } from '@autofleet/common-types';\nimport { CUSTOM_FIELDS_SORT_SCOPE } from '@autofleet/common-types/lib/custom-fields';\nimport {\n CustomFieldDefinition,\n CustomFieldValue,\n CustomValidator,\n} from '../models';\nimport {\n beforeFind,\n enrichResults,\n beforeBulkUpdate,\n beforeUpdate,\n beforeCreate,\n beforeBulkCreate,\n} from '../hooks';\nimport { customFieldsFilterScope } from '../scopes';\nimport logger from './logger';\nimport type { CustomFieldOptions, ModelFetcher, Models } from '../types';\nimport { customFieldsSortScope } from '../scopes/filter';\n\nconst { CUSTOM_FIELDS_FILTER_SCOPE } = customFields;\n\nexport const addHooks = (\n models: Models[],\n getModel: ModelFetcher,\n sadotOptions: { useCustomFieldsEntries?: boolean; } = { useCustomFieldsEntries: false },\n): void => {\n models.forEach(async ({\n name, scopeAttributes, modelOptions,\n }) => {\n try {\n const model = getModel(name);\n if (!model) {\n logger.warn('sadot - tried to addHooks to a model that does not exist yet', {\n name,\n scopeAttributes,\n });\n return;\n }\n model.rawAttributes.customFields = {\n type: DataTypes.VIRTUAL,\n };\n model.refreshAttributes();\n // TODO: Uncomment after tests are passed\n // model.addHook('afterFind', workaround);\n model.addHook('beforeFind', 'sadot-beforeFind', beforeFind(scopeAttributes));\n model.addHook('beforeBulkCreate', 'sadot-beforeBulkCreate', beforeBulkCreate);\n model.addHook('beforeBulkUpdate', 'sadot-beforeBulkUpdate', beforeBulkUpdate);\n model.addHook('beforeCreate', 'sadot-beforeCreate', beforeCreate(scopeAttributes, modelOptions, sadotOptions));\n model.addHook('beforeUpdate', 'sadot-beforeUpdate', beforeUpdate(scopeAttributes, modelOptions, sadotOptions));\n model.addHook('afterFind', 'sadot-afterFind', enrichResults(name, scopeAttributes, 'afterFind', modelOptions, sadotOptions));\n model.addHook('afterUpdate', 'sadot-afterUpdate', enrichResults(name, scopeAttributes, undefined, modelOptions, sadotOptions));\n model.addHook('afterCreate', 'sadot-afterCreate', enrichResults(name, scopeAttributes, undefined, modelOptions, sadotOptions));\n } catch (e) {\n logger.error(`Could not add custom fields hook to model ${name}. `, e);\n }\n });\n};\n\nexport const removeHooks = (models: Models[], getModel: ModelFetcher): void => {\n models.forEach(async ({ name }) => {\n try {\n const model = getModel(name);\n if (!model) return;\n if (model.rawAttributes.customFields) {\n delete model.rawAttributes.customFields;\n model.refreshAttributes();\n }\n // model.removeHook('afterFind', 'sadot-workaround');\n model.removeHook('beforeFind', 'sadot-beforeFind');\n model.removeHook('beforeBulkCreate', 'sadot-beforeBulkCreate');\n model.removeHook('beforeBulkUpdate', 'sadot-beforeBulkUpdate');\n model.removeHook('beforeCreate', 'sadot-beforeCreate');\n model.removeHook('beforeUpdate', 'sadot-beforeUpdate');\n model.removeHook('afterFind', 'sadot-afterFind');\n model.removeHook('afterUpdate', 'sadot-afterUpdate');\n } catch (e) {\n logger.error(`Could not add custom fields hook to model ${name}. `, e);\n }\n });\n};\n\n/**\n * Necessary associations for the {@link customFieldsFilterScope} scope\n */\nconst addAssociations = (model: ModelCtor, modelName: string, options: Pick<CustomFieldOptions, 'useCustomFieldsEntries'>): void => {\n if (options?.useCustomFieldsEntries) return;\n model.hasMany(CustomFieldValue, { foreignKey: 'modelId', as: 'customFieldValue' });\n // TBC: maybe can be removed\n CustomFieldValue.belongsTo(model, { foreignKey: 'modelId', as: modelName });\n};\n\nexport const addScopes = (models: Models[], getModel: ModelFetcher, options: Pick<CustomFieldOptions, 'useCustomFieldsEntries'> = { useCustomFieldsEntries: false }): void => {\n models.forEach(async ({ name, scopeAttributes }) => {\n try {\n const model = getModel(name);\n if (!model) {\n logger.warn('sadot - tried to addScopes to a model that does not exist yet', {\n name,\n scopeAttributes,\n });\n return;\n }\n // Necessary associations for the filtering scope\n addAssociations(model, name, options);\n // Add filter scope\n model.addScope(CUSTOM_FIELDS_FILTER_SCOPE, customFieldsFilterScope(name, options));\n model.addScope(CUSTOM_FIELDS_SORT_SCOPE, customFieldsSortScope(name, options));\n } catch (e) {\n logger.error(`Could not add custom fields scopes to model ${name}. `, e);\n }\n });\n};\n\nexport const applyCustomAssociation = (models: Models[]): void => {\n models.forEach(({ modelOptions }) => {\n modelOptions?.customAssociation?.(CustomFieldDefinition);\n modelOptions?.customAssociation?.(CustomValidator);\n });\n};\n"],"mappings":"ssBAsBA,KAAM,CAAE,8BAA+B,EAE1B,GACX,EACA,EACA,EAAsD,CAAE,uBAAwB,GAAO,GAC9E,CACT,EAAO,QAAQ,MAAO,CACpB,OAAM,kBAAiB,kBACnB,CACJ,GAAI,CACF,IAAM,EAAQ,EAAS,EAAK,CAC5B,GAAI,CAAC,EAAO,CACV,EAAO,KAAK,+DAAgE,CAC1E,OACA,kBACD,CAAC,CACF,OAEF,EAAM,cAAc,aAAe,CACjC,KAAM,EAAU,QACjB,CACD,EAAM,mBAAmB,CAGzB,EAAM,QAAQ,aAAc,mBAAoB,EAAW,EAAgB,CAAC,CAC5E,EAAM,QAAQ,mBAAoB,yBAA0B,EAAiB,CAC7E,EAAM,QAAQ,mBAAoB,yBAA0B,EAAiB,CAC7E,EAAM,QAAQ,eAAgB,qBAAsB,EAAa,EAAiB,EAAc,EAAa,CAAC,CAC9G,EAAM,QAAQ,eAAgB,qBAAsB,EAAa,EAAiB,EAAc,EAAa,CAAC,CAC9G,EAAM,QAAQ,YAAa,kBAAmBA,EAAc,EAAM,EAAiB,YAAa,EAAc,EAAa,CAAC,CAC5H,EAAM,QAAQ,cAAe,oBAAqBA,EAAc,EAAM,EAAiB,IAAA,GAAW,EAAc,EAAa,CAAC,CAC9H,EAAM,QAAQ,cAAe,oBAAqBA,EAAc,EAAM,EAAiB,IAAA,GAAW,EAAc,EAAa,CAAC,OACvH,EAAG,CACV,EAAO,MAAM,6CAA6C,EAAK,IAAK,EAAE,GAExE,EAGS,GAAe,EAAkB,IAAiC,CAC7E,EAAO,QAAQ,MAAO,CAAE,UAAW,CACjC,GAAI,CACF,IAAM,EAAQ,EAAS,EAAK,CAC5B,GAAI,CAAC,EAAO,OACR,EAAM,cAAc,eACtB,OAAO,EAAM,cAAc,aAC3B,EAAM,mBAAmB,EAG3B,EAAM,WAAW,aAAc,mBAAmB,CAClD,EAAM,WAAW,mBAAoB,yBAAyB,CAC9D,EAAM,WAAW,mBAAoB,yBAAyB,CAC9D,EAAM,WAAW,eAAgB,qBAAqB,CACtD,EAAM,WAAW,eAAgB,qBAAqB,CACtD,EAAM,WAAW,YAAa,kBAAkB,CAChD,EAAM,WAAW,cAAe,oBAAoB,OAC7C,EAAG,CACV,EAAO,MAAM,6CAA6C,EAAK,IAAK,EAAE,GAExE,EAME,GAAmB,EAAkB,EAAmB,IAAsE,CAC9H,GAAS,yBACb,EAAM,QAAQC,EAAkB,CAAE,WAAY,UAAW,GAAI,mBAAoB,CAAC,CAElF,EAAiB,UAAU,EAAO,CAAE,WAAY,UAAW,GAAI,EAAW,CAAC,GAGhE,GAAa,EAAkB,EAAwB,EAA8D,CAAE,uBAAwB,GAAO,GAAW,CAC5K,EAAO,QAAQ,MAAO,CAAE,OAAM,qBAAsB,CAClD,GAAI,CACF,IAAM,EAAQ,EAAS,EAAK,CAC5B,GAAI,CAAC,EAAO,CACV,EAAO,KAAK,gEAAiE,CAC3E,OACA,kBACD,CAAC,CACF,OAGF,EAAgB,EAAO,EAAM,EAAQ,CAErC,EAAM,SAAS,EAA4B,EAAwB,EAAM,EAAQ,CAAC,CAClF,EAAM,SAAS,EAA0B,EAAsB,EAAM,EAAQ,CAAC,OACvE,EAAG,CACV,EAAO,MAAM,+CAA+C,EAAK,IAAK,EAAE,GAE1E,EAGS,EAA0B,GAA2B,CAChE,EAAO,SAAS,CAAE,kBAAmB,CACnC,GAAc,oBAAoBC,EAAsB,CACxD,GAAc,oBAAoBC,EAAgB,EAClD"}
@@ -1,2 +1,2 @@
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;
1
+ const e=require(`../../_virtual/rolldown_runtime.cjs`);let t=require(`@autofleet/zehut`);t=e.__toESM(t);let n=require(`@autofleet/logger`);n=e.__toESM(n);const r=(0,n.default)();function i(){r.addContextMiddleware(()=>({traceId:t.outbreak.getCurrentContextTraceId()}))}var a=r;exports.default=a,exports.tryAddingTraceIdMiddleware=i;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
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
+ {"version":3,"file":"index.cjs","names":["logger: LoggerInstanceManager","outbreak"],"sources":["../../../src/utils/logger/index.ts"],"sourcesContent":["import { outbreak } from '@autofleet/zehut';\nimport Logger, { type LoggerInstanceManager } from '@autofleet/logger';\n\nconst logger: LoggerInstanceManager = Logger();\n\nexport function tryAddingTraceIdMiddleware(): void {\n logger.addContextMiddleware(() => ({ traceId: outbreak.getCurrentContextTraceId() }));\n}\n\nexport default logger;\n"],"mappings":"0JAGA,MAAMA,GAAAA,EAAAA,EAAAA,UAAwC,CAE9C,SAAgB,GAAmC,CACjD,EAAO,0BAA4B,CAAE,QAASC,EAAAA,SAAS,0BAA0B,CAAE,EAAE,CAGvF,IAAA,EAAe"}
@@ -1,2 +1,2 @@
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};
1
+ import{outbreak as e}from"@autofleet/zehut";import t from"@autofleet/logger";const n=t();function r(){n.addContextMiddleware(()=>({traceId:e.getCurrentContextTraceId()}))}var i=n;export{i as default,r as tryAddingTraceIdMiddleware};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
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
+ {"version":3,"file":"index.js","names":["logger: LoggerInstanceManager"],"sources":["../../../src/utils/logger/index.ts"],"sourcesContent":["import { outbreak } from '@autofleet/zehut';\nimport Logger, { type LoggerInstanceManager } from '@autofleet/logger';\n\nconst logger: LoggerInstanceManager = Logger();\n\nexport function tryAddingTraceIdMiddleware(): void {\n logger.addContextMiddleware(() => ({ traceId: outbreak.getCurrentContextTraceId() }));\n}\n\nexport default logger;\n"],"mappings":"6EAGA,MAAMA,EAAgC,GAAQ,CAE9C,SAAgB,GAAmC,CACjD,EAAO,0BAA4B,CAAE,QAAS,EAAS,0BAA0B,CAAE,EAAE,CAGvF,IAAA,EAAe"}
@@ -1 +1 @@
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
+ {"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,IAAI,GAAQ,EAAS,GAAM,CAEvC,GAAwB,EAAe,IAAqC,CAChF,IAAM,EAAmB,MAAM,KAAK,IAAI,IAAI,EAAgB,CAAC,CAI7D,OAHI,MAAM,QAAQ,EAAS,CAClB,EAAS,QAAQ,GAAO,EAAuB,EAAkB,EAAI,CAAC,CAExE,EAAuB,EAAkB,EAAS,EAG3D,IAAA,EAAe"}
@@ -1 +1 @@
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
+ {"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,IAAI,GAAQ,EAAS,GAAM,CAU7C,IAAA,GAR8B,EAAe,IAAqC,CAChF,IAAM,EAAmB,MAAM,KAAK,IAAI,IAAI,EAAgB,CAAC,CAI7D,OAHI,MAAM,QAAQ,EAAS,CAClB,EAAS,QAAQ,GAAO,EAAuB,EAAkB,EAAI,CAAC,CAExE,EAAuB,EAAkB,EAAS"}
@@ -1 +1 @@
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
+ {"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: Record<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,OAAO,GAAU,CAAC,CAAC,EAAO,CAE7B,GAAI,GAAkB,OACpB,MAAM,IAAIC,EAAAA,oBAAoB,EAAS,QAAS,EAAiB"}
@@ -1 +1 @@
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
+ {"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: Record<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,OAAO,GAAU,CAAC,CAAC,EAAO,CAE7B,GAAI,GAAkB,OACpB,MAAM,IAAI,EAAoB,EAAS,QAAS,EAAiB"}
@@ -1 +1 @@
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
+ {"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,IAAI,GAClD,GAAI,EAA6C,cAAgB,GAAG,GAAI,EAAwC,SAAW,6BAA6B,CAAC,KAAK,KAAK,CAOrK,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 +1 @@
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
+ {"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,IAAI,GAClD,GAAI,EAA6C,cAAgB,GAAG,GAAI,EAAwC,SAAW,6BAA6B,CAAC,KAAK,KAAK,CAOrK,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 +1 @@
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
+ {"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 { Validator, 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 as Validator<unknown, unknown>,\n [CustomFieldDefinitionType.STATUS]: validateStatus as Validator<unknown, unknown>,\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,MAAO,GAASI,EAAAA,QAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,SAAS,EAAM,EAC7EJ,EAAAA,0BAA0B,QAAS,GAASI,EAAAA,QAAI,QAAQ,CAAC,OAAO,GAAK,CAAC,SAAS,EAAM,EACrFJ,EAAAA,0BAA0B,SAAU,GAASI,EAAAA,QAAI,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAM,EACnFJ,EAAAA,0BAA0B,MAAO,GAASI,EAAAA,QAAI,MAAM,CAAC,SAAS,EAAM,EACpEJ,EAAAA,0BAA0B,UAAW,GAASI,EAAAA,QAAI,MAAM,CAAC,SAAS,EAAM,EACxEJ,EAAAA,0BAA0B,OAAQ,GAASI,EAAAA,QAAI,OAAO,CAAC,IAAI,EAAE,CAAC,QAAQ,CACpE,MAAMA,EAAAA,QAAI,QAAQ,CAAC,KAAK,CAAC,CACzB,SAAS,EAAM,EACjBJ,EAAAA,0BAA0B,MAAO,GAASI,EAAAA,QAAI,OAAO,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,MAAMA,EAAAA,QAAI,OAAO,CACtF,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 +1 @@
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
+ {"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 { Validator, 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 as Validator<unknown, unknown>,\n [CustomFieldDefinitionType.STATUS]: validateStatus as Validator<unknown, unknown>,\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,MAAO,GAAS,EAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,SAAS,EAAM,EAC7E,EAA0B,QAAS,GAAS,EAAI,QAAQ,CAAC,OAAO,GAAK,CAAC,SAAS,EAAM,EACrF,EAA0B,SAAU,GAAS,EAAI,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAM,EACnF,EAA0B,MAAO,GAAS,EAAI,MAAM,CAAC,SAAS,EAAM,EACpE,EAA0B,UAAW,GAAS,EAAI,MAAM,CAAC,SAAS,EAAM,EACxE,EAA0B,OAAQ,GAAS,EAAI,OAAO,CAAC,IAAI,EAAE,CAAC,QAAQ,CACpE,MAAM,EAAI,QAAQ,CAAC,KAAK,CAAC,CACzB,SAAS,EAAM,EACjB,EAA0B,MAAO,GAAS,EAAI,OAAO,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAI,OAAO,CACtF,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 +1 @@
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
+ {"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,EAAc,CAAC,SAAS,EAAM"}
@@ -1 +1 @@
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
+ {"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,EAAc,CAAC,SAAS,EAAM"}
@@ -1 +1 @@
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
+ {"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;\ninterface 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,EAAc,IAAI,GAAe,EAAY,MAAM,CAAC,CAC7D,SAAS,EAAM"}
@@ -1 +1 @@
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"}
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;\ninterface 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,EAAc,IAAI,GAAe,EAAY,MAAM,CAAC,CAC7D,SAAS,EAAM"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/sadot",
3
- "version": "1.0.13-beta-3",
3
+ "version": "1.0.13",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -62,18 +62,9 @@
62
62
  "@autofleet/node-common": "^4.1.10",
63
63
  "@autofleet/zehut": "^4.4.0",
64
64
  "@types/express": "^4.17.17",
65
- "@typescript-eslint/eslint-plugin": "^7.18.0",
66
- "@typescript-eslint/parser": "^7.18.0",
67
- "@vitest/coverage-v8": "^3.2.4",
68
- "eslint": "^8.57.0",
69
- "eslint-config-airbnb-base": "^15.0.0",
70
- "eslint-plugin-import": "^2.22.1",
71
65
  "express": "^4.21.2",
72
66
  "npm-watch": "^0.11.0",
73
- "supertest": "^7.0.0",
74
- "tsdown": "^0.15.2",
75
- "typescript": "^5.9.2",
76
- "vitest": "^3.2.4"
67
+ "supertest": "^7.0.0"
77
68
  },
78
69
  "peerDependencies": {
79
70
  "@autofleet/errors": "^3",
@@ -82,11 +73,6 @@
82
73
  "@autofleet/sheilta": "^2",
83
74
  "@autofleet/zehut": "^4"
84
75
  },
85
- "peerDependenciesMeta": {
86
- "@autofleet/zehut": {
87
- "optional": true
88
- }
89
- },
90
76
  "engines": {
91
77
  "node": ">=18.0.0"
92
78
  },