Simple serialization entities fixes and tests

This commit is contained in:
barsdeveloper
2024-03-30 20:07:26 +01:00
parent acedafc339
commit 279163cd54
24 changed files with 315 additions and 146 deletions

View File

@@ -10,6 +10,7 @@ import Union from "./Union.js"
/** @abstract */
export default class IEntity extends Serializable {
/** @type {{ [attribute: String]: AttributeInfo }} */
static attributes = {
attributes: new AttributeInfo({
ignored: true,
@@ -147,21 +148,6 @@ export default class IEntity extends Serializable {
return value != null && (value instanceof type || value.constructor === type)
}
static expectsAllKeys() {
return !Object.values(this.attributes)
.filter(/** @param {AttributeInformation} attribute */attribute => !attribute.ignored)
.some(/** @param {AttributeInformation} attribute */attribute => !attribute.expected)
}
static getAttribute(object, attribute) {
return this.getAttributes(object)[attribute]
}
/** @returns {AttributeDeclarations} */
static getAttributes(object) {
return object.attributes ?? object.constructor?.attributes ?? {}
}
static defineAttributes(object, attributes) {
Object.defineProperty(object, "attributes", {
writable: true,