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

v5.0.1

Published

`@pallad/query` provides shared TypeScript contracts for query objects, pagination results, sorting, and query runners.

Readme

@pallad/query

@pallad/query provides shared TypeScript contracts for query objects, pagination results, sorting, and query runners.

It does not execute queries or validate input. Use it as the core type package. Runtime validation and query/result creation live in packages such as @pallad/query-descriptor.

Query

Query<TFilter> is the base query shape:

import { Query } from "@pallad/query";

type UserQuery = Query<{
	status?: "active" | "archived";
}>;

Every query has a filter field. Pagination and sorting types can be added through intersections.

Pagination

Offset pagination uses offset and limit:

import { PaginationByOffset } from "@pallad/query";

type OffsetQuery = PaginationByOffset;

const result: PaginationByOffset.Result<User> = {
	list: users,
	pageInfo: {
		offset: 0,
		limit: 20,
		hasNextPage: true,
		hasPreviousPage: false,
	},
};

Cursor pagination uses optional before/after cursors and limit:

import { PaginationByCursor } from "@pallad/query";

const result: PaginationByCursor.Result<User> = {
	edges: users.map(user => ({
		node: user,
		cursor: { i: user.id },
	})),
	nodes: users,
	pageInfo: {
		limit: 20,
		hasNextPage: false,
		hasPreviousPage: false,
	},
};

When no pagination is used, return NoPagination.Result<T>:

import { NoPagination } from "@pallad/query";

const result: NoPagination.Result<User> = {
	list: users,
};

Sorting

Sorting is described with SortingFieldDefinition<TField> and SortDirection:

import { SortingSingle, SortingMulti } from "@pallad/query";

type UserSortField = "name" | "createdAt";

type SingleSort = SortingSingle<UserSortField>;
type MultiSort = SortingMulti<UserSortField>;

Single sorting stores one sortBy field. Multi sorting stores a sortBy array.

const single: SingleSort = {
	sortBy: { field: "name", direction: "ASC" },
};

const multi: MultiSort = {
	sortBy: [
		{ field: "createdAt", direction: "DESC" },
		{ field: "name", direction: "ASC" },
	],
};

Query Runner

QueryRunner<TQuery, TResult> describes a function that accepts a query and returns a paginated result, synchronously or asynchronously:

import { PaginationByOffset, Query, QueryRunner } from "@pallad/query";

type UserQuery = Query<{ status?: string }> & PaginationByOffset;

const runUsersQuery: QueryRunner<UserQuery, PaginationByOffset.Result<User>> = async query => {
	return {
		list: [],
		pageInfo: {
			offset: query.offset ?? 0,
			limit: query.limit,
			hasNextPage: false,
			hasPreviousPage: false,
		},
	};
};

Utility Types

SetResultType<TEntity, TResult> replaces entity type in a known result shape:

import { PaginationByCursor, SetResultType } from "@pallad/query";

type UserCursorResult = SetResultType<User, PaginationByCursor.Result<unknown>>;