JSDoc complete type check

This commit is contained in:
barsdeveloper
2022-10-09 11:43:28 +02:00
parent 91e1e0885e
commit cdc5e5b91b
68 changed files with 1603 additions and 648 deletions

View File

@@ -7,4 +7,10 @@ export default class FunctionReferenceEntity extends IEntity {
MemberParent: ObjectReferenceEntity,
MemberName: "",
}
constructor(options = {}) {
super(options)
/** @type {ObjectReferenceEntity} */ this.MemberParent
/** @type {String} */ this.MemberName
}
}

View File

@@ -18,6 +18,11 @@ export default class GuidEntity extends IEntity {
return new GuidEntity({ value: guid })
}
constructor(options = {}) {
super(options)
/** @type {String} */ this.value
}
valueOf() {
return this.value
}

View File

@@ -4,6 +4,11 @@ import SerializerFactory from "../serialization/SerializerFactory"
import TypeInitialization from "./TypeInitialization"
import Utility from "../Utility"
/**
* @template {IEntity} T
* @typedef {new (Object) => T} IEntityConstructor
*/
export default class IEntity extends Observable {
static attributes = {}
@@ -44,6 +49,7 @@ export default class IEntity extends Observable {
}
// Not instanceof because all objects are instenceof Object, exact match needed
// @ts-expect-error
if (defaultType === Object) {
target[property] = {}
defineAllAttributes(target[property], properties[property], values[property], property + ".")
@@ -58,7 +64,8 @@ export default class IEntity extends Observable {
&& defaultValue.serialized
&& defaultValue.type !== String
) {
value = SerializerFactory.getSerializer(defaultValue.type).deserialize(value)
// @ts-expect-error
value = SerializerFactory.getSerializer((defaultValue.type)).deserialize(value)
}
target[property] = TypeInitialization.sanitize(value, Utility.getType(defaultValue))
continue // We have a value, need nothing more
@@ -72,6 +79,7 @@ export default class IEntity extends Observable {
if (defaultValue.serialized) {
defaultValue = ""
} else {
// @ts-expect-error
defaultType = defaultValue.type
defaultValue = defaultValue.value
}
@@ -82,6 +90,7 @@ export default class IEntity extends Observable {
target[property] = TypeInitialization.sanitize(defaultValue, defaultType)
}
}
// @ts-expect-error
const attributes = this.constructor.attributes
if (values.constructor !== Object && Object.getOwnPropertyNames(attributes).length == 1) {
// Where there is just one attribute, option can be the value of that attribute

View File

@@ -11,6 +11,11 @@ export default class IdentifierEntity extends IEntity {
toAttribute: (value, type) => value.toString()
}
constructor(options = {}) {
super(options)
/** @type {String} */ this.value
}
valueOf() {
return this.value
}

View File

@@ -9,6 +9,7 @@ export default class IntegerEntity extends IEntity {
/** @param {Object | Number | String} options */
constructor(options = 0) {
super(options)
/** @type {Number} */
this.value = Math.round(this.value)
}

View File

@@ -6,4 +6,9 @@ export default class InvariantTextEntity extends IEntity {
static attributes = {
value: String,
}
constructor(options = {}) {
super(options)
/** @type {String} */ this.value
}
}

View File

@@ -19,5 +19,11 @@ export default class KeyBindingEntity extends IEntity {
options.bAlt = options.bAlt ?? false
options.bCmd = options.bCmd ?? false
super(options)
/** @type {String} */ this.ActionName
/** @type {Boolean} */ this.bShift
/** @type {Boolean} */ this.bCtrl
/** @type {Boolean} */ this.bAlt
/** @type {Boolean} */ this.bCmd
/** @type {IdentifierEntity} */ this.Key
}
}

View File

@@ -10,7 +10,55 @@ export default class LinearColorEntity extends IEntity {
A: Number,
}
static fromWheelLocation([x, y], radius) {
x -= radius
y -= radius
const mod = Math.sqrt(x * x + y * y)
}
constructor(options = {}) {
super(options)
/** @type {Number} */ this.R
/** @type {Number} */ this.G
/** @type {Number} */ this.B
/** @type {Number} */ this.A
}
toRGBA() {
return [this.R, this.G, this.B, this.A]
}
toHSV() {
const max = Math.max(this.R, this.G, this.B)
const min = Math.min(this.R, this.G, this.B)
const d = max - min
let h
const s = (max === 0 ? 0 : d / max)
const v = max / 255
switch (max) {
case min:
h = 0
break
case this.R:
h = (this.G - this.B) + d * (this.G < this.B ? 6 : 0)
break
case this.G:
h = (this.B - this.R) + d * 2
break
case this.B:
h = (this.R - this.G) + d * 4
break
}
h /= 6 * d
return [h, s, v]
}
toNumber() {
return this.A + this.B << 8 + this.G << 16 + this.R << 24
}
toString() {
return Utility.printLinearColor(this)
}
}

View File

@@ -8,4 +8,11 @@ export default class LocalizedTextEntity extends IEntity {
key: String,
value: String,
}
constructor(options = {}) {
super(options)
/** @type {String} */ this.namespace
/** @type {String} */ this.key
/** @type {String} */ this.value
}
}

View File

@@ -31,6 +31,25 @@ export default class ObjectEntity extends IEntity {
static nameRegex = /(\w+)_(\d+)/
constructor(options = {}) {
super(options)
/** @type {ObjectReferenceEntity} */ this.Class
/** @type {String} */ this.Name
/** @type {Boolean?} */ this.bIsPureFunc
/** @type {VariableReferenceEntity?} */ this.VariableReference
/** @type {FunctionReferenceEntity?} */ this.FunctionReference
/** @type {FunctionReferenceEntity?} */ this.EventReference
/** @type {ObjectReferenceEntity?} */ this.TargetType
/** @type {IntegerEntity} */ this.NodePosX
/** @type {IntegerEntity} */ this.NodePosY
/** @type {IdentifierEntity?} */ this.AdvancedPinDisplay
/** @type {IdentifierEntity?} */ this.EnabledState
/** @type {GuidEntity} */ this.NodeGuid
/** @type {IntegerEntity?} */ this.ErrorType
/** @type {String?} */ this.ErrorMsg
/** @type {PinEntity[]} */ this.CustomProperties
}
getObjectName(dropCounter = false) {
if (dropCounter) {
return this.getNameAndCounter()[0]

View File

@@ -6,4 +6,10 @@ export default class ObjectReferenceEntity extends IEntity {
type: String,
path: String,
}
constructor(options = {}) {
super(options)
/** @type {String} */ this.type
/** @type {String} */ this.path
}
}

View File

@@ -6,6 +6,11 @@ export default class PathSymbolEntity extends IEntity {
value: String,
}
constructor(options = {}) {
super(options)
/** @type {String} */ this.value
}
valueOf() {
return this.value
}

View File

@@ -11,6 +11,9 @@ import SimpleSerializationVectorEntity from "./SimpleSerializationVectorEntity"
import TypeInitialization from "./TypeInitialization"
import VectorEntity from "./VectorEntity"
/** @typedef {import("./TypeInitialization").AnyValue} AnyValue */
/** @template {AnyValue} T */
export default class PinEntity extends IEntity {
static #typeEntityMap = {
@@ -76,6 +79,41 @@ export default class PinEntity extends IEntity {
: entity
}
constructor(options = {}) {
super(options)
/** @type {GuidEntity} */ this.PinId
/** @type {String} */ this.PinName
/** @type {LocalizedTextEntity} */ this.PinFriendlyName
/** @type {String} */ this.PinToolTip
/** @type {String} */ this.Direction
/**
* @type {{
* PinCategory: String,
* PinSubCategory: String,
* PinSubCategoryObject: ObjectReferenceEntity,
* PinSubCategoryMemberReference: any,
* PinValueType: String,
* ContainerType: ObjectReferenceEntity,
* bIsReference: Boolean,
* bIsConst: Boolean,
* bIsWeakPointer: Boolean,
* bIsUObjectWrapper: Boolean,
* bSerializeAsSinglePrecisionFloat: Boolean,
* }}
*/ this.PinType
/** @type {PinReferenceEntity[]} */ this.LinkedTo
/** @type {T} */ this.DefaultValue
/** @type {String} */ this.AutogeneratedDefaultValue
/** @type {ObjectReferenceEntity} */ this.DefaultObject
/** @type {GuidEntity} */ this.PersistentGuid
/** @type {Boolean} */ this.bHidden
/** @type {Boolean} */ this.bNotConnectable
/** @type {Boolean} */ this.bDefaultValueIsReadOnly
/** @type {Boolean} */ this.bDefaultValueIsIgnored
/** @type {Boolean} */ this.bAdvancedView
/** @type {Boolean} */ this.bOrphanedPin
}
getType() {
if (this.PinType.PinCategory == "struct") {
return this.PinType.PinSubCategoryObject.path
@@ -84,7 +122,7 @@ export default class PinEntity extends IEntity {
}
getDefaultValue() {
return this.DefaultValue ?? ""
return this.DefaultValue
}
isHidden() {
@@ -111,7 +149,7 @@ export default class PinEntity extends IEntity {
/** @type {PinReferenceEntity[]} */
this.LinkedTo
const linkFound = this.LinkedTo?.find(pinReferenceEntity => {
return pinReferenceEntity.objectName == targetObjectName
return pinReferenceEntity.objectName.toString() == targetObjectName
&& pinReferenceEntity.pinGuid.valueOf() == targetPinEntity.PinId.valueOf()
})
if (!linkFound) {
@@ -130,7 +168,7 @@ export default class PinEntity extends IEntity {
*/
unlinkFrom(targetObjectName, targetPinEntity) {
const indexElement = this.LinkedTo?.findIndex(pinReferenceEntity => {
return pinReferenceEntity.objectName == targetObjectName
return pinReferenceEntity.objectName.toString() == targetObjectName
&& pinReferenceEntity.pinGuid.valueOf() == targetPinEntity.PinId.valueOf()
})
if (indexElement >= 0) {

View File

@@ -8,4 +8,10 @@ export default class PinReferenceEntity extends IEntity {
objectName: PathSymbolEntity,
pinGuid: GuidEntity,
}
constructor(options = {}) {
super(options)
/** @type {PathSymbolEntity} */ this.objectName
/** @type {GuidEntity} */ this.pinGuid
}
}

View File

@@ -7,4 +7,11 @@ export default class RotatorEntity extends IEntity {
P: Number,
Y: Number,
}
constructor(values = {}) {
super(values)
/** @type {Number} */ this.R
/** @type {Number} */ this.P
/** @type {Number} */ this.Y
}
}

View File

@@ -1,7 +1,21 @@
/** @template T */
/**
* @typedef {import("./IEntity").default} IEntity
* @typedef {IEntity | String | Number | Boolean | Array} AnyValue
*/
/**
* @template {AnyValue} T
* @typedef {import("./IEntity").IEntityConstructor<T>} IEntityConstructor
*/
/**
* @template {AnyValue} T
* @typedef {IEntityConstructor<T> | StringConstructor | NumberConstructor | BooleanConstructor | ArrayConstructor} AnyValueConstructor
*/
/** @template {AnyValue} T */
export default class TypeInitialization {
/** @type {Constructor|Array<Constructor>} */
/** @type {AnyValueConstructor<T>|AnyValueConstructor<T>[]} */
#type
get type() {
return this.#type
@@ -18,7 +32,7 @@ export default class TypeInitialization {
this.#showDefault = v
}
/** @type {T} */
/** @type {T | T[] | String} */
#value
get value() {
return this.#value
@@ -54,10 +68,9 @@ export default class TypeInitialization {
}
/**
* @typedef {(new () => T) | StringConstructor | NumberConstructor | BooleanConstructor} Constructor
* @param {Constructor|Array<Constructor>} type
* @param {AnyValueConstructor<T>|AnyValueConstructor<T>[]} type
* @param {Boolean} showDefault
* @param {any} value
* @param {T | T[] | String} value
* @param {Boolean} serialized
*/
constructor(type, showDefault = true, value = undefined, serialized = false) {

View File

@@ -7,4 +7,11 @@ export default class VectorEntity extends IEntity {
Y: Number,
Z: Number,
}
constructor(options = {}) {
super(options)
/** @type {Number} */ this.X
/** @type {Number} */ this.Y
/** @type {Number} */ this.Z
}
}