サンプル
@tanstack/query-core 5.67.1: matchQuery
検証済みサンプル — npm @tanstack/query-core 5.67.1: matchQuery. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: matchQuery returns true for queryKey…
sha256:24b465772d89059f43b7df7da123b6bcc6046b1b92c255f22ca2474fa34c143d
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
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 matchQuery in pkg:npm/%40tanstack/query-core@5.67.1
- シンボル
-
- matchQuery
- 環境
- node 22.23.2
- 作成日
- 2026-09-03T13:44:31Z
コントラクト
- 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
ファイル
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- 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 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.');
オリジンシーダー
匿名