Comparing version 1.4.19 to 1.5.0
{ | ||
"name": "mongot", | ||
"version": "1.4.19", | ||
"version": "1.5.0", | ||
"description": "MongoT is a modern ODM library for MongoDb.", | ||
@@ -34,4 +34,4 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"@types/mongodb": "^2.2.15", | ||
"@types/node": "^8.0.47", | ||
"@types/mongodb": "^2.2.16", | ||
"@types/node": "^8.0.57", | ||
"merge": "^1.2.0", | ||
@@ -45,4 +45,4 @@ "mongodb": "^2.2.33" | ||
"tape": "^4.8.0", | ||
"typescript": "^2.5.3" | ||
"typescript": "^2.6.2" | ||
} | ||
} |
@@ -21,2 +21,10 @@ import * as MongoDb from 'mongodb'; | ||
constructor(connection: Promise<Connection>, name?: string, options?: MongoDb.CollectionOptions | MongoDb.CollectionCreateOptions, construct?: typeof SchemaDocument); | ||
/** | ||
* Get collection | ||
* @param {{new(...args: any[]): F}} collection | ||
* @returns {F} | ||
*/ | ||
getRelative<D extends SchemaDocument, F extends Collection<D>>(collection: { | ||
new (...args: any[]): F; | ||
}): F; | ||
readonly collection: PromiseLike<MongoDb.Collection>; | ||
@@ -57,3 +65,3 @@ /** | ||
*/ | ||
count(query: Object, options: MongoDb.MongoCountPreferences): Promise<number>; | ||
count(query?: Object, options?: MongoDb.MongoCountPreferences): Promise<number>; | ||
/** | ||
@@ -60,0 +68,0 @@ * @param fieldOrSpec |
@@ -42,3 +42,2 @@ "use strict"; | ||
this.construct = construct || metadata.construct; | ||
// this.state provide a collection instance from a lazy connection | ||
this.state = connection.then((connection) => connection.get(this.name, options || metadata.options)); | ||
@@ -67,2 +66,10 @@ this.connection = connection; | ||
} | ||
/** | ||
* Get collection | ||
* @param {{new(...args: any[]): F}} collection | ||
* @returns {F} | ||
*/ | ||
getRelative(collection) { | ||
return new collection(this.connection); | ||
} | ||
get collection() { | ||
@@ -69,0 +76,0 @@ return this.state; |
import * as MongoDb from 'mongodb'; | ||
import { Repository } from "./repository"; | ||
export declare class Connection { | ||
readonly db: MongoDb.Db; | ||
readonly context: Repository; | ||
private constructor(); | ||
@@ -8,3 +10,3 @@ create(name: string, options?: MongoDb.CollectionCreateOptions): Promise<MongoDb.Collection>; | ||
disconnect(): Promise<void>; | ||
static connect(uri: string, options?: MongoDb.MongoClientOptions): Promise<Connection>; | ||
static connect(context: Repository, uri: string, options?: MongoDb.MongoClientOptions): Promise<Connection>; | ||
} |
@@ -5,4 +5,5 @@ "use strict"; | ||
class Connection { | ||
constructor(db) { | ||
constructor(db, context) { | ||
this.db = db; | ||
this.context = context; | ||
} | ||
@@ -32,3 +33,3 @@ create(name, options) { | ||
} | ||
static connect(uri, options) { | ||
static connect(context, uri, options) { | ||
if (process.env.hasOwnProperty('MONGODB_DEBUG')) { | ||
@@ -39,3 +40,3 @@ MongoDb.Logger.setLevel('debug'); | ||
const callback = (error, db) => { | ||
error ? reject(error) : resolve(new Connection(db)); | ||
error ? reject(error) : resolve(new Connection(db, context)); | ||
}; | ||
@@ -42,0 +43,0 @@ MongoDb.MongoClient.connect(uri, options, callback); |
@@ -1,19 +0,7 @@ | ||
import * as MongoDb from 'mongodb'; | ||
import { Connection } from "./connection"; | ||
import { Collection } from "./collection"; | ||
import { SchemaDocument } from "./document"; | ||
declare class Repository { | ||
readonly state: Promise<Connection>; | ||
constructor(uri: string, options?: MongoDb.MongoClientOptions); | ||
get<D extends SchemaDocument, F extends Collection<D>>(collection: { | ||
new (...args: any[]): F; | ||
}): F; | ||
destroy(): Promise<any>; | ||
} | ||
export { Repository }; | ||
export * from './connection'; | ||
export * from './collection'; | ||
export * from './collection/helpers'; | ||
export * from './document'; | ||
export * from './schema'; | ||
export * from './cursor'; | ||
export { Repository } from './repository'; | ||
export { Connection } from './connection'; | ||
export { Collection, Events, Partial } from './collection'; | ||
export { createNextAutoIncrementNumber, DeleteResult, FindAndModifyResult, InsertResult, UpdateResult } from './collection/helpers'; | ||
export { SchemaDocument, PartialDocumentFragment, PRIMARY_KEY_NAME, SchemaArray, SchemaFragment, SchemaFragmentArray, SchemaMetadata, TypeCast } from './document'; | ||
export { collection, document, auto, CollectionDecorator, fragment, hook, index, IndexDecorator, indexes, indexSpecType, Long, ObjectID, preq, prop, PropDecorator, PropRequiredDecorator, req, required, virtual } from './schema'; | ||
export { CastFunction, Cursor } from './cursor'; |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const connection_1 = require("./connection"); | ||
class Repository { | ||
constructor(uri, options) { | ||
this.state = connection_1.Connection.connect(uri, options); | ||
} | ||
get(collection) { | ||
return new collection(this.state); | ||
} | ||
destroy() { | ||
return this.state.then((connection) => connection.disconnect(), error => error); | ||
} | ||
} | ||
exports.Repository = Repository; | ||
__export(require("./connection")); | ||
__export(require("./collection")); | ||
__export(require("./collection/helpers")); | ||
__export(require("./document")); | ||
__export(require("./schema")); | ||
__export(require("./cursor")); | ||
var repository_1 = require("./repository"); | ||
exports.Repository = repository_1.Repository; | ||
var connection_1 = require("./connection"); | ||
exports.Connection = connection_1.Connection; | ||
var collection_1 = require("./collection"); | ||
exports.Collection = collection_1.Collection; | ||
exports.Events = collection_1.Events; | ||
var helpers_1 = require("./collection/helpers"); | ||
exports.createNextAutoIncrementNumber = helpers_1.createNextAutoIncrementNumber; | ||
exports.DeleteResult = helpers_1.DeleteResult; | ||
exports.FindAndModifyResult = helpers_1.FindAndModifyResult; | ||
exports.InsertResult = helpers_1.InsertResult; | ||
exports.UpdateResult = helpers_1.UpdateResult; | ||
var document_1 = require("./document"); | ||
exports.SchemaDocument = document_1.SchemaDocument; | ||
exports.PartialDocumentFragment = document_1.PartialDocumentFragment; | ||
exports.PRIMARY_KEY_NAME = document_1.PRIMARY_KEY_NAME; | ||
exports.SchemaArray = document_1.SchemaArray; | ||
exports.SchemaFragment = document_1.SchemaFragment; | ||
exports.SchemaFragmentArray = document_1.SchemaFragmentArray; | ||
exports.SchemaMetadata = document_1.SchemaMetadata; | ||
exports.TypeCast = document_1.TypeCast; | ||
var schema_1 = require("./schema"); | ||
exports.collection = schema_1.collection; | ||
exports.document = schema_1.document; | ||
exports.auto = schema_1.auto; | ||
exports.fragment = schema_1.fragment; | ||
exports.hook = schema_1.hook; | ||
exports.index = schema_1.index; | ||
exports.indexes = schema_1.indexes; | ||
exports.Long = schema_1.Long; | ||
exports.ObjectID = schema_1.ObjectID; | ||
exports.preq = schema_1.preq; | ||
exports.prop = schema_1.prop; | ||
exports.req = schema_1.req; | ||
exports.required = schema_1.required; | ||
exports.virtual = schema_1.virtual; | ||
var cursor_1 = require("./cursor"); | ||
exports.Cursor = cursor_1.Cursor; | ||
//# sourceMappingURL=index.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
152646
50
2051
Updated@types/mongodb@^2.2.16
Updated@types/node@^8.0.57