@autofleet/sadot 1.0.25 → 1.0.26

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 (74) hide show
  1. package/dist/api/index.cjs +1 -1
  2. package/dist/api/index.cjs.map +1 -1
  3. package/dist/api/v1/definition/index.cjs +1 -1
  4. package/dist/api/v1/definition/index.cjs.map +1 -1
  5. package/dist/api/v1/errors.cjs +1 -1
  6. package/dist/api/v1/errors.cjs.map +1 -1
  7. package/dist/api/v1/index.cjs +1 -1
  8. package/dist/api/v1/index.cjs.map +1 -1
  9. package/dist/api/v1/validator/index.cjs +1 -1
  10. package/dist/api/v1/validator/index.cjs.map +1 -1
  11. package/dist/api/v1/validator/validations.d.ts +1 -0
  12. package/dist/errors/index.cjs +1 -1
  13. package/dist/errors/index.cjs.map +1 -1
  14. package/dist/events/index.cjs +1 -1
  15. package/dist/events/index.cjs.map +1 -1
  16. package/dist/hooks/hooks.cjs +1 -1
  17. package/dist/hooks/hooks.cjs.map +1 -1
  18. package/dist/models/CustomFieldDefinition.cjs +1 -1
  19. package/dist/models/CustomFieldDefinition.cjs.map +1 -1
  20. package/dist/models/CustomFieldDefinition.d.cts +2 -0
  21. package/dist/models/CustomFieldDefinition.d.ts +4 -0
  22. package/dist/models/CustomFieldDefinition.js +1 -1
  23. package/dist/models/CustomFieldEntries.cjs +1 -1
  24. package/dist/models/CustomFieldEntries.cjs.map +1 -1
  25. package/dist/models/CustomFieldEntries.d.ts +2 -0
  26. package/dist/models/CustomFieldEntries.js +1 -1
  27. package/dist/models/CustomFieldValue.cjs +1 -1
  28. package/dist/models/CustomFieldValue.cjs.map +1 -1
  29. package/dist/models/CustomFieldValue.d.cts +1 -0
  30. package/dist/models/CustomFieldValue.d.ts +3 -0
  31. package/dist/models/CustomFieldValue.js +1 -1
  32. package/dist/models/CustomValidator.cjs +1 -1
  33. package/dist/models/CustomValidator.cjs.map +1 -1
  34. package/dist/models/CustomValidator.d.ts +3 -0
  35. package/dist/models/CustomValidator.js +1 -1
  36. package/dist/models/index.cjs +1 -1
  37. package/dist/models/index.cjs.map +1 -1
  38. package/dist/models/index.d.cts +4 -0
  39. package/dist/models/index.d.ts +6 -0
  40. package/dist/models/tests/AssociatedTestModel.cjs +1 -1
  41. package/dist/models/tests/AssociatedTestModel.cjs.map +1 -1
  42. package/dist/models/tests/AssociatedTestModel.js +1 -1
  43. package/dist/models/tests/TestModel.cjs +1 -1
  44. package/dist/models/tests/TestModel.cjs.map +1 -1
  45. package/dist/models/tests/TestModel.js +1 -1
  46. package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs +1 -1
  47. package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs.map +1 -1
  48. package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js +1 -1
  49. package/dist/models/tests/contextAwareModels/ContextTestModel.cjs +1 -1
  50. package/dist/models/tests/contextAwareModels/ContextTestModel.cjs.map +1 -1
  51. package/dist/models/tests/contextAwareModels/ContextTestModel.js +1 -1
  52. package/dist/repository/definition.cjs +1 -1
  53. package/dist/repository/definition.cjs.map +1 -1
  54. package/dist/scopes/filter.cjs +1 -1
  55. package/dist/scopes/filter.cjs.map +1 -1
  56. package/dist/types/index.d.cts +1 -0
  57. package/dist/types/index.d.ts +2 -0
  58. package/dist/utils/constants/index.cjs +1 -1
  59. package/dist/utils/constants/index.cjs.map +1 -1
  60. package/dist/utils/db/index.cjs +1 -1
  61. package/dist/utils/db/index.cjs.map +1 -1
  62. package/dist/utils/helpers/index.cjs +1 -1
  63. package/dist/utils/helpers/index.cjs.map +1 -1
  64. package/dist/utils/init.cjs +1 -1
  65. package/dist/utils/init.cjs.map +1 -1
  66. package/dist/utils/logger/index.cjs +1 -1
  67. package/dist/utils/logger/index.cjs.map +1 -1
  68. package/dist/utils/validations/schema/validator-schema.cjs +1 -1
  69. package/dist/utils/validations/schema/validator-schema.cjs.map +1 -1
  70. package/package.json +1 -1
  71. /package/dist/_virtual/{_@oxc-project_runtime@0.94.0 → _@oxc-project_runtime@0.96.0}/helpers/decorate.cjs +0 -0
  72. /package/dist/_virtual/{_@oxc-project_runtime@0.94.0 → _@oxc-project_runtime@0.96.0}/helpers/decorate.js +0 -0
  73. /package/dist/_virtual/{_@oxc-project_runtime@0.94.0 → _@oxc-project_runtime@0.96.0}/helpers/decorateMetadata.cjs +0 -0
  74. /package/dist/_virtual/{_@oxc-project_runtime@0.94.0 → _@oxc-project_runtime@0.96.0}/helpers/decorateMetadata.js +0 -0
@@ -1,2 +1,2 @@
1
- import{sendDimEvent as e}from"../events/index.js";import{InvalidFieldTypeError as t,InvalidValueError as n}from"../errors/index.js";import{validateFieldType as r,validateValue as i}from"../utils/validations/index.js";import{__decorateMetadata as a}from"../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorateMetadata.js";import{__decorate as o}from"../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorate.js";import s from"./CustomFieldDefinition.js";import{findById as c,findByIds as l}from"../repository/definition.js";import"./index.js";import{AfterUpsert as u,BeforeBulkCreate as d,BeforeBulkUpdate as f,BeforeCreate as p,BeforeUpdate as m,BeforeUpsert as h,BelongsTo as g,Column as _,DataType as v,ForeignKey as y,Model as b,PrimaryKey as x,Table as S}from"sequelize-typescript";var C,w,T,E,D;let O=class extends b{static validateValueAgainstDefinition(e,a){let{validation:o,fieldType:s,name:c}=a;if(!r(s))throw new t(s);if(e.value===null)return;let l=i(e.value,s,o);if(l.error)throw new n(e.value,c,l.error)}static async validateCustomFieldValues(e){let t=e.map(e=>e.customFieldDefinitionId),n=[...new Set(t)],r=await l(n,{withDisabled:!0});if(!r||r.length!==n.length)throw Error(`Definitions not found`);e.forEach(e=>{let t=r.find(t=>t.id===e.customFieldDefinitionId);t&&this.validateValueAgainstDefinition(e,t)})}static async validateCustomFieldValue(e){let{customFieldDefinitionId:t}=e,n=await c(t,{withDisabled:!0});this.validateValueAgainstDefinition(e,n)}static afterSaveHandler(t,n){n.transaction?n.transaction.afterCommit(()=>e(t[0])):e(t[0])}};o([x,_({type:v.UUID,allowNull:!1}),a(`design:type`,String)],O.prototype,`modelId`,void 0),o([x,y(()=>s),_({type:v.UUID,allowNull:!1}),a(`design:type`,String)],O.prototype,`customFieldDefinitionId`,void 0),o([_({type:v.JSONB,allowNull:!0}),a(`design:type`,Object)],O.prototype,`value`,void 0),o([_({type:v.DATE,allowNull:!1}),a(`design:type`,typeof(C=typeof Date<`u`&&Date)==`function`?C:Object)],O.prototype,`createdAt`,void 0),o([_({type:v.DATE,allowNull:!0}),a(`design:type`,typeof(w=typeof Date<`u`&&Date)==`function`?w:Object)],O.prototype,`updatedAt`,void 0),o([_({type:v.DATE,allowNull:!0}),a(`design:type`,typeof(T=typeof Date<`u`&&Date)==`function`?T:Object)],O.prototype,`deletedAt`,void 0),o([g(()=>s,{scope:{disabled:!1}}),a(`design:type`,typeof(E=s!==void 0&&s)==`function`?E:Object)],O.prototype,`customFieldDefinition`,void 0),o([d,f,a(`design:type`,Function),a(`design:paramtypes`,[Array]),a(`design:returntype`,Promise)],O,`validateCustomFieldValues`,null),o([m,p,h,a(`design:type`,Function),a(`design:paramtypes`,[typeof(D=O!==void 0&&O)==`function`?D:Object]),a(`design:returntype`,Promise)],O,`validateCustomFieldValue`,null),o([u,a(`design:type`,Function),a(`design:paramtypes`,[Array,Object]),a(`design:returntype`,void 0)],O,`afterSaveHandler`,null),O=o([S({tableName:`custom_field_values`,modelName:`CustomFieldValue`,timestamps:!0})],O);var k=O;export{k as default};
1
+ import{sendDimEvent as e}from"../events/index.js";import{InvalidFieldTypeError as t,InvalidValueError as n}from"../errors/index.js";import{validateFieldType as r,validateValue as i}from"../utils/validations/index.js";import{__decorateMetadata as a}from"../_virtual/_@oxc-project_runtime@0.96.0/helpers/decorateMetadata.js";import{__decorate as o}from"../_virtual/_@oxc-project_runtime@0.96.0/helpers/decorate.js";import s from"./CustomFieldDefinition.js";import{findById as c,findByIds as l}from"../repository/definition.js";import"./index.js";import{AfterUpsert as u,BeforeBulkCreate as d,BeforeBulkUpdate as f,BeforeCreate as p,BeforeUpdate as m,BeforeUpsert as h,BelongsTo as g,Column as _,DataType as v,ForeignKey as y,Model as b,PrimaryKey as x,Table as S}from"sequelize-typescript";var C,w,T,E,D;let O=class extends b{static validateValueAgainstDefinition(e,a){let{validation:o,fieldType:s,name:c}=a;if(!r(s))throw new t(s);if(e.value===null)return;let l=i(e.value,s,o);if(l.error)throw new n(e.value,c,l.error)}static async validateCustomFieldValues(e){let t=e.map(e=>e.customFieldDefinitionId),n=[...new Set(t)],r=await l(n,{withDisabled:!0});if(!r||r.length!==n.length)throw Error(`Definitions not found`);e.forEach(e=>{let t=r.find(t=>t.id===e.customFieldDefinitionId);t&&this.validateValueAgainstDefinition(e,t)})}static async validateCustomFieldValue(e){let{customFieldDefinitionId:t}=e,n=await c(t,{withDisabled:!0});this.validateValueAgainstDefinition(e,n)}static afterSaveHandler(t,n){n.transaction?n.transaction.afterCommit(()=>e(t[0])):e(t[0])}};o([x,_({type:v.UUID,allowNull:!1}),a(`design:type`,String)],O.prototype,`modelId`,void 0),o([x,y(()=>s),_({type:v.UUID,allowNull:!1}),a(`design:type`,String)],O.prototype,`customFieldDefinitionId`,void 0),o([_({type:v.JSONB,allowNull:!0}),a(`design:type`,Object)],O.prototype,`value`,void 0),o([_({type:v.DATE,allowNull:!1}),a(`design:type`,typeof(C=typeof Date<`u`&&Date)==`function`?C:Object)],O.prototype,`createdAt`,void 0),o([_({type:v.DATE,allowNull:!0}),a(`design:type`,typeof(w=typeof Date<`u`&&Date)==`function`?w:Object)],O.prototype,`updatedAt`,void 0),o([_({type:v.DATE,allowNull:!0}),a(`design:type`,typeof(T=typeof Date<`u`&&Date)==`function`?T:Object)],O.prototype,`deletedAt`,void 0),o([g(()=>s,{scope:{disabled:!1}}),a(`design:type`,typeof(E=s!==void 0&&s)==`function`?E:Object)],O.prototype,`customFieldDefinition`,void 0),o([d,f,a(`design:type`,Function),a(`design:paramtypes`,[Array]),a(`design:returntype`,Promise)],O,`validateCustomFieldValues`,null),o([m,p,h,a(`design:type`,Function),a(`design:paramtypes`,[typeof(D=O!==void 0&&O)==`function`?D:Object]),a(`design:returntype`,Promise)],O,`validateCustomFieldValue`,null),o([u,a(`design:type`,Function),a(`design:paramtypes`,[Array,Object]),a(`design:returntype`,void 0)],O,`afterSaveHandler`,null),O=o([S({tableName:`custom_field_values`,modelName:`CustomFieldValue`,timestamps:!0})],O);var k=O;export{k as default};
2
2
  //# sourceMappingURL=CustomFieldValue.js.map
@@ -1,2 +1,2 @@
1
- const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../events/index.cjs`),n=require(`../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorateMetadata.cjs`),r=require(`../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorate.cjs`);let i=require(`sequelize-typescript`);i=e.__toESM(i);let a=require(`node:crypto`);a=e.__toESM(a);var o,s,c;let l=class extends i.Model{static afterSaveHandler(e,n){n.transaction?n.transaction.afterCommit(()=>t.sendDimEvent(e)):t.sendDimEvent(e)}};r.__decorate([i.PrimaryKey,(0,i.Default)(()=>(0,a.randomUUID)()),(0,i.Column)({type:i.DataType.UUID,allowNull:!1}),n.__decorateMetadata(`design:type`,String)],l.prototype,`id`,void 0),r.__decorate([(0,i.Column)({type:i.DataType.UUID,allowNull:!1}),n.__decorateMetadata(`design:type`,String)],l.prototype,`entityId`,void 0),r.__decorate([(0,i.Column)({type:i.DataType.STRING,allowNull:!1}),n.__decorateMetadata(`design:type`,String)],l.prototype,`entityType`,void 0),r.__decorate([(0,i.Column)({type:i.DataType.STRING,allowNull:!1}),n.__decorateMetadata(`design:type`,String)],l.prototype,`modelType`,void 0),r.__decorate([(0,i.Column)({type:i.DataType.JSONB,allowNull:!1}),n.__decorateMetadata(`design:type`,Object)],l.prototype,`schema`,void 0),r.__decorate([(0,i.Column)({type:i.DataType.BOOLEAN,allowNull:!1,defaultValue:!1}),n.__decorateMetadata(`design:type`,Boolean)],l.prototype,`disabled`,void 0),r.__decorate([(0,i.Column)({type:i.DataType.DATE,allowNull:!1}),n.__decorateMetadata(`design:type`,typeof(o=typeof Date<`u`&&Date)==`function`?o:Object)],l.prototype,`createdAt`,void 0),r.__decorate([(0,i.Column)({type:i.DataType.DATE,allowNull:!0}),n.__decorateMetadata(`design:type`,typeof(s=typeof Date<`u`&&Date)==`function`?s:Object)],l.prototype,`updatedAt`,void 0),r.__decorate([i.AfterUpsert,n.__decorateMetadata(`design:type`,Function),n.__decorateMetadata(`design:paramtypes`,[typeof(c=l!==void 0&&l)==`function`?c:Object,Object]),n.__decorateMetadata(`design:returntype`,void 0)],l,`afterSaveHandler`,null),l=r.__decorate([(0,i.DefaultScope)(()=>({where:{disabled:!1}})),(0,i.Table)({tableName:`custom_validators`,modelName:`CustomValidator`,timestamps:!0})],l);var u=l;exports.default=u;
1
+ const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../events/index.cjs`),n=require(`../_virtual/_@oxc-project_runtime@0.96.0/helpers/decorateMetadata.cjs`),r=require(`../_virtual/_@oxc-project_runtime@0.96.0/helpers/decorate.cjs`);let i=require(`sequelize-typescript`),a=require(`node:crypto`);var o,s,c;let l=class extends i.Model{static afterSaveHandler(e,n){n.transaction?n.transaction.afterCommit(()=>t.sendDimEvent(e)):t.sendDimEvent(e)}};r.__decorate([i.PrimaryKey,(0,i.Default)(()=>(0,a.randomUUID)()),(0,i.Column)({type:i.DataType.UUID,allowNull:!1}),n.__decorateMetadata(`design:type`,String)],l.prototype,`id`,void 0),r.__decorate([(0,i.Column)({type:i.DataType.UUID,allowNull:!1}),n.__decorateMetadata(`design:type`,String)],l.prototype,`entityId`,void 0),r.__decorate([(0,i.Column)({type:i.DataType.STRING,allowNull:!1}),n.__decorateMetadata(`design:type`,String)],l.prototype,`entityType`,void 0),r.__decorate([(0,i.Column)({type:i.DataType.STRING,allowNull:!1}),n.__decorateMetadata(`design:type`,String)],l.prototype,`modelType`,void 0),r.__decorate([(0,i.Column)({type:i.DataType.JSONB,allowNull:!1}),n.__decorateMetadata(`design:type`,Object)],l.prototype,`schema`,void 0),r.__decorate([(0,i.Column)({type:i.DataType.BOOLEAN,allowNull:!1,defaultValue:!1}),n.__decorateMetadata(`design:type`,Boolean)],l.prototype,`disabled`,void 0),r.__decorate([(0,i.Column)({type:i.DataType.DATE,allowNull:!1}),n.__decorateMetadata(`design:type`,typeof(o=typeof Date<`u`&&Date)==`function`?o:Object)],l.prototype,`createdAt`,void 0),r.__decorate([(0,i.Column)({type:i.DataType.DATE,allowNull:!0}),n.__decorateMetadata(`design:type`,typeof(s=typeof Date<`u`&&Date)==`function`?s:Object)],l.prototype,`updatedAt`,void 0),r.__decorate([i.AfterUpsert,n.__decorateMetadata(`design:type`,Function),n.__decorateMetadata(`design:paramtypes`,[typeof(c=l!==void 0&&l)==`function`?c:Object,Object]),n.__decorateMetadata(`design:returntype`,void 0)],l,`afterSaveHandler`,null),l=r.__decorate([(0,i.DefaultScope)(()=>({where:{disabled:!1}})),(0,i.Table)({tableName:`custom_validators`,modelName:`CustomValidator`,timestamps:!0})],l);var u=l;exports.default=u;
2
2
  //# sourceMappingURL=CustomValidator.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"CustomValidator.cjs","names":["CustomValidator","Model","sendDimEvent","PrimaryKey","DataType","AfterUpsert"],"sources":["../../src/models/CustomValidator.ts"],"sourcesContent":["import {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n Default,\n AfterUpsert,\n DefaultScope,\n} from 'sequelize-typescript';\nimport type { CreateOptions } from 'sequelize';\nimport { randomUUID } from 'node:crypto';\nimport { sendDimEvent } from '../events';\nimport type { SchemaObject } from '../api/v1/validator/validations';\n\n@DefaultScope(() => ({ where: { disabled: false } }))\n@Table({\n tableName: 'custom_validators',\n modelName: 'CustomValidator',\n timestamps: true,\n})\nclass CustomValidator extends Model {\n @PrimaryKey\n @Default(() => randomUUID())\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n declare id: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n /** The ID of the entity for which this validator is defined, e.g. fleetId / etc. */\n entityId!: string;\n\n @Column({\n type: DataType.STRING,\n allowNull: false,\n })\n /** The type of entity (fleet, businessModel, etc). */\n entityType!: string;\n\n @Column({\n type: DataType.STRING,\n allowNull: false,\n })\n /** The type of model this validator applies to. e.g. Vehicle / StopPoint / etc. */\n modelType!: string;\n\n @Column({\n type: DataType.JSONB,\n allowNull: false,\n })\n /** JSON Schema to validate models against */\n schema!: SchemaObject;\n\n @Column({\n type: DataType.BOOLEAN,\n allowNull: false,\n defaultValue: false,\n })\n disabled!: boolean;\n\n @Column({\n type: DataType.DATE,\n allowNull: false,\n })\n declare createdAt?: Date;\n\n @Column({\n type: DataType.DATE,\n allowNull: true,\n })\n declare updatedAt?: Date;\n\n @AfterUpsert\n static afterSaveHandler(instance: CustomValidator, options: CreateOptions): void {\n if (options.transaction) {\n options.transaction.afterCommit(() => sendDimEvent(instance));\n } else {\n sendDimEvent(instance);\n }\n }\n}\n\nexport default CustomValidator;\n"],"mappings":"8VAeA,IAAA,EAAA,cAM8BC,EAAAA,KAAM,CAwDlC,OACO,iBAAiB,EAA2B,EAA8B,CAC3E,EAAQ,YACV,EAAQ,YAAY,gBAAkBC,EAAAA,aAAa,EAAS,CAAC,CAE7D,EAAA,aAAa,EAAS,iBA5DzBC,EAAAA,+CAC0B,CAAC,cACpB,CACN,KAAMC,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,iGAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,WAAA,IAAA,GAAA,4BAIM,CACN,KAAMA,EAAAA,SAAS,OACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,aAAA,IAAA,GAAA,4BAIM,CACN,KAAMA,EAAAA,SAAS,OACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,4BAIM,CACN,KAAMA,EAAAA,SAAS,MACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,SAAA,IAAA,GAAA,4BAIM,CACN,KAAMA,EAAAA,SAAS,QACf,UAAW,GACX,aAAc,GACf,CAAC,CAAA,EAAA,mBAAA,cAAA,QAAA,CAAA,CAAA,EAAA,UAAA,WAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,EAAA,OAAA,KAAA,KAAA,OAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,EAAA,OAAA,KAAA,KAAA,OAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,eAGDC,EAAAA,8QA9DkB,CAAE,MAAO,CAAE,SAAU,GAAO,CAAE,EAAE,EAAA,EAAA,EAAA,OAC9C,CACL,UAAW,oBACX,UAAW,kBACX,WAAY,GACb,CAAC,CAAA,CAAA,EAAA,CAmEF,IAAA,EAAe"}
