Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript Rewrite #22

Merged
merged 8 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 5 additions & 47 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,10 @@
{
"extends": "eslint:recommended",
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"root": true,
"env": {
"node": true
},
"globals": {
"Map": true,
"Promise": true
},
"parserOptions": {
"ecmaVersion": 13,
"sourceType": "module"
},
"plugins": [ "node" ],
"rules": {
"no-console": 0,
"arrow-parens": [ "error", "always" ],
"no-var": "error",
"prefer-const": "error",
"array-bracket-spacing": [ "error", "never" ],
"comma-dangle": [ "error", "never" ],
"computed-property-spacing": [ "error", "never" ],
"eol-last": "error",
"eqeqeq": [ "error", "smart" ],
"indent": [ "error", 4, { "SwitchCase": 1 } ],
"no-confusing-arrow": [ "error", { "allowParens": false } ],
"no-extend-native": "error",
"no-mixed-spaces-and-tabs": "error",
"func-call-spacing": [ "error", "never" ],
"no-trailing-spaces": "error",
"no-unused-vars": "error",
"no-use-before-define": [ "error", "nofunc" ],
"object-curly-spacing": [ "error", "always" ],
"prefer-arrow-callback": "error",
"quotes": [ "error", "single", "avoid-escape" ],
"semi": [ "error", "always" ],
"space-infix-ops": "error",
"spaced-comment": [ "error", "always" ],
"keyword-spacing": [ "error", { "before": true, "after": true } ],
"template-curly-spacing": [ "error", "never" ],
"semi-spacing": "error",
"strict": "error",
"node/no-missing-require": "error",
"valid-jsdoc": ["error", {
"requireParamDescription": false,
"requireReturnDescription": false,
"requireReturnType": false,
"requireReturn": false
}]
"@typescript-eslint/ban-ts-comment": 1,
"@typescript-eslint/no-explicit-any": 1
}
}
7 changes: 5 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Get tag
id: tag
uses: dawidd6/action-get-tag@v1

- uses: actions/setup-node@v1
- uses: actions/setup-node@v4
with:
node-version: 18
registry-url: https://registry.npmjs.org/

- name: npm install
run: npm install

- name: npm build
run: npm run build

- name: npm publish
run: npm publish
env:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
docs/

# Logs
logs
*.log
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

## Version History

### v10.0.0

- :rocket: Very rough support for Typescript based routes

### v9.4.0

- :rocket: Add support for `private` key which will hide endpoint in swagger
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 OpenAddresses
Copyright (c) 2024 OpenAddresses

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
38 changes: 21 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1 align=center>Batch-Schema</h1>

<p align=center>Express Plugin for JSON Schema based routes</p>
<p align=center>Express Plugin for [TypeBox](https://github.com/sinclairzx81/typebox) Request and Response Validation</p>

## Installation

Expand All @@ -11,13 +11,14 @@ npm i @openaddresses/batch-schema
## Example Usage

```js
const path = require('path');
const express = require('express');
const { Schema } = require('@openaddresses/batch-schema');
import express from 'express';
import Schema from '@openaddresses/batch-schema';
import { Type } from '@sinclair/typebox';

const app = express();
const schema = new Schema(express.Router(), {
schemas: path.resolve(__dirname, 'schemas')
logging: true, // Enable Morgan Logging
limit: 50 // Body size for parsing JSON
});

app.use('/api', schema.router);
Expand All @@ -26,22 +27,25 @@ server();

async function server() {
await schema.post('/api/:param1/:param2', {
':param1': 'integer',
':param2': 'string',
query: 'query-json-schema.json',
body: 'body-json-schema.json',
res: 'result-body-json-schema.json'
query: Type.Object({
example: Type.Optional(Type.Uppercase(Type.String()))
}),
params: Type.Object({
param1: Type.String(),
param2: Type.Number(),
}),
body: Type.Object({
username: Type.String(),
password: Type.String(),
}),
res: Type.Object({
token: Type.String()
}),
}, (req, res) => {
return res.json({
note: 'I only return if the request meets the query & body schemas'
token: 'I only return if the request meets the query & body schemas'
});
});

// Handle Unmatched Routes
schema.not_found();

// Handle Validation Errors => JSON Middleware
schema.error();
}
```

Expand Down
Loading
Loading