0.4.14 • Published 2 years ago

@tracktile/veritas v0.4.14

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Features

  • :muscle: Based on Koa, Typebox, and openapi3-ts.

  • :pencil2: Define your Request, Response, URL Parameters, and Query Parameters alongside with your endpoints.

  • :necktie: Automatically infers types of parameter, request, and response body types in your handler.

  • :lock: Automatically validates each request and response against defined types and validations.

  • :notebook_with_decorative_cover: Automatically generates an OpenAPI schema describing your API as YAML or JSON.

  • :battery: Deploy your API as microservice, or a modular monolith to AWS Lambda using our provided CDK construct.

  • :runner: Run all of your services in a single process for local development. Deploy as separate services.

Installation

  npm install @tracktile/veritas
  # OR
  yarn add @tracktile/veritas

Usage

Build an amazing API

import { Service, Controller, Type, serverless } from "@tracktile/veritas";

const users = new Controller({
  prefix: "/users",
  tags: ["Users"],
});

const GetUserParams = Type.Object({
  userId: Type.String({ format: "uuid" }),
});

const GetUserResponse = Type.Object({
  id: Type.String({ format: "uuid" }),
  firstName: Type.String(),
  lastName: Type.String(),
  email: Type.String({ format: "email" }),
});

users.addOperation(
  {
    name: "Get User By Id",
    path: "/:userId",
    method: "get",
    params: GetUserParams,
    res: GetUserResponse,
  },
  async (ctx, next) => {
    /* ctx.params has been validated and inferred as:
        { userId: string } */
    const { userId } = ctx.params;
    /* ctx.body type has been validated and inferred as:
       { id: string, firstName: string, lastName: string, email: string} */
    ctx.body = getUser(userId);
    return next();
  }
);

/* Service title, description, tags, etc are used to generate openapi schema */
export const MyService = new Service({
  title: "My Wonderful Service",
  description: "Microservice responsible for handling X in the N platform.",
  tags: ["ServiceA"],
  controllers: [users],
});

// Start and bind your service to a port
MyService.start(8080);

// OR run your service inside a lambda
exports.handler = serverless(MyService);

Generate your OpenAPI documentation

yarn veritas --in=./myService.ts --out=./my-api-schema.yaml --yaml
OR
yarn veritas --in=./myCombinedServices.ts --out=./my-api-schema.json --json

Examples

Small example projects can be found in the examples/ folder.

Authors

0.4.14

2 years ago

0.4.9

2 years ago

0.4.8

2 years ago

0.4.10

2 years ago

0.4.13

2 years ago

0.4.11

2 years ago

0.4.12

2 years ago

0.4.5

2 years ago

0.4.7

2 years ago

0.4.6

2 years ago

0.3.0

2 years ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.7

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.3

2 years ago

0.3.9

2 years ago

0.3.11

2 years ago

0.3.10

2 years ago

0.4.4

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.19

3 years ago

0.0.17

3 years ago

0.0.16

3 years ago

0.0.15

3 years ago

0.0.14

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago