@autofleet/sadot 1.1.12 → 1.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,`__esModule`,{value:!0});const e=require(`./utils/logger/index.cjs`),t=require(`./utils/constants/index.cjs`),n=require(`./models/CustomFieldDefinition.cjs`),r=require(`./models/CustomFieldValue.cjs`),i=require(`./models/CustomFieldEntries.cjs`),a=require(`./models/CustomValidator.cjs`),o=require(`./models/index.cjs`),s=require(`./api/index.cjs`),c=require(`./utils/db/index.cjs`),l=require(`./utils/helpers/index.cjs`),u=require(`./scopes/filter.cjs`),d=require(`./utils/init.cjs`),f=require(`./utils/validations/schema/custom-fields.cjs`),p=async(t,n,r)=>{e.tryAddingTraceIdMiddleware();let{models:i,useCustomFieldsEntries:a}=r;t&&t.use(`/api`,s.default);let l=r.sequelize??c.default(r.databaseConfig);return process.env.NODE_ENV===`test`&&await o.initTestModels(l),d.addHooks(i,n,{useCustomFieldsEntries:a}),await o.initTables(l,r.getUser,{useCustomFieldsEntries:a}),d.addScopes(i,n,{useCustomFieldsEntries:a}),d.applyCustomAssociation(i),e.default.debug(`sadot - custom fields finished initializing with models`,i),l};var m=p;const h=(e,t)=>{d.removeHooks(e,t)};exports.CUSTOM_FIELDS_FILTER_SCOPE=t.CUSTOM_FIELDS_FILTER_SCOPE,exports.CustomFieldDefinition=n,exports.CustomFieldDefinitionType=t.CustomFieldDefinitionType,exports.CustomFieldEntries=i,exports.CustomFieldValue=r,exports.CustomFieldsSchema=f.CustomFieldsSchema,exports.CustomValidator=a,exports.customFieldsSortScope=u.customFieldsSortScope,exports.default=m,exports.disableCustomFields=h,exports.generateCustomFieldSearchQueryPayload=l.generateCustomFieldSearchQueryPayload,exports.generateRandomString=l.generateRandomString,exports.supportedEntities=t.supportedEntities;
1
+ Object.defineProperty(exports,`__esModule`,{value:!0});const e=require(`./utils/logger/index.cjs`),t=require(`./utils/constants/index.cjs`),n=require(`./models/CustomFieldValue.cjs`),r=require(`./models/CustomFieldDefinition.cjs`),i=require(`./models/CustomFieldEntries.cjs`),a=require(`./models/CustomValidator.cjs`),o=require(`./models/index.cjs`),s=require(`./api/index.cjs`),c=require(`./utils/db/index.cjs`),l=require(`./utils/helpers/index.cjs`),u=require(`./scopes/filter.cjs`),d=require(`./utils/init.cjs`),f=require(`./utils/validations/schema/custom-fields.cjs`),p=async(t,n,r)=>{e.tryAddingTraceIdMiddleware();let{models:i,useCustomFieldsEntries:a}=r;t&&t.use(`/api`,s.default);let l=r.sequelize??c.default(r.databaseConfig);return process.env.NODE_ENV===`test`&&await o.initTestModels(l),d.addHooks(i,n,{useCustomFieldsEntries:a}),await o.initTables(l,r.getUser,{useCustomFieldsEntries:a}),d.addScopes(i,n,{useCustomFieldsEntries:a}),d.applyCustomAssociation(i),e.default.debug(`sadot - custom fields finished initializing with models`,i),l};var m=p;const h=(e,t)=>{d.removeHooks(e,t)};exports.CUSTOM_FIELDS_FILTER_SCOPE=t.CUSTOM_FIELDS_FILTER_SCOPE,exports.CustomFieldDefinition=r,exports.CustomFieldDefinitionType=t.CustomFieldDefinitionType,exports.CustomFieldEntries=i,exports.CustomFieldValue=n,exports.CustomFieldsSchema=f.CustomFieldsSchema,exports.CustomValidator=a,exports.customFieldsSortScope=u.customFieldsSortScope,exports.default=m,exports.disableCustomFields=h,exports.generateCustomFieldSearchQueryPayload=l.generateCustomFieldSearchQueryPayload,exports.generateRandomString=l.generateRandomString,exports.supportedEntities=t.supportedEntities;
2
2
  //# sourceMappingURL=index.cjs.map
package/dist/index.d.cts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { CUSTOM_FIELDS_FILTER_SCOPE, CustomFieldDefinitionType, supportedEntities } from "./utils/constants/index.cjs";
2
2
  import { CustomFieldValue } from "./models/CustomFieldValue.cjs";
3
- import { CustomFieldEntries } from "./models/CustomFieldEntries.cjs";
4
- import { CustomValidator } from "./models/CustomValidator.cjs";
5
- import "./models/index.cjs";
6
3
  import { CustomFieldDefinition } from "./models/CustomFieldDefinition.cjs";
4
+ import { CustomValidator } from "./models/CustomValidator.cjs";
7
5
  import { CustomFieldOptions, ModelFetcher, Models } from "./types/index.cjs";
8
6
  import { CustomFieldsSchema } from "./utils/validations/schema/custom-fields.cjs";
9
7
  import { generateCustomFieldSearchQueryPayload, generateRandomString } from "./utils/helpers/index.cjs";
10
8
  import { customFieldsSortScope } from "./scopes/filter.cjs";
9
+ import { CustomFieldEntries } from "./models/CustomFieldEntries.cjs";
10
+ import "./models/index.cjs";
11
11
  import { Application } from "express";
12
12
  import { Sequelize } from "sequelize-typescript";
13
13
 
package/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { CUSTOM_FIELDS_FILTER_SCOPE, CustomFieldDefinitionType, supportedEntities } from "./utils/constants/index.js";
2
2
  import { CustomFieldValue } from "./models/CustomFieldValue.js";
3
- import { CustomFieldEntries } from "./models/CustomFieldEntries.js";
4
- import { CustomValidator } from "./models/CustomValidator.js";
5
- import "./models/index.js";
6
3
  import { CustomFieldDefinition } from "./models/CustomFieldDefinition.js";
4
+ import { CustomValidator } from "./models/CustomValidator.js";
7
5
  import { CustomFieldOptions, ModelFetcher, Models } from "./types/index.js";
8
6
  import { CustomFieldsSchema } from "./utils/validations/schema/custom-fields.js";
9
7
  import { generateCustomFieldSearchQueryPayload, generateRandomString } from "./utils/helpers/index.js";
10
8
  import { customFieldsSortScope } from "./scopes/filter.js";
9
+ import { CustomFieldEntries } from "./models/CustomFieldEntries.js";
10
+ import "./models/index.js";
11
11
  import { Sequelize } from "sequelize-typescript";
12
12
  import { Application } from "express";
