CodeSampleX

Sample

@tanstack/query-core 5.90.20: InfiniteQueryObserver

Verified sample for npm @tanstack/query-core 5.90.20: InfiniteQueryObserver. The contract ran on node 22 · linux debian/x64 · docker and passed.

sha256:dee1ef2cf50480875c8fb383b134f847a0e8fe0303051cbdd0bc6174dde9983b

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify InfiniteQueryObserver in pkg:npm/%40tanstack/query-core@5.90.20
Packages
Symbols
  • InfiniteQueryObserver
Environment
node 22.23.2
Created
2026-09-03T09:03:00Z

Contract

  1. assert InfiniteQueryObserver constructs an instance with expected observer methods
  2. assert InfiniteQueryObserver fetchNextPage appends subsequent page data and updates pageParams
  3. assert InfiniteQueryObserver hasNextPage is false when getNextPageParam returns undefined
  4. assert InfiniteQueryObserver fetchPreviousPage prepends previous page data and updates pageParams
  5. assert InfiniteQueryObserver subscribe notifies listeners on query state changes
  6. assert InfiniteQueryObserver setOptions dynamically updates query configuration

Files

  • PROMPT.md
  • csx.json
  • index.cjs
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.cjs

Download the source artifact (tar.gz)

Source

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 InfiniteQueryObserver in pkg:npm/%40tanstack/query-core@5.90.20
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40tanstack/query-core@5.90.20
Demonstrate these symbols/APIs:
  - InfiniteQueryObserver
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:4505b23f71d1d2f66bef0c859741ec3d217f857ec43f23a541b667ac552c902b","constraints":{"executionContext":"node"},"contract":["assert InfiniteQueryObserver constructs an instance with expected observer methods","assert InfiniteQueryObserver fetchNextPage appends subsequent page data and updates pageParams","assert InfiniteQueryObserver hasNextPage is false when getNextPageParam returns undefined","assert InfiniteQueryObserver fetchPreviousPage prepends previous page data and updates pageParams","assert InfiniteQueryObserver subscribe notifies listeners on query state changes","assert InfiniteQueryObserver setOptions dynamically updates query configuration"],"goal":"verify InfiniteQueryObserver in pkg:npm/%40tanstack/query-core@5.90.20","kind":"HOW","packages":["pkg:npm/%40tanstack/query-core@5.90.20"],"schemaVersion":1,"symbols":["InfiniteQueryObserver"]},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","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.90.20"],"schemaVersion":1,"subject":"pkg:npm/%40tanstack/query-core@5.90.20","symbols":["InfiniteQueryObserver"],"verifierAdapter":"node-typescript@1"}
index.cjs
'use strict';

const { InfiniteQueryObserver, QueryClient } = require('@tanstack/query-core');

/**
 * Creates an InfiniteQueryObserver instance for a QueryClient.
 *
 * @param {QueryClient} client
 * @param {object} options
 * @returns {InfiniteQueryObserver}
 */
function createInfiniteObserver(client, options) {
  return new InfiniteQueryObserver(client, options);
}

/**
 * Subscribes a listener to InfiniteQueryObserver state transitions.
 *
 * @param {InfiniteQueryObserver} observer
 * @param {Function} listener
 * @returns {Function} Unsubscribe function
 */
function subscribeInfiniteObserver(observer, listener) {
  return observer.subscribe(listener);
}

/**
 * Fetches the next page of an infinite query observer.
 *
 * @param {InfiniteQueryObserver} observer
 * @returns {Promise<object>}
 */
function fetchNext(observer) {
  return observer.fetchNextPage();
}

/**
 * Fetches the previous page of an infinite query observer.
 *
 * @param {InfiniteQueryObserver} observer
 * @returns {Promise<object>}
 */
function fetchPrevious(observer) {
  return observer.fetchPreviousPage();
}

