ezobjects-mysql
Advanced tools
Comparing version 3.0.3 to 3.1.0
@@ -61,2 +61,3 @@ /** Require external modules */ | ||
{ name: `functionExample2`, type: `function`, store: true }, | ||
{ name: `plainObjectExample`, type: `object` }, | ||
{ name: `ezobjectTypeExample`, type: `OtherObj` }, | ||
@@ -102,2 +103,3 @@ { name: `ezobjectInstanceExample`, instanceOf: `OtherObj` }, | ||
{ name: `functionArrayExample2`, type: `Array`, arrayOf: { type: `function`, store: true } }, | ||
{ name: `plainObjectArrayExample`, type: `Array`, arrayOf: { type: `object` } }, | ||
{ name: `ezobjectTypeArrayExample`, type: `Array`, arrayOf: { type: `OtherObj` } }, | ||
@@ -175,2 +177,3 @@ { name: `ezobjectInstanceArrayExample`, type: `Array`, arrayOf: { instanceOf: `OtherObj` } }, | ||
functionExample2: (arg) => { return `I am ${arg} stored`; }, | ||
plainObjectExample: { a: 'I am A', 14: 'Plain Object' }, | ||
ezobjectTypeExample: new OtherObj({ name: `Type Example` }), | ||
@@ -216,2 +219,3 @@ ezobjectInstanceExample: new ExtendedObj({ name: `Instance Example Stored` }), | ||
functionArrayExample2: [(arg) => { return `I am ${arg} stored 1`; }, (arg) => { return `I am ${arg} stored 2`; }], | ||
plainObjectArrayExample: [{ a: 'I am A', 14: 'Plain Object' }, { and: 'So am I too a', 930: 'Plain Object' }], | ||
ezobjectTypeArrayExample: [new OtherObj({ name: `Type Example 1` }), new OtherObj({ name: `Type Example 2` })], | ||
@@ -218,0 +222,0 @@ ezobjectInstanceArrayExample: [new ExtendedObj({ name: `Instance Example Stored 1` }), new ExtendedObj({ name: `Instance Example Stored 2` })], |
const docket = require(`docket-parser`); | ||
docket.title(`EZ Objects v3.0.3`); | ||
docket.title(`EZ Objects v3.1.0`); | ||
docket.linkClass(`text-success`); | ||
docket.parseFiles([`index.js`, `mysql-connection.js`]); | ||
docket.generateDocs(`docs`); |
@@ -44,2 +44,4 @@ /** | ||
throw new TypeError(`${property.className}.${property.name}(): Non-Set value passed to '${property.type}' setter.`); | ||
else if ( x && property.ezobjectType.jsType == 'Object' && ( typeof x !== 'object' || x.constructor.type == 'Object' ) ) | ||
throw new TypeError(`${property.className}.${property.name}(): Non-Object value passed to '${property.type}' setter.`); | ||
else if ( x && property.ezobjectType.jsType == 'object' && ( typeof x !== 'object' || ( typeof property.type == 'string' && x.constructor.name != property.originalType ) || ( typeof property.instanceOf === 'string' && !module.exports.instanceOf(x, property.instanceOf) ) ) ) | ||
@@ -83,2 +85,4 @@ throw new TypeError(`${property.className}.${property.name}(): Invalid value passed to '${typeof property.type === 'string' ? property.originalType : property.instanceOf}' setter.`); | ||
throw new TypeError(`${property.className}.${property.name}(): Non-Set value passed as element of Array[${property.arrayOf.type}] setter.`); | ||
else if ( property.ezobjectType.jsType == 'Object' && x && x.some(y => ( typeof y !== 'object' || y.constructor.name != 'Object' ) && y !== null) ) | ||
throw new TypeError(`${property.className}.${property.name}(): Non-Object value passed as element of Array[${property.arrayOf.type}] setter.`); | ||
else if ( property.ezobjectType.jsType == 'object' && x && x.some(y => y !== null && (typeof y !== 'object' || ( typeof property.arrayOf.type == 'string' && y.constructor.name != property.arrayOf.type ) || ( typeof property.arrayOf.instanceOf === 'string' && !module.exports.instanceOf(y, property.arrayOf.instanceOf) ))) ) | ||
@@ -149,2 +153,3 @@ throw new TypeError(`${property.className}.${property.name}(): Invalid value passed as element of Array[${typeof property.arrayOf.type === 'string' ? property.arrayOf.type : property.arrayOf.instanceOf}] setter.`); | ||
{ type: `function`, jsType: `function`, mysqlType: `text`, default: function () {}, setTransform: setTransform, saveTransform: x => x.toString(), loadTransform: x => eval(x) }, | ||
{ type: `object`, jsType: `Object`, mysqlType: `text`, default: {}, setTransform: setTransform, saveTransform: x => JSON.stringify(x), loadTransform: x => JSON.parse(x) }, | ||
{ type: `other`, jsType: `object`, mysqlType: `int`, default: null, setTransform: setTransform, saveTransform: x => x ? x.id() : -1, loadTransform: async (x, property, db) => await (new parent[typeof property.type === 'string' ? property.originalType : property.instanceOf]).load(x, db) }, | ||
@@ -185,2 +190,3 @@ | ||
{ type: `array`, jsType: `Array`, mysqlType: `mediumtext`, default: [], arrayOfType: `function`, setTransform: setArrayTransform, saveTransform: x => x.map(y => y.toString()).join(`!&|&!`), loadTransform: x => x.split(`!&|&!`).map(y => eval(y)) }, | ||
{ type: `array`, jsType: `Array`, mysqlType: `mediumtext`, default: [], arrayOfType: `object`, setTransform: setArrayTransform, saveTransform: x => JSON.stringify(x), loadTransform: x => JSON.parse(x) }, | ||
{ type: `array`, jsType: `Array`, mysqlType: `text`, default: [], arrayOfType: `other`, setTransform: setArrayTransform, saveTransform: x => x.map(y => y.id()).join(`,`), loadTransform: async (x, property, db) => { const arr = []; for ( let i = 0, list = x.split(`,`), i_max = list.length; i < i_max; i++ ) { if ( !isNaN(parseInt(list[i])) ) arr.push(await (new parent[typeof property.arrayOf.type === 'string' ? property.arrayOf.type : property.arrayOf.instanceOf]).load(parseInt(list[i]), db)); } return arr; } } | ||
@@ -187,0 +193,0 @@ ]; |
{ | ||
"name": "ezobjects-mysql", | ||
"version": "3.0.3", | ||
"version": "3.1.0", | ||
"description": "Easy dynamic object generation with optional MySQL table linking", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,2 @@ | ||
# EZ Objects - MySQL Edition - v3.0.3 | ||
# EZ Objects - MySQL Edition - v3.1.0 | ||
@@ -311,3 +311,3 @@ EZ Objects (MySQL Edition) is a Node.js module (that can also be usefully browserify'd) that aims to save | ||
`timestamp`, `datetime`, `year`, `char`, `varchar`, `binary`, `varbinary`, `tinyblob`, `blob`, `mediumblob`, `longblob`, `tinytext`, | ||
`text`, `mediumtext`, `longtext`, `enum`, `set`, `boolean`, `function`, any other valid object constructor name, or `array` where `arrayOf` is provided with information about the array element types. \[either **type** or **instanceOf** is required] | ||
`text`, `mediumtext`, `longtext`, `enum`, `set`, `boolean`, `function`, `object`, any other valid object constructor name, or `array` where `arrayOf` is provided with information about the array element types. \[either **type** or **instanceOf** is required] | ||
* **instanceOf** - `string` - (optional) JavaScript class constructor name that the property must be an instance of \[either **type** or **instanceOf** is required] | ||
@@ -318,3 +318,3 @@ * **default** - `mixed` - (optional) Sets the default value for the property in the class object | ||
`timestamp`, `datetime`, `year`, `char`, `varchar`, `binary`, `varbinary`, `tinyblob`, `blob`, `mediumblob`, `longblob`, `tinytext`, | ||
`text`, `mediumtext`, `longtext`, `enum`, `set`, `boolean`, `function`, or any other valid object constructor name (which can alternatively be used with `instanceOf` instead). \[either **type** or **instanceOf** is required] | ||
`text`, `mediumtext`, `longtext`, `enum`, `set`, `boolean`, `function`, `object`, or any other valid object constructor name (which can alternatively be used with `instanceOf` instead). \[either **type** or **instanceOf** is required] | ||
* **setTransform(x, propertyConfig)** - `function` - (optional) Function that transforms and returns the property value prior to setting. The handler for this transform will be passed the expected value `type`, if needed. | ||
@@ -381,2 +381,3 @@ | ||
* `function` - `function () { }` | ||
* `object` - `{}` | ||
* All `array` types - `[]` | ||
@@ -383,0 +384,0 @@ * All other types - `null` |
Sorry, the diff of this file is not supported yet
411177
2676
391