13
13
 
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import e,{tryAddingTraceIdMiddleware as t}from"./utils/logger/index.js";import{CUSTOM_FIELDS_FILTER_SCOPE as n,CustomFieldDefinitionType as r,supportedEntities as i}from"./utils/constants/index.js";import a from"./models/CustomFieldDefinition.js";import o from"./models/CustomFieldValue.js";import s from"./models/CustomFieldEntries.js";import c from"./models/CustomValidator.js";import{initTables as l,initTestModels as u}from"./models/index.js";import d from"./api/index.js";import f from"./utils/db/index.js";import{generateCustomFieldSearchQueryPayload as p,generateRandomString as m}from"./utils/helpers/index.js";import{customFieldsSortScope as h}from"./scopes/filter.js";import{addHooks as g,addScopes as _,applyCustomAssociation as v,removeHooks as y}from"./utils/init.js";import{CustomFieldsSchema as b}from"./utils/validations/schema/custom-fields.js";var x=async(n,r,i)=>{t();let{models:a,useCustomFieldsEntries:o}=i;n&&n.use(`/api`,d);let s=i.sequelize??f(i.databaseConfig);return process.env.NODE_ENV===`test`&&await u(s),g(a,r,{useCustomFieldsEntries:o}),await l(s,i.getUser,{useCustomFieldsEntries:o}),_(a,r,{useCustomFieldsEntries:o}),v(a),e.debug(`sadot - custom fields finished initializing with models`,a),s};const S=(e,t)=>{y(e,t)};export{n as CUSTOM_FIELDS_FILTER_SCOPE,a as CustomFieldDefinition,r as CustomFieldDefinitionType,s as CustomFieldEntries,o as CustomFieldValue,b as CustomFieldsSchema,c as CustomValidator,h as customFieldsSortScope,x as default,S as disableCustomFields,p as generateCustomFieldSearchQueryPayload,m as generateRandomString,i as supportedEntities};
1
+ import e,{tryAddingTraceIdMiddleware as t}from"./utils/logger/index.js";import{CUSTOM_FIELDS_FILTER_SCOPE as n,CustomFieldDefinitionType as r,supportedEntities as i}from"./utils/constants/index.js";import a from"./models/CustomFieldValue.js";import o from"./models/CustomFieldDefinition.js";import s from"./models/CustomFieldEntries.js";import c from"./models/CustomValidator.js";import{initTables as l,initTestModels as u}from"./models/index.js";import d from"./api/index.js";import f from"./utils/db/index.js";import{generateCustomFieldSearchQueryPayload as p,generateRandomString as m}from"./utils/helpers/index.js";import{customFieldsSortScope as h}from"./scopes/filter.js";import{addHooks as g,addScopes as _,applyCustomAssociation as v,removeHooks as y}from"./utils/init.js";import{CustomFieldsSchema as b}from"./utils/validations/schema/custom-fields.js";var x=async(n,r,i)=>{t();let{models:a,useCustomFieldsEntries:o}=i;n&&n.use(`/api`,d);let s=i.sequelize??f(i.databaseConfig);return process.env.NODE_ENV===`test`&&await u(s),g(a,r,{useCustomFieldsEntries:o}),await l(s,i.getUser,{useCustomFieldsEntries:o}),_(a,r,{useCustomFieldsEntries:o}),v(a),e.debug(`sadot - custom fields finished initializing with models`,a),s};const S=(e,t)=>{y(e,t)};export{n as CUSTOM_FIELDS_FILTER_SCOPE,o as CustomFieldDefinition,r as CustomFieldDefinitionType,s as CustomFieldEntries,a as CustomFieldValue,b as CustomFieldsSchema,c as CustomValidator,h as customFieldsSortScope,x as default,S as disableCustomFields,p as generateCustomFieldSearchQueryPayload,m as generateRandomString,i as supportedEntities};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../utils/logger/index.cjs`),n=require(`../utils/constants/index.cjs`),r=require(`../utils/validations/validators/index.cjs`),i=require(`../events/index.cjs`),a=require(`../errors/index.cjs`),o=require(`../utils/validations/index.cjs`),s=require(`../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.cjs`),c=require(`../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorate.cjs`),l=require(`./CustomFieldValue.cjs`);require(`./index.cjs`);let u=require(`sequelize-typescript`);var d,f,p,m,h,g;let _=class extends u.Model{static displayNameDefaultValue(e){if(e?.displayName||(e.displayName=e.name),![null,void 0].includes(e.defaultValue)){let t=o.validateValue(e.defaultValue,e.fieldType,e.validation);if(t.error)throw new a.InvalidValueError(e.defaultValue,e.name,t.error)}}static afterSaveHandler(e,t){t.transaction?t.transaction.afterCommit(()=>i.sendDimEvent(e)):i.sendDimEvent(e)}};c.__decorate([u.PrimaryKey,(0,u.Column)({type:u.DataType.UUID,defaultValue:u.DataType.UUIDV4,allowNull:!1}),s.__decorateMetadata(`design:type`,String)],_.prototype,`id`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.STRING,allowNull:!1}),s.__decorateMetadata(`design:type`,String)],_.prototype,`name`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.STRING}),s.__decorateMetadata(`design:type`,String)],_.prototype,`displayName`,void 0),c.__decorate([(0,u.Is)(`SupportedType`,e=>{if(!Object.values(n.CustomFieldDefinitionType).includes(e))throw new a.UnsupportedCustomFieldTypeError(`"${e}" is not a supported type.`)}),(0,u.Column)({type:u.DataType.STRING,allowNull:!1}),s.__decorateMetadata(`design:type`,typeof(d=n.CustomFieldDefinitionType!==void 0&&n.CustomFieldDefinitionType)==`function`?d:Object)],_.prototype,`fieldType`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.JSONB}),s.__decorateMetadata(`design:type`,Object)],_.prototype,`validation`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.UUID,allowNull:!1}),s.__decorateMetadata(`design:type`,String)],_.prototype,`entityId`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.STRING,allowNull:!1}),s.__decorateMetadata(`design:type`,String)],_.prototype,`entityType`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.STRING,allowNull:!1}),s.__decorateMetadata(`design:type`,String)],_.prototype,`modelType`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.TEXT}),s.__decorateMetadata(`design:type`,String)],_.prototype,`description`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.BOOLEAN,defaultValue:!1}),s.__decorateMetadata(`design:type`,Boolean)],_.prototype,`required`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.BOOLEAN,defaultValue:!1}),s.__decorateMetadata(`design:type`,Boolean)],_.prototype,`disabled`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.JSONB,allowNull:!0}),s.__decorateMetadata(`design:type`,Object)],_.prototype,`defaultValue`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.DATE,allowNull:!1}),s.__decorateMetadata(`design:type`,typeof(f=typeof Date<`u`&&Date)==`function`?f:Object)],_.prototype,`createdAt`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.DATE,allowNull:!0}),s.__decorateMetadata(`design:type`,typeof(p=typeof Date<`u`&&Date)==`function`?p:Object)],_.prototype,`updatedAt`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.DATE,allowNull:!0}),s.__decorateMetadata(`design:type`,typeof(m=typeof Date<`u`&&Date)==`function`?m:Object)],_.prototype,`deletedAt`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.BOOLEAN,defaultValue:!1,allowNull:!1}),s.__decorateMetadata(`design:type`,Boolean)],_.prototype,`blockEditingFromUI`,void 0),c.__decorate([(0,u.HasMany)(()=>l.default),s.__decorateMetadata(`design:type`,Array)],_.prototype,`values`,void 0),c.__decorate([u.BeforeCreate,s.__decorateMetadata(`design:type`,Function),s.__decorateMetadata(`design:paramtypes`,[typeof(h=_!==void 0&&_)==`function`?h:Object]),s.__decorateMetadata(`design:returntype`,void 0)],_,`displayNameDefaultValue`,null),c.__decorate([u.AfterSave,s.__decorateMetadata(`design:type`,Function),s.__decorateMetadata(`design:paramtypes`,[typeof(g=_!==void 0&&_)==`function`?g:Object,Object]),s.__decorateMetadata(`design:returntype`,void 0)],_,`afterSaveHandler`,null),_=c.__decorate([(0,u.DefaultScope)(()=>({where:{disabled:!1}})),(0,u.Table)({tableName:`custom_field_definitions`,modelName:`CustomFieldDefinition`,indexes:[{name:`unique_name_model_type`,fields:[`model_type`,`entity_id`,`name`],unique:!0}],timestamps:!0,validate:{validationByType(){if(!this.validation&&r.CustomValidationTypes[this.fieldType])throw t.default.error(`No custom validation for custom field type ${this.fieldType} found`),new a.UnsupportedCustomValidationError(`Validation provided for "${this.fieldType}" is not supported`)}}})],_);var v=_;exports.default=v;
1
+ const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../utils/logger/index.cjs`),n=require(`../utils/constants/index.cjs`),r=require(`../utils/validations/validators/index.cjs`),i=require(`../events/index.cjs`),a=require(`../errors/index.cjs`),o=require(`../utils/validations/index.cjs`),s=require(`../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.cjs`),c=require(`../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorate.cjs`),l=require(`./CustomFieldValue.cjs`);let u=require(`sequelize-typescript`);var d,f,p,m,h,g;let _=class extends u.Model{static displayNameDefaultValue(e){if(e?.displayName||(e.displayName=e.name),![null,void 0].includes(e.defaultValue)){let t=o.validateValue(e.defaultValue,e.fieldType,e.validation);if(t.error)throw new a.InvalidValueError(e.defaultValue,e.name,t.error)}}static afterSaveHandler(e,t){t.transaction?t.transaction.afterCommit(()=>i.sendDimEvent(e)):i.sendDimEvent(e)}};c.__decorate([u.PrimaryKey,(0,u.Column)({type:u.DataType.UUID,defaultValue:u.DataType.UUIDV4,allowNull:!1}),s.__decorateMetadata(`design:type`,String)],_.prototype,`id`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.STRING,allowNull:!1}),s.__decorateMetadata(`design:type`,String)],_.prototype,`name`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.STRING}),s.__decorateMetadata(`design:type`,String)],_.prototype,`displayName`,void 0),c.__decorate([(0,u.Is)(`SupportedType`,e=>{if(!Object.values(n.CustomFieldDefinitionType).includes(e))throw new a.UnsupportedCustomFieldTypeError(`"${e}" is not a supported type.`)}),(0,u.Column)({type:u.DataType.STRING,allowNull:!1}),s.__decorateMetadata(`design:type`,typeof(d=n.CustomFieldDefinitionType!==void 0&&n.CustomFieldDefinitionType)==`function`?d:Object)],_.prototype,`fieldType`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.JSONB}),s.__decorateMetadata(`design:type`,Object)],_.prototype,`validation`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.UUID,allowNull:!1}),s.__decorateMetadata(`design:type`,String)],_.prototype,`entityId`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.STRING,allowNull:!1}),s.__decorateMetadata(`design:type`,String)],_.prototype,`entityType`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.STRING,allowNull:!1}),s.__decorateMetadata(`design:type`,String)],_.prototype,`modelType`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.TEXT}),s.__decorateMetadata(`design:type`,String)],_.prototype,`description`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.BOOLEAN,defaultValue:!1}),s.__decorateMetadata(`design:type`,Boolean)],_.prototype,`required`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.BOOLEAN,defaultValue:!1}),s.__decorateMetadata(`design:type`,Boolean)],_.prototype,`disabled`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.JSONB,allowNull:!0}),s.__decorateMetadata(`design:type`,Object)],_.prototype,`defaultValue`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.DATE,allowNull:!1}),s.__decorateMetadata(`design:type`,typeof(f=typeof Date<`u`&&Date)==`function`?f:Object)],_.prototype,`createdAt`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.DATE,allowNull:!0}),s.__decorateMetadata(`design:type`,typeof(p=typeof Date<`u`&&Date)==`function`?p:Object)],_.prototype,`updatedAt`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.DATE,allowNull:!0}),s.__decorateMetadata(`design:type`,typeof(m=typeof Date<`u`&&Date)==`function`?m:Object)],_.prototype,`deletedAt`,void 0),c.__decorate([(0,u.Column)({type:u.DataType.BOOLEAN,defaultValue:!1,allowNull:!1}),s.__decorateMetadata(`design:type`,Boolean)],_.prototype,`blockEditingFromUI`,void 0),c.__decorate([(0,u.HasMany)(()=>l.default),s.__decorateMetadata(`design:type`,Array)],_.prototype,`values`,void 0),c.__decorate([u.BeforeCreate,s.__decorateMetadata(`design:type`,Function),s.__decorateMetadata(`design:paramtypes`,[typeof(h=_!==void 0&&_)==`function`?h:Object]),s.__decorateMetadata(`design:returntype`,void 0)],_,`displayNameDefaultValue`,null),c.__decorate([u.AfterSave,s.__decorateMetadata(`design:type`,Function),s.__decorateMetadata(`design:paramtypes`,[typeof(g=_!==void 0&&_)==`function`?g:Object,Object]),s.__decorateMetadata(`design:returntype`,void 0)],_,`afterSaveHandler`,null),_=c.__decorate([(0,u.DefaultScope)(()=>({where:{disabled:!1}})),(0,u.Table)({tableName:`custom_field_definitions`,modelName:`CustomFieldDefinition`,indexes:[{name:`unique_name_model_type`,fields:[`model_type`,`entity_id`,`name`],unique:!0}],timestamps:!0,validate:{validationByType(){if(!this.validation&&r.CustomValidationTypes[this.fieldType])throw t.default.error(`No custom validation for custom field type ${this.fieldType} found`),new a.UnsupportedCustomValidationError(`Validation provided for "${this.fieldType}" is not supported`)}}})],_);var v=_;exports.default=v;
2
2
  //# sourceMappingURL=CustomFieldDefinition.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"CustomFieldDefinition.cjs","names":["CustomFieldDefinition","Model","validateValue","InvalidValueError","sendDimEvent","PrimaryKey","DataType","CustomFieldDefinitionType","UnsupportedCustomFieldTypeError","CustomFieldValue","BeforeCreate","AfterSave","CustomValidationTypes","UnsupportedCustomValidationError"],"sources":["../../src/models/CustomFieldDefinition.ts"],"sourcesContent":["import {\n Table,\n Column,\n Model,\n DataType,\n HasMany,\n PrimaryKey,\n BeforeCreate,\n DefaultScope,\n AfterSave,\n Is,\n} from 'sequelize-typescript';\nimport type { CreateOptions } from 'sequelize';\nimport { CustomFieldDefinitionType } from '../utils/constants';\nimport { CustomValidationTypes } from '../utils/validations/validators';\nimport { CustomFieldValue } from '.';\nimport { sendDimEvent } from '../events';\nimport { InvalidValueError, UnsupportedCustomFieldTypeError, UnsupportedCustomValidationError } from '../errors';\nimport logger from '../utils/logger';\nimport { validateValue } from '../utils/validations';\n\n@DefaultScope(() => ({ where: { disabled: false } }))\n@Table({\n tableName: 'custom_field_definitions',\n modelName: 'CustomFieldDefinition',\n indexes: [\n {\n name: 'unique_name_model_type',\n fields: ['model_type', 'entity_id', 'name'],\n unique: true,\n },\n ],\n timestamps: true,\n validate: {\n validationByType(this: CustomFieldDefinition) {\n // Verify the validation is provided if needed\n if (!this.validation && CustomValidationTypes[this.fieldType as keyof typeof CustomValidationTypes]) {\n // TODO: enforce the validation-object schema based on the fieldType\n logger.error(`No custom validation for custom field type ${this.fieldType} found`);\n throw new UnsupportedCustomValidationError(`Validation provided for \"${this.fieldType}\" is not supported`);\n }\n },\n },\n})\nclass CustomFieldDefinition 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.STRING,\n allowNull: false,\n })\n name!: string;\n\n @Column({\n type: DataType.STRING,\n })\n displayName?: string; // Defaulted to name with beforeCreate hook\n\n @Is('SupportedType', (value) => {\n if (!Object.values(CustomFieldDefinitionType).includes(value as CustomFieldDefinitionType)) {\n throw new UnsupportedCustomFieldTypeError(`\"${value}\" is not a supported type.`);\n }\n })\n @Column({\n type: DataType.STRING,\n allowNull: false,\n })\n fieldType!: CustomFieldDefinitionType;\n\n @Column({\n type: DataType.JSONB,\n })\n validation?: any;\n\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n entityId!: string; /** Client association entity id */\n\n @Column({\n type: DataType.STRING,\n allowNull: false,\n })\n entityType!: string; /** Client association entity type (demand source / fleet / etc.) */\n\n @Column({\n type: DataType.STRING,\n allowNull: false,\n })\n modelType!: string; /** Model type. e.g. Vehicle / StopPoint / etc. */\n\n @Column({\n type: DataType.TEXT,\n })\n description?: string;\n\n @Column({\n type: DataType.BOOLEAN,\n defaultValue: false,\n })\n required?: boolean;\n\n @Column({\n type: DataType.BOOLEAN,\n defaultValue: false,\n })\n disabled?: boolean;\n\n @Column({\n type: DataType.JSONB,\n allowNull: true,\n })\n defaultValue?: any;\n\n @Column({\n type: DataType.DATE,\n allowNull: false,\n })\n declare createdAt?: Date;\n\n @Column({\n type: DataType.DATE,\n allowNull: true,\n })\n declare updatedAt?: Date;\n\n @Column({\n type: DataType.DATE,\n allowNull: true,\n })\n declare deletedAt?: Date;\n\n @Column({\n type: DataType.BOOLEAN,\n defaultValue: false,\n allowNull: false,\n })\n blockEditingFromUI!: boolean;\n\n @HasMany(() => CustomFieldValue)\n declare values: CustomFieldValue[];\n\n @BeforeCreate\n static displayNameDefaultValue(instance: CustomFieldDefinition): void {\n if (!instance?.displayName) {\n instance.displayName = instance.name;\n }\n if (![null, undefined].includes(instance.defaultValue)) {\n const isValid = validateValue(instance.defaultValue, instance.fieldType, instance.validation);\n if (isValid.error) {\n throw new InvalidValueError(instance.defaultValue, instance.name, isValid.error);\n }\n }\n }\n\n @AfterSave\n static afterSaveHandler(instance: CustomFieldDefinition, options: CreateOptions): void {\n if (options.transaction) {\n options.transaction.afterCommit(() => sendDimEvent(instance));\n } else {\n sendDimEvent(instance);\n }\n }\n}\n\nexport default CustomFieldDefinition;\n"],"mappings":"2jBAqBA,IAAA,EAAA,cAuBoCC,EAAAA,KAAM,CAyGxC,OACO,wBAAwB,EAAuC,CAIpE,GAHK,GAAU,cACb,EAAS,YAAc,EAAS,MAE9B,CAAC,CAAC,KAAM,IAAA,GAAU,CAAC,SAAS,EAAS,aAAa,CAAE,CACtD,IAAM,EAAUC,EAAAA,cAAc,EAAS,aAAc,EAAS,UAAW,EAAS,WAAW,CAC7F,GAAI,EAAQ,MACV,MAAM,IAAIC,EAAAA,kBAAkB,EAAS,aAAc,EAAS,KAAM,EAAQ,MAAM,EAKtF,OACO,iBAAiB,EAAiC,EAA8B,CACjF,EAAQ,YACV,EAAQ,YAAY,gBAAkBC,EAAAA,aAAa,EAAS,CAAC,CAE7D,EAAA,aAAa,EAAS,iBA1HzBC,EAAAA,wBACO,CACN,KAAMC,EAAAA,SAAS,KACf,aAAcA,EAAAA,SAAS,OACvB,UAAW,GACZ,CAAC,iGAGM,CACN,KAAMA,EAAAA,SAAS,OACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,OAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,OAChB,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,cAAA,IA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AAe"}
