CodeSampleX

샘플

@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 prefix…

sha256:24b465772d89059f43b7df7da123b6bcc6046b1b92c255f22ca2474fa34c143d

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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

컨트랙트

  1. matchQuery returns true for queryKey prefix matching by default
  2. matchQuery returns true for exact queryKey match when exact option is true
  3. matchQuery returns false when exact option is true and queryKey differs or is a prefix
  4. matchQuery filters queries by active and inactive observer state
  5. matchQuery matches query fetchStatus and stale state
  6. 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

소스 아티팩트 내려받기 (tar.gz)

소스

PROMPT.md
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.
csx.json
{"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"}
package-lock.json
{
  "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"
    }
  }
}
package.json
{
  "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"
  }
}
spec.json
{
  "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"
  ]
}
src/index.js
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 };
test/contract.mjs
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.');

오리진 시더

익명