jari
TypeScript icon, indicating that this package has built-in type declarations

2024.1.20 • Public • Published

Jari

Jari is an opinionated code generation CLI library that makes it absolutely easy to build a CRUD RESTful Api with Node.js and Express.js using Typescript. Jari is capable of code generation for the following HTTP Verbs : POST, PUT and GET.

Tech Stack

  • MongoDb
  • Express.js
  • Typescript
  • Node.js

Installation

Use the package manager npm to install jari.

$ npm install jari -g

Usage

Creating a project

Creating the project where project-name is the name of the project

$ jari create 'project-name'

The following folder structure will be created

project-name
-- src/
------ root/
------ security/
------ utils/
------ app.ts
------ route.index.ts

CD into project directory

Generating API files

Creating blank api endpoints, api-name is the name of api

$ jari api 'api-name'

The following files will be created

api-name/
-- test/
------ create.spec.ts
------ edit.spec.ts
------ read.spec.ts
-- api-name.controller.ts
-- api-name.entity.ts
-- api-name.routes.ts
-- api-name.schema.ts
-- api-name.service.ts
-- api-name.utils.ts

Scaffolding API

Scaffolding api logic, this will create POST, PUT and GET methods inclusive of e2e tests and documentation

Step 1

$ jari schema 'api-name'

The name must be in singular, e.g. user not users

  • jari api user

For api that have more than one word. Use kebab-case or camel case

  • jari api user-detail
  • jari api userDetail

Step 2

You will be prompted to enter the number of fields the schema have

Lets generate user-detail schema. Enter the number of fields

Step 3

*********** FIELD 1 ***********

Enter Field 1 Name

Step 4

Select the field data type

Enter Field 1 Type
1. String
2. Boolean
3. Number
4. Schema.Types.ObjectId
5. Date
6. Enum

Step 5

Select if field is required/mandatory

Is Field 1 Required 
1. True
2. False

Step 6

Is Field 1 Unique 
1. True
2. False

NB: The above steps will be repeated for all fields

Managing Relationship/References

There are two types of relationships that are supported.

One-To-Many:

First create the child entity using steps above. Then create the parent entity/schema. In the parent schema, create a field that references the child schema. The field must have 4. Schema.Types.ObjectId data type. On prompt Enter Field 1 Reference enter the name of the child as entered on creation.

Many-To-Many:

Create both schemas, then create an additional one for relation which has two fields both referencing respective schemas

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Readme

Keywords

none

Package Sidebar

Install

npm i jari

Weekly Downloads

2

Version

2024.1.20

License

ISC

Unpacked Size

1.03 MB

Total Files

276

Last publish

Collaborators

  • tapiwajoel