@autofleet/sadot 1.1.15 → 1.2.0-0

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 (81) hide show
  1. package/dist/api/v1/definition/index.cjs +1 -1
  2. package/dist/api/v1/definition/index.cjs.map +1 -1
  3. package/dist/api/v1/definition/index.js +1 -1
  4. package/dist/api/v1/definition/index.js.map +1 -1
  5. package/dist/api/v1/definition/validations.cjs +1 -1
  6. package/dist/api/v1/definition/validations.cjs.map +1 -1
  7. package/dist/api/v1/definition/validations.js +1 -1
  8. package/dist/api/v1/definition/validations.js.map +1 -1
  9. package/dist/hooks/enrich.cjs +1 -1
  10. package/dist/hooks/enrich.cjs.map +1 -1
  11. package/dist/hooks/enrich.js +1 -1
  12. package/dist/hooks/enrich.js.map +1 -1
  13. package/dist/index.cjs +1 -1
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +3 -3
  16. package/dist/index.d.ts +3 -3
  17. package/dist/index.js +1 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/models/CustomFieldDefinition.cjs +1 -1
  20. package/dist/models/CustomFieldDefinition.cjs.map +1 -1
  21. package/dist/models/CustomFieldDefinition.d.cts +4 -0
  22. package/dist/models/CustomFieldDefinition.d.ts +4 -0
  23. package/dist/models/CustomFieldDefinition.js +1 -1
  24. package/dist/models/CustomFieldDefinition.js.map +1 -1
  25. package/dist/models/CustomFieldEntries.cjs +1 -1
  26. package/dist/models/CustomFieldEntries.cjs.map +1 -1
  27. package/dist/models/CustomFieldEntries.js +1 -1
  28. package/dist/models/CustomFieldEntries.js.map +1 -1
  29. package/dist/models/CustomFieldModelTypeMap.cjs +2 -0
  30. package/dist/models/CustomFieldModelTypeMap.cjs.map +1 -0
  31. package/dist/models/CustomFieldModelTypeMap.d.cts +15 -0
  32. package/dist/models/CustomFieldModelTypeMap.d.ts +15 -0
  33. package/dist/models/CustomFieldModelTypeMap.js +2 -0
  34. package/dist/models/CustomFieldModelTypeMap.js.map +1 -0
  35. package/dist/models/CustomFieldValue.cjs +1 -1
  36. package/dist/models/CustomFieldValue.cjs.map +1 -1
  37. package/dist/models/CustomFieldValue.d.cts +1 -0
  38. package/dist/models/CustomFieldValue.d.ts +1 -0
  39. package/dist/models/CustomFieldValue.js +1 -1
  40. package/dist/models/CustomFieldValue.js.map +1 -1
  41. package/dist/models/CustomValidator.cjs +1 -1
  42. package/dist/models/CustomValidator.cjs.map +1 -1
  43. package/dist/models/CustomValidator.js +1 -1
  44. package/dist/models/CustomValidator.js.map +1 -1
  45. package/dist/models/index.cjs +1 -1
  46. package/dist/models/index.cjs.map +1 -1
  47. package/dist/models/index.d.cts +3 -2
  48. package/dist/models/index.d.ts +3 -2
  49. package/dist/models/index.js +1 -1
  50. package/dist/models/index.js.map +1 -1
  51. package/dist/models/tests/AssociatedTestModel.cjs +1 -1
  52. package/dist/models/tests/AssociatedTestModel.cjs.map +1 -1
  53. package/dist/models/tests/AssociatedTestModel.js +1 -1
  54. package/dist/models/tests/AssociatedTestModel.js.map +1 -1
  55. package/dist/models/tests/TestModel.cjs +1 -1
  56. package/dist/models/tests/TestModel.cjs.map +1 -1
  57. package/dist/models/tests/TestModel.js +1 -1
  58. package/dist/models/tests/TestModel.js.map +1 -1
  59. package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs +1 -1
  60. package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs.map +1 -1
  61. package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js +1 -1
  62. package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js.map +1 -1
  63. package/dist/models/tests/contextAwareModels/ContextTestModel.cjs +1 -1
  64. package/dist/models/tests/contextAwareModels/ContextTestModel.cjs.map +1 -1
  65. package/dist/models/tests/contextAwareModels/ContextTestModel.js +1 -1
  66. package/dist/models/tests/contextAwareModels/ContextTestModel.js.map +1 -1
  67. package/dist/repository/definition.cjs +1 -1
  68. package/dist/repository/definition.cjs.map +1 -1
  69. package/dist/repository/definition.js +1 -1
  70. package/dist/repository/definition.js.map +1 -1
  71. package/dist/types/index.d.cts +3 -0
  72. package/dist/types/index.d.ts +4 -1
  73. package/dist/utils/init.cjs +1 -1
  74. package/dist/utils/init.cjs.map +1 -1
  75. package/dist/utils/init.js +1 -1
  76. package/dist/utils/init.js.map +1 -1
  77. package/package.json +22 -22
  78. /package/dist/_virtual/{_@oxc-project_runtime@0.103.0 → _@oxc-project_runtime@0.97.0}/helpers/decorate.cjs +0 -0
  79. /package/dist/_virtual/{_@oxc-project_runtime@0.103.0 → _@oxc-project_runtime@0.97.0}/helpers/decorate.js +0 -0
  80. /package/dist/_virtual/{_@oxc-project_runtime@0.103.0 → _@oxc-project_runtime@0.97.0}/helpers/decorateMetadata.cjs +0 -0
  81. /package/dist/_virtual/{_@oxc-project_runtime@0.103.0 → _@oxc-project_runtime@0.97.0}/helpers/decorateMetadata.js +0 -0
