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

@triadjs/solid-query

v0.2.2

Published

Solid Query hook generator for Triad routers

Readme

@triadjs/solid-query

Generate fully-typed Solid Query hooks from a Triad router. A single source of truth — changing a schema on the server produces compile errors in the exact call sites on the frontend.

Install

npm install --save-dev @triadjs/solid-query

@tanstack/solid-query is a peer concern: the generated code imports from it, so your frontend app must have it installed:

npm install @tanstack/solid-query

Usage

triad frontend generate --target solid-query --output ./src/generated/api

Or via triad.config.ts:

import { defineConfig } from '@triadjs/test-runner';

export default defineConfig({
  frontend: {
    target: 'solid-query',
    output: './src/generated/api',
  },
});

Output layout

src/generated/api/
  index.ts         — barrel re-exporting everything
  types.ts         — every named interface used by any hook
  query-keys.ts    — per-resource key factories
  client.ts        — runtime fetch client + HttpError
  <context>.ts     — one file per bounded context with its hooks

Example generated hook

// Generated: library.ts
import { createQuery, createMutation, useQueryClient,
         type SolidQueryOptions, type SolidMutationOptions } from '@tanstack/solid-query';
import { client, type HttpError } from './client.js';
import type { Book, BookPage, CreateBook, ListBooksQuery, GetBookParams } from './types.js';
import { bookKeys } from './query-keys.js';

export function useListBooks(
  query: () => ListBooksQuery,
  options?: Omit<SolidQueryOptions<BookPage, HttpError>, 'queryKey' | 'queryFn'>,
) {
  return createQuery(() => ({
    queryKey: bookKeys.list(query()),
    queryFn: () => client.get<BookPage>(`/books`, { query: query() }),
    ...(options ?? {}),
  }));
}

export function useBook(
  params: () => GetBookParams,
  options?: Omit<SolidQueryOptions<Book, HttpError>, 'queryKey' | 'queryFn'>,
) {
  return createQuery(() => ({
    queryKey: bookKeys.detail(params().bookId),
    queryFn: () => client.get<Book>(`/books/${params().bookId}`),
    ...(options ?? {}),
  }));
}

export function useCreateBook(
  options?: Omit<SolidMutationOptions<Book, HttpError, { body: CreateBook }>, 'mutationFn'>,
) {
  const qc = useQueryClient();
  return createMutation(() => ({
    mutationFn: (vars: { body: CreateBook }) => client.post<Book>(`/books`, { body: vars.body }),
    onSuccess: (data: Book, variables: { body: CreateBook }, context: unknown) => {
      qc.invalidateQueries({ queryKey: bookKeys.lists() });
      options?.onSuccess?.(data, variables, context);
    },
    ...(options ?? {}),
  }));
}

Reactive idioms

Solid Query resolves query options on every render via a thunk. The generator preserves reactivity end-to-end by:

  • Wrapping createQuery / createMutation options in () => ({ ... }).
  • Passing params and query as accessor functions (() => T) so changes to a parent signal cause re-fetches without re-creating the hook.
  • Deriving query keys inside the thunk so invalidation and refetch react to signal changes naturally.

Invalidation

The generator mirrors @triadjs/tanstack-query's invalidation heuristic:

  • POST /books invalidates bookKeys.lists().
  • PATCH /books/:bookId / PUT invalidate bookKeys.detail(id) and bookKeys.lists().
  • DELETE /books/:bookId invalidates both as well.
  • Endpoints whose paths don't map to a CRUD resource (e.g. /auth/login) use a flat key ['auth', 'login'] and no automatic invalidation.

You can override onSuccess via the options argument — it runs after the built-in invalidations.

Reuse

This package reuses the schema emitter, resource derivation, query-key factory, and fetch client template from @triadjs/tanstack-query. Only the hook emitter is unique to Solid Query.