@haventech/supertype
Advanced tools
Comparing version 6.0.0-beta.1 to 6.0.0-beta.2
@@ -199,2 +199,14 @@ import * as serializer from './serializer'; | ||
/** | ||
* Overridable property used by template setup to create an property descriptor for use by the constructor | ||
* | ||
* @param {unknown} propertyName is the name of the property | ||
* @param {unknown} defineProperty is the property descriptor passed to the template | ||
* @param {unknown} objectProperties is all properties that will be processed manually. A new property is | ||
* added to this if the property needs to be initialized by value | ||
* @param {unknown} defineProperties is all properties that will be passed to Object.defineProperties | ||
* A new property will be added to this object | ||
* | ||
*/ | ||
static _setupProperty(propertyName: any, defineProperty: any, objectProperties: any, defineProperties: any): void; | ||
/** | ||
* Clone an object created from an ObjectTemplate | ||
@@ -222,9 +234,9 @@ * Used only within supertype (see copyObject for general copy) | ||
/** | ||
* Purpose unknown | ||
* | ||
* @param {unknown} obj unknown | ||
* @param {unknown} creator unknown | ||
* | ||
* @returns {unknown} | ||
*/ | ||
* Purpose unknown | ||
* | ||
* @param {unknown} obj unknown | ||
* @param {unknown} creator unknown | ||
* | ||
* @returns {unknown} | ||
*/ | ||
static createCopy(obj: any, creator: any): any; | ||
@@ -273,2 +285,13 @@ /** | ||
/** | ||
* Overridable property to find the right subclass to instantiate by either looking at the | ||
* declared list in the subClasses define property or walking through | ||
* the subclasses of the declared template | ||
* | ||
* @param {unknown} template unknown | ||
* @param {unknown} objId unknown | ||
* @param {unknown} defineProperty unknown | ||
* @returns {*} | ||
*/ | ||
static _resolveSubClass(template: any, objId: any, defineProperty: any): any; | ||
/** | ||
* Return the highest level template | ||
@@ -275,0 +298,0 @@ * |
{ | ||
"name": "@haventech/supertype", | ||
"description": "A type system for classical inheritence, mix-ins and composition.", | ||
"version": "6.0.0-beta.1", | ||
"version": "6.0.0-beta.2", | ||
"main": "dist/index.js", | ||
@@ -33,3 +33,3 @@ "types": "dist/index.d.ts", | ||
"compile": "tsc", | ||
"test": "mocha test/**/*.js dist/test/**/*.js", | ||
"test": "mocha test/**/*.js", | ||
"test:config": "mocha test/config", | ||
@@ -36,0 +36,0 @@ "test:example": "mocha test/example", |
@@ -527,3 +527,2 @@ import * as serializer from './serializer'; | ||
/** | ||
@@ -539,2 +538,81 @@ * Overridden by other Type Systems to inject other elements | ||
/** | ||
* Overridable property used by template setup to create an property descriptor for use by the constructor | ||
* | ||
* @param {unknown} propertyName is the name of the property | ||
* @param {unknown} defineProperty is the property descriptor passed to the template | ||
* @param {unknown} objectProperties is all properties that will be processed manually. A new property is | ||
* added to this if the property needs to be initialized by value | ||
* @param {unknown} defineProperties is all properties that will be passed to Object.defineProperties | ||
* A new property will be added to this object | ||
* | ||
*/ | ||
static _setupProperty(propertyName, defineProperty, objectProperties, defineProperties) { | ||
// Determine whether value needs to be re-initialized in constructor | ||
const value = defineProperty.value; | ||
const byValue = value && typeof (value) !== 'number' && typeof (value) !== 'string'; | ||
if (byValue || !Object.defineProperties || defineProperty.get || defineProperty.set) { | ||
objectProperties[propertyName] = { | ||
init: defineProperty.value, | ||
type: defineProperty.type, | ||
of: defineProperty.of, | ||
byValue | ||
}; | ||
delete defineProperty.value; | ||
} | ||
// When a super class based on objectTemplate don't transport properties | ||
defineProperty.toServer = false; | ||
defineProperty.toClient = false; | ||
defineProperties[propertyName] = defineProperty; | ||
// Add getters and setters | ||
if (defineProperty.get || defineProperty.set) { | ||
const userSetter = defineProperty.set; | ||
defineProperty.set = (function d() { | ||
// Use a closure to record the property name which is not passed to the setter | ||
const prop = propertyName; | ||
return function c(value) { | ||
if (userSetter) { | ||
value = userSetter.call(this, value); | ||
} | ||
if (!defineProperty.isVirtual) { | ||
this[`__${prop}`] = value; | ||
} | ||
}; | ||
})(); | ||
const userGetter = defineProperty.get; | ||
defineProperty.get = (function get() { | ||
// Use closure to record property name which is not passed to the getter | ||
const prop = propertyName; | ||
return function b() { | ||
if (userGetter) { | ||
if (defineProperty.isVirtual) { | ||
return userGetter.call(this, undefined); | ||
} | ||
return userGetter.call(this, this[`__${prop}`]); | ||
} | ||
return this[`__${prop}`]; | ||
}; | ||
})(); | ||
if (!defineProperty.isVirtual) { | ||
defineProperties[`__${propertyName}`] = { enumerable: false, writable: true }; | ||
} | ||
delete defineProperty.value; | ||
delete defineProperty.writable; | ||
} | ||
} | ||
/** | ||
* Clone an object created from an ObjectTemplate | ||
@@ -611,9 +689,9 @@ * Used only within supertype (see copyObject for general copy) | ||
/** | ||
* Purpose unknown | ||
* | ||
* @param {unknown} obj unknown | ||
* @param {unknown} creator unknown | ||
* | ||
* @returns {unknown} | ||
*/ | ||
* Purpose unknown | ||
* | ||
* @param {unknown} obj unknown | ||
* @param {unknown} creator unknown | ||
* | ||
* @returns {unknown} | ||
*/ | ||
static createCopy(obj, creator) { | ||
@@ -671,2 +749,39 @@ return this.fromPOJO(obj, obj.__template__, null, null, undefined, null, null, creator); | ||
/** | ||
* Overridable property to find the right subclass to instantiate by either looking at the | ||
* declared list in the subClasses define property or walking through | ||
* the subclasses of the declared template | ||
* | ||
* @param {unknown} template unknown | ||
* @param {unknown} objId unknown | ||
* @param {unknown} defineProperty unknown | ||
* @returns {*} | ||
*/ | ||
static _resolveSubClass(template, objId, defineProperty) { | ||
let templateName = ''; | ||
if (objId.match(/-([A-Za-z0-9_:]*)-/)) { | ||
templateName = RegExp.$1; | ||
} | ||
// Resolve template subclass for polymorphic instantiation | ||
if (defineProperty && defineProperty.subClasses && objId != 'anonymous)') { | ||
if (templateName) { | ||
for (let ix = 0; ix < defineProperty.subClasses.length; ++ix) { | ||
if (templateName == defineProperty.subClasses[ix].__name__) { | ||
template = defineProperty.subClasses[ix]; | ||
} | ||
} | ||
} | ||
} | ||
else { | ||
const subClass = ObjectTemplateStatic._findSubClass(template, templateName); | ||
if (subClass) { | ||
template = subClass; | ||
} | ||
} | ||
return template; | ||
} | ||
/** | ||
* Return the highest level template | ||
@@ -700,3 +815,3 @@ * | ||
static _createEmptyObject(template, objId, defineProperty) { | ||
template = ObjectTemplateStatic._resolveSubClass(template, objId, defineProperty); | ||
template = this._resolveSubClass(template, objId, defineProperty); | ||
@@ -1083,3 +1198,3 @@ const oldStashObject = this._stashObject; | ||
ObjectTemplateStatic._setupProperty(propertyName, defineProperty, objectProperties, defineProperties); | ||
objectTemplate._setupProperty(propertyName, defineProperty, objectProperties, defineProperties); | ||
defineProperty.sourceTemplate = templateName; | ||
@@ -1108,118 +1223,2 @@ } | ||
/** | ||
* Used by template setup to create an property descriptor for use by the constructor | ||
* | ||
* @param {unknown} propertyName is the name of the property | ||
* @param {unknown} defineProperty is the property descriptor passed to the template | ||
* @param {unknown} objectProperties is all properties that will be processed manually. A new property is | ||
* added to this if the property needs to be initialized by value | ||
* @param {unknown} defineProperties is all properties that will be passed to Object.defineProperties | ||
* A new property will be added to this object | ||
* | ||
*/ | ||
static _setupProperty(propertyName, defineProperty, objectProperties, defineProperties) { | ||
// Determine whether value needs to be re-initialized in constructor | ||
const value = defineProperty.value; | ||
const byValue = value && typeof (value) !== 'number' && typeof (value) !== 'string'; | ||
if (byValue || !Object.defineProperties || defineProperty.get || defineProperty.set) { | ||
objectProperties[propertyName] = { | ||
init: defineProperty.value, | ||
type: defineProperty.type, | ||
of: defineProperty.of, | ||
byValue | ||
}; | ||
delete defineProperty.value; | ||
} | ||
// When a super class based on objectTemplate don't transport properties | ||
defineProperty.toServer = false; | ||
defineProperty.toClient = false; | ||
defineProperties[propertyName] = defineProperty; | ||
// Add getters and setters | ||
if (defineProperty.get || defineProperty.set) { | ||
const userSetter = defineProperty.set; | ||
defineProperty.set = (function d() { | ||
// Use a closure to record the property name which is not passed to the setter | ||
const prop = propertyName; | ||
return function c(value) { | ||
if (userSetter) { | ||
value = userSetter.call(this, value); | ||
} | ||
if (!defineProperty.isVirtual) { | ||
this[`__${prop}`] = value; | ||
} | ||
}; | ||
})(); | ||
const userGetter = defineProperty.get; | ||
defineProperty.get = (function get() { | ||
// Use closure to record property name which is not passed to the getter | ||
const prop = propertyName; | ||
return function b() { | ||
if (userGetter) { | ||
if (defineProperty.isVirtual) { | ||
return userGetter.call(this, undefined); | ||
} | ||
return userGetter.call(this, this[`__${prop}`]); | ||
} | ||
return this[`__${prop}`]; | ||
}; | ||
})(); | ||
if (!defineProperty.isVirtual) { | ||
defineProperties[`__${propertyName}`] = { enumerable: false, writable: true }; | ||
} | ||
delete defineProperty.value; | ||
delete defineProperty.writable; | ||
} | ||
} | ||
/** | ||
* Find the right subclass to instantiate by either looking at the | ||
* declared list in the subClasses define property or walking through | ||
* the subclasses of the declared template | ||
* | ||
* @param {unknown} template unknown | ||
* @param {unknown} objId unknown | ||
* @param {unknown} defineProperty unknown | ||
* @returns {*} | ||
*/ | ||
static _resolveSubClass(template, objId, defineProperty) { | ||
let templateName = ''; | ||
if (objId.match(/-([A-Za-z0-9_:]*)-/)) { | ||
templateName = RegExp.$1; | ||
} | ||
// Resolve template subclass for polymorphic instantiation | ||
if (defineProperty && defineProperty.subClasses && objId != 'anonymous)') { | ||
if (templateName) { | ||
for (let ix = 0; ix < defineProperty.subClasses.length; ++ix) { | ||
if (templateName == defineProperty.subClasses[ix].__name__) { | ||
template = defineProperty.subClasses[ix]; | ||
} | ||
} | ||
} | ||
} | ||
else { | ||
const subClass = this._findSubClass(template, templateName); | ||
if (subClass) { | ||
template = subClass; | ||
} | ||
} | ||
return template; | ||
} | ||
/** | ||
* Walk recursively through extensions of template via __children__ | ||
@@ -1226,0 +1225,0 @@ * looking for a name match |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
365152
132
4494
0