1
+ {"version":3,"file":"CustomFieldDefinition.cjs","names":["CustomFieldDefinition","Model","validateValue","InvalidValueError","sendDimEvent","PrimaryKey","DataType","CustomFieldDefinitionType","UnsupportedCustomFieldTypeError","CustomFieldValue","BeforeCreate","AfterSave","CustomValidationTypes","UnsupportedCustomValidationError"],"sources":["../../src/models/CustomFieldDefinition.ts"],"sourcesContent":["import {\n Table,\n Column,\n Model,\n DataType,\n HasMany,\n PrimaryKey,\n BeforeCreate,\n DefaultScope,\n AfterSave,\n Is,\n} from 'sequelize-typescript';\nimport type { CreateOptions } from 'sequelize';\nimport { CustomFieldDefinitionType } from '../utils/constants';\nimport { CustomValidationTypes } from '../utils/validations/validators';\nimport CustomFieldValue from './CustomFieldValue';\nimport { sendDimEvent } from '../events';\nimport { InvalidValueError, UnsupportedCustomFieldTypeError, UnsupportedCustomValidationError } from '../errors';\nimport logger from '../utils/logger';\nimport { validateValue } from '../utils/validations';\n\n@DefaultScope(() => ({ where: { disabled: false } }))\n@Table({\n tableName: 'custom_field_definitions',\n modelName: 'CustomFieldDefinition',\n indexes: [\n {\n name: 'unique_name_model_type',\n fields: ['model_type', 'entity_id', 'name'],\n unique: true,\n },\n ],\n timestamps: true,\n validate: {\n validationByType(this: CustomFieldDefinition) {\n // Verify the validation is provided if needed\n if (!this.validation && CustomValidationTypes[this.fieldType as keyof typeof CustomValidationTypes]) {\n // TODO: enforce the validation-object schema based on the fieldType\n logger.error(`No custom validation for custom field type ${this.fieldType} found`);\n throw new UnsupportedCustomValidationError(`Validation provided for \"${this.fieldType}\" is not supported`);\n }\n },\n },\n})\nclass CustomFieldDefinition 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.STRING,\n allowNull: false,\n })\n name!: string;\n\n @Column({\n type: DataType.STRING,\n })\n displayName?: string; // Defaulted to name with beforeCreate hook\n\n @Is('SupportedType', (value) => {\n if (!Object.values(CustomFieldDefinitionType).includes(value as CustomFieldDefinitionType)) {\n throw new UnsupportedCustomFieldTypeError(`\"${value}\" is not a supported type.`);\n }\n })\n @Column({\n type: DataType.STRING,\n allowNull: false,\n })\n fieldType!: CustomFieldDefinitionType;\n\n @Column({\n type: DataType.JSONB,\n })\n validation?: any;\n\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n entityId!: string; /** Client association entity id */\n\n @Column({\n type: DataType.STRING,\n allowNull: false,\n })\n entityType!: string; /** Client association entity type (demand source / fleet / etc.) */\n\n @Column({\n type: DataType.STRING,\n allowNull: false,\n })\n modelType!: string; /** Model type. e.g. Vehicle / StopPoint / etc. */\n\n @Column({\n type: DataType.TEXT,\n })\n description?: string;\n\n @Column({\n type: DataType.BOOLEAN,\n defaultValue: false,\n })\n required?: boolean;\n\n @Column({\n type: DataType.BOOLEAN,\n defaultValue: false,\n })\n disabled?: boolean;\n\n @Column({\n type: DataType.JSONB,\n allowNull: true,\n })\n defaultValue?: any;\n\n @Column({\n type: DataType.DATE,\n allowNull: false,\n })\n declare createdAt?: Date;\n\n @Column({\n type: DataType.DATE,\n allowNull: true,\n })\n declare updatedAt?: Date;\n\n @Column({\n type: DataType.DATE,\n allowNull: true,\n })\n declare deletedAt?: Date;\n\n @Column({\n type: DataType.BOOLEAN,\n defaultValue: false,\n allowNull: false,\n })\n blockEditingFromUI!: boolean;\n\n @HasMany(() => CustomFieldValue)\n declare values: CustomFieldValue[];\n\n @BeforeCreate\n static displayNameDefaultValue(instance: CustomFieldDefinition): void {\n if (!instance?.displayName) {\n instance.displayName = instance.name;\n }\n if (![null, undefined].includes(instance.defaultValue)) {\n const isValid = validateValue(instance.defaultValue, instance.fieldType, instance.validation);\n if (isValid.error) {\n throw new InvalidValueError(instance.defaultValue, instance.name, isValid.error);\n }\n }\n }\n\n @AfterSave\n static afterSaveHandler(instance: CustomFieldDefinition, options: CreateOptions): void {\n if (options.transaction) {\n options.transaction.afterCommit(() => sendDimEvent(instance));\n } else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,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,EAAA,OAAA,KAAA,KAAA,OAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,QACf,aAAc,GACd,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,QAAA,CAAA,CAAA,EAAA,UAAA,qBAAA,IAAA,GAAA,iCAGaG,EAAAA,QAAiB,CAAA,EAAA,mBAAA,cAAA,MAAA,CAAA,CAAA,EAAA,UAAA,SAAA,IAAA,GAAA,eAG/BC,EAAAA,qPAaAC,EAAAA,4QA7IkB,CAAE,MAAO,CAAE,SAAU,GAAO,CAAE,EAAE,EAAA,EAAA,EAAA,OAC9C,CACL,UAAW,2BACX,UAAW,wBACX,QAAS,CACP,CACE,KAAM,yBACN,OAAQ,CAAC,aAAc,YAAa,OAAO,CAC3C,OAAQ,GACT,CACF,CACD,WAAY,GACZ,SAAU,CACR,kBAA8C,CAE5C,GAAI,CAAC,KAAK,YAAcC,EAAAA,sBAAsB,KAAK,WAGjD,MADA,EAAA,QAAO,MAAM,8CAA8C,KAAK,UAAU,QAAQ,CAC5E,IAAIC,EAAAA,iCAAiC,4BAA4B,KAAK,UAAU,oBAAoB,EAG/G,CACF,CAAC,CAAA,CAAA,EAAA,CAiIF,IAAA,EAAe"}
@@ -1,6 +1,5 @@
1
1
  import { CustomFieldDefinitionType } from "../utils/constants/index.cjs";
2
2
  import { CustomFieldValue } from "./CustomFieldValue.cjs";
3
- import "./index.cjs";
4
3
  import { Model } from "sequelize-typescript";
5
4
  import { CreateOptions } from "sequelize";
6
5
 
@@ -1,6 +1,5 @@
1
1
  import { CustomFieldDefinitionType } from "../utils/constants/index.js";
2
2
  import { CustomFieldValue } from "./CustomFieldValue.js";
3
- import "./index.js";
4
3
  import { CreateOptions } from "sequelize";
5
4
  import { Model } from "sequelize-typescript";
6
5
 
@@ -1,2 +1,2 @@
1
- import e from"../utils/logger/index.js";import{CustomFieldDefinitionType as t}from"../utils/constants/index.js";import{CustomValidationTypes as n}from"../utils/validations/validators/index.js";import{sendDimEvent as r}from"../events/index.js";import{InvalidValueError as i,UnsupportedCustomFieldTypeError as a,UnsupportedCustomValidationError as o}from"../errors/index.js";import{validateValue as s}from"../utils/validations/index.js";import{__decorateMetadata as c}from"../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.js";import{__decorate as l}from"../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorate.js";import u from"./CustomFieldValue.js";import"./index.js";import{AfterSave as d,BeforeCreate as f,Column as p,DataType as m,DefaultScope as h,HasMany as g,Is as _,Model as v,PrimaryKey as y,Table as b}from"sequelize-typescript";var x,S,C,w,T,E;let D=class extends v{static displayNameDefaultValue(e){if(e?.displayName||(e.displayName=e.name),![null,void 0].includes(e.defaultValue)){let t=s(e.defaultValue,e.fieldType,e.validation);if(t.error)throw new i(e.defaultValue,e.name,t.error)}}static afterSaveHandler(e,t){t.transaction?t.transaction.afterCommit(()=>r(e)):r(e)}};l([y,p({type:m.UUID,defaultValue:m.UUIDV4,allowNull:!1}),c(`design:type`,String)],D.prototype,`id`,void 0),l([p({type:m.STRING,allowNull:!1}),c(`design:type`,String)],D.prototype,`name`,void 0),l([p({type:m.STRING}),c(`design:type`,String)],D.prototype,`displayName`,void 0),l([_(`SupportedType`,e=>{if(!Object.values(t).includes(e))throw new a(`"${e}" is not a supported type.`)}),p({type:m.STRING,allowNull:!1}),c(`design:type`,typeof(x=t!==void 0&&t)==`function`?x:Object)],D.prototype,`fieldType`,void 0),l([p({type:m.JSONB}),c(`design:type`,Object)],D.prototype,`validation`,void 0),l([p({type:m.UUID,allowNull:!1}),c(`design:type`,String)],D.prototype,`entityId`,void 0),l([p({type:m.STRING,allowNull:!1}),c(`design:type`,String)],D.prototype,`entityType`,void 0),l([p({type:m.STRING,allowNull:!1}),c(`design:type`,String)],D.prototype,`modelType`,void 0),l([p({type:m.TEXT}),c(`design:type`,String)],D.prototype,`description`,void 0),l([p({type:m.BOOLEAN,defaultValue:!1}),c(`design:type`,Boolean)],D.prototype,`required`,void 0),l([p({type:m.BOOLEAN,defaultValue:!1}),c(`design:type`,Boolean)],D.prototype,`disabled`,void 0),l([p({type:m.JSONB,allowNull:!0}),c(`design:type`,Object)],D.prototype,`defaultValue`,void 0),l([p({type:m.DATE,allowNull:!1}),c(`design:type`,typeof(S=typeof Date<`u`&&Date)==`function`?S:Object)],D.prototype,`createdAt`,void 0),l([p({type:m.DATE,allowNull:!0}),c(`design:type`,typeof(C=typeof Date<`u`&&Date)==`function`?C:Object)],D.prototype,`updatedAt`,void 0),l([p({type:m.DATE,allowNull:!0}),c(`design:type`,typeof(w=typeof Date<`u`&&Date)==`function`?w:Object)],D.prototype,`deletedAt`,void 0),l([p({type:m.BOOLEAN,defaultValue:!1,allowNull:!1}),c(`design:type`,Boolean)],D.prototype,`blockEditingFromUI`,void 0),l([g(()=>u),c(`design:type`,Array)],D.prototype,`values`,void 0),l([f,c(`design:type`,Function),c(`design:paramtypes`,[typeof(T=D!==void 0&&D)==`function`?T:Object]),c(`design:returntype`,void 0)],D,`displayNameDefaultValue`,null),l([d,c(`design:type`,Function),c(`design:paramtypes`,[typeof(E=D!==void 0&&D)==`function`?E:Object,Object]),c(`design:returntype`,void 0)],D,`afterSaveHandler`,null),D=l([h(()=>({where:{disabled:!1}})),b({tableName:`custom_field_definitions`,modelName:`CustomFieldDefinition`,indexes:[{name:`unique_name_model_type`,fields:[`model_type`,`entity_id`,`name`],unique:!0}],timestamps:!0,validate:{validationByType(){if(!this.validation&&n[this.fieldType])throw e.error(`No custom validation for custom field type ${this.fieldType} found`),new o(`Validation provided for "${this.fieldType}" is not supported`)}}})],D);var O=D;export{O as default};
1
+ import e from"../utils/logger/index.js";import{CustomFieldDefinitionType as t}from"../utils/constants/index.js";import{CustomValidationTypes as n}from"../utils/validations/validators/index.js";import{sendDimEvent as r}from"../events/index.js";import{InvalidValueError as i,UnsupportedCustomFieldTypeError as a,UnsupportedCustomValidationError as o}from"../errors/index.js";import{validateValue as s}from"../utils/validations/index.js";import{__decorateMetadata as c}from"../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.js";import{__decorate as l}from"../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorate.js";import u from"./CustomFieldValue.js";import{AfterSave as d,BeforeCreate as f,Column as p,DataType as m,DefaultScope as h,HasMany as g,Is as _,Model as v,PrimaryKey as y,Table as b}from"sequelize-typescript";var x,S,C,w,T,E;let D=class extends v{static displayNameDefaultValue(e){if(e?.displayName||(e.displayName=e.name),![null,void 0].includes(e.defaultValue)){let t=s(e.defaultValue,e.fieldType,e.validation);if(t.error)throw new i(e.defaultValue,e.name,t.error)}}static afterSaveHandler(e,t){t.transaction?t.transaction.afterCommit(()=>r(e)):r(e)}};l([y,p({type:m.UUID,defaultValue:m.UUIDV4,allowNull:!1}),c(`design:type`,String)],D.prototype,`id`,void 0),l([p({type:m.STRING,allowNull:!1}),c(`design:type`,String)],D.prototype,`name`,void 0),l([p({type:m.STRING}),c(`design:type`,String)],D.prototype,`displayName`,void 0),l([_(`SupportedType`,e=>{if(!Object.values(t).includes(e))throw new a(`"${e}" is not a supported type.`)}),p({type:m.STRING,allowNull:!1}),c(`design:type`,typeof(x=t!==void 0&&t)==`function`?x:Object)],D.prototype,`fieldType`,void 0),l([p({type:m.JSONB}),c(`design:type`,Object)],D.prototype,`validation`,void 0),l([p({type:m.UUID,allowNull:!1}),c(`design:type`,String)],D.prototype,`entityId`,void 0),l([p({type:m.STRING,allowNull:!1}),c(`design:type`,String)],D.prototype,`entityType`,void 0),l([p({type:m.STRING,allowNull:!1}),c(`design:type`,String)],D.prototype,`modelType`,void 0),l([p({type:m.TEXT}),c(`design:type`,String)],D.prototype,`description`,void 0),l([p({type:m.BOOLEAN,defaultValue:!1}),c(`design:type`,Boolean)],D.prototype,`required`,void 0),l([p({type:m.BOOLEAN,defaultValue:!1}),c(`design:type`,Boolean)],D.prototype,`disabled`,void 0),l([p({type:m.JSONB,allowNull:!0}),c(`design:type`,Object)],D.prototype,`defaultValue`,void 0),l([p({type:m.DATE,allowNull:!1}),c(`design:type`,typeof(S=typeof Date<`u`&&Date)==`function`?S:Object)],D.prototype,`createdAt`,void 0),l([p({type:m.DATE,allowNull:!0}),c(`design:type`,typeof(C=typeof Date<`u`&&Date)==`function`?C:Object)],D.prototype,`updatedAt`,void 0),l([p({type:m.DATE,allowNull:!0}),c(`design:type`,typeof(w=typeof Date<`u`&&Date)==`function`?w:Object)],D.prototype,`deletedAt`,void 0),l([p({type:m.BOOLEAN,defaultValue:!1,allowNull:!1}),c(`design:type`,Boolean)],D.prototype,`blockEditingFromUI`,void 0),l([g(()=>u),c(`design:type`,Array)],D.prototype,`values`,void 0),l([f,c(`design:type`,Function),c(`design:paramtypes`,[typeof(T=D!==void 0&&D)==`function`?T:Object]),c(`design:returntype`,void 0)],D,`displayNameDefaultValue`,null),l([d,c(`design:type`,Function),c(`design:paramtypes`,[typeof(E=D!==void 0&&D)==`function`?E:Object,Object]),c(`design:returntype`,void 0)],D,`afterSaveHandler`,null),D=l([h(()=>({where:{disabled:!1}})),b({tableName:`custom_field_definitions`,modelName:`CustomFieldDefinition`,indexes:[{name:`unique_name_model_type`,fields:[`model_type`,`entity_id`,`name`],unique:!0}],timestamps:!0,validate:{validationByType(){if(!this.validation&&n[this.fieldType])throw e.error(`No custom validation for custom field type ${this.fieldType} found`),new o(`Validation provided for "${this.fieldType}" is not supported`)}}})],D);var O=D;export{O as default};
2
2
  //# sourceMappingURL=CustomFieldDefinition.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CustomFieldDefinition.js","names":["CustomFieldDefinition","CustomFieldValue"],"sources":["../../src/models/CustomFieldDefinition.ts"],"sourcesContent":["import {\n Table,\n Column,\n Model,\n DataType,\n HasMany,\n PrimaryKey,\n BeforeCreate,\n DefaultScope,\n AfterSave,\n Is,\n} from 'sequelize-typescript';\nimport type { CreateOptions } from 'sequelize';\nimport { CustomFieldDefinitionType } from '../utils/constants';\nimport { CustomValidationTypes } from '../utils/validations/validators';\nimport { CustomFieldValue } from '.';\nimport { sendDimEvent } from '../events';\nimport { InvalidValueError, UnsupportedCustomFieldTypeError, UnsupportedCustomValidationError } from '../errors';\nimport logger from '../utils/logger';\nimport { validateValue } from '../utils/validations';\n\n@DefaultScope(() => ({ where: { disabled: false } }))\n@Table({\n tableName: 'custom_field_definitions',\n modelName: 'CustomFieldDefinition',\n indexes: [\n {\n name: 'unique_name_model_type',\n fields: ['model_type', 'entity_id', 'name'],\n unique: true,\n },\n ],\n timestamps: true,\n validate: {\n validationByType(this: CustomFieldDefinition) {\n // Verify the validation is provided if needed\n if (!this.validation && CustomValidationTypes[this.fieldType as keyof typeof CustomValidationTypes]) {\n // TODO: enforce the validation-object schema based on the fieldType\n logger.error(`No custom validation for custom field type ${this.fieldType} found`);\n throw new UnsupportedCustomValidationError(`Validation provided for \"${this.fieldType}\" is not supported`);\n }\n },\n },\n})\nclass CustomFieldDefinition 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.STRING,\n allowNull: false,\n })\n name!: string;\n\n @Column({\n type: DataType.STRING,\n })\n displayName?: string; // Defaulted to name with beforeCreate hook\n\n @Is('SupportedType', (value) => {\n if (!Object.values(CustomFieldDefinitionType).includes(value as CustomFieldDefinitionType)) {\n throw new UnsupportedCustomFieldTypeError(`\"${value}\" is not a supported type.`);\n }\n })\n @Column({\n type: DataType.STRING,\n allowNull: false,\n })\n fieldType!: CustomFieldDefinitionType;\n\n @Column({\n type: DataType.JSONB,\n })\n validation?: any;\n\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n entityId!: string; /** Client association entity id */\n\n @Column({\n type: DataType.STRING,\n allowNull: false,\n })\n entityType!: string; /** Client association entity type (demand source / fleet / etc.) */\n\n @Column({\n type: DataType.STRING,\n allowNull: false,\n })\n modelType!: string; /** Model type. e.g. Vehicle / StopPoint / etc. */\n\n @Column({\n type: DataType.TEXT,\n })\n description?: string;\n\n @Column({\n type: DataType.BOOLEAN,\n defaultValue: false,\n })\n required?: boolean;\n\n @Column({\n type: DataType.BOOLEAN,\n defaultValue: false,\n })\n disabled?: boolean;\n\n @Column({\n type: DataType.JSONB,\n allowNull: true,\n })\n defaultValue?: any;\n\n @Column({\n type: DataType.DATE,\n allowNull: false,\n })\n declare createdAt?: Date;\n\n @Column({\n type: DataType.DATE,\n allowNull: true,\n })\n declare updatedAt?: Date;\n\n @Column({\n type: DataType.DATE,\n allowNull: true,\n })\n declare deletedAt?: Date;\n\n @Column({\n type: DataType.BOOLEAN,\n defaultValue: false,\n allowNull: false,\n })\n blockEditingFromUI!: boolean;\n\n @HasMany(() => CustomFieldValue)\n declare values: CustomFieldValue[];\n\n @BeforeCreate\n static displayNameDefaultValue(instance: CustomFieldDefinition): void {\n if (!instance?.displayName) {\n instance.displayName = instance.name;\n }\n if (![null, undefined].includes(instance.defaultValue)) {\n const isValid = validateValue(instance.defaultValue, instance.fieldType, instance.validation);\n if (isValid.error) {\n throw new InvalidValueError(instance.defaultValue, instance.name, isValid.error);\n }\n }\n }\n\n @AfterSave\n static afterSaveHandler(instance: CustomFieldDefinition, options: CreateOptions): void {\n if (options.transaction) {\n options.transaction.afterCommit(() => sendDimEvent(instance));\n } else {\n sendDimEvent(instance);\n }\n }\n}\n\nexport default CustomFieldDefinition;\n"],"mappings":"22BAqBA,IAAA,EAAA,cAuBoC,CAAM,CAyGxC,OACO,wBAAwB,EAAuC,CAIpE,GAHK,GAAU,cACb,EAAS,YAAc,EAAS,MAE9B,CAAC,CAAC,KAAM,IAAA,GAAU,CAAC,SAAS,EAAS,aAAa,CAAE,CACtD,IAAM,EAAU,EAAc,EAAS,aAAc,EAAS,UAAW,EAAS,WAAW,CAC7F,GAAI,EAAQ,MACV,MAAM,IAAI,EAAkB,EAAS,aA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D,WAAY,GACZ,SAAU,CACR,kBAA8C,CAE5C,GAAI,CAAC,KAAK,YAAc,EAAsB,KAAK,WAGjD,MADA,EAAO,MAAM,8CAA8C,KAAK,UAAU,QAAQ,CAC5E,IAAI,EAAiC,4BAA4B,KAAK,UAAU,oBAAoB,EAG/G,CACF,CAAC,CAAA,CAAA,EAAA,CAiIF,IAAA,EAAe"}
1
+ {"version":3,"file":"CustomFieldDefinition.js","names":["CustomFieldDefinition","CustomFieldValue"],"sources":["../../src/models/CustomFieldDefinition.ts"],"sourcesContent":["import {\n Table,\n Column,\n Model,\n DataType,\n HasMany,\n PrimaryKey,\n BeforeCreate,\n DefaultScope,\n AfterSave,\n Is,\n} from 'sequelize-typescript';\nimport type { CreateOptions } from 'sequelize';\nimport { CustomFieldDefinitionType } from '../utils/constants';\nimport { CustomValidationTypes } from '../utils/validations/validators';\nimport CustomFieldValue from './CustomFieldValue';\nimport { sendDimEvent } from '../events';\nimport { InvalidValueError, UnsupportedCustomFieldTypeError, UnsupportedCustomValidationError } from '../errors';\nimport logger from '../utils/logger';\nimport { validateValue } from '../utils/validations';\n\n@DefaultScope(() => ({ where: { disabled: false } }))\n@Table({\n tableName: 'custom_field_definitions',\n modelName: 'CustomFieldDefinition',\n indexes: [\n {\n name: 'unique_name_model_type',\n fields: ['model_type', 'entity_id', 'name'],\n unique: true,\n },\n ],\n timestamps: true,\n validate: {\n validationByType(this: CustomFieldDefinition) {\n // Verify the validation is provided if needed\n if (!this.validation && CustomValidationTypes[this.fieldType as keyof typeof CustomValidationTypes]) {\n // TODO: enforce the validation-object schema based on the fieldType\n logger.error(`No custom validation for custom field type ${this.fieldType} found`);\n throw new UnsupportedCustomValidationError(`Validation provided for \"${this.fieldType}\" is not supported`);\n }\n },\n },\n})\nclass CustomFieldDefinition 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.STRING,\n allowNull: false,\n })\n name!: string;\n\n @Column({\n type: DataType.STRING,\n })\n displayName?: string; // Defaulted to name with beforeCreate hook\n\n @Is('SupportedType', (value) => {\n if (!Object.values(CustomFieldDefinitionType).includes(value as CustomFieldDefinitionType)) {\n throw new UnsupportedCustomFieldTypeError(`\"${value}\" is not a supported type.`);\n }\n })\n @Column({\n type: DataType.STRING,\n allowNull: false,\n })\n fieldType!: CustomFieldDefinitionType;\n\n @Column({\n type: DataType.JSONB,\n })\n validation?: any;\n\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n entityId!: string; /** Client association entity id */\n\n @Column({\n type: DataType.STRING,\n allowNull: false,\n })\n entityType!: string; /** Client association entity type (demand source / fleet / etc.) */\n\n @Column({\n type: DataType.STRING,\n allowNull: false,\n })\n modelType!: string; /** Model type. e.g. Vehicle / StopPoint / etc. */\n\n @Column({\n type: DataType.TEXT,\n })\n description?: string;\n\n @Column({\n type: DataType.BOOLEAN,\n defaultValue: false,\n })\n required?: boolean;\n\n @Column({\n type: DataType.BOOLEAN,\n defaultValue: false,\n })\n disabled?: boolean;\n\n @Column({\n type: DataType.JSONB,\n allowNull: true,\n })\n defaultValue?: any;\n\n @Column({\n type: DataType.DATE,\n allowNull: false,\n })\n declare createdAt?: Date;\n\n @Column({\n type: DataType.DATE,\n allowNull: true,\n })\n declare updatedAt?: Date;\n\n @Column({\n type: DataType.DATE,\n allowNull: true,\n })\n declare deletedAt?: Date;\n\n @Column({\n type: DataType.BOOLEAN,\n defaultValue: false,\n allowNull: false,\n })\n blockEditingFromUI!: boolean;\n\n @HasMany(() => CustomFieldValue)\n declare values: CustomFieldValue[];\n\n @BeforeCreate\n static displayNameDefaultValue(instance: CustomFieldDefinition): void {\n if (!instance?.displayName) {\n instance.displayName = instance.name;\n }\n if (![null, undefined].includes(instance.defaultValue)) {\n const isValid = validateValue(instance.defaultValue, instance.fieldType, instance.validation);\n if (isValid.error) {\n throw new InvalidValueError(instance.defaultValue, instance.name, isValid.error);\n }\n }\n }\n\n @AfterSave\n static afterSaveHandler(instance: CustomFieldDefinition, options: CreateOptions): void {\n if (options.transaction) {\n options.transaction.afterCommit(() => sendDimEvent(instance));\n } else {\n sendDimEvent(instance);\n }\n }\n}\n\nexport default CustomFieldDefinition;\n"],"mappings":"w1BAqBA,IAAA,EAAA,cAuBoC,CAAM,CAyGxC,OACO,wBAAwB,EAAuC,CAIpE,GAHK,GAAU,cACb,EAAS,YAAc,EAAS,MAE9B,CAAC,CAAC,KAAM,IAAA,GAAU,CAAC,SAAS,EAAS,aAAa,CAAE,CACtD,IAAM,EAAU,EAAc,EAAS,aAAc,EAAS,UAAW,EAAS,WAAW,CAC7F,GAAI,EAAQ,MACV,MAAM,IAAI,EAAkB,EAAS,aAAc,EAAS,KAAM,EAAQ,MAAM,EAKtF,OACO,iBAAiB,EAAiC,EAA8B,CACjF,EAAQ,YACV,EAAQ,YAAY,gBAAkB,EAAa,EAAS,CAAC,CAE7D,EAAa,EAAS,MA1HzB,EACA,EAAO,CACN,KAAM,EAAS,KACf,aAAc,EAAS,OACvB,UAAW,GACZ,CAAC,sDAGD,EAAO,CACN,KAAM,EAAS,OACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,OAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,OAChB,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,cAAA,IAAA,GAAA,IAGD,EAAG,gBAAkB,GAAU,CAC9B,GAAI,CAAC,OAAO,OAAO,EAA0B,CAAC,SAAS,EAAmC,CACxF,MAAM,IAAI,EAAgC,IAAI,EAAM,4BAA4B,EAElF,CACD,EAAO,CACN,KAAM,EAAS,OACf,UAAW,GACZ,CAAC,mGAGD,EAAO,CACN,KAAM,EAAS,MAChB,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,aAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GAC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CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,QACf,aAAc,GACd,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,QAAA,CAAA,CAAA,EAAA,UAAA,qBAAA,IAAA,GAAA,IAGD,MAAcC,EAAiB,CAAA,EAAA,cAAA,MAAA,CAAA,CAAA,EAAA,UAAA,SAAA,IAAA,GAAA,IAG/B,sKAaA,wKA7IF,OAAoB,CAAE,MAAO,CAAE,SAAU,GAAO,CAAE,EAAE,CACpD,EAAM,CACL,UAAW,2BACX,UAAW,wBACX,QAAS,CACP,CACE,KAAM,yBACN,OAAQ,CAAC,aAAc,YAAa,OAAO,CAC3C,OAAQ,GACT,CACF,CACD,WAAY,GACZ,SAAU,CACR,kBAA8C,CAE5C,GAAI,CAAC,KAAK,YAAc,EAAsB,KAAK,WAGjD,MADA,EAAO,MAAM,8CAA8C,KAAK,UAAU,QAAQ,CAC5E,IAAI,EAAiC,4BAA4B,KAAK,UAAU,oBAAoB,EAG/G,CACF,CAAC,CAAA,CAAA,EAAA,CAiIF,IAAA,EAAe"}
@@ -1,2 +1,2 @@
1
- const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../events/index.cjs`),n=require(`../utils/validations/index.cjs`),r=require(`../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.cjs`),i=require(`../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorate.cjs`),a=require(`../repository/definition.cjs`);let o=require(`sequelize-typescript`);var s,c,l;let u=class extends o.Model{static afterSaveHandler(e,n){n.transaction?n.transaction.afterCommit(()=>t.sendDimEvent(e[0])):t.sendDimEvent(e[0])}};i.__decorate([o.PrimaryKey,(0,o.Column)({type:o.DataType.UUID,allowNull:!1}),r.__decorateMetadata(`design:type`,String)],u.prototype,`modelId`,void 0),i.__decorate([(0,o.Column)({type:o.DataType.UUID,allowNull:!1}),r.__decorateMetadata(`design:type`,String)],u.prototype,`entityId`,void 0),i.__decorate([(0,o.Column)({type:o.DataType.JSONB,allowNull:!1,defaultValue:{}}),r.__decorateMetadata(`design:type`,typeof(s=typeof Record<`u`&&Record)==`function`?s:Object)],u.prototype,`customFields`,void 0),i.__decorate([(0,o.Column)({type:o.DataType.STRING,allowNull:!1}),r.__decorateMetadata(`design:type`,String)],u.prototype,`modelType`,void 0),i.__decorate([(0,o.Column)({type:o.DataType.DATE,allowNull:!1}),r.__decorateMetadata(`design:type`,typeof(c=typeof Date<`u`&&Date)==`function`?c:Object)],u.prototype,`createdAt`,void 0),i.__decorate([(0,o.Column)({type:o.DataType.DATE,allowNull:!0}),r.__decorateMetadata(`design:type`,typeof(l=typeof Date<`u`&&Date)==`function`?l:Object)],u.prototype,`updatedAt`,void 0),i.__decorate([o.AfterUpsert,r.__decorateMetadata(`design:type`,Function),r.__decorateMetadata(`design:paramtypes`,[Array,Object]),r.__decorateMetadata(`design:returntype`,void 0)],u,`afterSaveHandler`,null),u=i.__decorate([(0,o.Table)({tableName:`custom_field_entries`,modelName:`CustomFieldEntries`,timestamps:!0,indexes:[{name:`idx_cfe_custom_fields`,using:`gin`,operator:`jsonb_path_ops`,fields:[`custom_fields`]}],validate:{async validationByType(){if(!Object.keys(this.customFields??{}).length)return;let e=await a.getCustomFieldDefinitionsDictionary([this]);n.validateInstanceCustomFieldEntries(this,e)}}})],u);var d=u;exports.default=d;
1
+ const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../events/index.cjs`),n=require(`../utils/validations/index.cjs`),r=require(`../repository/definition.cjs`),i=require(`../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.cjs`),a=require(`../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorate.cjs`);let o=require(`sequelize-typescript`);var s,c,l;let u=class extends o.Model{static afterSaveHandler(e,n){n.transaction?n.transaction.afterCommit(()=>t.sendDimEvent(e[0])):t.sendDimEvent(e[0])}};a.__decorate([o.PrimaryKey,(0,o.Column)({type:o.DataType.UUID,allowNull:!1}),i.__decorateMetadata(`design:type`,String)],u.prototype,`modelId`,void 0),a.__decorate([(0,o.Column)({type:o.DataType.UUID,allowNull:!1}),i.__decorateMetadata(`design:type`,String)],u.prototype,`entityId`,void 0),a.__decorate([(0,o.Column)({type:o.DataType.JSONB,allowNull:!1,defaultValue:{}}),i.__decorateMetadata(`design:type`,typeof(s=typeof Record<`u`&&Record)==`function`?s:Object)],u.prototype,`customFields`,void 0),a.__decorate([(0,o.Column)({type:o.DataType.STRING,allowNull:!1}),i.__decorateMetadata(`design:type`,String)],u.prototype,`modelType`,void 0),a.__decorate([(0,o.Column)({type:o.DataType.DATE,allowNull:!1}),i.__decorateMetadata(`design:type`,typeof(c=typeof Date<`u`&&Date)==`function`?c:Object)],u.prototype,`createdAt`,void 0),a.__decorate([(0,o.Column)({type:o.DataType.DATE,allowNull:!0}),i.__decorateMetadata(`design:type`,typeof(l=typeof Date<`u`&&Date)==`function`?l:Object)],u.prototype,`updatedAt`,void 0),a.__decorate([o.AfterUpsert,i.__decorateMetadata(`design:type`,Function),i.__decorateMetadata(`design:paramtypes`,[Array,Object]),i.__decorateMetadata(`design:returntype`,void 0)],u,`afterSaveHandler`,null),u=a.__decorate([(0,o.Table)({tableName:`custom_field_entries`,modelName:`CustomFieldEntries`,timestamps:!0,indexes:[{name:`idx_cfe_custom_fields`,using:`gin`,operator:`jsonb_path_ops`,fields:[`custom_fields`]}],validate:{async validationByType(){if(!Object.keys(this.customFields??{}).length)return;let e=await r.getCustomFieldDefinitionsDictionary([this]);n.validateInstanceCustomFieldEntries(this,e)}}})],u);var d=u;exports.default=d;
2
2
  //# sourceMappingURL=CustomFieldEntries.cjs.map
