@zzznpm/mens
Version:
All about idea management.
140 lines (109 loc) • 2.11 kB
JavaScript
import { verifyUUID } from './utils.js'
class Entity{
get id(){
return this.
}
set id(value){
if (!verifyUUID(value)){
throw new Error('[Entity] Entity id must be a valid UUID!')
}
this.
}
set content(value){
if (typeof value !== 'string'){
throw new Error('[Entity] Content must have a string!')
}
this.
}
get content(){
return this.
}
get cTime(){
return this.
}
set cTime(value){
this.
}
get mTime(){
return this.
}
set mTime(value){
this.
}
set dropped(value){
if (typeof value !== 'boolean'){
throw new Error('[Entity] dropped must be a boolean value!')
}
this.
}
get dropped(){
return this.
}
get dTime(){
return this.
}
set dTime(value){
this.
}
get version(){
return this.
}
set version(value){
this.
}
get history(){
return this.
}
constructor(id, content){
this.id = id
this.content = content
}
static fromRaw(obj){
const entity = new Entity(obj.id, obj.content)
entity.cTime = obj.cTime
entity.mTime = obj.mTime
if(obj.dropped !== undefined){
entity.dropped = obj.dropped
}
entity.dTime = obj.dTime
entity.version = obj.version
if (obj.history){
entity.history.length = 0
obj.history.forEach(v=> entity.history.push(v))
}
return entity
}
static toRaw(entity){
return {
id: entity.id,
content: entity.content,
cTime: entity.cTime,
mTime: entity.mTime,
dropped: entity.dropped,
dTime: entity.dTime,
version: entity.version,
history: entity.history ? [...entity.history] : [],
}
}
// toString(){
// return `{
// id: ${this.id},
// content: ${this.content},
// cTime: ${this.cTime},
// mTime: ${this.mTime},
// dropped: ${this.dropped},
// dTime: ${this.dTime},
// version: ${this.version},
// history: ${this.history},
// }`
// }
}
export default Entity