Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
feat: Initial release
Browse files Browse the repository at this point in the history
* feat: Initial

* fix: Added `semantic-release-telegram-bot`

* feat: Added CI pipeline for `@relab/rejs-swagger`

* fix: Path typo fix `rejs-swagger`

* fix: Added `prepack` script

* fix: Fixed pipeline names

* fix: Adjustments to NPM package content

* fix: Fixed pipeline names

* fix: Pipelines added to trigger condition

* docs: Added `README.md`
  • Loading branch information
sergeyzwezdin authored Feb 4, 2024
1 parent 9fb3695 commit 1bc2108
Show file tree
Hide file tree
Showing 47 changed files with 15,608 additions and 1 deletion.
49 changes: 49 additions & 0 deletions .github/workflows/core.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: "@relab/rejs"

on:
push:
branches:
- master
- development
paths:
- packages/rejs/**
- .github/workflows/core.yml

jobs:
release:
permissions:
contents: write
issues: write
pull-requests: write
id-token: write
name: Release
runs-on: ubuntu-latest
environment: npm
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
cache: npm
node-version: '20'
- id: cache-npm
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('./package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
continue-on-error: true
run: npm list
- run: npm ci -ws
- run: npx semantic-release
working-directory: ./packages/rejs
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_BOT_CHAT_ID: ${{ vars.TELEGRAM_BOT_CHAT_ID }}
49 changes: 49 additions & 0 deletions .github/workflows/swagger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: "@relab/rejs-swagger"

on:
push:
branches:
- master
- development
paths:
- packages/rejs-swagger/**
- .github/workflows/swagger.yml

jobs:
release:
permissions:
contents: write
issues: write
pull-requests: write
id-token: write
name: Release
runs-on: ubuntu-latest
environment: npm
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
cache: npm
node-version: '20'
- id: cache-npm
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('./package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
continue-on-error: true
run: npm list
- run: npm ci -ws
- run: npx semantic-release
working-directory: ./packages/rejs-swagger
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_BOT_CHAT_ID: ${{ vars.TELEGRAM_BOT_CHAT_ID }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,6 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

.idea
lib
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
save-exact=true
99 changes: 98 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,98 @@
# rejs
# re.js

**re.js** is a framework built on top of Express that facilitates the development of API endpoints using the capabilities of Typescript and Zod.

## Features
- 💥 Tiny and lightweight
- 🏆 First class support of Zod and Typescript
- 🧠 Fully-typed routes, params and output
- 🤓 Out of the box OpenAPI/Swagger support
- 😎 Backward compatible with Express

## Getting started

``bash
npm install @relab/rejs --save
``

## Route

```typescript
import { route } from '@relab/rejs'
import { z } from 'zod'

export const helloWorld = route({
method: 'POST',
path: '/hello/:name',
schema: {
route: z.object({
name: z.coerce.string(),
}),
result: z.string(),
},
})(({ route }, context) => {
return `${route.name}, hello world!`
})
```

## Setup routes serving

In your `index.ts`:

```typescript
import { serve } from '@relab/rejs'

import { helloWorld } from './hello-world'

void serve(
{
port: Number(process.env.PORT) || 3000,
routes: [
helloWorld,
],
},
port => {
logger.info(`Listening http://localhost:${port}`)
}
)
```

## Setup swagger

```bash
npm install @relab/rejs-swagger --save
```

In your `index.ts`:

```typescript
import { serve } from '@relab/rejs'
import { swagger } from '@relab/rejs-swagger'

import { helloWorld } from './hello-world'

void serve(
{
port: Number(process.env.PORT) || 3000,
middlewares: [
swagger({
ui: {
enabled: true,
},
}),
],
routes: [
helloWorld,
],
},
port => {
logger.info(`Listening http://localhost:${port}`)
}
)
```

Now you can access Swagger by `/swagger` and `/swagger/swagger.json` URLs.

## License

Released under [MIT](/LICENSE) by [Sergey Zwezdin](https://github.com/sergeyzwezdin).
Loading

0 comments on commit 1bc2108

Please sign in to comment.