Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

roots-db

Package Overview
Dependencies
Maintainers
1
Versions
383
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

roots-db - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

test/to-be-re-implemented.js

69

lib/BatchWrapper.js

@@ -41,7 +41,68 @@ /*

*/
function BatchWrapper( collection , fingerprint , options )
function BatchWrapper( collection , rawBatch , options )
{
if ( ! ( collection instanceof rootsDb.Collection ) ) { throw new TypeError( '[roots-db] Argument #0 of rootsDb.BatchWrapper() should be an instance of rootsDb.Collection' ) ; }
if ( ! Array.isArray( rawBatch ) ) { rawBatch = [] ; }
if ( ! options || typeof options !== 'object' ) { options = {} ; }
// Already wrapped?
if ( rawBatch.$ instanceof BatchWrapper ) { return rawBatch.$ ; }
// Validation?
var wrapper = Object.create( BatchWrapper.prototype , {
batch: { value: rawBatch } ,
world: { value: collection.world } ,
collection: { value: collection } ,
//suspected: { writable: true, value: false } ,
// Useful here?
loaded: { value: options.fromUpstream ? true : false , writable: true , enumerable: true } ,
saved: { value: false , writable: true , enumerable: true } ,
deleted: { value: false , writable: true , enumerable: true } ,
upstreamExists: { value: options.fromUpstream ? true : false , writable: true , enumerable: true }
} ) ;
// Useful?
if ( options.fromUpstream )
{
wrapper.loaded = true ;
wrapper.upstreamExists = true ;
}
Object.defineProperty( rawBatch , '$' , { value: wrapper } ) ;
return wrapper ;
}
module.exports = BatchWrapper ;
function noop() {}
// Old batch methods...
function oldBatchWrapper( collection , fingerprint , options )
{
if ( ! ( collection instanceof rootsDb.Collection ) ) { throw new TypeError( '[roots-db] Argument #0 of rootsDb.BatchWrapper() should be an instance of rootsDb.Collection' ) ; }
if ( ! options || typeof options !== 'object' ) { options = {} ; }
var batch = Object.create( BatchWrapper.prototype , {

@@ -87,10 +148,4 @@ world: { value: collection.world } ,

module.exports = BatchWrapper ;
function noop() {}
/*

@@ -97,0 +152,0 @@ Should handle hooks, e.g. if the batch is related to a multilink, it should update the parent multilink property.

2

lib/bulk.js

@@ -54,3 +54,3 @@ /*

async.foreach( objectArray , function( object , foreachCallback ) {
if ( object.$ ) { object = object.$ }
if ( object.$ ) { object = object.$ ; }
object[ bulkMethod ].apply( object , bulkArgs.concat( foreachCallback ) ) ;

@@ -57,0 +57,0 @@ } )

@@ -435,3 +435,3 @@ /*

// Create fingerprint if needed
if ( ! ( fingerprint instanceof rootsDb.FingerprintWrapper ) ) { fingerprint = this.createFingerprint( fingerprint ) ; }
//if ( ! ( fingerprint instanceof rootsDb.FingerprintWrapper ) ) { fingerprint = this.createFingerprint( fingerprint ) ; }

@@ -444,4 +444,24 @@ // Sync mode: return a 'suspect' batch

if ( error ) { callback( error ) ; return ; }
if ( ! rawBatch ) { callback( ErrorStatus.notFound( { message: 'Batch not found' } ) ) ; return ; } // should never happen?
if ( ! rawBatch )
{
// should never happen?
callback( ErrorStatus.notFound( { message: 'Batch not found' } ) ) ;
return ;
}
if ( ! options.raw )
{
rootsDb.BatchWrapper( self , rawBatch , { fromUpstream: true , skipValidation: true } ) ;
}
callback( undefined , rawBatch ) ;
// How to deal with DocumentWrapper?
/*
var i , batch , length = rawBatch.length ;

@@ -463,2 +483,3 @@

callback( undefined , batch ) ;
*/
} ) ;

@@ -469,6 +490,50 @@ } ;

// Should check if those features are still working...
// Get a set of document
Collection.prototype.find = function collectionFind( queryObject , options , callback )
{
var self = this ;
// Managing function's arguments
if ( ! queryObject || typeof queryObject !== 'object' ) { throw new Error( "[odm] queryObject should be an object" ) ; }
if ( arguments.length === 2 && typeof options === 'function' ) { callback = options ; options = {} ; }
if ( ! options || typeof options !== 'object' ) { options = {} ; }
if ( typeof callback !== 'function' ) { throw new Error( "[odm] missing callback" ) ; }
this.driver.find( queryObject , function( error , rawBatch ) {
if ( error ) { callback( error ) ; return ; }
if ( ! rawBatch )
{
// should never happen?
callback( ErrorStatus.notFound( { message: 'Batch not found' } ) ) ;
return ;
}
if ( ! options.raw )
{
rootsDb.BatchWrapper( self , rawBatch , { fromUpstream: true , skipValidation: true } ) ;
}
callback( undefined , rawBatch ) ;
// How to deal with DocumentWrapper?
} ) ;
} ;
// Should re-implement those features later...
Collection.prototype.addMetaLink = function collectionAddMetaLink( key , property , collectionName )

