Bugfixes, LocalizedText is an entity again

This commit is contained in:
barsdeveloper
2021-10-31 14:51:36 +01:00
parent 113f65964d
commit 12e44c5482
10 changed files with 79 additions and 58 deletions

View File

@@ -11,17 +11,20 @@ export default class Serializer {
static grammar = Parsimmon.createLanguage(new Grammar())
constructor(entityType, prefix = "", separator = ",", trailingSeparator = false) {
constructor(entityType, prefix, separator, trailingSeparator, attributeValueConjunctionSign, attributeKeyPrinter) {
this.entityType = entityType
this.prefix = prefix
this.separator = separator
this.trailingSeparator = trailingSeparator
this.prefix = prefix ?? ""
this.separator = separator ?? ","
this.trailingSeparator = trailingSeparator ?? false
this.attributeValueConjunctionSign = attributeValueConjunctionSign ?? "="
this.attributeKeyPrinter = attributeKeyPrinter ?? (k => k.join("."))
}
writeValue(value) {
if (value === null) {
return "()"
}
// This is an exact match (and not instanceof) to hit also primitive types (by accessing value.constructor they are converted to objects automatically)
switch (value?.constructor) {
case Function:
return this.writeValue(value())
@@ -51,7 +54,11 @@ export default class Serializer {
// Recursive call when finding an object
result += this.subWrite(fullKey, value, this.prefix, this.separator)
} else if (this.showProperty(fullKey, value)) {
result += (result.length ? this.separator : "") + this.prefix + fullKey.join(".") + "=" + this.writeValue(value)
result += (result.length ? this.separator : "")
+ this.prefix
+ this.attributeKeyPrinter(fullKey)
+ this.attributeValueConjunctionSign
+ this.writeValue(value)
}
}
if (this.trailingSeparator && result.length) {