1
+ {"version":3,"file":"CustomValidator.cjs","names":["CustomValidator","Model","sendDimEvent","PrimaryKey","DataType","AfterUpsert"],"sources":["../../src/models/CustomValidator.ts"],"sourcesContent":["import {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n Default,\n AfterUpsert,\n DefaultScope,\n} from 'sequelize-typescript';\nimport type { CreateOptions } from 'sequelize';\nimport { randomUUID } from 'node:crypto';\nimport { sendDimEvent } from '../events';\nimport type { SchemaObject } from '../api/v1/validator/validations';\n\n@DefaultScope(() => ({ where: { disabled: false } }))\n@Table({\n tableName: 'custom_validators',\n modelName: 'CustomValidator',\n timestamps: true,\n})\nclass CustomValidator extends Model {\n @PrimaryKey\n @Default(() => randomUUID())\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n declare id: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n /** The ID of the entity for which this validator is defined, e.g. fleetId / etc. */\n entityId!: string;\n\n @Column({\n type: DataType.STRING,\n allowNull: false,\n })\n /** The type of entity (fleet, businessModel, etc). */\n entityType!: string;\n\n @Column({\n type: DataType.STRING,\n allowNull: false,\n })\n /** The type of model this validator applies to. e.g. Vehicle / StopPoint / etc. */\n modelType!: string;\n\n @Column({\n type: DataType.JSONB,\n allowNull: false,\n })\n /** JSON Schema to validate models against */\n schema!: SchemaObject;\n\n @Column({\n type: DataType.BOOLEAN,\n allowNull: false,\n defaultValue: false,\n })\n disabled!: boolean;\n\n @Column({\n type: DataType.DATE,\n allowNull: false,\n })\n declare createdAt?: Date;\n\n @Column({\n type: DataType.DATE,\n allowNull: true,\n })\n declare updatedAt?: Date;\n\n @AfterUpsert\n static afterSaveHandler(instance: CustomValidator, options: CreateOptions): void {\n if (options.transaction) {\n options.transaction.afterCommit(() => sendDimEvent(instance));\n } else {\n sendDimEvent(instance);\n }\n }\n}\n\nexport default CustomValidator;\n"],"mappings":"4TAeA,IAAA,EAAA,cAM8BC,EAAAA,KAAM,CAwDlC,OACO,iBAAiB,EAA2B,EAA8B,CAC3E,EAAQ,YACV,EAAQ,YAAY,gBAAkBC,EAAAA,aAAa,EAAS,CAAC,CAE7D,EAAA,aAAa,EAAS,iBA5DzBC,EAAAA,+CAC0B,CAAC,cACpB,CACN,KAAMC,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,iGAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,WAAA,IAAA,GAAA,4BAIM,CACN,KAAMA,EAAAA,SAAS,OACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,aAAA,IAAA,GAAA,4BAIM,CACN,KAAMA,EAAAA,SAAS,OACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,4BAIM,CACN,KAAMA,EAAAA,SAAS,MACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,SAAA,IAAA,GAAA,4BAIM,CACN,KAAMA,EAAAA,SAAS,QACf,UAAW,GACX,aAAc,GACf,CAAC,CAAA,EAAA,mBAAA,cAAA,QAAA,CAAA,CAAA,EAAA,UAAA,WAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,EAAA,OAAA,KAAA,KAAA,OAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,EAAA,OAAA,KAAA,KAAA,OAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,eAGDC,EAAAA,8QA9DkB,CAAE,MAAO,CAAE,SAAU,GAAO,CAAE,EAAE,EAAA,EAAA,EAAA,OAC9C,CACL,UAAW,oBACX,UAAW,kBACX,WAAY,GACb,CAAC,CAAA,CAAA,EAAA,CAmEF,IAAA,EAAe"}
@@ -0,0 +1,3 @@
1
+ import "../api/v1/validator/validations.js";
2
+ import "sequelize";
3
+ import { Model } from "sequelize-typescript";
@@ -1,2 +1,2 @@
1
- import{sendDimEvent as e}from"../events/index.js";import{__decorateMetadata as t}from"../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorateMetadata.js";import{__decorate as n}from"../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorate.js";import{AfterUpsert as r,Column as i,DataType as a,Default as o,DefaultScope as s,Model as c,PrimaryKey as l,Table as u}from"sequelize-typescript";import{randomUUID as d}from"node:crypto";var f,p,m;let h=class extends c{static afterSaveHandler(t,n){n.transaction?n.transaction.afterCommit(()=>e(t)):e(t)}};n([l,o(()=>d()),i({type:a.UUID,allowNull:!1}),t(`design:type`,String)],h.prototype,`id`,void 0),n([i({type:a.UUID,allowNull:!1}),t(`design:type`,String)],h.prototype,`entityId`,void 0),n([i({type:a.STRING,allowNull:!1}),t(`design:type`,String)],h.prototype,`entityType`,void 0),n([i({type:a.STRING,allowNull:!1}),t(`design:type`,String)],h.prototype,`modelType`,void 0),n([i({type:a.JSONB,allowNull:!1}),t(`design:type`,Object)],h.prototype,`schema`,void 0),n([i({type:a.BOOLEAN,allowNull:!1,defaultValue:!1}),t(`design:type`,Boolean)],h.prototype,`disabled`,void 0),n([i({type:a.DATE,allowNull:!1}),t(`design:type`,typeof(f=typeof Date<`u`&&Date)==`function`?f:Object)],h.prototype,`createdAt`,void 0),n([i({type:a.DATE,allowNull:!0}),t(`design:type`,typeof(p=typeof Date<`u`&&Date)==`function`?p:Object)],h.prototype,`updatedAt`,void 0),n([r,t(`design:type`,Function),t(`design:paramtypes`,[typeof(m=h!==void 0&&h)==`function`?m:Object,Object]),t(`design:returntype`,void 0)],h,`afterSaveHandler`,null),h=n([s(()=>({where:{disabled:!1}})),u({tableName:`custom_validators`,modelName:`CustomValidator`,timestamps:!0})],h);var g=h;export{g as default};
1
+ import{sendDimEvent as e}from"../events/index.js";import{__decorateMetadata as t}from"../_virtual/_@oxc-project_runtime@0.96.0/helpers/decorateMetadata.js";import{__decorate as n}from"../_virtual/_@oxc-project_runtime@0.96.0/helpers/decorate.js";import{AfterUpsert as r,Column as i,DataType as a,Default as o,DefaultScope as s,Model as c,PrimaryKey as l,Table as u}from"sequelize-typescript";import{randomUUID as d}from"node:crypto";var f,p,m;let h=class extends c{static afterSaveHandler(t,n){n.transaction?n.transaction.afterCommit(()=>e(t)):e(t)}};n([l,o(()=>d()),i({type:a.UUID,allowNull:!1}),t(`design:type`,String)],h.prototype,`id`,void 0),n([i({type:a.UUID,allowNull:!1}),t(`design:type`,String)],h.prototype,`entityId`,void 0),n([i({type:a.STRING,allowNull:!1}),t(`design:type`,String)],h.prototype,`entityType`,void 0),n([i({type:a.STRING,allowNull:!1}),t(`design:type`,String)],h.prototype,`modelType`,void 0),n([i({type:a.JSONB,allowNull:!1}),t(`design:type`,Object)],h.prototype,`schema`,void 0),n([i({type:a.BOOLEAN,allowNull:!1,defaultValue:!1}),t(`design:type`,Boolean)],h.prototype,`disabled`,void 0),n([i({type:a.DATE,allowNull:!1}),t(`design:type`,typeof(f=typeof Date<`u`&&Date)==`function`?f:Object)],h.prototype,`createdAt`,void 0),n([i({type:a.DATE,allowNull:!0}),t(`design:type`,typeof(p=typeof Date<`u`&&Date)==`function`?p:Object)],h.prototype,`updatedAt`,void 0),n([r,t(`design:type`,Function),t(`design:paramtypes`,[typeof(m=h!==void 0&&h)==`function`?m:Object,Object]),t(`design:returntype`,void 0)],h,`afterSaveHandler`,null),h=n([s(()=>({where:{disabled:!1}})),u({tableName:`custom_validators`,modelName:`CustomValidator`,timestamps:!0})],h);var g=h;export{g as default};
2
2
  //# sourceMappingURL=CustomValidator.js.map
