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

@@ -3,9 +3,9 @@ import Serializer from "./Serializer"
export default class GeneralSerializer extends Serializer {
constructor(keyword = "", entityType, prefix = "", separator = ",", trailingSeparator = false) {
super(entityType, prefix, separator, trailingSeparator)
this.keyword = keyword
constructor(keyword, entityType, prefix, separator, trailingSeparator, attributeValueConjunctionSign, attributeKeyPrinter) {
super(entityType, prefix, separator, trailingSeparator, attributeValueConjunctionSign, attributeKeyPrinter)
this.keyword = keyword ?? ""
}
read(value) {
@@ -19,7 +19,7 @@ export default class GeneralSerializer extends Serializer {
}
write(object) {
let result = `${this.key ?? ""}(${this.subWrite([], object)})`
let result = `${this.keyword}(${this.subWrite([], object)})`
return result
}
}

View File

@@ -1,7 +1,7 @@
import FunctionReferenceEntity from "../entity/FunctionReferenceEntity"
import Guid from "../entity/primitive/Guid"
import Integer from "../entity/primitive/Integer"
import LocalizedTextEntity from "../entity/primitive/LocalizedTextEntity"
import LocalizedTextEntity from "../entity/LocalizedTextEntity"
import ObjectEntity from "../entity/ObjectEntity"
import ObjectReference from "../entity/primitive/ObjectReference"
import Parsimmon from "parsimmon"
@@ -54,7 +54,11 @@ export default class Grammar {
P.string(","),
r.String.trim(P.optWhitespace), // value
P.string(")"),
(_, namespace, __, key, ___, value, ____) => new LocalizedTextEntity(namespace, key, value)
(_, namespace, __, key, ___, value, ____) => new LocalizedTextEntity({
namespace: namespace,
key: key,
value: value
})
)
PinReference = r => P.seqMap(
r.PathSymbol,

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) {