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

@pallad/query-descriptor

v6.0.0

Published

`@pallad/query-descriptor` builds typed, runtime-validated query contracts for `@pallad/query`.

Readme

@pallad/query-descriptor

@pallad/query-descriptor builds typed, runtime-validated query contracts for @pallad/query.

The main entry point is QueryDescriptor. It combines optional filter validation, pagination configuration, and sorting configuration into one Zod schema. The same descriptor can then parse incoming query input and create response metadata for result lists.

QueryDescriptor

QueryDescriptor is a builder for query objects. It supports:

  • filterSchema(schema) - adds a Zod object schema under filter.
  • paginationByOffset(options?) - adds offset and limit pagination.
  • paginationByCursor(options?) - adds before, after, and limit cursor pagination.
  • sortingBySingleField(config) - allows one sortable field.
  • sortingByMultipleFields(config) - allows a non-empty list of sortable fields.
  • createQuery(input) - parses input through the generated Zod schema.
  • createResult(query, entityList, paginationContext?) - creates response data with list/page/sort metadata.

Each builder method updates TypeScript input, output, pagination, and sorting types. querySchema is generated lazily and cached until descriptor configuration changes.

Example

import { QueryDescriptor } from "@pallad/query-descriptor";
import { z } from "zod";

const descriptor = new QueryDescriptor()
	.filterSchema(
		z.object({
			status: z.enum(["active", "archived"]).optional(),
		})
	)
	.paginationByOffset({ defaultLimit: 20 })
	.sortingByMultipleFields({
		sortableFields: ["name", "createdAt"],
		defaultSorting: [{ field: "createdAt", direction: "DESC" }],
	});

const query = descriptor.createQuery({
	filter: { status: "active" },
	offset: 0,
	sortBy: [{ field: "name", direction: "ASC" }],
});

const result = descriptor.createResult(query, [{ id: "user-1", name: "Ada" }], {
	hasNextPage: false,
	hasPreviousPage: false,
});

query contains parsed filter, pagination defaults, and validated sorting. result contains the entity list, pagination pageInfo, and sortBy metadata.

Pagination

Offset pagination produces input with offset and limit, and result metadata under pageInfo:

{
	list: entities,
	pageInfo: {
		offset,
		limit,
		hasNextPage,
		hasPreviousPage,
	},
}

Cursor pagination produces input with optional before/after cursors and limit. Result data follows the connection shape:

{
	edges: [{ node, cursor }],
	nodes: entities,
	pageInfo: {
		limit,
		startCursor,
		endCursor,
		hasNextPage,
		hasPreviousPage,
	},
}

Cursor pagination requires single-field sorting and rejects multi-field sorting. Cursors use entity id by default; pass idExtractor in createResult context when entities do not expose a string id field.

Sorting

Single-field sorting validates one sortBy object:

{ sortBy: { field: "name", direction: "ASC" } }

Multi-field sorting validates a non-empty sortBy array and applies configured default sorting when sortBy is missing.

Both sorting modes add sortBy metadata to results through createResult.