Socket
Socket
Sign inDemoInstall

type-mongodb

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

type-mongodb - npm Package Compare versions

Comparing version 1.0.0-beta.15 to 2.0.0-beta.0

9

lib/connection/Connection.js

@@ -27,4 +27,5 @@ "use strict";

connect() {
var _a;
return __awaiter(this, void 0, void 0, function* () {
if (!this.client.isConnected()) {
if (!((_a = this.client.topology) === null || _a === void 0 ? void 0 : _a.isConnected())) {
yield this.client.connect();

@@ -38,4 +39,5 @@ }

close(force) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
if (this.client.isConnected()) {
if ((_a = this.client.topology) === null || _a === void 0 ? void 0 : _a.isConnected()) {
yield this.client.close(force);

@@ -49,4 +51,3 @@ }

}
const client = opts.client ||
new mongodb_1.MongoClient(opts.uri, Object.assign(Object.assign({}, (opts.options || {})), { useNewUrlParser: true, useUnifiedTopology: true }));
const client = opts.client || new mongodb_1.MongoClient(opts.uri, opts.options);
return new Connection(client, opts.database);

@@ -53,0 +54,0 @@ }

@@ -5,8 +5,7 @@ "use strict";

require("reflect-metadata");
const definitionStorage_1 = require("../utils/definitionStorage");
const reflection_1 = require("../utils/reflection");
const utils_1 = require("../utils");
const errors_1 = require("../errors");
function Document(options = {}) {
return (target) => {
definitionStorage_1.definitionStorage.documents.set(target, Object.assign(Object.assign({}, options), { DocumentClass: target, repository: options.repository, database: options.database, collection: options.collection || target.name }));
utils_1.definitionStorage.documents.set(target, Object.assign(Object.assign({}, options), { DocumentClass: target, repository: options.repository, database: options.database, collection: options.collection || target.name }));
};

@@ -38,3 +37,3 @@ }

function addFieldDefinition(target, field, options, embedded) {
const def = Object.assign(Object.assign(Object.assign(Object.assign({}, options), { DocumentClass: target.constructor, propertyName: field, fieldName: options.name || field, isId: options.isId === true, isEmbedded: typeof embedded !== 'undefined', embedded }), reflection_1.fieldToType(target, field, options.type)), { shouldCreateJSValue: typeof options.create === 'boolean' ? options.create : false });
const def = Object.assign(Object.assign(Object.assign(Object.assign({}, options), { DocumentClass: target.constructor, propertyName: field, fieldName: options.name || field, isId: options.isId === true, isEmbedded: typeof embedded !== 'undefined', embedded }), utils_1.fieldToType(target, field, options.type)), { shouldCreateJSValue: typeof options.create === 'boolean' ? options.create : false });
if (def.type && def.typeIsArray && def.shouldCreateJSValue) {

@@ -44,7 +43,7 @@ console.log(def.type, def.typeIsArray, def.shouldCreateJSValue, options.create);

}
if (definitionStorage_1.definitionStorage.fields.has(def.DocumentClass)) {
definitionStorage_1.definitionStorage.fields.get(def.DocumentClass).set(field, def);
if (utils_1.definitionStorage.fields.has(def.DocumentClass)) {
utils_1.definitionStorage.fields.get(def.DocumentClass).set(field, def);
}
else {
definitionStorage_1.definitionStorage.fields.set(def.DocumentClass, new Map([[field, def]]));
utils_1.definitionStorage.fields.set(def.DocumentClass, new Map([[field, def]]));
}

@@ -58,6 +57,6 @@ }

};
if (definitionStorage_1.definitionStorage.parents.has(meta.DocumentClass)) {
if (utils_1.definitionStorage.parents.has(meta.DocumentClass)) {
errors_1.InternalError.throw(`Parent already exists for "${target.constructor.name}"`);
}
definitionStorage_1.definitionStorage.parents.set(meta.DocumentClass, meta);
utils_1.definitionStorage.parents.set(meta.DocumentClass, meta);
};

@@ -77,3 +76,3 @@ }

};
definitionStorage_1.definitionStorage.discriminators.set(target, Object.assign(Object.assign({}, (definitionStorage_1.definitionStorage.discriminators.get(target) || {})), mapping));
utils_1.definitionStorage.discriminators.set(target, Object.assign(Object.assign({}, (utils_1.definitionStorage.discriminators.get(target) || {})), mapping));
}

