0.0.19 • Published 1 year ago

@asaje/nesty v0.0.19

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

nesty

Description

A tool for easily configure NestJS/Prisma project based on yml file

Installation

npm i -D @asaje/nesty

or

yarn add -D @asaje/nesty

Getting started

# Step 1: Create a new nestjs project
nest g new my-project

cd my-project

You can follow the nestjs first steps guide here.

# Step 2: Install nesty as dependency
npm i -D @asaje/nesty
# Step 3: create your config.yml file
touch config.yml

# Write your configs
# Step 4: Use nesty to initialise your project
npx nesty config.yml init
# Step 5: Execute migrations and start your dev server
npm run migrate
npm run dev

Features (available commands)

init
Initialize a new empty project

# Eg:
npx nesty config.yml init

update
Use this command when your project is already configured and you want to make some updates

# Eg:
npx nesty config.yml update

gen:prisma
Use this command to only generate the prisma configs

# Eg:
npx nesty config.yml gen:prisma

gen:target
Use this command to only generate the config of a specific model or enum

# Eg:
npx nesty config.yml gen:target my-target

gen:db
Use this command to only generate the database configs

# Eg:
npx nesty config.yml gen:db

gen:env
Use this command to only generate the env configs

# Eg:
npx nesty config.yml gen:env

gen:sdk

Each time your project is built (the development server is started for example), a file named api.json is generated at the root of your project, this file is used to generate the equivalent sdk of your project.

# Eg:
npx nesty api.json gen:sdk

Write your config file

You can define in your configuration file five (5) configuration groups.

  • env: for the configuration of environment variables
  • database: for database configuation (only PostgresSQL databases are supported for the moment)
  • server: for server configuration
  • enums: list of all prisma schema enums
  • models: list of all prisma schema models

An example of config file is

env:
  dev:
    key: 'xxxxxxxxx'
  default:
    key: 'xxxxxxxxx'

database:
  dev:
    user: postgres
    pass: root
    port: 5432
    name: foo
    host: localhost

  default:
    user: john
    pass: p455w0rd
    port: 5432
    name: todo
    host: my.domain.app

server:
  port: 4300
  prefix: 'api'
  doc:
    title: 'TODO API'
    description: 'The todo API description'
    version: '1.0'
    path:
      swagger: 'docs'
      redocs: 'redocs'
    auth:
      user: 'admin'
      pass: 'admin'

enums:
  todo-status:
    - CREATED
    - PENDING
    - COMPLETED

models:
  todo:
    id:
      type: string
      id: uuid
    label:
      type: string
      validations:
        isString:
        minLength: 3
        maxLength: 10
    duration:
      type: int
      validations:
        isInt:
        min: 1
        max: 10
    status:
      type: enum
      enum: TodoStatus
      validations:
        isEnum: TodoStatus
    author:
      type: ref
      model: Author

  author:
    id:
      type: string
      id: uuid
    name:
      type: string

env

This is where you can specify all your env variables for your different environments. The syntax is:

# config.yml
env:
    env_name_1:
        key1: value1
        ...
        keyn: valueN
    ...
    env_name_N:
        key1: value1
        ...
        keyn: valueN

If you have two environments dev and prod for example, your configuration file should look like this

# config.yml
env:
  dev:
    api_key: xxxxxxxxx
  prod:
    api_key: xxxxxxxxx

As result, two files will be generated: .env.dev and .env.prod

NB: If you want to process .env without a specific environment suffix, you must use default as the environment name.

database

As for the env part, you can define database configurations for each of your working environments. The defaut environment is named default.

The available configurations are :

  • user: database username, default set to postgres
  • pass: database password, default set to root
  • port: database port, default set to 5432
  • name: database name, default set to test
  • host: database host, default set to localhost

server

The available configurations are:

  • port: the server port
  • prefix: the global api prefix, defautl set to api
  • doc: swagger and redocs configs

The available configurations for doc are:

  • title: the documentation page title
  • description: the documentation page description
  • version: the API version
  • path: the base paths for the documentation page. path.swagger defines the swagger path and path.redocs the redocs path
  • auth: the redocs page credentials. auth.user defines the username and auth.pass the password

enums

This is where you can specify all you enums.

The syntax is:

# config.yml
enums:
    enum_name_1:
      - value1
      - ...
      - valueN
    ...
    enum_name_N:
      - value1
      - ...
      - valueN

models

This is where you can specify all you models.

The syntax is:

# config.yml
models:
    model_name_1:
      column_name_1:
        attr_1: value1
        ...
        attr_N: valueN
      ...
      column_name_N:
        attr_1: value1
        ...
        attr_N: valueN
    ...
    model_name_N:
      column_name_1:
        attr_1: value1
        ...
        attr_N: valueN
      ...
      column_name_N:
        attr_1: value1
        ...
        attr_N: valueN

Available attributes are :

AttributePossible values 
idincrement, uuid, cuid
typestring, int, float, bool, ref, enum, date 
uniquetrue, false
requiredtrue, false
defaultthe default value
enumthe referenced enum
modelthe referenced model
validationsone of available validations

The available validations are:

  • min
  • max
  • minLength
  • maxLength
  • isInt
  • isDate
  • isEmail
  • isString
  • contains
  • isEmpty
  • isNotEmpty
  • isDefined
  • isOptional
  • equals
  • notEquals
  • isIn
  • isNotIn
  • isBoolean
  • isNumber
  • isArray
  • isEnum
  • isPositive
  • isNegative
  • minDate
  • maxDate
  • isBooleanString
  • isDateString
  • notContains
  • isAplha
  • isAlphanumeric
  • isDecimal
0.0.19

1 year ago

0.0.18

1 year ago

0.0.17

1 year ago

0.0.16

1 year ago

0.0.15

1 year ago

0.0.14

1 year ago

0.0.13

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago