0.4.14 • Published 10 months ago

@tracktile/veritas v0.4.14

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months 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

10 months ago

0.4.9

12 months ago

0.4.8

12 months ago

0.4.10

12 months ago

0.4.13

11 months ago

0.4.11

12 months ago

0.4.12

12 months ago

0.4.5

1 year ago

0.4.7

12 months ago

0.4.6

1 year ago

0.3.0

1 year ago

0.3.6

1 year ago

0.3.5

1 year ago

0.3.7

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.3

1 year ago

0.3.9

1 year ago

0.3.11

1 year ago

0.3.10

1 year ago

0.4.4

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.4.3

1 year ago

0.4.2

1 year ago

0.2.7

1 year ago

0.2.6

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.19

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