Entities semplification

* Entities semplification WIP

* Bug fixes after entity semplification

* Fix object serialization
This commit is contained in:
barsdeveloper
2023-05-05 18:50:31 +02:00
committed by GitHub
parent 4eb1ff2a7c
commit 90f19e1bca
26 changed files with 181 additions and 391 deletions

View File

@@ -175,6 +175,7 @@ export default class Grammar {
)
} else if (type instanceof MirroredEntity) {
return this.grammarFor(type.type.attributes[type.key])
.map(() => new MirroredEntity(type.type, type.key, type.getter))
} else if (attribute?.constructor === Object) {
result = this.grammarFor(undefined, type)
} else {
@@ -454,9 +455,7 @@ export default class Grammar {
static naturalNumberEntity = P.lazy(() => this.naturalNumber.map(v => new NaturalNumberEntity(v)))
static noneReferenceEntity = P.lazy(() =>
P.string("None").map(() =>
new ObjectReferenceEntity({ type: "None", path: "" })
)
P.string("None").map(() => ObjectReferenceEntity.createNoneInstance())
)
static typeReferenceEntity = P.lazy(() =>

View File

@@ -77,7 +77,7 @@ export default class ObjectSerializer extends Serializer {
)
}
let result = indentation + "Begin Object"
+ (entity.Class.type || entity.Class.path ? ` Class=${this.doWriteValue(entity.Class, insideString)}` : "")
+ (entity.Class?.type || entity.Class?.path ? ` Class=${this.doWriteValue(entity.Class, insideString)}` : "")
+ (entity.Name ? ` Name=${this.doWriteValue(entity.Name, insideString)}` : "")
+ "\n"
+ super.doWrite(

View File

@@ -82,10 +82,7 @@ export default class Serializer {
) {
let result = ""
const attributes = IEntity.getAttributes(entity)
const keys = Utility.mergeArrays(
Object.keys(attributes),
Object.keys(entity)
)
const keys = Object.keys(entity)
let first = true
for (const key of keys) {
const value = entity[key]
@@ -147,14 +144,9 @@ export default class Serializer {
}
showProperty(entity, key) {
const attributes = /** @type {EntityConstructor} */(this.entityType).attributes
const attribute = attributes[key]
const value = entity[key]
if (attribute?.constructor === Object) {
if (attribute.ignored) {
return false
}
return !Utility.equals(attribute.default, value) || attribute.showDefault
const attribute = /** @type {EntityConstructor} */(this.entityType).attributes[key]
if (attribute?.constructor === Object && attribute.ignored) {
return false
}
return true
}