Indexed array entity, user defined pins

This commit is contained in:
barsdeveloper
2023-04-04 22:52:42 +02:00
parent 3e2a20302f
commit 7d84062ff6
8 changed files with 151 additions and 45 deletions

View File

@@ -1,3 +1,4 @@
import IndexedArray from "../entity/IndexedArray.js"
import SerializerFactory from "./SerializerFactory.js"
import Utility from "../Utility.js"
@@ -66,14 +67,29 @@ export default class ISerializer {
const value = entity[key]
if (value !== undefined && this.showProperty(entity, key)) {
const isSerialized = Utility.isSerialized(entity, key)
if (value instanceof IndexedArray) {
value.value.forEach((value, i) =>
result += (result.length ? this.attributeSeparator : "")
+ this.attributePrefix
+ Utility.decodeKeyName(this.attributeKeyPrinter(key))
+ `(${i})`
+ this.attributeValueConjunctionSign
+ (
isSerialized
? `"${this.writeValue(value, true)}"`
: this.writeValue(value, insideString)
)
)
continue
}
result += (result.length ? this.attributeSeparator : "")
+ this.attributePrefix
+ Utility.decodeKeyName(this.attributeKeyPrinter(key))
+ this.attributeValueConjunctionSign
+ (
isSerialized
? `"${this.writeValue(entity, key, true)}"`
: this.writeValue(entity, key, insideString)
? `"${this.writeValue(value, true)}"`
: this.writeValue(value, insideString)
)
}
}
@@ -86,19 +102,20 @@ export default class ISerializer {
/**
* @protected
* @param {String} key
* @param {Boolean} insideString
*/
writeValue(entity, key, insideString) {
const value = entity[key]
writeValue(value, insideString) {
const type = Utility.getType(value)
// @ts-expect-error
const serializer = SerializerFactory.getSerializer(type)
if (!serializer) {
throw new Error(`Unknown value type "${type.name}", a serializer must be registered in the SerializerFactory class, check initializeSerializerFactory.js`)
throw new Error(
`Unknown value type "${type.name}", a serializer must be registered in the SerializerFactory class, `
+ "check initializeSerializerFactory.js"
)
}
return serializer.write(
entity[key],
value,
insideString
)
}