@@ -475,0 +540,0 @@ {

@@ -47,3 +47,2 @@ /*

// First, validate the document

@@ -64,3 +63,2 @@ if ( ! options.skipValidation )

var wrapper = Object.create( DocumentWrapper.prototype , {

@@ -81,3 +79,2 @@ document: { value: rawDocument , enumerable: true , writable: true } ,

if ( options.fromUpstream )

@@ -89,61 +86,9 @@ {

Object.defineProperty( rawDocument , '$' , { value: wrapper } ) ;
return wrapper ;
// Should probably have its instance type of its own
/*
// Suspect is set when the object is in a state where it may exist upstream but should be loaded first
if ( options.suspected )
{
wrapper.suspected = true ;
wrapper.upstream = deepInherit( null , collection.suspectedBase ) ;
wrapper.$ = deepInherit( null , wrapper.upstream ) ;
wrapper.id = null ;
wrapper.fingerprint = null ;
wrapper.witness = null ;
Object.defineProperty( wrapper.$ , '' , { value: wrapper } ) ; // link to the parent
if ( options.fingerprint && typeof options.fingerprint === 'object' )
{
var fingerprint ;
// Check if we have a unique fingerprint
if ( options.fingerprint instanceof rootsDb.FingerprintWrapper ) { fingerprint = options.fingerprint ; }
else { fingerprint = this.createFingerprint( options.fingerprint ) ; }
if ( fingerprint.unique )
{
tree.extend( { own: true } , wrapper.upstream , fingerprint.partialDocument ) ;
//console.log( '<<<<<<<<<< wrapper.upstream:' , wrapper.upstream ) ;
wrapper.fingerprint = fingerprint ;
}
}
if ( options.witness && typeof options.witness === 'object' && Object.keys( options.witness ).length )
{
wrapper.witness = options.witness ;
}
if ( options.id )
{
if ( typeof options.id !== 'string' && ! options.id.toString ) { throw new Error( '[roots-db] provided id cannot be converted to a string' ) ; }
Object.defineProperty( wrapper , 'id' , { value: collection.driver.createId( wrapper.$ , options.id ) , enumerable: true } ) ;
}
if ( ! wrapper.id && ! wrapper.fingerprint && ! wrapper.witness )
{
throw new Error( '[roots-db] cannot instanciate a suspect without id, fingerprint or witness' ) ;
}
return wrapper ;
}
*/
}
DocumentWrapper.prototype.constructor = DocumentWrapper ;
module.exports = DocumentWrapper ;

@@ -157,28 +102,2 @@

// Useful?
// Return a one-value state
DocumentWrapper.prototype.state = function documentState()
{
if ( this.deleted ) { return 'deleted' ; }
if ( this.suspected )
{
if ( this.upstreamExists ) { return 'existing-suspect' ; }
return 'suspected' ;
}
if ( this.upstreamExists )
{
if ( ( this.saved || this.loaded ) && Object.keys( this.$ ).length === 0 ) { return 'synced' ; }
return 'exists' ;
}
return 'app-side' ;
} ;
// callback( error )

@@ -335,6 +254,66 @@ DocumentWrapper.prototype.save = function documentSave( options , callback )

/* Old 'Suspect' document... */
// Should probably have its instance type of its own
function oldDocumentWrapper( collection , rawDocument , options )
{
// [...]
var wrapper , deepInherit ;
// Suspect is set when the object is in a state where it may exist upstream but should be loaded first
if ( options.suspected )
{
wrapper.suspected = true ;
wrapper.upstream = deepInherit( null , collection.suspectedBase ) ;
wrapper.$ = deepInherit( null , wrapper.upstream ) ;
wrapper.id = null ;
wrapper.fingerprint = null ;
wrapper.witness = null ;
Object.defineProperty( wrapper.$ , '' , { value: wrapper } ) ; // link to the parent
if ( options.fingerprint && typeof options.fingerprint === 'object' )
{
var fingerprint ;
// Check if we have a unique fingerprint
if ( options.fingerprint instanceof rootsDb.FingerprintWrapper ) { fingerprint = options.fingerprint ; }
else { fingerprint = this.createFingerprint( options.fingerprint ) ; }
if ( fingerprint.unique )
{
tree.extend( { own: true } , wrapper.upstream , fingerprint.partialDocument ) ;
//console.log( '<<<<<<<<<< wrapper.upstream:' , wrapper.upstream ) ;
wrapper.fingerprint = fingerprint ;
}
}
if ( options.witness && typeof options.witness === 'object' && Object.keys( options.witness ).length )
{
wrapper.witness = options.witness ;
}
if ( options.id )
{
if ( typeof options.id !== 'string' && ! options.id.toString ) { throw new Error( '[roots-db] provided id cannot be converted to a string' ) ; }
Object.defineProperty( wrapper , 'id' , { value: collection.driver.createId( wrapper.$ , options.id ) , enumerable: true } ) ;
}
if ( ! wrapper.id && ! wrapper.fingerprint && ! wrapper.witness )
{
throw new Error( '[roots-db] cannot instanciate a suspect without id, fingerprint or witness' ) ;
}
return wrapper ;
}
}
// Reveal a suspected Document

@@ -471,1 +450,29 @@ DocumentWrapper.prototype.reveal = function documentReveal( options , callback )

} ;
// Useful?
// Return a one-value state
DocumentWrapper.prototype.state = function documentState()
{
if ( this.deleted ) { return 'deleted' ; }
if ( this.suspected )
{
if ( this.upstreamExists ) { return 'existing-suspect' ; }
return 'suspected' ;
}
if ( this.upstreamExists )
{
if ( ( this.saved || this.loaded ) && Object.keys( this.$ ).length === 0 ) { return 'synced' ; }
return 'exists' ;
}
return 'app-side' ;
} ;

@@ -295,3 +295,3 @@ /*

if ( ! ( id instanceof mongodb.ObjectID ) ) { id = mongodb.ObjectID( id ) ; }
if ( typeof id === 'string' ) { id = mongodb.ObjectID( id ) ; }
this.mongoCollection.findOne( { _id : id } , callback ) ;

@@ -308,2 +308,3 @@ } ;

if ( typeof fingerprint._id === 'string' ) { fingerprint._id = mongodb.ObjectID( fingerprint._id ) ; }
this.mongoCollection.findOne( fingerprint , callback ) ;

@@ -320,2 +321,3 @@ } ;

if ( typeof rawDocument._id === 'string' ) { rawDocument._id = mongodb.ObjectID( rawDocument._id ) ; }
this.mongoCollection.insert( rawDocument , callback ) ;

@@ -332,2 +334,4 @@ } ;

if ( typeof rawDocument._id === 'string' ) { rawDocument._id = mongodb.ObjectID( rawDocument._id ) ; }
// save(): Shorthand for insert/update is save - if _id value set, the record is updated if it exists or inserted

@@ -346,2 +350,3 @@ // if it does not; if the _id value is not set, then the record is inserted as a new one.

if ( typeof id === 'string' ) { id = mongodb.ObjectID( id ) ; }
this.mongoCollection.update( { _id : id } , rawDocument , callback ) ;

@@ -358,2 +363,4 @@ } ;

if ( typeof id === 'string' ) { id = mongodb.ObjectID( id ) ; }
if ( typeof rawDocument._id === 'string' ) { rawDocument._id = mongodb.ObjectID( rawDocument._id ) ; }
this.mongoCollection.update( { _id : id } , { $set: rawDocument } , callback ) ;

@@ -370,2 +377,3 @@ } ;

if ( typeof id === 'string' ) { id = mongodb.ObjectID( id ) ; }
this.mongoCollection.remove( { _id: id } , { justOne: true } , callback ) ;

@@ -383,2 +391,3 @@ } ;

//console.log( 'driver collect fingerprint' , fingerprint ) ;
if ( typeof fingerprint._id === 'string' ) { fingerprint._id = mongodb.ObjectID( fingerprint._id ) ; }
this.mongoCollection.find( fingerprint ).toArray( callback ) ;

@@ -389,4 +398,20 @@ } ;

// Get a batch of documents given a query object
Mongodb.prototype.find = function find( queryObject , callback )
{
// If not ready, try to connect
if ( ! this.ready ) { return this.connect( Mongodb.prototype.find.bind( this , queryObject , callback ) , callback ) ; }
// In others driver, the queryObject should be processed to construct a complex query.
// But since roots-DB queries ARE MongoDB object's queries, there is nothing to do here.
//console.log( 'driver find queryObject' , queryObject ) ;
if ( typeof queryObject._id === 'string' ) { queryObject._id = mongodb.ObjectID( queryObject._id ) ; }
this.mongoCollection.find( queryObject ).toArray( callback ) ;
} ;
/* Polyfills & mongo shell consistencies */

@@ -393,0 +418,0 @@

{
"name": "roots-db",
"version": "0.0.3",
"version": "0.0.4",
"description": "Even more minimalistic ODM",

@@ -5,0 +5,0 @@ "main": "lib/rootsDb.js",

@@ -117,3 +117,3 @@ /*

meta: {
type: 'object',
type: 'strictObject',
default: {}

@@ -137,7 +137,2 @@ }

// it flatten prototype chain, so a single object owns every property of its parents
var protoflatten = tree.extend.bind( undefined , { deep: true , deepFilter: { blacklist: [ mongodb.ObjectID.prototype ] } } , null ) ;
// clear DB: remove every item, so we can safely test

@@ -766,3 +761,3 @@ function clearDB( callback )

describe( "Collect batchs" , function() {
describe( "Collect & find batchs" , function() {

@@ -809,7 +804,8 @@ beforeEach( clearDB ) ;

function( callback ) {
users.collect( { lastName: 'Marley' } , { raw: true } , function( error , batch ) {
users.collect( { lastName: 'Marley' } , function( error , batch ) {
var i , map = {} ;
//console.log( 'Error:' , error ) ;
//console.log( 'RawBatch:' , batch ) ;
//console.log( 'Batch:' , batch ) ;
expect( error ).not.to.be.ok() ;
expect( batch.$ ).to.be.a( rootsDb.BatchWrapper ) ;
expect( batch ).to.have.length( 5 ) ;

@@ -819,2 +815,3 @@

{
//expect( batch[ i ] ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( batch[ i ].firstName ).to.be.ok() ;

@@ -828,74 +825,2 @@ expect( batch[ i ].lastName ).to.equal( 'Marley' ) ;

} ) ;
} ,/*
function( callback ) {
users.collect( { lastName: 'Marley' } , function( error , batch ) {
var i , map = {} ;
//console.log( 'Error:' , error ) ;
//console.log( 'Batch:' , batch ) ;
expect( error ).not.to.be.ok() ;
expect( batch ).to.be.an( rootsDb.BatchWrapper ) ;
expect( batch.documents ).to.have.length( 5 ) ;
for ( i = 0 ; i < batch.documents.length ; i ++ )
{
expect( batch.documents[ i ] ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( batch.documents[ i ].firstName ).to.ok() ;
expect( batch.documents[ i ].lastName ).to.equal( 'Marley' ) ;
map[ batch.documents[ i ].firstName ] = true ;
}
expect( map ).to.only.have.keys( 'Bob' , 'Julian' , 'Stephen' , 'Ziggy' , 'Rita' ) ;
callback() ;
} ) ;
}*/
] )
.exec( done ) ;
} ) ;
} ) ;
describe( "Suspects and revealing" , function() {
it( "Synchronous 'get()' should provide an 'identified' suspect, and reveal it later" , function( done ) {
var user = users.createDocument( {
firstName: 'Dilbert' ,
lastName: 'Dugommier'
} ) ;
var id = user._id ;
expect( user.state() ).to.equal( 'app-side' ) ;
async.series( [
function( callback ) {
user.$.save( callback ) ;
} ,
function( callback ) {
var user = users.get( id ) ;
expect( user ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( user.suspected ).to.be.ok() ;
expect( user.loaded ).not.to.be.ok() ;
expect( user.upstreamExists ).not.to.be.ok() ;
expect( user.state() ).to.equal( 'suspected' ) ;
expect( user._id ).to.be.an( mongodb.ObjectID ) ;
expect( user._id ).to.eql( id ) ;
expect( tree.extend( null , {} , user.$ ) ).to.eql( { _id: id, firstName: undefined, lastName: undefined, jobId: undefined, godfatherId: undefined , memberSid: undefined } ) ;
user.reveal( function( error ) {
expect( user ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( user.suspected ).not.to.be.ok() ;
expect( user.loaded ).to.be.ok() ;
expect( user.upstreamExists ).to.be.ok() ;
//delete user._id ;
//console.log( '----------------------' , Object.keys( user.$ ) ) ;
expect( Object.keys( user.$ ).length ).to.equal( 0 ) ;
expect( user.state() ).to.equal( 'synced' ) ;
expect( user._id ).to.be.an( mongodb.ObjectID ) ;
expect( user._id ).to.eql( id ) ;
expect( tree.extend( null , {} , user.$ ) ).to.eql( { _id: id, firstName: 'Dilbert', lastName: 'Dugommier', jobId: undefined, godfatherId: undefined , memberSid: 'Dilbert Dugommier' } ) ;
callback() ;
} ) ;
}

@@ -906,375 +831,33 @@ ] )

it( "Synchronous 'get()' should provide a suspect with a bad identity, then reveal it as nothing" , function( done ) {
it( "should find documents (in a batch) using a queryObject (create, save and find)" , function( done ) {
var id = new mongodb.ObjectID() ;
var user = users.get( id ) ;
expect( user ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( user.suspected ).to.be.ok() ;
expect( user._id ).to.be.an( mongodb.ObjectID ) ;
expect( user._id ).to.eql( id ) ;
expect( user.loaded ).not.to.be.ok() ;
expect( user.upstreamExists ).not.to.be.ok() ;
expect( user.deleted ).not.to.be.ok() ;
expect( tree.extend( null , {} , user.$ ) ).to.eql( { _id: id, firstName: undefined, lastName: undefined, jobId: undefined, godfatherId: undefined , memberSid: undefined } ) ;
user.reveal( function( error ) {
expect( user ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( user.suspected ).not.to.be.ok() ;
expect( user._id ).to.be.an( mongodb.ObjectID ) ;
expect( user._id ).to.eql( id ) ;
expect( user.loaded ).not.to.be.ok() ;
expect( user.upstreamExists ).not.to.be.ok() ;
expect( user.deleted ).to.be.ok() ;
expect( tree.extend( null , {} , user.$ ) ).to.eql( { _id: id, firstName: undefined, lastName: undefined, jobId: undefined, godfatherId: undefined , memberSid: undefined } ) ;
done() ;
} ) ;
} ) ;
it( "Synchronous 'getUnique()' should provide an 'identified' suspect, and reveal it later" , function( done ) {
var user = users.createDocument( {
firstName: 'Joe' ,
lastName: 'Pink'
} ) ;
var id = user._id ;
var memberSid = user.$.memberSid ;
var job = jobs.createDocument() ;
var jobId = job.id ;
user.$.job = job ;
expect( user.state() ).to.equal( 'app-side' ) ;
async.series( [
function( callback ) {
user.$.save( callback ) ;
} ,
function( callback ) {
job.$.save( callback ) ;
} ,
function( callback ) {
var user = users.getUnique( { memberSid: memberSid , jobId: jobId } ) ;
expect( user ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( user.suspected ).to.be.ok() ;
expect( user.loaded ).not.to.be.ok() ;
expect( user.upstreamExists ).not.to.be.ok() ;
expect( user.state() ).to.equal( 'suspected' ) ;
expect( user._id ).to.be( undefined ) ;
expect( tree.extend( null , {} , user.$ ) ).to.eql( { firstName: undefined, lastName: undefined, jobId: jobId, godfatherId: undefined, memberSid: "Joe Pink" } ) ;
user.reveal( function( error ) {
expect( user ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( user.suspected ).not.to.be.ok() ;
expect( user.loaded ).to.be.ok() ;
expect( user.upstreamExists ).to.be.ok() ;
//delete user._id ;
//console.log( '----------------------' , Object.keys( user.$ ) ) ;
expect( Object.keys( user.$ ).length ).to.equal( 0 ) ;
expect( user.state() ).to.equal( 'synced' ) ;
expect( user._id ).to.be.an( mongodb.ObjectID ) ;
expect( user._id ).to.eql( id ) ;
expect( tree.extend( null , {} , user.$ ) ).to.eql( { _id: id, firstName: 'Joe', lastName: 'Pink', jobId: jobId, godfatherId: undefined , memberSid: 'Joe Pink' } ) ;
callback() ;
} ) ;
}
] )
.exec( done ) ;
} ) ;
it( "Save a suspect" ) ;
it( "Update a suspect" ) ;
it( "Delete a suspect" ) ;
} ) ;
describe( "Links" , function() {
it( "should retrieve a 'suspected' document from a document's link (create both, link, save both, retrieve parent, navigate to child, reveal child)" , function( done ) {
var user = users.createDocument( {
firstName: 'Jilbert' ,
lastName: 'Polson'
} ) ;
var id = user._id ;
var job = jobs.createDocument() ;
//console.log( job ) ;
var jobId = job.id ;
// Link the documents!
user.$.job = job ;
//user.$.jobId = jobId ;
expect( user.$.jobId ).to.eql( jobId ) ;
// Problème... stocker les liens dans les meta...
expect( tree.extend( null , {} , user.$.job.$ ) ).to.eql( tree.extend( null , {} , job.$ ) ) ;
expect( user.$.job.suspected ).not.to.be.ok() ;
//console.log( '>>>' , jobId ) ;
async.series( [
function( callback ) {
job.$.save( callback ) ;
} ,
function( callback ) {
user.$.save( callback ) ;
} ,
function( callback ) {
jobs.get( jobId , function( error , job ) {
//console.log( 'Error:' , error ) ;
//console.log( 'Job:' , job ) ;
expect( error ).not.to.be.ok() ;
expect( job ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( job._id ).to.be.an( mongodb.ObjectID ) ;
expect( job._id ).to.eql( jobId ) ;
expect( tree.extend( null , {} , job.$ ) ).to.eql( { _id: job._id , title: 'unemployed' , salary: 0 } ) ;
callback() ;
} ) ;
} ,
function( callback ) {
users.get( id , function( error , user ) {
//console.log( 'Error:' , error ) ;
//console.log( 'User:' , user ) ;
expect( error ).not.to.be.ok() ;
expect( user ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( user._id ).to.be.an( mongodb.ObjectID ) ;
expect( user._id ).to.eql( id ) ;
expect( user.$.jobId ).to.be.an( mongodb.ObjectID ) ;
expect( user.$.jobId ).to.eql( jobId ) ;
expect( tree.extend( null , {} , user.$ ) ).to.eql( { _id: user._id, jobId: user.$.jobId, godfatherId: undefined, firstName: 'Jilbert', lastName: 'Polson' , memberSid: 'Jilbert Polson' } ) ;
//user.$.toto = 'toto' ;
var job = user.$.job ;
expect( job ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( job.suspected ).to.be.ok() ;
expect( job._id ).to.be.an( mongodb.ObjectID ) ;
expect( job._id ).to.eql( jobId ) ;
expect( tree.extend( null , {} , job.$ ) ).to.eql( { _id: job._id , title: undefined , salary: undefined } ) ;
job.reveal( function( error ) {
// Not suspected anymore
expect( job.suspected ).not.to.be.ok() ;
expect( tree.extend( null , {} , job.$ ) ).to.eql( { _id: job._id , title: 'unemployed' , salary: 0 } ) ;
callback() ;
} ) ;
} ) ;
}
] )
.exec( done ) ;
} ) ;
it( "should retrieve a 'suspected' document from a 'suspected' document's link (suspected²: create both, link, save both, retrieve parent as suspect, navigate to child, reveal child)" , function( done ) {
var user = users.createDocument( {
firstName: 'Wilson' ,
lastName: 'Andrews'
} ) ;
var id = user._id ;
var job = jobs.createDocument() ;
var jobId = job.id ;
job.$.title = 'mechanic' ;
job.$.salary = 2100 ;
//console.log( job ) ;
// Link the documents!
user.$.job = job ;
//user.$.jobId = jobId ;
expect( user.$.jobId ).to.eql( jobId ) ;
expect( user.$.job ).to.equal( job ) ;
expect( user.$.job.suspected ).not.to.be.ok() ;
//console.log( '>>>' , jobId ) ;
async.series( [
function( callback ) {
job.$.save( callback ) ;
} ,
function( callback ) {
user.$.save( callback ) ;
} ,
function( callback ) {
jobs.get( jobId , function( error , job ) {
//console.log( 'Error:' , error ) ;
//console.log( 'Job:' , job ) ;
expect( error ).not.to.be.ok() ;
expect( job ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( job._id ).to.be.an( mongodb.ObjectID ) ;
expect( job._id ).to.eql( jobId ) ;
expect( tree.extend( null , {} , job.$ ) ).to.eql( { _id: job._id , title: 'mechanic' , salary: 2100 } ) ;
callback() ;
} ) ;
} ,
function( callback ) {
// The real test begins NOW!
var user = users.get( id ) ;
expect( user ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( user.suspected ).to.be.ok() ;
expect( user._id ).to.be.an( mongodb.ObjectID ) ;
expect( user._id ).to.eql( id ) ;
expect( tree.extend( null , {} , user.$ ) ).to.eql( { _id: id, firstName: undefined, lastName: undefined, jobId: undefined, godfatherId: undefined , memberSid: undefined } ) ;
var job = user.$.job ;
expect( job ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( job.suspected ).to.be.ok() ;
//expect( job._id ).to.be.an( mongodb.ObjectID ) ;
//expect( job._id ).to.eql( jobId ) ;
expect( job.witness.document ).to.equal( user ) ;
expect( job.witness.property ).to.equal( 'jobId' ) ;
expect( job.witness.type ).to.equal( 'link' ) ;
expect( tree.extend( null , {} , job.$ ) ).to.eql( { title: undefined , salary: undefined } ) ;
job.reveal( function( error ) {
// Not a suspected anymore
expect( job.suspected ).not.to.be.ok() ;
expect( job._id ).to.be.an( mongodb.ObjectID ) ;
expect( job._id ).to.eql( jobId ) ;
expect( tree.extend( null , {} , job.$ ) ).to.eql( { _id: job._id , title: 'mechanic' , salary: 2100 } ) ;
// user should be revealed
expect( user.suspected ).not.to.be.ok() ;
expect( user._id ).to.be.an( mongodb.ObjectID ) ;
expect( user._id ).to.eql( id ) ;
expect( user.$.jobId ).to.be.an( mongodb.ObjectID ) ;
expect( user.$.jobId ).to.eql( jobId ) ;
expect( tree.extend( null , {} , user.$ ) ).to.eql( { _id: user._id, jobId: user.$.jobId, godfatherId: undefined, firstName: 'Wilson', lastName: 'Andrews' , memberSid: 'Wilson Andrews' } ) ;
callback() ;
} ) ;
}
] )
.exec( done ) ;
} ) ;
it( "should retrieve a 'suspected' document from a 'suspected' document's link² (suspected³: create x3, link x2, save x3, retrieve grand-parent as suspect, navigate to parent, navigate to child, reveal child)" , function( done ) {
var user = users.createDocument( {
firstName: 'Paul' ,
lastName: 'Williams'
} ) ;
var id = user._id ;
var godfather = users.createDocument( {
firstName: 'Maxwell' ,
lastName: 'Jersey'
} ) ;
var godfatherId = godfather._id ;
var job = jobs.createDocument() ;
var jobId = job.id ;
job.$.title = 'plumber' ;
job.$.salary = 1900 ;
// Link the documents!
user.$.godfather = godfather ;
godfather.$.job = job ;
expect( user.$.godfatherId ).to.eql( godfatherId ) ;
expect( user.$.godfather ).to.equal( godfather ) ;
expect( user.$.godfather.suspected ).not.to.be.ok() ;
expect( godfather.$.jobId ).to.eql( jobId ) ;
expect( godfather.$.job ).to.equal( job ) ;
expect( godfather.$.job.suspected ).not.to.be.ok() ;
//console.log( '>>>' , jobId ) ;
async.series( [
function( callback ) {
job.$.save( callback ) ;
} ,
function( callback ) {
godfather.$.save( callback ) ;
} ,
function( callback ) {
user.$.save( callback ) ;
} ,
function( callback ) {
// The real test begins NOW!
var user = users.get( id ) ;
expect( user ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( user.suspected ).to.be.ok() ;
expect( user._id ).to.be.an( mongodb.ObjectID ) ;
expect( user._id ).to.eql( id ) ;
expect( tree.extend( null , {} , user.$ ) ).to.eql( { _id: id, firstName: undefined, lastName: undefined, jobId: undefined, godfatherId: undefined , memberSid: undefined } ) ;
var godfather = user.$.godfather ;
expect( godfather ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( godfather.suspected ).to.be.ok() ;
//expect( godfather._id ).to.be.an( mongodb.ObjectID ) ;
//expect( godfather._id ).to.eql( id ) ;
expect( godfather.witness.document ).to.equal( user ) ;
expect( godfather.witness.property ).to.equal( 'godfatherId' ) ;
expect( godfather.witness.type ).to.equal( 'link' ) ;
expect( tree.extend( null , {} , godfather.$ ) ).to.eql( { firstName: undefined, lastName: undefined, jobId: undefined, godfatherId: undefined , memberSid: undefined } ) ;
var job = godfather.$.job ;
expect( job ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( job.suspected ).to.be.ok() ;
//expect( job._id ).to.be.an( mongodb.ObjectID ) ;
//expect( job._id ).to.eql( jobId ) ;
expect( job.witness.document ).to.equal( godfather ) ;
expect( job.witness.property ).to.equal( 'jobId' ) ;
expect( job.witness.type ).to.equal( 'link' ) ;
expect( tree.extend( null , {} , job.$ ) ).to.eql( { title: undefined , salary: undefined } ) ;
job.reveal( function( error ) {
// Not a suspected anymore
expect( job.suspected ).not.to.be.ok() ;
expect( job._id ).to.be.an( mongodb.ObjectID ) ;
expect( job._id ).to.eql( jobId ) ;
expect( tree.extend( null , {} , job.$ ) ).to.eql( { _id: job._id , title: 'plumber' , salary: 1900 } ) ;
// godfather should be revealed
expect( godfather._id ).to.be.an( mongodb.ObjectID ) ;
expect( godfather._id ).to.eql( godfatherId ) ;
expect( godfather.$.jobId ).to.be.an( mongodb.ObjectID ) ;
expect( godfather.$.jobId ).to.eql( jobId ) ;
expect( tree.extend( null , {} , godfather.$ ) ).to.eql( { _id: godfather._id, jobId: godfather.$.jobId, godfatherId: undefined, firstName: 'Maxwell', lastName: 'Jersey' , memberSid: 'Maxwell Jersey' } ) ;
// user should be revealed
expect( user._id ).to.be.an( mongodb.ObjectID ) ;
expect( user._id ).to.eql( id ) ;
expect( user.$.godfatherId ).to.be.an( mongodb.ObjectID ) ;
expect( user.$.godfatherId ).to.eql( godfatherId ) ;
expect( tree.extend( null , {} , user.$ ) ).to.eql( { _id: user._id, jobId: user.$.jobId, godfatherId: godfatherId, firstName: 'Paul', lastName: 'Williams' , memberSid: 'Paul Williams' } ) ;
callback() ;
} ) ;
}
] )
.exec( done ) ;
} ) ;
} ) ;
describe( "Backlinks" , function() {
beforeEach( clearDB ) ;
it( "should retrieve a batch of 'suspected' document from a document's backlink (create, assign backlink ID, save, get parent, get backlink suspect batch containing childs, reveal batch)" , function( done ) {
var job = jobs.createDocument( { title: 'bowler' } ) ;
var jobId = job.id ;
var friends = [
users.createDocument( { firstName: 'Jeffrey' , lastName: 'Lebowski' , jobId: jobId } ) ,
users.createDocument( { firstName: 'Walter' , lastName: 'Sobchak' , jobId: jobId } ) ,
users.createDocument( { firstName: 'Donny' , lastName: 'Kerabatsos' , jobId: jobId } )
var marleys = [
users.createDocument( {
firstName: 'Bob' ,
lastName: 'Marley'
} ) ,
users.createDocument( {
firstName: 'Julian' ,
lastName: 'Marley'
} ) ,
users.createDocument( {
firstName: 'Thomas' ,
lastName: 'Jefferson'
} ) ,
users.createDocument( {
firstName: 'Stephen' ,
lastName: 'Marley'
} ) ,
users.createDocument( {
firstName: 'Mr' ,
lastName: 'X'
} ) ,
users.createDocument( {
firstName: 'Ziggy' ,
lastName: 'Marley'
} ) ,
users.createDocument( {
firstName: 'Rita' ,
lastName: 'Marley'
} )
] ;

@@ -1284,100 +867,21 @@

function( callback ) {
rootsDb.bulk( 'save' , friends.concat( job ) , callback ) ;
rootsDb.bulk( 'save' , marleys , callback ) ;
} ,
function( callback ) {
jobs.get( jobId , function( error , job ) {
users.find( { firstName: { $regex: /^[thomasstepn]+$/ , $options: 'i' } } , function( error , batch ) {
var i , map = {} ;
//console.log( 'Error:' , error ) ;
//console.log( 'Job:' , job ) ;
//console.log( 'Batch:' , batch ) ;
expect( error ).not.to.be.ok() ;
expect( job ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( job._id ).to.be.an( mongodb.ObjectID ) ;
expect( job._id ).to.eql( jobId ) ;
expect( tree.extend( null , {} , job.$ ) ).to.eql( { _id: job._id , title: 'bowler' , salary: 0 } ) ;
expect( batch.$ ).to.be.a( rootsDb.BatchWrapper ) ;
expect( batch ).to.have.length( 2 ) ;
var userBatch = job.$.members ;
expect( userBatch ).to.be.an( rootsDb.BatchWrapper ) ;
expect( userBatch.suspected ).to.be.ok() ;
userBatch.reveal( function( error , batch ) {
expect( error ).not.to.be.ok() ;
expect( batch ).to.be( userBatch ) ;
expect( userBatch.suspected ).not.to.be.ok() ;
expect( userBatch.documents ).to.be.an( Array ) ;
expect( userBatch.documents.length ).to.be( 3 ) ;
var i , mapFirstName = {} , mapLastName = {} ;
for ( i = 0 ; i < userBatch.documents.length ; i ++ )
{
expect( userBatch.documents[ i ].firstName ).to.be.ok() ;
expect( userBatch.documents[ i ].lastName ).to.be.ok() ;
mapFirstName[ userBatch.documents[ i ].firstName ] = true ;
mapLastName[ userBatch.documents[ i ].lastName ] = true ;
}
expect( mapFirstName ).to.only.have.keys( 'Jeffrey' , 'Walter' , 'Donny' ) ;
expect( mapLastName ).to.only.have.keys( 'Lebowski' , 'Sobchak' , 'Kerabatsos' ) ;
callback() ;
} ) ;
} ) ;
}
] )
.exec( done ) ;
} ) ;
it( "should retrieve a batch of 'suspected' document from a 'suspected' document's backlink (suspect²: create, assign backlink ID, save, get parent, get backlink suspect batch containing childs, reveal batch)" , function( done ) {
var job = jobs.createDocument( { title: 'bowler' } ) ;
var jobId = job.id ;
var friends = [
users.createDocument( { firstName: 'Jeffrey' , lastName: 'Lebowski' , jobId: jobId } ) ,
users.createDocument( { firstName: 'Walter' , lastName: 'Sobchak' , jobId: jobId } ) ,
users.createDocument( { firstName: 'Donny' , lastName: 'Kerabatsos' , jobId: jobId } )
] ;
async.series( [
function( callback ) {
rootsDb.bulk( 'save' , friends.concat( job ) , callback ) ;
} ,
function( callback ) {
job = jobs.get( jobId ) ;
expect( job ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( job.id ).to.be.an( mongodb.ObjectID ) ;
expect( job.id ).to.eql( jobId ) ;
expect( job._id ).to.be.an( mongodb.ObjectID ) ;
expect( job._id ).to.eql( jobId ) ;
expect( job.suspected ).to.be.ok() ;
var userBatch = job.$.members ;
expect( userBatch ).to.be.an( rootsDb.BatchWrapper ) ;
expect( userBatch.suspected ).to.be.ok() ;
expect( userBatch.witness ).not.to.be.ok( job ) ;
userBatch.reveal( function( error , batch ) {
expect( error ).not.to.be.ok() ;
expect( job.suspected ).to.be.ok() ; // Should not be loaded
expect( tree.extend( null , {} , job.$ ) ).to.eql( { _id: job._id , title: undefined , salary: undefined } ) ;
expect( batch ).to.be( userBatch ) ;
expect( userBatch.suspected ).not.to.be.ok() ;
expect( userBatch.documents ).to.be.an( Array ) ;
expect( userBatch.documents.length ).to.be( 3 ) ;
var i , mapFirstName = {} , mapLastName = {} ;
for ( i = 0 ; i < userBatch.documents.length ; i ++ )
for ( i = 0 ; i < batch.length ; i ++ )
{
expect( userBatch.documents[ i ].firstName ).to.be.ok() ;
expect( userBatch.documents[ i ].lastName ).to.be.ok() ;
mapFirstName[ userBatch.documents[ i ].firstName ] = true ;
mapLastName[ userBatch.documents[ i ].lastName ] = true ;
//expect( batch[ i ] ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( batch[ i ].firstName ).to.be.ok() ;
map[ batch[ i ].firstName ] = true ;
}
expect( mapFirstName ).to.only.have.keys( 'Jeffrey' , 'Walter' , 'Donny' ) ;
expect( mapLastName ).to.only.have.keys( 'Lebowski' , 'Sobchak' , 'Kerabatsos' ) ;
expect( map ).to.only.have.keys( 'Thomas' , 'Stephen' ) ;
callback() ;

@@ -1390,74 +894,2 @@ } ) ;

it( "should retrieve a batch of 'suspected' document from a 'suspected' document's backlink (suspect³: create, assign backlink ID, save, get parent, get backlink suspect batch containing childs, reveal batch)" , function( done ) {
var job = jobs.createDocument( { title: 'bowler' } ) ;
var jobId = job.id ;
var friends = [
users.createDocument( { firstName: 'Jeffrey' , lastName: 'Lebowski' , jobId: jobId } ) ,
users.createDocument( { firstName: 'Walter' , lastName: 'Sobchak' , jobId: jobId } ) ,
users.createDocument( { firstName: 'Donny' , lastName: 'Kerabatsos' , jobId: jobId } )
] ;
var dudeId = friends[ 0 ].id ;
async.series( [
function( callback ) {
rootsDb.bulk( 'save' , friends.concat( job ) , callback ) ;
} ,
function( callback ) {
var dude = users.get( dudeId ) ;
expect( dude ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( dude.suspected ).to.be.ok() ;
expect( dude._id ).to.be.an( mongodb.ObjectID ) ;
expect( dude._id ).to.eql( dudeId ) ;
expect( tree.extend( null , {} , dude.$ ) ).to.eql( { _id: dudeId, firstName: undefined, lastName: undefined, jobId: undefined, godfatherId: undefined , memberSid: undefined } ) ;
var job = dude.$.job ;
expect( job ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( job.suspected ).to.be.ok() ;
expect( job.witness.document ).to.equal( dude ) ;
expect( job.witness.property ).to.equal( 'jobId' ) ;
expect( job.witness.type ).to.equal( 'link' ) ;
expect( tree.extend( null , {} , job.$ ) ).to.eql( { title: undefined , salary: undefined } ) ;
var userBatch = job.$.members ;
expect( userBatch ).to.be.an( rootsDb.BatchWrapper ) ;
expect( userBatch.suspected ).to.be.ok() ;
expect( userBatch.witness.document ).to.equal( job ) ;
expect( userBatch.witness.property ).to.equal( 'jobId' ) ;
expect( userBatch.witness.type ).to.equal( 'backlink' ) ;
userBatch.reveal( function( error , batch ) {
expect( error ).not.to.be.ok() ;
expect( job.suspected ).to.be.ok() ; // Should not be loaded
expect( tree.extend( null , {} , job.$ ) ).to.eql( { title: undefined , salary: undefined } ) ;
expect( batch ).to.be( userBatch ) ;
expect( userBatch.suspected ).not.to.be.ok() ;
expect( userBatch.documents ).to.be.an( Array ) ;
expect( userBatch.documents.length ).to.be( 3 ) ;
var i , mapFirstName = {} , mapLastName = {} ;
for ( i = 0 ; i < userBatch.documents.length ; i ++ )
{
expect( userBatch.documents[ i ].firstName ).to.be.ok() ;
expect( userBatch.documents[ i ].lastName ).to.be.ok() ;
mapFirstName[ userBatch.documents[ i ].firstName ] = true ;
mapLastName[ userBatch.documents[ i ].lastName ] = true ;
}
expect( mapFirstName ).to.only.have.keys( 'Jeffrey' , 'Walter' , 'Donny' ) ;
expect( mapLastName ).to.only.have.keys( 'Lebowski' , 'Sobchak' , 'Kerabatsos' ) ;
callback() ;
} ) ;
}
] )
.exec( done ) ;
} ) ;
} ) ;

@@ -1471,3 +903,3 @@

it( "should be able to modify '$'s embedded data without updating 'upstream's embedded data (internally, we are using the 'deep inherit' feature of tree-kit)" , function( done ) {
it( "should save and retrieve embedded data" , function( done ) {

@@ -1477,8 +909,7 @@ var town = towns.createDocument( {

meta: {
population: '2200K'
population: '2200K' ,
country: 'France'
}
} ) ;
var id = town._id ;
async.series( [

@@ -1489,16 +920,9 @@ function( callback ) {

function( callback ) {
towns.get( id , function( error , town ) {
towns.get( town._id , function( error , t ) {
//console.log( 'Error:' , error ) ;
//console.log( 'Town:' , string.inspect( { style: 'color' , proto: true } , town.$.meta ) ) ;
expect( error ).not.to.be.ok() ;
expect( town ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( town._id ).to.be.an( mongodb.ObjectID ) ;
expect( town._id ).to.eql( id ) ;
expect( tree.extend( null , {} , town.upstream ) ).to.eql( { _id: town._id , name: 'Paris' , meta: { population: '2200K' } } ) ;
expect( protoflatten( town.$ ) ).to.eql( { _id: town._id , name: 'Paris' , meta: { population: '2200K' } } ) ;
town.$.meta.population = '2300K' ;
expect( tree.extend( null , {} , town.upstream ) ).to.eql( { _id: town._id , name: 'Paris' , meta: { population: '2200K' } } ) ;
expect( protoflatten( town.$ ) ).to.eql( { _id: town._id , name: 'Paris' , meta: { population: '2300K' } } ) ;
expect( t.$ ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( t._id ).to.be.an( mongodb.ObjectID ) ;
expect( t ).to.eql( { _id: town._id , name: 'Paris' , meta: { population: '2200K' , country: 'France' } } ) ;
callback() ;

@@ -1521,4 +945,2 @@ } ) ;

var id = town._id ;
async.series( [

@@ -1529,30 +951,21 @@ function( callback ) {

function( callback ) {
towns.get( id , function( error , town ) {
towns.get( town._id , function( error , t ) {
//console.log( 'Error:' , error ) ;
//console.log( 'Town:' , town ) ;
expect( error ).not.to.be.ok() ;
expect( town ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( town._id ).to.be.an( mongodb.ObjectID ) ;
expect( town._id ).to.eql( id ) ;
expect( tree.extend( null , {} , town.upstream ) ).to.eql( { _id: town._id , name: 'Paris' , meta: { population: '2200K' , country: 'France' } } ) ;
expect( protoflatten( town.$ ) ).to.eql( { _id: town._id , name: 'Paris' , meta: { population: '2200K' , country: 'France' } } ) ;
expect( t ).to.eql( { _id: town._id , name: 'Paris' , meta: { population: '2200K' , country: 'France' } } ) ;
expect( t.$ ).to.be.an( rootsDb.DocumentWrapper ) ;
town.$.meta.population = '2300K' ;
expect( tree.extend( null , {} , town.upstream ) ).to.eql( { _id: town._id , name: 'Paris' , meta: { population: '2200K' , country: 'France' } } ) ;
expect( protoflatten( town.$ ) ).to.eql( { _id: town._id , name: 'Paris' , meta: { population: '2300K' , country: 'France' } } ) ;
town.$.save( callback ) ;
t.$.patch( { "meta.population": "2300K" } ) ;
t.$.commit( callback ) ;
} ) ;
} ,
function( callback ) {
towns.get( id , function( error , town ) {
towns.get( town._id , function( error , t ) {
//console.log( 'Error:' , error ) ;
//console.log( 'Town:' , town ) ;
expect( error ).not.to.be.ok() ;
expect( town ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( town._id ).to.be.an( mongodb.ObjectID ) ;
expect( town._id ).to.eql( id ) ;
expect( tree.extend( null , {} , town.upstream ) ).to.eql( { _id: town._id , name: 'Paris' , meta: { population: '2300K' , country: 'France' } } ) ;
expect( protoflatten( town.$ ) ).to.eql( { _id: town._id , name: 'Paris' , meta: { population: '2300K' , country: 'France' } } ) ;
expect( t.$ ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( t._id ).to.be.an( mongodb.ObjectID ) ;
expect( t ).to.eql( { _id: town._id , name: 'Paris' , meta: { population: '2300K' , country: 'France' } } ) ;
callback() ;

@@ -1610,3 +1023,3 @@ } ) ;

function( callback ) {
towns.collect( { "meta.country": 'USA' } , { raw: true } , function( error , batch ) {
towns.collect( { "meta.country": 'USA' } , function( error , batch ) {
var i , map = {} ;

@@ -1616,2 +1029,3 @@ //console.log( 'Error:' , error ) ;

expect( error ).not.to.be.ok() ;
expect( batch.$ ).to.be.an( rootsDb.BatchWrapper ) ;
expect( batch ).to.have.length( 3 ) ;

@@ -1631,23 +1045,2 @@

function( callback ) {
towns.collect( { "meta.country": 'USA' } , function( error , batch ) {
var i , map = {} ;
//console.log( 'Error:' , error ) ;
//console.log( 'Batch:' , batch ) ;
expect( error ).not.to.be.ok() ;
expect( batch ).to.be.an( rootsDb.BatchWrapper ) ;
expect( batch.documents ).to.have.length( 3 ) ;
for ( i = 0 ; i < batch.documents.length ; i ++ )
{
expect( batch.documents[ i ] ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( batch.documents[ i ].$.name ).to.ok() ;
expect( batch.documents[ i ].$.meta.country ).to.equal( 'USA' ) ;
map[ batch.documents[ i ].$.name ] = true ;
}
expect( map ).to.only.have.keys( 'New York' , 'Washington' , 'San Francisco' ) ;
callback() ;
} ) ;
} ,
function( callback ) {
towns.collect( { "meta.country": 'USA' , "meta.capital": false } , function( error , batch ) {

@@ -1658,11 +1051,10 @@ var i , map = {} ;

expect( error ).not.to.be.ok() ;
expect( batch ).to.be.an( rootsDb.BatchWrapper ) ;
expect( batch.documents ).to.have.length( 2 ) ;
expect( batch.$ ).to.be.an( rootsDb.BatchWrapper ) ;
expect( batch ).to.have.length( 2 ) ;
for ( i = 0 ; i < batch.documents.length ; i ++ )
for ( i = 0 ; i < batch.length ; i ++ )
{
expect( batch.documents[ i ] ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( batch.documents[ i ].$.name ).to.ok() ;
expect( batch.documents[ i ].$.meta.country ).to.equal( 'USA' ) ;
map[ batch.documents[ i ].$.name ] = true ;
expect( batch[ i ].name ).to.ok() ;
expect( batch[ i ].meta.country ).to.equal( 'USA' ) ;
map[ batch[ i ].name ] = true ;
}

@@ -1676,8 +1068,7 @@

towns.getUnique( { name: 'Tokyo', "meta.country": 'Japan' } , function( error , town ) {
var i , map = {} ;
//console.log( 'Error:' , error ) ;
//console.log( 'Town:' , town ) ;
expect( error ).not.to.be.ok() ;
expect( town ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( protoflatten( town.$ ) ).to.eql( {
expect( town.$ ).to.be.an( rootsDb.DocumentWrapper ) ;
expect( town ).to.eql( {
_id: town._id ,

@@ -1705,3 +1096,5 @@ name: 'Tokyo' ,

} ) ;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc