Comparing version 0.1.1 to 0.2.0
@@ -9,2 +9,4 @@ var conductor = require( "./lib/transaction/conductor" ); | ||
var ChangeSet = require( "./lib/history/changeset" ); | ||
module.exports = { | ||
@@ -16,3 +18,4 @@ conductor : conductor, | ||
TypeHelper : TypeHelper, | ||
TypeInfo : TypeInfo | ||
TypeInfo : TypeInfo, | ||
ChangeSet : ChangeSet | ||
}; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
"use strict"; | ||
var _ = require( "lodash" ); | ||
var EventEmitter = require( "events" ).EventEmitter; | ||
var extend = require( "mongoose-schema-extend" ); | ||
@@ -9,2 +10,3 @@ var mongoose = require( "mongoose" ); | ||
var TypeInfo = require( "./info.js" ); | ||
var util = require( "util" ); | ||
@@ -32,2 +34,4 @@ /** | ||
util.inherits( Type, EventEmitter ); | ||
/** | ||
@@ -34,0 +38,0 @@ * Construct a new type. |
@@ -19,3 +19,3 @@ "use strict"; | ||
* Removes fields from an instance which are set to null. | ||
* @param {Object} instance The instance of the type on which operations should be performed. | ||
* @param {Object|Object[]} instance The instance of the type on which operations should be performed. | ||
* @param {Boolean} [clone=false] Should the operation be performed on a copy of the instance instead? | ||
@@ -52,3 +52,3 @@ * @returns {*} The instance with the null fields removed. | ||
* Removes hidden fields from an instance of the type. | ||
* @param {Object} instance The instance of the type on which operations should be performed. | ||
* @param {Object|Object[]} instance The instance of the type on which operations should be performed. | ||
* @param {String} [userClass="user"] The user class for which to check the hidden attribute. | ||
@@ -100,3 +100,3 @@ * @param {Boolean} [clone=false] Should the operation be performed on a copy of the instance instead? | ||
* Removes read-only fields from an instance of the type. | ||
* @param {Object} instance The instance of the type on which operations should be performed. | ||
* @param {Object|Object[]} instance The instance of the type on which operations should be performed. | ||
* @param {String} [userClass="user"] The user class for which to check the readonly attribute. | ||
@@ -148,3 +148,3 @@ * @param {Boolean} [clone=false] Should the operation be performed on a copy of the instance instead? | ||
* Replaces concealed fields from an instance of the type. | ||
* @param {Object} instance The instance of the type on which operations should be performed. | ||
* @param {Object|Object[]} instance The instance of the type on which operations should be performed. | ||
* @param {String} [userClass="user"] The user class for which to check the concealed attribute. | ||
@@ -196,2 +196,57 @@ * @param {Boolean} [clone=false] Should the operation be performed on a copy of the instance instead? | ||
/** | ||
* Replaces complex type instances with their ID. | ||
* @param {Object|Object[]} instance The instance of the type on which operations should be performed. | ||
* @param {Boolean} [clone=false] Should the operation be performed on a copy of the instance instead? | ||
* @returns {*} The instance with the complex fields replaced. | ||
*/ | ||
TypeHelper.prototype.reduceComplex = function( instance, clone ) { | ||
if( null === instance ) { | ||
throw new Error( "Type instance cannot be null!" ); | ||
} | ||
var targetInstance = ( clone ) ? _.clone( instance ) : instance; | ||
// Handle arrays. | ||
if( Array.isArray( instance ) ) { | ||
var helper = this; | ||
var results = []; | ||
instance.forEach( function( element ) { | ||
results.push( helper.reduceComplex( element, clone ) ); | ||
} ); | ||
return results; | ||
} | ||
for( var propertyName in targetInstance ) { | ||
if( !this.typeInfo.isComplex( propertyName ) ) { | ||
reduceObject( targetInstance[ propertyName ] ); | ||
} | ||
} | ||
return targetInstance; | ||
function reduceObject( entity, depth ) { | ||
if( 10 < depth ) { | ||
log.error( "Entity nesting too deep! Complex reduction can not be completed." ); | ||
return null; | ||
} | ||
for( var propertyName in entity ) { | ||
if( !entity.hasOwnProperty( propertyName ) ) { | ||
continue; | ||
} | ||
if( Array.isArray( entity[ propertyName ] ) ) { | ||
entity[ propertyName ] = reduceObject( entity[ propertyName ], depth + 1 ); | ||
continue; | ||
} | ||
if( entity[ propertyName ] && entity[ propertyName ].id ) { | ||
entity[ propertyName ] = entity[ propertyName ].id; | ||
continue; | ||
} | ||
} | ||
return entity[ propertyName ]; | ||
} | ||
}; | ||
return TypeHelper; | ||
@@ -198,0 +253,0 @@ })(); |
@@ -0,0 +0,0 @@ "use strict"; |
{ | ||
"name": "absync", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "absync", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -0,1 +1,3 @@ | ||
![](doc/logo.png) | ||
absync is a highly opinionated framework to synchronize data pools in MEAN applications. | ||
@@ -2,0 +4,0 @@ |
Sorry, the diff of this file is not supported yet
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
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
313679
14
841
94
1