CodeSampleX

サンプル

@tanstack/query-core 5.90.20: InfiniteQueryObserver

検証済みサンプル — npm @tanstack/query-core 5.90.20: InfiniteQueryObserver. node 22 · linux debian/x64 · docker で contract を実行し、成功しました.

sha256:59f30c76a3c89d37abaac2461b1de0d149e37ff6e347f3e7430444436ec272d8

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 npm

検証実行環境

環境 コントラクト ステージ 実行日
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 pkg:npm/%40tanstack/query-core@5.90.20
パッケージ
シンボル
  • InfiniteQueryObserver
作成日
2026-09-03T08:58:24Z

コントラクト

  1. assert InfiniteQueryObserver constructs an instance with 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

ファイル

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • spec.json
  • 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 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

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:0c4fe446204d70519d44a021a9cd9108e26f41d4484ef2585060f745e941fe3e","contract":["assert InfiniteQueryObserver constructs an instance with 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 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.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","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.mjs
import { InfiniteQueryObserver, QueryClient } from '@tanstack/query-core';

/**
 * Creates a new InfiniteQueryObserver instance for the given QueryClient and options.
 *
 * @param {QueryClient} client
 * @param {object} options
 * @returns {InfiniteQueryObserver}
 */
export function createInfiniteQueryObserver(client, options) {
  return new InfiniteQueryObserver(client, options);
}

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

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

export { InfiniteQueryObserver, QueryClient };
export default InfiniteQueryObserver;
package-lock.json
{
  "name": "sample-query-core-verify",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-query-core-verify",
      "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-verify",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "dependencies": {
    "@tanstack/query-core": "5.90.20"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40tanstack/query-core@5.90.20",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40tanstack/query-core@5.90.20"
  ],
  "symbols": [
    "InfiniteQueryObserver"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import {
  InfiniteQueryObserver,
  QueryClient,
  createInfiniteQueryObserver,
  subscribeInfiniteQuery,
  fetchNext,
} from '../index.mjs';

const client = new QueryClient();

// 1. assert InfiniteQueryObserver constructs an instance with observer methods
{
  const observer = createInfiniteQueryObserver(client, {
    queryKey: ['projects'],
    queryFn: ({ pageParam = 0 }) => ({
      items: [`project-${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: ['posts'],
    queryFn: ({ pageParam = 0 }) => ({
      items: [`post-${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, ['post-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, ['post-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: ['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: ['messages'],
    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 observer.fetchPreviousPage();
  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: ['notifications'],
    queryFn: async ({ pageParam = 1 }) => `note-${pageParam}`,
    initialPageParam: 1,
    getNextPageParam: (last) => (last === 'note-1' ? 2 : undefined),
  });

  const statuses = [];
  const unsubscribe = subscribeInfiniteQuery(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: ['dynamic'],
    queryFn: async () => 'initial',
    initialPageParam: 0,
    getNextPageParam: () => undefined,
    enabled: false,
  });

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

  observer.setOptions({
    queryKey: ['dynamic-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.');

オリジンシーダー

匿名