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

hydrate-mongodb

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hydrate-mongodb - npm Package Compare versions

Comparing version 0.12.0 to 0.13.0

6

core/objectUtil.d.ts

@@ -0,2 +1,8 @@

/**
* @hidden
*/
export declare function shallowClone(obj: any): any;
/**
* @hidden
*/
export declare function isObject(obj: any): boolean;
"use strict";
/**
* @hidden
*/
function shallowClone(obj) {

@@ -15,2 +18,5 @@ if (!isObject(obj)) {

exports.shallowClone = shallowClone;
/**
* @hidden
*/
function isObject(obj) {

@@ -17,0 +23,0 @@ return obj != null && typeof obj === "object" && !Array.isArray(obj);

3

core/timerUtil.d.ts

@@ -0,1 +1,4 @@

/**
* @hidden
*/
export declare function getDuration(start: number[]): number;
"use strict";
/**
* @hidden
*/
function getDuration(start) {

@@ -3,0 +6,0 @@ var stop = process.hrtime(start);

13

mapping/providers/decorators.d.ts

@@ -426,3 +426,3 @@ import { Constructor, ParameterlessConstructor } from "../../index";

/**
* ## FetchType.Eager
* ### FetchType.Eager
*

@@ -432,3 +432,3 @@ * By default entity references are not loaded and must be fetched using Session#fetch or similar. If a FetchType of Eager is specified on

*
* ### Notes
* #### Notes
* * This works on entity reference in Embeddable objects as well.

@@ -438,3 +438,3 @@ * * It is generally preferable to fetch references as needed.

*
* ### Example
* #### Example
* ```typescript

@@ -449,3 +449,3 @@ *  @Entity()

*
* ## FetchType.Lazy
* ### FetchType.Lazy
*

@@ -456,3 +456,3 @@ * When an entity is loaded, all fields for that entity are retrieved from the database. Specifying a FetchType of Lazy for a field causes

*
* ### Notes
* #### Notes
* * Useful for properties that contain large amounts of data, such as images, that are not always needed.

@@ -462,3 +462,3 @@ * * A FetchType of Lazy on a property in an Embeddable objects is ignored. All properties in an embeddable object are always loaded from the database.

*
* ### Example
* #### Example
* ```typescript

@@ -471,2 +471,3 @@ *  @Entity()

* }
* ```
*/

@@ -473,0 +474,0 @@ export declare function Fetch(type: FetchType): PropertyDecorator;

{
"name": "hydrate-mongodb",
"description": "An Object Document Mapper (ODM) for MongoDB.",
"version": "0.12.0",
"version": "0.13.0",
"author": {

@@ -26,3 +26,4 @@ "name": "Artifact Health, LLC",

"mongodb": "^2.1.19",
"reflect-helper": "^1.0.2"
"reflect-helper": "^1.0.2",
"rx": "^4.1.0"
},

@@ -29,0 +30,0 @@ "devDependencies": {

@@ -26,3 +26,3 @@ import * as mongodb from "mongodb";

watch(value: any, observer: Observer): void;
executeQuery(query: QueryDefinition, callback: ResultCallback<Object>): void;
executeQuery(query: QueryDefinition, callback: ResultCallback<any>): void;
findOneById(id: any, callback: ResultCallback<any>): void;

@@ -92,2 +92,3 @@ findInverseOf(entity: Object, path: string, callback: ResultCallback<Object[]>): void;

private _findEachSeries(query, callback);
private _findCursor(query, callback);
private _prepareFind(query);

@@ -105,1 +106,17 @@ private _findOneAndModify(query, callback);

}
/**
* Cursor to retrieve entities.
* @hidden
*/
export interface Cursor<T> {
/**
* Gets the next entity from the cursor.
* @param callback Called with the next entity.
*/
next(callback: ResultCallback<T>): void;
/**
* Closes the cursor.
* @param callback Called when the cursor is closed.
*/
close(callback?: Callback): void;
}

@@ -322,2 +322,5 @@ "use strict";

break;
case queryKind_1.QueryKind.FindCursor:
this._findCursor(query, handleCallback);
break;
case queryKind_1.QueryKind.FindOneAndRemove:

@@ -470,2 +473,16 @@ case queryKind_1.QueryKind.FindOneAndUpdate:

};
PersisterImpl.prototype._findCursor = function (query, callback) {
var _this = this;
callback(null, new CursorImpl(this._prepareFind(query), function (document, callback) {
_this._loadOne(document, function (err, entity) {
if (err)
return callback(err);
if (!query.fetchPaths) {
callback(null, entity);
return;
}
_this._session.fetchInternal(entity, query.fetchPaths, callback);
});
}));
};
PersisterImpl.prototype._prepareFind = function (query) {

@@ -828,37 +845,37 @@ var cursor = this._collection.find(query.criteria, query.fields);

}());
/*
class QueryStream extends Readable {
private _cursor: mongodb.Cursor;
private _persister: PersisterImpl;
constructor(persister: PersisterImpl, cursor: mongodb.Cursor) {
super({readableObjectMode: true});
/**
* Implementation of a cursor to retrieve entities.
* @hidden
*/
var CursorImpl = (function () {
function CursorImpl(cursor, loader) {
this.closed = false;
this._cursor = cursor;
this._persister = persister;
this._loader = loader;
}
_read(): void {
this._cursor.nextObject((err: Error, item: any) => {
if (err) return handleError(err);
CursorImpl.prototype.next = function (callback) {
var _this = this;
this._cursor.nextObject(function (err, item) {
if (err)
return handleError(err);
if (item == null) {
// end of cursor
this.push(null);
callback(null, null);
return;
}
this._persister._loadOne(item, (err, result) => {
if (err) return handleError(err);
this.push(result);
_this._loader(item, function (err, result) {
if (err)
return handleError(err);
callback(null, result);
});
});
function handleError(err: Error) {
this._cursor.close(); // close the cursor since it may not be exhausted
this.emit('error', err);
function handleError(err) {
this.close(); // close the cursor since it may not be exhausted
callback(err);
}
}
}
*/
};
CursorImpl.prototype.close = function (callback) {
this._cursor.close(callback);
};
return CursorImpl;
}());

@@ -6,2 +6,3 @@ import { Callback } from "../core/callback";

import { Constructor } from "../index";
import { Observable } from "rx";
export interface QueryBuilder<T> {

@@ -12,3 +13,3 @@ findAll(callback?: ResultCallback<T[]>): FindQuery<T>;

findOne(criteria: QueryDocument, callback?: ResultCallback<T>): FindOneQuery<T>;
findOneById(id: any, callback?: ResultCallback<Object>): FindOneQuery<T>;
findOneById(id: any, callback?: ResultCallback<T>): FindOneQuery<T>;
findOneAndRemove(callback?: ResultCallback<T>): FindOneAndRemoveQuery<T>;

@@ -39,3 +40,5 @@ findOneAndRemove(criteria: QueryDocument, callback?: ResultCallback<T>): FindOneAndRemoveQuery<T>;

export interface Query<T> {
execute(callback: ResultCallback<T>): void;
/**
* Returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) for the query.
*/
asPromise(): Promise<T>;

@@ -74,2 +77,6 @@ }

eachSeries(iterator: IteratorCallback<T>, callback: Callback): void;
/**
* Returns an [Observable](http://reactivex.io/documentation/observable.html) for the query.
*/
asObservable(): Observable<T>;
}

@@ -79,17 +86,17 @@ /**

*/
export declare class QueryBuilderImpl implements QueryBuilder<Object> {
export declare class QueryBuilderImpl<T> implements QueryBuilder<T> {
private _session;
private _entityCtr;
constructor(session: InternalSession, entityCtr: Constructor<any>);
findAll(callback?: ResultCallback<Object[]>): FindQuery<Object>;
findAll(criteria: QueryDocument, callback?: ResultCallback<Object[]>): FindQuery<Object>;
findOne(callback?: ResultCallback<Object>): FindOneQuery<Object>;
findOne(criteria: QueryDocument, callback?: ResultCallback<Object>): FindOneQuery<Object>;
findOneById(id: any, callback?: ResultCallback<Object>): FindOneQuery<Object>;
findOneAndRemove(callback?: ResultCallback<Object>): FindOneAndRemoveQuery<Object>;
findOneAndRemove(criteria: QueryDocument, callback?: ResultCallback<Object>): FindOneAndRemoveQuery<Object>;
findOneAndUpdate(updateDocument: QueryDocument, callback?: ResultCallback<Object>): FindOneAndUpdateQuery<Object>;
findOneAndUpdate(criteria: QueryDocument, updateDocument: QueryDocument, callback?: ResultCallback<Object>): FindOneAndUpdateQuery<Object>;
findOneAndUpsert(updateDocument: QueryDocument, callback?: ResultCallback<Object>): FindOneAndUpdateQuery<Object>;
findOneAndUpsert(criteria: QueryDocument, updateDocument: QueryDocument, callback?: ResultCallback<Object>): FindOneAndUpdateQuery<Object>;
findAll(callback?: ResultCallback<T[]>): FindQuery<T>;
findAll(criteria: QueryDocument, callback?: ResultCallback<T[]>): FindQuery<T>;
findOne(callback?: ResultCallback<T>): FindOneQuery<T>;
findOne(criteria: QueryDocument, callback?: ResultCallback<T>): FindOneQuery<T>;
findOneById(id: any, callback?: ResultCallback<T>): FindOneQuery<T>;
findOneAndRemove(callback?: ResultCallback<T>): FindOneAndRemoveQuery<T>;
findOneAndRemove(criteria: QueryDocument, callback?: ResultCallback<T>): FindOneAndRemoveQuery<T>;
findOneAndUpdate(updateDocument: QueryDocument, callback?: ResultCallback<T>): FindOneAndUpdateQuery<T>;
findOneAndUpdate(criteria: QueryDocument, updateDocument: QueryDocument, callback?: ResultCallback<T>): FindOneAndUpdateQuery<T>;
findOneAndUpsert(updateDocument: QueryDocument, callback?: ResultCallback<T>): FindOneAndUpdateQuery<T>;
findOneAndUpsert(criteria: QueryDocument, updateDocument: QueryDocument, callback?: ResultCallback<T>): FindOneAndUpdateQuery<T>;
removeAll(callback?: ResultCallback<number>): void;

@@ -96,0 +103,0 @@ removeAll(criteria: QueryDocument, callback?: ResultCallback<number>): void;

"use strict";
var queryKind_1 = require("./queryKind");
var persistenceError_1 = require("../persistenceError");
var rx_1 = require("rx");
/**

@@ -126,2 +127,3 @@ * @hidden

case queryKind_1.QueryKind.FindEachSeries:
case queryKind_1.QueryKind.FindCursor:
case queryKind_1.QueryKind.FindOne:

@@ -255,2 +257,41 @@ case queryKind_1.QueryKind.FindOneById:

};
QueryObject.prototype.asObservable = function () {
var _this = this;
this.kind = queryKind_1.QueryKind.FindCursor;
return rx_1.Observable.create(function (observer) {
var cursor, disposed = false;
_this.handleCallback(function (err, result) {
if (err) {
observer.onError(err);
}
else {
cursor = result;
(function next() {
cursor.next(function (err, entity) {
if (disposed) {
return;
}
if (err) {
observer.onError(err);
return;
}
if (entity == null) {
observer.onCompleted();
return;
}
observer.onNext(entity);
next();
});
})();
}
});
// return the dispose function
return function () {
disposed = true;
if (cursor) {
cursor.close();
}
};
});
};
/**

@@ -257,0 +298,0 @@ * Creates an object for logging purposes.

@@ -13,9 +13,10 @@ /**

FindOneAndUpsert = 7,
RemoveAll = 8,
RemoveOne = 9,
UpdateAll = 10,
UpdateOne = 11,
Upsert = 12,
Distinct = 13,
Count = 14,
FindCursor = 8,
RemoveAll = 9,
RemoveOne = 10,
UpdateAll = 11,
UpdateOne = 12,
Upsert = 13,
Distinct = 14,
Count = 15,
}

@@ -14,10 +14,11 @@ "use strict";

QueryKind[QueryKind["FindOneAndUpsert"] = 7] = "FindOneAndUpsert";
QueryKind[QueryKind["RemoveAll"] = 8] = "RemoveAll";
QueryKind[QueryKind["RemoveOne"] = 9] = "RemoveOne";
QueryKind[QueryKind["UpdateAll"] = 10] = "UpdateAll";
QueryKind[QueryKind["UpdateOne"] = 11] = "UpdateOne";
QueryKind[QueryKind["Upsert"] = 12] = "Upsert";
QueryKind[QueryKind["Distinct"] = 13] = "Distinct";
QueryKind[QueryKind["Count"] = 14] = "Count";
QueryKind[QueryKind["FindCursor"] = 8] = "FindCursor";
QueryKind[QueryKind["RemoveAll"] = 9] = "RemoveAll";
QueryKind[QueryKind["RemoveOne"] = 10] = "RemoveOne";
QueryKind[QueryKind["UpdateAll"] = 11] = "UpdateAll";
QueryKind[QueryKind["UpdateOne"] = 12] = "UpdateOne";
QueryKind[QueryKind["Upsert"] = 13] = "Upsert";
QueryKind[QueryKind["Distinct"] = 14] = "Distinct";
QueryKind[QueryKind["Count"] = 15] = "Count";
})(exports.QueryKind || (exports.QueryKind = {}));
var QueryKind = exports.QueryKind;

@@ -255,7 +255,7 @@ [![Build Status](https://travis-ci.org/artifacthealth/hydrate-mongodb.svg?branch=master)](https://travis-ci.org/artifacthealth/hydrate-mongodb)

### Promises
### Promises and Observables
All queries can return a Promise by chaining a call to `asPromise`.
All queries can use a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) for the query result by calling [asPromise](http://localhost:63342/hydrate/build/docs/interfaces/findonequery.html#aspromise).
Converting a find-by-id query to a Promise.
#### Example: Finding an entity by identifier

@@ -268,3 +268,3 @@ ```typescript

Converting a find-all query to a promise
#### Example: Finding entities by criteria

@@ -277,2 +277,10 @@ ```typescript

Queries that return multiple entities may return an [Observable](http://reactivex.io/documentation/observable.html) for the query by calling [asObservable](http://localhost:63342/hydrate/build/docs/interfaces/findquery.html#asobservable).
```typescript
session.query(Task).findAll({ assigned: person }).asObservable().subscribe((task) => {
...
});
```
## Modeling

@@ -291,2 +299,3 @@

* [`Discriminators`](#Discriminators)
* [`Fetching`](#Fetching)

@@ -319,2 +328,3 @@ <a name="Entities"></a>

* An identifier is assigned to the entity when it is saved.
* If the [Immutable](https://artifacthealth.github.io/hydrate-mongodb/globals.html#immutable) decorator is specified on an Entity, the entity is excluded from dirty checking.

@@ -456,2 +466,3 @@ <a name="Collections"></a>

represented by it's serialized fields.
* If the [Immutable](https://artifacthealth.github.io/hydrate-mongodb/globals.html#immutable) decorator is specified on an Embeddable class, the original document for the Embeddable is cached and used for serialization.

@@ -648,3 +659,3 @@ <a name="Types"></a>

<a name="Fetching"></a>
### Fetching

@@ -688,2 +699,2 @@

}
```
```
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