JSPM

  • Created
  • Published
  • Downloads 3704
  • Score
    100M100P100Q128111F
  • License MIT

Utilities for adhering to the JSON:API specification with NestJS.

Package Exports

  • @clipboard-health/json-api-nestjs
  • @clipboard-health/json-api-nestjs/src/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@clipboard-health/json-api-nestjs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@clipboard-health/json-api-nestjs

Utilities for adhering to the JSON:API specification with NestJS.

Table of Contents

Install

npm install @clipboard-health/json-api-nestjs

Usage

Query helpers

Create Zod schemas for your API's queries:

// ./examples/query.ts

import {
  booleanString,
  createCursorPagination,
  createFields,
  createFilter,
  createInclude,
  createSort,
} from "@clipboard-health/json-api-nestjs";
import { z } from "zod";

export const query = z
  .object({
    ...createCursorPagination(),
    ...createFields({ user: ["age", "name"], article: ["title"] }),
    ...createFilter({
      age: {
        filters: ["eq", "gt"],
        schema: z.coerce.number().int().positive().max(125),
      },
      isActive: {
        filters: ["eq"],
        schema: booleanString,
      },
      dateOfBirth: {
        filters: ["gte"],
        schema: z.coerce.date().min(new Date("1900-01-01")),
      },
    }),
    ...createSort(["age", "name"]),
    ...createInclude(["articles", "articles.comments"]),
  })
  .strict();

Local development commands

See package.json scripts for a list of commands.