@@ -1,2 +1,2 @@
1
- const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../utils/logger/index.cjs`),n=require(`./CustomFieldDefinition.cjs`),r=require(`./CustomFieldValue.cjs`),i=require(`./tests/AssociatedTestModel.cjs`),a=require(`./tests/TestModel.cjs`),o=require(`./tests/contextAwareModels/ContextTestModel.cjs`),s=require(`./tests/contextAwareModels/ContextAwareTestModel.cjs`),c=require(`./CustomFieldEntries.cjs`),l=require(`./CustomValidator.cjs`);let u=require(`sequelize`);u=e.__toESM(u);const d=[n.default,r.default,l.default],f=[a.default,i.default,s.default,o.default],p=`sadot-migration`,m=`49c9dd1d-b1cc-445b-a911-fd349d783110`,h=async(e,i,{schemaPrefix:a=`sadot-migration`,schemaVersion:o=`49c9dd1d-b1cc-445b-a911-fd349d783110`,useCustomFieldsEntries:s=!1}={})=>{let f=`${a}_${o}${s?`_withEntries`:``}`;if(t.default.info(`custom-fields: initialize custom-fields tables`),!e.addModels)throw Error(`sequelize instance must have addModels function`);s&&d.push(c.default),e.addModels(d),n.default.addScope(`userScope`,()=>{let e=i();return e?.permissions?{where:{entityId:[...Object.keys(e.permissions.fleets),...Object.keys(e.permissions.businessModels),...Object.keys(e.permissions.demandSources)]}}:{}}),l.default.addScope(`userScope`,()=>{let e=i();return e?.permissions?{where:{entityId:[...Object.keys(e.permissions.fleets),...Object.keys(e.permissions.businessModels),...Object.keys(e.permissions.demandSources)]}}:{}}),t.default.info(`custom-fields: models added`);let p=e.define(`SequelizeMeta`,{name:{type:u.DataTypes.STRING,allowNull:!1,unique:!0,primaryKey:!0,autoIncrement:!1}},{tableName:`SequelizeMeta`,timestamps:!1,schema:`public`});t.default.info(`custom-fields: starting migrations`);let m=await p.findAll({where:{name:{[u.Op.like]:`${a}%`}},raw:!0}),h=m.at(-1),g=m.findIndex(e=>e.name===f);if(t.default.info(`custom-fields: migrations`,{migrations:m,currentSadotSchemaVersion:h,expectedSchemaVersionIndex:g}),(!h||h.name!==f)&&(t.default.info(`custom-fields: syncing models`),await n.default.sync({alter:!0}),await r.default.sync({alter:!0}),s&&await c.default.sync({alter:!0}),await l.default.sync({alter:!0}),g===-1&&await p.create({name:f}),t.default.info(`custom-fields: models synced`),m.length&&g!==-1&&g<m.length-1)){let e=m.slice(g+1);await p.destroy({where:{name:{[u.Op.in]:e.map(e=>e.name)}}})}},g=async e=>{if(t.default.info(`custom-fields: initialize custom-fields test models`),!e.addModels)throw Error(`sequelize instance must have addModels function`);e.addModels(f),await e.dropSchema(`custom-fields`,{logging:!1}),await e.createSchema(`custom-fields`,{logging:!1}),t.default.info(`custom-fields: test models added`),await a.default.sync({alter:!0}),await i.default.sync({alter:!0}),await o.default.sync({alter:!0}),await s.default.sync({alter:!0}),t.default.info(`custom-fields: test models synced`)};exports.initTables=h,exports.initTestModels=g;
1
+ const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../utils/logger/index.cjs`),n=require(`./CustomFieldDefinition.cjs`),r=require(`./CustomFieldValue.cjs`),i=require(`./tests/AssociatedTestModel.cjs`),a=require(`./tests/TestModel.cjs`),o=require(`./tests/contextAwareModels/ContextTestModel.cjs`),s=require(`./tests/contextAwareModels/ContextAwareTestModel.cjs`),c=require(`./CustomFieldEntries.cjs`),l=require(`./CustomValidator.cjs`);let u=require(`sequelize`);const d=[n.default,r.default,l.default],f=[a.default,i.default,s.default,o.default],p=`sadot-migration`,m=`49c9dd1d-b1cc-445b-a911-fd349d783110`,h=async(e,i,{schemaPrefix:a=`sadot-migration`,schemaVersion:o=`49c9dd1d-b1cc-445b-a911-fd349d783110`,useCustomFieldsEntries:s=!1}={})=>{let f=`${a}_${o}${s?`_withEntries`:``}`;if(t.default.info(`custom-fields: initialize custom-fields tables`),!e.addModels)throw Error(`sequelize instance must have addModels function`);s&&d.push(c.default),e.addModels(d),n.default.addScope(`userScope`,()=>{let e=i();return e?.permissions?{where:{entityId:[...Object.keys(e.permissions.fleets),...Object.keys(e.permissions.businessModels),...Object.keys(e.permissions.demandSources)]}}:{}}),l.default.addScope(`userScope`,()=>{let e=i();return e?.permissions?{where:{entityId:[...Object.keys(e.permissions.fleets),...Object.keys(e.permissions.businessModels),...Object.keys(e.permissions.demandSources)]}}:{}}),t.default.info(`custom-fields: models added`);let p=e.define(`SequelizeMeta`,{name:{type:u.DataTypes.STRING,allowNull:!1,unique:!0,primaryKey:!0,autoIncrement:!1}},{tableName:`SequelizeMeta`,timestamps:!1,schema:`public`});t.default.info(`custom-fields: starting migrations`);let m=await p.findAll({where:{name:{[u.Op.like]:`${a}%`}},raw:!0}),h=m.at(-1),g=m.findIndex(e=>e.name===f);if(t.default.info(`custom-fields: migrations`,{migrations:m,currentSadotSchemaVersion:h,expectedSchemaVersionIndex:g}),(!h||h.name!==f)&&(t.default.info(`custom-fields: syncing models`),await n.default.sync({alter:!0}),await r.default.sync({alter:!0}),s&&await c.default.sync({alter:!0}),await l.default.sync({alter:!0}),g===-1&&await p.create({name:f}),t.default.info(`custom-fields: models synced`),m.length&&g!==-1&&g<m.length-1)){let e=m.slice(g+1);await p.destroy({where:{name:{[u.Op.in]:e.map(e=>e.name)}}})}},g=async e=>{if(t.default.info(`custom-fields: initialize custom-fields test models`),!e.addModels)throw Error(`sequelize instance must have addModels function`);e.addModels(f),await e.dropSchema(`custom-fields`,{logging:!1}),await e.createSchema(`custom-fields`,{logging:!1}),t.default.info(`custom-fields: test models added`),await a.default.sync({alter:!0}),await i.default.sync({alter:!0}),await o.default.sync({alter:!0}),await s.default.sync({alter:!0}),t.default.info(`custom-fields: test models synced`)};exports.initTables=h,exports.initTestModels=g;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["productionModels: ProductionModel[]","CustomFieldDefinition","CustomFieldValue","CustomValidator","TestModel","AssociatedTestModel","ContextAwareTestModel","ContextTestModel","sequelize","CustomFieldEntries","DataTypes","Op"],"sources":["../../src/models/index.ts"],"sourcesContent":["import { DataTypes, Op } from 'sequelize';\nimport type { Sequelize } from 'sequelize-typescript';\nimport logger from '../utils/logger';\nimport CustomFieldDefinition from './CustomFieldDefinition';\nimport CustomFieldValue from './CustomFieldValue';\nimport TestModel from './tests/TestModel';\nimport ContextAwareTestModel from './tests/contextAwareModels/ContextAwareTestModel';\nimport ContextTestModel from './tests/contextAwareModels/ContextTestModel';\nimport AssociatedTestModel from './tests/AssociatedTestModel';\nimport type { CustomFieldOptions } from '../types';\nimport CustomFieldEntries from './CustomFieldEntries';\nimport CustomValidator from './CustomValidator';\n\ntype ProductionModel = typeof CustomFieldDefinition | typeof CustomFieldValue | typeof CustomFieldEntries | typeof CustomValidator;\ninterface InitTablesOptions {\n schemaPrefix?: string;\n schemaVersion?: string;\n useCustomFieldsEntries?: boolean;\n}\n\nconst productionModels: ProductionModel[] = [CustomFieldDefinition, CustomFieldValue, CustomValidator];\nconst testModels = [TestModel, AssociatedTestModel, ContextAwareTestModel, ContextTestModel];\n\nconst SADOT_MIGRATION_PREFIX = 'sadot-migration';\nconst SCHEMA_VERSION = '49c9dd1d-b1cc-445b-a911-fd349d783110';\n\nconst initTables = async (\n sequelize: Sequelize,\n getUser: CustomFieldOptions['getUser'],\n {\n schemaPrefix = SADOT_MIGRATION_PREFIX,\n schemaVersion = SCHEMA_VERSION,\n useCustomFieldsEntries = false,\n }: InitTablesOptions = {},\n): Promise<void> => {\n const CUSTOM_FIELDS_SCHEMA_VERSION = `${schemaPrefix}_${schemaVersion}${useCustomFieldsEntries ? '_withEntries' : ''}`;\n logger.info('custom-fields: initialize custom-fields tables');\n // Detect models and import them to the orm\n if (!sequelize.addModels) {\n throw new Error('sequelize instance must have addModels function');\n }\n\n if (useCustomFieldsEntries) {\n productionModels.push(CustomFieldEntries);\n }\n\n sequelize.addModels(productionModels);\n\n CustomFieldDefinition.addScope('userScope', () => {\n const user = getUser();\n if (!user?.permissions) {\n return {};\n }\n return {\n where: {\n entityId: [\n ...Object.keys(user.permissions.fleets),\n ...Object.keys(user.permissions.businessModels),\n ...Object.keys(user.permissions.demandSources),\n ],\n },\n };\n });\n\n CustomValidator.addScope('userScope', () => {\n const user = getUser();\n if (!user?.permissions) {\n return {};\n }\n return {\n where: {\n entityId: [\n ...Object.keys(user.permissions.fleets),\n ...Object.keys(user.permissions.businessModels),\n ...Object.keys(user.permissions.demandSources),\n ],\n },\n };\n });\n\n logger.info('custom-fields: models added');\n\n const SequelizeMeta = sequelize.define(\n 'SequelizeMeta',\n {\n name: {\n type: DataTypes.STRING,\n allowNull: false,\n unique: true,\n primaryKey: true,\n autoIncrement: false,\n },\n },\n {\n tableName: 'SequelizeMeta',\n timestamps: false,\n schema: 'public',\n },\n );\n\n logger.info('custom-fields: starting migrations');\n const migrations = await SequelizeMeta.findAll({ where: { name: { [Op.like]: `${schemaPrefix}%` } }, raw: true });\n const currentSadotSchemaVersion = migrations.at(-1);\n const expectedSchemaVersionIndex = migrations.findIndex(m => (m as any).name === CUSTOM_FIELDS_SCHEMA_VERSION);\n\n logger.info('custom-fields: migrations', { migrations, currentSadotSchemaVersion, expectedSchemaVersionIndex });\n if (!currentSadotSchemaVersion || (currentSadotSchemaVersion as any).name !== CUSTOM_FIELDS_SCHEMA_VERSION) {\n logger.info('custom-fields: syncing models');\n await CustomFieldDefinition.sync({ alter: true });\n await CustomFieldValue.sync({ alter: true });\n // T.Y TODO: Remove the if statement once we're ready to add the new entries table for all MS\n if (useCustomFieldsEntries) {\n await CustomFieldEntries.sync({ alter: true });\n }\n\n // Always sync CustomValidator\n await CustomValidator.sync({ alter: true });\n\n if (expectedSchemaVersionIndex === -1) {\n await SequelizeMeta.create({ name: CUSTOM_FIELDS_SCHEMA_VERSION });\n }\n logger.info('custom-fields: models synced');\n if (migrations.length && expectedSchemaVersionIndex !== -1 && expectedSchemaVersionIndex < migrations.length - 1) {\n // We have existing migrations, and we are calling `sync`.\n // This means we are in a `down` migration, and hence we should delete newer migrations to ensure we can reapply them.\n const migrationsToDelete = migrations.slice(expectedSchemaVersionIndex + 1);\n await SequelizeMeta.destroy({ where: { name: { [Op.in]: migrationsToDelete.map(m => (m as any).name) } } });\n }\n }\n};\n\nconst initTestModels = async (sequelize: Sequelize): Promise<void> => {\n logger.info('custom-fields: initialize custom-fields test models');\n // Detect models and import them to the orm\n if (!sequelize.addModels) {\n throw new Error('sequelize instance must have addModels function');\n }\n\n sequelize.addModels(testModels);\n await sequelize.dropSchema('custom-fields', { logging: false });\n await sequelize.createSchema('custom-fields', { logging: false });\n\n logger.info('custom-fields: test models added');\n await TestModel.sync({ alter: true });\n await AssociatedTestModel.sync({ alter: true });\n await ContextTestModel.sync({ alter: true });\n await ContextAwareTestModel.sync({ alter: true });\n logger.info('custom-fields: test models synced');\n};\n\nexport {\n CustomFieldValue,\n CustomFieldDefinition,\n CustomFieldEntries,\n CustomValidator,\n TestModel,\n AssociatedTestModel,\n ContextAwareTestModel,\n ContextTestModel,\n initTables,\n initTestModels,\n};\n"],"mappings":"0eAoBA,MAAMA,EAAsC,CAACC,EAAAA,QAAuBC,EAAAA,QAAkBC,EAAAA,QAAgB,CAChG,EAAa,CAACC,EAAAA,QAAWC,EAAAA,QAAqBC,EAAAA,QAAuBC,EAAAA,QAAiB,CAEtF,EAAyB,kBACzB,EAAiB,uCAEjB,EAAa,MACjB,EACA,EACA,CACE,eAAe,kBACf,gBAAgB,uCAChB,yBAAyB,IACJ,EAAE,GACP,CAClB,IAAM,EAA+B,GAAG,EAAa,GAAG,IAAgB,EAAyB,eAAiB,KAGlH,GAFA,EAAA,QAAO,KAAK,iDAAiD,CAEzD,CAACC,EAAU,UACb,MAAU,MAAM,kDAAkD,CAGhE,GACF,EAAiB,KAAKC,EAAAA,QAAmB,CAG3C,EAAU,UAAU,EAAiB,CAErC,EAAA,QAAsB,SAAS,gBAAmB,CAChD,IAAM,EAAO,GAAS,CAItB,OAHK,GAAM,YAGJ,CACL,MAAO,CACL,SAAU,CACR,GAAG,OAAO,KAAK,EAAK,YAAY,OAAO,CACvC,GAAG,OAAO,KAAK,EAAK,YAAY,eAAe,CAC/C,GAAG,OAAO,KAAK,EAAK,YAAY,cAAc,CAC/C,CACF,CACF,CAVQ,EAAE,EAWX,CAEF,EAAA,QAAgB,SAAS,gBAAmB,CAC1C,IAAM,EAAO,GAAS,CAItB,OAHK,GAAM,YAGJ,CACL,MAAO,CACL,SAAU,CACR,GAAG,OAAO,KAAK,EAAK,YAAY,OAAO,CACvC,GAAG,OAAO,KAAK,EAAK,YAAY,eAAe,CAC/C,GAAG,OAAO,KAAK,EAAK,YAAY,cAAc,CAC/C,CACF,CACF,CAVQ,EAAE,EAWX,CAEF,EAAA,QAAO,KAAK,8BAA8B,CAE1C,IAAM,EAAgBD,EAAU,OAC9B,gBACA,CACE,KAAM,CACJ,KAAME,EAAAA,UAAU,OAChB,UAAW,GACX,OAAQ,GACR,WAAY,GACZ,cAAe,GAChB,CACF,CACD,CACE,UAAW,gBACX,WAAY,GACZ,OAAQ,SACT,CACF,CAED,EAAA,QAAO,KAAK,qCAAqC,CACjD,IAAM,EAAa,MAAM,EAAc,QAAQ,CAAE,MAAO,CAAE,KAAM,EAAGC,EAAAA,GAAG,MAAO,GAAG,EAAa,GAAI,CAAE,CAAE,IAAK,GAAM,CAAC,CAC3G,EAA4B,EAAW,GAAG,GAAG,CAC7C,EAA6B,EAAW,UAAU,GAAM,EAAU,OAAS,EAA6B,CAG9G,GADA,EAAA,QAAO,KAAK,4BAA6B,CAAE,aAAY,4BAA2B,6BAA4B,CAAC,EAC3G,CAAC,GAA8B,EAAkC,OAAS,KAC5E,EAAA,QAAO,KAAK,gCAAgC,CAC5C,MAAMV,EAAAA,QAAsB,KAAK,CAAE,MAAO,GAAM,CAAC,CACjD,MAAMC,EAAAA,QAAiB,KAAK,CAAE,MAAO,GAAM,CAAC,CAExC,GACF,MAAMO,EAAAA,QAAmB,KAAK,CAAE,MAAO,GAAM,CAAC,CAIhD,MAAMN,EAAAA,QAAgB,KAAK,CAAE,MAAO,GAAM,CAAC,CAEvC,IAA+B,IACjC,MAAM,EAAc,OAAO,CAAE,KAAM,EAA8B,CAAC,CAEpE,EAAA,QAAO,KAAK,+BAA+B,CACvC,EAAW,QAAU,IAA+B,IAAM,EAA6B,EAAW,OAAS,GAAG,CAGhH,IAAM,EAAqB,EAAW,MAAM,EAA6B,EAAE,CAC3E,MAAM,EAAc,QAAQ,CAAE,MAAO,CAAE,KAAM,EAAGQ,EAAAA,GAAG,IAAK,EAAmB,IAAI,GAAM,EAAU,KAAK,CAAE,CAAE,CAAE,CAAC,GAK3G,EAAiB,KAAO,IAAwC,CAGpE,GAFA,EAAA,QAAO,KAAK,sDAAsD,CAE9D,CAACH,EAAU,UACb,MAAU,MAAM,kDAAkD,CAGpE,EAAU,UAAU,EAAW,CAC/B,MAAMA,EAAU,WAAW,gBAAiB,CAAE,QAAS,GAAO,CAAC,CAC/D,MAAMA,EAAU,aAAa,gBAAiB,CAAE,QAAS,GAAO,CAAC,CAEjE,EAAA,QAAO,KAAK,mCAAmC,CAC/C,MAAMJ,EAAAA,QAAU,KAAK,CAAE,MAAO,GAAM,CAAC,CACrC,MAAMC,EAAAA,QAAoB,KAAK,CAAE,MAAO,GAAM,CAAC,CAC/C,MAAME,EAAAA,QAAiB,KAAK,CAAE,MAAO,GAAM,CAAC,CAC5C,MAAMD,EAAAA,QAAsB,KAAK,CAAE,MAAO,GAAM,CAAC,CACjD,EAAA,QAAO,KAAK,oCAAoC"}
1
+ {"version":3,"file":"index.cjs","names":["productionModels: ProductionModel[]","CustomFieldDefinition","CustomFieldValue","CustomValidator","TestModel","AssociatedTestModel","ContextAwareTestModel","ContextTestModel","sequelize","CustomFieldEntries","DataTypes","Op"],"sources":["../../src/models/index.ts"],"sourcesContent":["import { DataTypes, Op } from 'sequelize';\nimport type { Sequelize } from 'sequelize-typescript';\nimport logger from '../utils/logger';\nimport CustomFieldDefinition from './CustomFieldDefinition';\nimport CustomFieldValue from './CustomFieldValue';\nimport TestModel from './tests/TestModel';\nimport ContextAwareTestModel from './tests/contextAwareModels/ContextAwareTestModel';\nimport ContextTestModel from './tests/contextAwareModels/ContextTestModel';\nimport AssociatedTestModel from './tests/AssociatedTestModel';\nimport type { CustomFieldOptions } from '../types';\nimport CustomFieldEntries from './CustomFieldEntries';\nimport CustomValidator from './CustomValidator';\n\ntype ProductionModel = typeof CustomFieldDefinition | typeof CustomFieldValue | typeof CustomFieldEntries | typeof CustomValidator;\ninterface InitTablesOptions {\n schemaPrefix?: string;\n schemaVersion?: string;\n useCustomFieldsEntries?: boolean;\n}\n\nconst productionModels: ProductionModel[] = [CustomFieldDefinition, CustomFieldValue, CustomValidator];\nconst testModels = [TestModel, AssociatedTestModel, ContextAwareTestModel, ContextTestModel];\n\nconst SADOT_MIGRATION_PREFIX = 'sadot-migration';\nconst SCHEMA_VERSION = '49c9dd1d-b1cc-445b-a911-fd349d783110';\n\nconst initTables = async (\n sequelize: Sequelize,\n getUser: CustomFieldOptions['getUser'],\n {\n schemaPrefix = SADOT_MIGRATION_PREFIX,\n schemaVersion = SCHEMA_VERSION,\n useCustomFieldsEntries = false,\n }: InitTablesOptions = {},\n): Promise<void> => {\n const CUSTOM_FIELDS_SCHEMA_VERSION = `${schemaPrefix}_${schemaVersion}${useCustomFieldsEntries ? '_withEntries' : ''}`;\n logger.info('custom-fields: initialize custom-fields tables');\n // Detect models and import them to the orm\n if (!sequelize.addModels) {\n throw new Error('sequelize instance must have addModels function');\n }\n\n if (useCustomFieldsEntries) {\n productionModels.push(CustomFieldEntries);\n }\n\n sequelize.addModels(productionModels);\n\n CustomFieldDefinition.addScope('userScope', () => {\n const user = getUser();\n if (!user?.permissions) {\n return {};\n }\n return {\n where: {\n entityId: [\n ...Object.keys(user.permissions.fleets),\n ...Object.keys(user.permissions.businessModels),\n ...Object.keys(user.permissions.demandSources),\n ],\n },\n };\n });\n\n CustomValidator.addScope('userScope', () => {\n const user = getUser();\n if (!user?.permissions) {\n return {};\n }\n return {\n where: {\n entityId: [\n ...Object.keys(user.permissions.fleets),\n ...Object.keys(user.permissions.businessModels),\n ...Object.keys(user.permissions.demandSources),\n ],\n },\n };\n });\n\n logger.info('custom-fields: models added');\n\n const SequelizeMeta = sequelize.define(\n 'SequelizeMeta',\n {\n name: {\n type: DataTypes.STRING,\n allowNull: false,\n unique: true,\n primaryKey: true,\n autoIncrement: false,\n },\n },\n {\n tableName: 'SequelizeMeta',\n timestamps: false,\n schema: 'public',\n },\n );\n\n logger.info('custom-fields: starting migrations');\n const migrations = await SequelizeMeta.findAll({ where: { name: { [Op.like]: `${schemaPrefix}%` } }, raw: true });\n const currentSadotSchemaVersion = migrations.at(-1);\n const expectedSchemaVersionIndex = migrations.findIndex(m => (m as any).name === CUSTOM_FIELDS_SCHEMA_VERSION);\n\n logger.info('custom-fields: migrations', { migrations, currentSadotSchemaVersion, expectedSchemaVersionIndex });\n if (!currentSadotSchemaVersion || (currentSadotSchemaVersion as any).name !== CUSTOM_FIELDS_SCHEMA_VERSION) {\n logger.info('custom-fields: syncing models');\n await CustomFieldDefinition.sync({ alter: true });\n await CustomFieldValue.sync({ alter: true });\n // T.Y TODO: Remove the if statement once we're ready to add the new entries table for all MS\n if (useCustomFieldsEntries) {\n await CustomFieldEntries.sync({ alter: true });\n }\n\n // Always sync CustomValidator\n await CustomValidator.sync({ alter: true });\n\n if (expectedSchemaVersionIndex === -1) {\n await SequelizeMeta.create({ name: CUSTOM_FIELDS_SCHEMA_VERSION });\n }\n logger.info('custom-fields: models synced');\n if (migrations.length && expectedSchemaVersionIndex !== -1 && expectedSchemaVersionIndex < migrations.length - 1) {\n // We have existing migrations, and we are calling `sync`.\n // This means we are in a `down` migration, and hence we should delete newer migrations to ensure we can reapply them.\n const migrationsToDelete = migrations.slice(expectedSchemaVersionIndex + 1);\n await SequelizeMeta.destroy({ where: { name: { [Op.in]: migrationsToDelete.map(m => (m as any).name) } } });\n }\n }\n};\n\nconst initTestModels = async (sequelize: Sequelize): Promise<void> => {\n logger.info('custom-fields: initialize custom-fields test models');\n // Detect models and import them to the orm\n if (!sequelize.addModels) {\n throw new Error('sequelize instance must have addModels function');\n }\n\n sequelize.addModels(testModels);\n await sequelize.dropSchema('custom-fields', { logging: false });\n await sequelize.createSchema('custom-fields', { logging: false });\n\n logger.info('custom-fields: test models added');\n await TestModel.sync({ alter: true });\n await AssociatedTestModel.sync({ alter: true });\n await ContextTestModel.sync({ alter: true });\n await ContextAwareTestModel.sync({ alter: true });\n logger.info('custom-fields: test models synced');\n};\n\nexport {\n CustomFieldValue,\n CustomFieldDefinition,\n CustomFieldEntries,\n CustomValidator,\n TestModel,\n AssociatedTestModel,\n ContextAwareTestModel,\n ContextTestModel,\n initTables,\n initTestModels,\n};\n"],"mappings":"2dAoBA,MAAMA,EAAsC,CAACC,EAAAA,QAAuBC,EAAAA,QAAkBC,EAAAA,QAAgB,CAChG,EAAa,CAACC,EAAAA,QAAWC,EAAAA,QAAqBC,EAAAA,QAAuBC,EAAAA,QAAiB,CAEtF,EAAyB,kBACzB,EAAiB,uCAEjB,EAAa,MACjB,EACA,EACA,CACE,eAAe,kBACf,gBAAgB,uCAChB,yBAAyB,IACJ,EAAE,GACP,CAClB,IAAM,EAA+B,GAAG,EAAa,GAAG,IAAgB,EAAyB,eAAiB,KAGlH,GAFA,EAAA,QAAO,KAAK,iDAAiD,CAEzD,CAACC,EAAU,UACb,MAAU,MAAM,kDAAkD,CAGhE,GACF,EAAiB,KAAKC,EAAAA,QAAmB,CAG3C,EAAU,UAAU,EAAiB,CAErC,EAAA,QAAsB,SAAS,gBAAmB,CAChD,IAAM,EAAO,GAAS,CAItB,OAHK,GAAM,YAGJ,CACL,MAAO,CACL,SAAU,CACR,GAAG,OAAO,KAAK,EAAK,YAAY,OAAO,CACvC,GAAG,OAAO,KAAK,EAAK,YAAY,eAAe,CAC/C,GAAG,OAAO,KAAK,EAAK,YAAY,cAAc,CAC/C,CACF,CACF,CAVQ,EAAE,EAWX,CAEF,EAAA,QAAgB,SAAS,gBAAmB,CAC1C,IAAM,EAAO,GAAS,CAItB,OAHK,GAAM,YAGJ,CACL,MAAO,CACL,SAAU,CACR,GAAG,OAAO,KAAK,EAAK,YAAY,OAAO,CACvC,GAAG,OAAO,KAAK,EAAK,YAAY,eAAe,CAC/C,GAAG,OAAO,KAAK,EAAK,YAAY,cAAc,CAC/C,CACF,CACF,CAVQ,EAAE,EAWX,CAEF,EAAA,QAAO,KAAK,8BAA8B,CAE1C,IAAM,EAAgBD,EAAU,OAC9B,gBACA,CACE,KAAM,CACJ,KAAME,EAAAA,UAAU,OAChB,UAAW,GACX,OAAQ,GACR,WAAY,GACZ,cAAe,GAChB,CACF,CACD,CACE,UAAW,gBACX,WAAY,GACZ,OAAQ,SACT,CACF,CAED,EAAA,QAAO,KAAK,qCAAqC,CACjD,IAAM,EAAa,MAAM,EAAc,QAAQ,CAAE,MAAO,CAAE,KAAM,EAAGC,EAAAA,GAAG,MAAO,GAAG,EAAa,GAAI,CAAE,CAAE,IAAK,GAAM,CAAC,CAC3G,EAA4B,EAAW,GAAG,GAAG,CAC7C,EAA6B,EAAW,UAAU,GAAM,EAAU,OAAS,EAA6B,CAG9G,GADA,EAAA,QAAO,KAAK,4BAA6B,CAAE,aAAY,4BAA2B,6BAA4B,CAAC,EAC3G,CAAC,GAA8B,EAAkC,OAAS,KAC5E,EAAA,QAAO,KAAK,gCAAgC,CAC5C,MAAMV,EAAAA,QAAsB,KAAK,CAAE,MAAO,GAAM,CAAC,CACjD,MAAMC,EAAAA,QAAiB,KAAK,CAAE,MAAO,GAAM,CAAC,CAExC,GACF,MAAMO,EAAAA,QAAmB,KAAK,CAAE,MAAO,GAAM,CAAC,CAIhD,MAAMN,EAAAA,QAAgB,KAAK,CAAE,MAAO,GAAM,CAAC,CAEvC,IAA+B,IACjC,MAAM,EAAc,OAAO,CAAE,KAAM,EAA8B,CAAC,CAEpE,EAAA,QAAO,KAAK,+BAA+B,CACvC,EAAW,QAAU,IAA+B,IAAM,EAA6B,EAAW,OAAS,GAAG,CAGhH,IAAM,EAAqB,EAAW,MAAM,EAA6B,EAAE,CAC3E,MAAM,EAAc,QAAQ,CAAE,MAAO,CAAE,KAAM,EAAGQ,EAAAA,GAAG,IAAK,EAAmB,IAAI,GAAM,EAAU,KAAK,CAAE,CAAE,CAAE,CAAC,GAK3G,EAAiB,KAAO,IAAwC,CAGpE,GAFA,EAAA,QAAO,KAAK,sDAAsD,CAE9D,CAACH,EAAU,UACb,MAAU,MAAM,kDAAkD,CAGpE,EAAU,UAAU,EAAW,CAC/B,MAAMA,EAAU,WAAW,gBAAiB,CAAE,QAAS,GAAO,CAAC,CAC/D,MAAMA,EAAU,aAAa,gBAAiB,CAAE,QAAS,GAAO,CAAC,CAEjE,EAAA,QAAO,KAAK,mCAAmC,CAC/C,MAAMJ,EAAAA,QAAU,KAAK,CAAE,MAAO,GAAM,CAAC,CACrC,MAAMC,EAAAA,QAAoB,KAAK,CAAE,MAAO,GAAM,CAAC,CAC/C,MAAME,EAAAA,QAAiB,KAAK,CAAE,MAAO,GAAM,CAAC,CAC5C,MAAMD,EAAAA,QAAsB,KAAK,CAAE,MAAO,GAAM,CAAC,CACjD,EAAA,QAAO,KAAK,oCAAoC"}
@@ -0,0 +1,4 @@
1
+ import "./CustomFieldValue.cjs";
2
+ import "./CustomFieldDefinition.cjs";
3
+ import "../types/index.cjs";
4
+ import { Sequelize } from "sequelize-typescript";
@@ -0,0 +1,6 @@
1
+ import "./CustomFieldValue.js";
2
+ import "./CustomFieldEntries.js";
3
+ import "./CustomValidator.js";
4
+ import "./CustomFieldDefinition.js";
5
+ import "../types/index.js";
6
+ import { Sequelize } from "sequelize-typescript";
@@ -1,2 +1,2 @@
1
- const e=require(`../../_virtual/rolldown_runtime.cjs`),t=require(`../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorateMetadata.cjs`),n=require(`../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorate.cjs`),r=require(`./TestModel.cjs`);let i=require(`sequelize-typescript`);i=e.__toESM(i);var a;let o=class extends i.Model{};n.__decorate([i.PrimaryKey,(0,i.Column)({type:i.DataType.UUID,defaultValue:i.DataType.UUIDV4,allowNull:!1}),t.__decorateMetadata(`design:type`,String)],o.prototype,`id`,void 0),n.__decorate([(0,i.ForeignKey)(()=>r.default),(0,i.Column)({type:i.DataType.UUID,allowNull:!1}),t.__decorateMetadata(`design:type`,String)],o.prototype,`testModelId`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.UUID,allowNull:!1}),t.__decorateMetadata(`design:type`,String)],o.prototype,`fleetId`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.UUID,allowNull:!0}),t.__decorateMetadata(`design:type`,String)],o.prototype,`businessModelId`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.UUID,allowNull:!0}),t.__decorateMetadata(`design:type`,String)],o.prototype,`demandSourceId`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.BOOLEAN}),t.__decorateMetadata(`design:type`,Boolean)],o.prototype,`anotherAttribute`,void 0),n.__decorate([(0,i.BelongsTo)(()=>r.default),t.__decorateMetadata(`design:type`,typeof(a=r.default!==void 0&&r.default)==`function`?a:Object)],o.prototype,`testModel`,void 0),o=n.__decorate([(0,i.Table)({schema:`custom-fields`,tableName:`associated_test_models`,createdAt:!1,updatedAt:!1,modelName:`AssociatedTestModel`})],o);var s=o;exports.default=s;
1
+ const e=require(`../../_virtual/rolldown_runtime.cjs`),t=require(`../../_virtual/_@oxc-project_runtime@0.96.0/helpers/decorateMetadata.cjs`),n=require(`../../_virtual/_@oxc-project_runtime@0.96.0/helpers/decorate.cjs`),r=require(`./TestModel.cjs`);let i=require(`sequelize-typescript`);var a;let o=class extends i.Model{};n.__decorate([i.PrimaryKey,(0,i.Column)({type:i.DataType.UUID,defaultValue:i.DataType.UUIDV4,allowNull:!1}),t.__decorateMetadata(`design:type`,String)],o.prototype,`id`,void 0),n.__decorate([(0,i.ForeignKey)(()=>r.default),(0,i.Column)({type:i.DataType.UUID,allowNull:!1}),t.__decorateMetadata(`design:type`,String)],o.prototype,`testModelId`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.UUID,allowNull:!1}),t.__decorateMetadata(`design:type`,String)],o.prototype,`fleetId`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.UUID,allowNull:!0}),t.__decorateMetadata(`design:type`,String)],o.prototype,`businessModelId`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.UUID,allowNull:!0}),t.__decorateMetadata(`design:type`,String)],o.prototype,`demandSourceId`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.BOOLEAN}),t.__decorateMetadata(`design:type`,Boolean)],o.prototype,`anotherAttribute`,void 0),n.__decorate([(0,i.BelongsTo)(()=>r.default),t.__decorateMetadata(`design:type`,typeof(a=r.default!==void 0&&r.default)==`function`?a:Object)],o.prototype,`testModel`,void 0),o=n.__decorate([(0,i.Table)({schema:`custom-fields`,tableName:`associated_test_models`,createdAt:!1,updatedAt:!1,modelName:`AssociatedTestModel`})],o);var s=o;exports.default=s;
2
2
  //# sourceMappingURL=AssociatedTestModel.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"AssociatedTestModel.cjs","names":["AssociatedTestModel","Model","PrimaryKey","DataType","TestModel"],"sources":["../../../src/models/tests/AssociatedTestModel.ts"],"sourcesContent":["import {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n ForeignKey,\n BelongsTo,\n} from 'sequelize-typescript';\nimport TestModel from './TestModel';\n\n@Table({\n schema: 'custom-fields', tableName: 'associated_test_models', createdAt: false, updatedAt: false, modelName: 'AssociatedTestModel',\n})\nclass AssociatedTestModel extends Model {\n @PrimaryKey\n @Column({\n type: DataType.UUID,\n defaultValue: DataType.UUIDV4,\n allowNull: false,\n })\n declare id: string;\n\n @ForeignKey(() => TestModel)\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n testModelId!: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n declare fleetId: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: true,\n })\n declare businessModelId: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: true,\n })\n declare demandSourceId: string;\n\n @Column({\n type: DataType.BOOLEAN,\n })\n anotherAttribute?: boolean;\n\n @BelongsTo(() => TestModel)\n declare testModel: TestModel;\n}\n\nexport default AssociatedTestModel;\n"],"mappings":"mTAWA,IAAA,EAAA,cAGkCC,EAAAA,KAAM,iBACrCC,EAAAA,wBACO,CACN,KAAMC,EAAAA,SAAS,KACf,aAAcA,EAAAA,SAAS,OACvB,UAAW,GACZ,CAAC,yGAGgBC,EAAAA,QAAU,cACpB,CACN,KAAMD,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,0GAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,UAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,kBAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,iBAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,QAChB,CAAC,CAAA,EAAA,mBAAA,cAAA,QAAA,CAAA,CAAA,EAAA,UAAA,mBAAA,IAAA,GAAA,mCAGeC,EAAAA,QAAU,CAAA,EAAA,mBAAA,cAAA,OAAA,EAAA,EAAA,UAAA,QAAA,EAAA,UAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,6BA1CtB,CACL,OAAQ,gBAAiB,UAAW,yBAA0B,UAAW,GAAO,UAAW,GAAO,UAAW,sBAC9G,CAAC,CAAA,CAAA,EAAA,CA4CF,IAAA,EAAe"}