@@ -1,2 +1,2 @@
1
- import{sendDimEvent as e}from"../events/index.js";import{validateInstanceCustomFieldEntries as t}from"../utils/validations/index.js";import{__decorateMetadata as n}from"../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.js";import{__decorate as r}from"../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorate.js";import{getCustomFieldDefinitionsDictionary as i}from"../repository/definition.js";import{AfterUpsert as a,Column as o,DataType as s,Model as c,PrimaryKey as l,Table as u}from"sequelize-typescript";var d,f,p;let m=class extends c{static afterSaveHandler(t,n){n.transaction?n.transaction.afterCommit(()=>e(t[0])):e(t[0])}};r([l,o({type:s.UUID,allowNull:!1}),n(`design:type`,String)],m.prototype,`modelId`,void 0),r([o({type:s.UUID,allowNull:!1}),n(`design:type`,String)],m.prototype,`entityId`,void 0),r([o({type:s.JSONB,allowNull:!1,defaultValue:{}}),n(`design:type`,typeof(d=typeof Record<`u`&&Record)==`function`?d:Object)],m.prototype,`customFields`,void 0),r([o({type:s.STRING,allowNull:!1}),n(`design:type`,String)],m.prototype,`modelType`,void 0),r([o({type:s.DATE,allowNull:!1}),n(`design:type`,typeof(f=typeof Date<`u`&&Date)==`function`?f:Object)],m.prototype,`createdAt`,void 0),r([o({type:s.DATE,allowNull:!0}),n(`design:type`,typeof(p=typeof Date<`u`&&Date)==`function`?p:Object)],m.prototype,`updatedAt`,void 0),r([a,n(`design:type`,Function),n(`design:paramtypes`,[Array,Object]),n(`design:returntype`,void 0)],m,`afterSaveHandler`,null),m=r([u({tableName:`custom_field_entries`,modelName:`CustomFieldEntries`,timestamps:!0,indexes:[{name:`idx_cfe_custom_fields`,using:`gin`,operator:`jsonb_path_ops`,fields:[`custom_fields`]}],validate:{async validationByType(){if(!Object.keys(this.customFields??{}).length)return;let e=await i([this]);t(this,e)}}})],m);var h=m;export{h as default};
1
+ import{sendDimEvent as e}from"../events/index.js";import{validateInstanceCustomFieldEntries as t}from"../utils/validations/index.js";import{getCustomFieldDefinitionsDictionary as n}from"../repository/definition.js";import{__decorateMetadata as r}from"../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.js";import{__decorate as i}from"../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorate.js";import{AfterUpsert as a,Column as o,DataType as s,Model as c,PrimaryKey as l,Table as u}from"sequelize-typescript";var d,f,p;let m=class extends c{static afterSaveHandler(t,n){n.transaction?n.transaction.afterCommit(()=>e(t[0])):e(t[0])}};i([l,o({type:s.UUID,allowNull:!1}),r(`design:type`,String)],m.prototype,`modelId`,void 0),i([o({type:s.UUID,allowNull:!1}),r(`design:type`,String)],m.prototype,`entityId`,void 0),i([o({type:s.JSONB,allowNull:!1,defaultValue:{}}),r(`design:type`,typeof(d=typeof Record<`u`&&Record)==`function`?d:Object)],m.prototype,`customFields`,void 0),i([o({type:s.STRING,allowNull:!1}),r(`design:type`,String)],m.prototype,`modelType`,void 0),i([o({type:s.DATE,allowNull:!1}),r(`design:type`,typeof(f=typeof Date<`u`&&Date)==`function`?f:Object)],m.prototype,`createdAt`,void 0),i([o({type:s.DATE,allowNull:!0}),r(`design:type`,typeof(p=typeof Date<`u`&&Date)==`function`?p:Object)],m.prototype,`updatedAt`,void 0),i([a,r(`design:type`,Function),r(`design:paramtypes`,[Array,Object]),r(`design:returntype`,void 0)],m,`afterSaveHandler`,null),m=i([u({tableName:`custom_field_entries`,modelName:`CustomFieldEntries`,timestamps:!0,indexes:[{name:`idx_cfe_custom_fields`,using:`gin`,operator:`jsonb_path_ops`,fields:[`custom_fields`]}],validate:{async validationByType(){if(!Object.keys(this.customFields??{}).length)return;let e=await n([this]);t(this,e)}}})],m);var h=m;export{h as default};
2
2
  //# sourceMappingURL=CustomFieldEntries.js.map
