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

leafodm

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

leafodm - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

src/types/index.ts

5

package.json
{
"name": "leafodm",
"version": "1.0.0",
"version": "1.0.1",
"description": "MongoDB abstraction layer in TypeScript",

@@ -15,3 +15,4 @@ "scripts": {

"mongodb": "^3.6.9",
"reflect-metadata": "^0.1.13"
"reflect-metadata": "^0.1.13",
"utility-types": "^3.10.0"
},

@@ -18,0 +19,0 @@ "devDependencies": {

7

README.md
# Leaf ODM
[![npm](https://img.shields.io/npm/v/leafodm)](https://www.npmjs.com/package/leafodm)
![npm type definitions](https://img.shields.io/npm/types/leafodm)
Leaf ODM is an abstraction layer for MongoDB on NodeJS. It aims to provide a better class support for MongoDB while keeping it's schema-less feature.

@@ -93,4 +96,2 @@

user.name = 'John Doe Jr'
await user.delete()

@@ -118,3 +119,3 @@ ```

This library is very useful when combined with [`class-transformer`](https://github.com/typestack/class-transformer/) and [`class-validator`](https://github.com/typestack/class-validator),
no need to instance your model and write date to every fields.
no need to instance your model and write data to every fields.
Here is an example with the web framework [FoalTS](http://foalts.org/):

@@ -121,0 +122,0 @@ ```ts

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

import { ObjectID, WithoutProjection, FindOneOptions, Collection } from 'mongodb';
import { classToPlain, plainToClass, Type } from 'class-transformer';
import { classToPlain, plainToClass, plainToClassFromExist, Type } from 'class-transformer';
import { Collection, FindOneOptions, ObjectID, WithoutProjection } from 'mongodb';
import { DatabaseManager } from '../manager';
import { Filter } from '../typings/query';
import { Filter, PropertySorting } from '../types';

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

/**
* Force schema-less structure
* Allow schema-less
*/
[key: string]: any;
[key: string]: unknown

@@ -38,2 +38,10 @@ /**

/**
*
* @param { object } data
*/
constructor(data?: Record<string, unknown>) {
Object.assign(this, data)
}
/**
* Get repository from collection

@@ -89,3 +97,3 @@ *

*/
public static sortBy<T extends typeof BaseEntity>(this: T, sort: { [K in keyof Partial<T['prototype']>]: ('ASC' | 'DESC') }): T {
public static sortBy<T extends typeof BaseEntity>(this: T, sort: PropertySorting<T>): T {
this._sort = {};

@@ -142,3 +150,3 @@

return plainToClass(this, result);
return plainToClassFromExist(new this, result)
}

@@ -200,2 +208,2 @@

}
}
}
export * from './entity';
export * from './typings';
export * from './types';
export { DatabaseManager } from './manager';

@@ -19,2 +19,15 @@ import { BaseEntity } from '../src/entity/base'

describe('Entity', () => {
test('should create object with already existing data', () => {
const data = {
name: 'John Doe',
email: 'john.doe@example.org'
}
const user = new User(data)
expect(user.name).toBe('John Doe')
expect(user.email).toBe('john.doe@example.org')
expect(user.password).toBeUndefined()
})
test('should create an object', async () => {

@@ -65,3 +78,4 @@ const user = new User()

const users = await User.sortBy({
name: 'DESC'
name: 'DESC',
}).find()

@@ -90,2 +104,3 @@

expect(user?.name).toBe('John Doe')
expect(user).toBeInstanceOf(User)
})

@@ -92,0 +107,0 @@

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