1
+ {"version":3,"file":"AssociatedTestModel.cjs","names":["AssociatedTestModel","Model","PrimaryKey","DataType","TestModel"],"sources":["../../../src/models/tests/AssociatedTestModel.ts"],"sourcesContent":["import {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n ForeignKey,\n BelongsTo,\n} from 'sequelize-typescript';\nimport TestModel from './TestModel';\n\n@Table({\n schema: 'custom-fields', tableName: 'associated_test_models', createdAt: false, updatedAt: false, modelName: 'AssociatedTestModel',\n})\nclass AssociatedTestModel extends Model {\n @PrimaryKey\n @Column({\n type: DataType.UUID,\n defaultValue: DataType.UUIDV4,\n allowNull: false,\n })\n declare id: string;\n\n @ForeignKey(() => TestModel)\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n testModelId!: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n declare fleetId: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: true,\n })\n declare businessModelId: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: true,\n })\n declare demandSourceId: string;\n\n @Column({\n type: DataType.BOOLEAN,\n })\n anotherAttribute?: boolean;\n\n @BelongsTo(() => TestModel)\n declare testModel: TestModel;\n}\n\nexport default AssociatedTestModel;\n"],"mappings":"oSAWA,IAAA,EAAA,cAGkCC,EAAAA,KAAM,iBACrCC,EAAAA,wBACO,CACN,KAAMC,EAAAA,SAAS,KACf,aAAcA,EAAAA,SAAS,OACvB,UAAW,GACZ,CAAC,yGAGgBC,EAAAA,QAAU,cACpB,CACN,KAAMD,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,0GAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,UAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,kBAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,iBAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,QAChB,CAAC,CAAA,EAAA,mBAAA,cAAA,QAAA,CAAA,CAAA,EAAA,UAAA,mBAAA,IAAA,GAAA,mCAGeC,EAAAA,QAAU,CAAA,EAAA,mBAAA,cAAA,OAAA,EAAA,EAAA,UAAA,QAAA,EAAA,UAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,6BA1CtB,CACL,OAAQ,gBAAiB,UAAW,yBAA0B,UAAW,GAAO,UAAW,GAAO,UAAW,sBAC9G,CAAC,CAAA,CAAA,EAAA,CA4CF,IAAA,EAAe"}
@@ -1,2 +1,2 @@
1
- import{__decorateMetadata as e}from"../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorateMetadata.js";import{__decorate as t}from"../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorate.js";import n from"./TestModel.js";import{BelongsTo as r,Column as i,DataType as a,ForeignKey as o,Model as s,PrimaryKey as c,Table as l}from"sequelize-typescript";var u;let d=class extends s{};t([c,i({type:a.UUID,defaultValue:a.UUIDV4,allowNull:!1}),e(`design:type`,String)],d.prototype,`id`,void 0),t([o(()=>n),i({type:a.UUID,allowNull:!1}),e(`design:type`,String)],d.prototype,`testModelId`,void 0),t([i({type:a.UUID,allowNull:!1}),e(`design:type`,String)],d.prototype,`fleetId`,void 0),t([i({type:a.UUID,allowNull:!0}),e(`design:type`,String)],d.prototype,`businessModelId`,void 0),t([i({type:a.UUID,allowNull:!0}),e(`design:type`,String)],d.prototype,`demandSourceId`,void 0),t([i({type:a.BOOLEAN}),e(`design:type`,Boolean)],d.prototype,`anotherAttribute`,void 0),t([r(()=>n),e(`design:type`,typeof(u=n!==void 0&&n)==`function`?u:Object)],d.prototype,`testModel`,void 0),d=t([l({schema:`custom-fields`,tableName:`associated_test_models`,createdAt:!1,updatedAt:!1,modelName:`AssociatedTestModel`})],d);var f=d;export{f as default};
1
+ import{__decorateMetadata as e}from"../../_virtual/_@oxc-project_runtime@0.96.0/helpers/decorateMetadata.js";import{__decorate as t}from"../../_virtual/_@oxc-project_runtime@0.96.0/helpers/decorate.js";import n from"./TestModel.js";import{BelongsTo as r,Column as i,DataType as a,ForeignKey as o,Model as s,PrimaryKey as c,Table as l}from"sequelize-typescript";var u;let d=class extends s{};t([c,i({type:a.UUID,defaultValue:a.UUIDV4,allowNull:!1}),e(`design:type`,String)],d.prototype,`id`,void 0),t([o(()=>n),i({type:a.UUID,allowNull:!1}),e(`design:type`,String)],d.prototype,`testModelId`,void 0),t([i({type:a.UUID,allowNull:!1}),e(`design:type`,String)],d.prototype,`fleetId`,void 0),t([i({type:a.UUID,allowNull:!0}),e(`design:type`,String)],d.prototype,`businessModelId`,void 0),t([i({type:a.UUID,allowNull:!0}),e(`design:type`,String)],d.prototype,`demandSourceId`,void 0),t([i({type:a.BOOLEAN}),e(`design:type`,Boolean)],d.prototype,`anotherAttribute`,void 0),t([r(()=>n),e(`design:type`,typeof(u=n!==void 0&&n)==`function`?u:Object)],d.prototype,`testModel`,void 0),d=t([l({schema:`custom-fields`,tableName:`associated_test_models`,createdAt:!1,updatedAt:!1,modelName:`AssociatedTestModel`})],d);var f=d;export{f as default};
2
2
  //# sourceMappingURL=AssociatedTestModel.js.map
@@ -1,2 +1,2 @@
1
- const e=require(`../../_virtual/rolldown_runtime.cjs`),t=require(`../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorateMetadata.cjs`),n=require(`../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorate.cjs`),r=require(`./AssociatedTestModel.cjs`);let i=require(`sequelize-typescript`);i=e.__toESM(i);let a=class extends i.Model{};n.__decorate([i.PrimaryKey,(0,i.Column)({type:i.DataType.UUID,defaultValue:i.DataType.UUIDV4,allowNull:!1}),t.__decorateMetadata(`design:type`,String)],a.prototype,`id`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.UUID,allowNull:!1}),t.__decorateMetadata(`design:type`,String)],a.prototype,`fleetId`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.UUID,allowNull:!0}),t.__decorateMetadata(`design:type`,String)],a.prototype,`businessModelId`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.UUID,allowNull:!0}),t.__decorateMetadata(`design:type`,String)],a.prototype,`demandSourceId`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.BOOLEAN}),t.__decorateMetadata(`design:type`,Boolean)],a.prototype,`coolAttribute`,void 0),n.__decorate([(0,i.HasMany)(()=>r.default),t.__decorateMetadata(`design:type`,Array)],a.prototype,`associatedModels`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.VIRTUAL}),t.__decorateMetadata(`design:type`,Object)],a.prototype,`customFields`,void 0),a=n.__decorate([(0,i.Table)({schema:`custom-fields`,tableName:`test_models`,createdAt:!1,updatedAt:!1,modelName:`TestModel`})],a);var o=a;exports.default=o;
1
+ const e=require(`../../_virtual/rolldown_runtime.cjs`),t=require(`../../_virtual/_@oxc-project_runtime@0.96.0/helpers/decorateMetadata.cjs`),n=require(`../../_virtual/_@oxc-project_runtime@0.96.0/helpers/decorate.cjs`),r=require(`./AssociatedTestModel.cjs`);let i=require(`sequelize-typescript`),a=class extends i.Model{};n.__decorate([i.PrimaryKey,(0,i.Column)({type:i.DataType.UUID,defaultValue:i.DataType.UUIDV4,allowNull:!1}),t.__decorateMetadata(`design:type`,String)],a.prototype,`id`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.UUID,allowNull:!1}),t.__decorateMetadata(`design:type`,String)],a.prototype,`fleetId`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.UUID,allowNull:!0}),t.__decorateMetadata(`design:type`,String)],a.prototype,`businessModelId`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.UUID,allowNull:!0}),t.__decorateMetadata(`design:type`,String)],a.prototype,`demandSourceId`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.BOOLEAN}),t.__decorateMetadata(`design:type`,Boolean)],a.prototype,`coolAttribute`,void 0),n.__decorate([(0,i.HasMany)(()=>r.default),t.__decorateMetadata(`design:type`,Array)],a.prototype,`associatedModels`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.VIRTUAL}),t.__decorateMetadata(`design:type`,Object)],a.prototype,`customFields`,void 0),a=n.__decorate([(0,i.Table)({schema:`custom-fields`,tableName:`test_models`,createdAt:!1,updatedAt:!1,modelName:`TestModel`})],a);var o=a;exports.default=o;
2
2
  //# sourceMappingURL=TestModel.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"TestModel.cjs","names":["TestModel","Model","PrimaryKey","DataType","AssociatedTestModel"],"sources":["../../../src/models/tests/TestModel.ts"],"sourcesContent":["import {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n HasMany,\n} from 'sequelize-typescript';\nimport AssociatedTestModel from './AssociatedTestModel';\n\n@Table({\n schema: 'custom-fields', tableName: 'test_models', createdAt: false, updatedAt: false, modelName: 'TestModel',\n})\nclass TestModel extends Model {\n @PrimaryKey\n @Column({\n type: DataType.UUID,\n defaultValue: DataType.UUIDV4,\n allowNull: false,\n })\n declare id: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n declare fleetId: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: true,\n })\n declare businessModelId: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: true,\n })\n declare demandSourceId: string;\n\n @Column({\n type: DataType.BOOLEAN,\n })\n coolAttribute?: boolean;\n\n @HasMany(() => AssociatedTestModel)\n declare associatedModels: AssociatedTestModel[];\n\n @Column({\n type: DataType.VIRTUAL,\n })\n customFields?: any;\n}\n\nexport default TestModel;\n"],"mappings":"uTAUA,IAAA,EAAA,cAGwBC,EAAAA,KAAM,iBAC3BC,EAAAA,wBACO,CACN,KAAMC,EAAAA,SAAS,KACf,aAAcA,EAAAA,SAAS,OACvB,UAAW,GACZ,CAAC,iGAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,UAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,kBAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,iBAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,QAChB,CAAC,CAAA,EAAA,mBAAA,cAAA,QAAA,CAAA,CAAA,EAAA,UAAA,gBAAA,IAAA,GAAA,iCAGaC,EAAAA,QAAoB,CAAA,EAAA,mBAAA,cAAA,MAAA,CAAA,CAAA,EAAA,UAAA,mBAAA,IAAA,GAAA,4BAG3B,CACN,KAAMD,EAAAA,SAAS,QAChB,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,eAAA,IAAA,GAAA,6BAxCG,CACL,OAAQ,gBAAiB,UAAW,cAAe,UAAW,GAAO,UAAW,GAAO,UAAW,YACnG,CAAC,CAAA,CAAA,EAAA,CA0CF,IAAA,EAAe"}
1
+ {"version":3,"file":"TestModel.cjs","names":["TestModel","Model","PrimaryKey","DataType","AssociatedTestModel"],"sources":["../../../src/models/tests/TestModel.ts"],"sourcesContent":["import {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n HasMany,\n} from 'sequelize-typescript';\nimport AssociatedTestModel from './AssociatedTestModel';\n\n@Table({\n schema: 'custom-fields', tableName: 'test_models', createdAt: false, updatedAt: false, modelName: 'TestModel',\n})\nclass TestModel extends Model {\n @PrimaryKey\n @Column({\n type: DataType.UUID,\n defaultValue: DataType.UUIDV4,\n allowNull: false,\n })\n declare id: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n declare fleetId: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: true,\n })\n declare businessModelId: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: true,\n })\n declare demandSourceId: string;\n\n @Column({\n type: DataType.BOOLEAN,\n })\n coolAttribute?: boolean;\n\n @HasMany(() => AssociatedTestModel)\n declare associatedModels: AssociatedTestModel[];\n\n @Column({\n type: DataType.VIRTUAL,\n })\n customFields?: any;\n}\n\nexport default TestModel;\n"],"mappings":"wSAUA,EAAA,cAGwBC,EAAAA,KAAM,iBAC3BC,EAAAA,wBACO,CACN,KAAMC,EAAAA,SAAS,KACf,aAAcA,EAAAA,SAAS,OACvB,UAAW,GACZ,CAAC,iGAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,UAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,kBAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,iBAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,QAChB,CAAC,CAAA,EAAA,mBAAA,cAAA,QAAA,CAAA,CAAA,EAAA,UAAA,gBAAA,IAAA,GAAA,iCAGaC,EAAAA,QAAoB,CAAA,EAAA,mBAAA,cAAA,MAAA,CAAA,CAAA,EAAA,UAAA,mBAAA,IAAA,GAAA,4BAG3B,CACN,KAAMD,EAAAA,SAAS,QAChB,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,eAAA,IAAA,GAAA,6BAxCG,CACL,OAAQ,gBAAiB,UAAW,cAAe,UAAW,GAAO,UAAW,GAAO,UAAW,YACnG,CAAC,CAAA,CAAA,EAAA,CA0CF,IAAA,EAAe"}
@@ -1,2 +1,2 @@
1
- import{__decorateMetadata as e}from"../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorateMetadata.js";import{__decorate as t}from"../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorate.js";import n from"./AssociatedTestModel.js";import{Column as r,DataType as i,HasMany as a,Model as o,PrimaryKey as s,Table as c}from"sequelize-typescript";let l=class extends o{};t([s,r({type:i.UUID,defaultValue:i.UUIDV4,allowNull:!1}),e(`design:type`,String)],l.prototype,`id`,void 0),t([r({type:i.UUID,allowNull:!1}),e(`design:type`,String)],l.prototype,`fleetId`,void 0),t([r({type:i.UUID,allowNull:!0}),e(`design:type`,String)],l.prototype,`businessModelId`,void 0),t([r({type:i.UUID,allowNull:!0}),e(`design:type`,String)],l.prototype,`demandSourceId`,void 0),t([r({type:i.BOOLEAN}),e(`design:type`,Boolean)],l.prototype,`coolAttribute`,void 0),t([a(()=>n),e(`design:type`,Array)],l.prototype,`associatedModels`,void 0),t([r({type:i.VIRTUAL}),e(`design:type`,Object)],l.prototype,`customFields`,void 0),l=t([c({schema:`custom-fields`,tableName:`test_models`,createdAt:!1,updatedAt:!1,modelName:`TestModel`})],l);var u=l;export{u as default};
1
+ import{__decorateMetadata as e}from"../../_virtual/_@oxc-project_runtime@0.96.0/helpers/decorateMetadata.js";import{__decorate as t}from"../../_virtual/_@oxc-project_runtime@0.96.0/helpers/decorate.js";import n from"./AssociatedTestModel.js";import{Column as r,DataType as i,HasMany as a,Model as o,PrimaryKey as s,Table as c}from"sequelize-typescript";let l=class extends o{};t([s,r({type:i.UUID,defaultValue:i.UUIDV4,allowNull:!1}),e(`design:type`,String)],l.prototype,`id`,void 0),t([r({type:i.UUID,allowNull:!1}),e(`design:type`,String)],l.prototype,`fleetId`,void 0),t([r({type:i.UUID,allowNull:!0}),e(`design:type`,String)],l.prototype,`businessModelId`,void 0),t([r({type:i.UUID,allowNull:!0}),e(`design:type`,String)],l.prototype,`demandSourceId`,void 0),t([r({type:i.BOOLEAN}),e(`design:type`,Boolean)],l.prototype,`coolAttribute`,void 0),t([a(()=>n),e(`design:type`,Array)],l.prototype,`associatedModels`,void 0),t([r({type:i.VIRTUAL}),e(`design:type`,Object)],l.prototype,`customFields`,void 0),l=t([c({schema:`custom-fields`,tableName:`test_models`,createdAt:!1,updatedAt:!1,modelName:`TestModel`})],l);var u=l;export{u as default};
2
2
  //# sourceMappingURL=TestModel.js.map
@@ -1,2 +1,2 @@
1
- const e=require(`../../../_virtual/rolldown_runtime.cjs`),t=require(`../../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorateMetadata.cjs`),n=require(`../../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorate.cjs`),r=require(`./ContextTestModel.cjs`);let i=require(`sequelize-typescript`);i=e.__toESM(i);var a;let o=class extends i.Model{};n.__decorate([i.PrimaryKey,(0,i.Column)({type:i.DataType.UUID,defaultValue:i.DataType.UUIDV4,allowNull:!1}),t.__decorateMetadata(`design:type`,String)],o.prototype,`id`,void 0),n.__decorate([(0,i.ForeignKey)(()=>r.default),(0,i.Column)({type:i.DataType.UUID}),t.__decorateMetadata(`design:type`,String)],o.prototype,`contextId`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.BOOLEAN}),t.__decorateMetadata(`design:type`,Boolean)],o.prototype,`coolAttribute`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.VIRTUAL}),t.__decorateMetadata(`design:type`,Object)],o.prototype,`customFields`,void 0),n.__decorate([(0,i.BelongsTo)(()=>r.default),t.__decorateMetadata(`design:type`,typeof(a=r.default!==void 0&&r.default)==`function`?a:Object)],o.prototype,`context`,void 0),o=n.__decorate([(0,i.Table)({createdAt:!1,updatedAt:!1,modelName:`ContextAwareTestModel`})],o);var s=o;exports.default=s;
1
+ const e=require(`../../../_virtual/rolldown_runtime.cjs`),t=require(`../../../_virtual/_@oxc-project_runtime@0.96.0/helpers/decorateMetadata.cjs`),n=require(`../../../_virtual/_@oxc-project_runtime@0.96.0/helpers/decorate.cjs`),r=require(`./ContextTestModel.cjs`);let i=require(`sequelize-typescript`);var a;let o=class extends i.Model{};n.__decorate([i.PrimaryKey,(0,i.Column)({type:i.DataType.UUID,defaultValue:i.DataType.UUIDV4,allowNull:!1}),t.__decorateMetadata(`design:type`,String)],o.prototype,`id`,void 0),n.__decorate([(0,i.ForeignKey)(()=>r.default),(0,i.Column)({type:i.DataType.UUID}),t.__decorateMetadata(`design:type`,String)],o.prototype,`contextId`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.BOOLEAN}),t.__decorateMetadata(`design:type`,Boolean)],o.prototype,`coolAttribute`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.VIRTUAL}),t.__decorateMetadata(`design:type`,Object)],o.prototype,`customFields`,void 0),n.__decorate([(0,i.BelongsTo)(()=>r.default),t.__decorateMetadata(`design:type`,typeof(a=r.default!==void 0&&r.default)==`function`?a:Object)],o.prototype,`context`,void 0),o=n.__decorate([(0,i.Table)({createdAt:!1,updatedAt:!1,modelName:`ContextAwareTestModel`})],o);var s=o;exports.default=s;
2
2
  //# sourceMappingURL=ContextAwareTestModel.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ContextAwareTestModel.cjs","names":["ContextAwareTestModel","Model","PrimaryKey","DataType","ContextTestModel"],"sources":["../../../../src/models/tests/contextAwareModels/ContextAwareTestModel.ts"],"sourcesContent":["import {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n BelongsTo,\n ForeignKey,\n} from 'sequelize-typescript';\nimport ContextTestModel from './ContextTestModel';\n\n@Table({ createdAt: false, updatedAt: false, modelName: 'ContextAwareTestModel' })\nclass ContextAwareTestModel extends Model {\n @PrimaryKey\n @Column({\n type: DataType.UUID,\n defaultValue: DataType.UUIDV4,\n allowNull: false,\n })\n declare id: string;\n\n @ForeignKey(() => ContextTestModel)\n @Column({ type: DataType.UUID })\n declare contextId: string;\n\n @Column({\n type: DataType.BOOLEAN,\n })\n coolAttribute?: boolean;\n\n @Column({\n type: DataType.VIRTUAL,\n })\n customFields?: any;\n\n @BelongsTo(() => ContextTestModel)\n declare context: ContextTestModel;\n}\n\nexport default ContextAwareTestModel;\n"],"mappings":"mUAWA,IAAA,EAAA,cACoCC,EAAAA,KAAM,iBACvCC,EAAAA,wBACO,CACN,KAAMC,EAAAA,SAAS,KACf,aAAcA,EAAAA,SAAS,OACvB,UAAW,GACZ,CAAC,yGAGgBC,EAAAA,QAAiB,cAC3B,CAAE,KAAMD,EAAAA,SAAS,KAAM,CAAC,wGAGxB,CACN,KAAMA,EAAAA,SAAS,QAChB,CAAC,CAAA,EAAA,mBAAA,cAAA,QAAA,CAAA,CAAA,EAAA,UAAA,gBAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,QAChB,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,eAAA,IAAA,GAAA,mCAGeC,EAAAA,QAAiB,CAAA,EAAA,mBAAA,cAAA,OAAA,EAAA,EAAA,UAAA,QAAA,EAAA,UAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,UAAA,IAAA,GAAA,6BAxB7B,CAAE,UAAW,GAAO,UAAW,GAAO,UAAW,wBAAyB,CAAC,CAAA,CAAA,EAAA,CA4BlF,IAAA,EAAe"}
1
+ {"version":3,"file":"ContextAwareTestModel.cjs","names":["ContextAwareTestModel","Model","PrimaryKey","DataType","ContextTestModel"],"sources":["../../../../src/models/tests/contextAwareModels/ContextAwareTestModel.ts"],"sourcesContent":["import {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n BelongsTo,\n ForeignKey,\n} from 'sequelize-typescript';\nimport ContextTestModel from './ContextTestModel';\n\n@Table({ createdAt: false, updatedAt: false, modelName: 'ContextAwareTestModel' })\nclass ContextAwareTestModel extends Model {\n @PrimaryKey\n @Column({\n type: DataType.UUID,\n defaultValue: DataType.UUIDV4,\n allowNull: false,\n })\n declare id: string;\n\n @ForeignKey(() => ContextTestModel)\n @Column({ type: DataType.UUID })\n declare contextId: string;\n\n @Column({\n type: DataType.BOOLEAN,\n })\n coolAttribute?: boolean;\n\n @Column({\n type: DataType.VIRTUAL,\n })\n customFields?: any;\n\n @BelongsTo(() => ContextTestModel)\n declare context: ContextTestModel;\n}\n\nexport default ContextAwareTestModel;\n"],"mappings":"oTAWA,IAAA,EAAA,cACoCC,EAAAA,KAAM,iBACvCC,EAAAA,wBACO,CACN,KAAMC,EAAAA,SAAS,KACf,aAAcA,EAAAA,SAAS,OACvB,UAAW,GACZ,CAAC,yGAGgBC,EAAAA,QAAiB,cAC3B,CAAE,KAAMD,EAAAA,SAAS,KAAM,CAAC,wGAGxB,CACN,KAAMA,EAAAA,SAAS,QAChB,CAAC,CAAA,EAAA,mBAAA,cAAA,QAAA,CAAA,CAAA,EAAA,UAAA,gBAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,QAChB,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,eAAA,IAAA,GAAA,mCAGeC,EAAAA,QAAiB,CAAA,EAAA,mBAAA,cAAA,OAAA,EAAA,EAAA,UAAA,QAAA,EAAA,UAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,UAAA,IAAA,GAAA,6BAxB7B,CAAE,UAAW,GAAO,UAAW,GAAO,UAAW,wBAAyB,CAAC,CAAA,CAAA,EAAA,CA4BlF,IAAA,EAAe"}
@@ -1,2 +1,2 @@
1
- import{__decorateMetadata as e}from"../../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorateMetadata.js";import{__decorate as t}from"../../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorate.js";import n from"./ContextTestModel.js";import{BelongsTo as r,Column as i,DataType as a,ForeignKey as o,Model as s,PrimaryKey as c,Table as l}from"sequelize-typescript";var u;let d=class extends s{};t([c,i({type:a.UUID,defaultValue:a.UUIDV4,allowNull:!1}),e(`design:type`,String)],d.prototype,`id`,void 0),t([o(()=>n),i({type:a.UUID}),e(`design:type`,String)],d.prototype,`contextId`,void 0),t([i({type:a.BOOLEAN}),e(`design:type`,Boolean)],d.prototype,`coolAttribute`,void 0),t([i({type:a.VIRTUAL}),e(`design:type`,Object)],d.prototype,`customFields`,void 0),t([r(()=>n),e(`design:type`,typeof(u=n!==void 0&&n)==`function`?u:Object)],d.prototype,`context`,void 0),d=t([l({createdAt:!1,updatedAt:!1,modelName:`ContextAwareTestModel`})],d);var f=d;export{f as default};
1
+ import{__decorateMetadata as e}from"../../../_virtual/_@oxc-project_runtime@0.96.0/helpers/decorateMetadata.js";import{__decorate as t}from"../../../_virtual/_@oxc-project_runtime@0.96.0/helpers/decorate.js";import n from"./ContextTestModel.js";import{BelongsTo as r,Column as i,DataType as a,ForeignKey as o,Model as s,PrimaryKey as c,Table as l}from"sequelize-typescript";var u;let d=class extends s{};t([c,i({type:a.UUID,defaultValue:a.UUIDV4,allowNull:!1}),e(`design:type`,String)],d.prototype,`id`,void 0),t([o(()=>n),i({type:a.UUID}),e(`design:type`,String)],d.prototype,`contextId`,void 0),t([i({type:a.BOOLEAN}),e(`design:type`,Boolean)],d.prototype,`coolAttribute`,void 0),t([i({type:a.VIRTUAL}),e(`design:type`,Object)],d.prototype,`customFields`,void 0),t([r(()=>n),e(`design:type`,typeof(u=n!==void 0&&n)==`function`?u:Object)],d.prototype,`context`,void 0),d=t([l({createdAt:!1,updatedAt:!1,modelName:`ContextAwareTestModel`})],d);var f=d;export{f as default};
2
2
  //# sourceMappingURL=ContextAwareTestModel.js.map
@@ -1,2 +1,2 @@
1
- const e=require(`../../../_virtual/rolldown_runtime.cjs`),t=require(`../../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorateMetadata.cjs`),n=require(`../../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorate.cjs`);let r=require(`sequelize-typescript`);r=e.__toESM(r);var i=function(e){return e.BUSINESS_MODEL=`businessModel`,e.CONTEXT=`context`,e.DEMAND_SOURCE=`demandSource`,e.FLEET=`fleet`,e}(i||{});let a=class extends r.Model{};n.__decorate([r.PrimaryKey,(0,r.Column)({defaultValue:r.DataType.UUIDV4,type:r.DataType.UUID}),t.__decorateMetadata(`design:type`,String)],a.prototype,`id`,void 0),n.__decorate([(0,r.Column)({type:r.DataType.UUID}),t.__decorateMetadata(`design:type`,String)],a.prototype,`entityId`,void 0),n.__decorate([(0,r.Column)({type:r.DataType.ENUM(...Object.values(i))}),t.__decorateMetadata(`design:type`,String)],a.prototype,`entityType`,void 0),a=n.__decorate([(0,r.Table)({createdAt:!1,updatedAt:!1,modelName:`ContextTestModel`})],a);var o=a;exports.default=o;
1
+ const e=require(`../../../_virtual/rolldown_runtime.cjs`),t=require(`../../../_virtual/_@oxc-project_runtime@0.96.0/helpers/decorateMetadata.cjs`),n=require(`../../../_virtual/_@oxc-project_runtime@0.96.0/helpers/decorate.cjs`);let r=require(`sequelize-typescript`);var i=function(e){return e.BUSINESS_MODEL=`businessModel`,e.CONTEXT=`context`,e.DEMAND_SOURCE=`demandSource`,e.FLEET=`fleet`,e}(i||{});let a=class extends r.Model{};n.__decorate([r.PrimaryKey,(0,r.Column)({defaultValue:r.DataType.UUIDV4,type:r.DataType.UUID}),t.__decorateMetadata(`design:type`,String)],a.prototype,`id`,void 0),n.__decorate([(0,r.Column)({type:r.DataType.UUID}),t.__decorateMetadata(`design:type`,String)],a.prototype,`entityId`,void 0),n.__decorate([(0,r.Column)({type:r.DataType.ENUM(...Object.values(i))}),t.__decorateMetadata(`design:type`,String)],a.prototype,`entityType`,void 0),a=n.__decorate([(0,r.Table)({createdAt:!1,updatedAt:!1,modelName:`ContextTestModel`})],a);var o=a;exports.default=o;
2
2
  //# sourceMappingURL=ContextTestModel.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ContextTestModel.cjs","names":["ContextTestModel","Model","PrimaryKey","DataType"],"sources":["../../../../src/models/tests/contextAwareModels/ContextTestModel.ts"],"sourcesContent":["import {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n} from 'sequelize-typescript';\n\nenum EEntityTypes {\n BUSINESS_MODEL = 'businessModel',\n CONTEXT = 'context',\n DEMAND_SOURCE = 'demandSource',\n FLEET = 'fleet',\n}\n\n@Table({ createdAt: false, updatedAt: false, modelName: 'ContextTestModel' })\nclass ContextTestModel extends Model {\n @PrimaryKey\n @Column({\n defaultValue: DataType.UUIDV4,\n type: DataType.UUID,\n })\n declare id: string;\n\n @Column({\n type: DataType.UUID,\n })\n declare entityId: string;\n\n @Column({\n type: DataType.ENUM(...Object.values(EEntityTypes)),\n })\n declare entityType: EEntityTypes;\n}\n\nexport default ContextTestModel;\n"],"mappings":"yRAQA,IAAK,EAAA,SAAA,EAAL,OACE,GAAA,eAAA,gBACA,EAAA,QAAA,UACA,EAAA,cAAA,eACA,EAAA,MAAA,WAJG,GAAA,EAAA,CAAA,CAOL,IAAA,EAAA,cAC+BC,EAAAA,KAAM,iBAClCC,EAAAA,wBACO,CACN,aAAcC,EAAAA,SAAS,OACvB,KAAMA,EAAAA,SAAS,KAChB,CAAC,iGAGM,CACN,KAAMA,EAAAA,SAAS,KAChB,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,WAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KAAK,GAAG,OAAO,OAAO,EAAa,CAAC,CACpD,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,aAAA,IAAA,GAAA,6BAhBG,CAAE,UAAW,GAAO,UAAW,GAAO,UAAW,mBAAoB,CAAC,CAAA,CAAA,EAAA,CAoB7E,IAAA,EAAe"}
1
+ {"version":3,"file":"ContextTestModel.cjs","names":["ContextTestModel","Model","PrimaryKey","DataType"],"sources":["../../../../src/models/tests/contextAwareModels/ContextTestModel.ts"],"sourcesContent":["import {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n} from 'sequelize-typescript';\n\nenum EEntityTypes {\n BUSINESS_MODEL = 'businessModel',\n CONTEXT = 'context',\n DEMAND_SOURCE = 'demandSource',\n FLEET = 'fleet',\n}\n\n@Table({ createdAt: false, updatedAt: false, modelName: 'ContextTestModel' })\nclass ContextTestModel extends Model {\n @PrimaryKey\n @Column({\n defaultValue: DataType.UUIDV4,\n type: DataType.UUID,\n })\n declare id: string;\n\n @Column({\n type: DataType.UUID,\n })\n declare entityId: string;\n\n @Column({\n type: DataType.ENUM(...Object.values(EEntityTypes)),\n })\n declare entityType: EEntityTypes;\n}\n\nexport default ContextTestModel;\n"],"mappings":"0QAQA,IAAK,EAAA,SAAA,EAAL,OACE,GAAA,eAAA,gBACA,EAAA,QAAA,UACA,EAAA,cAAA,eACA,EAAA,MAAA,WAJG,GAAA,EAAA,CAAA,CAOL,IAAA,EAAA,cAC+BC,EAAAA,KAAM,iBAClCC,EAAAA,wBACO,CACN,aAAcC,EAAAA,SAAS,OACvB,KAAMA,EAAAA,SAAS,KAChB,CAAC,iGAGM,CACN,KAAMA,EAAAA,SAAS,KAChB,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,WAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KAAK,GAAG,OAAO,OAAO,EAAa,CAAC,CACpD,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,aAAA,IAAA,GAAA,6BAhBG,CAAE,UAAW,GAAO,UAAW,GAAO,UAAW,mBAAoB,CAAC,CAAA,CAAA,EAAA,CAoB7E,IAAA,EAAe"}
@@ -1,2 +1,2 @@
1
- import{__decorateMetadata as e}from"../../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorateMetadata.js";import{__decorate as t}from"../../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorate.js";import{Column as n,DataType as r,Model as i,PrimaryKey as a,Table as o}from"sequelize-typescript";var s=function(e){return e.BUSINESS_MODEL=`businessModel`,e.CONTEXT=`context`,e.DEMAND_SOURCE=`demandSource`,e.FLEET=`fleet`,e}(s||{});let c=class extends i{};t([a,n({defaultValue:r.UUIDV4,type:r.UUID}),e(`design:type`,String)],c.prototype,`id`,void 0),t([n({type:r.UUID}),e(`design:type`,String)],c.prototype,`entityId`,void 0),t([n({type:r.ENUM(...Object.values(s))}),e(`design:type`,String)],c.prototype,`entityType`,void 0),c=t([o({createdAt:!1,updatedAt:!1,modelName:`ContextTestModel`})],c);var l=c;export{l as default};
1
+ import{__decorateMetadata as e}from"../../../_virtual/_@oxc-project_runtime@0.96.0/helpers/decorateMetadata.js";import{__decorate as t}from"../../../_virtual/_@oxc-project_runtime@0.96.0/helpers/decorate.js";import{Column as n,DataType as r,Model as i,PrimaryKey as a,Table as o}from"sequelize-typescript";var s=function(e){return e.BUSINESS_MODEL=`businessModel`,e.CONTEXT=`context`,e.DEMAND_SOURCE=`demandSource`,e.FLEET=`fleet`,e}(s||{});let c=class extends i{};t([a,n({defaultValue:r.UUIDV4,type:r.UUID}),e(`design:type`,String)],c.prototype,`id`,void 0),t([n({type:r.UUID}),e(`design:type`,String)],c.prototype,`entityId`,void 0),t([n({type:r.ENUM(...Object.values(s))}),e(`design:type`,String)],c.prototype,`entityType`,void 0),c=t([o({createdAt:!1,updatedAt:!1,modelName:`ContextTestModel`})],c);var l=c;export{l as default};
2
2
  //# sourceMappingURL=ContextTestModel.js.map
@@ -1,2 +1,2 @@
1
- const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../errors/index.cjs`),n=require(`../models/CustomFieldDefinition.cjs`);require(`../models/index.cjs`);let r=require(`sequelize`);r=e.__toESM(r);const i=e=>n.default.create(e),a=(e,t={withDisabled:!1})=>(t.withDisabled?n.default.unscoped():n.default).scope(`userScope`).findAll({where:e,transaction:t.transaction,raw:!0,include:t.include}),o=(e,t={withDisabled:!1})=>a({id:{[r.Op.in]:e}},t),s=(e,t={withDisabled:!1})=>{let{withDisabled:r}=t;return r?n.default.unscoped().scope(`userScope`).findByPk(e):n.default.scope(`userScope`).findByPk(e)},c=async(e,t,i={})=>{let{include:a,useEntityIdFromInclude:o}=i.modelOptions,s={modelType:e,...!o&&{entityId:{[r.Op.in]:t}}};return n.default.findAll({where:s,transaction:i.transaction,include:a?.(t),raw:!0})},l=e=>n.default.scope(`userScope`).findOne({where:e}),u=async(e,t)=>(await n.default.scope(`userScope`).update(t,{where:{id:e},returning:!0,individualHooks:!0}))[1][0],d=async(e,{findAll:n,modelOptions:i={},withDisabled:o=!1,...s}={withDisabled:!1,modelOptions:{}})=>{let{modelType:c}=e[0]?.dataValues??{},l=new Set,u=[],d=new Set;e.forEach(e=>{let{dataValues:{modelId:t,entityId:n,customFields:r}}=e;u.push(t),d.add(n),Object.keys(r??{}).forEach(e=>{l.add(e)})});let f={modelType:c,entityId:{[r.Op.in]:Array.from(d)},name:{[r.Op.in]:Array.from(l)}},p=await(n??a)(f,{withDisabled:o,modelOptions:i,...s}),m=p.filter(e=>l.has(e.name)),h=Object.fromEntries(m.map(e=>[e.name,e]));if(!p?.length||m.length!==l.size)throw new t.MissingDefinitionError(Array.from(l).filter(e=>!h[e]));return h};exports.create=i,exports.findAll=a,exports.findByEntityIds=c,exports.findById=s,exports.findByIds=o,exports.findByWhere=l,exports.getCustomFieldDefinitionsDictionary=d,exports.update=u;
1
+ const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../errors/index.cjs`),n=require(`../models/CustomFieldDefinition.cjs`);require(`../models/index.cjs`);let r=require(`sequelize`);const i=e=>n.default.create(e),a=(e,t={withDisabled:!1})=>(t.withDisabled?n.default.unscoped():n.default).scope(`userScope`).findAll({where:e,transaction:t.transaction,raw:!0,include:t.include}),o=(e,t={withDisabled:!1})=>a({id:{[r.Op.in]:e}},t),s=(e,t={withDisabled:!1})=>{let{withDisabled:r}=t;return r?n.default.unscoped().scope(`userScope`).findByPk(e):n.default.scope(`userScope`).findByPk(e)},c=async(e,t,i={})=>{let{include:a,useEntityIdFromInclude:o}=i.modelOptions,s={modelType:e,...!o&&{entityId:{[r.Op.in]:t}}};return n.default.findAll({where:s,transaction:i.transaction,include:a?.(t),raw:!0})},l=e=>n.default.scope(`userScope`).findOne({where:e}),u=async(e,t)=>(await n.default.scope(`userScope`).update(t,{where:{id:e},returning:!0,individualHooks:!0}))[1][0],d=async(e,{findAll:n,modelOptions:i={},withDisabled:o=!1,...s}={withDisabled:!1,modelOptions:{}})=>{let{modelType:c}=e[0]?.dataValues??{},l=new Set,u=[],d=new Set;e.forEach(e=>{let{dataValues:{modelId:t,entityId:n,customFields:r}}=e;u.push(t),d.add(n),Object.keys(r??{}).forEach(e=>{l.add(e)})});let f={modelType:c,entityId:{[r.Op.in]:Array.from(d)},name:{[r.Op.in]:Array.from(l)}},p=await(n??a)(f,{withDisabled:o,modelOptions:i,...s}),m=p.filter(e=>l.has(e.name)),h=Object.fromEntries(m.map(e=>[e.name,e]));if(!p?.length||m.length!==l.size)throw new t.MissingDefinitionError(Array.from(l).filter(e=>!h[e]));return h};exports.create=i,exports.findAll=a,exports.findByEntityIds=c,exports.findById=s,exports.findByIds=o,exports.findByWhere=l,exports.getCustomFieldDefinitionsDictionary=d,exports.update=u;
2
2
  //# sourceMappingURL=definition.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"definition.cjs","names":["CustomFieldDefinition","Op","where: WhereOptions","MissingDefinitionError"],"sources":["../../src/repository/definition.ts"],"sourcesContent":["import {\n Op,\n type Includeable, type Transaction, type FindOptions, type WhereOptions, type Transactionable,\n} from 'sequelize';\nimport { CustomFieldDefinition, type CustomFieldEntries } from '../models';\nimport type { CreateCustomFieldDefinition, UpdateCustomFieldDefinition } from '../types/definition';\nimport type { ModelOptions } from '../types';\nimport { MissingDefinitionError } from '../errors';\n\nexport const create = (data: CreateCustomFieldDefinition): Promise<CustomFieldDefinition> =>\n CustomFieldDefinition.create(data);\n\ninterface SadotFindOptions {\n withDisabled?: boolean;\n transaction?: Transaction | null;\n include?: Includeable | Includeable[];\n}\n\ntype SadotGetDefinitionsByEntityIdsOptions = FindOptions & { modelOptions?: ModelOptions; findAll?: typeof findAll; } & Pick<SadotFindOptions, 'withDisabled'>;\n\nexport const findAll = (\n where: WhereOptions,\n options: SadotFindOptions = { withDisabled: false },\n): Promise<CustomFieldDefinition[]> => {\n const queryModel = options.withDisabled\n ? CustomFieldDefinition.unscoped()\n : CustomFieldDefinition;\n\n return queryModel.scope('userScope').findAll({\n where,\n transaction: options.transaction,\n raw: true,\n include: options.include,\n });\n};\n\nexport const findByIds = (\n ids: string[],\n options: SadotFindOptions = { withDisabled: false },\n): Promise<CustomFieldDefinition[]> => findAll({ id: { [Op.in]: ids } }, options);\n\nexport const findById = (\n id: string,\n options: Pick<SadotFindOptions, 'withDisabled'> = { withDisabled: false },\n): Promise<CustomFieldDefinition | null> => {\n const { withDisabled } = options;\n if (withDisabled) {\n return CustomFieldDefinition.unscoped().scope('userScope').findByPk(id);\n }\n return CustomFieldDefinition.scope('userScope').findByPk(id);\n};\n\nexport const findByEntityIds = async (\n modelType: string,\n entityIds: string[],\n options: FindOptions & { modelOptions?: ModelOptions; } = {},\n): Promise<CustomFieldDefinition[]> => {\n const { include, useEntityIdFromInclude } = options.modelOptions!;\n const where: WhereOptions = {\n modelType,\n ...(!useEntityIdFromInclude && { entityId: { [Op.in]: entityIds } }),\n };\n\n return CustomFieldDefinition.findAll({\n where,\n transaction: options.transaction,\n include: include?.(entityIds),\n raw: true,\n });\n};\n\nexport const findByWhere = (where: WhereOptions<CustomFieldDefinition>): Promise<CustomFieldDefinition | null> =>\n CustomFieldDefinition.scope('userScope').findOne({\n where,\n });\n\nexport const findDefinitionsByModels = async (\n modelTypes: string[],\n options?: Transactionable,\n): Promise<CustomFieldDefinition[]> => {\n const query: WhereOptions<CreateCustomFieldDefinition> = { modelType: { [Op.in]: modelTypes } };\n return CustomFieldDefinition.findAll({\n where: query,\n transaction: options?.transaction,\n });\n};\n\nexport const update = async (\n id: string,\n data: UpdateCustomFieldDefinition,\n): Promise<CustomFieldDefinition> => {\n const updatedDefinition = (await CustomFieldDefinition.scope('userScope').update(data, {\n where: { id },\n returning: true,\n individualHooks: true,\n }))[1][0];\n return updatedDefinition;\n};\n\nexport const disable = (id: string): Promise<[affectedCount: number]> =>\n CustomFieldDefinition.update(\n { disabled: true },\n { where: { id } },\n );\n\nexport const destroy = (id: string): Promise<number> =>\n CustomFieldDefinition.destroy({ where: { id } });\n\n/**\n * Return the names of the required fields for a given model\n */\nexport const getRequiredFields = async (\n modelType: string,\n modelId: string | string[],\n entityId: string | string[],\n modelOptions: ModelOptions = {},\n): Promise<string[]> => {\n const entityIds = Array.isArray(entityId) ? entityId : [entityId];\n const { include, useEntityIdFromInclude } = modelOptions;\n\n const where: WhereOptions = {\n modelType,\n required: true,\n ...(!useEntityIdFromInclude && { entityId: { [Op.in]: entityIds } }),\n };\n\n const requiredFields = await CustomFieldDefinition.findAll({\n where,\n include: include?.(entityIds),\n logging: true,\n });\n const requiredFieldsNames = requiredFields.map(definition => definition.name);\n return [...new Set(requiredFieldsNames)];\n};\n\n/**\n * @returns A promise resolving with a dictionary of custom field definitions by name.\n * @throws A {@link MissingDefinitionError} if any of the custom fields doesn't have a definition.\n */\nexport const getCustomFieldDefinitionsDictionary = async (\n instances: CustomFieldEntries[],\n {\n findAll: _findAll,\n modelOptions = {},\n withDisabled = false,\n ...options\n }: SadotGetDefinitionsByEntityIdsOptions = { withDisabled: false, modelOptions: {} },\n): Promise<Record<string, CustomFieldDefinition>> => {\n const { modelType } = instances[0]?.dataValues ?? {};\n const customFields = new Set<string>();\n const modelIds = [];\n const entityIds = new Set<string>();\n instances.forEach((instance) => {\n const { dataValues: { modelId, entityId, customFields: instanceCustomFields } } = instance;\n modelIds.push(modelId);\n entityIds.add(entityId);\n\n Object.keys(instanceCustomFields ?? {}).forEach((fieldName) => {\n customFields.add(fieldName);\n });\n });\n\n const where: WhereOptions = {\n modelType,\n entityId: { [Op.in]: Array.from(entityIds) },\n name: { [Op.in]: Array.from(customFields) },\n };\n\n const findAllToUse = _findAll ?? findAll;\n\n // @ts-expect-error findAll doesn't expect modelOptions at all.\n const definitions = await findAllToUse(where, { withDisabled, modelOptions, ...options });\n\n const matchedDefinitions = definitions.filter(def => customFields.has(def.name));\n const matchedDefinitionsByName = Object.fromEntries(matchedDefinitions.map(definition => [definition.name, definition]));\n\n if (!definitions?.length || matchedDefinitions.length !== customFields.size) {\n const unmatchedCustomFields = Array.from(customFields).filter(customField => !matchedDefinitionsByName[customField]);\n throw new MissingDefinitionError(unmatchedCustomFields);\n }\n\n return matchedDefinitionsByName;\n};\n"],"mappings":"+MASA,MAAa,EAAU,GACrBA,EAAAA,QAAsB,OAAO,EAAK,CAUvB,GACX,EACA,EAA4B,CAAE,aAAc,GAAO,IAEhC,EAAQ,aACvBA,EAAAA,QAAsB,UAAU,CAChCA,EAAAA,SAEc,MAAM,YAAY,CAAC,QAAQ,CAC3C,QACA,YAAa,EAAQ,YACrB,IAAK,GACL,QAAS,EAAQ,QAClB,CAAC,CAGS,GACX,EACA,EAA4B,CAAE,aAAc,GAAO,GACd,EAAQ,CAAE,GAAI,EAAGC,EAAAA,GAAG,IAAK,EAAK,CAAE,CAAE,EAAQ,CAEpE,GACX,EACA,EAAkD,CAAE,aAAc,GAAO,GAC/B,CAC1C,GAAM,CAAE,gBAAiB,EAIzB,OAHI,EACKD,EAAAA,QAAsB,UAAU,CAAC,MAAM,YAAY,CAAC,SAAS,EAAG,CAElEA,EAAAA,QAAsB,MAAM,YAAY,CAAC,SAAS,EAAG,EAGjD,EAAkB,MAC7B,EACA,EACA,EAA0D,EAAE,GACvB,CACrC,GAAM,CAAE,UAAS,0BAA2B,EAAQ,aAC9CE,EAAsB,CAC1B,YACA,GAAI,CAAC,GAA0B,CAAE,SAAU,EAAGD,EAAAA,GAAG,IAAK,EAAW,CAAE,CACpE,CAED,OAAOD,EAAAA,QAAsB,QAAQ,CACnC,QACA,YAAa,EAAQ,YACrB,QAAS,IAAU,EAAU,CAC7B,IAAK,GACN,CAAC,EAGS,EAAe,GAC1BA,EAAAA,QAAsB,MAAM,YAAY,CAAC,QAAQ,CAC/C,QACD,CAAC,CAaS,EAAS,MACpB,EACA,KAE2B,MAAMA,EAAAA,QAAsB,MAAM,YAAY,CAAC,OAAO,EAAM,CACrF,MAAO,CAAE,KAAI,CACb,UAAW,GACX,gBAAiB,GAClB,CAAC,EAAE,GAAG,GA4CI,EAAsC,MACjD,EACA,CACE,QAAS,EACT,eAAe,EAAE,CACjB,eAAe,GACf,GAAG,GACsC,CAAE,aAAc,GAAO,aAAc,EAAE,CAAE,GACjC,CACnD,GAAM,CAAE,aAAc,EAAU,IAAI,YAAc,EAAE,CAC9C,EAAe,IAAI,IACnB,EAAW,EAAE,CACb,EAAY,IAAI,IACtB,EAAU,QAAS,GAAa,CAC9B,GAAM,CAAE,WAAY,CAAE,UAAS,WAAU,aAAc,IAA2B,EAClF,EAAS,KAAK,EAAQ,CACtB,EAAU,IAAI,EAAS,CAEvB,OAAO,KAAK,GAAwB,EAAE,CAAC,CAAC,QAAS,GAAc,CAC7D,EAAa,IAAI,EAAU,EAC3B,EACF,CAEF,IAAME,EAAsB,CAC1B,YACA,SAAU,EAAGD,EAAAA,GAAG,IAAK,MAAM,KAAK,EAAU,CAAE,CAC5C,KAAM,EAAGA,EAAAA,GAAG,IAAK,MAAM,KAAK,EAAa,CAAE,CAC5C,CAKK,EAAc,MAHC,GAAY,GAGM,EAAO,CAAE,eAAc,eAAc,GAAG,EAAS,CAAC,CAEnF,EAAqB,EAAY,OAAO,GAAO,EAAa,IAAI,EAAI,KAAK,CAAC,CAC1E,EAA2B,OAAO,YAAY,EAAmB,IAAI,GAAc,CAAC,EAAW,KAAM,EAAW,CAAC,CAAC,CAExH,GAAI,CAAC,GAAa,QAAU,EAAmB,SAAW,EAAa,KAErE,MAAM,IAAIE,EAAAA,uBADoB,MAAM,KAAK,EAAa,CAAC,OAAO,GAAe,CAAC,EAAyB,GAAa,CAC7D,CAGzD,OAAO"}
