@autofleet/sadot 1.0.10 → 1.0.11
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/_virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.cjs +1 -0
- package/dist/_virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.js +1 -0
- package/dist/_virtual/_@oxc-project_runtime@0.89.0/helpers/decorateMetadata.cjs +1 -0
- package/dist/_virtual/_@oxc-project_runtime@0.89.0/helpers/decorateMetadata.js +1 -0
- package/dist/_virtual/rolldown_runtime.cjs +1 -0
- package/dist/api/index.cjs +2 -0
- package/dist/api/index.cjs.map +1 -0
- package/dist/api/index.js +2 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/v1/definition/index.cjs +2 -0
- package/dist/api/v1/definition/index.cjs.map +1 -0
- package/dist/api/v1/definition/index.js +2 -0
- package/dist/api/v1/definition/index.js.map +1 -0
- package/dist/api/v1/definition/validations.cjs +2 -0
- package/dist/api/v1/definition/validations.cjs.map +1 -0
- package/dist/api/v1/definition/validations.js +2 -0
- package/dist/api/v1/definition/validations.js.map +1 -0
- package/dist/api/v1/errors.cjs +2 -0
- package/dist/api/v1/errors.cjs.map +1 -0
- package/dist/api/v1/errors.js +2 -0
- package/dist/api/v1/errors.js.map +1 -0
- package/dist/api/v1/index.cjs +2 -0
- package/dist/api/v1/index.cjs.map +1 -0
- package/dist/api/v1/index.js +2 -0
- package/dist/api/v1/index.js.map +1 -0
- package/dist/api/v1/validator/index.cjs +2 -0
- package/dist/api/v1/validator/index.cjs.map +1 -0
- package/dist/api/v1/validator/index.js +2 -0
- package/dist/api/v1/validator/index.js.map +1 -0
- package/dist/api/v1/validator/validations.cjs +2 -0
- package/dist/api/v1/validator/validations.cjs.map +1 -0
- package/dist/api/v1/validator/validations.js +2 -0
- package/dist/api/v1/validator/validations.js.map +1 -0
- package/dist/errors/index.cjs +3 -0
- package/dist/errors/index.cjs.map +1 -0
- package/dist/errors/index.js +3 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/events/index.cjs +2 -0
- package/dist/events/index.cjs.map +1 -0
- package/dist/events/index.js +2 -0
- package/dist/events/index.js.map +1 -0
- package/dist/hooks/enrich.cjs +2 -0
- package/dist/hooks/enrich.cjs.map +1 -0
- package/dist/hooks/enrich.js +2 -0
- package/dist/hooks/enrich.js.map +1 -0
- package/dist/hooks/find.cjs +2 -0
- package/dist/hooks/find.cjs.map +1 -0
- package/dist/hooks/find.js +2 -0
- package/dist/hooks/find.js.map +1 -0
- package/dist/hooks/hooks.cjs +2 -0
- package/dist/hooks/hooks.cjs.map +1 -0
- package/dist/hooks/hooks.js +2 -0
- package/dist/hooks/hooks.js.map +1 -0
- package/dist/hooks/index.cjs +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/utils/updateInstanceValues.cjs +2 -0
- package/dist/hooks/utils/updateInstanceValues.cjs.map +1 -0
- package/dist/hooks/utils/updateInstanceValues.js +2 -0
- package/dist/hooks/utils/updateInstanceValues.js.map +1 -0
- package/dist/index.cjs +1 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -255
- package/dist/index.d.ts +8 -255
- package/dist/index.js +1 -46
- package/dist/index.js.map +1 -1
- package/dist/models/CustomFieldDefinition.cjs +2 -0
- package/dist/models/CustomFieldDefinition.cjs.map +1 -0
- package/dist/models/CustomFieldDefinition.js +2 -0
- package/dist/models/CustomFieldDefinition.js.map +1 -0
- package/dist/models/CustomFieldEntries.cjs +2 -0
- package/dist/models/CustomFieldEntries.cjs.map +1 -0
- package/dist/models/CustomFieldEntries.js +2 -0
- package/dist/models/CustomFieldEntries.js.map +1 -0
- package/dist/models/CustomFieldValue.cjs +2 -0
- package/dist/models/CustomFieldValue.cjs.map +1 -0
- package/dist/models/CustomFieldValue.js +2 -0
- package/dist/models/CustomFieldValue.js.map +1 -0
- package/dist/models/CustomValidator.cjs +2 -0
- package/dist/models/CustomValidator.cjs.map +1 -0
- package/dist/models/CustomValidator.js +2 -0
- package/dist/models/CustomValidator.js.map +1 -0
- package/dist/models/index.cjs +2 -0
- package/dist/models/index.cjs.map +1 -0
- package/dist/models/index.js +2 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/tests/AssociatedTestModel.cjs +2 -0
- package/dist/models/tests/AssociatedTestModel.cjs.map +1 -0
- package/dist/models/tests/AssociatedTestModel.js +2 -0
- package/dist/models/tests/AssociatedTestModel.js.map +1 -0
- package/dist/models/tests/TestModel.cjs +2 -0
- package/dist/models/tests/TestModel.cjs.map +1 -0
- package/dist/models/tests/TestModel.js +2 -0
- package/dist/models/tests/TestModel.js.map +1 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs +2 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs.map +1 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js +2 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js.map +1 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.cjs +2 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.cjs.map +1 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.js +2 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.js.map +1 -0
- package/dist/repository/definition.cjs +2 -0
- package/dist/repository/definition.cjs.map +1 -0
- package/dist/repository/definition.js +2 -0
- package/dist/repository/definition.js.map +1 -0
- package/dist/repository/entries.cjs +2 -0
- package/dist/repository/entries.cjs.map +1 -0
- package/dist/repository/entries.js +2 -0
- package/dist/repository/entries.js.map +1 -0
- package/dist/repository/utils/formatValues.cjs +2 -0
- package/dist/repository/utils/formatValues.cjs.map +1 -0
- package/dist/repository/utils/formatValues.js +2 -0
- package/dist/repository/utils/formatValues.js.map +1 -0
- package/dist/repository/validator.cjs +2 -0
- package/dist/repository/validator.cjs.map +1 -0
- package/dist/repository/validator.js +2 -0
- package/dist/repository/validator.js.map +1 -0
- package/dist/repository/value.cjs +2 -0
- package/dist/repository/value.cjs.map +1 -0
- package/dist/repository/value.js +2 -0
- package/dist/repository/value.js.map +1 -0
- package/dist/scopes/filter.cjs +2 -0
- package/dist/scopes/filter.cjs.map +1 -0
- package/dist/scopes/filter.d.cts +23 -0
- package/dist/scopes/filter.d.ts +23 -0
- package/dist/scopes/filter.js +2 -0
- package/dist/scopes/filter.js.map +1 -0
- package/dist/scopes/helpers/filter.helpers.cjs +46 -0
- package/dist/scopes/helpers/filter.helpers.cjs.map +1 -0
- package/dist/scopes/helpers/filter.helpers.d.cts +17 -0
- package/dist/scopes/helpers/filter.helpers.d.ts +17 -0
- package/dist/scopes/helpers/filter.helpers.js +46 -0
- package/dist/scopes/helpers/filter.helpers.js.map +1 -0
- package/dist/scopes/index.cjs +1 -0
- package/dist/scopes/index.js +1 -0
- package/dist/types/index.d.cts +44 -0
- package/dist/types/index.d.ts +44 -0
- package/dist/utils/constants/index.cjs +2 -0
- package/dist/utils/constants/index.cjs.map +1 -0
- package/dist/utils/constants/index.d.cts +22 -0
- package/dist/utils/constants/index.d.ts +22 -0
- package/dist/utils/constants/index.js +2 -0
- package/dist/utils/constants/index.js.map +1 -0
- package/dist/utils/db/index.cjs +2 -0
- package/dist/utils/db/index.cjs.map +1 -0
- package/dist/utils/db/index.js +2 -0
- package/dist/utils/db/index.js.map +1 -0
- package/dist/utils/helpers/index.cjs +2 -0
- package/dist/utils/helpers/index.cjs.map +1 -0
- package/dist/utils/helpers/index.d.cts +31 -0
- package/dist/utils/helpers/index.d.ts +31 -0
- package/dist/utils/helpers/index.js +2 -0
- package/dist/utils/helpers/index.js.map +1 -0
- package/dist/utils/init.cjs +2 -0
- package/dist/utils/init.cjs.map +1 -0
- package/dist/utils/init.js +2 -0
- package/dist/utils/init.js.map +1 -0
- package/dist/utils/logger/index.cjs +2 -0
- package/dist/utils/logger/index.cjs.map +1 -0
- package/dist/utils/logger/index.js +2 -0
- package/dist/utils/logger/index.js.map +1 -0
- package/dist/utils/scopeAttributes.cjs +2 -0
- package/dist/utils/scopeAttributes.cjs.map +1 -0
- package/dist/utils/scopeAttributes.js +2 -0
- package/dist/utils/scopeAttributes.js.map +1 -0
- package/dist/utils/validations/index.cjs +2 -0
- package/dist/utils/validations/index.cjs.map +1 -0
- package/dist/utils/validations/index.js +2 -0
- package/dist/utils/validations/index.js.map +1 -0
- package/dist/utils/validations/schema/custom-fields.cjs +2 -0
- package/dist/utils/validations/schema/custom-fields.cjs.map +1 -0
- package/dist/utils/validations/schema/custom-fields.d.cts +7 -0
- package/dist/utils/validations/schema/custom-fields.d.ts +7 -0
- package/dist/utils/validations/schema/custom-fields.js +2 -0
- package/dist/utils/validations/schema/custom-fields.js.map +1 -0
- package/dist/utils/validations/schema/validator-schema.cjs +2 -0
- package/dist/utils/validations/schema/validator-schema.cjs.map +1 -0
- package/dist/utils/validations/schema/validator-schema.js +2 -0
- package/dist/utils/validations/schema/validator-schema.js.map +1 -0
- package/dist/utils/validations/validators/index.cjs +2 -0
- package/dist/utils/validations/validators/index.cjs.map +1 -0
- package/dist/utils/validations/validators/index.js +2 -0
- package/dist/utils/validations/validators/index.js.map +1 -0
- package/dist/utils/validations/validators/select.validator.cjs +2 -0
- package/dist/utils/validations/validators/select.validator.cjs.map +1 -0
- package/dist/utils/validations/validators/select.validator.js +2 -0
- package/dist/utils/validations/validators/select.validator.js.map +1 -0
- package/dist/utils/validations/validators/status.validator.cjs +2 -0
- package/dist/utils/validations/validators/status.validator.cjs.map +1 -0
- package/dist/utils/validations/validators/status.validator.js +2 -0
- package/dist/utils/validations/validators/status.validator.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +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.89.0/helpers/decorateMetadata.cjs`),c=require(`../_virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.cjs`),l=require(`./CustomFieldValue.cjs`);require(`./index.cjs`);let u=require(`sequelize-typescript`);u=e.__toESM(u);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`,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
|
+
//# sourceMappingURL=CustomFieldDefinition.cjs.map
|
|
@@ -0,0 +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 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]) {\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 values: CustomFieldValue[];\n\n @BeforeCreate\n static displayNameDefaultValue(instance: CustomFieldDefinition): void {\n if (!instance?.displayName) {\n // eslint-disable-next-line no-param-reassign\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":"wkBAqBA,IAAA,EAAA,cAsBoCC,EAAAA,KAAM,CAyGxC,OACO,wBAAwB,EAAuC,CAKpE,GAJK,GAAU,cAEb,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,iBA3HzBC,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,IAAA,GAAA,wBAGE,gB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
|
|
|
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.89.0/helpers/decorateMetadata.js";import{__decorate as l}from"../_virtual/_@oxc-project_runtime@0.89.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`,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
|
+
//# sourceMappingURL=CustomFieldDefinition.js.map
|
|
@@ -0,0 +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 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]) {\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 values: CustomFieldValue[];\n\n @BeforeCreate\n static displayNameDefaultValue(instance: CustomFieldDefinition): void {\n if (!instance?.displayName) {\n // eslint-disable-next-line no-param-reassign\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":"y2BAqBA,IAAA,EAAA,cAsBoC,CAAM,CAyGxC,OACO,wBAAwB,EAAuC,CAKpE,GAJK,GAAU,cAEb,EAAS,YAAc,EAAS,MAE9B,CAAC,CAAC,KAAM,IAAA,GAAU,CAAC,SAAS,EAAS,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ACpD,EAAM,CACL,UAAW,2BACX,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,CAkIF,IAAA,EAAe"}
|
|
@@ -0,0 +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.89.0/helpers/decorateMetadata.cjs`),i=require(`../_virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.cjs`),a=require(`../repository/definition.cjs`);let o=require(`sequelize-typescript`);o=e.__toESM(o);var s,c,l,u;let d=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)],d.prototype,`modelId`,void 0),i.__decorate([(0,o.Column)({type:o.DataType.UUID,allowNull:!1}),r.__decorateMetadata(`design:type`,String)],d.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)],d.prototype,`customFields`,void 0),i.__decorate([(0,o.Column)({type:o.DataType.STRING,allowNull:!1}),r.__decorateMetadata(`design:type`,String)],d.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)],d.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)],d.prototype,`updatedAt`,void 0),i.__decorate([o.AfterUpsert,r.__decorateMetadata(`design:type`,Function),r.__decorateMetadata(`design:paramtypes`,[typeof(u=d!==void 0&&d)==`function`?u:Object,Object]),r.__decorateMetadata(`design:returntype`,void 0)],d,`afterSaveHandler`,null),d=i.__decorate([(0,o.Table)({tableName:`custom_field_entries`,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)}}})],d);var f=d;exports.default=f;
|
|
2
|
+
//# sourceMappingURL=CustomFieldEntries.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomFieldEntries.cjs","names":["CustomFieldEntries","Model","sendDimEvent","PrimaryKey","DataType","AfterUpsert"],"sources":["../../src/models/CustomFieldEntries.ts"],"sourcesContent":["import {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n AfterUpsert,\n} from 'sequelize-typescript';\nimport type { CreateOptions } from 'sequelize';\nimport { sendDimEvent } from '../events';\nimport * as CustomFieldDefinitionRepo from '../repository/definition';\nimport { validateInstanceCustomFieldEntries } from '../utils/validations';\n\n@Table({\n tableName: 'custom_field_entries',\n timestamps: true,\n indexes: [\n {\n name: 'idx_cfe_custom_fields',\n using: 'gin',\n operator: 'jsonb_path_ops',\n fields: ['custom_fields'],\n },\n ],\n validate: {\n async validationByType(this: CustomFieldEntries) {\n if (!Object.keys(this.customFields ?? {}).length) {\n return;\n }\n\n const definitionsByName = await CustomFieldDefinitionRepo.getCustomFieldDefinitionsDictionary([this]);\n validateInstanceCustomFieldEntries(this, definitionsByName);\n },\n },\n})\nclass CustomFieldEntries extends Model {\n @PrimaryKey\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n /** The ID of the model of which this row hold the custom field entries of, e.g. vehicleId / stopPointId / etc. */\n modelId!: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n /** The ID of the entity of which this row hold the custom field entries of, e.g. fleetId / etc. */\n entityId!: string;\n\n @Column({\n type: DataType.JSONB,\n allowNull: false,\n defaultValue: {},\n })\n /** A dictionary of customFields and values with the following structure: `{ customFieldName: 'CustomFieldValue' }` */\n customFields!: Record<string, any>;\n\n @Column({\n type: DataType.STRING,\n allowNull: false,\n })\n /** The type of model which this custom field entry represents. e.g. Vehicle / StopPoint / etc. */\n modelType!: string;\n\n @Column({\n type: DataType.DATE,\n allowNull: false,\n })\n declare createdAt?: Date;\n\n @Column({\n type: DataType.DATE,\n allowNull: true,\n })\n declare updatedAt?: Date;\n\n @AfterUpsert\n static afterSaveHandler(instance: CustomFieldEntries, 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 CustomFieldEntries;\n"],"mappings":"0YAaA,IAAA,EAAA,cAsBiCC,EAAAA,KAAM,CA2CrC,OACO,iBAAiB,EAA8B,EAA8B,CAC9E,EAAQ,YACV,EAAQ,YAAY,gBAAkBC,EAAAA,aAAa,EAAS,GAAG,CAAC,CAEhE,EAAA,aAAa,EAAS,GAAG,iBA/C5BC,EAAAA,wBACO,CACN,KAAMC,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,sGAIM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,WAAA,IAAA,GAAA,4BAIM,CACN,KAAMA,EAAAA,SAAS,MACf,UAAW,GACX,aAAc,EAAE,CACjB,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,EAAA,OAAA,OAAA,KAAA,SAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,eAAA,IAAA,GAAA,4BAIM,CACN,KAAMA,EAAAA,SAAS,OACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,4BAIM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,EAAA,OAAA,KAAA,KAAA,OAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,EAAA,OAAA,KAAA,KAAA,OAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,eAGDC,EAAAA,kQAjEI,CACL,UAAW,uBACX,WAAY,GACZ,QAAS,CACP,CACE,KAAM,wBACN,MAAO,MACP,SAAU,iBACV,OAAQ,CAAC,gBAAgB,CAC1B,CACF,CACD,SAAU,CACR,MAAM,kBAA2C,CAC/C,GAAI,CAAC,OAAO,KAAK,KAAK,cAAgB,EAAE,CAAC,CAAC,OACxC,OAGF,IAAM,EAAoB,MAAA,EAAA,oCAAoE,CAAC,KAAK,CAAC,CACrG,EAAA,mCAAmC,KAAM,EAAkB,EAE9D,CACF,CAAC,CAAA,CAAA,EAAA,CAsDF,IAAA,EAAe"}
|
|
@@ -0,0 +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.89.0/helpers/decorateMetadata.js";import{__decorate as r}from"../_virtual/_@oxc-project_runtime@0.89.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,m;let h=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)],h.prototype,`modelId`,void 0),r([o({type:s.UUID,allowNull:!1}),n(`design:type`,String)],h.prototype,`entityId`,void 0),r([o({type:s.JSONB,allowNull:!1,defaultValue:{}}),n(`design:type`,typeof(d=typeof Record<`u`&&Record)==`function`?d:Object)],h.prototype,`customFields`,void 0),r([o({type:s.STRING,allowNull:!1}),n(`design:type`,String)],h.prototype,`modelType`,void 0),r([o({type:s.DATE,allowNull:!1}),n(`design:type`,typeof(f=typeof Date<`u`&&Date)==`function`?f:Object)],h.prototype,`createdAt`,void 0),r([o({type:s.DATE,allowNull:!0}),n(`design:type`,typeof(p=typeof Date<`u`&&Date)==`function`?p:Object)],h.prototype,`updatedAt`,void 0),r([a,n(`design:type`,Function),n(`design:paramtypes`,[typeof(m=h!==void 0&&h)==`function`?m:Object,Object]),n(`design:returntype`,void 0)],h,`afterSaveHandler`,null),h=r([u({tableName:`custom_field_entries`,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)}}})],h);var g=h;export{g as default};
|
|
2
|
+
//# sourceMappingURL=CustomFieldEntries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomFieldEntries.js","names":["CustomFieldEntries","CustomFieldDefinitionRepo.getCustomFieldDefinitionsDictionary"],"sources":["../../src/models/CustomFieldEntries.ts"],"sourcesContent":["import {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n AfterUpsert,\n} from 'sequelize-typescript';\nimport type { CreateOptions } from 'sequelize';\nimport { sendDimEvent } from '../events';\nimport * as CustomFieldDefinitionRepo from '../repository/definition';\nimport { validateInstanceCustomFieldEntries } from '../utils/validations';\n\n@Table({\n tableName: 'custom_field_entries',\n timestamps: true,\n indexes: [\n {\n name: 'idx_cfe_custom_fields',\n using: 'gin',\n operator: 'jsonb_path_ops',\n fields: ['custom_fields'],\n },\n ],\n validate: {\n async validationByType(this: CustomFieldEntries) {\n if (!Object.keys(this.customFields ?? {}).length) {\n return;\n }\n\n const definitionsByName = await CustomFieldDefinitionRepo.getCustomFieldDefinitionsDictionary([this]);\n validateInstanceCustomFieldEntries(this, definitionsByName);\n },\n },\n})\nclass CustomFieldEntries extends Model {\n @PrimaryKey\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n /** The ID of the model of which this row hold the custom field entries of, e.g. vehicleId / stopPointId / etc. */\n modelId!: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n /** The ID of the entity of which this row hold the custom field entries of, e.g. fleetId / etc. */\n entityId!: string;\n\n @Column({\n type: DataType.JSONB,\n allowNull: false,\n defaultValue: {},\n })\n /** A dictionary of customFields and values with the following structure: `{ customFieldName: 'CustomFieldValue' }` */\n customFields!: Record<string, any>;\n\n @Column({\n type: DataType.STRING,\n allowNull: false,\n })\n /** The type of model which this custom field entry represents. e.g. Vehicle / StopPoint / etc. */\n modelType!: string;\n\n @Column({\n type: DataType.DATE,\n allowNull: false,\n })\n declare createdAt?: Date;\n\n @Column({\n type: DataType.DATE,\n allowNull: true,\n })\n declare updatedAt?: Date;\n\n @AfterUpsert\n static afterSaveHandler(instance: CustomFieldEntries, 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 CustomFieldEntries;\n"],"mappings":"0hBAaA,IAAA,EAAA,cAsBiC,CAAM,CA2CrC,OACO,iBAAiB,EAA8B,EAA8B,CAC9E,EAAQ,YACV,EAAQ,YAAY,gBAAkB,EAAa,EAAS,GAAG,CAAC,CAEhE,EAAa,EAAS,GAA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ldown_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.89.0/helpers/decorateMetadata.cjs`),a=require(`../_virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.cjs`),o=require(`./CustomFieldDefinition.cjs`),s=require(`../repository/definition.cjs`);require(`./index.cjs`);let c=require(`sequelize-typescript`);c=e.__toESM(c);var l,u,d,f,p,m;let h=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)],h.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)],h.prototype,`customFieldDefinitionId`,void 0),a.__decorate([(0,c.Column)({type:c.DataType.JSONB,allowNull:!0}),i.__decorateMetadata(`design:type`,Object)],h.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)],h.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)],h.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)],h.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)],h.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)],h,`validateCustomFieldValues`,null),a.__decorate([c.BeforeUpdate,c.BeforeCreate,c.BeforeUpsert,i.__decorateMetadata(`design:type`,Function),i.__decorateMetadata(`design:paramtypes`,[typeof(p=h!==void 0&&h)==`function`?p:Object]),i.__decorateMetadata(`design:returntype`,Promise)],h,`validateCustomFieldValue`,null),a.__decorate([c.AfterUpsert,i.__decorateMetadata(`design:type`,Function),i.__decorateMetadata(`design:paramtypes`,[typeof(m=h!==void 0&&h)==`function`?m:Object,Object]),i.__decorateMetadata(`design:returntype`,void 0)],h,`afterSaveHandler`,null),h=a.__decorate([(0,c.Table)({tableName:`custom_field_values`,timestamps:!0})],h);var g=h;exports.default=g;
|
|
2
|
+
//# sourceMappingURL=CustomFieldValue.cjs.map
|
|
@@ -0,0 +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 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 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 // eslint-disable-next-line max-len\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":"+eAsBA,IAAA,EAAA,cAI+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,IAAK,GAAa,EAAS,wBAAwB,CACnE,EAAY,CAAC,GAAG,IAAI,IAAI,EAAI,CAAC,CAC7B,EAAc,MAAA,EAAA,UAClB,EACA,CAAE,aAAc,GAAM,CACvB,CAED,GA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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,uPAQAC,EAAAA,kQAhGI,CACL,UAAW,sBACX,WAAY,GACb,CAAC,CAAA,CAAA,EAAA,CAuGF,IAAA,EAAe"}
|
|
@@ -0,0 +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.89.0/helpers/decorateMetadata.js";import{__decorate as o}from"../_virtual/_@oxc-project_runtime@0.89.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,O;let k=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)],k.prototype,`modelId`,void 0),o([x,y(()=>s),_({type:v.UUID,allowNull:!1}),a(`design:type`,String)],k.prototype,`customFieldDefinitionId`,void 0),o([_({type:v.JSONB,allowNull:!0}),a(`design:type`,Object)],k.prototype,`value`,void 0),o([_({type:v.DATE,allowNull:!1}),a(`design:type`,typeof(C=typeof Date<`u`&&Date)==`function`?C:Object)],k.prototype,`createdAt`,void 0),o([_({type:v.DATE,allowNull:!0}),a(`design:type`,typeof(w=typeof Date<`u`&&Date)==`function`?w:Object)],k.prototype,`updatedAt`,void 0),o([_({type:v.DATE,allowNull:!0}),a(`design:type`,typeof(T=typeof Date<`u`&&Date)==`function`?T:Object)],k.prototype,`deletedAt`,void 0),o([g(()=>s,{scope:{disabled:!1}}),a(`design:type`,typeof(E=s!==void 0&&s)==`function`?E:Object)],k.prototype,`customFieldDefinition`,void 0),o([d,f,a(`design:type`,Function),a(`design:paramtypes`,[Array]),a(`design:returntype`,Promise)],k,`validateCustomFieldValues`,null),o([m,p,h,a(`design:type`,Function),a(`design:paramtypes`,[typeof(D=k!==void 0&&k)==`function`?D:Object]),a(`design:returntype`,Promise)],k,`validateCustomFieldValue`,null),o([u,a(`design:type`,Function),a(`design:paramtypes`,[typeof(O=k!==void 0&&k)==`function`?O:Object,Object]),a(`design:returntype`,void 0)],k,`afterSaveHandler`,null),k=o([S({tableName:`custom_field_values`,timestamps:!0})],k);var A=k;export{A as default};
|
|
2
|
+
//# sourceMappingURL=CustomFieldValue.js.map
|
|
@@ -0,0 +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 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 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 // eslint-disable-next-line max-len\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,cAI+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,IAAK,GAAa,EAAS,wBAAwB,CACnE,EAAY,CAAC,GAAG,IAAI,IAAI,EAAI,CAAC,CAC7B,EAAc,MAAMC,EACxB,EACA,CAAE,aAAc,GAAM,CACvB,CAED,GAAI,CAAC,GAAe,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E,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,wKAQA,wKAhGF,EAAM,CACL,UAAW,sBACX,WAAY,GACb,CAAC,CAAA,CAAA,EAAA,CAuGF,IAAA,EAAe"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../events/index.cjs`),n=require(`../_virtual/_@oxc-project_runtime@0.89.0/helpers/decorateMetadata.cjs`),r=require(`../_virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.cjs`);let i=require(`sequelize-typescript`);i=e.__toESM(i);let a=require(`node:crypto`);a=e.__toESM(a);var o,s,c;let l=class extends i.Model{static afterSaveHandler(e,n){n.transaction?n.transaction.afterCommit(()=>t.sendDimEvent(e)):t.sendDimEvent(e)}};r.__decorate([i.PrimaryKey,(0,i.Default)(()=>(0,a.randomUUID)()),(0,i.Column)({type:i.DataType.UUID,allowNull:!1}),n.__decorateMetadata(`design:type`,String)],l.prototype,`id`,void 0),r.__decorate([(0,i.Column)({type:i.DataType.UUID,allowNull:!1}),n.__decorateMetadata(`design:type`,String)],l.prototype,`entityId`,void 0),r.__decorate([(0,i.Column)({type:i.DataType.STRING,allowNull:!1}),n.__decorateMetadata(`design:type`,String)],l.prototype,`entityType`,void 0),r.__decorate([(0,i.Column)({type:i.DataType.STRING,allowNull:!1}),n.__decorateMetadata(`design:type`,String)],l.prototype,`modelType`,void 0),r.__decorate([(0,i.Column)({type:i.DataType.JSONB,allowNull:!1}),n.__decorateMetadata(`design:type`,Object)],l.prototype,`schema`,void 0),r.__decorate([(0,i.Column)({type:i.DataType.BOOLEAN,allowNull:!1,defaultValue:!1}),n.__decorateMetadata(`design:type`,Boolean)],l.prototype,`disabled`,void 0),r.__decorate([(0,i.Column)({type:i.DataType.DATE,allowNull:!1}),n.__decorateMetadata(`design:type`,typeof(o=typeof Date<`u`&&Date)==`function`?o:Object)],l.prototype,`createdAt`,void 0),r.__decorate([(0,i.Column)({type:i.DataType.DATE,allowNull:!0}),n.__decorateMetadata(`design:type`,typeof(s=typeof Date<`u`&&Date)==`function`?s:Object)],l.prototype,`updatedAt`,void 0),r.__decorate([i.AfterUpsert,n.__decorateMetadata(`design:type`,Function),n.__decorateMetadata(`design:paramtypes`,[typeof(c=l!==void 0&&l)==`function`?c:Object,Object]),n.__decorateMetadata(`design:returntype`,void 0)],l,`afterSaveHandler`,null),l=r.__decorate([(0,i.DefaultScope)(()=>({where:{disabled:!1}})),(0,i.Table)({tableName:`custom_validators`,timestamps:!0})],l);var u=l;exports.default=u;
|
|
2
|
+
//# sourceMappingURL=CustomValidator.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomValidator.cjs","names":["CustomValidator","Model","sendDimEvent","PrimaryKey","DataType","AfterUpsert"],"sources":["../../src/models/CustomValidator.ts"],"sourcesContent":["import {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n Default,\n AfterUpsert,\n DefaultScope,\n} from 'sequelize-typescript';\nimport type { CreateOptions } from 'sequelize';\nimport { randomUUID } from 'node:crypto';\nimport { sendDimEvent } from '../events';\nimport type { SchemaObject } from '../api/v1/validator/validations';\n\n@DefaultScope(() => ({ where: { disabled: false } }))\n@Table({\n tableName: 'custom_validators',\n timestamps: true,\n})\nclass CustomValidator extends Model {\n @PrimaryKey\n @Default(() => randomUUID())\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n declare id: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n /** The ID of the entity for which this validator is defined, e.g. fleetId / etc. */\n entityId!: string;\n\n @Column({\n type: DataType.STRING,\n allowNull: false,\n })\n /** The type of entity (fleet, businessModel, etc). */\n entityType!: string;\n\n @Column({\n type: DataType.STRING,\n allowNull: false,\n })\n /** The type of model this validator applies to. e.g. Vehicle / StopPoint / etc. */\n modelType!: string;\n\n @Column({\n type: DataType.JSONB,\n allowNull: false,\n })\n /** JSON Schema to validate models against */\n schema!: SchemaObject;\n\n @Column({\n type: DataType.BOOLEAN,\n allowNull: false,\n defaultValue: false,\n })\n disabled!: boolean;\n\n @Column({\n type: DataType.DATE,\n allowNull: false,\n })\n declare createdAt?: Date;\n\n @Column({\n type: DataType.DATE,\n allowNull: true,\n })\n declare updatedAt?: Date;\n\n @AfterUpsert\n static afterSaveHandler(instance: CustomValidator, options: CreateOptions): void {\n if (options.transaction) {\n options.transaction.afterCommit(() => sendDimEvent(instance));\n } else {\n sendDimEvent(instance);\n }\n }\n}\n\nexport default CustomValidator;\n"],"mappings":"8VAeA,IAAA,EAAA,cAK8BC,EAAAA,KAAM,CAwDlC,OACO,iBAAiB,EAA2B,EAA8B,CAC3E,EAAQ,YACV,EAAQ,YAAY,gBAAkBC,EAAAA,aAAa,EAAS,CAAC,CAE7D,EAAA,aAAa,EAAS,iBA5DzBC,EAAAA,+CAC0B,CAAC,cACpB,CACN,KAAMC,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,iGAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,WAAA,IAAA,GAAA,4BAIM,CACN,KAAMA,EAAAA,SAAS,OACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,aAAA,IAAA,GAAA,4BAIM,CACN,KAAMA,EAAAA,SAAS,OACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,4BAIM,CACN,KAAMA,EAAAA,SAAS,MACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,SAAA,IAAA,GAAA,4BAIM,CACN,KAAMA,EAAAA,SAAS,QACf,UAAW,GACX,aAAc,GACf,CAAC,CAAA,EAAA,mBAAA,cAAA,QAAA,CAAA,CAAA,EAAA,UAAA,WAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,EAAA,OAAA,KAAA,KAAA,OAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,EAAA,OAAA,KAAA,KAAA,OAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,eAGDC,EAAAA,8QA7DkB,CAAE,MAAO,CAAE,SAAU,GAAO,CAAE,EAAE,EAAA,EAAA,EAAA,OAC9C,CACL,UAAW,oBACX,WAAY,GACb,CAAC,CAAA,CAAA,EAAA,CAmEF,IAAA,EAAe"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{sendDimEvent as e}from"../events/index.js";import{__decorateMetadata as t}from"../_virtual/_@oxc-project_runtime@0.89.0/helpers/decorateMetadata.js";import{__decorate as n}from"../_virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.js";import{AfterUpsert as r,Column as i,DataType as a,Default as o,DefaultScope as s,Model as c,PrimaryKey as l,Table as u}from"sequelize-typescript";import{randomUUID as d}from"node:crypto";var f,p,m;let h=class extends c{static afterSaveHandler(t,n){n.transaction?n.transaction.afterCommit(()=>e(t)):e(t)}};n([l,o(()=>d()),i({type:a.UUID,allowNull:!1}),t(`design:type`,String)],h.prototype,`id`,void 0),n([i({type:a.UUID,allowNull:!1}),t(`design:type`,String)],h.prototype,`entityId`,void 0),n([i({type:a.STRING,allowNull:!1}),t(`design:type`,String)],h.prototype,`entityType`,void 0),n([i({type:a.STRING,allowNull:!1}),t(`design:type`,String)],h.prototype,`modelType`,void 0),n([i({type:a.JSONB,allowNull:!1}),t(`design:type`,Object)],h.prototype,`schema`,void 0),n([i({type:a.BOOLEAN,allowNull:!1,defaultValue:!1}),t(`design:type`,Boolean)],h.prototype,`disabled`,void 0),n([i({type:a.DATE,allowNull:!1}),t(`design:type`,typeof(f=typeof Date<`u`&&Date)==`function`?f:Object)],h.prototype,`createdAt`,void 0),n([i({type:a.DATE,allowNull:!0}),t(`design:type`,typeof(p=typeof Date<`u`&&Date)==`function`?p:Object)],h.prototype,`updatedAt`,void 0),n([r,t(`design:type`,Function),t(`design:paramtypes`,[typeof(m=h!==void 0&&h)==`function`?m:Object,Object]),t(`design:returntype`,void 0)],h,`afterSaveHandler`,null),h=n([s(()=>({where:{disabled:!1}})),u({tableName:`custom_validators`,timestamps:!0})],h);var g=h;export{g as default};
|
|
2
|
+
//# sourceMappingURL=CustomValidator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomValidator.js","names":["CustomValidator"],"sources":["../../src/models/CustomValidator.ts"],"sourcesContent":["import {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n Default,\n AfterUpsert,\n DefaultScope,\n} from 'sequelize-typescript';\nimport type { CreateOptions } from 'sequelize';\nimport { randomUUID } from 'node:crypto';\nimport { sendDimEvent } from '../events';\nimport type { SchemaObject } from '../api/v1/validator/validations';\n\n@DefaultScope(() => ({ where: { disabled: false } }))\n@Table({\n tableName: 'custom_validators',\n timestamps: true,\n})\nclass CustomValidator extends Model {\n @PrimaryKey\n @Default(() => randomUUID())\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n declare id: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n /** The ID of the entity for which this validator is defined, e.g. fleetId / etc. */\n entityId!: string;\n\n @Column({\n type: DataType.STRING,\n allowNull: false,\n })\n /** The type of entity (fleet, businessModel, etc). */\n entityType!: string;\n\n @Column({\n type: DataType.STRING,\n allowNull: false,\n })\n /** The type of model this validator applies to. e.g. Vehicle / StopPoint / etc. */\n modelType!: string;\n\n @Column({\n type: DataType.JSONB,\n allowNull: false,\n })\n /** JSON Schema to validate models against */\n schema!: SchemaObject;\n\n @Column({\n type: DataType.BOOLEAN,\n allowNull: false,\n defaultValue: false,\n })\n disabled!: boolean;\n\n @Column({\n type: DataType.DATE,\n allowNull: false,\n })\n declare createdAt?: Date;\n\n @Column({\n type: DataType.DATE,\n allowNull: true,\n })\n declare updatedAt?: Date;\n\n @AfterUpsert\n static afterSaveHandler(instance: CustomValidator, options: CreateOptions): void {\n if (options.transaction) {\n options.transaction.afterCommit(() => sendDimEvent(instance));\n } else {\n sendDimEvent(instance);\n }\n }\n}\n\nexport default CustomValidator;\n"],"mappings":"2bAeA,IAAA,EAAA,cAK8B,CAAM,CAwDlC,OACO,iBAAiB,EAA2B,EAA8B,CAC3E,EAAQ,YACV,EAAQ,YAAY,gBAAkB,EAAa,EAAS,CAAC,CAE7D,EAAa,EAAS,MA5DzB,EACA,MAAc,GAAY,CAAC,CAC3B,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,sDAGD,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,WAAA,IAAA,GAAA,IAID,EAAO,CACN,KAAM,EAAS,OACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,aAAA,IAAA,GAAA,IAID,EAAO,CACN,KAAM,EAAS,OACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,IAID,EAAO,CACN,KAAM,EAAS,MACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,SAAA,IAAA,GAAA,IAID,EAAO,CACN,KAAM,EAAS,QACf,UAAW,GACX,aAAc,GACf,CAAC,CAAA,EAAA,cAAA,QAAA,CAAA,CAAA,EAAA,UAAA,WAAA,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,wKA7DF,OAAoB,CAAE,MAAO,CAAE,SAAU,GAAO,CAAE,EAAE,CACpD,EAAM,CACL,UAAW,oBACX,WAAY,GACb,CAAC,CAAA,CAAA,EAAA,CAmEF,IAAA,EAAe"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../utils/logger/index.cjs`),n=require(`./CustomFieldDefinition.cjs`),r=require(`./CustomFieldValue.cjs`),i=require(`./tests/AssociatedTestModel.cjs`),a=require(`./tests/TestModel.cjs`),o=require(`./tests/contextAwareModels/ContextTestModel.cjs`),s=require(`./tests/contextAwareModels/ContextAwareTestModel.cjs`),c=require(`./CustomFieldEntries.cjs`),l=require(`./CustomValidator.cjs`);let u=require(`sequelize`);u=e.__toESM(u);const d=[n.default,r.default,l.default],f=[a.default,i.default,s.default,o.default],p=`sadot-migration`,m=`49c9dd1d-b1cc-445b-a911-fd349d783110`,h=async(e,i,{schemaPrefix:a=`sadot-migration`,schemaVersion:o=`49c9dd1d-b1cc-445b-a911-fd349d783110`,useCustomFieldsEntries:s=!1}={})=>{let f=`${a}_${o}${s?`_withEntries`:``}`;if(t.default.info(`custom-fields: initialize custom-fields tables`),!e.addModels)throw Error(`sequelize instance must have addModels function`);s&&d.push(c.default),e.addModels(d),n.default.addScope(`userScope`,()=>{let e=i();return e?.permissions?{where:{entityId:[...Object.keys(e.permissions.fleets),...Object.keys(e.permissions.businessModels),...Object.keys(e.permissions.demandSources)]}}:{}}),l.default.addScope(`userScope`,()=>{let e=i();return e?.permissions?{where:{entityId:[...Object.keys(e.permissions.fleets),...Object.keys(e.permissions.businessModels),...Object.keys(e.permissions.demandSources)]}}:{}}),t.default.info(`custom-fields: models added`);let p=e.define(`SequelizeMeta`,{name:{type:u.DataTypes.STRING,allowNull:!1,unique:!0,primaryKey:!0,autoIncrement:!1}},{tableName:`SequelizeMeta`,timestamps:!1,schema:`public`});t.default.info(`custom-fields: starting migrations`);let m=await p.findAll({where:{name:{[u.Op.like]:`${a}%`}},raw:!0}),h=m.at(-1),g=m.findIndex(e=>e.name===f);if(t.default.info(`custom-fields: migrations`,{migrations:m,currentSadotSchemaVersion:h,expectedSchemaVersionIndex:g}),(!h||h.name!==f)&&(t.default.info(`custom-fields: syncing models`),await n.default.sync({alter:!0}),await r.default.sync({alter:!0}),s&&await c.default.sync({alter:!0}),await l.default.sync({alter:!0}),g===-1&&await p.create({name:f}),t.default.info(`custom-fields: models synced`),m.length&&g!==-1&&g<m.length-1)){let e=m.slice(g+1);await p.destroy({where:{name:{[u.Op.in]:e.map(e=>e.name)}}})}},g=async e=>{if(t.default.info(`custom-fields: initialize custom-fields test models`),!e.addModels)throw Error(`sequelize instance must have addModels function`);e.addModels(f),await e.dropSchema(`custom-fields`,{logging:!1}),await e.createSchema(`custom-fields`,{logging:!1}),t.default.info(`custom-fields: test models added`),await a.default.sync({alter:!0}),await i.default.sync({alter:!0}),await o.default.sync({alter:!0}),await s.default.sync({alter:!0}),t.default.info(`custom-fields: test models synced`)};exports.initTables=h,exports.initTestModels=g;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["productionModels: ProductionModel[]","CustomFieldDefinition","CustomFieldValue","CustomValidator","TestModel","AssociatedTestModel","ContextAwareTestModel","ContextTestModel","sequelize","CustomFieldEntries","DataTypes","Op"],"sources":["../../src/models/index.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport { DataTypes, Op } from 'sequelize';\nimport type { Sequelize } from 'sequelize-typescript';\nimport logger from '../utils/logger';\nimport CustomFieldDefinition from './CustomFieldDefinition';\nimport CustomFieldValue from './CustomFieldValue';\nimport TestModel from './tests/TestModel';\nimport ContextAwareTestModel from './tests/contextAwareModels/ContextAwareTestModel';\nimport ContextTestModel from './tests/contextAwareModels/ContextTestModel';\nimport AssociatedTestModel from './tests/AssociatedTestModel';\nimport type { CustomFieldOptions } from '../types';\nimport CustomFieldEntries from './CustomFieldEntries';\nimport CustomValidator from './CustomValidator';\n\ntype ProductionModel = typeof CustomFieldDefinition | typeof CustomFieldValue | typeof CustomFieldEntries | typeof CustomValidator\ninterface InitTablesOptions {\n schemaPrefix?: string\n schemaVersion?: string\n useCustomFieldsEntries?: boolean\n}\n\nconst productionModels: ProductionModel[] = [CustomFieldDefinition, CustomFieldValue, CustomValidator];\nconst testModels = [TestModel, AssociatedTestModel, ContextAwareTestModel, ContextTestModel];\n\nconst SADOT_MIGRATION_PREFIX = 'sadot-migration';\nconst SCHEMA_VERSION = '49c9dd1d-b1cc-445b-a911-fd349d783110';\n\nconst initTables = async (\n sequelize: Sequelize,\n getUser: CustomFieldOptions['getUser'],\n {\n schemaPrefix = SADOT_MIGRATION_PREFIX,\n schemaVersion = SCHEMA_VERSION,\n useCustomFieldsEntries = false,\n }: InitTablesOptions = {},\n): Promise<void> => {\n const CUSTOM_FIELDS_SCHEMA_VERSION = `${schemaPrefix}_${schemaVersion}${useCustomFieldsEntries ? '_withEntries' : ''}`;\n logger.info('custom-fields: initialize custom-fields tables');\n // Detect models and import them to the orm\n // eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n if (!sequelize.addModels) {\n throw new Error('sequelize instance must have addModels function');\n }\n\n if (useCustomFieldsEntries) {\n productionModels.push(CustomFieldEntries);\n }\n\n sequelize.addModels(productionModels);\n\n CustomFieldDefinition.addScope('userScope', () => {\n const user = getUser();\n if (!user?.permissions) {\n return {};\n }\n return {\n where: {\n entityId: [\n ...Object.keys(user.permissions.fleets),\n ...Object.keys(user.permissions.businessModels),\n ...Object.keys(user.permissions.demandSources),\n ],\n },\n };\n });\n\n CustomValidator.addScope('userScope', () => {\n const user = getUser();\n if (!user?.permissions) {\n return {};\n }\n return {\n where: {\n entityId: [\n ...Object.keys(user.permissions.fleets),\n ...Object.keys(user.permissions.businessModels),\n ...Object.keys(user.permissions.demandSources),\n ],\n },\n };\n });\n\n logger.info('custom-fields: models added');\n\n const SequelizeMeta = sequelize.define(\n 'SequelizeMeta',\n {\n name: {\n type: DataTypes.STRING,\n allowNull: false,\n unique: true,\n primaryKey: true,\n autoIncrement: false,\n },\n },\n {\n tableName: 'SequelizeMeta',\n timestamps: false,\n schema: 'public',\n },\n );\n\n logger.info('custom-fields: starting migrations');\n const migrations = await SequelizeMeta.findAll({ where: { name: { [Op.like]: `${schemaPrefix}%` } }, raw: true });\n const currentSadotSchemaVersion = migrations.at(-1);\n const expectedSchemaVersionIndex = migrations.findIndex((m) => (m as any).name === CUSTOM_FIELDS_SCHEMA_VERSION);\n\n logger.info('custom-fields: migrations', { migrations, currentSadotSchemaVersion, expectedSchemaVersionIndex });\n if (!currentSadotSchemaVersion || (currentSadotSchemaVersion as any).name !== CUSTOM_FIELDS_SCHEMA_VERSION) {\n logger.info('custom-fields: syncing models');\n await CustomFieldDefinition.sync({ alter: true });\n await CustomFieldValue.sync({ alter: true });\n // T.Y TODO: Remove the if statement once we're ready to add the new entries table for all MS\n if (useCustomFieldsEntries) {\n await CustomFieldEntries.sync({ alter: true });\n }\n\n // Always sync CustomValidator\n await CustomValidator.sync({ alter: true });\n\n if (expectedSchemaVersionIndex === -1) {\n await SequelizeMeta.create({ name: CUSTOM_FIELDS_SCHEMA_VERSION });\n }\n logger.info('custom-fields: models synced');\n if (migrations.length && expectedSchemaVersionIndex !== -1 && expectedSchemaVersionIndex < migrations.length - 1) {\n // We have existing migrations, and we are calling `sync`.\n // This means we are in a `down` migration, and hence we should delete newer migrations to ensure we can reapply them.\n const migrationsToDelete = migrations.slice(expectedSchemaVersionIndex + 1);\n await SequelizeMeta.destroy({ where: { name: { [Op.in]: migrationsToDelete.map((m) => (m as any).name) } } });\n }\n }\n};\n\nconst initTestModels = async (sequelize: Sequelize): Promise<void> => {\n logger.info('custom-fields: initialize custom-fields test models');\n // Detect models and import them to the orm\n // eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n if (!sequelize.addModels) {\n throw new Error('sequelize instance must have addModels function');\n }\n\n sequelize.addModels(testModels);\n await sequelize.dropSchema('custom-fields', { logging: false });\n await sequelize.createSchema('custom-fields', { logging: false });\n\n logger.info('custom-fields: test models added');\n await TestModel.sync({ alter: true });\n await AssociatedTestModel.sync({ alter: true });\n await ContextTestModel.sync({ alter: true });\n await ContextAwareTestModel.sync({ alter: true });\n logger.info('custom-fields: test models synced');\n};\n\nexport {\n CustomFieldValue,\n CustomFieldDefinition,\n CustomFieldEntries,\n CustomValidator,\n TestModel,\n AssociatedTestModel,\n ContextAwareTestModel,\n ContextTestModel,\n initTables,\n initTestModels,\n};\n"],"mappings":"0eAqBA,MAAMA,EAAsC,CAACC,EAAAA,QAAuBC,EAAAA,QAAkBC,EAAAA,QAAgB,CAChG,EAAa,CAACC,EAAAA,QAAWC,EAAAA,QAAqBC,EAAAA,QAAuBC,EAAAA,QAAiB,CAEtF,EAAyB,kBACzB,EAAiB,uCAEjB,EAAa,MACjB,EACA,EACA,CACE,eAAe,kBACf,gBAAgB,uCAChB,yBAAyB,IACJ,EAAE,GACP,CAClB,IAAM,EAA+B,GAAG,EAAa,GAAG,IAAgB,EAAyB,eAAiB,KAIlH,GAHA,EAAA,QAAO,KAAK,iDAAiD,CAGzD,CAACC,EAAU,UACb,MAAU,MAAM,kDAAkD,CAGhE,GACF,EAAiB,KAAKC,EAAAA,QAAmB,CAG3C,EAA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,EAAAA,QAAiB,KAAK,CAAE,MAAO,GAAM,CAAC,CAExC,GACF,MAAMO,EAAAA,QAAmB,KAAK,CAAE,MAAO,GAAM,CAAC,CAIhD,MAAMN,EAAAA,QAAgB,KAAK,CAAE,MAAO,GAAM,CAAC,CAEvC,IAA+B,IACjC,MAAM,EAAc,OAAO,CAAE,KAAM,EAA8B,CAAC,CAEpE,EAAA,QAAO,KAAK,+BAA+B,CACvC,EAAW,QAAU,IAA+B,IAAM,EAA6B,EAAW,OAAS,GAAG,CAGhH,IAAM,EAAqB,EAAW,MAAM,EAA6B,EAAE,CAC3E,MAAM,EAAc,QAAQ,CAAE,MAAO,CAAE,KAAM,EAAGQ,EAAAA,GAAG,IAAK,EAAmB,IAAK,GAAO,EAAU,KAAK,CAAE,CAAE,CAAE,CAAC,GAK7G,EAAiB,KAAO,IAAwC,CAIpE,GAHA,EAAA,QAAO,KAAK,sDAAsD,CAG9D,CAACH,EAAU,UACb,MAAU,MAAM,kDAAkD,CAGpE,EAAU,UAAU,EAAW,CAC/B,MAAMA,EAAU,WAAW,gBAAiB,CAAE,QAAS,GAAO,CAAC,CAC/D,MAAMA,EAAU,aAAa,gBAAiB,CAAE,QAAS,GAAO,CAAC,CAEjE,EAAA,QAAO,KAAK,mCAAmC,CAC/C,MAAMJ,EAAAA,QAAU,KAAK,CAAE,MAAO,GAAM,CAAC,CACrC,MAAMC,EAAAA,QAAoB,KAAK,CAAE,MAAO,GAAM,CAAC,CAC/C,MAAME,EAAAA,QAAiB,KAAK,CAAE,MAAO,GAAM,CAAC,CAC5C,MAAMD,EAAAA,QAAsB,KAAK,CAAE,MAAO,GAAM,CAAC,CACjD,EAAA,QAAO,KAAK,oCAAoC"}
|
|
@@ -0,0 +1,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=[t,n,c],f=[i,r,o,a],p=async(r,i,{schemaPrefix:a=`sadot-migration`,schemaVersion:o=`49c9dd1d-b1cc-445b-a911-fd349d783110`,useCustomFieldsEntries:f=!1}={})=>{let p=`${a}_${o}${f?`_withEntries`:``}`;if(e.info(`custom-fields: initialize custom-fields tables`),!r.addModels)throw Error(`sequelize instance must have addModels function`);f&&d.push(s),r.addModels(d),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===p);if(e.info(`custom-fields: migrations`,{migrations:h,currentSadotSchemaVersion:g,expectedSchemaVersionIndex:_}),(!g||g.name!==p)&&(e.info(`custom-fields: syncing models`),await t.sync({alter:!0}),await n.sync({alter:!0}),f&&await s.sync({alter:!0}),await c.sync({alter:!0}),_===-1&&await m.create({name:p}),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)}}})}},m=async t=>{if(e.info(`custom-fields: initialize custom-fields test models`),!t.addModels)throw Error(`sequelize instance must have addModels function`);t.addModels(f),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{p as initTables,m as initTestModels};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["productionModels: ProductionModel[]","CustomFieldDefinition","CustomFieldValue","CustomValidator","TestModel","AssociatedTestModel","ContextAwareTestModel","ContextTestModel","CustomFieldEntries"],"sources":["../../src/models/index.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport { DataTypes, Op } from 'sequelize';\nimport type { Sequelize } from 'sequelize-typescript';\nimport logger from '../utils/logger';\nimport CustomFieldDefinition from './CustomFieldDefinition';\nimport CustomFieldValue from './CustomFieldValue';\nimport TestModel from './tests/TestModel';\nimport ContextAwareTestModel from './tests/contextAwareModels/ContextAwareTestModel';\nimport ContextTestModel from './tests/contextAwareModels/ContextTestModel';\nimport AssociatedTestModel from './tests/AssociatedTestModel';\nimport type { CustomFieldOptions } from '../types';\nimport CustomFieldEntries from './CustomFieldEntries';\nimport CustomValidator from './CustomValidator';\n\ntype ProductionModel = typeof CustomFieldDefinition | typeof CustomFieldValue | typeof CustomFieldEntries | typeof CustomValidator\ninterface InitTablesOptions {\n schemaPrefix?: string\n schemaVersion?: string\n useCustomFieldsEntries?: boolean\n}\n\nconst productionModels: ProductionModel[] = [CustomFieldDefinition, CustomFieldValue, CustomValidator];\nconst testModels = [TestModel, AssociatedTestModel, ContextAwareTestModel, ContextTestModel];\n\nconst SADOT_MIGRATION_PREFIX = 'sadot-migration';\nconst SCHEMA_VERSION = '49c9dd1d-b1cc-445b-a911-fd349d783110';\n\nconst initTables = async (\n sequelize: Sequelize,\n getUser: CustomFieldOptions['getUser'],\n {\n schemaPrefix = SADOT_MIGRATION_PREFIX,\n schemaVersion = SCHEMA_VERSION,\n useCustomFieldsEntries = false,\n }: InitTablesOptions = {},\n): Promise<void> => {\n const CUSTOM_FIELDS_SCHEMA_VERSION = `${schemaPrefix}_${schemaVersion}${useCustomFieldsEntries ? '_withEntries' : ''}`;\n logger.info('custom-fields: initialize custom-fields tables');\n // Detect models and import them to the orm\n // eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n if (!sequelize.addModels) {\n throw new Error('sequelize instance must have addModels function');\n }\n\n if (useCustomFieldsEntries) {\n productionModels.push(CustomFieldEntries);\n }\n\n sequelize.addModels(productionModels);\n\n CustomFieldDefinition.addScope('userScope', () => {\n const user = getUser();\n if (!user?.permissions) {\n return {};\n }\n return {\n where: {\n entityId: [\n ...Object.keys(user.permissions.fleets),\n ...Object.keys(user.permissions.businessModels),\n ...Object.keys(user.permissions.demandSources),\n ],\n },\n };\n });\n\n CustomValidator.addScope('userScope', () => {\n const user = getUser();\n if (!user?.permissions) {\n return {};\n }\n return {\n where: {\n entityId: [\n ...Object.keys(user.permissions.fleets),\n ...Object.keys(user.permissions.businessModels),\n ...Object.keys(user.permissions.demandSources),\n ],\n },\n };\n });\n\n logger.info('custom-fields: models added');\n\n const SequelizeMeta = sequelize.define(\n 'SequelizeMeta',\n {\n name: {\n type: DataTypes.STRING,\n allowNull: false,\n unique: true,\n primaryKey: true,\n autoIncrement: false,\n },\n },\n {\n tableName: 'SequelizeMeta',\n timestamps: false,\n schema: 'public',\n },\n );\n\n logger.info('custom-fields: starting migrations');\n const migrations = await SequelizeMeta.findAll({ where: { name: { [Op.like]: `${schemaPrefix}%` } }, raw: true });\n const currentSadotSchemaVersion = migrations.at(-1);\n const expectedSchemaVersionIndex = migrations.findIndex((m) => (m as any).name === CUSTOM_FIELDS_SCHEMA_VERSION);\n\n logger.info('custom-fields: migrations', { migrations, currentSadotSchemaVersion, expectedSchemaVersionIndex });\n if (!currentSadotSchemaVersion || (currentSadotSchemaVersion as any).name !== CUSTOM_FIELDS_SCHEMA_VERSION) {\n logger.info('custom-fields: syncing models');\n await CustomFieldDefinition.sync({ alter: true });\n await CustomFieldValue.sync({ alter: true });\n // T.Y TODO: Remove the if statement once we're ready to add the new entries table for all MS\n if (useCustomFieldsEntries) {\n await CustomFieldEntries.sync({ alter: true });\n }\n\n // Always sync CustomValidator\n await CustomValidator.sync({ alter: true });\n\n if (expectedSchemaVersionIndex === -1) {\n await SequelizeMeta.create({ name: CUSTOM_FIELDS_SCHEMA_VERSION });\n }\n logger.info('custom-fields: models synced');\n if (migrations.length && expectedSchemaVersionIndex !== -1 && expectedSchemaVersionIndex < migrations.length - 1) {\n // We have existing migrations, and we are calling `sync`.\n // This means we are in a `down` migration, and hence we should delete newer migrations to ensure we can reapply them.\n const migrationsToDelete = migrations.slice(expectedSchemaVersionIndex + 1);\n await SequelizeMeta.destroy({ where: { name: { [Op.in]: migrationsToDelete.map((m) => (m as any).name) } } });\n }\n }\n};\n\nconst initTestModels = async (sequelize: Sequelize): Promise<void> => {\n logger.info('custom-fields: initialize custom-fields test models');\n // Detect models and import them to the orm\n // eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n if (!sequelize.addModels) {\n throw new Error('sequelize instance must have addModels function');\n }\n\n sequelize.addModels(testModels);\n await sequelize.dropSchema('custom-fields', { logging: false });\n await sequelize.createSchema('custom-fields', { logging: false });\n\n logger.info('custom-fields: test models added');\n await TestModel.sync({ alter: true });\n await AssociatedTestModel.sync({ alter: true });\n await ContextTestModel.sync({ alter: true });\n await ContextAwareTestModel.sync({ alter: true });\n logger.info('custom-fields: test models synced');\n};\n\nexport {\n CustomFieldValue,\n CustomFieldDefinition,\n CustomFieldEntries,\n CustomValidator,\n TestModel,\n AssociatedTestModel,\n ContextAwareTestModel,\n ContextTestModel,\n initTables,\n initTestModels,\n};\n"],"mappings":"mcAqBA,MAAMA,EAAsC,CAACC,EAAuBC,EAAkBC,EAAgB,CAChG,EAAa,CAACC,EAAWC,EAAqBC,EAAuBC,EAAiB,CAKtF,EAAa,MACjB,EACA,EACA,CACE,eAAe,kBACf,gBAAgB,uCAChB,yBAAyB,IACJ,EAAE,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virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.cjs`),r=require(`./TestModel.cjs`);let i=require(`sequelize-typescript`);i=e.__toESM(i);var a;let o=class extends i.Model{};n.__decorate([i.PrimaryKey,(0,i.Column)({type:i.DataType.UUID,defaultValue:i.DataType.UUIDV4,allowNull:!1}),t.__decorateMetadata(`design:type`,String)],o.prototype,`id`,void 0),n.__decorate([(0,i.ForeignKey)(()=>r.default),(0,i.Column)({type:i.DataType.UUID,allowNull:!1}),t.__decorateMetadata(`design:type`,String)],o.prototype,`testModelId`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.UUID,allowNull:!1}),t.__decorateMetadata(`design:type`,String)],o.prototype,`fleetId`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.UUID,allowNull:!0}),t.__decorateMetadata(`design:type`,String)],o.prototype,`businessModelId`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.UUID,allowNull:!0}),t.__decorateMetadata(`design:type`,String)],o.prototype,`demandSourceId`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.BOOLEAN}),t.__decorateMetadata(`design:type`,Boolean)],o.prototype,`anotherAttribute`,void 0),n.__decorate([(0,i.BelongsTo)(()=>r.default),t.__decorateMetadata(`design:type`,typeof(a=r.default!==void 0&&r.default)==`function`?a:Object)],o.prototype,`testModel`,void 0),o=n.__decorate([(0,i.Table)({schema:`custom-fields`,tableName:`associated_test_models`,createdAt:!1,updatedAt:!1})],o);var s=o;exports.default=s;
|
|
2
|
+
//# sourceMappingURL=AssociatedTestModel.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AssociatedTestModel.cjs","names":["AssociatedTestModel","Model","PrimaryKey","DataType","TestModel"],"sources":["../../../src/models/tests/AssociatedTestModel.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n ForeignKey,\n BelongsTo,\n} from 'sequelize-typescript';\nimport TestModel from './TestModel';\n\n@Table({\n schema: 'custom-fields', tableName: 'associated_test_models', createdAt: false, updatedAt: false,\n})\nclass AssociatedTestModel extends Model {\n @PrimaryKey\n @Column({\n type: DataType.UUID,\n defaultValue: DataType.UUIDV4,\n allowNull: false,\n })\n declare id: string;\n\n @ForeignKey(() => TestModel)\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n testModelId!: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n fleetId: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: true,\n })\n businessModelId: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: true,\n })\n demandSourceId: string;\n\n @Column({\n type: DataType.BOOLEAN,\n })\n anotherAttribute?: boolean;\n\n @BelongsTo(() => TestModel)\n testModel: TestModel;\n}\n\nexport default AssociatedTestModel;\n"],"mappings":"mTAYA,IAAA,EAAA,cAGkCC,EAAAA,KAAM,iBACrCC,EAAAA,wBACO,CACN,KAAMC,EAAAA,SAAS,KACf,aAAcA,EAAAA,SAAS,OACvB,UAAW,GACZ,CAAC,yGAGgBC,EAAAA,QAAU,cACpB,CACN,KAAMD,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,0GAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,UAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,kBAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,iBAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,QAChB,CAAC,CAAA,EAAA,mBAAA,cAAA,QAAA,CAAA,CAAA,EAAA,UAAA,mBAAA,IAAA,GAAA,mCAGeC,EAAAA,QAAU,CAAA,EAAA,mBAAA,cAAA,OAAA,EAAA,EAAA,UAAA,QAAA,EAAA,UAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,6BA1CtB,CACL,OAAQ,gBAAiB,UAAW,yBAA0B,UAAW,GAAO,UAAW,GAC5F,CAAC,CAAA,CAAA,EAAA,CA4CF,IAAA,EAAe"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{__decorateMetadata as e}from"../../_virtual/_@oxc-project_runtime@0.89.0/helpers/decorateMetadata.js";import{__decorate as t}from"../../_virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.js";import n from"./TestModel.js";import{BelongsTo as r,Column as i,DataType as a,ForeignKey as o,Model as s,PrimaryKey as c,Table as l}from"sequelize-typescript";var u;let d=class extends s{};t([c,i({type:a.UUID,defaultValue:a.UUIDV4,allowNull:!1}),e(`design:type`,String)],d.prototype,`id`,void 0),t([o(()=>n),i({type:a.UUID,allowNull:!1}),e(`design:type`,String)],d.prototype,`testModelId`,void 0),t([i({type:a.UUID,allowNull:!1}),e(`design:type`,String)],d.prototype,`fleetId`,void 0),t([i({type:a.UUID,allowNull:!0}),e(`design:type`,String)],d.prototype,`businessModelId`,void 0),t([i({type:a.UUID,allowNull:!0}),e(`design:type`,String)],d.prototype,`demandSourceId`,void 0),t([i({type:a.BOOLEAN}),e(`design:type`,Boolean)],d.prototype,`anotherAttribute`,void 0),t([r(()=>n),e(`design:type`,typeof(u=n!==void 0&&n)==`function`?u:Object)],d.prototype,`testModel`,void 0),d=t([l({schema:`custom-fields`,tableName:`associated_test_models`,createdAt:!1,updatedAt:!1})],d);var f=d;export{f as default};
|
|
2
|
+
//# sourceMappingURL=AssociatedTestModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AssociatedTestModel.js","names":["AssociatedTestModel","TestModel"],"sources":["../../../src/models/tests/AssociatedTestModel.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n ForeignKey,\n BelongsTo,\n} from 'sequelize-typescript';\nimport TestModel from './TestModel';\n\n@Table({\n schema: 'custom-fields', tableName: 'associated_test_models', createdAt: false, updatedAt: false,\n})\nclass AssociatedTestModel extends Model {\n @PrimaryKey\n @Column({\n type: DataType.UUID,\n defaultValue: DataType.UUIDV4,\n allowNull: false,\n })\n declare id: string;\n\n @ForeignKey(() => TestModel)\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n testModelId!: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n fleetId: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: true,\n })\n businessModelId: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: true,\n })\n demandSourceId: string;\n\n @Column({\n type: DataType.BOOLEAN,\n })\n anotherAttribute?: boolean;\n\n @BelongsTo(() => TestModel)\n testModel: TestModel;\n}\n\nexport default AssociatedTestModel;\n"],"mappings":"+WAYA,IAAA,EAAA,cAGkC,CAAM,MACrC,EACA,EAAO,CACN,KAAM,EAAS,KACf,aAAc,EAAS,OACvB,UAAW,GACZ,CAAC,sDAGD,MAAiBC,EAAU,CAC3B,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,+DAGD,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,UAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,kBAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,iBAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,QAChB,CAAC,CAAA,EAAA,cAAA,QAAA,CAAA,CAAA,EAAA,UAAA,mBAAA,IAAA,GAAA,IAGD,MAAgBA,EAAU,CAAA,EAAA,cAAA,OAAA,EAAA,IAAA,QAAA,IAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,YAAA,IAAA,GAAA,MA1C5B,EAAM,CACL,OAAQ,gBAAiB,UAAW,yBAA0B,UAAW,GAAO,UAAW,GAC5F,CAAC,CAAA,CAAA,EAAA,CA4CF,IAAA,EAAe"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`../../_virtual/rolldown_runtime.cjs`),t=require(`../../_virtual/_@oxc-project_runtime@0.89.0/helpers/decorateMetadata.cjs`),n=require(`../../_virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.cjs`),r=require(`./AssociatedTestModel.cjs`);let i=require(`sequelize-typescript`);i=e.__toESM(i);let a=class extends i.Model{};n.__decorate([i.PrimaryKey,(0,i.Column)({type:i.DataType.UUID,defaultValue:i.DataType.UUIDV4,allowNull:!1}),t.__decorateMetadata(`design:type`,String)],a.prototype,`id`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.UUID,allowNull:!1}),t.__decorateMetadata(`design:type`,String)],a.prototype,`fleetId`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.UUID,allowNull:!0}),t.__decorateMetadata(`design:type`,String)],a.prototype,`businessModelId`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.UUID,allowNull:!0}),t.__decorateMetadata(`design:type`,String)],a.prototype,`demandSourceId`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.BOOLEAN}),t.__decorateMetadata(`design:type`,Boolean)],a.prototype,`coolAttribute`,void 0),n.__decorate([(0,i.HasMany)(()=>r.default),t.__decorateMetadata(`design:type`,Array)],a.prototype,`associatedModels`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.VIRTUAL}),t.__decorateMetadata(`design:type`,Object)],a.prototype,`customFields`,void 0),a=n.__decorate([(0,i.Table)({schema:`custom-fields`,tableName:`test_models`,createdAt:!1,updatedAt:!1})],a);var o=a;exports.default=o;
|
|
2
|
+
//# sourceMappingURL=TestModel.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TestModel.cjs","names":["TestModel","Model","PrimaryKey","DataType","AssociatedTestModel"],"sources":["../../../src/models/tests/TestModel.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n HasMany,\n} from 'sequelize-typescript';\nimport AssociatedTestModel from './AssociatedTestModel';\n\n@Table({\n schema: 'custom-fields', tableName: 'test_models', createdAt: false, updatedAt: false,\n})\nclass TestModel extends Model {\n @PrimaryKey\n @Column({\n type: DataType.UUID,\n defaultValue: DataType.UUIDV4,\n allowNull: false,\n })\n declare id: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n fleetId: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: true,\n })\n businessModelId: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: true,\n })\n demandSourceId: string;\n\n @Column({\n type: DataType.BOOLEAN,\n })\n coolAttribute?: boolean;\n\n @HasMany(() => AssociatedTestModel)\n associatedModels: AssociatedTestModel[];\n\n @Column({\n type: DataType.VIRTUAL,\n })\n customFields?: any;\n}\n\nexport default TestModel;\n"],"mappings":"uTAWA,IAAA,EAAA,cAGwBC,EAAAA,KAAM,iBAC3BC,EAAAA,wBACO,CACN,KAAMC,EAAAA,SAAS,KACf,aAAcA,EAAAA,SAAS,OACvB,UAAW,GACZ,CAAC,iGAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,UAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,kBAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,iBAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,QAChB,CAAC,CAAA,EAAA,mBAAA,cAAA,QAAA,CAAA,CAAA,EAAA,UAAA,gBAAA,IAAA,GAAA,iCAGaC,EAAAA,QAAoB,CAAA,EAAA,mBAAA,cAAA,MAAA,CAAA,CAAA,EAAA,UAAA,mBAAA,IAAA,GAAA,4BAG3B,CACN,KAAMD,EAAAA,SAAS,QAChB,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,eAAA,IAAA,GAAA,6BAxCG,CACL,OAAQ,gBAAiB,UAAW,cAAe,UAAW,GAAO,UAAW,GACjF,CAAC,CAAA,CAAA,EAAA,CA0CF,IAAA,EAAe"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{__decorateMetadata as e}from"../../_virtual/_@oxc-project_runtime@0.89.0/helpers/decorateMetadata.js";import{__decorate as t}from"../../_virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.js";import n from"./AssociatedTestModel.js";import{Column as r,DataType as i,HasMany as a,Model as o,PrimaryKey as s,Table as c}from"sequelize-typescript";let l=class extends o{};t([s,r({type:i.UUID,defaultValue:i.UUIDV4,allowNull:!1}),e(`design:type`,String)],l.prototype,`id`,void 0),t([r({type:i.UUID,allowNull:!1}),e(`design:type`,String)],l.prototype,`fleetId`,void 0),t([r({type:i.UUID,allowNull:!0}),e(`design:type`,String)],l.prototype,`businessModelId`,void 0),t([r({type:i.UUID,allowNull:!0}),e(`design:type`,String)],l.prototype,`demandSourceId`,void 0),t([r({type:i.BOOLEAN}),e(`design:type`,Boolean)],l.prototype,`coolAttribute`,void 0),t([a(()=>n),e(`design:type`,Array)],l.prototype,`associatedModels`,void 0),t([r({type:i.VIRTUAL}),e(`design:type`,Object)],l.prototype,`customFields`,void 0),l=t([c({schema:`custom-fields`,tableName:`test_models`,createdAt:!1,updatedAt:!1})],l);var u=l;export{u as default};
|
|
2
|
+
//# sourceMappingURL=TestModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TestModel.js","names":["TestModel","AssociatedTestModel"],"sources":["../../../src/models/tests/TestModel.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n HasMany,\n} from 'sequelize-typescript';\nimport AssociatedTestModel from './AssociatedTestModel';\n\n@Table({\n schema: 'custom-fields', tableName: 'test_models', createdAt: false, updatedAt: false,\n})\nclass TestModel extends Model {\n @PrimaryKey\n @Column({\n type: DataType.UUID,\n defaultValue: DataType.UUIDV4,\n allowNull: false,\n })\n declare id: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: false,\n })\n fleetId: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: true,\n })\n businessModelId: string;\n\n @Column({\n type: DataType.UUID,\n allowNull: true,\n })\n demandSourceId: string;\n\n @Column({\n type: DataType.BOOLEAN,\n })\n coolAttribute?: boolean;\n\n @HasMany(() => AssociatedTestModel)\n associatedModels: AssociatedTestModel[];\n\n @Column({\n type: DataType.VIRTUAL,\n })\n customFields?: any;\n}\n\nexport default TestModel;\n"],"mappings":"iWAWA,IAAA,EAAA,cAGwB,CAAM,MAC3B,EACA,EAAO,CACN,KAAM,EAAS,KACf,aAAc,EAAS,OACvB,UAAW,GACZ,CAAC,sDAGD,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,UAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,kBAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,KACf,UAAW,GACZ,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,iBAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,QAChB,CAAC,CAAA,EAAA,cAAA,QAAA,CAAA,CAAA,EAAA,UAAA,gBAAA,IAAA,GAAA,IAGD,MAAcC,EAAoB,CAAA,EAAA,cAAA,MAAA,CAAA,CAAA,EAAA,UAAA,mBAAA,IAAA,GAAA,IAGlC,EAAO,CACN,KAAM,EAAS,QAChB,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,eAAA,IAAA,GAAA,MAxCH,EAAM,CACL,OAAQ,gBAAiB,UAAW,cAAe,UAAW,GAAO,UAAW,GACjF,CAAC,CAAA,CAAA,EAAA,CA0CF,IAAA,EAAe"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`../../../_virtual/rolldown_runtime.cjs`),t=require(`../../../_virtual/_@oxc-project_runtime@0.89.0/helpers/decorateMetadata.cjs`),n=require(`../../../_virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.cjs`),r=require(`./ContextTestModel.cjs`);let i=require(`sequelize-typescript`);i=e.__toESM(i);var a;let o=class extends i.Model{};n.__decorate([i.PrimaryKey,(0,i.Column)({type:i.DataType.UUID,defaultValue:i.DataType.UUIDV4,allowNull:!1}),t.__decorateMetadata(`design:type`,String)],o.prototype,`id`,void 0),n.__decorate([(0,i.ForeignKey)(()=>r.default),(0,i.Column)({type:i.DataType.UUID}),t.__decorateMetadata(`design:type`,String)],o.prototype,`contextId`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.BOOLEAN}),t.__decorateMetadata(`design:type`,Boolean)],o.prototype,`coolAttribute`,void 0),n.__decorate([(0,i.Column)({type:i.DataType.VIRTUAL}),t.__decorateMetadata(`design:type`,Object)],o.prototype,`customFields`,void 0),n.__decorate([(0,i.BelongsTo)(()=>r.default),t.__decorateMetadata(`design:type`,typeof(a=r.default!==void 0&&r.default)==`function`?a:Object)],o.prototype,`context`,void 0),o=n.__decorate([(0,i.Table)({createdAt:!1,updatedAt:!1})],o);var s=o;exports.default=s;
|
|
2
|
+
//# sourceMappingURL=ContextAwareTestModel.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContextAwareTestModel.cjs","names":["ContextAwareTestModel","Model","PrimaryKey","DataType","ContextTestModel"],"sources":["../../../../src/models/tests/contextAwareModels/ContextAwareTestModel.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n HasMany,\n BelongsTo,\n ForeignKey,\n} from 'sequelize-typescript';\nimport AssociatedTestModel from '../AssociatedTestModel';\nimport ContextTestModel from './ContextTestModel';\n\n@Table({ createdAt: false, updatedAt: false })\nclass ContextAwareTestModel extends Model {\n @PrimaryKey\n @Column({\n type: DataType.UUID,\n defaultValue: DataType.UUIDV4,\n allowNull: false,\n })\n declare id: string;\n\n @ForeignKey(() => ContextTestModel)\n @Column({ type: DataType.UUID })\n contextId: string;\n\n @Column({\n type: DataType.BOOLEAN,\n })\n coolAttribute?: boolean;\n\n @Column({\n type: DataType.VIRTUAL,\n })\n customFields?: any;\n\n @BelongsTo(() => ContextTestModel)\n context: ContextTestModel;\n}\n\nexport default ContextAwareTestModel;\n"],"mappings":"mUAcA,IAAA,EAAA,cACoCC,EAAAA,KAAM,iBACvCC,EAAAA,wBACO,CACN,KAAMC,EAAAA,SAAS,KACf,aAAcA,EAAAA,SAAS,OACvB,UAAW,GACZ,CAAC,yGAGgBC,EAAAA,QAAiB,cAC3B,CAAE,KAAMD,EAAAA,SAAS,KAAM,CAAC,wGAGxB,CACN,KAAMA,EAAAA,SAAS,QAChB,CAAC,CAAA,EAAA,mBAAA,cAAA,QAAA,CAAA,CAAA,EAAA,UAAA,gBAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,QAChB,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,eAAA,IAAA,GAAA,mCAGeC,EAAAA,QAAiB,CAAA,EAAA,mBAAA,cAAA,OAAA,EAAA,EAAA,UAAA,QAAA,EAAA,UAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,UAAA,IAAA,GAAA,6BAxB7B,CAAE,UAAW,GAAO,UAAW,GAAO,CAAC,CAAA,CAAA,EAAA,CA4B9C,IAAA,EAAe"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{__decorateMetadata as e}from"../../../_virtual/_@oxc-project_runtime@0.89.0/helpers/decorateMetadata.js";import{__decorate as t}from"../../../_virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.js";import n from"./ContextTestModel.js";import{BelongsTo as r,Column as i,DataType as a,ForeignKey as o,Model as s,PrimaryKey as c,Table as l}from"sequelize-typescript";var u;let d=class extends s{};t([c,i({type:a.UUID,defaultValue:a.UUIDV4,allowNull:!1}),e(`design:type`,String)],d.prototype,`id`,void 0),t([o(()=>n),i({type:a.UUID}),e(`design:type`,String)],d.prototype,`contextId`,void 0),t([i({type:a.BOOLEAN}),e(`design:type`,Boolean)],d.prototype,`coolAttribute`,void 0),t([i({type:a.VIRTUAL}),e(`design:type`,Object)],d.prototype,`customFields`,void 0),t([r(()=>n),e(`design:type`,typeof(u=n!==void 0&&n)==`function`?u:Object)],d.prototype,`context`,void 0),d=t([l({createdAt:!1,updatedAt:!1})],d);var f=d;export{f as default};
|
|
2
|
+
//# sourceMappingURL=ContextAwareTestModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContextAwareTestModel.js","names":["ContextAwareTestModel","ContextTestModel"],"sources":["../../../../src/models/tests/contextAwareModels/ContextAwareTestModel.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n HasMany,\n BelongsTo,\n ForeignKey,\n} from 'sequelize-typescript';\nimport AssociatedTestModel from '../AssociatedTestModel';\nimport ContextTestModel from './ContextTestModel';\n\n@Table({ createdAt: false, updatedAt: false })\nclass ContextAwareTestModel extends Model {\n @PrimaryKey\n @Column({\n type: DataType.UUID,\n defaultValue: DataType.UUIDV4,\n allowNull: false,\n })\n declare id: string;\n\n @ForeignKey(() => ContextTestModel)\n @Column({ type: DataType.UUID })\n contextId: string;\n\n @Column({\n type: DataType.BOOLEAN,\n })\n coolAttribute?: boolean;\n\n @Column({\n type: DataType.VIRTUAL,\n })\n customFields?: any;\n\n @BelongsTo(() => ContextTestModel)\n context: ContextTestModel;\n}\n\nexport default ContextAwareTestModel;\n"],"mappings":"4XAcA,IAAA,EAAA,cACoC,CAAM,MACvC,EACA,EAAO,CACN,KAAM,EAAS,KACf,aAAc,EAAS,OACvB,UAAW,GACZ,CAAC,sDAGD,MAAiBC,EAAiB,CAClC,EAAO,CAAE,KAAM,EAAS,KAAM,CAAC,6DAG/B,EAAO,CACN,KAAM,EAAS,QAChB,CAAC,CAAA,EAAA,cAAA,QAAA,CAAA,CAAA,EAAA,UAAA,gBAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,QAChB,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,eAAA,IAAA,GAAA,IAGD,MAAgBA,EAAiB,CAAA,EAAA,cAAA,OAAA,EAAA,IAAA,QAAA,IAAA,WAAA,EAAA,OAAA,CAAA,CAAA,EAAA,UAAA,UAAA,IAAA,GAAA,MAxBnC,EAAM,CAAE,UAAW,GAAO,UAAW,GAAO,CAAC,CAAA,CAAA,EAAA,CA4B9C,IAAA,EAAe"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`../../../_virtual/rolldown_runtime.cjs`),t=require(`../../../_virtual/_@oxc-project_runtime@0.89.0/helpers/decorateMetadata.cjs`),n=require(`../../../_virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.cjs`);let r=require(`sequelize-typescript`);r=e.__toESM(r);var i=function(e){return e.BUSINESS_MODEL=`businessModel`,e.CONTEXT=`context`,e.DEMAND_SOURCE=`demandSource`,e.FLEET=`fleet`,e}(i||{});let a=class extends r.Model{};n.__decorate([r.PrimaryKey,(0,r.Column)({defaultValue:r.DataType.UUIDV4,type:r.DataType.UUID}),t.__decorateMetadata(`design:type`,String)],a.prototype,`id`,void 0),n.__decorate([(0,r.Column)({type:r.DataType.UUID}),t.__decorateMetadata(`design:type`,String)],a.prototype,`entityId`,void 0),n.__decorate([(0,r.Column)({type:r.DataType.ENUM(...Object.values(i))}),t.__decorateMetadata(`design:type`,String)],a.prototype,`entityType`,void 0),a=n.__decorate([(0,r.Table)({createdAt:!1,updatedAt:!1})],a);var o=a;exports.default=o;
|
|
2
|
+
//# sourceMappingURL=ContextTestModel.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContextTestModel.cjs","names":["ContextTestModel","Model","PrimaryKey","DataType"],"sources":["../../../../src/models/tests/contextAwareModels/ContextTestModel.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n} from 'sequelize-typescript';\n\n// eslint-disable-next-line no-shadow\n enum EEntityTypes {\n BUSINESS_MODEL = 'businessModel',\n CONTEXT = 'context',\n DEMAND_SOURCE = 'demandSource',\n FLEET = 'fleet',\n}\n\n@Table({ createdAt: false, updatedAt: false })\nclass ContextTestModel extends Model {\n @PrimaryKey\n @Column({\n defaultValue: DataType.UUIDV4,\n type: DataType.UUID,\n })\n declare id: string;\n\n @Column({\n type: DataType.UUID,\n })\n entityId: string;\n\n @Column({\n type: DataType.ENUM(...Object.values(EEntityTypes)),\n })\n entityType: EEntityTypes;\n}\n\nexport default ContextTestModel;\n"],"mappings":"yRAUC,IAAK,EAAA,SAAA,EAAL,OACC,GAAA,eAAA,gBACA,EAAA,QAAA,UACA,EAAA,cAAA,eACA,EAAA,MAAA,WAJI,GAAA,EAAA,CAAA,CAON,IAAA,EAAA,cAC+BC,EAAAA,KAAM,iBAClCC,EAAAA,wBACO,CACN,aAAcC,EAAAA,SAAS,OACvB,KAAMA,EAAAA,SAAS,KAChB,CAAC,iGAGM,CACN,KAAMA,EAAAA,SAAS,KAChB,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,WAAA,IAAA,GAAA,4BAGM,CACN,KAAMA,EAAAA,SAAS,KAAK,GAAG,OAAO,OAAO,EAAa,CAAC,CACpD,CAAC,CAAA,EAAA,mBAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,aAAA,IAAA,GAAA,6BAhBG,CAAE,UAAW,GAAO,UAAW,GAAO,CAAC,CAAA,CAAA,EAAA,CAoB9C,IAAA,EAAe"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{__decorateMetadata as e}from"../../../_virtual/_@oxc-project_runtime@0.89.0/helpers/decorateMetadata.js";import{__decorate as t}from"../../../_virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.js";import{Column as n,DataType as r,Model as i,PrimaryKey as a,Table as o}from"sequelize-typescript";var s=function(e){return e.BUSINESS_MODEL=`businessModel`,e.CONTEXT=`context`,e.DEMAND_SOURCE=`demandSource`,e.FLEET=`fleet`,e}(s||{});let c=class extends i{};t([a,n({defaultValue:r.UUIDV4,type:r.UUID}),e(`design:type`,String)],c.prototype,`id`,void 0),t([n({type:r.UUID}),e(`design:type`,String)],c.prototype,`entityId`,void 0),t([n({type:r.ENUM(...Object.values(s))}),e(`design:type`,String)],c.prototype,`entityType`,void 0),c=t([o({createdAt:!1,updatedAt:!1})],c);var l=c;export{l as default};
|
|
2
|
+
//# sourceMappingURL=ContextTestModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContextTestModel.js","names":["ContextTestModel"],"sources":["../../../../src/models/tests/contextAwareModels/ContextTestModel.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport {\n Table,\n Column,\n Model,\n PrimaryKey,\n DataType,\n} from 'sequelize-typescript';\n\n// eslint-disable-next-line no-shadow\n enum EEntityTypes {\n BUSINESS_MODEL = 'businessModel',\n CONTEXT = 'context',\n DEMAND_SOURCE = 'demandSource',\n FLEET = 'fleet',\n}\n\n@Table({ createdAt: false, updatedAt: false })\nclass ContextTestModel extends Model {\n @PrimaryKey\n @Column({\n defaultValue: DataType.UUIDV4,\n type: DataType.UUID,\n })\n declare id: string;\n\n @Column({\n type: DataType.UUID,\n })\n entityId: string;\n\n @Column({\n type: DataType.ENUM(...Object.values(EEntityTypes)),\n })\n entityType: EEntityTypes;\n}\n\nexport default ContextTestModel;\n"],"mappings":"kTAUC,IAAK,EAAA,SAAA,EAAL,OACC,GAAA,eAAA,gBACA,EAAA,QAAA,UACA,EAAA,cAAA,eACA,EAAA,MAAA,WAJI,GAAA,EAAA,CAAA,CAON,IAAA,EAAA,cAC+B,CAAM,MAClC,EACA,EAAO,CACN,aAAc,EAAS,OACvB,KAAM,EAAS,KAChB,CAAC,sDAGD,EAAO,CACN,KAAM,EAAS,KAChB,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,WAAA,IAAA,GAAA,IAGD,EAAO,CACN,KAAM,EAAS,KAAK,GAAG,OAAO,OAAO,EAAa,CAAC,CACpD,CAAC,CAAA,EAAA,cAAA,OAAA,CAAA,CAAA,EAAA,UAAA,aAAA,IAAA,GAAA,MAhBH,EAAM,CAAE,UAAW,GAAO,UAAW,GAAO,CAAC,CAAA,CAAA,EAAA,CAoB9C,IAAA,EAAe"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../errors/index.cjs`),n=require(`../models/CustomFieldDefinition.cjs`);require(`../models/index.cjs`);let r=require(`sequelize`);r=e.__toESM(r);const i=e=>n.default.create(e),a=(e,t={withDisabled:!1})=>(t.withDisabled?n.default.unscoped():n.default).scope(`userScope`).findAll({where:e,transaction:t.transaction,raw:!0,include:t.include}),o=(e,t={withDisabled:!1})=>a({id:{[r.Op.in]:e}},t),s=(e,t={withDisabled:!1})=>{let{withDisabled:r}=t;return r?n.default.unscoped().scope(`userScope`).findByPk(e):n.default.scope(`userScope`).findByPk(e)},c=async(e,t,i={})=>{let{include:a,useEntityIdFromInclude:o}=i.modelOptions,s={modelType:e,...!o&&{entityId:{[r.Op.in]:t}}};return n.default.findAll({where:s,transaction:i.transaction,include:a?.(t),raw:!0})},l=e=>n.default.scope(`userScope`).findOne({where:e}),u=async(e,t)=>(await n.default.scope(`userScope`).update(t,{where:{id:e},returning:!0,individualHooks:!0}))[1][0],d=async(e,{findAll:n,modelOptions:i={},withDisabled:o=!1,...s}={withDisabled:!1,modelOptions:{}})=>{let{modelType:c}=e[0]?.dataValues??{},l=new Set,u=[],d=new Set;e.forEach(e=>{let{dataValues:{modelId:t,entityId:n,customFields:r}}=e;u.push(t),d.add(n),Object.keys(r??{}).forEach(e=>{l.add(e)})});let f={modelType:c,entityId:{[r.Op.in]:Array.from(d)},name:{[r.Op.in]:Array.from(l)}},p=await(n??a)(f,{withDisabled:o,modelOptions:i,...s}),m=p.filter(e=>l.has(e.name)),h=Object.fromEntries(m.map(e=>[e.name,e]));if(!p?.length||m.length!==l.size){let e=Array.from(l).filter(e=>!h[e]);throw new t.MissingDefinitionError(e)}return h};exports.create=i,exports.findAll=a,exports.findByEntityIds=c,exports.findById=s,exports.findByIds=o,exports.findByWhere=l,exports.getCustomFieldDefinitionsDictionary=d,exports.update=u;
|
|
2
|
+
//# sourceMappingURL=definition.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definition.cjs","names":["CustomFieldDefinition","Op","where: WhereOptions","MissingDefinitionError"],"sources":["../../src/repository/definition.ts"],"sourcesContent":["import {\n Op,\n type Includeable, type Transaction, type FindOptions, type WhereOptions, type Transactionable,\n} from 'sequelize';\nimport { CustomFieldDefinition, type CustomFieldEntries } from '../models';\nimport type { CreateCustomFieldDefinition, UpdateCustomFieldDefinition } from '../types/definition';\nimport type { ModelOptions } from '../types';\nimport { MissingDefinitionError } from '../errors';\n\nexport const create = (data: CreateCustomFieldDefinition): Promise<CustomFieldDefinition> =>\n CustomFieldDefinition.create(data);\n\ninterface SadotFindOptions {\n withDisabled?: boolean;\n transaction?: Transaction;\n include?: Includeable | Includeable[];\n}\n\ntype SadotGetDefinitionsByEntityIdsOptions = FindOptions & { modelOptions?: ModelOptions; findAll?: typeof findAll; } & Pick<SadotFindOptions, 'withDisabled'>;\n\nexport const findAll = (\n where: WhereOptions,\n options: SadotFindOptions = { withDisabled: false },\n): Promise<CustomFieldDefinition[]> => {\n const queryModel = options.withDisabled\n ? CustomFieldDefinition.unscoped()\n : CustomFieldDefinition;\n\n return queryModel.scope('userScope').findAll({\n where,\n transaction: options.transaction,\n raw: true,\n include: options.include,\n });\n};\n\nexport const findByIds = (\n ids: string[],\n options: SadotFindOptions = { withDisabled: false },\n): Promise<CustomFieldDefinition[]> => findAll({ id: { [Op.in]: ids } }, options);\n\nexport const findById = (\n id: string,\n options: Pick<SadotFindOptions, 'withDisabled'> = { withDisabled: false },\n): Promise<CustomFieldDefinition | null> => {\n const { withDisabled } = options;\n if (withDisabled) {\n return CustomFieldDefinition.unscoped().scope('userScope').findByPk(id);\n }\n return CustomFieldDefinition.scope('userScope').findByPk(id);\n};\n\nexport const findByEntityIds = async (\n modelType: string,\n entityIds: string[],\n options: FindOptions & { modelOptions?: ModelOptions } = {},\n): Promise<CustomFieldDefinition[]> => {\n const { include, useEntityIdFromInclude } = options.modelOptions;\n const where: WhereOptions = {\n modelType,\n ...(!useEntityIdFromInclude && { entityId: { [Op.in]: entityIds } }),\n };\n\n return CustomFieldDefinition.findAll({\n where,\n transaction: options.transaction,\n include: include?.(entityIds),\n raw: true,\n });\n};\n\nexport const findByWhere = (where: WhereOptions<CustomFieldDefinition>): Promise<CustomFieldDefinition | null> =>\n CustomFieldDefinition.scope('userScope').findOne({\n where,\n });\n\nexport const findDefinitionsByModels = async (\n modelTypes: string[],\n options?: Transactionable,\n): Promise<CustomFieldDefinition[]> => {\n const query: WhereOptions<CreateCustomFieldDefinition> = { modelType: { [Op.in]: modelTypes } };\n return CustomFieldDefinition.findAll({\n where: query,\n transaction: options?.transaction,\n });\n};\n\nexport const update = async (\n id: string,\n data: UpdateCustomFieldDefinition,\n): Promise<CustomFieldDefinition> => {\n const updatedDefinition = (await CustomFieldDefinition.scope('userScope').update(data, {\n where: { id },\n returning: true,\n individualHooks: true,\n }))[1][0];\n return updatedDefinition;\n};\n\nexport const disable = (id: string): Promise<[affectedCount: number]> =>\n CustomFieldDefinition.update(\n { disabled: true },\n { where: { id } },\n );\n\nexport const destroy = (id: string): Promise<number> =>\n CustomFieldDefinition.destroy({ where: { id } });\n\n/**\n * Return the names of the required fields for a given model\n */\nexport const getRequiredFields = async (\n modelType: string,\n modelId: string | string[],\n entityId: string | string[],\n modelOptions: ModelOptions = {},\n): Promise<string[]> => {\n const entityIds = Array.isArray(entityId) ? entityId : [entityId];\n const { include, useEntityIdFromInclude } = modelOptions;\n\n const where: WhereOptions = {\n modelType,\n required: true,\n ...(!useEntityIdFromInclude && { entityId: { [Op.in]: entityIds } }),\n };\n\n const requiredFields = await CustomFieldDefinition.findAll({\n where,\n include: include?.(entityIds),\n logging: true,\n });\n const requiredFieldsNames = requiredFields.map((definition) => definition.name);\n return [...new Set(requiredFieldsNames)];\n};\n\n/**\n * @returns A promise resolving with a dictionary of custom field definitions by name.\n * @throws A {@link MissingDefinitionError} if any of the custom fields doesn't have a definition.\n */\nexport const getCustomFieldDefinitionsDictionary = async (\n instances: CustomFieldEntries[],\n {\n findAll: _findAll,\n modelOptions = {},\n withDisabled = false,\n ...options\n }: SadotGetDefinitionsByEntityIdsOptions = { withDisabled: false, modelOptions: {} },\n): Promise<{ [definitionName: string]: CustomFieldDefinition }> => {\n const { modelType } = instances[0]?.dataValues ?? {};\n const customFields = new Set<string>();\n const modelIds = [];\n const entityIds = new Set<string>();\n instances.forEach((instance) => {\n const { dataValues: { modelId, entityId, customFields: instanceCustomFields } } = instance;\n modelIds.push(modelId);\n entityIds.add(entityId);\n\n Object.keys(instanceCustomFields ?? {}).forEach((fieldName) => {\n customFields.add(fieldName);\n });\n });\n\n const where: WhereOptions = {\n modelType,\n entityId: { [Op.in]: Array.from(entityIds) },\n name: { [Op.in]: Array.from(customFields) },\n };\n\n const findAllToUse = _findAll ?? findAll;\n\n // @ts-expect-error findAll doesn't expect modelOptions at all.\n const definitions = await findAllToUse(where, { withDisabled, modelOptions, ...options });\n\n const matchedDefinitions = definitions.filter((def) => customFields.has(def.name));\n const matchedDefinitionsByName = Object.fromEntries(matchedDefinitions.map((definition) => [definition.name, definition]));\n\n if (!definitions?.length || matchedDefinitions.length !== customFields.size) {\n const unmatchedCustomFields = Array.from(customFields).filter((customField) => !matchedDefinitionsByName[customField]);\n throw new MissingDefinitionError(unmatchedCustomFields);\n }\n\n return matchedDefinitionsByName;\n};\n"],"mappings":"+MASA,MAAa,EAAU,GACrBA,EAAAA,QAAsB,OAAO,EAAK,CAUvB,GACX,EACA,EAA4B,CAAE,aAAc,GAAO,IAEhC,EAAQ,aACvBA,EAAAA,QAAsB,UAAU,CAChCA,EAAAA,SAEc,MAAM,YAAY,CAAC,QAAQ,CAC3C,QACA,YAAa,EAAQ,YACrB,IAAK,GACL,QAAS,EAAQ,QAClB,CAAC,CAGS,GACX,EACA,EAA4B,CAAE,aAAc,GAAO,GACd,EAAQ,CAAE,GAAI,EAAGC,EAAAA,GAAG,IAAK,EAAK,CAAE,CAAE,EAAQ,CAEpE,GACX,EACA,EAAkD,CAAE,aAAc,GAAO,GAC/B,CAC1C,GAAM,CAAE,gBAAiB,EAIzB,OAHI,EACKD,EAAAA,QAAsB,UAAU,CAAC,MAAM,YAAY,CAAC,SAAS,EAAG,CAElEA,EAAAA,QAAsB,MAAM,YAAY,CAAC,SAAS,EAA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AY,OAAQ,GAAQ,EAAa,IAAI,EAAI,KAAK,CAAC,CAC5E,EAA2B,OAAO,YAAY,EAAmB,IAAK,GAAe,CAAC,EAAW,KAAM,EAAW,CAAC,CAAC,CAE1H,GAAI,CAAC,GAAa,QAAU,EAAmB,SAAW,EAAa,KAAM,CAC3E,IAAM,EAAwB,MAAM,KAAK,EAAa,CAAC,OAAQ,GAAgB,CAAC,EAAyB,GAAa,CACtH,MAAM,IAAIE,EAAAA,uBAAuB,EAAsB,CAGzD,OAAO"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{MissingDefinitionError as e}from"../errors/index.js";import t from"../models/CustomFieldDefinition.js";import"../models/index.js";import{Op as n}from"sequelize";const r=e=>t.create(e),i=(e,n={withDisabled:!1})=>(n.withDisabled?t.unscoped():t).scope(`userScope`).findAll({where:e,transaction:n.transaction,raw:!0,include:n.include}),a=(e,t={withDisabled:!1})=>i({id:{[n.in]:e}},t),o=(e,n={withDisabled:!1})=>{let{withDisabled:r}=n;return r?t.unscoped().scope(`userScope`).findByPk(e):t.scope(`userScope`).findByPk(e)},s=async(e,r,i={})=>{let{include:a,useEntityIdFromInclude:o}=i.modelOptions,s={modelType:e,...!o&&{entityId:{[n.in]:r}}};return t.findAll({where:s,transaction:i.transaction,include:a?.(r),raw:!0})},c=e=>t.scope(`userScope`).findOne({where:e}),l=async(e,n)=>(await t.scope(`userScope`).update(n,{where:{id:e},returning:!0,individualHooks:!0}))[1][0],u=async(t,{findAll:r,modelOptions:a={},withDisabled:o=!1,...s}={withDisabled:!1,modelOptions:{}})=>{let{modelType:c}=t[0]?.dataValues??{},l=new Set,u=[],d=new Set;t.forEach(e=>{let{dataValues:{modelId:t,entityId:n,customFields:r}}=e;u.push(t),d.add(n),Object.keys(r??{}).forEach(e=>{l.add(e)})});let f={modelType:c,entityId:{[n.in]:Array.from(d)},name:{[n.in]:Array.from(l)}},p=await(r??i)(f,{withDisabled:o,modelOptions:a,...s}),m=p.filter(e=>l.has(e.name)),h=Object.fromEntries(m.map(e=>[e.name,e]));if(!p?.length||m.length!==l.size){let t=Array.from(l).filter(e=>!h[e]);throw new e(t)}return h};export{r as create,i as findAll,s as findByEntityIds,o as findById,a as findByIds,c as findByWhere,u as getCustomFieldDefinitionsDictionary,l as update};
|
|
2
|
+
//# sourceMappingURL=definition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definition.js","names":["CustomFieldDefinition","where: WhereOptions"],"sources":["../../src/repository/definition.ts"],"sourcesContent":["import {\n Op,\n type Includeable, type Transaction, type FindOptions, type WhereOptions, type Transactionable,\n} from 'sequelize';\nimport { CustomFieldDefinition, type CustomFieldEntries } from '../models';\nimport type { CreateCustomFieldDefinition, UpdateCustomFieldDefinition } from '../types/definition';\nimport type { ModelOptions } from '../types';\nimport { MissingDefinitionError } from '../errors';\n\nexport const create = (data: CreateCustomFieldDefinition): Promise<CustomFieldDefinition> =>\n CustomFieldDefinition.create(data);\n\ninterface SadotFindOptions {\n withDisabled?: boolean;\n transaction?: Transaction;\n include?: Includeable | Includeable[];\n}\n\ntype SadotGetDefinitionsByEntityIdsOptions = FindOptions & { modelOptions?: ModelOptions; findAll?: typeof findAll; } & Pick<SadotFindOptions, 'withDisabled'>;\n\nexport const findAll = (\n where: WhereOptions,\n options: SadotFindOptions = { withDisabled: false },\n): Promise<CustomFieldDefinition[]> => {\n const queryModel = options.withDisabled\n ? CustomFieldDefinition.unscoped()\n : CustomFieldDefinition;\n\n return queryModel.scope('userScope').findAll({\n where,\n transaction: options.transaction,\n raw: true,\n include: options.include,\n });\n};\n\nexport const findByIds = (\n ids: string[],\n options: SadotFindOptions = { withDisabled: false },\n): Promise<CustomFieldDefinition[]> => findAll({ id: { [Op.in]: ids } }, options);\n\nexport const findById = (\n id: string,\n options: Pick<SadotFindOptions, 'withDisabled'> = { withDisabled: false },\n): Promise<CustomFieldDefinition | null> => {\n const { withDisabled } = options;\n if (withDisabled) {\n return CustomFieldDefinition.unscoped().scope('userScope').findByPk(id);\n }\n return CustomFieldDefinition.scope('userScope').findByPk(id);\n};\n\nexport const findByEntityIds = async (\n modelType: string,\n entityIds: string[],\n options: FindOptions & { modelOptions?: ModelOptions } = {},\n): Promise<CustomFieldDefinition[]> => {\n const { include, useEntityIdFromInclude } = options.modelOptions;\n const where: WhereOptions = {\n modelType,\n ...(!useEntityIdFromInclude && { entityId: { [Op.in]: entityIds } }),\n };\n\n return CustomFieldDefinition.findAll({\n where,\n transaction: options.transaction,\n include: include?.(entityIds),\n raw: true,\n });\n};\n\nexport const findByWhere = (where: WhereOptions<CustomFieldDefinition>): Promise<CustomFieldDefinition | null> =>\n CustomFieldDefinition.scope('userScope').findOne({\n where,\n });\n\nexport const findDefinitionsByModels = async (\n modelTypes: string[],\n options?: Transactionable,\n): Promise<CustomFieldDefinition[]> => {\n const query: WhereOptions<CreateCustomFieldDefinition> = { modelType: { [Op.in]: modelTypes } };\n return CustomFieldDefinition.findAll({\n where: query,\n transaction: options?.transaction,\n });\n};\n\nexport const update = async (\n id: string,\n data: UpdateCustomFieldDefinition,\n): Promise<CustomFieldDefinition> => {\n const updatedDefinition = (await CustomFieldDefinition.scope('userScope').update(data, {\n where: { id },\n returning: true,\n individualHooks: true,\n }))[1][0];\n return updatedDefinition;\n};\n\nexport const disable = (id: string): Promise<[affectedCount: number]> =>\n CustomFieldDefinition.update(\n { disabled: true },\n { where: { id } },\n );\n\nexport const destroy = (id: string): Promise<number> =>\n CustomFieldDefinition.destroy({ where: { id } });\n\n/**\n * Return the names of the required fields for a given model\n */\nexport const getRequiredFields = async (\n modelType: string,\n modelId: string | string[],\n entityId: string | string[],\n modelOptions: ModelOptions = {},\n): Promise<string[]> => {\n const entityIds = Array.isArray(entityId) ? entityId : [entityId];\n const { include, useEntityIdFromInclude } = modelOptions;\n\n const where: WhereOptions = {\n modelType,\n required: true,\n ...(!useEntityIdFromInclude && { entityId: { [Op.in]: entityIds } }),\n };\n\n const requiredFields = await CustomFieldDefinition.findAll({\n where,\n include: include?.(entityIds),\n logging: true,\n });\n const requiredFieldsNames = requiredFields.map((definition) => definition.name);\n return [...new Set(requiredFieldsNames)];\n};\n\n/**\n * @returns A promise resolving with a dictionary of custom field definitions by name.\n * @throws A {@link MissingDefinitionError} if any of the custom fields doesn't have a definition.\n */\nexport const getCustomFieldDefinitionsDictionary = async (\n instances: CustomFieldEntries[],\n {\n findAll: _findAll,\n modelOptions = {},\n withDisabled = false,\n ...options\n }: SadotGetDefinitionsByEntityIdsOptions = { withDisabled: false, modelOptions: {} },\n): Promise<{ [definitionName: string]: CustomFieldDefinition }> => {\n const { modelType } = instances[0]?.dataValues ?? {};\n const customFields = new Set<string>();\n const modelIds = [];\n const entityIds = new Set<string>();\n instances.forEach((instance) => {\n const { dataValues: { modelId, entityId, customFields: instanceCustomFields } } = instance;\n modelIds.push(modelId);\n entityIds.add(entityId);\n\n Object.keys(instanceCustomFields ?? {}).forEach((fieldName) => {\n customFields.add(fieldName);\n });\n });\n\n const where: WhereOptions = {\n modelType,\n entityId: { [Op.in]: Array.from(entityIds) },\n name: { [Op.in]: Array.from(customFields) },\n };\n\n const findAllToUse = _findAll ?? findAll;\n\n // @ts-expect-error findAll doesn't expect modelOptions at all.\n const definitions = await findAllToUse(where, { withDisabled, modelOptions, ...options });\n\n const matchedDefinitions = definitions.filter((def) => customFields.has(def.name));\n const matchedDefinitionsByName = Object.fromEntries(matchedDefinitions.map((definition) => [definition.name, definition]));\n\n if (!definitions?.length || matchedDefinitions.length !== customFields.size) {\n const unmatchedCustomFields = Array.from(customFields).filter((customField) => !matchedDefinitionsByName[customField]);\n throw new MissingDefinitionError(unmatchedCustomFields);\n }\n\n return matchedDefinitionsByName;\n};\n"],"mappings":"wKASA,MAAa,EAAU,GACrBA,EAAsB,OAAO,EAAK,CAUvB,GACX,EACA,EAA4B,CAAE,aAAc,GAAO,IAEhC,EAAQ,aACvBA,EAAsB,UAAU,CAChCA,GAEc,MAAM,YAAY,CAAC,QAAQ,CAC3C,Q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K,GAAwB,EAAE,CAAC,CAAC,QAAS,GAAc,CAC7D,EAAa,IAAI,EAAU,EAC3B,EACF,CAEF,IAAMC,EAAsB,CAC1B,YACA,SAAU,EAAG,EAAG,IAAK,MAAM,KAAK,EAAU,CAAE,CAC5C,KAAM,EAAG,EAAG,IAAK,MAAM,KAAK,EAAa,CAAE,CAC5C,CAKK,EAAc,MAHC,GAAY,GAGM,EAAO,CAAE,eAAc,eAAc,GAAG,EAAS,CAAC,CAEnF,EAAqB,EAAY,OAAQ,GAAQ,EAAa,IAAI,EAAI,KAAK,CAAC,CAC5E,EAA2B,OAAO,YAAY,EAAmB,IAAK,GAAe,CAAC,EAAW,KAAM,EAAW,CAAC,CAAC,CAE1H,GAAI,CAAC,GAAa,QAAU,EAAmB,SAAW,EAAa,KAAM,CAC3E,IAAM,EAAwB,MAAM,KAAK,EAAa,CAAC,OAAQ,GAAgB,CAAC,EAAyB,GAAa,CACtH,MAAM,IAAI,EAAuB,EAAsB,CAGzD,OAAO"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`../utils/logger/index.cjs`),t=require(`../errors/index.cjs`),n=require(`./definition.cjs`),r=require(`../models/CustomFieldEntries.cjs`);require(`../models/index.cjs`);const i=require(`./utils/formatValues.cjs`),a=async(e,t={})=>{let{transaction:n}=t;return r.default.findOne({where:{modelId:e},transaction:n})},o=async(e,t={})=>{let{transaction:n}=t;return r.default.findAll({where:{modelId:e},transaction:n})},s=async(a,o,s,c,l={})=>{let u=Object.keys(s);e.default.debug(`custom-fields: updating entries for ${o} ${a}`,{customFieldsNames:u,optionsKeys:l?Object.keys(l):null,customFields:s,identifiers:c});let{modelOptions:d,transaction:f}=l,p={modelType:o,name:u,...!l.modelOptions?.useEntityIdFromInclude&&{entityId:c}},m=await n.findAll(p,{withDisabled:!0,transaction:f,include:d.include?.(c)})??[],h=m.filter(e=>e.disabled);if(m.length!==u.length){e.default.warn(`custom-fields: missing definitions for ${o} ${a}`,{names:u,fieldDefinitions:m});let n=u.filter(e=>!m.some(t=>t.name===e));throw new t.MissingDefinitionError(n)}let g=h?.map(e=>e.name)||[],_=u.filter(e=>g.includes(e));_?.length>0&&e.default.warn(`custom-fields: trying to update disabled values: ${_.join(`, `)}`);let v=Object.fromEntries(m.map(e=>[e.name,e]));return Object.entries(s).filter(([e])=>i.formatFunctions[v[e].fieldType]).forEach(([e,t])=>{let{fieldType:n}=v[e];s[e]=i.formatFunctions[n](t)}),r.default.upsert({modelId:a,entityId:m[0].entityId,modelType:o,customFields:s},l)};exports.findEntriesByModelId=a,exports.findEntriesByModelIds=o,exports.updateEntries=s;
|
|
2
|
+
//# sourceMappingURL=entries.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entries.cjs","names":["CustomFieldEntries","where: WhereOptions","MissingDefinitionError","formatFunctions"],"sources":["../../src/repository/entries.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type {\n FindOptions,\n Includeable,\n Transaction,\n WhereOptions,\n} from 'sequelize';\nimport { CustomFieldEntries } from '../models';\nimport type { ModelOptions } from '../types';\nimport logger from '../utils/logger';\nimport { MissingDefinitionError } from '../errors';\nimport * as DefinitionRepo from './definition';\nimport { formatFunctions } from './utils/formatValues';\n\ntype CustomFieldEntriesModelOptions = ModelOptions & { include?: Includeable, transaction?: Transaction };\n\nexport const findEntriesByModelId = async (modelId: string, options: CustomFieldEntriesModelOptions = {}): Promise<CustomFieldEntries | null> => {\n const { transaction } = options;\n return CustomFieldEntries.findOne({\n where: { modelId },\n transaction,\n });\n};\n\nexport const findEntriesByModelIds = async (modelIds: string[], options: CustomFieldEntriesModelOptions = {}): Promise<CustomFieldEntries[]> => {\n const { transaction } = options;\n return CustomFieldEntries.findAll({\n where: { modelId: modelIds },\n transaction,\n });\n};\n\nexport const updateEntries = async (\n modelId: string,\n modelType: string,\n customFields: Record<string, any>,\n identifiers: string[],\n options: FindOptions & { modelOptions?: ModelOptions } = {},\n): Promise<[CustomFieldEntries, boolean | null]> => {\n const customFieldsNames = Object.keys(customFields);\n logger.debug(`custom-fields: updating entries for ${modelType} ${modelId}`, {\n customFieldsNames,\n optionsKeys: options ? Object.keys(options) : null,\n customFields,\n identifiers,\n });\n const { modelOptions, transaction } = options;\n\n const where: WhereOptions = {\n modelType,\n name: customFieldsNames,\n ...(!options.modelOptions?.useEntityIdFromInclude && { entityId: identifiers }),\n };\n\n const fieldDefinitions = await DefinitionRepo.findAll(where, { withDisabled: true, transaction, include: modelOptions.include?.(identifiers) }) ?? [];\n\n const disabledDefinitions = fieldDefinitions.filter((def) => def.disabled);\n if (fieldDefinitions.length !== customFieldsNames.length) {\n logger.warn(`custom-fields: missing definitions for ${modelType} ${modelId}`, { names: customFieldsNames, fieldDefinitions });\n const missingDefinitions = customFieldsNames.filter((name) => !fieldDefinitions.some((def) => def.name === name));\n throw new MissingDefinitionError(missingDefinitions);\n }\n\n const disabledNames = disabledDefinitions?.map((def) => def.name) || [];\n const valuesWithDisabledDefinitions = customFieldsNames.filter((name) => disabledNames.includes(name));\n if (valuesWithDisabledDefinitions?.length > 0) {\n logger.warn(`custom-fields: trying to update disabled values: ${valuesWithDisabledDefinitions.join(', ')}`);\n }\n\n const definitionsByName = Object.fromEntries(fieldDefinitions.map((definition) => [definition.name, definition]));\n // If we need to format the value before we save it\n Object.entries(customFields)\n .filter(([definitionName]) => formatFunctions[definitionsByName[definitionName].fieldType])\n .forEach(([definitionName, value]) => {\n const { fieldType } = definitionsByName[definitionName];\n customFields[definitionName] = formatFunctions[fieldType](value);\n });\n\n return CustomFieldEntries.upsert(\n {\n modelId,\n entityId: fieldDefinitions[0].entityId,\n modelType,\n customFields,\n },\n options,\n );\n};\n"],"mappings":"qOAgBa,EAAuB,MAAO,EAAiB,EAA0C,EAAE,GAAyC,CAC/I,GAAM,CAAE,eAAgB,EACxB,OAAOA,EAAAA,QAAmB,QAAQ,CAChC,MAAO,CAAE,UAAS,CAClB,cACD,CAAC,EAGS,EAAwB,MAAO,E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,CAAC,KAAoBC,EAAAA,gBAAgB,EAAkB,GAAgB,WAAW,CAC1F,SAAS,CAAC,EAAgB,KAAW,CACpC,GAAM,CAAE,aAAc,EAAkB,GACxC,EAAa,GAAkBA,EAAAA,gBAAgB,GAAW,EAAM,EAChE,CAEGH,EAAAA,QAAmB,OACxB,CACE,UACA,SAAU,EAAiB,GAAG,SAC9B,YACA,eACD,CACD,EACD"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e from"../utils/logger/index.js";import{MissingDefinitionError as t}from"../errors/index.js";import{findAll as n}from"./definition.js";import r from"../models/CustomFieldEntries.js";import"../models/index.js";import{formatFunctions as i}from"./utils/formatValues.js";const a=async(e,t={})=>{let{transaction:n}=t;return r.findOne({where:{modelId:e},transaction:n})},o=async(e,t={})=>{let{transaction:n}=t;return r.findAll({where:{modelId:e},transaction:n})},s=async(a,o,s,c,l={})=>{let u=Object.keys(s);e.debug(`custom-fields: updating entries for ${o} ${a}`,{customFieldsNames:u,optionsKeys:l?Object.keys(l):null,customFields:s,identifiers:c});let{modelOptions:d,transaction:f}=l,p={modelType:o,name:u,...!l.modelOptions?.useEntityIdFromInclude&&{entityId:c}},m=await n(p,{withDisabled:!0,transaction:f,include:d.include?.(c)})??[],h=m.filter(e=>e.disabled);if(m.length!==u.length){e.warn(`custom-fields: missing definitions for ${o} ${a}`,{names:u,fieldDefinitions:m});let n=u.filter(e=>!m.some(t=>t.name===e));throw new t(n)}let g=h?.map(e=>e.name)||[],_=u.filter(e=>g.includes(e));_?.length>0&&e.warn(`custom-fields: trying to update disabled values: ${_.join(`, `)}`);let v=Object.fromEntries(m.map(e=>[e.name,e]));return Object.entries(s).filter(([e])=>i[v[e].fieldType]).forEach(([e,t])=>{let{fieldType:n}=v[e];s[e]=i[n](t)}),r.upsert({modelId:a,entityId:m[0].entityId,modelType:o,customFields:s},l)};export{a as findEntriesByModelId,o as findEntriesByModelIds,s as updateEntries};
|
|
2
|
+
//# sourceMappingURL=entries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entries.js","names":["CustomFieldEntries","where: WhereOptions","DefinitionRepo.findAll"],"sources":["../../src/repository/entries.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type {\n FindOptions,\n Includeable,\n Transaction,\n WhereOptions,\n} from 'sequelize';\nimport { CustomFieldEntries } from '../models';\nimport type { ModelOptions } from '../types';\nimport logger from '../utils/logger';\nimport { MissingDefinitionError } from '../errors';\nimport * as DefinitionRepo from './definition';\nimport { formatFunctions } from './utils/formatValues';\n\ntype CustomFieldEntriesModelOptions = ModelOptions & { include?: Includeable, transaction?: Transaction };\n\nexport const findEntriesByModelId = async (modelId: string, options: CustomFieldEntriesModelOptions = {}): Promise<CustomFieldEntries | null> => {\n const { transaction } = options;\n return CustomFieldEntries.findOne({\n where: { modelId },\n transaction,\n });\n};\n\nexport const findEntriesByModelIds = async (modelIds: string[], options: CustomFieldEntriesModelOptions = {}): Promise<CustomFieldEntries[]> => {\n const { transaction } = options;\n return CustomFieldEntries.findAll({\n where: { modelId: modelIds },\n transaction,\n });\n};\n\nexport const updateEntries = async (\n modelId: string,\n modelType: string,\n customFields: Record<string, any>,\n identifiers: string[],\n options: FindOptions & { modelOptions?: ModelOptions } = {},\n): Promise<[CustomFieldEntries, boolean | null]> => {\n const customFieldsNames = Object.keys(customFields);\n logger.debug(`custom-fields: updating entries for ${modelType} ${modelId}`, {\n customFieldsNames,\n optionsKeys: options ? Object.keys(options) : null,\n customFields,\n identifiers,\n });\n const { modelOptions, transaction } = options;\n\n const where: WhereOptions = {\n modelType,\n name: customFieldsNames,\n ...(!options.modelOptions?.useEntityIdFromInclude && { entityId: identifiers }),\n };\n\n const fieldDefinitions = await DefinitionRepo.findAll(where, { withDisabled: true, transaction, include: modelOptions.include?.(identifiers) }) ?? [];\n\n const disabledDefinitions = fieldDefinitions.filter((def) => def.disabled);\n if (fieldDefinitions.length !== customFieldsNames.length) {\n logger.warn(`custom-fields: missing definitions for ${modelType} ${modelId}`, { names: customFieldsNames, fieldDefinitions });\n const missingDefinitions = customFieldsNames.filter((name) => !fieldDefinitions.some((def) => def.name === name));\n throw new MissingDefinitionError(missingDefinitions);\n }\n\n const disabledNames = disabledDefinitions?.map((def) => def.name) || [];\n const valuesWithDisabledDefinitions = customFieldsNames.filter((name) => disabledNames.includes(name));\n if (valuesWithDisabledDefinitions?.length > 0) {\n logger.warn(`custom-fields: trying to update disabled values: ${valuesWithDisabledDefinitions.join(', ')}`);\n }\n\n const definitionsByName = Object.fromEntries(fieldDefinitions.map((definition) => [definition.name, definition]));\n // If we need to format the value before we save it\n Object.entries(customFields)\n .filter(([definitionName]) => formatFunctions[definitionsByName[definitionName].fieldType])\n .forEach(([definitionName, value]) => {\n const { fieldType } = definitionsByName[definitionName];\n customFields[definitionName] = formatFunctions[fieldType](value);\n });\n\n return CustomFieldEntries.upsert(\n {\n modelId,\n entityId: fieldDefinitions[0].entityId,\n modelType,\n customFields,\n },\n options,\n );\n};\n"],"mappings":"kRAgBA,MAAa,EAAuB,MAAO,EAAiB,EAA0C,EAAE,GAAyC,CAC/I,GAAM,CAAE,eAAgB,EACxB,OAAOA,EAAmB,QAAQ,CAChC,MAAO,CAAE,UAAS,CAClB,cACD,CAAC,EAGS,EAAwB,MAAO,EAAoB,EAA0C,EAAE,GAAoC,CAC9I,GAAM,CAAE,eAAgB,EACxB,OAAOA,EAAmB,QAAQ,CAChC,MAAO,CAAE,QAAS,EAAU,CAC5B,cACD,CAAC,EAGS,EAAgB,MAC3B,EACA,EACA,EACA,EACA,EAAyD,EAAE,GACT,CAClD,IAAM,EAAoB,OAAO,KAAK,EAAa,CACnD,EAAO,MAAM,uCAAuC,EAAU,GAAG,IAAW,CAC1E,oBACA,YAAa,EAAU,OAAO,KAAK,EAAQ,CAAG,KAC9C,eACA,cACD,CAAC,CACF,GAAM,CAAE,eAAc,eAAgB,EAEhCC,EAAsB,CAC1B,YACA,KAAM,EACN,GAAI,CAAC,EAAQ,cAAc,wBAA0B,CAAE,SAAU,EAAa,CAC/E,CAEK,EAAmB,MAAMC,EAAuB,EAAO,CAAE,aAAc,GAAM,cAAa,QAAS,EAAa,UAAU,EAAY,CAAE,CAAC,EAAI,EAAE,CAE/I,EAAsB,EAAiB,OAAQ,GAAQ,EAAI,SAAS,CAC1E,GAAI,EAAiB,SAAW,EAAkB,OAAQ,CACxD,EAAO,KAAK,0CAA0C,EAAU,GAAG,IAAW,CAAE,MAAO,EAAmB,mBAAkB,CAAC,CAC7H,IAAM,EAAqB,EAAkB,OAAQ,GAAS,CAAC,EAAiB,KAAM,GAAQ,EAAI,OAAS,EAAK,CAAC,CACjH,MAAM,IAAI,EAAuB,EAAmB,CAGtD,IAAM,EAAgB,GAAqB,IAAK,GAAQ,EAAI,KAAK,EAAI,EAAE,CACjE,EAAgC,EAAkB,OAAQ,GAAS,EAAc,SAAS,EAAK,CAAC,CAClG,GAA+B,OAAS,GAC1C,EAAO,KAAK,oDAAoD,EAA8B,KAAK,KAAK,GAAG,CAG7G,IAAM,EAAoB,OAAO,YAAY,EAAiB,IAAK,GAAe,CAAC,EAAW,KAAM,EAAW,CAAC,CAAC,CASjH,OAPA,OAAO,QAAQ,EAAa,CACzB,QAAQ,CAAC,KAAoB,EAAgB,EAAkB,GAAgB,WAAW,CAC1F,SAAS,CAAC,EAAgB,KAAW,CACpC,GAAM,CAAE,aAAc,EAAkB,GACxC,EAAa,GAAkB,EAAgB,GAAW,EAAM,EAChE,CAEGF,EAAmB,OACxB,CACE,UACA,SAAU,EAAiB,GAAG,SAC9B,YACA,eACD,CACD,EACD"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`../../utils/constants/index.cjs`),t={[e.CustomFieldDefinitionType.DATE]:e=>{if(e){let t=new Date(e);if(t.toString()===`Invalid Date`)throw Error(`Invalid date value: ${e}`);return t.toISOString()}return null}};exports.formatFunctions=t;
|
|
2
|
+
//# sourceMappingURL=formatValues.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatValues.cjs","names":["formatFunctions: Partial<Record<CustomFieldDefinitionType, (value: any) => string | null>>","CustomFieldDefinitionType"],"sources":["../../../src/repository/utils/formatValues.ts"],"sourcesContent":["import { CustomFieldDefinitionType } from '../../utils/constants';\n\nexport const formatFunctions: Partial<Record<CustomFieldDefinitionType, (value: any) => string | null>> = {\n [CustomFieldDefinitionType.DATE]: (value) => {\n if (value) {\n const date = new Date(value);\n if (date.toString() === 'Invalid Date') {\n throw new Error(`Invalid date value: ${value}`);\n }\n return date.toISOString();\n }\n return null;\n },\n};\n"],"mappings":"mDAEaA,EAA6F,EACvGC,EAAAA,0BAA0B,MAAQ,GAAU,CAC3C,GAAI,EAAO,CACT,IAAM,EAAO,IAAI,KAAK,EAAM,CAC5B,GAAI,EAAK,UAAU,GAAK,eACtB,MAAU,MAAM,uBAAuB,IAAQ,CAEjD,OAAO,EAAK,aAAa,CAE3B,OAAO,MAEV"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{CustomFieldDefinitionType as e}from"../../utils/constants/index.js";const t={[e.DATE]:e=>{if(e){let t=new Date(e);if(t.toString()===`Invalid Date`)throw Error(`Invalid date value: ${e}`);return t.toISOString()}return null}};export{t as formatFunctions};
|
|
2
|
+
//# sourceMappingURL=formatValues.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatValues.js","names":["formatFunctions: Partial<Record<CustomFieldDefinitionType, (value: any) => string | null>>"],"sources":["../../../src/repository/utils/formatValues.ts"],"sourcesContent":["import { CustomFieldDefinitionType } from '../../utils/constants';\n\nexport const formatFunctions: Partial<Record<CustomFieldDefinitionType, (value: any) => string | null>> = {\n [CustomFieldDefinitionType.DATE]: (value) => {\n if (value) {\n const date = new Date(value);\n if (date.toString() === 'Invalid Date') {\n throw new Error(`Invalid date value: ${value}`);\n }\n return date.toISOString();\n }\n return null;\n },\n};\n"],"mappings":"2EAEA,MAAaA,EAA6F,EACvG,EAA0B,MAAQ,GAAU,CAC3C,GAAI,EAAO,CACT,IAAM,EAAO,IAAI,KAAK,EAAM,CAC5B,GAAI,EAAK,UAAU,GAAK,eACtB,MAAU,MAAM,uBAAuB,IAAQ,CAEjD,OAAO,EAAK,aAAa,CAE3B,OAAO,MAEV"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`../utils/logger/index.cjs`),t=require(`../models/CustomValidator.cjs`);require(`../models/index.cjs`);const n=async(n,r={})=>(e.default.debug(`custom-validator - create validator`),await t.default.create(n,r)),r=async(n={},r={})=>{e.default.debug(`custom-validator - find all validators`);let{transaction:i,withDisabled:a,include:o,attributes:s,raw:c}=r,l;return l=a?await t.default.unscoped().scope(`userScope`).findAll({where:n,transaction:i,include:o,attributes:s,raw:c}):await t.default.scope([`defaultScope`,`userScope`]).findAll({where:n,transaction:i,include:o,attributes:s,raw:c}),l},i=async(t,n,i={})=>(e.default.debug(`custom-validator - find all validators by model type`),r({modelType:t,...!i?.modelOptions?.useEntityIdFromInclude&&{entityId:n}},{...i,include:i?.modelOptions?.include?.(n)})),a=async(n,r,i)=>(e.default.debug(`custom-validator - update validator`),t.default.update(r,{where:{id:n},returning:!0,...i})),o=async(t,n)=>(e.default.debug(`custom-validator - disable validator`),a(t,{disabled:!0},n));exports.create=n,exports.disable=o,exports.findAll=r,exports.findAllByModelType=i,exports.update=a;
|
|
2
|
+
//# sourceMappingURL=validator.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.cjs","names":["CustomValidator"],"sources":["../../src/repository/validator.ts"],"sourcesContent":["import type { FindOptions, IncludeOptions, Transactionable } from 'sequelize';\nimport logger from '../utils/logger';\nimport { CustomValidator } from '../models';\nimport type { ModelOptions } from '../types';\n\nexport interface FindValidatorOptions extends Transactionable {\n withDisabled?: boolean;\n attributes?: string[];\n raw?: boolean;\n include?: IncludeOptions[];\n}\n\n// Make sure this interface is compatible with the Sequelize model\nexport interface ValidatorAttributes {\n entityId: string;\n entityType: string;\n modelType: string;\n schema: CustomValidator['schema'];\n disabled?: boolean;\n [key: string]: unknown; // Add index signature for Sequelize compatibility\n}\n\nexport const create = async (\n validatorAttributes: ValidatorAttributes,\n options: Transactionable = {},\n): Promise<CustomValidator> => {\n logger.debug('custom-validator - create validator');\n\n // Use unknown type to bypass TypeScript errors while maintaining compatibility\n const validator = await CustomValidator.create(validatorAttributes as Record<string, unknown>, options);\n\n return validator;\n};\n\nexport const findAll = async (\n where = {},\n options: FindOptions & {\n modelOptions?: ModelOptions,\n withDisabled?: boolean\n } = {},\n): Promise<CustomValidator[]> => {\n logger.debug('custom-validator - find all validators');\n\n const {\n transaction, withDisabled, include, attributes, raw,\n } = options;\n\n let validators;\n if (withDisabled) {\n // If withDisabled is true, use unscoped to ignore the default scope that filters disabled items\n // Apply the userScope separately to maintain permission filtering\n validators = await CustomValidator.unscoped().scope('userScope').findAll({\n where,\n transaction,\n include,\n attributes,\n raw,\n });\n } else {\n // Use defaultScope and userScope to filter both disabled and by permissions\n // The defaultScope keeps only non-disabled validators\n validators = await CustomValidator.scope(['defaultScope', 'userScope']).findAll({\n where,\n transaction,\n include,\n attributes,\n raw,\n });\n }\n\n return validators;\n};\n\nexport const findAllByModelType = async (\n modelType: string,\n entityId: string,\n options: FindOptions & {\n modelOptions?: ModelOptions,\n withDisabled?: boolean\n } = {},\n): Promise<CustomValidator[]> => {\n logger.debug('custom-validator - find all validators by model type');\n return findAll(\n {\n modelType,\n ...(!options?.modelOptions?.useEntityIdFromInclude && { entityId }),\n },\n {\n ...options,\n include: options?.modelOptions?.include?.(entityId),\n },\n );\n};\n\nexport const update = async (\n id: string,\n updates: Partial<ValidatorAttributes>,\n options?: Transactionable,\n): Promise<[number, CustomValidator[]]> => {\n logger.debug('custom-validator - update validator');\n\n return CustomValidator.update(\n updates,\n {\n where: { id },\n returning: true,\n ...options,\n },\n );\n};\n\nexport const disable = async (\n id: string,\n options?: Transactionable,\n): Promise<[number, CustomValidator[]]> => {\n logger.debug('custom-validator - disable validator');\n\n return update(id, { disabled: true }, options);\n};\n"],"mappings":"uHAsBA,MAAa,EAAS,MACpB,EACA,EAA2B,EAAE,IAE7B,EAAA,QAAO,MAAM,sCAAsC,CAGjC,MAAMA,EAAAA,QAAgB,OAAO,EAAgD,EAAQ,EAK5F,EAAU,MACrB,EAAQ,EAAE,CACV,EAGM,EAAE,GACuB,CAC/B,EAAA,QAAO,MAAM,yCAAyC,CAEtD,GAAM,CACJ,cAAa,eAAc,UAAS,aAAY,OAC9C,EAEA,EAuBJ,MAtBA,CAaE,EAbE,EAGW,MAAMA,EAAAA,QAAgB,UAAU,CAAC,MAAM,YAAY,CAAC,QAAQ,CACvE,QACA,cACA,UACA,aACA,MACD,CAAC,CAIW,MAAMA,EAAAA,QAAgB,MAAM,CAAC,eAAgB,YAAY,CAAC,CAAC,QAAQ,CAC9E,QACA,cACA,UACA,aACA,MACD,CAAC,CAGG,GAGI,EAAqB,MAChC,EACA,EACA,EAGI,EAAE,IAEN,EAAA,QAAO,MAAM,uDAAuD,CAC7D,EACL,CACE,YACA,GAAI,CAAC,GAAS,cAAc,wBAA0B,CAAE,WAAU,CACnE,CACD,CACE,GAAG,EACH,QAAS,GAAS,cAAc,UAAU,EAAS,CACpD,CACF,EAGU,EAAS,MACpB,EACA,EACA,KAEA,EAAA,QAAO,MAAM,sCAAsC,CAE5CA,EAAAA,QAAgB,OACrB,EACA,CACE,MAAO,CAAE,KAAI,CACb,UAAW,GACX,GAAG,EACJ,CACF,EAGU,EAAU,MACrB,EACA,KAEA,EAAA,QAAO,MAAM,uCAAuC,CAE7C,EAAO,EAAI,CAAE,SAAU,GAAM,CAAE,EAAQ"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e from"../utils/logger/index.js";import t from"../models/CustomValidator.js";import"../models/index.js";const n=async(n,r={})=>(e.debug(`custom-validator - create validator`),await t.create(n,r)),r=async(n={},r={})=>{e.debug(`custom-validator - find all validators`);let{transaction:i,withDisabled:a,include:o,attributes:s,raw:c}=r,l;return l=a?await t.unscoped().scope(`userScope`).findAll({where:n,transaction:i,include:o,attributes:s,raw:c}):await t.scope([`defaultScope`,`userScope`]).findAll({where:n,transaction:i,include:o,attributes:s,raw:c}),l},i=async(t,n,i={})=>(e.debug(`custom-validator - find all validators by model type`),r({modelType:t,...!i?.modelOptions?.useEntityIdFromInclude&&{entityId:n}},{...i,include:i?.modelOptions?.include?.(n)})),a=async(n,r,i)=>(e.debug(`custom-validator - update validator`),t.update(r,{where:{id:n},returning:!0,...i})),o=async(t,n)=>(e.debug(`custom-validator - disable validator`),a(t,{disabled:!0},n));export{n as create,o as disable,r as findAll,i as findAllByModelType,a as update};
|
|
2
|
+
//# sourceMappingURL=validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.js","names":["CustomValidator"],"sources":["../../src/repository/validator.ts"],"sourcesContent":["import type { FindOptions, IncludeOptions, Transactionable } from 'sequelize';\nimport logger from '../utils/logger';\nimport { CustomValidator } from '../models';\nimport type { ModelOptions } from '../types';\n\nexport interface FindValidatorOptions extends Transactionable {\n withDisabled?: boolean;\n attributes?: string[];\n raw?: boolean;\n include?: IncludeOptions[];\n}\n\n// Make sure this interface is compatible with the Sequelize model\nexport interface ValidatorAttributes {\n entityId: string;\n entityType: string;\n modelType: string;\n schema: CustomValidator['schema'];\n disabled?: boolean;\n [key: string]: unknown; // Add index signature for Sequelize compatibility\n}\n\nexport const create = async (\n validatorAttributes: ValidatorAttributes,\n options: Transactionable = {},\n): Promise<CustomValidator> => {\n logger.debug('custom-validator - create validator');\n\n // Use unknown type to bypass TypeScript errors while maintaining compatibility\n const validator = await CustomValidator.create(validatorAttributes as Record<string, unknown>, options);\n\n return validator;\n};\n\nexport const findAll = async (\n where = {},\n options: FindOptions & {\n modelOptions?: ModelOptions,\n withDisabled?: boolean\n } = {},\n): Promise<CustomValidator[]> => {\n logger.debug('custom-validator - find all validators');\n\n const {\n transaction, withDisabled, include, attributes, raw,\n } = options;\n\n let validators;\n if (withDisabled) {\n // If withDisabled is true, use unscoped to ignore the default scope that filters disabled items\n // Apply the userScope separately to maintain permission filtering\n validators = await CustomValidator.unscoped().scope('userScope').findAll({\n where,\n transaction,\n include,\n attributes,\n raw,\n });\n } else {\n // Use defaultScope and userScope to filter both disabled and by permissions\n // The defaultScope keeps only non-disabled validators\n validators = await CustomValidator.scope(['defaultScope', 'userScope']).findAll({\n where,\n transaction,\n include,\n attributes,\n raw,\n });\n }\n\n return validators;\n};\n\nexport const findAllByModelType = async (\n modelType: string,\n entityId: string,\n options: FindOptions & {\n modelOptions?: ModelOptions,\n withDisabled?: boolean\n } = {},\n): Promise<CustomValidator[]> => {\n logger.debug('custom-validator - find all validators by model type');\n return findAll(\n {\n modelType,\n ...(!options?.modelOptions?.useEntityIdFromInclude && { entityId }),\n },\n {\n ...options,\n include: options?.modelOptions?.include?.(entityId),\n },\n );\n};\n\nexport const update = async (\n id: string,\n updates: Partial<ValidatorAttributes>,\n options?: Transactionable,\n): Promise<[number, CustomValidator[]]> => {\n logger.debug('custom-validator - update validator');\n\n return CustomValidator.update(\n updates,\n {\n where: { id },\n returning: true,\n ...options,\n },\n );\n};\n\nexport const disable = async (\n id: string,\n options?: Transactionable,\n): Promise<[number, CustomValidator[]]> => {\n logger.debug('custom-validator - disable validator');\n\n return update(id, { disabled: true }, options);\n};\n"],"mappings":"+GAsBA,MAAa,EAAS,MACpB,EACA,EAA2B,EAAE,IAE7B,EAAO,MAAM,sCAAsC,CAGjC,MAAMA,EAAgB,OAAO,EAAgD,EAAQ,EAK5F,EAAU,MACrB,EAAQ,EAAE,CACV,EAGM,EAAE,GACuB,CAC/B,EAAO,MAAM,yCAAyC,CAEtD,GAAM,CACJ,cAAa,eAAc,UAAS,aAAY,OAC9C,EAEA,EAuBJ,MAtBA,CAaE,EAbE,EAGW,MAAMA,EAAgB,UAAU,CAAC,MAAM,YAAY,CAAC,QAAQ,CACvE,QACA,cACA,UACA,aACA,MACD,CAAC,CAIW,MAAMA,EAAgB,MAAM,CAAC,eAAgB,YAAY,CAAC,CAAC,QAAQ,CAC9E,QACA,cACA,UACA,aACA,MACD,CAAC,CAGG,GAGI,EAAqB,MAChC,EACA,EACA,EAGI,EAAE,IAEN,EAAO,MAAM,uDAAuD,CAC7D,EACL,CACE,YACA,GAAI,CAAC,GAAS,cAAc,wBAA0B,CAAE,WAAU,CACnE,CACD,CACE,GAAG,EACH,QAAS,GAAS,cAAc,UAAU,EAAS,CACpD,CACF,EAGU,EAAS,MACpB,EACA,EACA,KAEA,EAAO,MAAM,sCAAsC,CAE5CA,EAAgB,OACrB,EACA,CACE,MAAO,CAAE,KAAI,CACb,UAAW,GACX,GAAG,EACJ,CACF,EAGU,EAAU,MACrB,EACA,KAEA,EAAO,MAAM,uCAAuC,CAE7C,EAAO,EAAI,CAAE,SAAU,GAAM,CAAE,EAAQ"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`../utils/logger/index.cjs`),t=require(`../errors/index.cjs`),n=require(`./definition.cjs`),r=require(`../models/CustomFieldValue.cjs`);require(`../models/index.cjs`);const i=require(`./utils/formatValues.cjs`),a=async(e,t)=>{let{transaction:n}=t;return r.default.findAll({where:{modelId:e},transaction:n,raw:!0,nest:!0})},o=async(a,o,s,c,l={})=>{let u=Object.keys(c);e.default.debug(`custom-fields: updating values for ${a} ${o}`,{names:u,optionsKeys:l?Object.keys(l):null,valuesToUpdate:c,identifiers:s});let{modelOptions:d,transaction:f}=l,p={modelType:a,name:u,...!l.modelOptions?.useEntityIdFromInclude&&{entityId:s}},m=await n.findAll(p,{withDisabled:!0,transaction:f,include:d.include?.(s)})??[],h=m.filter(e=>e.disabled);if(m.length!==u.length){e.default.warn(`custom-fields: missing definitions for ${a} ${o}`,{names:u,fieldDefinitions:m});let n=u.filter(e=>!m.some(t=>t.name===e));throw new t.MissingDefinitionError(n)}let g=h?.map(e=>e.name)||[],_=u.filter(e=>g.includes(e));_?.length>0&&e.default.warn(`custom-fields: trying to update disabled values: ${_.join(`, `)}`);let v=u.map(e=>{let t=m.find(t=>t.name===e),n=i.formatFunctions[t.fieldType],r=n?n(c[e]):c[e];return{modelId:o,updatedAt:new Date,customFieldDefinitionId:t.id,value:r===void 0?t.defaultValue:r}});return Promise.all(v.map(async e=>{let[t]=await r.default.upsert(e,{transaction:l.transaction});return t}))};exports.findValuesByModelIds=a,exports.updateValues=o;
|
|
2
|
+
//# sourceMappingURL=value.cjs.map
|