@@ -1,2 +1,2 @@
1
- const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../events/index.cjs`),n=require(`../errors/index.cjs`),r=require(`../utils/validations/index.cjs`),i=require(`../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.cjs`),a=require(`../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorate.cjs`),o=require(`./CustomFieldDefinition.cjs`),s=require(`../repository/definition.cjs`);require(`./index.cjs`);let c=require(`sequelize-typescript`);var l,u,d,f,p;let m=class extends c.Model{static validateValueAgainstDefinition(e,t){let{validation:i,fieldType:a,name:o}=t;if(!r.validateFieldType(a))throw new n.InvalidFieldTypeError(a);if(e.value===null)return;let s=r.validateValue(e.value,a,i);if(s.error)throw new n.InvalidValueError(e.value,o,s.error)}static async validateCustomFieldValues(e){let t=e.map(e=>e.customFieldDefinitionId),n=[...new Set(t)],r=await s.findByIds(n,{withDisabled:!0});if(!r||r.length!==n.length)throw Error(`Definitions not found`);e.forEach(e=>{let t=r.find(t=>t.id===e.customFieldDefinitionId);t&&this.validateValueAgainstDefinition(e,t)})}static async validateCustomFieldValue(e){let{customFieldDefinitionId:t}=e,n=await s.findById(t,{withDisabled:!0});this.validateValueAgainstDefinition(e,n)}static afterSaveHandler(e,n){n.transaction?n.transaction.afterCommit(()=>t.sendDimEvent(e[0])):t.sendDimEvent(e[0])}};a.__decorate([c.PrimaryKey,(0,c.Column)({type:c.DataType.UUID,allowNull:!1}),i.__decorateMetadata(`design:type`,String)],m.prototype,`modelId`,void 0),a.__decorate([c.PrimaryKey,(0,c.ForeignKey)(()=>o.default),(0,c.Column)({type:c.DataType.UUID,allowNull:!1}),i.__decorateMetadata(`design:type`,String)],m.prototype,`customFieldDefinitionId`,void 0),a.__decorate([(0,c.Column)({type:c.DataType.JSONB,allowNull:!0}),i.__decorateMetadata(`design:type`,Object)],m.prototype,`value`,void 0),a.__decorate([(0,c.Column)({type:c.DataType.DATE,allowNull:!1}),i.__decorateMetadata(`design:type`,typeof(l=typeof Date<`u`&&Date)==`function`?l:Object)],m.prototype,`createdAt`,void 0),a.__decorate([(0,c.Column)({type:c.DataType.DATE,allowNull:!0}),i.__decorateMetadata(`design:type`,typeof(u=typeof Date<`u`&&Date)==`function`?u:Object)],m.prototype,`updatedAt`,void 0),a.__decorate([(0,c.Column)({type:c.DataType.DATE,allowNull:!0}),i.__decorateMetadata(`design:type`,typeof(d=typeof Date<`u`&&Date)==`function`?d:Object)],m.prototype,`deletedAt`,void 0),a.__decorate([(0,c.BelongsTo)(()=>o.default,{scope:{disabled:!1}}),i.__decorateMetadata(`design:type`,typeof(f=o.default!==void 0&&o.default)==`function`?f:Object)],m.prototype,`customFieldDefinition`,void 0),a.__decorate([c.BeforeBulkCreate,c.BeforeBulkUpdate,i.__decorateMetadata(`design:type`,Function),i.__decorateMetadata(`design:paramtypes`,[Array]),i.__decorateMetadata(`design:returntype`,Promise)],m,`validateCustomFieldValues`,null),a.__decorate([c.BeforeUpdate,c.BeforeCreate,c.BeforeUpsert,i.__decorateMetadata(`design:type`,Function),i.__decorateMetadata(`design:paramtypes`,[typeof(p=m!==void 0&&m)==`function`?p:Object]),i.__decorateMetadata(`design:returntype`,Promise)],m,`validateCustomFieldValue`,null),a.__decorate([c.AfterUpsert,i.__decorateMetadata(`design:type`,Function),i.__decorateMetadata(`design:paramtypes`,[Array,Object]),i.__decorateMetadata(`design:returntype`,void 0)],m,`afterSaveHandler`,null),m=a.__decorate([(0,c.Table)({tableName:`custom_field_values`,modelName:`CustomFieldValue`,timestamps:!0})],m);var h=m;exports.default=h;
1
+ const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../events/index.cjs`),n=require(`../errors/index.cjs`),r=require(`../utils/validations/index.cjs`),i=require(`../repository/definition.cjs`),a=require(`../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.cjs`),o=require(`../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorate.cjs`),s=require(`./CustomFieldDefinition.cjs`);let c=require(`sequelize-typescript`);var l,u,d,f,p;let m=class extends c.Model{static validateValueAgainstDefinition(e,t){let{validation:i,fieldType:a,name:o}=t;if(!r.validateFieldType(a))throw new n.InvalidFieldTypeError(a);if(e.value===null)return;let s=r.validateValue(e.value,a,i);if(s.error)throw new n.InvalidValueError(e.value,o,s.error)}static async validateCustomFieldValues(e){let t=e.map(e=>e.customFieldDefinitionId),n=[...new Set(t)],r=await i.findByIds(n,{withDisabled:!0});if(!r||r.length!==n.length)throw Error(`Definitions not found`);e.forEach(e=>{let t=r.find(t=>t.id===e.customFieldDefinitionId);t&&this.validateValueAgainstDefinition(e,t)})}static async validateCustomFieldValue(e){let{customFieldDefinitionId:t}=e,n=await i.findById(t,{withDisabled:!0});this.validateValueAgainstDefinition(e,n)}static afterSaveHandler(e,n){n.transaction?n.transaction.afterCommit(()=>t.sendDimEvent(e[0])):t.sendDimEvent(e[0])}};o.__decorate([c.PrimaryKey,(0,c.Column)({type:c.DataType.UUID,allowNull:!1}),a.__decorateMetadata(`design:type`,String)],m.prototype,`modelId`,void 0),o.__decorate([c.PrimaryKey,(0,c.ForeignKey)(()=>s.default),(0,c.Column)({type:c.DataType.UUID,allowNull:!1}),a.__decorateMetadata(`design:type`,String)],m.prototype,`customFieldDefinitionId`,void 0),o.__decorate([(0,c.Column)({type:c.DataType.JSONB,allowNull:!0}),a.__decorateMetadata(`design:type`,Object)],m.prototype,`value`,void 0),o.__decorate([(0,c.Column)({type:c.DataType.DATE,allowNull:!1}),a.__decorateMetadata(`design:type`,typeof(l=typeof Date<`u`&&Date)==`function`?l:Object)],m.prototype,`createdAt`,void 0),o.__decorate([(0,c.Column)({type:c.DataType.DATE,allowNull:!0}),a.__decorateMetadata(`design:type`,typeof(u=typeof Date<`u`&&Date)==`function`?u:Object)],m.prototype,`updatedAt`,void 0),o.__decorate([(0,c.Column)({type:c.DataType.DATE,allowNull:!0}),a.__decorateMetadata(`design:type`,typeof(d=typeof Date<`u`&&Date)==`function`?d:Object)],m.prototype,`deletedAt`,void 0),o.__decorate([(0,c.BelongsTo)(()=>s.default,{scope:{disabled:!1}}),a.__decorateMetadata(`design:type`,typeof(f=s.default!==void 0&&s.default)==`function`?f:Object)],m.prototype,`customFieldDefinition`,void 0),o.__decorate([c.BeforeBulkCreate,c.BeforeBulkUpdate,a.__decorateMetadata(`design:type`,Function),a.__decorateMetadata(`design:paramtypes`,[Array]),a.__decorateMetadata(`design:returntype`,Promise)],m,`validateCustomFieldValues`,null),o.__decorate([c.BeforeUpdate,c.BeforeCreate,c.BeforeUpsert,a.__decorateMetadata(`design:type`,Function),a.__decorateMetadata(`design:paramtypes`,[typeof(p=m!==void 0&&m)==`function`?p:Object]),a.__decorateMetadata(`design:returntype`,Promise)],m,`validateCustomFieldValue`,null),o.__decorate([c.AfterUpsert,a.__decorateMetadata(`design:type`,Function),a.__decorateMetadata(`design:paramtypes`,[Array,Object]),a.__decorateMetadata(`design:returntype`,void 0)],m,`afterSaveHandler`,null),m=o.__decorate([(0,c.Table)({tableName:`custom_field_values`,modelName:`CustomFieldValue`,timestamps:!0})],m);var h=m;exports.default=h;
2
2
  //# sourceMappingURL=CustomFieldValue.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"CustomFieldValue.cjs","names":["CustomFieldValue","Model","validateFieldType","InvalidFieldTypeError","validateValue","InvalidValueError","sendDimEvent","PrimaryKey","DataType","CustomFieldDefinition","BeforeBulkCreate","BeforeBulkUpdate","BeforeUpdate","BeforeCreate","BeforeUpsert","AfterUpsert"],"sources":["../../src/models/CustomFieldValue.ts"],"sourcesContent":["import {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n BelongsTo,\n ForeignKey,\n BeforeCreate,\n BeforeUpsert,\n AfterUpsert,\n BeforeUpdate,\n BeforeBulkCreate,\n BeforeBulkUpdate,\n} from 'sequelize-typescript';\nimport type { CreateOptions } from 'sequelize';\nimport { sendDimEvent } from '../events';\nimport { CustomFieldDefinition } from '.';\nimport { validateFieldType, validateValue } from '../utils/validations';\nimport * as CustomFieldDefinitionRepo from '../repository/definition';\nimport { InvalidFieldTypeError, InvalidValueError } from '../errors';\n\n@Table({\n tableName: 'custom_field_values',\n modelName: 'CustomFieldValue',\n timestamps: true,\n})\nclass CustomFieldValue extends Model {\n @PrimaryKey\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n modelId!: string;\n\n @PrimaryKey\n @ForeignKey(() => CustomFieldDefinition)\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n customFieldDefinitionId!: string;\n\n @Column({\n type: DataType.JSONB,\n allowNull: true,\n })\n value!: any;\n\n @Column({\n type: DataType.DATE,\n allowNull: false,\n })\n declare createdAt?: Date;\n\n @Column({\n type: DataType.DATE,\n allowNull: true,\n })\n declare updatedAt?: Date;\n\n @Column({\n type: DataType.DATE,\n allowNull: true,\n })\n declare deletedAt?: Date;\n\n @BelongsTo(() => CustomFieldDefinition, { scope: { disabled: false } })\n declare customFieldDefinition: CustomFieldDefinition;\n\n private static validateValueAgainstDefinition(\n instance: CustomFieldValue,\n definition: CustomFieldDefinition,\n ): void {\n const { validation, fieldType, name } = definition;\n const isValidFieldType = validateFieldType(fieldType);\n if (!isValidFieldType) {\n throw new InvalidFieldTypeError(fieldType);\n }\n // Always allow null values\n if (instance.value === null) return;\n const validateValueResponse = validateValue(instance.value, fieldType, validation);\n if (validateValueResponse.error) {\n throw new InvalidValueError(instance.value, name, validateValueResponse.error);\n }\n }\n\n @BeforeBulkCreate\n @BeforeBulkUpdate\n static async validateCustomFieldValues(instances: CustomFieldValue[]): Promise<void> {\n const ids = instances.map(instance => instance.customFieldDefinitionId);\n const uniqueIds = [...new Set(ids)];\n const definitions = await CustomFieldDefinitionRepo.findByIds(\n uniqueIds,\n { withDisabled: true },\n );\n\n if (!definitions || definitions.length !== uniqueIds.length) {\n throw new Error('Definitions not found');\n }\n\n instances.forEach((instance) => {\n const definition = definitions.find(d => d.id === instance.customFieldDefinitionId);\n if (definition) {\n this.validateValueAgainstDefinition(instance, definition);\n }\n });\n }\n\n @BeforeUpdate\n @BeforeCreate\n @BeforeUpsert\n static async validateCustomFieldValue(instance: CustomFieldValue): Promise<void> {\n const { customFieldDefinitionId } = instance;\n const cfd = await CustomFieldDefinitionRepo.findById(customFieldDefinitionId, { withDisabled: true });\n this.validateValueAgainstDefinition(instance, cfd!);\n }\n\n @AfterUpsert\n static afterSaveHandler(instance: CustomFieldValue[], options: CreateOptions): void {\n if (options.transaction) {\n options.transaction.afterCommit(() => sendDimEvent(instance[0]));\n } else {\n sendDimEvent(instance[0]);\n }\n }\n}\n\nexport default CustomFieldValue;\n"],"mappings":"geAsBA,IAAA,EAAA,cAK+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ACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,QAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,EAAA,OAAA,KAAA,KAAA,OAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,EAAA,OAAA,KAAA,KAAA,OAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,EAAA,OAAA,KAAA,KAAA,OAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,mCAGeC,EAAAA,QAAuB,CAAE,MAAO,CAAE,SAAU,GAAO,CAAE,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,EAAA,EAAA,UAAA,QAAA,EAAA,UAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,wBAAA,IAAA,GAAA,eAoBtEC,EAAAA,iBACAC,EAAAA,qNAqBAC,EAAAA,aACAC,EAAAA,aACAC,EAAAA,uPAOAC,EAAAA,2NAhGI,CACL,UAAW,sBACX,UAAW,mBACX,WAAY,GACb,CAAC,CAAA,CAAA,EAAA,CAsGF,IAAA,EAAe"}