1
+ {"version":3,"file":"definition.cjs","names":["CustomFieldDefinition","Op","where: WhereOptions","MissingDefinitionError"],"sources":["../../src/repository/definition.ts"],"sourcesContent":["import {\n Op,\n type Includeable, type Transaction, type FindOptions, type WhereOptions, type Transactionable,\n} from 'sequelize';\nimport { CustomFieldDefinition, type CustomFieldEntries } from '../models';\nimport type { CreateCustomFieldDefinition, UpdateCustomFieldDefinition } from '../types/definition';\nimport type { ModelOptions } from '../types';\nimport { MissingDefinitionError } from '../errors';\n\nexport const create = (data: CreateCustomFieldDefinition): Promise<CustomFieldDefinition> =>\n CustomFieldDefinition.create(data);\n\ninterface SadotFindOptions {\n withDisabled?: boolean;\n transaction?: Transaction | null;\n include?: Includeable | Includeable[];\n}\n\ntype SadotGetDefinitionsByEntityIdsOptions = FindOptions & { modelOptions?: ModelOptions; findAll?: typeof findAll; } & Pick<SadotFindOptions, 'withDisabled'>;\n\nexport const findAll = (\n where: WhereOptions,\n options: SadotFindOptions = { withDisabled: false },\n): Promise<CustomFieldDefinition[]> => {\n const queryModel = options.withDisabled\n ? CustomFieldDefinition.unscoped()\n : CustomFieldDefinition;\n\n return queryModel.scope('userScope').findAll({\n where,\n transaction: options.transaction,\n raw: true,\n include: options.include,\n });\n};\n\nexport const findByIds = (\n ids: string[],\n options: SadotFindOptions = { withDisabled: false },\n): Promise<CustomFieldDefinition[]> => findAll({ id: { [Op.in]: ids } }, options);\n\nexport const findById = (\n id: string,\n options: Pick<SadotFindOptions, 'withDisabled'> = { withDisabled: false },\n): Promise<CustomFieldDefinition | null> => {\n const { withDisabled } = options;\n if (withDisabled) {\n return CustomFieldDefinition.unscoped().scope('userScope').findByPk(id);\n }\n return CustomFieldDefinition.scope('userScope').findByPk(id);\n};\n\nexport const findByEntityIds = async (\n modelType: string,\n entityIds: string[],\n options: FindOptions & { modelOptions?: ModelOptions; } = {},\n): Promise<CustomFieldDefinition[]> => {\n const { include, useEntityIdFromInclude } = options.modelOptions!;\n const where: WhereOptions = {\n modelType,\n ...(!useEntityIdFromInclude && { entityId: { [Op.in]: entityIds } }),\n };\n\n return CustomFieldDefinition.findAll({\n where,\n transaction: options.transaction,\n include: include?.(entityIds),\n raw: true,\n });\n};\n\nexport const findByWhere = (where: WhereOptions<CustomFieldDefinition>): Promise<CustomFieldDefinition | null> =>\n CustomFieldDefinition.scope('userScope').findOne({\n where,\n });\n\nexport const findDefinitionsByModels = async (\n modelTypes: string[],\n options?: Transactionable,\n): Promise<CustomFieldDefinition[]> => {\n const query: WhereOptions<CreateCustomFieldDefinition> = { modelType: { [Op.in]: modelTypes } };\n return CustomFieldDefinition.findAll({\n where: query,\n transaction: options?.transaction,\n });\n};\n\nexport const update = async (\n id: string,\n data: UpdateCustomFieldDefinition,\n): Promise<CustomFieldDefinition> => {\n const updatedDefinition = (await CustomFieldDefinition.scope('userScope').update(data, {\n where: { id },\n returning: true,\n individualHooks: true,\n }))[1][0];\n return updatedDefinition;\n};\n\nexport const disable = (id: string): Promise<[affectedCount: number]> =>\n CustomFieldDefinition.update(\n { disabled: true },\n { where: { id } },\n );\n\nexport const destroy = (id: string): Promise<number> =>\n CustomFieldDefinition.destroy({ where: { id } });\n\n/**\n * Return the names of the required fields for a given model\n */\nexport const getRequiredFields = async (\n modelType: string,\n modelId: string | string[],\n entityId: string | string[],\n modelOptions: ModelOptions = {},\n): Promise<string[]> => {\n const entityIds = Array.isArray(entityId) ? entityId : [entityId];\n const { include, useEntityIdFromInclude } = modelOptions;\n\n const where: WhereOptions = {\n modelType,\n required: true,\n ...(!useEntityIdFromInclude && { entityId: { [Op.in]: entityIds } }),\n };\n\n const requiredFields = await CustomFieldDefinition.findAll({\n where,\n include: include?.(entityIds),\n logging: true,\n });\n const requiredFieldsNames = requiredFields.map(definition => definition.name);\n return [...new Set(requiredFieldsNames)];\n};\n\n/**\n * @returns A promise resolving with a dictionary of custom field definitions by name.\n * @throws A {@link MissingDefinitionError} if any of the custom fields doesn't have a definition.\n */\nexport const getCustomFieldDefinitionsDictionary = async (\n instances: CustomFieldEntries[],\n {\n findAll: _findAll,\n modelOptions = {},\n withDisabled = false,\n ...options\n }: SadotGetDefinitionsByEntityIdsOptions = { withDisabled: false, modelOptions: {} },\n): Promise<Record<string, CustomFieldDefinition>> => {\n const { modelType } = instances[0]?.dataValues ?? {};\n const customFields = new Set<string>();\n const modelIds = [];\n const entityIds = new Set<string>();\n instances.forEach((instance) => {\n const { dataValues: { modelId, entityId, customFields: instanceCustomFields } } = instance;\n modelIds.push(modelId);\n entityIds.add(entityId);\n\n Object.keys(instanceCustomFields ?? {}).forEach((fieldName) => {\n customFields.add(fieldName);\n });\n });\n\n const where: WhereOptions = {\n modelType,\n entityId: { [Op.in]: Array.from(entityIds) },\n name: { [Op.in]: Array.from(customFields) },\n };\n\n const findAllToUse = _findAll ?? findAll;\n\n // @ts-expect-error findAll doesn't expect modelOptions at all.\n const definitions = await findAllToUse(where, { withDisabled, modelOptions, ...options });\n\n const matchedDefinitions = definitions.filter(def => customFields.has(def.name));\n const matchedDefinitionsByName = Object.fromEntries(matchedDefinitions.map(definition => [definition.name, definition]));\n\n if (!definitions?.length || matchedDefinitions.length !== customFields.size) {\n const unmatchedCustomFields = Array.from(customFields).filter(customField => !matchedDefinitionsByName[customField]);\n throw new MissingDefinitionError(unmatchedCustomFields);\n }\n\n return matchedDefinitionsByName;\n};\n"],"mappings":"gMASA,MAAa,EAAU,GACrBA,EAAAA,QAAsB,OAAO,EAAK,CAUvB,GACX,EACA,EAA4B,CAAE,aAAc,GAAO,IAEhC,EAAQ,aACvBA,EAAAA,QAAsB,UAAU,CAChCA,EAAAA,SAEc,MAAM,YAAY,CAAC,QAAQ,CAC3C,QACA,YAAa,EAAQ,YACrB,IAAK,GACL,QAAS,EAAQ,QAClB,CAAC,CAGS,GACX,EACA,EAA4B,CAAE,aAAc,GAAO,GACd,EAAQ,CAAE,GAAI,EAAGC,EAAAA,GAAG,IAAK,EAAK,CAAE,CAAE,EAAQ,CAEpE,GACX,EACA,EAAkD,CAAE,aAAc,GAAO,GAC/B,CAC1C,GAAM,CAAE,gBAAiB,EAIzB,OAHI,EACKD,EAAAA,QAAsB,UAAU,CAAC,MAAM,YAAY,CAAC,SAAS,EAAG,CAElEA,EAAAA,QAAsB,MAAM,YAAY,CAAC,SAAS,EAAG,EAGjD,EAAkB,MAC7B,EACA,EACA,EAA0D,EAAE,GACvB,CACrC,GAAM,CAAE,UAAS,0BAA2B,EAAQ,aAC9CE,EAAsB,CAC1B,YACA,GAAI,CAAC,GAA0B,CAAE,SAAU,EAAGD,EAAAA,GAAG,IAAK,EAAW,CAAE,CACpE,CAED,OAAOD,EAAAA,QAAsB,QAAQ,CACnC,QACA,YAAa,EAAQ,YACrB,QAAS,IAAU,EAAU,CAC7B,IAAK,GACN,CAAC,EAGS,EAAe,GAC1BA,EAAAA,QAAsB,MAAM,YAAY,CAAC,QAAQ,CAC/C,QACD,CAAC,CAaS,EAAS,MACpB,EACA,KAE2B,MAAMA,EAAAA,QAAsB,MAAM,YAAY,CAAC,OAAO,EAAM,CACrF,MAAO,CAAE,KAAI,CACb,UAAW,GACX,gBAAiB,GAClB,CAAC,EAAE,GAAG,GA4CI,EAAsC,MACjD,EACA,CACE,QAAS,EACT,eAAe,EAAE,CACjB,eAAe,GACf,GAAG,GACsC,CAAE,aAAc,GAAO,aAAc,EAAE,CAAE,GACjC,CACnD,GAAM,CAAE,aAAc,EAAU,IAAI,YAAc,EAAE,CAC9C,EAAe,IAAI,IACnB,EAAW,EAAE,CACb,EAAY,IAAI,IACtB,EAAU,QAAS,GAAa,CAC9B,GAAM,CAAE,WAAY,CAAE,UAAS,WAAU,aAAc,IAA2B,EAClF,EAAS,KAAK,EAAQ,CACtB,EAAU,IAAI,EAAS,CAEvB,OAAO,KAAK,GAAwB,EAAE,CAAC,CAAC,QAAS,GAAc,CAC7D,EAAa,IAAI,EAAU,EAC3B,EACF,CAEF,IAAME,EAAsB,CAC1B,YACA,SAAU,EAAGD,EAAAA,GAAG,IAAK,MAAM,KAAK,EAAU,CAAE,CAC5C,KAAM,EAAGA,EAAAA,GAAG,IAAK,MAAM,KAAK,EAAa,CAAE,CAC5C,CAKK,EAAc,MAHC,GAAY,GAGM,EAAO,CAAE,eAAc,eAAc,GAAG,EAAS,CAAC,CAEnF,EAAqB,EAAY,OAAO,GAAO,EAAa,IAAI,EAAI,KAAK,CAAC,CAC1E,EAA2B,OAAO,YAAY,EAAmB,IAAI,GAAc,CAAC,EAAW,KAAM,EAAW,CAAC,CAAC,CAExH,GAAI,CAAC,GAAa,QAAU,EAAmB,SAAW,EAAa,KAErE,MAAM,IAAIE,EAAAA,uBADoB,MAAM,KAAK,EAAa,CAAC,OAAO,GAAe,CAAC,EAAyB,GAAa,CAC7D,CAGzD,OAAO"}
@@ -1,2 +1,2 @@
1
- const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../utils/helpers/index.cjs`),n=require(`./helpers/filter.helpers.cjs`);let r=require(`sequelize`);r=e.__toESM(r);let i=require(`sequelize-typescript`);i=e.__toESM(i);let a=require(`@autofleet/common-types`);a=e.__toESM(a);const o=(e,t)=>({replacementsMap:a,scopeValue:o})=>{if(!o||Object.keys(o).length===0)return{};let s=t?.useCustomFieldsEntries?n.SubQueryType.ENTRIES:n.SubQueryType.VALUES,c=new Map(Object.entries(a).map(([e,t])=>[t,e])),l=Object.entries(o).map(([e,t])=>{switch(s){case n.SubQueryType.ENTRIES:return n.formatConditionsForEntries(e,t,c);case n.SubQueryType.VALUES:return n.formatConditionsForValues(e,t,c);default:return!1}}).filter(Boolean);if(l.length===0)return{};let u=n.getFilterCustomFieldsSubQuery(s,e,l);return{where:{id:{[r.Op.in]:i.Sequelize.literal(`(${u})`)}},replacements:a}},s=a.customFields.CUSTOM_FIELDS_FILTER_SCOPE,c=(e,r)=>({replacementsMap:a,scopeValue:o})=>{if(!o||o.length===0)return{};let s=r?.useCustomFieldsEntries?n.SubQueryType.ENTRIES:n.SubQueryType.VALUES,c=t.generateRandomString(),l=Object.entries(o).map(([t])=>{let r=Object.keys(a).find(e=>a[e]===t);return[i.Sequelize.literal(n.getSortCustomFieldsSubQuery(s,e,r)),c]}),u=Object.entries(o).map(([,e])=>{let t=typeof e==`string`?e:Object.values(e)[0];return i.Sequelize.literal(`"${c}" ${t||`ASC`}`)});return{attributes:{include:l},order:u,replacements:a}};exports.customFieldsFilterScope=o,exports.customFieldsSortScope=c;
1
+ const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../utils/helpers/index.cjs`),n=require(`./helpers/filter.helpers.cjs`);let r=require(`sequelize`),i=require(`sequelize-typescript`),a=require(`@autofleet/common-types`);const o=(e,t)=>({replacementsMap:a,scopeValue:o})=>{if(!o||Object.keys(o).length===0)return{};let s=t?.useCustomFieldsEntries?n.SubQueryType.ENTRIES:n.SubQueryType.VALUES,c=new Map(Object.entries(a).map(([e,t])=>[t,e])),l=Object.entries(o).map(([e,t])=>{switch(s){case n.SubQueryType.ENTRIES:return n.formatConditionsForEntries(e,t,c);case n.SubQueryType.VALUES:return n.formatConditionsForValues(e,t,c);default:return!1}}).filter(Boolean);if(l.length===0)return{};let u=n.getFilterCustomFieldsSubQuery(s,e,l);return{where:{id:{[r.Op.in]:i.Sequelize.literal(`(${u})`)}},replacements:a}},s=a.customFields.CUSTOM_FIELDS_FILTER_SCOPE,c=(e,r)=>({replacementsMap:a,scopeValue:o})=>{if(!o||o.length===0)return{};let s=r?.useCustomFieldsEntries?n.SubQueryType.ENTRIES:n.SubQueryType.VALUES,c=t.generateRandomString(),l=Object.entries(o).map(([t])=>{let r=Object.keys(a).find(e=>a[e]===t);return[i.Sequelize.literal(n.getSortCustomFieldsSubQuery(s,e,r)),c]}),u=Object.entries(o).map(([,e])=>{let t=typeof e==`string`?e:Object.values(e)[0];return i.Sequelize.literal(`"${c}" ${t||`ASC`}`)});return{attributes:{include:l},order:u,replacements:a}};exports.customFieldsFilterScope=o,exports.customFieldsSortScope=c;
2
2
  //# sourceMappingURL=filter.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"filter.cjs","names":["SubQueryType","formatConditionsForEntries","formatConditionsForValues","getFilterCustomFieldsSubQuery","Op","Sequelize","scopeName: typeof customFields.CUSTOM_FIELDS_FILTER_SCOPE","customFields","generateRandomString","getSortCustomFieldsSubQuery"],"sources":["../../src/scopes/filter.ts"],"sourcesContent":["import { Op } from 'sequelize';\nimport type { Literal } from 'sequelize/types/utils';\nimport { Sequelize } from 'sequelize-typescript';\nimport { customFields } from '@autofleet/common-types';\nimport { generateRandomString } from '../utils/helpers';\nimport type { CustomFieldOptions } from '../types';\nimport {\n formatConditionsForEntries,\n formatConditionsForValues,\n getFilterCustomFieldsSubQuery,\n getSortCustomFieldsSubQuery,\n SubQueryType,\n type ConditionValue,\n type CustomFieldFilterOptions,\n} from './helpers/filter.helpers';\n\ninterface customFieldsFilterScopeParams {\n replacementsMap: Record<string, string>;\n scopeValue: Record<string, ConditionValue>;\n}\n\n/**\n * A Sequelize scope for filtering models by custom fields.\n * This scope builds a WHERE clause to be applied on the main query.\n *\n * @param name - The model type name used to join custom_field_definitions.\n * @returns A function that takes conditions and returns the Sequelize options object.\n */\nexport const customFieldsFilterScope = (\n name: string,\n options?: Pick<CustomFieldOptions, 'useCustomFieldsEntries'>,\n) => ({ replacementsMap: replacements, scopeValue: conditions }: customFieldsFilterScopeParams): CustomFieldFilterOptions => {\n if (!conditions || Object.keys(conditions).length === 0) {\n return {};\n }\n\n const queryType = options?.useCustomFieldsEntries ? SubQueryType.ENTRIES : SubQueryType.VALUES;\n const reverseReplacementsMap = new Map(Object.entries(replacements).map(([key, value]) => [value, key]));\n // Build the WHERE clause for custom field filtering\n const conditionsStrings = Object.entries(conditions).map(([key, condition]) => {\n switch (queryType) {\n case SubQueryType.ENTRIES:\n return formatConditionsForEntries(key, condition, reverseReplacementsMap);\n case SubQueryType.VALUES:\n return formatConditionsForValues(key, condition, reverseReplacementsMap);\n default:\n return false;\n }\n }).filter(Boolean);\n if (conditionsStrings.length === 0) {\n return {};\n }\n const subQuery = getFilterCustomFieldsSubQuery(queryType, name, conditionsStrings);\n\n return {\n where: {\n id: {\n [Op.in]: Sequelize.literal(`(${subQuery})`),\n },\n },\n replacements,\n };\n};\n\nexport const scopeName: typeof customFields.CUSTOM_FIELDS_FILTER_SCOPE = customFields.CUSTOM_FIELDS_FILTER_SCOPE;\n\nexport const customFieldsSortScope = (\n name: string,\n options?: Pick<CustomFieldOptions, 'useCustomFieldsEntries'>,\n) => ({ replacementsMap, scopeValue: sort }: { replacementsMap: Record<string, string>; scopeValue: Record<string, ConditionValue>; }): {\n attributes: { include: (string | Literal)[][]; };\n order: Literal[];\n replacements: Record<string, string>;\n} | Record<string, never> => {\n if (!sort || (sort as unknown as any[]).length === 0) {\n return {};\n }\n\n const queryType = options?.useCustomFieldsEntries ? SubQueryType.ENTRIES : SubQueryType.VALUES;\n const randomStr = generateRandomString();\n const includes = Object.entries(sort).map(([key]) => {\n const replacementKey = Object.keys(replacementsMap).find(\n randomString => replacementsMap[randomString] === key,\n );\n return ([\n Sequelize.literal(getSortCustomFieldsSubQuery(queryType, name, replacementKey!)),\n randomStr,\n ]);\n });\n\n const orders = Object.entries(sort).map(([, sortObject]) => {\n const direction = typeof sortObject === 'string' ? sortObject : Object.values(sortObject)[0];\n return Sequelize.literal(`\"${randomStr}\" ${direction || 'ASC'}`);\n });\n return {\n attributes: {\n include: includes,\n },\n order: orders,\n replacements: replacementsMap,\n };\n};\n"],"mappings":"6RA4BA,MAAa,GACX,EACA,KACI,CAAE,gBAAiB,EAAc,WAAY,KAA0E,CAC3H,GAAI,CAAC,GAAc,OAAO,KAAK,EAAW,CAAC,SAAW,EACpD,MAAO,EAAE,CAGX,IAAM,EAAY,GAAS,uBAAyBA,EAAAA,aAAa,QAAUA,EAAAA,aAAa,OAClF,EAAyB,IAAI,IAAI,OAAO,QAAQ,EAAa,CAAC,KAAK,CAAC,EAAK,KAAW,CAAC,EAAO,EAAI,CAAC,CAAC,CAElG,EAAoB,OAAO,QAAQ,EAAW,CAAC,KAAK,CAAC,EAAK,KAAe,CAC7E,OAAQ,EAAR,CACE,KAAKA,EAAAA,aAAa,QAChB,OAAOC,EAAAA,2BAA2B,EAAK,EAAW,EAAuB,CAC3E,KAAKD,EAAAA,aAAa,OAChB,OAAOE,EAAAA,0BAA0B,EAAK,EAAW,EAAuB,CAC1E,QACE,MAAO,KAEX,CAAC,OAAO,QAAQ,CAClB,GAAI,EAAkB,SAAW,EAC/B,MAAO,EAAE,CAEX,IAAM,EAAWC,EAAAA,8BAA8B,EAAW,EAAM,EAAkB,CAElF,MAAO,CACL,MAAO,CACL,GAAI,EACDC,EAAAA,GAAG,IAAKC,EAAAA,UAAU,QAAQ,IAAI,EAAS,GAAG,CAC5C,CACF,CACD,eACD,EAGUC,EAA4DC,EAAAA,aAAa,2BAEzE,GACX,EACA,KACI,CAAE,kBAAiB,WAAY,KAIR,CAC3B,GAAI,CAAC,GAAS,EAA0B,SAAW,EACjD,MAAO,EAAE,CAGX,IAAM,EAAY,GAAS,uBAAyBP,EAAAA,aAAa,QAAUA,EAAAA,aAAa,OAClF,EAAYQ,EAAAA,sBAAsB,CAClC,EAAW,OAAO,QAAQ,EAAK,CAAC,KAAK,CAAC,KAAS,CACnD,IAAM,EAAiB,OAAO,KAAK,EAAgB,CAAC,KAClD,GAAgB,EAAgB,KAAkB,EACnD,CACD,MAAQ,CACNH,EAAAA,UAAU,QAAQI,EAAAA,4BAA4B,EAAW,EAAM,EAAgB,CAAC,CAChF,EACD,EACD,CAEI,EAAS,OAAO,QAAQ,EAAK,CAAC,KAAK,EAAG,KAAgB,CAC1D,IAAM,EAAY,OAAO,GAAe,SAAW,EAAa,OAAO,OAAO,EAAW,CAAC,GAC1F,OAAOJ,EAAAA,UAAU,QAAQ,IAAI,EAAU,IAAI,GAAa,QAAQ,EAChE,CACF,MAAO,CACL,WAAY,CACV,QAAS,EACV,CACD,MAAO,EACP,aAAc,EACf"}
