import rfdc from 'rfdc' /** @public */ export type ValuesObject = Record /** @public */ export abstract class Data { [key: string]: any static assign(vo: Data, values: ValuesObject): Data { for (const key of Object.getOwnPropertyNames(values)) { vo[key] = values[key] } return vo } set(key: string, value: any) { this[key] = value } fromObject(object: ValuesObject): void { for (const key of Object.getOwnPropertyNames(object)) { if (key === '_id') continue this[key] = object[key] } } toObject(exclude: string[] = []): Record { const object = {} as ValuesObject for (const key of Object.getOwnPropertyNames(this)) { if (key.startsWith('__')) { continue } if (exclude.includes(key)) continue const type = typeof this[key] if (type === 'object') { object[key] = rfdc()(this[key]) } else if (['function', 'undefined'].includes(type)) { // ... } else { object[key] = this[key] } } return object } abstract uniqKey(): string }