CodeSampleX

Beispiel

@tanstack/query-core 5.67.1: matchQuery

Verifiziertes Beispiel für npm @tanstack/query-core 5.67.1: matchQuery. Der Vertrag lief auf node 22 · linux debian/x64 · docker und bestand.

sha256:24b465772d89059f43b7df7da123b6bcc6046b1b92c255f22ca2474fa34c143d

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
verify matchQuery in pkg:npm/%40tanstack/query-core@5.67.1
Pakete
Symbole
  • matchQuery
Umgebung
node 22.23.2
Erstellt
2026-09-03T13:44:31Z

Contract

  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

Dateien

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.mjs

Quellartefakt herunterladen (tar.gz)

Quelltext

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.');

Ursprungs-Seeder

anonym