1
+ {"version":3,"file":"filter.cjs","names":["SubQueryType","formatConditionsForEntries","formatConditionsForValues","getFilterCustomFieldsSubQuery","Op","Sequelize","scopeName: typeof customFields.CUSTOM_FIELDS_FILTER_SCOPE","customFields","generateRandomString","getSortCustomFieldsSubQuery"],"sources":["../../src/scopes/filter.ts"],"sourcesContent":["import { Op } from 'sequelize';\nimport type { Literal } from 'sequelize/types/utils';\nimport { Sequelize } from 'sequelize-typescript';\nimport { customFields } from '@autofleet/common-types';\nimport { generateRandomString } from '../utils/helpers';\nimport type { CustomFieldOptions } from '../types';\nimport {\n formatConditionsForEntries,\n formatConditionsForValues,\n getFilterCustomFieldsSubQuery,\n getSortCustomFieldsSubQuery,\n SubQueryType,\n type ConditionValue,\n type CustomFieldFilterOptions,\n} from './helpers/filter.helpers';\n\ninterface customFieldsFilterScopeParams {\n replacementsMap: Record<string, string>;\n scopeValue: Record<string, ConditionValue>;\n}\n\n/**\n * A Sequelize scope for filtering models by custom fields.\n * This scope builds a WHERE clause to be applied on the main query.\n *\n * @param name - The model type name used to join custom_field_definitions.\n * @returns A function that takes conditions and returns the Sequelize options object.\n */\nexport const customFieldsFilterScope = (\n name: string,\n options?: Pick<CustomFieldOptions, 'useCustomFieldsEntries'>,\n) => ({ replacementsMap: replacements, scopeValue: conditions }: customFieldsFilterScopeParams): CustomFieldFilterOptions => {\n if (!conditions || Object.keys(conditions).length === 0) {\n return {};\n }\n\n const queryType = options?.useCustomFieldsEntries ? SubQueryType.ENTRIES : SubQueryType.VALUES;\n const reverseReplacementsMap = new Map(Object.entries(replacements).map(([key, value]) => [value, key]));\n // Build the WHERE clause for custom field filtering\n const conditionsStrings = Object.entries(conditions).map(([key, condition]) => {\n switch (queryType) {\n case SubQueryType.ENTRIES:\n return formatConditionsForEntries(key, condition, reverseReplacementsMap);\n case SubQueryType.VALUES:\n return formatConditionsForValues(key, condition, reverseReplacementsMap);\n default:\n return false;\n }\n }).filter(Boolean);\n if (conditionsStrings.length === 0) {\n return {};\n }\n const subQuery = getFilterCustomFieldsSubQuery(queryType, name, conditionsStrings);\n\n return {\n where: {\n id: {\n [Op.in]: Sequelize.literal(`(${subQuery})`),\n },\n },\n replacements,\n };\n};\n\nexport const scopeName: typeof customFields.CUSTOM_FIELDS_FILTER_SCOPE = customFields.CUSTOM_FIELDS_FILTER_SCOPE;\n\nexport const customFieldsSortScope = (\n name: string,\n options?: Pick<CustomFieldOptions, 'useCustomFieldsEntries'>,\n) => ({ replacementsMap, scopeValue: sort }: { replacementsMap: Record<string, string>; scopeValue: Record<string, ConditionValue>; }): {\n attributes: { include: (string | Literal)[][]; };\n order: Literal[];\n replacements: Record<string, string>;\n} | Record<string, never> => {\n if (!sort || (sort as unknown as any[]).length === 0) {\n return {};\n }\n\n const queryType = options?.useCustomFieldsEntries ? SubQueryType.ENTRIES : SubQueryType.VALUES;\n const randomStr = generateRandomString();\n const includes = Object.entries(sort).map(([key]) => {\n const replacementKey = Object.keys(replacementsMap).find(\n randomString => replacementsMap[randomString] === key,\n );\n return ([\n Sequelize.literal(getSortCustomFieldsSubQuery(queryType, name, replacementKey!)),\n randomStr,\n ]);\n });\n\n const orders = Object.entries(sort).map(([, sortObject]) => {\n const direction = typeof sortObject === 'string' ? sortObject : Object.values(sortObject)[0];\n return Sequelize.literal(`\"${randomStr}\" ${direction || 'ASC'}`);\n });\n return {\n attributes: {\n include: includes,\n },\n order: orders,\n replacements: replacementsMap,\n };\n};\n"],"mappings":"wOA4BA,MAAa,GACX,EACA,KACI,CAAE,gBAAiB,EAAc,WAAY,KAA0E,CAC3H,GAAI,CAAC,GAAc,OAAO,KAAK,EAAW,CAAC,SAAW,EACpD,MAAO,EAAE,CAGX,IAAM,EAAY,GAAS,uBAAyBA,EAAAA,aAAa,QAAUA,EAAAA,aAAa,OAClF,EAAyB,IAAI,IAAI,OAAO,QAAQ,EAAa,CAAC,KAAK,CAAC,EAAK,KAAW,CAAC,EAAO,EAAI,CAAC,CAAC,CAElG,EAAoB,OAAO,QAAQ,EAAW,CAAC,KAAK,CAAC,EAAK,KAAe,CAC7E,OAAQ,EAAR,CACE,KAAKA,EAAAA,aAAa,QAChB,OAAOC,EAAAA,2BAA2B,EAAK,EAAW,EAAuB,CAC3E,KAAKD,EAAAA,aAAa,OAChB,OAAOE,EAAAA,0BAA0B,EAAK,EAAW,EAAuB,CAC1E,QACE,MAAO,KAEX,CAAC,OAAO,QAAQ,CAClB,GAAI,EAAkB,SAAW,EAC/B,MAAO,EAAE,CAEX,IAAM,EAAWC,EAAAA,8BAA8B,EAAW,EAAM,EAAkB,CAElF,MAAO,CACL,MAAO,CACL,GAAI,EACDC,EAAAA,GAAG,IAAKC,EAAAA,UAAU,QAAQ,IAAI,EAAS,GAAG,CAC5C,CACF,CACD,eACD,EAGUC,EAA4DC,EAAAA,aAAa,2BAEzE,GACX,EACA,KACI,CAAE,kBAAiB,WAAY,KAIR,CAC3B,GAAI,CAAC,GAAS,EAA0B,SAAW,EACjD,MAAO,EAAE,CAGX,IAAM,EAAY,GAAS,uBAAyBP,EAAAA,aAAa,QAAUA,EAAAA,aAAa,OAClF,EAAYQ,EAAAA,sBAAsB,CAClC,EAAW,OAAO,QAAQ,EAAK,CAAC,KAAK,CAAC,KAAS,CACnD,IAAM,EAAiB,OAAO,KAAK,EAAgB,CAAC,KAClD,GAAgB,EAAgB,KAAkB,EACnD,CACD,MAAQ,CACNH,EAAAA,UAAU,QAAQI,EAAAA,4BAA4B,EAAW,EAAM,EAAgB,CAAC,CAChF,EACD,EACD,CAEI,EAAS,OAAO,QAAQ,EAAK,CAAC,KAAK,EAAG,KAAgB,CAC1D,IAAM,EAAY,OAAO,GAAe,SAAW,EAAa,OAAO,OAAO,EAAW,CAAC,GAC1F,OAAOJ,EAAAA,UAAU,QAAQ,IAAI,EAAU,IAAI,GAAa,QAAQ,EAChE,CACF,MAAO,CACL,WAAY,CACV,QAAS,EACV,CACD,MAAO,EACP,aAAc,EACf"}
@@ -1,3 +1,4 @@
1
+ import "../models/CustomFieldDefinition.cjs";
1
2
  import { ModelCtor, Sequelize } from "sequelize-typescript";
2
3
  import { IncludeOptions } from "sequelize";
3
4
  import { getUser } from "@autofleet/zehut";
@@ -1,3 +1,5 @@
1
+ import "../models/CustomValidator.js";
2
+ import "../models/CustomFieldDefinition.js";
1
3
  import { IncludeOptions } from "sequelize";
2
4
  import { getUser } from "@autofleet/zehut";
3
5
  import { ModelCtor, Sequelize } from "sequelize-typescript";
@@ -1,2 +1,2 @@
1
- const e=require(`../../_virtual/rolldown_runtime.cjs`);let t=require(`@autofleet/common-types`);t=e.__toESM(t);const n=[`businessModelId`,`fleetId`,`demandSourceId`];let r=function(e){return e.NUMBER=`number`,e.BOOLEAN=`boolean`,e.DATE=`date`,e.DATETIME=`datetime`,e.TEXT=`text`,e.IMAGE=`image`,e.SELECT=`select`,e.STATUS=`status`,e.FILE=`file`,e}({});const i=t.customFields.CUSTOM_FIELDS_FILTER_SCOPE;exports.CUSTOM_FIELDS_FILTER_SCOPE=i,exports.CustomFieldDefinitionType=r,exports.supportedEntities=n;
1
+ const e=require(`../../_virtual/rolldown_runtime.cjs`);let t=require(`@autofleet/common-types`);const n=[`businessModelId`,`fleetId`,`demandSourceId`];let r=function(e){return e.NUMBER=`number`,e.BOOLEAN=`boolean`,e.DATE=`date`,e.DATETIME=`datetime`,e.TEXT=`text`,e.IMAGE=`image`,e.SELECT=`select`,e.STATUS=`status`,e.FILE=`file`,e}({});const i=t.customFields.CUSTOM_FIELDS_FILTER_SCOPE;exports.CUSTOM_FIELDS_FILTER_SCOPE=i,exports.CustomFieldDefinitionType=r,exports.supportedEntities=n;
2
2
  //# sourceMappingURL=index.cjs.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\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
