示例
@tanstack/query-core 5.67.1: matchQuery
已验证示例 — npm @tanstack/query-core 5.67.1: matchQuery. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: matchQuery returns true for queryKey prefix…
sha256:24b465772d89059f43b7df7da123b6bcc6046b1b92c255f22ca2474fa34c143d
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
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.');
原始种子者
匿名