@@ -86,3 +85,3 @@ else {

while (proto && proto.prototype) {
definition = definitionStorage_1.definitionStorage.discriminators.get(proto);
definition = utils_1.definitionStorage.discriminators.get(proto);
if (definition) {

@@ -89,0 +88,0 @@ break;

@@ -1,11 +0,11 @@

import { MongoClient, SessionOptions } from 'mongodb';
import { DocumentClass, Collection, Db, Newable } from './typings';
import { DocumentMetadataFactory } from './metadata/DocumentMetadataFactory';
import { DocumentMetadata } from './metadata/DocumentMetadata';
import { MongoClient, Collection, Db, ClientSessionOptions } from 'mongodb';
import { DocumentClass, Newable } from './typings';
import { DocumentMetadataFactory } from './metadata';
import { DocumentMetadata } from './metadata';
import { Connection, ConnectionOptions } from './connection/Connection';
import { EventSubscriber } from './events/interfaces';
import { EventSubscriber } from './events';
import { EventManager } from './events';
import { Repository } from './repository/Repository';
import { Repository } from './repository';
import { Session } from './transaction/Session';
import { EmbeddedDocumentMetadata } from './metadata/EmbeddedDocumentMetadata';
import { EmbeddedDocumentMetadata } from './metadata';
export interface ContainerLike {

@@ -85,5 +85,5 @@ get: <T = any>(service: Newable<T>) => any;

getRepository<T extends Repository<any>>(target: DocumentClass): T;
startSession(opts?: SessionOptions): Session;
startSession(opts?: ClientSessionOptions): Session;
static create(opts: DocumentManagerOptions): Promise<DocumentManager>;
}
//# sourceMappingURL=DocumentManager.d.ts.map

@@ -13,7 +13,7 @@ "use strict";

exports.DocumentManager = void 0;
const DocumentMetadataFactory_1 = require("./metadata/DocumentMetadataFactory");
const metadata_1 = require("./metadata");
const Connection_1 = require("./connection/Connection");
const events_1 = require("./events");
const Session_1 = require("./transaction/Session");
const DocumentTransformer_1 = require("./transformer/DocumentTransformer");
const transformer_1 = require("./transformer");
const errors_1 = require("./errors");

@@ -35,3 +35,3 @@ const defaultContainer = {

this.connection = Connection_1.Connection.create(this.opts.connection);
this.metadataFactory = new DocumentMetadataFactory_1.DocumentMetadataFactory({
this.metadataFactory = new metadata_1.DocumentMetadataFactory({
dm: this,

@@ -154,3 +154,3 @@ documents: opts.documents

dm.buildSubscribers();
DocumentTransformer_1.DocumentTransformer.compile();
transformer_1.DocumentTransformer.compile();
return dm;

@@ -157,0 +157,0 @@ });

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

import { FilterQuery } from '../typings';
import { Filter } from 'mongodb';
import { DocumentMetadata } from '../metadata';

@@ -28,4 +28,4 @@ import { Mode, Type } from '../types';

static invalidType(type: Type, value: any, mode: Mode): void;
static documentNotFound(meta: DocumentMetadata, filter: FilterQuery<any>): void;
static documentNotFound(meta: DocumentMetadata, filter: Filter<any>): void;
}
//# sourceMappingURL=index.d.ts.map

@@ -10,3 +10,3 @@ "use strict";

var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};

@@ -13,0 +13,0 @@ Object.defineProperty(exports, "__esModule", { value: true });

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

import { DocumentMetadata } from '../metadata/DocumentMetadata';
import { Filter, UpdateQuery } from 'mongodb';
import { DocumentMetadata } from '../metadata';
import { DocumentManager } from '../DocumentManager';
import { FilterQuery, UpdateQuery } from '../typings';
export declare enum Events {

@@ -26,9 +26,9 @@ BeforeInsert = "beforeInsert",

update: UpdateQuery<T>;
filter: FilterQuery<T>;
filter: Filter<T>;
}
export interface DeleteEvent<T = any> extends Event<T> {
filter: FilterQuery<T>;
filter: Filter<T>;
}
export interface ReplaceEvent<T = any> extends Event<T> {
filter: FilterQuery<T>;
filter: Filter<T>;
model: T;

@@ -35,0 +35,0 @@ }

@@ -10,3 +10,3 @@ "use strict";

var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};

@@ -13,0 +13,0 @@ Object.defineProperty(exports, "__esModule", { value: true });

@@ -1,3 +0,3 @@

import { FilterQuery } from 'mongodb';
import { Newable, OptionalId } from '../typings';
import { Filter, OptionalId } from 'mongodb';
import { Newable } from '../typings';
import { FieldMetadata } from './FieldMetadata';

@@ -55,4 +55,4 @@ import { ParentDefinition } from './definitions';

*/
transformQueryFilter(input: FilterQuery<T>): FilterQuery<any>;
transformQueryFilter(input: Filter<T>): Filter<any>;
}
//# sourceMappingURL=AbstractDocumentMetadata.d.ts.map
import { DocumentClass, Newable } from '../typings';
import { Repository } from '../repository/Repository';
import { Repository } from '../repository';
import { Type } from '../types';

@@ -4,0 +4,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DiscriminatorMetadata = void 0;
const definitionStorage_1 = require("../utils/definitionStorage");
const utils_1 = require("../utils");
const errors_1 = require("../errors");

@@ -14,3 +14,3 @@ class DiscriminatorMetadata {

// get fieldName from fields storage
this.fieldName = definitionStorage_1.definitionStorage.fields
this.fieldName = utils_1.definitionStorage.fields
.get(this.DocumentClass)

@@ -21,3 +21,3 @@ .get(this.propertyName).fieldName;

const { DocumentClass, propertyName } = definition;
const fieldsDef = definitionStorage_1.definitionStorage.fields.get(DocumentClass);
const fieldsDef = utils_1.definitionStorage.fields.get(DocumentClass);
if (!fieldsDef || !fieldsDef.has(propertyName)) {

@@ -24,0 +24,0 @@ errors_1.InternalError.throw(`@Discriminator() classes must have a decorated @Field() property with name "${propertyName}"`);

@@ -5,3 +5,3 @@ import { Collection, Db } from 'mongodb';

import { Connection } from '../connection/Connection';
import { Repository } from '../repository/Repository';
import { Repository } from '../repository';
import { DocumentManager } from '../DocumentManager';

@@ -24,3 +24,3 @@ export interface DocumentMetadataOpts<T = any, D extends Newable = Newable<T>> {

readonly db: Db;
readonly collection: Collection;
readonly collection: Collection<T>;
readonly extensions: Record<any, any>;

@@ -27,0 +27,0 @@ readonly repository: Repository<T>;

@@ -119,3 +119,3 @@ "use strict";

repository.manager = this.opts.dm;
const meta = new DocumentMetadata_1.DocumentMetadata({
return new DocumentMetadata_1.DocumentMetadata({
DocumentClass,

@@ -129,3 +129,2 @@ fields: this.buildFields(DocumentClass),

});
return meta;
});

@@ -132,0 +131,0 @@ }

@@ -10,3 +10,3 @@ "use strict";

var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};

@@ -13,0 +13,0 @@ Object.defineProperty(exports, "__esModule", { value: true });

@@ -1,6 +0,8 @@

import { Cursor, FindOneOptions, FindOneAndUpdateOption, FindOneAndReplaceOption, FindOneAndDeleteOption, UpdateWriteOpResult, ReplaceWriteOpResult, DeleteWriteOpResultObject } from 'mongodb';
import { Collection, Db, OptionalId, InsertOneWriteOpResult, CommonOptions, FilterQuery, UpdateQuery, UpdateManyOptions, UpdateOneOptions, ReplaceOneOptions, CollectionInsertOneOptions, InsertWriteOpResult, CollectionInsertManyOptions } from '../typings';
import { Db, Collection, FindCursor, FindOptions, Filter, InsertOneOptions, BulkWriteOptions, OptionalId, InsertOneResult, InsertManyResult, UpdateQuery, FindOneAndUpdateOptions, FindOneAndReplaceOptions, FindOneAndDeleteOptions, UpdateOptions, UpdateResult, DeleteOptions, DeleteResult } from 'mongodb';
import { DocumentMetadata } from '../metadata';
import { DocumentManager } from '../DocumentManager';
import { Type } from '../types';
export interface TransformQueryFilterOptions {
transformQueryFilter?: boolean;
}
/**

@@ -30,47 +32,44 @@ * Repository for documents

fromDB(doc: Partial<T>): T;
protected failIfEmpty(meta: DocumentMetadata<T>, filter: FilterQuery<any>, value: any): any;
abstract find(query?: FilterQuery<T | any>): Cursor<T>;
abstract find(query: FilterQuery<T | any>, opts: FindOneOptions): Cursor<T>;
abstract find(query: FilterQuery<T | any>, opts?: FindOneOptions): Cursor<T>;
abstract findByIds(ids: any[]): Cursor<T>;
abstract findByIds(ids: any[], opts: FindOneOptions): Cursor<T>;
abstract findByIds(ids: any[], opts?: FindOneOptions): Cursor<T>;
abstract findById(id: any, opts?: FindOneOptions): Promise<T | null>;
abstract findByIdOrFail(id: any, opts?: FindOneOptions): Promise<T>;
abstract findOne(filter: FilterQuery<T | any>, opts?: FindOneOptions): Promise<T | null>;
abstract findOneOrFail(filter: FilterQuery<T | any>, opts?: FindOneOptions): Promise<T | null>;
abstract create(props: Partial<T>, opts?: CollectionInsertOneOptions): Promise<T>;
abstract create(props: Partial<T>[], opts?: CollectionInsertManyOptions): Promise<T[]>;
abstract create(props: Partial<T> | Partial<T>[], opts?: CollectionInsertOneOptions | CollectionInsertManyOptions): Promise<T | T[]>;
abstract createOne(props: Partial<T>, opts?: CollectionInsertOneOptions): Promise<T>;
abstract createMany(props: Partial<T>[], opts?: CollectionInsertManyOptions): Promise<T[]>;
abstract insertOne(model: OptionalId<T>, opts?: CollectionInsertOneOptions): Promise<InsertOneWriteOpResult<any>>;
abstract insertMany(models: OptionalId<T>[], opts?: CollectionInsertManyOptions): Promise<InsertWriteOpResult<any>>;
abstract findOneAndUpdate(filter: FilterQuery<T | any>, update: UpdateQuery<T>, opts?: FindOneAndUpdateOption): Promise<T | null>;
abstract findOneAndUpdateOrFail(filter: FilterQuery<T | any>, update: UpdateQuery<T>, opts?: FindOneAndUpdateOption): Promise<T>;
abstract findByIdAndUpdate(id: any, update: UpdateQuery<T>, opts?: FindOneAndUpdateOption): Promise<T | null>;
abstract findByIdAndUpdateOrFail(id: any, update: UpdateQuery<T>, opts?: FindOneAndUpdateOption): Promise<T>;
abstract findOneAndReplace(filter: FilterQuery<T | any>, props: OptionalId<Partial<T>>, opts?: FindOneAndReplaceOption): Promise<T | null>;
abstract findOneAndReplaceOrFail(filter: FilterQuery<T | any>, props: OptionalId<Partial<T>>, opts?: FindOneAndReplaceOption): Promise<T>;
abstract findByIdAndReplace(id: any, props: OptionalId<Partial<T>>, opts?: FindOneAndReplaceOption): Promise<T | null>;
abstract findByIdAndReplaceOrFail(id: any, props: OptionalId<Partial<T>>, opts?: FindOneAndReplaceOption): Promise<T>;
abstract findOneAndDelete(filter: FilterQuery<T | any>, opts?: FindOneAndDeleteOption): Promise<T | null>;
abstract findOneAndDeleteOrFail(filter: FilterQuery<T | any>, opts?: FindOneAndDeleteOption): Promise<T>;
abstract findByIdAndDelete(id: any, opts?: FindOneAndDeleteOption): Promise<T | null>;
abstract findByIdAndDeleteOrFail(id: any, opts?: FindOneAndDeleteOption): Promise<T | null>;
abstract updateOne(filter: FilterQuery<T | any>, update: UpdateQuery<T>, opts?: UpdateOneOptions): Promise<UpdateWriteOpResult>;
abstract updateById(id: any, update: UpdateQuery<T>, opts?: UpdateOneOptions): Promise<UpdateWriteOpResult>;
abstract updateMany(filter: FilterQuery<T | any>, update: UpdateQuery<T>, opts?: UpdateManyOptions): Promise<UpdateWriteOpResult>;
abstract updateByIds(ids: any[], update: UpdateQuery<T>, opts?: UpdateManyOptions): Promise<UpdateWriteOpResult>;
abstract replaceOne(filter: FilterQuery<T | any>, props: Partial<T>, opts?: ReplaceOneOptions): Promise<ReplaceWriteOpResult>;
abstract replaceById(id: any, props: Partial<T>, opts?: ReplaceOneOptions): Promise<ReplaceWriteOpResult>;
abstract deleteOne(filter: FilterQuery<T | any>, opts?: CommonOptions & {
bypassDocumentValidation?: boolean;
}): Promise<boolean>;
abstract deleteById(id: any, opts?: CommonOptions & {
bypassDocumentValidation?: boolean;
}): Promise<boolean>;
abstract deleteMany(filter: FilterQuery<T | any>, opts?: CommonOptions): Promise<DeleteWriteOpResultObject>;
abstract deleteByIds(ids: any[], opts?: CommonOptions): Promise<DeleteWriteOpResultObject>;
transformQueryFilter(input: Filter<T | any>, opts?: TransformQueryFilterOptions & Record<any, any>): Filter<any>;
protected failIfEmpty(meta: DocumentMetadata<T>, filter: Filter<any>, value: any): any;
abstract find(query?: Filter<T | any>): FindCursor<T>;
abstract find(query: Filter<T | any>, opts: FindOptions): FindCursor<T>;
abstract find(query: Filter<T | any>, opts?: FindOptions): FindCursor<T>;
abstract findByIds(ids: any[]): FindCursor<T>;
abstract findByIds(ids: any[], opts: FindOptions): FindCursor<T>;
abstract findByIds(ids: any[], opts?: FindOptions): FindCursor<T>;
abstract findById(id: any, opts?: FindOptions): Promise<T | null>;
abstract findByIdOrFail(id: any, opts?: FindOptions): Promise<T>;
abstract findOne(filter: Filter<T | any>, opts?: FindOptions): Promise<T | null>;
abstract findOneOrFail(filter: Filter<T | any>, opts?: FindOptions): Promise<T | null>;
abstract create(props: Partial<T>, opts?: InsertOneOptions): Promise<T>;
abstract create(props: Partial<T>[], opts?: BulkWriteOptions): Promise<T[]>;
abstract create(props: Partial<T> | Partial<T>[], opts?: InsertOneOptions | BulkWriteOptions): Promise<T | T[]>;
abstract createOne(props: Partial<T>, opts?: InsertOneOptions): Promise<T>;
abstract createMany(props: Partial<T>[], opts?: BulkWriteOptions): Promise<T[]>;
abstract insertOne(model: OptionalId<T>, opts?: InsertOneOptions): Promise<InsertOneResult<any>>;
abstract insertMany(models: OptionalId<T>[], opts?: BulkWriteOptions): Promise<InsertManyResult<T>>;
abstract findOneAndUpdate(filter: Filter<T | any>, update: UpdateQuery<T>, opts?: FindOneAndUpdateOptions & TransformQueryFilterOptions): Promise<T | null>;
abstract findOneAndUpdateOrFail(filter: Filter<T | any>, update: UpdateQuery<T>, opts?: FindOneAndUpdateOptions & TransformQueryFilterOptions): Promise<T>;
abstract findByIdAndUpdate(id: any, update: UpdateQuery<T>, opts?: FindOneAndUpdateOptions & TransformQueryFilterOptions): Promise<T | null>;
abstract findByIdAndUpdateOrFail(id: any, update: UpdateQuery<T>, opts?: FindOneAndUpdateOptions & TransformQueryFilterOptions): Promise<T>;
abstract findOneAndReplace(filter: Filter<T | any>, props: Partial<T>, opts?: FindOneAndReplaceOptions & TransformQueryFilterOptions): Promise<T | null>;
abstract findOneAndReplaceOrFail(filter: Filter<T | any>, props: Partial<T>, opts?: FindOneAndReplaceOptions & TransformQueryFilterOptions): Promise<T>;
abstract findByIdAndReplace(id: any, props: Partial<T>, opts?: FindOneAndReplaceOptions & TransformQueryFilterOptions): Promise<T | null>;
abstract findByIdAndReplaceOrFail(id: any, props: Partial<T>, opts?: FindOneAndReplaceOptions & TransformQueryFilterOptions): Promise<T>;
abstract findOneAndDelete(filter: Filter<T | any>, opts?: FindOneAndDeleteOptions & TransformQueryFilterOptions): Promise<T | null>;
abstract findOneAndDeleteOrFail(filter: Filter<T | any>, opts?: FindOneAndDeleteOptions & TransformQueryFilterOptions): Promise<T | null>;
abstract findByIdAndDelete(id: any, opts?: FindOneAndDeleteOptions & TransformQueryFilterOptions): Promise<T | null>;
abstract findByIdAndDeleteOrFail(id: any, opts?: FindOneAndDeleteOptions & TransformQueryFilterOptions): Promise<T | null>;
abstract updateOne(filter: Filter<T | any>, update: UpdateQuery<T>, opts?: UpdateOptions & TransformQueryFilterOptions): Promise<UpdateResult>;
abstract updateById(id: any, update: UpdateQuery<T>, opts?: UpdateOptions & TransformQueryFilterOptions): Promise<UpdateResult>;
abstract updateMany(filter: Filter<T | any>, update: UpdateQuery<T>, opts?: UpdateOptions & TransformQueryFilterOptions): Promise<UpdateResult>;
abstract updateByIds(ids: any[], update: UpdateQuery<T>, opts?: UpdateOptions & TransformQueryFilterOptions): Promise<UpdateResult>;
abstract replaceOne(filter: Filter<T | any>, props: Partial<T>, opts?: UpdateOptions & TransformQueryFilterOptions): Promise<UpdateResult>;
abstract replaceById(id: any, props: Partial<T>, opts?: UpdateOptions & TransformQueryFilterOptions): Promise<UpdateResult>;
abstract deleteOne(filter: Filter<T | any>, opts?: DeleteOptions & TransformQueryFilterOptions): Promise<boolean>;
abstract deleteById(id: any, opts?: DeleteOptions & TransformQueryFilterOptions): Promise<boolean>;
abstract deleteMany(filter: Filter<T | any>, opts?: DeleteOptions & TransformQueryFilterOptions): Promise<DeleteResult>;
abstract deleteByIds(ids: any[], opts?: DeleteOptions & TransformQueryFilterOptions): Promise<DeleteResult>;
}
//# sourceMappingURL=AbstractRepository.d.ts.map

@@ -39,2 +39,12 @@ "use strict";

}
transformQueryFilter(input, opts) {
if (typeof opts === 'object' && 'transformQueryFilter' in opts) {
const transformQueryFilter = opts.transformQueryFilter;
delete opts.transformQueryFilter;
if (transformQueryFilter === false) {
return input;
}
}
return this.metadata.transformQueryFilter(input);
}
// -------------------------------------------------------------------------

@@ -41,0 +51,0 @@ // MongoDB specific methods

@@ -10,3 +10,3 @@ "use strict";

var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};

@@ -13,0 +13,0 @@ Object.defineProperty(exports, "__esModule", { value: true });

@@ -1,9 +0,5 @@

import { Cursor, FindOneOptions, FindOneAndUpdateOption, FindOneAndReplaceOption, FindOneAndDeleteOption, UpdateWriteOpResult, ReplaceWriteOpResult, DeleteWriteOpResultObject } from 'mongodb';
import { Collection, Db, OptionalId, InsertOneWriteOpResult, CommonOptions, FilterQuery, UpdateQuery, UpdateManyOptions, UpdateOneOptions, ReplaceOneOptions, CollectionInsertOneOptions, InsertWriteOpResult, CollectionInsertManyOptions } from '../typings';
import { DocumentMetadata } from '../metadata/DocumentMetadata';
import { BulkWriteOptions, Collection, Db, DeleteOptions, DeleteResult, Filter, FindCursor, FindOneAndDeleteOptions, FindOneAndReplaceOptions, FindOneAndUpdateOptions, FindOptions, InsertManyResult, InsertOneOptions, InsertOneResult, ModifyResult, OptionalId, UpdateOptions, UpdateQuery, UpdateResult } from 'mongodb';
import { DocumentMetadata } from '../metadata';
import { DocumentManager } from '../DocumentManager';
import { AbstractRepository } from './AbstractRepository';
interface FilterOptions {
transformQueryFilter?: boolean;
}
import { AbstractRepository, TransformQueryFilterOptions } from './AbstractRepository';
/**

@@ -34,47 +30,41 @@ * Repository for documents

}): T;
find(query?: FilterQuery<T | any>): Cursor<T>;
find(query: FilterQuery<T | any>, opts: FindOneOptions & FilterOptions): Cursor<T>;
findByIds(ids: any[]): Cursor<T>;
findByIds(ids: any[], opts: FindOneOptions & FilterOptions): Cursor<T>;
findById(id: any, opts?: FindOneOptions & FilterOptions): Promise<T | null>;
findByIdOrFail(id: any, opts?: FindOneOptions & FilterOptions): Promise<T>;
findOne(filter: FilterQuery<T | any>, opts?: FindOneOptions & FilterOptions): Promise<T | null>;
findOneOrFail(filter: FilterQuery<T | any>, opts?: FindOneOptions & FilterOptions): Promise<T | null>;
create(props: Partial<T>, opts?: CollectionInsertOneOptions): Promise<T>;
create(props: Partial<T>[], opts?: CollectionInsertManyOptions): Promise<T[]>;
createOne(props: Partial<T>, opts?: CollectionInsertOneOptions): Promise<T>;
createMany(props: Partial<T>[], opts?: CollectionInsertManyOptions): Promise<T[]>;
insertOne(model: OptionalId<T>, opts?: CollectionInsertOneOptions): Promise<InsertOneWriteOpResult<any>>;
insertMany(models: OptionalId<T>[], opts?: CollectionInsertManyOptions): Promise<InsertWriteOpResult<any>>;
findOneAndUpdate(filter: FilterQuery<T | any>, update: UpdateQuery<T>, opts?: FindOneAndUpdateOption & FilterOptions): Promise<T | null>;
findOneAndUpdateOrFail(filter: FilterQuery<T | any>, update: UpdateQuery<T>, opts?: FindOneAndUpdateOption & FilterOptions): Promise<T>;
findByIdAndUpdate(id: any, update: UpdateQuery<T>, opts?: FindOneAndUpdateOption & FilterOptions): Promise<T | null>;
findByIdAndUpdateOrFail(id: any, update: UpdateQuery<T>, opts?: FindOneAndUpdateOption & FilterOptions): Promise<T>;
findOneAndReplace(filter: FilterQuery<T | any>, props: OptionalId<Partial<T>>, opts?: FindOneAndReplaceOption & FilterOptions): Promise<T | null>;
findOneAndReplaceOrFail(filter: FilterQuery<T | any>, props: OptionalId<Partial<T>>, opts?: FindOneAndReplaceOption & FilterOptions): Promise<T>;
findByIdAndReplace(id: any, props: OptionalId<Partial<T>>, opts?: FindOneAndReplaceOption & FilterOptions): Promise<T | null>;
findByIdAndReplaceOrFail(id: any, props: OptionalId<Partial<T>>, opts?: FindOneAndReplaceOption & FilterOptions): Promise<T | null>;
findOneAndDelete(filter: FilterQuery<T | any>, opts?: FindOneAndDeleteOption & FilterOptions): Promise<T | null>;
findOneAndDeleteOrFail(filter: FilterQuery<T | any>, opts?: FindOneAndDeleteOption & FilterOptions): Promise<T | null>;
findByIdAndDelete(id: any, opts?: FindOneAndDeleteOption & FilterOptions): Promise<T | null>;
findByIdAndDeleteOrFail(id: any, opts?: FindOneAndDeleteOption & FilterOptions): Promise<T | null>;
updateOne(filter: FilterQuery<T | any>, update: UpdateQuery<T>, opts?: UpdateOneOptions & FilterOptions): Promise<UpdateWriteOpResult>;
updateById(id: any, update: UpdateQuery<T>, opts?: UpdateOneOptions & FilterOptions): Promise<UpdateWriteOpResult>;
updateMany(filter: FilterQuery<T | any>, update: UpdateQuery<T>, opts?: UpdateManyOptions & FilterOptions): Promise<UpdateWriteOpResult>;
updateByIds(ids: any[], update: UpdateQuery<T>, opts?: UpdateManyOptions & FilterOptions): Promise<UpdateWriteOpResult>;
replaceOne(filter: FilterQuery<T | any>, props: T | Partial<T>, opts?: ReplaceOneOptions & FilterOptions): Promise<ReplaceWriteOpResult>;
replaceById(id: any, props: Partial<T>, opts?: ReplaceOneOptions & FilterOptions): Promise<ReplaceWriteOpResult>;
deleteOne(filter: FilterQuery<T | any>, opts?: CommonOptions & {
bypassDocumentValidation?: boolean;
} & FilterOptions): Promise<boolean>;
deleteById(id: any, opts?: CommonOptions & {
bypassDocumentValidation?: boolean;
}): Promise<boolean>;
deleteMany(filter: FilterQuery<T | any>, opts?: CommonOptions & FilterOptions): Promise<DeleteWriteOpResultObject>;
deleteByIds(ids: any[], opts?: CommonOptions & FilterOptions): Promise<DeleteWriteOpResultObject>;
transformQueryFilter(input: FilterQuery<T | any>, opts?: FilterOptions): FilterQuery<any>;
protected failIfEmpty(meta: DocumentMetadata<T>, filter: FilterQuery<any>, value: any): any;
protected findOneAnd(op: 'Update' | 'Replace' | 'Delete', filter: FilterQuery<T | any>, ...args: any): Promise<T | null>;
find(query?: Filter<T | any>): FindCursor<T>;
find(query: Filter<T | any>, opts: FindOptions): FindCursor<T>;
findByIds(ids: any[]): FindCursor<T>;
findByIds(ids: any[], opts: FindOptions): FindCursor<T>;
findById(id: any, opts?: FindOptions): Promise<T | null>;
findByIdOrFail(id: any, opts?: FindOptions): Promise<T>;
findOne(filter: Filter<T | any>, opts?: FindOptions): Promise<T | null>;
findOneOrFail(filter: Filter<T | any>, opts?: FindOptions): Promise<T | null>;
create(props: Partial<T>, opts?: InsertOneOptions): Promise<T>;
create(props: Partial<T>[], opts?: BulkWriteOptions): Promise<T[]>;
createOne(props: Partial<T>, opts?: InsertOneOptions): Promise<T>;
createMany(props: Partial<T>[], opts?: BulkWriteOptions): Promise<T[]>;
insertOne(model: OptionalId<T>, opts?: InsertOneOptions): Promise<InsertOneResult<any>>;
insertMany(models: OptionalId<T>[], opts?: BulkWriteOptions): Promise<InsertManyResult<T>>;
findOneAndUpdate(filter: Filter<T | any>, update: UpdateQuery<T>, opts?: FindOneAndUpdateOptions & TransformQueryFilterOptions): Promise<T | null>;
findOneAndUpdateOrFail(filter: Filter<T | any>, update: UpdateQuery<T>, opts?: FindOneAndUpdateOptions & TransformQueryFilterOptions): Promise<T>;
findByIdAndUpdate(id: any, update: UpdateQuery<T>, opts?: FindOneAndUpdateOptions & TransformQueryFilterOptions): Promise<T | null>;
findByIdAndUpdateOrFail(id: any, update: UpdateQuery<T>, opts?: FindOneAndUpdateOptions & TransformQueryFilterOptions): Promise<T>;
findOneAndReplace(filter: Filter<T | any>, props: Partial<T>, opts?: FindOneAndReplaceOptions & TransformQueryFilterOptions): Promise<T | null>;
findOneAndReplaceOrFail(filter: Filter<T | any>, props: Partial<T>, opts?: FindOneAndReplaceOptions & TransformQueryFilterOptions): Promise<T>;
findByIdAndReplace(id: any, props: Partial<T>, opts?: FindOneAndReplaceOptions & TransformQueryFilterOptions): Promise<T | null>;
findByIdAndReplaceOrFail(id: any, props: Partial<T>, opts?: FindOneAndReplaceOptions & TransformQueryFilterOptions): Promise<T>;
findOneAndDelete(filter: Filter<T | any>, opts?: FindOneAndDeleteOptions & TransformQueryFilterOptions): Promise<T | null>;
findOneAndDeleteOrFail(filter: Filter<T | any>, opts?: FindOneAndDeleteOptions & TransformQueryFilterOptions): Promise<T>;
findByIdAndDelete(id: any, opts?: FindOneAndDeleteOptions & TransformQueryFilterOptions): Promise<T | null>;
findByIdAndDeleteOrFail(id: any, opts?: FindOneAndDeleteOptions & TransformQueryFilterOptions): Promise<T | null>;
updateOne(filter: Filter<T | any>, update: UpdateQuery<T>, opts?: UpdateOptions & TransformQueryFilterOptions): Promise<UpdateResult>;
updateById(id: any, update: UpdateQuery<T>, opts?: UpdateOptions & TransformQueryFilterOptions): Promise<UpdateResult>;
updateMany(filter: Filter<T | any>, update: UpdateQuery<T>, opts?: UpdateOptions & TransformQueryFilterOptions): Promise<UpdateResult>;
updateByIds(ids: any[], update: UpdateQuery<T>, opts?: UpdateOptions & TransformQueryFilterOptions): Promise<UpdateResult>;
replaceOne(filter: Filter<T | any>, props: Partial<T>, opts?: UpdateOptions & TransformQueryFilterOptions): Promise<UpdateResult>;
replaceById(id: any, props: Partial<T>, opts?: UpdateOptions & TransformQueryFilterOptions): Promise<UpdateResult>;
deleteOne(filter: Filter<T | any>, opts?: DeleteOptions & TransformQueryFilterOptions): Promise<boolean>;
deleteById(id: any, opts?: DeleteOptions & TransformQueryFilterOptions): Promise<boolean>;
deleteMany(filter: Filter<T | any>, opts?: DeleteOptions & TransformQueryFilterOptions): Promise<DeleteResult>;
deleteByIds(ids: any[], opts?: DeleteOptions & TransformQueryFilterOptions): Promise<DeleteResult>;
protected failIfEmpty(meta: DocumentMetadata<T>, filter: Filter<any>, value: any): any;
protected fromModifyResult(result: ModifyResult<T>): T;
}
export {};
//# sourceMappingURL=Repository.d.ts.map

@@ -98,4 +98,4 @@ "use strict";

const model = this.init(props);
const { result } = yield this.insertOne(model, opts);
return result && result.ok ? model : null;
const { acknowledged } = yield this.insertOne(model, opts);
return acknowledged ? model : null;
});

@@ -144,3 +144,3 @@ }

}
findOneAndUpdate(filter, update, opts = {}) {
findOneAndUpdate(filter, update, opts) {
return __awaiter(this, void 0, void 0, function* () {

@@ -152,7 +152,8 @@ return this.manager.eventManager.dispatchBeforeAndAfter(events_1.Events.BeforeUpdate, events_1.Events.AfterUpdate, {

}, () => __awaiter(this, void 0, void 0, function* () {
return this.findOneAnd('Update', this.transformQueryFilter(filter, opts), update, Object.assign({ returnOriginal: false }, opts));
const result = yield this.collection.findOneAndUpdate(this.transformQueryFilter(filter, opts), update, opts);
return this.fromModifyResult(result);
}));
});
}
findOneAndUpdateOrFail(filter, update, opts = {}) {
findOneAndUpdateOrFail(filter, update, opts) {
return __awaiter(this, void 0, void 0, function* () {

@@ -162,3 +163,3 @@ return this.failIfEmpty(this.metadata, filter, yield this.findOneAndUpdate(filter, update, opts));

}
findByIdAndUpdate(id, update, opts = {}) {
findByIdAndUpdate(id, update, opts) {
return __awaiter(this, void 0, void 0, function* () {

@@ -168,3 +169,3 @@ return this.findOneAndUpdate({ [this.metadata.idField.propertyName]: id }, update, opts);

}
findByIdAndUpdateOrFail(id, update, opts = {}) {
findByIdAndUpdateOrFail(id, update, opts) {
return __awaiter(this, void 0, void 0, function* () {

@@ -176,3 +177,4 @@ return this.findOneAndUpdateOrFail({ [this.metadata.idField.propertyName]: id }, update, opts);

return __awaiter(this, void 0, void 0, function* () {
return this.findOneAnd('Replace', this.transformQueryFilter(filter, opts), props, Object.assign({ returnOriginal: false }, opts));
const result = yield this.collection.findOneAndReplace(this.transformQueryFilter(filter, opts), props, opts);
return this.fromModifyResult(result);
});

@@ -200,3 +202,6 @@ }

filter
}, () => __awaiter(this, void 0, void 0, function* () { return this.findOneAnd('Delete', this.transformQueryFilter(filter, opts), opts); }));
}, () => __awaiter(this, void 0, void 0, function* () {
const result = yield this.collection.findOneAndDelete(this.transformQueryFilter(filter, opts), opts);
return this.fromModifyResult(result);
}));
});

@@ -259,3 +264,3 @@ }

delete doc._id;
return this.collection.replaceOne(this.transformQueryFilter(filter, opts), doc, opts);
return (yield this.collection.replaceOne(this.transformQueryFilter(filter, opts), doc, opts));
}));

@@ -302,12 +307,2 @@ });

}
transformQueryFilter(input, opts) {
if (typeof opts === 'object' && 'transformQueryFilter' in opts) {
const transformQueryFilter = opts.transformQueryFilter;
delete opts.transformQueryFilter;
if (transformQueryFilter === false) {
return input;
}
}
return this.metadata.transformQueryFilter(input);
}
// -------------------------------------------------------------------------

@@ -322,9 +317,6 @@ // Protected Methods

}
findOneAnd(op, filter, ...args) {
return __awaiter(this, void 0, void 0, function* () {
const result = yield this.collection[`findOneAnd${op}`].apply(this.collection, [filter, ...args]);
return result && result.ok && result.value
? this.fromDB(result.value)
: null;
});
fromModifyResult(result) {
return result && result.ok && result.value
? this.fromDB(result.value)
: null;
}

@@ -331,0 +323,0 @@ }

@@ -1,7 +0,6 @@

import { Cursor, ClientSession, FindOneOptions, FindOneAndUpdateOption, FindOneAndReplaceOption, FindOneAndDeleteOption, UpdateWriteOpResult, ReplaceWriteOpResult, DeleteWriteOpResultObject } from 'mongodb';
import { OptionalId, InsertOneWriteOpResult, CommonOptions, FilterQuery, UpdateQuery, UpdateManyOptions, UpdateOneOptions, ReplaceOneOptions, CollectionInsertOneOptions, InsertWriteOpResult, CollectionInsertManyOptions } from '../typings';
import { ClientSession, Filter, FindCursor, FindOptions, InsertOneOptions, BulkWriteOptions, InsertOneResult, InsertManyResult, FindOneAndUpdateOptions, FindOneAndReplaceOptions, FindOneAndDeleteOptions, UpdateOptions, UpdateResult, DeleteOptions, DeleteResult, OptionalId, UpdateQuery } from 'mongodb';
import { Repository } from './Repository';
import { DocumentManager } from '../DocumentManager';
import { DocumentMetadata } from '../metadata/DocumentMetadata';
import { AbstractRepository } from './AbstractRepository';
import { DocumentMetadata } from '../metadata';
import { AbstractRepository, TransformQueryFilterOptions } from './AbstractRepository';
/**

@@ -16,42 +15,40 @@ * Repository for documents

get metadata(): DocumentMetadata<T>;
find(query?: FilterQuery<T | any>, opts?: FindOneOptions): Cursor<T>;
findByIds(ids: any[], opts?: FindOneOptions): Cursor<T>;
findById(id: any, opts?: FindOneOptions): Promise<T | null>;
findByIdOrFail(id: any, opts?: FindOneOptions): Promise<T>;
findOne(filter: FilterQuery<T | any>, opts?: FindOneOptions): Promise<T | null>;
findOneOrFail(filter: FilterQuery<T | any>, opts?: FindOneOptions): Promise<T | null>;
create(props: Partial<T>, opts?: CollectionInsertOneOptions): Promise<T>;
create(props: Partial<T>[], opts?: CollectionInsertManyOptions): Promise<T[]>;
createOne(props: Partial<T>, opts?: CollectionInsertOneOptions): Promise<T>;
createMany(props: Partial<T>[], opts?: CollectionInsertManyOptions): Promise<T[]>;
insertOne(model: OptionalId<T>, opts?: CollectionInsertOneOptions): Promise<InsertOneWriteOpResult<any>>;
insertMany(models: OptionalId<T>[], opts?: CollectionInsertManyOptions): Promise<InsertWriteOpResult<any>>;
findOneAndUpdate(filter: FilterQuery<T | any>, update: UpdateQuery<T>, opts?: FindOneAndUpdateOption): Promise<T | null>;
findOneAndUpdateOrFail(filter: FilterQuery<T | any>, update: UpdateQuery<T>, opts?: FindOneAndUpdateOption): Promise<T>;
findByIdAndUpdate(id: any, update: UpdateQuery<T>, opts?: FindOneAndUpdateOption): Promise<T | null>;
findByIdAndUpdateOrFail(id: any, update: UpdateQuery<T>, opts?: FindOneAndUpdateOption): Promise<T | null>;
findOneAndReplace(filter: FilterQuery<T | any>, props: OptionalId<Partial<T>>, opts?: FindOneAndReplaceOption): Promise<T | null>;
findOneAndReplaceOrFail(filter: FilterQuery<T | any>, props: OptionalId<Partial<T>>, opts?: FindOneAndReplaceOption): Promise<T | null>;
findByIdAndReplace(id: any, props: OptionalId<Partial<T>>, opts?: FindOneAndReplaceOption): Promise<T | null>;
findByIdAndReplaceOrFail(id: any, props: OptionalId<Partial<T>>, opts?: FindOneAndReplaceOption): Promise<T | null>;
findOneAndDelete(filter: FilterQuery<T | any>, opts?: FindOneAndDeleteOption): Promise<T | null>;
findOneAndDeleteOrFail(filter: FilterQuery<T | any>, opts?: FindOneAndDeleteOption): Promise<T | null>;
findByIdAndDelete(id: any, opts?: FindOneAndDeleteOption): Promise<T | null>;
findByIdAndDeleteOrFail(id: any, opts?: FindOneAndDeleteOption): Promise<T | null>;
updateOne(filter: FilterQuery<T | any>, update: UpdateQuery<T>, opts?: UpdateOneOptions): Promise<UpdateWriteOpResult>;
updateById(id: any, update: UpdateQuery<T>, opts?: UpdateOneOptions): Promise<UpdateWriteOpResult>;
updateMany(filter: FilterQuery<T | any>, update: UpdateQuery<T>, opts?: UpdateManyOptions): Promise<UpdateWriteOpResult>;
updateByIds(ids: any[], update: UpdateQuery<T>, opts?: UpdateManyOptions): Promise<UpdateWriteOpResult>;
replaceOne(filter: FilterQuery<T | any>, props: Partial<T>, opts?: ReplaceOneOptions): Promise<ReplaceWriteOpResult>;
replaceById(id: any, props: Partial<T>, opts?: ReplaceOneOptions): Promise<ReplaceWriteOpResult>;
deleteOne(filter: FilterQuery<T | any>, opts?: CommonOptions & {
bypassDocumentValidation?: boolean;
}): Promise<boolean>;
deleteById(id: any, opts?: CommonOptions & {
bypassDocumentValidation?: boolean;
}): Promise<boolean>;
deleteMany(filter: FilterQuery<T | any>, opts?: CommonOptions): Promise<DeleteWriteOpResultObject>;
deleteByIds(ids: any[], opts?: CommonOptions): Promise<DeleteWriteOpResultObject>;
find(query?: Filter<T | any>): FindCursor<T>;
find(query: Filter<T | any>, opts: FindOptions): FindCursor<T>;
findByIds(ids: any[]): FindCursor<T>;
findByIds(ids: any[], opts: FindOptions): FindCursor<T>;
findById(id: any, opts?: FindOptions): Promise<T | null>;
findByIdOrFail(id: any, opts?: FindOptions): Promise<T>;
findOne(filter: Filter<T | any>, opts?: FindOptions): Promise<T | null>;
findOneOrFail(filter: Filter<T | any>, opts?: FindOptions): Promise<T | null>;
create(props: Partial<T>, opts?: InsertOneOptions): Promise<T>;
create(props: Partial<T>[], opts?: BulkWriteOptions): Promise<T[]>;
createOne(props: Partial<T>, opts?: InsertOneOptions): Promise<T>;
createMany(props: Partial<T>[], opts?: BulkWriteOptions): Promise<T[]>;
insertOne(model: OptionalId<T>, opts?: InsertOneOptions): Promise<InsertOneResult<any>>;
insertMany(models: OptionalId<T>[], opts?: BulkWriteOptions): Promise<InsertManyResult<T>>;
findOneAndUpdate(filter: Filter<T | any>, update: UpdateQuery<T>, opts?: FindOneAndUpdateOptions & TransformQueryFilterOptions): Promise<T | null>;
findOneAndUpdateOrFail(filter: Filter<T | any>, update: UpdateQuery<T>, opts?: FindOneAndUpdateOptions & TransformQueryFilterOptions): Promise<T>;
findByIdAndUpdate(id: any, update: UpdateQuery<T>, opts?: FindOneAndUpdateOptions & TransformQueryFilterOptions): Promise<T | null>;
findByIdAndUpdateOrFail(id: any, update: UpdateQuery<T>, opts?: FindOneAndUpdateOptions & TransformQueryFilterOptions): Promise<T>;
findOneAndReplace(filter: Filter<T | any>, props: Partial<T>, opts?: FindOneAndReplaceOptions & TransformQueryFilterOptions): Promise<T | null>;
findOneAndReplaceOrFail(filter: Filter<T | any>, props: Partial<T>, opts?: FindOneAndReplaceOptions & TransformQueryFilterOptions): Promise<T>;
findByIdAndReplace(id: any, props: Partial<T>, opts?: FindOneAndReplaceOptions & TransformQueryFilterOptions): Promise<T | null>;
findByIdAndReplaceOrFail(id: any, props: Partial<T>, opts?: FindOneAndReplaceOptions & TransformQueryFilterOptions): Promise<T>;
findOneAndDelete(filter: Filter<T | any>, opts?: FindOneAndDeleteOptions & TransformQueryFilterOptions): Promise<T | null>;
findOneAndDeleteOrFail(filter: Filter<T | any>, opts?: FindOneAndDeleteOptions & TransformQueryFilterOptions): Promise<T | null>;
findByIdAndDelete(id: any, opts?: FindOneAndDeleteOptions & TransformQueryFilterOptions): Promise<T | null>;
findByIdAndDeleteOrFail(id: any, opts?: FindOneAndDeleteOptions & TransformQueryFilterOptions): Promise<T | null>;
updateOne(filter: Filter<T | any>, update: UpdateQuery<T>, opts?: UpdateOptions & TransformQueryFilterOptions): Promise<UpdateResult>;
updateById(id: any, update: UpdateQuery<T>, opts?: UpdateOptions & TransformQueryFilterOptions): Promise<UpdateResult>;
updateMany(filter: Filter<T | any>, update: UpdateQuery<T>, opts?: UpdateOptions & TransformQueryFilterOptions): Promise<UpdateResult>;
updateByIds(ids: any[], update: UpdateQuery<T>, opts?: UpdateOptions & TransformQueryFilterOptions): Promise<UpdateResult>;
replaceOne(filter: Filter<T | any>, props: Partial<T>, opts?: UpdateOptions & TransformQueryFilterOptions): Promise<UpdateResult>;
replaceById(id: any, props: Partial<T>, opts?: UpdateOptions & TransformQueryFilterOptions): Promise<UpdateResult>;
deleteOne(filter: Filter<T | any>, opts?: DeleteOptions & TransformQueryFilterOptions): Promise<boolean>;
deleteById(id: any, opts?: DeleteOptions & TransformQueryFilterOptions): Promise<boolean>;
deleteMany(filter: Filter<T | any>, opts?: DeleteOptions & TransformQueryFilterOptions): Promise<DeleteResult>;
deleteByIds(ids: any[], opts?: DeleteOptions & TransformQueryFilterOptions): Promise<DeleteResult>;
private opts;
}
//# sourceMappingURL=TransactionRepository.d.ts.map

@@ -29,3 +29,3 @@ "use strict";

}
find(query, opts = {}) {
find(query, opts) {
return this.repository.find(query, this.opts(opts));

@@ -46,3 +46,3 @@ }

}
findOne(filter, opts = {}) {
findOne(filter, opts) {
return __awaiter(this, void 0, void 0, function* () {

@@ -82,3 +82,3 @@ return this.repository.findOne(filter, this.opts(opts));

}
findOneAndUpdate(filter, update, opts = {}) {
findOneAndUpdate(filter, update, opts) {
return __awaiter(this, void 0, void 0, function* () {

@@ -88,3 +88,3 @@ return this.repository.findOneAndUpdate(filter, update, this.opts(opts));

}
findOneAndUpdateOrFail(filter, update, opts = {}) {
findOneAndUpdateOrFail(filter, update, opts) {
return __awaiter(this, void 0, void 0, function* () {

@@ -94,3 +94,3 @@ return this.repository.findOneAndUpdateOrFail(filter, update, opts);

}
findByIdAndUpdate(id, update, opts = {}) {
findByIdAndUpdate(id, update, opts) {
return __awaiter(this, void 0, void 0, function* () {

@@ -100,3 +100,3 @@ return this.repository.findByIdAndUpdate(id, update, this.opts(opts));

}
findByIdAndUpdateOrFail(id, update, opts = {}) {
findByIdAndUpdateOrFail(id, update, opts) {
return __awaiter(this, void 0, void 0, function* () {

@@ -196,3 +196,3 @@ return this.repository.findOneAndUpdateOrFail(id, update, this.opts(opts));

}
opts(opts = {}) {
opts(opts) {
return Object.assign(Object.assign({}, opts), { session: this.session });

@@ -199,0 +199,0 @@ }

@@ -1,15 +0,5 @@

import { SessionOptions, TransactionOptions, ClientSession, MongoClient, WithTransactionCallback } from 'mongodb';
import { TransactionOptions, ClientSession, ClientSessionOptions, MongoClient, WithTransactionCallback } from 'mongodb';
import { DocumentClass } from '../typings';
import { DocumentManager } from '../DocumentManager';
import { TransactionRepository } from '../repository/TransactionRepository';
declare module 'mongodb' {
interface MongoError {
hasErrorLabel(label: string): boolean;
writeConcernError: WriteConcernError;
}
}
interface Config {
session?: SessionOptions;
transaction?: TransactionOptions;
}
export declare enum SessionState {

@@ -25,11 +15,12 @@ Pending = 0,

protected state: SessionState;
protected config: Config;
protected transactionOptions: TransactionOptions;
protected sessionOptions: ClientSessionOptions;
constructor(dm: DocumentManager);
setSessionOptions(opts: SessionOptions): this;
setSessionOptions(opts: ClientSessionOptions): this;
setTransactionOptions(opts: TransactionOptions): this;
withTransaction<T>(fn: WithTransactionCallback<T>): Promise<T>;
startSession(): ClientSession;
withTransaction<T>(fn: WithTransactionCallback<T>): Promise<T | void>;
getRepository<T>(target: DocumentClass<T>): TransactionRepository<T>;
protected assertTransactionState(state: SessionState): void;
}
export {};
//# sourceMappingURL=Session.d.ts.map

@@ -25,16 +25,15 @@ "use strict";

this.state = SessionState.Pending;
this.config = {
session: undefined,
transaction: undefined
};
this.client = dm.connection.client;
}
setSessionOptions(opts) {
this.config.session = opts;
this.sessionOptions = opts;
return this;
}
setTransactionOptions(opts) {
this.config.transaction = opts;
this.transactionOptions = opts;
return this;
}
startSession() {
return this.client.startSession(this.sessionOptions);
}
withTransaction(fn) {

@@ -46,6 +45,6 @@ return __awaiter(this, void 0, void 0, function* () {

this.state = SessionState.InProgress;
this.session = this.client.startSession();
yield this.session.withTransaction((session) => __awaiter(this, void 0, void 0, function* () {
result = yield fn(session);
}), this.config.transaction);
this.session = this.startSession();
result = yield this.session.withTransaction((session) => __awaiter(this, void 0, void 0, function* () {
return (yield fn(session));
}), this.transactionOptions);
}

@@ -57,3 +56,3 @@ catch (err) {

this.state = SessionState.Done;
this.session.endSession();
yield this.session.endSession();
}

@@ -60,0 +59,0 @@ return result;

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

import { OptionalId } from 'mongodb';
import { AbstractDocumentMetadata } from '../metadata';
import { DocumentClass, Newable, OptionalId } from '../typings';
import { DocumentClass, Newable } from '../typings';
export declare type DocumentTransformerCompiledFunction = (target: any, source: any, parent?: any) => any;

@@ -4,0 +5,0 @@ export declare class DocumentTransformer<T = any, D extends Newable = Newable<T>> {

@@ -10,3 +10,3 @@ "use strict";

var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};

@@ -13,0 +13,0 @@ Object.defineProperty(exports, "__esModule", { value: true });

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

import { Condition, FilterQuery } from 'mongodb';
import { Filter } from 'mongodb';
import { AbstractDocumentMetadata } from '../metadata';

@@ -27,7 +27,7 @@ import { Type } from '../types';

private constructor();
transform(input: FilterQuery<T>): FilterQuery<T | any>;
transform(input: Filter<T>): Filter<T | any>;
/**
* Assumes the input is a direct queriable object.
*/
transformObject(input: FilterQuery<any> | FilterQuery<any>): FilterQuery<any>;
transformObject(input: Filter<any>): Filter<any>;
/**

@@ -37,7 +37,7 @@ * Determines if the path is a query against an embedded document, a direct field,

*/
transformPath(path: string, condition: Condition<any>): [string, Condition<any>];
transformPath(path: string, condition: Filter<any>): [string, Filter<any>];
/**
* Transforms the values for the given path.
*/
transformPathValue(type: Type, value: Condition<any>): Condition<any>;
transformPathValue(type: Type, value: Filter<any>): Filter<any>;
private isOperator;

@@ -44,0 +44,0 @@ private containsOperator;

@@ -10,3 +10,3 @@ "use strict";

var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};

@@ -13,0 +13,0 @@ Object.defineProperty(exports, "__esModule", { value: true });

@@ -8,6 +8,2 @@ import { WithId } from 'mongodb';

};
/**
* Mongo Types
*/
export { Db, OptionalId, WithId, Collection, CollectionInsertManyOptions, InsertWriteOpResult, CommonOptions, CollectionInsertOneOptions, InsertOneWriteOpResult, FindOneAndDeleteOption, FindOneAndUpdateOption, FindOneAndReplaceOption, UpdateWriteOpResult, ReplaceWriteOpResult, DeleteWriteOpResultObject, FilterQuery, UpdateQuery, UpdateManyOptions, UpdateOneOptions, ReplaceOneOptions } from 'mongodb';
//# sourceMappingURL=typings.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Mongo Types
*/
var mongodb_1 = require("mongodb");
Object.defineProperty(exports, "Db", { enumerable: true, get: function () { return mongodb_1.Db; } });
//# sourceMappingURL=typings.js.map
import { DocumentClass } from '../typings';
import { DocumentDefinition, FieldDefinition, ParentDefinition, DiscriminatorDefinition } from '../metadata/definitions';
import { DocumentDefinition, FieldDefinition, ParentDefinition, DiscriminatorDefinition } from '../metadata';
declare type FieldName = string;

@@ -4,0 +4,0 @@ declare type DocumentStorage = Map<DocumentClass, DocumentDefinition>;

@@ -10,3 +10,3 @@ "use strict";

var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};

@@ -13,0 +13,0 @@ Object.defineProperty(exports, "__esModule", { value: true });

{
"name": "type-mongodb",
"version": "1.0.0-beta.15",
"version": "2.0.0-beta.0",
"description": "A simple decorator based MongoDB ODM.",

@@ -43,3 +43,2 @@ "repository": "https://github.com/j/type-mongodb",

"@types/jest": "^26.0.3",
"@types/mongodb": "3.5.25",
"@types/uuid": "^8.3.0",

@@ -49,3 +48,3 @@ "benchmark": "^2.1.4",

"jest": "^26.1.0",
"mongodb": "3.x.x",
"mongodb": "^4.0.0",
"mongodb-runner": "^4.7.2",

@@ -57,3 +56,3 @@ "prettier": "^2.0.5",

"ts-jest": "^26.1.1",
"typescript": "^3.9.5",
"typescript": "^4.2.4",
"uuid": "^8.3.2",

@@ -66,3 +65,3 @@ "uuid-mongodb": "^2.4.1"

"peerDependencies": {
"mongodb": "3.x.x",
"mongodb": "^4.0.0",
"reflect-metadata": "^0.1.13"

@@ -69,0 +68,0 @@ },

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

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

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

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

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

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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