Guid => GuidEntity

This commit is contained in:
barsdeveloper
2021-11-23 20:40:27 +01:00
parent a224903f35
commit 6a3e2cc36f
9 changed files with 63 additions and 68 deletions

28
js/entity/GuidEntity.js Executable file
View File

@@ -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
}
}

View File

@@ -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]
}

View File

@@ -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,

View File

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

View File

@@ -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
}

View File

@@ -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()
}
}