+ {"version":3,"file":"index.cjs","names":["CUSTOM_FIELDS_FILTER_SCOPE: typeof customFields.CUSTOM_FIELDS_FILTER_SCOPE","customFields"],"sources":["../../../src/utils/constants/index.ts"],"sourcesContent":["import { customFields } from '@autofleet/common-types';\n\nexport const supportedEntities = ['businessModelId', 'fleetId', 'demandSourceId'] as const;\n\n/**\n * Supported custom field types\n */\nexport enum CustomFieldDefinitionType {\n NUMBER = 'number',\n BOOLEAN = 'boolean',\n DATE = 'date',\n DATETIME = 'datetime',\n TEXT = 'text',\n IMAGE = 'image',\n SELECT = 'select',\n STATUS = 'status',\n FILE = 'file',\n}\n\nconst CUSTOM_FIELDS_FILTER_SCOPE: typeof customFields.CUSTOM_FIELDS_FILTER_SCOPE = customFields.CUSTOM_FIELDS_FILTER_SCOPE;\n\nexport {\n /** @deprecated Use the value from `@autofleet/common-types` instead */\n CUSTOM_FIELDS_FILTER_SCOPE,\n};\n"],"mappings":"gGAEA,MAAa,EAAoB,CAAC,kBAAmB,UAAW,iBAAiB,CAKjF,IAAY,EAAA,SAAA,EAAL,OACL,GAAA,OAAA,SACA,EAAA,QAAA,UACA,EAAA,KAAA,OACA,EAAA,SAAA,WACA,EAAA,KAAA,OACA,EAAA,MAAA,QACA,EAAA,OAAA,SACA,EAAA,OAAA,SACA,EAAA,KAAA,cAGF,MAAMA,EAA6EC,EAAAA,aAAa"}
@@ -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=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;
1
+ const e=require(`../../_virtual/rolldown_runtime.cjs`);let t=require(`sequelize`),n=require(`sequelize-typescript`);var r=e=>{let t=e[process.env.NODE_ENV||`test`],r;return r=t.use_env_variable?new n.Sequelize(process.env[t.use_env_variable],t):new n.Sequelize(t.database,t.username,t.password,t),r};exports.default=r;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["sequelize: Sequelize","Sequelize","sequelize"],"sources":["../../../src/utils/db/index.ts"],"sourcesContent":["import { Sequelize } from 'sequelize-typescript';\nimport { QueryTypes } from 'sequelize';\n\nexport default (databaseConfig: any): Sequelize => {\n const ENV_DEV = 'test';\n const env: string = process.env.NODE_ENV || ENV_DEV;\n const config = databaseConfig[env];\n let sequelize: Sequelize;\n if (config.use_env_variable) {\n sequelize = new Sequelize(process.env[config.use_env_variable]!, config);\n } else {\n sequelize = new Sequelize(config.database, config.username, config.password, config);\n }\n return sequelize;\n};\n\nexport const createSequelizeMeta = (sequelize: Sequelize): Promise<{ name: string; }[]> => sequelize.query(`\nCREATE TABLE IF NOT EXISTS \"SequelizeMeta\" (\n name character varying(255) PRIMARY KEY\n);\n`, { type: QueryTypes.SELECT });\n"],"mappings":"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
+ {"version":3,"file":"index.cjs","names":["sequelize: Sequelize","Sequelize","sequelize"],"sources":["../../../src/utils/db/index.ts"],"sourcesContent":["import { Sequelize } from 'sequelize-typescript';\nimport { QueryTypes } from 'sequelize';\n\nexport default (databaseConfig: any): Sequelize => {\n const ENV_DEV = 'test';\n const env: string = process.env.NODE_ENV || ENV_DEV;\n const config = databaseConfig[env];\n let sequelize: Sequelize;\n if (config.use_env_variable) {\n sequelize = new Sequelize(process.env[config.use_env_variable]!, config);\n } else {\n sequelize = new Sequelize(config.database, config.username, config.password, config);\n }\n return sequelize;\n};\n\nexport const createSequelizeMeta = (sequelize: Sequelize): Promise<{ name: string; }[]> => sequelize.query(`\nCREATE TABLE IF NOT EXISTS \"SequelizeMeta\" (\n name character varying(255) PRIMARY KEY\n);\n`, { type: QueryTypes.SELECT });\n"],"mappings":"oHAGA,IAAA,EAAgB,GAAmC,CAGjD,IAAM,EAAS,EADK,QAAQ,IAAI,UADhB,QAGZA,EAMJ,MALA,CAGE,EAHE,EAAO,iBACG,IAAIC,EAAAA,UAAU,QAAQ,IAAI,EAAO,kBAAoB,EAAO,CAE5D,IAAIA,EAAAA,UAAU,EAAO,SAAU,EAAO,SAAU,EAAO,SAAU,EAAO,CAE/EC"}
@@ -1,2 +1,2 @@
1
- const e=require(`../../_virtual/rolldown_runtime.cjs`),t=require(`../constants/index.cjs`);let n=require(`sequelize`);n=e.__toESM(n);let r=require(`sequelize-typescript`);r=e.__toESM(r);let i=require(`node:crypto`);i=e.__toESM(i);const a=(e=5)=>Array.from({length:e},()=>`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`.charAt((0,i.randomInt)(52))).join(``),o=(e,i,a,o=[t.CustomFieldDefinitionType.DATETIME,t.CustomFieldDefinitionType.DATE])=>{let s=o.map(e=>`'${e}'`).join(`,`),c=`EXISTS ( SELECT 1 FROM "custom_field_values" AS "cv" INNER JOIN custom_field_definitions AS cd ON cd.entity_id = '${a}' AND cv.custom_field_definition_id = cd.id AND cd.model_type = '${i.name}' ${s?`AND cd.field_type NOT IN (${s})`:``} WHERE "cv"."deleted_at" IS NULL AND "cv"."model_id" = "${i.name}"."id" AND CAST("cv"."value" AS TEXT) ILIKE :searchTerm)`;return{where:{[n.Op.or]:[r.Sequelize.where(r.Sequelize.literal(c),!0)]},replacements:{searchTerm:`%${e}%`}}};exports.generateCustomFieldSearchQueryPayload=o,exports.generateRandomString=a;
1
+ const e=require(`../../_virtual/rolldown_runtime.cjs`),t=require(`../constants/index.cjs`);let n=require(`sequelize`),r=require(`sequelize-typescript`),i=require(`node:crypto`);const a=(e=5)=>Array.from({length:e},()=>`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`.charAt((0,i.randomInt)(52))).join(``),o=(e,i,a,o=[t.CustomFieldDefinitionType.DATETIME,t.CustomFieldDefinitionType.DATE])=>{let s=o.map(e=>`'${e}'`).join(`,`),c=`EXISTS ( SELECT 1 FROM "custom_field_values" AS "cv" INNER JOIN custom_field_definitions AS cd ON cd.entity_id = '${a}' AND cv.custom_field_definition_id = cd.id AND cd.model_type = '${i.name}' ${s?`AND cd.field_type NOT IN (${s})`:``} WHERE "cv"."deleted_at" IS NULL AND "cv"."model_id" = "${i.name}"."id" AND CAST("cv"."value" AS TEXT) ILIKE :searchTerm)`;return{where:{[n.Op.or]:[r.Sequelize.where(r.Sequelize.literal(c),!0)]},replacements:{searchTerm:`%${e}%`}}};exports.generateCustomFieldSearchQueryPayload=o,exports.generateRandomString=a;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["CustomFieldDefinitionType","Op","Sequelize"],"sources":["../../../src/utils/helpers/index.ts"],"sourcesContent":["import { type WhereOptions, Op, type BindOrReplacements } from 'sequelize';\nimport { type ModelStatic, Sequelize } from 'sequelize-typescript';\nimport { randomInt } from 'node:crypto';\nimport { CustomFieldDefinitionType } from '../constants';\n\n/**\n * Builds a WHERE clause and replacements for free-text search by custom fields.\n *\n * This function constructs a WHERE clause and replacement bindings that allow searching\n * for a given term within custom fields associated with a specific model type and entity ID.\n * The WHERE clause and replacements are designed to be added to the main query.\n *\n * @param {string} searchTerm - The term to search for within custom fields.\n * @param {ModelStatic} model - The Sequelize model representing the entity type to search for.\n * @param {string} entityId - The entity ID to filter the custom fields by.\n * @param {CustomFieldDefinitionType[]} excludedCustomFieldsTypes - An array of custom field types\n * to exclude from the search\n *\n * @returns {CustomFieldsSearchPayload} - An object containing the WHERE clause and replacements\n * for Sequelize.\n */\n\ninterface CustomFieldsSearchPayload {\n where: WhereOptions;\n replacements: BindOrReplacements;\n}\n\nexport const generateRandomString = (length = 5): string => {\n const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';\n return Array.from({ length }, () => characters.charAt(randomInt(characters.length))).join('');\n};\n\nexport const generateCustomFieldSearchQueryPayload = (\n searchTerm: string,\n model: ModelStatic,\n entityId: string,\n customFieldsTypesToExclude: CustomFieldDefinitionType[] = [\n CustomFieldDefinitionType.DATETIME,\n CustomFieldDefinitionType.DATE,\n ],\n): CustomFieldsSearchPayload => {\n const excludedTypesString = customFieldsTypesToExclude.map(type => `'${type}'`).join(',');\n\n const subQuery = 'EXISTS ('\n + ' SELECT 1'\n + ' FROM \"custom_field_values\" AS \"cv\"'\n + ' INNER JOIN custom_field_definitions AS cd '\n + ` ON cd.entity_id = '${entityId}'`\n + ' AND cv.custom_field_definition_id = cd.id'\n + ` AND cd.model_type = '${model.name}'`\n + ` ${excludedTypesString ? `AND cd.field_type NOT IN (${excludedTypesString})` : ''}`\n + ' WHERE'\n + ' \"cv\".\"deleted_at\" IS NULL'\n + ` AND \"cv\".\"model_id\" = \"${model.name}\".\"id\"`\n + ' AND CAST(\"cv\".\"value\" AS TEXT) ILIKE :searchTerm)';\n\n return {\n where: {\n [Op.or]: [\n Sequelize.where(Sequelize.literal(subQuery), true),\n ],\n },\n replacements: { searchTerm: `%${searchTerm}%` },\n };\n};\n"],"mappings":"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
+ {"version":3,"file":"index.cjs","names":["CustomFieldDefinitionType","Op","Sequelize"],"sources":["../../../src/utils/helpers/index.ts"],"sourcesContent":["import { type WhereOptions, Op, type BindOrReplacements } from 'sequelize';\nimport { type ModelStatic, Sequelize } from 'sequelize-typescript';\nimport { randomInt } from 'node:crypto';\nimport { CustomFieldDefinitionType } from '../constants';\n\n/**\n * Builds a WHERE clause and replacements for free-text search by custom fields.\n *\n * This function constructs a WHERE clause and replacement bindings that allow searching\n * for a given term within custom fields associated with a specific model type and entity ID.\n * The WHERE clause and replacements are designed to be added to the main query.\n *\n * @param {string} searchTerm - The term to search for within custom fields.\n * @param {ModelStatic} model - The Sequelize model representing the entity type to search for.\n * @param {string} entityId - The entity ID to filter the custom fields by.\n * @param {CustomFieldDefinitionType[]} excludedCustomFieldsTypes - An array of custom field types\n * to exclude from the search\n *\n * @returns {CustomFieldsSearchPayload} - An object containing the WHERE clause and replacements\n * for Sequelize.\n */\n\ninterface CustomFieldsSearchPayload {\n where: WhereOptions;\n replacements: BindOrReplacements;\n}\n\nexport const generateRandomString = (length = 5): string => {\n const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';\n return Array.from({ length }, () => characters.charAt(randomInt(characters.length))).join('');\n};\n\nexport const generateCustomFieldSearchQueryPayload = (\n searchTerm: string,\n model: ModelStatic,\n entityId: string,\n customFieldsTypesToExclude: CustomFieldDefinitionType[] = [\n CustomFieldDefinitionType.DATETIME,\n CustomFieldDefinitionType.DATE,\n ],\n): CustomFieldsSearchPayload => {\n const excludedTypesString = customFieldsTypesToExclude.map(type => `'${type}'`).join(',');\n\n const subQuery = 'EXISTS ('\n + ' SELECT 1'\n + ' FROM \"custom_field_values\" AS \"cv\"'\n + ' INNER JOIN custom_field_definitions AS cd '\n + ` ON cd.entity_id = '${entityId}'`\n + ' AND cv.custom_field_definition_id = cd.id'\n + ` AND cd.model_type = '${model.name}'`\n + ` ${excludedTypesString ? `AND cd.field_type NOT IN (${excludedTypesString})` : ''}`\n + ' WHERE'\n + ' \"cv\".\"deleted_at\" IS NULL'\n + ` AND \"cv\".\"model_id\" = \"${model.name}\".\"id\"`\n + ' AND CAST(\"cv\".\"value\" AS TEXT) ILIKE :searchTerm)';\n\n return {\n where: {\n [Op.or]: [\n Sequelize.where(Sequelize.literal(subQuery), true),\n ],\n },\n replacements: { searchTerm: `%${searchTerm}%` },\n };\n};\n"],"mappings":"iLA2BA,MAAa,GAAwB,EAAS,IAErC,MAAM,KAAK,CAAE,SAAQ,KAAQ,uDAAW,QAAA,EAAA,EAAA,WAAiB,GAAkB,CAAC,CAAC,CAAC,KAAK,GAAG,CAGlF,GACX,EACA,EACA,EACA,EAA0D,CACxDA,EAAAA,0BAA0B,SAC1BA,EAAAA,0BAA0B,KAC3B,GAC6B,CAC9B,IAAM,EAAsB,EAA2B,IAAI,GAAQ,IAAI,EAAK,GAAG,CAAC,KAAK,IAAI,CAEnF,EAAW,sHAIU,EAAS,mEAEP,EAAM,KAAK,IAChC,EAAsB,6BAA6B,EAAoB,GAAK,GAAA,0DAGrD,EAAM,KAAK,0DAG1C,MAAO,CACL,MAAO,EACJC,EAAAA,GAAG,IAAK,CACPC,EAAAA,UAAU,MAAMA,EAAAA,UAAU,QAAQ,EAAS,CAAE,GAAK,CACnD,CACF,CACD,aAAc,CAAE,WAAY,IAAI,EAAW,GAAI,CAChD"}
@@ -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,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;
1
+ const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`./logger/index.cjs`),n=require(`../models/CustomFieldDefinition.cjs`),r=require(`../models/CustomFieldValue.cjs`),i=require(`../models/CustomValidator.cjs`);require(`../models/index.cjs`);const a=require(`../hooks/enrich.cjs`),o=require(`../hooks/find.cjs`),s=require(`../hooks/hooks.cjs`);require(`../hooks/index.cjs`);const c=require(`../scopes/filter.cjs`);require(`../scopes/index.cjs`);let l=require(`sequelize`),u=require(`@autofleet/common-types`),d=require(`@autofleet/common-types/lib/custom-fields`);const{CUSTOM_FIELDS_FILTER_SCOPE:f}=u.customFields,p=(e,n,r={useCustomFieldsEntries:!1})=>{e.forEach(async({name:e,scopeAttributes:i,modelOptions:c})=>{try{let u=n(e);if(!u){t.default.warn(`sadot - tried to addHooks to a model that does not exist yet`,{name:e,scopeAttributes:i});return}u.rawAttributes.customFields={type:l.DataTypes.VIRTUAL},u.refreshAttributes(),u.addHook(`beforeFind`,`sadot-beforeFind`,o.beforeFind(i)),u.addHook(`beforeBulkCreate`,`sadot-beforeBulkCreate`,s.beforeBulkCreate),u.addHook(`beforeBulkUpdate`,`sadot-beforeBulkUpdate`,s.beforeBulkUpdate),u.addHook(`beforeCreate`,`sadot-beforeCreate`,s.beforeCreate(i,c,r)),u.addHook(`beforeUpdate`,`sadot-beforeUpdate`,s.beforeUpdate(i,c,r)),u.addHook(`afterFind`,`sadot-afterFind`,a.default(e,i,`afterFind`,c,r)),u.addHook(`afterUpdate`,`sadot-afterUpdate`,a.default(e,i,void 0,c,r)),u.addHook(`afterCreate`,`sadot-afterCreate`,a.default(e,i,void 0,c,r))}catch(n){t.default.error(`Could not add custom fields hook to model ${e}. `,n)}})},m=(e,n)=>{e.forEach(async({name:e})=>{try{let t=n(e);if(!t)return;t.rawAttributes.customFields&&(delete t.rawAttributes.customFields,t.refreshAttributes()),t.removeHook(`beforeFind`,`sadot-beforeFind`),t.removeHook(`beforeBulkCreate`,`sadot-beforeBulkCreate`),t.removeHook(`beforeBulkUpdate`,`sadot-beforeBulkUpdate`),t.removeHook(`beforeCreate`,`sadot-beforeCreate`),t.removeHook(`beforeUpdate`,`sadot-beforeUpdate`),t.removeHook(`afterFind`,`sadot-afterFind`),t.removeHook(`afterUpdate`,`sadot-afterUpdate`)}catch(n){t.default.error(`Could not add custom fields hook to model ${e}. `,n)}})},h=(e,t,n)=>{n?.useCustomFieldsEntries||(e.hasMany(r.default,{foreignKey:`modelId`,as:`customFieldValue`}),r.default.belongsTo(e,{foreignKey:`modelId`,as:t}))},g=(e,n,r={useCustomFieldsEntries:!1})=>{e.forEach(async({name:e,scopeAttributes:i})=>{try{let a=n(e);if(!a){t.default.warn(`sadot - tried to addScopes to a model that does not exist yet`,{name:e,scopeAttributes:i});return}h(a,e,r),a.addScope(f,c.customFieldsFilterScope(e,r)),a.addScope(d.CUSTOM_FIELDS_SORT_SCOPE,c.customFieldsSortScope(e,r))}catch(n){t.default.error(`Could not add custom fields scopes to model ${e}. `,n)}})},_=e=>{e.forEach(({modelOptions:e})=>{e?.customAssociation?.(n.default),e?.customAssociation?.(i.default)})};exports.addHooks=p,exports.addScopes=g,exports.applyCustomAssociation=_,exports.removeHooks=m;
2
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, 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
+ {"version":3,"file":"init.cjs","names":["customFields","DataTypes","beforeFind","beforeBulkCreate","beforeBulkUpdate","beforeCreate","beforeUpdate","enrichResults","CustomFieldValue","customFieldsFilterScope","CUSTOM_FIELDS_SORT_SCOPE","customFieldsSortScope","CustomFieldDefinition","CustomValidator"],"sources":["../../src/utils/init.ts"],"sourcesContent":["import { DataTypes } from 'sequelize';\nimport type { ModelCtor } from 'sequelize-typescript';\nimport { customFields } from '@autofleet/common-types';\nimport { CUSTOM_FIELDS_SORT_SCOPE } from '@autofleet/common-types/lib/custom-fields';\nimport {\n CustomFieldDefinition,\n CustomFieldValue,\n CustomValidator,\n} from '../models';\nimport {\n beforeFind,\n enrichResults,\n beforeBulkUpdate,\n beforeUpdate,\n beforeCreate,\n beforeBulkCreate,\n} from '../hooks';\nimport { customFieldsFilterScope } from '../scopes';\nimport logger from './logger';\nimport type { CustomFieldOptions, ModelFetcher, Models } from '../types';\nimport { customFieldsSortScope } from '../scopes/filter';\n\nconst { CUSTOM_FIELDS_FILTER_SCOPE } = customFields;\n\nexport const addHooks = (\n models: Models[],\n getModel: ModelFetcher,\n sadotOptions: { useCustomFieldsEntries?: boolean; } = { useCustomFieldsEntries: false },\n): void => {\n models.forEach(async ({\n name, scopeAttributes, modelOptions,\n }) => {\n try {\n const model = getModel(name);\n if (!model) {\n logger.warn('sadot - tried to addHooks to a model that does not exist yet', {\n name,\n scopeAttributes,\n });\n return;\n }\n model.rawAttributes.customFields = {\n type: DataTypes.VIRTUAL,\n };\n model.refreshAttributes();\n // TODO: Uncomment after tests are passed\n // model.addHook('afterFind', workaround);\n model.addHook('beforeFind', 'sadot-beforeFind', beforeFind(scopeAttributes));\n model.addHook('beforeBulkCreate', 'sadot-beforeBulkCreate', beforeBulkCreate);\n model.addHook('beforeBulkUpdate', 'sadot-beforeBulkUpdate', beforeBulkUpdate);\n model.addHook('beforeCreate', 'sadot-beforeCreate', beforeCreate(scopeAttributes, modelOptions, sadotOptions));\n model.addHook('beforeUpdate', 'sadot-beforeUpdate', beforeUpdate(scopeAttributes, modelOptions, sadotOptions));\n model.addHook('afterFind', 'sadot-afterFind', enrichResults(name, scopeAttributes, 'afterFind', modelOptions, sadotOptions));\n model.addHook('afterUpdate', 'sadot-afterUpdate', enrichResults(name, scopeAttributes, undefined, modelOptions, sadotOptions));\n model.addHook('afterCreate', 'sadot-afterCreate', enrichResults(name, scopeAttributes, undefined, modelOptions, sadotOptions));\n } catch (e) {\n logger.error(`Could not add custom fields hook to model ${name}. `, e);\n }\n });\n};\n\nexport const removeHooks = (models: Models[], getModel: ModelFetcher): void => {\n models.forEach(async ({ name }) => {\n try {\n const model = getModel(name);\n if (!model) return;\n if (model.rawAttributes.customFields) {\n delete model.rawAttributes.customFields;\n model.refreshAttributes();\n }\n // model.removeHook('afterFind', 'sadot-workaround');\n model.removeHook('beforeFind', 'sadot-beforeFind');\n model.removeHook('beforeBulkCreate', 'sadot-beforeBulkCreate');\n model.removeHook('beforeBulkUpdate', 'sadot-beforeBulkUpdate');\n model.removeHook('beforeCreate', 'sadot-beforeCreate');\n model.removeHook('beforeUpdate', 'sadot-beforeUpdate');\n model.removeHook('afterFind', 'sadot-afterFind');\n model.removeHook('afterUpdate', 'sadot-afterUpdate');\n } catch (e) {\n logger.error(`Could not add custom fields hook to model ${name}. `, e);\n }\n });\n};\n\n/**\n * Necessary associations for the {@link customFieldsFilterScope} scope\n */\nconst addAssociations = (model: ModelCtor, modelName: string, options: Pick<CustomFieldOptions, 'useCustomFieldsEntries'>): void => {\n if (options?.useCustomFieldsEntries) return;\n model.hasMany(CustomFieldValue, { foreignKey: 'modelId', as: 'customFieldValue' });\n // TBC: maybe can be removed\n CustomFieldValue.belongsTo(model, { foreignKey: 'modelId', as: modelName });\n};\n\nexport const addScopes = (models: Models[], getModel: ModelFetcher, options: Pick<CustomFieldOptions, 'useCustomFieldsEntries'> = { useCustomFieldsEntries: false }): void => {\n models.forEach(async ({ name, scopeAttributes }) => {\n try {\n const model = getModel(name);\n if (!model) {\n logger.warn('sadot - tried to addScopes to a model that does not exist yet', {\n name,\n scopeAttributes,\n });\n return;\n }\n // Necessary associations for the filtering scope\n addAssociations(model, name, options);\n // Add filter scope\n model.addScope(CUSTOM_FIELDS_FILTER_SCOPE, customFieldsFilterScope(name, options));\n model.addScope(CUSTOM_FIELDS_SORT_SCOPE, customFieldsSortScope(name, options));\n } catch (e) {\n logger.error(`Could not add custom fields scopes to model ${name}. `, e);\n }\n });\n};\n\nexport const applyCustomAssociation = (models: Models[]): void => {\n models.forEach(({ modelOptions }) => {\n modelOptions?.customAssociation?.(CustomFieldDefinition);\n modelOptions?.customAssociation?.(CustomValidator);\n });\n};\n"],"mappings":"6jBAsBA,KAAM,CAAE,8BAA+BA,EAAAA,aAE1B,GACX,EACA,EACA,EAAsD,CAAE,uBAAwB,GAAO,GAC9E,CACT,EAAO,QAAQ,MAAO,CACpB,OAAM,kBAAiB,kBACnB,CACJ,GAAI,CACF,IAAM,EAAQ,EAAS,EAAK,CAC5B,GAAI,CAAC,EAAO,CACV,EAAA,QAAO,KAAK,+DAAgE,CAC1E,OACA,kBACD,CAAC,CACF,OAEF,EAAM,cAAc,aAAe,CACjC,KAAMC,EAAAA,UAAU,QACjB,CACD,EAAM,mBAAmB,CAGzB,EAAM,QAAQ,aAAc,mBAAoBC,EAAAA,WAAW,EAAgB,CAAC,CAC5E,EAAM,QAAQ,mBAAoB,yBAA0BC,EAAAA,iBAAiB,CAC7E,EAAM,QAAQ,mBAAoB,yBAA0BC,EAAAA,iBAAiB,CAC7E,EAAM,QAAQ,eAAgB,qBAAsBC,EAAAA,aAAa,EAAiB,EAAc,EAAa,CAAC,CAC9G,EAAM,QAAQ,eAAgB,qBAAsBC,EAAAA,aAAa,EAAiB,EAAc,EAAa,CAAC,CAC9G,EAAM,QAAQ,YAAa,kBAAmBC,EAAAA,QAAc,EAAM,EAAiB,YAAa,EAAc,EAAa,CAAC,CAC5H,EAAM,QAAQ,cAAe,oBAAqBA,EAAAA,QAAc,EAAM,EAAiB,IAAA,GAAW,EAAc,EAAa,CAAC,CAC9H,EAAM,QAAQ,cAAe,oBAAqBA,EAAAA,QAAc,EAAM,EAAiB,IAAA,GAAW,EAAc,EAAa,CAAC,OACvH,EAAG,CACV,EAAA,QAAO,MAAM,6CAA6C,EAAK,IAAK,EAAE,GAExE,EAGS,GAAe,EAAkB,IAAiC,CAC7E,EAAO,QAAQ,MAAO,CAAE,UAAW,CACjC,GAAI,CACF,IAAM,EAAQ,EAAS,EAAK,CAC5B,GAAI,CAAC,EAAO,OACR,EAAM,cAAc,eACtB,OAAO,EAAM,cAAc,aAC3B,EAAM,mBAAmB,EAG3B,EAAM,WAAW,aAAc,mBAAmB,CAClD,EAAM,WAAW,mBAAoB,yBAAyB,CAC9D,EAAM,WAAW,mBAAoB,yBAAyB,CAC9D,EAAM,WAAW,eAAgB,qBAAqB,CACtD,EAAM,WAAW,eAAgB,qBAAqB,CACtD,EAAM,WAAW,YAAa,kBAAkB,CAChD,EAAM,WAAW,cAAe,oBAAoB,OAC7C,EAAG,CACV,EAAA,QAAO,MAAM,6CAA6C,EAAK,IAAK,EAAE,GAExE,EAME,GAAmB,EAAkB,EAAmB,IAAsE,CAC9H,GAAS,yBACb,EAAM,QAAQC,EAAAA,QAAkB,CAAE,WAAY,UAAW,GAAI,mBAAoB,CAAC,CAElF,EAAA,QAAiB,UAAU,EAAO,CAAE,WAAY,UAAW,GAAI,EAAW,CAAC,GAGhE,GAAa,EAAkB,EAAwB,EAA8D,CAAE,uBAAwB,GAAO,GAAW,CAC5K,EAAO,QAAQ,MAAO,CAAE,OAAM,qBAAsB,CAClD,GAAI,CACF,IAAM,EAAQ,EAAS,EAAK,CAC5B,GAAI,CAAC,EAAO,CACV,EAAA,QAAO,KAAK,gEAAiE,CAC3E,OACA,kBACD,CAAC,CACF,OAGF,EAAgB,EAAO,EAAM,EAAQ,CAErC,EAAM,SAAS,EAA4BC,EAAAA,wBAAwB,EAAM,EAAQ,CAAC,CAClF,EAAM,SAASC,EAAAA,yBAA0BC,EAAAA,sBAAsB,EAAM,EAAQ,CAAC,OACvE,EAAG,CACV,EAAA,QAAO,MAAM,+CAA+C,EAAK,IAAK,EAAE,GAE1E,EAGS,EAA0B,GAA2B,CAChE,EAAO,SAAS,CAAE,kBAAmB,CACnC,GAAc,oBAAoBC,EAAAA,QAAsB,CACxD,GAAc,oBAAoBC,EAAAA,QAAgB,EAClD"}
@@ -1,2 +1,2 @@
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;
1
+ const e=require(`../../_virtual/rolldown_runtime.cjs`);let t=require(`@autofleet/zehut`),n=require(`@autofleet/logger`);n=e.__toESM(n);const r=(0,n.default)();function i(){r.addContextMiddleware(()=>({traceId:t.outbreak.getCurrentContextTraceId()}))}var a=r;exports.default=a,exports.tryAddingTraceIdMiddleware=i;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
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
+ {"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":"uIAGA,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
- const e=require(`../../../_virtual/rolldown_runtime.cjs`),t=require(`../../logger/index.cjs`);let n=require(`@autofleet/errors`);n=e.__toESM(n);let r=require(`ajv`);r=e.__toESM(r);let i=require(`ajv-formats`);i=e.__toESM(i);const a=new r.default({allErrors:!0,strict:!1,strictTypes:!1,$data:!0});(0,i.default)(a);const o={type:`object`,properties:{type:{type:`string`,enum:[`object`]},properties:{type:`object`,properties:{before:{type:`object`,properties:{type:{type:`string`,enum:[`object`]},properties:{type:`object`}}},after:{type:`object`,properties:{type:{type:`string`,enum:[`object`]},properties:{type:`object`}}}}},required:{type:`array`,items:{type:`string`}},if:{type:`object`},then:{type:`object`},else:{type:`object`}},required:[`type`,`properties`]},s=e=>{try{let r=a.compile(o);if(!r(e)){let i=r.errors?.map(e=>`${e.instancePath||``} ${e.message||`Invalid schema structure`}`).join(`, `);throw t.default.error(`Invalid validator schema structure`,{errors:r.errors,schema:e}),new n.BadRequest([Error(`Invalid validator schema structure: ${i}`)],[`Invalid validator schema structure`])}try{return a.compile(e),!0}catch(r){throw t.default.error(`Failed to compile validator schema`,{error:r,schema:e}),new n.BadRequest([Error(`Failed to compile validator schema: ${r.message}`)],[`Invalid validator schema`])}}catch(r){throw r instanceof n.BadRequest?r:(t.default.error(`Error validating validator schema`,{error:r,schema:e}),new n.BadRequest([Error(`Error validating validator schema: ${r.message}`)],[`Invalid validator schema`]))}};exports.validateValidatorSchema=s;
1
+ const e=require(`../../../_virtual/rolldown_runtime.cjs`),t=require(`../../logger/index.cjs`);let n=require(`@autofleet/errors`),r=require(`ajv`);r=e.__toESM(r);let i=require(`ajv-formats`);i=e.__toESM(i);const a=new r.default({allErrors:!0,strict:!1,strictTypes:!1,$data:!0});(0,i.default)(a);const o={type:`object`,properties:{type:{type:`string`,enum:[`object`]},properties:{type:`object`,properties:{before:{type:`object`,properties:{type:{type:`string`,enum:[`object`]},properties:{type:`object`}}},after:{type:`object`,properties:{type:{type:`string`,enum:[`object`]},properties:{type:`object`}}}}},required:{type:`array`,items:{type:`string`}},if:{type:`object`},then:{type:`object`},else:{type:`object`}},required:[`type`,`properties`]},s=e=>{try{let r=a.compile(o);if(!r(e)){let i=r.errors?.map(e=>`${e.instancePath||``} ${e.message||`Invalid schema structure`}`).join(`, `);throw t.default.error(`Invalid validator schema structure`,{errors:r.errors,schema:e}),new n.BadRequest([Error(`Invalid validator schema structure: ${i}`)],[`Invalid validator schema structure`])}try{return a.compile(e),!0}catch(r){throw t.default.error(`Failed to compile validator schema`,{error:r,schema:e}),new n.BadRequest([Error(`Failed to compile validator schema: ${r.message}`)],[`Invalid validator schema`])}}catch(r){throw r instanceof n.BadRequest?r:(t.default.error(`Error validating validator schema`,{error:r,schema:e}),new n.BadRequest([Error(`Error validating validator schema: ${r.message}`)],[`Invalid validator schema`]))}};exports.validateValidatorSchema=s;
2
2
  //# sourceMappingURL=validator-schema.cjs.map