From 6a3e2cc36fe3afac25ce59ec67c984097a11547d Mon Sep 17 00:00:00 2001 From: barsdeveloper Date: Tue, 23 Nov 2021 20:40:27 +0100 Subject: [PATCH] Guid => GuidEntity --- dist/ueblueprint.js | 45 +++++++++++++--------------- js/entity/GuidEntity.js | 28 +++++++++++++++++ js/entity/ObjectEntity.js | 4 +-- js/entity/PinEntity.js | 6 ++-- js/entity/PinReferenceEntity.js | 4 +-- js/entity/VariableReferenceEntity.js | 4 +-- js/entity/primitive/Guid.js | 32 -------------------- js/export.js | 2 ++ js/serialization/Grammar.js | 6 ++-- 9 files changed, 63 insertions(+), 68 deletions(-) create mode 100755 js/entity/GuidEntity.js delete mode 100755 js/entity/primitive/Guid.js diff --git a/dist/ueblueprint.js b/dist/ueblueprint.js index 0166cb7..3306729 100644 --- a/dist/ueblueprint.js +++ b/dist/ueblueprint.js @@ -850,34 +850,30 @@ class Entity { } } -class Guid extends Primitive { +class GuidEntity extends Entity { - static generateGuid(random) { + static attributes = { + value: String + } + + static generateGuid(random = true) { let values = new Uint32Array(4); if (random === true) { crypto.getRandomValues(values); } - let result = ""; + let guid = ""; values.forEach(n => { - result += ('00000000' + n.toString(16).toUpperCase()).slice(-8); + guid += ('00000000' + n.toString(16).toUpperCase()).slice(-8); }); - return result + return new GuidEntity({ valud: guid }) } - constructor(guid) { - super(); - // Using constructor equality and not instanceof in order to consider both primitives and objects - if (guid?.constructor === Boolean) { - guid = Guid.generateGuid(guid == true); - } - if (guid instanceof Guid) { - guid = guid.value; - } - this.value = guid; + getAttributes() { + return GuidEntity.attributes } toString() { - return this.value.toString() + return this.value } } @@ -925,7 +921,7 @@ class PinReferenceEntity extends Entity { static attributes = { objectName: PathSymbolEntity, - pinGuid: Guid + pinGuid: GuidEntity } getAttributes() { @@ -936,7 +932,7 @@ class PinReferenceEntity extends Entity { class PinEntity extends Entity { static attributes = { - PinId: Guid, + PinId: GuidEntity, PinName: "", PinFriendlyName: new TypeInitialization(LocalizedTextEntity, false, null), PinToolTip: "", @@ -956,7 +952,7 @@ class PinEntity extends Entity { LinkedTo: [PinReferenceEntity], DefaultValue: "", AutogeneratedDefaultValue: "", - PersistentGuid: Guid, + PersistentGuid: GuidEntity, bHidden: false, bNotConnectable: false, bDefaultValueIsReadOnly: false, @@ -1070,7 +1066,7 @@ class VariableReferenceEntity extends Entity { static attributes = { MemberName: String, - MemberGuid: Guid, + MemberGuid: GuidEntity, bSelfContext: false } @@ -1090,7 +1086,7 @@ class ObjectEntity extends Entity { TargetType: new TypeInitialization(ObjectReferenceEntity, false, null), NodePosX: 0, NodePosY: 0, - NodeGuid: Guid, + NodeGuid: GuidEntity, CustomProperties: [PinEntity] } @@ -1323,7 +1319,7 @@ class Grammar { Integer = _ => P.regex(/[0-9]+/).map(v => new Integer(v)).desc("an integer") String = _ => P.regex(/(?:[^"\\]|\\")*/).wrap(P.string('"'), P.string('"')).desc('string (with possibility to escape the quote using \")') Word = _ => P.regex(/[a-zA-Z]+/).desc("a word") - Guid = _ => P.regex(/[0-9a-zA-Z]{32}/).map(v => new Guid(v)).desc("32 digit hexadecimal (accepts all the letters for safety) value") + Guid = _ => P.regex(/[0-9a-zA-Z]{32}/).map(v => new GuidEntity({ value: v })).desc("32 digit hexadecimal (accepts all the letters for safety) value") PathSymbolEntity = _ => P.regex(/[0-9a-zA-Z_]+/).map(v => new PathSymbolEntity({ value: v })) ReferencePath = r => P.seq(P.string("/"), r.PathSymbolEntity.map(v => v.toString()).sepBy1(P.string(".")).tieWith(".")) .tie() @@ -1379,7 +1375,7 @@ class Grammar { return r.Integer case String: return r.String - case Guid: + case GuidEntity: return r.Guid case ObjectReferenceEntity: return r.Reference @@ -2224,6 +2220,7 @@ SerializerFactory.registerSerializer( : "" )) ); -SerializerFactory.registerSerializer(PathSymbolEntity, new ToStringSerializer(PathSymbolEntity)); +SerializerFactory.registerSerializer(PathSymbolEntity, new ToStringSerializer(PathSymbolEntity)); +SerializerFactory.registerSerializer(GuidEntity, new ToStringSerializer(GuidEntity)); export { Blueprint, GraphLink, GraphNode }; diff --git a/js/entity/GuidEntity.js b/js/entity/GuidEntity.js new file mode 100755 index 0000000..05b085e --- /dev/null +++ b/js/entity/GuidEntity.js @@ -0,0 +1,28 @@ +import Entity from "./Entity" + +export default class GuidEntity extends Entity { + + static attributes = { + value: String + } + + static generateGuid(random = true) { + let values = new Uint32Array(4) + if (random === true) { + crypto.getRandomValues(values) + } + let guid = "" + values.forEach(n => { + guid += ('00000000' + n.toString(16).toUpperCase()).slice(-8) + }) + return new GuidEntity({ valud: guid }) + } + + getAttributes() { + return GuidEntity.attributes + } + + toString() { + return this.value + } +} diff --git a/js/entity/ObjectEntity.js b/js/entity/ObjectEntity.js index 0391540..cdfddec 100755 --- a/js/entity/ObjectEntity.js +++ b/js/entity/ObjectEntity.js @@ -1,6 +1,6 @@ import Entity from "./Entity" import FunctionReferenceEntity from "./FunctionReferenceEntity" -import Guid from "./primitive/Guid" +import GuidEntity from "./GuidEntity" import ObjectReferenceEntity from "./ObjectReferenceEntity" import PinEntity from "./PinEntity" import TypeInitialization from "./TypeInitialization" @@ -17,7 +17,7 @@ export default class ObjectEntity extends Entity { TargetType: new TypeInitialization(ObjectReferenceEntity, false, null), NodePosX: 0, NodePosY: 0, - NodeGuid: Guid, + NodeGuid: GuidEntity, CustomProperties: [PinEntity] } diff --git a/js/entity/PinEntity.js b/js/entity/PinEntity.js index 48937d2..bc46a65 100755 --- a/js/entity/PinEntity.js +++ b/js/entity/PinEntity.js @@ -1,5 +1,5 @@ import Entity from "./Entity" -import Guid from "./primitive/Guid" +import GuidEntity from "./GuidEntity" import LocalizedTextEntity from "./LocalizedTextEntity" import ObjectReferenceEntity from "./ObjectReferenceEntity" import PinReferenceEntity from "./PinReferenceEntity" @@ -8,7 +8,7 @@ import TypeInitialization from "./TypeInitialization" export default class PinEntity extends Entity { static attributes = { - PinId: Guid, + PinId: GuidEntity, PinName: "", PinFriendlyName: new TypeInitialization(LocalizedTextEntity, false, null), PinToolTip: "", @@ -28,7 +28,7 @@ export default class PinEntity extends Entity { LinkedTo: [PinReferenceEntity], DefaultValue: "", AutogeneratedDefaultValue: "", - PersistentGuid: Guid, + PersistentGuid: GuidEntity, bHidden: false, bNotConnectable: false, bDefaultValueIsReadOnly: false, diff --git a/js/entity/PinReferenceEntity.js b/js/entity/PinReferenceEntity.js index e071185..00aaa5e 100755 --- a/js/entity/PinReferenceEntity.js +++ b/js/entity/PinReferenceEntity.js @@ -1,12 +1,12 @@ import Entity from "./Entity" -import Guid from "./primitive/Guid" +import GuidEntity from "./GuidEntity" import PathSymbol from "./PathSymbolEntity" export default class PinReferenceEntity extends Entity { static attributes = { objectName: PathSymbol, - pinGuid: Guid + pinGuid: GuidEntity } getAttributes() { diff --git a/js/entity/VariableReferenceEntity.js b/js/entity/VariableReferenceEntity.js index cf4e1ed..141d9e2 100755 --- a/js/entity/VariableReferenceEntity.js +++ b/js/entity/VariableReferenceEntity.js @@ -1,11 +1,11 @@ import Entity from "./Entity" -import Guid from "./primitive/Guid" +import GuidEntity from "./GuidEntity" export default class VariableReferenceEntity extends Entity { static attributes = { MemberName: String, - MemberGuid: Guid, + MemberGuid: GuidEntity, bSelfContext: false } diff --git a/js/entity/primitive/Guid.js b/js/entity/primitive/Guid.js deleted file mode 100755 index 1c9e9b5..0000000 --- a/js/entity/primitive/Guid.js +++ /dev/null @@ -1,32 +0,0 @@ -import Primitive from "./Primitive" - -export default class Guid extends Primitive { - - static generateGuid(random) { - let values = new Uint32Array(4) - if (random === true) { - crypto.getRandomValues(values) - } - let result = "" - values.forEach(n => { - result += ('00000000' + n.toString(16).toUpperCase()).slice(-8) - }) - return result - } - - constructor(guid) { - super() - // Using constructor equality and not instanceof in order to consider both primitives and objects - if (guid?.constructor === Boolean) { - guid = Guid.generateGuid(guid == true) - } - if (guid instanceof Guid) { - guid = guid.value - } - this.value = guid - } - - toString() { - return this.value.toString() - } -} diff --git a/js/export.js b/js/export.js index d5ef9fc..92f4d04 100755 --- a/js/export.js +++ b/js/export.js @@ -4,6 +4,7 @@ import FunctionReferenceEntity from "./entity/FunctionReferenceEntity" import GeneralSerializer from "./serialization/GeneralSerializer" import GraphLink from "./graph/GraphLink" import GraphNode from "./graph/GraphNode" +import GuidEntity from "./entity/GuidEntity" import LocalizedTextEntity from "./entity/LocalizedTextEntity" import ObjectEntity from "./entity/ObjectEntity" import ObjectReferenceEntity from "./entity/ObjectReferenceEntity" @@ -45,5 +46,6 @@ SerializerFactory.registerSerializer( )) ) SerializerFactory.registerSerializer(PathSymbolEntity, new ToStringSerializer(PathSymbolEntity)) +SerializerFactory.registerSerializer(GuidEntity, new ToStringSerializer(GuidEntity)) export { Blueprint as Blueprint, GraphNode as GraphNode, GraphLink as GraphLink } \ No newline at end of file diff --git a/js/serialization/Grammar.js b/js/serialization/Grammar.js index 74a3ec7..c2c7d9c 100755 --- a/js/serialization/Grammar.js +++ b/js/serialization/Grammar.js @@ -1,5 +1,5 @@ import FunctionReferenceEntity from "../entity/FunctionReferenceEntity" -import Guid from "../entity/primitive/Guid" +import GuidEntity from "../entity/GuidEntity" import Integer from "../entity/primitive/Integer" import LocalizedTextEntity from "../entity/LocalizedTextEntity" import ObjectEntity from "../entity/ObjectEntity" @@ -24,7 +24,7 @@ export default class Grammar { Integer = _ => P.regex(/[0-9]+/).map(v => new Integer(v)).desc("an integer") String = _ => P.regex(/(?:[^"\\]|\\")*/).wrap(P.string('"'), P.string('"')).desc('string (with possibility to escape the quote using \")') Word = _ => P.regex(/[a-zA-Z]+/).desc("a word") - Guid = _ => P.regex(/[0-9a-zA-Z]{32}/).map(v => new Guid(v)).desc("32 digit hexadecimal (accepts all the letters for safety) value") + Guid = _ => P.regex(/[0-9a-zA-Z]{32}/).map(v => new GuidEntity({ value: v })).desc("32 digit hexadecimal (accepts all the letters for safety) value") PathSymbolEntity = _ => P.regex(/[0-9a-zA-Z_]+/).map(v => new PathSymbolEntity({ value: v })) ReferencePath = r => P.seq(P.string("/"), r.PathSymbolEntity.map(v => v.toString()).sepBy1(P.string(".")).tieWith(".")) .tie() @@ -80,7 +80,7 @@ export default class Grammar { return r.Integer case String: return r.String - case Guid: + case GuidEntity: return r.Guid case ObjectReferenceEntity: return r.Reference