1
+ {"version":3,"file":"CustomFieldValue.cjs","names":["CustomFieldValue","Model","validateFieldType","InvalidFieldTypeError","validateValue","InvalidValueError","sendDimEvent","PrimaryKey","DataType","CustomFieldDefinition","BeforeBulkCreate","BeforeBulkUpdate","BeforeUpdate","BeforeCreate","BeforeUpsert","AfterUpsert"],"sources":["../../src/models/CustomFieldValue.ts"],"sourcesContent":["import {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n BelongsTo,\n ForeignKey,\n BeforeCreate,\n BeforeUpsert,\n AfterUpsert,\n BeforeUpdate,\n BeforeBulkCreate,\n BeforeBulkUpdate,\n} from 'sequelize-typescript';\nimport type { CreateOptions } from 'sequelize';\nimport { sendDimEvent } from '../events';\nimport CustomFieldDefinition from './CustomFieldDefinition';\nimport { validateFieldType, validateValue } from '../utils/validations';\nimport * as CustomFieldDefinitionRepo from '../repository/definition';\nimport { InvalidFieldTypeError, InvalidValueError } from '../errors';\n\n@Table({\n tableName: 'custom_field_values',\n modelName: 'CustomFieldValue',\n timestamps: true,\n})\nclass CustomFieldValue extends Model {\n @PrimaryKey\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n modelId!: string;\n\n @PrimaryKey\n @ForeignKey(() => CustomFieldDefinition)\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n customFieldDefinitionId!: string;\n\n @Column({\n type: DataType.JSONB,\n allowNull: true,\n })\n value!: any;\n\n @Column({\n type: DataType.DATE,\n allowNull: false,\n })\n declare createdAt?: Date;\n\n @Column({\n type: DataType.DATE,\n allowNull: true,\n })\n declare updatedAt?: Date;\n\n @Column({\n type: DataType.DATE,\n allowNull: true,\n })\n declare deletedAt?: Date;\n\n @BelongsTo(() => CustomFieldDefinition, { scope: { disabled: false } })\n declare customFieldDefinition: CustomFieldDefinition;\n\n private static validateValueAgainstDefinition(\n instance: CustomFieldValue,\n definition: CustomFieldDefinition,\n ): void {\n const { validation, fieldType, name } = definition;\n const isValidFieldType = validateFieldType(fieldType);\n if (!isValidFieldType) {\n throw new InvalidFieldTypeError(fieldType);\n }\n // Always allow null values\n if (instance.value === null) return;\n const validateValueResponse = validateValue(instance.value, fieldType, validation);\n if (validateValueResponse.error) {\n throw new InvalidValueError(instance.value, name, validateValueResponse.error);\n }\n }\n\n @BeforeBulkCreate\n @BeforeBulkUpdate\n static async validateCustomFieldValues(instances: CustomFieldValue[]): Promise<void> {\n const ids = instances.map(instance => instance.customFieldDefinitionId);\n const uniqueIds = [...new Set(ids)];\n const definitions = await CustomFieldDefinitionRepo.findByIds(\n uniqueIds,\n { withDisabled: true },\n );\n\n if (!definitions || definitions.length !== uniqueIds.length) {\n throw new Error('Definitions not found');\n }\n\n instances.forEach((instance) => {\n const definition = definitions.find(d => d.id === instance.customFieldDefinitionId);\n if (definition) {\n this.validateValueAgainstDefinition(instance, definition);\n }\n });\n }\n\n @BeforeUpdate\n @BeforeCreate\n @BeforeUpsert\n static async validateCustomFieldValue(instance: CustomFieldValue): Promise<void> {\n const { customFieldDefinitionId } = instance;\n const cfd = await CustomFieldDefinitionRepo.findById(customFieldDefinitionId, { withDisabled: true });\n this.validateValueAgainstDefinition(instance, cfd!);\n }\n\n @AfterUpsert\n static afterSaveHandler(instance: CustomFieldValue[], options: CreateOptions): void {\n if (options.transaction) {\n options.transaction.afterCommit(() => sendDimEvent(instance[0]));\n } else {\n sendDimEvent(instance[0]);\n }\n }\n}\n\nexport default CustomFieldValue;\n"],"mappings":"ycAsBA,IAAA,EAAA,cAK+BC,EAAAA,KAAM,CA2CnC,OAAe,+BACb,EACA,EACM,CACN,GAAM,CAAE,aAAY,YAAW,QAAS,EAExC,GAAI,CADqBC,EAAAA,kBAAkB,EAAU,CAEnD,MAAM,IAAIC,EAAAA,sBAAsB,EAAU,CAG5C,GAAI,EAAS,QAAU,KAAM,OAC7B,IAAM,EAAwBC,EAAAA,cAAc,EAAS,MAAO,EAAW,EAAW,CAClF,GAAI,EAAsB,MACxB,MAAM,IAAIC,EAAAA,kBAAkB,EAAS,MAAO,EAAM,EAAsB,MAAM,CAIlF,aAEa,0BAA0B,EAA8C,CACnF,IAAM,EAAM,EAAU,IAAI,GAAY,EAAS,wBAAwB,CACjE,EAAY,CAAC,GAAG,IAAI,IAAI,EAAI,CAAC,CAC7B,EAAc,MAAA,EAAA,UAClB,EACA,CAAE,aAAc,GAAM,CACvB,CAED,GAAI,CAAC,GAAe,EAAY,SA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,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,mCAGeC,EAAAA,QAAuB,CAAE,MAAO,CAAE,SAAU,GAAO,CAAE,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,EAAA,EAAA,UAAA,QAAA,EAAA,UAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,wBAAA,IAAA,GAAA,eAoBtEC,EAAAA,iBACAC,EAAAA,qNAqBAC,EAAAA,aACAC,EAAAA,aACAC,EAAAA,uPAOAC,EAAAA,2NAhGI,CACL,UAAW,sBACX,UAAW,mBACX,WAAY,GACb,CAAC,CAAA,CAAA,EAAA,CAsGF,IAAA,EAAe"}
@@ -1,4 +1,3 @@
1
- import "./index.cjs";
2
1
  import { CustomFieldDefinition } from "./CustomFieldDefinition.cjs";
3
2
  import { Model } from "sequelize-typescript";
4
3
  import { CreateOptions } from "sequelize";
@@ -1,4 +1,3 @@
1
- import "./index.js";
2
1
  import { CustomFieldDefinition } from "./CustomFieldDefinition.js";
3
2
  import { CreateOptions } from "sequelize";
4
3
  import { Model } from "sequelize-typescript";
@@ -1,2 +1,2 @@
1
- import{sendDimEvent as e}from"../events/index.js";import{InvalidFieldTypeError as t,InvalidValueError as n}from"../errors/index.js";import{validateFieldType as r,validateValue as i}from"../utils/validations/index.js";import{__decorateMetadata as a}from"../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.js";import{__decorate as o}from"../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorate.js";import s from"./CustomFieldDefinition.js";import{findById as c,findByIds as l}from"../repository/definition.js";import"./index.js";import{AfterUpsert as u,BeforeBulkCreate as d,BeforeBulkUpdate as f,BeforeCreate as p,BeforeUpdate as m,BeforeUpsert as h,BelongsTo as g,Column as _,DataType as v,ForeignKey as y,Model as b,PrimaryKey as x,Table as S}from"sequelize-typescript";var C,w,T,E,D;let O=class extends b{static validateValueAgainstDefinition(e,a){let{validation:o,fieldType:s,name:c}=a;if(!r(s))throw new t(s);if(e.value===null)return;let l=i(e.value,s,o);if(l.error)throw new n(e.value,c,l.error)}static async validateCustomFieldValues(e){let t=e.map(e=>e.customFieldDefinitionId),n=[...new Set(t)],r=await l(n,{withDisabled:!0});if(!r||r.length!==n.length)throw Error(`Definitions not found`);e.forEach(e=>{let t=r.find(t=>t.id===e.customFieldDefinitionId);t&&this.validateValueAgainstDefinition(e,t)})}static async validateCustomFieldValue(e){let{customFieldDefinitionId:t}=e,n=await c(t,{withDisabled:!0});this.validateValueAgainstDefinition(e,n)}static afterSaveHandler(t,n){n.transaction?n.transaction.afterCommit(()=>e(t[0])):e(t[0])}};o([x,_({type:v.UUID,allowNull:!1}),a(`design:type`,String)],O.prototype,`modelId`,void 0),o([x,y(()=>s),_({type:v.UUID,allowNull:!1}),a(`design:type`,String)],O.prototype,`customFieldDefinitionId`,void 0),o([_({type:v.JSONB,allowNull:!0}),a(`design:type`,Object)],O.prototype,`value`,void 0),o([_({type:v.DATE,allowNull:!1}),a(`design:type`,typeof(C=typeof Date<`u`&&Date)==`function`?C:Object)],O.prototype,`createdAt`,void 0),o([_({type:v.DATE,allowNull:!0}),a(`design:type`,typeof(w=typeof Date<`u`&&Date)==`function`?w:Object)],O.prototype,`updatedAt`,void 0),o([_({type:v.DATE,allowNull:!0}),a(`design:type`,typeof(T=typeof Date<`u`&&Date)==`function`?T:Object)],O.prototype,`deletedAt`,void 0),o([g(()=>s,{scope:{disabled:!1}}),a(`design:type`,typeof(E=s!==void 0&&s)==`function`?E:Object)],O.prototype,`customFieldDefinition`,void 0),o([d,f,a(`design:type`,Function),a(`design:paramtypes`,[Array]),a(`design:returntype`,Promise)],O,`validateCustomFieldValues`,null),o([m,p,h,a(`design:type`,Function),a(`design:paramtypes`,[typeof(D=O!==void 0&&O)==`function`?D:Object]),a(`design:returntype`,Promise)],O,`validateCustomFieldValue`,null),o([u,a(`design:type`,Function),a(`design:paramtypes`,[Array,Object]),a(`design:returntype`,void 0)],O,`afterSaveHandler`,null),O=o([S({tableName:`custom_field_values`,modelName:`CustomFieldValue`,timestamps:!0})],O);var k=O;export{k as default};
1
+ import{sendDimEvent as e}from"../events/index.js";import{InvalidFieldTypeError as t,InvalidValueError as n}from"../errors/index.js";import{validateFieldType as r,validateValue as i}from"../utils/validations/index.js";import{findById as a,findByIds as o}from"../repository/definition.js";import{__decorateMetadata as s}from"../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.js";import{__decorate as c}from"../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorate.js";import l from"./CustomFieldDefinition.js";import{AfterUpsert as u,BeforeBulkCreate as d,BeforeBulkUpdate as f,BeforeCreate as p,BeforeUpdate as m,BeforeUpsert as h,BelongsTo as g,Column as _,DataType as v,ForeignKey as y,Model as b,PrimaryKey as x,Table as S}from"sequelize-typescript";var C,w,T,E,D;let O=class extends b{static validateValueAgainstDefinition(e,a){let{validation:o,fieldType:s,name:c}=a;if(!r(s))throw new t(s);if(e.value===null)return;let l=i(e.value,s,o);if(l.error)throw new n(e.value,c,l.error)}static async validateCustomFieldValues(e){let t=e.map(e=>e.customFieldDefinitionId),n=[...new Set(t)],r=await o(n,{withDisabled:!0});if(!r||r.length!==n.length)throw Error(`Definitions not found`);e.forEach(e=>{let t=r.find(t=>t.id===e.customFieldDefinitionId);t&&this.validateValueAgainstDefinition(e,t)})}static async validateCustomFieldValue(e){let{customFieldDefinitionId:t}=e,n=await a(t,{withDisabled:!0});this.validateValueAgainstDefinition(e,n)}static afterSaveHandler(t,n){n.transaction?n.transaction.afterCommit(()=>e(t[0])):e(t[0])}};c([x,_({type:v.UUID,allowNull:!1}),s(`design:type`,String)],O.prototype,`modelId`,void 0),c([x,y(()=>l),_({type:v.UUID,allowNull:!1}),s(`design:type`,String)],O.prototype,`customFieldDefinitionId`,void 0),c([_({type:v.JSONB,allowNull:!0}),s(`design:type`,Object)],O.prototype,`value`,void 0),c([_({type:v.DATE,allowNull:!1}),s(`design:type`,typeof(C=typeof Date<`u`&&Date)==`function`?C:Object)],O.prototype,`createdAt`,void 0),c([_({type:v.DATE,allowNull:!0}),s(`design:type`,typeof(w=typeof Date<`u`&&Date)==`function`?w:Object)],O.prototype,`updatedAt`,void 0),c([_({type:v.DATE,allowNull:!0}),s(`design:type`,typeof(T=typeof Date<`u`&&Date)==`function`?T:Object)],O.prototype,`deletedAt`,void 0),c([g(()=>l,{scope:{disabled:!1}}),s(`design:type`,typeof(E=l!==void 0&&l)==`function`?E:Object)],O.prototype,`customFieldDefinition`,void 0),c([d,f,s(`design:type`,Function),s(`design:paramtypes`,[Array]),s(`design:returntype`,Promise)],O,`validateCustomFieldValues`,null),c([m,p,h,s(`design:type`,Function),s(`design:paramtypes`,[typeof(D=O!==void 0&&O)==`function`?D:Object]),s(`design:returntype`,Promise)],O,`validateCustomFieldValue`,null),c([u,s(`design:type`,Function),s(`design:paramtypes`,[Array,Object]),s(`design:returntype`,void 0)],O,`afterSaveHandler`,null),O=c([S({tableName:`custom_field_values`,modelName:`CustomFieldValue`,timestamps:!0})],O);var k=O;export{k as default};
2
2
  //# sourceMappingURL=CustomFieldValue.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CustomFieldValue.js","names":["CustomFieldValue","CustomFieldDefinitionRepo.findByIds","CustomFieldDefinitionRepo.findById","CustomFieldDefinition"],"sources":["../../src/models/CustomFieldValue.ts"],"sourcesContent":["import {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n BelongsTo,\n ForeignKey,\n BeforeCreate,\n BeforeUpsert,\n AfterUpsert,\n BeforeUpdate,\n BeforeBulkCreate,\n BeforeBulkUpdate,\n} from 'sequelize-typescript';\nimport type { CreateOptions } from 'sequelize';\nimport { sendDimEvent } from '../events';\nimport { CustomFieldDefinition } from '.';\nimport { validateFieldType, validateValue } from '../utils/validations';\nimport * as CustomFieldDefinitionRepo from '../repository/definition';\nimport { InvalidFieldTypeError, InvalidValueError } from '../errors';\n\n@Table({\n tableName: 'custom_field_values',\n modelName: 'CustomFieldValue',\n timestamps: true,\n})\nclass CustomFieldValue extends Model {\n @PrimaryKey\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n modelId!: string;\n\n @PrimaryKey\n @ForeignKey(() => CustomFieldDefinition)\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n customFieldDefinitionId!: string;\n\n @Column({\n type: DataType.JSONB,\n allowNull: true,\n })\n value!: any;\n\n @Column({\n type: DataType.DATE,\n allowNull: false,\n })\n declare createdAt?: Date;\n\n @Column({\n type: DataType.DATE,\n allowNull: true,\n })\n declare updatedAt?: Date;\n\n @Column({\n type: DataType.DATE,\n allowNull: true,\n })\n declare deletedAt?: Date;\n\n @BelongsTo(() => CustomFieldDefinition, { scope: { disabled: false } })\n declare customFieldDefinition: CustomFieldDefinition;\n\n private static validateValueAgainstDefinition(\n instance: CustomFieldValue,\n definition: CustomFieldDefinition,\n ): void {\n const { validation, fieldType, name } = definition;\n const isValidFieldType = validateFieldType(fieldType);\n if (!isValidFieldType) {\n throw new InvalidFieldTypeError(fieldType);\n }\n // Always allow null values\n if (instance.value === null) return;\n const validateValueResponse = validateValue(instance.value, fieldType, validation);\n if (validateValueResponse.error) {\n throw new InvalidValueError(instance.value, name, validateValueResponse.error);\n }\n }\n\n @BeforeBulkCreate\n @BeforeBulkUpdate\n static async validateCustomFieldValues(instances: CustomFieldValue[]): Promise<void> {\n const ids = instances.map(instance => instance.customFieldDefinitionId);\n const uniqueIds = [...new Set(ids)];\n const definitions = await CustomFieldDefinitionRepo.findByIds(\n uniqueIds,\n { withDisabled: true },\n );\n\n if (!definitions || definitions.length !== uniqueIds.length) {\n throw new Error('Definitions not found');\n }\n\n instances.forEach((instance) => {\n const definition = definitions.find(d => d.id === instance.customFieldDefinitionId);\n if (definition) {\n this.validateValueAgainstDefinition(instance, definition);\n }\n });\n }\n\n @BeforeUpdate\n @BeforeCreate\n @BeforeUpsert\n static async validateCustomFieldValue(instance: CustomFieldValue): Promise<void> {\n const { customFieldDefinitionId } = instance;\n const cfd = await CustomFieldDefinitionRepo.findById(customFieldDefinitionId, { withDisabled: true });\n this.validateValueAgainstDefinition(instance, cfd!);\n }\n\n @AfterUpsert\n static afterSaveHandler(instance: CustomFieldValue[], options: CreateOptions): void {\n if (options.transaction) {\n options.transaction.afterCommit(() => sendDimEvent(instance[0]));\n } else {\n sendDimEvent(instance[0]);\n }\n }\n}\n\nexport default CustomFieldValue;\n"],"mappings":"oyBAsBA,IAAA,EAAA,cAK+B,CAAM,CA2CnC,OAAe,+BACb,EACA,EACM,CACN,GAAM,CAAE,aAAY,YAAW,QAAS,EAExC,GAAI,CADqB,EAAkB,EAAU,CAEnD,MAAM,IAAI,EAAsB,EAAU,CAG5C,GAAI,EAAS,QAAU,KAAM,OAC7B,IAAM,EAAwB,EAAc,EAAS,MAAO,EAAW,EAAW,CAClF,GAAI,EAAsB,MACxB,MAAM,IAAI,EAAkB,EAAS,MAAO,EAAM,EAAsB,MAAM,CAIlF,aAEa,0BAA0B,EAA8C,CACnF,IAAM,EAAM,EAAU,IAAI,GAAY,EAAS,wBAAwB,CACjE,EAAY,CAAC,GAAG,IAAI,IAAI,EAAI,CAAC,CAC7B,EAAc,MAAMC,EACxB,EACA,CAAE,aAAc,GAAM,CACvB,CAED,GAAI,CAAC,GAAe,EAAY,SAAW,EAAU,OACnD,MAAU,MAAM,wBAAwB,CAG1C,EAAU,QAAS,GAAa,CAC9B,IAAM,EAAa,EAAY,KAAK,GAAK,EAAE,KAAO,EAAS,wBAAwB,CAC/E,GACF,KAAK,+BAA+B,EAAU,EAAW,EAE3D,CAGJ,aAGa,yBAAyB,EAA2C,CAC/E,GAAM,CAAE,2BAA4B,EAC9B,EAAM,MAAMC,EAAmC,EAAyB,CAAE,aAAc,GAAM,CAAC,CACrG,KAAK,+BAA+B,EAAU,EAAK,CAGrD,OACO,iBAAiB,EAA8B,EAA8B,CAC9E,EAAQ,YACV,EAAQ,YAAY,gBAAkB,EAAa,EAAS,GAAG,CAAC,CAEhE,EAAa,EAAS,GAAG,MA/F5B,EACA,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,2DAGD,EACA,MAAiBC,EAAsB,CACvC,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,2EAGD,EAAO,CACN,KAAM,EAAS,MACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,QAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,EAAA,OAAA,KAAA,KAAA,OAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,EAAA,OAAA,KAAA,KAAA,OAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,EAAA,OAAA,KAAA,KAAA,OAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,IAGD,MAAgBA,EAAuB,CAAE,MAAO,CAAE,SAAU,GAAO,CAAE,CAAC,CAAA,EAAA,cAAA,OAAA,EAAA,IAAA,QAAA,IAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,wBAAA,IAAA,GAAA,IAoBtE,EACA,kIAqBA,EACA,EACA,wKAOA,iIAhGF,EAAM,CACL,UAAW,sBACX,UAAW,mBACX,WAAY,GACb,CAAC,CAAA,CAAA,EAAA,CAsGF,IAAA,EAAe"}
