An open API service indexing awesome lists of open source software.

https://github.com/secjs/base

📐 Base classes with prebuild methods for Node.js
https://github.com/secjs/base

base nodejs prebuild

Last synced: about 1 month ago
JSON representation

📐 Base classes with prebuild methods for Node.js

Awesome Lists containing this project

README

        

# Base 📐

> Base stuffs for any NodeJS project

[![GitHub followers](https://img.shields.io/github/followers/jlenon7.svg?style=social&label=Follow&maxAge=2592000)](https://github.com/jlenon7?tab=followers)
[![GitHub stars](https://img.shields.io/github/stars/secjs/base.svg?style=social&label=Star&maxAge=2592000)](https://github.com/secjs/base/stargazers/)


Buy Me A Coffee


GitHub language count

Repository size

License

Commitizen

The intention behind this repository is to always maintain a `Base` project to any NodeJS project.

## Installation

> To use the high potential from this package you need to install first this other packages from SecJS,
> it keeps as dev dependency because one day `@secjs/core` will install everything once.

```bash
npm install @secjs/contracts @secjs/exceptions @secjs/utils
```

> Then you can install the package using:

```bash
npm install @secjs/base
```

### BaseService

> Use to get nice methods to use with @secjs/base repositories

```ts
import { User } from 'app/Models/User'
import { NotFoundException } from '@nestjs/common'
import { BaseService } from '@secjs/base/services/BaseService'
import { ContactResource } from 'app/Resources/ContactResource'
import { ContactRepository } from 'app/Repositories/ContactRepository'

class ContactService extends BaseService {
protected resourceName = 'contact'
protected resource = new ContactResource()
protected repository = new ContactRepository()
protected NotFoundException: any = NotFoundException // Define exception or use NotFoundException default from @secjs/exceptions

// You can subscribe BaseService methods in here if you want!
}
```

---

### LucidRepository

> Use LucidRepository to get nice methods based on ApiRequestContract

```ts
import { User } from 'app/Models/User'
import { LucidRepository } from '@secjs/base/repositories/LucidRepository'

class UserRepository extends LucidRepository {
model = User // Give the Model value to Lucid, so he knows what to work with.

wheres = ['id', 'name'] // What wheres can be executed by client
relations = ['contacts'] // What relations can be get by client

// Both, wheres and relations will only work for external requests.

// You can subscribe LucidRepository methods in here if you want!
}
```

---

### TypeOrmRepository

> Use TypeOrmRepository to get nice methods based on ApiRequestContract

```ts
import { User } from 'app/Models/User'
import { TypeOrmRepository } from '@secjs/base/repositories/TypeOrmRepository'

class UserRepository extends TypeOrmRepository {
model = User // Give the Model value to Lucid, so he knows what to work with.

wheres = ['id', 'name'] // What wheres can be executed by client
relations = ['contacts'] // What relations can be get by client

// Both, wheres and relations will only work for external requests.

// You can subscribe TypeOrmRepository methods in here if you want!
}
```

---

### MongooseRepository

> Use MongooseRepository to get nice methods based on ApiRequestContract

```ts
import { User, UserDocument } from 'app/Schemas/User'
import { MongooseRepository } from '@secjs/base/repositories/MongooseRepository'

class UserRepository extends MongooseRepository {
model = User // Give the Model value to Mongoose, so he knows what to work with.

wheres = ['id', 'name'] // What wheres can be executed by client
relations = ['contacts'] // What relations can be get by client

// Both, wheres and relations will only work for external requests.

// You can subscribe MongooseRepository methods in here if you want!
}
```

---

### PrismaRepository

> Use PrismaRepository to get nice methods based on ApiRequestContract

```ts
import { User } from 'app/Models/User'
import { PrismaRepository } from '@secjs/base/repositories/PrismaRepository'

class UserRepository extends PrismaRepository {
model = User // Give the Model value to Lucid, so he knows what to work with.

wheres = ['id', 'name'] // What wheres can be executed by client
relations = ['contacts'] // What relations can be get by client

// Both, wheres and relations will only work for external requests.

// You can subscribe PrismaRepository methods in here if you want!
}
```

---

## License

Made with 🖤 by [jlenon7](https://github.com/jlenon7) :wave: