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

strapi-query

v0.5.6

Published

Schema-first typed query client for Strapi REST APIs.

Readme

strapi-query

Schema-first typed query client for Strapi REST APIs.

strapi-query keeps runtime entity types clean while deriving relation-aware filters, populate options, and response types from a schema registry.

Install

pnpm add strapi-query

Define a Schema

import { collection, defineSchema, entity, many, one, single } from 'strapi-query';

interface Article {
  id: number;
  documentId: string;
  title: string;
  slug: string;
  content: string;
  publishedAt: string;
}

interface Theme {
  id: number;
  documentId: string;
  name: string;
  uid: string;
}

interface UploadFile {
  id: number;
  documentId: string;
  url: string;
  alternativeText: string | null;
}

interface HomePage {
  id: number;
  documentId: string;
}

export const schema = defineSchema({
  article: collection('articles', {
    entity: entity<Article>(),
    relations: {
      cover: one('uploadFile'),
      themes: many('theme')
    }
  }),
  theme: collection('themes', { entity: entity<Theme>() }),
  uploadFile: collection('upload-files', { entity: entity<UploadFile>() }),
  homePage: single('home-page', {
    entity: entity<HomePage>(),
    relations: {
      featuredArticle: one('article'),
      trendingArticles: many('article')
    }
  })
});

Query Strapi

import { createStrapiClient } from 'strapi-query';
import { schema } from './schema';

const strapi = createStrapiClient({
  endpoint: 'https://cms.example.com',
  token: process.env.STRAPI_API_TOKEN,
  schema
});

const articles = await strapi.collection('article').findMany({
  filters: {
    slug: { $eq: 'best-reits-singapore' },
    themes: { uid: 'reits' }
  },
  fields: ['title', 'slug', 'publishedAt'],
  populate: {
    cover: true,
    themes: true
  },
  sort: ['publishedAt:desc'],
  pagination: { page: 1, pageSize: 10 },
  publicationFilter: 'has-published-version'
});

The response type is inferred from the schema and populate object. Runtime records do not contain fake relation metadata.

Generate a Schema

strapi-query can generate the TypeScript entity interfaces, relations, and schema registry directly from Strapi schema files:

strapi-query generate --strapi-schema ./src --out ./src/strapi-schema.ts

Pass a Strapi project src directory to discover content type schema.json files and component JSON files automatically. You can also pass individual files or repeat --strapi-schema.

If your Strapi project has the GraphQL plugin enabled, you can still generate from GraphQL introspection.

strapi-query generate --graphql-url http://localhost:1337/graphql --out ./src/strapi-schema.ts

You can also generate from a saved introspection result:

strapi-query generate --graphql ./graphql-introspection.json --out ./src/strapi-schema.ts

The generator discovers resources from GraphQL Query fields, maps GraphQL object types to TypeScript interfaces, and turns object/list fields that point at other resources into one() and many() relations. Generated resource paths follow Strapi REST conventions, such as articles, home-page, and upload/files.

By default, generated interfaces use an optimistic REST-friendly nullability mode: scalar and enum fields are emitted as required non-null properties, while object-valued component fields can still be null. To mirror GraphQL introspection nullability exactly, pass --nullability graphql.

Type Helpers

import type { Entity, Populated } from 'strapi-query';
import { schema } from './schema';

type PlainArticle = Entity<typeof schema, 'article'>;
type ArticleCard = Populated<typeof schema, 'article', { cover: true; themes: true }>;

Scope

This is intentionally not an ORM. It does not model persistence, lazy loading, transactions, or identity maps. It is a typed REST query boundary for Strapi.