1
+ {"version":3,"file":"CustomFieldValue.js","names":["CustomFieldValue","CustomFieldDefinitionRepo.findByIds","CustomFieldDefinitionRepo.findById","CustomFieldDefinition"],"sources":["../../src/models/CustomFieldValue.ts"],"sourcesContent":["import {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n BelongsTo,\n ForeignKey,\n BeforeCreate,\n BeforeUpsert,\n AfterUpsert,\n BeforeUpdate,\n BeforeBulkCreate,\n BeforeBulkUpdate,\n} from 'sequelize-typescript';\nimport type { CreateOptions } from 'sequelize';\nimport { sendDimEvent } from '../events';\nimport CustomFieldDefinition from './CustomFieldDefinition';\nimport { validateFieldType, validateValue } from '../utils/validations';\nimport * as CustomFieldDefinitionRepo from '../repository/definition';\nimport { InvalidFieldTypeError, InvalidValueError } from '../errors';\n\n@Table({\n tableName: 'custom_field_values',\n modelName: 'CustomFieldValue',\n timestamps: true,\n})\nclass CustomFieldValue extends Model {\n @PrimaryKey\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n modelId!: string;\n\n @PrimaryKey\n @ForeignKey(() => CustomFieldDefinition)\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n customFieldDefinitionId!: string;\n\n @Column({\n type: DataType.JSONB,\n allowNull: true,\n })\n value!: any;\n\n @Column({\n type: DataType.DATE,\n allowNull: false,\n })\n declare createdAt?: Date;\n\n @Column({\n type: DataType.DATE,\n allowNull: true,\n })\n declare updatedAt?: Date;\n\n @Column({\n type: DataType.DATE,\n allowNull: true,\n })\n declare deletedAt?: Date;\n\n @BelongsTo(() => CustomFieldDefinition, { scope: { disabled: false } })\n declare customFieldDefinition: CustomFieldDefinition;\n\n private static validateValueAgainstDefinition(\n instance: CustomFieldValue,\n definition: CustomFieldDefinition,\n ): void {\n const { validation, fieldType, name } = definition;\n const isValidFieldType = validateFieldType(fieldType);\n if (!isValidFieldType) {\n throw new InvalidFieldTypeError(fieldType);\n }\n // Always allow null values\n if (instance.value === null) return;\n const validateValueResponse = validateValue(instance.value, fieldType, validation);\n if (validateValueResponse.error) {\n throw new InvalidValueError(instance.value, name, validateValueResponse.error);\n }\n }\n\n @BeforeBulkCreate\n @BeforeBulkUpdate\n static async validateCustomFieldValues(instances: CustomFieldValue[]): Promise<void> {\n const ids = instances.map(instance => instance.customFieldDefinitionId);\n const uniqueIds = [...new Set(ids)];\n const definitions = await CustomFieldDefinitionRepo.findByIds(\n uniqueIds,\n { withDisabled: true },\n );\n\n if (!definitions || definitions.length !== uniqueIds.length) {\n throw new Error('Definitions not found');\n }\n\n instances.forEach((instance) => {\n const definition = definitions.find(d => d.id === instance.customFieldDefinitionId);\n if (definition) {\n this.validateValueAgainstDefinition(instance, definition);\n }\n });\n }\n\n @BeforeUpdate\n @BeforeCreate\n @BeforeUpsert\n static async validateCustomFieldValue(instance: CustomFieldValue): Promise<void> {\n const { customFieldDefinitionId } = instance;\n const cfd = await CustomFieldDefinitionRepo.findById(customFieldDefinitionId, { withDisabled: true });\n this.validateValueAgainstDefinition(instance, cfd!);\n }\n\n @AfterUpsert\n static afterSaveHandler(instance: CustomFieldValue[], options: CreateOptions): void {\n if (options.transaction) {\n options.transaction.afterCommit(() => sendDimEvent(instance[0]));\n } else {\n sendDimEvent(instance[0]);\n }\n }\n}\n\nexport default CustomFieldValue;\n"],"mappings":"ixBAsBA,IAAA,EAAA,cAK+B,CAAM,CA2CnC,OAAe,+BACb,EACA,EACM,CACN,GAAM,CAAE,aAAY,YAAW,QAAS,EAExC,GAAI,CADqB,EAAkB,EAAU,CAEnD,MAAM,IAAI,EAAsB,EAAU,CAG5C,GAAI,EAAS,QAAU,KAAM,OAC7B,IAAM,EAAwB,EAAc,EAAS,MAAO,EAAW,EAAW,CAClF,GAAI,EAAsB,MACxB,MAAM,IAAI,EAAkB,EAAS,MAAO,EAAM,EAAsB,MAAM,CAIlF,aAEa,0BAA0B,EAA8C,CACnF,IAAM,EAAM,EAAU,IAAI,GAAY,EAAS,wBAAwB,CACjE,EAAY,CAAC,GAAG,IAAI,IAAI,EAAI,CAAC,CAC7B,EAAc,MAAMC,EACxB,EACA,CAAE,aAAc,GAAM,CACvB,CAED,GAAI,CAAC,GAAe,EAAY,SAAW,EAAU,OACnD,MAAU,MAAM,wBAAwB,CAG1C,EAAU,QAAS,GAAa,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IAAA,QAAA,IAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,wBAAA,IAAA,GAAA,IAoBtE,EACA,kIAqBA,EACA,EACA,wKAOA,iIAhGF,EAAM,CACL,UAAW,sBACX,UAAW,mBACX,WAAY,GACb,CAAC,CAAA,CAAA,EAAA,CAsGF,IAAA,EAAe"}
@@ -1,2 +1,2 @@
1
- const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../utils/logger/index.cjs`),n=require(`./CustomFieldDefinition.cjs`),r=require(`./CustomFieldValue.cjs`),i=require(`./tests/AssociatedTestModel.cjs`),a=require(`./tests/TestModel.cjs`),o=require(`./tests/contextAwareModels/ContextTestModel.cjs`),s=require(`./tests/contextAwareModels/ContextAwareTestModel.cjs`),c=require(`./CustomFieldEntries.cjs`),l=require(`./CustomValidator.cjs`);let u=require(`sequelize`);const d=[a.default,i.default,s.default,o.default],f=`sadot-migration`,p=`49c9dd1d-b1cc-445b-a911-fd349d783110`,m=async(e,i,{schemaPrefix:a=`sadot-migration`,schemaVersion:o=`49c9dd1d-b1cc-445b-a911-fd349d783110`,useCustomFieldsEntries:s=!1}={})=>{let d=`${a}_${o}${s?`_withEntries`:``}`;if(t.default.info(`custom-fields: initialize custom-fields tables`),!e.addModels)throw Error(`sequelize instance must have addModels function`);let f=[n.default,r.default,l.default,...s?[c.default]:[]];e.addModels(f),n.default.addScope(`userScope`,()=>{let e=i();return e?.permissions?{where:{entityId:[...Object.keys(e.permissions.fleets),...Object.keys(e.permissions.businessModels),...Object.keys(e.permissions.demandSources)]}}:{}}),l.default.addScope(`userScope`,()=>{let e=i();return e?.permissions?{where:{entityId:[...Object.keys(e.permissions.fleets),...Object.keys(e.permissions.businessModels),...Object.keys(e.permissions.demandSources)]}}:{}}),t.default.info(`custom-fields: models added`);let p=e.define(`SequelizeMeta`,{name:{type:u.DataTypes.STRING,allowNull:!1,unique:!0,primaryKey:!0,autoIncrement:!1}},{tableName:`SequelizeMeta`,timestamps:!1,schema:`public`});t.default.info(`custom-fields: starting migrations`);let m=await p.findAll({where:{name:{[u.Op.like]:`${a}%`}},raw:!0}),h=m.at(-1),g=m.findIndex(e=>e.name===d);if(t.default.info(`custom-fields: migrations`,{migrations:m,currentSadotSchemaVersion:h,expectedSchemaVersionIndex:g}),(!h||h.name!==d)&&(t.default.info(`custom-fields: syncing models`),await n.default.sync({alter:!0}),await r.default.sync({alter:!0}),s&&await c.default.sync({alter:!0}),await l.default.sync({alter:!0}),g===-1&&await p.create({name:d}),t.default.info(`custom-fields: models synced`),m.length&&g!==-1&&g<m.length-1)){let e=m.slice(g+1);await p.destroy({where:{name:{[u.Op.in]:e.map(e=>e.name)}}})}},h=async e=>{if(t.default.info(`custom-fields: initialize custom-fields test models`),!e.addModels)throw Error(`sequelize instance must have addModels function`);e.addModels(d),await e.dropSchema(`custom-fields`,{logging:!1}),await e.createSchema(`custom-fields`,{logging:!1}),t.default.info(`custom-fields: test models added`),await a.default.sync({alter:!0}),await i.default.sync({alter:!0}),await o.default.sync({alter:!0}),await s.default.sync({alter:!0}),t.default.info(`custom-fields: test models synced`)};exports.initTables=m,exports.initTestModels=h;
1
+ const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../utils/logger/index.cjs`),n=require(`./CustomFieldValue.cjs`),r=require(`./CustomFieldDefinition.cjs`),i=require(`./tests/AssociatedTestModel.cjs`),a=require(`./tests/TestModel.cjs`),o=require(`./tests/contextAwareModels/ContextTestModel.cjs`),s=require(`./tests/contextAwareModels/ContextAwareTestModel.cjs`),c=require(`./CustomFieldEntries.cjs`),l=require(`./CustomValidator.cjs`);let u=require(`sequelize`);const d=[a.default,i.default,s.default,o.default],f=`sadot-migration`,p=`49c9dd1d-b1cc-445b-a911-fd349d783110`,m=async(e,i,{schemaPrefix:a=`sadot-migration`,schemaVersion:o=`49c9dd1d-b1cc-445b-a911-fd349d783110`,useCustomFieldsEntries:s=!1}={})=>{let d=`${a}_${o}${s?`_withEntries`:``}`;if(t.default.info(`custom-fields: initialize custom-fields tables`),!e.addModels)throw Error(`sequelize instance must have addModels function`);let f=[r.default,n.default,l.default,...s?[c.default]:[]];e.addModels(f),r.default.addScope(`userScope`,()=>{let e=i();return e?.permissions?{where:{entityId:[...Object.keys(e.permissions.fleets),...Object.keys(e.permissions.businessModels),...Object.keys(e.permissions.demandSources)]}}:{}}),l.default.addScope(`userScope`,()=>{let e=i();return e?.permissions?{where:{entityId:[...Object.keys(e.permissions.fleets),...Object.keys(e.permissions.businessModels),...Object.keys(e.permissions.demandSources)]}}:{}}),t.default.info(`custom-fields: models added`);let p=e.define(`SequelizeMeta`,{name:{type:u.DataTypes.STRING,allowNull:!1,unique:!0,primaryKey:!0,autoIncrement:!1}},{tableName:`SequelizeMeta`,timestamps:!1,schema:`public`});t.default.info(`custom-fields: starting migrations`);let m=await p.findAll({where:{name:{[u.Op.like]:`${a}%`}},raw:!0}),h=m.at(-1),g=m.findIndex(e=>e.name===d);if(t.default.info(`custom-fields: migrations`,{migrations:m,currentSadotSchemaVersion:h,expectedSchemaVersionIndex:g}),(!h||h.name!==d)&&(t.default.info(`custom-fields: syncing models`),await r.default.sync({alter:!0}),await n.default.sync({alter:!0}),s&&await c.default.sync({alter:!0}),await l.default.sync({alter:!0}),g===-1&&await p.create({name:d}),t.default.info(`custom-fields: models synced`),m.length&&g!==-1&&g<m.length-1)){let e=m.slice(g+1);await p.destroy({where:{name:{[u.Op.in]:e.map(e=>e.name)}}})}},h=async e=>{if(t.default.info(`custom-fields: initialize custom-fields test models`),!e.addModels)throw Error(`sequelize instance must have addModels function`);e.addModels(d),await e.dropSchema(`custom-fields`,{logging:!1}),await e.createSchema(`custom-fields`,{logging:!1}),t.default.info(`custom-fields: test models added`),await a.default.sync({alter:!0}),await i.default.sync({alter:!0}),await o.default.sync({alter:!0}),await s.default.sync({alter:!0}),t.default.info(`custom-fields: test models synced`)};exports.initTables=m,exports.initTestModels=h;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1,6 +1,6 @@
1
1
  import { CustomFieldValue } from "./CustomFieldValue.cjs";
2
- import { CustomFieldEntries } from "./CustomFieldEntries.cjs";
3
- import { CustomValidator } from "./CustomValidator.cjs";
4
2
  import { CustomFieldDefinition } from "./CustomFieldDefinition.cjs";
3
+ import { CustomValidator } from "./CustomValidator.cjs";
5
4
  import "../types/index.cjs";
5
+ import { CustomFieldEntries } from "./CustomFieldEntries.cjs";
6
6
  import { Sequelize } from "sequelize-typescript";
@@ -1,6 +1,6 @@
1
1
  import { CustomFieldValue } from "./CustomFieldValue.js";
2
- import { CustomFieldEntries } from "./CustomFieldEntries.js";
3
- import { CustomValidator } from "./CustomValidator.js";
4
2
  import { CustomFieldDefinition } from "./CustomFieldDefinition.js";
3
+ import { CustomValidator } from "./CustomValidator.js";
5
4
  import "../types/index.js";
5
+ import { CustomFieldEntries } from "./CustomFieldEntries.js";
6
6
  import { Sequelize } from "sequelize-typescript";
@@ -1,2 +1,2 @@
1
- import e from"../utils/logger/index.js";import t from"./CustomFieldDefinition.js";import n from"./CustomFieldValue.js";import r from"./tests/AssociatedTestModel.js";import i from"./tests/TestModel.js";import a from"./tests/contextAwareModels/ContextTestModel.js";import o from"./tests/contextAwareModels/ContextAwareTestModel.js";import s from"./CustomFieldEntries.js";import c from"./CustomValidator.js";import{DataTypes as l,Op as u}from"sequelize";const d=[i,r,o,a],f=async(r,i,{schemaPrefix:a=`sadot-migration`,schemaVersion:o=`49c9dd1d-b1cc-445b-a911-fd349d783110`,useCustomFieldsEntries:d=!1}={})=>{let f=`${a}_${o}${d?`_withEntries`:``}`;if(e.info(`custom-fields: initialize custom-fields tables`),!r.addModels)throw Error(`sequelize instance must have addModels function`);let p=[t,n,c,...d?[s]:[]];r.addModels(p),t.addScope(`userScope`,()=>{let e=i();return e?.permissions?{where:{entityId:[...Object.keys(e.permissions.fleets),...Object.keys(e.permissions.businessModels),...Object.keys(e.permissions.demandSources)]}}:{}}),c.addScope(`userScope`,()=>{let e=i();return e?.permissions?{where:{entityId:[...Object.keys(e.permissions.fleets),...Object.keys(e.permissions.businessModels),...Object.keys(e.permissions.demandSources)]}}:{}}),e.info(`custom-fields: models added`);let m=r.define(`SequelizeMeta`,{name:{type:l.STRING,allowNull:!1,unique:!0,primaryKey:!0,autoIncrement:!1}},{tableName:`SequelizeMeta`,timestamps:!1,schema:`public`});e.info(`custom-fields: starting migrations`);let h=await m.findAll({where:{name:{[u.like]:`${a}%`}},raw:!0}),g=h.at(-1),_=h.findIndex(e=>e.name===f);if(e.info(`custom-fields: migrations`,{migrations:h,currentSadotSchemaVersion:g,expectedSchemaVersionIndex:_}),(!g||g.name!==f)&&(e.info(`custom-fields: syncing models`),await t.sync({alter:!0}),await n.sync({alter:!0}),d&&await s.sync({alter:!0}),await c.sync({alter:!0}),_===-1&&await m.create({name:f}),e.info(`custom-fields: models synced`),h.length&&_!==-1&&_<h.length-1)){let e=h.slice(_+1);await m.destroy({where:{name:{[u.in]:e.map(e=>e.name)}}})}},p=async t=>{if(e.info(`custom-fields: initialize custom-fields test models`),!t.addModels)throw Error(`sequelize instance must have addModels function`);t.addModels(d),await t.dropSchema(`custom-fields`,{logging:!1}),await t.createSchema(`custom-fields`,{logging:!1}),e.info(`custom-fields: test models added`),await i.sync({alter:!0}),await r.sync({alter:!0}),await a.sync({alter:!0}),await o.sync({alter:!0}),e.info(`custom-fields: test models synced`)};export{f as initTables,p as initTestModels};
1
+ import e from"../utils/logger/index.js";import t from"./CustomFieldValue.js";import n from"./CustomFieldDefinition.js";import r from"./tests/AssociatedTestModel.js";import i from"./tests/TestModel.js";import a from"./tests/contextAwareModels/ContextTestModel.js";import o from"./tests/contextAwareModels/ContextAwareTestModel.js";import s from"./CustomFieldEntries.js";import c from"./CustomValidator.js";import{DataTypes as l,Op as u}from"sequelize";const d=[i,r,o,a],f=async(r,i,{schemaPrefix:a=`sadot-migration`,schemaVersion:o=`49c9dd1d-b1cc-445b-a911-fd349d783110`,useCustomFieldsEntries:d=!1}={})=>{let f=`${a}_${o}${d?`_withEntries`:``}`;if(e.info(`custom-fields: initialize custom-fields tables`),!r.addModels)throw Error(`sequelize instance must have addModels function`);let p=[n,t,c,...d?[s]:[]];r.addModels(p),n.addScope(`userScope`,()=>{let e=i();return e?.permissions?{where:{entityId:[...Object.keys(e.permissions.fleets),...Object.keys(e.permissions.businessModels),...Object.keys(e.permissions.demandSources)]}}:{}}),c.addScope(`userScope`,()=>{let e=i();return e?.permissions?{where:{entityId:[...Object.keys(e.permissions.fleets),...Object.keys(e.permissions.businessModels),...Object.keys(e.permissions.demandSources)]}}:{}}),e.info(`custom-fields: models added`);let m=r.define(`SequelizeMeta`,{name:{type:l.STRING,allowNull:!1,unique:!0,primaryKey:!0,autoIncrement:!1}},{tableName:`SequelizeMeta`,timestamps:!1,schema:`public`});e.info(`custom-fields: starting migrations`);let h=await m.findAll({where:{name:{[u.like]:`${a}%`}},raw:!0}),g=h.at(-1),_=h.findIndex(e=>e.name===f);if(e.info(`custom-fields: migrations`,{migrations:h,currentSadotSchemaVersion:g,expectedSchemaVersionIndex:_}),(!g||g.name!==f)&&(e.info(`custom-fields: syncing models`),await n.sync({alter:!0}),await t.sync({alter:!0}),d&&await s.sync({alter:!0}),await c.sync({alter:!0}),_===-1&&await m.create({name:f}),e.info(`custom-fields: models synced`),h.length&&_!==-1&&_<h.length-1)){let e=h.slice(_+1);await m.destroy({where:{name:{[u.in]:e.map(e=>e.name)}}})}},p=async t=>{if(e.info(`custom-fields: initialize custom-fields test models`),!t.addModels)throw Error(`sequelize instance must have addModels function`);t.addModels(d),await t.dropSchema(`custom-fields`,{logging:!1}),await t.createSchema(`custom-fields`,{logging:!1}),e.info(`custom-fields: test models added`),await i.sync({alter:!0}),await r.sync({alter:!0}),await a.sync({alter:!0}),await o.sync({alter:!0}),e.info(`custom-fields: test models synced`)};export{f as initTables,p as initTestModels};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,5 @@
1
- import "../models/CustomValidator.js";
2
1
  import "../models/CustomFieldDefinition.js";
2
+ import "../models/CustomValidator.js";
3
3
  import { IncludeOptions } from "sequelize";
4
4
  import { getUser } from "@autofleet/zehut";
5
5
  import { ModelCtor, Sequelize } from "sequelize-typescript";
@@ -1,2 +1,2 @@
1
- const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`./logger/index.cjs`),n=require(`../models/CustomFieldDefinition.cjs`),r=require(`../models/CustomFieldValue.cjs`),i=require(`../models/CustomValidator.cjs`);require(`../models/index.cjs`);const a=require(`../hooks/enrich.cjs`),o=require(`../hooks/find.cjs`),s=require(`../hooks/hooks.cjs`);require(`../hooks/index.cjs`);const c=require(`../scopes/filter.cjs`);require(`../scopes/index.cjs`);let l=require(`sequelize`),u=require(`@autofleet/common-types`),d=require(`@autofleet/common-types/lib/custom-fields`);const{CUSTOM_FIELDS_FILTER_SCOPE:f}=u.customFields,p=(e,n,r={useCustomFieldsEntries:!1})=>{e.forEach(async({name:e,scopeAttributes:i,modelOptions:c})=>{try{let u=n(e);if(!u){t.default.warn(`sadot - tried to addHooks to a model that does not exist yet`,{name:e,scopeAttributes:i});return}u.rawAttributes.customFields={type:l.DataTypes.VIRTUAL},u.refreshAttributes(),u.addHook(`beforeFind`,`sadot-beforeFind`,o.beforeFind(i)),u.addHook(`beforeBulkCreate`,`sadot-beforeBulkCreate`,s.beforeBulkCreate),u.addHook(`beforeBulkUpdate`,`sadot-beforeBulkUpdate`,s.beforeBulkUpdate),u.addHook(`beforeCreate`,`sadot-beforeCreate`,s.beforeCreate(i,c,r)),u.addHook(`beforeUpdate`,`sadot-beforeUpdate`,s.beforeUpdate(i,c,r)),u.addHook(`afterFind`,`sadot-afterFind`,a.default(e,i,`afterFind`,c,r)),u.addHook(`afterUpdate`,`sadot-afterUpdate`,a.default(e,i,void 0,c,r)),u.addHook(`afterCreate`,`sadot-afterCreate`,a.default(e,i,void 0,c,r))}catch(n){t.default.error(`Could not add custom fields hook to model ${e}. `,n)}})},m=(e,n)=>{e.forEach(async({name:e})=>{try{let t=n(e);if(!t)return;t.rawAttributes.customFields&&(delete t.rawAttributes.customFields,t.refreshAttributes()),t.removeHook(`beforeFind`,`sadot-beforeFind`),t.removeHook(`beforeBulkCreate`,`sadot-beforeBulkCreate`),t.removeHook(`beforeBulkUpdate`,`sadot-beforeBulkUpdate`),t.removeHook(`beforeCreate`,`sadot-beforeCreate`),t.removeHook(`beforeUpdate`,`sadot-beforeUpdate`),t.removeHook(`afterFind`,`sadot-afterFind`),t.removeHook(`afterUpdate`,`sadot-afterUpdate`)}catch(n){t.default.error(`Could not add custom fields hook to model ${e}. `,n)}})},h=(e,t,n)=>{n?.useCustomFieldsEntries||(e.hasMany(r.default,{foreignKey:`modelId`,as:`customFieldValue`}),r.default.belongsTo(e,{foreignKey:`modelId`,as:t}))},g=(e,n,r={useCustomFieldsEntries:!1})=>{e.forEach(async({name:e,scopeAttributes:i})=>{try{let a=n(e);if(!a){t.default.warn(`sadot - tried to addScopes to a model that does not exist yet`,{name:e,scopeAttributes:i});return}h(a,e,r),a.addScope(f,c.customFieldsFilterScope(e,r)),a.addScope(d.CUSTOM_FIELDS_SORT_SCOPE,c.customFieldsSortScope(e,r))}catch(n){t.default.error(`Could not add custom fields scopes to model ${e}. `,n)}})},_=e=>{e.forEach(({modelOptions:e})=>{e?.customAssociation?.(n.default),e?.customAssociation?.(i.default)})};exports.addHooks=p,exports.addScopes=g,exports.applyCustomAssociation=_,exports.removeHooks=m;
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;
2
2
  //# sourceMappingURL=init.cjs.map
@@ -1,2 +1,2 @@
1
- import e from"./logger/index.js";import t from"../models/CustomFieldDefinition.js";import n from"../models/CustomFieldValue.js";import r from"../models/CustomValidator.js";import"../models/index.js";import i from"../hooks/enrich.js";import{beforeFind as a}from"../hooks/find.js";import{beforeBulkCreate as o,beforeBulkUpdate as s,beforeCreate as c,beforeUpdate as l}from"../hooks/hooks.js";import"../hooks/index.js";import{customFieldsFilterScope as u,customFieldsSortScope as d}from"../scopes/filter.js";import"../scopes/index.js";import{DataTypes as f}from"sequelize";import{customFields as p}from"@autofleet/common-types";import{CUSTOM_FIELDS_SORT_SCOPE as m}from"@autofleet/common-types/lib/custom-fields";const{CUSTOM_FIELDS_FILTER_SCOPE:h}=p,g=(t,n,r={useCustomFieldsEntries:!1})=>{t.forEach(async({name:t,scopeAttributes:u,modelOptions:d})=>{try{let p=n(t);if(!p){e.warn(`sadot - tried to addHooks to a model that does not exist yet`,{name:t,scopeAttributes:u});return}p.rawAttributes.customFields={type:f.VIRTUAL},p.refreshAttributes(),p.addHook(`beforeFind`,`sadot-beforeFind`,a(u)),p.addHook(`beforeBulkCreate`,`sadot-beforeBulkCreate`,o),p.addHook(`beforeBulkUpdate`,`sadot-beforeBulkUpdate`,s),p.addHook(`beforeCreate`,`sadot-beforeCreate`,c(u,d,r)),p.addHook(`beforeUpdate`,`sadot-beforeUpdate`,l(u,d,r)),p.addHook(`afterFind`,`sadot-afterFind`,i(t,u,`afterFind`,d,r)),p.addHook(`afterUpdate`,`sadot-afterUpdate`,i(t,u,void 0,d,r)),p.addHook(`afterCreate`,`sadot-afterCreate`,i(t,u,void 0,d,r))}catch(n){e.error(`Could not add custom fields hook to model ${t}. `,n)}})},_=(t,n)=>{t.forEach(async({name:t})=>{try{let e=n(t);if(!e)return;e.rawAttributes.customFields&&(delete e.rawAttributes.customFields,e.refreshAttributes()),e.removeHook(`beforeFind`,`sadot-beforeFind`),e.removeHook(`beforeBulkCreate`,`sadot-beforeBulkCreate`),e.removeHook(`beforeBulkUpdate`,`sadot-beforeBulkUpdate`),e.removeHook(`beforeCreate`,`sadot-beforeCreate`),e.removeHook(`beforeUpdate`,`sadot-beforeUpdate`),e.removeHook(`afterFind`,`sadot-afterFind`),e.removeHook(`afterUpdate`,`sadot-afterUpdate`)}catch(n){e.error(`Could not add custom fields hook to model ${t}. `,n)}})},v=(e,t,r)=>{r?.useCustomFieldsEntries||(e.hasMany(n,{foreignKey:`modelId`,as:`customFieldValue`}),n.belongsTo(e,{foreignKey:`modelId`,as:t}))},y=(t,n,r={useCustomFieldsEntries:!1})=>{t.forEach(async({name:t,scopeAttributes:i})=>{try{let a=n(t);if(!a){e.warn(`sadot - tried to addScopes to a model that does not exist yet`,{name:t,scopeAttributes:i});return}v(a,t,r),a.addScope(h,u(t,r)),a.addScope(m,d(t,r))}catch(n){e.error(`Could not add custom fields scopes to model ${t}. `,n)}})},b=e=>{e.forEach(({modelOptions:e})=>{e?.customAssociation?.(t),e?.customAssociation?.(r)})};export{g as addHooks,y as addScopes,b as applyCustomAssociation,_ as removeHooks};
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};
2
2
  //# sourceMappingURL=init.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/sadot",
3
- "version": "1.1.12",
3
+ "version": "1.1.14",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -35,7 +35,7 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@autofleet/common-types": "4.94.0",
38
+ "@autofleet/common-types": "4.101.0",
39
39
  "ajv": "^8.12.0",
40
40
  "ajv-errors": "^3.0.0",
41
41
  "ajv-formats": "^3.0.1",
@@ -52,10 +52,10 @@
52
52
  "express": "^4.21.2",
53
53
  "npm-watch": "^0.11.0",
54
54
  "supertest": "^7.0.0",
55
- "@autofleet/node-common": "^4.2.19",
55
+ "@autofleet/errors": "^3.1.38",
56
56
  "@autofleet/logger": "^4.2.42",
57
- "@autofleet/zehut": "^4.6.6",
58
- "@autofleet/errors": "^3.1.38"
57
+ "@autofleet/node-common": "^4.2.19",
58
+ "@autofleet/zehut": "^4.7.0"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "@autofleet/errors": "^3",