Пример
@tanstack/query-core 5.67.1: QueryClient
Проверенный пример — npm @tanstack/query-core 5.67.1: QueryClient. Контракт выполнен на node 22 · linux debian/x64 · docker и пройден.
sha256:6c8e0b1da0423c3b012ab379f50c4413b8e3bd2f7f6fa77dc9f31bd5aa137a4d
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
MIT-0
Свидетельства выполнения
Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.
- Основа свидетельства
- Подписанный контракт пройден
- Квитанции проверки
- 1
- Ключи подписи, собравшие его
- 1
Заявленная среда
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Среды запусков проверки
| Окружение | Контракт | Этапы | Запуск |
|---|---|---|---|
| node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-09-03 |
Кейс
HOW- Цель
- verify pkg:npm/%40tanstack/query-core@5.67.1
- Пакеты
- Символы
-
- QueryClient
- Окружение
- node 22.23.2
- Создан
- 2026-09-03T12:54:40Z
Контракт
- assert QueryClient constructs an instance with default configuration and caches
- assert QueryClient getQueryData and setQueryData manages cached query values
- assert QueryClient fetchQuery executes queryFn and caches the resolved data
- assert QueryClient prefetchQuery loads data into cache without returning value
- assert QueryClient invalidateQueries marks matching queries as stale
- assert QueryClient removeQueries removes matching queries and clear resets all caches
Файлы
- PROMPT.md
- csx.json
- index.mjs
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Исходный код
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify pkg:npm/%40tanstack/query-core@5.67.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40tanstack/query-core@5.67.1
Demonstrate these symbols/APIs:
- QueryClient
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:e88188f3c8298802461a1a3a18c65fdc854920f76c0cf9f1a3b5f9c39c2cf6d5","constraints":{"executionContext":"node"},"contract":["assert QueryClient constructs an instance with default configuration and caches","assert QueryClient getQueryData and setQueryData manages cached query values","assert QueryClient fetchQuery executes queryFn and caches the resolved data","assert QueryClient prefetchQuery loads data into cache without returning value","assert QueryClient invalidateQueries marks matching queries as stale","assert QueryClient removeQueries removes matching queries and clear resets all caches"],"goal":"verify pkg:npm/%40tanstack/query-core@5.67.1","kind":"HOW","packages":["pkg:npm/%40tanstack/query-core@5.67.1"],"schemaVersion":1,"symbols":["QueryClient"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40tanstack/query-core@5.67.1"],"schemaVersion":1,"subject":"pkg:npm/%40tanstack/query-core@5.67.1","symbols":["QueryClient"],"verifierAdapter":"node-typescript@1"}
import { QueryClient, QueryCache, MutationCache } from '@tanstack/query-core';
/**
* Creates a new QueryClient instance with optional configuration.
*
* @param {object} [config]
* @returns {QueryClient}
*/
export function createQueryClient(config) {
return new QueryClient(config);
}
/**
* Fetches query data using the provided QueryClient.
*
* @param {QueryClient} client
* @param {object} options
* @returns {Promise<any>}
*/
export async function fetchQuery(client, options) {
return client.fetchQuery(options);
}
/**
* Prefetches query data into the cache using the provided QueryClient.
*
* @param {QueryClient} client
* @param {object} options
* @returns {Promise<void>}
*/
export async function prefetchQuery(client, options) {
return client.prefetchQuery(options);
}
/**
* Sets query data in the QueryClient cache.
*
* @param {QueryClient} client
* @param {Array<any>} queryKey
* @param {any} updater
* @returns {any}
*/
export function setQueryData(client, queryKey, updater) {
return client.setQueryData(queryKey, updater);
}
/**
* Gets query data from the QueryClient cache.
*
* @param {QueryClient} client
* @param {Array<any>} queryKey
* @returns {any}
*/
export function getQueryData(client, queryKey) {
return client.getQueryData(queryKey);
}
export { QueryClient, QueryCache, MutationCache };
export default QueryClient;
{
"name": "sample-query-core-verify",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-query-core-verify",
"version": "1.0.0",
"dependencies": {
"@tanstack/query-core": "5.67.1"
}
},
"node_modules/@tanstack/query-core": {
"version": "5.67.1",
"resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.67.1.tgz",
"integrity": "sha512-AkFmuukVejyqVIjEQoFhLb3q+xHl7JG8G9cANWTMe3s8iKzD9j1VBSYXgCjy6vm6xM8cUCR9zP2yqWxY9pTWOA==",
"license": "MIT",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/tannerlinsley"
}
}
}
}
{
"name": "sample-query-core-verify",
"version": "1.0.0",
"private": true,
"type": "module",
"dependencies": {
"@tanstack/query-core": "5.67.1"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/%40tanstack/query-core@5.67.1",
"kind": "HOW",
"packages": [
"pkg:npm/%40tanstack/query-core@5.67.1"
],
"symbols": [
"QueryClient"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
import assert from 'node:assert/strict';
import {
QueryClient,
QueryCache,
MutationCache,
createQueryClient,
fetchQuery,
prefetchQuery,
setQueryData,
getQueryData,
} from '../index.mjs';
// 1. assert QueryClient constructs an instance with default configuration and caches
{
const client = createQueryClient();
assert.ok(client instanceof QueryClient);
assert.strictEqual(typeof client.getQueryData, 'function');
assert.strictEqual(typeof client.setQueryData, 'function');
assert.strictEqual(typeof client.fetchQuery, 'function');
assert.strictEqual(typeof client.prefetchQuery, 'function');
assert.strictEqual(typeof client.invalidateQueries, 'function');
assert.strictEqual(typeof client.removeQueries, 'function');
assert.strictEqual(typeof client.clear, 'function');
assert.ok(client.getQueryCache() instanceof QueryCache);
assert.ok(client.getMutationCache() instanceof MutationCache);
}
// 2. assert QueryClient getQueryData and setQueryData manages cached query values
{
const client = createQueryClient();
setQueryData(client, ['user', 1], { id: 1, name: 'Alice' });
const user = getQueryData(client, ['user', 1]);
assert.deepStrictEqual(user, { id: 1, name: 'Alice' });
setQueryData(client, ['user', 1], (prev) => ({ ...prev, name: 'Bob' }));
assert.deepStrictEqual(getQueryData(client, ['user', 1]), { id: 1, name: 'Bob' });
assert.strictEqual(getQueryData(client, ['user', 999]), undefined);
}
// 3. assert QueryClient fetchQuery executes queryFn and caches the resolved data
{
const client = createQueryClient();
let fetchCount = 0;
const data = await fetchQuery(client, {
queryKey: ['post', 1],
queryFn: async () => {
fetchCount++;
return { id: 1, title: 'Hello' };
},
});
assert.deepStrictEqual(data, { id: 1, title: 'Hello' });
assert.strictEqual(fetchCount, 1);
assert.deepStrictEqual(getQueryData(client, ['post', 1]), { id: 1, title: 'Hello' });
const state = client.getQueryState(['post', 1]);
assert.strictEqual(state.status, 'success');
assert.strictEqual(state.dataUpdatedAt > 0, true);
}
// 4. assert QueryClient prefetchQuery loads data into cache without returning value
{
const client = createQueryClient();
let prefetchCount = 0;
const result = await prefetchQuery(client, {
queryKey: ['items'],
queryFn: async () => {
prefetchCount++;
return ['item1', 'item2'];
},
});
assert.strictEqual(result, undefined);
assert.strictEqual(prefetchCount, 1);
assert.deepStrictEqual(getQueryData(client, ['items']), ['item1', 'item2']);
}
// 5. assert QueryClient invalidateQueries marks matching queries as stale
{
const client = createQueryClient();
setQueryData(client, ['todos', 1], 'Buy groceries');
setQueryData(client, ['todos', 2], 'Read docs');
setQueryData(client, ['posts', 1], 'Blog post');
const todo1 = client.getQueryCache().find({ queryKey: ['todos', 1] });
assert.strictEqual(todo1.isStale(), false);
await client.invalidateQueries({ queryKey: ['todos'] });
assert.strictEqual(todo1.isStale(), true);
const todo2 = client.getQueryCache().find({ queryKey: ['todos', 2] });
assert.strictEqual(todo2.isStale(), true);
const post1 = client.getQueryCache().find({ queryKey: ['posts', 1] });
assert.strictEqual(post1.isStale(), false);
}
// 6. assert QueryClient removeQueries removes matching queries and clear resets all caches
{
const client = createQueryClient();
setQueryData(client, ['data', 1], 'alpha');
setQueryData(client, ['data', 2], 'beta');
setQueryData(client, ['other', 1], 'gamma');
assert.strictEqual(client.getQueryCache().getAll().length, 3);
client.removeQueries({ queryKey: ['data'] });
assert.strictEqual(client.getQueryCache().getAll().length, 1);
assert.strictEqual(getQueryData(client, ['data', 1]), undefined);
assert.strictEqual(getQueryData(client, ['other', 1]), 'gamma');
client.clear();
assert.strictEqual(client.getQueryCache().getAll().length, 0);
assert.strictEqual(client.getMutationCache().getAll().length, 0);
}
console.log('All QueryClient contract assertions passed.');
Исходный сидер
аноним