( prop: string, value: unknown, schema: SchemaEntity )
| 28 | } |
| 29 | |
| 30 | export function validateEntityDataProp( |
| 31 | prop: string, |
| 32 | value: unknown, |
| 33 | schema: SchemaEntity |
| 34 | ) { |
| 35 | const attribute = schema.attributes.find((a) => a.name === prop); |
| 36 | if (!attribute) { |
| 37 | throw new Error(`Attribute ${prop} not found in entity ${schema.name}`); |
| 38 | } |
| 39 | |
| 40 | if (attribute.isNullable && (value === null || value === undefined)) { |
| 41 | return; |
| 42 | } |
| 43 | |
| 44 | if (!getIsDataTypeValid(value, attribute.type)) { |
| 45 | throw new Error(`Attribute ${prop} has invalid type ${attribute.type}`); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | export function validateEntityData( |
| 50 | data: Record<any, any>, |
no test coverage detected