npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@genfeedai/api-types

v1.0.1

Published

Auto-generated TypeScript types from OpenAPI spec with Zod validation schemas

Downloads

213

Readme

@genfeedai/api-types

Auto-generated TypeScript types from the OpenAPI spec with Zod validation schemas for runtime validation.

Overview

This package provides:

  1. Type-safe API contracts - TypeScript types derived from backend DTOs via OpenAPI
  2. Zod schemas - Runtime validation matching backend class-validator rules
  3. Form integration - Use with @hookform/resolvers for type-safe forms

Usage

Service Layer

import type { CreatePostRequest, UpdatePostRequest } from '@genfeedai/api-types';

class PostsService extends BaseService<Post, CreatePostRequest, UpdatePostRequest> {
  // post() and patch() now have compile-time type safety
}

// TypeScript enforces required fields
await postsService.post({
  credential: credentialId,
  label: 'My Post',
  description: 'Content',
  status: PostStatus.DRAFT,
  ingredients: [],
}); // Required fields enforced at compile time

Form Validation

import { createPostSchema, type CreatePostRequest } from '@genfeedai/api-types';
import { zodResolver } from '@hookform/resolvers/zod';

const form = useForm<CreatePostRequest>({
  resolver: zodResolver(createPostSchema),
});

Generating Types

Types are generated from the running API server's OpenAPI spec:

cd packages/api-types

# Local development (fails if API not running)
bun run generate:strict

# With fallback to existing types (default, used in CI)
bun run generate

# Specify a different URL
bun run generate:strict --url https://api.staging.genfeed.ai/v1/openapi.json

CI/CD Integration

Type generation runs automatically before build via turbo:

// turbo.json
{
  "@genfeedai/api-types#generate": {
    "env": ["OPENAPI_URL"],
    "outputs": ["src/generated/**"]
  },
  "@genfeedai/api-types#build": {
    "dependsOn": ["generate"]
  }
}

GitHub Actions Example

- name: Build packages
  env:
    OPENAPI_URL: https://api.staging.genfeed.ai/v1/openapi.json
  run: bunx turbo build --filter=@genfeedai/api-types

Fallback Behavior

The generate script uses --skip-on-error by default:

  • If API is reachable: generates fresh types
  • If API is unreachable but types exist: uses existing types (warning logged)
  • If API is unreachable and no types: build may fail

Adding New Contracts

  1. Create a new contract file in src/contracts/:
// src/contracts/articles.contract.ts
import { z } from 'zod';
import type { components } from '../generated/api';

export type CreateArticleRequest = components['schemas']['CreateArticleDto'];
export type UpdateArticleRequest = components['schemas']['UpdateArticleDto'];

export const createArticleSchema = z.object({
  // Match the DTO fields
}) satisfies z.ZodType<CreateArticleRequest>;
  1. Export from src/contracts/index.ts

  2. Update the service to use typed generics:

class ArticlesService extends BaseService<
  Article,
  CreateArticleRequest,
  UpdateArticleRequest
> {}

File Structure

src/
├── index.ts              # Main exports
├── generated/
│   └── api.d.ts          # Auto-generated from OpenAPI
├── contracts/
│   ├── index.ts          # Contract exports
│   ├── posts.contract.ts
│   └── ingredients.contract.ts
└── helpers/
    └── common-schemas.ts  # Reusable Zod primitives