Exemple
@tanstack/query-core 5.67.1: matchQuery
Échantillon vérifié pour npm @tanstack/query-core 5.67.1: matchQuery. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a réussi.
sha256:24b465772d89059f43b7df7da123b6bcc6046b1b92c255f22ca2474fa34c143d
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| 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 |
Cas
HOW- Objectif
- verify matchQuery in pkg:npm/%40tanstack/query-core@5.67.1
- Paquets
- Symboles
-
- matchQuery
- Environnement
- node 22.23.2
- Créé
- 2026-09-03T13:44:31Z
Contrat
- matchQuery returns true for queryKey prefix matching by default
- matchQuery returns true for exact queryKey match when exact option is true
- matchQuery returns false when exact option is true and queryKey differs or is a prefix
- matchQuery filters queries by active and inactive observer state
- matchQuery matches query fetchStatus and stale state
- matchQuery evaluates custom predicate function against the query instance
Fichiers
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
Code source
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 matchQuery in 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:
- matchQuery
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:710f36a84a14d86768acd99a22cf2531cab5733744ada73775b7215ab1ec4c5d","contract":["matchQuery returns true for queryKey prefix matching by default","matchQuery returns true for exact queryKey match when exact option is true","matchQuery returns false when exact option is true and queryKey differs or is a prefix","matchQuery filters queries by active and inactive observer state","matchQuery matches query fetchStatus and stale state","matchQuery evaluates custom predicate function against the query instance"],"goal":"verify matchQuery in pkg:npm/%40tanstack/query-core@5.67.1","kind":"HOW","packages":["pkg:npm/%40tanstack/query-core@5.67.1"],"schemaVersion":1,"symbols":["matchQuery"]},"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":["matchQuery"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-query-core-match-query",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-query-core-match-query",
"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"
}
}
}
{
"name": "sample-query-core-match-query",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification of matchQuery in @tanstack/query-core",
"type": "module",
"main": "src/index.js",
"dependencies": {
"@tanstack/query-core": "5.67.1"
}
}
{
"schemaVersion": 1,
"goal": "verify matchQuery in pkg:npm/%40tanstack/query-core@5.67.1",
"kind": "HOW",
"packages": [
"pkg:npm/%40tanstack/query-core@5.67.1"
],
"symbols": [
"matchQuery"
]
}
import { matchQuery } from '@tanstack/query-core';
/**
* Evaluates whether a query matches the provided filter criteria.
*
* @param {object} filters - The query filters to evaluate.
* @param {object} query - The query instance to check against.
* @returns {boolean} True if query satisfies filters, false otherwise.
*/
export function isQueryMatching(filters, query) {
return matchQuery(filters, query);
}
/**
* Filters a collection of query instances based on matching criteria.
*
* @param {Array<object>} queries - Collection of query instances.
* @param {object} filters - Query filter criteria.
* @returns {Array<object>} Query instances that match the filters.
*/
export function filterQueries(queries, filters) {
return queries.filter((query) => matchQuery(filters, query));
}
export { matchQuery };
import assert from 'node:assert/strict';
import { QueryClient, QueryObserver } from '@tanstack/query-core';
import { matchQuery, isQueryMatching, filterQueries } from '../src/index.js';
// 1. Export verification
assert.equal(typeof matchQuery, 'function', 'matchQuery should be exported as a function');
assert.equal(typeof isQueryMatching, 'function', 'isQueryMatching helper should be a function');
assert.equal(typeof filterQueries, 'function', 'filterQueries helper should be a function');
const client = new QueryClient();
const queryCache = client.getQueryCache();
// 2. Query key prefix matching by default
const query1 = queryCache.build(client, {
queryKey: ['todos', 'detail', 1],
});
assert.equal(matchQuery({ queryKey: ['todos'] }, query1), true);
assert.equal(matchQuery({ queryKey: ['todos', 'detail'] }, query1), true);
assert.equal(matchQuery({ queryKey: ['todos', 'detail', 1] }, query1), true);
assert.equal(isQueryMatching({ queryKey: ['todos'] }, query1), true);
// 3. Exact query key matching
assert.equal(matchQuery({ queryKey: ['todos', 'detail', 1], exact: true }, query1), true);
assert.equal(matchQuery({ queryKey: ['todos'], exact: true }, query1), false);
assert.equal(matchQuery({ queryKey: ['todos', 'detail'], exact: true }, query1), false);
assert.equal(matchQuery({ queryKey: ['todos', 'other'], exact: true }, query1), false);
assert.equal(matchQuery({ queryKey: ['todos', 'other'] }, query1), false);
// Exact match with object keys
const query2 = queryCache.build(client, {
queryKey: ['users', { role: 'admin', team: 'eng' }],
});
assert.equal(matchQuery({ queryKey: ['users', { role: 'admin', team: 'eng' }], exact: true }, query2), true);
assert.equal(matchQuery({ queryKey: ['users', { role: 'admin' }], exact: false }, query2), true);
assert.equal(matchQuery({ queryKey: ['users', { role: 'admin' }], exact: true }, query2), false);
// 4. Filtering queries by active and inactive observer state
assert.equal(query1.isActive(), false, 'query should initially be inactive');
assert.equal(matchQuery({ type: 'inactive' }, query1), true);
assert.equal(matchQuery({ type: 'active' }, query1), false);
assert.equal(matchQuery({ type: 'all' }, query1), true);
const observer = new QueryObserver(client, { queryKey: ['todos', 'detail', 1] });
const unsubscribe = observer.subscribe(() => {});
assert.equal(query1.isActive(), true, 'query should become active after subscription');
assert.equal(matchQuery({ type: 'active' }, query1), true);
assert.equal(matchQuery({ type: 'inactive' }, query1), false);
unsubscribe();
assert.equal(query1.isActive(), false, 'query should become inactive after unsubscription');
assert.equal(matchQuery({ type: 'inactive' }, query1), true);
assert.equal(matchQuery({ type: 'active' }, query1), false);
// 5. Matching query fetchStatus and stale state
const staleQuery = queryCache.build(client, {
queryKey: ['posts', 'stale'],
staleTime: 0,
});
assert.equal(staleQuery.isStale(), true);
assert.equal(matchQuery({ stale: true }, staleQuery), true);
assert.equal(matchQuery({ stale: false }, staleQuery), false);
const freshQuery = queryCache.build(client, {
queryKey: ['posts', 'fresh'],
staleTime: 60000,
});
freshQuery.setData('sample-post-data');
assert.equal(freshQuery.isStale(), false);
assert.equal(matchQuery({ stale: false }, freshQuery), true);
assert.equal(matchQuery({ stale: true }, freshQuery), false);
assert.equal(matchQuery({ fetchStatus: 'idle' }, freshQuery), true);
assert.equal(matchQuery({ fetchStatus: 'fetching' }, freshQuery), false);
// 6. Custom predicate evaluation
assert.equal(matchQuery({ predicate: (q) => q.queryKey[0] === 'posts' }, freshQuery), true);
assert.equal(matchQuery({ predicate: (q) => q.queryKey[0] === 'todos' }, freshQuery), false);
// 7. filterQueries helper verification
const allQueries = [query1, query2, staleQuery, freshQuery];
const postQueries = filterQueries(allQueries, { queryKey: ['posts'] });
assert.equal(postQueries.length, 2);
assert.deepEqual(
postQueries.map((q) => q.queryKey),
[['posts', 'stale'], ['posts', 'fresh']]
);
console.log('Contract tests passed successfully.');
Seeder d'origine
anonyme