Skip to content

Getting Started

Terminal window
npm install @t87s/core

t87s has two APIs: QueryCache and primitives.

  1. QueryCache is a typed API that helps speed up application development with a pleasant DX. It attempts to remove more footguns than it causes.
  2. Primitives provide lower-level building blocks for custom caching solutions. QueryCache is built on top of it.

This quickstart uses the QueryCache API, but in another world we could have used primitives and you would have been an equally-happy reader.

import { QueryCache, at, wild, MemoryAdapter } from '@t87s/core';
const schema = at('users', () =>
wild.at('settings').at('posts', () => wild.at('comments', () => wild))
);
const cache = QueryCache({
schema,
adapter: new MemoryAdapter(),
queries: (tags) => ({
getUser: (id: string) => ({
tags: tags.users(id)],
fn: () => db.users.findById(id),
}),
}),
});
await cache.getUser('123');
await cache.invalidate(cache.tags.users('123'));

If you want the full tour, start with the QueryCache tutorial, then circle back to Primitives if you feel that you or your human can build a better QueryCache. In that case, PRs are welcome!