@@ -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":"sSAWA,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.103.0/helpers/decorateMetadata.js";import{__decorate as t}from"../../_virtual/_@oxc-project_runtime@0.103.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.97.0/helpers/decorateMetadata.js";import{__decorate as t}from"../../_virtual/_@oxc-project_runtime@0.97.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 +1 @@
1
- {"version":3,"file":"AssociatedTestModel.js","names":["AssociatedTestModel","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":"iXAWA,IAAA,EAAA,cAGkC,CAAM,MACrC,EACA,EAAO,CACN,KAAM,EAAS,KACf,aAAc,EAAS,OACvB,UAAW,GACZ,CAAC,sDAGD,MAAiBC,EAAU,CAC3B,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,+DAGD,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,UAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,kBAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,iBAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,QAChB,CAAC,CAAA,EAAA,cAAA,QAAA,CAAA,CAAA,EAAA,UAAA,mBAAA,IAAA,GAAA,IAGD,MAAgBA,EAAU,CAAA,EAAA,cAAA,OAAA,EAAA,IAAA,QAAA,IAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,MA1C5B,EAAM,CACL,OAAQ,gBAAiB,UAAW,yBAA0B,UAAW,GAAO,UAAW,GAAO,UAAW,sBAC9G,CAAC,CAAA,CAAA,EAAA,CA4CF,IAAA,EAAe"}
1
+ {"version":3,"file":"AssociatedTestModel.js","names":["AssociatedTestModel","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":"+WAWA,IAAA,EAAA,cAGkC,CAAM,MACrC,EACA,EAAO,CACN,KAAM,EAAS,KACf,aAAc,EAAS,OACvB,UAAW,GACZ,CAAC,sDAGD,MAAiBC,EAAU,CAC3B,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,+DAGD,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,UAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,kBAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,iBAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,QAChB,CAAC,CAAA,EAAA,cAAA,QAAA,CAAA,CAAA,EAAA,UAAA,mBAAA,IAAA,GAAA,IAGD,MAAgBA,EAAU,CAAA,EAAA,cAAA,OAAA,EAAA,IAAA,QAAA,IAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,MA1C5B,EAAM,CACL,OAAQ,gBAAiB,UAAW,yBAA0B,UAAW,GAAO,UAAW,GAAO,UAAW,sBAC9G,CAAC,CAAA,CAAA,EAAA,CA4CF,IAAA,EAAe"}
@@ -1,2 +1,2 @@
1
- const e=require(`../../_virtual/rolldown_runtime.cjs`),t=require(`../../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.cjs`),n=require(`../../_virtual/_@oxc-project_runtime@0.103.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;
1
+ const e=require(`../../_virtual/rolldown_runtime.cjs`),t=require(`../../_virtual/_@oxc-project_runtime@0.97.0/helpers/decorateMetadata.cjs`),n=require(`../../_virtual/_@oxc-project_runtime@0.97.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":"0SAUA,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.103.0/helpers/decorateMetadata.js";import{__decorate as t}from"../../_virtual/_@oxc-project_runtime@0.103.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.97.0/helpers/decorateMetadata.js";import{__decorate as t}from"../../_virtual/_@oxc-project_runtime@0.97.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 +1 @@
1
- {"version":3,"file":"TestModel.js","names":["TestModel","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":"mWAUA,IAAA,EAAA,cAGwB,CAAM,MAC3B,EACA,EAAO,CACN,KAAM,EAAS,KACf,aAAc,EAAS,OACvB,UAAW,GACZ,CAAC,sDAGD,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,UAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,kBAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,iBAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,QAChB,CAAC,CAAA,EAAA,cAAA,QAAA,CAAA,CAAA,EAAA,UAAA,gBAAA,IAAA,GAAA,IAGD,MAAcC,EAAoB,CAAA,EAAA,cAAA,MAAA,CAAA,CAAA,EAAA,UAAA,mBAAA,IAAA,GAAA,IAGlC,EAAO,CACN,KAAM,EAAS,QAChB,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,eAAA,IAAA,GAAA,MAxCH,EAAM,CACL,OAAQ,gBAAiB,UAAW,cAAe,UAAW,GAAO,UAAW,GAAO,UAAW,YACnG,CAAC,CAAA,CAAA,EAAA,CA0CF,IAAA,EAAe"}
1
+ {"version":3,"file":"TestModel.js","names":["TestModel","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":"iWAUA,IAAA,EAAA,cAGwB,CAAM,MAC3B,EACA,EAAO,CACN,KAAM,EAAS,KACf,aAAc,EAAS,OACvB,UAAW,GACZ,CAAC,sDAGD,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,UAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,kBAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,iBAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,QAChB,CAAC,CAAA,EAAA,cAAA,QAAA,CAAA,CAAA,EAAA,UAAA,gBAAA,IAAA,GAAA,IAGD,MAAcC,EAAoB,CAAA,EAAA,cAAA,MAAA,CAAA,CAAA,EAAA,UAAA,mBAAA,IAAA,GAAA,IAGlC,EAAO,CACN,KAAM,EAAS,QAChB,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,eAAA,IAAA,GAAA,MAxCH,EAAM,CACL,OAAQ,gBAAiB,UAAW,cAAe,UAAW,GAAO,UAAW,GAAO,UAAW,YACnG,CAAC,CAAA,CAAA,EAAA,CA0CF,IAAA,EAAe"}
@@ -1,2 +1,2 @@
1
- const e=require(`../../../_virtual/rolldown_runtime.cjs`),t=require(`../../../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.cjs`),n=require(`../../../_virtual/_@oxc-project_runtime@0.103.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;
1
+ const e=require(`../../../_virtual/rolldown_runtime.cjs`),t=require(`../../../_virtual/_@oxc-project_runtime@0.97.0/helpers/decorateMetadata.cjs`),n=require(`../../../_virtual/_@oxc-project_runtime@0.97.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":"sTAWA,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.103.0/helpers/decorateMetadata.js";import{__decorate as t}from"../../../_virtual/_@oxc-project_runtime@0.103.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.97.0/helpers/decorateMetadata.js";import{__decorate as t}from"../../../_virtual/_@oxc-project_runtime@0.97.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 +1 @@
1
- {"version":3,"file":"ContextAwareTestModel.js","names":["ContextAwareTestModel","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":"8XAWA,IAAA,EAAA,cACoC,CAAM,MACvC,EACA,EAAO,CACN,KAAM,EAAS,KACf,aAAc,EAAS,OACvB,UAAW,GACZ,CAAC,sDAGD,MAAiBC,EAAiB,CAClC,EAAO,CAAE,KAAM,EAAS,KAAM,CAAC,6DAG/B,EAAO,CACN,KAAM,EAAS,QAChB,CAAC,CAAA,EAAA,cAAA,QAAA,CAAA,CAAA,EAAA,UAAA,gBAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,QAChB,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,eAAA,IAAA,GAAA,IAGD,MAAgBA,EAAiB,CAAA,EAAA,cAAA,OAAA,EAAA,IAAA,QAAA,IAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,UAAA,IAAA,GAAA,MAxBnC,EAAM,CAAE,UAAW,GAAO,UAAW,GAAO,UAAW,wBAAyB,CAAC,CAAA,CAAA,EAAA,CA4BlF,IAAA,EAAe"}
1
+ {"version":3,"file":"ContextAwareTestModel.js","names":["ContextAwareTestModel","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":"4XAWA,IAAA,EAAA,cACoC,CAAM,MACvC,EACA,EAAO,CACN,KAAM,EAAS,KACf,aAAc,EAAS,OACvB,UAAW,GACZ,CAAC,sDAGD,MAAiBC,EAAiB,CAClC,EAAO,CAAE,KAAM,EAAS,KAAM,CAAC,6DAG/B,EAAO,CACN,KAAM,EAAS,QAChB,CAAC,CAAA,EAAA,cAAA,QAAA,CAAA,CAAA,EAAA,UAAA,gBAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,QAChB,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,eAAA,IAAA,GAAA,IAGD,MAAgBA,EAAiB,CAAA,EAAA,cAAA,OAAA,EAAA,IAAA,QAAA,IAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,UAAA,IAAA,GAAA,MAxBnC,EAAM,CAAE,UAAW,GAAO,UAAW,GAAO,UAAW,wBAAyB,CAAC,CAAA,CAAA,EAAA,CA4BlF,IAAA,EAAe"}
@@ -1,2 +1,2 @@
1
- const e=require(`../../../_virtual/rolldown_runtime.cjs`),t=require(`../../../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.cjs`),n=require(`../../../_virtual/_@oxc-project_runtime@0.103.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;
1
+ const e=require(`../../../_virtual/rolldown_runtime.cjs`),t=require(`../../../_virtual/_@oxc-project_runtime@0.97.0/helpers/decorateMetadata.cjs`),n=require(`../../../_virtual/_@oxc-project_runtime@0.97.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":"4QAQA,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.103.0/helpers/decorateMetadata.js";import{__decorate as t}from"../../../_virtual/_@oxc-project_runtime@0.103.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.97.0/helpers/decorateMetadata.js";import{__decorate as t}from"../../../_virtual/_@oxc-project_runtime@0.97.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 +1 @@
1
- {"version":3,"file":"ContextTestModel.js","names":["ContextTestModel"],"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":"oTAQA,IAAK,EAAA,SAAA,EAAL,OACE,GAAA,eAAA,gBACA,EAAA,QAAA,UACA,EAAA,cAAA,eACA,EAAA,MAAA,WAJG,GAAA,EAAA,CAAA,CAOL,IAAA,EAAA,cAC+B,CAAM,MAClC,EACA,EAAO,CACN,aAAc,EAAS,OACvB,KAAM,EAAS,KAChB,CAAC,sDAGD,EAAO,CACN,KAAM,EAAS,KAChB,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,WAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,KAAK,GAAG,OAAO,OAAO,EAAa,CAAC,CACpD,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,aAAA,IAAA,GAAA,MAhBH,EAAM,CAAE,UAAW,GAAO,UAAW,GAAO,UAAW,mBAAoB,CAAC,CAAA,CAAA,EAAA,CAoB7E,IAAA,EAAe"}
1
+ {"version":3,"file":"ContextTestModel.js","names":["ContextTestModel"],"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":"kTAQA,IAAK,EAAA,SAAA,EAAL,OACE,GAAA,eAAA,gBACA,EAAA,QAAA,UACA,EAAA,cAAA,eACA,EAAA,MAAA,WAJG,GAAA,EAAA,CAAA,CAOL,IAAA,EAAA,cAC+B,CAAM,MAClC,EACA,EAAO,CACN,aAAc,EAAS,OACvB,KAAM,EAAS,KAChB,CAAC,sDAGD,EAAO,CACN,KAAM,EAAS,KAChB,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,WAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,KAAK,GAAG,OAAO,OAAO,EAAa,CAAC,CACpD,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,aAAA,IAAA,GAAA,MAhBH,EAAM,CAAE,UAAW,GAAO,UAAW,GAAO,UAAW,mBAAoB,CAAC,CAAA,CAAA,EAAA,CAoB7E,IAAA,EAAe"}
@@ -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`);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`),r=require(`../models/CustomFieldModelTypeMap.cjs`);require(`../models/index.cjs`);let i=require(`sequelize`);const a=async e=>{try{e.modelTypeIds=(await r.default.findAll({where:{customFieldDefinitionId:e.id},attributes:[`modelTypeId`],raw:!0})).map(e=>e.modelTypeId)}catch{e.modelTypeIds=[]}return e},o=async e=>{let{modelTypeIds:t,...i}=e;return a(await n.default.sequelize.transaction(async e=>{let a=await n.default.create(i,{transaction:e});return t?.length&&await Promise.all(t.map(t=>r.default.create({customFieldDefinitionId:a.id,modelTypeId:t},{transaction:e}))),a}))},s=async(e,t={withDisabled:!1})=>{let r=await(t.withDisabled?n.default.unscoped():n.default).scope(`userScope`).findAll({where:e,transaction:t.transaction,raw:!t.enrichWithModelTypeIds,include:t.include});return t.enrichWithModelTypeIds?Promise.all(r.map(e=>a(e))):r},c=(e,t={withDisabled:!1})=>s({id:{[i.Op.in]:e}},t),l=async(e,t={withDisabled:!1})=>{let{withDisabled:r}=t,i=r?await n.default.unscoped().scope(`userScope`).findByPk(e):await n.default.scope(`userScope`).findByPk(e);return i?a(i):null},u=async(e,t,r={})=>{let{include:a,useEntityIdFromInclude:o}=r.modelOptions,s={modelType:e,...!o&&{entityId:{[i.Op.in]:t}}};return n.default.findAll({where:s,transaction:r.transaction,include:a?.(t),raw:!0})},d=e=>n.default.scope(`userScope`).findOne({where:e}),f=async(e,t)=>{let{modelTypeIds:i,...o}=t;return a(await n.default.sequelize.transaction(async t=>{let a=(await n.default.scope(`userScope`).update(o,{where:{id:e},returning:!0,individualHooks:!0,transaction:t}))[1][0];return i&&(await r.default.destroy({where:{customFieldDefinitionId:e},transaction:t}),i.length>0&&await Promise.all(i.map(n=>r.default.create({customFieldDefinitionId:e,modelTypeId:n},{transaction:t})))),a}))},p=async(e,t={withDisabled:!1,modelType:``})=>{let{withDisabled:r,entityIds:o,modelType:s,modelOptions:c}=t,{include:l,useEntityIdFromInclude:u}=c??{},d={modelType:s,...!u&&o&&o.length>0&&{entityId:{[i.Op.in]:o}}},f=r?n.default.unscoped():n.default,p=[{association:`modelTypeMappings`,required:!1,attributes:[`id`,`modelTypeId`]}];if(u&&l&&o){let e=l(o);p.push(...e)}let m=(await f.scope(`userScope`).findAll({where:d,include:p,raw:!1})).filter(t=>{let n=t.modelTypeMappings||t.dataValues?.modelTypeMappings||[];return!Array.isArray(n)||n.length===0?!0:n.some(t=>(t.modelTypeId||t.dataValues?.modelTypeId)===e)});return Promise.all(m.map(e=>a(e)))},m=async(e,{findAll:n,modelOptions:r={},withDisabled:a=!1,...o}={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:{[i.Op.in]:Array.from(d)},name:{[i.Op.in]:Array.from(l)}},p=await(n??s)(f,{withDisabled:a,modelOptions:r,...o}),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=o,exports.findAll=s,exports.findByEntityIds=u,exports.findById=l,exports.findByIds=c,exports.findByModelTypeId=p,exports.findByWhere=d,exports.getCustomFieldDefinitionsDictionary=m,exports.update=f;
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":"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
+ {"version":3,"file":"definition.cjs","names":["CustomFieldModelTypeMap","CustomFieldDefinition","Op","where: WhereOptions","baseWhere: WhereOptions","includeArray: any[]","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, CustomFieldModelTypeMap, type CustomFieldEntries } from '../models';\nimport type { CreateCustomFieldDefinition, UpdateCustomFieldDefinition } from '../types/definition';\nimport type { ModelOptions } from '../types';\nimport { MissingDefinitionError } from '../errors';\n\n/**\n * Enriches a custom field definition with modelTypeIds array\n */\nconst enrichWithModelTypeIds = async (\n definition: CustomFieldDefinition,\n): Promise<CustomFieldDefinition> => {\n try {\n const mappings = await CustomFieldModelTypeMap.findAll({\n where: { customFieldDefinitionId: definition.id },\n attributes: ['modelTypeId'],\n raw: true,\n });\n\n definition.modelTypeIds = mappings.map((m: { modelTypeId: string; }) => m.modelTypeId);\n } catch {\n definition.modelTypeIds = [];\n }\n\n return definition;\n};\n\nexport const create = async (\n data: CreateCustomFieldDefinition,\n): Promise<CustomFieldDefinition> => {\n const { modelTypeIds, ...definitionData } = data;\n\n const result = await CustomFieldDefinition.sequelize!.transaction(async (transaction: Transaction) => {\n const customFieldDefinition = await CustomFieldDefinition.create(definitionData as any, {\n transaction,\n });\n\n if (modelTypeIds?.length) {\n await Promise.all(\n modelTypeIds.map(modelTypeId =>\n CustomFieldModelTypeMap.create({\n customFieldDefinitionId: customFieldDefinition.id,\n modelTypeId,\n }, {\n transaction,\n }),\n ),\n );\n }\n\n return customFieldDefinition;\n });\n\n return enrichWithModelTypeIds(result);\n};\n\ninterface SadotFindOptions {\n withDisabled?: boolean;\n transaction?: Transaction | null;\n include?: Includeable | Includeable[];\n enrichWithModelTypeIds?: boolean;\n}\n\ntype SadotGetDefinitionsByEntityIdsOptions = FindOptions & { modelOptions?: ModelOptions; findAll?: typeof findAll; } & Pick<SadotFindOptions, 'withDisabled'>;\n\nexport const findAll = async (\n where: WhereOptions,\n options: SadotFindOptions = { withDisabled: false },\n): Promise<CustomFieldDefinition[]> => {\n const queryModel = options.withDisabled\n ? CustomFieldDefinition.unscoped()\n : CustomFieldDefinition;\n\n const definitions = await queryModel.scope('userScope').findAll({\n where,\n transaction: options.transaction,\n raw: !options.enrichWithModelTypeIds,\n include: options.include,\n });\n\n if (options.enrichWithModelTypeIds) {\n return Promise.all(definitions.map(def => enrichWithModelTypeIds(def)));\n }\n\n return definitions;\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 = async (\n id: string,\n options: Pick<SadotFindOptions, 'withDisabled'> = { withDisabled: false },\n): Promise<CustomFieldDefinition | null> => {\n const { withDisabled } = options;\n const definition = withDisabled\n ? await CustomFieldDefinition.unscoped().scope('userScope').findByPk(id)\n : await CustomFieldDefinition.scope('userScope').findByPk(id);\n\n if (!definition) {\n return null;\n }\n\n return enrichWithModelTypeIds(definition);\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 { modelTypeIds, ...definitionData } = data;\n\n const result = await CustomFieldDefinition.sequelize!.transaction(async (transaction: Transaction) => {\n const updatedDefinition = (await CustomFieldDefinition.scope('userScope').update(definitionData, {\n where: { id },\n returning: true,\n individualHooks: true,\n transaction,\n }))[1][0];\n\n if (modelTypeIds) {\n await CustomFieldModelTypeMap.destroy({\n where: { customFieldDefinitionId: id },\n transaction,\n });\n\n if (modelTypeIds.length > 0) {\n await Promise.all(\n modelTypeIds.map(modelTypeId =>\n CustomFieldModelTypeMap.create({\n customFieldDefinitionId: id,\n modelTypeId,\n }, {\n transaction,\n }),\n ),\n );\n }\n }\n\n return updatedDefinition;\n });\n\n return enrichWithModelTypeIds(result);\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 */\n/**\n * Find custom field definitions applicable to a specific model type instance\n *\n * Returns definitions that either:\n * 1. Have NO mappings (apply to all instances of this model type)\n * 2. Have a mapping to this specific model type instance\n */\nexport const findByModelTypeId = async (\n modelTypeId: string,\n options: Pick<SadotFindOptions, 'withDisabled'> & { entityIds?: string[]; modelType: string; modelOptions?: ModelOptions; } = { withDisabled: false, modelType: '' },\n): Promise<CustomFieldDefinition[]> => {\n const { withDisabled, entityIds, modelType, modelOptions } = options;\n\n const { include, useEntityIdFromInclude } = modelOptions ?? {};\n\n const baseWhere: WhereOptions = {\n modelType,\n ...(!useEntityIdFromInclude && entityIds && entityIds.length > 0 && { entityId: { [Op.in]: entityIds } }),\n };\n\n const queryModel = withDisabled\n ? (CustomFieldDefinition as any).unscoped()\n : CustomFieldDefinition;\n\n const includeArray: any[] = [\n {\n association: 'modelTypeMappings',\n required: false,\n attributes: ['id', 'modelTypeId'],\n },\n ];\n\n if (useEntityIdFromInclude && include && entityIds) {\n const contextIncludes = include(entityIds);\n includeArray.push(...contextIncludes);\n }\n\n const definitions = await queryModel.scope('userScope').findAll({\n where: baseWhere,\n include: includeArray,\n raw: false,\n });\n\n const filteredDefinitions = definitions.filter((def: any) => {\n const mappings = def.modelTypeMappings || def.dataValues?.modelTypeMappings || [];\n\n if (!Array.isArray(mappings) || mappings.length === 0) {\n return true;\n }\n\n const hasMatch = mappings.some((mapping: any) => {\n const mappingTypeId = mapping.modelTypeId || mapping.dataValues?.modelTypeId;\n return mappingTypeId === modelTypeId;\n });\n\n return hasMatch;\n });\n\n return Promise.all(filteredDefinitions.map((def: CustomFieldDefinition) => enrichWithModelTypeIds(def)));\n};\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":"mPAYA,MAAM,EAAyB,KAC7B,IACmC,CACnC,GAAI,CAOF,EAAW,cANM,MAAMA,EAAAA,QAAwB,QAAQ,CACrD,MAAO,CAAE,wBAAyB,EAAW,GAAI,CACjD,WAAY,CAAC,cAAc,CAC3B,IAAK,GACN,CAAC,EAEiC,IAAK,GAAgC,EAAE,YAAY,MAChF,CACN,EAAW,aAAe,EAAE,CAG9B,OAAO,GAGI,EAAS,KACpB,IACmC,CACnC,GAAM,CAAE,eAAc,GAAG,GAAmB,EAuB5C,OAAO,EArBQ,MAAMC,EAAAA,QAAsB,UAAW,YAAY,KAAO,IAA6B,CACpG,IAAM,EAAwB,MAAMA,EAAAA,QAAsB,OAAO,EAAuB,CACtF,cACD,CAAC,CAeF,OAbI,GAAc,QAChB,MAAM,QAAQ,IACZ,EAAa,IAAI,GACfD,EAAAA,QAAwB,OAAO,CAC7B,wBAAyB,EAAsB,GAC/C,cACD,CAAE,CACD,cACD,CAAC,CACH,CACF,CAGI,GACP,CAEmC,EAY1B,EAAU,MACrB,EACA,EAA4B,CAAE,aAAc,GAAO,GACd,CAKrC,IAAM,EAAc,MAJD,EAAQ,aACvBC,EAAAA,QAAsB,UAAU,CAChCA,EAAAA,SAEiC,MAAM,YAAY,CAAC,QAAQ,CAC9D,QACA,YAAa,EAAQ,YACrB,IAAK,CAAC,EAAQ,uBACd,QAAS,EAAQ,QAClB,CAAC,CAMF,OAJI,EAAQ,uBACH,QAAQ,IAAI,EAAY,IAAI,GAAO,EAA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S,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,IAAMF,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,IAAII,EAAAA,uBADoB,MAAM,KAAK,EAAa,CAAC,OAAO,GAAe,CAAC,EAAyB,GAAa,CAC7D,CAGzD,OAAO"}
@@ -1,2 +1,2 @@
1
- import{MissingDefinitionError as e}from"../errors/index.js";import t from"../models/CustomFieldDefinition.js";import"../models/index.js";import{Op as n}from"sequelize";const r=e=>t.create(e),i=(e,n={withDisabled:!1})=>(n.withDisabled?t.unscoped():t).scope(`userScope`).findAll({where:e,transaction:n.transaction,raw:!0,include:n.include}),a=(e,t={withDisabled:!1})=>i({id:{[n.in]:e}},t),o=(e,n={withDisabled:!1})=>{let{withDisabled:r}=n;return r?t.unscoped().scope(`userScope`).findByPk(e):t.scope(`userScope`).findByPk(e)},s=async(e,r,i={})=>{let{include:a,useEntityIdFromInclude:o}=i.modelOptions,s={modelType:e,...!o&&{entityId:{[n.in]:r}}};return t.findAll({where:s,transaction:i.transaction,include:a?.(r),raw:!0})},c=e=>t.scope(`userScope`).findOne({where:e}),l=async(e,n)=>(await t.scope(`userScope`).update(n,{where:{id:e},returning:!0,individualHooks:!0}))[1][0],u=async(t,{findAll:r,modelOptions:a={},withDisabled:o=!1,...s}={withDisabled:!1,modelOptions:{}})=>{let{modelType:c}=t[0]?.dataValues??{},l=new Set,u=[],d=new Set;t.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:{[n.in]:Array.from(d)},name:{[n.in]:Array.from(l)}},p=await(r??i)(f,{withDisabled:o,modelOptions:a,...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 e(Array.from(l).filter(e=>!h[e]));return h};export{r as create,i as findAll,s as findByEntityIds,o as findById,a as findByIds,c as findByWhere,u as getCustomFieldDefinitionsDictionary,l as update};
1
+ import{MissingDefinitionError as e}from"../errors/index.js";import t from"../models/CustomFieldDefinition.js";import n from"../models/CustomFieldModelTypeMap.js";import"../models/index.js";import{Op as r}from"sequelize";const i=async e=>{try{e.modelTypeIds=(await n.findAll({where:{customFieldDefinitionId:e.id},attributes:[`modelTypeId`],raw:!0})).map(e=>e.modelTypeId)}catch{e.modelTypeIds=[]}return e},a=async e=>{let{modelTypeIds:r,...a}=e;return i(await t.sequelize.transaction(async e=>{let i=await t.create(a,{transaction:e});return r?.length&&await Promise.all(r.map(t=>n.create({customFieldDefinitionId:i.id,modelTypeId:t},{transaction:e}))),i}))},o=async(e,n={withDisabled:!1})=>{let r=await(n.withDisabled?t.unscoped():t).scope(`userScope`).findAll({where:e,transaction:n.transaction,raw:!n.enrichWithModelTypeIds,include:n.include});return n.enrichWithModelTypeIds?Promise.all(r.map(e=>i(e))):r},s=(e,t={withDisabled:!1})=>o({id:{[r.in]:e}},t),c=async(e,n={withDisabled:!1})=>{let{withDisabled:r}=n,a=r?await t.unscoped().scope(`userScope`).findByPk(e):await t.scope(`userScope`).findByPk(e);return a?i(a):null},l=async(e,n,i={})=>{let{include:a,useEntityIdFromInclude:o}=i.modelOptions,s={modelType:e,...!o&&{entityId:{[r.in]:n}}};return t.findAll({where:s,transaction:i.transaction,include:a?.(n),raw:!0})},u=e=>t.scope(`userScope`).findOne({where:e}),d=async(e,r)=>{let{modelTypeIds:a,...o}=r;return i(await t.sequelize.transaction(async r=>{let i=(await t.scope(`userScope`).update(o,{where:{id:e},returning:!0,individualHooks:!0,transaction:r}))[1][0];return a&&(await n.destroy({where:{customFieldDefinitionId:e},transaction:r}),a.length>0&&await Promise.all(a.map(t=>n.create({customFieldDefinitionId:e,modelTypeId:t},{transaction:r})))),i}))},f=async(e,n={withDisabled:!1,modelType:``})=>{let{withDisabled:a,entityIds:o,modelType:s,modelOptions:c}=n,{include:l,useEntityIdFromInclude:u}=c??{},d={modelType:s,...!u&&o&&o.length>0&&{entityId:{[r.in]:o}}},f=a?t.unscoped():t,p=[{association:`modelTypeMappings`,required:!1,attributes:[`id`,`modelTypeId`]}];if(u&&l&&o){let e=l(o);p.push(...e)}let m=(await f.scope(`userScope`).findAll({where:d,include:p,raw:!1})).filter(t=>{let n=t.modelTypeMappings||t.dataValues?.modelTypeMappings||[];return!Array.isArray(n)||n.length===0?!0:n.some(t=>(t.modelTypeId||t.dataValues?.modelTypeId)===e)});return Promise.all(m.map(e=>i(e)))},p=async(t,{findAll:n,modelOptions:i={},withDisabled:a=!1,...s}={withDisabled:!1,modelOptions:{}})=>{let{modelType:c}=t[0]?.dataValues??{},l=new Set,u=[],d=new Set;t.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.in]:Array.from(d)},name:{[r.in]:Array.from(l)}},p=await(n??o)(f,{withDisabled:a,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 e(Array.from(l).filter(e=>!h[e]));return h};export{a as create,o as findAll,l as findByEntityIds,c as findById,s as findByIds,f as findByModelTypeId,u as findByWhere,p as getCustomFieldDefinitionsDictionary,d as update};
2
2
  //# sourceMappingURL=definition.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"definition.js","names":["CustomFieldDefinition","where: WhereOptions"],"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":"wKASA,MAAa,EAAU,GACrBA,EAAsB,OAAO,EAAK,CAUvB,GACX,EACA,EAA4B,CAAE,aAAc,GAAO,IAEhC,EAAQ,aACvBA,EAAsB,UAAU,CAChCA,GAEc,MAAM,YAAY,CAAC,QAAQ,CAC3C,QACA,YAAa,EAAQ,YACrB,IAAK,GACL,QAAS,EAAQ,QAClB,CAAC,CAGS,GACX,EACA,E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,CAEF,IAAMC,EAAsB,CAC1B,YACA,SAAU,EAAG,EAAG,IAAK,MAAM,KAAK,EAAU,CAAE,CAC5C,KAAM,EAAG,EAAG,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,IAAI,EADoB,MAAM,KAAK,EAAa,CAAC,OAAO,GAAe,CAAC,EAAyB,GAAa,CAC7D,CAGzD,OAAO"}
1
+ {"version":3,"file":"definition.js","names":["CustomFieldModelTypeMap","CustomFieldDefinition","where: WhereOptions","baseWhere: WhereOptions","includeArray: any[]"],"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, CustomFieldModelTypeMap, type CustomFieldEntries } from '../models';\nimport type { CreateCustomFieldDefinition, UpdateCustomFieldDefinition } from '../types/definition';\nimport type { ModelOptions } from '../types';\nimport { MissingDefinitionError } from '../errors';\n\n/**\n * Enriches a custom field definition with modelTypeIds array\n */\nconst enrichWithModelTypeIds = async (\n definition: CustomFieldDefinition,\n): Promise<CustomFieldDefinition> => {\n try {\n const mappings = await CustomFieldModelTypeMap.findAll({\n where: { customFieldDefinitionId: definition.id },\n attributes: ['modelTypeId'],\n raw: true,\n });\n\n definition.modelTypeIds = mappings.map((m: { modelTypeId: string; }) => m.modelTypeId);\n } catch {\n definition.modelTypeIds = [];\n }\n\n return definition;\n};\n\nexport const create = async (\n data: CreateCustomFieldDefinition,\n): Promise<CustomFieldDefinition> => {\n const { modelTypeIds, ...definitionData } = data;\n\n const result = await CustomFieldDefinition.sequelize!.transaction(async (transaction: Transaction) => {\n const customFieldDefinition = await CustomFieldDefinition.create(definitionData as any, {\n transaction,\n });\n\n if (modelTypeIds?.length) {\n await Promise.all(\n modelTypeIds.map(modelTypeId =>\n CustomFieldModelTypeMap.create({\n customFieldDefinitionId: customFieldDefinition.id,\n modelTypeId,\n }, {\n transaction,\n }),\n ),\n );\n }\n\n return customFieldDefinition;\n });\n\n return enrichWithModelTypeIds(result);\n};\n\ninterface SadotFindOptions {\n withDisabled?: boolean;\n transaction?: Transaction | null;\n include?: Includeable | Includeable[];\n enrichWithModelTypeIds?: boolean;\n}\n\ntype SadotGetDefinitionsByEntityIdsOptions = FindOptions & { modelOptions?: ModelOptions; findAll?: typeof findAll; } & Pick<SadotFindOptions, 'withDisabled'>;\n\nexport const findAll = async (\n where: WhereOptions,\n options: SadotFindOptions = { withDisabled: false },\n): Promise<CustomFieldDefinition[]> => {\n const queryModel = options.withDisabled\n ? CustomFieldDefinition.unscoped()\n : CustomFieldDefinition;\n\n const definitions = await queryModel.scope('userScope').findAll({\n where,\n transaction: options.transaction,\n raw: !options.enrichWithModelTypeIds,\n include: options.include,\n });\n\n if (options.enrichWithModelTypeIds) {\n return Promise.all(definitions.map(def => enrichWithModelTypeIds(def)));\n }\n\n return definitions;\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 = async (\n id: string,\n options: Pick<SadotFindOptions, 'withDisabled'> = { withDisabled: false },\n): Promise<CustomFieldDefinition | null> => {\n const { withDisabled } = options;\n const definition = withDisabled\n ? await CustomFieldDefinition.unscoped().scope('userScope').findByPk(id)\n : await CustomFieldDefinition.scope('userScope').findByPk(id);\n\n if (!definition) {\n return null;\n }\n\n return enrichWithModelTypeIds(definition);\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 { modelTypeIds, ...definitionData } = data;\n\n const result = await CustomFieldDefinition.sequelize!.transaction(async (transaction: Transaction) => {\n const updatedDefinition = (await CustomFieldDefinition.scope('userScope').update(definitionData, {\n where: { id },\n returning: true,\n individualHooks: true,\n transaction,\n }))[1][0];\n\n if (modelTypeIds) {\n await CustomFieldModelTypeMap.destroy({\n where: { customFieldDefinitionId: id },\n transaction,\n });\n\n if (modelTypeIds.length > 0) {\n await Promise.all(\n modelTypeIds.map(modelTypeId =>\n CustomFieldModelTypeMap.create({\n customFieldDefinitionId: id,\n modelTypeId,\n }, {\n transaction,\n }),\n ),\n );\n }\n }\n\n return updatedDefinition;\n });\n\n return enrichWithModelTypeIds(result);\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 */\n/**\n * Find custom field definitions applicable to a specific model type instance\n *\n * Returns definitions that either:\n * 1. Have NO mappings (apply to all instances of this model type)\n * 2. Have a mapping to this specific model type instance\n */\nexport const findByModelTypeId = async (\n modelTypeId: string,\n options: Pick<SadotFindOptions, 'withDisabled'> & { entityIds?: string[]; modelType: string; modelOptions?: ModelOptions; } = { withDisabled: false, modelType: '' },\n): Promise<CustomFieldDefinition[]> => {\n const { withDisabled, entityIds, modelType, modelOptions } = options;\n\n const { include, useEntityIdFromInclude } = modelOptions ?? {};\n\n const baseWhere: WhereOptions = {\n modelType,\n ...(!useEntityIdFromInclude && entityIds && entityIds.length > 0 && { entityId: { [Op.in]: entityIds } }),\n };\n\n const queryModel = withDisabled\n ? (CustomFieldDefinition as any).unscoped()\n : CustomFieldDefinition;\n\n const includeArray: any[] = [\n {\n association: 'modelTypeMappings',\n required: false,\n attributes: ['id', 'modelTypeId'],\n },\n ];\n\n if (useEntityIdFromInclude && include && entityIds) {\n const contextIncludes = include(entityIds);\n includeArray.push(...contextIncludes);\n }\n\n const definitions = await queryModel.scope('userScope').findAll({\n where: baseWhere,\n include: includeArray,\n raw: false,\n });\n\n const filteredDefinitions = definitions.filter((def: any) => {\n const mappings = def.modelTypeMappings || def.dataValues?.modelTypeMappings || [];\n\n if (!Array.isArray(mappings) || mappings.length === 0) {\n return true;\n }\n\n const hasMatch = mappings.some((mapping: any) => {\n const mappingTypeId = mapping.modelTypeId || mapping.dataValues?.modelTypeId;\n return mappingTypeId === modelTypeId;\n });\n\n return hasMatch;\n });\n\n return Promise.all(filteredDefinitions.map((def: CustomFieldDefinition) => enrichWithModelTypeIds(def)));\n};\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":"4NAYA,MAAM,EAAyB,KAC7B,IACmC,CACnC,GAAI,CAOF,EAAW,cANM,MAAMA,EAAwB,QAAQ,CACrD,MAAO,CAAE,wBAAyB,EAAW,GAAI,CACjD,WAAY,CAAC,cAAc,CAC3B,IAAK,GACN,CAA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AErE,MAAM,IAAI,EADoB,MAAM,KAAK,EAAa,CAAC,OAAO,GAAe,CAAC,EAAyB,GAAa,CAC7D,CAGzD,OAAO"}
@@ -28,17 +28,20 @@ interface Models {
28
28
  name: string;
29
29
  scopeAttributes: any[];
30
30
  modelOptions?: ModelOptions;
31
+ hasTypeId?: boolean;
31
32
  creationWebhookHandler?: (instance: any) => any;
32
33
  updateWebhookHandler?: (instance: any) => any;
33
34
  deletionWebhookHandler?: (instance: any) => any;
34
35
  }
35
36
  interface CustomFieldOptions {
36
37
  models: Models[];
38
+ hasTypeId?: boolean;
37
39
  databaseConfig: any;
38
40
  getUser: typeof getUser;
39
41
  sequelize?: Sequelize;
40
42
  useCustomFieldsEntries?: boolean;
41
43
  useValidators?: boolean;
44
+ useModelTypeMapping?: boolean;
42
45
  }
43
46
  //#endregion
44
47
  export { CustomFieldOptions, ModelFetcher, Models };
@@ -1,5 +1,5 @@
1
- import "../models/CustomFieldDefinition.js";
2
1
  import "../models/CustomValidator.js";
2
+ import "../models/CustomFieldDefinition.js";
3
3
  import { IncludeOptions } from "sequelize";
4
4
  import { getUser } from "@autofleet/zehut";
5
5
  import { ModelCtor, Sequelize } from "sequelize-typescript";
@@ -29,17 +29,20 @@ interface Models {
29
29
  name: string;
30
30
  scopeAttributes: any[];
31
31
  modelOptions?: ModelOptions;
32
+ hasTypeId?: boolean;
32
33
  creationWebhookHandler?: (instance: any) => any;
33
34
  updateWebhookHandler?: (instance: any) => any;
34
35
  deletionWebhookHandler?: (instance: any) => any;
35
36
  }
36
37
  interface CustomFieldOptions {
37
38
  models: Models[];
39
+ hasTypeId?: boolean;
38
40
  databaseConfig: any;
39
41
  getUser: typeof getUser;
40
42
  sequelize?: Sequelize;
41
43
  useCustomFieldsEntries?: boolean;
42
44
  useValidators?: boolean;
45
+ useModelTypeMapping?: boolean;
43
46
  }
44
47
  //#endregion
45
48
  export { CustomFieldOptions, ModelFetcher, Models };
@@ -1,2 +1,2 @@
1
- const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`./logger/index.cjs`),n=require(`../models/CustomFieldValue.cjs`),r=require(`../models/CustomFieldDefinition.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,r)=>{r?.useCustomFieldsEntries||(e.hasMany(n.default,{foreignKey:`modelId`,as:`customFieldValue`}),n.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?.(r.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,hasTypeId:u})=>{try{let d=n(e);if(!d){t.default.warn(`sadot - tried to addHooks to a model that does not exist yet`,{name:e,scopeAttributes:i});return}d.rawAttributes.customFields={type:l.DataTypes.VIRTUAL},d.refreshAttributes();let f={...r,hasTypeId:u??!1};d.addHook(`beforeFind`,`sadot-beforeFind`,o.beforeFind(i)),d.addHook(`beforeBulkCreate`,`sadot-beforeBulkCreate`,s.beforeBulkCreate),d.addHook(`beforeBulkUpdate`,`sadot-beforeBulkUpdate`,s.beforeBulkUpdate),d.addHook(`beforeCreate`,`sadot-beforeCreate`,s.beforeCreate(i,c,r)),d.addHook(`beforeUpdate`,`sadot-beforeUpdate`,s.beforeUpdate(i,c,r)),d.addHook(`afterFind`,`sadot-afterFind`,a.default(e,i,`afterFind`,c,f)),d.addHook(`afterUpdate`,`sadot-afterUpdate`,a.default(e,i,void 0,c,f)),d.addHook(`afterCreate`,`sadot-afterCreate`,a.default(e,i,void 0,c,f))}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":"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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AAwB,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, hasTypeId,\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\n const enrichOptions = { ...sadotOptions, hasTypeId: hasTypeId ?? false };\n\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, enrichOptions));\n model.addHook('afterUpdate', 'sadot-afterUpdate', enrichResults(name, scopeAttributes, undefined, modelOptions, enrichOptions));\n model.addHook('afterCreate', 'sadot-afterCreate', enrichResults(name, scopeAttributes, undefined, modelOptions, enrichOptions));\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,eAAc,eACjC,CACJ,GAAI,CACF,IAAM,EAAQ,EAAS,EA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AW,eAAgB,qBAAqB,CACtD,EAAM,WAAW,YAAa,kBAAkB,CAChD,EAAM,WAAW,cAAe,oBAAoB,OAC7C,EAAG,CACV,EAAA,QAAO,MAAM,6CAA6C,EAAK,IAAK,EAAE,GAExE,EAME,GAAmB,EAAkB,EAAmB,IAAsE,CAC9H,GAAS,yBACb,EAAM,QAAQC,EAAAA,QAAkB,CAAE,WAAY,UAAW,GAAI,mBAAoB,CAAC,CAElF,EAAA,QAAiB,UAAU,EAAO,CAAE,WAAY,UAAW,GAAI,EAAW,CAAC,GAGhE,GAAa,EAAkB,EAAwB,EAA8D,CAAE,uBAAwB,GAAO,GAAW,CAC5K,EAAO,QAAQ,MAAO,CAAE,OAAM,qBAAsB,CAClD,GAAI,CACF,IAAM,EAAQ,EAAS,EAAK,CAC5B,GAAI,CAAC,EAAO,CACV,EAAA,QAAO,KAAK,gEAAiE,CAC3E,OACA,kBACD,CAAC,CACF,OAGF,EAAgB,EAAO,EAAM,EAAQ,CAErC,EAAM,SAAS,EAA4BC,EAAAA,wBAAwB,EAAM,EAAQ,CAAC,CAClF,EAAM,SAASC,EAAAA,yBAA0BC,EAAAA,sBAAsB,EAAM,EAAQ,CAAC,OACvE,EAAG,CACV,EAAA,QAAO,MAAM,+CAA+C,EAAK,IAAK,EAAE,GAE1E,EAGS,EAA0B,GAA2B,CAChE,EAAO,SAAS,CAAE,kBAAmB,CACnC,GAAc,oBAAoBC,EAAAA,QAAsB,CACxD,GAAc,oBAAoBC,EAAAA,QAAgB,EAClD"}
@@ -1,2 +1,2 @@
1
- import e from"./logger/index.js";import t from"../models/CustomFieldValue.js";import n from"../models/CustomFieldDefinition.js";import r from"../models/CustomValidator.js";import"../models/index.js";import i from"../hooks/enrich.js";import{beforeFind as a}from"../hooks/find.js";import{beforeBulkCreate as o,beforeBulkUpdate as s,beforeCreate as c,beforeUpdate as l}from"../hooks/hooks.js";import"../hooks/index.js";import{customFieldsFilterScope as u,customFieldsSortScope as d}from"../scopes/filter.js";import"../scopes/index.js";import{DataTypes as f}from"sequelize";import{customFields as p}from"@autofleet/common-types";import{CUSTOM_FIELDS_SORT_SCOPE as m}from"@autofleet/common-types/lib/custom-fields";const{CUSTOM_FIELDS_FILTER_SCOPE:h}=p,g=(t,n,r={useCustomFieldsEntries:!1})=>{t.forEach(async({name:t,scopeAttributes:u,modelOptions:d})=>{try{let p=n(t);if(!p){e.warn(`sadot - tried to addHooks to a model that does not exist yet`,{name:t,scopeAttributes:u});return}p.rawAttributes.customFields={type:f.VIRTUAL},p.refreshAttributes(),p.addHook(`beforeFind`,`sadot-beforeFind`,a(u)),p.addHook(`beforeBulkCreate`,`sadot-beforeBulkCreate`,o),p.addHook(`beforeBulkUpdate`,`sadot-beforeBulkUpdate`,s),p.addHook(`beforeCreate`,`sadot-beforeCreate`,c(u,d,r)),p.addHook(`beforeUpdate`,`sadot-beforeUpdate`,l(u,d,r)),p.addHook(`afterFind`,`sadot-afterFind`,i(t,u,`afterFind`,d,r)),p.addHook(`afterUpdate`,`sadot-afterUpdate`,i(t,u,void 0,d,r)),p.addHook(`afterCreate`,`sadot-afterCreate`,i(t,u,void 0,d,r))}catch(n){e.error(`Could not add custom fields hook to model ${t}. `,n)}})},_=(t,n)=>{t.forEach(async({name:t})=>{try{let e=n(t);if(!e)return;e.rawAttributes.customFields&&(delete e.rawAttributes.customFields,e.refreshAttributes()),e.removeHook(`beforeFind`,`sadot-beforeFind`),e.removeHook(`beforeBulkCreate`,`sadot-beforeBulkCreate`),e.removeHook(`beforeBulkUpdate`,`sadot-beforeBulkUpdate`),e.removeHook(`beforeCreate`,`sadot-beforeCreate`),e.removeHook(`beforeUpdate`,`sadot-beforeUpdate`),e.removeHook(`afterFind`,`sadot-afterFind`),e.removeHook(`afterUpdate`,`sadot-afterUpdate`)}catch(n){e.error(`Could not add custom fields hook to model ${t}. `,n)}})},v=(e,n,r)=>{r?.useCustomFieldsEntries||(e.hasMany(t,{foreignKey:`modelId`,as:`customFieldValue`}),t.belongsTo(e,{foreignKey:`modelId`,as:n}))},y=(t,n,r={useCustomFieldsEntries:!1})=>{t.forEach(async({name:t,scopeAttributes:i})=>{try{let a=n(t);if(!a){e.warn(`sadot - tried to addScopes to a model that does not exist yet`,{name:t,scopeAttributes:i});return}v(a,t,r),a.addScope(h,u(t,r)),a.addScope(m,d(t,r))}catch(n){e.error(`Could not add custom fields scopes to model ${t}. `,n)}})},b=e=>{e.forEach(({modelOptions:e})=>{e?.customAssociation?.(n),e?.customAssociation?.(r)})};export{g as addHooks,y as addScopes,b as applyCustomAssociation,_ as removeHooks};
1
+ import e from"./logger/index.js";import t from"../models/CustomFieldDefinition.js";import n from"../models/CustomFieldValue.js";import r from"../models/CustomValidator.js";import"../models/index.js";import i from"../hooks/enrich.js";import{beforeFind as a}from"../hooks/find.js";import{beforeBulkCreate as o,beforeBulkUpdate as s,beforeCreate as c,beforeUpdate as l}from"../hooks/hooks.js";import"../hooks/index.js";import{customFieldsFilterScope as u,customFieldsSortScope as d}from"../scopes/filter.js";import"../scopes/index.js";import{DataTypes as f}from"sequelize";import{customFields as p}from"@autofleet/common-types";import{CUSTOM_FIELDS_SORT_SCOPE as m}from"@autofleet/common-types/lib/custom-fields";const{CUSTOM_FIELDS_FILTER_SCOPE:h}=p,g=(t,n,r={useCustomFieldsEntries:!1})=>{t.forEach(async({name:t,scopeAttributes:u,modelOptions:d,hasTypeId:p})=>{try{let m=n(t);if(!m){e.warn(`sadot - tried to addHooks to a model that does not exist yet`,{name:t,scopeAttributes:u});return}m.rawAttributes.customFields={type:f.VIRTUAL},m.refreshAttributes();let h={...r,hasTypeId:p??!1};m.addHook(`beforeFind`,`sadot-beforeFind`,a(u)),m.addHook(`beforeBulkCreate`,`sadot-beforeBulkCreate`,o),m.addHook(`beforeBulkUpdate`,`sadot-beforeBulkUpdate`,s),m.addHook(`beforeCreate`,`sadot-beforeCreate`,c(u,d,r)),m.addHook(`beforeUpdate`,`sadot-beforeUpdate`,l(u,d,r)),m.addHook(`afterFind`,`sadot-afterFind`,i(t,u,`afterFind`,d,h)),m.addHook(`afterUpdate`,`sadot-afterUpdate`,i(t,u,void 0,d,h)),m.addHook(`afterCreate`,`sadot-afterCreate`,i(t,u,void 0,d,h))}catch(n){e.error(`Could not add custom fields hook to model ${t}. `,n)}})},_=(t,n)=>{t.forEach(async({name:t})=>{try{let e=n(t);if(!e)return;e.rawAttributes.customFields&&(delete e.rawAttributes.customFields,e.refreshAttributes()),e.removeHook(`beforeFind`,`sadot-beforeFind`),e.removeHook(`beforeBulkCreate`,`sadot-beforeBulkCreate`),e.removeHook(`beforeBulkUpdate`,`sadot-beforeBulkUpdate`),e.removeHook(`beforeCreate`,`sadot-beforeCreate`),e.removeHook(`beforeUpdate`,`sadot-beforeUpdate`),e.removeHook(`afterFind`,`sadot-afterFind`),e.removeHook(`afterUpdate`,`sadot-afterUpdate`)}catch(n){e.error(`Could not add custom fields hook to model ${t}. `,n)}})},v=(e,t,r)=>{r?.useCustomFieldsEntries||(e.hasMany(n,{foreignKey:`modelId`,as:`customFieldValue`}),n.belongsTo(e,{foreignKey:`modelId`,as:t}))},y=(t,n,r={useCustomFieldsEntries:!1})=>{t.forEach(async({name:t,scopeAttributes:i})=>{try{let a=n(t);if(!a){e.warn(`sadot - tried to addScopes to a model that does not exist yet`,{name:t,scopeAttributes:i});return}v(a,t,r),a.addScope(h,u(t,r)),a.addScope(m,d(t,r))}catch(n){e.error(`Could not add custom fields scopes to model ${t}. `,n)}})},b=e=>{e.forEach(({modelOptions:e})=>{e?.customAssociation?.(t),e?.customAssociation?.(r)})};export{g as addHooks,y as addScopes,b as applyCustomAssociation,_ as removeHooks};
2
2
  //# sourceMappingURL=init.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"init.js","names":["enrichResults","CustomFieldValue","CustomFieldDefinition","CustomValidator"],"sources":["../../src/utils/init.ts"],"sourcesContent":["import { DataTypes } from 'sequelize';\nimport type { ModelCtor } from 'sequelize-typescript';\nimport { customFields } from '@autofleet/common-types';\nimport { CUSTOM_FIELDS_SORT_SCOPE } from '@autofleet/common-types/lib/custom-fields';\nimport {\n CustomFieldDefinition,\n CustomFieldValue,\n CustomValidator,\n} from '../models';\nimport {\n beforeFind,\n enrichResults,\n beforeBulkUpdate,\n beforeUpdate,\n beforeCreate,\n beforeBulkCreate,\n} from '../hooks';\nimport { customFieldsFilterScope } from '../scopes';\nimport logger from './logger';\nimport type { CustomFieldOptions, ModelFetcher, Models } from '../types';\nimport { customFieldsSortScope } from '../scopes/filter';\n\nconst { CUSTOM_FIELDS_FILTER_SCOPE } = customFields;\n\nexport const addHooks = (\n models: Models[],\n getModel: ModelFetcher,\n sadotOptions: { useCustomFieldsEntries?: boolean; } = { useCustomFieldsEntries: false },\n): void => {\n models.forEach(async ({\n name, scopeAttributes, modelOptions,\n }) => {\n try {\n const model = getModel(name);\n if (!model) {\n logger.warn('sadot - tried to addHooks to a model that does not exist yet', {\n name,\n scopeAttributes,\n });\n return;\n }\n model.rawAttributes.customFields = {\n type: DataTypes.VIRTUAL,\n };\n model.refreshAttributes();\n // TODO: Uncomment after tests are passed\n // model.addHook('afterFind', workaround);\n model.addHook('beforeFind', 'sadot-beforeFind', beforeFind(scopeAttributes));\n model.addHook('beforeBulkCreate', 'sadot-beforeBulkCreate', beforeBulkCreate);\n model.addHook('beforeBulkUpdate', 'sadot-beforeBulkUpdate', beforeBulkUpdate);\n model.addHook('beforeCreate', 'sadot-beforeCreate', beforeCreate(scopeAttributes, modelOptions, sadotOptions));\n model.addHook('beforeUpdate', 'sadot-beforeUpdate', beforeUpdate(scopeAttributes, modelOptions, sadotOptions));\n model.addHook('afterFind', 'sadot-afterFind', enrichResults(name, scopeAttributes, 'afterFind', modelOptions, sadotOptions));\n model.addHook('afterUpdate', 'sadot-afterUpdate', enrichResults(name, scopeAttributes, undefined, modelOptions, sadotOptions));\n model.addHook('afterCreate', 'sadot-afterCreate', enrichResults(name, scopeAttributes, undefined, modelOptions, sadotOptions));\n } catch (e) {\n logger.error(`Could not add custom fields hook to model ${name}. `, e);\n }\n });\n};\n\nexport const removeHooks = (models: Models[], getModel: ModelFetcher): void => {\n models.forEach(async ({ name }) => {\n try {\n const model = getModel(name);\n if (!model) return;\n if (model.rawAttributes.customFields) {\n delete model.rawAttributes.customFields;\n model.refreshAttributes();\n }\n // model.removeHook('afterFind', 'sadot-workaround');\n model.removeHook('beforeFind', 'sadot-beforeFind');\n model.removeHook('beforeBulkCreate', 'sadot-beforeBulkCreate');\n model.removeHook('beforeBulkUpdate', 'sadot-beforeBulkUpdate');\n model.removeHook('beforeCreate', 'sadot-beforeCreate');\n model.removeHook('beforeUpdate', 'sadot-beforeUpdate');\n model.removeHook('afterFind', 'sadot-afterFind');\n model.removeHook('afterUpdate', 'sadot-afterUpdate');\n } catch (e) {\n logger.error(`Could not add custom fields hook to model ${name}. `, e);\n }\n });\n};\n\n/**\n * Necessary associations for the {@link customFieldsFilterScope} scope\n */\nconst addAssociations = (model: ModelCtor, modelName: string, options: Pick<CustomFieldOptions, 'useCustomFieldsEntries'>): void => {\n if (options?.useCustomFieldsEntries) return;\n model.hasMany(CustomFieldValue, { foreignKey: 'modelId', as: 'customFieldValue' });\n // TBC: maybe can be removed\n CustomFieldValue.belongsTo(model, { foreignKey: 'modelId', as: modelName });\n};\n\nexport const addScopes = (models: Models[], getModel: ModelFetcher, options: Pick<CustomFieldOptions, 'useCustomFieldsEntries'> = { useCustomFieldsEntries: false }): void => {\n models.forEach(async ({ name, scopeAttributes }) => {\n try {\n const model = getModel(name);\n if (!model) {\n logger.warn('sadot - tried to addScopes to a model that does not exist yet', {\n name,\n scopeAttributes,\n });\n return;\n }\n // Necessary associations for the filtering scope\n addAssociations(model, name, options);\n // Add filter scope\n model.addScope(CUSTOM_FIELDS_FILTER_SCOPE, customFieldsFilterScope(name, options));\n model.addScope(CUSTOM_FIELDS_SORT_SCOPE, customFieldsSortScope(name, options));\n } catch (e) {\n logger.error(`Could not add custom fields scopes to model ${name}. `, e);\n }\n });\n};\n\nexport const applyCustomAssociation = (models: Models[]): void => {\n models.forEach(({ modelOptions }) => {\n modelOptions?.customAssociation?.(CustomFieldDefinition);\n modelOptions?.customAssociation?.(CustomValidator);\n });\n};\n"],"mappings":"ssBAsBA,KAAM,CAAE,8BAA+B,EAE1B,GACX,EACA,EACA,EAAsD,CAAE,uBAAwB,GAAO,GAC9E,CACT,EAAO,QAAQ,MAAO,CACpB,OAAM,kBAAiB,kBACnB,CACJ,GAAI,CACF,IAAM,EAAQ,EAAS,EAAK,CAC5B,GAAI,CAAC,EAAO,CACV,EAAO,KAAK,+DAAgE,CAC1E,OACA,kBACD,CAAC,CACF,OAEF,EAAM,cAAc,aAAe,CACjC,KAAM,EAAU,QACjB,CACD,EAAM,mBAAmB,CAGzB,EAAM,QAAQ,aAAc,mBAAoB,EAAW,EAAgB,CAAC,CAC5E,EAAM,QAAQ,mBAAoB,yBAA0B,EAAiB,CAC7E,EAAM,QAAQ,mBAAoB,yBAA0B,EAAiB,CAC7E,EAAM,QAAQ,eAAgB,qBAAsB,EAAa,EAAiB,EAAc,EAAa,CAAC,CAC9G,EAAM,QAAQ,eAAgB,qBAAsB,EAAa,EAAiB,EAAc,EAAa,CAAC,CAC9G,EAAM,QAAQ,YAAa,kBAAmBA,EAAc,EAAM,EAAiB,YAAa,EAAc,EAAa,CAAC,CAC5H,EAAM,QAAQ,cAAe,oBAAqBA,EAAc,EAAM,EAAiB,IAAA,GAAW,EAAc,EAAa,CAAC,CAC9H,EAAM,QAAQ,cAAe,oBAAqBA,EAAc,EAAM,EAAiB,IAAA,GAAW,EAAc,EAAa,CAAC,OACvH,EAAG,CACV,EAAO,MAAM,6CAA6C,EAAK,IAAK,EAAE,GAExE,EAGS,GAAe,EAAkB,IAAiC,CAC7E,EAAO,QAAQ,MAAO,CAAE,UAAW,CACjC,GAAI,CACF,IAAM,EAAQ,EAAS,EAAK,CAC5B,GAAI,CAAC,EAAO,OACR,EAAM,cAAc,eACtB,OAAO,EAAM,cAAc,aAC3B,EAAM,mBAAmB,EAG3B,EAAM,WAAW,aAAc,mBAAmB,CAClD,EAAM,WAAW,mBAAoB,yBAAyB,CAC9D,EAAM,WAAW,mBAAoB,yBAAyB,CAC9D,EAAM,WAAW,eAAgB,qBAAqB,CACtD,EAAM,WAAW,eAAgB,qBAAqB,CACtD,EAAM,WAAW,YAAa,kBAAkB,CAChD,EAAM,WAAW,cAAe,oBAAoB,OAC7C,EAAG,CACV,EAAO,MAAM,6CAA6C,EAAK,IAAK,EAAE,GAExE,EAME,GAAmB,EAAkB,EAAmB,IAAsE,CAC9H,GAAS,yBACb,EAAM,QAAQC,EAAkB,CAAE,WAAY,UAAW,GAAI,mBAAoB,CAAC,CAElF,EAAiB,UAAU,EAAO,CAAE,WAAY,UAAW,GAAI,EAAW,CAAC,GAGhE,GAAa,EAAkB,EAAwB,EAA8D,CAAE,uBAAwB,GAAO,GAAW,CAC5K,EAAO,QAAQ,MAAO,CAAE,OAAM,qBAAsB,CAClD,GAAI,CACF,IAAM,EAAQ,EAAS,EAAK,CAC5B,GAAI,CAAC,EAAO,CACV,EAAO,KAAK,gEAAiE,CAC3E,OACA,kBACD,CAAC,CACF,OAGF,EAAgB,EAAO,EAAM,EAAQ,CAErC,EAAM,SAAS,EAA4B,EAAwB,EAAM,EAAQ,CAAC,CAClF,EAAM,SAAS,EAA0B,EAAsB,EAAM,EAAQ,CAAC,OACvE,EAAG,CACV,EAAO,MAAM,+CAA+C,EAAK,IAAK,EAAE,GAE1E,EAGS,EAA0B,GAA2B,CAChE,EAAO,SAAS,CAAE,kBAAmB,CACnC,GAAc,oBAAoBC,EAAsB,CACxD,GAAc,oBAAoBC,EAAgB,EAClD"}
1
+ {"version":3,"file":"init.js","names":["enrichResults","CustomFieldValue","CustomFieldDefinition","CustomValidator"],"sources":["../../src/utils/init.ts"],"sourcesContent":["import { DataTypes } from 'sequelize';\nimport type { ModelCtor } from 'sequelize-typescript';\nimport { customFields } from '@autofleet/common-types';\nimport { CUSTOM_FIELDS_SORT_SCOPE } from '@autofleet/common-types/lib/custom-fields';\nimport {\n CustomFieldDefinition,\n CustomFieldValue,\n CustomValidator,\n} from '../models';\nimport {\n beforeFind,\n enrichResults,\n beforeBulkUpdate,\n beforeUpdate,\n beforeCreate,\n beforeBulkCreate,\n} from '../hooks';\nimport { customFieldsFilterScope } from '../scopes';\nimport logger from './logger';\nimport type { CustomFieldOptions, ModelFetcher, Models } from '../types';\nimport { customFieldsSortScope } from '../scopes/filter';\n\nconst { CUSTOM_FIELDS_FILTER_SCOPE } = customFields;\n\nexport const addHooks = (\n models: Models[],\n getModel: ModelFetcher,\n sadotOptions: { useCustomFieldsEntries?: boolean; } = { useCustomFieldsEntries: false },\n): void => {\n models.forEach(async ({\n name, scopeAttributes, modelOptions, hasTypeId,\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\n const enrichOptions = { ...sadotOptions, hasTypeId: hasTypeId ?? false };\n\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, enrichOptions));\n model.addHook('afterUpdate', 'sadot-afterUpdate', enrichResults(name, scopeAttributes, undefined, modelOptions, enrichOptions));\n model.addHook('afterCreate', 'sadot-afterCreate', enrichResults(name, scopeAttributes, undefined, modelOptions, enrichOptions));\n } catch (e) {\n logger.error(`Could not add custom fields hook to model ${name}. `, e);\n }\n });\n};\n\nexport const removeHooks = (models: Models[], getModel: ModelFetcher): void => {\n models.forEach(async ({ name }) => {\n try {\n const model = getModel(name);\n if (!model) return;\n if (model.rawAttributes.customFields) {\n delete model.rawAttributes.customFields;\n model.refreshAttributes();\n }\n // model.removeHook('afterFind', 'sadot-workaround');\n model.removeHook('beforeFind', 'sadot-beforeFind');\n model.removeHook('beforeBulkCreate', 'sadot-beforeBulkCreate');\n model.removeHook('beforeBulkUpdate', 'sadot-beforeBulkUpdate');\n model.removeHook('beforeCreate', 'sadot-beforeCreate');\n model.removeHook('beforeUpdate', 'sadot-beforeUpdate');\n model.removeHook('afterFind', 'sadot-afterFind');\n model.removeHook('afterUpdate', 'sadot-afterUpdate');\n } catch (e) {\n logger.error(`Could not add custom fields hook to model ${name}. `, e);\n }\n });\n};\n\n/**\n * Necessary associations for the {@link customFieldsFilterScope} scope\n */\nconst addAssociations = (model: ModelCtor, modelName: string, options: Pick<CustomFieldOptions, 'useCustomFieldsEntries'>): void => {\n if (options?.useCustomFieldsEntries) return;\n model.hasMany(CustomFieldValue, { foreignKey: 'modelId', as: 'customFieldValue' });\n // TBC: maybe can be removed\n CustomFieldValue.belongsTo(model, { foreignKey: 'modelId', as: modelName });\n};\n\nexport const addScopes = (models: Models[], getModel: ModelFetcher, options: Pick<CustomFieldOptions, 'useCustomFieldsEntries'> = { useCustomFieldsEntries: false }): void => {\n models.forEach(async ({ name, scopeAttributes }) => {\n try {\n const model = getModel(name);\n if (!model) {\n logger.warn('sadot - tried to addScopes to a model that does not exist yet', {\n name,\n scopeAttributes,\n });\n return;\n }\n // Necessary associations for the filtering scope\n addAssociations(model, name, options);\n // Add filter scope\n model.addScope(CUSTOM_FIELDS_FILTER_SCOPE, customFieldsFilterScope(name, options));\n model.addScope(CUSTOM_FIELDS_SORT_SCOPE, customFieldsSortScope(name, options));\n } catch (e) {\n logger.error(`Could not add custom fields scopes to model ${name}. `, e);\n }\n });\n};\n\nexport const applyCustomAssociation = (models: Models[]): void => {\n models.forEach(({ modelOptions }) => {\n modelOptions?.customAssociation?.(CustomFieldDefinition);\n modelOptions?.customAssociation?.(CustomValidator);\n });\n};\n"],"mappings":"ssBAsBA,KAAM,CAAE,8BAA+B,EAE1B,GACX,EACA,EACA,EAAsD,CAAE,uBAAwB,GAAO,GAC9E,CACT,EAAO,QAAQ,MAAO,CACpB,OAAM,kBAAiB,eAAc,eACjC,CACJ,GAAI,CACF,IAAM,EAAQ,EAAS,EAAK,CAC5B,GAAI,CAAC,EAAO,CACV,EAAO,KAAK,+DAAgE,CAC1E,OACA,kBACD,CAAC,CACF,OAEF,EAAM,cAAc,aAAe,CACjC,KAAM,EAAU,QACjB,CACD,EAAM,mBAAmB,CAEzB,IAAM,EAAgB,CAAE,GAAG,EAAc,UAAW,GAAa,GAAO,CAIxE,EAAM,QAAQ,aAAc,mBAAoB,EAAW,EAAgB,CAAC,CAC5E,EAAM,QAAQ,mBAAoB,yBAA0B,EAAiB,CAC7E,EAAM,QAAQ,mBAAoB,yBAA0B,EAAiB,CAC7E,EAAM,QAAQ,eAAgB,qBAAsB,EAAa,EAAiB,EAAc,EAAa,CAAC,CAC9G,EAAM,QAAQ,eAAgB,qBAAsB,EAAa,EAAiB,EAAc,EAAa,CAAC,CAC9G,EAAM,QAAQ,YAAa,kBAAmBA,EAAc,EAAM,EAAiB,YAAa,EAAc,EAAc,CAAC,CAC7H,EAAM,QAAQ,cAAe,oBAAqBA,EAAc,EAAM,EAAiB,IAAA,GAAW,EAAc,EAAc,CAAC,CAC/H,EAAM,QAAQ,cAAe,oBAAqBA,EAAc,EAAM,EAAiB,IAAA,GAAW,EAAc,EAAc,CAAC,OACxH,EAAG,CACV,EAAO,MAAM,6CAA6C,EAAK,IAAK,EAAE,GAExE,EAGS,GAAe,EAAkB,IAAiC,CAC7E,EAAO,QAAQ,MAAO,CAAE,UAAW,CACjC,GAAI,CACF,IAAM,EAAQ,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": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -22,6 +22,15 @@
22
22
  "dist",
23
23
  "README.md"
24
24
  ],
25
+ "scripts": {
26
+ "build": "pnpm -w tsdown -W ./packages/sadot",
27
+ "linter": "eslint .",
28
+ "test": "vitest",
29
+ "test-debug": "node --inspect-brk node_modules/.bin/vitest --testTimeout=10000000",
30
+ "coverage": "vitest --coverage",
31
+ "build-to-local-repo": "node --run build && cp -r dist/* ../$REPO/node_modules/$npm_package_name/dist",
32
+ "watch": "npm-watch build-to-local-repo"
33
+ },
25
34
  "watch": {
26
35
  "build-to-local-repo": {
27
36
  "extensions": [
@@ -35,27 +44,27 @@
35
44
  }
36
45
  },
37
46
  "dependencies": {
38
- "@autofleet/common-types": "4.101.0",
47
+ "@autofleet/common-types": "catalog:",
48
+ "@autofleet/events": "workspace:^",
39
49
  "ajv": "^8.12.0",
40
50
  "ajv-errors": "^3.0.0",
41
51
  "ajv-formats": "^3.0.1",
42
52
  "http-status-codes": "^2.3.0",
43
53
  "joi": "^17.7.0",
44
- "pg": "^8.16.3",
54
+ "pg": "catalog:",
45
55
  "reflect-metadata": "^0.1.13",
46
- "sequelize": "^6.37.7",
47
- "sequelize-typescript": "^2.1.6",
48
- "@autofleet/events": "^5.2.31"
56
+ "sequelize": "catalog:",
57
+ "sequelize-typescript": "catalog:"
49
58
  },
50
59
  "devDependencies": {
60
+ "@autofleet/errors": "workspace:^",
61
+ "@autofleet/logger": "workspace:^",
62
+ "@autofleet/node-common": "workspace:^",
63
+ "@autofleet/zehut": "workspace:^",
51
64
  "@types/express": "^4.17.17",
52
65
  "express": "^4.21.2",
53
66
  "npm-watch": "^0.11.0",
54
- "supertest": "^7.0.0",
55
- "@autofleet/errors": "^3.1.38",
56
- "@autofleet/node-common": "^4.2.19",
57
- "@autofleet/logger": "^4.2.42",
58
- "@autofleet/zehut": "^4.7.1"
67
+ "supertest": "^7.0.0"
59
68
  },
60
69
  "peerDependencies": {
61
70
  "@autofleet/errors": "^3",
@@ -68,14 +77,5 @@
68
77
  "node": ">=18.0.0"
69
78
  },
70
79
  "author": "Autofleet",
71
- "license": "ISC",
72
- "scripts": {
73
- "build": "pnpm -w tsdown -W ./packages/sadot",
74
- "linter": "eslint .",
75
- "test": "vitest",
76
- "test-debug": "node --inspect-brk node_modules/.bin/vitest --testTimeout=10000000",
77
- "coverage": "vitest --coverage",
78
- "build-to-local-repo": "node --run build && cp -r dist/* ../$REPO/node_modules/$npm_package_name/dist",
79
- "watch": "npm-watch build-to-local-repo"
80
- }
81
- }
80
+ "license": "ISC"
81
+ }