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

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.13 to 1.0.0-beta.14

lib/metadata/index.d.ts

2

lib/DocumentManager.js

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

const Session_1 = require("./transaction/Session");
const DocumentTransformer_1 = require("./document/DocumentTransformer");
const DocumentTransformer_1 = require("./transformer/DocumentTransformer");
const errors_1 = require("./errors");

@@ -20,0 +20,0 @@ const defaultContainer = {

import { FilterQuery } from '../typings';
import { DocumentMetadata } from '../metadata/DocumentMetadata';
import { DocumentMetadata } from '../metadata';
import { Mode, Type } from '../types';

@@ -4,0 +4,0 @@ export declare class InternalError extends Error {

@@ -56,12 +56,6 @@ "use strict";

static documentNotFound(meta, filter) {
let message;
if (filter &&
Object.keys(filter).length === 1 &&
typeof filter._id !== 'undefined') {
message = `"${meta.name}" with id "${filter._id}" not found`;
}
else {
message = `"${meta.name}" not found with criteria: '${JSON.stringify(filter)}'`;
}
this.throw(message, { code: 'DOCUMENT_NOT_FOUND' });
this.throw(`"${meta.name}" not found`, {
code: 'DOCUMENT_NOT_FOUND',
filter
});
}

@@ -68,0 +62,0 @@ }

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

import { FilterQuery } from 'mongodb';
import { Newable, OptionalId } from '../typings';
import { FieldMetadata } from './FieldMetadata';
import { DocumentTransformer } from '../document/DocumentTransformer';
import { ParentDefinition } from './definitions';
import { DiscriminatorMetadata } from './DiscriminatorMetadata';
import { DocumentTransformer, QueryFilterTransformer } from '../transformer';
export declare type FieldsMetadata = Map<string, FieldMetadata>;

@@ -16,5 +17,6 @@ /**

readonly idField: FieldMetadata;
readonly transformer: DocumentTransformer;
readonly parent?: ParentDefinition;
readonly discriminator?: DiscriminatorMetadata;
readonly documentTransformer: DocumentTransformer<T, D>;
readonly queryFilterTransformer: QueryFilterTransformer<T>;
constructor(DocumentClass: D, fields: FieldsMetadata, parent?: ParentDefinition, discriminator?: DiscriminatorMetadata);

@@ -36,3 +38,3 @@ /**

*/
fromDB(doc: Partial<T> | {
fromDB(doc: Partial<D> | {
[key: string]: any;

@@ -52,3 +54,7 @@ }): T;

}): T;
/**
* Transforms query filters.
*/
transformQueryFilter(input: FilterQuery<T>): FilterQuery<any>;
}
//# sourceMappingURL=AbstractDocumentMetadata.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AbstractDocumentMetadata = void 0;
const DocumentTransformer_1 = require("../document/DocumentTransformer");
const errors_1 = require("../errors");
const transformer_1 = require("../transformer");
/**

@@ -17,5 +17,6 @@ * AbstractDocumentMetadata contains all the needed info for Document and embedded

this.discriminator = discriminator;
this.transformer = DocumentTransformer_1.DocumentTransformer.create(this);
this.documentTransformer = transformer_1.DocumentTransformer.create(this);
this.queryFilterTransformer = transformer_1.QueryFilterTransformer.create(this);
// set the idField property if it exists
this.idField = this.fields.get('_id');
this.idField = [...this.fields.values()].find((f) => f.fieldName === '_id');
if (

@@ -36,3 +37,3 @@ // root documents must have an `_id` field

toDB(model) {
return this.transformer.toDB(model);
return this.documentTransformer.toDB(model);
}

@@ -43,3 +44,3 @@ /**

fromDB(doc) {
return this.transformer.fromDB(doc);
return this.documentTransformer.fromDB(doc);
}

@@ -50,3 +51,3 @@ /**

init(props) {
return this.transformer.init(props);
return this.documentTransformer.init(props);
}

@@ -57,6 +58,12 @@ /**

merge(model, props) {
return this.transformer.merge(model, props);
return this.documentTransformer.merge(model, props);
}
/**
* Transforms query filters.
*/
transformQueryFilter(input) {
return this.queryFilterTransformer.transform(input);
}
}
exports.AbstractDocumentMetadata = AbstractDocumentMetadata;
//# sourceMappingURL=AbstractDocumentMetadata.js.map
import { Collection, Db } from 'mongodb';
import { DocumentClass } from '../typings';
import { Newable } from '../typings';
import { AbstractDocumentMetadata, FieldsMetadata } from './AbstractDocumentMetadata';
import { Connection } from '../connection/Connection';
import { Repository } from '../repository/Repository';
export interface DocumentMetadataOpts<T = any> {
DocumentClass: DocumentClass<T>;
import { DocumentManager } from '../DocumentManager';
export interface DocumentMetadataOpts<T = any, D extends Newable = Newable<T>> {
DocumentClass: D;
fields: FieldsMetadata;

@@ -18,3 +19,4 @@ connection: Connection;

*/
export declare class DocumentMetadata<T = any> extends AbstractDocumentMetadata<T, DocumentClass> {
export declare class DocumentMetadata<T = any, D extends Newable = Newable<T>> extends AbstractDocumentMetadata<T, D> {
readonly dm: DocumentManager;
readonly connection: Connection;

@@ -25,5 +27,5 @@ readonly db: Db;

readonly repository: Repository<T>;
constructor(opts: DocumentMetadataOpts<T>);
constructor(opts: DocumentMetadataOpts<T, D>);
isRoot(): boolean;
}
//# sourceMappingURL=DocumentMetadata.d.ts.map

@@ -15,6 +15,5 @@ "use strict";

const FieldMetadata_1 = require("./FieldMetadata");
const definitionStorage_1 = require("../utils/definitionStorage");
const utils_1 = require("../utils");
const EmbeddedDocumentMetadata_1 = require("./EmbeddedDocumentMetadata");
const repository_1 = require("../repository");
const isPromise_1 = require("../utils/isPromise");
const DiscriminatorMetadata_1 = require("./DiscriminatorMetadata");

@@ -109,6 +108,6 @@ const errors_1 = require("../errors");

return __awaiter(this, void 0, void 0, function* () {
if (!definitionStorage_1.definitionStorage.documents.has(DocumentClass)) {
if (!utils_1.definitionStorage.documents.has(DocumentClass)) {
errors_1.InternalError.throw(`"${DocumentClass.name}" is not a decorated @Document()`);
}
const def = definitionStorage_1.definitionStorage.documents.get(DocumentClass);
const def = utils_1.definitionStorage.documents.get(DocumentClass);
const connection = this.opts.dm.connection;

@@ -118,3 +117,3 @@ const db = connection.getDatabase(connection, def.database);

const repositoryOrPromise = this.opts.dm.container.get(RepositoryClass);
const repository = isPromise_1.isPromise(repositoryOrPromise)
const repository = utils_1.isPromise(repositoryOrPromise)
? yield repositoryOrPromise

@@ -148,6 +147,6 @@ : repositoryOrPromise;

fields = fields || new Map();
if (definitionStorage_1.definitionStorage.fields.has(target)) {
definitionStorage_1.definitionStorage.fields.get(target).forEach((prop) => {
if (utils_1.definitionStorage.fields.has(target)) {
utils_1.definitionStorage.fields.get(target).forEach((prop) => {
if (!prop.isEmbedded) {
fields.set(prop.fieldName, new FieldMetadata_1.FieldMetadata(Object.assign(Object.assign({}, prop), { isEmbeddedArray: false })));
fields.set(prop.propertyName, new FieldMetadata_1.FieldMetadata(Object.assign(Object.assign({}, prop), { isEmbeddedArray: false })));
}

@@ -161,3 +160,3 @@ else {

const embeddedMetadata = this.buildEmbeddedDocumentMetadata(embeddedType);
fields.set(prop.fieldName, new FieldMetadata_1.FieldMetadata(Object.assign(Object.assign({}, prop), { isEmbeddedArray,
fields.set(prop.propertyName, new FieldMetadata_1.FieldMetadata(Object.assign(Object.assign({}, prop), { isEmbeddedArray,
embeddedMetadata,

@@ -171,3 +170,3 @@ embeddedType })));

while (proto && proto.prototype) {
if (definitionStorage_1.definitionStorage.fields.has(proto)) {
if (utils_1.definitionStorage.fields.has(proto)) {
this.buildFields(proto, fields);

@@ -179,4 +178,4 @@ }

// make the error more clear for discriminator mapped classes
if (definitionStorage_1.definitionStorage.discriminators.has(target)) {
DiscriminatorMetadata_1.DiscriminatorMetadata.assertValid(definitionStorage_1.definitionStorage.discriminators.get(target));
if (utils_1.definitionStorage.discriminators.has(target)) {
DiscriminatorMetadata_1.DiscriminatorMetadata.assertValid(utils_1.definitionStorage.discriminators.get(target));
}

@@ -188,4 +187,4 @@ errors_1.InternalError.throw(`"${target.name}" does not have any fields`);

locateParentDefinition(target) {
if (definitionStorage_1.definitionStorage.parents.get(target)) {
return definitionStorage_1.definitionStorage.parents.get(target);
if (utils_1.definitionStorage.parents.get(target)) {
return utils_1.definitionStorage.parents.get(target);
}

@@ -195,4 +194,4 @@ // locate inherited `Parent()`

while (proto && proto.prototype) {
if (definitionStorage_1.definitionStorage.parents.get(proto)) {
return definitionStorage_1.definitionStorage.parents.get(proto);
if (utils_1.definitionStorage.parents.get(proto)) {
return utils_1.definitionStorage.parents.get(proto);
}

@@ -203,6 +202,6 @@ proto = Object.getPrototypeOf(proto);

buildDiscriminatorMetadata(target) {
if (!definitionStorage_1.definitionStorage.discriminators.has(target)) {
if (!utils_1.definitionStorage.discriminators.has(target)) {
return;
}
const def = definitionStorage_1.definitionStorage.discriminators.get(target);
const def = utils_1.definitionStorage.discriminators.get(target);
const map = new Map();

@@ -209,0 +208,0 @@ Object.keys(def.map).forEach((type) => {

@@ -1,6 +0,5 @@

import { Cursor } from 'mongodb';
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 { DocumentMetadata } from '../metadata';
import { DocumentManager } from '../DocumentManager';
import { FindOneOptions, FindOneAndUpdateOption, FindOneAndReplaceOption, FindOneAndDeleteOption, UpdateWriteOpResult, ReplaceWriteOpResult, DeleteWriteOpResultObject } from 'mongodb';
import { Type } from '../types';

@@ -7,0 +6,0 @@ /**

@@ -6,2 +6,5 @@ import { Cursor, FindOneOptions, FindOneAndUpdateOption, FindOneAndReplaceOption, FindOneAndDeleteOption, UpdateWriteOpResult, ReplaceWriteOpResult, DeleteWriteOpResultObject } from 'mongodb';

import { AbstractRepository } from './AbstractRepository';
interface FilterOptions {
transformQueryFilter?: boolean;
}
/**

@@ -33,9 +36,9 @@ * Repository for documents

find(query?: FilterQuery<T | any>): Cursor<T>;
find(query: FilterQuery<T | any>, opts: FindOneOptions): Cursor<T>;
find(query: FilterQuery<T | any>, opts: FindOneOptions & FilterOptions): Cursor<T>;
findByIds(ids: any[]): 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>;
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>;

@@ -47,31 +50,33 @@ create(props: Partial<T>[], opts?: CollectionInsertManyOptions): Promise<T[]>;

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>;
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>;
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: T | Partial<T>, opts?: ReplaceOneOptions): Promise<ReplaceWriteOpResult>;
replaceById(id: any, props: Partial<T>, opts?: ReplaceOneOptions): Promise<ReplaceWriteOpResult>;
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;
}): Promise<boolean>;
} & FilterOptions): 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>;
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>;
}
export {};
//# sourceMappingURL=Repository.d.ts.map

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

find(query, opts) {
const cursor = this.collection.find(query, opts);
const cursor = this.collection.find(this.transformQueryFilter(query, opts), opts);
cursor.map((doc) => this.fromDB(doc));

@@ -66,9 +66,7 @@ return cursor;

findByIds(ids, opts) {
return this.find({
_id: { $in: ids.map((id) => this.id.convertToDatabaseValue(id)) }
}, opts);
return this.find({ [this.metadata.idField.propertyName]: { $in: ids } }, opts);
}
findById(id, opts) {
return __awaiter(this, void 0, void 0, function* () {
return this.findOne({ _id: this.id.convertToDatabaseValue(id) }, opts);
return this.findOne({ [this.metadata.idField.propertyName]: id }, opts);
});

@@ -78,3 +76,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
return this.failIfEmpty(this.metadata, { _id: id }, yield this.findById(id, opts));
return this.failIfEmpty(this.metadata, { [this.metadata.idField.propertyName]: id }, yield this.findById(id, opts));
});

@@ -84,3 +82,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
const found = yield this.collection.findOne(filter, opts);
const found = yield this.collection.findOne(this.transformQueryFilter(filter, opts), opts);
return found ? this.fromDB(found) : null;

@@ -129,5 +127,6 @@ });

const docs = models.map((model) => this.toDB(model));
const idProp = this.metadata.idField.propertyName;
models.forEach((model) => {
if (!model._id) {
model._id = this.id.createJSValue();
if (idProp && !model[idProp]) {
model[idProp] = this.id.createJSValue();
}

@@ -156,3 +155,3 @@ beforeInsertEvents.push(this.manager.eventManager.dispatch(events_1.Events.BeforeInsert, {

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

@@ -168,3 +167,3 @@ });

return __awaiter(this, void 0, void 0, function* () {
return this.findOneAndUpdate({ _id: this.id.convertToDatabaseValue(id) }, update, opts);
return this.findOneAndUpdate({ [this.metadata.idField.propertyName]: id }, update, opts);
});

@@ -174,3 +173,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
return this.findOneAndUpdateOrFail({ _id: this.id.convertToDatabaseValue(id) }, update, opts);
return this.findOneAndUpdateOrFail({ [this.metadata.idField.propertyName]: id }, update, opts);
});

@@ -180,3 +179,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
return this.findOneAnd('Replace', filter, props, Object.assign({ returnOriginal: false }, opts));
return this.findOneAnd('Replace', this.transformQueryFilter(filter, opts), props, Object.assign({ returnOriginal: false }, opts));
});

@@ -186,3 +185,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
return this.failIfEmpty(this.metadata, filter, yield this.findOneAndReplaceOrFail(filter, props, opts));
return this.failIfEmpty(this.metadata, filter, yield this.findOneAndReplace(filter, props, opts));
});

@@ -192,3 +191,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
return this.findOneAndReplace({ _id: this.id.convertToDatabaseValue(id) }, props, opts);
return this.findOneAndReplace({ [this.metadata.idField.propertyName]: id }, props, opts);
});

@@ -198,3 +197,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
return this.findOneAndReplaceOrFail({ _id: this.id.convertToDatabaseValue(id) }, props, opts);
return this.findOneAndReplaceOrFail({ [this.metadata.idField.propertyName]: id }, props, opts);
});

@@ -207,3 +206,3 @@ }

filter
}, () => __awaiter(this, void 0, void 0, function* () { return this.findOneAnd('Delete', filter, opts); }));
}, () => __awaiter(this, void 0, void 0, function* () { return this.findOneAnd('Delete', this.transformQueryFilter(filter, opts), opts); }));
});

@@ -218,3 +217,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
return this.findOneAndDelete({ _id: this.id.convertToDatabaseValue(id) }, opts);
return this.findOneAndDelete({ [this.metadata.idField.propertyName]: id }, opts);
});

@@ -224,3 +223,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
return this.findOneAndDeleteOrFail({ _id: this.id.convertToDatabaseValue(id) }, opts);
return this.findOneAndDeleteOrFail({ [this.metadata.idField.propertyName]: id }, opts);
});

@@ -234,3 +233,3 @@ }

update
}, () => this.collection.updateOne(filter, update, opts));
}, () => this.collection.updateOne(this.transformQueryFilter(filter, opts), update, opts));
});

@@ -240,3 +239,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
return this.updateOne({ _id: this.id.convertToDatabaseValue(id) }, update, opts);
return this.updateOne({ [this.metadata.idField.propertyName]: id }, update, opts);
});

@@ -250,3 +249,3 @@ }

update
}, () => this.collection.updateMany(filter, update, opts));
}, () => this.collection.updateMany(this.transformQueryFilter(filter, opts), update, opts));
});

@@ -256,3 +255,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
return this.updateMany({ _id: { $in: ids.map((id) => this.id.convertToDatabaseValue(id)) } }, update, opts);
return this.updateMany({ [this.metadata.idField.propertyName]: { $in: ids } }, update, opts);
});

@@ -272,3 +271,3 @@ }

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

@@ -279,3 +278,3 @@ });

return __awaiter(this, void 0, void 0, function* () {
return this.replaceOne({ _id: this.id.convertToDatabaseValue(id) }, props, opts);
return this.replaceOne({ [this.metadata.idField.propertyName]: id }, props, opts);
});

@@ -289,3 +288,3 @@ }

}, () => __awaiter(this, void 0, void 0, function* () {
const result = yield this.collection.deleteOne(filter, opts);
const result = yield this.collection.deleteOne(this.transformQueryFilter(filter, opts), opts);
return result && result.deletedCount === 1;

@@ -297,3 +296,3 @@ }));

return __awaiter(this, void 0, void 0, function* () {
return this.deleteOne({ _id: this.id.convertToDatabaseValue(id) }, opts);
return this.deleteOne({ [this.metadata.idField.propertyName]: id }, opts);
});

@@ -306,3 +305,3 @@ }

filter
}, () => this.collection.deleteMany(filter, opts));
}, () => this.collection.deleteMany(this.transformQueryFilter(filter, opts), opts));
});

@@ -312,5 +311,19 @@ }

return __awaiter(this, void 0, void 0, function* () {
return this.deleteMany({ _id: { $in: ids.map((id) => this.id.convertToDatabaseValue(id)) } }, opts);
return this.deleteMany({
[this.metadata.idField.propertyName]: {
$in: ids.map((i) => this.id.convertToDatabaseValue(i))
}
}, Object.assign(Object.assign({}, opts), { transformQueryFilter: false }));
});
}
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);
}
// -------------------------------------------------------------------------

@@ -317,0 +330,0 @@ // Protected Methods

import { WithId } from 'mongodb';
export declare type DocumentClass<T = any> = Newable<WithId<T>>;
export declare type DocumentClass<T = any> = Newable<T>;
export declare type DocumentInstance<T = any> = WithId<T>;

@@ -4,0 +4,0 @@ export declare type Newable<T = any> = new (...args: any[]) => T;

{
"name": "type-mongodb",
"version": "1.0.0-beta.13",
"version": "1.0.0-beta.14",
"description": "A simple decorator based MongoDB ODM.",

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

"typescript": "^3.9.5",
"uuid": "^8.3.2"
"uuid": "^8.3.2",
"uuid-mongodb": "^2.4.1"
},

@@ -59,0 +60,0 @@ "optionalDependencies": {

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