Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
A lightweight typed MongoDb library for TypeScript.
npm i -S mongot
A collection is a class which support CRUD operations for own documents.
# UserCollection.ts
import {Collection, collection} from 'mongot';
import {UserDocument} from './UserDocument';
@collection('users', UserDocument) // bind to a document schema
class UserCollection extends Collection<UserDocument> {
findByEmail(email: string) {
return this.findOne({email});
}
}
Document schemas support following types: string
, boolean
, number
,
date
, Object
(any), SchemaFragment
(also known as subdocument),
array
type may contain any of these type.
Buffer
didn't tested at this time.
Any type can be defined via a function decorator @prop
:
@prop fieldName: string
For arrays you need pass a proto to the function decorator @prop
like as:
@prop(Date) loginDates: SchemaArray<Date> = new SchemaArray();
# UserDocument.ts
import {hook, prop, SchemaDocument} from 'mongot';
@unique({email: -1})
class UserDocument extends SchemaDocument {
@prop firstName: string;
@prop lastName: string;
@prop @req email: string;
@prop registered: Date = new Date(); // default value
@prop updated: Date;
@hook
beforeUpdate() {
this.updated = new Date();
}
get displayName() {
return this.firstName +
(this.lastName ? ' ' + this.lastName : '');
}
}
To connect your collections to MongoDb you should create a repository:
# index.ts
import {Repository} from 'mongot';
const options = {};
const repository = new Repository('mongodb://localhost/test', options);
The Repository
class constructor has same arguments that MongoClient.
Before querying you should get a collection instance via
Repository.get
.
# index.ts
async function main(): void {
const users: UserCollection = repository.get(UserCollection);
const user = await users.findByEmail('username@example.com');
// do something
...
}
Coming soon... maybe
You can if you know how it cook.
MIT
FAQs
MongoT is a modern ODM library for MongoDb.
The npm package mongot receives a total of 9 weekly downloads. As such, mongot popularity was classified as not popular.
We found that mongot 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
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.