Define mutators for fields
import { Model } from 'pinia-orm'class User extends Model { static entity = 'users' static fields () { return { id: this.attr(null), firstName: this.attr(''), lastName: this.attr('') } } static mutators() { return { firstName: { get: (value: any) => value.toLowerCase(), set: (value: any) => value.toUpperCase(), }, lastName(value: any) => value.toLowerCase() } }}
import { Model } from 'pinia-orm'import { Attr, Mutate } from 'pinia-orm/dist/decorators'class User extends Model { static entity = 'users' @Mutate((value: any) => value.toUpperCase()) @Str('') declare name: string}
export type Mutator<T> = (value: T) => Texport interface MutatorFunctions<T> { get?: Mutator<T> set?: Mutator<T>}export interface Mutators { [name: string]: MutatorFunctions<any> | Mutator<any>}function mutators(): Mutators