module.exports = {
  InfiniteQueryObserver,
  QueryClient,
  createInfiniteObserver,
  subscribeInfiniteObserver,
  fetchNext,
  fetchPrevious,
};
package-lock.json
{
  "name": "sample-query-core-infinite-query-observer",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-query-core-infinite-query-observer",
      "version": "1.0.0",
      "dependencies": {
        "@tanstack/query-core": "5.90.20"
      }
    },
    "node_modules/@tanstack/query-core": {
      "version": "5.90.20",
      "resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.90.20.tgz",
      "integrity": "sha512-OMD2HLpNouXEfZJWcKeVKUgQ5n+n3A2JFmBaScpNDUqSrQSjiveC7dKMe53uJUg1nDG16ttFPz2xfilz6i2uVg==",
      "license": "MIT",
      "funding": {
        "type": "github",
        "url": "https://github.com/sponsors/tannerlinsley"
      }
    }
  }
}
package.json
{
  "name": "sample-query-core-infinite-query-observer",
  "version": "1.0.0",
  "private": true,
  "description": "Verify InfiniteQueryObserver in @tanstack/query-core",
  "main": "index.cjs",
  "dependencies": {
    "@tanstack/query-core": "5.90.20"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify InfiniteQueryObserver in pkg:npm/%40tanstack/query-core@5.90.20",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40tanstack/query-core@5.90.20"
  ],
  "symbols": [
    "InfiniteQueryObserver"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.cjs
'use strict';

const assert = require('node:assert/strict');
const {
  InfiniteQueryObserver,
  QueryClient,
  createInfiniteObserver,
  subscribeInfiniteObserver,
  fetchNext,
  fetchPrevious,
} = require('../index.cjs');

async function main() {
  const client = new QueryClient();

  // 1. assert InfiniteQueryObserver constructs an instance with expected observer methods
  {
    const observer = createInfiniteObserver(client, {
      queryKey: ['contract-construct'],
      queryFn: ({ pageParam = 0 }) => ({
        items: [`item-${pageParam}`],
        nextCursor: pageParam < 2 ? pageParam + 1 : undefined,
      }),
      initialPageParam: 0,
      getNextPageParam: (lastPage) => lastPage.nextCursor,
    });

    assert.ok(observer instanceof InfiniteQueryObserver);
    assert.strictEqual(typeof observer.fetchNextPage, 'function');
    assert.strictEqual(typeof observer.fetchPreviousPage, 'function');
    assert.strictEqual(typeof observer.getCurrentResult, 'function');
    assert.strictEqual(typeof observer.subscribe, 'function');
    assert.strictEqual(typeof observer.setOptions, 'function');
  }

  // 2. assert InfiniteQueryObserver fetchNextPage appends subsequent page data and updates pageParams
  {
    const observer = new InfiniteQueryObserver(client, {
      queryKey: ['contract-pagination'],
      queryFn: ({ pageParam = 0 }) => ({
        items: [`page-${pageParam}`],
        nextCursor: pageParam < 2 ? pageParam + 1 : undefined,
      }),
      initialPageParam: 0,
      getNextPageParam: (lastPage) => lastPage.nextCursor,
    });

    const initial = observer.getCurrentResult();
    assert.strictEqual(initial.status, 'pending');

    const res1 = await fetchNext(observer);
    assert.strictEqual(res1.status, 'success');
    assert.strictEqual(res1.data.pages.length, 1);
    assert.deepStrictEqual(res1.data.pageParams, [0]);
    assert.deepStrictEqual(res1.data.pages[0].items, ['page-0']);
    assert.strictEqual(res1.hasNextPage, true);

    const res2 = await fetchNext(observer);
    assert.strictEqual(res2.status, 'success');
    assert.strictEqual(res2.data.pages.length, 2);
    assert.deepStrictEqual(res2.data.pageParams, [0, 1]);
    assert.deepStrictEqual(res2.data.pages[1].items, ['page-1']);
    assert.strictEqual(res2.hasNextPage, true);

    const res3 = await fetchNext(observer);
    assert.strictEqual(res3.status, 'success');
    assert.strictEqual(res3.data.pages.length, 3);
    assert.deepStrictEqual(res3.data.pageParams, [0, 1, 2]);
    assert.strictEqual(res3.hasNextPage, false);
  }

  // 3. assert InfiniteQueryObserver hasNextPage is false when getNextPageParam returns undefined
  {
    const observer = new InfiniteQueryObserver(client, {
      queryKey: ['contract-single-page'],
      queryFn: () => ({ data: 'only-page' }),
      initialPageParam: 'start',
      getNextPageParam: () => undefined,
    });

    await fetchNext(observer);
    const res = observer.getCurrentResult();
    assert.strictEqual(res.hasNextPage, false);
  }

  // 4. assert InfiniteQueryObserver fetchPreviousPage prepends previous page data and updates pageParams
  {
    const observer = new InfiniteQueryObserver(client, {
      queryKey: ['contract-bidirectional'],
      queryFn: ({ pageParam }) => ({
        page: pageParam,
        prev: pageParam > 0 ? pageParam - 1 : undefined,
        next: pageParam < 5 ? pageParam + 1 : undefined,
      }),
      initialPageParam: 2,
      getNextPageParam: (lastPage) => lastPage.next,
      getPreviousPageParam: (firstPage) => firstPage.prev,
    });

    await fetchNext(observer);
    assert.strictEqual(observer.getCurrentResult().hasPreviousPage, true);

    await fetchPrevious(observer);
    const res = observer.getCurrentResult();
    assert.strictEqual(res.data.pages.length, 2);
    assert.deepStrictEqual(res.data.pageParams, [1, 2]);
    assert.strictEqual(res.data.pages[0].page, 1);
    assert.strictEqual(res.data.pages[1].page, 2);
  }

  // 5. assert InfiniteQueryObserver subscribe notifies listeners on query state changes
  {
    const observer = new InfiniteQueryObserver(client, {
      queryKey: ['contract-subscribe'],
      queryFn: async ({ pageParam = 1 }) => `note-${pageParam}`,
      initialPageParam: 1,
      getNextPageParam: (last) => (last === 'note-1' ? 2 : undefined),
    });

    const statuses = [];
    const unsubscribe = subscribeInfiniteObserver(observer, (result) => {
      statuses.push(result.status);
    });

    await fetchNext(observer);
    unsubscribe();

    assert.ok(statuses.includes('success'));
  }

  // 6. assert InfiniteQueryObserver setOptions dynamically updates query configuration
  {
    const observer = new InfiniteQueryObserver(client, {
      queryKey: ['contract-options'],
      queryFn: async () => 'initial',
      initialPageParam: 0,
      getNextPageParam: () => undefined,
      enabled: false,
    });

    assert.strictEqual(observer.getCurrentResult().fetchStatus, 'idle');

    observer.setOptions({
      queryKey: ['contract-options-updated'],
      queryFn: async () => 'updated',
      initialPageParam: 0,
      getNextPageParam: () => undefined,
      enabled: true,
    });

    await fetchNext(observer);
    assert.strictEqual(observer.getCurrentResult().data.pages[0], 'updated');
  }

  console.log('All InfiniteQueryObserver contract assertions passed.');
}

main().catch((err) => {
  console.error(err);
  process.exit(1);
});

Origin Seeder

anonymous