# @mahdi.js/macore

> macore is a nodejs core using typescript and express

Latest version **0.0.7** (published 2021-02-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install @mahdi.js/macore
pnpm add @mahdi.js/macore
yarn add @mahdi.js/macore
bun add @mahdi.js/macore
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2021-02-19 |
| First published | 2021-02-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 18 |
| Unpacked size | 106 KB |
| Known vulnerabilities | 0 (+32 in 3 direct dependencies) |
| Install scripts | no |
| Author | mahdi.js |
| Maintainers | mahdi.js |
| Keywords | nodejs framework, web framework, nodejs orm, orm, typescript orm, node.js library, node.js orm, mongo orm, mahdi pakravan, mahdipakravan |

## Links

- npm: https://www.npmjs.com/package/@mahdi.js/macore
- Repository: https://github.com/engpakravan/macore
- Issues: https://github.com/engpakravan/macore/issues
- npm.io page: https://npm.io/package/@mahdi.js/macore

## Dependencies (18)

- [ejs](https://npm.io/package/ejs.md) ^3.1.6
- [pad](https://npm.io/package/pad.md) ^3.2.0
- [axios](https://npm.io/package/axios.md) ^0.21.1
- [chalk](https://npm.io/package/chalk.md) ^4.1.0
- [config](https://npm.io/package/config.md) ^3.3.3
- [dotenv](https://npm.io/package/dotenv.md) ^8.2.0
- [express](https://npm.io/package/express.md) ^4.17.1
- [i18next](https://npm.io/package/i18next.md) ^19.8.9
- [inquirer](https://npm.io/package/inquirer.md) ^7.3.3
- [mongoose](https://npm.io/package/mongoose.md) 5.5.2
- [commander](https://npm.io/package/commander.md) ^7.0.0
- [body-parser](https://npm.io/package/body-parser.md) ^1.19.0
- [cookie-parser](https://npm.io/package/cookie-parser.md) ^1.4.5
- [class-validator](https://npm.io/package/class-validator.md) ^0.13.1
- [express-session](https://npm.io/package/express-session.md) ^1.17.1
- [class-transformer](https://npm.io/package/class-transformer.md) ^0.3.2
- [i18next-express-middleware](https://npm.io/package/i18next-express-middleware.md) ^2.0.0
- [@types/i18next-express-middleware](https://npm.io/package/@types/i18next-express-middleware.md) ^1.7.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.7 (latest) — 2021-02-19
- 0.0.6 — 2021-02-15
- 0.0.5 — 2021-02-12
- 0.0.3 — 2021-02-10
- 0.0.2 — 2021-02-10
- 0.0.1 — 2021-02-10

## README

<p align="center">
  <a href="http://macore.ir" target="blank"><img src="https://s16.picofile.com/file/8424560968/profile_pic.png" width="120" alt="Mahdi Pakravan مهدی پاکروان" /></a>
  <h1 align="center">Macore <span>(Mahdi Nodejs Core)</span></h1>
</p>


## Description (V 0.0.7)

Macore is a framework for building <b>easy , fast and MultiLangual</b> <a href="http://nodejs.org" target="_blank">Node.js</a> server-side applications. It uses modern JavaScript, is built with  <a href="http://www.typescriptlang.org" target="_blank">TypeScript</a> and combines elements of OOP (Object Oriented Programming), FP (Functional Programming) , DP (Design Patterns)

<p>Under the hood, Macore makes use of <a href="https://expressjs.com/" target="_blank">Express</a> .

## Table Of Macore Features

- [Quick Start](#quick-start)
- [Router](#router)
- [Utilities](#utilities)
    - [Validation](#validation)
    - [ApiService](#apiservice)
    - [Chalk](#chalk)
    - [MultiLingual](#multilingual)
- [ORM](#orm)

## Quick Start

* 1 - Install This nodejs Module From npm using : ``` npm i --save @mahdi.js/macore ```
* 2 - Create Your <b>start.js|ts</b> With Below Code : 
```
  //TypeScript : 
  import App from 'macore'
  App(port)

  //javascript :
  const App = require('macore')
  App(port)

  // Also You Can Config view+session+cookie !
  App(
    port , 
    host , 
    viewConfig ,  // config OR {} OR Null(if you not need view)
    sessionConfig , // config OR {} OR Null(if you not need session)
    cookieConfig , // config OR {} OR Null(if you not need cookie)
    true // MongoConnection => true OR false ,
    MultiLingualConfig // config OR Null (if you not need i18Next[MultiLingual])
  ) 
```
* 3 - Your <b>Macore</b> App Configured !

<br/>
<hr/>

## Router

```
  //const app = new App(port , host , ...)
  app.route("/" , Request_Methods.GET , (req:Request , res:Response , next:NextFunction) => {res.send("Hello Macore")})
```

## Validation
Macore Validator is Using [class-validator](https://github.com/typestack/class-validator)
1-Create Your dto(data transfer object) file , Example : Signin.dto.ts
```
  import { IsString, Length } from 'class-validator';
  export default class SigninDto {
      @IsString()
      public name!: string;
  }
```
2-Set This Dto To Your app as a midleware
```
  app.route("/" , Request_Methods.POST , MacoreValidator(SignInDto) , Controller)
  
  /*
    * also you can pass your callback url if you are using view
    * this will be rediredct to callbackUrl
  */
  app.route("/" , Request_Methods.POST , MacoreValidator(SignInDto , "/home") , Controller)
```

## Utilities
This is Really Can Help You in any projects
> Note: you can cancel several requests with the same cancel token.

### `ApiService`
**Send Any Request Using axios inside this package**
```
    import {ApiService} from '@mahdi.js/macore'
    const apiInstance = new ApiService("https://jsonplaceholder.typicode.com/")
    await apiInstance.callService("todos/1" , Request_Methods.GET)
    
    //Also You Can Send Type of your Request & Response in Typescript
    await apiInstance.callService<RequestInterface , ResponseInterface>("todos/1" , Request_Methods.GET) 
```

### `chalk`
**console.log With Fucking Great TextColors!**
> You Can Read Document Inside [chalk](https://npmjs.com/package/chalk)
```
  import {ch} from '@mahdi.js/macore'
  console.log(ch.red("Hello With Red Color"))
```

### `MultiLingual`
**Create MultiLingual Server-side App Easssssyyyy**
1 - Config : this example for an english + spanish Server-side app
```
  new App(... , {
    lng : "en" ,
    fallbackLng : "en" ,
    preload : ["en" , "es"] ,
    saveMissing : false ,
    load : "languageOnly" ,
    resources : {
      en : {translation : {"greeting" : "Hello {{name}}" , 
      es : {translation : {"greeting" : "Hallo {{name}}  "}}
    }
  })
```
2 - Use it Using <b>app.t</b> Function
```
  app.t(
    "greeting" ,
    "en" , //This Lang
    {name : "Mahdi"}   // For pass Value Of {{name}}
  )
```

<br/>

> Also You Can Use it as Middleware or something else
For Example , This is Your Middleware
```
  function (req , res , next) {
    this.app.changeLanguage(req.query.lang || "en")
  }
```
<hr/>


## ORM
> In This Version You Just Can Use MongoORM in the future we use typeORM :) 

1 - Create a File For Your Model , Example : User.ts
```
  import {MongoBaseRepository} from "@mahdi.js/macore/utils/mongo";
  import {CustomSchemaDefinition} from "@mahdi.js/macore/types/mongo";
  
  export interface IUsers {
    name : string
  }
  
  class User extends MongoBaseRepository<IUsers>{

    definition(): CustomSchemaDefinition<IUsers> {
        return {
            name : {type : String , required : true}
        };
    }

    protected initiateIndexes(): void {}
    protected initiatePlugins(): void {}

  }

  export default new User("users")
```
2- End! , Use EveryWhere :)
```
    const users = await User.find({})
```

---
_Source: https://npm.io/package/@mahdi.js/macore · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
