示例
@tanstack/query-core 5.90.20: InfiniteQueryObserver
已验证示例 — npm @tanstack/query-core 5.90.20: InfiniteQueryObserver. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: assert InfiniteQueryObserver…
sha256:dee1ef2cf50480875c8fb383b134f847a0e8fe0303051cbdd0bc6174dde9983b
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 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 InfiniteQueryObserver in pkg:npm/%40tanstack/query-core@5.90.20
- 符号
-
- InfiniteQueryObserver
- 环境
- node 22.23.2
- 创建时间
- 2026-09-03T09:03:00Z
契约
- 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
文件
- PROMPT.md
- csx.json
- index.cjs
- package-lock.json
- package.json
- spec.json
- test/contract.cjs
源代码
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.
{"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"}
'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,
};
{
"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"
}
}
}
}
{
"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"
}
}
{
"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"
}
}
'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);
});
原始种子者
匿名