
Research
Malicious fezbox npm Package Steals Browser Passwords from Cookies via Innovative QR Code Steganographic Technique
A malicious package uses a QR code as steganography in an innovative technique.
Mongoose-based ODM inspired by Hibernate and TypeORM
First, install reflect metadata and monbernate via npm
npm install reflect-metadata monbernate
Add string below in the top of main app file (main.ts, for example)
import 'reflect-metadata';
Add flags "experimentalDecorators": true
and "emitDecoratorMetadata": true
in tsconfig.json
file
Declare database repositories, as in example below
import { RecursivePopulateRepository, Repository } from '../../src';
import { Entity } from '../constants/enums';
import { userModel } from '../models';
import { RecursivelyPopulatedUser } from '../types/recursive-populate';
import { IUserDocument, IUserPopulated } from '../types/user';
import { EntityNotFoundError } from '../errors/entity-not-found.error';
@Repository({
entityName: Entity.USER,
getModel: () => userModel,
entityType: Entity.USER,
notFoundErrorClass: EntityNotFoundError,
})
export class UserRepository extends RecursivePopulateRepository<
IUserDocument,
IUserPopulated,
RecursivelyPopulatedUser
> {}
Then use declared repositories in app
const user: IUserDocument = await userRepository.save({ email: 'admin@gmail.com' });
const userAmount: number = await userRepository.count({ email: 'admin@gmail.com' });
Get all entities:
const allUsers: LeanDocument<IUserDocument>[] = await userRepository.get();
Get entities by filter conditions:
const byFirstName: LeanDocument<IUserDocument>[] = await userRepository.get({
firstName: 'admin',
});
Get only needed fields (using projection):
const onlyFirstName: { firstName: string }[] = await userRepository.get(
{},
{ firstName: true, _id: false },
);
Get all entities with all fields and limit=100, skip=20 and desc sorting by email field:
const withAdditionalParams: LeanDocument<IUserDocument>[] = await userRepository.get(
{},
{},
100,
20,
{ email: -1 },
);
const emails: string[] = await userRepository.distinct({}, 'email');
const isExists: boolean = await userRepository.isExists({ email: 'admin@gmail.com' });
const isExistsWithId: boolean = await userRepository.isExistsWithId('123');
const byId: LeanDocument<IUserDocument> = await userRepository.getById('123');
const byIdNullable: LeanDocument<IUserDocument> | null = await userRepository.getByIdOrNull(
'123',
);
const getOne: LeanDocument<IUserDocument> = await userRepository.getOne({ firstName: 'admin' });
const getOneNullable: LeanDocument<IUserDocument> | null = await userRepository.getOneOrNull({
firstName: 'admin',
});
const updateById: LeanDocument<IUserDocument> = await userRepository.updateById('123', {
email: 'admin@gmail.com',
});
const updateByIdNullable: LeanDocument<IUserDocument> | null =
await userRepository.updateByIdOrReturnNull('123', {
email: 'admin@gmail.com',
});
const updateOne: LeanDocument<IUserDocument> = await userRepository.updateOne(
{ email: 'user@gmail.com' },
{ email: 'admin@gmail.com' },
);
const updateOneNullable: LeanDocument<IUserDocument> | null =
await userRepository.updateOneOrReturnNull(
{ email: 'user@gmail.com' },
{ email: 'admin@gmail.com' },
);
await userRepository.updateMany({ firstName: 'admin' }, { firstName: 'user' });
await userRepository.deleteMany({ firstName: 'admin' });
const deleteById: LeanDocument<IUserDocument> = await userRepository.deleteById('123');
const deleteByIdNullable: LeanDocument<IUserDocument> | null =
await userRepository.deleteByIdOrReturnNull('123');
const byId: Omit<IUserPopulated, 'todos'> & {
todos: Pick<ITodo, 'comments'>;
} = await userRepository.getPartiallyPopulatedById('123', {
__all: true, // grab all non-populate fields
todos: { comments: true },
});
const byIdNullable: Pick<IUserPopulated, 'todos'> | null =
await userRepository.getPartiallyPopulatedByIdOrReturnNull('123', { todos: null });
const getOne: Omit<IUserPopulated, 'todos'> & {
todos: Pick<ITodo, 'comments'>;
} = await userRepository.getOnePartiallyPopulated({ email: 'admin@gmail.com' }, {
__all: true, // grab all non-populate fields
todos: { comments: 1 },
});
const getOneNullable: { todos: MongoId[] } | null =
await userRepository.getOnePartiallyPopulatedOrReturnNull(
{
email: 'admin@gmail.com',
},
{ todos: true },
);
const users: Pick<IUserPopulated, 'firstName' | 'todos'>[] =
await userRepository.getPartiallyPopulated(
{ email: 'admin@gmail.com' },
{ firstName: true, email: 0, lastName: false, todos: null },
100,
20,
{ email: 1 },
);
const updateById: Pick<IUserPopulated, 'todos'> =
await userRepository.updatePartiallyPopulatedById(
'123',
{ firstName: 'admin' },
{ todos: null },
);
const updateByIdNullable: Pick<IUserPopulated, 'todos'> | null =
await userRepository.updatePartiallyPopulatedByIdOrReturnNull(
'123',
{ firstName: 'admin' },
{ todos: null },
);
const updateOne: Pick<IUserPopulated, 'todos'> = await userRepository.updateOnePartiallyPopulated(
{ email: 'admin@gmail.com' },
{ firstName: 'admin' },
{ todos: null },
);
const updateOneNullable: Pick<IUserPopulated, 'todos'> | null =
await userRepository.updateOnePartiallyPopulatedOrReturnNull(
{ email: 'admin@gmail.com' },
{ firstName: 'admin' },
{ todos: null },
);
Methods similar like in PartialPopulateRepository
, but populate object is more deeper
type Return = Omit<RecursivelyPopulatedUser, 'todos'> & {
todos: Pick<ITodo, 'text'> & {
comments: {
author: Pick<IUser, 'email' | 'todos'>;
};
};
};
const users: Return[] = await userRepository.getRecursivelyPopulated(
{},
{
__all: true,
todos: {
text: true,
comments: {
author: {
email: true,
todos: true,
},
},
},
},
);
const repository: CommentRepository | TodoRepository = todoOrCommentRepository.byEntityType(
Entity.COMMENT,
);
const commentsAmount: number = await repository.count({});
FAQs
Mongoose-based ODM inspired by Hibernate and TypeORM
The npm package monbernate receives a total of 0 weekly downloads. As such, monbernate popularity was classified as not popular.
We found that monbernate demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.
Application Security
/Research
/Security News
Socket detected multiple compromised CrowdStrike npm packages, continuing the "Shai-Hulud" supply chain attack that has now impacted nearly 500 packages.